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