nshlib/nsh_console.h: Add nsh_none, where any empty output can be forwarded

Add nsh_none to consume all empty traces from nsh.

For the variadic argument case need to add a (inline) function to eat
away the __VA_ARGS__ list, there is no good / portable way to do this by
pre-processor macros, but a function will eat the variadic list whatever
its size is.
This commit is contained in:
Ville Juven 2023-08-24 13:26:20 +03:00 committed by Xiang Xiao
parent 1668c3e97d
commit 94d477b3df

View File

@ -51,20 +51,19 @@
#define nsh_exit(v,s) (v)->exit(v,s)
#ifdef CONFIG_CPP_HAVE_VARARGS
# define nsh_error(v, ...) (v)->error(v, ##__VA_ARGS__)
# define nsh_output(v, ...) (v)->output(v, ##__VA_ARGS__)
# define nsh_error(v, ...) (v)->error(v, ##__VA_ARGS__)
# define nsh_output(v, ...) (v)->output(v, ##__VA_ARGS__)
# define nsh_none(v, ...) \
do { if (0) nsh_output_none(v, ##__VA_ARGS__); } while (0)
#else
# define nsh_error vtbl->error
# define nsh_output vtbl->output
# define nsh_error vtbl->error
# define nsh_output vtbl->output
# define nsh_none (void)
#endif
#ifdef CONFIG_NSH_DISABLE_ERROR_PRINT
# undef nsh_error
# ifdef CONFIG_CPP_HAVE_VARARGS
# define nsh_error(v, ...) (void)(v)
# else
# define nsh_error (void)(vtbl)
# endif
# define nsh_error nsh_none
#endif
/* Size of info to be saved in call to nsh_redirect
@ -183,6 +182,19 @@ struct console_stdio_s
* Public Data
****************************************************************************/
/****************************************************************************
* Inline functions
****************************************************************************/
#ifdef CONFIG_CPP_HAVE_VARARGS
/* Can be used to suppress any nsh output */
static inline void nsh_output_none(FAR struct nsh_vtbl_s *vtbl, ...)
{
UNUSED(vtbl);
}
#endif
/****************************************************************************
* Public Function Prototypes
****************************************************************************/