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


##########
nshlib/nsh_parse.c:
##########
@@ -2685,45 +2750,118 @@ static int nsh_parse_command(FAR struct nsh_vtbl_s 
*vtbl, FAR char *cmdline)
               argv[argc] = pbegin;
             }
         }
-    }
-
-  /* Check if the command should run in background */
+      else if (!strncmp(argv[argc], g_redirect_out2,
+                        strlen(g_redirect_out2)))
+        {
+          char *arg;

Review Comment:
   FAR



##########
nshlib/nsh_parse.c:
##########
@@ -2685,45 +2750,118 @@ static int nsh_parse_command(FAR struct nsh_vtbl_s 
*vtbl, FAR char *cmdline)
               argv[argc] = pbegin;
             }
         }
-    }
-
-  /* Check if the command should run in background */
+      else if (!strncmp(argv[argc], g_redirect_out2,
+                        strlen(g_redirect_out2)))
+        {
+          char *arg;
+          if (argv[argc][strlen(g_redirect_out2)])
+            {
+              arg = &argv[argc][strlen(g_redirect_out2)];
+            }
+          else
+            {
+              arg = nsh_argument(vtbl, &saveptr, &memlist, NULL, &isenvvar);
+            }
 
-#ifndef CONFIG_NSH_DISABLEBG
-  if (argc > 1 && strcmp(argv[argc - 1], "&") == 0)
-    {
-      vtbl->np.np_bg = true;
-      argc--;
-    }
-#endif
+          if (!arg)
+            {
+              nsh_error(vtbl, g_fmtarginvalid, cmd);
+              ret = ERROR;
+              goto dynlist_free;
+            }
 
-  /* Check if the output was re-directed using > or >> */
+          redirect_out_save     = vtbl->np.np_redir_out;
+          vtbl->np.np_redir_out = true;
+          oflags                = O_WRONLY | O_CREAT | O_APPEND;
+          redirfile_out         = nsh_getfullpath(vtbl, arg);
+        }
+      else if (!strncmp(argv[argc], g_redirect_out1,
+                        strlen(g_redirect_out1)))
+        {
+          char *arg;
+          if (argv[argc][strlen(g_redirect_out1)])
+            {
+              arg = &argv[argc][strlen(g_redirect_out1)];
+            }
+          else
+            {
+              arg = nsh_argument(vtbl, &saveptr, &memlist, NULL, &isenvvar);
+            }
 
-  if (argc > 2)
-    {
-      /* Check for redirection to a new file */
+          if (!arg)
+            {
+              nsh_error(vtbl, g_fmtarginvalid, cmd);
+              ret = ERROR;
+              goto dynlist_free;
+            }
 
-      if (strcmp(argv[argc - 2], g_redirect1) == 0)
+          redirect_out_save     = vtbl->np.np_redir_out;
+          vtbl->np.np_redir_out = true;
+          oflags                = O_WRONLY | O_CREAT | O_TRUNC;
+          redirfile_out         = nsh_getfullpath(vtbl, arg);
+        }
+      else if (!strncmp(argv[argc], g_redirect_in2, strlen(g_redirect_in2)))
         {
-          redirect_save        = vtbl->np.np_redirect;
-          vtbl->np.np_redirect = true;
-          oflags               = O_WRONLY | O_CREAT | O_TRUNC;
-          redirfile            = nsh_getfullpath(vtbl, argv[argc - 1]);
-          argc                -= 2;
+          char *arg;

Review Comment:
   ditto



##########
nshlib/nsh_parse.c:
##########
@@ -275,8 +276,11 @@ static const char g_line_separator[]  = "\"'#;\n";
 #ifdef CONFIG_NSH_ARGCAT
 static const char g_arg_separator[]   = "`$";
 #endif
-static const char g_redirect1[]       = ">";
-static const char g_redirect2[]       = ">>";
+static const char g_redirect_out1[]   = ">";
+static const char g_redirect_out2[]  = ">>";
+static const char g_redirect_in1[]   = "<";
+static const char g_redirect_in2[]  = "<<";
+static const char g_pipe[]  = "|";

Review Comment:
   nice work, @casaroli do you plan to support pipe operator?



##########
nshlib/nsh_parse.c:
##########
@@ -2685,45 +2750,118 @@ static int nsh_parse_command(FAR struct nsh_vtbl_s 
*vtbl, FAR char *cmdline)
               argv[argc] = pbegin;
             }
         }
-    }
-
-  /* Check if the command should run in background */
+      else if (!strncmp(argv[argc], g_redirect_out2,
+                        strlen(g_redirect_out2)))
+        {
+          char *arg;
+          if (argv[argc][strlen(g_redirect_out2)])
+            {
+              arg = &argv[argc][strlen(g_redirect_out2)];
+            }
+          else
+            {
+              arg = nsh_argument(vtbl, &saveptr, &memlist, NULL, &isenvvar);
+            }
 
-#ifndef CONFIG_NSH_DISABLEBG
-  if (argc > 1 && strcmp(argv[argc - 1], "&") == 0)
-    {
-      vtbl->np.np_bg = true;
-      argc--;
-    }
-#endif
+          if (!arg)
+            {
+              nsh_error(vtbl, g_fmtarginvalid, cmd);
+              ret = ERROR;
+              goto dynlist_free;
+            }
 
-  /* Check if the output was re-directed using > or >> */
+          redirect_out_save     = vtbl->np.np_redir_out;
+          vtbl->np.np_redir_out = true;
+          oflags                = O_WRONLY | O_CREAT | O_APPEND;
+          redirfile_out         = nsh_getfullpath(vtbl, arg);
+        }
+      else if (!strncmp(argv[argc], g_redirect_out1,
+                        strlen(g_redirect_out1)))

Review Comment:
   ditto



##########
nshlib/nsh_parse.c:
##########
@@ -2685,45 +2750,118 @@ static int nsh_parse_command(FAR struct nsh_vtbl_s 
*vtbl, FAR char *cmdline)
               argv[argc] = pbegin;
             }
         }
-    }
-
-  /* Check if the command should run in background */
+      else if (!strncmp(argv[argc], g_redirect_out2,
+                        strlen(g_redirect_out2)))
+        {
+          char *arg;
+          if (argv[argc][strlen(g_redirect_out2)])
+            {
+              arg = &argv[argc][strlen(g_redirect_out2)];
+            }
+          else
+            {
+              arg = nsh_argument(vtbl, &saveptr, &memlist, NULL, &isenvvar);
+            }
 
-#ifndef CONFIG_NSH_DISABLEBG
-  if (argc > 1 && strcmp(argv[argc - 1], "&") == 0)
-    {
-      vtbl->np.np_bg = true;
-      argc--;
-    }
-#endif
+          if (!arg)
+            {
+              nsh_error(vtbl, g_fmtarginvalid, cmd);
+              ret = ERROR;
+              goto dynlist_free;
+            }
 
-  /* Check if the output was re-directed using > or >> */
+          redirect_out_save     = vtbl->np.np_redir_out;
+          vtbl->np.np_redir_out = true;
+          oflags                = O_WRONLY | O_CREAT | O_APPEND;
+          redirfile_out         = nsh_getfullpath(vtbl, arg);
+        }
+      else if (!strncmp(argv[argc], g_redirect_out1,
+                        strlen(g_redirect_out1)))
+        {
+          char *arg;

Review Comment:
   ditto



##########
nshlib/nsh_parse.c:
##########
@@ -2685,45 +2750,118 @@ static int nsh_parse_command(FAR struct nsh_vtbl_s 
*vtbl, FAR char *cmdline)
               argv[argc] = pbegin;
             }
         }
-    }
-
-  /* Check if the command should run in background */
+      else if (!strncmp(argv[argc], g_redirect_out2,
+                        strlen(g_redirect_out2)))

Review Comment:
   should we save the result to avoid the dup at line 2759



##########
nshlib/nsh_parse.c:
##########
@@ -2685,45 +2750,118 @@ static int nsh_parse_command(FAR struct nsh_vtbl_s 
*vtbl, FAR char *cmdline)
               argv[argc] = pbegin;
             }
         }
-    }
-
-  /* Check if the command should run in background */
+      else if (!strncmp(argv[argc], g_redirect_out2,
+                        strlen(g_redirect_out2)))
+        {
+          char *arg;
+          if (argv[argc][strlen(g_redirect_out2)])
+            {
+              arg = &argv[argc][strlen(g_redirect_out2)];
+            }
+          else
+            {
+              arg = nsh_argument(vtbl, &saveptr, &memlist, NULL, &isenvvar);
+            }
 
-#ifndef CONFIG_NSH_DISABLEBG
-  if (argc > 1 && strcmp(argv[argc - 1], "&") == 0)
-    {
-      vtbl->np.np_bg = true;
-      argc--;
-    }
-#endif
+          if (!arg)
+            {
+              nsh_error(vtbl, g_fmtarginvalid, cmd);
+              ret = ERROR;
+              goto dynlist_free;
+            }
 
-  /* Check if the output was re-directed using > or >> */
+          redirect_out_save     = vtbl->np.np_redir_out;
+          vtbl->np.np_redir_out = true;
+          oflags                = O_WRONLY | O_CREAT | O_APPEND;
+          redirfile_out         = nsh_getfullpath(vtbl, arg);
+        }
+      else if (!strncmp(argv[argc], g_redirect_out1,
+                        strlen(g_redirect_out1)))
+        {
+          char *arg;
+          if (argv[argc][strlen(g_redirect_out1)])
+            {
+              arg = &argv[argc][strlen(g_redirect_out1)];
+            }
+          else
+            {
+              arg = nsh_argument(vtbl, &saveptr, &memlist, NULL, &isenvvar);
+            }
 
-  if (argc > 2)
-    {
-      /* Check for redirection to a new file */
+          if (!arg)
+            {
+              nsh_error(vtbl, g_fmtarginvalid, cmd);
+              ret = ERROR;
+              goto dynlist_free;
+            }
 
-      if (strcmp(argv[argc - 2], g_redirect1) == 0)
+          redirect_out_save     = vtbl->np.np_redir_out;
+          vtbl->np.np_redir_out = true;
+          oflags                = O_WRONLY | O_CREAT | O_TRUNC;
+          redirfile_out         = nsh_getfullpath(vtbl, arg);
+        }
+      else if (!strncmp(argv[argc], g_redirect_in2, strlen(g_redirect_in2)))
         {
-          redirect_save        = vtbl->np.np_redirect;
-          vtbl->np.np_redirect = true;
-          oflags               = O_WRONLY | O_CREAT | O_TRUNC;
-          redirfile            = nsh_getfullpath(vtbl, argv[argc - 1]);
-          argc                -= 2;
+          char *arg;
+          if (argv[argc][strlen(g_redirect_in2)])

Review Comment:
   dito



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to