]> git.ipfire.org Git - thirdparty/bash.git/blobdiff - make_cmd.c
fix for SIGINT in sourced script
[thirdparty/bash.git] / make_cmd.c
index 58c4432ffb4380dbab938e4726f8c001e6a909d3..b42e9ff148b22b43c7e087cd79ce2972488d44d6 100644 (file)
@@ -34,6 +34,7 @@
 
 #include "bashintl.h"
 
+#include "parser.h"
 #include "syntax.h"
 #include "command.h"
 #include "general.h"
 
 #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;
+extern int shell_initialized;
+
+int here_doc_first_line = 0;
 
 /* Object caching */
 sh_obj_cache_t wdcache = {0, 0, 0};
 sh_obj_cache_t wlcache = {0, 0, 0};
 
-#define WDCACHESIZE    60
-#define WLCACHESIZE    60
+#define WDCACHESIZE    128
+#define WLCACHESIZE    128
 
 static COMMAND *make_for_or_select __P((enum command_type, WORD_DESC *, WORD_LIST *, COMMAND *, int));
 #if defined (ARITH_FOR_COMMAND)
@@ -260,6 +264,9 @@ make_arith_for_expr (s)
     return ((WORD_LIST *)NULL);
   wd = make_word (s);
   wd->flags |= W_NOGLOB|W_NOSPLIT|W_QUOTED|W_DQUOTE;   /* no word splitting or globbing */
+#if defined (PROCESS_SUBSTITUTION)
+  wd->flags |= W_NOPROCSUB;    /* no process substitution */
+#endif
   result = make_word_list (wd, (WORD_LIST *)NULL);
   return result;
 }
@@ -279,7 +286,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 +298,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|SD_NOPROCSUB);
+      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 +330,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 +538,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 +560,7 @@ make_simple_command (element, command)
       r->next = command->value.Simple->redirects;
       command->value.Simple->redirects = element.redirect;
     }
+
   return (command);
 }
 
@@ -608,6 +625,7 @@ make_here_document (temp, lineno)
       register char *line;
       int len;
 
+      here_doc_first_line = 0;
       line = full_line;
       line_number++;
 
@@ -659,16 +677,18 @@ document_done:
       document[0] = '\0';
     }
   temp->redirectee.filename->word = document;
+  here_doc_first_line = 0;
 }
 
 /* Generate a REDIRECT from SOURCE, DEST, and INSTRUCTION.
    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;
@@ -680,8 +700,10 @@ make_redirection (source, instruction, dest_and_filename)
   /* First do the common cases. */
   temp->redirector = source;
   temp->redirectee = dest_and_filename;
+  temp->here_doc_eof = 0;
   temp->instruction = instruction;
   temp->flags = 0;
+  temp->rflags = flags;
   temp->next = (REDIRECT *)NULL;
 
   switch (instruction)
@@ -776,11 +798,18 @@ make_function_def (name, command, lineno, lstart)
   if (bash_source_a && array_num_elements (bash_source_a) > 0)
     temp->source_file = array_reference (bash_source_a, 0);
 #endif
+  /* Assume that shell functions without a source file before the shell is
+     initialized come from the environment.  Otherwise default to "main"
+     (usually functions being defined interactively) */
+  if (temp->source_file == 0)
+    temp->source_file = shell_initialized ? "main" : "environment";
+
 #if defined (DEBUGGER)
   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 +856,7 @@ clean_simple_command (command)
        REVERSE_LIST (command->value.Simple->redirects, REDIRECT *);
     }
 
+  parser_state &= ~PST_REDIRLIST;
   return (command);
 }