diff options
author | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2012-02-01 19:07:57 +0000 |
---|---|---|
committer | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2012-02-01 19:07:57 +0000 |
commit | 6d35541209058b86bda7b34e47fa28c8c959d365 (patch) | |
tree | 058c4031d3edf80d524112e76c6da2bdc0be8e5c /apps/nshlib/nsh_serial.c | |
parent | 4b8f5a9e6dc87bad723af14933cb8c17284eade6 (diff) | |
download | nuttx-6d35541209058b86bda7b34e47fa28c8c959d365.tar.gz nuttx-6d35541209058b86bda7b34e47fa28c8c959d365.tar.bz2 nuttx-6d35541209058b86bda7b34e47fa28c8c959d365.zip |
Move lib/stdio/lib_fgets.c to apps/system/readline; simplify fgets(); use readline instead of fgets in NSH
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@4356 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'apps/nshlib/nsh_serial.c')
-rw-r--r-- | apps/nshlib/nsh_serial.c | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/apps/nshlib/nsh_serial.c b/apps/nshlib/nsh_serial.c index 43b5e0f53..72004dd7f 100644 --- a/apps/nshlib/nsh_serial.c +++ b/apps/nshlib/nsh_serial.c @@ -50,6 +50,8 @@ #include <errno.h> #include <debug.h> +#include <apps/readline.h> + #include "nsh.h" /**************************************************************************** @@ -473,6 +475,7 @@ int nsh_consolemain(int argc, char *argv[]) { FAR struct serial_s *pstate = nsh_allocstruct(); DEBUGASSERT(pstate); + int ret; /* If we are using a USB console, then we will have to wait for the USB to * be connected/ @@ -504,13 +507,28 @@ int nsh_consolemain(int argc, char *argv[]) /* Get the next line of input */ - if (fgets(pstate->ss_line, CONFIG_NSH_LINELEN, INSTREAM(pstate))) + ret = readline(pstate->ss_line, CONFIG_NSH_LINELEN, + INSTREAM(pstate), OUTSTREAM(pstate)); + if (ret > 0) { /* Parse process the command */ (void)nsh_parse(&pstate->ss_vtbl, pstate->ss_line); fflush(pstate->ss_outstream); } + + /* Readline normally returns the number of characters read, + * but will return 0 on end of file or a negative value + * if an error occurs. Either will cause the session to + * terminate. + */ + + else + { + fprintf(pstate->ss_outstream, g_fmtcmdfailed, "readline", NSH_ERRNO); + return 1; + } } + return OK; } |