raw: Add file declarations in source test files.
[swifty.git] / src / raw / test / debug.h
1 /*
2  * debugging macros
3  *    heavily inspired by previous work and Internet resources
4  *
5  * uses C99 variadic macros
6  * uses non-standard usage of the token-paste operator (##) for
7  *   removing the comma symbol (,) when not followed by a token
8  * uses non-standard __FUNCTION__ macro (MSVC doesn't support __func__)
9  * tested on gcc 4.4.5 and Visual Studio 2008 (9.0), compiler version 15.00
10  *
11  * 2011, Razvan Deaconescu, razvan.deaconescu@cs.pub.ro
12  */
13
14 #ifndef DEBUG_H_
15 #define DEBUG_H_        1
16
17 #ifdef __cplusplus
18 extern "C" {
19 #endif
20
21 #include <stdio.h>
22
23 /* log levels */
24 enum {
25         LOG_EMERG = 1,
26         LOG_ALERT,
27         LOG_CRIT,
28         LOG_ERR,
29         LOG_WARNING,
30         LOG_NOTICE,
31         LOG_INFO,
32         LOG_DEBUG
33 };
34
35 /*
36  * initialize default loglevel (for dlog)
37  * may be redefined in the including code
38  */
39
40 #ifndef LOG_LEVEL
41 #define LOG_LEVEL       LOG_WARNING
42 #endif
43
44 /*
45  * define DEBUG macro as a compiler option:
46  *    -DDEBUG for GCC
47  *    /DDEBUG for MSVC
48  */
49
50 #if defined DEBUG
51 #define dprintf(format, ...)                                    \
52         fprintf(stderr, " [%s(), %s:%u] " format,               \
53                         __FUNCTION__, __FILE__, __LINE__,       \
54                         ##__VA_ARGS__)
55 #else
56 #define dprintf(format, ...)                                    \
57         do {                                                    \
58         } while (0)
59 #endif
60
61 #if defined DEBUG
62 #define dlog(level, format, ...)                                \
63         do {                                                    \
64                 if (level <= LOG_LEVEL)                         \
65                         dprintf(format, ##__VA_ARGS__);         \
66         } while (0)
67 #else
68 #define dlog(level, format, ...)                                \
69         do {                                                    \
70         } while (0)
71 #endif
72
73 #ifdef __cplusplus
74 }
75 #endif
76
77 #endif