From 3584f8f5aeff3f70e09f57e459ede138bde58eeb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rostislav=20St=C5=99=C3=ADbrn=C3=BD?= Date: Fri, 4 Nov 2022 14:25:08 +0100 Subject: [PATCH] Pre-C99 compatible definitions --- src/hellolog.c | 3 +++ src/log.h | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+) diff --git a/src/hellolog.c b/src/hellolog.c index 961a6ab..19d1b4c 100644 --- a/src/hellolog.c +++ b/src/hellolog.c @@ -31,6 +31,9 @@ int main(int argc, char** argv) { log_error("ERROR - Hello %s", "world"); log_fatal("FATAL - Hello %s", "world"); + // Pre-C99 usage example + log_trace3("test 3 args: %s %s", "arg1", "arg2"); + fclose(f1); fclose(f2); fclose(f3); diff --git a/src/log.h b/src/log.h index e73fb47..df61e25 100644 --- a/src/log.h +++ b/src/log.h @@ -57,6 +57,75 @@ typedef struct { typedef void (*log_LogFn)(log_Event *ev); typedef void (*log_LockFn)(bool lock, void *udata); +// Pre-C99 compatible definitions - BEGIN +#define log_internal1(level, file, line, arg1) \ + do { \ + if (LOG_TRACE >= RXI_LOGC_DEFAULT_LEVEL) \ + log_log(level, file, line, arg1); \ + } while (0) + +#define log_internal2(level, file, line, arg1, arg2) \ + do { \ + if (LOG_TRACE >= RXI_LOGC_DEFAULT_LEVEL) \ + log_log(level, file, line, arg1, arg2); \ + } while (0) + +#define log_internal3(level, file, line, arg1, arg2, arg3) \ + do { \ + if (LOG_TRACE >= RXI_LOGC_DEFAULT_LEVEL) \ + log_log(level, file, line, arg1, arg2, arg3); \ + } while (0) + +#define log_internal4(level, file, line, arg1, arg2, arg3, arg4) \ + do { \ + if (LOG_TRACE >= RXI_LOGC_DEFAULT_LEVEL) \ + log_log(level, file, line, arg1, arg2, arg3, arg4); \ + } while (0) + +#define log_internal5(level, file, line, arg1, arg2, arg3, arg4, arg5) \ + do { \ + if (LOG_TRACE >= RXI_LOGC_DEFAULT_LEVEL) \ + log_log(level, file, line, arg1, arg2, arg3, arg4, arg5); \ + } while (0) + +#define log_trace1(arg1) log_internal1(LOG_TRACE, __FILE__, __LINE__, arg1); +#define log_trace2(arg1, arg2) log_internal2(LOG_TRACE, __FILE__, __LINE__, arg1, arg2); +#define log_trace3(arg1, arg2, arg3) log_internal3(LOG_TRACE, __FILE__, __LINE__, arg1, arg2, arg3); +#define log_trace4(arg1, arg2, arg3, arg4) log_internal4(LOG_TRACE, __FILE__, __LINE__, arg1, arg2, arg3, arg4); +#define log_trace5(arg1, arg2, arg3, arg4, arg5) log_internal5(LOG_TRACE, __FILE__, __LINE__, arg1, arg2, arg3, arg4, arg5); + +#define log_debug1(arg1) log_internal1(LOG_DEBUG, __FILE__, __LINE__, arg1); +#define log_debug2(arg1, arg2) log_internal2(LOG_DEBUG, __FILE__, __LINE__, arg1, arg2); +#define log_debug3(arg1, arg2, arg3) log_internal3(LOG_DEBUG, __FILE__, __LINE__, arg1, arg2, arg3); +#define log_debug4(arg1, arg2, arg3, arg4) log_internal4(LOG_DEBUG, __FILE__, __LINE__, arg1, arg2, arg3, arg4); +#define log_debug5(arg1, arg2, arg3, arg4, arg5) log_internal5(LOG_DEBUG, __FILE__, __LINE__, arg1, arg2, arg3, arg4, arg5); + +#define log_info1(arg1) log_internal1(LOG_INFO, __FILE__, __LINE__, arg1); +#define log_info2(arg1, arg2) log_internal2(LOG_INFO, __FILE__, __LINE__, arg1, arg2); +#define log_info3(arg1, arg2, arg3) log_internal3(LOG_INFO, __FILE__, __LINE__, arg1, arg2, arg3); +#define log_info4(arg1, arg2, arg3, arg4) log_internal4(LOG_INFO, __FILE__, __LINE__, arg1, arg2, arg3, arg4); +#define log_info5(arg1, arg2, arg3, arg4, arg5) log_internal5(LOG_INFO, __FILE__, __LINE__, arg1, arg2, arg3, arg4, arg5); + +#define log_warn1(arg1) log_internal1(LOG_WARN, __FILE__, __LINE__, arg1); +#define log_warn2(arg1, arg2) log_internal2(LOG_WARN, __FILE__, __LINE__, arg1, arg2); +#define log_warn3(arg1, arg2, arg3) log_internal3(LOG_WARN, __FILE__, __LINE__, arg1, arg2, arg3); +#define log_warn4(arg1, arg2, arg3, arg4) log_internal4(LOG_WARN, __FILE__, __LINE__, arg1, arg2, arg3, arg4); +#define log_warn5(arg1, arg2, arg3, arg4, arg5) log_internal5(LOG_WARN, __FILE__, __LINE__, arg1, arg2, arg3, arg4, arg5); + +#define log_error1(arg1) log_internal1(LOG_ERROR, __FILE__, __LINE__, arg1); +#define log_error2(arg1, arg2) log_internal2(LOG_ERROR, __FILE__, __LINE__, arg1, arg2); +#define log_error3(arg1, arg2, arg3) log_internal3(LOG_ERROR, __FILE__, __LINE__, arg1, arg2, arg3); +#define log_error4(arg1, arg2, arg3, arg4) log_internal4(LOG_ERROR, __FILE__, __LINE__, arg1, arg2, arg3, arg4); +#define log_error5(arg1, arg2, arg3, arg4, arg5) log_internal5(LOG_ERROR, __FILE__, __LINE__, arg1, arg2, arg3, arg4, arg5); + +#define log_fatal1(arg1) log_internal1(LOG_FATAL, __FILE__, __LINE__, arg1); +#define log_fatal2(arg1, arg2) log_internal2(LOG_FATAL, __FILE__, __LINE__, arg1, arg2); +#define log_fatal3(arg1, arg2, arg3) log_internal3(LOG_FATAL, __FILE__, __LINE__, arg1, arg2, arg3); +#define log_fatal4(arg1, arg2, arg3, arg4) log_internal4(LOG_FATAL, __FILE__, __LINE__, arg1, arg2, arg3, arg4); +#define log_fatal5(arg1, arg2, arg3, arg4, arg5) log_internal5(LOG_FATAL, __FILE__, __LINE__, arg1, arg2, arg3, arg4, arg5); +// Pre-C99 compatible definitions - END + + #define log_trace(...) \ do { \ if (LOG_TRACE >= RXI_LOGC_DEFAULT_LEVEL) \