mirror of
https://github.com/apache/nuttx-apps.git
synced 2025-10-18 08:52:01 +08:00
nsh: Decouple with CONFIG_FILE_STREAM
Replace all fwrite/fread/fgets/... to write/read/... Before: ``` text data bss dec hex filename 109827 601 6608 117036 1c92c nuttx/nuttx ``` After: ``` text data bss dec hex filename 108053 601 6608 115262 1c23e nuttx/nuttx ``` After with CONFIG_FILE_STREAM disabled: ``` text data bss dec hex filename 105667 601 6608 112876 1b8ec nuttx/nuttx ``` Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
This commit is contained in:
@@ -104,24 +104,21 @@ int nsh_session(FAR struct console_stdio_s *pstate,
|
||||
{
|
||||
/* Present a greeting and possibly a Message of the Day (MOTD) */
|
||||
|
||||
fputs(g_nshgreeting, pstate->cn_outstream);
|
||||
write(OUTFD(pstate), g_nshgreeting, strlen(g_nshgreeting));
|
||||
|
||||
#ifdef CONFIG_NSH_MOTD
|
||||
# ifdef CONFIG_NSH_PLATFORM_MOTD
|
||||
/* Output the platform message of the day */
|
||||
|
||||
platform_motd(vtbl->iobuffer, IOBUFFERSIZE);
|
||||
fprintf(pstate->cn_outstream, "%s\n", vtbl->iobuffer);
|
||||
|
||||
dprintf(OUTFD(pstate), "%s\n", vtbl->iobuffer);
|
||||
# else
|
||||
/* Output the fixed message of the day */
|
||||
|
||||
fprintf(pstate->cn_outstream, "%s\n", g_nshmotd);
|
||||
dprintf(OUTFD(pstate), "%s\n", g_nshmotd);
|
||||
# endif
|
||||
#endif
|
||||
|
||||
fflush(pstate->cn_outstream);
|
||||
|
||||
/* Execute the login script */
|
||||
|
||||
#ifdef CONFIG_NSH_ROMFSRC
|
||||
@@ -194,34 +191,33 @@ int nsh_session(FAR struct console_stdio_s *pstate,
|
||||
* occurs. Either will cause the session to terminate.
|
||||
*/
|
||||
|
||||
ret = cle(pstate->cn_line, g_nshprompt, CONFIG_NSH_LINELEN,
|
||||
INSTREAM(pstate), OUTSTREAM(pstate));
|
||||
ret = cle_fd(pstate->cn_line, g_nshprompt, CONFIG_NSH_LINELEN,
|
||||
INFD(pstate), OUTFD(pstate));
|
||||
if (ret < 0)
|
||||
{
|
||||
fprintf(pstate->cn_errstream, g_fmtcmdfailed, "nsh_session",
|
||||
dprintf(ERRFD(pstate), g_fmtcmdfailed, "nsh_session",
|
||||
"cle", NSH_ERRNO_OF(-ret));
|
||||
continue;
|
||||
}
|
||||
#else
|
||||
/* Display the prompt string */
|
||||
|
||||
fputs(g_nshprompt, pstate->cn_outstream);
|
||||
fflush(pstate->cn_outstream);
|
||||
write(OUTFD(pstate), g_nshprompt, strlen(g_nshprompt));
|
||||
|
||||
/* readline() normally returns the number of characters read, but
|
||||
* will return EOF on end of file or if an error occurs. EOF
|
||||
* will cause the session to terminate.
|
||||
*/
|
||||
|
||||
ret = readline(pstate->cn_line, CONFIG_NSH_LINELEN,
|
||||
INSTREAM(pstate), OUTSTREAM(pstate));
|
||||
ret = readline_fd(pstate->cn_line, CONFIG_NSH_LINELEN,
|
||||
INFD(pstate), OUTFD(pstate));
|
||||
if (ret == EOF)
|
||||
{
|
||||
/* NOTE: readline() does not set the errno variable, but
|
||||
* perhaps we will be lucky and it will still be valid.
|
||||
*/
|
||||
|
||||
fprintf(pstate->cn_errstream, g_fmtcmdfailed, "nsh_session",
|
||||
dprintf(ERRFD(pstate), g_fmtcmdfailed, "nsh_session",
|
||||
"readline", NSH_ERRNO);
|
||||
ret = EXIT_SUCCESS;
|
||||
break;
|
||||
@@ -231,7 +227,6 @@ int nsh_session(FAR struct console_stdio_s *pstate,
|
||||
/* Parse process the command */
|
||||
|
||||
nsh_parse(vtbl, pstate->cn_line);
|
||||
fflush(pstate->cn_outstream);
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
Reference in New Issue
Block a user