mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-06-05 22:24:47 +08:00
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:
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user