-
Notifications
You must be signed in to change notification settings - Fork 0
/
dev.h
144 lines (117 loc) · 5.31 KB
/
dev.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#ifndef __DEV__
#define __DEV__
#define DEV 0
#if 1 == DEV
// ----------------------------------------------------------------------------->
// DEV MODE: ON
// ----------------------------------------------------------------------------->
/* -> DEVELOPMENT/DEBUGGING MACROS
* --------------------------------------------*/
// enabled if `make DEV=1` is used
/*
* Macro:[DEVASSERT]
* Works the same way as ASSERT in shared.h, but only run if dev mode is on
*/
#define DEVASSERT_EXPAND(x) x
#define DEVASSERT(expr) \
do { \
if (!(DEVASSERT_EXPAND(expr))){ \
fprintf(stderr, "\n\n*******\n[ERROR](%s/%s:%d) %s\n*******\n", \
__FILE__, __FUNCTION__, __LINE__, #expr); \
exit(1); \
} \
} while (0);
/*
* Macro:[DEVRUN]
* @param expr - an expression to run
* runs a given expression if DEV==1
*/
#define DEVRUN_EXPAND(x) x
#define DEVRUN(expr) \
do { \
DEVRUN_EXPAND(expr); \
} while (0);
/*
* Macro:[DEVRUNV]
* @param expr - an expression to run
* same as macro:DEVRUN but verbose (prints what it is running)
*/
#define DEVRUNV(expr) \
do { \
fprintf(stderr, "\n\n\n*****************************************\n"); \
fprintf(stderr, "*** [DEV]<%s:%d>\n\n-> Running:\t%s\n\n-> Output:\t", \
__FILE__, __LINE__, #expr); \
DEVRUN_EXPAND(expr); \
fprintf(stderr, "\n*****************************************\n\n\n"); \
} while (0);
/*
* Macro:[DEVRUNVX]
* @param expr - an expression to run
* same as DEVRUNV, but exits after running
*/
#define DEVRUNVX(expr) \
do { \
fprintf(stderr, "\n\n\n*****************************************\n"); \
fprintf(stderr, "*** [DEV]<%s:%d>\n\n-> Running:\t%s\n\n-> Output:\t", \
__FILE__, __LINE__, #expr); \
DEVRUN_EXPAND(expr); \
fprintf(stderr, "\n*****************************************\n\n\n"); \
exit(1); \
} while (0);
/*
*
* Macro:[DEVPRINT]
* @param msg - a message to print
* @details uses variable arguments to print a message to stderr with additional
* info
* @usage DEVPRINT("Hello %s", "World");
* @note VAARGS may not work on all compilers, so only defined in dev mode
*/
#define DEVPRINT(msg, ...) \
do { \
fprintf(stderr, "\n\n\n*****************************************\n"); \
fprintf(stderr, "*** [DEV]<%s:%d>\n\n-> Message:\t", __FILE__, \
__LINE__); \
fprintf(stderr, msg, ##__VA_ARGS__); \
fprintf(stderr, "\n*****************************************\n\n\n"); \
} while (0);
/*
*
* Macro:[DEVPRINTX]
* @param msg - a message to print
* @details same as macro:DEVPRINT, but exits after printing
*/
#define DEVPRINTX(msg, ...) \
do { \
fprintf(stderr, "\n\n\n*****************************************\n"); \
fprintf(stderr, "*** [DEV]<%s:%d>\n\n-> Message:\t", __FILE__, \
__LINE__); \
fprintf(stderr, msg, ##__VA_ARGS__); \
fprintf(stderr, "\n*****************************************\n\n\n"); \
exit(1); \
} while (0);
/*
* Macro:[DEVEND]
* @details defines a development end point
* when reached; prints a message and exits
*/
#define DEVEND \
do{ \
fprintf(stderr, "\n\n\n\n--------------------------------------------------------------------------------\n"); \
fprintf(stderr, "\t-> Reached END at %s:%d", __FILE__, __LINE__); \
fprintf(stderr, "\n--------------------------------------------------------------------------------\n\n\n\n"); \
exit(1); \
} while (0);
#else
// ----------------------------------------------------------------------------->
// DEV MODE: OFF
// ----------------------------------------------------------------------------->
#define DEVASSERT(expr)
#define DEVRUN(expr)
#define DEVRUNX(expr)
#define DEVPRINT(msg, ...)
#define DEVPRINTX(msg, ...)
#define DEVEND
#endif
/* --------------------------------------------------------------------------*/
#endif // __DEV__