xiaoxiang781216 commented on code in PR #1559:
URL: https://github.com/apache/nuttx-apps/pull/1559#discussion_r1103641543


##########
system/readline/readline_fd.c:
##########
@@ -149,6 +156,13 @@ static void readline_write(FAR struct rl_common_s *vtbl,
   FAR struct readline_s *priv = (FAR struct readline_s *)vtbl;
   DEBUGASSERT(priv && buffer && buflen > 0);
 
+  /* If output fd is invalid, return directly. */
+
+  if (priv->outfd < 0)

Review Comment:
   why need add the special check here?



##########
system/readline/readline_fd.c:
##########
@@ -117,6 +117,13 @@ static void readline_putc(FAR struct rl_common_s *vtbl, 
int ch)
 
   DEBUGASSERT(priv);
 
+  /* If output fd is invalid, return directly. */
+
+  if (priv->outfd < 0)

Review Comment:
   ditto



##########
nshlib/nsh_script.c:
##########
@@ -155,8 +152,9 @@ int nsh_script(FAR struct nsh_vtbl_s *vtbl, FAR const FAR 
char *cmd,
 
           /* Now read the next line from the script file */
 
-          pret = fgets(buffer, CONFIG_NSH_LINELEN, vtbl->np.np_stream);
-          if (pret)
+          ret = readline_fd(buffer, CONFIG_NSH_LINELEN, vtbl->np.np_fd, -1);
+

Review Comment:
   remove the blank line



##########
nshlib/nsh_console.c:
##########
@@ -462,20 +416,16 @@ FAR struct console_stdio_s *nsh_newconsole(bool isctty)
       pstate->cn_vtbl.np.np_flags = NSH_NP_SET_OPTIONS_INIT;
 #endif
 
-#ifdef CONFIG_FILE_STREAM
       pstate->cn_vtbl.redirect    = nsh_consoleredirect;
       pstate->cn_vtbl.undirect    = nsh_consoleundirect;
 
       /* Initialize the error stream */
 
-      pstate->cn_errfd            = ERRFD(pstate);
-      pstate->cn_errstream        = ERRSTREAM(pstate);
+      ERRFD(pstate)            = STDERR_FILENO;
 
       /* Initialize the output stream */
 
-      pstate->cn_outfd            = OUTFD(pstate);
-      pstate->cn_outstream        = OUTSTREAM(pstate);
-#endif
+      OUTFD(pstate)            = STDOUT_FILENO;

Review Comment:
   ```suggestion
         OUTFD(pstate)              = STDOUT_FILENO;
   ```



##########
nshlib/nsh_console.c:
##########
@@ -406,10 +362,8 @@ static void nsh_consoleundirect(FAR struct nsh_vtbl_s 
*vtbl,
   FAR struct serialsave_s *ssave  = (FAR struct serialsave_s *)save;

Review Comment:
   ```suggestion
     FAR struct serialsave_s *ssave = (FAR struct serialsave_s *)save;
   ```



##########
nshlib/nsh_console.c:
##########
@@ -88,21 +84,11 @@ static int nsh_openifnotopen(struct console_stdio_s *pstate)
    * descriptor may be opened on a different task than the stream.
    */
 
-  if (!pstate->cn_outstream)
-    {
-      pstate->cn_outstream = fdopen(pstate->cn_outfd, "w");
-      if (!pstate->cn_outstream)
-        {
-          return ERROR;
-        }
-
-#if !defined(CONFIG_NSH_ALTCONDEV)
+#ifndef CONFIG_NSH_ALTCONDEV
       /* If the alternative console is not enabled then stderr = stdout */
 
-      pstate->cn_errfd     = pstate->cn_outfd;
-      pstate->cn_errstream = pstate->cn_outstream;
+      ERRFD(pstate) = OUTFD(pstate);

Review Comment:
   ```suggestion
     ERRFD(pstate) = OUTFD(pstate);
   ```



##########
nshlib/nsh_parse.c:
##########
@@ -527,11 +523,8 @@ static int nsh_execute(FAR struct nsh_vtbl_s *vtbl,
    */
 
 #ifdef CONFIG_NSH_BUILTIN_APPS
-#ifdef CONFIG_FILE_STREAM
   ret = nsh_builtin(vtbl, argv[0], argv, redirfile, oflags);
-#else
-  ret = nsh_builtin(vtbl, argv[0], argv, NULL, 0);
-#endif
+

Review Comment:
   remove the blank line



##########
nshlib/nsh_script.c:
##########
@@ -155,8 +152,9 @@ int nsh_script(FAR struct nsh_vtbl_s *vtbl, FAR const FAR 
char *cmd,
 
           /* Now read the next line from the script file */
 
-          pret = fgets(buffer, CONFIG_NSH_LINELEN, vtbl->np.np_stream);
-          if (pret)
+          ret = readline_fd(buffer, CONFIG_NSH_LINELEN, vtbl->np.np_fd, -1);
+
+          if (ret)

Review Comment:
   ```suggestion
             if (ret >= 0)
   ```



##########
nshlib/nsh_script.c:
##########
@@ -171,15 +169,15 @@ int nsh_script(FAR struct nsh_vtbl_s *vtbl, FAR const FAR 
char *cmd,
               ret = nsh_parse(vtbl, buffer);
             }
         }
-      while (pret && (ret == OK || (vtbl->np.np_flags & NSH_PFLAG_IGNORE)));
+      while (ret && (ret == OK || (vtbl->np.np_flags & NSH_PFLAG_IGNORE)));

Review Comment:
   ```suggestion
         while (ret >= 0 || (vtbl->np.np_flags & NSH_PFLAG_IGNORE));
   ```



##########
nshlib/nsh_console.c:
##########
@@ -462,20 +416,16 @@ FAR struct console_stdio_s *nsh_newconsole(bool isctty)
       pstate->cn_vtbl.np.np_flags = NSH_NP_SET_OPTIONS_INIT;
 #endif
 
-#ifdef CONFIG_FILE_STREAM
       pstate->cn_vtbl.redirect    = nsh_consoleredirect;
       pstate->cn_vtbl.undirect    = nsh_consoleundirect;
 
       /* Initialize the error stream */
 
-      pstate->cn_errfd            = ERRFD(pstate);
-      pstate->cn_errstream        = ERRSTREAM(pstate);
+      ERRFD(pstate)            = STDERR_FILENO;

Review Comment:
   ```suggestion
         ERRFD(pstate)              = STDERR_FILENO;
   ```



-- 
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

Reply via email to