xiaoxiang781216 commented on code in PR #1559: URL: https://github.com/apache/nuttx-apps/pull/1559#discussion_r1104723398
########## system/readline/readline_fd.c: ########## @@ -32,19 +32,6 @@ #include "system/readline.h" #include "readline.h" -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -struct readline_s Review Comment: revert, keep in source file ########## system/readline/readline_common.c: ########## @@ -494,7 +497,10 @@ ssize_t readline_common(FAR struct rl_common_s *vtbl, FAR char *buf, /* <esc>[K is the VT100 command that erases to the end of the line. */ #ifdef CONFIG_READLINE_ECHO - RL_WRITE(vtbl, g_erasetoeol, sizeof(g_erasetoeol)); + if (rl->outfd >= 0) Review Comment: let's move the check to readline_putc/readline_write ########## nshlib/nsh_telnetlogin.c: ########## @@ -207,18 +206,17 @@ int nsh_telnetlogin(FAR struct console_stdio_s *pstate) #ifdef CONFIG_NSH_PLATFORM_CHALLENGE platform_challenge(challenge, sizeof(challenge)); - fputs(challenge, pstate->cn_outstream); + write(OUTFD(pstate), challenge, strlen(challenge)); #endif /* Ask for the login password */ - fputs(g_passwordprompt, pstate->cn_outstream); - fflush(pstate->cn_outstream); + write(OUTFD(pstate), g_passwordprompt, strlen(g_passwordprompt)); nsh_telnetecho(pstate, TELNET_NOTUSE_ECHO); password[0] = '\0'; - if (fgets(pstate->cn_line, CONFIG_NSH_LINELEN, - INSTREAM(pstate)) != NULL) + if (readline_fd(pstate->cn_line, CONFIG_NSH_LINELEN, + INFD(pstate), OUTFD(pstate)) >= 0) Review Comment: align ########## nshlib/nsh_console.c: ########## @@ -115,33 +101,21 @@ static int nsh_openifnotopen(struct console_stdio_s *pstate) * ****************************************************************************/ -#ifdef CONFIG_FILE_STREAM static void nsh_closeifnotclosed(struct console_stdio_s *pstate) { - if (pstate->cn_outstream == OUTSTREAM(pstate)) + if (OUTFD(pstate) >= 0 && OUTFD(pstate) != STDOUT_FILENO) Review Comment: why need check OUTFD(pstate) != STDOUT_FILENO ########## nshlib/nsh_telnetlogin.c: ########## @@ -178,21 +178,20 @@ int nsh_telnetlogin(FAR struct console_stdio_s *pstate) /* Present the NSH Telnet greeting */ - fputs(g_telnetgreeting, pstate->cn_outstream); - fflush(pstate->cn_outstream); + write(OUTFD(pstate), g_telnetgreeting, strlen(g_telnetgreeting)); /* Loop for the configured number of retries */ for (i = 0; i < CONFIG_NSH_LOGIN_FAILCOUNT; i++) { /* Ask for the login username */ - fputs(g_userprompt, pstate->cn_outstream); - fflush(pstate->cn_outstream); + write(OUTFD(pstate), g_userprompt, strlen(g_userprompt)); username[0] = '\0'; - if (fgets(pstate->cn_line, CONFIG_NSH_LINELEN, - INSTREAM(pstate)) != NULL) + if (readline_fd(pstate->cn_line, CONFIG_NSH_LINELEN, + INFD(pstate), OUTFD(pstate)) >= 0) Review Comment: align ########## nshlib/nsh_telnetlogin.c: ########## @@ -65,8 +66,7 @@ static void nsh_telnetecho(FAR struct console_stdio_s *pstate, optbuf[1] = (is_use == TELNET_USE_ECHO) ? TELNET_WILL : TELNET_DO; optbuf[2] = 1; optbuf[3] = 0; - fputs((FAR char *)optbuf, pstate->cn_outstream); - fflush(pstate->cn_outstream); + write(OUTFD(pstate), optbuf, strlen((const char *)optbuf)); Review Comment: add FAR to the cast ########## nshlib/nsh_console.c: ########## @@ -115,33 +101,21 @@ static int nsh_openifnotopen(struct console_stdio_s *pstate) * ****************************************************************************/ -#ifdef CONFIG_FILE_STREAM static void nsh_closeifnotclosed(struct console_stdio_s *pstate) { - if (pstate->cn_outstream == OUTSTREAM(pstate)) + if (OUTFD(pstate) >= 0 && OUTFD(pstate) != STDOUT_FILENO) { - fflush(OUTSTREAM(pstate)); - pstate->cn_outfd = OUTFD(pstate); + close(OUTFD(pstate)); } - else + + if (ERRFD(pstate) != OUTFD(pstate)) Review Comment: ERRFD(pstate) >= 0 && ERRFD(pstate) != STDERR_FILENO && ERRFD(pstate) != OUTFD(pstate) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@nuttx.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org