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