From cab7429706aa6fce9d217ba6c5e3b6e5557914d5 Mon Sep 17 00:00:00 2001 From: David Härdeman Date: Tue, 16 Jun 2020 11:22:46 +0200 Subject: Cleanup debugging macros a bit --- main.h | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) (limited to 'main.h') diff --git a/main.h b/main.h index 23be852..255a252 100644 --- a/main.h +++ b/main.h @@ -10,12 +10,30 @@ struct cfg; extern bool exiting; -extern int debuglvl; +extern unsigned debug_mask; -void debug(unsigned lvl, const char *fmt, ...); +enum debug_category { + DBG_ERROR = (0x1 << 1), + DBG_INFO = (0x1 << 2), + DBG_VERBOSE = (0x1 << 3), + DBG_CFG = (0x1 << 4), + DBG_REF = (0x1 << 5), + DBG_MALLOC = (0x1 << 6), +}; + +static inline bool +debug_enabled(enum debug_category category) +{ + return !!(category & debug_mask); +} + +void do_debug(enum debug_category category, const char *fmt, ...); -#define info(...) fprintf(stderr, __VA_ARGS__) -#define error(...) fprintf(stderr, __VA_ARGS__) +#define __debug(c, ...) do { if (debug_enabled((c))) do_debug((c), __VA_ARGS__); } while (0) +#define debug(c, fmt, ...) __debug(c, "%s:" fmt, __func__, __VA_ARGS__) +#define verbose(...) __debug(DBG_VERBOSE, __VA_ARGS__) +#define info(...) __debug(DBG_ERROR, __VA_ARGS__) +#define error(...) __debug(DBG_ERROR, __VA_ARGS__) void die(const char *fmt, ...); -- cgit v1.2.3