add debug and gtest hook like as option
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
#include <stdbool.h>
|
||||
#include <time.h>
|
||||
|
||||
|
||||
// to define DEBUG in gcc cli do: gcc -D DEBUG=1 or 0 if need!
|
||||
#ifndef DEBUG
|
||||
#define DEBUG 0
|
||||
@@ -45,7 +46,7 @@ void gotoxy(int x, int y);
|
||||
do { if (DEBUG) fprintf(stderr, "%s:%d:%s(): " fmt, __FILE__, \
|
||||
__LINE__, __func__, __VA_ARGS__); } while (0)
|
||||
|
||||
#define PRINT_DEBUG(fmt, ...) \
|
||||
#define PRINT_DEBUG_(fmt, ...) \
|
||||
do { if (DEBUG) fprintf(F_ERR, "%s:%d:%s(): " fmt, __FILE__, \
|
||||
__LINE__, __func__, __VA_ARGS__); } while (0)
|
||||
|
||||
|
||||
@@ -89,7 +89,7 @@ TYPE_STRING TYPE_STRING_TO_STR(TYPE_STRING var){
|
||||
#define GENERATE_FUNCTION_NUMERIC(type)\
|
||||
int COMPARE_N_##type(const void *a, const void *b){ \
|
||||
type diff = (*(type*)a - *(type*)b)*PRECISION_##type; \
|
||||
PRINT_DEBUG(" diff = %s a=%s b=%s \n",type##_TO_STR(diff),type##_TO_STR(*(type*)a), type##_TO_STR(*(type*)b));\
|
||||
PRINT_DEBUG_(" diff = %s a=%s b=%s \n",type##_TO_STR(diff),type##_TO_STR(*(type*)a), type##_TO_STR(*(type*)b));\
|
||||
if ((diff < 1) && (diff > -1) ) return 0; \
|
||||
return diff; \
|
||||
} \
|
||||
@@ -102,7 +102,7 @@ TYPE_STRING TYPE_STRING_TO_STR(TYPE_STRING var){
|
||||
int
|
||||
COMPARE_N_TYPE_STRING(const void *a,const void* b)
|
||||
{
|
||||
PRINT_DEBUG("a=%s, b=%s\n",(char*)a, (char*)b);
|
||||
PRINT_DEBUG_("a=%s, b=%s\n",(char*)a, (char*)b);
|
||||
return strcmp(( char*)a,( char*)b);
|
||||
}
|
||||
|
||||
@@ -172,17 +172,17 @@ GENERATE_FUNCTION_ALL(TYPE_STRING)
|
||||
*/
|
||||
|
||||
double diff_timespec_seconds(struct timespec time_stop, struct timespec time_start){
|
||||
//PRINT_DEBUG("\n\nstop.sec:%ld, start.sec:%ld, stop.nsec:%ld, start.nsec:%ld\n\n", time_stop.tv_sec , time_start.tv_sec, time_stop.tv_nsec , time_start.tv_nsec);
|
||||
//PRINT_DEBUG_("\n\nstop.sec:%ld, start.sec:%ld, stop.nsec:%ld, start.nsec:%ld\n\n", time_stop.tv_sec , time_start.tv_sec, time_stop.tv_nsec , time_start.tv_nsec);
|
||||
return (time_stop.tv_sec - time_start.tv_sec) + 1.0e-9 * (time_stop.tv_nsec - time_start.tv_nsec);
|
||||
}
|
||||
|
||||
double diff_timespec_milliseconds(struct timespec time_stop, struct timespec time_start){
|
||||
//PRINT_DEBUG("\n\nstop.sec:%ld, start.sec:%ld, stop.nsec:%ld, start.nsec:%ld\n\n", time_stop.tv_sec , time_start.tv_sec, time_stop.tv_nsec , time_start.tv_nsec);
|
||||
//PRINT_DEBUG_("\n\nstop.sec:%ld, start.sec:%ld, stop.nsec:%ld, start.nsec:%ld\n\n", time_stop.tv_sec , time_start.tv_sec, time_stop.tv_nsec , time_start.tv_nsec);
|
||||
return 1.0e3 * (time_stop.tv_sec - time_start.tv_sec) + 1.0e-6 * (time_stop.tv_nsec - time_start.tv_nsec);
|
||||
}
|
||||
|
||||
long diff_timespec_nanoseconds(struct timespec time_stop, struct timespec time_start){
|
||||
//PRINT_DEBUG("\n\nstop.sec:%ld, start.sec:%ld, stop.nsec:%ld, start.nsec:%ld\n\n", time_stop.tv_sec , time_start.tv_sec, time_stop.tv_nsec , time_start.tv_nsec);
|
||||
//PRINT_DEBUG_("\n\nstop.sec:%ld, start.sec:%ld, stop.nsec:%ld, start.nsec:%ld\n\n", time_stop.tv_sec , time_start.tv_sec, time_stop.tv_nsec , time_start.tv_nsec);
|
||||
return 1.0e9 * (time_stop.tv_sec - time_start.tv_sec) + (time_stop.tv_nsec - time_start.tv_nsec);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,119 +0,0 @@
|
||||
#ifndef __TOOLS_T_C_H__
|
||||
#define __TOOLS_T_C_H__
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdbool.h>
|
||||
#include <time.h>
|
||||
|
||||
// to define DEBUG in gcc cli do: gcc -D DEBUG=1 or 0 if need!
|
||||
#ifndef DEBUG
|
||||
#define DEBUG 0
|
||||
#endif
|
||||
|
||||
|
||||
// F_OUT file (stream) to log
|
||||
#ifndef F_OUT
|
||||
#define F_OUT stdout
|
||||
#endif
|
||||
// F_ERR file (stream) to log
|
||||
#ifndef F_ERR
|
||||
#define F_ERR stderr
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/*
|
||||
#ifndef SECOND
|
||||
#define SECOND 0
|
||||
#endif
|
||||
#ifndef NANOSECOND
|
||||
#define NANOSECOND 0
|
||||
#endif
|
||||
|
||||
double diff_timespec_seconds(struct timespec time_stop, struct timespec time_start);
|
||||
double diff_timespec_milliseconds(struct timespec time_stop, struct timespec time_start);
|
||||
long diff_timespec_nanoseconds(struct timespec time_stop, struct timespec time_start);
|
||||
*/
|
||||
|
||||
void gotoxy(int x, int y);
|
||||
//void get_cursor_position(int *col, int *rows);
|
||||
|
||||
|
||||
#define debug_print(fmt, ...) \
|
||||
do { if (DEBUG) fprintf(stderr, "%s:%d:%s(): " fmt, __FILE__, \
|
||||
__LINE__, __func__, __VA_ARGS__); } while (0)
|
||||
|
||||
#define PRINT_DEBUG(fmt, ...) \
|
||||
do { if (DEBUG) fprintf(F_ERR, "%s:%d:%s(): " fmt, __FILE__, \
|
||||
__LINE__, __func__, __VA_ARGS__); } while (0)
|
||||
|
||||
|
||||
#define error_print(fmt, ...) \
|
||||
fprintf(stderr, "%s:%d:%s(): " fmt, __FILE__, \
|
||||
__LINE__, __func__, __VA_ARGS__);
|
||||
|
||||
#define PRINT_ERROR(fmt, ...) \
|
||||
fprintf(F_ERR, "%s:%d:%s(): " fmt, __FILE__, \
|
||||
__LINE__, __func__, __VA_ARGS__);
|
||||
|
||||
#define PRINT_LOC_T(fmt, ...) \
|
||||
fprintf(F_OUT, "%s:%d:%s(): " fmt, __FILE__, \
|
||||
__LINE__, __func__, __VA_ARGS__);
|
||||
|
||||
|
||||
|
||||
#define TYPE_CHAR char
|
||||
#define TYPE_U_CHAR unsigned char
|
||||
#define TYPE_INT int
|
||||
#define TYPE_U_INT unsigned int
|
||||
#define TYPE_L_INT long int
|
||||
#define TYPE_U_L_INT unsigned long int
|
||||
#define TYPE_SIZE_T size_t
|
||||
#define TYPE_FLOAT float
|
||||
#define TYPE_DOUBLE double
|
||||
#define TYPE_L_DOUBLE long double
|
||||
#define TYPE_STRING char*
|
||||
|
||||
#define FREE(x) { free((x)); (x) = NULL;}
|
||||
|
||||
#define FOREACH(array, size, function)\
|
||||
for(size_t _ind = 0; _ind < size; ++_ind) function(array[_ind]);
|
||||
|
||||
|
||||
#define GENERATE_ALL(type)\
|
||||
int COMPARE_N_##type(const void *,const void*);\
|
||||
void COPY_ARRAY_##type(type* dst, const type* src, size_t size);\
|
||||
type MAX_ARRAY_##type(const type *array, size_t size);\
|
||||
size_t ARG_MAX_ARRAY_##type(const type *array, size_t size);\
|
||||
type MIN_ARRAY_##type(const type *array, size_t size);\
|
||||
size_t ARG_MIN_ARRAY_##type(const type *array, size_t size);\
|
||||
TYPE_STRING type##_TO_STR(type var);\
|
||||
|
||||
|
||||
GENERATE_ALL(TYPE_CHAR)
|
||||
GENERATE_ALL(TYPE_U_CHAR)
|
||||
GENERATE_ALL(TYPE_INT)
|
||||
GENERATE_ALL(TYPE_U_INT)
|
||||
GENERATE_ALL(TYPE_L_INT)
|
||||
GENERATE_ALL(TYPE_U_L_INT)
|
||||
GENERATE_ALL(TYPE_SIZE_T)
|
||||
GENERATE_ALL(TYPE_FLOAT)
|
||||
GENERATE_ALL(TYPE_DOUBLE)
|
||||
GENERATE_ALL(TYPE_L_DOUBLE)
|
||||
GENERATE_ALL(TYPE_STRING)
|
||||
|
||||
|
||||
/*
|
||||
* time calucl
|
||||
*/
|
||||
double diff_timespec_seconds(struct timespec time_stop, struct timespec time_start);
|
||||
|
||||
double diff_timespec_milliseconds(struct timespec time_stop, struct timespec time_start);
|
||||
|
||||
long diff_timespec_nanoseconds(struct timespec time_stop, struct timespec time_start);
|
||||
|
||||
|
||||
#endif /*__TOOLS_T_C_H__*/
|
||||
|
||||
Reference in New Issue
Block a user