Imported from ../bash-2.05b.tar.gz.
[platform/upstream/bash.git] / make_cmd.c
1 /* make_cmd.c -- Functions for making instances of the various
2    parser constructs. */
3
4 /* Copyright (C) 1989-2002 Free Software Foundation, Inc.
5
6 This file is part of GNU Bash, the Bourne Again SHell.
7
8 Bash is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 2, or (at your option) any later
11 version.
12
13 Bash is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
16 for more details.
17
18 You should have received a copy of the GNU General Public License along
19 with Bash; see the file COPYING.  If not, write to the Free Software
20 Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. */
21
22 #include "config.h"
23
24 #include <stdio.h>
25 #include "bashtypes.h"
26 #ifndef _MINIX
27 #  include <sys/file.h>
28 #endif
29 #include "filecntl.h"
30 #include "bashansi.h"
31 #if defined (HAVE_UNISTD_H)
32 #  include <unistd.h>
33 #endif
34
35 #include "syntax.h"
36 #include "command.h"
37 #include "general.h"
38 #include "error.h"
39 #include "flags.h"
40 #include "make_cmd.h"
41 #include "dispose_cmd.h"
42 #include "variables.h"
43 #include "subst.h"
44 #include "input.h"
45 #include "ocache.h"
46 #include "externs.h"
47
48 #if defined (JOB_CONTROL)
49 #include "jobs.h"
50 #endif
51
52 #include "shmbutil.h"
53
54 extern int line_number, current_command_line_count;
55 extern int last_command_exit_value;
56
57 /* Object caching */
58 sh_obj_cache_t wdcache = {0, 0, 0};
59 sh_obj_cache_t wlcache = {0, 0, 0};
60
61 #define WDCACHESIZE     60
62 #define WLCACHESIZE     60
63
64 static COMMAND *make_for_or_select __P((enum command_type, WORD_DESC *, WORD_LIST *, COMMAND *));
65 #if defined (ARITH_FOR_COMMAND)
66 static WORD_LIST *make_arith_for_expr __P((char *));
67 #endif
68 static COMMAND *make_until_or_while __P((enum command_type, COMMAND *, COMMAND *));
69
70 void
71 cmd_init ()
72 {
73   ocache_create (wdcache, WORD_DESC, WDCACHESIZE);
74   ocache_create (wlcache, WORD_LIST, WLCACHESIZE);
75 }
76
77 WORD_DESC *
78 make_bare_word (string)
79      const char *string;
80 {
81   WORD_DESC *temp;
82 #if 0
83   temp = (WORD_DESC *)xmalloc (sizeof (WORD_DESC));
84 #else
85   ocache_alloc (wdcache, WORD_DESC, temp);
86 #endif
87
88   if (*string)
89     temp->word = savestring (string);
90   else
91     {
92       temp->word = (char *)xmalloc (1);
93       temp->word[0] = '\0';
94     }
95
96   temp->flags = 0;
97   return (temp);
98 }
99
100 WORD_DESC *
101 make_word_flags (w, string)
102      WORD_DESC *w;
103      const char *string;
104 {
105   register int i;
106   size_t slen;
107   DECLARE_MBSTATE;
108
109   i = 0;
110   slen = strlen (string);
111   while (i < slen)
112     {
113       switch (string[i])
114         {
115         case '$':
116           w->flags |= W_HASDOLLAR;
117           break;
118         case '\\':
119           break;        /* continue the loop */
120         case '\'':
121         case '`':
122         case '"':
123           w->flags |= W_QUOTED;
124           break;
125         }
126
127       ADVANCE_CHAR (string, slen, i);
128     }
129
130   return (w);
131 }
132
133 WORD_DESC *
134 make_word (string)
135      const char *string;
136 {
137   WORD_DESC *temp;
138
139   temp = make_bare_word (string);
140   return (make_word_flags (temp, string));
141 }
142
143 WORD_DESC *
144 make_word_from_token (token)
145      int token;
146 {
147   char tokenizer[2];
148
149   tokenizer[0] = token;
150   tokenizer[1] = '\0';
151
152   return (make_word (tokenizer));
153 }
154
155 WORD_LIST *
156 make_word_list (word, wlink)
157      WORD_DESC *word;
158      WORD_LIST *wlink;
159 {
160   WORD_LIST *temp;
161
162 #if 0
163   temp = (WORD_LIST *)xmalloc (sizeof (WORD_LIST));
164 #else
165   ocache_alloc (wlcache, WORD_LIST, temp);
166 #endif
167   temp->word = word;
168   temp->next = wlink;
169   return (temp);
170 }
171
172 COMMAND *
173 make_command (type, pointer)
174      enum command_type type;
175      SIMPLE_COM *pointer;
176 {
177   COMMAND *temp;
178
179   temp = (COMMAND *)xmalloc (sizeof (COMMAND));
180   temp->type = type;
181   temp->value.Simple = pointer;
182   temp->value.Simple->flags = temp->flags = 0;
183   temp->redirects = (REDIRECT *)NULL;
184   return (temp);
185 }
186
187 COMMAND *
188 command_connect (com1, com2, connector)
189      COMMAND *com1, *com2;
190      int connector;
191 {
192   CONNECTION *temp;
193
194   temp = (CONNECTION *)xmalloc (sizeof (CONNECTION));
195   temp->connector = connector;
196   temp->first = com1;
197   temp->second = com2;
198   return (make_command (cm_connection, (SIMPLE_COM *)temp));
199 }
200
201 static COMMAND *
202 make_for_or_select (type, name, map_list, action)
203      enum command_type type;
204      WORD_DESC *name;
205      WORD_LIST *map_list;
206      COMMAND *action;
207 {
208   FOR_COM *temp;
209
210   temp = (FOR_COM *)xmalloc (sizeof (FOR_COM));
211   temp->flags = 0;
212   temp->name = name;
213   temp->map_list = map_list;
214   temp->action = action;
215   return (make_command (type, (SIMPLE_COM *)temp));
216 }
217
218 COMMAND *
219 make_for_command (name, map_list, action)
220      WORD_DESC *name;
221      WORD_LIST *map_list;
222      COMMAND *action;
223 {
224   return (make_for_or_select (cm_for, name, map_list, action));
225 }
226
227 COMMAND *
228 make_select_command (name, map_list, action)
229      WORD_DESC *name;
230      WORD_LIST *map_list;
231      COMMAND *action;
232 {
233 #if defined (SELECT_COMMAND)
234   return (make_for_or_select (cm_select, name, map_list, action));
235 #else
236   last_command_exit_value = 2;
237   return ((COMMAND *)NULL);
238 #endif
239 }
240
241 #if defined (ARITH_FOR_COMMAND)
242 static WORD_LIST *
243 make_arith_for_expr (s)
244      char *s;
245 {
246   WORD_LIST *result;
247
248   if (s == 0 || *s == '\0')
249     return ((WORD_LIST *)NULL);
250   result = make_word_list (make_word (s), (WORD_LIST *)NULL);
251   return result;
252 }
253 #endif
254
255 COMMAND *
256 make_arith_for_command (exprs, action, lineno)
257      WORD_LIST *exprs;
258      COMMAND *action;
259      int lineno;
260 {
261 #if defined (ARITH_FOR_COMMAND)
262   ARITH_FOR_COM *temp;
263   WORD_LIST *init, *test, *step;
264   char *s, *t, *start;
265   int nsemi;
266
267   init = test = step = (WORD_LIST *)NULL;
268   /* Parse the string into the three component sub-expressions. */
269   start = t = s = exprs->word->word;
270   for (nsemi = 0; ;)
271     {
272       /* skip whitespace at the start of each sub-expression. */
273       while (whitespace (*s))
274         s++;
275       start = s;
276       /* skip to the semicolon or EOS */
277       while (*s && *s != ';')
278         s++;
279
280       t = (s > start) ? substring (start, 0, s - start) : (char *)NULL;
281
282       nsemi++;
283       switch (nsemi)
284         {
285         case 1:
286           init = make_arith_for_expr (t);
287           break;
288         case 2:
289           test = make_arith_for_expr (t);
290           break;
291         case 3:
292           step = make_arith_for_expr (t);
293           break;
294         }
295
296       FREE (t);
297       if (*s == '\0')
298         break;
299       s++;      /* skip over semicolon */
300     }
301
302   if (nsemi != 3)
303     {
304       if (nsemi < 3)
305         parser_error (lineno, "syntax error: arithmetic expression required");
306       else
307         parser_error (lineno, "syntax error: `;' unexpected");
308       parser_error (lineno, "syntax error: `((%s))'", exprs->word->word);
309       last_command_exit_value = 2;
310       return ((COMMAND *)NULL);
311     }
312
313   temp = (ARITH_FOR_COM *)xmalloc (sizeof (ARITH_FOR_COM));
314   temp->flags = 0;
315   temp->line = lineno;
316   temp->init = init ? init : make_arith_for_expr ("1");
317   temp->test = test ? test : make_arith_for_expr ("1");
318   temp->step = step ? step : make_arith_for_expr ("1");
319   temp->action = action;
320
321   return (make_command (cm_arith_for, (SIMPLE_COM *)temp));
322 #else
323   last_command_exit_value = 2;
324   return ((COMMAND *)NULL);
325 #endif /* ARITH_FOR_COMMAND */
326 }
327
328 COMMAND *
329 make_group_command (command)
330      COMMAND *command;
331 {
332   GROUP_COM *temp;
333
334   temp = (GROUP_COM *)xmalloc (sizeof (GROUP_COM));
335   temp->command = command;
336   return (make_command (cm_group, (SIMPLE_COM *)temp));
337 }
338
339 COMMAND *
340 make_case_command (word, clauses)
341      WORD_DESC *word;
342      PATTERN_LIST *clauses;
343 {
344   CASE_COM *temp;
345
346   temp = (CASE_COM *)xmalloc (sizeof (CASE_COM));
347   temp->flags = 0;
348   temp->word = word;
349   temp->clauses = REVERSE_LIST (clauses, PATTERN_LIST *);
350   return (make_command (cm_case, (SIMPLE_COM *)temp));
351 }
352
353 PATTERN_LIST *
354 make_pattern_list (patterns, action)
355      WORD_LIST *patterns;
356      COMMAND *action;
357 {
358   PATTERN_LIST *temp;
359
360   temp = (PATTERN_LIST *)xmalloc (sizeof (PATTERN_LIST));
361   temp->patterns = REVERSE_LIST (patterns, WORD_LIST *);
362   temp->action = action;
363   temp->next = NULL;
364   return (temp);
365 }
366
367 COMMAND *
368 make_if_command (test, true_case, false_case)
369      COMMAND *test, *true_case, *false_case;
370 {
371   IF_COM *temp;
372
373   temp = (IF_COM *)xmalloc (sizeof (IF_COM));
374   temp->flags = 0;
375   temp->test = test;
376   temp->true_case = true_case;
377   temp->false_case = false_case;
378   return (make_command (cm_if, (SIMPLE_COM *)temp));
379 }
380
381 static COMMAND *
382 make_until_or_while (which, test, action)
383      enum command_type which;
384      COMMAND *test, *action;
385 {
386   WHILE_COM *temp;
387
388   temp = (WHILE_COM *)xmalloc (sizeof (WHILE_COM));
389   temp->flags = 0;
390   temp->test = test;
391   temp->action = action;
392   return (make_command (which, (SIMPLE_COM *)temp));
393 }
394
395 COMMAND *
396 make_while_command (test, action)
397      COMMAND *test, *action;
398 {
399   return (make_until_or_while (cm_while, test, action));
400 }
401
402 COMMAND *
403 make_until_command (test, action)
404      COMMAND *test, *action;
405 {
406   return (make_until_or_while (cm_until, test, action));
407 }
408
409 COMMAND *
410 make_arith_command (exp)
411      WORD_LIST *exp;
412 {
413 #if defined (DPAREN_ARITHMETIC)
414   COMMAND *command;
415   ARITH_COM *temp;
416
417   command = (COMMAND *)xmalloc (sizeof (COMMAND));
418   command->value.Arith = temp = (ARITH_COM *)xmalloc (sizeof (ARITH_COM));
419
420   temp->flags = 0;
421   temp->line = line_number;
422   temp->exp = exp;
423
424   command->type = cm_arith;
425   command->redirects = (REDIRECT *)NULL;
426   command->flags = 0;
427
428   return (command);
429 #else
430   last_command_exit_value = 2;
431   return ((COMMAND *)NULL);
432 #endif
433 }
434
435 #if defined (COND_COMMAND)
436 struct cond_com *
437 make_cond_node (type, op, left, right)
438      int type;
439      WORD_DESC *op;
440      struct cond_com *left, *right;
441 {
442   COND_COM *temp;
443
444   temp = (COND_COM *)xmalloc (sizeof (COND_COM));
445   temp->flags = 0;
446   temp->line = line_number;
447   temp->type = type;
448   temp->op = op;
449   temp->left = left;
450   temp->right = right;
451
452   return (temp);
453 }
454 #endif
455
456 COMMAND *
457 make_cond_command (cond_node)
458      COND_COM *cond_node;
459 {
460 #if defined (COND_COMMAND)
461   COMMAND *command;
462
463   command = (COMMAND *)xmalloc (sizeof (COMMAND));
464   command->value.Cond = cond_node;
465
466   command->type = cm_cond;
467   command->redirects = (REDIRECT *)NULL;
468   command->flags = 0;
469   command->line = cond_node ? cond_node->line : 0;
470
471   return (command);
472 #else
473   last_command_exit_value = 2;
474   return ((COMMAND *)NULL);
475 #endif
476 }
477
478 COMMAND *
479 make_bare_simple_command ()
480 {
481   COMMAND *command;
482   SIMPLE_COM *temp;
483
484   command = (COMMAND *)xmalloc (sizeof (COMMAND));
485   command->value.Simple = temp = (SIMPLE_COM *)xmalloc (sizeof (SIMPLE_COM));
486
487   temp->flags = 0;
488   temp->line = line_number;
489   temp->words = (WORD_LIST *)NULL;
490   temp->redirects = (REDIRECT *)NULL;
491
492   command->type = cm_simple;
493   command->redirects = (REDIRECT *)NULL;
494   command->flags = 0;
495
496   return (command);
497 }
498
499 /* Return a command which is the connection of the word or redirection
500    in ELEMENT, and the command * or NULL in COMMAND. */
501 COMMAND *
502 make_simple_command (element, command)
503      ELEMENT element;
504      COMMAND *command;
505 {
506   /* If we are starting from scratch, then make the initial command
507      structure.  Also note that we have to fill in all the slots, since
508      malloc doesn't return zeroed space. */
509   if (!command)
510     command = make_bare_simple_command ();
511
512   if (element.word)
513     command->value.Simple->words = make_word_list (element.word, command->value.Simple->words);
514   else
515     {
516       REDIRECT *r = element.redirect;
517       /* Due to the way <> is implemented, there may be more than a single
518          redirection in element.redirect.  We just follow the chain as far
519          as it goes, and hook onto the end. */
520       while (r->next)
521         r = r->next;
522       r->next = command->value.Simple->redirects;
523       command->value.Simple->redirects = element.redirect;
524     }
525   return (command);
526 }
527
528 /* Because we are Bourne compatible, we read the input for this
529    << or <<- redirection now, from wherever input is coming from.
530    We store the input read into a WORD_DESC.  Replace the text of
531    the redirectee.word with the new input text.  If <<- is on,
532    then remove leading TABS from each line. */
533 void
534 make_here_document (temp)
535      REDIRECT *temp;
536 {
537   int kill_leading, redir_len;
538   char *redir_word, *document, *full_line;
539   int document_index, document_size, delim_unquoted;
540
541   if (temp->instruction != r_deblank_reading_until &&
542       temp->instruction != r_reading_until)
543     {
544       internal_error ("make_here_document: bad instruction type %d", temp->instruction);
545       return;
546     }
547
548   kill_leading = temp->instruction == r_deblank_reading_until;
549
550   document = (char *)NULL;
551   document_index = document_size = 0;
552
553   /* Quote removal is the only expansion performed on the delimiter
554      for here documents, making it an extremely special case. */
555   redir_word = string_quote_removal (temp->redirectee.filename->word, 0);
556
557   /* redirection_expand will return NULL if the expansion results in
558      multiple words or no words.  Check for that here, and just abort
559      this here document if it does. */
560   if (redir_word)
561     redir_len = strlen (redir_word);
562   else
563     {
564       temp->here_doc_eof = (char *)xmalloc (1);
565       temp->here_doc_eof[0] = '\0';
566       goto document_done;
567     }
568
569   free (temp->redirectee.filename->word);
570   temp->here_doc_eof = redir_word;
571
572   /* Read lines from wherever lines are coming from.
573      For each line read, if kill_leading, then kill the
574      leading tab characters.
575      If the line matches redir_word exactly, then we have
576      manufactured the document.  Otherwise, add the line to the
577      list of lines in the document. */
578
579   /* If the here-document delimiter was quoted, the lines should
580      be read verbatim from the input.  If it was not quoted, we
581      need to perform backslash-quoted newline removal. */
582   delim_unquoted = (temp->redirectee.filename->flags & W_QUOTED) == 0;
583   while (full_line = read_secondary_line (delim_unquoted))
584     {
585       register char *line;
586       int len;
587
588       line = full_line;
589       line_number++;
590
591       if (kill_leading && *line)
592         {
593           /* Hack:  To be compatible with some Bourne shells, we
594              check the word before stripping the whitespace.  This
595              is a hack, though. */
596           if (STREQN (line, redir_word, redir_len) && line[redir_len] == '\n')
597             goto document_done;
598
599           while (*line == '\t')
600             line++;
601         }
602
603       if (*line == 0)
604         continue;
605
606       if (STREQN (line, redir_word, redir_len) && line[redir_len] == '\n')
607         goto document_done;
608
609       len = strlen (line);
610       if (len + document_index >= document_size)
611         {
612           document_size = document_size ? 2 * (document_size + len) : len + 2;
613           document = (char *)xrealloc (document, document_size);
614         }
615
616       /* len is guaranteed to be > 0 because of the check for line
617          being an empty string before the call to strlen. */
618       FASTCOPY (line, document + document_index, len);
619       document_index += len;
620     }
621
622 document_done:
623   if (document)
624     document[document_index] = '\0';
625   else
626     {
627       document = (char *)xmalloc (1);
628       document[0] = '\0';
629     }
630   temp->redirectee.filename->word = document;
631 }
632
633 /* Generate a REDIRECT from SOURCE, DEST, and INSTRUCTION.
634    INSTRUCTION is the instruction type, SOURCE is a file descriptor,
635    and DEST is a file descriptor or a WORD_DESC *. */
636 REDIRECT *
637 make_redirection (source, instruction, dest_and_filename)
638      int source;
639      enum r_instruction instruction;
640      REDIRECTEE dest_and_filename;
641 {
642   REDIRECT *temp;
643   WORD_DESC *w;
644   int wlen;
645   intmax_t lfd;
646
647   temp = (REDIRECT *)xmalloc (sizeof (REDIRECT));
648
649   /* First do the common cases. */
650   temp->redirector = source;
651   temp->redirectee = dest_and_filename;
652   temp->instruction = instruction;
653   temp->flags = 0;
654   temp->next = (REDIRECT *)NULL;
655
656   switch (instruction)
657     {
658
659     case r_output_direction:            /* >foo */
660     case r_output_force:                /* >| foo */
661     case r_err_and_out:                 /* command &>filename */
662       temp->flags = O_TRUNC | O_WRONLY | O_CREAT;
663       break;
664
665     case r_appending_to:                /* >>foo */
666       temp->flags = O_APPEND | O_WRONLY | O_CREAT;
667       break;
668
669     case r_input_direction:             /* <foo */
670     case r_inputa_direction:            /* foo & makes this. */
671       temp->flags = O_RDONLY;
672       break;
673
674     case r_input_output:                /* <>foo */
675       temp->flags = O_RDWR | O_CREAT;
676       break;
677
678     case r_deblank_reading_until:       /* <<-foo */
679     case r_reading_until:               /* << foo */
680     case r_reading_string:              /* <<< foo */
681     case r_close_this:                  /* <&- */
682     case r_duplicating_input:           /* 1<&2 */
683     case r_duplicating_output:          /* 1>&2 */
684       break;
685
686     /* the parser doesn't pass these. */
687     case r_move_input:                  /* 1<&2- */
688     case r_move_output:                 /* 1>&2- */
689     case r_move_input_word:             /* 1<&$foo- */
690     case r_move_output_word:            /* 1>&$foo- */
691       break;
692
693     /* The way the lexer works we have to do this here. */
694     case r_duplicating_input_word:      /* 1<&$foo */
695     case r_duplicating_output_word:     /* 1>&$foo */
696       w = dest_and_filename.filename;
697       wlen = strlen (w->word) - 1;
698       if (w->word[wlen] == '-')         /* Yuck */
699         {
700           w->word[wlen] = '\0';
701           if (all_digits (w->word) && legal_number (w->word, &lfd) && lfd == (int)lfd)
702             {
703               dispose_word (w);
704               temp->instruction = (instruction == r_duplicating_input_word) ? r_move_input : r_move_output;
705               temp->redirectee.dest = lfd;
706             }
707           else
708             temp->instruction = (instruction == r_duplicating_input_word) ? r_move_input_word : r_move_output_word;
709         }
710           
711       break;
712
713     default:
714       programming_error ("make_redirection: redirection instruction `%d' out of range", instruction);
715       abort ();
716       break;
717     }
718   return (temp);
719 }
720
721 COMMAND *
722 make_function_def (name, command, lineno, lstart)
723      WORD_DESC *name;
724      COMMAND *command;
725      int lineno, lstart;
726 {
727   FUNCTION_DEF *temp;
728
729   temp = (FUNCTION_DEF *)xmalloc (sizeof (FUNCTION_DEF));
730   temp->command = command;
731   temp->name = name;
732   temp->line = lineno;
733   temp->flags = 0;
734   command->line = lstart;
735   return (make_command (cm_function_def, (SIMPLE_COM *)temp));
736 }
737
738 COMMAND *
739 make_subshell_command (command)
740      COMMAND *command;
741 {
742   SUBSHELL_COM *temp;
743
744   temp = (SUBSHELL_COM *)xmalloc (sizeof (SUBSHELL_COM));
745   temp->command = command;
746   temp->flags = CMD_WANT_SUBSHELL;
747   return (make_command (cm_subshell, (SIMPLE_COM *)temp));
748 }
749
750 /* Reverse the word list and redirection list in the simple command
751    has just been parsed.  It seems simpler to do this here the one
752    time then by any other method that I can think of. */
753 COMMAND *
754 clean_simple_command (command)
755      COMMAND *command;
756 {
757   if (command->type != cm_simple)
758     command_error ("clean_simple_command", CMDERR_BADTYPE, command->type, 0);
759   else
760     {
761       command->value.Simple->words =
762         REVERSE_LIST (command->value.Simple->words, WORD_LIST *);
763       command->value.Simple->redirects =
764         REVERSE_LIST (command->value.Simple->redirects, REDIRECT *);
765     }
766
767   return (command);
768 }
769
770 /* The Yacc grammar productions have a problem, in that they take a
771    list followed by an ampersand (`&') and do a simple command connection,
772    making the entire list effectively asynchronous, instead of just
773    the last command.  This means that when the list is executed, all
774    the commands have stdin set to /dev/null when job control is not
775    active, instead of just the last.  This is wrong, and needs fixing
776    up.  This function takes the `&' and applies it to the last command
777    in the list.  This is done only for lists connected by `;'; it makes
778    `;' bind `tighter' than `&'. */
779 COMMAND *
780 connect_async_list (command, command2, connector)
781      COMMAND *command, *command2;
782      int connector;
783 {
784   COMMAND *t, *t1, *t2;
785
786   t1 = command;
787   t = command->value.Connection->second;
788
789   if (!t || (command->flags & CMD_WANT_SUBSHELL) ||
790       command->value.Connection->connector != ';')
791     {
792       t = command_connect (command, command2, connector);
793       return t;
794     }
795
796   /* This is just defensive programming.  The Yacc precedence rules
797      will generally hand this function a command where t points directly
798      to the command we want (e.g. given a ; b ; c ; d &, t1 will point
799      to the `a ; b ; c' list and t will be the `d').  We only want to do
800      this if the list is not being executed as a unit in the background
801      with `( ... )', so we have to check for CMD_WANT_SUBSHELL.  That's
802      the only way to tell. */
803   while (((t->flags & CMD_WANT_SUBSHELL) == 0) && t->type == cm_connection &&
804          t->value.Connection->connector == ';')
805     {
806       t1 = t;
807       t = t->value.Connection->second;
808     }
809   /* Now we have t pointing to the last command in the list, and
810      t1->value.Connection->second == t. */
811   t2 = command_connect (t, command2, connector);
812   t1->value.Connection->second = t2;
813   return command;
814 }