nshlib: disable nsh error print if NSH_DISABLE_ERROR_PRINT enabled
text data bss dec hex filename 398953 27088 4128 430169 69059 nuttx /* before */ 389241 27072 4128 420441 66a59 nuttx /* after */ -9712 -16 Signed-off-by: chao an <anchao@xiaomi.com>
This commit is contained in:
parent
900b32c908
commit
ec63217b48
@ -377,6 +377,10 @@ config NSH_DISABLE_HELP
|
|||||||
bool "Disable help"
|
bool "Disable help"
|
||||||
default DEFAULT_SMALL
|
default DEFAULT_SMALL
|
||||||
|
|
||||||
|
config NSH_DISABLE_ERROR_PRINT
|
||||||
|
bool "Disable NSH Error Printing"
|
||||||
|
default DEFAULT_SMALL
|
||||||
|
|
||||||
config NSH_DISABLE_HEXDUMP
|
config NSH_DISABLE_HEXDUMP
|
||||||
bool "Disable hexdump"
|
bool "Disable hexdump"
|
||||||
default DEFAULT_SMALL
|
default DEFAULT_SMALL
|
||||||
|
@ -47,9 +47,13 @@
|
|||||||
#define alias_head(list) (FAR struct nsh_alias_s *)sq_peek(list)
|
#define alias_head(list) (FAR struct nsh_alias_s *)sq_peek(list)
|
||||||
#define alias_remfirst(list) (FAR struct nsh_alias_s *)sq_remfirst(list)
|
#define alias_remfirst(list) (FAR struct nsh_alias_s *)sq_remfirst(list)
|
||||||
|
|
||||||
/****************************************************************************
|
/* Alias message format */
|
||||||
* Private Types
|
|
||||||
****************************************************************************/
|
#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
|
* Private Data
|
||||||
@ -58,11 +62,6 @@
|
|||||||
/* Alias message format */
|
/* Alias message format */
|
||||||
|
|
||||||
static const char g_aliasfmt[] = "alias %s='%s'\n";
|
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
|
* 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);
|
ret = alias_save(vtbl, *arg, value);
|
||||||
if (ret < 0)
|
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)
|
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 */
|
/* Nothing found */
|
||||||
|
|
||||||
nsh_error(vtbl, g_noaliasfmt, "alias", *arg);
|
nsh_error(vtbl, g_noalias_format, "alias", *arg);
|
||||||
ret = -ENOENT;
|
ret = -ENOENT;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -429,7 +428,7 @@ int cmd_unalias(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv)
|
|||||||
{
|
{
|
||||||
/* Nothing found */
|
/* Nothing found */
|
||||||
|
|
||||||
nsh_error(vtbl, g_noaliasfmt, "unalias", *arg);
|
nsh_error(vtbl, g_noalias_format, "unalias", *arg);
|
||||||
ret = -ENOENT;
|
ret = -ENOENT;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -63,8 +63,10 @@ static int nsh_consoleioctl(FAR struct nsh_vtbl_s *vtbl,
|
|||||||
int cmd, unsigned long arg);
|
int cmd, unsigned long arg);
|
||||||
static int nsh_consoleoutput(FAR struct nsh_vtbl_s *vtbl,
|
static int nsh_consoleoutput(FAR struct nsh_vtbl_s *vtbl,
|
||||||
FAR const char *fmt, ...) printf_like(2, 3);
|
FAR const char *fmt, ...) printf_like(2, 3);
|
||||||
|
#ifndef CONFIG_NSH_DISABLE_ERROR_PRINT
|
||||||
static int nsh_erroroutput(FAR struct nsh_vtbl_s *vtbl,
|
static int nsh_erroroutput(FAR struct nsh_vtbl_s *vtbl,
|
||||||
FAR const char *fmt, ...) printf_like(2, 3);
|
FAR const char *fmt, ...) printf_like(2, 3);
|
||||||
|
#endif
|
||||||
static FAR char *nsh_consolelinebuffer(FAR struct nsh_vtbl_s *vtbl);
|
static FAR char *nsh_consolelinebuffer(FAR struct nsh_vtbl_s *vtbl);
|
||||||
static void nsh_consoleredirect(FAR struct nsh_vtbl_s *vtbl, int fd,
|
static void nsh_consoleredirect(FAR struct nsh_vtbl_s *vtbl, int fd,
|
||||||
FAR uint8_t *save);
|
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,
|
static int nsh_erroroutput(FAR struct nsh_vtbl_s *vtbl,
|
||||||
FAR const char *fmt, ...)
|
FAR const char *fmt, ...)
|
||||||
{
|
{
|
||||||
@ -189,6 +192,7 @@ static int nsh_erroroutput(FAR struct nsh_vtbl_s *vtbl,
|
|||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Name: nsh_consolelinebuffer
|
* 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.write = nsh_consolewrite;
|
||||||
pstate->cn_vtbl.ioctl = nsh_consoleioctl;
|
pstate->cn_vtbl.ioctl = nsh_consoleioctl;
|
||||||
pstate->cn_vtbl.output = nsh_consoleoutput;
|
pstate->cn_vtbl.output = nsh_consoleoutput;
|
||||||
|
#ifndef CONFIG_NSH_DISABLE_ERROR_PRINT
|
||||||
pstate->cn_vtbl.error = nsh_erroroutput;
|
pstate->cn_vtbl.error = nsh_erroroutput;
|
||||||
|
#endif
|
||||||
pstate->cn_vtbl.linebuffer = nsh_consolelinebuffer;
|
pstate->cn_vtbl.linebuffer = nsh_consolelinebuffer;
|
||||||
pstate->cn_vtbl.exit = nsh_consoleexit;
|
pstate->cn_vtbl.exit = nsh_consoleexit;
|
||||||
pstate->cn_vtbl.isctty = isctty;
|
pstate->cn_vtbl.isctty = isctty;
|
||||||
|
@ -58,6 +58,15 @@
|
|||||||
# define nsh_output vtbl->output
|
# define nsh_output vtbl->output
|
||||||
#endif
|
#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
|
/* Size of info to be saved in call to nsh_redirect
|
||||||
* See struct serialsave_s in nsh_console.c
|
* 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,
|
ssize_t (*write)(FAR struct nsh_vtbl_s *vtbl, FAR const void *buffer,
|
||||||
size_t nbytes);
|
size_t nbytes);
|
||||||
int (*ioctl)(FAR struct nsh_vtbl_s *vtbl, int cmd, unsigned long arg);
|
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, ...)
|
int (*error)(FAR struct nsh_vtbl_s *vtbl, FAR const char *fmt, ...)
|
||||||
printf_like(2, 3);
|
printf_like(2, 3);
|
||||||
|
#endif
|
||||||
int (*output)(FAR struct nsh_vtbl_s *vtbl, FAR const char *fmt, ...)
|
int (*output)(FAR struct nsh_vtbl_s *vtbl, FAR const char *fmt, ...)
|
||||||
printf_like(2, 3);
|
printf_like(2, 3);
|
||||||
FAR char *(*linebuffer)(FAR struct nsh_vtbl_s *vtbl);
|
FAR char *(*linebuffer)(FAR struct nsh_vtbl_s *vtbl);
|
||||||
|
@ -419,9 +419,8 @@ int cmd_hexdump(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv)
|
|||||||
|
|
||||||
if (nbytesread < 0)
|
if (nbytesread < 0)
|
||||||
{
|
{
|
||||||
int errval = errno;
|
|
||||||
nsh_error(vtbl, g_fmtcmdfailed, "hexdump", "read",
|
nsh_error(vtbl, g_fmtcmdfailed, "hexdump", "read",
|
||||||
NSH_ERRNO_OF(errval));
|
NSH_ERRNO_OF(errno));
|
||||||
ret = ERROR;
|
ret = ERROR;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -60,6 +60,8 @@
|
|||||||
|
|
||||||
#undef CAN_PIPE_FROM_STD
|
#undef CAN_PIPE_FROM_STD
|
||||||
|
|
||||||
|
#define g_dd "dd"
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Private Types
|
* Private Types
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
@ -79,12 +81,6 @@ struct dd_s
|
|||||||
FAR uint8_t *buffer; /* Buffer of data to write to the output file */
|
FAR uint8_t *buffer; /* Buffer of data to write to the output file */
|
||||||
};
|
};
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Private Data
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
static const char g_dd[] = "dd";
|
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Private Functions
|
* Private Functions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
@ -2002,7 +2002,6 @@ int cmd_cmp(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv)
|
|||||||
|
|
||||||
FAR char *path1 = NULL;
|
FAR char *path1 = NULL;
|
||||||
FAR char *path2 = NULL;
|
FAR char *path2 = NULL;
|
||||||
off_t total_read = 0;
|
|
||||||
int fd1 = -1;
|
int fd1 = -1;
|
||||||
int fd2 = -1;
|
int fd2 = -1;
|
||||||
int ret = ERROR;
|
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;
|
goto errout_with_fd2;
|
||||||
}
|
}
|
||||||
|
|
||||||
total_read += nbytesread1 > nbytesread2 ? nbytesread2 : nbytesread1;
|
|
||||||
|
|
||||||
/* Compare the file data */
|
/* Compare the file data */
|
||||||
|
|
||||||
if (nbytesread1 != nbytesread2 ||
|
if (nbytesread1 != nbytesread2 ||
|
||||||
memcmp(buf1, buf2, nbytesread1) != 0)
|
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;
|
goto errout_with_fd2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1796,12 +1796,14 @@ static FAR char *nsh_argument(FAR struct nsh_vtbl_s *vtbl,
|
|||||||
{
|
{
|
||||||
/* No terminator found, get out */
|
/* No terminator found, get out */
|
||||||
|
|
||||||
|
#ifndef CONFIG_NSH_DISABLE_ERROR_PRINT
|
||||||
char qterm[2];
|
char qterm[2];
|
||||||
|
|
||||||
qterm[0] = *pend;
|
qterm[0] = *pend;
|
||||||
qterm[1] = '\0';
|
qterm[1] = '\0';
|
||||||
|
|
||||||
nsh_error(vtbl, g_fmtnomatching, qterm, qterm);
|
nsh_error(vtbl, g_fmtnomatching, qterm, qterm);
|
||||||
|
#endif
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -2867,12 +2869,14 @@ int nsh_parse(FAR struct nsh_vtbl_s *vtbl, FAR char *cmdline)
|
|||||||
{
|
{
|
||||||
/* No closing quotation mark! */
|
/* No closing quotation mark! */
|
||||||
|
|
||||||
|
#ifndef CONFIG_NSH_DISABLE_ERROR_PRINT
|
||||||
char qterm[2];
|
char qterm[2];
|
||||||
|
|
||||||
qterm[0] = *ptr;
|
qterm[0] = *ptr;
|
||||||
qterm[1] = '\0';
|
qterm[1] = '\0';
|
||||||
|
|
||||||
nsh_error(vtbl, g_fmtnomatching, qterm, qterm);
|
nsh_error(vtbl, g_fmtnomatching, qterm, qterm);
|
||||||
|
#endif
|
||||||
|
|
||||||
return ERROR;
|
return ERROR;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user