Bash-4.3 distribution sources and documentation
[platform/upstream/bash.git] / make_cmd.c
index 58c4432..3bc5408 100644 (file)
@@ -34,6 +34,7 @@
 
 #include "bashintl.h"
 
+#include "parser.h"
 #include "syntax.h"
 #include "command.h"
 #include "general.h"
@@ -53,7 +54,7 @@
 
 #include "shmbutil.h"
 
-extern int line_number, current_command_line_count;
+extern int line_number, current_command_line_count, parser_state;
 extern int last_command_exit_value;
 
 /* Object caching */
@@ -279,7 +280,7 @@ make_arith_for_command (exprs, action, lineno)
   ARITH_FOR_COM *temp;
   WORD_LIST *init, *test, *step;
   char *s, *t, *start;
-  int nsemi;
+  int nsemi, i;
 
   init = test = step = (WORD_LIST *)NULL;
   /* Parse the string into the three component sub-expressions. */
@@ -291,10 +292,10 @@ make_arith_for_command (exprs, action, lineno)
        s++;
       start = s;
       /* skip to the semicolon or EOS */
-      while (*s && *s != ';')
-       s++;
+      i = skip_to_delim (start, 0, ";", SD_NOJMP);
+      s = start + i;
 
-      t = (s > start) ? substring (start, 0, s - start) : (char *)NULL;
+      t = (i > 0) ? substring (start, 0, i) : (char *)NULL;
 
       nsemi++;
       switch (nsemi)
@@ -323,6 +324,9 @@ make_arith_for_command (exprs, action, lineno)
       else
        parser_error (lineno, _("syntax error: `;' unexpected"));
       parser_error (lineno, _("syntax error: `((%s))'"), exprs->word->word);
+      free (init);
+      free (test);
+      free (step);
       last_command_exit_value = 2;
       return ((COMMAND *)NULL);
     }
@@ -528,11 +532,17 @@ make_simple_command (element, command)
   /* If we are starting from scratch, then make the initial command
      structure.  Also note that we have to fill in all the slots, since
      malloc doesn't return zeroed space. */
-  if (!command)
-    command = make_bare_simple_command ();
+  if (command == 0)
+    {
+      command = make_bare_simple_command ();
+      parser_state |= PST_REDIRLIST;
+    }
 
   if (element.word)
-    command->value.Simple->words = make_word_list (element.word, command->value.Simple->words);
+    {
+      command->value.Simple->words = make_word_list (element.word, command->value.Simple->words);
+      parser_state &= ~PST_REDIRLIST;
+    }
   else if (element.redirect)
     {
       REDIRECT *r = element.redirect;
@@ -544,6 +554,7 @@ make_simple_command (element, command)
       r->next = command->value.Simple->redirects;
       command->value.Simple->redirects = element.redirect;
     }
+
   return (command);
 }
 
@@ -665,10 +676,11 @@ document_done:
    INSTRUCTION is the instruction type, SOURCE is a file descriptor,
    and DEST is a file descriptor or a WORD_DESC *. */
 REDIRECT *
-make_redirection (source, instruction, dest_and_filename)
-     int source;
+make_redirection (source, instruction, dest_and_filename, flags)
+     REDIRECTEE source;
      enum r_instruction instruction;
      REDIRECTEE dest_and_filename;
+     int flags;
 {
   REDIRECT *temp;
   WORD_DESC *w;
@@ -682,6 +694,7 @@ make_redirection (source, instruction, dest_and_filename)
   temp->redirectee = dest_and_filename;
   temp->instruction = instruction;
   temp->flags = 0;
+  temp->rflags = flags;
   temp->next = (REDIRECT *)NULL;
 
   switch (instruction)
@@ -780,7 +793,7 @@ make_function_def (name, command, lineno, lstart)
   bind_function_def (name->word, temp);
 #endif
 
-  temp->source_file = 0;
+  temp->source_file = temp->source_file ? savestring (temp->source_file) : 0;
   return (make_command (cm_function_def, (SIMPLE_COM *)temp));
 }
 
@@ -827,6 +840,7 @@ clean_simple_command (command)
        REVERSE_LIST (command->value.Simple->redirects, REDIRECT *);
     }
 
+  parser_state &= ~PST_REDIRLIST;
   return (command);
 }