diff --git a/nshlib/Kconfig b/nshlib/Kconfig index 8adde6c78..793c9daf3 100644 --- a/nshlib/Kconfig +++ b/nshlib/Kconfig @@ -377,6 +377,10 @@ config NSH_DISABLE_HELP bool "Disable help" default DEFAULT_SMALL +config NSH_DISABLE_ERROR_PRINT + bool "Disable NSH Error Printing" + default DEFAULT_SMALL + config NSH_DISABLE_HEXDUMP bool "Disable hexdump" default DEFAULT_SMALL diff --git a/nshlib/nsh_alias.c b/nshlib/nsh_alias.c index 3a819dd02..b6ef0c753 100644 --- a/nshlib/nsh_alias.c +++ b/nshlib/nsh_alias.c @@ -47,9 +47,13 @@ #define alias_head(list) (FAR struct nsh_alias_s *)sq_peek(list) #define alias_remfirst(list) (FAR struct nsh_alias_s *)sq_remfirst(list) -/**************************************************************************** - * Private Types - ****************************************************************************/ +/* Alias message format */ + +#define g_savefail_format "alias %s='%s' failed\n" + +/* Common for both alias / unalias */ + +#define g_noalias_format "%s: %s not found\n" /**************************************************************************** * Private Data @@ -58,11 +62,6 @@ /* Alias message format */ static const char g_aliasfmt[] = "alias %s='%s'\n"; -static const char g_savefailfmt[] = "alias %s='%s' failed\n"; - -/* Common for both alias / unalias */ - -static const char g_noaliasfmt[] = "%s: %s not found\n"; /**************************************************************************** * Private Functions @@ -348,7 +347,7 @@ int cmd_alias(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv) ret = alias_save(vtbl, *arg, value); if (ret < 0) { - nsh_error(vtbl, g_savefailfmt, *arg, value); + nsh_error(vtbl, g_savefail_format, *arg, value); } } else if ((alias = alias_find(vtbl, *arg)) != NULL) @@ -361,7 +360,7 @@ int cmd_alias(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv) { /* Nothing found */ - nsh_error(vtbl, g_noaliasfmt, "alias", *arg); + nsh_error(vtbl, g_noalias_format, "alias", *arg); ret = -ENOENT; } } @@ -429,7 +428,7 @@ int cmd_unalias(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv) { /* Nothing found */ - nsh_error(vtbl, g_noaliasfmt, "unalias", *arg); + nsh_error(vtbl, g_noalias_format, "unalias", *arg); ret = -ENOENT; } } diff --git a/nshlib/nsh_console.c b/nshlib/nsh_console.c index 7d29749b1..2fd1c9c12 100644 --- a/nshlib/nsh_console.c +++ b/nshlib/nsh_console.c @@ -63,8 +63,10 @@ static int nsh_consoleioctl(FAR struct nsh_vtbl_s *vtbl, int cmd, unsigned long arg); static int nsh_consoleoutput(FAR struct nsh_vtbl_s *vtbl, FAR const char *fmt, ...) printf_like(2, 3); +#ifndef CONFIG_NSH_DISABLE_ERROR_PRINT static int nsh_erroroutput(FAR struct nsh_vtbl_s *vtbl, FAR const char *fmt, ...) printf_like(2, 3); +#endif static FAR char *nsh_consolelinebuffer(FAR struct nsh_vtbl_s *vtbl); static void nsh_consoleredirect(FAR struct nsh_vtbl_s *vtbl, int fd, FAR uint8_t *save); @@ -176,6 +178,7 @@ static int nsh_consoleoutput(FAR struct nsh_vtbl_s *vtbl, * ****************************************************************************/ +#ifndef CONFIG_NSH_DISABLE_ERROR_PRINT static int nsh_erroroutput(FAR struct nsh_vtbl_s *vtbl, FAR const char *fmt, ...) { @@ -189,6 +192,7 @@ static int nsh_erroroutput(FAR struct nsh_vtbl_s *vtbl, return ret; } +#endif /**************************************************************************** * Name: nsh_consolelinebuffer @@ -368,7 +372,9 @@ FAR struct console_stdio_s *nsh_newconsole(bool isctty) pstate->cn_vtbl.write = nsh_consolewrite; pstate->cn_vtbl.ioctl = nsh_consoleioctl; pstate->cn_vtbl.output = nsh_consoleoutput; +#ifndef CONFIG_NSH_DISABLE_ERROR_PRINT pstate->cn_vtbl.error = nsh_erroroutput; +#endif pstate->cn_vtbl.linebuffer = nsh_consolelinebuffer; pstate->cn_vtbl.exit = nsh_consoleexit; pstate->cn_vtbl.isctty = isctty; diff --git a/nshlib/nsh_console.h b/nshlib/nsh_console.h index bb376e01d..a9a382045 100644 --- a/nshlib/nsh_console.h +++ b/nshlib/nsh_console.h @@ -58,6 +58,15 @@ # define nsh_output vtbl->output #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 +#endif + /* Size of info to be saved in call to nsh_redirect * See struct serialsave_s in nsh_console.c */ @@ -106,8 +115,10 @@ struct nsh_vtbl_s ssize_t (*write)(FAR struct nsh_vtbl_s *vtbl, FAR const void *buffer, size_t nbytes); int (*ioctl)(FAR struct nsh_vtbl_s *vtbl, int cmd, unsigned long arg); +#ifndef CONFIG_NSH_DISABLE_ERROR_PRINT int (*error)(FAR struct nsh_vtbl_s *vtbl, FAR const char *fmt, ...) printf_like(2, 3); +#endif int (*output)(FAR struct nsh_vtbl_s *vtbl, FAR const char *fmt, ...) printf_like(2, 3); FAR char *(*linebuffer)(FAR struct nsh_vtbl_s *vtbl); diff --git a/nshlib/nsh_dbgcmds.c b/nshlib/nsh_dbgcmds.c index df6709a88..ada21293b 100644 --- a/nshlib/nsh_dbgcmds.c +++ b/nshlib/nsh_dbgcmds.c @@ -419,9 +419,8 @@ int cmd_hexdump(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv) if (nbytesread < 0) { - int errval = errno; nsh_error(vtbl, g_fmtcmdfailed, "hexdump", "read", - NSH_ERRNO_OF(errval)); + NSH_ERRNO_OF(errno)); ret = ERROR; break; } diff --git a/nshlib/nsh_ddcmd.c b/nshlib/nsh_ddcmd.c index 1d25b2ad7..7b005d3d2 100644 --- a/nshlib/nsh_ddcmd.c +++ b/nshlib/nsh_ddcmd.c @@ -60,6 +60,8 @@ #undef CAN_PIPE_FROM_STD +#define g_dd "dd" + /**************************************************************************** * Private Types ****************************************************************************/ @@ -79,12 +81,6 @@ struct dd_s FAR uint8_t *buffer; /* Buffer of data to write to the output file */ }; -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static const char g_dd[] = "dd"; - /**************************************************************************** * Private Functions ****************************************************************************/ diff --git a/nshlib/nsh_fscmds.c b/nshlib/nsh_fscmds.c index 0c84cd5b4..10c4fbca2 100644 --- a/nshlib/nsh_fscmds.c +++ b/nshlib/nsh_fscmds.c @@ -2002,7 +2002,6 @@ int cmd_cmp(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv) FAR char *path1 = NULL; FAR char *path2 = NULL; - off_t total_read = 0; int fd1 = -1; int fd2 = -1; int ret = ERROR; @@ -2065,14 +2064,13 @@ int cmd_cmp(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv) goto errout_with_fd2; } - total_read += nbytesread1 > nbytesread2 ? nbytesread2 : nbytesread1; - /* Compare the file data */ if (nbytesread1 != nbytesread2 || memcmp(buf1, buf2, nbytesread1) != 0) { - nsh_error(vtbl, "files differ: byte %" PRIuOFF "\n", total_read); + nsh_error(vtbl, "files differ: byte %zd\n", + nbytesread1 > nbytesread2 ? nbytesread2 : nbytesread1); goto errout_with_fd2; } diff --git a/nshlib/nsh_parse.c b/nshlib/nsh_parse.c index 4f1a3b015..fb57ed3e3 100644 --- a/nshlib/nsh_parse.c +++ b/nshlib/nsh_parse.c @@ -1796,12 +1796,14 @@ static FAR char *nsh_argument(FAR struct nsh_vtbl_s *vtbl, { /* No terminator found, get out */ +#ifndef CONFIG_NSH_DISABLE_ERROR_PRINT char qterm[2]; qterm[0] = *pend; qterm[1] = '\0'; nsh_error(vtbl, g_fmtnomatching, qterm, qterm); +#endif return NULL; } @@ -2867,12 +2869,14 @@ int nsh_parse(FAR struct nsh_vtbl_s *vtbl, FAR char *cmdline) { /* No closing quotation mark! */ +#ifndef CONFIG_NSH_DISABLE_ERROR_PRINT char qterm[2]; qterm[0] = *ptr; qterm[1] = '\0'; nsh_error(vtbl, g_fmtnomatching, qterm, qterm); +#endif return ERROR; }