-
Notifications
You must be signed in to change notification settings - Fork 4
/
cbug.h
96 lines (82 loc) · 4.49 KB
/
cbug.h
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/* INFO ************************************************************************
** **
** cutils **
** ====== **
** **
** Modern and Lightweight C Utilities **
** Version: 0.8.90.788 (20140826) **
** **
** File: cbug.h **
** **
** For more information about the project, visit <http://www.cutils.org>. **
** Copyright (C) 2014 Peter Varo **
** **
** This program is free software: you can redistribute it and/or modify it **
** under the terms of the GNU General Public License as published by the **
** Free Software Foundation, either version 3 of the License, or **
** (at your option) any later version. **
** **
** This program is distributed in the hope that it will be useful, but **
** WITHOUT ANY WARRANTY; without even the implied warranty of **
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. **
** See the GNU General Public License for more details. **
** **
** You should have received a copy of the GNU General Public License **
** along with this program, most likely a file in the root directory, **
** called 'LICENSE'. If not, see <http://www.gnu.org/licenses>. **
** **
************************************************************************ INFO */
#ifndef _C_DEBUG_H_10629572188582681_
#define _C_DEBUG_H_10629572188582681_
/* TODO: sdebug() -> expands to string literal or
debugexc(func, msg, len) -> calls raise() or ccraise() */
#ifndef CBUG_OFF
#include <stdio.h> /* fprintf(), stderr */
#include "carg.h" /* vargs() */
/* Make macro variables available */
#undef __space
#undef __tab
#undef __debug0
#undef __debug1
#undef __debug2
#undef cutils_cbug_debug
/* Base function */
static inline void
__debug_9802738545513323(const char *file_name,
unsigned int line_number,
const char *function_name)
{
static size_t counter = 0;
fprintf(stderr, "%03zu\tFile: '%s', line: %d, function: '%s'\n",
counter++, file_name, line_number, function_name);
}
/* White spaces */
#define __space " "
#define __tab __space __space __space __space
/* Generic debug information */
#define __debug0() (__debug_9802738545513323(__FILE__, __LINE__, __func__))
/* Generic debug information + simple string */
#define __debug1(str) \
do { __debug0(); fprintf(stderr, __tab "%s\n", str); } while(0)
/* Generic debug information + formatted string */
#define __debug2(fmt, ...) \
do { __debug0(); fprintf(stderr, __tab fmt "\n", __VA_ARGS__); } while (0)
/* Debug dispatcher */
#define cutils_cbug_debug(...) cutils_carg_vargs(__VA_ARGS__)(64)(__VA_ARGS__, \
__debug0,__debug2,__debug2,__debug2,__debug2,__debug2,__debug2,__debug2, \
__debug2,__debug2,__debug2,__debug2,__debug2,__debug2,__debug2,__debug2, \
__debug2,__debug2,__debug2,__debug2,__debug2,__debug2,__debug2,__debug2, \
__debug2,__debug2,__debug2,__debug2,__debug2,__debug2,__debug2,__debug2, \
__debug2,__debug2,__debug2,__debug2,__debug2,__debug2,__debug2,__debug2, \
__debug2,__debug2,__debug2,__debug2,__debug2,__debug2,__debug2,__debug2, \
__debug2,__debug2,__debug2,__debug2,__debug2,__debug2,__debug2,__debug2, \
__debug2,__debug2,__debug2,__debug2,__debug2,__debug2,__debug2,__debug1) \
(__VA_ARGS__)
#else
#undef cutils_cbug_debug
#define cutils_cbug_debug(...)
#endif /* CBUG_OFF */
/* Format value into boolean representation */
#undef cutils_cbug_boolean
#define cutils_cbug_boolean(value) (value ? "true" : "false")
#endif /* _C_DEBUG_H_10629572188582681_ */