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
|
/* base library internal error checking system */
#ifndef BASE_ERROR_H
#define BASE_ERROR_H
#define error_at(msg) \
do { \
write_string(STDERR_FD, Red "[ERROR] " __FILE__ ":"); \
write_int(STDERR_FD, __LINE__); \
write_string(STDERR_FD, ":" __func__ ": " Reset); \
write_string(STDERR_FD, (msg)); \
write_string(STDERR_FD, "\n"); \
} while (0)
#define warn(msg) \
do { \
write_string(STDERR_FD, Yellow "[WARN] " __FILE__ ":"); \
write_int(STDERR_FD, __LINE__); \
write_string(STDERR_FD, ":" __func__ ": " Reset); \
write_string(STDERR_FD, (msg)); \
write_string(STDERR_FD, "\n"); \
} while (0)
#define assert_msg(expr, msg) \
do { \
if (!(expr)) { \
write_string(STDERR_FD, Red "[ERROR] " __FILE__ ":"); \
write_int(STDERR_FD, __LINE__); \
write_string(STDERR_FD, ":" __func__ ": " Reset); \
write_string(STDERR_FD, (msg)); \
write_string(STDERR_FD, "\n"); \
_exit(1); \
} \
} while (0)
#define show \
do { \
write_string(STDOUT_FD, __FILE__ ":"); \
write_int(STDOUT_FD, __LINE__); \
write_string(STDOUT_FD, ":" __func__ "\n"); \
} while (0)
#define test(expr) \
do { \
if ((expr) != 0) { \
write_string(STDERR_FD, "[FAILED] " __FILE__ ":"); \
write_int(STDERR_FD, __LINE__); \
write_string(STDERR_FD, ":" __func__ "\n"); \
_exit(1); \
} \
} while (0)
#define verify(expr) \
do { \
if ((expr) != 0) { \
write_string(STDERR_FD, Red "[ERROR] " __FILE__ ":"); \
write_int(STDERR_FD, __LINE__); \
write_string(STDERR_FD, ":" __func__ "\n" Reset); \
_exit(1); \
} else { \
write_string(STDERR_FD, Green "[OK] " __FILE__ ":"); \
write_int(STDERR_FD, __LINE__); \
write_string(STDERR_FD, ":" __func__ "\n" Reset); \
} \
} while (0)
#endif /* BASE_ERROR_H */
|