From e4f356b9592599ad91aac34bf2265c9bcdfbb81f Mon Sep 17 00:00:00 2001 From: Sebastiano Tronto Date: Tue, 8 Apr 2025 15:16:21 +0200 Subject: Some minor changes to the interface. - Simplified logger to accept only a string, not a variadic list of args like printf(). This can still use some improvement, but now it is easier to use from other languages. - Fixed some misuses of the logger (wrong types etc) - Renamed some constants - Fixed some typos in comments. --- src/utils/dbg_log.h | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'src/utils/dbg_log.h') diff --git a/src/utils/dbg_log.h b/src/utils/dbg_log.h index f9b1d8a..c30993a 100644 --- a/src/utils/dbg_log.h +++ b/src/utils/dbg_log.h @@ -1,6 +1,23 @@ -void (*nissy_log)(const char *, ...); +#include -#define LOG(...) if (nissy_log != NULL) nissy_log(__VA_ARGS__); +void (*nissy_log)(const char *); +void write_wrapper(void (*)(const char *), const char *, ...); + +void +write_wrapper(void (*write)(const char *), const char *str, ...) +{ + static const size_t len = 1000; + char message[len]; + va_list args; + + va_start(args, str); + sprintf(message, str, args); + va_end(args); + + write(message); +} + +#define LOG(...) if (nissy_log != NULL) write_wrapper(nissy_log, __VA_ARGS__); #ifdef DEBUG #define STATIC -- cgit v1.3