diff options
author | Konstantin Kowalski <kostyakow42@gmail.com> | 2013-08-06 16:47:15 -0400 |
---|---|---|
committer | Nick ODell <nickodell@gmail.com> | 2013-08-06 18:11:13 -0600 |
commit | f603342acfdc4196a91e0f2356f2ffb286b02d81 (patch) | |
tree | 8ce91a3e84af65eef89431649f735f86a46aaad2 /testing | |
parent | 60f333328cea995585e7199b1e9fc93dfae53428 (diff) |
Added ERROR() and WARNING() for debugging.
Diffstat (limited to 'testing')
-rw-r--r-- | testing/misc_tools.h | 37 |
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 | ||
27 | unsigned char * hex_string_to_bin(char hex_string[]); | 27 | unsigned 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 |