From e986713657bc5f9880e91ed49dd9b0d0227f048d Mon Sep 17 00:00:00 2001 From: Sebastiano Tronto Date: Mon, 17 Jun 2024 17:39:06 +0200 Subject: Use callback function to log to stderr --- src/cube.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) (limited to 'src/cube.c') diff --git a/src/cube.c b/src/cube.c index 97f7844..890e3fb 100644 --- a/src/cube.c +++ b/src/cube.c @@ -1,20 +1,32 @@ #include +#include #include #include +void (*nissy_log)(const char *, va_list); + +void +_log(const char *str, ...) /* TODO: rename */ +{ + va_list args; + + if (nissy_log != NULL) { + va_start(args, str); + nissy_log(str, args); + va_end(args); + } +} + #ifdef DEBUG -#include #define _static #define _static_inline -#define DBG_LOG(...) fprintf(stderr, __VA_ARGS__) -#define DBG_WARN(condition, ...) if (!(condition)) DBG_LOG(__VA_ARGS__); +#define DBG_WARN(condition, ...) if (!(condition)) _log(__VA_ARGS__); #define DBG_ASSERT(condition, retval, ...) \ - if (!(condition)) { DBG_LOG(__VA_ARGS__); return retval; } + if (!(condition)) { _log(__VA_ARGS__); return retval; } #else #define _static static #define _static_inline static inline -#define DBG_LOG(...) #define DBG_WARN(condition, ...) #define DBG_ASSERT(condition, retval, ...) #endif -- cgit v1.3