Merged altconsole into master

This commit is contained in:
GregoryN 2018-12-08 18:53:54 -06:00
parent c8a252d4ed
commit 3bf4b6d245
30 changed files with 533 additions and 515 deletions

View File

@ -894,26 +894,6 @@ config NSH_CONSOLE
NSH_USBCONSOLE and NSH_USBCONDEV - Sets up some other USB
serial device as the NSH console (not necessarily dev/console).
config NSH_SLCDCONSOLE
bool "Use a SLCD as console"
default n if !SLCD_CONSOLE
default y if SLCD_CONSOLE
depends on SLCD && NSH_CONSOLE
---help---
If defined, then the a configured SLCD display could be used as
output console to NuttShell (nsh>).
if NSH_SLCDCONSOLE
config NSH_SLCDCONDEV
string "SLCD console display device"
default "/dev/slcd0"
---help---
If NSH_SLCDCONSOLE is set to 'y', then NSH_SLCDCONDEV must
also be set to select the SLCD device used as output display.
endif # NSH_SLCDCONSOLE
config NSH_USBCONSOLE
bool "Use a USB serial console"
default n
@ -953,11 +933,13 @@ config NSH_ALTCONDEV
If CONFIG_NSH_CONSOLE is set to y, then CONFIG_NSH_ALTCONDEV may
also be selected to enable use of an alternate character device
to support the NSH console. If CONFIG_NSH_ALTCONDEV is selected,
then NSH_CONDEV must be set to select the serial device used to
support the NSH console. This may be useful, for example, to
separate the NSH command line from the system console when the
system console is used to provide debug output. Default: stdin
and stdout (probably "/dev/console")
then NSH_ALTSTDIN, NSH_ALTSTDOUT and NSH_ALTSTDERR must be set
to select the serial devices used to support the NSH console.
This may be useful, for example, to separate the NSH command
line from the system console when the system console is used to
provide debug output.
Default: stdin, stderr and stdout (probably "/dev/console")
NOTE 1: When any other device other than /dev/console is used
for a user interface, (1) linefeeds (\n) will not be expanded to
@ -966,39 +948,59 @@ config NSH_ALTCONDEV
not automatically echoed so you will have to turn local echo on.
NOTE 2: This option forces the console of all sessions to use
NSH_CONDEV. Hence, this option only makes sense for a system
that supports only a single session. This option is, in
particular, incompatible with Telnet sessions because each Telnet
session must use a different console device.
NSH_ALTSTD(IN/OUT/ERR). Hence, this option only makes sense for
a system that supports only a single session. This option is,
in particular, incompatible with Telnet sessions because each
Telnet session must use a different console device.
if NSH_ALTCONDEV
config NSH_CONDEV
string "Alternative console device name"
config NSH_ALTSTDIN
string "Alternative console \"stdin\" device name"
default "/dev/console"
---help---
If CONFIG_NSH_CONSOLE is set to y, then CONFIG_NSH_ALTCONDEV may
also be selected to enable use of an alternate character device
to support the NSH console. If CONFIG_NSH_ALTCONDEV is selected,
then NSH_CONDEV must be set to select the serial device used to
then NSH_ALTSTDIN must be set to select the "stdin" device to
support the NSH console. This should be set to the quoted name
of a readable/write-able character driver such as:
NSH_CONDEV="/dev/ttyS1". This is useful, for example, to separate
the NSH command line from the system console when the system console
is used to provide debug output. Default: stdin and stdout
(probably "/dev/console")
of a readable character driver such as:
NOTE 1: When any other device other than /dev/console is used
for a user interface, (1) linefeeds (\n) will not be expanded to
carriage return / linefeeds (\r\n). You will need to set
your terminal program to account for this. And (2) input is
not automatically echoed so you will have to turn local echo on.
NSH_ALTSTDIN="/dev/ttyS1".
NOTE 2: This option forces the console of all sessions to use
NSH_CONDEV. Hence, this option only makes sense for a system
that supports only a single session. This option is, in
particular, incompatible with Telnet sessions because each Telnet
session must use a different console device.
This way the input will come from "/dev/ttyS1".
config NSH_ALTSTDOUT
string "Alternative console \"stdout\" device name"
default "/dev/console" if !SLCD_CONSOLE
default "/dev/slcd0" if SLCD_CONSOLE
---help---
If CONFIG_NSH_CONSOLE is set to y, then CONFIG_NSH_ALTCONDEV may
also be selected to enable use of an alternate character device
to support the NSH console. If CONFIG_NSH_ALTCONDEV is selected,
then NSH_ALTSTDOUT must be set to select the "stdout" device to
support the NSH console. This should be set to the quoted name
of a write-able character driver such as:
NSH_ALTSTDIN="/dev/ttyS1".
This way the standard output will go to "/dev/ttyS1".
config NSH_ALTSTDERR
string "Alternative console \"stderr\" device name"
default "/dev/console" if !SLCD_CONSOLE
default "/dev/slcd0" if SLCD_CONSOLE
---help---
If CONFIG_NSH_CONSOLE is set to y, then CONFIG_NSH_ALTCONDEV may
also be selected to enable use of an alternate character device
to support the NSH console. If CONFIG_NSH_ALTCONDEV is selected,
then NSH_ALTSTDERR must be set to select the "stderr" device to
support the NSH console. This should be set to the quoted name
of a write-able character driver such as:
NSH_ALTSTDIN="/dev/ttyS1".
This way the standard error output will go to "/dev/ttyS1".
endif # NSH_ALTCONDEV

View File

@ -122,12 +122,8 @@ ifeq ($(CONFIG_USBDEV),y)
CSRCS += nsh_usbconsole.c
endif
ifeq ($(CONFIG_USBHOST),y)
CSRCS += nsh_usbkeyboard.c
endif
ifeq ($(CONFIG_SLCD),y)
CSRCS += nsh_slcd.c
ifeq ($(CONFIG_NSH_ALTCONDEV),y)
CSRCS += nsh_altconsole.c
endif
ifeq ($(CONFIG_NSH_USBDEV_TRACE),y)

View File

@ -289,22 +289,14 @@
# ifndef NSH_USBKBD_DEVNAME
# define NSH_USBKBD_DEVNAME "/dev/kbda"
# endif
/* In this case NSH_ALTSTDIN should be "/dev/kbda" */
# undef CONFIG_NSH_ALTSTDIN
# define CONFIG_NSH_ALTSTDIN NSH_USBKBD_DEVNAME
#endif /* HAVE_USB_KEYBOARD */
#undef HAVE_SLCD_CONSOLE
/* Check if SLCD is configured as console */
#if defined(CONFIG_SLCD) && defined(CONFIG_NSH_SLCDCONSOLE)
# define HAVE_SLCD_CONSOLE 1
# ifndef CONFIG_NSH_SLCDCONDEV
# define CONFIG_NSH_SLCDCONDEV "/dev/slcd0"
# endif
#endif /* HAVE_SLCD_CONSOLE */
/* USB trace settings */
#ifndef CONFIG_USBDEV_TRACE

View File

@ -1,8 +1,9 @@
/****************************************************************************
* apps/nshlib/nsh_usbkeyboard.c
* apps/nshlib/nsh_altconsole.c
*
* Copyright (C) 2014 Gregory Nutt. All rights reserved.
* Copyright (C) 2018 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
* Author: Alan Carvalho de Assis <acassis@gmail.com>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@ -49,46 +50,121 @@
#include "nsh.h"
#include "nsh_console.h"
#if defined(HAVE_USB_KEYBOARD) && !defined(HAVE_USB_CONSOLE)
#if defined(CONFIG_NSH_ALTCONDEV) && !defined(HAVE_USB_CONSOLE)
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Name: nsh_wait_usbready
* Name: nsh_clone_console
*
* Description:
* Wait for the USB keyboard device to be ready
* Clone stdout and stderr to alternatives devices
*
****************************************************************************/
static int nsh_wait_usbready(FAR const char *msg)
static int nsh_clone_console(FAR struct console_stdio_s *pstate)
{
int fd;
/* Don't start the NSH console until the keyboard device is ready. Chances
* are, we get here with no functional stdin. The USB keyboard device will
* not be available until the device is connected to the host and enumerated.
*/
/* Open the alternative standard error device */
/* Close standard fd 0. Unbeknownst to stdin. We do this here in case we
* had the USB keyboard device open. In that case, the driver will exist
* we will get an ENODEV error when we try to open it (instead of ENOENT).
*
* NOTE: This might not be portable behavior!
*/
fd = open(CONFIG_NSH_ALTSTDERR, O_WRONLY);
if (fd < 0)
{
return -ENODEV;
}
(void)close(0);
sleep(1);
/* Close stderr: note we only close stderr if we opened the alternative one */
(void)fclose(stderr);
/* Associate the new opened file descriptor to stderr */
(void)dup2(fd, 2);
/* Close the console device that we just opened */
if (fd != 0)
{
close(fd);
}
/* Open the alternative standard output device */
fd = open(CONFIG_NSH_ALTSTDOUT, O_WRONLY);
if (fd < 0)
{
return -ENODEV;
}
/* Close stdout: note we only close stdout if we opened the alternative one */
(void)fclose(stdout);
/* Associate the new opened file descriptor to stdout */
(void)dup2(fd, 1);
/* Close the console device that we just opened */
if (fd != 0)
{
close(fd);
}
/* Setup the stderr */
pstate->cn_errfd = 2;
pstate->cn_errstream = fdopen(pstate->cn_errfd, "a");
if (!pstate->cn_errstream)
{
close(pstate->cn_errfd);
free(pstate);
return -EIO;
}
/* Setup the stdout */
pstate->cn_outfd = 1;
pstate->cn_outstream = fdopen(pstate->cn_outfd, "a");
if (!pstate->cn_outstream)
{
close(pstate->cn_outfd);
free(pstate);
return -EIO;
}
return OK;
}
/****************************************************************************
* Name: nsh_wait_inputdev
*
* Description:
* Wait for the input device to be ready
*
****************************************************************************/
static int nsh_wait_inputdev(FAR struct console_stdio_s *pstate,
FAR const char *msg)
{
int fd;
/* Don't start the NSH console until the input device is ready. Chances
* are, we get here with no functional stdin. For example a USB keyboard
* device will not be available until the device is connected to the host
* and enumerated.
*/
/* Open the USB keyboard device for read-only access */
do
{
/* Try to open the console */
/* Try to open the alternative stdin device */
fd = open(NSH_USBKBD_DEVNAME, O_RDONLY);
fd = open(CONFIG_NSH_ALTSTDIN, O_RDWR);
if (fd < 0)
{
#ifdef CONFIG_DEBUG_FEATURES
@ -124,7 +200,11 @@ static int nsh_wait_usbready(FAR const char *msg)
}
while (fd < 0);
/* Okay.. we have successfully opened a keyboard device. Did
/* Close stdin: note we only closed stdin if we opened the alternative one */
(void)fclose(stdin);
/* Okay.. we have successfully opened the input device. Did
* we just re-open fd 0?
*/
@ -134,7 +214,21 @@ static int nsh_wait_usbready(FAR const char *msg)
(void)dup2(fd, 0);
/* Close the keyboard device that we just opened */
/* Setup the input console */
pstate->cn_confd = 0;
/* Create a standard C stream on the console device */
pstate->cn_constream = fdopen(pstate->cn_confd, "r+");
if (!pstate->cn_constream)
{
close(pstate->cn_confd);
free(pstate);
return -EIO;
}
/* Close the input device that we just opened */
close(fd);
}
@ -196,16 +290,25 @@ int nsh_consolemain(int argc, char *argv[])
(void)boardctl(BOARDIOC_FINALINIT, 0);
#endif
/* First map stderr and stdout to alternative devices */
ret = nsh_clone_console(pstate);
if (ret < 0)
{
return ret;
}
/* Now loop, executing creating a session for each USB connection */
msg = "Waiting for a keyboard...\n";
for (;;)
for (; ; )
{
/* Wait for the USB to be connected to the host and switch
* standard I/O to the USB serial device.
*/
ret = nsh_wait_usbready(msg);
ret = nsh_wait_inputdev(pstate, msg);
DEBUGASSERT(ret == OK);
UNUSED(ret);

View File

@ -179,8 +179,8 @@ int nsh_builtin(FAR struct nsh_vtbl_s *vtbl, FAR const char *cmd,
}
else
{
nsh_output(vtbl, g_fmtcmdfailed, cmd, "waitpid",
NSH_ERRNO_OF(errcode));
nsh_error(vtbl, g_fmtcmdfailed, cmd, "waitpid",
NSH_ERRNO_OF(errcode));
}
}

View File

@ -296,13 +296,13 @@ static int cmd_codecs_proc(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv,
break;
#endif
case ':':
nsh_output(vtbl, g_fmtargrequired, argv[0]);
nsh_error(vtbl, g_fmtargrequired, argv[0]);
badarg = true;
break;
case '?':
default:
nsh_output(vtbl, g_fmtarginvalid, argv[0]);
nsh_error(vtbl, g_fmtarginvalid, argv[0]);
badarg = true;
break;
}
@ -354,7 +354,7 @@ static int cmd_codecs_proc(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv,
fd = open(fullpath, O_RDONLY);
if (fd < 0)
{
nsh_output(vtbl, g_fmtcmdfailed, argv[0], "open", NSH_ERRNO);
nsh_error(vtbl, g_fmtcmdfailed, argv[0], "open", NSH_ERRNO);
ret = ERROR;
goto exit;
}
@ -379,7 +379,7 @@ static int cmd_codecs_proc(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv,
ret=read(fd, srcbuf, srclen);
if (ret < 0)
{
nsh_output(vtbl, g_fmtcmdfailed, argv[0], "read", NSH_ERRNO);
nsh_error(vtbl, g_fmtcmdfailed, argv[0], "read", NSH_ERRNO);
ret = ERROR;
goto exit;
}

View File

@ -693,7 +693,7 @@ static int help_cmd(FAR struct nsh_vtbl_s *vtbl, FAR const char *cmd)
}
}
nsh_output(vtbl, g_fmtcmdnotfound, cmd);
nsh_error(vtbl, g_fmtcmdnotfound, cmd);
return ERROR;
}
#endif
@ -828,7 +828,7 @@ static int cmd_help(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
static int cmd_unrecognized(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
{
nsh_output(vtbl, g_fmtcmdnotfound, argv[0]);
nsh_error(vtbl, g_fmtcmdnotfound, argv[0]);
return ERROR;
}
@ -915,14 +915,14 @@ int nsh_command(FAR struct nsh_vtbl_s *vtbl, int argc, char *argv[])
{
/* Fewer than the minimum number were provided */
nsh_output(vtbl, g_fmtargrequired, cmd);
nsh_error(vtbl, g_fmtargrequired, cmd);
return ERROR;
}
else if (argc > cmdmap->maxargs)
{
/* More than the maximum number were provided */
nsh_output(vtbl, g_fmttoomanyargs, cmd);
nsh_error(vtbl, g_fmttoomanyargs, cmd);
return ERROR;
}
else

View File

@ -60,7 +60,9 @@
#if CONFIG_NFILE_STREAMS > 0
struct serialsave_s
{
int cn_errfd; /* Re-directed error output file descriptor */
int cn_outfd; /* Re-directed output file descriptor */
FILE *cn_errstream; /* Re-directed error output stream */
FILE *cn_outstream; /* Re-directed output stream */
};
#endif
@ -77,6 +79,8 @@ static ssize_t nsh_consolewrite(FAR struct nsh_vtbl_s *vtbl,
FAR const void *buffer, size_t nbytes);
static int nsh_consoleoutput(FAR struct nsh_vtbl_s *vtbl,
FAR const char *fmt, ...);
static int nsh_erroroutput(FAR struct nsh_vtbl_s *vtbl,
FAR const char *fmt, ...);
static FAR char *nsh_consolelinebuffer(FAR struct nsh_vtbl_s *vtbl);
#if CONFIG_NFILE_DESCRIPTORS > 0
@ -111,6 +115,13 @@ static int nsh_openifnotopen(struct console_stdio_s *pstate)
{
return ERROR;
}
#if !defined(CONFIG_NSH_ALTCONDEV)
/* If the alternative console is not enabled then stderr = stdout */
pstate->cn_errfd = pstate->cn_outfd;
pstate->cn_errstream = pstate->cn_outstream;
#endif
}
return 0;
@ -145,7 +156,9 @@ static void nsh_closeifnotclosed(struct console_stdio_s *pstate)
close(pstate->cn_outfd);
}
pstate->cn_errfd = -1;
pstate->cn_outfd = -1;
pstate->cn_errstream = NULL;
pstate->cn_outstream = NULL;
}
}
@ -258,6 +271,64 @@ static int nsh_consoleoutput(FAR struct nsh_vtbl_s *vtbl,
#endif
}
/****************************************************************************
* Name: nsh_erroroutput
*
* Description:
* Print a string to the currently selected error stream.
*
****************************************************************************/
static int nsh_erroroutput(FAR struct nsh_vtbl_s *vtbl,
FAR const char *fmt, ...)
{
#if CONFIG_NFILE_DESCRIPTORS > 0
FAR struct console_stdio_s *pstate = (FAR struct console_stdio_s *)vtbl;
va_list ap;
int ret;
/* The stream is open in a lazy fashion. This is done because the file
* descriptor may be opened on a different task than the stream. The
* actual open will then occur with the first output from the new task.
*/
if (nsh_openifnotopen(pstate) != 0)
{
return ERROR;
}
va_start(ap, fmt);
ret = vfprintf(pstate->cn_errstream, fmt, ap);
va_end(ap);
return ret;
#else
va_list ap;
char *str;
/* Use vasprintf() to allocate a buffer and fill it with the formatted
* data
*/
va_start(ap, fmt);
str = NULL;
(void)vasprintf(&str, fmt, ap);
/* Was a string allocated? */
if (str)
{
/* Yes.. Print then free the allocated string */
printf("%s", str);
free(str);
}
va_end(ap);
return 0;
#endif
}
/****************************************************************************
* Name: nsh_consolelinebuffer
*
@ -374,6 +445,7 @@ static void nsh_consoleredirect(FAR struct nsh_vtbl_s *vtbl, int fd,
if (pstate->cn_outstream)
{
fflush(pstate->cn_errstream);
fflush(pstate->cn_outstream);
}
@ -381,7 +453,9 @@ static void nsh_consoleredirect(FAR struct nsh_vtbl_s *vtbl, int fd,
* when nsh_consoleundirect() is called.
*/
ssave->cn_errfd = pstate->cn_errfd;
ssave->cn_outfd = pstate->cn_outfd;
ssave->cn_errstream = pstate->cn_errstream;
ssave->cn_outstream = pstate->cn_outstream;
}
else
@ -416,7 +490,9 @@ static void nsh_consoleundirect(FAR struct nsh_vtbl_s *vtbl, FAR uint8_t *save)
FAR struct serialsave_s *ssave = (FAR struct serialsave_s *)save;
nsh_closeifnotclosed(pstate);
pstate->cn_errfd = ssave->cn_errfd;
pstate->cn_outfd = ssave->cn_outfd;
pstate->cn_errstream = ssave->cn_errstream;
pstate->cn_outstream = ssave->cn_outstream;
}
#endif
@ -460,6 +536,7 @@ FAR struct console_stdio_s *nsh_newconsole(void)
#endif
pstate->cn_vtbl.write = nsh_consolewrite;
pstate->cn_vtbl.output = nsh_consoleoutput;
pstate->cn_vtbl.error = nsh_erroroutput;
pstate->cn_vtbl.linebuffer = nsh_consolelinebuffer;
pstate->cn_vtbl.exit = nsh_consoleexit;
@ -473,10 +550,11 @@ FAR struct console_stdio_s *nsh_newconsole(void)
pstate->cn_vtbl.redirect = nsh_consoleredirect;
pstate->cn_vtbl.undirect = nsh_consoleundirect;
#if 0
/* (Re-) open the console input device */
#ifdef CONFIG_NSH_ALTCONDEV
pstate->cn_confd = open(CONFIG_NSH_CONDEV, O_RDWR);
pstate->cn_confd = open(CONFIG_NSH_ALTSTDIN, O_RDWR);
if (pstate->cn_confd < 0)
{
free(pstate);
@ -493,6 +571,12 @@ FAR struct console_stdio_s *nsh_newconsole(void)
return NULL;
}
#endif
#endif /* if 0 */
/* Initialize the error stream */
pstate->cn_errfd = ERRFD(pstate);
pstate->cn_errstream = ERRSTREAM(pstate);
/* Initialize the output stream */

View File

@ -63,8 +63,10 @@
#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__)
#else
# define nsh_error vtbl->error
# define nsh_output vtbl->output
#endif
@ -77,14 +79,17 @@
#if CONFIG_NFILE_STREAMS > 0
# ifdef CONFIG_NSH_ALTCONDEV
# ifndef CONFIG_NSH_CONDEV
# error CONFIG_NSH_ALTCONDEV selected but CONFIG_NSH_CONDEV not provided
# if !defined(CONFIG_NSH_ALTSTDIN) && !defined(NSH_ALTSTDOUT) && \
!defined(CONFIGNSH_ALTSTDERR)
# error CONFIG_NSH_ALTCONDEV selected but CONFIG_NSH_ALTSTDxxx not provided
# endif
# define INFD(p) ((p)->cn_confd)
# define INSTREAM(p) ((p)->cn_constream)
# define OUTFD(p) ((p)->cn_confd)
# define OUTSTREAM(p) ((p)->cn_constream)
# define OUTFD(p) ((p)->cn_outfd)
# define OUTSTREAM(p) ((p)->cn_outstream)
# define ERRFD(p) ((p)->cn_errfd)
# define ERRSTREAM(p) ((p)->cn_errstream)
# else
@ -92,6 +97,8 @@
# define INSTREAM(p) stdin
# define OUTFD(p) 1
# define OUTSTREAM(p) stdout
# define ERRFD(p) 2
# define ERRSTREAM(p) stderr
# endif
#endif
@ -116,6 +123,7 @@ struct nsh_vtbl_s
#endif
ssize_t (*write)(FAR struct nsh_vtbl_s *vtbl, FAR const void *buffer,
size_t nbytes);
int (*error)(FAR struct nsh_vtbl_s *vtbl, FAR const char *fmt, ...);
int (*output)(FAR struct nsh_vtbl_s *vtbl, FAR const char *fmt, ...);
FAR char *(*linebuffer)(FAR struct nsh_vtbl_s *vtbl);
#if CONFIG_NFILE_DESCRIPTORS > 0
@ -152,10 +160,12 @@ struct console_stdio_s
int cn_confd; /* Console I/O file descriptor */
#endif
int cn_outfd; /* Output file descriptor (possibly redirected) */
int cn_errfd; /* Error Output file descriptor (possibly redirected) */
#ifdef CONFIG_NSH_ALTCONDEV
FILE *cn_constream; /* Console I/O stream (possibly redirected) */
#endif
FILE *cn_outstream; /* Output stream */
FILE *cn_errstream; /* Error Output stream */
#endif
#ifdef CONFIG_NSH_VARS

View File

@ -47,8 +47,8 @@
#include "nsh.h"
#include "nsh_console.h"
#if !defined(HAVE_USB_CONSOLE) && !defined(HAVE_USB_KEYBOARD) && \
!defined(HAVE_SLCD_CONSOLE)
#if !defined(CONFIG_NSH_ALTCONDEV) && !defined(HAVE_USB_CONSOLE) && \
!defined(HAVE_USB_KEYBOARD)
/****************************************************************************
* Public Functions

View File

@ -169,7 +169,7 @@ int cmd_mb(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv)
if (mem.dm_value > 0x000000ff)
{
nsh_output(vtbl, g_fmtargrange, argv[0]);
nsh_error(vtbl, g_fmtargrange, argv[0]);
return ERROR;
}
@ -225,7 +225,7 @@ int cmd_mh(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv)
if (mem.dm_value > 0x0000ffff)
{
nsh_output(vtbl, g_fmtargrange, argv[0]);
nsh_error(vtbl, g_fmtargrange, argv[0]);
return ERROR;
}
@ -389,7 +389,7 @@ int cmd_hexdump(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv)
fd = open(argv[1], O_RDONLY);
if (fd < 0)
{
nsh_output(vtbl, g_fmtcmdfailed, "hexdump", "open", NSH_ERRNO);
nsh_error(vtbl, g_fmtcmdfailed, "hexdump", "open", NSH_ERRNO);
return ERROR;
}
@ -397,7 +397,7 @@ int cmd_hexdump(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv)
if(buffer == NULL)
{
(void)close(fd);
nsh_output(vtbl, g_fmtcmdfailed, "hexdump", "malloc", NSH_ERRNO);
nsh_error(vtbl, g_fmtcmdfailed, "hexdump", "malloc", NSH_ERRNO);
return ERROR;
}
@ -425,7 +425,7 @@ int cmd_hexdump(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv)
if (nbytesread < 0)
{
int errval = errno;
nsh_output(vtbl, g_fmtcmdfailed, "hexdump", "read",
nsh_error(vtbl, g_fmtcmdfailed, "hexdump", "read",
NSH_ERRNO_OF(errval));
ret = ERROR;
break;

View File

@ -121,7 +121,7 @@ static int dd_write(struct dd_s *dd)
if (nbytes < 0)
{
FAR struct nsh_vtbl_s *vtbl = dd->vtbl;
nsh_output(vtbl, g_fmtcmdfailed, g_dd, "write", NSH_ERRNO_OF(-nbytes));
nsh_error(vtbl, g_fmtcmdfailed, g_dd, "write", NSH_ERRNO_OF(-nbytes));
return ERROR;
}
@ -149,7 +149,7 @@ static int dd_read(struct dd_s *dd)
if (nbytes < 0)
{
FAR struct nsh_vtbl_s *vtbl = dd->vtbl;
nsh_output(vtbl, g_fmtcmdfailed, g_dd, "read", NSH_ERRNO_OF(-nbytes));
nsh_error(vtbl, g_fmtcmdfailed, g_dd, "read", NSH_ERRNO_OF(-nbytes));
return ERROR;
}
@ -172,7 +172,7 @@ static inline int dd_infopen(const char *name, struct dd_s *dd)
if (dd->infd < 0)
{
FAR struct nsh_vtbl_s *vtbl = dd->vtbl;
nsh_output(vtbl, g_fmtcmdfailed, g_dd, "open", NSH_ERRNO);
nsh_error(vtbl, g_fmtcmdfailed, g_dd, "open", NSH_ERRNO);
return ERROR;
}
@ -188,7 +188,7 @@ static inline int dd_outfopen(const char *name, struct dd_s *dd)
dd->outfd = open(name, O_WRONLY|O_CREAT|O_TRUNC, 0644);
if (dd->outfd < 0)
{
nsh_output(dd->vtbl, g_fmtcmdfailed, g_dd, "open", NSH_ERRNO);
nsh_error(dd->vtbl, g_fmtcmdfailed, g_dd, "open", NSH_ERRNO);
return ERROR;
}
@ -279,7 +279,7 @@ int cmd_dd(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
#ifndef CAN_PIPE_FROM_STD
if (infile == NULL || outfile == NULL)
{
nsh_output(vtbl, g_fmtargrequired, g_dd);
nsh_error(vtbl, g_fmtargrequired, g_dd);
goto errout_with_paths;
}
#endif
@ -289,7 +289,7 @@ int cmd_dd(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
dd.buffer = malloc(dd.sectsize);
if (!dd.buffer)
{
nsh_output(vtbl, g_fmtcmdoutofmemory, g_dd);
nsh_error(vtbl, g_fmtcmdoutofmemory, g_dd);
goto errout_with_paths;
}

View File

@ -120,7 +120,7 @@ static inline char *nsh_getdirpath(FAR struct nsh_vtbl_s *vtbl,
if (!alloc)
{
nsh_output(vtbl, g_fmtcmdoutofmemory, "nsh_getdirpath");
nsh_error(vtbl, g_fmtcmdoutofmemory, "nsh_getdirpath");
}
return alloc;
@ -248,7 +248,7 @@ int cmd_cd(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
ret = chdir(path);
if (ret != 0)
{
nsh_output(vtbl, g_fmtcmdfailed, argv[0], "chdir", NSH_ERRNO);
nsh_error(vtbl, g_fmtcmdfailed, argv[0], "chdir", NSH_ERRNO);
ret = ERROR;
}
@ -374,7 +374,7 @@ int cmd_set(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
if (strlen(argv[1]) < 2)
{
ret = -EINVAL;
nsh_output(vtbl, g_fmtargrequired, argv[0], "set", NSH_ERRNO);
nsh_error(vtbl, g_fmtargrequired, argv[0], "set", NSH_ERRNO);
}
else
{
@ -382,7 +382,7 @@ int cmd_set(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
if (op != '-' && op != '+')
{
ret = -EINVAL;
nsh_output(vtbl, g_fmtarginvalid, argv[0], "set", NSH_ERRNO);
nsh_error(vtbl, g_fmtarginvalid, argv[0], "set", NSH_ERRNO);
}
else
{
@ -392,7 +392,7 @@ int cmd_set(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
popt = strchr(opts, *value++);
if (popt == NULL)
{
nsh_output(vtbl, g_fmtarginvalid, argv[0], "set", NSH_ERRNO);
nsh_error(vtbl, g_fmtarginvalid, argv[0], "set", NSH_ERRNO);
ret = -EINVAL;
break;
}
@ -449,7 +449,7 @@ int cmd_set(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
ret = nsh_setvar(vtbl, argv[ndx], value);
if (ret < 0)
{
nsh_output(vtbl, g_fmtcmdfailed, argv[0], "nsh_setvar",
nsh_error(vtbl, g_fmtcmdfailed, argv[0], "nsh_setvar",
NSH_ERRNO_OF(-ret));
}
}
@ -465,7 +465,7 @@ int cmd_set(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
ret = setenv(argv[ndx], value, TRUE);
if (ret < 0)
{
nsh_output(vtbl, g_fmtcmdfailed, argv[0], "setenv",
nsh_error(vtbl, g_fmtcmdfailed, argv[0], "setenv",
NSH_ERRNO);
}
}
@ -495,8 +495,8 @@ int cmd_unset(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
status = nsh_unsetvar(vtbl, argv[1]);
if (status < 0 && status != -ENOENT)
{
nsh_output(vtbl, g_fmtcmdfailed, argv[0], "nsh_unsetvar",
NSH_ERRNO_OF(-status));
nsh_error(vtbl, g_fmtcmdfailed, argv[0], "nsh_unsetvar",
NSH_ERRNO_OF(-status));
ret = ERROR;
}
#endif
@ -507,7 +507,7 @@ int cmd_unset(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
status = unsetenv(argv[1]);
if (status < 0)
{
nsh_output(vtbl, g_fmtcmdfailed, argv[0], "unsetenv", NSH_ERRNO);
nsh_error(vtbl, g_fmtcmdfailed, argv[0], "unsetenv", NSH_ERRNO);
ret = ERROR;
}
#endif
@ -553,7 +553,7 @@ int cmd_export(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
status = setenv(argv[1], value, TRUE);
if (status < 0)
{
nsh_output(vtbl, g_fmtcmdfailed, argv[0], "unsetenv", NSH_ERRNO);
nsh_error(vtbl, g_fmtcmdfailed, argv[0], "unsetenv", NSH_ERRNO);
ret = ERROR;
}
else
@ -567,7 +567,7 @@ int cmd_export(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
status = nsh_unsetvar(vtbl, argv[1]);
if (status < 0 && status != -ENOENT)
{
nsh_output(vtbl, g_fmtcmdfailed, argv[0], "nsh_unsetvar",
nsh_error(vtbl, g_fmtcmdfailed, argv[0], "nsh_unsetvar",
NSH_ERRNO_OF(-status));
ret = ERROR;
}
@ -575,4 +575,4 @@ int cmd_export(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
return ret;
}
#endif
#endif

View File

@ -96,7 +96,7 @@ int nsh_fileapp(FAR struct nsh_vtbl_s *vtbl, FAR const char *cmd,
* failure.
*/
nsh_output(vtbl, g_fmtcmdfailed, cmd, "posix_spawn_file_actions_init",
nsh_error(vtbl, g_fmtcmdfailed, cmd, "posix_spawn_file_actions_init",
NSH_ERRNO_OF(ret));
goto errout;
}
@ -106,8 +106,8 @@ int nsh_fileapp(FAR struct nsh_vtbl_s *vtbl, FAR const char *cmd,
{
/* posix_spawnattr_init returns a positive errno value on failure. */
nsh_output(vtbl, g_fmtcmdfailed, cmd, "posix_spawnattr_init",
NSH_ERRNO);
nsh_error(vtbl, g_fmtcmdfailed, cmd, "posix_spawnattr_init",
NSH_ERRNO);
goto errout_with_actions;
}
@ -123,7 +123,7 @@ int nsh_fileapp(FAR struct nsh_vtbl_s *vtbl, FAR const char *cmd,
* value on failure.
*/
nsh_output(vtbl, g_fmtcmdfailed, cmd,
nsh_error(vtbl, g_fmtcmdfailed, cmd,
"posix_spawn_file_actions_addopen",
NSH_ERRNO);
goto errout_with_attrs;
@ -211,7 +211,7 @@ int nsh_fileapp(FAR struct nsh_vtbl_s *vtbl, FAR const char *cmd,
}
else
{
nsh_output(vtbl, g_fmtcmdfailed, cmd, "waitpid",
nsh_error(vtbl, g_fmtcmdfailed, cmd, "waitpid",
NSH_ERRNO_OF(errcode));
}
}

View File

@ -176,7 +176,7 @@ static int ls_handler(FAR struct nsh_vtbl_s *vtbl, FAR const char *dirpath,
if (ret != 0)
{
nsh_output(vtbl, g_fmtcmdfailed, "ls", "stat", NSH_ERRNO);
nsh_error(vtbl, g_fmtcmdfailed, "ls", "stat", NSH_ERRNO);
return ERROR;
}
@ -313,7 +313,7 @@ static int ls_handler(FAR struct nsh_vtbl_s *vtbl, FAR const char *dirpath,
if (len < 0)
{
nsh_output(vtbl, g_fmtcmdfailed, "ls", "readlink", NSH_ERRNO);
nsh_error(vtbl, g_fmtcmdfailed, "ls", "readlink", NSH_ERRNO);
return ERROR;
}
@ -475,7 +475,7 @@ int cmd_cat(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
fullpath = nsh_getfullpath(vtbl, argv[i]);
if (fullpath == NULL)
{
nsh_output(vtbl, g_fmtcmdoutofmemory, argv[0]);
nsh_error(vtbl, g_fmtcmdoutofmemory, argv[0]);
ret = ERROR;
}
else
@ -529,7 +529,7 @@ int cmd_cp(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
srcpath = nsh_getfullpath(vtbl, argv[1]);
if (srcpath == NULL)
{
nsh_output(vtbl, g_fmtcmdoutofmemory, argv[0]);
nsh_error(vtbl, g_fmtcmdoutofmemory, argv[0]);
goto errout;
}
@ -538,7 +538,7 @@ int cmd_cp(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
rdfd = open(srcpath, O_RDONLY);
if (rdfd < 0)
{
nsh_output(vtbl, g_fmtcmdfailed, argv[0], "open", NSH_ERRNO);
nsh_error(vtbl, g_fmtcmdfailed, argv[0], "open", NSH_ERRNO);
goto errout_with_srcpath;
}
@ -547,7 +547,7 @@ int cmd_cp(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
destpath = nsh_getfullpath(vtbl, argv[2]);
if (destpath == NULL)
{
nsh_output(vtbl, g_fmtcmdoutofmemory, argv[0]);
nsh_error(vtbl, g_fmtcmdoutofmemory, argv[0]);
goto errout_with_rdfd;
}
@ -569,7 +569,7 @@ int cmd_cp(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
allocpath = nsh_getdirpath(vtbl, destpath, basename(argv[1]) );
if (!allocpath)
{
nsh_output(vtbl, g_fmtcmdoutofmemory, argv[0]);
nsh_error(vtbl, g_fmtcmdoutofmemory, argv[0]);
goto errout_with_destpath;
}
@ -591,7 +591,7 @@ int cmd_cp(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
wrfd = open(destpath, oflags, 0666);
if (wrfd < 0)
{
nsh_output(vtbl, g_fmtcmdfailed, argv[0], "open", NSH_ERRNO);
nsh_error(vtbl, g_fmtcmdfailed, argv[0], "open", NSH_ERRNO);
goto errout_with_allocpath;
}
@ -619,14 +619,14 @@ int cmd_cp(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
#ifndef CONFIG_DISABLE_SIGNALS
if (errno == EINTR)
{
nsh_output(vtbl, g_fmtsignalrecvd, argv[0]);
nsh_error(vtbl, g_fmtsignalrecvd, argv[0]);
}
else
#endif
{
/* Read error */
nsh_output(vtbl, g_fmtcmdfailed, argv[0], "read", NSH_ERRNO);
nsh_error(vtbl, g_fmtcmdfailed, argv[0], "read", NSH_ERRNO);
}
goto errout_with_wrfd;
}
@ -647,14 +647,14 @@ int cmd_cp(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
#ifndef CONFIG_DISABLE_SIGNALS
if (errno == EINTR)
{
nsh_output(vtbl, g_fmtsignalrecvd, argv[0]);
nsh_error(vtbl, g_fmtsignalrecvd, argv[0]);
}
else
#endif
{
/* Read error */
nsh_output(vtbl, g_fmtcmdfailed, argv[0], "write", NSH_ERRNO);
nsh_error(vtbl, g_fmtcmdfailed, argv[0], "write", NSH_ERRNO);
}
goto errout_with_wrfd;
}
@ -738,7 +738,7 @@ int cmd_losetup(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
case '?':
default:
nsh_output(vtbl, g_fmtarginvalid, argv[0]);
nsh_error(vtbl, g_fmtarginvalid, argv[0]);
badarg = true;
break;
}
@ -769,7 +769,7 @@ int cmd_losetup(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
}
else
{
nsh_output(vtbl, g_fmtargrequired, argv[0]);
nsh_error(vtbl, g_fmtargrequired, argv[0]);
goto errout_with_paths;
}
}
@ -778,7 +778,7 @@ int cmd_losetup(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
if (optind < argc)
{
nsh_output(vtbl, g_fmttoomanyargs, argv[0]);
nsh_error(vtbl, g_fmttoomanyargs, argv[0]);
goto errout_with_paths;
}
@ -787,7 +787,7 @@ int cmd_losetup(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
fd = open("/dev/loop", O_RDONLY);
if (fd < 0)
{
nsh_output(vtbl, g_fmtcmdfailed, argv[0], "open", NSH_ERRNO);
nsh_error(vtbl, g_fmtcmdfailed, argv[0], "open", NSH_ERRNO);
goto errout_with_paths;
}
@ -800,7 +800,7 @@ int cmd_losetup(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
ret = ioctl(fd, LOOPIOC_TEARDOWN, (unsigned long)((uintptr_t)loopdev));
if (ret < 0)
{
nsh_output(vtbl, g_fmtcmdfailed, argv[0], "ioctl", NSH_ERRNO);
nsh_error(vtbl, g_fmtcmdfailed, argv[0], "ioctl", NSH_ERRNO);
goto errout_with_fd;
}
}
@ -817,7 +817,7 @@ int cmd_losetup(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
ret = ioctl(fd, LOOPIOC_SETUP, (unsigned long)((uintptr_t)&setup));
if (ret < 0)
{
nsh_output(vtbl, g_fmtcmdfailed, argv[0], "ioctl", NSH_ERRNO);
nsh_error(vtbl, g_fmtcmdfailed, argv[0], "ioctl", NSH_ERRNO);
goto errout_with_fd;
}
}
@ -907,7 +907,7 @@ int cmd_losmart(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
case '?':
default:
nsh_output(vtbl, g_fmtarginvalid, argv[0]);
nsh_error(vtbl, g_fmtarginvalid, argv[0]);
badarg = true;
break;
}
@ -935,7 +935,7 @@ int cmd_losmart(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
}
else
{
nsh_output(vtbl, g_fmtargrequired, argv[0]);
nsh_error(vtbl, g_fmtargrequired, argv[0]);
goto errout_with_paths;
}
}
@ -944,7 +944,7 @@ int cmd_losmart(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
if (optind < argc)
{
nsh_output(vtbl, g_fmttoomanyargs, argv[0]);
nsh_error(vtbl, g_fmttoomanyargs, argv[0]);
goto errout_with_paths;
}
@ -953,7 +953,7 @@ int cmd_losmart(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
fd = open("/dev/smart", O_RDONLY);
if (fd < 0)
{
nsh_output(vtbl, g_fmtcmdfailed, argv[0], "open", NSH_ERRNO);
nsh_error(vtbl, g_fmtcmdfailed, argv[0], "open", NSH_ERRNO);
goto errout_with_paths;
}
@ -966,7 +966,7 @@ int cmd_losmart(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
ret = ioctl(fd, SMART_LOOPIOC_TEARDOWN, (unsigned long)((uintptr_t) loopdev));
if (ret < 0)
{
nsh_output(vtbl, g_fmtcmdfailed, argv[0], "ioctl", NSH_ERRNO);
nsh_error(vtbl, g_fmtcmdfailed, argv[0], "ioctl", NSH_ERRNO);
goto errout_with_fd;
}
}
@ -984,7 +984,7 @@ int cmd_losmart(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
ret = ioctl(fd, SMART_LOOPIOC_SETUP, (unsigned long)((uintptr_t)&setup));
if (ret < 0)
{
nsh_output(vtbl, g_fmtcmdfailed, argv[0], "ioctl", NSH_ERRNO);
nsh_error(vtbl, g_fmtcmdfailed, argv[0], "ioctl", NSH_ERRNO);
goto errout_with_fd;
}
}
@ -1031,7 +1031,7 @@ int cmd_ln(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
{
if (strcmp(argv[1], "-s") != 0)
{
nsh_output(vtbl, g_fmtarginvalid, argv[0]);
nsh_error(vtbl, g_fmtarginvalid, argv[0]);
return ERROR;
}
@ -1061,7 +1061,7 @@ int cmd_ln(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
ret = link(tgtpath, linkpath);
if (ret < 0)
{
nsh_output(vtbl, g_fmtcmdfailed, argv[0], "link", NSH_ERRNO);
nsh_error(vtbl, g_fmtcmdfailed, argv[0], "link", NSH_ERRNO);
ret = ERROR;
}
@ -1072,7 +1072,7 @@ int cmd_ln(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
errout_with_tgtpath:
nsh_freefullpath(tgtpath);
errout_with_nomemory:
nsh_output(vtbl, g_fmtcmdoutofmemory, argv[0]);
nsh_error(vtbl, g_fmtcmdoutofmemory, argv[0]);
return ERROR;
}
#endif
@ -1115,7 +1115,7 @@ int cmd_ls(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
case '?':
default:
nsh_output(vtbl, g_fmtarginvalid, argv[0]);
nsh_error(vtbl, g_fmtarginvalid, argv[0]);
badarg = true;
break;
}
@ -1132,7 +1132,7 @@ int cmd_ls(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
if (optind + 1 < argc)
{
nsh_output(vtbl, g_fmttoomanyargs, argv[0]);
nsh_error(vtbl, g_fmttoomanyargs, argv[0]);
return ERROR;
}
else if (optind >= argc)
@ -1140,7 +1140,7 @@ int cmd_ls(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
#ifndef CONFIG_DISABLE_ENVIRON
relpath = nsh_getcwd();
#else
nsh_output(vtbl, g_fmtargrequired, argv[0]);
nsh_error(vtbl, g_fmtargrequired, argv[0]);
return ERROR;
#endif
}
@ -1154,7 +1154,7 @@ int cmd_ls(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
fullpath = nsh_getfullpath(vtbl, relpath);
if (fullpath == NULL)
{
nsh_output(vtbl, g_fmtcmdoutofmemory, argv[0]);
nsh_error(vtbl, g_fmtcmdoutofmemory, argv[0]);
return ERROR;
}
@ -1171,7 +1171,7 @@ int cmd_ls(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
if (stat(fullpath, &st) < 0)
{
nsh_output(vtbl, g_fmtcmdfailed, argv[0], "stat", NSH_ERRNO);
nsh_error(vtbl, g_fmtcmdfailed, argv[0], "stat", NSH_ERRNO);
ret = ERROR;
}
else if (!S_ISDIR(st.st_mode))
@ -1221,7 +1221,7 @@ int cmd_mkdir(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
ret = mkdir(fullpath, 0777);
if (ret < 0)
{
nsh_output(vtbl, g_fmtcmdfailed, argv[0], "mkdir", NSH_ERRNO);
nsh_error(vtbl, g_fmtcmdfailed, argv[0], "mkdir", NSH_ERRNO);
}
nsh_freefullpath(fullpath);
@ -1259,7 +1259,7 @@ int cmd_mkfatfs(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
if (fmt.ff_fattype != 0 && fmt.ff_fattype != 12 &&
fmt.ff_fattype != 16 && fmt.ff_fattype != 32)
{
nsh_output(vtbl, g_fmtargrange, argv[0]);
nsh_error(vtbl, g_fmtargrange, argv[0]);
badarg = true;
}
break;
@ -1268,19 +1268,19 @@ int cmd_mkfatfs(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
fmt.ff_rootdirentries = atoi(optarg);
if (fmt.ff_rootdirentries < 0)
{
nsh_output(vtbl, g_fmtargrange, argv[0]);
nsh_error(vtbl, g_fmtargrange, argv[0]);
badarg = true;
}
break;
case ':':
nsh_output(vtbl, g_fmtargrequired, argv[0]);
nsh_error(vtbl, g_fmtargrequired, argv[0]);
badarg = true;
break;
case '?':
default:
nsh_output(vtbl, g_fmtarginvalid, argv[0]);
nsh_error(vtbl, g_fmtarginvalid, argv[0]);
badarg = true;
break;
}
@ -1300,18 +1300,18 @@ int cmd_mkfatfs(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
fullpath = nsh_getfullpath(vtbl, argv[optind]);
if (fullpath == NULL)
{
nsh_output(vtbl, g_fmtcmdoutofmemory, argv[0]);
nsh_error(vtbl, g_fmtcmdoutofmemory, argv[0]);
return ERROR;
}
}
else if (optind >= argc)
{
nsh_output(vtbl, g_fmttoomanyargs, argv[0]);
nsh_error(vtbl, g_fmttoomanyargs, argv[0]);
return ERROR;
}
else
{
nsh_output(vtbl, g_fmtargrequired, argv[0]);
nsh_error(vtbl, g_fmtargrequired, argv[0]);
return ERROR;
}
@ -1320,7 +1320,7 @@ int cmd_mkfatfs(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
ret = mkfatfs(fullpath, &fmt);
if (ret < 0)
{
nsh_output(vtbl, g_fmtcmdfailed, argv[0], "mkfatfs", NSH_ERRNO);
nsh_error(vtbl, g_fmtcmdfailed, argv[0], "mkfatfs", NSH_ERRNO);
}
nsh_freefullpath(fullpath);
@ -1346,7 +1346,7 @@ int cmd_mkfifo(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
ret = mkfifo(fullpath, 0777);
if (ret < 0)
{
nsh_output(vtbl, g_fmtcmdfailed, argv[0], "mkfifo", NSH_ERRNO);
nsh_error(vtbl, g_fmtcmdfailed, argv[0], "mkfifo", NSH_ERRNO);
}
nsh_freefullpath(fullpath);
@ -1384,7 +1384,7 @@ int cmd_mkrd(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
minor = atoi(optarg);
if (minor < 0 || minor > 255)
{
nsh_output(vtbl, g_fmtargrange, argv[0]);
nsh_error(vtbl, g_fmtargrange, argv[0]);
badarg = true;
}
break;
@ -1393,19 +1393,19 @@ int cmd_mkrd(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
sectsize = atoi(optarg);
if (minor < 0 || minor > 16384)
{
nsh_output(vtbl, g_fmtargrange, argv[0]);
nsh_error(vtbl, g_fmtargrange, argv[0]);
badarg = true;
}
break;
case ':':
nsh_output(vtbl, g_fmtargrequired, argv[0]);
nsh_error(vtbl, g_fmtargrequired, argv[0]);
badarg = true;
break;
case '?':
default:
nsh_output(vtbl, g_fmtarginvalid, argv[0]);
nsh_error(vtbl, g_fmtarginvalid, argv[0]);
badarg = true;
break;
}
@ -1455,7 +1455,7 @@ int cmd_mkrd(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
RDFLAG_WRENABLED | RDFLAG_FUNLINK);
if (ret < 0)
{
nsh_output(vtbl, g_fmtcmdfailed, argv[0], "ramdisk_register", NSH_ERRNO_OF(-ret));
nsh_error(vtbl, g_fmtcmdfailed, argv[0], "ramdisk_register", NSH_ERRNO_OF(-ret));
free(buffer);
return ERROR;
}
@ -1502,12 +1502,12 @@ int cmd_mksmartfs(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
sectorsize = atoi(optarg);
if (sectorsize < 256 || sectorsize > 16384)
{
nsh_output(vtbl, "Sector size must be 256-16384\n");
nsh_error(vtbl, "Sector size must be 256-16384\n");
return EINVAL;
}
if (sectorsize & (sectorsize-1))
{
nsh_output(vtbl, "Sector size must be power of 2\n");
nsh_error(vtbl, "Sector size must be power of 2\n");
return EINVAL;
}
@ -1535,7 +1535,7 @@ int cmd_mksmartfs(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
if (nrootdirs > 8 || nrootdirs < 1)
{
nsh_output(vtbl, "Invalid number of root directories specified\n");
nsh_error(vtbl, "Invalid number of root directories specified\n");
}
else
#endif
@ -1548,7 +1548,7 @@ int cmd_mksmartfs(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
#endif
if (ret < 0)
{
nsh_output(vtbl, g_fmtcmdfailed, argv[0], "mksmartfs", NSH_ERRNO);
nsh_error(vtbl, g_fmtcmdfailed, argv[0], "mksmartfs", NSH_ERRNO);
}
}
@ -1577,14 +1577,14 @@ int cmd_mv(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
oldpath = nsh_getfullpath(vtbl, argv[1]);
if (oldpath == NULL)
{
nsh_output(vtbl, g_fmtcmdoutofmemory, argv[0]);
nsh_error(vtbl, g_fmtcmdoutofmemory, argv[0]);
return ERROR;
}
newpath = nsh_getfullpath(vtbl, argv[2]);
if (newpath == NULL)
{
nsh_output(vtbl, g_fmtcmdoutofmemory, argv[0]);
nsh_error(vtbl, g_fmtcmdoutofmemory, argv[0]);
ret = ERROR;
goto errout_with_oldpath;
}
@ -1594,7 +1594,7 @@ int cmd_mv(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
ret = rename(oldpath, newpath);
if (ret < 0)
{
nsh_output(vtbl, g_fmtcmdfailed, argv[0], "rename", NSH_ERRNO);
nsh_error(vtbl, g_fmtcmdfailed, argv[0], "rename", NSH_ERRNO);
}
/* Free the file paths */
@ -1625,7 +1625,7 @@ int cmd_readlink(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
fullpath = nsh_getfullpath(vtbl, argv[1]);
if (fullpath == NULL)
{
nsh_output(vtbl, g_fmtcmdoutofmemory, argv[0]);
nsh_error(vtbl, g_fmtcmdoutofmemory, argv[0]);
return ERROR;
}
@ -1634,7 +1634,7 @@ int cmd_readlink(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
if (len < 0)
{
nsh_output(vtbl, g_fmtcmdfailed, "ls", "readlink", NSH_ERRNO);
nsh_error(vtbl, g_fmtcmdfailed, "ls", "readlink", NSH_ERRNO);
return ERROR;
}
@ -1660,7 +1660,7 @@ int cmd_rm(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
ret = unlink(fullpath);
if (ret < 0)
{
nsh_output(vtbl, g_fmtcmdfailed, argv[0], "unlink", NSH_ERRNO);
nsh_error(vtbl, g_fmtcmdfailed, argv[0], "unlink", NSH_ERRNO);
}
nsh_freefullpath(fullpath);
@ -1687,7 +1687,7 @@ int cmd_rmdir(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
ret = rmdir(fullpath);
if (ret < 0)
{
nsh_output(vtbl, g_fmtcmdfailed, argv[0], "rmdir", NSH_ERRNO);
nsh_error(vtbl, g_fmtcmdfailed, argv[0], "rmdir", NSH_ERRNO);
}
nsh_freefullpath(fullpath);
@ -1731,14 +1731,14 @@ int cmd_cmp(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
path1 = nsh_getfullpath(vtbl, argv[1]);
if (path1 == NULL)
{
nsh_output(vtbl, g_fmtargrequired, argv[0]);
nsh_error(vtbl, g_fmtargrequired, argv[0]);
goto errout;
}
path2 = nsh_getfullpath(vtbl, argv[2]);
if (path2 == NULL)
{
nsh_output(vtbl, g_fmtargrequired, argv[0]);
nsh_error(vtbl, g_fmtargrequired, argv[0]);
goto errout_with_path1;
}
@ -1747,14 +1747,14 @@ int cmd_cmp(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
fd1 = open(path1, O_RDONLY);
if (fd1 < 0)
{
nsh_output(vtbl, g_fmtcmdfailed, argv[0], "open", NSH_ERRNO);
nsh_error(vtbl, g_fmtcmdfailed, argv[0], "open", NSH_ERRNO);
goto errout_with_path2;
}
fd2 = open(path2, O_RDONLY);
if (fd2 < 0)
{
nsh_output(vtbl, g_fmtcmdfailed, argv[0], "open", NSH_ERRNO);
nsh_error(vtbl, g_fmtcmdfailed, argv[0], "open", NSH_ERRNO);
goto errout_with_fd1;
}
@ -1774,13 +1774,13 @@ int cmd_cmp(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
if (nbytesread1 < 0)
{
nsh_output(vtbl, g_fmtcmdfailed, argv[0], "read", NSH_ERRNO);
nsh_error(vtbl, g_fmtcmdfailed, argv[0], "read", NSH_ERRNO);
goto errout_with_fd2;
}
if (nbytesread2 < 0)
{
nsh_output(vtbl, g_fmtcmdfailed, argv[0], "read", NSH_ERRNO);
nsh_error(vtbl, g_fmtcmdfailed, argv[0], "read", NSH_ERRNO);
goto errout_with_fd2;
}
@ -1791,7 +1791,7 @@ int cmd_cmp(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
if (nbytesread1 != nbytesread2 ||
memcmp(buf1, buf2, nbytesread1) != 0)
{
nsh_output(vtbl, "files differ: byte %u\n", total_read);
nsh_error(vtbl, "files differ: byte %u\n", total_read);
goto errout_with_fd2;
}
@ -1841,14 +1841,14 @@ int cmd_truncate(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
if (strcmp(argv[1], "-s") != 0)
{
nsh_output(vtbl, g_fmtarginvalid, argv[0]);
nsh_error(vtbl, g_fmtarginvalid, argv[0]);
return ERROR;
}
length = strtoul(argv[2], &endptr, 0);
if (*endptr != '\0')
{
nsh_output(vtbl, g_fmtarginvalid, argv[0]);
nsh_error(vtbl, g_fmtarginvalid, argv[0]);
return ERROR;
}
@ -1857,7 +1857,7 @@ int cmd_truncate(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
fullpath = nsh_getfullpath(vtbl, argv[3]);
if (fullpath == NULL)
{
nsh_output(vtbl, g_fmtcmdoutofmemory, argv[0]);
nsh_error(vtbl, g_fmtcmdoutofmemory, argv[0]);
return ERROR;
}
@ -1877,7 +1877,7 @@ int cmd_truncate(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
int fd = creat(fullpath, 0666);
if (fd < 0)
{
nsh_output(vtbl, g_fmtcmdfailed, argv[0], "stat", NSH_ERRNO);
nsh_error(vtbl, g_fmtcmdfailed, argv[0], "stat", NSH_ERRNO);
ret = ERROR;
}
else
@ -1895,7 +1895,7 @@ int cmd_truncate(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
ret = ftruncate(fd, length);
if (ret < 0)
{
nsh_output(vtbl, g_fmtcmdfailed, argv[0], "ftruncate",
nsh_error(vtbl, g_fmtcmdfailed, argv[0], "ftruncate",
NSH_ERRNO);
}
}
@ -1905,14 +1905,14 @@ int cmd_truncate(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
}
else
{
nsh_output(vtbl, g_fmtcmdfailed, argv[0], "stat",
nsh_error(vtbl, g_fmtcmdfailed, argv[0], "stat",
NSH_ERRNO_OF(errval));
ret = ERROR;
}
}
else if (!S_ISREG(buf.st_mode))
{
nsh_output(vtbl, g_fmtarginvalid, argv[0]);
nsh_error(vtbl, g_fmtarginvalid, argv[0]);
ret = ERROR;
}
else
@ -1922,7 +1922,7 @@ int cmd_truncate(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
ret = truncate(fullpath, length);
if (ret < 0)
{
nsh_output(vtbl, g_fmtcmdfailed, argv[0], "truncate", NSH_ERRNO);
nsh_error(vtbl, g_fmtcmdfailed, argv[0], "truncate", NSH_ERRNO);
}
}

View File

@ -85,7 +85,7 @@ int nsh_catfile(FAR struct nsh_vtbl_s *vtbl, FAR const char *cmd,
fd = open(filepath, O_RDONLY);
if (fd < 0)
{
nsh_output(vtbl, g_fmtcmdfailed, cmd, "open", NSH_ERRNO);
nsh_error(vtbl, g_fmtcmdfailed, cmd, "open", NSH_ERRNO);
return ERROR;
}
@ -93,7 +93,7 @@ int nsh_catfile(FAR struct nsh_vtbl_s *vtbl, FAR const char *cmd,
if(buffer == NULL)
{
(void)close(fd);
nsh_output(vtbl, g_fmtcmdfailed, cmd, "malloc", NSH_ERRNO);
nsh_error(vtbl, g_fmtcmdfailed, cmd, "malloc", NSH_ERRNO);
return ERROR;
}
@ -114,12 +114,12 @@ int nsh_catfile(FAR struct nsh_vtbl_s *vtbl, FAR const char *cmd,
#ifndef CONFIG_DISABLE_SIGNALS
if (errval == EINTR)
{
nsh_output(vtbl, g_fmtsignalrecvd, cmd);
nsh_error(vtbl, g_fmtsignalrecvd, cmd);
}
else
#endif
{
nsh_output(vtbl, g_fmtcmdfailed, cmd, "read", NSH_ERRNO_OF(errval));
nsh_error(vtbl, g_fmtcmdfailed, cmd, "read", NSH_ERRNO_OF(errval));
}
ret = ERROR;
@ -145,12 +145,12 @@ int nsh_catfile(FAR struct nsh_vtbl_s *vtbl, FAR const char *cmd,
#ifndef CONFIG_DISABLE_SIGNALS
if (errcode == EINTR)
{
nsh_output(vtbl, g_fmtsignalrecvd, cmd);
nsh_error(vtbl, g_fmtsignalrecvd, cmd);
}
else
#endif
{
nsh_output(vtbl, g_fmtcmdfailed, cmd, "write",
nsh_error(vtbl, g_fmtcmdfailed, cmd, "write",
NSH_ERRNO_OF(errcode));
}
@ -228,7 +228,7 @@ int nsh_readfile(FAR struct nsh_vtbl_s *vtbl, FAR const char *cmd,
fd = open(filepath, O_RDONLY);
if (fd < 0)
{
nsh_output(vtbl, g_fmtcmdfailed, cmd, "open", NSH_ERRNO);
nsh_error(vtbl, g_fmtcmdfailed, cmd, "open", NSH_ERRNO);
return ERROR;
}
@ -260,7 +260,7 @@ int nsh_readfile(FAR struct nsh_vtbl_s *vtbl, FAR const char *cmd,
{
/* Fatal error */
nsh_output(vtbl, g_fmtcmdfailed, cmd, "read", NSH_ERRNO);
nsh_error(vtbl, g_fmtcmdfailed, cmd, "read", NSH_ERRNO);
break;
}
}
@ -330,7 +330,7 @@ int nsh_foreach_direntry(FAR struct nsh_vtbl_s *vtbl, FAR const char *cmd,
{
/* Failed to open the directory */
nsh_output(vtbl, g_fmtnosuch, cmd, "directory", dirpath);
nsh_error(vtbl, g_fmtnosuch, cmd, "directory", dirpath);
return ERROR;
}

View File

@ -140,13 +140,13 @@ int cmd_mount(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
break;
case ':':
nsh_output(vtbl, g_fmtargrequired, argv[0]);
nsh_error(vtbl, g_fmtargrequired, argv[0]);
badarg = true;
break;
case '?':
default:
nsh_output(vtbl, g_fmtarginvalid, argv[0]);
nsh_error(vtbl, g_fmtarginvalid, argv[0]);
badarg = true;
break;
}
@ -168,7 +168,7 @@ int cmd_mount(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
if (optind >= argc)
{
nsh_output(vtbl, g_fmtargrequired, argv[0]);
nsh_error(vtbl, g_fmtargrequired, argv[0]);
return ERROR;
}
@ -184,7 +184,7 @@ int cmd_mount(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
if (optind < argc)
{
nsh_output(vtbl, g_fmttoomanyargs, argv[0]);
nsh_error(vtbl, g_fmttoomanyargs, argv[0]);
return ERROR;
}
}
@ -195,7 +195,7 @@ int cmd_mount(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
if (!filesystem)
{
nsh_output(vtbl, g_fmtargrequired, argv[0]);
nsh_error(vtbl, g_fmtargrequired, argv[0]);
return ERROR;
}
@ -227,7 +227,7 @@ int cmd_mount(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
ret = mount(fullsource, fulltarget, filesystem, 0, options);
if (ret < 0)
{
nsh_output(vtbl, g_fmtcmdfailed, argv[0], "mount", NSH_ERRNO);
nsh_error(vtbl, g_fmtcmdfailed, argv[0], "mount", NSH_ERRNO);
}
errout:
@ -340,7 +340,7 @@ int cmd_nfsmount(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
ret = mount(NULL, lpath, "nfs", 0, (FAR void *)&data);
if (ret < 0)
{
nsh_output(vtbl, g_fmtcmdfailed, argv[0], "mount", NSH_ERRNO);
nsh_error(vtbl, g_fmtcmdfailed, argv[0], "mount", NSH_ERRNO);
}
/* We no longer need the allocated mount point path */
@ -368,7 +368,7 @@ int cmd_umount(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
ret = umount(fullpath);
if (ret < 0)
{
nsh_output(vtbl, g_fmtcmdfailed, argv[0], "umount", NSH_ERRNO);
nsh_error(vtbl, g_fmtcmdfailed, argv[0], "umount", NSH_ERRNO);
}
nsh_freefullpath(fullpath);

View File

@ -67,7 +67,7 @@ int cmd_insmod(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
handle = insmod(argv[1], argv[2]);
if (handle == NULL)
{
nsh_output(vtbl, g_fmtcmdfailed, argv[0], "insmod", NSH_ERRNO);
nsh_error(vtbl, g_fmtcmdfailed, argv[0], "insmod", NSH_ERRNO);
return ERROR;
}
@ -89,7 +89,7 @@ int cmd_rmmod(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
handle = modhandle(argv[1]);
if (handle == NULL)
{
nsh_output(vtbl, g_fmtcmdfailed, argv[0], "modhandle", NSH_ERRNO);
nsh_error(vtbl, g_fmtcmdfailed, argv[0], "modhandle", NSH_ERRNO);
return ERROR;
}
@ -98,7 +98,7 @@ int cmd_rmmod(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
ret = rmmod(handle);
if (ret < 0)
{
nsh_output(vtbl, g_fmtcmdfailed, argv[0], "rmmod", NSH_ERRNO);
nsh_error(vtbl, g_fmtcmdfailed, argv[0], "rmmod", NSH_ERRNO);
return ERROR;
}
@ -120,7 +120,7 @@ int cmd_lsmod(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
stream = fopen("/proc/modules", "r");
if (stream == NULL)
{
nsh_output(vtbl, g_fmtcmdfailed, argv[0], "fopen", NSH_ERRNO);
nsh_error(vtbl, g_fmtcmdfailed, argv[0], "fopen", NSH_ERRNO);
return ERROR;
}

View File

@ -242,19 +242,19 @@ int tftpc_parseargs(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv,
case 'h':
if (!netlib_ipv4addrconv(optarg, (FAR unsigned char*)&args->ipaddr))
{
nsh_output(vtbl, g_fmtarginvalid, argv[0]);
nsh_error(vtbl, g_fmtarginvalid, argv[0]);
badarg = true;
}
break;
case ':':
nsh_output(vtbl, g_fmtargrequired, argv[0]);
nsh_error(vtbl, g_fmtargrequired, argv[0]);
badarg = true;
break;
case '?':
default:
nsh_output(vtbl, g_fmtarginvalid, argv[0]);
nsh_error(vtbl, g_fmtarginvalid, argv[0]);
badarg = true;
break;
}
@ -377,7 +377,7 @@ static int nsh_foreach_netdev(nsh_netdev_callback_t callback,
dir = opendir(CONFIG_NSH_PROC_MOUNTPOINT "/net");
if (dir == NULL)
{
nsh_output(vtbl, g_fmtcmdfailed, cmd, "opendir", NSH_ERRNO);
nsh_error(vtbl, g_fmtcmdfailed, cmd, "opendir", NSH_ERRNO);
return ERROR;
}
@ -479,7 +479,7 @@ int cmd_get(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
if (tftpget(args.srcpath, fullpath, args.ipaddr, args.binary) != OK)
{
nsh_output(vtbl, g_fmtcmdfailed, argv[0], "tftpget", NSH_ERRNO);
nsh_error(vtbl, g_fmtcmdfailed, argv[0], "tftpget", NSH_ERRNO);
}
/* Release any allocated memory */
@ -707,13 +707,13 @@ int cmd_ifconfig(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
if (missingarg)
{
nsh_output(vtbl, g_fmtargrequired, argv[0]);
nsh_error(vtbl, g_fmtargrequired, argv[0]);
return ERROR;
}
if (badarg)
{
nsh_output(vtbl, g_fmtarginvalid, argv[0]);
nsh_error(vtbl, g_fmtarginvalid, argv[0]);
return ERROR;
}
@ -980,7 +980,7 @@ int cmd_nslookup(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
{
/* REVISIT: gethostbyname() does not set errno, but h_errno */
nsh_output(vtbl, g_fmtcmdfailed, argv[0], "gethostbyname", NSH_ERRNO);
nsh_error(vtbl, g_fmtcmdfailed, argv[0], "gethostbyname", NSH_ERRNO);
return ERROR;
}
@ -991,7 +991,7 @@ int cmd_nslookup(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
{
if (inet_ntop(AF_INET, host->h_addr, buffer, 48) == NULL)
{
nsh_output(vtbl, g_fmtcmdfailed, argv[0], "inet_ntop", NSH_ERRNO);
nsh_error(vtbl, g_fmtcmdfailed, argv[0], "inet_ntop", NSH_ERRNO);
return ERROR;
}
@ -1006,7 +1006,7 @@ int cmd_nslookup(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
if (inet_ntop(AF_INET6, host->h_addr, buffer, 48) == NULL)
{
nsh_output(vtbl, g_fmtcmdfailed, argv[0], "inet_ntop", NSH_ERRNO);
nsh_error(vtbl, g_fmtcmdfailed, argv[0], "inet_ntop", NSH_ERRNO);
return ERROR;
}
@ -1132,25 +1132,25 @@ int cmd_arp(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
errout_cmdfaild:
if (ret == -ENOENT)
{
nsh_output(vtbl, g_fmtnosuch, argv[0], "ARP entry", argv[2]);
nsh_error(vtbl, g_fmtnosuch, argv[0], "ARP entry", argv[2]);
}
else
{
nsh_output(vtbl, g_fmtcmdfailed, argv[0], "ioctl", NSH_ERRNO);
nsh_error(vtbl, g_fmtcmdfailed, argv[0], "ioctl", NSH_ERRNO);
}
return ERROR;
errout_missing:
nsh_output(vtbl, g_fmttoomanyargs, argv[0]);
nsh_error(vtbl, g_fmttoomanyargs, argv[0]);
return ERROR;
errout_toomany:
nsh_output(vtbl, g_fmtargrequired, argv[0]);
nsh_error(vtbl, g_fmtargrequired, argv[0]);
return ERROR;
errout_invalid:
nsh_output(vtbl, g_fmtarginvalid, argv[0]);
nsh_error(vtbl, g_fmtarginvalid, argv[0]);
return ERROR;
}
#endif
@ -1181,7 +1181,7 @@ int cmd_put(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
if (tftpput(fullpath, args.destpath, args.ipaddr, args.binary) != OK)
{
nsh_output(vtbl, g_fmtcmdfailed, argv[0], "tftpput", NSH_ERRNO);
nsh_error(vtbl, g_fmtcmdfailed, argv[0], "tftpput", NSH_ERRNO);
}
/* Release any allocated memory */
@ -1227,13 +1227,13 @@ int cmd_wget(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
break;
case ':':
nsh_output(vtbl, g_fmtargrequired, argv[0]);
nsh_error(vtbl, g_fmtargrequired, argv[0]);
badarg = true;
break;
case '?':
default:
nsh_output(vtbl, g_fmtarginvalid, argv[0]);
nsh_error(vtbl, g_fmtarginvalid, argv[0]);
badarg = true;
break;
}
@ -1282,7 +1282,7 @@ int cmd_wget(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
fd = open(fullpath, O_WRONLY|O_CREAT|O_TRUNC, 0644);
if (fd < 0)
{
nsh_output(vtbl, g_fmtcmdfailed, argv[0], "open", NSH_ERRNO);
nsh_error(vtbl, g_fmtcmdfailed, argv[0], "open", NSH_ERRNO);
ret = ERROR;
goto exit;
}
@ -1301,7 +1301,7 @@ int cmd_wget(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
ret = wget(url, buffer, 512, wget_callback, (FAR void *)((intptr_t)fd));
if (ret < 0)
{
nsh_output(vtbl, g_fmtcmdfailed, argv[0], "wget", NSH_ERRNO);
nsh_error(vtbl, g_fmtcmdfailed, argv[0], "wget", NSH_ERRNO);
goto exit;
}
@ -1331,7 +1331,7 @@ exit:
return ret;
errout:
nsh_output(vtbl, fmt, argv[0]);
nsh_error(vtbl, fmt, argv[0]);
ret = ERROR;
goto exit;
}

View File

@ -585,7 +585,7 @@ static int nsh_execute(FAR struct nsh_vtbl_s *vtbl,
fd = open(redirfile, oflags, 0666);
if (fd < 0)
{
nsh_output(vtbl, g_fmtcmdfailed, argv[0], "open", NSH_ERRNO);
nsh_error(vtbl, g_fmtcmdfailed, argv[0], "open", NSH_ERRNO);
goto errout;
}
}
@ -639,7 +639,7 @@ static int nsh_execute(FAR struct nsh_vtbl_s *vtbl,
ret = sched_getparam(0, &param);
if (ret != 0)
{
nsh_output(vtbl, g_fmtcmdfailed, argv[0], "sched_getparm", NSH_ERRNO);
nsh_error(vtbl, g_fmtcmdfailed, argv[0], "sched_getparm", NSH_ERRNO);
nsh_releaseargs(args);
nsh_release(bkgvtbl);
goto errout;
@ -681,7 +681,7 @@ static int nsh_execute(FAR struct nsh_vtbl_s *vtbl,
ret = pthread_create(&thread, &attr, nsh_child, (pthread_addr_t)args);
if (ret != 0)
{
nsh_output(vtbl, g_fmtcmdfailed, argv[0], "pthread_create", NSH_ERRNO_OF(ret));
nsh_error(vtbl, g_fmtcmdfailed, argv[0], "pthread_create", NSH_ERRNO_OF(ret));
nsh_releaseargs(args);
nsh_release(bkgvtbl);
goto errout;
@ -788,7 +788,7 @@ static FAR char *nsh_filecat(FAR struct nsh_vtbl_s *vtbl, FAR char *s1,
ret = stat(filename, &buf);
if (ret != 0)
{
nsh_output(vtbl, g_fmtcmdfailed, "``", "stat", NSH_ERRNO);
nsh_error(vtbl, g_fmtcmdfailed, "``", "stat", NSH_ERRNO);
return NULL;
}
@ -798,7 +798,7 @@ static FAR char *nsh_filecat(FAR struct nsh_vtbl_s *vtbl, FAR char *s1,
argument = (FAR char *)realloc(s1, allocsize);
if (!argument)
{
nsh_output(vtbl, g_fmtcmdoutofmemory, "``");
nsh_error(vtbl, g_fmtcmdoutofmemory, "``");
return NULL;
}
@ -807,7 +807,7 @@ static FAR char *nsh_filecat(FAR struct nsh_vtbl_s *vtbl, FAR char *s1,
fd = open(filename, O_RDONLY);
if (fd < 0)
{
nsh_output(vtbl, g_fmtcmdfailed, "``", "open", NSH_ERRNO);
nsh_error(vtbl, g_fmtcmdfailed, "``", "open", NSH_ERRNO);
goto errout_with_alloc;
}
@ -837,14 +837,14 @@ static FAR char *nsh_filecat(FAR struct nsh_vtbl_s *vtbl, FAR char *s1,
#ifndef CONFIG_DISABLE_SIGNALS
if (errno == EINTR)
{
nsh_output(vtbl, g_fmtsignalrecvd, "``");
nsh_error(vtbl, g_fmtsignalrecvd, "``");
}
else
#endif
{
/* Read error */
nsh_output(vtbl, g_fmtcmdfailed, "``", "read", NSH_ERRNO);
nsh_error(vtbl, g_fmtcmdfailed, "``", "read", NSH_ERRNO);
}
goto errout_with_fd;
@ -900,7 +900,7 @@ static FAR char *nsh_cmdparm(FAR struct nsh_vtbl_s *vtbl, FAR char *cmdline,
ret = asprintf(&tmpfile, "%s/TMP%d.dat", CONFIG_LIBC_TMPDIR, getpid());
if (ret < 0 || !tmpfile)
{
nsh_output(vtbl, g_fmtcmdoutofmemory, "``");
nsh_error(vtbl, g_fmtcmdoutofmemory, "``");
return (FAR char *)g_nullstring;
}
@ -914,7 +914,7 @@ static FAR char *nsh_cmdparm(FAR struct nsh_vtbl_s *vtbl, FAR char *cmdline,
{
/* Report the failure */
nsh_output(vtbl, g_fmtcmdfailed, "``", "exec", NSH_ERRNO);
nsh_error(vtbl, g_fmtcmdfailed, "``", "exec", NSH_ERRNO);
free(tmpfile);
return (FAR char *)g_nullstring;
}
@ -929,7 +929,7 @@ static FAR char *nsh_cmdparm(FAR struct nsh_vtbl_s *vtbl, FAR char *cmdline,
ret = unlink(tmpfile);
if (ret < 0)
{
nsh_output(vtbl, g_fmtcmdfailed, "``", "unlink", NSH_ERRNO);
nsh_error(vtbl, g_fmtcmdfailed, "``", "unlink", NSH_ERRNO);
}
free(tmpfile);
@ -964,7 +964,7 @@ static FAR char *nsh_strcat(FAR struct nsh_vtbl_s *vtbl, FAR char *s1,
argument = (FAR char *)realloc(s1, allocsize);
if (!argument)
{
nsh_output(vtbl, g_fmtcmdoutofmemory, "$");
nsh_error(vtbl, g_fmtcmdoutofmemory, "$");
argument = s1;
}
else
@ -1235,7 +1235,7 @@ static FAR char *nsh_argexpand(FAR struct nsh_vtbl_s *vtbl, FAR char *cmdline,
rptr = nsh_strchr(ptr, '`');
if (!rptr)
{
nsh_output(vtbl, g_fmtnomatching, "`", "`");
nsh_error(vtbl, g_fmtnomatching, "`", "`");
return (FAR char *)g_nullstring;
}
@ -1302,7 +1302,7 @@ static FAR char *nsh_argexpand(FAR struct nsh_vtbl_s *vtbl, FAR char *cmdline,
rptr = nsh_strchr(ptr, '}');
if (!rptr)
{
nsh_output(vtbl, g_fmtnomatching, "${", "}");
nsh_error(vtbl, g_fmtnomatching, "${", "}");
return (FAR char *)g_nullstring;
}
@ -1394,7 +1394,7 @@ static FAR char *nsh_argexpand(FAR struct nsh_vtbl_s *vtbl, FAR char *cmdline,
FAR char *rptr = nsh_strchr(cmdline + 1, '`');
if (!rptr || rptr[1] != '\0')
{
nsh_output(vtbl, g_fmtnomatching, "`", "`");
nsh_error(vtbl, g_fmtnomatching, "`", "`");
return (FAR char *)g_nullstring;
}
@ -1800,7 +1800,7 @@ static int nsh_loop(FAR struct nsh_vtbl_s *vtbl, FAR char **ppcmd,
*ppcmd = nsh_argument(vtbl, saveptr, memlist);
if (*ppcmd == NULL || **ppcmd == '\0')
{
nsh_output(vtbl, g_fmtarginvalid, cmd);
nsh_error(vtbl, g_fmtarginvalid, cmd);
goto errout;
}
@ -1814,7 +1814,7 @@ static int nsh_loop(FAR struct nsh_vtbl_s *vtbl, FAR char **ppcmd,
np->np_lpstate[np->np_lpndx].lp_state == NSH_LOOP_UNTIL ||
np->np_stream == NULL || np->np_foffs < 0)
{
nsh_output(vtbl, g_fmtcontext, cmd);
nsh_error(vtbl, g_fmtcontext, cmd);
goto errout;
}
@ -1822,7 +1822,7 @@ static int nsh_loop(FAR struct nsh_vtbl_s *vtbl, FAR char **ppcmd,
if (np->np_lpndx >= CONFIG_NSH_NESTDEPTH-1)
{
nsh_output(vtbl, g_fmtdeepnesting, cmd);
nsh_error(vtbl, g_fmtdeepnesting, cmd);
goto errout;
}
@ -1861,7 +1861,7 @@ static int nsh_loop(FAR struct nsh_vtbl_s *vtbl, FAR char **ppcmd,
if (np->np_lpstate[np->np_lpndx].lp_state != NSH_LOOP_WHILE &&
np->np_lpstate[np->np_lpndx].lp_state != NSH_LOOP_UNTIL)
{
nsh_output(vtbl, g_fmtcontext, "do");
nsh_error(vtbl, g_fmtcontext, "do");
goto errout;
}
@ -1877,7 +1877,7 @@ static int nsh_loop(FAR struct nsh_vtbl_s *vtbl, FAR char **ppcmd,
*ppcmd = nsh_argument(vtbl, saveptr, memlist);
if (*ppcmd)
{
nsh_output(vtbl, g_fmtarginvalid, "done");
nsh_error(vtbl, g_fmtarginvalid, "done");
goto errout;
}
@ -1885,13 +1885,13 @@ static int nsh_loop(FAR struct nsh_vtbl_s *vtbl, FAR char **ppcmd,
if (np->np_lpstate[np->np_lpndx].lp_state != NSH_LOOP_DO)
{
nsh_output(vtbl, g_fmtcontext, "done");
nsh_error(vtbl, g_fmtcontext, "done");
goto errout;
}
if (np->np_lpndx < 1) /* Shouldn't happen */
{
nsh_output(vtbl, g_fmtinternalerror, "done");
nsh_error(vtbl, g_fmtinternalerror, "done");
goto errout;
}
@ -1909,7 +1909,7 @@ static int nsh_loop(FAR struct nsh_vtbl_s *vtbl, FAR char **ppcmd,
SEEK_SET);
if (ret < 0)
{
nsh_output(vtbl, g_fmtcmdfailed, "done", "fseek", NSH_ERRNO);
nsh_error(vtbl, g_fmtcmdfailed, "done", "fseek", NSH_ERRNO);
}
#ifndef NSH_DISABLE_SEMICOLON
@ -1940,7 +1940,7 @@ static int nsh_loop(FAR struct nsh_vtbl_s *vtbl, FAR char **ppcmd,
else if (np->np_lpstate[np->np_lpndx].lp_state == NSH_LOOP_WHILE ||
np->np_lpstate[np->np_lpndx].lp_state == NSH_LOOP_UNTIL)
{
nsh_output(vtbl, g_fmtcontext, cmd);
nsh_error(vtbl, g_fmtcontext, cmd);
goto errout;
}
}
@ -1983,7 +1983,7 @@ static int nsh_itef(FAR struct nsh_vtbl_s *vtbl, FAR char **ppcmd,
*ppcmd = nsh_argument(vtbl, saveptr, memlist);
if (*ppcmd == NULL || **ppcmd == '\0')
{
nsh_output(vtbl, g_fmtarginvalid, "if");
nsh_error(vtbl, g_fmtarginvalid, "if");
goto errout;
}
@ -1998,7 +1998,7 @@ static int nsh_itef(FAR struct nsh_vtbl_s *vtbl, FAR char **ppcmd,
*ppcmd = nsh_argument(vtbl, saveptr, memlist);
if (*ppcmd == NULL || **ppcmd == '\0')
{
nsh_output(vtbl, g_fmtarginvalid, "if");
nsh_error(vtbl, g_fmtarginvalid, "if");
goto errout;
}
}
@ -2007,7 +2007,7 @@ static int nsh_itef(FAR struct nsh_vtbl_s *vtbl, FAR char **ppcmd,
if (np->np_iestate[np->np_iendx].ie_state == NSH_ITEF_IF)
{
nsh_output(vtbl, g_fmtcontext, "if");
nsh_error(vtbl, g_fmtcontext, "if");
goto errout;
}
@ -2015,7 +2015,7 @@ static int nsh_itef(FAR struct nsh_vtbl_s *vtbl, FAR char **ppcmd,
if (np->np_iendx >= CONFIG_NSH_NESTDEPTH-1)
{
nsh_output(vtbl, g_fmtdeepnesting, "if");
nsh_error(vtbl, g_fmtdeepnesting, "if");
goto errout;
}
@ -2041,7 +2041,7 @@ static int nsh_itef(FAR struct nsh_vtbl_s *vtbl, FAR char **ppcmd,
if (np->np_iestate[np->np_iendx].ie_state != NSH_ITEF_IF)
{
nsh_output(vtbl, g_fmtcontext, "then");
nsh_error(vtbl, g_fmtcontext, "then");
goto errout;
}
@ -2060,7 +2060,7 @@ static int nsh_itef(FAR struct nsh_vtbl_s *vtbl, FAR char **ppcmd,
if (np->np_iestate[np->np_iendx].ie_state != NSH_ITEF_THEN)
{
nsh_output(vtbl, g_fmtcontext, "else");
nsh_error(vtbl, g_fmtcontext, "else");
goto errout;
}
@ -2076,7 +2076,7 @@ static int nsh_itef(FAR struct nsh_vtbl_s *vtbl, FAR char **ppcmd,
*ppcmd = nsh_argument(vtbl, saveptr, memlist);
if (*ppcmd)
{
nsh_output(vtbl, g_fmtarginvalid, "fi");
nsh_error(vtbl, g_fmtarginvalid, "fi");
goto errout;
}
@ -2085,13 +2085,13 @@ static int nsh_itef(FAR struct nsh_vtbl_s *vtbl, FAR char **ppcmd,
if (np->np_iestate[np->np_iendx].ie_state != NSH_ITEF_THEN &&
np->np_iestate[np->np_iendx].ie_state != NSH_ITEF_ELSE)
{
nsh_output(vtbl, g_fmtcontext, "fi");
nsh_error(vtbl, g_fmtcontext, "fi");
goto errout;
}
if (np->np_iendx < 1) /* Shouldn't happen */
{
nsh_output(vtbl, g_fmtinternalerror, "if");
nsh_error(vtbl, g_fmtinternalerror, "if");
goto errout;
}
@ -2104,7 +2104,7 @@ static int nsh_itef(FAR struct nsh_vtbl_s *vtbl, FAR char **ppcmd,
else if (np->np_iestate[np->np_iendx].ie_state == NSH_ITEF_IF)
{
nsh_output(vtbl, g_fmtcontext, cmd);
nsh_error(vtbl, g_fmtcontext, cmd);
goto errout;
}
}
@ -2157,7 +2157,7 @@ static int nsh_nice(FAR struct nsh_vtbl_s *vtbl, FAR char **ppcmd,
if (vtbl->np.np_nice > 19 || vtbl->np.np_nice < -20 ||
endptr == val || *endptr != '\0')
{
nsh_output(vtbl, g_fmtarginvalid, "nice");
nsh_error(vtbl, g_fmtarginvalid, "nice");
return ERROR;
}
cmd = nsh_argument(vtbl, saveptr, memlist);
@ -2277,7 +2277,7 @@ static int nsh_parse_cmdparm(FAR struct nsh_vtbl_s *vtbl, FAR char *cmdline,
if (argc > CONFIG_NSH_MAXARGUMENTS)
{
nsh_output(vtbl, g_fmttoomanyargs, cmd);
nsh_error(vtbl, g_fmttoomanyargs, cmd);
}
/* Then execute the command */
@ -2452,7 +2452,7 @@ static int nsh_parse_command(FAR struct nsh_vtbl_s *vtbl, FAR char *cmdline)
if (argc > CONFIG_NSH_MAXARGUMENTS)
{
nsh_output(vtbl, g_fmttoomanyargs, cmd);
nsh_error(vtbl, g_fmttoomanyargs, cmd);
}
/* Then execute the command */
@ -2584,7 +2584,7 @@ int nsh_parse(FAR struct nsh_vtbl_s *vtbl, FAR char *cmdline)
{
/* No closing quotation mark! */
nsh_output(vtbl, g_fmtnomatching, "\"", "\"");
nsh_error(vtbl, g_fmtnomatching, "\"", "\"");
return ERROR;
}

View File

@ -64,8 +64,8 @@ int cmd_useradd(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
ret = passwd_adduser(argv[1], argv[2]);
if (ret < 0)
{
nsh_output(vtbl, g_fmtcmdfailed, argv[0], "passwd_adduser",
NSH_ERRNO_OF(-ret));
nsh_error(vtbl, g_fmtcmdfailed, argv[0], "passwd_adduser",
NSH_ERRNO_OF(-ret));
return ERROR;
}
@ -85,7 +85,7 @@ int cmd_userdel(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
ret = passwd_deluser(argv[1]);
if (ret < 0)
{
nsh_output(vtbl, g_fmtcmdfailed, argv[0], "passwd_deluser",
nsh_error(vtbl, g_fmtcmdfailed, argv[0], "passwd_deluser",
NSH_ERRNO_OF(-ret));
return ERROR;
}
@ -106,7 +106,7 @@ int cmd_passwd(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
ret = passwd_update(argv[1], argv[2]);
if (ret < 0)
{
nsh_output(vtbl, g_fmtcmdfailed, argv[0], "passwd_update",
nsh_error(vtbl, g_fmtcmdfailed, argv[0], "passwd_update",
NSH_ERRNO_OF(-ret));
return ERROR;
}

View File

@ -344,7 +344,7 @@ static int ps_callback(FAR struct nsh_vtbl_s *vtbl, FAR const char *dirpath,
ret = asprintf(&filepath, "%s/%s/status", dirpath, entryp->d_name);
if (ret < 0 || filepath == NULL)
{
nsh_output(vtbl, g_fmtcmdfailed, "ps", "asprintf", NSH_ERRNO);
nsh_error(vtbl, g_fmtcmdfailed, "ps", "asprintf", NSH_ERRNO);
}
else
{
@ -420,7 +420,7 @@ static int ps_callback(FAR struct nsh_vtbl_s *vtbl, FAR const char *dirpath,
ret = asprintf(&filepath, "%s/%s/stack", dirpath, entryp->d_name);
if (ret < 0 || filepath == NULL)
{
nsh_output(vtbl, g_fmtcmdfailed, "ps", "asprintf", NSH_ERRNO);
nsh_error(vtbl, g_fmtcmdfailed, "ps", "asprintf", NSH_ERRNO);
vtbl->iobuffer[0] = '\0';
}
else
@ -506,7 +506,7 @@ static int ps_callback(FAR struct nsh_vtbl_s *vtbl, FAR const char *dirpath,
ret = asprintf(&filepath, "%s/%s/loadavg", dirpath, entryp->d_name);
if (ret < 0 || filepath == NULL)
{
nsh_output(vtbl, g_fmtcmdfailed, "ps", "asprintf", NSH_ERRNO);
nsh_error(vtbl, g_fmtcmdfailed, "ps", "asprintf", NSH_ERRNO);
vtbl->iobuffer[0] = '\0';
}
else
@ -530,7 +530,7 @@ static int ps_callback(FAR struct nsh_vtbl_s *vtbl, FAR const char *dirpath,
if (ret < 0 || filepath == NULL)
{
nsh_output(vtbl, g_fmtcmdfailed, "ps", "asprintf", NSH_ERRNO);
nsh_error(vtbl, g_fmtcmdfailed, "ps", "asprintf", NSH_ERRNO);
return ERROR;
}
@ -564,7 +564,7 @@ int cmd_exec(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv)
addr = (uintptr_t)strtol(argv[1], &endptr, 0);
if (!addr || endptr == argv[1] || *endptr != '\0')
{
nsh_output(vtbl, g_fmtarginvalid, argv[0]);
nsh_error(vtbl, g_fmtarginvalid, argv[0]);
return ERROR;
}
@ -676,18 +676,18 @@ int cmd_kill(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
goto invalid_arg;
case ESRCH:
nsh_output(vtbl, g_fmtnosuch, argv[0], "task", argv[2]);
nsh_error(vtbl, g_fmtnosuch, argv[0], "task", argv[2]);
return ERROR;
case EPERM:
case ENOSYS:
default:
nsh_output(vtbl, g_fmtcmdfailed, argv[0], "kill", NSH_ERRNO);
nsh_error(vtbl, g_fmtcmdfailed, argv[0], "kill", NSH_ERRNO);
return ERROR;
}
invalid_arg:
nsh_output(vtbl, g_fmtarginvalid, argv[0]);
nsh_error(vtbl, g_fmtarginvalid, argv[0]);
return ERROR;
}
#endif
@ -707,7 +707,7 @@ int cmd_sleep(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
secs = strtol(argv[1], &endptr, 0);
if (!secs || endptr == argv[1] || *endptr != '\0')
{
nsh_output(vtbl, g_fmtarginvalid, argv[0]);
nsh_error(vtbl, g_fmtarginvalid, argv[0]);
return ERROR;
}
@ -731,7 +731,7 @@ int cmd_usleep(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
usecs = strtol(argv[1], &endptr, 0);
if (!usecs || endptr == argv[1] || *endptr != '\0')
{
nsh_output(vtbl, g_fmtarginvalid, argv[0]);
nsh_error(vtbl, g_fmtarginvalid, argv[0]);
return ERROR;
}

View File

@ -162,12 +162,12 @@ int cmd_addroute(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
if (shift > 0 && argc != 3)
{
nsh_output(vtbl, g_fmttoomanyargs, argv[0]);
nsh_error(vtbl, g_fmttoomanyargs, argv[0]);
goto errout;
}
else if (shift < 0 && argc != 4)
{
nsh_output(vtbl, g_fmtargrequired, argv[0]);
nsh_error(vtbl, g_fmtargrequired, argv[0]);
goto errout;
}
@ -187,7 +187,7 @@ int cmd_addroute(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
if (ret != 1)
#endif
{
nsh_output(vtbl, g_fmtarginvalid, argv[0]);
nsh_error(vtbl, g_fmtarginvalid, argv[0]);
goto errout;
}
}
@ -197,7 +197,7 @@ int cmd_addroute(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
sockfd = socket(family, NETLIB_SOCK_TYPE, 0);
if (sockfd < 0)
{
nsh_output(vtbl, g_fmtcmdfailed, argv[0], "socket", NSH_ERRNO);
nsh_error(vtbl, g_fmtcmdfailed, argv[0], "socket", NSH_ERRNO);
goto errout;
}
@ -243,7 +243,7 @@ int cmd_addroute(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
if (shift > 32)
{
nsh_output(vtbl, g_fmtarginvalid, argv[0]);
nsh_error(vtbl, g_fmtarginvalid, argv[0]);
goto errout_with_sockfd;
}
@ -273,7 +273,7 @@ int cmd_addroute(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
if (shift > 16 || (shift > 0 && i >= 8))
{
nsh_output(vtbl, g_fmtarginvalid, argv[0]);
nsh_error(vtbl, g_fmtarginvalid, argv[0]);
goto errout_with_sockfd;
}
@ -299,7 +299,7 @@ int cmd_addroute(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
ret = inet_pton(family, argv[2], &inaddr);
if (ret != 1)
{
nsh_output(vtbl, g_fmtarginvalid, argv[0]);
nsh_error(vtbl, g_fmtarginvalid, argv[0]);
goto errout_with_sockfd;
}
@ -336,7 +336,7 @@ int cmd_addroute(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
ret = inet_pton(family, argv[rtrndx], &inaddr);
if (ret != 1)
{
nsh_output(vtbl, g_fmtarginvalid, argv[0]);
nsh_error(vtbl, g_fmtarginvalid, argv[0]);
goto errout_with_sockfd;
}
@ -373,7 +373,7 @@ int cmd_addroute(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
(FAR struct sockaddr_storage *)&router);
if (ret < 0)
{
nsh_output(vtbl, g_fmtcmdfailed, argv[0], "addroute", NSH_ERRNO);
nsh_error(vtbl, g_fmtcmdfailed, argv[0], "addroute", NSH_ERRNO);
goto errout_with_sockfd;
}
@ -442,12 +442,12 @@ int cmd_delroute(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
if (shift > 0 && argc != 2)
{
nsh_output(vtbl, g_fmttoomanyargs, argv[0]);
nsh_error(vtbl, g_fmttoomanyargs, argv[0]);
goto errout;
}
else if (shift < 0 && argc != 3)
{
nsh_output(vtbl, g_fmtargrequired, argv[0]);
nsh_error(vtbl, g_fmtargrequired, argv[0]);
goto errout;
}
@ -467,7 +467,7 @@ int cmd_delroute(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
if (ret != 1)
#endif
{
nsh_output(vtbl, g_fmtarginvalid, argv[0]);
nsh_error(vtbl, g_fmtarginvalid, argv[0]);
goto errout;
}
}
@ -477,7 +477,7 @@ int cmd_delroute(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
sockfd = socket(family, NETLIB_SOCK_TYPE, 0);
if (sockfd < 0)
{
nsh_output(vtbl, g_fmtcmdfailed, argv[0], "socket", NSH_ERRNO);
nsh_error(vtbl, g_fmtcmdfailed, argv[0], "socket", NSH_ERRNO);
goto errout;
}
@ -523,7 +523,7 @@ int cmd_delroute(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
if (shift > 32)
{
nsh_output(vtbl, g_fmtarginvalid, argv[0]);
nsh_error(vtbl, g_fmtarginvalid, argv[0]);
goto errout_with_sockfd;
}
@ -553,7 +553,7 @@ int cmd_delroute(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
if (shift > 16 || (shift > 0 && i >= 8))
{
nsh_output(vtbl, g_fmtarginvalid, argv[0]);
nsh_error(vtbl, g_fmtarginvalid, argv[0]);
goto errout_with_sockfd;
}
@ -578,7 +578,7 @@ int cmd_delroute(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
ret = inet_pton(family, argv[2], &inaddr);
if (ret != 1)
{
nsh_output(vtbl, g_fmtarginvalid, argv[0]);
nsh_error(vtbl, g_fmtarginvalid, argv[0]);
goto errout_with_sockfd;
}
}
@ -615,7 +615,7 @@ int cmd_delroute(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
(FAR struct sockaddr_storage *)&netmask);
if (ret < 0)
{
nsh_output(vtbl, g_fmtcmdfailed, argv[0], "delroute", NSH_ERRNO);
nsh_error(vtbl, g_fmtcmdfailed, argv[0], "delroute", NSH_ERRNO);
goto errout_with_sockfd;
}
@ -660,19 +660,19 @@ int cmd_route(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
else
{
nsh_output(vtbl, g_fmtarginvalid, argv[0]);
nsh_error(vtbl, g_fmtarginvalid, argv[0]);
return ERROR;
}
#elif defined(CONFIG_NET_IPv4)
if (argc == 2 && strcmp(argv[1], "ipv4") != 0)
{
nsh_output(vtbl, g_fmtarginvalid, argv[0]);
nsh_error(vtbl, g_fmtarginvalid, argv[0]);
return ERROR;
}
#else
if (argc == 2 && strcmp(argv[1], "ipv6") != 0)
{
nsh_output(vtbl, g_fmtarginvalid, argv[0]);
nsh_error(vtbl, g_fmtarginvalid, argv[0]);
return ERROR;
}
#endif

View File

@ -88,7 +88,7 @@ int nsh_script(FAR struct nsh_vtbl_s *vtbl, FAR const char *cmd,
vtbl->np.np_stream = fopen(fullpath, "r");
if (!vtbl->np.np_stream)
{
nsh_output(vtbl, g_fmtcmdfailed, cmd, "fopen", NSH_ERRNO);
nsh_error(vtbl, g_fmtcmdfailed, cmd, "fopen", NSH_ERRNO);
/* Free the allocated path */
@ -122,7 +122,7 @@ int nsh_script(FAR struct nsh_vtbl_s *vtbl, FAR const char *cmd,
if (vtbl->np.np_foffs < 0)
{
nsh_output(vtbl, g_fmtcmdfailed, "loop", "ftell", NSH_ERRNO);
nsh_error(vtbl, g_fmtcmdfailed, "loop", "ftell", NSH_ERRNO);
}
#endif

View File

@ -163,7 +163,7 @@ int nsh_session(FAR struct console_stdio_s *pstate)
else
{
fprintf(pstate->cn_outstream, g_fmtcmdfailed, "nsh_session",
fprintf(pstate->cn_errstream, g_fmtcmdfailed, "nsh_session",
"readline", NSH_ERRNO_OF(-ret));
return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
}

View File

@ -1,169 +0,0 @@
/****************************************************************************
* apps/nshlib/nsh_slcd.c
*
* Copyright (C) 2018 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
* Author: Alan Carvalho de Assis <acassis@gmail.com>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <assert.h>
#include <debug.h>
#include "nsh.h"
#include "nsh_console.h"
#if defined(HAVE_SLCD_CONSOLE)
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Name: nsh_clone_console
*
* Description:
* Wait for the USB keyboard device to be ready
*
****************************************************************************/
static int nsh_clone_console(FAR struct console_stdio_s *pstate)
{
int fd;
/* Close stdin */
(void)fclose(stdout);
(void)fclose(stderr);
/* Open the console */
fd = open(CONFIG_NSH_SLCDCONDEV, O_WRONLY);
if (fd < 0)
{
return -ENODEV;
}
/* Associate /dev/slcd0 to stdout/stderr */
(void)dup2(fd, 1);
(void)dup2(fd, 2);
/* Close the console device that we just opened */
if (fd != 0)
{
close(fd);
}
(void)fdopen(1, "a");
(void)fdopen(2, "a");
return OK;
}
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: nsh_consolemain (USB console version)
*
* Description:
* This interfaces maybe to called or started with task_start to start a
* single an NSH instance that operates on stdin and stdout. This
* function does not return.
*
* This function handles generic /dev/console character devices for output
* but uses a special USB keyboard device for input. The USB keyboard
* requires some special operations to handle the cases where the session
* input is lost when the USB keyboard is unplugged and restarted when the
* USB keyboard is plugged in again.
*
* Input Parameters:
* Standard task start-up arguments. These are not used. argc may be
* zero and argv may be NULL.
*
* Returned Values:
* This function does not return nor does it ever exit (unless the user
* executes the NSH exit command).
*
****************************************************************************/
int nsh_consolemain(int argc, char *argv[])
{
FAR struct console_stdio_s *pstate = nsh_newconsole();
int ret;
DEBUGASSERT(pstate);
/* Execute the one-time start-up script. Any output will go to
* /dev/console.
*/
#ifdef CONFIG_NSH_ROMFSETC
(void)nsh_initscript(&pstate->cn_vtbl);
#endif
#if defined(CONFIG_NSH_ARCHINIT) && defined(CONFIG_BOARDCTL_FINALINIT)
/* Perform architecture-specific final-initialization (if configured) */
(void)boardctl(BOARDIOC_FINALINIT, 0);
#endif
/* Try to associate /dev/console as stdin because otherwise /dev/slcd0
* will be it
*/
ret = nsh_clone_console(pstate);
if (ret < 0)
{
return ret;
}
/* Execute the session */
(void)nsh_session(pstate);
return OK;
}
#endif /* HAVE_SLCD_CONSOLE */

View File

@ -115,7 +115,7 @@ int cmd_shutdown(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
if (strcmp(argv[1], "--reboot") != 0)
{
nsh_output(vtbl, g_fmtarginvalid, argv[0]);
nsh_error(vtbl, g_fmtarginvalid, argv[0]);
return ERROR;
}
@ -145,7 +145,7 @@ int cmd_shutdown(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
if (strcmp(argv[1], "--reboot") != 0)
{
nsh_output(vtbl, g_fmtarginvalid, argv[0]);
nsh_error(vtbl, g_fmtarginvalid, argv[0]);
return ERROR;
}
@ -173,7 +173,7 @@ int cmd_shutdown(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
* there was a problem with the shutdown/resaet operaion.
*/
nsh_output(vtbl, g_fmtcmdfailed, argv[0], "boardctl", NSH_ERRNO);
nsh_error(vtbl, g_fmtcmdfailed, argv[0], "boardctl", NSH_ERRNO);
return ERROR;
}
#endif /* CONFIG_BOARDCTL_POWEROFF && !CONFIG_NSH_DISABLE_SHUTDOWN */
@ -203,7 +203,7 @@ int cmd_poweroff(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
* there was a problem with the shutdown operaion.
*/
nsh_output(vtbl, g_fmtcmdfailed, argv[0], "boardctl", NSH_ERRNO);
nsh_error(vtbl, g_fmtcmdfailed, argv[0], "boardctl", NSH_ERRNO);
return ERROR;
}
#endif
@ -233,7 +233,7 @@ int cmd_reboot(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
* there was a problem with the reset operaion.
*/
nsh_output(vtbl, g_fmtcmdfailed, argv[0], "boardctl", NSH_ERRNO);
nsh_error(vtbl, g_fmtcmdfailed, argv[0], "boardctl", NSH_ERRNO);
return ERROR;
}
#endif
@ -303,7 +303,7 @@ int cmd_uname(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
case '?':
default:
nsh_output(vtbl, g_fmtarginvalid, argv[0]);
nsh_error(vtbl, g_fmtarginvalid, argv[0]);
badarg = true;
break;
}
@ -330,7 +330,7 @@ int cmd_uname(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
ret = uname(&info);
if (ret < 0)
{
nsh_output(vtbl, g_fmtcmdfailed, argv[0], "uname", NSH_ERRNO);
nsh_error(vtbl, g_fmtcmdfailed, argv[0], "uname", NSH_ERRNO);
return ERROR;
}
@ -375,7 +375,7 @@ int cmd_uname(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
break;
default:
nsh_output(vtbl, g_fmtarginvalid, argv[0]);
nsh_error(vtbl, g_fmtarginvalid, argv[0]);
return ERROR;
}

View File

@ -180,7 +180,7 @@ static int nsh_telnetmain(int argc, char *argv[])
}
else
{
fprintf(pstate->cn_outstream, g_fmtcmdfailed, "nsh_telnetmain",
fprintf(pstate->cn_errstream, g_fmtcmdfailed, "nsh_telnetmain",
"cle/readline/fgets", NSH_ERRNO);
nsh_exit(vtbl, 1);
}

View File

@ -410,7 +410,7 @@ static int expression(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
return value;
errout_syntax:
nsh_output(vtbl, g_fmtsyntax, "test");
nsh_error(vtbl, g_fmtsyntax, "test");
return TEST_FALSE;
}
@ -439,7 +439,7 @@ int cmd_lbracket(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
if (strcmp(argv[argc - 1], "]") != 0)
{
nsh_output(vtbl, g_fmtsyntax, argv[0]);
nsh_error(vtbl, g_fmtsyntax, argv[0]);
return ERROR;
}

View File

@ -125,7 +125,7 @@ static inline int date_showtime(FAR struct nsh_vtbl_s *vtbl, FAR const char *nam
ret = clock_gettime(CLOCK_REALTIME, &ts);
if (ret < 0)
{
nsh_output(vtbl, g_fmtcmdfailed, name, "clock_gettime", NSH_ERRNO);
nsh_error(vtbl, g_fmtcmdfailed, name, "clock_gettime", NSH_ERRNO);
return ERROR;
}
@ -133,7 +133,7 @@ static inline int date_showtime(FAR struct nsh_vtbl_s *vtbl, FAR const char *nam
if (gmtime_r((FAR const time_t*)&ts.tv_sec, &tm) == NULL)
{
nsh_output(vtbl, g_fmtcmdfailed, name, "gmtime_r", NSH_ERRNO);
nsh_error(vtbl, g_fmtcmdfailed, name, "gmtime_r", NSH_ERRNO);
return ERROR;
}
@ -142,7 +142,7 @@ static inline int date_showtime(FAR struct nsh_vtbl_s *vtbl, FAR const char *nam
ret = strftime(timbuf, MAX_TIME_STRING, format, &tm);
if (ret < 0)
{
nsh_output(vtbl, g_fmtcmdfailed, name, "strftime", NSH_ERRNO);
nsh_error(vtbl, g_fmtcmdfailed, name, "strftime", NSH_ERRNO);
return ERROR;
}
@ -269,14 +269,14 @@ static inline int date_settime(FAR struct nsh_vtbl_s *vtbl, FAR const char *name
ret = clock_settime(CLOCK_REALTIME, &ts);
if (ret < 0)
{
nsh_output(vtbl, g_fmtcmdfailed, name, "clock_settime", NSH_ERRNO);
nsh_error(vtbl, g_fmtcmdfailed, name, "clock_settime", NSH_ERRNO);
return ERROR;
}
return OK;
errout_bad_parm:
nsh_output(vtbl, g_fmtarginvalid, name);
nsh_error(vtbl, g_fmtarginvalid, name);
return ERROR;
}
#endif
@ -306,7 +306,7 @@ int cmd_time(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
ret = clock_gettime(TIME_CLOCK, &start);
if (ret < 0)
{
nsh_output(vtbl, g_fmtcmdfailed, argv[0], "clock_gettime", NSH_ERRNO);
nsh_error(vtbl, g_fmtcmdfailed, argv[0], "clock_gettime", NSH_ERRNO);
return ERROR;
}
@ -332,7 +332,7 @@ int cmd_time(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
ret = clock_gettime(TIME_CLOCK, &end);
if (ret < 0)
{
nsh_output(vtbl, g_fmtcmdfailed, argv[0], "clock_gettime", NSH_ERRNO);
nsh_error(vtbl, g_fmtcmdfailed, argv[0], "clock_gettime", NSH_ERRNO);
ret = ERROR;
}
else
@ -426,7 +426,7 @@ int cmd_date(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
return ret;
errout:
nsh_output(vtbl, errfmt, argv[0]);
nsh_error(vtbl, errfmt, argv[0]);
return ERROR;
}
#endif