summaryrefslogtreecommitdiff
path: root/apps/nshlib/nsh_parse.c
diff options
context:
space:
mode:
authorGregory Nutt <gnutt@nuttx.org>2013-09-30 11:34:04 -0600
committerGregory Nutt <gnutt@nuttx.org>2013-09-30 11:34:04 -0600
commit9f2b12c2529e0fbe02693c35a82bd35168637c23 (patch)
tree45b4abb98431d8a20f1b77a56aee77cbc9929dc8 /apps/nshlib/nsh_parse.c
parentf30cf5dcb7a09c5facd0329b21640005c19b541f (diff)
downloadnuttx-9f2b12c2529e0fbe02693c35a82bd35168637c23.tar.gz
nuttx-9f2b12c2529e0fbe02693c35a82bd35168637c23.tar.bz2
nuttx-9f2b12c2529e0fbe02693c35a82bd35168637c23.zip
Changes to NSH and readline to permit NSH to work on a platform with no file system
Diffstat (limited to 'apps/nshlib/nsh_parse.c')
-rw-r--r--apps/nshlib/nsh_parse.c27
1 files changed, 26 insertions, 1 deletions
diff --git a/apps/nshlib/nsh_parse.c b/apps/nshlib/nsh_parse.c
index 3f17149f5..d449bf61e 100644
--- a/apps/nshlib/nsh_parse.c
+++ b/apps/nshlib/nsh_parse.c
@@ -821,6 +821,7 @@ static void nsh_releaseargs(struct cmdarg_s *arg)
FAR struct nsh_vtbl_s *vtbl = arg->vtbl;
int i;
+#if CONFIG_NFILE_STREAMS > 0
/* If the output was redirected, then file descriptor should
* be closed. The created task has its one, independent copy of
* the file descriptor
@@ -830,6 +831,7 @@ static void nsh_releaseargs(struct cmdarg_s *arg)
{
(void)close(arg->fd);
}
+#endif
/* Released the cloned vtbl instance */
@@ -1297,9 +1299,11 @@ int nsh_parse(FAR struct nsh_vtbl_s *vtbl, char *cmdline)
FAR char *argv[MAX_ARGV_ENTRIES];
FAR char *saveptr;
FAR char *cmd;
+#if CONFIG_NFILE_STREAMS > 0
FAR char *redirfile = NULL;
- int fd = -1;
int oflags = 0;
+#endif
+ int fd = -1;
int argc;
int ret;
@@ -1309,7 +1313,9 @@ int nsh_parse(FAR struct nsh_vtbl_s *vtbl, char *cmdline)
#ifndef CONFIG_NSH_DISABLEBG
vtbl->np.np_bg = false;
#endif
+#if CONFIG_NFILE_STREAMS > 0
vtbl->np.np_redirect = false;
+#endif
/* Parse out the command at the beginning of the line */
@@ -1388,6 +1394,7 @@ int nsh_parse(FAR struct nsh_vtbl_s *vtbl, char *cmdline)
}
#endif
+#if CONFIG_NFILE_STREAMS > 0
/* Check if the output was re-directed using > or >> */
if (argc > 2)
@@ -1412,6 +1419,7 @@ int nsh_parse(FAR struct nsh_vtbl_s *vtbl, char *cmdline)
argc -= 2;
}
}
+#endif
/* Check if the maximum number of arguments was exceeded */
@@ -1480,7 +1488,11 @@ int nsh_parse(FAR struct nsh_vtbl_s *vtbl, char *cmdline)
*/
#if defined(CONFIG_NSH_BUILTIN_APPS) && (!defined(CONFIG_NSH_FILE_APPS) || !defined(CONFIG_FS_BINFS))
+#if CONFIG_NFILE_STREAMS > 0
ret = nsh_builtin(vtbl, argv[0], argv, redirfile, oflags);
+#else
+ ret = nsh_builtin(vtbl, argv[0], argv, NULL, 0);
+#endif
if (ret >= 0)
{
/* nsh_builtin() returned 0 or 1. This means that the builtin
@@ -1488,12 +1500,14 @@ int nsh_parse(FAR struct nsh_vtbl_s *vtbl, char *cmdline)
* successfully). So certainly it is not an NSH command.
*/
+#if CONFIG_NFILE_STREAMS > 0
/* Free the redirected output file path */
if (redirfile)
{
nsh_freefullpath(redirfile);
}
+#endif
/* Save the result: success if 0; failure if 1 */
@@ -1506,6 +1520,7 @@ int nsh_parse(FAR struct nsh_vtbl_s *vtbl, char *cmdline)
#endif
+#if CONFIG_NFILE_STREAMS > 0
/* Redirected output? */
if (vtbl->np.np_redirect)
@@ -1526,6 +1541,7 @@ int nsh_parse(FAR struct nsh_vtbl_s *vtbl, char *cmdline)
goto errout;
}
}
+#endif
/* Handle the case where the command is executed in background.
* However is app is to be started as builtin new process will
@@ -1561,12 +1577,14 @@ int nsh_parse(FAR struct nsh_vtbl_s *vtbl, char *cmdline)
goto errout_with_redirect;
}
+#if CONFIG_NFILE_STREAMS > 0
/* Handle redirection of output via a file descriptor */
if (vtbl->np.np_redirect)
{
(void)nsh_redirect(bkgvtbl, fd, NULL);
}
+#endif
/* Get the execution priority of this task */
@@ -1634,12 +1652,14 @@ int nsh_parse(FAR struct nsh_vtbl_s *vtbl, char *cmdline)
{
uint8_t save[SAVE_SIZE];
+#if CONFIG_NFILE_STREAMS > 0
/* Handle redirection of output via a file descriptor */
if (vtbl->np.np_redirect)
{
nsh_redirect(vtbl, fd, save);
}
+#endif
/* Then execute the command in "foreground" -- i.e., while the user waits
* for the next prompt. nsh_execute will return:
@@ -1650,6 +1670,7 @@ int nsh_parse(FAR struct nsh_vtbl_s *vtbl, char *cmdline)
ret = nsh_execute(vtbl, argc, argv);
+#if CONFIG_NFILE_STREAMS > 0
/* Restore the original output. Undirect will close the redirection
* file descriptor.
*/
@@ -1658,6 +1679,7 @@ int nsh_parse(FAR struct nsh_vtbl_s *vtbl, char *cmdline)
{
nsh_undirect(vtbl, save);
}
+#endif
/* Mark errors so that it is possible to test for non-zero return values
* in nsh scripts.
@@ -1677,11 +1699,14 @@ int nsh_parse(FAR struct nsh_vtbl_s *vtbl, char *cmdline)
#ifndef CONFIG_NSH_DISABLEBG
errout_with_redirect:
+#if CONFIG_NFILE_STREAMS > 0
if (vtbl->np.np_redirect)
{
close(fd);
}
#endif
+#endif
+
errout:
return nsh_saveresult(vtbl, true);
}