From 3dfaa464ac008ac1f3f0e87be55d2918e6f6b667 Mon Sep 17 00:00:00 2001 From: Konstantin Kowalski Date: Tue, 6 Aug 2013 16:47:15 -0400 Subject: Added ERROR() and WARNING() for debugging. --- testing/misc_tools.h | 37 ++++++++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) (limited to 'testing/misc_tools.h') 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 @@ unsigned char * hex_string_to_bin(char hex_string[]); - - - +/* WARNING(msg) takes a printf()-styled string and prints it + * with some additional details. + * ERROR(exit_status, msg) does the same thing as WARNING(), but + * also exits the program with the given exit status. + * Examples: + * WARNING(""); + * int exit_status = 2; + * ERROR(exit_status, "exiting with status %i", exit_status); + */ +#ifdef DEBUG + #include + #include + #include + + #define DEBUG_PRINT(str, ...) do { \ + char msg[1000]; \ + sprintf(msg, "%s(): line %d (file %s): %s%%c\n", __FUNCTION__, __LINE__, __FILE__, str); \ + fprintf(stderr, msg, __VA_ARGS__); \ + } while (0) + + #define WARNING(...) do { \ + fprintf(stderr, "warning in "); \ + DEBUG_PRINT(__VA_ARGS__, ' '); \ + } while (0) + + #define ERROR(exit_status, ...) do { \ + fprintf(stderr, "error in "); \ + DEBUG_PRINT(__VA_ARGS__, ' '); \ + exit(exit_status); \ + } while (0) +#else + #define WARNING(...) + #define ERROR(...) +#endif // DEBUG /************************Linked List*********************** * This is a simple linked list implementation, very similar -- cgit v1.2.3