]>
Commit | Line | Data |
---|---|---|
74091dd4 | 1 | /* A Bison parser, made by GNU Bison 3.8.2. */ |
b80f6443 | 2 | |
a0c0a00f | 3 | /* Bison implementation for Yacc-like parsers in C |
b80f6443 | 4 | |
74091dd4 | 5 | Copyright (C) 1984, 1989-1990, 2000-2015, 2018-2021 Free Software Foundation, |
8868edaf | 6 | Inc. |
3185942a | 7 | |
a0c0a00f | 8 | This program is free software: you can redistribute it and/or modify |
3185942a | 9 | it under the terms of the GNU General Public License as published by |
a0c0a00f CR |
10 | the Free Software Foundation, either version 3 of the License, or |
11 | (at your option) any later version. | |
3185942a JA |
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 | |
74091dd4 | 19 | along with this program. If not, see <https://www.gnu.org/licenses/>. */ |
3185942a JA |
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 | ||
8868edaf CR |
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 | ||
3185942a JA |
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 | ||
74091dd4 CR |
48 | /* Identify Bison output, and Bison version. */ |
49 | #define YYBISON 30802 | |
3185942a | 50 | |
74091dd4 CR |
51 | /* Bison version string. */ |
52 | #define YYBISON_VERSION "3.8.2" | |
3185942a JA |
53 | |
54 | /* Skeleton name. */ | |
55 | #define YYSKELETON_NAME "yacc.c" | |
56 | ||
57 | /* Pure parsers. */ | |
58 | #define YYPURE 0 | |
59 | ||
a0c0a00f CR |
60 | /* Push parsers. */ |
61 | #define YYPUSH 0 | |
3185942a | 62 | |
a0c0a00f CR |
63 | /* Pull parsers. */ |
64 | #define YYPULL 1 | |
3185942a JA |
65 | |
66 | ||
67 | ||
68 | ||
8868edaf | 69 | /* First part of user prologue. */ |
74091dd4 | 70 | #line 21 "/usr/local/src/chet/src/bash/src/parse.y" |
f73dda09 | 71 | |
ccc6cda3 JA |
72 | #include "config.h" |
73 | ||
726f6388 | 74 | #include "bashtypes.h" |
726f6388 | 75 | #include "bashansi.h" |
ccc6cda3 | 76 | |
28ef6c31 JA |
77 | #include "filecntl.h" |
78 | ||
ccc6cda3 JA |
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> | |
f73dda09 | 88 | #include "chartypes.h" |
ccc6cda3 JA |
89 | #include <signal.h> |
90 | ||
91 | #include "memalloc.h" | |
92 | ||
b80f6443 JA |
93 | #include "bashintl.h" |
94 | ||
7117c2d2 JA |
95 | #define NEED_STRFTIME_DECL /* used in externs.h */ |
96 | ||
726f6388 | 97 | #include "shell.h" |
d233b485 | 98 | #include "execute_cmd.h" |
ac50fbac | 99 | #include "typemax.h" /* SIZE_MAX if needed */ |
ccc6cda3 | 100 | #include "trap.h" |
726f6388 | 101 | #include "flags.h" |
ccc6cda3 JA |
102 | #include "parser.h" |
103 | #include "mailcheck.h" | |
f73dda09 | 104 | #include "test.h" |
95732b49 | 105 | #include "builtins.h" |
ccc6cda3 JA |
106 | #include "builtins/common.h" |
107 | #include "builtins/builtext.h" | |
726f6388 | 108 | |
7117c2d2 JA |
109 | #include "shmbutil.h" |
110 | ||
726f6388 | 111 | #if defined (READLINE) |
ccc6cda3 | 112 | # include "bashline.h" |
726f6388 JA |
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" | |
a0c0a00f | 123 | #else |
8868edaf | 124 | extern int cleanup_dead_jobs PARAMS((void)); |
726f6388 JA |
125 | #endif /* JOB_CONTROL */ |
126 | ||
127 | #if defined (ALIAS) | |
128 | # include "alias.h" | |
b80f6443 JA |
129 | #else |
130 | typedef void *alias_t; | |
726f6388 JA |
131 | #endif /* ALIAS */ |
132 | ||
133 | #if defined (PROMPT_STRING_DECODE) | |
cce855bc JA |
134 | # ifndef _MINIX |
135 | # include <sys/param.h> | |
136 | # endif | |
137 | # include <time.h> | |
7117c2d2 JA |
138 | # if defined (TM_IN_SYS_TIME) |
139 | # include <sys/types.h> | |
140 | # include <sys/time.h> | |
141 | # endif /* TM_IN_SYS_TIME */ | |
cce855bc | 142 | # include "maxpath.h" |
726f6388 JA |
143 | #endif /* PROMPT_STRING_DECODE */ |
144 | ||
ccc6cda3 JA |
145 | #define RE_READ_TOKEN -99 |
146 | #define NO_EXPANSION -100 | |
147 | ||
d233b485 CR |
148 | #define END_ALIAS -2 |
149 | ||
7117c2d2 JA |
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 | |
ccc6cda3 | 166 | |
74091dd4 CR |
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 | ||
cce855bc | 177 | #if defined (EXTENDED_GLOB) |
c7bb74de | 178 | extern int extended_glob, extglob_flag; |
cce855bc JA |
179 | #endif |
180 | ||
74091dd4 | 181 | #if defined (TRANSLATABLE_STRINGS) |
cce855bc | 182 | extern int dump_translatable_strings, dump_po_strings; |
74091dd4 CR |
183 | extern int singlequote_translations; |
184 | #endif /* TRANSLATABLE_STRINGS */ | |
726f6388 | 185 | |
d233b485 | 186 | #if !defined (errno) |
bb70624e | 187 | extern int errno; |
d233b485 CR |
188 | #endif |
189 | ||
726f6388 JA |
190 | /* **************************************************************** */ |
191 | /* */ | |
192 | /* "Forward" declarations */ | |
193 | /* */ | |
194 | /* **************************************************************** */ | |
195 | ||
f73dda09 | 196 | #ifdef DEBUG |
8868edaf | 197 | static void debug_parser PARAMS((int)); |
f73dda09 JA |
198 | #endif |
199 | ||
8868edaf CR |
200 | static int yy_getc PARAMS((void)); |
201 | static int yy_ungetc PARAMS((int)); | |
f73dda09 JA |
202 | |
203 | #if defined (READLINE) | |
8868edaf CR |
204 | static int yy_readline_get PARAMS((void)); |
205 | static int yy_readline_unget PARAMS((int)); | |
f73dda09 JA |
206 | #endif |
207 | ||
8868edaf CR |
208 | static int yy_string_get PARAMS((void)); |
209 | static int yy_string_unget PARAMS((int)); | |
8868edaf CR |
210 | static int yy_stream_get PARAMS((void)); |
211 | static int yy_stream_unget PARAMS((int)); | |
f73dda09 | 212 | |
8868edaf CR |
213 | static int shell_getc PARAMS((int)); |
214 | static void shell_ungetc PARAMS((int)); | |
215 | static void discard_until PARAMS((int)); | |
f73dda09 | 216 | |
8868edaf CR |
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)); | |
f73dda09 | 220 | |
8868edaf | 221 | static char *read_a_line PARAMS((int)); |
f73dda09 | 222 | |
8868edaf CR |
223 | static int reserved_word_acceptable PARAMS((int)); |
224 | static int yylex PARAMS((void)); | |
90a39f32 | 225 | |
8868edaf CR |
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)); | |
7117c2d2 | 234 | #if defined (ARRAY_VARS) |
8868edaf | 235 | static char *parse_compound_assignment PARAMS((int *)); |
7117c2d2 | 236 | #endif |
f73dda09 | 237 | #if defined (DPAREN_ARITHMETIC) || defined (ARITH_FOR_COMMAND) |
8868edaf CR |
238 | static int parse_dparen PARAMS((int)); |
239 | static int parse_arith_cmd PARAMS((char **, int)); | |
f73dda09 | 240 | #endif |
cce855bc | 241 | #if defined (COND_COMMAND) |
8868edaf CR |
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)); | |
cce855bc | 249 | #endif |
7117c2d2 | 250 | #if defined (ARRAY_VARS) |
8868edaf CR |
251 | static int token_is_assignment PARAMS((char *, int)); |
252 | static int token_is_ident PARAMS((char *, int)); | |
7117c2d2 | 253 | #endif |
8868edaf CR |
254 | static int read_token_word PARAMS((int)); |
255 | static void discard_parser_constructs PARAMS((int)); | |
726f6388 | 256 | |
8868edaf CR |
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 *)); | |
7117c2d2 | 261 | |
8868edaf | 262 | static void handle_eof_input_unit PARAMS((void)); |
74091dd4 | 263 | static void prompt_again PARAMS((int)); |
d166f048 | 264 | #if 0 |
8868edaf | 265 | static void reset_readline_prompt PARAMS((void)); |
d166f048 | 266 | #endif |
8868edaf | 267 | static void print_prompt PARAMS((void)); |
726f6388 | 268 | |
7117c2d2 | 269 | #if defined (HANDLE_MULTIBYTE) |
8868edaf | 270 | static void set_line_mbstate PARAMS((void)); |
7117c2d2 | 271 | static char *shell_input_line_property = NULL; |
d233b485 | 272 | static size_t shell_input_line_propsize = 0; |
7117c2d2 JA |
273 | #else |
274 | # define set_line_mbstate() | |
275 | #endif | |
276 | ||
8868edaf | 277 | extern int yyerror PARAMS((const char *)); |
d166f048 | 278 | |
7117c2d2 JA |
279 | #ifdef DEBUG |
280 | extern int yydebug; | |
281 | #endif | |
282 | ||
ccc6cda3 JA |
283 | /* Default prompt strings */ |
284 | char *primary_prompt = PPROMPT; | |
285 | char *secondary_prompt = SPROMPT; | |
286 | ||
726f6388 JA |
287 | /* PROMPT_STRING_POINTER points to one of these, never to an actual string. */ |
288 | char *ps1_prompt, *ps2_prompt; | |
289 | ||
a0c0a00f CR |
290 | /* Displayed after reading a command but before executing it in an interactive shell */ |
291 | char *ps0_prompt; | |
292 | ||
726f6388 JA |
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 | ||
ccc6cda3 JA |
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 | ||
b80f6443 JA |
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 | ||
726f6388 | 312 | /* The number of lines read from input while creating the current command. */ |
ccc6cda3 | 313 | int current_command_line_count; |
726f6388 | 314 | |
495aee44 CR |
315 | /* The number of lines in a command saved while we run parse_and_execute */ |
316 | int saved_command_line_count; | |
317 | ||
3185942a JA |
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 | ||
0001803f CR |
324 | /* The current parser state. */ |
325 | int parser_state; | |
326 | ||
726f6388 JA |
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. */ | |
90a39f32 | 329 | static REDIRECT *redir_stack[HEREDOC_MAX]; |
ccc6cda3 | 330 | int need_here_doc; |
726f6388 JA |
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; | |
ac50fbac CR |
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) */ | |
726f6388 JA |
338 | |
339 | /* Either zero or EOF. */ | |
ccc6cda3 JA |
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; | |
726f6388 | 347 | |
bb70624e JA |
348 | /* The line number in a script at which an arithmetic for command starts. */ |
349 | static int arith_for_lineno; | |
350 | ||
0001803f CR |
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; | |
3185942a JA |
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 | ||
0001803f CR |
365 | static int global_extglob; |
366 | ||
b80f6443 JA |
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 | |
90a39f32 | 371 | static int word_lineno[MAX_CASE_NEST+1]; |
b80f6443 JA |
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 | ||
0001803f | 381 | static REDIRECTEE source; |
726f6388 | 382 | static REDIRECTEE redir; |
f73dda09 | 383 | |
d233b485 CR |
384 | static FILE *yyoutstream; |
385 | static FILE *yyerrstream; | |
386 | ||
74091dd4 | 387 | #line 388 "y.tab.c" |
3185942a | 388 | |
8868edaf CR |
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 | |
a0c0a00f | 398 | # ifndef YY_NULLPTR |
8868edaf CR |
399 | # if defined __cplusplus |
400 | # if 201103L <= __cplusplus | |
401 | # define YY_NULLPTR nullptr | |
402 | # else | |
403 | # define YY_NULLPTR 0 | |
404 | # endif | |
a0c0a00f | 405 | # else |
8868edaf | 406 | # define YY_NULLPTR ((void*)0) |
a0c0a00f CR |
407 | # endif |
408 | # endif | |
3185942a | 409 | |
8868edaf CR |
410 | /* Use api.header.include to #include this header |
411 | instead of duplicating it here. */ | |
a0c0a00f CR |
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; | |
3185942a JA |
420 | #endif |
421 | ||
8868edaf | 422 | /* Token kinds. */ |
a0c0a00f CR |
423 | #ifndef YYTOKENTYPE |
424 | # define YYTOKENTYPE | |
425 | enum yytokentype | |
426 | { | |
8868edaf CR |
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 */ | |
74091dd4 CR |
477 | DOLPAREN = 304, /* DOLPAREN */ |
478 | yacc_EOF = 305 /* yacc_EOF */ | |
a0c0a00f | 479 | }; |
8868edaf | 480 | typedef enum yytokentype yytoken_kind_t; |
a0c0a00f | 481 | #endif |
8868edaf | 482 | /* Token kinds. */ |
74091dd4 | 483 | #define YYEMPTY -2 |
8868edaf CR |
484 | #define YYEOF 0 |
485 | #define YYerror 256 | |
486 | #define YYUNDEF 257 | |
a0c0a00f CR |
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 | |
74091dd4 CR |
533 | #define DOLPAREN 304 |
534 | #define yacc_EOF 305 | |
a0c0a00f CR |
535 | |
536 | /* Value type. */ | |
3185942a | 537 | #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED |
a0c0a00f | 538 | union YYSTYPE |
3185942a | 539 | { |
74091dd4 | 540 | #line 338 "/usr/local/src/chet/src/bash/src/parse.y" |
a0c0a00f | 541 | |
726f6388 JA |
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; | |
a0c0a00f | 549 | |
74091dd4 | 550 | #line 551 "y.tab.c" |
a0c0a00f | 551 | |
8868edaf | 552 | }; |
a0c0a00f | 553 | typedef union YYSTYPE YYSTYPE; |
3185942a | 554 | # define YYSTYPE_IS_TRIVIAL 1 |
a0c0a00f | 555 | # define YYSTYPE_IS_DECLARED 1 |
3185942a JA |
556 | #endif |
557 | ||
558 | ||
a0c0a00f | 559 | extern YYSTYPE yylval; |
3185942a | 560 | |
74091dd4 | 561 | |
a0c0a00f | 562 | int yyparse (void); |
3185942a | 563 | |
74091dd4 | 564 | |
a0c0a00f | 565 | #endif /* !YY_YY_Y_TAB_H_INCLUDED */ |
8868edaf CR |
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 */ | |
74091dd4 CR |
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 */ | |
8868edaf CR |
670 | }; |
671 | typedef enum yysymbol_kind_t yysymbol_kind_t; | |
672 | ||
3185942a | 673 | |
a0c0a00f | 674 | |
b80f6443 | 675 | |
3185942a JA |
676 | #ifdef short |
677 | # undef short | |
f73dda09 | 678 | #endif |
3185942a | 679 | |
8868edaf CR |
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 | |
f73dda09 JA |
690 | #endif |
691 | ||
8868edaf CR |
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; | |
3185942a | 701 | #else |
a0c0a00f | 702 | typedef signed char yytype_int8; |
3185942a | 703 | #endif |
f73dda09 | 704 | |
8868edaf CR |
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 | ||
74091dd4 CR |
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 | ||
8868edaf CR |
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; | |
3185942a | 732 | #else |
8868edaf | 733 | typedef short yytype_uint8; |
3185942a | 734 | #endif |
f73dda09 | 735 | |
8868edaf CR |
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; | |
3185942a | 743 | #else |
8868edaf CR |
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 | |
3185942a | 761 | #endif |
f73dda09 | 762 | |
3185942a JA |
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 | |
8868edaf | 768 | # elif defined __STDC_VERSION__ && 199901 <= __STDC_VERSION__ |
3185942a JA |
769 | # include <stddef.h> /* INFRINGES ON USER NAME SPACE */ |
770 | # define YYSIZE_T size_t | |
771 | # else | |
8868edaf | 772 | # define YYSIZE_T unsigned |
3185942a JA |
773 | # endif |
774 | #endif | |
b80f6443 | 775 | |
8868edaf CR |
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; | |
f73dda09 | 790 | |
3185942a | 791 | #ifndef YY_ |
509a4430 | 792 | # if defined YYENABLE_NLS && YYENABLE_NLS |
3185942a JA |
793 | # if ENABLE_NLS |
794 | # include <libintl.h> /* INFRINGES ON USER NAME SPACE */ | |
a0c0a00f | 795 | # define YY_(Msgid) dgettext ("bison-runtime", Msgid) |
3185942a JA |
796 | # endif |
797 | # endif | |
798 | # ifndef YY_ | |
a0c0a00f CR |
799 | # define YY_(Msgid) Msgid |
800 | # endif | |
801 | #endif | |
802 | ||
a0c0a00f CR |
803 | |
804 | #ifndef YY_ATTRIBUTE_PURE | |
8868edaf CR |
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 | |
a0c0a00f CR |
810 | #endif |
811 | ||
812 | #ifndef YY_ATTRIBUTE_UNUSED | |
8868edaf CR |
813 | # if defined __GNUC__ && 2 < __GNUC__ + (7 <= __GNUC_MINOR__) |
814 | # define YY_ATTRIBUTE_UNUSED __attribute__ ((__unused__)) | |
a0c0a00f | 815 | # else |
8868edaf | 816 | # define YY_ATTRIBUTE_UNUSED |
3185942a | 817 | # endif |
f73dda09 JA |
818 | #endif |
819 | ||
3185942a JA |
820 | /* Suppress unused-variable warnings by "using" E. */ |
821 | #if ! defined lint || defined __GNUC__ | |
74091dd4 | 822 | # define YY_USE(E) ((void) (E)) |
3185942a | 823 | #else |
74091dd4 | 824 | # define YY_USE(E) /* empty */ |
f73dda09 JA |
825 | #endif |
826 | ||
a0c0a00f | 827 | /* Suppress an incorrect diagnostic about yylval being uninitialized. */ |
74091dd4 CR |
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 \ | |
8868edaf CR |
835 | _Pragma ("GCC diagnostic push") \ |
836 | _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"") \ | |
a0c0a00f | 837 | _Pragma ("GCC diagnostic ignored \"-Wmaybe-uninitialized\"") |
74091dd4 | 838 | # endif |
8868edaf | 839 | # define YY_IGNORE_MAYBE_UNINITIALIZED_END \ |
a0c0a00f | 840 | _Pragma ("GCC diagnostic pop") |
3185942a | 841 | #else |
a0c0a00f | 842 | # define YY_INITIAL_VALUE(Value) Value |
3185942a | 843 | #endif |
a0c0a00f CR |
844 | #ifndef YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN |
845 | # define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN | |
846 | # define YY_IGNORE_MAYBE_UNINITIALIZED_END | |
3185942a | 847 | #endif |
a0c0a00f CR |
848 | #ifndef YY_INITIAL_VALUE |
849 | # define YY_INITIAL_VALUE(Value) /* Nothing. */ | |
850 | #endif | |
851 | ||
8868edaf CR |
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 | ||
3185942a | 864 | |
8868edaf CR |
865 | #define YY_ASSERT(E) ((void) (0 && (E))) |
866 | ||
867 | #if !defined yyoverflow | |
3185942a JA |
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 | |
a0c0a00f | 884 | # if ! defined _ALLOCA_H && ! defined EXIT_SUCCESS |
3185942a | 885 | # include <stdlib.h> /* INFRINGES ON USER NAME SPACE */ |
a0c0a00f CR |
886 | /* Use EXIT_SUCCESS as a witness for stdlib.h. */ |
887 | # ifndef EXIT_SUCCESS | |
888 | # define EXIT_SUCCESS 0 | |
3185942a JA |
889 | # endif |
890 | # endif | |
891 | # endif | |
892 | # endif | |
893 | # endif | |
894 | ||
895 | # ifdef YYSTACK_ALLOC | |
a0c0a00f CR |
896 | /* Pacify GCC's 'empty if-body' warning. */ |
897 | # define YYSTACK_FREE(Ptr) do { /* empty */; } while (0) | |
3185942a JA |
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 | |
a0c0a00f | 911 | # if (defined __cplusplus && ! defined EXIT_SUCCESS \ |
3185942a | 912 | && ! ((defined YYMALLOC || defined malloc) \ |
a0c0a00f | 913 | && (defined YYFREE || defined free))) |
3185942a | 914 | # include <stdlib.h> /* INFRINGES ON USER NAME SPACE */ |
a0c0a00f CR |
915 | # ifndef EXIT_SUCCESS |
916 | # define EXIT_SUCCESS 0 | |
3185942a JA |
917 | # endif |
918 | # endif | |
919 | # ifndef YYMALLOC | |
920 | # define YYMALLOC malloc | |
a0c0a00f | 921 | # if ! defined malloc && ! defined EXIT_SUCCESS |
3185942a JA |
922 | void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */ |
923 | # endif | |
924 | # endif | |
925 | # ifndef YYFREE | |
926 | # define YYFREE free | |
a0c0a00f | 927 | # if ! defined free && ! defined EXIT_SUCCESS |
3185942a JA |
928 | void free (void *); /* INFRINGES ON USER NAME SPACE */ |
929 | # endif | |
930 | # endif | |
931 | # endif | |
8868edaf | 932 | #endif /* !defined yyoverflow */ |
3185942a JA |
933 | |
934 | #if (! defined yyoverflow \ | |
935 | && (! defined __cplusplus \ | |
a0c0a00f | 936 | || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL))) |
3185942a JA |
937 | |
938 | /* A type that is properly aligned for any stack member. */ | |
939 | union yyalloc | |
940 | { | |
8868edaf | 941 | yy_state_t yyss_alloc; |
a0c0a00f CR |
942 | YYSTYPE yyvs_alloc; |
943 | }; | |
3185942a JA |
944 | |
945 | /* The size of the maximum gap between one aligned stack and the next. */ | |
8868edaf | 946 | # define YYSTACK_GAP_MAXIMUM (YYSIZEOF (union yyalloc) - 1) |
3185942a JA |
947 | |
948 | /* The size of an array large to enough to hold all stacks, each with | |
949 | N elements. */ | |
950 | # define YYSTACK_BYTES(N) \ | |
8868edaf | 951 | ((N) * (YYSIZEOF (yy_state_t) + YYSIZEOF (YYSTYPE)) \ |
3185942a JA |
952 | + YYSTACK_GAP_MAXIMUM) |
953 | ||
a0c0a00f | 954 | # define YYCOPY_NEEDED 1 |
3185942a JA |
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. */ | |
a0c0a00f CR |
961 | # define YYSTACK_RELOCATE(Stack_alloc, Stack) \ |
962 | do \ | |
963 | { \ | |
8868edaf | 964 | YYPTRDIFF_T yynewbytes; \ |
a0c0a00f CR |
965 | YYCOPY (&yyptr->Stack_alloc, Stack, yysize); \ |
966 | Stack = &yyptr->Stack_alloc; \ | |
8868edaf CR |
967 | yynewbytes = yystacksize * YYSIZEOF (*Stack) + YYSTACK_GAP_MAXIMUM; \ |
968 | yyptr += yynewbytes / YYSIZEOF (*yyptr); \ | |
a0c0a00f CR |
969 | } \ |
970 | while (0) | |
f73dda09 | 971 | |
f73dda09 JA |
972 | #endif |
973 | ||
a0c0a00f CR |
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) \ | |
8868edaf | 980 | __builtin_memcpy (Dst, Src, YY_CAST (YYSIZE_T, (Count)) * sizeof (*(Src))) |
a0c0a00f CR |
981 | # else |
982 | # define YYCOPY(Dst, Src, Count) \ | |
983 | do \ | |
984 | { \ | |
8868edaf | 985 | YYPTRDIFF_T yyi; \ |
a0c0a00f CR |
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 | ||
3185942a | 994 | /* YYFINAL -- State number of the termination state. */ |
a78e27a1 | 995 | #define YYFINAL 122 |
3185942a | 996 | /* YYLAST -- Last index in YYTABLE. */ |
74091dd4 | 997 | #define YYLAST 740 |
3185942a JA |
998 | |
999 | /* YYNTOKENS -- Number of terminals. */ | |
74091dd4 | 1000 | #define YYNTOKENS 62 |
3185942a JA |
1001 | /* YYNNTS -- Number of nonterminals. */ |
1002 | #define YYNNTS 38 | |
1003 | /* YYNRULES -- Number of rules. */ | |
a78e27a1 | 1004 | #define YYNRULES 175 |
a0c0a00f | 1005 | /* YYNSTATES -- Number of states. */ |
a78e27a1 | 1006 | #define YYNSTATES 350 |
3185942a | 1007 | |
74091dd4 CR |
1008 | /* YYMAXUTOK -- Last valid token kind. */ |
1009 | #define YYMAXUTOK 305 | |
3185942a | 1010 | |
8868edaf CR |
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) | |
3185942a | 1018 | |
a0c0a00f | 1019 | /* YYTRANSLATE[TOKEN-NUM] -- Symbol number corresponding to TOKEN-NUM |
8868edaf CR |
1020 | as returned by yylex. */ |
1021 | static const yytype_int8 yytranslate[] = | |
3185942a JA |
1022 | { |
1023 | 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
74091dd4 | 1024 | 52, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
3185942a | 1025 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
74091dd4 CR |
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, | |
3185942a JA |
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, | |
74091dd4 | 1035 | 2, 2, 2, 58, 54, 59, 2, 2, 2, 2, |
3185942a JA |
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, | |
74091dd4 | 1053 | 45, 46, 47, 48, 49, 53 |
726f6388 | 1054 | }; |
f73dda09 | 1055 | |
3185942a | 1056 | #if YYDEBUG |
74091dd4 | 1057 | /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */ |
8868edaf | 1058 | static const yytype_int16 yyrline[] = |
3185942a | 1059 | { |
a78e27a1 CR |
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 | |
726f6388 | 1078 | }; |
3185942a | 1079 | #endif |
f73dda09 | 1080 | |
8868edaf CR |
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 | ||
3185942a JA |
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 | { | |
8868edaf CR |
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", | |
495aee44 CR |
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", | |
74091dd4 CR |
1101 | "LESS_GREATER", "GREATER_BAR", "BAR_AND", "DOLPAREN", "'&'", "';'", |
1102 | "'\\n'", "yacc_EOF", "'|'", "'>'", "'<'", "'-'", "'{'", "'}'", "'('", | |
1103 | "')'", "$accept", "inputunit", "word_list", "redirection", | |
495aee44 CR |
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", | |
74091dd4 CR |
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 | |
726f6388 | 1113 | }; |
8868edaf CR |
1114 | |
1115 | static const char * | |
1116 | yysymbol_name (yysymbol_kind_t yysymbol) | |
1117 | { | |
1118 | return yytname[yysymbol]; | |
1119 | } | |
3185942a | 1120 | #endif |
f73dda09 | 1121 | |
a78e27a1 | 1122 | #define YYPACT_NINF (-125) |
f73dda09 | 1123 | |
8868edaf CR |
1124 | #define yypact_value_is_default(Yyn) \ |
1125 | ((Yyn) == YYPACT_NINF) | |
a0c0a00f | 1126 | |
8868edaf | 1127 | #define YYTABLE_NINF (-1) |
a0c0a00f | 1128 | |
8868edaf | 1129 | #define yytable_value_is_error(Yyn) \ |
a0c0a00f CR |
1130 | 0 |
1131 | ||
74091dd4 CR |
1132 | /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing |
1133 | STATE-NUM. */ | |
a0c0a00f | 1134 | static const yytype_int16 yypact[] = |
3185942a | 1135 | { |
a78e27a1 CR |
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 | |
3185942a | 1171 | }; |
f73dda09 | 1172 | |
74091dd4 CR |
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. */ | |
3185942a JA |
1176 | static const yytype_uint8 yydefact[] = |
1177 | { | |
a78e27a1 CR |
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, | |
8868edaf | 1187 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
a78e27a1 CR |
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 | |
726f6388 | 1213 | }; |
f73dda09 | 1214 | |
74091dd4 | 1215 | /* YYPGOTO[NTERM-NUM]. */ |
a0c0a00f | 1216 | static const yytype_int16 yypgoto[] = |
3185942a | 1217 | { |
a78e27a1 CR |
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 | |
3185942a | 1222 | }; |
f73dda09 | 1223 | |
74091dd4 | 1224 | /* YYDEFGOTO[NTERM-NUM]. */ |
a0c0a00f | 1225 | static const yytype_int16 yydefgoto[] = |
3185942a | 1226 | { |
a78e27a1 CR |
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 | |
3185942a | 1231 | }; |
f73dda09 | 1232 | |
74091dd4 CR |
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. */ | |
8868edaf | 1236 | static const yytype_int16 yytable[] = |
3185942a | 1237 | { |
a78e27a1 CR |
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, | |
74091dd4 | 1274 | 0, 0, 0, 0, 18, 19, 20, 21, 22, 0, |
a78e27a1 CR |
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, | |
74091dd4 CR |
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, | |
a78e27a1 | 1286 | 26, 27, 0, 0, 0, 74, 75, 76, 2, 31, |
74091dd4 CR |
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, | |
a78e27a1 | 1291 | 25, 26, 27, 0, 0, 0, 0, 139, 0, 2, |
74091dd4 | 1292 | 31, 32, 0, 33, 3, 34, 4, 5, 6, 7, |
a78e27a1 | 1293 | 0, 0, 8, 9, 10, 0, 0, 0, 11, 12, |
74091dd4 CR |
1294 | 0, 0, 13, 14, 15, 16, 17, 0, 0, 0, |
1295 | 0, 18, 19, 20, 21, 22, 0, 0, 0, 23, | |
a78e27a1 | 1296 | 24, 25, 26, 27, 0, 0, 0, 0, 0, 0, |
74091dd4 | 1297 | 2, 31, 32, 0, 33, 3, 34, 4, 5, 6, |
a78e27a1 CR |
1298 | 7, 0, 0, 8, 9, 10, 0, 0, 0, 0, |
1299 | 0, 0, 0, 13, 14, 15, 16, 17, 0, 0, | |
74091dd4 | 1300 | 0, 0, 18, 19, 20, 21, 22, 0, 0, 0, |
a78e27a1 CR |
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 | |
3185942a | 1313 | }; |
f73dda09 | 1314 | |
3185942a JA |
1315 | static const yytype_int16 yycheck[] = |
1316 | { | |
a78e27a1 CR |
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, | |
74091dd4 | 1353 | -1, -1, -1, -1, 35, 36, 37, 38, 39, -1, |
a78e27a1 CR |
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, | |
74091dd4 CR |
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, | |
a78e27a1 | 1365 | 46, 47, -1, -1, -1, 51, 52, 53, 3, 55, |
74091dd4 CR |
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, | |
a78e27a1 | 1370 | 45, 46, 47, -1, -1, -1, -1, 52, -1, 3, |
74091dd4 | 1371 | 55, 56, -1, 58, 8, 60, 10, 11, 12, 13, |
a78e27a1 | 1372 | -1, -1, 16, 17, 18, -1, -1, -1, 22, 23, |
74091dd4 CR |
1373 | -1, -1, 26, 27, 28, 29, 30, -1, -1, -1, |
1374 | -1, 35, 36, 37, 38, 39, -1, -1, -1, 43, | |
a78e27a1 | 1375 | 44, 45, 46, 47, -1, -1, -1, -1, -1, -1, |
74091dd4 | 1376 | 3, 55, 56, -1, 58, 8, 60, 10, 11, 12, |
a78e27a1 | 1377 | 13, -1, -1, 16, 17, 18, -1, -1, -1, -1, |
74091dd4 CR |
1378 | -1, -1, -1, 26, 27, 28, 29, 30, -1, -1, |
1379 | -1, -1, 35, 36, 37, 38, 39, -1, -1, -1, | |
a78e27a1 CR |
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, | |
74091dd4 CR |
1389 | 36, 37, 38, 39, -1, 55, 56, 43, -1, -1, |
1390 | 46, 47, -1, -1, -1, -1, -1, -1, -1, 55, | |
1391 | 56 | |
3185942a | 1392 | }; |
f73dda09 | 1393 | |
74091dd4 CR |
1394 | /* YYSTOS[STATE-NUM] -- The symbol kind of the accessing symbol of |
1395 | state STATE-NUM. */ | |
8868edaf | 1396 | static const yytype_int8 yystos[] = |
3185942a JA |
1397 | { |
1398 | 0, 1, 3, 8, 10, 11, 12, 13, 16, 17, | |
495aee44 | 1399 | 18, 22, 23, 26, 27, 28, 29, 30, 35, 36, |
74091dd4 CR |
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, | |
a78e27a1 CR |
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 | |
3185942a | 1433 | }; |
b80f6443 | 1434 | |
74091dd4 | 1435 | /* YYR1[RULE-NUM] -- Symbol kind of the left-hand side of rule RULE-NUM. */ |
8868edaf | 1436 | static const yytype_int8 yyr1[] = |
a0c0a00f | 1437 | { |
a78e27a1 CR |
1438 | 0, 62, 63, 63, 63, 63, 63, 63, 63, 64, |
1439 | 64, 65, 65, 65, 65, 65, 65, 65, 65, 65, | |
74091dd4 CR |
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, | |
a78e27a1 CR |
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 | |
a0c0a00f CR |
1456 | }; |
1457 | ||
74091dd4 | 1458 | /* YYR2[RULE-NUM] -- Number of symbols on the right-hand side of rule RULE-NUM. */ |
8868edaf | 1459 | static const yytype_int8 yyr2[] = |
a0c0a00f | 1460 | { |
a78e27a1 CR |
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, | |
74091dd4 | 1464 | 3, 3, 2, 3, 3, 2, 3, 3, 2, 3, |
d233b485 | 1465 | 3, 2, 3, 3, 2, 3, 3, 2, 3, 3, |
a78e27a1 CR |
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 | |
a0c0a00f | 1479 | }; |
3185942a | 1480 | |
3185942a | 1481 | |
8868edaf CR |
1482 | enum { YYENOMEM = -2 }; |
1483 | ||
a0c0a00f CR |
1484 | #define yyerrok (yyerrstatus = 0) |
1485 | #define yyclearin (yychar = YYEMPTY) | |
3185942a | 1486 | |
a0c0a00f CR |
1487 | #define YYACCEPT goto yyacceptlab |
1488 | #define YYABORT goto yyabortlab | |
1489 | #define YYERROR goto yyerrorlab | |
74091dd4 | 1490 | #define YYNOMEM goto yyexhaustedlab |
3185942a | 1491 | |
3185942a | 1492 | |
f73dda09 | 1493 | #define YYRECOVERING() (!!yyerrstatus) |
3185942a | 1494 | |
8868edaf CR |
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) | |
3185942a | 1511 | |
8868edaf CR |
1512 | /* Backward compatibility with an undocumented macro. |
1513 | Use YYerror or YYUNDEF. */ | |
1514 | #define YYERRCODE YYUNDEF | |
3185942a | 1515 | |
3185942a JA |
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 | ||
a0c0a00f CR |
1525 | # define YYDPRINTF(Args) \ |
1526 | do { \ | |
1527 | if (yydebug) \ | |
1528 | YYFPRINTF Args; \ | |
1529 | } while (0) | |
1530 | ||
74091dd4 | 1531 | |
3185942a | 1532 | |
3185942a | 1533 | |
8868edaf | 1534 | # define YY_SYMBOL_PRINT(Title, Kind, Value, Location) \ |
a0c0a00f CR |
1535 | do { \ |
1536 | if (yydebug) \ | |
1537 | { \ | |
1538 | YYFPRINTF (stderr, "%s ", Title); \ | |
1539 | yy_symbol_print (stderr, \ | |
8868edaf | 1540 | Kind, Value); \ |
a0c0a00f CR |
1541 | YYFPRINTF (stderr, "\n"); \ |
1542 | } \ | |
1543 | } while (0) | |
3185942a | 1544 | |
3185942a | 1545 | |
8868edaf CR |
1546 | /*-----------------------------------. |
1547 | | Print this symbol's value on YYO. | | |
1548 | `-----------------------------------*/ | |
a0c0a00f | 1549 | |
3185942a | 1550 | static void |
8868edaf CR |
1551 | yy_symbol_value_print (FILE *yyo, |
1552 | yysymbol_kind_t yykind, YYSTYPE const * const yyvaluep) | |
3185942a | 1553 | { |
8868edaf | 1554 | FILE *yyoutput = yyo; |
74091dd4 | 1555 | YY_USE (yyoutput); |
3185942a JA |
1556 | if (!yyvaluep) |
1557 | return; | |
8868edaf | 1558 | YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN |
74091dd4 | 1559 | YY_USE (yykind); |
8868edaf | 1560 | YY_IGNORE_MAYBE_UNINITIALIZED_END |
3185942a JA |
1561 | } |
1562 | ||
1563 | ||
8868edaf CR |
1564 | /*---------------------------. |
1565 | | Print this symbol on YYO. | | |
1566 | `---------------------------*/ | |
b80f6443 | 1567 | |
3185942a | 1568 | static void |
8868edaf CR |
1569 | yy_symbol_print (FILE *yyo, |
1570 | yysymbol_kind_t yykind, YYSTYPE const * const yyvaluep) | |
3185942a | 1571 | { |
8868edaf CR |
1572 | YYFPRINTF (yyo, "%s %s (", |
1573 | yykind < YYNTOKENS ? "token" : "nterm", yysymbol_name (yykind)); | |
726f6388 | 1574 | |
8868edaf CR |
1575 | yy_symbol_value_print (yyo, yykind, yyvaluep); |
1576 | YYFPRINTF (yyo, ")"); | |
3185942a | 1577 | } |
726f6388 | 1578 | |
3185942a JA |
1579 | /*------------------------------------------------------------------. |
1580 | | yy_stack_print -- Print the state stack from its BOTTOM up to its | | |
1581 | | TOP (included). | | |
1582 | `------------------------------------------------------------------*/ | |
b80f6443 | 1583 | |
3185942a | 1584 | static void |
8868edaf | 1585 | yy_stack_print (yy_state_t *yybottom, yy_state_t *yytop) |
3185942a JA |
1586 | { |
1587 | YYFPRINTF (stderr, "Stack now"); | |
a0c0a00f CR |
1588 | for (; yybottom <= yytop; yybottom++) |
1589 | { | |
1590 | int yybot = *yybottom; | |
1591 | YYFPRINTF (stderr, " %d", yybot); | |
1592 | } | |
3185942a JA |
1593 | YYFPRINTF (stderr, "\n"); |
1594 | } | |
726f6388 | 1595 | |
a0c0a00f CR |
1596 | # define YY_STACK_PRINT(Bottom, Top) \ |
1597 | do { \ | |
1598 | if (yydebug) \ | |
1599 | yy_stack_print ((Bottom), (Top)); \ | |
1600 | } while (0) | |
726f6388 | 1601 | |
3185942a JA |
1602 | |
1603 | /*------------------------------------------------. | |
1604 | | Report that the YYRULE is going to be reduced. | | |
1605 | `------------------------------------------------*/ | |
1606 | ||
3185942a | 1607 | static void |
8868edaf CR |
1608 | yy_reduce_print (yy_state_t *yyssp, YYSTYPE *yyvsp, |
1609 | int yyrule) | |
3185942a | 1610 | { |
8868edaf | 1611 | int yylno = yyrline[yyrule]; |
3185942a JA |
1612 | int yynrhs = yyr2[yyrule]; |
1613 | int yyi; | |
8868edaf | 1614 | YYFPRINTF (stderr, "Reducing stack by rule %d (line %d):\n", |
a0c0a00f | 1615 | yyrule - 1, yylno); |
3185942a JA |
1616 | /* The symbols being reduced. */ |
1617 | for (yyi = 0; yyi < yynrhs; yyi++) | |
1618 | { | |
a0c0a00f CR |
1619 | YYFPRINTF (stderr, " $%d = ", yyi + 1); |
1620 | yy_symbol_print (stderr, | |
8868edaf CR |
1621 | YY_ACCESSING_SYMBOL (+yyssp[yyi + 1 - yynrhs]), |
1622 | &yyvsp[(yyi + 1) - (yynrhs)]); | |
a0c0a00f | 1623 | YYFPRINTF (stderr, "\n"); |
3185942a JA |
1624 | } |
1625 | } | |
1626 | ||
a0c0a00f CR |
1627 | # define YY_REDUCE_PRINT(Rule) \ |
1628 | do { \ | |
1629 | if (yydebug) \ | |
1630 | yy_reduce_print (yyssp, yyvsp, Rule); \ | |
1631 | } while (0) | |
b80f6443 | 1632 | |
3185942a JA |
1633 | /* Nonzero means print parse trace. It is left uninitialized so that |
1634 | multiple parsers can coexist. */ | |
1635 | int yydebug; | |
1636 | #else /* !YYDEBUG */ | |
8868edaf CR |
1637 | # define YYDPRINTF(Args) ((void) 0) |
1638 | # define YY_SYMBOL_PRINT(Title, Kind, Value, Location) | |
3185942a JA |
1639 | # define YY_STACK_PRINT(Bottom, Top) |
1640 | # define YY_REDUCE_PRINT(Rule) | |
1641 | #endif /* !YYDEBUG */ | |
726f6388 | 1642 | |
3185942a JA |
1643 | |
1644 | /* YYINITDEPTH -- initial size of the parser's stacks. */ | |
a0c0a00f | 1645 | #ifndef YYINITDEPTH |
3185942a | 1646 | # define YYINITDEPTH 200 |
f73dda09 | 1647 | #endif |
726f6388 | 1648 | |
3185942a JA |
1649 | /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only |
1650 | if the built-in stack extension method is used). | |
726f6388 | 1651 | |
3185942a JA |
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. */ | |
726f6388 | 1655 | |
f73dda09 | 1656 | #ifndef YYMAXDEPTH |
3185942a | 1657 | # define YYMAXDEPTH 10000 |
f73dda09 | 1658 | #endif |
3185942a | 1659 | |
3185942a | 1660 | |
3185942a | 1661 | |
3185942a | 1662 | |
a0c0a00f | 1663 | |
726f6388 | 1664 | |
3185942a JA |
1665 | /*-----------------------------------------------. |
1666 | | Release the memory associated to this symbol. | | |
1667 | `-----------------------------------------------*/ | |
726f6388 | 1668 | |
3185942a | 1669 | static void |
8868edaf CR |
1670 | yydestruct (const char *yymsg, |
1671 | yysymbol_kind_t yykind, YYSTYPE *yyvaluep) | |
7117c2d2 | 1672 | { |
74091dd4 | 1673 | YY_USE (yyvaluep); |
3185942a JA |
1674 | if (!yymsg) |
1675 | yymsg = "Deleting"; | |
8868edaf | 1676 | YY_SYMBOL_PRINT (yymsg, yykind, yyvaluep, yylocationp); |
b80f6443 | 1677 | |
a0c0a00f | 1678 | YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN |
74091dd4 | 1679 | YY_USE (yykind); |
a0c0a00f | 1680 | YY_IGNORE_MAYBE_UNINITIALIZED_END |
3185942a | 1681 | } |
f73dda09 | 1682 | |
3185942a | 1683 | |
74091dd4 | 1684 | /* Lookahead token kind. */ |
3185942a | 1685 | int yychar; |
b80f6443 | 1686 | |
a0c0a00f | 1687 | /* The semantic value of the lookahead symbol. */ |
3185942a | 1688 | YYSTYPE yylval; |
3185942a JA |
1689 | /* Number of syntax errors so far. */ |
1690 | int yynerrs; | |
726f6388 | 1691 | |
3185942a | 1692 | |
8868edaf CR |
1693 | |
1694 | ||
3185942a JA |
1695 | /*----------. |
1696 | | yyparse. | | |
1697 | `----------*/ | |
1698 | ||
3185942a JA |
1699 | int |
1700 | yyparse (void) | |
3185942a | 1701 | { |
74091dd4 | 1702 | yy_state_fast_t yystate = 0; |
a0c0a00f | 1703 | /* Number of tokens to shift before error messages enabled. */ |
74091dd4 | 1704 | int yyerrstatus = 0; |
a0c0a00f | 1705 | |
74091dd4 | 1706 | /* Refer to the stacks through separate pointers, to allow yyoverflow |
a0c0a00f CR |
1707 | to reallocate them elsewhere. */ |
1708 | ||
8868edaf | 1709 | /* Their size. */ |
74091dd4 | 1710 | YYPTRDIFF_T yystacksize = YYINITDEPTH; |
8868edaf | 1711 | |
74091dd4 | 1712 | /* The state stack: array, bottom, top. */ |
8868edaf | 1713 | yy_state_t yyssa[YYINITDEPTH]; |
74091dd4 CR |
1714 | yy_state_t *yyss = yyssa; |
1715 | yy_state_t *yyssp = yyss; | |
a0c0a00f | 1716 | |
74091dd4 | 1717 | /* The semantic value stack: array, bottom, top. */ |
a0c0a00f | 1718 | YYSTYPE yyvsa[YYINITDEPTH]; |
74091dd4 CR |
1719 | YYSTYPE *yyvs = yyvsa; |
1720 | YYSTYPE *yyvsp = yyvs; | |
a0c0a00f | 1721 | |
3185942a | 1722 | int yyn; |
8868edaf | 1723 | /* The return value of yyparse. */ |
3185942a | 1724 | int yyresult; |
74091dd4 | 1725 | /* Lookahead symbol kind. */ |
8868edaf | 1726 | yysymbol_kind_t yytoken = YYSYMBOL_YYEMPTY; |
a0c0a00f CR |
1727 | /* The variables used to return semantic value and location from the |
1728 | action routines. */ | |
1729 | YYSTYPE yyval; | |
1730 | ||
8868edaf | 1731 | |
726f6388 | 1732 | |
3185942a JA |
1733 | #define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N)) |
1734 | ||
3185942a JA |
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")); | |
726f6388 | 1740 | |
a0c0a00f | 1741 | yychar = YYEMPTY; /* Cause a token to be read. */ |
74091dd4 | 1742 | |
3185942a | 1743 | goto yysetstate; |
f73dda09 | 1744 | |
8868edaf | 1745 | |
3185942a | 1746 | /*------------------------------------------------------------. |
8868edaf | 1747 | | yynewstate -- push a new state, which is found in yystate. | |
3185942a | 1748 | `------------------------------------------------------------*/ |
8868edaf | 1749 | yynewstate: |
3185942a JA |
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++; | |
f73dda09 | 1753 | |
8868edaf CR |
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); | |
b80f6443 | 1765 | |
3185942a | 1766 | if (yyss + yystacksize - 1 <= yyssp) |
8868edaf | 1767 | #if !defined yyoverflow && !defined YYSTACK_RELOCATE |
74091dd4 | 1768 | YYNOMEM; |
8868edaf | 1769 | #else |
3185942a | 1770 | { |
f73dda09 | 1771 | /* Get the current used size of the three stacks, in elements. */ |
8868edaf | 1772 | YYPTRDIFF_T yysize = yyssp - yyss + 1; |
f73dda09 | 1773 | |
8868edaf | 1774 | # if defined yyoverflow |
3185942a | 1775 | { |
a0c0a00f CR |
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. */ | |
8868edaf | 1779 | yy_state_t *yyss1 = yyss; |
a0c0a00f | 1780 | YYSTYPE *yyvs1 = yyvs; |
a0c0a00f CR |
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"), | |
8868edaf CR |
1787 | &yyss1, yysize * YYSIZEOF (*yyssp), |
1788 | &yyvs1, yysize * YYSIZEOF (*yyvsp), | |
a0c0a00f | 1789 | &yystacksize); |
a0c0a00f CR |
1790 | yyss = yyss1; |
1791 | yyvs = yyvs1; | |
3185942a | 1792 | } |
8868edaf | 1793 | # else /* defined YYSTACK_RELOCATE */ |
f73dda09 | 1794 | /* Extend the stack our own way. */ |
3185942a | 1795 | if (YYMAXDEPTH <= yystacksize) |
74091dd4 | 1796 | YYNOMEM; |
f73dda09 | 1797 | yystacksize *= 2; |
3185942a | 1798 | if (YYMAXDEPTH < yystacksize) |
a0c0a00f | 1799 | yystacksize = YYMAXDEPTH; |
3185942a JA |
1800 | |
1801 | { | |
8868edaf | 1802 | yy_state_t *yyss1 = yyss; |
a0c0a00f | 1803 | union yyalloc *yyptr = |
8868edaf CR |
1804 | YY_CAST (union yyalloc *, |
1805 | YYSTACK_ALLOC (YY_CAST (YYSIZE_T, YYSTACK_BYTES (yystacksize)))); | |
a0c0a00f | 1806 | if (! yyptr) |
74091dd4 | 1807 | YYNOMEM; |
a0c0a00f CR |
1808 | YYSTACK_RELOCATE (yyss_alloc, yyss); |
1809 | YYSTACK_RELOCATE (yyvs_alloc, yyvs); | |
3185942a | 1810 | # undef YYSTACK_RELOCATE |
a0c0a00f CR |
1811 | if (yyss1 != yyssa) |
1812 | YYSTACK_FREE (yyss1); | |
3185942a JA |
1813 | } |
1814 | # endif | |
726f6388 | 1815 | |
3185942a JA |
1816 | yyssp = yyss + yysize - 1; |
1817 | yyvsp = yyvs + yysize - 1; | |
726f6388 | 1818 | |
8868edaf CR |
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 | |
3185942a JA |
1823 | |
1824 | if (yyss + yystacksize - 1 <= yyssp) | |
a0c0a00f | 1825 | YYABORT; |
726f6388 | 1826 | } |
8868edaf | 1827 | #endif /* !defined yyoverflow && !defined YYSTACK_RELOCATE */ |
28ef6c31 | 1828 | |
74091dd4 | 1829 | |
a0c0a00f CR |
1830 | if (yystate == YYFINAL) |
1831 | YYACCEPT; | |
1832 | ||
f73dda09 | 1833 | goto yybackup; |
28ef6c31 | 1834 | |
8868edaf | 1835 | |
3185942a JA |
1836 | /*-----------. |
1837 | | yybackup. | | |
1838 | `-----------*/ | |
1839 | yybackup: | |
3185942a | 1840 | /* Do appropriate processing given the current state. Read a |
a0c0a00f | 1841 | lookahead token if we need one and don't already have one. */ |
726f6388 | 1842 | |
a0c0a00f | 1843 | /* First try to decide what to do without reference to lookahead token. */ |
f73dda09 | 1844 | yyn = yypact[yystate]; |
a0c0a00f | 1845 | if (yypact_value_is_default (yyn)) |
f73dda09 | 1846 | goto yydefault; |
726f6388 | 1847 | |
a0c0a00f | 1848 | /* Not known => get a lookahead token if don't already have one. */ |
726f6388 | 1849 | |
8868edaf | 1850 | /* YYCHAR is either empty, or end-of-input, or a valid lookahead. */ |
f73dda09 | 1851 | if (yychar == YYEMPTY) |
726f6388 | 1852 | { |
8868edaf | 1853 | YYDPRINTF ((stderr, "Reading a token\n")); |
a0c0a00f | 1854 | yychar = yylex (); |
726f6388 | 1855 | } |
726f6388 | 1856 | |
3185942a | 1857 | if (yychar <= YYEOF) |
f73dda09 | 1858 | { |
8868edaf CR |
1859 | yychar = YYEOF; |
1860 | yytoken = YYSYMBOL_YYEOF; | |
3185942a | 1861 | YYDPRINTF ((stderr, "Now at end of input.\n")); |
f73dda09 | 1862 | } |
8868edaf CR |
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 | } | |
f73dda09 JA |
1873 | else |
1874 | { | |
3185942a JA |
1875 | yytoken = YYTRANSLATE (yychar); |
1876 | YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc); | |
f73dda09 | 1877 | } |
726f6388 | 1878 | |
3185942a JA |
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) | |
f73dda09 | 1883 | goto yydefault; |
f73dda09 | 1884 | yyn = yytable[yyn]; |
3185942a | 1885 | if (yyn <= 0) |
f73dda09 | 1886 | { |
a0c0a00f CR |
1887 | if (yytable_value_is_error (yyn)) |
1888 | goto yyerrlab; | |
f73dda09 JA |
1889 | yyn = -yyn; |
1890 | goto yyreduce; | |
1891 | } | |
726f6388 | 1892 | |
3185942a JA |
1893 | /* Count tokens shifted since error; after three, turn off error |
1894 | status. */ | |
1895 | if (yyerrstatus) | |
1896 | yyerrstatus--; | |
b80f6443 | 1897 | |
a0c0a00f | 1898 | /* Shift the lookahead token. */ |
3185942a | 1899 | YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc); |
3185942a | 1900 | yystate = yyn; |
a0c0a00f | 1901 | YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN |
f73dda09 | 1902 | *++yyvsp = yylval; |
a0c0a00f | 1903 | YY_IGNORE_MAYBE_UNINITIALIZED_END |
28ef6c31 | 1904 | |
8868edaf CR |
1905 | /* Discard the shifted token. */ |
1906 | yychar = YYEMPTY; | |
f73dda09 | 1907 | goto yynewstate; |
726f6388 | 1908 | |
b80f6443 | 1909 | |
3185942a JA |
1910 | /*-----------------------------------------------------------. |
1911 | | yydefault -- do the default action for the current state. | | |
1912 | `-----------------------------------------------------------*/ | |
1913 | yydefault: | |
f73dda09 JA |
1914 | yyn = yydefact[yystate]; |
1915 | if (yyn == 0) | |
1916 | goto yyerrlab; | |
3185942a | 1917 | goto yyreduce; |
28ef6c31 | 1918 | |
3185942a JA |
1919 | |
1920 | /*-----------------------------. | |
8868edaf | 1921 | | yyreduce -- do a reduction. | |
3185942a | 1922 | `-----------------------------*/ |
f73dda09 | 1923 | yyreduce: |
3185942a | 1924 | /* yyn is the number of a rule to reduce with. */ |
f73dda09 | 1925 | yylen = yyr2[yyn]; |
28ef6c31 | 1926 | |
3185942a | 1927 | /* If YYLEN is nonzero, implement the default value of the action: |
a0c0a00f | 1928 | '$$ = $1'. |
28ef6c31 | 1929 | |
3185942a JA |
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]; | |
b80f6443 | 1936 | |
28ef6c31 | 1937 | |
3185942a JA |
1938 | YY_REDUCE_PRINT (yyn); |
1939 | switch (yyn) | |
1940 | { | |
74091dd4 CR |
1941 | case 2: /* inputunit: simple_list simple_list_terminator */ |
1942 | #line 396 "/usr/local/src/chet/src/bash/src/parse.y" | |
8868edaf | 1943 | { |
f73dda09 JA |
1944 | /* Case of regular command. Discard the error |
1945 | safety net,and return the command just parsed. */ | |
a0c0a00f | 1946 | global_command = (yyvsp[-1].command); |
f73dda09 | 1947 | eof_encountered = 0; |
7117c2d2 | 1948 | /* discard_parser_constructs (0); */ |
3185942a JA |
1949 | if (parser_state & PST_CMDSUBST) |
1950 | parser_state |= PST_EOFTOKEN; | |
f73dda09 | 1951 | YYACCEPT; |
3185942a | 1952 | } |
74091dd4 CR |
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" | |
3185942a JA |
1966 | break; |
1967 | ||
74091dd4 CR |
1968 | case 4: /* inputunit: '\n' */ |
1969 | #line 415 "/usr/local/src/chet/src/bash/src/parse.y" | |
8868edaf | 1970 | { |
f73dda09 JA |
1971 | /* Case of regular command, but not a very |
1972 | interesting one. Return a NULL command. */ | |
1973 | global_command = (COMMAND *)NULL; | |
3185942a JA |
1974 | if (parser_state & PST_CMDSUBST) |
1975 | parser_state |= PST_EOFTOKEN; | |
f73dda09 | 1976 | YYACCEPT; |
3185942a | 1977 | } |
74091dd4 | 1978 | #line 1979 "y.tab.c" |
3185942a JA |
1979 | break; |
1980 | ||
74091dd4 CR |
1981 | case 5: /* inputunit: error '\n' */ |
1982 | #line 424 "/usr/local/src/chet/src/bash/src/parse.y" | |
8868edaf | 1983 | { |
f73dda09 JA |
1984 | /* Error during parsing. Return NULL command. */ |
1985 | global_command = (COMMAND *)NULL; | |
1986 | eof_encountered = 0; | |
7117c2d2 | 1987 | /* discard_parser_constructs (1); */ |
3185942a | 1988 | if (interactive && parse_and_execute_level == 0) |
f73dda09 JA |
1989 | { |
1990 | YYACCEPT; | |
1991 | } | |
1992 | else | |
1993 | { | |
1994 | YYABORT; | |
1995 | } | |
3185942a | 1996 | } |
74091dd4 | 1997 | #line 1998 "y.tab.c" |
3185942a JA |
1998 | break; |
1999 | ||
74091dd4 CR |
2000 | case 6: /* inputunit: error yacc_EOF */ |
2001 | #line 439 "/usr/local/src/chet/src/bash/src/parse.y" | |
8868edaf | 2002 | { |
d233b485 CR |
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 */ | |
d233b485 CR |
2008 | if (interactive && parse_and_execute_level == 0) |
2009 | { | |
8868edaf | 2010 | handle_eof_input_unit (); |
d233b485 CR |
2011 | YYACCEPT; |
2012 | } | |
2013 | else | |
2014 | { | |
2015 | YYABORT; | |
2016 | } | |
2017 | } | |
74091dd4 | 2018 | #line 2019 "y.tab.c" |
d233b485 CR |
2019 | break; |
2020 | ||
a78e27a1 | 2021 | case 7: /* inputunit: error $end */ |
74091dd4 | 2022 | #line 456 "/usr/local/src/chet/src/bash/src/parse.y" |
a78e27a1 CR |
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" | |
8868edaf | 2042 | { |
f73dda09 JA |
2043 | /* Case of EOF seen by itself. Do ignoreeof or |
2044 | not. */ | |
2045 | global_command = (COMMAND *)NULL; | |
2046 | handle_eof_input_unit (); | |
2047 | YYACCEPT; | |
3185942a | 2048 | } |
a78e27a1 | 2049 | #line 2050 "y.tab.c" |
3185942a JA |
2050 | break; |
2051 | ||
a78e27a1 CR |
2052 | case 9: /* word_list: WORD */ |
2053 | #line 481 "/usr/local/src/chet/src/bash/src/parse.y" | |
8868edaf | 2054 | { (yyval.word_list) = make_word_list ((yyvsp[0].word), (WORD_LIST *)NULL); } |
a78e27a1 | 2055 | #line 2056 "y.tab.c" |
3185942a JA |
2056 | break; |
2057 | ||
a78e27a1 CR |
2058 | case 10: /* word_list: word_list WORD */ |
2059 | #line 483 "/usr/local/src/chet/src/bash/src/parse.y" | |
8868edaf | 2060 | { (yyval.word_list) = make_word_list ((yyvsp[0].word), (yyvsp[-1].word_list)); } |
a78e27a1 | 2061 | #line 2062 "y.tab.c" |
3185942a JA |
2062 | break; |
2063 | ||
a78e27a1 CR |
2064 | case 11: /* redirection: '>' WORD */ |
2065 | #line 487 "/usr/local/src/chet/src/bash/src/parse.y" | |
8868edaf | 2066 | { |
0001803f | 2067 | source.dest = 1; |
a0c0a00f | 2068 | redir.filename = (yyvsp[0].word); |
0001803f | 2069 | (yyval.redirect) = make_redirection (source, r_output_direction, redir, 0); |
3185942a | 2070 | } |
a78e27a1 | 2071 | #line 2072 "y.tab.c" |
3185942a JA |
2072 | break; |
2073 | ||
a78e27a1 CR |
2074 | case 12: /* redirection: '<' WORD */ |
2075 | #line 493 "/usr/local/src/chet/src/bash/src/parse.y" | |
8868edaf | 2076 | { |
0001803f | 2077 | source.dest = 0; |
a0c0a00f | 2078 | redir.filename = (yyvsp[0].word); |
0001803f | 2079 | (yyval.redirect) = make_redirection (source, r_input_direction, redir, 0); |
3185942a | 2080 | } |
a78e27a1 | 2081 | #line 2082 "y.tab.c" |
3185942a JA |
2082 | break; |
2083 | ||
a78e27a1 CR |
2084 | case 13: /* redirection: NUMBER '>' WORD */ |
2085 | #line 499 "/usr/local/src/chet/src/bash/src/parse.y" | |
8868edaf | 2086 | { |
a0c0a00f CR |
2087 | source.dest = (yyvsp[-2].number); |
2088 | redir.filename = (yyvsp[0].word); | |
0001803f | 2089 | (yyval.redirect) = make_redirection (source, r_output_direction, redir, 0); |
3185942a | 2090 | } |
a78e27a1 | 2091 | #line 2092 "y.tab.c" |
3185942a JA |
2092 | break; |
2093 | ||
a78e27a1 CR |
2094 | case 14: /* redirection: NUMBER '<' WORD */ |
2095 | #line 505 "/usr/local/src/chet/src/bash/src/parse.y" | |
8868edaf | 2096 | { |
a0c0a00f CR |
2097 | source.dest = (yyvsp[-2].number); |
2098 | redir.filename = (yyvsp[0].word); | |
0001803f | 2099 | (yyval.redirect) = make_redirection (source, r_input_direction, redir, 0); |
3185942a | 2100 | } |
a78e27a1 | 2101 | #line 2102 "y.tab.c" |
3185942a JA |
2102 | break; |
2103 | ||
a78e27a1 CR |
2104 | case 15: /* redirection: REDIR_WORD '>' WORD */ |
2105 | #line 511 "/usr/local/src/chet/src/bash/src/parse.y" | |
8868edaf | 2106 | { |
a0c0a00f CR |
2107 | source.filename = (yyvsp[-2].word); |
2108 | redir.filename = (yyvsp[0].word); | |
0001803f | 2109 | (yyval.redirect) = make_redirection (source, r_output_direction, redir, REDIR_VARASSIGN); |
3185942a | 2110 | } |
a78e27a1 | 2111 | #line 2112 "y.tab.c" |
3185942a JA |
2112 | break; |
2113 | ||
a78e27a1 CR |
2114 | case 16: /* redirection: REDIR_WORD '<' WORD */ |
2115 | #line 517 "/usr/local/src/chet/src/bash/src/parse.y" | |
8868edaf | 2116 | { |
a0c0a00f CR |
2117 | source.filename = (yyvsp[-2].word); |
2118 | redir.filename = (yyvsp[0].word); | |
0001803f | 2119 | (yyval.redirect) = make_redirection (source, r_input_direction, redir, REDIR_VARASSIGN); |
3185942a | 2120 | } |
a78e27a1 | 2121 | #line 2122 "y.tab.c" |
3185942a JA |
2122 | break; |
2123 | ||
a78e27a1 CR |
2124 | case 17: /* redirection: GREATER_GREATER WORD */ |
2125 | #line 523 "/usr/local/src/chet/src/bash/src/parse.y" | |
8868edaf | 2126 | { |
0001803f | 2127 | source.dest = 1; |
a0c0a00f | 2128 | redir.filename = (yyvsp[0].word); |
0001803f | 2129 | (yyval.redirect) = make_redirection (source, r_appending_to, redir, 0); |
3185942a | 2130 | } |
a78e27a1 | 2131 | #line 2132 "y.tab.c" |
3185942a JA |
2132 | break; |
2133 | ||
a78e27a1 CR |
2134 | case 18: /* redirection: NUMBER GREATER_GREATER WORD */ |
2135 | #line 529 "/usr/local/src/chet/src/bash/src/parse.y" | |
8868edaf | 2136 | { |
a0c0a00f CR |
2137 | source.dest = (yyvsp[-2].number); |
2138 | redir.filename = (yyvsp[0].word); | |
0001803f | 2139 | (yyval.redirect) = make_redirection (source, r_appending_to, redir, 0); |
3185942a | 2140 | } |
a78e27a1 | 2141 | #line 2142 "y.tab.c" |
3185942a JA |
2142 | break; |
2143 | ||
a78e27a1 CR |
2144 | case 19: /* redirection: REDIR_WORD GREATER_GREATER WORD */ |
2145 | #line 535 "/usr/local/src/chet/src/bash/src/parse.y" | |
8868edaf | 2146 | { |
a0c0a00f CR |
2147 | source.filename = (yyvsp[-2].word); |
2148 | redir.filename = (yyvsp[0].word); | |
0001803f | 2149 | (yyval.redirect) = make_redirection (source, r_appending_to, redir, REDIR_VARASSIGN); |
3185942a | 2150 | } |
a78e27a1 | 2151 | #line 2152 "y.tab.c" |
3185942a JA |
2152 | break; |
2153 | ||
a78e27a1 CR |
2154 | case 20: /* redirection: GREATER_BAR WORD */ |
2155 | #line 541 "/usr/local/src/chet/src/bash/src/parse.y" | |
8868edaf | 2156 | { |
0001803f | 2157 | source.dest = 1; |
a0c0a00f | 2158 | redir.filename = (yyvsp[0].word); |
0001803f | 2159 | (yyval.redirect) = make_redirection (source, r_output_force, redir, 0); |
3185942a | 2160 | } |
a78e27a1 | 2161 | #line 2162 "y.tab.c" |
3185942a JA |
2162 | break; |
2163 | ||
a78e27a1 CR |
2164 | case 21: /* redirection: NUMBER GREATER_BAR WORD */ |
2165 | #line 547 "/usr/local/src/chet/src/bash/src/parse.y" | |
8868edaf | 2166 | { |
a0c0a00f CR |
2167 | source.dest = (yyvsp[-2].number); |
2168 | redir.filename = (yyvsp[0].word); | |
0001803f | 2169 | (yyval.redirect) = make_redirection (source, r_output_force, redir, 0); |
3185942a | 2170 | } |
a78e27a1 | 2171 | #line 2172 "y.tab.c" |
3185942a JA |
2172 | break; |
2173 | ||
a78e27a1 CR |
2174 | case 22: /* redirection: REDIR_WORD GREATER_BAR WORD */ |
2175 | #line 553 "/usr/local/src/chet/src/bash/src/parse.y" | |
8868edaf | 2176 | { |
a0c0a00f CR |
2177 | source.filename = (yyvsp[-2].word); |
2178 | redir.filename = (yyvsp[0].word); | |
0001803f | 2179 | (yyval.redirect) = make_redirection (source, r_output_force, redir, REDIR_VARASSIGN); |
3185942a | 2180 | } |
a78e27a1 | 2181 | #line 2182 "y.tab.c" |
3185942a JA |
2182 | break; |
2183 | ||
a78e27a1 CR |
2184 | case 23: /* redirection: LESS_GREATER WORD */ |
2185 | #line 559 "/usr/local/src/chet/src/bash/src/parse.y" | |
8868edaf | 2186 | { |
0001803f | 2187 | source.dest = 0; |
a0c0a00f | 2188 | redir.filename = (yyvsp[0].word); |
0001803f | 2189 | (yyval.redirect) = make_redirection (source, r_input_output, redir, 0); |
3185942a | 2190 | } |
a78e27a1 | 2191 | #line 2192 "y.tab.c" |
3185942a JA |
2192 | break; |
2193 | ||
a78e27a1 CR |
2194 | case 24: /* redirection: NUMBER LESS_GREATER WORD */ |
2195 | #line 565 "/usr/local/src/chet/src/bash/src/parse.y" | |
8868edaf | 2196 | { |
a0c0a00f CR |
2197 | source.dest = (yyvsp[-2].number); |
2198 | redir.filename = (yyvsp[0].word); | |
0001803f | 2199 | (yyval.redirect) = make_redirection (source, r_input_output, redir, 0); |
3185942a | 2200 | } |
a78e27a1 | 2201 | #line 2202 "y.tab.c" |
3185942a JA |
2202 | break; |
2203 | ||
a78e27a1 CR |
2204 | case 25: /* redirection: REDIR_WORD LESS_GREATER WORD */ |
2205 | #line 571 "/usr/local/src/chet/src/bash/src/parse.y" | |
8868edaf | 2206 | { |
a0c0a00f CR |
2207 | source.filename = (yyvsp[-2].word); |
2208 | redir.filename = (yyvsp[0].word); | |
0001803f | 2209 | (yyval.redirect) = make_redirection (source, r_input_output, redir, REDIR_VARASSIGN); |
3185942a | 2210 | } |
a78e27a1 | 2211 | #line 2212 "y.tab.c" |
3185942a JA |
2212 | break; |
2213 | ||
a78e27a1 CR |
2214 | case 26: /* redirection: LESS_LESS WORD */ |
2215 | #line 577 "/usr/local/src/chet/src/bash/src/parse.y" | |
8868edaf | 2216 | { |
0001803f | 2217 | source.dest = 0; |
a0c0a00f | 2218 | redir.filename = (yyvsp[0].word); |
0001803f | 2219 | (yyval.redirect) = make_redirection (source, r_reading_until, redir, 0); |
90a39f32 | 2220 | push_heredoc ((yyval.redirect)); |
3185942a | 2221 | } |
a78e27a1 | 2222 | #line 2223 "y.tab.c" |
3185942a JA |
2223 | break; |
2224 | ||
a78e27a1 CR |
2225 | case 27: /* redirection: NUMBER LESS_LESS WORD */ |
2226 | #line 584 "/usr/local/src/chet/src/bash/src/parse.y" | |
8868edaf | 2227 | { |
a0c0a00f CR |
2228 | source.dest = (yyvsp[-2].number); |
2229 | redir.filename = (yyvsp[0].word); | |
0001803f | 2230 | (yyval.redirect) = make_redirection (source, r_reading_until, redir, 0); |
90a39f32 | 2231 | push_heredoc ((yyval.redirect)); |
3185942a | 2232 | } |
a78e27a1 | 2233 | #line 2234 "y.tab.c" |
3185942a JA |
2234 | break; |
2235 | ||
a78e27a1 CR |
2236 | case 28: /* redirection: REDIR_WORD LESS_LESS WORD */ |
2237 | #line 591 "/usr/local/src/chet/src/bash/src/parse.y" | |
8868edaf | 2238 | { |
a0c0a00f CR |
2239 | source.filename = (yyvsp[-2].word); |
2240 | redir.filename = (yyvsp[0].word); | |
0001803f | 2241 | (yyval.redirect) = make_redirection (source, r_reading_until, redir, REDIR_VARASSIGN); |
90a39f32 | 2242 | push_heredoc ((yyval.redirect)); |
3185942a | 2243 | } |
a78e27a1 | 2244 | #line 2245 "y.tab.c" |
3185942a JA |
2245 | break; |
2246 | ||
a78e27a1 CR |
2247 | case 29: /* redirection: LESS_LESS_MINUS WORD */ |
2248 | #line 598 "/usr/local/src/chet/src/bash/src/parse.y" | |
8868edaf | 2249 | { |
0001803f | 2250 | source.dest = 0; |
a0c0a00f | 2251 | redir.filename = (yyvsp[0].word); |
0001803f | 2252 | (yyval.redirect) = make_redirection (source, r_deblank_reading_until, redir, 0); |
90a39f32 | 2253 | push_heredoc ((yyval.redirect)); |
3185942a | 2254 | } |
a78e27a1 | 2255 | #line 2256 "y.tab.c" |
3185942a JA |
2256 | break; |
2257 | ||
a78e27a1 CR |
2258 | case 30: /* redirection: NUMBER LESS_LESS_MINUS WORD */ |
2259 | #line 605 "/usr/local/src/chet/src/bash/src/parse.y" | |
8868edaf | 2260 | { |
a0c0a00f CR |
2261 | source.dest = (yyvsp[-2].number); |
2262 | redir.filename = (yyvsp[0].word); | |
0001803f | 2263 | (yyval.redirect) = make_redirection (source, r_deblank_reading_until, redir, 0); |
90a39f32 | 2264 | push_heredoc ((yyval.redirect)); |
3185942a | 2265 | } |
a78e27a1 | 2266 | #line 2267 "y.tab.c" |
3185942a JA |
2267 | break; |
2268 | ||
a78e27a1 CR |
2269 | case 31: /* redirection: REDIR_WORD LESS_LESS_MINUS WORD */ |
2270 | #line 612 "/usr/local/src/chet/src/bash/src/parse.y" | |
8868edaf | 2271 | { |
a0c0a00f CR |
2272 | source.filename = (yyvsp[-2].word); |
2273 | redir.filename = (yyvsp[0].word); | |
0001803f | 2274 | (yyval.redirect) = make_redirection (source, r_deblank_reading_until, redir, REDIR_VARASSIGN); |
90a39f32 | 2275 | push_heredoc ((yyval.redirect)); |
3185942a | 2276 | } |
a78e27a1 | 2277 | #line 2278 "y.tab.c" |
3185942a JA |
2278 | break; |
2279 | ||
a78e27a1 CR |
2280 | case 32: /* redirection: LESS_LESS_LESS WORD */ |
2281 | #line 619 "/usr/local/src/chet/src/bash/src/parse.y" | |
8868edaf | 2282 | { |
0001803f | 2283 | source.dest = 0; |
a0c0a00f | 2284 | redir.filename = (yyvsp[0].word); |
0001803f | 2285 | (yyval.redirect) = make_redirection (source, r_reading_string, redir, 0); |
3185942a | 2286 | } |
a78e27a1 | 2287 | #line 2288 "y.tab.c" |
3185942a JA |
2288 | break; |
2289 | ||
a78e27a1 CR |
2290 | case 33: /* redirection: NUMBER LESS_LESS_LESS WORD */ |
2291 | #line 625 "/usr/local/src/chet/src/bash/src/parse.y" | |
8868edaf | 2292 | { |
a0c0a00f CR |
2293 | source.dest = (yyvsp[-2].number); |
2294 | redir.filename = (yyvsp[0].word); | |
0001803f | 2295 | (yyval.redirect) = make_redirection (source, r_reading_string, redir, 0); |
3185942a | 2296 | } |
a78e27a1 | 2297 | #line 2298 "y.tab.c" |
3185942a JA |
2298 | break; |
2299 | ||
a78e27a1 CR |
2300 | case 34: /* redirection: REDIR_WORD LESS_LESS_LESS WORD */ |
2301 | #line 631 "/usr/local/src/chet/src/bash/src/parse.y" | |
8868edaf | 2302 | { |
a0c0a00f CR |
2303 | source.filename = (yyvsp[-2].word); |
2304 | redir.filename = (yyvsp[0].word); | |
0001803f | 2305 | (yyval.redirect) = make_redirection (source, r_reading_string, redir, REDIR_VARASSIGN); |
3185942a | 2306 | } |
a78e27a1 | 2307 | #line 2308 "y.tab.c" |
3185942a JA |
2308 | break; |
2309 | ||
a78e27a1 CR |
2310 | case 35: /* redirection: LESS_AND NUMBER */ |
2311 | #line 637 "/usr/local/src/chet/src/bash/src/parse.y" | |
8868edaf | 2312 | { |
0001803f | 2313 | source.dest = 0; |
a0c0a00f | 2314 | redir.dest = (yyvsp[0].number); |
0001803f | 2315 | (yyval.redirect) = make_redirection (source, r_duplicating_input, redir, 0); |
3185942a | 2316 | } |
a78e27a1 | 2317 | #line 2318 "y.tab.c" |
3185942a JA |
2318 | break; |
2319 | ||
a78e27a1 CR |
2320 | case 36: /* redirection: NUMBER LESS_AND NUMBER */ |
2321 | #line 643 "/usr/local/src/chet/src/bash/src/parse.y" | |
8868edaf | 2322 | { |
a0c0a00f CR |
2323 | source.dest = (yyvsp[-2].number); |
2324 | redir.dest = (yyvsp[0].number); | |
0001803f | 2325 | (yyval.redirect) = make_redirection (source, r_duplicating_input, redir, 0); |
3185942a | 2326 | } |
a78e27a1 | 2327 | #line 2328 "y.tab.c" |
3185942a JA |
2328 | break; |
2329 | ||
a78e27a1 CR |
2330 | case 37: /* redirection: REDIR_WORD LESS_AND NUMBER */ |
2331 | #line 649 "/usr/local/src/chet/src/bash/src/parse.y" | |
8868edaf | 2332 | { |
a0c0a00f CR |
2333 | source.filename = (yyvsp[-2].word); |
2334 | redir.dest = (yyvsp[0].number); | |
0001803f | 2335 | (yyval.redirect) = make_redirection (source, r_duplicating_input, redir, REDIR_VARASSIGN); |
3185942a | 2336 | } |
a78e27a1 | 2337 | #line 2338 "y.tab.c" |
3185942a JA |
2338 | break; |
2339 | ||
a78e27a1 CR |
2340 | case 38: /* redirection: GREATER_AND NUMBER */ |
2341 | #line 655 "/usr/local/src/chet/src/bash/src/parse.y" | |
8868edaf | 2342 | { |
0001803f | 2343 | source.dest = 1; |
a0c0a00f | 2344 | redir.dest = (yyvsp[0].number); |
0001803f | 2345 | (yyval.redirect) = make_redirection (source, r_duplicating_output, redir, 0); |
3185942a | 2346 | } |
a78e27a1 | 2347 | #line 2348 "y.tab.c" |
3185942a JA |
2348 | break; |
2349 | ||
a78e27a1 CR |
2350 | case 39: /* redirection: NUMBER GREATER_AND NUMBER */ |
2351 | #line 661 "/usr/local/src/chet/src/bash/src/parse.y" | |
8868edaf | 2352 | { |
a0c0a00f CR |
2353 | source.dest = (yyvsp[-2].number); |
2354 | redir.dest = (yyvsp[0].number); | |
0001803f | 2355 | (yyval.redirect) = make_redirection (source, r_duplicating_output, redir, 0); |
3185942a | 2356 | } |
a78e27a1 | 2357 | #line 2358 "y.tab.c" |
3185942a JA |
2358 | break; |
2359 | ||
a78e27a1 CR |
2360 | case 40: /* redirection: REDIR_WORD GREATER_AND NUMBER */ |
2361 | #line 667 "/usr/local/src/chet/src/bash/src/parse.y" | |
8868edaf | 2362 | { |
a0c0a00f CR |
2363 | source.filename = (yyvsp[-2].word); |
2364 | redir.dest = (yyvsp[0].number); | |
0001803f | 2365 | (yyval.redirect) = make_redirection (source, r_duplicating_output, redir, REDIR_VARASSIGN); |
3185942a | 2366 | } |
a78e27a1 | 2367 | #line 2368 "y.tab.c" |
3185942a JA |
2368 | break; |
2369 | ||
a78e27a1 CR |
2370 | case 41: /* redirection: LESS_AND WORD */ |
2371 | #line 673 "/usr/local/src/chet/src/bash/src/parse.y" | |
8868edaf | 2372 | { |
0001803f | 2373 | source.dest = 0; |
a0c0a00f | 2374 | redir.filename = (yyvsp[0].word); |
0001803f CR |
2375 | (yyval.redirect) = make_redirection (source, r_duplicating_input_word, redir, 0); |
2376 | } | |
a78e27a1 | 2377 | #line 2378 "y.tab.c" |
3185942a JA |
2378 | break; |
2379 | ||
a78e27a1 CR |
2380 | case 42: /* redirection: NUMBER LESS_AND WORD */ |
2381 | #line 679 "/usr/local/src/chet/src/bash/src/parse.y" | |
8868edaf | 2382 | { |
a0c0a00f CR |
2383 | source.dest = (yyvsp[-2].number); |
2384 | redir.filename = (yyvsp[0].word); | |
0001803f CR |
2385 | (yyval.redirect) = make_redirection (source, r_duplicating_input_word, redir, 0); |
2386 | } | |
a78e27a1 | 2387 | #line 2388 "y.tab.c" |
3185942a JA |
2388 | break; |
2389 | ||
a78e27a1 CR |
2390 | case 43: /* redirection: REDIR_WORD LESS_AND WORD */ |
2391 | #line 685 "/usr/local/src/chet/src/bash/src/parse.y" | |
8868edaf | 2392 | { |
a0c0a00f CR |
2393 | source.filename = (yyvsp[-2].word); |
2394 | redir.filename = (yyvsp[0].word); | |
0001803f CR |
2395 | (yyval.redirect) = make_redirection (source, r_duplicating_input_word, redir, REDIR_VARASSIGN); |
2396 | } | |
a78e27a1 | 2397 | #line 2398 "y.tab.c" |
3185942a JA |
2398 | break; |
2399 | ||
a78e27a1 CR |
2400 | case 44: /* redirection: GREATER_AND WORD */ |
2401 | #line 691 "/usr/local/src/chet/src/bash/src/parse.y" | |
8868edaf | 2402 | { |
0001803f | 2403 | source.dest = 1; |
a0c0a00f | 2404 | redir.filename = (yyvsp[0].word); |
0001803f | 2405 | (yyval.redirect) = make_redirection (source, r_duplicating_output_word, redir, 0); |
3185942a | 2406 | } |
a78e27a1 | 2407 | #line 2408 "y.tab.c" |
3185942a JA |
2408 | break; |
2409 | ||
a78e27a1 CR |
2410 | case 45: /* redirection: NUMBER GREATER_AND WORD */ |
2411 | #line 697 "/usr/local/src/chet/src/bash/src/parse.y" | |
8868edaf | 2412 | { |
a0c0a00f CR |
2413 | source.dest = (yyvsp[-2].number); |
2414 | redir.filename = (yyvsp[0].word); | |
0001803f CR |
2415 | (yyval.redirect) = make_redirection (source, r_duplicating_output_word, redir, 0); |
2416 | } | |
a78e27a1 | 2417 | #line 2418 "y.tab.c" |
0001803f CR |
2418 | break; |
2419 | ||
a78e27a1 CR |
2420 | case 46: /* redirection: REDIR_WORD GREATER_AND WORD */ |
2421 | #line 703 "/usr/local/src/chet/src/bash/src/parse.y" | |
8868edaf | 2422 | { |
a0c0a00f CR |
2423 | source.filename = (yyvsp[-2].word); |
2424 | redir.filename = (yyvsp[0].word); | |
0001803f CR |
2425 | (yyval.redirect) = make_redirection (source, r_duplicating_output_word, redir, REDIR_VARASSIGN); |
2426 | } | |
a78e27a1 | 2427 | #line 2428 "y.tab.c" |
0001803f CR |
2428 | break; |
2429 | ||
a78e27a1 CR |
2430 | case 47: /* redirection: GREATER_AND '-' */ |
2431 | #line 709 "/usr/local/src/chet/src/bash/src/parse.y" | |
8868edaf | 2432 | { |
0001803f CR |
2433 | source.dest = 1; |
2434 | redir.dest = 0; | |
2435 | (yyval.redirect) = make_redirection (source, r_close_this, redir, 0); | |
2436 | } | |
a78e27a1 | 2437 | #line 2438 "y.tab.c" |
0001803f CR |
2438 | break; |
2439 | ||
a78e27a1 CR |
2440 | case 48: /* redirection: NUMBER GREATER_AND '-' */ |
2441 | #line 715 "/usr/local/src/chet/src/bash/src/parse.y" | |
8868edaf | 2442 | { |
a0c0a00f | 2443 | source.dest = (yyvsp[-2].number); |
0001803f CR |
2444 | redir.dest = 0; |
2445 | (yyval.redirect) = make_redirection (source, r_close_this, redir, 0); | |
2446 | } | |
a78e27a1 | 2447 | #line 2448 "y.tab.c" |
0001803f CR |
2448 | break; |
2449 | ||
a78e27a1 CR |
2450 | case 49: /* redirection: REDIR_WORD GREATER_AND '-' */ |
2451 | #line 721 "/usr/local/src/chet/src/bash/src/parse.y" | |
8868edaf | 2452 | { |
a0c0a00f | 2453 | source.filename = (yyvsp[-2].word); |
0001803f CR |
2454 | redir.dest = 0; |
2455 | (yyval.redirect) = make_redirection (source, r_close_this, redir, REDIR_VARASSIGN); | |
2456 | } | |
a78e27a1 | 2457 | #line 2458 "y.tab.c" |
0001803f CR |
2458 | break; |
2459 | ||
a78e27a1 CR |
2460 | case 50: /* redirection: LESS_AND '-' */ |
2461 | #line 727 "/usr/local/src/chet/src/bash/src/parse.y" | |
8868edaf | 2462 | { |
0001803f CR |
2463 | source.dest = 0; |
2464 | redir.dest = 0; | |
2465 | (yyval.redirect) = make_redirection (source, r_close_this, redir, 0); | |
2466 | } | |
a78e27a1 | 2467 | #line 2468 "y.tab.c" |
0001803f CR |
2468 | break; |
2469 | ||
a78e27a1 CR |
2470 | case 51: /* redirection: NUMBER LESS_AND '-' */ |
2471 | #line 733 "/usr/local/src/chet/src/bash/src/parse.y" | |
8868edaf | 2472 | { |
a0c0a00f | 2473 | source.dest = (yyvsp[-2].number); |
0001803f CR |
2474 | redir.dest = 0; |
2475 | (yyval.redirect) = make_redirection (source, r_close_this, redir, 0); | |
2476 | } | |
a78e27a1 | 2477 | #line 2478 "y.tab.c" |
0001803f CR |
2478 | break; |
2479 | ||
a78e27a1 CR |
2480 | case 52: /* redirection: REDIR_WORD LESS_AND '-' */ |
2481 | #line 739 "/usr/local/src/chet/src/bash/src/parse.y" | |
8868edaf | 2482 | { |
a0c0a00f | 2483 | source.filename = (yyvsp[-2].word); |
0001803f CR |
2484 | redir.dest = 0; |
2485 | (yyval.redirect) = make_redirection (source, r_close_this, redir, REDIR_VARASSIGN); | |
2486 | } | |
a78e27a1 | 2487 | #line 2488 "y.tab.c" |
0001803f CR |
2488 | break; |
2489 | ||
a78e27a1 CR |
2490 | case 53: /* redirection: AND_GREATER WORD */ |
2491 | #line 745 "/usr/local/src/chet/src/bash/src/parse.y" | |
8868edaf | 2492 | { |
0001803f | 2493 | source.dest = 1; |
a0c0a00f | 2494 | redir.filename = (yyvsp[0].word); |
0001803f CR |
2495 | (yyval.redirect) = make_redirection (source, r_err_and_out, redir, 0); |
2496 | } | |
a78e27a1 | 2497 | #line 2498 "y.tab.c" |
0001803f CR |
2498 | break; |
2499 | ||
a78e27a1 CR |
2500 | case 54: /* redirection: AND_GREATER_GREATER WORD */ |
2501 | #line 751 "/usr/local/src/chet/src/bash/src/parse.y" | |
8868edaf | 2502 | { |
0001803f | 2503 | source.dest = 1; |
a0c0a00f | 2504 | redir.filename = (yyvsp[0].word); |
0001803f CR |
2505 | (yyval.redirect) = make_redirection (source, r_append_err_and_out, redir, 0); |
2506 | } | |
a78e27a1 | 2507 | #line 2508 "y.tab.c" |
0001803f CR |
2508 | break; |
2509 | ||
a78e27a1 CR |
2510 | case 55: /* simple_command_element: WORD */ |
2511 | #line 759 "/usr/local/src/chet/src/bash/src/parse.y" | |
8868edaf | 2512 | { (yyval.element).word = (yyvsp[0].word); (yyval.element).redirect = 0; } |
a78e27a1 | 2513 | #line 2514 "y.tab.c" |
0001803f CR |
2514 | break; |
2515 | ||
a78e27a1 CR |
2516 | case 56: /* simple_command_element: ASSIGNMENT_WORD */ |
2517 | #line 761 "/usr/local/src/chet/src/bash/src/parse.y" | |
8868edaf | 2518 | { (yyval.element).word = (yyvsp[0].word); (yyval.element).redirect = 0; } |
a78e27a1 | 2519 | #line 2520 "y.tab.c" |
0001803f CR |
2520 | break; |
2521 | ||
a78e27a1 CR |
2522 | case 57: /* simple_command_element: redirection */ |
2523 | #line 763 "/usr/local/src/chet/src/bash/src/parse.y" | |
8868edaf | 2524 | { (yyval.element).redirect = (yyvsp[0].redirect); (yyval.element).word = 0; } |
a78e27a1 | 2525 | #line 2526 "y.tab.c" |
0001803f CR |
2526 | break; |
2527 | ||
a78e27a1 CR |
2528 | case 58: /* redirection_list: redirection */ |
2529 | #line 767 "/usr/local/src/chet/src/bash/src/parse.y" | |
8868edaf | 2530 | { |
a0c0a00f | 2531 | (yyval.redirect) = (yyvsp[0].redirect); |
0001803f | 2532 | } |
a78e27a1 | 2533 | #line 2534 "y.tab.c" |
0001803f CR |
2534 | break; |
2535 | ||
a78e27a1 CR |
2536 | case 59: /* redirection_list: redirection_list redirection */ |
2537 | #line 771 "/usr/local/src/chet/src/bash/src/parse.y" | |
8868edaf | 2538 | { |
f73dda09 JA |
2539 | register REDIRECT *t; |
2540 | ||
a0c0a00f | 2541 | for (t = (yyvsp[-1].redirect); t->next; t = t->next) |
f73dda09 | 2542 | ; |
a0c0a00f CR |
2543 | t->next = (yyvsp[0].redirect); |
2544 | (yyval.redirect) = (yyvsp[-1].redirect); | |
3185942a | 2545 | } |
a78e27a1 | 2546 | #line 2547 "y.tab.c" |
3185942a JA |
2547 | break; |
2548 | ||
a78e27a1 CR |
2549 | case 60: /* simple_command: simple_command_element */ |
2550 | #line 782 "/usr/local/src/chet/src/bash/src/parse.y" | |
8868edaf | 2551 | { (yyval.command) = make_simple_command ((yyvsp[0].element), (COMMAND *)NULL); } |
a78e27a1 | 2552 | #line 2553 "y.tab.c" |
3185942a JA |
2553 | break; |
2554 | ||
a78e27a1 CR |
2555 | case 61: /* simple_command: simple_command simple_command_element */ |
2556 | #line 784 "/usr/local/src/chet/src/bash/src/parse.y" | |
8868edaf | 2557 | { (yyval.command) = make_simple_command ((yyvsp[0].element), (yyvsp[-1].command)); } |
a78e27a1 | 2558 | #line 2559 "y.tab.c" |
3185942a JA |
2559 | break; |
2560 | ||
a78e27a1 CR |
2561 | case 62: /* command: simple_command */ |
2562 | #line 788 "/usr/local/src/chet/src/bash/src/parse.y" | |
8868edaf | 2563 | { (yyval.command) = clean_simple_command ((yyvsp[0].command)); } |
a78e27a1 | 2564 | #line 2565 "y.tab.c" |
3185942a JA |
2565 | break; |
2566 | ||
a78e27a1 CR |
2567 | case 63: /* command: shell_command */ |
2568 | #line 790 "/usr/local/src/chet/src/bash/src/parse.y" | |
8868edaf | 2569 | { (yyval.command) = (yyvsp[0].command); } |
a78e27a1 | 2570 | #line 2571 "y.tab.c" |
3185942a JA |
2571 | break; |
2572 | ||
a78e27a1 CR |
2573 | case 64: /* command: shell_command redirection_list */ |
2574 | #line 792 "/usr/local/src/chet/src/bash/src/parse.y" | |
8868edaf | 2575 | { |
f73dda09 JA |
2576 | COMMAND *tc; |
2577 | ||
a0c0a00f | 2578 | tc = (yyvsp[-1].command); |
d233b485 | 2579 | if (tc && tc->redirects) |
f73dda09 JA |
2580 | { |
2581 | register REDIRECT *t; | |
2582 | for (t = tc->redirects; t->next; t = t->next) | |
2583 | ; | |
a0c0a00f | 2584 | t->next = (yyvsp[0].redirect); |
f73dda09 | 2585 | } |
d233b485 | 2586 | else if (tc) |
a0c0a00f CR |
2587 | tc->redirects = (yyvsp[0].redirect); |
2588 | (yyval.command) = (yyvsp[-1].command); | |
3185942a | 2589 | } |
a78e27a1 | 2590 | #line 2591 "y.tab.c" |
3185942a JA |
2591 | break; |
2592 | ||
a78e27a1 CR |
2593 | case 65: /* command: function_def */ |
2594 | #line 808 "/usr/local/src/chet/src/bash/src/parse.y" | |
8868edaf | 2595 | { (yyval.command) = (yyvsp[0].command); } |
a78e27a1 | 2596 | #line 2597 "y.tab.c" |
3185942a JA |
2597 | break; |
2598 | ||
a78e27a1 CR |
2599 | case 66: /* command: coproc */ |
2600 | #line 810 "/usr/local/src/chet/src/bash/src/parse.y" | |
8868edaf | 2601 | { (yyval.command) = (yyvsp[0].command); } |
a78e27a1 | 2602 | #line 2603 "y.tab.c" |
3185942a JA |
2603 | break; |
2604 | ||
a78e27a1 CR |
2605 | case 67: /* shell_command: for_command */ |
2606 | #line 814 "/usr/local/src/chet/src/bash/src/parse.y" | |
8868edaf | 2607 | { (yyval.command) = (yyvsp[0].command); } |
a78e27a1 | 2608 | #line 2609 "y.tab.c" |
3185942a JA |
2609 | break; |
2610 | ||
a78e27a1 CR |
2611 | case 68: /* shell_command: case_command */ |
2612 | #line 816 "/usr/local/src/chet/src/bash/src/parse.y" | |
8868edaf | 2613 | { (yyval.command) = (yyvsp[0].command); } |
a78e27a1 | 2614 | #line 2615 "y.tab.c" |
3185942a JA |
2615 | break; |
2616 | ||
a78e27a1 CR |
2617 | case 69: /* shell_command: WHILE compound_list DO compound_list DONE */ |
2618 | #line 818 "/usr/local/src/chet/src/bash/src/parse.y" | |
8868edaf | 2619 | { (yyval.command) = make_while_command ((yyvsp[-3].command), (yyvsp[-1].command)); } |
a78e27a1 | 2620 | #line 2621 "y.tab.c" |
3185942a JA |
2621 | break; |
2622 | ||
a78e27a1 CR |
2623 | case 70: /* shell_command: UNTIL compound_list DO compound_list DONE */ |
2624 | #line 820 "/usr/local/src/chet/src/bash/src/parse.y" | |
8868edaf | 2625 | { (yyval.command) = make_until_command ((yyvsp[-3].command), (yyvsp[-1].command)); } |
a78e27a1 | 2626 | #line 2627 "y.tab.c" |
3185942a JA |
2627 | break; |
2628 | ||
a78e27a1 CR |
2629 | case 71: /* shell_command: select_command */ |
2630 | #line 822 "/usr/local/src/chet/src/bash/src/parse.y" | |
8868edaf | 2631 | { (yyval.command) = (yyvsp[0].command); } |
a78e27a1 | 2632 | #line 2633 "y.tab.c" |
3185942a JA |
2633 | break; |
2634 | ||
a78e27a1 CR |
2635 | case 72: /* shell_command: if_command */ |
2636 | #line 824 "/usr/local/src/chet/src/bash/src/parse.y" | |
8868edaf | 2637 | { (yyval.command) = (yyvsp[0].command); } |
a78e27a1 | 2638 | #line 2639 "y.tab.c" |
3185942a JA |
2639 | break; |
2640 | ||
a78e27a1 CR |
2641 | case 73: /* shell_command: subshell */ |
2642 | #line 826 "/usr/local/src/chet/src/bash/src/parse.y" | |
8868edaf | 2643 | { (yyval.command) = (yyvsp[0].command); } |
a78e27a1 | 2644 | #line 2645 "y.tab.c" |
3185942a JA |
2645 | break; |
2646 | ||
a78e27a1 CR |
2647 | case 74: /* shell_command: group_command */ |
2648 | #line 828 "/usr/local/src/chet/src/bash/src/parse.y" | |
8868edaf | 2649 | { (yyval.command) = (yyvsp[0].command); } |
a78e27a1 | 2650 | #line 2651 "y.tab.c" |
3185942a JA |
2651 | break; |
2652 | ||
a78e27a1 CR |
2653 | case 75: /* shell_command: arith_command */ |
2654 | #line 830 "/usr/local/src/chet/src/bash/src/parse.y" | |
8868edaf | 2655 | { (yyval.command) = (yyvsp[0].command); } |
a78e27a1 | 2656 | #line 2657 "y.tab.c" |
3185942a JA |
2657 | break; |
2658 | ||
a78e27a1 CR |
2659 | case 76: /* shell_command: cond_command */ |
2660 | #line 832 "/usr/local/src/chet/src/bash/src/parse.y" | |
8868edaf | 2661 | { (yyval.command) = (yyvsp[0].command); } |
a78e27a1 | 2662 | #line 2663 "y.tab.c" |
3185942a JA |
2663 | break; |
2664 | ||
a78e27a1 CR |
2665 | case 77: /* shell_command: arith_for_command */ |
2666 | #line 834 "/usr/local/src/chet/src/bash/src/parse.y" | |
8868edaf | 2667 | { (yyval.command) = (yyvsp[0].command); } |
a78e27a1 | 2668 | #line 2669 "y.tab.c" |
3185942a JA |
2669 | break; |
2670 | ||
a78e27a1 CR |
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" | |
8868edaf | 2673 | { |
a0c0a00f | 2674 | (yyval.command) = make_for_command ((yyvsp[-4].word), add_string_to_list ("\"$@\"", (WORD_LIST *)NULL), (yyvsp[-1].command), word_lineno[word_top]); |
b80f6443 | 2675 | if (word_top > 0) word_top--; |
3185942a | 2676 | } |
a78e27a1 | 2677 | #line 2678 "y.tab.c" |
3185942a JA |
2678 | break; |
2679 | ||
a78e27a1 CR |
2680 | case 79: /* for_command: FOR WORD newline_list '{' compound_list '}' */ |
2681 | #line 843 "/usr/local/src/chet/src/bash/src/parse.y" | |
8868edaf | 2682 | { |
d233b485 | 2683 | (yyval.command) = make_for_command ((yyvsp[-4].word), add_string_to_list ("\"$@\"", (WORD_LIST *)NULL), (yyvsp[-1].command), word_lineno[word_top]); |
b80f6443 | 2684 | if (word_top > 0) word_top--; |
3185942a | 2685 | } |
a78e27a1 | 2686 | #line 2687 "y.tab.c" |
3185942a JA |
2687 | break; |
2688 | ||
a78e27a1 CR |
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" | |
8868edaf | 2691 | { |
a0c0a00f | 2692 | (yyval.command) = make_for_command ((yyvsp[-5].word), add_string_to_list ("\"$@\"", (WORD_LIST *)NULL), (yyvsp[-1].command), word_lineno[word_top]); |
b80f6443 | 2693 | if (word_top > 0) word_top--; |
3185942a | 2694 | } |
a78e27a1 | 2695 | #line 2696 "y.tab.c" |
3185942a JA |
2696 | break; |
2697 | ||
a78e27a1 CR |
2698 | case 81: /* for_command: FOR WORD ';' newline_list '{' compound_list '}' */ |
2699 | #line 853 "/usr/local/src/chet/src/bash/src/parse.y" | |
8868edaf | 2700 | { |
d233b485 | 2701 | (yyval.command) = make_for_command ((yyvsp[-5].word), add_string_to_list ("\"$@\"", (WORD_LIST *)NULL), (yyvsp[-1].command), word_lineno[word_top]); |
b80f6443 | 2702 | if (word_top > 0) word_top--; |
3185942a | 2703 | } |
a78e27a1 | 2704 | #line 2705 "y.tab.c" |
3185942a JA |
2705 | break; |
2706 | ||
a78e27a1 CR |
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" | |
8868edaf | 2709 | { |
a0c0a00f | 2710 | (yyval.command) = make_for_command ((yyvsp[-8].word), REVERSE_LIST ((yyvsp[-5].word_list), WORD_LIST *), (yyvsp[-1].command), word_lineno[word_top]); |
b80f6443 | 2711 | if (word_top > 0) word_top--; |
3185942a | 2712 | } |
a78e27a1 | 2713 | #line 2714 "y.tab.c" |
3185942a JA |
2714 | break; |
2715 | ||
a78e27a1 CR |
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" | |
8868edaf | 2718 | { |
d233b485 | 2719 | (yyval.command) = make_for_command ((yyvsp[-8].word), REVERSE_LIST ((yyvsp[-5].word_list), WORD_LIST *), (yyvsp[-1].command), word_lineno[word_top]); |
b80f6443 | 2720 | if (word_top > 0) word_top--; |
3185942a | 2721 | } |
a78e27a1 | 2722 | #line 2723 "y.tab.c" |
3185942a JA |
2723 | break; |
2724 | ||
a78e27a1 CR |
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" | |
8868edaf | 2727 | { |
a0c0a00f | 2728 | (yyval.command) = make_for_command ((yyvsp[-7].word), (WORD_LIST *)NULL, (yyvsp[-1].command), word_lineno[word_top]); |
b80f6443 | 2729 | if (word_top > 0) word_top--; |
3185942a | 2730 | } |
a78e27a1 | 2731 | #line 2732 "y.tab.c" |
3185942a JA |
2732 | break; |
2733 | ||
a78e27a1 CR |
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" | |
8868edaf | 2736 | { |
d233b485 CR |
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 | } | |
a78e27a1 | 2740 | #line 2741 "y.tab.c" |
3185942a JA |
2741 | break; |
2742 | ||
a78e27a1 CR |
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" | |
8868edaf | 2745 | { |
a0c0a00f | 2746 | (yyval.command) = make_arith_for_command ((yyvsp[-5].word_list), (yyvsp[-1].command), arith_for_lineno); |
d233b485 | 2747 | if ((yyval.command) == 0) YYERROR; |
b80f6443 | 2748 | if (word_top > 0) word_top--; |
3185942a | 2749 | } |
a78e27a1 | 2750 | #line 2751 "y.tab.c" |
3185942a JA |
2751 | break; |
2752 | ||
a78e27a1 CR |
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" | |
8868edaf | 2755 | { |
d233b485 CR |
2756 | (yyval.command) = make_arith_for_command ((yyvsp[-5].word_list), (yyvsp[-1].command), arith_for_lineno); |
2757 | if ((yyval.command) == 0) YYERROR; | |
b80f6443 | 2758 | if (word_top > 0) word_top--; |
3185942a | 2759 | } |
a78e27a1 | 2760 | #line 2761 "y.tab.c" |
3185942a JA |
2761 | break; |
2762 | ||
a78e27a1 CR |
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" | |
8868edaf | 2765 | { |
a0c0a00f | 2766 | (yyval.command) = make_arith_for_command ((yyvsp[-3].word_list), (yyvsp[-1].command), arith_for_lineno); |
d233b485 | 2767 | if ((yyval.command) == 0) YYERROR; |
b80f6443 | 2768 | if (word_top > 0) word_top--; |
3185942a | 2769 | } |
a78e27a1 | 2770 | #line 2771 "y.tab.c" |
3185942a JA |
2771 | break; |
2772 | ||
a78e27a1 CR |
2773 | case 89: /* arith_for_command: FOR ARITH_FOR_EXPRS '{' compound_list '}' */ |
2774 | #line 898 "/usr/local/src/chet/src/bash/src/parse.y" | |
8868edaf | 2775 | { |
d233b485 CR |
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 | } | |
a78e27a1 | 2780 | #line 2781 "y.tab.c" |
3185942a JA |
2781 | break; |
2782 | ||
a78e27a1 CR |
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" | |
8868edaf | 2785 | { |
a0c0a00f | 2786 | (yyval.command) = make_select_command ((yyvsp[-4].word), add_string_to_list ("\"$@\"", (WORD_LIST *)NULL), (yyvsp[-1].command), word_lineno[word_top]); |
b80f6443 | 2787 | if (word_top > 0) word_top--; |
3185942a | 2788 | } |
a78e27a1 | 2789 | #line 2790 "y.tab.c" |
3185942a JA |
2790 | break; |
2791 | ||
a78e27a1 CR |
2792 | case 91: /* select_command: SELECT WORD newline_list '{' compound_list '}' */ |
2793 | #line 911 "/usr/local/src/chet/src/bash/src/parse.y" | |
8868edaf | 2794 | { |
d233b485 | 2795 | (yyval.command) = make_select_command ((yyvsp[-4].word), add_string_to_list ("\"$@\"", (WORD_LIST *)NULL), (yyvsp[-1].command), word_lineno[word_top]); |
b80f6443 | 2796 | if (word_top > 0) word_top--; |
3185942a | 2797 | } |
a78e27a1 | 2798 | #line 2799 "y.tab.c" |
3185942a JA |
2799 | break; |
2800 | ||
a78e27a1 CR |
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" | |
8868edaf | 2803 | { |
a0c0a00f | 2804 | (yyval.command) = make_select_command ((yyvsp[-5].word), add_string_to_list ("\"$@\"", (WORD_LIST *)NULL), (yyvsp[-1].command), word_lineno[word_top]); |
b80f6443 | 2805 | if (word_top > 0) word_top--; |
3185942a | 2806 | } |
a78e27a1 | 2807 | #line 2808 "y.tab.c" |
3185942a JA |
2808 | break; |
2809 | ||
a78e27a1 CR |
2810 | case 93: /* select_command: SELECT WORD ';' newline_list '{' compound_list '}' */ |
2811 | #line 921 "/usr/local/src/chet/src/bash/src/parse.y" | |
8868edaf | 2812 | { |
d233b485 | 2813 | (yyval.command) = make_select_command ((yyvsp[-5].word), add_string_to_list ("\"$@\"", (WORD_LIST *)NULL), (yyvsp[-1].command), word_lineno[word_top]); |
b80f6443 | 2814 | if (word_top > 0) word_top--; |
3185942a | 2815 | } |
a78e27a1 | 2816 | #line 2817 "y.tab.c" |
3185942a JA |
2817 | break; |
2818 | ||
a78e27a1 CR |
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" | |
8868edaf | 2821 | { |
a0c0a00f | 2822 | (yyval.command) = make_select_command ((yyvsp[-8].word), REVERSE_LIST ((yyvsp[-5].word_list), WORD_LIST *), (yyvsp[-1].command), word_lineno[word_top]); |
b80f6443 | 2823 | if (word_top > 0) word_top--; |
3185942a | 2824 | } |
a78e27a1 | 2825 | #line 2826 "y.tab.c" |
3185942a JA |
2826 | break; |
2827 | ||
a78e27a1 CR |
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" | |
8868edaf | 2830 | { |
d233b485 | 2831 | (yyval.command) = make_select_command ((yyvsp[-8].word), REVERSE_LIST ((yyvsp[-5].word_list), WORD_LIST *), (yyvsp[-1].command), word_lineno[word_top]); |
b80f6443 | 2832 | if (word_top > 0) word_top--; |
3185942a | 2833 | } |
a78e27a1 | 2834 | #line 2835 "y.tab.c" |
3185942a JA |
2835 | break; |
2836 | ||
a78e27a1 CR |
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" | |
8868edaf | 2839 | { |
d233b485 | 2840 | (yyval.command) = make_select_command ((yyvsp[-7].word), (WORD_LIST *)NULL, (yyvsp[-1].command), word_lineno[word_top]); |
b80f6443 | 2841 | if (word_top > 0) word_top--; |
3185942a | 2842 | } |
a78e27a1 | 2843 | #line 2844 "y.tab.c" |
3185942a JA |
2844 | break; |
2845 | ||
a78e27a1 CR |
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" | |
8868edaf | 2848 | { |
d233b485 | 2849 | (yyval.command) = make_select_command ((yyvsp[-7].word), (WORD_LIST *)NULL, (yyvsp[-1].command), word_lineno[word_top]); |
b80f6443 | 2850 | if (word_top > 0) word_top--; |
3185942a | 2851 | } |
a78e27a1 | 2852 | #line 2853 "y.tab.c" |
3185942a JA |
2853 | break; |
2854 | ||
a78e27a1 CR |
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" | |
8868edaf | 2857 | { |
d233b485 CR |
2858 | (yyval.command) = make_case_command ((yyvsp[-4].word), (PATTERN_LIST *)NULL, word_lineno[word_top]); |
2859 | if (word_top > 0) word_top--; | |
2860 | } | |
a78e27a1 | 2861 | #line 2862 "y.tab.c" |
3185942a JA |
2862 | break; |
2863 | ||
a78e27a1 CR |
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" | |
8868edaf | 2866 | { |
d233b485 CR |
2867 | (yyval.command) = make_case_command ((yyvsp[-5].word), (yyvsp[-2].pattern), word_lineno[word_top]); |
2868 | if (word_top > 0) word_top--; | |
2869 | } | |
a78e27a1 | 2870 | #line 2871 "y.tab.c" |
3185942a JA |
2871 | break; |
2872 | ||
a78e27a1 CR |
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" | |
8868edaf | 2875 | { |
d233b485 CR |
2876 | (yyval.command) = make_case_command ((yyvsp[-4].word), (yyvsp[-1].pattern), word_lineno[word_top]); |
2877 | if (word_top > 0) word_top--; | |
2878 | } | |
a78e27a1 | 2879 | #line 2880 "y.tab.c" |
3185942a JA |
2880 | break; |
2881 | ||
a78e27a1 CR |
2882 | case 101: /* function_def: WORD '(' ')' newline_list function_body */ |
2883 | #line 965 "/usr/local/src/chet/src/bash/src/parse.y" | |
8868edaf | 2884 | { (yyval.command) = make_function_def ((yyvsp[-4].word), (yyvsp[0].command), function_dstart, function_bstart); } |
a78e27a1 | 2885 | #line 2886 "y.tab.c" |
3185942a JA |
2886 | break; |
2887 | ||
a78e27a1 CR |
2888 | case 102: /* function_def: FUNCTION WORD '(' ')' newline_list function_body */ |
2889 | #line 967 "/usr/local/src/chet/src/bash/src/parse.y" | |
8868edaf | 2890 | { (yyval.command) = make_function_def ((yyvsp[-4].word), (yyvsp[0].command), function_dstart, function_bstart); } |
a78e27a1 | 2891 | #line 2892 "y.tab.c" |
d233b485 CR |
2892 | break; |
2893 | ||
a78e27a1 CR |
2894 | case 103: /* function_def: FUNCTION WORD function_body */ |
2895 | #line 969 "/usr/local/src/chet/src/bash/src/parse.y" | |
8868edaf | 2896 | { (yyval.command) = make_function_def ((yyvsp[-1].word), (yyvsp[0].command), function_dstart, function_bstart); } |
a78e27a1 | 2897 | #line 2898 "y.tab.c" |
d233b485 CR |
2898 | break; |
2899 | ||
a78e27a1 CR |
2900 | case 104: /* function_def: FUNCTION WORD '\n' newline_list function_body */ |
2901 | #line 971 "/usr/local/src/chet/src/bash/src/parse.y" | |
8868edaf | 2902 | { (yyval.command) = make_function_def ((yyvsp[-3].word), (yyvsp[0].command), function_dstart, function_bstart); } |
a78e27a1 | 2903 | #line 2904 "y.tab.c" |
d233b485 CR |
2904 | break; |
2905 | ||
a78e27a1 CR |
2906 | case 105: /* function_body: shell_command */ |
2907 | #line 975 "/usr/local/src/chet/src/bash/src/parse.y" | |
8868edaf | 2908 | { (yyval.command) = (yyvsp[0].command); } |
a78e27a1 | 2909 | #line 2910 "y.tab.c" |
8868edaf CR |
2910 | break; |
2911 | ||
a78e27a1 CR |
2912 | case 106: /* function_body: shell_command redirection_list */ |
2913 | #line 977 "/usr/local/src/chet/src/bash/src/parse.y" | |
8868edaf | 2914 | { |
f73dda09 JA |
2915 | COMMAND *tc; |
2916 | ||
a0c0a00f | 2917 | tc = (yyvsp[-1].command); |
f73dda09 JA |
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. */ | |
d233b485 | 2931 | if (tc && tc->redirects) |
f73dda09 JA |
2932 | { |
2933 | register REDIRECT *t; | |
2934 | for (t = tc->redirects; t->next; t = t->next) | |
2935 | ; | |
a0c0a00f | 2936 | t->next = (yyvsp[0].redirect); |
f73dda09 | 2937 | } |
d233b485 | 2938 | else if (tc) |
a0c0a00f CR |
2939 | tc->redirects = (yyvsp[0].redirect); |
2940 | (yyval.command) = (yyvsp[-1].command); | |
3185942a | 2941 | } |
a78e27a1 | 2942 | #line 2943 "y.tab.c" |
3185942a JA |
2943 | break; |
2944 | ||
a78e27a1 CR |
2945 | case 107: /* subshell: '(' compound_list ')' */ |
2946 | #line 1008 "/usr/local/src/chet/src/bash/src/parse.y" | |
8868edaf | 2947 | { |
a0c0a00f | 2948 | (yyval.command) = make_subshell_command ((yyvsp[-1].command)); |
3185942a JA |
2949 | (yyval.command)->flags |= CMD_WANT_SUBSHELL; |
2950 | } | |
a78e27a1 | 2951 | #line 2952 "y.tab.c" |
74091dd4 CR |
2952 | break; |
2953 | ||
a78e27a1 CR |
2954 | case 108: /* comsub: DOLPAREN compound_list ')' */ |
2955 | #line 1015 "/usr/local/src/chet/src/bash/src/parse.y" | |
74091dd4 CR |
2956 | { |
2957 | (yyval.command) = (yyvsp[-1].command); | |
2958 | } | |
a78e27a1 | 2959 | #line 2960 "y.tab.c" |
74091dd4 CR |
2960 | break; |
2961 | ||
a78e27a1 CR |
2962 | case 109: /* comsub: DOLPAREN newline_list ')' */ |
2963 | #line 1019 "/usr/local/src/chet/src/bash/src/parse.y" | |
74091dd4 CR |
2964 | { |
2965 | (yyval.command) = (COMMAND *)NULL; | |
2966 | } | |
a78e27a1 | 2967 | #line 2968 "y.tab.c" |
3185942a JA |
2968 | break; |
2969 | ||
a78e27a1 CR |
2970 | case 110: /* coproc: COPROC shell_command */ |
2971 | #line 1025 "/usr/local/src/chet/src/bash/src/parse.y" | |
8868edaf | 2972 | { |
a0c0a00f | 2973 | (yyval.command) = make_coproc_command ("COPROC", (yyvsp[0].command)); |
3185942a JA |
2974 | (yyval.command)->flags |= CMD_WANT_SUBSHELL|CMD_COPROC_SUBSHELL; |
2975 | } | |
a78e27a1 | 2976 | #line 2977 "y.tab.c" |
3185942a JA |
2977 | break; |
2978 | ||
a78e27a1 CR |
2979 | case 111: /* coproc: COPROC shell_command redirection_list */ |
2980 | #line 1030 "/usr/local/src/chet/src/bash/src/parse.y" | |
8868edaf | 2981 | { |
3185942a JA |
2982 | COMMAND *tc; |
2983 | ||
a0c0a00f | 2984 | tc = (yyvsp[-1].command); |
d233b485 | 2985 | if (tc && tc->redirects) |
3185942a JA |
2986 | { |
2987 | register REDIRECT *t; | |
2988 | for (t = tc->redirects; t->next; t = t->next) | |
2989 | ; | |
a0c0a00f | 2990 | t->next = (yyvsp[0].redirect); |
3185942a | 2991 | } |
d233b485 | 2992 | else if (tc) |
a0c0a00f CR |
2993 | tc->redirects = (yyvsp[0].redirect); |
2994 | (yyval.command) = make_coproc_command ("COPROC", (yyvsp[-1].command)); | |
3185942a JA |
2995 | (yyval.command)->flags |= CMD_WANT_SUBSHELL|CMD_COPROC_SUBSHELL; |
2996 | } | |
a78e27a1 | 2997 | #line 2998 "y.tab.c" |
3185942a JA |
2998 | break; |
2999 | ||
a78e27a1 CR |
3000 | case 112: /* coproc: COPROC WORD shell_command */ |
3001 | #line 1047 "/usr/local/src/chet/src/bash/src/parse.y" | |
8868edaf | 3002 | { |
a0c0a00f | 3003 | (yyval.command) = make_coproc_command ((yyvsp[-1].word)->word, (yyvsp[0].command)); |
3185942a JA |
3004 | (yyval.command)->flags |= CMD_WANT_SUBSHELL|CMD_COPROC_SUBSHELL; |
3005 | } | |
a78e27a1 | 3006 | #line 3007 "y.tab.c" |
3185942a JA |
3007 | break; |
3008 | ||
a78e27a1 CR |
3009 | case 113: /* coproc: COPROC WORD shell_command redirection_list */ |
3010 | #line 1052 "/usr/local/src/chet/src/bash/src/parse.y" | |
8868edaf | 3011 | { |
3185942a JA |
3012 | COMMAND *tc; |
3013 | ||
a0c0a00f | 3014 | tc = (yyvsp[-1].command); |
d233b485 | 3015 | if (tc && tc->redirects) |
3185942a JA |
3016 | { |
3017 | register REDIRECT *t; | |
3018 | for (t = tc->redirects; t->next; t = t->next) | |
3019 | ; | |
a0c0a00f | 3020 | t->next = (yyvsp[0].redirect); |
3185942a | 3021 | } |
d233b485 | 3022 | else if (tc) |
a0c0a00f CR |
3023 | tc->redirects = (yyvsp[0].redirect); |
3024 | (yyval.command) = make_coproc_command ((yyvsp[-2].word)->word, (yyvsp[-1].command)); | |
3185942a JA |
3025 | (yyval.command)->flags |= CMD_WANT_SUBSHELL|CMD_COPROC_SUBSHELL; |
3026 | } | |
a78e27a1 | 3027 | #line 3028 "y.tab.c" |
3185942a JA |
3028 | break; |
3029 | ||
a78e27a1 CR |
3030 | case 114: /* coproc: COPROC simple_command */ |
3031 | #line 1069 "/usr/local/src/chet/src/bash/src/parse.y" | |
8868edaf | 3032 | { |
a0c0a00f | 3033 | (yyval.command) = make_coproc_command ("COPROC", clean_simple_command ((yyvsp[0].command))); |
3185942a JA |
3034 | (yyval.command)->flags |= CMD_WANT_SUBSHELL|CMD_COPROC_SUBSHELL; |
3035 | } | |
a78e27a1 | 3036 | #line 3037 "y.tab.c" |
3185942a JA |
3037 | break; |
3038 | ||
a78e27a1 CR |
3039 | case 115: /* if_command: IF compound_list THEN compound_list FI */ |
3040 | #line 1076 "/usr/local/src/chet/src/bash/src/parse.y" | |
8868edaf | 3041 | { (yyval.command) = make_if_command ((yyvsp[-3].command), (yyvsp[-1].command), (COMMAND *)NULL); } |
a78e27a1 | 3042 | #line 3043 "y.tab.c" |
3185942a JA |
3043 | break; |
3044 | ||
a78e27a1 CR |
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" | |
8868edaf | 3047 | { (yyval.command) = make_if_command ((yyvsp[-5].command), (yyvsp[-3].command), (yyvsp[-1].command)); } |
a78e27a1 | 3048 | #line 3049 "y.tab.c" |
3185942a JA |
3049 | break; |
3050 | ||
a78e27a1 CR |
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" | |
8868edaf | 3053 | { (yyval.command) = make_if_command ((yyvsp[-4].command), (yyvsp[-2].command), (yyvsp[-1].command)); } |
a78e27a1 | 3054 | #line 3055 "y.tab.c" |
3185942a JA |
3055 | break; |
3056 | ||
a78e27a1 CR |
3057 | case 118: /* group_command: '{' compound_list '}' */ |
3058 | #line 1085 "/usr/local/src/chet/src/bash/src/parse.y" | |
8868edaf | 3059 | { (yyval.command) = make_group_command ((yyvsp[-1].command)); } |
a78e27a1 | 3060 | #line 3061 "y.tab.c" |
3185942a JA |
3061 | break; |
3062 | ||
a78e27a1 CR |
3063 | case 119: /* arith_command: ARITH_CMD */ |
3064 | #line 1089 "/usr/local/src/chet/src/bash/src/parse.y" | |
8868edaf | 3065 | { (yyval.command) = make_arith_command ((yyvsp[0].word_list)); } |
a78e27a1 | 3066 | #line 3067 "y.tab.c" |
3185942a JA |
3067 | break; |
3068 | ||
a78e27a1 CR |
3069 | case 120: /* cond_command: COND_START COND_CMD COND_END */ |
3070 | #line 1093 "/usr/local/src/chet/src/bash/src/parse.y" | |
8868edaf | 3071 | { (yyval.command) = (yyvsp[-1].command); } |
a78e27a1 | 3072 | #line 3073 "y.tab.c" |
3185942a JA |
3073 | break; |
3074 | ||
a78e27a1 CR |
3075 | case 121: /* elif_clause: ELIF compound_list THEN compound_list */ |
3076 | #line 1097 "/usr/local/src/chet/src/bash/src/parse.y" | |
8868edaf | 3077 | { (yyval.command) = make_if_command ((yyvsp[-2].command), (yyvsp[0].command), (COMMAND *)NULL); } |
a78e27a1 | 3078 | #line 3079 "y.tab.c" |
3185942a JA |
3079 | break; |
3080 | ||
a78e27a1 CR |
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" | |
8868edaf | 3083 | { (yyval.command) = make_if_command ((yyvsp[-4].command), (yyvsp[-2].command), (yyvsp[0].command)); } |
a78e27a1 | 3084 | #line 3085 "y.tab.c" |
3185942a JA |
3085 | break; |
3086 | ||
a78e27a1 CR |
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" | |
8868edaf | 3089 | { (yyval.command) = make_if_command ((yyvsp[-3].command), (yyvsp[-1].command), (yyvsp[0].command)); } |
a78e27a1 | 3090 | #line 3091 "y.tab.c" |
3185942a JA |
3091 | break; |
3092 | ||
a78e27a1 CR |
3093 | case 125: /* case_clause: case_clause_sequence pattern_list */ |
3094 | #line 1106 "/usr/local/src/chet/src/bash/src/parse.y" | |
8868edaf | 3095 | { (yyvsp[0].pattern)->next = (yyvsp[-1].pattern); (yyval.pattern) = (yyvsp[0].pattern); } |
a78e27a1 | 3096 | #line 3097 "y.tab.c" |
3185942a JA |
3097 | break; |
3098 | ||
a78e27a1 CR |
3099 | case 126: /* pattern_list: newline_list pattern ')' compound_list */ |
3100 | #line 1110 "/usr/local/src/chet/src/bash/src/parse.y" | |
8868edaf | 3101 | { (yyval.pattern) = make_pattern_list ((yyvsp[-2].word_list), (yyvsp[0].command)); } |
a78e27a1 | 3102 | #line 3103 "y.tab.c" |
3185942a JA |
3103 | break; |
3104 | ||
a78e27a1 CR |
3105 | case 127: /* pattern_list: newline_list pattern ')' newline_list */ |
3106 | #line 1112 "/usr/local/src/chet/src/bash/src/parse.y" | |
8868edaf | 3107 | { (yyval.pattern) = make_pattern_list ((yyvsp[-2].word_list), (COMMAND *)NULL); } |
a78e27a1 | 3108 | #line 3109 "y.tab.c" |
3185942a JA |
3109 | break; |
3110 | ||
a78e27a1 CR |
3111 | case 128: /* pattern_list: newline_list '(' pattern ')' compound_list */ |
3112 | #line 1114 "/usr/local/src/chet/src/bash/src/parse.y" | |
8868edaf | 3113 | { (yyval.pattern) = make_pattern_list ((yyvsp[-2].word_list), (yyvsp[0].command)); } |
a78e27a1 | 3114 | #line 3115 "y.tab.c" |
3185942a JA |
3115 | break; |
3116 | ||
a78e27a1 CR |
3117 | case 129: /* pattern_list: newline_list '(' pattern ')' newline_list */ |
3118 | #line 1116 "/usr/local/src/chet/src/bash/src/parse.y" | |
8868edaf | 3119 | { (yyval.pattern) = make_pattern_list ((yyvsp[-2].word_list), (COMMAND *)NULL); } |
a78e27a1 | 3120 | #line 3121 "y.tab.c" |
3185942a JA |
3121 | break; |
3122 | ||
a78e27a1 CR |
3123 | case 130: /* case_clause_sequence: pattern_list SEMI_SEMI */ |
3124 | #line 1120 "/usr/local/src/chet/src/bash/src/parse.y" | |
8868edaf | 3125 | { (yyval.pattern) = (yyvsp[-1].pattern); } |
a78e27a1 | 3126 | #line 3127 "y.tab.c" |
3185942a JA |
3127 | break; |
3128 | ||
a78e27a1 CR |
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" | |
8868edaf | 3131 | { (yyvsp[-1].pattern)->next = (yyvsp[-2].pattern); (yyval.pattern) = (yyvsp[-1].pattern); } |
a78e27a1 | 3132 | #line 3133 "y.tab.c" |
3185942a JA |
3133 | break; |
3134 | ||
a78e27a1 CR |
3135 | case 132: /* case_clause_sequence: pattern_list SEMI_AND */ |
3136 | #line 1124 "/usr/local/src/chet/src/bash/src/parse.y" | |
8868edaf | 3137 | { (yyvsp[-1].pattern)->flags |= CASEPAT_FALLTHROUGH; (yyval.pattern) = (yyvsp[-1].pattern); } |
a78e27a1 | 3138 | #line 3139 "y.tab.c" |
3185942a JA |
3139 | break; |
3140 | ||
a78e27a1 CR |
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" | |
8868edaf | 3143 | { (yyvsp[-1].pattern)->flags |= CASEPAT_FALLTHROUGH; (yyvsp[-1].pattern)->next = (yyvsp[-2].pattern); (yyval.pattern) = (yyvsp[-1].pattern); } |
a78e27a1 | 3144 | #line 3145 "y.tab.c" |
3185942a JA |
3145 | break; |
3146 | ||
a78e27a1 CR |
3147 | case 134: /* case_clause_sequence: pattern_list SEMI_SEMI_AND */ |
3148 | #line 1128 "/usr/local/src/chet/src/bash/src/parse.y" | |
8868edaf | 3149 | { (yyvsp[-1].pattern)->flags |= CASEPAT_TESTNEXT; (yyval.pattern) = (yyvsp[-1].pattern); } |
a78e27a1 | 3150 | #line 3151 "y.tab.c" |
3185942a JA |
3151 | break; |
3152 | ||
a78e27a1 CR |
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" | |
8868edaf | 3155 | { (yyvsp[-1].pattern)->flags |= CASEPAT_TESTNEXT; (yyvsp[-1].pattern)->next = (yyvsp[-2].pattern); (yyval.pattern) = (yyvsp[-1].pattern); } |
a78e27a1 | 3156 | #line 3157 "y.tab.c" |
3185942a JA |
3157 | break; |
3158 | ||
a78e27a1 CR |
3159 | case 136: /* pattern: WORD */ |
3160 | #line 1134 "/usr/local/src/chet/src/bash/src/parse.y" | |
8868edaf | 3161 | { (yyval.word_list) = make_word_list ((yyvsp[0].word), (WORD_LIST *)NULL); } |
a78e27a1 | 3162 | #line 3163 "y.tab.c" |
3185942a JA |
3163 | break; |
3164 | ||
a78e27a1 CR |
3165 | case 137: /* pattern: pattern '|' WORD */ |
3166 | #line 1136 "/usr/local/src/chet/src/bash/src/parse.y" | |
8868edaf | 3167 | { (yyval.word_list) = make_word_list ((yyvsp[0].word), (yyvsp[-2].word_list)); } |
a78e27a1 | 3168 | #line 3169 "y.tab.c" |
8868edaf CR |
3169 | break; |
3170 | ||
a78e27a1 CR |
3171 | case 138: /* compound_list: newline_list list0 */ |
3172 | #line 1145 "/usr/local/src/chet/src/bash/src/parse.y" | |
8868edaf | 3173 | { |
a0c0a00f | 3174 | (yyval.command) = (yyvsp[0].command); |
74091dd4 | 3175 | if (need_here_doc && last_read_token == '\n') |
f73dda09 | 3176 | gather_here_documents (); |
3185942a | 3177 | } |
a78e27a1 | 3178 | #line 3179 "y.tab.c" |
3185942a JA |
3179 | break; |
3180 | ||
a78e27a1 CR |
3181 | case 139: /* compound_list: newline_list list1 */ |
3182 | #line 1151 "/usr/local/src/chet/src/bash/src/parse.y" | |
8868edaf | 3183 | { |
a0c0a00f | 3184 | (yyval.command) = (yyvsp[0].command); |
3185942a | 3185 | } |
a78e27a1 | 3186 | #line 3187 "y.tab.c" |
3185942a JA |
3187 | break; |
3188 | ||
a78e27a1 CR |
3189 | case 141: /* list0: list1 '&' newline_list */ |
3190 | #line 1158 "/usr/local/src/chet/src/bash/src/parse.y" | |
8868edaf | 3191 | { |
a0c0a00f CR |
3192 | if ((yyvsp[-2].command)->type == cm_connection) |
3193 | (yyval.command) = connect_async_list ((yyvsp[-2].command), (COMMAND *)NULL, '&'); | |
f73dda09 | 3194 | else |
a0c0a00f | 3195 | (yyval.command) = command_connect ((yyvsp[-2].command), (COMMAND *)NULL, '&'); |
3185942a | 3196 | } |
a78e27a1 | 3197 | #line 3198 "y.tab.c" |
3185942a JA |
3198 | break; |
3199 | ||
a78e27a1 CR |
3200 | case 143: /* list1: list1 AND_AND newline_list list1 */ |
3201 | #line 1169 "/usr/local/src/chet/src/bash/src/parse.y" | |
8868edaf | 3202 | { (yyval.command) = command_connect ((yyvsp[-3].command), (yyvsp[0].command), AND_AND); } |
a78e27a1 | 3203 | #line 3204 "y.tab.c" |
3185942a JA |
3204 | break; |
3205 | ||
a78e27a1 CR |
3206 | case 144: /* list1: list1 OR_OR newline_list list1 */ |
3207 | #line 1171 "/usr/local/src/chet/src/bash/src/parse.y" | |
8868edaf | 3208 | { (yyval.command) = command_connect ((yyvsp[-3].command), (yyvsp[0].command), OR_OR); } |
a78e27a1 | 3209 | #line 3210 "y.tab.c" |
8868edaf CR |
3210 | break; |
3211 | ||
a78e27a1 CR |
3212 | case 145: /* list1: list1 '&' newline_list list1 */ |
3213 | #line 1173 "/usr/local/src/chet/src/bash/src/parse.y" | |
8868edaf | 3214 | { |
a0c0a00f CR |
3215 | if ((yyvsp[-3].command)->type == cm_connection) |
3216 | (yyval.command) = connect_async_list ((yyvsp[-3].command), (yyvsp[0].command), '&'); | |
f73dda09 | 3217 | else |
a0c0a00f | 3218 | (yyval.command) = command_connect ((yyvsp[-3].command), (yyvsp[0].command), '&'); |
3185942a | 3219 | } |
a78e27a1 | 3220 | #line 3221 "y.tab.c" |
3185942a JA |
3221 | break; |
3222 | ||
a78e27a1 CR |
3223 | case 146: /* list1: list1 ';' newline_list list1 */ |
3224 | #line 1180 "/usr/local/src/chet/src/bash/src/parse.y" | |
8868edaf | 3225 | { (yyval.command) = command_connect ((yyvsp[-3].command), (yyvsp[0].command), ';'); } |
a78e27a1 | 3226 | #line 3227 "y.tab.c" |
3185942a JA |
3227 | break; |
3228 | ||
a78e27a1 CR |
3229 | case 147: /* list1: list1 '\n' newline_list list1 */ |
3230 | #line 1182 "/usr/local/src/chet/src/bash/src/parse.y" | |
74091dd4 CR |
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 | } | |
a78e27a1 | 3237 | #line 3238 "y.tab.c" |
3185942a JA |
3238 | break; |
3239 | ||
a78e27a1 CR |
3240 | case 148: /* list1: pipeline_command */ |
3241 | #line 1189 "/usr/local/src/chet/src/bash/src/parse.y" | |
8868edaf | 3242 | { (yyval.command) = (yyvsp[0].command); } |
a78e27a1 | 3243 | #line 3244 "y.tab.c" |
3185942a JA |
3244 | break; |
3245 | ||
a78e27a1 CR |
3246 | case 151: /* list_terminator: '\n' */ |
3247 | #line 1197 "/usr/local/src/chet/src/bash/src/parse.y" | |
8868edaf | 3248 | { (yyval.number) = '\n'; } |
a78e27a1 | 3249 | #line 3250 "y.tab.c" |
3185942a JA |
3250 | break; |
3251 | ||
a78e27a1 CR |
3252 | case 152: /* list_terminator: ';' */ |
3253 | #line 1199 "/usr/local/src/chet/src/bash/src/parse.y" | |
8868edaf | 3254 | { (yyval.number) = ';'; } |
a78e27a1 | 3255 | #line 3256 "y.tab.c" |
3185942a JA |
3256 | break; |
3257 | ||
a78e27a1 CR |
3258 | case 153: /* list_terminator: yacc_EOF */ |
3259 | #line 1201 "/usr/local/src/chet/src/bash/src/parse.y" | |
8868edaf | 3260 | { (yyval.number) = yacc_EOF; } |
a78e27a1 | 3261 | #line 3262 "y.tab.c" |
8868edaf CR |
3262 | break; |
3263 | ||
a78e27a1 CR |
3264 | case 156: /* simple_list: simple_list1 */ |
3265 | #line 1215 "/usr/local/src/chet/src/bash/src/parse.y" | |
8868edaf | 3266 | { |
a0c0a00f | 3267 | (yyval.command) = (yyvsp[0].command); |
f73dda09 | 3268 | if (need_here_doc) |
74091dd4 | 3269 | gather_here_documents (); /* XXX */ |
3185942a JA |
3270 | if ((parser_state & PST_CMDSUBST) && current_token == shell_eof_token) |
3271 | { | |
74091dd4 | 3272 | INTERNAL_DEBUG (("LEGACY: parser: command substitution simple_list1 -> simple_list")); |
a0c0a00f | 3273 | global_command = (yyvsp[0].command); |
3185942a | 3274 | eof_encountered = 0; |
74091dd4 CR |
3275 | if (bash_input.type == st_string) |
3276 | rewind_input_string (); | |
3185942a JA |
3277 | YYACCEPT; |
3278 | } | |
3279 | } | |
a78e27a1 | 3280 | #line 3281 "y.tab.c" |
3185942a JA |
3281 | break; |
3282 | ||
a78e27a1 CR |
3283 | case 157: /* simple_list: simple_list1 '&' */ |
3284 | #line 1230 "/usr/local/src/chet/src/bash/src/parse.y" | |
8868edaf | 3285 | { |
a0c0a00f CR |
3286 | if ((yyvsp[-1].command)->type == cm_connection) |
3287 | (yyval.command) = connect_async_list ((yyvsp[-1].command), (COMMAND *)NULL, '&'); | |
f73dda09 | 3288 | else |
a0c0a00f | 3289 | (yyval.command) = command_connect ((yyvsp[-1].command), (COMMAND *)NULL, '&'); |
f73dda09 | 3290 | if (need_here_doc) |
74091dd4 | 3291 | gather_here_documents (); /* XXX */ |
3185942a JA |
3292 | if ((parser_state & PST_CMDSUBST) && current_token == shell_eof_token) |
3293 | { | |
74091dd4 | 3294 | INTERNAL_DEBUG (("LEGACY: parser: command substitution simple_list1 '&' -> simple_list")); |
a0c0a00f | 3295 | global_command = (yyvsp[-1].command); |
3185942a | 3296 | eof_encountered = 0; |
74091dd4 CR |
3297 | if (bash_input.type == st_string) |
3298 | rewind_input_string (); | |
3185942a JA |
3299 | YYACCEPT; |
3300 | } | |
3301 | } | |
a78e27a1 | 3302 | #line 3303 "y.tab.c" |
3185942a JA |
3303 | break; |
3304 | ||
a78e27a1 CR |
3305 | case 158: /* simple_list: simple_list1 ';' */ |
3306 | #line 1248 "/usr/local/src/chet/src/bash/src/parse.y" | |
8868edaf | 3307 | { |
a0c0a00f | 3308 | (yyval.command) = (yyvsp[-1].command); |
f73dda09 | 3309 | if (need_here_doc) |
74091dd4 | 3310 | gather_here_documents (); /* XXX */ |
3185942a JA |
3311 | if ((parser_state & PST_CMDSUBST) && current_token == shell_eof_token) |
3312 | { | |
74091dd4 | 3313 | INTERNAL_DEBUG (("LEGACY: parser: command substitution simple_list1 ';' -> simple_list")); |
a0c0a00f | 3314 | global_command = (yyvsp[-1].command); |
3185942a | 3315 | eof_encountered = 0; |
74091dd4 CR |
3316 | if (bash_input.type == st_string) |
3317 | rewind_input_string (); | |
3185942a JA |
3318 | YYACCEPT; |
3319 | } | |
3320 | } | |
a78e27a1 | 3321 | #line 3322 "y.tab.c" |
3185942a JA |
3322 | break; |
3323 | ||
a78e27a1 CR |
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" | |
8868edaf | 3326 | { (yyval.command) = command_connect ((yyvsp[-3].command), (yyvsp[0].command), AND_AND); } |
a78e27a1 | 3327 | #line 3328 "y.tab.c" |
3185942a JA |
3328 | break; |
3329 | ||
a78e27a1 CR |
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" | |
8868edaf | 3332 | { (yyval.command) = command_connect ((yyvsp[-3].command), (yyvsp[0].command), OR_OR); } |
a78e27a1 | 3333 | #line 3334 "y.tab.c" |
8868edaf CR |
3334 | break; |
3335 | ||
a78e27a1 CR |
3336 | case 161: /* simple_list1: simple_list1 '&' simple_list1 */ |
3337 | #line 1269 "/usr/local/src/chet/src/bash/src/parse.y" | |
8868edaf | 3338 | { |
a0c0a00f CR |
3339 | if ((yyvsp[-2].command)->type == cm_connection) |
3340 | (yyval.command) = connect_async_list ((yyvsp[-2].command), (yyvsp[0].command), '&'); | |
f73dda09 | 3341 | else |
a0c0a00f | 3342 | (yyval.command) = command_connect ((yyvsp[-2].command), (yyvsp[0].command), '&'); |
3185942a | 3343 | } |
a78e27a1 | 3344 | #line 3345 "y.tab.c" |
3185942a JA |
3345 | break; |
3346 | ||
a78e27a1 CR |
3347 | case 162: /* simple_list1: simple_list1 ';' simple_list1 */ |
3348 | #line 1276 "/usr/local/src/chet/src/bash/src/parse.y" | |
8868edaf | 3349 | { (yyval.command) = command_connect ((yyvsp[-2].command), (yyvsp[0].command), ';'); } |
a78e27a1 | 3350 | #line 3351 "y.tab.c" |
3185942a JA |
3351 | break; |
3352 | ||
a78e27a1 CR |
3353 | case 163: /* simple_list1: pipeline_command */ |
3354 | #line 1279 "/usr/local/src/chet/src/bash/src/parse.y" | |
8868edaf | 3355 | { (yyval.command) = (yyvsp[0].command); } |
a78e27a1 | 3356 | #line 3357 "y.tab.c" |
3185942a JA |
3357 | break; |
3358 | ||
a78e27a1 CR |
3359 | case 164: /* pipeline_command: pipeline */ |
3360 | #line 1283 "/usr/local/src/chet/src/bash/src/parse.y" | |
8868edaf | 3361 | { (yyval.command) = (yyvsp[0].command); } |
a78e27a1 | 3362 | #line 3363 "y.tab.c" |
8868edaf CR |
3363 | break; |
3364 | ||
a78e27a1 CR |
3365 | case 165: /* pipeline_command: BANG pipeline_command */ |
3366 | #line 1285 "/usr/local/src/chet/src/bash/src/parse.y" | |
8868edaf | 3367 | { |
a0c0a00f CR |
3368 | if ((yyvsp[0].command)) |
3369 | (yyvsp[0].command)->flags ^= CMD_INVERT_RETURN; /* toggle */ | |
3370 | (yyval.command) = (yyvsp[0].command); | |
3185942a | 3371 | } |
a78e27a1 | 3372 | #line 3373 "y.tab.c" |
3185942a JA |
3373 | break; |
3374 | ||
a78e27a1 CR |
3375 | case 166: /* pipeline_command: timespec pipeline_command */ |
3376 | #line 1291 "/usr/local/src/chet/src/bash/src/parse.y" | |
8868edaf | 3377 | { |
a0c0a00f CR |
3378 | if ((yyvsp[0].command)) |
3379 | (yyvsp[0].command)->flags |= (yyvsp[-1].number); | |
3380 | (yyval.command) = (yyvsp[0].command); | |
3185942a | 3381 | } |
a78e27a1 | 3382 | #line 3383 "y.tab.c" |
3185942a JA |
3383 | break; |
3384 | ||
a78e27a1 CR |
3385 | case 167: /* pipeline_command: timespec list_terminator */ |
3386 | #line 1297 "/usr/local/src/chet/src/bash/src/parse.y" | |
8868edaf | 3387 | { |
495aee44 | 3388 | ELEMENT x; |
3185942a | 3389 | |
495aee44 CR |
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); | |
a0c0a00f | 3398 | (yyval.command)->flags |= (yyvsp[-1].number); |
495aee44 | 3399 | /* XXX - let's cheat and push a newline back */ |
a0c0a00f | 3400 | if ((yyvsp[0].number) == '\n') |
495aee44 | 3401 | token_to_read = '\n'; |
a0c0a00f CR |
3402 | else if ((yyvsp[0].number) == ';') |
3403 | token_to_read = ';'; | |
d233b485 | 3404 | parser_state &= ~PST_REDIRLIST; /* make_simple_command sets this */ |
3185942a | 3405 | } |
a78e27a1 | 3406 | #line 3407 "y.tab.c" |
3185942a JA |
3407 | break; |
3408 | ||
a78e27a1 CR |
3409 | case 168: /* pipeline_command: BANG list_terminator */ |
3410 | #line 1317 "/usr/local/src/chet/src/bash/src/parse.y" | |
8868edaf | 3411 | { |
b80f6443 JA |
3412 | ELEMENT x; |
3413 | ||
495aee44 CR |
3414 | /* This is just as unclean. Posix says that `!' |
3415 | by itself should be equivalent to `false'. | |
3416 | We cheat and push a | |
b80f6443 JA |
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; | |
3185942a | 3422 | (yyval.command) = make_simple_command (x, (COMMAND *)NULL); |
495aee44 | 3423 | (yyval.command)->flags |= CMD_INVERT_RETURN; |
b80f6443 | 3424 | /* XXX - let's cheat and push a newline back */ |
a0c0a00f | 3425 | if ((yyvsp[0].number) == '\n') |
b80f6443 | 3426 | token_to_read = '\n'; |
a0c0a00f CR |
3427 | if ((yyvsp[0].number) == ';') |
3428 | token_to_read = ';'; | |
d233b485 | 3429 | parser_state &= ~PST_REDIRLIST; /* make_simple_command sets this */ |
3185942a | 3430 | } |
a78e27a1 | 3431 | #line 3432 "y.tab.c" |
3185942a | 3432 | break; |
f73dda09 | 3433 | |
a78e27a1 CR |
3434 | case 169: /* pipeline: pipeline '|' newline_list pipeline */ |
3435 | #line 1340 "/usr/local/src/chet/src/bash/src/parse.y" | |
8868edaf | 3436 | { (yyval.command) = command_connect ((yyvsp[-3].command), (yyvsp[0].command), '|'); } |
a78e27a1 | 3437 | #line 3438 "y.tab.c" |
3185942a JA |
3438 | break; |
3439 | ||
a78e27a1 CR |
3440 | case 170: /* pipeline: pipeline BAR_AND newline_list pipeline */ |
3441 | #line 1342 "/usr/local/src/chet/src/bash/src/parse.y" | |
8868edaf | 3442 | { |
3185942a JA |
3443 | /* Make cmd1 |& cmd2 equivalent to cmd1 2>&1 | cmd2 */ |
3444 | COMMAND *tc; | |
0001803f | 3445 | REDIRECTEE rd, sd; |
3185942a JA |
3446 | REDIRECT *r; |
3447 | ||
a0c0a00f | 3448 | tc = (yyvsp[-3].command)->type == cm_simple ? (COMMAND *)(yyvsp[-3].command)->value.Simple : (yyvsp[-3].command); |
0001803f | 3449 | sd.dest = 2; |
3185942a | 3450 | rd.dest = 1; |
0001803f | 3451 | r = make_redirection (sd, r_duplicating_output, rd, 0); |
3185942a JA |
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 | ||
a0c0a00f | 3462 | (yyval.command) = command_connect ((yyvsp[-3].command), (yyvsp[0].command), '|'); |
3185942a | 3463 | } |
a78e27a1 | 3464 | #line 3465 "y.tab.c" |
3185942a JA |
3465 | break; |
3466 | ||
a78e27a1 CR |
3467 | case 171: /* pipeline: command */ |
3468 | #line 1365 "/usr/local/src/chet/src/bash/src/parse.y" | |
8868edaf | 3469 | { (yyval.command) = (yyvsp[0].command); } |
a78e27a1 | 3470 | #line 3471 "y.tab.c" |
3185942a JA |
3471 | break; |
3472 | ||
a78e27a1 CR |
3473 | case 172: /* timespec: TIME */ |
3474 | #line 1369 "/usr/local/src/chet/src/bash/src/parse.y" | |
8868edaf | 3475 | { (yyval.number) = CMD_TIME_PIPELINE; } |
a78e27a1 | 3476 | #line 3477 "y.tab.c" |
495aee44 CR |
3477 | break; |
3478 | ||
a78e27a1 CR |
3479 | case 173: /* timespec: TIME TIMEOPT */ |
3480 | #line 1371 "/usr/local/src/chet/src/bash/src/parse.y" | |
8868edaf | 3481 | { (yyval.number) = CMD_TIME_PIPELINE|CMD_TIME_POSIX; } |
a78e27a1 | 3482 | #line 3483 "y.tab.c" |
3185942a JA |
3483 | break; |
3484 | ||
a78e27a1 CR |
3485 | case 174: /* timespec: TIME TIMEIGN */ |
3486 | #line 1373 "/usr/local/src/chet/src/bash/src/parse.y" | |
8868edaf | 3487 | { (yyval.number) = CMD_TIME_PIPELINE|CMD_TIME_POSIX; } |
a78e27a1 | 3488 | #line 3489 "y.tab.c" |
8868edaf CR |
3489 | break; |
3490 | ||
a78e27a1 CR |
3491 | case 175: /* timespec: TIME TIMEOPT TIMEIGN */ |
3492 | #line 1375 "/usr/local/src/chet/src/bash/src/parse.y" | |
8868edaf | 3493 | { (yyval.number) = CMD_TIME_PIPELINE|CMD_TIME_POSIX; } |
a78e27a1 | 3494 | #line 3495 "y.tab.c" |
8868edaf CR |
3495 | break; |
3496 | ||
3497 | ||
a78e27a1 | 3498 | #line 3499 "y.tab.c" |
3185942a | 3499 | |
3185942a | 3500 | default: break; |
f73dda09 | 3501 | } |
a0c0a00f CR |
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. */ | |
8868edaf | 3513 | YY_SYMBOL_PRINT ("-> $$ =", YY_CAST (yysymbol_kind_t, yyr1[yyn]), &yyval, &yyloc); |
3185942a JA |
3514 | |
3515 | YYPOPSTACK (yylen); | |
3516 | yylen = 0; | |
f73dda09 JA |
3517 | |
3518 | *++yyvsp = yyval; | |
b80f6443 | 3519 | |
a0c0a00f | 3520 | /* Now 'shift' the result of the reduction. Determine what state |
3185942a JA |
3521 | that goes to, based on the state we popped back to and the rule |
3522 | number reduced by. */ | |
8868edaf CR |
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 | } | |
f73dda09 JA |
3530 | |
3531 | goto yynewstate; | |
3532 | ||
f73dda09 | 3533 | |
a0c0a00f CR |
3534 | /*--------------------------------------. |
3535 | | yyerrlab -- here on detecting error. | | |
3536 | `--------------------------------------*/ | |
3185942a | 3537 | yyerrlab: |
a0c0a00f CR |
3538 | /* Make sure we have latest lookahead translation. See comments at |
3539 | user semantic actions for why this is necessary. */ | |
8868edaf | 3540 | yytoken = yychar == YYEMPTY ? YYSYMBOL_YYEMPTY : YYTRANSLATE (yychar); |
3185942a JA |
3541 | /* If not already recovering from an error, report this error. */ |
3542 | if (!yyerrstatus) | |
f73dda09 JA |
3543 | { |
3544 | ++yynerrs; | |
3185942a | 3545 | yyerror (YY_("syntax error")); |
f73dda09 | 3546 | } |
f73dda09 JA |
3547 | |
3548 | if (yyerrstatus == 3) | |
3549 | { | |
a0c0a00f CR |
3550 | /* If just tried and failed to reuse lookahead token after an |
3551 | error, discard it. */ | |
b80f6443 | 3552 | |
3185942a | 3553 | if (yychar <= YYEOF) |
a0c0a00f CR |
3554 | { |
3555 | /* Return failure if at end of input. */ | |
3556 | if (yychar == YYEOF) | |
3557 | YYABORT; | |
3558 | } | |
3185942a | 3559 | else |
a0c0a00f CR |
3560 | { |
3561 | yydestruct ("Error: discarding", | |
3562 | yytoken, &yylval); | |
3563 | yychar = YYEMPTY; | |
3564 | } | |
f73dda09 JA |
3565 | } |
3566 | ||
a0c0a00f | 3567 | /* Else will try to reuse lookahead token after shifting the error |
3185942a JA |
3568 | token. */ |
3569 | goto yyerrlab1; | |
f73dda09 | 3570 | |
f73dda09 | 3571 | |
3185942a JA |
3572 | /*---------------------------------------------------. |
3573 | | yyerrorlab -- error raised explicitly by YYERROR. | | |
3574 | `---------------------------------------------------*/ | |
3575 | yyerrorlab: | |
8868edaf CR |
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; | |
74091dd4 | 3580 | ++yynerrs; |
f73dda09 | 3581 | |
a0c0a00f | 3582 | /* Do not reclaim the symbols of the rule whose action triggered |
3185942a JA |
3583 | this YYERROR. */ |
3584 | YYPOPSTACK (yylen); | |
3585 | yylen = 0; | |
3586 | YY_STACK_PRINT (yyss, yyssp); | |
3587 | yystate = *yyssp; | |
3588 | goto yyerrlab1; | |
f73dda09 | 3589 | |
f73dda09 | 3590 | |
3185942a JA |
3591 | /*-------------------------------------------------------------. |
3592 | | yyerrlab1 -- common code for both syntax error and YYERROR. | | |
3593 | `-------------------------------------------------------------*/ | |
3594 | yyerrlab1: | |
a0c0a00f | 3595 | yyerrstatus = 3; /* Each real token shifted decrements this. */ |
f73dda09 | 3596 | |
8868edaf | 3597 | /* Pop stack until we find a state that shifts the error token. */ |
3185942a | 3598 | for (;;) |
f73dda09 | 3599 | { |
3185942a | 3600 | yyn = yypact[yystate]; |
a0c0a00f CR |
3601 | if (!yypact_value_is_default (yyn)) |
3602 | { | |
8868edaf CR |
3603 | yyn += YYSYMBOL_YYerror; |
3604 | if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYSYMBOL_YYerror) | |
a0c0a00f CR |
3605 | { |
3606 | yyn = yytable[yyn]; | |
3607 | if (0 < yyn) | |
3608 | break; | |
3609 | } | |
3610 | } | |
b80f6443 | 3611 | |
3185942a JA |
3612 | /* Pop the current state because it cannot handle the error token. */ |
3613 | if (yyssp == yyss) | |
a0c0a00f | 3614 | YYABORT; |
f73dda09 | 3615 | |
f73dda09 | 3616 | |
3185942a | 3617 | yydestruct ("Error: popping", |
8868edaf | 3618 | YY_ACCESSING_SYMBOL (yystate), yyvsp); |
3185942a JA |
3619 | YYPOPSTACK (1); |
3620 | yystate = *yyssp; | |
3621 | YY_STACK_PRINT (yyss, yyssp); | |
f73dda09 | 3622 | } |
f73dda09 | 3623 | |
a0c0a00f | 3624 | YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN |
f73dda09 | 3625 | *++yyvsp = yylval; |
a0c0a00f | 3626 | YY_IGNORE_MAYBE_UNINITIALIZED_END |
3185942a JA |
3627 | |
3628 | ||
3629 | /* Shift the error token. */ | |
8868edaf | 3630 | YY_SYMBOL_PRINT ("Shifting", YY_ACCESSING_SYMBOL (yyn), yyvsp, yylsp); |
f73dda09 JA |
3631 | |
3632 | yystate = yyn; | |
3633 | goto yynewstate; | |
3634 | ||
3185942a JA |
3635 | |
3636 | /*-------------------------------------. | |
3637 | | yyacceptlab -- YYACCEPT comes here. | | |
3638 | `-------------------------------------*/ | |
3639 | yyacceptlab: | |
3640 | yyresult = 0; | |
74091dd4 | 3641 | goto yyreturnlab; |
3185942a | 3642 | |
8868edaf | 3643 | |
3185942a JA |
3644 | /*-----------------------------------. |
3645 | | yyabortlab -- YYABORT comes here. | | |
3646 | `-----------------------------------*/ | |
3647 | yyabortlab: | |
3648 | yyresult = 1; | |
74091dd4 | 3649 | goto yyreturnlab; |
3185942a | 3650 | |
8868edaf | 3651 | |
74091dd4 CR |
3652 | /*-----------------------------------------------------------. |
3653 | | yyexhaustedlab -- YYNOMEM (memory exhaustion) comes here. | | |
3654 | `-----------------------------------------------------------*/ | |
3185942a JA |
3655 | yyexhaustedlab: |
3656 | yyerror (YY_("memory exhausted")); | |
3657 | yyresult = 2; | |
74091dd4 | 3658 | goto yyreturnlab; |
f73dda09 | 3659 | |
8868edaf | 3660 | |
74091dd4 CR |
3661 | /*----------------------------------------------------------. |
3662 | | yyreturnlab -- parsing is finished, clean up and return. | | |
3663 | `----------------------------------------------------------*/ | |
3664 | yyreturnlab: | |
a0c0a00f CR |
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 | |
3185942a JA |
3674 | this YYABORT or YYACCEPT. */ |
3675 | YYPOPSTACK (yylen); | |
3676 | YY_STACK_PRINT (yyss, yyssp); | |
3677 | while (yyssp != yyss) | |
b80f6443 | 3678 | { |
3185942a | 3679 | yydestruct ("Cleanup: popping", |
8868edaf | 3680 | YY_ACCESSING_SYMBOL (+*yyssp), yyvsp); |
3185942a | 3681 | YYPOPSTACK (1); |
b80f6443 | 3682 | } |
3185942a JA |
3683 | #ifndef yyoverflow |
3684 | if (yyss != yyssa) | |
3685 | YYSTACK_FREE (yyss); | |
3686 | #endif | |
8868edaf | 3687 | |
a0c0a00f | 3688 | return yyresult; |
f73dda09 | 3689 | } |
8868edaf | 3690 | |
a78e27a1 | 3691 | #line 1377 "/usr/local/src/chet/src/bash/src/parse.y" |
3185942a | 3692 | |
f73dda09 JA |
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 | ||
b80f6443 JA |
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 | ||
f73dda09 JA |
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; | |
d233b485 CR |
3719 | yyoutstream = stdout; |
3720 | yyerrstream = stderr; | |
f73dda09 JA |
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 | ||
7117c2d2 JA |
3782 | char * |
3783 | yy_input_name () | |
3784 | { | |
3785 | return (bash_input.name ? bash_input.name : "stdin"); | |
3786 | } | |
3787 | ||
f73dda09 JA |
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 | ||
a0c0a00f | 3841 | if (current_readline_line == 0) |
f73dda09 | 3842 | { |
a0c0a00f | 3843 | if (bash_readline_initialized == 0) |
f73dda09 JA |
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 | ||
a0c0a00f | 3851 | old_sigint = IMPOSSIBLE_TRAP_HANDLER; |
f73dda09 JA |
3852 | if (signal_is_ignored (SIGINT) == 0) |
3853 | { | |
495aee44 | 3854 | old_sigint = (SigHandler *)set_signal_handler (SIGINT, sigint_sighandler); |
f73dda09 JA |
3855 | } |
3856 | ||
d233b485 | 3857 | sh_unset_nodelay_mode (fileno (rl_instream)); /* just in case */ |
f73dda09 JA |
3858 | current_readline_line = readline (current_readline_prompt ? |
3859 | current_readline_prompt : ""); | |
3860 | ||
ac50fbac | 3861 | CHECK_TERMSIG; |
495aee44 | 3862 | if (signal_is_ignored (SIGINT) == 0) |
f73dda09 | 3863 | { |
495aee44 CR |
3864 | if (old_sigint != IMPOSSIBLE_TRAP_HANDLER) |
3865 | set_signal_handler (SIGINT, old_sigint); | |
f73dda09 JA |
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 | ||
8868edaf CR |
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 | ||
f73dda09 JA |
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 | ||
3185942a JA |
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. */ | |
74091dd4 | 3987 | void |
3185942a JA |
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 | |
74091dd4 | 3999 | parse_and_execute or xparse_dolparen? xparse_dolparen needs to know how |
3185942a JA |
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 | ||
f73dda09 JA |
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 | |
8868edaf CR |
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. */ | |
f73dda09 JA |
4020 | |
4021 | static int | |
4022 | yy_stream_get () | |
4023 | { | |
4024 | int result; | |
4025 | ||
4026 | result = EOF; | |
4027 | if (bash_input.location.file) | |
95732b49 | 4028 | { |
ac50fbac CR |
4029 | /* XXX - don't need terminate_immediately; getc_with_restart checks |
4030 | for terminating signals itself if read returns < 0 */ | |
95732b49 | 4031 | result = getc_with_restart (bash_input.location.file); |
95732b49 | 4032 | } |
f73dda09 JA |
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 | ||
495aee44 CR |
4066 | /* The line number offset set by assigning to LINENO. Not currently used. */ |
4067 | int line_number_base = 0; | |
4068 | ||
f73dda09 JA |
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 | ||
0001803f | 4167 | ret = (int *)xmalloc (4 * sizeof (int)); |
f73dda09 JA |
4168 | ret[0] = last_read_token; |
4169 | ret[1] = token_before_that; | |
4170 | ret[2] = two_tokens_ago; | |
0001803f | 4171 | ret[3] = current_token; |
f73dda09 JA |
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]; | |
0001803f | 4184 | current_token = ts[3]; |
f73dda09 JA |
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 | ||
f73dda09 JA |
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 | ||
ac50fbac CR |
4207 | #define PSH_ALIAS 0x01 |
4208 | #define PSH_DPAREN 0x02 | |
4209 | #define PSH_SOURCE 0x04 | |
8868edaf | 4210 | #define PSH_ARRAY 0x08 |
ac50fbac | 4211 | |
f73dda09 JA |
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 | |
74091dd4 | 4219 | size_t saved_line_size, saved_line_index, saved_line_len; |
ac50fbac CR |
4220 | int saved_line_terminator; |
4221 | int flags; | |
f73dda09 JA |
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; | |
74091dd4 | 4245 | temp->saved_line_len = shell_input_line_len; |
f73dda09 JA |
4246 | temp->saved_line_index = shell_input_line_index; |
4247 | temp->saved_line_terminator = shell_input_line_terminator; | |
ac50fbac | 4248 | temp->flags = 0; |
f73dda09 JA |
4249 | #if defined (ALIAS) |
4250 | temp->expander = ap; | |
ac50fbac CR |
4251 | if (ap) |
4252 | temp->flags = PSH_ALIAS; | |
f73dda09 JA |
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; | |
74091dd4 | 4263 | shell_input_line_size = shell_input_line_len = STRLEN (s); |
f73dda09 JA |
4264 | shell_input_line_index = 0; |
4265 | shell_input_line_terminator = '\0'; | |
b80f6443 JA |
4266 | #if 0 |
4267 | parser_state &= ~PST_ALEXPNEXT; /* XXX */ | |
4268 | #endif | |
7117c2d2 JA |
4269 | |
4270 | set_line_mbstate (); | |
f73dda09 JA |
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; | |
74091dd4 | 4288 | shell_input_line_len = pushed_string_list->saved_line_len; |
f73dda09 JA |
4289 | shell_input_line_terminator = pushed_string_list->saved_line_terminator; |
4290 | ||
74091dd4 | 4291 | #if defined (ALIAS) |
f73dda09 JA |
4292 | if (pushed_string_list->expand_alias) |
4293 | parser_state |= PST_ALEXPNEXT; | |
4294 | else | |
4295 | parser_state &= ~PST_ALEXPNEXT; | |
74091dd4 | 4296 | #endif |
f73dda09 JA |
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); | |
7117c2d2 JA |
4307 | |
4308 | set_line_mbstate (); | |
f73dda09 JA |
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 | ||
b80f6443 JA |
4330 | void |
4331 | free_pushed_string_input () | |
4332 | { | |
4333 | #if defined (ALIAS) || defined (DPAREN_ARITHMETIC) | |
4334 | free_string_list (); | |
4335 | #endif | |
4336 | } | |
4337 | ||
ac50fbac CR |
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 | ||
d233b485 CR |
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 | ||
a0c0a00f CR |
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 | ||
f73dda09 JA |
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; | |
0001803f | 4400 | int indx, c, peekc, pass_next; |
f73dda09 JA |
4401 | |
4402 | #if defined (READLINE) | |
b80f6443 | 4403 | if (no_line_editing && SHOULD_PROMPT ()) |
f73dda09 | 4404 | #else |
b80f6443 | 4405 | if (SHOULD_PROMPT ()) |
f73dda09 JA |
4406 | #endif |
4407 | print_prompt (); | |
4408 | ||
0001803f | 4409 | pass_next = indx = 0; |
f73dda09 JA |
4410 | while (1) |
4411 | { | |
f73dda09 JA |
4412 | /* Allow immediate exit if interrupted during input. */ |
4413 | QUIT; | |
4414 | ||
95732b49 JA |
4415 | c = yy_getc (); |
4416 | ||
f73dda09 JA |
4417 | /* Ignore null bytes in input. */ |
4418 | if (c == 0) | |
74091dd4 | 4419 | continue; |
f73dda09 JA |
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 | ||
d233b485 CR |
4431 | /* `+2' in case the final character in the buffer is a newline or we |
4432 | have to handle CTLESC or CTLNUL. */ | |
f73dda09 JA |
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 | { | |
495aee44 | 4448 | QUIT; |
f73dda09 JA |
4449 | peekc = yy_getc (); |
4450 | if (peekc == '\n') | |
b80f6443 JA |
4451 | { |
4452 | line_number++; | |
4453 | continue; /* Make the unquoted \<newline> pair disappear. */ | |
4454 | } | |
f73dda09 JA |
4455 | else |
4456 | { | |
4457 | yy_ungetc (peekc); | |
4458 | pass_next = 1; | |
4459 | line_buffer[indx++] = c; /* Preserve the backslash. */ | |
4460 | } | |
4461 | } | |
4462 | else | |
d233b485 CR |
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 | } | |
f73dda09 JA |
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 | { | |
3185942a JA |
4489 | char *ret; |
4490 | int n, c; | |
4491 | ||
f73dda09 | 4492 | prompt_string_pointer = &ps2_prompt; |
74091dd4 CR |
4493 | if (SHOULD_PROMPT ()) |
4494 | prompt_again (0); | |
3185942a JA |
4495 | ret = read_a_line (remove_quoted_newline); |
4496 | #if defined (HISTORY) | |
0001803f | 4497 | if (ret && remember_on_history && (parser_state & PST_HEREDOC)) |
3185942a | 4498 | { |
a0c0a00f CR |
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. | |
3185942a JA |
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; | |
f73dda09 JA |
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 }, | |
28ef6c31 JA |
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 }, | |
726f6388 | 4531 | #endif |
28ef6c31 JA |
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 }, | |
3185942a JA |
4547 | #endif |
4548 | #if defined (COPROCESS_SUPPORT) | |
4549 | { "coproc", COPROC }, | |
726f6388 | 4550 | #endif |
28ef6c31 JA |
4551 | { (char *)NULL, 0} |
4552 | }; | |
726f6388 | 4553 | |
7117c2d2 JA |
4554 | /* other tokens that can be returned by read_token() */ |
4555 | STRING_INT_ALIST other_token_alist[] = { | |
4556 | /* Multiple-character tokens with special values */ | |
495aee44 | 4557 | { "--", TIMEIGN }, |
7117c2d2 JA |
4558 | { "-p", TIMEOPT }, |
4559 | { "&&", AND_AND }, | |
4560 | { "||", OR_OR }, | |
4561 | { ">>", GREATER_GREATER }, | |
4562 | { "<<", LESS_LESS }, | |
4563 | { "<&", LESS_AND }, | |
4564 | { ">&", GREATER_AND }, | |
4565 | { ";;", SEMI_SEMI }, | |
3185942a JA |
4566 | { ";&", SEMI_AND }, |
4567 | { ";;&", SEMI_SEMI_AND }, | |
7117c2d2 JA |
4568 | { "<<-", LESS_LESS_MINUS }, |
4569 | { "<<<", LESS_LESS_LESS }, | |
4570 | { "&>", AND_GREATER }, | |
3185942a | 4571 | { "&>>", AND_GREATER_GREATER }, |
7117c2d2 JA |
4572 | { "<>", LESS_GREATER }, |
4573 | { ">|", GREATER_BAR }, | |
3185942a | 4574 | { "|&", BAR_AND }, |
7117c2d2 JA |
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 | */ | |
726f6388 | 4599 | |
28ef6c31 JA |
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. */ | |
726f6388 | 4602 | |
28ef6c31 JA |
4603 | /* The primary delimiter stack. */ |
4604 | struct dstack dstack = { (char *)NULL, 0, 0 }; | |
726f6388 | 4605 | |
28ef6c31 JA |
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 }; | |
726f6388 | 4610 | |
28ef6c31 JA |
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) | |
726f6388 | 4615 | |
28ef6c31 JA |
4616 | #define push_delimiter(ds, character) \ |
4617 | do \ | |
4618 | { \ | |
4619 | if (ds.delimiter_depth + 2 > ds.delimiter_space) \ | |
f73dda09 | 4620 | ds.delimiters = (char *)xrealloc \ |
28ef6c31 JA |
4621 | (ds.delimiters, (ds.delimiter_space += 10) * sizeof (char)); \ |
4622 | ds.delimiters[ds.delimiter_depth] = character; \ | |
4623 | ds.delimiter_depth++; \ | |
4624 | } \ | |
4625 | while (0) | |
726f6388 | 4626 | |
28ef6c31 | 4627 | #define pop_delimiter(ds) ds.delimiter_depth-- |
726f6388 | 4628 | |
28ef6c31 JA |
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. */ | |
ccc6cda3 | 4633 | |
28ef6c31 JA |
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; | |
726f6388 | 4638 | |
8868edaf CR |
4639 | static int unquoted_backslash = 0; |
4640 | ||
28ef6c31 JA |
4641 | static int |
4642 | shell_getc (remove_quoted_newline) | |
4643 | int remove_quoted_newline; | |
4644 | { | |
4645 | register int i; | |
a0c0a00f | 4646 | int c, truncating, last_was_backslash; |
f73dda09 | 4647 | unsigned char uc; |
726f6388 | 4648 | |
28ef6c31 | 4649 | QUIT; |
726f6388 | 4650 | |
a0c0a00f | 4651 | last_was_backslash = 0; |
95732b49 JA |
4652 | if (sigwinch_received) |
4653 | { | |
4654 | sigwinch_received = 0; | |
4655 | get_new_window_size (0, (int *)0, (int *)0); | |
4656 | } | |
4657 | ||
28ef6c31 JA |
4658 | if (eol_ungetc_lookahead) |
4659 | { | |
4660 | c = eol_ungetc_lookahead; | |
4661 | eol_ungetc_lookahead = 0; | |
4662 | return (c); | |
4663 | } | |
ccc6cda3 | 4664 | |
28ef6c31 JA |
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. */ | |
b72432fd | 4669 | |
28ef6c31 JA |
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++; | |
726f6388 | 4677 | |
ac50fbac CR |
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 | ||
28ef6c31 | 4686 | restart_read: |
726f6388 | 4687 | |
28ef6c31 JA |
4688 | /* Allow immediate exit if interrupted during input. */ |
4689 | QUIT; | |
ccc6cda3 | 4690 | |
ac50fbac | 4691 | i = truncating = 0; |
28ef6c31 | 4692 | shell_input_line_terminator = 0; |
726f6388 | 4693 | |
8868edaf | 4694 | /* If the shell is interactive, but not currently printing a prompt |
b80f6443 JA |
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 | { | |
28ef6c31 JA |
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. */ | |
b80f6443 | 4705 | notify_and_cleanup (); |
28ef6c31 | 4706 | #else /* !JOB_CONTROL */ |
b80f6443 | 4707 | cleanup_dead_jobs (); |
28ef6c31 | 4708 | #endif /* !JOB_CONTROL */ |
b80f6443 | 4709 | } |
ccc6cda3 | 4710 | |
28ef6c31 | 4711 | #if defined (READLINE) |
b80f6443 | 4712 | if (no_line_editing && SHOULD_PROMPT()) |
28ef6c31 | 4713 | #else |
b80f6443 | 4714 | if (SHOULD_PROMPT()) |
28ef6c31 JA |
4715 | #endif |
4716 | print_prompt (); | |
726f6388 | 4717 | |
28ef6c31 JA |
4718 | if (bash_input.type == st_stream) |
4719 | clearerr (stdin); | |
726f6388 | 4720 | |
28ef6c31 JA |
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 | { | |
d233b485 CR |
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 | } | |
28ef6c31 JA |
4740 | continue; |
4741 | } | |
ccc6cda3 | 4742 | |
ac50fbac CR |
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) | |
a0c0a00f | 4755 | internal_warning(_("shell_getc: shell_input_line_size (%zu) exceeds SIZE_MAX (%lu): line truncated"), shell_input_line_size, (unsigned long)SIZE_MAX); |
ac50fbac CR |
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); | |
726f6388 | 4767 | |
28ef6c31 JA |
4768 | if (c == EOF) |
4769 | { | |
4770 | if (bash_input.type == st_stream) | |
4771 | clearerr (stdin); | |
726f6388 | 4772 | |
28ef6c31 JA |
4773 | if (i == 0) |
4774 | shell_input_line_terminator = EOF; | |
726f6388 | 4775 | |
28ef6c31 JA |
4776 | shell_input_line[i] = '\0'; |
4777 | break; | |
4778 | } | |
726f6388 | 4779 | |
ac50fbac CR |
4780 | if (truncating == 0 || c == '\n') |
4781 | shell_input_line[i++] = c; | |
726f6388 | 4782 | |
28ef6c31 JA |
4783 | if (c == '\n') |
4784 | { | |
4785 | shell_input_line[--i] = '\0'; | |
4786 | current_command_line_count++; | |
4787 | break; | |
4788 | } | |
a0c0a00f CR |
4789 | |
4790 | last_was_backslash = last_was_backslash == 0 && c == '\\'; | |
28ef6c31 | 4791 | } |
726f6388 | 4792 | |
28ef6c31 JA |
4793 | shell_input_line_index = 0; |
4794 | shell_input_line_len = i; /* == strlen (shell_input_line) */ | |
ccc6cda3 | 4795 | |
7117c2d2 JA |
4796 | set_line_mbstate (); |
4797 | ||
28ef6c31 JA |
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) | |
28ef6c31 JA |
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. */ | |
28ef6c31 | 4806 | if (current_delimiter (dstack) == '\'') |
d233b485 CR |
4807 | history_quoting_state = '\''; |
4808 | else if (current_delimiter (dstack) == '"') | |
4809 | history_quoting_state = '"'; | |
4810 | else | |
4811 | history_quoting_state = 0; | |
28ef6c31 | 4812 | # endif |
a0c0a00f CR |
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 */ | |
28ef6c31 JA |
4815 | expansions = pre_process_line (shell_input_line, 1, 1); |
4816 | # if defined (BANG_HISTORY) | |
d233b485 | 4817 | history_quoting_state = 0; |
28ef6c31 JA |
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; | |
495aee44 | 4825 | if (shell_input_line_len == 0) |
28ef6c31 | 4826 | current_command_line_count--; |
726f6388 | 4827 | |
28ef6c31 JA |
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; | |
7117c2d2 JA |
4831 | |
4832 | set_line_mbstate (); | |
28ef6c31 JA |
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) | |
726f6388 | 4840 | { |
28ef6c31 JA |
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; | |
495aee44 | 4850 | hdcs = history_delimiting_chars (shell_input_line); |
28ef6c31 JA |
4851 | if (hdcs && hdcs[0] == ';') |
4852 | maybe_add_history (shell_input_line); | |
4853 | } | |
726f6388 JA |
4854 | } |
4855 | ||
28ef6c31 | 4856 | #endif /* HISTORY */ |
726f6388 | 4857 | |
28ef6c31 | 4858 | if (shell_input_line) |
726f6388 | 4859 | { |
28ef6c31 | 4860 | /* Lines that signify the end of the shell's input should not be |
ac50fbac CR |
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. */ | |
28ef6c31 | 4866 | if (echo_input_at_read && (shell_input_line[0] || |
ac50fbac CR |
4867 | shell_input_line_terminator != EOF) && |
4868 | shell_eof_token == 0) | |
28ef6c31 JA |
4869 | fprintf (stderr, "%s\n", shell_input_line); |
4870 | } | |
4871 | else | |
4872 | { | |
4873 | shell_input_line_size = 0; | |
4874 | prompt_string_pointer = ¤t_prompt_string; | |
b80f6443 | 4875 | if (SHOULD_PROMPT ()) |
74091dd4 | 4876 | prompt_again (0); |
28ef6c31 | 4877 | goto restart_read; |
726f6388 JA |
4878 | } |
4879 | ||
28ef6c31 JA |
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 | { | |
6ebbb24a | 4884 | if (shell_input_line_size < SIZE_MAX-3 && (shell_input_line_len+3 > shell_input_line_size)) |
f73dda09 | 4885 | shell_input_line = (char *)xrealloc (shell_input_line, |
28ef6c31 | 4886 | 1 + (shell_input_line_size += 2)); |
726f6388 | 4887 | |
a0c0a00f CR |
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'; | |
28ef6c31 | 4896 | shell_input_line[shell_input_line_len + 1] = '\0'; |
7117c2d2 | 4897 | |
74091dd4 | 4898 | #if defined (HANDLE_MULTIBYTE) |
8868edaf CR |
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(). */ | |
74091dd4 | 4902 | EXTEND_SHELL_INPUT_LINE_PROPERTY(); |
8868edaf | 4903 | shell_input_line_property[shell_input_line_len] = 1; |
8868edaf | 4904 | #endif |
28ef6c31 JA |
4905 | } |
4906 | } | |
726f6388 | 4907 | |
495aee44 | 4908 | next_alias_char: |
8868edaf CR |
4909 | if (shell_input_line_index == 0) |
4910 | unquoted_backslash = 0; | |
4911 | ||
f73dda09 | 4912 | uc = shell_input_line[shell_input_line_index]; |
ccc6cda3 | 4913 | |
f73dda09 | 4914 | if (uc) |
8868edaf CR |
4915 | { |
4916 | unquoted_backslash = unquoted_backslash == 0 && uc == '\\'; | |
4917 | shell_input_line_index++; | |
4918 | } | |
726f6388 | 4919 | |
28ef6c31 | 4920 | #if defined (ALIAS) || defined (DPAREN_ARITHMETIC) |
f73dda09 | 4921 | /* If UC is NULL, we have reached the end of the current input string. If |
28ef6c31 JA |
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. */ | |
ac50fbac CR |
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. */ | |
d233b485 CR |
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 && | |
ddf3f643 | 4947 | (parser_state & PST_ENDALIAS) == 0 && /* only once */ |
d233b485 | 4948 | shell_input_line_index > 0 && |
ddf3f643 | 4949 | shellblank (shell_input_line[shell_input_line_index-1]) == 0 && |
d233b485 | 4950 | shell_input_line[shell_input_line_index-1] != '\n' && |
8868edaf | 4951 | unquoted_backslash == 0 && |
d233b485 CR |
4952 | shellmeta (shell_input_line[shell_input_line_index-1]) == 0 && |
4953 | (current_delimiter (dstack) != '\'' && current_delimiter (dstack) != '"')) | |
4954 | { | |
ddf3f643 | 4955 | parser_state |= PST_ENDALIAS; |
74091dd4 CR |
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 | } | |
d233b485 CR |
4971 | return ' '; /* END_ALIAS */ |
4972 | } | |
4973 | #endif | |
4974 | ||
0001803f | 4975 | pop_alias: |
74091dd4 CR |
4976 | #endif /* ALIAS || DPAREN_ARITHMETIC */ |
4977 | /* This case works for PSH_DPAREN as well as the shell_ungets() case that uses | |
4978 | push_string */ | |
ac50fbac | 4979 | if (uc == 0 && pushed_string_list && pushed_string_list->flags != PSH_SOURCE) |
726f6388 | 4980 | { |
ddf3f643 | 4981 | parser_state &= ~PST_ENDALIAS; |
b80f6443 JA |
4982 | pop_string (); |
4983 | uc = shell_input_line[shell_input_line_index]; | |
4984 | if (uc) | |
4985 | shell_input_line_index++; | |
726f6388 | 4986 | } |
28ef6c31 | 4987 | |
95732b49 JA |
4988 | if MBTEST(uc == '\\' && remove_quoted_newline && shell_input_line[shell_input_line_index] == '\n') |
4989 | { | |
4990 | if (SHOULD_PROMPT ()) | |
74091dd4 | 4991 | prompt_again (0); |
95732b49 | 4992 | line_number++; |
8868edaf | 4993 | |
495aee44 CR |
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 | |
d233b485 CR |
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. */ | |
509a4430 | 5000 | #if defined (ALIAS) |
0001803f CR |
5001 | if (expanding_alias () && shell_input_line[shell_input_line_index+1] == '\0') |
5002 | { | |
5003 | uc = 0; | |
5004 | goto pop_alias; | |
5005 | } | |
495aee44 CR |
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 | } | |
509a4430 CR |
5011 | else |
5012 | #endif | |
495aee44 | 5013 | goto restart_read; |
95732b49 JA |
5014 | } |
5015 | ||
495aee44 | 5016 | if (uc == 0 && shell_input_line_terminator == EOF) |
28ef6c31 JA |
5017 | return ((shell_input_line_index != 0) ? '\n' : EOF); |
5018 | ||
ac50fbac CR |
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 | ||
f73dda09 | 5041 | return (uc); |
726f6388 JA |
5042 | } |
5043 | ||
7117c2d2 JA |
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. */ | |
28ef6c31 JA |
5049 | static void |
5050 | shell_ungetc (c) | |
ccc6cda3 | 5051 | int c; |
726f6388 | 5052 | { |
28ef6c31 JA |
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; | |
726f6388 JA |
5057 | } |
5058 | ||
74091dd4 CR |
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 | ||
ca6a2ba4 CR |
5113 | char * |
5114 | parser_remaining_input () | |
5115 | { | |
5116 | if (shell_input_line == 0) | |
5117 | return 0; | |
d233b485 | 5118 | if ((int)shell_input_line_index < 0 || shell_input_line_index >= shell_input_line_len) |
a0c0a00f | 5119 | return ""; /* XXX */ |
ca6a2ba4 CR |
5120 | return (shell_input_line + shell_input_line_index); |
5121 | } | |
5122 | ||
f73dda09 JA |
5123 | #ifdef INCLUDE_UNUSED |
5124 | /* Back the input pointer up by one, effectively `ungetting' a character. */ | |
28ef6c31 JA |
5125 | static void |
5126 | shell_ungetchar () | |
726f6388 | 5127 | { |
28ef6c31 JA |
5128 | if (shell_input_line && shell_input_line_index) |
5129 | shell_input_line_index--; | |
726f6388 | 5130 | } |
f73dda09 | 5131 | #endif |
726f6388 | 5132 | |
28ef6c31 JA |
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; | |
726f6388 | 5138 | { |
28ef6c31 | 5139 | int c; |
726f6388 | 5140 | |
28ef6c31 JA |
5141 | while ((c = shell_getc (0)) != EOF && c != character) |
5142 | ; | |
726f6388 | 5143 | |
28ef6c31 JA |
5144 | if (c != EOF) |
5145 | shell_ungetc (c); | |
5146 | } | |
726f6388 | 5147 | |
28ef6c31 | 5148 | void |
0628567a JA |
5149 | execute_variable_command (command, vname) |
5150 | char *command, *vname; | |
28ef6c31 | 5151 | { |
28ef6c31 | 5152 | char *last_lastarg; |
b80f6443 | 5153 | sh_parser_state_t ps; |
726f6388 | 5154 | |
b80f6443 | 5155 | save_parser_state (&ps); |
28ef6c31 JA |
5156 | last_lastarg = get_string_value ("_"); |
5157 | if (last_lastarg) | |
5158 | last_lastarg = savestring (last_lastarg); | |
726f6388 | 5159 | |
ec8113b9 | 5160 | parse_and_execute (savestring (command), vname, SEVAL_NONINT|SEVAL_NOHIST|SEVAL_NOOPTIMIZE); |
726f6388 | 5161 | |
b80f6443 | 5162 | restore_parser_state (&ps); |
95732b49 | 5163 | bind_variable ("_", last_lastarg, 0); |
28ef6c31 JA |
5164 | FREE (last_lastarg); |
5165 | ||
5166 | if (token_to_read == '\n') /* reset_parser was called */ | |
5167 | token_to_read = 0; | |
726f6388 JA |
5168 | } |
5169 | ||
a0c0a00f CR |
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 | ||
28ef6c31 JA |
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; | |
726f6388 | 5184 | |
28ef6c31 | 5185 | /* Current size of the token buffer. */ |
74091dd4 | 5186 | static size_t token_buffer_size; |
28ef6c31 JA |
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) | |
bb70624e | 5193 | |
28ef6c31 JA |
5194 | /* Function for yyparse to call. yylex keeps track of |
5195 | the last two tokens read, and calls read_token. */ | |
726f6388 | 5196 | static int |
28ef6c31 | 5197 | yylex () |
726f6388 | 5198 | { |
28ef6c31 JA |
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. */ | |
509a4430 | 5205 | if (prompt_is_ps1 && parse_and_execute_level == 0 && time_to_check_mail ()) |
28ef6c31 JA |
5206 | { |
5207 | check_mail (); | |
5208 | reset_mail_timer (); | |
5209 | } | |
726f6388 | 5210 | |
28ef6c31 JA |
5211 | /* Avoid printing a prompt if we're not going to read anything, e.g. |
5212 | after resetting the parser with read_token (RESET). */ | |
b80f6443 | 5213 | if (token_to_read == 0 && SHOULD_PROMPT ()) |
74091dd4 | 5214 | prompt_again (0); |
28ef6c31 | 5215 | } |
bb70624e | 5216 | |
28ef6c31 JA |
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); | |
3185942a JA |
5221 | |
5222 | if ((parser_state & PST_EOFTOKEN) && current_token == shell_eof_token) | |
5223 | { | |
74091dd4 CR |
5224 | /* placeholder for any special handling. */ |
5225 | return (current_token); | |
3185942a | 5226 | } |
74091dd4 CR |
5227 | |
5228 | if (current_token < 0) | |
5229 | #if defined (YYERRCODE) && !defined (YYUNDEF) | |
a78e27a1 | 5230 | current_token = EOF_Reached ? YYEOF : YYERRCODE; |
74091dd4 | 5231 | #else |
a78e27a1 | 5232 | current_token = EOF_Reached ? YYEOF : YYUNDEF; |
74091dd4 | 5233 | #endif |
3185942a | 5234 | |
28ef6c31 | 5235 | return (current_token); |
726f6388 JA |
5236 | } |
5237 | ||
28ef6c31 JA |
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; | |
726f6388 | 5241 | |
d233b485 CR |
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 | ||
90a39f32 CR |
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 | ||
726f6388 | 5261 | void |
28ef6c31 | 5262 | gather_here_documents () |
726f6388 | 5263 | { |
3185942a JA |
5264 | int r; |
5265 | ||
5266 | r = 0; | |
a0c0a00f | 5267 | here_doc_first_line = 1; |
daefb2c5 | 5268 | while (need_here_doc > 0) |
28ef6c31 | 5269 | { |
3185942a JA |
5270 | parser_state |= PST_HEREDOC; |
5271 | make_here_document (redir_stack[r++], line_number); | |
5272 | parser_state &= ~PST_HEREDOC; | |
28ef6c31 | 5273 | need_here_doc--; |
a0c0a00f | 5274 | redir_stack[r - 1] = 0; /* XXX */ |
28ef6c31 | 5275 | } |
a0c0a00f | 5276 | here_doc_first_line = 0; /* just in case */ |
726f6388 JA |
5277 | } |
5278 | ||
28ef6c31 JA |
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; | |
726f6388 | 5282 | |
a0c0a00f CR |
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. */ | |
28ef6c31 | 5298 | #define command_token_position(token) \ |
a0c0a00f CR |
5299 | (((token) == ASSIGNMENT_WORD) || \ |
5300 | ((parser_state&PST_REDIRLIST) && parsing_redirection(token) == 0) || \ | |
3185942a | 5301 | ((token) != SEMI_SEMI && (token) != SEMI_AND && (token) != SEMI_SEMI_AND && reserved_word_acceptable(token))) |
cce855bc | 5302 | |
a0c0a00f | 5303 | /* Are we in a position where we can read an assignment statement? */ |
b80f6443 JA |
5304 | #define assignment_acceptable(token) \ |
5305 | (command_token_position(token) && ((parser_state & PST_CASEPAT) == 0)) | |
726f6388 | 5306 | |
28ef6c31 JA |
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; \ | |
b80f6443 | 5320 | if (word_token_alist[i].token == TIME && time_command_acceptable () == 0) \ |
28ef6c31 | 5321 | break; \ |
a0c0a00f CR |
5322 | if ((parser_state & PST_CASEPAT) && last_read_token == '|' && word_token_alist[i].token == ESAC) \ |
5323 | break; /* Posix grammar rule 4 */ \ | |
74091dd4 CR |
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) { \ | |
28ef6c31 | 5327 | parser_state &= ~(PST_CASEPAT|PST_CASESTMT); \ |
74091dd4 CR |
5328 | esacs_needed_count--; \ |
5329 | } else if (word_token_alist[i].token == CASE) \ | |
28ef6c31 JA |
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) | |
726f6388 | 5343 | |
28ef6c31 | 5344 | #if defined (ALIAS) |
726f6388 | 5345 | |
28ef6c31 JA |
5346 | /* OK, we have a token. Let's try to alias expand it, if (and only if) |
5347 | it's eligible. | |
726f6388 | 5348 | |
7117c2d2 | 5349 | It is eligible for expansion if EXPAND_ALIASES is set, and |
28ef6c31 JA |
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. | |
726f6388 | 5355 | |
28ef6c31 JA |
5356 | Special cases that disqualify: |
5357 | In a pattern list in a case statement (parser_state & PST_CASEPAT). */ | |
b80f6443 JA |
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); | |
d233b485 | 5369 | #ifdef OLD_ALIAS_HACK |
495aee44 CR |
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. */ | |
d233b485 CR |
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) | |
b80f6443 | 5376 | r[l++] = ' '; |
d233b485 | 5377 | #endif |
b80f6443 JA |
5378 | r[l] = '\0'; |
5379 | return r; | |
5380 | } | |
5381 | ||
28ef6c31 | 5382 | static int |
f73dda09 JA |
5383 | alias_expand_token (tokstr) |
5384 | char *tokstr; | |
726f6388 | 5385 | { |
28ef6c31 JA |
5386 | char *expanded; |
5387 | alias_t *ap; | |
5388 | ||
74091dd4 | 5389 | #if 0 |
28ef6c31 JA |
5390 | if (((parser_state & PST_ALEXPNEXT) || command_token_position (last_read_token)) && |
5391 | (parser_state & PST_CASEPAT) == 0) | |
74091dd4 CR |
5392 | #else |
5393 | if ((parser_state & PST_ALEXPNEXT) || assignment_acceptable (last_read_token)) | |
5394 | #endif | |
726f6388 | 5395 | { |
f73dda09 | 5396 | ap = find_alias (tokstr); |
726f6388 | 5397 | |
28ef6c31 JA |
5398 | /* Currently expanding this token. */ |
5399 | if (ap && (ap->flags & AL_BEINGEXPANDED)) | |
5400 | return (NO_EXPANSION); | |
726f6388 | 5401 | |
d233b485 | 5402 | #ifdef OLD_ALIAS_HACK |
b80f6443 | 5403 | /* mk_alexpansion puts an extra space on the end of the alias expansion, |
d233b485 CR |
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 | |
b80f6443 JA |
5410 | expanded = ap ? mk_alexpansion (ap->value) : (char *)NULL; |
5411 | ||
28ef6c31 JA |
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 */ | |
726f6388 | 5424 | |
28ef6c31 JA |
5425 | static int |
5426 | time_command_acceptable () | |
726f6388 | 5427 | { |
28ef6c31 | 5428 | #if defined (COMMAND_TIMING) |
495aee44 CR |
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 | ||
28ef6c31 JA |
5443 | switch (last_read_token) |
5444 | { | |
5445 | case 0: | |
5446 | case ';': | |
5447 | case '\n': | |
a0c0a00f CR |
5448 | if (token_before_that == '|') |
5449 | return (0); | |
5450 | /* FALLTHROUGH */ | |
28ef6c31 JA |
5451 | case AND_AND: |
5452 | case OR_OR: | |
5453 | case '&': | |
af61c549 | 5454 | case WHILE: |
28ef6c31 | 5455 | case DO: |
af61c549 CR |
5456 | case UNTIL: |
5457 | case IF: | |
28ef6c31 | 5458 | case THEN: |
af61c549 | 5459 | case ELIF: |
28ef6c31 JA |
5460 | case ELSE: |
5461 | case '{': /* } */ | |
af61c549 CR |
5462 | case '(': /* )( */ |
5463 | case ')': /* only valid in case statement */ | |
495aee44 CR |
5464 | case BANG: /* ! time pipeline */ |
5465 | case TIME: /* time time pipeline */ | |
5466 | case TIMEOPT: /* time -p time pipeline */ | |
5467 | case TIMEIGN: /* time -p -- ... */ | |
b8a52e05 | 5468 | case DOLPAREN: |
726f6388 | 5469 | return 1; |
28ef6c31 JA |
5470 | default: |
5471 | return 0; | |
5472 | } | |
5473 | #else | |
726f6388 | 5474 | return 0; |
28ef6c31 | 5475 | #endif /* COMMAND_TIMING */ |
726f6388 JA |
5476 | } |
5477 | ||
28ef6c31 JA |
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. | |
726f6388 | 5481 | |
28ef6c31 JA |
5482 | DO is recognized if the last token was WORD and the token |
5483 | before that was FOR or SELECT. | |
cce855bc | 5484 | |
28ef6c31 JA |
5485 | ESAC is recognized if the last token caused `esacs_needed_count' |
5486 | to be set | |
ccc6cda3 | 5487 | |
28ef6c31 JA |
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. | |
ccc6cda3 | 5491 | |
28ef6c31 | 5492 | `}' is recognized if there is an unclosed `{' present. |
726f6388 | 5493 | |
28ef6c31 | 5494 | `-p' is returned as TIMEOPT if the last read token was TIME. |
8868edaf | 5495 | `--' is returned as TIMEIGN if the last read token was TIME or TIMEOPT. |
726f6388 | 5496 | |
28ef6c31 JA |
5497 | ']]' is returned as COND_END if the parser is currently parsing |
5498 | a conditional expression ((parser_state & PST_CONDEXPR) != 0) | |
726f6388 | 5499 | |
28ef6c31 JA |
5500 | `time' is returned as TIME if and only if it is immediately |
5501 | preceded by one of `;', `\n', `||', `&&', or `&'. | |
5502 | */ | |
726f6388 | 5503 | |
28ef6c31 | 5504 | static int |
f73dda09 JA |
5505 | special_case_tokens (tokstr) |
5506 | char *tokstr; | |
726f6388 | 5507 | { |
d233b485 | 5508 | /* Posix grammar rule 6 */ |
28ef6c31 JA |
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)) && | |
cce855bc | 5514 | #endif |
f73dda09 | 5515 | (tokstr[0] == 'i' && tokstr[1] == 'n' && tokstr[2] == 0)) |
28ef6c31 JA |
5516 | { |
5517 | if (token_before_that == CASE) | |
5518 | { | |
5519 | parser_state |= PST_CASEPAT; | |
5520 | esacs_needed_count++; | |
5521 | } | |
d233b485 CR |
5522 | if (expecting_in_token) |
5523 | expecting_in_token--; | |
28ef6c31 JA |
5524 | return (IN); |
5525 | } | |
726f6388 | 5526 | |
d233b485 CR |
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 */ | |
28ef6c31 JA |
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) && | |
cce855bc | 5555 | #endif |
f73dda09 | 5556 | (tokstr[0] == 'd' && tokstr[1] == 'o' && tokstr[2] == '\0')) |
d233b485 CR |
5557 | { |
5558 | if (expecting_in_token) | |
5559 | expecting_in_token--; | |
5560 | return (DO); | |
5561 | } | |
726f6388 | 5562 | |
28ef6c31 JA |
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 | { | |
d233b485 | 5571 | if (last_read_token == IN && STREQ (tokstr, "esac")) |
28ef6c31 | 5572 | { |
d233b485 | 5573 | esacs_needed_count--; |
28ef6c31 JA |
5574 | parser_state &= ~PST_CASEPAT; |
5575 | return (ESAC); | |
5576 | } | |
5577 | } | |
726f6388 | 5578 | |
28ef6c31 JA |
5579 | /* The start of a shell function definition. */ |
5580 | if (parser_state & PST_ALLOWOPNBRC) | |
5581 | { | |
5582 | parser_state &= ~PST_ALLOWOPNBRC; | |
f73dda09 | 5583 | if (tokstr[0] == '{' && tokstr[1] == '\0') /* } */ |
28ef6c31 JA |
5584 | { |
5585 | open_brace_count++; | |
5586 | function_bstart = line_number; | |
5587 | return ('{'); /* } */ | |
5588 | } | |
5589 | } | |
726f6388 | 5590 | |
28ef6c31 JA |
5591 | /* We allow a `do' after a for ((...)) without an intervening |
5592 | list_terminator */ | |
f73dda09 | 5593 | if (last_read_token == ARITH_FOR_EXPRS && tokstr[0] == 'd' && tokstr[1] == 'o' && !tokstr[2]) |
28ef6c31 | 5594 | return (DO); |
f73dda09 | 5595 | if (last_read_token == ARITH_FOR_EXPRS && tokstr[0] == '{' && tokstr[1] == '\0') /* } */ |
28ef6c31 JA |
5596 | { |
5597 | open_brace_count++; | |
5598 | return ('{'); /* } */ | |
5599 | } | |
726f6388 | 5600 | |
f73dda09 | 5601 | if (open_brace_count && reserved_word_acceptable (last_read_token) && tokstr[0] == '}' && !tokstr[1]) |
28ef6c31 JA |
5602 | { |
5603 | open_brace_count--; /* { */ | |
5604 | return ('}'); | |
5605 | } | |
ccc6cda3 | 5606 | |
28ef6c31 JA |
5607 | #if defined (COMMAND_TIMING) |
5608 | /* Handle -p after `time'. */ | |
f73dda09 | 5609 | if (last_read_token == TIME && tokstr[0] == '-' && tokstr[1] == 'p' && !tokstr[2]) |
28ef6c31 | 5610 | return (TIMEOPT); |
8868edaf CR |
5611 | /* Handle -- after `time'. */ |
5612 | if (last_read_token == TIME && tokstr[0] == '-' && tokstr[1] == '-' && !tokstr[2]) | |
5613 | return (TIMEIGN); | |
495aee44 CR |
5614 | /* Handle -- after `time -p'. */ |
5615 | if (last_read_token == TIMEOPT && tokstr[0] == '-' && tokstr[1] == '-' && !tokstr[2]) | |
5616 | return (TIMEIGN); | |
b80f6443 | 5617 | #endif |
28ef6c31 JA |
5618 | |
5619 | #if defined (COND_COMMAND) /* [[ */ | |
f73dda09 | 5620 | if ((parser_state & PST_CONDEXPR) && tokstr[0] == ']' && tokstr[1] == ']' && tokstr[2] == '\0') |
28ef6c31 | 5621 | return (COND_END); |
cce855bc | 5622 | #endif |
ccc6cda3 | 5623 | |
28ef6c31 | 5624 | return (-1); |
726f6388 JA |
5625 | } |
5626 | ||
28ef6c31 JA |
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 () | |
726f6388 | 5631 | { |
28ef6c31 JA |
5632 | dstack.delimiter_depth = 0; /* No delimiters found so far. */ |
5633 | open_brace_count = 0; | |
726f6388 | 5634 | |
0001803f CR |
5635 | #if defined (EXTENDED_GLOB) |
5636 | /* Reset to global value of extended glob */ | |
74091dd4 | 5637 | if (parser_state & (PST_EXTPAT|PST_CMDSUBST)) |
c7bb74de | 5638 | extended_glob = extglob_flag; |
0001803f | 5639 | #endif |
8c9524f9 CR |
5640 | if (parser_state & (PST_CMDSUBST|PST_STRING)) |
5641 | expand_aliases = expaliases_flag; | |
0001803f | 5642 | |
28ef6c31 | 5643 | parser_state = 0; |
a0c0a00f | 5644 | here_doc_first_line = 0; |
726f6388 | 5645 | |
28ef6c31 JA |
5646 | #if defined (ALIAS) || defined (DPAREN_ARITHMETIC) |
5647 | if (pushed_string_list) | |
5648 | free_string_list (); | |
cce855bc | 5649 | #endif /* ALIAS || DPAREN_ARITHMETIC */ |
ccc6cda3 | 5650 | |
a0c0a00f | 5651 | /* This is where we resynchronize to the next newline on error/reset */ |
28ef6c31 | 5652 | if (shell_input_line) |
726f6388 | 5653 | { |
28ef6c31 JA |
5654 | free (shell_input_line); |
5655 | shell_input_line = (char *)NULL; | |
5656 | shell_input_line_size = shell_input_line_index = 0; | |
5657 | } | |
726f6388 | 5658 | |
28ef6c31 JA |
5659 | FREE (word_desc_to_read); |
5660 | word_desc_to_read = (WORD_DESC *)NULL; | |
726f6388 | 5661 | |
836a17be CR |
5662 | eol_ungetc_lookahead = 0; |
5663 | ||
74091dd4 CR |
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 | ||
0001803f | 5669 | current_token = '\n'; /* XXX */ |
28ef6c31 JA |
5670 | last_read_token = '\n'; |
5671 | token_to_read = '\n'; | |
5672 | } | |
726f6388 | 5673 | |
d233b485 CR |
5674 | void |
5675 | reset_readahead_token () | |
5676 | { | |
5677 | if (token_to_read == '\n') | |
5678 | token_to_read = 0; | |
5679 | } | |
5680 | ||
28ef6c31 JA |
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. */ | |
726f6388 | 5690 | |
28ef6c31 JA |
5691 | if (command == RESET) |
5692 | { | |
5693 | reset_parser (); | |
5694 | return ('\n'); | |
5695 | } | |
726f6388 | 5696 | |
28ef6c31 JA |
5697 | if (token_to_read) |
5698 | { | |
5699 | result = token_to_read; | |
5700 | if (token_to_read == WORD || token_to_read == ASSIGNMENT_WORD) | |
726f6388 | 5701 | { |
28ef6c31 JA |
5702 | yylval.word = word_desc_to_read; |
5703 | word_desc_to_read = (WORD_DESC *)NULL; | |
726f6388 | 5704 | } |
28ef6c31 JA |
5705 | token_to_read = 0; |
5706 | return (result); | |
5707 | } | |
726f6388 | 5708 | |
28ef6c31 JA |
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) | |
726f6388 | 5716 | { |
7117c2d2 | 5717 | cond_error (); |
28ef6c31 | 5718 | return (-1); |
726f6388 | 5719 | } |
28ef6c31 JA |
5720 | token_to_read = COND_END; |
5721 | parser_state &= ~(PST_CONDEXPR|PST_CONDCMD); | |
5722 | return (COND_CMD); | |
726f6388 | 5723 | } |
cce855bc | 5724 | #endif |
726f6388 | 5725 | |
28ef6c31 JA |
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 */ | |
ccc6cda3 | 5731 | |
28ef6c31 | 5732 | /* Read a single word from input. Start by skipping blanks. */ |
0628567a | 5733 | while ((character = shell_getc (1)) != EOF && shellblank (character)) |
28ef6c31 | 5734 | ; |
ccc6cda3 | 5735 | |
28ef6c31 JA |
5736 | if (character == EOF) |
5737 | { | |
5738 | EOF_Reached = 1; | |
5739 | return (yacc_EOF); | |
5740 | } | |
ccc6cda3 | 5741 | |
d233b485 CR |
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 | { | |
74091dd4 | 5746 | INTERNAL_DEBUG (("shell_getc: bash_input.location.string = `%s'", bash_input.location.string)); |
d233b485 CR |
5747 | EOF_Reached = 1; |
5748 | return (yacc_EOF); | |
5749 | } | |
5750 | ||
7117c2d2 | 5751 | if MBTEST(character == '#' && (!interactive || interactive_comments)) |
28ef6c31 JA |
5752 | { |
5753 | /* A comment. Discard until EOL or EOF, and then return a newline. */ | |
d233b485 | 5754 | parser_state |= PST_COMMENT; |
28ef6c31 JA |
5755 | discard_until ('\n'); |
5756 | shell_getc (0); | |
d233b485 | 5757 | parser_state &= ~PST_COMMENT; |
28ef6c31 JA |
5758 | character = '\n'; /* this will take the next if statement and return. */ |
5759 | } | |
ccc6cda3 | 5760 | |
74091dd4 | 5761 | if MBTEST(character == '\n') |
28ef6c31 JA |
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 (); | |
ccc6cda3 | 5767 | |
28ef6c31 JA |
5768 | #if defined (ALIAS) |
5769 | parser_state &= ~PST_ALEXPNEXT; | |
5770 | #endif /* ALIAS */ | |
ccc6cda3 | 5771 | |
95732b49 JA |
5772 | parser_state &= ~PST_ASSIGNOK; |
5773 | ||
28ef6c31 JA |
5774 | return (character); |
5775 | } | |
726f6388 | 5776 | |
3185942a JA |
5777 | if (parser_state & PST_REGEXP) |
5778 | goto tokword; | |
5779 | ||
28ef6c31 | 5780 | /* Shell meta-characters. */ |
74091dd4 | 5781 | if MBTEST(shellmeta (character)) |
28ef6c31 JA |
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 */ | |
726f6388 | 5789 | |
95732b49 JA |
5790 | parser_state &= ~PST_ASSIGNOK; |
5791 | ||
a0c0a00f CR |
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 | ||
74091dd4 | 5802 | if MBTEST(character == peek_char) |
28ef6c31 JA |
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); | |
3185942a | 5810 | if MBTEST(peek_char == '-') |
28ef6c31 | 5811 | return (LESS_LESS_MINUS); |
3185942a | 5812 | else if MBTEST(peek_char == '<') |
7117c2d2 | 5813 | return (LESS_LESS_LESS); |
28ef6c31 JA |
5814 | else |
5815 | { | |
5816 | shell_ungetc (peek_char); | |
5817 | return (LESS_LESS); | |
5818 | } | |
726f6388 | 5819 | |
28ef6c31 JA |
5820 | case '>': |
5821 | return (GREATER_GREATER); | |
726f6388 | 5822 | |
28ef6c31 JA |
5823 | case ';': |
5824 | parser_state |= PST_CASEPAT; | |
5825 | #if defined (ALIAS) | |
5826 | parser_state &= ~PST_ALEXPNEXT; | |
5827 | #endif /* ALIAS */ | |
95732b49 | 5828 | |
3185942a JA |
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 | } | |
726f6388 | 5837 | |
28ef6c31 JA |
5838 | case '&': |
5839 | return (AND_AND); | |
726f6388 | 5840 | |
28ef6c31 JA |
5841 | case '|': |
5842 | return (OR_OR); | |
726f6388 | 5843 | |
28ef6c31 JA |
5844 | #if defined (DPAREN_ARITHMETIC) || defined (ARITH_FOR_COMMAND) |
5845 | case '(': /* ) */ | |
7117c2d2 JA |
5846 | result = parse_dparen (character); |
5847 | if (result == -2) | |
5848 | break; | |
5849 | else | |
5850 | return result; | |
726f6388 | 5851 | #endif |
28ef6c31 JA |
5852 | } |
5853 | } | |
7117c2d2 | 5854 | else if MBTEST(character == '<' && peek_char == '&') |
28ef6c31 | 5855 | return (LESS_AND); |
7117c2d2 | 5856 | else if MBTEST(character == '>' && peek_char == '&') |
28ef6c31 | 5857 | return (GREATER_AND); |
7117c2d2 | 5858 | else if MBTEST(character == '<' && peek_char == '>') |
28ef6c31 | 5859 | return (LESS_GREATER); |
7117c2d2 | 5860 | else if MBTEST(character == '>' && peek_char == '|') |
28ef6c31 | 5861 | return (GREATER_BAR); |
3185942a JA |
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 | } | |
726f6388 | 5883 | |
28ef6c31 | 5884 | shell_ungetc (peek_char); |
726f6388 | 5885 | |
28ef6c31 JA |
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 `{'. */ | |
7117c2d2 | 5889 | if MBTEST(character == ')' && last_read_token == '(' && token_before_that == WORD) |
726f6388 | 5890 | { |
28ef6c31 JA |
5891 | parser_state |= PST_ALLOWOPNBRC; |
5892 | #if defined (ALIAS) | |
5893 | parser_state &= ~PST_ALEXPNEXT; | |
5894 | #endif /* ALIAS */ | |
5895 | function_dstart = line_number; | |
5896 | } | |
726f6388 | 5897 | |
28ef6c31 JA |
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. */ | |
7117c2d2 | 5901 | if MBTEST(character == '(' && (parser_state & PST_CASEPAT) == 0) /* ) */ |
28ef6c31 JA |
5902 | parser_state |= PST_SUBSHELL; |
5903 | /*(*/ | |
7117c2d2 | 5904 | else if MBTEST((parser_state & PST_CASEPAT) && character == ')') |
28ef6c31 JA |
5905 | parser_state &= ~PST_CASEPAT; |
5906 | /*(*/ | |
7117c2d2 | 5907 | else if MBTEST((parser_state & PST_SUBSHELL) && character == ')') |
28ef6c31 | 5908 | parser_state &= ~PST_SUBSHELL; |
726f6388 | 5909 | |
28ef6c31 JA |
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. */ | |
8868edaf | 5913 | if MBTEST((character != '>' && character != '<') || peek_char != '(') /*)*/ |
28ef6c31 JA |
5914 | #endif /* PROCESS_SUBSTITUTION */ |
5915 | return (character); | |
5916 | } | |
726f6388 | 5917 | |
3185942a JA |
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 | */ | |
495aee44 CR |
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 */ | |
6ddc9cf2 | 5946 | #define P_ARITH 0x0080 /* parsing a $(( )) arithmetic expansion */ |
3185942a JA |
5947 | |
5948 | /* Lexical state while parsing a grouping construct or $(...). */ | |
d233b485 CR |
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 | |
74091dd4 CR |
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 */ | |
3185942a JA |
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 | { | |
d233b485 | 5995 | int count, ch, prevch, tflags; |
3185942a JA |
5996 | int nestlen, ttranslen, start_lineno; |
5997 | char *ret, *nestret, *ttrans; | |
5998 | int retind, retsize, rflags; | |
495aee44 CR |
5999 | int dolbrace_state; |
6000 | ||
6001 | dolbrace_state = (flags & P_DOLBRACE) ? DOLBRACE_PARAM : 0; | |
3185942a | 6002 | |
0001803f | 6003 | /*itrace("parse_matched_pair[%d]: open = %c close = %c flags = %d", line_number, open, close, flags);*/ |
3185942a JA |
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; | |
d233b485 | 6017 | ch = EOF; /* just in case */ |
3185942a JA |
6018 | while (count) |
6019 | { | |
d233b485 | 6020 | prevch = ch; |
495aee44 | 6021 | ch = shell_getc (qc != '\'' && (tflags & (LEX_PASSNEXT)) == 0); |
3185942a JA |
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 */ | |
a78e27a1 | 6028 | parser_state |= PST_NOERROR; /* avoid redundant error message */ |
3185942a JA |
6029 | return (&matched_pair_error); |
6030 | } | |
6031 | ||
6032 | /* Possible reprompting. */ | |
74091dd4 CR |
6033 | if MBTEST(ch == '\n' && SHOULD_PROMPT ()) |
6034 | prompt_again (0); | |
3185942a JA |
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 | ||
74091dd4 | 6044 | if MBTEST(ch == '\n') |
3185942a JA |
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; | |
74091dd4 CR |
6059 | /* XXX - PST_NOEXPAND? */ |
6060 | if MBTEST(qc != '\'' && ch == '\n') /* double-quoted \<newline> disappears. */ | |
3185942a JA |
6061 | { |
6062 | if (retind > 0) | |
6063 | retind--; /* swallow previously-added backslash */ | |
6064 | continue; | |
6065 | } | |
6066 | ||
6067 | RESIZE_MALLOCED_BUFFER (ret, retind, 2, retsize, 64); | |
ac50fbac | 6068 | if MBTEST(ch == CTLESC) |
3185942a JA |
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 | ||
495aee44 CR |
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. */ | |
ac50fbac | 6122 | /* FLAG POSIX INTERP 221 */ |
495aee44 CR |
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) | |
ac50fbac | 6133 | dolbrace_state = DOLBRACE_QUOTE2; /* XXX */ |
495aee44 CR |
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 | ||
3185942a | 6146 | /* The big hammer. Single quotes aren't special in double quotes. The |
495aee44 | 6147 | problem is that Posix used to say the single quotes are semi-special: |
3185942a JA |
6148 | within a double-quoted ${...} construct "an even number of |
6149 | unescaped double-quotes or single-quotes, if any, shall occur." */ | |
495aee44 | 6150 | /* This was changed in Austin Group Interp 221 */ |
bc63a081 | 6151 | if MBTEST(posixly_correct && shell_compatibility_level > 41 && dolbrace_state != DOLBRACE_QUOTE && dolbrace_state != DOLBRACE_QUOTE2 && (flags & P_DQUOTE) && (flags & P_DOLBRACE) && ch == '\'') |
3185942a | 6152 | continue; |
3185942a JA |
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 | ||
74091dd4 | 6169 | if MBTEST((tflags & LEX_WASDOL) && ch == '\'' && (extended_quote || (rflags & P_DQUOTE) == 0 || dolbrace_state == DOLBRACE_QUOTE || dolbrace_state == DOLBRACE_QUOTE2)) |
3185942a JA |
6170 | { |
6171 | /* Translate $'...' here. */ | |
74091dd4 | 6172 | /* PST_NOEXPAND */ |
3185942a | 6173 | ttrans = ansiexpand (nestret, 0, nestlen - 1, &ttranslen); |
d233b485 | 6174 | free (nestret); |
3185942a | 6175 | |
ac50fbac CR |
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 */ | |
74091dd4 CR |
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)) | |
ac50fbac CR |
6191 | { |
6192 | nestret = sh_single_quote (ttrans); | |
6193 | free (ttrans); | |
6194 | nestlen = strlen (nestret); | |
6195 | } | |
74091dd4 | 6196 | #endif |
ac50fbac | 6197 | else if ((rflags & P_DQUOTE) == 0) |
3185942a JA |
6198 | { |
6199 | nestret = sh_single_quote (ttrans); | |
6200 | free (ttrans); | |
6201 | nestlen = strlen (nestret); | |
6202 | } | |
6203 | else | |
6204 | { | |
74091dd4 | 6205 | /* Should we quote CTLESC here? */ |
3185942a JA |
6206 | nestret = ttrans; |
6207 | nestlen = ttranslen; | |
6208 | } | |
6209 | retind -= 2; /* back up before the $' */ | |
6210 | } | |
74091dd4 | 6211 | #if defined (TRANSLATABLE_STRINGS) |
3185942a JA |
6212 | else if MBTEST((tflags & LEX_WASDOL) && ch == '"' && (extended_quote || (rflags & P_DQUOTE) == 0)) |
6213 | { | |
6214 | /* Locale expand $"..." here. */ | |
74091dd4 CR |
6215 | /* PST_NOEXPAND */ |
6216 | ttrans = locale_expand (nestret, 0, nestlen - 1, start_lineno, &ttranslen); | |
d233b485 | 6217 | free (nestret); |
3185942a | 6218 | |
74091dd4 CR |
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); | |
3185942a | 6235 | free (ttrans); |
74091dd4 | 6236 | nestlen = strlen (nestret); |
3185942a JA |
6237 | retind -= 2; /* back up before the $" */ |
6238 | } | |
74091dd4 | 6239 | #endif /* TRANSLATABLE_STRINGS */ |
3185942a JA |
6240 | |
6241 | APPEND_NESTRET (); | |
6242 | FREE (nestret); | |
6243 | } | |
a0c0a00f | 6244 | else if ((flags & (P_ARRAYSUB|P_DOLBRACE)) && (tflags & LEX_WASDOL) && (ch == '(' || ch == '{' || ch == '[')) /* ) } ] */ |
0001803f | 6245 | goto parse_dollar_word; |
6ddc9cf2 CR |
6246 | else if ((flags & P_ARITH) && (tflags & LEX_WASDOL) && ch == '(') /*)*/ |
6247 | /* $() inside $(( ))/$[ ] */ | |
6248 | goto parse_dollar_word; | |
d233b485 CR |
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 | |
3185942a JA |
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 | { | |
0001803f | 6271 | parse_dollar_word: |
3185942a JA |
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 == '{') /* } */ | |
495aee44 | 6277 | nestret = parse_matched_pair (0, '{', '}', &nestlen, P_FIRSTCLOSE|P_DOLBRACE|rflags); |
3185942a | 6278 | else if (ch == '[') /* ] */ |
6ddc9cf2 | 6279 | nestret = parse_matched_pair (0, '[', ']', &nestlen, rflags|P_ARITH); |
3185942a JA |
6280 | |
6281 | CHECK_NESTRET_ERROR (); | |
6282 | APPEND_NESTRET (); | |
726f6388 | 6283 | |
3185942a JA |
6284 | FREE (nestret); |
6285 | } | |
d233b485 CR |
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) | |
3185942a JA |
6293 | tflags |= LEX_WASDOL; |
6294 | else | |
6295 | tflags &= ~LEX_WASDOL; | |
6296 | } | |
726f6388 | 6297 | |
3185942a JA |
6298 | ret[retind] = '\0'; |
6299 | if (lenp) | |
6300 | *lenp = retind; | |
0001803f | 6301 | /*itrace("parse_matched_pair[%d]: returning %s", line_number, ret);*/ |
3185942a JA |
6302 | return ret; |
6303 | } | |
726f6388 | 6304 | |
a0c0a00f CR |
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 | } | |
74091dd4 CR |
6344 | if (f & LEX_CKESAC) |
6345 | { | |
6346 | f &= ~LEX_CKESAC; | |
6347 | fprintf (stderr, "LEX_CKESAC%s", f ? "|" : ""); | |
6348 | } | |
a0c0a00f CR |
6349 | if (f & LEX_INCASE) |
6350 | { | |
6351 | f &= ~LEX_INCASE; | |
6352 | fprintf (stderr, "LEX_INCASE%s", f ? "|" : ""); | |
6353 | } | |
74091dd4 CR |
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 | } | |
a0c0a00f CR |
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 | ||
74091dd4 CR |
6395 | /* Parse a $(...) command substitution. This reads input from the current |
6396 | input stream. */ | |
28ef6c31 | 6397 | static char * |
3185942a | 6398 | parse_comsub (qc, open, close, lenp, flags) |
28ef6c31 JA |
6399 | int qc; /* `"' if this construct is within double quotes */ |
6400 | int open, close; | |
6401 | int *lenp, flags; | |
6402 | { | |
74091dd4 CR |
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; | |
ccc6cda3 | 6410 | |
495aee44 CR |
6411 | /* Posix interp 217 says arithmetic expressions have precedence, so |
6412 | assume $(( introduces arithmetic expansion and parse accordingly. */ | |
74091dd4 CR |
6413 | if (open == '(') /*)*/ |
6414 | { | |
6415 | peekc = shell_getc (1); | |
6416 | shell_ungetc (peekc); | |
6417 | if (peekc == '(') /*)*/ | |
6ddc9cf2 | 6418 | return (parse_matched_pair (qc, open, close, lenp, P_ARITH)); |
74091dd4 | 6419 | } |
495aee44 | 6420 | |
3185942a | 6421 | /*itrace("parse_comsub: qc = `%c' open = %c close = %c", qc, open, close);*/ |
3185942a | 6422 | |
74091dd4 CR |
6423 | /*debug_parser(1);*/ |
6424 | start_lineno = line_number; | |
d166f048 | 6425 | |
74091dd4 | 6426 | save_parser_state (&ps); |
b80f6443 | 6427 | |
74091dd4 CR |
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 | |
c7bb74de | 6459 | conditional command and have already set extended_glob appropriately. */ |
74091dd4 CR |
6460 | if (shell_compatibility_level <= 51 && was_extpat == 0) |
6461 | { | |
c7bb74de | 6462 | local_extglob = extended_glob; |
74091dd4 CR |
6463 | extended_glob = 1; |
6464 | } | |
6465 | #endif | |
28ef6c31 | 6466 | |
74091dd4 CR |
6467 | current_token = '\n'; /* XXX */ |
6468 | token_to_read = DOLPAREN; /* let's trick the parser */ | |
3185942a | 6469 | |
74091dd4 | 6470 | r = yyparse (); |
3185942a | 6471 | |
74091dd4 | 6472 | if (need_here_doc > 0) |
28ef6c31 | 6473 | { |
74091dd4 CR |
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 | } | |
0628567a | 6477 | |
74091dd4 CR |
6478 | #if defined (EXTENDED_GLOB) |
6479 | if (shell_compatibility_level <= 51 && was_extpat == 0) | |
6480 | extended_glob = local_extglob; | |
8868edaf | 6481 | #endif |
ccc6cda3 | 6482 | |
74091dd4 | 6483 | parsed_command = global_command; |
3185942a | 6484 | |
74091dd4 CR |
6485 | if (EOF_Reached) |
6486 | { | |
6487 | shell_eof_token = ps.eof_token; | |
6488 | expand_aliases = ps.expand_aliases; | |
726f6388 | 6489 | |
74091dd4 | 6490 | /* yyparse() has already called yyerror() and reset_parser() */ |
a78e27a1 | 6491 | parser_state |= PST_NOERROR; |
74091dd4 CR |
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 | |
0001803f | 6504 | { |
74091dd4 CR |
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)? */ | |
0001803f | 6509 | } |
74091dd4 | 6510 | } |
0001803f | 6511 | |
74091dd4 CR |
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; | |
95732b49 | 6516 | |
74091dd4 CR |
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; | |
95732b49 | 6523 | |
74091dd4 CR |
6524 | return (&matched_pair_error); |
6525 | } | |
95732b49 | 6526 | |
74091dd4 CR |
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'; | |
0001803f | 6548 | |
74091dd4 CR |
6549 | dispose_command (parsed_command); |
6550 | global_command = saved_global; | |
ccc6cda3 | 6551 | |
28ef6c31 | 6552 | if (lenp) |
74091dd4 CR |
6553 | *lenp = retlen; |
6554 | ||
3185942a JA |
6555 | /*itrace("parse_comsub:%d: returning `%s'", line_number, ret);*/ |
6556 | return ret; | |
6557 | } | |
6558 | ||
74091dd4 CR |
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(). */ | |
3185942a JA |
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; | |
509a4430 | 6570 | sh_input_line_state_t ls; |
c7bb74de | 6571 | int orig_ind, nc, sflags, start_lineno, local_extglob; |
d233b485 | 6572 | char *ret, *ep, *ostring; |
3185942a | 6573 | |
d233b485 | 6574 | /*debug_parser(1);*/ |
3185942a JA |
6575 | orig_ind = *indp; |
6576 | ostring = string; | |
8868edaf | 6577 | start_lineno = line_number; |
3185942a | 6578 | |
d233b485 CR |
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 | ||
8868edaf | 6589 | /*itrace("xparse_dolparen: size = %d shell_input_line = `%s' string=`%s'", shell_input_line_size, shell_input_line, string);*/ |
74091dd4 | 6590 | |
3185942a JA |
6591 | sflags = SEVAL_NONINT|SEVAL_NOHIST|SEVAL_NOFREE; |
6592 | if (flags & SX_NOLONGJMP) | |
6593 | sflags |= SEVAL_NOLONGJMP; | |
74091dd4 | 6594 | |
3185942a | 6595 | save_parser_state (&ps); |
509a4430 | 6596 | save_input_line_state (&ls); |
74091dd4 | 6597 | |
d233b485 | 6598 | #if defined (ALIAS) || defined (DPAREN_ARITHMETIC) |
d233b485 CR |
6599 | pushed_string_list = (STRING_SAVER *)NULL; |
6600 | #endif | |
3185942a JA |
6601 | /*(*/ |
6602 | parser_state |= PST_CMDSUBST|PST_EOFTOKEN; /* allow instant ')' */ /*(*/ | |
6603 | shell_eof_token = ')'; | |
74091dd4 CR |
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) | |
c7bb74de | 6614 | local_extglob = extended_glob; |
74091dd4 | 6615 | #endif |
a0c0a00f | 6616 | |
74091dd4 | 6617 | token_to_read = DOLPAREN; /* let's trick the parser */ |
d233b485 | 6618 | |
74091dd4 | 6619 | nc = parse_string (string, "command substitution", sflags, (COMMAND **)NULL, &ep); |
3185942a | 6620 | |
74091dd4 CR |
6621 | /* Should we save and restore the bison/yacc lookahead token (yychar) here? |
6622 | Or only if it's not YYEMPTY? */ | |
d233b485 CR |
6623 | if (current_token == shell_eof_token) |
6624 | yyclearin; /* might want to clear lookahead token unconditionally */ | |
6625 | ||
74091dd4 | 6626 | reset_parser (); /* resets extended_glob too */ |
8868edaf CR |
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. */ | |
509a4430 | 6629 | restore_input_line_state (&ls); |
8868edaf CR |
6630 | restore_parser_state (&ps); |
6631 | ||
c7bb74de CR |
6632 | #if defined (EXTENDED_GLOB) |
6633 | extended_glob = local_extglob; | |
6634 | #endif | |
ca6a2ba4 | 6635 | token_to_read = 0; |
3185942a | 6636 | |
a0c0a00f | 6637 | /* If parse_string returns < 0, we need to jump to top level with the |
d233b485 CR |
6638 | negative of the return value. We abandon the rest of this input line |
6639 | first */ | |
a0c0a00f | 6640 | if (nc < 0) |
d233b485 CR |
6641 | { |
6642 | clear_shell_input_line (); /* XXX */ | |
8868edaf CR |
6643 | if (bash_input.type != st_string) /* paranoia */ |
6644 | parser_state &= ~(PST_CMDSUBST|PST_EOFTOKEN); | |
74091dd4 CR |
6645 | if ((flags & SX_NOLONGJMP) == 0) |
6646 | jump_to_top_level (-nc); /* XXX */ | |
d233b485 | 6647 | } |
a0c0a00f | 6648 | |
74091dd4 | 6649 | /* Need to find how many characters parse_string() consumed, update |
3185942a | 6650 | *indp, if flags != 0, copy the portion of the string parsed into RET |
d233b485 | 6651 | and return it. If flags & 1 (SX_NOALLOC) we can return NULL. */ |
3185942a JA |
6652 | |
6653 | /*(*/ | |
6654 | if (ep[-1] != ')') | |
6655 | { | |
74091dd4 | 6656 | #if 0 |
3185942a JA |
6657 | if (ep[-1] != '\n') |
6658 | itrace("xparse_dolparen:%d: ep[-1] != RPAREN (%d), ep = `%s'", line_number, ep[-1], ep); | |
6659 | #endif | |
8868edaf | 6660 | |
3185942a JA |
6661 | while (ep > ostring && ep[-1] == '\n') ep--; |
6662 | } | |
6663 | ||
6664 | nc = ep - ostring; | |
6665 | *indp = ep - base - 1; | |
6666 | ||
8868edaf | 6667 | /*((*/ |
74091dd4 | 6668 | #if 0 |
3185942a JA |
6669 | if (base[*indp] != ')') |
6670 | itrace("xparse_dolparen:%d: base[%d] != RPAREN (%d), base = `%s'", line_number, *indp, base[*indp], base); | |
d233b485 CR |
6671 | if (*indp < orig_ind) |
6672 | itrace("xparse_dolparen:%d: *indp (%d) < orig_ind (%d), orig_string = `%s'", line_number, *indp, orig_ind, ostring); | |
3185942a JA |
6673 | #endif |
6674 | ||
74091dd4 | 6675 | if (base[*indp] != ')' && (flags & SX_NOLONGJMP) == 0) |
8868edaf CR |
6676 | { |
6677 | /*(*/ | |
74091dd4 CR |
6678 | if ((flags & SX_NOERROR) == 0) |
6679 | parser_error (start_lineno, _("unexpected EOF while looking for matching `%c'"), ')'); | |
8868edaf CR |
6680 | jump_to_top_level (DISCARD); |
6681 | } | |
6682 | ||
3185942a JA |
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 | ||
28ef6c31 JA |
6694 | return ret; |
6695 | } | |
726f6388 | 6696 | |
74091dd4 CR |
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 | ||
8c9524f9 | 6733 | parser_state |= PST_STRING; |
74091dd4 CR |
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 | ||
28ef6c31 | 6766 | #if defined (DPAREN_ARITHMETIC) || defined (ARITH_FOR_COMMAND) |
7117c2d2 JA |
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 | { | |
0628567a JA |
6775 | int cmdtyp, sline; |
6776 | char *wval; | |
7117c2d2 JA |
6777 | WORD_DESC *wd; |
6778 | ||
6779 | #if defined (ARITH_FOR_COMMAND) | |
6780 | if (last_read_token == FOR) | |
6781 | { | |
74091dd4 CR |
6782 | if (word_top < MAX_CASE_NEST) |
6783 | word_top++; | |
6784 | arith_for_lineno = word_lineno[word_top] = line_number; | |
b80f6443 | 6785 | cmdtyp = parse_arith_cmd (&wval, 0); |
7117c2d2 JA |
6786 | if (cmdtyp == 1) |
6787 | { | |
95732b49 JA |
6788 | wd = alloc_word_desc (); |
6789 | wd->word = wval; | |
7117c2d2 | 6790 | yylval.word_list = make_word_list (wd, (WORD_LIST *)NULL); |
7117c2d2 JA |
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; | |
95732b49 | 6802 | |
b80f6443 | 6803 | cmdtyp = parse_arith_cmd (&wval, 0); |
7117c2d2 JA |
6804 | if (cmdtyp == 1) /* arithmetic command */ |
6805 | { | |
95732b49 JA |
6806 | wd = alloc_word_desc (); |
6807 | wd->word = wval; | |
74091dd4 | 6808 | wd->flags = W_QUOTED|W_NOSPLIT|W_NOGLOB|W_NOTILDE|W_NOPROCSUB; |
7117c2d2 | 6809 | yylval.word_list = make_word_list (wd, (WORD_LIST *)NULL); |
7117c2d2 JA |
6810 | return (ARITH_CMD); |
6811 | } | |
6812 | else if (cmdtyp == 0) /* nested subshell */ | |
6813 | { | |
6814 | push_string (wval, 0, (alias_t *)NULL); | |
ac50fbac | 6815 | pushed_string_list->flags = PSH_DPAREN; |
7117c2d2 JA |
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 | ||
28ef6c31 JA |
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 | |
b80f6443 | 6834 | parse_arith_cmd (ep, adddq) |
28ef6c31 | 6835 | char **ep; |
b80f6443 | 6836 | int adddq; |
28ef6c31 JA |
6837 | { |
6838 | int exp_lineno, rval, c; | |
f73dda09 | 6839 | char *ttok, *tokstr; |
28ef6c31 | 6840 | int ttoklen; |
726f6388 | 6841 | |
28ef6c31 | 6842 | exp_lineno = line_number; |
6ddc9cf2 | 6843 | ttok = parse_matched_pair (0, '(', ')', &ttoklen, P_ARITH); |
28ef6c31 JA |
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. ( */ | |
7117c2d2 JA |
6849 | c = shell_getc (0); |
6850 | if MBTEST(c != ')') | |
28ef6c31 JA |
6851 | rval = 0; |
6852 | ||
f73dda09 | 6853 | tokstr = (char *)xmalloc (ttoklen + 4); |
28ef6c31 | 6854 | |
b80f6443 JA |
6855 | /* if ADDDQ != 0 then (( ... )) -> "..." */ |
6856 | if (rval == 1 && adddq) /* arith cmd, add double quotes */ | |
726f6388 | 6857 | { |
b80f6443 JA |
6858 | tokstr[0] = '"'; |
6859 | strncpy (tokstr + 1, ttok, ttoklen - 1); | |
f73dda09 JA |
6860 | tokstr[ttoklen] = '"'; |
6861 | tokstr[ttoklen+1] = '\0'; | |
726f6388 | 6862 | } |
b80f6443 JA |
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 */ | |
726f6388 | 6869 | { |
b80f6443 JA |
6870 | tokstr[0] = '('; |
6871 | strncpy (tokstr + 1, ttok, ttoklen - 1); | |
f73dda09 JA |
6872 | tokstr[ttoklen] = ')'; |
6873 | tokstr[ttoklen+1] = c; | |
6874 | tokstr[ttoklen+2] = '\0'; | |
726f6388 | 6875 | } |
b80f6443 | 6876 | |
f73dda09 | 6877 | *ep = tokstr; |
28ef6c31 JA |
6878 | FREE (ttok); |
6879 | return rval; | |
726f6388 | 6880 | } |
28ef6c31 | 6881 | #endif /* DPAREN_ARITHMETIC || ARITH_FOR_COMMAND */ |
726f6388 | 6882 | |
28ef6c31 | 6883 | #if defined (COND_COMMAND) |
7117c2d2 JA |
6884 | static void |
6885 | cond_error () | |
6886 | { | |
6887 | char *etext; | |
6888 | ||
6889 | if (EOF_Reached && cond_token != COND_ERROR) /* [[ */ | |
b80f6443 | 6890 | parser_error (cond_lineno, _("unexpected EOF while looking for `]]'")); |
7117c2d2 JA |
6891 | else if (cond_token != COND_ERROR) |
6892 | { | |
6893 | if (etext = error_token_from_token (cond_token)) | |
6894 | { | |
b80f6443 | 6895 | parser_error (cond_lineno, _("syntax error in conditional expression: unexpected token `%s'"), etext); |
7117c2d2 JA |
6896 | free (etext); |
6897 | } | |
6898 | else | |
b80f6443 | 6899 | parser_error (cond_lineno, _("syntax error in conditional expression")); |
7117c2d2 JA |
6900 | } |
6901 | } | |
6902 | ||
28ef6c31 JA |
6903 | static COND_COM * |
6904 | cond_expr () | |
ccc6cda3 | 6905 | { |
28ef6c31 | 6906 | return (cond_or ()); |
ccc6cda3 JA |
6907 | } |
6908 | ||
28ef6c31 JA |
6909 | static COND_COM * |
6910 | cond_or () | |
726f6388 | 6911 | { |
28ef6c31 | 6912 | COND_COM *l, *r; |
726f6388 | 6913 | |
28ef6c31 JA |
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; | |
726f6388 | 6921 | } |
726f6388 | 6922 | |
28ef6c31 JA |
6923 | static COND_COM * |
6924 | cond_and () | |
726f6388 | 6925 | { |
28ef6c31 | 6926 | COND_COM *l, *r; |
726f6388 | 6927 | |
28ef6c31 JA |
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; | |
726f6388 JA |
6935 | } |
6936 | ||
ccc6cda3 | 6937 | static int |
28ef6c31 | 6938 | cond_skip_newlines () |
726f6388 | 6939 | { |
28ef6c31 | 6940 | while ((cond_token = read_token (READ)) == '\n') |
726f6388 | 6941 | { |
b80f6443 | 6942 | if (SHOULD_PROMPT ()) |
74091dd4 | 6943 | prompt_again (0); |
726f6388 | 6944 | } |
28ef6c31 | 6945 | return (cond_token); |
726f6388 JA |
6946 | } |
6947 | ||
28ef6c31 JA |
6948 | #define COND_RETURN_ERROR() \ |
6949 | do { cond_token = COND_ERROR; return ((COND_COM *)NULL); } while (0) | |
726f6388 | 6950 | |
28ef6c31 JA |
6951 | static COND_COM * |
6952 | cond_term () | |
726f6388 | 6953 | { |
28ef6c31 JA |
6954 | WORD_DESC *op; |
6955 | COND_COM *term, *tleft, *tright; | |
74091dd4 | 6956 | int tok, lineno, local_extglob; |
7117c2d2 | 6957 | char *etext; |
28ef6c31 JA |
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) | |
726f6388 | 6965 | { |
28ef6c31 | 6966 | COND_RETURN_ERROR (); |
726f6388 | 6967 | } |
28ef6c31 JA |
6968 | else if (tok == '(') |
6969 | { | |
6970 | term = cond_expr (); | |
6971 | if (cond_token != ')') | |
6972 | { | |
6973 | if (term) | |
6974 | dispose_cond_node (term); /* ( */ | |
7117c2d2 JA |
6975 | if (etext = error_token_from_token (cond_token)) |
6976 | { | |
b80f6443 | 6977 | parser_error (lineno, _("unexpected token `%s', expected `)'"), etext); |
7117c2d2 JA |
6978 | free (etext); |
6979 | } | |
6980 | else | |
b80f6443 | 6981 | parser_error (lineno, _("expected `)'")); |
28ef6c31 JA |
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) | |
9439ce09 | 6993 | term->flags ^= CMD_INVERT_RETURN; |
28ef6c31 | 6994 | } |
d233b485 | 6995 | else if (tok == WORD && yylval.word->word[0] == '-' && yylval.word->word[1] && yylval.word->word[2] == 0 && test_unop (yylval.word->word)) |
28ef6c31 JA |
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); | |
7117c2d2 JA |
7007 | if (etext = error_token_from_token (tok)) |
7008 | { | |
b80f6443 | 7009 | parser_error (line_number, _("unexpected argument `%s' to conditional unary operator"), etext); |
7117c2d2 JA |
7010 | free (etext); |
7011 | } | |
7012 | else | |
b80f6443 | 7013 | parser_error (line_number, _("unexpected argument to conditional unary operator")); |
28ef6c31 JA |
7014 | COND_RETURN_ERROR (); |
7015 | } | |
726f6388 | 7016 | |
28ef6c31 JA |
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); | |
726f6388 | 7023 | |
28ef6c31 | 7024 | /* binop */ |
74091dd4 | 7025 | /* tok = cond_skip_newlines (); ? */ |
28ef6c31 JA |
7026 | tok = read_token (READ); |
7027 | if (tok == WORD && test_binop (yylval.word->word)) | |
0001803f CR |
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 | } | |
b80f6443 | 7035 | #if defined (COND_REGEXP) |
3185942a JA |
7036 | else if (tok == WORD && STREQ (yylval.word->word, "=~")) |
7037 | { | |
7038 | op = yylval.word; | |
7039 | parser_state |= PST_REGEXP; | |
7040 | } | |
b80f6443 | 7041 | #endif |
28ef6c31 JA |
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 | { | |
7117c2d2 JA |
7058 | if (etext = error_token_from_token (tok)) |
7059 | { | |
b80f6443 | 7060 | parser_error (line_number, _("unexpected token `%s', conditional binary operator expected"), etext); |
7117c2d2 JA |
7061 | free (etext); |
7062 | } | |
7063 | else | |
b80f6443 | 7064 | parser_error (line_number, _("conditional binary operator expected")); |
28ef6c31 JA |
7065 | dispose_cond_node (tleft); |
7066 | COND_RETURN_ERROR (); | |
7067 | } | |
726f6388 | 7068 | |
28ef6c31 | 7069 | /* rhs */ |
c7bb74de | 7070 | #if defined (EXTENDED_GLOB) |
74091dd4 | 7071 | local_extglob = extended_glob; |
0001803f CR |
7072 | if (parser_state & PST_EXTPAT) |
7073 | extended_glob = 1; | |
c7bb74de | 7074 | #endif |
28ef6c31 | 7075 | tok = read_token (READ); |
c7bb74de | 7076 | #if defined (EXTENDED_GLOB) |
0001803f | 7077 | if (parser_state & PST_EXTPAT) |
74091dd4 | 7078 | extended_glob = local_extglob; |
c7bb74de | 7079 | #endif |
0001803f CR |
7080 | parser_state &= ~(PST_REGEXP|PST_EXTPAT); |
7081 | ||
28ef6c31 JA |
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 | { | |
7117c2d2 JA |
7089 | if (etext = error_token_from_token (tok)) |
7090 | { | |
b80f6443 | 7091 | parser_error (line_number, _("unexpected argument `%s' to conditional binary operator"), etext); |
7117c2d2 JA |
7092 | free (etext); |
7093 | } | |
7094 | else | |
b80f6443 | 7095 | parser_error (line_number, _("unexpected argument to conditional binary operator")); |
28ef6c31 JA |
7096 | dispose_cond_node (tleft); |
7097 | dispose_word (op); | |
7098 | COND_RETURN_ERROR (); | |
7099 | } | |
726f6388 | 7100 | |
28ef6c31 JA |
7101 | (void)cond_skip_newlines (); |
7102 | } | |
7103 | else | |
7104 | { | |
7105 | if (tok < 256) | |
b80f6443 | 7106 | parser_error (line_number, _("unexpected token `%c' in conditional command"), tok); |
7117c2d2 JA |
7107 | else if (etext = error_token_from_token (tok)) |
7108 | { | |
b80f6443 | 7109 | parser_error (line_number, _("unexpected token `%s' in conditional command"), etext); |
7117c2d2 JA |
7110 | free (etext); |
7111 | } | |
28ef6c31 | 7112 | else |
b80f6443 | 7113 | parser_error (line_number, _("unexpected token %d in conditional command"), tok); |
28ef6c31 JA |
7114 | COND_RETURN_ERROR (); |
7115 | } | |
7116 | return (term); | |
7117 | } | |
ccc6cda3 | 7118 | |
28ef6c31 JA |
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; | |
ccc6cda3 | 7125 | |
28ef6c31 JA |
7126 | cexp = cond_expr (); |
7127 | return (make_cond_command (cexp)); | |
7128 | } | |
7129 | #endif | |
ccc6cda3 | 7130 | |
7117c2d2 JA |
7131 | #if defined (ARRAY_VARS) |
7132 | /* When this is called, it's guaranteed that we don't care about anything | |
d233b485 CR |
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. */ | |
7117c2d2 JA |
7137 | static int |
7138 | token_is_assignment (t, i) | |
7139 | char *t; | |
7140 | int i; | |
7141 | { | |
7117c2d2 | 7142 | int r; |
d233b485 | 7143 | char *atoken; |
7117c2d2 | 7144 | |
d233b485 CR |
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); | |
7117c2d2 JA |
7157 | } |
7158 | ||
95732b49 | 7159 | /* XXX - possible changes here for `+=' */ |
7117c2d2 JA |
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 | ||
726f6388 | 7176 | static int |
28ef6c31 JA |
7177 | read_token_word (character) |
7178 | int character; | |
726f6388 | 7179 | { |
28ef6c31 JA |
7180 | /* The value for YYLVAL when a WORD is read. */ |
7181 | WORD_DESC *the_word; | |
726f6388 | 7182 | |
28ef6c31 JA |
7183 | /* Index into the token that we are building. */ |
7184 | int token_index; | |
ccc6cda3 | 7185 | |
28ef6c31 | 7186 | /* ALL_DIGITS becomes zero when we see a non-digit. */ |
f73dda09 | 7187 | int all_digit_token; |
ccc6cda3 | 7188 | |
28ef6c31 JA |
7189 | /* DOLLAR_PRESENT becomes non-zero if we see a `$'. */ |
7190 | int dollar_present; | |
cce855bc | 7191 | |
95732b49 JA |
7192 | /* COMPOUND_ASSIGNMENT becomes non-zero if we are parsing a compound |
7193 | assignment. */ | |
7194 | int compound_assignment; | |
7195 | ||
28ef6c31 JA |
7196 | /* QUOTED becomes non-zero if we see one of ("), ('), (`), or (\). */ |
7197 | int quoted; | |
cce855bc | 7198 | |
28ef6c31 JA |
7199 | /* Non-zero means to ignore the value of the next character, and just |
7200 | to add it no matter what. */ | |
a0c0a00f | 7201 | int pass_next_character; |
cce855bc | 7202 | |
28ef6c31 JA |
7203 | /* The current delimiting character. */ |
7204 | int cd; | |
7205 | int result, peek_char; | |
7206 | char *ttok, *ttrans; | |
7207 | int ttoklen, ttranslen; | |
7117c2d2 | 7208 | intmax_t lvalue; |
ccc6cda3 | 7209 | |
28ef6c31 | 7210 | if (token_buffer_size < TOKEN_DEFAULT_INITIAL_SIZE) |
f73dda09 | 7211 | token = (char *)xrealloc (token, token_buffer_size = TOKEN_DEFAULT_INITIAL_SIZE); |
726f6388 | 7212 | |
28ef6c31 | 7213 | token_index = 0; |
f73dda09 | 7214 | all_digit_token = DIGIT (character); |
95732b49 | 7215 | dollar_present = quoted = pass_next_character = compound_assignment = 0; |
ccc6cda3 | 7216 | |
28ef6c31 | 7217 | for (;;) |
ccc6cda3 | 7218 | { |
28ef6c31 JA |
7219 | if (character == EOF) |
7220 | goto got_token; | |
726f6388 | 7221 | |
28ef6c31 | 7222 | if (pass_next_character) |
726f6388 | 7223 | { |
28ef6c31 | 7224 | pass_next_character = 0; |
3185942a | 7225 | goto got_escaped_character; |
726f6388 | 7226 | } |
726f6388 | 7227 | |
28ef6c31 | 7228 | cd = current_delimiter (dstack); |
ccc6cda3 | 7229 | |
28ef6c31 JA |
7230 | /* Handle backslashes. Quote lots of things when not inside of |
7231 | double-quotes, quote some things inside of double-quotes. */ | |
7117c2d2 | 7232 | if MBTEST(character == '\\') |
28ef6c31 | 7233 | { |
74091dd4 CR |
7234 | if (parser_state & PST_NOEXPAND) |
7235 | { | |
7236 | pass_next_character++; | |
7237 | quoted = 1; | |
7238 | goto got_character; | |
7239 | } | |
7240 | ||
28ef6c31 | 7241 | peek_char = shell_getc (0); |
ccc6cda3 | 7242 | |
28ef6c31 JA |
7243 | /* Backslash-newline is ignored in all cases except |
7244 | when quoted with single quotes. */ | |
74091dd4 | 7245 | if MBTEST(peek_char == '\n') |
28ef6c31 JA |
7246 | { |
7247 | character = '\n'; | |
7248 | goto next_character; | |
7249 | } | |
7250 | else | |
7251 | { | |
7252 | shell_ungetc (peek_char); | |
ccc6cda3 | 7253 | |
28ef6c31 | 7254 | /* If the next character is to be quoted, note it now. */ |
74091dd4 | 7255 | if MBTEST(cd == 0 || cd == '`' || |
f73dda09 | 7256 | (cd == '"' && peek_char >= 0 && (sh_syntaxtab[peek_char] & CBSDQUOTE))) |
28ef6c31 | 7257 | pass_next_character++; |
ccc6cda3 | 7258 | |
28ef6c31 JA |
7259 | quoted = 1; |
7260 | goto got_character; | |
7261 | } | |
7262 | } | |
726f6388 | 7263 | |
28ef6c31 | 7264 | /* Parse a matched pair of quote characters. */ |
7117c2d2 | 7265 | if MBTEST(shellquote (character)) |
d166f048 | 7266 | { |
28ef6c31 | 7267 | push_delimiter (dstack, character); |
95732b49 | 7268 | ttok = parse_matched_pair (character, character, character, &ttoklen, (character == '`') ? P_COMMAND : 0); |
28ef6c31 JA |
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; | |
f73dda09 | 7277 | all_digit_token = 0; |
d233b485 CR |
7278 | if (character != '`') |
7279 | quoted = 1; | |
28ef6c31 JA |
7280 | dollar_present |= (character == '"' && strchr (ttok, '$') != 0); |
7281 | FREE (ttok); | |
7282 | goto next_character; | |
d166f048 | 7283 | } |
726f6388 | 7284 | |
3185942a JA |
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 | ||
28ef6c31 JA |
7310 | #ifdef EXTENDED_GLOB |
7311 | /* Parse a ksh-style extended pattern matching specification. */ | |
3185942a | 7312 | if MBTEST(extended_glob && PATTERN_CHAR (character)) |
cce855bc | 7313 | { |
28ef6c31 | 7314 | peek_char = shell_getc (1); |
7117c2d2 | 7315 | if MBTEST(peek_char == '(') /* ) */ |
28ef6c31 JA |
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. */ | |
ac50fbac | 7322 | RESIZE_MALLOCED_BUFFER (token, token_index, ttoklen + 3, |
28ef6c31 JA |
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); | |
f73dda09 | 7330 | dollar_present = all_digit_token = 0; |
28ef6c31 JA |
7331 | goto next_character; |
7332 | } | |
7333 | else | |
7334 | shell_ungetc (peek_char); | |
7335 | } | |
7336 | #endif /* EXTENDED_GLOB */ | |
726f6388 | 7337 | |
28ef6c31 JA |
7338 | /* If the delimiter character is not single quote, parse some of |
7339 | the shell expansions that must be read as a single word. */ | |
74091dd4 | 7340 | if MBTEST(shellexp (character)) |
28ef6c31 JA |
7341 | { |
7342 | peek_char = shell_getc (1); | |
7343 | /* $(...), <(...), >(...), $((...)), ${...}, and $[...] constructs */ | |
ac50fbac | 7344 | if MBTEST(peek_char == '(' || |
28ef6c31 JA |
7345 | ((peek_char == '{' || peek_char == '[') && character == '$')) /* ) ] } */ |
7346 | { | |
7347 | if (peek_char == '{') /* } */ | |
495aee44 | 7348 | ttok = parse_matched_pair (cd, '{', '}', &ttoklen, P_FIRSTCLOSE|P_DOLBRACE); |
28ef6c31 JA |
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); | |
3185942a | 7357 | ttok = parse_comsub (cd, '(', ')', &ttoklen, P_COMMAND); |
28ef6c31 JA |
7358 | pop_delimiter (dstack); |
7359 | } | |
7360 | else | |
6ddc9cf2 | 7361 | ttok = parse_matched_pair (cd, '[', ']', &ttoklen, P_ARITH); |
28ef6c31 JA |
7362 | if (ttok == &matched_pair_error) |
7363 | return -1; /* Bail immediately. */ | |
ac50fbac | 7364 | RESIZE_MALLOCED_BUFFER (token, token_index, ttoklen + 3, |
28ef6c31 JA |
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; | |
f73dda09 | 7373 | all_digit_token = 0; |
28ef6c31 JA |
7374 | goto next_character; |
7375 | } | |
7376 | /* This handles $'...' and $"..." new-style quoted strings. */ | |
74091dd4 | 7377 | #if defined (TRANSLATABLE_STRINGS) |
7117c2d2 | 7378 | else if MBTEST(character == '$' && (peek_char == '\'' || peek_char == '"')) |
74091dd4 CR |
7379 | #else |
7380 | else if MBTEST(character == '$' && peek_char == '\'') | |
7381 | #endif | |
28ef6c31 JA |
7382 | { |
7383 | int first_line; | |
726f6388 | 7384 | |
28ef6c31 JA |
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 | { | |
74091dd4 | 7395 | /* PST_NOEXPAND */ |
28ef6c31 JA |
7396 | ttrans = ansiexpand (ttok, 0, ttoklen - 1, &ttranslen); |
7397 | free (ttok); | |
95732b49 | 7398 | |
28ef6c31 JA |
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); | |
95732b49 | 7404 | ttranslen = strlen (ttok); |
28ef6c31 | 7405 | ttrans = ttok; |
28ef6c31 | 7406 | } |
74091dd4 | 7407 | #if defined (TRANSLATABLE_STRINGS) |
28ef6c31 JA |
7408 | else |
7409 | { | |
74091dd4 | 7410 | /* PST_NOEXPAND */ |
0628567a | 7411 | /* Try to locale-expand the converted string. */ |
74091dd4 | 7412 | ttrans = locale_expand (ttok, 0, ttoklen - 1, first_line, &ttranslen); |
28ef6c31 | 7413 | free (ttok); |
726f6388 | 7414 | |
74091dd4 CR |
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 | ||
28ef6c31 JA |
7423 | free (ttrans); |
7424 | ttrans = ttok; | |
74091dd4 | 7425 | ttranslen = strlen (ttrans); |
28ef6c31 | 7426 | } |
74091dd4 | 7427 | #endif /* TRANSLATABLE_STRINGS */ |
726f6388 | 7428 | |
ac50fbac | 7429 | RESIZE_MALLOCED_BUFFER (token, token_index, ttranslen + 1, |
f73dda09 JA |
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.*/ | |
7117c2d2 | 7441 | else if MBTEST(character == '$' && peek_char == '$') |
f73dda09 | 7442 | { |
f73dda09 JA |
7443 | RESIZE_MALLOCED_BUFFER (token, token_index, 3, |
7444 | token_buffer_size, | |
7445 | TOKEN_DEFAULT_GROW_SIZE); | |
ac50fbac CR |
7446 | token[token_index++] = '$'; |
7447 | token[token_index++] = peek_char; | |
f73dda09 JA |
7448 | dollar_present = 1; |
7449 | all_digit_token = 0; | |
f73dda09 JA |
7450 | goto next_character; |
7451 | } | |
7452 | else | |
7453 | shell_ungetc (peek_char); | |
7454 | } | |
28ef6c31 | 7455 | |
f73dda09 | 7456 | #if defined (ARRAY_VARS) |
3185942a JA |
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)))) | |
7117c2d2 | 7463 | { |
0001803f | 7464 | ttok = parse_matched_pair (cd, '[', ']', &ttoklen, P_ARRAYSUB); |
7117c2d2 JA |
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 | } | |
f73dda09 | 7477 | /* Identify possible compound array variable assignment. */ |
95732b49 | 7478 | else if MBTEST(character == '=' && token_index > 0 && (assignment_acceptable (last_read_token) || (parser_state & PST_ASSIGNOK)) && token_is_assignment (token, token_index)) |
ccc6cda3 | 7479 | { |
f73dda09 | 7480 | peek_char = shell_getc (1); |
7117c2d2 | 7481 | if MBTEST(peek_char == '(') /* ) */ |
f73dda09 | 7482 | { |
7117c2d2 JA |
7483 | ttok = parse_compound_assignment (&ttoklen); |
7484 | ||
7485 | RESIZE_MALLOCED_BUFFER (token, token_index, ttoklen + 4, | |
f73dda09 JA |
7486 | token_buffer_size, |
7487 | TOKEN_DEFAULT_GROW_SIZE); | |
7117c2d2 JA |
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++] = ')'; | |
f73dda09 JA |
7497 | FREE (ttok); |
7498 | all_digit_token = 0; | |
95732b49 | 7499 | compound_assignment = 1; |
0628567a | 7500 | #if 1 |
f73dda09 | 7501 | goto next_character; |
95732b49 JA |
7502 | #else |
7503 | goto got_token; /* ksh93 seems to do this */ | |
7504 | #endif | |
f73dda09 JA |
7505 | } |
7506 | else | |
7507 | shell_ungetc (peek_char); | |
ccc6cda3 | 7508 | } |
f73dda09 | 7509 | #endif |
726f6388 | 7510 | |
f73dda09 JA |
7511 | /* When not parsing a multi-character word construct, shell meta- |
7512 | characters break words. */ | |
7117c2d2 | 7513 | if MBTEST(shellbreak (character)) |
f73dda09 JA |
7514 | { |
7515 | shell_ungetc (character); | |
7516 | goto got_token; | |
7517 | } | |
726f6388 | 7518 | |
ac50fbac | 7519 | got_character: |
74091dd4 | 7520 | if MBTEST(character == CTLESC || character == CTLNUL) |
ac50fbac CR |
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); | |
d166f048 | 7530 | |
ac50fbac | 7531 | token[token_index++] = character; |
3185942a JA |
7532 | |
7533 | all_digit_token &= DIGIT (character); | |
7534 | dollar_present |= character == '$'; | |
7535 | ||
f73dda09 | 7536 | next_character: |
b80f6443 | 7537 | if (character == '\n' && SHOULD_PROMPT ()) |
74091dd4 | 7538 | prompt_again (0); |
cce855bc | 7539 | |
f73dda09 JA |
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 (;;) */ | |
cce855bc | 7546 | |
f73dda09 | 7547 | got_token: |
cce855bc | 7548 | |
ac50fbac | 7549 | /* Calls to RESIZE_MALLOCED_BUFFER ensure there is sufficient room. */ |
f73dda09 | 7550 | token[token_index] = '\0'; |
28ef6c31 | 7551 | |
f73dda09 JA |
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. */ | |
ac50fbac CR |
7556 | if MBTEST(all_digit_token && (character == '<' || character == '>' || |
7557 | last_read_token == LESS_AND || | |
f73dda09 JA |
7558 | last_read_token == GREATER_AND)) |
7559 | { | |
7560 | if (legal_number (token, &lvalue) && (int)lvalue == lvalue) | |
ac50fbac CR |
7561 | { |
7562 | yylval.number = lvalue; | |
7563 | return (NUMBER); | |
7564 | } | |
f73dda09 | 7565 | } |
cce855bc | 7566 | |
f73dda09 | 7567 | /* Check for special case tokens. */ |
7117c2d2 | 7568 | result = (last_shell_getc_is_singlebyte) ? special_case_tokens (token) : -1; |
f73dda09 JA |
7569 | if (result >= 0) |
7570 | return result; | |
cce855bc | 7571 | |
f73dda09 JA |
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. */ | |
7117c2d2 | 7576 | if MBTEST(posixly_correct) |
f73dda09 | 7577 | CHECK_FOR_RESERVED_WORD (token); |
cce855bc | 7578 | |
f73dda09 JA |
7579 | /* Aliases are expanded iff EXPAND_ALIASES is non-zero, and quoting |
7580 | inhibits alias expansion. */ | |
7581 | if (expand_aliases && quoted == 0) | |
cce855bc | 7582 | { |
f73dda09 JA |
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; | |
cce855bc | 7588 | } |
28ef6c31 | 7589 | |
f73dda09 JA |
7590 | /* If not in Posix.2 mode, check for reserved words after alias |
7591 | expansion. */ | |
7117c2d2 | 7592 | if MBTEST(posixly_correct == 0) |
f73dda09 JA |
7593 | #endif |
7594 | CHECK_FOR_RESERVED_WORD (token); | |
7595 | ||
a0c0a00f | 7596 | the_word = alloc_word_desc (); |
f73dda09 JA |
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) | |
0628567a JA |
7603 | the_word->flags |= W_QUOTED; /*(*/ |
7604 | if (compound_assignment && token[token_index-1] == ')') | |
95732b49 | 7605 | the_word->flags |= W_COMPASSIGN; |
f73dda09 JA |
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. */ | |
b80f6443 | 7609 | if (assignment (token, (parser_state & PST_COMPASSIGN) != 0)) |
cce855bc | 7610 | { |
f73dda09 JA |
7611 | the_word->flags |= W_ASSIGNMENT; |
7612 | /* Don't perform word splitting on assignment statements. */ | |
b80f6443 | 7613 | if (assignment_acceptable (last_read_token) || (parser_state & PST_COMPASSIGN) != 0) |
ac50fbac CR |
7614 | { |
7615 | the_word->flags |= W_NOSPLIT; | |
7616 | if (parser_state & PST_COMPASSIGN) | |
7617 | the_word->flags |= W_NOGLOB; /* XXX - W_NOBRACE? */ | |
7618 | } | |
cce855bc | 7619 | } |
28ef6c31 | 7620 | |
95732b49 JA |
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)) | |
0628567a JA |
7626 | parser_state |= PST_ASSIGNOK; |
7627 | else if (STREQ (token, "eval") || STREQ (token, "let")) | |
7628 | parser_state |= PST_ASSIGNOK; | |
95732b49 JA |
7629 | } |
7630 | ||
f73dda09 JA |
7631 | yylval.word = the_word; |
7632 | ||
d233b485 | 7633 | /* should we check that quoted == 0 as well? */ |
74091dd4 | 7634 | if MBTEST(token[0] == '{' && token[token_index-1] == '}' && |
0001803f CR |
7635 | (character == '<' || character == '>')) |
7636 | { | |
7637 | /* can use token; already copied to the_word */ | |
7638 | token[token_index-1] = '\0'; | |
ac50fbac | 7639 | #if defined (ARRAY_VARS) |
a0c0a00f | 7640 | if (legal_identifier (token+1) || valid_array_reference (token+1, 0)) |
ac50fbac | 7641 | #else |
0001803f | 7642 | if (legal_identifier (token+1)) |
ac50fbac | 7643 | #endif |
0001803f CR |
7644 | { |
7645 | strcpy (the_word->word, token+1); | |
d233b485 CR |
7646 | /* itrace("read_token_word: returning REDIR_WORD for %s", the_word->word); */ |
7647 | yylval.word = the_word; /* accommodate recursive call */ | |
0001803f CR |
7648 | return (REDIR_WORD); |
7649 | } | |
d233b485 CR |
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; | |
0001803f CR |
7655 | } |
7656 | ||
f73dda09 JA |
7657 | result = ((the_word->flags & (W_ASSIGNMENT|W_NOSPLIT)) == (W_ASSIGNMENT|W_NOSPLIT)) |
7658 | ? ASSIGNMENT_WORD : WORD; | |
7659 | ||
b80f6443 | 7660 | switch (last_read_token) |
cce855bc | 7661 | { |
b80f6443 | 7662 | case FUNCTION: |
f73dda09 JA |
7663 | parser_state |= PST_ALLOWOPNBRC; |
7664 | function_dstart = line_number; | |
b80f6443 JA |
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; | |
d233b485 | 7672 | expecting_in_token++; |
b80f6443 | 7673 | break; |
cce855bc | 7674 | } |
cce855bc | 7675 | |
f73dda09 | 7676 | return (result); |
28ef6c31 | 7677 | } |
cce855bc | 7678 | |
f73dda09 JA |
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 | { | |
7117c2d2 JA |
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: | |
74091dd4 | 7696 | case ARITH_CMD: |
7117c2d2 | 7697 | case BANG: |
0001803f | 7698 | case BAR_AND: |
74091dd4 | 7699 | case COND_END: |
7117c2d2 JA |
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: | |
3185942a JA |
7709 | case SEMI_AND: |
7710 | case SEMI_SEMI_AND: | |
7117c2d2 JA |
7711 | case THEN: |
7712 | case TIME: | |
7713 | case TIMEOPT: | |
495aee44 | 7714 | case TIMEIGN: |
3185942a | 7715 | case COPROC: |
7117c2d2 JA |
7716 | case UNTIL: |
7717 | case WHILE: | |
7718 | case 0: | |
74091dd4 | 7719 | case DOLPAREN: |
7117c2d2 JA |
7720 | return 1; |
7721 | default: | |
3185942a JA |
7722 | #if defined (COPROCESS_SUPPORT) |
7723 | if (last_read_token == WORD && token_before_that == COPROC) | |
7724 | return 1; | |
7725 | #endif | |
495aee44 CR |
7726 | if (last_read_token == WORD && token_before_that == FUNCTION) |
7727 | return 1; | |
7117c2d2 JA |
7728 | return 0; |
7729 | } | |
f73dda09 | 7730 | } |
7117c2d2 | 7731 | |
f73dda09 JA |
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 | } | |
ccc6cda3 | 7744 | |
ac50fbac CR |
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 | ||
f73dda09 JA |
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; | |
726f6388 | 7762 | |
f73dda09 JA |
7763 | if (prompt_string_pointer) |
7764 | { | |
7765 | temp_prompt = (*prompt_string_pointer) | |
7766 | ? decode_prompt_string (*prompt_string_pointer) | |
7767 | : (char *)NULL; | |
726f6388 | 7768 | |
f73dda09 JA |
7769 | if (temp_prompt == 0) |
7770 | { | |
7771 | temp_prompt = (char *)xmalloc (1); | |
7772 | temp_prompt[0] = '\0'; | |
7773 | } | |
ccc6cda3 | 7774 | |
f73dda09 JA |
7775 | FREE (current_readline_prompt); |
7776 | current_readline_prompt = temp_prompt; | |
7777 | } | |
7778 | } | |
7779 | #endif /* READLINE */ | |
7780 | #endif /* 0 */ | |
726f6388 | 7781 | |
f73dda09 JA |
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. */ | |
3185942a | 7786 | static const int no_semi_successors[] = { |
f73dda09 | 7787 | '\n', '{', '(', ')', ';', '&', '|', |
3185942a JA |
7788 | CASE, DO, ELSE, IF, SEMI_SEMI, SEMI_AND, SEMI_SEMI_AND, THEN, UNTIL, |
7789 | WHILE, AND_AND, OR_OR, IN, | |
f73dda09 JA |
7790 | 0 |
7791 | }; | |
ccc6cda3 | 7792 | |
f73dda09 JA |
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 | |
495aee44 CR |
7796 | history entry. LINE is the line we're about to add; it helps |
7797 | make some more intelligent decisions in certain cases. */ | |
f73dda09 | 7798 | char * |
495aee44 CR |
7799 | history_delimiting_chars (line) |
7800 | const char *line; | |
f73dda09 | 7801 | { |
495aee44 | 7802 | static int last_was_heredoc = 0; /* was the last entry the start of a here document? */ |
f73dda09 | 7803 | register int i; |
726f6388 | 7804 | |
495aee44 CR |
7805 | if ((parser_state & PST_HEREDOC) == 0) |
7806 | last_was_heredoc = 0; | |
7807 | ||
f73dda09 JA |
7808 | if (dstack.delimiter_depth != 0) |
7809 | return ("\n"); | |
3185942a JA |
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 | |
495aee44 CR |
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) */ | |
3185942a | 7816 | if (parser_state & PST_HEREDOC) |
495aee44 CR |
7817 | { |
7818 | if (last_was_heredoc) | |
7819 | { | |
7820 | last_was_heredoc = 0; | |
7821 | return "\n"; | |
7822 | } | |
a0c0a00f | 7823 | return (here_doc_first_line ? "\n" : ""); |
495aee44 | 7824 | } |
3185942a | 7825 | |
509a4430 CR |
7826 | if (parser_state & PST_COMPASSIGN) |
7827 | return (" "); | |
7828 | ||
f73dda09 JA |
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 " "; | |
a0c0a00f | 7844 | else |
f73dda09 JA |
7845 | return "; "; /* (...) subshell */ |
7846 | } | |
7847 | else if (token_before_that == WORD && two_tokens_ago == FUNCTION) | |
7848 | return " "; /* function def using `function name' without `()' */ | |
726f6388 | 7849 | |
495aee44 CR |
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 | } | |
a0c0a00f CR |
7858 | else if ((parser_state & PST_HEREDOC) == 0 && current_command_line_count > 1 && need_here_doc > 0) |
7859 | return "\n"; | |
f73dda09 JA |
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. */ | |
3185942a | 7864 | for (i = shell_input_line_index; whitespace (shell_input_line[i]); i++) |
f73dda09 JA |
7865 | ; |
7866 | if (shell_input_line[i] && shell_input_line[i] == 'i' && shell_input_line[i+1] == 'n') | |
7867 | return " "; | |
7868 | return ";"; | |
7869 | } | |
95732b49 JA |
7870 | else if (two_tokens_ago == CASE && token_before_that == WORD && (parser_state & PST_CASESTMT)) |
7871 | return " "; | |
726f6388 | 7872 | |
f73dda09 JA |
7873 | for (i = 0; no_semi_successors[i]; i++) |
7874 | { | |
7875 | if (token_before_that == no_semi_successors[i]) | |
7876 | return (" "); | |
7877 | } | |
726f6388 | 7878 | |
74091dd4 CR |
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. */ | |
d233b485 | 7882 | if (line_isblank (line)) |
74091dd4 | 7883 | return (current_command_line_count > 1 && last_read_token == '\n' && token_before_that != '\n') ? "; " : ""; |
d233b485 | 7884 | |
f73dda09 JA |
7885 | return ("; "); |
7886 | } | |
7887 | #endif /* HISTORY */ | |
ccc6cda3 | 7888 | |
f73dda09 JA |
7889 | /* Issue a prompt, or prepare to issue a prompt when the next character |
7890 | is read. */ | |
7891 | static void | |
74091dd4 CR |
7892 | prompt_again (force) |
7893 | int force; | |
f73dda09 JA |
7894 | { |
7895 | char *temp_prompt; | |
726f6388 | 7896 | |
0001803f | 7897 | if (interactive == 0 || expanding_alias ()) /* XXX */ |
f73dda09 | 7898 | return; |
726f6388 | 7899 | |
f73dda09 JA |
7900 | ps1_prompt = get_string_value ("PS1"); |
7901 | ps2_prompt = get_string_value ("PS2"); | |
28ef6c31 | 7902 | |
a0c0a00f CR |
7903 | ps0_prompt = get_string_value ("PS0"); |
7904 | ||
f73dda09 JA |
7905 | if (!prompt_string_pointer) |
7906 | prompt_string_pointer = &ps1_prompt; | |
28ef6c31 | 7907 | |
f73dda09 JA |
7908 | temp_prompt = *prompt_string_pointer |
7909 | ? decode_prompt_string (*prompt_string_pointer) | |
7910 | : (char *)NULL; | |
28ef6c31 | 7911 | |
f73dda09 JA |
7912 | if (temp_prompt == 0) |
7913 | { | |
7914 | temp_prompt = (char *)xmalloc (1); | |
7915 | temp_prompt[0] = '\0'; | |
28ef6c31 | 7916 | } |
28ef6c31 | 7917 | |
f73dda09 JA |
7918 | current_prompt_string = *prompt_string_pointer; |
7919 | prompt_string_pointer = &ps2_prompt; | |
28ef6c31 | 7920 | |
f73dda09 JA |
7921 | #if defined (READLINE) |
7922 | if (!no_line_editing) | |
ccc6cda3 | 7923 | { |
f73dda09 JA |
7924 | FREE (current_readline_prompt); |
7925 | current_readline_prompt = temp_prompt; | |
ccc6cda3 JA |
7926 | } |
7927 | else | |
f73dda09 | 7928 | #endif /* READLINE */ |
ccc6cda3 | 7929 | { |
f73dda09 JA |
7930 | FREE (current_decoded_prompt); |
7931 | current_decoded_prompt = temp_prompt; | |
ccc6cda3 JA |
7932 | } |
7933 | } | |
726f6388 | 7934 | |
28ef6c31 | 7935 | int |
f73dda09 | 7936 | get_current_prompt_level () |
bb70624e | 7937 | { |
f73dda09 | 7938 | return ((current_prompt_string && current_prompt_string == ps2_prompt) ? 2 : 1); |
28ef6c31 | 7939 | } |
bb70624e | 7940 | |
f73dda09 JA |
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 | ||
28ef6c31 | 7949 | static void |
f73dda09 | 7950 | print_prompt () |
28ef6c31 | 7951 | { |
f73dda09 JA |
7952 | fprintf (stderr, "%s", current_decoded_prompt); |
7953 | fflush (stderr); | |
7954 | } | |
bb70624e | 7955 | |
d233b485 CR |
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 | ||
f73dda09 JA |
7981 | /* Return a string which will be printed as a prompt. The string |
7982 | may contain special characters which are decoded as follows: | |
726f6388 | 7983 | |
f73dda09 | 7984 | \a bell (ascii 07) |
f73dda09 | 7985 | \d the date in Day Mon Date format |
7117c2d2 | 7986 | \e escape (ascii 033) |
f73dda09 JA |
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 | |
7117c2d2 | 7992 | \r CR |
f73dda09 JA |
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 | |
7117c2d2 JA |
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 | |
f73dda09 JA |
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 | |
f73dda09 | 8004 | \! the history number of this command |
7117c2d2 | 8005 | \# the command number of this command |
f73dda09 JA |
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; | |
d233b485 | 8018 | char *result, *t, *orig_string; |
f73dda09 | 8019 | struct dstack save_dstack; |
0001803f | 8020 | int last_exit_value, last_comsub_pid; |
f73dda09 | 8021 | #if defined (PROMPT_STRING_DECODE) |
a0c0a00f | 8022 | size_t result_size; |
74091dd4 | 8023 | size_t result_index; |
0628567a | 8024 | int c, n, i; |
a0c0a00f | 8025 | char *temp, *t_host, octal_string[4]; |
7117c2d2 | 8026 | struct tm *tm; |
f73dda09 | 8027 | time_t the_time; |
7117c2d2 JA |
8028 | char timebuf[128]; |
8029 | char *timefmt; | |
726f6388 | 8030 | |
f73dda09 JA |
8031 | result = (char *)xmalloc (result_size = PROMPT_GROWTH); |
8032 | result[result_index = 0] = 0; | |
8033 | temp = (char *)NULL; | |
d233b485 | 8034 | orig_string = string; |
28ef6c31 | 8035 | |
f73dda09 JA |
8036 | while (c = *string++) |
8037 | { | |
8038 | if (posixly_correct && c == '!') | |
bb70624e | 8039 | { |
f73dda09 | 8040 | if (*string == '!') |
28ef6c31 | 8041 | { |
f73dda09 JA |
8042 | temp = savestring ("!"); |
8043 | goto add_string; | |
8044 | } | |
8045 | else | |
8046 | { | |
8047 | #if !defined (HISTORY) | |
8048 | temp = savestring ("1"); | |
8049 | #else /* HISTORY */ | |
d233b485 | 8050 | temp = itos (prompt_history_number (orig_string)); |
f73dda09 JA |
8051 | #endif /* HISTORY */ |
8052 | string--; /* add_string increments string again. */ | |
8053 | goto add_string; | |
28ef6c31 | 8054 | } |
28ef6c31 | 8055 | } |
f73dda09 JA |
8056 | if (c == '\\') |
8057 | { | |
8058 | c = *string; | |
726f6388 | 8059 | |
f73dda09 JA |
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'; | |
726f6388 | 8072 | |
f73dda09 JA |
8073 | n = read_octal (octal_string); |
8074 | temp = (char *)xmalloc (3); | |
726f6388 | 8075 | |
f73dda09 JA |
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 | } | |
28ef6c31 | 8092 | |
f73dda09 JA |
8093 | for (c = 0; n != -1 && c < 3 && ISOCTAL (*string); c++) |
8094 | string++; | |
28ef6c31 | 8095 | |
7117c2d2 | 8096 | c = 0; /* tested at add_string: */ |
f73dda09 | 8097 | goto add_string; |
28ef6c31 | 8098 | |
f73dda09 | 8099 | case 'd': |
7117c2d2 | 8100 | case 't': |
f73dda09 JA |
8101 | case 'T': |
8102 | case '@': | |
8103 | case 'A': | |
8104 | /* Make the current time/date into a string. */ | |
7117c2d2 | 8105 | (void) time (&the_time); |
509a4430 CR |
8106 | #if defined (HAVE_TZSET) |
8107 | sv_tz ("TZ"); /* XXX -- just make sure */ | |
8108 | #endif | |
7117c2d2 JA |
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 | ||
b80f6443 JA |
8122 | if (n == 0) |
8123 | timebuf[0] = '\0'; | |
8124 | else | |
8125 | timebuf[sizeof(timebuf) - 1] = '\0'; | |
8126 | ||
7117c2d2 JA |
8127 | temp = savestring (timebuf); |
8128 | goto add_string; | |
726f6388 | 8129 | |
7117c2d2 JA |
8130 | case 'D': /* strftime format */ |
8131 | if (string[1] != '{') /* } */ | |
8132 | goto not_escape; | |
726f6388 | 8133 | |
7117c2d2 JA |
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') | |
f73dda09 | 8143 | { |
7117c2d2 JA |
8144 | timefmt[0] = '%'; |
8145 | timefmt[1] = 'X'; /* locale-specific current time */ | |
8146 | timefmt[2] = '\0'; | |
f73dda09 | 8147 | } |
7117c2d2 JA |
8148 | n = strftime (timebuf, sizeof (timebuf), timefmt, tm); |
8149 | free (timefmt); | |
8150 | ||
b80f6443 JA |
8151 | if (n == 0) |
8152 | timebuf[0] = '\0'; | |
8153 | else | |
8154 | timebuf[sizeof(timebuf) - 1] = '\0'; | |
8155 | ||
7117c2d2 JA |
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. */ | |
74091dd4 | 8160 | temp = sh_backslash_quote_for_double_quotes (timebuf, 0); |
7117c2d2 JA |
8161 | else |
8162 | temp = savestring (timebuf); | |
f73dda09 | 8163 | goto add_string; |
7117c2d2 | 8164 | |
f73dda09 JA |
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; | |
ccc6cda3 | 8171 | |
f73dda09 JA |
8172 | case 's': |
8173 | temp = base_pathname (shell_name); | |
a0c0a00f CR |
8174 | /* Try to quote anything the user can set in the file system */ |
8175 | if (promptvars || posixly_correct) | |
74091dd4 CR |
8176 | { |
8177 | char *t; | |
8178 | t = sh_strvis (temp); | |
8179 | temp = sh_backslash_quote_for_double_quotes (t, 0); | |
8180 | free (t); | |
8181 | } | |
a0c0a00f | 8182 | else |
74091dd4 | 8183 | temp = sh_strvis (temp); |
f73dda09 | 8184 | goto add_string; |
726f6388 | 8185 | |
f73dda09 JA |
8186 | case 'v': |
8187 | case 'V': | |
7117c2d2 | 8188 | temp = (char *)xmalloc (16); |
f73dda09 JA |
8189 | if (c == 'v') |
8190 | strcpy (temp, dist_version); | |
8191 | else | |
8192 | sprintf (temp, "%s.%d", dist_version, patch_level); | |
8193 | goto add_string; | |
bb70624e | 8194 | |
f73dda09 JA |
8195 | case 'w': |
8196 | case 'W': | |
8197 | { | |
8198 | /* Use the value of PWD because it is much more efficient. */ | |
0628567a | 8199 | char t_string[PATH_MAX]; |
f73dda09 | 8200 | int tlen; |
28ef6c31 | 8201 | |
f73dda09 | 8202 | temp = get_string_value ("PWD"); |
ccc6cda3 | 8203 | |
f73dda09 JA |
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'; | |
726f6388 | 8220 | |
0001803f CR |
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 | ||
f73dda09 JA |
8228 | #define ROOT_PATH(x) ((x)[0] == '/' && (x)[1] == 0) |
8229 | #define DOUBLE_SLASH_ROOT(x) ((x)[0] == '/' && (x)[1] == '/' && (x)[2] == 0) | |
b80f6443 | 8230 | /* Abbreviate \W as ~ if $PWD == $HOME */ |
95732b49 | 8231 | if (c == 'W' && (((t = get_string_value ("HOME")) == 0) || STREQ (t, t_string) == 0)) |
f73dda09 JA |
8232 | { |
8233 | if (ROOT_PATH (t_string) == 0 && DOUBLE_SLASH_ROOT (t_string) == 0) | |
8234 | { | |
8235 | t = strrchr (t_string, '/'); | |
8236 | if (t) | |
495aee44 | 8237 | memmove (t_string, t + 1, strlen (t)); /* strlen(t) to copy NULL */ |
f73dda09 JA |
8238 | } |
8239 | } | |
8240 | #undef ROOT_PATH | |
8241 | #undef DOUBLE_SLASH_ROOT | |
8242 | else | |
ac50fbac CR |
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 | } | |
726f6388 | 8250 | |
3185942a | 8251 | temp = trim_pathname (t_string, PATH_MAX - 1); |
f73dda09 JA |
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 | |
7117c2d2 | 8256 | second argument of Q_DOUBLE_QUOTES if we use this |
f73dda09 | 8257 | function here. */ |
74091dd4 CR |
8258 | { |
8259 | char *t; | |
8260 | t = sh_strvis (t_string); | |
8261 | temp = sh_backslash_quote_for_double_quotes (t, 0); | |
8262 | free (t); | |
8263 | } | |
f73dda09 | 8264 | else |
74091dd4 | 8265 | temp = sh_strvis (t_string); |
726f6388 | 8266 | |
f73dda09 JA |
8267 | goto add_string; |
8268 | } | |
726f6388 | 8269 | |
f73dda09 JA |
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; | |
726f6388 | 8275 | |
f73dda09 JA |
8276 | case 'h': |
8277 | case 'H': | |
a0c0a00f CR |
8278 | t_host = savestring (current_host_name); |
8279 | if (c == 'h' && (t = (char *)strchr (t_host, '.'))) | |
f73dda09 | 8280 | *t = '\0'; |
a0c0a00f CR |
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. */ | |
74091dd4 | 8285 | temp = sh_backslash_quote_for_double_quotes (t_host, 0); |
a0c0a00f CR |
8286 | else |
8287 | temp = savestring (t_host); | |
8288 | free (t_host); | |
f73dda09 | 8289 | goto add_string; |
726f6388 | 8290 | |
f73dda09 | 8291 | case '#': |
d233b485 CR |
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); | |
f73dda09 | 8298 | goto add_string; |
28ef6c31 | 8299 | |
f73dda09 JA |
8300 | case '!': |
8301 | #if !defined (HISTORY) | |
8302 | temp = savestring ("1"); | |
8303 | #else /* HISTORY */ | |
d233b485 | 8304 | temp = itos (prompt_history_number (orig_string)); |
f73dda09 JA |
8305 | #endif /* HISTORY */ |
8306 | goto add_string; | |
726f6388 | 8307 | |
f73dda09 JA |
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; | |
726f6388 | 8315 | |
f73dda09 JA |
8316 | case 'j': |
8317 | temp = itos (count_all_jobs ()); | |
8318 | goto add_string; | |
28ef6c31 | 8319 | |
f73dda09 JA |
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; | |
726f6388 | 8329 | |
f73dda09 JA |
8330 | #if defined (READLINE) |
8331 | case '[': | |
8332 | case ']': | |
b80f6443 JA |
8333 | if (no_line_editing) |
8334 | { | |
8335 | string++; | |
8336 | break; | |
8337 | } | |
f73dda09 | 8338 | temp = (char *)xmalloc (3); |
0628567a JA |
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'; | |
f73dda09 JA |
8345 | goto add_string; |
8346 | #endif /* READLINE */ | |
ccc6cda3 | 8347 | |
f73dda09 | 8348 | case '\\': |
f73dda09 JA |
8349 | case 'a': |
8350 | case 'e': | |
7117c2d2 | 8351 | case 'r': |
f73dda09 | 8352 | temp = (char *)xmalloc (2); |
7117c2d2 JA |
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; | |
f73dda09 JA |
8361 | temp[1] = '\0'; |
8362 | goto add_string; | |
8363 | ||
8364 | default: | |
7117c2d2 | 8365 | not_escape: |
f73dda09 JA |
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); | |
a0c0a00f CR |
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; | |
f73dda09 JA |
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; | |
0001803f | 8408 | last_comsub_pid = last_command_subst_pid; |
3185942a | 8409 | list = expand_prompt_string (result, Q_DOUBLE_QUOTES, 0); |
f73dda09 JA |
8410 | free (result); |
8411 | result = string_list (list); | |
8412 | dispose_words (list); | |
8413 | last_command_exit_value = last_exit_value; | |
0001803f | 8414 | last_command_subst_pid = last_comsub_pid; |
f73dda09 JA |
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 | ||
7117c2d2 JA |
8428 | /************************************************ |
8429 | * * | |
8430 | * ERROR HANDLING * | |
8431 | * * | |
8432 | ************************************************/ | |
8433 | ||
f73dda09 JA |
8434 | /* Report a syntax error, and restart the parser. Call here for fatal |
8435 | errors. */ | |
8436 | int | |
8437 | yyerror (msg) | |
8438 | const char *msg; | |
726f6388 | 8439 | { |
74091dd4 CR |
8440 | if ((parser_state & PST_NOERROR) == 0) |
8441 | report_syntax_error ((char *)NULL); | |
f73dda09 JA |
8442 | reset_parser (); |
8443 | return (0); | |
8444 | } | |
8445 | ||
7117c2d2 | 8446 | static char * |
0628567a JA |
8447 | error_token_from_token (tok) |
8448 | int tok; | |
7117c2d2 JA |
8449 | { |
8450 | char *t; | |
8451 | ||
0628567a | 8452 | if (t = find_token_in_alist (tok, word_token_alist, 0)) |
7117c2d2 JA |
8453 | return t; |
8454 | ||
0628567a | 8455 | if (t = find_token_in_alist (tok, other_token_alist, 0)) |
7117c2d2 JA |
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 | ||
f73dda09 JA |
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; | |
726f6388 | 8550 | { |
495aee44 | 8551 | char *msg, *p; |
f73dda09 JA |
8552 | |
8553 | if (message) | |
8554 | { | |
8555 | parser_error (line_number, "%s", message); | |
8556 | if (interactive && EOF_Reached) | |
8557 | EOF_Reached = 0; | |
8868edaf CR |
8558 | last_command_exit_value = (executing_builtin && parse_and_execute_level) ? EX_BADSYNTAX : EX_BADUSAGE; |
8559 | set_pipestatus_from_exit (last_command_exit_value); | |
f73dda09 JA |
8560 | return; |
8561 | } | |
8562 | ||
8563 | /* If the line of input we're reading is not null, try to find the | |
7117c2d2 JA |
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))) | |
f73dda09 | 8567 | { |
495aee44 CR |
8568 | if (ansic_shouldquote (msg)) |
8569 | { | |
8570 | p = ansic_quote (msg, 0, NULL); | |
8571 | free (msg); | |
8572 | msg = p; | |
8573 | } | |
b80f6443 | 8574 | parser_error (line_number, _("syntax error near unexpected token `%s'"), msg); |
7117c2d2 | 8575 | free (msg); |
f73dda09 | 8576 | |
7117c2d2 JA |
8577 | if (interactive == 0) |
8578 | print_offending_line (); | |
f73dda09 | 8579 | |
8868edaf CR |
8580 | last_command_exit_value = (executing_builtin && parse_and_execute_level) ? EX_BADSYNTAX : EX_BADUSAGE; |
8581 | set_pipestatus_from_exit (last_command_exit_value); | |
7117c2d2 JA |
8582 | return; |
8583 | } | |
f73dda09 | 8584 | |
7117c2d2 JA |
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) | |
f73dda09 | 8592 | { |
b80f6443 | 8593 | parser_error (line_number, _("syntax error near `%s'"), msg); |
7117c2d2 | 8594 | free (msg); |
f73dda09 JA |
8595 | } |
8596 | ||
8597 | /* If not interactive, print the line containing the error. */ | |
8598 | if (interactive == 0) | |
7117c2d2 | 8599 | print_offending_line (); |
f73dda09 JA |
8600 | } |
8601 | else | |
8602 | { | |
74091dd4 CR |
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 | ||
f73dda09 JA |
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 | } | |
7117c2d2 | 8617 | |
8868edaf CR |
8618 | last_command_exit_value = (executing_builtin && parse_and_execute_level) ? EX_BADSYNTAX : EX_BADUSAGE; |
8619 | set_pipestatus_from_exit (last_command_exit_value); | |
f73dda09 JA |
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. | |
7117c2d2 | 8626 | (dispose_command () will actually free the command.) */ |
f73dda09 JA |
8627 | static void |
8628 | discard_parser_constructs (error_p) | |
8629 | int error_p; | |
28ef6c31 | 8630 | { |
f73dda09 JA |
8631 | } |
8632 | ||
7117c2d2 JA |
8633 | /************************************************ |
8634 | * * | |
8635 | * EOF HANDLING * | |
8636 | * * | |
8637 | ************************************************/ | |
8638 | ||
f73dda09 JA |
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 () | |
28ef6c31 | 8658 | { |
f73dda09 JA |
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 | { | |
b80f6443 | 8672 | fprintf (stderr, _("Use \"%s\" to leave the shell.\n"), |
f73dda09 JA |
8673 | login_shell ? "logout" : "exit"); |
8674 | eof_encountered++; | |
7117c2d2 JA |
8675 | /* Reset the parsing state. */ |
8676 | last_read_token = current_token = '\n'; | |
f73dda09 JA |
8677 | /* Reset the prompt string to be $PS1. */ |
8678 | prompt_string_pointer = (char **)NULL; | |
74091dd4 | 8679 | prompt_again (0); |
f73dda09 JA |
8680 | return; |
8681 | } | |
8682 | } | |
8683 | ||
8684 | /* In this case EOF should exit the shell. Do it now. */ | |
8685 | reset_parser (); | |
8868edaf CR |
8686 | |
8687 | last_shell_builtin = this_shell_builtin; | |
8688 | this_shell_builtin = exit_builtin; | |
f73dda09 | 8689 | exit_builtin ((WORD_LIST *)NULL); |
726f6388 | 8690 | } |
f73dda09 | 8691 | else |
726f6388 | 8692 | { |
f73dda09 JA |
8693 | /* We don't write history files, etc., for non-interactive shells. */ |
8694 | EOF_Reached = 1; | |
8695 | } | |
8696 | } | |
8697 | ||
7117c2d2 JA |
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 | ||
f73dda09 JA |
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 * | |
b80f6443 | 8712 | parse_string_to_word_list (s, flags, whom) |
f73dda09 | 8713 | char *s; |
b80f6443 | 8714 | int flags; |
f73dda09 JA |
8715 | const char *whom; |
8716 | { | |
8717 | WORD_LIST *wl; | |
74091dd4 CR |
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); | |
f73dda09 JA |
8725 | |
8726 | #if defined (HISTORY) | |
f73dda09 | 8727 | bash_history_disable (); |
bb70624e | 8728 | #endif |
f73dda09 | 8729 | |
f73dda09 | 8730 | push_stream (1); |
8868edaf CR |
8731 | if (ea = expanding_alias ()) |
8732 | parser_save_alias (); | |
74091dd4 CR |
8733 | |
8734 | /* WORD to avoid parsing reserved words as themselves and just parse them as | |
8735 | WORDs. */ | |
8736 | last_read_token = WORD; | |
8737 | ||
f73dda09 | 8738 | current_command_line_count = 0; |
7117c2d2 | 8739 | echo_input_at_read = expand_aliases = 0; |
f73dda09 JA |
8740 | |
8741 | with_input_from_string (s, whom); | |
8742 | wl = (WORD_LIST *)NULL; | |
b80f6443 JA |
8743 | |
8744 | if (flags & 1) | |
74091dd4 CR |
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. */ | |
8c9524f9 | 8750 | parser_state |= PST_COMPASSIGN|PST_REPARSE|PST_STRING; |
74091dd4 | 8751 | } |
b80f6443 | 8752 | |
f73dda09 JA |
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; | |
7117c2d2 JA |
8762 | orig_current_token = current_token; |
8763 | current_token = tok; | |
95732b49 | 8764 | yyerror (NULL); /* does the right thing */ |
7117c2d2 | 8765 | current_token = orig_current_token; |
f73dda09 JA |
8766 | if (wl) |
8767 | dispose_words (wl); | |
8768 | wl = &parse_string_error; | |
8769 | break; | |
8770 | } | |
8771 | wl = make_word_list (yylval.word, wl); | |
bb70624e | 8772 | } |
f73dda09 JA |
8773 | |
8774 | last_read_token = '\n'; | |
8775 | pop_stream (); | |
8776 | ||
8868edaf CR |
8777 | if (ea) |
8778 | parser_restore_alias (); | |
8868edaf | 8779 | |
74091dd4 | 8780 | restore_parser_state (&ps); |
f73dda09 | 8781 | |
b80f6443 | 8782 | if (flags & 1) |
74091dd4 | 8783 | parser_state = orig_parser_state; /* XXX - not needed? */ |
b80f6443 | 8784 | |
f73dda09 | 8785 | if (wl == &parse_string_error) |
bb70624e | 8786 | { |
8868edaf | 8787 | set_exit_status (EXECUTION_FAILURE); |
f73dda09 JA |
8788 | if (interactive_shell == 0 && posixly_correct) |
8789 | jump_to_top_level (FORCE_EOF); | |
8790 | else | |
8791 | jump_to_top_level (DISCARD); | |
bb70624e | 8792 | } |
f73dda09 JA |
8793 | |
8794 | return (REVERSE_LIST (wl, WORD_LIST *)); | |
bb70624e | 8795 | } |
7117c2d2 JA |
8796 | |
8797 | static char * | |
8798 | parse_compound_assignment (retlenp) | |
8799 | int *retlenp; | |
8800 | { | |
8801 | WORD_LIST *wl, *rl; | |
74091dd4 CR |
8802 | int tok, orig_line_number, assignok; |
8803 | sh_parser_state_t ps; | |
8804 | char *ret; | |
7117c2d2 | 8805 | |
7117c2d2 | 8806 | orig_line_number = line_number; |
74091dd4 | 8807 | save_parser_state (&ps); |
7117c2d2 | 8808 | |
74091dd4 CR |
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; | |
7117c2d2 JA |
8813 | |
8814 | token = (char *)NULL; | |
8815 | token_buffer_size = 0; | |
74091dd4 | 8816 | wl = (WORD_LIST *)NULL; /* ( */ |
7117c2d2 | 8817 | |
0628567a JA |
8818 | assignok = parser_state&PST_ASSIGNOK; /* XXX */ |
8819 | ||
74091dd4 CR |
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. */ | |
b80f6443 JA |
8823 | parser_state |= PST_COMPASSIGN; |
8824 | ||
74091dd4 CR |
8825 | esacs_needed_count = expecting_in_token = 0; |
8826 | ||
7117c2d2 JA |
8827 | while ((tok = read_token (READ)) != ')') |
8828 | { | |
8829 | if (tok == '\n') /* Allow newlines in compound assignments */ | |
b80f6443 JA |
8830 | { |
8831 | if (SHOULD_PROMPT ()) | |
74091dd4 | 8832 | prompt_again (0); |
b80f6443 JA |
8833 | continue; |
8834 | } | |
7117c2d2 JA |
8835 | if (tok != WORD && tok != ASSIGNMENT_WORD) |
8836 | { | |
8837 | current_token = tok; /* for error reporting */ | |
8838 | if (tok == yacc_EOF) /* ( */ | |
b80f6443 | 8839 | parser_error (orig_line_number, _("unexpected EOF while looking for matching `)'")); |
7117c2d2 | 8840 | else |
95732b49 | 8841 | yyerror(NULL); /* does the right thing */ |
7117c2d2 JA |
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 | ||
74091dd4 | 8850 | restore_parser_state (&ps); |
b80f6443 | 8851 | |
7117c2d2 JA |
8852 | if (wl == &parse_string_error) |
8853 | { | |
8868edaf | 8854 | set_exit_status (EXECUTION_FAILURE); |
7117c2d2 JA |
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 | ||
7117c2d2 JA |
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; | |
0628567a JA |
8873 | |
8874 | if (assignok) | |
8875 | parser_state |= PST_ASSIGNOK; | |
8876 | ||
7117c2d2 JA |
8877 | return ret; |
8878 | } | |
8879 | ||
b80f6443 JA |
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 | { | |
b80f6443 | 8890 | if (ps == 0) |
95732b49 | 8891 | ps = (sh_parser_state_t *)xmalloc (sizeof (sh_parser_state_t)); |
b80f6443 JA |
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; | |
74091dd4 | 8900 | ps->eol_lookahead = eol_ungetc_lookahead; |
b80f6443 | 8901 | |
495aee44 CR |
8902 | ps->prompt_string_pointer = prompt_string_pointer; |
8903 | ||
b80f6443 JA |
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) | |
495aee44 | 8915 | ps->pipestatus = save_pipestatus_array (); |
b80f6443 JA |
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; | |
daefb2c5 | 8923 | ps->need_here_doc = need_here_doc; |
a0c0a00f CR |
8924 | ps->here_doc_first_line = here_doc_first_line; |
8925 | ||
74091dd4 CR |
8926 | ps->esacs_needed = esacs_needed_count; |
8927 | ps->expecting_in = expecting_in_token; | |
8928 | ||
a0c0a00f CR |
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); | |
b80f6443 | 8933 | |
74091dd4 CR |
8934 | #if defined (ALIAS) || defined (DPAREN_ARITHMETIC) |
8935 | ps->pushed_strings = pushed_string_list; | |
8936 | #endif | |
8937 | ||
8938 | ps->eof_token = shell_eof_token; | |
509a4430 CR |
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 | ||
b80f6443 JA |
8945 | return (ps); |
8946 | } | |
8947 | ||
8948 | void | |
8949 | restore_parser_state (ps) | |
8950 | sh_parser_state_t *ps; | |
8951 | { | |
a0c0a00f CR |
8952 | int i; |
8953 | ||
b80f6443 JA |
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; | |
74091dd4 | 8966 | eol_ungetc_lookahead = ps->eol_lookahead; |
b80f6443 | 8967 | |
495aee44 CR |
8968 | prompt_string_pointer = ps->prompt_string_pointer; |
8969 | ||
b80f6443 JA |
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) | |
495aee44 | 8981 | restore_pipestatus_array (ps->pipestatus); |
b80f6443 JA |
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; | |
daefb2c5 | 8989 | need_here_doc = ps->need_here_doc; |
a0c0a00f CR |
8990 | here_doc_first_line = ps->here_doc_first_line; |
8991 | ||
74091dd4 CR |
8992 | esacs_needed_count = ps->esacs_needed; |
8993 | expecting_in_token = ps->expecting_in; | |
8994 | ||
a0c0a00f CR |
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 | |
509a4430 | 9004 | |
74091dd4 CR |
9005 | #if defined (ALIAS) || defined (DPAREN_ARITHMETIC) |
9006 | pushed_string_list = (STRING_SAVER *)ps->pushed_strings; | |
9007 | #endif | |
9008 | ||
509a4430 CR |
9009 | FREE (token); |
9010 | token = ps->token; | |
9011 | token_buffer_size = ps->token_buffer_size; | |
74091dd4 | 9012 | shell_eof_token = ps->eof_token; |
509a4430 CR |
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 | ||
8868edaf CR |
9029 | #if defined (HANDLE_MULTIBYTE) |
9030 | ls->input_property = shell_input_line_property; | |
9031 | ls->input_propsize = shell_input_line_propsize; | |
9032 | #endif | |
9033 | ||
509a4430 CR |
9034 | /* force reallocation */ |
9035 | shell_input_line = 0; | |
9036 | shell_input_line_size = shell_input_line_len = shell_input_line_index = 0; | |
ac50fbac | 9037 | |
8868edaf CR |
9038 | #if defined (HANDLE_MULTIBYTE) |
9039 | shell_input_line_property = 0; | |
9040 | shell_input_line_propsize = 0; | |
9041 | #endif | |
9042 | ||
ac50fbac | 9043 | return ls; |
509a4430 CR |
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 | ||
8868edaf CR |
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 | |
509a4430 | 9063 | set_line_mbstate (); |
8868edaf | 9064 | #endif |
b80f6443 JA |
9065 | } |
9066 | ||
7117c2d2 JA |
9067 | /************************************************ |
9068 | * * | |
9069 | * MULTIBYTE CHARACTER HANDLING * | |
9070 | * * | |
9071 | ************************************************/ | |
9072 | ||
9073 | #if defined (HANDLE_MULTIBYTE) | |
d233b485 CR |
9074 | |
9075 | /* We don't let the property buffer get larger than this unless the line is */ | |
9076 | #define MAX_PROPSIZE 32768 | |
9077 | ||
7117c2d2 JA |
9078 | static void |
9079 | set_line_mbstate () | |
9080 | { | |
ac50fbac CR |
9081 | int c; |
9082 | size_t i, previ, len; | |
7117c2d2 JA |
9083 | mbstate_t mbs, prevs; |
9084 | size_t mbclen; | |
8868edaf | 9085 | int ilen; |
7117c2d2 JA |
9086 | |
9087 | if (shell_input_line == NULL) | |
9088 | return; | |
8868edaf | 9089 | len = STRLEN (shell_input_line); /* XXX - shell_input_line_len ? */ |
d233b485 CR |
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 | } | |
7117c2d2 | 9103 | |
8868edaf CR |
9104 | if (locale_mb_cur_max == 1) |
9105 | { | |
9106 | memset (shell_input_line_property, 1, len); | |
9107 | return; | |
9108 | } | |
9109 | ||
d233b485 CR |
9110 | /* XXX - use whether or not we are in a UTF-8 locale to avoid calls to |
9111 | mbrlen */ | |
8868edaf CR |
9112 | if (locale_utf8locale == 0) |
9113 | memset (&prevs, '\0', sizeof (mbstate_t)); | |
9114 | ||
7117c2d2 JA |
9115 | for (i = previ = 0; i < len; i++) |
9116 | { | |
8868edaf CR |
9117 | if (locale_utf8locale == 0) |
9118 | mbs = prevs; | |
7117c2d2 | 9119 | |
b80f6443 JA |
9120 | c = shell_input_line[i]; |
9121 | if (c == EOF) | |
7117c2d2 | 9122 | { |
ac50fbac | 9123 | size_t j; |
7117c2d2 JA |
9124 | for (j = i; j < len; j++) |
9125 | shell_input_line_property[j] = 1; | |
9126 | break; | |
9127 | } | |
9128 | ||
8868edaf CR |
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 | ||
7117c2d2 JA |
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; | |
8868edaf CR |
9154 | if (locale_utf8locale == 0) |
9155 | prevs = mbs; | |
7117c2d2 JA |
9156 | } |
9157 | else | |
9158 | { | |
ac50fbac | 9159 | size_t j; |
b80f6443 JA |
9160 | for (j = i; j < len; j++) |
9161 | shell_input_line_property[j] = 1; | |
9162 | break; | |
7117c2d2 JA |
9163 | } |
9164 | ||
9165 | shell_input_line_property[i] = mbclen; | |
9166 | } | |
9167 | } | |
9168 | #endif /* HANDLE_MULTIBYTE */ |