Bash-4.1 distribution source
[platform/upstream/bash.git] / y.tab.c
1 /* A Bison parser, made by GNU Bison 2.3.  */
2
3 /* Skeleton implementation for Bison's Yacc-like parsers in C
4
5    Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006
6    Free Software Foundation, Inc.
7
8    This program is free software; you can redistribute it and/or modify
9    it under the terms of the GNU General Public License as published by
10    the Free Software Foundation; either version 2, or (at your option)
11    any later version.
12
13    This program is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
17
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 51 Franklin Street, Fifth Floor,
21    Boston, MA 02110-1301, USA.  */
22
23 /* As a special exception, you may create a larger work that contains
24    part or all of the Bison parser skeleton and distribute that work
25    under terms of your choice, so long as that work isn't itself a
26    parser generator using the skeleton or a modified version thereof
27    as a parser skeleton.  Alternatively, if you modify or redistribute
28    the parser skeleton itself, you may (at your option) remove this
29    special exception, which will cause the skeleton and the resulting
30    Bison output files to be licensed under the GNU General Public
31    License without this special exception.
32
33    This special exception was added by the Free Software Foundation in
34    version 2.2 of Bison.  */
35
36 /* C LALR(1) parser skeleton written by Richard Stallman, by
37    simplifying the original so-called "semantic" parser.  */
38
39 /* All symbols defined below should begin with yy or YY, to avoid
40    infringing on user name space.  This should be done even for local
41    variables, as they might otherwise be expanded by user macros.
42    There are some unavoidable exceptions within include files to
43    define necessary library symbols; they are noted "INFRINGES ON
44    USER NAME SPACE" below.  */
45
46 /* Identify Bison output.  */
47 #define YYBISON 1
48
49 /* Bison version.  */
50 #define YYBISON_VERSION "2.3"
51
52 /* Skeleton name.  */
53 #define YYSKELETON_NAME "yacc.c"
54
55 /* Pure parsers.  */
56 #define YYPURE 0
57
58 /* Using locations.  */
59 #define YYLSP_NEEDED 0
60
61
62
63 /* Tokens.  */
64 #ifndef YYTOKENTYPE
65 # define YYTOKENTYPE
66    /* Put the tokens into the symbol table, so that GDB and other debuggers
67       know about them.  */
68    enum yytokentype {
69      IF = 258,
70      THEN = 259,
71      ELSE = 260,
72      ELIF = 261,
73      FI = 262,
74      CASE = 263,
75      ESAC = 264,
76      FOR = 265,
77      SELECT = 266,
78      WHILE = 267,
79      UNTIL = 268,
80      DO = 269,
81      DONE = 270,
82      FUNCTION = 271,
83      COPROC = 272,
84      COND_START = 273,
85      COND_END = 274,
86      COND_ERROR = 275,
87      IN = 276,
88      BANG = 277,
89      TIME = 278,
90      TIMEOPT = 279,
91      WORD = 280,
92      ASSIGNMENT_WORD = 281,
93      REDIR_WORD = 282,
94      NUMBER = 283,
95      ARITH_CMD = 284,
96      ARITH_FOR_EXPRS = 285,
97      COND_CMD = 286,
98      AND_AND = 287,
99      OR_OR = 288,
100      GREATER_GREATER = 289,
101      LESS_LESS = 290,
102      LESS_AND = 291,
103      LESS_LESS_LESS = 292,
104      GREATER_AND = 293,
105      SEMI_SEMI = 294,
106      SEMI_AND = 295,
107      SEMI_SEMI_AND = 296,
108      LESS_LESS_MINUS = 297,
109      AND_GREATER = 298,
110      AND_GREATER_GREATER = 299,
111      LESS_GREATER = 300,
112      GREATER_BAR = 301,
113      BAR_AND = 302,
114      yacc_EOF = 303
115    };
116 #endif
117 /* Tokens.  */
118 #define IF 258
119 #define THEN 259
120 #define ELSE 260
121 #define ELIF 261
122 #define FI 262
123 #define CASE 263
124 #define ESAC 264
125 #define FOR 265
126 #define SELECT 266
127 #define WHILE 267
128 #define UNTIL 268
129 #define DO 269
130 #define DONE 270
131 #define FUNCTION 271
132 #define COPROC 272
133 #define COND_START 273
134 #define COND_END 274
135 #define COND_ERROR 275
136 #define IN 276
137 #define BANG 277
138 #define TIME 278
139 #define TIMEOPT 279
140 #define WORD 280
141 #define ASSIGNMENT_WORD 281
142 #define REDIR_WORD 282
143 #define NUMBER 283
144 #define ARITH_CMD 284
145 #define ARITH_FOR_EXPRS 285
146 #define COND_CMD 286
147 #define AND_AND 287
148 #define OR_OR 288
149 #define GREATER_GREATER 289
150 #define LESS_LESS 290
151 #define LESS_AND 291
152 #define LESS_LESS_LESS 292
153 #define GREATER_AND 293
154 #define SEMI_SEMI 294
155 #define SEMI_AND 295
156 #define SEMI_SEMI_AND 296
157 #define LESS_LESS_MINUS 297
158 #define AND_GREATER 298
159 #define AND_GREATER_GREATER 299
160 #define LESS_GREATER 300
161 #define GREATER_BAR 301
162 #define BAR_AND 302
163 #define yacc_EOF 303
164
165
166
167
168 /* Copy the first part of user declarations.  */
169 #line 21 "/Users/chet/src/bash/src/parse.y"
170
171 #include "config.h"
172
173 #include "bashtypes.h"
174 #include "bashansi.h"
175
176 #include "filecntl.h"
177
178 #if defined (HAVE_UNISTD_H)
179 #  include <unistd.h>
180 #endif
181
182 #if defined (HAVE_LOCALE_H)
183 #  include <locale.h>
184 #endif
185
186 #include <stdio.h>
187 #include "chartypes.h"
188 #include <signal.h>
189
190 #include "memalloc.h"
191
192 #include "bashintl.h"
193
194 #define NEED_STRFTIME_DECL      /* used in externs.h */
195
196 #include "shell.h"
197 #include "trap.h"
198 #include "flags.h"
199 #include "parser.h"
200 #include "mailcheck.h"
201 #include "test.h"
202 #include "builtins.h"
203 #include "builtins/common.h"
204 #include "builtins/builtext.h"
205
206 #include "shmbutil.h"
207
208 #if defined (READLINE)
209 #  include "bashline.h"
210 #  include <readline/readline.h>
211 #endif /* READLINE */
212
213 #if defined (HISTORY)
214 #  include "bashhist.h"
215 #  include <readline/history.h>
216 #endif /* HISTORY */
217
218 #if defined (JOB_CONTROL)
219 #  include "jobs.h"
220 #endif /* JOB_CONTROL */
221
222 #if defined (ALIAS)
223 #  include "alias.h"
224 #else
225 typedef void *alias_t;
226 #endif /* ALIAS */
227
228 #if defined (PROMPT_STRING_DECODE)
229 #  ifndef _MINIX
230 #    include <sys/param.h>
231 #  endif
232 #  include <time.h>
233 #  if defined (TM_IN_SYS_TIME)
234 #    include <sys/types.h>
235 #    include <sys/time.h>
236 #  endif /* TM_IN_SYS_TIME */
237 #  include "maxpath.h"
238 #endif /* PROMPT_STRING_DECODE */
239
240 #define RE_READ_TOKEN   -99
241 #define NO_EXPANSION    -100
242
243 #ifdef DEBUG
244 #  define YYDEBUG 1
245 #else
246 #  define YYDEBUG 0
247 #endif
248
249 #if defined (HANDLE_MULTIBYTE)
250 #  define last_shell_getc_is_singlebyte \
251         ((shell_input_line_index > 1) \
252                 ? shell_input_line_property[shell_input_line_index - 1] \
253                 : 1)
254 #  define MBTEST(x)     ((x) && last_shell_getc_is_singlebyte)
255 #else
256 #  define last_shell_getc_is_singlebyte 1
257 #  define MBTEST(x)     ((x))
258 #endif
259
260 #if defined (EXTENDED_GLOB)
261 extern int extended_glob;
262 #endif
263
264 extern int eof_encountered;
265 extern int no_line_editing, running_under_emacs;
266 extern int current_command_number;
267 extern int sourcelevel, parse_and_execute_level;
268 extern int posixly_correct;
269 extern int last_command_exit_value;
270 extern pid_t last_command_subst_pid;
271 extern char *shell_name, *current_host_name;
272 extern char *dist_version;
273 extern int patch_level;
274 extern int dump_translatable_strings, dump_po_strings;
275 extern sh_builtin_func_t *last_shell_builtin, *this_shell_builtin;
276 #if defined (BUFFERED_INPUT)
277 extern int bash_input_fd_changed;
278 #endif
279
280 extern int errno;
281 /* **************************************************************** */
282 /*                                                                  */
283 /*                  "Forward" declarations                          */
284 /*                                                                  */
285 /* **************************************************************** */
286
287 #ifdef DEBUG
288 static void debug_parser __P((int));
289 #endif
290
291 static int yy_getc __P((void));
292 static int yy_ungetc __P((int));
293
294 #if defined (READLINE)
295 static int yy_readline_get __P((void));
296 static int yy_readline_unget __P((int));
297 #endif
298
299 static int yy_string_get __P((void));
300 static int yy_string_unget __P((int));
301 static void rewind_input_string __P((void));
302 static int yy_stream_get __P((void));
303 static int yy_stream_unget __P((int));
304
305 static int shell_getc __P((int));
306 static void shell_ungetc __P((int));
307 static void discard_until __P((int));
308
309 #if defined (ALIAS) || defined (DPAREN_ARITHMETIC)
310 static void push_string __P((char *, int, alias_t *));
311 static void pop_string __P((void));
312 static void free_string_list __P((void));
313 #endif
314
315 static char *read_a_line __P((int));
316
317 static int reserved_word_acceptable __P((int));
318 static int yylex __P((void));
319 static int alias_expand_token __P((char *));
320 static int time_command_acceptable __P((void));
321 static int special_case_tokens __P((char *));
322 static int read_token __P((int));
323 static char *parse_matched_pair __P((int, int, int, int *, int));
324 static char *parse_comsub __P((int, int, int, int *, int));
325 #if defined (ARRAY_VARS)
326 static char *parse_compound_assignment __P((int *));
327 #endif
328 #if defined (DPAREN_ARITHMETIC) || defined (ARITH_FOR_COMMAND)
329 static int parse_dparen __P((int));
330 static int parse_arith_cmd __P((char **, int));
331 #endif
332 #if defined (COND_COMMAND)
333 static void cond_error __P((void));
334 static COND_COM *cond_expr __P((void));
335 static COND_COM *cond_or __P((void));
336 static COND_COM *cond_and __P((void));
337 static COND_COM *cond_term __P((void));
338 static int cond_skip_newlines __P((void));
339 static COMMAND *parse_cond_command __P((void));
340 #endif
341 #if defined (ARRAY_VARS)
342 static int token_is_assignment __P((char *, int));
343 static int token_is_ident __P((char *, int));
344 #endif
345 static int read_token_word __P((int));
346 static void discard_parser_constructs __P((int));
347
348 static char *error_token_from_token __P((int));
349 static char *error_token_from_text __P((void));
350 static void print_offending_line __P((void));
351 static void report_syntax_error __P((char *));
352
353 static void handle_eof_input_unit __P((void));
354 static void prompt_again __P((void));
355 #if 0
356 static void reset_readline_prompt __P((void));
357 #endif
358 static void print_prompt __P((void));
359
360 #if defined (HANDLE_MULTIBYTE)
361 static void set_line_mbstate __P((void));
362 static char *shell_input_line_property = NULL;
363 #else
364 #  define set_line_mbstate()
365 #endif
366
367 extern int yyerror __P((const char *));
368
369 #ifdef DEBUG
370 extern int yydebug;
371 #endif
372
373 /* Default prompt strings */
374 char *primary_prompt = PPROMPT;
375 char *secondary_prompt = SPROMPT;
376
377 /* PROMPT_STRING_POINTER points to one of these, never to an actual string. */
378 char *ps1_prompt, *ps2_prompt;
379
380 /* Handle on the current prompt string.  Indirectly points through
381    ps1_ or ps2_prompt. */
382 char **prompt_string_pointer = (char **)NULL;
383 char *current_prompt_string;
384
385 /* Non-zero means we expand aliases in commands. */
386 int expand_aliases = 0;
387
388 /* If non-zero, the decoded prompt string undergoes parameter and
389    variable substitution, command substitution, arithmetic substitution,
390    string expansion, process substitution, and quote removal in
391    decode_prompt_string. */
392 int promptvars = 1;
393
394 /* If non-zero, $'...' and $"..." are expanded when they appear within
395    a ${...} expansion, even when the expansion appears within double
396    quotes. */
397 int extended_quote = 1;
398
399 /* The number of lines read from input while creating the current command. */
400 int current_command_line_count;
401
402 /* The token that currently denotes the end of parse. */
403 int shell_eof_token;
404
405 /* The token currently being read. */
406 int current_token;
407
408 /* The current parser state. */
409 int parser_state;
410
411 /* Variables to manage the task of reading here documents, because we need to
412    defer the reading until after a complete command has been collected. */
413 static REDIRECT *redir_stack[10];
414 int need_here_doc;
415
416 /* Where shell input comes from.  History expansion is performed on each
417    line when the shell is interactive. */
418 static char *shell_input_line = (char *)NULL;
419 static int shell_input_line_index;
420 static int shell_input_line_size;       /* Amount allocated for shell_input_line. */
421 static int shell_input_line_len;        /* strlen (shell_input_line) */
422
423 /* Either zero or EOF. */
424 static int shell_input_line_terminator;
425
426 /* The line number in a script on which a function definition starts. */
427 static int function_dstart;
428
429 /* The line number in a script on which a function body starts. */
430 static int function_bstart;
431
432 /* The line number in a script at which an arithmetic for command starts. */
433 static int arith_for_lineno;
434
435 /* The decoded prompt string.  Used if READLINE is not defined or if
436    editing is turned off.  Analogous to current_readline_prompt. */
437 static char *current_decoded_prompt;
438
439 /* The last read token, or NULL.  read_token () uses this for context
440    checking. */
441 static int last_read_token;
442
443 /* The token read prior to last_read_token. */
444 static int token_before_that;
445
446 /* The token read prior to token_before_that. */
447 static int two_tokens_ago;
448
449 static int global_extglob;
450
451 /* The line number in a script where the word in a `case WORD', `select WORD'
452    or `for WORD' begins.  This is a nested command maximum, since the array
453    index is decremented after a case, select, or for command is parsed. */
454 #define MAX_CASE_NEST   128
455 static int word_lineno[MAX_CASE_NEST];
456 static int word_top = -1;
457
458 /* If non-zero, it is the token that we want read_token to return
459    regardless of what text is (or isn't) present to be read.  This
460    is reset by read_token.  If token_to_read == WORD or
461    ASSIGNMENT_WORD, yylval.word should be set to word_desc_to_read. */
462 static int token_to_read;
463 static WORD_DESC *word_desc_to_read;
464
465 static REDIRECTEE source;
466 static REDIRECTEE redir;
467
468
469 /* Enabling traces.  */
470 #ifndef YYDEBUG
471 # define YYDEBUG 0
472 #endif
473
474 /* Enabling verbose error messages.  */
475 #ifdef YYERROR_VERBOSE
476 # undef YYERROR_VERBOSE
477 # define YYERROR_VERBOSE 1
478 #else
479 # define YYERROR_VERBOSE 0
480 #endif
481
482 /* Enabling the token table.  */
483 #ifndef YYTOKEN_TABLE
484 # define YYTOKEN_TABLE 0
485 #endif
486
487 #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
488 typedef union YYSTYPE
489 #line 320 "/Users/chet/src/bash/src/parse.y"
490 {
491   WORD_DESC *word;              /* the word that we read. */
492   int number;                   /* the number that we read. */
493   WORD_LIST *word_list;
494   COMMAND *command;
495   REDIRECT *redirect;
496   ELEMENT element;
497   PATTERN_LIST *pattern;
498 }
499 /* Line 187 of yacc.c.  */
500 #line 501 "y.tab.c"
501         YYSTYPE;
502 # define yystype YYSTYPE /* obsolescent; will be withdrawn */
503 # define YYSTYPE_IS_DECLARED 1
504 # define YYSTYPE_IS_TRIVIAL 1
505 #endif
506
507
508
509 /* Copy the second part of user declarations.  */
510
511
512 /* Line 216 of yacc.c.  */
513 #line 514 "y.tab.c"
514
515 #ifdef short
516 # undef short
517 #endif
518
519 #ifdef YYTYPE_UINT8
520 typedef YYTYPE_UINT8 yytype_uint8;
521 #else
522 typedef unsigned char yytype_uint8;
523 #endif
524
525 #ifdef YYTYPE_INT8
526 typedef YYTYPE_INT8 yytype_int8;
527 #elif (defined __STDC__ || defined __C99__FUNC__ \
528      || defined __cplusplus || defined _MSC_VER)
529 typedef signed char yytype_int8;
530 #else
531 typedef short int yytype_int8;
532 #endif
533
534 #ifdef YYTYPE_UINT16
535 typedef YYTYPE_UINT16 yytype_uint16;
536 #else
537 typedef unsigned short int yytype_uint16;
538 #endif
539
540 #ifdef YYTYPE_INT16
541 typedef YYTYPE_INT16 yytype_int16;
542 #else
543 typedef short int yytype_int16;
544 #endif
545
546 #ifndef YYSIZE_T
547 # ifdef __SIZE_TYPE__
548 #  define YYSIZE_T __SIZE_TYPE__
549 # elif defined size_t
550 #  define YYSIZE_T size_t
551 # elif ! defined YYSIZE_T && (defined __STDC__ || defined __C99__FUNC__ \
552      || defined __cplusplus || defined _MSC_VER)
553 #  include <stddef.h> /* INFRINGES ON USER NAME SPACE */
554 #  define YYSIZE_T size_t
555 # else
556 #  define YYSIZE_T unsigned int
557 # endif
558 #endif
559
560 #define YYSIZE_MAXIMUM ((YYSIZE_T) -1)
561
562 #ifndef YY_
563 # if YYENABLE_NLS
564 #  if ENABLE_NLS
565 #   include <libintl.h> /* INFRINGES ON USER NAME SPACE */
566 #   define YY_(msgid) dgettext ("bison-runtime", msgid)
567 #  endif
568 # endif
569 # ifndef YY_
570 #  define YY_(msgid) msgid
571 # endif
572 #endif
573
574 /* Suppress unused-variable warnings by "using" E.  */
575 #if ! defined lint || defined __GNUC__
576 # define YYUSE(e) ((void) (e))
577 #else
578 # define YYUSE(e) /* empty */
579 #endif
580
581 /* Identity function, used to suppress warnings about constant conditions.  */
582 #ifndef lint
583 # define YYID(n) (n)
584 #else
585 #if (defined __STDC__ || defined __C99__FUNC__ \
586      || defined __cplusplus || defined _MSC_VER)
587 static int
588 YYID (int i)
589 #else
590 static int
591 YYID (i)
592     int i;
593 #endif
594 {
595   return i;
596 }
597 #endif
598
599 #if ! defined yyoverflow || YYERROR_VERBOSE
600
601 /* The parser invokes alloca or malloc; define the necessary symbols.  */
602
603 # ifdef YYSTACK_USE_ALLOCA
604 #  if YYSTACK_USE_ALLOCA
605 #   ifdef __GNUC__
606 #    define YYSTACK_ALLOC __builtin_alloca
607 #   elif defined __BUILTIN_VA_ARG_INCR
608 #    include <alloca.h> /* INFRINGES ON USER NAME SPACE */
609 #   elif defined _AIX
610 #    define YYSTACK_ALLOC __alloca
611 #   elif defined _MSC_VER
612 #    include <malloc.h> /* INFRINGES ON USER NAME SPACE */
613 #    define alloca _alloca
614 #   else
615 #    define YYSTACK_ALLOC alloca
616 #    if ! defined _ALLOCA_H && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
617      || defined __cplusplus || defined _MSC_VER)
618 #     include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
619 #     ifndef _STDLIB_H
620 #      define _STDLIB_H 1
621 #     endif
622 #    endif
623 #   endif
624 #  endif
625 # endif
626
627 # ifdef YYSTACK_ALLOC
628    /* Pacify GCC's `empty if-body' warning.  */
629 #  define YYSTACK_FREE(Ptr) do { /* empty */; } while (YYID (0))
630 #  ifndef YYSTACK_ALLOC_MAXIMUM
631     /* The OS might guarantee only one guard page at the bottom of the stack,
632        and a page size can be as small as 4096 bytes.  So we cannot safely
633        invoke alloca (N) if N exceeds 4096.  Use a slightly smaller number
634        to allow for a few compiler-allocated temporary stack slots.  */
635 #   define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */
636 #  endif
637 # else
638 #  define YYSTACK_ALLOC YYMALLOC
639 #  define YYSTACK_FREE YYFREE
640 #  ifndef YYSTACK_ALLOC_MAXIMUM
641 #   define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM
642 #  endif
643 #  if (defined __cplusplus && ! defined _STDLIB_H \
644        && ! ((defined YYMALLOC || defined malloc) \
645              && (defined YYFREE || defined free)))
646 #   include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
647 #   ifndef _STDLIB_H
648 #    define _STDLIB_H 1
649 #   endif
650 #  endif
651 #  ifndef YYMALLOC
652 #   define YYMALLOC malloc
653 #   if ! defined malloc && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
654      || defined __cplusplus || defined _MSC_VER)
655 void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */
656 #   endif
657 #  endif
658 #  ifndef YYFREE
659 #   define YYFREE free
660 #   if ! defined free && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
661      || defined __cplusplus || defined _MSC_VER)
662 void free (void *); /* INFRINGES ON USER NAME SPACE */
663 #   endif
664 #  endif
665 # endif
666 #endif /* ! defined yyoverflow || YYERROR_VERBOSE */
667
668
669 #if (! defined yyoverflow \
670      && (! defined __cplusplus \
671          || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
672
673 /* A type that is properly aligned for any stack member.  */
674 union yyalloc
675 {
676   yytype_int16 yyss;
677   YYSTYPE yyvs;
678   };
679
680 /* The size of the maximum gap between one aligned stack and the next.  */
681 # define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1)
682
683 /* The size of an array large to enough to hold all stacks, each with
684    N elements.  */
685 # define YYSTACK_BYTES(N) \
686      ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE)) \
687       + YYSTACK_GAP_MAXIMUM)
688
689 /* Copy COUNT objects from FROM to TO.  The source and destination do
690    not overlap.  */
691 # ifndef YYCOPY
692 #  if defined __GNUC__ && 1 < __GNUC__
693 #   define YYCOPY(To, From, Count) \
694       __builtin_memcpy (To, From, (Count) * sizeof (*(From)))
695 #  else
696 #   define YYCOPY(To, From, Count)              \
697       do                                        \
698         {                                       \
699           YYSIZE_T yyi;                         \
700           for (yyi = 0; yyi < (Count); yyi++)   \
701             (To)[yyi] = (From)[yyi];            \
702         }                                       \
703       while (YYID (0))
704 #  endif
705 # endif
706
707 /* Relocate STACK from its old location to the new one.  The
708    local variables YYSIZE and YYSTACKSIZE give the old and new number of
709    elements in the stack, and YYPTR gives the new location of the
710    stack.  Advance YYPTR to a properly aligned location for the next
711    stack.  */
712 # define YYSTACK_RELOCATE(Stack)                                        \
713     do                                                                  \
714       {                                                                 \
715         YYSIZE_T yynewbytes;                                            \
716         YYCOPY (&yyptr->Stack, Stack, yysize);                          \
717         Stack = &yyptr->Stack;                                          \
718         yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \
719         yyptr += yynewbytes / sizeof (*yyptr);                          \
720       }                                                                 \
721     while (YYID (0))
722
723 #endif
724
725 /* YYFINAL -- State number of the termination state.  */
726 #define YYFINAL  113
727 /* YYLAST -- Last index in YYTABLE.  */
728 #define YYLAST   760
729
730 /* YYNTOKENS -- Number of terminals.  */
731 #define YYNTOKENS  60
732 /* YYNNTS -- Number of nonterminals.  */
733 #define YYNNTS  38
734 /* YYNRULES -- Number of rules.  */
735 #define YYNRULES  167
736 /* YYNRULES -- Number of states.  */
737 #define YYNSTATES  344
738
739 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX.  */
740 #define YYUNDEFTOK  2
741 #define YYMAXUTOK   303
742
743 #define YYTRANSLATE(YYX)                                                \
744   ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
745
746 /* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX.  */
747 static const yytype_uint8 yytranslate[] =
748 {
749        0,     2,     2,     2,     2,     2,     2,     2,     2,     2,
750       50,     2,     2,     2,     2,     2,     2,     2,     2,     2,
751        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
752        2,     2,     2,     2,     2,     2,     2,     2,    48,     2,
753       58,    59,     2,     2,     2,    55,     2,     2,     2,     2,
754        2,     2,     2,     2,     2,     2,     2,     2,     2,    49,
755       54,     2,    53,     2,     2,     2,     2,     2,     2,     2,
756        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
757        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
758        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
759        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
760        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
761        2,     2,     2,    56,    52,    57,     2,     2,     2,     2,
762        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
763        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
764        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
765        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
766        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
767        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
768        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
769        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
770        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
771        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
772        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
773        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
774        2,     2,     2,     2,     2,     2,     1,     2,     3,     4,
775        5,     6,     7,     8,     9,    10,    11,    12,    13,    14,
776       15,    16,    17,    18,    19,    20,    21,    22,    23,    24,
777       25,    26,    27,    28,    29,    30,    31,    32,    33,    34,
778       35,    36,    37,    38,    39,    40,    41,    42,    43,    44,
779       45,    46,    47,    51
780 };
781
782 #if YYDEBUG
783 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
784    YYRHS.  */
785 static const yytype_uint16 yyprhs[] =
786 {
787        0,     0,     3,     6,     8,    11,    13,    15,    18,    21,
788       24,    28,    32,    36,    40,    43,    47,    51,    54,    58,
789       62,    65,    69,    73,    76,    80,    84,    87,    91,    95,
790       98,   102,   106,   109,   113,   117,   120,   124,   128,   131,
791      135,   139,   142,   146,   150,   153,   157,   161,   164,   168,
792      172,   175,   178,   180,   182,   184,   186,   189,   191,   194,
793      196,   198,   201,   203,   205,   207,   209,   215,   221,   223,
794      225,   227,   229,   231,   233,   235,   242,   249,   257,   265,
795      276,   287,   297,   307,   315,   323,   329,   335,   342,   349,
796      357,   365,   376,   387,   394,   402,   409,   415,   422,   427,
797      429,   432,   436,   439,   443,   447,   452,   455,   461,   469,
798      476,   480,   482,   486,   491,   498,   504,   506,   509,   514,
799      519,   525,   531,   534,   538,   541,   545,   548,   552,   554,
800      558,   561,   563,   566,   570,   574,   578,   583,   588,   593,
801      598,   603,   605,   607,   609,   611,   613,   615,   616,   619,
802      621,   624,   627,   632,   637,   641,   645,   647,   649,   652,
803      655,   659,   663,   666,   671,   676,   678,   680
804 };
805
806 /* YYRHS -- A `-1'-separated list of the rules' RHS.  */
807 static const yytype_int8 yyrhs[] =
808 {
809       61,     0,    -1,    93,    90,    -1,    50,    -1,     1,    50,
810       -1,    51,    -1,    25,    -1,    62,    25,    -1,    53,    25,
811       -1,    54,    25,    -1,    28,    53,    25,    -1,    28,    54,
812       25,    -1,    27,    53,    25,    -1,    27,    54,    25,    -1,
813       34,    25,    -1,    28,    34,    25,    -1,    27,    34,    25,
814       -1,    46,    25,    -1,    28,    46,    25,    -1,    27,    46,
815       25,    -1,    45,    25,    -1,    28,    45,    25,    -1,    27,
816       45,    25,    -1,    35,    25,    -1,    28,    35,    25,    -1,
817       27,    35,    25,    -1,    42,    25,    -1,    28,    42,    25,
818       -1,    27,    42,    25,    -1,    37,    25,    -1,    28,    37,
819       25,    -1,    27,    37,    25,    -1,    36,    28,    -1,    28,
820       36,    28,    -1,    27,    36,    28,    -1,    38,    28,    -1,
821       28,    38,    28,    -1,    27,    38,    28,    -1,    36,    25,
822       -1,    28,    36,    25,    -1,    27,    36,    25,    -1,    38,
823       25,    -1,    28,    38,    25,    -1,    27,    38,    25,    -1,
824       38,    55,    -1,    28,    38,    55,    -1,    27,    38,    55,
825       -1,    36,    55,    -1,    28,    36,    55,    -1,    27,    36,
826       55,    -1,    43,    25,    -1,    44,    25,    -1,    25,    -1,
827       26,    -1,    63,    -1,    63,    -1,    65,    63,    -1,    64,
828       -1,    66,    64,    -1,    66,    -1,    68,    -1,    68,    65,
829       -1,    73,    -1,    76,    -1,    69,    -1,    72,    -1,    12,
830       87,    14,    87,    15,    -1,    13,    87,    14,    87,    15,
831       -1,    71,    -1,    77,    -1,    75,    -1,    78,    -1,    79,
832       -1,    80,    -1,    70,    -1,    10,    25,    92,    14,    87,
833       15,    -1,    10,    25,    92,    56,    87,    57,    -1,    10,
834       25,    49,    92,    14,    87,    15,    -1,    10,    25,    49,
835       92,    56,    87,    57,    -1,    10,    25,    92,    21,    62,
836       91,    92,    14,    87,    15,    -1,    10,    25,    92,    21,
837       62,    91,    92,    56,    87,    57,    -1,    10,    25,    92,
838       21,    91,    92,    14,    87,    15,    -1,    10,    25,    92,
839       21,    91,    92,    56,    87,    57,    -1,    10,    30,    91,
840       92,    14,    87,    15,    -1,    10,    30,    91,    92,    56,
841       87,    57,    -1,    10,    30,    14,    87,    15,    -1,    10,
842       30,    56,    87,    57,    -1,    11,    25,    92,    14,    86,
843       15,    -1,    11,    25,    92,    56,    86,    57,    -1,    11,
844       25,    49,    92,    14,    86,    15,    -1,    11,    25,    49,
845       92,    56,    86,    57,    -1,    11,    25,    92,    21,    62,
846       91,    92,    14,    86,    15,    -1,    11,    25,    92,    21,
847       62,    91,    92,    56,    86,    57,    -1,     8,    25,    92,
848       21,    92,     9,    -1,     8,    25,    92,    21,    84,    92,
849        9,    -1,     8,    25,    92,    21,    82,     9,    -1,    25,
850       58,    59,    92,    74,    -1,    16,    25,    58,    59,    92,
851       74,    -1,    16,    25,    92,    74,    -1,    68,    -1,    68,
852       65,    -1,    58,    87,    59,    -1,    17,    68,    -1,    17,
853       68,    65,    -1,    17,    25,    68,    -1,    17,    25,    68,
854       65,    -1,    17,    66,    -1,     3,    87,     4,    87,     7,
855       -1,     3,    87,     4,    87,     5,    87,     7,    -1,     3,
856       87,     4,    87,    81,     7,    -1,    56,    87,    57,    -1,
857       29,    -1,    18,    31,    19,    -1,     6,    87,     4,    87,
858       -1,     6,    87,     4,    87,     5,    87,    -1,     6,    87,
859        4,    87,    81,    -1,    83,    -1,    84,    83,    -1,    92,
860       85,    59,    87,    -1,    92,    85,    59,    92,    -1,    92,
861       58,    85,    59,    87,    -1,    92,    58,    85,    59,    92,
862       -1,    83,    39,    -1,    84,    83,    39,    -1,    83,    40,
863       -1,    84,    83,    40,    -1,    83,    41,    -1,    84,    83,
864       41,    -1,    25,    -1,    85,    52,    25,    -1,    92,    88,
865       -1,    86,    -1,    92,    89,    -1,    89,    50,    92,    -1,
866       89,    48,    92,    -1,    89,    49,    92,    -1,    89,    32,
867       92,    89,    -1,    89,    33,    92,    89,    -1,    89,    48,
868       92,    89,    -1,    89,    49,    92,    89,    -1,    89,    50,
869       92,    89,    -1,    95,    -1,    50,    -1,    51,    -1,    50,
870       -1,    49,    -1,    51,    -1,    -1,    92,    50,    -1,    94,
871       -1,    94,    48,    -1,    94,    49,    -1,    94,    32,    92,
872       94,    -1,    94,    33,    92,    94,    -1,    94,    48,    94,
873       -1,    94,    49,    94,    -1,    95,    -1,    96,    -1,    22,
874       96,    -1,    97,    96,    -1,    97,    22,    96,    -1,    22,
875       97,    96,    -1,    97,    91,    -1,    96,    52,    92,    96,
876       -1,    96,    47,    92,    96,    -1,    67,    -1,    23,    -1,
877       23,    24,    -1
878 };
879
880 /* YYRLINE[YYN] -- source line where rule number YYN was defined.  */
881 static const yytype_uint16 yyrline[] =
882 {
883        0,   373,   373,   384,   393,   408,   418,   420,   424,   430,
884      436,   442,   448,   454,   460,   466,   472,   478,   484,   490,
885      496,   502,   508,   514,   521,   528,   535,   542,   549,   556,
886      562,   568,   574,   580,   586,   592,   598,   604,   610,   616,
887      622,   628,   634,   640,   646,   652,   658,   664,   670,   676,
888      682,   688,   696,   698,   700,   704,   708,   719,   721,   725,
889      727,   729,   745,   747,   751,   753,   755,   757,   759,   761,
890      763,   765,   767,   769,   771,   775,   780,   785,   790,   795,
891      800,   805,   810,   817,   822,   827,   832,   839,   844,   849,
892      854,   859,   864,   871,   876,   881,   888,   891,   894,   898,
893      900,   931,   938,   943,   960,   965,   982,   989,   991,   993,
894      998,  1002,  1006,  1010,  1012,  1014,  1018,  1019,  1023,  1025,
895     1027,  1029,  1033,  1035,  1037,  1039,  1041,  1043,  1047,  1049,
896     1058,  1066,  1067,  1073,  1074,  1081,  1085,  1087,  1089,  1096,
897     1098,  1100,  1104,  1105,  1108,  1110,  1112,  1116,  1117,  1126,
898     1139,  1155,  1170,  1172,  1174,  1181,  1184,  1188,  1190,  1196,
899     1202,  1208,  1214,  1234,  1236,  1259,  1263,  1265
900 };
901 #endif
902
903 #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
904 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
905    First, the terminals, then, starting at YYNTOKENS, nonterminals.  */
906 static const char *const yytname[] =
907 {
908   "$end", "error", "$undefined", "IF", "THEN", "ELSE", "ELIF", "FI",
909   "CASE", "ESAC", "FOR", "SELECT", "WHILE", "UNTIL", "DO", "DONE",
910   "FUNCTION", "COPROC", "COND_START", "COND_END", "COND_ERROR", "IN",
911   "BANG", "TIME", "TIMEOPT", "WORD", "ASSIGNMENT_WORD", "REDIR_WORD",
912   "NUMBER", "ARITH_CMD", "ARITH_FOR_EXPRS", "COND_CMD", "AND_AND", "OR_OR",
913   "GREATER_GREATER", "LESS_LESS", "LESS_AND", "LESS_LESS_LESS",
914   "GREATER_AND", "SEMI_SEMI", "SEMI_AND", "SEMI_SEMI_AND",
915   "LESS_LESS_MINUS", "AND_GREATER", "AND_GREATER_GREATER", "LESS_GREATER",
916   "GREATER_BAR", "BAR_AND", "'&'", "';'", "'\\n'", "yacc_EOF", "'|'",
917   "'>'", "'<'", "'-'", "'{'", "'}'", "'('", "')'", "$accept", "inputunit",
918   "word_list", "redirection", "simple_command_element", "redirection_list",
919   "simple_command", "command", "shell_command", "for_command",
920   "arith_for_command", "select_command", "case_command", "function_def",
921   "function_body", "subshell", "coproc", "if_command", "group_command",
922   "arith_command", "cond_command", "elif_clause", "case_clause",
923   "pattern_list", "case_clause_sequence", "pattern", "list",
924   "compound_list", "list0", "list1", "simple_list_terminator",
925   "list_terminator", "newline_list", "simple_list", "simple_list1",
926   "pipeline_command", "pipeline", "timespec", 0
927 };
928 #endif
929
930 # ifdef YYPRINT
931 /* YYTOKNUM[YYLEX-NUM] -- Internal token number corresponding to
932    token YYLEX-NUM.  */
933 static const yytype_uint16 yytoknum[] =
934 {
935        0,   256,   257,   258,   259,   260,   261,   262,   263,   264,
936      265,   266,   267,   268,   269,   270,   271,   272,   273,   274,
937      275,   276,   277,   278,   279,   280,   281,   282,   283,   284,
938      285,   286,   287,   288,   289,   290,   291,   292,   293,   294,
939      295,   296,   297,   298,   299,   300,   301,   302,    38,    59,
940       10,   303,   124,    62,    60,    45,   123,   125,    40,    41
941 };
942 # endif
943
944 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives.  */
945 static const yytype_uint8 yyr1[] =
946 {
947        0,    60,    61,    61,    61,    61,    62,    62,    63,    63,
948       63,    63,    63,    63,    63,    63,    63,    63,    63,    63,
949       63,    63,    63,    63,    63,    63,    63,    63,    63,    63,
950       63,    63,    63,    63,    63,    63,    63,    63,    63,    63,
951       63,    63,    63,    63,    63,    63,    63,    63,    63,    63,
952       63,    63,    64,    64,    64,    65,    65,    66,    66,    67,
953       67,    67,    67,    67,    68,    68,    68,    68,    68,    68,
954       68,    68,    68,    68,    68,    69,    69,    69,    69,    69,
955       69,    69,    69,    70,    70,    70,    70,    71,    71,    71,
956       71,    71,    71,    72,    72,    72,    73,    73,    73,    74,
957       74,    75,    76,    76,    76,    76,    76,    77,    77,    77,
958       78,    79,    80,    81,    81,    81,    82,    82,    83,    83,
959       83,    83,    84,    84,    84,    84,    84,    84,    85,    85,
960       86,    87,    87,    88,    88,    88,    89,    89,    89,    89,
961       89,    89,    90,    90,    91,    91,    91,    92,    92,    93,
962       93,    93,    94,    94,    94,    94,    94,    95,    95,    95,
963       95,    95,    95,    96,    96,    96,    97,    97
964 };
965
966 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN.  */
967 static const yytype_uint8 yyr2[] =
968 {
969        0,     2,     2,     1,     2,     1,     1,     2,     2,     2,
970        3,     3,     3,     3,     2,     3,     3,     2,     3,     3,
971        2,     3,     3,     2,     3,     3,     2,     3,     3,     2,
972        3,     3,     2,     3,     3,     2,     3,     3,     2,     3,
973        3,     2,     3,     3,     2,     3,     3,     2,     3,     3,
974        2,     2,     1,     1,     1,     1,     2,     1,     2,     1,
975        1,     2,     1,     1,     1,     1,     5,     5,     1,     1,
976        1,     1,     1,     1,     1,     6,     6,     7,     7,    10,
977       10,     9,     9,     7,     7,     5,     5,     6,     6,     7,
978        7,    10,    10,     6,     7,     6,     5,     6,     4,     1,
979        2,     3,     2,     3,     3,     4,     2,     5,     7,     6,
980        3,     1,     3,     4,     6,     5,     1,     2,     4,     4,
981        5,     5,     2,     3,     2,     3,     2,     3,     1,     3,
982        2,     1,     2,     3,     3,     3,     4,     4,     4,     4,
983        4,     1,     1,     1,     1,     1,     1,     0,     2,     1,
984        2,     2,     4,     4,     3,     3,     1,     1,     2,     2,
985        3,     3,     2,     4,     4,     1,     1,     2
986 };
987
988 /* YYDEFACT[STATE-NAME] -- Default rule to reduce with in state
989    STATE-NUM when YYTABLE doesn't specify something else to do.  Zero
990    means the default is an error.  */
991 static const yytype_uint8 yydefact[] =
992 {
993        0,     0,   147,     0,     0,     0,   147,   147,     0,     0,
994        0,     0,   166,    52,    53,     0,     0,   111,     0,     0,
995        0,     0,     0,     0,     0,     0,     0,     0,     3,     5,
996        0,     0,   147,   147,     0,    54,    57,    59,   165,    60,
997       64,    74,    68,    65,    62,    70,    63,    69,    71,    72,
998       73,     0,   149,   156,   157,     0,     4,   131,     0,     0,
999      147,   147,     0,   147,     0,     0,   147,    52,   106,   102,
1000        0,   158,     0,   167,     0,     0,     0,     0,     0,     0,
1001        0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
1002        0,     0,     0,     0,     0,    14,    23,    38,    32,    47,
1003       29,    41,    35,    44,    26,    50,    51,    20,    17,     8,
1004        9,     0,     0,     1,    52,    58,    55,    61,   142,   143,
1005        2,   147,   147,   150,   151,   147,   147,     0,   145,   144,
1006      146,   162,   159,   147,   148,   130,   132,   141,     0,   147,
1007        0,   147,   147,   147,   147,     0,   147,   147,     0,     0,
1008      104,   103,   112,   161,   147,    16,    25,    40,    34,    49,
1009       31,    43,    37,    46,    28,    22,    19,    12,    13,    15,
1010       24,    39,    33,    48,    30,    42,    36,    45,    27,    21,
1011       18,    10,    11,   110,   101,    56,     0,     0,   154,   155,
1012        0,     0,   160,     0,   147,   147,   147,   147,   147,   147,
1013        0,   147,     0,   147,     0,     0,     0,     0,   147,     0,
1014      147,     0,     0,   147,    99,    98,   105,     0,   152,   153,
1015        0,     0,   164,   163,   147,   147,   107,     0,     0,     0,
1016      134,   135,   133,     0,   116,   147,     0,   147,   147,     0,
1017        6,     0,   147,     0,    85,    86,   147,   147,   147,   147,
1018        0,     0,     0,     0,    66,    67,     0,   100,    96,     0,
1019        0,   109,   136,   137,   138,   139,   140,    95,   122,   124,
1020      126,   117,     0,    93,   128,     0,     0,     0,     0,    75,
1021        7,   147,     0,    76,     0,     0,     0,     0,    87,     0,
1022      147,    88,    97,   108,   147,   147,   147,   147,   123,   125,
1023      127,    94,     0,     0,   147,    77,    78,     0,   147,   147,
1024       83,    84,    89,    90,     0,   113,     0,     0,     0,   147,
1025      129,   118,   119,   147,   147,     0,     0,   147,   147,   147,
1026      115,   120,   121,     0,     0,    81,    82,     0,     0,   114,
1027       79,    80,    91,    92
1028 };
1029
1030 /* YYDEFGOTO[NTERM-NUM].  */
1031 static const yytype_int16 yydefgoto[] =
1032 {
1033       -1,    34,   241,    35,    36,   117,    37,    38,    39,    40,
1034       41,    42,    43,    44,   215,    45,    46,    47,    48,    49,
1035       50,   227,   233,   234,   235,   276,    57,    58,   135,   136,
1036      120,   131,    59,    51,   188,   137,    54,    55
1037 };
1038
1039 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
1040    STATE-NUM.  */
1041 #define YYPACT_NINF -212
1042 static const yytype_int16 yypact[] =
1043 {
1044      318,   -40,  -212,    11,    10,    32,  -212,  -212,    34,   661,
1045       39,   514,    52,    21,  -212,   255,   706,  -212,    65,    79,
1046       47,    98,    55,   133,   134,   139,   151,   152,  -212,  -212,
1047      156,   157,  -212,  -212,   142,  -212,  -212,   232,  -212,   693,
1048     -212,  -212,  -212,  -212,  -212,  -212,  -212,  -212,  -212,  -212,
1049     -212,    49,   213,  -212,   -28,   367,  -212,  -212,   150,   416,
1050     -212,   135,    -3,   137,   184,   194,   158,    31,   232,   693,
1051      191,   -28,   612,  -212,   166,   199,   202,    69,   209,   128,
1052      210,   214,   218,   219,   225,   227,   247,   165,   248,   181,
1053      256,   257,   258,   259,   262,  -212,  -212,  -212,  -212,  -212,
1054     -212,  -212,  -212,  -212,  -212,  -212,  -212,  -212,  -212,  -212,
1055     -212,   237,   236,  -212,  -212,  -212,  -212,   693,  -212,  -212,
1056     -212,  -212,  -212,   465,   465,  -212,  -212,   612,  -212,  -212,
1057     -212,  -212,   -28,  -212,  -212,  -212,   205,  -212,   -13,  -212,
1058      116,  -212,  -212,  -212,  -212,   117,  -212,  -212,   240,    53,
1059      693,   693,  -212,   -28,  -212,  -212,  -212,  -212,  -212,  -212,
1060     -212,  -212,  -212,  -212,  -212,  -212,  -212,  -212,  -212,  -212,
1061     -212,  -212,  -212,  -212,  -212,  -212,  -212,  -212,  -212,  -212,
1062     -212,  -212,  -212,  -212,  -212,  -212,   416,   416,    75,    75,
1063      563,   563,   -28,    15,  -212,  -212,  -212,  -212,  -212,  -212,
1064       72,  -212,   120,  -212,   281,   249,   105,   118,  -212,   279,
1065     -212,   290,   292,  -212,   693,  -212,   693,    53,  -212,  -212,
1066      465,   465,   -28,   -28,  -212,  -212,  -212,   303,   416,   416,
1067      416,   416,   416,   302,   174,  -212,     0,  -212,  -212,   297,
1068     -212,   179,  -212,   263,  -212,  -212,  -212,  -212,  -212,  -212,
1069      299,   416,   179,   265,  -212,  -212,    53,   693,  -212,   308,
1070      312,  -212,  -212,  -212,    80,    80,    80,  -212,  -212,  -212,
1071     -212,   224,    43,  -212,  -212,   300,    33,   309,   270,  -212,
1072     -212,  -212,   129,  -212,   317,   276,   322,   282,  -212,   205,
1073     -212,  -212,  -212,  -212,  -212,  -212,  -212,  -212,  -212,  -212,
1074     -212,  -212,    46,   313,  -212,  -212,  -212,   149,  -212,  -212,
1075     -212,  -212,  -212,  -212,   161,   115,   416,   416,   416,  -212,
1076     -212,  -212,   416,  -212,  -212,   327,   291,  -212,  -212,  -212,
1077     -212,  -212,   416,   334,   293,  -212,  -212,   336,   301,  -212,
1078     -212,  -212,  -212,  -212
1079 };
1080
1081 /* YYPGOTO[NTERM-NUM].  */
1082 static const yytype_int16 yypgoto[] =
1083 {
1084     -212,  -212,   148,   -36,     1,   -62,   350,  -212,    -5,  -212,
1085     -212,  -212,  -212,  -212,  -211,  -212,  -212,  -212,  -212,  -212,
1086     -212,    50,  -212,   131,  -212,    92,  -194,    -6,  -212,  -200,
1087     -212,   -45,   -48,  -212,     5,     2,    12,   362
1088 };
1089
1090 /* YYTABLE[YYPACT[STATE-NUM]].  What to do in state STATE-NUM.  If
1091    positive, shift that token.  If negative, reduce the rule which
1092    number is the opposite.  If zero, do what YYDEFACT says.
1093    If YYTABLE_NINF, syntax error.  */
1094 #define YYTABLE_NINF -1
1095 static const yytype_uint16 yytable[] =
1096 {
1097       64,    65,    53,   116,    69,    52,   258,   151,   199,   273,
1098       56,   141,   138,   140,   250,   145,   253,   143,   149,   125,
1099      224,   225,   226,    71,   126,   274,   111,   112,   262,   263,
1100      264,   265,   266,   116,     2,    61,    60,   134,   115,     3,
1101       62,     4,     5,     6,     7,   292,   128,   129,   130,    10,
1102      134,   289,   301,   142,   286,   287,     2,    63,   275,    66,
1103       17,     3,   150,     4,     5,     6,     7,   132,   274,   115,
1104       70,    10,    97,   186,   187,    98,    73,   190,   191,    74,
1105      101,   185,    17,   102,   153,   303,   237,    32,   216,    33,
1106       95,   200,   304,   134,   157,   206,   207,   158,   303,   118,
1107      119,   275,    99,   134,    96,   319,   217,   121,   122,    32,
1108      103,    33,   194,   195,   116,   185,   264,   265,   266,   246,
1109      329,   225,   134,   100,   159,    53,    53,   193,   238,   189,
1110      201,   208,   248,   337,   338,   204,   205,   202,   209,   192,
1111      211,   212,   113,   308,   214,   240,   228,   229,   230,   231,
1112      232,   236,   257,   161,   133,   134,   162,   242,   104,   105,
1113      251,   247,   251,   323,   106,   256,   134,   134,   134,   128,
1114      129,   130,   203,   210,   249,   327,   107,   108,   116,   134,
1115      185,   109,   110,   163,   139,   309,   144,   272,    53,    53,
1116      171,   218,   219,   172,   282,   239,   281,   243,   146,   134,
1117      251,   251,   222,   223,   280,   324,   175,   290,   147,   176,
1118      152,   134,   214,   268,   269,   270,   148,   328,   259,   260,
1119      173,   185,    53,    53,   155,   154,   189,   156,   128,   129,
1120      130,   277,   278,   307,   160,   164,   177,   194,   195,   165,
1121      284,   285,   314,   166,   167,   121,   122,   316,   317,   318,
1122      168,   214,   169,   196,   197,   198,   322,   114,    14,    15,
1123       16,   123,   124,   298,   299,   300,    18,    19,    20,    21,
1124       22,   332,   170,   174,    23,    24,    25,    26,    27,   251,
1125      251,   178,   179,   180,   181,    30,    31,   182,   315,    75,
1126       76,    77,    78,    79,   183,   184,   244,    80,   321,   213,
1127       81,    82,   325,   326,   240,   254,   245,   255,    83,    84,
1128      261,   267,   279,   331,   288,   293,   294,   333,   334,     1,
1129      283,     2,   291,   339,   305,   274,     3,   306,     4,     5,
1130        6,     7,   310,   311,     8,     9,    10,   312,   320,   313,
1131       11,    12,   335,    13,    14,    15,    16,    17,   336,   340,
1132      341,   342,    18,    19,    20,    21,    22,   252,   343,    68,
1133       23,    24,    25,    26,    27,   330,   271,   302,    28,    29,
1134        2,    30,    31,    72,    32,     3,    33,     4,     5,     6,
1135        7,     0,     0,     8,     9,    10,     0,     0,     0,   127,
1136        0,     0,    13,    14,    15,    16,    17,     0,     0,     0,
1137        0,    18,    19,    20,    21,    22,     0,     0,     0,    23,
1138       24,    25,    26,    27,     0,     0,   128,   129,   130,     2,
1139       30,    31,     0,    32,     3,    33,     4,     5,     6,     7,
1140        0,     0,     8,     9,    10,     0,     0,     0,    11,    12,
1141        0,    13,    14,    15,    16,    17,     0,     0,     0,     0,
1142       18,    19,    20,    21,    22,     0,     0,     0,    23,    24,
1143       25,    26,    27,     0,     0,     0,   134,     0,     2,    30,
1144       31,     0,    32,     3,    33,     4,     5,     6,     7,     0,
1145        0,     8,     9,    10,     0,     0,     0,    11,    12,     0,
1146       13,    14,    15,    16,    17,     0,     0,     0,     0,    18,
1147       19,    20,    21,    22,     0,     0,     0,    23,    24,    25,
1148       26,    27,     0,     0,     0,     0,     0,     2,    30,    31,
1149        0,    32,     3,    33,     4,     5,     6,     7,     0,     0,
1150        8,     9,    10,     0,     0,     0,     0,    12,     0,    13,
1151       14,    15,    16,    17,     0,     0,     0,     0,    18,    19,
1152       20,    21,    22,     0,     0,     0,    23,    24,    25,    26,
1153       27,     0,     0,     0,     0,     0,     2,    30,    31,     0,
1154       32,     3,    33,     4,     5,     6,     7,     0,     0,     8,
1155        9,    10,     0,     0,     0,     0,     0,     0,    13,    14,
1156       15,    16,    17,     0,     0,     0,     0,    18,    19,    20,
1157       21,    22,     0,     0,     0,    23,    24,    25,    26,    27,
1158        0,     0,     0,   134,     0,     2,    30,    31,     0,    32,
1159        3,    33,     4,     5,     6,     7,     0,     0,     8,     9,
1160       10,     0,     0,     0,     0,     0,     0,    13,    14,    15,
1161       16,    17,     0,     0,     0,     0,    18,    19,    20,    21,
1162       22,     0,     0,     0,    23,    24,    25,    26,    27,     0,
1163        0,     0,     0,     0,     2,    30,    31,     0,    32,     3,
1164       33,     4,     5,     6,     7,     0,     0,     0,     0,    10,
1165        0,     0,     0,     0,     0,     0,    67,    14,    15,    16,
1166       17,     0,     0,     0,     0,    18,    19,    20,    21,    22,
1167        0,     0,     0,    23,    24,    25,    26,    27,     0,     0,
1168        0,     0,     0,     0,    30,    31,     0,    32,     0,    33,
1169       15,    16,     0,     0,     0,     0,     0,    18,    19,    20,
1170       21,    22,     0,     0,     0,    23,    24,    25,    26,    27,
1171       85,    86,    87,    88,    89,     0,    30,    31,    90,     0,
1172        0,    91,    92,     0,     0,     0,     0,     0,     0,    93,
1173       94
1174 };
1175
1176 static const yytype_int16 yycheck[] =
1177 {
1178        6,     7,     0,    39,     9,     0,   217,    69,    21,     9,
1179       50,    14,    60,    61,   208,    63,   210,    62,    66,    47,
1180        5,     6,     7,    11,    52,    25,    32,    33,   228,   229,
1181      230,   231,   232,    69,     3,    25,    25,    50,    37,     8,
1182       30,    10,    11,    12,    13,   256,    49,    50,    51,    18,
1183       50,   251,     9,    56,   248,   249,     3,    25,    58,    25,
1184       29,     8,    67,    10,    11,    12,    13,    55,    25,    68,
1185       31,    18,    25,   121,   122,    28,    24,   125,   126,    58,
1186       25,   117,    29,    28,    72,    52,    14,    56,   150,    58,
1187       25,   139,    59,    50,    25,   143,   144,    28,    52,    50,
1188       51,    58,    55,    50,    25,    59,   154,    32,    33,    56,
1189       55,    58,    32,    33,   150,   151,   316,   317,   318,    14,
1190        5,     6,    50,    25,    55,   123,   124,   133,    56,   124,
1191       14,    14,    14,   327,   328,   141,   142,    21,    21,   127,
1192      146,   147,     0,    14,   149,    25,   194,   195,   196,   197,
1193      198,   199,   214,    25,     4,    50,    28,   202,    25,    25,
1194      208,    56,   210,    14,    25,   213,    50,    50,    50,    49,
1195       50,    51,    56,    56,    56,    14,    25,    25,   214,    50,
1196      216,    25,    25,    55,    49,    56,    49,   235,   186,   187,
1197       25,   186,   187,    28,   242,   201,   241,   203,    14,    50,
1198      248,   249,   190,   191,    25,    56,    25,   252,    14,    28,
1199       19,    50,   217,    39,    40,    41,    58,    56,   224,   225,
1200       55,   257,   220,   221,    25,    59,   221,    25,    49,    50,
1201       51,   237,   238,   281,    25,    25,    55,    32,    33,    25,
1202      246,   247,   290,    25,    25,    32,    33,   295,   296,   297,
1203       25,   256,    25,    48,    49,    50,   304,    25,    26,    27,
1204       28,    48,    49,    39,    40,    41,    34,    35,    36,    37,
1205       38,   319,    25,    25,    42,    43,    44,    45,    46,   327,
1206      328,    25,    25,    25,    25,    53,    54,    25,   294,    34,
1207       35,    36,    37,    38,    57,    59,    15,    42,   304,    59,
1208       45,    46,   308,   309,    25,    15,    57,    15,    53,    54,
1209        7,     9,    15,   319,    15,     7,     4,   323,   324,     1,
1210       57,     3,    57,   329,    15,    25,     8,    57,    10,    11,
1211       12,    13,    15,    57,    16,    17,    18,    15,    25,    57,
1212       22,    23,    15,    25,    26,    27,    28,    29,    57,    15,
1213       57,    15,    34,    35,    36,    37,    38,   209,    57,     9,
1214       42,    43,    44,    45,    46,   315,   235,   275,    50,    51,
1215        3,    53,    54,    11,    56,     8,    58,    10,    11,    12,
1216       13,    -1,    -1,    16,    17,    18,    -1,    -1,    -1,    22,
1217       -1,    -1,    25,    26,    27,    28,    29,    -1,    -1,    -1,
1218       -1,    34,    35,    36,    37,    38,    -1,    -1,    -1,    42,
1219       43,    44,    45,    46,    -1,    -1,    49,    50,    51,     3,
1220       53,    54,    -1,    56,     8,    58,    10,    11,    12,    13,
1221       -1,    -1,    16,    17,    18,    -1,    -1,    -1,    22,    23,
1222       -1,    25,    26,    27,    28,    29,    -1,    -1,    -1,    -1,
1223       34,    35,    36,    37,    38,    -1,    -1,    -1,    42,    43,
1224       44,    45,    46,    -1,    -1,    -1,    50,    -1,     3,    53,
1225       54,    -1,    56,     8,    58,    10,    11,    12,    13,    -1,
1226       -1,    16,    17,    18,    -1,    -1,    -1,    22,    23,    -1,
1227       25,    26,    27,    28,    29,    -1,    -1,    -1,    -1,    34,
1228       35,    36,    37,    38,    -1,    -1,    -1,    42,    43,    44,
1229       45,    46,    -1,    -1,    -1,    -1,    -1,     3,    53,    54,
1230       -1,    56,     8,    58,    10,    11,    12,    13,    -1,    -1,
1231       16,    17,    18,    -1,    -1,    -1,    -1,    23,    -1,    25,
1232       26,    27,    28,    29,    -1,    -1,    -1,    -1,    34,    35,
1233       36,    37,    38,    -1,    -1,    -1,    42,    43,    44,    45,
1234       46,    -1,    -1,    -1,    -1,    -1,     3,    53,    54,    -1,
1235       56,     8,    58,    10,    11,    12,    13,    -1,    -1,    16,
1236       17,    18,    -1,    -1,    -1,    -1,    -1,    -1,    25,    26,
1237       27,    28,    29,    -1,    -1,    -1,    -1,    34,    35,    36,
1238       37,    38,    -1,    -1,    -1,    42,    43,    44,    45,    46,
1239       -1,    -1,    -1,    50,    -1,     3,    53,    54,    -1,    56,
1240        8,    58,    10,    11,    12,    13,    -1,    -1,    16,    17,
1241       18,    -1,    -1,    -1,    -1,    -1,    -1,    25,    26,    27,
1242       28,    29,    -1,    -1,    -1,    -1,    34,    35,    36,    37,
1243       38,    -1,    -1,    -1,    42,    43,    44,    45,    46,    -1,
1244       -1,    -1,    -1,    -1,     3,    53,    54,    -1,    56,     8,
1245       58,    10,    11,    12,    13,    -1,    -1,    -1,    -1,    18,
1246       -1,    -1,    -1,    -1,    -1,    -1,    25,    26,    27,    28,
1247       29,    -1,    -1,    -1,    -1,    34,    35,    36,    37,    38,
1248       -1,    -1,    -1,    42,    43,    44,    45,    46,    -1,    -1,
1249       -1,    -1,    -1,    -1,    53,    54,    -1,    56,    -1,    58,
1250       27,    28,    -1,    -1,    -1,    -1,    -1,    34,    35,    36,
1251       37,    38,    -1,    -1,    -1,    42,    43,    44,    45,    46,
1252       34,    35,    36,    37,    38,    -1,    53,    54,    42,    -1,
1253       -1,    45,    46,    -1,    -1,    -1,    -1,    -1,    -1,    53,
1254       54
1255 };
1256
1257 /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
1258    symbol of state STATE-NUM.  */
1259 static const yytype_uint8 yystos[] =
1260 {
1261        0,     1,     3,     8,    10,    11,    12,    13,    16,    17,
1262       18,    22,    23,    25,    26,    27,    28,    29,    34,    35,
1263       36,    37,    38,    42,    43,    44,    45,    46,    50,    51,
1264       53,    54,    56,    58,    61,    63,    64,    66,    67,    68,
1265       69,    70,    71,    72,    73,    75,    76,    77,    78,    79,
1266       80,    93,    94,    95,    96,    97,    50,    86,    87,    92,
1267       25,    25,    30,    25,    87,    87,    25,    25,    66,    68,
1268       31,    96,    97,    24,    58,    34,    35,    36,    37,    38,
1269       42,    45,    46,    53,    54,    34,    35,    36,    37,    38,
1270       42,    45,    46,    53,    54,    25,    25,    25,    28,    55,
1271       25,    25,    28,    55,    25,    25,    25,    25,    25,    25,
1272       25,    87,    87,     0,    25,    64,    63,    65,    50,    51,
1273       90,    32,    33,    48,    49,    47,    52,    22,    49,    50,
1274       51,    91,    96,     4,    50,    88,    89,    95,    92,    49,
1275       92,    14,    56,    91,    49,    92,    14,    14,    58,    92,
1276       68,    65,    19,    96,    59,    25,    25,    25,    28,    55,
1277       25,    25,    28,    55,    25,    25,    25,    25,    25,    25,
1278       25,    25,    28,    55,    25,    25,    28,    55,    25,    25,
1279       25,    25,    25,    57,    59,    63,    92,    92,    94,    94,
1280       92,    92,    96,    87,    32,    33,    48,    49,    50,    21,
1281       92,    14,    21,    56,    87,    87,    92,    92,    14,    21,
1282       56,    87,    87,    59,    68,    74,    65,    92,    94,    94,
1283       48,    49,    96,    96,     5,     6,     7,    81,    92,    92,
1284       92,    92,    92,    82,    83,    84,    92,    14,    56,    87,
1285       25,    62,    91,    87,    15,    57,    14,    56,    14,    56,
1286       86,    92,    62,    86,    15,    15,    92,    65,    74,    87,
1287       87,     7,    89,    89,    89,    89,    89,     9,    39,    40,
1288       41,    83,    92,     9,    25,    58,    85,    87,    87,    15,
1289       25,    91,    92,    57,    87,    87,    86,    86,    15,    89,
1290       91,    57,    74,     7,     4,    48,    49,    50,    39,    40,
1291       41,     9,    85,    52,    59,    15,    57,    92,    14,    56,
1292       15,    57,    15,    57,    92,    87,    92,    92,    92,    59,
1293       25,    87,    92,    14,    56,    87,    87,    14,    56,     5,
1294       81,    87,    92,    87,    87,    15,    57,    86,    86,    87,
1295       15,    57,    15,    57
1296 };
1297
1298 #define yyerrok         (yyerrstatus = 0)
1299 #define yyclearin       (yychar = YYEMPTY)
1300 #define YYEMPTY         (-2)
1301 #define YYEOF           0
1302
1303 #define YYACCEPT        goto yyacceptlab
1304 #define YYABORT         goto yyabortlab
1305 #define YYERROR         goto yyerrorlab
1306
1307
1308 /* Like YYERROR except do call yyerror.  This remains here temporarily
1309    to ease the transition to the new meaning of YYERROR, for GCC.
1310    Once GCC version 2 has supplanted version 1, this can go.  */
1311
1312 #define YYFAIL          goto yyerrlab
1313
1314 #define YYRECOVERING()  (!!yyerrstatus)
1315
1316 #define YYBACKUP(Token, Value)                                  \
1317 do                                                              \
1318   if (yychar == YYEMPTY && yylen == 1)                          \
1319     {                                                           \
1320       yychar = (Token);                                         \
1321       yylval = (Value);                                         \
1322       yytoken = YYTRANSLATE (yychar);                           \
1323       YYPOPSTACK (1);                                           \
1324       goto yybackup;                                            \
1325     }                                                           \
1326   else                                                          \
1327     {                                                           \
1328       yyerror (YY_("syntax error: cannot back up")); \
1329       YYERROR;                                                  \
1330     }                                                           \
1331 while (YYID (0))
1332
1333
1334 #define YYTERROR        1
1335 #define YYERRCODE       256
1336
1337
1338 /* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
1339    If N is 0, then set CURRENT to the empty location which ends
1340    the previous symbol: RHS[0] (always defined).  */
1341
1342 #define YYRHSLOC(Rhs, K) ((Rhs)[K])
1343 #ifndef YYLLOC_DEFAULT
1344 # define YYLLOC_DEFAULT(Current, Rhs, N)                                \
1345     do                                                                  \
1346       if (YYID (N))                                                    \
1347         {                                                               \
1348           (Current).first_line   = YYRHSLOC (Rhs, 1).first_line;        \
1349           (Current).first_column = YYRHSLOC (Rhs, 1).first_column;      \
1350           (Current).last_line    = YYRHSLOC (Rhs, N).last_line;         \
1351           (Current).last_column  = YYRHSLOC (Rhs, N).last_column;       \
1352         }                                                               \
1353       else                                                              \
1354         {                                                               \
1355           (Current).first_line   = (Current).last_line   =              \
1356             YYRHSLOC (Rhs, 0).last_line;                                \
1357           (Current).first_column = (Current).last_column =              \
1358             YYRHSLOC (Rhs, 0).last_column;                              \
1359         }                                                               \
1360     while (YYID (0))
1361 #endif
1362
1363
1364 /* YY_LOCATION_PRINT -- Print the location on the stream.
1365    This macro was not mandated originally: define only if we know
1366    we won't break user code: when these are the locations we know.  */
1367
1368 #ifndef YY_LOCATION_PRINT
1369 # if YYLTYPE_IS_TRIVIAL
1370 #  define YY_LOCATION_PRINT(File, Loc)                  \
1371      fprintf (File, "%d.%d-%d.%d",                      \
1372               (Loc).first_line, (Loc).first_column,     \
1373               (Loc).last_line,  (Loc).last_column)
1374 # else
1375 #  define YY_LOCATION_PRINT(File, Loc) ((void) 0)
1376 # endif
1377 #endif
1378
1379
1380 /* YYLEX -- calling `yylex' with the right arguments.  */
1381
1382 #ifdef YYLEX_PARAM
1383 # define YYLEX yylex (YYLEX_PARAM)
1384 #else
1385 # define YYLEX yylex ()
1386 #endif
1387
1388 /* Enable debugging if requested.  */
1389 #if YYDEBUG
1390
1391 # ifndef YYFPRINTF
1392 #  include <stdio.h> /* INFRINGES ON USER NAME SPACE */
1393 #  define YYFPRINTF fprintf
1394 # endif
1395
1396 # define YYDPRINTF(Args)                        \
1397 do {                                            \
1398   if (yydebug)                                  \
1399     YYFPRINTF Args;                             \
1400 } while (YYID (0))
1401
1402 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)                    \
1403 do {                                                                      \
1404   if (yydebug)                                                            \
1405     {                                                                     \
1406       YYFPRINTF (stderr, "%s ", Title);                                   \
1407       yy_symbol_print (stderr,                                            \
1408                   Type, Value); \
1409       YYFPRINTF (stderr, "\n");                                           \
1410     }                                                                     \
1411 } while (YYID (0))
1412
1413
1414 /*--------------------------------.
1415 | Print this symbol on YYOUTPUT.  |
1416 `--------------------------------*/
1417
1418 /*ARGSUSED*/
1419 #if (defined __STDC__ || defined __C99__FUNC__ \
1420      || defined __cplusplus || defined _MSC_VER)
1421 static void
1422 yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep)
1423 #else
1424 static void
1425 yy_symbol_value_print (yyoutput, yytype, yyvaluep)
1426     FILE *yyoutput;
1427     int yytype;
1428     YYSTYPE const * const yyvaluep;
1429 #endif
1430 {
1431   if (!yyvaluep)
1432     return;
1433 # ifdef YYPRINT
1434   if (yytype < YYNTOKENS)
1435     YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep);
1436 # else
1437   YYUSE (yyoutput);
1438 # endif
1439   switch (yytype)
1440     {
1441       default:
1442         break;
1443     }
1444 }
1445
1446
1447 /*--------------------------------.
1448 | Print this symbol on YYOUTPUT.  |
1449 `--------------------------------*/
1450
1451 #if (defined __STDC__ || defined __C99__FUNC__ \
1452      || defined __cplusplus || defined _MSC_VER)
1453 static void
1454 yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep)
1455 #else
1456 static void
1457 yy_symbol_print (yyoutput, yytype, yyvaluep)
1458     FILE *yyoutput;
1459     int yytype;
1460     YYSTYPE const * const yyvaluep;
1461 #endif
1462 {
1463   if (yytype < YYNTOKENS)
1464     YYFPRINTF (yyoutput, "token %s (", yytname[yytype]);
1465   else
1466     YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]);
1467
1468   yy_symbol_value_print (yyoutput, yytype, yyvaluep);
1469   YYFPRINTF (yyoutput, ")");
1470 }
1471
1472 /*------------------------------------------------------------------.
1473 | yy_stack_print -- Print the state stack from its BOTTOM up to its |
1474 | TOP (included).                                                   |
1475 `------------------------------------------------------------------*/
1476
1477 #if (defined __STDC__ || defined __C99__FUNC__ \
1478      || defined __cplusplus || defined _MSC_VER)
1479 static void
1480 yy_stack_print (yytype_int16 *bottom, yytype_int16 *top)
1481 #else
1482 static void
1483 yy_stack_print (bottom, top)
1484     yytype_int16 *bottom;
1485     yytype_int16 *top;
1486 #endif
1487 {
1488   YYFPRINTF (stderr, "Stack now");
1489   for (; bottom <= top; ++bottom)
1490     YYFPRINTF (stderr, " %d", *bottom);
1491   YYFPRINTF (stderr, "\n");
1492 }
1493
1494 # define YY_STACK_PRINT(Bottom, Top)                            \
1495 do {                                                            \
1496   if (yydebug)                                                  \
1497     yy_stack_print ((Bottom), (Top));                           \
1498 } while (YYID (0))
1499
1500
1501 /*------------------------------------------------.
1502 | Report that the YYRULE is going to be reduced.  |
1503 `------------------------------------------------*/
1504
1505 #if (defined __STDC__ || defined __C99__FUNC__ \
1506      || defined __cplusplus || defined _MSC_VER)
1507 static void
1508 yy_reduce_print (YYSTYPE *yyvsp, int yyrule)
1509 #else
1510 static void
1511 yy_reduce_print (yyvsp, yyrule)
1512     YYSTYPE *yyvsp;
1513     int yyrule;
1514 #endif
1515 {
1516   int yynrhs = yyr2[yyrule];
1517   int yyi;
1518   unsigned long int yylno = yyrline[yyrule];
1519   YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n",
1520              yyrule - 1, yylno);
1521   /* The symbols being reduced.  */
1522   for (yyi = 0; yyi < yynrhs; yyi++)
1523     {
1524       fprintf (stderr, "   $%d = ", yyi + 1);
1525       yy_symbol_print (stderr, yyrhs[yyprhs[yyrule] + yyi],
1526                        &(yyvsp[(yyi + 1) - (yynrhs)])
1527                                        );
1528       fprintf (stderr, "\n");
1529     }
1530 }
1531
1532 # define YY_REDUCE_PRINT(Rule)          \
1533 do {                                    \
1534   if (yydebug)                          \
1535     yy_reduce_print (yyvsp, Rule); \
1536 } while (YYID (0))
1537
1538 /* Nonzero means print parse trace.  It is left uninitialized so that
1539    multiple parsers can coexist.  */
1540 int yydebug;
1541 #else /* !YYDEBUG */
1542 # define YYDPRINTF(Args)
1543 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
1544 # define YY_STACK_PRINT(Bottom, Top)
1545 # define YY_REDUCE_PRINT(Rule)
1546 #endif /* !YYDEBUG */
1547
1548
1549 /* YYINITDEPTH -- initial size of the parser's stacks.  */
1550 #ifndef YYINITDEPTH
1551 # define YYINITDEPTH 200
1552 #endif
1553
1554 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
1555    if the built-in stack extension method is used).
1556
1557    Do not make this value too large; the results are undefined if
1558    YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH)
1559    evaluated with infinite-precision integer arithmetic.  */
1560
1561 #ifndef YYMAXDEPTH
1562 # define YYMAXDEPTH 10000
1563 #endif
1564
1565 \f
1566
1567 #if YYERROR_VERBOSE
1568
1569 # ifndef yystrlen
1570 #  if defined __GLIBC__ && defined _STRING_H
1571 #   define yystrlen strlen
1572 #  else
1573 /* Return the length of YYSTR.  */
1574 #if (defined __STDC__ || defined __C99__FUNC__ \
1575      || defined __cplusplus || defined _MSC_VER)
1576 static YYSIZE_T
1577 yystrlen (const char *yystr)
1578 #else
1579 static YYSIZE_T
1580 yystrlen (yystr)
1581     const char *yystr;
1582 #endif
1583 {
1584   YYSIZE_T yylen;
1585   for (yylen = 0; yystr[yylen]; yylen++)
1586     continue;
1587   return yylen;
1588 }
1589 #  endif
1590 # endif
1591
1592 # ifndef yystpcpy
1593 #  if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
1594 #   define yystpcpy stpcpy
1595 #  else
1596 /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
1597    YYDEST.  */
1598 #if (defined __STDC__ || defined __C99__FUNC__ \
1599      || defined __cplusplus || defined _MSC_VER)
1600 static char *
1601 yystpcpy (char *yydest, const char *yysrc)
1602 #else
1603 static char *
1604 yystpcpy (yydest, yysrc)
1605     char *yydest;
1606     const char *yysrc;
1607 #endif
1608 {
1609   char *yyd = yydest;
1610   const char *yys = yysrc;
1611
1612   while ((*yyd++ = *yys++) != '\0')
1613     continue;
1614
1615   return yyd - 1;
1616 }
1617 #  endif
1618 # endif
1619
1620 # ifndef yytnamerr
1621 /* Copy to YYRES the contents of YYSTR after stripping away unnecessary
1622    quotes and backslashes, so that it's suitable for yyerror.  The
1623    heuristic is that double-quoting is unnecessary unless the string
1624    contains an apostrophe, a comma, or backslash (other than
1625    backslash-backslash).  YYSTR is taken from yytname.  If YYRES is
1626    null, do not copy; instead, return the length of what the result
1627    would have been.  */
1628 static YYSIZE_T
1629 yytnamerr (char *yyres, const char *yystr)
1630 {
1631   if (*yystr == '"')
1632     {
1633       YYSIZE_T yyn = 0;
1634       char const *yyp = yystr;
1635
1636       for (;;)
1637         switch (*++yyp)
1638           {
1639           case '\'':
1640           case ',':
1641             goto do_not_strip_quotes;
1642
1643           case '\\':
1644             if (*++yyp != '\\')
1645               goto do_not_strip_quotes;
1646             /* Fall through.  */
1647           default:
1648             if (yyres)
1649               yyres[yyn] = *yyp;
1650             yyn++;
1651             break;
1652
1653           case '"':
1654             if (yyres)
1655               yyres[yyn] = '\0';
1656             return yyn;
1657           }
1658     do_not_strip_quotes: ;
1659     }
1660
1661   if (! yyres)
1662     return yystrlen (yystr);
1663
1664   return yystpcpy (yyres, yystr) - yyres;
1665 }
1666 # endif
1667
1668 /* Copy into YYRESULT an error message about the unexpected token
1669    YYCHAR while in state YYSTATE.  Return the number of bytes copied,
1670    including the terminating null byte.  If YYRESULT is null, do not
1671    copy anything; just return the number of bytes that would be
1672    copied.  As a special case, return 0 if an ordinary "syntax error"
1673    message will do.  Return YYSIZE_MAXIMUM if overflow occurs during
1674    size calculation.  */
1675 static YYSIZE_T
1676 yysyntax_error (char *yyresult, int yystate, int yychar)
1677 {
1678   int yyn = yypact[yystate];
1679
1680   if (! (YYPACT_NINF < yyn && yyn <= YYLAST))
1681     return 0;
1682   else
1683     {
1684       int yytype = YYTRANSLATE (yychar);
1685       YYSIZE_T yysize0 = yytnamerr (0, yytname[yytype]);
1686       YYSIZE_T yysize = yysize0;
1687       YYSIZE_T yysize1;
1688       int yysize_overflow = 0;
1689       enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
1690       char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
1691       int yyx;
1692
1693 # if 0
1694       /* This is so xgettext sees the translatable formats that are
1695          constructed on the fly.  */
1696       YY_("syntax error, unexpected %s");
1697       YY_("syntax error, unexpected %s, expecting %s");
1698       YY_("syntax error, unexpected %s, expecting %s or %s");
1699       YY_("syntax error, unexpected %s, expecting %s or %s or %s");
1700       YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s");
1701 # endif
1702       char *yyfmt;
1703       char const *yyf;
1704       static char const yyunexpected[] = "syntax error, unexpected %s";
1705       static char const yyexpecting[] = ", expecting %s";
1706       static char const yyor[] = " or %s";
1707       char yyformat[sizeof yyunexpected
1708                     + sizeof yyexpecting - 1
1709                     + ((YYERROR_VERBOSE_ARGS_MAXIMUM - 2)
1710                        * (sizeof yyor - 1))];
1711       char const *yyprefix = yyexpecting;
1712
1713       /* Start YYX at -YYN if negative to avoid negative indexes in
1714          YYCHECK.  */
1715       int yyxbegin = yyn < 0 ? -yyn : 0;
1716
1717       /* Stay within bounds of both yycheck and yytname.  */
1718       int yychecklim = YYLAST - yyn + 1;
1719       int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
1720       int yycount = 1;
1721
1722       yyarg[0] = yytname[yytype];
1723       yyfmt = yystpcpy (yyformat, yyunexpected);
1724
1725       for (yyx = yyxbegin; yyx < yyxend; ++yyx)
1726         if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
1727           {
1728             if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
1729               {
1730                 yycount = 1;
1731                 yysize = yysize0;
1732                 yyformat[sizeof yyunexpected - 1] = '\0';
1733                 break;
1734               }
1735             yyarg[yycount++] = yytname[yyx];
1736             yysize1 = yysize + yytnamerr (0, yytname[yyx]);
1737             yysize_overflow |= (yysize1 < yysize);
1738             yysize = yysize1;
1739             yyfmt = yystpcpy (yyfmt, yyprefix);
1740             yyprefix = yyor;
1741           }
1742
1743       yyf = YY_(yyformat);
1744       yysize1 = yysize + yystrlen (yyf);
1745       yysize_overflow |= (yysize1 < yysize);
1746       yysize = yysize1;
1747
1748       if (yysize_overflow)
1749         return YYSIZE_MAXIMUM;
1750
1751       if (yyresult)
1752         {
1753           /* Avoid sprintf, as that infringes on the user's name space.
1754              Don't have undefined behavior even if the translation
1755              produced a string with the wrong number of "%s"s.  */
1756           char *yyp = yyresult;
1757           int yyi = 0;
1758           while ((*yyp = *yyf) != '\0')
1759             {
1760               if (*yyp == '%' && yyf[1] == 's' && yyi < yycount)
1761                 {
1762                   yyp += yytnamerr (yyp, yyarg[yyi++]);
1763                   yyf += 2;
1764                 }
1765               else
1766                 {
1767                   yyp++;
1768                   yyf++;
1769                 }
1770             }
1771         }
1772       return yysize;
1773     }
1774 }
1775 #endif /* YYERROR_VERBOSE */
1776 \f
1777
1778 /*-----------------------------------------------.
1779 | Release the memory associated to this symbol.  |
1780 `-----------------------------------------------*/
1781
1782 /*ARGSUSED*/
1783 #if (defined __STDC__ || defined __C99__FUNC__ \
1784      || defined __cplusplus || defined _MSC_VER)
1785 static void
1786 yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep)
1787 #else
1788 static void
1789 yydestruct (yymsg, yytype, yyvaluep)
1790     const char *yymsg;
1791     int yytype;
1792     YYSTYPE *yyvaluep;
1793 #endif
1794 {
1795   YYUSE (yyvaluep);
1796
1797   if (!yymsg)
1798     yymsg = "Deleting";
1799   YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
1800
1801   switch (yytype)
1802     {
1803
1804       default:
1805         break;
1806     }
1807 }
1808 \f
1809
1810 /* Prevent warnings from -Wmissing-prototypes.  */
1811
1812 #ifdef YYPARSE_PARAM
1813 #if defined __STDC__ || defined __cplusplus
1814 int yyparse (void *YYPARSE_PARAM);
1815 #else
1816 int yyparse ();
1817 #endif
1818 #else /* ! YYPARSE_PARAM */
1819 #if defined __STDC__ || defined __cplusplus
1820 int yyparse (void);
1821 #else
1822 int yyparse ();
1823 #endif
1824 #endif /* ! YYPARSE_PARAM */
1825
1826
1827
1828 /* The look-ahead symbol.  */
1829 int yychar;
1830
1831 /* The semantic value of the look-ahead symbol.  */
1832 YYSTYPE yylval;
1833
1834 /* Number of syntax errors so far.  */
1835 int yynerrs;
1836
1837
1838
1839 /*----------.
1840 | yyparse.  |
1841 `----------*/
1842
1843 #ifdef YYPARSE_PARAM
1844 #if (defined __STDC__ || defined __C99__FUNC__ \
1845      || defined __cplusplus || defined _MSC_VER)
1846 int
1847 yyparse (void *YYPARSE_PARAM)
1848 #else
1849 int
1850 yyparse (YYPARSE_PARAM)
1851     void *YYPARSE_PARAM;
1852 #endif
1853 #else /* ! YYPARSE_PARAM */
1854 #if (defined __STDC__ || defined __C99__FUNC__ \
1855      || defined __cplusplus || defined _MSC_VER)
1856 int
1857 yyparse (void)
1858 #else
1859 int
1860 yyparse ()
1861
1862 #endif
1863 #endif
1864 {
1865   
1866   int yystate;
1867   int yyn;
1868   int yyresult;
1869   /* Number of tokens to shift before error messages enabled.  */
1870   int yyerrstatus;
1871   /* Look-ahead token as an internal (translated) token number.  */
1872   int yytoken = 0;
1873 #if YYERROR_VERBOSE
1874   /* Buffer for error messages, and its allocated size.  */
1875   char yymsgbuf[128];
1876   char *yymsg = yymsgbuf;
1877   YYSIZE_T yymsg_alloc = sizeof yymsgbuf;
1878 #endif
1879
1880   /* Three stacks and their tools:
1881      `yyss': related to states,
1882      `yyvs': related to semantic values,
1883      `yyls': related to locations.
1884
1885      Refer to the stacks thru separate pointers, to allow yyoverflow
1886      to reallocate them elsewhere.  */
1887
1888   /* The state stack.  */
1889   yytype_int16 yyssa[YYINITDEPTH];
1890   yytype_int16 *yyss = yyssa;
1891   yytype_int16 *yyssp;
1892
1893   /* The semantic value stack.  */
1894   YYSTYPE yyvsa[YYINITDEPTH];
1895   YYSTYPE *yyvs = yyvsa;
1896   YYSTYPE *yyvsp;
1897
1898
1899
1900 #define YYPOPSTACK(N)   (yyvsp -= (N), yyssp -= (N))
1901
1902   YYSIZE_T yystacksize = YYINITDEPTH;
1903
1904   /* The variables used to return semantic value and location from the
1905      action routines.  */
1906   YYSTYPE yyval;
1907
1908
1909   /* The number of symbols on the RHS of the reduced rule.
1910      Keep to zero when no symbol should be popped.  */
1911   int yylen = 0;
1912
1913   YYDPRINTF ((stderr, "Starting parse\n"));
1914
1915   yystate = 0;
1916   yyerrstatus = 0;
1917   yynerrs = 0;
1918   yychar = YYEMPTY;             /* Cause a token to be read.  */
1919
1920   /* Initialize stack pointers.
1921      Waste one element of value and location stack
1922      so that they stay on the same level as the state stack.
1923      The wasted elements are never initialized.  */
1924
1925   yyssp = yyss;
1926   yyvsp = yyvs;
1927
1928   goto yysetstate;
1929
1930 /*------------------------------------------------------------.
1931 | yynewstate -- Push a new state, which is found in yystate.  |
1932 `------------------------------------------------------------*/
1933  yynewstate:
1934   /* In all cases, when you get here, the value and location stacks
1935      have just been pushed.  So pushing a state here evens the stacks.  */
1936   yyssp++;
1937
1938  yysetstate:
1939   *yyssp = yystate;
1940
1941   if (yyss + yystacksize - 1 <= yyssp)
1942     {
1943       /* Get the current used size of the three stacks, in elements.  */
1944       YYSIZE_T yysize = yyssp - yyss + 1;
1945
1946 #ifdef yyoverflow
1947       {
1948         /* Give user a chance to reallocate the stack.  Use copies of
1949            these so that the &'s don't force the real ones into
1950            memory.  */
1951         YYSTYPE *yyvs1 = yyvs;
1952         yytype_int16 *yyss1 = yyss;
1953
1954
1955         /* Each stack pointer address is followed by the size of the
1956            data in use in that stack, in bytes.  This used to be a
1957            conditional around just the two extra args, but that might
1958            be undefined if yyoverflow is a macro.  */
1959         yyoverflow (YY_("memory exhausted"),
1960                     &yyss1, yysize * sizeof (*yyssp),
1961                     &yyvs1, yysize * sizeof (*yyvsp),
1962
1963                     &yystacksize);
1964
1965         yyss = yyss1;
1966         yyvs = yyvs1;
1967       }
1968 #else /* no yyoverflow */
1969 # ifndef YYSTACK_RELOCATE
1970       goto yyexhaustedlab;
1971 # else
1972       /* Extend the stack our own way.  */
1973       if (YYMAXDEPTH <= yystacksize)
1974         goto yyexhaustedlab;
1975       yystacksize *= 2;
1976       if (YYMAXDEPTH < yystacksize)
1977         yystacksize = YYMAXDEPTH;
1978
1979       {
1980         yytype_int16 *yyss1 = yyss;
1981         union yyalloc *yyptr =
1982           (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
1983         if (! yyptr)
1984           goto yyexhaustedlab;
1985         YYSTACK_RELOCATE (yyss);
1986         YYSTACK_RELOCATE (yyvs);
1987
1988 #  undef YYSTACK_RELOCATE
1989         if (yyss1 != yyssa)
1990           YYSTACK_FREE (yyss1);
1991       }
1992 # endif
1993 #endif /* no yyoverflow */
1994
1995       yyssp = yyss + yysize - 1;
1996       yyvsp = yyvs + yysize - 1;
1997
1998
1999       YYDPRINTF ((stderr, "Stack size increased to %lu\n",
2000                   (unsigned long int) yystacksize));
2001
2002       if (yyss + yystacksize - 1 <= yyssp)
2003         YYABORT;
2004     }
2005
2006   YYDPRINTF ((stderr, "Entering state %d\n", yystate));
2007
2008   goto yybackup;
2009
2010 /*-----------.
2011 | yybackup.  |
2012 `-----------*/
2013 yybackup:
2014
2015   /* Do appropriate processing given the current state.  Read a
2016      look-ahead token if we need one and don't already have one.  */
2017
2018   /* First try to decide what to do without reference to look-ahead token.  */
2019   yyn = yypact[yystate];
2020   if (yyn == YYPACT_NINF)
2021     goto yydefault;
2022
2023   /* Not known => get a look-ahead token if don't already have one.  */
2024
2025   /* YYCHAR is either YYEMPTY or YYEOF or a valid look-ahead symbol.  */
2026   if (yychar == YYEMPTY)
2027     {
2028       YYDPRINTF ((stderr, "Reading a token: "));
2029       yychar = YYLEX;
2030     }
2031
2032   if (yychar <= YYEOF)
2033     {
2034       yychar = yytoken = YYEOF;
2035       YYDPRINTF ((stderr, "Now at end of input.\n"));
2036     }
2037   else
2038     {
2039       yytoken = YYTRANSLATE (yychar);
2040       YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
2041     }
2042
2043   /* If the proper action on seeing token YYTOKEN is to reduce or to
2044      detect an error, take that action.  */
2045   yyn += yytoken;
2046   if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
2047     goto yydefault;
2048   yyn = yytable[yyn];
2049   if (yyn <= 0)
2050     {
2051       if (yyn == 0 || yyn == YYTABLE_NINF)
2052         goto yyerrlab;
2053       yyn = -yyn;
2054       goto yyreduce;
2055     }
2056
2057   if (yyn == YYFINAL)
2058     YYACCEPT;
2059
2060   /* Count tokens shifted since error; after three, turn off error
2061      status.  */
2062   if (yyerrstatus)
2063     yyerrstatus--;
2064
2065   /* Shift the look-ahead token.  */
2066   YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
2067
2068   /* Discard the shifted token unless it is eof.  */
2069   if (yychar != YYEOF)
2070     yychar = YYEMPTY;
2071
2072   yystate = yyn;
2073   *++yyvsp = yylval;
2074
2075   goto yynewstate;
2076
2077
2078 /*-----------------------------------------------------------.
2079 | yydefault -- do the default action for the current state.  |
2080 `-----------------------------------------------------------*/
2081 yydefault:
2082   yyn = yydefact[yystate];
2083   if (yyn == 0)
2084     goto yyerrlab;
2085   goto yyreduce;
2086
2087
2088 /*-----------------------------.
2089 | yyreduce -- Do a reduction.  |
2090 `-----------------------------*/
2091 yyreduce:
2092   /* yyn is the number of a rule to reduce with.  */
2093   yylen = yyr2[yyn];
2094
2095   /* If YYLEN is nonzero, implement the default value of the action:
2096      `$$ = $1'.
2097
2098      Otherwise, the following line sets YYVAL to garbage.
2099      This behavior is undocumented and Bison
2100      users should not rely upon it.  Assigning to YYVAL
2101      unconditionally makes the parser a bit smaller, and it avoids a
2102      GCC warning that YYVAL may be used uninitialized.  */
2103   yyval = yyvsp[1-yylen];
2104
2105
2106   YY_REDUCE_PRINT (yyn);
2107   switch (yyn)
2108     {
2109         case 2:
2110 #line 374 "/Users/chet/src/bash/src/parse.y"
2111     {
2112                           /* Case of regular command.  Discard the error
2113                              safety net,and return the command just parsed. */
2114                           global_command = (yyvsp[(1) - (2)].command);
2115                           eof_encountered = 0;
2116                           /* discard_parser_constructs (0); */
2117                           if (parser_state & PST_CMDSUBST)
2118                             parser_state |= PST_EOFTOKEN;
2119                           YYACCEPT;
2120                         }
2121     break;
2122
2123   case 3:
2124 #line 385 "/Users/chet/src/bash/src/parse.y"
2125     {
2126                           /* Case of regular command, but not a very
2127                              interesting one.  Return a NULL command. */
2128                           global_command = (COMMAND *)NULL;
2129                           if (parser_state & PST_CMDSUBST)
2130                             parser_state |= PST_EOFTOKEN;
2131                           YYACCEPT;
2132                         }
2133     break;
2134
2135   case 4:
2136 #line 394 "/Users/chet/src/bash/src/parse.y"
2137     {
2138                           /* Error during parsing.  Return NULL command. */
2139                           global_command = (COMMAND *)NULL;
2140                           eof_encountered = 0;
2141                           /* discard_parser_constructs (1); */
2142                           if (interactive && parse_and_execute_level == 0)
2143                             {
2144                               YYACCEPT;
2145                             }
2146                           else
2147                             {
2148                               YYABORT;
2149                             }
2150                         }
2151     break;
2152
2153   case 5:
2154 #line 409 "/Users/chet/src/bash/src/parse.y"
2155     {
2156                           /* Case of EOF seen by itself.  Do ignoreeof or
2157                              not. */
2158                           global_command = (COMMAND *)NULL;
2159                           handle_eof_input_unit ();
2160                           YYACCEPT;
2161                         }
2162     break;
2163
2164   case 6:
2165 #line 419 "/Users/chet/src/bash/src/parse.y"
2166     { (yyval.word_list) = make_word_list ((yyvsp[(1) - (1)].word), (WORD_LIST *)NULL); }
2167     break;
2168
2169   case 7:
2170 #line 421 "/Users/chet/src/bash/src/parse.y"
2171     { (yyval.word_list) = make_word_list ((yyvsp[(2) - (2)].word), (yyvsp[(1) - (2)].word_list)); }
2172     break;
2173
2174   case 8:
2175 #line 425 "/Users/chet/src/bash/src/parse.y"
2176     {
2177                           source.dest = 1;
2178                           redir.filename = (yyvsp[(2) - (2)].word);
2179                           (yyval.redirect) = make_redirection (source, r_output_direction, redir, 0);
2180                         }
2181     break;
2182
2183   case 9:
2184 #line 431 "/Users/chet/src/bash/src/parse.y"
2185     {
2186                           source.dest = 0;
2187                           redir.filename = (yyvsp[(2) - (2)].word);
2188                           (yyval.redirect) = make_redirection (source, r_input_direction, redir, 0);
2189                         }
2190     break;
2191
2192   case 10:
2193 #line 437 "/Users/chet/src/bash/src/parse.y"
2194     {
2195                           source.dest = (yyvsp[(1) - (3)].number);
2196                           redir.filename = (yyvsp[(3) - (3)].word);
2197                           (yyval.redirect) = make_redirection (source, r_output_direction, redir, 0);
2198                         }
2199     break;
2200
2201   case 11:
2202 #line 443 "/Users/chet/src/bash/src/parse.y"
2203     {
2204                           source.dest = (yyvsp[(1) - (3)].number);
2205                           redir.filename = (yyvsp[(3) - (3)].word);
2206                           (yyval.redirect) = make_redirection (source, r_input_direction, redir, 0);
2207                         }
2208     break;
2209
2210   case 12:
2211 #line 449 "/Users/chet/src/bash/src/parse.y"
2212     {
2213                           source.filename = (yyvsp[(1) - (3)].word);
2214                           redir.filename = (yyvsp[(3) - (3)].word);
2215                           (yyval.redirect) = make_redirection (source, r_output_direction, redir, REDIR_VARASSIGN);
2216                         }
2217     break;
2218
2219   case 13:
2220 #line 455 "/Users/chet/src/bash/src/parse.y"
2221     {
2222                           source.filename = (yyvsp[(1) - (3)].word);
2223                           redir.filename = (yyvsp[(3) - (3)].word);
2224                           (yyval.redirect) = make_redirection (source, r_input_direction, redir, REDIR_VARASSIGN);
2225                         }
2226     break;
2227
2228   case 14:
2229 #line 461 "/Users/chet/src/bash/src/parse.y"
2230     {
2231                           source.dest = 1;
2232                           redir.filename = (yyvsp[(2) - (2)].word);
2233                           (yyval.redirect) = make_redirection (source, r_appending_to, redir, 0);
2234                         }
2235     break;
2236
2237   case 15:
2238 #line 467 "/Users/chet/src/bash/src/parse.y"
2239     {
2240                           source.dest = (yyvsp[(1) - (3)].number);
2241                           redir.filename = (yyvsp[(3) - (3)].word);
2242                           (yyval.redirect) = make_redirection (source, r_appending_to, redir, 0);
2243                         }
2244     break;
2245
2246   case 16:
2247 #line 473 "/Users/chet/src/bash/src/parse.y"
2248     {
2249                           source.filename = (yyvsp[(1) - (3)].word);
2250                           redir.filename = (yyvsp[(3) - (3)].word);
2251                           (yyval.redirect) = make_redirection (source, r_appending_to, redir, REDIR_VARASSIGN);
2252                         }
2253     break;
2254
2255   case 17:
2256 #line 479 "/Users/chet/src/bash/src/parse.y"
2257     {
2258                           source.dest = 1;
2259                           redir.filename = (yyvsp[(2) - (2)].word);
2260                           (yyval.redirect) = make_redirection (source, r_output_force, redir, 0);
2261                         }
2262     break;
2263
2264   case 18:
2265 #line 485 "/Users/chet/src/bash/src/parse.y"
2266     {
2267                           source.dest = (yyvsp[(1) - (3)].number);
2268                           redir.filename = (yyvsp[(3) - (3)].word);
2269                           (yyval.redirect) = make_redirection (source, r_output_force, redir, 0);
2270                         }
2271     break;
2272
2273   case 19:
2274 #line 491 "/Users/chet/src/bash/src/parse.y"
2275     {
2276                           source.filename = (yyvsp[(1) - (3)].word);
2277                           redir.filename = (yyvsp[(3) - (3)].word);
2278                           (yyval.redirect) = make_redirection (source, r_output_force, redir, REDIR_VARASSIGN);
2279                         }
2280     break;
2281
2282   case 20:
2283 #line 497 "/Users/chet/src/bash/src/parse.y"
2284     {
2285                           source.dest = 0;
2286                           redir.filename = (yyvsp[(2) - (2)].word);
2287                           (yyval.redirect) = make_redirection (source, r_input_output, redir, 0);
2288                         }
2289     break;
2290
2291   case 21:
2292 #line 503 "/Users/chet/src/bash/src/parse.y"
2293     {
2294                           source.dest = (yyvsp[(1) - (3)].number);
2295                           redir.filename = (yyvsp[(3) - (3)].word);
2296                           (yyval.redirect) = make_redirection (source, r_input_output, redir, 0);
2297                         }
2298     break;
2299
2300   case 22:
2301 #line 509 "/Users/chet/src/bash/src/parse.y"
2302     {
2303                           source.filename = (yyvsp[(1) - (3)].word);
2304                           redir.filename = (yyvsp[(3) - (3)].word);
2305                           (yyval.redirect) = make_redirection (source, r_input_output, redir, REDIR_VARASSIGN);
2306                         }
2307     break;
2308
2309   case 23:
2310 #line 515 "/Users/chet/src/bash/src/parse.y"
2311     {
2312                           source.dest = 0;
2313                           redir.filename = (yyvsp[(2) - (2)].word);
2314                           (yyval.redirect) = make_redirection (source, r_reading_until, redir, 0);
2315                           redir_stack[need_here_doc++] = (yyval.redirect);
2316                         }
2317     break;
2318
2319   case 24:
2320 #line 522 "/Users/chet/src/bash/src/parse.y"
2321     {
2322                           source.dest = (yyvsp[(1) - (3)].number);
2323                           redir.filename = (yyvsp[(3) - (3)].word);
2324                           (yyval.redirect) = make_redirection (source, r_reading_until, redir, 0);
2325                           redir_stack[need_here_doc++] = (yyval.redirect);
2326                         }
2327     break;
2328
2329   case 25:
2330 #line 529 "/Users/chet/src/bash/src/parse.y"
2331     {
2332                           source.filename = (yyvsp[(1) - (3)].word);
2333                           redir.filename = (yyvsp[(3) - (3)].word);
2334                           (yyval.redirect) = make_redirection (source, r_reading_until, redir, REDIR_VARASSIGN);
2335                           redir_stack[need_here_doc++] = (yyval.redirect);
2336                         }
2337     break;
2338
2339   case 26:
2340 #line 536 "/Users/chet/src/bash/src/parse.y"
2341     {
2342                           source.dest = 0;
2343                           redir.filename = (yyvsp[(2) - (2)].word);
2344                           (yyval.redirect) = make_redirection (source, r_deblank_reading_until, redir, 0);
2345                           redir_stack[need_here_doc++] = (yyval.redirect);
2346                         }
2347     break;
2348
2349   case 27:
2350 #line 543 "/Users/chet/src/bash/src/parse.y"
2351     {
2352                           source.dest = (yyvsp[(1) - (3)].number);
2353                           redir.filename = (yyvsp[(3) - (3)].word);
2354                           (yyval.redirect) = make_redirection (source, r_deblank_reading_until, redir, 0);
2355                           redir_stack[need_here_doc++] = (yyval.redirect);
2356                         }
2357     break;
2358
2359   case 28:
2360 #line 550 "/Users/chet/src/bash/src/parse.y"
2361     {
2362                           source.filename = (yyvsp[(1) - (3)].word);
2363                           redir.filename = (yyvsp[(3) - (3)].word);
2364                           (yyval.redirect) = make_redirection (source, r_deblank_reading_until, redir, REDIR_VARASSIGN);
2365                           redir_stack[need_here_doc++] = (yyval.redirect);
2366                         }
2367     break;
2368
2369   case 29:
2370 #line 557 "/Users/chet/src/bash/src/parse.y"
2371     {
2372                           source.dest = 0;
2373                           redir.filename = (yyvsp[(2) - (2)].word);
2374                           (yyval.redirect) = make_redirection (source, r_reading_string, redir, 0);
2375                         }
2376     break;
2377
2378   case 30:
2379 #line 563 "/Users/chet/src/bash/src/parse.y"
2380     {
2381                           source.dest = (yyvsp[(1) - (3)].number);
2382                           redir.filename = (yyvsp[(3) - (3)].word);
2383                           (yyval.redirect) = make_redirection (source, r_reading_string, redir, 0);
2384                         }
2385     break;
2386
2387   case 31:
2388 #line 569 "/Users/chet/src/bash/src/parse.y"
2389     {
2390                           source.filename = (yyvsp[(1) - (3)].word);
2391                           redir.filename = (yyvsp[(3) - (3)].word);
2392                           (yyval.redirect) = make_redirection (source, r_reading_string, redir, REDIR_VARASSIGN);
2393                         }
2394     break;
2395
2396   case 32:
2397 #line 575 "/Users/chet/src/bash/src/parse.y"
2398     {
2399                           source.dest = 0;
2400                           redir.dest = (yyvsp[(2) - (2)].number);
2401                           (yyval.redirect) = make_redirection (source, r_duplicating_input, redir, 0);
2402                         }
2403     break;
2404
2405   case 33:
2406 #line 581 "/Users/chet/src/bash/src/parse.y"
2407     {
2408                           source.dest = (yyvsp[(1) - (3)].number);
2409                           redir.dest = (yyvsp[(3) - (3)].number);
2410                           (yyval.redirect) = make_redirection (source, r_duplicating_input, redir, 0);
2411                         }
2412     break;
2413
2414   case 34:
2415 #line 587 "/Users/chet/src/bash/src/parse.y"
2416     {
2417                           source.filename = (yyvsp[(1) - (3)].word);
2418                           redir.dest = (yyvsp[(3) - (3)].number);
2419                           (yyval.redirect) = make_redirection (source, r_duplicating_input, redir, REDIR_VARASSIGN);
2420                         }
2421     break;
2422
2423   case 35:
2424 #line 593 "/Users/chet/src/bash/src/parse.y"
2425     {
2426                           source.dest = 1;
2427                           redir.dest = (yyvsp[(2) - (2)].number);
2428                           (yyval.redirect) = make_redirection (source, r_duplicating_output, redir, 0);
2429                         }
2430     break;
2431
2432   case 36:
2433 #line 599 "/Users/chet/src/bash/src/parse.y"
2434     {
2435                           source.dest = (yyvsp[(1) - (3)].number);
2436                           redir.dest = (yyvsp[(3) - (3)].number);
2437                           (yyval.redirect) = make_redirection (source, r_duplicating_output, redir, 0);
2438                         }
2439     break;
2440
2441   case 37:
2442 #line 605 "/Users/chet/src/bash/src/parse.y"
2443     {
2444                           source.filename = (yyvsp[(1) - (3)].word);
2445                           redir.dest = (yyvsp[(3) - (3)].number);
2446                           (yyval.redirect) = make_redirection (source, r_duplicating_output, redir, REDIR_VARASSIGN);
2447                         }
2448     break;
2449
2450   case 38:
2451 #line 611 "/Users/chet/src/bash/src/parse.y"
2452     {
2453                           source.dest = 0;
2454                           redir.filename = (yyvsp[(2) - (2)].word);
2455                           (yyval.redirect) = make_redirection (source, r_duplicating_input_word, redir, 0);
2456                         }
2457     break;
2458
2459   case 39:
2460 #line 617 "/Users/chet/src/bash/src/parse.y"
2461     {
2462                           source.dest = (yyvsp[(1) - (3)].number);
2463                           redir.filename = (yyvsp[(3) - (3)].word);
2464                           (yyval.redirect) = make_redirection (source, r_duplicating_input_word, redir, 0);
2465                         }
2466     break;
2467
2468   case 40:
2469 #line 623 "/Users/chet/src/bash/src/parse.y"
2470     {
2471                           source.filename = (yyvsp[(1) - (3)].word);
2472                           redir.filename = (yyvsp[(3) - (3)].word);
2473                           (yyval.redirect) = make_redirection (source, r_duplicating_input_word, redir, REDIR_VARASSIGN);
2474                         }
2475     break;
2476
2477   case 41:
2478 #line 629 "/Users/chet/src/bash/src/parse.y"
2479     {
2480                           source.dest = 1;
2481                           redir.filename = (yyvsp[(2) - (2)].word);
2482                           (yyval.redirect) = make_redirection (source, r_duplicating_output_word, redir, 0);
2483                         }
2484     break;
2485
2486   case 42:
2487 #line 635 "/Users/chet/src/bash/src/parse.y"
2488     {
2489                           source.dest = (yyvsp[(1) - (3)].number);
2490                           redir.filename = (yyvsp[(3) - (3)].word);
2491                           (yyval.redirect) = make_redirection (source, r_duplicating_output_word, redir, 0);
2492                         }
2493     break;
2494
2495   case 43:
2496 #line 641 "/Users/chet/src/bash/src/parse.y"
2497     {
2498                           source.filename = (yyvsp[(1) - (3)].word);
2499                           redir.filename = (yyvsp[(3) - (3)].word);
2500                           (yyval.redirect) = make_redirection (source, r_duplicating_output_word, redir, REDIR_VARASSIGN);
2501                         }
2502     break;
2503
2504   case 44:
2505 #line 647 "/Users/chet/src/bash/src/parse.y"
2506     {
2507                           source.dest = 1;
2508                           redir.dest = 0;
2509                           (yyval.redirect) = make_redirection (source, r_close_this, redir, 0);
2510                         }
2511     break;
2512
2513   case 45:
2514 #line 653 "/Users/chet/src/bash/src/parse.y"
2515     {
2516                           source.dest = (yyvsp[(1) - (3)].number);
2517                           redir.dest = 0;
2518                           (yyval.redirect) = make_redirection (source, r_close_this, redir, 0);
2519                         }
2520     break;
2521
2522   case 46:
2523 #line 659 "/Users/chet/src/bash/src/parse.y"
2524     {
2525                           source.filename = (yyvsp[(1) - (3)].word);
2526                           redir.dest = 0;
2527                           (yyval.redirect) = make_redirection (source, r_close_this, redir, REDIR_VARASSIGN);
2528                         }
2529     break;
2530
2531   case 47:
2532 #line 665 "/Users/chet/src/bash/src/parse.y"
2533     {
2534                           source.dest = 0;
2535                           redir.dest = 0;
2536                           (yyval.redirect) = make_redirection (source, r_close_this, redir, 0);
2537                         }
2538     break;
2539
2540   case 48:
2541 #line 671 "/Users/chet/src/bash/src/parse.y"
2542     {
2543                           source.dest = (yyvsp[(1) - (3)].number);
2544                           redir.dest = 0;
2545                           (yyval.redirect) = make_redirection (source, r_close_this, redir, 0);
2546                         }
2547     break;
2548
2549   case 49:
2550 #line 677 "/Users/chet/src/bash/src/parse.y"
2551     {
2552                           source.filename = (yyvsp[(1) - (3)].word);
2553                           redir.dest = 0;
2554                           (yyval.redirect) = make_redirection (source, r_close_this, redir, REDIR_VARASSIGN);
2555                         }
2556     break;
2557
2558   case 50:
2559 #line 683 "/Users/chet/src/bash/src/parse.y"
2560     {
2561                           source.dest = 1;
2562                           redir.filename = (yyvsp[(2) - (2)].word);
2563                           (yyval.redirect) = make_redirection (source, r_err_and_out, redir, 0);
2564                         }
2565     break;
2566
2567   case 51:
2568 #line 689 "/Users/chet/src/bash/src/parse.y"
2569     {
2570                           source.dest = 1;
2571                           redir.filename = (yyvsp[(2) - (2)].word);
2572                           (yyval.redirect) = make_redirection (source, r_append_err_and_out, redir, 0);
2573                         }
2574     break;
2575
2576   case 52:
2577 #line 697 "/Users/chet/src/bash/src/parse.y"
2578     { (yyval.element).word = (yyvsp[(1) - (1)].word); (yyval.element).redirect = 0; }
2579     break;
2580
2581   case 53:
2582 #line 699 "/Users/chet/src/bash/src/parse.y"
2583     { (yyval.element).word = (yyvsp[(1) - (1)].word); (yyval.element).redirect = 0; }
2584     break;
2585
2586   case 54:
2587 #line 701 "/Users/chet/src/bash/src/parse.y"
2588     { (yyval.element).redirect = (yyvsp[(1) - (1)].redirect); (yyval.element).word = 0; }
2589     break;
2590
2591   case 55:
2592 #line 705 "/Users/chet/src/bash/src/parse.y"
2593     {
2594                           (yyval.redirect) = (yyvsp[(1) - (1)].redirect);
2595                         }
2596     break;
2597
2598   case 56:
2599 #line 709 "/Users/chet/src/bash/src/parse.y"
2600     {
2601                           register REDIRECT *t;
2602
2603                           for (t = (yyvsp[(1) - (2)].redirect); t->next; t = t->next)
2604                             ;
2605                           t->next = (yyvsp[(2) - (2)].redirect);
2606                           (yyval.redirect) = (yyvsp[(1) - (2)].redirect);
2607                         }
2608     break;
2609
2610   case 57:
2611 #line 720 "/Users/chet/src/bash/src/parse.y"
2612     { (yyval.command) = make_simple_command ((yyvsp[(1) - (1)].element), (COMMAND *)NULL); }
2613     break;
2614
2615   case 58:
2616 #line 722 "/Users/chet/src/bash/src/parse.y"
2617     { (yyval.command) = make_simple_command ((yyvsp[(2) - (2)].element), (yyvsp[(1) - (2)].command)); }
2618     break;
2619
2620   case 59:
2621 #line 726 "/Users/chet/src/bash/src/parse.y"
2622     { (yyval.command) = clean_simple_command ((yyvsp[(1) - (1)].command)); }
2623     break;
2624
2625   case 60:
2626 #line 728 "/Users/chet/src/bash/src/parse.y"
2627     { (yyval.command) = (yyvsp[(1) - (1)].command); }
2628     break;
2629
2630   case 61:
2631 #line 730 "/Users/chet/src/bash/src/parse.y"
2632     {
2633                           COMMAND *tc;
2634
2635                           tc = (yyvsp[(1) - (2)].command);
2636                           if (tc->redirects)
2637                             {
2638                               register REDIRECT *t;
2639                               for (t = tc->redirects; t->next; t = t->next)
2640                                 ;
2641                               t->next = (yyvsp[(2) - (2)].redirect);
2642                             }
2643                           else
2644                             tc->redirects = (yyvsp[(2) - (2)].redirect);
2645                           (yyval.command) = (yyvsp[(1) - (2)].command);
2646                         }
2647     break;
2648
2649   case 62:
2650 #line 746 "/Users/chet/src/bash/src/parse.y"
2651     { (yyval.command) = (yyvsp[(1) - (1)].command); }
2652     break;
2653
2654   case 63:
2655 #line 748 "/Users/chet/src/bash/src/parse.y"
2656     { (yyval.command) = (yyvsp[(1) - (1)].command); }
2657     break;
2658
2659   case 64:
2660 #line 752 "/Users/chet/src/bash/src/parse.y"
2661     { (yyval.command) = (yyvsp[(1) - (1)].command); }
2662     break;
2663
2664   case 65:
2665 #line 754 "/Users/chet/src/bash/src/parse.y"
2666     { (yyval.command) = (yyvsp[(1) - (1)].command); }
2667     break;
2668
2669   case 66:
2670 #line 756 "/Users/chet/src/bash/src/parse.y"
2671     { (yyval.command) = make_while_command ((yyvsp[(2) - (5)].command), (yyvsp[(4) - (5)].command)); }
2672     break;
2673
2674   case 67:
2675 #line 758 "/Users/chet/src/bash/src/parse.y"
2676     { (yyval.command) = make_until_command ((yyvsp[(2) - (5)].command), (yyvsp[(4) - (5)].command)); }
2677     break;
2678
2679   case 68:
2680 #line 760 "/Users/chet/src/bash/src/parse.y"
2681     { (yyval.command) = (yyvsp[(1) - (1)].command); }
2682     break;
2683
2684   case 69:
2685 #line 762 "/Users/chet/src/bash/src/parse.y"
2686     { (yyval.command) = (yyvsp[(1) - (1)].command); }
2687     break;
2688
2689   case 70:
2690 #line 764 "/Users/chet/src/bash/src/parse.y"
2691     { (yyval.command) = (yyvsp[(1) - (1)].command); }
2692     break;
2693
2694   case 71:
2695 #line 766 "/Users/chet/src/bash/src/parse.y"
2696     { (yyval.command) = (yyvsp[(1) - (1)].command); }
2697     break;
2698
2699   case 72:
2700 #line 768 "/Users/chet/src/bash/src/parse.y"
2701     { (yyval.command) = (yyvsp[(1) - (1)].command); }
2702     break;
2703
2704   case 73:
2705 #line 770 "/Users/chet/src/bash/src/parse.y"
2706     { (yyval.command) = (yyvsp[(1) - (1)].command); }
2707     break;
2708
2709   case 74:
2710 #line 772 "/Users/chet/src/bash/src/parse.y"
2711     { (yyval.command) = (yyvsp[(1) - (1)].command); }
2712     break;
2713
2714   case 75:
2715 #line 776 "/Users/chet/src/bash/src/parse.y"
2716     {
2717                           (yyval.command) = make_for_command ((yyvsp[(2) - (6)].word), add_string_to_list ("\"$@\"", (WORD_LIST *)NULL), (yyvsp[(5) - (6)].command), word_lineno[word_top]);
2718                           if (word_top > 0) word_top--;
2719                         }
2720     break;
2721
2722   case 76:
2723 #line 781 "/Users/chet/src/bash/src/parse.y"
2724     {
2725                           (yyval.command) = make_for_command ((yyvsp[(2) - (6)].word), add_string_to_list ("\"$@\"", (WORD_LIST *)NULL), (yyvsp[(5) - (6)].command), word_lineno[word_top]);
2726                           if (word_top > 0) word_top--;
2727                         }
2728     break;
2729
2730   case 77:
2731 #line 786 "/Users/chet/src/bash/src/parse.y"
2732     {
2733                           (yyval.command) = make_for_command ((yyvsp[(2) - (7)].word), add_string_to_list ("\"$@\"", (WORD_LIST *)NULL), (yyvsp[(6) - (7)].command), word_lineno[word_top]);
2734                           if (word_top > 0) word_top--;
2735                         }
2736     break;
2737
2738   case 78:
2739 #line 791 "/Users/chet/src/bash/src/parse.y"
2740     {
2741                           (yyval.command) = make_for_command ((yyvsp[(2) - (7)].word), add_string_to_list ("\"$@\"", (WORD_LIST *)NULL), (yyvsp[(6) - (7)].command), word_lineno[word_top]);
2742                           if (word_top > 0) word_top--;
2743                         }
2744     break;
2745
2746   case 79:
2747 #line 796 "/Users/chet/src/bash/src/parse.y"
2748     {
2749                           (yyval.command) = make_for_command ((yyvsp[(2) - (10)].word), REVERSE_LIST ((yyvsp[(5) - (10)].word_list), WORD_LIST *), (yyvsp[(9) - (10)].command), word_lineno[word_top]);
2750                           if (word_top > 0) word_top--;
2751                         }
2752     break;
2753
2754   case 80:
2755 #line 801 "/Users/chet/src/bash/src/parse.y"
2756     {
2757                           (yyval.command) = make_for_command ((yyvsp[(2) - (10)].word), REVERSE_LIST ((yyvsp[(5) - (10)].word_list), WORD_LIST *), (yyvsp[(9) - (10)].command), word_lineno[word_top]);
2758                           if (word_top > 0) word_top--;
2759                         }
2760     break;
2761
2762   case 81:
2763 #line 806 "/Users/chet/src/bash/src/parse.y"
2764     {
2765                           (yyval.command) = make_for_command ((yyvsp[(2) - (9)].word), (WORD_LIST *)NULL, (yyvsp[(8) - (9)].command), word_lineno[word_top]);
2766                           if (word_top > 0) word_top--;
2767                         }
2768     break;
2769
2770   case 82:
2771 #line 811 "/Users/chet/src/bash/src/parse.y"
2772     {
2773                           (yyval.command) = make_for_command ((yyvsp[(2) - (9)].word), (WORD_LIST *)NULL, (yyvsp[(8) - (9)].command), word_lineno[word_top]);
2774                           if (word_top > 0) word_top--;
2775                         }
2776     break;
2777
2778   case 83:
2779 #line 818 "/Users/chet/src/bash/src/parse.y"
2780     {
2781                                   (yyval.command) = make_arith_for_command ((yyvsp[(2) - (7)].word_list), (yyvsp[(6) - (7)].command), arith_for_lineno);
2782                                   if (word_top > 0) word_top--;
2783                                 }
2784     break;
2785
2786   case 84:
2787 #line 823 "/Users/chet/src/bash/src/parse.y"
2788     {
2789                                   (yyval.command) = make_arith_for_command ((yyvsp[(2) - (7)].word_list), (yyvsp[(6) - (7)].command), arith_for_lineno);
2790                                   if (word_top > 0) word_top--;
2791                                 }
2792     break;
2793
2794   case 85:
2795 #line 828 "/Users/chet/src/bash/src/parse.y"
2796     {
2797                                   (yyval.command) = make_arith_for_command ((yyvsp[(2) - (5)].word_list), (yyvsp[(4) - (5)].command), arith_for_lineno);
2798                                   if (word_top > 0) word_top--;
2799                                 }
2800     break;
2801
2802   case 86:
2803 #line 833 "/Users/chet/src/bash/src/parse.y"
2804     {
2805                                   (yyval.command) = make_arith_for_command ((yyvsp[(2) - (5)].word_list), (yyvsp[(4) - (5)].command), arith_for_lineno);
2806                                   if (word_top > 0) word_top--;
2807                                 }
2808     break;
2809
2810   case 87:
2811 #line 840 "/Users/chet/src/bash/src/parse.y"
2812     {
2813                           (yyval.command) = make_select_command ((yyvsp[(2) - (6)].word), add_string_to_list ("\"$@\"", (WORD_LIST *)NULL), (yyvsp[(5) - (6)].command), word_lineno[word_top]);
2814                           if (word_top > 0) word_top--;
2815                         }
2816     break;
2817
2818   case 88:
2819 #line 845 "/Users/chet/src/bash/src/parse.y"
2820     {
2821                           (yyval.command) = make_select_command ((yyvsp[(2) - (6)].word), add_string_to_list ("\"$@\"", (WORD_LIST *)NULL), (yyvsp[(5) - (6)].command), word_lineno[word_top]);
2822                           if (word_top > 0) word_top--;
2823                         }
2824     break;
2825
2826   case 89:
2827 #line 850 "/Users/chet/src/bash/src/parse.y"
2828     {
2829                           (yyval.command) = make_select_command ((yyvsp[(2) - (7)].word), add_string_to_list ("\"$@\"", (WORD_LIST *)NULL), (yyvsp[(6) - (7)].command), word_lineno[word_top]);
2830                           if (word_top > 0) word_top--;
2831                         }
2832     break;
2833
2834   case 90:
2835 #line 855 "/Users/chet/src/bash/src/parse.y"
2836     {
2837                           (yyval.command) = make_select_command ((yyvsp[(2) - (7)].word), add_string_to_list ("\"$@\"", (WORD_LIST *)NULL), (yyvsp[(6) - (7)].command), word_lineno[word_top]);
2838                           if (word_top > 0) word_top--;
2839                         }
2840     break;
2841
2842   case 91:
2843 #line 860 "/Users/chet/src/bash/src/parse.y"
2844     {
2845                           (yyval.command) = make_select_command ((yyvsp[(2) - (10)].word), REVERSE_LIST ((yyvsp[(5) - (10)].word_list), WORD_LIST *), (yyvsp[(9) - (10)].command), word_lineno[word_top]);
2846                           if (word_top > 0) word_top--;
2847                         }
2848     break;
2849
2850   case 92:
2851 #line 865 "/Users/chet/src/bash/src/parse.y"
2852     {
2853                           (yyval.command) = make_select_command ((yyvsp[(2) - (10)].word), REVERSE_LIST ((yyvsp[(5) - (10)].word_list), WORD_LIST *), (yyvsp[(9) - (10)].command), word_lineno[word_top]);
2854                           if (word_top > 0) word_top--;
2855                         }
2856     break;
2857
2858   case 93:
2859 #line 872 "/Users/chet/src/bash/src/parse.y"
2860     {
2861                           (yyval.command) = make_case_command ((yyvsp[(2) - (6)].word), (PATTERN_LIST *)NULL, word_lineno[word_top]);
2862                           if (word_top > 0) word_top--;
2863                         }
2864     break;
2865
2866   case 94:
2867 #line 877 "/Users/chet/src/bash/src/parse.y"
2868     {
2869                           (yyval.command) = make_case_command ((yyvsp[(2) - (7)].word), (yyvsp[(5) - (7)].pattern), word_lineno[word_top]);
2870                           if (word_top > 0) word_top--;
2871                         }
2872     break;
2873
2874   case 95:
2875 #line 882 "/Users/chet/src/bash/src/parse.y"
2876     {
2877                           (yyval.command) = make_case_command ((yyvsp[(2) - (6)].word), (yyvsp[(5) - (6)].pattern), word_lineno[word_top]);
2878                           if (word_top > 0) word_top--;
2879                         }
2880     break;
2881
2882   case 96:
2883 #line 889 "/Users/chet/src/bash/src/parse.y"
2884     { (yyval.command) = make_function_def ((yyvsp[(1) - (5)].word), (yyvsp[(5) - (5)].command), function_dstart, function_bstart); }
2885     break;
2886
2887   case 97:
2888 #line 892 "/Users/chet/src/bash/src/parse.y"
2889     { (yyval.command) = make_function_def ((yyvsp[(2) - (6)].word), (yyvsp[(6) - (6)].command), function_dstart, function_bstart); }
2890     break;
2891
2892   case 98:
2893 #line 895 "/Users/chet/src/bash/src/parse.y"
2894     { (yyval.command) = make_function_def ((yyvsp[(2) - (4)].word), (yyvsp[(4) - (4)].command), function_dstart, function_bstart); }
2895     break;
2896
2897   case 99:
2898 #line 899 "/Users/chet/src/bash/src/parse.y"
2899     { (yyval.command) = (yyvsp[(1) - (1)].command); }
2900     break;
2901
2902   case 100:
2903 #line 901 "/Users/chet/src/bash/src/parse.y"
2904     {
2905                           COMMAND *tc;
2906
2907                           tc = (yyvsp[(1) - (2)].command);
2908                           /* According to Posix.2 3.9.5, redirections
2909                              specified after the body of a function should
2910                              be attached to the function and performed when
2911                              the function is executed, not as part of the
2912                              function definition command. */
2913                           /* XXX - I don't think it matters, but we might
2914                              want to change this in the future to avoid
2915                              problems differentiating between a function
2916                              definition with a redirection and a function
2917                              definition containing a single command with a
2918                              redirection.  The two are semantically equivalent,
2919                              though -- the only difference is in how the
2920                              command printing code displays the redirections. */
2921                           if (tc->redirects)
2922                             {
2923                               register REDIRECT *t;
2924                               for (t = tc->redirects; t->next; t = t->next)
2925                                 ;
2926                               t->next = (yyvsp[(2) - (2)].redirect);
2927                             }
2928                           else
2929                             tc->redirects = (yyvsp[(2) - (2)].redirect);
2930                           (yyval.command) = (yyvsp[(1) - (2)].command);
2931                         }
2932     break;
2933
2934   case 101:
2935 #line 932 "/Users/chet/src/bash/src/parse.y"
2936     {
2937                           (yyval.command) = make_subshell_command ((yyvsp[(2) - (3)].command));
2938                           (yyval.command)->flags |= CMD_WANT_SUBSHELL;
2939                         }
2940     break;
2941
2942   case 102:
2943 #line 939 "/Users/chet/src/bash/src/parse.y"
2944     {
2945                           (yyval.command) = make_coproc_command ("COPROC", (yyvsp[(2) - (2)].command));
2946                           (yyval.command)->flags |= CMD_WANT_SUBSHELL|CMD_COPROC_SUBSHELL;
2947                         }
2948     break;
2949
2950   case 103:
2951 #line 944 "/Users/chet/src/bash/src/parse.y"
2952     {
2953                           COMMAND *tc;
2954
2955                           tc = (yyvsp[(2) - (3)].command);
2956                           if (tc->redirects)
2957                             {
2958                               register REDIRECT *t;
2959                               for (t = tc->redirects; t->next; t = t->next)
2960                                 ;
2961                               t->next = (yyvsp[(3) - (3)].redirect);
2962                             }
2963                           else
2964                             tc->redirects = (yyvsp[(3) - (3)].redirect);
2965                           (yyval.command) = make_coproc_command ("COPROC", (yyvsp[(2) - (3)].command));
2966                           (yyval.command)->flags |= CMD_WANT_SUBSHELL|CMD_COPROC_SUBSHELL;
2967                         }
2968     break;
2969
2970   case 104:
2971 #line 961 "/Users/chet/src/bash/src/parse.y"
2972     {
2973                           (yyval.command) = make_coproc_command ((yyvsp[(2) - (3)].word)->word, (yyvsp[(3) - (3)].command));
2974                           (yyval.command)->flags |= CMD_WANT_SUBSHELL|CMD_COPROC_SUBSHELL;
2975                         }
2976     break;
2977
2978   case 105:
2979 #line 966 "/Users/chet/src/bash/src/parse.y"
2980     {
2981                           COMMAND *tc;
2982
2983                           tc = (yyvsp[(3) - (4)].command);
2984                           if (tc->redirects)
2985                             {
2986                               register REDIRECT *t;
2987                               for (t = tc->redirects; t->next; t = t->next)
2988                                 ;
2989                               t->next = (yyvsp[(4) - (4)].redirect);
2990                             }
2991                           else
2992                             tc->redirects = (yyvsp[(4) - (4)].redirect);
2993                           (yyval.command) = make_coproc_command ((yyvsp[(2) - (4)].word)->word, (yyvsp[(3) - (4)].command));
2994                           (yyval.command)->flags |= CMD_WANT_SUBSHELL|CMD_COPROC_SUBSHELL;
2995                         }
2996     break;
2997
2998   case 106:
2999 #line 983 "/Users/chet/src/bash/src/parse.y"
3000     {
3001                           (yyval.command) = make_coproc_command ("COPROC", clean_simple_command ((yyvsp[(2) - (2)].command)));
3002                           (yyval.command)->flags |= CMD_WANT_SUBSHELL|CMD_COPROC_SUBSHELL;
3003                         }
3004     break;
3005
3006   case 107:
3007 #line 990 "/Users/chet/src/bash/src/parse.y"
3008     { (yyval.command) = make_if_command ((yyvsp[(2) - (5)].command), (yyvsp[(4) - (5)].command), (COMMAND *)NULL); }
3009     break;
3010
3011   case 108:
3012 #line 992 "/Users/chet/src/bash/src/parse.y"
3013     { (yyval.command) = make_if_command ((yyvsp[(2) - (7)].command), (yyvsp[(4) - (7)].command), (yyvsp[(6) - (7)].command)); }
3014     break;
3015
3016   case 109:
3017 #line 994 "/Users/chet/src/bash/src/parse.y"
3018     { (yyval.command) = make_if_command ((yyvsp[(2) - (6)].command), (yyvsp[(4) - (6)].command), (yyvsp[(5) - (6)].command)); }
3019     break;
3020
3021   case 110:
3022 #line 999 "/Users/chet/src/bash/src/parse.y"
3023     { (yyval.command) = make_group_command ((yyvsp[(2) - (3)].command)); }
3024     break;
3025
3026   case 111:
3027 #line 1003 "/Users/chet/src/bash/src/parse.y"
3028     { (yyval.command) = make_arith_command ((yyvsp[(1) - (1)].word_list)); }
3029     break;
3030
3031   case 112:
3032 #line 1007 "/Users/chet/src/bash/src/parse.y"
3033     { (yyval.command) = (yyvsp[(2) - (3)].command); }
3034     break;
3035
3036   case 113:
3037 #line 1011 "/Users/chet/src/bash/src/parse.y"
3038     { (yyval.command) = make_if_command ((yyvsp[(2) - (4)].command), (yyvsp[(4) - (4)].command), (COMMAND *)NULL); }
3039     break;
3040
3041   case 114:
3042 #line 1013 "/Users/chet/src/bash/src/parse.y"
3043     { (yyval.command) = make_if_command ((yyvsp[(2) - (6)].command), (yyvsp[(4) - (6)].command), (yyvsp[(6) - (6)].command)); }
3044     break;
3045
3046   case 115:
3047 #line 1015 "/Users/chet/src/bash/src/parse.y"
3048     { (yyval.command) = make_if_command ((yyvsp[(2) - (5)].command), (yyvsp[(4) - (5)].command), (yyvsp[(5) - (5)].command)); }
3049     break;
3050
3051   case 117:
3052 #line 1020 "/Users/chet/src/bash/src/parse.y"
3053     { (yyvsp[(2) - (2)].pattern)->next = (yyvsp[(1) - (2)].pattern); (yyval.pattern) = (yyvsp[(2) - (2)].pattern); }
3054     break;
3055
3056   case 118:
3057 #line 1024 "/Users/chet/src/bash/src/parse.y"
3058     { (yyval.pattern) = make_pattern_list ((yyvsp[(2) - (4)].word_list), (yyvsp[(4) - (4)].command)); }
3059     break;
3060
3061   case 119:
3062 #line 1026 "/Users/chet/src/bash/src/parse.y"
3063     { (yyval.pattern) = make_pattern_list ((yyvsp[(2) - (4)].word_list), (COMMAND *)NULL); }
3064     break;
3065
3066   case 120:
3067 #line 1028 "/Users/chet/src/bash/src/parse.y"
3068     { (yyval.pattern) = make_pattern_list ((yyvsp[(3) - (5)].word_list), (yyvsp[(5) - (5)].command)); }
3069     break;
3070
3071   case 121:
3072 #line 1030 "/Users/chet/src/bash/src/parse.y"
3073     { (yyval.pattern) = make_pattern_list ((yyvsp[(3) - (5)].word_list), (COMMAND *)NULL); }
3074     break;
3075
3076   case 122:
3077 #line 1034 "/Users/chet/src/bash/src/parse.y"
3078     { (yyval.pattern) = (yyvsp[(1) - (2)].pattern); }
3079     break;
3080
3081   case 123:
3082 #line 1036 "/Users/chet/src/bash/src/parse.y"
3083     { (yyvsp[(2) - (3)].pattern)->next = (yyvsp[(1) - (3)].pattern); (yyval.pattern) = (yyvsp[(2) - (3)].pattern); }
3084     break;
3085
3086   case 124:
3087 #line 1038 "/Users/chet/src/bash/src/parse.y"
3088     { (yyvsp[(1) - (2)].pattern)->flags |= CASEPAT_FALLTHROUGH; (yyval.pattern) = (yyvsp[(1) - (2)].pattern); }
3089     break;
3090
3091   case 125:
3092 #line 1040 "/Users/chet/src/bash/src/parse.y"
3093     { (yyvsp[(2) - (3)].pattern)->flags |= CASEPAT_FALLTHROUGH; (yyvsp[(2) - (3)].pattern)->next = (yyvsp[(1) - (3)].pattern); (yyval.pattern) = (yyvsp[(2) - (3)].pattern); }
3094     break;
3095
3096   case 126:
3097 #line 1042 "/Users/chet/src/bash/src/parse.y"
3098     { (yyvsp[(1) - (2)].pattern)->flags |= CASEPAT_TESTNEXT; (yyval.pattern) = (yyvsp[(1) - (2)].pattern); }
3099     break;
3100
3101   case 127:
3102 #line 1044 "/Users/chet/src/bash/src/parse.y"
3103     { (yyvsp[(2) - (3)].pattern)->flags |= CASEPAT_TESTNEXT; (yyvsp[(2) - (3)].pattern)->next = (yyvsp[(1) - (3)].pattern); (yyval.pattern) = (yyvsp[(2) - (3)].pattern); }
3104     break;
3105
3106   case 128:
3107 #line 1048 "/Users/chet/src/bash/src/parse.y"
3108     { (yyval.word_list) = make_word_list ((yyvsp[(1) - (1)].word), (WORD_LIST *)NULL); }
3109     break;
3110
3111   case 129:
3112 #line 1050 "/Users/chet/src/bash/src/parse.y"
3113     { (yyval.word_list) = make_word_list ((yyvsp[(3) - (3)].word), (yyvsp[(1) - (3)].word_list)); }
3114     break;
3115
3116   case 130:
3117 #line 1059 "/Users/chet/src/bash/src/parse.y"
3118     {
3119                           (yyval.command) = (yyvsp[(2) - (2)].command);
3120                           if (need_here_doc)
3121                             gather_here_documents ();
3122                          }
3123     break;
3124
3125   case 132:
3126 #line 1068 "/Users/chet/src/bash/src/parse.y"
3127     {
3128                           (yyval.command) = (yyvsp[(2) - (2)].command);
3129                         }
3130     break;
3131
3132   case 134:
3133 #line 1075 "/Users/chet/src/bash/src/parse.y"
3134     {
3135                           if ((yyvsp[(1) - (3)].command)->type == cm_connection)
3136                             (yyval.command) = connect_async_list ((yyvsp[(1) - (3)].command), (COMMAND *)NULL, '&');
3137                           else
3138                             (yyval.command) = command_connect ((yyvsp[(1) - (3)].command), (COMMAND *)NULL, '&');
3139                         }
3140     break;
3141
3142   case 136:
3143 #line 1086 "/Users/chet/src/bash/src/parse.y"
3144     { (yyval.command) = command_connect ((yyvsp[(1) - (4)].command), (yyvsp[(4) - (4)].command), AND_AND); }
3145     break;
3146
3147   case 137:
3148 #line 1088 "/Users/chet/src/bash/src/parse.y"
3149     { (yyval.command) = command_connect ((yyvsp[(1) - (4)].command), (yyvsp[(4) - (4)].command), OR_OR); }
3150     break;
3151
3152   case 138:
3153 #line 1090 "/Users/chet/src/bash/src/parse.y"
3154     {
3155                           if ((yyvsp[(1) - (4)].command)->type == cm_connection)
3156                             (yyval.command) = connect_async_list ((yyvsp[(1) - (4)].command), (yyvsp[(4) - (4)].command), '&');
3157                           else
3158                             (yyval.command) = command_connect ((yyvsp[(1) - (4)].command), (yyvsp[(4) - (4)].command), '&');
3159                         }
3160     break;
3161
3162   case 139:
3163 #line 1097 "/Users/chet/src/bash/src/parse.y"
3164     { (yyval.command) = command_connect ((yyvsp[(1) - (4)].command), (yyvsp[(4) - (4)].command), ';'); }
3165     break;
3166
3167   case 140:
3168 #line 1099 "/Users/chet/src/bash/src/parse.y"
3169     { (yyval.command) = command_connect ((yyvsp[(1) - (4)].command), (yyvsp[(4) - (4)].command), ';'); }
3170     break;
3171
3172   case 141:
3173 #line 1101 "/Users/chet/src/bash/src/parse.y"
3174     { (yyval.command) = (yyvsp[(1) - (1)].command); }
3175     break;
3176
3177   case 144:
3178 #line 1109 "/Users/chet/src/bash/src/parse.y"
3179     { (yyval.number) = '\n'; }
3180     break;
3181
3182   case 145:
3183 #line 1111 "/Users/chet/src/bash/src/parse.y"
3184     { (yyval.number) = ';'; }
3185     break;
3186
3187   case 146:
3188 #line 1113 "/Users/chet/src/bash/src/parse.y"
3189     { (yyval.number) = yacc_EOF; }
3190     break;
3191
3192   case 149:
3193 #line 1127 "/Users/chet/src/bash/src/parse.y"
3194     {
3195                           (yyval.command) = (yyvsp[(1) - (1)].command);
3196                           if (need_here_doc)
3197                             gather_here_documents ();
3198                           if ((parser_state & PST_CMDSUBST) && current_token == shell_eof_token)
3199                             {
3200                               global_command = (yyvsp[(1) - (1)].command);
3201                               eof_encountered = 0;
3202                               rewind_input_string ();
3203                               YYACCEPT;
3204                             }
3205                         }
3206     break;
3207
3208   case 150:
3209 #line 1140 "/Users/chet/src/bash/src/parse.y"
3210     {
3211                           if ((yyvsp[(1) - (2)].command)->type == cm_connection)
3212                             (yyval.command) = connect_async_list ((yyvsp[(1) - (2)].command), (COMMAND *)NULL, '&');
3213                           else
3214                             (yyval.command) = command_connect ((yyvsp[(1) - (2)].command), (COMMAND *)NULL, '&');
3215                           if (need_here_doc)
3216                             gather_here_documents ();
3217                           if ((parser_state & PST_CMDSUBST) && current_token == shell_eof_token)
3218                             {
3219                               global_command = (yyvsp[(1) - (2)].command);
3220                               eof_encountered = 0;
3221                               rewind_input_string ();
3222                               YYACCEPT;
3223                             }
3224                         }
3225     break;
3226
3227   case 151:
3228 #line 1156 "/Users/chet/src/bash/src/parse.y"
3229     {
3230                           (yyval.command) = (yyvsp[(1) - (2)].command);
3231                           if (need_here_doc)
3232                             gather_here_documents ();
3233                           if ((parser_state & PST_CMDSUBST) && current_token == shell_eof_token)
3234                             {
3235                               global_command = (yyvsp[(1) - (2)].command);
3236                               eof_encountered = 0;
3237                               rewind_input_string ();
3238                               YYACCEPT;
3239                             }
3240                         }
3241     break;
3242
3243   case 152:
3244 #line 1171 "/Users/chet/src/bash/src/parse.y"
3245     { (yyval.command) = command_connect ((yyvsp[(1) - (4)].command), (yyvsp[(4) - (4)].command), AND_AND); }
3246     break;
3247
3248   case 153:
3249 #line 1173 "/Users/chet/src/bash/src/parse.y"
3250     { (yyval.command) = command_connect ((yyvsp[(1) - (4)].command), (yyvsp[(4) - (4)].command), OR_OR); }
3251     break;
3252
3253   case 154:
3254 #line 1175 "/Users/chet/src/bash/src/parse.y"
3255     {
3256                           if ((yyvsp[(1) - (3)].command)->type == cm_connection)
3257                             (yyval.command) = connect_async_list ((yyvsp[(1) - (3)].command), (yyvsp[(3) - (3)].command), '&');
3258                           else
3259                             (yyval.command) = command_connect ((yyvsp[(1) - (3)].command), (yyvsp[(3) - (3)].command), '&');
3260                         }
3261     break;
3262
3263   case 155:
3264 #line 1182 "/Users/chet/src/bash/src/parse.y"
3265     { (yyval.command) = command_connect ((yyvsp[(1) - (3)].command), (yyvsp[(3) - (3)].command), ';'); }
3266     break;
3267
3268   case 156:
3269 #line 1185 "/Users/chet/src/bash/src/parse.y"
3270     { (yyval.command) = (yyvsp[(1) - (1)].command); }
3271     break;
3272
3273   case 157:
3274 #line 1189 "/Users/chet/src/bash/src/parse.y"
3275     { (yyval.command) = (yyvsp[(1) - (1)].command); }
3276     break;
3277
3278   case 158:
3279 #line 1191 "/Users/chet/src/bash/src/parse.y"
3280     {
3281                           if ((yyvsp[(2) - (2)].command))
3282                             (yyvsp[(2) - (2)].command)->flags |= CMD_INVERT_RETURN;
3283                           (yyval.command) = (yyvsp[(2) - (2)].command);
3284                         }
3285     break;
3286
3287   case 159:
3288 #line 1197 "/Users/chet/src/bash/src/parse.y"
3289     {
3290                           if ((yyvsp[(2) - (2)].command))
3291                             (yyvsp[(2) - (2)].command)->flags |= (yyvsp[(1) - (2)].number);
3292                           (yyval.command) = (yyvsp[(2) - (2)].command);
3293                         }
3294     break;
3295
3296   case 160:
3297 #line 1203 "/Users/chet/src/bash/src/parse.y"
3298     {
3299                           if ((yyvsp[(3) - (3)].command))
3300                             (yyvsp[(3) - (3)].command)->flags |= (yyvsp[(1) - (3)].number)|CMD_INVERT_RETURN;
3301                           (yyval.command) = (yyvsp[(3) - (3)].command);
3302                         }
3303     break;
3304
3305   case 161:
3306 #line 1209 "/Users/chet/src/bash/src/parse.y"
3307     {
3308                           if ((yyvsp[(3) - (3)].command))
3309                             (yyvsp[(3) - (3)].command)->flags |= (yyvsp[(2) - (3)].number)|CMD_INVERT_RETURN;
3310                           (yyval.command) = (yyvsp[(3) - (3)].command);
3311                         }
3312     break;
3313
3314   case 162:
3315 #line 1215 "/Users/chet/src/bash/src/parse.y"
3316     {
3317                           ELEMENT x;
3318
3319                           /* Boy, this is unclean.  `time' by itself can
3320                              time a null command.  We cheat and push a
3321                              newline back if the list_terminator was a newline
3322                              to avoid the double-newline problem (one to
3323                              terminate this, one to terminate the command) */
3324                           x.word = 0;
3325                           x.redirect = 0;
3326                           (yyval.command) = make_simple_command (x, (COMMAND *)NULL);
3327                           (yyval.command)->flags |= (yyvsp[(1) - (2)].number);
3328                           /* XXX - let's cheat and push a newline back */
3329                           if ((yyvsp[(2) - (2)].number) == '\n')
3330                             token_to_read = '\n';
3331                         }
3332     break;
3333
3334   case 163:
3335 #line 1235 "/Users/chet/src/bash/src/parse.y"
3336     { (yyval.command) = command_connect ((yyvsp[(1) - (4)].command), (yyvsp[(4) - (4)].command), '|'); }
3337     break;
3338
3339   case 164:
3340 #line 1237 "/Users/chet/src/bash/src/parse.y"
3341     {
3342                           /* Make cmd1 |& cmd2 equivalent to cmd1 2>&1 | cmd2 */
3343                           COMMAND *tc;
3344                           REDIRECTEE rd, sd;
3345                           REDIRECT *r;
3346
3347                           tc = (yyvsp[(1) - (4)].command)->type == cm_simple ? (COMMAND *)(yyvsp[(1) - (4)].command)->value.Simple : (yyvsp[(1) - (4)].command);
3348                           sd.dest = 2;
3349                           rd.dest = 1;
3350                           r = make_redirection (sd, r_duplicating_output, rd, 0);
3351                           if (tc->redirects)
3352                             {
3353                               register REDIRECT *t;
3354                               for (t = tc->redirects; t->next; t = t->next)
3355                                 ;
3356                               t->next = r;
3357                             }
3358                           else
3359                             tc->redirects = r;
3360
3361                           (yyval.command) = command_connect ((yyvsp[(1) - (4)].command), (yyvsp[(4) - (4)].command), '|');
3362                         }
3363     break;
3364
3365   case 165:
3366 #line 1260 "/Users/chet/src/bash/src/parse.y"
3367     { (yyval.command) = (yyvsp[(1) - (1)].command); }
3368     break;
3369
3370   case 166:
3371 #line 1264 "/Users/chet/src/bash/src/parse.y"
3372     { (yyval.number) = CMD_TIME_PIPELINE; }
3373     break;
3374
3375   case 167:
3376 #line 1266 "/Users/chet/src/bash/src/parse.y"
3377     { (yyval.number) = CMD_TIME_PIPELINE|CMD_TIME_POSIX; }
3378     break;
3379
3380
3381 /* Line 1267 of yacc.c.  */
3382 #line 3383 "y.tab.c"
3383       default: break;
3384     }
3385   YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc);
3386
3387   YYPOPSTACK (yylen);
3388   yylen = 0;
3389   YY_STACK_PRINT (yyss, yyssp);
3390
3391   *++yyvsp = yyval;
3392
3393
3394   /* Now `shift' the result of the reduction.  Determine what state
3395      that goes to, based on the state we popped back to and the rule
3396      number reduced by.  */
3397
3398   yyn = yyr1[yyn];
3399
3400   yystate = yypgoto[yyn - YYNTOKENS] + *yyssp;
3401   if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp)
3402     yystate = yytable[yystate];
3403   else
3404     yystate = yydefgoto[yyn - YYNTOKENS];
3405
3406   goto yynewstate;
3407
3408
3409 /*------------------------------------.
3410 | yyerrlab -- here on detecting error |
3411 `------------------------------------*/
3412 yyerrlab:
3413   /* If not already recovering from an error, report this error.  */
3414   if (!yyerrstatus)
3415     {
3416       ++yynerrs;
3417 #if ! YYERROR_VERBOSE
3418       yyerror (YY_("syntax error"));
3419 #else
3420       {
3421         YYSIZE_T yysize = yysyntax_error (0, yystate, yychar);
3422         if (yymsg_alloc < yysize && yymsg_alloc < YYSTACK_ALLOC_MAXIMUM)
3423           {
3424             YYSIZE_T yyalloc = 2 * yysize;
3425             if (! (yysize <= yyalloc && yyalloc <= YYSTACK_ALLOC_MAXIMUM))
3426               yyalloc = YYSTACK_ALLOC_MAXIMUM;
3427             if (yymsg != yymsgbuf)
3428               YYSTACK_FREE (yymsg);
3429             yymsg = (char *) YYSTACK_ALLOC (yyalloc);
3430             if (yymsg)
3431               yymsg_alloc = yyalloc;
3432             else
3433               {
3434                 yymsg = yymsgbuf;
3435                 yymsg_alloc = sizeof yymsgbuf;
3436               }
3437           }
3438
3439         if (0 < yysize && yysize <= yymsg_alloc)
3440           {
3441             (void) yysyntax_error (yymsg, yystate, yychar);
3442             yyerror (yymsg);
3443           }
3444         else
3445           {
3446             yyerror (YY_("syntax error"));
3447             if (yysize != 0)
3448               goto yyexhaustedlab;
3449           }
3450       }
3451 #endif
3452     }
3453
3454
3455
3456   if (yyerrstatus == 3)
3457     {
3458       /* If just tried and failed to reuse look-ahead token after an
3459          error, discard it.  */
3460
3461       if (yychar <= YYEOF)
3462         {
3463           /* Return failure if at end of input.  */
3464           if (yychar == YYEOF)
3465             YYABORT;
3466         }
3467       else
3468         {
3469           yydestruct ("Error: discarding",
3470                       yytoken, &yylval);
3471           yychar = YYEMPTY;
3472         }
3473     }
3474
3475   /* Else will try to reuse look-ahead token after shifting the error
3476      token.  */
3477   goto yyerrlab1;
3478
3479
3480 /*---------------------------------------------------.
3481 | yyerrorlab -- error raised explicitly by YYERROR.  |
3482 `---------------------------------------------------*/
3483 yyerrorlab:
3484
3485   /* Pacify compilers like GCC when the user code never invokes
3486      YYERROR and the label yyerrorlab therefore never appears in user
3487      code.  */
3488   if (/*CONSTCOND*/ 0)
3489      goto yyerrorlab;
3490
3491   /* Do not reclaim the symbols of the rule which action triggered
3492      this YYERROR.  */
3493   YYPOPSTACK (yylen);
3494   yylen = 0;
3495   YY_STACK_PRINT (yyss, yyssp);
3496   yystate = *yyssp;
3497   goto yyerrlab1;
3498
3499
3500 /*-------------------------------------------------------------.
3501 | yyerrlab1 -- common code for both syntax error and YYERROR.  |
3502 `-------------------------------------------------------------*/
3503 yyerrlab1:
3504   yyerrstatus = 3;      /* Each real token shifted decrements this.  */
3505
3506   for (;;)
3507     {
3508       yyn = yypact[yystate];
3509       if (yyn != YYPACT_NINF)
3510         {
3511           yyn += YYTERROR;
3512           if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
3513             {
3514               yyn = yytable[yyn];
3515               if (0 < yyn)
3516                 break;
3517             }
3518         }
3519
3520       /* Pop the current state because it cannot handle the error token.  */
3521       if (yyssp == yyss)
3522         YYABORT;
3523
3524
3525       yydestruct ("Error: popping",
3526                   yystos[yystate], yyvsp);
3527       YYPOPSTACK (1);
3528       yystate = *yyssp;
3529       YY_STACK_PRINT (yyss, yyssp);
3530     }
3531
3532   if (yyn == YYFINAL)
3533     YYACCEPT;
3534
3535   *++yyvsp = yylval;
3536
3537
3538   /* Shift the error token.  */
3539   YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp);
3540
3541   yystate = yyn;
3542   goto yynewstate;
3543
3544
3545 /*-------------------------------------.
3546 | yyacceptlab -- YYACCEPT comes here.  |
3547 `-------------------------------------*/
3548 yyacceptlab:
3549   yyresult = 0;
3550   goto yyreturn;
3551
3552 /*-----------------------------------.
3553 | yyabortlab -- YYABORT comes here.  |
3554 `-----------------------------------*/
3555 yyabortlab:
3556   yyresult = 1;
3557   goto yyreturn;
3558
3559 #ifndef yyoverflow
3560 /*-------------------------------------------------.
3561 | yyexhaustedlab -- memory exhaustion comes here.  |
3562 `-------------------------------------------------*/
3563 yyexhaustedlab:
3564   yyerror (YY_("memory exhausted"));
3565   yyresult = 2;
3566   /* Fall through.  */
3567 #endif
3568
3569 yyreturn:
3570   if (yychar != YYEOF && yychar != YYEMPTY)
3571      yydestruct ("Cleanup: discarding lookahead",
3572                  yytoken, &yylval);
3573   /* Do not reclaim the symbols of the rule which action triggered
3574      this YYABORT or YYACCEPT.  */
3575   YYPOPSTACK (yylen);
3576   YY_STACK_PRINT (yyss, yyssp);
3577   while (yyssp != yyss)
3578     {
3579       yydestruct ("Cleanup: popping",
3580                   yystos[*yyssp], yyvsp);
3581       YYPOPSTACK (1);
3582     }
3583 #ifndef yyoverflow
3584   if (yyss != yyssa)
3585     YYSTACK_FREE (yyss);
3586 #endif
3587 #if YYERROR_VERBOSE
3588   if (yymsg != yymsgbuf)
3589     YYSTACK_FREE (yymsg);
3590 #endif
3591   /* Make sure YYID is used.  */
3592   return YYID (yyresult);
3593 }
3594
3595
3596 #line 1268 "/Users/chet/src/bash/src/parse.y"
3597
3598
3599 /* Initial size to allocate for tokens, and the
3600    amount to grow them by. */
3601 #define TOKEN_DEFAULT_INITIAL_SIZE 496
3602 #define TOKEN_DEFAULT_GROW_SIZE 512
3603
3604 /* Should we call prompt_again? */
3605 #define SHOULD_PROMPT() \
3606   (interactive && (bash_input.type == st_stdin || bash_input.type == st_stream))
3607
3608 #if defined (ALIAS)
3609 #  define expanding_alias() (pushed_string_list && pushed_string_list->expander)
3610 #else
3611 #  define expanding_alias() 0
3612 #endif
3613
3614 /* Global var is non-zero when end of file has been reached. */
3615 int EOF_Reached = 0;
3616
3617 #ifdef DEBUG
3618 static void
3619 debug_parser (i)
3620      int i;
3621 {
3622 #if YYDEBUG != 0
3623   yydebug = i;
3624 #endif
3625 }
3626 #endif
3627
3628 /* yy_getc () returns the next available character from input or EOF.
3629    yy_ungetc (c) makes `c' the next character to read.
3630    init_yy_io (get, unget, type, location) makes the function GET the
3631    installed function for getting the next character, makes UNGET the
3632    installed function for un-getting a character, sets the type of stream
3633    (either string or file) from TYPE, and makes LOCATION point to where
3634    the input is coming from. */
3635
3636 /* Unconditionally returns end-of-file. */
3637 int
3638 return_EOF ()
3639 {
3640   return (EOF);
3641 }
3642
3643 /* Variable containing the current get and unget functions.
3644    See ./input.h for a clearer description. */
3645 BASH_INPUT bash_input;
3646
3647 /* Set all of the fields in BASH_INPUT to NULL.  Free bash_input.name if it
3648    is non-null, avoiding a memory leak. */
3649 void
3650 initialize_bash_input ()
3651 {
3652   bash_input.type = st_none;
3653   FREE (bash_input.name);
3654   bash_input.name = (char *)NULL;
3655   bash_input.location.file = (FILE *)NULL;
3656   bash_input.location.string = (char *)NULL;
3657   bash_input.getter = (sh_cget_func_t *)NULL;
3658   bash_input.ungetter = (sh_cunget_func_t *)NULL;
3659 }
3660
3661 /* Set the contents of the current bash input stream from
3662    GET, UNGET, TYPE, NAME, and LOCATION. */
3663 void
3664 init_yy_io (get, unget, type, name, location)
3665      sh_cget_func_t *get;
3666      sh_cunget_func_t *unget;
3667      enum stream_type type;
3668      const char *name;
3669      INPUT_STREAM location;
3670 {
3671   bash_input.type = type;
3672   FREE (bash_input.name);
3673   bash_input.name = name ? savestring (name) : (char *)NULL;
3674
3675   /* XXX */
3676 #if defined (CRAY)
3677   memcpy((char *)&bash_input.location.string, (char *)&location.string, sizeof(location));
3678 #else
3679   bash_input.location = location;
3680 #endif
3681   bash_input.getter = get;
3682   bash_input.ungetter = unget;
3683 }
3684
3685 char *
3686 yy_input_name ()
3687 {
3688   return (bash_input.name ? bash_input.name : "stdin");
3689 }
3690
3691 /* Call this to get the next character of input. */
3692 static int
3693 yy_getc ()
3694 {
3695   return (*(bash_input.getter)) ();
3696 }
3697
3698 /* Call this to unget C.  That is, to make C the next character
3699    to be read. */
3700 static int
3701 yy_ungetc (c)
3702      int c;
3703 {
3704   return (*(bash_input.ungetter)) (c);
3705 }
3706
3707 #if defined (BUFFERED_INPUT)
3708 #ifdef INCLUDE_UNUSED
3709 int
3710 input_file_descriptor ()
3711 {
3712   switch (bash_input.type)
3713     {
3714     case st_stream:
3715       return (fileno (bash_input.location.file));
3716     case st_bstream:
3717       return (bash_input.location.buffered_fd);
3718     case st_stdin:
3719     default:
3720       return (fileno (stdin));
3721     }
3722 }
3723 #endif
3724 #endif /* BUFFERED_INPUT */
3725
3726 /* **************************************************************** */
3727 /*                                                                  */
3728 /*                Let input be read from readline ().               */
3729 /*                                                                  */
3730 /* **************************************************************** */
3731
3732 #if defined (READLINE)
3733 char *current_readline_prompt = (char *)NULL;
3734 char *current_readline_line = (char *)NULL;
3735 int current_readline_line_index = 0;
3736
3737 static int
3738 yy_readline_get ()
3739 {
3740   SigHandler *old_sigint;
3741   int line_len;
3742   unsigned char c;
3743
3744   if (!current_readline_line)
3745     {
3746       if (!bash_readline_initialized)
3747         initialize_readline ();
3748
3749 #if defined (JOB_CONTROL)
3750       if (job_control)
3751         give_terminal_to (shell_pgrp, 0);
3752 #endif /* JOB_CONTROL */
3753
3754       old_sigint = (SigHandler *)NULL;
3755       if (signal_is_ignored (SIGINT) == 0)
3756         {
3757           old_sigint = (SigHandler *)set_signal_handler (SIGINT, sigint_sighandler);
3758           interrupt_immediately++;
3759         }
3760       terminate_immediately = 1;
3761
3762       current_readline_line = readline (current_readline_prompt ?
3763                                           current_readline_prompt : "");
3764
3765       terminate_immediately = 0;
3766       if (signal_is_ignored (SIGINT) == 0 && old_sigint)
3767         {
3768           interrupt_immediately--;
3769           set_signal_handler (SIGINT, old_sigint);
3770         }
3771
3772 #if 0
3773       /* Reset the prompt to the decoded value of prompt_string_pointer. */
3774       reset_readline_prompt ();
3775 #endif
3776
3777       if (current_readline_line == 0)
3778         return (EOF);
3779
3780       current_readline_line_index = 0;
3781       line_len = strlen (current_readline_line);
3782
3783       current_readline_line = (char *)xrealloc (current_readline_line, 2 + line_len);
3784       current_readline_line[line_len++] = '\n';
3785       current_readline_line[line_len] = '\0';
3786     }
3787
3788   if (current_readline_line[current_readline_line_index] == 0)
3789     {
3790       free (current_readline_line);
3791       current_readline_line = (char *)NULL;
3792       return (yy_readline_get ());
3793     }
3794   else
3795     {
3796       c = current_readline_line[current_readline_line_index++];
3797       return (c);
3798     }
3799 }
3800
3801 static int
3802 yy_readline_unget (c)
3803      int c;
3804 {
3805   if (current_readline_line_index && current_readline_line)
3806     current_readline_line[--current_readline_line_index] = c;
3807   return (c);
3808 }
3809
3810 void
3811 with_input_from_stdin ()
3812 {
3813   INPUT_STREAM location;
3814
3815   if (bash_input.type != st_stdin && stream_on_stack (st_stdin) == 0)
3816     {
3817       location.string = current_readline_line;
3818       init_yy_io (yy_readline_get, yy_readline_unget,
3819                   st_stdin, "readline stdin", location);
3820     }
3821 }
3822
3823 #else  /* !READLINE */
3824
3825 void
3826 with_input_from_stdin ()
3827 {
3828   with_input_from_stream (stdin, "stdin");
3829 }
3830 #endif  /* !READLINE */
3831
3832 /* **************************************************************** */
3833 /*                                                                  */
3834 /*   Let input come from STRING.  STRING is zero terminated.        */
3835 /*                                                                  */
3836 /* **************************************************************** */
3837
3838 static int
3839 yy_string_get ()
3840 {
3841   register char *string;
3842   register unsigned char c;
3843
3844   string = bash_input.location.string;
3845
3846   /* If the string doesn't exist, or is empty, EOF found. */
3847   if (string && *string)
3848     {
3849       c = *string++;
3850       bash_input.location.string = string;
3851       return (c);
3852     }
3853   else
3854     return (EOF);
3855 }
3856
3857 static int
3858 yy_string_unget (c)
3859      int c;
3860 {
3861   *(--bash_input.location.string) = c;
3862   return (c);
3863 }
3864
3865 void
3866 with_input_from_string (string, name)
3867      char *string;
3868      const char *name;
3869 {
3870   INPUT_STREAM location;
3871
3872   location.string = string;
3873   init_yy_io (yy_string_get, yy_string_unget, st_string, name, location);
3874 }
3875
3876 /* Count the number of characters we've consumed from bash_input.location.string
3877    and read into shell_input_line, but have not returned from shell_getc.
3878    That is the true input location.  Rewind bash_input.location.string by
3879    that number of characters, so it points to the last character actually
3880    consumed by the parser. */
3881 static void
3882 rewind_input_string ()
3883 {
3884   int xchars;
3885
3886   /* number of unconsumed characters in the input -- XXX need to take newlines
3887      into account, e.g., $(...\n) */
3888   xchars = shell_input_line_len - shell_input_line_index;
3889   if (bash_input.location.string[-1] == '\n')
3890     xchars++;
3891
3892   /* XXX - how to reflect bash_input.location.string back to string passed to
3893      parse_and_execute or xparse_dolparen?  xparse_dolparen needs to know how
3894      far into the string we parsed.  parse_and_execute knows where bash_input.
3895      location.string is, and how far from orig_string that is -- that's the
3896      number of characters the command consumed. */
3897
3898   /* bash_input.location.string - xchars should be where we parsed to */
3899   /* need to do more validation on xchars value for sanity -- test cases. */
3900   bash_input.location.string -= xchars;
3901 }
3902
3903 /* **************************************************************** */
3904 /*                                                                  */
3905 /*                   Let input come from STREAM.                    */
3906 /*                                                                  */
3907 /* **************************************************************** */
3908
3909 /* These two functions used to test the value of the HAVE_RESTARTABLE_SYSCALLS
3910    define, and just use getc/ungetc if it was defined, but since bash
3911    installs its signal handlers without the SA_RESTART flag, some signals
3912    (like SIGCHLD, SIGWINCH, etc.) received during a read(2) will not cause
3913    the read to be restarted.  We need to restart it ourselves. */
3914
3915 static int
3916 yy_stream_get ()
3917 {
3918   int result;
3919
3920   result = EOF;
3921   if (bash_input.location.file)
3922     {
3923       if (interactive)
3924         {
3925           interrupt_immediately++;
3926           terminate_immediately++;
3927         }
3928       result = getc_with_restart (bash_input.location.file);
3929       if (interactive)
3930         {
3931           interrupt_immediately--;
3932           terminate_immediately--;
3933         }
3934     }
3935   return (result);
3936 }
3937
3938 static int
3939 yy_stream_unget (c)
3940      int c;
3941 {
3942   return (ungetc_with_restart (c, bash_input.location.file));
3943 }
3944
3945 void
3946 with_input_from_stream (stream, name)
3947      FILE *stream;
3948      const char *name;
3949 {
3950   INPUT_STREAM location;
3951
3952   location.file = stream;
3953   init_yy_io (yy_stream_get, yy_stream_unget, st_stream, name, location);
3954 }
3955
3956 typedef struct stream_saver {
3957   struct stream_saver *next;
3958   BASH_INPUT bash_input;
3959   int line;
3960 #if defined (BUFFERED_INPUT)
3961   BUFFERED_STREAM *bstream;
3962 #endif /* BUFFERED_INPUT */
3963 } STREAM_SAVER;
3964
3965 /* The globally known line number. */
3966 int line_number = 0;
3967
3968 #if defined (COND_COMMAND)
3969 static int cond_lineno;
3970 static int cond_token;
3971 #endif
3972
3973 STREAM_SAVER *stream_list = (STREAM_SAVER *)NULL;
3974
3975 void
3976 push_stream (reset_lineno)
3977      int reset_lineno;
3978 {
3979   STREAM_SAVER *saver = (STREAM_SAVER *)xmalloc (sizeof (STREAM_SAVER));
3980
3981   xbcopy ((char *)&bash_input, (char *)&(saver->bash_input), sizeof (BASH_INPUT));
3982
3983 #if defined (BUFFERED_INPUT)
3984   saver->bstream = (BUFFERED_STREAM *)NULL;
3985   /* If we have a buffered stream, clear out buffers[fd]. */
3986   if (bash_input.type == st_bstream && bash_input.location.buffered_fd >= 0)
3987     saver->bstream = set_buffered_stream (bash_input.location.buffered_fd,
3988                                           (BUFFERED_STREAM *)NULL);
3989 #endif /* BUFFERED_INPUT */
3990
3991   saver->line = line_number;
3992   bash_input.name = (char *)NULL;
3993   saver->next = stream_list;
3994   stream_list = saver;
3995   EOF_Reached = 0;
3996   if (reset_lineno)
3997     line_number = 0;
3998 }
3999
4000 void
4001 pop_stream ()
4002 {
4003   if (!stream_list)
4004     EOF_Reached = 1;
4005   else
4006     {
4007       STREAM_SAVER *saver = stream_list;
4008
4009       EOF_Reached = 0;
4010       stream_list = stream_list->next;
4011
4012       init_yy_io (saver->bash_input.getter,
4013                   saver->bash_input.ungetter,
4014                   saver->bash_input.type,
4015                   saver->bash_input.name,
4016                   saver->bash_input.location);
4017
4018 #if defined (BUFFERED_INPUT)
4019       /* If we have a buffered stream, restore buffers[fd]. */
4020       /* If the input file descriptor was changed while this was on the
4021          save stack, update the buffered fd to the new file descriptor and
4022          re-establish the buffer <-> bash_input fd correspondence. */
4023       if (bash_input.type == st_bstream && bash_input.location.buffered_fd >= 0)
4024         {
4025           if (bash_input_fd_changed)
4026             {
4027               bash_input_fd_changed = 0;
4028               if (default_buffered_input >= 0)
4029                 {
4030                   bash_input.location.buffered_fd = default_buffered_input;
4031                   saver->bstream->b_fd = default_buffered_input;
4032                   SET_CLOSE_ON_EXEC (default_buffered_input);
4033                 }
4034             }
4035           /* XXX could free buffered stream returned as result here. */
4036           set_buffered_stream (bash_input.location.buffered_fd, saver->bstream);
4037         }
4038 #endif /* BUFFERED_INPUT */
4039
4040       line_number = saver->line;
4041
4042       FREE (saver->bash_input.name);
4043       free (saver);
4044     }
4045 }
4046
4047 /* Return 1 if a stream of type TYPE is saved on the stack. */
4048 int
4049 stream_on_stack (type)
4050      enum stream_type type;
4051 {
4052   register STREAM_SAVER *s;
4053
4054   for (s = stream_list; s; s = s->next)
4055     if (s->bash_input.type == type)
4056       return 1;
4057   return 0;
4058 }
4059
4060 /* Save the current token state and return it in a malloced array. */
4061 int *
4062 save_token_state ()
4063 {
4064   int *ret;
4065
4066   ret = (int *)xmalloc (4 * sizeof (int));
4067   ret[0] = last_read_token;
4068   ret[1] = token_before_that;
4069   ret[2] = two_tokens_ago;
4070   ret[3] = current_token;
4071   return ret;
4072 }
4073
4074 void
4075 restore_token_state (ts)
4076      int *ts;
4077 {
4078   if (ts == 0)
4079     return;
4080   last_read_token = ts[0];
4081   token_before_that = ts[1];
4082   two_tokens_ago = ts[2];
4083   current_token = ts[3];
4084 }
4085
4086 /*
4087  * This is used to inhibit alias expansion and reserved word recognition
4088  * inside case statement pattern lists.  A `case statement pattern list' is:
4089  *
4090  *      everything between the `in' in a `case word in' and the next ')'
4091  *      or `esac'
4092  *      everything between a `;;' and the next `)' or `esac'
4093  */
4094
4095 #if defined (ALIAS) || defined (DPAREN_ARITHMETIC)
4096
4097 #define END_OF_ALIAS 0
4098
4099 /*
4100  * Pseudo-global variables used in implementing token-wise alias expansion.
4101  */
4102
4103 /*
4104  * Pushing and popping strings.  This works together with shell_getc to
4105  * implement alias expansion on a per-token basis.
4106  */
4107
4108 typedef struct string_saver {
4109   struct string_saver *next;
4110   int expand_alias;  /* Value to set expand_alias to when string is popped. */
4111   char *saved_line;
4112 #if defined (ALIAS)
4113   alias_t *expander;   /* alias that caused this line to be pushed. */
4114 #endif
4115   int saved_line_size, saved_line_index, saved_line_terminator;
4116 } STRING_SAVER;
4117
4118 STRING_SAVER *pushed_string_list = (STRING_SAVER *)NULL;
4119
4120 /*
4121  * Push the current shell_input_line onto a stack of such lines and make S
4122  * the current input.  Used when expanding aliases.  EXPAND is used to set
4123  * the value of expand_next_token when the string is popped, so that the
4124  * word after the alias in the original line is handled correctly when the
4125  * alias expands to multiple words.  TOKEN is the token that was expanded
4126  * into S; it is saved and used to prevent infinite recursive expansion.
4127  */
4128 static void
4129 push_string (s, expand, ap)
4130      char *s;
4131      int expand;
4132      alias_t *ap;
4133 {
4134   STRING_SAVER *temp = (STRING_SAVER *)xmalloc (sizeof (STRING_SAVER));
4135
4136   temp->expand_alias = expand;
4137   temp->saved_line = shell_input_line;
4138   temp->saved_line_size = shell_input_line_size;
4139   temp->saved_line_index = shell_input_line_index;
4140   temp->saved_line_terminator = shell_input_line_terminator;
4141 #if defined (ALIAS)
4142   temp->expander = ap;
4143 #endif
4144   temp->next = pushed_string_list;
4145   pushed_string_list = temp;
4146
4147 #if defined (ALIAS)
4148   if (ap)
4149     ap->flags |= AL_BEINGEXPANDED;
4150 #endif
4151
4152   shell_input_line = s;
4153   shell_input_line_size = strlen (s);
4154   shell_input_line_index = 0;
4155   shell_input_line_terminator = '\0';
4156 #if 0
4157   parser_state &= ~PST_ALEXPNEXT;       /* XXX */
4158 #endif
4159
4160   set_line_mbstate ();
4161 }
4162
4163 /*
4164  * Make the top of the pushed_string stack be the current shell input.
4165  * Only called when there is something on the stack.  Called from shell_getc
4166  * when it thinks it has consumed the string generated by an alias expansion
4167  * and needs to return to the original input line.
4168  */
4169 static void
4170 pop_string ()
4171 {
4172   STRING_SAVER *t;
4173
4174   FREE (shell_input_line);
4175   shell_input_line = pushed_string_list->saved_line;
4176   shell_input_line_index = pushed_string_list->saved_line_index;
4177   shell_input_line_size = pushed_string_list->saved_line_size;
4178   shell_input_line_terminator = pushed_string_list->saved_line_terminator;
4179
4180   if (pushed_string_list->expand_alias)
4181     parser_state |= PST_ALEXPNEXT;
4182   else
4183     parser_state &= ~PST_ALEXPNEXT;
4184
4185   t = pushed_string_list;
4186   pushed_string_list = pushed_string_list->next;
4187
4188 #if defined (ALIAS)
4189   if (t->expander)
4190     t->expander->flags &= ~AL_BEINGEXPANDED;
4191 #endif
4192
4193   free ((char *)t);
4194
4195   set_line_mbstate ();
4196 }
4197
4198 static void
4199 free_string_list ()
4200 {
4201   register STRING_SAVER *t, *t1;
4202
4203   for (t = pushed_string_list; t; )
4204     {
4205       t1 = t->next;
4206       FREE (t->saved_line);
4207 #if defined (ALIAS)
4208       if (t->expander)
4209         t->expander->flags &= ~AL_BEINGEXPANDED;
4210 #endif
4211       free ((char *)t);
4212       t = t1;
4213     }
4214   pushed_string_list = (STRING_SAVER *)NULL;
4215 }
4216
4217 #endif /* ALIAS || DPAREN_ARITHMETIC */
4218
4219 void
4220 free_pushed_string_input ()
4221 {
4222 #if defined (ALIAS) || defined (DPAREN_ARITHMETIC)
4223   free_string_list ();
4224 #endif
4225 }
4226
4227 /* Return a line of text, taken from wherever yylex () reads input.
4228    If there is no more input, then we return NULL.  If REMOVE_QUOTED_NEWLINE
4229    is non-zero, we remove unquoted \<newline> pairs.  This is used by
4230    read_secondary_line to read here documents. */
4231 static char *
4232 read_a_line (remove_quoted_newline)
4233      int remove_quoted_newline;
4234 {
4235   static char *line_buffer = (char *)NULL;
4236   static int buffer_size = 0;
4237   int indx, c, peekc, pass_next;
4238
4239 #if defined (READLINE)
4240   if (no_line_editing && SHOULD_PROMPT ())
4241 #else
4242   if (SHOULD_PROMPT ())
4243 #endif
4244     print_prompt ();
4245
4246   pass_next = indx = 0;
4247   while (1)
4248     {
4249       /* Allow immediate exit if interrupted during input. */
4250       QUIT;
4251
4252       c = yy_getc ();
4253
4254       /* Ignore null bytes in input. */
4255       if (c == 0)
4256         {
4257 #if 0
4258           internal_warning ("read_a_line: ignored null byte in input");
4259 #endif
4260           continue;
4261         }
4262
4263       /* If there is no more input, then we return NULL. */
4264       if (c == EOF)
4265         {
4266           if (interactive && bash_input.type == st_stream)
4267             clearerr (stdin);
4268           if (indx == 0)
4269             return ((char *)NULL);
4270           c = '\n';
4271         }
4272
4273       /* `+2' in case the final character in the buffer is a newline. */
4274       RESIZE_MALLOCED_BUFFER (line_buffer, indx, 2, buffer_size, 128);
4275
4276       /* IF REMOVE_QUOTED_NEWLINES is non-zero, we are reading a
4277          here document with an unquoted delimiter.  In this case,
4278          the line will be expanded as if it were in double quotes.
4279          We allow a backslash to escape the next character, but we
4280          need to treat the backslash specially only if a backslash
4281          quoting a backslash-newline pair appears in the line. */
4282       if (pass_next)
4283         {
4284           line_buffer[indx++] = c;
4285           pass_next = 0;
4286         }
4287       else if (c == '\\' && remove_quoted_newline)
4288         {
4289           peekc = yy_getc ();
4290           if (peekc == '\n')
4291             {
4292               line_number++;
4293               continue; /* Make the unquoted \<newline> pair disappear. */
4294             }
4295           else
4296             {
4297               yy_ungetc (peekc);
4298               pass_next = 1;
4299               line_buffer[indx++] = c;          /* Preserve the backslash. */
4300             }
4301         }
4302       else
4303         line_buffer[indx++] = c;
4304
4305       if (c == '\n')
4306         {
4307           line_buffer[indx] = '\0';
4308           return (line_buffer);
4309         }
4310     }
4311 }
4312
4313 /* Return a line as in read_a_line (), but insure that the prompt is
4314    the secondary prompt.  This is used to read the lines of a here
4315    document.  REMOVE_QUOTED_NEWLINE is non-zero if we should remove
4316    newlines quoted with backslashes while reading the line.  It is
4317    non-zero unless the delimiter of the here document was quoted. */
4318 char *
4319 read_secondary_line (remove_quoted_newline)
4320      int remove_quoted_newline;
4321 {
4322   char *ret;
4323   int n, c;
4324
4325   prompt_string_pointer = &ps2_prompt;
4326   if (SHOULD_PROMPT())
4327     prompt_again ();
4328   ret = read_a_line (remove_quoted_newline);
4329 #if defined (HISTORY)
4330   if (ret && remember_on_history && (parser_state & PST_HEREDOC))
4331     {
4332       /* To make adding the the here-document body right, we need to rely
4333          on history_delimiting_chars() returning \n for the first line of
4334          the here-document body and the null string for the second and
4335          subsequent lines, so we avoid double newlines.
4336          current_command_line_count == 2 for the first line of the body. */
4337
4338       current_command_line_count++;
4339       maybe_add_history (ret);
4340     }
4341 #endif /* HISTORY */
4342   return ret;
4343 }
4344
4345 /* **************************************************************** */
4346 /*                                                                  */
4347 /*                              YYLEX ()                            */
4348 /*                                                                  */
4349 /* **************************************************************** */
4350
4351 /* Reserved words.  These are only recognized as the first word of a
4352    command. */
4353 STRING_INT_ALIST word_token_alist[] = {
4354   { "if", IF },
4355   { "then", THEN },
4356   { "else", ELSE },
4357   { "elif", ELIF },
4358   { "fi", FI },
4359   { "case", CASE },
4360   { "esac", ESAC },
4361   { "for", FOR },
4362 #if defined (SELECT_COMMAND)
4363   { "select", SELECT },
4364 #endif
4365   { "while", WHILE },
4366   { "until", UNTIL },
4367   { "do", DO },
4368   { "done", DONE },
4369   { "in", IN },
4370   { "function", FUNCTION },
4371 #if defined (COMMAND_TIMING)
4372   { "time", TIME },
4373 #endif
4374   { "{", '{' },
4375   { "}", '}' },
4376   { "!", BANG },
4377 #if defined (COND_COMMAND)
4378   { "[[", COND_START },
4379   { "]]", COND_END },
4380 #endif
4381 #if defined (COPROCESS_SUPPORT)
4382   { "coproc", COPROC },
4383 #endif
4384   { (char *)NULL, 0}
4385 };
4386
4387 /* other tokens that can be returned by read_token() */
4388 STRING_INT_ALIST other_token_alist[] = {
4389   /* Multiple-character tokens with special values */
4390   { "-p", TIMEOPT },
4391   { "&&", AND_AND },
4392   { "||", OR_OR },
4393   { ">>", GREATER_GREATER },
4394   { "<<", LESS_LESS },
4395   { "<&", LESS_AND },
4396   { ">&", GREATER_AND },
4397   { ";;", SEMI_SEMI },
4398   { ";&", SEMI_AND },
4399   { ";;&", SEMI_SEMI_AND },
4400   { "<<-", LESS_LESS_MINUS },
4401   { "<<<", LESS_LESS_LESS },
4402   { "&>", AND_GREATER },
4403   { "&>>", AND_GREATER_GREATER },
4404   { "<>", LESS_GREATER },
4405   { ">|", GREATER_BAR },
4406   { "|&", BAR_AND },
4407   { "EOF", yacc_EOF },
4408   /* Tokens whose value is the character itself */
4409   { ">", '>' },
4410   { "<", '<' },
4411   { "-", '-' },
4412   { "{", '{' },
4413   { "}", '}' },
4414   { ";", ';' },
4415   { "(", '(' },
4416   { ")", ')' },
4417   { "|", '|' },
4418   { "&", '&' },
4419   { "newline", '\n' },
4420   { (char *)NULL, 0}
4421 };
4422
4423 /* others not listed here:
4424         WORD                    look at yylval.word
4425         ASSIGNMENT_WORD         look at yylval.word
4426         NUMBER                  look at yylval.number
4427         ARITH_CMD               look at yylval.word_list
4428         ARITH_FOR_EXPRS         look at yylval.word_list
4429         COND_CMD                look at yylval.command
4430 */
4431
4432 /* These are used by read_token_word, but appear up here so that shell_getc
4433    can use them to decide when to add otherwise blank lines to the history. */
4434
4435 /* The primary delimiter stack. */
4436 struct dstack dstack = {  (char *)NULL, 0, 0 };
4437
4438 /* A temporary delimiter stack to be used when decoding prompt strings.
4439    This is needed because command substitutions in prompt strings (e.g., PS2)
4440    can screw up the parser's quoting state. */
4441 static struct dstack temp_dstack = { (char *)NULL, 0, 0 };
4442
4443 /* Macro for accessing the top delimiter on the stack.  Returns the
4444    delimiter or zero if none. */
4445 #define current_delimiter(ds) \
4446   (ds.delimiter_depth ? ds.delimiters[ds.delimiter_depth - 1] : 0)
4447
4448 #define push_delimiter(ds, character) \
4449   do \
4450     { \
4451       if (ds.delimiter_depth + 2 > ds.delimiter_space) \
4452         ds.delimiters = (char *)xrealloc \
4453           (ds.delimiters, (ds.delimiter_space += 10) * sizeof (char)); \
4454       ds.delimiters[ds.delimiter_depth] = character; \
4455       ds.delimiter_depth++; \
4456     } \
4457   while (0)
4458
4459 #define pop_delimiter(ds)       ds.delimiter_depth--
4460
4461 /* Return the next shell input character.  This always reads characters
4462    from shell_input_line; when that line is exhausted, it is time to
4463    read the next line.  This is called by read_token when the shell is
4464    processing normal command input. */
4465
4466 /* This implements one-character lookahead/lookbehind across physical input
4467    lines, to avoid something being lost because it's pushed back with
4468    shell_ungetc when we're at the start of a line. */
4469 static int eol_ungetc_lookahead = 0;
4470
4471 static int
4472 shell_getc (remove_quoted_newline)
4473      int remove_quoted_newline;
4474 {
4475   register int i;
4476   int c;
4477   unsigned char uc;
4478
4479   QUIT;
4480
4481   if (sigwinch_received)
4482     {
4483       sigwinch_received = 0;
4484       get_new_window_size (0, (int *)0, (int *)0);
4485     }
4486       
4487   if (eol_ungetc_lookahead)
4488     {
4489       c = eol_ungetc_lookahead;
4490       eol_ungetc_lookahead = 0;
4491       return (c);
4492     }
4493
4494 #if defined (ALIAS) || defined (DPAREN_ARITHMETIC)
4495   /* If shell_input_line[shell_input_line_index] == 0, but there is
4496      something on the pushed list of strings, then we don't want to go
4497      off and get another line.  We let the code down below handle it. */
4498
4499   if (!shell_input_line || ((!shell_input_line[shell_input_line_index]) &&
4500                             (pushed_string_list == (STRING_SAVER *)NULL)))
4501 #else /* !ALIAS && !DPAREN_ARITHMETIC */
4502   if (!shell_input_line || !shell_input_line[shell_input_line_index])
4503 #endif /* !ALIAS && !DPAREN_ARITHMETIC */
4504     {
4505       line_number++;
4506
4507     restart_read:
4508
4509       /* Allow immediate exit if interrupted during input. */
4510       QUIT;
4511
4512       i = 0;
4513       shell_input_line_terminator = 0;
4514
4515       /* If the shell is interatctive, but not currently printing a prompt
4516          (interactive_shell && interactive == 0), we don't want to print
4517          notifies or cleanup the jobs -- we want to defer it until we do
4518          print the next prompt. */
4519       if (interactive_shell == 0 || SHOULD_PROMPT())
4520         {
4521 #if defined (JOB_CONTROL)
4522       /* This can cause a problem when reading a command as the result
4523          of a trap, when the trap is called from flush_child.  This call
4524          had better not cause jobs to disappear from the job table in
4525          that case, or we will have big trouble. */
4526           notify_and_cleanup ();
4527 #else /* !JOB_CONTROL */
4528           cleanup_dead_jobs ();
4529 #endif /* !JOB_CONTROL */
4530         }
4531
4532 #if defined (READLINE)
4533       if (no_line_editing && SHOULD_PROMPT())
4534 #else
4535       if (SHOULD_PROMPT())
4536 #endif
4537         print_prompt ();
4538
4539       if (bash_input.type == st_stream)
4540         clearerr (stdin);
4541
4542       while (1)
4543         {
4544           c = yy_getc ();
4545
4546           /* Allow immediate exit if interrupted during input. */
4547           QUIT;
4548
4549           if (c == '\0')
4550             {
4551 #if 0
4552               internal_warning ("shell_getc: ignored null byte in input");
4553 #endif
4554               continue;
4555             }
4556
4557           RESIZE_MALLOCED_BUFFER (shell_input_line, i, 2, shell_input_line_size, 256);
4558
4559           if (c == EOF)
4560             {
4561               if (bash_input.type == st_stream)
4562                 clearerr (stdin);
4563
4564               if (i == 0)
4565                 shell_input_line_terminator = EOF;
4566
4567               shell_input_line[i] = '\0';
4568               break;
4569             }
4570
4571           shell_input_line[i++] = c;
4572
4573           if (c == '\n')
4574             {
4575               shell_input_line[--i] = '\0';
4576               current_command_line_count++;
4577               break;
4578             }
4579         }
4580
4581       shell_input_line_index = 0;
4582       shell_input_line_len = i;         /* == strlen (shell_input_line) */
4583
4584       set_line_mbstate ();
4585
4586 #if defined (HISTORY)
4587       if (remember_on_history && shell_input_line && shell_input_line[0])
4588         {
4589           char *expansions;
4590 #  if defined (BANG_HISTORY)
4591           int old_hist;
4592
4593           /* If the current delimiter is a single quote, we should not be
4594              performing history expansion, even if we're on a different
4595              line from the original single quote. */
4596           old_hist = history_expansion_inhibited;
4597           if (current_delimiter (dstack) == '\'')
4598             history_expansion_inhibited = 1;
4599 #  endif
4600           expansions = pre_process_line (shell_input_line, 1, 1);
4601 #  if defined (BANG_HISTORY)
4602           history_expansion_inhibited = old_hist;
4603 #  endif
4604           if (expansions != shell_input_line)
4605             {
4606               free (shell_input_line);
4607               shell_input_line = expansions;
4608               shell_input_line_len = shell_input_line ?
4609                                         strlen (shell_input_line) : 0;
4610               if (!shell_input_line_len)
4611                 current_command_line_count--;
4612
4613               /* We have to force the xrealloc below because we don't know
4614                  the true allocated size of shell_input_line anymore. */
4615               shell_input_line_size = shell_input_line_len;
4616
4617               set_line_mbstate ();
4618             }
4619         }
4620       /* Try to do something intelligent with blank lines encountered while
4621          entering multi-line commands.  XXX - this is grotesque */
4622       else if (remember_on_history && shell_input_line &&
4623                shell_input_line[0] == '\0' &&
4624                current_command_line_count > 1)
4625         {
4626           if (current_delimiter (dstack))
4627             /* We know shell_input_line[0] == 0 and we're reading some sort of
4628                quoted string.  This means we've got a line consisting of only
4629                a newline in a quoted string.  We want to make sure this line
4630                gets added to the history. */
4631             maybe_add_history (shell_input_line);
4632           else
4633             {
4634               char *hdcs;
4635               hdcs = history_delimiting_chars ();
4636               if (hdcs && hdcs[0] == ';')
4637                 maybe_add_history (shell_input_line);
4638             }
4639         }
4640
4641 #endif /* HISTORY */
4642
4643       if (shell_input_line)
4644         {
4645           /* Lines that signify the end of the shell's input should not be
4646              echoed. */
4647           if (echo_input_at_read && (shell_input_line[0] ||
4648                                      shell_input_line_terminator != EOF))
4649             fprintf (stderr, "%s\n", shell_input_line);
4650         }
4651       else
4652         {
4653           shell_input_line_size = 0;
4654           prompt_string_pointer = &current_prompt_string;
4655           if (SHOULD_PROMPT ())
4656             prompt_again ();
4657           goto restart_read;
4658         }
4659
4660       /* Add the newline to the end of this string, iff the string does
4661          not already end in an EOF character.  */
4662       if (shell_input_line_terminator != EOF)
4663         {
4664           if (shell_input_line_len + 3 > shell_input_line_size)
4665             shell_input_line = (char *)xrealloc (shell_input_line,
4666                                         1 + (shell_input_line_size += 2));
4667
4668           shell_input_line[shell_input_line_len] = '\n';
4669           shell_input_line[shell_input_line_len + 1] = '\0';
4670
4671           set_line_mbstate ();
4672         }
4673     }
4674
4675   uc = shell_input_line[shell_input_line_index];
4676
4677   if (uc)
4678     shell_input_line_index++;
4679
4680 #if defined (ALIAS) || defined (DPAREN_ARITHMETIC)
4681   /* If UC is NULL, we have reached the end of the current input string.  If
4682      pushed_string_list is non-empty, it's time to pop to the previous string
4683      because we have fully consumed the result of the last alias expansion.
4684      Do it transparently; just return the next character of the string popped
4685      to. */
4686 pop_alias:
4687   if (!uc && (pushed_string_list != (STRING_SAVER *)NULL))
4688     {
4689       pop_string ();
4690       uc = shell_input_line[shell_input_line_index];
4691       if (uc)
4692         shell_input_line_index++;
4693     }
4694 #endif /* ALIAS || DPAREN_ARITHMETIC */
4695
4696   if MBTEST(uc == '\\' && remove_quoted_newline && shell_input_line[shell_input_line_index] == '\n')
4697     {
4698         if (SHOULD_PROMPT ())
4699           prompt_again ();
4700         line_number++;
4701         /* XXX - what do we do here if we're expanding an alias whose definition
4702            ends with a newline?  Recall that we inhibit the appending of a
4703            space in mk_alexpansion() if newline is the last character. */
4704 #if 0   /* XXX - bash-4.2 (jonathan@claggett.org) */
4705         if (expanding_alias () && shell_input_line[shell_input_line_index+1] == '\0')
4706           {
4707             uc = 0;
4708             goto pop_alias;
4709           }
4710 #endif
4711           
4712         goto restart_read;
4713     }
4714
4715   if (!uc && shell_input_line_terminator == EOF)
4716     return ((shell_input_line_index != 0) ? '\n' : EOF);
4717
4718   return (uc);
4719 }
4720
4721 /* Put C back into the input for the shell.  This might need changes for
4722    HANDLE_MULTIBYTE around EOLs.  Since we (currently) never push back a
4723    character different than we read, shell_input_line_property doesn't need
4724    to change when manipulating shell_input_line.  The define for
4725    last_shell_getc_is_singlebyte should take care of it, though. */
4726 static void
4727 shell_ungetc (c)
4728      int c;
4729 {
4730   if (shell_input_line && shell_input_line_index)
4731     shell_input_line[--shell_input_line_index] = c;
4732   else
4733     eol_ungetc_lookahead = c;
4734 }
4735
4736 #ifdef INCLUDE_UNUSED
4737 /* Back the input pointer up by one, effectively `ungetting' a character. */
4738 static void
4739 shell_ungetchar ()
4740 {
4741   if (shell_input_line && shell_input_line_index)
4742     shell_input_line_index--;
4743 }
4744 #endif
4745
4746 /* Discard input until CHARACTER is seen, then push that character back
4747    onto the input stream. */
4748 static void
4749 discard_until (character)
4750      int character;
4751 {
4752   int c;
4753
4754   while ((c = shell_getc (0)) != EOF && c != character)
4755     ;
4756
4757   if (c != EOF)
4758     shell_ungetc (c);
4759 }
4760
4761 void
4762 execute_variable_command (command, vname)
4763      char *command, *vname;
4764 {
4765   char *last_lastarg;
4766   sh_parser_state_t ps;
4767
4768   save_parser_state (&ps);
4769   last_lastarg = get_string_value ("_");
4770   if (last_lastarg)
4771     last_lastarg = savestring (last_lastarg);
4772
4773   parse_and_execute (savestring (command), vname, SEVAL_NONINT|SEVAL_NOHIST);
4774
4775   restore_parser_state (&ps);
4776   bind_variable ("_", last_lastarg, 0);
4777   FREE (last_lastarg);
4778
4779   if (token_to_read == '\n')    /* reset_parser was called */
4780     token_to_read = 0;
4781 }
4782
4783 /* Place to remember the token.  We try to keep the buffer
4784    at a reasonable size, but it can grow. */
4785 static char *token = (char *)NULL;
4786
4787 /* Current size of the token buffer. */
4788 static int token_buffer_size;
4789
4790 /* Command to read_token () explaining what we want it to do. */
4791 #define READ 0
4792 #define RESET 1
4793 #define prompt_is_ps1 \
4794       (!prompt_string_pointer || prompt_string_pointer == &ps1_prompt)
4795
4796 /* Function for yyparse to call.  yylex keeps track of
4797    the last two tokens read, and calls read_token.  */
4798 static int
4799 yylex ()
4800 {
4801   if (interactive && (current_token == 0 || current_token == '\n'))
4802     {
4803       /* Before we print a prompt, we might have to check mailboxes.
4804          We do this only if it is time to do so. Notice that only here
4805          is the mail alarm reset; nothing takes place in check_mail ()
4806          except the checking of mail.  Please don't change this. */
4807       if (prompt_is_ps1 && time_to_check_mail ())
4808         {
4809           check_mail ();
4810           reset_mail_timer ();
4811         }
4812
4813       /* Avoid printing a prompt if we're not going to read anything, e.g.
4814          after resetting the parser with read_token (RESET). */
4815       if (token_to_read == 0 && SHOULD_PROMPT ())
4816         prompt_again ();
4817     }
4818
4819   two_tokens_ago = token_before_that;
4820   token_before_that = last_read_token;
4821   last_read_token = current_token;
4822   current_token = read_token (READ);
4823
4824   if ((parser_state & PST_EOFTOKEN) && current_token == shell_eof_token)
4825     {
4826       current_token = yacc_EOF;
4827       if (bash_input.type == st_string)
4828         rewind_input_string ();
4829     }
4830   parser_state &= ~PST_EOFTOKEN;
4831
4832   return (current_token);
4833 }
4834
4835 /* When non-zero, we have read the required tokens
4836    which allow ESAC to be the next one read. */
4837 static int esacs_needed_count;
4838
4839 void
4840 gather_here_documents ()
4841 {
4842   int r;
4843
4844   r = 0;
4845   while (need_here_doc)
4846     {
4847       parser_state |= PST_HEREDOC;
4848       make_here_document (redir_stack[r++], line_number);
4849       parser_state &= ~PST_HEREDOC;
4850       need_here_doc--;
4851     }
4852 }
4853
4854 /* When non-zero, an open-brace used to create a group is awaiting a close
4855    brace partner. */
4856 static int open_brace_count;
4857
4858 #define command_token_position(token) \
4859   (((token) == ASSIGNMENT_WORD) || (parser_state&PST_REDIRLIST) || \
4860    ((token) != SEMI_SEMI && (token) != SEMI_AND && (token) != SEMI_SEMI_AND && reserved_word_acceptable(token)))
4861
4862 #define assignment_acceptable(token) \
4863   (command_token_position(token) && ((parser_state & PST_CASEPAT) == 0))
4864
4865 /* Check to see if TOKEN is a reserved word and return the token
4866    value if it is. */
4867 #define CHECK_FOR_RESERVED_WORD(tok) \
4868   do { \
4869     if (!dollar_present && !quoted && \
4870         reserved_word_acceptable (last_read_token)) \
4871       { \
4872         int i; \
4873         for (i = 0; word_token_alist[i].word != (char *)NULL; i++) \
4874           if (STREQ (tok, word_token_alist[i].word)) \
4875             { \
4876               if ((parser_state & PST_CASEPAT) && (word_token_alist[i].token != ESAC)) \
4877                 break; \
4878               if (word_token_alist[i].token == TIME && time_command_acceptable () == 0) \
4879                 break; \
4880               if (word_token_alist[i].token == ESAC) \
4881                 parser_state &= ~(PST_CASEPAT|PST_CASESTMT); \
4882               else if (word_token_alist[i].token == CASE) \
4883                 parser_state |= PST_CASESTMT; \
4884               else if (word_token_alist[i].token == COND_END) \
4885                 parser_state &= ~(PST_CONDCMD|PST_CONDEXPR); \
4886               else if (word_token_alist[i].token == COND_START) \
4887                 parser_state |= PST_CONDCMD; \
4888               else if (word_token_alist[i].token == '{') \
4889                 open_brace_count++; \
4890               else if (word_token_alist[i].token == '}' && open_brace_count) \
4891                 open_brace_count--; \
4892               return (word_token_alist[i].token); \
4893             } \
4894       } \
4895   } while (0)
4896
4897 #if defined (ALIAS)
4898
4899     /* OK, we have a token.  Let's try to alias expand it, if (and only if)
4900        it's eligible.
4901
4902        It is eligible for expansion if EXPAND_ALIASES is set, and
4903        the token is unquoted and the last token read was a command
4904        separator (or expand_next_token is set), and we are currently
4905        processing an alias (pushed_string_list is non-empty) and this
4906        token is not the same as the current or any previously
4907        processed alias.
4908
4909        Special cases that disqualify:
4910          In a pattern list in a case statement (parser_state & PST_CASEPAT). */
4911
4912 static char *
4913 mk_alexpansion (s)
4914      char *s;
4915 {
4916   int l;
4917   char *r;
4918
4919   l = strlen (s);
4920   r = xmalloc (l + 2);
4921   strcpy (r, s);
4922 #if 0           /* XXX - bash-4.2 */
4923   if (r[l -1] != ' ' && r[l -1] != '\n')
4924 #else
4925   if (r[l -1] != ' ')
4926 #endif
4927     r[l++] = ' ';
4928   r[l] = '\0';
4929   return r;
4930 }
4931
4932 static int
4933 alias_expand_token (tokstr)
4934      char *tokstr;
4935 {
4936   char *expanded;
4937   alias_t *ap;
4938
4939   if (((parser_state & PST_ALEXPNEXT) || command_token_position (last_read_token)) &&
4940         (parser_state & PST_CASEPAT) == 0)
4941     {
4942       ap = find_alias (tokstr);
4943
4944       /* Currently expanding this token. */
4945       if (ap && (ap->flags & AL_BEINGEXPANDED))
4946         return (NO_EXPANSION);
4947
4948       /* mk_alexpansion puts an extra space on the end of the alias expansion,
4949          so the lookahead by the parser works right.  If this gets changed,
4950          make sure the code in shell_getc that deals with reaching the end of
4951          an expanded alias is changed with it. */
4952       expanded = ap ? mk_alexpansion (ap->value) : (char *)NULL;
4953
4954       if (expanded)
4955         {
4956           push_string (expanded, ap->flags & AL_EXPANDNEXT, ap);
4957           return (RE_READ_TOKEN);
4958         }
4959       else
4960         /* This is an eligible token that does not have an expansion. */
4961         return (NO_EXPANSION);
4962     }
4963   return (NO_EXPANSION);
4964 }
4965 #endif /* ALIAS */
4966
4967 static int
4968 time_command_acceptable ()
4969 {
4970 #if defined (COMMAND_TIMING)
4971   switch (last_read_token)
4972     {
4973     case 0:
4974     case ';':
4975     case '\n':
4976     case AND_AND:
4977     case OR_OR:
4978     case '&':
4979     case DO:
4980     case THEN:
4981     case ELSE:
4982     case '{':           /* } */
4983     case '(':           /* ) */
4984       return 1;
4985     default:
4986       return 0;
4987     }
4988 #else
4989   return 0;
4990 #endif /* COMMAND_TIMING */
4991 }
4992
4993 /* Handle special cases of token recognition:
4994         IN is recognized if the last token was WORD and the token
4995         before that was FOR or CASE or SELECT.
4996
4997         DO is recognized if the last token was WORD and the token
4998         before that was FOR or SELECT.
4999
5000         ESAC is recognized if the last token caused `esacs_needed_count'
5001         to be set
5002
5003         `{' is recognized if the last token as WORD and the token
5004         before that was FUNCTION, or if we just parsed an arithmetic
5005         `for' command.
5006
5007         `}' is recognized if there is an unclosed `{' present.
5008
5009         `-p' is returned as TIMEOPT if the last read token was TIME.
5010
5011         ']]' is returned as COND_END if the parser is currently parsing
5012         a conditional expression ((parser_state & PST_CONDEXPR) != 0)
5013
5014         `time' is returned as TIME if and only if it is immediately
5015         preceded by one of `;', `\n', `||', `&&', or `&'.
5016 */
5017
5018 static int
5019 special_case_tokens (tokstr)
5020      char *tokstr;
5021 {
5022   if ((last_read_token == WORD) &&
5023 #if defined (SELECT_COMMAND)
5024       ((token_before_that == FOR) || (token_before_that == CASE) || (token_before_that == SELECT)) &&
5025 #else
5026       ((token_before_that == FOR) || (token_before_that == CASE)) &&
5027 #endif
5028       (tokstr[0] == 'i' && tokstr[1] == 'n' && tokstr[2] == 0))
5029     {
5030       if (token_before_that == CASE)
5031         {
5032           parser_state |= PST_CASEPAT;
5033           esacs_needed_count++;
5034         }
5035       return (IN);
5036     }
5037
5038   if (last_read_token == WORD &&
5039 #if defined (SELECT_COMMAND)
5040       (token_before_that == FOR || token_before_that == SELECT) &&
5041 #else
5042       (token_before_that == FOR) &&
5043 #endif
5044       (tokstr[0] == 'd' && tokstr[1] == 'o' && tokstr[2] == '\0'))
5045     return (DO);
5046
5047   /* Ditto for ESAC in the CASE case.
5048      Specifically, this handles "case word in esac", which is a legal
5049      construct, certainly because someone will pass an empty arg to the
5050      case construct, and we don't want it to barf.  Of course, we should
5051      insist that the case construct has at least one pattern in it, but
5052      the designers disagree. */
5053   if (esacs_needed_count)
5054     {
5055       esacs_needed_count--;
5056       if (STREQ (tokstr, "esac"))
5057         {
5058           parser_state &= ~PST_CASEPAT;
5059           return (ESAC);
5060         }
5061     }
5062
5063   /* The start of a shell function definition. */
5064   if (parser_state & PST_ALLOWOPNBRC)
5065     {
5066       parser_state &= ~PST_ALLOWOPNBRC;
5067       if (tokstr[0] == '{' && tokstr[1] == '\0')                /* } */
5068         {
5069           open_brace_count++;
5070           function_bstart = line_number;
5071           return ('{');                                 /* } */
5072         }
5073     }
5074
5075   /* We allow a `do' after a for ((...)) without an intervening
5076      list_terminator */
5077   if (last_read_token == ARITH_FOR_EXPRS && tokstr[0] == 'd' && tokstr[1] == 'o' && !tokstr[2])
5078     return (DO);
5079   if (last_read_token == ARITH_FOR_EXPRS && tokstr[0] == '{' && tokstr[1] == '\0')      /* } */
5080     {
5081       open_brace_count++;
5082       return ('{');                     /* } */
5083     }
5084
5085   if (open_brace_count && reserved_word_acceptable (last_read_token) && tokstr[0] == '}' && !tokstr[1])
5086     {
5087       open_brace_count--;               /* { */
5088       return ('}');
5089     }
5090
5091 #if defined (COMMAND_TIMING)
5092   /* Handle -p after `time'. */
5093   if (last_read_token == TIME && tokstr[0] == '-' && tokstr[1] == 'p' && !tokstr[2])
5094     return (TIMEOPT);
5095 #endif
5096
5097 #if 0
5098 #if defined (COMMAND_TIMING)
5099   if (STREQ (token, "time") && ((parser_state & PST_CASEPAT) == 0) && time_command_acceptable ())
5100     return (TIME);
5101 #endif /* COMMAND_TIMING */
5102 #endif
5103
5104 #if defined (COND_COMMAND) /* [[ */
5105   if ((parser_state & PST_CONDEXPR) && tokstr[0] == ']' && tokstr[1] == ']' && tokstr[2] == '\0')
5106     return (COND_END);
5107 #endif
5108
5109   return (-1);
5110 }
5111
5112 /* Called from shell.c when Control-C is typed at top level.  Or
5113    by the error rule at top level. */
5114 void
5115 reset_parser ()
5116 {
5117   dstack.delimiter_depth = 0;   /* No delimiters found so far. */
5118   open_brace_count = 0;
5119
5120 #if defined (EXTENDED_GLOB)
5121   /* Reset to global value of extended glob */
5122   if (parser_state & PST_EXTPAT)
5123     extended_glob = global_extglob;
5124 #endif
5125
5126   parser_state = 0;
5127
5128 #if defined (ALIAS) || defined (DPAREN_ARITHMETIC)
5129   if (pushed_string_list)
5130     free_string_list ();
5131 #endif /* ALIAS || DPAREN_ARITHMETIC */
5132
5133   if (shell_input_line)
5134     {
5135       free (shell_input_line);
5136       shell_input_line = (char *)NULL;
5137       shell_input_line_size = shell_input_line_index = 0;
5138     }
5139
5140   FREE (word_desc_to_read);
5141   word_desc_to_read = (WORD_DESC *)NULL;
5142
5143   current_token = '\n';         /* XXX */
5144   last_read_token = '\n';
5145   token_to_read = '\n';
5146 }
5147
5148 /* Read the next token.  Command can be READ (normal operation) or
5149    RESET (to normalize state). */
5150 static int
5151 read_token (command)
5152      int command;
5153 {
5154   int character;                /* Current character. */
5155   int peek_char;                /* Temporary look-ahead character. */
5156   int result;                   /* The thing to return. */
5157
5158   if (command == RESET)
5159     {
5160       reset_parser ();
5161       return ('\n');
5162     }
5163
5164   if (token_to_read)
5165     {
5166       result = token_to_read;
5167       if (token_to_read == WORD || token_to_read == ASSIGNMENT_WORD)
5168         {
5169           yylval.word = word_desc_to_read;
5170           word_desc_to_read = (WORD_DESC *)NULL;
5171         }
5172       token_to_read = 0;
5173       return (result);
5174     }
5175
5176 #if defined (COND_COMMAND)
5177   if ((parser_state & (PST_CONDCMD|PST_CONDEXPR)) == PST_CONDCMD)
5178     {
5179       cond_lineno = line_number;
5180       parser_state |= PST_CONDEXPR;
5181       yylval.command = parse_cond_command ();
5182       if (cond_token != COND_END)
5183         {
5184           cond_error ();
5185           return (-1);
5186         }
5187       token_to_read = COND_END;
5188       parser_state &= ~(PST_CONDEXPR|PST_CONDCMD);
5189       return (COND_CMD);
5190     }
5191 #endif
5192
5193 #if defined (ALIAS)
5194   /* This is a place to jump back to once we have successfully expanded a
5195      token with an alias and pushed the string with push_string () */
5196  re_read_token:
5197 #endif /* ALIAS */
5198
5199   /* Read a single word from input.  Start by skipping blanks. */
5200   while ((character = shell_getc (1)) != EOF && shellblank (character))
5201     ;
5202
5203   if (character == EOF)
5204     {
5205       EOF_Reached = 1;
5206       return (yacc_EOF);
5207     }
5208
5209   if MBTEST(character == '#' && (!interactive || interactive_comments))
5210     {
5211       /* A comment.  Discard until EOL or EOF, and then return a newline. */
5212       discard_until ('\n');
5213       shell_getc (0);
5214       character = '\n'; /* this will take the next if statement and return. */
5215     }
5216
5217   if (character == '\n')
5218     {
5219       /* If we're about to return an unquoted newline, we can go and collect
5220          the text of any pending here document. */
5221       if (need_here_doc)
5222         gather_here_documents ();
5223
5224 #if defined (ALIAS)
5225       parser_state &= ~PST_ALEXPNEXT;
5226 #endif /* ALIAS */
5227
5228       parser_state &= ~PST_ASSIGNOK;
5229
5230       return (character);
5231     }
5232
5233   if (parser_state & PST_REGEXP)
5234     goto tokword;
5235
5236   /* Shell meta-characters. */
5237   if MBTEST(shellmeta (character) && ((parser_state & PST_DBLPAREN) == 0))
5238     {
5239 #if defined (ALIAS)
5240       /* Turn off alias tokenization iff this character sequence would
5241          not leave us ready to read a command. */
5242       if (character == '<' || character == '>')
5243         parser_state &= ~PST_ALEXPNEXT;
5244 #endif /* ALIAS */
5245
5246       parser_state &= ~PST_ASSIGNOK;
5247
5248       peek_char = shell_getc (1);
5249       if (character == peek_char)
5250         {
5251           switch (character)
5252             {
5253             case '<':
5254               /* If '<' then we could be at "<<" or at "<<-".  We have to
5255                  look ahead one more character. */
5256               peek_char = shell_getc (1);
5257               if MBTEST(peek_char == '-')
5258                 return (LESS_LESS_MINUS);
5259               else if MBTEST(peek_char == '<')
5260                 return (LESS_LESS_LESS);
5261               else
5262                 {
5263                   shell_ungetc (peek_char);
5264                   return (LESS_LESS);
5265                 }
5266
5267             case '>':
5268               return (GREATER_GREATER);
5269
5270             case ';':
5271               parser_state |= PST_CASEPAT;
5272 #if defined (ALIAS)
5273               parser_state &= ~PST_ALEXPNEXT;
5274 #endif /* ALIAS */
5275
5276               peek_char = shell_getc (1);
5277               if MBTEST(peek_char == '&')
5278                 return (SEMI_SEMI_AND);
5279               else
5280                 {
5281                   shell_ungetc (peek_char);
5282                   return (SEMI_SEMI);
5283                 }
5284
5285             case '&':
5286               return (AND_AND);
5287
5288             case '|':
5289               return (OR_OR);
5290
5291 #if defined (DPAREN_ARITHMETIC) || defined (ARITH_FOR_COMMAND)
5292             case '(':           /* ) */
5293               result = parse_dparen (character);
5294               if (result == -2)
5295                 break;
5296               else
5297                 return result;
5298 #endif
5299             }
5300         }
5301       else if MBTEST(character == '<' && peek_char == '&')
5302         return (LESS_AND);
5303       else if MBTEST(character == '>' && peek_char == '&')
5304         return (GREATER_AND);
5305       else if MBTEST(character == '<' && peek_char == '>')
5306         return (LESS_GREATER);
5307       else if MBTEST(character == '>' && peek_char == '|')
5308         return (GREATER_BAR);
5309       else if MBTEST(character == '&' && peek_char == '>')
5310         {
5311           peek_char = shell_getc (1);
5312           if MBTEST(peek_char == '>')
5313             return (AND_GREATER_GREATER);
5314           else
5315             {
5316               shell_ungetc (peek_char);
5317               return (AND_GREATER);
5318             }
5319         }
5320       else if MBTEST(character == '|' && peek_char == '&')
5321         return (BAR_AND);
5322       else if MBTEST(character == ';' && peek_char == '&')
5323         {
5324           parser_state |= PST_CASEPAT;
5325 #if defined (ALIAS)
5326           parser_state &= ~PST_ALEXPNEXT;
5327 #endif /* ALIAS */
5328           return (SEMI_AND);
5329         }
5330
5331       shell_ungetc (peek_char);
5332
5333       /* If we look like we are reading the start of a function
5334          definition, then let the reader know about it so that
5335          we will do the right thing with `{'. */
5336       if MBTEST(character == ')' && last_read_token == '(' && token_before_that == WORD)
5337         {
5338           parser_state |= PST_ALLOWOPNBRC;
5339 #if defined (ALIAS)
5340           parser_state &= ~PST_ALEXPNEXT;
5341 #endif /* ALIAS */
5342           function_dstart = line_number;
5343         }
5344
5345       /* case pattern lists may be preceded by an optional left paren.  If
5346          we're not trying to parse a case pattern list, the left paren
5347          indicates a subshell. */
5348       if MBTEST(character == '(' && (parser_state & PST_CASEPAT) == 0) /* ) */
5349         parser_state |= PST_SUBSHELL;
5350       /*(*/
5351       else if MBTEST((parser_state & PST_CASEPAT) && character == ')')
5352         parser_state &= ~PST_CASEPAT;
5353       /*(*/
5354       else if MBTEST((parser_state & PST_SUBSHELL) && character == ')')
5355         parser_state &= ~PST_SUBSHELL;
5356
5357 #if defined (PROCESS_SUBSTITUTION)
5358       /* Check for the constructs which introduce process substitution.
5359          Shells running in `posix mode' don't do process substitution. */
5360       if MBTEST(posixly_correct || ((character != '>' && character != '<') || peek_char != '(')) /*)*/
5361 #endif /* PROCESS_SUBSTITUTION */
5362         return (character);
5363     }
5364
5365   /* Hack <&- (close stdin) case.  Also <&N- (dup and close). */
5366   if MBTEST(character == '-' && (last_read_token == LESS_AND || last_read_token == GREATER_AND))
5367     return (character);
5368
5369 tokword:
5370   /* Okay, if we got this far, we have to read a word.  Read one,
5371      and then check it against the known ones. */
5372   result = read_token_word (character);
5373 #if defined (ALIAS)
5374   if (result == RE_READ_TOKEN)
5375     goto re_read_token;
5376 #endif
5377   return result;
5378 }
5379
5380 /*
5381  * Match a $(...) or other grouping construct.  This has to handle embedded
5382  * quoted strings ('', ``, "") and nested constructs.  It also must handle
5383  * reprompting the user, if necessary, after reading a newline, and returning
5384  * correct error values if it reads EOF.
5385  */
5386 #define P_FIRSTCLOSE    0x01
5387 #define P_ALLOWESC      0x02
5388 #define P_DQUOTE        0x04
5389 #define P_COMMAND       0x08    /* parsing a command, so look for comments */
5390 #define P_BACKQUOTE     0x10    /* parsing a backquoted command substitution */
5391 #define P_ARRAYSUB      0x20    /* parsing a [...] array subscript for assignment */
5392
5393 /* Lexical state while parsing a grouping construct or $(...). */
5394 #define LEX_WASDOL      0x001
5395 #define LEX_CKCOMMENT   0x002
5396 #define LEX_INCOMMENT   0x004
5397 #define LEX_PASSNEXT    0x008
5398 #define LEX_RESWDOK     0x010
5399 #define LEX_CKCASE      0x020
5400 #define LEX_INCASE      0x040
5401 #define LEX_INHEREDOC   0x080
5402 #define LEX_HEREDELIM   0x100           /* reading here-doc delimiter */
5403 #define LEX_STRIPDOC    0x200           /* <<- strip tabs from here doc delim */
5404 #define LEX_INWORD      0x400
5405
5406 #define COMSUB_META(ch)         ((ch) == ';' || (ch) == '&' || (ch) == '|')
5407
5408 #define CHECK_NESTRET_ERROR() \
5409   do { \
5410     if (nestret == &matched_pair_error) \
5411       { \
5412         free (ret); \
5413         return &matched_pair_error; \
5414       } \
5415   } while (0)
5416
5417 #define APPEND_NESTRET() \
5418   do { \
5419     if (nestlen) \
5420       { \
5421         RESIZE_MALLOCED_BUFFER (ret, retind, nestlen, retsize, 64); \
5422         strcpy (ret + retind, nestret); \
5423         retind += nestlen; \
5424       } \
5425   } while (0)
5426
5427 static char matched_pair_error;
5428
5429 static char *
5430 parse_matched_pair (qc, open, close, lenp, flags)
5431      int qc;    /* `"' if this construct is within double quotes */
5432      int open, close;
5433      int *lenp, flags;
5434 {
5435   int count, ch, tflags;
5436   int nestlen, ttranslen, start_lineno;
5437   char *ret, *nestret, *ttrans;
5438   int retind, retsize, rflags;
5439
5440 /*itrace("parse_matched_pair[%d]: open = %c close = %c flags = %d", line_number, open, close, flags);*/
5441   count = 1;
5442   tflags = 0;
5443
5444   if ((flags & P_COMMAND) && qc != '`' && qc != '\'' && qc != '"' && (flags & P_DQUOTE) == 0)
5445     tflags |= LEX_CKCOMMENT;
5446
5447   /* RFLAGS is the set of flags we want to pass to recursive calls. */
5448   rflags = (qc == '"') ? P_DQUOTE : (flags & P_DQUOTE);
5449
5450   ret = (char *)xmalloc (retsize = 64);
5451   retind = 0;
5452
5453   start_lineno = line_number;
5454   while (count)
5455     {
5456       ch = shell_getc (qc != '\'' && (tflags & LEX_PASSNEXT) == 0);
5457
5458       if (ch == EOF)
5459         {
5460           free (ret);
5461           parser_error (start_lineno, _("unexpected EOF while looking for matching `%c'"), close);
5462           EOF_Reached = 1;      /* XXX */
5463           return (&matched_pair_error);
5464         }
5465
5466       /* Possible reprompting. */
5467       if (ch == '\n' && SHOULD_PROMPT ())
5468         prompt_again ();
5469
5470       /* Don't bother counting parens or doing anything else if in a comment
5471          or part of a case statement */
5472       if (tflags & LEX_INCOMMENT)
5473         {
5474           /* Add this character. */
5475           RESIZE_MALLOCED_BUFFER (ret, retind, 1, retsize, 64);
5476           ret[retind++] = ch;
5477
5478           if (ch == '\n')
5479             tflags &= ~LEX_INCOMMENT;
5480
5481           continue;
5482         }
5483
5484       /* Not exactly right yet, should handle shell metacharacters, too.  If
5485          any changes are made to this test, make analogous changes to subst.c:
5486          extract_delimited_string(). */
5487       else if MBTEST((tflags & LEX_CKCOMMENT) && (tflags & LEX_INCOMMENT) == 0 && ch == '#' && (retind == 0 || ret[retind-1] == '\n' || shellblank (ret[retind - 1])))
5488         tflags |= LEX_INCOMMENT;
5489
5490       if (tflags & LEX_PASSNEXT)                /* last char was backslash */
5491         {
5492           tflags &= ~LEX_PASSNEXT;
5493           if (qc != '\'' && ch == '\n') /* double-quoted \<newline> disappears. */
5494             {
5495               if (retind > 0)
5496                 retind--;       /* swallow previously-added backslash */
5497               continue;
5498             }
5499
5500           RESIZE_MALLOCED_BUFFER (ret, retind, 2, retsize, 64);
5501           if MBTEST(ch == CTLESC || ch == CTLNUL)
5502             ret[retind++] = CTLESC;
5503           ret[retind++] = ch;
5504           continue;
5505         }
5506       /* If we're reparsing the input (e.g., from parse_string_to_word_list),
5507          we've already prepended CTLESC to single-quoted results of $'...'.
5508          We may want to do this for other CTLESC-quoted characters in
5509          reparse, too. */
5510       else if MBTEST((parser_state & PST_REPARSE) && open == '\'' && (ch == CTLESC || ch == CTLNUL))
5511         {
5512           RESIZE_MALLOCED_BUFFER (ret, retind, 1, retsize, 64);
5513           ret[retind++] = ch;
5514           continue;
5515         }
5516       else if MBTEST(ch == CTLESC || ch == CTLNUL)      /* special shell escapes */
5517         {
5518           RESIZE_MALLOCED_BUFFER (ret, retind, 2, retsize, 64);
5519           ret[retind++] = CTLESC;
5520           ret[retind++] = ch;
5521           continue;
5522         }
5523       else if MBTEST(ch == close)               /* ending delimiter */
5524         count--;
5525       /* handle nested ${...} specially. */
5526       else if MBTEST(open != close && (tflags & LEX_WASDOL) && open == '{' && ch == open) /* } */
5527         count++;
5528       else if MBTEST(((flags & P_FIRSTCLOSE) == 0) && ch == open)       /* nested begin */
5529         count++;
5530
5531       /* Add this character. */
5532       RESIZE_MALLOCED_BUFFER (ret, retind, 1, retsize, 64);
5533       ret[retind++] = ch;
5534
5535       /* If we just read the ending character, don't bother continuing. */
5536       if (count == 0)
5537         break;
5538
5539       if (open == '\'')                 /* '' inside grouping construct */
5540         {
5541           if MBTEST((flags & P_ALLOWESC) && ch == '\\')
5542             tflags |= LEX_PASSNEXT;
5543           continue;
5544         }
5545
5546       if MBTEST(ch == '\\')                     /* backslashes */
5547         tflags |= LEX_PASSNEXT;
5548
5549 #if 0
5550       /* The big hammer.  Single quotes aren't special in double quotes.  The
5551          problem is that Posix says the single quotes are semi-special:
5552          within a double-quoted ${...} construct "an even number of
5553          unescaped double-quotes or single-quotes, if any, shall occur." */
5554       if MBTEST(open == '{' && (flags & P_DQUOTE) && ch == '\'')        /* } */
5555         continue;
5556 #endif
5557
5558       /* Could also check open == '`' if we want to parse grouping constructs
5559          inside old-style command substitution. */
5560       if (open != close)                /* a grouping construct */
5561         {
5562           if MBTEST(shellquote (ch))
5563             {
5564               /* '', ``, or "" inside $(...) or other grouping construct. */
5565               push_delimiter (dstack, ch);
5566               if MBTEST((tflags & LEX_WASDOL) && ch == '\'')    /* $'...' inside group */
5567                 nestret = parse_matched_pair (ch, ch, ch, &nestlen, P_ALLOWESC|rflags);
5568               else
5569                 nestret = parse_matched_pair (ch, ch, ch, &nestlen, rflags);
5570               pop_delimiter (dstack);
5571               CHECK_NESTRET_ERROR ();
5572
5573               if MBTEST((tflags & LEX_WASDOL) && ch == '\'' && (extended_quote || (rflags & P_DQUOTE) == 0))
5574                 {
5575                   /* Translate $'...' here. */
5576                   ttrans = ansiexpand (nestret, 0, nestlen - 1, &ttranslen);
5577                   xfree (nestret);
5578
5579                   if ((rflags & P_DQUOTE) == 0)
5580                     {
5581                       nestret = sh_single_quote (ttrans);
5582                       free (ttrans);
5583                       nestlen = strlen (nestret);
5584                     }
5585                   else
5586                     {
5587                       nestret = ttrans;
5588                       nestlen = ttranslen;
5589                     }
5590                   retind -= 2;          /* back up before the $' */
5591                 }
5592               else if MBTEST((tflags & LEX_WASDOL) && ch == '"' && (extended_quote || (rflags & P_DQUOTE) == 0))
5593                 {
5594                   /* Locale expand $"..." here. */
5595                   ttrans = localeexpand (nestret, 0, nestlen - 1, start_lineno, &ttranslen);
5596                   xfree (nestret);
5597
5598                   nestret = sh_mkdoublequoted (ttrans, ttranslen, 0);
5599                   free (ttrans);
5600                   nestlen = ttranslen + 2;
5601                   retind -= 2;          /* back up before the $" */
5602                 }
5603
5604               APPEND_NESTRET ();
5605               FREE (nestret);
5606             }
5607           else if ((flags & P_ARRAYSUB) && (tflags & LEX_WASDOL) && (ch == '(' || ch == '{' || ch == '['))      /* ) } ] */
5608             goto parse_dollar_word;
5609         }
5610       /* Parse an old-style command substitution within double quotes as a
5611          single word. */
5612       /* XXX - sh and ksh93 don't do this - XXX */
5613       else if MBTEST(open == '"' && ch == '`')
5614         {
5615           nestret = parse_matched_pair (0, '`', '`', &nestlen, rflags);
5616
5617           CHECK_NESTRET_ERROR ();
5618           APPEND_NESTRET ();
5619
5620           FREE (nestret);
5621         }
5622       else if MBTEST(open != '`' && (tflags & LEX_WASDOL) && (ch == '(' || ch == '{' || ch == '['))     /* ) } ] */
5623         /* check for $(), $[], or ${} inside quoted string. */
5624         {
5625 parse_dollar_word:
5626           if (open == ch)       /* undo previous increment */
5627             count--;
5628           if (ch == '(')                /* ) */
5629             nestret = parse_comsub (0, '(', ')', &nestlen, (rflags|P_COMMAND) & ~P_DQUOTE);
5630           else if (ch == '{')           /* } */
5631             nestret = parse_matched_pair (0, '{', '}', &nestlen, P_FIRSTCLOSE|rflags);
5632           else if (ch == '[')           /* ] */
5633             nestret = parse_matched_pair (0, '[', ']', &nestlen, rflags);
5634
5635           CHECK_NESTRET_ERROR ();
5636           APPEND_NESTRET ();
5637
5638           FREE (nestret);
5639         }
5640       if MBTEST(ch == '$')
5641         tflags |= LEX_WASDOL;
5642       else
5643         tflags &= ~LEX_WASDOL;
5644     }
5645
5646   ret[retind] = '\0';
5647   if (lenp)
5648     *lenp = retind;
5649 /*itrace("parse_matched_pair[%d]: returning %s", line_number, ret);*/
5650   return ret;
5651 }
5652
5653 /* Parse a $(...) command substitution.  This is messier than I'd like, and
5654    reproduces a lot more of the token-reading code than I'd like. */
5655 static char *
5656 parse_comsub (qc, open, close, lenp, flags)
5657      int qc;    /* `"' if this construct is within double quotes */
5658      int open, close;
5659      int *lenp, flags;
5660 {
5661   int count, ch, peekc, tflags, lex_rwlen, lex_wlen, lex_firstind;
5662   int nestlen, ttranslen, start_lineno;
5663   char *ret, *nestret, *ttrans, *heredelim;
5664   int retind, retsize, rflags, hdlen;
5665
5666 /*itrace("parse_comsub: qc = `%c' open = %c close = %c", qc, open, close);*/
5667   count = 1;
5668   tflags = LEX_RESWDOK;
5669
5670   if ((flags & P_COMMAND) && qc != '\'' && qc != '"' && (flags & P_DQUOTE) == 0)
5671     tflags |= LEX_CKCASE;
5672   if ((tflags & LEX_CKCASE) && (interactive == 0 || interactive_comments))
5673     tflags |= LEX_CKCOMMENT;
5674
5675   /* RFLAGS is the set of flags we want to pass to recursive calls. */
5676   rflags = (flags & P_DQUOTE);
5677
5678   ret = (char *)xmalloc (retsize = 64);
5679   retind = 0;
5680
5681   start_lineno = line_number;
5682   lex_rwlen = lex_wlen = 0;
5683
5684   heredelim = 0;
5685   lex_firstind = -1;
5686
5687   while (count)
5688     {
5689 comsub_readchar:
5690       ch = shell_getc (qc != '\'' && (tflags & LEX_PASSNEXT) == 0);
5691
5692       if (ch == EOF)
5693         {
5694 eof_error:
5695           free (ret);
5696           FREE (heredelim);
5697           parser_error (start_lineno, _("unexpected EOF while looking for matching `%c'"), close);
5698           EOF_Reached = 1;      /* XXX */
5699           return (&matched_pair_error);
5700         }
5701
5702       /* If we hit the end of a line and are reading the contents of a here
5703          document, and it's not the same line that the document starts on,
5704          check for this line being the here doc delimiter.  Otherwise, if
5705          we're in a here document, mark the next character as the beginning
5706          of a line. */
5707       if (ch == '\n')
5708         {
5709           if ((tflags & LEX_HEREDELIM) && heredelim)
5710             {
5711               tflags &= ~LEX_HEREDELIM;
5712               tflags |= LEX_INHEREDOC;
5713               lex_firstind = retind + 1;
5714             }
5715           else if (tflags & LEX_INHEREDOC)
5716             {
5717               int tind;
5718               tind = lex_firstind;
5719               while ((tflags & LEX_STRIPDOC) && ret[tind] == '\t')
5720                 tind++;
5721               if (STREQN (ret + tind, heredelim, hdlen))
5722                 {
5723                   tflags &= ~(LEX_STRIPDOC|LEX_INHEREDOC);
5724 /*itrace("parse_comsub:%d: found here doc end `%s'", line_number, ret + tind);*/
5725                   free (heredelim);
5726                   heredelim = 0;
5727                   lex_firstind = -1;
5728                 }
5729               else
5730                 lex_firstind = retind + 1;
5731             }
5732         }
5733
5734       /* Possible reprompting. */
5735       if (ch == '\n' && SHOULD_PROMPT ())
5736         prompt_again ();
5737
5738       /* XXX -- possibly allow here doc to be delimited by ending right
5739          paren. */
5740       if ((tflags & LEX_INHEREDOC) && ch == close && count == 1)
5741         {
5742           int tind;
5743 /*itrace("parse_comsub: in here doc, ch == close, retind - firstind = %d hdlen = %d retind = %d", retind-lex_firstind, hdlen, retind);*/
5744           tind = lex_firstind;
5745           while ((tflags & LEX_STRIPDOC) && ret[tind] == '\t')
5746             tind++;
5747           if (retind-tind == hdlen && STREQN (ret + tind, heredelim, hdlen))
5748             {
5749               tflags &= ~(LEX_STRIPDOC|LEX_INHEREDOC);
5750 /*itrace("parse_comsub:%d: found here doc end `%s'", line_number, ret + tind);*/
5751               free (heredelim);
5752               heredelim = 0;
5753               lex_firstind = -1;
5754             }
5755         }
5756
5757       /* Don't bother counting parens or doing anything else if in a comment */
5758       if (tflags & (LEX_INCOMMENT|LEX_INHEREDOC))
5759         {
5760           /* Add this character. */
5761           RESIZE_MALLOCED_BUFFER (ret, retind, 1, retsize, 64);
5762           ret[retind++] = ch;
5763
5764           if ((tflags & LEX_INCOMMENT) && ch == '\n')
5765 {
5766 /*itrace("parse_comsub:%d: lex_incomment -> 0 ch = `%c'", line_number, ch);*/
5767             tflags &= ~LEX_INCOMMENT;
5768 }
5769
5770           continue;
5771         }
5772
5773       if (tflags & LEX_PASSNEXT)                /* last char was backslash */
5774         {
5775 /*itrace("parse_comsub:%d: lex_passnext -> 0 ch = `%c' (%d)", line_number, ch, __LINE__);*/
5776           tflags &= ~LEX_PASSNEXT;
5777           if (qc != '\'' && ch == '\n') /* double-quoted \<newline> disappears. */
5778             {
5779               if (retind > 0)
5780                 retind--;       /* swallow previously-added backslash */
5781               continue;
5782             }
5783
5784           RESIZE_MALLOCED_BUFFER (ret, retind, 2, retsize, 64);
5785           if MBTEST(ch == CTLESC || ch == CTLNUL)
5786             ret[retind++] = CTLESC;
5787           ret[retind++] = ch;
5788           continue;
5789         }
5790
5791       /* If this is a shell break character, we are not in a word.  If not,
5792          we either start or continue a word. */
5793       if MBTEST(shellbreak (ch))
5794         {
5795           tflags &= ~LEX_INWORD;
5796 /*itrace("parse_comsub:%d: lex_inword -> 0 ch = `%c' (%d)", line_number, ch, __LINE__);*/
5797         }
5798       else
5799         {
5800           if (tflags & LEX_INWORD)
5801             {
5802               lex_wlen++;
5803 /*itrace("parse_comsub:%d: lex_inword == 1 ch = `%c' lex_wlen = %d (%d)", line_number, ch, lex_wlen, __LINE__);*/
5804             }         
5805           else
5806             {
5807 /*itrace("parse_comsub:%d: lex_inword -> 1 ch = `%c' (%d)", line_number, ch, __LINE__);*/
5808               tflags |= LEX_INWORD;
5809               lex_wlen = 0;
5810             }
5811         }
5812
5813       /* Skip whitespace */
5814       if MBTEST(shellblank (ch) && lex_rwlen == 0)
5815         {
5816           /* Add this character. */
5817           RESIZE_MALLOCED_BUFFER (ret, retind, 1, retsize, 64);
5818           ret[retind++] = ch;
5819           continue;
5820         }
5821
5822       /* Either we are looking for the start of the here-doc delimiter
5823          (lex_firstind == -1) or we are reading one (lex_firstind >= 0).
5824          If this character is a shell break character and we are reading
5825          the delimiter, save it and note that we are now reading a here
5826          document.  If we've found the start of the delimiter, note it by
5827          setting lex_firstind.  Backslashes can quote shell metacharacters
5828          in here-doc delimiters. */
5829       if (tflags & LEX_HEREDELIM)
5830         {
5831           if (lex_firstind == -1 && shellbreak (ch) == 0)
5832             lex_firstind = retind;
5833 #if 0
5834           else if (heredelim && (tflags & LEX_PASSNEXT) == 0 && ch == '\n')
5835             {
5836               tflags |= LEX_INHEREDOC;
5837               tflags &= ~LEX_HEREDELIM;
5838               lex_firstind = retind + 1;
5839             }
5840 #endif
5841           else if (lex_firstind >= 0 && (tflags & LEX_PASSNEXT) == 0 && shellbreak (ch))
5842             {
5843               if (heredelim == 0)
5844                 {
5845                   nestret = substring (ret, lex_firstind, retind);
5846                   heredelim = string_quote_removal (nestret, 0);
5847                   free (nestret);
5848                   hdlen = STRLEN(heredelim);
5849 /*itrace("parse_comsub:%d: found here doc delimiter `%s' (%d)", line_number, heredelim, hdlen);*/
5850                 }
5851               if (ch == '\n')
5852                 {
5853                   tflags |= LEX_INHEREDOC;
5854                   tflags &= ~LEX_HEREDELIM;
5855                   lex_firstind = retind + 1;
5856                 }
5857               else
5858                 lex_firstind = -1;
5859             }
5860         }
5861
5862       /* Meta-characters that can introduce a reserved word.  Not perfect yet. */
5863       if MBTEST((tflags & LEX_RESWDOK) == 0 && (tflags & LEX_CKCASE) && (tflags & LEX_INCOMMENT) == 0 && (shellmeta(ch) || ch == '\n'))
5864         {
5865           /* Add this character. */
5866           RESIZE_MALLOCED_BUFFER (ret, retind, 1, retsize, 64);
5867           ret[retind++] = ch;
5868           peekc = shell_getc (1);
5869           if (ch == peekc && (ch == '&' || ch == '|' || ch == ';'))     /* two-character tokens */
5870             {
5871               RESIZE_MALLOCED_BUFFER (ret, retind, 1, retsize, 64);
5872               ret[retind++] = peekc;
5873 /*itrace("parse_comsub:%d: set lex_reswordok = 1, ch = `%c'", line_number, ch);*/
5874               tflags |= LEX_RESWDOK;
5875               lex_rwlen = 0;
5876               continue;
5877             }
5878           else if (ch == '\n' || COMSUB_META(ch))
5879             {
5880               shell_ungetc (peekc);
5881 /*itrace("parse_comsub:%d: set lex_reswordok = 1, ch = `%c'", line_number, ch);*/
5882               tflags |= LEX_RESWDOK;
5883               lex_rwlen = 0;
5884               continue;
5885             }
5886           else if (ch == EOF)
5887             goto eof_error;
5888           else
5889             {
5890               /* `unget' the character we just added and fall through */
5891               retind--;
5892               shell_ungetc (peekc);
5893             }
5894         }
5895
5896       /* If we can read a reserved word, try to read one. */
5897       if (tflags & LEX_RESWDOK)
5898         {
5899           if MBTEST(islower (ch))
5900             {
5901               /* Add this character. */
5902               RESIZE_MALLOCED_BUFFER (ret, retind, 1, retsize, 64);
5903               ret[retind++] = ch;
5904               lex_rwlen++;
5905               continue;
5906             }
5907           else if MBTEST(lex_rwlen == 4 && shellbreak (ch))
5908             {
5909               if (STREQN (ret + retind - 4, "case", 4))
5910 {
5911                 tflags |= LEX_INCASE;
5912 /*itrace("parse_comsub:%d: found `case', lex_incase -> 1 lex_reswdok -> 0", line_number);*/
5913 }
5914               else if (STREQN (ret + retind - 4, "esac", 4))
5915 {
5916                 tflags &= ~LEX_INCASE;
5917 /*itrace("parse_comsub:%d: found `esac', lex_incase -> 0 lex_reswdok -> 0", line_number);*/
5918 }               
5919               tflags &= ~LEX_RESWDOK;
5920             }
5921           else if MBTEST((tflags & LEX_CKCOMMENT) && ch == '#' && (lex_rwlen == 0 || ((tflags & LEX_INWORD) && lex_wlen == 0)))
5922             ;   /* don't modify LEX_RESWDOK if we're starting a comment */
5923           else if MBTEST((tflags & LEX_INCASE) && ch != '\n')
5924             /* If we can read a reserved word and we're in case, we're at the
5925                point where we can read a new pattern list or an esac.  We
5926                handle the esac case above.  If we read a newline, we want to
5927                leave LEX_RESWDOK alone.  If we read anything else, we want to
5928                turn off LEX_RESWDOK, since we're going to read a pattern list. */
5929 {
5930             tflags &= ~LEX_RESWDOK;
5931 /*itrace("parse_comsub:%d: lex_incase == 1 found `%c', lex_reswordok -> 0", line_number, ch);*/
5932 }
5933           else if MBTEST(shellbreak (ch) == 0)
5934 {
5935             tflags &= ~LEX_RESWDOK;
5936 /*itrace("parse_comsub:%d: found `%c', lex_reswordok -> 0", line_number, ch);*/
5937 }
5938         }
5939
5940       /* Might be the start of a here-doc delimiter */
5941       if MBTEST((tflags & LEX_INCOMMENT) == 0 && (tflags & LEX_CKCASE) && ch == '<')
5942         {
5943           /* Add this character. */
5944           RESIZE_MALLOCED_BUFFER (ret, retind, 1, retsize, 64);
5945           ret[retind++] = ch;
5946           peekc = shell_getc (1);
5947           if (peekc == EOF)
5948             goto eof_error;
5949           if (peekc == ch)
5950             {
5951               RESIZE_MALLOCED_BUFFER (ret, retind, 1, retsize, 64);
5952               ret[retind++] = peekc;
5953               peekc = shell_getc (1);
5954               if (peekc == EOF)
5955                 goto eof_error;
5956               if (peekc == '-')
5957                 {
5958                   RESIZE_MALLOCED_BUFFER (ret, retind, 1, retsize, 64);
5959                   ret[retind++] = peekc;
5960                   tflags |= LEX_STRIPDOC;
5961                 }
5962               else
5963                 shell_ungetc (peekc);
5964               if (peekc != '<')
5965                 {
5966                   tflags |= LEX_HEREDELIM;
5967                   lex_firstind = -1;
5968                 }
5969               continue;
5970             }
5971           else
5972             ch = peekc;         /* fall through and continue XXX */
5973         }
5974       else if MBTEST((tflags & LEX_CKCOMMENT) && (tflags & LEX_INCOMMENT) == 0 && ch == '#' && (((tflags & LEX_RESWDOK) && lex_rwlen == 0) || ((tflags & LEX_INWORD) && lex_wlen == 0)))
5975 {
5976 /*itrace("parse_comsub:%d: lex_incomment -> 1 (%d)", line_number, __LINE__);*/
5977         tflags |= LEX_INCOMMENT;
5978 }
5979
5980       if MBTEST(ch == CTLESC || ch == CTLNUL)   /* special shell escapes */
5981         {
5982           RESIZE_MALLOCED_BUFFER (ret, retind, 2, retsize, 64);
5983           ret[retind++] = CTLESC;
5984           ret[retind++] = ch;
5985           continue;
5986         }
5987 #if 0
5988       else if MBTEST((tflags & LEX_INCASE) && ch == close && close == ')')
5989         tflags &= ~LEX_INCASE;          /* XXX */
5990 #endif
5991       else if MBTEST(ch == close && (tflags & LEX_INCASE) == 0)         /* ending delimiter */
5992 {
5993         count--;
5994 /*itrace("parse_comsub:%d: found close: count = %d", line_number, count);*/
5995 }
5996       else if MBTEST(((flags & P_FIRSTCLOSE) == 0) && (tflags & LEX_INCASE) == 0 && ch == open) /* nested begin */
5997 {
5998         count++;
5999 /*itrace("parse_comsub:%d: found open: count = %d", line_number, count);*/
6000 }
6001
6002       /* Add this character. */
6003       RESIZE_MALLOCED_BUFFER (ret, retind, 1, retsize, 64);
6004       ret[retind++] = ch;
6005
6006       /* If we just read the ending character, don't bother continuing. */
6007       if (count == 0)
6008         break;
6009
6010       if MBTEST(ch == '\\')                     /* backslashes */
6011         tflags |= LEX_PASSNEXT;
6012
6013       if MBTEST(shellquote (ch))
6014         {
6015           /* '', ``, or "" inside $(...). */
6016           push_delimiter (dstack, ch);
6017           if MBTEST((tflags & LEX_WASDOL) && ch == '\'')        /* $'...' inside group */
6018             nestret = parse_matched_pair (ch, ch, ch, &nestlen, P_ALLOWESC|rflags);
6019           else
6020             nestret = parse_matched_pair (ch, ch, ch, &nestlen, rflags);
6021           pop_delimiter (dstack);
6022           CHECK_NESTRET_ERROR ();
6023
6024           if MBTEST((tflags & LEX_WASDOL) && ch == '\'' && (extended_quote || (rflags & P_DQUOTE) == 0))
6025             {
6026               /* Translate $'...' here. */
6027               ttrans = ansiexpand (nestret, 0, nestlen - 1, &ttranslen);
6028               xfree (nestret);
6029
6030               if ((rflags & P_DQUOTE) == 0)
6031                 {
6032                   nestret = sh_single_quote (ttrans);
6033                   free (ttrans);
6034                   nestlen = strlen (nestret);
6035                 }
6036               else
6037                 {
6038                   nestret = ttrans;
6039                   nestlen = ttranslen;
6040                 }
6041               retind -= 2;              /* back up before the $' */
6042             }
6043           else if MBTEST((tflags & LEX_WASDOL) && ch == '"' && (extended_quote || (rflags & P_DQUOTE) == 0))
6044             {
6045               /* Locale expand $"..." here. */
6046               ttrans = localeexpand (nestret, 0, nestlen - 1, start_lineno, &ttranslen);
6047               xfree (nestret);
6048
6049               nestret = sh_mkdoublequoted (ttrans, ttranslen, 0);
6050               free (ttrans);
6051               nestlen = ttranslen + 2;
6052               retind -= 2;              /* back up before the $" */
6053             }
6054
6055           APPEND_NESTRET ();
6056           FREE (nestret);
6057         }
6058       else if MBTEST((tflags & LEX_WASDOL) && (ch == '(' || ch == '{' || ch == '['))    /* ) } ] */
6059         /* check for $(), $[], or ${} inside command substitution. */
6060         {
6061           if ((tflags & LEX_INCASE) == 0 && open == ch) /* undo previous increment */
6062             count--;
6063           if (ch == '(')                /* ) */
6064             nestret = parse_comsub (0, '(', ')', &nestlen, (rflags|P_COMMAND) & ~P_DQUOTE);
6065           else if (ch == '{')           /* } */
6066             nestret = parse_matched_pair (0, '{', '}', &nestlen, P_FIRSTCLOSE|rflags);
6067           else if (ch == '[')           /* ] */
6068             nestret = parse_matched_pair (0, '[', ']', &nestlen, rflags);
6069
6070           CHECK_NESTRET_ERROR ();
6071           APPEND_NESTRET ();
6072
6073           FREE (nestret);
6074         }
6075       if MBTEST(ch == '$')
6076         tflags |= LEX_WASDOL;
6077       else
6078         tflags &= ~LEX_WASDOL;
6079     }
6080
6081   FREE (heredelim);
6082   ret[retind] = '\0';
6083   if (lenp)
6084     *lenp = retind;
6085 /*itrace("parse_comsub:%d: returning `%s'", line_number, ret);*/
6086   return ret;
6087 }
6088
6089 /* XXX - this needs to handle functionality like subst.c:no_longjmp_on_fatal_error;
6090    maybe extract_command_subst should handle it. */
6091 char *
6092 xparse_dolparen (base, string, indp, flags)
6093      char *base;
6094      char *string;
6095      int *indp;
6096      int flags;
6097 {
6098   sh_parser_state_t ps;
6099   int orig_ind, nc, sflags;
6100   char *ret, *s, *ep, *ostring;
6101
6102   /*yydebug = 1;*/
6103   orig_ind = *indp;
6104   ostring = string;
6105
6106   sflags = SEVAL_NONINT|SEVAL_NOHIST|SEVAL_NOFREE;
6107   if (flags & SX_NOLONGJMP)
6108     sflags |= SEVAL_NOLONGJMP;
6109   save_parser_state (&ps);
6110
6111   /*(*/
6112   parser_state |= PST_CMDSUBST|PST_EOFTOKEN;    /* allow instant ')' */ /*(*/
6113   shell_eof_token = ')';
6114   parse_string (string, "command substitution", sflags, &ep);
6115
6116   restore_parser_state (&ps);
6117   reset_parser ();
6118   if (interactive)
6119     token_to_read = 0;
6120
6121   /* Need to find how many characters parse_and_execute consumed, update
6122      *indp, if flags != 0, copy the portion of the string parsed into RET
6123      and return it.  If flags & 1 (EX_NOALLOC) we can return NULL. */
6124
6125   /*(*/
6126   if (ep[-1] != ')')
6127     {
6128 #if DEBUG
6129       if (ep[-1] != '\n')
6130         itrace("xparse_dolparen:%d: ep[-1] != RPAREN (%d), ep = `%s'", line_number, ep[-1], ep);
6131 #endif
6132       while (ep > ostring && ep[-1] == '\n') ep--;
6133     }
6134
6135   nc = ep - ostring;
6136   *indp = ep - base - 1;
6137
6138   /*(*/
6139 #if DEBUG
6140   if (base[*indp] != ')')
6141     itrace("xparse_dolparen:%d: base[%d] != RPAREN (%d), base = `%s'", line_number, *indp, base[*indp], base);
6142 #endif
6143
6144   if (flags & SX_NOALLOC) 
6145     return (char *)NULL;
6146
6147   if (nc == 0)
6148     {
6149       ret = xmalloc (1);
6150       ret[0] = '\0';
6151     }
6152   else
6153     ret = substring (ostring, 0, nc - 1);
6154
6155   return ret;
6156 }
6157
6158 #if defined (DPAREN_ARITHMETIC) || defined (ARITH_FOR_COMMAND)
6159 /* Parse a double-paren construct.  It can be either an arithmetic
6160    command, an arithmetic `for' command, or a nested subshell.  Returns
6161    the parsed token, -1 on error, or -2 if we didn't do anything and
6162    should just go on. */
6163 static int
6164 parse_dparen (c)
6165      int c;
6166 {
6167   int cmdtyp, sline;
6168   char *wval;
6169   WORD_DESC *wd;
6170
6171 #if defined (ARITH_FOR_COMMAND)
6172   if (last_read_token == FOR)
6173     {
6174       arith_for_lineno = line_number;
6175       cmdtyp = parse_arith_cmd (&wval, 0);
6176       if (cmdtyp == 1)
6177         {
6178           wd = alloc_word_desc ();
6179           wd->word = wval;
6180           yylval.word_list = make_word_list (wd, (WORD_LIST *)NULL);
6181           return (ARITH_FOR_EXPRS);
6182         }
6183       else
6184         return -1;              /* ERROR */
6185     }
6186 #endif
6187
6188 #if defined (DPAREN_ARITHMETIC)
6189   if (reserved_word_acceptable (last_read_token))
6190     {
6191       sline = line_number;
6192
6193       cmdtyp = parse_arith_cmd (&wval, 0);
6194       if (cmdtyp == 1)  /* arithmetic command */
6195         {
6196           wd = alloc_word_desc ();
6197           wd->word = wval;
6198           wd->flags = W_QUOTED|W_NOSPLIT|W_NOGLOB|W_DQUOTE;
6199           yylval.word_list = make_word_list (wd, (WORD_LIST *)NULL);
6200           return (ARITH_CMD);
6201         }
6202       else if (cmdtyp == 0)     /* nested subshell */
6203         {
6204           push_string (wval, 0, (alias_t *)NULL);
6205           if ((parser_state & PST_CASEPAT) == 0)
6206             parser_state |= PST_SUBSHELL;
6207           return (c);
6208         }
6209       else                      /* ERROR */
6210         return -1;
6211     }
6212 #endif
6213
6214   return -2;                    /* XXX */
6215 }
6216
6217 /* We've seen a `(('.  Look for the matching `))'.  If we get it, return 1.
6218    If not, assume it's a nested subshell for backwards compatibility and
6219    return 0.  In any case, put the characters we've consumed into a locally-
6220    allocated buffer and make *ep point to that buffer.  Return -1 on an
6221    error, for example EOF. */
6222 static int
6223 parse_arith_cmd (ep, adddq)
6224      char **ep;
6225      int adddq;
6226 {
6227   int exp_lineno, rval, c;
6228   char *ttok, *tokstr;
6229   int ttoklen;
6230
6231   exp_lineno = line_number;
6232   ttok = parse_matched_pair (0, '(', ')', &ttoklen, 0);
6233   rval = 1;
6234   if (ttok == &matched_pair_error)
6235     return -1;
6236   /* Check that the next character is the closing right paren.  If
6237      not, this is a syntax error. ( */
6238   c = shell_getc (0);
6239   if MBTEST(c != ')')
6240     rval = 0;
6241
6242   tokstr = (char *)xmalloc (ttoklen + 4);
6243
6244   /* if ADDDQ != 0 then (( ... )) -> "..." */
6245   if (rval == 1 && adddq)       /* arith cmd, add double quotes */
6246     {
6247       tokstr[0] = '"';
6248       strncpy (tokstr + 1, ttok, ttoklen - 1);
6249       tokstr[ttoklen] = '"';
6250       tokstr[ttoklen+1] = '\0';
6251     }
6252   else if (rval == 1)           /* arith cmd, don't add double quotes */
6253     {
6254       strncpy (tokstr, ttok, ttoklen - 1);
6255       tokstr[ttoklen-1] = '\0';
6256     }
6257   else                          /* nested subshell */
6258     {
6259       tokstr[0] = '(';
6260       strncpy (tokstr + 1, ttok, ttoklen - 1);
6261       tokstr[ttoklen] = ')';
6262       tokstr[ttoklen+1] = c;
6263       tokstr[ttoklen+2] = '\0';
6264     }
6265
6266   *ep = tokstr;
6267   FREE (ttok);
6268   return rval;
6269 }
6270 #endif /* DPAREN_ARITHMETIC || ARITH_FOR_COMMAND */
6271
6272 #if defined (COND_COMMAND)
6273 static void
6274 cond_error ()
6275 {
6276   char *etext;
6277
6278   if (EOF_Reached && cond_token != COND_ERROR)          /* [[ */
6279     parser_error (cond_lineno, _("unexpected EOF while looking for `]]'"));
6280   else if (cond_token != COND_ERROR)
6281     {
6282       if (etext = error_token_from_token (cond_token))
6283         {
6284           parser_error (cond_lineno, _("syntax error in conditional expression: unexpected token `%s'"), etext);
6285           free (etext);
6286         }
6287       else
6288         parser_error (cond_lineno, _("syntax error in conditional expression"));
6289     }
6290 }
6291
6292 static COND_COM *
6293 cond_expr ()
6294 {
6295   return (cond_or ());  
6296 }
6297
6298 static COND_COM *
6299 cond_or ()
6300 {
6301   COND_COM *l, *r;
6302
6303   l = cond_and ();
6304   if (cond_token == OR_OR)
6305     {
6306       r = cond_or ();
6307       l = make_cond_node (COND_OR, (WORD_DESC *)NULL, l, r);
6308     }
6309   return l;
6310 }
6311
6312 static COND_COM *
6313 cond_and ()
6314 {
6315   COND_COM *l, *r;
6316
6317   l = cond_term ();
6318   if (cond_token == AND_AND)
6319     {
6320       r = cond_and ();
6321       l = make_cond_node (COND_AND, (WORD_DESC *)NULL, l, r);
6322     }
6323   return l;
6324 }
6325
6326 static int
6327 cond_skip_newlines ()
6328 {
6329   while ((cond_token = read_token (READ)) == '\n')
6330     {
6331       if (SHOULD_PROMPT ())
6332         prompt_again ();
6333     }
6334   return (cond_token);
6335 }
6336
6337 #define COND_RETURN_ERROR() \
6338   do { cond_token = COND_ERROR; return ((COND_COM *)NULL); } while (0)
6339
6340 static COND_COM *
6341 cond_term ()
6342 {
6343   WORD_DESC *op;
6344   COND_COM *term, *tleft, *tright;
6345   int tok, lineno;
6346   char *etext;
6347
6348   /* Read a token.  It can be a left paren, a `!', a unary operator, or a
6349      word that should be the first argument of a binary operator.  Start by
6350      skipping newlines, since this is a compound command. */
6351   tok = cond_skip_newlines ();
6352   lineno = line_number;
6353   if (tok == COND_END)
6354     {
6355       COND_RETURN_ERROR ();
6356     }
6357   else if (tok == '(')
6358     {
6359       term = cond_expr ();
6360       if (cond_token != ')')
6361         {
6362           if (term)
6363             dispose_cond_node (term);           /* ( */
6364           if (etext = error_token_from_token (cond_token))
6365             {
6366               parser_error (lineno, _("unexpected token `%s', expected `)'"), etext);
6367               free (etext);
6368             }
6369           else
6370             parser_error (lineno, _("expected `)'"));
6371           COND_RETURN_ERROR ();
6372         }
6373       term = make_cond_node (COND_EXPR, (WORD_DESC *)NULL, term, (COND_COM *)NULL);
6374       (void)cond_skip_newlines ();
6375     }
6376   else if (tok == BANG || (tok == WORD && (yylval.word->word[0] == '!' && yylval.word->word[1] == '\0')))
6377     {
6378       if (tok == WORD)
6379         dispose_word (yylval.word);     /* not needed */
6380       term = cond_term ();
6381       if (term)
6382         term->flags |= CMD_INVERT_RETURN;
6383     }
6384   else if (tok == WORD && yylval.word->word[0] == '-' && yylval.word->word[2] == 0 && test_unop (yylval.word->word))
6385     {
6386       op = yylval.word;
6387       tok = read_token (READ);
6388       if (tok == WORD)
6389         {
6390           tleft = make_cond_node (COND_TERM, yylval.word, (COND_COM *)NULL, (COND_COM *)NULL);
6391           term = make_cond_node (COND_UNARY, op, tleft, (COND_COM *)NULL);
6392         }
6393       else
6394         {
6395           dispose_word (op);
6396           if (etext = error_token_from_token (tok))
6397             {
6398               parser_error (line_number, _("unexpected argument `%s' to conditional unary operator"), etext);
6399               free (etext);
6400             }
6401           else
6402             parser_error (line_number, _("unexpected argument to conditional unary operator"));
6403           COND_RETURN_ERROR ();
6404         }
6405
6406       (void)cond_skip_newlines ();
6407     }
6408   else if (tok == WORD)         /* left argument to binary operator */
6409     {
6410       /* lhs */
6411       tleft = make_cond_node (COND_TERM, yylval.word, (COND_COM *)NULL, (COND_COM *)NULL);
6412
6413       /* binop */
6414       tok = read_token (READ);
6415       if (tok == WORD && test_binop (yylval.word->word))
6416         {
6417           op = yylval.word;
6418           if (op->word[0] == '=' && (op->word[1] == '\0' || (op->word[1] == '=' && op->word[2] == '\0')))
6419             parser_state |= PST_EXTPAT;
6420           else if (op->word[0] == '!' && op->word[1] == '=' && op->word[2] == '\0')
6421             parser_state |= PST_EXTPAT;
6422         }
6423 #if defined (COND_REGEXP)
6424       else if (tok == WORD && STREQ (yylval.word->word, "=~"))
6425         {
6426           op = yylval.word;
6427           parser_state |= PST_REGEXP;
6428         }
6429 #endif
6430       else if (tok == '<' || tok == '>')
6431         op = make_word_from_token (tok);  /* ( */
6432       /* There should be a check before blindly accepting the `)' that we have
6433          seen the opening `('. */
6434       else if (tok == COND_END || tok == AND_AND || tok == OR_OR || tok == ')')
6435         {
6436           /* Special case.  [[ x ]] is equivalent to [[ -n x ]], just like
6437              the test command.  Similarly for [[ x && expr ]] or
6438              [[ x || expr ]] or [[ (x) ]]. */
6439           op = make_word ("-n");
6440           term = make_cond_node (COND_UNARY, op, tleft, (COND_COM *)NULL);
6441           cond_token = tok;
6442           return (term);
6443         }
6444       else
6445         {
6446           if (etext = error_token_from_token (tok))
6447             {
6448               parser_error (line_number, _("unexpected token `%s', conditional binary operator expected"), etext);
6449               free (etext);
6450             }
6451           else
6452             parser_error (line_number, _("conditional binary operator expected"));
6453           dispose_cond_node (tleft);
6454           COND_RETURN_ERROR ();
6455         }
6456
6457       /* rhs */
6458       if (parser_state & PST_EXTPAT)
6459         extended_glob = 1;
6460       tok = read_token (READ);
6461       if (parser_state & PST_EXTPAT)
6462         extended_glob = global_extglob;
6463       parser_state &= ~(PST_REGEXP|PST_EXTPAT);
6464
6465       if (tok == WORD)
6466         {
6467           tright = make_cond_node (COND_TERM, yylval.word, (COND_COM *)NULL, (COND_COM *)NULL);
6468           term = make_cond_node (COND_BINARY, op, tleft, tright);
6469         }
6470       else
6471         {
6472           if (etext = error_token_from_token (tok))
6473             {
6474               parser_error (line_number, _("unexpected argument `%s' to conditional binary operator"), etext);
6475               free (etext);
6476             }
6477           else
6478             parser_error (line_number, _("unexpected argument to conditional binary operator"));
6479           dispose_cond_node (tleft);
6480           dispose_word (op);
6481           COND_RETURN_ERROR ();
6482         }
6483
6484       (void)cond_skip_newlines ();
6485     }
6486   else
6487     {
6488       if (tok < 256)
6489         parser_error (line_number, _("unexpected token `%c' in conditional command"), tok);
6490       else if (etext = error_token_from_token (tok))
6491         {
6492           parser_error (line_number, _("unexpected token `%s' in conditional command"), etext);
6493           free (etext);
6494         }
6495       else
6496         parser_error (line_number, _("unexpected token %d in conditional command"), tok);
6497       COND_RETURN_ERROR ();
6498     }
6499   return (term);
6500 }      
6501
6502 /* This is kind of bogus -- we slip a mini recursive-descent parser in
6503    here to handle the conditional statement syntax. */
6504 static COMMAND *
6505 parse_cond_command ()
6506 {
6507   COND_COM *cexp;
6508
6509   global_extglob = extended_glob;
6510   cexp = cond_expr ();
6511   return (make_cond_command (cexp));
6512 }
6513 #endif
6514
6515 #if defined (ARRAY_VARS)
6516 /* When this is called, it's guaranteed that we don't care about anything
6517    in t beyond i.  We do save and restore the chars, though. */
6518 static int
6519 token_is_assignment (t, i)
6520      char *t;
6521      int i;
6522 {
6523   unsigned char c, c1;
6524   int r;
6525
6526   c = t[i]; c1 = t[i+1];
6527   t[i] = '='; t[i+1] = '\0';
6528   r = assignment (t, (parser_state & PST_COMPASSIGN) != 0);
6529   t[i] = c; t[i+1] = c1;
6530   return r;
6531 }
6532
6533 /* XXX - possible changes here for `+=' */
6534 static int
6535 token_is_ident (t, i)
6536      char *t;
6537      int i;
6538 {
6539   unsigned char c;
6540   int r;
6541
6542   c = t[i];
6543   t[i] = '\0';
6544   r = legal_identifier (t);
6545   t[i] = c;
6546   return r;
6547 }
6548 #endif
6549
6550 static int
6551 read_token_word (character)
6552      int character;
6553 {
6554   /* The value for YYLVAL when a WORD is read. */
6555   WORD_DESC *the_word;
6556
6557   /* Index into the token that we are building. */
6558   int token_index;
6559
6560   /* ALL_DIGITS becomes zero when we see a non-digit. */
6561   int all_digit_token;
6562
6563   /* DOLLAR_PRESENT becomes non-zero if we see a `$'. */
6564   int dollar_present;
6565
6566   /* COMPOUND_ASSIGNMENT becomes non-zero if we are parsing a compound
6567      assignment. */
6568   int compound_assignment;
6569
6570   /* QUOTED becomes non-zero if we see one of ("), ('), (`), or (\). */
6571   int quoted;
6572
6573   /* Non-zero means to ignore the value of the next character, and just
6574      to add it no matter what. */
6575  int pass_next_character;
6576
6577   /* The current delimiting character. */
6578   int cd;
6579   int result, peek_char;
6580   char *ttok, *ttrans;
6581   int ttoklen, ttranslen;
6582   intmax_t lvalue;
6583
6584   if (token_buffer_size < TOKEN_DEFAULT_INITIAL_SIZE)
6585     token = (char *)xrealloc (token, token_buffer_size = TOKEN_DEFAULT_INITIAL_SIZE);
6586
6587   token_index = 0;
6588   all_digit_token = DIGIT (character);
6589   dollar_present = quoted = pass_next_character = compound_assignment = 0;
6590
6591   for (;;)
6592     {
6593       if (character == EOF)
6594         goto got_token;
6595
6596       if (pass_next_character)
6597         {
6598           pass_next_character = 0;
6599           goto got_escaped_character;
6600         }
6601
6602       cd = current_delimiter (dstack);
6603
6604       /* Handle backslashes.  Quote lots of things when not inside of
6605          double-quotes, quote some things inside of double-quotes. */
6606       if MBTEST(character == '\\')
6607         {
6608           peek_char = shell_getc (0);
6609
6610           /* Backslash-newline is ignored in all cases except
6611              when quoted with single quotes. */
6612           if (peek_char == '\n')
6613             {
6614               character = '\n';
6615               goto next_character;
6616             }
6617           else
6618             {
6619               shell_ungetc (peek_char);
6620
6621               /* If the next character is to be quoted, note it now. */
6622               if (cd == 0 || cd == '`' ||
6623                   (cd == '"' && peek_char >= 0 && (sh_syntaxtab[peek_char] & CBSDQUOTE)))
6624                 pass_next_character++;
6625
6626               quoted = 1;
6627               goto got_character;
6628             }
6629         }
6630
6631       /* Parse a matched pair of quote characters. */
6632       if MBTEST(shellquote (character))
6633         {
6634           push_delimiter (dstack, character);
6635           ttok = parse_matched_pair (character, character, character, &ttoklen, (character == '`') ? P_COMMAND : 0);
6636           pop_delimiter (dstack);
6637           if (ttok == &matched_pair_error)
6638             return -1;          /* Bail immediately. */
6639           RESIZE_MALLOCED_BUFFER (token, token_index, ttoklen + 2,
6640                                   token_buffer_size, TOKEN_DEFAULT_GROW_SIZE);
6641           token[token_index++] = character;
6642           strcpy (token + token_index, ttok);
6643           token_index += ttoklen;
6644           all_digit_token = 0;
6645           quoted = 1;
6646           dollar_present |= (character == '"' && strchr (ttok, '$') != 0);
6647           FREE (ttok);
6648           goto next_character;
6649         }
6650
6651 #ifdef COND_REGEXP
6652       /* When parsing a regexp as a single word inside a conditional command,
6653          we need to special-case characters special to both the shell and
6654          regular expressions.  Right now, that is only '(' and '|'. */ /*)*/
6655       if MBTEST((parser_state & PST_REGEXP) && (character == '(' || character == '|'))          /*)*/
6656         {
6657           if (character == '|')
6658             goto got_character;
6659
6660           push_delimiter (dstack, character);
6661           ttok = parse_matched_pair (cd, '(', ')', &ttoklen, 0);
6662           pop_delimiter (dstack);
6663           if (ttok == &matched_pair_error)
6664             return -1;          /* Bail immediately. */
6665           RESIZE_MALLOCED_BUFFER (token, token_index, ttoklen + 2,
6666                                   token_buffer_size, TOKEN_DEFAULT_GROW_SIZE);
6667           token[token_index++] = character;
6668           strcpy (token + token_index, ttok);
6669           token_index += ttoklen;
6670           FREE (ttok);
6671           dollar_present = all_digit_token = 0;
6672           goto next_character;
6673         }
6674 #endif /* COND_REGEXP */
6675
6676 #ifdef EXTENDED_GLOB
6677       /* Parse a ksh-style extended pattern matching specification. */
6678       if MBTEST(extended_glob && PATTERN_CHAR (character))
6679         {
6680           peek_char = shell_getc (1);
6681           if MBTEST(peek_char == '(')           /* ) */
6682             {
6683               push_delimiter (dstack, peek_char);
6684               ttok = parse_matched_pair (cd, '(', ')', &ttoklen, 0);
6685               pop_delimiter (dstack);
6686               if (ttok == &matched_pair_error)
6687                 return -1;              /* Bail immediately. */
6688               RESIZE_MALLOCED_BUFFER (token, token_index, ttoklen + 2,
6689                                       token_buffer_size,
6690                                       TOKEN_DEFAULT_GROW_SIZE);
6691               token[token_index++] = character;
6692               token[token_index++] = peek_char;
6693               strcpy (token + token_index, ttok);
6694               token_index += ttoklen;
6695               FREE (ttok);
6696               dollar_present = all_digit_token = 0;
6697               goto next_character;
6698             }
6699           else
6700             shell_ungetc (peek_char);
6701         }
6702 #endif /* EXTENDED_GLOB */
6703
6704       /* If the delimiter character is not single quote, parse some of
6705          the shell expansions that must be read as a single word. */
6706       if (shellexp (character))
6707         {
6708           peek_char = shell_getc (1);
6709           /* $(...), <(...), >(...), $((...)), ${...}, and $[...] constructs */
6710           if MBTEST(peek_char == '(' || \
6711                 ((peek_char == '{' || peek_char == '[') && character == '$'))   /* ) ] } */
6712             {
6713               if (peek_char == '{')             /* } */
6714                 ttok = parse_matched_pair (cd, '{', '}', &ttoklen, P_FIRSTCLOSE);
6715               else if (peek_char == '(')                /* ) */
6716                 {
6717                   /* XXX - push and pop the `(' as a delimiter for use by
6718                      the command-oriented-history code.  This way newlines
6719                      appearing in the $(...) string get added to the
6720                      history literally rather than causing a possibly-
6721                      incorrect `;' to be added. ) */
6722                   push_delimiter (dstack, peek_char);
6723                   ttok = parse_comsub (cd, '(', ')', &ttoklen, P_COMMAND);
6724                   pop_delimiter (dstack);
6725                 }
6726               else
6727                 ttok = parse_matched_pair (cd, '[', ']', &ttoklen, 0);
6728               if (ttok == &matched_pair_error)
6729                 return -1;              /* Bail immediately. */
6730               RESIZE_MALLOCED_BUFFER (token, token_index, ttoklen + 2,
6731                                       token_buffer_size,
6732                                       TOKEN_DEFAULT_GROW_SIZE);
6733               token[token_index++] = character;
6734               token[token_index++] = peek_char;
6735               strcpy (token + token_index, ttok);
6736               token_index += ttoklen;
6737               FREE (ttok);
6738               dollar_present = 1;
6739               all_digit_token = 0;
6740               goto next_character;
6741             }
6742           /* This handles $'...' and $"..." new-style quoted strings. */
6743           else if MBTEST(character == '$' && (peek_char == '\'' || peek_char == '"'))
6744             {
6745               int first_line;
6746
6747               first_line = line_number;
6748               push_delimiter (dstack, peek_char);
6749               ttok = parse_matched_pair (peek_char, peek_char, peek_char,
6750                                          &ttoklen,
6751                                          (peek_char == '\'') ? P_ALLOWESC : 0);
6752               pop_delimiter (dstack);
6753               if (ttok == &matched_pair_error)
6754                 return -1;
6755               if (peek_char == '\'')
6756                 {
6757                   ttrans = ansiexpand (ttok, 0, ttoklen - 1, &ttranslen);
6758                   free (ttok);
6759
6760                   /* Insert the single quotes and correctly quote any
6761                      embedded single quotes (allowed because P_ALLOWESC was
6762                      passed to parse_matched_pair). */
6763                   ttok = sh_single_quote (ttrans);
6764                   free (ttrans);
6765                   ttranslen = strlen (ttok);
6766                   ttrans = ttok;
6767                 }
6768               else
6769                 {
6770                   /* Try to locale-expand the converted string. */
6771                   ttrans = localeexpand (ttok, 0, ttoklen - 1, first_line, &ttranslen);
6772                   free (ttok);
6773
6774                   /* Add the double quotes back */
6775                   ttok = sh_mkdoublequoted (ttrans, ttranslen, 0);
6776                   free (ttrans);
6777                   ttranslen += 2;
6778                   ttrans = ttok;
6779                 }
6780
6781               RESIZE_MALLOCED_BUFFER (token, token_index, ttranslen + 2,
6782                                       token_buffer_size,
6783                                       TOKEN_DEFAULT_GROW_SIZE);
6784               strcpy (token + token_index, ttrans);
6785               token_index += ttranslen;
6786               FREE (ttrans);
6787               quoted = 1;
6788               all_digit_token = 0;
6789               goto next_character;
6790             }
6791           /* This could eventually be extended to recognize all of the
6792              shell's single-character parameter expansions, and set flags.*/
6793           else if MBTEST(character == '$' && peek_char == '$')
6794             {
6795               ttok = (char *)xmalloc (3);
6796               ttok[0] = ttok[1] = '$';
6797               ttok[2] = '\0';
6798               RESIZE_MALLOCED_BUFFER (token, token_index, 3,
6799                                       token_buffer_size,
6800                                       TOKEN_DEFAULT_GROW_SIZE);
6801               strcpy (token + token_index, ttok);
6802               token_index += 2;
6803               dollar_present = 1;
6804               all_digit_token = 0;
6805               FREE (ttok);
6806               goto next_character;
6807             }
6808           else
6809             shell_ungetc (peek_char);
6810         }
6811
6812 #if defined (ARRAY_VARS)
6813       /* Identify possible array subscript assignment; match [...].  If
6814          parser_state&PST_COMPASSIGN, we need to parse [sub]=words treating
6815          `sub' as if it were enclosed in double quotes. */
6816       else if MBTEST(character == '[' &&                /* ] */
6817                      ((token_index > 0 && assignment_acceptable (last_read_token) && token_is_ident (token, token_index)) ||
6818                       (token_index == 0 && (parser_state&PST_COMPASSIGN))))
6819         {
6820           ttok = parse_matched_pair (cd, '[', ']', &ttoklen, P_ARRAYSUB);
6821           if (ttok == &matched_pair_error)
6822             return -1;          /* Bail immediately. */
6823           RESIZE_MALLOCED_BUFFER (token, token_index, ttoklen + 2,
6824                                   token_buffer_size,
6825                                   TOKEN_DEFAULT_GROW_SIZE);
6826           token[token_index++] = character;
6827           strcpy (token + token_index, ttok);
6828           token_index += ttoklen;
6829           FREE (ttok);
6830           all_digit_token = 0;
6831           goto next_character;
6832         }
6833       /* Identify possible compound array variable assignment. */
6834       else if MBTEST(character == '=' && token_index > 0 && (assignment_acceptable (last_read_token) || (parser_state & PST_ASSIGNOK)) && token_is_assignment (token, token_index))
6835         {
6836           peek_char = shell_getc (1);
6837           if MBTEST(peek_char == '(')           /* ) */
6838             {
6839               ttok = parse_compound_assignment (&ttoklen);
6840
6841               RESIZE_MALLOCED_BUFFER (token, token_index, ttoklen + 4,
6842                                       token_buffer_size,
6843                                       TOKEN_DEFAULT_GROW_SIZE);
6844
6845               token[token_index++] = '=';
6846               token[token_index++] = '(';
6847               if (ttok)
6848                 {
6849                   strcpy (token + token_index, ttok);
6850                   token_index += ttoklen;
6851                 }
6852               token[token_index++] = ')';
6853               FREE (ttok);
6854               all_digit_token = 0;
6855               compound_assignment = 1;
6856 #if 1
6857               goto next_character;
6858 #else
6859               goto got_token;           /* ksh93 seems to do this */
6860 #endif
6861             }
6862           else
6863             shell_ungetc (peek_char);
6864         }
6865 #endif
6866
6867       /* When not parsing a multi-character word construct, shell meta-
6868          characters break words. */
6869       if MBTEST(shellbreak (character))
6870         {
6871           shell_ungetc (character);
6872           goto got_token;
6873         }
6874
6875     got_character:
6876
6877       if (character == CTLESC || character == CTLNUL)
6878         token[token_index++] = CTLESC;
6879
6880     got_escaped_character:
6881
6882       all_digit_token &= DIGIT (character);
6883       dollar_present |= character == '$';
6884
6885       token[token_index++] = character;
6886
6887       RESIZE_MALLOCED_BUFFER (token, token_index, 1, token_buffer_size,
6888                               TOKEN_DEFAULT_GROW_SIZE);
6889
6890     next_character:
6891       if (character == '\n' && SHOULD_PROMPT ())
6892         prompt_again ();
6893
6894       /* We want to remove quoted newlines (that is, a \<newline> pair)
6895          unless we are within single quotes or pass_next_character is
6896          set (the shell equivalent of literal-next). */
6897       cd = current_delimiter (dstack);
6898       character = shell_getc (cd != '\'' && pass_next_character == 0);
6899     }   /* end for (;;) */
6900
6901 got_token:
6902
6903   token[token_index] = '\0';
6904
6905   /* Check to see what thing we should return.  If the last_read_token
6906      is a `<', or a `&', or the character which ended this token is
6907      a '>' or '<', then, and ONLY then, is this input token a NUMBER.
6908      Otherwise, it is just a word, and should be returned as such. */
6909   if MBTEST(all_digit_token && (character == '<' || character == '>' || \
6910                     last_read_token == LESS_AND || \
6911                     last_read_token == GREATER_AND))
6912       {
6913         if (legal_number (token, &lvalue) && (int)lvalue == lvalue)
6914           yylval.number = lvalue;
6915         else
6916           yylval.number = -1;
6917         return (NUMBER);
6918       }
6919
6920   /* Check for special case tokens. */
6921   result = (last_shell_getc_is_singlebyte) ? special_case_tokens (token) : -1;
6922   if (result >= 0)
6923     return result;
6924
6925 #if defined (ALIAS)
6926   /* Posix.2 does not allow reserved words to be aliased, so check for all
6927      of them, including special cases, before expanding the current token
6928      as an alias. */
6929   if MBTEST(posixly_correct)
6930     CHECK_FOR_RESERVED_WORD (token);
6931
6932   /* Aliases are expanded iff EXPAND_ALIASES is non-zero, and quoting
6933      inhibits alias expansion. */
6934   if (expand_aliases && quoted == 0)
6935     {
6936       result = alias_expand_token (token);
6937       if (result == RE_READ_TOKEN)
6938         return (RE_READ_TOKEN);
6939       else if (result == NO_EXPANSION)
6940         parser_state &= ~PST_ALEXPNEXT;
6941     }
6942
6943   /* If not in Posix.2 mode, check for reserved words after alias
6944      expansion. */
6945   if MBTEST(posixly_correct == 0)
6946 #endif
6947     CHECK_FOR_RESERVED_WORD (token);
6948
6949   the_word = (WORD_DESC *)xmalloc (sizeof (WORD_DESC));
6950   the_word->word = (char *)xmalloc (1 + token_index);
6951   the_word->flags = 0;
6952   strcpy (the_word->word, token);
6953   if (dollar_present)
6954     the_word->flags |= W_HASDOLLAR;
6955   if (quoted)
6956     the_word->flags |= W_QUOTED;                /*(*/
6957   if (compound_assignment && token[token_index-1] == ')')
6958     the_word->flags |= W_COMPASSIGN;
6959   /* A word is an assignment if it appears at the beginning of a
6960      simple command, or after another assignment word.  This is
6961      context-dependent, so it cannot be handled in the grammar. */
6962   if (assignment (token, (parser_state & PST_COMPASSIGN) != 0))
6963     {
6964       the_word->flags |= W_ASSIGNMENT;
6965       /* Don't perform word splitting on assignment statements. */
6966       if (assignment_acceptable (last_read_token) || (parser_state & PST_COMPASSIGN) != 0)
6967         the_word->flags |= W_NOSPLIT;
6968     }
6969
6970   if (command_token_position (last_read_token))
6971     {
6972       struct builtin *b;
6973       b = builtin_address_internal (token, 0);
6974       if (b && (b->flags & ASSIGNMENT_BUILTIN))
6975         parser_state |= PST_ASSIGNOK;
6976       else if (STREQ (token, "eval") || STREQ (token, "let"))
6977         parser_state |= PST_ASSIGNOK;
6978     }
6979
6980   yylval.word = the_word;
6981
6982   if (token[0] == '{' && token[token_index-1] == '}' &&
6983       (character == '<' || character == '>'))
6984     {
6985       /* can use token; already copied to the_word */
6986       token[token_index-1] = '\0';
6987       if (legal_identifier (token+1))
6988         {
6989           strcpy (the_word->word, token+1);
6990 /*itrace("read_token_word: returning REDIR_WORD for %s", the_word->word);*/
6991           return (REDIR_WORD);
6992         }
6993     }
6994
6995   result = ((the_word->flags & (W_ASSIGNMENT|W_NOSPLIT)) == (W_ASSIGNMENT|W_NOSPLIT))
6996                 ? ASSIGNMENT_WORD : WORD;
6997
6998   switch (last_read_token)
6999     {
7000     case FUNCTION:
7001       parser_state |= PST_ALLOWOPNBRC;
7002       function_dstart = line_number;
7003       break;
7004     case CASE:
7005     case SELECT:
7006     case FOR:
7007       if (word_top < MAX_CASE_NEST)
7008         word_top++;
7009       word_lineno[word_top] = line_number;
7010       break;
7011     }
7012
7013   return (result);
7014 }
7015
7016 /* Return 1 if TOKSYM is a token that after being read would allow
7017    a reserved word to be seen, else 0. */
7018 static int
7019 reserved_word_acceptable (toksym)
7020      int toksym;
7021 {
7022   switch (toksym)
7023     {
7024     case '\n':
7025     case ';':
7026     case '(':
7027     case ')':
7028     case '|':
7029     case '&':
7030     case '{':
7031     case '}':           /* XXX */
7032     case AND_AND:
7033     case BANG:
7034     case BAR_AND:
7035     case DO:
7036     case DONE:
7037     case ELIF:
7038     case ELSE:
7039     case ESAC:
7040     case FI:
7041     case IF:
7042     case OR_OR:
7043     case SEMI_SEMI:
7044     case SEMI_AND:
7045     case SEMI_SEMI_AND:
7046     case THEN:
7047     case TIME:
7048     case TIMEOPT:
7049     case COPROC:
7050     case UNTIL:
7051     case WHILE:
7052     case 0:
7053       return 1;
7054     default:
7055 #if defined (COPROCESS_SUPPORT)
7056       if (last_read_token == WORD && token_before_that == COPROC)
7057         return 1;
7058 #endif
7059       return 0;
7060     }
7061 }
7062     
7063 /* Return the index of TOKEN in the alist of reserved words, or -1 if
7064    TOKEN is not a shell reserved word. */
7065 int
7066 find_reserved_word (tokstr)
7067      char *tokstr;
7068 {
7069   int i;
7070   for (i = 0; word_token_alist[i].word; i++)
7071     if (STREQ (tokstr, word_token_alist[i].word))
7072       return i;
7073   return -1;
7074 }
7075
7076 #if 0
7077 #if defined (READLINE)
7078 /* Called after each time readline is called.  This insures that whatever
7079    the new prompt string is gets propagated to readline's local prompt
7080    variable. */
7081 static void
7082 reset_readline_prompt ()
7083 {
7084   char *temp_prompt;
7085
7086   if (prompt_string_pointer)
7087     {
7088       temp_prompt = (*prompt_string_pointer)
7089                         ? decode_prompt_string (*prompt_string_pointer)
7090                         : (char *)NULL;
7091
7092       if (temp_prompt == 0)
7093         {
7094           temp_prompt = (char *)xmalloc (1);
7095           temp_prompt[0] = '\0';
7096         }
7097
7098       FREE (current_readline_prompt);
7099       current_readline_prompt = temp_prompt;
7100     }
7101 }
7102 #endif /* READLINE */
7103 #endif /* 0 */
7104
7105 #if defined (HISTORY)
7106 /* A list of tokens which can be followed by newlines, but not by
7107    semi-colons.  When concatenating multiple lines of history, the
7108    newline separator for such tokens is replaced with a space. */
7109 static const int no_semi_successors[] = {
7110   '\n', '{', '(', ')', ';', '&', '|',
7111   CASE, DO, ELSE, IF, SEMI_SEMI, SEMI_AND, SEMI_SEMI_AND, THEN, UNTIL,
7112   WHILE, AND_AND, OR_OR, IN,
7113   0
7114 };
7115
7116 /* If we are not within a delimited expression, try to be smart
7117    about which separators can be semi-colons and which must be
7118    newlines.  Returns the string that should be added into the
7119    history entry. */
7120 char *
7121 history_delimiting_chars ()
7122 {
7123   register int i;
7124
7125   if (dstack.delimiter_depth != 0)
7126     return ("\n");
7127
7128   /* We look for current_command_line_count == 2 because we are looking to
7129      add the first line of the body of the here document (the second line
7130      of the command). */
7131   if (parser_state & PST_HEREDOC)
7132     return (current_command_line_count == 2 ? "\n" : "");
7133
7134   /* First, handle some special cases. */
7135   /*(*/
7136   /* If we just read `()', assume it's a function definition, and don't
7137      add a semicolon.  If the token before the `)' was not `(', and we're
7138      not in the midst of parsing a case statement, assume it's a
7139      parenthesized command and add the semicolon. */
7140   /*)(*/
7141   if (token_before_that == ')')
7142     {
7143       if (two_tokens_ago == '(')        /*)*/   /* function def */
7144         return " ";
7145       /* This does not work for subshells inside case statement
7146          command lists.  It's a suboptimal solution. */
7147       else if (parser_state & PST_CASESTMT)     /* case statement pattern */
7148         return " ";
7149       else      
7150         return "; ";                            /* (...) subshell */
7151     }
7152   else if (token_before_that == WORD && two_tokens_ago == FUNCTION)
7153     return " ";         /* function def using `function name' without `()' */
7154
7155   else if (token_before_that == WORD && two_tokens_ago == FOR)
7156     {
7157       /* Tricky.  `for i\nin ...' should not have a semicolon, but
7158          `for i\ndo ...' should.  We do what we can. */
7159       for (i = shell_input_line_index; whitespace (shell_input_line[i]); i++)
7160         ;
7161       if (shell_input_line[i] && shell_input_line[i] == 'i' && shell_input_line[i+1] == 'n')
7162         return " ";
7163       return ";";
7164     }
7165   else if (two_tokens_ago == CASE && token_before_that == WORD && (parser_state & PST_CASESTMT))
7166     return " ";
7167
7168   for (i = 0; no_semi_successors[i]; i++)
7169     {
7170       if (token_before_that == no_semi_successors[i])
7171         return (" ");
7172     }
7173
7174   return ("; ");
7175 }
7176 #endif /* HISTORY */
7177
7178 /* Issue a prompt, or prepare to issue a prompt when the next character
7179    is read. */
7180 static void
7181 prompt_again ()
7182 {
7183   char *temp_prompt;
7184
7185   if (interactive == 0 || expanding_alias ())   /* XXX */
7186     return;
7187
7188   ps1_prompt = get_string_value ("PS1");
7189   ps2_prompt = get_string_value ("PS2");
7190
7191   if (!prompt_string_pointer)
7192     prompt_string_pointer = &ps1_prompt;
7193
7194   temp_prompt = *prompt_string_pointer
7195                         ? decode_prompt_string (*prompt_string_pointer)
7196                         : (char *)NULL;
7197
7198   if (temp_prompt == 0)
7199     {
7200       temp_prompt = (char *)xmalloc (1);
7201       temp_prompt[0] = '\0';
7202     }
7203
7204   current_prompt_string = *prompt_string_pointer;
7205   prompt_string_pointer = &ps2_prompt;
7206
7207 #if defined (READLINE)
7208   if (!no_line_editing)
7209     {
7210       FREE (current_readline_prompt);
7211       current_readline_prompt = temp_prompt;
7212     }
7213   else
7214 #endif  /* READLINE */
7215     {
7216       FREE (current_decoded_prompt);
7217       current_decoded_prompt = temp_prompt;
7218     }
7219 }
7220
7221 int
7222 get_current_prompt_level ()
7223 {
7224   return ((current_prompt_string && current_prompt_string == ps2_prompt) ? 2 : 1);
7225 }
7226
7227 void
7228 set_current_prompt_level (x)
7229      int x;
7230 {
7231   prompt_string_pointer = (x == 2) ? &ps2_prompt : &ps1_prompt;
7232   current_prompt_string = *prompt_string_pointer;
7233 }
7234       
7235 static void
7236 print_prompt ()
7237 {
7238   fprintf (stderr, "%s", current_decoded_prompt);
7239   fflush (stderr);
7240 }
7241
7242 /* Return a string which will be printed as a prompt.  The string
7243    may contain special characters which are decoded as follows:
7244
7245         \a      bell (ascii 07)
7246         \d      the date in Day Mon Date format
7247         \e      escape (ascii 033)
7248         \h      the hostname up to the first `.'
7249         \H      the hostname
7250         \j      the number of active jobs
7251         \l      the basename of the shell's tty device name
7252         \n      CRLF
7253         \r      CR
7254         \s      the name of the shell
7255         \t      the time in 24-hour hh:mm:ss format
7256         \T      the time in 12-hour hh:mm:ss format
7257         \@      the time in 12-hour hh:mm am/pm format
7258         \A      the time in 24-hour hh:mm format
7259         \D{fmt} the result of passing FMT to strftime(3)
7260         \u      your username
7261         \v      the version of bash (e.g., 2.00)
7262         \V      the release of bash, version + patchlevel (e.g., 2.00.0)
7263         \w      the current working directory
7264         \W      the last element of $PWD
7265         \!      the history number of this command
7266         \#      the command number of this command
7267         \$      a $ or a # if you are root
7268         \nnn    character code nnn in octal
7269         \\      a backslash
7270         \[      begin a sequence of non-printing chars
7271         \]      end a sequence of non-printing chars
7272 */
7273 #define PROMPT_GROWTH 48
7274 char *
7275 decode_prompt_string (string)
7276      char *string;
7277 {
7278   WORD_LIST *list;
7279   char *result, *t;
7280   struct dstack save_dstack;
7281   int last_exit_value, last_comsub_pid;
7282 #if defined (PROMPT_STRING_DECODE)
7283   int result_size, result_index;
7284   int c, n, i;
7285   char *temp, octal_string[4];
7286   struct tm *tm;  
7287   time_t the_time;
7288   char timebuf[128];
7289   char *timefmt;
7290
7291   result = (char *)xmalloc (result_size = PROMPT_GROWTH);
7292   result[result_index = 0] = 0;
7293   temp = (char *)NULL;
7294
7295   while (c = *string++)
7296     {
7297       if (posixly_correct && c == '!')
7298         {
7299           if (*string == '!')
7300             {
7301               temp = savestring ("!");
7302               goto add_string;
7303             }
7304           else
7305             {
7306 #if !defined (HISTORY)
7307                 temp = savestring ("1");
7308 #else /* HISTORY */
7309                 temp = itos (history_number ());
7310 #endif /* HISTORY */
7311                 string--;       /* add_string increments string again. */
7312                 goto add_string;
7313             }
7314         }
7315       if (c == '\\')
7316         {
7317           c = *string;
7318
7319           switch (c)
7320             {
7321             case '0':
7322             case '1':
7323             case '2':
7324             case '3':
7325             case '4':
7326             case '5':
7327             case '6':
7328             case '7':
7329               strncpy (octal_string, string, 3);
7330               octal_string[3] = '\0';
7331
7332               n = read_octal (octal_string);
7333               temp = (char *)xmalloc (3);
7334
7335               if (n == CTLESC || n == CTLNUL)
7336                 {
7337                   temp[0] = CTLESC;
7338                   temp[1] = n;
7339                   temp[2] = '\0';
7340                 }
7341               else if (n == -1)
7342                 {
7343                   temp[0] = '\\';
7344                   temp[1] = '\0';
7345                 }
7346               else
7347                 {
7348                   temp[0] = n;
7349                   temp[1] = '\0';
7350                 }
7351
7352               for (c = 0; n != -1 && c < 3 && ISOCTAL (*string); c++)
7353                 string++;
7354
7355               c = 0;            /* tested at add_string: */
7356               goto add_string;
7357
7358             case 'd':
7359             case 't':
7360             case 'T':
7361             case '@':
7362             case 'A':
7363               /* Make the current time/date into a string. */
7364               (void) time (&the_time);
7365               tm = localtime (&the_time);
7366
7367               if (c == 'd')
7368                 n = strftime (timebuf, sizeof (timebuf), "%a %b %d", tm);
7369               else if (c == 't')
7370                 n = strftime (timebuf, sizeof (timebuf), "%H:%M:%S", tm);
7371               else if (c == 'T')
7372                 n = strftime (timebuf, sizeof (timebuf), "%I:%M:%S", tm);
7373               else if (c == '@')
7374                 n = strftime (timebuf, sizeof (timebuf), "%I:%M %p", tm);
7375               else if (c == 'A')
7376                 n = strftime (timebuf, sizeof (timebuf), "%H:%M", tm);
7377
7378               if (n == 0)
7379                 timebuf[0] = '\0';
7380               else
7381                 timebuf[sizeof(timebuf) - 1] = '\0';
7382
7383               temp = savestring (timebuf);
7384               goto add_string;
7385
7386             case 'D':           /* strftime format */
7387               if (string[1] != '{')             /* } */
7388                 goto not_escape;
7389
7390               (void) time (&the_time);
7391               tm = localtime (&the_time);
7392               string += 2;                      /* skip { */
7393               timefmt = xmalloc (strlen (string) + 3);
7394               for (t = timefmt; *string && *string != '}'; )
7395                 *t++ = *string++;
7396               *t = '\0';
7397               c = *string;      /* tested at add_string */
7398               if (timefmt[0] == '\0')
7399                 {
7400                   timefmt[0] = '%';
7401                   timefmt[1] = 'X';     /* locale-specific current time */
7402                   timefmt[2] = '\0';
7403                 }
7404               n = strftime (timebuf, sizeof (timebuf), timefmt, tm);
7405               free (timefmt);
7406
7407               if (n == 0)
7408                 timebuf[0] = '\0';
7409               else
7410                 timebuf[sizeof(timebuf) - 1] = '\0';
7411
7412               if (promptvars || posixly_correct)
7413                 /* Make sure that expand_prompt_string is called with a
7414                    second argument of Q_DOUBLE_QUOTES if we use this
7415                    function here. */
7416                 temp = sh_backslash_quote_for_double_quotes (timebuf);
7417               else
7418                 temp = savestring (timebuf);
7419               goto add_string;
7420               
7421             case 'n':
7422               temp = (char *)xmalloc (3);
7423               temp[0] = no_line_editing ? '\n' : '\r';
7424               temp[1] = no_line_editing ? '\0' : '\n';
7425               temp[2] = '\0';
7426               goto add_string;
7427
7428             case 's':
7429               temp = base_pathname (shell_name);
7430               temp = savestring (temp);
7431               goto add_string;
7432
7433             case 'v':
7434             case 'V':
7435               temp = (char *)xmalloc (16);
7436               if (c == 'v')
7437                 strcpy (temp, dist_version);
7438               else
7439                 sprintf (temp, "%s.%d", dist_version, patch_level);
7440               goto add_string;
7441
7442             case 'w':
7443             case 'W':
7444               {
7445                 /* Use the value of PWD because it is much more efficient. */
7446                 char t_string[PATH_MAX];
7447                 int tlen;
7448
7449                 temp = get_string_value ("PWD");
7450
7451                 if (temp == 0)
7452                   {
7453                     if (getcwd (t_string, sizeof(t_string)) == 0)
7454                       {
7455                         t_string[0] = '.';
7456                         tlen = 1;
7457                       }
7458                     else
7459                       tlen = strlen (t_string);
7460                   }
7461                 else
7462                   {
7463                     tlen = sizeof (t_string) - 1;
7464                     strncpy (t_string, temp, tlen);
7465                   }
7466                 t_string[tlen] = '\0';
7467
7468 #if defined (MACOSX)
7469                 /* Convert from "fs" format to "input" format */
7470                 temp = fnx_fromfs (t_string, strlen (t_string));
7471                 if (temp != t_string)
7472                   strcpy (t_string, temp);
7473 #endif
7474
7475 #define ROOT_PATH(x)    ((x)[0] == '/' && (x)[1] == 0)
7476 #define DOUBLE_SLASH_ROOT(x)    ((x)[0] == '/' && (x)[1] == '/' && (x)[2] == 0)
7477                 /* Abbreviate \W as ~ if $PWD == $HOME */
7478                 if (c == 'W' && (((t = get_string_value ("HOME")) == 0) || STREQ (t, t_string) == 0))
7479                   {
7480                     if (ROOT_PATH (t_string) == 0 && DOUBLE_SLASH_ROOT (t_string) == 0)
7481                       {
7482                         t = strrchr (t_string, '/');
7483                         if (t)
7484                           strcpy (t_string, t + 1);
7485                       }
7486                   }
7487 #undef ROOT_PATH
7488 #undef DOUBLE_SLASH_ROOT
7489                 else
7490                   /* polite_directory_format is guaranteed to return a string
7491                      no longer than PATH_MAX - 1 characters. */
7492                   strcpy (t_string, polite_directory_format (t_string));
7493
7494                 temp = trim_pathname (t_string, PATH_MAX - 1);
7495                 /* If we're going to be expanding the prompt string later,
7496                    quote the directory name. */
7497                 if (promptvars || posixly_correct)
7498                   /* Make sure that expand_prompt_string is called with a
7499                      second argument of Q_DOUBLE_QUOTES if we use this
7500                      function here. */
7501                   temp = sh_backslash_quote_for_double_quotes (t_string);
7502                 else
7503                   temp = savestring (t_string);
7504
7505                 goto add_string;
7506               }
7507
7508             case 'u':
7509               if (current_user.user_name == 0)
7510                 get_current_user_info ();
7511               temp = savestring (current_user.user_name);
7512               goto add_string;
7513
7514             case 'h':
7515             case 'H':
7516               temp = savestring (current_host_name);
7517               if (c == 'h' && (t = (char *)strchr (temp, '.')))
7518                 *t = '\0';
7519               goto add_string;
7520
7521             case '#':
7522               temp = itos (current_command_number);
7523               goto add_string;
7524
7525             case '!':
7526 #if !defined (HISTORY)
7527               temp = savestring ("1");
7528 #else /* HISTORY */
7529               temp = itos (history_number ());
7530 #endif /* HISTORY */
7531               goto add_string;
7532
7533             case '$':
7534               t = temp = (char *)xmalloc (3);
7535               if ((promptvars || posixly_correct) && (current_user.euid != 0))
7536                 *t++ = '\\';
7537               *t++ = current_user.euid == 0 ? '#' : '$';
7538               *t = '\0';
7539               goto add_string;
7540
7541             case 'j':
7542               temp = itos (count_all_jobs ());
7543               goto add_string;
7544
7545             case 'l':
7546 #if defined (HAVE_TTYNAME)
7547               temp = (char *)ttyname (fileno (stdin));
7548               t = temp ? base_pathname (temp) : "tty";
7549               temp = savestring (t);
7550 #else
7551               temp = savestring ("tty");
7552 #endif /* !HAVE_TTYNAME */
7553               goto add_string;
7554
7555 #if defined (READLINE)
7556             case '[':
7557             case ']':
7558               if (no_line_editing)
7559                 {
7560                   string++;
7561                   break;
7562                 }
7563               temp = (char *)xmalloc (3);
7564               n = (c == '[') ? RL_PROMPT_START_IGNORE : RL_PROMPT_END_IGNORE;
7565               i = 0;
7566               if (n == CTLESC || n == CTLNUL)
7567                 temp[i++] = CTLESC;
7568               temp[i++] = n;
7569               temp[i] = '\0';
7570               goto add_string;
7571 #endif /* READLINE */
7572
7573             case '\\':
7574             case 'a':
7575             case 'e':
7576             case 'r':
7577               temp = (char *)xmalloc (2);
7578               if (c == 'a')
7579                 temp[0] = '\07';
7580               else if (c == 'e')
7581                 temp[0] = '\033';
7582               else if (c == 'r')
7583                 temp[0] = '\r';
7584               else                      /* (c == '\\') */
7585                 temp[0] = c;
7586               temp[1] = '\0';
7587               goto add_string;
7588
7589             default:
7590 not_escape:
7591               temp = (char *)xmalloc (3);
7592               temp[0] = '\\';
7593               temp[1] = c;
7594               temp[2] = '\0';
7595
7596             add_string:
7597               if (c)
7598                 string++;
7599               result =
7600                 sub_append_string (temp, result, &result_index, &result_size);
7601               temp = (char *)NULL; /* Freed in sub_append_string (). */
7602               result[result_index] = '\0';
7603               break;
7604             }
7605         }
7606       else
7607         {
7608           RESIZE_MALLOCED_BUFFER (result, result_index, 3, result_size, PROMPT_GROWTH);
7609           result[result_index++] = c;
7610           result[result_index] = '\0';
7611         }
7612     }
7613 #else /* !PROMPT_STRING_DECODE */
7614   result = savestring (string);
7615 #endif /* !PROMPT_STRING_DECODE */
7616
7617   /* Save the delimiter stack and point `dstack' to temp space so any
7618      command substitutions in the prompt string won't result in screwing
7619      up the parser's quoting state. */
7620   save_dstack = dstack;
7621   dstack = temp_dstack;
7622   dstack.delimiter_depth = 0;
7623
7624   /* Perform variable and parameter expansion and command substitution on
7625      the prompt string. */
7626   if (promptvars || posixly_correct)
7627     {
7628       last_exit_value = last_command_exit_value;
7629       last_comsub_pid = last_command_subst_pid;
7630       list = expand_prompt_string (result, Q_DOUBLE_QUOTES, 0);
7631       free (result);
7632       result = string_list (list);
7633       dispose_words (list);
7634       last_command_exit_value = last_exit_value;
7635       last_command_subst_pid = last_comsub_pid;
7636     }
7637   else
7638     {
7639       t = dequote_string (result);
7640       free (result);
7641       result = t;
7642     }
7643
7644   dstack = save_dstack;
7645
7646   return (result);
7647 }
7648
7649 /************************************************
7650  *                                              *
7651  *              ERROR HANDLING                  *
7652  *                                              *
7653  ************************************************/
7654
7655 /* Report a syntax error, and restart the parser.  Call here for fatal
7656    errors. */
7657 int
7658 yyerror (msg)
7659      const char *msg;
7660 {
7661   report_syntax_error ((char *)NULL);
7662   reset_parser ();
7663   return (0);
7664 }
7665
7666 static char *
7667 error_token_from_token (tok)
7668      int tok;
7669 {
7670   char *t;
7671
7672   if (t = find_token_in_alist (tok, word_token_alist, 0))
7673     return t;
7674
7675   if (t = find_token_in_alist (tok, other_token_alist, 0))
7676     return t;
7677
7678   t = (char *)NULL;
7679   /* This stuff is dicy and needs closer inspection */
7680   switch (current_token)
7681     {
7682     case WORD:
7683     case ASSIGNMENT_WORD:
7684       if (yylval.word)
7685         t = savestring (yylval.word->word);
7686       break;
7687     case NUMBER:
7688       t = itos (yylval.number);
7689       break;
7690     case ARITH_CMD:
7691       if (yylval.word_list)
7692         t = string_list (yylval.word_list);
7693       break;
7694     case ARITH_FOR_EXPRS:
7695       if (yylval.word_list)
7696         t = string_list_internal (yylval.word_list, " ; ");
7697       break;
7698     case COND_CMD:
7699       t = (char *)NULL;         /* punt */
7700       break;
7701     }
7702
7703   return t;
7704 }
7705
7706 static char *
7707 error_token_from_text ()
7708 {
7709   char *msg, *t;
7710   int token_end, i;
7711
7712   t = shell_input_line;
7713   i = shell_input_line_index;
7714   token_end = 0;
7715   msg = (char *)NULL;
7716
7717   if (i && t[i] == '\0')
7718     i--;
7719
7720   while (i && (whitespace (t[i]) || t[i] == '\n'))
7721     i--;
7722
7723   if (i)
7724     token_end = i + 1;
7725
7726   while (i && (member (t[i], " \n\t;|&") == 0))
7727     i--;
7728
7729   while (i != token_end && (whitespace (t[i]) || t[i] == '\n'))
7730     i++;
7731
7732   /* Return our idea of the offending token. */
7733   if (token_end || (i == 0 && token_end == 0))
7734     {
7735       if (token_end)
7736         msg = substring (t, i, token_end);
7737       else      /* one-character token */
7738         {
7739           msg = (char *)xmalloc (2);
7740           msg[0] = t[i];
7741           msg[1] = '\0';
7742         }
7743     }
7744
7745   return (msg);
7746 }
7747
7748 static void
7749 print_offending_line ()
7750 {
7751   char *msg;
7752   int token_end;
7753
7754   msg = savestring (shell_input_line);
7755   token_end = strlen (msg);
7756   while (token_end && msg[token_end - 1] == '\n')
7757     msg[--token_end] = '\0';
7758
7759   parser_error (line_number, "`%s'", msg);
7760   free (msg);
7761 }
7762
7763 /* Report a syntax error with line numbers, etc.
7764    Call here for recoverable errors.  If you have a message to print,
7765    then place it in MESSAGE, otherwise pass NULL and this will figure
7766    out an appropriate message for you. */
7767 static void
7768 report_syntax_error (message)
7769      char *message;
7770 {
7771   char *msg;
7772
7773   if (message)
7774     {
7775       parser_error (line_number, "%s", message);
7776       if (interactive && EOF_Reached)
7777         EOF_Reached = 0;
7778       last_command_exit_value = parse_and_execute_level ? EX_BADSYNTAX : EX_BADUSAGE;
7779       return;
7780     }
7781
7782   /* If the line of input we're reading is not null, try to find the
7783      objectionable token.  First, try to figure out what token the
7784      parser's complaining about by looking at current_token. */
7785   if (current_token != 0 && EOF_Reached == 0 && (msg = error_token_from_token (current_token)))
7786     {
7787       parser_error (line_number, _("syntax error near unexpected token `%s'"), msg);
7788       free (msg);
7789
7790       if (interactive == 0)
7791         print_offending_line ();
7792
7793       last_command_exit_value = parse_and_execute_level ? EX_BADSYNTAX : EX_BADUSAGE;
7794       return;
7795     }
7796
7797   /* If looking at the current token doesn't prove fruitful, try to find the
7798      offending token by analyzing the text of the input line near the current
7799      input line index and report what we find. */
7800   if (shell_input_line && *shell_input_line)
7801     {
7802       msg = error_token_from_text ();
7803       if (msg)
7804         {
7805           parser_error (line_number, _("syntax error near `%s'"), msg);
7806           free (msg);
7807         }
7808
7809       /* If not interactive, print the line containing the error. */
7810       if (interactive == 0)
7811         print_offending_line ();
7812     }
7813   else
7814     {
7815       msg = EOF_Reached ? _("syntax error: unexpected end of file") : _("syntax error");
7816       parser_error (line_number, "%s", msg);
7817       /* When the shell is interactive, this file uses EOF_Reached
7818          only for error reporting.  Other mechanisms are used to
7819          decide whether or not to exit. */
7820       if (interactive && EOF_Reached)
7821         EOF_Reached = 0;
7822     }
7823
7824   last_command_exit_value = parse_and_execute_level ? EX_BADSYNTAX : EX_BADUSAGE;
7825 }
7826
7827 /* ??? Needed function. ??? We have to be able to discard the constructs
7828    created during parsing.  In the case of error, we want to return
7829    allocated objects to the memory pool.  In the case of no error, we want
7830    to throw away the information about where the allocated objects live.
7831    (dispose_command () will actually free the command.) */
7832 static void
7833 discard_parser_constructs (error_p)
7834      int error_p;
7835 {
7836 }
7837
7838 /************************************************
7839  *                                              *
7840  *              EOF HANDLING                    *
7841  *                                              *
7842  ************************************************/
7843
7844 /* Do that silly `type "bye" to exit' stuff.  You know, "ignoreeof". */
7845
7846 /* A flag denoting whether or not ignoreeof is set. */
7847 int ignoreeof = 0;
7848
7849 /* The number of times that we have encountered an EOF character without
7850    another character intervening.  When this gets above the limit, the
7851    shell terminates. */
7852 int eof_encountered = 0;
7853
7854 /* The limit for eof_encountered. */
7855 int eof_encountered_limit = 10;
7856
7857 /* If we have EOF as the only input unit, this user wants to leave
7858    the shell.  If the shell is not interactive, then just leave.
7859    Otherwise, if ignoreeof is set, and we haven't done this the
7860    required number of times in a row, print a message. */
7861 static void
7862 handle_eof_input_unit ()
7863 {
7864   if (interactive)
7865     {
7866       /* shell.c may use this to decide whether or not to write out the
7867          history, among other things.  We use it only for error reporting
7868          in this file. */
7869       if (EOF_Reached)
7870         EOF_Reached = 0;
7871
7872       /* If the user wants to "ignore" eof, then let her do so, kind of. */
7873       if (ignoreeof)
7874         {
7875           if (eof_encountered < eof_encountered_limit)
7876             {
7877               fprintf (stderr, _("Use \"%s\" to leave the shell.\n"),
7878                        login_shell ? "logout" : "exit");
7879               eof_encountered++;
7880               /* Reset the parsing state. */
7881               last_read_token = current_token = '\n';
7882               /* Reset the prompt string to be $PS1. */
7883               prompt_string_pointer = (char **)NULL;
7884               prompt_again ();
7885               return;
7886             }
7887         }
7888
7889       /* In this case EOF should exit the shell.  Do it now. */
7890       reset_parser ();
7891       exit_builtin ((WORD_LIST *)NULL);
7892     }
7893   else
7894     {
7895       /* We don't write history files, etc., for non-interactive shells. */
7896       EOF_Reached = 1;
7897     }
7898 }
7899
7900 /************************************************
7901  *                                              *
7902  *      STRING PARSING FUNCTIONS                *
7903  *                                              *
7904  ************************************************/
7905
7906 /* It's very important that these two functions treat the characters
7907    between ( and ) identically. */
7908
7909 static WORD_LIST parse_string_error;
7910
7911 /* Take a string and run it through the shell parser, returning the
7912    resultant word list.  Used by compound array assignment. */
7913 WORD_LIST *
7914 parse_string_to_word_list (s, flags, whom)
7915      char *s;
7916      int flags;
7917      const char *whom;
7918 {
7919   WORD_LIST *wl;
7920   int tok, orig_current_token, orig_line_number, orig_input_terminator;
7921   int orig_line_count;
7922   int old_echo_input, old_expand_aliases;
7923 #if defined (HISTORY)
7924   int old_remember_on_history, old_history_expansion_inhibited;
7925 #endif
7926
7927 #if defined (HISTORY)
7928   old_remember_on_history = remember_on_history;
7929 #  if defined (BANG_HISTORY)
7930   old_history_expansion_inhibited = history_expansion_inhibited;
7931 #  endif
7932   bash_history_disable ();
7933 #endif
7934
7935   orig_line_number = line_number;
7936   orig_line_count = current_command_line_count;
7937   orig_input_terminator = shell_input_line_terminator;
7938   old_echo_input = echo_input_at_read;
7939   old_expand_aliases = expand_aliases;
7940
7941   push_stream (1);
7942   last_read_token = WORD;               /* WORD to allow reserved words here */
7943   current_command_line_count = 0;
7944   echo_input_at_read = expand_aliases = 0;
7945
7946   with_input_from_string (s, whom);
7947   wl = (WORD_LIST *)NULL;
7948
7949   if (flags & 1)
7950     parser_state |= PST_COMPASSIGN|PST_REPARSE;
7951
7952   while ((tok = read_token (READ)) != yacc_EOF)
7953     {
7954       if (tok == '\n' && *bash_input.location.string == '\0')
7955         break;
7956       if (tok == '\n')          /* Allow newlines in compound assignments */
7957         continue;
7958       if (tok != WORD && tok != ASSIGNMENT_WORD)
7959         {
7960           line_number = orig_line_number + line_number - 1;
7961           orig_current_token = current_token;
7962           current_token = tok;
7963           yyerror (NULL);       /* does the right thing */
7964           current_token = orig_current_token;
7965           if (wl)
7966             dispose_words (wl);
7967           wl = &parse_string_error;
7968           break;
7969         }
7970       wl = make_word_list (yylval.word, wl);
7971     }
7972   
7973   last_read_token = '\n';
7974   pop_stream ();
7975
7976 #if defined (HISTORY)
7977   remember_on_history = old_remember_on_history;
7978 #  if defined (BANG_HISTORY)
7979   history_expansion_inhibited = old_history_expansion_inhibited;
7980 #  endif /* BANG_HISTORY */
7981 #endif /* HISTORY */
7982
7983   echo_input_at_read = old_echo_input;
7984   expand_aliases = old_expand_aliases;
7985
7986   current_command_line_count = orig_line_count;
7987   shell_input_line_terminator = orig_input_terminator;
7988
7989   if (flags & 1)
7990     parser_state &= ~(PST_COMPASSIGN|PST_REPARSE);
7991
7992   if (wl == &parse_string_error)
7993     {
7994       last_command_exit_value = EXECUTION_FAILURE;
7995       if (interactive_shell == 0 && posixly_correct)
7996         jump_to_top_level (FORCE_EOF);
7997       else
7998         jump_to_top_level (DISCARD);
7999     }
8000
8001   return (REVERSE_LIST (wl, WORD_LIST *));
8002 }
8003
8004 static char *
8005 parse_compound_assignment (retlenp)
8006      int *retlenp;
8007 {
8008   WORD_LIST *wl, *rl;
8009   int tok, orig_line_number, orig_token_size, orig_last_token, assignok;
8010   char *saved_token, *ret;
8011
8012   saved_token = token;
8013   orig_token_size = token_buffer_size;
8014   orig_line_number = line_number;
8015   orig_last_token = last_read_token;
8016
8017   last_read_token = WORD;       /* WORD to allow reserved words here */
8018
8019   token = (char *)NULL;
8020   token_buffer_size = 0;
8021
8022   assignok = parser_state&PST_ASSIGNOK;         /* XXX */
8023
8024   wl = (WORD_LIST *)NULL;       /* ( */
8025   parser_state |= PST_COMPASSIGN;
8026
8027   while ((tok = read_token (READ)) != ')')
8028     {
8029       if (tok == '\n')                  /* Allow newlines in compound assignments */
8030         {
8031           if (SHOULD_PROMPT ())
8032             prompt_again ();
8033           continue;
8034         }
8035       if (tok != WORD && tok != ASSIGNMENT_WORD)
8036         {
8037           current_token = tok;  /* for error reporting */
8038           if (tok == yacc_EOF)  /* ( */
8039             parser_error (orig_line_number, _("unexpected EOF while looking for matching `)'"));
8040           else
8041             yyerror(NULL);      /* does the right thing */
8042           if (wl)
8043             dispose_words (wl);
8044           wl = &parse_string_error;
8045           break;
8046         }
8047       wl = make_word_list (yylval.word, wl);
8048     }
8049
8050   FREE (token);
8051   token = saved_token;
8052   token_buffer_size = orig_token_size;
8053
8054   parser_state &= ~PST_COMPASSIGN;
8055
8056   if (wl == &parse_string_error)
8057     {
8058       last_command_exit_value = EXECUTION_FAILURE;
8059       last_read_token = '\n';   /* XXX */
8060       if (interactive_shell == 0 && posixly_correct)
8061         jump_to_top_level (FORCE_EOF);
8062       else
8063         jump_to_top_level (DISCARD);
8064     }
8065
8066   last_read_token = orig_last_token;            /* XXX - was WORD? */
8067
8068   if (wl)
8069     {
8070       rl = REVERSE_LIST (wl, WORD_LIST *);
8071       ret = string_list (rl);
8072       dispose_words (rl);
8073     }
8074   else
8075     ret = (char *)NULL;
8076
8077   if (retlenp)
8078     *retlenp = (ret && *ret) ? strlen (ret) : 0;
8079
8080   if (assignok)
8081     parser_state |= PST_ASSIGNOK;
8082
8083   return ret;
8084 }
8085
8086 /************************************************
8087  *                                              *
8088  *   SAVING AND RESTORING PARTIAL PARSE STATE   *
8089  *                                              *
8090  ************************************************/
8091
8092 sh_parser_state_t *
8093 save_parser_state (ps)
8094      sh_parser_state_t *ps;
8095 {
8096 #if defined (ARRAY_VARS)
8097   SHELL_VAR *v;
8098 #endif
8099
8100   if (ps == 0)
8101     ps = (sh_parser_state_t *)xmalloc (sizeof (sh_parser_state_t));
8102   if (ps == 0)
8103     return ((sh_parser_state_t *)NULL);
8104
8105   ps->parser_state = parser_state;
8106   ps->token_state = save_token_state ();
8107
8108   ps->input_line_terminator = shell_input_line_terminator;
8109   ps->eof_encountered = eof_encountered;
8110
8111   ps->current_command_line_count = current_command_line_count;
8112
8113 #if defined (HISTORY)
8114   ps->remember_on_history = remember_on_history;
8115 #  if defined (BANG_HISTORY)
8116   ps->history_expansion_inhibited = history_expansion_inhibited;
8117 #  endif
8118 #endif
8119
8120   ps->last_command_exit_value = last_command_exit_value;
8121 #if defined (ARRAY_VARS)
8122   v = find_variable ("PIPESTATUS");
8123   if (v && array_p (v) && array_cell (v))
8124     ps->pipestatus = array_copy (array_cell (v));
8125   else
8126     ps->pipestatus = (ARRAY *)NULL;
8127 #endif
8128     
8129   ps->last_shell_builtin = last_shell_builtin;
8130   ps->this_shell_builtin = this_shell_builtin;
8131
8132   ps->expand_aliases = expand_aliases;
8133   ps->echo_input_at_read = echo_input_at_read;
8134
8135   return (ps);
8136 }
8137
8138 void
8139 restore_parser_state (ps)
8140      sh_parser_state_t *ps;
8141 {
8142 #if defined (ARRAY_VARS)
8143   SHELL_VAR *v;
8144 #endif
8145
8146   if (ps == 0)
8147     return;
8148
8149   parser_state = ps->parser_state;
8150   if (ps->token_state)
8151     {
8152       restore_token_state (ps->token_state);
8153       free (ps->token_state);
8154     }
8155
8156   shell_input_line_terminator = ps->input_line_terminator;
8157   eof_encountered = ps->eof_encountered;
8158
8159   current_command_line_count = ps->current_command_line_count;
8160
8161 #if defined (HISTORY)
8162   remember_on_history = ps->remember_on_history;
8163 #  if defined (BANG_HISTORY)
8164   history_expansion_inhibited = ps->history_expansion_inhibited;
8165 #  endif
8166 #endif
8167
8168   last_command_exit_value = ps->last_command_exit_value;
8169 #if defined (ARRAY_VARS)
8170   v = find_variable ("PIPESTATUS");
8171   if (v && array_p (v) && array_cell (v))
8172     {
8173       array_dispose (array_cell (v));
8174       var_setarray (v, ps->pipestatus);
8175     }
8176 #endif
8177
8178   last_shell_builtin = ps->last_shell_builtin;
8179   this_shell_builtin = ps->this_shell_builtin;
8180
8181   expand_aliases = ps->expand_aliases;
8182   echo_input_at_read = ps->echo_input_at_read;
8183 }
8184
8185 /************************************************
8186  *                                              *
8187  *      MULTIBYTE CHARACTER HANDLING            *
8188  *                                              *
8189  ************************************************/
8190
8191 #if defined (HANDLE_MULTIBYTE)
8192 static void
8193 set_line_mbstate ()
8194 {
8195   int i, previ, len, c;
8196   mbstate_t mbs, prevs;
8197   size_t mbclen;
8198
8199   if (shell_input_line == NULL)
8200     return;
8201   len = strlen (shell_input_line);      /* XXX - shell_input_line_len ? */
8202   FREE (shell_input_line_property);
8203   shell_input_line_property = (char *)xmalloc (len + 1);
8204
8205   memset (&prevs, '\0', sizeof (mbstate_t));
8206   for (i = previ = 0; i < len; i++)
8207     {
8208       mbs = prevs;
8209
8210       c = shell_input_line[i];
8211       if (c == EOF)
8212         {
8213           int j;
8214           for (j = i; j < len; j++)
8215             shell_input_line_property[j] = 1;
8216           break;
8217         }
8218
8219       mbclen = mbrlen (shell_input_line + previ, i - previ + 1, &mbs);
8220       if (mbclen == 1 || mbclen == (size_t)-1)
8221         {
8222           mbclen = 1;
8223           previ = i + 1;
8224         }
8225       else if (mbclen == (size_t)-2)
8226         mbclen = 0;
8227       else if (mbclen > 1)
8228         {
8229           mbclen = 0;
8230           previ = i + 1;
8231           prevs = mbs;
8232         }
8233       else
8234         {
8235           /* XXX - what to do if mbrlen returns 0? (null wide character) */
8236           int j;
8237           for (j = i; j < len; j++)
8238             shell_input_line_property[j] = 1;
8239           break;
8240         }
8241
8242       shell_input_line_property[i] = mbclen;
8243     }
8244 }
8245 #endif /* HANDLE_MULTIBYTE */
8246