Added ERROR() and WARNING() for debugging.

This commit is contained in:
Konstantin Kowalski 2013-08-06 16:47:15 -04:00 committed by Nick ODell
parent 60f333328c
commit f603342acf

View File

@ -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("<insert warning message here>");
* int exit_status = 2;
* ERROR(exit_status, "exiting with status %i", exit_status);
*/
#ifdef DEBUG
#include <assert.h>
#include <stdio.h>
#include <string.h>
#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