From 8a1f5ee34c782dc585a339007878fb4a7407e3d2 Mon Sep 17 00:00:00 2001 From: Xiang Xiao Date: Mon, 4 May 2020 18:52:59 +0800 Subject: [PATCH] debug: Reduce CONFIG_CPP_HAVE_VARARGS usage Signed-off-by: Xiang Xiao --- examples/elf/elf_main.c | 29 ++++--------- examples/ft80x/ft80x.h | 58 ++++++++++--------------- examples/nxflat/nxflat_main.c | 29 ++++--------- examples/posix_spawn/spawn_main.c | 20 +++------ fsutils/inifile/inifile.c | 38 ++++++---------- graphics/ft80x/ft80x.h | 58 ++++++++++--------------- graphics/nxwm/src/cmediaplayer.cxx | 14 ------ graphics/nxwm/src/ctouchscreen.cxx | 19 -------- netutils/thttpd/fdwatch.c | 18 ++------ system/cle/cle.c | 36 +++++---------- system/i2c/i2ctool.h | 4 -- system/spi/spitool.h | 4 -- system/vi/vi.c | 70 ++++++------------------------ system/zmodem/zm.h | 13 ++---- 14 files changed, 110 insertions(+), 300 deletions(-) diff --git a/examples/elf/elf_main.c b/examples/elf/elf_main.c index 8c1593516..5ddf81b21 100644 --- a/examples/elf/elf_main.c +++ b/examples/elf/elf_main.c @@ -105,28 +105,15 @@ * that the output will be synchronous with the debug output. */ -#ifdef CONFIG_CPP_HAVE_VARARGS -# ifdef CONFIG_DEBUG_INFO -# define message(format, ...) syslog(LOG_INFO, format, ##__VA_ARGS__) -# else -# define message(format, ...) printf(format, ##__VA_ARGS__) -# endif -# ifdef CONFIG_DEBUG_ERROR -# define errmsg(format, ...) syslog(LOG_ERR, format, ##__VA_ARGS__) -# else -# define errmsg(format, ...) fprintf(stderr, format, ##__VA_ARGS__) -# endif +#ifdef CONFIG_DEBUG_INFO +# define message _info #else -# ifdef CONFIG_DEBUG_INFO -# define message _info -# else -# define message printf -# endif -# ifdef CONFIG_DEBUG_ERROR -# define errmsg _err -# else -# define errmsg printf -# endif +# define message printf +#endif +#ifdef CONFIG_DEBUG_ERROR +# define errmsg _err +#else +# define errmsg printf #endif /**************************************************************************** diff --git a/examples/ft80x/ft80x.h b/examples/ft80x/ft80x.h index ca9438de8..110b80ea5 100644 --- a/examples/ft80x/ft80x.h +++ b/examples/ft80x/ft80x.h @@ -56,45 +56,31 @@ * Could be a porting issue. */ -#ifdef CONFIG_CPP_HAVE_VARARGS -# ifdef GRAPHICS_FT80X_DEBUG_ERROR -# define ft80x_err(format, ...) \ - fprintf(stderr, EXTRA_FMT format EXTRA_ARG, ##__VA_ARGS__) -# else -# define ft80x_err(format, ...) -# endif - -# ifdef GRAPHICS_FT80X_DEBUG_WARN -# define ft80x_warn(format, ...) \ - fprintf(stderr, EXTRA_FMT format EXTRA_ARG, ##__VA_ARGS__) -# else -# define ft80x_warn(format, ...) -# endif - -# ifdef GRAPHICS_FT80X_DEBUG_INFO -# define ft80x_info(format, ...) \ - printf(EXTRA_FMT format EXTRA_ARG, ##__VA_ARGS__) -# else -# define ft80x_info(format, ...) -# endif +#if !defined(GRAPHICS_FT80X_DEBUG_ERROR) +# define ft80x_err _none +#elif defined(CONFIG_CPP_HAVE_VARARGS) +# define ft80x_err(format, ...) \ + fprintf(stderr, EXTRA_FMT format EXTRA_ARG, ##__VA_ARGS__) #else -# ifdef GRAPHICS_FT80X_DEBUG_ERROR -# define ft80x_err printf -# else -# define ft80x_err (void) -# endif +# define ft80x_err printf +#endif -# ifdef GRAPHICS_FT80X_DEBUG_WARN -# define ft80x_warn printf -# else -# define ft80x_warn (void) -# endif +#if !defined(GRAPHICS_FT80X_DEBUG_WARN) +# define ft80x_warn _none +#elif defined(CONFIG_CPP_HAVE_VARARGS) +# define ft80x_warn(format, ...) \ + fprintf(stderr, EXTRA_FMT format EXTRA_ARG, ##__VA_ARGS__) +#else +# define ft80x_warn printf +#endif -# ifdef GRAPHICS_FT80X_DEBUG_INFO -# define ft80x_info printf -# else -# define ft80x_info (void) -# endif +#if !defined(GRAPHICS_FT80X_DEBUG_INFO) +# define ft80x_info _none +#elif defined(CONFIG_CPP_HAVE_VARARGS) +# define ft80x_info(format, ...) \ + printf(EXTRA_FMT format EXTRA_ARG, ##__VA_ARGS__) +#else +# define ft80x_info printf #endif /**************************************************************************** diff --git a/examples/nxflat/nxflat_main.c b/examples/nxflat/nxflat_main.c index 5001f3aee..2d1620ab9 100644 --- a/examples/nxflat/nxflat_main.c +++ b/examples/nxflat/nxflat_main.c @@ -96,28 +96,15 @@ * that the output will be synchronous with the debug output. */ -#ifdef CONFIG_CPP_HAVE_VARARGS -# ifdef CONFIG_DEBUG_INFO -# define message(format, ...) syslog(LOG_INFO, format, ##__VA_ARGS__) -# else -# define message(format, ...) printf(format, ##__VA_ARGS__) -# endif -# ifdef CONFIG_DEBUG_ERROR -# define errmsg(format, ...) syslog(LOG_ERR, format, ##__VA_ARGS__) -# else -# define errmsg(format, ...) fprintf(stderr, format, ##__VA_ARGS__) -# endif +#ifdef CONFIG_DEBUG_INFO +# define message _info #else -# ifdef CONFIG_DEBUG_INFO -# define message _info -# else -# define message printf -# endif -# ifdef CONFIG_DEBUG_ERROR -# define errmsg _err -# else -# define errmsg printf -# endif +# define message printf +#endif +#ifdef CONFIG_DEBUG_ERROR +# define errmsg _err +#else +# define errmsg printf #endif /**************************************************************************** diff --git a/examples/posix_spawn/spawn_main.c b/examples/posix_spawn/spawn_main.c index 6316f5886..add4d2d83 100644 --- a/examples/posix_spawn/spawn_main.c +++ b/examples/posix_spawn/spawn_main.c @@ -96,22 +96,12 @@ * that the output will be synchronous with the debug output. */ -#ifdef CONFIG_CPP_HAVE_VARARGS -# ifdef CONFIG_DEBUG_FEATURES -# define message(format, ...) _info(format, ##__VA_ARGS__) -# define errmsg(format, ...) _err(format, ##__VA_ARGS__) -# else -# define message(format, ...) printf(format, ##__VA_ARGS__) -# define errmsg(format, ...) fprintf(stderr, format, ##__VA_ARGS__) -# endif +#ifdef CONFIG_DEBUG_FEATURES +# define message _info +# define errmsg _err #else -# ifdef CONFIG_DEBUG_FEATURES -# define message _info -# define errmsg _err -# else -# define message printf -# define errmsg printf -# endif +# define message printf +# define errmsg printf #endif /**************************************************************************** diff --git a/fsutils/inifile/inifile.c b/fsutils/inifile/inifile.c index 6707abf92..75098f61a 100644 --- a/fsutils/inifile/inifile.c +++ b/fsutils/inifile/inifile.c @@ -60,32 +60,22 @@ # define CONFIG_FSUTILS_INIFILE_DEBUGLEVEL 0 #endif -#ifdef CONFIG_CPP_HAVE_VARARGS -# if CONFIG_FSUTILS_INIFILE_DEBUGLEVEL > 0 -# define inidbg(format, ...) \ - printf(EXTRA_FMT format EXTRA_ARG, ##__VA_ARGS__) -# else -# define inidbg(x...) -# endif - -# if CONFIG_FSUTILS_INIFILE_DEBUGLEVEL > 1 -# define iniinfo(format, ...) \ - printf(EXTRA_FMT format EXTRA_ARG, ##__VA_ARGS__) -# else -# define iniinfo(x...) -# endif +#if CONFIG_FSUTILS_INIFILE_DEBUGLEVEL < 1 +# define inidbg _none +#elif defined(CONFIG_CPP_HAVE_VARARGS) +# define inidbg(format, ...) \ + printf(EXTRA_FMT format EXTRA_ARG, ##__VA_ARGS__) #else -# if CONFIG_FSUTILS_INIFILE_DEBUGLEVEL > 0 -# define inidbg printf -# else -# define inidbg (void) -# endif +# define inidbg printf +#endif -# if CONFIG_FSUTILS_INIFILE_DEBUGLEVEL > 1 -# define iniinfo printf -# else -# define iniinfo (void) -# endif +#if CONFIG_FSUTILS_INIFILE_DEBUGLEVEL < 2 +# define iniinfo _none +#elif defined(CONFIG_CPP_HAVE_VARARGS) +# define iniinfo(format, ...) \ + printf(EXTRA_FMT format EXTRA_ARG, ##__VA_ARGS__) +#else +# define iniinfo printf #endif /**************************************************************************** diff --git a/graphics/ft80x/ft80x.h b/graphics/ft80x/ft80x.h index fa2224c83..cbfcb883e 100644 --- a/graphics/ft80x/ft80x.h +++ b/graphics/ft80x/ft80x.h @@ -57,45 +57,31 @@ * Could be a porting issue. */ -#ifdef CONFIG_CPP_HAVE_VARARGS -# ifdef CONFIG_GRAPHICS_FT80X_DEBUG_ERROR -# define ft80x_err(format, ...) \ - fprintf(stderr, EXTRA_FMT format EXTRA_ARG, ##__VA_ARGS__) -# else -# define ft80x_err(format, ...) -# endif - -# ifdef CONFIG_GRAPHICS_FT80X_DEBUG_WARN -# define ft80x_warn(format, ...) \ - fprintf(stderr, EXTRA_FMT format EXTRA_ARG, ##__VA_ARGS__) -# else -# define ft80x_warn(format, ...) -# endif - -# ifdef CONFIG_GRAPHICS_FT80X_DEBUG_INFO -# define ft80x_info(format, ...) \ - printf(EXTRA_FMT format EXTRA_ARG, ##__VA_ARGS__) -# else -# define ft80x_info(format, ...) -# endif +#if !defined(CONFIG_GRAPHICS_FT80X_DEBUG_ERROR) +# define ft80x_err _none +#elif defined(CONFIG_CPP_HAVE_VARARGS) +# define ft80x_err(format, ...) \ + fprintf(stderr, EXTRA_FMT format EXTRA_ARG, ##__VA_ARGS__) #else -# ifdef CONFIG_GRAPHICS_FT80X_DEBUG_ERROR -# define ft80x_err printf -# else -# define ft80x_err (void) -# endif +# define ft80x_err printf +#endif -# ifdef CONFIG_GRAPHICS_FT80X_DEBUG_WARN -# define ft80x_warn printf -# else -# define ft80x_warn (void) -# endif +#if !defined(CONFIG_GRAPHICS_FT80X_DEBUG_WARN) +# define ft80x_warn _none +#elif defined(CONFIG_CPP_HAVE_VARARGS) +# define ft80x_warn(format, ...) \ + fprintf(stderr, EXTRA_FMT format EXTRA_ARG, ##__VA_ARGS__) +#else +# define ft80x_warn printf +#endif -# ifdef CONFIG_GRAPHICS_FT80X_DEBUG_INFO -# define ft80x_info printf -# else -# define ft80x_info (void) -# endif +#if !defined(CONFIG_GRAPHICS_FT80X_DEBUG_INFO) +# define ft80x_info _none +#elif defined(CONFIG_CPP_HAVE_VARARGS) +# define ft80x_info(format, ...) \ + printf(EXTRA_FMT format EXTRA_ARG, ##__VA_ARGS__) +#else +# define ft80x_info printf #endif #define FT80X_CMDFIFO_MASK (FT80X_CMDFIFO_SIZE - 1) diff --git a/graphics/nxwm/src/cmediaplayer.cxx b/graphics/nxwm/src/cmediaplayer.cxx index 1e5d36767..4c32f993b 100644 --- a/graphics/nxwm/src/cmediaplayer.cxx +++ b/graphics/nxwm/src/cmediaplayer.cxx @@ -63,20 +63,6 @@ * Pre-Processor Definitions ********************************************************************************************/ -/* We want debug output from this file if either audio or graphics debug is enabled. */ - -#if !defined(CONFIG_DEBUG_AUDIO) && !defined(CONFIG_DEBUG_GRAPHICS) -# undef gerr -# undef _info -# ifdef CONFIG_CPP_HAVE_VARARGS -# define gerr(x...) -# define _info(x...) -# else -# define gerr (void) -# define _info (void) -# endif -#endif - #define AUDIO_NSUBSAMPLES 4 /******************************************************************************************** diff --git a/graphics/nxwm/src/ctouchscreen.cxx b/graphics/nxwm/src/ctouchscreen.cxx index 19253b2ac..b7e279cc5 100644 --- a/graphics/nxwm/src/ctouchscreen.cxx +++ b/graphics/nxwm/src/ctouchscreen.cxx @@ -60,25 +60,6 @@ #include "graphics/nxglyphs.hxx" #include "graphics/nxwm/ctouchscreen.hxx" -/******************************************************************************************** - * Pre-Processor Definitions - ********************************************************************************************/ -/* We want debug output from this file if either input/touchscreen or graphics debug is - * enabled. - */ - -#if !defined(CONFIG_DEBUG_INPUT) && !defined(CONFIG_DEBUG_GRAPHICS) -# undef gerr -# undef _info -# ifdef CONFIG_CPP_HAVE_VARARGS -# define gerr(x...) -# define _info(x...) -# else -# define gerr (void) -# define _info (void) -# endif -#endif - /******************************************************************************************** * CTouchscreen Method Implementations ********************************************************************************************/ diff --git a/netutils/thttpd/fdwatch.c b/netutils/thttpd/fdwatch.c index 0706aafcc..ed1880d25 100644 --- a/netutils/thttpd/fdwatch.c +++ b/netutils/thttpd/fdwatch.c @@ -61,21 +61,11 @@ */ #ifdef CONFIG_THTTPD_FDWATCH_DEBUG -# ifdef CONFIG_CPP_HAVE_VARARGS -# define fwerr(format, ...) nerr(format, ##__VA_ARGS__) -# define fwinfo(format, ...) ninfo(format, ##__VA_ARGS__) -# else -# define fwerr nerr -# define fwinfo ninfo -# endif +# define fwerr nerr +# define fwinfo ninfo #else -# ifdef CONFIG_CPP_HAVE_VARARGS -# define fwerr(x...) -# define fwinfo(x...) -# else -# define fwerr (void) -# define fwinfo (void) -# endif +# define fwerr _none +# define fwinfo _none #endif #ifndef MIN diff --git a/system/cle/cle.c b/system/cle/cle.c index bb3937131..f2e0cfd7f 100644 --- a/system/cle/cle.c +++ b/system/cle/cle.c @@ -106,32 +106,16 @@ # define CONFIG_SYSTEM_CLE_DEBUGLEVEL 0 #endif -#ifdef CONFIG_CPP_HAVE_VARARGS -# if CONFIG_SYSTEM_CLE_DEBUGLEVEL > 0 -# define cledbg(format, ...) \ - syslog(LOG_DEBUG, EXTRA_FMT format EXTRA_ARG, ##__VA_ARGS__) -# else -# define cledbg(x...) -# endif - -# if CONFIG_SYSTEM_CLE_DEBUGLEVEL > 1 -# define cleinfo(format, ...) \ - syslog(LOG_DEBUG, EXTRA_FMT format EXTRA_ARG, ##__VA_ARGS__) -# else -# define cleinfo(x...) -# endif +#if CONFIG_SYSTEM_CLE_DEBUGLEVEL > 0 +# define cledbg cle_debug #else -# if CONFIG_SYSTEM_CLE_DEBUGLEVEL > 0 -# define cledbg cle_debug -# else -# define cledbg (void) -# endif +# define cledbg _none +#endif -# if CONFIG_SYSTEM_CLE_DEBUGLEVEL > 1 -# define cleinfo cle_debug -# else -# define cleinfo (void) -# endif +#if CONFIG_SYSTEM_CLE_DEBUGLEVEL > 1 +# define cleinfo cle_debug +#else +# define cleinfo _none #endif #ifdef CONFIG_SYSTEM_COLOR_CLE @@ -182,7 +166,7 @@ struct cle_s * Private Function Prototypes ****************************************************************************/ -#if !defined(CONFIG_CPP_HAVE_VARARGS) && CONFIG_SYSTEM_CLE_DEBUGLEVEL > 0 +#if CONFIG_SYSTEM_CLE_DEBUGLEVEL > 0 static int cle_debug(FAR const char *fmt, ...); #endif @@ -262,7 +246,7 @@ static const char g_setcolor[] = VT100_FMT_FORE_COLOR; * ****************************************************************************/ -#if !defined(CONFIG_CPP_HAVE_VARARGS) && CONFIG_SYSTEM_CLE_DEBUGLEVEL > 0 +#if CONFIG_SYSTEM_CLE_DEBUGLEVEL > 0 static int cle_debug(FAR const char *fmt, ...) { va_list ap; diff --git a/system/i2c/i2ctool.h b/system/i2c/i2ctool.h index 3cf7cce5a..b90113573 100644 --- a/system/i2c/i2ctool.h +++ b/system/i2c/i2ctool.h @@ -127,11 +127,7 @@ /* Output is via printf but can be changed using this macro */ -#ifdef CONFIG_CPP_HAVE_VARARGS -# define i2c_output(v, ...) printf(v, ##__VA_ARGS__) -#else # define i2c_output printf -#endif /**************************************************************************** * Public Types diff --git a/system/spi/spitool.h b/system/spi/spitool.h index 211f4ffdd..e545cb65c 100644 --- a/system/spi/spitool.h +++ b/system/spi/spitool.h @@ -131,11 +131,7 @@ /* Output is via printf but can be changed using this macro */ -#ifdef CONFIG_CPP_HAVE_VARARGS -# define spi_output(v, ...) printf(v, ##__VA_ARGS__) -#else # define spi_output printf -#endif /**************************************************************************** * Public Types diff --git a/system/vi/vi.c b/system/vi/vi.c index d6e292738..272a7f344 100644 --- a/system/vi/vi.c +++ b/system/vi/vi.c @@ -170,37 +170,21 @@ # define CONFIG_SYSTEM_VI_DEBUGLEVEL 0 #endif -#ifdef CONFIG_CPP_HAVE_VARARGS -# if CONFIG_SYSTEM_VI_DEBUGLEVEL > 0 -# define vidbg(format, ...) \ - syslog(LOG_DEBUG, EXTRA_FMT format EXTRA_ARG, ##__VA_ARGS__) -# define vvidbg(format, ap) \ - vsyslog(LOG_DEBUG, format, ap) -# else -# define vidbg(x...) -# define vvidbg(x...) -# endif - -# if CONFIG_SYSTEM_VI_DEBUGLEVEL > 1 -# define viinfo(format, ...) \ - syslog(LOG_DEBUG, EXTRA_FMT format EXTRA_ARG, ##__VA_ARGS__) -# else -# define viinfo(x...) -# endif +#if CONFIG_SYSTEM_VI_DEBUGLEVEL > 0 +# define vidbg(format, ...) \ + syslog(LOG_DEBUG, EXTRA_FMT format EXTRA_ARG, ##__VA_ARGS__) +# define vvidbg(format, ap) \ + vsyslog(LOG_DEBUG, format, ap) #else -# if CONFIG_SYSTEM_VI_DEBUGLEVEL > 0 -# define vidbg vi_debug -# define vvidbg vi_vdebug -# else -# define vidbg (void) -# define vvidbg (void) -# endif +# define vidbg(x...) +# define vvidbg(x...) +#endif -# if CONFIG_SYSTEM_VI_DEBUGLEVEL > 1 -# define viinfo vi_debug -# else -# define viinfo (void) -# endif +#if CONFIG_SYSTEM_VI_DEBUGLEVEL > 1 +# define viinfo(format, ...) \ + syslog(LOG_DEBUG, EXTRA_FMT format EXTRA_ARG, ##__VA_ARGS__) +#else +# define viinfo(x...) #endif /* Uncomment to enable bottom line debug printing. Useful during yank / @@ -576,34 +560,6 @@ static const char g_fmtinsert[] = "--INSERT--"; * Private Functions ****************************************************************************/ -/**************************************************************************** - * Name: vi_vdebug and vi_debug - * - * Description: - * Print a debug message to the syslog - * - ****************************************************************************/ - -#if !defined(CONFIG_CPP_HAVE_VARARGS) && CONFIG_SYSTEM_VI_DEBUGLEVEL > 0 -static inline int vi_vdebug(FAR const char *fmt, va_list ap) -{ - return vsyslog(LOG_DEBUG, fmt, ap); -} - -static int vi_debug(FAR const char *fmt, ...) -{ - va_list ap; - int ret; - - /* Let vsyslog do the real work */ - - va_start(ap, fmt); - ret = vsyslog(LOG_DEBUG, fmt, ap); - va_end(ap); - return ret; -} -#endif - /**************************************************************************** * Low-level display and data entry functions ****************************************************************************/ diff --git a/system/zmodem/zm.h b/system/zmodem/zm.h index d99a281dd..822f9e901 100644 --- a/system/zmodem/zm.h +++ b/system/zmodem/zm.h @@ -230,17 +230,12 @@ */ #ifdef CONFIG_DEBUG_ZMODEM -# define zmprintf(format, ...) syslog(LOG_INFO, format, ##__VA_ARGS__) -# define zmdbg(format, ...) syslog(LOG_INFO, EXTRA_FMT format EXTRA_ARG, ##__VA_ARGS__) +# define zmprintf(format, ...) _info +# define zmdbg(format, ...) _info #else # undef CONFIG_SYSTEM_ZMODEM_DUMPBUFFER -# ifdef CONFIG_CPP_HAVE_VARARGS -# define zmprintf(x...) -# define zmdbg(x...) -# else -# define zmprintf (void) -# define zmdbg (void) -# endif +# define zmprintf _none +# define zmdbg _none #endif /****************************************************************************