Debian Codegraph @

lib/util/debug.h

raw
1 /// @file
2 /// @brief helpers for verbose/debug printing
3
4 #pragma once
5
6 #include <stddef.h>
7 #include <stdio.h>
8 #include <string.h>
9 #include <time.h>
10 #include <util/lockfile.h>
11
12 /// print an informational message
13 ///
14 /// This assumes the `Verbose` global is in scope.
15 #define GV_INFO(...) \
16 do { \
17 if (Verbose) { \
18 const char *const name_ = strrchr(__FILE__, '/') == NULL \
19 ? __FILE__ \
20 : strrchr(__FILE__, '/') + 1; \
21 lockfile(stderr); \
22 const time_t now_ = time(NULL); \
23 const struct tm *const now_tm_ = localtime(&now_); \
24 fprintf(stderr, "[Graphviz] %s:%d: %04d-%02d-%02d %02d:%02d: ", name_, \
25 __LINE__, now_tm_->tm_year + 1900, now_tm_->tm_mon + 1, \
26 now_tm_->tm_mday, now_tm_->tm_hour, now_tm_->tm_sec); \
27 fprintf(stderr, __VA_ARGS__); \
28 fprintf(stderr, "\n"); \
29 unlockfile(stderr); \
30 } \
31 } while (0)
32
33 /// print a debug message
34 ///
35 /// The distinction between this and `GV_INFO` is purely semantic; this is
36 /// intended for messages for Graphviz developers while `GV_INFO` is intended
37 /// for messages for Graphviz users. In future, `GV_DEBUG` may use something
38 /// other than `Verbose` to guard its output.
39 #define GV_DEBUG(...) GV_INFO(__VA_ARGS__)