Pre-C99 compatible definitions

This commit is contained in:
Rostislav Stříbrný 2022-11-04 14:25:08 +01:00
parent 96f39b5f39
commit 3584f8f5ae
2 changed files with 72 additions and 0 deletions

View File

@ -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);

View File

@ -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) \