summaryrefslogtreecommitdiff
path: root/apps/nshlib
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2012-02-01 19:07:57 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2012-02-01 19:07:57 +0000
commit6d35541209058b86bda7b34e47fa28c8c959d365 (patch)
tree058c4031d3edf80d524112e76c6da2bdc0be8e5c /apps/nshlib
parent4b8f5a9e6dc87bad723af14933cb8c17284eade6 (diff)
downloadnuttx-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')
-rw-r--r--apps/nshlib/nsh_fscmds.c6
-rw-r--r--apps/nshlib/nsh_parse.c4
-rw-r--r--apps/nshlib/nsh_serial.c20
3 files changed, 24 insertions, 6 deletions
diff --git a/apps/nshlib/nsh_fscmds.c b/apps/nshlib/nsh_fscmds.c
index f0451ce02..350055fae 100644
--- a/apps/nshlib/nsh_fscmds.c
+++ b/apps/nshlib/nsh_fscmds.c
@@ -1,8 +1,8 @@
/****************************************************************************
* apps/nshlib/nsh_fscmds.c
*
- * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved.
- * Author: Gregory Nutt <spudmonkey@racsa.co.cr>
+ * Copyright (C) 2007-2009, 2011-2012 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -1277,7 +1277,7 @@ int nsh_script(FAR struct nsh_vtbl_s *vtbl, const char *cmd, const char *path)
do
{
- /* Get the next line of input from the file*/
+ /* Get the next line of input from the file */
fflush(stdout);
pret = fgets(buffer, CONFIG_NSH_LINELEN, stream);
diff --git a/apps/nshlib/nsh_parse.c b/apps/nshlib/nsh_parse.c
index a193ebc9e..cc0443258 100644
--- a/apps/nshlib/nsh_parse.c
+++ b/apps/nshlib/nsh_parse.c
@@ -1,8 +1,8 @@
/****************************************************************************
* apps/nshlib/nsh_parse.c
*
- * Copyright (C) 2007-2011 Gregory Nutt. All rights reserved.
- * Author: Gregory Nutt <spudmonkey@racsa.co.cr>
+ * Copyright (C) 2007-2012 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
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;
}