File: debug.h

package info (click to toggle)
graphviz 14.0.5-2
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 139,388 kB
  • sloc: ansic: 141,938; cpp: 11,957; python: 7,766; makefile: 4,043; yacc: 3,030; xml: 2,972; tcl: 2,495; sh: 1,388; objc: 1,159; java: 560; lex: 423; perl: 243; awk: 156; pascal: 139; php: 58; ruby: 49; cs: 31; sed: 1
file content (39 lines) | stat: -rw-r--r-- 1,926 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/// @file
/// @brief helpers for verbose/debug printing

#pragma once

#include <stddef.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <util/lockfile.h>

/// print an informational message
///
/// This assumes the `Verbose` global is in scope.
#define GV_INFO(...)                                                           \
  do {                                                                         \
    if (Verbose) {                                                             \
      const char *const name_ = strrchr(__FILE__, '/') == NULL                 \
                                    ? __FILE__                                 \
                                    : strrchr(__FILE__, '/') + 1;              \
      lockfile(stderr);                                                        \
      const time_t now_ = time(NULL);                                          \
      const struct tm *const now_tm_ = localtime(&now_);                       \
      fprintf(stderr, "[Graphviz] %s:%d: %04d-%02d-%02d %02d:%02d: ", name_,   \
              __LINE__, now_tm_->tm_year + 1900, now_tm_->tm_mon + 1,          \
              now_tm_->tm_mday, now_tm_->tm_hour, now_tm_->tm_sec);            \
      fprintf(stderr, __VA_ARGS__);                                            \
      fprintf(stderr, "\n");                                                   \
      unlockfile(stderr);                                                      \
    }                                                                          \
  } while (0)

/// print a debug message
///
/// The distinction between this and `GV_INFO` is purely semantic; this is
/// intended for messages for Graphviz developers while `GV_INFO` is intended
/// for messages for Graphviz users. In future, `GV_DEBUG` may use something
/// other than `Verbose` to guard its output.
#define GV_DEBUG(...) GV_INFO(__VA_ARGS__)