]>
Commit | Line | Data |
---|---|---|
712f80b0 | 1 | /* A Bison parser, made by GNU Bison 3.5.2. */ |
b80f6443 | 2 | |
a0c0a00f | 3 | /* Bison implementation for Yacc-like parsers in C |
b80f6443 | 4 | |
712f80b0 CR |
5 | Copyright (C) 1984, 1989-1990, 2000-2015, 2018-2020 Free Software Foundation, |
6 | Inc. | |
3185942a | 7 | |
a0c0a00f | 8 | This program is free software: you can redistribute it and/or modify |
3185942a | 9 | it under the terms of the GNU General Public License as published by |
a0c0a00f CR |
10 | the Free Software Foundation, either version 3 of the License, or |
11 | (at your option) any later version. | |
3185942a JA |
12 | |
13 | This program is distributed in the hope that it will be useful, | |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | GNU General Public License for more details. | |
17 | ||
18 | You should have received a copy of the GNU General Public License | |
a0c0a00f | 19 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
3185942a JA |
20 | |
21 | /* As a special exception, you may create a larger work that contains | |
22 | part or all of the Bison parser skeleton and distribute that work | |
23 | under terms of your choice, so long as that work isn't itself a | |
24 | parser generator using the skeleton or a modified version thereof | |
25 | as a parser skeleton. Alternatively, if you modify or redistribute | |
26 | the parser skeleton itself, you may (at your option) remove this | |
27 | special exception, which will cause the skeleton and the resulting | |
28 | Bison output files to be licensed under the GNU General Public | |
29 | License without this special exception. | |
30 | ||
31 | This special exception was added by the Free Software Foundation in | |
32 | version 2.2 of Bison. */ | |
33 | ||
34 | /* C LALR(1) parser skeleton written by Richard Stallman, by | |
35 | simplifying the original so-called "semantic" parser. */ | |
36 | ||
37 | /* All symbols defined below should begin with yy or YY, to avoid | |
38 | infringing on user name space. This should be done even for local | |
39 | variables, as they might otherwise be expanded by user macros. | |
40 | There are some unavoidable exceptions within include files to | |
41 | define necessary library symbols; they are noted "INFRINGES ON | |
42 | USER NAME SPACE" below. */ | |
43 | ||
712f80b0 CR |
44 | /* Undocumented macros, especially those whose name start with YY_, |
45 | are private implementation details. Do not rely on them. */ | |
46 | ||
3185942a JA |
47 | /* Identify Bison output. */ |
48 | #define YYBISON 1 | |
49 | ||
50 | /* Bison version. */ | |
712f80b0 | 51 | #define YYBISON_VERSION "3.5.2" |
3185942a JA |
52 | |
53 | /* Skeleton name. */ | |
54 | #define YYSKELETON_NAME "yacc.c" | |
55 | ||
56 | /* Pure parsers. */ | |
57 | #define YYPURE 0 | |
58 | ||
a0c0a00f CR |
59 | /* Push parsers. */ |
60 | #define YYPUSH 0 | |
3185942a | 61 | |
a0c0a00f CR |
62 | /* Pull parsers. */ |
63 | #define YYPULL 1 | |
3185942a JA |
64 | |
65 | ||
66 | ||
67 | ||
712f80b0 CR |
68 | /* First part of user prologue. */ |
69 | #line 21 "/usr/src/local/chet/src/bash/src/parse.y" | |
f73dda09 | 70 | |
ccc6cda3 JA |
71 | #include "config.h" |
72 | ||
726f6388 | 73 | #include "bashtypes.h" |
726f6388 | 74 | #include "bashansi.h" |
ccc6cda3 | 75 | |
28ef6c31 JA |
76 | #include "filecntl.h" |
77 | ||
ccc6cda3 JA |
78 | #if defined (HAVE_UNISTD_H) |
79 | # include <unistd.h> | |
80 | #endif | |
81 | ||
82 | #if defined (HAVE_LOCALE_H) | |
83 | # include <locale.h> | |
84 | #endif | |
85 | ||
86 | #include <stdio.h> | |
f73dda09 | 87 | #include "chartypes.h" |
ccc6cda3 JA |
88 | #include <signal.h> |
89 | ||
90 | #include "memalloc.h" | |
91 | ||
b80f6443 JA |
92 | #include "bashintl.h" |
93 | ||
7117c2d2 JA |
94 | #define NEED_STRFTIME_DECL /* used in externs.h */ |
95 | ||
726f6388 | 96 | #include "shell.h" |
d233b485 | 97 | #include "execute_cmd.h" |
ac50fbac | 98 | #include "typemax.h" /* SIZE_MAX if needed */ |
ccc6cda3 | 99 | #include "trap.h" |
726f6388 | 100 | #include "flags.h" |
ccc6cda3 JA |
101 | #include "parser.h" |
102 | #include "mailcheck.h" | |
f73dda09 | 103 | #include "test.h" |
95732b49 | 104 | #include "builtins.h" |
ccc6cda3 JA |
105 | #include "builtins/common.h" |
106 | #include "builtins/builtext.h" | |
726f6388 | 107 | |
7117c2d2 JA |
108 | #include "shmbutil.h" |
109 | ||
726f6388 | 110 | #if defined (READLINE) |
ccc6cda3 | 111 | # include "bashline.h" |
726f6388 JA |
112 | # include <readline/readline.h> |
113 | #endif /* READLINE */ | |
114 | ||
115 | #if defined (HISTORY) | |
116 | # include "bashhist.h" | |
117 | # include <readline/history.h> | |
118 | #endif /* HISTORY */ | |
119 | ||
120 | #if defined (JOB_CONTROL) | |
121 | # include "jobs.h" | |
a0c0a00f | 122 | #else |
712f80b0 | 123 | extern int cleanup_dead_jobs PARAMS((void)); |
726f6388 JA |
124 | #endif /* JOB_CONTROL */ |
125 | ||
126 | #if defined (ALIAS) | |
127 | # include "alias.h" | |
b80f6443 JA |
128 | #else |
129 | typedef void *alias_t; | |
726f6388 JA |
130 | #endif /* ALIAS */ |
131 | ||
132 | #if defined (PROMPT_STRING_DECODE) | |
cce855bc JA |
133 | # ifndef _MINIX |
134 | # include <sys/param.h> | |
135 | # endif | |
136 | # include <time.h> | |
7117c2d2 JA |
137 | # if defined (TM_IN_SYS_TIME) |
138 | # include <sys/types.h> | |
139 | # include <sys/time.h> | |
140 | # endif /* TM_IN_SYS_TIME */ | |
cce855bc | 141 | # include "maxpath.h" |
726f6388 JA |
142 | #endif /* PROMPT_STRING_DECODE */ |
143 | ||
ccc6cda3 JA |
144 | #define RE_READ_TOKEN -99 |
145 | #define NO_EXPANSION -100 | |
146 | ||
d233b485 CR |
147 | #define END_ALIAS -2 |
148 | ||
7117c2d2 JA |
149 | #ifdef DEBUG |
150 | # define YYDEBUG 1 | |
151 | #else | |
152 | # define YYDEBUG 0 | |
153 | #endif | |
154 | ||
155 | #if defined (HANDLE_MULTIBYTE) | |
156 | # define last_shell_getc_is_singlebyte \ | |
157 | ((shell_input_line_index > 1) \ | |
158 | ? shell_input_line_property[shell_input_line_index - 1] \ | |
159 | : 1) | |
160 | # define MBTEST(x) ((x) && last_shell_getc_is_singlebyte) | |
161 | #else | |
162 | # define last_shell_getc_is_singlebyte 1 | |
163 | # define MBTEST(x) ((x)) | |
164 | #endif | |
ccc6cda3 | 165 | |
cce855bc | 166 | #if defined (EXTENDED_GLOB) |
cce855bc JA |
167 | extern int extended_glob; |
168 | #endif | |
169 | ||
cce855bc | 170 | extern int dump_translatable_strings, dump_po_strings; |
726f6388 | 171 | |
d233b485 | 172 | #if !defined (errno) |
bb70624e | 173 | extern int errno; |
d233b485 CR |
174 | #endif |
175 | ||
726f6388 JA |
176 | /* **************************************************************** */ |
177 | /* */ | |
178 | /* "Forward" declarations */ | |
179 | /* */ | |
180 | /* **************************************************************** */ | |
181 | ||
f73dda09 | 182 | #ifdef DEBUG |
712f80b0 | 183 | static void debug_parser PARAMS((int)); |
f73dda09 JA |
184 | #endif |
185 | ||
712f80b0 CR |
186 | static int yy_getc PARAMS((void)); |
187 | static int yy_ungetc PARAMS((int)); | |
f73dda09 JA |
188 | |
189 | #if defined (READLINE) | |
712f80b0 CR |
190 | static int yy_readline_get PARAMS((void)); |
191 | static int yy_readline_unget PARAMS((int)); | |
f73dda09 JA |
192 | #endif |
193 | ||
712f80b0 CR |
194 | static int yy_string_get PARAMS((void)); |
195 | static int yy_string_unget PARAMS((int)); | |
196 | static void rewind_input_string PARAMS((void)); | |
197 | static int yy_stream_get PARAMS((void)); | |
198 | static int yy_stream_unget PARAMS((int)); | |
f73dda09 | 199 | |
712f80b0 CR |
200 | static int shell_getc PARAMS((int)); |
201 | static void shell_ungetc PARAMS((int)); | |
202 | static void discard_until PARAMS((int)); | |
f73dda09 JA |
203 | |
204 | #if defined (ALIAS) || defined (DPAREN_ARITHMETIC) | |
712f80b0 CR |
205 | static void push_string PARAMS((char *, int, alias_t *)); |
206 | static void pop_string PARAMS((void)); | |
207 | static void free_string_list PARAMS((void)); | |
f73dda09 JA |
208 | #endif |
209 | ||
712f80b0 | 210 | static char *read_a_line PARAMS((int)); |
f73dda09 | 211 | |
712f80b0 CR |
212 | static int reserved_word_acceptable PARAMS((int)); |
213 | static int yylex PARAMS((void)); | |
90a39f32 | 214 | |
712f80b0 CR |
215 | static void push_heredoc PARAMS((REDIRECT *)); |
216 | static char *mk_alexpansion PARAMS((char *)); | |
217 | static int alias_expand_token PARAMS((char *)); | |
218 | static int time_command_acceptable PARAMS((void)); | |
219 | static int special_case_tokens PARAMS((char *)); | |
220 | static int read_token PARAMS((int)); | |
221 | static char *parse_matched_pair PARAMS((int, int, int, int *, int)); | |
222 | static char *parse_comsub PARAMS((int, int, int, int *, int)); | |
7117c2d2 | 223 | #if defined (ARRAY_VARS) |
712f80b0 | 224 | static char *parse_compound_assignment PARAMS((int *)); |
7117c2d2 | 225 | #endif |
f73dda09 | 226 | #if defined (DPAREN_ARITHMETIC) || defined (ARITH_FOR_COMMAND) |
712f80b0 CR |
227 | static int parse_dparen PARAMS((int)); |
228 | static int parse_arith_cmd PARAMS((char **, int)); | |
f73dda09 | 229 | #endif |
cce855bc | 230 | #if defined (COND_COMMAND) |
712f80b0 CR |
231 | static void cond_error PARAMS((void)); |
232 | static COND_COM *cond_expr PARAMS((void)); | |
233 | static COND_COM *cond_or PARAMS((void)); | |
234 | static COND_COM *cond_and PARAMS((void)); | |
235 | static COND_COM *cond_term PARAMS((void)); | |
236 | static int cond_skip_newlines PARAMS((void)); | |
237 | static COMMAND *parse_cond_command PARAMS((void)); | |
cce855bc | 238 | #endif |
7117c2d2 | 239 | #if defined (ARRAY_VARS) |
712f80b0 CR |
240 | static int token_is_assignment PARAMS((char *, int)); |
241 | static int token_is_ident PARAMS((char *, int)); | |
7117c2d2 | 242 | #endif |
712f80b0 CR |
243 | static int read_token_word PARAMS((int)); |
244 | static void discard_parser_constructs PARAMS((int)); | |
726f6388 | 245 | |
712f80b0 CR |
246 | static char *error_token_from_token PARAMS((int)); |
247 | static char *error_token_from_text PARAMS((void)); | |
248 | static void print_offending_line PARAMS((void)); | |
249 | static void report_syntax_error PARAMS((char *)); | |
7117c2d2 | 250 | |
712f80b0 CR |
251 | static void handle_eof_input_unit PARAMS((void)); |
252 | static void prompt_again PARAMS((void)); | |
d166f048 | 253 | #if 0 |
712f80b0 | 254 | static void reset_readline_prompt PARAMS((void)); |
d166f048 | 255 | #endif |
712f80b0 | 256 | static void print_prompt PARAMS((void)); |
726f6388 | 257 | |
7117c2d2 | 258 | #if defined (HANDLE_MULTIBYTE) |
712f80b0 | 259 | static void set_line_mbstate PARAMS((void)); |
7117c2d2 | 260 | static char *shell_input_line_property = NULL; |
d233b485 | 261 | static size_t shell_input_line_propsize = 0; |
7117c2d2 JA |
262 | #else |
263 | # define set_line_mbstate() | |
264 | #endif | |
265 | ||
712f80b0 | 266 | extern int yyerror PARAMS((const char *)); |
d166f048 | 267 | |
7117c2d2 JA |
268 | #ifdef DEBUG |
269 | extern int yydebug; | |
270 | #endif | |
271 | ||
ccc6cda3 JA |
272 | /* Default prompt strings */ |
273 | char *primary_prompt = PPROMPT; | |
274 | char *secondary_prompt = SPROMPT; | |
275 | ||
726f6388 JA |
276 | /* PROMPT_STRING_POINTER points to one of these, never to an actual string. */ |
277 | char *ps1_prompt, *ps2_prompt; | |
278 | ||
a0c0a00f CR |
279 | /* Displayed after reading a command but before executing it in an interactive shell */ |
280 | char *ps0_prompt; | |
281 | ||
726f6388 JA |
282 | /* Handle on the current prompt string. Indirectly points through |
283 | ps1_ or ps2_prompt. */ | |
284 | char **prompt_string_pointer = (char **)NULL; | |
285 | char *current_prompt_string; | |
286 | ||
ccc6cda3 JA |
287 | /* Non-zero means we expand aliases in commands. */ |
288 | int expand_aliases = 0; | |
289 | ||
290 | /* If non-zero, the decoded prompt string undergoes parameter and | |
291 | variable substitution, command substitution, arithmetic substitution, | |
292 | string expansion, process substitution, and quote removal in | |
293 | decode_prompt_string. */ | |
294 | int promptvars = 1; | |
295 | ||
b80f6443 JA |
296 | /* If non-zero, $'...' and $"..." are expanded when they appear within |
297 | a ${...} expansion, even when the expansion appears within double | |
298 | quotes. */ | |
299 | int extended_quote = 1; | |
300 | ||
726f6388 | 301 | /* The number of lines read from input while creating the current command. */ |
ccc6cda3 | 302 | int current_command_line_count; |
726f6388 | 303 | |
495aee44 CR |
304 | /* The number of lines in a command saved while we run parse_and_execute */ |
305 | int saved_command_line_count; | |
306 | ||
3185942a JA |
307 | /* The token that currently denotes the end of parse. */ |
308 | int shell_eof_token; | |
309 | ||
310 | /* The token currently being read. */ | |
311 | int current_token; | |
312 | ||
0001803f CR |
313 | /* The current parser state. */ |
314 | int parser_state; | |
315 | ||
726f6388 JA |
316 | /* Variables to manage the task of reading here documents, because we need to |
317 | defer the reading until after a complete command has been collected. */ | |
90a39f32 | 318 | static REDIRECT *redir_stack[HEREDOC_MAX]; |
ccc6cda3 | 319 | int need_here_doc; |
726f6388 JA |
320 | |
321 | /* Where shell input comes from. History expansion is performed on each | |
322 | line when the shell is interactive. */ | |
323 | static char *shell_input_line = (char *)NULL; | |
ac50fbac CR |
324 | static size_t shell_input_line_index; |
325 | static size_t shell_input_line_size; /* Amount allocated for shell_input_line. */ | |
326 | static size_t shell_input_line_len; /* strlen (shell_input_line) */ | |
726f6388 JA |
327 | |
328 | /* Either zero or EOF. */ | |
ccc6cda3 JA |
329 | static int shell_input_line_terminator; |
330 | ||
331 | /* The line number in a script on which a function definition starts. */ | |
332 | static int function_dstart; | |
333 | ||
334 | /* The line number in a script on which a function body starts. */ | |
335 | static int function_bstart; | |
726f6388 | 336 | |
bb70624e JA |
337 | /* The line number in a script at which an arithmetic for command starts. */ |
338 | static int arith_for_lineno; | |
339 | ||
0001803f CR |
340 | /* The decoded prompt string. Used if READLINE is not defined or if |
341 | editing is turned off. Analogous to current_readline_prompt. */ | |
342 | static char *current_decoded_prompt; | |
3185942a JA |
343 | |
344 | /* The last read token, or NULL. read_token () uses this for context | |
345 | checking. */ | |
346 | static int last_read_token; | |
347 | ||
348 | /* The token read prior to last_read_token. */ | |
349 | static int token_before_that; | |
350 | ||
351 | /* The token read prior to token_before_that. */ | |
352 | static int two_tokens_ago; | |
353 | ||
0001803f CR |
354 | static int global_extglob; |
355 | ||
b80f6443 JA |
356 | /* The line number in a script where the word in a `case WORD', `select WORD' |
357 | or `for WORD' begins. This is a nested command maximum, since the array | |
358 | index is decremented after a case, select, or for command is parsed. */ | |
359 | #define MAX_CASE_NEST 128 | |
90a39f32 | 360 | static int word_lineno[MAX_CASE_NEST+1]; |
b80f6443 JA |
361 | static int word_top = -1; |
362 | ||
363 | /* If non-zero, it is the token that we want read_token to return | |
364 | regardless of what text is (or isn't) present to be read. This | |
365 | is reset by read_token. If token_to_read == WORD or | |
366 | ASSIGNMENT_WORD, yylval.word should be set to word_desc_to_read. */ | |
367 | static int token_to_read; | |
368 | static WORD_DESC *word_desc_to_read; | |
369 | ||
0001803f | 370 | static REDIRECTEE source; |
726f6388 | 371 | static REDIRECTEE redir; |
f73dda09 | 372 | |
d233b485 CR |
373 | static FILE *yyoutstream; |
374 | static FILE *yyerrstream; | |
375 | ||
712f80b0 | 376 | #line 377 "y.tab.c" |
3185942a | 377 | |
712f80b0 CR |
378 | # ifndef YY_CAST |
379 | # ifdef __cplusplus | |
380 | # define YY_CAST(Type, Val) static_cast<Type> (Val) | |
381 | # define YY_REINTERPRET_CAST(Type, Val) reinterpret_cast<Type> (Val) | |
382 | # else | |
383 | # define YY_CAST(Type, Val) ((Type) (Val)) | |
384 | # define YY_REINTERPRET_CAST(Type, Val) ((Type) (Val)) | |
385 | # endif | |
386 | # endif | |
a0c0a00f | 387 | # ifndef YY_NULLPTR |
712f80b0 CR |
388 | # if defined __cplusplus |
389 | # if 201103L <= __cplusplus | |
390 | # define YY_NULLPTR nullptr | |
391 | # else | |
392 | # define YY_NULLPTR 0 | |
393 | # endif | |
a0c0a00f | 394 | # else |
712f80b0 | 395 | # define YY_NULLPTR ((void*)0) |
a0c0a00f CR |
396 | # endif |
397 | # endif | |
3185942a JA |
398 | |
399 | /* Enabling verbose error messages. */ | |
400 | #ifdef YYERROR_VERBOSE | |
401 | # undef YYERROR_VERBOSE | |
402 | # define YYERROR_VERBOSE 1 | |
403 | #else | |
404 | # define YYERROR_VERBOSE 0 | |
405 | #endif | |
406 | ||
712f80b0 CR |
407 | /* Use api.header.include to #include this header |
408 | instead of duplicating it here. */ | |
a0c0a00f CR |
409 | #ifndef YY_YY_Y_TAB_H_INCLUDED |
410 | # define YY_YY_Y_TAB_H_INCLUDED | |
411 | /* Debug traces. */ | |
412 | #ifndef YYDEBUG | |
413 | # define YYDEBUG 0 | |
414 | #endif | |
415 | #if YYDEBUG | |
416 | extern int yydebug; | |
3185942a JA |
417 | #endif |
418 | ||
a0c0a00f CR |
419 | /* Token type. */ |
420 | #ifndef YYTOKENTYPE | |
421 | # define YYTOKENTYPE | |
422 | enum yytokentype | |
423 | { | |
424 | IF = 258, | |
425 | THEN = 259, | |
426 | ELSE = 260, | |
427 | ELIF = 261, | |
428 | FI = 262, | |
429 | CASE = 263, | |
430 | ESAC = 264, | |
431 | FOR = 265, | |
432 | SELECT = 266, | |
433 | WHILE = 267, | |
434 | UNTIL = 268, | |
435 | DO = 269, | |
436 | DONE = 270, | |
437 | FUNCTION = 271, | |
438 | COPROC = 272, | |
439 | COND_START = 273, | |
440 | COND_END = 274, | |
441 | COND_ERROR = 275, | |
442 | IN = 276, | |
443 | BANG = 277, | |
444 | TIME = 278, | |
445 | TIMEOPT = 279, | |
446 | TIMEIGN = 280, | |
447 | WORD = 281, | |
448 | ASSIGNMENT_WORD = 282, | |
449 | REDIR_WORD = 283, | |
450 | NUMBER = 284, | |
451 | ARITH_CMD = 285, | |
452 | ARITH_FOR_EXPRS = 286, | |
453 | COND_CMD = 287, | |
454 | AND_AND = 288, | |
455 | OR_OR = 289, | |
456 | GREATER_GREATER = 290, | |
457 | LESS_LESS = 291, | |
458 | LESS_AND = 292, | |
459 | LESS_LESS_LESS = 293, | |
460 | GREATER_AND = 294, | |
461 | SEMI_SEMI = 295, | |
462 | SEMI_AND = 296, | |
463 | SEMI_SEMI_AND = 297, | |
464 | LESS_LESS_MINUS = 298, | |
465 | AND_GREATER = 299, | |
466 | AND_GREATER_GREATER = 300, | |
467 | LESS_GREATER = 301, | |
468 | GREATER_BAR = 302, | |
469 | BAR_AND = 303, | |
470 | yacc_EOF = 304 | |
471 | }; | |
472 | #endif | |
473 | /* Tokens. */ | |
474 | #define IF 258 | |
475 | #define THEN 259 | |
476 | #define ELSE 260 | |
477 | #define ELIF 261 | |
478 | #define FI 262 | |
479 | #define CASE 263 | |
480 | #define ESAC 264 | |
481 | #define FOR 265 | |
482 | #define SELECT 266 | |
483 | #define WHILE 267 | |
484 | #define UNTIL 268 | |
485 | #define DO 269 | |
486 | #define DONE 270 | |
487 | #define FUNCTION 271 | |
488 | #define COPROC 272 | |
489 | #define COND_START 273 | |
490 | #define COND_END 274 | |
491 | #define COND_ERROR 275 | |
492 | #define IN 276 | |
493 | #define BANG 277 | |
494 | #define TIME 278 | |
495 | #define TIMEOPT 279 | |
496 | #define TIMEIGN 280 | |
497 | #define WORD 281 | |
498 | #define ASSIGNMENT_WORD 282 | |
499 | #define REDIR_WORD 283 | |
500 | #define NUMBER 284 | |
501 | #define ARITH_CMD 285 | |
502 | #define ARITH_FOR_EXPRS 286 | |
503 | #define COND_CMD 287 | |
504 | #define AND_AND 288 | |
505 | #define OR_OR 289 | |
506 | #define GREATER_GREATER 290 | |
507 | #define LESS_LESS 291 | |
508 | #define LESS_AND 292 | |
509 | #define LESS_LESS_LESS 293 | |
510 | #define GREATER_AND 294 | |
511 | #define SEMI_SEMI 295 | |
512 | #define SEMI_AND 296 | |
513 | #define SEMI_SEMI_AND 297 | |
514 | #define LESS_LESS_MINUS 298 | |
515 | #define AND_GREATER 299 | |
516 | #define AND_GREATER_GREATER 300 | |
517 | #define LESS_GREATER 301 | |
518 | #define GREATER_BAR 302 | |
519 | #define BAR_AND 303 | |
520 | #define yacc_EOF 304 | |
521 | ||
522 | /* Value type. */ | |
3185942a | 523 | #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED |
a0c0a00f | 524 | union YYSTYPE |
3185942a | 525 | { |
712f80b0 | 526 | #line 328 "/usr/src/local/chet/src/bash/src/parse.y" |
a0c0a00f | 527 | |
726f6388 JA |
528 | WORD_DESC *word; /* the word that we read. */ |
529 | int number; /* the number that we read. */ | |
530 | WORD_LIST *word_list; | |
531 | COMMAND *command; | |
532 | REDIRECT *redirect; | |
533 | ELEMENT element; | |
534 | PATTERN_LIST *pattern; | |
a0c0a00f | 535 | |
712f80b0 | 536 | #line 537 "y.tab.c" |
a0c0a00f | 537 | |
712f80b0 | 538 | }; |
a0c0a00f | 539 | typedef union YYSTYPE YYSTYPE; |
3185942a | 540 | # define YYSTYPE_IS_TRIVIAL 1 |
a0c0a00f | 541 | # define YYSTYPE_IS_DECLARED 1 |
3185942a JA |
542 | #endif |
543 | ||
544 | ||
a0c0a00f | 545 | extern YYSTYPE yylval; |
3185942a | 546 | |
a0c0a00f | 547 | int yyparse (void); |
3185942a | 548 | |
a0c0a00f | 549 | #endif /* !YY_YY_Y_TAB_H_INCLUDED */ |
3185942a | 550 | |
a0c0a00f | 551 | |
b80f6443 | 552 | |
3185942a JA |
553 | #ifdef short |
554 | # undef short | |
f73dda09 | 555 | #endif |
3185942a | 556 | |
712f80b0 CR |
557 | /* On compilers that do not define __PTRDIFF_MAX__ etc., make sure |
558 | <limits.h> and (if available) <stdint.h> are included | |
559 | so that the code can choose integer types of a good width. */ | |
560 | ||
561 | #ifndef __PTRDIFF_MAX__ | |
562 | # include <limits.h> /* INFRINGES ON USER NAME SPACE */ | |
563 | # if defined __STDC_VERSION__ && 199901 <= __STDC_VERSION__ | |
564 | # include <stdint.h> /* INFRINGES ON USER NAME SPACE */ | |
565 | # define YY_STDINT_H | |
566 | # endif | |
f73dda09 JA |
567 | #endif |
568 | ||
712f80b0 CR |
569 | /* Narrow types that promote to a signed type and that can represent a |
570 | signed or unsigned integer of at least N bits. In tables they can | |
571 | save space and decrease cache pressure. Promoting to a signed type | |
572 | helps avoid bugs in integer arithmetic. */ | |
573 | ||
574 | #ifdef __INT_LEAST8_MAX__ | |
575 | typedef __INT_LEAST8_TYPE__ yytype_int8; | |
576 | #elif defined YY_STDINT_H | |
577 | typedef int_least8_t yytype_int8; | |
3185942a | 578 | #else |
a0c0a00f | 579 | typedef signed char yytype_int8; |
3185942a | 580 | #endif |
f73dda09 | 581 | |
712f80b0 CR |
582 | #ifdef __INT_LEAST16_MAX__ |
583 | typedef __INT_LEAST16_TYPE__ yytype_int16; | |
584 | #elif defined YY_STDINT_H | |
585 | typedef int_least16_t yytype_int16; | |
3185942a | 586 | #else |
712f80b0 | 587 | typedef short yytype_int16; |
3185942a | 588 | #endif |
f73dda09 | 589 | |
712f80b0 CR |
590 | #if defined __UINT_LEAST8_MAX__ && __UINT_LEAST8_MAX__ <= __INT_MAX__ |
591 | typedef __UINT_LEAST8_TYPE__ yytype_uint8; | |
592 | #elif (!defined __UINT_LEAST8_MAX__ && defined YY_STDINT_H \ | |
593 | && UINT_LEAST8_MAX <= INT_MAX) | |
594 | typedef uint_least8_t yytype_uint8; | |
595 | #elif !defined __UINT_LEAST8_MAX__ && UCHAR_MAX <= INT_MAX | |
596 | typedef unsigned char yytype_uint8; | |
3185942a | 597 | #else |
712f80b0 CR |
598 | typedef short yytype_uint8; |
599 | #endif | |
600 | ||
601 | #if defined __UINT_LEAST16_MAX__ && __UINT_LEAST16_MAX__ <= __INT_MAX__ | |
602 | typedef __UINT_LEAST16_TYPE__ yytype_uint16; | |
603 | #elif (!defined __UINT_LEAST16_MAX__ && defined YY_STDINT_H \ | |
604 | && UINT_LEAST16_MAX <= INT_MAX) | |
605 | typedef uint_least16_t yytype_uint16; | |
606 | #elif !defined __UINT_LEAST16_MAX__ && USHRT_MAX <= INT_MAX | |
607 | typedef unsigned short yytype_uint16; | |
608 | #else | |
609 | typedef int yytype_uint16; | |
610 | #endif | |
611 | ||
612 | #ifndef YYPTRDIFF_T | |
613 | # if defined __PTRDIFF_TYPE__ && defined __PTRDIFF_MAX__ | |
614 | # define YYPTRDIFF_T __PTRDIFF_TYPE__ | |
615 | # define YYPTRDIFF_MAXIMUM __PTRDIFF_MAX__ | |
616 | # elif defined PTRDIFF_MAX | |
617 | # ifndef ptrdiff_t | |
618 | # include <stddef.h> /* INFRINGES ON USER NAME SPACE */ | |
619 | # endif | |
620 | # define YYPTRDIFF_T ptrdiff_t | |
621 | # define YYPTRDIFF_MAXIMUM PTRDIFF_MAX | |
622 | # else | |
623 | # define YYPTRDIFF_T long | |
624 | # define YYPTRDIFF_MAXIMUM LONG_MAX | |
625 | # endif | |
3185942a | 626 | #endif |
f73dda09 | 627 | |
3185942a JA |
628 | #ifndef YYSIZE_T |
629 | # ifdef __SIZE_TYPE__ | |
630 | # define YYSIZE_T __SIZE_TYPE__ | |
631 | # elif defined size_t | |
632 | # define YYSIZE_T size_t | |
712f80b0 | 633 | # elif defined __STDC_VERSION__ && 199901 <= __STDC_VERSION__ |
3185942a JA |
634 | # include <stddef.h> /* INFRINGES ON USER NAME SPACE */ |
635 | # define YYSIZE_T size_t | |
636 | # else | |
712f80b0 | 637 | # define YYSIZE_T unsigned |
3185942a JA |
638 | # endif |
639 | #endif | |
b80f6443 | 640 | |
712f80b0 CR |
641 | #define YYSIZE_MAXIMUM \ |
642 | YY_CAST (YYPTRDIFF_T, \ | |
643 | (YYPTRDIFF_MAXIMUM < YY_CAST (YYSIZE_T, -1) \ | |
644 | ? YYPTRDIFF_MAXIMUM \ | |
645 | : YY_CAST (YYSIZE_T, -1))) | |
646 | ||
647 | #define YYSIZEOF(X) YY_CAST (YYPTRDIFF_T, sizeof (X)) | |
648 | ||
649 | /* Stored state numbers (used for stacks). */ | |
650 | typedef yytype_int16 yy_state_t; | |
651 | ||
652 | /* State numbers in computations. */ | |
653 | typedef int yy_state_fast_t; | |
f73dda09 | 654 | |
3185942a | 655 | #ifndef YY_ |
509a4430 | 656 | # if defined YYENABLE_NLS && YYENABLE_NLS |
3185942a JA |
657 | # if ENABLE_NLS |
658 | # include <libintl.h> /* INFRINGES ON USER NAME SPACE */ | |
a0c0a00f | 659 | # define YY_(Msgid) dgettext ("bison-runtime", Msgid) |
3185942a JA |
660 | # endif |
661 | # endif | |
662 | # ifndef YY_ | |
a0c0a00f CR |
663 | # define YY_(Msgid) Msgid |
664 | # endif | |
665 | #endif | |
666 | ||
712f80b0 CR |
667 | #ifndef YY_ATTRIBUTE_PURE |
668 | # if defined __GNUC__ && 2 < __GNUC__ + (96 <= __GNUC_MINOR__) | |
669 | # define YY_ATTRIBUTE_PURE __attribute__ ((__pure__)) | |
a0c0a00f | 670 | # else |
712f80b0 | 671 | # define YY_ATTRIBUTE_PURE |
a0c0a00f CR |
672 | # endif |
673 | #endif | |
674 | ||
a0c0a00f | 675 | #ifndef YY_ATTRIBUTE_UNUSED |
712f80b0 CR |
676 | # if defined __GNUC__ && 2 < __GNUC__ + (7 <= __GNUC_MINOR__) |
677 | # define YY_ATTRIBUTE_UNUSED __attribute__ ((__unused__)) | |
a0c0a00f | 678 | # else |
712f80b0 | 679 | # define YY_ATTRIBUTE_UNUSED |
3185942a | 680 | # endif |
f73dda09 JA |
681 | #endif |
682 | ||
3185942a JA |
683 | /* Suppress unused-variable warnings by "using" E. */ |
684 | #if ! defined lint || defined __GNUC__ | |
a0c0a00f | 685 | # define YYUSE(E) ((void) (E)) |
3185942a | 686 | #else |
a0c0a00f | 687 | # define YYUSE(E) /* empty */ |
f73dda09 JA |
688 | #endif |
689 | ||
712f80b0 | 690 | #if defined __GNUC__ && ! defined __ICC && 407 <= __GNUC__ * 100 + __GNUC_MINOR__ |
a0c0a00f | 691 | /* Suppress an incorrect diagnostic about yylval being uninitialized. */ |
712f80b0 CR |
692 | # define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \ |
693 | _Pragma ("GCC diagnostic push") \ | |
694 | _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"") \ | |
a0c0a00f | 695 | _Pragma ("GCC diagnostic ignored \"-Wmaybe-uninitialized\"") |
712f80b0 | 696 | # define YY_IGNORE_MAYBE_UNINITIALIZED_END \ |
a0c0a00f | 697 | _Pragma ("GCC diagnostic pop") |
3185942a | 698 | #else |
a0c0a00f | 699 | # define YY_INITIAL_VALUE(Value) Value |
3185942a | 700 | #endif |
a0c0a00f CR |
701 | #ifndef YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN |
702 | # define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN | |
703 | # define YY_IGNORE_MAYBE_UNINITIALIZED_END | |
3185942a | 704 | #endif |
a0c0a00f CR |
705 | #ifndef YY_INITIAL_VALUE |
706 | # define YY_INITIAL_VALUE(Value) /* Nothing. */ | |
707 | #endif | |
708 | ||
712f80b0 CR |
709 | #if defined __cplusplus && defined __GNUC__ && ! defined __ICC && 6 <= __GNUC__ |
710 | # define YY_IGNORE_USELESS_CAST_BEGIN \ | |
711 | _Pragma ("GCC diagnostic push") \ | |
712 | _Pragma ("GCC diagnostic ignored \"-Wuseless-cast\"") | |
713 | # define YY_IGNORE_USELESS_CAST_END \ | |
714 | _Pragma ("GCC diagnostic pop") | |
715 | #endif | |
716 | #ifndef YY_IGNORE_USELESS_CAST_BEGIN | |
717 | # define YY_IGNORE_USELESS_CAST_BEGIN | |
718 | # define YY_IGNORE_USELESS_CAST_END | |
719 | #endif | |
720 | ||
721 | ||
722 | #define YY_ASSERT(E) ((void) (0 && (E))) | |
3185942a JA |
723 | |
724 | #if ! defined yyoverflow || YYERROR_VERBOSE | |
725 | ||
726 | /* The parser invokes alloca or malloc; define the necessary symbols. */ | |
727 | ||
728 | # ifdef YYSTACK_USE_ALLOCA | |
729 | # if YYSTACK_USE_ALLOCA | |
730 | # ifdef __GNUC__ | |
731 | # define YYSTACK_ALLOC __builtin_alloca | |
732 | # elif defined __BUILTIN_VA_ARG_INCR | |
733 | # include <alloca.h> /* INFRINGES ON USER NAME SPACE */ | |
734 | # elif defined _AIX | |
735 | # define YYSTACK_ALLOC __alloca | |
736 | # elif defined _MSC_VER | |
737 | # include <malloc.h> /* INFRINGES ON USER NAME SPACE */ | |
738 | # define alloca _alloca | |
739 | # else | |
740 | # define YYSTACK_ALLOC alloca | |
a0c0a00f | 741 | # if ! defined _ALLOCA_H && ! defined EXIT_SUCCESS |
3185942a | 742 | # include <stdlib.h> /* INFRINGES ON USER NAME SPACE */ |
a0c0a00f CR |
743 | /* Use EXIT_SUCCESS as a witness for stdlib.h. */ |
744 | # ifndef EXIT_SUCCESS | |
745 | # define EXIT_SUCCESS 0 | |
3185942a JA |
746 | # endif |
747 | # endif | |
748 | # endif | |
749 | # endif | |
750 | # endif | |
751 | ||
752 | # ifdef YYSTACK_ALLOC | |
a0c0a00f CR |
753 | /* Pacify GCC's 'empty if-body' warning. */ |
754 | # define YYSTACK_FREE(Ptr) do { /* empty */; } while (0) | |
3185942a JA |
755 | # ifndef YYSTACK_ALLOC_MAXIMUM |
756 | /* The OS might guarantee only one guard page at the bottom of the stack, | |
757 | and a page size can be as small as 4096 bytes. So we cannot safely | |
758 | invoke alloca (N) if N exceeds 4096. Use a slightly smaller number | |
759 | to allow for a few compiler-allocated temporary stack slots. */ | |
760 | # define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */ | |
761 | # endif | |
762 | # else | |
763 | # define YYSTACK_ALLOC YYMALLOC | |
764 | # define YYSTACK_FREE YYFREE | |
765 | # ifndef YYSTACK_ALLOC_MAXIMUM | |
766 | # define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM | |
767 | # endif | |
a0c0a00f | 768 | # if (defined __cplusplus && ! defined EXIT_SUCCESS \ |
3185942a | 769 | && ! ((defined YYMALLOC || defined malloc) \ |
a0c0a00f | 770 | && (defined YYFREE || defined free))) |
3185942a | 771 | # include <stdlib.h> /* INFRINGES ON USER NAME SPACE */ |
a0c0a00f CR |
772 | # ifndef EXIT_SUCCESS |
773 | # define EXIT_SUCCESS 0 | |
3185942a JA |
774 | # endif |
775 | # endif | |
776 | # ifndef YYMALLOC | |
777 | # define YYMALLOC malloc | |
a0c0a00f | 778 | # if ! defined malloc && ! defined EXIT_SUCCESS |
3185942a JA |
779 | void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */ |
780 | # endif | |
781 | # endif | |
782 | # ifndef YYFREE | |
783 | # define YYFREE free | |
a0c0a00f | 784 | # if ! defined free && ! defined EXIT_SUCCESS |
3185942a JA |
785 | void free (void *); /* INFRINGES ON USER NAME SPACE */ |
786 | # endif | |
787 | # endif | |
788 | # endif | |
789 | #endif /* ! defined yyoverflow || YYERROR_VERBOSE */ | |
790 | ||
791 | ||
792 | #if (! defined yyoverflow \ | |
793 | && (! defined __cplusplus \ | |
a0c0a00f | 794 | || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL))) |
3185942a JA |
795 | |
796 | /* A type that is properly aligned for any stack member. */ | |
797 | union yyalloc | |
798 | { | |
712f80b0 | 799 | yy_state_t yyss_alloc; |
a0c0a00f CR |
800 | YYSTYPE yyvs_alloc; |
801 | }; | |
3185942a JA |
802 | |
803 | /* The size of the maximum gap between one aligned stack and the next. */ | |
712f80b0 | 804 | # define YYSTACK_GAP_MAXIMUM (YYSIZEOF (union yyalloc) - 1) |
3185942a JA |
805 | |
806 | /* The size of an array large to enough to hold all stacks, each with | |
807 | N elements. */ | |
808 | # define YYSTACK_BYTES(N) \ | |
712f80b0 | 809 | ((N) * (YYSIZEOF (yy_state_t) + YYSIZEOF (YYSTYPE)) \ |
3185942a JA |
810 | + YYSTACK_GAP_MAXIMUM) |
811 | ||
a0c0a00f | 812 | # define YYCOPY_NEEDED 1 |
3185942a JA |
813 | |
814 | /* Relocate STACK from its old location to the new one. The | |
815 | local variables YYSIZE and YYSTACKSIZE give the old and new number of | |
816 | elements in the stack, and YYPTR gives the new location of the | |
817 | stack. Advance YYPTR to a properly aligned location for the next | |
818 | stack. */ | |
a0c0a00f CR |
819 | # define YYSTACK_RELOCATE(Stack_alloc, Stack) \ |
820 | do \ | |
821 | { \ | |
712f80b0 | 822 | YYPTRDIFF_T yynewbytes; \ |
a0c0a00f CR |
823 | YYCOPY (&yyptr->Stack_alloc, Stack, yysize); \ |
824 | Stack = &yyptr->Stack_alloc; \ | |
712f80b0 CR |
825 | yynewbytes = yystacksize * YYSIZEOF (*Stack) + YYSTACK_GAP_MAXIMUM; \ |
826 | yyptr += yynewbytes / YYSIZEOF (*yyptr); \ | |
a0c0a00f CR |
827 | } \ |
828 | while (0) | |
f73dda09 | 829 | |
f73dda09 JA |
830 | #endif |
831 | ||
a0c0a00f CR |
832 | #if defined YYCOPY_NEEDED && YYCOPY_NEEDED |
833 | /* Copy COUNT objects from SRC to DST. The source and destination do | |
834 | not overlap. */ | |
835 | # ifndef YYCOPY | |
836 | # if defined __GNUC__ && 1 < __GNUC__ | |
837 | # define YYCOPY(Dst, Src, Count) \ | |
712f80b0 | 838 | __builtin_memcpy (Dst, Src, YY_CAST (YYSIZE_T, (Count)) * sizeof (*(Src))) |
a0c0a00f CR |
839 | # else |
840 | # define YYCOPY(Dst, Src, Count) \ | |
841 | do \ | |
842 | { \ | |
712f80b0 | 843 | YYPTRDIFF_T yyi; \ |
a0c0a00f CR |
844 | for (yyi = 0; yyi < (Count); yyi++) \ |
845 | (Dst)[yyi] = (Src)[yyi]; \ | |
846 | } \ | |
847 | while (0) | |
848 | # endif | |
849 | # endif | |
850 | #endif /* !YYCOPY_NEEDED */ | |
851 | ||
3185942a | 852 | /* YYFINAL -- State number of the termination state. */ |
712f80b0 | 853 | #define YYFINAL 118 |
3185942a | 854 | /* YYLAST -- Last index in YYTABLE. */ |
712f80b0 | 855 | #define YYLAST 661 |
3185942a JA |
856 | |
857 | /* YYNTOKENS -- Number of terminals. */ | |
495aee44 | 858 | #define YYNTOKENS 61 |
3185942a JA |
859 | /* YYNNTS -- Number of nonterminals. */ |
860 | #define YYNNTS 38 | |
861 | /* YYNRULES -- Number of rules. */ | |
712f80b0 | 862 | #define YYNRULES 172 |
a0c0a00f | 863 | /* YYNSTATES -- Number of states. */ |
712f80b0 | 864 | #define YYNSTATES 346 |
3185942a | 865 | |
3185942a | 866 | #define YYUNDEFTOK 2 |
495aee44 | 867 | #define YYMAXUTOK 304 |
3185942a | 868 | |
712f80b0 CR |
869 | |
870 | /* YYTRANSLATE(TOKEN-NUM) -- Symbol number corresponding to TOKEN-NUM | |
871 | as returned by yylex, with out-of-bounds checking. */ | |
a0c0a00f | 872 | #define YYTRANSLATE(YYX) \ |
712f80b0 | 873 | (0 <= (YYX) && (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK) |
3185942a | 874 | |
a0c0a00f | 875 | /* YYTRANSLATE[TOKEN-NUM] -- Symbol number corresponding to TOKEN-NUM |
712f80b0 CR |
876 | as returned by yylex. */ |
877 | static const yytype_int8 yytranslate[] = | |
3185942a JA |
878 | { |
879 | 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
495aee44 | 880 | 51, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
3185942a | 881 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
495aee44 CR |
882 | 2, 2, 2, 2, 2, 2, 2, 2, 49, 2, |
883 | 59, 60, 2, 2, 2, 56, 2, 2, 2, 2, | |
884 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 50, | |
885 | 55, 2, 54, 2, 2, 2, 2, 2, 2, 2, | |
3185942a JA |
886 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
887 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
888 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
889 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
890 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
495aee44 | 891 | 2, 2, 2, 57, 53, 58, 2, 2, 2, 2, |
3185942a JA |
892 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
893 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
894 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
895 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
896 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
897 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
898 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
899 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
900 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
901 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
902 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
903 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
904 | 2, 2, 2, 2, 2, 2, 1, 2, 3, 4, | |
905 | 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, | |
906 | 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, | |
907 | 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, | |
908 | 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, | |
495aee44 | 909 | 45, 46, 47, 48, 52 |
726f6388 | 910 | }; |
f73dda09 | 911 | |
3185942a | 912 | #if YYDEBUG |
a0c0a00f | 913 | /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */ |
712f80b0 | 914 | static const yytype_int16 yyrline[] = |
3185942a | 915 | { |
d233b485 CR |
916 | 0, 381, 381, 392, 401, 416, 433, 443, 445, 449, |
917 | 455, 461, 467, 473, 479, 485, 491, 497, 503, 509, | |
918 | 515, 521, 527, 533, 539, 546, 553, 560, 567, 574, | |
919 | 581, 587, 593, 599, 605, 611, 617, 623, 629, 635, | |
920 | 641, 647, 653, 659, 665, 671, 677, 683, 689, 695, | |
921 | 701, 707, 713, 721, 723, 725, 729, 733, 744, 746, | |
922 | 750, 752, 754, 770, 772, 776, 778, 780, 782, 784, | |
923 | 786, 788, 790, 792, 794, 796, 800, 805, 810, 815, | |
924 | 820, 825, 830, 835, 842, 848, 854, 860, 868, 873, | |
925 | 878, 883, 888, 893, 898, 903, 910, 915, 920, 927, | |
712f80b0 CR |
926 | 929, 931, 933, 937, 939, 970, 977, 982, 999, 1004, |
927 | 1021, 1028, 1030, 1032, 1037, 1041, 1045, 1049, 1051, 1053, | |
928 | 1057, 1058, 1062, 1064, 1066, 1068, 1072, 1074, 1076, 1078, | |
929 | 1080, 1082, 1086, 1088, 1097, 1105, 1106, 1112, 1113, 1120, | |
930 | 1124, 1126, 1128, 1135, 1137, 1139, 1143, 1144, 1147, 1149, | |
931 | 1151, 1155, 1156, 1165, 1178, 1194, 1209, 1211, 1213, 1220, | |
932 | 1223, 1227, 1229, 1235, 1241, 1261, 1284, 1286, 1309, 1313, | |
933 | 1315, 1317, 1319 | |
726f6388 | 934 | }; |
3185942a | 935 | #endif |
f73dda09 | 936 | |
a0c0a00f | 937 | #if YYDEBUG || YYERROR_VERBOSE || 0 |
3185942a JA |
938 | /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM. |
939 | First, the terminals, then, starting at YYNTOKENS, nonterminals. */ | |
940 | static const char *const yytname[] = | |
941 | { | |
942 | "$end", "error", "$undefined", "IF", "THEN", "ELSE", "ELIF", "FI", | |
943 | "CASE", "ESAC", "FOR", "SELECT", "WHILE", "UNTIL", "DO", "DONE", | |
944 | "FUNCTION", "COPROC", "COND_START", "COND_END", "COND_ERROR", "IN", | |
495aee44 CR |
945 | "BANG", "TIME", "TIMEOPT", "TIMEIGN", "WORD", "ASSIGNMENT_WORD", |
946 | "REDIR_WORD", "NUMBER", "ARITH_CMD", "ARITH_FOR_EXPRS", "COND_CMD", | |
947 | "AND_AND", "OR_OR", "GREATER_GREATER", "LESS_LESS", "LESS_AND", | |
948 | "LESS_LESS_LESS", "GREATER_AND", "SEMI_SEMI", "SEMI_AND", | |
949 | "SEMI_SEMI_AND", "LESS_LESS_MINUS", "AND_GREATER", "AND_GREATER_GREATER", | |
950 | "LESS_GREATER", "GREATER_BAR", "BAR_AND", "'&'", "';'", "'\\n'", | |
951 | "yacc_EOF", "'|'", "'>'", "'<'", "'-'", "'{'", "'}'", "'('", "')'", | |
952 | "$accept", "inputunit", "word_list", "redirection", | |
953 | "simple_command_element", "redirection_list", "simple_command", | |
954 | "command", "shell_command", "for_command", "arith_for_command", | |
955 | "select_command", "case_command", "function_def", "function_body", | |
956 | "subshell", "coproc", "if_command", "group_command", "arith_command", | |
957 | "cond_command", "elif_clause", "case_clause", "pattern_list", | |
958 | "case_clause_sequence", "pattern", "list", "compound_list", "list0", | |
959 | "list1", "simple_list_terminator", "list_terminator", "newline_list", | |
960 | "simple_list", "simple_list1", "pipeline_command", "pipeline", | |
a0c0a00f | 961 | "timespec", YY_NULLPTR |
726f6388 | 962 | }; |
3185942a | 963 | #endif |
f73dda09 | 964 | |
3185942a | 965 | # ifdef YYPRINT |
a0c0a00f CR |
966 | /* YYTOKNUM[NUM] -- (External) token number corresponding to the |
967 | (internal) symbol number NUM (which must be that of a token). */ | |
712f80b0 | 968 | static const yytype_int16 yytoknum[] = |
3185942a JA |
969 | { |
970 | 0, 256, 257, 258, 259, 260, 261, 262, 263, 264, | |
971 | 265, 266, 267, 268, 269, 270, 271, 272, 273, 274, | |
972 | 275, 276, 277, 278, 279, 280, 281, 282, 283, 284, | |
973 | 285, 286, 287, 288, 289, 290, 291, 292, 293, 294, | |
495aee44 CR |
974 | 295, 296, 297, 298, 299, 300, 301, 302, 303, 38, |
975 | 59, 10, 304, 124, 62, 60, 45, 123, 125, 40, | |
976 | 41 | |
3185942a JA |
977 | }; |
978 | # endif | |
979 | ||
712f80b0 | 980 | #define YYPACT_NINF (-204) |
f73dda09 | 981 | |
712f80b0 CR |
982 | #define yypact_value_is_default(Yyn) \ |
983 | ((Yyn) == YYPACT_NINF) | |
a0c0a00f | 984 | |
712f80b0 | 985 | #define YYTABLE_NINF (-1) |
a0c0a00f | 986 | |
712f80b0 | 987 | #define yytable_value_is_error(Yyn) \ |
a0c0a00f CR |
988 | 0 |
989 | ||
990 | /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing | |
991 | STATE-NUM. */ | |
992 | static const yytype_int16 yypact[] = | |
3185942a | 993 | { |
712f80b0 CR |
994 | 313, 108, -204, -6, 8, 2, -204, -204, 10, 513, |
995 | 17, 363, 153, -21, -204, 593, 606, -204, 14, 26, | |
996 | 113, 41, 127, 72, 85, 92, 95, 98, -204, -204, | |
997 | 100, 105, -204, -204, 65, -204, -204, 551, -204, 572, | |
d233b485 | 998 | -204, -204, -204, -204, -204, -204, -204, -204, -204, -204, |
712f80b0 CR |
999 | -204, 146, 140, -204, 67, 363, -204, -204, -204, 133, |
1000 | 413, -204, 93, 55, 104, 156, 161, 11, 45, 551, | |
1001 | 572, 163, -204, -204, -204, -204, -204, 167, -204, 152, | |
1002 | 208, 217, 129, 220, 150, 221, 223, 225, 233, 234, | |
1003 | 238, 239, 158, 240, 162, 241, 243, 244, 252, 253, | |
d233b485 | 1004 | -204, -204, -204, -204, -204, -204, -204, -204, -204, -204, |
712f80b0 CR |
1005 | -204, -204, -204, -204, -204, -204, 194, 227, -204, -204, |
1006 | -204, -204, 572, -204, -204, -204, -204, -204, 463, 463, | |
1007 | -204, -204, -204, -204, -204, -204, -204, -7, -204, 59, | |
1008 | -204, 52, -204, -204, -204, -204, 62, -204, -204, -204, | |
1009 | 235, 572, -204, 572, 572, -204, -204, -204, -204, -204, | |
d233b485 CR |
1010 | -204, -204, -204, -204, -204, -204, -204, -204, -204, -204, |
1011 | -204, -204, -204, -204, -204, -204, -204, -204, -204, -204, | |
712f80b0 CR |
1012 | -204, -204, -204, -204, -204, -204, -204, -204, -204, 413, |
1013 | 413, 191, 191, 245, 245, 203, -204, -204, -204, -204, | |
1014 | -204, -204, 37, -204, 176, -204, 270, 228, 76, 79, | |
1015 | -204, 176, -204, 278, 282, 563, -204, 572, 572, 563, | |
1016 | -204, -204, 67, 67, -204, -204, -204, 291, 413, 413, | |
1017 | 413, 413, 413, 294, 175, -204, 28, -204, -204, 292, | |
1018 | -204, 187, -204, 250, -204, -204, -204, -204, -204, -204, | |
1019 | 295, 413, 187, -204, 251, -204, -204, -204, 563, -204, | |
1020 | 304, 314, -204, -204, -204, 196, 196, 196, -204, -204, | |
1021 | -204, -204, 179, 38, -204, -204, 296, -28, 302, 274, | |
1022 | -204, -204, -204, 87, -204, 318, 276, 322, 280, -204, | |
1023 | -7, -204, 111, -204, -204, -204, -204, -204, -204, -204, | |
1024 | -204, 39, 319, -204, -204, -204, 114, -204, -204, -204, | |
1025 | -204, -204, -204, 115, -204, -204, 226, -204, -204, -204, | |
1026 | 413, -204, -204, 329, 288, -204, -204, 332, 297, -204, | |
1027 | -204, -204, 413, 338, 303, -204, -204, 339, 305, -204, | |
1028 | -204, -204, -204, -204, -204, -204 | |
3185942a | 1029 | }; |
f73dda09 | 1030 | |
a0c0a00f CR |
1031 | /* YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM. |
1032 | Performed when YYTABLE does not specify something else to do. Zero | |
1033 | means the default is an error. */ | |
3185942a JA |
1034 | static const yytype_uint8 yydefact[] = |
1035 | { | |
712f80b0 CR |
1036 | 0, 0, 151, 0, 0, 0, 151, 151, 0, 0, |
1037 | 0, 0, 169, 53, 54, 0, 0, 115, 0, 0, | |
d233b485 | 1038 | 0, 0, 0, 0, 0, 0, 0, 0, 3, 6, |
712f80b0 | 1039 | 0, 0, 151, 151, 0, 55, 58, 60, 168, 61, |
d233b485 | 1040 | 65, 75, 69, 66, 63, 71, 64, 70, 72, 73, |
712f80b0 CR |
1041 | 74, 0, 153, 160, 161, 0, 4, 5, 135, 0, |
1042 | 0, 151, 151, 0, 151, 0, 0, 0, 53, 110, | |
1043 | 106, 0, 149, 148, 150, 165, 162, 170, 171, 0, | |
0001803f | 1044 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
712f80b0 CR |
1045 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
1046 | 15, 24, 39, 33, 48, 30, 42, 36, 45, 27, | |
1047 | 51, 52, 21, 18, 9, 10, 0, 0, 1, 53, | |
1048 | 59, 56, 62, 146, 147, 2, 151, 151, 154, 155, | |
1049 | 151, 151, 164, 163, 151, 152, 134, 136, 145, 0, | |
1050 | 151, 0, 151, 151, 151, 151, 0, 151, 151, 151, | |
1051 | 151, 103, 101, 108, 107, 116, 172, 151, 17, 26, | |
1052 | 41, 35, 50, 32, 44, 38, 47, 29, 23, 20, | |
1053 | 13, 14, 16, 25, 40, 34, 49, 31, 43, 37, | |
1054 | 46, 28, 22, 19, 11, 12, 114, 105, 57, 0, | |
1055 | 0, 158, 159, 0, 0, 0, 151, 151, 151, 151, | |
1056 | 151, 151, 0, 151, 0, 151, 0, 0, 0, 0, | |
1057 | 151, 0, 151, 0, 0, 0, 151, 104, 109, 0, | |
1058 | 156, 157, 167, 166, 151, 151, 111, 0, 0, 0, | |
1059 | 138, 139, 137, 0, 120, 151, 0, 151, 151, 0, | |
1060 | 7, 0, 151, 0, 86, 87, 151, 151, 151, 151, | |
1061 | 0, 0, 0, 151, 0, 67, 68, 102, 0, 99, | |
1062 | 0, 0, 113, 140, 141, 142, 143, 144, 98, 126, | |
1063 | 128, 130, 121, 0, 96, 132, 0, 0, 0, 0, | |
1064 | 76, 8, 151, 0, 77, 0, 0, 0, 0, 88, | |
1065 | 0, 151, 0, 89, 100, 112, 151, 127, 129, 131, | |
1066 | 97, 0, 0, 151, 78, 79, 0, 151, 151, 84, | |
1067 | 85, 90, 91, 0, 151, 151, 117, 151, 133, 122, | |
1068 | 123, 151, 151, 0, 0, 151, 151, 0, 0, 151, | |
1069 | 119, 124, 125, 0, 0, 82, 83, 0, 0, 94, | |
1070 | 95, 118, 80, 81, 92, 93 | |
726f6388 | 1071 | }; |
f73dda09 | 1072 | |
a0c0a00f CR |
1073 | /* YYPGOTO[NTERM-NUM]. */ |
1074 | static const yytype_int16 yypgoto[] = | |
3185942a | 1075 | { |
712f80b0 CR |
1076 | -204, -204, 117, -37, -19, -67, 353, -204, -8, -204, |
1077 | -204, -204, -204, -204, -184, -204, -204, -204, -204, -204, | |
1078 | -204, 53, -204, 142, -204, 102, -203, -2, -204, 283, | |
1079 | -204, -47, -49, -204, -118, 6, 47, -204 | |
3185942a | 1080 | }; |
f73dda09 | 1081 | |
a0c0a00f CR |
1082 | /* YYDEFGOTO[NTERM-NUM]. */ |
1083 | static const yytype_int16 yydefgoto[] = | |
3185942a | 1084 | { |
712f80b0 CR |
1085 | -1, 34, 241, 35, 36, 122, 37, 38, 39, 40, |
1086 | 41, 42, 43, 44, 152, 45, 46, 47, 48, 49, | |
1087 | 50, 227, 233, 234, 235, 277, 58, 117, 136, 137, | |
1088 | 125, 75, 60, 51, 52, 138, 54, 55 | |
3185942a | 1089 | }; |
f73dda09 | 1090 | |
a0c0a00f CR |
1091 | /* YYTABLE[YYPACT[STATE-NUM]] -- What to do in state STATE-NUM. If |
1092 | positive, shift that token. If negative, reduce the rule whose | |
1093 | number is the opposite. If YYTABLE_NINF, syntax error. */ | |
712f80b0 | 1094 | static const yytype_int16 yytable[] = |
3185942a | 1095 | { |
712f80b0 CR |
1096 | 59, 70, 121, 154, 65, 66, 53, 250, 132, 254, |
1097 | 191, 192, 139, 141, 2, 146, 144, 76, 120, 3, | |
1098 | 61, 4, 5, 6, 7, 302, 196, 197, 64, 10, | |
1099 | 116, 257, 303, 121, 62, 259, 67, 274, 79, 63, | |
1100 | 100, 17, 198, 199, 200, 287, 288, 300, 2, 71, | |
1101 | 120, 237, 101, 3, 275, 4, 5, 6, 7, 151, | |
1102 | 153, 133, 149, 10, 275, 118, 203, 105, 32, 142, | |
1103 | 150, 220, 221, 204, 294, 17, 210, 189, 190, 135, | |
1104 | 201, 193, 194, 211, 217, 188, 218, 276, 135, 135, | |
1105 | 246, 202, 302, 248, 238, 208, 209, 276, 109, 317, | |
1106 | 215, 307, 32, 135, 33, 72, 73, 74, 219, 205, | |
1107 | 135, 110, 143, 135, 121, 130, 121, 188, 111, 212, | |
1108 | 131, 112, 337, 338, 113, 314, 114, 135, 321, 325, | |
1109 | 135, 115, 195, 247, 53, 53, 249, 134, 135, 102, | |
1110 | 206, 207, 103, 140, 308, 213, 214, 228, 229, 230, | |
1111 | 231, 232, 236, 106, 145, 160, 107, 242, 161, 56, | |
1112 | 57, 251, 135, 251, 253, 135, 135, 258, 315, 104, | |
1113 | 147, 322, 326, 126, 127, 148, 164, 77, 78, 165, | |
1114 | 188, 188, 155, 108, 174, 162, 273, 175, 178, 128, | |
1115 | 129, 179, 156, 283, 282, 53, 53, 123, 124, 251, | |
1116 | 251, 239, 240, 243, 292, 291, 166, 151, 224, 225, | |
1117 | 226, 151, 157, 281, 176, 269, 270, 271, 180, 297, | |
1118 | 298, 299, 260, 261, 126, 127, 72, 73, 74, 196, | |
1119 | 197, 329, 225, 306, 158, 278, 279, 72, 73, 74, | |
1120 | 222, 223, 313, 159, 285, 286, 163, 167, 2, 168, | |
1121 | 151, 169, 186, 3, 320, 4, 5, 6, 7, 170, | |
1122 | 171, 8, 9, 10, 172, 173, 177, 181, 332, 182, | |
1123 | 183, 13, 14, 15, 16, 17, 251, 251, 184, 185, | |
1124 | 18, 19, 20, 21, 22, 244, 245, 187, 23, 24, | |
1125 | 25, 26, 27, 255, 316, 216, 135, 256, 262, 30, | |
1126 | 31, 319, 32, 268, 33, 323, 324, 280, 284, 293, | |
1127 | 289, 295, 327, 328, 1, 331, 2, 304, 296, 333, | |
1128 | 334, 3, 275, 4, 5, 6, 7, 341, 252, 8, | |
1129 | 9, 10, 305, 309, 310, 11, 12, 311, 312, 13, | |
1130 | 14, 15, 16, 17, 335, 318, 336, 339, 18, 19, | |
1131 | 20, 21, 22, 342, 344, 340, 23, 24, 25, 26, | |
1132 | 27, 343, 69, 345, 28, 29, 2, 30, 31, 330, | |
1133 | 32, 3, 33, 4, 5, 6, 7, 272, 301, 8, | |
1134 | 9, 10, 0, 0, 0, 11, 12, 0, 0, 13, | |
1135 | 14, 15, 16, 17, 0, 0, 0, 0, 18, 19, | |
1136 | 20, 21, 22, 0, 0, 0, 23, 24, 25, 26, | |
1137 | 27, 0, 0, 72, 73, 74, 2, 30, 31, 0, | |
1138 | 32, 3, 33, 4, 5, 6, 7, 0, 0, 8, | |
1139 | 9, 10, 0, 0, 0, 11, 12, 0, 0, 13, | |
1140 | 14, 15, 16, 17, 0, 0, 0, 0, 18, 19, | |
1141 | 20, 21, 22, 0, 0, 0, 23, 24, 25, 26, | |
1142 | 27, 0, 0, 0, 135, 0, 2, 30, 31, 0, | |
1143 | 32, 3, 33, 4, 5, 6, 7, 0, 0, 8, | |
1144 | 9, 10, 0, 0, 0, 11, 12, 0, 0, 13, | |
1145 | 14, 15, 16, 17, 0, 0, 0, 0, 18, 19, | |
1146 | 20, 21, 22, 0, 0, 0, 23, 24, 25, 26, | |
1147 | 27, 263, 264, 265, 266, 267, 2, 30, 31, 0, | |
1148 | 32, 3, 33, 4, 5, 6, 7, 0, 0, 0, | |
1149 | 0, 10, 0, 0, 290, 0, 0, 0, 0, 68, | |
1150 | 14, 15, 16, 17, 0, 0, 0, 0, 18, 19, | |
1151 | 20, 21, 22, 0, 0, 0, 23, 24, 25, 26, | |
1152 | 27, 0, 0, 0, 0, 0, 2, 30, 31, 0, | |
1153 | 32, 3, 33, 4, 5, 6, 7, 119, 14, 15, | |
1154 | 16, 10, 0, 0, 0, 0, 18, 19, 20, 21, | |
1155 | 22, 0, 0, 17, 23, 24, 25, 26, 27, 0, | |
1156 | 15, 16, 0, 0, 0, 30, 31, 18, 19, 20, | |
1157 | 21, 22, 0, 0, 135, 23, 24, 25, 26, 27, | |
1158 | 32, 0, 33, 0, 0, 0, 30, 31, 80, 81, | |
1159 | 82, 83, 84, 0, 0, 0, 85, 0, 0, 86, | |
1160 | 87, 90, 91, 92, 93, 94, 0, 88, 89, 95, | |
1161 | 0, 0, 96, 97, 0, 0, 0, 0, 0, 0, | |
1162 | 98, 99 | |
3185942a | 1163 | }; |
f73dda09 | 1164 | |
3185942a JA |
1165 | static const yytype_int16 yycheck[] = |
1166 | { | |
712f80b0 CR |
1167 | 2, 9, 39, 70, 6, 7, 0, 210, 55, 212, |
1168 | 128, 129, 61, 62, 3, 64, 63, 11, 37, 8, | |
1169 | 26, 10, 11, 12, 13, 53, 33, 34, 26, 18, | |
1170 | 32, 215, 60, 70, 26, 219, 26, 9, 59, 31, | |
1171 | 26, 30, 49, 50, 51, 248, 249, 9, 3, 32, | |
1172 | 69, 14, 26, 8, 26, 10, 11, 12, 13, 67, | |
1173 | 68, 55, 51, 18, 26, 0, 14, 26, 57, 14, | |
1174 | 59, 189, 190, 21, 258, 30, 14, 126, 127, 51, | |
1175 | 21, 130, 131, 21, 151, 122, 153, 59, 51, 51, | |
1176 | 14, 140, 53, 14, 57, 144, 145, 59, 26, 60, | |
1177 | 149, 14, 57, 51, 59, 50, 51, 52, 157, 57, | |
1178 | 51, 26, 57, 51, 151, 48, 153, 154, 26, 57, | |
1179 | 53, 26, 325, 326, 26, 14, 26, 51, 14, 14, | |
1180 | 51, 26, 134, 57, 128, 129, 57, 4, 51, 26, | |
1181 | 142, 143, 29, 50, 57, 147, 148, 196, 197, 198, | |
1182 | 199, 200, 201, 26, 50, 26, 29, 204, 29, 51, | |
1183 | 52, 210, 51, 212, 211, 51, 51, 216, 57, 56, | |
1184 | 14, 57, 57, 33, 34, 14, 26, 24, 25, 29, | |
1185 | 217, 218, 19, 56, 26, 56, 235, 29, 26, 49, | |
1186 | 50, 29, 25, 242, 241, 189, 190, 51, 52, 248, | |
1187 | 249, 203, 26, 205, 253, 252, 56, 215, 5, 6, | |
1188 | 7, 219, 60, 26, 56, 40, 41, 42, 56, 40, | |
1189 | 41, 42, 224, 225, 33, 34, 50, 51, 52, 33, | |
1190 | 34, 5, 6, 282, 26, 237, 238, 50, 51, 52, | |
1191 | 193, 194, 291, 26, 246, 247, 26, 26, 3, 26, | |
1192 | 258, 26, 58, 8, 303, 10, 11, 12, 13, 26, | |
1193 | 26, 16, 17, 18, 26, 26, 26, 26, 317, 26, | |
1194 | 26, 26, 27, 28, 29, 30, 325, 326, 26, 26, | |
1195 | 35, 36, 37, 38, 39, 15, 58, 60, 43, 44, | |
1196 | 45, 46, 47, 15, 296, 60, 51, 15, 7, 54, | |
1197 | 55, 303, 57, 9, 59, 307, 308, 15, 58, 58, | |
1198 | 15, 7, 314, 315, 1, 317, 3, 15, 4, 321, | |
1199 | 322, 8, 26, 10, 11, 12, 13, 329, 211, 16, | |
1200 | 17, 18, 58, 15, 58, 22, 23, 15, 58, 26, | |
1201 | 27, 28, 29, 30, 15, 26, 58, 15, 35, 36, | |
1202 | 37, 38, 39, 15, 15, 58, 43, 44, 45, 46, | |
1203 | 47, 58, 9, 58, 51, 52, 3, 54, 55, 316, | |
1204 | 57, 8, 59, 10, 11, 12, 13, 235, 276, 16, | |
1205 | 17, 18, -1, -1, -1, 22, 23, -1, -1, 26, | |
1206 | 27, 28, 29, 30, -1, -1, -1, -1, 35, 36, | |
1207 | 37, 38, 39, -1, -1, -1, 43, 44, 45, 46, | |
1208 | 47, -1, -1, 50, 51, 52, 3, 54, 55, -1, | |
1209 | 57, 8, 59, 10, 11, 12, 13, -1, -1, 16, | |
1210 | 17, 18, -1, -1, -1, 22, 23, -1, -1, 26, | |
1211 | 27, 28, 29, 30, -1, -1, -1, -1, 35, 36, | |
1212 | 37, 38, 39, -1, -1, -1, 43, 44, 45, 46, | |
1213 | 47, -1, -1, -1, 51, -1, 3, 54, 55, -1, | |
1214 | 57, 8, 59, 10, 11, 12, 13, -1, -1, 16, | |
1215 | 17, 18, -1, -1, -1, 22, 23, -1, -1, 26, | |
1216 | 27, 28, 29, 30, -1, -1, -1, -1, 35, 36, | |
1217 | 37, 38, 39, -1, -1, -1, 43, 44, 45, 46, | |
1218 | 47, 228, 229, 230, 231, 232, 3, 54, 55, -1, | |
1219 | 57, 8, 59, 10, 11, 12, 13, -1, -1, -1, | |
1220 | -1, 18, -1, -1, 251, -1, -1, -1, -1, 26, | |
1221 | 27, 28, 29, 30, -1, -1, -1, -1, 35, 36, | |
1222 | 37, 38, 39, -1, -1, -1, 43, 44, 45, 46, | |
1223 | 47, -1, -1, -1, -1, -1, 3, 54, 55, -1, | |
1224 | 57, 8, 59, 10, 11, 12, 13, 26, 27, 28, | |
1225 | 29, 18, -1, -1, -1, -1, 35, 36, 37, 38, | |
1226 | 39, -1, -1, 30, 43, 44, 45, 46, 47, -1, | |
1227 | 28, 29, -1, -1, -1, 54, 55, 35, 36, 37, | |
1228 | 38, 39, -1, -1, 51, 43, 44, 45, 46, 47, | |
1229 | 57, -1, 59, -1, -1, -1, 54, 55, 35, 36, | |
1230 | 37, 38, 39, -1, -1, -1, 43, -1, -1, 46, | |
1231 | 47, 35, 36, 37, 38, 39, -1, 54, 55, 43, | |
1232 | -1, -1, 46, 47, -1, -1, -1, -1, -1, -1, | |
1233 | 54, 55 | |
3185942a | 1234 | }; |
f73dda09 | 1235 | |
a0c0a00f CR |
1236 | /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing |
1237 | symbol of state STATE-NUM. */ | |
712f80b0 | 1238 | static const yytype_int8 yystos[] = |
3185942a JA |
1239 | { |
1240 | 0, 1, 3, 8, 10, 11, 12, 13, 16, 17, | |
495aee44 CR |
1241 | 18, 22, 23, 26, 27, 28, 29, 30, 35, 36, |
1242 | 37, 38, 39, 43, 44, 45, 46, 47, 51, 52, | |
1243 | 54, 55, 57, 59, 62, 64, 65, 67, 68, 69, | |
1244 | 70, 71, 72, 73, 74, 76, 77, 78, 79, 80, | |
d233b485 CR |
1245 | 81, 94, 95, 96, 97, 98, 51, 52, 87, 88, |
1246 | 93, 26, 26, 31, 26, 88, 88, 26, 26, 67, | |
712f80b0 CR |
1247 | 69, 32, 50, 51, 52, 92, 96, 24, 25, 59, |
1248 | 35, 36, 37, 38, 39, 43, 46, 47, 54, 55, | |
1249 | 35, 36, 37, 38, 39, 43, 46, 47, 54, 55, | |
1250 | 26, 26, 26, 29, 56, 26, 26, 29, 56, 26, | |
1251 | 26, 26, 26, 26, 26, 26, 88, 88, 0, 26, | |
1252 | 65, 64, 66, 51, 52, 91, 33, 34, 49, 50, | |
1253 | 48, 53, 92, 96, 4, 51, 89, 90, 96, 93, | |
1254 | 50, 93, 14, 57, 92, 50, 93, 14, 14, 51, | |
1255 | 59, 69, 75, 69, 66, 19, 25, 60, 26, 26, | |
1256 | 26, 29, 56, 26, 26, 29, 56, 26, 26, 26, | |
1257 | 26, 26, 26, 26, 26, 29, 56, 26, 26, 29, | |
1258 | 56, 26, 26, 26, 26, 26, 58, 60, 64, 93, | |
1259 | 93, 95, 95, 93, 93, 88, 33, 34, 49, 50, | |
1260 | 51, 21, 93, 14, 21, 57, 88, 88, 93, 93, | |
1261 | 14, 21, 57, 88, 88, 93, 60, 66, 66, 93, | |
1262 | 95, 95, 97, 97, 5, 6, 7, 82, 93, 93, | |
1263 | 93, 93, 93, 83, 84, 85, 93, 14, 57, 88, | |
1264 | 26, 63, 92, 88, 15, 58, 14, 57, 14, 57, | |
1265 | 87, 93, 63, 92, 87, 15, 15, 75, 93, 75, | |
1266 | 88, 88, 7, 90, 90, 90, 90, 90, 9, 40, | |
1267 | 41, 42, 84, 93, 9, 26, 59, 86, 88, 88, | |
1268 | 15, 26, 92, 93, 58, 88, 88, 87, 87, 15, | |
1269 | 90, 92, 93, 58, 75, 7, 4, 40, 41, 42, | |
1270 | 9, 86, 53, 60, 15, 58, 93, 14, 57, 15, | |
1271 | 58, 15, 58, 93, 14, 57, 88, 60, 26, 88, | |
1272 | 93, 14, 57, 88, 88, 14, 57, 88, 88, 5, | |
1273 | 82, 88, 93, 88, 88, 15, 58, 87, 87, 15, | |
1274 | 58, 88, 15, 58, 15, 58 | |
3185942a | 1275 | }; |
b80f6443 | 1276 | |
a0c0a00f | 1277 | /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */ |
712f80b0 | 1278 | static const yytype_int8 yyr1[] = |
a0c0a00f | 1279 | { |
d233b485 | 1280 | 0, 61, 62, 62, 62, 62, 62, 63, 63, 64, |
a0c0a00f CR |
1281 | 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, |
1282 | 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, | |
1283 | 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, | |
1284 | 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, | |
d233b485 CR |
1285 | 64, 64, 64, 65, 65, 65, 66, 66, 67, 67, |
1286 | 68, 68, 68, 68, 68, 69, 69, 69, 69, 69, | |
1287 | 69, 69, 69, 69, 69, 69, 70, 70, 70, 70, | |
1288 | 70, 70, 70, 70, 71, 71, 71, 71, 72, 72, | |
1289 | 72, 72, 72, 72, 72, 72, 73, 73, 73, 74, | |
712f80b0 CR |
1290 | 74, 74, 74, 75, 75, 76, 77, 77, 77, 77, |
1291 | 77, 78, 78, 78, 79, 80, 81, 82, 82, 82, | |
1292 | 83, 83, 84, 84, 84, 84, 85, 85, 85, 85, | |
1293 | 85, 85, 86, 86, 87, 88, 88, 89, 89, 89, | |
1294 | 90, 90, 90, 90, 90, 90, 91, 91, 92, 92, | |
1295 | 92, 93, 93, 94, 94, 94, 95, 95, 95, 95, | |
1296 | 95, 96, 96, 96, 96, 96, 97, 97, 97, 98, | |
1297 | 98, 98, 98 | |
a0c0a00f CR |
1298 | }; |
1299 | ||
1300 | /* YYR2[YYN] -- Number of symbols on the right hand side of rule YYN. */ | |
712f80b0 | 1301 | static const yytype_int8 yyr2[] = |
a0c0a00f | 1302 | { |
d233b485 CR |
1303 | 0, 2, 2, 1, 2, 2, 1, 1, 2, 2, |
1304 | 2, 3, 3, 3, 3, 2, 3, 3, 2, 3, | |
1305 | 3, 2, 3, 3, 2, 3, 3, 2, 3, 3, | |
a0c0a00f CR |
1306 | 2, 3, 3, 2, 3, 3, 2, 3, 3, 2, |
1307 | 3, 3, 2, 3, 3, 2, 3, 3, 2, 3, | |
d233b485 CR |
1308 | 3, 2, 2, 1, 1, 1, 1, 2, 1, 2, |
1309 | 1, 1, 2, 1, 1, 1, 1, 5, 5, 1, | |
1310 | 1, 1, 1, 1, 1, 1, 6, 6, 7, 7, | |
1311 | 10, 10, 9, 9, 7, 7, 5, 5, 6, 6, | |
1312 | 7, 7, 10, 10, 9, 9, 6, 7, 6, 5, | |
712f80b0 CR |
1313 | 6, 3, 5, 1, 2, 3, 2, 3, 3, 4, |
1314 | 2, 5, 7, 6, 3, 1, 3, 4, 6, 5, | |
1315 | 1, 2, 4, 4, 5, 5, 2, 3, 2, 3, | |
1316 | 2, 3, 1, 3, 2, 1, 2, 3, 3, 3, | |
1317 | 4, 4, 4, 4, 4, 1, 1, 1, 1, 1, | |
1318 | 1, 0, 2, 1, 2, 2, 4, 4, 3, 3, | |
1319 | 1, 1, 2, 2, 2, 2, 4, 4, 1, 1, | |
1320 | 2, 2, 3 | |
a0c0a00f | 1321 | }; |
3185942a | 1322 | |
3185942a | 1323 | |
a0c0a00f CR |
1324 | #define yyerrok (yyerrstatus = 0) |
1325 | #define yyclearin (yychar = YYEMPTY) | |
1326 | #define YYEMPTY (-2) | |
1327 | #define YYEOF 0 | |
3185942a | 1328 | |
a0c0a00f CR |
1329 | #define YYACCEPT goto yyacceptlab |
1330 | #define YYABORT goto yyabortlab | |
1331 | #define YYERROR goto yyerrorlab | |
3185942a | 1332 | |
3185942a | 1333 | |
f73dda09 | 1334 | #define YYRECOVERING() (!!yyerrstatus) |
3185942a | 1335 | |
712f80b0 CR |
1336 | #define YYBACKUP(Token, Value) \ |
1337 | do \ | |
1338 | if (yychar == YYEMPTY) \ | |
1339 | { \ | |
1340 | yychar = (Token); \ | |
1341 | yylval = (Value); \ | |
1342 | YYPOPSTACK (yylen); \ | |
1343 | yystate = *yyssp; \ | |
1344 | goto yybackup; \ | |
1345 | } \ | |
1346 | else \ | |
1347 | { \ | |
1348 | yyerror (YY_("syntax error: cannot back up")); \ | |
1349 | YYERROR; \ | |
1350 | } \ | |
1351 | while (0) | |
f73dda09 | 1352 | |
a0c0a00f CR |
1353 | /* Error token number */ |
1354 | #define YYTERROR 1 | |
1355 | #define YYERRCODE 256 | |
3185942a | 1356 | |
3185942a | 1357 | |
3185942a JA |
1358 | |
1359 | /* Enable debugging if requested. */ | |
1360 | #if YYDEBUG | |
1361 | ||
1362 | # ifndef YYFPRINTF | |
1363 | # include <stdio.h> /* INFRINGES ON USER NAME SPACE */ | |
1364 | # define YYFPRINTF fprintf | |
1365 | # endif | |
1366 | ||
a0c0a00f CR |
1367 | # define YYDPRINTF(Args) \ |
1368 | do { \ | |
1369 | if (yydebug) \ | |
1370 | YYFPRINTF Args; \ | |
1371 | } while (0) | |
1372 | ||
1373 | /* This macro is provided for backward compatibility. */ | |
1374 | #ifndef YY_LOCATION_PRINT | |
1375 | # define YY_LOCATION_PRINT(File, Loc) ((void) 0) | |
1376 | #endif | |
3185942a | 1377 | |
3185942a | 1378 | |
a0c0a00f CR |
1379 | # define YY_SYMBOL_PRINT(Title, Type, Value, Location) \ |
1380 | do { \ | |
1381 | if (yydebug) \ | |
1382 | { \ | |
1383 | YYFPRINTF (stderr, "%s ", Title); \ | |
1384 | yy_symbol_print (stderr, \ | |
1385 | Type, Value); \ | |
1386 | YYFPRINTF (stderr, "\n"); \ | |
1387 | } \ | |
1388 | } while (0) | |
3185942a | 1389 | |
3185942a | 1390 | |
712f80b0 CR |
1391 | /*-----------------------------------. |
1392 | | Print this symbol's value on YYO. | | |
1393 | `-----------------------------------*/ | |
a0c0a00f | 1394 | |
3185942a | 1395 | static void |
712f80b0 | 1396 | yy_symbol_value_print (FILE *yyo, int yytype, YYSTYPE const * const yyvaluep) |
3185942a | 1397 | { |
712f80b0 CR |
1398 | FILE *yyoutput = yyo; |
1399 | YYUSE (yyoutput); | |
3185942a JA |
1400 | if (!yyvaluep) |
1401 | return; | |
1402 | # ifdef YYPRINT | |
1403 | if (yytype < YYNTOKENS) | |
712f80b0 | 1404 | YYPRINT (yyo, yytoknum[yytype], *yyvaluep); |
3185942a | 1405 | # endif |
712f80b0 | 1406 | YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN |
a0c0a00f | 1407 | YYUSE (yytype); |
712f80b0 | 1408 | YY_IGNORE_MAYBE_UNINITIALIZED_END |
3185942a JA |
1409 | } |
1410 | ||
1411 | ||
712f80b0 CR |
1412 | /*---------------------------. |
1413 | | Print this symbol on YYO. | | |
1414 | `---------------------------*/ | |
b80f6443 | 1415 | |
3185942a | 1416 | static void |
712f80b0 | 1417 | yy_symbol_print (FILE *yyo, int yytype, YYSTYPE const * const yyvaluep) |
3185942a | 1418 | { |
712f80b0 | 1419 | YYFPRINTF (yyo, "%s %s (", |
a0c0a00f | 1420 | yytype < YYNTOKENS ? "token" : "nterm", yytname[yytype]); |
726f6388 | 1421 | |
712f80b0 CR |
1422 | yy_symbol_value_print (yyo, yytype, yyvaluep); |
1423 | YYFPRINTF (yyo, ")"); | |
3185942a | 1424 | } |
726f6388 | 1425 | |
3185942a JA |
1426 | /*------------------------------------------------------------------. |
1427 | | yy_stack_print -- Print the state stack from its BOTTOM up to its | | |
1428 | | TOP (included). | | |
1429 | `------------------------------------------------------------------*/ | |
b80f6443 | 1430 | |
3185942a | 1431 | static void |
712f80b0 | 1432 | yy_stack_print (yy_state_t *yybottom, yy_state_t *yytop) |
3185942a JA |
1433 | { |
1434 | YYFPRINTF (stderr, "Stack now"); | |
a0c0a00f CR |
1435 | for (; yybottom <= yytop; yybottom++) |
1436 | { | |
1437 | int yybot = *yybottom; | |
1438 | YYFPRINTF (stderr, " %d", yybot); | |
1439 | } | |
3185942a JA |
1440 | YYFPRINTF (stderr, "\n"); |
1441 | } | |
726f6388 | 1442 | |
a0c0a00f CR |
1443 | # define YY_STACK_PRINT(Bottom, Top) \ |
1444 | do { \ | |
1445 | if (yydebug) \ | |
1446 | yy_stack_print ((Bottom), (Top)); \ | |
1447 | } while (0) | |
726f6388 | 1448 | |
3185942a JA |
1449 | |
1450 | /*------------------------------------------------. | |
1451 | | Report that the YYRULE is going to be reduced. | | |
1452 | `------------------------------------------------*/ | |
1453 | ||
3185942a | 1454 | static void |
712f80b0 | 1455 | yy_reduce_print (yy_state_t *yyssp, YYSTYPE *yyvsp, int yyrule) |
3185942a | 1456 | { |
712f80b0 | 1457 | int yylno = yyrline[yyrule]; |
3185942a JA |
1458 | int yynrhs = yyr2[yyrule]; |
1459 | int yyi; | |
712f80b0 | 1460 | YYFPRINTF (stderr, "Reducing stack by rule %d (line %d):\n", |
a0c0a00f | 1461 | yyrule - 1, yylno); |
3185942a JA |
1462 | /* The symbols being reduced. */ |
1463 | for (yyi = 0; yyi < yynrhs; yyi++) | |
1464 | { | |
a0c0a00f CR |
1465 | YYFPRINTF (stderr, " $%d = ", yyi + 1); |
1466 | yy_symbol_print (stderr, | |
712f80b0 CR |
1467 | yystos[+yyssp[yyi + 1 - yynrhs]], |
1468 | &yyvsp[(yyi + 1) - (yynrhs)] | |
a0c0a00f CR |
1469 | ); |
1470 | YYFPRINTF (stderr, "\n"); | |
3185942a JA |
1471 | } |
1472 | } | |
1473 | ||
a0c0a00f CR |
1474 | # define YY_REDUCE_PRINT(Rule) \ |
1475 | do { \ | |
1476 | if (yydebug) \ | |
1477 | yy_reduce_print (yyssp, yyvsp, Rule); \ | |
1478 | } while (0) | |
b80f6443 | 1479 | |
3185942a JA |
1480 | /* Nonzero means print parse trace. It is left uninitialized so that |
1481 | multiple parsers can coexist. */ | |
1482 | int yydebug; | |
1483 | #else /* !YYDEBUG */ | |
1484 | # define YYDPRINTF(Args) | |
1485 | # define YY_SYMBOL_PRINT(Title, Type, Value, Location) | |
1486 | # define YY_STACK_PRINT(Bottom, Top) | |
1487 | # define YY_REDUCE_PRINT(Rule) | |
1488 | #endif /* !YYDEBUG */ | |
726f6388 | 1489 | |
3185942a JA |
1490 | |
1491 | /* YYINITDEPTH -- initial size of the parser's stacks. */ | |
a0c0a00f | 1492 | #ifndef YYINITDEPTH |
3185942a | 1493 | # define YYINITDEPTH 200 |
f73dda09 | 1494 | #endif |
726f6388 | 1495 | |
3185942a JA |
1496 | /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only |
1497 | if the built-in stack extension method is used). | |
726f6388 | 1498 | |
3185942a JA |
1499 | Do not make this value too large; the results are undefined if |
1500 | YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH) | |
1501 | evaluated with infinite-precision integer arithmetic. */ | |
726f6388 | 1502 | |
f73dda09 | 1503 | #ifndef YYMAXDEPTH |
3185942a | 1504 | # define YYMAXDEPTH 10000 |
f73dda09 | 1505 | #endif |
3185942a | 1506 | |
3185942a JA |
1507 | |
1508 | #if YYERROR_VERBOSE | |
1509 | ||
1510 | # ifndef yystrlen | |
1511 | # if defined __GLIBC__ && defined _STRING_H | |
712f80b0 | 1512 | # define yystrlen(S) (YY_CAST (YYPTRDIFF_T, strlen (S))) |
3185942a JA |
1513 | # else |
1514 | /* Return the length of YYSTR. */ | |
712f80b0 | 1515 | static YYPTRDIFF_T |
3185942a | 1516 | yystrlen (const char *yystr) |
3185942a | 1517 | { |
712f80b0 | 1518 | YYPTRDIFF_T yylen; |
3185942a JA |
1519 | for (yylen = 0; yystr[yylen]; yylen++) |
1520 | continue; | |
1521 | return yylen; | |
1522 | } | |
1523 | # endif | |
1524 | # endif | |
1525 | ||
1526 | # ifndef yystpcpy | |
1527 | # if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE | |
1528 | # define yystpcpy stpcpy | |
1529 | # else | |
1530 | /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in | |
1531 | YYDEST. */ | |
3185942a JA |
1532 | static char * |
1533 | yystpcpy (char *yydest, const char *yysrc) | |
726f6388 | 1534 | { |
3185942a JA |
1535 | char *yyd = yydest; |
1536 | const char *yys = yysrc; | |
1537 | ||
1538 | while ((*yyd++ = *yys++) != '\0') | |
1539 | continue; | |
1540 | ||
1541 | return yyd - 1; | |
1542 | } | |
1543 | # endif | |
1544 | # endif | |
1545 | ||
1546 | # ifndef yytnamerr | |
1547 | /* Copy to YYRES the contents of YYSTR after stripping away unnecessary | |
1548 | quotes and backslashes, so that it's suitable for yyerror. The | |
1549 | heuristic is that double-quoting is unnecessary unless the string | |
1550 | contains an apostrophe, a comma, or backslash (other than | |
1551 | backslash-backslash). YYSTR is taken from yytname. If YYRES is | |
1552 | null, do not copy; instead, return the length of what the result | |
1553 | would have been. */ | |
712f80b0 | 1554 | static YYPTRDIFF_T |
3185942a JA |
1555 | yytnamerr (char *yyres, const char *yystr) |
1556 | { | |
1557 | if (*yystr == '"') | |
1558 | { | |
712f80b0 | 1559 | YYPTRDIFF_T yyn = 0; |
3185942a JA |
1560 | char const *yyp = yystr; |
1561 | ||
1562 | for (;;) | |
a0c0a00f CR |
1563 | switch (*++yyp) |
1564 | { | |
1565 | case '\'': | |
1566 | case ',': | |
1567 | goto do_not_strip_quotes; | |
1568 | ||
1569 | case '\\': | |
1570 | if (*++yyp != '\\') | |
1571 | goto do_not_strip_quotes; | |
712f80b0 CR |
1572 | else |
1573 | goto append; | |
1574 | ||
1575 | append: | |
a0c0a00f CR |
1576 | default: |
1577 | if (yyres) | |
1578 | yyres[yyn] = *yyp; | |
1579 | yyn++; | |
1580 | break; | |
1581 | ||
1582 | case '"': | |
1583 | if (yyres) | |
1584 | yyres[yyn] = '\0'; | |
1585 | return yyn; | |
1586 | } | |
3185942a JA |
1587 | do_not_strip_quotes: ; |
1588 | } | |
f73dda09 | 1589 | |
712f80b0 CR |
1590 | if (yyres) |
1591 | return yystpcpy (yyres, yystr) - yyres; | |
1592 | else | |
3185942a | 1593 | return yystrlen (yystr); |
3185942a JA |
1594 | } |
1595 | # endif | |
1596 | ||
a0c0a00f CR |
1597 | /* Copy into *YYMSG, which is of size *YYMSG_ALLOC, an error message |
1598 | about the unexpected token YYTOKEN for the state stack whose top is | |
1599 | YYSSP. | |
3185942a | 1600 | |
a0c0a00f CR |
1601 | Return 0 if *YYMSG was successfully written. Return 1 if *YYMSG is |
1602 | not large enough to hold the message. In that case, also set | |
1603 | *YYMSG_ALLOC to the required number of bytes. Return 2 if the | |
1604 | required number of bytes is too large to store. */ | |
1605 | static int | |
712f80b0 CR |
1606 | yysyntax_error (YYPTRDIFF_T *yymsg_alloc, char **yymsg, |
1607 | yy_state_t *yyssp, int yytoken) | |
a0c0a00f | 1608 | { |
a0c0a00f CR |
1609 | enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 }; |
1610 | /* Internationalized format string. */ | |
1611 | const char *yyformat = YY_NULLPTR; | |
712f80b0 CR |
1612 | /* Arguments of yyformat: reported tokens (one for the "unexpected", |
1613 | one per "expected"). */ | |
a0c0a00f | 1614 | char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM]; |
712f80b0 | 1615 | /* Actual size of YYARG. */ |
a0c0a00f | 1616 | int yycount = 0; |
712f80b0 CR |
1617 | /* Cumulated lengths of YYARG. */ |
1618 | YYPTRDIFF_T yysize = 0; | |
a0c0a00f CR |
1619 | |
1620 | /* There are many possibilities here to consider: | |
1621 | - If this state is a consistent state with a default action, then | |
1622 | the only way this function was invoked is if the default action | |
1623 | is an error action. In that case, don't check for expected | |
1624 | tokens because there are none. | |
1625 | - The only way there can be no lookahead present (in yychar) is if | |
1626 | this state is a consistent state with a default action. Thus, | |
1627 | detecting the absence of a lookahead is sufficient to determine | |
1628 | that there is no unexpected or expected token to report. In that | |
1629 | case, just report a simple "syntax error". | |
1630 | - Don't assume there isn't a lookahead just because this state is a | |
1631 | consistent state with a default action. There might have been a | |
1632 | previous inconsistent state, consistent state with a non-default | |
1633 | action, or user semantic action that manipulated yychar. | |
1634 | - Of course, the expected token list depends on states to have | |
1635 | correct lookahead information, and it depends on the parser not | |
1636 | to perform extra reductions after fetching a lookahead from the | |
1637 | scanner and before detecting a syntax error. Thus, state merging | |
1638 | (from LALR or IELR) and default reductions corrupt the expected | |
1639 | token list. However, the list is correct for canonical LR with | |
1640 | one exception: it will still contain any token that will not be | |
1641 | accepted due to an error action in a later state. | |
1642 | */ | |
1643 | if (yytoken != YYEMPTY) | |
1644 | { | |
712f80b0 CR |
1645 | int yyn = yypact[+*yyssp]; |
1646 | YYPTRDIFF_T yysize0 = yytnamerr (YY_NULLPTR, yytname[yytoken]); | |
1647 | yysize = yysize0; | |
a0c0a00f CR |
1648 | yyarg[yycount++] = yytname[yytoken]; |
1649 | if (!yypact_value_is_default (yyn)) | |
1650 | { | |
1651 | /* Start YYX at -YYN if negative to avoid negative indexes in | |
1652 | YYCHECK. In other words, skip the first -YYN actions for | |
1653 | this state because they are default actions. */ | |
1654 | int yyxbegin = yyn < 0 ? -yyn : 0; | |
1655 | /* Stay within bounds of both yycheck and yytname. */ | |
1656 | int yychecklim = YYLAST - yyn + 1; | |
1657 | int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS; | |
1658 | int yyx; | |
1659 | ||
1660 | for (yyx = yyxbegin; yyx < yyxend; ++yyx) | |
1661 | if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR | |
1662 | && !yytable_value_is_error (yytable[yyx + yyn])) | |
1663 | { | |
1664 | if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM) | |
1665 | { | |
1666 | yycount = 1; | |
1667 | yysize = yysize0; | |
1668 | break; | |
1669 | } | |
1670 | yyarg[yycount++] = yytname[yyx]; | |
1671 | { | |
712f80b0 CR |
1672 | YYPTRDIFF_T yysize1 |
1673 | = yysize + yytnamerr (YY_NULLPTR, yytname[yyx]); | |
1674 | if (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM) | |
1675 | yysize = yysize1; | |
1676 | else | |
a0c0a00f | 1677 | return 2; |
a0c0a00f CR |
1678 | } |
1679 | } | |
1680 | } | |
1681 | } | |
3185942a | 1682 | |
a0c0a00f CR |
1683 | switch (yycount) |
1684 | { | |
1685 | # define YYCASE_(N, S) \ | |
1686 | case N: \ | |
1687 | yyformat = S; \ | |
1688 | break | |
d233b485 | 1689 | default: /* Avoid compiler warnings. */ |
a0c0a00f CR |
1690 | YYCASE_(0, YY_("syntax error")); |
1691 | YYCASE_(1, YY_("syntax error, unexpected %s")); | |
1692 | YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s")); | |
1693 | YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s")); | |
1694 | YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s")); | |
1695 | YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s")); | |
1696 | # undef YYCASE_ | |
1697 | } | |
3185942a | 1698 | |
a0c0a00f | 1699 | { |
712f80b0 CR |
1700 | /* Don't count the "%s"s in the final size, but reserve room for |
1701 | the terminator. */ | |
1702 | YYPTRDIFF_T yysize1 = yysize + (yystrlen (yyformat) - 2 * yycount) + 1; | |
1703 | if (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM) | |
1704 | yysize = yysize1; | |
1705 | else | |
a0c0a00f | 1706 | return 2; |
a0c0a00f | 1707 | } |
3185942a | 1708 | |
a0c0a00f CR |
1709 | if (*yymsg_alloc < yysize) |
1710 | { | |
1711 | *yymsg_alloc = 2 * yysize; | |
1712 | if (! (yysize <= *yymsg_alloc | |
1713 | && *yymsg_alloc <= YYSTACK_ALLOC_MAXIMUM)) | |
1714 | *yymsg_alloc = YYSTACK_ALLOC_MAXIMUM; | |
1715 | return 1; | |
3185942a | 1716 | } |
a0c0a00f CR |
1717 | |
1718 | /* Avoid sprintf, as that infringes on the user's name space. | |
1719 | Don't have undefined behavior even if the translation | |
1720 | produced a string with the wrong number of "%s"s. */ | |
1721 | { | |
1722 | char *yyp = *yymsg; | |
1723 | int yyi = 0; | |
1724 | while ((*yyp = *yyformat) != '\0') | |
1725 | if (*yyp == '%' && yyformat[1] == 's' && yyi < yycount) | |
1726 | { | |
1727 | yyp += yytnamerr (yyp, yyarg[yyi++]); | |
1728 | yyformat += 2; | |
1729 | } | |
1730 | else | |
1731 | { | |
712f80b0 CR |
1732 | ++yyp; |
1733 | ++yyformat; | |
a0c0a00f CR |
1734 | } |
1735 | } | |
1736 | return 0; | |
726f6388 | 1737 | } |
3185942a | 1738 | #endif /* YYERROR_VERBOSE */ |
726f6388 | 1739 | |
3185942a JA |
1740 | /*-----------------------------------------------. |
1741 | | Release the memory associated to this symbol. | | |
1742 | `-----------------------------------------------*/ | |
726f6388 | 1743 | |
3185942a JA |
1744 | static void |
1745 | yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep) | |
7117c2d2 | 1746 | { |
3185942a | 1747 | YYUSE (yyvaluep); |
3185942a JA |
1748 | if (!yymsg) |
1749 | yymsg = "Deleting"; | |
1750 | YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp); | |
b80f6443 | 1751 | |
a0c0a00f CR |
1752 | YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN |
1753 | YYUSE (yytype); | |
1754 | YY_IGNORE_MAYBE_UNINITIALIZED_END | |
3185942a | 1755 | } |
f73dda09 | 1756 | |
3185942a | 1757 | |
726f6388 | 1758 | |
726f6388 | 1759 | |
a0c0a00f | 1760 | /* The lookahead symbol. */ |
3185942a | 1761 | int yychar; |
b80f6443 | 1762 | |
a0c0a00f | 1763 | /* The semantic value of the lookahead symbol. */ |
3185942a | 1764 | YYSTYPE yylval; |
3185942a JA |
1765 | /* Number of syntax errors so far. */ |
1766 | int yynerrs; | |
726f6388 | 1767 | |
3185942a | 1768 | |
3185942a JA |
1769 | /*----------. |
1770 | | yyparse. | | |
1771 | `----------*/ | |
1772 | ||
3185942a JA |
1773 | int |
1774 | yyparse (void) | |
3185942a | 1775 | { |
712f80b0 | 1776 | yy_state_fast_t yystate; |
a0c0a00f CR |
1777 | /* Number of tokens to shift before error messages enabled. */ |
1778 | int yyerrstatus; | |
1779 | ||
1780 | /* The stacks and their tools: | |
1781 | 'yyss': related to states. | |
1782 | 'yyvs': related to semantic values. | |
1783 | ||
1784 | Refer to the stacks through separate pointers, to allow yyoverflow | |
1785 | to reallocate them elsewhere. */ | |
1786 | ||
1787 | /* The state stack. */ | |
712f80b0 CR |
1788 | yy_state_t yyssa[YYINITDEPTH]; |
1789 | yy_state_t *yyss; | |
1790 | yy_state_t *yyssp; | |
a0c0a00f CR |
1791 | |
1792 | /* The semantic value stack. */ | |
1793 | YYSTYPE yyvsa[YYINITDEPTH]; | |
1794 | YYSTYPE *yyvs; | |
1795 | YYSTYPE *yyvsp; | |
1796 | ||
712f80b0 | 1797 | YYPTRDIFF_T yystacksize; |
a0c0a00f | 1798 | |
3185942a JA |
1799 | int yyn; |
1800 | int yyresult; | |
a0c0a00f | 1801 | /* Lookahead token as an internal (translated) token number. */ |
3185942a | 1802 | int yytoken = 0; |
a0c0a00f CR |
1803 | /* The variables used to return semantic value and location from the |
1804 | action routines. */ | |
1805 | YYSTYPE yyval; | |
1806 | ||
3185942a JA |
1807 | #if YYERROR_VERBOSE |
1808 | /* Buffer for error messages, and its allocated size. */ | |
1809 | char yymsgbuf[128]; | |
1810 | char *yymsg = yymsgbuf; | |
712f80b0 | 1811 | YYPTRDIFF_T yymsg_alloc = sizeof yymsgbuf; |
7117c2d2 | 1812 | #endif |
726f6388 | 1813 | |
3185942a JA |
1814 | #define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N)) |
1815 | ||
3185942a JA |
1816 | /* The number of symbols on the RHS of the reduced rule. |
1817 | Keep to zero when no symbol should be popped. */ | |
1818 | int yylen = 0; | |
1819 | ||
a0c0a00f CR |
1820 | yyssp = yyss = yyssa; |
1821 | yyvsp = yyvs = yyvsa; | |
1822 | yystacksize = YYINITDEPTH; | |
1823 | ||
3185942a | 1824 | YYDPRINTF ((stderr, "Starting parse\n")); |
726f6388 | 1825 | |
f73dda09 JA |
1826 | yystate = 0; |
1827 | yyerrstatus = 0; | |
1828 | yynerrs = 0; | |
a0c0a00f | 1829 | yychar = YYEMPTY; /* Cause a token to be read. */ |
3185942a | 1830 | goto yysetstate; |
f73dda09 | 1831 | |
712f80b0 | 1832 | |
3185942a | 1833 | /*------------------------------------------------------------. |
712f80b0 | 1834 | | yynewstate -- push a new state, which is found in yystate. | |
3185942a | 1835 | `------------------------------------------------------------*/ |
712f80b0 | 1836 | yynewstate: |
3185942a JA |
1837 | /* In all cases, when you get here, the value and location stacks |
1838 | have just been pushed. So pushing a state here evens the stacks. */ | |
1839 | yyssp++; | |
f73dda09 | 1840 | |
712f80b0 CR |
1841 | |
1842 | /*--------------------------------------------------------------------. | |
1843 | | yysetstate -- set current state (the top of the stack) to yystate. | | |
1844 | `--------------------------------------------------------------------*/ | |
1845 | yysetstate: | |
1846 | YYDPRINTF ((stderr, "Entering state %d\n", yystate)); | |
1847 | YY_ASSERT (0 <= yystate && yystate < YYNSTATES); | |
1848 | YY_IGNORE_USELESS_CAST_BEGIN | |
1849 | *yyssp = YY_CAST (yy_state_t, yystate); | |
1850 | YY_IGNORE_USELESS_CAST_END | |
b80f6443 | 1851 | |
3185942a | 1852 | if (yyss + yystacksize - 1 <= yyssp) |
712f80b0 CR |
1853 | #if !defined yyoverflow && !defined YYSTACK_RELOCATE |
1854 | goto yyexhaustedlab; | |
1855 | #else | |
3185942a | 1856 | { |
f73dda09 | 1857 | /* Get the current used size of the three stacks, in elements. */ |
712f80b0 | 1858 | YYPTRDIFF_T yysize = yyssp - yyss + 1; |
f73dda09 | 1859 | |
712f80b0 | 1860 | # if defined yyoverflow |
3185942a | 1861 | { |
a0c0a00f CR |
1862 | /* Give user a chance to reallocate the stack. Use copies of |
1863 | these so that the &'s don't force the real ones into | |
1864 | memory. */ | |
712f80b0 | 1865 | yy_state_t *yyss1 = yyss; |
a0c0a00f | 1866 | YYSTYPE *yyvs1 = yyvs; |
a0c0a00f CR |
1867 | |
1868 | /* Each stack pointer address is followed by the size of the | |
1869 | data in use in that stack, in bytes. This used to be a | |
1870 | conditional around just the two extra args, but that might | |
1871 | be undefined if yyoverflow is a macro. */ | |
1872 | yyoverflow (YY_("memory exhausted"), | |
712f80b0 CR |
1873 | &yyss1, yysize * YYSIZEOF (*yyssp), |
1874 | &yyvs1, yysize * YYSIZEOF (*yyvsp), | |
a0c0a00f | 1875 | &yystacksize); |
a0c0a00f CR |
1876 | yyss = yyss1; |
1877 | yyvs = yyvs1; | |
3185942a | 1878 | } |
712f80b0 | 1879 | # else /* defined YYSTACK_RELOCATE */ |
f73dda09 | 1880 | /* Extend the stack our own way. */ |
3185942a | 1881 | if (YYMAXDEPTH <= yystacksize) |
a0c0a00f | 1882 | goto yyexhaustedlab; |
f73dda09 | 1883 | yystacksize *= 2; |
3185942a | 1884 | if (YYMAXDEPTH < yystacksize) |
a0c0a00f | 1885 | yystacksize = YYMAXDEPTH; |
3185942a JA |
1886 | |
1887 | { | |
712f80b0 | 1888 | yy_state_t *yyss1 = yyss; |
a0c0a00f | 1889 | union yyalloc *yyptr = |
712f80b0 CR |
1890 | YY_CAST (union yyalloc *, |
1891 | YYSTACK_ALLOC (YY_CAST (YYSIZE_T, YYSTACK_BYTES (yystacksize)))); | |
a0c0a00f CR |
1892 | if (! yyptr) |
1893 | goto yyexhaustedlab; | |
1894 | YYSTACK_RELOCATE (yyss_alloc, yyss); | |
1895 | YYSTACK_RELOCATE (yyvs_alloc, yyvs); | |
712f80b0 | 1896 | # undef YYSTACK_RELOCATE |
a0c0a00f CR |
1897 | if (yyss1 != yyssa) |
1898 | YYSTACK_FREE (yyss1); | |
3185942a JA |
1899 | } |
1900 | # endif | |
726f6388 | 1901 | |
3185942a JA |
1902 | yyssp = yyss + yysize - 1; |
1903 | yyvsp = yyvs + yysize - 1; | |
726f6388 | 1904 | |
712f80b0 CR |
1905 | YY_IGNORE_USELESS_CAST_BEGIN |
1906 | YYDPRINTF ((stderr, "Stack size increased to %ld\n", | |
1907 | YY_CAST (long, yystacksize))); | |
1908 | YY_IGNORE_USELESS_CAST_END | |
3185942a JA |
1909 | |
1910 | if (yyss + yystacksize - 1 <= yyssp) | |
a0c0a00f | 1911 | YYABORT; |
726f6388 | 1912 | } |
712f80b0 | 1913 | #endif /* !defined yyoverflow && !defined YYSTACK_RELOCATE */ |
28ef6c31 | 1914 | |
a0c0a00f CR |
1915 | if (yystate == YYFINAL) |
1916 | YYACCEPT; | |
1917 | ||
f73dda09 | 1918 | goto yybackup; |
28ef6c31 | 1919 | |
712f80b0 | 1920 | |
3185942a JA |
1921 | /*-----------. |
1922 | | yybackup. | | |
1923 | `-----------*/ | |
1924 | yybackup: | |
3185942a | 1925 | /* Do appropriate processing given the current state. Read a |
a0c0a00f | 1926 | lookahead token if we need one and don't already have one. */ |
726f6388 | 1927 | |
a0c0a00f | 1928 | /* First try to decide what to do without reference to lookahead token. */ |
f73dda09 | 1929 | yyn = yypact[yystate]; |
a0c0a00f | 1930 | if (yypact_value_is_default (yyn)) |
f73dda09 | 1931 | goto yydefault; |
726f6388 | 1932 | |
a0c0a00f | 1933 | /* Not known => get a lookahead token if don't already have one. */ |
726f6388 | 1934 | |
a0c0a00f | 1935 | /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol. */ |
f73dda09 | 1936 | if (yychar == YYEMPTY) |
726f6388 | 1937 | { |
3185942a | 1938 | YYDPRINTF ((stderr, "Reading a token: ")); |
a0c0a00f | 1939 | yychar = yylex (); |
726f6388 | 1940 | } |
726f6388 | 1941 | |
3185942a | 1942 | if (yychar <= YYEOF) |
f73dda09 | 1943 | { |
3185942a JA |
1944 | yychar = yytoken = YYEOF; |
1945 | YYDPRINTF ((stderr, "Now at end of input.\n")); | |
f73dda09 JA |
1946 | } |
1947 | else | |
1948 | { | |
3185942a JA |
1949 | yytoken = YYTRANSLATE (yychar); |
1950 | YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc); | |
f73dda09 | 1951 | } |
726f6388 | 1952 | |
3185942a JA |
1953 | /* If the proper action on seeing token YYTOKEN is to reduce or to |
1954 | detect an error, take that action. */ | |
1955 | yyn += yytoken; | |
1956 | if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken) | |
f73dda09 | 1957 | goto yydefault; |
f73dda09 | 1958 | yyn = yytable[yyn]; |
3185942a | 1959 | if (yyn <= 0) |
f73dda09 | 1960 | { |
a0c0a00f CR |
1961 | if (yytable_value_is_error (yyn)) |
1962 | goto yyerrlab; | |
f73dda09 JA |
1963 | yyn = -yyn; |
1964 | goto yyreduce; | |
1965 | } | |
726f6388 | 1966 | |
3185942a JA |
1967 | /* Count tokens shifted since error; after three, turn off error |
1968 | status. */ | |
1969 | if (yyerrstatus) | |
1970 | yyerrstatus--; | |
b80f6443 | 1971 | |
a0c0a00f | 1972 | /* Shift the lookahead token. */ |
3185942a | 1973 | YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc); |
3185942a | 1974 | yystate = yyn; |
a0c0a00f | 1975 | YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN |
f73dda09 | 1976 | *++yyvsp = yylval; |
a0c0a00f | 1977 | YY_IGNORE_MAYBE_UNINITIALIZED_END |
28ef6c31 | 1978 | |
712f80b0 CR |
1979 | /* Discard the shifted token. */ |
1980 | yychar = YYEMPTY; | |
f73dda09 | 1981 | goto yynewstate; |
726f6388 | 1982 | |
b80f6443 | 1983 | |
3185942a JA |
1984 | /*-----------------------------------------------------------. |
1985 | | yydefault -- do the default action for the current state. | | |
1986 | `-----------------------------------------------------------*/ | |
1987 | yydefault: | |
f73dda09 JA |
1988 | yyn = yydefact[yystate]; |
1989 | if (yyn == 0) | |
1990 | goto yyerrlab; | |
3185942a | 1991 | goto yyreduce; |
28ef6c31 | 1992 | |
3185942a JA |
1993 | |
1994 | /*-----------------------------. | |
712f80b0 | 1995 | | yyreduce -- do a reduction. | |
3185942a | 1996 | `-----------------------------*/ |
f73dda09 | 1997 | yyreduce: |
3185942a | 1998 | /* yyn is the number of a rule to reduce with. */ |
f73dda09 | 1999 | yylen = yyr2[yyn]; |
28ef6c31 | 2000 | |
3185942a | 2001 | /* If YYLEN is nonzero, implement the default value of the action: |
a0c0a00f | 2002 | '$$ = $1'. |
28ef6c31 | 2003 | |
3185942a JA |
2004 | Otherwise, the following line sets YYVAL to garbage. |
2005 | This behavior is undocumented and Bison | |
2006 | users should not rely upon it. Assigning to YYVAL | |
2007 | unconditionally makes the parser a bit smaller, and it avoids a | |
2008 | GCC warning that YYVAL may be used uninitialized. */ | |
2009 | yyval = yyvsp[1-yylen]; | |
b80f6443 | 2010 | |
28ef6c31 | 2011 | |
3185942a JA |
2012 | YY_REDUCE_PRINT (yyn); |
2013 | switch (yyn) | |
2014 | { | |
712f80b0 CR |
2015 | case 2: |
2016 | #line 382 "/usr/src/local/chet/src/bash/src/parse.y" | |
2017 | { | |
f73dda09 JA |
2018 | /* Case of regular command. Discard the error |
2019 | safety net,and return the command just parsed. */ | |
a0c0a00f | 2020 | global_command = (yyvsp[-1].command); |
f73dda09 | 2021 | eof_encountered = 0; |
7117c2d2 | 2022 | /* discard_parser_constructs (0); */ |
3185942a JA |
2023 | if (parser_state & PST_CMDSUBST) |
2024 | parser_state |= PST_EOFTOKEN; | |
f73dda09 | 2025 | YYACCEPT; |
3185942a | 2026 | } |
712f80b0 | 2027 | #line 2028 "y.tab.c" |
3185942a JA |
2028 | break; |
2029 | ||
2030 | case 3: | |
712f80b0 CR |
2031 | #line 393 "/usr/src/local/chet/src/bash/src/parse.y" |
2032 | { | |
f73dda09 JA |
2033 | /* Case of regular command, but not a very |
2034 | interesting one. Return a NULL command. */ | |
2035 | global_command = (COMMAND *)NULL; | |
3185942a JA |
2036 | if (parser_state & PST_CMDSUBST) |
2037 | parser_state |= PST_EOFTOKEN; | |
f73dda09 | 2038 | YYACCEPT; |
3185942a | 2039 | } |
712f80b0 | 2040 | #line 2041 "y.tab.c" |
3185942a JA |
2041 | break; |
2042 | ||
2043 | case 4: | |
712f80b0 CR |
2044 | #line 402 "/usr/src/local/chet/src/bash/src/parse.y" |
2045 | { | |
f73dda09 JA |
2046 | /* Error during parsing. Return NULL command. */ |
2047 | global_command = (COMMAND *)NULL; | |
2048 | eof_encountered = 0; | |
7117c2d2 | 2049 | /* discard_parser_constructs (1); */ |
3185942a | 2050 | if (interactive && parse_and_execute_level == 0) |
f73dda09 JA |
2051 | { |
2052 | YYACCEPT; | |
2053 | } | |
2054 | else | |
2055 | { | |
2056 | YYABORT; | |
2057 | } | |
3185942a | 2058 | } |
712f80b0 | 2059 | #line 2060 "y.tab.c" |
3185942a JA |
2060 | break; |
2061 | ||
2062 | case 5: | |
712f80b0 CR |
2063 | #line 417 "/usr/src/local/chet/src/bash/src/parse.y" |
2064 | { | |
d233b485 CR |
2065 | /* EOF after an error. Do ignoreeof or not. Really |
2066 | only interesting in non-interactive shells */ | |
2067 | global_command = (COMMAND *)NULL; | |
2068 | if (last_command_exit_value == 0) | |
2069 | last_command_exit_value = EX_BADUSAGE; /* force error return */ | |
2070 | handle_eof_input_unit (); | |
2071 | if (interactive && parse_and_execute_level == 0) | |
2072 | { | |
2073 | YYACCEPT; | |
2074 | } | |
2075 | else | |
2076 | { | |
2077 | YYABORT; | |
2078 | } | |
2079 | } | |
712f80b0 | 2080 | #line 2081 "y.tab.c" |
d233b485 CR |
2081 | break; |
2082 | ||
2083 | case 6: | |
712f80b0 CR |
2084 | #line 434 "/usr/src/local/chet/src/bash/src/parse.y" |
2085 | { | |
f73dda09 JA |
2086 | /* Case of EOF seen by itself. Do ignoreeof or |
2087 | not. */ | |
2088 | global_command = (COMMAND *)NULL; | |
2089 | handle_eof_input_unit (); | |
2090 | YYACCEPT; | |
3185942a | 2091 | } |
712f80b0 | 2092 | #line 2093 "y.tab.c" |
3185942a JA |
2093 | break; |
2094 | ||
d233b485 | 2095 | case 7: |
712f80b0 CR |
2096 | #line 444 "/usr/src/local/chet/src/bash/src/parse.y" |
2097 | { (yyval.word_list) = make_word_list ((yyvsp[0].word), (WORD_LIST *)NULL); } | |
2098 | #line 2099 "y.tab.c" | |
3185942a JA |
2099 | break; |
2100 | ||
d233b485 | 2101 | case 8: |
712f80b0 CR |
2102 | #line 446 "/usr/src/local/chet/src/bash/src/parse.y" |
2103 | { (yyval.word_list) = make_word_list ((yyvsp[0].word), (yyvsp[-1].word_list)); } | |
2104 | #line 2105 "y.tab.c" | |
3185942a JA |
2105 | break; |
2106 | ||
d233b485 | 2107 | case 9: |
712f80b0 CR |
2108 | #line 450 "/usr/src/local/chet/src/bash/src/parse.y" |
2109 | { | |
0001803f | 2110 | source.dest = 1; |
a0c0a00f | 2111 | redir.filename = (yyvsp[0].word); |
0001803f | 2112 | (yyval.redirect) = make_redirection (source, r_output_direction, redir, 0); |
3185942a | 2113 | } |
712f80b0 | 2114 | #line 2115 "y.tab.c" |
3185942a JA |
2115 | break; |
2116 | ||
d233b485 | 2117 | case 10: |
712f80b0 CR |
2118 | #line 456 "/usr/src/local/chet/src/bash/src/parse.y" |
2119 | { | |
0001803f | 2120 | source.dest = 0; |
a0c0a00f | 2121 | redir.filename = (yyvsp[0].word); |
0001803f | 2122 | (yyval.redirect) = make_redirection (source, r_input_direction, redir, 0); |
3185942a | 2123 | } |
712f80b0 | 2124 | #line 2125 "y.tab.c" |
3185942a JA |
2125 | break; |
2126 | ||
d233b485 | 2127 | case 11: |
712f80b0 CR |
2128 | #line 462 "/usr/src/local/chet/src/bash/src/parse.y" |
2129 | { | |
a0c0a00f CR |
2130 | source.dest = (yyvsp[-2].number); |
2131 | redir.filename = (yyvsp[0].word); | |
0001803f | 2132 | (yyval.redirect) = make_redirection (source, r_output_direction, redir, 0); |
3185942a | 2133 | } |
712f80b0 | 2134 | #line 2135 "y.tab.c" |
3185942a JA |
2135 | break; |
2136 | ||
d233b485 | 2137 | case 12: |
712f80b0 CR |
2138 | #line 468 "/usr/src/local/chet/src/bash/src/parse.y" |
2139 | { | |
a0c0a00f CR |
2140 | source.dest = (yyvsp[-2].number); |
2141 | redir.filename = (yyvsp[0].word); | |
0001803f | 2142 | (yyval.redirect) = make_redirection (source, r_input_direction, redir, 0); |
3185942a | 2143 | } |
712f80b0 | 2144 | #line 2145 "y.tab.c" |
3185942a JA |
2145 | break; |
2146 | ||
d233b485 | 2147 | case 13: |
712f80b0 CR |
2148 | #line 474 "/usr/src/local/chet/src/bash/src/parse.y" |
2149 | { | |
a0c0a00f CR |
2150 | source.filename = (yyvsp[-2].word); |
2151 | redir.filename = (yyvsp[0].word); | |
0001803f | 2152 | (yyval.redirect) = make_redirection (source, r_output_direction, redir, REDIR_VARASSIGN); |
3185942a | 2153 | } |
712f80b0 | 2154 | #line 2155 "y.tab.c" |
3185942a JA |
2155 | break; |
2156 | ||
d233b485 | 2157 | case 14: |
712f80b0 CR |
2158 | #line 480 "/usr/src/local/chet/src/bash/src/parse.y" |
2159 | { | |
a0c0a00f CR |
2160 | source.filename = (yyvsp[-2].word); |
2161 | redir.filename = (yyvsp[0].word); | |
0001803f | 2162 | (yyval.redirect) = make_redirection (source, r_input_direction, redir, REDIR_VARASSIGN); |
3185942a | 2163 | } |
712f80b0 | 2164 | #line 2165 "y.tab.c" |
3185942a JA |
2165 | break; |
2166 | ||
d233b485 | 2167 | case 15: |
712f80b0 CR |
2168 | #line 486 "/usr/src/local/chet/src/bash/src/parse.y" |
2169 | { | |
0001803f | 2170 | source.dest = 1; |
a0c0a00f | 2171 | redir.filename = (yyvsp[0].word); |
0001803f | 2172 | (yyval.redirect) = make_redirection (source, r_appending_to, redir, 0); |
3185942a | 2173 | } |
712f80b0 | 2174 | #line 2175 "y.tab.c" |
3185942a JA |
2175 | break; |
2176 | ||
d233b485 | 2177 | case 16: |
712f80b0 CR |
2178 | #line 492 "/usr/src/local/chet/src/bash/src/parse.y" |
2179 | { | |
a0c0a00f CR |
2180 | source.dest = (yyvsp[-2].number); |
2181 | redir.filename = (yyvsp[0].word); | |
0001803f | 2182 | (yyval.redirect) = make_redirection (source, r_appending_to, redir, 0); |
3185942a | 2183 | } |
712f80b0 | 2184 | #line 2185 "y.tab.c" |
3185942a JA |
2185 | break; |
2186 | ||
d233b485 | 2187 | case 17: |
712f80b0 CR |
2188 | #line 498 "/usr/src/local/chet/src/bash/src/parse.y" |
2189 | { | |
a0c0a00f CR |
2190 | source.filename = (yyvsp[-2].word); |
2191 | redir.filename = (yyvsp[0].word); | |
0001803f | 2192 | (yyval.redirect) = make_redirection (source, r_appending_to, redir, REDIR_VARASSIGN); |
3185942a | 2193 | } |
712f80b0 | 2194 | #line 2195 "y.tab.c" |
3185942a JA |
2195 | break; |
2196 | ||
d233b485 | 2197 | case 18: |
712f80b0 CR |
2198 | #line 504 "/usr/src/local/chet/src/bash/src/parse.y" |
2199 | { | |
0001803f | 2200 | source.dest = 1; |
a0c0a00f | 2201 | redir.filename = (yyvsp[0].word); |
0001803f | 2202 | (yyval.redirect) = make_redirection (source, r_output_force, redir, 0); |
3185942a | 2203 | } |
712f80b0 | 2204 | #line 2205 "y.tab.c" |
3185942a JA |
2205 | break; |
2206 | ||
d233b485 | 2207 | case 19: |
712f80b0 CR |
2208 | #line 510 "/usr/src/local/chet/src/bash/src/parse.y" |
2209 | { | |
a0c0a00f CR |
2210 | source.dest = (yyvsp[-2].number); |
2211 | redir.filename = (yyvsp[0].word); | |
0001803f | 2212 | (yyval.redirect) = make_redirection (source, r_output_force, redir, 0); |
3185942a | 2213 | } |
712f80b0 | 2214 | #line 2215 "y.tab.c" |
3185942a JA |
2215 | break; |
2216 | ||
d233b485 | 2217 | case 20: |
712f80b0 CR |
2218 | #line 516 "/usr/src/local/chet/src/bash/src/parse.y" |
2219 | { | |
a0c0a00f CR |
2220 | source.filename = (yyvsp[-2].word); |
2221 | redir.filename = (yyvsp[0].word); | |
0001803f | 2222 | (yyval.redirect) = make_redirection (source, r_output_force, redir, REDIR_VARASSIGN); |
3185942a | 2223 | } |
712f80b0 | 2224 | #line 2225 "y.tab.c" |
3185942a JA |
2225 | break; |
2226 | ||
d233b485 | 2227 | case 21: |
712f80b0 CR |
2228 | #line 522 "/usr/src/local/chet/src/bash/src/parse.y" |
2229 | { | |
0001803f | 2230 | source.dest = 0; |
a0c0a00f | 2231 | redir.filename = (yyvsp[0].word); |
0001803f | 2232 | (yyval.redirect) = make_redirection (source, r_input_output, redir, 0); |
3185942a | 2233 | } |
712f80b0 | 2234 | #line 2235 "y.tab.c" |
3185942a JA |
2235 | break; |
2236 | ||
d233b485 | 2237 | case 22: |
712f80b0 CR |
2238 | #line 528 "/usr/src/local/chet/src/bash/src/parse.y" |
2239 | { | |
a0c0a00f CR |
2240 | source.dest = (yyvsp[-2].number); |
2241 | redir.filename = (yyvsp[0].word); | |
0001803f | 2242 | (yyval.redirect) = make_redirection (source, r_input_output, redir, 0); |
3185942a | 2243 | } |
712f80b0 | 2244 | #line 2245 "y.tab.c" |
3185942a JA |
2245 | break; |
2246 | ||
d233b485 | 2247 | case 23: |
712f80b0 CR |
2248 | #line 534 "/usr/src/local/chet/src/bash/src/parse.y" |
2249 | { | |
a0c0a00f CR |
2250 | source.filename = (yyvsp[-2].word); |
2251 | redir.filename = (yyvsp[0].word); | |
0001803f | 2252 | (yyval.redirect) = make_redirection (source, r_input_output, redir, REDIR_VARASSIGN); |
3185942a | 2253 | } |
712f80b0 | 2254 | #line 2255 "y.tab.c" |
3185942a JA |
2255 | break; |
2256 | ||
d233b485 | 2257 | case 24: |
712f80b0 CR |
2258 | #line 540 "/usr/src/local/chet/src/bash/src/parse.y" |
2259 | { | |
0001803f | 2260 | source.dest = 0; |
a0c0a00f | 2261 | redir.filename = (yyvsp[0].word); |
0001803f | 2262 | (yyval.redirect) = make_redirection (source, r_reading_until, redir, 0); |
90a39f32 | 2263 | push_heredoc ((yyval.redirect)); |
3185942a | 2264 | } |
712f80b0 | 2265 | #line 2266 "y.tab.c" |
3185942a JA |
2266 | break; |
2267 | ||
d233b485 | 2268 | case 25: |
712f80b0 CR |
2269 | #line 547 "/usr/src/local/chet/src/bash/src/parse.y" |
2270 | { | |
a0c0a00f CR |
2271 | source.dest = (yyvsp[-2].number); |
2272 | redir.filename = (yyvsp[0].word); | |
0001803f | 2273 | (yyval.redirect) = make_redirection (source, r_reading_until, redir, 0); |
90a39f32 | 2274 | push_heredoc ((yyval.redirect)); |
3185942a | 2275 | } |
712f80b0 | 2276 | #line 2277 "y.tab.c" |
3185942a JA |
2277 | break; |
2278 | ||
d233b485 | 2279 | case 26: |
712f80b0 CR |
2280 | #line 554 "/usr/src/local/chet/src/bash/src/parse.y" |
2281 | { | |
a0c0a00f CR |
2282 | source.filename = (yyvsp[-2].word); |
2283 | redir.filename = (yyvsp[0].word); | |
0001803f | 2284 | (yyval.redirect) = make_redirection (source, r_reading_until, redir, REDIR_VARASSIGN); |
90a39f32 | 2285 | push_heredoc ((yyval.redirect)); |
3185942a | 2286 | } |
712f80b0 | 2287 | #line 2288 "y.tab.c" |
3185942a JA |
2288 | break; |
2289 | ||
d233b485 | 2290 | case 27: |
712f80b0 CR |
2291 | #line 561 "/usr/src/local/chet/src/bash/src/parse.y" |
2292 | { | |
0001803f | 2293 | source.dest = 0; |
a0c0a00f | 2294 | redir.filename = (yyvsp[0].word); |
0001803f | 2295 | (yyval.redirect) = make_redirection (source, r_deblank_reading_until, redir, 0); |
90a39f32 | 2296 | push_heredoc ((yyval.redirect)); |
3185942a | 2297 | } |
712f80b0 | 2298 | #line 2299 "y.tab.c" |
3185942a JA |
2299 | break; |
2300 | ||
d233b485 | 2301 | case 28: |
712f80b0 CR |
2302 | #line 568 "/usr/src/local/chet/src/bash/src/parse.y" |
2303 | { | |
a0c0a00f CR |
2304 | source.dest = (yyvsp[-2].number); |
2305 | redir.filename = (yyvsp[0].word); | |
0001803f | 2306 | (yyval.redirect) = make_redirection (source, r_deblank_reading_until, redir, 0); |
90a39f32 | 2307 | push_heredoc ((yyval.redirect)); |
3185942a | 2308 | } |
712f80b0 | 2309 | #line 2310 "y.tab.c" |
3185942a JA |
2310 | break; |
2311 | ||
d233b485 | 2312 | case 29: |
712f80b0 CR |
2313 | #line 575 "/usr/src/local/chet/src/bash/src/parse.y" |
2314 | { | |
a0c0a00f CR |
2315 | source.filename = (yyvsp[-2].word); |
2316 | redir.filename = (yyvsp[0].word); | |
0001803f | 2317 | (yyval.redirect) = make_redirection (source, r_deblank_reading_until, redir, REDIR_VARASSIGN); |
90a39f32 | 2318 | push_heredoc ((yyval.redirect)); |
3185942a | 2319 | } |
712f80b0 | 2320 | #line 2321 "y.tab.c" |
3185942a JA |
2321 | break; |
2322 | ||
d233b485 | 2323 | case 30: |
712f80b0 CR |
2324 | #line 582 "/usr/src/local/chet/src/bash/src/parse.y" |
2325 | { | |
0001803f | 2326 | source.dest = 0; |
a0c0a00f | 2327 | redir.filename = (yyvsp[0].word); |
0001803f | 2328 | (yyval.redirect) = make_redirection (source, r_reading_string, redir, 0); |
3185942a | 2329 | } |
712f80b0 | 2330 | #line 2331 "y.tab.c" |
3185942a JA |
2331 | break; |
2332 | ||
d233b485 | 2333 | case 31: |
712f80b0 CR |
2334 | #line 588 "/usr/src/local/chet/src/bash/src/parse.y" |
2335 | { | |
a0c0a00f CR |
2336 | source.dest = (yyvsp[-2].number); |
2337 | redir.filename = (yyvsp[0].word); | |
0001803f | 2338 | (yyval.redirect) = make_redirection (source, r_reading_string, redir, 0); |
3185942a | 2339 | } |
712f80b0 | 2340 | #line 2341 "y.tab.c" |
3185942a JA |
2341 | break; |
2342 | ||
d233b485 | 2343 | case 32: |
712f80b0 CR |
2344 | #line 594 "/usr/src/local/chet/src/bash/src/parse.y" |
2345 | { | |
a0c0a00f CR |
2346 | source.filename = (yyvsp[-2].word); |
2347 | redir.filename = (yyvsp[0].word); | |
0001803f | 2348 | (yyval.redirect) = make_redirection (source, r_reading_string, redir, REDIR_VARASSIGN); |
3185942a | 2349 | } |
712f80b0 | 2350 | #line 2351 "y.tab.c" |
3185942a JA |
2351 | break; |
2352 | ||
d233b485 | 2353 | case 33: |
712f80b0 CR |
2354 | #line 600 "/usr/src/local/chet/src/bash/src/parse.y" |
2355 | { | |
0001803f | 2356 | source.dest = 0; |
a0c0a00f | 2357 | redir.dest = (yyvsp[0].number); |
0001803f | 2358 | (yyval.redirect) = make_redirection (source, r_duplicating_input, redir, 0); |
3185942a | 2359 | } |
712f80b0 | 2360 | #line 2361 "y.tab.c" |
3185942a JA |
2361 | break; |
2362 | ||
d233b485 | 2363 | case 34: |
712f80b0 CR |
2364 | #line 606 "/usr/src/local/chet/src/bash/src/parse.y" |
2365 | { | |
a0c0a00f CR |
2366 | source.dest = (yyvsp[-2].number); |
2367 | redir.dest = (yyvsp[0].number); | |
0001803f | 2368 | (yyval.redirect) = make_redirection (source, r_duplicating_input, redir, 0); |
3185942a | 2369 | } |
712f80b0 | 2370 | #line 2371 "y.tab.c" |
3185942a JA |
2371 | break; |
2372 | ||
d233b485 | 2373 | case 35: |
712f80b0 CR |
2374 | #line 612 "/usr/src/local/chet/src/bash/src/parse.y" |
2375 | { | |
a0c0a00f CR |
2376 | source.filename = (yyvsp[-2].word); |
2377 | redir.dest = (yyvsp[0].number); | |
0001803f | 2378 | (yyval.redirect) = make_redirection (source, r_duplicating_input, redir, REDIR_VARASSIGN); |
3185942a | 2379 | } |
712f80b0 | 2380 | #line 2381 "y.tab.c" |
3185942a JA |
2381 | break; |
2382 | ||
d233b485 | 2383 | case 36: |
712f80b0 CR |
2384 | #line 618 "/usr/src/local/chet/src/bash/src/parse.y" |
2385 | { | |
0001803f | 2386 | source.dest = 1; |
a0c0a00f | 2387 | redir.dest = (yyvsp[0].number); |
0001803f | 2388 | (yyval.redirect) = make_redirection (source, r_duplicating_output, redir, 0); |
3185942a | 2389 | } |
712f80b0 | 2390 | #line 2391 "y.tab.c" |
3185942a JA |
2391 | break; |
2392 | ||
d233b485 | 2393 | case 37: |
712f80b0 CR |
2394 | #line 624 "/usr/src/local/chet/src/bash/src/parse.y" |
2395 | { | |
a0c0a00f CR |
2396 | source.dest = (yyvsp[-2].number); |
2397 | redir.dest = (yyvsp[0].number); | |
0001803f | 2398 | (yyval.redirect) = make_redirection (source, r_duplicating_output, redir, 0); |
3185942a | 2399 | } |
712f80b0 | 2400 | #line 2401 "y.tab.c" |
3185942a JA |
2401 | break; |
2402 | ||
d233b485 | 2403 | case 38: |
712f80b0 CR |
2404 | #line 630 "/usr/src/local/chet/src/bash/src/parse.y" |
2405 | { | |
a0c0a00f CR |
2406 | source.filename = (yyvsp[-2].word); |
2407 | redir.dest = (yyvsp[0].number); | |
0001803f | 2408 | (yyval.redirect) = make_redirection (source, r_duplicating_output, redir, REDIR_VARASSIGN); |
3185942a | 2409 | } |
712f80b0 | 2410 | #line 2411 "y.tab.c" |
3185942a JA |
2411 | break; |
2412 | ||
d233b485 | 2413 | case 39: |
712f80b0 CR |
2414 | #line 636 "/usr/src/local/chet/src/bash/src/parse.y" |
2415 | { | |
0001803f | 2416 | source.dest = 0; |
a0c0a00f | 2417 | redir.filename = (yyvsp[0].word); |
0001803f CR |
2418 | (yyval.redirect) = make_redirection (source, r_duplicating_input_word, redir, 0); |
2419 | } | |
712f80b0 | 2420 | #line 2421 "y.tab.c" |
3185942a JA |
2421 | break; |
2422 | ||
d233b485 | 2423 | case 40: |
712f80b0 CR |
2424 | #line 642 "/usr/src/local/chet/src/bash/src/parse.y" |
2425 | { | |
a0c0a00f CR |
2426 | source.dest = (yyvsp[-2].number); |
2427 | redir.filename = (yyvsp[0].word); | |
0001803f CR |
2428 | (yyval.redirect) = make_redirection (source, r_duplicating_input_word, redir, 0); |
2429 | } | |
712f80b0 | 2430 | #line 2431 "y.tab.c" |
3185942a JA |
2431 | break; |
2432 | ||
d233b485 | 2433 | case 41: |
712f80b0 CR |
2434 | #line 648 "/usr/src/local/chet/src/bash/src/parse.y" |
2435 | { | |
a0c0a00f CR |
2436 | source.filename = (yyvsp[-2].word); |
2437 | redir.filename = (yyvsp[0].word); | |
0001803f CR |
2438 | (yyval.redirect) = make_redirection (source, r_duplicating_input_word, redir, REDIR_VARASSIGN); |
2439 | } | |
712f80b0 | 2440 | #line 2441 "y.tab.c" |
3185942a JA |
2441 | break; |
2442 | ||
d233b485 | 2443 | case 42: |
712f80b0 CR |
2444 | #line 654 "/usr/src/local/chet/src/bash/src/parse.y" |
2445 | { | |
0001803f | 2446 | source.dest = 1; |
a0c0a00f | 2447 | redir.filename = (yyvsp[0].word); |
0001803f | 2448 | (yyval.redirect) = make_redirection (source, r_duplicating_output_word, redir, 0); |
3185942a | 2449 | } |
712f80b0 | 2450 | #line 2451 "y.tab.c" |
3185942a JA |
2451 | break; |
2452 | ||
d233b485 | 2453 | case 43: |
712f80b0 CR |
2454 | #line 660 "/usr/src/local/chet/src/bash/src/parse.y" |
2455 | { | |
a0c0a00f CR |
2456 | source.dest = (yyvsp[-2].number); |
2457 | redir.filename = (yyvsp[0].word); | |
0001803f CR |
2458 | (yyval.redirect) = make_redirection (source, r_duplicating_output_word, redir, 0); |
2459 | } | |
712f80b0 | 2460 | #line 2461 "y.tab.c" |
0001803f CR |
2461 | break; |
2462 | ||
d233b485 | 2463 | case 44: |
712f80b0 CR |
2464 | #line 666 "/usr/src/local/chet/src/bash/src/parse.y" |
2465 | { | |
a0c0a00f CR |
2466 | source.filename = (yyvsp[-2].word); |
2467 | redir.filename = (yyvsp[0].word); | |
0001803f CR |
2468 | (yyval.redirect) = make_redirection (source, r_duplicating_output_word, redir, REDIR_VARASSIGN); |
2469 | } | |
712f80b0 | 2470 | #line 2471 "y.tab.c" |
0001803f CR |
2471 | break; |
2472 | ||
d233b485 | 2473 | case 45: |
712f80b0 CR |
2474 | #line 672 "/usr/src/local/chet/src/bash/src/parse.y" |
2475 | { | |
0001803f CR |
2476 | source.dest = 1; |
2477 | redir.dest = 0; | |
2478 | (yyval.redirect) = make_redirection (source, r_close_this, redir, 0); | |
2479 | } | |
712f80b0 | 2480 | #line 2481 "y.tab.c" |
0001803f CR |
2481 | break; |
2482 | ||
d233b485 | 2483 | case 46: |
712f80b0 CR |
2484 | #line 678 "/usr/src/local/chet/src/bash/src/parse.y" |
2485 | { | |
a0c0a00f | 2486 | source.dest = (yyvsp[-2].number); |
0001803f CR |
2487 | redir.dest = 0; |
2488 | (yyval.redirect) = make_redirection (source, r_close_this, redir, 0); | |
2489 | } | |
712f80b0 | 2490 | #line 2491 "y.tab.c" |
0001803f CR |
2491 | break; |
2492 | ||
d233b485 | 2493 | case 47: |
712f80b0 CR |
2494 | #line 684 "/usr/src/local/chet/src/bash/src/parse.y" |
2495 | { | |
a0c0a00f | 2496 | source.filename = (yyvsp[-2].word); |
0001803f CR |
2497 | redir.dest = 0; |
2498 | (yyval.redirect) = make_redirection (source, r_close_this, redir, REDIR_VARASSIGN); | |
2499 | } | |
712f80b0 | 2500 | #line 2501 "y.tab.c" |
0001803f CR |
2501 | break; |
2502 | ||
d233b485 | 2503 | case 48: |
712f80b0 CR |
2504 | #line 690 "/usr/src/local/chet/src/bash/src/parse.y" |
2505 | { | |
0001803f CR |
2506 | source.dest = 0; |
2507 | redir.dest = 0; | |
2508 | (yyval.redirect) = make_redirection (source, r_close_this, redir, 0); | |
2509 | } | |
712f80b0 | 2510 | #line 2511 "y.tab.c" |
0001803f CR |
2511 | break; |
2512 | ||
d233b485 | 2513 | case 49: |
712f80b0 CR |
2514 | #line 696 "/usr/src/local/chet/src/bash/src/parse.y" |
2515 | { | |
a0c0a00f | 2516 | source.dest = (yyvsp[-2].number); |
0001803f CR |
2517 | redir.dest = 0; |
2518 | (yyval.redirect) = make_redirection (source, r_close_this, redir, 0); | |
2519 | } | |
712f80b0 | 2520 | #line 2521 "y.tab.c" |
0001803f CR |
2521 | break; |
2522 | ||
d233b485 | 2523 | case 50: |
712f80b0 CR |
2524 | #line 702 "/usr/src/local/chet/src/bash/src/parse.y" |
2525 | { | |
a0c0a00f | 2526 | source.filename = (yyvsp[-2].word); |
0001803f CR |
2527 | redir.dest = 0; |
2528 | (yyval.redirect) = make_redirection (source, r_close_this, redir, REDIR_VARASSIGN); | |
2529 | } | |
712f80b0 | 2530 | #line 2531 "y.tab.c" |
0001803f CR |
2531 | break; |
2532 | ||
d233b485 | 2533 | case 51: |
712f80b0 CR |
2534 | #line 708 "/usr/src/local/chet/src/bash/src/parse.y" |
2535 | { | |
0001803f | 2536 | source.dest = 1; |
a0c0a00f | 2537 | redir.filename = (yyvsp[0].word); |
0001803f CR |
2538 | (yyval.redirect) = make_redirection (source, r_err_and_out, redir, 0); |
2539 | } | |
712f80b0 | 2540 | #line 2541 "y.tab.c" |
0001803f CR |
2541 | break; |
2542 | ||
d233b485 | 2543 | case 52: |
712f80b0 CR |
2544 | #line 714 "/usr/src/local/chet/src/bash/src/parse.y" |
2545 | { | |
0001803f | 2546 | source.dest = 1; |
a0c0a00f | 2547 | redir.filename = (yyvsp[0].word); |
0001803f CR |
2548 | (yyval.redirect) = make_redirection (source, r_append_err_and_out, redir, 0); |
2549 | } | |
712f80b0 | 2550 | #line 2551 "y.tab.c" |
0001803f CR |
2551 | break; |
2552 | ||
d233b485 | 2553 | case 53: |
712f80b0 CR |
2554 | #line 722 "/usr/src/local/chet/src/bash/src/parse.y" |
2555 | { (yyval.element).word = (yyvsp[0].word); (yyval.element).redirect = 0; } | |
2556 | #line 2557 "y.tab.c" | |
0001803f CR |
2557 | break; |
2558 | ||
d233b485 | 2559 | case 54: |
712f80b0 CR |
2560 | #line 724 "/usr/src/local/chet/src/bash/src/parse.y" |
2561 | { (yyval.element).word = (yyvsp[0].word); (yyval.element).redirect = 0; } | |
2562 | #line 2563 "y.tab.c" | |
0001803f CR |
2563 | break; |
2564 | ||
d233b485 | 2565 | case 55: |
712f80b0 CR |
2566 | #line 726 "/usr/src/local/chet/src/bash/src/parse.y" |
2567 | { (yyval.element).redirect = (yyvsp[0].redirect); (yyval.element).word = 0; } | |
2568 | #line 2569 "y.tab.c" | |
0001803f CR |
2569 | break; |
2570 | ||
d233b485 | 2571 | case 56: |
712f80b0 CR |
2572 | #line 730 "/usr/src/local/chet/src/bash/src/parse.y" |
2573 | { | |
a0c0a00f | 2574 | (yyval.redirect) = (yyvsp[0].redirect); |
0001803f | 2575 | } |
712f80b0 | 2576 | #line 2577 "y.tab.c" |
0001803f CR |
2577 | break; |
2578 | ||
d233b485 | 2579 | case 57: |
712f80b0 CR |
2580 | #line 734 "/usr/src/local/chet/src/bash/src/parse.y" |
2581 | { | |
f73dda09 JA |
2582 | register REDIRECT *t; |
2583 | ||
a0c0a00f | 2584 | for (t = (yyvsp[-1].redirect); t->next; t = t->next) |
f73dda09 | 2585 | ; |
a0c0a00f CR |
2586 | t->next = (yyvsp[0].redirect); |
2587 | (yyval.redirect) = (yyvsp[-1].redirect); | |
3185942a | 2588 | } |
712f80b0 | 2589 | #line 2590 "y.tab.c" |
3185942a JA |
2590 | break; |
2591 | ||
d233b485 | 2592 | case 58: |
712f80b0 CR |
2593 | #line 745 "/usr/src/local/chet/src/bash/src/parse.y" |
2594 | { (yyval.command) = make_simple_command ((yyvsp[0].element), (COMMAND *)NULL); } | |
2595 | #line 2596 "y.tab.c" | |
3185942a JA |
2596 | break; |
2597 | ||
d233b485 | 2598 | case 59: |
712f80b0 CR |
2599 | #line 747 "/usr/src/local/chet/src/bash/src/parse.y" |
2600 | { (yyval.command) = make_simple_command ((yyvsp[0].element), (yyvsp[-1].command)); } | |
2601 | #line 2602 "y.tab.c" | |
3185942a JA |
2602 | break; |
2603 | ||
d233b485 | 2604 | case 60: |
712f80b0 CR |
2605 | #line 751 "/usr/src/local/chet/src/bash/src/parse.y" |
2606 | { (yyval.command) = clean_simple_command ((yyvsp[0].command)); } | |
2607 | #line 2608 "y.tab.c" | |
3185942a JA |
2608 | break; |
2609 | ||
d233b485 | 2610 | case 61: |
712f80b0 CR |
2611 | #line 753 "/usr/src/local/chet/src/bash/src/parse.y" |
2612 | { (yyval.command) = (yyvsp[0].command); } | |
2613 | #line 2614 "y.tab.c" | |
3185942a JA |
2614 | break; |
2615 | ||
d233b485 | 2616 | case 62: |
712f80b0 CR |
2617 | #line 755 "/usr/src/local/chet/src/bash/src/parse.y" |
2618 | { | |
f73dda09 JA |
2619 | COMMAND *tc; |
2620 | ||
a0c0a00f | 2621 | tc = (yyvsp[-1].command); |
d233b485 | 2622 | if (tc && tc->redirects) |
f73dda09 JA |
2623 | { |
2624 | register REDIRECT *t; | |
2625 | for (t = tc->redirects; t->next; t = t->next) | |
2626 | ; | |
a0c0a00f | 2627 | t->next = (yyvsp[0].redirect); |
f73dda09 | 2628 | } |
d233b485 | 2629 | else if (tc) |
a0c0a00f CR |
2630 | tc->redirects = (yyvsp[0].redirect); |
2631 | (yyval.command) = (yyvsp[-1].command); | |
3185942a | 2632 | } |
712f80b0 | 2633 | #line 2634 "y.tab.c" |
3185942a JA |
2634 | break; |
2635 | ||
0001803f | 2636 | case 63: |
712f80b0 CR |
2637 | #line 771 "/usr/src/local/chet/src/bash/src/parse.y" |
2638 | { (yyval.command) = (yyvsp[0].command); } | |
2639 | #line 2640 "y.tab.c" | |
3185942a JA |
2640 | break; |
2641 | ||
0001803f | 2642 | case 64: |
712f80b0 CR |
2643 | #line 773 "/usr/src/local/chet/src/bash/src/parse.y" |
2644 | { (yyval.command) = (yyvsp[0].command); } | |
2645 | #line 2646 "y.tab.c" | |
3185942a JA |
2646 | break; |
2647 | ||
0001803f | 2648 | case 65: |
712f80b0 CR |
2649 | #line 777 "/usr/src/local/chet/src/bash/src/parse.y" |
2650 | { (yyval.command) = (yyvsp[0].command); } | |
2651 | #line 2652 "y.tab.c" | |
3185942a JA |
2652 | break; |
2653 | ||
0001803f | 2654 | case 66: |
712f80b0 CR |
2655 | #line 779 "/usr/src/local/chet/src/bash/src/parse.y" |
2656 | { (yyval.command) = (yyvsp[0].command); } | |
2657 | #line 2658 "y.tab.c" | |
3185942a JA |
2658 | break; |
2659 | ||
0001803f | 2660 | case 67: |
712f80b0 CR |
2661 | #line 781 "/usr/src/local/chet/src/bash/src/parse.y" |
2662 | { (yyval.command) = make_while_command ((yyvsp[-3].command), (yyvsp[-1].command)); } | |
2663 | #line 2664 "y.tab.c" | |
3185942a JA |
2664 | break; |
2665 | ||
0001803f | 2666 | case 68: |
712f80b0 CR |
2667 | #line 783 "/usr/src/local/chet/src/bash/src/parse.y" |
2668 | { (yyval.command) = make_until_command ((yyvsp[-3].command), (yyvsp[-1].command)); } | |
2669 | #line 2670 "y.tab.c" | |
3185942a JA |
2670 | break; |
2671 | ||
0001803f | 2672 | case 69: |
712f80b0 CR |
2673 | #line 785 "/usr/src/local/chet/src/bash/src/parse.y" |
2674 | { (yyval.command) = (yyvsp[0].command); } | |
2675 | #line 2676 "y.tab.c" | |
3185942a JA |
2676 | break; |
2677 | ||
0001803f | 2678 | case 70: |
712f80b0 CR |
2679 | #line 787 "/usr/src/local/chet/src/bash/src/parse.y" |
2680 | { (yyval.command) = (yyvsp[0].command); } | |
2681 | #line 2682 "y.tab.c" | |
3185942a JA |
2682 | break; |
2683 | ||
0001803f | 2684 | case 71: |
712f80b0 CR |
2685 | #line 789 "/usr/src/local/chet/src/bash/src/parse.y" |
2686 | { (yyval.command) = (yyvsp[0].command); } | |
2687 | #line 2688 "y.tab.c" | |
3185942a JA |
2688 | break; |
2689 | ||
0001803f | 2690 | case 72: |
712f80b0 CR |
2691 | #line 791 "/usr/src/local/chet/src/bash/src/parse.y" |
2692 | { (yyval.command) = (yyvsp[0].command); } | |
2693 | #line 2694 "y.tab.c" | |
3185942a JA |
2694 | break; |
2695 | ||
0001803f | 2696 | case 73: |
712f80b0 CR |
2697 | #line 793 "/usr/src/local/chet/src/bash/src/parse.y" |
2698 | { (yyval.command) = (yyvsp[0].command); } | |
2699 | #line 2700 "y.tab.c" | |
3185942a JA |
2700 | break; |
2701 | ||
0001803f | 2702 | case 74: |
712f80b0 CR |
2703 | #line 795 "/usr/src/local/chet/src/bash/src/parse.y" |
2704 | { (yyval.command) = (yyvsp[0].command); } | |
2705 | #line 2706 "y.tab.c" | |
3185942a JA |
2706 | break; |
2707 | ||
0001803f | 2708 | case 75: |
712f80b0 CR |
2709 | #line 797 "/usr/src/local/chet/src/bash/src/parse.y" |
2710 | { (yyval.command) = (yyvsp[0].command); } | |
2711 | #line 2712 "y.tab.c" | |
3185942a JA |
2712 | break; |
2713 | ||
0001803f | 2714 | case 76: |
712f80b0 CR |
2715 | #line 801 "/usr/src/local/chet/src/bash/src/parse.y" |
2716 | { | |
a0c0a00f | 2717 | (yyval.command) = make_for_command ((yyvsp[-4].word), add_string_to_list ("\"$@\"", (WORD_LIST *)NULL), (yyvsp[-1].command), word_lineno[word_top]); |
b80f6443 | 2718 | if (word_top > 0) word_top--; |
3185942a | 2719 | } |
712f80b0 | 2720 | #line 2721 "y.tab.c" |
3185942a JA |
2721 | break; |
2722 | ||
0001803f | 2723 | case 77: |
712f80b0 CR |
2724 | #line 806 "/usr/src/local/chet/src/bash/src/parse.y" |
2725 | { | |
d233b485 | 2726 | (yyval.command) = make_for_command ((yyvsp[-4].word), add_string_to_list ("\"$@\"", (WORD_LIST *)NULL), (yyvsp[-1].command), word_lineno[word_top]); |
b80f6443 | 2727 | if (word_top > 0) word_top--; |
3185942a | 2728 | } |
712f80b0 | 2729 | #line 2730 "y.tab.c" |
3185942a JA |
2730 | break; |
2731 | ||
0001803f | 2732 | case 78: |
712f80b0 CR |
2733 | #line 811 "/usr/src/local/chet/src/bash/src/parse.y" |
2734 | { | |
a0c0a00f | 2735 | (yyval.command) = make_for_command ((yyvsp[-5].word), add_string_to_list ("\"$@\"", (WORD_LIST *)NULL), (yyvsp[-1].command), word_lineno[word_top]); |
b80f6443 | 2736 | if (word_top > 0) word_top--; |
3185942a | 2737 | } |
712f80b0 | 2738 | #line 2739 "y.tab.c" |
3185942a JA |
2739 | break; |
2740 | ||
0001803f | 2741 | case 79: |
712f80b0 CR |
2742 | #line 816 "/usr/src/local/chet/src/bash/src/parse.y" |
2743 | { | |
d233b485 | 2744 | (yyval.command) = make_for_command ((yyvsp[-5].word), add_string_to_list ("\"$@\"", (WORD_LIST *)NULL), (yyvsp[-1].command), word_lineno[word_top]); |
b80f6443 | 2745 | if (word_top > 0) word_top--; |
3185942a | 2746 | } |
712f80b0 | 2747 | #line 2748 "y.tab.c" |
3185942a JA |
2748 | break; |
2749 | ||
0001803f | 2750 | case 80: |
712f80b0 CR |
2751 | #line 821 "/usr/src/local/chet/src/bash/src/parse.y" |
2752 | { | |
a0c0a00f | 2753 | (yyval.command) = make_for_command ((yyvsp[-8].word), REVERSE_LIST ((yyvsp[-5].word_list), WORD_LIST *), (yyvsp[-1].command), word_lineno[word_top]); |
b80f6443 | 2754 | if (word_top > 0) word_top--; |
3185942a | 2755 | } |
712f80b0 | 2756 | #line 2757 "y.tab.c" |
3185942a JA |
2757 | break; |
2758 | ||
0001803f | 2759 | case 81: |
712f80b0 CR |
2760 | #line 826 "/usr/src/local/chet/src/bash/src/parse.y" |
2761 | { | |
d233b485 | 2762 | (yyval.command) = make_for_command ((yyvsp[-8].word), REVERSE_LIST ((yyvsp[-5].word_list), WORD_LIST *), (yyvsp[-1].command), word_lineno[word_top]); |
b80f6443 | 2763 | if (word_top > 0) word_top--; |
3185942a | 2764 | } |
712f80b0 | 2765 | #line 2766 "y.tab.c" |
3185942a JA |
2766 | break; |
2767 | ||
0001803f | 2768 | case 82: |
712f80b0 CR |
2769 | #line 831 "/usr/src/local/chet/src/bash/src/parse.y" |
2770 | { | |
a0c0a00f | 2771 | (yyval.command) = make_for_command ((yyvsp[-7].word), (WORD_LIST *)NULL, (yyvsp[-1].command), word_lineno[word_top]); |
b80f6443 | 2772 | if (word_top > 0) word_top--; |
3185942a | 2773 | } |
712f80b0 | 2774 | #line 2775 "y.tab.c" |
3185942a JA |
2775 | break; |
2776 | ||
0001803f | 2777 | case 83: |
712f80b0 CR |
2778 | #line 836 "/usr/src/local/chet/src/bash/src/parse.y" |
2779 | { | |
d233b485 CR |
2780 | (yyval.command) = make_for_command ((yyvsp[-7].word), (WORD_LIST *)NULL, (yyvsp[-1].command), word_lineno[word_top]); |
2781 | if (word_top > 0) word_top--; | |
2782 | } | |
712f80b0 | 2783 | #line 2784 "y.tab.c" |
3185942a JA |
2784 | break; |
2785 | ||
0001803f | 2786 | case 84: |
712f80b0 CR |
2787 | #line 843 "/usr/src/local/chet/src/bash/src/parse.y" |
2788 | { | |
a0c0a00f | 2789 | (yyval.command) = make_arith_for_command ((yyvsp[-5].word_list), (yyvsp[-1].command), arith_for_lineno); |
d233b485 | 2790 | if ((yyval.command) == 0) YYERROR; |
b80f6443 | 2791 | if (word_top > 0) word_top--; |
3185942a | 2792 | } |
712f80b0 | 2793 | #line 2794 "y.tab.c" |
3185942a JA |
2794 | break; |
2795 | ||
0001803f | 2796 | case 85: |
712f80b0 CR |
2797 | #line 849 "/usr/src/local/chet/src/bash/src/parse.y" |
2798 | { | |
d233b485 CR |
2799 | (yyval.command) = make_arith_for_command ((yyvsp[-5].word_list), (yyvsp[-1].command), arith_for_lineno); |
2800 | if ((yyval.command) == 0) YYERROR; | |
b80f6443 | 2801 | if (word_top > 0) word_top--; |
3185942a | 2802 | } |
712f80b0 | 2803 | #line 2804 "y.tab.c" |
3185942a JA |
2804 | break; |
2805 | ||
0001803f | 2806 | case 86: |
712f80b0 CR |
2807 | #line 855 "/usr/src/local/chet/src/bash/src/parse.y" |
2808 | { | |
a0c0a00f | 2809 | (yyval.command) = make_arith_for_command ((yyvsp[-3].word_list), (yyvsp[-1].command), arith_for_lineno); |
d233b485 | 2810 | if ((yyval.command) == 0) YYERROR; |
b80f6443 | 2811 | if (word_top > 0) word_top--; |
3185942a | 2812 | } |
712f80b0 | 2813 | #line 2814 "y.tab.c" |
3185942a JA |
2814 | break; |
2815 | ||
0001803f | 2816 | case 87: |
712f80b0 CR |
2817 | #line 861 "/usr/src/local/chet/src/bash/src/parse.y" |
2818 | { | |
d233b485 CR |
2819 | (yyval.command) = make_arith_for_command ((yyvsp[-3].word_list), (yyvsp[-1].command), arith_for_lineno); |
2820 | if ((yyval.command) == 0) YYERROR; | |
2821 | if (word_top > 0) word_top--; | |
2822 | } | |
712f80b0 | 2823 | #line 2824 "y.tab.c" |
3185942a JA |
2824 | break; |
2825 | ||
0001803f | 2826 | case 88: |
712f80b0 CR |
2827 | #line 869 "/usr/src/local/chet/src/bash/src/parse.y" |
2828 | { | |
a0c0a00f | 2829 | (yyval.command) = make_select_command ((yyvsp[-4].word), add_string_to_list ("\"$@\"", (WORD_LIST *)NULL), (yyvsp[-1].command), word_lineno[word_top]); |
b80f6443 | 2830 | if (word_top > 0) word_top--; |
3185942a | 2831 | } |
712f80b0 | 2832 | #line 2833 "y.tab.c" |
3185942a JA |
2833 | break; |
2834 | ||
0001803f | 2835 | case 89: |
712f80b0 CR |
2836 | #line 874 "/usr/src/local/chet/src/bash/src/parse.y" |
2837 | { | |
d233b485 | 2838 | (yyval.command) = make_select_command ((yyvsp[-4].word), add_string_to_list ("\"$@\"", (WORD_LIST *)NULL), (yyvsp[-1].command), word_lineno[word_top]); |
b80f6443 | 2839 | if (word_top > 0) word_top--; |
3185942a | 2840 | } |
712f80b0 | 2841 | #line 2842 "y.tab.c" |
3185942a JA |
2842 | break; |
2843 | ||
0001803f | 2844 | case 90: |
712f80b0 CR |
2845 | #line 879 "/usr/src/local/chet/src/bash/src/parse.y" |
2846 | { | |
a0c0a00f | 2847 | (yyval.command) = make_select_command ((yyvsp[-5].word), add_string_to_list ("\"$@\"", (WORD_LIST *)NULL), (yyvsp[-1].command), word_lineno[word_top]); |
b80f6443 | 2848 | if (word_top > 0) word_top--; |
3185942a | 2849 | } |
712f80b0 | 2850 | #line 2851 "y.tab.c" |
3185942a JA |
2851 | break; |
2852 | ||
0001803f | 2853 | case 91: |
712f80b0 CR |
2854 | #line 884 "/usr/src/local/chet/src/bash/src/parse.y" |
2855 | { | |
d233b485 | 2856 | (yyval.command) = make_select_command ((yyvsp[-5].word), add_string_to_list ("\"$@\"", (WORD_LIST *)NULL), (yyvsp[-1].command), word_lineno[word_top]); |
b80f6443 | 2857 | if (word_top > 0) word_top--; |
3185942a | 2858 | } |
712f80b0 | 2859 | #line 2860 "y.tab.c" |
3185942a JA |
2860 | break; |
2861 | ||
0001803f | 2862 | case 92: |
712f80b0 CR |
2863 | #line 889 "/usr/src/local/chet/src/bash/src/parse.y" |
2864 | { | |
a0c0a00f | 2865 | (yyval.command) = make_select_command ((yyvsp[-8].word), REVERSE_LIST ((yyvsp[-5].word_list), WORD_LIST *), (yyvsp[-1].command), word_lineno[word_top]); |
b80f6443 | 2866 | if (word_top > 0) word_top--; |
3185942a | 2867 | } |
712f80b0 | 2868 | #line 2869 "y.tab.c" |
3185942a JA |
2869 | break; |
2870 | ||
0001803f | 2871 | case 93: |
712f80b0 CR |
2872 | #line 894 "/usr/src/local/chet/src/bash/src/parse.y" |
2873 | { | |
d233b485 | 2874 | (yyval.command) = make_select_command ((yyvsp[-8].word), REVERSE_LIST ((yyvsp[-5].word_list), WORD_LIST *), (yyvsp[-1].command), word_lineno[word_top]); |
b80f6443 | 2875 | if (word_top > 0) word_top--; |
3185942a | 2876 | } |
712f80b0 | 2877 | #line 2878 "y.tab.c" |
3185942a JA |
2878 | break; |
2879 | ||
0001803f | 2880 | case 94: |
712f80b0 CR |
2881 | #line 899 "/usr/src/local/chet/src/bash/src/parse.y" |
2882 | { | |
d233b485 | 2883 | (yyval.command) = make_select_command ((yyvsp[-7].word), (WORD_LIST *)NULL, (yyvsp[-1].command), word_lineno[word_top]); |
b80f6443 | 2884 | if (word_top > 0) word_top--; |
3185942a | 2885 | } |
712f80b0 | 2886 | #line 2887 "y.tab.c" |
3185942a JA |
2887 | break; |
2888 | ||
0001803f | 2889 | case 95: |
712f80b0 CR |
2890 | #line 904 "/usr/src/local/chet/src/bash/src/parse.y" |
2891 | { | |
d233b485 | 2892 | (yyval.command) = make_select_command ((yyvsp[-7].word), (WORD_LIST *)NULL, (yyvsp[-1].command), word_lineno[word_top]); |
b80f6443 | 2893 | if (word_top > 0) word_top--; |
3185942a | 2894 | } |
712f80b0 | 2895 | #line 2896 "y.tab.c" |
3185942a JA |
2896 | break; |
2897 | ||
0001803f | 2898 | case 96: |
712f80b0 CR |
2899 | #line 911 "/usr/src/local/chet/src/bash/src/parse.y" |
2900 | { | |
d233b485 CR |
2901 | (yyval.command) = make_case_command ((yyvsp[-4].word), (PATTERN_LIST *)NULL, word_lineno[word_top]); |
2902 | if (word_top > 0) word_top--; | |
2903 | } | |
712f80b0 | 2904 | #line 2905 "y.tab.c" |
3185942a JA |
2905 | break; |
2906 | ||
0001803f | 2907 | case 97: |
712f80b0 CR |
2908 | #line 916 "/usr/src/local/chet/src/bash/src/parse.y" |
2909 | { | |
d233b485 CR |
2910 | (yyval.command) = make_case_command ((yyvsp[-5].word), (yyvsp[-2].pattern), word_lineno[word_top]); |
2911 | if (word_top > 0) word_top--; | |
2912 | } | |
712f80b0 | 2913 | #line 2914 "y.tab.c" |
3185942a JA |
2914 | break; |
2915 | ||
0001803f | 2916 | case 98: |
712f80b0 CR |
2917 | #line 921 "/usr/src/local/chet/src/bash/src/parse.y" |
2918 | { | |
d233b485 CR |
2919 | (yyval.command) = make_case_command ((yyvsp[-4].word), (yyvsp[-1].pattern), word_lineno[word_top]); |
2920 | if (word_top > 0) word_top--; | |
2921 | } | |
712f80b0 | 2922 | #line 2923 "y.tab.c" |
3185942a JA |
2923 | break; |
2924 | ||
0001803f | 2925 | case 99: |
712f80b0 CR |
2926 | #line 928 "/usr/src/local/chet/src/bash/src/parse.y" |
2927 | { (yyval.command) = make_function_def ((yyvsp[-4].word), (yyvsp[0].command), function_dstart, function_bstart); } | |
2928 | #line 2929 "y.tab.c" | |
3185942a JA |
2929 | break; |
2930 | ||
0001803f | 2931 | case 100: |
712f80b0 CR |
2932 | #line 930 "/usr/src/local/chet/src/bash/src/parse.y" |
2933 | { (yyval.command) = make_function_def ((yyvsp[-4].word), (yyvsp[0].command), function_dstart, function_bstart); } | |
2934 | #line 2935 "y.tab.c" | |
d233b485 CR |
2935 | break; |
2936 | ||
2937 | case 101: | |
712f80b0 CR |
2938 | #line 932 "/usr/src/local/chet/src/bash/src/parse.y" |
2939 | { (yyval.command) = make_function_def ((yyvsp[-1].word), (yyvsp[0].command), function_dstart, function_bstart); } | |
2940 | #line 2941 "y.tab.c" | |
d233b485 CR |
2941 | break; |
2942 | ||
2943 | case 102: | |
712f80b0 CR |
2944 | #line 934 "/usr/src/local/chet/src/bash/src/parse.y" |
2945 | { (yyval.command) = make_function_def ((yyvsp[-3].word), (yyvsp[0].command), function_dstart, function_bstart); } | |
2946 | #line 2947 "y.tab.c" | |
d233b485 CR |
2947 | break; |
2948 | ||
2949 | case 103: | |
712f80b0 CR |
2950 | #line 938 "/usr/src/local/chet/src/bash/src/parse.y" |
2951 | { (yyval.command) = (yyvsp[0].command); } | |
2952 | #line 2953 "y.tab.c" | |
2953 | break; | |
2954 | ||
2955 | case 104: | |
2956 | #line 940 "/usr/src/local/chet/src/bash/src/parse.y" | |
2957 | { | |
f73dda09 JA |
2958 | COMMAND *tc; |
2959 | ||
a0c0a00f | 2960 | tc = (yyvsp[-1].command); |
f73dda09 JA |
2961 | /* According to Posix.2 3.9.5, redirections |
2962 | specified after the body of a function should | |
2963 | be attached to the function and performed when | |
2964 | the function is executed, not as part of the | |
2965 | function definition command. */ | |
2966 | /* XXX - I don't think it matters, but we might | |
2967 | want to change this in the future to avoid | |
2968 | problems differentiating between a function | |
2969 | definition with a redirection and a function | |
2970 | definition containing a single command with a | |
2971 | redirection. The two are semantically equivalent, | |
2972 | though -- the only difference is in how the | |
2973 | command printing code displays the redirections. */ | |
d233b485 | 2974 | if (tc && tc->redirects) |
f73dda09 JA |
2975 | { |
2976 | register REDIRECT *t; | |
2977 | for (t = tc->redirects; t->next; t = t->next) | |
2978 | ; | |
a0c0a00f | 2979 | t->next = (yyvsp[0].redirect); |
f73dda09 | 2980 | } |
d233b485 | 2981 | else if (tc) |
a0c0a00f CR |
2982 | tc->redirects = (yyvsp[0].redirect); |
2983 | (yyval.command) = (yyvsp[-1].command); | |
3185942a | 2984 | } |
712f80b0 | 2985 | #line 2986 "y.tab.c" |
3185942a JA |
2986 | break; |
2987 | ||
712f80b0 CR |
2988 | case 105: |
2989 | #line 971 "/usr/src/local/chet/src/bash/src/parse.y" | |
2990 | { | |
a0c0a00f | 2991 | (yyval.command) = make_subshell_command ((yyvsp[-1].command)); |
3185942a JA |
2992 | (yyval.command)->flags |= CMD_WANT_SUBSHELL; |
2993 | } | |
712f80b0 | 2994 | #line 2995 "y.tab.c" |
3185942a JA |
2995 | break; |
2996 | ||
712f80b0 CR |
2997 | case 106: |
2998 | #line 978 "/usr/src/local/chet/src/bash/src/parse.y" | |
2999 | { | |
a0c0a00f | 3000 | (yyval.command) = make_coproc_command ("COPROC", (yyvsp[0].command)); |
3185942a JA |
3001 | (yyval.command)->flags |= CMD_WANT_SUBSHELL|CMD_COPROC_SUBSHELL; |
3002 | } | |
712f80b0 | 3003 | #line 3004 "y.tab.c" |
3185942a JA |
3004 | break; |
3005 | ||
712f80b0 CR |
3006 | case 107: |
3007 | #line 983 "/usr/src/local/chet/src/bash/src/parse.y" | |
3008 | { | |
3185942a JA |
3009 | COMMAND *tc; |
3010 | ||
a0c0a00f | 3011 | tc = (yyvsp[-1].command); |
d233b485 | 3012 | if (tc && tc->redirects) |
3185942a JA |
3013 | { |
3014 | register REDIRECT *t; | |
3015 | for (t = tc->redirects; t->next; t = t->next) | |
3016 | ; | |
a0c0a00f | 3017 | t->next = (yyvsp[0].redirect); |
3185942a | 3018 | } |
d233b485 | 3019 | else if (tc) |
a0c0a00f CR |
3020 | tc->redirects = (yyvsp[0].redirect); |
3021 | (yyval.command) = make_coproc_command ("COPROC", (yyvsp[-1].command)); | |
3185942a JA |
3022 | (yyval.command)->flags |= CMD_WANT_SUBSHELL|CMD_COPROC_SUBSHELL; |
3023 | } | |
712f80b0 | 3024 | #line 3025 "y.tab.c" |
3185942a JA |
3025 | break; |
3026 | ||
712f80b0 CR |
3027 | case 108: |
3028 | #line 1000 "/usr/src/local/chet/src/bash/src/parse.y" | |
3029 | { | |
a0c0a00f | 3030 | (yyval.command) = make_coproc_command ((yyvsp[-1].word)->word, (yyvsp[0].command)); |
3185942a JA |
3031 | (yyval.command)->flags |= CMD_WANT_SUBSHELL|CMD_COPROC_SUBSHELL; |
3032 | } | |
712f80b0 | 3033 | #line 3034 "y.tab.c" |
3185942a JA |
3034 | break; |
3035 | ||
712f80b0 CR |
3036 | case 109: |
3037 | #line 1005 "/usr/src/local/chet/src/bash/src/parse.y" | |
3038 | { | |
3185942a JA |
3039 | COMMAND *tc; |
3040 | ||
a0c0a00f | 3041 | tc = (yyvsp[-1].command); |
d233b485 | 3042 | if (tc && tc->redirects) |
3185942a JA |
3043 | { |
3044 | register REDIRECT *t; | |
3045 | for (t = tc->redirects; t->next; t = t->next) | |
3046 | ; | |
a0c0a00f | 3047 | t->next = (yyvsp[0].redirect); |
3185942a | 3048 | } |
d233b485 | 3049 | else if (tc) |
a0c0a00f CR |
3050 | tc->redirects = (yyvsp[0].redirect); |
3051 | (yyval.command) = make_coproc_command ((yyvsp[-2].word)->word, (yyvsp[-1].command)); | |
3185942a JA |
3052 | (yyval.command)->flags |= CMD_WANT_SUBSHELL|CMD_COPROC_SUBSHELL; |
3053 | } | |
712f80b0 | 3054 | #line 3055 "y.tab.c" |
3185942a JA |
3055 | break; |
3056 | ||
712f80b0 CR |
3057 | case 110: |
3058 | #line 1022 "/usr/src/local/chet/src/bash/src/parse.y" | |
3059 | { | |
a0c0a00f | 3060 | (yyval.command) = make_coproc_command ("COPROC", clean_simple_command ((yyvsp[0].command))); |
3185942a JA |
3061 | (yyval.command)->flags |= CMD_WANT_SUBSHELL|CMD_COPROC_SUBSHELL; |
3062 | } | |
712f80b0 | 3063 | #line 3064 "y.tab.c" |
3185942a JA |
3064 | break; |
3065 | ||
d233b485 | 3066 | case 111: |
712f80b0 CR |
3067 | #line 1029 "/usr/src/local/chet/src/bash/src/parse.y" |
3068 | { (yyval.command) = make_if_command ((yyvsp[-3].command), (yyvsp[-1].command), (COMMAND *)NULL); } | |
3069 | #line 3070 "y.tab.c" | |
3185942a JA |
3070 | break; |
3071 | ||
d233b485 | 3072 | case 112: |
712f80b0 CR |
3073 | #line 1031 "/usr/src/local/chet/src/bash/src/parse.y" |
3074 | { (yyval.command) = make_if_command ((yyvsp[-5].command), (yyvsp[-3].command), (yyvsp[-1].command)); } | |
3075 | #line 3076 "y.tab.c" | |
3185942a JA |
3076 | break; |
3077 | ||
d233b485 | 3078 | case 113: |
712f80b0 CR |
3079 | #line 1033 "/usr/src/local/chet/src/bash/src/parse.y" |
3080 | { (yyval.command) = make_if_command ((yyvsp[-4].command), (yyvsp[-2].command), (yyvsp[-1].command)); } | |
3081 | #line 3082 "y.tab.c" | |
3185942a JA |
3082 | break; |
3083 | ||
d233b485 | 3084 | case 114: |
712f80b0 CR |
3085 | #line 1038 "/usr/src/local/chet/src/bash/src/parse.y" |
3086 | { (yyval.command) = make_group_command ((yyvsp[-1].command)); } | |
3087 | #line 3088 "y.tab.c" | |
3185942a JA |
3088 | break; |
3089 | ||
d233b485 | 3090 | case 115: |
712f80b0 CR |
3091 | #line 1042 "/usr/src/local/chet/src/bash/src/parse.y" |
3092 | { (yyval.command) = make_arith_command ((yyvsp[0].word_list)); } | |
3093 | #line 3094 "y.tab.c" | |
3185942a JA |
3094 | break; |
3095 | ||
d233b485 | 3096 | case 116: |
712f80b0 CR |
3097 | #line 1046 "/usr/src/local/chet/src/bash/src/parse.y" |
3098 | { (yyval.command) = (yyvsp[-1].command); } | |
3099 | #line 3100 "y.tab.c" | |
3185942a JA |
3100 | break; |
3101 | ||
d233b485 | 3102 | case 117: |
712f80b0 CR |
3103 | #line 1050 "/usr/src/local/chet/src/bash/src/parse.y" |
3104 | { (yyval.command) = make_if_command ((yyvsp[-2].command), (yyvsp[0].command), (COMMAND *)NULL); } | |
3105 | #line 3106 "y.tab.c" | |
3185942a JA |
3106 | break; |
3107 | ||
d233b485 | 3108 | case 118: |
712f80b0 CR |
3109 | #line 1052 "/usr/src/local/chet/src/bash/src/parse.y" |
3110 | { (yyval.command) = make_if_command ((yyvsp[-4].command), (yyvsp[-2].command), (yyvsp[0].command)); } | |
3111 | #line 3112 "y.tab.c" | |
3185942a JA |
3112 | break; |
3113 | ||
712f80b0 CR |
3114 | case 119: |
3115 | #line 1054 "/usr/src/local/chet/src/bash/src/parse.y" | |
3116 | { (yyval.command) = make_if_command ((yyvsp[-3].command), (yyvsp[-1].command), (yyvsp[0].command)); } | |
3117 | #line 3118 "y.tab.c" | |
3185942a JA |
3118 | break; |
3119 | ||
d233b485 | 3120 | case 121: |
712f80b0 CR |
3121 | #line 1059 "/usr/src/local/chet/src/bash/src/parse.y" |
3122 | { (yyvsp[0].pattern)->next = (yyvsp[-1].pattern); (yyval.pattern) = (yyvsp[0].pattern); } | |
3123 | #line 3124 "y.tab.c" | |
3185942a JA |
3124 | break; |
3125 | ||
d233b485 | 3126 | case 122: |
712f80b0 CR |
3127 | #line 1063 "/usr/src/local/chet/src/bash/src/parse.y" |
3128 | { (yyval.pattern) = make_pattern_list ((yyvsp[-2].word_list), (yyvsp[0].command)); } | |
3129 | #line 3130 "y.tab.c" | |
3185942a JA |
3130 | break; |
3131 | ||
d233b485 | 3132 | case 123: |
712f80b0 CR |
3133 | #line 1065 "/usr/src/local/chet/src/bash/src/parse.y" |
3134 | { (yyval.pattern) = make_pattern_list ((yyvsp[-2].word_list), (COMMAND *)NULL); } | |
3135 | #line 3136 "y.tab.c" | |
3185942a JA |
3136 | break; |
3137 | ||
d233b485 | 3138 | case 124: |
712f80b0 CR |
3139 | #line 1067 "/usr/src/local/chet/src/bash/src/parse.y" |
3140 | { (yyval.pattern) = make_pattern_list ((yyvsp[-2].word_list), (yyvsp[0].command)); } | |
3141 | #line 3142 "y.tab.c" | |
3185942a JA |
3142 | break; |
3143 | ||
d233b485 | 3144 | case 125: |
712f80b0 CR |
3145 | #line 1069 "/usr/src/local/chet/src/bash/src/parse.y" |
3146 | { (yyval.pattern) = make_pattern_list ((yyvsp[-2].word_list), (COMMAND *)NULL); } | |
3147 | #line 3148 "y.tab.c" | |
3185942a JA |
3148 | break; |
3149 | ||
d233b485 | 3150 | case 126: |
712f80b0 CR |
3151 | #line 1073 "/usr/src/local/chet/src/bash/src/parse.y" |
3152 | { (yyval.pattern) = (yyvsp[-1].pattern); } | |
3153 | #line 3154 "y.tab.c" | |
3185942a JA |
3154 | break; |
3155 | ||
d233b485 | 3156 | case 127: |
712f80b0 CR |
3157 | #line 1075 "/usr/src/local/chet/src/bash/src/parse.y" |
3158 | { (yyvsp[-1].pattern)->next = (yyvsp[-2].pattern); (yyval.pattern) = (yyvsp[-1].pattern); } | |
3159 | #line 3160 "y.tab.c" | |
3185942a JA |
3160 | break; |
3161 | ||
d233b485 | 3162 | case 128: |
712f80b0 CR |
3163 | #line 1077 "/usr/src/local/chet/src/bash/src/parse.y" |
3164 | { (yyvsp[-1].pattern)->flags |= CASEPAT_FALLTHROUGH; (yyval.pattern) = (yyvsp[-1].pattern); } | |
3165 | #line 3166 "y.tab.c" | |
3185942a JA |
3166 | break; |
3167 | ||
d233b485 | 3168 | case 129: |
712f80b0 CR |
3169 | #line 1079 "/usr/src/local/chet/src/bash/src/parse.y" |
3170 | { (yyvsp[-1].pattern)->flags |= CASEPAT_FALLTHROUGH; (yyvsp[-1].pattern)->next = (yyvsp[-2].pattern); (yyval.pattern) = (yyvsp[-1].pattern); } | |
3171 | #line 3172 "y.tab.c" | |
3185942a JA |
3172 | break; |
3173 | ||
d233b485 | 3174 | case 130: |
712f80b0 CR |
3175 | #line 1081 "/usr/src/local/chet/src/bash/src/parse.y" |
3176 | { (yyvsp[-1].pattern)->flags |= CASEPAT_TESTNEXT; (yyval.pattern) = (yyvsp[-1].pattern); } | |
3177 | #line 3178 "y.tab.c" | |
3185942a JA |
3178 | break; |
3179 | ||
d233b485 | 3180 | case 131: |
712f80b0 CR |
3181 | #line 1083 "/usr/src/local/chet/src/bash/src/parse.y" |
3182 | { (yyvsp[-1].pattern)->flags |= CASEPAT_TESTNEXT; (yyvsp[-1].pattern)->next = (yyvsp[-2].pattern); (yyval.pattern) = (yyvsp[-1].pattern); } | |
3183 | #line 3184 "y.tab.c" | |
3185942a JA |
3184 | break; |
3185 | ||
d233b485 | 3186 | case 132: |
712f80b0 CR |
3187 | #line 1087 "/usr/src/local/chet/src/bash/src/parse.y" |
3188 | { (yyval.word_list) = make_word_list ((yyvsp[0].word), (WORD_LIST *)NULL); } | |
3189 | #line 3190 "y.tab.c" | |
3185942a JA |
3190 | break; |
3191 | ||
d233b485 | 3192 | case 133: |
712f80b0 CR |
3193 | #line 1089 "/usr/src/local/chet/src/bash/src/parse.y" |
3194 | { (yyval.word_list) = make_word_list ((yyvsp[0].word), (yyvsp[-2].word_list)); } | |
3195 | #line 3196 "y.tab.c" | |
3196 | break; | |
3197 | ||
3198 | case 134: | |
3199 | #line 1098 "/usr/src/local/chet/src/bash/src/parse.y" | |
3200 | { | |
a0c0a00f | 3201 | (yyval.command) = (yyvsp[0].command); |
f73dda09 JA |
3202 | if (need_here_doc) |
3203 | gather_here_documents (); | |
3185942a | 3204 | } |
712f80b0 | 3205 | #line 3206 "y.tab.c" |
3185942a JA |
3206 | break; |
3207 | ||
712f80b0 CR |
3208 | case 136: |
3209 | #line 1107 "/usr/src/local/chet/src/bash/src/parse.y" | |
3210 | { | |
a0c0a00f | 3211 | (yyval.command) = (yyvsp[0].command); |
3185942a | 3212 | } |
712f80b0 | 3213 | #line 3214 "y.tab.c" |
3185942a JA |
3214 | break; |
3215 | ||
712f80b0 CR |
3216 | case 138: |
3217 | #line 1114 "/usr/src/local/chet/src/bash/src/parse.y" | |
3218 | { | |
a0c0a00f CR |
3219 | if ((yyvsp[-2].command)->type == cm_connection) |
3220 | (yyval.command) = connect_async_list ((yyvsp[-2].command), (COMMAND *)NULL, '&'); | |
f73dda09 | 3221 | else |
a0c0a00f | 3222 | (yyval.command) = command_connect ((yyvsp[-2].command), (COMMAND *)NULL, '&'); |
3185942a | 3223 | } |
712f80b0 | 3224 | #line 3225 "y.tab.c" |
3185942a JA |
3225 | break; |
3226 | ||
d233b485 | 3227 | case 140: |
712f80b0 CR |
3228 | #line 1125 "/usr/src/local/chet/src/bash/src/parse.y" |
3229 | { (yyval.command) = command_connect ((yyvsp[-3].command), (yyvsp[0].command), AND_AND); } | |
3230 | #line 3231 "y.tab.c" | |
3185942a JA |
3231 | break; |
3232 | ||
d233b485 | 3233 | case 141: |
712f80b0 CR |
3234 | #line 1127 "/usr/src/local/chet/src/bash/src/parse.y" |
3235 | { (yyval.command) = command_connect ((yyvsp[-3].command), (yyvsp[0].command), OR_OR); } | |
3236 | #line 3237 "y.tab.c" | |
3237 | break; | |
3238 | ||
3239 | case 142: | |
3240 | #line 1129 "/usr/src/local/chet/src/bash/src/parse.y" | |
3241 | { | |
a0c0a00f CR |
3242 | if ((yyvsp[-3].command)->type == cm_connection) |
3243 | (yyval.command) = connect_async_list ((yyvsp[-3].command), (yyvsp[0].command), '&'); | |
f73dda09 | 3244 | else |
a0c0a00f | 3245 | (yyval.command) = command_connect ((yyvsp[-3].command), (yyvsp[0].command), '&'); |
3185942a | 3246 | } |
712f80b0 | 3247 | #line 3248 "y.tab.c" |
3185942a JA |
3248 | break; |
3249 | ||
d233b485 | 3250 | case 143: |
712f80b0 CR |
3251 | #line 1136 "/usr/src/local/chet/src/bash/src/parse.y" |
3252 | { (yyval.command) = command_connect ((yyvsp[-3].command), (yyvsp[0].command), ';'); } | |
3253 | #line 3254 "y.tab.c" | |
3185942a JA |
3254 | break; |
3255 | ||
d233b485 | 3256 | case 144: |
712f80b0 CR |
3257 | #line 1138 "/usr/src/local/chet/src/bash/src/parse.y" |
3258 | { (yyval.command) = command_connect ((yyvsp[-3].command), (yyvsp[0].command), ';'); } | |
3259 | #line 3260 "y.tab.c" | |
3185942a JA |
3260 | break; |
3261 | ||
712f80b0 CR |
3262 | case 145: |
3263 | #line 1140 "/usr/src/local/chet/src/bash/src/parse.y" | |
3264 | { (yyval.command) = (yyvsp[0].command); } | |
3265 | #line 3266 "y.tab.c" | |
3185942a JA |
3266 | break; |
3267 | ||
d233b485 | 3268 | case 148: |
712f80b0 CR |
3269 | #line 1148 "/usr/src/local/chet/src/bash/src/parse.y" |
3270 | { (yyval.number) = '\n'; } | |
3271 | #line 3272 "y.tab.c" | |
3185942a JA |
3272 | break; |
3273 | ||
d233b485 | 3274 | case 149: |
712f80b0 CR |
3275 | #line 1150 "/usr/src/local/chet/src/bash/src/parse.y" |
3276 | { (yyval.number) = ';'; } | |
3277 | #line 3278 "y.tab.c" | |
3185942a JA |
3278 | break; |
3279 | ||
712f80b0 CR |
3280 | case 150: |
3281 | #line 1152 "/usr/src/local/chet/src/bash/src/parse.y" | |
3282 | { (yyval.number) = yacc_EOF; } | |
3283 | #line 3284 "y.tab.c" | |
3284 | break; | |
3285 | ||
3286 | case 153: | |
3287 | #line 1166 "/usr/src/local/chet/src/bash/src/parse.y" | |
3288 | { | |
a0c0a00f | 3289 | (yyval.command) = (yyvsp[0].command); |
f73dda09 JA |
3290 | if (need_here_doc) |
3291 | gather_here_documents (); | |
3185942a JA |
3292 | if ((parser_state & PST_CMDSUBST) && current_token == shell_eof_token) |
3293 | { | |
a0c0a00f | 3294 | global_command = (yyvsp[0].command); |
3185942a JA |
3295 | eof_encountered = 0; |
3296 | rewind_input_string (); | |
3297 | YYACCEPT; | |
3298 | } | |
3299 | } | |
712f80b0 | 3300 | #line 3301 "y.tab.c" |
3185942a JA |
3301 | break; |
3302 | ||
712f80b0 CR |
3303 | case 154: |
3304 | #line 1179 "/usr/src/local/chet/src/bash/src/parse.y" | |
3305 | { | |
a0c0a00f CR |
3306 | if ((yyvsp[-1].command)->type == cm_connection) |
3307 | (yyval.command) = connect_async_list ((yyvsp[-1].command), (COMMAND *)NULL, '&'); | |
f73dda09 | 3308 | else |
a0c0a00f | 3309 | (yyval.command) = command_connect ((yyvsp[-1].command), (COMMAND *)NULL, '&'); |
f73dda09 JA |
3310 | if (need_here_doc) |
3311 | gather_here_documents (); | |
3185942a JA |
3312 | if ((parser_state & PST_CMDSUBST) && current_token == shell_eof_token) |
3313 | { | |
a0c0a00f | 3314 | global_command = (yyvsp[-1].command); |
3185942a JA |
3315 | eof_encountered = 0; |
3316 | rewind_input_string (); | |
3317 | YYACCEPT; | |
3318 | } | |
3319 | } | |
712f80b0 | 3320 | #line 3321 "y.tab.c" |
3185942a JA |
3321 | break; |
3322 | ||
712f80b0 CR |
3323 | case 155: |
3324 | #line 1195 "/usr/src/local/chet/src/bash/src/parse.y" | |
3325 | { | |
a0c0a00f | 3326 | (yyval.command) = (yyvsp[-1].command); |
f73dda09 JA |
3327 | if (need_here_doc) |
3328 | gather_here_documents (); | |
3185942a JA |
3329 | if ((parser_state & PST_CMDSUBST) && current_token == shell_eof_token) |
3330 | { | |
a0c0a00f | 3331 | global_command = (yyvsp[-1].command); |
3185942a JA |
3332 | eof_encountered = 0; |
3333 | rewind_input_string (); | |
3334 | YYACCEPT; | |
3335 | } | |
3336 | } | |
712f80b0 | 3337 | #line 3338 "y.tab.c" |
3185942a JA |
3338 | break; |
3339 | ||
d233b485 | 3340 | case 156: |
712f80b0 CR |
3341 | #line 1210 "/usr/src/local/chet/src/bash/src/parse.y" |
3342 | { (yyval.command) = command_connect ((yyvsp[-3].command), (yyvsp[0].command), AND_AND); } | |
3343 | #line 3344 "y.tab.c" | |
3185942a JA |
3344 | break; |
3345 | ||
d233b485 | 3346 | case 157: |
712f80b0 CR |
3347 | #line 1212 "/usr/src/local/chet/src/bash/src/parse.y" |
3348 | { (yyval.command) = command_connect ((yyvsp[-3].command), (yyvsp[0].command), OR_OR); } | |
3349 | #line 3350 "y.tab.c" | |
3350 | break; | |
3351 | ||
3352 | case 158: | |
3353 | #line 1214 "/usr/src/local/chet/src/bash/src/parse.y" | |
3354 | { | |
a0c0a00f CR |
3355 | if ((yyvsp[-2].command)->type == cm_connection) |
3356 | (yyval.command) = connect_async_list ((yyvsp[-2].command), (yyvsp[0].command), '&'); | |
f73dda09 | 3357 | else |
a0c0a00f | 3358 | (yyval.command) = command_connect ((yyvsp[-2].command), (yyvsp[0].command), '&'); |
3185942a | 3359 | } |
712f80b0 | 3360 | #line 3361 "y.tab.c" |
3185942a JA |
3361 | break; |
3362 | ||
d233b485 | 3363 | case 159: |
712f80b0 CR |
3364 | #line 1221 "/usr/src/local/chet/src/bash/src/parse.y" |
3365 | { (yyval.command) = command_connect ((yyvsp[-2].command), (yyvsp[0].command), ';'); } | |
3366 | #line 3367 "y.tab.c" | |
3185942a JA |
3367 | break; |
3368 | ||
d233b485 | 3369 | case 160: |
712f80b0 CR |
3370 | #line 1224 "/usr/src/local/chet/src/bash/src/parse.y" |
3371 | { (yyval.command) = (yyvsp[0].command); } | |
3372 | #line 3373 "y.tab.c" | |
3185942a JA |
3373 | break; |
3374 | ||
d233b485 | 3375 | case 161: |
712f80b0 CR |
3376 | #line 1228 "/usr/src/local/chet/src/bash/src/parse.y" |
3377 | { (yyval.command) = (yyvsp[0].command); } | |
3378 | #line 3379 "y.tab.c" | |
3379 | break; | |
3380 | ||
3381 | case 162: | |
3382 | #line 1230 "/usr/src/local/chet/src/bash/src/parse.y" | |
3383 | { | |
a0c0a00f CR |
3384 | if ((yyvsp[0].command)) |
3385 | (yyvsp[0].command)->flags ^= CMD_INVERT_RETURN; /* toggle */ | |
3386 | (yyval.command) = (yyvsp[0].command); | |
3185942a | 3387 | } |
712f80b0 | 3388 | #line 3389 "y.tab.c" |
3185942a JA |
3389 | break; |
3390 | ||
712f80b0 CR |
3391 | case 163: |
3392 | #line 1236 "/usr/src/local/chet/src/bash/src/parse.y" | |
3393 | { | |
a0c0a00f CR |
3394 | if ((yyvsp[0].command)) |
3395 | (yyvsp[0].command)->flags |= (yyvsp[-1].number); | |
3396 | (yyval.command) = (yyvsp[0].command); | |
3185942a | 3397 | } |
712f80b0 | 3398 | #line 3399 "y.tab.c" |
3185942a JA |
3399 | break; |
3400 | ||
712f80b0 CR |
3401 | case 164: |
3402 | #line 1242 "/usr/src/local/chet/src/bash/src/parse.y" | |
3403 | { | |
495aee44 | 3404 | ELEMENT x; |
3185942a | 3405 | |
495aee44 CR |
3406 | /* Boy, this is unclean. `time' by itself can |
3407 | time a null command. We cheat and push a | |
3408 | newline back if the list_terminator was a newline | |
3409 | to avoid the double-newline problem (one to | |
3410 | terminate this, one to terminate the command) */ | |
3411 | x.word = 0; | |
3412 | x.redirect = 0; | |
3413 | (yyval.command) = make_simple_command (x, (COMMAND *)NULL); | |
a0c0a00f | 3414 | (yyval.command)->flags |= (yyvsp[-1].number); |
495aee44 | 3415 | /* XXX - let's cheat and push a newline back */ |
a0c0a00f | 3416 | if ((yyvsp[0].number) == '\n') |
495aee44 | 3417 | token_to_read = '\n'; |
a0c0a00f CR |
3418 | else if ((yyvsp[0].number) == ';') |
3419 | token_to_read = ';'; | |
d233b485 | 3420 | parser_state &= ~PST_REDIRLIST; /* make_simple_command sets this */ |
3185942a | 3421 | } |
712f80b0 | 3422 | #line 3423 "y.tab.c" |
3185942a JA |
3423 | break; |
3424 | ||
712f80b0 CR |
3425 | case 165: |
3426 | #line 1262 "/usr/src/local/chet/src/bash/src/parse.y" | |
3427 | { | |
b80f6443 JA |
3428 | ELEMENT x; |
3429 | ||
495aee44 CR |
3430 | /* This is just as unclean. Posix says that `!' |
3431 | by itself should be equivalent to `false'. | |
3432 | We cheat and push a | |
b80f6443 JA |
3433 | newline back if the list_terminator was a newline |
3434 | to avoid the double-newline problem (one to | |
3435 | terminate this, one to terminate the command) */ | |
3436 | x.word = 0; | |
3437 | x.redirect = 0; | |
3185942a | 3438 | (yyval.command) = make_simple_command (x, (COMMAND *)NULL); |
495aee44 | 3439 | (yyval.command)->flags |= CMD_INVERT_RETURN; |
b80f6443 | 3440 | /* XXX - let's cheat and push a newline back */ |
a0c0a00f | 3441 | if ((yyvsp[0].number) == '\n') |
b80f6443 | 3442 | token_to_read = '\n'; |
a0c0a00f CR |
3443 | if ((yyvsp[0].number) == ';') |
3444 | token_to_read = ';'; | |
d233b485 | 3445 | parser_state &= ~PST_REDIRLIST; /* make_simple_command sets this */ |
3185942a | 3446 | } |
712f80b0 | 3447 | #line 3448 "y.tab.c" |
3185942a | 3448 | break; |
f73dda09 | 3449 | |
712f80b0 CR |
3450 | case 166: |
3451 | #line 1285 "/usr/src/local/chet/src/bash/src/parse.y" | |
3452 | { (yyval.command) = command_connect ((yyvsp[-3].command), (yyvsp[0].command), '|'); } | |
3453 | #line 3454 "y.tab.c" | |
3185942a JA |
3454 | break; |
3455 | ||
712f80b0 CR |
3456 | case 167: |
3457 | #line 1287 "/usr/src/local/chet/src/bash/src/parse.y" | |
3458 | { | |
3185942a JA |
3459 | /* Make cmd1 |& cmd2 equivalent to cmd1 2>&1 | cmd2 */ |
3460 | COMMAND *tc; | |
0001803f | 3461 | REDIRECTEE rd, sd; |
3185942a JA |
3462 | REDIRECT *r; |
3463 | ||
a0c0a00f | 3464 | tc = (yyvsp[-3].command)->type == cm_simple ? (COMMAND *)(yyvsp[-3].command)->value.Simple : (yyvsp[-3].command); |
0001803f | 3465 | sd.dest = 2; |
3185942a | 3466 | rd.dest = 1; |
0001803f | 3467 | r = make_redirection (sd, r_duplicating_output, rd, 0); |
3185942a JA |
3468 | if (tc->redirects) |
3469 | { | |
3470 | register REDIRECT *t; | |
3471 | for (t = tc->redirects; t->next; t = t->next) | |
3472 | ; | |
3473 | t->next = r; | |
3474 | } | |
3475 | else | |
3476 | tc->redirects = r; | |
3477 | ||
a0c0a00f | 3478 | (yyval.command) = command_connect ((yyvsp[-3].command), (yyvsp[0].command), '|'); |
3185942a | 3479 | } |
712f80b0 | 3480 | #line 3481 "y.tab.c" |
3185942a JA |
3481 | break; |
3482 | ||
d233b485 | 3483 | case 168: |
712f80b0 CR |
3484 | #line 1310 "/usr/src/local/chet/src/bash/src/parse.y" |
3485 | { (yyval.command) = (yyvsp[0].command); } | |
3486 | #line 3487 "y.tab.c" | |
3185942a JA |
3487 | break; |
3488 | ||
d233b485 | 3489 | case 169: |
712f80b0 CR |
3490 | #line 1314 "/usr/src/local/chet/src/bash/src/parse.y" |
3491 | { (yyval.number) = CMD_TIME_PIPELINE; } | |
3492 | #line 3493 "y.tab.c" | |
495aee44 CR |
3493 | break; |
3494 | ||
d233b485 | 3495 | case 170: |
712f80b0 CR |
3496 | #line 1316 "/usr/src/local/chet/src/bash/src/parse.y" |
3497 | { (yyval.number) = CMD_TIME_PIPELINE|CMD_TIME_POSIX; } | |
3498 | #line 3499 "y.tab.c" | |
3185942a JA |
3499 | break; |
3500 | ||
712f80b0 CR |
3501 | case 171: |
3502 | #line 1318 "/usr/src/local/chet/src/bash/src/parse.y" | |
3503 | { (yyval.number) = CMD_TIME_PIPELINE|CMD_TIME_POSIX; } | |
3504 | #line 3505 "y.tab.c" | |
3505 | break; | |
3506 | ||
3507 | case 172: | |
3508 | #line 1320 "/usr/src/local/chet/src/bash/src/parse.y" | |
3509 | { (yyval.number) = CMD_TIME_PIPELINE|CMD_TIME_POSIX; } | |
3510 | #line 3511 "y.tab.c" | |
3511 | break; | |
3512 | ||
3513 | ||
3514 | #line 3515 "y.tab.c" | |
3185942a | 3515 | |
3185942a | 3516 | default: break; |
f73dda09 | 3517 | } |
a0c0a00f CR |
3518 | /* User semantic actions sometimes alter yychar, and that requires |
3519 | that yytoken be updated with the new translation. We take the | |
3520 | approach of translating immediately before every use of yytoken. | |
3521 | One alternative is translating here after every semantic action, | |
3522 | but that translation would be missed if the semantic action invokes | |
3523 | YYABORT, YYACCEPT, or YYERROR immediately after altering yychar or | |
3524 | if it invokes YYBACKUP. In the case of YYABORT or YYACCEPT, an | |
3525 | incorrect destructor might then be invoked immediately. In the | |
3526 | case of YYERROR or YYBACKUP, subsequent parser actions might lead | |
3527 | to an incorrect destructor call or verbose syntax error message | |
3528 | before the lookahead is translated. */ | |
3185942a JA |
3529 | YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc); |
3530 | ||
3531 | YYPOPSTACK (yylen); | |
3532 | yylen = 0; | |
3533 | YY_STACK_PRINT (yyss, yyssp); | |
f73dda09 JA |
3534 | |
3535 | *++yyvsp = yyval; | |
b80f6443 | 3536 | |
a0c0a00f | 3537 | /* Now 'shift' the result of the reduction. Determine what state |
3185942a JA |
3538 | that goes to, based on the state we popped back to and the rule |
3539 | number reduced by. */ | |
712f80b0 CR |
3540 | { |
3541 | const int yylhs = yyr1[yyn] - YYNTOKENS; | |
3542 | const int yyi = yypgoto[yylhs] + *yyssp; | |
3543 | yystate = (0 <= yyi && yyi <= YYLAST && yycheck[yyi] == *yyssp | |
3544 | ? yytable[yyi] | |
3545 | : yydefgoto[yylhs]); | |
3546 | } | |
f73dda09 JA |
3547 | |
3548 | goto yynewstate; | |
3549 | ||
f73dda09 | 3550 | |
a0c0a00f CR |
3551 | /*--------------------------------------. |
3552 | | yyerrlab -- here on detecting error. | | |
3553 | `--------------------------------------*/ | |
3185942a | 3554 | yyerrlab: |
a0c0a00f CR |
3555 | /* Make sure we have latest lookahead translation. See comments at |
3556 | user semantic actions for why this is necessary. */ | |
3557 | yytoken = yychar == YYEMPTY ? YYEMPTY : YYTRANSLATE (yychar); | |
3558 | ||
3185942a JA |
3559 | /* If not already recovering from an error, report this error. */ |
3560 | if (!yyerrstatus) | |
f73dda09 JA |
3561 | { |
3562 | ++yynerrs; | |
3185942a JA |
3563 | #if ! YYERROR_VERBOSE |
3564 | yyerror (YY_("syntax error")); | |
3565 | #else | |
a0c0a00f CR |
3566 | # define YYSYNTAX_ERROR yysyntax_error (&yymsg_alloc, &yymsg, \ |
3567 | yyssp, yytoken) | |
3185942a | 3568 | { |
a0c0a00f CR |
3569 | char const *yymsgp = YY_("syntax error"); |
3570 | int yysyntax_error_status; | |
3571 | yysyntax_error_status = YYSYNTAX_ERROR; | |
3572 | if (yysyntax_error_status == 0) | |
3573 | yymsgp = yymsg; | |
3574 | else if (yysyntax_error_status == 1) | |
3575 | { | |
3576 | if (yymsg != yymsgbuf) | |
3577 | YYSTACK_FREE (yymsg); | |
712f80b0 | 3578 | yymsg = YY_CAST (char *, YYSTACK_ALLOC (YY_CAST (YYSIZE_T, yymsg_alloc))); |
a0c0a00f CR |
3579 | if (!yymsg) |
3580 | { | |
3581 | yymsg = yymsgbuf; | |
3582 | yymsg_alloc = sizeof yymsgbuf; | |
3583 | yysyntax_error_status = 2; | |
3584 | } | |
3585 | else | |
3586 | { | |
3587 | yysyntax_error_status = YYSYNTAX_ERROR; | |
3588 | yymsgp = yymsg; | |
3589 | } | |
3590 | } | |
3591 | yyerror (yymsgp); | |
3592 | if (yysyntax_error_status == 2) | |
3593 | goto yyexhaustedlab; | |
3185942a | 3594 | } |
a0c0a00f | 3595 | # undef YYSYNTAX_ERROR |
3185942a | 3596 | #endif |
f73dda09 | 3597 | } |
f73dda09 | 3598 | |
3185942a | 3599 | |
7117c2d2 | 3600 | |
f73dda09 JA |
3601 | if (yyerrstatus == 3) |
3602 | { | |
a0c0a00f CR |
3603 | /* If just tried and failed to reuse lookahead token after an |
3604 | error, discard it. */ | |
b80f6443 | 3605 | |
3185942a | 3606 | if (yychar <= YYEOF) |
a0c0a00f CR |
3607 | { |
3608 | /* Return failure if at end of input. */ | |
3609 | if (yychar == YYEOF) | |
3610 | YYABORT; | |
3611 | } | |
3185942a | 3612 | else |
a0c0a00f CR |
3613 | { |
3614 | yydestruct ("Error: discarding", | |
3615 | yytoken, &yylval); | |
3616 | yychar = YYEMPTY; | |
3617 | } | |
f73dda09 JA |
3618 | } |
3619 | ||
a0c0a00f | 3620 | /* Else will try to reuse lookahead token after shifting the error |
3185942a JA |
3621 | token. */ |
3622 | goto yyerrlab1; | |
f73dda09 | 3623 | |
f73dda09 | 3624 | |
3185942a JA |
3625 | /*---------------------------------------------------. |
3626 | | yyerrorlab -- error raised explicitly by YYERROR. | | |
3627 | `---------------------------------------------------*/ | |
3628 | yyerrorlab: | |
712f80b0 CR |
3629 | /* Pacify compilers when the user code never invokes YYERROR and the |
3630 | label yyerrorlab therefore never appears in user code. */ | |
3631 | if (0) | |
3632 | YYERROR; | |
f73dda09 | 3633 | |
a0c0a00f | 3634 | /* Do not reclaim the symbols of the rule whose action triggered |
3185942a JA |
3635 | this YYERROR. */ |
3636 | YYPOPSTACK (yylen); | |
3637 | yylen = 0; | |
3638 | YY_STACK_PRINT (yyss, yyssp); | |
3639 | yystate = *yyssp; | |
3640 | goto yyerrlab1; | |
f73dda09 | 3641 | |
f73dda09 | 3642 | |
3185942a JA |
3643 | /*-------------------------------------------------------------. |
3644 | | yyerrlab1 -- common code for both syntax error and YYERROR. | | |
3645 | `-------------------------------------------------------------*/ | |
3646 | yyerrlab1: | |
a0c0a00f | 3647 | yyerrstatus = 3; /* Each real token shifted decrements this. */ |
f73dda09 | 3648 | |
3185942a | 3649 | for (;;) |
f73dda09 | 3650 | { |
3185942a | 3651 | yyn = yypact[yystate]; |
a0c0a00f CR |
3652 | if (!yypact_value_is_default (yyn)) |
3653 | { | |
3654 | yyn += YYTERROR; | |
3655 | if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR) | |
3656 | { | |
3657 | yyn = yytable[yyn]; | |
3658 | if (0 < yyn) | |
3659 | break; | |
3660 | } | |
3661 | } | |
b80f6443 | 3662 | |
3185942a JA |
3663 | /* Pop the current state because it cannot handle the error token. */ |
3664 | if (yyssp == yyss) | |
a0c0a00f | 3665 | YYABORT; |
f73dda09 | 3666 | |
f73dda09 | 3667 | |
3185942a | 3668 | yydestruct ("Error: popping", |
a0c0a00f | 3669 | yystos[yystate], yyvsp); |
3185942a JA |
3670 | YYPOPSTACK (1); |
3671 | yystate = *yyssp; | |
3672 | YY_STACK_PRINT (yyss, yyssp); | |
f73dda09 | 3673 | } |
f73dda09 | 3674 | |
a0c0a00f | 3675 | YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN |
f73dda09 | 3676 | *++yyvsp = yylval; |
a0c0a00f | 3677 | YY_IGNORE_MAYBE_UNINITIALIZED_END |
3185942a JA |
3678 | |
3679 | ||
3680 | /* Shift the error token. */ | |
3681 | YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp); | |
f73dda09 JA |
3682 | |
3683 | yystate = yyn; | |
3684 | goto yynewstate; | |
3685 | ||
3185942a JA |
3686 | |
3687 | /*-------------------------------------. | |
3688 | | yyacceptlab -- YYACCEPT comes here. | | |
3689 | `-------------------------------------*/ | |
3690 | yyacceptlab: | |
3691 | yyresult = 0; | |
3692 | goto yyreturn; | |
3693 | ||
712f80b0 | 3694 | |
3185942a JA |
3695 | /*-----------------------------------. |
3696 | | yyabortlab -- YYABORT comes here. | | |
3697 | `-----------------------------------*/ | |
3698 | yyabortlab: | |
3699 | yyresult = 1; | |
3700 | goto yyreturn; | |
3701 | ||
712f80b0 | 3702 | |
a0c0a00f | 3703 | #if !defined yyoverflow || YYERROR_VERBOSE |
3185942a JA |
3704 | /*-------------------------------------------------. |
3705 | | yyexhaustedlab -- memory exhaustion comes here. | | |
3706 | `-------------------------------------------------*/ | |
3707 | yyexhaustedlab: | |
3708 | yyerror (YY_("memory exhausted")); | |
3709 | yyresult = 2; | |
3710 | /* Fall through. */ | |
b80f6443 | 3711 | #endif |
f73dda09 | 3712 | |
712f80b0 CR |
3713 | |
3714 | /*-----------------------------------------------------. | |
3715 | | yyreturn -- parsing is finished, return the result. | | |
3716 | `-----------------------------------------------------*/ | |
3185942a | 3717 | yyreturn: |
a0c0a00f CR |
3718 | if (yychar != YYEMPTY) |
3719 | { | |
3720 | /* Make sure we have latest lookahead translation. See comments at | |
3721 | user semantic actions for why this is necessary. */ | |
3722 | yytoken = YYTRANSLATE (yychar); | |
3723 | yydestruct ("Cleanup: discarding lookahead", | |
3724 | yytoken, &yylval); | |
3725 | } | |
3726 | /* Do not reclaim the symbols of the rule whose action triggered | |
3185942a JA |
3727 | this YYABORT or YYACCEPT. */ |
3728 | YYPOPSTACK (yylen); | |
3729 | YY_STACK_PRINT (yyss, yyssp); | |
3730 | while (yyssp != yyss) | |
b80f6443 | 3731 | { |
3185942a | 3732 | yydestruct ("Cleanup: popping", |
712f80b0 | 3733 | yystos[+*yyssp], yyvsp); |
3185942a | 3734 | YYPOPSTACK (1); |
b80f6443 | 3735 | } |
3185942a JA |
3736 | #ifndef yyoverflow |
3737 | if (yyss != yyssa) | |
3738 | YYSTACK_FREE (yyss); | |
3739 | #endif | |
3740 | #if YYERROR_VERBOSE | |
3741 | if (yymsg != yymsgbuf) | |
3742 | YYSTACK_FREE (yymsg); | |
3743 | #endif | |
a0c0a00f | 3744 | return yyresult; |
f73dda09 | 3745 | } |
712f80b0 | 3746 | #line 1322 "/usr/src/local/chet/src/bash/src/parse.y" |
3185942a | 3747 | |
f73dda09 JA |
3748 | |
3749 | /* Initial size to allocate for tokens, and the | |
3750 | amount to grow them by. */ | |
3751 | #define TOKEN_DEFAULT_INITIAL_SIZE 496 | |
3752 | #define TOKEN_DEFAULT_GROW_SIZE 512 | |
3753 | ||
b80f6443 JA |
3754 | /* Should we call prompt_again? */ |
3755 | #define SHOULD_PROMPT() \ | |
3756 | (interactive && (bash_input.type == st_stdin || bash_input.type == st_stream)) | |
3757 | ||
3758 | #if defined (ALIAS) | |
3759 | # define expanding_alias() (pushed_string_list && pushed_string_list->expander) | |
3760 | #else | |
3761 | # define expanding_alias() 0 | |
3762 | #endif | |
3763 | ||
f73dda09 JA |
3764 | /* Global var is non-zero when end of file has been reached. */ |
3765 | int EOF_Reached = 0; | |
3766 | ||
3767 | #ifdef DEBUG | |
3768 | static void | |
3769 | debug_parser (i) | |
3770 | int i; | |
3771 | { | |
3772 | #if YYDEBUG != 0 | |
3773 | yydebug = i; | |
d233b485 CR |
3774 | yyoutstream = stdout; |
3775 | yyerrstream = stderr; | |
f73dda09 JA |
3776 | #endif |
3777 | } | |
3778 | #endif | |
3779 | ||
3780 | /* yy_getc () returns the next available character from input or EOF. | |
3781 | yy_ungetc (c) makes `c' the next character to read. | |
3782 | init_yy_io (get, unget, type, location) makes the function GET the | |
3783 | installed function for getting the next character, makes UNGET the | |
3784 | installed function for un-getting a character, sets the type of stream | |
3785 | (either string or file) from TYPE, and makes LOCATION point to where | |
3786 | the input is coming from. */ | |
3787 | ||
3788 | /* Unconditionally returns end-of-file. */ | |
3789 | int | |
3790 | return_EOF () | |
3791 | { | |
3792 | return (EOF); | |
3793 | } | |
3794 | ||
3795 | /* Variable containing the current get and unget functions. | |
3796 | See ./input.h for a clearer description. */ | |
3797 | BASH_INPUT bash_input; | |
3798 | ||
3799 | /* Set all of the fields in BASH_INPUT to NULL. Free bash_input.name if it | |
3800 | is non-null, avoiding a memory leak. */ | |
3801 | void | |
3802 | initialize_bash_input () | |
3803 | { | |
3804 | bash_input.type = st_none; | |
3805 | FREE (bash_input.name); | |
3806 | bash_input.name = (char *)NULL; | |
3807 | bash_input.location.file = (FILE *)NULL; | |
3808 | bash_input.location.string = (char *)NULL; | |
3809 | bash_input.getter = (sh_cget_func_t *)NULL; | |
3810 | bash_input.ungetter = (sh_cunget_func_t *)NULL; | |
3811 | } | |
3812 | ||
3813 | /* Set the contents of the current bash input stream from | |
3814 | GET, UNGET, TYPE, NAME, and LOCATION. */ | |
3815 | void | |
3816 | init_yy_io (get, unget, type, name, location) | |
3817 | sh_cget_func_t *get; | |
3818 | sh_cunget_func_t *unget; | |
3819 | enum stream_type type; | |
3820 | const char *name; | |
3821 | INPUT_STREAM location; | |
3822 | { | |
3823 | bash_input.type = type; | |
3824 | FREE (bash_input.name); | |
3825 | bash_input.name = name ? savestring (name) : (char *)NULL; | |
3826 | ||
3827 | /* XXX */ | |
3828 | #if defined (CRAY) | |
3829 | memcpy((char *)&bash_input.location.string, (char *)&location.string, sizeof(location)); | |
3830 | #else | |
3831 | bash_input.location = location; | |
3832 | #endif | |
3833 | bash_input.getter = get; | |
3834 | bash_input.ungetter = unget; | |
3835 | } | |
3836 | ||
7117c2d2 JA |
3837 | char * |
3838 | yy_input_name () | |
3839 | { | |
3840 | return (bash_input.name ? bash_input.name : "stdin"); | |
3841 | } | |
3842 | ||
f73dda09 JA |
3843 | /* Call this to get the next character of input. */ |
3844 | static int | |
3845 | yy_getc () | |
3846 | { | |
3847 | return (*(bash_input.getter)) (); | |
3848 | } | |
3849 | ||
3850 | /* Call this to unget C. That is, to make C the next character | |
3851 | to be read. */ | |
3852 | static int | |
3853 | yy_ungetc (c) | |
3854 | int c; | |
3855 | { | |
3856 | return (*(bash_input.ungetter)) (c); | |
3857 | } | |
3858 | ||
3859 | #if defined (BUFFERED_INPUT) | |
3860 | #ifdef INCLUDE_UNUSED | |
3861 | int | |
3862 | input_file_descriptor () | |
3863 | { | |
3864 | switch (bash_input.type) | |
3865 | { | |
3866 | case st_stream: | |
3867 | return (fileno (bash_input.location.file)); | |
3868 | case st_bstream: | |
3869 | return (bash_input.location.buffered_fd); | |
3870 | case st_stdin: | |
3871 | default: | |
3872 | return (fileno (stdin)); | |
3873 | } | |
3874 | } | |
3875 | #endif | |
3876 | #endif /* BUFFERED_INPUT */ | |
3877 | ||
3878 | /* **************************************************************** */ | |
3879 | /* */ | |
3880 | /* Let input be read from readline (). */ | |
3881 | /* */ | |
3882 | /* **************************************************************** */ | |
3883 | ||
3884 | #if defined (READLINE) | |
3885 | char *current_readline_prompt = (char *)NULL; | |
3886 | char *current_readline_line = (char *)NULL; | |
3887 | int current_readline_line_index = 0; | |
3888 | ||
3889 | static int | |
3890 | yy_readline_get () | |
3891 | { | |
3892 | SigHandler *old_sigint; | |
3893 | int line_len; | |
3894 | unsigned char c; | |
3895 | ||
a0c0a00f | 3896 | if (current_readline_line == 0) |
f73dda09 | 3897 | { |
a0c0a00f | 3898 | if (bash_readline_initialized == 0) |
f73dda09 JA |
3899 | initialize_readline (); |
3900 | ||
3901 | #if defined (JOB_CONTROL) | |
3902 | if (job_control) | |
3903 | give_terminal_to (shell_pgrp, 0); | |
3904 | #endif /* JOB_CONTROL */ | |
3905 | ||
a0c0a00f | 3906 | old_sigint = IMPOSSIBLE_TRAP_HANDLER; |
f73dda09 JA |
3907 | if (signal_is_ignored (SIGINT) == 0) |
3908 | { | |
495aee44 | 3909 | old_sigint = (SigHandler *)set_signal_handler (SIGINT, sigint_sighandler); |
f73dda09 JA |
3910 | } |
3911 | ||
d233b485 | 3912 | sh_unset_nodelay_mode (fileno (rl_instream)); /* just in case */ |
f73dda09 JA |
3913 | current_readline_line = readline (current_readline_prompt ? |
3914 | current_readline_prompt : ""); | |
3915 | ||
ac50fbac | 3916 | CHECK_TERMSIG; |
495aee44 | 3917 | if (signal_is_ignored (SIGINT) == 0) |
f73dda09 | 3918 | { |
495aee44 CR |
3919 | if (old_sigint != IMPOSSIBLE_TRAP_HANDLER) |
3920 | set_signal_handler (SIGINT, old_sigint); | |
f73dda09 JA |
3921 | } |
3922 | ||
3923 | #if 0 | |
3924 | /* Reset the prompt to the decoded value of prompt_string_pointer. */ | |
3925 | reset_readline_prompt (); | |
3926 | #endif | |
3927 | ||
3928 | if (current_readline_line == 0) | |
3929 | return (EOF); | |
3930 | ||
3931 | current_readline_line_index = 0; | |
3932 | line_len = strlen (current_readline_line); | |
3933 | ||
3934 | current_readline_line = (char *)xrealloc (current_readline_line, 2 + line_len); | |
3935 | current_readline_line[line_len++] = '\n'; | |
3936 | current_readline_line[line_len] = '\0'; | |
3937 | } | |
3938 | ||
3939 | if (current_readline_line[current_readline_line_index] == 0) | |
3940 | { | |
3941 | free (current_readline_line); | |
3942 | current_readline_line = (char *)NULL; | |
3943 | return (yy_readline_get ()); | |
3944 | } | |
3945 | else | |
3946 | { | |
3947 | c = current_readline_line[current_readline_line_index++]; | |
3948 | return (c); | |
3949 | } | |
3950 | } | |
3951 | ||
3952 | static int | |
3953 | yy_readline_unget (c) | |
3954 | int c; | |
3955 | { | |
3956 | if (current_readline_line_index && current_readline_line) | |
3957 | current_readline_line[--current_readline_line_index] = c; | |
3958 | return (c); | |
3959 | } | |
3960 | ||
3961 | void | |
3962 | with_input_from_stdin () | |
3963 | { | |
3964 | INPUT_STREAM location; | |
3965 | ||
3966 | if (bash_input.type != st_stdin && stream_on_stack (st_stdin) == 0) | |
3967 | { | |
3968 | location.string = current_readline_line; | |
3969 | init_yy_io (yy_readline_get, yy_readline_unget, | |
3970 | st_stdin, "readline stdin", location); | |
3971 | } | |
3972 | } | |
3973 | ||
712f80b0 CR |
3974 | /* Will we be collecting another input line and printing a prompt? This uses |
3975 | different conditions than SHOULD_PROMPT(), since readline allows a user to | |
3976 | embed a newline in the middle of the line it collects, which the parser | |
3977 | will interpret as a line break and command delimiter. */ | |
3978 | int | |
3979 | parser_will_prompt () | |
3980 | { | |
3981 | return (current_readline_line == 0 || current_readline_line[current_readline_line_index] == 0); | |
3982 | } | |
3983 | ||
f73dda09 JA |
3984 | #else /* !READLINE */ |
3985 | ||
3986 | void | |
3987 | with_input_from_stdin () | |
3988 | { | |
3989 | with_input_from_stream (stdin, "stdin"); | |
3990 | } | |
3991 | #endif /* !READLINE */ | |
3992 | ||
3993 | /* **************************************************************** */ | |
3994 | /* */ | |
3995 | /* Let input come from STRING. STRING is zero terminated. */ | |
3996 | /* */ | |
3997 | /* **************************************************************** */ | |
3998 | ||
3999 | static int | |
4000 | yy_string_get () | |
4001 | { | |
4002 | register char *string; | |
4003 | register unsigned char c; | |
4004 | ||
4005 | string = bash_input.location.string; | |
4006 | ||
4007 | /* If the string doesn't exist, or is empty, EOF found. */ | |
4008 | if (string && *string) | |
4009 | { | |
4010 | c = *string++; | |
4011 | bash_input.location.string = string; | |
4012 | return (c); | |
4013 | } | |
4014 | else | |
4015 | return (EOF); | |
4016 | } | |
4017 | ||
4018 | static int | |
4019 | yy_string_unget (c) | |
4020 | int c; | |
4021 | { | |
4022 | *(--bash_input.location.string) = c; | |
4023 | return (c); | |
4024 | } | |
4025 | ||
4026 | void | |
4027 | with_input_from_string (string, name) | |
4028 | char *string; | |
4029 | const char *name; | |
4030 | { | |
4031 | INPUT_STREAM location; | |
4032 | ||
4033 | location.string = string; | |
4034 | init_yy_io (yy_string_get, yy_string_unget, st_string, name, location); | |
4035 | } | |
4036 | ||
3185942a JA |
4037 | /* Count the number of characters we've consumed from bash_input.location.string |
4038 | and read into shell_input_line, but have not returned from shell_getc. | |
4039 | That is the true input location. Rewind bash_input.location.string by | |
4040 | that number of characters, so it points to the last character actually | |
4041 | consumed by the parser. */ | |
4042 | static void | |
4043 | rewind_input_string () | |
4044 | { | |
4045 | int xchars; | |
4046 | ||
4047 | /* number of unconsumed characters in the input -- XXX need to take newlines | |
4048 | into account, e.g., $(...\n) */ | |
4049 | xchars = shell_input_line_len - shell_input_line_index; | |
4050 | if (bash_input.location.string[-1] == '\n') | |
4051 | xchars++; | |
4052 | ||
4053 | /* XXX - how to reflect bash_input.location.string back to string passed to | |
4054 | parse_and_execute or xparse_dolparen? xparse_dolparen needs to know how | |
4055 | far into the string we parsed. parse_and_execute knows where bash_input. | |
4056 | location.string is, and how far from orig_string that is -- that's the | |
4057 | number of characters the command consumed. */ | |
4058 | ||
4059 | /* bash_input.location.string - xchars should be where we parsed to */ | |
4060 | /* need to do more validation on xchars value for sanity -- test cases. */ | |
4061 | bash_input.location.string -= xchars; | |
4062 | } | |
4063 | ||
f73dda09 JA |
4064 | /* **************************************************************** */ |
4065 | /* */ | |
4066 | /* Let input come from STREAM. */ | |
4067 | /* */ | |
4068 | /* **************************************************************** */ | |
4069 | ||
4070 | /* These two functions used to test the value of the HAVE_RESTARTABLE_SYSCALLS | |
4071 | define, and just use getc/ungetc if it was defined, but since bash | |
4072 | installs its signal handlers without the SA_RESTART flag, some signals | |
4073 | (like SIGCHLD, SIGWINCH, etc.) received during a read(2) will not cause | |
4074 | the read to be restarted. We need to restart it ourselves. */ | |
4075 | ||
4076 | static int | |
4077 | yy_stream_get () | |
4078 | { | |
4079 | int result; | |
4080 | ||
4081 | result = EOF; | |
4082 | if (bash_input.location.file) | |
95732b49 | 4083 | { |
ac50fbac CR |
4084 | /* XXX - don't need terminate_immediately; getc_with_restart checks |
4085 | for terminating signals itself if read returns < 0 */ | |
95732b49 | 4086 | result = getc_with_restart (bash_input.location.file); |
95732b49 | 4087 | } |
f73dda09 JA |
4088 | return (result); |
4089 | } | |
4090 | ||
4091 | static int | |
4092 | yy_stream_unget (c) | |
4093 | int c; | |
4094 | { | |
4095 | return (ungetc_with_restart (c, bash_input.location.file)); | |
4096 | } | |
4097 | ||
4098 | void | |
4099 | with_input_from_stream (stream, name) | |
4100 | FILE *stream; | |
4101 | const char *name; | |
4102 | { | |
4103 | INPUT_STREAM location; | |
4104 | ||
4105 | location.file = stream; | |
4106 | init_yy_io (yy_stream_get, yy_stream_unget, st_stream, name, location); | |
4107 | } | |
4108 | ||
4109 | typedef struct stream_saver { | |
4110 | struct stream_saver *next; | |
4111 | BASH_INPUT bash_input; | |
4112 | int line; | |
4113 | #if defined (BUFFERED_INPUT) | |
4114 | BUFFERED_STREAM *bstream; | |
4115 | #endif /* BUFFERED_INPUT */ | |
4116 | } STREAM_SAVER; | |
4117 | ||
4118 | /* The globally known line number. */ | |
4119 | int line_number = 0; | |
4120 | ||
495aee44 CR |
4121 | /* The line number offset set by assigning to LINENO. Not currently used. */ |
4122 | int line_number_base = 0; | |
4123 | ||
f73dda09 JA |
4124 | #if defined (COND_COMMAND) |
4125 | static int cond_lineno; | |
4126 | static int cond_token; | |
4127 | #endif | |
4128 | ||
4129 | STREAM_SAVER *stream_list = (STREAM_SAVER *)NULL; | |
4130 | ||
4131 | void | |
4132 | push_stream (reset_lineno) | |
4133 | int reset_lineno; | |
4134 | { | |
4135 | STREAM_SAVER *saver = (STREAM_SAVER *)xmalloc (sizeof (STREAM_SAVER)); | |
4136 | ||
4137 | xbcopy ((char *)&bash_input, (char *)&(saver->bash_input), sizeof (BASH_INPUT)); | |
4138 | ||
4139 | #if defined (BUFFERED_INPUT) | |
4140 | saver->bstream = (BUFFERED_STREAM *)NULL; | |
4141 | /* If we have a buffered stream, clear out buffers[fd]. */ | |
4142 | if (bash_input.type == st_bstream && bash_input.location.buffered_fd >= 0) | |
4143 | saver->bstream = set_buffered_stream (bash_input.location.buffered_fd, | |
4144 | (BUFFERED_STREAM *)NULL); | |
4145 | #endif /* BUFFERED_INPUT */ | |
4146 | ||
4147 | saver->line = line_number; | |
4148 | bash_input.name = (char *)NULL; | |
4149 | saver->next = stream_list; | |
4150 | stream_list = saver; | |
4151 | EOF_Reached = 0; | |
4152 | if (reset_lineno) | |
4153 | line_number = 0; | |
4154 | } | |
4155 | ||
4156 | void | |
4157 | pop_stream () | |
4158 | { | |
4159 | if (!stream_list) | |
4160 | EOF_Reached = 1; | |
4161 | else | |
4162 | { | |
4163 | STREAM_SAVER *saver = stream_list; | |
4164 | ||
4165 | EOF_Reached = 0; | |
4166 | stream_list = stream_list->next; | |
4167 | ||
4168 | init_yy_io (saver->bash_input.getter, | |
4169 | saver->bash_input.ungetter, | |
4170 | saver->bash_input.type, | |
4171 | saver->bash_input.name, | |
4172 | saver->bash_input.location); | |
4173 | ||
4174 | #if defined (BUFFERED_INPUT) | |
4175 | /* If we have a buffered stream, restore buffers[fd]. */ | |
4176 | /* If the input file descriptor was changed while this was on the | |
4177 | save stack, update the buffered fd to the new file descriptor and | |
4178 | re-establish the buffer <-> bash_input fd correspondence. */ | |
4179 | if (bash_input.type == st_bstream && bash_input.location.buffered_fd >= 0) | |
4180 | { | |
4181 | if (bash_input_fd_changed) | |
4182 | { | |
4183 | bash_input_fd_changed = 0; | |
4184 | if (default_buffered_input >= 0) | |
4185 | { | |
4186 | bash_input.location.buffered_fd = default_buffered_input; | |
4187 | saver->bstream->b_fd = default_buffered_input; | |
4188 | SET_CLOSE_ON_EXEC (default_buffered_input); | |
4189 | } | |
4190 | } | |
4191 | /* XXX could free buffered stream returned as result here. */ | |
4192 | set_buffered_stream (bash_input.location.buffered_fd, saver->bstream); | |
4193 | } | |
4194 | #endif /* BUFFERED_INPUT */ | |
4195 | ||
4196 | line_number = saver->line; | |
4197 | ||
4198 | FREE (saver->bash_input.name); | |
4199 | free (saver); | |
4200 | } | |
4201 | } | |
4202 | ||
4203 | /* Return 1 if a stream of type TYPE is saved on the stack. */ | |
4204 | int | |
4205 | stream_on_stack (type) | |
4206 | enum stream_type type; | |
4207 | { | |
4208 | register STREAM_SAVER *s; | |
4209 | ||
4210 | for (s = stream_list; s; s = s->next) | |
4211 | if (s->bash_input.type == type) | |
4212 | return 1; | |
4213 | return 0; | |
4214 | } | |
4215 | ||
4216 | /* Save the current token state and return it in a malloced array. */ | |
4217 | int * | |
4218 | save_token_state () | |
4219 | { | |
4220 | int *ret; | |
4221 | ||
0001803f | 4222 | ret = (int *)xmalloc (4 * sizeof (int)); |
f73dda09 JA |
4223 | ret[0] = last_read_token; |
4224 | ret[1] = token_before_that; | |
4225 | ret[2] = two_tokens_ago; | |
0001803f | 4226 | ret[3] = current_token; |
f73dda09 JA |
4227 | return ret; |
4228 | } | |
4229 | ||
4230 | void | |
4231 | restore_token_state (ts) | |
4232 | int *ts; | |
4233 | { | |
4234 | if (ts == 0) | |
4235 | return; | |
4236 | last_read_token = ts[0]; | |
4237 | token_before_that = ts[1]; | |
4238 | two_tokens_ago = ts[2]; | |
0001803f | 4239 | current_token = ts[3]; |
f73dda09 JA |
4240 | } |
4241 | ||
4242 | /* | |
4243 | * This is used to inhibit alias expansion and reserved word recognition | |
4244 | * inside case statement pattern lists. A `case statement pattern list' is: | |
4245 | * | |
4246 | * everything between the `in' in a `case word in' and the next ')' | |
4247 | * or `esac' | |
4248 | * everything between a `;;' and the next `)' or `esac' | |
4249 | */ | |
4250 | ||
4251 | #if defined (ALIAS) || defined (DPAREN_ARITHMETIC) | |
4252 | ||
f73dda09 JA |
4253 | #define END_OF_ALIAS 0 |
4254 | ||
4255 | /* | |
4256 | * Pseudo-global variables used in implementing token-wise alias expansion. | |
4257 | */ | |
4258 | ||
4259 | /* | |
4260 | * Pushing and popping strings. This works together with shell_getc to | |
4261 | * implement alias expansion on a per-token basis. | |
4262 | */ | |
4263 | ||
ac50fbac CR |
4264 | #define PSH_ALIAS 0x01 |
4265 | #define PSH_DPAREN 0x02 | |
4266 | #define PSH_SOURCE 0x04 | |
4267 | ||
f73dda09 JA |
4268 | typedef struct string_saver { |
4269 | struct string_saver *next; | |
4270 | int expand_alias; /* Value to set expand_alias to when string is popped. */ | |
4271 | char *saved_line; | |
4272 | #if defined (ALIAS) | |
4273 | alias_t *expander; /* alias that caused this line to be pushed. */ | |
4274 | #endif | |
ac50fbac CR |
4275 | size_t saved_line_size, saved_line_index; |
4276 | int saved_line_terminator; | |
4277 | int flags; | |
f73dda09 JA |
4278 | } STRING_SAVER; |
4279 | ||
4280 | STRING_SAVER *pushed_string_list = (STRING_SAVER *)NULL; | |
4281 | ||
4282 | /* | |
4283 | * Push the current shell_input_line onto a stack of such lines and make S | |
4284 | * the current input. Used when expanding aliases. EXPAND is used to set | |
4285 | * the value of expand_next_token when the string is popped, so that the | |
4286 | * word after the alias in the original line is handled correctly when the | |
4287 | * alias expands to multiple words. TOKEN is the token that was expanded | |
4288 | * into S; it is saved and used to prevent infinite recursive expansion. | |
4289 | */ | |
4290 | static void | |
4291 | push_string (s, expand, ap) | |
4292 | char *s; | |
4293 | int expand; | |
4294 | alias_t *ap; | |
4295 | { | |
4296 | STRING_SAVER *temp = (STRING_SAVER *)xmalloc (sizeof (STRING_SAVER)); | |
4297 | ||
4298 | temp->expand_alias = expand; | |
4299 | temp->saved_line = shell_input_line; | |
4300 | temp->saved_line_size = shell_input_line_size; | |
4301 | temp->saved_line_index = shell_input_line_index; | |
4302 | temp->saved_line_terminator = shell_input_line_terminator; | |
ac50fbac | 4303 | temp->flags = 0; |
f73dda09 JA |
4304 | #if defined (ALIAS) |
4305 | temp->expander = ap; | |
ac50fbac CR |
4306 | if (ap) |
4307 | temp->flags = PSH_ALIAS; | |
f73dda09 JA |
4308 | #endif |
4309 | temp->next = pushed_string_list; | |
4310 | pushed_string_list = temp; | |
4311 | ||
4312 | #if defined (ALIAS) | |
4313 | if (ap) | |
4314 | ap->flags |= AL_BEINGEXPANDED; | |
4315 | #endif | |
4316 | ||
4317 | shell_input_line = s; | |
ac50fbac | 4318 | shell_input_line_size = STRLEN (s); |
f73dda09 JA |
4319 | shell_input_line_index = 0; |
4320 | shell_input_line_terminator = '\0'; | |
b80f6443 JA |
4321 | #if 0 |
4322 | parser_state &= ~PST_ALEXPNEXT; /* XXX */ | |
4323 | #endif | |
7117c2d2 JA |
4324 | |
4325 | set_line_mbstate (); | |
f73dda09 JA |
4326 | } |
4327 | ||
4328 | /* | |
4329 | * Make the top of the pushed_string stack be the current shell input. | |
4330 | * Only called when there is something on the stack. Called from shell_getc | |
4331 | * when it thinks it has consumed the string generated by an alias expansion | |
4332 | * and needs to return to the original input line. | |
4333 | */ | |
4334 | static void | |
4335 | pop_string () | |
4336 | { | |
4337 | STRING_SAVER *t; | |
4338 | ||
4339 | FREE (shell_input_line); | |
4340 | shell_input_line = pushed_string_list->saved_line; | |
4341 | shell_input_line_index = pushed_string_list->saved_line_index; | |
4342 | shell_input_line_size = pushed_string_list->saved_line_size; | |
4343 | shell_input_line_terminator = pushed_string_list->saved_line_terminator; | |
4344 | ||
4345 | if (pushed_string_list->expand_alias) | |
4346 | parser_state |= PST_ALEXPNEXT; | |
4347 | else | |
4348 | parser_state &= ~PST_ALEXPNEXT; | |
4349 | ||
4350 | t = pushed_string_list; | |
4351 | pushed_string_list = pushed_string_list->next; | |
4352 | ||
4353 | #if defined (ALIAS) | |
4354 | if (t->expander) | |
4355 | t->expander->flags &= ~AL_BEINGEXPANDED; | |
4356 | #endif | |
4357 | ||
4358 | free ((char *)t); | |
7117c2d2 JA |
4359 | |
4360 | set_line_mbstate (); | |
f73dda09 JA |
4361 | } |
4362 | ||
4363 | static void | |
4364 | free_string_list () | |
4365 | { | |
4366 | register STRING_SAVER *t, *t1; | |
4367 | ||
4368 | for (t = pushed_string_list; t; ) | |
4369 | { | |
4370 | t1 = t->next; | |
4371 | FREE (t->saved_line); | |
4372 | #if defined (ALIAS) | |
4373 | if (t->expander) | |
4374 | t->expander->flags &= ~AL_BEINGEXPANDED; | |
4375 | #endif | |
4376 | free ((char *)t); | |
4377 | t = t1; | |
4378 | } | |
4379 | pushed_string_list = (STRING_SAVER *)NULL; | |
4380 | } | |
4381 | ||
4382 | #endif /* ALIAS || DPAREN_ARITHMETIC */ | |
4383 | ||
b80f6443 JA |
4384 | void |
4385 | free_pushed_string_input () | |
4386 | { | |
4387 | #if defined (ALIAS) || defined (DPAREN_ARITHMETIC) | |
4388 | free_string_list (); | |
4389 | #endif | |
4390 | } | |
4391 | ||
ac50fbac CR |
4392 | int |
4393 | parser_expanding_alias () | |
4394 | { | |
4395 | return (expanding_alias ()); | |
4396 | } | |
4397 | ||
4398 | void | |
4399 | parser_save_alias () | |
4400 | { | |
4401 | #if defined (ALIAS) || defined (DPAREN_ARITHMETIC) | |
4402 | push_string ((char *)NULL, 0, (alias_t *)NULL); | |
4403 | pushed_string_list->flags = PSH_SOURCE; /* XXX - for now */ | |
4404 | #else | |
4405 | ; | |
4406 | #endif | |
4407 | } | |
4408 | ||
4409 | void | |
4410 | parser_restore_alias () | |
4411 | { | |
4412 | #if defined (ALIAS) || defined (DPAREN_ARITHMETIC) | |
4413 | if (pushed_string_list) | |
4414 | pop_string (); | |
4415 | #else | |
4416 | ; | |
4417 | #endif | |
4418 | } | |
4419 | ||
d233b485 CR |
4420 | #if defined (ALIAS) |
4421 | /* Before freeing AP, make sure that there aren't any cases of pointer | |
4422 | aliasing that could cause us to reference freed memory later on. */ | |
4423 | void | |
4424 | clear_string_list_expander (ap) | |
4425 | alias_t *ap; | |
4426 | { | |
4427 | register STRING_SAVER *t; | |
4428 | ||
4429 | for (t = pushed_string_list; t; t = t->next) | |
4430 | { | |
4431 | if (t->expander && t->expander == ap) | |
4432 | t->expander = 0; | |
4433 | } | |
4434 | } | |
4435 | #endif | |
4436 | ||
a0c0a00f CR |
4437 | void |
4438 | clear_shell_input_line () | |
4439 | { | |
4440 | if (shell_input_line) | |
4441 | shell_input_line[shell_input_line_index = 0] = '\0'; | |
4442 | } | |
4443 | ||
f73dda09 JA |
4444 | /* Return a line of text, taken from wherever yylex () reads input. |
4445 | If there is no more input, then we return NULL. If REMOVE_QUOTED_NEWLINE | |
4446 | is non-zero, we remove unquoted \<newline> pairs. This is used by | |
4447 | read_secondary_line to read here documents. */ | |
4448 | static char * | |
4449 | read_a_line (remove_quoted_newline) | |
4450 | int remove_quoted_newline; | |
4451 | { | |
4452 | static char *line_buffer = (char *)NULL; | |
4453 | static int buffer_size = 0; | |
0001803f | 4454 | int indx, c, peekc, pass_next; |
f73dda09 JA |
4455 | |
4456 | #if defined (READLINE) | |
b80f6443 | 4457 | if (no_line_editing && SHOULD_PROMPT ()) |
f73dda09 | 4458 | #else |
b80f6443 | 4459 | if (SHOULD_PROMPT ()) |
f73dda09 JA |
4460 | #endif |
4461 | print_prompt (); | |
4462 | ||
0001803f | 4463 | pass_next = indx = 0; |
f73dda09 JA |
4464 | while (1) |
4465 | { | |
f73dda09 JA |
4466 | /* Allow immediate exit if interrupted during input. */ |
4467 | QUIT; | |
4468 | ||
95732b49 JA |
4469 | c = yy_getc (); |
4470 | ||
f73dda09 JA |
4471 | /* Ignore null bytes in input. */ |
4472 | if (c == 0) | |
4473 | { | |
4474 | #if 0 | |
4475 | internal_warning ("read_a_line: ignored null byte in input"); | |
4476 | #endif | |
4477 | continue; | |
4478 | } | |
4479 | ||
4480 | /* If there is no more input, then we return NULL. */ | |
4481 | if (c == EOF) | |
4482 | { | |
4483 | if (interactive && bash_input.type == st_stream) | |
4484 | clearerr (stdin); | |
4485 | if (indx == 0) | |
4486 | return ((char *)NULL); | |
4487 | c = '\n'; | |
4488 | } | |
4489 | ||
d233b485 CR |
4490 | /* `+2' in case the final character in the buffer is a newline or we |
4491 | have to handle CTLESC or CTLNUL. */ | |
f73dda09 JA |
4492 | RESIZE_MALLOCED_BUFFER (line_buffer, indx, 2, buffer_size, 128); |
4493 | ||
4494 | /* IF REMOVE_QUOTED_NEWLINES is non-zero, we are reading a | |
4495 | here document with an unquoted delimiter. In this case, | |
4496 | the line will be expanded as if it were in double quotes. | |
4497 | We allow a backslash to escape the next character, but we | |
4498 | need to treat the backslash specially only if a backslash | |
4499 | quoting a backslash-newline pair appears in the line. */ | |
4500 | if (pass_next) | |
4501 | { | |
4502 | line_buffer[indx++] = c; | |
4503 | pass_next = 0; | |
4504 | } | |
4505 | else if (c == '\\' && remove_quoted_newline) | |
4506 | { | |
495aee44 | 4507 | QUIT; |
f73dda09 JA |
4508 | peekc = yy_getc (); |
4509 | if (peekc == '\n') | |
b80f6443 JA |
4510 | { |
4511 | line_number++; | |
4512 | continue; /* Make the unquoted \<newline> pair disappear. */ | |
4513 | } | |
f73dda09 JA |
4514 | else |
4515 | { | |
4516 | yy_ungetc (peekc); | |
4517 | pass_next = 1; | |
4518 | line_buffer[indx++] = c; /* Preserve the backslash. */ | |
4519 | } | |
4520 | } | |
4521 | else | |
d233b485 CR |
4522 | { |
4523 | /* remove_quoted_newline is non-zero if the here-document delimiter | |
4524 | is unquoted. In this case, we will be expanding the lines and | |
4525 | need to make sure CTLESC and CTLNUL in the input are quoted. */ | |
4526 | if (remove_quoted_newline && (c == CTLESC || c == CTLNUL)) | |
4527 | line_buffer[indx++] = CTLESC; | |
4528 | line_buffer[indx++] = c; | |
4529 | } | |
f73dda09 JA |
4530 | |
4531 | if (c == '\n') | |
4532 | { | |
4533 | line_buffer[indx] = '\0'; | |
4534 | return (line_buffer); | |
4535 | } | |
4536 | } | |
4537 | } | |
4538 | ||
4539 | /* Return a line as in read_a_line (), but insure that the prompt is | |
4540 | the secondary prompt. This is used to read the lines of a here | |
4541 | document. REMOVE_QUOTED_NEWLINE is non-zero if we should remove | |
4542 | newlines quoted with backslashes while reading the line. It is | |
4543 | non-zero unless the delimiter of the here document was quoted. */ | |
4544 | char * | |
4545 | read_secondary_line (remove_quoted_newline) | |
4546 | int remove_quoted_newline; | |
4547 | { | |
3185942a JA |
4548 | char *ret; |
4549 | int n, c; | |
4550 | ||
f73dda09 | 4551 | prompt_string_pointer = &ps2_prompt; |
b80f6443 JA |
4552 | if (SHOULD_PROMPT()) |
4553 | prompt_again (); | |
3185942a JA |
4554 | ret = read_a_line (remove_quoted_newline); |
4555 | #if defined (HISTORY) | |
0001803f | 4556 | if (ret && remember_on_history && (parser_state & PST_HEREDOC)) |
3185942a | 4557 | { |
a0c0a00f CR |
4558 | /* To make adding the here-document body right, we need to rely on |
4559 | history_delimiting_chars() returning \n for the first line of the | |
4560 | here-document body and the null string for the second and subsequent | |
4561 | lines, so we avoid double newlines. | |
3185942a JA |
4562 | current_command_line_count == 2 for the first line of the body. */ |
4563 | ||
4564 | current_command_line_count++; | |
4565 | maybe_add_history (ret); | |
4566 | } | |
4567 | #endif /* HISTORY */ | |
4568 | return ret; | |
f73dda09 JA |
4569 | } |
4570 | ||
4571 | /* **************************************************************** */ | |
4572 | /* */ | |
4573 | /* YYLEX () */ | |
4574 | /* */ | |
4575 | /* **************************************************************** */ | |
4576 | ||
4577 | /* Reserved words. These are only recognized as the first word of a | |
4578 | command. */ | |
4579 | STRING_INT_ALIST word_token_alist[] = { | |
4580 | { "if", IF }, | |
4581 | { "then", THEN }, | |
28ef6c31 JA |
4582 | { "else", ELSE }, |
4583 | { "elif", ELIF }, | |
4584 | { "fi", FI }, | |
4585 | { "case", CASE }, | |
4586 | { "esac", ESAC }, | |
4587 | { "for", FOR }, | |
4588 | #if defined (SELECT_COMMAND) | |
4589 | { "select", SELECT }, | |
726f6388 | 4590 | #endif |
28ef6c31 JA |
4591 | { "while", WHILE }, |
4592 | { "until", UNTIL }, | |
4593 | { "do", DO }, | |
4594 | { "done", DONE }, | |
4595 | { "in", IN }, | |
4596 | { "function", FUNCTION }, | |
4597 | #if defined (COMMAND_TIMING) | |
4598 | { "time", TIME }, | |
4599 | #endif | |
4600 | { "{", '{' }, | |
4601 | { "}", '}' }, | |
4602 | { "!", BANG }, | |
4603 | #if defined (COND_COMMAND) | |
4604 | { "[[", COND_START }, | |
4605 | { "]]", COND_END }, | |
3185942a JA |
4606 | #endif |
4607 | #if defined (COPROCESS_SUPPORT) | |
4608 | { "coproc", COPROC }, | |
726f6388 | 4609 | #endif |
28ef6c31 JA |
4610 | { (char *)NULL, 0} |
4611 | }; | |
726f6388 | 4612 | |
7117c2d2 JA |
4613 | /* other tokens that can be returned by read_token() */ |
4614 | STRING_INT_ALIST other_token_alist[] = { | |
4615 | /* Multiple-character tokens with special values */ | |
495aee44 | 4616 | { "--", TIMEIGN }, |
7117c2d2 JA |
4617 | { "-p", TIMEOPT }, |
4618 | { "&&", AND_AND }, | |
4619 | { "||", OR_OR }, | |
4620 | { ">>", GREATER_GREATER }, | |
4621 | { "<<", LESS_LESS }, | |
4622 | { "<&", LESS_AND }, | |
4623 | { ">&", GREATER_AND }, | |
4624 | { ";;", SEMI_SEMI }, | |
3185942a JA |
4625 | { ";&", SEMI_AND }, |
4626 | { ";;&", SEMI_SEMI_AND }, | |
7117c2d2 JA |
4627 | { "<<-", LESS_LESS_MINUS }, |
4628 | { "<<<", LESS_LESS_LESS }, | |
4629 | { "&>", AND_GREATER }, | |
3185942a | 4630 | { "&>>", AND_GREATER_GREATER }, |
7117c2d2 JA |
4631 | { "<>", LESS_GREATER }, |
4632 | { ">|", GREATER_BAR }, | |
3185942a | 4633 | { "|&", BAR_AND }, |
7117c2d2 JA |
4634 | { "EOF", yacc_EOF }, |
4635 | /* Tokens whose value is the character itself */ | |
4636 | { ">", '>' }, | |
4637 | { "<", '<' }, | |
4638 | { "-", '-' }, | |
4639 | { "{", '{' }, | |
4640 | { "}", '}' }, | |
4641 | { ";", ';' }, | |
4642 | { "(", '(' }, | |
4643 | { ")", ')' }, | |
4644 | { "|", '|' }, | |
4645 | { "&", '&' }, | |
4646 | { "newline", '\n' }, | |
4647 | { (char *)NULL, 0} | |
4648 | }; | |
4649 | ||
4650 | /* others not listed here: | |
4651 | WORD look at yylval.word | |
4652 | ASSIGNMENT_WORD look at yylval.word | |
4653 | NUMBER look at yylval.number | |
4654 | ARITH_CMD look at yylval.word_list | |
4655 | ARITH_FOR_EXPRS look at yylval.word_list | |
4656 | COND_CMD look at yylval.command | |
4657 | */ | |
726f6388 | 4658 | |
28ef6c31 JA |
4659 | /* These are used by read_token_word, but appear up here so that shell_getc |
4660 | can use them to decide when to add otherwise blank lines to the history. */ | |
726f6388 | 4661 | |
28ef6c31 JA |
4662 | /* The primary delimiter stack. */ |
4663 | struct dstack dstack = { (char *)NULL, 0, 0 }; | |
726f6388 | 4664 | |
28ef6c31 JA |
4665 | /* A temporary delimiter stack to be used when decoding prompt strings. |
4666 | This is needed because command substitutions in prompt strings (e.g., PS2) | |
4667 | can screw up the parser's quoting state. */ | |
4668 | static struct dstack temp_dstack = { (char *)NULL, 0, 0 }; | |
726f6388 | 4669 | |
28ef6c31 JA |
4670 | /* Macro for accessing the top delimiter on the stack. Returns the |
4671 | delimiter or zero if none. */ | |
4672 | #define current_delimiter(ds) \ | |
4673 | (ds.delimiter_depth ? ds.delimiters[ds.delimiter_depth - 1] : 0) | |
726f6388 | 4674 | |
28ef6c31 JA |
4675 | #define push_delimiter(ds, character) \ |
4676 | do \ | |
4677 | { \ | |
4678 | if (ds.delimiter_depth + 2 > ds.delimiter_space) \ | |
f73dda09 | 4679 | ds.delimiters = (char *)xrealloc \ |
28ef6c31 JA |
4680 | (ds.delimiters, (ds.delimiter_space += 10) * sizeof (char)); \ |
4681 | ds.delimiters[ds.delimiter_depth] = character; \ | |
4682 | ds.delimiter_depth++; \ | |
4683 | } \ | |
4684 | while (0) | |
726f6388 | 4685 | |
28ef6c31 | 4686 | #define pop_delimiter(ds) ds.delimiter_depth-- |
726f6388 | 4687 | |
28ef6c31 JA |
4688 | /* Return the next shell input character. This always reads characters |
4689 | from shell_input_line; when that line is exhausted, it is time to | |
4690 | read the next line. This is called by read_token when the shell is | |
4691 | processing normal command input. */ | |
ccc6cda3 | 4692 | |
28ef6c31 JA |
4693 | /* This implements one-character lookahead/lookbehind across physical input |
4694 | lines, to avoid something being lost because it's pushed back with | |
4695 | shell_ungetc when we're at the start of a line. */ | |
4696 | static int eol_ungetc_lookahead = 0; | |
726f6388 | 4697 | |
712f80b0 CR |
4698 | static int unquoted_backslash = 0; |
4699 | ||
28ef6c31 JA |
4700 | static int |
4701 | shell_getc (remove_quoted_newline) | |
4702 | int remove_quoted_newline; | |
4703 | { | |
4704 | register int i; | |
a0c0a00f | 4705 | int c, truncating, last_was_backslash; |
f73dda09 | 4706 | unsigned char uc; |
726f6388 | 4707 | |
28ef6c31 | 4708 | QUIT; |
726f6388 | 4709 | |
a0c0a00f | 4710 | last_was_backslash = 0; |
95732b49 JA |
4711 | if (sigwinch_received) |
4712 | { | |
4713 | sigwinch_received = 0; | |
4714 | get_new_window_size (0, (int *)0, (int *)0); | |
4715 | } | |
4716 | ||
28ef6c31 JA |
4717 | if (eol_ungetc_lookahead) |
4718 | { | |
4719 | c = eol_ungetc_lookahead; | |
4720 | eol_ungetc_lookahead = 0; | |
4721 | return (c); | |
4722 | } | |
ccc6cda3 | 4723 | |
28ef6c31 JA |
4724 | #if defined (ALIAS) || defined (DPAREN_ARITHMETIC) |
4725 | /* If shell_input_line[shell_input_line_index] == 0, but there is | |
4726 | something on the pushed list of strings, then we don't want to go | |
4727 | off and get another line. We let the code down below handle it. */ | |
b72432fd | 4728 | |
28ef6c31 JA |
4729 | if (!shell_input_line || ((!shell_input_line[shell_input_line_index]) && |
4730 | (pushed_string_list == (STRING_SAVER *)NULL))) | |
4731 | #else /* !ALIAS && !DPAREN_ARITHMETIC */ | |
4732 | if (!shell_input_line || !shell_input_line[shell_input_line_index]) | |
4733 | #endif /* !ALIAS && !DPAREN_ARITHMETIC */ | |
4734 | { | |
4735 | line_number++; | |
726f6388 | 4736 | |
ac50fbac CR |
4737 | /* Let's not let one really really long line blow up memory allocation */ |
4738 | if (shell_input_line && shell_input_line_size >= 32768) | |
4739 | { | |
4740 | free (shell_input_line); | |
4741 | shell_input_line = 0; | |
4742 | shell_input_line_size = 0; | |
4743 | } | |
4744 | ||
28ef6c31 | 4745 | restart_read: |
726f6388 | 4746 | |
28ef6c31 JA |
4747 | /* Allow immediate exit if interrupted during input. */ |
4748 | QUIT; | |
ccc6cda3 | 4749 | |
ac50fbac | 4750 | i = truncating = 0; |
28ef6c31 | 4751 | shell_input_line_terminator = 0; |
726f6388 | 4752 | |
712f80b0 | 4753 | /* If the shell is interactive, but not currently printing a prompt |
b80f6443 JA |
4754 | (interactive_shell && interactive == 0), we don't want to print |
4755 | notifies or cleanup the jobs -- we want to defer it until we do | |
4756 | print the next prompt. */ | |
4757 | if (interactive_shell == 0 || SHOULD_PROMPT()) | |
4758 | { | |
28ef6c31 JA |
4759 | #if defined (JOB_CONTROL) |
4760 | /* This can cause a problem when reading a command as the result | |
4761 | of a trap, when the trap is called from flush_child. This call | |
4762 | had better not cause jobs to disappear from the job table in | |
4763 | that case, or we will have big trouble. */ | |
b80f6443 | 4764 | notify_and_cleanup (); |
28ef6c31 | 4765 | #else /* !JOB_CONTROL */ |
b80f6443 | 4766 | cleanup_dead_jobs (); |
28ef6c31 | 4767 | #endif /* !JOB_CONTROL */ |
b80f6443 | 4768 | } |
ccc6cda3 | 4769 | |
28ef6c31 | 4770 | #if defined (READLINE) |
b80f6443 | 4771 | if (no_line_editing && SHOULD_PROMPT()) |
28ef6c31 | 4772 | #else |
b80f6443 | 4773 | if (SHOULD_PROMPT()) |
28ef6c31 JA |
4774 | #endif |
4775 | print_prompt (); | |
726f6388 | 4776 | |
28ef6c31 JA |
4777 | if (bash_input.type == st_stream) |
4778 | clearerr (stdin); | |
726f6388 | 4779 | |
28ef6c31 JA |
4780 | while (1) |
4781 | { | |
4782 | c = yy_getc (); | |
4783 | ||
4784 | /* Allow immediate exit if interrupted during input. */ | |
4785 | QUIT; | |
4786 | ||
4787 | if (c == '\0') | |
4788 | { | |
4789 | #if 0 | |
4790 | internal_warning ("shell_getc: ignored null byte in input"); | |
ccc6cda3 | 4791 | #endif |
d233b485 CR |
4792 | /* If we get EOS while parsing a string, treat it as EOF so we |
4793 | don't just keep looping. Happens very rarely */ | |
4794 | if (bash_input.type == st_string) | |
4795 | { | |
4796 | if (i == 0) | |
4797 | shell_input_line_terminator = EOF; | |
4798 | shell_input_line[i] = '\0'; | |
4799 | c = EOF; | |
4800 | break; | |
4801 | } | |
28ef6c31 JA |
4802 | continue; |
4803 | } | |
ccc6cda3 | 4804 | |
ac50fbac CR |
4805 | /* Theoretical overflow */ |
4806 | /* If we can't put 256 bytes more into the buffer, allocate | |
4807 | everything we can and fill it as full as we can. */ | |
4808 | /* XXX - we ignore rest of line using `truncating' flag */ | |
4809 | if (shell_input_line_size > (SIZE_MAX - 256)) | |
4810 | { | |
4811 | size_t n; | |
4812 | ||
4813 | n = SIZE_MAX - i; /* how much more can we put into the buffer? */ | |
4814 | if (n <= 2) /* we have to save 1 for the newline added below */ | |
4815 | { | |
4816 | if (truncating == 0) | |
a0c0a00f | 4817 | internal_warning(_("shell_getc: shell_input_line_size (%zu) exceeds SIZE_MAX (%lu): line truncated"), shell_input_line_size, (unsigned long)SIZE_MAX); |
ac50fbac CR |
4818 | shell_input_line[i] = '\0'; |
4819 | truncating = 1; | |
4820 | } | |
4821 | if (shell_input_line_size < SIZE_MAX) | |
4822 | { | |
4823 | shell_input_line_size = SIZE_MAX; | |
4824 | shell_input_line = xrealloc (shell_input_line, shell_input_line_size); | |
4825 | } | |
4826 | } | |
4827 | else | |
4828 | RESIZE_MALLOCED_BUFFER (shell_input_line, i, 2, shell_input_line_size, 256); | |
726f6388 | 4829 | |
28ef6c31 JA |
4830 | if (c == EOF) |
4831 | { | |
4832 | if (bash_input.type == st_stream) | |
4833 | clearerr (stdin); | |
726f6388 | 4834 | |
28ef6c31 JA |
4835 | if (i == 0) |
4836 | shell_input_line_terminator = EOF; | |
726f6388 | 4837 | |
28ef6c31 JA |
4838 | shell_input_line[i] = '\0'; |
4839 | break; | |
4840 | } | |
726f6388 | 4841 | |
ac50fbac CR |
4842 | if (truncating == 0 || c == '\n') |
4843 | shell_input_line[i++] = c; | |
726f6388 | 4844 | |
28ef6c31 JA |
4845 | if (c == '\n') |
4846 | { | |
4847 | shell_input_line[--i] = '\0'; | |
4848 | current_command_line_count++; | |
4849 | break; | |
4850 | } | |
a0c0a00f CR |
4851 | |
4852 | last_was_backslash = last_was_backslash == 0 && c == '\\'; | |
28ef6c31 | 4853 | } |
726f6388 | 4854 | |
28ef6c31 JA |
4855 | shell_input_line_index = 0; |
4856 | shell_input_line_len = i; /* == strlen (shell_input_line) */ | |
ccc6cda3 | 4857 | |
7117c2d2 JA |
4858 | set_line_mbstate (); |
4859 | ||
28ef6c31 JA |
4860 | #if defined (HISTORY) |
4861 | if (remember_on_history && shell_input_line && shell_input_line[0]) | |
4862 | { | |
4863 | char *expansions; | |
4864 | # if defined (BANG_HISTORY) | |
28ef6c31 JA |
4865 | /* If the current delimiter is a single quote, we should not be |
4866 | performing history expansion, even if we're on a different | |
4867 | line from the original single quote. */ | |
28ef6c31 | 4868 | if (current_delimiter (dstack) == '\'') |
d233b485 CR |
4869 | history_quoting_state = '\''; |
4870 | else if (current_delimiter (dstack) == '"') | |
4871 | history_quoting_state = '"'; | |
4872 | else | |
4873 | history_quoting_state = 0; | |
28ef6c31 | 4874 | # endif |
a0c0a00f CR |
4875 | /* Calling with a third argument of 1 allows remember_on_history to |
4876 | determine whether or not the line is saved to the history list */ | |
28ef6c31 JA |
4877 | expansions = pre_process_line (shell_input_line, 1, 1); |
4878 | # if defined (BANG_HISTORY) | |
d233b485 | 4879 | history_quoting_state = 0; |
28ef6c31 JA |
4880 | # endif |
4881 | if (expansions != shell_input_line) | |
4882 | { | |
4883 | free (shell_input_line); | |
4884 | shell_input_line = expansions; | |
4885 | shell_input_line_len = shell_input_line ? | |
4886 | strlen (shell_input_line) : 0; | |
495aee44 | 4887 | if (shell_input_line_len == 0) |
28ef6c31 | 4888 | current_command_line_count--; |
726f6388 | 4889 | |
28ef6c31 JA |
4890 | /* We have to force the xrealloc below because we don't know |
4891 | the true allocated size of shell_input_line anymore. */ | |
4892 | shell_input_line_size = shell_input_line_len; | |
7117c2d2 JA |
4893 | |
4894 | set_line_mbstate (); | |
28ef6c31 JA |
4895 | } |
4896 | } | |
4897 | /* Try to do something intelligent with blank lines encountered while | |
4898 | entering multi-line commands. XXX - this is grotesque */ | |
4899 | else if (remember_on_history && shell_input_line && | |
4900 | shell_input_line[0] == '\0' && | |
4901 | current_command_line_count > 1) | |
726f6388 | 4902 | { |
28ef6c31 JA |
4903 | if (current_delimiter (dstack)) |
4904 | /* We know shell_input_line[0] == 0 and we're reading some sort of | |
4905 | quoted string. This means we've got a line consisting of only | |
4906 | a newline in a quoted string. We want to make sure this line | |
4907 | gets added to the history. */ | |
4908 | maybe_add_history (shell_input_line); | |
4909 | else | |
4910 | { | |
4911 | char *hdcs; | |
495aee44 | 4912 | hdcs = history_delimiting_chars (shell_input_line); |
28ef6c31 JA |
4913 | if (hdcs && hdcs[0] == ';') |
4914 | maybe_add_history (shell_input_line); | |
4915 | } | |
726f6388 JA |
4916 | } |
4917 | ||
28ef6c31 | 4918 | #endif /* HISTORY */ |
726f6388 | 4919 | |
28ef6c31 | 4920 | if (shell_input_line) |
726f6388 | 4921 | { |
28ef6c31 | 4922 | /* Lines that signify the end of the shell's input should not be |
ac50fbac CR |
4923 | echoed. We should not echo lines while parsing command |
4924 | substitutions with recursive calls into the parsing engine; those | |
4925 | should only be echoed once when we read the word. That is the | |
4926 | reason for the test against shell_eof_token, which is set to a | |
4927 | right paren when parsing the contents of command substitutions. */ | |
28ef6c31 | 4928 | if (echo_input_at_read && (shell_input_line[0] || |
ac50fbac CR |
4929 | shell_input_line_terminator != EOF) && |
4930 | shell_eof_token == 0) | |
28ef6c31 JA |
4931 | fprintf (stderr, "%s\n", shell_input_line); |
4932 | } | |
4933 | else | |
4934 | { | |
4935 | shell_input_line_size = 0; | |
4936 | prompt_string_pointer = ¤t_prompt_string; | |
b80f6443 JA |
4937 | if (SHOULD_PROMPT ()) |
4938 | prompt_again (); | |
28ef6c31 | 4939 | goto restart_read; |
726f6388 JA |
4940 | } |
4941 | ||
28ef6c31 JA |
4942 | /* Add the newline to the end of this string, iff the string does |
4943 | not already end in an EOF character. */ | |
4944 | if (shell_input_line_terminator != EOF) | |
4945 | { | |
6ebbb24a | 4946 | if (shell_input_line_size < SIZE_MAX-3 && (shell_input_line_len+3 > shell_input_line_size)) |
f73dda09 | 4947 | shell_input_line = (char *)xrealloc (shell_input_line, |
28ef6c31 | 4948 | 1 + (shell_input_line_size += 2)); |
726f6388 | 4949 | |
a0c0a00f CR |
4950 | /* Don't add a newline to a string that ends with a backslash if we're |
4951 | going to be removing quoted newlines, since that will eat the | |
4952 | backslash. Add another backslash instead (will be removed by | |
4953 | word expansion). */ | |
4954 | if (bash_input.type == st_string && expanding_alias() == 0 && last_was_backslash && c == EOF && remove_quoted_newline) | |
4955 | shell_input_line[shell_input_line_len] = '\\'; | |
4956 | else | |
4957 | shell_input_line[shell_input_line_len] = '\n'; | |
28ef6c31 | 4958 | shell_input_line[shell_input_line_len + 1] = '\0'; |
7117c2d2 | 4959 | |
712f80b0 CR |
4960 | #if 0 |
4961 | set_line_mbstate (); /* XXX - this is wasteful */ | |
4962 | #else | |
4963 | # if defined (HANDLE_MULTIBYTE) | |
4964 | /* This is kind of an abstraction violation, but there's no need to | |
4965 | go through the entire shell_input_line again with a call to | |
4966 | set_line_mbstate(). */ | |
4967 | if (shell_input_line_len + 2 > shell_input_line_propsize) | |
4968 | { | |
4969 | shell_input_line_propsize = shell_input_line_len + 2; | |
4970 | shell_input_line_property = (char *)xrealloc (shell_input_line_property, | |
4971 | shell_input_line_propsize); | |
4972 | } | |
4973 | shell_input_line_property[shell_input_line_len] = 1; | |
4974 | # endif | |
4975 | #endif | |
28ef6c31 JA |
4976 | } |
4977 | } | |
726f6388 | 4978 | |
495aee44 | 4979 | next_alias_char: |
712f80b0 CR |
4980 | if (shell_input_line_index == 0) |
4981 | unquoted_backslash = 0; | |
4982 | ||
f73dda09 | 4983 | uc = shell_input_line[shell_input_line_index]; |
ccc6cda3 | 4984 | |
f73dda09 | 4985 | if (uc) |
712f80b0 CR |
4986 | { |
4987 | unquoted_backslash = unquoted_backslash == 0 && uc == '\\'; | |
4988 | shell_input_line_index++; | |
4989 | } | |
726f6388 | 4990 | |
28ef6c31 | 4991 | #if defined (ALIAS) || defined (DPAREN_ARITHMETIC) |
f73dda09 | 4992 | /* If UC is NULL, we have reached the end of the current input string. If |
28ef6c31 JA |
4993 | pushed_string_list is non-empty, it's time to pop to the previous string |
4994 | because we have fully consumed the result of the last alias expansion. | |
4995 | Do it transparently; just return the next character of the string popped | |
4996 | to. */ | |
ac50fbac CR |
4997 | /* If pushed_string_list != 0 but pushed_string_list->expander == 0 (not |
4998 | currently tested) and the flags value is not PSH_SOURCE, we are not | |
4999 | parsing an alias, we have just saved one (push_string, when called by | |
5000 | the parse_dparen code) In this case, just go on as well. The PSH_SOURCE | |
5001 | case is handled below. */ | |
d233b485 CR |
5002 | |
5003 | /* If we're at the end of an alias expansion add a space to make sure that | |
5004 | the alias remains marked as being in use while we expand its last word. | |
5005 | This makes sure that pop_string doesn't mark the alias as not in use | |
5006 | before the string resulting from the alias expansion is tokenized and | |
5007 | checked for alias expansion, preventing recursion. At this point, the | |
5008 | last character in shell_input_line is the last character of the alias | |
5009 | expansion. We test that last character to determine whether or not to | |
5010 | return the space that will delimit the token and postpone the pop_string. | |
5011 | This set of conditions duplicates what used to be in mk_alexpansion () | |
5012 | below, with the addition that we don't add a space if we're currently | |
5013 | reading a quoted string or in a shell comment. */ | |
5014 | #ifndef OLD_ALIAS_HACK | |
5015 | if (uc == 0 && pushed_string_list && pushed_string_list->flags != PSH_SOURCE && | |
5016 | pushed_string_list->flags != PSH_DPAREN && | |
5017 | (parser_state & PST_COMMENT) == 0 && | |
ddf3f643 | 5018 | (parser_state & PST_ENDALIAS) == 0 && /* only once */ |
d233b485 | 5019 | shell_input_line_index > 0 && |
ddf3f643 | 5020 | shellblank (shell_input_line[shell_input_line_index-1]) == 0 && |
d233b485 | 5021 | shell_input_line[shell_input_line_index-1] != '\n' && |
712f80b0 | 5022 | unquoted_backslash == 0 && |
d233b485 CR |
5023 | shellmeta (shell_input_line[shell_input_line_index-1]) == 0 && |
5024 | (current_delimiter (dstack) != '\'' && current_delimiter (dstack) != '"')) | |
5025 | { | |
ddf3f643 | 5026 | parser_state |= PST_ENDALIAS; |
d233b485 CR |
5027 | return ' '; /* END_ALIAS */ |
5028 | } | |
5029 | #endif | |
5030 | ||
0001803f | 5031 | pop_alias: |
d233b485 | 5032 | /* This case works for PSH_DPAREN as well */ |
ac50fbac | 5033 | if (uc == 0 && pushed_string_list && pushed_string_list->flags != PSH_SOURCE) |
726f6388 | 5034 | { |
ddf3f643 | 5035 | parser_state &= ~PST_ENDALIAS; |
b80f6443 JA |
5036 | pop_string (); |
5037 | uc = shell_input_line[shell_input_line_index]; | |
5038 | if (uc) | |
5039 | shell_input_line_index++; | |
726f6388 | 5040 | } |
28ef6c31 JA |
5041 | #endif /* ALIAS || DPAREN_ARITHMETIC */ |
5042 | ||
95732b49 JA |
5043 | if MBTEST(uc == '\\' && remove_quoted_newline && shell_input_line[shell_input_line_index] == '\n') |
5044 | { | |
5045 | if (SHOULD_PROMPT ()) | |
5046 | prompt_again (); | |
5047 | line_number++; | |
712f80b0 | 5048 | |
495aee44 CR |
5049 | /* What do we do here if we're expanding an alias whose definition |
5050 | includes an escaped newline? If that's the last character in the | |
5051 | alias expansion, we just pop the pushed string list (recall that | |
d233b485 CR |
5052 | we inhibit the appending of a space if newline is the last |
5053 | character). If it's not the last character, we need to consume the | |
5054 | quoted newline and move to the next character in the expansion. */ | |
509a4430 | 5055 | #if defined (ALIAS) |
0001803f CR |
5056 | if (expanding_alias () && shell_input_line[shell_input_line_index+1] == '\0') |
5057 | { | |
5058 | uc = 0; | |
5059 | goto pop_alias; | |
5060 | } | |
495aee44 CR |
5061 | else if (expanding_alias () && shell_input_line[shell_input_line_index+1] != '\0') |
5062 | { | |
5063 | shell_input_line_index++; /* skip newline */ | |
5064 | goto next_alias_char; /* and get next character */ | |
5065 | } | |
509a4430 CR |
5066 | else |
5067 | #endif | |
495aee44 | 5068 | goto restart_read; |
95732b49 JA |
5069 | } |
5070 | ||
495aee44 | 5071 | if (uc == 0 && shell_input_line_terminator == EOF) |
28ef6c31 JA |
5072 | return ((shell_input_line_index != 0) ? '\n' : EOF); |
5073 | ||
ac50fbac CR |
5074 | #if defined (ALIAS) || defined (DPAREN_ARITHMETIC) |
5075 | /* We already know that we are not parsing an alias expansion because of the | |
5076 | check for expanding_alias() above. This knows how parse_and_execute | |
5077 | handles switching to st_string input while an alias is being expanded, | |
5078 | hence the check for pushed_string_list without pushed_string_list->expander | |
5079 | and the check for PSH_SOURCE as pushed_string_list->flags. | |
5080 | parse_and_execute and parse_string both change the input type to st_string | |
5081 | and place the string to be parsed and executed into location.string, so | |
5082 | we should not stop reading that until the pointer is '\0'. | |
5083 | The check for shell_input_line_terminator may be superfluous. | |
5084 | ||
5085 | This solves the problem of `.' inside a multi-line alias with embedded | |
5086 | newlines executing things out of order. */ | |
5087 | if (uc == 0 && bash_input.type == st_string && *bash_input.location.string && | |
5088 | pushed_string_list && pushed_string_list->flags == PSH_SOURCE && | |
5089 | shell_input_line_terminator == 0) | |
5090 | { | |
5091 | shell_input_line_index = 0; | |
5092 | goto restart_read; | |
5093 | } | |
5094 | #endif | |
5095 | ||
f73dda09 | 5096 | return (uc); |
726f6388 JA |
5097 | } |
5098 | ||
7117c2d2 JA |
5099 | /* Put C back into the input for the shell. This might need changes for |
5100 | HANDLE_MULTIBYTE around EOLs. Since we (currently) never push back a | |
5101 | character different than we read, shell_input_line_property doesn't need | |
5102 | to change when manipulating shell_input_line. The define for | |
5103 | last_shell_getc_is_singlebyte should take care of it, though. */ | |
28ef6c31 JA |
5104 | static void |
5105 | shell_ungetc (c) | |
ccc6cda3 | 5106 | int c; |
726f6388 | 5107 | { |
28ef6c31 JA |
5108 | if (shell_input_line && shell_input_line_index) |
5109 | shell_input_line[--shell_input_line_index] = c; | |
5110 | else | |
5111 | eol_ungetc_lookahead = c; | |
726f6388 JA |
5112 | } |
5113 | ||
ca6a2ba4 CR |
5114 | char * |
5115 | parser_remaining_input () | |
5116 | { | |
5117 | if (shell_input_line == 0) | |
5118 | return 0; | |
d233b485 | 5119 | if ((int)shell_input_line_index < 0 || shell_input_line_index >= shell_input_line_len) |
a0c0a00f | 5120 | return ""; /* XXX */ |
ca6a2ba4 CR |
5121 | return (shell_input_line + shell_input_line_index); |
5122 | } | |
5123 | ||
f73dda09 JA |
5124 | #ifdef INCLUDE_UNUSED |
5125 | /* Back the input pointer up by one, effectively `ungetting' a character. */ | |
28ef6c31 JA |
5126 | static void |
5127 | shell_ungetchar () | |
726f6388 | 5128 | { |
28ef6c31 JA |
5129 | if (shell_input_line && shell_input_line_index) |
5130 | shell_input_line_index--; | |
726f6388 | 5131 | } |
f73dda09 | 5132 | #endif |
726f6388 | 5133 | |
28ef6c31 JA |
5134 | /* Discard input until CHARACTER is seen, then push that character back |
5135 | onto the input stream. */ | |
5136 | static void | |
5137 | discard_until (character) | |
5138 | int character; | |
726f6388 | 5139 | { |
28ef6c31 | 5140 | int c; |
726f6388 | 5141 | |
28ef6c31 JA |
5142 | while ((c = shell_getc (0)) != EOF && c != character) |
5143 | ; | |
726f6388 | 5144 | |
28ef6c31 JA |
5145 | if (c != EOF) |
5146 | shell_ungetc (c); | |
5147 | } | |
726f6388 | 5148 | |
28ef6c31 | 5149 | void |
0628567a JA |
5150 | execute_variable_command (command, vname) |
5151 | char *command, *vname; | |
28ef6c31 | 5152 | { |
28ef6c31 | 5153 | char *last_lastarg; |
b80f6443 | 5154 | sh_parser_state_t ps; |
726f6388 | 5155 | |
b80f6443 | 5156 | save_parser_state (&ps); |
28ef6c31 JA |
5157 | last_lastarg = get_string_value ("_"); |
5158 | if (last_lastarg) | |
5159 | last_lastarg = savestring (last_lastarg); | |
726f6388 | 5160 | |
0628567a | 5161 | parse_and_execute (savestring (command), vname, SEVAL_NONINT|SEVAL_NOHIST); |
726f6388 | 5162 | |
b80f6443 | 5163 | restore_parser_state (&ps); |
95732b49 | 5164 | bind_variable ("_", last_lastarg, 0); |
28ef6c31 JA |
5165 | FREE (last_lastarg); |
5166 | ||
5167 | if (token_to_read == '\n') /* reset_parser was called */ | |
5168 | token_to_read = 0; | |
726f6388 JA |
5169 | } |
5170 | ||
a0c0a00f CR |
5171 | void |
5172 | push_token (x) | |
5173 | int x; | |
5174 | { | |
5175 | two_tokens_ago = token_before_that; | |
5176 | token_before_that = last_read_token; | |
5177 | last_read_token = current_token; | |
5178 | ||
5179 | current_token = x; | |
5180 | } | |
5181 | ||
28ef6c31 JA |
5182 | /* Place to remember the token. We try to keep the buffer |
5183 | at a reasonable size, but it can grow. */ | |
5184 | static char *token = (char *)NULL; | |
726f6388 | 5185 | |
28ef6c31 JA |
5186 | /* Current size of the token buffer. */ |
5187 | static int token_buffer_size; | |
5188 | ||
5189 | /* Command to read_token () explaining what we want it to do. */ | |
5190 | #define READ 0 | |
5191 | #define RESET 1 | |
5192 | #define prompt_is_ps1 \ | |
5193 | (!prompt_string_pointer || prompt_string_pointer == &ps1_prompt) | |
bb70624e | 5194 | |
28ef6c31 JA |
5195 | /* Function for yyparse to call. yylex keeps track of |
5196 | the last two tokens read, and calls read_token. */ | |
726f6388 | 5197 | static int |
28ef6c31 | 5198 | yylex () |
726f6388 | 5199 | { |
28ef6c31 JA |
5200 | if (interactive && (current_token == 0 || current_token == '\n')) |
5201 | { | |
5202 | /* Before we print a prompt, we might have to check mailboxes. | |
5203 | We do this only if it is time to do so. Notice that only here | |
5204 | is the mail alarm reset; nothing takes place in check_mail () | |
5205 | except the checking of mail. Please don't change this. */ | |
509a4430 | 5206 | if (prompt_is_ps1 && parse_and_execute_level == 0 && time_to_check_mail ()) |
28ef6c31 JA |
5207 | { |
5208 | check_mail (); | |
5209 | reset_mail_timer (); | |
5210 | } | |
726f6388 | 5211 | |
28ef6c31 JA |
5212 | /* Avoid printing a prompt if we're not going to read anything, e.g. |
5213 | after resetting the parser with read_token (RESET). */ | |
b80f6443 | 5214 | if (token_to_read == 0 && SHOULD_PROMPT ()) |
28ef6c31 JA |
5215 | prompt_again (); |
5216 | } | |
bb70624e | 5217 | |
28ef6c31 JA |
5218 | two_tokens_ago = token_before_that; |
5219 | token_before_that = last_read_token; | |
5220 | last_read_token = current_token; | |
5221 | current_token = read_token (READ); | |
3185942a JA |
5222 | |
5223 | if ((parser_state & PST_EOFTOKEN) && current_token == shell_eof_token) | |
5224 | { | |
5225 | current_token = yacc_EOF; | |
5226 | if (bash_input.type == st_string) | |
5227 | rewind_input_string (); | |
5228 | } | |
d233b485 | 5229 | parser_state &= ~PST_EOFTOKEN; /* ??? */ |
3185942a | 5230 | |
28ef6c31 | 5231 | return (current_token); |
726f6388 JA |
5232 | } |
5233 | ||
28ef6c31 JA |
5234 | /* When non-zero, we have read the required tokens |
5235 | which allow ESAC to be the next one read. */ | |
5236 | static int esacs_needed_count; | |
726f6388 | 5237 | |
d233b485 CR |
5238 | /* When non-zero, we can read IN as an acceptable token, regardless of how |
5239 | many newlines we read. */ | |
5240 | static int expecting_in_token; | |
5241 | ||
90a39f32 CR |
5242 | static void |
5243 | push_heredoc (r) | |
5244 | REDIRECT *r; | |
5245 | { | |
5246 | if (need_here_doc >= HEREDOC_MAX) | |
5247 | { | |
5248 | last_command_exit_value = EX_BADUSAGE; | |
5249 | need_here_doc = 0; | |
5250 | report_syntax_error (_("maximum here-document count exceeded")); | |
5251 | reset_parser (); | |
5252 | exit_shell (last_command_exit_value); | |
5253 | } | |
5254 | redir_stack[need_here_doc++] = r; | |
5255 | } | |
5256 | ||
726f6388 | 5257 | void |
28ef6c31 | 5258 | gather_here_documents () |
726f6388 | 5259 | { |
3185942a JA |
5260 | int r; |
5261 | ||
5262 | r = 0; | |
a0c0a00f | 5263 | here_doc_first_line = 1; |
daefb2c5 | 5264 | while (need_here_doc > 0) |
28ef6c31 | 5265 | { |
3185942a JA |
5266 | parser_state |= PST_HEREDOC; |
5267 | make_here_document (redir_stack[r++], line_number); | |
5268 | parser_state &= ~PST_HEREDOC; | |
28ef6c31 | 5269 | need_here_doc--; |
a0c0a00f | 5270 | redir_stack[r - 1] = 0; /* XXX */ |
28ef6c31 | 5271 | } |
a0c0a00f | 5272 | here_doc_first_line = 0; /* just in case */ |
726f6388 JA |
5273 | } |
5274 | ||
28ef6c31 JA |
5275 | /* When non-zero, an open-brace used to create a group is awaiting a close |
5276 | brace partner. */ | |
5277 | static int open_brace_count; | |
726f6388 | 5278 | |
a0c0a00f CR |
5279 | /* In the following three macros, `token' is always last_read_token */ |
5280 | ||
5281 | /* Are we in the middle of parsing a redirection where we are about to read | |
5282 | a word? This is used to make sure alias expansion doesn't happen in the | |
5283 | middle of a redirection, even though we're parsing a simple command. */ | |
5284 | #define parsing_redirection(token) \ | |
5285 | (token == '<' || token == '>' || \ | |
5286 | token == GREATER_GREATER || token == GREATER_BAR || \ | |
5287 | token == LESS_GREATER || token == LESS_LESS_MINUS || \ | |
5288 | token == LESS_LESS || token == LESS_LESS_LESS || \ | |
5289 | token == LESS_AND || token == GREATER_AND || token == AND_GREATER) | |
5290 | ||
5291 | /* Is `token' one that will allow a WORD to be read in a command position? | |
5292 | We can read a simple command name on which we should attempt alias expansion | |
5293 | or we can read an assignment statement. */ | |
28ef6c31 | 5294 | #define command_token_position(token) \ |
a0c0a00f CR |
5295 | (((token) == ASSIGNMENT_WORD) || \ |
5296 | ((parser_state&PST_REDIRLIST) && parsing_redirection(token) == 0) || \ | |
3185942a | 5297 | ((token) != SEMI_SEMI && (token) != SEMI_AND && (token) != SEMI_SEMI_AND && reserved_word_acceptable(token))) |
cce855bc | 5298 | |
a0c0a00f | 5299 | /* Are we in a position where we can read an assignment statement? */ |
b80f6443 JA |
5300 | #define assignment_acceptable(token) \ |
5301 | (command_token_position(token) && ((parser_state & PST_CASEPAT) == 0)) | |
726f6388 | 5302 | |
28ef6c31 JA |
5303 | /* Check to see if TOKEN is a reserved word and return the token |
5304 | value if it is. */ | |
5305 | #define CHECK_FOR_RESERVED_WORD(tok) \ | |
5306 | do { \ | |
5307 | if (!dollar_present && !quoted && \ | |
5308 | reserved_word_acceptable (last_read_token)) \ | |
5309 | { \ | |
5310 | int i; \ | |
5311 | for (i = 0; word_token_alist[i].word != (char *)NULL; i++) \ | |
5312 | if (STREQ (tok, word_token_alist[i].word)) \ | |
5313 | { \ | |
5314 | if ((parser_state & PST_CASEPAT) && (word_token_alist[i].token != ESAC)) \ | |
5315 | break; \ | |
b80f6443 | 5316 | if (word_token_alist[i].token == TIME && time_command_acceptable () == 0) \ |
28ef6c31 | 5317 | break; \ |
a0c0a00f CR |
5318 | if ((parser_state & PST_CASEPAT) && last_read_token == '|' && word_token_alist[i].token == ESAC) \ |
5319 | break; /* Posix grammar rule 4 */ \ | |
28ef6c31 JA |
5320 | if (word_token_alist[i].token == ESAC) \ |
5321 | parser_state &= ~(PST_CASEPAT|PST_CASESTMT); \ | |
5322 | else if (word_token_alist[i].token == CASE) \ | |
5323 | parser_state |= PST_CASESTMT; \ | |
5324 | else if (word_token_alist[i].token == COND_END) \ | |
5325 | parser_state &= ~(PST_CONDCMD|PST_CONDEXPR); \ | |
5326 | else if (word_token_alist[i].token == COND_START) \ | |
5327 | parser_state |= PST_CONDCMD; \ | |
5328 | else if (word_token_alist[i].token == '{') \ | |
5329 | open_brace_count++; \ | |
5330 | else if (word_token_alist[i].token == '}' && open_brace_count) \ | |
5331 | open_brace_count--; \ | |
5332 | return (word_token_alist[i].token); \ | |
5333 | } \ | |
5334 | } \ | |
5335 | } while (0) | |
726f6388 | 5336 | |
28ef6c31 | 5337 | #if defined (ALIAS) |
726f6388 | 5338 | |
28ef6c31 JA |
5339 | /* OK, we have a token. Let's try to alias expand it, if (and only if) |
5340 | it's eligible. | |
726f6388 | 5341 | |
7117c2d2 | 5342 | It is eligible for expansion if EXPAND_ALIASES is set, and |
28ef6c31 JA |
5343 | the token is unquoted and the last token read was a command |
5344 | separator (or expand_next_token is set), and we are currently | |
5345 | processing an alias (pushed_string_list is non-empty) and this | |
5346 | token is not the same as the current or any previously | |
5347 | processed alias. | |
726f6388 | 5348 | |
28ef6c31 JA |
5349 | Special cases that disqualify: |
5350 | In a pattern list in a case statement (parser_state & PST_CASEPAT). */ | |
b80f6443 JA |
5351 | |
5352 | static char * | |
5353 | mk_alexpansion (s) | |
5354 | char *s; | |
5355 | { | |
5356 | int l; | |
5357 | char *r; | |
5358 | ||
5359 | l = strlen (s); | |
5360 | r = xmalloc (l + 2); | |
5361 | strcpy (r, s); | |
d233b485 | 5362 | #ifdef OLD_ALIAS_HACK |
495aee44 CR |
5363 | /* If the last character in the alias is a newline, don't add a trailing |
5364 | space to the expansion. Works with shell_getc above. */ | |
d233b485 CR |
5365 | /* Need to do something about the case where the alias expansion contains |
5366 | an unmatched quoted string, since appending this space affects the | |
5367 | subsequent output. */ | |
5368 | if (l > 0 && r[l - 1] != ' ' && r[l - 1] != '\n' && shellmeta(r[l - 1]) == 0) | |
b80f6443 | 5369 | r[l++] = ' '; |
d233b485 | 5370 | #endif |
b80f6443 JA |
5371 | r[l] = '\0'; |
5372 | return r; | |
5373 | } | |
5374 | ||
28ef6c31 | 5375 | static int |
f73dda09 JA |
5376 | alias_expand_token (tokstr) |
5377 | char *tokstr; | |
726f6388 | 5378 | { |
28ef6c31 JA |
5379 | char *expanded; |
5380 | alias_t *ap; | |
5381 | ||
5382 | if (((parser_state & PST_ALEXPNEXT) || command_token_position (last_read_token)) && | |
5383 | (parser_state & PST_CASEPAT) == 0) | |
726f6388 | 5384 | { |
f73dda09 | 5385 | ap = find_alias (tokstr); |
726f6388 | 5386 | |
28ef6c31 JA |
5387 | /* Currently expanding this token. */ |
5388 | if (ap && (ap->flags & AL_BEINGEXPANDED)) | |
5389 | return (NO_EXPANSION); | |
726f6388 | 5390 | |
d233b485 | 5391 | #ifdef OLD_ALIAS_HACK |
b80f6443 | 5392 | /* mk_alexpansion puts an extra space on the end of the alias expansion, |
d233b485 CR |
5393 | so the lookahead by the parser works right (the alias needs to remain |
5394 | `in use' while parsing its last word to avoid alias recursion for | |
5395 | something like "alias echo=echo"). If this gets changed, make sure | |
5396 | the code in shell_getc that deals with reaching the end of an | |
5397 | expanded alias is changed with it. */ | |
5398 | #endif | |
b80f6443 JA |
5399 | expanded = ap ? mk_alexpansion (ap->value) : (char *)NULL; |
5400 | ||
28ef6c31 JA |
5401 | if (expanded) |
5402 | { | |
5403 | push_string (expanded, ap->flags & AL_EXPANDNEXT, ap); | |
5404 | return (RE_READ_TOKEN); | |
5405 | } | |
5406 | else | |
5407 | /* This is an eligible token that does not have an expansion. */ | |
5408 | return (NO_EXPANSION); | |
5409 | } | |
5410 | return (NO_EXPANSION); | |
5411 | } | |
5412 | #endif /* ALIAS */ | |
726f6388 | 5413 | |
28ef6c31 JA |
5414 | static int |
5415 | time_command_acceptable () | |
726f6388 | 5416 | { |
28ef6c31 | 5417 | #if defined (COMMAND_TIMING) |
495aee44 CR |
5418 | int i; |
5419 | ||
5420 | if (posixly_correct && shell_compatibility_level > 41) | |
5421 | { | |
5422 | /* Quick check of the rest of the line to find the next token. If it | |
5423 | begins with a `-', Posix says to not return `time' as the token. | |
5424 | This was interp 267. */ | |
5425 | i = shell_input_line_index; | |
5426 | while (i < shell_input_line_len && (shell_input_line[i] == ' ' || shell_input_line[i] == '\t')) | |
5427 | i++; | |
5428 | if (shell_input_line[i] == '-') | |
5429 | return 0; | |
5430 | } | |
5431 | ||
28ef6c31 JA |
5432 | switch (last_read_token) |
5433 | { | |
5434 | case 0: | |
5435 | case ';': | |
5436 | case '\n': | |
a0c0a00f CR |
5437 | if (token_before_that == '|') |
5438 | return (0); | |
5439 | /* FALLTHROUGH */ | |
28ef6c31 JA |
5440 | case AND_AND: |
5441 | case OR_OR: | |
5442 | case '&': | |
af61c549 | 5443 | case WHILE: |
28ef6c31 | 5444 | case DO: |
af61c549 CR |
5445 | case UNTIL: |
5446 | case IF: | |
28ef6c31 | 5447 | case THEN: |
af61c549 | 5448 | case ELIF: |
28ef6c31 JA |
5449 | case ELSE: |
5450 | case '{': /* } */ | |
af61c549 CR |
5451 | case '(': /* )( */ |
5452 | case ')': /* only valid in case statement */ | |
495aee44 CR |
5453 | case BANG: /* ! time pipeline */ |
5454 | case TIME: /* time time pipeline */ | |
5455 | case TIMEOPT: /* time -p time pipeline */ | |
5456 | case TIMEIGN: /* time -p -- ... */ | |
726f6388 | 5457 | return 1; |
28ef6c31 JA |
5458 | default: |
5459 | return 0; | |
5460 | } | |
5461 | #else | |
726f6388 | 5462 | return 0; |
28ef6c31 | 5463 | #endif /* COMMAND_TIMING */ |
726f6388 JA |
5464 | } |
5465 | ||
28ef6c31 JA |
5466 | /* Handle special cases of token recognition: |
5467 | IN is recognized if the last token was WORD and the token | |
5468 | before that was FOR or CASE or SELECT. | |
726f6388 | 5469 | |
28ef6c31 JA |
5470 | DO is recognized if the last token was WORD and the token |
5471 | before that was FOR or SELECT. | |
cce855bc | 5472 | |
28ef6c31 JA |
5473 | ESAC is recognized if the last token caused `esacs_needed_count' |
5474 | to be set | |
ccc6cda3 | 5475 | |
28ef6c31 JA |
5476 | `{' is recognized if the last token as WORD and the token |
5477 | before that was FUNCTION, or if we just parsed an arithmetic | |
5478 | `for' command. | |
ccc6cda3 | 5479 | |
28ef6c31 | 5480 | `}' is recognized if there is an unclosed `{' present. |
726f6388 | 5481 | |
28ef6c31 | 5482 | `-p' is returned as TIMEOPT if the last read token was TIME. |
712f80b0 | 5483 | `--' is returned as TIMEIGN if the last read token was TIME or TIMEOPT. |
726f6388 | 5484 | |
28ef6c31 JA |
5485 | ']]' is returned as COND_END if the parser is currently parsing |
5486 | a conditional expression ((parser_state & PST_CONDEXPR) != 0) | |
726f6388 | 5487 | |
28ef6c31 JA |
5488 | `time' is returned as TIME if and only if it is immediately |
5489 | preceded by one of `;', `\n', `||', `&&', or `&'. | |
5490 | */ | |
726f6388 | 5491 | |
28ef6c31 | 5492 | static int |
f73dda09 JA |
5493 | special_case_tokens (tokstr) |
5494 | char *tokstr; | |
726f6388 | 5495 | { |
d233b485 | 5496 | /* Posix grammar rule 6 */ |
28ef6c31 JA |
5497 | if ((last_read_token == WORD) && |
5498 | #if defined (SELECT_COMMAND) | |
5499 | ((token_before_that == FOR) || (token_before_that == CASE) || (token_before_that == SELECT)) && | |
5500 | #else | |
5501 | ((token_before_that == FOR) || (token_before_that == CASE)) && | |
cce855bc | 5502 | #endif |
f73dda09 | 5503 | (tokstr[0] == 'i' && tokstr[1] == 'n' && tokstr[2] == 0)) |
28ef6c31 JA |
5504 | { |
5505 | if (token_before_that == CASE) | |
5506 | { | |
5507 | parser_state |= PST_CASEPAT; | |
5508 | esacs_needed_count++; | |
5509 | } | |
d233b485 CR |
5510 | if (expecting_in_token) |
5511 | expecting_in_token--; | |
28ef6c31 JA |
5512 | return (IN); |
5513 | } | |
726f6388 | 5514 | |
d233b485 CR |
5515 | /* XXX - leaving above code intact for now, but it should eventually be |
5516 | removed in favor of this clause. */ | |
5517 | /* Posix grammar rule 6 */ | |
5518 | if (expecting_in_token && (last_read_token == WORD || last_read_token == '\n') && | |
5519 | (tokstr[0] == 'i' && tokstr[1] == 'n' && tokstr[2] == 0)) | |
5520 | { | |
5521 | if (parser_state & PST_CASESTMT) | |
5522 | { | |
5523 | parser_state |= PST_CASEPAT; | |
5524 | esacs_needed_count++; | |
5525 | } | |
5526 | expecting_in_token--; | |
5527 | return (IN); | |
5528 | } | |
5529 | /* Posix grammar rule 6, third word in FOR: for i; do command-list; done */ | |
5530 | else if (expecting_in_token && (last_read_token == '\n' || last_read_token == ';') && | |
5531 | (tokstr[0] == 'd' && tokstr[1] == 'o' && tokstr[2] == '\0')) | |
5532 | { | |
5533 | expecting_in_token--; | |
5534 | return (DO); | |
5535 | } | |
5536 | ||
5537 | /* for i do; command-list; done */ | |
28ef6c31 JA |
5538 | if (last_read_token == WORD && |
5539 | #if defined (SELECT_COMMAND) | |
5540 | (token_before_that == FOR || token_before_that == SELECT) && | |
5541 | #else | |
5542 | (token_before_that == FOR) && | |
cce855bc | 5543 | #endif |
f73dda09 | 5544 | (tokstr[0] == 'd' && tokstr[1] == 'o' && tokstr[2] == '\0')) |
d233b485 CR |
5545 | { |
5546 | if (expecting_in_token) | |
5547 | expecting_in_token--; | |
5548 | return (DO); | |
5549 | } | |
726f6388 | 5550 | |
28ef6c31 JA |
5551 | /* Ditto for ESAC in the CASE case. |
5552 | Specifically, this handles "case word in esac", which is a legal | |
5553 | construct, certainly because someone will pass an empty arg to the | |
5554 | case construct, and we don't want it to barf. Of course, we should | |
5555 | insist that the case construct has at least one pattern in it, but | |
5556 | the designers disagree. */ | |
5557 | if (esacs_needed_count) | |
5558 | { | |
d233b485 | 5559 | if (last_read_token == IN && STREQ (tokstr, "esac")) |
28ef6c31 | 5560 | { |
d233b485 | 5561 | esacs_needed_count--; |
28ef6c31 JA |
5562 | parser_state &= ~PST_CASEPAT; |
5563 | return (ESAC); | |
5564 | } | |
5565 | } | |
726f6388 | 5566 | |
28ef6c31 JA |
5567 | /* The start of a shell function definition. */ |
5568 | if (parser_state & PST_ALLOWOPNBRC) | |
5569 | { | |
5570 | parser_state &= ~PST_ALLOWOPNBRC; | |
f73dda09 | 5571 | if (tokstr[0] == '{' && tokstr[1] == '\0') /* } */ |
28ef6c31 JA |
5572 | { |
5573 | open_brace_count++; | |
5574 | function_bstart = line_number; | |
5575 | return ('{'); /* } */ | |
5576 | } | |
5577 | } | |
726f6388 | 5578 | |
28ef6c31 JA |
5579 | /* We allow a `do' after a for ((...)) without an intervening |
5580 | list_terminator */ | |
f73dda09 | 5581 | if (last_read_token == ARITH_FOR_EXPRS && tokstr[0] == 'd' && tokstr[1] == 'o' && !tokstr[2]) |
28ef6c31 | 5582 | return (DO); |
f73dda09 | 5583 | if (last_read_token == ARITH_FOR_EXPRS && tokstr[0] == '{' && tokstr[1] == '\0') /* } */ |
28ef6c31 JA |
5584 | { |
5585 | open_brace_count++; | |
5586 | return ('{'); /* } */ | |
5587 | } | |
726f6388 | 5588 | |
f73dda09 | 5589 | if (open_brace_count && reserved_word_acceptable (last_read_token) && tokstr[0] == '}' && !tokstr[1]) |
28ef6c31 JA |
5590 | { |
5591 | open_brace_count--; /* { */ | |
5592 | return ('}'); | |
5593 | } | |
ccc6cda3 | 5594 | |
28ef6c31 JA |
5595 | #if defined (COMMAND_TIMING) |
5596 | /* Handle -p after `time'. */ | |
f73dda09 | 5597 | if (last_read_token == TIME && tokstr[0] == '-' && tokstr[1] == 'p' && !tokstr[2]) |
28ef6c31 | 5598 | return (TIMEOPT); |
712f80b0 CR |
5599 | /* Handle -- after `time'. */ |
5600 | if (last_read_token == TIME && tokstr[0] == '-' && tokstr[1] == '-' && !tokstr[2]) | |
5601 | return (TIMEIGN); | |
495aee44 CR |
5602 | /* Handle -- after `time -p'. */ |
5603 | if (last_read_token == TIMEOPT && tokstr[0] == '-' && tokstr[1] == '-' && !tokstr[2]) | |
5604 | return (TIMEIGN); | |
b80f6443 | 5605 | #endif |
28ef6c31 JA |
5606 | |
5607 | #if defined (COND_COMMAND) /* [[ */ | |
f73dda09 | 5608 | if ((parser_state & PST_CONDEXPR) && tokstr[0] == ']' && tokstr[1] == ']' && tokstr[2] == '\0') |
28ef6c31 | 5609 | return (COND_END); |
cce855bc | 5610 | #endif |
ccc6cda3 | 5611 | |
28ef6c31 | 5612 | return (-1); |
726f6388 JA |
5613 | } |
5614 | ||
28ef6c31 JA |
5615 | /* Called from shell.c when Control-C is typed at top level. Or |
5616 | by the error rule at top level. */ | |
5617 | void | |
5618 | reset_parser () | |
726f6388 | 5619 | { |
28ef6c31 JA |
5620 | dstack.delimiter_depth = 0; /* No delimiters found so far. */ |
5621 | open_brace_count = 0; | |
726f6388 | 5622 | |
0001803f CR |
5623 | #if defined (EXTENDED_GLOB) |
5624 | /* Reset to global value of extended glob */ | |
5625 | if (parser_state & PST_EXTPAT) | |
5626 | extended_glob = global_extglob; | |
5627 | #endif | |
5628 | ||
28ef6c31 | 5629 | parser_state = 0; |
a0c0a00f | 5630 | here_doc_first_line = 0; |
726f6388 | 5631 | |
28ef6c31 JA |
5632 | #if defined (ALIAS) || defined (DPAREN_ARITHMETIC) |
5633 | if (pushed_string_list) | |
5634 | free_string_list (); | |
cce855bc | 5635 | #endif /* ALIAS || DPAREN_ARITHMETIC */ |
ccc6cda3 | 5636 | |
a0c0a00f | 5637 | /* This is where we resynchronize to the next newline on error/reset */ |
28ef6c31 | 5638 | if (shell_input_line) |
726f6388 | 5639 | { |
28ef6c31 JA |
5640 | free (shell_input_line); |
5641 | shell_input_line = (char *)NULL; | |
5642 | shell_input_line_size = shell_input_line_index = 0; | |
5643 | } | |
726f6388 | 5644 | |
28ef6c31 JA |
5645 | FREE (word_desc_to_read); |
5646 | word_desc_to_read = (WORD_DESC *)NULL; | |
726f6388 | 5647 | |
836a17be CR |
5648 | eol_ungetc_lookahead = 0; |
5649 | ||
0001803f | 5650 | current_token = '\n'; /* XXX */ |
28ef6c31 JA |
5651 | last_read_token = '\n'; |
5652 | token_to_read = '\n'; | |
5653 | } | |
726f6388 | 5654 | |
d233b485 CR |
5655 | void |
5656 | reset_readahead_token () | |
5657 | { | |
5658 | if (token_to_read == '\n') | |
5659 | token_to_read = 0; | |
5660 | } | |
5661 | ||
28ef6c31 JA |
5662 | /* Read the next token. Command can be READ (normal operation) or |
5663 | RESET (to normalize state). */ | |
5664 | static int | |
5665 | read_token (command) | |
5666 | int command; | |
5667 | { | |
5668 | int character; /* Current character. */ | |
5669 | int peek_char; /* Temporary look-ahead character. */ | |
5670 | int result; /* The thing to return. */ | |
726f6388 | 5671 | |
28ef6c31 JA |
5672 | if (command == RESET) |
5673 | { | |
5674 | reset_parser (); | |
5675 | return ('\n'); | |
5676 | } | |
726f6388 | 5677 | |
28ef6c31 JA |
5678 | if (token_to_read) |
5679 | { | |
5680 | result = token_to_read; | |
5681 | if (token_to_read == WORD || token_to_read == ASSIGNMENT_WORD) | |
726f6388 | 5682 | { |
28ef6c31 JA |
5683 | yylval.word = word_desc_to_read; |
5684 | word_desc_to_read = (WORD_DESC *)NULL; | |
726f6388 | 5685 | } |
28ef6c31 JA |
5686 | token_to_read = 0; |
5687 | return (result); | |
5688 | } | |
726f6388 | 5689 | |
28ef6c31 JA |
5690 | #if defined (COND_COMMAND) |
5691 | if ((parser_state & (PST_CONDCMD|PST_CONDEXPR)) == PST_CONDCMD) | |
5692 | { | |
5693 | cond_lineno = line_number; | |
5694 | parser_state |= PST_CONDEXPR; | |
5695 | yylval.command = parse_cond_command (); | |
5696 | if (cond_token != COND_END) | |
726f6388 | 5697 | { |
7117c2d2 | 5698 | cond_error (); |
28ef6c31 | 5699 | return (-1); |
726f6388 | 5700 | } |
28ef6c31 JA |
5701 | token_to_read = COND_END; |
5702 | parser_state &= ~(PST_CONDEXPR|PST_CONDCMD); | |
5703 | return (COND_CMD); | |
726f6388 | 5704 | } |
cce855bc | 5705 | #endif |
726f6388 | 5706 | |
28ef6c31 JA |
5707 | #if defined (ALIAS) |
5708 | /* This is a place to jump back to once we have successfully expanded a | |
5709 | token with an alias and pushed the string with push_string () */ | |
5710 | re_read_token: | |
5711 | #endif /* ALIAS */ | |
ccc6cda3 | 5712 | |
28ef6c31 | 5713 | /* Read a single word from input. Start by skipping blanks. */ |
0628567a | 5714 | while ((character = shell_getc (1)) != EOF && shellblank (character)) |
28ef6c31 | 5715 | ; |
ccc6cda3 | 5716 | |
28ef6c31 JA |
5717 | if (character == EOF) |
5718 | { | |
5719 | EOF_Reached = 1; | |
5720 | return (yacc_EOF); | |
5721 | } | |
ccc6cda3 | 5722 | |
d233b485 CR |
5723 | /* If we hit the end of the string and we're not expanding an alias (e.g., |
5724 | we are eval'ing a string that is an incomplete command), return EOF */ | |
5725 | if (character == '\0' && bash_input.type == st_string && expanding_alias() == 0) | |
5726 | { | |
5727 | #if defined (DEBUG) | |
5728 | itrace("shell_getc: bash_input.location.string = `%s'", bash_input.location.string); | |
5729 | #endif | |
5730 | EOF_Reached = 1; | |
5731 | return (yacc_EOF); | |
5732 | } | |
5733 | ||
7117c2d2 | 5734 | if MBTEST(character == '#' && (!interactive || interactive_comments)) |
28ef6c31 JA |
5735 | { |
5736 | /* A comment. Discard until EOL or EOF, and then return a newline. */ | |
d233b485 | 5737 | parser_state |= PST_COMMENT; |
28ef6c31 JA |
5738 | discard_until ('\n'); |
5739 | shell_getc (0); | |
d233b485 | 5740 | parser_state &= ~PST_COMMENT; |
28ef6c31 JA |
5741 | character = '\n'; /* this will take the next if statement and return. */ |
5742 | } | |
ccc6cda3 | 5743 | |
28ef6c31 JA |
5744 | if (character == '\n') |
5745 | { | |
5746 | /* If we're about to return an unquoted newline, we can go and collect | |
5747 | the text of any pending here document. */ | |
5748 | if (need_here_doc) | |
5749 | gather_here_documents (); | |
ccc6cda3 | 5750 | |
28ef6c31 JA |
5751 | #if defined (ALIAS) |
5752 | parser_state &= ~PST_ALEXPNEXT; | |
5753 | #endif /* ALIAS */ | |
ccc6cda3 | 5754 | |
95732b49 JA |
5755 | parser_state &= ~PST_ASSIGNOK; |
5756 | ||
28ef6c31 JA |
5757 | return (character); |
5758 | } | |
726f6388 | 5759 | |
3185942a JA |
5760 | if (parser_state & PST_REGEXP) |
5761 | goto tokword; | |
5762 | ||
28ef6c31 | 5763 | /* Shell meta-characters. */ |
7117c2d2 | 5764 | if MBTEST(shellmeta (character) && ((parser_state & PST_DBLPAREN) == 0)) |
28ef6c31 JA |
5765 | { |
5766 | #if defined (ALIAS) | |
5767 | /* Turn off alias tokenization iff this character sequence would | |
5768 | not leave us ready to read a command. */ | |
5769 | if (character == '<' || character == '>') | |
5770 | parser_state &= ~PST_ALEXPNEXT; | |
5771 | #endif /* ALIAS */ | |
726f6388 | 5772 | |
95732b49 JA |
5773 | parser_state &= ~PST_ASSIGNOK; |
5774 | ||
a0c0a00f CR |
5775 | /* If we are parsing a command substitution and we have read a character |
5776 | that marks the end of it, don't bother to skip over quoted newlines | |
5777 | when we read the next token. We're just interested in a character | |
5778 | that will turn this into a two-character token, so we let the higher | |
5779 | layers deal with quoted newlines following the command substitution. */ | |
5780 | if ((parser_state & PST_CMDSUBST) && character == shell_eof_token) | |
5781 | peek_char = shell_getc (0); | |
5782 | else | |
5783 | peek_char = shell_getc (1); | |
5784 | ||
28ef6c31 JA |
5785 | if (character == peek_char) |
5786 | { | |
5787 | switch (character) | |
5788 | { | |
5789 | case '<': | |
5790 | /* If '<' then we could be at "<<" or at "<<-". We have to | |
5791 | look ahead one more character. */ | |
5792 | peek_char = shell_getc (1); | |
3185942a | 5793 | if MBTEST(peek_char == '-') |
28ef6c31 | 5794 | return (LESS_LESS_MINUS); |
3185942a | 5795 | else if MBTEST(peek_char == '<') |
7117c2d2 | 5796 | return (LESS_LESS_LESS); |
28ef6c31 JA |
5797 | else |
5798 | { | |
5799 | shell_ungetc (peek_char); | |
5800 | return (LESS_LESS); | |
5801 | } | |
726f6388 | 5802 | |
28ef6c31 JA |
5803 | case '>': |
5804 | return (GREATER_GREATER); | |
726f6388 | 5805 | |
28ef6c31 JA |
5806 | case ';': |
5807 | parser_state |= PST_CASEPAT; | |
5808 | #if defined (ALIAS) | |
5809 | parser_state &= ~PST_ALEXPNEXT; | |
5810 | #endif /* ALIAS */ | |
95732b49 | 5811 | |
3185942a JA |
5812 | peek_char = shell_getc (1); |
5813 | if MBTEST(peek_char == '&') | |
5814 | return (SEMI_SEMI_AND); | |
5815 | else | |
5816 | { | |
5817 | shell_ungetc (peek_char); | |
5818 | return (SEMI_SEMI); | |
5819 | } | |
726f6388 | 5820 | |
28ef6c31 JA |
5821 | case '&': |
5822 | return (AND_AND); | |
726f6388 | 5823 | |
28ef6c31 JA |
5824 | case '|': |
5825 | return (OR_OR); | |
726f6388 | 5826 | |
28ef6c31 JA |
5827 | #if defined (DPAREN_ARITHMETIC) || defined (ARITH_FOR_COMMAND) |
5828 | case '(': /* ) */ | |
7117c2d2 JA |
5829 | result = parse_dparen (character); |
5830 | if (result == -2) | |
5831 | break; | |
5832 | else | |
5833 | return result; | |
726f6388 | 5834 | #endif |
28ef6c31 JA |
5835 | } |
5836 | } | |
7117c2d2 | 5837 | else if MBTEST(character == '<' && peek_char == '&') |
28ef6c31 | 5838 | return (LESS_AND); |
7117c2d2 | 5839 | else if MBTEST(character == '>' && peek_char == '&') |
28ef6c31 | 5840 | return (GREATER_AND); |
7117c2d2 | 5841 | else if MBTEST(character == '<' && peek_char == '>') |
28ef6c31 | 5842 | return (LESS_GREATER); |
7117c2d2 | 5843 | else if MBTEST(character == '>' && peek_char == '|') |
28ef6c31 | 5844 | return (GREATER_BAR); |
3185942a JA |
5845 | else if MBTEST(character == '&' && peek_char == '>') |
5846 | { | |
5847 | peek_char = shell_getc (1); | |
5848 | if MBTEST(peek_char == '>') | |
5849 | return (AND_GREATER_GREATER); | |
5850 | else | |
5851 | { | |
5852 | shell_ungetc (peek_char); | |
5853 | return (AND_GREATER); | |
5854 | } | |
5855 | } | |
5856 | else if MBTEST(character == '|' && peek_char == '&') | |
5857 | return (BAR_AND); | |
5858 | else if MBTEST(character == ';' && peek_char == '&') | |
5859 | { | |
5860 | parser_state |= PST_CASEPAT; | |
5861 | #if defined (ALIAS) | |
5862 | parser_state &= ~PST_ALEXPNEXT; | |
5863 | #endif /* ALIAS */ | |
5864 | return (SEMI_AND); | |
5865 | } | |
726f6388 | 5866 | |
28ef6c31 | 5867 | shell_ungetc (peek_char); |
726f6388 | 5868 | |
28ef6c31 JA |
5869 | /* If we look like we are reading the start of a function |
5870 | definition, then let the reader know about it so that | |
5871 | we will do the right thing with `{'. */ | |
7117c2d2 | 5872 | if MBTEST(character == ')' && last_read_token == '(' && token_before_that == WORD) |
726f6388 | 5873 | { |
28ef6c31 JA |
5874 | parser_state |= PST_ALLOWOPNBRC; |
5875 | #if defined (ALIAS) | |
5876 | parser_state &= ~PST_ALEXPNEXT; | |
5877 | #endif /* ALIAS */ | |
5878 | function_dstart = line_number; | |
5879 | } | |
726f6388 | 5880 | |
28ef6c31 JA |
5881 | /* case pattern lists may be preceded by an optional left paren. If |
5882 | we're not trying to parse a case pattern list, the left paren | |
5883 | indicates a subshell. */ | |
7117c2d2 | 5884 | if MBTEST(character == '(' && (parser_state & PST_CASEPAT) == 0) /* ) */ |
28ef6c31 JA |
5885 | parser_state |= PST_SUBSHELL; |
5886 | /*(*/ | |
7117c2d2 | 5887 | else if MBTEST((parser_state & PST_CASEPAT) && character == ')') |
28ef6c31 JA |
5888 | parser_state &= ~PST_CASEPAT; |
5889 | /*(*/ | |
7117c2d2 | 5890 | else if MBTEST((parser_state & PST_SUBSHELL) && character == ')') |
28ef6c31 | 5891 | parser_state &= ~PST_SUBSHELL; |
726f6388 | 5892 | |
28ef6c31 JA |
5893 | #if defined (PROCESS_SUBSTITUTION) |
5894 | /* Check for the constructs which introduce process substitution. | |
5895 | Shells running in `posix mode' don't do process substitution. */ | |
712f80b0 | 5896 | if MBTEST((character != '>' && character != '<') || peek_char != '(') /*)*/ |
28ef6c31 JA |
5897 | #endif /* PROCESS_SUBSTITUTION */ |
5898 | return (character); | |
5899 | } | |
726f6388 | 5900 | |
3185942a JA |
5901 | /* Hack <&- (close stdin) case. Also <&N- (dup and close). */ |
5902 | if MBTEST(character == '-' && (last_read_token == LESS_AND || last_read_token == GREATER_AND)) | |
5903 | return (character); | |
5904 | ||
5905 | tokword: | |
5906 | /* Okay, if we got this far, we have to read a word. Read one, | |
5907 | and then check it against the known ones. */ | |
5908 | result = read_token_word (character); | |
5909 | #if defined (ALIAS) | |
5910 | if (result == RE_READ_TOKEN) | |
5911 | goto re_read_token; | |
5912 | #endif | |
5913 | return result; | |
5914 | } | |
5915 | ||
5916 | /* | |
5917 | * Match a $(...) or other grouping construct. This has to handle embedded | |
5918 | * quoted strings ('', ``, "") and nested constructs. It also must handle | |
5919 | * reprompting the user, if necessary, after reading a newline, and returning | |
5920 | * correct error values if it reads EOF. | |
5921 | */ | |
495aee44 CR |
5922 | #define P_FIRSTCLOSE 0x0001 |
5923 | #define P_ALLOWESC 0x0002 | |
5924 | #define P_DQUOTE 0x0004 | |
5925 | #define P_COMMAND 0x0008 /* parsing a command, so look for comments */ | |
5926 | #define P_BACKQUOTE 0x0010 /* parsing a backquoted command substitution */ | |
5927 | #define P_ARRAYSUB 0x0020 /* parsing a [...] array subscript for assignment */ | |
5928 | #define P_DOLBRACE 0x0040 /* parsing a ${...} construct */ | |
3185942a JA |
5929 | |
5930 | /* Lexical state while parsing a grouping construct or $(...). */ | |
d233b485 CR |
5931 | #define LEX_WASDOL 0x0001 |
5932 | #define LEX_CKCOMMENT 0x0002 | |
5933 | #define LEX_INCOMMENT 0x0004 | |
5934 | #define LEX_PASSNEXT 0x0008 | |
5935 | #define LEX_RESWDOK 0x0010 | |
5936 | #define LEX_CKCASE 0x0020 | |
5937 | #define LEX_INCASE 0x0040 | |
5938 | #define LEX_INHEREDOC 0x0080 | |
5939 | #define LEX_HEREDELIM 0x0100 /* reading here-doc delimiter */ | |
5940 | #define LEX_STRIPDOC 0x0200 /* <<- strip tabs from here doc delim */ | |
5941 | #define LEX_QUOTEDDOC 0x0400 /* here doc with quoted delim */ | |
5942 | #define LEX_INWORD 0x0800 | |
5943 | #define LEX_GTLT 0x1000 | |
3185942a JA |
5944 | |
5945 | #define COMSUB_META(ch) ((ch) == ';' || (ch) == '&' || (ch) == '|') | |
5946 | ||
5947 | #define CHECK_NESTRET_ERROR() \ | |
5948 | do { \ | |
5949 | if (nestret == &matched_pair_error) \ | |
5950 | { \ | |
5951 | free (ret); \ | |
5952 | return &matched_pair_error; \ | |
5953 | } \ | |
5954 | } while (0) | |
5955 | ||
5956 | #define APPEND_NESTRET() \ | |
5957 | do { \ | |
5958 | if (nestlen) \ | |
5959 | { \ | |
5960 | RESIZE_MALLOCED_BUFFER (ret, retind, nestlen, retsize, 64); \ | |
5961 | strcpy (ret + retind, nestret); \ | |
5962 | retind += nestlen; \ | |
5963 | } \ | |
5964 | } while (0) | |
5965 | ||
5966 | static char matched_pair_error; | |
5967 | ||
5968 | static char * | |
5969 | parse_matched_pair (qc, open, close, lenp, flags) | |
5970 | int qc; /* `"' if this construct is within double quotes */ | |
5971 | int open, close; | |
5972 | int *lenp, flags; | |
5973 | { | |
d233b485 | 5974 | int count, ch, prevch, tflags; |
3185942a JA |
5975 | int nestlen, ttranslen, start_lineno; |
5976 | char *ret, *nestret, *ttrans; | |
5977 | int retind, retsize, rflags; | |
495aee44 CR |
5978 | int dolbrace_state; |
5979 | ||
5980 | dolbrace_state = (flags & P_DOLBRACE) ? DOLBRACE_PARAM : 0; | |
3185942a | 5981 | |
0001803f | 5982 | /*itrace("parse_matched_pair[%d]: open = %c close = %c flags = %d", line_number, open, close, flags);*/ |
3185942a JA |
5983 | count = 1; |
5984 | tflags = 0; | |
5985 | ||
5986 | if ((flags & P_COMMAND) && qc != '`' && qc != '\'' && qc != '"' && (flags & P_DQUOTE) == 0) | |
5987 | tflags |= LEX_CKCOMMENT; | |
5988 | ||
5989 | /* RFLAGS is the set of flags we want to pass to recursive calls. */ | |
5990 | rflags = (qc == '"') ? P_DQUOTE : (flags & P_DQUOTE); | |
5991 | ||
5992 | ret = (char *)xmalloc (retsize = 64); | |
5993 | retind = 0; | |
5994 | ||
5995 | start_lineno = line_number; | |
d233b485 | 5996 | ch = EOF; /* just in case */ |
3185942a JA |
5997 | while (count) |
5998 | { | |
d233b485 | 5999 | prevch = ch; |
495aee44 | 6000 | ch = shell_getc (qc != '\'' && (tflags & (LEX_PASSNEXT)) == 0); |
3185942a JA |
6001 | |
6002 | if (ch == EOF) | |
6003 | { | |
6004 | free (ret); | |
6005 | parser_error (start_lineno, _("unexpected EOF while looking for matching `%c'"), close); | |
6006 | EOF_Reached = 1; /* XXX */ | |
6007 | return (&matched_pair_error); | |
6008 | } | |
6009 | ||
6010 | /* Possible reprompting. */ | |
6011 | if (ch == '\n' && SHOULD_PROMPT ()) | |
6012 | prompt_again (); | |
6013 | ||
6014 | /* Don't bother counting parens or doing anything else if in a comment | |
6015 | or part of a case statement */ | |
6016 | if (tflags & LEX_INCOMMENT) | |
6017 | { | |
6018 | /* Add this character. */ | |
6019 | RESIZE_MALLOCED_BUFFER (ret, retind, 1, retsize, 64); | |
6020 | ret[retind++] = ch; | |
6021 | ||
6022 | if (ch == '\n') | |
6023 | tflags &= ~LEX_INCOMMENT; | |
6024 | ||
6025 | continue; | |
6026 | } | |
6027 | ||
6028 | /* Not exactly right yet, should handle shell metacharacters, too. If | |
6029 | any changes are made to this test, make analogous changes to subst.c: | |
6030 | extract_delimited_string(). */ | |
6031 | else if MBTEST((tflags & LEX_CKCOMMENT) && (tflags & LEX_INCOMMENT) == 0 && ch == '#' && (retind == 0 || ret[retind-1] == '\n' || shellblank (ret[retind - 1]))) | |
6032 | tflags |= LEX_INCOMMENT; | |
6033 | ||
6034 | if (tflags & LEX_PASSNEXT) /* last char was backslash */ | |
6035 | { | |
6036 | tflags &= ~LEX_PASSNEXT; | |
6037 | if (qc != '\'' && ch == '\n') /* double-quoted \<newline> disappears. */ | |
6038 | { | |
6039 | if (retind > 0) | |
6040 | retind--; /* swallow previously-added backslash */ | |
6041 | continue; | |
6042 | } | |
6043 | ||
6044 | RESIZE_MALLOCED_BUFFER (ret, retind, 2, retsize, 64); | |
ac50fbac | 6045 | if MBTEST(ch == CTLESC) |
3185942a JA |
6046 | ret[retind++] = CTLESC; |
6047 | ret[retind++] = ch; | |
6048 | continue; | |
6049 | } | |
6050 | /* If we're reparsing the input (e.g., from parse_string_to_word_list), | |
6051 | we've already prepended CTLESC to single-quoted results of $'...'. | |
6052 | We may want to do this for other CTLESC-quoted characters in | |
6053 | reparse, too. */ | |
6054 | else if MBTEST((parser_state & PST_REPARSE) && open == '\'' && (ch == CTLESC || ch == CTLNUL)) | |
6055 | { | |
6056 | RESIZE_MALLOCED_BUFFER (ret, retind, 1, retsize, 64); | |
6057 | ret[retind++] = ch; | |
6058 | continue; | |
6059 | } | |
6060 | else if MBTEST(ch == CTLESC || ch == CTLNUL) /* special shell escapes */ | |
6061 | { | |
6062 | RESIZE_MALLOCED_BUFFER (ret, retind, 2, retsize, 64); | |
6063 | ret[retind++] = CTLESC; | |
6064 | ret[retind++] = ch; | |
6065 | continue; | |
6066 | } | |
6067 | else if MBTEST(ch == close) /* ending delimiter */ | |
6068 | count--; | |
6069 | /* handle nested ${...} specially. */ | |
6070 | else if MBTEST(open != close && (tflags & LEX_WASDOL) && open == '{' && ch == open) /* } */ | |
6071 | count++; | |
6072 | else if MBTEST(((flags & P_FIRSTCLOSE) == 0) && ch == open) /* nested begin */ | |
6073 | count++; | |
6074 | ||
6075 | /* Add this character. */ | |
6076 | RESIZE_MALLOCED_BUFFER (ret, retind, 1, retsize, 64); | |
6077 | ret[retind++] = ch; | |
6078 | ||
6079 | /* If we just read the ending character, don't bother continuing. */ | |
6080 | if (count == 0) | |
6081 | break; | |
6082 | ||
6083 | if (open == '\'') /* '' inside grouping construct */ | |
6084 | { | |
6085 | if MBTEST((flags & P_ALLOWESC) && ch == '\\') | |
6086 | tflags |= LEX_PASSNEXT; | |
6087 | continue; | |
6088 | } | |
6089 | ||
6090 | if MBTEST(ch == '\\') /* backslashes */ | |
6091 | tflags |= LEX_PASSNEXT; | |
6092 | ||
495aee44 CR |
6093 | /* Based on which dolstate is currently in (param, op, or word), |
6094 | decide what the op is. We're really only concerned if it's % or | |
6095 | #, so we can turn on a flag that says whether or not we should | |
6096 | treat single quotes as special when inside a double-quoted | |
6097 | ${...}. This logic must agree with subst.c:extract_dollar_brace_string | |
6098 | since they share the same defines. */ | |
ac50fbac | 6099 | /* FLAG POSIX INTERP 221 */ |
495aee44 CR |
6100 | if (flags & P_DOLBRACE) |
6101 | { | |
6102 | /* ${param%[%]word} */ | |
6103 | if MBTEST(dolbrace_state == DOLBRACE_PARAM && ch == '%' && retind > 1) | |
6104 | dolbrace_state = DOLBRACE_QUOTE; | |
6105 | /* ${param#[#]word} */ | |
6106 | else if MBTEST(dolbrace_state == DOLBRACE_PARAM && ch == '#' && retind > 1) | |
6107 | dolbrace_state = DOLBRACE_QUOTE; | |
6108 | /* ${param/[/]pat/rep} */ | |
6109 | else if MBTEST(dolbrace_state == DOLBRACE_PARAM && ch == '/' && retind > 1) | |
ac50fbac | 6110 | dolbrace_state = DOLBRACE_QUOTE2; /* XXX */ |
495aee44 CR |
6111 | /* ${param^[^]pat} */ |
6112 | else if MBTEST(dolbrace_state == DOLBRACE_PARAM && ch == '^' && retind > 1) | |
6113 | dolbrace_state = DOLBRACE_QUOTE; | |
6114 | /* ${param,[,]pat} */ | |
6115 | else if MBTEST(dolbrace_state == DOLBRACE_PARAM && ch == ',' && retind > 1) | |
6116 | dolbrace_state = DOLBRACE_QUOTE; | |
6117 | else if MBTEST(dolbrace_state == DOLBRACE_PARAM && strchr ("#%^,~:-=?+/", ch) != 0) | |
6118 | dolbrace_state = DOLBRACE_OP; | |
6119 | else if MBTEST(dolbrace_state == DOLBRACE_OP && strchr ("#%^,~:-=?+/", ch) == 0) | |
6120 | dolbrace_state = DOLBRACE_WORD; | |
6121 | } | |
6122 | ||
3185942a | 6123 | /* The big hammer. Single quotes aren't special in double quotes. The |
495aee44 | 6124 | problem is that Posix used to say the single quotes are semi-special: |
3185942a JA |
6125 | within a double-quoted ${...} construct "an even number of |
6126 | unescaped double-quotes or single-quotes, if any, shall occur." */ | |
495aee44 | 6127 | /* This was changed in Austin Group Interp 221 */ |
bc63a081 | 6128 | if MBTEST(posixly_correct && shell_compatibility_level > 41 && dolbrace_state != DOLBRACE_QUOTE && dolbrace_state != DOLBRACE_QUOTE2 && (flags & P_DQUOTE) && (flags & P_DOLBRACE) && ch == '\'') |
3185942a | 6129 | continue; |
3185942a JA |
6130 | |
6131 | /* Could also check open == '`' if we want to parse grouping constructs | |
6132 | inside old-style command substitution. */ | |
6133 | if (open != close) /* a grouping construct */ | |
6134 | { | |
6135 | if MBTEST(shellquote (ch)) | |
6136 | { | |
6137 | /* '', ``, or "" inside $(...) or other grouping construct. */ | |
6138 | push_delimiter (dstack, ch); | |
6139 | if MBTEST((tflags & LEX_WASDOL) && ch == '\'') /* $'...' inside group */ | |
6140 | nestret = parse_matched_pair (ch, ch, ch, &nestlen, P_ALLOWESC|rflags); | |
6141 | else | |
6142 | nestret = parse_matched_pair (ch, ch, ch, &nestlen, rflags); | |
6143 | pop_delimiter (dstack); | |
6144 | CHECK_NESTRET_ERROR (); | |
6145 | ||
6146 | if MBTEST((tflags & LEX_WASDOL) && ch == '\'' && (extended_quote || (rflags & P_DQUOTE) == 0)) | |
6147 | { | |
6148 | /* Translate $'...' here. */ | |
6149 | ttrans = ansiexpand (nestret, 0, nestlen - 1, &ttranslen); | |
d233b485 | 6150 | free (nestret); |
3185942a | 6151 | |
ac50fbac CR |
6152 | /* If we're parsing a double-quoted brace expansion and we are |
6153 | not in a place where single quotes are treated specially, | |
6154 | make sure we single-quote the results of the ansi | |
6155 | expansion because quote removal should remove them later */ | |
6156 | /* FLAG POSIX INTERP 221 */ | |
6157 | if ((shell_compatibility_level > 42) && (rflags & P_DQUOTE) && (dolbrace_state == DOLBRACE_QUOTE2) && (flags & P_DOLBRACE)) | |
6158 | { | |
6159 | nestret = sh_single_quote (ttrans); | |
6160 | free (ttrans); | |
6161 | nestlen = strlen (nestret); | |
6162 | } | |
6163 | else if ((rflags & P_DQUOTE) == 0) | |
3185942a JA |
6164 | { |
6165 | nestret = sh_single_quote (ttrans); | |
6166 | free (ttrans); | |
6167 | nestlen = strlen (nestret); | |
6168 | } | |
6169 | else | |
6170 | { | |
6171 | nestret = ttrans; | |
6172 | nestlen = ttranslen; | |
6173 | } | |
6174 | retind -= 2; /* back up before the $' */ | |
6175 | } | |
6176 | else if MBTEST((tflags & LEX_WASDOL) && ch == '"' && (extended_quote || (rflags & P_DQUOTE) == 0)) | |
6177 | { | |
6178 | /* Locale expand $"..." here. */ | |
6179 | ttrans = localeexpand (nestret, 0, nestlen - 1, start_lineno, &ttranslen); | |
d233b485 | 6180 | free (nestret); |
3185942a JA |
6181 | |
6182 | nestret = sh_mkdoublequoted (ttrans, ttranslen, 0); | |
6183 | free (ttrans); | |
6184 | nestlen = ttranslen + 2; | |
6185 | retind -= 2; /* back up before the $" */ | |
6186 | } | |
6187 | ||
6188 | APPEND_NESTRET (); | |
6189 | FREE (nestret); | |
6190 | } | |
a0c0a00f | 6191 | else if ((flags & (P_ARRAYSUB|P_DOLBRACE)) && (tflags & LEX_WASDOL) && (ch == '(' || ch == '{' || ch == '[')) /* ) } ] */ |
0001803f | 6192 | goto parse_dollar_word; |
d233b485 CR |
6193 | #if defined (PROCESS_SUBSTITUTION) |
6194 | /* XXX - technically this should only be recognized at the start of | |
6195 | a word */ | |
6196 | else if ((flags & (P_ARRAYSUB|P_DOLBRACE)) && (tflags & LEX_GTLT) && (ch == '(')) /* ) */ | |
6197 | goto parse_dollar_word; | |
6198 | #endif | |
3185942a JA |
6199 | } |
6200 | /* Parse an old-style command substitution within double quotes as a | |
6201 | single word. */ | |
6202 | /* XXX - sh and ksh93 don't do this - XXX */ | |
6203 | else if MBTEST(open == '"' && ch == '`') | |
6204 | { | |
6205 | nestret = parse_matched_pair (0, '`', '`', &nestlen, rflags); | |
6206 | ||
6207 | CHECK_NESTRET_ERROR (); | |
6208 | APPEND_NESTRET (); | |
6209 | ||
6210 | FREE (nestret); | |
6211 | } | |
6212 | else if MBTEST(open != '`' && (tflags & LEX_WASDOL) && (ch == '(' || ch == '{' || ch == '[')) /* ) } ] */ | |
6213 | /* check for $(), $[], or ${} inside quoted string. */ | |
6214 | { | |
0001803f | 6215 | parse_dollar_word: |
3185942a JA |
6216 | if (open == ch) /* undo previous increment */ |
6217 | count--; | |
6218 | if (ch == '(') /* ) */ | |
6219 | nestret = parse_comsub (0, '(', ')', &nestlen, (rflags|P_COMMAND) & ~P_DQUOTE); | |
6220 | else if (ch == '{') /* } */ | |
495aee44 | 6221 | nestret = parse_matched_pair (0, '{', '}', &nestlen, P_FIRSTCLOSE|P_DOLBRACE|rflags); |
3185942a JA |
6222 | else if (ch == '[') /* ] */ |
6223 | nestret = parse_matched_pair (0, '[', ']', &nestlen, rflags); | |
6224 | ||
6225 | CHECK_NESTRET_ERROR (); | |
6226 | APPEND_NESTRET (); | |
726f6388 | 6227 | |
3185942a JA |
6228 | FREE (nestret); |
6229 | } | |
d233b485 CR |
6230 | #if defined (PROCESS_SUBSTITUTION) |
6231 | if MBTEST((ch == '<' || ch == '>') && (tflags & LEX_GTLT) == 0) | |
6232 | tflags |= LEX_GTLT; | |
6233 | else | |
6234 | tflags &= ~LEX_GTLT; | |
6235 | #endif | |
6236 | if MBTEST(ch == '$' && (tflags & LEX_WASDOL) == 0) | |
3185942a JA |
6237 | tflags |= LEX_WASDOL; |
6238 | else | |
6239 | tflags &= ~LEX_WASDOL; | |
6240 | } | |
726f6388 | 6241 | |
3185942a JA |
6242 | ret[retind] = '\0'; |
6243 | if (lenp) | |
6244 | *lenp = retind; | |
0001803f | 6245 | /*itrace("parse_matched_pair[%d]: returning %s", line_number, ret);*/ |
3185942a JA |
6246 | return ret; |
6247 | } | |
726f6388 | 6248 | |
a0c0a00f CR |
6249 | #if defined (DEBUG) |
6250 | static void | |
6251 | dump_tflags (flags) | |
6252 | int flags; | |
6253 | { | |
6254 | int f; | |
6255 | ||
6256 | f = flags; | |
6257 | fprintf (stderr, "%d -> ", f); | |
6258 | if (f & LEX_WASDOL) | |
6259 | { | |
6260 | f &= ~LEX_WASDOL; | |
6261 | fprintf (stderr, "LEX_WASDOL%s", f ? "|" : ""); | |
6262 | } | |
6263 | if (f & LEX_CKCOMMENT) | |
6264 | { | |
6265 | f &= ~LEX_CKCOMMENT; | |
6266 | fprintf (stderr, "LEX_CKCOMMENT%s", f ? "|" : ""); | |
6267 | } | |
6268 | if (f & LEX_INCOMMENT) | |
6269 | { | |
6270 | f &= ~LEX_INCOMMENT; | |
6271 | fprintf (stderr, "LEX_INCOMMENT%s", f ? "|" : ""); | |
6272 | } | |
6273 | if (f & LEX_PASSNEXT) | |
6274 | { | |
6275 | f &= ~LEX_PASSNEXT; | |
6276 | fprintf (stderr, "LEX_PASSNEXT%s", f ? "|" : ""); | |
6277 | } | |
6278 | if (f & LEX_RESWDOK) | |
6279 | { | |
6280 | f &= ~LEX_RESWDOK; | |
6281 | fprintf (stderr, "LEX_RESWDOK%s", f ? "|" : ""); | |
6282 | } | |
6283 | if (f & LEX_CKCASE) | |
6284 | { | |
6285 | f &= ~LEX_CKCASE; | |
6286 | fprintf (stderr, "LEX_CKCASE%s", f ? "|" : ""); | |
6287 | } | |
6288 | if (f & LEX_INCASE) | |
6289 | { | |
6290 | f &= ~LEX_INCASE; | |
6291 | fprintf (stderr, "LEX_INCASE%s", f ? "|" : ""); | |
6292 | } | |
6293 | if (f & LEX_INHEREDOC) | |
6294 | { | |
6295 | f &= ~LEX_INHEREDOC; | |
6296 | fprintf (stderr, "LEX_INHEREDOC%s", f ? "|" : ""); | |
6297 | } | |
6298 | if (f & LEX_HEREDELIM) | |
6299 | { | |
6300 | f &= ~LEX_HEREDELIM; | |
6301 | fprintf (stderr, "LEX_HEREDELIM%s", f ? "|" : ""); | |
6302 | } | |
6303 | if (f & LEX_STRIPDOC) | |
6304 | { | |
6305 | f &= ~LEX_STRIPDOC; | |
6306 | fprintf (stderr, "LEX_WASDOL%s", f ? "|" : ""); | |
6307 | } | |
6308 | if (f & LEX_QUOTEDDOC) | |
6309 | { | |
6310 | f &= ~LEX_QUOTEDDOC; | |
6311 | fprintf (stderr, "LEX_QUOTEDDOC%s", f ? "|" : ""); | |
6312 | } | |
6313 | if (f & LEX_INWORD) | |
6314 | { | |
6315 | f &= ~LEX_INWORD; | |
6316 | fprintf (stderr, "LEX_INWORD%s", f ? "|" : ""); | |
6317 | } | |
6318 | ||
6319 | fprintf (stderr, "\n"); | |
6320 | fflush (stderr); | |
6321 | } | |
6322 | #endif | |
6323 | ||
3185942a JA |
6324 | /* Parse a $(...) command substitution. This is messier than I'd like, and |
6325 | reproduces a lot more of the token-reading code than I'd like. */ | |
28ef6c31 | 6326 | static char * |
3185942a | 6327 | parse_comsub (qc, open, close, lenp, flags) |
28ef6c31 JA |
6328 | int qc; /* `"' if this construct is within double quotes */ |
6329 | int open, close; | |
6330 | int *lenp, flags; | |
6331 | { | |
0001803f | 6332 | int count, ch, peekc, tflags, lex_rwlen, lex_wlen, lex_firstind; |
712f80b0 | 6333 | int nestlen, ttranslen, start_lineno, orig_histexp; |
3185942a JA |
6334 | char *ret, *nestret, *ttrans, *heredelim; |
6335 | int retind, retsize, rflags, hdlen; | |
ccc6cda3 | 6336 | |
495aee44 CR |
6337 | /* Posix interp 217 says arithmetic expressions have precedence, so |
6338 | assume $(( introduces arithmetic expansion and parse accordingly. */ | |
6339 | peekc = shell_getc (0); | |
6340 | shell_ungetc (peekc); | |
6341 | if (peekc == '(') | |
6342 | return (parse_matched_pair (qc, open, close, lenp, 0)); | |
6343 | ||
3185942a | 6344 | /*itrace("parse_comsub: qc = `%c' open = %c close = %c", qc, open, close);*/ |
28ef6c31 | 6345 | count = 1; |
3185942a | 6346 | tflags = LEX_RESWDOK; |
712f80b0 CR |
6347 | #if defined (BANG_HISTORY) |
6348 | orig_histexp = history_expansion_inhibited; | |
6349 | #endif | |
3185942a JA |
6350 | |
6351 | if ((flags & P_COMMAND) && qc != '\'' && qc != '"' && (flags & P_DQUOTE) == 0) | |
6352 | tflags |= LEX_CKCASE; | |
6353 | if ((tflags & LEX_CKCASE) && (interactive == 0 || interactive_comments)) | |
6354 | tflags |= LEX_CKCOMMENT; | |
d166f048 | 6355 | |
b80f6443 | 6356 | /* RFLAGS is the set of flags we want to pass to recursive calls. */ |
3185942a | 6357 | rflags = (flags & P_DQUOTE); |
b80f6443 | 6358 | |
f73dda09 | 6359 | ret = (char *)xmalloc (retsize = 64); |
28ef6c31 JA |
6360 | retind = 0; |
6361 | ||
6362 | start_lineno = line_number; | |
0001803f | 6363 | lex_rwlen = lex_wlen = 0; |
3185942a JA |
6364 | |
6365 | heredelim = 0; | |
6366 | lex_firstind = -1; | |
6367 | ||
28ef6c31 JA |
6368 | while (count) |
6369 | { | |
3185942a | 6370 | comsub_readchar: |
d233b485 | 6371 | ch = shell_getc (qc != '\'' && (tflags & (LEX_INCOMMENT|LEX_PASSNEXT|LEX_QUOTEDDOC)) == 0); |
0628567a | 6372 | |
28ef6c31 | 6373 | if (ch == EOF) |
ccc6cda3 | 6374 | { |
3185942a | 6375 | eof_error: |
712f80b0 CR |
6376 | #if defined (BANG_HISTORY) |
6377 | history_expansion_inhibited = orig_histexp; | |
6378 | #endif | |
28ef6c31 | 6379 | free (ret); |
3185942a | 6380 | FREE (heredelim); |
b80f6443 | 6381 | parser_error (start_lineno, _("unexpected EOF while looking for matching `%c'"), close); |
28ef6c31 JA |
6382 | EOF_Reached = 1; /* XXX */ |
6383 | return (&matched_pair_error); | |
ccc6cda3 JA |
6384 | } |
6385 | ||
3185942a JA |
6386 | /* If we hit the end of a line and are reading the contents of a here |
6387 | document, and it's not the same line that the document starts on, | |
6388 | check for this line being the here doc delimiter. Otherwise, if | |
6389 | we're in a here document, mark the next character as the beginning | |
6390 | of a line. */ | |
6391 | if (ch == '\n') | |
6392 | { | |
6393 | if ((tflags & LEX_HEREDELIM) && heredelim) | |
6394 | { | |
6395 | tflags &= ~LEX_HEREDELIM; | |
6396 | tflags |= LEX_INHEREDOC; | |
712f80b0 CR |
6397 | #if defined (BANG_HISTORY) |
6398 | history_expansion_inhibited = 1; | |
6399 | #endif | |
3185942a JA |
6400 | lex_firstind = retind + 1; |
6401 | } | |
6402 | else if (tflags & LEX_INHEREDOC) | |
6403 | { | |
6404 | int tind; | |
6405 | tind = lex_firstind; | |
6406 | while ((tflags & LEX_STRIPDOC) && ret[tind] == '\t') | |
6407 | tind++; | |
d233b485 | 6408 | if (retind-tind == hdlen && STREQN (ret + tind, heredelim, hdlen)) |
3185942a | 6409 | { |
a0c0a00f | 6410 | tflags &= ~(LEX_STRIPDOC|LEX_INHEREDOC|LEX_QUOTEDDOC); |
3185942a | 6411 | /*itrace("parse_comsub:%d: found here doc end `%s'", line_number, ret + tind);*/ |
0001803f CR |
6412 | free (heredelim); |
6413 | heredelim = 0; | |
3185942a | 6414 | lex_firstind = -1; |
712f80b0 CR |
6415 | #if defined (BANG_HISTORY) |
6416 | history_expansion_inhibited = orig_histexp; | |
6417 | #endif | |
3185942a JA |
6418 | } |
6419 | else | |
6420 | lex_firstind = retind + 1; | |
6421 | } | |
6422 | } | |
6423 | ||
28ef6c31 | 6424 | /* Possible reprompting. */ |
b80f6443 | 6425 | if (ch == '\n' && SHOULD_PROMPT ()) |
28ef6c31 | 6426 | prompt_again (); |
726f6388 | 6427 | |
712f80b0 CR |
6428 | /* XXX -- we currently allow here doc to be delimited by ending right |
6429 | paren in default mode and posix mode. To change posix mode, change | |
6430 | the #if 1 to #if 0 below */ | |
0001803f CR |
6431 | if ((tflags & LEX_INHEREDOC) && ch == close && count == 1) |
6432 | { | |
6433 | int tind; | |
a0c0a00f | 6434 | /*itrace("parse_comsub:%d: in here doc, ch == close, retind - firstind = %d hdlen = %d retind = %d", line_number, retind-lex_firstind, hdlen, retind);*/ |
0001803f CR |
6435 | tind = lex_firstind; |
6436 | while ((tflags & LEX_STRIPDOC) && ret[tind] == '\t') | |
6437 | tind++; | |
712f80b0 CR |
6438 | #if 1 |
6439 | if (retind-tind == hdlen && STREQN (ret + tind, heredelim, hdlen)) | |
6440 | #else | |
6441 | /* Posix-mode shells require the newline after the here-document | |
6442 | delimiter. */ | |
6443 | if (retind-tind == hdlen && STREQN (ret + tind, heredelim, hdlen) && | |
6444 | posixly_correct == 0) | |
6445 | #endif | |
0001803f | 6446 | { |
a0c0a00f CR |
6447 | tflags &= ~(LEX_STRIPDOC|LEX_INHEREDOC|LEX_QUOTEDDOC); |
6448 | /*itrace("parse_comsub:%d: found here doc end `%*s'", line_number, hdlen, ret + tind);*/ | |
0001803f CR |
6449 | free (heredelim); |
6450 | heredelim = 0; | |
6451 | lex_firstind = -1; | |
712f80b0 CR |
6452 | #if defined (BANG_HISTORY) |
6453 | history_expansion_inhibited = orig_histexp; | |
6454 | #endif | |
0001803f CR |
6455 | } |
6456 | } | |
6457 | ||
a0c0a00f CR |
6458 | /* Don't bother counting parens or doing anything else if in a comment or |
6459 | here document (not exactly right for here-docs -- if we want to allow | |
6460 | recursive calls to parse_comsub to have their own here documents, | |
6461 | change the LEX_INHEREDOC to LEX_QUOTEDDOC here and uncomment the next | |
6462 | clause below. Note that to make this work completely, we need to make | |
6463 | additional changes to allow xparse_dolparen to work right when the | |
6464 | command substitution is parsed, because read_secondary_line doesn't know | |
6465 | to recursively parse through command substitutions embedded in here- | |
6466 | documents */ | |
3185942a | 6467 | if (tflags & (LEX_INCOMMENT|LEX_INHEREDOC)) |
95732b49 JA |
6468 | { |
6469 | /* Add this character. */ | |
6470 | RESIZE_MALLOCED_BUFFER (ret, retind, 1, retsize, 64); | |
6471 | ret[retind++] = ch; | |
6472 | ||
3185942a | 6473 | if ((tflags & LEX_INCOMMENT) && ch == '\n') |
ac50fbac | 6474 | { |
0001803f | 6475 | /*itrace("parse_comsub:%d: lex_incomment -> 0 ch = `%c'", line_number, ch);*/ |
ac50fbac CR |
6476 | tflags &= ~LEX_INCOMMENT; |
6477 | } | |
95732b49 JA |
6478 | |
6479 | continue; | |
6480 | } | |
a0c0a00f CR |
6481 | #if 0 |
6482 | /* If we're going to recursively parse a command substitution inside a | |
6483 | here-document, make sure we call parse_comsub recursively below. See | |
6484 | above for additional caveats. */ | |
6485 | if ((tflags & LEX_INHEREDOC) && ((tflags & LEX_WASDOL) == 0 || ch != '(')) /*)*/ | |
6486 | { | |
6487 | /* Add this character. */ | |
6488 | RESIZE_MALLOCED_BUFFER (ret, retind, 1, retsize, 64); | |
6489 | ret[retind++] = ch; | |
6490 | if MBTEST(ch == '$') | |
6491 | tflags |= LEX_WASDOL; | |
6492 | else | |
6493 | tflags &= ~LEX_WASDOL; | |
6494 | } | |
6495 | #endif | |
95732b49 | 6496 | |
0001803f CR |
6497 | if (tflags & LEX_PASSNEXT) /* last char was backslash */ |
6498 | { | |
6499 | /*itrace("parse_comsub:%d: lex_passnext -> 0 ch = `%c' (%d)", line_number, ch, __LINE__);*/ | |
6500 | tflags &= ~LEX_PASSNEXT; | |
6501 | if (qc != '\'' && ch == '\n') /* double-quoted \<newline> disappears. */ | |
6502 | { | |
6503 | if (retind > 0) | |
6504 | retind--; /* swallow previously-added backslash */ | |
6505 | continue; | |
6506 | } | |
6507 | ||
6508 | RESIZE_MALLOCED_BUFFER (ret, retind, 2, retsize, 64); | |
ac50fbac | 6509 | if MBTEST(ch == CTLESC) |
0001803f CR |
6510 | ret[retind++] = CTLESC; |
6511 | ret[retind++] = ch; | |
6512 | continue; | |
6513 | } | |
6514 | ||
6515 | /* If this is a shell break character, we are not in a word. If not, | |
6516 | we either start or continue a word. */ | |
6517 | if MBTEST(shellbreak (ch)) | |
6518 | { | |
6519 | tflags &= ~LEX_INWORD; | |
6520 | /*itrace("parse_comsub:%d: lex_inword -> 0 ch = `%c' (%d)", line_number, ch, __LINE__);*/ | |
6521 | } | |
6522 | else | |
6523 | { | |
6524 | if (tflags & LEX_INWORD) | |
6525 | { | |
6526 | lex_wlen++; | |
6527 | /*itrace("parse_comsub:%d: lex_inword == 1 ch = `%c' lex_wlen = %d (%d)", line_number, ch, lex_wlen, __LINE__);*/ | |
6528 | } | |
6529 | else | |
6530 | { | |
6531 | /*itrace("parse_comsub:%d: lex_inword -> 1 ch = `%c' (%d)", line_number, ch, __LINE__);*/ | |
6532 | tflags |= LEX_INWORD; | |
6533 | lex_wlen = 0; | |
ae339e9c CR |
6534 | if (tflags & LEX_RESWDOK) |
6535 | lex_rwlen = 0; | |
0001803f CR |
6536 | } |
6537 | } | |
6538 | ||
3185942a | 6539 | /* Skip whitespace */ |
495aee44 | 6540 | if MBTEST(shellblank (ch) && (tflags & LEX_HEREDELIM) == 0 && lex_rwlen == 0) |
3185942a JA |
6541 | { |
6542 | /* Add this character. */ | |
6543 | RESIZE_MALLOCED_BUFFER (ret, retind, 1, retsize, 64); | |
6544 | ret[retind++] = ch; | |
6545 | continue; | |
6546 | } | |
6547 | ||
6548 | /* Either we are looking for the start of the here-doc delimiter | |
6549 | (lex_firstind == -1) or we are reading one (lex_firstind >= 0). | |
6550 | If this character is a shell break character and we are reading | |
6551 | the delimiter, save it and note that we are now reading a here | |
6552 | document. If we've found the start of the delimiter, note it by | |
6553 | setting lex_firstind. Backslashes can quote shell metacharacters | |
6554 | in here-doc delimiters. */ | |
6555 | if (tflags & LEX_HEREDELIM) | |
0628567a | 6556 | { |
3185942a JA |
6557 | if (lex_firstind == -1 && shellbreak (ch) == 0) |
6558 | lex_firstind = retind; | |
0001803f CR |
6559 | #if 0 |
6560 | else if (heredelim && (tflags & LEX_PASSNEXT) == 0 && ch == '\n') | |
6561 | { | |
6562 | tflags |= LEX_INHEREDOC; | |
6563 | tflags &= ~LEX_HEREDELIM; | |
6564 | lex_firstind = retind + 1; | |
712f80b0 CR |
6565 | #if defined (BANG_HISTORY) |
6566 | history_expansion_inhibited = 1; | |
6567 | #endif | |
0001803f CR |
6568 | } |
6569 | #endif | |
3185942a JA |
6570 | else if (lex_firstind >= 0 && (tflags & LEX_PASSNEXT) == 0 && shellbreak (ch)) |
6571 | { | |
0001803f CR |
6572 | if (heredelim == 0) |
6573 | { | |
6574 | nestret = substring (ret, lex_firstind, retind); | |
6575 | heredelim = string_quote_removal (nestret, 0); | |
0001803f | 6576 | hdlen = STRLEN(heredelim); |
3185942a | 6577 | /*itrace("parse_comsub:%d: found here doc delimiter `%s' (%d)", line_number, heredelim, hdlen);*/ |
a0c0a00f CR |
6578 | if (STREQ (heredelim, nestret) == 0) |
6579 | tflags |= LEX_QUOTEDDOC; | |
6580 | free (nestret); | |
0001803f | 6581 | } |
3185942a JA |
6582 | if (ch == '\n') |
6583 | { | |
6584 | tflags |= LEX_INHEREDOC; | |
6585 | tflags &= ~LEX_HEREDELIM; | |
6586 | lex_firstind = retind + 1; | |
712f80b0 CR |
6587 | #if defined (BANG_HISTORY) |
6588 | history_expansion_inhibited = 1; | |
6589 | #endif | |
3185942a JA |
6590 | } |
6591 | else | |
6592 | lex_firstind = -1; | |
6593 | } | |
0628567a JA |
6594 | } |
6595 | ||
3185942a | 6596 | /* Meta-characters that can introduce a reserved word. Not perfect yet. */ |
0001803f | 6597 | if MBTEST((tflags & LEX_RESWDOK) == 0 && (tflags & LEX_CKCASE) && (tflags & LEX_INCOMMENT) == 0 && (shellmeta(ch) || ch == '\n')) |
726f6388 | 6598 | { |
3185942a JA |
6599 | /* Add this character. */ |
6600 | RESIZE_MALLOCED_BUFFER (ret, retind, 1, retsize, 64); | |
6601 | ret[retind++] = ch; | |
6602 | peekc = shell_getc (1); | |
6603 | if (ch == peekc && (ch == '&' || ch == '|' || ch == ';')) /* two-character tokens */ | |
6604 | { | |
6605 | RESIZE_MALLOCED_BUFFER (ret, retind, 1, retsize, 64); | |
6606 | ret[retind++] = peekc; | |
0001803f | 6607 | /*itrace("parse_comsub:%d: set lex_reswordok = 1, ch = `%c'", line_number, ch);*/ |
3185942a JA |
6608 | tflags |= LEX_RESWDOK; |
6609 | lex_rwlen = 0; | |
6610 | continue; | |
6611 | } | |
6612 | else if (ch == '\n' || COMSUB_META(ch)) | |
6613 | { | |
6614 | shell_ungetc (peekc); | |
3185942a | 6615 | /*itrace("parse_comsub:%d: set lex_reswordok = 1, ch = `%c'", line_number, ch);*/ |
0001803f | 6616 | tflags |= LEX_RESWDOK; |
3185942a JA |
6617 | lex_rwlen = 0; |
6618 | continue; | |
6619 | } | |
6620 | else if (ch == EOF) | |
6621 | goto eof_error; | |
6622 | else | |
6623 | { | |
6624 | /* `unget' the character we just added and fall through */ | |
6625 | retind--; | |
6626 | shell_ungetc (peekc); | |
6627 | } | |
6628 | } | |
6629 | ||
6630 | /* If we can read a reserved word, try to read one. */ | |
6631 | if (tflags & LEX_RESWDOK) | |
6632 | { | |
a0c0a00f | 6633 | if MBTEST(islower ((unsigned char)ch)) |
3185942a JA |
6634 | { |
6635 | /* Add this character. */ | |
6636 | RESIZE_MALLOCED_BUFFER (ret, retind, 1, retsize, 64); | |
6637 | ret[retind++] = ch; | |
6638 | lex_rwlen++; | |
6639 | continue; | |
6640 | } | |
6641 | else if MBTEST(lex_rwlen == 4 && shellbreak (ch)) | |
6642 | { | |
6643 | if (STREQN (ret + retind - 4, "case", 4)) | |
ac50fbac CR |
6644 | { |
6645 | tflags |= LEX_INCASE; | |
a0c0a00f | 6646 | tflags &= ~LEX_RESWDOK; |
0001803f | 6647 | /*itrace("parse_comsub:%d: found `case', lex_incase -> 1 lex_reswdok -> 0", line_number);*/ |
ac50fbac | 6648 | } |
3185942a | 6649 | else if (STREQN (ret + retind - 4, "esac", 4)) |
ac50fbac CR |
6650 | { |
6651 | tflags &= ~LEX_INCASE; | |
a0c0a00f CR |
6652 | /*itrace("parse_comsub:%d: found `esac', lex_incase -> 0 lex_reswdok -> 1", line_number);*/ |
6653 | tflags |= LEX_RESWDOK; | |
6654 | lex_rwlen = 0; | |
6655 | } | |
6656 | else if (STREQN (ret + retind - 4, "done", 4) || | |
6657 | STREQN (ret + retind - 4, "then", 4) || | |
6658 | STREQN (ret + retind - 4, "else", 4) || | |
6659 | STREQN (ret + retind - 4, "elif", 4) || | |
6660 | STREQN (ret + retind - 4, "time", 4)) | |
6661 | { | |
6662 | /* these are four-character reserved words that can be | |
6663 | followed by a reserved word; anything else turns off | |
6664 | the reserved-word-ok flag */ | |
6665 | /*itrace("parse_comsub:%d: found `%.4s', lex_reswdok -> 1", line_number, ret+retind-4);*/ | |
6666 | tflags |= LEX_RESWDOK; | |
6667 | lex_rwlen = 0; | |
6668 | } | |
d233b485 | 6669 | else if (shellmeta (ch) == 0) |
a0c0a00f CR |
6670 | { |
6671 | tflags &= ~LEX_RESWDOK; | |
6672 | /*itrace("parse_comsub:%d: found `%.4s', lex_reswdok -> 0", line_number, ret+retind-4);*/ | |
ac50fbac | 6673 | } |
d233b485 CR |
6674 | else /* can't be in a reserved word any more */ |
6675 | lex_rwlen = 0; | |
3185942a | 6676 | } |
0001803f CR |
6677 | else if MBTEST((tflags & LEX_CKCOMMENT) && ch == '#' && (lex_rwlen == 0 || ((tflags & LEX_INWORD) && lex_wlen == 0))) |
6678 | ; /* don't modify LEX_RESWDOK if we're starting a comment */ | |
ac50fbac CR |
6679 | /* Allow `do' followed by space, tab, or newline to preserve the |
6680 | RESWDOK flag, but reset the reserved word length counter so we | |
6681 | can read another one. */ | |
6682 | else if MBTEST(((tflags & LEX_INCASE) == 0) && | |
a0c0a00f | 6683 | (isblank((unsigned char)ch) || ch == '\n') && |
ac50fbac CR |
6684 | lex_rwlen == 2 && |
6685 | STREQN (ret + retind - 2, "do", 2)) | |
6686 | { | |
a0c0a00f | 6687 | /*itrace("parse_comsub:%d: lex_incase == 0 found `%c', found \"do\"", line_number, ch);*/ |
ac50fbac CR |
6688 | lex_rwlen = 0; |
6689 | } | |
0001803f CR |
6690 | else if MBTEST((tflags & LEX_INCASE) && ch != '\n') |
6691 | /* If we can read a reserved word and we're in case, we're at the | |
6692 | point where we can read a new pattern list or an esac. We | |
6693 | handle the esac case above. If we read a newline, we want to | |
6694 | leave LEX_RESWDOK alone. If we read anything else, we want to | |
6695 | turn off LEX_RESWDOK, since we're going to read a pattern list. */ | |
ac50fbac CR |
6696 | { |
6697 | tflags &= ~LEX_RESWDOK; | |
0001803f | 6698 | /*itrace("parse_comsub:%d: lex_incase == 1 found `%c', lex_reswordok -> 0", line_number, ch);*/ |
ac50fbac | 6699 | } |
0001803f | 6700 | else if MBTEST(shellbreak (ch) == 0) |
ac50fbac CR |
6701 | { |
6702 | tflags &= ~LEX_RESWDOK; | |
3185942a | 6703 | /*itrace("parse_comsub:%d: found `%c', lex_reswordok -> 0", line_number, ch);*/ |
ac50fbac CR |
6704 | } |
6705 | #if 0 | |
6706 | /* If we find a space or tab but have read something and it's not | |
6707 | `do', turn off the reserved-word-ok flag */ | |
a0c0a00f | 6708 | else if MBTEST(isblank ((unsigned char)ch) && lex_rwlen > 0) |
ac50fbac CR |
6709 | { |
6710 | tflags &= ~LEX_RESWDOK; | |
6711 | /*itrace("parse_comsub:%d: found `%c', lex_reswordok -> 0", line_number, ch);*/ | |
6712 | } | |
6713 | #endif | |
3185942a JA |
6714 | } |
6715 | ||
0001803f | 6716 | /* Might be the start of a here-doc delimiter */ |
3185942a JA |
6717 | if MBTEST((tflags & LEX_INCOMMENT) == 0 && (tflags & LEX_CKCASE) && ch == '<') |
6718 | { | |
6719 | /* Add this character. */ | |
6720 | RESIZE_MALLOCED_BUFFER (ret, retind, 1, retsize, 64); | |
6721 | ret[retind++] = ch; | |
6722 | peekc = shell_getc (1); | |
6723 | if (peekc == EOF) | |
6724 | goto eof_error; | |
6725 | if (peekc == ch) | |
6726 | { | |
6727 | RESIZE_MALLOCED_BUFFER (ret, retind, 1, retsize, 64); | |
6728 | ret[retind++] = peekc; | |
6729 | peekc = shell_getc (1); | |
6730 | if (peekc == EOF) | |
6731 | goto eof_error; | |
6732 | if (peekc == '-') | |
6733 | { | |
6734 | RESIZE_MALLOCED_BUFFER (ret, retind, 1, retsize, 64); | |
6735 | ret[retind++] = peekc; | |
6736 | tflags |= LEX_STRIPDOC; | |
6737 | } | |
6738 | else | |
6739 | shell_ungetc (peekc); | |
0001803f CR |
6740 | if (peekc != '<') |
6741 | { | |
6742 | tflags |= LEX_HEREDELIM; | |
6743 | lex_firstind = -1; | |
6744 | } | |
3185942a JA |
6745 | continue; |
6746 | } | |
6747 | else | |
d233b485 CR |
6748 | { |
6749 | shell_ungetc (peekc); /* not a here-doc, start over */ | |
6750 | continue; | |
6751 | } | |
3185942a | 6752 | } |
0001803f | 6753 | else if MBTEST((tflags & LEX_CKCOMMENT) && (tflags & LEX_INCOMMENT) == 0 && ch == '#' && (((tflags & LEX_RESWDOK) && lex_rwlen == 0) || ((tflags & LEX_INWORD) && lex_wlen == 0))) |
ac50fbac | 6754 | { |
0001803f | 6755 | /*itrace("parse_comsub:%d: lex_incomment -> 1 (%d)", line_number, __LINE__);*/ |
ac50fbac CR |
6756 | tflags |= LEX_INCOMMENT; |
6757 | } | |
3185942a | 6758 | |
0001803f | 6759 | if MBTEST(ch == CTLESC || ch == CTLNUL) /* special shell escapes */ |
726f6388 | 6760 | { |
28ef6c31 JA |
6761 | RESIZE_MALLOCED_BUFFER (ret, retind, 2, retsize, 64); |
6762 | ret[retind++] = CTLESC; | |
6763 | ret[retind++] = ch; | |
6764 | continue; | |
726f6388 | 6765 | } |
3185942a JA |
6766 | #if 0 |
6767 | else if MBTEST((tflags & LEX_INCASE) && ch == close && close == ')') | |
6768 | tflags &= ~LEX_INCASE; /* XXX */ | |
6769 | #endif | |
6770 | else if MBTEST(ch == close && (tflags & LEX_INCASE) == 0) /* ending delimiter */ | |
ac50fbac CR |
6771 | { |
6772 | count--; | |
3185942a | 6773 | /*itrace("parse_comsub:%d: found close: count = %d", line_number, count);*/ |
ac50fbac | 6774 | } |
3185942a | 6775 | else if MBTEST(((flags & P_FIRSTCLOSE) == 0) && (tflags & LEX_INCASE) == 0 && ch == open) /* nested begin */ |
ac50fbac CR |
6776 | { |
6777 | count++; | |
0001803f | 6778 | /*itrace("parse_comsub:%d: found open: count = %d", line_number, count);*/ |
ac50fbac | 6779 | } |
726f6388 | 6780 | |
28ef6c31 JA |
6781 | /* Add this character. */ |
6782 | RESIZE_MALLOCED_BUFFER (ret, retind, 1, retsize, 64); | |
6783 | ret[retind++] = ch; | |
6784 | ||
3185942a JA |
6785 | /* If we just read the ending character, don't bother continuing. */ |
6786 | if (count == 0) | |
6787 | break; | |
726f6388 | 6788 | |
7117c2d2 | 6789 | if MBTEST(ch == '\\') /* backslashes */ |
3185942a | 6790 | tflags |= LEX_PASSNEXT; |
28ef6c31 | 6791 | |
3185942a JA |
6792 | if MBTEST(shellquote (ch)) |
6793 | { | |
6794 | /* '', ``, or "" inside $(...). */ | |
6795 | push_delimiter (dstack, ch); | |
6796 | if MBTEST((tflags & LEX_WASDOL) && ch == '\'') /* $'...' inside group */ | |
6797 | nestret = parse_matched_pair (ch, ch, ch, &nestlen, P_ALLOWESC|rflags); | |
6798 | else | |
6799 | nestret = parse_matched_pair (ch, ch, ch, &nestlen, rflags); | |
6800 | pop_delimiter (dstack); | |
6801 | CHECK_NESTRET_ERROR (); | |
6802 | ||
6803 | if MBTEST((tflags & LEX_WASDOL) && ch == '\'' && (extended_quote || (rflags & P_DQUOTE) == 0)) | |
28ef6c31 | 6804 | { |
3185942a JA |
6805 | /* Translate $'...' here. */ |
6806 | ttrans = ansiexpand (nestret, 0, nestlen - 1, &ttranslen); | |
d233b485 | 6807 | free (nestret); |
95732b49 | 6808 | |
3185942a | 6809 | if ((rflags & P_DQUOTE) == 0) |
28ef6c31 | 6810 | { |
3185942a | 6811 | nestret = sh_single_quote (ttrans); |
28ef6c31 | 6812 | free (ttrans); |
3185942a | 6813 | nestlen = strlen (nestret); |
28ef6c31 | 6814 | } |
3185942a | 6815 | else |
28ef6c31 | 6816 | { |
3185942a JA |
6817 | nestret = ttrans; |
6818 | nestlen = ttranslen; | |
28ef6c31 | 6819 | } |
3185942a | 6820 | retind -= 2; /* back up before the $' */ |
28ef6c31 | 6821 | } |
3185942a | 6822 | else if MBTEST((tflags & LEX_WASDOL) && ch == '"' && (extended_quote || (rflags & P_DQUOTE) == 0)) |
28ef6c31 | 6823 | { |
3185942a JA |
6824 | /* Locale expand $"..." here. */ |
6825 | ttrans = localeexpand (nestret, 0, nestlen - 1, start_lineno, &ttranslen); | |
d233b485 | 6826 | free (nestret); |
3185942a JA |
6827 | |
6828 | nestret = sh_mkdoublequoted (ttrans, ttranslen, 0); | |
6829 | free (ttrans); | |
6830 | nestlen = ttranslen + 2; | |
6831 | retind -= 2; /* back up before the $" */ | |
28ef6c31 | 6832 | } |
3185942a JA |
6833 | |
6834 | APPEND_NESTRET (); | |
28ef6c31 JA |
6835 | FREE (nestret); |
6836 | } | |
3185942a JA |
6837 | else if MBTEST((tflags & LEX_WASDOL) && (ch == '(' || ch == '{' || ch == '[')) /* ) } ] */ |
6838 | /* check for $(), $[], or ${} inside command substitution. */ | |
28ef6c31 | 6839 | { |
3185942a | 6840 | if ((tflags & LEX_INCASE) == 0 && open == ch) /* undo previous increment */ |
28ef6c31 JA |
6841 | count--; |
6842 | if (ch == '(') /* ) */ | |
3185942a | 6843 | nestret = parse_comsub (0, '(', ')', &nestlen, (rflags|P_COMMAND) & ~P_DQUOTE); |
28ef6c31 | 6844 | else if (ch == '{') /* } */ |
495aee44 | 6845 | nestret = parse_matched_pair (0, '{', '}', &nestlen, P_FIRSTCLOSE|P_DOLBRACE|rflags); |
28ef6c31 | 6846 | else if (ch == '[') /* ] */ |
b80f6443 | 6847 | nestret = parse_matched_pair (0, '[', ']', &nestlen, rflags); |
95732b49 | 6848 | |
3185942a JA |
6849 | CHECK_NESTRET_ERROR (); |
6850 | APPEND_NESTRET (); | |
6851 | ||
6852 | FREE (nestret); | |
726f6388 | 6853 | } |
d233b485 | 6854 | if MBTEST(ch == '$' && (tflags & LEX_WASDOL) == 0) |
3185942a JA |
6855 | tflags |= LEX_WASDOL; |
6856 | else | |
6857 | tflags &= ~LEX_WASDOL; | |
726f6388 | 6858 | } |
ccc6cda3 | 6859 | |
712f80b0 CR |
6860 | #if defined (BANG_HISTORY) |
6861 | history_expansion_inhibited = orig_histexp; | |
6862 | #endif | |
3185942a | 6863 | FREE (heredelim); |
28ef6c31 JA |
6864 | ret[retind] = '\0'; |
6865 | if (lenp) | |
6866 | *lenp = retind; | |
3185942a JA |
6867 | /*itrace("parse_comsub:%d: returning `%s'", line_number, ret);*/ |
6868 | return ret; | |
6869 | } | |
6870 | ||
495aee44 | 6871 | /* Recursively call the parser to parse a $(...) command substitution. */ |
3185942a JA |
6872 | char * |
6873 | xparse_dolparen (base, string, indp, flags) | |
6874 | char *base; | |
6875 | char *string; | |
6876 | int *indp; | |
6877 | int flags; | |
6878 | { | |
6879 | sh_parser_state_t ps; | |
509a4430 | 6880 | sh_input_line_state_t ls; |
712f80b0 | 6881 | int orig_ind, nc, sflags, orig_eof_token, start_lineno; |
d233b485 CR |
6882 | char *ret, *ep, *ostring; |
6883 | #if defined (ALIAS) || defined (DPAREN_ARITHMETIC) | |
6884 | STRING_SAVER *saved_pushed_strings; | |
6885 | #endif | |
3185942a | 6886 | |
d233b485 | 6887 | /*debug_parser(1);*/ |
3185942a JA |
6888 | orig_ind = *indp; |
6889 | ostring = string; | |
712f80b0 | 6890 | start_lineno = line_number; |
3185942a | 6891 | |
d233b485 CR |
6892 | if (*string == 0) |
6893 | { | |
6894 | if (flags & SX_NOALLOC) | |
6895 | return (char *)NULL; | |
6896 | ||
6897 | ret = xmalloc (1); | |
6898 | ret[0] = '\0'; | |
6899 | return ret; | |
6900 | } | |
6901 | ||
712f80b0 | 6902 | /*itrace("xparse_dolparen: size = %d shell_input_line = `%s' string=`%s'", shell_input_line_size, shell_input_line, string);*/ |
3185942a JA |
6903 | sflags = SEVAL_NONINT|SEVAL_NOHIST|SEVAL_NOFREE; |
6904 | if (flags & SX_NOLONGJMP) | |
6905 | sflags |= SEVAL_NOLONGJMP; | |
6906 | save_parser_state (&ps); | |
509a4430 | 6907 | save_input_line_state (&ls); |
ac50fbac | 6908 | orig_eof_token = shell_eof_token; |
d233b485 CR |
6909 | #if defined (ALIAS) || defined (DPAREN_ARITHMETIC) |
6910 | saved_pushed_strings = pushed_string_list; /* separate parsing context */ | |
6911 | pushed_string_list = (STRING_SAVER *)NULL; | |
6912 | #endif | |
3185942a JA |
6913 | |
6914 | /*(*/ | |
6915 | parser_state |= PST_CMDSUBST|PST_EOFTOKEN; /* allow instant ')' */ /*(*/ | |
6916 | shell_eof_token = ')'; | |
a0c0a00f | 6917 | |
d233b485 CR |
6918 | /* Should we save and restore the bison/yacc lookahead token (yychar) here? |
6919 | Or only if it's not YYEMPTY? */ | |
6920 | ||
a0c0a00f | 6921 | nc = parse_string (string, "command substitution", sflags, &ep); |
3185942a | 6922 | |
d233b485 CR |
6923 | if (current_token == shell_eof_token) |
6924 | yyclearin; /* might want to clear lookahead token unconditionally */ | |
6925 | ||
3185942a | 6926 | reset_parser (); |
712f80b0 CR |
6927 | /* reset_parser() clears shell_input_line and associated variables, including |
6928 | parser_state, so we want to reset things, then restore what we need. */ | |
509a4430 | 6929 | restore_input_line_state (&ls); |
ca6a2ba4 | 6930 | |
712f80b0 CR |
6931 | shell_eof_token = orig_eof_token; |
6932 | restore_parser_state (&ps); | |
6933 | ||
d233b485 CR |
6934 | #if defined (ALIAS) || defined (DPAREN_ARITHMETIC) |
6935 | pushed_string_list = saved_pushed_strings; | |
6936 | #endif | |
6937 | ||
ca6a2ba4 | 6938 | token_to_read = 0; |
3185942a | 6939 | |
a0c0a00f | 6940 | /* If parse_string returns < 0, we need to jump to top level with the |
d233b485 CR |
6941 | negative of the return value. We abandon the rest of this input line |
6942 | first */ | |
a0c0a00f | 6943 | if (nc < 0) |
d233b485 CR |
6944 | { |
6945 | clear_shell_input_line (); /* XXX */ | |
6946 | jump_to_top_level (-nc); /* XXX */ | |
6947 | } | |
a0c0a00f | 6948 | |
3185942a JA |
6949 | /* Need to find how many characters parse_and_execute consumed, update |
6950 | *indp, if flags != 0, copy the portion of the string parsed into RET | |
d233b485 | 6951 | and return it. If flags & 1 (SX_NOALLOC) we can return NULL. */ |
3185942a JA |
6952 | |
6953 | /*(*/ | |
6954 | if (ep[-1] != ')') | |
6955 | { | |
6956 | #if DEBUG | |
6957 | if (ep[-1] != '\n') | |
6958 | itrace("xparse_dolparen:%d: ep[-1] != RPAREN (%d), ep = `%s'", line_number, ep[-1], ep); | |
6959 | #endif | |
712f80b0 | 6960 | |
3185942a JA |
6961 | while (ep > ostring && ep[-1] == '\n') ep--; |
6962 | } | |
6963 | ||
6964 | nc = ep - ostring; | |
6965 | *indp = ep - base - 1; | |
6966 | ||
712f80b0 | 6967 | /*((*/ |
3185942a JA |
6968 | #if DEBUG |
6969 | if (base[*indp] != ')') | |
6970 | itrace("xparse_dolparen:%d: base[%d] != RPAREN (%d), base = `%s'", line_number, *indp, base[*indp], base); | |
d233b485 CR |
6971 | if (*indp < orig_ind) |
6972 | itrace("xparse_dolparen:%d: *indp (%d) < orig_ind (%d), orig_string = `%s'", line_number, *indp, orig_ind, ostring); | |
3185942a JA |
6973 | #endif |
6974 | ||
712f80b0 CR |
6975 | if (base[*indp] != ')') |
6976 | { | |
6977 | /*(*/ | |
6978 | parser_error (start_lineno, _("unexpected EOF while looking for matching `%c'"), ')'); | |
6979 | jump_to_top_level (DISCARD); | |
6980 | } | |
6981 | ||
3185942a JA |
6982 | if (flags & SX_NOALLOC) |
6983 | return (char *)NULL; | |
6984 | ||
6985 | if (nc == 0) | |
6986 | { | |
6987 | ret = xmalloc (1); | |
6988 | ret[0] = '\0'; | |
6989 | } | |
6990 | else | |
6991 | ret = substring (ostring, 0, nc - 1); | |
6992 | ||
28ef6c31 JA |
6993 | return ret; |
6994 | } | |
726f6388 | 6995 | |
28ef6c31 | 6996 | #if defined (DPAREN_ARITHMETIC) || defined (ARITH_FOR_COMMAND) |
7117c2d2 JA |
6997 | /* Parse a double-paren construct. It can be either an arithmetic |
6998 | command, an arithmetic `for' command, or a nested subshell. Returns | |
6999 | the parsed token, -1 on error, or -2 if we didn't do anything and | |
7000 | should just go on. */ | |
7001 | static int | |
7002 | parse_dparen (c) | |
7003 | int c; | |
7004 | { | |
0628567a JA |
7005 | int cmdtyp, sline; |
7006 | char *wval; | |
7117c2d2 JA |
7007 | WORD_DESC *wd; |
7008 | ||
7009 | #if defined (ARITH_FOR_COMMAND) | |
7010 | if (last_read_token == FOR) | |
7011 | { | |
7012 | arith_for_lineno = line_number; | |
b80f6443 | 7013 | cmdtyp = parse_arith_cmd (&wval, 0); |
7117c2d2 JA |
7014 | if (cmdtyp == 1) |
7015 | { | |
95732b49 JA |
7016 | wd = alloc_word_desc (); |
7017 | wd->word = wval; | |
7117c2d2 | 7018 | yylval.word_list = make_word_list (wd, (WORD_LIST *)NULL); |
7117c2d2 JA |
7019 | return (ARITH_FOR_EXPRS); |
7020 | } | |
7021 | else | |
7022 | return -1; /* ERROR */ | |
7023 | } | |
7024 | #endif | |
7025 | ||
7026 | #if defined (DPAREN_ARITHMETIC) | |
7027 | if (reserved_word_acceptable (last_read_token)) | |
7028 | { | |
7029 | sline = line_number; | |
95732b49 | 7030 | |
b80f6443 | 7031 | cmdtyp = parse_arith_cmd (&wval, 0); |
7117c2d2 JA |
7032 | if (cmdtyp == 1) /* arithmetic command */ |
7033 | { | |
95732b49 JA |
7034 | wd = alloc_word_desc (); |
7035 | wd->word = wval; | |
7036 | wd->flags = W_QUOTED|W_NOSPLIT|W_NOGLOB|W_DQUOTE; | |
7117c2d2 | 7037 | yylval.word_list = make_word_list (wd, (WORD_LIST *)NULL); |
7117c2d2 JA |
7038 | return (ARITH_CMD); |
7039 | } | |
7040 | else if (cmdtyp == 0) /* nested subshell */ | |
7041 | { | |
7042 | push_string (wval, 0, (alias_t *)NULL); | |
ac50fbac | 7043 | pushed_string_list->flags = PSH_DPAREN; |
7117c2d2 JA |
7044 | if ((parser_state & PST_CASEPAT) == 0) |
7045 | parser_state |= PST_SUBSHELL; | |
7046 | return (c); | |
7047 | } | |
7048 | else /* ERROR */ | |
7049 | return -1; | |
7050 | } | |
7051 | #endif | |
7052 | ||
7053 | return -2; /* XXX */ | |
7054 | } | |
7055 | ||
28ef6c31 JA |
7056 | /* We've seen a `(('. Look for the matching `))'. If we get it, return 1. |
7057 | If not, assume it's a nested subshell for backwards compatibility and | |
7058 | return 0. In any case, put the characters we've consumed into a locally- | |
7059 | allocated buffer and make *ep point to that buffer. Return -1 on an | |
7060 | error, for example EOF. */ | |
7061 | static int | |
b80f6443 | 7062 | parse_arith_cmd (ep, adddq) |
28ef6c31 | 7063 | char **ep; |
b80f6443 | 7064 | int adddq; |
28ef6c31 JA |
7065 | { |
7066 | int exp_lineno, rval, c; | |
f73dda09 | 7067 | char *ttok, *tokstr; |
28ef6c31 | 7068 | int ttoklen; |
726f6388 | 7069 | |
28ef6c31 JA |
7070 | exp_lineno = line_number; |
7071 | ttok = parse_matched_pair (0, '(', ')', &ttoklen, 0); | |
7072 | rval = 1; | |
7073 | if (ttok == &matched_pair_error) | |
7074 | return -1; | |
7075 | /* Check that the next character is the closing right paren. If | |
7076 | not, this is a syntax error. ( */ | |
7117c2d2 JA |
7077 | c = shell_getc (0); |
7078 | if MBTEST(c != ')') | |
28ef6c31 JA |
7079 | rval = 0; |
7080 | ||
f73dda09 | 7081 | tokstr = (char *)xmalloc (ttoklen + 4); |
28ef6c31 | 7082 | |
b80f6443 JA |
7083 | /* if ADDDQ != 0 then (( ... )) -> "..." */ |
7084 | if (rval == 1 && adddq) /* arith cmd, add double quotes */ | |
726f6388 | 7085 | { |
b80f6443 JA |
7086 | tokstr[0] = '"'; |
7087 | strncpy (tokstr + 1, ttok, ttoklen - 1); | |
f73dda09 JA |
7088 | tokstr[ttoklen] = '"'; |
7089 | tokstr[ttoklen+1] = '\0'; | |
726f6388 | 7090 | } |
b80f6443 JA |
7091 | else if (rval == 1) /* arith cmd, don't add double quotes */ |
7092 | { | |
7093 | strncpy (tokstr, ttok, ttoklen - 1); | |
7094 | tokstr[ttoklen-1] = '\0'; | |
7095 | } | |
7096 | else /* nested subshell */ | |
726f6388 | 7097 | { |
b80f6443 JA |
7098 | tokstr[0] = '('; |
7099 | strncpy (tokstr + 1, ttok, ttoklen - 1); | |
f73dda09 JA |
7100 | tokstr[ttoklen] = ')'; |
7101 | tokstr[ttoklen+1] = c; | |
7102 | tokstr[ttoklen+2] = '\0'; | |
726f6388 | 7103 | } |
b80f6443 | 7104 | |
f73dda09 | 7105 | *ep = tokstr; |
28ef6c31 JA |
7106 | FREE (ttok); |
7107 | return rval; | |
726f6388 | 7108 | } |
28ef6c31 | 7109 | #endif /* DPAREN_ARITHMETIC || ARITH_FOR_COMMAND */ |
726f6388 | 7110 | |
28ef6c31 | 7111 | #if defined (COND_COMMAND) |
7117c2d2 JA |
7112 | static void |
7113 | cond_error () | |
7114 | { | |
7115 | char *etext; | |
7116 | ||
7117 | if (EOF_Reached && cond_token != COND_ERROR) /* [[ */ | |
b80f6443 | 7118 | parser_error (cond_lineno, _("unexpected EOF while looking for `]]'")); |
7117c2d2 JA |
7119 | else if (cond_token != COND_ERROR) |
7120 | { | |
7121 | if (etext = error_token_from_token (cond_token)) | |
7122 | { | |
b80f6443 | 7123 | parser_error (cond_lineno, _("syntax error in conditional expression: unexpected token `%s'"), etext); |
7117c2d2 JA |
7124 | free (etext); |
7125 | } | |
7126 | else | |
b80f6443 | 7127 | parser_error (cond_lineno, _("syntax error in conditional expression")); |
7117c2d2 JA |
7128 | } |
7129 | } | |
7130 | ||
28ef6c31 JA |
7131 | static COND_COM * |
7132 | cond_expr () | |
ccc6cda3 | 7133 | { |
28ef6c31 | 7134 | return (cond_or ()); |
ccc6cda3 JA |
7135 | } |
7136 | ||
28ef6c31 JA |
7137 | static COND_COM * |
7138 | cond_or () | |
726f6388 | 7139 | { |
28ef6c31 | 7140 | COND_COM *l, *r; |
726f6388 | 7141 | |
28ef6c31 JA |
7142 | l = cond_and (); |
7143 | if (cond_token == OR_OR) | |
7144 | { | |
7145 | r = cond_or (); | |
7146 | l = make_cond_node (COND_OR, (WORD_DESC *)NULL, l, r); | |
7147 | } | |
7148 | return l; | |
726f6388 | 7149 | } |
726f6388 | 7150 | |
28ef6c31 JA |
7151 | static COND_COM * |
7152 | cond_and () | |
726f6388 | 7153 | { |
28ef6c31 | 7154 | COND_COM *l, *r; |
726f6388 | 7155 | |
28ef6c31 JA |
7156 | l = cond_term (); |
7157 | if (cond_token == AND_AND) | |
7158 | { | |
7159 | r = cond_and (); | |
7160 | l = make_cond_node (COND_AND, (WORD_DESC *)NULL, l, r); | |
7161 | } | |
7162 | return l; | |
726f6388 JA |
7163 | } |
7164 | ||
ccc6cda3 | 7165 | static int |
28ef6c31 | 7166 | cond_skip_newlines () |
726f6388 | 7167 | { |
28ef6c31 | 7168 | while ((cond_token = read_token (READ)) == '\n') |
726f6388 | 7169 | { |
b80f6443 | 7170 | if (SHOULD_PROMPT ()) |
726f6388 JA |
7171 | prompt_again (); |
7172 | } | |
28ef6c31 | 7173 | return (cond_token); |
726f6388 JA |
7174 | } |
7175 | ||
28ef6c31 JA |
7176 | #define COND_RETURN_ERROR() \ |
7177 | do { cond_token = COND_ERROR; return ((COND_COM *)NULL); } while (0) | |
726f6388 | 7178 | |
28ef6c31 JA |
7179 | static COND_COM * |
7180 | cond_term () | |
726f6388 | 7181 | { |
28ef6c31 JA |
7182 | WORD_DESC *op; |
7183 | COND_COM *term, *tleft, *tright; | |
7184 | int tok, lineno; | |
7117c2d2 | 7185 | char *etext; |
28ef6c31 JA |
7186 | |
7187 | /* Read a token. It can be a left paren, a `!', a unary operator, or a | |
7188 | word that should be the first argument of a binary operator. Start by | |
7189 | skipping newlines, since this is a compound command. */ | |
7190 | tok = cond_skip_newlines (); | |
7191 | lineno = line_number; | |
7192 | if (tok == COND_END) | |
726f6388 | 7193 | { |
28ef6c31 | 7194 | COND_RETURN_ERROR (); |
726f6388 | 7195 | } |
28ef6c31 JA |
7196 | else if (tok == '(') |
7197 | { | |
7198 | term = cond_expr (); | |
7199 | if (cond_token != ')') | |
7200 | { | |
7201 | if (term) | |
7202 | dispose_cond_node (term); /* ( */ | |
7117c2d2 JA |
7203 | if (etext = error_token_from_token (cond_token)) |
7204 | { | |
b80f6443 | 7205 | parser_error (lineno, _("unexpected token `%s', expected `)'"), etext); |
7117c2d2 JA |
7206 | free (etext); |
7207 | } | |
7208 | else | |
b80f6443 | 7209 | parser_error (lineno, _("expected `)'")); |
28ef6c31 JA |
7210 | COND_RETURN_ERROR (); |
7211 | } | |
7212 | term = make_cond_node (COND_EXPR, (WORD_DESC *)NULL, term, (COND_COM *)NULL); | |
7213 | (void)cond_skip_newlines (); | |
7214 | } | |
7215 | else if (tok == BANG || (tok == WORD && (yylval.word->word[0] == '!' && yylval.word->word[1] == '\0'))) | |
7216 | { | |
7217 | if (tok == WORD) | |
7218 | dispose_word (yylval.word); /* not needed */ | |
7219 | term = cond_term (); | |
7220 | if (term) | |
7221 | term->flags |= CMD_INVERT_RETURN; | |
7222 | } | |
d233b485 | 7223 | else if (tok == WORD && yylval.word->word[0] == '-' && yylval.word->word[1] && yylval.word->word[2] == 0 && test_unop (yylval.word->word)) |
28ef6c31 JA |
7224 | { |
7225 | op = yylval.word; | |
7226 | tok = read_token (READ); | |
7227 | if (tok == WORD) | |
7228 | { | |
7229 | tleft = make_cond_node (COND_TERM, yylval.word, (COND_COM *)NULL, (COND_COM *)NULL); | |
7230 | term = make_cond_node (COND_UNARY, op, tleft, (COND_COM *)NULL); | |
7231 | } | |
7232 | else | |
7233 | { | |
7234 | dispose_word (op); | |
7117c2d2 JA |
7235 | if (etext = error_token_from_token (tok)) |
7236 | { | |
b80f6443 | 7237 | parser_error (line_number, _("unexpected argument `%s' to conditional unary operator"), etext); |
7117c2d2 JA |
7238 | free (etext); |
7239 | } | |
7240 | else | |
b80f6443 | 7241 | parser_error (line_number, _("unexpected argument to conditional unary operator")); |
28ef6c31 JA |
7242 | COND_RETURN_ERROR (); |
7243 | } | |
726f6388 | 7244 | |
28ef6c31 JA |
7245 | (void)cond_skip_newlines (); |
7246 | } | |
7247 | else if (tok == WORD) /* left argument to binary operator */ | |
7248 | { | |
7249 | /* lhs */ | |
7250 | tleft = make_cond_node (COND_TERM, yylval.word, (COND_COM *)NULL, (COND_COM *)NULL); | |
726f6388 | 7251 | |
28ef6c31 JA |
7252 | /* binop */ |
7253 | tok = read_token (READ); | |
7254 | if (tok == WORD && test_binop (yylval.word->word)) | |
0001803f CR |
7255 | { |
7256 | op = yylval.word; | |
7257 | if (op->word[0] == '=' && (op->word[1] == '\0' || (op->word[1] == '=' && op->word[2] == '\0'))) | |
7258 | parser_state |= PST_EXTPAT; | |
7259 | else if (op->word[0] == '!' && op->word[1] == '=' && op->word[2] == '\0') | |
7260 | parser_state |= PST_EXTPAT; | |
7261 | } | |
b80f6443 | 7262 | #if defined (COND_REGEXP) |
3185942a JA |
7263 | else if (tok == WORD && STREQ (yylval.word->word, "=~")) |
7264 | { | |
7265 | op = yylval.word; | |
7266 | parser_state |= PST_REGEXP; | |
7267 | } | |
b80f6443 | 7268 | #endif |
28ef6c31 JA |
7269 | else if (tok == '<' || tok == '>') |
7270 | op = make_word_from_token (tok); /* ( */ | |
7271 | /* There should be a check before blindly accepting the `)' that we have | |
7272 | seen the opening `('. */ | |
7273 | else if (tok == COND_END || tok == AND_AND || tok == OR_OR || tok == ')') | |
7274 | { | |
7275 | /* Special case. [[ x ]] is equivalent to [[ -n x ]], just like | |
7276 | the test command. Similarly for [[ x && expr ]] or | |
7277 | [[ x || expr ]] or [[ (x) ]]. */ | |
7278 | op = make_word ("-n"); | |
7279 | term = make_cond_node (COND_UNARY, op, tleft, (COND_COM *)NULL); | |
7280 | cond_token = tok; | |
7281 | return (term); | |
7282 | } | |
7283 | else | |
7284 | { | |
7117c2d2 JA |
7285 | if (etext = error_token_from_token (tok)) |
7286 | { | |
b80f6443 | 7287 | parser_error (line_number, _("unexpected token `%s', conditional binary operator expected"), etext); |
7117c2d2 JA |
7288 | free (etext); |
7289 | } | |
7290 | else | |
b80f6443 | 7291 | parser_error (line_number, _("conditional binary operator expected")); |
28ef6c31 JA |
7292 | dispose_cond_node (tleft); |
7293 | COND_RETURN_ERROR (); | |
7294 | } | |
726f6388 | 7295 | |
28ef6c31 | 7296 | /* rhs */ |
0001803f CR |
7297 | if (parser_state & PST_EXTPAT) |
7298 | extended_glob = 1; | |
28ef6c31 | 7299 | tok = read_token (READ); |
0001803f CR |
7300 | if (parser_state & PST_EXTPAT) |
7301 | extended_glob = global_extglob; | |
7302 | parser_state &= ~(PST_REGEXP|PST_EXTPAT); | |
7303 | ||
28ef6c31 JA |
7304 | if (tok == WORD) |
7305 | { | |
7306 | tright = make_cond_node (COND_TERM, yylval.word, (COND_COM *)NULL, (COND_COM *)NULL); | |
7307 | term = make_cond_node (COND_BINARY, op, tleft, tright); | |
7308 | } | |
7309 | else | |
7310 | { | |
7117c2d2 JA |
7311 | if (etext = error_token_from_token (tok)) |
7312 | { | |
b80f6443 | 7313 | parser_error (line_number, _("unexpected argument `%s' to conditional binary operator"), etext); |
7117c2d2 JA |
7314 | free (etext); |
7315 | } | |
7316 | else | |
b80f6443 | 7317 | parser_error (line_number, _("unexpected argument to conditional binary operator")); |
28ef6c31 JA |
7318 | dispose_cond_node (tleft); |
7319 | dispose_word (op); | |
7320 | COND_RETURN_ERROR (); | |
7321 | } | |
726f6388 | 7322 | |
28ef6c31 JA |
7323 | (void)cond_skip_newlines (); |
7324 | } | |
7325 | else | |
7326 | { | |
7327 | if (tok < 256) | |
b80f6443 | 7328 | parser_error (line_number, _("unexpected token `%c' in conditional command"), tok); |
7117c2d2 JA |
7329 | else if (etext = error_token_from_token (tok)) |
7330 | { | |
b80f6443 | 7331 | parser_error (line_number, _("unexpected token `%s' in conditional command"), etext); |
7117c2d2 JA |
7332 | free (etext); |
7333 | } | |
28ef6c31 | 7334 | else |
b80f6443 | 7335 | parser_error (line_number, _("unexpected token %d in conditional command"), tok); |
28ef6c31 JA |
7336 | COND_RETURN_ERROR (); |
7337 | } | |
7338 | return (term); | |
7339 | } | |
ccc6cda3 | 7340 | |
28ef6c31 JA |
7341 | /* This is kind of bogus -- we slip a mini recursive-descent parser in |
7342 | here to handle the conditional statement syntax. */ | |
7343 | static COMMAND * | |
7344 | parse_cond_command () | |
7345 | { | |
7346 | COND_COM *cexp; | |
ccc6cda3 | 7347 | |
0001803f | 7348 | global_extglob = extended_glob; |
28ef6c31 JA |
7349 | cexp = cond_expr (); |
7350 | return (make_cond_command (cexp)); | |
7351 | } | |
7352 | #endif | |
ccc6cda3 | 7353 | |
7117c2d2 JA |
7354 | #if defined (ARRAY_VARS) |
7355 | /* When this is called, it's guaranteed that we don't care about anything | |
d233b485 CR |
7356 | in t beyond i. We use a buffer with room for the characters we add just |
7357 | in case assignment() ends up doing something like parsing a command | |
7358 | substitution that will reallocate atoken. We don't want to write beyond | |
7359 | the end of an allocated buffer. */ | |
7117c2d2 JA |
7360 | static int |
7361 | token_is_assignment (t, i) | |
7362 | char *t; | |
7363 | int i; | |
7364 | { | |
7117c2d2 | 7365 | int r; |
d233b485 | 7366 | char *atoken; |
7117c2d2 | 7367 | |
d233b485 CR |
7368 | atoken = xmalloc (i + 3); |
7369 | memcpy (atoken, t, i); | |
7370 | atoken[i] = '='; | |
7371 | atoken[i+1] = '\0'; | |
7372 | ||
7373 | r = assignment (atoken, (parser_state & PST_COMPASSIGN) != 0); | |
7374 | ||
7375 | free (atoken); | |
7376 | ||
7377 | /* XXX - check that r == i to avoid returning false positive for | |
7378 | t containing `=' before t[i]. */ | |
7379 | return (r > 0 && r == i); | |
7117c2d2 JA |
7380 | } |
7381 | ||
95732b49 | 7382 | /* XXX - possible changes here for `+=' */ |
7117c2d2 JA |
7383 | static int |
7384 | token_is_ident (t, i) | |
7385 | char *t; | |
7386 | int i; | |
7387 | { | |
7388 | unsigned char c; | |
7389 | int r; | |
7390 | ||
7391 | c = t[i]; | |
7392 | t[i] = '\0'; | |
7393 | r = legal_identifier (t); | |
7394 | t[i] = c; | |
7395 | return r; | |
7396 | } | |
7397 | #endif | |
7398 | ||
726f6388 | 7399 | static int |
28ef6c31 JA |
7400 | read_token_word (character) |
7401 | int character; | |
726f6388 | 7402 | { |
28ef6c31 JA |
7403 | /* The value for YYLVAL when a WORD is read. */ |
7404 | WORD_DESC *the_word; | |
726f6388 | 7405 | |
28ef6c31 JA |
7406 | /* Index into the token that we are building. */ |
7407 | int token_index; | |
ccc6cda3 | 7408 | |
28ef6c31 | 7409 | /* ALL_DIGITS becomes zero when we see a non-digit. */ |
f73dda09 | 7410 | int all_digit_token; |
ccc6cda3 | 7411 | |
28ef6c31 JA |
7412 | /* DOLLAR_PRESENT becomes non-zero if we see a `$'. */ |
7413 | int dollar_present; | |
cce855bc | 7414 | |
95732b49 JA |
7415 | /* COMPOUND_ASSIGNMENT becomes non-zero if we are parsing a compound |
7416 | assignment. */ | |
7417 | int compound_assignment; | |
7418 | ||
28ef6c31 JA |
7419 | /* QUOTED becomes non-zero if we see one of ("), ('), (`), or (\). */ |
7420 | int quoted; | |
cce855bc | 7421 | |
28ef6c31 JA |
7422 | /* Non-zero means to ignore the value of the next character, and just |
7423 | to add it no matter what. */ | |
a0c0a00f | 7424 | int pass_next_character; |
cce855bc | 7425 | |
28ef6c31 JA |
7426 | /* The current delimiting character. */ |
7427 | int cd; | |
7428 | int result, peek_char; | |
7429 | char *ttok, *ttrans; | |
7430 | int ttoklen, ttranslen; | |
7117c2d2 | 7431 | intmax_t lvalue; |
ccc6cda3 | 7432 | |
28ef6c31 | 7433 | if (token_buffer_size < TOKEN_DEFAULT_INITIAL_SIZE) |
f73dda09 | 7434 | token = (char *)xrealloc (token, token_buffer_size = TOKEN_DEFAULT_INITIAL_SIZE); |
726f6388 | 7435 | |
28ef6c31 | 7436 | token_index = 0; |
f73dda09 | 7437 | all_digit_token = DIGIT (character); |
95732b49 | 7438 | dollar_present = quoted = pass_next_character = compound_assignment = 0; |
ccc6cda3 | 7439 | |
28ef6c31 | 7440 | for (;;) |
ccc6cda3 | 7441 | { |
28ef6c31 JA |
7442 | if (character == EOF) |
7443 | goto got_token; | |
726f6388 | 7444 | |
28ef6c31 | 7445 | if (pass_next_character) |
726f6388 | 7446 | { |
28ef6c31 | 7447 | pass_next_character = 0; |
3185942a | 7448 | goto got_escaped_character; |
726f6388 | 7449 | } |
726f6388 | 7450 | |
28ef6c31 | 7451 | cd = current_delimiter (dstack); |
ccc6cda3 | 7452 | |
28ef6c31 JA |
7453 | /* Handle backslashes. Quote lots of things when not inside of |
7454 | double-quotes, quote some things inside of double-quotes. */ | |
7117c2d2 | 7455 | if MBTEST(character == '\\') |
28ef6c31 JA |
7456 | { |
7457 | peek_char = shell_getc (0); | |
ccc6cda3 | 7458 | |
28ef6c31 JA |
7459 | /* Backslash-newline is ignored in all cases except |
7460 | when quoted with single quotes. */ | |
7461 | if (peek_char == '\n') | |
7462 | { | |
7463 | character = '\n'; | |
7464 | goto next_character; | |
7465 | } | |
7466 | else | |
7467 | { | |
7468 | shell_ungetc (peek_char); | |
ccc6cda3 | 7469 | |
28ef6c31 JA |
7470 | /* If the next character is to be quoted, note it now. */ |
7471 | if (cd == 0 || cd == '`' || | |
f73dda09 | 7472 | (cd == '"' && peek_char >= 0 && (sh_syntaxtab[peek_char] & CBSDQUOTE))) |
28ef6c31 | 7473 | pass_next_character++; |
ccc6cda3 | 7474 | |
28ef6c31 JA |
7475 | quoted = 1; |
7476 | goto got_character; | |
7477 | } | |
7478 | } | |
726f6388 | 7479 | |
28ef6c31 | 7480 | /* Parse a matched pair of quote characters. */ |
7117c2d2 | 7481 | if MBTEST(shellquote (character)) |
d166f048 | 7482 | { |
28ef6c31 | 7483 | push_delimiter (dstack, character); |
95732b49 | 7484 | ttok = parse_matched_pair (character, character, character, &ttoklen, (character == '`') ? P_COMMAND : 0); |
28ef6c31 JA |
7485 | pop_delimiter (dstack); |
7486 | if (ttok == &matched_pair_error) | |
7487 | return -1; /* Bail immediately. */ | |
7488 | RESIZE_MALLOCED_BUFFER (token, token_index, ttoklen + 2, | |
7489 | token_buffer_size, TOKEN_DEFAULT_GROW_SIZE); | |
7490 | token[token_index++] = character; | |
7491 | strcpy (token + token_index, ttok); | |
7492 | token_index += ttoklen; | |
f73dda09 | 7493 | all_digit_token = 0; |
d233b485 CR |
7494 | if (character != '`') |
7495 | quoted = 1; | |
28ef6c31 JA |
7496 | dollar_present |= (character == '"' && strchr (ttok, '$') != 0); |
7497 | FREE (ttok); | |
7498 | goto next_character; | |
d166f048 | 7499 | } |
726f6388 | 7500 | |
3185942a JA |
7501 | #ifdef COND_REGEXP |
7502 | /* When parsing a regexp as a single word inside a conditional command, | |
7503 | we need to special-case characters special to both the shell and | |
7504 | regular expressions. Right now, that is only '(' and '|'. */ /*)*/ | |
7505 | if MBTEST((parser_state & PST_REGEXP) && (character == '(' || character == '|')) /*)*/ | |
7506 | { | |
7507 | if (character == '|') | |
7508 | goto got_character; | |
7509 | ||
7510 | push_delimiter (dstack, character); | |
7511 | ttok = parse_matched_pair (cd, '(', ')', &ttoklen, 0); | |
7512 | pop_delimiter (dstack); | |
7513 | if (ttok == &matched_pair_error) | |
7514 | return -1; /* Bail immediately. */ | |
7515 | RESIZE_MALLOCED_BUFFER (token, token_index, ttoklen + 2, | |
7516 | token_buffer_size, TOKEN_DEFAULT_GROW_SIZE); | |
7517 | token[token_index++] = character; | |
7518 | strcpy (token + token_index, ttok); | |
7519 | token_index += ttoklen; | |
7520 | FREE (ttok); | |
7521 | dollar_present = all_digit_token = 0; | |
7522 | goto next_character; | |
7523 | } | |
7524 | #endif /* COND_REGEXP */ | |
7525 | ||
28ef6c31 JA |
7526 | #ifdef EXTENDED_GLOB |
7527 | /* Parse a ksh-style extended pattern matching specification. */ | |
3185942a | 7528 | if MBTEST(extended_glob && PATTERN_CHAR (character)) |
cce855bc | 7529 | { |
28ef6c31 | 7530 | peek_char = shell_getc (1); |
7117c2d2 | 7531 | if MBTEST(peek_char == '(') /* ) */ |
28ef6c31 JA |
7532 | { |
7533 | push_delimiter (dstack, peek_char); | |
7534 | ttok = parse_matched_pair (cd, '(', ')', &ttoklen, 0); | |
7535 | pop_delimiter (dstack); | |
7536 | if (ttok == &matched_pair_error) | |
7537 | return -1; /* Bail immediately. */ | |
ac50fbac | 7538 | RESIZE_MALLOCED_BUFFER (token, token_index, ttoklen + 3, |
28ef6c31 JA |
7539 | token_buffer_size, |
7540 | TOKEN_DEFAULT_GROW_SIZE); | |
7541 | token[token_index++] = character; | |
7542 | token[token_index++] = peek_char; | |
7543 | strcpy (token + token_index, ttok); | |
7544 | token_index += ttoklen; | |
7545 | FREE (ttok); | |
f73dda09 | 7546 | dollar_present = all_digit_token = 0; |
28ef6c31 JA |
7547 | goto next_character; |
7548 | } | |
7549 | else | |
7550 | shell_ungetc (peek_char); | |
7551 | } | |
7552 | #endif /* EXTENDED_GLOB */ | |
726f6388 | 7553 | |
28ef6c31 JA |
7554 | /* If the delimiter character is not single quote, parse some of |
7555 | the shell expansions that must be read as a single word. */ | |
7556 | if (shellexp (character)) | |
7557 | { | |
7558 | peek_char = shell_getc (1); | |
7559 | /* $(...), <(...), >(...), $((...)), ${...}, and $[...] constructs */ | |
ac50fbac | 7560 | if MBTEST(peek_char == '(' || |
28ef6c31 JA |
7561 | ((peek_char == '{' || peek_char == '[') && character == '$')) /* ) ] } */ |
7562 | { | |
7563 | if (peek_char == '{') /* } */ | |
495aee44 | 7564 | ttok = parse_matched_pair (cd, '{', '}', &ttoklen, P_FIRSTCLOSE|P_DOLBRACE); |
28ef6c31 JA |
7565 | else if (peek_char == '(') /* ) */ |
7566 | { | |
7567 | /* XXX - push and pop the `(' as a delimiter for use by | |
7568 | the command-oriented-history code. This way newlines | |
7569 | appearing in the $(...) string get added to the | |
7570 | history literally rather than causing a possibly- | |
7571 | incorrect `;' to be added. ) */ | |
7572 | push_delimiter (dstack, peek_char); | |
3185942a | 7573 | ttok = parse_comsub (cd, '(', ')', &ttoklen, P_COMMAND); |
28ef6c31 JA |
7574 | pop_delimiter (dstack); |
7575 | } | |
7576 | else | |
7577 | ttok = parse_matched_pair (cd, '[', ']', &ttoklen, 0); | |
7578 | if (ttok == &matched_pair_error) | |
7579 | return -1; /* Bail immediately. */ | |
ac50fbac | 7580 | RESIZE_MALLOCED_BUFFER (token, token_index, ttoklen + 3, |
28ef6c31 JA |
7581 | token_buffer_size, |
7582 | TOKEN_DEFAULT_GROW_SIZE); | |
7583 | token[token_index++] = character; | |
7584 | token[token_index++] = peek_char; | |
7585 | strcpy (token + token_index, ttok); | |
7586 | token_index += ttoklen; | |
7587 | FREE (ttok); | |
7588 | dollar_present = 1; | |
f73dda09 | 7589 | all_digit_token = 0; |
28ef6c31 JA |
7590 | goto next_character; |
7591 | } | |
7592 | /* This handles $'...' and $"..." new-style quoted strings. */ | |
7117c2d2 | 7593 | else if MBTEST(character == '$' && (peek_char == '\'' || peek_char == '"')) |
28ef6c31 JA |
7594 | { |
7595 | int first_line; | |
726f6388 | 7596 | |
28ef6c31 JA |
7597 | first_line = line_number; |
7598 | push_delimiter (dstack, peek_char); | |
7599 | ttok = parse_matched_pair (peek_char, peek_char, peek_char, | |
7600 | &ttoklen, | |
7601 | (peek_char == '\'') ? P_ALLOWESC : 0); | |
7602 | pop_delimiter (dstack); | |
7603 | if (ttok == &matched_pair_error) | |
7604 | return -1; | |
7605 | if (peek_char == '\'') | |
7606 | { | |
7607 | ttrans = ansiexpand (ttok, 0, ttoklen - 1, &ttranslen); | |
7608 | free (ttok); | |
95732b49 | 7609 | |
28ef6c31 JA |
7610 | /* Insert the single quotes and correctly quote any |
7611 | embedded single quotes (allowed because P_ALLOWESC was | |
7612 | passed to parse_matched_pair). */ | |
7613 | ttok = sh_single_quote (ttrans); | |
7614 | free (ttrans); | |
95732b49 | 7615 | ttranslen = strlen (ttok); |
28ef6c31 | 7616 | ttrans = ttok; |
28ef6c31 JA |
7617 | } |
7618 | else | |
7619 | { | |
0628567a | 7620 | /* Try to locale-expand the converted string. */ |
28ef6c31 JA |
7621 | ttrans = localeexpand (ttok, 0, ttoklen - 1, first_line, &ttranslen); |
7622 | free (ttok); | |
726f6388 | 7623 | |
28ef6c31 | 7624 | /* Add the double quotes back */ |
95732b49 | 7625 | ttok = sh_mkdoublequoted (ttrans, ttranslen, 0); |
28ef6c31 | 7626 | free (ttrans); |
95732b49 | 7627 | ttranslen += 2; |
28ef6c31 JA |
7628 | ttrans = ttok; |
7629 | } | |
726f6388 | 7630 | |
ac50fbac | 7631 | RESIZE_MALLOCED_BUFFER (token, token_index, ttranslen + 1, |
f73dda09 JA |
7632 | token_buffer_size, |
7633 | TOKEN_DEFAULT_GROW_SIZE); | |
7634 | strcpy (token + token_index, ttrans); | |
7635 | token_index += ttranslen; | |
7636 | FREE (ttrans); | |
7637 | quoted = 1; | |
7638 | all_digit_token = 0; | |
7639 | goto next_character; | |
7640 | } | |
7641 | /* This could eventually be extended to recognize all of the | |
7642 | shell's single-character parameter expansions, and set flags.*/ | |
7117c2d2 | 7643 | else if MBTEST(character == '$' && peek_char == '$') |
f73dda09 | 7644 | { |
f73dda09 JA |
7645 | RESIZE_MALLOCED_BUFFER (token, token_index, 3, |
7646 | token_buffer_size, | |
7647 | TOKEN_DEFAULT_GROW_SIZE); | |
ac50fbac CR |
7648 | token[token_index++] = '$'; |
7649 | token[token_index++] = peek_char; | |
f73dda09 JA |
7650 | dollar_present = 1; |
7651 | all_digit_token = 0; | |
f73dda09 JA |
7652 | goto next_character; |
7653 | } | |
7654 | else | |
7655 | shell_ungetc (peek_char); | |
7656 | } | |
28ef6c31 | 7657 | |
f73dda09 | 7658 | #if defined (ARRAY_VARS) |
3185942a JA |
7659 | /* Identify possible array subscript assignment; match [...]. If |
7660 | parser_state&PST_COMPASSIGN, we need to parse [sub]=words treating | |
7661 | `sub' as if it were enclosed in double quotes. */ | |
7662 | else if MBTEST(character == '[' && /* ] */ | |
7663 | ((token_index > 0 && assignment_acceptable (last_read_token) && token_is_ident (token, token_index)) || | |
7664 | (token_index == 0 && (parser_state&PST_COMPASSIGN)))) | |
7117c2d2 | 7665 | { |
0001803f | 7666 | ttok = parse_matched_pair (cd, '[', ']', &ttoklen, P_ARRAYSUB); |
7117c2d2 JA |
7667 | if (ttok == &matched_pair_error) |
7668 | return -1; /* Bail immediately. */ | |
7669 | RESIZE_MALLOCED_BUFFER (token, token_index, ttoklen + 2, | |
7670 | token_buffer_size, | |
7671 | TOKEN_DEFAULT_GROW_SIZE); | |
7672 | token[token_index++] = character; | |
7673 | strcpy (token + token_index, ttok); | |
7674 | token_index += ttoklen; | |
7675 | FREE (ttok); | |
7676 | all_digit_token = 0; | |
7677 | goto next_character; | |
7678 | } | |
f73dda09 | 7679 | /* Identify possible compound array variable assignment. */ |
95732b49 | 7680 | else if MBTEST(character == '=' && token_index > 0 && (assignment_acceptable (last_read_token) || (parser_state & PST_ASSIGNOK)) && token_is_assignment (token, token_index)) |
ccc6cda3 | 7681 | { |
f73dda09 | 7682 | peek_char = shell_getc (1); |
7117c2d2 | 7683 | if MBTEST(peek_char == '(') /* ) */ |
f73dda09 | 7684 | { |
7117c2d2 JA |
7685 | ttok = parse_compound_assignment (&ttoklen); |
7686 | ||
7687 | RESIZE_MALLOCED_BUFFER (token, token_index, ttoklen + 4, | |
f73dda09 JA |
7688 | token_buffer_size, |
7689 | TOKEN_DEFAULT_GROW_SIZE); | |
7117c2d2 JA |
7690 | |
7691 | token[token_index++] = '='; | |
7692 | token[token_index++] = '('; | |
7693 | if (ttok) | |
7694 | { | |
7695 | strcpy (token + token_index, ttok); | |
7696 | token_index += ttoklen; | |
7697 | } | |
7698 | token[token_index++] = ')'; | |
f73dda09 JA |
7699 | FREE (ttok); |
7700 | all_digit_token = 0; | |
95732b49 | 7701 | compound_assignment = 1; |
0628567a | 7702 | #if 1 |
f73dda09 | 7703 | goto next_character; |
95732b49 JA |
7704 | #else |
7705 | goto got_token; /* ksh93 seems to do this */ | |
7706 | #endif | |
f73dda09 JA |
7707 | } |
7708 | else | |
7709 | shell_ungetc (peek_char); | |
ccc6cda3 | 7710 | } |
f73dda09 | 7711 | #endif |
726f6388 | 7712 | |
f73dda09 JA |
7713 | /* When not parsing a multi-character word construct, shell meta- |
7714 | characters break words. */ | |
7117c2d2 | 7715 | if MBTEST(shellbreak (character)) |
f73dda09 JA |
7716 | { |
7717 | shell_ungetc (character); | |
7718 | goto got_token; | |
7719 | } | |
726f6388 | 7720 | |
ac50fbac | 7721 | got_character: |
f73dda09 | 7722 | if (character == CTLESC || character == CTLNUL) |
ac50fbac CR |
7723 | { |
7724 | RESIZE_MALLOCED_BUFFER (token, token_index, 2, token_buffer_size, | |
7725 | TOKEN_DEFAULT_GROW_SIZE); | |
7726 | token[token_index++] = CTLESC; | |
7727 | } | |
7728 | else | |
7729 | got_escaped_character: | |
7730 | RESIZE_MALLOCED_BUFFER (token, token_index, 1, token_buffer_size, | |
7731 | TOKEN_DEFAULT_GROW_SIZE); | |
d166f048 | 7732 | |
ac50fbac | 7733 | token[token_index++] = character; |
3185942a JA |
7734 | |
7735 | all_digit_token &= DIGIT (character); | |
7736 | dollar_present |= character == '$'; | |
7737 | ||
f73dda09 | 7738 | next_character: |
b80f6443 | 7739 | if (character == '\n' && SHOULD_PROMPT ()) |
f73dda09 | 7740 | prompt_again (); |
cce855bc | 7741 | |
f73dda09 JA |
7742 | /* We want to remove quoted newlines (that is, a \<newline> pair) |
7743 | unless we are within single quotes or pass_next_character is | |
7744 | set (the shell equivalent of literal-next). */ | |
7745 | cd = current_delimiter (dstack); | |
7746 | character = shell_getc (cd != '\'' && pass_next_character == 0); | |
7747 | } /* end for (;;) */ | |
cce855bc | 7748 | |
f73dda09 | 7749 | got_token: |
cce855bc | 7750 | |
ac50fbac | 7751 | /* Calls to RESIZE_MALLOCED_BUFFER ensure there is sufficient room. */ |
f73dda09 | 7752 | token[token_index] = '\0'; |
28ef6c31 | 7753 | |
f73dda09 JA |
7754 | /* Check to see what thing we should return. If the last_read_token |
7755 | is a `<', or a `&', or the character which ended this token is | |
7756 | a '>' or '<', then, and ONLY then, is this input token a NUMBER. | |
7757 | Otherwise, it is just a word, and should be returned as such. */ | |
ac50fbac CR |
7758 | if MBTEST(all_digit_token && (character == '<' || character == '>' || |
7759 | last_read_token == LESS_AND || | |
f73dda09 JA |
7760 | last_read_token == GREATER_AND)) |
7761 | { | |
7762 | if (legal_number (token, &lvalue) && (int)lvalue == lvalue) | |
ac50fbac CR |
7763 | { |
7764 | yylval.number = lvalue; | |
7765 | return (NUMBER); | |
7766 | } | |
f73dda09 | 7767 | } |
cce855bc | 7768 | |
f73dda09 | 7769 | /* Check for special case tokens. */ |
7117c2d2 | 7770 | result = (last_shell_getc_is_singlebyte) ? special_case_tokens (token) : -1; |
f73dda09 JA |
7771 | if (result >= 0) |
7772 | return result; | |
cce855bc | 7773 | |
f73dda09 JA |
7774 | #if defined (ALIAS) |
7775 | /* Posix.2 does not allow reserved words to be aliased, so check for all | |
7776 | of them, including special cases, before expanding the current token | |
7777 | as an alias. */ | |
7117c2d2 | 7778 | if MBTEST(posixly_correct) |
f73dda09 | 7779 | CHECK_FOR_RESERVED_WORD (token); |
cce855bc | 7780 | |
f73dda09 JA |
7781 | /* Aliases are expanded iff EXPAND_ALIASES is non-zero, and quoting |
7782 | inhibits alias expansion. */ | |
7783 | if (expand_aliases && quoted == 0) | |
cce855bc | 7784 | { |
f73dda09 JA |
7785 | result = alias_expand_token (token); |
7786 | if (result == RE_READ_TOKEN) | |
7787 | return (RE_READ_TOKEN); | |
7788 | else if (result == NO_EXPANSION) | |
7789 | parser_state &= ~PST_ALEXPNEXT; | |
cce855bc | 7790 | } |
28ef6c31 | 7791 | |
f73dda09 JA |
7792 | /* If not in Posix.2 mode, check for reserved words after alias |
7793 | expansion. */ | |
7117c2d2 | 7794 | if MBTEST(posixly_correct == 0) |
f73dda09 JA |
7795 | #endif |
7796 | CHECK_FOR_RESERVED_WORD (token); | |
7797 | ||
a0c0a00f | 7798 | the_word = alloc_word_desc (); |
f73dda09 JA |
7799 | the_word->word = (char *)xmalloc (1 + token_index); |
7800 | the_word->flags = 0; | |
7801 | strcpy (the_word->word, token); | |
7802 | if (dollar_present) | |
7803 | the_word->flags |= W_HASDOLLAR; | |
7804 | if (quoted) | |
0628567a JA |
7805 | the_word->flags |= W_QUOTED; /*(*/ |
7806 | if (compound_assignment && token[token_index-1] == ')') | |
95732b49 | 7807 | the_word->flags |= W_COMPASSIGN; |
f73dda09 JA |
7808 | /* A word is an assignment if it appears at the beginning of a |
7809 | simple command, or after another assignment word. This is | |
7810 | context-dependent, so it cannot be handled in the grammar. */ | |
b80f6443 | 7811 | if (assignment (token, (parser_state & PST_COMPASSIGN) != 0)) |
cce855bc | 7812 | { |
f73dda09 JA |
7813 | the_word->flags |= W_ASSIGNMENT; |
7814 | /* Don't perform word splitting on assignment statements. */ | |
b80f6443 | 7815 | if (assignment_acceptable (last_read_token) || (parser_state & PST_COMPASSIGN) != 0) |
ac50fbac CR |
7816 | { |
7817 | the_word->flags |= W_NOSPLIT; | |
7818 | if (parser_state & PST_COMPASSIGN) | |
7819 | the_word->flags |= W_NOGLOB; /* XXX - W_NOBRACE? */ | |
7820 | } | |
cce855bc | 7821 | } |
28ef6c31 | 7822 | |
95732b49 JA |
7823 | if (command_token_position (last_read_token)) |
7824 | { | |
7825 | struct builtin *b; | |
7826 | b = builtin_address_internal (token, 0); | |
7827 | if (b && (b->flags & ASSIGNMENT_BUILTIN)) | |
0628567a JA |
7828 | parser_state |= PST_ASSIGNOK; |
7829 | else if (STREQ (token, "eval") || STREQ (token, "let")) | |
7830 | parser_state |= PST_ASSIGNOK; | |
95732b49 JA |
7831 | } |
7832 | ||
f73dda09 JA |
7833 | yylval.word = the_word; |
7834 | ||
d233b485 | 7835 | /* should we check that quoted == 0 as well? */ |
0001803f CR |
7836 | if (token[0] == '{' && token[token_index-1] == '}' && |
7837 | (character == '<' || character == '>')) | |
7838 | { | |
7839 | /* can use token; already copied to the_word */ | |
7840 | token[token_index-1] = '\0'; | |
ac50fbac | 7841 | #if defined (ARRAY_VARS) |
a0c0a00f | 7842 | if (legal_identifier (token+1) || valid_array_reference (token+1, 0)) |
ac50fbac | 7843 | #else |
0001803f | 7844 | if (legal_identifier (token+1)) |
ac50fbac | 7845 | #endif |
0001803f CR |
7846 | { |
7847 | strcpy (the_word->word, token+1); | |
d233b485 CR |
7848 | /* itrace("read_token_word: returning REDIR_WORD for %s", the_word->word); */ |
7849 | yylval.word = the_word; /* accommodate recursive call */ | |
0001803f CR |
7850 | return (REDIR_WORD); |
7851 | } | |
d233b485 CR |
7852 | else |
7853 | /* valid_array_reference can call the parser recursively; need to | |
7854 | make sure that yylval.word doesn't change if we are going to | |
7855 | return WORD or ASSIGNMENT_WORD */ | |
7856 | yylval.word = the_word; | |
0001803f CR |
7857 | } |
7858 | ||
f73dda09 JA |
7859 | result = ((the_word->flags & (W_ASSIGNMENT|W_NOSPLIT)) == (W_ASSIGNMENT|W_NOSPLIT)) |
7860 | ? ASSIGNMENT_WORD : WORD; | |
7861 | ||
b80f6443 | 7862 | switch (last_read_token) |
cce855bc | 7863 | { |
b80f6443 | 7864 | case FUNCTION: |
f73dda09 JA |
7865 | parser_state |= PST_ALLOWOPNBRC; |
7866 | function_dstart = line_number; | |
b80f6443 JA |
7867 | break; |
7868 | case CASE: | |
7869 | case SELECT: | |
7870 | case FOR: | |
7871 | if (word_top < MAX_CASE_NEST) | |
7872 | word_top++; | |
7873 | word_lineno[word_top] = line_number; | |
d233b485 | 7874 | expecting_in_token++; |
b80f6443 | 7875 | break; |
cce855bc | 7876 | } |
cce855bc | 7877 | |
f73dda09 | 7878 | return (result); |
28ef6c31 | 7879 | } |
cce855bc | 7880 | |
f73dda09 JA |
7881 | /* Return 1 if TOKSYM is a token that after being read would allow |
7882 | a reserved word to be seen, else 0. */ | |
7883 | static int | |
7884 | reserved_word_acceptable (toksym) | |
7885 | int toksym; | |
7886 | { | |
7117c2d2 JA |
7887 | switch (toksym) |
7888 | { | |
7889 | case '\n': | |
7890 | case ';': | |
7891 | case '(': | |
7892 | case ')': | |
7893 | case '|': | |
7894 | case '&': | |
7895 | case '{': | |
7896 | case '}': /* XXX */ | |
7897 | case AND_AND: | |
7898 | case BANG: | |
0001803f | 7899 | case BAR_AND: |
7117c2d2 JA |
7900 | case DO: |
7901 | case DONE: | |
7902 | case ELIF: | |
7903 | case ELSE: | |
7904 | case ESAC: | |
7905 | case FI: | |
7906 | case IF: | |
7907 | case OR_OR: | |
7908 | case SEMI_SEMI: | |
3185942a JA |
7909 | case SEMI_AND: |
7910 | case SEMI_SEMI_AND: | |
7117c2d2 JA |
7911 | case THEN: |
7912 | case TIME: | |
7913 | case TIMEOPT: | |
495aee44 | 7914 | case TIMEIGN: |
3185942a | 7915 | case COPROC: |
7117c2d2 JA |
7916 | case UNTIL: |
7917 | case WHILE: | |
7918 | case 0: | |
7919 | return 1; | |
7920 | default: | |
3185942a JA |
7921 | #if defined (COPROCESS_SUPPORT) |
7922 | if (last_read_token == WORD && token_before_that == COPROC) | |
7923 | return 1; | |
7924 | #endif | |
495aee44 CR |
7925 | if (last_read_token == WORD && token_before_that == FUNCTION) |
7926 | return 1; | |
7117c2d2 JA |
7927 | return 0; |
7928 | } | |
f73dda09 | 7929 | } |
7117c2d2 | 7930 | |
f73dda09 JA |
7931 | /* Return the index of TOKEN in the alist of reserved words, or -1 if |
7932 | TOKEN is not a shell reserved word. */ | |
7933 | int | |
7934 | find_reserved_word (tokstr) | |
7935 | char *tokstr; | |
7936 | { | |
7937 | int i; | |
7938 | for (i = 0; word_token_alist[i].word; i++) | |
7939 | if (STREQ (tokstr, word_token_alist[i].word)) | |
7940 | return i; | |
7941 | return -1; | |
7942 | } | |
ccc6cda3 | 7943 | |
ac50fbac CR |
7944 | /* An interface to let the rest of the shell (primarily the completion |
7945 | system) know what the parser is expecting. */ | |
7946 | int | |
7947 | parser_in_command_position () | |
7948 | { | |
7949 | return (command_token_position (last_read_token)); | |
7950 | } | |
7951 | ||
f73dda09 JA |
7952 | #if 0 |
7953 | #if defined (READLINE) | |
7954 | /* Called after each time readline is called. This insures that whatever | |
7955 | the new prompt string is gets propagated to readline's local prompt | |
7956 | variable. */ | |
7957 | static void | |
7958 | reset_readline_prompt () | |
7959 | { | |
7960 | char *temp_prompt; | |
726f6388 | 7961 | |
f73dda09 JA |
7962 | if (prompt_string_pointer) |
7963 | { | |
7964 | temp_prompt = (*prompt_string_pointer) | |
7965 | ? decode_prompt_string (*prompt_string_pointer) | |
7966 | : (char *)NULL; | |
726f6388 | 7967 | |
f73dda09 JA |
7968 | if (temp_prompt == 0) |
7969 | { | |
7970 | temp_prompt = (char *)xmalloc (1); | |
7971 | temp_prompt[0] = '\0'; | |
7972 | } | |
ccc6cda3 | 7973 | |
f73dda09 JA |
7974 | FREE (current_readline_prompt); |
7975 | current_readline_prompt = temp_prompt; | |
7976 | } | |
7977 | } | |
7978 | #endif /* READLINE */ | |
7979 | #endif /* 0 */ | |
726f6388 | 7980 | |
f73dda09 JA |
7981 | #if defined (HISTORY) |
7982 | /* A list of tokens which can be followed by newlines, but not by | |
7983 | semi-colons. When concatenating multiple lines of history, the | |
7984 | newline separator for such tokens is replaced with a space. */ | |
3185942a | 7985 | static const int no_semi_successors[] = { |
f73dda09 | 7986 | '\n', '{', '(', ')', ';', '&', '|', |
3185942a JA |
7987 | CASE, DO, ELSE, IF, SEMI_SEMI, SEMI_AND, SEMI_SEMI_AND, THEN, UNTIL, |
7988 | WHILE, AND_AND, OR_OR, IN, | |
f73dda09 JA |
7989 | 0 |
7990 | }; | |
ccc6cda3 | 7991 | |
f73dda09 JA |
7992 | /* If we are not within a delimited expression, try to be smart |
7993 | about which separators can be semi-colons and which must be | |
7994 | newlines. Returns the string that should be added into the | |
495aee44 CR |
7995 | history entry. LINE is the line we're about to add; it helps |
7996 | make some more intelligent decisions in certain cases. */ | |
f73dda09 | 7997 | char * |
495aee44 CR |
7998 | history_delimiting_chars (line) |
7999 | const char *line; | |
f73dda09 | 8000 | { |
495aee44 | 8001 | static int last_was_heredoc = 0; /* was the last entry the start of a here document? */ |
f73dda09 | 8002 | register int i; |
726f6388 | 8003 | |
495aee44 CR |
8004 | if ((parser_state & PST_HEREDOC) == 0) |
8005 | last_was_heredoc = 0; | |
8006 | ||
f73dda09 JA |
8007 | if (dstack.delimiter_depth != 0) |
8008 | return ("\n"); | |
3185942a JA |
8009 | |
8010 | /* We look for current_command_line_count == 2 because we are looking to | |
8011 | add the first line of the body of the here document (the second line | |
495aee44 CR |
8012 | of the command). We also keep LAST_WAS_HEREDOC as a private sentinel |
8013 | variable to note when we think we added the first line of a here doc | |
8014 | (the one with a "<<" somewhere in it) */ | |
3185942a | 8015 | if (parser_state & PST_HEREDOC) |
495aee44 CR |
8016 | { |
8017 | if (last_was_heredoc) | |
8018 | { | |
8019 | last_was_heredoc = 0; | |
8020 | return "\n"; | |
8021 | } | |
a0c0a00f | 8022 | return (here_doc_first_line ? "\n" : ""); |
495aee44 | 8023 | } |
3185942a | 8024 | |
509a4430 CR |
8025 | if (parser_state & PST_COMPASSIGN) |
8026 | return (" "); | |
8027 | ||
f73dda09 JA |
8028 | /* First, handle some special cases. */ |
8029 | /*(*/ | |
8030 | /* If we just read `()', assume it's a function definition, and don't | |
8031 | add a semicolon. If the token before the `)' was not `(', and we're | |
8032 | not in the midst of parsing a case statement, assume it's a | |
8033 | parenthesized command and add the semicolon. */ | |
8034 | /*)(*/ | |
8035 | if (token_before_that == ')') | |
8036 | { | |
8037 | if (two_tokens_ago == '(') /*)*/ /* function def */ | |
8038 | return " "; | |
8039 | /* This does not work for subshells inside case statement | |
8040 | command lists. It's a suboptimal solution. */ | |
8041 | else if (parser_state & PST_CASESTMT) /* case statement pattern */ | |
8042 | return " "; | |
a0c0a00f | 8043 | else |
f73dda09 JA |
8044 | return "; "; /* (...) subshell */ |
8045 | } | |
8046 | else if (token_before_that == WORD && two_tokens_ago == FUNCTION) | |
8047 | return " "; /* function def using `function name' without `()' */ | |
726f6388 | 8048 | |
495aee44 CR |
8049 | /* If we're not in a here document, but we think we're about to parse one, |
8050 | and we would otherwise return a `;', return a newline to delimit the | |
8051 | line with the here-doc delimiter */ | |
8052 | else if ((parser_state & PST_HEREDOC) == 0 && current_command_line_count > 1 && last_read_token == '\n' && strstr (line, "<<")) | |
8053 | { | |
8054 | last_was_heredoc = 1; | |
8055 | return "\n"; | |
8056 | } | |
a0c0a00f CR |
8057 | else if ((parser_state & PST_HEREDOC) == 0 && current_command_line_count > 1 && need_here_doc > 0) |
8058 | return "\n"; | |
f73dda09 JA |
8059 | else if (token_before_that == WORD && two_tokens_ago == FOR) |
8060 | { | |
8061 | /* Tricky. `for i\nin ...' should not have a semicolon, but | |
8062 | `for i\ndo ...' should. We do what we can. */ | |
3185942a | 8063 | for (i = shell_input_line_index; whitespace (shell_input_line[i]); i++) |
f73dda09 JA |
8064 | ; |
8065 | if (shell_input_line[i] && shell_input_line[i] == 'i' && shell_input_line[i+1] == 'n') | |
8066 | return " "; | |
8067 | return ";"; | |
8068 | } | |
95732b49 JA |
8069 | else if (two_tokens_ago == CASE && token_before_that == WORD && (parser_state & PST_CASESTMT)) |
8070 | return " "; | |
726f6388 | 8071 | |
f73dda09 JA |
8072 | for (i = 0; no_semi_successors[i]; i++) |
8073 | { | |
8074 | if (token_before_that == no_semi_successors[i]) | |
8075 | return (" "); | |
8076 | } | |
726f6388 | 8077 | |
d233b485 CR |
8078 | if (line_isblank (line)) |
8079 | return (""); | |
8080 | ||
f73dda09 JA |
8081 | return ("; "); |
8082 | } | |
8083 | #endif /* HISTORY */ | |
ccc6cda3 | 8084 | |
f73dda09 JA |
8085 | /* Issue a prompt, or prepare to issue a prompt when the next character |
8086 | is read. */ | |
8087 | static void | |
8088 | prompt_again () | |
8089 | { | |
8090 | char *temp_prompt; | |
726f6388 | 8091 | |
0001803f | 8092 | if (interactive == 0 || expanding_alias ()) /* XXX */ |
f73dda09 | 8093 | return; |
726f6388 | 8094 | |
f73dda09 JA |
8095 | ps1_prompt = get_string_value ("PS1"); |
8096 | ps2_prompt = get_string_value ("PS2"); | |
28ef6c31 | 8097 | |
a0c0a00f CR |
8098 | ps0_prompt = get_string_value ("PS0"); |
8099 | ||
f73dda09 JA |
8100 | if (!prompt_string_pointer) |
8101 | prompt_string_pointer = &ps1_prompt; | |
28ef6c31 | 8102 | |
f73dda09 JA |
8103 | temp_prompt = *prompt_string_pointer |
8104 | ? decode_prompt_string (*prompt_string_pointer) | |
8105 | : (char *)NULL; | |
28ef6c31 | 8106 | |
f73dda09 JA |
8107 | if (temp_prompt == 0) |
8108 | { | |
8109 | temp_prompt = (char *)xmalloc (1); | |
8110 | temp_prompt[0] = '\0'; | |
28ef6c31 | 8111 | } |
28ef6c31 | 8112 | |
f73dda09 JA |
8113 | current_prompt_string = *prompt_string_pointer; |
8114 | prompt_string_pointer = &ps2_prompt; | |
28ef6c31 | 8115 | |
f73dda09 JA |
8116 | #if defined (READLINE) |
8117 | if (!no_line_editing) | |
ccc6cda3 | 8118 | { |
f73dda09 JA |
8119 | FREE (current_readline_prompt); |
8120 | current_readline_prompt = temp_prompt; | |
ccc6cda3 JA |
8121 | } |
8122 | else | |
f73dda09 | 8123 | #endif /* READLINE */ |
ccc6cda3 | 8124 | { |
f73dda09 JA |
8125 | FREE (current_decoded_prompt); |
8126 | current_decoded_prompt = temp_prompt; | |
ccc6cda3 JA |
8127 | } |
8128 | } | |
726f6388 | 8129 | |
28ef6c31 | 8130 | int |
f73dda09 | 8131 | get_current_prompt_level () |
bb70624e | 8132 | { |
f73dda09 | 8133 | return ((current_prompt_string && current_prompt_string == ps2_prompt) ? 2 : 1); |
28ef6c31 | 8134 | } |
bb70624e | 8135 | |
f73dda09 JA |
8136 | void |
8137 | set_current_prompt_level (x) | |
8138 | int x; | |
8139 | { | |
8140 | prompt_string_pointer = (x == 2) ? &ps2_prompt : &ps1_prompt; | |
8141 | current_prompt_string = *prompt_string_pointer; | |
8142 | } | |
8143 | ||
28ef6c31 | 8144 | static void |
f73dda09 | 8145 | print_prompt () |
28ef6c31 | 8146 | { |
f73dda09 JA |
8147 | fprintf (stderr, "%s", current_decoded_prompt); |
8148 | fflush (stderr); | |
8149 | } | |
bb70624e | 8150 | |
d233b485 CR |
8151 | #if defined (HISTORY) |
8152 | /* The history library increments the history offset as soon as it stores | |
8153 | the first line of a potentially multi-line command, so we compensate | |
8154 | here by returning one fewer when appropriate. */ | |
8155 | static int | |
8156 | prompt_history_number (pmt) | |
8157 | char *pmt; | |
8158 | { | |
8159 | int ret; | |
8160 | ||
8161 | ret = history_number (); | |
8162 | if (ret == 1) | |
8163 | return ret; | |
8164 | ||
8165 | if (pmt == ps1_prompt) /* are we expanding $PS1? */ | |
8166 | return ret; | |
8167 | else if (pmt == ps2_prompt && command_oriented_history == 0) | |
8168 | return ret; /* not command oriented history */ | |
8169 | else if (pmt == ps2_prompt && command_oriented_history && current_command_first_line_saved) | |
8170 | return ret - 1; | |
8171 | else | |
8172 | return ret - 1; /* PS0, PS4, ${var@P}, PS2 other cases */ | |
8173 | } | |
8174 | #endif | |
8175 | ||
f73dda09 JA |
8176 | /* Return a string which will be printed as a prompt. The string |
8177 | may contain special characters which are decoded as follows: | |
726f6388 | 8178 | |
f73dda09 | 8179 | \a bell (ascii 07) |
f73dda09 | 8180 | \d the date in Day Mon Date format |
7117c2d2 | 8181 | \e escape (ascii 033) |
f73dda09 JA |
8182 | \h the hostname up to the first `.' |
8183 | \H the hostname | |
8184 | \j the number of active jobs | |
8185 | \l the basename of the shell's tty device name | |
8186 | \n CRLF | |
7117c2d2 | 8187 | \r CR |
f73dda09 JA |
8188 | \s the name of the shell |
8189 | \t the time in 24-hour hh:mm:ss format | |
8190 | \T the time in 12-hour hh:mm:ss format | |
7117c2d2 JA |
8191 | \@ the time in 12-hour hh:mm am/pm format |
8192 | \A the time in 24-hour hh:mm format | |
8193 | \D{fmt} the result of passing FMT to strftime(3) | |
8194 | \u your username | |
f73dda09 JA |
8195 | \v the version of bash (e.g., 2.00) |
8196 | \V the release of bash, version + patchlevel (e.g., 2.00.0) | |
8197 | \w the current working directory | |
8198 | \W the last element of $PWD | |
f73dda09 | 8199 | \! the history number of this command |
7117c2d2 | 8200 | \# the command number of this command |
f73dda09 JA |
8201 | \$ a $ or a # if you are root |
8202 | \nnn character code nnn in octal | |
8203 | \\ a backslash | |
8204 | \[ begin a sequence of non-printing chars | |
8205 | \] end a sequence of non-printing chars | |
8206 | */ | |
8207 | #define PROMPT_GROWTH 48 | |
8208 | char * | |
8209 | decode_prompt_string (string) | |
8210 | char *string; | |
8211 | { | |
8212 | WORD_LIST *list; | |
d233b485 | 8213 | char *result, *t, *orig_string; |
f73dda09 | 8214 | struct dstack save_dstack; |
0001803f | 8215 | int last_exit_value, last_comsub_pid; |
f73dda09 | 8216 | #if defined (PROMPT_STRING_DECODE) |
a0c0a00f CR |
8217 | size_t result_size; |
8218 | int result_index; | |
0628567a | 8219 | int c, n, i; |
a0c0a00f | 8220 | char *temp, *t_host, octal_string[4]; |
7117c2d2 | 8221 | struct tm *tm; |
f73dda09 | 8222 | time_t the_time; |
7117c2d2 JA |
8223 | char timebuf[128]; |
8224 | char *timefmt; | |
726f6388 | 8225 | |
f73dda09 JA |
8226 | result = (char *)xmalloc (result_size = PROMPT_GROWTH); |
8227 | result[result_index = 0] = 0; | |
8228 | temp = (char *)NULL; | |
d233b485 | 8229 | orig_string = string; |
28ef6c31 | 8230 | |
f73dda09 JA |
8231 | while (c = *string++) |
8232 | { | |
8233 | if (posixly_correct && c == '!') | |
bb70624e | 8234 | { |
f73dda09 | 8235 | if (*string == '!') |
28ef6c31 | 8236 | { |
f73dda09 JA |
8237 | temp = savestring ("!"); |
8238 | goto add_string; | |
8239 | } | |
8240 | else | |
8241 | { | |
8242 | #if !defined (HISTORY) | |
8243 | temp = savestring ("1"); | |
8244 | #else /* HISTORY */ | |
d233b485 | 8245 | temp = itos (prompt_history_number (orig_string)); |
f73dda09 JA |
8246 | #endif /* HISTORY */ |
8247 | string--; /* add_string increments string again. */ | |
8248 | goto add_string; | |
28ef6c31 | 8249 | } |
28ef6c31 | 8250 | } |
f73dda09 JA |
8251 | if (c == '\\') |
8252 | { | |
8253 | c = *string; | |
726f6388 | 8254 | |
f73dda09 JA |
8255 | switch (c) |
8256 | { | |
8257 | case '0': | |
8258 | case '1': | |
8259 | case '2': | |
8260 | case '3': | |
8261 | case '4': | |
8262 | case '5': | |
8263 | case '6': | |
8264 | case '7': | |
8265 | strncpy (octal_string, string, 3); | |
8266 | octal_string[3] = '\0'; | |
726f6388 | 8267 | |
f73dda09 JA |
8268 | n = read_octal (octal_string); |
8269 | temp = (char *)xmalloc (3); | |
726f6388 | 8270 | |
f73dda09 JA |
8271 | if (n == CTLESC || n == CTLNUL) |
8272 | { | |
8273 | temp[0] = CTLESC; | |
8274 | temp[1] = n; | |
8275 | temp[2] = '\0'; | |
8276 | } | |
8277 | else if (n == -1) | |
8278 | { | |
8279 | temp[0] = '\\'; | |
8280 | temp[1] = '\0'; | |
8281 | } | |
8282 | else | |
8283 | { | |
8284 | temp[0] = n; | |
8285 | temp[1] = '\0'; | |
8286 | } | |
28ef6c31 | 8287 | |
f73dda09 JA |
8288 | for (c = 0; n != -1 && c < 3 && ISOCTAL (*string); c++) |
8289 | string++; | |
28ef6c31 | 8290 | |
7117c2d2 | 8291 | c = 0; /* tested at add_string: */ |
f73dda09 | 8292 | goto add_string; |
28ef6c31 | 8293 | |
f73dda09 | 8294 | case 'd': |
7117c2d2 | 8295 | case 't': |
f73dda09 JA |
8296 | case 'T': |
8297 | case '@': | |
8298 | case 'A': | |
8299 | /* Make the current time/date into a string. */ | |
7117c2d2 | 8300 | (void) time (&the_time); |
509a4430 CR |
8301 | #if defined (HAVE_TZSET) |
8302 | sv_tz ("TZ"); /* XXX -- just make sure */ | |
8303 | #endif | |
7117c2d2 JA |
8304 | tm = localtime (&the_time); |
8305 | ||
8306 | if (c == 'd') | |
8307 | n = strftime (timebuf, sizeof (timebuf), "%a %b %d", tm); | |
8308 | else if (c == 't') | |
8309 | n = strftime (timebuf, sizeof (timebuf), "%H:%M:%S", tm); | |
8310 | else if (c == 'T') | |
8311 | n = strftime (timebuf, sizeof (timebuf), "%I:%M:%S", tm); | |
8312 | else if (c == '@') | |
8313 | n = strftime (timebuf, sizeof (timebuf), "%I:%M %p", tm); | |
8314 | else if (c == 'A') | |
8315 | n = strftime (timebuf, sizeof (timebuf), "%H:%M", tm); | |
8316 | ||
b80f6443 JA |
8317 | if (n == 0) |
8318 | timebuf[0] = '\0'; | |
8319 | else | |
8320 | timebuf[sizeof(timebuf) - 1] = '\0'; | |
8321 | ||
7117c2d2 JA |
8322 | temp = savestring (timebuf); |
8323 | goto add_string; | |
726f6388 | 8324 | |
7117c2d2 JA |
8325 | case 'D': /* strftime format */ |
8326 | if (string[1] != '{') /* } */ | |
8327 | goto not_escape; | |
726f6388 | 8328 | |
7117c2d2 JA |
8329 | (void) time (&the_time); |
8330 | tm = localtime (&the_time); | |
8331 | string += 2; /* skip { */ | |
8332 | timefmt = xmalloc (strlen (string) + 3); | |
8333 | for (t = timefmt; *string && *string != '}'; ) | |
8334 | *t++ = *string++; | |
8335 | *t = '\0'; | |
8336 | c = *string; /* tested at add_string */ | |
8337 | if (timefmt[0] == '\0') | |
f73dda09 | 8338 | { |
7117c2d2 JA |
8339 | timefmt[0] = '%'; |
8340 | timefmt[1] = 'X'; /* locale-specific current time */ | |
8341 | timefmt[2] = '\0'; | |
f73dda09 | 8342 | } |
7117c2d2 JA |
8343 | n = strftime (timebuf, sizeof (timebuf), timefmt, tm); |
8344 | free (timefmt); | |
8345 | ||
b80f6443 JA |
8346 | if (n == 0) |
8347 | timebuf[0] = '\0'; | |
8348 | else | |
8349 | timebuf[sizeof(timebuf) - 1] = '\0'; | |
8350 | ||
7117c2d2 JA |
8351 | if (promptvars || posixly_correct) |
8352 | /* Make sure that expand_prompt_string is called with a | |
8353 | second argument of Q_DOUBLE_QUOTES if we use this | |
8354 | function here. */ | |
8355 | temp = sh_backslash_quote_for_double_quotes (timebuf); | |
8356 | else | |
8357 | temp = savestring (timebuf); | |
f73dda09 | 8358 | goto add_string; |
7117c2d2 | 8359 | |
f73dda09 JA |
8360 | case 'n': |
8361 | temp = (char *)xmalloc (3); | |
8362 | temp[0] = no_line_editing ? '\n' : '\r'; | |
8363 | temp[1] = no_line_editing ? '\0' : '\n'; | |
8364 | temp[2] = '\0'; | |
8365 | goto add_string; | |
ccc6cda3 | 8366 | |
f73dda09 JA |
8367 | case 's': |
8368 | temp = base_pathname (shell_name); | |
a0c0a00f CR |
8369 | /* Try to quote anything the user can set in the file system */ |
8370 | if (promptvars || posixly_correct) | |
8371 | temp = sh_backslash_quote_for_double_quotes (temp); | |
8372 | else | |
8373 | temp = savestring (temp); | |
f73dda09 | 8374 | goto add_string; |
726f6388 | 8375 | |
f73dda09 JA |
8376 | case 'v': |
8377 | case 'V': | |
7117c2d2 | 8378 | temp = (char *)xmalloc (16); |
f73dda09 JA |
8379 | if (c == 'v') |
8380 | strcpy (temp, dist_version); | |
8381 | else | |
8382 | sprintf (temp, "%s.%d", dist_version, patch_level); | |
8383 | goto add_string; | |
bb70624e | 8384 | |
f73dda09 JA |
8385 | case 'w': |
8386 | case 'W': | |
8387 | { | |
8388 | /* Use the value of PWD because it is much more efficient. */ | |
0628567a | 8389 | char t_string[PATH_MAX]; |
f73dda09 | 8390 | int tlen; |
28ef6c31 | 8391 | |
f73dda09 | 8392 | temp = get_string_value ("PWD"); |
ccc6cda3 | 8393 | |
f73dda09 JA |
8394 | if (temp == 0) |
8395 | { | |
8396 | if (getcwd (t_string, sizeof(t_string)) == 0) | |
8397 | { | |
8398 | t_string[0] = '.'; | |
8399 | tlen = 1; | |
8400 | } | |
8401 | else | |
8402 | tlen = strlen (t_string); | |
8403 | } | |
8404 | else | |
8405 | { | |
8406 | tlen = sizeof (t_string) - 1; | |
8407 | strncpy (t_string, temp, tlen); | |
8408 | } | |
8409 | t_string[tlen] = '\0'; | |
726f6388 | 8410 | |
0001803f CR |
8411 | #if defined (MACOSX) |
8412 | /* Convert from "fs" format to "input" format */ | |
8413 | temp = fnx_fromfs (t_string, strlen (t_string)); | |
8414 | if (temp != t_string) | |
8415 | strcpy (t_string, temp); | |
8416 | #endif | |
8417 | ||
f73dda09 JA |
8418 | #define ROOT_PATH(x) ((x)[0] == '/' && (x)[1] == 0) |
8419 | #define DOUBLE_SLASH_ROOT(x) ((x)[0] == '/' && (x)[1] == '/' && (x)[2] == 0) | |
b80f6443 | 8420 | /* Abbreviate \W as ~ if $PWD == $HOME */ |
95732b49 | 8421 | if (c == 'W' && (((t = get_string_value ("HOME")) == 0) || STREQ (t, t_string) == 0)) |
f73dda09 JA |
8422 | { |
8423 | if (ROOT_PATH (t_string) == 0 && DOUBLE_SLASH_ROOT (t_string) == 0) | |
8424 | { | |
8425 | t = strrchr (t_string, '/'); | |
8426 | if (t) | |
495aee44 | 8427 | memmove (t_string, t + 1, strlen (t)); /* strlen(t) to copy NULL */ |
f73dda09 JA |
8428 | } |
8429 | } | |
8430 | #undef ROOT_PATH | |
8431 | #undef DOUBLE_SLASH_ROOT | |
8432 | else | |
ac50fbac CR |
8433 | { |
8434 | /* polite_directory_format is guaranteed to return a string | |
8435 | no longer than PATH_MAX - 1 characters. */ | |
8436 | temp = polite_directory_format (t_string); | |
8437 | if (temp != t_string) | |
8438 | strcpy (t_string, temp); | |
8439 | } | |
726f6388 | 8440 | |
3185942a | 8441 | temp = trim_pathname (t_string, PATH_MAX - 1); |
f73dda09 JA |
8442 | /* If we're going to be expanding the prompt string later, |
8443 | quote the directory name. */ | |
8444 | if (promptvars || posixly_correct) | |
8445 | /* Make sure that expand_prompt_string is called with a | |
7117c2d2 | 8446 | second argument of Q_DOUBLE_QUOTES if we use this |
f73dda09 JA |
8447 | function here. */ |
8448 | temp = sh_backslash_quote_for_double_quotes (t_string); | |
8449 | else | |
8450 | temp = savestring (t_string); | |
726f6388 | 8451 | |
f73dda09 JA |
8452 | goto add_string; |
8453 | } | |
726f6388 | 8454 | |
f73dda09 JA |
8455 | case 'u': |
8456 | if (current_user.user_name == 0) | |
8457 | get_current_user_info (); | |
8458 | temp = savestring (current_user.user_name); | |
8459 | goto add_string; | |
726f6388 | 8460 | |
f73dda09 JA |
8461 | case 'h': |
8462 | case 'H': | |
a0c0a00f CR |
8463 | t_host = savestring (current_host_name); |
8464 | if (c == 'h' && (t = (char *)strchr (t_host, '.'))) | |
f73dda09 | 8465 | *t = '\0'; |
a0c0a00f CR |
8466 | if (promptvars || posixly_correct) |
8467 | /* Make sure that expand_prompt_string is called with a | |
8468 | second argument of Q_DOUBLE_QUOTES if we use this | |
8469 | function here. */ | |
8470 | temp = sh_backslash_quote_for_double_quotes (t_host); | |
8471 | else | |
8472 | temp = savestring (t_host); | |
8473 | free (t_host); | |
f73dda09 | 8474 | goto add_string; |
726f6388 | 8475 | |
f73dda09 | 8476 | case '#': |
d233b485 CR |
8477 | n = current_command_number; |
8478 | /* If we have already incremented current_command_number (PS4, | |
8479 | ${var@P}), compensate */ | |
8480 | if (orig_string != ps0_prompt && orig_string != ps1_prompt && orig_string != ps2_prompt) | |
8481 | n--; | |
8482 | temp = itos (n); | |
f73dda09 | 8483 | goto add_string; |
28ef6c31 | 8484 | |
f73dda09 JA |
8485 | case '!': |
8486 | #if !defined (HISTORY) | |
8487 | temp = savestring ("1"); | |
8488 | #else /* HISTORY */ | |
d233b485 | 8489 | temp = itos (prompt_history_number (orig_string)); |
f73dda09 JA |
8490 | #endif /* HISTORY */ |
8491 | goto add_string; | |
726f6388 | 8492 | |
f73dda09 JA |
8493 | case '$': |
8494 | t = temp = (char *)xmalloc (3); | |
8495 | if ((promptvars || posixly_correct) && (current_user.euid != 0)) | |
8496 | *t++ = '\\'; | |
8497 | *t++ = current_user.euid == 0 ? '#' : '$'; | |
8498 | *t = '\0'; | |
8499 | goto add_string; | |
726f6388 | 8500 | |
f73dda09 JA |
8501 | case 'j': |
8502 | temp = itos (count_all_jobs ()); | |
8503 | goto add_string; | |
28ef6c31 | 8504 | |
f73dda09 JA |
8505 | case 'l': |
8506 | #if defined (HAVE_TTYNAME) | |
8507 | temp = (char *)ttyname (fileno (stdin)); | |
8508 | t = temp ? base_pathname (temp) : "tty"; | |
8509 | temp = savestring (t); | |
8510 | #else | |
8511 | temp = savestring ("tty"); | |
8512 | #endif /* !HAVE_TTYNAME */ | |
8513 | goto add_string; | |
726f6388 | 8514 | |
f73dda09 JA |
8515 | #if defined (READLINE) |
8516 | case '[': | |
8517 | case ']': | |
b80f6443 JA |
8518 | if (no_line_editing) |
8519 | { | |
8520 | string++; | |
8521 | break; | |
8522 | } | |
f73dda09 | 8523 | temp = (char *)xmalloc (3); |
0628567a JA |
8524 | n = (c == '[') ? RL_PROMPT_START_IGNORE : RL_PROMPT_END_IGNORE; |
8525 | i = 0; | |
8526 | if (n == CTLESC || n == CTLNUL) | |
8527 | temp[i++] = CTLESC; | |
8528 | temp[i++] = n; | |
8529 | temp[i] = '\0'; | |
f73dda09 JA |
8530 | goto add_string; |
8531 | #endif /* READLINE */ | |
ccc6cda3 | 8532 | |
f73dda09 | 8533 | case '\\': |
f73dda09 JA |
8534 | case 'a': |
8535 | case 'e': | |
7117c2d2 | 8536 | case 'r': |
f73dda09 | 8537 | temp = (char *)xmalloc (2); |
7117c2d2 JA |
8538 | if (c == 'a') |
8539 | temp[0] = '\07'; | |
8540 | else if (c == 'e') | |
8541 | temp[0] = '\033'; | |
8542 | else if (c == 'r') | |
8543 | temp[0] = '\r'; | |
8544 | else /* (c == '\\') */ | |
8545 | temp[0] = c; | |
f73dda09 JA |
8546 | temp[1] = '\0'; |
8547 | goto add_string; | |
8548 | ||
8549 | default: | |
7117c2d2 | 8550 | not_escape: |
f73dda09 JA |
8551 | temp = (char *)xmalloc (3); |
8552 | temp[0] = '\\'; | |
8553 | temp[1] = c; | |
8554 | temp[2] = '\0'; | |
8555 | ||
8556 | add_string: | |
8557 | if (c) | |
8558 | string++; | |
8559 | result = | |
8560 | sub_append_string (temp, result, &result_index, &result_size); | |
8561 | temp = (char *)NULL; /* Freed in sub_append_string (). */ | |
8562 | result[result_index] = '\0'; | |
8563 | break; | |
8564 | } | |
8565 | } | |
8566 | else | |
8567 | { | |
8568 | RESIZE_MALLOCED_BUFFER (result, result_index, 3, result_size, PROMPT_GROWTH); | |
a0c0a00f CR |
8569 | /* dequote_string should take care of removing this if we are not |
8570 | performing the rest of the word expansions. */ | |
8571 | if (c == CTLESC || c == CTLNUL) | |
8572 | result[result_index++] = CTLESC; | |
f73dda09 JA |
8573 | result[result_index++] = c; |
8574 | result[result_index] = '\0'; | |
8575 | } | |
8576 | } | |
8577 | #else /* !PROMPT_STRING_DECODE */ | |
8578 | result = savestring (string); | |
8579 | #endif /* !PROMPT_STRING_DECODE */ | |
8580 | ||
8581 | /* Save the delimiter stack and point `dstack' to temp space so any | |
8582 | command substitutions in the prompt string won't result in screwing | |
8583 | up the parser's quoting state. */ | |
8584 | save_dstack = dstack; | |
8585 | dstack = temp_dstack; | |
8586 | dstack.delimiter_depth = 0; | |
8587 | ||
8588 | /* Perform variable and parameter expansion and command substitution on | |
8589 | the prompt string. */ | |
8590 | if (promptvars || posixly_correct) | |
8591 | { | |
8592 | last_exit_value = last_command_exit_value; | |
0001803f | 8593 | last_comsub_pid = last_command_subst_pid; |
3185942a | 8594 | list = expand_prompt_string (result, Q_DOUBLE_QUOTES, 0); |
f73dda09 JA |
8595 | free (result); |
8596 | result = string_list (list); | |
8597 | dispose_words (list); | |
8598 | last_command_exit_value = last_exit_value; | |
0001803f | 8599 | last_command_subst_pid = last_comsub_pid; |
f73dda09 JA |
8600 | } |
8601 | else | |
8602 | { | |
8603 | t = dequote_string (result); | |
8604 | free (result); | |
8605 | result = t; | |
8606 | } | |
8607 | ||
8608 | dstack = save_dstack; | |
8609 | ||
8610 | return (result); | |
8611 | } | |
8612 | ||
7117c2d2 JA |
8613 | /************************************************ |
8614 | * * | |
8615 | * ERROR HANDLING * | |
8616 | * * | |
8617 | ************************************************/ | |
8618 | ||
f73dda09 JA |
8619 | /* Report a syntax error, and restart the parser. Call here for fatal |
8620 | errors. */ | |
8621 | int | |
8622 | yyerror (msg) | |
8623 | const char *msg; | |
726f6388 | 8624 | { |
f73dda09 JA |
8625 | report_syntax_error ((char *)NULL); |
8626 | reset_parser (); | |
8627 | return (0); | |
8628 | } | |
8629 | ||
7117c2d2 | 8630 | static char * |
0628567a JA |
8631 | error_token_from_token (tok) |
8632 | int tok; | |
7117c2d2 JA |
8633 | { |
8634 | char *t; | |
8635 | ||
0628567a | 8636 | if (t = find_token_in_alist (tok, word_token_alist, 0)) |
7117c2d2 JA |
8637 | return t; |
8638 | ||
0628567a | 8639 | if (t = find_token_in_alist (tok, other_token_alist, 0)) |
7117c2d2 JA |
8640 | return t; |
8641 | ||
8642 | t = (char *)NULL; | |
8643 | /* This stuff is dicy and needs closer inspection */ | |
8644 | switch (current_token) | |
8645 | { | |
8646 | case WORD: | |
8647 | case ASSIGNMENT_WORD: | |
8648 | if (yylval.word) | |
8649 | t = savestring (yylval.word->word); | |
8650 | break; | |
8651 | case NUMBER: | |
8652 | t = itos (yylval.number); | |
8653 | break; | |
8654 | case ARITH_CMD: | |
8655 | if (yylval.word_list) | |
8656 | t = string_list (yylval.word_list); | |
8657 | break; | |
8658 | case ARITH_FOR_EXPRS: | |
8659 | if (yylval.word_list) | |
8660 | t = string_list_internal (yylval.word_list, " ; "); | |
8661 | break; | |
8662 | case COND_CMD: | |
8663 | t = (char *)NULL; /* punt */ | |
8664 | break; | |
8665 | } | |
8666 | ||
8667 | return t; | |
8668 | } | |
8669 | ||
8670 | static char * | |
8671 | error_token_from_text () | |
8672 | { | |
8673 | char *msg, *t; | |
8674 | int token_end, i; | |
8675 | ||
8676 | t = shell_input_line; | |
8677 | i = shell_input_line_index; | |
8678 | token_end = 0; | |
8679 | msg = (char *)NULL; | |
8680 | ||
8681 | if (i && t[i] == '\0') | |
8682 | i--; | |
8683 | ||
8684 | while (i && (whitespace (t[i]) || t[i] == '\n')) | |
8685 | i--; | |
8686 | ||
8687 | if (i) | |
8688 | token_end = i + 1; | |
8689 | ||
8690 | while (i && (member (t[i], " \n\t;|&") == 0)) | |
8691 | i--; | |
8692 | ||
8693 | while (i != token_end && (whitespace (t[i]) || t[i] == '\n')) | |
8694 | i++; | |
8695 | ||
8696 | /* Return our idea of the offending token. */ | |
8697 | if (token_end || (i == 0 && token_end == 0)) | |
8698 | { | |
8699 | if (token_end) | |
8700 | msg = substring (t, i, token_end); | |
8701 | else /* one-character token */ | |
8702 | { | |
8703 | msg = (char *)xmalloc (2); | |
8704 | msg[0] = t[i]; | |
8705 | msg[1] = '\0'; | |
8706 | } | |
8707 | } | |
8708 | ||
8709 | return (msg); | |
8710 | } | |
8711 | ||
8712 | static void | |
8713 | print_offending_line () | |
8714 | { | |
8715 | char *msg; | |
8716 | int token_end; | |
8717 | ||
8718 | msg = savestring (shell_input_line); | |
8719 | token_end = strlen (msg); | |
8720 | while (token_end && msg[token_end - 1] == '\n') | |
8721 | msg[--token_end] = '\0'; | |
8722 | ||
8723 | parser_error (line_number, "`%s'", msg); | |
8724 | free (msg); | |
8725 | } | |
8726 | ||
f73dda09 JA |
8727 | /* Report a syntax error with line numbers, etc. |
8728 | Call here for recoverable errors. If you have a message to print, | |
8729 | then place it in MESSAGE, otherwise pass NULL and this will figure | |
8730 | out an appropriate message for you. */ | |
8731 | static void | |
8732 | report_syntax_error (message) | |
8733 | char *message; | |
726f6388 | 8734 | { |
495aee44 | 8735 | char *msg, *p; |
f73dda09 JA |
8736 | |
8737 | if (message) | |
8738 | { | |
8739 | parser_error (line_number, "%s", message); | |
8740 | if (interactive && EOF_Reached) | |
8741 | EOF_Reached = 0; | |
0001803f | 8742 | last_command_exit_value = parse_and_execute_level ? EX_BADSYNTAX : EX_BADUSAGE; |
712f80b0 | 8743 | set_pipestatus_from_exit (last_command_exit_value); |
f73dda09 JA |
8744 | return; |
8745 | } | |
8746 | ||
8747 | /* If the line of input we're reading is not null, try to find the | |
7117c2d2 JA |
8748 | objectionable token. First, try to figure out what token the |
8749 | parser's complaining about by looking at current_token. */ | |
8750 | if (current_token != 0 && EOF_Reached == 0 && (msg = error_token_from_token (current_token))) | |
f73dda09 | 8751 | { |
495aee44 CR |
8752 | if (ansic_shouldquote (msg)) |
8753 | { | |
8754 | p = ansic_quote (msg, 0, NULL); | |
8755 | free (msg); | |
8756 | msg = p; | |
8757 | } | |
b80f6443 | 8758 | parser_error (line_number, _("syntax error near unexpected token `%s'"), msg); |
7117c2d2 | 8759 | free (msg); |
f73dda09 | 8760 | |
7117c2d2 JA |
8761 | if (interactive == 0) |
8762 | print_offending_line (); | |
f73dda09 | 8763 | |
0001803f | 8764 | last_command_exit_value = parse_and_execute_level ? EX_BADSYNTAX : EX_BADUSAGE; |
712f80b0 | 8765 | set_pipestatus_from_exit (last_command_exit_value); |
7117c2d2 JA |
8766 | return; |
8767 | } | |
f73dda09 | 8768 | |
7117c2d2 JA |
8769 | /* If looking at the current token doesn't prove fruitful, try to find the |
8770 | offending token by analyzing the text of the input line near the current | |
8771 | input line index and report what we find. */ | |
8772 | if (shell_input_line && *shell_input_line) | |
8773 | { | |
8774 | msg = error_token_from_text (); | |
8775 | if (msg) | |
f73dda09 | 8776 | { |
b80f6443 | 8777 | parser_error (line_number, _("syntax error near `%s'"), msg); |
7117c2d2 | 8778 | free (msg); |
f73dda09 JA |
8779 | } |
8780 | ||
8781 | /* If not interactive, print the line containing the error. */ | |
8782 | if (interactive == 0) | |
7117c2d2 | 8783 | print_offending_line (); |
f73dda09 JA |
8784 | } |
8785 | else | |
8786 | { | |
b80f6443 | 8787 | msg = EOF_Reached ? _("syntax error: unexpected end of file") : _("syntax error"); |
f73dda09 JA |
8788 | parser_error (line_number, "%s", msg); |
8789 | /* When the shell is interactive, this file uses EOF_Reached | |
8790 | only for error reporting. Other mechanisms are used to | |
8791 | decide whether or not to exit. */ | |
8792 | if (interactive && EOF_Reached) | |
8793 | EOF_Reached = 0; | |
8794 | } | |
7117c2d2 | 8795 | |
0001803f | 8796 | last_command_exit_value = parse_and_execute_level ? EX_BADSYNTAX : EX_BADUSAGE; |
712f80b0 | 8797 | set_pipestatus_from_exit (last_command_exit_value); |
f73dda09 JA |
8798 | } |
8799 | ||
8800 | /* ??? Needed function. ??? We have to be able to discard the constructs | |
8801 | created during parsing. In the case of error, we want to return | |
8802 | allocated objects to the memory pool. In the case of no error, we want | |
8803 | to throw away the information about where the allocated objects live. | |
7117c2d2 | 8804 | (dispose_command () will actually free the command.) */ |
f73dda09 JA |
8805 | static void |
8806 | discard_parser_constructs (error_p) | |
8807 | int error_p; | |
28ef6c31 | 8808 | { |
f73dda09 JA |
8809 | } |
8810 | ||
7117c2d2 JA |
8811 | /************************************************ |
8812 | * * | |
8813 | * EOF HANDLING * | |
8814 | * * | |
8815 | ************************************************/ | |
8816 | ||
f73dda09 JA |
8817 | /* Do that silly `type "bye" to exit' stuff. You know, "ignoreeof". */ |
8818 | ||
8819 | /* A flag denoting whether or not ignoreeof is set. */ | |
8820 | int ignoreeof = 0; | |
8821 | ||
8822 | /* The number of times that we have encountered an EOF character without | |
8823 | another character intervening. When this gets above the limit, the | |
8824 | shell terminates. */ | |
8825 | int eof_encountered = 0; | |
8826 | ||
8827 | /* The limit for eof_encountered. */ | |
8828 | int eof_encountered_limit = 10; | |
8829 | ||
8830 | /* If we have EOF as the only input unit, this user wants to leave | |
8831 | the shell. If the shell is not interactive, then just leave. | |
8832 | Otherwise, if ignoreeof is set, and we haven't done this the | |
8833 | required number of times in a row, print a message. */ | |
8834 | static void | |
8835 | handle_eof_input_unit () | |
28ef6c31 | 8836 | { |
f73dda09 JA |
8837 | if (interactive) |
8838 | { | |
8839 | /* shell.c may use this to decide whether or not to write out the | |
8840 | history, among other things. We use it only for error reporting | |
8841 | in this file. */ | |
8842 | if (EOF_Reached) | |
8843 | EOF_Reached = 0; | |
8844 | ||
8845 | /* If the user wants to "ignore" eof, then let her do so, kind of. */ | |
8846 | if (ignoreeof) | |
8847 | { | |
8848 | if (eof_encountered < eof_encountered_limit) | |
8849 | { | |
b80f6443 | 8850 | fprintf (stderr, _("Use \"%s\" to leave the shell.\n"), |
f73dda09 JA |
8851 | login_shell ? "logout" : "exit"); |
8852 | eof_encountered++; | |
7117c2d2 JA |
8853 | /* Reset the parsing state. */ |
8854 | last_read_token = current_token = '\n'; | |
f73dda09 JA |
8855 | /* Reset the prompt string to be $PS1. */ |
8856 | prompt_string_pointer = (char **)NULL; | |
8857 | prompt_again (); | |
f73dda09 JA |
8858 | return; |
8859 | } | |
8860 | } | |
8861 | ||
8862 | /* In this case EOF should exit the shell. Do it now. */ | |
8863 | reset_parser (); | |
712f80b0 CR |
8864 | |
8865 | last_shell_builtin = this_shell_builtin; | |
8866 | this_shell_builtin = exit_builtin; | |
f73dda09 | 8867 | exit_builtin ((WORD_LIST *)NULL); |
726f6388 | 8868 | } |
f73dda09 | 8869 | else |
726f6388 | 8870 | { |
f73dda09 JA |
8871 | /* We don't write history files, etc., for non-interactive shells. */ |
8872 | EOF_Reached = 1; | |
8873 | } | |
8874 | } | |
8875 | ||
7117c2d2 JA |
8876 | /************************************************ |
8877 | * * | |
8878 | * STRING PARSING FUNCTIONS * | |
8879 | * * | |
8880 | ************************************************/ | |
8881 | ||
8882 | /* It's very important that these two functions treat the characters | |
8883 | between ( and ) identically. */ | |
8884 | ||
f73dda09 JA |
8885 | static WORD_LIST parse_string_error; |
8886 | ||
8887 | /* Take a string and run it through the shell parser, returning the | |
8888 | resultant word list. Used by compound array assignment. */ | |
8889 | WORD_LIST * | |
b80f6443 | 8890 | parse_string_to_word_list (s, flags, whom) |
f73dda09 | 8891 | char *s; |
b80f6443 | 8892 | int flags; |
f73dda09 JA |
8893 | const char *whom; |
8894 | { | |
8895 | WORD_LIST *wl; | |
7117c2d2 | 8896 | int tok, orig_current_token, orig_line_number, orig_input_terminator; |
f73dda09 | 8897 | int orig_line_count; |
7117c2d2 | 8898 | int old_echo_input, old_expand_aliases; |
f73dda09 JA |
8899 | #if defined (HISTORY) |
8900 | int old_remember_on_history, old_history_expansion_inhibited; | |
bb70624e | 8901 | #endif |
f73dda09 JA |
8902 | |
8903 | #if defined (HISTORY) | |
8904 | old_remember_on_history = remember_on_history; | |
8905 | # if defined (BANG_HISTORY) | |
8906 | old_history_expansion_inhibited = history_expansion_inhibited; | |
8907 | # endif | |
8908 | bash_history_disable (); | |
bb70624e | 8909 | #endif |
f73dda09 JA |
8910 | |
8911 | orig_line_number = line_number; | |
8912 | orig_line_count = current_command_line_count; | |
8913 | orig_input_terminator = shell_input_line_terminator; | |
7117c2d2 JA |
8914 | old_echo_input = echo_input_at_read; |
8915 | old_expand_aliases = expand_aliases; | |
f73dda09 JA |
8916 | |
8917 | push_stream (1); | |
7117c2d2 | 8918 | last_read_token = WORD; /* WORD to allow reserved words here */ |
f73dda09 | 8919 | current_command_line_count = 0; |
7117c2d2 | 8920 | echo_input_at_read = expand_aliases = 0; |
f73dda09 JA |
8921 | |
8922 | with_input_from_string (s, whom); | |
8923 | wl = (WORD_LIST *)NULL; | |
b80f6443 JA |
8924 | |
8925 | if (flags & 1) | |
3185942a | 8926 | parser_state |= PST_COMPASSIGN|PST_REPARSE; |
b80f6443 | 8927 | |
f73dda09 JA |
8928 | while ((tok = read_token (READ)) != yacc_EOF) |
8929 | { | |
8930 | if (tok == '\n' && *bash_input.location.string == '\0') | |
8931 | break; | |
8932 | if (tok == '\n') /* Allow newlines in compound assignments */ | |
8933 | continue; | |
8934 | if (tok != WORD && tok != ASSIGNMENT_WORD) | |
8935 | { | |
8936 | line_number = orig_line_number + line_number - 1; | |
7117c2d2 JA |
8937 | orig_current_token = current_token; |
8938 | current_token = tok; | |
95732b49 | 8939 | yyerror (NULL); /* does the right thing */ |
7117c2d2 | 8940 | current_token = orig_current_token; |
f73dda09 JA |
8941 | if (wl) |
8942 | dispose_words (wl); | |
8943 | wl = &parse_string_error; | |
8944 | break; | |
8945 | } | |
8946 | wl = make_word_list (yylval.word, wl); | |
bb70624e | 8947 | } |
f73dda09 JA |
8948 | |
8949 | last_read_token = '\n'; | |
8950 | pop_stream (); | |
8951 | ||
8952 | #if defined (HISTORY) | |
8953 | remember_on_history = old_remember_on_history; | |
8954 | # if defined (BANG_HISTORY) | |
8955 | history_expansion_inhibited = old_history_expansion_inhibited; | |
8956 | # endif /* BANG_HISTORY */ | |
8957 | #endif /* HISTORY */ | |
8958 | ||
7117c2d2 JA |
8959 | echo_input_at_read = old_echo_input; |
8960 | expand_aliases = old_expand_aliases; | |
8961 | ||
f73dda09 JA |
8962 | current_command_line_count = orig_line_count; |
8963 | shell_input_line_terminator = orig_input_terminator; | |
8964 | ||
b80f6443 | 8965 | if (flags & 1) |
3185942a | 8966 | parser_state &= ~(PST_COMPASSIGN|PST_REPARSE); |
b80f6443 | 8967 | |
f73dda09 | 8968 | if (wl == &parse_string_error) |
bb70624e | 8969 | { |
712f80b0 | 8970 | set_exit_status (EXECUTION_FAILURE); |
f73dda09 JA |
8971 | if (interactive_shell == 0 && posixly_correct) |
8972 | jump_to_top_level (FORCE_EOF); | |
8973 | else | |
8974 | jump_to_top_level (DISCARD); | |
bb70624e | 8975 | } |
f73dda09 JA |
8976 | |
8977 | return (REVERSE_LIST (wl, WORD_LIST *)); | |
bb70624e | 8978 | } |
7117c2d2 JA |
8979 | |
8980 | static char * | |
8981 | parse_compound_assignment (retlenp) | |
8982 | int *retlenp; | |
8983 | { | |
8984 | WORD_LIST *wl, *rl; | |
0628567a | 8985 | int tok, orig_line_number, orig_token_size, orig_last_token, assignok; |
7117c2d2 JA |
8986 | char *saved_token, *ret; |
8987 | ||
8988 | saved_token = token; | |
8989 | orig_token_size = token_buffer_size; | |
8990 | orig_line_number = line_number; | |
0628567a | 8991 | orig_last_token = last_read_token; |
7117c2d2 JA |
8992 | |
8993 | last_read_token = WORD; /* WORD to allow reserved words here */ | |
8994 | ||
8995 | token = (char *)NULL; | |
8996 | token_buffer_size = 0; | |
8997 | ||
0628567a JA |
8998 | assignok = parser_state&PST_ASSIGNOK; /* XXX */ |
8999 | ||
7117c2d2 | 9000 | wl = (WORD_LIST *)NULL; /* ( */ |
b80f6443 JA |
9001 | parser_state |= PST_COMPASSIGN; |
9002 | ||
7117c2d2 JA |
9003 | while ((tok = read_token (READ)) != ')') |
9004 | { | |
9005 | if (tok == '\n') /* Allow newlines in compound assignments */ | |
b80f6443 JA |
9006 | { |
9007 | if (SHOULD_PROMPT ()) | |
9008 | prompt_again (); | |
9009 | continue; | |
9010 | } | |
7117c2d2 JA |
9011 | if (tok != WORD && tok != ASSIGNMENT_WORD) |
9012 | { | |
9013 | current_token = tok; /* for error reporting */ | |
9014 | if (tok == yacc_EOF) /* ( */ | |
b80f6443 | 9015 | parser_error (orig_line_number, _("unexpected EOF while looking for matching `)'")); |
7117c2d2 | 9016 | else |
95732b49 | 9017 | yyerror(NULL); /* does the right thing */ |
7117c2d2 JA |
9018 | if (wl) |
9019 | dispose_words (wl); | |
9020 | wl = &parse_string_error; | |
9021 | break; | |
9022 | } | |
9023 | wl = make_word_list (yylval.word, wl); | |
9024 | } | |
9025 | ||
9026 | FREE (token); | |
9027 | token = saved_token; | |
9028 | token_buffer_size = orig_token_size; | |
9029 | ||
b80f6443 JA |
9030 | parser_state &= ~PST_COMPASSIGN; |
9031 | ||
7117c2d2 JA |
9032 | if (wl == &parse_string_error) |
9033 | { | |
712f80b0 | 9034 | set_exit_status (EXECUTION_FAILURE); |
7117c2d2 JA |
9035 | last_read_token = '\n'; /* XXX */ |
9036 | if (interactive_shell == 0 && posixly_correct) | |
9037 | jump_to_top_level (FORCE_EOF); | |
9038 | else | |
9039 | jump_to_top_level (DISCARD); | |
9040 | } | |
9041 | ||
0628567a JA |
9042 | last_read_token = orig_last_token; /* XXX - was WORD? */ |
9043 | ||
7117c2d2 JA |
9044 | if (wl) |
9045 | { | |
9046 | rl = REVERSE_LIST (wl, WORD_LIST *); | |
9047 | ret = string_list (rl); | |
9048 | dispose_words (rl); | |
9049 | } | |
9050 | else | |
9051 | ret = (char *)NULL; | |
9052 | ||
9053 | if (retlenp) | |
9054 | *retlenp = (ret && *ret) ? strlen (ret) : 0; | |
0628567a JA |
9055 | |
9056 | if (assignok) | |
9057 | parser_state |= PST_ASSIGNOK; | |
9058 | ||
7117c2d2 JA |
9059 | return ret; |
9060 | } | |
9061 | ||
b80f6443 JA |
9062 | /************************************************ |
9063 | * * | |
9064 | * SAVING AND RESTORING PARTIAL PARSE STATE * | |
9065 | * * | |
9066 | ************************************************/ | |
9067 | ||
9068 | sh_parser_state_t * | |
9069 | save_parser_state (ps) | |
9070 | sh_parser_state_t *ps; | |
9071 | { | |
b80f6443 | 9072 | if (ps == 0) |
95732b49 | 9073 | ps = (sh_parser_state_t *)xmalloc (sizeof (sh_parser_state_t)); |
b80f6443 JA |
9074 | if (ps == 0) |
9075 | return ((sh_parser_state_t *)NULL); | |
9076 | ||
9077 | ps->parser_state = parser_state; | |
9078 | ps->token_state = save_token_state (); | |
9079 | ||
9080 | ps->input_line_terminator = shell_input_line_terminator; | |
9081 | ps->eof_encountered = eof_encountered; | |
9082 | ||
495aee44 CR |
9083 | ps->prompt_string_pointer = prompt_string_pointer; |
9084 | ||
b80f6443 JA |
9085 | ps->current_command_line_count = current_command_line_count; |
9086 | ||
9087 | #if defined (HISTORY) | |
9088 | ps->remember_on_history = remember_on_history; | |
9089 | # if defined (BANG_HISTORY) | |
9090 | ps->history_expansion_inhibited = history_expansion_inhibited; | |
9091 | # endif | |
9092 | #endif | |
9093 | ||
9094 | ps->last_command_exit_value = last_command_exit_value; | |
9095 | #if defined (ARRAY_VARS) | |
495aee44 | 9096 | ps->pipestatus = save_pipestatus_array (); |
b80f6443 JA |
9097 | #endif |
9098 | ||
9099 | ps->last_shell_builtin = last_shell_builtin; | |
9100 | ps->this_shell_builtin = this_shell_builtin; | |
9101 | ||
9102 | ps->expand_aliases = expand_aliases; | |
9103 | ps->echo_input_at_read = echo_input_at_read; | |
daefb2c5 | 9104 | ps->need_here_doc = need_here_doc; |
a0c0a00f CR |
9105 | ps->here_doc_first_line = here_doc_first_line; |
9106 | ||
a0c0a00f CR |
9107 | if (need_here_doc == 0) |
9108 | ps->redir_stack[0] = 0; | |
9109 | else | |
9110 | memcpy (ps->redir_stack, redir_stack, sizeof (redir_stack[0]) * HEREDOC_MAX); | |
b80f6443 | 9111 | |
509a4430 CR |
9112 | ps->token = token; |
9113 | ps->token_buffer_size = token_buffer_size; | |
9114 | /* Force reallocation on next call to read_token_word */ | |
9115 | token = 0; | |
9116 | token_buffer_size = 0; | |
9117 | ||
b80f6443 JA |
9118 | return (ps); |
9119 | } | |
9120 | ||
9121 | void | |
9122 | restore_parser_state (ps) | |
9123 | sh_parser_state_t *ps; | |
9124 | { | |
a0c0a00f CR |
9125 | int i; |
9126 | ||
b80f6443 JA |
9127 | if (ps == 0) |
9128 | return; | |
9129 | ||
9130 | parser_state = ps->parser_state; | |
9131 | if (ps->token_state) | |
9132 | { | |
9133 | restore_token_state (ps->token_state); | |
9134 | free (ps->token_state); | |
9135 | } | |
9136 | ||
9137 | shell_input_line_terminator = ps->input_line_terminator; | |
9138 | eof_encountered = ps->eof_encountered; | |
9139 | ||
495aee44 CR |
9140 | prompt_string_pointer = ps->prompt_string_pointer; |
9141 | ||
b80f6443 JA |
9142 | current_command_line_count = ps->current_command_line_count; |
9143 | ||
9144 | #if defined (HISTORY) | |
9145 | remember_on_history = ps->remember_on_history; | |
9146 | # if defined (BANG_HISTORY) | |
9147 | history_expansion_inhibited = ps->history_expansion_inhibited; | |
9148 | # endif | |
9149 | #endif | |
9150 | ||
9151 | last_command_exit_value = ps->last_command_exit_value; | |
9152 | #if defined (ARRAY_VARS) | |
495aee44 | 9153 | restore_pipestatus_array (ps->pipestatus); |
b80f6443 JA |
9154 | #endif |
9155 | ||
9156 | last_shell_builtin = ps->last_shell_builtin; | |
9157 | this_shell_builtin = ps->this_shell_builtin; | |
9158 | ||
9159 | expand_aliases = ps->expand_aliases; | |
9160 | echo_input_at_read = ps->echo_input_at_read; | |
daefb2c5 | 9161 | need_here_doc = ps->need_here_doc; |
a0c0a00f CR |
9162 | here_doc_first_line = ps->here_doc_first_line; |
9163 | ||
9164 | #if 0 | |
9165 | for (i = 0; i < HEREDOC_MAX; i++) | |
9166 | redir_stack[i] = ps->redir_stack[i]; | |
9167 | #else | |
9168 | if (need_here_doc == 0) | |
9169 | redir_stack[0] = 0; | |
9170 | else | |
9171 | memcpy (redir_stack, ps->redir_stack, sizeof (redir_stack[0]) * HEREDOC_MAX); | |
9172 | #endif | |
509a4430 CR |
9173 | |
9174 | FREE (token); | |
9175 | token = ps->token; | |
9176 | token_buffer_size = ps->token_buffer_size; | |
9177 | } | |
9178 | ||
9179 | sh_input_line_state_t * | |
9180 | save_input_line_state (ls) | |
9181 | sh_input_line_state_t *ls; | |
9182 | { | |
9183 | if (ls == 0) | |
9184 | ls = (sh_input_line_state_t *)xmalloc (sizeof (sh_input_line_state_t)); | |
9185 | if (ls == 0) | |
9186 | return ((sh_input_line_state_t *)NULL); | |
9187 | ||
9188 | ls->input_line = shell_input_line; | |
9189 | ls->input_line_size = shell_input_line_size; | |
9190 | ls->input_line_len = shell_input_line_len; | |
9191 | ls->input_line_index = shell_input_line_index; | |
9192 | ||
712f80b0 CR |
9193 | #if defined (HANDLE_MULTIBYTE) |
9194 | ls->input_property = shell_input_line_property; | |
9195 | ls->input_propsize = shell_input_line_propsize; | |
9196 | #endif | |
9197 | ||
509a4430 CR |
9198 | /* force reallocation */ |
9199 | shell_input_line = 0; | |
9200 | shell_input_line_size = shell_input_line_len = shell_input_line_index = 0; | |
ac50fbac | 9201 | |
712f80b0 CR |
9202 | #if defined (HANDLE_MULTIBYTE) |
9203 | shell_input_line_property = 0; | |
9204 | shell_input_line_propsize = 0; | |
9205 | #endif | |
9206 | ||
ac50fbac | 9207 | return ls; |
509a4430 CR |
9208 | } |
9209 | ||
9210 | void | |
9211 | restore_input_line_state (ls) | |
9212 | sh_input_line_state_t *ls; | |
9213 | { | |
9214 | FREE (shell_input_line); | |
9215 | shell_input_line = ls->input_line; | |
9216 | shell_input_line_size = ls->input_line_size; | |
9217 | shell_input_line_len = ls->input_line_len; | |
9218 | shell_input_line_index = ls->input_line_index; | |
9219 | ||
712f80b0 CR |
9220 | #if defined (HANDLE_MULTIBYTE) |
9221 | FREE (shell_input_line_property); | |
9222 | shell_input_line_property = ls->input_property; | |
9223 | shell_input_line_propsize = ls->input_propsize; | |
9224 | #endif | |
9225 | ||
9226 | #if 0 | |
509a4430 | 9227 | set_line_mbstate (); |
712f80b0 | 9228 | #endif |
b80f6443 JA |
9229 | } |
9230 | ||
7117c2d2 JA |
9231 | /************************************************ |
9232 | * * | |
9233 | * MULTIBYTE CHARACTER HANDLING * | |
9234 | * * | |
9235 | ************************************************/ | |
9236 | ||
9237 | #if defined (HANDLE_MULTIBYTE) | |
d233b485 CR |
9238 | |
9239 | /* We don't let the property buffer get larger than this unless the line is */ | |
9240 | #define MAX_PROPSIZE 32768 | |
9241 | ||
7117c2d2 JA |
9242 | static void |
9243 | set_line_mbstate () | |
9244 | { | |
ac50fbac CR |
9245 | int c; |
9246 | size_t i, previ, len; | |
7117c2d2 JA |
9247 | mbstate_t mbs, prevs; |
9248 | size_t mbclen; | |
712f80b0 | 9249 | int ilen; |
7117c2d2 JA |
9250 | |
9251 | if (shell_input_line == NULL) | |
9252 | return; | |
712f80b0 | 9253 | len = STRLEN (shell_input_line); /* XXX - shell_input_line_len ? */ |
d233b485 CR |
9254 | if (len == 0) |
9255 | return; | |
9256 | if (shell_input_line_propsize >= MAX_PROPSIZE && len < MAX_PROPSIZE>>1) | |
9257 | { | |
9258 | free (shell_input_line_property); | |
9259 | shell_input_line_property = 0; | |
9260 | shell_input_line_propsize = 0; | |
9261 | } | |
9262 | if (len+1 > shell_input_line_propsize) | |
9263 | { | |
9264 | shell_input_line_propsize = len + 1; | |
9265 | shell_input_line_property = (char *)xrealloc (shell_input_line_property, shell_input_line_propsize); | |
9266 | } | |
7117c2d2 | 9267 | |
712f80b0 CR |
9268 | if (locale_mb_cur_max == 1) |
9269 | { | |
9270 | memset (shell_input_line_property, 1, len); | |
9271 | return; | |
9272 | } | |
9273 | ||
d233b485 CR |
9274 | /* XXX - use whether or not we are in a UTF-8 locale to avoid calls to |
9275 | mbrlen */ | |
712f80b0 CR |
9276 | if (locale_utf8locale == 0) |
9277 | memset (&prevs, '\0', sizeof (mbstate_t)); | |
9278 | ||
7117c2d2 JA |
9279 | for (i = previ = 0; i < len; i++) |
9280 | { | |
712f80b0 CR |
9281 | if (locale_utf8locale == 0) |
9282 | mbs = prevs; | |
7117c2d2 | 9283 | |
b80f6443 JA |
9284 | c = shell_input_line[i]; |
9285 | if (c == EOF) | |
7117c2d2 | 9286 | { |
ac50fbac | 9287 | size_t j; |
7117c2d2 JA |
9288 | for (j = i; j < len; j++) |
9289 | shell_input_line_property[j] = 1; | |
9290 | break; | |
9291 | } | |
9292 | ||
712f80b0 CR |
9293 | if (locale_utf8locale) |
9294 | { | |
9295 | if ((unsigned char)shell_input_line[previ] < 128) /* i != previ */ | |
9296 | mbclen = 1; | |
9297 | else | |
9298 | { | |
9299 | ilen = utf8_mblen (shell_input_line + previ, i - previ + 1); | |
9300 | mbclen = (ilen == -1) ? (size_t)-1 | |
9301 | : ((ilen == -2) ? (size_t)-2 : (size_t)ilen); | |
9302 | } | |
9303 | } | |
9304 | else | |
9305 | mbclen = mbrlen (shell_input_line + previ, i - previ + 1, &mbs); | |
9306 | ||
7117c2d2 JA |
9307 | if (mbclen == 1 || mbclen == (size_t)-1) |
9308 | { | |
9309 | mbclen = 1; | |
9310 | previ = i + 1; | |
9311 | } | |
9312 | else if (mbclen == (size_t)-2) | |
9313 | mbclen = 0; | |
9314 | else if (mbclen > 1) | |
9315 | { | |
9316 | mbclen = 0; | |
9317 | previ = i + 1; | |
712f80b0 CR |
9318 | if (locale_utf8locale == 0) |
9319 | prevs = mbs; | |
7117c2d2 JA |
9320 | } |
9321 | else | |
9322 | { | |
ac50fbac | 9323 | size_t j; |
b80f6443 JA |
9324 | for (j = i; j < len; j++) |
9325 | shell_input_line_property[j] = 1; | |
9326 | break; | |
7117c2d2 JA |
9327 | } |
9328 | ||
9329 | shell_input_line_property[i] = mbclen; | |
9330 | } | |
9331 | } | |
9332 | #endif /* HANDLE_MULTIBYTE */ |