summaryrefslogtreecommitdiff
path: root/testing/misc_tools.h
diff options
context:
space:
mode:
authorKonstantin Kowalski <kostyakow42@gmail.com>2013-08-06 16:47:15 -0400
committerKonstantin Kowalski <kostyakow42@gmail.com>2013-08-06 16:47:15 -0400
commit3dfaa464ac008ac1f3f0e87be55d2918e6f6b667 (patch)
treeabdb615a0186323872155cc147430f607dbc47df /testing/misc_tools.h
parent543b129ba72210c54abd7bf7a898e3f02a136e25 (diff)
Added ERROR() and WARNING() for debugging.
Diffstat (limited to 'testing/misc_tools.h')
-rw-r--r--testing/misc_tools.h37
1 files changed, 34 insertions, 3 deletions
diff --git a/testing/misc_tools.h b/testing/misc_tools.h
index 4e09d40d..eb09693e 100644
--- a/testing/misc_tools.h
+++ b/testing/misc_tools.h
@@ -26,9 +26,40 @@
26 26
27unsigned char * hex_string_to_bin(char hex_string[]); 27unsigned char * hex_string_to_bin(char hex_string[]);
28 28
29 29/* WARNING(msg) takes a printf()-styled string and prints it
30 30 * with some additional details.
31 31 * ERROR(exit_status, msg) does the same thing as WARNING(), but
32 * also exits the program with the given exit status.
33 * Examples:
34 * WARNING("<insert warning message here>");
35 * int exit_status = 2;
36 * ERROR(exit_status, "exiting with status %i", exit_status);
37 */
38#ifdef DEBUG
39 #include <assert.h>
40 #include <stdio.h>
41 #include <string.h>
42
43 #define DEBUG_PRINT(str, ...) do { \
44 char msg[1000]; \
45 sprintf(msg, "%s(): line %d (file %s): %s%%c\n", __FUNCTION__, __LINE__, __FILE__, str); \
46 fprintf(stderr, msg, __VA_ARGS__); \
47 } while (0)
48
49 #define WARNING(...) do { \
50 fprintf(stderr, "warning in "); \
51 DEBUG_PRINT(__VA_ARGS__, ' '); \
52 } while (0)
53
54 #define ERROR(exit_status, ...) do { \
55 fprintf(stderr, "error in "); \
56 DEBUG_PRINT(__VA_ARGS__, ' '); \
57 exit(exit_status); \
58 } while (0)
59#else
60 #define WARNING(...)
61 #define ERROR(...)
62#endif // DEBUG
32 63
33/************************Linked List*********************** 64/************************Linked List***********************
34 * This is a simple linked list implementation, very similar 65 * This is a simple linked list implementation, very similar