]>
Commit | Line | Data |
---|---|---|
3185942a | 1 | /* A Bison parser, made by GNU Bison 2.3. */ |
b80f6443 | 2 | |
3185942a | 3 | /* Skeleton implementation for Bison's Yacc-like parsers in C |
b80f6443 | 4 | |
3185942a JA |
5 | Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006 |
6 | Free Software Foundation, Inc. | |
7 | ||
8 | This program is free software; you can redistribute it and/or modify | |
9 | it under the terms of the GNU General Public License as published by | |
10 | the Free Software Foundation; either version 2, or (at your option) | |
11 | any later version. | |
12 | ||
13 | This program is distributed in the hope that it will be useful, | |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | GNU General Public License for more details. | |
17 | ||
18 | You should have received a copy of the GNU General Public License | |
19 | along with this program; if not, write to the Free Software | |
20 | Foundation, Inc., 51 Franklin Street, Fifth Floor, | |
21 | Boston, MA 02110-1301, USA. */ | |
22 | ||
23 | /* As a special exception, you may create a larger work that contains | |
24 | part or all of the Bison parser skeleton and distribute that work | |
25 | under terms of your choice, so long as that work isn't itself a | |
26 | parser generator using the skeleton or a modified version thereof | |
27 | as a parser skeleton. Alternatively, if you modify or redistribute | |
28 | the parser skeleton itself, you may (at your option) remove this | |
29 | special exception, which will cause the skeleton and the resulting | |
30 | Bison output files to be licensed under the GNU General Public | |
31 | License without this special exception. | |
32 | ||
33 | This special exception was added by the Free Software Foundation in | |
34 | version 2.2 of Bison. */ | |
35 | ||
36 | /* C LALR(1) parser skeleton written by Richard Stallman, by | |
37 | simplifying the original so-called "semantic" parser. */ | |
38 | ||
39 | /* All symbols defined below should begin with yy or YY, to avoid | |
40 | infringing on user name space. This should be done even for local | |
41 | variables, as they might otherwise be expanded by user macros. | |
42 | There are some unavoidable exceptions within include files to | |
43 | define necessary library symbols; they are noted "INFRINGES ON | |
44 | USER NAME SPACE" below. */ | |
45 | ||
46 | /* Identify Bison output. */ | |
47 | #define YYBISON 1 | |
48 | ||
49 | /* Bison version. */ | |
50 | #define YYBISON_VERSION "2.3" | |
51 | ||
52 | /* Skeleton name. */ | |
53 | #define YYSKELETON_NAME "yacc.c" | |
54 | ||
55 | /* Pure parsers. */ | |
56 | #define YYPURE 0 | |
57 | ||
58 | /* Using locations. */ | |
59 | #define YYLSP_NEEDED 0 | |
60 | ||
61 | ||
62 | ||
63 | /* Tokens. */ | |
64 | #ifndef YYTOKENTYPE | |
65 | # define YYTOKENTYPE | |
66 | /* Put the tokens into the symbol table, so that GDB and other debuggers | |
67 | know about them. */ | |
68 | enum yytokentype { | |
69 | IF = 258, | |
70 | THEN = 259, | |
71 | ELSE = 260, | |
72 | ELIF = 261, | |
73 | FI = 262, | |
74 | CASE = 263, | |
75 | ESAC = 264, | |
76 | FOR = 265, | |
77 | SELECT = 266, | |
78 | WHILE = 267, | |
79 | UNTIL = 268, | |
80 | DO = 269, | |
81 | DONE = 270, | |
82 | FUNCTION = 271, | |
83 | COPROC = 272, | |
84 | COND_START = 273, | |
85 | COND_END = 274, | |
86 | COND_ERROR = 275, | |
87 | IN = 276, | |
88 | BANG = 277, | |
89 | TIME = 278, | |
90 | TIMEOPT = 279, | |
495aee44 CR |
91 | TIMEIGN = 280, |
92 | WORD = 281, | |
93 | ASSIGNMENT_WORD = 282, | |
94 | REDIR_WORD = 283, | |
95 | NUMBER = 284, | |
96 | ARITH_CMD = 285, | |
97 | ARITH_FOR_EXPRS = 286, | |
98 | COND_CMD = 287, | |
99 | AND_AND = 288, | |
100 | OR_OR = 289, | |
101 | GREATER_GREATER = 290, | |
102 | LESS_LESS = 291, | |
103 | LESS_AND = 292, | |
104 | LESS_LESS_LESS = 293, | |
105 | GREATER_AND = 294, | |
106 | SEMI_SEMI = 295, | |
107 | SEMI_AND = 296, | |
108 | SEMI_SEMI_AND = 297, | |
109 | LESS_LESS_MINUS = 298, | |
110 | AND_GREATER = 299, | |
111 | AND_GREATER_GREATER = 300, | |
112 | LESS_GREATER = 301, | |
113 | GREATER_BAR = 302, | |
114 | BAR_AND = 303, | |
115 | yacc_EOF = 304 | |
3185942a JA |
116 | }; |
117 | #endif | |
118 | /* Tokens. */ | |
119 | #define IF 258 | |
120 | #define THEN 259 | |
121 | #define ELSE 260 | |
122 | #define ELIF 261 | |
123 | #define FI 262 | |
124 | #define CASE 263 | |
125 | #define ESAC 264 | |
126 | #define FOR 265 | |
127 | #define SELECT 266 | |
128 | #define WHILE 267 | |
129 | #define UNTIL 268 | |
130 | #define DO 269 | |
131 | #define DONE 270 | |
132 | #define FUNCTION 271 | |
133 | #define COPROC 272 | |
134 | #define COND_START 273 | |
135 | #define COND_END 274 | |
136 | #define COND_ERROR 275 | |
137 | #define IN 276 | |
138 | #define BANG 277 | |
139 | #define TIME 278 | |
140 | #define TIMEOPT 279 | |
495aee44 CR |
141 | #define TIMEIGN 280 |
142 | #define WORD 281 | |
143 | #define ASSIGNMENT_WORD 282 | |
144 | #define REDIR_WORD 283 | |
145 | #define NUMBER 284 | |
146 | #define ARITH_CMD 285 | |
147 | #define ARITH_FOR_EXPRS 286 | |
148 | #define COND_CMD 287 | |
149 | #define AND_AND 288 | |
150 | #define OR_OR 289 | |
151 | #define GREATER_GREATER 290 | |
152 | #define LESS_LESS 291 | |
153 | #define LESS_AND 292 | |
154 | #define LESS_LESS_LESS 293 | |
155 | #define GREATER_AND 294 | |
156 | #define SEMI_SEMI 295 | |
157 | #define SEMI_AND 296 | |
158 | #define SEMI_SEMI_AND 297 | |
159 | #define LESS_LESS_MINUS 298 | |
160 | #define AND_GREATER 299 | |
161 | #define AND_GREATER_GREATER 300 | |
162 | #define LESS_GREATER 301 | |
163 | #define GREATER_BAR 302 | |
164 | #define BAR_AND 303 | |
165 | #define yacc_EOF 304 | |
3185942a JA |
166 | |
167 | ||
168 | ||
169 | ||
170 | /* Copy the first part of user declarations. */ | |
0628567a | 171 | #line 21 "/Users/chet/src/bash/src/parse.y" |
f73dda09 | 172 | |
ccc6cda3 JA |
173 | #include "config.h" |
174 | ||
726f6388 | 175 | #include "bashtypes.h" |
726f6388 | 176 | #include "bashansi.h" |
ccc6cda3 | 177 | |
28ef6c31 JA |
178 | #include "filecntl.h" |
179 | ||
ccc6cda3 JA |
180 | #if defined (HAVE_UNISTD_H) |
181 | # include <unistd.h> | |
182 | #endif | |
183 | ||
184 | #if defined (HAVE_LOCALE_H) | |
185 | # include <locale.h> | |
186 | #endif | |
187 | ||
188 | #include <stdio.h> | |
f73dda09 | 189 | #include "chartypes.h" |
ccc6cda3 JA |
190 | #include <signal.h> |
191 | ||
192 | #include "memalloc.h" | |
193 | ||
b80f6443 JA |
194 | #include "bashintl.h" |
195 | ||
7117c2d2 JA |
196 | #define NEED_STRFTIME_DECL /* used in externs.h */ |
197 | ||
726f6388 | 198 | #include "shell.h" |
ccc6cda3 | 199 | #include "trap.h" |
726f6388 | 200 | #include "flags.h" |
ccc6cda3 JA |
201 | #include "parser.h" |
202 | #include "mailcheck.h" | |
f73dda09 | 203 | #include "test.h" |
95732b49 | 204 | #include "builtins.h" |
ccc6cda3 JA |
205 | #include "builtins/common.h" |
206 | #include "builtins/builtext.h" | |
726f6388 | 207 | |
7117c2d2 JA |
208 | #include "shmbutil.h" |
209 | ||
726f6388 | 210 | #if defined (READLINE) |
ccc6cda3 | 211 | # include "bashline.h" |
726f6388 JA |
212 | # include <readline/readline.h> |
213 | #endif /* READLINE */ | |
214 | ||
215 | #if defined (HISTORY) | |
216 | # include "bashhist.h" | |
217 | # include <readline/history.h> | |
218 | #endif /* HISTORY */ | |
219 | ||
220 | #if defined (JOB_CONTROL) | |
221 | # include "jobs.h" | |
222 | #endif /* JOB_CONTROL */ | |
223 | ||
224 | #if defined (ALIAS) | |
225 | # include "alias.h" | |
b80f6443 JA |
226 | #else |
227 | typedef void *alias_t; | |
726f6388 JA |
228 | #endif /* ALIAS */ |
229 | ||
230 | #if defined (PROMPT_STRING_DECODE) | |
cce855bc JA |
231 | # ifndef _MINIX |
232 | # include <sys/param.h> | |
233 | # endif | |
234 | # include <time.h> | |
7117c2d2 JA |
235 | # if defined (TM_IN_SYS_TIME) |
236 | # include <sys/types.h> | |
237 | # include <sys/time.h> | |
238 | # endif /* TM_IN_SYS_TIME */ | |
cce855bc | 239 | # include "maxpath.h" |
726f6388 JA |
240 | #endif /* PROMPT_STRING_DECODE */ |
241 | ||
ccc6cda3 JA |
242 | #define RE_READ_TOKEN -99 |
243 | #define NO_EXPANSION -100 | |
244 | ||
7117c2d2 JA |
245 | #ifdef DEBUG |
246 | # define YYDEBUG 1 | |
247 | #else | |
248 | # define YYDEBUG 0 | |
249 | #endif | |
250 | ||
251 | #if defined (HANDLE_MULTIBYTE) | |
252 | # define last_shell_getc_is_singlebyte \ | |
253 | ((shell_input_line_index > 1) \ | |
254 | ? shell_input_line_property[shell_input_line_index - 1] \ | |
255 | : 1) | |
256 | # define MBTEST(x) ((x) && last_shell_getc_is_singlebyte) | |
257 | #else | |
258 | # define last_shell_getc_is_singlebyte 1 | |
259 | # define MBTEST(x) ((x)) | |
260 | #endif | |
ccc6cda3 | 261 | |
cce855bc | 262 | #if defined (EXTENDED_GLOB) |
cce855bc JA |
263 | extern int extended_glob; |
264 | #endif | |
265 | ||
726f6388 | 266 | extern int eof_encountered; |
ccc6cda3 | 267 | extern int no_line_editing, running_under_emacs; |
726f6388 | 268 | extern int current_command_number; |
3185942a | 269 | extern int sourcelevel, parse_and_execute_level; |
726f6388 JA |
270 | extern int posixly_correct; |
271 | extern int last_command_exit_value; | |
0001803f | 272 | extern pid_t last_command_subst_pid; |
726f6388 | 273 | extern char *shell_name, *current_host_name; |
ccc6cda3 JA |
274 | extern char *dist_version; |
275 | extern int patch_level; | |
cce855bc | 276 | extern int dump_translatable_strings, dump_po_strings; |
f73dda09 | 277 | extern sh_builtin_func_t *last_shell_builtin, *this_shell_builtin; |
726f6388 JA |
278 | #if defined (BUFFERED_INPUT) |
279 | extern int bash_input_fd_changed; | |
280 | #endif | |
281 | ||
bb70624e | 282 | extern int errno; |
726f6388 JA |
283 | /* **************************************************************** */ |
284 | /* */ | |
285 | /* "Forward" declarations */ | |
286 | /* */ | |
287 | /* **************************************************************** */ | |
288 | ||
f73dda09 JA |
289 | #ifdef DEBUG |
290 | static void debug_parser __P((int)); | |
291 | #endif | |
292 | ||
293 | static int yy_getc __P((void)); | |
294 | static int yy_ungetc __P((int)); | |
295 | ||
296 | #if defined (READLINE) | |
297 | static int yy_readline_get __P((void)); | |
298 | static int yy_readline_unget __P((int)); | |
299 | #endif | |
300 | ||
301 | static int yy_string_get __P((void)); | |
302 | static int yy_string_unget __P((int)); | |
3185942a | 303 | static void rewind_input_string __P((void)); |
f73dda09 JA |
304 | static int yy_stream_get __P((void)); |
305 | static int yy_stream_unget __P((int)); | |
306 | ||
307 | static int shell_getc __P((int)); | |
308 | static void shell_ungetc __P((int)); | |
309 | static void discard_until __P((int)); | |
310 | ||
311 | #if defined (ALIAS) || defined (DPAREN_ARITHMETIC) | |
312 | static void push_string __P((char *, int, alias_t *)); | |
313 | static void pop_string __P((void)); | |
314 | static void free_string_list __P((void)); | |
315 | #endif | |
316 | ||
317 | static char *read_a_line __P((int)); | |
318 | ||
f73dda09 JA |
319 | static int reserved_word_acceptable __P((int)); |
320 | static int yylex __P((void)); | |
321 | static int alias_expand_token __P((char *)); | |
322 | static int time_command_acceptable __P((void)); | |
323 | static int special_case_tokens __P((char *)); | |
324 | static int read_token __P((int)); | |
325 | static char *parse_matched_pair __P((int, int, int, int *, int)); | |
3185942a | 326 | static char *parse_comsub __P((int, int, int, int *, int)); |
7117c2d2 JA |
327 | #if defined (ARRAY_VARS) |
328 | static char *parse_compound_assignment __P((int *)); | |
329 | #endif | |
f73dda09 | 330 | #if defined (DPAREN_ARITHMETIC) || defined (ARITH_FOR_COMMAND) |
7117c2d2 | 331 | static int parse_dparen __P((int)); |
b80f6443 | 332 | static int parse_arith_cmd __P((char **, int)); |
f73dda09 | 333 | #endif |
cce855bc | 334 | #if defined (COND_COMMAND) |
7117c2d2 | 335 | static void cond_error __P((void)); |
f73dda09 JA |
336 | static COND_COM *cond_expr __P((void)); |
337 | static COND_COM *cond_or __P((void)); | |
338 | static COND_COM *cond_and __P((void)); | |
339 | static COND_COM *cond_term __P((void)); | |
340 | static int cond_skip_newlines __P((void)); | |
341 | static COMMAND *parse_cond_command __P((void)); | |
cce855bc | 342 | #endif |
7117c2d2 JA |
343 | #if defined (ARRAY_VARS) |
344 | static int token_is_assignment __P((char *, int)); | |
345 | static int token_is_ident __P((char *, int)); | |
346 | #endif | |
f73dda09 JA |
347 | static int read_token_word __P((int)); |
348 | static void discard_parser_constructs __P((int)); | |
726f6388 | 349 | |
7117c2d2 JA |
350 | static char *error_token_from_token __P((int)); |
351 | static char *error_token_from_text __P((void)); | |
352 | static void print_offending_line __P((void)); | |
f73dda09 | 353 | static void report_syntax_error __P((char *)); |
7117c2d2 | 354 | |
f73dda09 JA |
355 | static void handle_eof_input_unit __P((void)); |
356 | static void prompt_again __P((void)); | |
d166f048 | 357 | #if 0 |
f73dda09 | 358 | static void reset_readline_prompt __P((void)); |
d166f048 | 359 | #endif |
f73dda09 | 360 | static void print_prompt __P((void)); |
726f6388 | 361 | |
7117c2d2 JA |
362 | #if defined (HANDLE_MULTIBYTE) |
363 | static void set_line_mbstate __P((void)); | |
364 | static char *shell_input_line_property = NULL; | |
365 | #else | |
366 | # define set_line_mbstate() | |
367 | #endif | |
368 | ||
f73dda09 | 369 | extern int yyerror __P((const char *)); |
d166f048 | 370 | |
7117c2d2 JA |
371 | #ifdef DEBUG |
372 | extern int yydebug; | |
373 | #endif | |
374 | ||
ccc6cda3 JA |
375 | /* Default prompt strings */ |
376 | char *primary_prompt = PPROMPT; | |
377 | char *secondary_prompt = SPROMPT; | |
378 | ||
726f6388 JA |
379 | /* PROMPT_STRING_POINTER points to one of these, never to an actual string. */ |
380 | char *ps1_prompt, *ps2_prompt; | |
381 | ||
382 | /* Handle on the current prompt string. Indirectly points through | |
383 | ps1_ or ps2_prompt. */ | |
384 | char **prompt_string_pointer = (char **)NULL; | |
385 | char *current_prompt_string; | |
386 | ||
ccc6cda3 JA |
387 | /* Non-zero means we expand aliases in commands. */ |
388 | int expand_aliases = 0; | |
389 | ||
390 | /* If non-zero, the decoded prompt string undergoes parameter and | |
391 | variable substitution, command substitution, arithmetic substitution, | |
392 | string expansion, process substitution, and quote removal in | |
393 | decode_prompt_string. */ | |
394 | int promptvars = 1; | |
395 | ||
b80f6443 JA |
396 | /* If non-zero, $'...' and $"..." are expanded when they appear within |
397 | a ${...} expansion, even when the expansion appears within double | |
398 | quotes. */ | |
399 | int extended_quote = 1; | |
400 | ||
726f6388 | 401 | /* The number of lines read from input while creating the current command. */ |
ccc6cda3 | 402 | int current_command_line_count; |
726f6388 | 403 | |
495aee44 CR |
404 | /* The number of lines in a command saved while we run parse_and_execute */ |
405 | int saved_command_line_count; | |
406 | ||
3185942a JA |
407 | /* The token that currently denotes the end of parse. */ |
408 | int shell_eof_token; | |
409 | ||
410 | /* The token currently being read. */ | |
411 | int current_token; | |
412 | ||
0001803f CR |
413 | /* The current parser state. */ |
414 | int parser_state; | |
415 | ||
726f6388 JA |
416 | /* Variables to manage the task of reading here documents, because we need to |
417 | defer the reading until after a complete command has been collected. */ | |
418 | static REDIRECT *redir_stack[10]; | |
ccc6cda3 | 419 | int need_here_doc; |
726f6388 JA |
420 | |
421 | /* Where shell input comes from. History expansion is performed on each | |
422 | line when the shell is interactive. */ | |
423 | static char *shell_input_line = (char *)NULL; | |
ccc6cda3 JA |
424 | static int shell_input_line_index; |
425 | static int shell_input_line_size; /* Amount allocated for shell_input_line. */ | |
426 | static int shell_input_line_len; /* strlen (shell_input_line) */ | |
726f6388 JA |
427 | |
428 | /* Either zero or EOF. */ | |
ccc6cda3 JA |
429 | static int shell_input_line_terminator; |
430 | ||
431 | /* The line number in a script on which a function definition starts. */ | |
432 | static int function_dstart; | |
433 | ||
434 | /* The line number in a script on which a function body starts. */ | |
435 | static int function_bstart; | |
726f6388 | 436 | |
bb70624e JA |
437 | /* The line number in a script at which an arithmetic for command starts. */ |
438 | static int arith_for_lineno; | |
439 | ||
0001803f CR |
440 | /* The decoded prompt string. Used if READLINE is not defined or if |
441 | editing is turned off. Analogous to current_readline_prompt. */ | |
442 | static char *current_decoded_prompt; | |
3185942a JA |
443 | |
444 | /* The last read token, or NULL. read_token () uses this for context | |
445 | checking. */ | |
446 | static int last_read_token; | |
447 | ||
448 | /* The token read prior to last_read_token. */ | |
449 | static int token_before_that; | |
450 | ||
451 | /* The token read prior to token_before_that. */ | |
452 | static int two_tokens_ago; | |
453 | ||
0001803f CR |
454 | static int global_extglob; |
455 | ||
b80f6443 JA |
456 | /* The line number in a script where the word in a `case WORD', `select WORD' |
457 | or `for WORD' begins. This is a nested command maximum, since the array | |
458 | index is decremented after a case, select, or for command is parsed. */ | |
459 | #define MAX_CASE_NEST 128 | |
460 | static int word_lineno[MAX_CASE_NEST]; | |
461 | static int word_top = -1; | |
462 | ||
463 | /* If non-zero, it is the token that we want read_token to return | |
464 | regardless of what text is (or isn't) present to be read. This | |
465 | is reset by read_token. If token_to_read == WORD or | |
466 | ASSIGNMENT_WORD, yylval.word should be set to word_desc_to_read. */ | |
467 | static int token_to_read; | |
468 | static WORD_DESC *word_desc_to_read; | |
469 | ||
0001803f | 470 | static REDIRECTEE source; |
726f6388 | 471 | static REDIRECTEE redir; |
f73dda09 | 472 | |
3185942a JA |
473 | |
474 | /* Enabling traces. */ | |
475 | #ifndef YYDEBUG | |
476 | # define YYDEBUG 0 | |
477 | #endif | |
478 | ||
479 | /* Enabling verbose error messages. */ | |
480 | #ifdef YYERROR_VERBOSE | |
481 | # undef YYERROR_VERBOSE | |
482 | # define YYERROR_VERBOSE 1 | |
483 | #else | |
484 | # define YYERROR_VERBOSE 0 | |
485 | #endif | |
486 | ||
487 | /* Enabling the token table. */ | |
488 | #ifndef YYTOKEN_TABLE | |
489 | # define YYTOKEN_TABLE 0 | |
490 | #endif | |
491 | ||
492 | #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED | |
493 | typedef union YYSTYPE | |
495aee44 | 494 | #line 323 "/Users/chet/src/bash/src/parse.y" |
3185942a | 495 | { |
726f6388 JA |
496 | WORD_DESC *word; /* the word that we read. */ |
497 | int number; /* the number that we read. */ | |
498 | WORD_LIST *word_list; | |
499 | COMMAND *command; | |
500 | REDIRECT *redirect; | |
501 | ELEMENT element; | |
502 | PATTERN_LIST *pattern; | |
3185942a JA |
503 | } |
504 | /* Line 187 of yacc.c. */ | |
495aee44 | 505 | #line 506 "y.tab.c" |
3185942a JA |
506 | YYSTYPE; |
507 | # define yystype YYSTYPE /* obsolescent; will be withdrawn */ | |
508 | # define YYSTYPE_IS_DECLARED 1 | |
509 | # define YYSTYPE_IS_TRIVIAL 1 | |
510 | #endif | |
511 | ||
512 | ||
513 | ||
514 | /* Copy the second part of user declarations. */ | |
515 | ||
516 | ||
517 | /* Line 216 of yacc.c. */ | |
495aee44 | 518 | #line 519 "y.tab.c" |
b80f6443 | 519 | |
3185942a JA |
520 | #ifdef short |
521 | # undef short | |
f73dda09 | 522 | #endif |
3185942a JA |
523 | |
524 | #ifdef YYTYPE_UINT8 | |
525 | typedef YYTYPE_UINT8 yytype_uint8; | |
526 | #else | |
527 | typedef unsigned char yytype_uint8; | |
f73dda09 JA |
528 | #endif |
529 | ||
3185942a JA |
530 | #ifdef YYTYPE_INT8 |
531 | typedef YYTYPE_INT8 yytype_int8; | |
532 | #elif (defined __STDC__ || defined __C99__FUNC__ \ | |
533 | || defined __cplusplus || defined _MSC_VER) | |
534 | typedef signed char yytype_int8; | |
535 | #else | |
536 | typedef short int yytype_int8; | |
537 | #endif | |
f73dda09 | 538 | |
3185942a JA |
539 | #ifdef YYTYPE_UINT16 |
540 | typedef YYTYPE_UINT16 yytype_uint16; | |
541 | #else | |
542 | typedef unsigned short int yytype_uint16; | |
543 | #endif | |
f73dda09 | 544 | |
3185942a JA |
545 | #ifdef YYTYPE_INT16 |
546 | typedef YYTYPE_INT16 yytype_int16; | |
547 | #else | |
548 | typedef short int yytype_int16; | |
549 | #endif | |
f73dda09 | 550 | |
3185942a JA |
551 | #ifndef YYSIZE_T |
552 | # ifdef __SIZE_TYPE__ | |
553 | # define YYSIZE_T __SIZE_TYPE__ | |
554 | # elif defined size_t | |
555 | # define YYSIZE_T size_t | |
556 | # elif ! defined YYSIZE_T && (defined __STDC__ || defined __C99__FUNC__ \ | |
557 | || defined __cplusplus || defined _MSC_VER) | |
558 | # include <stddef.h> /* INFRINGES ON USER NAME SPACE */ | |
559 | # define YYSIZE_T size_t | |
560 | # else | |
561 | # define YYSIZE_T unsigned int | |
562 | # endif | |
563 | #endif | |
b80f6443 | 564 | |
3185942a | 565 | #define YYSIZE_MAXIMUM ((YYSIZE_T) -1) |
f73dda09 | 566 | |
3185942a JA |
567 | #ifndef YY_ |
568 | # if YYENABLE_NLS | |
569 | # if ENABLE_NLS | |
570 | # include <libintl.h> /* INFRINGES ON USER NAME SPACE */ | |
571 | # define YY_(msgid) dgettext ("bison-runtime", msgid) | |
572 | # endif | |
573 | # endif | |
574 | # ifndef YY_ | |
575 | # define YY_(msgid) msgid | |
576 | # endif | |
f73dda09 JA |
577 | #endif |
578 | ||
3185942a JA |
579 | /* Suppress unused-variable warnings by "using" E. */ |
580 | #if ! defined lint || defined __GNUC__ | |
581 | # define YYUSE(e) ((void) (e)) | |
582 | #else | |
583 | # define YYUSE(e) /* empty */ | |
f73dda09 JA |
584 | #endif |
585 | ||
3185942a JA |
586 | /* Identity function, used to suppress warnings about constant conditions. */ |
587 | #ifndef lint | |
588 | # define YYID(n) (n) | |
589 | #else | |
590 | #if (defined __STDC__ || defined __C99__FUNC__ \ | |
591 | || defined __cplusplus || defined _MSC_VER) | |
592 | static int | |
593 | YYID (int i) | |
594 | #else | |
595 | static int | |
596 | YYID (i) | |
597 | int i; | |
598 | #endif | |
599 | { | |
600 | return i; | |
601 | } | |
602 | #endif | |
603 | ||
604 | #if ! defined yyoverflow || YYERROR_VERBOSE | |
605 | ||
606 | /* The parser invokes alloca or malloc; define the necessary symbols. */ | |
607 | ||
608 | # ifdef YYSTACK_USE_ALLOCA | |
609 | # if YYSTACK_USE_ALLOCA | |
610 | # ifdef __GNUC__ | |
611 | # define YYSTACK_ALLOC __builtin_alloca | |
612 | # elif defined __BUILTIN_VA_ARG_INCR | |
613 | # include <alloca.h> /* INFRINGES ON USER NAME SPACE */ | |
614 | # elif defined _AIX | |
615 | # define YYSTACK_ALLOC __alloca | |
616 | # elif defined _MSC_VER | |
617 | # include <malloc.h> /* INFRINGES ON USER NAME SPACE */ | |
618 | # define alloca _alloca | |
619 | # else | |
620 | # define YYSTACK_ALLOC alloca | |
621 | # if ! defined _ALLOCA_H && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \ | |
622 | || defined __cplusplus || defined _MSC_VER) | |
623 | # include <stdlib.h> /* INFRINGES ON USER NAME SPACE */ | |
624 | # ifndef _STDLIB_H | |
625 | # define _STDLIB_H 1 | |
626 | # endif | |
627 | # endif | |
628 | # endif | |
629 | # endif | |
630 | # endif | |
631 | ||
632 | # ifdef YYSTACK_ALLOC | |
633 | /* Pacify GCC's `empty if-body' warning. */ | |
634 | # define YYSTACK_FREE(Ptr) do { /* empty */; } while (YYID (0)) | |
635 | # ifndef YYSTACK_ALLOC_MAXIMUM | |
636 | /* The OS might guarantee only one guard page at the bottom of the stack, | |
637 | and a page size can be as small as 4096 bytes. So we cannot safely | |
638 | invoke alloca (N) if N exceeds 4096. Use a slightly smaller number | |
639 | to allow for a few compiler-allocated temporary stack slots. */ | |
640 | # define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */ | |
641 | # endif | |
642 | # else | |
643 | # define YYSTACK_ALLOC YYMALLOC | |
644 | # define YYSTACK_FREE YYFREE | |
645 | # ifndef YYSTACK_ALLOC_MAXIMUM | |
646 | # define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM | |
647 | # endif | |
648 | # if (defined __cplusplus && ! defined _STDLIB_H \ | |
649 | && ! ((defined YYMALLOC || defined malloc) \ | |
650 | && (defined YYFREE || defined free))) | |
651 | # include <stdlib.h> /* INFRINGES ON USER NAME SPACE */ | |
652 | # ifndef _STDLIB_H | |
653 | # define _STDLIB_H 1 | |
654 | # endif | |
655 | # endif | |
656 | # ifndef YYMALLOC | |
657 | # define YYMALLOC malloc | |
658 | # if ! defined malloc && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \ | |
659 | || defined __cplusplus || defined _MSC_VER) | |
660 | void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */ | |
661 | # endif | |
662 | # endif | |
663 | # ifndef YYFREE | |
664 | # define YYFREE free | |
665 | # if ! defined free && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \ | |
666 | || defined __cplusplus || defined _MSC_VER) | |
667 | void free (void *); /* INFRINGES ON USER NAME SPACE */ | |
668 | # endif | |
669 | # endif | |
670 | # endif | |
671 | #endif /* ! defined yyoverflow || YYERROR_VERBOSE */ | |
672 | ||
673 | ||
674 | #if (! defined yyoverflow \ | |
675 | && (! defined __cplusplus \ | |
676 | || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL))) | |
677 | ||
678 | /* A type that is properly aligned for any stack member. */ | |
679 | union yyalloc | |
680 | { | |
681 | yytype_int16 yyss; | |
682 | YYSTYPE yyvs; | |
683 | }; | |
684 | ||
685 | /* The size of the maximum gap between one aligned stack and the next. */ | |
686 | # define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1) | |
687 | ||
688 | /* The size of an array large to enough to hold all stacks, each with | |
689 | N elements. */ | |
690 | # define YYSTACK_BYTES(N) \ | |
691 | ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE)) \ | |
692 | + YYSTACK_GAP_MAXIMUM) | |
693 | ||
694 | /* Copy COUNT objects from FROM to TO. The source and destination do | |
695 | not overlap. */ | |
696 | # ifndef YYCOPY | |
697 | # if defined __GNUC__ && 1 < __GNUC__ | |
698 | # define YYCOPY(To, From, Count) \ | |
699 | __builtin_memcpy (To, From, (Count) * sizeof (*(From))) | |
700 | # else | |
701 | # define YYCOPY(To, From, Count) \ | |
702 | do \ | |
703 | { \ | |
704 | YYSIZE_T yyi; \ | |
705 | for (yyi = 0; yyi < (Count); yyi++) \ | |
706 | (To)[yyi] = (From)[yyi]; \ | |
707 | } \ | |
708 | while (YYID (0)) | |
709 | # endif | |
710 | # endif | |
711 | ||
712 | /* Relocate STACK from its old location to the new one. The | |
713 | local variables YYSIZE and YYSTACKSIZE give the old and new number of | |
714 | elements in the stack, and YYPTR gives the new location of the | |
715 | stack. Advance YYPTR to a properly aligned location for the next | |
716 | stack. */ | |
717 | # define YYSTACK_RELOCATE(Stack) \ | |
718 | do \ | |
719 | { \ | |
720 | YYSIZE_T yynewbytes; \ | |
721 | YYCOPY (&yyptr->Stack, Stack, yysize); \ | |
722 | Stack = &yyptr->Stack; \ | |
723 | yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \ | |
724 | yyptr += yynewbytes / sizeof (*yyptr); \ | |
725 | } \ | |
726 | while (YYID (0)) | |
f73dda09 | 727 | |
f73dda09 JA |
728 | #endif |
729 | ||
3185942a | 730 | /* YYFINAL -- State number of the termination state. */ |
495aee44 | 731 | #define YYFINAL 116 |
3185942a | 732 | /* YYLAST -- Last index in YYTABLE. */ |
495aee44 | 733 | #define YYLAST 659 |
3185942a JA |
734 | |
735 | /* YYNTOKENS -- Number of terminals. */ | |
495aee44 | 736 | #define YYNTOKENS 61 |
3185942a JA |
737 | /* YYNNTS -- Number of nonterminals. */ |
738 | #define YYNNTS 38 | |
739 | /* YYNRULES -- Number of rules. */ | |
0001803f | 740 | #define YYNRULES 167 |
3185942a | 741 | /* YYNRULES -- Number of states. */ |
495aee44 | 742 | #define YYNSTATES 342 |
3185942a JA |
743 | |
744 | /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */ | |
745 | #define YYUNDEFTOK 2 | |
495aee44 | 746 | #define YYMAXUTOK 304 |
3185942a JA |
747 | |
748 | #define YYTRANSLATE(YYX) \ | |
749 | ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK) | |
750 | ||
751 | /* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */ | |
752 | static const yytype_uint8 yytranslate[] = | |
753 | { | |
754 | 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
495aee44 | 755 | 51, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
3185942a | 756 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
495aee44 CR |
757 | 2, 2, 2, 2, 2, 2, 2, 2, 49, 2, |
758 | 59, 60, 2, 2, 2, 56, 2, 2, 2, 2, | |
759 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 50, | |
760 | 55, 2, 54, 2, 2, 2, 2, 2, 2, 2, | |
3185942a JA |
761 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
762 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
763 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
764 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
765 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
495aee44 | 766 | 2, 2, 2, 57, 53, 58, 2, 2, 2, 2, |
3185942a JA |
767 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
768 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
769 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
770 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
771 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
772 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
773 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
774 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
775 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
776 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
777 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
778 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
779 | 2, 2, 2, 2, 2, 2, 1, 2, 3, 4, | |
780 | 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, | |
781 | 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, | |
782 | 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, | |
783 | 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, | |
495aee44 | 784 | 45, 46, 47, 48, 52 |
726f6388 | 785 | }; |
f73dda09 | 786 | |
3185942a JA |
787 | #if YYDEBUG |
788 | /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in | |
789 | YYRHS. */ | |
790 | static const yytype_uint16 yyprhs[] = | |
791 | { | |
792 | 0, 0, 3, 6, 8, 11, 13, 15, 18, 21, | |
0001803f CR |
793 | 24, 28, 32, 36, 40, 43, 47, 51, 54, 58, |
794 | 62, 65, 69, 73, 76, 80, 84, 87, 91, 95, | |
795 | 98, 102, 106, 109, 113, 117, 120, 124, 128, 131, | |
796 | 135, 139, 142, 146, 150, 153, 157, 161, 164, 168, | |
797 | 172, 175, 178, 180, 182, 184, 186, 189, 191, 194, | |
798 | 196, 198, 201, 203, 205, 207, 209, 215, 221, 223, | |
799 | 225, 227, 229, 231, 233, 235, 242, 249, 257, 265, | |
800 | 276, 287, 297, 307, 315, 323, 329, 335, 342, 349, | |
801 | 357, 365, 376, 387, 394, 402, 409, 415, 422, 427, | |
802 | 429, 432, 436, 439, 443, 447, 452, 455, 461, 469, | |
803 | 476, 480, 482, 486, 491, 498, 504, 506, 509, 514, | |
804 | 519, 525, 531, 534, 538, 541, 545, 548, 552, 554, | |
805 | 558, 561, 563, 566, 570, 574, 578, 583, 588, 593, | |
806 | 598, 603, 605, 607, 609, 611, 613, 615, 616, 619, | |
807 | 621, 624, 627, 632, 637, 641, 645, 647, 649, 652, | |
495aee44 | 808 | 655, 658, 661, 666, 671, 673, 675, 678 |
726f6388 | 809 | }; |
f73dda09 | 810 | |
3185942a JA |
811 | /* YYRHS -- A `-1'-separated list of the rules' RHS. */ |
812 | static const yytype_int8 yyrhs[] = | |
813 | { | |
495aee44 CR |
814 | 62, 0, -1, 94, 91, -1, 51, -1, 1, 51, |
815 | -1, 52, -1, 26, -1, 63, 26, -1, 54, 26, | |
816 | -1, 55, 26, -1, 29, 54, 26, -1, 29, 55, | |
817 | 26, -1, 28, 54, 26, -1, 28, 55, 26, -1, | |
818 | 35, 26, -1, 29, 35, 26, -1, 28, 35, 26, | |
819 | -1, 47, 26, -1, 29, 47, 26, -1, 28, 47, | |
820 | 26, -1, 46, 26, -1, 29, 46, 26, -1, 28, | |
821 | 46, 26, -1, 36, 26, -1, 29, 36, 26, -1, | |
822 | 28, 36, 26, -1, 43, 26, -1, 29, 43, 26, | |
823 | -1, 28, 43, 26, -1, 38, 26, -1, 29, 38, | |
824 | 26, -1, 28, 38, 26, -1, 37, 29, -1, 29, | |
825 | 37, 29, -1, 28, 37, 29, -1, 39, 29, -1, | |
826 | 29, 39, 29, -1, 28, 39, 29, -1, 37, 26, | |
827 | -1, 29, 37, 26, -1, 28, 37, 26, -1, 39, | |
828 | 26, -1, 29, 39, 26, -1, 28, 39, 26, -1, | |
829 | 39, 56, -1, 29, 39, 56, -1, 28, 39, 56, | |
830 | -1, 37, 56, -1, 29, 37, 56, -1, 28, 37, | |
831 | 56, -1, 44, 26, -1, 45, 26, -1, 26, -1, | |
832 | 27, -1, 64, -1, 64, -1, 66, 64, -1, 65, | |
833 | -1, 67, 65, -1, 67, -1, 69, -1, 69, 66, | |
834 | -1, 74, -1, 77, -1, 70, -1, 73, -1, 12, | |
835 | 88, 14, 88, 15, -1, 13, 88, 14, 88, 15, | |
836 | -1, 72, -1, 78, -1, 76, -1, 79, -1, 80, | |
837 | -1, 81, -1, 71, -1, 10, 26, 93, 14, 88, | |
838 | 15, -1, 10, 26, 93, 57, 88, 58, -1, 10, | |
839 | 26, 50, 93, 14, 88, 15, -1, 10, 26, 50, | |
840 | 93, 57, 88, 58, -1, 10, 26, 93, 21, 63, | |
841 | 92, 93, 14, 88, 15, -1, 10, 26, 93, 21, | |
842 | 63, 92, 93, 57, 88, 58, -1, 10, 26, 93, | |
843 | 21, 92, 93, 14, 88, 15, -1, 10, 26, 93, | |
844 | 21, 92, 93, 57, 88, 58, -1, 10, 31, 92, | |
845 | 93, 14, 88, 15, -1, 10, 31, 92, 93, 57, | |
846 | 88, 58, -1, 10, 31, 14, 88, 15, -1, 10, | |
847 | 31, 57, 88, 58, -1, 11, 26, 93, 14, 87, | |
848 | 15, -1, 11, 26, 93, 57, 87, 58, -1, 11, | |
849 | 26, 50, 93, 14, 87, 15, -1, 11, 26, 50, | |
850 | 93, 57, 87, 58, -1, 11, 26, 93, 21, 63, | |
851 | 92, 93, 14, 87, 15, -1, 11, 26, 93, 21, | |
852 | 63, 92, 93, 57, 87, 58, -1, 8, 26, 93, | |
853 | 21, 93, 9, -1, 8, 26, 93, 21, 85, 93, | |
854 | 9, -1, 8, 26, 93, 21, 83, 9, -1, 26, | |
855 | 59, 60, 93, 75, -1, 16, 26, 59, 60, 93, | |
856 | 75, -1, 16, 26, 93, 75, -1, 69, -1, 69, | |
857 | 66, -1, 59, 88, 60, -1, 17, 69, -1, 17, | |
858 | 69, 66, -1, 17, 26, 69, -1, 17, 26, 69, | |
859 | 66, -1, 17, 67, -1, 3, 88, 4, 88, 7, | |
860 | -1, 3, 88, 4, 88, 5, 88, 7, -1, 3, | |
861 | 88, 4, 88, 82, 7, -1, 57, 88, 58, -1, | |
862 | 30, -1, 18, 32, 19, -1, 6, 88, 4, 88, | |
863 | -1, 6, 88, 4, 88, 5, 88, -1, 6, 88, | |
864 | 4, 88, 82, -1, 84, -1, 85, 84, -1, 93, | |
865 | 86, 60, 88, -1, 93, 86, 60, 93, -1, 93, | |
866 | 59, 86, 60, 88, -1, 93, 59, 86, 60, 93, | |
867 | -1, 84, 40, -1, 85, 84, 40, -1, 84, 41, | |
868 | -1, 85, 84, 41, -1, 84, 42, -1, 85, 84, | |
869 | 42, -1, 26, -1, 86, 53, 26, -1, 93, 89, | |
870 | -1, 87, -1, 93, 90, -1, 90, 51, 93, -1, | |
871 | 90, 49, 93, -1, 90, 50, 93, -1, 90, 33, | |
872 | 93, 90, -1, 90, 34, 93, 90, -1, 90, 49, | |
873 | 93, 90, -1, 90, 50, 93, 90, -1, 90, 51, | |
874 | 93, 90, -1, 96, -1, 51, -1, 52, -1, 51, | |
875 | -1, 50, -1, 52, -1, -1, 93, 51, -1, 95, | |
876 | -1, 95, 49, -1, 95, 50, -1, 95, 33, 93, | |
877 | 95, -1, 95, 34, 93, 95, -1, 95, 49, 95, | |
878 | -1, 95, 50, 95, -1, 96, -1, 97, -1, 22, | |
879 | 96, -1, 98, 96, -1, 98, 92, -1, 22, 92, | |
880 | -1, 97, 53, 93, 97, -1, 97, 48, 93, 97, | |
881 | -1, 68, -1, 23, -1, 23, 24, -1, 23, 24, | |
882 | 25, -1 | |
726f6388 | 883 | }; |
f73dda09 | 884 | |
3185942a JA |
885 | /* YYRLINE[YYN] -- source line where rule number YYN was defined. */ |
886 | static const yytype_uint16 yyrline[] = | |
887 | { | |
495aee44 CR |
888 | 0, 376, 376, 387, 396, 411, 421, 423, 427, 433, |
889 | 439, 445, 451, 457, 463, 469, 475, 481, 487, 493, | |
890 | 499, 505, 511, 517, 524, 531, 538, 545, 552, 559, | |
891 | 565, 571, 577, 583, 589, 595, 601, 607, 613, 619, | |
892 | 625, 631, 637, 643, 649, 655, 661, 667, 673, 679, | |
893 | 685, 691, 699, 701, 703, 707, 711, 722, 724, 728, | |
894 | 730, 732, 748, 750, 754, 756, 758, 760, 762, 764, | |
895 | 766, 768, 770, 772, 774, 778, 783, 788, 793, 798, | |
896 | 803, 808, 813, 820, 825, 830, 835, 842, 847, 852, | |
897 | 857, 862, 867, 874, 879, 884, 891, 894, 897, 901, | |
898 | 903, 934, 941, 946, 963, 968, 985, 992, 994, 996, | |
899 | 1001, 1005, 1009, 1013, 1015, 1017, 1021, 1022, 1026, 1028, | |
900 | 1030, 1032, 1036, 1038, 1040, 1042, 1044, 1046, 1050, 1052, | |
901 | 1061, 1069, 1070, 1076, 1077, 1084, 1088, 1090, 1092, 1099, | |
902 | 1101, 1103, 1107, 1108, 1111, 1113, 1115, 1119, 1120, 1129, | |
903 | 1142, 1158, 1173, 1175, 1177, 1184, 1187, 1191, 1193, 1199, | |
904 | 1205, 1222, 1242, 1244, 1267, 1271, 1273, 1275 | |
726f6388 | 905 | }; |
3185942a | 906 | #endif |
f73dda09 | 907 | |
3185942a JA |
908 | #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE |
909 | /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM. | |
910 | First, the terminals, then, starting at YYNTOKENS, nonterminals. */ | |
911 | static const char *const yytname[] = | |
912 | { | |
913 | "$end", "error", "$undefined", "IF", "THEN", "ELSE", "ELIF", "FI", | |
914 | "CASE", "ESAC", "FOR", "SELECT", "WHILE", "UNTIL", "DO", "DONE", | |
915 | "FUNCTION", "COPROC", "COND_START", "COND_END", "COND_ERROR", "IN", | |
495aee44 CR |
916 | "BANG", "TIME", "TIMEOPT", "TIMEIGN", "WORD", "ASSIGNMENT_WORD", |
917 | "REDIR_WORD", "NUMBER", "ARITH_CMD", "ARITH_FOR_EXPRS", "COND_CMD", | |
918 | "AND_AND", "OR_OR", "GREATER_GREATER", "LESS_LESS", "LESS_AND", | |
919 | "LESS_LESS_LESS", "GREATER_AND", "SEMI_SEMI", "SEMI_AND", | |
920 | "SEMI_SEMI_AND", "LESS_LESS_MINUS", "AND_GREATER", "AND_GREATER_GREATER", | |
921 | "LESS_GREATER", "GREATER_BAR", "BAR_AND", "'&'", "';'", "'\\n'", | |
922 | "yacc_EOF", "'|'", "'>'", "'<'", "'-'", "'{'", "'}'", "'('", "')'", | |
923 | "$accept", "inputunit", "word_list", "redirection", | |
924 | "simple_command_element", "redirection_list", "simple_command", | |
925 | "command", "shell_command", "for_command", "arith_for_command", | |
926 | "select_command", "case_command", "function_def", "function_body", | |
927 | "subshell", "coproc", "if_command", "group_command", "arith_command", | |
928 | "cond_command", "elif_clause", "case_clause", "pattern_list", | |
929 | "case_clause_sequence", "pattern", "list", "compound_list", "list0", | |
930 | "list1", "simple_list_terminator", "list_terminator", "newline_list", | |
931 | "simple_list", "simple_list1", "pipeline_command", "pipeline", | |
932 | "timespec", 0 | |
726f6388 | 933 | }; |
3185942a | 934 | #endif |
f73dda09 | 935 | |
3185942a JA |
936 | # ifdef YYPRINT |
937 | /* YYTOKNUM[YYLEX-NUM] -- Internal token number corresponding to | |
938 | token YYLEX-NUM. */ | |
939 | static const yytype_uint16 yytoknum[] = | |
940 | { | |
941 | 0, 256, 257, 258, 259, 260, 261, 262, 263, 264, | |
942 | 265, 266, 267, 268, 269, 270, 271, 272, 273, 274, | |
943 | 275, 276, 277, 278, 279, 280, 281, 282, 283, 284, | |
944 | 285, 286, 287, 288, 289, 290, 291, 292, 293, 294, | |
495aee44 CR |
945 | 295, 296, 297, 298, 299, 300, 301, 302, 303, 38, |
946 | 59, 10, 304, 124, 62, 60, 45, 123, 125, 40, | |
947 | 41 | |
3185942a JA |
948 | }; |
949 | # endif | |
950 | ||
951 | /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */ | |
952 | static const yytype_uint8 yyr1[] = | |
953 | { | |
495aee44 CR |
954 | 0, 61, 62, 62, 62, 62, 63, 63, 64, 64, |
955 | 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, | |
956 | 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, | |
957 | 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, | |
958 | 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, | |
959 | 64, 64, 65, 65, 65, 66, 66, 67, 67, 68, | |
960 | 68, 68, 68, 68, 69, 69, 69, 69, 69, 69, | |
961 | 69, 69, 69, 69, 69, 70, 70, 70, 70, 70, | |
962 | 70, 70, 70, 71, 71, 71, 71, 72, 72, 72, | |
963 | 72, 72, 72, 73, 73, 73, 74, 74, 74, 75, | |
964 | 75, 76, 77, 77, 77, 77, 77, 78, 78, 78, | |
965 | 79, 80, 81, 82, 82, 82, 83, 83, 84, 84, | |
966 | 84, 84, 85, 85, 85, 85, 85, 85, 86, 86, | |
967 | 87, 88, 88, 89, 89, 89, 90, 90, 90, 90, | |
968 | 90, 90, 91, 91, 92, 92, 92, 93, 93, 94, | |
969 | 94, 94, 95, 95, 95, 95, 95, 96, 96, 96, | |
970 | 96, 96, 97, 97, 97, 98, 98, 98 | |
726f6388 | 971 | }; |
f73dda09 | 972 | |
3185942a JA |
973 | /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */ |
974 | static const yytype_uint8 yyr2[] = | |
975 | { | |
976 | 0, 2, 2, 1, 2, 1, 1, 2, 2, 2, | |
0001803f CR |
977 | 3, 3, 3, 3, 2, 3, 3, 2, 3, 3, |
978 | 2, 3, 3, 2, 3, 3, 2, 3, 3, 2, | |
979 | 3, 3, 2, 3, 3, 2, 3, 3, 2, 3, | |
980 | 3, 2, 3, 3, 2, 3, 3, 2, 3, 3, | |
981 | 2, 2, 1, 1, 1, 1, 2, 1, 2, 1, | |
982 | 1, 2, 1, 1, 1, 1, 5, 5, 1, 1, | |
983 | 1, 1, 1, 1, 1, 6, 6, 7, 7, 10, | |
984 | 10, 9, 9, 7, 7, 5, 5, 6, 6, 7, | |
985 | 7, 10, 10, 6, 7, 6, 5, 6, 4, 1, | |
986 | 2, 3, 2, 3, 3, 4, 2, 5, 7, 6, | |
987 | 3, 1, 3, 4, 6, 5, 1, 2, 4, 4, | |
988 | 5, 5, 2, 3, 2, 3, 2, 3, 1, 3, | |
989 | 2, 1, 2, 3, 3, 3, 4, 4, 4, 4, | |
990 | 4, 1, 1, 1, 1, 1, 1, 0, 2, 1, | |
991 | 2, 2, 4, 4, 3, 3, 1, 1, 2, 2, | |
495aee44 | 992 | 2, 2, 4, 4, 1, 1, 2, 3 |
3185942a | 993 | }; |
f73dda09 | 994 | |
3185942a JA |
995 | /* YYDEFACT[STATE-NAME] -- Default rule to reduce with in state |
996 | STATE-NUM when YYTABLE doesn't specify something else to do. Zero | |
997 | means the default is an error. */ | |
998 | static const yytype_uint8 yydefact[] = | |
999 | { | |
0001803f | 1000 | 0, 0, 147, 0, 0, 0, 147, 147, 0, 0, |
495aee44 | 1001 | 0, 0, 165, 52, 53, 0, 0, 111, 0, 0, |
0001803f | 1002 | 0, 0, 0, 0, 0, 0, 0, 0, 3, 5, |
495aee44 | 1003 | 0, 0, 147, 147, 0, 54, 57, 59, 164, 60, |
0001803f CR |
1004 | 64, 74, 68, 65, 62, 70, 63, 69, 71, 72, |
1005 | 73, 0, 149, 156, 157, 0, 4, 131, 0, 0, | |
1006 | 147, 147, 0, 147, 0, 0, 147, 52, 106, 102, | |
495aee44 | 1007 | 0, 145, 144, 146, 161, 158, 166, 0, 0, 0, |
0001803f | 1008 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
495aee44 CR |
1009 | 0, 0, 0, 0, 0, 0, 0, 0, 14, 23, |
1010 | 38, 32, 47, 29, 41, 35, 44, 26, 50, 51, | |
1011 | 20, 17, 8, 9, 0, 0, 1, 52, 58, 55, | |
1012 | 61, 142, 143, 2, 147, 147, 150, 151, 147, 147, | |
1013 | 160, 159, 147, 148, 130, 132, 141, 0, 147, 0, | |
1014 | 147, 147, 147, 147, 0, 147, 147, 0, 0, 104, | |
1015 | 103, 112, 167, 147, 16, 25, 40, 34, 49, 31, | |
1016 | 43, 37, 46, 28, 22, 19, 12, 13, 15, 24, | |
1017 | 39, 33, 48, 30, 42, 36, 45, 27, 21, 18, | |
1018 | 10, 11, 110, 101, 56, 0, 0, 154, 155, 0, | |
1019 | 0, 0, 147, 147, 147, 147, 147, 147, 0, 147, | |
1020 | 0, 147, 0, 0, 0, 0, 147, 0, 147, 0, | |
1021 | 0, 147, 99, 98, 105, 0, 152, 153, 0, 0, | |
1022 | 163, 162, 147, 147, 107, 0, 0, 0, 134, 135, | |
1023 | 133, 0, 116, 147, 0, 147, 147, 0, 6, 0, | |
1024 | 147, 0, 85, 86, 147, 147, 147, 147, 0, 0, | |
1025 | 0, 0, 66, 67, 0, 100, 96, 0, 0, 109, | |
1026 | 136, 137, 138, 139, 140, 95, 122, 124, 126, 117, | |
1027 | 0, 93, 128, 0, 0, 0, 0, 75, 7, 147, | |
1028 | 0, 76, 0, 0, 0, 0, 87, 0, 147, 88, | |
1029 | 97, 108, 147, 147, 147, 147, 123, 125, 127, 94, | |
1030 | 0, 0, 147, 77, 78, 0, 147, 147, 83, 84, | |
1031 | 89, 90, 0, 113, 0, 0, 0, 147, 129, 118, | |
1032 | 119, 147, 147, 0, 0, 147, 147, 147, 115, 120, | |
1033 | 121, 0, 0, 81, 82, 0, 0, 114, 79, 80, | |
1034 | 91, 92 | |
726f6388 | 1035 | }; |
f73dda09 | 1036 | |
3185942a JA |
1037 | /* YYDEFGOTO[NTERM-NUM]. */ |
1038 | static const yytype_int16 yydefgoto[] = | |
1039 | { | |
495aee44 CR |
1040 | -1, 34, 239, 35, 36, 120, 37, 38, 39, 40, |
1041 | 41, 42, 43, 44, 213, 45, 46, 47, 48, 49, | |
1042 | 50, 225, 231, 232, 233, 274, 57, 58, 134, 135, | |
1043 | 123, 74, 59, 51, 187, 136, 54, 55 | |
726f6388 | 1044 | }; |
f73dda09 | 1045 | |
3185942a JA |
1046 | /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing |
1047 | STATE-NUM. */ | |
495aee44 | 1048 | #define YYPACT_NINF -208 |
3185942a JA |
1049 | static const yytype_int16 yypact[] = |
1050 | { | |
495aee44 CR |
1051 | 296, -35, -208, -2, 38, 10, -208, -208, 24, 546, |
1052 | 31, 346, 51, 47, -208, 591, 604, -208, 56, 71, | |
1053 | -18, 112, 130, 115, 128, 136, 143, 154, -208, -208, | |
1054 | 157, 170, -208, -208, 111, -208, -208, 229, -208, 578, | |
1055 | -208, -208, -208, -208, -208, -208, -208, -208, -208, -208, | |
1056 | -208, -12, -3, -208, 48, 346, -208, -208, 208, 396, | |
1057 | -208, 73, 15, 163, 190, 201, 160, 107, 229, 578, | |
1058 | 204, -208, -208, -208, -208, -208, 195, 165, 202, 215, | |
1059 | 152, 216, 153, 222, 227, 236, 237, 244, 245, 253, | |
1060 | 158, 254, 171, 255, 256, 259, 261, 262, -208, -208, | |
1061 | -208, -208, -208, -208, -208, -208, -208, -208, -208, -208, | |
1062 | -208, -208, -208, -208, 231, 230, -208, -208, -208, -208, | |
1063 | 578, -208, -208, -208, -208, -208, 446, 446, -208, -208, | |
1064 | -208, -208, -208, -208, -208, 210, -208, 4, -208, 65, | |
1065 | -208, -208, -208, -208, 70, -208, -208, 232, 41, 578, | |
1066 | 578, -208, -208, -208, -208, -208, -208, -208, -208, -208, | |
1067 | -208, -208, -208, -208, -208, -208, -208, -208, -208, -208, | |
1068 | -208, -208, -208, -208, -208, -208, -208, -208, -208, -208, | |
1069 | -208, -208, -208, -208, -208, 396, 396, 23, 23, 496, | |
1070 | 496, 97, -208, -208, -208, -208, -208, -208, 85, -208, | |
1071 | 185, -208, 276, 235, 100, 110, -208, 268, -208, 280, | |
1072 | 283, -208, 578, -208, 578, 41, -208, -208, 446, 446, | |
1073 | 48, 48, -208, -208, -208, 295, 396, 396, 396, 396, | |
1074 | 396, 294, 161, -208, 19, -208, -208, 290, -208, 200, | |
1075 | -208, 252, -208, -208, -208, -208, -208, -208, 302, 396, | |
1076 | 200, 269, -208, -208, 41, 578, -208, 313, 324, -208, | |
1077 | -208, -208, 55, 55, 55, -208, -208, -208, -208, 192, | |
1078 | 34, -208, -208, 303, -19, 315, 278, -208, -208, -208, | |
1079 | 114, -208, 322, 286, 323, 287, -208, 210, -208, -208, | |
1080 | -208, -208, -208, -208, -208, -208, -208, -208, -208, -208, | |
1081 | 8, 320, -208, -208, -208, 117, -208, -208, -208, -208, | |
1082 | -208, -208, 119, 167, 396, 396, 396, -208, -208, -208, | |
1083 | 396, -208, -208, 337, 307, -208, -208, -208, -208, -208, | |
1084 | 396, 345, 308, -208, -208, 352, 312, -208, -208, -208, | |
1085 | -208, -208 | |
3185942a | 1086 | }; |
f73dda09 | 1087 | |
3185942a JA |
1088 | /* YYPGOTO[NTERM-NUM]. */ |
1089 | static const yytype_int16 yypgoto[] = | |
1090 | { | |
495aee44 CR |
1091 | -208, -208, 164, -37, -31, -62, 368, -208, -5, -208, |
1092 | -208, -208, -208, -208, -206, -208, -208, -208, -208, -208, | |
1093 | -208, 66, -208, 145, -208, 88, -173, -6, -208, -207, | |
1094 | -208, -45, -48, -208, 5, 3, 17, -208 | |
3185942a | 1095 | }; |
f73dda09 | 1096 | |
3185942a JA |
1097 | /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If |
1098 | positive, shift that token. If negative, reduce the rule which | |
1099 | number is the opposite. If zero, do what YYDEFACT says. | |
1100 | If YYTABLE_NINF, syntax error. */ | |
1101 | #define YYTABLE_NINF -1 | |
1102 | static const yytype_uint16 yytable[] = | |
1103 | { | |
495aee44 CR |
1104 | 64, 65, 119, 53, 69, 52, 118, 150, 100, 256, |
1105 | 130, 101, 137, 139, 75, 144, 56, 142, 148, 260, | |
1106 | 261, 262, 263, 264, 60, 197, 114, 115, 271, 140, | |
1107 | 124, 125, 119, 248, 301, 251, 63, 118, 102, 121, | |
1108 | 122, 302, 287, 299, 2, 272, 126, 127, 290, 3, | |
1109 | 66, 4, 5, 6, 7, 133, 124, 125, 131, 10, | |
1110 | 272, 301, 149, 70, 61, 71, 72, 73, 317, 62, | |
1111 | 133, 17, 141, 284, 285, 76, 185, 186, 273, 199, | |
1112 | 189, 190, 98, 184, 206, 133, 200, 214, 192, 193, | |
1113 | 198, 207, 133, 273, 204, 205, 128, 99, 32, 235, | |
1114 | 33, 129, 222, 223, 224, 215, 77, 262, 263, 264, | |
1115 | 2, 116, 119, 184, 244, 3, 133, 4, 5, 6, | |
1116 | 7, 133, 201, 138, 246, 10, 191, 208, 306, 53, | |
1117 | 53, 321, 188, 325, 202, 203, 133, 17, 103, 209, | |
1118 | 210, 107, 236, 212, 226, 227, 228, 229, 230, 234, | |
1119 | 255, 133, 335, 336, 108, 240, 104, 245, 249, 105, | |
1120 | 249, 133, 109, 254, 32, 133, 33, 247, 133, 110, | |
1121 | 133, 307, 327, 223, 322, 119, 326, 184, 156, 160, | |
1122 | 111, 157, 161, 112, 170, 270, 106, 171, 53, 53, | |
1123 | 216, 217, 280, 237, 279, 241, 113, 174, 249, 249, | |
1124 | 175, 266, 267, 268, 145, 288, 220, 221, 158, 162, | |
1125 | 212, 238, 132, 143, 172, 146, 257, 258, 184, 147, | |
1126 | 152, 53, 53, 151, 188, 153, 278, 176, 154, 275, | |
1127 | 276, 305, 296, 297, 298, 71, 72, 73, 282, 283, | |
1128 | 312, 155, 159, 192, 193, 314, 315, 316, 163, 212, | |
1129 | 71, 72, 73, 164, 320, 117, 14, 15, 16, 194, | |
1130 | 195, 196, 165, 166, 18, 19, 20, 21, 22, 330, | |
1131 | 167, 168, 23, 24, 25, 26, 27, 249, 249, 169, | |
1132 | 173, 177, 178, 30, 31, 179, 313, 180, 181, 182, | |
1133 | 183, 242, 211, 243, 238, 252, 319, 1, 253, 2, | |
1134 | 323, 324, 259, 265, 3, 277, 4, 5, 6, 7, | |
1135 | 281, 329, 8, 9, 10, 331, 332, 286, 11, 12, | |
1136 | 291, 337, 13, 14, 15, 16, 17, 289, 292, 272, | |
1137 | 303, 18, 19, 20, 21, 22, 304, 308, 310, 23, | |
1138 | 24, 25, 26, 27, 309, 311, 318, 28, 29, 2, | |
1139 | 30, 31, 333, 32, 3, 33, 4, 5, 6, 7, | |
1140 | 338, 300, 8, 9, 10, 334, 339, 340, 11, 12, | |
1141 | 341, 250, 13, 14, 15, 16, 17, 68, 269, 328, | |
1142 | 0, 18, 19, 20, 21, 22, 0, 0, 0, 23, | |
1143 | 24, 25, 26, 27, 0, 0, 71, 72, 73, 2, | |
1144 | 30, 31, 0, 32, 3, 33, 4, 5, 6, 7, | |
1145 | 0, 0, 8, 9, 10, 0, 0, 0, 11, 12, | |
0001803f CR |
1146 | 0, 0, 13, 14, 15, 16, 17, 0, 0, 0, |
1147 | 0, 18, 19, 20, 21, 22, 0, 0, 0, 23, | |
495aee44 | 1148 | 24, 25, 26, 27, 0, 0, 0, 133, 0, 2, |
0001803f CR |
1149 | 30, 31, 0, 32, 3, 33, 4, 5, 6, 7, |
1150 | 0, 0, 8, 9, 10, 0, 0, 0, 11, 12, | |
495aee44 CR |
1151 | 0, 0, 13, 14, 15, 16, 17, 0, 0, 0, |
1152 | 0, 18, 19, 20, 21, 22, 0, 0, 0, 23, | |
1153 | 24, 25, 26, 27, 0, 0, 0, 0, 0, 2, | |
1154 | 30, 31, 0, 32, 3, 33, 4, 5, 6, 7, | |
1155 | 0, 0, 8, 9, 10, 0, 0, 0, 0, 0, | |
1156 | 0, 0, 13, 14, 15, 16, 17, 0, 0, 0, | |
1157 | 0, 18, 19, 20, 21, 22, 0, 0, 0, 23, | |
1158 | 24, 25, 26, 27, 0, 0, 0, 133, 0, 2, | |
1159 | 30, 31, 0, 32, 3, 33, 4, 5, 6, 7, | |
1160 | 0, 0, 0, 0, 10, 0, 0, 0, 0, 0, | |
1161 | 0, 0, 67, 14, 15, 16, 17, 0, 0, 0, | |
1162 | 0, 18, 19, 20, 21, 22, 0, 0, 0, 23, | |
1163 | 24, 25, 26, 27, 0, 0, 0, 0, 0, 0, | |
1164 | 30, 31, 0, 32, 0, 33, 15, 16, 0, 0, | |
1165 | 0, 0, 0, 18, 19, 20, 21, 22, 0, 0, | |
1166 | 0, 23, 24, 25, 26, 27, 78, 79, 80, 81, | |
1167 | 82, 0, 30, 31, 83, 0, 0, 84, 85, 88, | |
1168 | 89, 90, 91, 92, 0, 86, 87, 93, 0, 0, | |
1169 | 94, 95, 0, 0, 0, 0, 0, 0, 96, 97 | |
3185942a | 1170 | }; |
f73dda09 | 1171 | |
3185942a JA |
1172 | static const yytype_int16 yycheck[] = |
1173 | { | |
495aee44 CR |
1174 | 6, 7, 39, 0, 9, 0, 37, 69, 26, 215, |
1175 | 55, 29, 60, 61, 11, 63, 51, 62, 66, 226, | |
1176 | 227, 228, 229, 230, 26, 21, 32, 33, 9, 14, | |
1177 | 33, 34, 69, 206, 53, 208, 26, 68, 56, 51, | |
1178 | 52, 60, 249, 9, 3, 26, 49, 50, 254, 8, | |
1179 | 26, 10, 11, 12, 13, 51, 33, 34, 55, 18, | |
1180 | 26, 53, 67, 32, 26, 50, 51, 52, 60, 31, | |
1181 | 51, 30, 57, 246, 247, 24, 124, 125, 59, 14, | |
1182 | 128, 129, 26, 120, 14, 51, 21, 149, 33, 34, | |
1183 | 138, 21, 51, 59, 142, 143, 48, 26, 57, 14, | |
1184 | 59, 53, 5, 6, 7, 153, 59, 314, 315, 316, | |
1185 | 3, 0, 149, 150, 14, 8, 51, 10, 11, 12, | |
1186 | 13, 51, 57, 50, 14, 18, 132, 57, 14, 126, | |
1187 | 127, 14, 127, 14, 140, 141, 51, 30, 26, 145, | |
1188 | 146, 26, 57, 148, 192, 193, 194, 195, 196, 197, | |
1189 | 212, 51, 325, 326, 26, 200, 26, 57, 206, 29, | |
1190 | 208, 51, 26, 211, 57, 51, 59, 57, 51, 26, | |
1191 | 51, 57, 5, 6, 57, 212, 57, 214, 26, 26, | |
1192 | 26, 29, 29, 26, 26, 233, 56, 29, 185, 186, | |
1193 | 185, 186, 240, 199, 239, 201, 26, 26, 246, 247, | |
1194 | 29, 40, 41, 42, 14, 250, 189, 190, 56, 56, | |
1195 | 215, 26, 4, 50, 56, 14, 222, 223, 255, 59, | |
1196 | 25, 218, 219, 19, 219, 60, 26, 56, 26, 235, | |
1197 | 236, 279, 40, 41, 42, 50, 51, 52, 244, 245, | |
1198 | 288, 26, 26, 33, 34, 293, 294, 295, 26, 254, | |
1199 | 50, 51, 52, 26, 302, 26, 27, 28, 29, 49, | |
1200 | 50, 51, 26, 26, 35, 36, 37, 38, 39, 317, | |
1201 | 26, 26, 43, 44, 45, 46, 47, 325, 326, 26, | |
1202 | 26, 26, 26, 54, 55, 26, 292, 26, 26, 58, | |
1203 | 60, 15, 60, 58, 26, 15, 302, 1, 15, 3, | |
1204 | 306, 307, 7, 9, 8, 15, 10, 11, 12, 13, | |
1205 | 58, 317, 16, 17, 18, 321, 322, 15, 22, 23, | |
1206 | 7, 327, 26, 27, 28, 29, 30, 58, 4, 26, | |
1207 | 15, 35, 36, 37, 38, 39, 58, 15, 15, 43, | |
1208 | 44, 45, 46, 47, 58, 58, 26, 51, 52, 3, | |
1209 | 54, 55, 15, 57, 8, 59, 10, 11, 12, 13, | |
1210 | 15, 273, 16, 17, 18, 58, 58, 15, 22, 23, | |
1211 | 58, 207, 26, 27, 28, 29, 30, 9, 233, 313, | |
1212 | -1, 35, 36, 37, 38, 39, -1, -1, -1, 43, | |
1213 | 44, 45, 46, 47, -1, -1, 50, 51, 52, 3, | |
1214 | 54, 55, -1, 57, 8, 59, 10, 11, 12, 13, | |
0001803f | 1215 | -1, -1, 16, 17, 18, -1, -1, -1, 22, 23, |
495aee44 CR |
1216 | -1, -1, 26, 27, 28, 29, 30, -1, -1, -1, |
1217 | -1, 35, 36, 37, 38, 39, -1, -1, -1, 43, | |
1218 | 44, 45, 46, 47, -1, -1, -1, 51, -1, 3, | |
1219 | 54, 55, -1, 57, 8, 59, 10, 11, 12, 13, | |
1220 | -1, -1, 16, 17, 18, -1, -1, -1, 22, 23, | |
1221 | -1, -1, 26, 27, 28, 29, 30, -1, -1, -1, | |
1222 | -1, 35, 36, 37, 38, 39, -1, -1, -1, 43, | |
1223 | 44, 45, 46, 47, -1, -1, -1, -1, -1, 3, | |
1224 | 54, 55, -1, 57, 8, 59, 10, 11, 12, 13, | |
1225 | -1, -1, 16, 17, 18, -1, -1, -1, -1, -1, | |
1226 | -1, -1, 26, 27, 28, 29, 30, -1, -1, -1, | |
1227 | -1, 35, 36, 37, 38, 39, -1, -1, -1, 43, | |
1228 | 44, 45, 46, 47, -1, -1, -1, 51, -1, 3, | |
1229 | 54, 55, -1, 57, 8, 59, 10, 11, 12, 13, | |
1230 | -1, -1, -1, -1, 18, -1, -1, -1, -1, -1, | |
1231 | -1, -1, 26, 27, 28, 29, 30, -1, -1, -1, | |
1232 | -1, 35, 36, 37, 38, 39, -1, -1, -1, 43, | |
1233 | 44, 45, 46, 47, -1, -1, -1, -1, -1, -1, | |
1234 | 54, 55, -1, 57, -1, 59, 28, 29, -1, -1, | |
1235 | -1, -1, -1, 35, 36, 37, 38, 39, -1, -1, | |
1236 | -1, 43, 44, 45, 46, 47, 35, 36, 37, 38, | |
1237 | 39, -1, 54, 55, 43, -1, -1, 46, 47, 35, | |
1238 | 36, 37, 38, 39, -1, 54, 55, 43, -1, -1, | |
1239 | 46, 47, -1, -1, -1, -1, -1, -1, 54, 55 | |
3185942a | 1240 | }; |
f73dda09 | 1241 | |
3185942a JA |
1242 | /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing |
1243 | symbol of state STATE-NUM. */ | |
1244 | static const yytype_uint8 yystos[] = | |
1245 | { | |
1246 | 0, 1, 3, 8, 10, 11, 12, 13, 16, 17, | |
495aee44 CR |
1247 | 18, 22, 23, 26, 27, 28, 29, 30, 35, 36, |
1248 | 37, 38, 39, 43, 44, 45, 46, 47, 51, 52, | |
1249 | 54, 55, 57, 59, 62, 64, 65, 67, 68, 69, | |
1250 | 70, 71, 72, 73, 74, 76, 77, 78, 79, 80, | |
1251 | 81, 94, 95, 96, 97, 98, 51, 87, 88, 93, | |
1252 | 26, 26, 31, 26, 88, 88, 26, 26, 67, 69, | |
1253 | 32, 50, 51, 52, 92, 96, 24, 59, 35, 36, | |
1254 | 37, 38, 39, 43, 46, 47, 54, 55, 35, 36, | |
1255 | 37, 38, 39, 43, 46, 47, 54, 55, 26, 26, | |
1256 | 26, 29, 56, 26, 26, 29, 56, 26, 26, 26, | |
1257 | 26, 26, 26, 26, 88, 88, 0, 26, 65, 64, | |
1258 | 66, 51, 52, 91, 33, 34, 49, 50, 48, 53, | |
1259 | 92, 96, 4, 51, 89, 90, 96, 93, 50, 93, | |
1260 | 14, 57, 92, 50, 93, 14, 14, 59, 93, 69, | |
1261 | 66, 19, 25, 60, 26, 26, 26, 29, 56, 26, | |
1262 | 26, 29, 56, 26, 26, 26, 26, 26, 26, 26, | |
1263 | 26, 29, 56, 26, 26, 29, 56, 26, 26, 26, | |
1264 | 26, 26, 58, 60, 64, 93, 93, 95, 95, 93, | |
1265 | 93, 88, 33, 34, 49, 50, 51, 21, 93, 14, | |
1266 | 21, 57, 88, 88, 93, 93, 14, 21, 57, 88, | |
1267 | 88, 60, 69, 75, 66, 93, 95, 95, 49, 50, | |
1268 | 97, 97, 5, 6, 7, 82, 93, 93, 93, 93, | |
1269 | 93, 83, 84, 85, 93, 14, 57, 88, 26, 63, | |
1270 | 92, 88, 15, 58, 14, 57, 14, 57, 87, 93, | |
1271 | 63, 87, 15, 15, 93, 66, 75, 88, 88, 7, | |
1272 | 90, 90, 90, 90, 90, 9, 40, 41, 42, 84, | |
1273 | 93, 9, 26, 59, 86, 88, 88, 15, 26, 92, | |
1274 | 93, 58, 88, 88, 87, 87, 15, 90, 92, 58, | |
1275 | 75, 7, 4, 49, 50, 51, 40, 41, 42, 9, | |
1276 | 86, 53, 60, 15, 58, 93, 14, 57, 15, 58, | |
1277 | 15, 58, 93, 88, 93, 93, 93, 60, 26, 88, | |
1278 | 93, 14, 57, 88, 88, 14, 57, 5, 82, 88, | |
1279 | 93, 88, 88, 15, 58, 87, 87, 88, 15, 58, | |
1280 | 15, 58 | |
3185942a | 1281 | }; |
b80f6443 | 1282 | |
f73dda09 JA |
1283 | #define yyerrok (yyerrstatus = 0) |
1284 | #define yyclearin (yychar = YYEMPTY) | |
3185942a | 1285 | #define YYEMPTY (-2) |
f73dda09 | 1286 | #define YYEOF 0 |
3185942a | 1287 | |
f73dda09 | 1288 | #define YYACCEPT goto yyacceptlab |
3185942a JA |
1289 | #define YYABORT goto yyabortlab |
1290 | #define YYERROR goto yyerrorlab | |
1291 | ||
1292 | ||
1293 | /* Like YYERROR except do call yyerror. This remains here temporarily | |
1294 | to ease the transition to the new meaning of YYERROR, for GCC. | |
f73dda09 | 1295 | Once GCC version 2 has supplanted version 1, this can go. */ |
3185942a | 1296 | |
f73dda09 | 1297 | #define YYFAIL goto yyerrlab |
3185942a | 1298 | |
f73dda09 | 1299 | #define YYRECOVERING() (!!yyerrstatus) |
3185942a JA |
1300 | |
1301 | #define YYBACKUP(Token, Value) \ | |
f73dda09 JA |
1302 | do \ |
1303 | if (yychar == YYEMPTY && yylen == 1) \ | |
3185942a JA |
1304 | { \ |
1305 | yychar = (Token); \ | |
1306 | yylval = (Value); \ | |
1307 | yytoken = YYTRANSLATE (yychar); \ | |
1308 | YYPOPSTACK (1); \ | |
f73dda09 JA |
1309 | goto yybackup; \ |
1310 | } \ | |
1311 | else \ | |
3185942a JA |
1312 | { \ |
1313 | yyerror (YY_("syntax error: cannot back up")); \ | |
1314 | YYERROR; \ | |
1315 | } \ | |
1316 | while (YYID (0)) | |
1317 | ||
f73dda09 JA |
1318 | |
1319 | #define YYTERROR 1 | |
1320 | #define YYERRCODE 256 | |
1321 | ||
3185942a JA |
1322 | |
1323 | /* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N]. | |
1324 | If N is 0, then set CURRENT to the empty location which ends | |
1325 | the previous symbol: RHS[0] (always defined). */ | |
1326 | ||
1327 | #define YYRHSLOC(Rhs, K) ((Rhs)[K]) | |
1328 | #ifndef YYLLOC_DEFAULT | |
1329 | # define YYLLOC_DEFAULT(Current, Rhs, N) \ | |
1330 | do \ | |
1331 | if (YYID (N)) \ | |
1332 | { \ | |
1333 | (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \ | |
1334 | (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \ | |
1335 | (Current).last_line = YYRHSLOC (Rhs, N).last_line; \ | |
1336 | (Current).last_column = YYRHSLOC (Rhs, N).last_column; \ | |
1337 | } \ | |
1338 | else \ | |
1339 | { \ | |
1340 | (Current).first_line = (Current).last_line = \ | |
1341 | YYRHSLOC (Rhs, 0).last_line; \ | |
1342 | (Current).first_column = (Current).last_column = \ | |
1343 | YYRHSLOC (Rhs, 0).last_column; \ | |
1344 | } \ | |
1345 | while (YYID (0)) | |
b80f6443 | 1346 | #endif |
f73dda09 | 1347 | |
3185942a JA |
1348 | |
1349 | /* YY_LOCATION_PRINT -- Print the location on the stream. | |
1350 | This macro was not mandated originally: define only if we know | |
1351 | we won't break user code: when these are the locations we know. */ | |
1352 | ||
1353 | #ifndef YY_LOCATION_PRINT | |
1354 | # if YYLTYPE_IS_TRIVIAL | |
1355 | # define YY_LOCATION_PRINT(File, Loc) \ | |
1356 | fprintf (File, "%d.%d-%d.%d", \ | |
1357 | (Loc).first_line, (Loc).first_column, \ | |
1358 | (Loc).last_line, (Loc).last_column) | |
1359 | # else | |
1360 | # define YY_LOCATION_PRINT(File, Loc) ((void) 0) | |
1361 | # endif | |
b80f6443 | 1362 | #endif |
3185942a JA |
1363 | |
1364 | ||
1365 | /* YYLEX -- calling `yylex' with the right arguments. */ | |
1366 | ||
b80f6443 | 1367 | #ifdef YYLEX_PARAM |
3185942a | 1368 | # define YYLEX yylex (YYLEX_PARAM) |
b80f6443 | 1369 | #else |
3185942a | 1370 | # define YYLEX yylex () |
b80f6443 | 1371 | #endif |
3185942a JA |
1372 | |
1373 | /* Enable debugging if requested. */ | |
1374 | #if YYDEBUG | |
1375 | ||
1376 | # ifndef YYFPRINTF | |
1377 | # include <stdio.h> /* INFRINGES ON USER NAME SPACE */ | |
1378 | # define YYFPRINTF fprintf | |
1379 | # endif | |
1380 | ||
1381 | # define YYDPRINTF(Args) \ | |
1382 | do { \ | |
1383 | if (yydebug) \ | |
1384 | YYFPRINTF Args; \ | |
1385 | } while (YYID (0)) | |
1386 | ||
1387 | # define YY_SYMBOL_PRINT(Title, Type, Value, Location) \ | |
1388 | do { \ | |
1389 | if (yydebug) \ | |
1390 | { \ | |
1391 | YYFPRINTF (stderr, "%s ", Title); \ | |
1392 | yy_symbol_print (stderr, \ | |
1393 | Type, Value); \ | |
1394 | YYFPRINTF (stderr, "\n"); \ | |
1395 | } \ | |
1396 | } while (YYID (0)) | |
1397 | ||
1398 | ||
1399 | /*--------------------------------. | |
1400 | | Print this symbol on YYOUTPUT. | | |
1401 | `--------------------------------*/ | |
1402 | ||
1403 | /*ARGSUSED*/ | |
1404 | #if (defined __STDC__ || defined __C99__FUNC__ \ | |
1405 | || defined __cplusplus || defined _MSC_VER) | |
1406 | static void | |
1407 | yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep) | |
1408 | #else | |
1409 | static void | |
1410 | yy_symbol_value_print (yyoutput, yytype, yyvaluep) | |
1411 | FILE *yyoutput; | |
1412 | int yytype; | |
1413 | YYSTYPE const * const yyvaluep; | |
b80f6443 | 1414 | #endif |
3185942a JA |
1415 | { |
1416 | if (!yyvaluep) | |
1417 | return; | |
1418 | # ifdef YYPRINT | |
1419 | if (yytype < YYNTOKENS) | |
1420 | YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep); | |
1421 | # else | |
1422 | YYUSE (yyoutput); | |
1423 | # endif | |
1424 | switch (yytype) | |
1425 | { | |
1426 | default: | |
1427 | break; | |
1428 | } | |
1429 | } | |
1430 | ||
1431 | ||
1432 | /*--------------------------------. | |
1433 | | Print this symbol on YYOUTPUT. | | |
1434 | `--------------------------------*/ | |
b80f6443 | 1435 | |
3185942a JA |
1436 | #if (defined __STDC__ || defined __C99__FUNC__ \ |
1437 | || defined __cplusplus || defined _MSC_VER) | |
1438 | static void | |
1439 | yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep) | |
1440 | #else | |
1441 | static void | |
1442 | yy_symbol_print (yyoutput, yytype, yyvaluep) | |
1443 | FILE *yyoutput; | |
1444 | int yytype; | |
1445 | YYSTYPE const * const yyvaluep; | |
1446 | #endif | |
1447 | { | |
1448 | if (yytype < YYNTOKENS) | |
1449 | YYFPRINTF (yyoutput, "token %s (", yytname[yytype]); | |
1450 | else | |
1451 | YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]); | |
726f6388 | 1452 | |
3185942a JA |
1453 | yy_symbol_value_print (yyoutput, yytype, yyvaluep); |
1454 | YYFPRINTF (yyoutput, ")"); | |
1455 | } | |
726f6388 | 1456 | |
3185942a JA |
1457 | /*------------------------------------------------------------------. |
1458 | | yy_stack_print -- Print the state stack from its BOTTOM up to its | | |
1459 | | TOP (included). | | |
1460 | `------------------------------------------------------------------*/ | |
b80f6443 | 1461 | |
3185942a JA |
1462 | #if (defined __STDC__ || defined __C99__FUNC__ \ |
1463 | || defined __cplusplus || defined _MSC_VER) | |
1464 | static void | |
1465 | yy_stack_print (yytype_int16 *bottom, yytype_int16 *top) | |
1466 | #else | |
1467 | static void | |
1468 | yy_stack_print (bottom, top) | |
1469 | yytype_int16 *bottom; | |
1470 | yytype_int16 *top; | |
f73dda09 | 1471 | #endif |
3185942a JA |
1472 | { |
1473 | YYFPRINTF (stderr, "Stack now"); | |
1474 | for (; bottom <= top; ++bottom) | |
1475 | YYFPRINTF (stderr, " %d", *bottom); | |
1476 | YYFPRINTF (stderr, "\n"); | |
1477 | } | |
726f6388 | 1478 | |
3185942a JA |
1479 | # define YY_STACK_PRINT(Bottom, Top) \ |
1480 | do { \ | |
1481 | if (yydebug) \ | |
1482 | yy_stack_print ((Bottom), (Top)); \ | |
1483 | } while (YYID (0)) | |
726f6388 | 1484 | |
3185942a JA |
1485 | |
1486 | /*------------------------------------------------. | |
1487 | | Report that the YYRULE is going to be reduced. | | |
1488 | `------------------------------------------------*/ | |
1489 | ||
1490 | #if (defined __STDC__ || defined __C99__FUNC__ \ | |
1491 | || defined __cplusplus || defined _MSC_VER) | |
1492 | static void | |
1493 | yy_reduce_print (YYSTYPE *yyvsp, int yyrule) | |
1494 | #else | |
1495 | static void | |
1496 | yy_reduce_print (yyvsp, yyrule) | |
1497 | YYSTYPE *yyvsp; | |
1498 | int yyrule; | |
b80f6443 | 1499 | #endif |
3185942a JA |
1500 | { |
1501 | int yynrhs = yyr2[yyrule]; | |
1502 | int yyi; | |
1503 | unsigned long int yylno = yyrline[yyrule]; | |
1504 | YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n", | |
1505 | yyrule - 1, yylno); | |
1506 | /* The symbols being reduced. */ | |
1507 | for (yyi = 0; yyi < yynrhs; yyi++) | |
1508 | { | |
1509 | fprintf (stderr, " $%d = ", yyi + 1); | |
1510 | yy_symbol_print (stderr, yyrhs[yyprhs[yyrule] + yyi], | |
1511 | &(yyvsp[(yyi + 1) - (yynrhs)]) | |
1512 | ); | |
1513 | fprintf (stderr, "\n"); | |
1514 | } | |
1515 | } | |
1516 | ||
1517 | # define YY_REDUCE_PRINT(Rule) \ | |
1518 | do { \ | |
1519 | if (yydebug) \ | |
1520 | yy_reduce_print (yyvsp, Rule); \ | |
1521 | } while (YYID (0)) | |
b80f6443 | 1522 | |
3185942a JA |
1523 | /* Nonzero means print parse trace. It is left uninitialized so that |
1524 | multiple parsers can coexist. */ | |
1525 | int yydebug; | |
1526 | #else /* !YYDEBUG */ | |
1527 | # define YYDPRINTF(Args) | |
1528 | # define YY_SYMBOL_PRINT(Title, Type, Value, Location) | |
1529 | # define YY_STACK_PRINT(Bottom, Top) | |
1530 | # define YY_REDUCE_PRINT(Rule) | |
1531 | #endif /* !YYDEBUG */ | |
726f6388 | 1532 | |
3185942a JA |
1533 | |
1534 | /* YYINITDEPTH -- initial size of the parser's stacks. */ | |
f73dda09 | 1535 | #ifndef YYINITDEPTH |
3185942a | 1536 | # define YYINITDEPTH 200 |
f73dda09 | 1537 | #endif |
726f6388 | 1538 | |
3185942a JA |
1539 | /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only |
1540 | if the built-in stack extension method is used). | |
726f6388 | 1541 | |
3185942a JA |
1542 | Do not make this value too large; the results are undefined if |
1543 | YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH) | |
1544 | evaluated with infinite-precision integer arithmetic. */ | |
726f6388 | 1545 | |
f73dda09 | 1546 | #ifndef YYMAXDEPTH |
3185942a | 1547 | # define YYMAXDEPTH 10000 |
f73dda09 | 1548 | #endif |
3185942a | 1549 | |
f73dda09 | 1550 | \f |
3185942a JA |
1551 | |
1552 | #if YYERROR_VERBOSE | |
1553 | ||
1554 | # ifndef yystrlen | |
1555 | # if defined __GLIBC__ && defined _STRING_H | |
1556 | # define yystrlen strlen | |
1557 | # else | |
1558 | /* Return the length of YYSTR. */ | |
1559 | #if (defined __STDC__ || defined __C99__FUNC__ \ | |
1560 | || defined __cplusplus || defined _MSC_VER) | |
1561 | static YYSIZE_T | |
1562 | yystrlen (const char *yystr) | |
1563 | #else | |
1564 | static YYSIZE_T | |
1565 | yystrlen (yystr) | |
1566 | const char *yystr; | |
1567 | #endif | |
1568 | { | |
1569 | YYSIZE_T yylen; | |
1570 | for (yylen = 0; yystr[yylen]; yylen++) | |
1571 | continue; | |
1572 | return yylen; | |
1573 | } | |
1574 | # endif | |
1575 | # endif | |
1576 | ||
1577 | # ifndef yystpcpy | |
1578 | # if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE | |
1579 | # define yystpcpy stpcpy | |
1580 | # else | |
1581 | /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in | |
1582 | YYDEST. */ | |
1583 | #if (defined __STDC__ || defined __C99__FUNC__ \ | |
1584 | || defined __cplusplus || defined _MSC_VER) | |
1585 | static char * | |
1586 | yystpcpy (char *yydest, const char *yysrc) | |
1587 | #else | |
1588 | static char * | |
1589 | yystpcpy (yydest, yysrc) | |
1590 | char *yydest; | |
1591 | const char *yysrc; | |
1592 | #endif | |
726f6388 | 1593 | { |
3185942a JA |
1594 | char *yyd = yydest; |
1595 | const char *yys = yysrc; | |
1596 | ||
1597 | while ((*yyd++ = *yys++) != '\0') | |
1598 | continue; | |
1599 | ||
1600 | return yyd - 1; | |
1601 | } | |
1602 | # endif | |
1603 | # endif | |
1604 | ||
1605 | # ifndef yytnamerr | |
1606 | /* Copy to YYRES the contents of YYSTR after stripping away unnecessary | |
1607 | quotes and backslashes, so that it's suitable for yyerror. The | |
1608 | heuristic is that double-quoting is unnecessary unless the string | |
1609 | contains an apostrophe, a comma, or backslash (other than | |
1610 | backslash-backslash). YYSTR is taken from yytname. If YYRES is | |
1611 | null, do not copy; instead, return the length of what the result | |
1612 | would have been. */ | |
1613 | static YYSIZE_T | |
1614 | yytnamerr (char *yyres, const char *yystr) | |
1615 | { | |
1616 | if (*yystr == '"') | |
1617 | { | |
1618 | YYSIZE_T yyn = 0; | |
1619 | char const *yyp = yystr; | |
1620 | ||
1621 | for (;;) | |
1622 | switch (*++yyp) | |
1623 | { | |
1624 | case '\'': | |
1625 | case ',': | |
1626 | goto do_not_strip_quotes; | |
1627 | ||
1628 | case '\\': | |
1629 | if (*++yyp != '\\') | |
1630 | goto do_not_strip_quotes; | |
1631 | /* Fall through. */ | |
1632 | default: | |
1633 | if (yyres) | |
1634 | yyres[yyn] = *yyp; | |
1635 | yyn++; | |
1636 | break; | |
1637 | ||
1638 | case '"': | |
1639 | if (yyres) | |
1640 | yyres[yyn] = '\0'; | |
1641 | return yyn; | |
1642 | } | |
1643 | do_not_strip_quotes: ; | |
1644 | } | |
f73dda09 | 1645 | |
3185942a JA |
1646 | if (! yyres) |
1647 | return yystrlen (yystr); | |
1648 | ||
1649 | return yystpcpy (yyres, yystr) - yyres; | |
1650 | } | |
1651 | # endif | |
1652 | ||
1653 | /* Copy into YYRESULT an error message about the unexpected token | |
1654 | YYCHAR while in state YYSTATE. Return the number of bytes copied, | |
1655 | including the terminating null byte. If YYRESULT is null, do not | |
1656 | copy anything; just return the number of bytes that would be | |
1657 | copied. As a special case, return 0 if an ordinary "syntax error" | |
1658 | message will do. Return YYSIZE_MAXIMUM if overflow occurs during | |
1659 | size calculation. */ | |
1660 | static YYSIZE_T | |
1661 | yysyntax_error (char *yyresult, int yystate, int yychar) | |
1662 | { | |
1663 | int yyn = yypact[yystate]; | |
1664 | ||
1665 | if (! (YYPACT_NINF < yyn && yyn <= YYLAST)) | |
1666 | return 0; | |
1667 | else | |
1668 | { | |
1669 | int yytype = YYTRANSLATE (yychar); | |
1670 | YYSIZE_T yysize0 = yytnamerr (0, yytname[yytype]); | |
1671 | YYSIZE_T yysize = yysize0; | |
1672 | YYSIZE_T yysize1; | |
1673 | int yysize_overflow = 0; | |
1674 | enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 }; | |
1675 | char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM]; | |
1676 | int yyx; | |
1677 | ||
1678 | # if 0 | |
1679 | /* This is so xgettext sees the translatable formats that are | |
1680 | constructed on the fly. */ | |
1681 | YY_("syntax error, unexpected %s"); | |
1682 | YY_("syntax error, unexpected %s, expecting %s"); | |
1683 | YY_("syntax error, unexpected %s, expecting %s or %s"); | |
1684 | YY_("syntax error, unexpected %s, expecting %s or %s or %s"); | |
1685 | YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"); | |
1686 | # endif | |
1687 | char *yyfmt; | |
1688 | char const *yyf; | |
1689 | static char const yyunexpected[] = "syntax error, unexpected %s"; | |
1690 | static char const yyexpecting[] = ", expecting %s"; | |
1691 | static char const yyor[] = " or %s"; | |
1692 | char yyformat[sizeof yyunexpected | |
1693 | + sizeof yyexpecting - 1 | |
1694 | + ((YYERROR_VERBOSE_ARGS_MAXIMUM - 2) | |
1695 | * (sizeof yyor - 1))]; | |
1696 | char const *yyprefix = yyexpecting; | |
1697 | ||
1698 | /* Start YYX at -YYN if negative to avoid negative indexes in | |
1699 | YYCHECK. */ | |
1700 | int yyxbegin = yyn < 0 ? -yyn : 0; | |
1701 | ||
1702 | /* Stay within bounds of both yycheck and yytname. */ | |
1703 | int yychecklim = YYLAST - yyn + 1; | |
1704 | int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS; | |
1705 | int yycount = 1; | |
1706 | ||
1707 | yyarg[0] = yytname[yytype]; | |
1708 | yyfmt = yystpcpy (yyformat, yyunexpected); | |
1709 | ||
1710 | for (yyx = yyxbegin; yyx < yyxend; ++yyx) | |
1711 | if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR) | |
1712 | { | |
1713 | if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM) | |
1714 | { | |
1715 | yycount = 1; | |
1716 | yysize = yysize0; | |
1717 | yyformat[sizeof yyunexpected - 1] = '\0'; | |
1718 | break; | |
1719 | } | |
1720 | yyarg[yycount++] = yytname[yyx]; | |
1721 | yysize1 = yysize + yytnamerr (0, yytname[yyx]); | |
1722 | yysize_overflow |= (yysize1 < yysize); | |
1723 | yysize = yysize1; | |
1724 | yyfmt = yystpcpy (yyfmt, yyprefix); | |
1725 | yyprefix = yyor; | |
1726 | } | |
1727 | ||
1728 | yyf = YY_(yyformat); | |
1729 | yysize1 = yysize + yystrlen (yyf); | |
1730 | yysize_overflow |= (yysize1 < yysize); | |
1731 | yysize = yysize1; | |
1732 | ||
1733 | if (yysize_overflow) | |
1734 | return YYSIZE_MAXIMUM; | |
1735 | ||
1736 | if (yyresult) | |
1737 | { | |
1738 | /* Avoid sprintf, as that infringes on the user's name space. | |
1739 | Don't have undefined behavior even if the translation | |
1740 | produced a string with the wrong number of "%s"s. */ | |
1741 | char *yyp = yyresult; | |
1742 | int yyi = 0; | |
1743 | while ((*yyp = *yyf) != '\0') | |
1744 | { | |
1745 | if (*yyp == '%' && yyf[1] == 's' && yyi < yycount) | |
1746 | { | |
1747 | yyp += yytnamerr (yyp, yyarg[yyi++]); | |
1748 | yyf += 2; | |
1749 | } | |
1750 | else | |
1751 | { | |
1752 | yyp++; | |
1753 | yyf++; | |
1754 | } | |
1755 | } | |
1756 | } | |
1757 | return yysize; | |
1758 | } | |
726f6388 | 1759 | } |
3185942a JA |
1760 | #endif /* YYERROR_VERBOSE */ |
1761 | \f | |
726f6388 | 1762 | |
3185942a JA |
1763 | /*-----------------------------------------------. |
1764 | | Release the memory associated to this symbol. | | |
1765 | `-----------------------------------------------*/ | |
726f6388 | 1766 | |
3185942a JA |
1767 | /*ARGSUSED*/ |
1768 | #if (defined __STDC__ || defined __C99__FUNC__ \ | |
1769 | || defined __cplusplus || defined _MSC_VER) | |
1770 | static void | |
1771 | yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep) | |
1772 | #else | |
b80f6443 | 1773 | static void |
3185942a JA |
1774 | yydestruct (yymsg, yytype, yyvaluep) |
1775 | const char *yymsg; | |
1776 | int yytype; | |
1777 | YYSTYPE *yyvaluep; | |
1778 | #endif | |
7117c2d2 | 1779 | { |
3185942a | 1780 | YYUSE (yyvaluep); |
726f6388 | 1781 | |
3185942a JA |
1782 | if (!yymsg) |
1783 | yymsg = "Deleting"; | |
1784 | YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp); | |
b80f6443 | 1785 | |
3185942a JA |
1786 | switch (yytype) |
1787 | { | |
1788 | ||
1789 | default: | |
1790 | break; | |
1791 | } | |
1792 | } | |
f73dda09 | 1793 | \f |
f73dda09 | 1794 | |
3185942a | 1795 | /* Prevent warnings from -Wmissing-prototypes. */ |
f73dda09 JA |
1796 | |
1797 | #ifdef YYPARSE_PARAM | |
3185942a JA |
1798 | #if defined __STDC__ || defined __cplusplus |
1799 | int yyparse (void *YYPARSE_PARAM); | |
b80f6443 | 1800 | #else |
3185942a | 1801 | int yyparse (); |
f73dda09 | 1802 | #endif |
3185942a JA |
1803 | #else /* ! YYPARSE_PARAM */ |
1804 | #if defined __STDC__ || defined __cplusplus | |
1805 | int yyparse (void); | |
1806 | #else | |
1807 | int yyparse (); | |
726f6388 | 1808 | #endif |
3185942a JA |
1809 | #endif /* ! YYPARSE_PARAM */ |
1810 | ||
726f6388 | 1811 | |
726f6388 | 1812 | |
3185942a JA |
1813 | /* The look-ahead symbol. */ |
1814 | int yychar; | |
b80f6443 | 1815 | |
3185942a JA |
1816 | /* The semantic value of the look-ahead symbol. */ |
1817 | YYSTYPE yylval; | |
b80f6443 | 1818 | |
3185942a JA |
1819 | /* Number of syntax errors so far. */ |
1820 | int yynerrs; | |
726f6388 | 1821 | |
3185942a JA |
1822 | |
1823 | ||
1824 | /*----------. | |
1825 | | yyparse. | | |
1826 | `----------*/ | |
1827 | ||
1828 | #ifdef YYPARSE_PARAM | |
1829 | #if (defined __STDC__ || defined __C99__FUNC__ \ | |
1830 | || defined __cplusplus || defined _MSC_VER) | |
1831 | int | |
1832 | yyparse (void *YYPARSE_PARAM) | |
f73dda09 | 1833 | #else |
3185942a JA |
1834 | int |
1835 | yyparse (YYPARSE_PARAM) | |
1836 | void *YYPARSE_PARAM; | |
f73dda09 | 1837 | #endif |
3185942a JA |
1838 | #else /* ! YYPARSE_PARAM */ |
1839 | #if (defined __STDC__ || defined __C99__FUNC__ \ | |
1840 | || defined __cplusplus || defined _MSC_VER) | |
1841 | int | |
1842 | yyparse (void) | |
1843 | #else | |
1844 | int | |
1845 | yyparse () | |
726f6388 | 1846 | |
b80f6443 | 1847 | #endif |
3185942a JA |
1848 | #endif |
1849 | { | |
1850 | ||
1851 | int yystate; | |
1852 | int yyn; | |
1853 | int yyresult; | |
1854 | /* Number of tokens to shift before error messages enabled. */ | |
1855 | int yyerrstatus; | |
1856 | /* Look-ahead token as an internal (translated) token number. */ | |
1857 | int yytoken = 0; | |
1858 | #if YYERROR_VERBOSE | |
1859 | /* Buffer for error messages, and its allocated size. */ | |
1860 | char yymsgbuf[128]; | |
1861 | char *yymsg = yymsgbuf; | |
1862 | YYSIZE_T yymsg_alloc = sizeof yymsgbuf; | |
7117c2d2 | 1863 | #endif |
726f6388 | 1864 | |
3185942a JA |
1865 | /* Three stacks and their tools: |
1866 | `yyss': related to states, | |
1867 | `yyvs': related to semantic values, | |
1868 | `yyls': related to locations. | |
b80f6443 | 1869 | |
3185942a JA |
1870 | Refer to the stacks thru separate pointers, to allow yyoverflow |
1871 | to reallocate them elsewhere. */ | |
726f6388 | 1872 | |
3185942a JA |
1873 | /* The state stack. */ |
1874 | yytype_int16 yyssa[YYINITDEPTH]; | |
1875 | yytype_int16 *yyss = yyssa; | |
1876 | yytype_int16 *yyssp; | |
1877 | ||
1878 | /* The semantic value stack. */ | |
1879 | YYSTYPE yyvsa[YYINITDEPTH]; | |
1880 | YYSTYPE *yyvs = yyvsa; | |
1881 | YYSTYPE *yyvsp; | |
1882 | ||
1883 | ||
1884 | ||
1885 | #define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N)) | |
1886 | ||
1887 | YYSIZE_T yystacksize = YYINITDEPTH; | |
1888 | ||
1889 | /* The variables used to return semantic value and location from the | |
1890 | action routines. */ | |
1891 | YYSTYPE yyval; | |
1892 | ||
1893 | ||
1894 | /* The number of symbols on the RHS of the reduced rule. | |
1895 | Keep to zero when no symbol should be popped. */ | |
1896 | int yylen = 0; | |
1897 | ||
1898 | YYDPRINTF ((stderr, "Starting parse\n")); | |
726f6388 | 1899 | |
f73dda09 JA |
1900 | yystate = 0; |
1901 | yyerrstatus = 0; | |
1902 | yynerrs = 0; | |
1903 | yychar = YYEMPTY; /* Cause a token to be read. */ | |
1904 | ||
1905 | /* Initialize stack pointers. | |
1906 | Waste one element of value and location stack | |
1907 | so that they stay on the same level as the state stack. | |
1908 | The wasted elements are never initialized. */ | |
1909 | ||
3185942a | 1910 | yyssp = yyss; |
f73dda09 | 1911 | yyvsp = yyvs; |
f73dda09 | 1912 | |
3185942a | 1913 | goto yysetstate; |
f73dda09 | 1914 | |
3185942a JA |
1915 | /*------------------------------------------------------------. |
1916 | | yynewstate -- Push a new state, which is found in yystate. | | |
1917 | `------------------------------------------------------------*/ | |
1918 | yynewstate: | |
1919 | /* In all cases, when you get here, the value and location stacks | |
1920 | have just been pushed. So pushing a state here evens the stacks. */ | |
1921 | yyssp++; | |
f73dda09 | 1922 | |
3185942a JA |
1923 | yysetstate: |
1924 | *yyssp = yystate; | |
b80f6443 | 1925 | |
3185942a JA |
1926 | if (yyss + yystacksize - 1 <= yyssp) |
1927 | { | |
f73dda09 | 1928 | /* Get the current used size of the three stacks, in elements. */ |
3185942a | 1929 | YYSIZE_T yysize = yyssp - yyss + 1; |
f73dda09 JA |
1930 | |
1931 | #ifdef yyoverflow | |
3185942a JA |
1932 | { |
1933 | /* Give user a chance to reallocate the stack. Use copies of | |
1934 | these so that the &'s don't force the real ones into | |
1935 | memory. */ | |
1936 | YYSTYPE *yyvs1 = yyvs; | |
1937 | yytype_int16 *yyss1 = yyss; | |
b80f6443 | 1938 | |
3185942a JA |
1939 | |
1940 | /* Each stack pointer address is followed by the size of the | |
1941 | data in use in that stack, in bytes. This used to be a | |
1942 | conditional around just the two extra args, but that might | |
1943 | be undefined if yyoverflow is a macro. */ | |
1944 | yyoverflow (YY_("memory exhausted"), | |
1945 | &yyss1, yysize * sizeof (*yyssp), | |
1946 | &yyvs1, yysize * sizeof (*yyvsp), | |
1947 | ||
1948 | &yystacksize); | |
1949 | ||
1950 | yyss = yyss1; | |
1951 | yyvs = yyvs1; | |
1952 | } | |
f73dda09 | 1953 | #else /* no yyoverflow */ |
3185942a JA |
1954 | # ifndef YYSTACK_RELOCATE |
1955 | goto yyexhaustedlab; | |
1956 | # else | |
f73dda09 | 1957 | /* Extend the stack our own way. */ |
3185942a JA |
1958 | if (YYMAXDEPTH <= yystacksize) |
1959 | goto yyexhaustedlab; | |
f73dda09 | 1960 | yystacksize *= 2; |
3185942a | 1961 | if (YYMAXDEPTH < yystacksize) |
f73dda09 | 1962 | yystacksize = YYMAXDEPTH; |
3185942a JA |
1963 | |
1964 | { | |
1965 | yytype_int16 *yyss1 = yyss; | |
1966 | union yyalloc *yyptr = | |
1967 | (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize)); | |
1968 | if (! yyptr) | |
1969 | goto yyexhaustedlab; | |
1970 | YYSTACK_RELOCATE (yyss); | |
1971 | YYSTACK_RELOCATE (yyvs); | |
1972 | ||
1973 | # undef YYSTACK_RELOCATE | |
1974 | if (yyss1 != yyssa) | |
1975 | YYSTACK_FREE (yyss1); | |
1976 | } | |
1977 | # endif | |
f73dda09 | 1978 | #endif /* no yyoverflow */ |
726f6388 | 1979 | |
3185942a JA |
1980 | yyssp = yyss + yysize - 1; |
1981 | yyvsp = yyvs + yysize - 1; | |
726f6388 | 1982 | |
726f6388 | 1983 | |
3185942a JA |
1984 | YYDPRINTF ((stderr, "Stack size increased to %lu\n", |
1985 | (unsigned long int) yystacksize)); | |
1986 | ||
1987 | if (yyss + yystacksize - 1 <= yyssp) | |
f73dda09 | 1988 | YYABORT; |
726f6388 JA |
1989 | } |
1990 | ||
3185942a | 1991 | YYDPRINTF ((stderr, "Entering state %d\n", yystate)); |
28ef6c31 | 1992 | |
f73dda09 | 1993 | goto yybackup; |
28ef6c31 | 1994 | |
3185942a JA |
1995 | /*-----------. |
1996 | | yybackup. | | |
1997 | `-----------*/ | |
1998 | yybackup: | |
28ef6c31 | 1999 | |
3185942a JA |
2000 | /* Do appropriate processing given the current state. Read a |
2001 | look-ahead token if we need one and don't already have one. */ | |
726f6388 | 2002 | |
3185942a | 2003 | /* First try to decide what to do without reference to look-ahead token. */ |
f73dda09 | 2004 | yyn = yypact[yystate]; |
3185942a | 2005 | if (yyn == YYPACT_NINF) |
f73dda09 | 2006 | goto yydefault; |
726f6388 | 2007 | |
3185942a | 2008 | /* Not known => get a look-ahead token if don't already have one. */ |
726f6388 | 2009 | |
3185942a | 2010 | /* YYCHAR is either YYEMPTY or YYEOF or a valid look-ahead symbol. */ |
f73dda09 | 2011 | if (yychar == YYEMPTY) |
726f6388 | 2012 | { |
3185942a | 2013 | YYDPRINTF ((stderr, "Reading a token: ")); |
f73dda09 | 2014 | yychar = YYLEX; |
726f6388 | 2015 | } |
726f6388 | 2016 | |
3185942a | 2017 | if (yychar <= YYEOF) |
f73dda09 | 2018 | { |
3185942a JA |
2019 | yychar = yytoken = YYEOF; |
2020 | YYDPRINTF ((stderr, "Now at end of input.\n")); | |
f73dda09 JA |
2021 | } |
2022 | else | |
2023 | { | |
3185942a JA |
2024 | yytoken = YYTRANSLATE (yychar); |
2025 | YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc); | |
f73dda09 | 2026 | } |
726f6388 | 2027 | |
3185942a JA |
2028 | /* If the proper action on seeing token YYTOKEN is to reduce or to |
2029 | detect an error, take that action. */ | |
2030 | yyn += yytoken; | |
2031 | if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken) | |
f73dda09 | 2032 | goto yydefault; |
f73dda09 | 2033 | yyn = yytable[yyn]; |
3185942a | 2034 | if (yyn <= 0) |
f73dda09 | 2035 | { |
3185942a | 2036 | if (yyn == 0 || yyn == YYTABLE_NINF) |
f73dda09 JA |
2037 | goto yyerrlab; |
2038 | yyn = -yyn; | |
2039 | goto yyreduce; | |
2040 | } | |
726f6388 | 2041 | |
f73dda09 JA |
2042 | if (yyn == YYFINAL) |
2043 | YYACCEPT; | |
726f6388 | 2044 | |
3185942a JA |
2045 | /* Count tokens shifted since error; after three, turn off error |
2046 | status. */ | |
2047 | if (yyerrstatus) | |
2048 | yyerrstatus--; | |
b80f6443 | 2049 | |
3185942a JA |
2050 | /* Shift the look-ahead token. */ |
2051 | YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc); | |
726f6388 | 2052 | |
3185942a | 2053 | /* Discard the shifted token unless it is eof. */ |
f73dda09 JA |
2054 | if (yychar != YYEOF) |
2055 | yychar = YYEMPTY; | |
28ef6c31 | 2056 | |
3185942a | 2057 | yystate = yyn; |
f73dda09 | 2058 | *++yyvsp = yylval; |
28ef6c31 | 2059 | |
f73dda09 | 2060 | goto yynewstate; |
726f6388 | 2061 | |
b80f6443 | 2062 | |
3185942a JA |
2063 | /*-----------------------------------------------------------. |
2064 | | yydefault -- do the default action for the current state. | | |
2065 | `-----------------------------------------------------------*/ | |
2066 | yydefault: | |
f73dda09 JA |
2067 | yyn = yydefact[yystate]; |
2068 | if (yyn == 0) | |
2069 | goto yyerrlab; | |
3185942a | 2070 | goto yyreduce; |
28ef6c31 | 2071 | |
3185942a JA |
2072 | |
2073 | /*-----------------------------. | |
2074 | | yyreduce -- Do a reduction. | | |
2075 | `-----------------------------*/ | |
f73dda09 | 2076 | yyreduce: |
3185942a | 2077 | /* yyn is the number of a rule to reduce with. */ |
f73dda09 | 2078 | yylen = yyr2[yyn]; |
28ef6c31 | 2079 | |
3185942a JA |
2080 | /* If YYLEN is nonzero, implement the default value of the action: |
2081 | `$$ = $1'. | |
28ef6c31 | 2082 | |
3185942a JA |
2083 | Otherwise, the following line sets YYVAL to garbage. |
2084 | This behavior is undocumented and Bison | |
2085 | users should not rely upon it. Assigning to YYVAL | |
2086 | unconditionally makes the parser a bit smaller, and it avoids a | |
2087 | GCC warning that YYVAL may be used uninitialized. */ | |
2088 | yyval = yyvsp[1-yylen]; | |
b80f6443 | 2089 | |
28ef6c31 | 2090 | |
3185942a JA |
2091 | YY_REDUCE_PRINT (yyn); |
2092 | switch (yyn) | |
2093 | { | |
2094 | case 2: | |
495aee44 | 2095 | #line 377 "/Users/chet/src/bash/src/parse.y" |
3185942a | 2096 | { |
f73dda09 JA |
2097 | /* Case of regular command. Discard the error |
2098 | safety net,and return the command just parsed. */ | |
3185942a | 2099 | global_command = (yyvsp[(1) - (2)].command); |
f73dda09 | 2100 | eof_encountered = 0; |
7117c2d2 | 2101 | /* discard_parser_constructs (0); */ |
3185942a JA |
2102 | if (parser_state & PST_CMDSUBST) |
2103 | parser_state |= PST_EOFTOKEN; | |
f73dda09 | 2104 | YYACCEPT; |
3185942a JA |
2105 | } |
2106 | break; | |
2107 | ||
2108 | case 3: | |
495aee44 | 2109 | #line 388 "/Users/chet/src/bash/src/parse.y" |
3185942a | 2110 | { |
f73dda09 JA |
2111 | /* Case of regular command, but not a very |
2112 | interesting one. Return a NULL command. */ | |
2113 | global_command = (COMMAND *)NULL; | |
3185942a JA |
2114 | if (parser_state & PST_CMDSUBST) |
2115 | parser_state |= PST_EOFTOKEN; | |
f73dda09 | 2116 | YYACCEPT; |
3185942a JA |
2117 | } |
2118 | break; | |
2119 | ||
2120 | case 4: | |
495aee44 | 2121 | #line 397 "/Users/chet/src/bash/src/parse.y" |
3185942a | 2122 | { |
f73dda09 JA |
2123 | /* Error during parsing. Return NULL command. */ |
2124 | global_command = (COMMAND *)NULL; | |
2125 | eof_encountered = 0; | |
7117c2d2 | 2126 | /* discard_parser_constructs (1); */ |
3185942a | 2127 | if (interactive && parse_and_execute_level == 0) |
f73dda09 JA |
2128 | { |
2129 | YYACCEPT; | |
2130 | } | |
2131 | else | |
2132 | { | |
2133 | YYABORT; | |
2134 | } | |
3185942a JA |
2135 | } |
2136 | break; | |
2137 | ||
2138 | case 5: | |
495aee44 | 2139 | #line 412 "/Users/chet/src/bash/src/parse.y" |
3185942a | 2140 | { |
f73dda09 JA |
2141 | /* Case of EOF seen by itself. Do ignoreeof or |
2142 | not. */ | |
2143 | global_command = (COMMAND *)NULL; | |
2144 | handle_eof_input_unit (); | |
2145 | YYACCEPT; | |
3185942a JA |
2146 | } |
2147 | break; | |
2148 | ||
2149 | case 6: | |
495aee44 | 2150 | #line 422 "/Users/chet/src/bash/src/parse.y" |
3185942a JA |
2151 | { (yyval.word_list) = make_word_list ((yyvsp[(1) - (1)].word), (WORD_LIST *)NULL); } |
2152 | break; | |
2153 | ||
2154 | case 7: | |
495aee44 | 2155 | #line 424 "/Users/chet/src/bash/src/parse.y" |
3185942a JA |
2156 | { (yyval.word_list) = make_word_list ((yyvsp[(2) - (2)].word), (yyvsp[(1) - (2)].word_list)); } |
2157 | break; | |
2158 | ||
2159 | case 8: | |
495aee44 | 2160 | #line 428 "/Users/chet/src/bash/src/parse.y" |
3185942a | 2161 | { |
0001803f | 2162 | source.dest = 1; |
3185942a | 2163 | redir.filename = (yyvsp[(2) - (2)].word); |
0001803f | 2164 | (yyval.redirect) = make_redirection (source, r_output_direction, redir, 0); |
3185942a JA |
2165 | } |
2166 | break; | |
2167 | ||
2168 | case 9: | |
495aee44 | 2169 | #line 434 "/Users/chet/src/bash/src/parse.y" |
3185942a | 2170 | { |
0001803f | 2171 | source.dest = 0; |
3185942a | 2172 | redir.filename = (yyvsp[(2) - (2)].word); |
0001803f | 2173 | (yyval.redirect) = make_redirection (source, r_input_direction, redir, 0); |
3185942a JA |
2174 | } |
2175 | break; | |
2176 | ||
2177 | case 10: | |
495aee44 | 2178 | #line 440 "/Users/chet/src/bash/src/parse.y" |
3185942a | 2179 | { |
0001803f | 2180 | source.dest = (yyvsp[(1) - (3)].number); |
3185942a | 2181 | redir.filename = (yyvsp[(3) - (3)].word); |
0001803f | 2182 | (yyval.redirect) = make_redirection (source, r_output_direction, redir, 0); |
3185942a JA |
2183 | } |
2184 | break; | |
2185 | ||
2186 | case 11: | |
495aee44 | 2187 | #line 446 "/Users/chet/src/bash/src/parse.y" |
3185942a | 2188 | { |
0001803f | 2189 | source.dest = (yyvsp[(1) - (3)].number); |
3185942a | 2190 | redir.filename = (yyvsp[(3) - (3)].word); |
0001803f | 2191 | (yyval.redirect) = make_redirection (source, r_input_direction, redir, 0); |
3185942a JA |
2192 | } |
2193 | break; | |
2194 | ||
2195 | case 12: | |
495aee44 | 2196 | #line 452 "/Users/chet/src/bash/src/parse.y" |
3185942a | 2197 | { |
0001803f CR |
2198 | source.filename = (yyvsp[(1) - (3)].word); |
2199 | redir.filename = (yyvsp[(3) - (3)].word); | |
2200 | (yyval.redirect) = make_redirection (source, r_output_direction, redir, REDIR_VARASSIGN); | |
3185942a JA |
2201 | } |
2202 | break; | |
2203 | ||
2204 | case 13: | |
495aee44 | 2205 | #line 458 "/Users/chet/src/bash/src/parse.y" |
3185942a | 2206 | { |
0001803f | 2207 | source.filename = (yyvsp[(1) - (3)].word); |
3185942a | 2208 | redir.filename = (yyvsp[(3) - (3)].word); |
0001803f | 2209 | (yyval.redirect) = make_redirection (source, r_input_direction, redir, REDIR_VARASSIGN); |
3185942a JA |
2210 | } |
2211 | break; | |
2212 | ||
2213 | case 14: | |
495aee44 | 2214 | #line 464 "/Users/chet/src/bash/src/parse.y" |
3185942a | 2215 | { |
0001803f | 2216 | source.dest = 1; |
3185942a | 2217 | redir.filename = (yyvsp[(2) - (2)].word); |
0001803f | 2218 | (yyval.redirect) = make_redirection (source, r_appending_to, redir, 0); |
3185942a JA |
2219 | } |
2220 | break; | |
2221 | ||
2222 | case 15: | |
495aee44 | 2223 | #line 470 "/Users/chet/src/bash/src/parse.y" |
3185942a | 2224 | { |
0001803f | 2225 | source.dest = (yyvsp[(1) - (3)].number); |
3185942a | 2226 | redir.filename = (yyvsp[(3) - (3)].word); |
0001803f | 2227 | (yyval.redirect) = make_redirection (source, r_appending_to, redir, 0); |
3185942a JA |
2228 | } |
2229 | break; | |
2230 | ||
2231 | case 16: | |
495aee44 | 2232 | #line 476 "/Users/chet/src/bash/src/parse.y" |
3185942a | 2233 | { |
0001803f CR |
2234 | source.filename = (yyvsp[(1) - (3)].word); |
2235 | redir.filename = (yyvsp[(3) - (3)].word); | |
2236 | (yyval.redirect) = make_redirection (source, r_appending_to, redir, REDIR_VARASSIGN); | |
3185942a JA |
2237 | } |
2238 | break; | |
2239 | ||
2240 | case 17: | |
495aee44 | 2241 | #line 482 "/Users/chet/src/bash/src/parse.y" |
3185942a | 2242 | { |
0001803f CR |
2243 | source.dest = 1; |
2244 | redir.filename = (yyvsp[(2) - (2)].word); | |
2245 | (yyval.redirect) = make_redirection (source, r_output_force, redir, 0); | |
3185942a JA |
2246 | } |
2247 | break; | |
2248 | ||
2249 | case 18: | |
495aee44 | 2250 | #line 488 "/Users/chet/src/bash/src/parse.y" |
3185942a | 2251 | { |
0001803f CR |
2252 | source.dest = (yyvsp[(1) - (3)].number); |
2253 | redir.filename = (yyvsp[(3) - (3)].word); | |
2254 | (yyval.redirect) = make_redirection (source, r_output_force, redir, 0); | |
3185942a JA |
2255 | } |
2256 | break; | |
2257 | ||
2258 | case 19: | |
495aee44 | 2259 | #line 494 "/Users/chet/src/bash/src/parse.y" |
3185942a | 2260 | { |
0001803f CR |
2261 | source.filename = (yyvsp[(1) - (3)].word); |
2262 | redir.filename = (yyvsp[(3) - (3)].word); | |
2263 | (yyval.redirect) = make_redirection (source, r_output_force, redir, REDIR_VARASSIGN); | |
3185942a JA |
2264 | } |
2265 | break; | |
2266 | ||
2267 | case 20: | |
495aee44 | 2268 | #line 500 "/Users/chet/src/bash/src/parse.y" |
3185942a | 2269 | { |
0001803f CR |
2270 | source.dest = 0; |
2271 | redir.filename = (yyvsp[(2) - (2)].word); | |
2272 | (yyval.redirect) = make_redirection (source, r_input_output, redir, 0); | |
3185942a JA |
2273 | } |
2274 | break; | |
2275 | ||
2276 | case 21: | |
495aee44 | 2277 | #line 506 "/Users/chet/src/bash/src/parse.y" |
3185942a | 2278 | { |
0001803f CR |
2279 | source.dest = (yyvsp[(1) - (3)].number); |
2280 | redir.filename = (yyvsp[(3) - (3)].word); | |
2281 | (yyval.redirect) = make_redirection (source, r_input_output, redir, 0); | |
3185942a JA |
2282 | } |
2283 | break; | |
2284 | ||
2285 | case 22: | |
495aee44 | 2286 | #line 512 "/Users/chet/src/bash/src/parse.y" |
3185942a | 2287 | { |
0001803f CR |
2288 | source.filename = (yyvsp[(1) - (3)].word); |
2289 | redir.filename = (yyvsp[(3) - (3)].word); | |
2290 | (yyval.redirect) = make_redirection (source, r_input_output, redir, REDIR_VARASSIGN); | |
3185942a JA |
2291 | } |
2292 | break; | |
2293 | ||
2294 | case 23: | |
495aee44 | 2295 | #line 518 "/Users/chet/src/bash/src/parse.y" |
3185942a | 2296 | { |
0001803f CR |
2297 | source.dest = 0; |
2298 | redir.filename = (yyvsp[(2) - (2)].word); | |
2299 | (yyval.redirect) = make_redirection (source, r_reading_until, redir, 0); | |
2300 | redir_stack[need_here_doc++] = (yyval.redirect); | |
3185942a JA |
2301 | } |
2302 | break; | |
2303 | ||
2304 | case 24: | |
495aee44 | 2305 | #line 525 "/Users/chet/src/bash/src/parse.y" |
3185942a | 2306 | { |
0001803f CR |
2307 | source.dest = (yyvsp[(1) - (3)].number); |
2308 | redir.filename = (yyvsp[(3) - (3)].word); | |
2309 | (yyval.redirect) = make_redirection (source, r_reading_until, redir, 0); | |
2310 | redir_stack[need_here_doc++] = (yyval.redirect); | |
3185942a JA |
2311 | } |
2312 | break; | |
2313 | ||
2314 | case 25: | |
495aee44 | 2315 | #line 532 "/Users/chet/src/bash/src/parse.y" |
3185942a | 2316 | { |
0001803f | 2317 | source.filename = (yyvsp[(1) - (3)].word); |
3185942a | 2318 | redir.filename = (yyvsp[(3) - (3)].word); |
0001803f CR |
2319 | (yyval.redirect) = make_redirection (source, r_reading_until, redir, REDIR_VARASSIGN); |
2320 | redir_stack[need_here_doc++] = (yyval.redirect); | |
3185942a JA |
2321 | } |
2322 | break; | |
2323 | ||
2324 | case 26: | |
495aee44 | 2325 | #line 539 "/Users/chet/src/bash/src/parse.y" |
3185942a | 2326 | { |
0001803f | 2327 | source.dest = 0; |
3185942a | 2328 | redir.filename = (yyvsp[(2) - (2)].word); |
0001803f | 2329 | (yyval.redirect) = make_redirection (source, r_deblank_reading_until, redir, 0); |
3185942a JA |
2330 | redir_stack[need_here_doc++] = (yyval.redirect); |
2331 | } | |
2332 | break; | |
2333 | ||
2334 | case 27: | |
495aee44 | 2335 | #line 546 "/Users/chet/src/bash/src/parse.y" |
3185942a | 2336 | { |
0001803f | 2337 | source.dest = (yyvsp[(1) - (3)].number); |
3185942a | 2338 | redir.filename = (yyvsp[(3) - (3)].word); |
0001803f | 2339 | (yyval.redirect) = make_redirection (source, r_deblank_reading_until, redir, 0); |
3185942a JA |
2340 | redir_stack[need_here_doc++] = (yyval.redirect); |
2341 | } | |
2342 | break; | |
2343 | ||
2344 | case 28: | |
495aee44 | 2345 | #line 553 "/Users/chet/src/bash/src/parse.y" |
3185942a | 2346 | { |
0001803f CR |
2347 | source.filename = (yyvsp[(1) - (3)].word); |
2348 | redir.filename = (yyvsp[(3) - (3)].word); | |
2349 | (yyval.redirect) = make_redirection (source, r_deblank_reading_until, redir, REDIR_VARASSIGN); | |
2350 | redir_stack[need_here_doc++] = (yyval.redirect); | |
3185942a JA |
2351 | } |
2352 | break; | |
2353 | ||
2354 | case 29: | |
495aee44 | 2355 | #line 560 "/Users/chet/src/bash/src/parse.y" |
3185942a | 2356 | { |
0001803f CR |
2357 | source.dest = 0; |
2358 | redir.filename = (yyvsp[(2) - (2)].word); | |
2359 | (yyval.redirect) = make_redirection (source, r_reading_string, redir, 0); | |
3185942a JA |
2360 | } |
2361 | break; | |
2362 | ||
2363 | case 30: | |
495aee44 | 2364 | #line 566 "/Users/chet/src/bash/src/parse.y" |
3185942a | 2365 | { |
0001803f CR |
2366 | source.dest = (yyvsp[(1) - (3)].number); |
2367 | redir.filename = (yyvsp[(3) - (3)].word); | |
2368 | (yyval.redirect) = make_redirection (source, r_reading_string, redir, 0); | |
3185942a JA |
2369 | } |
2370 | break; | |
2371 | ||
2372 | case 31: | |
495aee44 | 2373 | #line 572 "/Users/chet/src/bash/src/parse.y" |
3185942a | 2374 | { |
0001803f CR |
2375 | source.filename = (yyvsp[(1) - (3)].word); |
2376 | redir.filename = (yyvsp[(3) - (3)].word); | |
2377 | (yyval.redirect) = make_redirection (source, r_reading_string, redir, REDIR_VARASSIGN); | |
3185942a JA |
2378 | } |
2379 | break; | |
2380 | ||
2381 | case 32: | |
495aee44 | 2382 | #line 578 "/Users/chet/src/bash/src/parse.y" |
3185942a | 2383 | { |
0001803f CR |
2384 | source.dest = 0; |
2385 | redir.dest = (yyvsp[(2) - (2)].number); | |
2386 | (yyval.redirect) = make_redirection (source, r_duplicating_input, redir, 0); | |
3185942a JA |
2387 | } |
2388 | break; | |
2389 | ||
2390 | case 33: | |
495aee44 | 2391 | #line 584 "/Users/chet/src/bash/src/parse.y" |
3185942a | 2392 | { |
0001803f CR |
2393 | source.dest = (yyvsp[(1) - (3)].number); |
2394 | redir.dest = (yyvsp[(3) - (3)].number); | |
2395 | (yyval.redirect) = make_redirection (source, r_duplicating_input, redir, 0); | |
3185942a JA |
2396 | } |
2397 | break; | |
2398 | ||
2399 | case 34: | |
495aee44 | 2400 | #line 590 "/Users/chet/src/bash/src/parse.y" |
3185942a | 2401 | { |
0001803f CR |
2402 | source.filename = (yyvsp[(1) - (3)].word); |
2403 | redir.dest = (yyvsp[(3) - (3)].number); | |
2404 | (yyval.redirect) = make_redirection (source, r_duplicating_input, redir, REDIR_VARASSIGN); | |
3185942a JA |
2405 | } |
2406 | break; | |
2407 | ||
2408 | case 35: | |
495aee44 | 2409 | #line 596 "/Users/chet/src/bash/src/parse.y" |
3185942a | 2410 | { |
0001803f CR |
2411 | source.dest = 1; |
2412 | redir.dest = (yyvsp[(2) - (2)].number); | |
2413 | (yyval.redirect) = make_redirection (source, r_duplicating_output, redir, 0); | |
3185942a JA |
2414 | } |
2415 | break; | |
2416 | ||
2417 | case 36: | |
495aee44 | 2418 | #line 602 "/Users/chet/src/bash/src/parse.y" |
3185942a | 2419 | { |
0001803f CR |
2420 | source.dest = (yyvsp[(1) - (3)].number); |
2421 | redir.dest = (yyvsp[(3) - (3)].number); | |
2422 | (yyval.redirect) = make_redirection (source, r_duplicating_output, redir, 0); | |
3185942a JA |
2423 | } |
2424 | break; | |
2425 | ||
2426 | case 37: | |
495aee44 | 2427 | #line 608 "/Users/chet/src/bash/src/parse.y" |
3185942a | 2428 | { |
0001803f CR |
2429 | source.filename = (yyvsp[(1) - (3)].word); |
2430 | redir.dest = (yyvsp[(3) - (3)].number); | |
2431 | (yyval.redirect) = make_redirection (source, r_duplicating_output, redir, REDIR_VARASSIGN); | |
3185942a JA |
2432 | } |
2433 | break; | |
2434 | ||
2435 | case 38: | |
495aee44 | 2436 | #line 614 "/Users/chet/src/bash/src/parse.y" |
0001803f CR |
2437 | { |
2438 | source.dest = 0; | |
2439 | redir.filename = (yyvsp[(2) - (2)].word); | |
2440 | (yyval.redirect) = make_redirection (source, r_duplicating_input_word, redir, 0); | |
2441 | } | |
3185942a JA |
2442 | break; |
2443 | ||
2444 | case 39: | |
495aee44 | 2445 | #line 620 "/Users/chet/src/bash/src/parse.y" |
0001803f CR |
2446 | { |
2447 | source.dest = (yyvsp[(1) - (3)].number); | |
2448 | redir.filename = (yyvsp[(3) - (3)].word); | |
2449 | (yyval.redirect) = make_redirection (source, r_duplicating_input_word, redir, 0); | |
2450 | } | |
3185942a JA |
2451 | break; |
2452 | ||
2453 | case 40: | |
495aee44 | 2454 | #line 626 "/Users/chet/src/bash/src/parse.y" |
0001803f CR |
2455 | { |
2456 | source.filename = (yyvsp[(1) - (3)].word); | |
2457 | redir.filename = (yyvsp[(3) - (3)].word); | |
2458 | (yyval.redirect) = make_redirection (source, r_duplicating_input_word, redir, REDIR_VARASSIGN); | |
2459 | } | |
3185942a JA |
2460 | break; |
2461 | ||
2462 | case 41: | |
495aee44 | 2463 | #line 632 "/Users/chet/src/bash/src/parse.y" |
3185942a | 2464 | { |
0001803f CR |
2465 | source.dest = 1; |
2466 | redir.filename = (yyvsp[(2) - (2)].word); | |
2467 | (yyval.redirect) = make_redirection (source, r_duplicating_output_word, redir, 0); | |
3185942a JA |
2468 | } |
2469 | break; | |
2470 | ||
2471 | case 42: | |
495aee44 | 2472 | #line 638 "/Users/chet/src/bash/src/parse.y" |
0001803f CR |
2473 | { |
2474 | source.dest = (yyvsp[(1) - (3)].number); | |
2475 | redir.filename = (yyvsp[(3) - (3)].word); | |
2476 | (yyval.redirect) = make_redirection (source, r_duplicating_output_word, redir, 0); | |
2477 | } | |
2478 | break; | |
2479 | ||
2480 | case 43: | |
495aee44 | 2481 | #line 644 "/Users/chet/src/bash/src/parse.y" |
0001803f CR |
2482 | { |
2483 | source.filename = (yyvsp[(1) - (3)].word); | |
2484 | redir.filename = (yyvsp[(3) - (3)].word); | |
2485 | (yyval.redirect) = make_redirection (source, r_duplicating_output_word, redir, REDIR_VARASSIGN); | |
2486 | } | |
2487 | break; | |
2488 | ||
2489 | case 44: | |
495aee44 | 2490 | #line 650 "/Users/chet/src/bash/src/parse.y" |
0001803f CR |
2491 | { |
2492 | source.dest = 1; | |
2493 | redir.dest = 0; | |
2494 | (yyval.redirect) = make_redirection (source, r_close_this, redir, 0); | |
2495 | } | |
2496 | break; | |
2497 | ||
2498 | case 45: | |
495aee44 | 2499 | #line 656 "/Users/chet/src/bash/src/parse.y" |
0001803f CR |
2500 | { |
2501 | source.dest = (yyvsp[(1) - (3)].number); | |
2502 | redir.dest = 0; | |
2503 | (yyval.redirect) = make_redirection (source, r_close_this, redir, 0); | |
2504 | } | |
2505 | break; | |
2506 | ||
2507 | case 46: | |
495aee44 | 2508 | #line 662 "/Users/chet/src/bash/src/parse.y" |
0001803f CR |
2509 | { |
2510 | source.filename = (yyvsp[(1) - (3)].word); | |
2511 | redir.dest = 0; | |
2512 | (yyval.redirect) = make_redirection (source, r_close_this, redir, REDIR_VARASSIGN); | |
2513 | } | |
2514 | break; | |
2515 | ||
2516 | case 47: | |
495aee44 | 2517 | #line 668 "/Users/chet/src/bash/src/parse.y" |
0001803f CR |
2518 | { |
2519 | source.dest = 0; | |
2520 | redir.dest = 0; | |
2521 | (yyval.redirect) = make_redirection (source, r_close_this, redir, 0); | |
2522 | } | |
2523 | break; | |
2524 | ||
2525 | case 48: | |
495aee44 | 2526 | #line 674 "/Users/chet/src/bash/src/parse.y" |
0001803f CR |
2527 | { |
2528 | source.dest = (yyvsp[(1) - (3)].number); | |
2529 | redir.dest = 0; | |
2530 | (yyval.redirect) = make_redirection (source, r_close_this, redir, 0); | |
2531 | } | |
2532 | break; | |
2533 | ||
2534 | case 49: | |
495aee44 | 2535 | #line 680 "/Users/chet/src/bash/src/parse.y" |
0001803f CR |
2536 | { |
2537 | source.filename = (yyvsp[(1) - (3)].word); | |
2538 | redir.dest = 0; | |
2539 | (yyval.redirect) = make_redirection (source, r_close_this, redir, REDIR_VARASSIGN); | |
2540 | } | |
2541 | break; | |
2542 | ||
2543 | case 50: | |
495aee44 | 2544 | #line 686 "/Users/chet/src/bash/src/parse.y" |
0001803f CR |
2545 | { |
2546 | source.dest = 1; | |
2547 | redir.filename = (yyvsp[(2) - (2)].word); | |
2548 | (yyval.redirect) = make_redirection (source, r_err_and_out, redir, 0); | |
2549 | } | |
2550 | break; | |
2551 | ||
2552 | case 51: | |
495aee44 | 2553 | #line 692 "/Users/chet/src/bash/src/parse.y" |
0001803f CR |
2554 | { |
2555 | source.dest = 1; | |
2556 | redir.filename = (yyvsp[(2) - (2)].word); | |
2557 | (yyval.redirect) = make_redirection (source, r_append_err_and_out, redir, 0); | |
2558 | } | |
2559 | break; | |
2560 | ||
2561 | case 52: | |
495aee44 | 2562 | #line 700 "/Users/chet/src/bash/src/parse.y" |
0001803f CR |
2563 | { (yyval.element).word = (yyvsp[(1) - (1)].word); (yyval.element).redirect = 0; } |
2564 | break; | |
2565 | ||
2566 | case 53: | |
495aee44 | 2567 | #line 702 "/Users/chet/src/bash/src/parse.y" |
0001803f CR |
2568 | { (yyval.element).word = (yyvsp[(1) - (1)].word); (yyval.element).redirect = 0; } |
2569 | break; | |
2570 | ||
2571 | case 54: | |
495aee44 | 2572 | #line 704 "/Users/chet/src/bash/src/parse.y" |
0001803f CR |
2573 | { (yyval.element).redirect = (yyvsp[(1) - (1)].redirect); (yyval.element).word = 0; } |
2574 | break; | |
2575 | ||
2576 | case 55: | |
495aee44 | 2577 | #line 708 "/Users/chet/src/bash/src/parse.y" |
0001803f CR |
2578 | { |
2579 | (yyval.redirect) = (yyvsp[(1) - (1)].redirect); | |
2580 | } | |
2581 | break; | |
2582 | ||
2583 | case 56: | |
495aee44 | 2584 | #line 712 "/Users/chet/src/bash/src/parse.y" |
3185942a | 2585 | { |
f73dda09 JA |
2586 | register REDIRECT *t; |
2587 | ||
3185942a | 2588 | for (t = (yyvsp[(1) - (2)].redirect); t->next; t = t->next) |
f73dda09 | 2589 | ; |
3185942a JA |
2590 | t->next = (yyvsp[(2) - (2)].redirect); |
2591 | (yyval.redirect) = (yyvsp[(1) - (2)].redirect); | |
2592 | } | |
2593 | break; | |
2594 | ||
0001803f | 2595 | case 57: |
495aee44 | 2596 | #line 723 "/Users/chet/src/bash/src/parse.y" |
3185942a JA |
2597 | { (yyval.command) = make_simple_command ((yyvsp[(1) - (1)].element), (COMMAND *)NULL); } |
2598 | break; | |
2599 | ||
0001803f | 2600 | case 58: |
495aee44 | 2601 | #line 725 "/Users/chet/src/bash/src/parse.y" |
3185942a JA |
2602 | { (yyval.command) = make_simple_command ((yyvsp[(2) - (2)].element), (yyvsp[(1) - (2)].command)); } |
2603 | break; | |
2604 | ||
0001803f | 2605 | case 59: |
495aee44 | 2606 | #line 729 "/Users/chet/src/bash/src/parse.y" |
3185942a JA |
2607 | { (yyval.command) = clean_simple_command ((yyvsp[(1) - (1)].command)); } |
2608 | break; | |
2609 | ||
0001803f | 2610 | case 60: |
495aee44 | 2611 | #line 731 "/Users/chet/src/bash/src/parse.y" |
3185942a JA |
2612 | { (yyval.command) = (yyvsp[(1) - (1)].command); } |
2613 | break; | |
2614 | ||
0001803f | 2615 | case 61: |
495aee44 | 2616 | #line 733 "/Users/chet/src/bash/src/parse.y" |
3185942a | 2617 | { |
f73dda09 JA |
2618 | COMMAND *tc; |
2619 | ||
3185942a | 2620 | tc = (yyvsp[(1) - (2)].command); |
f73dda09 JA |
2621 | if (tc->redirects) |
2622 | { | |
2623 | register REDIRECT *t; | |
2624 | for (t = tc->redirects; t->next; t = t->next) | |
2625 | ; | |
3185942a | 2626 | t->next = (yyvsp[(2) - (2)].redirect); |
f73dda09 JA |
2627 | } |
2628 | else | |
3185942a JA |
2629 | tc->redirects = (yyvsp[(2) - (2)].redirect); |
2630 | (yyval.command) = (yyvsp[(1) - (2)].command); | |
2631 | } | |
2632 | break; | |
2633 | ||
0001803f | 2634 | case 62: |
495aee44 | 2635 | #line 749 "/Users/chet/src/bash/src/parse.y" |
3185942a JA |
2636 | { (yyval.command) = (yyvsp[(1) - (1)].command); } |
2637 | break; | |
2638 | ||
0001803f | 2639 | case 63: |
495aee44 | 2640 | #line 751 "/Users/chet/src/bash/src/parse.y" |
3185942a JA |
2641 | { (yyval.command) = (yyvsp[(1) - (1)].command); } |
2642 | break; | |
2643 | ||
0001803f | 2644 | case 64: |
495aee44 | 2645 | #line 755 "/Users/chet/src/bash/src/parse.y" |
3185942a JA |
2646 | { (yyval.command) = (yyvsp[(1) - (1)].command); } |
2647 | break; | |
2648 | ||
0001803f | 2649 | case 65: |
495aee44 | 2650 | #line 757 "/Users/chet/src/bash/src/parse.y" |
3185942a JA |
2651 | { (yyval.command) = (yyvsp[(1) - (1)].command); } |
2652 | break; | |
2653 | ||
0001803f | 2654 | case 66: |
495aee44 | 2655 | #line 759 "/Users/chet/src/bash/src/parse.y" |
3185942a JA |
2656 | { (yyval.command) = make_while_command ((yyvsp[(2) - (5)].command), (yyvsp[(4) - (5)].command)); } |
2657 | break; | |
2658 | ||
0001803f | 2659 | case 67: |
495aee44 | 2660 | #line 761 "/Users/chet/src/bash/src/parse.y" |
3185942a JA |
2661 | { (yyval.command) = make_until_command ((yyvsp[(2) - (5)].command), (yyvsp[(4) - (5)].command)); } |
2662 | break; | |
2663 | ||
0001803f | 2664 | case 68: |
495aee44 | 2665 | #line 763 "/Users/chet/src/bash/src/parse.y" |
3185942a JA |
2666 | { (yyval.command) = (yyvsp[(1) - (1)].command); } |
2667 | break; | |
2668 | ||
0001803f | 2669 | case 69: |
495aee44 | 2670 | #line 765 "/Users/chet/src/bash/src/parse.y" |
3185942a JA |
2671 | { (yyval.command) = (yyvsp[(1) - (1)].command); } |
2672 | break; | |
2673 | ||
0001803f | 2674 | case 70: |
495aee44 | 2675 | #line 767 "/Users/chet/src/bash/src/parse.y" |
3185942a JA |
2676 | { (yyval.command) = (yyvsp[(1) - (1)].command); } |
2677 | break; | |
2678 | ||
0001803f | 2679 | case 71: |
495aee44 | 2680 | #line 769 "/Users/chet/src/bash/src/parse.y" |
3185942a JA |
2681 | { (yyval.command) = (yyvsp[(1) - (1)].command); } |
2682 | break; | |
2683 | ||
0001803f | 2684 | case 72: |
495aee44 | 2685 | #line 771 "/Users/chet/src/bash/src/parse.y" |
3185942a JA |
2686 | { (yyval.command) = (yyvsp[(1) - (1)].command); } |
2687 | break; | |
2688 | ||
0001803f | 2689 | case 73: |
495aee44 | 2690 | #line 773 "/Users/chet/src/bash/src/parse.y" |
3185942a JA |
2691 | { (yyval.command) = (yyvsp[(1) - (1)].command); } |
2692 | break; | |
2693 | ||
0001803f | 2694 | case 74: |
495aee44 | 2695 | #line 775 "/Users/chet/src/bash/src/parse.y" |
3185942a JA |
2696 | { (yyval.command) = (yyvsp[(1) - (1)].command); } |
2697 | break; | |
2698 | ||
0001803f | 2699 | case 75: |
495aee44 | 2700 | #line 779 "/Users/chet/src/bash/src/parse.y" |
3185942a JA |
2701 | { |
2702 | (yyval.command) = make_for_command ((yyvsp[(2) - (6)].word), add_string_to_list ("\"$@\"", (WORD_LIST *)NULL), (yyvsp[(5) - (6)].command), word_lineno[word_top]); | |
b80f6443 | 2703 | if (word_top > 0) word_top--; |
3185942a JA |
2704 | } |
2705 | break; | |
2706 | ||
0001803f | 2707 | case 76: |
495aee44 | 2708 | #line 784 "/Users/chet/src/bash/src/parse.y" |
3185942a JA |
2709 | { |
2710 | (yyval.command) = make_for_command ((yyvsp[(2) - (6)].word), add_string_to_list ("\"$@\"", (WORD_LIST *)NULL), (yyvsp[(5) - (6)].command), word_lineno[word_top]); | |
b80f6443 | 2711 | if (word_top > 0) word_top--; |
3185942a JA |
2712 | } |
2713 | break; | |
2714 | ||
0001803f | 2715 | case 77: |
495aee44 | 2716 | #line 789 "/Users/chet/src/bash/src/parse.y" |
3185942a JA |
2717 | { |
2718 | (yyval.command) = make_for_command ((yyvsp[(2) - (7)].word), add_string_to_list ("\"$@\"", (WORD_LIST *)NULL), (yyvsp[(6) - (7)].command), word_lineno[word_top]); | |
b80f6443 | 2719 | if (word_top > 0) word_top--; |
3185942a JA |
2720 | } |
2721 | break; | |
2722 | ||
0001803f | 2723 | case 78: |
495aee44 | 2724 | #line 794 "/Users/chet/src/bash/src/parse.y" |
3185942a JA |
2725 | { |
2726 | (yyval.command) = make_for_command ((yyvsp[(2) - (7)].word), add_string_to_list ("\"$@\"", (WORD_LIST *)NULL), (yyvsp[(6) - (7)].command), word_lineno[word_top]); | |
b80f6443 | 2727 | if (word_top > 0) word_top--; |
3185942a JA |
2728 | } |
2729 | break; | |
2730 | ||
0001803f | 2731 | case 79: |
495aee44 | 2732 | #line 799 "/Users/chet/src/bash/src/parse.y" |
3185942a JA |
2733 | { |
2734 | (yyval.command) = make_for_command ((yyvsp[(2) - (10)].word), REVERSE_LIST ((yyvsp[(5) - (10)].word_list), WORD_LIST *), (yyvsp[(9) - (10)].command), word_lineno[word_top]); | |
b80f6443 | 2735 | if (word_top > 0) word_top--; |
3185942a JA |
2736 | } |
2737 | break; | |
2738 | ||
0001803f | 2739 | case 80: |
495aee44 | 2740 | #line 804 "/Users/chet/src/bash/src/parse.y" |
3185942a JA |
2741 | { |
2742 | (yyval.command) = make_for_command ((yyvsp[(2) - (10)].word), REVERSE_LIST ((yyvsp[(5) - (10)].word_list), WORD_LIST *), (yyvsp[(9) - (10)].command), word_lineno[word_top]); | |
b80f6443 | 2743 | if (word_top > 0) word_top--; |
3185942a JA |
2744 | } |
2745 | break; | |
2746 | ||
0001803f | 2747 | case 81: |
495aee44 | 2748 | #line 809 "/Users/chet/src/bash/src/parse.y" |
3185942a JA |
2749 | { |
2750 | (yyval.command) = make_for_command ((yyvsp[(2) - (9)].word), (WORD_LIST *)NULL, (yyvsp[(8) - (9)].command), word_lineno[word_top]); | |
b80f6443 | 2751 | if (word_top > 0) word_top--; |
3185942a JA |
2752 | } |
2753 | break; | |
2754 | ||
0001803f | 2755 | case 82: |
495aee44 | 2756 | #line 814 "/Users/chet/src/bash/src/parse.y" |
3185942a JA |
2757 | { |
2758 | (yyval.command) = make_for_command ((yyvsp[(2) - (9)].word), (WORD_LIST *)NULL, (yyvsp[(8) - (9)].command), word_lineno[word_top]); | |
b80f6443 | 2759 | if (word_top > 0) word_top--; |
3185942a JA |
2760 | } |
2761 | break; | |
2762 | ||
0001803f | 2763 | case 83: |
495aee44 | 2764 | #line 821 "/Users/chet/src/bash/src/parse.y" |
3185942a JA |
2765 | { |
2766 | (yyval.command) = make_arith_for_command ((yyvsp[(2) - (7)].word_list), (yyvsp[(6) - (7)].command), arith_for_lineno); | |
b80f6443 | 2767 | if (word_top > 0) word_top--; |
3185942a JA |
2768 | } |
2769 | break; | |
2770 | ||
0001803f | 2771 | case 84: |
495aee44 | 2772 | #line 826 "/Users/chet/src/bash/src/parse.y" |
3185942a JA |
2773 | { |
2774 | (yyval.command) = make_arith_for_command ((yyvsp[(2) - (7)].word_list), (yyvsp[(6) - (7)].command), arith_for_lineno); | |
b80f6443 | 2775 | if (word_top > 0) word_top--; |
3185942a JA |
2776 | } |
2777 | break; | |
2778 | ||
0001803f | 2779 | case 85: |
495aee44 | 2780 | #line 831 "/Users/chet/src/bash/src/parse.y" |
3185942a JA |
2781 | { |
2782 | (yyval.command) = make_arith_for_command ((yyvsp[(2) - (5)].word_list), (yyvsp[(4) - (5)].command), arith_for_lineno); | |
b80f6443 | 2783 | if (word_top > 0) word_top--; |
3185942a JA |
2784 | } |
2785 | break; | |
2786 | ||
0001803f | 2787 | case 86: |
495aee44 | 2788 | #line 836 "/Users/chet/src/bash/src/parse.y" |
3185942a JA |
2789 | { |
2790 | (yyval.command) = make_arith_for_command ((yyvsp[(2) - (5)].word_list), (yyvsp[(4) - (5)].command), arith_for_lineno); | |
b80f6443 | 2791 | if (word_top > 0) word_top--; |
3185942a JA |
2792 | } |
2793 | break; | |
2794 | ||
0001803f | 2795 | case 87: |
495aee44 | 2796 | #line 843 "/Users/chet/src/bash/src/parse.y" |
3185942a JA |
2797 | { |
2798 | (yyval.command) = make_select_command ((yyvsp[(2) - (6)].word), add_string_to_list ("\"$@\"", (WORD_LIST *)NULL), (yyvsp[(5) - (6)].command), word_lineno[word_top]); | |
b80f6443 | 2799 | if (word_top > 0) word_top--; |
3185942a JA |
2800 | } |
2801 | break; | |
2802 | ||
0001803f | 2803 | case 88: |
495aee44 | 2804 | #line 848 "/Users/chet/src/bash/src/parse.y" |
3185942a JA |
2805 | { |
2806 | (yyval.command) = make_select_command ((yyvsp[(2) - (6)].word), add_string_to_list ("\"$@\"", (WORD_LIST *)NULL), (yyvsp[(5) - (6)].command), word_lineno[word_top]); | |
b80f6443 | 2807 | if (word_top > 0) word_top--; |
3185942a JA |
2808 | } |
2809 | break; | |
2810 | ||
0001803f | 2811 | case 89: |
495aee44 | 2812 | #line 853 "/Users/chet/src/bash/src/parse.y" |
3185942a JA |
2813 | { |
2814 | (yyval.command) = make_select_command ((yyvsp[(2) - (7)].word), add_string_to_list ("\"$@\"", (WORD_LIST *)NULL), (yyvsp[(6) - (7)].command), word_lineno[word_top]); | |
b80f6443 | 2815 | if (word_top > 0) word_top--; |
3185942a JA |
2816 | } |
2817 | break; | |
2818 | ||
0001803f | 2819 | case 90: |
495aee44 | 2820 | #line 858 "/Users/chet/src/bash/src/parse.y" |
3185942a JA |
2821 | { |
2822 | (yyval.command) = make_select_command ((yyvsp[(2) - (7)].word), add_string_to_list ("\"$@\"", (WORD_LIST *)NULL), (yyvsp[(6) - (7)].command), word_lineno[word_top]); | |
b80f6443 | 2823 | if (word_top > 0) word_top--; |
3185942a JA |
2824 | } |
2825 | break; | |
2826 | ||
0001803f | 2827 | case 91: |
495aee44 | 2828 | #line 863 "/Users/chet/src/bash/src/parse.y" |
3185942a JA |
2829 | { |
2830 | (yyval.command) = make_select_command ((yyvsp[(2) - (10)].word), REVERSE_LIST ((yyvsp[(5) - (10)].word_list), WORD_LIST *), (yyvsp[(9) - (10)].command), word_lineno[word_top]); | |
b80f6443 | 2831 | if (word_top > 0) word_top--; |
3185942a JA |
2832 | } |
2833 | break; | |
2834 | ||
0001803f | 2835 | case 92: |
495aee44 | 2836 | #line 868 "/Users/chet/src/bash/src/parse.y" |
3185942a JA |
2837 | { |
2838 | (yyval.command) = make_select_command ((yyvsp[(2) - (10)].word), REVERSE_LIST ((yyvsp[(5) - (10)].word_list), WORD_LIST *), (yyvsp[(9) - (10)].command), word_lineno[word_top]); | |
b80f6443 | 2839 | if (word_top > 0) word_top--; |
3185942a JA |
2840 | } |
2841 | break; | |
2842 | ||
0001803f | 2843 | case 93: |
495aee44 | 2844 | #line 875 "/Users/chet/src/bash/src/parse.y" |
3185942a JA |
2845 | { |
2846 | (yyval.command) = make_case_command ((yyvsp[(2) - (6)].word), (PATTERN_LIST *)NULL, word_lineno[word_top]); | |
b80f6443 | 2847 | if (word_top > 0) word_top--; |
3185942a JA |
2848 | } |
2849 | break; | |
2850 | ||
0001803f | 2851 | case 94: |
495aee44 | 2852 | #line 880 "/Users/chet/src/bash/src/parse.y" |
3185942a JA |
2853 | { |
2854 | (yyval.command) = make_case_command ((yyvsp[(2) - (7)].word), (yyvsp[(5) - (7)].pattern), word_lineno[word_top]); | |
b80f6443 | 2855 | if (word_top > 0) word_top--; |
3185942a JA |
2856 | } |
2857 | break; | |
2858 | ||
0001803f | 2859 | case 95: |
495aee44 | 2860 | #line 885 "/Users/chet/src/bash/src/parse.y" |
3185942a JA |
2861 | { |
2862 | (yyval.command) = make_case_command ((yyvsp[(2) - (6)].word), (yyvsp[(5) - (6)].pattern), word_lineno[word_top]); | |
b80f6443 | 2863 | if (word_top > 0) word_top--; |
3185942a JA |
2864 | } |
2865 | break; | |
2866 | ||
0001803f | 2867 | case 96: |
495aee44 | 2868 | #line 892 "/Users/chet/src/bash/src/parse.y" |
3185942a JA |
2869 | { (yyval.command) = make_function_def ((yyvsp[(1) - (5)].word), (yyvsp[(5) - (5)].command), function_dstart, function_bstart); } |
2870 | break; | |
2871 | ||
0001803f | 2872 | case 97: |
495aee44 | 2873 | #line 895 "/Users/chet/src/bash/src/parse.y" |
3185942a JA |
2874 | { (yyval.command) = make_function_def ((yyvsp[(2) - (6)].word), (yyvsp[(6) - (6)].command), function_dstart, function_bstart); } |
2875 | break; | |
2876 | ||
0001803f | 2877 | case 98: |
495aee44 | 2878 | #line 898 "/Users/chet/src/bash/src/parse.y" |
3185942a JA |
2879 | { (yyval.command) = make_function_def ((yyvsp[(2) - (4)].word), (yyvsp[(4) - (4)].command), function_dstart, function_bstart); } |
2880 | break; | |
2881 | ||
0001803f | 2882 | case 99: |
495aee44 | 2883 | #line 902 "/Users/chet/src/bash/src/parse.y" |
3185942a JA |
2884 | { (yyval.command) = (yyvsp[(1) - (1)].command); } |
2885 | break; | |
2886 | ||
0001803f | 2887 | case 100: |
495aee44 | 2888 | #line 904 "/Users/chet/src/bash/src/parse.y" |
3185942a | 2889 | { |
f73dda09 JA |
2890 | COMMAND *tc; |
2891 | ||
3185942a | 2892 | tc = (yyvsp[(1) - (2)].command); |
f73dda09 JA |
2893 | /* According to Posix.2 3.9.5, redirections |
2894 | specified after the body of a function should | |
2895 | be attached to the function and performed when | |
2896 | the function is executed, not as part of the | |
2897 | function definition command. */ | |
2898 | /* XXX - I don't think it matters, but we might | |
2899 | want to change this in the future to avoid | |
2900 | problems differentiating between a function | |
2901 | definition with a redirection and a function | |
2902 | definition containing a single command with a | |
2903 | redirection. The two are semantically equivalent, | |
2904 | though -- the only difference is in how the | |
2905 | command printing code displays the redirections. */ | |
2906 | if (tc->redirects) | |
2907 | { | |
2908 | register REDIRECT *t; | |
2909 | for (t = tc->redirects; t->next; t = t->next) | |
2910 | ; | |
3185942a | 2911 | t->next = (yyvsp[(2) - (2)].redirect); |
f73dda09 JA |
2912 | } |
2913 | else | |
3185942a JA |
2914 | tc->redirects = (yyvsp[(2) - (2)].redirect); |
2915 | (yyval.command) = (yyvsp[(1) - (2)].command); | |
2916 | } | |
2917 | break; | |
2918 | ||
0001803f | 2919 | case 101: |
495aee44 | 2920 | #line 935 "/Users/chet/src/bash/src/parse.y" |
3185942a JA |
2921 | { |
2922 | (yyval.command) = make_subshell_command ((yyvsp[(2) - (3)].command)); | |
2923 | (yyval.command)->flags |= CMD_WANT_SUBSHELL; | |
2924 | } | |
2925 | break; | |
2926 | ||
0001803f | 2927 | case 102: |
495aee44 | 2928 | #line 942 "/Users/chet/src/bash/src/parse.y" |
3185942a JA |
2929 | { |
2930 | (yyval.command) = make_coproc_command ("COPROC", (yyvsp[(2) - (2)].command)); | |
2931 | (yyval.command)->flags |= CMD_WANT_SUBSHELL|CMD_COPROC_SUBSHELL; | |
2932 | } | |
2933 | break; | |
2934 | ||
0001803f | 2935 | case 103: |
495aee44 | 2936 | #line 947 "/Users/chet/src/bash/src/parse.y" |
3185942a JA |
2937 | { |
2938 | COMMAND *tc; | |
2939 | ||
2940 | tc = (yyvsp[(2) - (3)].command); | |
2941 | if (tc->redirects) | |
2942 | { | |
2943 | register REDIRECT *t; | |
2944 | for (t = tc->redirects; t->next; t = t->next) | |
2945 | ; | |
2946 | t->next = (yyvsp[(3) - (3)].redirect); | |
2947 | } | |
2948 | else | |
2949 | tc->redirects = (yyvsp[(3) - (3)].redirect); | |
2950 | (yyval.command) = make_coproc_command ("COPROC", (yyvsp[(2) - (3)].command)); | |
2951 | (yyval.command)->flags |= CMD_WANT_SUBSHELL|CMD_COPROC_SUBSHELL; | |
2952 | } | |
2953 | break; | |
2954 | ||
0001803f | 2955 | case 104: |
495aee44 | 2956 | #line 964 "/Users/chet/src/bash/src/parse.y" |
3185942a JA |
2957 | { |
2958 | (yyval.command) = make_coproc_command ((yyvsp[(2) - (3)].word)->word, (yyvsp[(3) - (3)].command)); | |
2959 | (yyval.command)->flags |= CMD_WANT_SUBSHELL|CMD_COPROC_SUBSHELL; | |
2960 | } | |
2961 | break; | |
2962 | ||
0001803f | 2963 | case 105: |
495aee44 | 2964 | #line 969 "/Users/chet/src/bash/src/parse.y" |
3185942a JA |
2965 | { |
2966 | COMMAND *tc; | |
2967 | ||
2968 | tc = (yyvsp[(3) - (4)].command); | |
2969 | if (tc->redirects) | |
2970 | { | |
2971 | register REDIRECT *t; | |
2972 | for (t = tc->redirects; t->next; t = t->next) | |
2973 | ; | |
2974 | t->next = (yyvsp[(4) - (4)].redirect); | |
2975 | } | |
2976 | else | |
2977 | tc->redirects = (yyvsp[(4) - (4)].redirect); | |
2978 | (yyval.command) = make_coproc_command ((yyvsp[(2) - (4)].word)->word, (yyvsp[(3) - (4)].command)); | |
2979 | (yyval.command)->flags |= CMD_WANT_SUBSHELL|CMD_COPROC_SUBSHELL; | |
2980 | } | |
2981 | break; | |
2982 | ||
0001803f | 2983 | case 106: |
495aee44 | 2984 | #line 986 "/Users/chet/src/bash/src/parse.y" |
3185942a JA |
2985 | { |
2986 | (yyval.command) = make_coproc_command ("COPROC", clean_simple_command ((yyvsp[(2) - (2)].command))); | |
2987 | (yyval.command)->flags |= CMD_WANT_SUBSHELL|CMD_COPROC_SUBSHELL; | |
2988 | } | |
2989 | break; | |
2990 | ||
0001803f | 2991 | case 107: |
495aee44 | 2992 | #line 993 "/Users/chet/src/bash/src/parse.y" |
3185942a JA |
2993 | { (yyval.command) = make_if_command ((yyvsp[(2) - (5)].command), (yyvsp[(4) - (5)].command), (COMMAND *)NULL); } |
2994 | break; | |
2995 | ||
0001803f | 2996 | case 108: |
495aee44 | 2997 | #line 995 "/Users/chet/src/bash/src/parse.y" |
3185942a JA |
2998 | { (yyval.command) = make_if_command ((yyvsp[(2) - (7)].command), (yyvsp[(4) - (7)].command), (yyvsp[(6) - (7)].command)); } |
2999 | break; | |
3000 | ||
0001803f | 3001 | case 109: |
495aee44 | 3002 | #line 997 "/Users/chet/src/bash/src/parse.y" |
3185942a JA |
3003 | { (yyval.command) = make_if_command ((yyvsp[(2) - (6)].command), (yyvsp[(4) - (6)].command), (yyvsp[(5) - (6)].command)); } |
3004 | break; | |
3005 | ||
0001803f | 3006 | case 110: |
495aee44 | 3007 | #line 1002 "/Users/chet/src/bash/src/parse.y" |
3185942a JA |
3008 | { (yyval.command) = make_group_command ((yyvsp[(2) - (3)].command)); } |
3009 | break; | |
3010 | ||
0001803f | 3011 | case 111: |
495aee44 | 3012 | #line 1006 "/Users/chet/src/bash/src/parse.y" |
3185942a JA |
3013 | { (yyval.command) = make_arith_command ((yyvsp[(1) - (1)].word_list)); } |
3014 | break; | |
3015 | ||
0001803f | 3016 | case 112: |
495aee44 | 3017 | #line 1010 "/Users/chet/src/bash/src/parse.y" |
3185942a JA |
3018 | { (yyval.command) = (yyvsp[(2) - (3)].command); } |
3019 | break; | |
3020 | ||
0001803f | 3021 | case 113: |
495aee44 | 3022 | #line 1014 "/Users/chet/src/bash/src/parse.y" |
3185942a JA |
3023 | { (yyval.command) = make_if_command ((yyvsp[(2) - (4)].command), (yyvsp[(4) - (4)].command), (COMMAND *)NULL); } |
3024 | break; | |
3025 | ||
0001803f | 3026 | case 114: |
495aee44 | 3027 | #line 1016 "/Users/chet/src/bash/src/parse.y" |
3185942a JA |
3028 | { (yyval.command) = make_if_command ((yyvsp[(2) - (6)].command), (yyvsp[(4) - (6)].command), (yyvsp[(6) - (6)].command)); } |
3029 | break; | |
3030 | ||
0001803f | 3031 | case 115: |
495aee44 | 3032 | #line 1018 "/Users/chet/src/bash/src/parse.y" |
3185942a JA |
3033 | { (yyval.command) = make_if_command ((yyvsp[(2) - (5)].command), (yyvsp[(4) - (5)].command), (yyvsp[(5) - (5)].command)); } |
3034 | break; | |
3035 | ||
0001803f | 3036 | case 117: |
495aee44 | 3037 | #line 1023 "/Users/chet/src/bash/src/parse.y" |
3185942a JA |
3038 | { (yyvsp[(2) - (2)].pattern)->next = (yyvsp[(1) - (2)].pattern); (yyval.pattern) = (yyvsp[(2) - (2)].pattern); } |
3039 | break; | |
3040 | ||
0001803f | 3041 | case 118: |
495aee44 | 3042 | #line 1027 "/Users/chet/src/bash/src/parse.y" |
3185942a JA |
3043 | { (yyval.pattern) = make_pattern_list ((yyvsp[(2) - (4)].word_list), (yyvsp[(4) - (4)].command)); } |
3044 | break; | |
3045 | ||
0001803f | 3046 | case 119: |
495aee44 | 3047 | #line 1029 "/Users/chet/src/bash/src/parse.y" |
3185942a JA |
3048 | { (yyval.pattern) = make_pattern_list ((yyvsp[(2) - (4)].word_list), (COMMAND *)NULL); } |
3049 | break; | |
3050 | ||
0001803f | 3051 | case 120: |
495aee44 | 3052 | #line 1031 "/Users/chet/src/bash/src/parse.y" |
3185942a JA |
3053 | { (yyval.pattern) = make_pattern_list ((yyvsp[(3) - (5)].word_list), (yyvsp[(5) - (5)].command)); } |
3054 | break; | |
3055 | ||
0001803f | 3056 | case 121: |
495aee44 | 3057 | #line 1033 "/Users/chet/src/bash/src/parse.y" |
3185942a JA |
3058 | { (yyval.pattern) = make_pattern_list ((yyvsp[(3) - (5)].word_list), (COMMAND *)NULL); } |
3059 | break; | |
3060 | ||
0001803f | 3061 | case 122: |
495aee44 | 3062 | #line 1037 "/Users/chet/src/bash/src/parse.y" |
3185942a JA |
3063 | { (yyval.pattern) = (yyvsp[(1) - (2)].pattern); } |
3064 | break; | |
3065 | ||
0001803f | 3066 | case 123: |
495aee44 | 3067 | #line 1039 "/Users/chet/src/bash/src/parse.y" |
3185942a JA |
3068 | { (yyvsp[(2) - (3)].pattern)->next = (yyvsp[(1) - (3)].pattern); (yyval.pattern) = (yyvsp[(2) - (3)].pattern); } |
3069 | break; | |
3070 | ||
0001803f | 3071 | case 124: |
495aee44 | 3072 | #line 1041 "/Users/chet/src/bash/src/parse.y" |
3185942a JA |
3073 | { (yyvsp[(1) - (2)].pattern)->flags |= CASEPAT_FALLTHROUGH; (yyval.pattern) = (yyvsp[(1) - (2)].pattern); } |
3074 | break; | |
3075 | ||
0001803f | 3076 | case 125: |
495aee44 | 3077 | #line 1043 "/Users/chet/src/bash/src/parse.y" |
3185942a JA |
3078 | { (yyvsp[(2) - (3)].pattern)->flags |= CASEPAT_FALLTHROUGH; (yyvsp[(2) - (3)].pattern)->next = (yyvsp[(1) - (3)].pattern); (yyval.pattern) = (yyvsp[(2) - (3)].pattern); } |
3079 | break; | |
3080 | ||
0001803f | 3081 | case 126: |
495aee44 | 3082 | #line 1045 "/Users/chet/src/bash/src/parse.y" |
3185942a JA |
3083 | { (yyvsp[(1) - (2)].pattern)->flags |= CASEPAT_TESTNEXT; (yyval.pattern) = (yyvsp[(1) - (2)].pattern); } |
3084 | break; | |
3085 | ||
0001803f | 3086 | case 127: |
495aee44 | 3087 | #line 1047 "/Users/chet/src/bash/src/parse.y" |
3185942a JA |
3088 | { (yyvsp[(2) - (3)].pattern)->flags |= CASEPAT_TESTNEXT; (yyvsp[(2) - (3)].pattern)->next = (yyvsp[(1) - (3)].pattern); (yyval.pattern) = (yyvsp[(2) - (3)].pattern); } |
3089 | break; | |
3090 | ||
0001803f | 3091 | case 128: |
495aee44 | 3092 | #line 1051 "/Users/chet/src/bash/src/parse.y" |
3185942a JA |
3093 | { (yyval.word_list) = make_word_list ((yyvsp[(1) - (1)].word), (WORD_LIST *)NULL); } |
3094 | break; | |
3095 | ||
0001803f | 3096 | case 129: |
495aee44 | 3097 | #line 1053 "/Users/chet/src/bash/src/parse.y" |
3185942a JA |
3098 | { (yyval.word_list) = make_word_list ((yyvsp[(3) - (3)].word), (yyvsp[(1) - (3)].word_list)); } |
3099 | break; | |
3100 | ||
0001803f | 3101 | case 130: |
495aee44 | 3102 | #line 1062 "/Users/chet/src/bash/src/parse.y" |
3185942a JA |
3103 | { |
3104 | (yyval.command) = (yyvsp[(2) - (2)].command); | |
f73dda09 JA |
3105 | if (need_here_doc) |
3106 | gather_here_documents (); | |
3185942a JA |
3107 | } |
3108 | break; | |
3109 | ||
0001803f | 3110 | case 132: |
495aee44 | 3111 | #line 1071 "/Users/chet/src/bash/src/parse.y" |
3185942a JA |
3112 | { |
3113 | (yyval.command) = (yyvsp[(2) - (2)].command); | |
3114 | } | |
3115 | break; | |
3116 | ||
0001803f | 3117 | case 134: |
495aee44 | 3118 | #line 1078 "/Users/chet/src/bash/src/parse.y" |
3185942a JA |
3119 | { |
3120 | if ((yyvsp[(1) - (3)].command)->type == cm_connection) | |
3121 | (yyval.command) = connect_async_list ((yyvsp[(1) - (3)].command), (COMMAND *)NULL, '&'); | |
f73dda09 | 3122 | else |
3185942a JA |
3123 | (yyval.command) = command_connect ((yyvsp[(1) - (3)].command), (COMMAND *)NULL, '&'); |
3124 | } | |
3125 | break; | |
3126 | ||
0001803f | 3127 | case 136: |
495aee44 | 3128 | #line 1089 "/Users/chet/src/bash/src/parse.y" |
3185942a JA |
3129 | { (yyval.command) = command_connect ((yyvsp[(1) - (4)].command), (yyvsp[(4) - (4)].command), AND_AND); } |
3130 | break; | |
3131 | ||
0001803f | 3132 | case 137: |
495aee44 | 3133 | #line 1091 "/Users/chet/src/bash/src/parse.y" |
3185942a JA |
3134 | { (yyval.command) = command_connect ((yyvsp[(1) - (4)].command), (yyvsp[(4) - (4)].command), OR_OR); } |
3135 | break; | |
3136 | ||
0001803f | 3137 | case 138: |
495aee44 | 3138 | #line 1093 "/Users/chet/src/bash/src/parse.y" |
3185942a JA |
3139 | { |
3140 | if ((yyvsp[(1) - (4)].command)->type == cm_connection) | |
3141 | (yyval.command) = connect_async_list ((yyvsp[(1) - (4)].command), (yyvsp[(4) - (4)].command), '&'); | |
f73dda09 | 3142 | else |
3185942a JA |
3143 | (yyval.command) = command_connect ((yyvsp[(1) - (4)].command), (yyvsp[(4) - (4)].command), '&'); |
3144 | } | |
3145 | break; | |
3146 | ||
0001803f | 3147 | case 139: |
495aee44 | 3148 | #line 1100 "/Users/chet/src/bash/src/parse.y" |
3185942a JA |
3149 | { (yyval.command) = command_connect ((yyvsp[(1) - (4)].command), (yyvsp[(4) - (4)].command), ';'); } |
3150 | break; | |
3151 | ||
0001803f | 3152 | case 140: |
495aee44 | 3153 | #line 1102 "/Users/chet/src/bash/src/parse.y" |
3185942a JA |
3154 | { (yyval.command) = command_connect ((yyvsp[(1) - (4)].command), (yyvsp[(4) - (4)].command), ';'); } |
3155 | break; | |
3156 | ||
0001803f | 3157 | case 141: |
495aee44 | 3158 | #line 1104 "/Users/chet/src/bash/src/parse.y" |
3185942a JA |
3159 | { (yyval.command) = (yyvsp[(1) - (1)].command); } |
3160 | break; | |
3161 | ||
0001803f | 3162 | case 144: |
495aee44 | 3163 | #line 1112 "/Users/chet/src/bash/src/parse.y" |
3185942a JA |
3164 | { (yyval.number) = '\n'; } |
3165 | break; | |
3166 | ||
0001803f | 3167 | case 145: |
495aee44 | 3168 | #line 1114 "/Users/chet/src/bash/src/parse.y" |
3185942a JA |
3169 | { (yyval.number) = ';'; } |
3170 | break; | |
3171 | ||
0001803f | 3172 | case 146: |
495aee44 | 3173 | #line 1116 "/Users/chet/src/bash/src/parse.y" |
3185942a JA |
3174 | { (yyval.number) = yacc_EOF; } |
3175 | break; | |
3176 | ||
0001803f | 3177 | case 149: |
495aee44 | 3178 | #line 1130 "/Users/chet/src/bash/src/parse.y" |
3185942a JA |
3179 | { |
3180 | (yyval.command) = (yyvsp[(1) - (1)].command); | |
f73dda09 JA |
3181 | if (need_here_doc) |
3182 | gather_here_documents (); | |
3185942a JA |
3183 | if ((parser_state & PST_CMDSUBST) && current_token == shell_eof_token) |
3184 | { | |
3185 | global_command = (yyvsp[(1) - (1)].command); | |
3186 | eof_encountered = 0; | |
3187 | rewind_input_string (); | |
3188 | YYACCEPT; | |
3189 | } | |
3190 | } | |
3191 | break; | |
3192 | ||
0001803f | 3193 | case 150: |
495aee44 | 3194 | #line 1143 "/Users/chet/src/bash/src/parse.y" |
3185942a JA |
3195 | { |
3196 | if ((yyvsp[(1) - (2)].command)->type == cm_connection) | |
3197 | (yyval.command) = connect_async_list ((yyvsp[(1) - (2)].command), (COMMAND *)NULL, '&'); | |
f73dda09 | 3198 | else |
3185942a | 3199 | (yyval.command) = command_connect ((yyvsp[(1) - (2)].command), (COMMAND *)NULL, '&'); |
f73dda09 JA |
3200 | if (need_here_doc) |
3201 | gather_here_documents (); | |
3185942a JA |
3202 | if ((parser_state & PST_CMDSUBST) && current_token == shell_eof_token) |
3203 | { | |
3204 | global_command = (yyvsp[(1) - (2)].command); | |
3205 | eof_encountered = 0; | |
3206 | rewind_input_string (); | |
3207 | YYACCEPT; | |
3208 | } | |
3209 | } | |
3210 | break; | |
3211 | ||
0001803f | 3212 | case 151: |
495aee44 | 3213 | #line 1159 "/Users/chet/src/bash/src/parse.y" |
3185942a JA |
3214 | { |
3215 | (yyval.command) = (yyvsp[(1) - (2)].command); | |
f73dda09 JA |
3216 | if (need_here_doc) |
3217 | gather_here_documents (); | |
3185942a JA |
3218 | if ((parser_state & PST_CMDSUBST) && current_token == shell_eof_token) |
3219 | { | |
3220 | global_command = (yyvsp[(1) - (2)].command); | |
3221 | eof_encountered = 0; | |
3222 | rewind_input_string (); | |
3223 | YYACCEPT; | |
3224 | } | |
3225 | } | |
3226 | break; | |
3227 | ||
0001803f | 3228 | case 152: |
495aee44 | 3229 | #line 1174 "/Users/chet/src/bash/src/parse.y" |
3185942a JA |
3230 | { (yyval.command) = command_connect ((yyvsp[(1) - (4)].command), (yyvsp[(4) - (4)].command), AND_AND); } |
3231 | break; | |
3232 | ||
0001803f | 3233 | case 153: |
495aee44 | 3234 | #line 1176 "/Users/chet/src/bash/src/parse.y" |
3185942a JA |
3235 | { (yyval.command) = command_connect ((yyvsp[(1) - (4)].command), (yyvsp[(4) - (4)].command), OR_OR); } |
3236 | break; | |
3237 | ||
0001803f | 3238 | case 154: |
495aee44 | 3239 | #line 1178 "/Users/chet/src/bash/src/parse.y" |
3185942a JA |
3240 | { |
3241 | if ((yyvsp[(1) - (3)].command)->type == cm_connection) | |
3242 | (yyval.command) = connect_async_list ((yyvsp[(1) - (3)].command), (yyvsp[(3) - (3)].command), '&'); | |
f73dda09 | 3243 | else |
3185942a JA |
3244 | (yyval.command) = command_connect ((yyvsp[(1) - (3)].command), (yyvsp[(3) - (3)].command), '&'); |
3245 | } | |
3246 | break; | |
3247 | ||
0001803f | 3248 | case 155: |
495aee44 | 3249 | #line 1185 "/Users/chet/src/bash/src/parse.y" |
3185942a JA |
3250 | { (yyval.command) = command_connect ((yyvsp[(1) - (3)].command), (yyvsp[(3) - (3)].command), ';'); } |
3251 | break; | |
3252 | ||
0001803f | 3253 | case 156: |
495aee44 | 3254 | #line 1188 "/Users/chet/src/bash/src/parse.y" |
3185942a JA |
3255 | { (yyval.command) = (yyvsp[(1) - (1)].command); } |
3256 | break; | |
3257 | ||
0001803f | 3258 | case 157: |
495aee44 | 3259 | #line 1192 "/Users/chet/src/bash/src/parse.y" |
3185942a JA |
3260 | { (yyval.command) = (yyvsp[(1) - (1)].command); } |
3261 | break; | |
3262 | ||
0001803f | 3263 | case 158: |
495aee44 | 3264 | #line 1194 "/Users/chet/src/bash/src/parse.y" |
3185942a JA |
3265 | { |
3266 | if ((yyvsp[(2) - (2)].command)) | |
495aee44 | 3267 | (yyvsp[(2) - (2)].command)->flags ^= CMD_INVERT_RETURN; /* toggle */ |
3185942a JA |
3268 | (yyval.command) = (yyvsp[(2) - (2)].command); |
3269 | } | |
3270 | break; | |
3271 | ||
0001803f | 3272 | case 159: |
495aee44 | 3273 | #line 1200 "/Users/chet/src/bash/src/parse.y" |
3185942a JA |
3274 | { |
3275 | if ((yyvsp[(2) - (2)].command)) | |
3276 | (yyvsp[(2) - (2)].command)->flags |= (yyvsp[(1) - (2)].number); | |
3277 | (yyval.command) = (yyvsp[(2) - (2)].command); | |
3278 | } | |
3279 | break; | |
3280 | ||
0001803f | 3281 | case 160: |
495aee44 | 3282 | #line 1206 "/Users/chet/src/bash/src/parse.y" |
3185942a | 3283 | { |
495aee44 | 3284 | ELEMENT x; |
3185942a | 3285 | |
495aee44 CR |
3286 | /* Boy, this is unclean. `time' by itself can |
3287 | time a null command. We cheat and push a | |
3288 | newline back if the list_terminator was a newline | |
3289 | to avoid the double-newline problem (one to | |
3290 | terminate this, one to terminate the command) */ | |
3291 | x.word = 0; | |
3292 | x.redirect = 0; | |
3293 | (yyval.command) = make_simple_command (x, (COMMAND *)NULL); | |
3294 | (yyval.command)->flags |= (yyvsp[(1) - (2)].number); | |
3295 | /* XXX - let's cheat and push a newline back */ | |
3296 | if ((yyvsp[(2) - (2)].number) == '\n') | |
3297 | token_to_read = '\n'; | |
3185942a JA |
3298 | } |
3299 | break; | |
3300 | ||
495aee44 CR |
3301 | case 161: |
3302 | #line 1223 "/Users/chet/src/bash/src/parse.y" | |
3185942a | 3303 | { |
b80f6443 JA |
3304 | ELEMENT x; |
3305 | ||
495aee44 CR |
3306 | /* This is just as unclean. Posix says that `!' |
3307 | by itself should be equivalent to `false'. | |
3308 | We cheat and push a | |
b80f6443 JA |
3309 | newline back if the list_terminator was a newline |
3310 | to avoid the double-newline problem (one to | |
3311 | terminate this, one to terminate the command) */ | |
3312 | x.word = 0; | |
3313 | x.redirect = 0; | |
3185942a | 3314 | (yyval.command) = make_simple_command (x, (COMMAND *)NULL); |
495aee44 | 3315 | (yyval.command)->flags |= CMD_INVERT_RETURN; |
b80f6443 | 3316 | /* XXX - let's cheat and push a newline back */ |
3185942a | 3317 | if ((yyvsp[(2) - (2)].number) == '\n') |
b80f6443 | 3318 | token_to_read = '\n'; |
3185942a JA |
3319 | } |
3320 | break; | |
f73dda09 | 3321 | |
495aee44 CR |
3322 | case 162: |
3323 | #line 1243 "/Users/chet/src/bash/src/parse.y" | |
3185942a JA |
3324 | { (yyval.command) = command_connect ((yyvsp[(1) - (4)].command), (yyvsp[(4) - (4)].command), '|'); } |
3325 | break; | |
3326 | ||
495aee44 CR |
3327 | case 163: |
3328 | #line 1245 "/Users/chet/src/bash/src/parse.y" | |
f73dda09 | 3329 | { |
3185942a JA |
3330 | /* Make cmd1 |& cmd2 equivalent to cmd1 2>&1 | cmd2 */ |
3331 | COMMAND *tc; | |
0001803f | 3332 | REDIRECTEE rd, sd; |
3185942a JA |
3333 | REDIRECT *r; |
3334 | ||
0001803f CR |
3335 | tc = (yyvsp[(1) - (4)].command)->type == cm_simple ? (COMMAND *)(yyvsp[(1) - (4)].command)->value.Simple : (yyvsp[(1) - (4)].command); |
3336 | sd.dest = 2; | |
3185942a | 3337 | rd.dest = 1; |
0001803f | 3338 | r = make_redirection (sd, r_duplicating_output, rd, 0); |
3185942a JA |
3339 | if (tc->redirects) |
3340 | { | |
3341 | register REDIRECT *t; | |
3342 | for (t = tc->redirects; t->next; t = t->next) | |
3343 | ; | |
3344 | t->next = r; | |
3345 | } | |
3346 | else | |
3347 | tc->redirects = r; | |
3348 | ||
3349 | (yyval.command) = command_connect ((yyvsp[(1) - (4)].command), (yyvsp[(4) - (4)].command), '|'); | |
3350 | } | |
3351 | break; | |
3352 | ||
495aee44 CR |
3353 | case 164: |
3354 | #line 1268 "/Users/chet/src/bash/src/parse.y" | |
3185942a JA |
3355 | { (yyval.command) = (yyvsp[(1) - (1)].command); } |
3356 | break; | |
3357 | ||
495aee44 CR |
3358 | case 165: |
3359 | #line 1272 "/Users/chet/src/bash/src/parse.y" | |
3185942a JA |
3360 | { (yyval.number) = CMD_TIME_PIPELINE; } |
3361 | break; | |
3362 | ||
495aee44 CR |
3363 | case 166: |
3364 | #line 1274 "/Users/chet/src/bash/src/parse.y" | |
3365 | { (yyval.number) = CMD_TIME_PIPELINE|CMD_TIME_POSIX; } | |
3366 | break; | |
3367 | ||
0001803f | 3368 | case 167: |
495aee44 | 3369 | #line 1276 "/Users/chet/src/bash/src/parse.y" |
3185942a JA |
3370 | { (yyval.number) = CMD_TIME_PIPELINE|CMD_TIME_POSIX; } |
3371 | break; | |
3372 | ||
3373 | ||
3374 | /* Line 1267 of yacc.c. */ | |
495aee44 | 3375 | #line 3376 "y.tab.c" |
3185942a | 3376 | default: break; |
f73dda09 | 3377 | } |
3185942a JA |
3378 | YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc); |
3379 | ||
3380 | YYPOPSTACK (yylen); | |
3381 | yylen = 0; | |
3382 | YY_STACK_PRINT (yyss, yyssp); | |
f73dda09 JA |
3383 | |
3384 | *++yyvsp = yyval; | |
b80f6443 | 3385 | |
f73dda09 | 3386 | |
3185942a JA |
3387 | /* Now `shift' the result of the reduction. Determine what state |
3388 | that goes to, based on the state we popped back to and the rule | |
3389 | number reduced by. */ | |
f73dda09 JA |
3390 | |
3391 | yyn = yyr1[yyn]; | |
3392 | ||
3185942a JA |
3393 | yystate = yypgoto[yyn - YYNTOKENS] + *yyssp; |
3394 | if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp) | |
f73dda09 JA |
3395 | yystate = yytable[yystate]; |
3396 | else | |
3185942a | 3397 | yystate = yydefgoto[yyn - YYNTOKENS]; |
f73dda09 JA |
3398 | |
3399 | goto yynewstate; | |
3400 | ||
f73dda09 | 3401 | |
3185942a JA |
3402 | /*------------------------------------. |
3403 | | yyerrlab -- here on detecting error | | |
3404 | `------------------------------------*/ | |
3405 | yyerrlab: | |
3406 | /* If not already recovering from an error, report this error. */ | |
3407 | if (!yyerrstatus) | |
f73dda09 JA |
3408 | { |
3409 | ++yynerrs; | |
3185942a JA |
3410 | #if ! YYERROR_VERBOSE |
3411 | yyerror (YY_("syntax error")); | |
3412 | #else | |
3413 | { | |
3414 | YYSIZE_T yysize = yysyntax_error (0, yystate, yychar); | |
3415 | if (yymsg_alloc < yysize && yymsg_alloc < YYSTACK_ALLOC_MAXIMUM) | |
3416 | { | |
3417 | YYSIZE_T yyalloc = 2 * yysize; | |
3418 | if (! (yysize <= yyalloc && yyalloc <= YYSTACK_ALLOC_MAXIMUM)) | |
3419 | yyalloc = YYSTACK_ALLOC_MAXIMUM; | |
3420 | if (yymsg != yymsgbuf) | |
3421 | YYSTACK_FREE (yymsg); | |
3422 | yymsg = (char *) YYSTACK_ALLOC (yyalloc); | |
3423 | if (yymsg) | |
3424 | yymsg_alloc = yyalloc; | |
3425 | else | |
3426 | { | |
3427 | yymsg = yymsgbuf; | |
3428 | yymsg_alloc = sizeof yymsgbuf; | |
3429 | } | |
3430 | } | |
f73dda09 | 3431 | |
3185942a JA |
3432 | if (0 < yysize && yysize <= yymsg_alloc) |
3433 | { | |
3434 | (void) yysyntax_error (yymsg, yystate, yychar); | |
3435 | yyerror (yymsg); | |
3436 | } | |
3437 | else | |
3438 | { | |
3439 | yyerror (YY_("syntax error")); | |
3440 | if (yysize != 0) | |
3441 | goto yyexhaustedlab; | |
3442 | } | |
3443 | } | |
3444 | #endif | |
f73dda09 | 3445 | } |
f73dda09 | 3446 | |
3185942a | 3447 | |
7117c2d2 | 3448 | |
f73dda09 JA |
3449 | if (yyerrstatus == 3) |
3450 | { | |
3185942a JA |
3451 | /* If just tried and failed to reuse look-ahead token after an |
3452 | error, discard it. */ | |
b80f6443 | 3453 | |
3185942a JA |
3454 | if (yychar <= YYEOF) |
3455 | { | |
3456 | /* Return failure if at end of input. */ | |
3457 | if (yychar == YYEOF) | |
3458 | YYABORT; | |
3459 | } | |
3460 | else | |
3461 | { | |
3462 | yydestruct ("Error: discarding", | |
3463 | yytoken, &yylval); | |
3464 | yychar = YYEMPTY; | |
3465 | } | |
f73dda09 JA |
3466 | } |
3467 | ||
3185942a JA |
3468 | /* Else will try to reuse look-ahead token after shifting the error |
3469 | token. */ | |
3470 | goto yyerrlab1; | |
f73dda09 | 3471 | |
f73dda09 | 3472 | |
3185942a JA |
3473 | /*---------------------------------------------------. |
3474 | | yyerrorlab -- error raised explicitly by YYERROR. | | |
3475 | `---------------------------------------------------*/ | |
3476 | yyerrorlab: | |
f73dda09 | 3477 | |
3185942a JA |
3478 | /* Pacify compilers like GCC when the user code never invokes |
3479 | YYERROR and the label yyerrorlab therefore never appears in user | |
3480 | code. */ | |
3481 | if (/*CONSTCOND*/ 0) | |
3482 | goto yyerrorlab; | |
f73dda09 | 3483 | |
3185942a JA |
3484 | /* Do not reclaim the symbols of the rule which action triggered |
3485 | this YYERROR. */ | |
3486 | YYPOPSTACK (yylen); | |
3487 | yylen = 0; | |
3488 | YY_STACK_PRINT (yyss, yyssp); | |
3489 | yystate = *yyssp; | |
3490 | goto yyerrlab1; | |
f73dda09 | 3491 | |
f73dda09 | 3492 | |
3185942a JA |
3493 | /*-------------------------------------------------------------. |
3494 | | yyerrlab1 -- common code for both syntax error and YYERROR. | | |
3495 | `-------------------------------------------------------------*/ | |
3496 | yyerrlab1: | |
3497 | yyerrstatus = 3; /* Each real token shifted decrements this. */ | |
f73dda09 | 3498 | |
3185942a | 3499 | for (;;) |
f73dda09 | 3500 | { |
3185942a JA |
3501 | yyn = yypact[yystate]; |
3502 | if (yyn != YYPACT_NINF) | |
3503 | { | |
3504 | yyn += YYTERROR; | |
3505 | if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR) | |
3506 | { | |
3507 | yyn = yytable[yyn]; | |
3508 | if (0 < yyn) | |
3509 | break; | |
3510 | } | |
3511 | } | |
b80f6443 | 3512 | |
3185942a JA |
3513 | /* Pop the current state because it cannot handle the error token. */ |
3514 | if (yyssp == yyss) | |
3515 | YYABORT; | |
f73dda09 | 3516 | |
f73dda09 | 3517 | |
3185942a JA |
3518 | yydestruct ("Error: popping", |
3519 | yystos[yystate], yyvsp); | |
3520 | YYPOPSTACK (1); | |
3521 | yystate = *yyssp; | |
3522 | YY_STACK_PRINT (yyss, yyssp); | |
f73dda09 | 3523 | } |
f73dda09 JA |
3524 | |
3525 | if (yyn == YYFINAL) | |
3526 | YYACCEPT; | |
3527 | ||
f73dda09 | 3528 | *++yyvsp = yylval; |
3185942a JA |
3529 | |
3530 | ||
3531 | /* Shift the error token. */ | |
3532 | YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp); | |
f73dda09 JA |
3533 | |
3534 | yystate = yyn; | |
3535 | goto yynewstate; | |
3536 | ||
3185942a JA |
3537 | |
3538 | /*-------------------------------------. | |
3539 | | yyacceptlab -- YYACCEPT comes here. | | |
3540 | `-------------------------------------*/ | |
3541 | yyacceptlab: | |
3542 | yyresult = 0; | |
3543 | goto yyreturn; | |
3544 | ||
3545 | /*-----------------------------------. | |
3546 | | yyabortlab -- YYABORT comes here. | | |
3547 | `-----------------------------------*/ | |
3548 | yyabortlab: | |
3549 | yyresult = 1; | |
3550 | goto yyreturn; | |
3551 | ||
3552 | #ifndef yyoverflow | |
3553 | /*-------------------------------------------------. | |
3554 | | yyexhaustedlab -- memory exhaustion comes here. | | |
3555 | `-------------------------------------------------*/ | |
3556 | yyexhaustedlab: | |
3557 | yyerror (YY_("memory exhausted")); | |
3558 | yyresult = 2; | |
3559 | /* Fall through. */ | |
b80f6443 | 3560 | #endif |
f73dda09 | 3561 | |
3185942a JA |
3562 | yyreturn: |
3563 | if (yychar != YYEOF && yychar != YYEMPTY) | |
3564 | yydestruct ("Cleanup: discarding lookahead", | |
3565 | yytoken, &yylval); | |
3566 | /* Do not reclaim the symbols of the rule which action triggered | |
3567 | this YYABORT or YYACCEPT. */ | |
3568 | YYPOPSTACK (yylen); | |
3569 | YY_STACK_PRINT (yyss, yyssp); | |
3570 | while (yyssp != yyss) | |
b80f6443 | 3571 | { |
3185942a JA |
3572 | yydestruct ("Cleanup: popping", |
3573 | yystos[*yyssp], yyvsp); | |
3574 | YYPOPSTACK (1); | |
b80f6443 | 3575 | } |
3185942a JA |
3576 | #ifndef yyoverflow |
3577 | if (yyss != yyssa) | |
3578 | YYSTACK_FREE (yyss); | |
3579 | #endif | |
3580 | #if YYERROR_VERBOSE | |
3581 | if (yymsg != yymsgbuf) | |
3582 | YYSTACK_FREE (yymsg); | |
3583 | #endif | |
3584 | /* Make sure YYID is used. */ | |
3585 | return YYID (yyresult); | |
f73dda09 | 3586 | } |
3185942a JA |
3587 | |
3588 | ||
495aee44 | 3589 | #line 1278 "/Users/chet/src/bash/src/parse.y" |
3185942a | 3590 | |
f73dda09 JA |
3591 | |
3592 | /* Initial size to allocate for tokens, and the | |
3593 | amount to grow them by. */ | |
3594 | #define TOKEN_DEFAULT_INITIAL_SIZE 496 | |
3595 | #define TOKEN_DEFAULT_GROW_SIZE 512 | |
3596 | ||
b80f6443 JA |
3597 | /* Should we call prompt_again? */ |
3598 | #define SHOULD_PROMPT() \ | |
3599 | (interactive && (bash_input.type == st_stdin || bash_input.type == st_stream)) | |
3600 | ||
3601 | #if defined (ALIAS) | |
3602 | # define expanding_alias() (pushed_string_list && pushed_string_list->expander) | |
3603 | #else | |
3604 | # define expanding_alias() 0 | |
3605 | #endif | |
3606 | ||
f73dda09 JA |
3607 | /* Global var is non-zero when end of file has been reached. */ |
3608 | int EOF_Reached = 0; | |
3609 | ||
3610 | #ifdef DEBUG | |
3611 | static void | |
3612 | debug_parser (i) | |
3613 | int i; | |
3614 | { | |
3615 | #if YYDEBUG != 0 | |
3616 | yydebug = i; | |
3617 | #endif | |
3618 | } | |
3619 | #endif | |
3620 | ||
3621 | /* yy_getc () returns the next available character from input or EOF. | |
3622 | yy_ungetc (c) makes `c' the next character to read. | |
3623 | init_yy_io (get, unget, type, location) makes the function GET the | |
3624 | installed function for getting the next character, makes UNGET the | |
3625 | installed function for un-getting a character, sets the type of stream | |
3626 | (either string or file) from TYPE, and makes LOCATION point to where | |
3627 | the input is coming from. */ | |
3628 | ||
3629 | /* Unconditionally returns end-of-file. */ | |
3630 | int | |
3631 | return_EOF () | |
3632 | { | |
3633 | return (EOF); | |
3634 | } | |
3635 | ||
3636 | /* Variable containing the current get and unget functions. | |
3637 | See ./input.h for a clearer description. */ | |
3638 | BASH_INPUT bash_input; | |
3639 | ||
3640 | /* Set all of the fields in BASH_INPUT to NULL. Free bash_input.name if it | |
3641 | is non-null, avoiding a memory leak. */ | |
3642 | void | |
3643 | initialize_bash_input () | |
3644 | { | |
3645 | bash_input.type = st_none; | |
3646 | FREE (bash_input.name); | |
3647 | bash_input.name = (char *)NULL; | |
3648 | bash_input.location.file = (FILE *)NULL; | |
3649 | bash_input.location.string = (char *)NULL; | |
3650 | bash_input.getter = (sh_cget_func_t *)NULL; | |
3651 | bash_input.ungetter = (sh_cunget_func_t *)NULL; | |
3652 | } | |
3653 | ||
3654 | /* Set the contents of the current bash input stream from | |
3655 | GET, UNGET, TYPE, NAME, and LOCATION. */ | |
3656 | void | |
3657 | init_yy_io (get, unget, type, name, location) | |
3658 | sh_cget_func_t *get; | |
3659 | sh_cunget_func_t *unget; | |
3660 | enum stream_type type; | |
3661 | const char *name; | |
3662 | INPUT_STREAM location; | |
3663 | { | |
3664 | bash_input.type = type; | |
3665 | FREE (bash_input.name); | |
3666 | bash_input.name = name ? savestring (name) : (char *)NULL; | |
3667 | ||
3668 | /* XXX */ | |
3669 | #if defined (CRAY) | |
3670 | memcpy((char *)&bash_input.location.string, (char *)&location.string, sizeof(location)); | |
3671 | #else | |
3672 | bash_input.location = location; | |
3673 | #endif | |
3674 | bash_input.getter = get; | |
3675 | bash_input.ungetter = unget; | |
3676 | } | |
3677 | ||
7117c2d2 JA |
3678 | char * |
3679 | yy_input_name () | |
3680 | { | |
3681 | return (bash_input.name ? bash_input.name : "stdin"); | |
3682 | } | |
3683 | ||
f73dda09 JA |
3684 | /* Call this to get the next character of input. */ |
3685 | static int | |
3686 | yy_getc () | |
3687 | { | |
3688 | return (*(bash_input.getter)) (); | |
3689 | } | |
3690 | ||
3691 | /* Call this to unget C. That is, to make C the next character | |
3692 | to be read. */ | |
3693 | static int | |
3694 | yy_ungetc (c) | |
3695 | int c; | |
3696 | { | |
3697 | return (*(bash_input.ungetter)) (c); | |
3698 | } | |
3699 | ||
3700 | #if defined (BUFFERED_INPUT) | |
3701 | #ifdef INCLUDE_UNUSED | |
3702 | int | |
3703 | input_file_descriptor () | |
3704 | { | |
3705 | switch (bash_input.type) | |
3706 | { | |
3707 | case st_stream: | |
3708 | return (fileno (bash_input.location.file)); | |
3709 | case st_bstream: | |
3710 | return (bash_input.location.buffered_fd); | |
3711 | case st_stdin: | |
3712 | default: | |
3713 | return (fileno (stdin)); | |
3714 | } | |
3715 | } | |
3716 | #endif | |
3717 | #endif /* BUFFERED_INPUT */ | |
3718 | ||
3719 | /* **************************************************************** */ | |
3720 | /* */ | |
3721 | /* Let input be read from readline (). */ | |
3722 | /* */ | |
3723 | /* **************************************************************** */ | |
3724 | ||
3725 | #if defined (READLINE) | |
3726 | char *current_readline_prompt = (char *)NULL; | |
3727 | char *current_readline_line = (char *)NULL; | |
3728 | int current_readline_line_index = 0; | |
3729 | ||
3730 | static int | |
3731 | yy_readline_get () | |
3732 | { | |
3733 | SigHandler *old_sigint; | |
3734 | int line_len; | |
3735 | unsigned char c; | |
3736 | ||
3737 | if (!current_readline_line) | |
3738 | { | |
3739 | if (!bash_readline_initialized) | |
3740 | initialize_readline (); | |
3741 | ||
3742 | #if defined (JOB_CONTROL) | |
3743 | if (job_control) | |
3744 | give_terminal_to (shell_pgrp, 0); | |
3745 | #endif /* JOB_CONTROL */ | |
3746 | ||
495aee44 | 3747 | old_sigint = (SigHandler *)IMPOSSIBLE_TRAP_HANDLER; |
f73dda09 JA |
3748 | if (signal_is_ignored (SIGINT) == 0) |
3749 | { | |
f73dda09 | 3750 | interrupt_immediately++; |
495aee44 | 3751 | old_sigint = (SigHandler *)set_signal_handler (SIGINT, sigint_sighandler); |
f73dda09 | 3752 | } |
0628567a | 3753 | terminate_immediately = 1; |
f73dda09 JA |
3754 | |
3755 | current_readline_line = readline (current_readline_prompt ? | |
3756 | current_readline_prompt : ""); | |
3757 | ||
0628567a | 3758 | terminate_immediately = 0; |
495aee44 | 3759 | if (signal_is_ignored (SIGINT) == 0) |
f73dda09 JA |
3760 | { |
3761 | interrupt_immediately--; | |
495aee44 CR |
3762 | if (old_sigint != IMPOSSIBLE_TRAP_HANDLER) |
3763 | set_signal_handler (SIGINT, old_sigint); | |
f73dda09 JA |
3764 | } |
3765 | ||
3766 | #if 0 | |
3767 | /* Reset the prompt to the decoded value of prompt_string_pointer. */ | |
3768 | reset_readline_prompt (); | |
3769 | #endif | |
3770 | ||
3771 | if (current_readline_line == 0) | |
3772 | return (EOF); | |
3773 | ||
3774 | current_readline_line_index = 0; | |
3775 | line_len = strlen (current_readline_line); | |
3776 | ||
3777 | current_readline_line = (char *)xrealloc (current_readline_line, 2 + line_len); | |
3778 | current_readline_line[line_len++] = '\n'; | |
3779 | current_readline_line[line_len] = '\0'; | |
3780 | } | |
3781 | ||
3782 | if (current_readline_line[current_readline_line_index] == 0) | |
3783 | { | |
3784 | free (current_readline_line); | |
3785 | current_readline_line = (char *)NULL; | |
3786 | return (yy_readline_get ()); | |
3787 | } | |
3788 | else | |
3789 | { | |
3790 | c = current_readline_line[current_readline_line_index++]; | |
3791 | return (c); | |
3792 | } | |
3793 | } | |
3794 | ||
3795 | static int | |
3796 | yy_readline_unget (c) | |
3797 | int c; | |
3798 | { | |
3799 | if (current_readline_line_index && current_readline_line) | |
3800 | current_readline_line[--current_readline_line_index] = c; | |
3801 | return (c); | |
3802 | } | |
3803 | ||
3804 | void | |
3805 | with_input_from_stdin () | |
3806 | { | |
3807 | INPUT_STREAM location; | |
3808 | ||
3809 | if (bash_input.type != st_stdin && stream_on_stack (st_stdin) == 0) | |
3810 | { | |
3811 | location.string = current_readline_line; | |
3812 | init_yy_io (yy_readline_get, yy_readline_unget, | |
3813 | st_stdin, "readline stdin", location); | |
3814 | } | |
3815 | } | |
3816 | ||
3817 | #else /* !READLINE */ | |
3818 | ||
3819 | void | |
3820 | with_input_from_stdin () | |
3821 | { | |
3822 | with_input_from_stream (stdin, "stdin"); | |
3823 | } | |
3824 | #endif /* !READLINE */ | |
3825 | ||
3826 | /* **************************************************************** */ | |
3827 | /* */ | |
3828 | /* Let input come from STRING. STRING is zero terminated. */ | |
3829 | /* */ | |
3830 | /* **************************************************************** */ | |
3831 | ||
3832 | static int | |
3833 | yy_string_get () | |
3834 | { | |
3835 | register char *string; | |
3836 | register unsigned char c; | |
3837 | ||
3838 | string = bash_input.location.string; | |
3839 | ||
3840 | /* If the string doesn't exist, or is empty, EOF found. */ | |
3841 | if (string && *string) | |
3842 | { | |
3843 | c = *string++; | |
3844 | bash_input.location.string = string; | |
3845 | return (c); | |
3846 | } | |
3847 | else | |
3848 | return (EOF); | |
3849 | } | |
3850 | ||
3851 | static int | |
3852 | yy_string_unget (c) | |
3853 | int c; | |
3854 | { | |
3855 | *(--bash_input.location.string) = c; | |
3856 | return (c); | |
3857 | } | |
3858 | ||
3859 | void | |
3860 | with_input_from_string (string, name) | |
3861 | char *string; | |
3862 | const char *name; | |
3863 | { | |
3864 | INPUT_STREAM location; | |
3865 | ||
3866 | location.string = string; | |
3867 | init_yy_io (yy_string_get, yy_string_unget, st_string, name, location); | |
3868 | } | |
3869 | ||
3185942a JA |
3870 | /* Count the number of characters we've consumed from bash_input.location.string |
3871 | and read into shell_input_line, but have not returned from shell_getc. | |
3872 | That is the true input location. Rewind bash_input.location.string by | |
3873 | that number of characters, so it points to the last character actually | |
3874 | consumed by the parser. */ | |
3875 | static void | |
3876 | rewind_input_string () | |
3877 | { | |
3878 | int xchars; | |
3879 | ||
3880 | /* number of unconsumed characters in the input -- XXX need to take newlines | |
3881 | into account, e.g., $(...\n) */ | |
3882 | xchars = shell_input_line_len - shell_input_line_index; | |
3883 | if (bash_input.location.string[-1] == '\n') | |
3884 | xchars++; | |
3885 | ||
3886 | /* XXX - how to reflect bash_input.location.string back to string passed to | |
3887 | parse_and_execute or xparse_dolparen? xparse_dolparen needs to know how | |
3888 | far into the string we parsed. parse_and_execute knows where bash_input. | |
3889 | location.string is, and how far from orig_string that is -- that's the | |
3890 | number of characters the command consumed. */ | |
3891 | ||
3892 | /* bash_input.location.string - xchars should be where we parsed to */ | |
3893 | /* need to do more validation on xchars value for sanity -- test cases. */ | |
3894 | bash_input.location.string -= xchars; | |
3895 | } | |
3896 | ||
f73dda09 JA |
3897 | /* **************************************************************** */ |
3898 | /* */ | |
3899 | /* Let input come from STREAM. */ | |
3900 | /* */ | |
3901 | /* **************************************************************** */ | |
3902 | ||
3903 | /* These two functions used to test the value of the HAVE_RESTARTABLE_SYSCALLS | |
3904 | define, and just use getc/ungetc if it was defined, but since bash | |
3905 | installs its signal handlers without the SA_RESTART flag, some signals | |
3906 | (like SIGCHLD, SIGWINCH, etc.) received during a read(2) will not cause | |
3907 | the read to be restarted. We need to restart it ourselves. */ | |
3908 | ||
3909 | static int | |
3910 | yy_stream_get () | |
3911 | { | |
3912 | int result; | |
3913 | ||
3914 | result = EOF; | |
3915 | if (bash_input.location.file) | |
95732b49 JA |
3916 | { |
3917 | if (interactive) | |
0628567a JA |
3918 | { |
3919 | interrupt_immediately++; | |
3920 | terminate_immediately++; | |
3921 | } | |
95732b49 JA |
3922 | result = getc_with_restart (bash_input.location.file); |
3923 | if (interactive) | |
0628567a JA |
3924 | { |
3925 | interrupt_immediately--; | |
3926 | terminate_immediately--; | |
3927 | } | |
95732b49 | 3928 | } |
f73dda09 JA |
3929 | return (result); |
3930 | } | |
3931 | ||
3932 | static int | |
3933 | yy_stream_unget (c) | |
3934 | int c; | |
3935 | { | |
3936 | return (ungetc_with_restart (c, bash_input.location.file)); | |
3937 | } | |
3938 | ||
3939 | void | |
3940 | with_input_from_stream (stream, name) | |
3941 | FILE *stream; | |
3942 | const char *name; | |
3943 | { | |
3944 | INPUT_STREAM location; | |
3945 | ||
3946 | location.file = stream; | |
3947 | init_yy_io (yy_stream_get, yy_stream_unget, st_stream, name, location); | |
3948 | } | |
3949 | ||
3950 | typedef struct stream_saver { | |
3951 | struct stream_saver *next; | |
3952 | BASH_INPUT bash_input; | |
3953 | int line; | |
3954 | #if defined (BUFFERED_INPUT) | |
3955 | BUFFERED_STREAM *bstream; | |
3956 | #endif /* BUFFERED_INPUT */ | |
3957 | } STREAM_SAVER; | |
3958 | ||
3959 | /* The globally known line number. */ | |
3960 | int line_number = 0; | |
3961 | ||
495aee44 CR |
3962 | /* The line number offset set by assigning to LINENO. Not currently used. */ |
3963 | int line_number_base = 0; | |
3964 | ||
f73dda09 JA |
3965 | #if defined (COND_COMMAND) |
3966 | static int cond_lineno; | |
3967 | static int cond_token; | |
3968 | #endif | |
3969 | ||
3970 | STREAM_SAVER *stream_list = (STREAM_SAVER *)NULL; | |
3971 | ||
3972 | void | |
3973 | push_stream (reset_lineno) | |
3974 | int reset_lineno; | |
3975 | { | |
3976 | STREAM_SAVER *saver = (STREAM_SAVER *)xmalloc (sizeof (STREAM_SAVER)); | |
3977 | ||
3978 | xbcopy ((char *)&bash_input, (char *)&(saver->bash_input), sizeof (BASH_INPUT)); | |
3979 | ||
3980 | #if defined (BUFFERED_INPUT) | |
3981 | saver->bstream = (BUFFERED_STREAM *)NULL; | |
3982 | /* If we have a buffered stream, clear out buffers[fd]. */ | |
3983 | if (bash_input.type == st_bstream && bash_input.location.buffered_fd >= 0) | |
3984 | saver->bstream = set_buffered_stream (bash_input.location.buffered_fd, | |
3985 | (BUFFERED_STREAM *)NULL); | |
3986 | #endif /* BUFFERED_INPUT */ | |
3987 | ||
3988 | saver->line = line_number; | |
3989 | bash_input.name = (char *)NULL; | |
3990 | saver->next = stream_list; | |
3991 | stream_list = saver; | |
3992 | EOF_Reached = 0; | |
3993 | if (reset_lineno) | |
3994 | line_number = 0; | |
3995 | } | |
3996 | ||
3997 | void | |
3998 | pop_stream () | |
3999 | { | |
4000 | if (!stream_list) | |
4001 | EOF_Reached = 1; | |
4002 | else | |
4003 | { | |
4004 | STREAM_SAVER *saver = stream_list; | |
4005 | ||
4006 | EOF_Reached = 0; | |
4007 | stream_list = stream_list->next; | |
4008 | ||
4009 | init_yy_io (saver->bash_input.getter, | |
4010 | saver->bash_input.ungetter, | |
4011 | saver->bash_input.type, | |
4012 | saver->bash_input.name, | |
4013 | saver->bash_input.location); | |
4014 | ||
4015 | #if defined (BUFFERED_INPUT) | |
4016 | /* If we have a buffered stream, restore buffers[fd]. */ | |
4017 | /* If the input file descriptor was changed while this was on the | |
4018 | save stack, update the buffered fd to the new file descriptor and | |
4019 | re-establish the buffer <-> bash_input fd correspondence. */ | |
4020 | if (bash_input.type == st_bstream && bash_input.location.buffered_fd >= 0) | |
4021 | { | |
4022 | if (bash_input_fd_changed) | |
4023 | { | |
4024 | bash_input_fd_changed = 0; | |
4025 | if (default_buffered_input >= 0) | |
4026 | { | |
4027 | bash_input.location.buffered_fd = default_buffered_input; | |
4028 | saver->bstream->b_fd = default_buffered_input; | |
4029 | SET_CLOSE_ON_EXEC (default_buffered_input); | |
4030 | } | |
4031 | } | |
4032 | /* XXX could free buffered stream returned as result here. */ | |
4033 | set_buffered_stream (bash_input.location.buffered_fd, saver->bstream); | |
4034 | } | |
4035 | #endif /* BUFFERED_INPUT */ | |
4036 | ||
4037 | line_number = saver->line; | |
4038 | ||
4039 | FREE (saver->bash_input.name); | |
4040 | free (saver); | |
4041 | } | |
4042 | } | |
4043 | ||
4044 | /* Return 1 if a stream of type TYPE is saved on the stack. */ | |
4045 | int | |
4046 | stream_on_stack (type) | |
4047 | enum stream_type type; | |
4048 | { | |
4049 | register STREAM_SAVER *s; | |
4050 | ||
4051 | for (s = stream_list; s; s = s->next) | |
4052 | if (s->bash_input.type == type) | |
4053 | return 1; | |
4054 | return 0; | |
4055 | } | |
4056 | ||
4057 | /* Save the current token state and return it in a malloced array. */ | |
4058 | int * | |
4059 | save_token_state () | |
4060 | { | |
4061 | int *ret; | |
4062 | ||
0001803f | 4063 | ret = (int *)xmalloc (4 * sizeof (int)); |
f73dda09 JA |
4064 | ret[0] = last_read_token; |
4065 | ret[1] = token_before_that; | |
4066 | ret[2] = two_tokens_ago; | |
0001803f | 4067 | ret[3] = current_token; |
f73dda09 JA |
4068 | return ret; |
4069 | } | |
4070 | ||
4071 | void | |
4072 | restore_token_state (ts) | |
4073 | int *ts; | |
4074 | { | |
4075 | if (ts == 0) | |
4076 | return; | |
4077 | last_read_token = ts[0]; | |
4078 | token_before_that = ts[1]; | |
4079 | two_tokens_ago = ts[2]; | |
0001803f | 4080 | current_token = ts[3]; |
f73dda09 JA |
4081 | } |
4082 | ||
4083 | /* | |
4084 | * This is used to inhibit alias expansion and reserved word recognition | |
4085 | * inside case statement pattern lists. A `case statement pattern list' is: | |
4086 | * | |
4087 | * everything between the `in' in a `case word in' and the next ')' | |
4088 | * or `esac' | |
4089 | * everything between a `;;' and the next `)' or `esac' | |
4090 | */ | |
4091 | ||
4092 | #if defined (ALIAS) || defined (DPAREN_ARITHMETIC) | |
4093 | ||
f73dda09 JA |
4094 | #define END_OF_ALIAS 0 |
4095 | ||
4096 | /* | |
4097 | * Pseudo-global variables used in implementing token-wise alias expansion. | |
4098 | */ | |
4099 | ||
4100 | /* | |
4101 | * Pushing and popping strings. This works together with shell_getc to | |
4102 | * implement alias expansion on a per-token basis. | |
4103 | */ | |
4104 | ||
4105 | typedef struct string_saver { | |
4106 | struct string_saver *next; | |
4107 | int expand_alias; /* Value to set expand_alias to when string is popped. */ | |
4108 | char *saved_line; | |
4109 | #if defined (ALIAS) | |
4110 | alias_t *expander; /* alias that caused this line to be pushed. */ | |
4111 | #endif | |
4112 | int saved_line_size, saved_line_index, saved_line_terminator; | |
4113 | } STRING_SAVER; | |
4114 | ||
4115 | STRING_SAVER *pushed_string_list = (STRING_SAVER *)NULL; | |
4116 | ||
4117 | /* | |
4118 | * Push the current shell_input_line onto a stack of such lines and make S | |
4119 | * the current input. Used when expanding aliases. EXPAND is used to set | |
4120 | * the value of expand_next_token when the string is popped, so that the | |
4121 | * word after the alias in the original line is handled correctly when the | |
4122 | * alias expands to multiple words. TOKEN is the token that was expanded | |
4123 | * into S; it is saved and used to prevent infinite recursive expansion. | |
4124 | */ | |
4125 | static void | |
4126 | push_string (s, expand, ap) | |
4127 | char *s; | |
4128 | int expand; | |
4129 | alias_t *ap; | |
4130 | { | |
4131 | STRING_SAVER *temp = (STRING_SAVER *)xmalloc (sizeof (STRING_SAVER)); | |
4132 | ||
4133 | temp->expand_alias = expand; | |
4134 | temp->saved_line = shell_input_line; | |
4135 | temp->saved_line_size = shell_input_line_size; | |
4136 | temp->saved_line_index = shell_input_line_index; | |
4137 | temp->saved_line_terminator = shell_input_line_terminator; | |
4138 | #if defined (ALIAS) | |
4139 | temp->expander = ap; | |
4140 | #endif | |
4141 | temp->next = pushed_string_list; | |
4142 | pushed_string_list = temp; | |
4143 | ||
4144 | #if defined (ALIAS) | |
4145 | if (ap) | |
4146 | ap->flags |= AL_BEINGEXPANDED; | |
4147 | #endif | |
4148 | ||
4149 | shell_input_line = s; | |
4150 | shell_input_line_size = strlen (s); | |
4151 | shell_input_line_index = 0; | |
4152 | shell_input_line_terminator = '\0'; | |
b80f6443 JA |
4153 | #if 0 |
4154 | parser_state &= ~PST_ALEXPNEXT; /* XXX */ | |
4155 | #endif | |
7117c2d2 JA |
4156 | |
4157 | set_line_mbstate (); | |
f73dda09 JA |
4158 | } |
4159 | ||
4160 | /* | |
4161 | * Make the top of the pushed_string stack be the current shell input. | |
4162 | * Only called when there is something on the stack. Called from shell_getc | |
4163 | * when it thinks it has consumed the string generated by an alias expansion | |
4164 | * and needs to return to the original input line. | |
4165 | */ | |
4166 | static void | |
4167 | pop_string () | |
4168 | { | |
4169 | STRING_SAVER *t; | |
4170 | ||
4171 | FREE (shell_input_line); | |
4172 | shell_input_line = pushed_string_list->saved_line; | |
4173 | shell_input_line_index = pushed_string_list->saved_line_index; | |
4174 | shell_input_line_size = pushed_string_list->saved_line_size; | |
4175 | shell_input_line_terminator = pushed_string_list->saved_line_terminator; | |
4176 | ||
4177 | if (pushed_string_list->expand_alias) | |
4178 | parser_state |= PST_ALEXPNEXT; | |
4179 | else | |
4180 | parser_state &= ~PST_ALEXPNEXT; | |
4181 | ||
4182 | t = pushed_string_list; | |
4183 | pushed_string_list = pushed_string_list->next; | |
4184 | ||
4185 | #if defined (ALIAS) | |
4186 | if (t->expander) | |
4187 | t->expander->flags &= ~AL_BEINGEXPANDED; | |
4188 | #endif | |
4189 | ||
4190 | free ((char *)t); | |
7117c2d2 JA |
4191 | |
4192 | set_line_mbstate (); | |
f73dda09 JA |
4193 | } |
4194 | ||
4195 | static void | |
4196 | free_string_list () | |
4197 | { | |
4198 | register STRING_SAVER *t, *t1; | |
4199 | ||
4200 | for (t = pushed_string_list; t; ) | |
4201 | { | |
4202 | t1 = t->next; | |
4203 | FREE (t->saved_line); | |
4204 | #if defined (ALIAS) | |
4205 | if (t->expander) | |
4206 | t->expander->flags &= ~AL_BEINGEXPANDED; | |
4207 | #endif | |
4208 | free ((char *)t); | |
4209 | t = t1; | |
4210 | } | |
4211 | pushed_string_list = (STRING_SAVER *)NULL; | |
4212 | } | |
4213 | ||
4214 | #endif /* ALIAS || DPAREN_ARITHMETIC */ | |
4215 | ||
b80f6443 JA |
4216 | void |
4217 | free_pushed_string_input () | |
4218 | { | |
4219 | #if defined (ALIAS) || defined (DPAREN_ARITHMETIC) | |
4220 | free_string_list (); | |
4221 | #endif | |
4222 | } | |
4223 | ||
f73dda09 JA |
4224 | /* Return a line of text, taken from wherever yylex () reads input. |
4225 | If there is no more input, then we return NULL. If REMOVE_QUOTED_NEWLINE | |
4226 | is non-zero, we remove unquoted \<newline> pairs. This is used by | |
4227 | read_secondary_line to read here documents. */ | |
4228 | static char * | |
4229 | read_a_line (remove_quoted_newline) | |
4230 | int remove_quoted_newline; | |
4231 | { | |
4232 | static char *line_buffer = (char *)NULL; | |
4233 | static int buffer_size = 0; | |
0001803f | 4234 | int indx, c, peekc, pass_next; |
f73dda09 JA |
4235 | |
4236 | #if defined (READLINE) | |
b80f6443 | 4237 | if (no_line_editing && SHOULD_PROMPT ()) |
f73dda09 | 4238 | #else |
b80f6443 | 4239 | if (SHOULD_PROMPT ()) |
f73dda09 JA |
4240 | #endif |
4241 | print_prompt (); | |
4242 | ||
0001803f | 4243 | pass_next = indx = 0; |
f73dda09 JA |
4244 | while (1) |
4245 | { | |
f73dda09 JA |
4246 | /* Allow immediate exit if interrupted during input. */ |
4247 | QUIT; | |
4248 | ||
95732b49 JA |
4249 | c = yy_getc (); |
4250 | ||
f73dda09 JA |
4251 | /* Ignore null bytes in input. */ |
4252 | if (c == 0) | |
4253 | { | |
4254 | #if 0 | |
4255 | internal_warning ("read_a_line: ignored null byte in input"); | |
4256 | #endif | |
4257 | continue; | |
4258 | } | |
4259 | ||
4260 | /* If there is no more input, then we return NULL. */ | |
4261 | if (c == EOF) | |
4262 | { | |
4263 | if (interactive && bash_input.type == st_stream) | |
4264 | clearerr (stdin); | |
4265 | if (indx == 0) | |
4266 | return ((char *)NULL); | |
4267 | c = '\n'; | |
4268 | } | |
4269 | ||
4270 | /* `+2' in case the final character in the buffer is a newline. */ | |
4271 | RESIZE_MALLOCED_BUFFER (line_buffer, indx, 2, buffer_size, 128); | |
4272 | ||
4273 | /* IF REMOVE_QUOTED_NEWLINES is non-zero, we are reading a | |
4274 | here document with an unquoted delimiter. In this case, | |
4275 | the line will be expanded as if it were in double quotes. | |
4276 | We allow a backslash to escape the next character, but we | |
4277 | need to treat the backslash specially only if a backslash | |
4278 | quoting a backslash-newline pair appears in the line. */ | |
4279 | if (pass_next) | |
4280 | { | |
4281 | line_buffer[indx++] = c; | |
4282 | pass_next = 0; | |
4283 | } | |
4284 | else if (c == '\\' && remove_quoted_newline) | |
4285 | { | |
495aee44 | 4286 | QUIT; |
f73dda09 JA |
4287 | peekc = yy_getc (); |
4288 | if (peekc == '\n') | |
b80f6443 JA |
4289 | { |
4290 | line_number++; | |
4291 | continue; /* Make the unquoted \<newline> pair disappear. */ | |
4292 | } | |
f73dda09 JA |
4293 | else |
4294 | { | |
4295 | yy_ungetc (peekc); | |
4296 | pass_next = 1; | |
4297 | line_buffer[indx++] = c; /* Preserve the backslash. */ | |
4298 | } | |
4299 | } | |
4300 | else | |
4301 | line_buffer[indx++] = c; | |
4302 | ||
4303 | if (c == '\n') | |
4304 | { | |
4305 | line_buffer[indx] = '\0'; | |
4306 | return (line_buffer); | |
4307 | } | |
4308 | } | |
4309 | } | |
4310 | ||
4311 | /* Return a line as in read_a_line (), but insure that the prompt is | |
4312 | the secondary prompt. This is used to read the lines of a here | |
4313 | document. REMOVE_QUOTED_NEWLINE is non-zero if we should remove | |
4314 | newlines quoted with backslashes while reading the line. It is | |
4315 | non-zero unless the delimiter of the here document was quoted. */ | |
4316 | char * | |
4317 | read_secondary_line (remove_quoted_newline) | |
4318 | int remove_quoted_newline; | |
4319 | { | |
3185942a JA |
4320 | char *ret; |
4321 | int n, c; | |
4322 | ||
f73dda09 | 4323 | prompt_string_pointer = &ps2_prompt; |
b80f6443 JA |
4324 | if (SHOULD_PROMPT()) |
4325 | prompt_again (); | |
3185942a JA |
4326 | ret = read_a_line (remove_quoted_newline); |
4327 | #if defined (HISTORY) | |
0001803f | 4328 | if (ret && remember_on_history && (parser_state & PST_HEREDOC)) |
3185942a JA |
4329 | { |
4330 | /* To make adding the the here-document body right, we need to rely | |
4331 | on history_delimiting_chars() returning \n for the first line of | |
4332 | the here-document body and the null string for the second and | |
4333 | subsequent lines, so we avoid double newlines. | |
4334 | current_command_line_count == 2 for the first line of the body. */ | |
4335 | ||
4336 | current_command_line_count++; | |
4337 | maybe_add_history (ret); | |
4338 | } | |
4339 | #endif /* HISTORY */ | |
4340 | return ret; | |
f73dda09 JA |
4341 | } |
4342 | ||
4343 | /* **************************************************************** */ | |
4344 | /* */ | |
4345 | /* YYLEX () */ | |
4346 | /* */ | |
4347 | /* **************************************************************** */ | |
4348 | ||
4349 | /* Reserved words. These are only recognized as the first word of a | |
4350 | command. */ | |
4351 | STRING_INT_ALIST word_token_alist[] = { | |
4352 | { "if", IF }, | |
4353 | { "then", THEN }, | |
28ef6c31 JA |
4354 | { "else", ELSE }, |
4355 | { "elif", ELIF }, | |
4356 | { "fi", FI }, | |
4357 | { "case", CASE }, | |
4358 | { "esac", ESAC }, | |
4359 | { "for", FOR }, | |
4360 | #if defined (SELECT_COMMAND) | |
4361 | { "select", SELECT }, | |
726f6388 | 4362 | #endif |
28ef6c31 JA |
4363 | { "while", WHILE }, |
4364 | { "until", UNTIL }, | |
4365 | { "do", DO }, | |
4366 | { "done", DONE }, | |
4367 | { "in", IN }, | |
4368 | { "function", FUNCTION }, | |
4369 | #if defined (COMMAND_TIMING) | |
4370 | { "time", TIME }, | |
4371 | #endif | |
4372 | { "{", '{' }, | |
4373 | { "}", '}' }, | |
4374 | { "!", BANG }, | |
4375 | #if defined (COND_COMMAND) | |
4376 | { "[[", COND_START }, | |
4377 | { "]]", COND_END }, | |
3185942a JA |
4378 | #endif |
4379 | #if defined (COPROCESS_SUPPORT) | |
4380 | { "coproc", COPROC }, | |
726f6388 | 4381 | #endif |
28ef6c31 JA |
4382 | { (char *)NULL, 0} |
4383 | }; | |
726f6388 | 4384 | |
7117c2d2 JA |
4385 | /* other tokens that can be returned by read_token() */ |
4386 | STRING_INT_ALIST other_token_alist[] = { | |
4387 | /* Multiple-character tokens with special values */ | |
495aee44 | 4388 | { "--", TIMEIGN }, |
7117c2d2 JA |
4389 | { "-p", TIMEOPT }, |
4390 | { "&&", AND_AND }, | |
4391 | { "||", OR_OR }, | |
4392 | { ">>", GREATER_GREATER }, | |
4393 | { "<<", LESS_LESS }, | |
4394 | { "<&", LESS_AND }, | |
4395 | { ">&", GREATER_AND }, | |
4396 | { ";;", SEMI_SEMI }, | |
3185942a JA |
4397 | { ";&", SEMI_AND }, |
4398 | { ";;&", SEMI_SEMI_AND }, | |
7117c2d2 JA |
4399 | { "<<-", LESS_LESS_MINUS }, |
4400 | { "<<<", LESS_LESS_LESS }, | |
4401 | { "&>", AND_GREATER }, | |
3185942a | 4402 | { "&>>", AND_GREATER_GREATER }, |
7117c2d2 JA |
4403 | { "<>", LESS_GREATER }, |
4404 | { ">|", GREATER_BAR }, | |
3185942a | 4405 | { "|&", BAR_AND }, |
7117c2d2 JA |
4406 | { "EOF", yacc_EOF }, |
4407 | /* Tokens whose value is the character itself */ | |
4408 | { ">", '>' }, | |
4409 | { "<", '<' }, | |
4410 | { "-", '-' }, | |
4411 | { "{", '{' }, | |
4412 | { "}", '}' }, | |
4413 | { ";", ';' }, | |
4414 | { "(", '(' }, | |
4415 | { ")", ')' }, | |
4416 | { "|", '|' }, | |
4417 | { "&", '&' }, | |
4418 | { "newline", '\n' }, | |
4419 | { (char *)NULL, 0} | |
4420 | }; | |
4421 | ||
4422 | /* others not listed here: | |
4423 | WORD look at yylval.word | |
4424 | ASSIGNMENT_WORD look at yylval.word | |
4425 | NUMBER look at yylval.number | |
4426 | ARITH_CMD look at yylval.word_list | |
4427 | ARITH_FOR_EXPRS look at yylval.word_list | |
4428 | COND_CMD look at yylval.command | |
4429 | */ | |
726f6388 | 4430 | |
28ef6c31 JA |
4431 | /* These are used by read_token_word, but appear up here so that shell_getc |
4432 | can use them to decide when to add otherwise blank lines to the history. */ | |
726f6388 | 4433 | |
28ef6c31 JA |
4434 | /* The primary delimiter stack. */ |
4435 | struct dstack dstack = { (char *)NULL, 0, 0 }; | |
726f6388 | 4436 | |
28ef6c31 JA |
4437 | /* A temporary delimiter stack to be used when decoding prompt strings. |
4438 | This is needed because command substitutions in prompt strings (e.g., PS2) | |
4439 | can screw up the parser's quoting state. */ | |
4440 | static struct dstack temp_dstack = { (char *)NULL, 0, 0 }; | |
726f6388 | 4441 | |
28ef6c31 JA |
4442 | /* Macro for accessing the top delimiter on the stack. Returns the |
4443 | delimiter or zero if none. */ | |
4444 | #define current_delimiter(ds) \ | |
4445 | (ds.delimiter_depth ? ds.delimiters[ds.delimiter_depth - 1] : 0) | |
726f6388 | 4446 | |
28ef6c31 JA |
4447 | #define push_delimiter(ds, character) \ |
4448 | do \ | |
4449 | { \ | |
4450 | if (ds.delimiter_depth + 2 > ds.delimiter_space) \ | |
f73dda09 | 4451 | ds.delimiters = (char *)xrealloc \ |
28ef6c31 JA |
4452 | (ds.delimiters, (ds.delimiter_space += 10) * sizeof (char)); \ |
4453 | ds.delimiters[ds.delimiter_depth] = character; \ | |
4454 | ds.delimiter_depth++; \ | |
4455 | } \ | |
4456 | while (0) | |
726f6388 | 4457 | |
28ef6c31 | 4458 | #define pop_delimiter(ds) ds.delimiter_depth-- |
726f6388 | 4459 | |
28ef6c31 JA |
4460 | /* Return the next shell input character. This always reads characters |
4461 | from shell_input_line; when that line is exhausted, it is time to | |
4462 | read the next line. This is called by read_token when the shell is | |
4463 | processing normal command input. */ | |
ccc6cda3 | 4464 | |
28ef6c31 JA |
4465 | /* This implements one-character lookahead/lookbehind across physical input |
4466 | lines, to avoid something being lost because it's pushed back with | |
4467 | shell_ungetc when we're at the start of a line. */ | |
4468 | static int eol_ungetc_lookahead = 0; | |
726f6388 | 4469 | |
28ef6c31 JA |
4470 | static int |
4471 | shell_getc (remove_quoted_newline) | |
4472 | int remove_quoted_newline; | |
4473 | { | |
4474 | register int i; | |
4475 | int c; | |
f73dda09 | 4476 | unsigned char uc; |
726f6388 | 4477 | |
28ef6c31 | 4478 | QUIT; |
726f6388 | 4479 | |
95732b49 JA |
4480 | if (sigwinch_received) |
4481 | { | |
4482 | sigwinch_received = 0; | |
4483 | get_new_window_size (0, (int *)0, (int *)0); | |
4484 | } | |
4485 | ||
28ef6c31 JA |
4486 | if (eol_ungetc_lookahead) |
4487 | { | |
4488 | c = eol_ungetc_lookahead; | |
4489 | eol_ungetc_lookahead = 0; | |
4490 | return (c); | |
4491 | } | |
ccc6cda3 | 4492 | |
28ef6c31 JA |
4493 | #if defined (ALIAS) || defined (DPAREN_ARITHMETIC) |
4494 | /* If shell_input_line[shell_input_line_index] == 0, but there is | |
4495 | something on the pushed list of strings, then we don't want to go | |
4496 | off and get another line. We let the code down below handle it. */ | |
b72432fd | 4497 | |
28ef6c31 JA |
4498 | if (!shell_input_line || ((!shell_input_line[shell_input_line_index]) && |
4499 | (pushed_string_list == (STRING_SAVER *)NULL))) | |
4500 | #else /* !ALIAS && !DPAREN_ARITHMETIC */ | |
4501 | if (!shell_input_line || !shell_input_line[shell_input_line_index]) | |
4502 | #endif /* !ALIAS && !DPAREN_ARITHMETIC */ | |
4503 | { | |
4504 | line_number++; | |
726f6388 | 4505 | |
28ef6c31 | 4506 | restart_read: |
726f6388 | 4507 | |
28ef6c31 JA |
4508 | /* Allow immediate exit if interrupted during input. */ |
4509 | QUIT; | |
ccc6cda3 | 4510 | |
28ef6c31 JA |
4511 | i = 0; |
4512 | shell_input_line_terminator = 0; | |
726f6388 | 4513 | |
b80f6443 JA |
4514 | /* If the shell is interatctive, but not currently printing a prompt |
4515 | (interactive_shell && interactive == 0), we don't want to print | |
4516 | notifies or cleanup the jobs -- we want to defer it until we do | |
4517 | print the next prompt. */ | |
4518 | if (interactive_shell == 0 || SHOULD_PROMPT()) | |
4519 | { | |
28ef6c31 JA |
4520 | #if defined (JOB_CONTROL) |
4521 | /* This can cause a problem when reading a command as the result | |
4522 | of a trap, when the trap is called from flush_child. This call | |
4523 | had better not cause jobs to disappear from the job table in | |
4524 | that case, or we will have big trouble. */ | |
b80f6443 | 4525 | notify_and_cleanup (); |
28ef6c31 | 4526 | #else /* !JOB_CONTROL */ |
b80f6443 | 4527 | cleanup_dead_jobs (); |
28ef6c31 | 4528 | #endif /* !JOB_CONTROL */ |
b80f6443 | 4529 | } |
ccc6cda3 | 4530 | |
28ef6c31 | 4531 | #if defined (READLINE) |
b80f6443 | 4532 | if (no_line_editing && SHOULD_PROMPT()) |
28ef6c31 | 4533 | #else |
b80f6443 | 4534 | if (SHOULD_PROMPT()) |
28ef6c31 JA |
4535 | #endif |
4536 | print_prompt (); | |
726f6388 | 4537 | |
28ef6c31 JA |
4538 | if (bash_input.type == st_stream) |
4539 | clearerr (stdin); | |
726f6388 | 4540 | |
28ef6c31 JA |
4541 | while (1) |
4542 | { | |
4543 | c = yy_getc (); | |
4544 | ||
4545 | /* Allow immediate exit if interrupted during input. */ | |
4546 | QUIT; | |
4547 | ||
4548 | if (c == '\0') | |
4549 | { | |
4550 | #if 0 | |
4551 | internal_warning ("shell_getc: ignored null byte in input"); | |
ccc6cda3 | 4552 | #endif |
28ef6c31 JA |
4553 | continue; |
4554 | } | |
ccc6cda3 | 4555 | |
28ef6c31 | 4556 | RESIZE_MALLOCED_BUFFER (shell_input_line, i, 2, shell_input_line_size, 256); |
726f6388 | 4557 | |
28ef6c31 JA |
4558 | if (c == EOF) |
4559 | { | |
4560 | if (bash_input.type == st_stream) | |
4561 | clearerr (stdin); | |
726f6388 | 4562 | |
28ef6c31 JA |
4563 | if (i == 0) |
4564 | shell_input_line_terminator = EOF; | |
726f6388 | 4565 | |
28ef6c31 JA |
4566 | shell_input_line[i] = '\0'; |
4567 | break; | |
4568 | } | |
726f6388 | 4569 | |
28ef6c31 | 4570 | shell_input_line[i++] = c; |
726f6388 | 4571 | |
28ef6c31 JA |
4572 | if (c == '\n') |
4573 | { | |
4574 | shell_input_line[--i] = '\0'; | |
4575 | current_command_line_count++; | |
4576 | break; | |
4577 | } | |
4578 | } | |
726f6388 | 4579 | |
28ef6c31 JA |
4580 | shell_input_line_index = 0; |
4581 | shell_input_line_len = i; /* == strlen (shell_input_line) */ | |
ccc6cda3 | 4582 | |
7117c2d2 JA |
4583 | set_line_mbstate (); |
4584 | ||
28ef6c31 JA |
4585 | #if defined (HISTORY) |
4586 | if (remember_on_history && shell_input_line && shell_input_line[0]) | |
4587 | { | |
4588 | char *expansions; | |
4589 | # if defined (BANG_HISTORY) | |
4590 | int old_hist; | |
726f6388 | 4591 | |
28ef6c31 JA |
4592 | /* If the current delimiter is a single quote, we should not be |
4593 | performing history expansion, even if we're on a different | |
4594 | line from the original single quote. */ | |
4595 | old_hist = history_expansion_inhibited; | |
4596 | if (current_delimiter (dstack) == '\'') | |
4597 | history_expansion_inhibited = 1; | |
4598 | # endif | |
4599 | expansions = pre_process_line (shell_input_line, 1, 1); | |
4600 | # if defined (BANG_HISTORY) | |
4601 | history_expansion_inhibited = old_hist; | |
4602 | # endif | |
4603 | if (expansions != shell_input_line) | |
4604 | { | |
4605 | free (shell_input_line); | |
4606 | shell_input_line = expansions; | |
4607 | shell_input_line_len = shell_input_line ? | |
4608 | strlen (shell_input_line) : 0; | |
495aee44 | 4609 | if (shell_input_line_len == 0) |
28ef6c31 | 4610 | current_command_line_count--; |
726f6388 | 4611 | |
28ef6c31 JA |
4612 | /* We have to force the xrealloc below because we don't know |
4613 | the true allocated size of shell_input_line anymore. */ | |
4614 | shell_input_line_size = shell_input_line_len; | |
7117c2d2 JA |
4615 | |
4616 | set_line_mbstate (); | |
28ef6c31 JA |
4617 | } |
4618 | } | |
4619 | /* Try to do something intelligent with blank lines encountered while | |
4620 | entering multi-line commands. XXX - this is grotesque */ | |
4621 | else if (remember_on_history && shell_input_line && | |
4622 | shell_input_line[0] == '\0' && | |
4623 | current_command_line_count > 1) | |
726f6388 | 4624 | { |
28ef6c31 JA |
4625 | if (current_delimiter (dstack)) |
4626 | /* We know shell_input_line[0] == 0 and we're reading some sort of | |
4627 | quoted string. This means we've got a line consisting of only | |
4628 | a newline in a quoted string. We want to make sure this line | |
4629 | gets added to the history. */ | |
4630 | maybe_add_history (shell_input_line); | |
4631 | else | |
4632 | { | |
4633 | char *hdcs; | |
495aee44 | 4634 | hdcs = history_delimiting_chars (shell_input_line); |
28ef6c31 JA |
4635 | if (hdcs && hdcs[0] == ';') |
4636 | maybe_add_history (shell_input_line); | |
4637 | } | |
726f6388 JA |
4638 | } |
4639 | ||
28ef6c31 | 4640 | #endif /* HISTORY */ |
726f6388 | 4641 | |
28ef6c31 | 4642 | if (shell_input_line) |
726f6388 | 4643 | { |
28ef6c31 JA |
4644 | /* Lines that signify the end of the shell's input should not be |
4645 | echoed. */ | |
4646 | if (echo_input_at_read && (shell_input_line[0] || | |
4647 | shell_input_line_terminator != EOF)) | |
4648 | fprintf (stderr, "%s\n", shell_input_line); | |
4649 | } | |
4650 | else | |
4651 | { | |
4652 | shell_input_line_size = 0; | |
4653 | prompt_string_pointer = ¤t_prompt_string; | |
b80f6443 JA |
4654 | if (SHOULD_PROMPT ()) |
4655 | prompt_again (); | |
28ef6c31 | 4656 | goto restart_read; |
726f6388 JA |
4657 | } |
4658 | ||
28ef6c31 JA |
4659 | /* Add the newline to the end of this string, iff the string does |
4660 | not already end in an EOF character. */ | |
4661 | if (shell_input_line_terminator != EOF) | |
4662 | { | |
4663 | if (shell_input_line_len + 3 > shell_input_line_size) | |
f73dda09 | 4664 | shell_input_line = (char *)xrealloc (shell_input_line, |
28ef6c31 | 4665 | 1 + (shell_input_line_size += 2)); |
726f6388 | 4666 | |
28ef6c31 JA |
4667 | shell_input_line[shell_input_line_len] = '\n'; |
4668 | shell_input_line[shell_input_line_len + 1] = '\0'; | |
7117c2d2 JA |
4669 | |
4670 | set_line_mbstate (); | |
28ef6c31 JA |
4671 | } |
4672 | } | |
726f6388 | 4673 | |
495aee44 | 4674 | next_alias_char: |
f73dda09 | 4675 | uc = shell_input_line[shell_input_line_index]; |
ccc6cda3 | 4676 | |
f73dda09 | 4677 | if (uc) |
28ef6c31 | 4678 | shell_input_line_index++; |
726f6388 | 4679 | |
28ef6c31 | 4680 | #if defined (ALIAS) || defined (DPAREN_ARITHMETIC) |
f73dda09 | 4681 | /* If UC is NULL, we have reached the end of the current input string. If |
28ef6c31 JA |
4682 | pushed_string_list is non-empty, it's time to pop to the previous string |
4683 | because we have fully consumed the result of the last alias expansion. | |
4684 | Do it transparently; just return the next character of the string popped | |
4685 | to. */ | |
0001803f | 4686 | pop_alias: |
495aee44 | 4687 | if (uc == 0 && (pushed_string_list != (STRING_SAVER *)NULL)) |
726f6388 | 4688 | { |
b80f6443 JA |
4689 | pop_string (); |
4690 | uc = shell_input_line[shell_input_line_index]; | |
4691 | if (uc) | |
4692 | shell_input_line_index++; | |
726f6388 | 4693 | } |
28ef6c31 JA |
4694 | #endif /* ALIAS || DPAREN_ARITHMETIC */ |
4695 | ||
95732b49 JA |
4696 | if MBTEST(uc == '\\' && remove_quoted_newline && shell_input_line[shell_input_line_index] == '\n') |
4697 | { | |
4698 | if (SHOULD_PROMPT ()) | |
4699 | prompt_again (); | |
4700 | line_number++; | |
495aee44 CR |
4701 | /* What do we do here if we're expanding an alias whose definition |
4702 | includes an escaped newline? If that's the last character in the | |
4703 | alias expansion, we just pop the pushed string list (recall that | |
4704 | we inhibit the appending of a space in mk_alexpansion() if newline | |
4705 | is the last character). If it's not the last character, we need | |
4706 | to consume the quoted newline and move to the next character in | |
4707 | the expansion. */ | |
0001803f CR |
4708 | if (expanding_alias () && shell_input_line[shell_input_line_index+1] == '\0') |
4709 | { | |
4710 | uc = 0; | |
4711 | goto pop_alias; | |
4712 | } | |
495aee44 CR |
4713 | else if (expanding_alias () && shell_input_line[shell_input_line_index+1] != '\0') |
4714 | { | |
4715 | shell_input_line_index++; /* skip newline */ | |
4716 | goto next_alias_char; /* and get next character */ | |
4717 | } | |
4718 | else | |
4719 | goto restart_read; | |
95732b49 JA |
4720 | } |
4721 | ||
495aee44 | 4722 | if (uc == 0 && shell_input_line_terminator == EOF) |
28ef6c31 JA |
4723 | return ((shell_input_line_index != 0) ? '\n' : EOF); |
4724 | ||
f73dda09 | 4725 | return (uc); |
726f6388 JA |
4726 | } |
4727 | ||
7117c2d2 JA |
4728 | /* Put C back into the input for the shell. This might need changes for |
4729 | HANDLE_MULTIBYTE around EOLs. Since we (currently) never push back a | |
4730 | character different than we read, shell_input_line_property doesn't need | |
4731 | to change when manipulating shell_input_line. The define for | |
4732 | last_shell_getc_is_singlebyte should take care of it, though. */ | |
28ef6c31 JA |
4733 | static void |
4734 | shell_ungetc (c) | |
ccc6cda3 | 4735 | int c; |
726f6388 | 4736 | { |
28ef6c31 JA |
4737 | if (shell_input_line && shell_input_line_index) |
4738 | shell_input_line[--shell_input_line_index] = c; | |
4739 | else | |
4740 | eol_ungetc_lookahead = c; | |
726f6388 JA |
4741 | } |
4742 | ||
f73dda09 JA |
4743 | #ifdef INCLUDE_UNUSED |
4744 | /* Back the input pointer up by one, effectively `ungetting' a character. */ | |
28ef6c31 JA |
4745 | static void |
4746 | shell_ungetchar () | |
726f6388 | 4747 | { |
28ef6c31 JA |
4748 | if (shell_input_line && shell_input_line_index) |
4749 | shell_input_line_index--; | |
726f6388 | 4750 | } |
f73dda09 | 4751 | #endif |
726f6388 | 4752 | |
28ef6c31 JA |
4753 | /* Discard input until CHARACTER is seen, then push that character back |
4754 | onto the input stream. */ | |
4755 | static void | |
4756 | discard_until (character) | |
4757 | int character; | |
726f6388 | 4758 | { |
28ef6c31 | 4759 | int c; |
726f6388 | 4760 | |
28ef6c31 JA |
4761 | while ((c = shell_getc (0)) != EOF && c != character) |
4762 | ; | |
726f6388 | 4763 | |
28ef6c31 JA |
4764 | if (c != EOF) |
4765 | shell_ungetc (c); | |
4766 | } | |
726f6388 | 4767 | |
28ef6c31 | 4768 | void |
0628567a JA |
4769 | execute_variable_command (command, vname) |
4770 | char *command, *vname; | |
28ef6c31 | 4771 | { |
28ef6c31 | 4772 | char *last_lastarg; |
b80f6443 | 4773 | sh_parser_state_t ps; |
726f6388 | 4774 | |
b80f6443 | 4775 | save_parser_state (&ps); |
28ef6c31 JA |
4776 | last_lastarg = get_string_value ("_"); |
4777 | if (last_lastarg) | |
4778 | last_lastarg = savestring (last_lastarg); | |
726f6388 | 4779 | |
0628567a | 4780 | parse_and_execute (savestring (command), vname, SEVAL_NONINT|SEVAL_NOHIST); |
726f6388 | 4781 | |
b80f6443 | 4782 | restore_parser_state (&ps); |
95732b49 | 4783 | bind_variable ("_", last_lastarg, 0); |
28ef6c31 JA |
4784 | FREE (last_lastarg); |
4785 | ||
4786 | if (token_to_read == '\n') /* reset_parser was called */ | |
4787 | token_to_read = 0; | |
726f6388 JA |
4788 | } |
4789 | ||
28ef6c31 JA |
4790 | /* Place to remember the token. We try to keep the buffer |
4791 | at a reasonable size, but it can grow. */ | |
4792 | static char *token = (char *)NULL; | |
726f6388 | 4793 | |
28ef6c31 JA |
4794 | /* Current size of the token buffer. */ |
4795 | static int token_buffer_size; | |
4796 | ||
4797 | /* Command to read_token () explaining what we want it to do. */ | |
4798 | #define READ 0 | |
4799 | #define RESET 1 | |
4800 | #define prompt_is_ps1 \ | |
4801 | (!prompt_string_pointer || prompt_string_pointer == &ps1_prompt) | |
bb70624e | 4802 | |
28ef6c31 JA |
4803 | /* Function for yyparse to call. yylex keeps track of |
4804 | the last two tokens read, and calls read_token. */ | |
726f6388 | 4805 | static int |
28ef6c31 | 4806 | yylex () |
726f6388 | 4807 | { |
28ef6c31 JA |
4808 | if (interactive && (current_token == 0 || current_token == '\n')) |
4809 | { | |
4810 | /* Before we print a prompt, we might have to check mailboxes. | |
4811 | We do this only if it is time to do so. Notice that only here | |
4812 | is the mail alarm reset; nothing takes place in check_mail () | |
4813 | except the checking of mail. Please don't change this. */ | |
4814 | if (prompt_is_ps1 && time_to_check_mail ()) | |
4815 | { | |
4816 | check_mail (); | |
4817 | reset_mail_timer (); | |
4818 | } | |
726f6388 | 4819 | |
28ef6c31 JA |
4820 | /* Avoid printing a prompt if we're not going to read anything, e.g. |
4821 | after resetting the parser with read_token (RESET). */ | |
b80f6443 | 4822 | if (token_to_read == 0 && SHOULD_PROMPT ()) |
28ef6c31 JA |
4823 | prompt_again (); |
4824 | } | |
bb70624e | 4825 | |
28ef6c31 JA |
4826 | two_tokens_ago = token_before_that; |
4827 | token_before_that = last_read_token; | |
4828 | last_read_token = current_token; | |
4829 | current_token = read_token (READ); | |
3185942a JA |
4830 | |
4831 | if ((parser_state & PST_EOFTOKEN) && current_token == shell_eof_token) | |
4832 | { | |
4833 | current_token = yacc_EOF; | |
4834 | if (bash_input.type == st_string) | |
4835 | rewind_input_string (); | |
4836 | } | |
4837 | parser_state &= ~PST_EOFTOKEN; | |
4838 | ||
28ef6c31 | 4839 | return (current_token); |
726f6388 JA |
4840 | } |
4841 | ||
28ef6c31 JA |
4842 | /* When non-zero, we have read the required tokens |
4843 | which allow ESAC to be the next one read. */ | |
4844 | static int esacs_needed_count; | |
726f6388 JA |
4845 | |
4846 | void | |
28ef6c31 | 4847 | gather_here_documents () |
726f6388 | 4848 | { |
3185942a JA |
4849 | int r; |
4850 | ||
4851 | r = 0; | |
28ef6c31 JA |
4852 | while (need_here_doc) |
4853 | { | |
3185942a JA |
4854 | parser_state |= PST_HEREDOC; |
4855 | make_here_document (redir_stack[r++], line_number); | |
4856 | parser_state &= ~PST_HEREDOC; | |
28ef6c31 JA |
4857 | need_here_doc--; |
4858 | } | |
726f6388 JA |
4859 | } |
4860 | ||
28ef6c31 JA |
4861 | /* When non-zero, an open-brace used to create a group is awaiting a close |
4862 | brace partner. */ | |
4863 | static int open_brace_count; | |
726f6388 | 4864 | |
28ef6c31 | 4865 | #define command_token_position(token) \ |
0001803f | 4866 | (((token) == ASSIGNMENT_WORD) || (parser_state&PST_REDIRLIST) || \ |
3185942a | 4867 | ((token) != SEMI_SEMI && (token) != SEMI_AND && (token) != SEMI_SEMI_AND && reserved_word_acceptable(token))) |
cce855bc | 4868 | |
b80f6443 JA |
4869 | #define assignment_acceptable(token) \ |
4870 | (command_token_position(token) && ((parser_state & PST_CASEPAT) == 0)) | |
726f6388 | 4871 | |
28ef6c31 JA |
4872 | /* Check to see if TOKEN is a reserved word and return the token |
4873 | value if it is. */ | |
4874 | #define CHECK_FOR_RESERVED_WORD(tok) \ | |
4875 | do { \ | |
4876 | if (!dollar_present && !quoted && \ | |
4877 | reserved_word_acceptable (last_read_token)) \ | |
4878 | { \ | |
4879 | int i; \ | |
4880 | for (i = 0; word_token_alist[i].word != (char *)NULL; i++) \ | |
4881 | if (STREQ (tok, word_token_alist[i].word)) \ | |
4882 | { \ | |
4883 | if ((parser_state & PST_CASEPAT) && (word_token_alist[i].token != ESAC)) \ | |
4884 | break; \ | |
b80f6443 | 4885 | if (word_token_alist[i].token == TIME && time_command_acceptable () == 0) \ |
28ef6c31 JA |
4886 | break; \ |
4887 | if (word_token_alist[i].token == ESAC) \ | |
4888 | parser_state &= ~(PST_CASEPAT|PST_CASESTMT); \ | |
4889 | else if (word_token_alist[i].token == CASE) \ | |
4890 | parser_state |= PST_CASESTMT; \ | |
4891 | else if (word_token_alist[i].token == COND_END) \ | |
4892 | parser_state &= ~(PST_CONDCMD|PST_CONDEXPR); \ | |
4893 | else if (word_token_alist[i].token == COND_START) \ | |
4894 | parser_state |= PST_CONDCMD; \ | |
4895 | else if (word_token_alist[i].token == '{') \ | |
4896 | open_brace_count++; \ | |
4897 | else if (word_token_alist[i].token == '}' && open_brace_count) \ | |
4898 | open_brace_count--; \ | |
4899 | return (word_token_alist[i].token); \ | |
4900 | } \ | |
4901 | } \ | |
4902 | } while (0) | |
726f6388 | 4903 | |
28ef6c31 | 4904 | #if defined (ALIAS) |
726f6388 | 4905 | |
28ef6c31 JA |
4906 | /* OK, we have a token. Let's try to alias expand it, if (and only if) |
4907 | it's eligible. | |
726f6388 | 4908 | |
7117c2d2 | 4909 | It is eligible for expansion if EXPAND_ALIASES is set, and |
28ef6c31 JA |
4910 | the token is unquoted and the last token read was a command |
4911 | separator (or expand_next_token is set), and we are currently | |
4912 | processing an alias (pushed_string_list is non-empty) and this | |
4913 | token is not the same as the current or any previously | |
4914 | processed alias. | |
726f6388 | 4915 | |
28ef6c31 JA |
4916 | Special cases that disqualify: |
4917 | In a pattern list in a case statement (parser_state & PST_CASEPAT). */ | |
b80f6443 JA |
4918 | |
4919 | static char * | |
4920 | mk_alexpansion (s) | |
4921 | char *s; | |
4922 | { | |
4923 | int l; | |
4924 | char *r; | |
4925 | ||
4926 | l = strlen (s); | |
4927 | r = xmalloc (l + 2); | |
4928 | strcpy (r, s); | |
495aee44 CR |
4929 | /* If the last character in the alias is a newline, don't add a trailing |
4930 | space to the expansion. Works with shell_getc above. */ | |
4931 | if (r[l - 1] != ' ' && r[l - 1] != '\n') | |
b80f6443 JA |
4932 | r[l++] = ' '; |
4933 | r[l] = '\0'; | |
4934 | return r; | |
4935 | } | |
4936 | ||
28ef6c31 | 4937 | static int |
f73dda09 JA |
4938 | alias_expand_token (tokstr) |
4939 | char *tokstr; | |
726f6388 | 4940 | { |
28ef6c31 JA |
4941 | char *expanded; |
4942 | alias_t *ap; | |
4943 | ||
4944 | if (((parser_state & PST_ALEXPNEXT) || command_token_position (last_read_token)) && | |
4945 | (parser_state & PST_CASEPAT) == 0) | |
726f6388 | 4946 | { |
f73dda09 | 4947 | ap = find_alias (tokstr); |
726f6388 | 4948 | |
28ef6c31 JA |
4949 | /* Currently expanding this token. */ |
4950 | if (ap && (ap->flags & AL_BEINGEXPANDED)) | |
4951 | return (NO_EXPANSION); | |
726f6388 | 4952 | |
b80f6443 JA |
4953 | /* mk_alexpansion puts an extra space on the end of the alias expansion, |
4954 | so the lookahead by the parser works right. If this gets changed, | |
4955 | make sure the code in shell_getc that deals with reaching the end of | |
4956 | an expanded alias is changed with it. */ | |
4957 | expanded = ap ? mk_alexpansion (ap->value) : (char *)NULL; | |
4958 | ||
28ef6c31 JA |
4959 | if (expanded) |
4960 | { | |
4961 | push_string (expanded, ap->flags & AL_EXPANDNEXT, ap); | |
4962 | return (RE_READ_TOKEN); | |
4963 | } | |
4964 | else | |
4965 | /* This is an eligible token that does not have an expansion. */ | |
4966 | return (NO_EXPANSION); | |
4967 | } | |
4968 | return (NO_EXPANSION); | |
4969 | } | |
4970 | #endif /* ALIAS */ | |
726f6388 | 4971 | |
28ef6c31 JA |
4972 | static int |
4973 | time_command_acceptable () | |
726f6388 | 4974 | { |
28ef6c31 | 4975 | #if defined (COMMAND_TIMING) |
495aee44 CR |
4976 | int i; |
4977 | ||
4978 | if (posixly_correct && shell_compatibility_level > 41) | |
4979 | { | |
4980 | /* Quick check of the rest of the line to find the next token. If it | |
4981 | begins with a `-', Posix says to not return `time' as the token. | |
4982 | This was interp 267. */ | |
4983 | i = shell_input_line_index; | |
4984 | while (i < shell_input_line_len && (shell_input_line[i] == ' ' || shell_input_line[i] == '\t')) | |
4985 | i++; | |
4986 | if (shell_input_line[i] == '-') | |
4987 | return 0; | |
4988 | } | |
4989 | ||
28ef6c31 JA |
4990 | switch (last_read_token) |
4991 | { | |
4992 | case 0: | |
4993 | case ';': | |
4994 | case '\n': | |
4995 | case AND_AND: | |
4996 | case OR_OR: | |
4997 | case '&': | |
4998 | case DO: | |
4999 | case THEN: | |
5000 | case ELSE: | |
5001 | case '{': /* } */ | |
5002 | case '(': /* ) */ | |
495aee44 CR |
5003 | case BANG: /* ! time pipeline */ |
5004 | case TIME: /* time time pipeline */ | |
5005 | case TIMEOPT: /* time -p time pipeline */ | |
5006 | case TIMEIGN: /* time -p -- ... */ | |
726f6388 | 5007 | return 1; |
28ef6c31 JA |
5008 | default: |
5009 | return 0; | |
5010 | } | |
5011 | #else | |
726f6388 | 5012 | return 0; |
28ef6c31 | 5013 | #endif /* COMMAND_TIMING */ |
726f6388 JA |
5014 | } |
5015 | ||
28ef6c31 JA |
5016 | /* Handle special cases of token recognition: |
5017 | IN is recognized if the last token was WORD and the token | |
5018 | before that was FOR or CASE or SELECT. | |
726f6388 | 5019 | |
28ef6c31 JA |
5020 | DO is recognized if the last token was WORD and the token |
5021 | before that was FOR or SELECT. | |
cce855bc | 5022 | |
28ef6c31 JA |
5023 | ESAC is recognized if the last token caused `esacs_needed_count' |
5024 | to be set | |
ccc6cda3 | 5025 | |
28ef6c31 JA |
5026 | `{' is recognized if the last token as WORD and the token |
5027 | before that was FUNCTION, or if we just parsed an arithmetic | |
5028 | `for' command. | |
ccc6cda3 | 5029 | |
28ef6c31 | 5030 | `}' is recognized if there is an unclosed `{' present. |
726f6388 | 5031 | |
28ef6c31 | 5032 | `-p' is returned as TIMEOPT if the last read token was TIME. |
495aee44 | 5033 | `--' is returned as TIMEIGN if the last read token was TIMEOPT. |
726f6388 | 5034 | |
28ef6c31 JA |
5035 | ']]' is returned as COND_END if the parser is currently parsing |
5036 | a conditional expression ((parser_state & PST_CONDEXPR) != 0) | |
726f6388 | 5037 | |
28ef6c31 JA |
5038 | `time' is returned as TIME if and only if it is immediately |
5039 | preceded by one of `;', `\n', `||', `&&', or `&'. | |
5040 | */ | |
726f6388 | 5041 | |
28ef6c31 | 5042 | static int |
f73dda09 JA |
5043 | special_case_tokens (tokstr) |
5044 | char *tokstr; | |
726f6388 | 5045 | { |
28ef6c31 JA |
5046 | if ((last_read_token == WORD) && |
5047 | #if defined (SELECT_COMMAND) | |
5048 | ((token_before_that == FOR) || (token_before_that == CASE) || (token_before_that == SELECT)) && | |
5049 | #else | |
5050 | ((token_before_that == FOR) || (token_before_that == CASE)) && | |
cce855bc | 5051 | #endif |
f73dda09 | 5052 | (tokstr[0] == 'i' && tokstr[1] == 'n' && tokstr[2] == 0)) |
28ef6c31 JA |
5053 | { |
5054 | if (token_before_that == CASE) | |
5055 | { | |
5056 | parser_state |= PST_CASEPAT; | |
5057 | esacs_needed_count++; | |
5058 | } | |
5059 | return (IN); | |
5060 | } | |
726f6388 | 5061 | |
28ef6c31 JA |
5062 | if (last_read_token == WORD && |
5063 | #if defined (SELECT_COMMAND) | |
5064 | (token_before_that == FOR || token_before_that == SELECT) && | |
5065 | #else | |
5066 | (token_before_that == FOR) && | |
cce855bc | 5067 | #endif |
f73dda09 | 5068 | (tokstr[0] == 'd' && tokstr[1] == 'o' && tokstr[2] == '\0')) |
28ef6c31 | 5069 | return (DO); |
726f6388 | 5070 | |
28ef6c31 JA |
5071 | /* Ditto for ESAC in the CASE case. |
5072 | Specifically, this handles "case word in esac", which is a legal | |
5073 | construct, certainly because someone will pass an empty arg to the | |
5074 | case construct, and we don't want it to barf. Of course, we should | |
5075 | insist that the case construct has at least one pattern in it, but | |
5076 | the designers disagree. */ | |
5077 | if (esacs_needed_count) | |
5078 | { | |
5079 | esacs_needed_count--; | |
f73dda09 | 5080 | if (STREQ (tokstr, "esac")) |
28ef6c31 JA |
5081 | { |
5082 | parser_state &= ~PST_CASEPAT; | |
5083 | return (ESAC); | |
5084 | } | |
5085 | } | |
726f6388 | 5086 | |
28ef6c31 JA |
5087 | /* The start of a shell function definition. */ |
5088 | if (parser_state & PST_ALLOWOPNBRC) | |
5089 | { | |
5090 | parser_state &= ~PST_ALLOWOPNBRC; | |
f73dda09 | 5091 | if (tokstr[0] == '{' && tokstr[1] == '\0') /* } */ |
28ef6c31 JA |
5092 | { |
5093 | open_brace_count++; | |
5094 | function_bstart = line_number; | |
5095 | return ('{'); /* } */ | |
5096 | } | |
5097 | } | |
726f6388 | 5098 | |
28ef6c31 JA |
5099 | /* We allow a `do' after a for ((...)) without an intervening |
5100 | list_terminator */ | |
f73dda09 | 5101 | if (last_read_token == ARITH_FOR_EXPRS && tokstr[0] == 'd' && tokstr[1] == 'o' && !tokstr[2]) |
28ef6c31 | 5102 | return (DO); |
f73dda09 | 5103 | if (last_read_token == ARITH_FOR_EXPRS && tokstr[0] == '{' && tokstr[1] == '\0') /* } */ |
28ef6c31 JA |
5104 | { |
5105 | open_brace_count++; | |
5106 | return ('{'); /* } */ | |
5107 | } | |
726f6388 | 5108 | |
f73dda09 | 5109 | if (open_brace_count && reserved_word_acceptable (last_read_token) && tokstr[0] == '}' && !tokstr[1]) |
28ef6c31 JA |
5110 | { |
5111 | open_brace_count--; /* { */ | |
5112 | return ('}'); | |
5113 | } | |
ccc6cda3 | 5114 | |
28ef6c31 JA |
5115 | #if defined (COMMAND_TIMING) |
5116 | /* Handle -p after `time'. */ | |
f73dda09 | 5117 | if (last_read_token == TIME && tokstr[0] == '-' && tokstr[1] == 'p' && !tokstr[2]) |
28ef6c31 | 5118 | return (TIMEOPT); |
495aee44 CR |
5119 | /* Handle -- after `time -p'. */ |
5120 | if (last_read_token == TIMEOPT && tokstr[0] == '-' && tokstr[1] == '-' && !tokstr[2]) | |
5121 | return (TIMEIGN); | |
b80f6443 | 5122 | #endif |
28ef6c31 JA |
5123 | |
5124 | #if defined (COND_COMMAND) /* [[ */ | |
f73dda09 | 5125 | if ((parser_state & PST_CONDEXPR) && tokstr[0] == ']' && tokstr[1] == ']' && tokstr[2] == '\0') |
28ef6c31 | 5126 | return (COND_END); |
cce855bc | 5127 | #endif |
ccc6cda3 | 5128 | |
28ef6c31 | 5129 | return (-1); |
726f6388 JA |
5130 | } |
5131 | ||
28ef6c31 JA |
5132 | /* Called from shell.c when Control-C is typed at top level. Or |
5133 | by the error rule at top level. */ | |
5134 | void | |
5135 | reset_parser () | |
726f6388 | 5136 | { |
28ef6c31 JA |
5137 | dstack.delimiter_depth = 0; /* No delimiters found so far. */ |
5138 | open_brace_count = 0; | |
726f6388 | 5139 | |
0001803f CR |
5140 | #if defined (EXTENDED_GLOB) |
5141 | /* Reset to global value of extended glob */ | |
5142 | if (parser_state & PST_EXTPAT) | |
5143 | extended_glob = global_extglob; | |
5144 | #endif | |
5145 | ||
28ef6c31 | 5146 | parser_state = 0; |
726f6388 | 5147 | |
28ef6c31 JA |
5148 | #if defined (ALIAS) || defined (DPAREN_ARITHMETIC) |
5149 | if (pushed_string_list) | |
5150 | free_string_list (); | |
cce855bc | 5151 | #endif /* ALIAS || DPAREN_ARITHMETIC */ |
ccc6cda3 | 5152 | |
28ef6c31 | 5153 | if (shell_input_line) |
726f6388 | 5154 | { |
28ef6c31 JA |
5155 | free (shell_input_line); |
5156 | shell_input_line = (char *)NULL; | |
5157 | shell_input_line_size = shell_input_line_index = 0; | |
5158 | } | |
726f6388 | 5159 | |
28ef6c31 JA |
5160 | FREE (word_desc_to_read); |
5161 | word_desc_to_read = (WORD_DESC *)NULL; | |
726f6388 | 5162 | |
0001803f | 5163 | current_token = '\n'; /* XXX */ |
28ef6c31 JA |
5164 | last_read_token = '\n'; |
5165 | token_to_read = '\n'; | |
5166 | } | |
726f6388 | 5167 | |
28ef6c31 JA |
5168 | /* Read the next token. Command can be READ (normal operation) or |
5169 | RESET (to normalize state). */ | |
5170 | static int | |
5171 | read_token (command) | |
5172 | int command; | |
5173 | { | |
5174 | int character; /* Current character. */ | |
5175 | int peek_char; /* Temporary look-ahead character. */ | |
5176 | int result; /* The thing to return. */ | |
726f6388 | 5177 | |
28ef6c31 JA |
5178 | if (command == RESET) |
5179 | { | |
5180 | reset_parser (); | |
5181 | return ('\n'); | |
5182 | } | |
726f6388 | 5183 | |
28ef6c31 JA |
5184 | if (token_to_read) |
5185 | { | |
5186 | result = token_to_read; | |
5187 | if (token_to_read == WORD || token_to_read == ASSIGNMENT_WORD) | |
726f6388 | 5188 | { |
28ef6c31 JA |
5189 | yylval.word = word_desc_to_read; |
5190 | word_desc_to_read = (WORD_DESC *)NULL; | |
726f6388 | 5191 | } |
28ef6c31 JA |
5192 | token_to_read = 0; |
5193 | return (result); | |
5194 | } | |
726f6388 | 5195 | |
28ef6c31 JA |
5196 | #if defined (COND_COMMAND) |
5197 | if ((parser_state & (PST_CONDCMD|PST_CONDEXPR)) == PST_CONDCMD) | |
5198 | { | |
5199 | cond_lineno = line_number; | |
5200 | parser_state |= PST_CONDEXPR; | |
5201 | yylval.command = parse_cond_command (); | |
5202 | if (cond_token != COND_END) | |
726f6388 | 5203 | { |
7117c2d2 | 5204 | cond_error (); |
28ef6c31 | 5205 | return (-1); |
726f6388 | 5206 | } |
28ef6c31 JA |
5207 | token_to_read = COND_END; |
5208 | parser_state &= ~(PST_CONDEXPR|PST_CONDCMD); | |
5209 | return (COND_CMD); | |
726f6388 | 5210 | } |
cce855bc | 5211 | #endif |
726f6388 | 5212 | |
28ef6c31 JA |
5213 | #if defined (ALIAS) |
5214 | /* This is a place to jump back to once we have successfully expanded a | |
5215 | token with an alias and pushed the string with push_string () */ | |
5216 | re_read_token: | |
5217 | #endif /* ALIAS */ | |
ccc6cda3 | 5218 | |
28ef6c31 | 5219 | /* Read a single word from input. Start by skipping blanks. */ |
0628567a | 5220 | while ((character = shell_getc (1)) != EOF && shellblank (character)) |
28ef6c31 | 5221 | ; |
ccc6cda3 | 5222 | |
28ef6c31 JA |
5223 | if (character == EOF) |
5224 | { | |
5225 | EOF_Reached = 1; | |
5226 | return (yacc_EOF); | |
5227 | } | |
ccc6cda3 | 5228 | |
7117c2d2 | 5229 | if MBTEST(character == '#' && (!interactive || interactive_comments)) |
28ef6c31 JA |
5230 | { |
5231 | /* A comment. Discard until EOL or EOF, and then return a newline. */ | |
5232 | discard_until ('\n'); | |
5233 | shell_getc (0); | |
5234 | character = '\n'; /* this will take the next if statement and return. */ | |
5235 | } | |
ccc6cda3 | 5236 | |
28ef6c31 JA |
5237 | if (character == '\n') |
5238 | { | |
5239 | /* If we're about to return an unquoted newline, we can go and collect | |
5240 | the text of any pending here document. */ | |
5241 | if (need_here_doc) | |
5242 | gather_here_documents (); | |
ccc6cda3 | 5243 | |
28ef6c31 JA |
5244 | #if defined (ALIAS) |
5245 | parser_state &= ~PST_ALEXPNEXT; | |
5246 | #endif /* ALIAS */ | |
ccc6cda3 | 5247 | |
95732b49 JA |
5248 | parser_state &= ~PST_ASSIGNOK; |
5249 | ||
28ef6c31 JA |
5250 | return (character); |
5251 | } | |
726f6388 | 5252 | |
3185942a JA |
5253 | if (parser_state & PST_REGEXP) |
5254 | goto tokword; | |
5255 | ||
28ef6c31 | 5256 | /* Shell meta-characters. */ |
7117c2d2 | 5257 | if MBTEST(shellmeta (character) && ((parser_state & PST_DBLPAREN) == 0)) |
28ef6c31 JA |
5258 | { |
5259 | #if defined (ALIAS) | |
5260 | /* Turn off alias tokenization iff this character sequence would | |
5261 | not leave us ready to read a command. */ | |
5262 | if (character == '<' || character == '>') | |
5263 | parser_state &= ~PST_ALEXPNEXT; | |
5264 | #endif /* ALIAS */ | |
726f6388 | 5265 | |
95732b49 JA |
5266 | parser_state &= ~PST_ASSIGNOK; |
5267 | ||
28ef6c31 JA |
5268 | peek_char = shell_getc (1); |
5269 | if (character == peek_char) | |
5270 | { | |
5271 | switch (character) | |
5272 | { | |
5273 | case '<': | |
5274 | /* If '<' then we could be at "<<" or at "<<-". We have to | |
5275 | look ahead one more character. */ | |
5276 | peek_char = shell_getc (1); | |
3185942a | 5277 | if MBTEST(peek_char == '-') |
28ef6c31 | 5278 | return (LESS_LESS_MINUS); |
3185942a | 5279 | else if MBTEST(peek_char == '<') |
7117c2d2 | 5280 | return (LESS_LESS_LESS); |
28ef6c31 JA |
5281 | else |
5282 | { | |
5283 | shell_ungetc (peek_char); | |
5284 | return (LESS_LESS); | |
5285 | } | |
726f6388 | 5286 | |
28ef6c31 JA |
5287 | case '>': |
5288 | return (GREATER_GREATER); | |
726f6388 | 5289 | |
28ef6c31 JA |
5290 | case ';': |
5291 | parser_state |= PST_CASEPAT; | |
5292 | #if defined (ALIAS) | |
5293 | parser_state &= ~PST_ALEXPNEXT; | |
5294 | #endif /* ALIAS */ | |
95732b49 | 5295 | |
3185942a JA |
5296 | peek_char = shell_getc (1); |
5297 | if MBTEST(peek_char == '&') | |
5298 | return (SEMI_SEMI_AND); | |
5299 | else | |
5300 | { | |
5301 | shell_ungetc (peek_char); | |
5302 | return (SEMI_SEMI); | |
5303 | } | |
726f6388 | 5304 | |
28ef6c31 JA |
5305 | case '&': |
5306 | return (AND_AND); | |
726f6388 | 5307 | |
28ef6c31 JA |
5308 | case '|': |
5309 | return (OR_OR); | |
726f6388 | 5310 | |
28ef6c31 JA |
5311 | #if defined (DPAREN_ARITHMETIC) || defined (ARITH_FOR_COMMAND) |
5312 | case '(': /* ) */ | |
7117c2d2 JA |
5313 | result = parse_dparen (character); |
5314 | if (result == -2) | |
5315 | break; | |
5316 | else | |
5317 | return result; | |
726f6388 | 5318 | #endif |
28ef6c31 JA |
5319 | } |
5320 | } | |
7117c2d2 | 5321 | else if MBTEST(character == '<' && peek_char == '&') |
28ef6c31 | 5322 | return (LESS_AND); |
7117c2d2 | 5323 | else if MBTEST(character == '>' && peek_char == '&') |
28ef6c31 | 5324 | return (GREATER_AND); |
7117c2d2 | 5325 | else if MBTEST(character == '<' && peek_char == '>') |
28ef6c31 | 5326 | return (LESS_GREATER); |
7117c2d2 | 5327 | else if MBTEST(character == '>' && peek_char == '|') |
28ef6c31 | 5328 | return (GREATER_BAR); |
3185942a JA |
5329 | else if MBTEST(character == '&' && peek_char == '>') |
5330 | { | |
5331 | peek_char = shell_getc (1); | |
5332 | if MBTEST(peek_char == '>') | |
5333 | return (AND_GREATER_GREATER); | |
5334 | else | |
5335 | { | |
5336 | shell_ungetc (peek_char); | |
5337 | return (AND_GREATER); | |
5338 | } | |
5339 | } | |
5340 | else if MBTEST(character == '|' && peek_char == '&') | |
5341 | return (BAR_AND); | |
5342 | else if MBTEST(character == ';' && peek_char == '&') | |
5343 | { | |
5344 | parser_state |= PST_CASEPAT; | |
5345 | #if defined (ALIAS) | |
5346 | parser_state &= ~PST_ALEXPNEXT; | |
5347 | #endif /* ALIAS */ | |
5348 | return (SEMI_AND); | |
5349 | } | |
726f6388 | 5350 | |
28ef6c31 | 5351 | shell_ungetc (peek_char); |
726f6388 | 5352 | |
28ef6c31 JA |
5353 | /* If we look like we are reading the start of a function |
5354 | definition, then let the reader know about it so that | |
5355 | we will do the right thing with `{'. */ | |
7117c2d2 | 5356 | if MBTEST(character == ')' && last_read_token == '(' && token_before_that == WORD) |
726f6388 | 5357 | { |
28ef6c31 JA |
5358 | parser_state |= PST_ALLOWOPNBRC; |
5359 | #if defined (ALIAS) | |
5360 | parser_state &= ~PST_ALEXPNEXT; | |
5361 | #endif /* ALIAS */ | |
5362 | function_dstart = line_number; | |
5363 | } | |
726f6388 | 5364 | |
28ef6c31 JA |
5365 | /* case pattern lists may be preceded by an optional left paren. If |
5366 | we're not trying to parse a case pattern list, the left paren | |
5367 | indicates a subshell. */ | |
7117c2d2 | 5368 | if MBTEST(character == '(' && (parser_state & PST_CASEPAT) == 0) /* ) */ |
28ef6c31 JA |
5369 | parser_state |= PST_SUBSHELL; |
5370 | /*(*/ | |
7117c2d2 | 5371 | else if MBTEST((parser_state & PST_CASEPAT) && character == ')') |
28ef6c31 JA |
5372 | parser_state &= ~PST_CASEPAT; |
5373 | /*(*/ | |
7117c2d2 | 5374 | else if MBTEST((parser_state & PST_SUBSHELL) && character == ')') |
28ef6c31 | 5375 | parser_state &= ~PST_SUBSHELL; |
726f6388 | 5376 | |
28ef6c31 JA |
5377 | #if defined (PROCESS_SUBSTITUTION) |
5378 | /* Check for the constructs which introduce process substitution. | |
5379 | Shells running in `posix mode' don't do process substitution. */ | |
7117c2d2 | 5380 | if MBTEST(posixly_correct || ((character != '>' && character != '<') || peek_char != '(')) /*)*/ |
28ef6c31 JA |
5381 | #endif /* PROCESS_SUBSTITUTION */ |
5382 | return (character); | |
5383 | } | |
726f6388 | 5384 | |
3185942a JA |
5385 | /* Hack <&- (close stdin) case. Also <&N- (dup and close). */ |
5386 | if MBTEST(character == '-' && (last_read_token == LESS_AND || last_read_token == GREATER_AND)) | |
5387 | return (character); | |
5388 | ||
5389 | tokword: | |
5390 | /* Okay, if we got this far, we have to read a word. Read one, | |
5391 | and then check it against the known ones. */ | |
5392 | result = read_token_word (character); | |
5393 | #if defined (ALIAS) | |
5394 | if (result == RE_READ_TOKEN) | |
5395 | goto re_read_token; | |
5396 | #endif | |
5397 | return result; | |
5398 | } | |
5399 | ||
5400 | /* | |
5401 | * Match a $(...) or other grouping construct. This has to handle embedded | |
5402 | * quoted strings ('', ``, "") and nested constructs. It also must handle | |
5403 | * reprompting the user, if necessary, after reading a newline, and returning | |
5404 | * correct error values if it reads EOF. | |
5405 | */ | |
495aee44 CR |
5406 | #define P_FIRSTCLOSE 0x0001 |
5407 | #define P_ALLOWESC 0x0002 | |
5408 | #define P_DQUOTE 0x0004 | |
5409 | #define P_COMMAND 0x0008 /* parsing a command, so look for comments */ | |
5410 | #define P_BACKQUOTE 0x0010 /* parsing a backquoted command substitution */ | |
5411 | #define P_ARRAYSUB 0x0020 /* parsing a [...] array subscript for assignment */ | |
5412 | #define P_DOLBRACE 0x0040 /* parsing a ${...} construct */ | |
3185942a JA |
5413 | |
5414 | /* Lexical state while parsing a grouping construct or $(...). */ | |
5415 | #define LEX_WASDOL 0x001 | |
5416 | #define LEX_CKCOMMENT 0x002 | |
5417 | #define LEX_INCOMMENT 0x004 | |
5418 | #define LEX_PASSNEXT 0x008 | |
5419 | #define LEX_RESWDOK 0x010 | |
5420 | #define LEX_CKCASE 0x020 | |
5421 | #define LEX_INCASE 0x040 | |
5422 | #define LEX_INHEREDOC 0x080 | |
5423 | #define LEX_HEREDELIM 0x100 /* reading here-doc delimiter */ | |
5424 | #define LEX_STRIPDOC 0x200 /* <<- strip tabs from here doc delim */ | |
0001803f | 5425 | #define LEX_INWORD 0x400 |
3185942a JA |
5426 | |
5427 | #define COMSUB_META(ch) ((ch) == ';' || (ch) == '&' || (ch) == '|') | |
5428 | ||
5429 | #define CHECK_NESTRET_ERROR() \ | |
5430 | do { \ | |
5431 | if (nestret == &matched_pair_error) \ | |
5432 | { \ | |
5433 | free (ret); \ | |
5434 | return &matched_pair_error; \ | |
5435 | } \ | |
5436 | } while (0) | |
5437 | ||
5438 | #define APPEND_NESTRET() \ | |
5439 | do { \ | |
5440 | if (nestlen) \ | |
5441 | { \ | |
5442 | RESIZE_MALLOCED_BUFFER (ret, retind, nestlen, retsize, 64); \ | |
5443 | strcpy (ret + retind, nestret); \ | |
5444 | retind += nestlen; \ | |
5445 | } \ | |
5446 | } while (0) | |
5447 | ||
5448 | static char matched_pair_error; | |
5449 | ||
5450 | static char * | |
5451 | parse_matched_pair (qc, open, close, lenp, flags) | |
5452 | int qc; /* `"' if this construct is within double quotes */ | |
5453 | int open, close; | |
5454 | int *lenp, flags; | |
5455 | { | |
5456 | int count, ch, tflags; | |
5457 | int nestlen, ttranslen, start_lineno; | |
5458 | char *ret, *nestret, *ttrans; | |
5459 | int retind, retsize, rflags; | |
495aee44 CR |
5460 | int dolbrace_state; |
5461 | ||
5462 | dolbrace_state = (flags & P_DOLBRACE) ? DOLBRACE_PARAM : 0; | |
3185942a | 5463 | |
0001803f | 5464 | /*itrace("parse_matched_pair[%d]: open = %c close = %c flags = %d", line_number, open, close, flags);*/ |
3185942a JA |
5465 | count = 1; |
5466 | tflags = 0; | |
5467 | ||
5468 | if ((flags & P_COMMAND) && qc != '`' && qc != '\'' && qc != '"' && (flags & P_DQUOTE) == 0) | |
5469 | tflags |= LEX_CKCOMMENT; | |
5470 | ||
5471 | /* RFLAGS is the set of flags we want to pass to recursive calls. */ | |
5472 | rflags = (qc == '"') ? P_DQUOTE : (flags & P_DQUOTE); | |
5473 | ||
5474 | ret = (char *)xmalloc (retsize = 64); | |
5475 | retind = 0; | |
5476 | ||
5477 | start_lineno = line_number; | |
5478 | while (count) | |
5479 | { | |
495aee44 | 5480 | ch = shell_getc (qc != '\'' && (tflags & (LEX_PASSNEXT)) == 0); |
3185942a JA |
5481 | |
5482 | if (ch == EOF) | |
5483 | { | |
5484 | free (ret); | |
5485 | parser_error (start_lineno, _("unexpected EOF while looking for matching `%c'"), close); | |
5486 | EOF_Reached = 1; /* XXX */ | |
5487 | return (&matched_pair_error); | |
5488 | } | |
5489 | ||
5490 | /* Possible reprompting. */ | |
5491 | if (ch == '\n' && SHOULD_PROMPT ()) | |
5492 | prompt_again (); | |
5493 | ||
5494 | /* Don't bother counting parens or doing anything else if in a comment | |
5495 | or part of a case statement */ | |
5496 | if (tflags & LEX_INCOMMENT) | |
5497 | { | |
5498 | /* Add this character. */ | |
5499 | RESIZE_MALLOCED_BUFFER (ret, retind, 1, retsize, 64); | |
5500 | ret[retind++] = ch; | |
5501 | ||
5502 | if (ch == '\n') | |
5503 | tflags &= ~LEX_INCOMMENT; | |
5504 | ||
5505 | continue; | |
5506 | } | |
5507 | ||
5508 | /* Not exactly right yet, should handle shell metacharacters, too. If | |
5509 | any changes are made to this test, make analogous changes to subst.c: | |
5510 | extract_delimited_string(). */ | |
5511 | else if MBTEST((tflags & LEX_CKCOMMENT) && (tflags & LEX_INCOMMENT) == 0 && ch == '#' && (retind == 0 || ret[retind-1] == '\n' || shellblank (ret[retind - 1]))) | |
5512 | tflags |= LEX_INCOMMENT; | |
5513 | ||
5514 | if (tflags & LEX_PASSNEXT) /* last char was backslash */ | |
5515 | { | |
5516 | tflags &= ~LEX_PASSNEXT; | |
5517 | if (qc != '\'' && ch == '\n') /* double-quoted \<newline> disappears. */ | |
5518 | { | |
5519 | if (retind > 0) | |
5520 | retind--; /* swallow previously-added backslash */ | |
5521 | continue; | |
5522 | } | |
5523 | ||
5524 | RESIZE_MALLOCED_BUFFER (ret, retind, 2, retsize, 64); | |
5525 | if MBTEST(ch == CTLESC || ch == CTLNUL) | |
5526 | ret[retind++] = CTLESC; | |
5527 | ret[retind++] = ch; | |
5528 | continue; | |
5529 | } | |
5530 | /* If we're reparsing the input (e.g., from parse_string_to_word_list), | |
5531 | we've already prepended CTLESC to single-quoted results of $'...'. | |
5532 | We may want to do this for other CTLESC-quoted characters in | |
5533 | reparse, too. */ | |
5534 | else if MBTEST((parser_state & PST_REPARSE) && open == '\'' && (ch == CTLESC || ch == CTLNUL)) | |
5535 | { | |
5536 | RESIZE_MALLOCED_BUFFER (ret, retind, 1, retsize, 64); | |
5537 | ret[retind++] = ch; | |
5538 | continue; | |
5539 | } | |
5540 | else if MBTEST(ch == CTLESC || ch == CTLNUL) /* special shell escapes */ | |
5541 | { | |
5542 | RESIZE_MALLOCED_BUFFER (ret, retind, 2, retsize, 64); | |
5543 | ret[retind++] = CTLESC; | |
5544 | ret[retind++] = ch; | |
5545 | continue; | |
5546 | } | |
5547 | else if MBTEST(ch == close) /* ending delimiter */ | |
5548 | count--; | |
5549 | /* handle nested ${...} specially. */ | |
5550 | else if MBTEST(open != close && (tflags & LEX_WASDOL) && open == '{' && ch == open) /* } */ | |
5551 | count++; | |
5552 | else if MBTEST(((flags & P_FIRSTCLOSE) == 0) && ch == open) /* nested begin */ | |
5553 | count++; | |
5554 | ||
5555 | /* Add this character. */ | |
5556 | RESIZE_MALLOCED_BUFFER (ret, retind, 1, retsize, 64); | |
5557 | ret[retind++] = ch; | |
5558 | ||
5559 | /* If we just read the ending character, don't bother continuing. */ | |
5560 | if (count == 0) | |
5561 | break; | |
5562 | ||
5563 | if (open == '\'') /* '' inside grouping construct */ | |
5564 | { | |
5565 | if MBTEST((flags & P_ALLOWESC) && ch == '\\') | |
5566 | tflags |= LEX_PASSNEXT; | |
5567 | continue; | |
5568 | } | |
5569 | ||
5570 | if MBTEST(ch == '\\') /* backslashes */ | |
5571 | tflags |= LEX_PASSNEXT; | |
5572 | ||
495aee44 CR |
5573 | /* Based on which dolstate is currently in (param, op, or word), |
5574 | decide what the op is. We're really only concerned if it's % or | |
5575 | #, so we can turn on a flag that says whether or not we should | |
5576 | treat single quotes as special when inside a double-quoted | |
5577 | ${...}. This logic must agree with subst.c:extract_dollar_brace_string | |
5578 | since they share the same defines. */ | |
5579 | if (flags & P_DOLBRACE) | |
5580 | { | |
5581 | /* ${param%[%]word} */ | |
5582 | if MBTEST(dolbrace_state == DOLBRACE_PARAM && ch == '%' && retind > 1) | |
5583 | dolbrace_state = DOLBRACE_QUOTE; | |
5584 | /* ${param#[#]word} */ | |
5585 | else if MBTEST(dolbrace_state == DOLBRACE_PARAM && ch == '#' && retind > 1) | |
5586 | dolbrace_state = DOLBRACE_QUOTE; | |
5587 | /* ${param/[/]pat/rep} */ | |
5588 | else if MBTEST(dolbrace_state == DOLBRACE_PARAM && ch == '/' && retind > 1) | |
5589 | dolbrace_state = DOLBRACE_QUOTE; | |
5590 | /* ${param^[^]pat} */ | |
5591 | else if MBTEST(dolbrace_state == DOLBRACE_PARAM && ch == '^' && retind > 1) | |
5592 | dolbrace_state = DOLBRACE_QUOTE; | |
5593 | /* ${param,[,]pat} */ | |
5594 | else if MBTEST(dolbrace_state == DOLBRACE_PARAM && ch == ',' && retind > 1) | |
5595 | dolbrace_state = DOLBRACE_QUOTE; | |
5596 | else if MBTEST(dolbrace_state == DOLBRACE_PARAM && strchr ("#%^,~:-=?+/", ch) != 0) | |
5597 | dolbrace_state = DOLBRACE_OP; | |
5598 | else if MBTEST(dolbrace_state == DOLBRACE_OP && strchr ("#%^,~:-=?+/", ch) == 0) | |
5599 | dolbrace_state = DOLBRACE_WORD; | |
5600 | } | |
5601 | ||
3185942a | 5602 | /* The big hammer. Single quotes aren't special in double quotes. The |
495aee44 | 5603 | problem is that Posix used to say the single quotes are semi-special: |
3185942a JA |
5604 | within a double-quoted ${...} construct "an even number of |
5605 | unescaped double-quotes or single-quotes, if any, shall occur." */ | |
495aee44 CR |
5606 | /* This was changed in Austin Group Interp 221 */ |
5607 | if MBTEST(posixly_correct && shell_compatibility_level > 41 && dolbrace_state != DOLBRACE_QUOTE && (flags & P_DQUOTE) && (flags & P_DOLBRACE) && ch == '\'') | |
3185942a | 5608 | continue; |
3185942a JA |
5609 | |
5610 | /* Could also check open == '`' if we want to parse grouping constructs | |
5611 | inside old-style command substitution. */ | |
5612 | if (open != close) /* a grouping construct */ | |
5613 | { | |
5614 | if MBTEST(shellquote (ch)) | |
5615 | { | |
5616 | /* '', ``, or "" inside $(...) or other grouping construct. */ | |
5617 | push_delimiter (dstack, ch); | |
5618 | if MBTEST((tflags & LEX_WASDOL) && ch == '\'') /* $'...' inside group */ | |
5619 | nestret = parse_matched_pair (ch, ch, ch, &nestlen, P_ALLOWESC|rflags); | |
5620 | else | |
5621 | nestret = parse_matched_pair (ch, ch, ch, &nestlen, rflags); | |
5622 | pop_delimiter (dstack); | |
5623 | CHECK_NESTRET_ERROR (); | |
5624 | ||
5625 | if MBTEST((tflags & LEX_WASDOL) && ch == '\'' && (extended_quote || (rflags & P_DQUOTE) == 0)) | |
5626 | { | |
5627 | /* Translate $'...' here. */ | |
5628 | ttrans = ansiexpand (nestret, 0, nestlen - 1, &ttranslen); | |
5629 | xfree (nestret); | |
5630 | ||
5631 | if ((rflags & P_DQUOTE) == 0) | |
5632 | { | |
5633 | nestret = sh_single_quote (ttrans); | |
5634 | free (ttrans); | |
5635 | nestlen = strlen (nestret); | |
5636 | } | |
5637 | else | |
5638 | { | |
5639 | nestret = ttrans; | |
5640 | nestlen = ttranslen; | |
5641 | } | |
5642 | retind -= 2; /* back up before the $' */ | |
5643 | } | |
5644 | else if MBTEST((tflags & LEX_WASDOL) && ch == '"' && (extended_quote || (rflags & P_DQUOTE) == 0)) | |
5645 | { | |
5646 | /* Locale expand $"..." here. */ | |
5647 | ttrans = localeexpand (nestret, 0, nestlen - 1, start_lineno, &ttranslen); | |
5648 | xfree (nestret); | |
5649 | ||
5650 | nestret = sh_mkdoublequoted (ttrans, ttranslen, 0); | |
5651 | free (ttrans); | |
5652 | nestlen = ttranslen + 2; | |
5653 | retind -= 2; /* back up before the $" */ | |
5654 | } | |
5655 | ||
5656 | APPEND_NESTRET (); | |
5657 | FREE (nestret); | |
5658 | } | |
0001803f CR |
5659 | else if ((flags & P_ARRAYSUB) && (tflags & LEX_WASDOL) && (ch == '(' || ch == '{' || ch == '[')) /* ) } ] */ |
5660 | goto parse_dollar_word; | |
3185942a JA |
5661 | } |
5662 | /* Parse an old-style command substitution within double quotes as a | |
5663 | single word. */ | |
5664 | /* XXX - sh and ksh93 don't do this - XXX */ | |
5665 | else if MBTEST(open == '"' && ch == '`') | |
5666 | { | |
5667 | nestret = parse_matched_pair (0, '`', '`', &nestlen, rflags); | |
5668 | ||
5669 | CHECK_NESTRET_ERROR (); | |
5670 | APPEND_NESTRET (); | |
5671 | ||
5672 | FREE (nestret); | |
5673 | } | |
5674 | else if MBTEST(open != '`' && (tflags & LEX_WASDOL) && (ch == '(' || ch == '{' || ch == '[')) /* ) } ] */ | |
5675 | /* check for $(), $[], or ${} inside quoted string. */ | |
5676 | { | |
0001803f | 5677 | parse_dollar_word: |
3185942a JA |
5678 | if (open == ch) /* undo previous increment */ |
5679 | count--; | |
5680 | if (ch == '(') /* ) */ | |
5681 | nestret = parse_comsub (0, '(', ')', &nestlen, (rflags|P_COMMAND) & ~P_DQUOTE); | |
5682 | else if (ch == '{') /* } */ | |
495aee44 | 5683 | nestret = parse_matched_pair (0, '{', '}', &nestlen, P_FIRSTCLOSE|P_DOLBRACE|rflags); |
3185942a JA |
5684 | else if (ch == '[') /* ] */ |
5685 | nestret = parse_matched_pair (0, '[', ']', &nestlen, rflags); | |
5686 | ||
5687 | CHECK_NESTRET_ERROR (); | |
5688 | APPEND_NESTRET (); | |
726f6388 | 5689 | |
3185942a JA |
5690 | FREE (nestret); |
5691 | } | |
5692 | if MBTEST(ch == '$') | |
5693 | tflags |= LEX_WASDOL; | |
5694 | else | |
5695 | tflags &= ~LEX_WASDOL; | |
5696 | } | |
726f6388 | 5697 | |
3185942a JA |
5698 | ret[retind] = '\0'; |
5699 | if (lenp) | |
5700 | *lenp = retind; | |
0001803f | 5701 | /*itrace("parse_matched_pair[%d]: returning %s", line_number, ret);*/ |
3185942a JA |
5702 | return ret; |
5703 | } | |
726f6388 | 5704 | |
3185942a JA |
5705 | /* Parse a $(...) command substitution. This is messier than I'd like, and |
5706 | reproduces a lot more of the token-reading code than I'd like. */ | |
28ef6c31 | 5707 | static char * |
3185942a | 5708 | parse_comsub (qc, open, close, lenp, flags) |
28ef6c31 JA |
5709 | int qc; /* `"' if this construct is within double quotes */ |
5710 | int open, close; | |
5711 | int *lenp, flags; | |
5712 | { | |
0001803f | 5713 | int count, ch, peekc, tflags, lex_rwlen, lex_wlen, lex_firstind; |
3185942a JA |
5714 | int nestlen, ttranslen, start_lineno; |
5715 | char *ret, *nestret, *ttrans, *heredelim; | |
5716 | int retind, retsize, rflags, hdlen; | |
ccc6cda3 | 5717 | |
495aee44 CR |
5718 | /* Posix interp 217 says arithmetic expressions have precedence, so |
5719 | assume $(( introduces arithmetic expansion and parse accordingly. */ | |
5720 | peekc = shell_getc (0); | |
5721 | shell_ungetc (peekc); | |
5722 | if (peekc == '(') | |
5723 | return (parse_matched_pair (qc, open, close, lenp, 0)); | |
5724 | ||
3185942a | 5725 | /*itrace("parse_comsub: qc = `%c' open = %c close = %c", qc, open, close);*/ |
28ef6c31 | 5726 | count = 1; |
3185942a JA |
5727 | tflags = LEX_RESWDOK; |
5728 | ||
5729 | if ((flags & P_COMMAND) && qc != '\'' && qc != '"' && (flags & P_DQUOTE) == 0) | |
5730 | tflags |= LEX_CKCASE; | |
5731 | if ((tflags & LEX_CKCASE) && (interactive == 0 || interactive_comments)) | |
5732 | tflags |= LEX_CKCOMMENT; | |
d166f048 | 5733 | |
b80f6443 | 5734 | /* RFLAGS is the set of flags we want to pass to recursive calls. */ |
3185942a | 5735 | rflags = (flags & P_DQUOTE); |
b80f6443 | 5736 | |
f73dda09 | 5737 | ret = (char *)xmalloc (retsize = 64); |
28ef6c31 JA |
5738 | retind = 0; |
5739 | ||
5740 | start_lineno = line_number; | |
0001803f | 5741 | lex_rwlen = lex_wlen = 0; |
3185942a JA |
5742 | |
5743 | heredelim = 0; | |
5744 | lex_firstind = -1; | |
5745 | ||
28ef6c31 JA |
5746 | while (count) |
5747 | { | |
3185942a | 5748 | comsub_readchar: |
495aee44 | 5749 | ch = shell_getc (qc != '\'' && (tflags & (LEX_INCOMMENT|LEX_PASSNEXT)) == 0); |
0628567a | 5750 | |
28ef6c31 | 5751 | if (ch == EOF) |
ccc6cda3 | 5752 | { |
3185942a | 5753 | eof_error: |
28ef6c31 | 5754 | free (ret); |
3185942a | 5755 | FREE (heredelim); |
b80f6443 | 5756 | parser_error (start_lineno, _("unexpected EOF while looking for matching `%c'"), close); |
28ef6c31 JA |
5757 | EOF_Reached = 1; /* XXX */ |
5758 | return (&matched_pair_error); | |
ccc6cda3 JA |
5759 | } |
5760 | ||
3185942a JA |
5761 | /* If we hit the end of a line and are reading the contents of a here |
5762 | document, and it's not the same line that the document starts on, | |
5763 | check for this line being the here doc delimiter. Otherwise, if | |
5764 | we're in a here document, mark the next character as the beginning | |
5765 | of a line. */ | |
5766 | if (ch == '\n') | |
5767 | { | |
5768 | if ((tflags & LEX_HEREDELIM) && heredelim) | |
5769 | { | |
5770 | tflags &= ~LEX_HEREDELIM; | |
5771 | tflags |= LEX_INHEREDOC; | |
5772 | lex_firstind = retind + 1; | |
5773 | } | |
5774 | else if (tflags & LEX_INHEREDOC) | |
5775 | { | |
5776 | int tind; | |
5777 | tind = lex_firstind; | |
5778 | while ((tflags & LEX_STRIPDOC) && ret[tind] == '\t') | |
5779 | tind++; | |
5780 | if (STREQN (ret + tind, heredelim, hdlen)) | |
5781 | { | |
5782 | tflags &= ~(LEX_STRIPDOC|LEX_INHEREDOC); | |
5783 | /*itrace("parse_comsub:%d: found here doc end `%s'", line_number, ret + tind);*/ | |
0001803f CR |
5784 | free (heredelim); |
5785 | heredelim = 0; | |
3185942a JA |
5786 | lex_firstind = -1; |
5787 | } | |
5788 | else | |
5789 | lex_firstind = retind + 1; | |
5790 | } | |
5791 | } | |
5792 | ||
28ef6c31 | 5793 | /* Possible reprompting. */ |
b80f6443 | 5794 | if (ch == '\n' && SHOULD_PROMPT ()) |
28ef6c31 | 5795 | prompt_again (); |
726f6388 | 5796 | |
0001803f CR |
5797 | /* XXX -- possibly allow here doc to be delimited by ending right |
5798 | paren. */ | |
5799 | if ((tflags & LEX_INHEREDOC) && ch == close && count == 1) | |
5800 | { | |
5801 | int tind; | |
5802 | /*itrace("parse_comsub: in here doc, ch == close, retind - firstind = %d hdlen = %d retind = %d", retind-lex_firstind, hdlen, retind);*/ | |
5803 | tind = lex_firstind; | |
5804 | while ((tflags & LEX_STRIPDOC) && ret[tind] == '\t') | |
5805 | tind++; | |
5806 | if (retind-tind == hdlen && STREQN (ret + tind, heredelim, hdlen)) | |
5807 | { | |
5808 | tflags &= ~(LEX_STRIPDOC|LEX_INHEREDOC); | |
5809 | /*itrace("parse_comsub:%d: found here doc end `%s'", line_number, ret + tind);*/ | |
5810 | free (heredelim); | |
5811 | heredelim = 0; | |
5812 | lex_firstind = -1; | |
5813 | } | |
5814 | } | |
5815 | ||
3185942a JA |
5816 | /* Don't bother counting parens or doing anything else if in a comment */ |
5817 | if (tflags & (LEX_INCOMMENT|LEX_INHEREDOC)) | |
95732b49 JA |
5818 | { |
5819 | /* Add this character. */ | |
5820 | RESIZE_MALLOCED_BUFFER (ret, retind, 1, retsize, 64); | |
5821 | ret[retind++] = ch; | |
5822 | ||
3185942a | 5823 | if ((tflags & LEX_INCOMMENT) && ch == '\n') |
0001803f CR |
5824 | { |
5825 | /*itrace("parse_comsub:%d: lex_incomment -> 0 ch = `%c'", line_number, ch);*/ | |
3185942a | 5826 | tflags &= ~LEX_INCOMMENT; |
0001803f | 5827 | } |
95732b49 JA |
5828 | |
5829 | continue; | |
5830 | } | |
95732b49 | 5831 | |
0001803f CR |
5832 | if (tflags & LEX_PASSNEXT) /* last char was backslash */ |
5833 | { | |
5834 | /*itrace("parse_comsub:%d: lex_passnext -> 0 ch = `%c' (%d)", line_number, ch, __LINE__);*/ | |
5835 | tflags &= ~LEX_PASSNEXT; | |
5836 | if (qc != '\'' && ch == '\n') /* double-quoted \<newline> disappears. */ | |
5837 | { | |
5838 | if (retind > 0) | |
5839 | retind--; /* swallow previously-added backslash */ | |
5840 | continue; | |
5841 | } | |
5842 | ||
5843 | RESIZE_MALLOCED_BUFFER (ret, retind, 2, retsize, 64); | |
5844 | if MBTEST(ch == CTLESC || ch == CTLNUL) | |
5845 | ret[retind++] = CTLESC; | |
5846 | ret[retind++] = ch; | |
5847 | continue; | |
5848 | } | |
5849 | ||
5850 | /* If this is a shell break character, we are not in a word. If not, | |
5851 | we either start or continue a word. */ | |
5852 | if MBTEST(shellbreak (ch)) | |
5853 | { | |
5854 | tflags &= ~LEX_INWORD; | |
5855 | /*itrace("parse_comsub:%d: lex_inword -> 0 ch = `%c' (%d)", line_number, ch, __LINE__);*/ | |
5856 | } | |
5857 | else | |
5858 | { | |
5859 | if (tflags & LEX_INWORD) | |
5860 | { | |
5861 | lex_wlen++; | |
5862 | /*itrace("parse_comsub:%d: lex_inword == 1 ch = `%c' lex_wlen = %d (%d)", line_number, ch, lex_wlen, __LINE__);*/ | |
5863 | } | |
5864 | else | |
5865 | { | |
5866 | /*itrace("parse_comsub:%d: lex_inword -> 1 ch = `%c' (%d)", line_number, ch, __LINE__);*/ | |
5867 | tflags |= LEX_INWORD; | |
5868 | lex_wlen = 0; | |
5869 | } | |
5870 | } | |
5871 | ||
3185942a | 5872 | /* Skip whitespace */ |
495aee44 | 5873 | if MBTEST(shellblank (ch) && (tflags & LEX_HEREDELIM) == 0 && lex_rwlen == 0) |
3185942a JA |
5874 | { |
5875 | /* Add this character. */ | |
5876 | RESIZE_MALLOCED_BUFFER (ret, retind, 1, retsize, 64); | |
5877 | ret[retind++] = ch; | |
5878 | continue; | |
5879 | } | |
5880 | ||
5881 | /* Either we are looking for the start of the here-doc delimiter | |
5882 | (lex_firstind == -1) or we are reading one (lex_firstind >= 0). | |
5883 | If this character is a shell break character and we are reading | |
5884 | the delimiter, save it and note that we are now reading a here | |
5885 | document. If we've found the start of the delimiter, note it by | |
5886 | setting lex_firstind. Backslashes can quote shell metacharacters | |
5887 | in here-doc delimiters. */ | |
5888 | if (tflags & LEX_HEREDELIM) | |
0628567a | 5889 | { |
3185942a JA |
5890 | if (lex_firstind == -1 && shellbreak (ch) == 0) |
5891 | lex_firstind = retind; | |
0001803f CR |
5892 | #if 0 |
5893 | else if (heredelim && (tflags & LEX_PASSNEXT) == 0 && ch == '\n') | |
5894 | { | |
5895 | tflags |= LEX_INHEREDOC; | |
5896 | tflags &= ~LEX_HEREDELIM; | |
5897 | lex_firstind = retind + 1; | |
5898 | } | |
5899 | #endif | |
3185942a JA |
5900 | else if (lex_firstind >= 0 && (tflags & LEX_PASSNEXT) == 0 && shellbreak (ch)) |
5901 | { | |
0001803f CR |
5902 | if (heredelim == 0) |
5903 | { | |
5904 | nestret = substring (ret, lex_firstind, retind); | |
5905 | heredelim = string_quote_removal (nestret, 0); | |
5906 | free (nestret); | |
5907 | hdlen = STRLEN(heredelim); | |
3185942a | 5908 | /*itrace("parse_comsub:%d: found here doc delimiter `%s' (%d)", line_number, heredelim, hdlen);*/ |
0001803f | 5909 | } |
3185942a JA |
5910 | if (ch == '\n') |
5911 | { | |
5912 | tflags |= LEX_INHEREDOC; | |
5913 | tflags &= ~LEX_HEREDELIM; | |
5914 | lex_firstind = retind + 1; | |
5915 | } | |
5916 | else | |
5917 | lex_firstind = -1; | |
5918 | } | |
0628567a JA |
5919 | } |
5920 | ||
3185942a | 5921 | /* Meta-characters that can introduce a reserved word. Not perfect yet. */ |
0001803f | 5922 | if MBTEST((tflags & LEX_RESWDOK) == 0 && (tflags & LEX_CKCASE) && (tflags & LEX_INCOMMENT) == 0 && (shellmeta(ch) || ch == '\n')) |
726f6388 | 5923 | { |
3185942a JA |
5924 | /* Add this character. */ |
5925 | RESIZE_MALLOCED_BUFFER (ret, retind, 1, retsize, 64); | |
5926 | ret[retind++] = ch; | |
5927 | peekc = shell_getc (1); | |
5928 | if (ch == peekc && (ch == '&' || ch == '|' || ch == ';')) /* two-character tokens */ | |
5929 | { | |
5930 | RESIZE_MALLOCED_BUFFER (ret, retind, 1, retsize, 64); | |
5931 | ret[retind++] = peekc; | |
0001803f | 5932 | /*itrace("parse_comsub:%d: set lex_reswordok = 1, ch = `%c'", line_number, ch);*/ |
3185942a JA |
5933 | tflags |= LEX_RESWDOK; |
5934 | lex_rwlen = 0; | |
5935 | continue; | |
5936 | } | |
5937 | else if (ch == '\n' || COMSUB_META(ch)) | |
5938 | { | |
5939 | shell_ungetc (peekc); | |
3185942a | 5940 | /*itrace("parse_comsub:%d: set lex_reswordok = 1, ch = `%c'", line_number, ch);*/ |
0001803f | 5941 | tflags |= LEX_RESWDOK; |
3185942a JA |
5942 | lex_rwlen = 0; |
5943 | continue; | |
5944 | } | |
5945 | else if (ch == EOF) | |
5946 | goto eof_error; | |
5947 | else | |
5948 | { | |
5949 | /* `unget' the character we just added and fall through */ | |
5950 | retind--; | |
5951 | shell_ungetc (peekc); | |
5952 | } | |
5953 | } | |
5954 | ||
5955 | /* If we can read a reserved word, try to read one. */ | |
5956 | if (tflags & LEX_RESWDOK) | |
5957 | { | |
5958 | if MBTEST(islower (ch)) | |
5959 | { | |
5960 | /* Add this character. */ | |
5961 | RESIZE_MALLOCED_BUFFER (ret, retind, 1, retsize, 64); | |
5962 | ret[retind++] = ch; | |
5963 | lex_rwlen++; | |
5964 | continue; | |
5965 | } | |
5966 | else if MBTEST(lex_rwlen == 4 && shellbreak (ch)) | |
5967 | { | |
5968 | if (STREQN (ret + retind - 4, "case", 4)) | |
5969 | { | |
5970 | tflags |= LEX_INCASE; | |
0001803f | 5971 | /*itrace("parse_comsub:%d: found `case', lex_incase -> 1 lex_reswdok -> 0", line_number);*/ |
3185942a JA |
5972 | } |
5973 | else if (STREQN (ret + retind - 4, "esac", 4)) | |
5974 | { | |
5975 | tflags &= ~LEX_INCASE; | |
0001803f | 5976 | /*itrace("parse_comsub:%d: found `esac', lex_incase -> 0 lex_reswdok -> 0", line_number);*/ |
3185942a JA |
5977 | } |
5978 | tflags &= ~LEX_RESWDOK; | |
5979 | } | |
0001803f CR |
5980 | else if MBTEST((tflags & LEX_CKCOMMENT) && ch == '#' && (lex_rwlen == 0 || ((tflags & LEX_INWORD) && lex_wlen == 0))) |
5981 | ; /* don't modify LEX_RESWDOK if we're starting a comment */ | |
5982 | else if MBTEST((tflags & LEX_INCASE) && ch != '\n') | |
5983 | /* If we can read a reserved word and we're in case, we're at the | |
5984 | point where we can read a new pattern list or an esac. We | |
5985 | handle the esac case above. If we read a newline, we want to | |
5986 | leave LEX_RESWDOK alone. If we read anything else, we want to | |
5987 | turn off LEX_RESWDOK, since we're going to read a pattern list. */ | |
3185942a | 5988 | { |
0001803f CR |
5989 | tflags &= ~LEX_RESWDOK; |
5990 | /*itrace("parse_comsub:%d: lex_incase == 1 found `%c', lex_reswordok -> 0", line_number, ch);*/ | |
5991 | } | |
5992 | else if MBTEST(shellbreak (ch) == 0) | |
5993 | { | |
5994 | tflags &= ~LEX_RESWDOK; | |
3185942a JA |
5995 | /*itrace("parse_comsub:%d: found `%c', lex_reswordok -> 0", line_number, ch);*/ |
5996 | } | |
5997 | } | |
5998 | ||
0001803f | 5999 | /* Might be the start of a here-doc delimiter */ |
3185942a JA |
6000 | if MBTEST((tflags & LEX_INCOMMENT) == 0 && (tflags & LEX_CKCASE) && ch == '<') |
6001 | { | |
6002 | /* Add this character. */ | |
6003 | RESIZE_MALLOCED_BUFFER (ret, retind, 1, retsize, 64); | |
6004 | ret[retind++] = ch; | |
6005 | peekc = shell_getc (1); | |
6006 | if (peekc == EOF) | |
6007 | goto eof_error; | |
6008 | if (peekc == ch) | |
6009 | { | |
6010 | RESIZE_MALLOCED_BUFFER (ret, retind, 1, retsize, 64); | |
6011 | ret[retind++] = peekc; | |
6012 | peekc = shell_getc (1); | |
6013 | if (peekc == EOF) | |
6014 | goto eof_error; | |
6015 | if (peekc == '-') | |
6016 | { | |
6017 | RESIZE_MALLOCED_BUFFER (ret, retind, 1, retsize, 64); | |
6018 | ret[retind++] = peekc; | |
6019 | tflags |= LEX_STRIPDOC; | |
6020 | } | |
6021 | else | |
6022 | shell_ungetc (peekc); | |
0001803f CR |
6023 | if (peekc != '<') |
6024 | { | |
6025 | tflags |= LEX_HEREDELIM; | |
6026 | lex_firstind = -1; | |
6027 | } | |
3185942a JA |
6028 | continue; |
6029 | } | |
6030 | else | |
0001803f | 6031 | ch = peekc; /* fall through and continue XXX */ |
3185942a | 6032 | } |
0001803f CR |
6033 | else if MBTEST((tflags & LEX_CKCOMMENT) && (tflags & LEX_INCOMMENT) == 0 && ch == '#' && (((tflags & LEX_RESWDOK) && lex_rwlen == 0) || ((tflags & LEX_INWORD) && lex_wlen == 0))) |
6034 | { | |
6035 | /*itrace("parse_comsub:%d: lex_incomment -> 1 (%d)", line_number, __LINE__);*/ | |
3185942a | 6036 | tflags |= LEX_INCOMMENT; |
0001803f | 6037 | } |
3185942a | 6038 | |
0001803f | 6039 | if MBTEST(ch == CTLESC || ch == CTLNUL) /* special shell escapes */ |
726f6388 | 6040 | { |
28ef6c31 JA |
6041 | RESIZE_MALLOCED_BUFFER (ret, retind, 2, retsize, 64); |
6042 | ret[retind++] = CTLESC; | |
6043 | ret[retind++] = ch; | |
6044 | continue; | |
726f6388 | 6045 | } |
3185942a JA |
6046 | #if 0 |
6047 | else if MBTEST((tflags & LEX_INCASE) && ch == close && close == ')') | |
6048 | tflags &= ~LEX_INCASE; /* XXX */ | |
6049 | #endif | |
6050 | else if MBTEST(ch == close && (tflags & LEX_INCASE) == 0) /* ending delimiter */ | |
6051 | { | |
28ef6c31 | 6052 | count--; |
3185942a JA |
6053 | /*itrace("parse_comsub:%d: found close: count = %d", line_number, count);*/ |
6054 | } | |
6055 | else if MBTEST(((flags & P_FIRSTCLOSE) == 0) && (tflags & LEX_INCASE) == 0 && ch == open) /* nested begin */ | |
0001803f | 6056 | { |
28ef6c31 | 6057 | count++; |
0001803f CR |
6058 | /*itrace("parse_comsub:%d: found open: count = %d", line_number, count);*/ |
6059 | } | |
726f6388 | 6060 | |
28ef6c31 JA |
6061 | /* Add this character. */ |
6062 | RESIZE_MALLOCED_BUFFER (ret, retind, 1, retsize, 64); | |
6063 | ret[retind++] = ch; | |
6064 | ||
3185942a JA |
6065 | /* If we just read the ending character, don't bother continuing. */ |
6066 | if (count == 0) | |
6067 | break; | |
726f6388 | 6068 | |
7117c2d2 | 6069 | if MBTEST(ch == '\\') /* backslashes */ |
3185942a | 6070 | tflags |= LEX_PASSNEXT; |
28ef6c31 | 6071 | |
3185942a JA |
6072 | if MBTEST(shellquote (ch)) |
6073 | { | |
6074 | /* '', ``, or "" inside $(...). */ | |
6075 | push_delimiter (dstack, ch); | |
6076 | if MBTEST((tflags & LEX_WASDOL) && ch == '\'') /* $'...' inside group */ | |
6077 | nestret = parse_matched_pair (ch, ch, ch, &nestlen, P_ALLOWESC|rflags); | |
6078 | else | |
6079 | nestret = parse_matched_pair (ch, ch, ch, &nestlen, rflags); | |
6080 | pop_delimiter (dstack); | |
6081 | CHECK_NESTRET_ERROR (); | |
6082 | ||
6083 | if MBTEST((tflags & LEX_WASDOL) && ch == '\'' && (extended_quote || (rflags & P_DQUOTE) == 0)) | |
28ef6c31 | 6084 | { |
3185942a JA |
6085 | /* Translate $'...' here. */ |
6086 | ttrans = ansiexpand (nestret, 0, nestlen - 1, &ttranslen); | |
6087 | xfree (nestret); | |
95732b49 | 6088 | |
3185942a | 6089 | if ((rflags & P_DQUOTE) == 0) |
28ef6c31 | 6090 | { |
3185942a | 6091 | nestret = sh_single_quote (ttrans); |
28ef6c31 | 6092 | free (ttrans); |
3185942a | 6093 | nestlen = strlen (nestret); |
28ef6c31 | 6094 | } |
3185942a | 6095 | else |
28ef6c31 | 6096 | { |
3185942a JA |
6097 | nestret = ttrans; |
6098 | nestlen = ttranslen; | |
28ef6c31 | 6099 | } |
3185942a | 6100 | retind -= 2; /* back up before the $' */ |
28ef6c31 | 6101 | } |
3185942a | 6102 | else if MBTEST((tflags & LEX_WASDOL) && ch == '"' && (extended_quote || (rflags & P_DQUOTE) == 0)) |
28ef6c31 | 6103 | { |
3185942a JA |
6104 | /* Locale expand $"..." here. */ |
6105 | ttrans = localeexpand (nestret, 0, nestlen - 1, start_lineno, &ttranslen); | |
6106 | xfree (nestret); | |
6107 | ||
6108 | nestret = sh_mkdoublequoted (ttrans, ttranslen, 0); | |
6109 | free (ttrans); | |
6110 | nestlen = ttranslen + 2; | |
6111 | retind -= 2; /* back up before the $" */ | |
28ef6c31 | 6112 | } |
3185942a JA |
6113 | |
6114 | APPEND_NESTRET (); | |
28ef6c31 JA |
6115 | FREE (nestret); |
6116 | } | |
3185942a JA |
6117 | else if MBTEST((tflags & LEX_WASDOL) && (ch == '(' || ch == '{' || ch == '[')) /* ) } ] */ |
6118 | /* check for $(), $[], or ${} inside command substitution. */ | |
28ef6c31 | 6119 | { |
3185942a | 6120 | if ((tflags & LEX_INCASE) == 0 && open == ch) /* undo previous increment */ |
28ef6c31 JA |
6121 | count--; |
6122 | if (ch == '(') /* ) */ | |
3185942a | 6123 | nestret = parse_comsub (0, '(', ')', &nestlen, (rflags|P_COMMAND) & ~P_DQUOTE); |
28ef6c31 | 6124 | else if (ch == '{') /* } */ |
495aee44 | 6125 | nestret = parse_matched_pair (0, '{', '}', &nestlen, P_FIRSTCLOSE|P_DOLBRACE|rflags); |
28ef6c31 | 6126 | else if (ch == '[') /* ] */ |
b80f6443 | 6127 | nestret = parse_matched_pair (0, '[', ']', &nestlen, rflags); |
95732b49 | 6128 | |
3185942a JA |
6129 | CHECK_NESTRET_ERROR (); |
6130 | APPEND_NESTRET (); | |
6131 | ||
6132 | FREE (nestret); | |
726f6388 | 6133 | } |
3185942a JA |
6134 | if MBTEST(ch == '$') |
6135 | tflags |= LEX_WASDOL; | |
6136 | else | |
6137 | tflags &= ~LEX_WASDOL; | |
726f6388 | 6138 | } |
ccc6cda3 | 6139 | |
3185942a | 6140 | FREE (heredelim); |
28ef6c31 JA |
6141 | ret[retind] = '\0'; |
6142 | if (lenp) | |
6143 | *lenp = retind; | |
3185942a JA |
6144 | /*itrace("parse_comsub:%d: returning `%s'", line_number, ret);*/ |
6145 | return ret; | |
6146 | } | |
6147 | ||
495aee44 | 6148 | /* Recursively call the parser to parse a $(...) command substitution. */ |
3185942a JA |
6149 | char * |
6150 | xparse_dolparen (base, string, indp, flags) | |
6151 | char *base; | |
6152 | char *string; | |
6153 | int *indp; | |
6154 | int flags; | |
6155 | { | |
6156 | sh_parser_state_t ps; | |
6157 | int orig_ind, nc, sflags; | |
6158 | char *ret, *s, *ep, *ostring; | |
6159 | ||
6160 | /*yydebug = 1;*/ | |
6161 | orig_ind = *indp; | |
6162 | ostring = string; | |
6163 | ||
6164 | sflags = SEVAL_NONINT|SEVAL_NOHIST|SEVAL_NOFREE; | |
6165 | if (flags & SX_NOLONGJMP) | |
6166 | sflags |= SEVAL_NOLONGJMP; | |
6167 | save_parser_state (&ps); | |
6168 | ||
6169 | /*(*/ | |
6170 | parser_state |= PST_CMDSUBST|PST_EOFTOKEN; /* allow instant ')' */ /*(*/ | |
6171 | shell_eof_token = ')'; | |
6172 | parse_string (string, "command substitution", sflags, &ep); | |
6173 | ||
6174 | restore_parser_state (&ps); | |
6175 | reset_parser (); | |
6176 | if (interactive) | |
6177 | token_to_read = 0; | |
6178 | ||
6179 | /* Need to find how many characters parse_and_execute consumed, update | |
6180 | *indp, if flags != 0, copy the portion of the string parsed into RET | |
6181 | and return it. If flags & 1 (EX_NOALLOC) we can return NULL. */ | |
6182 | ||
6183 | /*(*/ | |
6184 | if (ep[-1] != ')') | |
6185 | { | |
6186 | #if DEBUG | |
6187 | if (ep[-1] != '\n') | |
6188 | itrace("xparse_dolparen:%d: ep[-1] != RPAREN (%d), ep = `%s'", line_number, ep[-1], ep); | |
6189 | #endif | |
6190 | while (ep > ostring && ep[-1] == '\n') ep--; | |
6191 | } | |
6192 | ||
6193 | nc = ep - ostring; | |
6194 | *indp = ep - base - 1; | |
6195 | ||
6196 | /*(*/ | |
6197 | #if DEBUG | |
6198 | if (base[*indp] != ')') | |
6199 | itrace("xparse_dolparen:%d: base[%d] != RPAREN (%d), base = `%s'", line_number, *indp, base[*indp], base); | |
6200 | #endif | |
6201 | ||
6202 | if (flags & SX_NOALLOC) | |
6203 | return (char *)NULL; | |
6204 | ||
6205 | if (nc == 0) | |
6206 | { | |
6207 | ret = xmalloc (1); | |
6208 | ret[0] = '\0'; | |
6209 | } | |
6210 | else | |
6211 | ret = substring (ostring, 0, nc - 1); | |
6212 | ||
28ef6c31 JA |
6213 | return ret; |
6214 | } | |
726f6388 | 6215 | |
28ef6c31 | 6216 | #if defined (DPAREN_ARITHMETIC) || defined (ARITH_FOR_COMMAND) |
7117c2d2 JA |
6217 | /* Parse a double-paren construct. It can be either an arithmetic |
6218 | command, an arithmetic `for' command, or a nested subshell. Returns | |
6219 | the parsed token, -1 on error, or -2 if we didn't do anything and | |
6220 | should just go on. */ | |
6221 | static int | |
6222 | parse_dparen (c) | |
6223 | int c; | |
6224 | { | |
0628567a JA |
6225 | int cmdtyp, sline; |
6226 | char *wval; | |
7117c2d2 JA |
6227 | WORD_DESC *wd; |
6228 | ||
6229 | #if defined (ARITH_FOR_COMMAND) | |
6230 | if (last_read_token == FOR) | |
6231 | { | |
6232 | arith_for_lineno = line_number; | |
b80f6443 | 6233 | cmdtyp = parse_arith_cmd (&wval, 0); |
7117c2d2 JA |
6234 | if (cmdtyp == 1) |
6235 | { | |
95732b49 JA |
6236 | wd = alloc_word_desc (); |
6237 | wd->word = wval; | |
7117c2d2 | 6238 | yylval.word_list = make_word_list (wd, (WORD_LIST *)NULL); |
7117c2d2 JA |
6239 | return (ARITH_FOR_EXPRS); |
6240 | } | |
6241 | else | |
6242 | return -1; /* ERROR */ | |
6243 | } | |
6244 | #endif | |
6245 | ||
6246 | #if defined (DPAREN_ARITHMETIC) | |
6247 | if (reserved_word_acceptable (last_read_token)) | |
6248 | { | |
6249 | sline = line_number; | |
95732b49 | 6250 | |
b80f6443 | 6251 | cmdtyp = parse_arith_cmd (&wval, 0); |
7117c2d2 JA |
6252 | if (cmdtyp == 1) /* arithmetic command */ |
6253 | { | |
95732b49 JA |
6254 | wd = alloc_word_desc (); |
6255 | wd->word = wval; | |
6256 | wd->flags = W_QUOTED|W_NOSPLIT|W_NOGLOB|W_DQUOTE; | |
7117c2d2 | 6257 | yylval.word_list = make_word_list (wd, (WORD_LIST *)NULL); |
7117c2d2 JA |
6258 | return (ARITH_CMD); |
6259 | } | |
6260 | else if (cmdtyp == 0) /* nested subshell */ | |
6261 | { | |
6262 | push_string (wval, 0, (alias_t *)NULL); | |
6263 | if ((parser_state & PST_CASEPAT) == 0) | |
6264 | parser_state |= PST_SUBSHELL; | |
6265 | return (c); | |
6266 | } | |
6267 | else /* ERROR */ | |
6268 | return -1; | |
6269 | } | |
6270 | #endif | |
6271 | ||
6272 | return -2; /* XXX */ | |
6273 | } | |
6274 | ||
28ef6c31 JA |
6275 | /* We've seen a `(('. Look for the matching `))'. If we get it, return 1. |
6276 | If not, assume it's a nested subshell for backwards compatibility and | |
6277 | return 0. In any case, put the characters we've consumed into a locally- | |
6278 | allocated buffer and make *ep point to that buffer. Return -1 on an | |
6279 | error, for example EOF. */ | |
6280 | static int | |
b80f6443 | 6281 | parse_arith_cmd (ep, adddq) |
28ef6c31 | 6282 | char **ep; |
b80f6443 | 6283 | int adddq; |
28ef6c31 JA |
6284 | { |
6285 | int exp_lineno, rval, c; | |
f73dda09 | 6286 | char *ttok, *tokstr; |
28ef6c31 | 6287 | int ttoklen; |
726f6388 | 6288 | |
28ef6c31 JA |
6289 | exp_lineno = line_number; |
6290 | ttok = parse_matched_pair (0, '(', ')', &ttoklen, 0); | |
6291 | rval = 1; | |
6292 | if (ttok == &matched_pair_error) | |
6293 | return -1; | |
6294 | /* Check that the next character is the closing right paren. If | |
6295 | not, this is a syntax error. ( */ | |
7117c2d2 JA |
6296 | c = shell_getc (0); |
6297 | if MBTEST(c != ')') | |
28ef6c31 JA |
6298 | rval = 0; |
6299 | ||
f73dda09 | 6300 | tokstr = (char *)xmalloc (ttoklen + 4); |
28ef6c31 | 6301 | |
b80f6443 JA |
6302 | /* if ADDDQ != 0 then (( ... )) -> "..." */ |
6303 | if (rval == 1 && adddq) /* arith cmd, add double quotes */ | |
726f6388 | 6304 | { |
b80f6443 JA |
6305 | tokstr[0] = '"'; |
6306 | strncpy (tokstr + 1, ttok, ttoklen - 1); | |
f73dda09 JA |
6307 | tokstr[ttoklen] = '"'; |
6308 | tokstr[ttoklen+1] = '\0'; | |
726f6388 | 6309 | } |
b80f6443 JA |
6310 | else if (rval == 1) /* arith cmd, don't add double quotes */ |
6311 | { | |
6312 | strncpy (tokstr, ttok, ttoklen - 1); | |
6313 | tokstr[ttoklen-1] = '\0'; | |
6314 | } | |
6315 | else /* nested subshell */ | |
726f6388 | 6316 | { |
b80f6443 JA |
6317 | tokstr[0] = '('; |
6318 | strncpy (tokstr + 1, ttok, ttoklen - 1); | |
f73dda09 JA |
6319 | tokstr[ttoklen] = ')'; |
6320 | tokstr[ttoklen+1] = c; | |
6321 | tokstr[ttoklen+2] = '\0'; | |
726f6388 | 6322 | } |
b80f6443 | 6323 | |
f73dda09 | 6324 | *ep = tokstr; |
28ef6c31 JA |
6325 | FREE (ttok); |
6326 | return rval; | |
726f6388 | 6327 | } |
28ef6c31 | 6328 | #endif /* DPAREN_ARITHMETIC || ARITH_FOR_COMMAND */ |
726f6388 | 6329 | |
28ef6c31 | 6330 | #if defined (COND_COMMAND) |
7117c2d2 JA |
6331 | static void |
6332 | cond_error () | |
6333 | { | |
6334 | char *etext; | |
6335 | ||
6336 | if (EOF_Reached && cond_token != COND_ERROR) /* [[ */ | |
b80f6443 | 6337 | parser_error (cond_lineno, _("unexpected EOF while looking for `]]'")); |
7117c2d2 JA |
6338 | else if (cond_token != COND_ERROR) |
6339 | { | |
6340 | if (etext = error_token_from_token (cond_token)) | |
6341 | { | |
b80f6443 | 6342 | parser_error (cond_lineno, _("syntax error in conditional expression: unexpected token `%s'"), etext); |
7117c2d2 JA |
6343 | free (etext); |
6344 | } | |
6345 | else | |
b80f6443 | 6346 | parser_error (cond_lineno, _("syntax error in conditional expression")); |
7117c2d2 JA |
6347 | } |
6348 | } | |
6349 | ||
28ef6c31 JA |
6350 | static COND_COM * |
6351 | cond_expr () | |
ccc6cda3 | 6352 | { |
28ef6c31 | 6353 | return (cond_or ()); |
ccc6cda3 JA |
6354 | } |
6355 | ||
28ef6c31 JA |
6356 | static COND_COM * |
6357 | cond_or () | |
726f6388 | 6358 | { |
28ef6c31 | 6359 | COND_COM *l, *r; |
726f6388 | 6360 | |
28ef6c31 JA |
6361 | l = cond_and (); |
6362 | if (cond_token == OR_OR) | |
6363 | { | |
6364 | r = cond_or (); | |
6365 | l = make_cond_node (COND_OR, (WORD_DESC *)NULL, l, r); | |
6366 | } | |
6367 | return l; | |
726f6388 | 6368 | } |
726f6388 | 6369 | |
28ef6c31 JA |
6370 | static COND_COM * |
6371 | cond_and () | |
726f6388 | 6372 | { |
28ef6c31 | 6373 | COND_COM *l, *r; |
726f6388 | 6374 | |
28ef6c31 JA |
6375 | l = cond_term (); |
6376 | if (cond_token == AND_AND) | |
6377 | { | |
6378 | r = cond_and (); | |
6379 | l = make_cond_node (COND_AND, (WORD_DESC *)NULL, l, r); | |
6380 | } | |
6381 | return l; | |
726f6388 JA |
6382 | } |
6383 | ||
ccc6cda3 | 6384 | static int |
28ef6c31 | 6385 | cond_skip_newlines () |
726f6388 | 6386 | { |
28ef6c31 | 6387 | while ((cond_token = read_token (READ)) == '\n') |
726f6388 | 6388 | { |
b80f6443 | 6389 | if (SHOULD_PROMPT ()) |
726f6388 JA |
6390 | prompt_again (); |
6391 | } | |
28ef6c31 | 6392 | return (cond_token); |
726f6388 JA |
6393 | } |
6394 | ||
28ef6c31 JA |
6395 | #define COND_RETURN_ERROR() \ |
6396 | do { cond_token = COND_ERROR; return ((COND_COM *)NULL); } while (0) | |
726f6388 | 6397 | |
28ef6c31 JA |
6398 | static COND_COM * |
6399 | cond_term () | |
726f6388 | 6400 | { |
28ef6c31 JA |
6401 | WORD_DESC *op; |
6402 | COND_COM *term, *tleft, *tright; | |
6403 | int tok, lineno; | |
7117c2d2 | 6404 | char *etext; |
28ef6c31 JA |
6405 | |
6406 | /* Read a token. It can be a left paren, a `!', a unary operator, or a | |
6407 | word that should be the first argument of a binary operator. Start by | |
6408 | skipping newlines, since this is a compound command. */ | |
6409 | tok = cond_skip_newlines (); | |
6410 | lineno = line_number; | |
6411 | if (tok == COND_END) | |
726f6388 | 6412 | { |
28ef6c31 | 6413 | COND_RETURN_ERROR (); |
726f6388 | 6414 | } |
28ef6c31 JA |
6415 | else if (tok == '(') |
6416 | { | |
6417 | term = cond_expr (); | |
6418 | if (cond_token != ')') | |
6419 | { | |
6420 | if (term) | |
6421 | dispose_cond_node (term); /* ( */ | |
7117c2d2 JA |
6422 | if (etext = error_token_from_token (cond_token)) |
6423 | { | |
b80f6443 | 6424 | parser_error (lineno, _("unexpected token `%s', expected `)'"), etext); |
7117c2d2 JA |
6425 | free (etext); |
6426 | } | |
6427 | else | |
b80f6443 | 6428 | parser_error (lineno, _("expected `)'")); |
28ef6c31 JA |
6429 | COND_RETURN_ERROR (); |
6430 | } | |
6431 | term = make_cond_node (COND_EXPR, (WORD_DESC *)NULL, term, (COND_COM *)NULL); | |
6432 | (void)cond_skip_newlines (); | |
6433 | } | |
6434 | else if (tok == BANG || (tok == WORD && (yylval.word->word[0] == '!' && yylval.word->word[1] == '\0'))) | |
6435 | { | |
6436 | if (tok == WORD) | |
6437 | dispose_word (yylval.word); /* not needed */ | |
6438 | term = cond_term (); | |
6439 | if (term) | |
6440 | term->flags |= CMD_INVERT_RETURN; | |
6441 | } | |
3185942a | 6442 | else if (tok == WORD && yylval.word->word[0] == '-' && yylval.word->word[2] == 0 && test_unop (yylval.word->word)) |
28ef6c31 JA |
6443 | { |
6444 | op = yylval.word; | |
6445 | tok = read_token (READ); | |
6446 | if (tok == WORD) | |
6447 | { | |
6448 | tleft = make_cond_node (COND_TERM, yylval.word, (COND_COM *)NULL, (COND_COM *)NULL); | |
6449 | term = make_cond_node (COND_UNARY, op, tleft, (COND_COM *)NULL); | |
6450 | } | |
6451 | else | |
6452 | { | |
6453 | dispose_word (op); | |
7117c2d2 JA |
6454 | if (etext = error_token_from_token (tok)) |
6455 | { | |
b80f6443 | 6456 | parser_error (line_number, _("unexpected argument `%s' to conditional unary operator"), etext); |
7117c2d2 JA |
6457 | free (etext); |
6458 | } | |
6459 | else | |
b80f6443 | 6460 | parser_error (line_number, _("unexpected argument to conditional unary operator")); |
28ef6c31 JA |
6461 | COND_RETURN_ERROR (); |
6462 | } | |
726f6388 | 6463 | |
28ef6c31 JA |
6464 | (void)cond_skip_newlines (); |
6465 | } | |
6466 | else if (tok == WORD) /* left argument to binary operator */ | |
6467 | { | |
6468 | /* lhs */ | |
6469 | tleft = make_cond_node (COND_TERM, yylval.word, (COND_COM *)NULL, (COND_COM *)NULL); | |
726f6388 | 6470 | |
28ef6c31 JA |
6471 | /* binop */ |
6472 | tok = read_token (READ); | |
6473 | if (tok == WORD && test_binop (yylval.word->word)) | |
0001803f CR |
6474 | { |
6475 | op = yylval.word; | |
6476 | if (op->word[0] == '=' && (op->word[1] == '\0' || (op->word[1] == '=' && op->word[2] == '\0'))) | |
6477 | parser_state |= PST_EXTPAT; | |
6478 | else if (op->word[0] == '!' && op->word[1] == '=' && op->word[2] == '\0') | |
6479 | parser_state |= PST_EXTPAT; | |
6480 | } | |
b80f6443 | 6481 | #if defined (COND_REGEXP) |
3185942a JA |
6482 | else if (tok == WORD && STREQ (yylval.word->word, "=~")) |
6483 | { | |
6484 | op = yylval.word; | |
6485 | parser_state |= PST_REGEXP; | |
6486 | } | |
b80f6443 | 6487 | #endif |
28ef6c31 JA |
6488 | else if (tok == '<' || tok == '>') |
6489 | op = make_word_from_token (tok); /* ( */ | |
6490 | /* There should be a check before blindly accepting the `)' that we have | |
6491 | seen the opening `('. */ | |
6492 | else if (tok == COND_END || tok == AND_AND || tok == OR_OR || tok == ')') | |
6493 | { | |
6494 | /* Special case. [[ x ]] is equivalent to [[ -n x ]], just like | |
6495 | the test command. Similarly for [[ x && expr ]] or | |
6496 | [[ x || expr ]] or [[ (x) ]]. */ | |
6497 | op = make_word ("-n"); | |
6498 | term = make_cond_node (COND_UNARY, op, tleft, (COND_COM *)NULL); | |
6499 | cond_token = tok; | |
6500 | return (term); | |
6501 | } | |
6502 | else | |
6503 | { | |
7117c2d2 JA |
6504 | if (etext = error_token_from_token (tok)) |
6505 | { | |
b80f6443 | 6506 | parser_error (line_number, _("unexpected token `%s', conditional binary operator expected"), etext); |
7117c2d2 JA |
6507 | free (etext); |
6508 | } | |
6509 | else | |
b80f6443 | 6510 | parser_error (line_number, _("conditional binary operator expected")); |
28ef6c31 JA |
6511 | dispose_cond_node (tleft); |
6512 | COND_RETURN_ERROR (); | |
6513 | } | |
726f6388 | 6514 | |
28ef6c31 | 6515 | /* rhs */ |
0001803f CR |
6516 | if (parser_state & PST_EXTPAT) |
6517 | extended_glob = 1; | |
28ef6c31 | 6518 | tok = read_token (READ); |
0001803f CR |
6519 | if (parser_state & PST_EXTPAT) |
6520 | extended_glob = global_extglob; | |
6521 | parser_state &= ~(PST_REGEXP|PST_EXTPAT); | |
6522 | ||
28ef6c31 JA |
6523 | if (tok == WORD) |
6524 | { | |
6525 | tright = make_cond_node (COND_TERM, yylval.word, (COND_COM *)NULL, (COND_COM *)NULL); | |
6526 | term = make_cond_node (COND_BINARY, op, tleft, tright); | |
6527 | } | |
6528 | else | |
6529 | { | |
7117c2d2 JA |
6530 | if (etext = error_token_from_token (tok)) |
6531 | { | |
b80f6443 | 6532 | parser_error (line_number, _("unexpected argument `%s' to conditional binary operator"), etext); |
7117c2d2 JA |
6533 | free (etext); |
6534 | } | |
6535 | else | |
b80f6443 | 6536 | parser_error (line_number, _("unexpected argument to conditional binary operator")); |
28ef6c31 JA |
6537 | dispose_cond_node (tleft); |
6538 | dispose_word (op); | |
6539 | COND_RETURN_ERROR (); | |
6540 | } | |
726f6388 | 6541 | |
28ef6c31 JA |
6542 | (void)cond_skip_newlines (); |
6543 | } | |
6544 | else | |
6545 | { | |
6546 | if (tok < 256) | |
b80f6443 | 6547 | parser_error (line_number, _("unexpected token `%c' in conditional command"), tok); |
7117c2d2 JA |
6548 | else if (etext = error_token_from_token (tok)) |
6549 | { | |
b80f6443 | 6550 | parser_error (line_number, _("unexpected token `%s' in conditional command"), etext); |
7117c2d2 JA |
6551 | free (etext); |
6552 | } | |
28ef6c31 | 6553 | else |
b80f6443 | 6554 | parser_error (line_number, _("unexpected token %d in conditional command"), tok); |
28ef6c31 JA |
6555 | COND_RETURN_ERROR (); |
6556 | } | |
6557 | return (term); | |
6558 | } | |
ccc6cda3 | 6559 | |
28ef6c31 JA |
6560 | /* This is kind of bogus -- we slip a mini recursive-descent parser in |
6561 | here to handle the conditional statement syntax. */ | |
6562 | static COMMAND * | |
6563 | parse_cond_command () | |
6564 | { | |
6565 | COND_COM *cexp; | |
ccc6cda3 | 6566 | |
0001803f | 6567 | global_extglob = extended_glob; |
28ef6c31 JA |
6568 | cexp = cond_expr (); |
6569 | return (make_cond_command (cexp)); | |
6570 | } | |
6571 | #endif | |
ccc6cda3 | 6572 | |
7117c2d2 JA |
6573 | #if defined (ARRAY_VARS) |
6574 | /* When this is called, it's guaranteed that we don't care about anything | |
6575 | in t beyond i. We do save and restore the chars, though. */ | |
6576 | static int | |
6577 | token_is_assignment (t, i) | |
6578 | char *t; | |
6579 | int i; | |
6580 | { | |
6581 | unsigned char c, c1; | |
6582 | int r; | |
6583 | ||
6584 | c = t[i]; c1 = t[i+1]; | |
6585 | t[i] = '='; t[i+1] = '\0'; | |
b80f6443 | 6586 | r = assignment (t, (parser_state & PST_COMPASSIGN) != 0); |
7117c2d2 JA |
6587 | t[i] = c; t[i+1] = c1; |
6588 | return r; | |
6589 | } | |
6590 | ||
95732b49 | 6591 | /* XXX - possible changes here for `+=' */ |
7117c2d2 JA |
6592 | static int |
6593 | token_is_ident (t, i) | |
6594 | char *t; | |
6595 | int i; | |
6596 | { | |
6597 | unsigned char c; | |
6598 | int r; | |
6599 | ||
6600 | c = t[i]; | |
6601 | t[i] = '\0'; | |
6602 | r = legal_identifier (t); | |
6603 | t[i] = c; | |
6604 | return r; | |
6605 | } | |
6606 | #endif | |
6607 | ||
726f6388 | 6608 | static int |
28ef6c31 JA |
6609 | read_token_word (character) |
6610 | int character; | |
726f6388 | 6611 | { |
28ef6c31 JA |
6612 | /* The value for YYLVAL when a WORD is read. */ |
6613 | WORD_DESC *the_word; | |
726f6388 | 6614 | |
28ef6c31 JA |
6615 | /* Index into the token that we are building. */ |
6616 | int token_index; | |
ccc6cda3 | 6617 | |
28ef6c31 | 6618 | /* ALL_DIGITS becomes zero when we see a non-digit. */ |
f73dda09 | 6619 | int all_digit_token; |
ccc6cda3 | 6620 | |
28ef6c31 JA |
6621 | /* DOLLAR_PRESENT becomes non-zero if we see a `$'. */ |
6622 | int dollar_present; | |
cce855bc | 6623 | |
95732b49 JA |
6624 | /* COMPOUND_ASSIGNMENT becomes non-zero if we are parsing a compound |
6625 | assignment. */ | |
6626 | int compound_assignment; | |
6627 | ||
28ef6c31 JA |
6628 | /* QUOTED becomes non-zero if we see one of ("), ('), (`), or (\). */ |
6629 | int quoted; | |
cce855bc | 6630 | |
28ef6c31 JA |
6631 | /* Non-zero means to ignore the value of the next character, and just |
6632 | to add it no matter what. */ | |
6633 | int pass_next_character; | |
cce855bc | 6634 | |
28ef6c31 JA |
6635 | /* The current delimiting character. */ |
6636 | int cd; | |
6637 | int result, peek_char; | |
6638 | char *ttok, *ttrans; | |
6639 | int ttoklen, ttranslen; | |
7117c2d2 | 6640 | intmax_t lvalue; |
ccc6cda3 | 6641 | |
28ef6c31 | 6642 | if (token_buffer_size < TOKEN_DEFAULT_INITIAL_SIZE) |
f73dda09 | 6643 | token = (char *)xrealloc (token, token_buffer_size = TOKEN_DEFAULT_INITIAL_SIZE); |
726f6388 | 6644 | |
28ef6c31 | 6645 | token_index = 0; |
f73dda09 | 6646 | all_digit_token = DIGIT (character); |
95732b49 | 6647 | dollar_present = quoted = pass_next_character = compound_assignment = 0; |
ccc6cda3 | 6648 | |
28ef6c31 | 6649 | for (;;) |
ccc6cda3 | 6650 | { |
28ef6c31 JA |
6651 | if (character == EOF) |
6652 | goto got_token; | |
726f6388 | 6653 | |
28ef6c31 | 6654 | if (pass_next_character) |
726f6388 | 6655 | { |
28ef6c31 | 6656 | pass_next_character = 0; |
3185942a | 6657 | goto got_escaped_character; |
726f6388 | 6658 | } |
726f6388 | 6659 | |
28ef6c31 | 6660 | cd = current_delimiter (dstack); |
ccc6cda3 | 6661 | |
28ef6c31 JA |
6662 | /* Handle backslashes. Quote lots of things when not inside of |
6663 | double-quotes, quote some things inside of double-quotes. */ | |
7117c2d2 | 6664 | if MBTEST(character == '\\') |
28ef6c31 JA |
6665 | { |
6666 | peek_char = shell_getc (0); | |
ccc6cda3 | 6667 | |
28ef6c31 JA |
6668 | /* Backslash-newline is ignored in all cases except |
6669 | when quoted with single quotes. */ | |
6670 | if (peek_char == '\n') | |
6671 | { | |
6672 | character = '\n'; | |
6673 | goto next_character; | |
6674 | } | |
6675 | else | |
6676 | { | |
6677 | shell_ungetc (peek_char); | |
ccc6cda3 | 6678 | |
28ef6c31 JA |
6679 | /* If the next character is to be quoted, note it now. */ |
6680 | if (cd == 0 || cd == '`' || | |
f73dda09 | 6681 | (cd == '"' && peek_char >= 0 && (sh_syntaxtab[peek_char] & CBSDQUOTE))) |
28ef6c31 | 6682 | pass_next_character++; |
ccc6cda3 | 6683 | |
28ef6c31 JA |
6684 | quoted = 1; |
6685 | goto got_character; | |
6686 | } | |
6687 | } | |
726f6388 | 6688 | |
28ef6c31 | 6689 | /* Parse a matched pair of quote characters. */ |
7117c2d2 | 6690 | if MBTEST(shellquote (character)) |
d166f048 | 6691 | { |
28ef6c31 | 6692 | push_delimiter (dstack, character); |
95732b49 | 6693 | ttok = parse_matched_pair (character, character, character, &ttoklen, (character == '`') ? P_COMMAND : 0); |
28ef6c31 JA |
6694 | pop_delimiter (dstack); |
6695 | if (ttok == &matched_pair_error) | |
6696 | return -1; /* Bail immediately. */ | |
6697 | RESIZE_MALLOCED_BUFFER (token, token_index, ttoklen + 2, | |
6698 | token_buffer_size, TOKEN_DEFAULT_GROW_SIZE); | |
6699 | token[token_index++] = character; | |
6700 | strcpy (token + token_index, ttok); | |
6701 | token_index += ttoklen; | |
f73dda09 | 6702 | all_digit_token = 0; |
28ef6c31 JA |
6703 | quoted = 1; |
6704 | dollar_present |= (character == '"' && strchr (ttok, '$') != 0); | |
6705 | FREE (ttok); | |
6706 | goto next_character; | |
d166f048 | 6707 | } |
726f6388 | 6708 | |
3185942a JA |
6709 | #ifdef COND_REGEXP |
6710 | /* When parsing a regexp as a single word inside a conditional command, | |
6711 | we need to special-case characters special to both the shell and | |
6712 | regular expressions. Right now, that is only '(' and '|'. */ /*)*/ | |
6713 | if MBTEST((parser_state & PST_REGEXP) && (character == '(' || character == '|')) /*)*/ | |
6714 | { | |
6715 | if (character == '|') | |
6716 | goto got_character; | |
6717 | ||
6718 | push_delimiter (dstack, character); | |
6719 | ttok = parse_matched_pair (cd, '(', ')', &ttoklen, 0); | |
6720 | pop_delimiter (dstack); | |
6721 | if (ttok == &matched_pair_error) | |
6722 | return -1; /* Bail immediately. */ | |
6723 | RESIZE_MALLOCED_BUFFER (token, token_index, ttoklen + 2, | |
6724 | token_buffer_size, TOKEN_DEFAULT_GROW_SIZE); | |
6725 | token[token_index++] = character; | |
6726 | strcpy (token + token_index, ttok); | |
6727 | token_index += ttoklen; | |
6728 | FREE (ttok); | |
6729 | dollar_present = all_digit_token = 0; | |
6730 | goto next_character; | |
6731 | } | |
6732 | #endif /* COND_REGEXP */ | |
6733 | ||
28ef6c31 JA |
6734 | #ifdef EXTENDED_GLOB |
6735 | /* Parse a ksh-style extended pattern matching specification. */ | |
3185942a | 6736 | if MBTEST(extended_glob && PATTERN_CHAR (character)) |
cce855bc | 6737 | { |
28ef6c31 | 6738 | peek_char = shell_getc (1); |
7117c2d2 | 6739 | if MBTEST(peek_char == '(') /* ) */ |
28ef6c31 JA |
6740 | { |
6741 | push_delimiter (dstack, peek_char); | |
6742 | ttok = parse_matched_pair (cd, '(', ')', &ttoklen, 0); | |
6743 | pop_delimiter (dstack); | |
6744 | if (ttok == &matched_pair_error) | |
6745 | return -1; /* Bail immediately. */ | |
6746 | RESIZE_MALLOCED_BUFFER (token, token_index, ttoklen + 2, | |
6747 | token_buffer_size, | |
6748 | TOKEN_DEFAULT_GROW_SIZE); | |
6749 | token[token_index++] = character; | |
6750 | token[token_index++] = peek_char; | |
6751 | strcpy (token + token_index, ttok); | |
6752 | token_index += ttoklen; | |
6753 | FREE (ttok); | |
f73dda09 | 6754 | dollar_present = all_digit_token = 0; |
28ef6c31 JA |
6755 | goto next_character; |
6756 | } | |
6757 | else | |
6758 | shell_ungetc (peek_char); | |
6759 | } | |
6760 | #endif /* EXTENDED_GLOB */ | |
726f6388 | 6761 | |
28ef6c31 JA |
6762 | /* If the delimiter character is not single quote, parse some of |
6763 | the shell expansions that must be read as a single word. */ | |
6764 | if (shellexp (character)) | |
6765 | { | |
6766 | peek_char = shell_getc (1); | |
6767 | /* $(...), <(...), >(...), $((...)), ${...}, and $[...] constructs */ | |
7117c2d2 | 6768 | if MBTEST(peek_char == '(' || \ |
28ef6c31 JA |
6769 | ((peek_char == '{' || peek_char == '[') && character == '$')) /* ) ] } */ |
6770 | { | |
6771 | if (peek_char == '{') /* } */ | |
495aee44 | 6772 | ttok = parse_matched_pair (cd, '{', '}', &ttoklen, P_FIRSTCLOSE|P_DOLBRACE); |
28ef6c31 JA |
6773 | else if (peek_char == '(') /* ) */ |
6774 | { | |
6775 | /* XXX - push and pop the `(' as a delimiter for use by | |
6776 | the command-oriented-history code. This way newlines | |
6777 | appearing in the $(...) string get added to the | |
6778 | history literally rather than causing a possibly- | |
6779 | incorrect `;' to be added. ) */ | |
6780 | push_delimiter (dstack, peek_char); | |
3185942a | 6781 | ttok = parse_comsub (cd, '(', ')', &ttoklen, P_COMMAND); |
28ef6c31 JA |
6782 | pop_delimiter (dstack); |
6783 | } | |
6784 | else | |
6785 | ttok = parse_matched_pair (cd, '[', ']', &ttoklen, 0); | |
6786 | if (ttok == &matched_pair_error) | |
6787 | return -1; /* Bail immediately. */ | |
6788 | RESIZE_MALLOCED_BUFFER (token, token_index, ttoklen + 2, | |
6789 | token_buffer_size, | |
6790 | TOKEN_DEFAULT_GROW_SIZE); | |
6791 | token[token_index++] = character; | |
6792 | token[token_index++] = peek_char; | |
6793 | strcpy (token + token_index, ttok); | |
6794 | token_index += ttoklen; | |
6795 | FREE (ttok); | |
6796 | dollar_present = 1; | |
f73dda09 | 6797 | all_digit_token = 0; |
28ef6c31 JA |
6798 | goto next_character; |
6799 | } | |
6800 | /* This handles $'...' and $"..." new-style quoted strings. */ | |
7117c2d2 | 6801 | else if MBTEST(character == '$' && (peek_char == '\'' || peek_char == '"')) |
28ef6c31 JA |
6802 | { |
6803 | int first_line; | |
726f6388 | 6804 | |
28ef6c31 JA |
6805 | first_line = line_number; |
6806 | push_delimiter (dstack, peek_char); | |
6807 | ttok = parse_matched_pair (peek_char, peek_char, peek_char, | |
6808 | &ttoklen, | |
6809 | (peek_char == '\'') ? P_ALLOWESC : 0); | |
6810 | pop_delimiter (dstack); | |
6811 | if (ttok == &matched_pair_error) | |
6812 | return -1; | |
6813 | if (peek_char == '\'') | |
6814 | { | |
6815 | ttrans = ansiexpand (ttok, 0, ttoklen - 1, &ttranslen); | |
6816 | free (ttok); | |
95732b49 | 6817 | |
28ef6c31 JA |
6818 | /* Insert the single quotes and correctly quote any |
6819 | embedded single quotes (allowed because P_ALLOWESC was | |
6820 | passed to parse_matched_pair). */ | |
6821 | ttok = sh_single_quote (ttrans); | |
6822 | free (ttrans); | |
95732b49 | 6823 | ttranslen = strlen (ttok); |
28ef6c31 | 6824 | ttrans = ttok; |
28ef6c31 JA |
6825 | } |
6826 | else | |
6827 | { | |
0628567a | 6828 | /* Try to locale-expand the converted string. */ |
28ef6c31 JA |
6829 | ttrans = localeexpand (ttok, 0, ttoklen - 1, first_line, &ttranslen); |
6830 | free (ttok); | |
726f6388 | 6831 | |
28ef6c31 | 6832 | /* Add the double quotes back */ |
95732b49 | 6833 | ttok = sh_mkdoublequoted (ttrans, ttranslen, 0); |
28ef6c31 | 6834 | free (ttrans); |
95732b49 | 6835 | ttranslen += 2; |
28ef6c31 JA |
6836 | ttrans = ttok; |
6837 | } | |
726f6388 | 6838 | |
28ef6c31 | 6839 | RESIZE_MALLOCED_BUFFER (token, token_index, ttranslen + 2, |
f73dda09 JA |
6840 | token_buffer_size, |
6841 | TOKEN_DEFAULT_GROW_SIZE); | |
6842 | strcpy (token + token_index, ttrans); | |
6843 | token_index += ttranslen; | |
6844 | FREE (ttrans); | |
6845 | quoted = 1; | |
6846 | all_digit_token = 0; | |
6847 | goto next_character; | |
6848 | } | |
6849 | /* This could eventually be extended to recognize all of the | |
6850 | shell's single-character parameter expansions, and set flags.*/ | |
7117c2d2 | 6851 | else if MBTEST(character == '$' && peek_char == '$') |
f73dda09 JA |
6852 | { |
6853 | ttok = (char *)xmalloc (3); | |
6854 | ttok[0] = ttok[1] = '$'; | |
6855 | ttok[2] = '\0'; | |
6856 | RESIZE_MALLOCED_BUFFER (token, token_index, 3, | |
6857 | token_buffer_size, | |
6858 | TOKEN_DEFAULT_GROW_SIZE); | |
6859 | strcpy (token + token_index, ttok); | |
6860 | token_index += 2; | |
6861 | dollar_present = 1; | |
6862 | all_digit_token = 0; | |
6863 | FREE (ttok); | |
6864 | goto next_character; | |
6865 | } | |
6866 | else | |
6867 | shell_ungetc (peek_char); | |
6868 | } | |
28ef6c31 | 6869 | |
f73dda09 | 6870 | #if defined (ARRAY_VARS) |
3185942a JA |
6871 | /* Identify possible array subscript assignment; match [...]. If |
6872 | parser_state&PST_COMPASSIGN, we need to parse [sub]=words treating | |
6873 | `sub' as if it were enclosed in double quotes. */ | |
6874 | else if MBTEST(character == '[' && /* ] */ | |
6875 | ((token_index > 0 && assignment_acceptable (last_read_token) && token_is_ident (token, token_index)) || | |
6876 | (token_index == 0 && (parser_state&PST_COMPASSIGN)))) | |
7117c2d2 | 6877 | { |
0001803f | 6878 | ttok = parse_matched_pair (cd, '[', ']', &ttoklen, P_ARRAYSUB); |
7117c2d2 JA |
6879 | if (ttok == &matched_pair_error) |
6880 | return -1; /* Bail immediately. */ | |
6881 | RESIZE_MALLOCED_BUFFER (token, token_index, ttoklen + 2, | |
6882 | token_buffer_size, | |
6883 | TOKEN_DEFAULT_GROW_SIZE); | |
6884 | token[token_index++] = character; | |
6885 | strcpy (token + token_index, ttok); | |
6886 | token_index += ttoklen; | |
6887 | FREE (ttok); | |
6888 | all_digit_token = 0; | |
6889 | goto next_character; | |
6890 | } | |
f73dda09 | 6891 | /* Identify possible compound array variable assignment. */ |
95732b49 | 6892 | else if MBTEST(character == '=' && token_index > 0 && (assignment_acceptable (last_read_token) || (parser_state & PST_ASSIGNOK)) && token_is_assignment (token, token_index)) |
ccc6cda3 | 6893 | { |
f73dda09 | 6894 | peek_char = shell_getc (1); |
7117c2d2 | 6895 | if MBTEST(peek_char == '(') /* ) */ |
f73dda09 | 6896 | { |
7117c2d2 JA |
6897 | ttok = parse_compound_assignment (&ttoklen); |
6898 | ||
6899 | RESIZE_MALLOCED_BUFFER (token, token_index, ttoklen + 4, | |
f73dda09 JA |
6900 | token_buffer_size, |
6901 | TOKEN_DEFAULT_GROW_SIZE); | |
7117c2d2 JA |
6902 | |
6903 | token[token_index++] = '='; | |
6904 | token[token_index++] = '('; | |
6905 | if (ttok) | |
6906 | { | |
6907 | strcpy (token + token_index, ttok); | |
6908 | token_index += ttoklen; | |
6909 | } | |
6910 | token[token_index++] = ')'; | |
f73dda09 JA |
6911 | FREE (ttok); |
6912 | all_digit_token = 0; | |
95732b49 | 6913 | compound_assignment = 1; |
0628567a | 6914 | #if 1 |
f73dda09 | 6915 | goto next_character; |
95732b49 JA |
6916 | #else |
6917 | goto got_token; /* ksh93 seems to do this */ | |
6918 | #endif | |
f73dda09 JA |
6919 | } |
6920 | else | |
6921 | shell_ungetc (peek_char); | |
ccc6cda3 | 6922 | } |
f73dda09 | 6923 | #endif |
726f6388 | 6924 | |
f73dda09 JA |
6925 | /* When not parsing a multi-character word construct, shell meta- |
6926 | characters break words. */ | |
7117c2d2 | 6927 | if MBTEST(shellbreak (character)) |
f73dda09 JA |
6928 | { |
6929 | shell_ungetc (character); | |
6930 | goto got_token; | |
6931 | } | |
726f6388 | 6932 | |
f73dda09 | 6933 | got_character: |
726f6388 | 6934 | |
f73dda09 JA |
6935 | if (character == CTLESC || character == CTLNUL) |
6936 | token[token_index++] = CTLESC; | |
d166f048 | 6937 | |
3185942a JA |
6938 | got_escaped_character: |
6939 | ||
6940 | all_digit_token &= DIGIT (character); | |
6941 | dollar_present |= character == '$'; | |
6942 | ||
f73dda09 | 6943 | token[token_index++] = character; |
cce855bc | 6944 | |
f73dda09 JA |
6945 | RESIZE_MALLOCED_BUFFER (token, token_index, 1, token_buffer_size, |
6946 | TOKEN_DEFAULT_GROW_SIZE); | |
cce855bc | 6947 | |
f73dda09 | 6948 | next_character: |
b80f6443 | 6949 | if (character == '\n' && SHOULD_PROMPT ()) |
f73dda09 | 6950 | prompt_again (); |
cce855bc | 6951 | |
f73dda09 JA |
6952 | /* We want to remove quoted newlines (that is, a \<newline> pair) |
6953 | unless we are within single quotes or pass_next_character is | |
6954 | set (the shell equivalent of literal-next). */ | |
6955 | cd = current_delimiter (dstack); | |
6956 | character = shell_getc (cd != '\'' && pass_next_character == 0); | |
6957 | } /* end for (;;) */ | |
cce855bc | 6958 | |
f73dda09 | 6959 | got_token: |
cce855bc | 6960 | |
f73dda09 | 6961 | token[token_index] = '\0'; |
28ef6c31 | 6962 | |
f73dda09 JA |
6963 | /* Check to see what thing we should return. If the last_read_token |
6964 | is a `<', or a `&', or the character which ended this token is | |
6965 | a '>' or '<', then, and ONLY then, is this input token a NUMBER. | |
6966 | Otherwise, it is just a word, and should be returned as such. */ | |
7117c2d2 JA |
6967 | if MBTEST(all_digit_token && (character == '<' || character == '>' || \ |
6968 | last_read_token == LESS_AND || \ | |
f73dda09 JA |
6969 | last_read_token == GREATER_AND)) |
6970 | { | |
6971 | if (legal_number (token, &lvalue) && (int)lvalue == lvalue) | |
6972 | yylval.number = lvalue; | |
6973 | else | |
6974 | yylval.number = -1; | |
6975 | return (NUMBER); | |
6976 | } | |
cce855bc | 6977 | |
f73dda09 | 6978 | /* Check for special case tokens. */ |
7117c2d2 | 6979 | result = (last_shell_getc_is_singlebyte) ? special_case_tokens (token) : -1; |
f73dda09 JA |
6980 | if (result >= 0) |
6981 | return result; | |
cce855bc | 6982 | |
f73dda09 JA |
6983 | #if defined (ALIAS) |
6984 | /* Posix.2 does not allow reserved words to be aliased, so check for all | |
6985 | of them, including special cases, before expanding the current token | |
6986 | as an alias. */ | |
7117c2d2 | 6987 | if MBTEST(posixly_correct) |
f73dda09 | 6988 | CHECK_FOR_RESERVED_WORD (token); |
cce855bc | 6989 | |
f73dda09 JA |
6990 | /* Aliases are expanded iff EXPAND_ALIASES is non-zero, and quoting |
6991 | inhibits alias expansion. */ | |
6992 | if (expand_aliases && quoted == 0) | |
cce855bc | 6993 | { |
f73dda09 JA |
6994 | result = alias_expand_token (token); |
6995 | if (result == RE_READ_TOKEN) | |
6996 | return (RE_READ_TOKEN); | |
6997 | else if (result == NO_EXPANSION) | |
6998 | parser_state &= ~PST_ALEXPNEXT; | |
cce855bc | 6999 | } |
28ef6c31 | 7000 | |
f73dda09 JA |
7001 | /* If not in Posix.2 mode, check for reserved words after alias |
7002 | expansion. */ | |
7117c2d2 | 7003 | if MBTEST(posixly_correct == 0) |
f73dda09 JA |
7004 | #endif |
7005 | CHECK_FOR_RESERVED_WORD (token); | |
7006 | ||
7007 | the_word = (WORD_DESC *)xmalloc (sizeof (WORD_DESC)); | |
7008 | the_word->word = (char *)xmalloc (1 + token_index); | |
7009 | the_word->flags = 0; | |
7010 | strcpy (the_word->word, token); | |
7011 | if (dollar_present) | |
7012 | the_word->flags |= W_HASDOLLAR; | |
7013 | if (quoted) | |
0628567a JA |
7014 | the_word->flags |= W_QUOTED; /*(*/ |
7015 | if (compound_assignment && token[token_index-1] == ')') | |
95732b49 | 7016 | the_word->flags |= W_COMPASSIGN; |
f73dda09 JA |
7017 | /* A word is an assignment if it appears at the beginning of a |
7018 | simple command, or after another assignment word. This is | |
7019 | context-dependent, so it cannot be handled in the grammar. */ | |
b80f6443 | 7020 | if (assignment (token, (parser_state & PST_COMPASSIGN) != 0)) |
cce855bc | 7021 | { |
f73dda09 JA |
7022 | the_word->flags |= W_ASSIGNMENT; |
7023 | /* Don't perform word splitting on assignment statements. */ | |
b80f6443 | 7024 | if (assignment_acceptable (last_read_token) || (parser_state & PST_COMPASSIGN) != 0) |
f73dda09 | 7025 | the_word->flags |= W_NOSPLIT; |
cce855bc | 7026 | } |
28ef6c31 | 7027 | |
95732b49 JA |
7028 | if (command_token_position (last_read_token)) |
7029 | { | |
7030 | struct builtin *b; | |
7031 | b = builtin_address_internal (token, 0); | |
7032 | if (b && (b->flags & ASSIGNMENT_BUILTIN)) | |
0628567a JA |
7033 | parser_state |= PST_ASSIGNOK; |
7034 | else if (STREQ (token, "eval") || STREQ (token, "let")) | |
7035 | parser_state |= PST_ASSIGNOK; | |
95732b49 JA |
7036 | } |
7037 | ||
f73dda09 JA |
7038 | yylval.word = the_word; |
7039 | ||
0001803f CR |
7040 | if (token[0] == '{' && token[token_index-1] == '}' && |
7041 | (character == '<' || character == '>')) | |
7042 | { | |
7043 | /* can use token; already copied to the_word */ | |
7044 | token[token_index-1] = '\0'; | |
7045 | if (legal_identifier (token+1)) | |
7046 | { | |
7047 | strcpy (the_word->word, token+1); | |
7048 | /*itrace("read_token_word: returning REDIR_WORD for %s", the_word->word);*/ | |
7049 | return (REDIR_WORD); | |
7050 | } | |
7051 | } | |
7052 | ||
f73dda09 JA |
7053 | result = ((the_word->flags & (W_ASSIGNMENT|W_NOSPLIT)) == (W_ASSIGNMENT|W_NOSPLIT)) |
7054 | ? ASSIGNMENT_WORD : WORD; | |
7055 | ||
b80f6443 | 7056 | switch (last_read_token) |
cce855bc | 7057 | { |
b80f6443 | 7058 | case FUNCTION: |
f73dda09 JA |
7059 | parser_state |= PST_ALLOWOPNBRC; |
7060 | function_dstart = line_number; | |
b80f6443 JA |
7061 | break; |
7062 | case CASE: | |
7063 | case SELECT: | |
7064 | case FOR: | |
7065 | if (word_top < MAX_CASE_NEST) | |
7066 | word_top++; | |
7067 | word_lineno[word_top] = line_number; | |
7068 | break; | |
cce855bc | 7069 | } |
cce855bc | 7070 | |
f73dda09 | 7071 | return (result); |
28ef6c31 | 7072 | } |
cce855bc | 7073 | |
f73dda09 JA |
7074 | /* Return 1 if TOKSYM is a token that after being read would allow |
7075 | a reserved word to be seen, else 0. */ | |
7076 | static int | |
7077 | reserved_word_acceptable (toksym) | |
7078 | int toksym; | |
7079 | { | |
7117c2d2 JA |
7080 | switch (toksym) |
7081 | { | |
7082 | case '\n': | |
7083 | case ';': | |
7084 | case '(': | |
7085 | case ')': | |
7086 | case '|': | |
7087 | case '&': | |
7088 | case '{': | |
7089 | case '}': /* XXX */ | |
7090 | case AND_AND: | |
7091 | case BANG: | |
0001803f | 7092 | case BAR_AND: |
7117c2d2 JA |
7093 | case DO: |
7094 | case DONE: | |
7095 | case ELIF: | |
7096 | case ELSE: | |
7097 | case ESAC: | |
7098 | case FI: | |
7099 | case IF: | |
7100 | case OR_OR: | |
7101 | case SEMI_SEMI: | |
3185942a JA |
7102 | case SEMI_AND: |
7103 | case SEMI_SEMI_AND: | |
7117c2d2 JA |
7104 | case THEN: |
7105 | case TIME: | |
7106 | case TIMEOPT: | |
495aee44 | 7107 | case TIMEIGN: |
3185942a | 7108 | case COPROC: |
7117c2d2 JA |
7109 | case UNTIL: |
7110 | case WHILE: | |
7111 | case 0: | |
7112 | return 1; | |
7113 | default: | |
3185942a JA |
7114 | #if defined (COPROCESS_SUPPORT) |
7115 | if (last_read_token == WORD && token_before_that == COPROC) | |
7116 | return 1; | |
7117 | #endif | |
495aee44 CR |
7118 | if (last_read_token == WORD && token_before_that == FUNCTION) |
7119 | return 1; | |
7117c2d2 JA |
7120 | return 0; |
7121 | } | |
f73dda09 | 7122 | } |
7117c2d2 | 7123 | |
f73dda09 JA |
7124 | /* Return the index of TOKEN in the alist of reserved words, or -1 if |
7125 | TOKEN is not a shell reserved word. */ | |
7126 | int | |
7127 | find_reserved_word (tokstr) | |
7128 | char *tokstr; | |
7129 | { | |
7130 | int i; | |
7131 | for (i = 0; word_token_alist[i].word; i++) | |
7132 | if (STREQ (tokstr, word_token_alist[i].word)) | |
7133 | return i; | |
7134 | return -1; | |
7135 | } | |
ccc6cda3 | 7136 | |
f73dda09 JA |
7137 | #if 0 |
7138 | #if defined (READLINE) | |
7139 | /* Called after each time readline is called. This insures that whatever | |
7140 | the new prompt string is gets propagated to readline's local prompt | |
7141 | variable. */ | |
7142 | static void | |
7143 | reset_readline_prompt () | |
7144 | { | |
7145 | char *temp_prompt; | |
726f6388 | 7146 | |
f73dda09 JA |
7147 | if (prompt_string_pointer) |
7148 | { | |
7149 | temp_prompt = (*prompt_string_pointer) | |
7150 | ? decode_prompt_string (*prompt_string_pointer) | |
7151 | : (char *)NULL; | |
726f6388 | 7152 | |
f73dda09 JA |
7153 | if (temp_prompt == 0) |
7154 | { | |
7155 | temp_prompt = (char *)xmalloc (1); | |
7156 | temp_prompt[0] = '\0'; | |
7157 | } | |
ccc6cda3 | 7158 | |
f73dda09 JA |
7159 | FREE (current_readline_prompt); |
7160 | current_readline_prompt = temp_prompt; | |
7161 | } | |
7162 | } | |
7163 | #endif /* READLINE */ | |
7164 | #endif /* 0 */ | |
726f6388 | 7165 | |
f73dda09 JA |
7166 | #if defined (HISTORY) |
7167 | /* A list of tokens which can be followed by newlines, but not by | |
7168 | semi-colons. When concatenating multiple lines of history, the | |
7169 | newline separator for such tokens is replaced with a space. */ | |
3185942a | 7170 | static const int no_semi_successors[] = { |
f73dda09 | 7171 | '\n', '{', '(', ')', ';', '&', '|', |
3185942a JA |
7172 | CASE, DO, ELSE, IF, SEMI_SEMI, SEMI_AND, SEMI_SEMI_AND, THEN, UNTIL, |
7173 | WHILE, AND_AND, OR_OR, IN, | |
f73dda09 JA |
7174 | 0 |
7175 | }; | |
ccc6cda3 | 7176 | |
f73dda09 JA |
7177 | /* If we are not within a delimited expression, try to be smart |
7178 | about which separators can be semi-colons and which must be | |
7179 | newlines. Returns the string that should be added into the | |
495aee44 CR |
7180 | history entry. LINE is the line we're about to add; it helps |
7181 | make some more intelligent decisions in certain cases. */ | |
f73dda09 | 7182 | char * |
495aee44 CR |
7183 | history_delimiting_chars (line) |
7184 | const char *line; | |
f73dda09 | 7185 | { |
495aee44 | 7186 | static int last_was_heredoc = 0; /* was the last entry the start of a here document? */ |
f73dda09 | 7187 | register int i; |
726f6388 | 7188 | |
495aee44 CR |
7189 | if ((parser_state & PST_HEREDOC) == 0) |
7190 | last_was_heredoc = 0; | |
7191 | ||
f73dda09 JA |
7192 | if (dstack.delimiter_depth != 0) |
7193 | return ("\n"); | |
3185942a JA |
7194 | |
7195 | /* We look for current_command_line_count == 2 because we are looking to | |
7196 | add the first line of the body of the here document (the second line | |
495aee44 CR |
7197 | of the command). We also keep LAST_WAS_HEREDOC as a private sentinel |
7198 | variable to note when we think we added the first line of a here doc | |
7199 | (the one with a "<<" somewhere in it) */ | |
3185942a | 7200 | if (parser_state & PST_HEREDOC) |
495aee44 CR |
7201 | { |
7202 | if (last_was_heredoc) | |
7203 | { | |
7204 | last_was_heredoc = 0; | |
7205 | return "\n"; | |
7206 | } | |
7207 | return (current_command_line_count == 2 ? "\n" : ""); | |
7208 | } | |
3185942a | 7209 | |
f73dda09 JA |
7210 | /* First, handle some special cases. */ |
7211 | /*(*/ | |
7212 | /* If we just read `()', assume it's a function definition, and don't | |
7213 | add a semicolon. If the token before the `)' was not `(', and we're | |
7214 | not in the midst of parsing a case statement, assume it's a | |
7215 | parenthesized command and add the semicolon. */ | |
7216 | /*)(*/ | |
7217 | if (token_before_that == ')') | |
7218 | { | |
7219 | if (two_tokens_ago == '(') /*)*/ /* function def */ | |
7220 | return " "; | |
7221 | /* This does not work for subshells inside case statement | |
7222 | command lists. It's a suboptimal solution. */ | |
7223 | else if (parser_state & PST_CASESTMT) /* case statement pattern */ | |
7224 | return " "; | |
7225 | else | |
7226 | return "; "; /* (...) subshell */ | |
7227 | } | |
7228 | else if (token_before_that == WORD && two_tokens_ago == FUNCTION) | |
7229 | return " "; /* function def using `function name' without `()' */ | |
726f6388 | 7230 | |
495aee44 CR |
7231 | /* If we're not in a here document, but we think we're about to parse one, |
7232 | and we would otherwise return a `;', return a newline to delimit the | |
7233 | line with the here-doc delimiter */ | |
7234 | else if ((parser_state & PST_HEREDOC) == 0 && current_command_line_count > 1 && last_read_token == '\n' && strstr (line, "<<")) | |
7235 | { | |
7236 | last_was_heredoc = 1; | |
7237 | return "\n"; | |
7238 | } | |
7239 | ||
f73dda09 JA |
7240 | else if (token_before_that == WORD && two_tokens_ago == FOR) |
7241 | { | |
7242 | /* Tricky. `for i\nin ...' should not have a semicolon, but | |
7243 | `for i\ndo ...' should. We do what we can. */ | |
3185942a | 7244 | for (i = shell_input_line_index; whitespace (shell_input_line[i]); i++) |
f73dda09 JA |
7245 | ; |
7246 | if (shell_input_line[i] && shell_input_line[i] == 'i' && shell_input_line[i+1] == 'n') | |
7247 | return " "; | |
7248 | return ";"; | |
7249 | } | |
95732b49 JA |
7250 | else if (two_tokens_ago == CASE && token_before_that == WORD && (parser_state & PST_CASESTMT)) |
7251 | return " "; | |
726f6388 | 7252 | |
f73dda09 JA |
7253 | for (i = 0; no_semi_successors[i]; i++) |
7254 | { | |
7255 | if (token_before_that == no_semi_successors[i]) | |
7256 | return (" "); | |
7257 | } | |
726f6388 | 7258 | |
f73dda09 JA |
7259 | return ("; "); |
7260 | } | |
7261 | #endif /* HISTORY */ | |
ccc6cda3 | 7262 | |
f73dda09 JA |
7263 | /* Issue a prompt, or prepare to issue a prompt when the next character |
7264 | is read. */ | |
7265 | static void | |
7266 | prompt_again () | |
7267 | { | |
7268 | char *temp_prompt; | |
726f6388 | 7269 | |
0001803f | 7270 | if (interactive == 0 || expanding_alias ()) /* XXX */ |
f73dda09 | 7271 | return; |
726f6388 | 7272 | |
f73dda09 JA |
7273 | ps1_prompt = get_string_value ("PS1"); |
7274 | ps2_prompt = get_string_value ("PS2"); | |
28ef6c31 | 7275 | |
f73dda09 JA |
7276 | if (!prompt_string_pointer) |
7277 | prompt_string_pointer = &ps1_prompt; | |
28ef6c31 | 7278 | |
f73dda09 JA |
7279 | temp_prompt = *prompt_string_pointer |
7280 | ? decode_prompt_string (*prompt_string_pointer) | |
7281 | : (char *)NULL; | |
28ef6c31 | 7282 | |
f73dda09 JA |
7283 | if (temp_prompt == 0) |
7284 | { | |
7285 | temp_prompt = (char *)xmalloc (1); | |
7286 | temp_prompt[0] = '\0'; | |
28ef6c31 | 7287 | } |
28ef6c31 | 7288 | |
f73dda09 JA |
7289 | current_prompt_string = *prompt_string_pointer; |
7290 | prompt_string_pointer = &ps2_prompt; | |
28ef6c31 | 7291 | |
f73dda09 JA |
7292 | #if defined (READLINE) |
7293 | if (!no_line_editing) | |
ccc6cda3 | 7294 | { |
f73dda09 JA |
7295 | FREE (current_readline_prompt); |
7296 | current_readline_prompt = temp_prompt; | |
ccc6cda3 JA |
7297 | } |
7298 | else | |
f73dda09 | 7299 | #endif /* READLINE */ |
ccc6cda3 | 7300 | { |
f73dda09 JA |
7301 | FREE (current_decoded_prompt); |
7302 | current_decoded_prompt = temp_prompt; | |
ccc6cda3 JA |
7303 | } |
7304 | } | |
726f6388 | 7305 | |
28ef6c31 | 7306 | int |
f73dda09 | 7307 | get_current_prompt_level () |
bb70624e | 7308 | { |
f73dda09 | 7309 | return ((current_prompt_string && current_prompt_string == ps2_prompt) ? 2 : 1); |
28ef6c31 | 7310 | } |
bb70624e | 7311 | |
f73dda09 JA |
7312 | void |
7313 | set_current_prompt_level (x) | |
7314 | int x; | |
7315 | { | |
7316 | prompt_string_pointer = (x == 2) ? &ps2_prompt : &ps1_prompt; | |
7317 | current_prompt_string = *prompt_string_pointer; | |
7318 | } | |
7319 | ||
28ef6c31 | 7320 | static void |
f73dda09 | 7321 | print_prompt () |
28ef6c31 | 7322 | { |
f73dda09 JA |
7323 | fprintf (stderr, "%s", current_decoded_prompt); |
7324 | fflush (stderr); | |
7325 | } | |
bb70624e | 7326 | |
f73dda09 JA |
7327 | /* Return a string which will be printed as a prompt. The string |
7328 | may contain special characters which are decoded as follows: | |
726f6388 | 7329 | |
f73dda09 | 7330 | \a bell (ascii 07) |
f73dda09 | 7331 | \d the date in Day Mon Date format |
7117c2d2 | 7332 | \e escape (ascii 033) |
f73dda09 JA |
7333 | \h the hostname up to the first `.' |
7334 | \H the hostname | |
7335 | \j the number of active jobs | |
7336 | \l the basename of the shell's tty device name | |
7337 | \n CRLF | |
7117c2d2 | 7338 | \r CR |
f73dda09 JA |
7339 | \s the name of the shell |
7340 | \t the time in 24-hour hh:mm:ss format | |
7341 | \T the time in 12-hour hh:mm:ss format | |
7117c2d2 JA |
7342 | \@ the time in 12-hour hh:mm am/pm format |
7343 | \A the time in 24-hour hh:mm format | |
7344 | \D{fmt} the result of passing FMT to strftime(3) | |
7345 | \u your username | |
f73dda09 JA |
7346 | \v the version of bash (e.g., 2.00) |
7347 | \V the release of bash, version + patchlevel (e.g., 2.00.0) | |
7348 | \w the current working directory | |
7349 | \W the last element of $PWD | |
f73dda09 | 7350 | \! the history number of this command |
7117c2d2 | 7351 | \# the command number of this command |
f73dda09 JA |
7352 | \$ a $ or a # if you are root |
7353 | \nnn character code nnn in octal | |
7354 | \\ a backslash | |
7355 | \[ begin a sequence of non-printing chars | |
7356 | \] end a sequence of non-printing chars | |
7357 | */ | |
7358 | #define PROMPT_GROWTH 48 | |
7359 | char * | |
7360 | decode_prompt_string (string) | |
7361 | char *string; | |
7362 | { | |
7363 | WORD_LIST *list; | |
7364 | char *result, *t; | |
7365 | struct dstack save_dstack; | |
0001803f | 7366 | int last_exit_value, last_comsub_pid; |
f73dda09 JA |
7367 | #if defined (PROMPT_STRING_DECODE) |
7368 | int result_size, result_index; | |
0628567a | 7369 | int c, n, i; |
f73dda09 | 7370 | char *temp, octal_string[4]; |
7117c2d2 | 7371 | struct tm *tm; |
f73dda09 | 7372 | time_t the_time; |
7117c2d2 JA |
7373 | char timebuf[128]; |
7374 | char *timefmt; | |
726f6388 | 7375 | |
f73dda09 JA |
7376 | result = (char *)xmalloc (result_size = PROMPT_GROWTH); |
7377 | result[result_index = 0] = 0; | |
7378 | temp = (char *)NULL; | |
28ef6c31 | 7379 | |
f73dda09 JA |
7380 | while (c = *string++) |
7381 | { | |
7382 | if (posixly_correct && c == '!') | |
bb70624e | 7383 | { |
f73dda09 | 7384 | if (*string == '!') |
28ef6c31 | 7385 | { |
f73dda09 JA |
7386 | temp = savestring ("!"); |
7387 | goto add_string; | |
7388 | } | |
7389 | else | |
7390 | { | |
7391 | #if !defined (HISTORY) | |
7392 | temp = savestring ("1"); | |
7393 | #else /* HISTORY */ | |
7394 | temp = itos (history_number ()); | |
7395 | #endif /* HISTORY */ | |
7396 | string--; /* add_string increments string again. */ | |
7397 | goto add_string; | |
28ef6c31 | 7398 | } |
28ef6c31 | 7399 | } |
f73dda09 JA |
7400 | if (c == '\\') |
7401 | { | |
7402 | c = *string; | |
726f6388 | 7403 | |
f73dda09 JA |
7404 | switch (c) |
7405 | { | |
7406 | case '0': | |
7407 | case '1': | |
7408 | case '2': | |
7409 | case '3': | |
7410 | case '4': | |
7411 | case '5': | |
7412 | case '6': | |
7413 | case '7': | |
7414 | strncpy (octal_string, string, 3); | |
7415 | octal_string[3] = '\0'; | |
726f6388 | 7416 | |
f73dda09 JA |
7417 | n = read_octal (octal_string); |
7418 | temp = (char *)xmalloc (3); | |
726f6388 | 7419 | |
f73dda09 JA |
7420 | if (n == CTLESC || n == CTLNUL) |
7421 | { | |
7422 | temp[0] = CTLESC; | |
7423 | temp[1] = n; | |
7424 | temp[2] = '\0'; | |
7425 | } | |
7426 | else if (n == -1) | |
7427 | { | |
7428 | temp[0] = '\\'; | |
7429 | temp[1] = '\0'; | |
7430 | } | |
7431 | else | |
7432 | { | |
7433 | temp[0] = n; | |
7434 | temp[1] = '\0'; | |
7435 | } | |
28ef6c31 | 7436 | |
f73dda09 JA |
7437 | for (c = 0; n != -1 && c < 3 && ISOCTAL (*string); c++) |
7438 | string++; | |
28ef6c31 | 7439 | |
7117c2d2 | 7440 | c = 0; /* tested at add_string: */ |
f73dda09 | 7441 | goto add_string; |
28ef6c31 | 7442 | |
f73dda09 | 7443 | case 'd': |
7117c2d2 | 7444 | case 't': |
f73dda09 JA |
7445 | case 'T': |
7446 | case '@': | |
7447 | case 'A': | |
7448 | /* Make the current time/date into a string. */ | |
7117c2d2 JA |
7449 | (void) time (&the_time); |
7450 | tm = localtime (&the_time); | |
7451 | ||
7452 | if (c == 'd') | |
7453 | n = strftime (timebuf, sizeof (timebuf), "%a %b %d", tm); | |
7454 | else if (c == 't') | |
7455 | n = strftime (timebuf, sizeof (timebuf), "%H:%M:%S", tm); | |
7456 | else if (c == 'T') | |
7457 | n = strftime (timebuf, sizeof (timebuf), "%I:%M:%S", tm); | |
7458 | else if (c == '@') | |
7459 | n = strftime (timebuf, sizeof (timebuf), "%I:%M %p", tm); | |
7460 | else if (c == 'A') | |
7461 | n = strftime (timebuf, sizeof (timebuf), "%H:%M", tm); | |
7462 | ||
b80f6443 JA |
7463 | if (n == 0) |
7464 | timebuf[0] = '\0'; | |
7465 | else | |
7466 | timebuf[sizeof(timebuf) - 1] = '\0'; | |
7467 | ||
7117c2d2 JA |
7468 | temp = savestring (timebuf); |
7469 | goto add_string; | |
726f6388 | 7470 | |
7117c2d2 JA |
7471 | case 'D': /* strftime format */ |
7472 | if (string[1] != '{') /* } */ | |
7473 | goto not_escape; | |
726f6388 | 7474 | |
7117c2d2 JA |
7475 | (void) time (&the_time); |
7476 | tm = localtime (&the_time); | |
7477 | string += 2; /* skip { */ | |
7478 | timefmt = xmalloc (strlen (string) + 3); | |
7479 | for (t = timefmt; *string && *string != '}'; ) | |
7480 | *t++ = *string++; | |
7481 | *t = '\0'; | |
7482 | c = *string; /* tested at add_string */ | |
7483 | if (timefmt[0] == '\0') | |
f73dda09 | 7484 | { |
7117c2d2 JA |
7485 | timefmt[0] = '%'; |
7486 | timefmt[1] = 'X'; /* locale-specific current time */ | |
7487 | timefmt[2] = '\0'; | |
f73dda09 | 7488 | } |
7117c2d2 JA |
7489 | n = strftime (timebuf, sizeof (timebuf), timefmt, tm); |
7490 | free (timefmt); | |
7491 | ||
b80f6443 JA |
7492 | if (n == 0) |
7493 | timebuf[0] = '\0'; | |
7494 | else | |
7495 | timebuf[sizeof(timebuf) - 1] = '\0'; | |
7496 | ||
7117c2d2 JA |
7497 | if (promptvars || posixly_correct) |
7498 | /* Make sure that expand_prompt_string is called with a | |
7499 | second argument of Q_DOUBLE_QUOTES if we use this | |
7500 | function here. */ | |
7501 | temp = sh_backslash_quote_for_double_quotes (timebuf); | |
7502 | else | |
7503 | temp = savestring (timebuf); | |
f73dda09 | 7504 | goto add_string; |
7117c2d2 | 7505 | |
f73dda09 JA |
7506 | case 'n': |
7507 | temp = (char *)xmalloc (3); | |
7508 | temp[0] = no_line_editing ? '\n' : '\r'; | |
7509 | temp[1] = no_line_editing ? '\0' : '\n'; | |
7510 | temp[2] = '\0'; | |
7511 | goto add_string; | |
ccc6cda3 | 7512 | |
f73dda09 JA |
7513 | case 's': |
7514 | temp = base_pathname (shell_name); | |
7515 | temp = savestring (temp); | |
7516 | goto add_string; | |
726f6388 | 7517 | |
f73dda09 JA |
7518 | case 'v': |
7519 | case 'V': | |
7117c2d2 | 7520 | temp = (char *)xmalloc (16); |
f73dda09 JA |
7521 | if (c == 'v') |
7522 | strcpy (temp, dist_version); | |
7523 | else | |
7524 | sprintf (temp, "%s.%d", dist_version, patch_level); | |
7525 | goto add_string; | |
bb70624e | 7526 | |
f73dda09 JA |
7527 | case 'w': |
7528 | case 'W': | |
7529 | { | |
7530 | /* Use the value of PWD because it is much more efficient. */ | |
0628567a | 7531 | char t_string[PATH_MAX]; |
f73dda09 | 7532 | int tlen; |
28ef6c31 | 7533 | |
f73dda09 | 7534 | temp = get_string_value ("PWD"); |
ccc6cda3 | 7535 | |
f73dda09 JA |
7536 | if (temp == 0) |
7537 | { | |
7538 | if (getcwd (t_string, sizeof(t_string)) == 0) | |
7539 | { | |
7540 | t_string[0] = '.'; | |
7541 | tlen = 1; | |
7542 | } | |
7543 | else | |
7544 | tlen = strlen (t_string); | |
7545 | } | |
7546 | else | |
7547 | { | |
7548 | tlen = sizeof (t_string) - 1; | |
7549 | strncpy (t_string, temp, tlen); | |
7550 | } | |
7551 | t_string[tlen] = '\0'; | |
726f6388 | 7552 | |
0001803f CR |
7553 | #if defined (MACOSX) |
7554 | /* Convert from "fs" format to "input" format */ | |
7555 | temp = fnx_fromfs (t_string, strlen (t_string)); | |
7556 | if (temp != t_string) | |
7557 | strcpy (t_string, temp); | |
7558 | #endif | |
7559 | ||
f73dda09 JA |
7560 | #define ROOT_PATH(x) ((x)[0] == '/' && (x)[1] == 0) |
7561 | #define DOUBLE_SLASH_ROOT(x) ((x)[0] == '/' && (x)[1] == '/' && (x)[2] == 0) | |
b80f6443 | 7562 | /* Abbreviate \W as ~ if $PWD == $HOME */ |
95732b49 | 7563 | if (c == 'W' && (((t = get_string_value ("HOME")) == 0) || STREQ (t, t_string) == 0)) |
f73dda09 JA |
7564 | { |
7565 | if (ROOT_PATH (t_string) == 0 && DOUBLE_SLASH_ROOT (t_string) == 0) | |
7566 | { | |
7567 | t = strrchr (t_string, '/'); | |
7568 | if (t) | |
495aee44 | 7569 | memmove (t_string, t + 1, strlen (t)); /* strlen(t) to copy NULL */ |
f73dda09 JA |
7570 | } |
7571 | } | |
7572 | #undef ROOT_PATH | |
7573 | #undef DOUBLE_SLASH_ROOT | |
7574 | else | |
7575 | /* polite_directory_format is guaranteed to return a string | |
7576 | no longer than PATH_MAX - 1 characters. */ | |
7577 | strcpy (t_string, polite_directory_format (t_string)); | |
726f6388 | 7578 | |
3185942a | 7579 | temp = trim_pathname (t_string, PATH_MAX - 1); |
f73dda09 JA |
7580 | /* If we're going to be expanding the prompt string later, |
7581 | quote the directory name. */ | |
7582 | if (promptvars || posixly_correct) | |
7583 | /* Make sure that expand_prompt_string is called with a | |
7117c2d2 | 7584 | second argument of Q_DOUBLE_QUOTES if we use this |
f73dda09 JA |
7585 | function here. */ |
7586 | temp = sh_backslash_quote_for_double_quotes (t_string); | |
7587 | else | |
7588 | temp = savestring (t_string); | |
726f6388 | 7589 | |
f73dda09 JA |
7590 | goto add_string; |
7591 | } | |
726f6388 | 7592 | |
f73dda09 JA |
7593 | case 'u': |
7594 | if (current_user.user_name == 0) | |
7595 | get_current_user_info (); | |
7596 | temp = savestring (current_user.user_name); | |
7597 | goto add_string; | |
726f6388 | 7598 | |
f73dda09 JA |
7599 | case 'h': |
7600 | case 'H': | |
7601 | temp = savestring (current_host_name); | |
7602 | if (c == 'h' && (t = (char *)strchr (temp, '.'))) | |
7603 | *t = '\0'; | |
7604 | goto add_string; | |
726f6388 | 7605 | |
f73dda09 JA |
7606 | case '#': |
7607 | temp = itos (current_command_number); | |
7608 | goto add_string; | |
28ef6c31 | 7609 | |
f73dda09 JA |
7610 | case '!': |
7611 | #if !defined (HISTORY) | |
7612 | temp = savestring ("1"); | |
7613 | #else /* HISTORY */ | |
7614 | temp = itos (history_number ()); | |
7615 | #endif /* HISTORY */ | |
7616 | goto add_string; | |
726f6388 | 7617 | |
f73dda09 JA |
7618 | case '$': |
7619 | t = temp = (char *)xmalloc (3); | |
7620 | if ((promptvars || posixly_correct) && (current_user.euid != 0)) | |
7621 | *t++ = '\\'; | |
7622 | *t++ = current_user.euid == 0 ? '#' : '$'; | |
7623 | *t = '\0'; | |
7624 | goto add_string; | |
726f6388 | 7625 | |
f73dda09 JA |
7626 | case 'j': |
7627 | temp = itos (count_all_jobs ()); | |
7628 | goto add_string; | |
28ef6c31 | 7629 | |
f73dda09 JA |
7630 | case 'l': |
7631 | #if defined (HAVE_TTYNAME) | |
7632 | temp = (char *)ttyname (fileno (stdin)); | |
7633 | t = temp ? base_pathname (temp) : "tty"; | |
7634 | temp = savestring (t); | |
7635 | #else | |
7636 | temp = savestring ("tty"); | |
7637 | #endif /* !HAVE_TTYNAME */ | |
7638 | goto add_string; | |
726f6388 | 7639 | |
f73dda09 JA |
7640 | #if defined (READLINE) |
7641 | case '[': | |
7642 | case ']': | |
b80f6443 JA |
7643 | if (no_line_editing) |
7644 | { | |
7645 | string++; | |
7646 | break; | |
7647 | } | |
f73dda09 | 7648 | temp = (char *)xmalloc (3); |
0628567a JA |
7649 | n = (c == '[') ? RL_PROMPT_START_IGNORE : RL_PROMPT_END_IGNORE; |
7650 | i = 0; | |
7651 | if (n == CTLESC || n == CTLNUL) | |
7652 | temp[i++] = CTLESC; | |
7653 | temp[i++] = n; | |
7654 | temp[i] = '\0'; | |
f73dda09 JA |
7655 | goto add_string; |
7656 | #endif /* READLINE */ | |
ccc6cda3 | 7657 | |
f73dda09 | 7658 | case '\\': |
f73dda09 JA |
7659 | case 'a': |
7660 | case 'e': | |
7117c2d2 | 7661 | case 'r': |
f73dda09 | 7662 | temp = (char *)xmalloc (2); |
7117c2d2 JA |
7663 | if (c == 'a') |
7664 | temp[0] = '\07'; | |
7665 | else if (c == 'e') | |
7666 | temp[0] = '\033'; | |
7667 | else if (c == 'r') | |
7668 | temp[0] = '\r'; | |
7669 | else /* (c == '\\') */ | |
7670 | temp[0] = c; | |
f73dda09 JA |
7671 | temp[1] = '\0'; |
7672 | goto add_string; | |
7673 | ||
7674 | default: | |
7117c2d2 | 7675 | not_escape: |
f73dda09 JA |
7676 | temp = (char *)xmalloc (3); |
7677 | temp[0] = '\\'; | |
7678 | temp[1] = c; | |
7679 | temp[2] = '\0'; | |
7680 | ||
7681 | add_string: | |
7682 | if (c) | |
7683 | string++; | |
7684 | result = | |
7685 | sub_append_string (temp, result, &result_index, &result_size); | |
7686 | temp = (char *)NULL; /* Freed in sub_append_string (). */ | |
7687 | result[result_index] = '\0'; | |
7688 | break; | |
7689 | } | |
7690 | } | |
7691 | else | |
7692 | { | |
7693 | RESIZE_MALLOCED_BUFFER (result, result_index, 3, result_size, PROMPT_GROWTH); | |
7694 | result[result_index++] = c; | |
7695 | result[result_index] = '\0'; | |
7696 | } | |
7697 | } | |
7698 | #else /* !PROMPT_STRING_DECODE */ | |
7699 | result = savestring (string); | |
7700 | #endif /* !PROMPT_STRING_DECODE */ | |
7701 | ||
7702 | /* Save the delimiter stack and point `dstack' to temp space so any | |
7703 | command substitutions in the prompt string won't result in screwing | |
7704 | up the parser's quoting state. */ | |
7705 | save_dstack = dstack; | |
7706 | dstack = temp_dstack; | |
7707 | dstack.delimiter_depth = 0; | |
7708 | ||
7709 | /* Perform variable and parameter expansion and command substitution on | |
7710 | the prompt string. */ | |
7711 | if (promptvars || posixly_correct) | |
7712 | { | |
7713 | last_exit_value = last_command_exit_value; | |
0001803f | 7714 | last_comsub_pid = last_command_subst_pid; |
3185942a | 7715 | list = expand_prompt_string (result, Q_DOUBLE_QUOTES, 0); |
f73dda09 JA |
7716 | free (result); |
7717 | result = string_list (list); | |
7718 | dispose_words (list); | |
7719 | last_command_exit_value = last_exit_value; | |
0001803f | 7720 | last_command_subst_pid = last_comsub_pid; |
f73dda09 JA |
7721 | } |
7722 | else | |
7723 | { | |
7724 | t = dequote_string (result); | |
7725 | free (result); | |
7726 | result = t; | |
7727 | } | |
7728 | ||
7729 | dstack = save_dstack; | |
7730 | ||
7731 | return (result); | |
7732 | } | |
7733 | ||
7117c2d2 JA |
7734 | /************************************************ |
7735 | * * | |
7736 | * ERROR HANDLING * | |
7737 | * * | |
7738 | ************************************************/ | |
7739 | ||
f73dda09 JA |
7740 | /* Report a syntax error, and restart the parser. Call here for fatal |
7741 | errors. */ | |
7742 | int | |
7743 | yyerror (msg) | |
7744 | const char *msg; | |
726f6388 | 7745 | { |
f73dda09 JA |
7746 | report_syntax_error ((char *)NULL); |
7747 | reset_parser (); | |
7748 | return (0); | |
7749 | } | |
7750 | ||
7117c2d2 | 7751 | static char * |
0628567a JA |
7752 | error_token_from_token (tok) |
7753 | int tok; | |
7117c2d2 JA |
7754 | { |
7755 | char *t; | |
7756 | ||
0628567a | 7757 | if (t = find_token_in_alist (tok, word_token_alist, 0)) |
7117c2d2 JA |
7758 | return t; |
7759 | ||
0628567a | 7760 | if (t = find_token_in_alist (tok, other_token_alist, 0)) |
7117c2d2 JA |
7761 | return t; |
7762 | ||
7763 | t = (char *)NULL; | |
7764 | /* This stuff is dicy and needs closer inspection */ | |
7765 | switch (current_token) | |
7766 | { | |
7767 | case WORD: | |
7768 | case ASSIGNMENT_WORD: | |
7769 | if (yylval.word) | |
7770 | t = savestring (yylval.word->word); | |
7771 | break; | |
7772 | case NUMBER: | |
7773 | t = itos (yylval.number); | |
7774 | break; | |
7775 | case ARITH_CMD: | |
7776 | if (yylval.word_list) | |
7777 | t = string_list (yylval.word_list); | |
7778 | break; | |
7779 | case ARITH_FOR_EXPRS: | |
7780 | if (yylval.word_list) | |
7781 | t = string_list_internal (yylval.word_list, " ; "); | |
7782 | break; | |
7783 | case COND_CMD: | |
7784 | t = (char *)NULL; /* punt */ | |
7785 | break; | |
7786 | } | |
7787 | ||
7788 | return t; | |
7789 | } | |
7790 | ||
7791 | static char * | |
7792 | error_token_from_text () | |
7793 | { | |
7794 | char *msg, *t; | |
7795 | int token_end, i; | |
7796 | ||
7797 | t = shell_input_line; | |
7798 | i = shell_input_line_index; | |
7799 | token_end = 0; | |
7800 | msg = (char *)NULL; | |
7801 | ||
7802 | if (i && t[i] == '\0') | |
7803 | i--; | |
7804 | ||
7805 | while (i && (whitespace (t[i]) || t[i] == '\n')) | |
7806 | i--; | |
7807 | ||
7808 | if (i) | |
7809 | token_end = i + 1; | |
7810 | ||
7811 | while (i && (member (t[i], " \n\t;|&") == 0)) | |
7812 | i--; | |
7813 | ||
7814 | while (i != token_end && (whitespace (t[i]) || t[i] == '\n')) | |
7815 | i++; | |
7816 | ||
7817 | /* Return our idea of the offending token. */ | |
7818 | if (token_end || (i == 0 && token_end == 0)) | |
7819 | { | |
7820 | if (token_end) | |
7821 | msg = substring (t, i, token_end); | |
7822 | else /* one-character token */ | |
7823 | { | |
7824 | msg = (char *)xmalloc (2); | |
7825 | msg[0] = t[i]; | |
7826 | msg[1] = '\0'; | |
7827 | } | |
7828 | } | |
7829 | ||
7830 | return (msg); | |
7831 | } | |
7832 | ||
7833 | static void | |
7834 | print_offending_line () | |
7835 | { | |
7836 | char *msg; | |
7837 | int token_end; | |
7838 | ||
7839 | msg = savestring (shell_input_line); | |
7840 | token_end = strlen (msg); | |
7841 | while (token_end && msg[token_end - 1] == '\n') | |
7842 | msg[--token_end] = '\0'; | |
7843 | ||
7844 | parser_error (line_number, "`%s'", msg); | |
7845 | free (msg); | |
7846 | } | |
7847 | ||
f73dda09 JA |
7848 | /* Report a syntax error with line numbers, etc. |
7849 | Call here for recoverable errors. If you have a message to print, | |
7850 | then place it in MESSAGE, otherwise pass NULL and this will figure | |
7851 | out an appropriate message for you. */ | |
7852 | static void | |
7853 | report_syntax_error (message) | |
7854 | char *message; | |
726f6388 | 7855 | { |
495aee44 | 7856 | char *msg, *p; |
f73dda09 JA |
7857 | |
7858 | if (message) | |
7859 | { | |
7860 | parser_error (line_number, "%s", message); | |
7861 | if (interactive && EOF_Reached) | |
7862 | EOF_Reached = 0; | |
0001803f | 7863 | last_command_exit_value = parse_and_execute_level ? EX_BADSYNTAX : EX_BADUSAGE; |
f73dda09 JA |
7864 | return; |
7865 | } | |
7866 | ||
7867 | /* If the line of input we're reading is not null, try to find the | |
7117c2d2 JA |
7868 | objectionable token. First, try to figure out what token the |
7869 | parser's complaining about by looking at current_token. */ | |
7870 | if (current_token != 0 && EOF_Reached == 0 && (msg = error_token_from_token (current_token))) | |
f73dda09 | 7871 | { |
495aee44 CR |
7872 | if (ansic_shouldquote (msg)) |
7873 | { | |
7874 | p = ansic_quote (msg, 0, NULL); | |
7875 | free (msg); | |
7876 | msg = p; | |
7877 | } | |
b80f6443 | 7878 | parser_error (line_number, _("syntax error near unexpected token `%s'"), msg); |
7117c2d2 | 7879 | free (msg); |
f73dda09 | 7880 | |
7117c2d2 JA |
7881 | if (interactive == 0) |
7882 | print_offending_line (); | |
f73dda09 | 7883 | |
0001803f | 7884 | last_command_exit_value = parse_and_execute_level ? EX_BADSYNTAX : EX_BADUSAGE; |
7117c2d2 JA |
7885 | return; |
7886 | } | |
f73dda09 | 7887 | |
7117c2d2 JA |
7888 | /* If looking at the current token doesn't prove fruitful, try to find the |
7889 | offending token by analyzing the text of the input line near the current | |
7890 | input line index and report what we find. */ | |
7891 | if (shell_input_line && *shell_input_line) | |
7892 | { | |
7893 | msg = error_token_from_text (); | |
7894 | if (msg) | |
f73dda09 | 7895 | { |
b80f6443 | 7896 | parser_error (line_number, _("syntax error near `%s'"), msg); |
7117c2d2 | 7897 | free (msg); |
f73dda09 JA |
7898 | } |
7899 | ||
7900 | /* If not interactive, print the line containing the error. */ | |
7901 | if (interactive == 0) | |
7117c2d2 | 7902 | print_offending_line (); |
f73dda09 JA |
7903 | } |
7904 | else | |
7905 | { | |
b80f6443 | 7906 | msg = EOF_Reached ? _("syntax error: unexpected end of file") : _("syntax error"); |
f73dda09 JA |
7907 | parser_error (line_number, "%s", msg); |
7908 | /* When the shell is interactive, this file uses EOF_Reached | |
7909 | only for error reporting. Other mechanisms are used to | |
7910 | decide whether or not to exit. */ | |
7911 | if (interactive && EOF_Reached) | |
7912 | EOF_Reached = 0; | |
7913 | } | |
7117c2d2 | 7914 | |
0001803f | 7915 | last_command_exit_value = parse_and_execute_level ? EX_BADSYNTAX : EX_BADUSAGE; |
f73dda09 JA |
7916 | } |
7917 | ||
7918 | /* ??? Needed function. ??? We have to be able to discard the constructs | |
7919 | created during parsing. In the case of error, we want to return | |
7920 | allocated objects to the memory pool. In the case of no error, we want | |
7921 | to throw away the information about where the allocated objects live. | |
7117c2d2 | 7922 | (dispose_command () will actually free the command.) */ |
f73dda09 JA |
7923 | static void |
7924 | discard_parser_constructs (error_p) | |
7925 | int error_p; | |
28ef6c31 | 7926 | { |
f73dda09 JA |
7927 | } |
7928 | ||
7117c2d2 JA |
7929 | /************************************************ |
7930 | * * | |
7931 | * EOF HANDLING * | |
7932 | * * | |
7933 | ************************************************/ | |
7934 | ||
f73dda09 JA |
7935 | /* Do that silly `type "bye" to exit' stuff. You know, "ignoreeof". */ |
7936 | ||
7937 | /* A flag denoting whether or not ignoreeof is set. */ | |
7938 | int ignoreeof = 0; | |
7939 | ||
7940 | /* The number of times that we have encountered an EOF character without | |
7941 | another character intervening. When this gets above the limit, the | |
7942 | shell terminates. */ | |
7943 | int eof_encountered = 0; | |
7944 | ||
7945 | /* The limit for eof_encountered. */ | |
7946 | int eof_encountered_limit = 10; | |
7947 | ||
7948 | /* If we have EOF as the only input unit, this user wants to leave | |
7949 | the shell. If the shell is not interactive, then just leave. | |
7950 | Otherwise, if ignoreeof is set, and we haven't done this the | |
7951 | required number of times in a row, print a message. */ | |
7952 | static void | |
7953 | handle_eof_input_unit () | |
28ef6c31 | 7954 | { |
f73dda09 JA |
7955 | if (interactive) |
7956 | { | |
7957 | /* shell.c may use this to decide whether or not to write out the | |
7958 | history, among other things. We use it only for error reporting | |
7959 | in this file. */ | |
7960 | if (EOF_Reached) | |
7961 | EOF_Reached = 0; | |
7962 | ||
7963 | /* If the user wants to "ignore" eof, then let her do so, kind of. */ | |
7964 | if (ignoreeof) | |
7965 | { | |
7966 | if (eof_encountered < eof_encountered_limit) | |
7967 | { | |
b80f6443 | 7968 | fprintf (stderr, _("Use \"%s\" to leave the shell.\n"), |
f73dda09 JA |
7969 | login_shell ? "logout" : "exit"); |
7970 | eof_encountered++; | |
7117c2d2 JA |
7971 | /* Reset the parsing state. */ |
7972 | last_read_token = current_token = '\n'; | |
f73dda09 JA |
7973 | /* Reset the prompt string to be $PS1. */ |
7974 | prompt_string_pointer = (char **)NULL; | |
7975 | prompt_again (); | |
f73dda09 JA |
7976 | return; |
7977 | } | |
7978 | } | |
7979 | ||
7980 | /* In this case EOF should exit the shell. Do it now. */ | |
7981 | reset_parser (); | |
7982 | exit_builtin ((WORD_LIST *)NULL); | |
726f6388 | 7983 | } |
f73dda09 | 7984 | else |
726f6388 | 7985 | { |
f73dda09 JA |
7986 | /* We don't write history files, etc., for non-interactive shells. */ |
7987 | EOF_Reached = 1; | |
7988 | } | |
7989 | } | |
7990 | ||
7117c2d2 JA |
7991 | /************************************************ |
7992 | * * | |
7993 | * STRING PARSING FUNCTIONS * | |
7994 | * * | |
7995 | ************************************************/ | |
7996 | ||
7997 | /* It's very important that these two functions treat the characters | |
7998 | between ( and ) identically. */ | |
7999 | ||
f73dda09 JA |
8000 | static WORD_LIST parse_string_error; |
8001 | ||
8002 | /* Take a string and run it through the shell parser, returning the | |
8003 | resultant word list. Used by compound array assignment. */ | |
8004 | WORD_LIST * | |
b80f6443 | 8005 | parse_string_to_word_list (s, flags, whom) |
f73dda09 | 8006 | char *s; |
b80f6443 | 8007 | int flags; |
f73dda09 JA |
8008 | const char *whom; |
8009 | { | |
8010 | WORD_LIST *wl; | |
7117c2d2 | 8011 | int tok, orig_current_token, orig_line_number, orig_input_terminator; |
f73dda09 | 8012 | int orig_line_count; |
7117c2d2 | 8013 | int old_echo_input, old_expand_aliases; |
f73dda09 JA |
8014 | #if defined (HISTORY) |
8015 | int old_remember_on_history, old_history_expansion_inhibited; | |
bb70624e | 8016 | #endif |
f73dda09 JA |
8017 | |
8018 | #if defined (HISTORY) | |
8019 | old_remember_on_history = remember_on_history; | |
8020 | # if defined (BANG_HISTORY) | |
8021 | old_history_expansion_inhibited = history_expansion_inhibited; | |
8022 | # endif | |
8023 | bash_history_disable (); | |
bb70624e | 8024 | #endif |
f73dda09 JA |
8025 | |
8026 | orig_line_number = line_number; | |
8027 | orig_line_count = current_command_line_count; | |
8028 | orig_input_terminator = shell_input_line_terminator; | |
7117c2d2 JA |
8029 | old_echo_input = echo_input_at_read; |
8030 | old_expand_aliases = expand_aliases; | |
f73dda09 JA |
8031 | |
8032 | push_stream (1); | |
7117c2d2 | 8033 | last_read_token = WORD; /* WORD to allow reserved words here */ |
f73dda09 | 8034 | current_command_line_count = 0; |
7117c2d2 | 8035 | echo_input_at_read = expand_aliases = 0; |
f73dda09 JA |
8036 | |
8037 | with_input_from_string (s, whom); | |
8038 | wl = (WORD_LIST *)NULL; | |
b80f6443 JA |
8039 | |
8040 | if (flags & 1) | |
3185942a | 8041 | parser_state |= PST_COMPASSIGN|PST_REPARSE; |
b80f6443 | 8042 | |
f73dda09 JA |
8043 | while ((tok = read_token (READ)) != yacc_EOF) |
8044 | { | |
8045 | if (tok == '\n' && *bash_input.location.string == '\0') | |
8046 | break; | |
8047 | if (tok == '\n') /* Allow newlines in compound assignments */ | |
8048 | continue; | |
8049 | if (tok != WORD && tok != ASSIGNMENT_WORD) | |
8050 | { | |
8051 | line_number = orig_line_number + line_number - 1; | |
7117c2d2 JA |
8052 | orig_current_token = current_token; |
8053 | current_token = tok; | |
95732b49 | 8054 | yyerror (NULL); /* does the right thing */ |
7117c2d2 | 8055 | current_token = orig_current_token; |
f73dda09 JA |
8056 | if (wl) |
8057 | dispose_words (wl); | |
8058 | wl = &parse_string_error; | |
8059 | break; | |
8060 | } | |
8061 | wl = make_word_list (yylval.word, wl); | |
bb70624e | 8062 | } |
f73dda09 JA |
8063 | |
8064 | last_read_token = '\n'; | |
8065 | pop_stream (); | |
8066 | ||
8067 | #if defined (HISTORY) | |
8068 | remember_on_history = old_remember_on_history; | |
8069 | # if defined (BANG_HISTORY) | |
8070 | history_expansion_inhibited = old_history_expansion_inhibited; | |
8071 | # endif /* BANG_HISTORY */ | |
8072 | #endif /* HISTORY */ | |
8073 | ||
7117c2d2 JA |
8074 | echo_input_at_read = old_echo_input; |
8075 | expand_aliases = old_expand_aliases; | |
8076 | ||
f73dda09 JA |
8077 | current_command_line_count = orig_line_count; |
8078 | shell_input_line_terminator = orig_input_terminator; | |
8079 | ||
b80f6443 | 8080 | if (flags & 1) |
3185942a | 8081 | parser_state &= ~(PST_COMPASSIGN|PST_REPARSE); |
b80f6443 | 8082 | |
f73dda09 | 8083 | if (wl == &parse_string_error) |
bb70624e | 8084 | { |
f73dda09 JA |
8085 | last_command_exit_value = EXECUTION_FAILURE; |
8086 | if (interactive_shell == 0 && posixly_correct) | |
8087 | jump_to_top_level (FORCE_EOF); | |
8088 | else | |
8089 | jump_to_top_level (DISCARD); | |
bb70624e | 8090 | } |
f73dda09 JA |
8091 | |
8092 | return (REVERSE_LIST (wl, WORD_LIST *)); | |
bb70624e | 8093 | } |
7117c2d2 JA |
8094 | |
8095 | static char * | |
8096 | parse_compound_assignment (retlenp) | |
8097 | int *retlenp; | |
8098 | { | |
8099 | WORD_LIST *wl, *rl; | |
0628567a | 8100 | int tok, orig_line_number, orig_token_size, orig_last_token, assignok; |
7117c2d2 JA |
8101 | char *saved_token, *ret; |
8102 | ||
8103 | saved_token = token; | |
8104 | orig_token_size = token_buffer_size; | |
8105 | orig_line_number = line_number; | |
0628567a | 8106 | orig_last_token = last_read_token; |
7117c2d2 JA |
8107 | |
8108 | last_read_token = WORD; /* WORD to allow reserved words here */ | |
8109 | ||
8110 | token = (char *)NULL; | |
8111 | token_buffer_size = 0; | |
8112 | ||
0628567a JA |
8113 | assignok = parser_state&PST_ASSIGNOK; /* XXX */ |
8114 | ||
7117c2d2 | 8115 | wl = (WORD_LIST *)NULL; /* ( */ |
b80f6443 JA |
8116 | parser_state |= PST_COMPASSIGN; |
8117 | ||
7117c2d2 JA |
8118 | while ((tok = read_token (READ)) != ')') |
8119 | { | |
8120 | if (tok == '\n') /* Allow newlines in compound assignments */ | |
b80f6443 JA |
8121 | { |
8122 | if (SHOULD_PROMPT ()) | |
8123 | prompt_again (); | |
8124 | continue; | |
8125 | } | |
7117c2d2 JA |
8126 | if (tok != WORD && tok != ASSIGNMENT_WORD) |
8127 | { | |
8128 | current_token = tok; /* for error reporting */ | |
8129 | if (tok == yacc_EOF) /* ( */ | |
b80f6443 | 8130 | parser_error (orig_line_number, _("unexpected EOF while looking for matching `)'")); |
7117c2d2 | 8131 | else |
95732b49 | 8132 | yyerror(NULL); /* does the right thing */ |
7117c2d2 JA |
8133 | if (wl) |
8134 | dispose_words (wl); | |
8135 | wl = &parse_string_error; | |
8136 | break; | |
8137 | } | |
8138 | wl = make_word_list (yylval.word, wl); | |
8139 | } | |
8140 | ||
8141 | FREE (token); | |
8142 | token = saved_token; | |
8143 | token_buffer_size = orig_token_size; | |
8144 | ||
b80f6443 JA |
8145 | parser_state &= ~PST_COMPASSIGN; |
8146 | ||
7117c2d2 JA |
8147 | if (wl == &parse_string_error) |
8148 | { | |
8149 | last_command_exit_value = EXECUTION_FAILURE; | |
8150 | last_read_token = '\n'; /* XXX */ | |
8151 | if (interactive_shell == 0 && posixly_correct) | |
8152 | jump_to_top_level (FORCE_EOF); | |
8153 | else | |
8154 | jump_to_top_level (DISCARD); | |
8155 | } | |
8156 | ||
0628567a JA |
8157 | last_read_token = orig_last_token; /* XXX - was WORD? */ |
8158 | ||
7117c2d2 JA |
8159 | if (wl) |
8160 | { | |
8161 | rl = REVERSE_LIST (wl, WORD_LIST *); | |
8162 | ret = string_list (rl); | |
8163 | dispose_words (rl); | |
8164 | } | |
8165 | else | |
8166 | ret = (char *)NULL; | |
8167 | ||
8168 | if (retlenp) | |
8169 | *retlenp = (ret && *ret) ? strlen (ret) : 0; | |
0628567a JA |
8170 | |
8171 | if (assignok) | |
8172 | parser_state |= PST_ASSIGNOK; | |
8173 | ||
7117c2d2 JA |
8174 | return ret; |
8175 | } | |
8176 | ||
b80f6443 JA |
8177 | /************************************************ |
8178 | * * | |
8179 | * SAVING AND RESTORING PARTIAL PARSE STATE * | |
8180 | * * | |
8181 | ************************************************/ | |
8182 | ||
8183 | sh_parser_state_t * | |
8184 | save_parser_state (ps) | |
8185 | sh_parser_state_t *ps; | |
8186 | { | |
b80f6443 | 8187 | if (ps == 0) |
95732b49 | 8188 | ps = (sh_parser_state_t *)xmalloc (sizeof (sh_parser_state_t)); |
b80f6443 JA |
8189 | if (ps == 0) |
8190 | return ((sh_parser_state_t *)NULL); | |
8191 | ||
8192 | ps->parser_state = parser_state; | |
8193 | ps->token_state = save_token_state (); | |
8194 | ||
8195 | ps->input_line_terminator = shell_input_line_terminator; | |
8196 | ps->eof_encountered = eof_encountered; | |
8197 | ||
495aee44 CR |
8198 | ps->prompt_string_pointer = prompt_string_pointer; |
8199 | ||
b80f6443 JA |
8200 | ps->current_command_line_count = current_command_line_count; |
8201 | ||
8202 | #if defined (HISTORY) | |
8203 | ps->remember_on_history = remember_on_history; | |
8204 | # if defined (BANG_HISTORY) | |
8205 | ps->history_expansion_inhibited = history_expansion_inhibited; | |
8206 | # endif | |
8207 | #endif | |
8208 | ||
8209 | ps->last_command_exit_value = last_command_exit_value; | |
8210 | #if defined (ARRAY_VARS) | |
495aee44 | 8211 | ps->pipestatus = save_pipestatus_array (); |
b80f6443 JA |
8212 | #endif |
8213 | ||
8214 | ps->last_shell_builtin = last_shell_builtin; | |
8215 | ps->this_shell_builtin = this_shell_builtin; | |
8216 | ||
8217 | ps->expand_aliases = expand_aliases; | |
8218 | ps->echo_input_at_read = echo_input_at_read; | |
8219 | ||
8220 | return (ps); | |
8221 | } | |
8222 | ||
8223 | void | |
8224 | restore_parser_state (ps) | |
8225 | sh_parser_state_t *ps; | |
8226 | { | |
b80f6443 JA |
8227 | if (ps == 0) |
8228 | return; | |
8229 | ||
8230 | parser_state = ps->parser_state; | |
8231 | if (ps->token_state) | |
8232 | { | |
8233 | restore_token_state (ps->token_state); | |
8234 | free (ps->token_state); | |
8235 | } | |
8236 | ||
8237 | shell_input_line_terminator = ps->input_line_terminator; | |
8238 | eof_encountered = ps->eof_encountered; | |
8239 | ||
495aee44 CR |
8240 | prompt_string_pointer = ps->prompt_string_pointer; |
8241 | ||
b80f6443 JA |
8242 | current_command_line_count = ps->current_command_line_count; |
8243 | ||
8244 | #if defined (HISTORY) | |
8245 | remember_on_history = ps->remember_on_history; | |
8246 | # if defined (BANG_HISTORY) | |
8247 | history_expansion_inhibited = ps->history_expansion_inhibited; | |
8248 | # endif | |
8249 | #endif | |
8250 | ||
8251 | last_command_exit_value = ps->last_command_exit_value; | |
8252 | #if defined (ARRAY_VARS) | |
495aee44 | 8253 | restore_pipestatus_array (ps->pipestatus); |
b80f6443 JA |
8254 | #endif |
8255 | ||
8256 | last_shell_builtin = ps->last_shell_builtin; | |
8257 | this_shell_builtin = ps->this_shell_builtin; | |
8258 | ||
8259 | expand_aliases = ps->expand_aliases; | |
8260 | echo_input_at_read = ps->echo_input_at_read; | |
8261 | } | |
8262 | ||
7117c2d2 JA |
8263 | /************************************************ |
8264 | * * | |
8265 | * MULTIBYTE CHARACTER HANDLING * | |
8266 | * * | |
8267 | ************************************************/ | |
8268 | ||
8269 | #if defined (HANDLE_MULTIBYTE) | |
8270 | static void | |
8271 | set_line_mbstate () | |
8272 | { | |
b80f6443 | 8273 | int i, previ, len, c; |
7117c2d2 JA |
8274 | mbstate_t mbs, prevs; |
8275 | size_t mbclen; | |
8276 | ||
8277 | if (shell_input_line == NULL) | |
8278 | return; | |
8279 | len = strlen (shell_input_line); /* XXX - shell_input_line_len ? */ | |
8280 | FREE (shell_input_line_property); | |
8281 | shell_input_line_property = (char *)xmalloc (len + 1); | |
8282 | ||
8283 | memset (&prevs, '\0', sizeof (mbstate_t)); | |
8284 | for (i = previ = 0; i < len; i++) | |
8285 | { | |
8286 | mbs = prevs; | |
8287 | ||
b80f6443 JA |
8288 | c = shell_input_line[i]; |
8289 | if (c == EOF) | |
7117c2d2 JA |
8290 | { |
8291 | int j; | |
8292 | for (j = i; j < len; j++) | |
8293 | shell_input_line_property[j] = 1; | |
8294 | break; | |
8295 | } | |
8296 | ||
8297 | mbclen = mbrlen (shell_input_line + previ, i - previ + 1, &mbs); | |
8298 | if (mbclen == 1 || mbclen == (size_t)-1) | |
8299 | { | |
8300 | mbclen = 1; | |
8301 | previ = i + 1; | |
8302 | } | |
8303 | else if (mbclen == (size_t)-2) | |
8304 | mbclen = 0; | |
8305 | else if (mbclen > 1) | |
8306 | { | |
8307 | mbclen = 0; | |
8308 | previ = i + 1; | |
8309 | prevs = mbs; | |
8310 | } | |
8311 | else | |
8312 | { | |
b80f6443 JA |
8313 | /* XXX - what to do if mbrlen returns 0? (null wide character) */ |
8314 | int j; | |
8315 | for (j = i; j < len; j++) | |
8316 | shell_input_line_property[j] = 1; | |
8317 | break; | |
7117c2d2 JA |
8318 | } |
8319 | ||
8320 | shell_input_line_property[i] = mbclen; | |
8321 | } | |
8322 | } | |
8323 | #endif /* HANDLE_MULTIBYTE */ | |
495aee44 | 8324 |