From f82ba904bd1a28ebf4653d3d3265cb5c8679e9a5 Mon Sep 17 00:00:00 2001 From: Kp Date: Sun, 8 Dec 2013 23:37:40 +0000 Subject: [PATCH] Use Warning_puts instead of Warning where possible --- common/include/dxxerror.h | 3 +++ common/misc/error.cpp | 14 +++++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/common/include/dxxerror.h b/common/include/dxxerror.h index 8eb62fc1d..3c181ee30 100644 --- a/common/include/dxxerror.h +++ b/common/include/dxxerror.h @@ -23,6 +23,7 @@ COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. #include #include "dxxsconf.h" #include +#include "fmtcheck.h" #ifdef __cplusplus @@ -34,7 +35,9 @@ COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. void warn_printf(const char *s); int error_init(void (*func)(const char *)); //init error system, returns 0=ok +void Warning_puts(const char *str) __attribute_nonnull(); void Warning(const char *fmt,...) __attribute_format_printf(1, 2); //print out warning message to user +#define Warning(F,...) dxx_call_printf_checked(Warning,Warning_puts,(),(F),##__VA_ARGS__) void set_warn_func(void (*f)(const char *s));//specifies the function to call with warning messages void clear_warn_func();//say this function no longer valid void Error(const char *func, unsigned line, const char *fmt,...) __noreturn __attribute_format_printf(3, 4); //exit with error code=1, print message diff --git a/common/misc/error.cpp b/common/misc/error.cpp index 5857f5a32..be4f5a9fd 100644 --- a/common/misc/error.cpp +++ b/common/misc/error.cpp @@ -30,8 +30,6 @@ COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. static void (*ErrorPrintFunc)(const char *); -static char warn_message[MAX_MSG_LEN]; - //takes string in register, calls printf with string on stack void warn_printf(const char *s) { @@ -79,14 +77,24 @@ void (Error)(const char *func, const unsigned line, const char *fmt,...) exit(1); } +void Warning_puts(const char *str) +{ + if (warn_func == NULL) + return; + char warn_message[MAX_MSG_LEN]; + snprintf(warn_message, sizeof(warn_message), "Warning: %s", str); + (*warn_func)(warn_message); +} + //print out warning message to user -void Warning(const char *fmt,...) +void (Warning)(const char *fmt,...) { va_list arglist; if (warn_func == NULL) return; + char warn_message[MAX_MSG_LEN]; strcpy(warn_message,"Warning: "); va_start(arglist,fmt);