util: Add the trace() debugging macro

Copied from libinput but pushed into util-macros with the color escape
codes expanded for simplicity.

Part-of: <https://gitlab.freedesktop.org/libinput/libei/-/merge_requests/315>
This commit is contained in:
Peter Hutterer 2024-12-02 15:54:32 +10:00 committed by Marge Bot
parent 327dd4f8b1
commit b33317cda0

View file

@ -65,3 +65,10 @@
#define run_only_once \
static int _once_per_##__func__ = 0; \
for (; _once_per_##__func__ == 0; _once_per_##__func__ = 1)
#define trace(...) \
do { \
char buf_[1024]; \
snprintf(buf_, sizeof(buf_), __VA_ARGS__); \
printf("\x1B[0;34m" "%s():%d - " "\x1B[0;31m" "%s" "\x1B[0m" "\n", __func__, __LINE__, buf_); \
} while (0)