summaryrefslogtreecommitdiff
path: root/nuttx/examples/nsh/nsh_fscmds.c
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2008-08-12 23:59:32 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2008-08-12 23:59:32 +0000
commitb796f476c1dc59a2f063181b65648993b3e1a858 (patch)
treeabd9e21d3ef52a586da75728a35385f79b81efb0 /nuttx/examples/nsh/nsh_fscmds.c
parent51172e243d849989e1c2f3a5ce7e570f054d84e3 (diff)
downloadpx4-nuttx-b796f476c1dc59a2f063181b65648993b3e1a858.tar.gz
px4-nuttx-b796f476c1dc59a2f063181b65648993b3e1a858.tar.bz2
px4-nuttx-b796f476c1dc59a2f063181b65648993b3e1a858.zip
Add 'sh' to NSH
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@819 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx/examples/nsh/nsh_fscmds.c')
-rw-r--r--nuttx/examples/nsh/nsh_fscmds.c47
1 files changed, 46 insertions, 1 deletions
diff --git a/nuttx/examples/nsh/nsh_fscmds.c b/nuttx/examples/nsh/nsh_fscmds.c
index 2cfb24098..7650c8144 100644
--- a/nuttx/examples/nsh/nsh_fscmds.c
+++ b/nuttx/examples/nsh/nsh_fscmds.c
@@ -742,7 +742,7 @@ void cmd_rm(FAR void *handle, int argc, char **argv)
#endif
/****************************************************************************
- * Name: cmd_rm
+ * Name: cmd_rmdir
****************************************************************************/
#if !defined(CONFIG_DISABLE_MOUNTPOINT) && CONFIG_NFILE_DESCRIPTORS > 0
@@ -756,6 +756,51 @@ void cmd_rmdir(FAR void *handle, int argc, char **argv)
#endif
/****************************************************************************
+ * Name: cmd_sh
+ ****************************************************************************/
+
+#if CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NFILE_STREAMS > 0
+void cmd_sh(FAR void *handle, int argc, char **argv)
+{
+ FILE *stream;
+ char *buffer;
+ char *pret;
+
+ /* Get a reference to the common input buffer */
+
+ buffer = nsh_linebuffer(handle);
+ if (buffer)
+ {
+ stream = fopen(argv[1], "r");
+ if (!stream)
+ {
+ nsh_output(handle, g_fmtcmdfailed, argv[0], "fopen", NSH_ERRNO);
+ return;
+ }
+
+ do
+ {
+ /* Get the next line of input from the file*/
+
+ fflush(stdout);
+ pret = fgets(buffer, CONFIG_EXAMPLES_NSH_LINELEN, stream);
+ if (pret)
+ {
+ /* Parse process the command. NOTE: this is recursive...
+ * we got to cmd_sh via a call to nsh_parse. So some
+ * considerable amount of stack may be used.
+ */
+
+ (void)nsh_parse(handle, buffer);
+ }
+ }
+ while(pret);
+ fclose(stream);
+ }
+}
+#endif
+
+/****************************************************************************
* Name: cmd_umount
****************************************************************************/