Move lib/stdio/lib_fgets.c to apps/system/readline; simplify fgets(); use readline instead of fgets in NSH

git-svn-id: https://nuttx.svn.sourceforge.net/svnroot/nuttx/trunk@4356 7fd9a85b-ad96-42d3-883c-3090e2eb8679
This commit is contained in:
patacongo
2012-02-01 19:07:57 +00:00
parent 47fa99c4a8
commit 6a4e8b32b3
52 changed files with 732 additions and 290 deletions
+3 -3
View File
@@ -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);
+2 -2
View File
@@ -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
+19 -1
View File
@@ -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;
}