9
0
Fork 0

Add 'sh' to NSH

git-svn-id: https://nuttx.svn.sourceforge.net/svnroot/nuttx/trunk@819 7fd9a85b-ad96-42d3-883c-3090e2eb8679
This commit is contained in:
patacongo 2008-08-12 23:59:32 +00:00
parent da6160fad4
commit cd1bcdcb3c
8 changed files with 101 additions and 19 deletions

View File

@ -395,7 +395,11 @@
0.3.13 2008-xx-xx Gregory Nutt <spudmonkey@racsa.co.cr> 0.3.13 2008-xx-xx Gregory Nutt <spudmonkey@racsa.co.cr>
* Added mkfatfs, mkfifo, sleep, usleep and nice commands to NSH * 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 * NSH will now execute commands in background
* sched_get_priority_max/min returned error on SCHED_RR * sched_get_priority_max/min returned error on SCHED_RR
* Removed duplicate getenv() implementation in /lib * Removed duplicate getenv() implementation in /lib
* Correct detection of End-of-File in fgets
* Implement sh and crude script handler in NSH

View File

@ -8,7 +8,7 @@
<tr align="center" bgcolor="#e4e4e4"> <tr align="center" bgcolor="#e4e4e4">
<td> <td>
<h1><big><font color="#3c34ec"><i>NuttX RTOS</i></font></big></h1> <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> </td>
</tr> </tr>
</table> </table>
@ -1029,9 +1029,13 @@ buildroot-0.1.0 2007-03-09 &lt;spudmonkey@racsa.co.cr&gt
nuttx-0.3.13 2008-xx-xx Gregory Nutt &lt;spudmonkey@racsa.co.cr&gt; nuttx-0.3.13 2008-xx-xx Gregory Nutt &lt;spudmonkey@racsa.co.cr&gt;
* Added mkfatfs, mkfifo, sleep, usleep and nice commands to NSH * 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 * NSH will now execute commands in background
* sched_get_priority_max/min returned error on SCHED_RR * sched_get_priority_max/min returned error on SCHED_RR
* Removed duplicate getenv() implementation in /lib * 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 &lt;spudmonkey@racsa.co.cr&gt; pascal-0.1.3 2008-xx-xx Gregory Nutt &lt;spudmonkey@racsa.co.cr&gt;

View File

@ -66,7 +66,8 @@ examples/nsh
very large and will not be used unless this setting is 'y' very large and will not be used unless this setting is 'y'
* CONFIG_EXAMPLES_NSH_LINELEN * 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 * CONFIG_EXAMPLES_NSH_TELNET
By default, NSH is configured to use the serial console. 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/ Determines the size of the I/O buffer to use for sending/
receiving TELNET commands/reponses receiving TELNET commands/reponses
* CONFIG_EXAMPLES_NSH_CMD_SIZE
The size of one parsed NSH command
* CONFIG_EXAMPLES_NSH_STACKSIZE * CONFIG_EXAMPLES_NSH_STACKSIZE
The stack size to use when spawning new threads as new TELNET The stack size to use when spawning new threads as new TELNET
connections are established. connections are established.

View File

@ -76,10 +76,6 @@
# define CONFIG_EXAMPLES_NSH_IOBUFFER_SIZE 512 # define CONFIG_EXAMPLES_NSH_IOBUFFER_SIZE 512
#endif #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 /* 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. * for the thread. Use a default if the user provided no stacksize.
*/ */
@ -119,7 +115,7 @@ extern const char g_fmtcmdoutofmemory[];
/* Message handler */ /* Message handler */
extern int nsh_parse(FAR void *handle, char *cmdline); extern int nsh_parse(FAR void *handle, char *cmdline);
/* I/O interfaces */ /* I/O interfaces */
@ -139,6 +135,7 @@ extern int nsh_serialmain(void);
# define nsh_output(handle, ...) printf(__VA_ARGS__) # define nsh_output(handle, ...) printf(__VA_ARGS__)
#endif #endif
extern char *nsh_linebuffer(FAR void *handle);
/* Shell command handlers */ /* 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_cat(FAR void *handle, int argc, char **argv);
extern void cmd_cp(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); 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 # ifndef CONFIG_DISABLE_MOUNTPOINT
extern void cmd_mkdir(FAR void *handle, int argc, char **argv); extern void cmd_mkdir(FAR void *handle, int argc, char **argv);
extern void cmd_mkfifo(FAR void *handle, int argc, char **argv); extern void cmd_mkfifo(FAR void *handle, int argc, char **argv);

View File

@ -742,7 +742,7 @@ void cmd_rm(FAR void *handle, int argc, char **argv)
#endif #endif
/**************************************************************************** /****************************************************************************
* Name: cmd_rm * Name: cmd_rmdir
****************************************************************************/ ****************************************************************************/
#if !defined(CONFIG_DISABLE_MOUNTPOINT) && CONFIG_NFILE_DESCRIPTORS > 0 #if !defined(CONFIG_DISABLE_MOUNTPOINT) && CONFIG_NFILE_DESCRIPTORS > 0
@ -755,6 +755,51 @@ void cmd_rmdir(FAR void *handle, int argc, char **argv)
} }
#endif #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 * Name: cmd_umount
****************************************************************************/ ****************************************************************************/

View File

@ -116,6 +116,9 @@ static const struct cmdmap_s g_cmdmap[] =
{ "rm", cmd_rm, 2, 2, "<file-path>" }, { "rm", cmd_rm, 2, 2, "<file-path>" },
{ "rmdir", cmd_rmdir, 2, 2, "<dir-path>" }, { "rmdir", cmd_rmdir, 2, 2, "<dir-path>" },
#endif #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 #ifndef CONFIG_DISABLE_SIGNALS
{ "sleep", cmd_sleep, 2, 2, "<sec>" }, { "sleep", cmd_sleep, 2, 2, "<sec>" },
#endif /* CONFIG_DISABLE_SIGNALS */ #endif /* CONFIG_DISABLE_SIGNALS */

View File

@ -71,7 +71,7 @@ struct cmdmap_s
* Private Data * Private Data
****************************************************************************/ ****************************************************************************/
static char line[CONFIG_EXAMPLES_NSH_LINELEN]; static char g_line[CONFIG_EXAMPLES_NSH_LINELEN];
/**************************************************************************** /****************************************************************************
* Public Data * Public Data
@ -103,15 +103,29 @@ int nsh_serialmain(void)
/* Get the next line of input */ /* 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, g_line);
fflush(stdout);
(void)nsh_parse(NULL, 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 * Name: cmd_exit
* *

View File

@ -90,7 +90,7 @@ struct telnetd_s
uint8 tn_bufndx; uint8 tn_bufndx;
uint8 tn_state; uint8 tn_state;
char tn_iobuffer[CONFIG_EXAMPLES_NSH_IOBUFFER_SIZE]; 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 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) if (pstate->tn_bufndx > 0)
{ {
@ -550,6 +550,20 @@ int nsh_telnetout(FAR void *handle, const char *fmt, ...)
return len; return len;
} }
/****************************************************************************
* 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 * Name: cmd_exit
* *