From 1af58bb8886673ac115f019094853fa763e79187 Mon Sep 17 00:00:00 2001 From: Nathanael Sensfelder Date: Tue, 1 Sep 2015 22:48:51 +0200 Subject: Initial commit. --- src/error.h | 123 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 123 insertions(+) create mode 100644 src/error.h (limited to 'src/error.h') diff --git a/src/error.h b/src/error.h new file mode 100644 index 0000000..aa85e63 --- /dev/null +++ b/src/error.h @@ -0,0 +1,123 @@ +#ifndef RELABSD_ERROR_H +#define RELABSD_ERROR_H + +#include + +#include "config.h" +#include "pervasive.h" + +#define _HIGHEST_DEBUG_LVL 100 + +#define _DEBUG_LVL _HIGHEST_DEBUG_LVL +#define _ENABLE_WARNINGS_OUTPUT 1 +#define _ENABLE_RUNTIME_ERRORS_OUTPUT 1 +#define _ENABLE_PROGRAMMING_ERRORS_OUTPUT 1 +#define _ENABLE_FATAL_ERROR_OUTPUT 1 +#define _ENABLE_ERROR_LOCATION 0 + +#if _ENABLE_ERROR_LOCATION + #define _LOCATION "[" __FILE__ "][" _TO_STRING(__LINE__) "]" +#else + #define _LOCATION "" +#endif + +#define _PRINT_STDERR(symbol, str, ...)\ + fprintf(stderr, "[" symbol "]" _LOCATION " " str "\n", __VA_ARGS__); + +#define _DEBUG(level, str, ...)\ + _ISOLATE\ + (\ + if (level < _DEBUG_LVL)\ + {\ + _PRINT_STDERR("D", str, __VA_ARGS__);\ + }\ + ) + + +#define _WARNING(str, ...)\ + _ISOLATE\ + (\ + if (_ENABLE_WARNINGS_OUTPUT)\ + {\ + _PRINT_STDERR("W", str, __VA_ARGS__);\ + }\ + ) + +#define _ERROR(str, ...)\ + _ISOLATE\ + (\ + if (_ENABLE_RUNTIME_ERRORS_OUTPUT)\ + {\ + _PRINT_STDERR("E", str, __VA_ARGS__);\ + }\ + ) + +#define _PROG_ERROR(str, ...)\ + _ISOLATE\ + (\ + if (_ENABLE_PROGRAMMING_ERRORS_OUTPUT)\ + {\ + _PRINT_STDERR("P", str, __VA_ARGS__);\ + }\ + ) + +#define _FATAL(str, ...)\ + _ISOLATE\ + (\ + if (_ENABLE_FATAL_ERROR_OUTPUT)\ + {\ + _PRINT_STDERR("F", str, __VA_ARGS__);\ + }\ + ) + +/* For outputs without dynamic content (static). ******************************/ + +#define _PRINT_S_STDERR(symbol, str)\ + fprintf(stderr, "[" symbol "]" _LOCATION " " str "\n"); + +#define _S_DEBUG(level, str)\ + _ISOLATE\ + (\ + if (level < _DEBUG_LVL)\ + {\ + _PRINT_S_STDERR("D", str);\ + }\ + ) + +#define _S_WARNING(str)\ + _ISOLATE\ + (\ + if (_ENABLE_WARNINGS_OUTPUT)\ + {\ + _PRINT_S_STDERR("W", str);\ + }\ + ) + +#define _S_ERROR(str)\ + _ISOLATE\ + (\ + if (_ENABLE_RUNTIME_ERRORS_OUTPUT)\ + {\ + _PRINT_S_STDERR("E", str);\ + }\ + ) + +#define _S_PROG_ERROR(str)\ + _ISOLATE\ + (\ + if (_ENABLE_PROGRAMMING_ERRORS_OUTPUT)\ + {\ + _PRINT_S_STDERR("P", str);\ + }\ + ) + +#define _S_FATAL(str)\ + _ISOLATE\ + (\ + if (_ENABLE_FATAL_ERROR_OUTPUT)\ + {\ + _PRINT_S_STDERR("F", str);\ + }\ + ) + +#endif -- cgit v1.2.3-70-g09d2