diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2024-06-17 17:39:06 +0200 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2024-06-17 17:39:30 +0200 |
| commit | e986713657bc5f9880e91ed49dd9b0d0227f048d (patch) | |
| tree | 908d371e60546795c4ca1f9a3b67571b964203c5 /src/cube.c | |
| parent | 02ce9adf6a9168ec66c322ce9e5a5cb9fe1e60a5 (diff) | |
| download | nissy-core-e986713657bc5f9880e91ed49dd9b0d0227f048d.tar.gz nissy-core-e986713657bc5f9880e91ed49dd9b0d0227f048d.zip | |
Use callback function to log to stderr
Diffstat (limited to '')
| -rw-r--r-- | src/cube.c | 22 |
1 files changed, 17 insertions, 5 deletions
| @@ -1,20 +1,32 @@ | |||
| 1 | #include <inttypes.h> | 1 | #include <inttypes.h> |
| 2 | #include <stdarg.h> | ||
| 2 | #include <stdbool.h> | 3 | #include <stdbool.h> |
| 3 | #include <string.h> | 4 | #include <string.h> |
| 4 | 5 | ||
| 6 | void (*nissy_log)(const char *, va_list); | ||
| 7 | |||
| 8 | void | ||
| 9 | _log(const char *str, ...) /* TODO: rename */ | ||
| 10 | { | ||
| 11 | va_list args; | ||
| 12 | |||
| 13 | if (nissy_log != NULL) { | ||
| 14 | va_start(args, str); | ||
| 15 | nissy_log(str, args); | ||
| 16 | va_end(args); | ||
| 17 | } | ||
| 18 | } | ||
| 19 | |||
| 5 | #ifdef DEBUG | 20 | #ifdef DEBUG |
| 6 | #include <stdio.h> | ||
| 7 | #define _static | 21 | #define _static |
| 8 | #define _static_inline | 22 | #define _static_inline |
| 9 | #define DBG_LOG(...) fprintf(stderr, __VA_ARGS__) | 23 | #define DBG_WARN(condition, ...) if (!(condition)) _log(__VA_ARGS__); |
| 10 | #define DBG_WARN(condition, ...) if (!(condition)) DBG_LOG(__VA_ARGS__); | ||
| 11 | #define DBG_ASSERT(condition, retval, ...) \ | 24 | #define DBG_ASSERT(condition, retval, ...) \ |
| 12 | if (!(condition)) { DBG_LOG(__VA_ARGS__); return retval; } | 25 | if (!(condition)) { _log(__VA_ARGS__); return retval; } |
| 13 | 26 | ||
| 14 | #else | 27 | #else |
| 15 | #define _static static | 28 | #define _static static |
| 16 | #define _static_inline static inline | 29 | #define _static_inline static inline |
| 17 | #define DBG_LOG(...) | ||
| 18 | #define DBG_WARN(condition, ...) | 30 | #define DBG_WARN(condition, ...) |
| 19 | #define DBG_ASSERT(condition, retval, ...) | 31 | #define DBG_ASSERT(condition, retval, ...) |
| 20 | #endif | 32 | #endif |
