From 689e1f1f5584467465b5c16610bec6bbf59df9a7 Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Mon, 28 Dec 2015 07:30:48 +0100 Subject: [PATCH] Change the format for error and warning messages. Use the same format as used for printing the error and warning messages from libdivecomputer itself. --- examples/utils.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/examples/utils.h b/examples/utils.h index 7562beb..da8a65b 100644 --- a/examples/utils.h +++ b/examples/utils.h @@ -26,13 +26,20 @@ extern "C" { #endif /* __cplusplus */ +#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) +#define FUNCTION __func__ +#else +#define FUNCTION __FUNCTION__ +#endif + #if defined(__GNUC__) #define ATTR_FORMAT_PRINTF(a,b) __attribute__((format(printf, a, b))) #else #define ATTR_FORMAT_PRINTF(a,b) #endif -#define WARNING(expr) message ("%s:%d: %s\n", __FILE__, __LINE__, expr) +#define WARNING(expr) message("WARNING: %s [in %s:%d (%s)]\n", expr, __FILE__, __LINE__, FUNCTION) +#define ERROR(expr) message("ERROR: %s [in %s:%d (%s)]\n", expr, __FILE__, __LINE__, FUNCTION) int message (const char* fmt, ...) ATTR_FORMAT_PRINTF(1, 2);