diff options
author | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2008-08-12 23:59:32 +0000 |
---|---|---|
committer | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2008-08-12 23:59:32 +0000 |
commit | b796f476c1dc59a2f063181b65648993b3e1a858 (patch) | |
tree | abd9e21d3ef52a586da75728a35385f79b81efb0 | |
parent | 51172e243d849989e1c2f3a5ce7e570f054d84e3 (diff) | |
download | px4-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
-rw-r--r-- | nuttx/ChangeLog | 4 | ||||
-rw-r--r-- | nuttx/Documentation/NuttX.html | 6 | ||||
-rw-r--r-- | nuttx/examples/README.txt | 6 | ||||
-rw-r--r-- | nuttx/examples/nsh/nsh.h | 10 | ||||
-rw-r--r-- | nuttx/examples/nsh/nsh_fscmds.c | 47 | ||||
-rw-r--r-- | nuttx/examples/nsh/nsh_main.c | 3 | ||||
-rw-r--r-- | nuttx/examples/nsh/nsh_serial.c | 26 | ||||
-rw-r--r-- | nuttx/examples/nsh/nsh_telnetd.c | 18 |
8 files changed, 101 insertions, 19 deletions
diff --git a/nuttx/ChangeLog b/nuttx/ChangeLog index 93b6ce297..98ecf7778 100644 --- a/nuttx/ChangeLog +++ b/nuttx/ChangeLog @@ -395,7 +395,11 @@ 0.3.13 2008-xx-xx Gregory Nutt <spudmonkey@racsa.co.cr> * Added mkfatfs, mkfifo, sleep, usleep and nice commands to NSH + * Fixed problem with console input in Cygwin-based simulator; NSH now works + with simulator. * NSH will now execute commands in background * sched_get_priority_max/min returned error on SCHED_RR * Removed duplicate getenv() implementation in /lib + * Correct detection of End-of-File in fgets + * Implement sh and crude script handler in NSH diff --git a/nuttx/Documentation/NuttX.html b/nuttx/Documentation/NuttX.html index 93cf94966..6356422c5 100644 --- a/nuttx/Documentation/NuttX.html +++ b/nuttx/Documentation/NuttX.html @@ -8,7 +8,7 @@ <tr align="center" bgcolor="#e4e4e4"> <td> <h1><big><font color="#3c34ec"><i>NuttX RTOS</i></font></big></h1> - <p>Last Updated: August 10, 2008</p> + <p>Last Updated: August 12, 2008</p> </td> </tr> </table> @@ -1029,9 +1029,13 @@ buildroot-0.1.0 2007-03-09 <spudmonkey@racsa.co.cr> nuttx-0.3.13 2008-xx-xx Gregory Nutt <spudmonkey@racsa.co.cr> * Added mkfatfs, mkfifo, sleep, usleep and nice commands to NSH + * Fixed problem with console input in Cygwin-based simulator; NSH now works + with simulator. * NSH will now execute commands in background * sched_get_priority_max/min returned error on SCHED_RR * Removed duplicate getenv() implementation in /lib + * Correct detection of End-of-File in fgets + * Implement sh and crude script handler in NSH pascal-0.1.3 2008-xx-xx Gregory Nutt <spudmonkey@racsa.co.cr> diff --git a/nuttx/examples/README.txt b/nuttx/examples/README.txt index 07a3f9d54..3dd7f1494 100644 --- a/nuttx/examples/README.txt +++ b/nuttx/examples/README.txt @@ -66,7 +66,8 @@ examples/nsh very large and will not be used unless this setting is 'y' * CONFIG_EXAMPLES_NSH_LINELEN - The maximum length of one command line. Default: 80 + The maximum length of one command line and of one output line. + Default: 80 * CONFIG_EXAMPLES_NSH_TELNET By default, NSH is configured to use the serial console. @@ -82,9 +83,6 @@ examples/nsh Determines the size of the I/O buffer to use for sending/ receiving TELNET commands/reponses - * CONFIG_EXAMPLES_NSH_CMD_SIZE - The size of one parsed NSH command - * CONFIG_EXAMPLES_NSH_STACKSIZE The stack size to use when spawning new threads as new TELNET connections are established. diff --git a/nuttx/examples/nsh/nsh.h b/nuttx/examples/nsh/nsh.h index a4b9c4160..0cc47274a 100644 --- a/nuttx/examples/nsh/nsh.h +++ b/nuttx/examples/nsh/nsh.h @@ -76,10 +76,6 @@ # define CONFIG_EXAMPLES_NSH_IOBUFFER_SIZE 512 #endif -#ifndef CONFIG_EXAMPLES_NSH_CMD_SIZE -# define CONFIG_EXAMPLES_NSH_CMD_SIZE 40 -#endif - /* As threads are created to handle each request, a stack must be allocated * for the thread. Use a default if the user provided no stacksize. */ @@ -119,7 +115,7 @@ extern const char g_fmtcmdoutofmemory[]; /* Message handler */ -extern int nsh_parse(FAR void *handle, char *cmdline); +extern int nsh_parse(FAR void *handle, char *cmdline); /* I/O interfaces */ @@ -139,6 +135,7 @@ extern int nsh_serialmain(void); # define nsh_output(handle, ...) printf(__VA_ARGS__) #endif +extern char *nsh_linebuffer(FAR void *handle); /* Shell command handlers */ @@ -151,6 +148,9 @@ extern void cmd_ps(FAR void *handle, int argc, char **argv); extern void cmd_cat(FAR void *handle, int argc, char **argv); extern void cmd_cp(FAR void *handle, int argc, char **argv); extern void cmd_ls(FAR void *handle, int argc, char **argv); +# if CONFIG_NFILE_STREAMS > 0 + extern void cmd_sh(FAR void *handle, int argc, char **argv); +# endif /* CONFIG_NFILE_STREAMS */ # ifndef CONFIG_DISABLE_MOUNTPOINT extern void cmd_mkdir(FAR void *handle, int argc, char **argv); extern void cmd_mkfifo(FAR void *handle, int argc, char **argv); 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 ****************************************************************************/ diff --git a/nuttx/examples/nsh/nsh_main.c b/nuttx/examples/nsh/nsh_main.c index 4f6b62454..785062bc5 100644 --- a/nuttx/examples/nsh/nsh_main.c +++ b/nuttx/examples/nsh/nsh_main.c @@ -116,6 +116,9 @@ static const struct cmdmap_s g_cmdmap[] = { "rm", cmd_rm, 2, 2, "<file-path>" }, { "rmdir", cmd_rmdir, 2, 2, "<dir-path>" }, #endif +#if CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NFILE_STREAMS > 0 + { "sh", cmd_sh, 2, 2, "<script-path>" }, +# endif /* CONFIG_NFILE_STREAMS */ #ifndef CONFIG_DISABLE_SIGNALS { "sleep", cmd_sleep, 2, 2, "<sec>" }, #endif /* CONFIG_DISABLE_SIGNALS */ diff --git a/nuttx/examples/nsh/nsh_serial.c b/nuttx/examples/nsh/nsh_serial.c index ad8ccad17..5052109d2 100644 --- a/nuttx/examples/nsh/nsh_serial.c +++ b/nuttx/examples/nsh/nsh_serial.c @@ -71,7 +71,7 @@ struct cmdmap_s * Private Data ****************************************************************************/ -static char line[CONFIG_EXAMPLES_NSH_LINELEN]; +static char g_line[CONFIG_EXAMPLES_NSH_LINELEN]; /**************************************************************************** * Public Data @@ -103,16 +103,30 @@ int nsh_serialmain(void) /* Get the next line of input */ - fgets(line, CONFIG_EXAMPLES_NSH_LINELEN, stdin); + if (fgets(g_line, CONFIG_EXAMPLES_NSH_LINELEN, stdin)) + { + /* Parse process the command */ - /* Parse process the command */ - - (void)nsh_parse(NULL, line); - fflush(stdout); + (void)nsh_parse(NULL, g_line); + fflush(stdout); + } } } /**************************************************************************** + * Name: nsh_linebuffer + * + * Description: + * Return a reference to the current line buffer + * + ****************************************************************************/ + +extern char *nsh_linebuffer(FAR void *handle) +{ + return g_line; +} + +/**************************************************************************** * Name: cmd_exit * * Description: diff --git a/nuttx/examples/nsh/nsh_telnetd.c b/nuttx/examples/nsh/nsh_telnetd.c index 872390d5f..0dbf6b18b 100644 --- a/nuttx/examples/nsh/nsh_telnetd.c +++ b/nuttx/examples/nsh/nsh_telnetd.c @@ -90,7 +90,7 @@ struct telnetd_s uint8 tn_bufndx; uint8 tn_state; char tn_iobuffer[CONFIG_EXAMPLES_NSH_IOBUFFER_SIZE]; - char tn_cmd[CONFIG_EXAMPLES_NSH_CMD_SIZE]; + char tn_cmd[CONFIG_EXAMPLES_NSH_LINELEN]; }; /**************************************************************************** @@ -170,7 +170,7 @@ static void nsh_putchar(struct telnetd_s *pstate, uint8 ch) /* If a newline was added or if the buffer is full, then process it now */ - if (ch == ISO_nl || pstate->tn_bufndx == (CONFIG_EXAMPLES_NSH_CMD_SIZE - 1)) + if (ch == ISO_nl || pstate->tn_bufndx == (CONFIG_EXAMPLES_NSH_LINELEN - 1)) { if (pstate->tn_bufndx > 0) { @@ -551,6 +551,20 @@ int nsh_telnetout(FAR void *handle, const char *fmt, ...) } /**************************************************************************** + * Name: nsh_linebuffer + * + * Description: + * Return a reference to the current line buffer + * + ****************************************************************************/ + +extern char *nsh_linebuffer(FAR void *handle) +{ + struct telnetd_s *pstate = (struct telnetd_s *)handle; + return pstate->tn_cmd; +} + +/**************************************************************************** * Name: cmd_exit * * Description: |