mirror of
https://github.com/apache/nuttx.git
synced 2026-06-07 17:33:08 +08:00
Added 130 and if-then-else-fi to NSH
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@828 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
+49
-20
@@ -112,8 +112,32 @@
|
||||
* Public Types
|
||||
****************************************************************************/
|
||||
|
||||
enum nsh_parser_e
|
||||
{
|
||||
NSH_PARSER_NORMAL = 0,
|
||||
NSH_PARSER_IF,
|
||||
NSH_PARSER_THEN,
|
||||
NSH_PARSER_ELSE
|
||||
};
|
||||
|
||||
struct nsh_parser_s
|
||||
{
|
||||
boolean np_bg; /* TRUE: The last command executed in background */
|
||||
boolean np_redirect; /* TRUE: Output from the last command was re-directed */
|
||||
boolean np_fail; /* TRUE: The last command failed */
|
||||
boolean np_ifcond; /* Value of command in 'if' statement */
|
||||
ubyte np_state; /* Parser state (see enum nsh_parser_e) */
|
||||
int np_nice; /* "nice" value applied to last background cmd */
|
||||
};
|
||||
|
||||
struct nsh_vtbl_s
|
||||
{
|
||||
/* This function pointers are "hooks" into the front end logic to
|
||||
* handle things like output of command results, redirection, etc.
|
||||
* -- all of which must be done in a way that is unique to the nature
|
||||
* of the front end.
|
||||
*/
|
||||
|
||||
FAR struct nsh_vtbl_s *(*clone)(FAR struct nsh_vtbl_s *vtbl);
|
||||
void (*addref)(FAR struct nsh_vtbl_s *vtbl);
|
||||
void (*release)(FAR struct nsh_vtbl_s *vtbl);
|
||||
@@ -122,9 +146,13 @@ struct nsh_vtbl_s
|
||||
void (*redirect)(FAR struct nsh_vtbl_s *vtbl, int fd, FAR ubyte *save);
|
||||
void (*undirect)(FAR struct nsh_vtbl_s *vtbl, FAR ubyte *save);
|
||||
void (*exit)(FAR struct nsh_vtbl_s *vtbl);
|
||||
|
||||
/* Parser state data */
|
||||
|
||||
struct nsh_parser_s np;
|
||||
};
|
||||
|
||||
typedef void (*cmd_t)(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
|
||||
typedef int (*cmd_t)(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
|
||||
|
||||
/****************************************************************************
|
||||
* Public Data
|
||||
@@ -137,6 +165,7 @@ extern const char g_fmtcmdnotfound[];
|
||||
extern const char g_fmtcmdnotimpl[];
|
||||
extern const char g_fmtnosuch[];
|
||||
extern const char g_fmttoomanyargs[];
|
||||
extern const char g_fmtcontext[];
|
||||
extern const char g_fmtcmdfailed[];
|
||||
extern const char g_fmtcmdoutofmemory[];
|
||||
|
||||
@@ -160,42 +189,42 @@ extern int nsh_telnetmain(int argc, char *argv[]);
|
||||
|
||||
/* Shell command handlers */
|
||||
|
||||
extern void cmd_echo(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
|
||||
extern void cmd_exec(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
|
||||
extern void cmd_ps(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
|
||||
extern int cmd_echo(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
|
||||
extern int cmd_exec(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
|
||||
extern int cmd_ps(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
|
||||
|
||||
#if CONFIG_NFILE_DESCRIPTORS > 0
|
||||
extern void cmd_cat(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
|
||||
extern void cmd_cp(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
|
||||
extern void cmd_ls(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
|
||||
extern int cmd_cat(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
|
||||
extern int cmd_cp(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
|
||||
extern int cmd_ls(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
|
||||
# if CONFIG_NFILE_STREAMS > 0
|
||||
extern void cmd_sh(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
|
||||
extern int cmd_sh(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
|
||||
# endif /* CONFIG_NFILE_STREAMS */
|
||||
# ifndef CONFIG_DISABLE_MOUNTPOINT
|
||||
extern void cmd_mkdir(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
|
||||
extern void cmd_mkfifo(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
|
||||
extern void cmd_rm(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
|
||||
extern void cmd_rmdir(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
|
||||
extern int cmd_mkdir(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
|
||||
extern int cmd_mkfifo(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
|
||||
extern int cmd_rm(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
|
||||
extern int cmd_rmdir(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
|
||||
# ifdef CONFIG_FS_FAT
|
||||
extern void cmd_mkfatfs(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
|
||||
extern void cmd_mount(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
|
||||
extern void cmd_umount(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
|
||||
extern int cmd_mkfatfs(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
|
||||
extern int cmd_mount(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
|
||||
extern int cmd_umount(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
|
||||
# endif /* CONFIG_FS_FAT */
|
||||
# endif /* !CONFIG_DISABLE_MOUNTPOINT */
|
||||
#endif /* CONFIG_NFILE_DESCRIPTORS */
|
||||
|
||||
#if defined(CONFIG_NET) && CONFIG_NSOCKET_DESCRIPTORS > 0
|
||||
extern void cmd_ifconfig(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
|
||||
extern int cmd_ifconfig(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_DISABLE_ENVIRON
|
||||
extern void cmd_set(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
|
||||
extern void cmd_unset(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
|
||||
extern int cmd_set(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
|
||||
extern int cmd_unset(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
|
||||
#endif /* CONFIG_DISABLE_ENVIRON */
|
||||
|
||||
#ifndef CONFIG_DISABLE_SIGNALS
|
||||
extern void cmd_sleep(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
|
||||
extern void cmd_usleep(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
|
||||
extern int cmd_sleep(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
|
||||
extern int cmd_usleep(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
|
||||
#endif /* CONFIG_DISABLE_SIGNALS */
|
||||
|
||||
#endif /* __NSH_H */
|
||||
|
||||
@@ -79,7 +79,7 @@
|
||||
* Name: cmd_echo
|
||||
****************************************************************************/
|
||||
|
||||
void cmd_echo(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
||||
int cmd_echo(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
||||
{
|
||||
int i;
|
||||
|
||||
@@ -92,6 +92,7 @@ void cmd_echo(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
||||
nsh_output(vtbl, "%s ", argv[i]);
|
||||
}
|
||||
nsh_output(vtbl, "\n");
|
||||
return OK;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
@@ -99,12 +100,14 @@ void cmd_echo(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef CONFIG_DISABLE_ENVIRON
|
||||
void cmd_set(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
||||
int cmd_set(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
||||
{
|
||||
if (setenv(argv[1], argv[2], TRUE) < 0)
|
||||
int ret = setenv(argv[1], argv[2], TRUE);
|
||||
if (ret < 0)
|
||||
{
|
||||
nsh_output(vtbl, g_fmtcmdfailed, argv[0], "setenv", NSH_ERRNO);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -113,11 +116,13 @@ void cmd_set(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef CONFIG_DISABLE_ENVIRON
|
||||
void cmd_unset(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
||||
int cmd_unset(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
||||
{
|
||||
if (unsetenv(argv[1]) < 0)
|
||||
int ret = unsetenv(argv[1]);
|
||||
if (ret < 0)
|
||||
{
|
||||
nsh_output(vtbl, g_fmtcmdfailed, argv[0], "unsetenv", NSH_ERRNO);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
+57
-38
@@ -237,7 +237,7 @@ static int ls_handler(FAR struct nsh_vtbl_s *vtbl, const char *dirpath, struct d
|
||||
if (ret != 0)
|
||||
{
|
||||
nsh_output(vtbl, g_fmtcmdfailed, "ls", "stat", NSH_ERRNO);
|
||||
return OK;
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
if ((lsflags & LSFLAGS_LONG) != 0)
|
||||
@@ -337,6 +337,7 @@ static int ls_handler(FAR struct nsh_vtbl_s *vtbl, const char *dirpath, struct d
|
||||
#if CONFIG_NFILE_DESCRIPTORS > 0
|
||||
static int ls_recursive(FAR struct nsh_vtbl_s *vtbl, const char *dirpath, struct dirent *entryp, void *pvarg)
|
||||
{
|
||||
int ret = OK;
|
||||
/* Is this entry a directory? */
|
||||
|
||||
if (DIRENT_ISDIRECTORY(entryp->d_type))
|
||||
@@ -349,14 +350,16 @@ static int ls_recursive(FAR struct nsh_vtbl_s *vtbl, const char *dirpath, struct
|
||||
/* List the directory contents */
|
||||
|
||||
nsh_output(vtbl, "%s:\n", newpath);
|
||||
foreach_direntry(vtbl, "ls", newpath, ls_handler, pvarg);
|
||||
ret = foreach_direntry(vtbl, "ls", newpath, ls_handler, pvarg);
|
||||
if (ret == 0)
|
||||
{
|
||||
/* Then recurse to list each directory within the directory */
|
||||
|
||||
/* Then recurse to list each directory within the directory */
|
||||
|
||||
foreach_direntry(vtbl, "ls", newpath, ls_recursive, pvarg);
|
||||
free(newpath);
|
||||
ret = foreach_direntry(vtbl, "ls", newpath, ls_recursive, pvarg);
|
||||
free(newpath);
|
||||
}
|
||||
}
|
||||
return OK;
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -369,9 +372,10 @@ static int ls_recursive(FAR struct nsh_vtbl_s *vtbl, const char *dirpath, struct
|
||||
****************************************************************************/
|
||||
|
||||
#if CONFIG_NFILE_DESCRIPTORS > 0
|
||||
void cmd_cat(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
||||
int cmd_cat(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
||||
{
|
||||
char buffer[IOBUFFERSIZE];
|
||||
int ret = ERROR;
|
||||
|
||||
/* Open the file for reading */
|
||||
|
||||
@@ -379,7 +383,7 @@ void cmd_cat(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
||||
if (fd < 0)
|
||||
{
|
||||
nsh_output(vtbl, g_fmtcmdfailed, argv[0], "open", NSH_ERRNO);
|
||||
return;
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
/* And just dump it byte for byte into stdout */
|
||||
@@ -431,11 +435,13 @@ void cmd_cat(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
||||
|
||||
else
|
||||
{
|
||||
ret = OK;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
(void)close(fd);
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -444,7 +450,7 @@ void cmd_cat(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
||||
****************************************************************************/
|
||||
|
||||
#if CONFIG_NFILE_DESCRIPTORS > 0
|
||||
void cmd_cp(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
||||
int cmd_cp(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
||||
{
|
||||
struct stat buf;
|
||||
char *fullpath = NULL;
|
||||
@@ -452,7 +458,7 @@ void cmd_cp(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
||||
int oflags = O_WRONLY|O_CREAT|O_TRUNC;
|
||||
int rdfd;
|
||||
int wrfd;
|
||||
int ret;
|
||||
int ret = ERROR;
|
||||
|
||||
/* Open the source file for reading */
|
||||
|
||||
@@ -460,7 +466,7 @@ void cmd_cp(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
||||
if (rdfd < 0)
|
||||
{
|
||||
nsh_output(vtbl, g_fmtcmdfailed, argv[0], "open", NSH_ERRNO);
|
||||
return;
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
/* Check if the destination is a directory */
|
||||
@@ -519,6 +525,7 @@ void cmd_cp(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
||||
{
|
||||
/* End of file */
|
||||
|
||||
ret = OK;
|
||||
goto out_with_wrfd;
|
||||
}
|
||||
else if (nbytesread < 0 && errno != EINTR)
|
||||
@@ -560,6 +567,7 @@ out_with_fullpath:
|
||||
|
||||
out_with_rdfd:
|
||||
close(rdfd);
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -568,7 +576,7 @@ out_with_rdfd:
|
||||
****************************************************************************/
|
||||
|
||||
#if CONFIG_NFILE_DESCRIPTORS > 0
|
||||
void cmd_ls(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
||||
int cmd_ls(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
||||
{
|
||||
unsigned int lsflags = 0;
|
||||
int ret;
|
||||
@@ -595,7 +603,7 @@ void cmd_ls(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
||||
case '?':
|
||||
default:
|
||||
nsh_output(vtbl, g_fmtarginvalid, argv[0]);
|
||||
return;
|
||||
return ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -604,12 +612,12 @@ void cmd_ls(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
||||
if (optind + 1 < argc)
|
||||
{
|
||||
nsh_output(vtbl, g_fmttoomanyargs, argv[0]);
|
||||
return;
|
||||
return ERROR;
|
||||
}
|
||||
else if (optind + 1 > argc)
|
||||
{
|
||||
nsh_output(vtbl, g_fmtargrequired, argv[0]);
|
||||
return;
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
/* List the directory contents */
|
||||
@@ -622,6 +630,7 @@ void cmd_ls(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
||||
|
||||
ret = foreach_direntry(vtbl, "ls", argv[optind], ls_recursive, (void*)lsflags);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -630,13 +639,14 @@ void cmd_ls(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
||||
****************************************************************************/
|
||||
|
||||
#if !defined(CONFIG_DISABLE_MOUNTPOINT) && CONFIG_NFILE_DESCRIPTORS > 0
|
||||
void cmd_mkdir(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
||||
int cmd_mkdir(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
||||
{
|
||||
int result = mkdir(argv[1], 0777);
|
||||
if ( result < 0)
|
||||
int ret = mkdir(argv[1], 0777);
|
||||
if (ret < 0)
|
||||
{
|
||||
nsh_output(vtbl, g_fmtcmdfailed, argv[0], "mkdir", NSH_ERRNO);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -645,14 +655,15 @@ void cmd_mkdir(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
||||
****************************************************************************/
|
||||
|
||||
#if !defined(CONFIG_DISABLE_MOUNTPOINT) && CONFIG_NFILE_DESCRIPTORS > 0 && defined(CONFIG_FS_FAT)
|
||||
void cmd_mkfatfs(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
||||
int cmd_mkfatfs(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
||||
{
|
||||
struct fat_format_s fmt = FAT_FORMAT_INITIALIZER;
|
||||
int result = mkfatfs(argv[1], &fmt);
|
||||
if ( result < 0)
|
||||
int ret = mkfatfs(argv[1], &fmt);
|
||||
if (ret < 0)
|
||||
{
|
||||
nsh_output(vtbl, g_fmtcmdfailed, argv[0], "mkfatfs", NSH_ERRNO);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -661,13 +672,14 @@ void cmd_mkfatfs(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
||||
****************************************************************************/
|
||||
|
||||
#if !defined(CONFIG_DISABLE_MOUNTPOINT) && CONFIG_NFILE_DESCRIPTORS > 0
|
||||
void cmd_mkfifo(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
||||
int cmd_mkfifo(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
||||
{
|
||||
int result = mkfifo(argv[1], 0777);
|
||||
if ( result < 0)
|
||||
int ret = mkfifo(argv[1], 0777);
|
||||
if (ret < 0)
|
||||
{
|
||||
nsh_output(vtbl, g_fmtcmdfailed, argv[0], "mkfifo", NSH_ERRNO);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -677,7 +689,7 @@ void cmd_mkfifo(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
||||
|
||||
#if !defined(CONFIG_DISABLE_MOUNTPOINT) && CONFIG_NFILE_DESCRIPTORS > 0
|
||||
#ifdef CONFIG_FS_FAT /* Need at least one filesytem in configuration */
|
||||
void cmd_mount(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
||||
int cmd_mount(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
||||
{
|
||||
char *filesystem = 0;
|
||||
int result;
|
||||
@@ -695,12 +707,12 @@ void cmd_mount(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
||||
|
||||
case ':':
|
||||
nsh_output(vtbl, g_fmtargrequired, argv[0]);
|
||||
return;
|
||||
return ERROR;
|
||||
|
||||
case '?':
|
||||
default:
|
||||
nsh_output(vtbl, g_fmtarginvalid, argv[0]);
|
||||
return;
|
||||
return ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -709,12 +721,12 @@ void cmd_mount(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
||||
if (optind + 2 < argc)
|
||||
{
|
||||
nsh_output(vtbl, g_fmttoomanyargs, argv[0]);
|
||||
return;
|
||||
return ERROR;
|
||||
}
|
||||
else if (optind + 2 > argc)
|
||||
{
|
||||
nsh_output(vtbl, g_fmtargrequired, argv[0]);
|
||||
return;
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
/* Perform the mount */
|
||||
@@ -723,6 +735,7 @@ void cmd_mount(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
||||
{
|
||||
nsh_output(vtbl, g_fmtcmdfailed, argv[0], "mount", NSH_ERRNO);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
@@ -732,12 +745,14 @@ void cmd_mount(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
||||
****************************************************************************/
|
||||
|
||||
#if !defined(CONFIG_DISABLE_MOUNTPOINT) && CONFIG_NFILE_DESCRIPTORS > 0
|
||||
void cmd_rm(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
||||
int cmd_rm(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
||||
{
|
||||
if (unlink(argv[1]) < 0)
|
||||
int ret = unlink(argv[1]);
|
||||
if (ret < 0)
|
||||
{
|
||||
nsh_output(vtbl, g_fmtcmdfailed, argv[0], "unlink", NSH_ERRNO);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -746,12 +761,14 @@ void cmd_rm(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
||||
****************************************************************************/
|
||||
|
||||
#if !defined(CONFIG_DISABLE_MOUNTPOINT) && CONFIG_NFILE_DESCRIPTORS > 0
|
||||
void cmd_rmdir(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
||||
int cmd_rmdir(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
||||
{
|
||||
if (rmdir(argv[1]) < 0)
|
||||
int ret = rmdir(argv[1]);
|
||||
if (ret < 0)
|
||||
{
|
||||
nsh_output(vtbl, g_fmtcmdfailed, argv[0], "rmdir", NSH_ERRNO);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -760,7 +777,7 @@ void cmd_rmdir(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
||||
****************************************************************************/
|
||||
|
||||
#if CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NFILE_STREAMS > 0
|
||||
void cmd_sh(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
||||
int cmd_sh(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
||||
{
|
||||
FILE *stream;
|
||||
char *buffer;
|
||||
@@ -775,7 +792,7 @@ void cmd_sh(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
||||
if (!stream)
|
||||
{
|
||||
nsh_output(vtbl, g_fmtcmdfailed, argv[0], "fopen", NSH_ERRNO);
|
||||
return;
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
do
|
||||
@@ -797,6 +814,7 @@ void cmd_sh(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
||||
while(pret);
|
||||
fclose(stream);
|
||||
}
|
||||
return OK;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -806,14 +824,15 @@ void cmd_sh(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
||||
|
||||
#if !defined(CONFIG_DISABLE_MOUNTPOINT) && CONFIG_NFILE_DESCRIPTORS > 0
|
||||
#ifdef CONFIG_FS_FAT /* Need at least one filesytem in configuration */
|
||||
void cmd_umount(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
||||
int cmd_umount(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
||||
{
|
||||
/* Perform the umount */
|
||||
int result = umount(argv[1]);
|
||||
if ( result < 0)
|
||||
if (result < 0)
|
||||
{
|
||||
nsh_output(vtbl, g_fmtcmdfailed, argv[0], "umount", NSH_ERRNO);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
+290
-83
File diff suppressed because it is too large
Load Diff
@@ -221,10 +221,11 @@ int ifconfig_callback(FAR struct uip_driver_s *dev, void *arg)
|
||||
* Name: cmd_ifconfig
|
||||
****************************************************************************/
|
||||
|
||||
void cmd_ifconfig(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
||||
int cmd_ifconfig(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
||||
{
|
||||
netdev_foreach(ifconfig_callback, vtbl);
|
||||
uip_statistics(vtbl);
|
||||
return OK;
|
||||
}
|
||||
|
||||
#endif /* CONFIG_NET && CONFIG_NSOCKET_DESCRIPTORS */
|
||||
|
||||
@@ -139,7 +139,7 @@ static void ps_task(FAR _TCB *tcb, FAR void *arg)
|
||||
* Name: cmd_exec
|
||||
****************************************************************************/
|
||||
|
||||
void cmd_exec(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
||||
int cmd_exec(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
||||
{
|
||||
char *endptr;
|
||||
long addr;
|
||||
@@ -148,21 +148,23 @@ void cmd_exec(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
||||
if (!addr || endptr == argv[1] || *endptr != '\0')
|
||||
{
|
||||
nsh_output(vtbl, g_fmtarginvalid, argv[0]);
|
||||
return;
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
nsh_output(vtbl, "Calling %p\n", (exec_t)addr);
|
||||
((exec_t)addr)();
|
||||
return OK;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: cmd_ps
|
||||
****************************************************************************/
|
||||
|
||||
void cmd_ps(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
||||
int cmd_ps(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
||||
{
|
||||
nsh_output(vtbl, "PID PRI SCHD TYPE NP STATE NAME\n");
|
||||
sched_foreach(ps_task, vtbl);
|
||||
return OK;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
@@ -170,7 +172,7 @@ void cmd_ps(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef CONFIG_DISABLE_SIGNALS
|
||||
void cmd_sleep(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
||||
int cmd_sleep(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
||||
{
|
||||
char *endptr;
|
||||
long secs;
|
||||
@@ -179,9 +181,10 @@ void cmd_sleep(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
||||
if (!secs || endptr == argv[1] || *endptr != '\0')
|
||||
{
|
||||
nsh_output(vtbl, g_fmtarginvalid, argv[0]);
|
||||
return;
|
||||
return ERROR;
|
||||
}
|
||||
sleep(secs);
|
||||
return OK;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -190,7 +193,7 @@ void cmd_sleep(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef CONFIG_DISABLE_SIGNALS
|
||||
void cmd_usleep(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
||||
int cmd_usleep(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
||||
{
|
||||
char *endptr;
|
||||
long usecs;
|
||||
@@ -199,8 +202,9 @@ void cmd_usleep(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
||||
if (!usecs || endptr == argv[1] || *endptr != '\0')
|
||||
{
|
||||
nsh_output(vtbl, g_fmtarginvalid, argv[0]);
|
||||
return;
|
||||
return ERROR;
|
||||
}
|
||||
usleep(usecs);
|
||||
return OK;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -114,6 +114,8 @@ static inline FAR struct serial_s *nsh_allocstruct(void)
|
||||
pstate->ss_vtbl.undirect = nsh_consoleundirect;
|
||||
pstate->ss_vtbl.exit = nsh_consoleexit;
|
||||
|
||||
memset(&pstate->ss_vtbl.np, 0, sizeof(struct nsh_parser_s));
|
||||
|
||||
pstate->ss_refs = 1;
|
||||
pstate->ss_fd = 1;
|
||||
pstate->ss_stream = stdout;
|
||||
|
||||
@@ -209,6 +209,8 @@ static FAR struct telnetd_s *nsh_allocstruct(void)
|
||||
pstate->tn_vtbl.undirect = nsh_telnetundirect;
|
||||
pstate->tn_vtbl.exit = nsh_telnetexit;
|
||||
|
||||
memset(&pstate->tn_vtbl.np, 0, sizeof(struct nsh_parser_s));
|
||||
|
||||
pstate->tn_refs = 1;
|
||||
}
|
||||
return pstate;
|
||||
|
||||
Reference in New Issue
Block a user