1 /* A Bison parser, made from /usr/homes/chet/src/bash/src/parse.y
4 #define YYBISON 1 /* Identify Bison output. */
20 # define COND_START 271
22 # define COND_ERROR 273
28 # define ASSIGNMENT_WORD 279
30 # define ARITH_CMD 281
31 # define ARITH_FOR_EXPRS 282
35 # define GREATER_GREATER 286
36 # define LESS_LESS 287
38 # define LESS_LESS_LESS 289
39 # define GREATER_AND 290
40 # define SEMI_SEMI 291
41 # define LESS_LESS_MINUS 292
42 # define AND_GREATER 293
43 # define LESS_GREATER 294
44 # define GREATER_BAR 295
47 #line 21 "/usr/homes/chet/src/bash/src/parse.y"
51 #include "bashtypes.h"
56 #if defined (HAVE_UNISTD_H)
60 #if defined (HAVE_LOCALE_H)
65 #include "chartypes.h"
70 #define NEED_STRFTIME_DECL /* used in externs.h */
76 #include "mailcheck.h"
78 #include "builtins/common.h"
79 #include "builtins/builtext.h"
83 #if defined (READLINE)
84 # include "bashline.h"
85 # include <readline/readline.h>
89 # include "bashhist.h"
90 # include <readline/history.h>
93 #if defined (JOB_CONTROL)
95 #endif /* JOB_CONTROL */
101 #if defined (PROMPT_STRING_DECODE)
103 # include <sys/param.h>
106 # if defined (TM_IN_SYS_TIME)
107 # include <sys/types.h>
108 # include <sys/time.h>
109 # endif /* TM_IN_SYS_TIME */
110 # include "maxpath.h"
111 #endif /* PROMPT_STRING_DECODE */
113 #define RE_READ_TOKEN -99
114 #define NO_EXPANSION -100
122 #if defined (HANDLE_MULTIBYTE)
123 # define last_shell_getc_is_singlebyte \
124 ((shell_input_line_index > 1) \
125 ? shell_input_line_property[shell_input_line_index - 1] \
127 # define MBTEST(x) ((x) && last_shell_getc_is_singlebyte)
129 # define last_shell_getc_is_singlebyte 1
130 # define MBTEST(x) ((x))
133 #if defined (EXTENDED_GLOB)
134 extern int extended_glob;
137 extern int eof_encountered;
138 extern int no_line_editing, running_under_emacs;
139 extern int current_command_number;
140 extern int sourcelevel;
141 extern int posixly_correct;
142 extern int last_command_exit_value;
143 extern int interrupt_immediately;
144 extern char *shell_name, *current_host_name;
145 extern char *dist_version;
146 extern int patch_level;
147 extern int dump_translatable_strings, dump_po_strings;
148 extern sh_builtin_func_t *last_shell_builtin, *this_shell_builtin;
149 #if defined (BUFFERED_INPUT)
150 extern int bash_input_fd_changed;
154 /* **************************************************************** */
156 /* "Forward" declarations */
158 /* **************************************************************** */
161 static void debug_parser __P((int));
164 static int yy_getc __P((void));
165 static int yy_ungetc __P((int));
167 #if defined (READLINE)
168 static int yy_readline_get __P((void));
169 static int yy_readline_unget __P((int));
172 static int yy_string_get __P((void));
173 static int yy_string_unget __P((int));
174 static int yy_stream_get __P((void));
175 static int yy_stream_unget __P((int));
177 static int shell_getc __P((int));
178 static void shell_ungetc __P((int));
179 static void discard_until __P((int));
181 #if defined (ALIAS) || defined (DPAREN_ARITHMETIC)
182 static void push_string __P((char *, int, alias_t *));
183 static void pop_string __P((void));
184 static void free_string_list __P((void));
187 static char *read_a_line __P((int));
189 static int reserved_word_acceptable __P((int));
190 static int yylex __P((void));
191 static int alias_expand_token __P((char *));
192 static int time_command_acceptable __P((void));
193 static int special_case_tokens __P((char *));
194 static int read_token __P((int));
195 static char *parse_matched_pair __P((int, int, int, int *, int));
196 #if defined (ARRAY_VARS)
197 static char *parse_compound_assignment __P((int *));
199 #if defined (DPAREN_ARITHMETIC) || defined (ARITH_FOR_COMMAND)
200 static int parse_dparen __P((int));
201 static int parse_arith_cmd __P((char **));
203 #if defined (COND_COMMAND)
204 static void cond_error __P((void));
205 static COND_COM *cond_expr __P((void));
206 static COND_COM *cond_or __P((void));
207 static COND_COM *cond_and __P((void));
208 static COND_COM *cond_term __P((void));
209 static int cond_skip_newlines __P((void));
210 static COMMAND *parse_cond_command __P((void));
212 #if defined (ARRAY_VARS)
213 static int token_is_assignment __P((char *, int));
214 static int token_is_ident __P((char *, int));
216 static int read_token_word __P((int));
217 static void discard_parser_constructs __P((int));
219 static char *error_token_from_token __P((int));
220 static char *error_token_from_text __P((void));
221 static void print_offending_line __P((void));
222 static void report_syntax_error __P((char *));
224 static void handle_eof_input_unit __P((void));
225 static void prompt_again __P((void));
227 static void reset_readline_prompt __P((void));
229 static void print_prompt __P((void));
231 #if defined (HISTORY)
232 char *history_delimiting_chars __P((void));
235 #if defined (HANDLE_MULTIBYTE)
236 static void set_line_mbstate __P((void));
237 static char *shell_input_line_property = NULL;
239 # define set_line_mbstate()
242 extern int yyerror __P((const char *));
248 /* Default prompt strings */
249 char *primary_prompt = PPROMPT;
250 char *secondary_prompt = SPROMPT;
252 /* PROMPT_STRING_POINTER points to one of these, never to an actual string. */
253 char *ps1_prompt, *ps2_prompt;
255 /* Handle on the current prompt string. Indirectly points through
256 ps1_ or ps2_prompt. */
257 char **prompt_string_pointer = (char **)NULL;
258 char *current_prompt_string;
260 /* Non-zero means we expand aliases in commands. */
261 int expand_aliases = 0;
263 /* If non-zero, the decoded prompt string undergoes parameter and
264 variable substitution, command substitution, arithmetic substitution,
265 string expansion, process substitution, and quote removal in
266 decode_prompt_string. */
269 /* The decoded prompt string. Used if READLINE is not defined or if
270 editing is turned off. Analogous to current_readline_prompt. */
271 static char *current_decoded_prompt;
273 /* The number of lines read from input while creating the current command. */
274 int current_command_line_count;
276 /* Variables to manage the task of reading here documents, because we need to
277 defer the reading until after a complete command has been collected. */
278 static REDIRECT *redir_stack[10];
281 /* Where shell input comes from. History expansion is performed on each
282 line when the shell is interactive. */
283 static char *shell_input_line = (char *)NULL;
284 static int shell_input_line_index;
285 static int shell_input_line_size; /* Amount allocated for shell_input_line. */
286 static int shell_input_line_len; /* strlen (shell_input_line) */
288 /* Either zero or EOF. */
289 static int shell_input_line_terminator;
291 /* The line number in a script on which a function definition starts. */
292 static int function_dstart;
294 /* The line number in a script on which a function body starts. */
295 static int function_bstart;
297 /* The line number in a script at which an arithmetic for command starts. */
298 static int arith_for_lineno;
300 static REDIRECTEE redir;
302 #line 276 "/usr/homes/chet/src/bash/src/parse.y"
305 WORD_DESC *word; /* the word that we read. */
306 int number; /* the number that we read. */
307 WORD_LIST *word_list;
311 PATTERN_LIST *pattern;
313 # define YYSTYPE yystype
322 #define YYFLAG -32768
325 /* YYTRANSLATE(YYLEX) -- Bison token number corresponding to YYLEX. */
326 #define YYTRANSLATE(x) ((unsigned)(x) <= 296 ? yytranslate[x] : 90)
328 /* YYTRANSLATE[YYLEX] -- Bison token number corresponding to YYLEX. */
329 static const char yytranslate[] =
331 0, 2, 2, 2, 2, 2, 2, 2, 2, 2,
332 44, 2, 2, 2, 2, 2, 2, 2, 2, 2,
333 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
334 2, 2, 2, 2, 2, 2, 2, 2, 42, 2,
335 52, 53, 2, 2, 2, 49, 2, 2, 2, 2,
336 2, 2, 2, 2, 2, 2, 2, 2, 2, 43,
337 48, 2, 47, 2, 2, 2, 2, 2, 2, 2,
338 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
339 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
340 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
341 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
342 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
343 2, 2, 2, 50, 46, 51, 2, 2, 2, 2,
344 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
345 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
346 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
347 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
348 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
349 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
350 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
351 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
352 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
353 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
354 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
355 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
356 2, 2, 2, 2, 2, 2, 1, 3, 4, 5,
357 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
358 16, 17, 18, 19, 20, 21, 22, 23, 24, 25,
359 26, 27, 28, 29, 30, 31, 32, 33, 34, 35,
360 36, 37, 38, 39, 40, 41, 45
364 static const short yyprhs[] =
366 0, 0, 3, 5, 8, 10, 12, 15, 18, 21,
367 25, 29, 32, 36, 39, 43, 46, 50, 53, 57,
368 60, 64, 67, 71, 74, 78, 81, 85, 88, 92,
369 95, 99, 102, 106, 109, 112, 116, 118, 120, 122,
370 124, 127, 129, 132, 134, 136, 139, 141, 143, 145,
371 151, 157, 159, 161, 163, 165, 167, 169, 171, 178,
372 185, 193, 201, 212, 223, 233, 243, 251, 259, 265,
373 271, 278, 285, 293, 301, 312, 323, 330, 338, 345,
374 351, 358, 363, 365, 368, 372, 378, 386, 393, 397,
375 399, 403, 408, 415, 421, 423, 426, 431, 436, 442,
376 448, 451, 455, 457, 461, 464, 466, 469, 473, 477,
377 481, 486, 491, 496, 501, 506, 508, 510, 512, 514,
378 516, 518, 519, 522, 524, 527, 530, 535, 540, 544,
379 548, 550, 552, 555, 558, 562, 566, 571, 573, 575
381 static const short yyrhs[] =
383 85, 82, 0, 44, 0, 1, 44, 0, 45, 0,
384 24, 0, 55, 24, 0, 47, 24, 0, 48, 24,
385 0, 26, 47, 24, 0, 26, 48, 24, 0, 32,
386 24, 0, 26, 32, 24, 0, 33, 24, 0, 26,
387 33, 24, 0, 35, 24, 0, 26, 35, 24, 0,
388 34, 26, 0, 26, 34, 26, 0, 36, 26, 0,
389 26, 36, 26, 0, 34, 24, 0, 26, 34, 24,
390 0, 36, 24, 0, 26, 36, 24, 0, 38, 24,
391 0, 26, 38, 24, 0, 36, 49, 0, 26, 36,
392 49, 0, 34, 49, 0, 26, 34, 49, 0, 39,
393 24, 0, 26, 40, 24, 0, 40, 24, 0, 41,
394 24, 0, 26, 41, 24, 0, 24, 0, 25, 0,
395 56, 0, 56, 0, 58, 56, 0, 57, 0, 59,
396 57, 0, 59, 0, 61, 0, 61, 58, 0, 66,
397 0, 62, 0, 65, 0, 12, 79, 14, 79, 15,
398 0, 13, 79, 14, 79, 15, 0, 64, 0, 69,
399 0, 68, 0, 70, 0, 71, 0, 72, 0, 63,
400 0, 10, 24, 84, 14, 79, 15, 0, 10, 24,
401 84, 50, 79, 51, 0, 10, 24, 43, 84, 14,
402 79, 15, 0, 10, 24, 43, 84, 50, 79, 51,
403 0, 10, 24, 84, 20, 55, 83, 84, 14, 79,
404 15, 0, 10, 24, 84, 20, 55, 83, 84, 50,
405 79, 51, 0, 10, 24, 84, 20, 83, 84, 14,
406 79, 15, 0, 10, 24, 84, 20, 83, 84, 50,
407 79, 51, 0, 10, 28, 83, 84, 14, 79, 15,
408 0, 10, 28, 83, 84, 50, 79, 51, 0, 10,
409 28, 14, 79, 15, 0, 10, 28, 50, 79, 51,
410 0, 11, 24, 84, 14, 78, 15, 0, 11, 24,
411 84, 50, 78, 51, 0, 11, 24, 43, 84, 14,
412 78, 15, 0, 11, 24, 43, 84, 50, 78, 51,
413 0, 11, 24, 84, 20, 55, 83, 84, 14, 78,
414 15, 0, 11, 24, 84, 20, 55, 83, 84, 50,
415 78, 51, 0, 8, 24, 84, 20, 84, 9, 0,
416 8, 24, 84, 20, 76, 84, 9, 0, 8, 24,
417 84, 20, 74, 9, 0, 24, 52, 53, 84, 67,
418 0, 16, 24, 52, 53, 84, 67, 0, 16, 24,
419 84, 67, 0, 61, 0, 61, 58, 0, 52, 79,
420 53, 0, 3, 79, 4, 79, 7, 0, 3, 79,
421 4, 79, 5, 79, 7, 0, 3, 79, 4, 79,
422 73, 7, 0, 50, 79, 51, 0, 27, 0, 17,
423 29, 18, 0, 6, 79, 4, 79, 0, 6, 79,
424 4, 79, 5, 79, 0, 6, 79, 4, 79, 73,
425 0, 75, 0, 76, 75, 0, 84, 77, 53, 79,
426 0, 84, 77, 53, 84, 0, 84, 52, 77, 53,
427 79, 0, 84, 52, 77, 53, 84, 0, 75, 37,
428 0, 76, 75, 37, 0, 24, 0, 77, 46, 24,
429 0, 84, 80, 0, 78, 0, 84, 81, 0, 81,
430 44, 84, 0, 81, 42, 84, 0, 81, 43, 84,
431 0, 81, 30, 84, 81, 0, 81, 31, 84, 81,
432 0, 81, 42, 84, 81, 0, 81, 43, 84, 81,
433 0, 81, 44, 84, 81, 0, 87, 0, 44, 0,
434 45, 0, 44, 0, 43, 0, 45, 0, 0, 84,
435 44, 0, 86, 0, 86, 42, 0, 86, 43, 0,
436 86, 30, 84, 86, 0, 86, 31, 84, 86, 0,
437 86, 42, 86, 0, 86, 43, 86, 0, 87, 0,
438 88, 0, 21, 88, 0, 89, 88, 0, 89, 21,
439 88, 0, 21, 89, 88, 0, 88, 46, 84, 88,
440 0, 60, 0, 22, 0, 22, 23, 0
446 /* YYRLINE[YYN] -- source line where rule number YYN was defined. */
447 static const short yyrline[] =
449 0, 326, 335, 342, 357, 367, 369, 373, 378, 383,
450 388, 393, 398, 403, 409, 415, 420, 425, 430, 435,
451 440, 445, 450, 455, 460, 465, 472, 479, 484, 489,
452 494, 499, 504, 509, 514, 519, 526, 528, 530, 534,
453 538, 549, 551, 555, 557, 559, 575, 579, 581, 583,
454 585, 587, 589, 591, 593, 595, 597, 599, 603, 605,
455 607, 609, 611, 613, 615, 617, 621, 623, 625, 627,
456 631, 635, 639, 643, 647, 651, 657, 659, 661, 665,
457 668, 671, 676, 678, 709, 716, 718, 720, 725, 729,
458 733, 737, 739, 741, 745, 746, 750, 752, 754, 756,
459 760, 761, 765, 767, 776, 784, 785, 791, 792, 799,
460 803, 805, 807, 814, 816, 818, 822, 823, 826, 827,
461 828, 831, 832, 841, 847, 856, 864, 866, 868, 875,
462 878, 882, 884, 889, 894, 899, 906, 909, 913, 915
467 #if (YYDEBUG) || defined YYERROR_VERBOSE
469 /* YYTNAME[TOKEN_NUM] -- String name of the token TOKEN_NUM. */
470 static const char *const yytname[] =
472 "$", "error", "$undefined.", "IF", "THEN", "ELSE", "ELIF", "FI", "CASE",
473 "ESAC", "FOR", "SELECT", "WHILE", "UNTIL", "DO", "DONE", "FUNCTION",
474 "COND_START", "COND_END", "COND_ERROR", "IN", "BANG", "TIME", "TIMEOPT",
475 "WORD", "ASSIGNMENT_WORD", "NUMBER", "ARITH_CMD", "ARITH_FOR_EXPRS",
476 "COND_CMD", "AND_AND", "OR_OR", "GREATER_GREATER", "LESS_LESS",
477 "LESS_AND", "LESS_LESS_LESS", "GREATER_AND", "SEMI_SEMI",
478 "LESS_LESS_MINUS", "AND_GREATER", "LESS_GREATER", "GREATER_BAR", "'&'",
479 "';'", "'\\n'", "yacc_EOF", "'|'", "'>'", "'<'", "'-'", "'{'", "'}'",
480 "'('", "')'", "inputunit", "word_list", "redirection",
481 "simple_command_element", "redirection_list", "simple_command",
482 "command", "shell_command", "for_command", "arith_for_command",
483 "select_command", "case_command", "function_def", "function_body",
484 "subshell", "if_command", "group_command", "arith_command",
485 "cond_command", "elif_clause", "case_clause", "pattern_list",
486 "case_clause_sequence", "pattern", "list", "compound_list", "list0",
487 "list1", "simple_list_terminator", "list_terminator", "newline_list",
488 "simple_list", "simple_list1", "pipeline_command", "pipeline",
493 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
494 static const short yyr1[] =
496 0, 54, 54, 54, 54, 55, 55, 56, 56, 56,
497 56, 56, 56, 56, 56, 56, 56, 56, 56, 56,
498 56, 56, 56, 56, 56, 56, 56, 56, 56, 56,
499 56, 56, 56, 56, 56, 56, 57, 57, 57, 58,
500 58, 59, 59, 60, 60, 60, 60, 61, 61, 61,
501 61, 61, 61, 61, 61, 61, 61, 61, 62, 62,
502 62, 62, 62, 62, 62, 62, 63, 63, 63, 63,
503 64, 64, 64, 64, 64, 64, 65, 65, 65, 66,
504 66, 66, 67, 67, 68, 69, 69, 69, 70, 71,
505 72, 73, 73, 73, 74, 74, 75, 75, 75, 75,
506 76, 76, 77, 77, 78, 79, 79, 80, 80, 80,
507 81, 81, 81, 81, 81, 81, 82, 82, 83, 83,
508 83, 84, 84, 85, 85, 85, 86, 86, 86, 86,
509 86, 87, 87, 87, 87, 87, 88, 88, 89, 89
512 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
513 static const short yyr2[] =
515 0, 2, 1, 2, 1, 1, 2, 2, 2, 3,
516 3, 2, 3, 2, 3, 2, 3, 2, 3, 2,
517 3, 2, 3, 2, 3, 2, 3, 2, 3, 2,
518 3, 2, 3, 2, 2, 3, 1, 1, 1, 1,
519 2, 1, 2, 1, 1, 2, 1, 1, 1, 5,
520 5, 1, 1, 1, 1, 1, 1, 1, 6, 6,
521 7, 7, 10, 10, 9, 9, 7, 7, 5, 5,
522 6, 6, 7, 7, 10, 10, 6, 7, 6, 5,
523 6, 4, 1, 2, 3, 5, 7, 6, 3, 1,
524 3, 4, 6, 5, 1, 2, 4, 4, 5, 5,
525 2, 3, 1, 3, 2, 1, 2, 3, 3, 3,
526 4, 4, 4, 4, 4, 1, 1, 1, 1, 1,
527 1, 0, 2, 1, 2, 2, 4, 4, 3, 3,
528 1, 1, 2, 2, 3, 3, 4, 1, 1, 2
531 /* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE
532 doesn't specify something else to do. Zero means the default is an
534 static const short yydefact[] =
536 0, 0, 121, 0, 0, 0, 121, 121, 0, 0,
537 0, 138, 36, 37, 0, 89, 0, 0, 0, 0,
538 0, 0, 0, 0, 0, 2, 4, 0, 0, 121,
539 121, 38, 41, 43, 137, 44, 47, 57, 51, 48,
540 46, 53, 52, 54, 55, 56, 0, 123, 130, 131,
541 0, 3, 105, 0, 0, 121, 121, 0, 121, 0,
542 0, 121, 0, 132, 0, 139, 0, 0, 0, 0,
543 0, 0, 0, 0, 0, 0, 0, 11, 13, 21,
544 17, 29, 15, 23, 19, 27, 25, 31, 33, 34,
545 7, 8, 0, 0, 36, 42, 39, 45, 116, 117,
546 1, 121, 121, 124, 125, 121, 0, 133, 121, 122,
547 104, 106, 115, 0, 121, 0, 121, 119, 118, 120,
548 121, 121, 121, 0, 121, 121, 0, 0, 90, 135,
549 121, 12, 14, 22, 18, 30, 16, 24, 20, 28,
550 26, 32, 35, 9, 10, 88, 84, 40, 0, 0,
551 128, 129, 0, 134, 0, 121, 121, 121, 121, 121,
552 121, 0, 121, 0, 121, 0, 0, 0, 0, 121,
553 0, 121, 0, 0, 121, 82, 81, 0, 126, 127,
554 0, 0, 136, 121, 121, 85, 0, 0, 0, 108,
555 109, 107, 0, 94, 121, 0, 121, 121, 0, 5,
556 0, 121, 0, 68, 69, 121, 121, 121, 121, 0,
557 0, 0, 0, 49, 50, 0, 83, 79, 0, 0,
558 87, 110, 111, 112, 113, 114, 78, 100, 95, 0,
559 76, 102, 0, 0, 0, 0, 58, 6, 121, 0,
560 59, 0, 0, 0, 0, 70, 0, 121, 71, 80,
561 86, 121, 121, 121, 121, 101, 77, 0, 0, 121,
562 60, 61, 0, 121, 121, 66, 67, 72, 73, 0,
563 91, 0, 0, 0, 121, 103, 96, 97, 121, 121,
564 0, 0, 121, 121, 121, 93, 98, 99, 0, 0,
565 64, 65, 0, 0, 92, 62, 63, 74, 75, 0,
569 static const short yydefgoto[] =
571 299, 200, 31, 32, 97, 33, 34, 35, 36, 37,
572 38, 39, 40, 176, 41, 42, 43, 44, 45, 186,
573 192, 193, 194, 233, 52, 53, 110, 111, 100, 121,
574 54, 46, 150, 112, 49, 50
577 static const short yypact[] =
579 273, -24,-32768, -2, 11, 6,-32768,-32768, 12, 9,
580 402, 41, 10,-32768, 552,-32768, 46, 52, -5, 58,
581 64, 68, 102, 117, 135,-32768,-32768, 146, 149,-32768,
582 -32768,-32768,-32768, 169,-32768, 202,-32768,-32768,-32768,-32768,
583 -32768,-32768,-32768,-32768,-32768,-32768, -33, 42,-32768, 91,
584 445,-32768,-32768, 142, 316,-32768, 133, 72, 136, 172,
585 174, 97, 171, 91, 531,-32768, 139, 173, 182, 99,
586 188, 138, 189, 190, 191, 194, 195,-32768,-32768,-32768,
587 -32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,
588 -32768,-32768, 145, 168,-32768,-32768,-32768, 202,-32768,-32768,
589 -32768,-32768,-32768, 359, 359,-32768, 531, 91,-32768,-32768,
590 -32768, 249,-32768, -12,-32768, 13,-32768,-32768,-32768,-32768,
591 -32768,-32768,-32768, 57,-32768,-32768, 170, 39,-32768, 91,
592 -32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,
593 -32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768, 316, 316,
594 28, 28, 488, 91, 74,-32768,-32768,-32768,-32768,-32768,
595 -32768, 90,-32768, 220,-32768, 183, 178, 110, 113,-32768,
596 198,-32768, 209, 215,-32768, 202,-32768, 39,-32768,-32768,
597 359, 359, 91,-32768,-32768,-32768, 224, 316, 316, 316,
598 316, 316, 230, 196,-32768, 16,-32768,-32768, 231,-32768,
599 258,-32768, 197,-32768,-32768,-32768,-32768,-32768,-32768, 236,
600 316, 258, 201,-32768,-32768, 39, 202,-32768, 247, 255,
601 -32768,-32768,-32768, 66, 66, 66,-32768,-32768, 223, 17,
602 -32768,-32768, 237, 92, 251, 211,-32768,-32768,-32768, 121,
603 -32768, 252, 218, 256, 219,-32768, 249,-32768,-32768,-32768,
604 -32768,-32768,-32768,-32768,-32768,-32768,-32768, 115, 253,-32768,
605 -32768,-32768, 122,-32768,-32768,-32768,-32768,-32768,-32768, 125,
606 106, 316, 316, 316,-32768,-32768,-32768, 316,-32768,-32768,
607 260, 245,-32768,-32768,-32768,-32768,-32768, 316, 272, 259,
608 -32768,-32768, 289, 264,-32768,-32768,-32768,-32768,-32768, 288,
612 static const short yypgoto[] =
614 -32768, 160, -32, 283, 156,-32768,-32768, -122,-32768,-32768,
615 -32768,-32768,-32768, -167,-32768,-32768,-32768,-32768,-32768, 65,
616 -32768, 140,-32768, 104, -162, -6,-32768, -173,-32768, -157,
617 -27,-32768, 4, 2, 3, 329
624 static const short yytable[] =
626 59, 60, 48, 96, 47, 175, 201, 209, 160, 212,
627 217, 98, 99, 63, 221, 222, 223, 224, 225, 79,
628 51, 80, 55, 92, 93, 230, 256, 162, 113, 115,
629 58, 123, 109, 163, 127, 56, 61, 246, 62, 57,
630 231, 231, 2, 238, 81, 243, 244, 3, 249, 4,
631 5, 6, 7, 107, 247, 175, 9, 109, 101, 102,
632 109, 109, 66, 164, 65, 147, 15, 129, 232, 232,
633 77, 169, 101, 102, 148, 149, 78, 170, 152, 183,
634 184, 185, 82, 109, 103, 104, 116, 161, 83, 29,
635 84, 30, 86, 175, 167, 168, 155, 156, 223, 224,
636 225, 109, 154, 177, 196, 48, 48, 171, 151, 153,
637 165, 284, 184, 85, 166, 117, 118, 119, 172, 173,
638 292, 293, 120, 133, 205, 134, 87, 207, 187, 188,
639 189, 190, 191, 195, 109, 263, 278, 105, 258, 282,
640 197, 88, 210, 96, 210, 259, 108, 215, 135, 126,
641 48, 48, 178, 179, 109, 182, 198, 109, 202, 89,
642 206, 258, 137, 208, 138, 109, 109, 229, 274, 109,
643 90, 264, 279, 91, 239, 283, 114, 218, 219, 122,
644 210, 210, 48, 48, 147, 151, 124, 139, 125, 128,
645 234, 235, 130, 94, 13, 14, 145, 131, 203, 241,
646 242, 16, 17, 18, 19, 20, 132, 21, 22, 23,
647 24, 262, 136, 140, 141, 142, 27, 28, 143, 144,
648 269, 146, 199, 174, 213, 271, 272, 273, 14, 204,
649 214, 220, 277, 227, 16, 17, 18, 19, 20, 226,
650 21, 22, 23, 24, 199, 270, 236, 287, 240, 27,
651 28, 245, 248, 276, 250, 210, 210, 280, 281, 251,
652 255, 231, 261, 117, 118, 119, 260, 265, 286, 266,
653 268, 267, 288, 289, 1, 290, 2, 275, 294, 155,
654 156, 3, 237, 4, 5, 6, 7, 295, 300, 8,
655 9, 157, 158, 159, 10, 11, 291, 12, 13, 14,
656 15, 117, 118, 119, 297, 16, 17, 18, 19, 20,
657 296, 21, 22, 23, 24, 298, 95, 25, 26, 2,
658 27, 28, 301, 29, 3, 30, 4, 5, 6, 7,
659 211, 216, 8, 9, 228, 285, 257, 10, 11, 64,
660 12, 13, 14, 15, 0, 0, 0, 0, 16, 17,
661 18, 19, 20, 0, 21, 22, 23, 24, 0, 0,
662 109, 0, 2, 27, 28, 0, 29, 3, 30, 4,
663 5, 6, 7, 0, 0, 8, 9, 0, 0, 0,
664 10, 11, 0, 12, 13, 14, 15, 0, 0, 0,
665 0, 16, 17, 18, 19, 20, 0, 21, 22, 23,
666 24, 0, 0, 0, 0, 2, 27, 28, 0, 29,
667 3, 30, 4, 5, 6, 7, 0, 0, 8, 9,
668 0, 0, 0, 0, 11, 0, 12, 13, 14, 15,
669 0, 0, 0, 0, 16, 17, 18, 19, 20, 0,
670 21, 22, 23, 24, 0, 0, 0, 0, 2, 27,
671 28, 0, 29, 3, 30, 4, 5, 6, 7, 0,
672 0, 8, 9, 0, 0, 0, 106, 0, 0, 12,
673 13, 14, 15, 0, 0, 0, 0, 16, 17, 18,
674 19, 20, 0, 21, 22, 23, 24, 0, 0, 0,
675 0, 2, 27, 28, 0, 29, 3, 30, 4, 5,
676 6, 7, 0, 0, 8, 9, 0, 0, 0, 0,
677 0, 0, 12, 13, 14, 15, 0, 0, 0, 0,
678 16, 17, 18, 19, 20, 0, 21, 22, 23, 24,
679 0, 0, 109, 0, 2, 27, 28, 0, 29, 3,
680 30, 4, 5, 6, 7, 0, 0, 8, 9, 0,
681 0, 0, 0, 0, 0, 12, 13, 14, 15, 0,
682 0, 0, 0, 16, 17, 18, 19, 20, 0, 21,
683 22, 23, 24, 0, 0, 0, 0, 0, 27, 28,
684 0, 29, 0, 30, 67, 68, 69, 70, 71, 0,
685 72, 0, 73, 74, 0, 0, 0, 0, 0, 75,
689 static const short yycheck[] =
691 6, 7, 0, 35, 0, 127, 163, 169, 20, 171,
692 177, 44, 45, 10, 187, 188, 189, 190, 191, 24,
693 44, 26, 24, 29, 30, 9, 9, 14, 55, 56,
694 24, 58, 44, 20, 61, 24, 24, 210, 29, 28,
695 24, 24, 3, 200, 49, 207, 208, 8, 215, 10,
696 11, 12, 13, 50, 211, 177, 17, 44, 30, 31,
697 44, 44, 52, 50, 23, 97, 27, 64, 52, 52,
698 24, 14, 30, 31, 101, 102, 24, 20, 105, 5,
699 6, 7, 24, 44, 42, 43, 14, 114, 24, 50,
700 26, 52, 24, 215, 121, 122, 30, 31, 271, 272,
701 273, 44, 108, 130, 14, 103, 104, 50, 104, 106,
702 116, 5, 6, 49, 120, 43, 44, 45, 124, 125,
703 282, 283, 50, 24, 14, 26, 24, 14, 155, 156,
704 157, 158, 159, 160, 44, 14, 14, 46, 46, 14,
705 50, 24, 169, 175, 171, 53, 4, 174, 49, 52,
706 148, 149, 148, 149, 44, 152, 162, 44, 164, 24,
707 50, 46, 24, 50, 26, 44, 44, 194, 53, 44,
708 24, 50, 50, 24, 201, 50, 43, 183, 184, 43,
709 207, 208, 180, 181, 216, 181, 14, 49, 14, 18,
710 196, 197, 53, 24, 25, 26, 51, 24, 15, 205,
711 206, 32, 33, 34, 35, 36, 24, 38, 39, 40,
712 41, 238, 24, 24, 24, 24, 47, 48, 24, 24,
713 247, 53, 24, 53, 15, 252, 253, 254, 26, 51,
714 15, 7, 259, 37, 32, 33, 34, 35, 36, 9,
715 38, 39, 40, 41, 24, 251, 15, 274, 51, 47,
716 48, 15, 51, 259, 7, 282, 283, 263, 264, 4,
717 37, 24, 51, 43, 44, 45, 15, 15, 274, 51,
718 51, 15, 278, 279, 1, 15, 3, 24, 284, 30,
719 31, 8, 24, 10, 11, 12, 13, 15, 0, 16,
720 17, 42, 43, 44, 21, 22, 51, 24, 25, 26,
721 27, 43, 44, 45, 15, 32, 33, 34, 35, 36,
722 51, 38, 39, 40, 41, 51, 33, 44, 45, 3,
723 47, 48, 0, 50, 8, 52, 10, 11, 12, 13,
724 170, 175, 16, 17, 194, 270, 232, 21, 22, 10,
725 24, 25, 26, 27, -1, -1, -1, -1, 32, 33,
726 34, 35, 36, -1, 38, 39, 40, 41, -1, -1,
727 44, -1, 3, 47, 48, -1, 50, 8, 52, 10,
728 11, 12, 13, -1, -1, 16, 17, -1, -1, -1,
729 21, 22, -1, 24, 25, 26, 27, -1, -1, -1,
730 -1, 32, 33, 34, 35, 36, -1, 38, 39, 40,
731 41, -1, -1, -1, -1, 3, 47, 48, -1, 50,
732 8, 52, 10, 11, 12, 13, -1, -1, 16, 17,
733 -1, -1, -1, -1, 22, -1, 24, 25, 26, 27,
734 -1, -1, -1, -1, 32, 33, 34, 35, 36, -1,
735 38, 39, 40, 41, -1, -1, -1, -1, 3, 47,
736 48, -1, 50, 8, 52, 10, 11, 12, 13, -1,
737 -1, 16, 17, -1, -1, -1, 21, -1, -1, 24,
738 25, 26, 27, -1, -1, -1, -1, 32, 33, 34,
739 35, 36, -1, 38, 39, 40, 41, -1, -1, -1,
740 -1, 3, 47, 48, -1, 50, 8, 52, 10, 11,
741 12, 13, -1, -1, 16, 17, -1, -1, -1, -1,
742 -1, -1, 24, 25, 26, 27, -1, -1, -1, -1,
743 32, 33, 34, 35, 36, -1, 38, 39, 40, 41,
744 -1, -1, 44, -1, 3, 47, 48, -1, 50, 8,
745 52, 10, 11, 12, 13, -1, -1, 16, 17, -1,
746 -1, -1, -1, -1, -1, 24, 25, 26, 27, -1,
747 -1, -1, -1, 32, 33, 34, 35, 36, -1, 38,
748 39, 40, 41, -1, -1, -1, -1, -1, 47, 48,
749 -1, 50, -1, 52, 32, 33, 34, 35, 36, -1,
750 38, -1, 40, 41, -1, -1, -1, -1, -1, 47,
753 /* -*-C-*- Note some compilers choke on comments on `#line' lines. */
754 #line 3 "/usr/local/share/bison/bison.simple"
756 /* Skeleton output parser for bison,
758 Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002 Free Software
761 This program is free software; you can redistribute it and/or modify
762 it under the terms of the GNU General Public License as published by
763 the Free Software Foundation; either version 2, or (at your option)
766 This program is distributed in the hope that it will be useful,
767 but WITHOUT ANY WARRANTY; without even the implied warranty of
768 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
769 GNU General Public License for more details.
771 You should have received a copy of the GNU General Public License
772 along with this program; if not, write to the Free Software
773 Foundation, Inc., 59 Temple Place - Suite 330,
774 Boston, MA 02111-1307, USA. */
776 /* As a special exception, when this file is copied by Bison into a
777 Bison output file, you may use that output file without restriction.
778 This special exception was added by the Free Software Foundation
779 in version 1.24 of Bison. */
781 /* This is the parser code that is written into each bison parser when
782 the %semantic_parser declaration is not specified in the grammar.
783 It was written by Richard Stallman by simplifying the hairy parser
784 used when %semantic_parser is specified. */
786 /* All symbols defined below should begin with yy or YY, to avoid
787 infringing on user name space. This should be done even for local
788 variables, as they might otherwise be expanded by user macros.
789 There are some unavoidable exceptions within include files to
790 define necessary library symbols; they are noted "INFRINGES ON
791 USER NAME SPACE" below. */
793 #if ! defined (yyoverflow) || defined (YYERROR_VERBOSE)
795 /* The parser invokes alloca or malloc; define the necessary symbols. */
797 # if YYSTACK_USE_ALLOCA
798 # define YYSTACK_ALLOC alloca
800 # ifndef YYSTACK_USE_ALLOCA
801 # if defined (alloca) || defined (_ALLOCA_H)
802 # define YYSTACK_ALLOC alloca
805 # define YYSTACK_ALLOC __builtin_alloca
811 # ifdef YYSTACK_ALLOC
812 /* Pacify GCC's `empty if-body' warning. */
813 # define YYSTACK_FREE(Ptr) do { /* empty */; } while (0)
815 # if defined (__STDC__) || defined (__cplusplus)
816 # include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
817 # define YYSIZE_T size_t
819 # define YYSTACK_ALLOC malloc
820 # define YYSTACK_FREE free
823 /* A type that is properly aligned for any stack member. */
833 /* The size of the maximum gap between one aligned stack and the next. */
834 # define YYSTACK_GAP_MAX (sizeof (union yyalloc) - 1)
836 /* The size of an array large to enough to hold all stacks, each with
839 # define YYSTACK_BYTES(N) \
840 ((N) * (sizeof (short) + sizeof (YYSTYPE) + sizeof (YYLTYPE)) \
841 + 2 * YYSTACK_GAP_MAX)
843 # define YYSTACK_BYTES(N) \
844 ((N) * (sizeof (short) + sizeof (YYSTYPE)) \
848 /* Relocate the TYPE STACK from its old location to the new one. The
849 local variables YYSIZE and YYSTACKSIZE give the old and new number of
850 elements in the stack, and YYPTR gives the new location of the
851 stack. Advance YYPTR to a properly aligned location for the next
853 # define YYSTACK_RELOCATE(Type, Stack) \
856 YYSIZE_T yynewbytes; \
857 yymemcpy ((char *) yyptr, (char *) (Stack), \
858 yysize * (YYSIZE_T) sizeof (Type)); \
859 Stack = &yyptr->Stack; \
860 yynewbytes = yystacksize * sizeof (Type) + YYSTACK_GAP_MAX; \
861 yyptr += yynewbytes / sizeof (*yyptr); \
865 #endif /* ! defined (yyoverflow) || defined (YYERROR_VERBOSE) */
868 #if ! defined (YYSIZE_T) && defined (__SIZE_TYPE__)
869 # define YYSIZE_T __SIZE_TYPE__
871 #if ! defined (YYSIZE_T) && defined (size_t)
872 # define YYSIZE_T size_t
874 #if ! defined (YYSIZE_T)
875 # if defined (__STDC__) || defined (__cplusplus)
876 # include <stddef.h> /* INFRINGES ON USER NAME SPACE */
877 # define YYSIZE_T size_t
880 #if ! defined (YYSIZE_T)
881 # define YYSIZE_T unsigned int
884 #define yyerrok (yyerrstatus = 0)
885 #define yyclearin (yychar = YYEMPTY)
888 #define YYACCEPT goto yyacceptlab
889 #define YYABORT goto yyabortlab
890 #define YYERROR goto yyerrlab1
891 /* Like YYERROR except do call yyerror. This remains here temporarily
892 to ease the transition to the new meaning of YYERROR, for GCC.
893 Once GCC version 2 has supplanted version 1, this can go. */
894 #define YYFAIL goto yyerrlab
895 #define YYRECOVERING() (!!yyerrstatus)
896 #define YYBACKUP(Token, Value) \
898 if (yychar == YYEMPTY && yylen == 1) \
902 yychar1 = YYTRANSLATE (yychar); \
908 yyerror ("syntax error: cannot back up"); \
914 #define YYERRCODE 256
917 /* YYLLOC_DEFAULT -- Compute the default location (before the actions
920 When YYLLOC_DEFAULT is run, CURRENT is set the location of the
921 first token. By default, to implement support for ranges, extend
922 its range to the last symbol. */
924 #ifndef YYLLOC_DEFAULT
925 # define YYLLOC_DEFAULT(Current, Rhs, N) \
926 Current.last_line = Rhs[N].last_line; \
927 Current.last_column = Rhs[N].last_column;
931 /* YYLEX -- calling `yylex' with the right arguments. */
936 # define YYLEX yylex (&yylval, &yylloc, YYLEX_PARAM)
938 # define YYLEX yylex (&yylval, &yylloc)
940 # else /* !YYLSP_NEEDED */
942 # define YYLEX yylex (&yylval, YYLEX_PARAM)
944 # define YYLEX yylex (&yylval)
946 # endif /* !YYLSP_NEEDED */
948 # define YYLEX yylex ()
952 /* Enable debugging if requested. */
956 # include <stdio.h> /* INFRINGES ON USER NAME SPACE */
957 # define YYFPRINTF fprintf
960 # define YYDPRINTF(Args) \
965 /* Nonzero means print parse trace. It is left uninitialized so that
966 multiple parsers can coexist. */
969 # define YYDPRINTF(Args)
970 #endif /* !YYDEBUG */
972 /* YYINITDEPTH -- initial size of the parser's stacks. */
974 # define YYINITDEPTH 200
977 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
978 if the built-in stack extension method is used).
980 Do not make this value too large; the results are undefined if
981 SIZE_MAX < YYSTACK_BYTES (YYMAXDEPTH)
982 evaluated with infinite-precision integer arithmetic. */
989 # define YYMAXDEPTH 10000
992 #if ! defined (yyoverflow) && ! defined (yymemcpy)
993 # if __GNUC__ > 1 /* GNU C and GNU C++ define this. */
994 # define yymemcpy __builtin_memcpy
995 # else /* not GNU C or C++ */
997 /* This is the most reliable way to avoid incompatibilities
998 in available built-in functions on various systems. */
1000 # if defined (__STDC__) || defined (__cplusplus)
1001 yymemcpy (char *yyto, const char *yyfrom, YYSIZE_T yycount)
1003 yymemcpy (yyto, yyfrom, yycount)
1009 register const char *yyf = yyfrom;
1010 register char *yyt = yyto;
1011 register YYSIZE_T yyi = yycount;
1019 #ifdef YYERROR_VERBOSE
1022 # if defined (__GLIBC__) && defined (_STRING_H)
1023 # define yystrlen strlen
1025 /* Return the length of YYSTR. */
1027 # if defined (__STDC__) || defined (__cplusplus)
1028 yystrlen (const char *yystr)
1034 register const char *yys = yystr;
1036 while (*yys++ != '\0')
1039 return yys - yystr - 1;
1045 # if defined (__GLIBC__) && defined (_STRING_H) && defined (_GNU_SOURCE)
1046 # define yystpcpy stpcpy
1048 /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
1051 # if defined (__STDC__) || defined (__cplusplus)
1052 yystpcpy (char *yydest, const char *yysrc)
1054 yystpcpy (yydest, yysrc)
1059 register char *yyd = yydest;
1060 register const char *yys = yysrc;
1062 while ((*yyd++ = *yys++) != '\0')
1071 #line 319 "/usr/local/share/bison/bison.simple"
1074 /* The user can define YYPARSE_PARAM as the name of an argument to be passed
1075 into yyparse. The argument should have type void *.
1076 It should actually point to an object.
1077 Grammar actions can access the variable by casting it
1078 to the proper pointer type. */
1080 #ifdef YYPARSE_PARAM
1081 # if defined (__STDC__) || defined (__cplusplus)
1082 # define YYPARSE_PARAM_ARG void *YYPARSE_PARAM
1083 # define YYPARSE_PARAM_DECL
1085 # define YYPARSE_PARAM_ARG YYPARSE_PARAM
1086 # define YYPARSE_PARAM_DECL void *YYPARSE_PARAM;
1088 #else /* !YYPARSE_PARAM */
1089 # define YYPARSE_PARAM_ARG
1090 # define YYPARSE_PARAM_DECL
1091 #endif /* !YYPARSE_PARAM */
1093 /* Prevent warning if -Wstrict-prototypes. */
1095 # ifdef YYPARSE_PARAM
1096 int yyparse (void *);
1102 /* YY_DECL_VARIABLES -- depending whether we use a pure parser,
1103 variables are global, or local to YYPARSE. */
1105 #define YY_DECL_NON_LSP_VARIABLES \
1106 /* The lookahead symbol. */ \
1109 /* The semantic value of the lookahead symbol. */ \
1112 /* Number of parse errors so far. */ \
1116 # define YY_DECL_VARIABLES \
1117 YY_DECL_NON_LSP_VARIABLES \
1119 /* Location data for the lookahead symbol. */ \
1122 # define YY_DECL_VARIABLES \
1123 YY_DECL_NON_LSP_VARIABLES
1127 /* If nonreentrant, generate the variables here. */
1131 #endif /* !YYPURE */
1134 yyparse (YYPARSE_PARAM_ARG)
1137 /* If reentrant, generate the variables here. */
1140 #endif /* !YYPURE */
1142 register int yystate;
1145 /* Number of tokens to shift before error messages enabled. */
1147 /* Lookahead token as an internal (translated) token number. */
1150 /* Three stacks and their tools:
1151 `yyss': related to states,
1152 `yyvs': related to semantic values,
1153 `yyls': related to locations.
1155 Refer to the stacks thru separate pointers, to allow yyoverflow
1156 to reallocate them elsewhere. */
1158 /* The state stack. */
1159 short yyssa[YYINITDEPTH];
1160 short *yyss = yyssa;
1161 register short *yyssp;
1163 /* The semantic value stack. */
1164 YYSTYPE yyvsa[YYINITDEPTH];
1165 YYSTYPE *yyvs = yyvsa;
1166 register YYSTYPE *yyvsp;
1169 /* The location stack. */
1170 YYLTYPE yylsa[YYINITDEPTH];
1171 YYLTYPE *yyls = yylsa;
1176 # define YYPOPSTACK (yyvsp--, yyssp--, yylsp--)
1178 # define YYPOPSTACK (yyvsp--, yyssp--)
1181 YYSIZE_T yystacksize = YYINITDEPTH;
1184 /* The variables used to return semantic value and location from the
1191 /* When reducing, the number of symbols on the RHS of the reduced
1195 YYDPRINTF ((stderr, "Starting parse\n"));
1200 yychar = YYEMPTY; /* Cause a token to be read. */
1202 /* Initialize stack pointers.
1203 Waste one element of value and location stack
1204 so that they stay on the same level as the state stack.
1205 The wasted elements are never initialized. */
1214 /*------------------------------------------------------------.
1215 | yynewstate -- Push a new state, which is found in yystate. |
1216 `------------------------------------------------------------*/
1218 /* In all cases, when you get here, the value and location stacks
1219 have just been pushed. so pushing a state here evens the stacks.
1226 if (yyssp >= yyss + yystacksize - 1)
1228 /* Get the current used size of the three stacks, in elements. */
1229 YYSIZE_T yysize = yyssp - yyss + 1;
1233 /* Give user a chance to reallocate the stack. Use copies of
1234 these so that the &'s don't force the real ones into
1236 YYSTYPE *yyvs1 = yyvs;
1237 short *yyss1 = yyss;
1239 /* Each stack pointer address is followed by the size of the
1240 data in use in that stack, in bytes. */
1242 YYLTYPE *yyls1 = yyls;
1243 /* This used to be a conditional around just the two extra args,
1244 but that might be undefined if yyoverflow is a macro. */
1245 yyoverflow ("parser stack overflow",
1246 &yyss1, yysize * sizeof (*yyssp),
1247 &yyvs1, yysize * sizeof (*yyvsp),
1248 &yyls1, yysize * sizeof (*yylsp),
1252 yyoverflow ("parser stack overflow",
1253 &yyss1, yysize * sizeof (*yyssp),
1254 &yyvs1, yysize * sizeof (*yyvsp),
1260 #else /* no yyoverflow */
1261 /* Extend the stack our own way. */
1262 if (yystacksize >= YYMAXDEPTH)
1265 if (yystacksize > YYMAXDEPTH)
1266 yystacksize = YYMAXDEPTH;
1269 short *yyss1 = yyss;
1270 union yyalloc *yyptr =
1271 (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
1274 YYSTACK_RELOCATE (short, yyss);
1275 YYSTACK_RELOCATE (YYSTYPE, yyvs);
1277 YYSTACK_RELOCATE (YYLTYPE, yyls);
1279 # undef YYSTACK_RELOCATE
1281 YYSTACK_FREE (yyss1);
1283 #endif /* no yyoverflow */
1285 yyssp = yyss + yysize - 1;
1286 yyvsp = yyvs + yysize - 1;
1288 yylsp = yyls + yysize - 1;
1291 YYDPRINTF ((stderr, "Stack size increased to %lu\n",
1292 (unsigned long int) yystacksize));
1294 if (yyssp >= yyss + yystacksize - 1)
1298 YYDPRINTF ((stderr, "Entering state %d\n", yystate));
1308 /* Do appropriate processing given the current state. */
1309 /* Read a lookahead token if we need one and don't already have one. */
1312 /* First try to decide what to do without reference to lookahead token. */
1314 yyn = yypact[yystate];
1318 /* Not known => get a lookahead token if don't already have one. */
1320 /* yychar is either YYEMPTY or YYEOF
1321 or a valid token in external form. */
1323 if (yychar == YYEMPTY)
1325 YYDPRINTF ((stderr, "Reading a token: "));
1329 /* Convert token to internal form (in yychar1) for indexing tables with */
1331 if (yychar <= 0) /* This means end of input. */
1334 yychar = YYEOF; /* Don't call YYLEX any more */
1336 YYDPRINTF ((stderr, "Now at end of input.\n"));
1340 yychar1 = YYTRANSLATE (yychar);
1343 /* We have to keep this `#if YYDEBUG', since we use variables
1344 which are defined only if `YYDEBUG' is set. */
1347 YYFPRINTF (stderr, "Next token is %d (%s",
1348 yychar, yytname[yychar1]);
1349 /* Give the individual parser a way to print the precise
1350 meaning of a token, for further debugging info. */
1352 YYPRINT (stderr, yychar, yylval);
1354 YYFPRINTF (stderr, ")\n");
1360 if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != yychar1)
1365 /* yyn is what to do for this token type in this state.
1366 Negative => reduce, -yyn is rule number.
1367 Positive => shift, yyn is new state.
1368 New state is final state => don't bother to shift,
1369 just return success.
1370 0, or most negative number => error. */
1385 /* Shift the lookahead token. */
1386 YYDPRINTF ((stderr, "Shifting token %d (%s), ",
1387 yychar, yytname[yychar1]));
1389 /* Discard the token being shifted unless it is eof. */
1390 if (yychar != YYEOF)
1398 /* Count tokens shifted since error; after three, turn off error
1407 /*-----------------------------------------------------------.
1408 | yydefault -- do the default action for the current state. |
1409 `-----------------------------------------------------------*/
1411 yyn = yydefact[yystate];
1417 /*-----------------------------.
1418 | yyreduce -- Do a reduction. |
1419 `-----------------------------*/
1421 /* yyn is the number of a rule to reduce with. */
1424 /* If YYLEN is nonzero, implement the default value of the action:
1427 Otherwise, the following line sets YYVAL to the semantic value of
1428 the lookahead token. This behavior is undocumented and Bison
1429 users should not rely upon it. Assigning to YYVAL
1430 unconditionally makes the parser a bit smaller, and it avoids a
1431 GCC warning that YYVAL may be used uninitialized. */
1432 yyval = yyvsp[1-yylen];
1435 /* Similarly for the default location. Let the user run additional
1436 commands if for instance locations are ranges. */
1437 yyloc = yylsp[1-yylen];
1438 YYLLOC_DEFAULT (yyloc, (yylsp - yylen), yylen);
1442 /* We have to keep this `#if YYDEBUG', since we use variables which
1443 are defined only if `YYDEBUG' is set. */
1448 YYFPRINTF (stderr, "Reducing via rule %d (line %d), ",
1451 /* Print the symbols being reduced, and their result. */
1452 for (yyi = yyprhs[yyn]; yyrhs[yyi] > 0; yyi++)
1453 YYFPRINTF (stderr, "%s ", yytname[yyrhs[yyi]]);
1454 YYFPRINTF (stderr, " -> %s\n", yytname[yyr1[yyn]]);
1461 #line 327 "/usr/homes/chet/src/bash/src/parse.y"
1463 /* Case of regular command. Discard the error
1464 safety net,and return the command just parsed. */
1465 global_command = yyvsp[-1].command;
1466 eof_encountered = 0;
1467 /* discard_parser_constructs (0); */
1472 #line 336 "/usr/homes/chet/src/bash/src/parse.y"
1474 /* Case of regular command, but not a very
1475 interesting one. Return a NULL command. */
1476 global_command = (COMMAND *)NULL;
1481 #line 343 "/usr/homes/chet/src/bash/src/parse.y"
1483 /* Error during parsing. Return NULL command. */
1484 global_command = (COMMAND *)NULL;
1485 eof_encountered = 0;
1486 /* discard_parser_constructs (1); */
1498 #line 358 "/usr/homes/chet/src/bash/src/parse.y"
1500 /* Case of EOF seen by itself. Do ignoreeof or
1502 global_command = (COMMAND *)NULL;
1503 handle_eof_input_unit ();
1508 #line 368 "/usr/homes/chet/src/bash/src/parse.y"
1509 { yyval.word_list = make_word_list (yyvsp[0].word, (WORD_LIST *)NULL); }
1512 #line 370 "/usr/homes/chet/src/bash/src/parse.y"
1513 { yyval.word_list = make_word_list (yyvsp[0].word, yyvsp[-1].word_list); }
1516 #line 374 "/usr/homes/chet/src/bash/src/parse.y"
1518 redir.filename = yyvsp[0].word;
1519 yyval.redirect = make_redirection (1, r_output_direction, redir);
1523 #line 379 "/usr/homes/chet/src/bash/src/parse.y"
1525 redir.filename = yyvsp[0].word;
1526 yyval.redirect = make_redirection (0, r_input_direction, redir);
1530 #line 384 "/usr/homes/chet/src/bash/src/parse.y"
1532 redir.filename = yyvsp[0].word;
1533 yyval.redirect = make_redirection (yyvsp[-2].number, r_output_direction, redir);
1537 #line 389 "/usr/homes/chet/src/bash/src/parse.y"
1539 redir.filename = yyvsp[0].word;
1540 yyval.redirect = make_redirection (yyvsp[-2].number, r_input_direction, redir);
1544 #line 394 "/usr/homes/chet/src/bash/src/parse.y"
1546 redir.filename = yyvsp[0].word;
1547 yyval.redirect = make_redirection (1, r_appending_to, redir);
1551 #line 399 "/usr/homes/chet/src/bash/src/parse.y"
1553 redir.filename = yyvsp[0].word;
1554 yyval.redirect = make_redirection (yyvsp[-2].number, r_appending_to, redir);
1558 #line 404 "/usr/homes/chet/src/bash/src/parse.y"
1560 redir.filename = yyvsp[0].word;
1561 yyval.redirect = make_redirection (0, r_reading_until, redir);
1562 redir_stack[need_here_doc++] = yyval.redirect;
1566 #line 410 "/usr/homes/chet/src/bash/src/parse.y"
1568 redir.filename = yyvsp[0].word;
1569 yyval.redirect = make_redirection (yyvsp[-2].number, r_reading_until, redir);
1570 redir_stack[need_here_doc++] = yyval.redirect;
1574 #line 416 "/usr/homes/chet/src/bash/src/parse.y"
1576 redir.filename = yyvsp[0].word;
1577 yyval.redirect = make_redirection (0, r_reading_string, redir);
1581 #line 421 "/usr/homes/chet/src/bash/src/parse.y"
1583 redir.filename = yyvsp[0].word;
1584 yyval.redirect = make_redirection (yyvsp[-2].number, r_reading_string, redir);
1588 #line 426 "/usr/homes/chet/src/bash/src/parse.y"
1590 redir.dest = yyvsp[0].number;
1591 yyval.redirect = make_redirection (0, r_duplicating_input, redir);
1595 #line 431 "/usr/homes/chet/src/bash/src/parse.y"
1597 redir.dest = yyvsp[0].number;
1598 yyval.redirect = make_redirection (yyvsp[-2].number, r_duplicating_input, redir);
1602 #line 436 "/usr/homes/chet/src/bash/src/parse.y"
1604 redir.dest = yyvsp[0].number;
1605 yyval.redirect = make_redirection (1, r_duplicating_output, redir);
1609 #line 441 "/usr/homes/chet/src/bash/src/parse.y"
1611 redir.dest = yyvsp[0].number;
1612 yyval.redirect = make_redirection (yyvsp[-2].number, r_duplicating_output, redir);
1616 #line 446 "/usr/homes/chet/src/bash/src/parse.y"
1618 redir.filename = yyvsp[0].word;
1619 yyval.redirect = make_redirection (0, r_duplicating_input_word, redir);
1623 #line 451 "/usr/homes/chet/src/bash/src/parse.y"
1625 redir.filename = yyvsp[0].word;
1626 yyval.redirect = make_redirection (yyvsp[-2].number, r_duplicating_input_word, redir);
1630 #line 456 "/usr/homes/chet/src/bash/src/parse.y"
1632 redir.filename = yyvsp[0].word;
1633 yyval.redirect = make_redirection (1, r_duplicating_output_word, redir);
1637 #line 461 "/usr/homes/chet/src/bash/src/parse.y"
1639 redir.filename = yyvsp[0].word;
1640 yyval.redirect = make_redirection (yyvsp[-2].number, r_duplicating_output_word, redir);
1644 #line 466 "/usr/homes/chet/src/bash/src/parse.y"
1646 redir.filename = yyvsp[0].word;
1647 yyval.redirect = make_redirection
1648 (0, r_deblank_reading_until, redir);
1649 redir_stack[need_here_doc++] = yyval.redirect;
1653 #line 473 "/usr/homes/chet/src/bash/src/parse.y"
1655 redir.filename = yyvsp[0].word;
1656 yyval.redirect = make_redirection
1657 (yyvsp[-2].number, r_deblank_reading_until, redir);
1658 redir_stack[need_here_doc++] = yyval.redirect;
1662 #line 480 "/usr/homes/chet/src/bash/src/parse.y"
1665 yyval.redirect = make_redirection (1, r_close_this, redir);
1669 #line 485 "/usr/homes/chet/src/bash/src/parse.y"
1672 yyval.redirect = make_redirection (yyvsp[-2].number, r_close_this, redir);
1676 #line 490 "/usr/homes/chet/src/bash/src/parse.y"
1679 yyval.redirect = make_redirection (0, r_close_this, redir);
1683 #line 495 "/usr/homes/chet/src/bash/src/parse.y"
1686 yyval.redirect = make_redirection (yyvsp[-2].number, r_close_this, redir);
1690 #line 500 "/usr/homes/chet/src/bash/src/parse.y"
1692 redir.filename = yyvsp[0].word;
1693 yyval.redirect = make_redirection (1, r_err_and_out, redir);
1697 #line 505 "/usr/homes/chet/src/bash/src/parse.y"
1699 redir.filename = yyvsp[0].word;
1700 yyval.redirect = make_redirection (yyvsp[-2].number, r_input_output, redir);
1704 #line 510 "/usr/homes/chet/src/bash/src/parse.y"
1706 redir.filename = yyvsp[0].word;
1707 yyval.redirect = make_redirection (0, r_input_output, redir);
1711 #line 515 "/usr/homes/chet/src/bash/src/parse.y"
1713 redir.filename = yyvsp[0].word;
1714 yyval.redirect = make_redirection (1, r_output_force, redir);
1718 #line 520 "/usr/homes/chet/src/bash/src/parse.y"
1720 redir.filename = yyvsp[0].word;
1721 yyval.redirect = make_redirection (yyvsp[-2].number, r_output_force, redir);
1725 #line 527 "/usr/homes/chet/src/bash/src/parse.y"
1726 { yyval.element.word = yyvsp[0].word; yyval.element.redirect = 0; }
1729 #line 529 "/usr/homes/chet/src/bash/src/parse.y"
1730 { yyval.element.word = yyvsp[0].word; yyval.element.redirect = 0; }
1733 #line 531 "/usr/homes/chet/src/bash/src/parse.y"
1734 { yyval.element.redirect = yyvsp[0].redirect; yyval.element.word = 0; }
1737 #line 535 "/usr/homes/chet/src/bash/src/parse.y"
1739 yyval.redirect = yyvsp[0].redirect;
1743 #line 539 "/usr/homes/chet/src/bash/src/parse.y"
1745 register REDIRECT *t;
1747 for (t = yyvsp[-1].redirect; t->next; t = t->next)
1749 t->next = yyvsp[0].redirect;
1750 yyval.redirect = yyvsp[-1].redirect;
1754 #line 550 "/usr/homes/chet/src/bash/src/parse.y"
1755 { yyval.command = make_simple_command (yyvsp[0].element, (COMMAND *)NULL); }
1758 #line 552 "/usr/homes/chet/src/bash/src/parse.y"
1759 { yyval.command = make_simple_command (yyvsp[0].element, yyvsp[-1].command); }
1762 #line 556 "/usr/homes/chet/src/bash/src/parse.y"
1763 { yyval.command = clean_simple_command (yyvsp[0].command); }
1766 #line 558 "/usr/homes/chet/src/bash/src/parse.y"
1767 { yyval.command = yyvsp[0].command; }
1770 #line 560 "/usr/homes/chet/src/bash/src/parse.y"
1774 tc = yyvsp[-1].command;
1777 register REDIRECT *t;
1778 for (t = tc->redirects; t->next; t = t->next)
1780 t->next = yyvsp[0].redirect;
1783 tc->redirects = yyvsp[0].redirect;
1784 yyval.command = yyvsp[-1].command;
1788 #line 576 "/usr/homes/chet/src/bash/src/parse.y"
1789 { yyval.command = yyvsp[0].command; }
1792 #line 580 "/usr/homes/chet/src/bash/src/parse.y"
1793 { yyval.command = yyvsp[0].command; }
1796 #line 582 "/usr/homes/chet/src/bash/src/parse.y"
1797 { yyval.command = yyvsp[0].command; }
1800 #line 584 "/usr/homes/chet/src/bash/src/parse.y"
1801 { yyval.command = make_while_command (yyvsp[-3].command, yyvsp[-1].command); }
1804 #line 586 "/usr/homes/chet/src/bash/src/parse.y"
1805 { yyval.command = make_until_command (yyvsp[-3].command, yyvsp[-1].command); }
1808 #line 588 "/usr/homes/chet/src/bash/src/parse.y"
1809 { yyval.command = yyvsp[0].command; }
1812 #line 590 "/usr/homes/chet/src/bash/src/parse.y"
1813 { yyval.command = yyvsp[0].command; }
1816 #line 592 "/usr/homes/chet/src/bash/src/parse.y"
1817 { yyval.command = yyvsp[0].command; }
1820 #line 594 "/usr/homes/chet/src/bash/src/parse.y"
1821 { yyval.command = yyvsp[0].command; }
1824 #line 596 "/usr/homes/chet/src/bash/src/parse.y"
1825 { yyval.command = yyvsp[0].command; }
1828 #line 598 "/usr/homes/chet/src/bash/src/parse.y"
1829 { yyval.command = yyvsp[0].command; }
1832 #line 600 "/usr/homes/chet/src/bash/src/parse.y"
1833 { yyval.command = yyvsp[0].command; }
1836 #line 604 "/usr/homes/chet/src/bash/src/parse.y"
1837 { yyval.command = make_for_command (yyvsp[-4].word, add_string_to_list ("\"$@\"", (WORD_LIST *)NULL), yyvsp[-1].command); }
1840 #line 606 "/usr/homes/chet/src/bash/src/parse.y"
1841 { yyval.command = make_for_command (yyvsp[-4].word, add_string_to_list ("$@", (WORD_LIST *)NULL), yyvsp[-1].command); }
1844 #line 608 "/usr/homes/chet/src/bash/src/parse.y"
1845 { yyval.command = make_for_command (yyvsp[-5].word, add_string_to_list ("\"$@\"", (WORD_LIST *)NULL), yyvsp[-1].command); }
1848 #line 610 "/usr/homes/chet/src/bash/src/parse.y"
1849 { yyval.command = make_for_command (yyvsp[-5].word, add_string_to_list ("\"$@\"", (WORD_LIST *)NULL), yyvsp[-1].command); }
1852 #line 612 "/usr/homes/chet/src/bash/src/parse.y"
1853 { yyval.command = make_for_command (yyvsp[-8].word, REVERSE_LIST (yyvsp[-5].word_list, WORD_LIST *), yyvsp[-1].command); }
1856 #line 614 "/usr/homes/chet/src/bash/src/parse.y"
1857 { yyval.command = make_for_command (yyvsp[-8].word, REVERSE_LIST (yyvsp[-5].word_list, WORD_LIST *), yyvsp[-1].command); }
1860 #line 616 "/usr/homes/chet/src/bash/src/parse.y"
1861 { yyval.command = make_for_command (yyvsp[-7].word, (WORD_LIST *)NULL, yyvsp[-1].command); }
1864 #line 618 "/usr/homes/chet/src/bash/src/parse.y"
1865 { yyval.command = make_for_command (yyvsp[-7].word, (WORD_LIST *)NULL, yyvsp[-1].command); }
1868 #line 622 "/usr/homes/chet/src/bash/src/parse.y"
1869 { yyval.command = make_arith_for_command (yyvsp[-5].word_list, yyvsp[-1].command, arith_for_lineno); }
1872 #line 624 "/usr/homes/chet/src/bash/src/parse.y"
1873 { yyval.command = make_arith_for_command (yyvsp[-5].word_list, yyvsp[-1].command, arith_for_lineno); }
1876 #line 626 "/usr/homes/chet/src/bash/src/parse.y"
1877 { yyval.command = make_arith_for_command (yyvsp[-3].word_list, yyvsp[-1].command, arith_for_lineno); }
1880 #line 628 "/usr/homes/chet/src/bash/src/parse.y"
1881 { yyval.command = make_arith_for_command (yyvsp[-3].word_list, yyvsp[-1].command, arith_for_lineno); }
1884 #line 632 "/usr/homes/chet/src/bash/src/parse.y"
1886 yyval.command = make_select_command (yyvsp[-4].word, add_string_to_list ("\"$@\"", (WORD_LIST *)NULL), yyvsp[-1].command);
1890 #line 636 "/usr/homes/chet/src/bash/src/parse.y"
1892 yyval.command = make_select_command (yyvsp[-4].word, add_string_to_list ("$@", (WORD_LIST *)NULL), yyvsp[-1].command);
1896 #line 640 "/usr/homes/chet/src/bash/src/parse.y"
1898 yyval.command = make_select_command (yyvsp[-5].word, add_string_to_list ("\"$@\"", (WORD_LIST *)NULL), yyvsp[-1].command);
1902 #line 644 "/usr/homes/chet/src/bash/src/parse.y"
1904 yyval.command = make_select_command (yyvsp[-5].word, add_string_to_list ("\"$@\"", (WORD_LIST *)NULL), yyvsp[-1].command);
1908 #line 648 "/usr/homes/chet/src/bash/src/parse.y"
1910 yyval.command = make_select_command (yyvsp[-8].word, REVERSE_LIST (yyvsp[-5].word_list, WORD_LIST *), yyvsp[-1].command);
1914 #line 652 "/usr/homes/chet/src/bash/src/parse.y"
1916 yyval.command = make_select_command (yyvsp[-8].word, REVERSE_LIST (yyvsp[-5].word_list, WORD_LIST *), yyvsp[-1].command);
1920 #line 658 "/usr/homes/chet/src/bash/src/parse.y"
1921 { yyval.command = make_case_command (yyvsp[-4].word, (PATTERN_LIST *)NULL); }
1924 #line 660 "/usr/homes/chet/src/bash/src/parse.y"
1925 { yyval.command = make_case_command (yyvsp[-5].word, yyvsp[-2].pattern); }
1928 #line 662 "/usr/homes/chet/src/bash/src/parse.y"
1929 { yyval.command = make_case_command (yyvsp[-4].word, yyvsp[-1].pattern); }
1932 #line 666 "/usr/homes/chet/src/bash/src/parse.y"
1933 { yyval.command = make_function_def (yyvsp[-4].word, yyvsp[0].command, function_dstart, function_bstart); }
1936 #line 669 "/usr/homes/chet/src/bash/src/parse.y"
1937 { yyval.command = make_function_def (yyvsp[-4].word, yyvsp[0].command, function_dstart, function_bstart); }
1940 #line 672 "/usr/homes/chet/src/bash/src/parse.y"
1941 { yyval.command = make_function_def (yyvsp[-2].word, yyvsp[0].command, function_dstart, function_bstart); }
1944 #line 677 "/usr/homes/chet/src/bash/src/parse.y"
1945 { yyval.command = yyvsp[0].command; }
1948 #line 679 "/usr/homes/chet/src/bash/src/parse.y"
1952 tc = yyvsp[-1].command;
1953 /* According to Posix.2 3.9.5, redirections
1954 specified after the body of a function should
1955 be attached to the function and performed when
1956 the function is executed, not as part of the
1957 function definition command. */
1958 /* XXX - I don't think it matters, but we might
1959 want to change this in the future to avoid
1960 problems differentiating between a function
1961 definition with a redirection and a function
1962 definition containing a single command with a
1963 redirection. The two are semantically equivalent,
1964 though -- the only difference is in how the
1965 command printing code displays the redirections. */
1968 register REDIRECT *t;
1969 for (t = tc->redirects; t->next; t = t->next)
1971 t->next = yyvsp[0].redirect;
1974 tc->redirects = yyvsp[0].redirect;
1975 yyval.command = yyvsp[-1].command;
1979 #line 710 "/usr/homes/chet/src/bash/src/parse.y"
1981 yyval.command = make_subshell_command (yyvsp[-1].command);
1982 yyval.command->flags |= CMD_WANT_SUBSHELL;
1986 #line 717 "/usr/homes/chet/src/bash/src/parse.y"
1987 { yyval.command = make_if_command (yyvsp[-3].command, yyvsp[-1].command, (COMMAND *)NULL); }
1990 #line 719 "/usr/homes/chet/src/bash/src/parse.y"
1991 { yyval.command = make_if_command (yyvsp[-5].command, yyvsp[-3].command, yyvsp[-1].command); }
1994 #line 721 "/usr/homes/chet/src/bash/src/parse.y"
1995 { yyval.command = make_if_command (yyvsp[-4].command, yyvsp[-2].command, yyvsp[-1].command); }
1998 #line 726 "/usr/homes/chet/src/bash/src/parse.y"
1999 { yyval.command = make_group_command (yyvsp[-1].command); }
2002 #line 730 "/usr/homes/chet/src/bash/src/parse.y"
2003 { yyval.command = make_arith_command (yyvsp[0].word_list); }
2006 #line 734 "/usr/homes/chet/src/bash/src/parse.y"
2007 { yyval.command = yyvsp[-1].command; }
2010 #line 738 "/usr/homes/chet/src/bash/src/parse.y"
2011 { yyval.command = make_if_command (yyvsp[-2].command, yyvsp[0].command, (COMMAND *)NULL); }
2014 #line 740 "/usr/homes/chet/src/bash/src/parse.y"
2015 { yyval.command = make_if_command (yyvsp[-4].command, yyvsp[-2].command, yyvsp[0].command); }
2018 #line 742 "/usr/homes/chet/src/bash/src/parse.y"
2019 { yyval.command = make_if_command (yyvsp[-3].command, yyvsp[-1].command, yyvsp[0].command); }
2022 #line 747 "/usr/homes/chet/src/bash/src/parse.y"
2023 { yyvsp[0].pattern->next = yyvsp[-1].pattern; yyval.pattern = yyvsp[0].pattern; }
2026 #line 751 "/usr/homes/chet/src/bash/src/parse.y"
2027 { yyval.pattern = make_pattern_list (yyvsp[-2].word_list, yyvsp[0].command); }
2030 #line 753 "/usr/homes/chet/src/bash/src/parse.y"
2031 { yyval.pattern = make_pattern_list (yyvsp[-2].word_list, (COMMAND *)NULL); }
2034 #line 755 "/usr/homes/chet/src/bash/src/parse.y"
2035 { yyval.pattern = make_pattern_list (yyvsp[-2].word_list, yyvsp[0].command); }
2038 #line 757 "/usr/homes/chet/src/bash/src/parse.y"
2039 { yyval.pattern = make_pattern_list (yyvsp[-2].word_list, (COMMAND *)NULL); }
2042 #line 762 "/usr/homes/chet/src/bash/src/parse.y"
2043 { yyvsp[-1].pattern->next = yyvsp[-2].pattern; yyval.pattern = yyvsp[-1].pattern; }
2046 #line 766 "/usr/homes/chet/src/bash/src/parse.y"
2047 { yyval.word_list = make_word_list (yyvsp[0].word, (WORD_LIST *)NULL); }
2050 #line 768 "/usr/homes/chet/src/bash/src/parse.y"
2051 { yyval.word_list = make_word_list (yyvsp[0].word, yyvsp[-2].word_list); }
2054 #line 777 "/usr/homes/chet/src/bash/src/parse.y"
2056 yyval.command = yyvsp[0].command;
2058 gather_here_documents ();
2062 #line 786 "/usr/homes/chet/src/bash/src/parse.y"
2064 yyval.command = yyvsp[0].command;
2068 #line 793 "/usr/homes/chet/src/bash/src/parse.y"
2070 if (yyvsp[-2].command->type == cm_connection)
2071 yyval.command = connect_async_list (yyvsp[-2].command, (COMMAND *)NULL, '&');
2073 yyval.command = command_connect (yyvsp[-2].command, (COMMAND *)NULL, '&');
2077 #line 804 "/usr/homes/chet/src/bash/src/parse.y"
2078 { yyval.command = command_connect (yyvsp[-3].command, yyvsp[0].command, AND_AND); }
2081 #line 806 "/usr/homes/chet/src/bash/src/parse.y"
2082 { yyval.command = command_connect (yyvsp[-3].command, yyvsp[0].command, OR_OR); }
2085 #line 808 "/usr/homes/chet/src/bash/src/parse.y"
2087 if (yyvsp[-3].command->type == cm_connection)
2088 yyval.command = connect_async_list (yyvsp[-3].command, yyvsp[0].command, '&');
2090 yyval.command = command_connect (yyvsp[-3].command, yyvsp[0].command, '&');
2094 #line 815 "/usr/homes/chet/src/bash/src/parse.y"
2095 { yyval.command = command_connect (yyvsp[-3].command, yyvsp[0].command, ';'); }
2098 #line 817 "/usr/homes/chet/src/bash/src/parse.y"
2099 { yyval.command = command_connect (yyvsp[-3].command, yyvsp[0].command, ';'); }
2102 #line 819 "/usr/homes/chet/src/bash/src/parse.y"
2103 { yyval.command = yyvsp[0].command; }
2106 #line 842 "/usr/homes/chet/src/bash/src/parse.y"
2108 yyval.command = yyvsp[0].command;
2110 gather_here_documents ();
2114 #line 848 "/usr/homes/chet/src/bash/src/parse.y"
2116 if (yyvsp[-1].command->type == cm_connection)
2117 yyval.command = connect_async_list (yyvsp[-1].command, (COMMAND *)NULL, '&');
2119 yyval.command = command_connect (yyvsp[-1].command, (COMMAND *)NULL, '&');
2121 gather_here_documents ();
2125 #line 857 "/usr/homes/chet/src/bash/src/parse.y"
2127 yyval.command = yyvsp[-1].command;
2129 gather_here_documents ();
2133 #line 865 "/usr/homes/chet/src/bash/src/parse.y"
2134 { yyval.command = command_connect (yyvsp[-3].command, yyvsp[0].command, AND_AND); }
2137 #line 867 "/usr/homes/chet/src/bash/src/parse.y"
2138 { yyval.command = command_connect (yyvsp[-3].command, yyvsp[0].command, OR_OR); }
2141 #line 869 "/usr/homes/chet/src/bash/src/parse.y"
2143 if (yyvsp[-2].command->type == cm_connection)
2144 yyval.command = connect_async_list (yyvsp[-2].command, yyvsp[0].command, '&');
2146 yyval.command = command_connect (yyvsp[-2].command, yyvsp[0].command, '&');
2150 #line 876 "/usr/homes/chet/src/bash/src/parse.y"
2151 { yyval.command = command_connect (yyvsp[-2].command, yyvsp[0].command, ';'); }
2154 #line 879 "/usr/homes/chet/src/bash/src/parse.y"
2155 { yyval.command = yyvsp[0].command; }
2158 #line 883 "/usr/homes/chet/src/bash/src/parse.y"
2159 { yyval.command = yyvsp[0].command; }
2162 #line 885 "/usr/homes/chet/src/bash/src/parse.y"
2164 yyvsp[0].command->flags |= CMD_INVERT_RETURN;
2165 yyval.command = yyvsp[0].command;
2169 #line 890 "/usr/homes/chet/src/bash/src/parse.y"
2171 yyvsp[0].command->flags |= yyvsp[-1].number;
2172 yyval.command = yyvsp[0].command;
2176 #line 895 "/usr/homes/chet/src/bash/src/parse.y"
2178 yyvsp[0].command->flags |= yyvsp[-2].number|CMD_INVERT_RETURN;
2179 yyval.command = yyvsp[0].command;
2183 #line 900 "/usr/homes/chet/src/bash/src/parse.y"
2185 yyvsp[0].command->flags |= yyvsp[-1].number|CMD_INVERT_RETURN;
2186 yyval.command = yyvsp[0].command;
2190 #line 908 "/usr/homes/chet/src/bash/src/parse.y"
2191 { yyval.command = command_connect (yyvsp[-3].command, yyvsp[0].command, '|'); }
2194 #line 910 "/usr/homes/chet/src/bash/src/parse.y"
2195 { yyval.command = yyvsp[0].command; }
2198 #line 914 "/usr/homes/chet/src/bash/src/parse.y"
2199 { yyval.number = CMD_TIME_PIPELINE; }
2202 #line 916 "/usr/homes/chet/src/bash/src/parse.y"
2203 { yyval.number = CMD_TIME_PIPELINE|CMD_TIME_POSIX; }
2207 #line 705 "/usr/local/share/bison/bison.simple"
2219 short *yyssp1 = yyss - 1;
2220 YYFPRINTF (stderr, "state stack now");
2221 while (yyssp1 != yyssp)
2222 YYFPRINTF (stderr, " %d", *++yyssp1);
2223 YYFPRINTF (stderr, "\n");
2232 /* Now `shift' the result of the reduction. Determine what state
2233 that goes to, based on the state we popped back to and the rule
2234 number reduced by. */
2238 yystate = yypgoto[yyn - YYNTBASE] + *yyssp;
2239 if (yystate >= 0 && yystate <= YYLAST && yycheck[yystate] == *yyssp)
2240 yystate = yytable[yystate];
2242 yystate = yydefgoto[yyn - YYNTBASE];
2247 /*------------------------------------.
2248 | yyerrlab -- here on detecting error |
2249 `------------------------------------*/
2251 /* If not already recovering from an error, report this error. */
2256 #ifdef YYERROR_VERBOSE
2257 yyn = yypact[yystate];
2259 if (yyn > YYFLAG && yyn < YYLAST)
2261 YYSIZE_T yysize = 0;
2266 /* Start YYX at -YYN if negative to avoid negative indexes in
2268 for (yyx = yyn < 0 ? -yyn : 0;
2269 yyx < (int) (sizeof (yytname) / sizeof (char *)); yyx++)
2270 if (yycheck[yyx + yyn] == yyx)
2271 yysize += yystrlen (yytname[yyx]) + 15, yycount++;
2272 yysize += yystrlen ("parse error, unexpected ") + 1;
2273 yysize += yystrlen (yytname[YYTRANSLATE (yychar)]);
2274 yymsg = (char *) YYSTACK_ALLOC (yysize);
2277 char *yyp = yystpcpy (yymsg, "parse error, unexpected ");
2278 yyp = yystpcpy (yyp, yytname[YYTRANSLATE (yychar)]);
2283 for (yyx = yyn < 0 ? -yyn : 0;
2284 yyx < (int) (sizeof (yytname) / sizeof (char *));
2286 if (yycheck[yyx + yyn] == yyx)
2288 const char *yyq = ! yycount ? ", expecting " : " or ";
2289 yyp = yystpcpy (yyp, yyq);
2290 yyp = yystpcpy (yyp, yytname[yyx]);
2295 YYSTACK_FREE (yymsg);
2298 yyerror ("parse error; also virtual memory exhausted");
2301 #endif /* defined (YYERROR_VERBOSE) */
2302 yyerror ("parse error");
2307 /*--------------------------------------------------.
2308 | yyerrlab1 -- error raised explicitly by an action |
2309 `--------------------------------------------------*/
2311 if (yyerrstatus == 3)
2313 /* If just tried and failed to reuse lookahead token after an
2314 error, discard it. */
2316 /* return failure if at end of input */
2317 if (yychar == YYEOF)
2319 YYDPRINTF ((stderr, "Discarding token %d (%s).\n",
2320 yychar, yytname[yychar1]));
2324 /* Else will try to reuse lookahead token after shifting the error
2327 yyerrstatus = 3; /* Each real token shifted decrements this */
2332 /*-------------------------------------------------------------------.
2333 | yyerrdefault -- current state does not do anything special for the |
2335 `-------------------------------------------------------------------*/
2338 /* This is wrong; only states that explicitly want error tokens
2339 should shift them. */
2341 /* If its default is to accept any token, ok. Otherwise pop it. */
2342 yyn = yydefact[yystate];
2348 /*---------------------------------------------------------------.
2349 | yyerrpop -- pop the current state because it cannot handle the |
2351 `---------------------------------------------------------------*/
2364 short *yyssp1 = yyss - 1;
2365 YYFPRINTF (stderr, "Error: state stack now");
2366 while (yyssp1 != yyssp)
2367 YYFPRINTF (stderr, " %d", *++yyssp1);
2368 YYFPRINTF (stderr, "\n");
2376 yyn = yypact[yystate];
2381 if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != YYTERROR)
2398 YYDPRINTF ((stderr, "Shifting error token, "));
2409 /*-------------------------------------.
2410 | yyacceptlab -- YYACCEPT comes here. |
2411 `-------------------------------------*/
2416 /*-----------------------------------.
2417 | yyabortlab -- YYABORT comes here. |
2418 `-----------------------------------*/
2423 /*---------------------------------------------.
2424 | yyoverflowab -- parser overflow comes here. |
2425 `---------------------------------------------*/
2427 yyerror ("parser stack overflow");
2434 YYSTACK_FREE (yyss);
2438 #line 918 "/usr/homes/chet/src/bash/src/parse.y"
2441 /* Possible states for the parser that require it to do special things. */
2442 #define PST_CASEPAT 0x001 /* in a case pattern list */
2443 #define PST_ALEXPNEXT 0x002 /* expand next word for aliases */
2444 #define PST_ALLOWOPNBRC 0x004 /* allow open brace for function def */
2445 #define PST_NEEDCLOSBRC 0x008 /* need close brace */
2446 #define PST_DBLPAREN 0x010 /* double-paren parsing */
2447 #define PST_SUBSHELL 0x020 /* ( ... ) subshell */
2448 #define PST_CMDSUBST 0x040 /* $( ... ) command substitution */
2449 #define PST_CASESTMT 0x080 /* parsing a case statement */
2450 #define PST_CONDCMD 0x100 /* parsing a [[...]] command */
2451 #define PST_CONDEXPR 0x200 /* parsing the guts of [[...]] */
2452 #define PST_ARITHFOR 0x400 /* parsing an arithmetic for command */
2454 /* Initial size to allocate for tokens, and the
2455 amount to grow them by. */
2456 #define TOKEN_DEFAULT_INITIAL_SIZE 496
2457 #define TOKEN_DEFAULT_GROW_SIZE 512
2459 /* The token currently being read. */
2460 static int current_token;
2462 /* The last read token, or NULL. read_token () uses this for context
2464 static int last_read_token;
2466 /* The token read prior to last_read_token. */
2467 static int token_before_that;
2469 /* The token read prior to token_before_that. */
2470 static int two_tokens_ago;
2472 /* If non-zero, it is the token that we want read_token to return
2473 regardless of what text is (or isn't) present to be read. This
2474 is reset by read_token. If token_to_read == WORD or
2475 ASSIGNMENT_WORD, yylval.word should be set to word_desc_to_read. */
2476 static int token_to_read;
2477 static WORD_DESC *word_desc_to_read;
2479 /* The current parser state. */
2480 static int parser_state;
2482 /* Global var is non-zero when end of file has been reached. */
2483 int EOF_Reached = 0;
2496 /* yy_getc () returns the next available character from input or EOF.
2497 yy_ungetc (c) makes `c' the next character to read.
2498 init_yy_io (get, unget, type, location) makes the function GET the
2499 installed function for getting the next character, makes UNGET the
2500 installed function for un-getting a character, sets the type of stream
2501 (either string or file) from TYPE, and makes LOCATION point to where
2502 the input is coming from. */
2504 /* Unconditionally returns end-of-file. */
2511 /* Variable containing the current get and unget functions.
2512 See ./input.h for a clearer description. */
2513 BASH_INPUT bash_input;
2515 /* Set all of the fields in BASH_INPUT to NULL. Free bash_input.name if it
2516 is non-null, avoiding a memory leak. */
2518 initialize_bash_input ()
2520 bash_input.type = st_none;
2521 FREE (bash_input.name);
2522 bash_input.name = (char *)NULL;
2523 bash_input.location.file = (FILE *)NULL;
2524 bash_input.location.string = (char *)NULL;
2525 bash_input.getter = (sh_cget_func_t *)NULL;
2526 bash_input.ungetter = (sh_cunget_func_t *)NULL;
2529 /* Set the contents of the current bash input stream from
2530 GET, UNGET, TYPE, NAME, and LOCATION. */
2532 init_yy_io (get, unget, type, name, location)
2533 sh_cget_func_t *get;
2534 sh_cunget_func_t *unget;
2535 enum stream_type type;
2537 INPUT_STREAM location;
2539 bash_input.type = type;
2540 FREE (bash_input.name);
2541 bash_input.name = name ? savestring (name) : (char *)NULL;
2545 memcpy((char *)&bash_input.location.string, (char *)&location.string, sizeof(location));
2547 bash_input.location = location;
2549 bash_input.getter = get;
2550 bash_input.ungetter = unget;
2556 return (bash_input.name ? bash_input.name : "stdin");
2559 /* Call this to get the next character of input. */
2563 return (*(bash_input.getter)) ();
2566 /* Call this to unget C. That is, to make C the next character
2572 return (*(bash_input.ungetter)) (c);
2575 #if defined (BUFFERED_INPUT)
2576 #ifdef INCLUDE_UNUSED
2578 input_file_descriptor ()
2580 switch (bash_input.type)
2583 return (fileno (bash_input.location.file));
2585 return (bash_input.location.buffered_fd);
2588 return (fileno (stdin));
2592 #endif /* BUFFERED_INPUT */
2594 /* **************************************************************** */
2596 /* Let input be read from readline (). */
2598 /* **************************************************************** */
2600 #if defined (READLINE)
2601 char *current_readline_prompt = (char *)NULL;
2602 char *current_readline_line = (char *)NULL;
2603 int current_readline_line_index = 0;
2608 SigHandler *old_sigint;
2612 if (!current_readline_line)
2614 if (!bash_readline_initialized)
2615 initialize_readline ();
2617 #if defined (JOB_CONTROL)
2619 give_terminal_to (shell_pgrp, 0);
2620 #endif /* JOB_CONTROL */
2622 old_sigint = (SigHandler *)NULL;
2623 if (signal_is_ignored (SIGINT) == 0)
2625 old_sigint = (SigHandler *)set_signal_handler (SIGINT, sigint_sighandler);
2626 interrupt_immediately++;
2629 current_readline_line = readline (current_readline_prompt ?
2630 current_readline_prompt : "");
2632 if (signal_is_ignored (SIGINT) == 0 && old_sigint)
2634 interrupt_immediately--;
2635 set_signal_handler (SIGINT, old_sigint);
2639 /* Reset the prompt to the decoded value of prompt_string_pointer. */
2640 reset_readline_prompt ();
2643 if (current_readline_line == 0)
2646 current_readline_line_index = 0;
2647 line_len = strlen (current_readline_line);
2649 current_readline_line = (char *)xrealloc (current_readline_line, 2 + line_len);
2650 current_readline_line[line_len++] = '\n';
2651 current_readline_line[line_len] = '\0';
2654 if (current_readline_line[current_readline_line_index] == 0)
2656 free (current_readline_line);
2657 current_readline_line = (char *)NULL;
2658 return (yy_readline_get ());
2662 c = current_readline_line[current_readline_line_index++];
2668 yy_readline_unget (c)
2671 if (current_readline_line_index && current_readline_line)
2672 current_readline_line[--current_readline_line_index] = c;
2677 with_input_from_stdin ()
2679 INPUT_STREAM location;
2681 if (bash_input.type != st_stdin && stream_on_stack (st_stdin) == 0)
2683 location.string = current_readline_line;
2684 init_yy_io (yy_readline_get, yy_readline_unget,
2685 st_stdin, "readline stdin", location);
2689 #else /* !READLINE */
2692 with_input_from_stdin ()
2694 with_input_from_stream (stdin, "stdin");
2696 #endif /* !READLINE */
2698 /* **************************************************************** */
2700 /* Let input come from STRING. STRING is zero terminated. */
2702 /* **************************************************************** */
2707 register char *string;
2708 register unsigned char c;
2710 string = bash_input.location.string;
2712 /* If the string doesn't exist, or is empty, EOF found. */
2713 if (string && *string)
2716 bash_input.location.string = string;
2727 *(--bash_input.location.string) = c;
2732 with_input_from_string (string, name)
2736 INPUT_STREAM location;
2738 location.string = string;
2739 init_yy_io (yy_string_get, yy_string_unget, st_string, name, location);
2742 /* **************************************************************** */
2744 /* Let input come from STREAM. */
2746 /* **************************************************************** */
2748 /* These two functions used to test the value of the HAVE_RESTARTABLE_SYSCALLS
2749 define, and just use getc/ungetc if it was defined, but since bash
2750 installs its signal handlers without the SA_RESTART flag, some signals
2751 (like SIGCHLD, SIGWINCH, etc.) received during a read(2) will not cause
2752 the read to be restarted. We need to restart it ourselves. */
2760 if (bash_input.location.file)
2761 result = getc_with_restart (bash_input.location.file);
2770 return (ungetc_with_restart (c, bash_input.location.file));
2774 with_input_from_stream (stream, name)
2778 INPUT_STREAM location;
2780 location.file = stream;
2781 init_yy_io (yy_stream_get, yy_stream_unget, st_stream, name, location);
2784 typedef struct stream_saver {
2785 struct stream_saver *next;
2786 BASH_INPUT bash_input;
2788 #if defined (BUFFERED_INPUT)
2789 BUFFERED_STREAM *bstream;
2790 #endif /* BUFFERED_INPUT */
2793 /* The globally known line number. */
2794 int line_number = 0;
2796 #if defined (COND_COMMAND)
2797 static int cond_lineno;
2798 static int cond_token;
2801 STREAM_SAVER *stream_list = (STREAM_SAVER *)NULL;
2804 push_stream (reset_lineno)
2807 STREAM_SAVER *saver = (STREAM_SAVER *)xmalloc (sizeof (STREAM_SAVER));
2809 xbcopy ((char *)&bash_input, (char *)&(saver->bash_input), sizeof (BASH_INPUT));
2811 #if defined (BUFFERED_INPUT)
2812 saver->bstream = (BUFFERED_STREAM *)NULL;
2813 /* If we have a buffered stream, clear out buffers[fd]. */
2814 if (bash_input.type == st_bstream && bash_input.location.buffered_fd >= 0)
2815 saver->bstream = set_buffered_stream (bash_input.location.buffered_fd,
2816 (BUFFERED_STREAM *)NULL);
2817 #endif /* BUFFERED_INPUT */
2819 saver->line = line_number;
2820 bash_input.name = (char *)NULL;
2821 saver->next = stream_list;
2822 stream_list = saver;
2835 STREAM_SAVER *saver = stream_list;
2838 stream_list = stream_list->next;
2840 init_yy_io (saver->bash_input.getter,
2841 saver->bash_input.ungetter,
2842 saver->bash_input.type,
2843 saver->bash_input.name,
2844 saver->bash_input.location);
2846 #if defined (BUFFERED_INPUT)
2847 /* If we have a buffered stream, restore buffers[fd]. */
2848 /* If the input file descriptor was changed while this was on the
2849 save stack, update the buffered fd to the new file descriptor and
2850 re-establish the buffer <-> bash_input fd correspondence. */
2851 if (bash_input.type == st_bstream && bash_input.location.buffered_fd >= 0)
2853 if (bash_input_fd_changed)
2855 bash_input_fd_changed = 0;
2856 if (default_buffered_input >= 0)
2858 bash_input.location.buffered_fd = default_buffered_input;
2859 saver->bstream->b_fd = default_buffered_input;
2860 SET_CLOSE_ON_EXEC (default_buffered_input);
2863 /* XXX could free buffered stream returned as result here. */
2864 set_buffered_stream (bash_input.location.buffered_fd, saver->bstream);
2866 #endif /* BUFFERED_INPUT */
2868 line_number = saver->line;
2870 FREE (saver->bash_input.name);
2875 /* Return 1 if a stream of type TYPE is saved on the stack. */
2877 stream_on_stack (type)
2878 enum stream_type type;
2880 register STREAM_SAVER *s;
2882 for (s = stream_list; s; s = s->next)
2883 if (s->bash_input.type == type)
2888 /* Save the current token state and return it in a malloced array. */
2894 ret = (int *)xmalloc (3 * sizeof (int));
2895 ret[0] = last_read_token;
2896 ret[1] = token_before_that;
2897 ret[2] = two_tokens_ago;
2902 restore_token_state (ts)
2907 last_read_token = ts[0];
2908 token_before_that = ts[1];
2909 two_tokens_ago = ts[2];
2913 * This is used to inhibit alias expansion and reserved word recognition
2914 * inside case statement pattern lists. A `case statement pattern list' is:
2916 * everything between the `in' in a `case word in' and the next ')'
2918 * everything between a `;;' and the next `)' or `esac'
2921 #if defined (ALIAS) || defined (DPAREN_ARITHMETIC)
2923 #if !defined (ALIAS)
2924 typedef void *alias_t;
2927 #define END_OF_ALIAS 0
2930 * Pseudo-global variables used in implementing token-wise alias expansion.
2934 * Pushing and popping strings. This works together with shell_getc to
2935 * implement alias expansion on a per-token basis.
2938 typedef struct string_saver {
2939 struct string_saver *next;
2940 int expand_alias; /* Value to set expand_alias to when string is popped. */
2943 alias_t *expander; /* alias that caused this line to be pushed. */
2945 int saved_line_size, saved_line_index, saved_line_terminator;
2948 STRING_SAVER *pushed_string_list = (STRING_SAVER *)NULL;
2951 * Push the current shell_input_line onto a stack of such lines and make S
2952 * the current input. Used when expanding aliases. EXPAND is used to set
2953 * the value of expand_next_token when the string is popped, so that the
2954 * word after the alias in the original line is handled correctly when the
2955 * alias expands to multiple words. TOKEN is the token that was expanded
2956 * into S; it is saved and used to prevent infinite recursive expansion.
2959 push_string (s, expand, ap)
2964 STRING_SAVER *temp = (STRING_SAVER *)xmalloc (sizeof (STRING_SAVER));
2966 temp->expand_alias = expand;
2967 temp->saved_line = shell_input_line;
2968 temp->saved_line_size = shell_input_line_size;
2969 temp->saved_line_index = shell_input_line_index;
2970 temp->saved_line_terminator = shell_input_line_terminator;
2972 temp->expander = ap;
2974 temp->next = pushed_string_list;
2975 pushed_string_list = temp;
2979 ap->flags |= AL_BEINGEXPANDED;
2982 shell_input_line = s;
2983 shell_input_line_size = strlen (s);
2984 shell_input_line_index = 0;
2985 shell_input_line_terminator = '\0';
2986 parser_state &= ~PST_ALEXPNEXT;
2988 set_line_mbstate ();
2992 * Make the top of the pushed_string stack be the current shell input.
2993 * Only called when there is something on the stack. Called from shell_getc
2994 * when it thinks it has consumed the string generated by an alias expansion
2995 * and needs to return to the original input line.
3002 FREE (shell_input_line);
3003 shell_input_line = pushed_string_list->saved_line;
3004 shell_input_line_index = pushed_string_list->saved_line_index;
3005 shell_input_line_size = pushed_string_list->saved_line_size;
3006 shell_input_line_terminator = pushed_string_list->saved_line_terminator;
3008 if (pushed_string_list->expand_alias)
3009 parser_state |= PST_ALEXPNEXT;
3011 parser_state &= ~PST_ALEXPNEXT;
3013 t = pushed_string_list;
3014 pushed_string_list = pushed_string_list->next;
3018 t->expander->flags &= ~AL_BEINGEXPANDED;
3023 set_line_mbstate ();
3029 register STRING_SAVER *t, *t1;
3031 for (t = pushed_string_list; t; )
3034 FREE (t->saved_line);
3037 t->expander->flags &= ~AL_BEINGEXPANDED;
3042 pushed_string_list = (STRING_SAVER *)NULL;
3045 #endif /* ALIAS || DPAREN_ARITHMETIC */
3047 /* Return a line of text, taken from wherever yylex () reads input.
3048 If there is no more input, then we return NULL. If REMOVE_QUOTED_NEWLINE
3049 is non-zero, we remove unquoted \<newline> pairs. This is used by
3050 read_secondary_line to read here documents. */
3052 read_a_line (remove_quoted_newline)
3053 int remove_quoted_newline;
3055 static char *line_buffer = (char *)NULL;
3056 static int buffer_size = 0;
3057 int indx = 0, c, peekc, pass_next;
3059 #if defined (READLINE)
3060 if (interactive && bash_input.type != st_string && no_line_editing)
3062 if (interactive && bash_input.type != st_string)
3071 /* Allow immediate exit if interrupted during input. */
3074 /* Ignore null bytes in input. */
3078 internal_warning ("read_a_line: ignored null byte in input");
3083 /* If there is no more input, then we return NULL. */
3086 if (interactive && bash_input.type == st_stream)
3089 return ((char *)NULL);
3093 /* `+2' in case the final character in the buffer is a newline. */
3094 RESIZE_MALLOCED_BUFFER (line_buffer, indx, 2, buffer_size, 128);
3096 /* IF REMOVE_QUOTED_NEWLINES is non-zero, we are reading a
3097 here document with an unquoted delimiter. In this case,
3098 the line will be expanded as if it were in double quotes.
3099 We allow a backslash to escape the next character, but we
3100 need to treat the backslash specially only if a backslash
3101 quoting a backslash-newline pair appears in the line. */
3104 line_buffer[indx++] = c;
3107 else if (c == '\\' && remove_quoted_newline)
3111 continue; /* Make the unquoted \<newline> pair disappear. */
3116 line_buffer[indx++] = c; /* Preserve the backslash. */
3120 line_buffer[indx++] = c;
3124 line_buffer[indx] = '\0';
3125 return (line_buffer);
3130 /* Return a line as in read_a_line (), but insure that the prompt is
3131 the secondary prompt. This is used to read the lines of a here
3132 document. REMOVE_QUOTED_NEWLINE is non-zero if we should remove
3133 newlines quoted with backslashes while reading the line. It is
3134 non-zero unless the delimiter of the here document was quoted. */
3136 read_secondary_line (remove_quoted_newline)
3137 int remove_quoted_newline;
3139 prompt_string_pointer = &ps2_prompt;
3141 return (read_a_line (remove_quoted_newline));
3144 /* **************************************************************** */
3148 /* **************************************************************** */
3150 /* Reserved words. These are only recognized as the first word of a
3152 STRING_INT_ALIST word_token_alist[] = {
3161 #if defined (SELECT_COMMAND)
3162 { "select", SELECT },
3169 { "function", FUNCTION },
3170 #if defined (COMMAND_TIMING)
3176 #if defined (COND_COMMAND)
3177 { "[[", COND_START },
3183 /* other tokens that can be returned by read_token() */
3184 STRING_INT_ALIST other_token_alist[] = {
3185 /* Multiple-character tokens with special values */
3189 { ">>", GREATER_GREATER },
3190 { "<<", LESS_LESS },
3192 { ">&", GREATER_AND },
3193 { ";;", SEMI_SEMI },
3194 { "<<-", LESS_LESS_MINUS },
3195 { "<<<", LESS_LESS_LESS },
3196 { "&>", AND_GREATER },
3197 { "<>", LESS_GREATER },
3198 { ">|", GREATER_BAR },
3199 { "EOF", yacc_EOF },
3200 /* Tokens whose value is the character itself */
3211 { "newline", '\n' },
3215 /* others not listed here:
3216 WORD look at yylval.word
3217 ASSIGNMENT_WORD look at yylval.word
3218 NUMBER look at yylval.number
3219 ARITH_CMD look at yylval.word_list
3220 ARITH_FOR_EXPRS look at yylval.word_list
3221 COND_CMD look at yylval.command
3224 /* These are used by read_token_word, but appear up here so that shell_getc
3225 can use them to decide when to add otherwise blank lines to the history. */
3227 /* The primary delimiter stack. */
3228 struct dstack dstack = { (char *)NULL, 0, 0 };
3230 /* A temporary delimiter stack to be used when decoding prompt strings.
3231 This is needed because command substitutions in prompt strings (e.g., PS2)
3232 can screw up the parser's quoting state. */
3233 static struct dstack temp_dstack = { (char *)NULL, 0, 0 };
3235 /* Macro for accessing the top delimiter on the stack. Returns the
3236 delimiter or zero if none. */
3237 #define current_delimiter(ds) \
3238 (ds.delimiter_depth ? ds.delimiters[ds.delimiter_depth - 1] : 0)
3240 #define push_delimiter(ds, character) \
3243 if (ds.delimiter_depth + 2 > ds.delimiter_space) \
3244 ds.delimiters = (char *)xrealloc \
3245 (ds.delimiters, (ds.delimiter_space += 10) * sizeof (char)); \
3246 ds.delimiters[ds.delimiter_depth] = character; \
3247 ds.delimiter_depth++; \
3251 #define pop_delimiter(ds) ds.delimiter_depth--
3253 /* Return the next shell input character. This always reads characters
3254 from shell_input_line; when that line is exhausted, it is time to
3255 read the next line. This is called by read_token when the shell is
3256 processing normal command input. */
3258 /* This implements one-character lookahead/lookbehind across physical input
3259 lines, to avoid something being lost because it's pushed back with
3260 shell_ungetc when we're at the start of a line. */
3261 static int eol_ungetc_lookahead = 0;
3264 shell_getc (remove_quoted_newline)
3265 int remove_quoted_newline;
3270 static int mustpop = 0;
3274 if (eol_ungetc_lookahead)
3276 c = eol_ungetc_lookahead;
3277 eol_ungetc_lookahead = 0;
3281 #if defined (ALIAS) || defined (DPAREN_ARITHMETIC)
3282 /* If shell_input_line[shell_input_line_index] == 0, but there is
3283 something on the pushed list of strings, then we don't want to go
3284 off and get another line. We let the code down below handle it. */
3286 if (!shell_input_line || ((!shell_input_line[shell_input_line_index]) &&
3287 (pushed_string_list == (STRING_SAVER *)NULL)))
3288 #else /* !ALIAS && !DPAREN_ARITHMETIC */
3289 if (!shell_input_line || !shell_input_line[shell_input_line_index])
3290 #endif /* !ALIAS && !DPAREN_ARITHMETIC */
3296 /* Allow immediate exit if interrupted during input. */
3300 shell_input_line_terminator = 0;
3302 #if defined (JOB_CONTROL)
3303 /* This can cause a problem when reading a command as the result
3304 of a trap, when the trap is called from flush_child. This call
3305 had better not cause jobs to disappear from the job table in
3306 that case, or we will have big trouble. */
3307 notify_and_cleanup ();
3308 #else /* !JOB_CONTROL */
3309 cleanup_dead_jobs ();
3310 #endif /* !JOB_CONTROL */
3312 #if defined (READLINE)
3313 if (interactive && bash_input.type != st_string && no_line_editing)
3315 if (interactive && bash_input.type != st_string)
3319 if (bash_input.type == st_stream)
3326 /* Allow immediate exit if interrupted during input. */
3332 internal_warning ("shell_getc: ignored null byte in input");
3337 RESIZE_MALLOCED_BUFFER (shell_input_line, i, 2, shell_input_line_size, 256);
3341 if (bash_input.type == st_stream)
3345 shell_input_line_terminator = EOF;
3347 shell_input_line[i] = '\0';
3351 shell_input_line[i++] = c;
3355 shell_input_line[--i] = '\0';
3356 current_command_line_count++;
3361 shell_input_line_index = 0;
3362 shell_input_line_len = i; /* == strlen (shell_input_line) */
3364 set_line_mbstate ();
3366 #if defined (HISTORY)
3367 if (remember_on_history && shell_input_line && shell_input_line[0])
3370 # if defined (BANG_HISTORY)
3373 /* If the current delimiter is a single quote, we should not be
3374 performing history expansion, even if we're on a different
3375 line from the original single quote. */
3376 old_hist = history_expansion_inhibited;
3377 if (current_delimiter (dstack) == '\'')
3378 history_expansion_inhibited = 1;
3380 expansions = pre_process_line (shell_input_line, 1, 1);
3381 # if defined (BANG_HISTORY)
3382 history_expansion_inhibited = old_hist;
3384 if (expansions != shell_input_line)
3386 free (shell_input_line);
3387 shell_input_line = expansions;
3388 shell_input_line_len = shell_input_line ?
3389 strlen (shell_input_line) : 0;
3390 if (!shell_input_line_len)
3391 current_command_line_count--;
3393 /* We have to force the xrealloc below because we don't know
3394 the true allocated size of shell_input_line anymore. */
3395 shell_input_line_size = shell_input_line_len;
3397 set_line_mbstate ();
3400 /* Try to do something intelligent with blank lines encountered while
3401 entering multi-line commands. XXX - this is grotesque */
3402 else if (remember_on_history && shell_input_line &&
3403 shell_input_line[0] == '\0' &&
3404 current_command_line_count > 1)
3406 if (current_delimiter (dstack))
3407 /* We know shell_input_line[0] == 0 and we're reading some sort of
3408 quoted string. This means we've got a line consisting of only
3409 a newline in a quoted string. We want to make sure this line
3410 gets added to the history. */
3411 maybe_add_history (shell_input_line);
3415 hdcs = history_delimiting_chars ();
3416 if (hdcs && hdcs[0] == ';')
3417 maybe_add_history (shell_input_line);
3421 #endif /* HISTORY */
3423 if (shell_input_line)
3425 /* Lines that signify the end of the shell's input should not be
3427 if (echo_input_at_read && (shell_input_line[0] ||
3428 shell_input_line_terminator != EOF))
3429 fprintf (stderr, "%s\n", shell_input_line);
3433 shell_input_line_size = 0;
3434 prompt_string_pointer = ¤t_prompt_string;
3439 /* Add the newline to the end of this string, iff the string does
3440 not already end in an EOF character. */
3441 if (shell_input_line_terminator != EOF)
3443 if (shell_input_line_len + 3 > shell_input_line_size)
3444 shell_input_line = (char *)xrealloc (shell_input_line,
3445 1 + (shell_input_line_size += 2));
3447 shell_input_line[shell_input_line_len] = '\n';
3448 shell_input_line[shell_input_line_len + 1] = '\0';
3450 set_line_mbstate ();
3454 uc = shell_input_line[shell_input_line_index];
3457 shell_input_line_index++;
3459 if MBTEST(uc == '\\' && remove_quoted_newline && shell_input_line[shell_input_line_index] == '\n')
3466 #if defined (ALIAS) || defined (DPAREN_ARITHMETIC)
3467 /* If UC is NULL, we have reached the end of the current input string. If
3468 pushed_string_list is non-empty, it's time to pop to the previous string
3469 because we have fully consumed the result of the last alias expansion.
3470 Do it transparently; just return the next character of the string popped
3472 if (!uc && (pushed_string_list != (STRING_SAVER *)NULL))
3477 uc = shell_input_line[shell_input_line_index];
3479 shell_input_line_index++;
3488 #endif /* ALIAS || DPAREN_ARITHMETIC */
3490 if (!uc && shell_input_line_terminator == EOF)
3491 return ((shell_input_line_index != 0) ? '\n' : EOF);
3496 /* Put C back into the input for the shell. This might need changes for
3497 HANDLE_MULTIBYTE around EOLs. Since we (currently) never push back a
3498 character different than we read, shell_input_line_property doesn't need
3499 to change when manipulating shell_input_line. The define for
3500 last_shell_getc_is_singlebyte should take care of it, though. */
3505 if (shell_input_line && shell_input_line_index)
3506 shell_input_line[--shell_input_line_index] = c;
3508 eol_ungetc_lookahead = c;
3511 #ifdef INCLUDE_UNUSED
3512 /* Back the input pointer up by one, effectively `ungetting' a character. */
3516 if (shell_input_line && shell_input_line_index)
3517 shell_input_line_index--;
3521 /* Discard input until CHARACTER is seen, then push that character back
3522 onto the input stream. */
3524 discard_until (character)
3529 while ((c = shell_getc (0)) != EOF && c != character)
3537 execute_prompt_command (command)
3540 sh_builtin_func_t *temp_last, *temp_this;
3542 int temp_exit_value, temp_eof_encountered;
3544 temp_last = last_shell_builtin;
3545 temp_this = this_shell_builtin;
3546 temp_exit_value = last_command_exit_value;
3547 temp_eof_encountered = eof_encountered;
3548 last_lastarg = get_string_value ("_");
3550 last_lastarg = savestring (last_lastarg);
3552 parse_and_execute (savestring (command), "PROMPT_COMMAND", SEVAL_NONINT|SEVAL_NOHIST);
3554 last_shell_builtin = temp_last;
3555 this_shell_builtin = temp_this;
3556 last_command_exit_value = temp_exit_value;
3557 eof_encountered = temp_eof_encountered;
3559 bind_variable ("_", last_lastarg);
3560 FREE (last_lastarg);
3562 if (token_to_read == '\n') /* reset_parser was called */
3566 /* Place to remember the token. We try to keep the buffer
3567 at a reasonable size, but it can grow. */
3568 static char *token = (char *)NULL;
3570 /* Current size of the token buffer. */
3571 static int token_buffer_size;
3573 /* Command to read_token () explaining what we want it to do. */
3576 #define prompt_is_ps1 \
3577 (!prompt_string_pointer || prompt_string_pointer == &ps1_prompt)
3579 /* Function for yyparse to call. yylex keeps track of
3580 the last two tokens read, and calls read_token. */
3584 if (interactive && (current_token == 0 || current_token == '\n'))
3586 /* Before we print a prompt, we might have to check mailboxes.
3587 We do this only if it is time to do so. Notice that only here
3588 is the mail alarm reset; nothing takes place in check_mail ()
3589 except the checking of mail. Please don't change this. */
3590 if (prompt_is_ps1 && time_to_check_mail ())
3593 reset_mail_timer ();
3596 /* Avoid printing a prompt if we're not going to read anything, e.g.
3597 after resetting the parser with read_token (RESET). */
3598 if (token_to_read == 0 && interactive)
3602 two_tokens_ago = token_before_that;
3603 token_before_that = last_read_token;
3604 last_read_token = current_token;
3605 current_token = read_token (READ);
3606 return (current_token);
3609 /* When non-zero, we have read the required tokens
3610 which allow ESAC to be the next one read. */
3611 static int esacs_needed_count;
3614 gather_here_documents ()
3617 while (need_here_doc)
3619 make_here_document (redir_stack[r++]);
3624 /* When non-zero, an open-brace used to create a group is awaiting a close
3626 static int open_brace_count;
3628 #define command_token_position(token) \
3629 (((token) == ASSIGNMENT_WORD) || \
3630 ((token) != SEMI_SEMI && reserved_word_acceptable(token)))
3632 #define assignment_acceptable(token) command_token_position(token) && \
3633 ((parser_state & PST_CASEPAT) == 0)
3635 /* Check to see if TOKEN is a reserved word and return the token
3637 #define CHECK_FOR_RESERVED_WORD(tok) \
3639 if (!dollar_present && !quoted && \
3640 reserved_word_acceptable (last_read_token)) \
3643 for (i = 0; word_token_alist[i].word != (char *)NULL; i++) \
3644 if (STREQ (tok, word_token_alist[i].word)) \
3646 if ((parser_state & PST_CASEPAT) && (word_token_alist[i].token != ESAC)) \
3648 if (word_token_alist[i].token == TIME) \
3650 if (word_token_alist[i].token == ESAC) \
3651 parser_state &= ~(PST_CASEPAT|PST_CASESTMT); \
3652 else if (word_token_alist[i].token == CASE) \
3653 parser_state |= PST_CASESTMT; \
3654 else if (word_token_alist[i].token == COND_END) \
3655 parser_state &= ~(PST_CONDCMD|PST_CONDEXPR); \
3656 else if (word_token_alist[i].token == COND_START) \
3657 parser_state |= PST_CONDCMD; \
3658 else if (word_token_alist[i].token == '{') \
3659 open_brace_count++; \
3660 else if (word_token_alist[i].token == '}' && open_brace_count) \
3661 open_brace_count--; \
3662 return (word_token_alist[i].token); \
3669 /* OK, we have a token. Let's try to alias expand it, if (and only if)
3672 It is eligible for expansion if EXPAND_ALIASES is set, and
3673 the token is unquoted and the last token read was a command
3674 separator (or expand_next_token is set), and we are currently
3675 processing an alias (pushed_string_list is non-empty) and this
3676 token is not the same as the current or any previously
3679 Special cases that disqualify:
3680 In a pattern list in a case statement (parser_state & PST_CASEPAT). */
3682 alias_expand_token (tokstr)
3688 if (((parser_state & PST_ALEXPNEXT) || command_token_position (last_read_token)) &&
3689 (parser_state & PST_CASEPAT) == 0)
3691 ap = find_alias (tokstr);
3693 /* Currently expanding this token. */
3694 if (ap && (ap->flags & AL_BEINGEXPANDED))
3695 return (NO_EXPANSION);
3697 expanded = ap ? savestring (ap->value) : (char *)NULL;
3700 push_string (expanded, ap->flags & AL_EXPANDNEXT, ap);
3701 return (RE_READ_TOKEN);
3704 /* This is an eligible token that does not have an expansion. */
3705 return (NO_EXPANSION);
3707 return (NO_EXPANSION);
3712 time_command_acceptable ()
3714 #if defined (COMMAND_TIMING)
3715 switch (last_read_token)
3734 #endif /* COMMAND_TIMING */
3737 /* Handle special cases of token recognition:
3738 IN is recognized if the last token was WORD and the token
3739 before that was FOR or CASE or SELECT.
3741 DO is recognized if the last token was WORD and the token
3742 before that was FOR or SELECT.
3744 ESAC is recognized if the last token caused `esacs_needed_count'
3747 `{' is recognized if the last token as WORD and the token
3748 before that was FUNCTION, or if we just parsed an arithmetic
3751 `}' is recognized if there is an unclosed `{' present.
3753 `-p' is returned as TIMEOPT if the last read token was TIME.
3755 ']]' is returned as COND_END if the parser is currently parsing
3756 a conditional expression ((parser_state & PST_CONDEXPR) != 0)
3758 `time' is returned as TIME if and only if it is immediately
3759 preceded by one of `;', `\n', `||', `&&', or `&'.
3763 special_case_tokens (tokstr)
3766 if ((last_read_token == WORD) &&
3767 #if defined (SELECT_COMMAND)
3768 ((token_before_that == FOR) || (token_before_that == CASE) || (token_before_that == SELECT)) &&
3770 ((token_before_that == FOR) || (token_before_that == CASE)) &&
3772 (tokstr[0] == 'i' && tokstr[1] == 'n' && tokstr[2] == 0))
3774 if (token_before_that == CASE)
3776 parser_state |= PST_CASEPAT;
3777 esacs_needed_count++;
3782 if (last_read_token == WORD &&
3783 #if defined (SELECT_COMMAND)
3784 (token_before_that == FOR || token_before_that == SELECT) &&
3786 (token_before_that == FOR) &&
3788 (tokstr[0] == 'd' && tokstr[1] == 'o' && tokstr[2] == '\0'))
3791 /* Ditto for ESAC in the CASE case.
3792 Specifically, this handles "case word in esac", which is a legal
3793 construct, certainly because someone will pass an empty arg to the
3794 case construct, and we don't want it to barf. Of course, we should
3795 insist that the case construct has at least one pattern in it, but
3796 the designers disagree. */
3797 if (esacs_needed_count)
3799 esacs_needed_count--;
3800 if (STREQ (tokstr, "esac"))
3802 parser_state &= ~PST_CASEPAT;
3807 /* The start of a shell function definition. */
3808 if (parser_state & PST_ALLOWOPNBRC)
3810 parser_state &= ~PST_ALLOWOPNBRC;
3811 if (tokstr[0] == '{' && tokstr[1] == '\0') /* } */
3814 function_bstart = line_number;
3815 return ('{'); /* } */
3819 /* We allow a `do' after a for ((...)) without an intervening
3821 if (last_read_token == ARITH_FOR_EXPRS && tokstr[0] == 'd' && tokstr[1] == 'o' && !tokstr[2])
3823 if (last_read_token == ARITH_FOR_EXPRS && tokstr[0] == '{' && tokstr[1] == '\0') /* } */
3826 return ('{'); /* } */
3829 if (open_brace_count && reserved_word_acceptable (last_read_token) && tokstr[0] == '}' && !tokstr[1])
3831 open_brace_count--; /* { */
3835 #if defined (COMMAND_TIMING)
3836 /* Handle -p after `time'. */
3837 if (last_read_token == TIME && tokstr[0] == '-' && tokstr[1] == 'p' && !tokstr[2])
3841 #if defined (COMMAND_TIMING)
3842 if (STREQ (token, "time") && ((parser_state & PST_CASEPAT) == 0) && time_command_acceptable ())
3844 #endif /* COMMAND_TIMING */
3846 #if defined (COND_COMMAND) /* [[ */
3847 if ((parser_state & PST_CONDEXPR) && tokstr[0] == ']' && tokstr[1] == ']' && tokstr[2] == '\0')
3854 /* Called from shell.c when Control-C is typed at top level. Or
3855 by the error rule at top level. */
3859 dstack.delimiter_depth = 0; /* No delimiters found so far. */
3860 open_brace_count = 0;
3864 #if defined (ALIAS) || defined (DPAREN_ARITHMETIC)
3865 if (pushed_string_list)
3866 free_string_list ();
3867 #endif /* ALIAS || DPAREN_ARITHMETIC */
3869 if (shell_input_line)
3871 free (shell_input_line);
3872 shell_input_line = (char *)NULL;
3873 shell_input_line_size = shell_input_line_index = 0;
3876 FREE (word_desc_to_read);
3877 word_desc_to_read = (WORD_DESC *)NULL;
3879 last_read_token = '\n';
3880 token_to_read = '\n';
3883 /* Read the next token. Command can be READ (normal operation) or
3884 RESET (to normalize state). */
3886 read_token (command)
3889 int character; /* Current character. */
3890 int peek_char; /* Temporary look-ahead character. */
3891 int result; /* The thing to return. */
3893 if (command == RESET)
3901 result = token_to_read;
3902 if (token_to_read == WORD || token_to_read == ASSIGNMENT_WORD)
3904 yylval.word = word_desc_to_read;
3905 word_desc_to_read = (WORD_DESC *)NULL;
3911 #if defined (COND_COMMAND)
3912 if ((parser_state & (PST_CONDCMD|PST_CONDEXPR)) == PST_CONDCMD)
3914 cond_lineno = line_number;
3915 parser_state |= PST_CONDEXPR;
3916 yylval.command = parse_cond_command ();
3917 if (cond_token != COND_END)
3922 token_to_read = COND_END;
3923 parser_state &= ~(PST_CONDEXPR|PST_CONDCMD);
3929 /* This is a place to jump back to once we have successfully expanded a
3930 token with an alias and pushed the string with push_string () */
3934 /* Read a single word from input. Start by skipping blanks. */
3935 while ((character = shell_getc (1)) != EOF && whitespace (character))
3938 if (character == EOF)
3944 if MBTEST(character == '#' && (!interactive || interactive_comments))
3946 /* A comment. Discard until EOL or EOF, and then return a newline. */
3947 discard_until ('\n');
3949 character = '\n'; /* this will take the next if statement and return. */
3952 if (character == '\n')
3954 /* If we're about to return an unquoted newline, we can go and collect
3955 the text of any pending here document. */
3957 gather_here_documents ();
3960 parser_state &= ~PST_ALEXPNEXT;
3966 /* Shell meta-characters. */
3967 if MBTEST(shellmeta (character) && ((parser_state & PST_DBLPAREN) == 0))
3970 /* Turn off alias tokenization iff this character sequence would
3971 not leave us ready to read a command. */
3972 if (character == '<' || character == '>')
3973 parser_state &= ~PST_ALEXPNEXT;
3976 peek_char = shell_getc (1);
3977 if (character == peek_char)
3982 /* If '<' then we could be at "<<" or at "<<-". We have to
3983 look ahead one more character. */
3984 peek_char = shell_getc (1);
3985 if (peek_char == '-')
3986 return (LESS_LESS_MINUS);
3987 else if (peek_char == '<')
3988 return (LESS_LESS_LESS);
3991 shell_ungetc (peek_char);
3996 return (GREATER_GREATER);
3999 parser_state |= PST_CASEPAT;
4001 parser_state &= ~PST_ALEXPNEXT;
4011 #if defined (DPAREN_ARITHMETIC) || defined (ARITH_FOR_COMMAND)
4013 result = parse_dparen (character);
4021 else if MBTEST(character == '<' && peek_char == '&')
4023 else if MBTEST(character == '>' && peek_char == '&')
4024 return (GREATER_AND);
4025 else if MBTEST(character == '<' && peek_char == '>')
4026 return (LESS_GREATER);
4027 else if MBTEST(character == '>' && peek_char == '|')
4028 return (GREATER_BAR);
4029 else if MBTEST(peek_char == '>' && character == '&')
4030 return (AND_GREATER);
4032 shell_ungetc (peek_char);
4034 /* If we look like we are reading the start of a function
4035 definition, then let the reader know about it so that
4036 we will do the right thing with `{'. */
4037 if MBTEST(character == ')' && last_read_token == '(' && token_before_that == WORD)
4039 parser_state |= PST_ALLOWOPNBRC;
4041 parser_state &= ~PST_ALEXPNEXT;
4043 function_dstart = line_number;
4046 /* case pattern lists may be preceded by an optional left paren. If
4047 we're not trying to parse a case pattern list, the left paren
4048 indicates a subshell. */
4049 if MBTEST(character == '(' && (parser_state & PST_CASEPAT) == 0) /* ) */
4050 parser_state |= PST_SUBSHELL;
4052 else if MBTEST((parser_state & PST_CASEPAT) && character == ')')
4053 parser_state &= ~PST_CASEPAT;
4055 else if MBTEST((parser_state & PST_SUBSHELL) && character == ')')
4056 parser_state &= ~PST_SUBSHELL;
4058 #if defined (PROCESS_SUBSTITUTION)
4059 /* Check for the constructs which introduce process substitution.
4060 Shells running in `posix mode' don't do process substitution. */
4061 if MBTEST(posixly_correct || ((character != '>' && character != '<') || peek_char != '(')) /*)*/
4062 #endif /* PROCESS_SUBSTITUTION */
4066 /* Hack <&- (close stdin) case. Also <&N- (dup and close). */
4067 if MBTEST(character == '-' && (last_read_token == LESS_AND || last_read_token == GREATER_AND))
4070 /* Okay, if we got this far, we have to read a word. Read one,
4071 and then check it against the known ones. */
4072 result = read_token_word (character);
4074 if (result == RE_READ_TOKEN)
4081 * Match a $(...) or other grouping construct. This has to handle embedded
4082 * quoted strings ('', ``, "") and nested constructs. It also must handle
4083 * reprompting the user, if necessary, after reading a newline (unless the
4084 * P_NONL flag is passed), and returning correct error values if it reads
4087 #define P_FIRSTCLOSE 0x01
4088 #define P_ALLOWESC 0x02
4090 static char matched_pair_error;
4092 parse_matched_pair (qc, open, close, lenp, flags)
4093 int qc; /* `"' if this construct is within double quotes */
4097 int count, ch, was_dollar;
4098 int pass_next_character, nestlen, ttranslen, start_lineno;
4099 char *ret, *nestret, *ttrans;
4100 int retind, retsize;
4103 pass_next_character = was_dollar = 0;
4105 ret = (char *)xmalloc (retsize = 64);
4108 start_lineno = line_number;
4111 ch = shell_getc ((qc != '\'' || (flags & P_ALLOWESC)) && pass_next_character == 0);
4115 parser_error (start_lineno, "unexpected EOF while looking for matching `%c'", close);
4116 EOF_Reached = 1; /* XXX */
4117 return (&matched_pair_error);
4120 /* Possible reprompting. */
4121 if (ch == '\n' && interactive &&
4122 (bash_input.type == st_stdin || bash_input.type == st_stream))
4125 if (pass_next_character) /* last char was backslash */
4127 pass_next_character = 0;
4128 if (qc != '\'' && ch == '\n') /* double-quoted \<newline> disappears. */
4130 if (retind > 0) retind--; /* swallow previously-added backslash */
4134 RESIZE_MALLOCED_BUFFER (ret, retind, 2, retsize, 64);
4135 if MBTEST(ch == CTLESC || ch == CTLNUL)
4136 ret[retind++] = CTLESC;
4140 else if MBTEST(ch == CTLESC || ch == CTLNUL) /* special shell escapes */
4142 RESIZE_MALLOCED_BUFFER (ret, retind, 2, retsize, 64);
4143 ret[retind++] = CTLESC;
4147 else if MBTEST(ch == close) /* ending delimiter */
4150 /* handle nested ${...} specially. */
4151 else if MBTEST(open != close && was_dollar && open == '{' && ch == open) /* } */
4154 else if MBTEST(((flags & P_FIRSTCLOSE) == 0) && ch == open) /* nested begin */
4157 /* Add this character. */
4158 RESIZE_MALLOCED_BUFFER (ret, retind, 1, retsize, 64);
4161 if (open == '\'') /* '' inside grouping construct */
4163 if MBTEST((flags & P_ALLOWESC) && ch == '\\')
4164 pass_next_character++;
4168 if MBTEST(ch == '\\') /* backslashes */
4169 pass_next_character++;
4171 if (open != close) /* a grouping construct */
4173 if MBTEST(shellquote (ch))
4175 /* '', ``, or "" inside $(...) or other grouping construct. */
4176 push_delimiter (dstack, ch);
4177 if MBTEST(was_dollar && ch == '\'') /* $'...' inside group */
4178 nestret = parse_matched_pair (ch, ch, ch, &nestlen, P_ALLOWESC);
4180 nestret = parse_matched_pair (ch, ch, ch, &nestlen, 0);
4181 pop_delimiter (dstack);
4182 if (nestret == &matched_pair_error)
4185 return &matched_pair_error;
4187 if MBTEST(was_dollar && ch == '\'')
4189 /* Translate $'...' here. */
4190 ttrans = ansiexpand (nestret, 0, nestlen - 1, &ttranslen);
4192 nestret = sh_single_quote (ttrans);
4194 nestlen = strlen (nestret);
4195 retind -= 2; /* back up before the $' */
4197 else if MBTEST(was_dollar && ch == '"')
4199 /* Locale expand $"..." here. */
4200 ttrans = localeexpand (nestret, 0, nestlen - 1, start_lineno, &ttranslen);
4202 nestret = (char *)xmalloc (ttranslen + 3);
4204 strcpy (nestret + 1, ttrans);
4205 nestret[ttranslen + 1] = '"';
4206 nestret[ttranslen += 2] = '\0';
4208 nestlen = ttranslen;
4209 retind -= 2; /* back up before the $" */
4214 RESIZE_MALLOCED_BUFFER (ret, retind, nestlen, retsize, 64);
4215 strcpy (ret + retind, nestret);
4221 /* Parse an old-style command substitution within double quotes as a
4223 /* XXX - sh and ksh93 don't do this - XXX */
4224 else if MBTEST(open == '"' && ch == '`')
4226 nestret = parse_matched_pair (0, '`', '`', &nestlen, 0);
4227 if (nestret == &matched_pair_error)
4230 return &matched_pair_error;
4234 RESIZE_MALLOCED_BUFFER (ret, retind, nestlen, retsize, 64);
4235 strcpy (ret + retind, nestret);
4240 else if MBTEST(was_dollar && (ch == '(' || ch == '{' || ch == '[')) /* ) } ] */
4241 /* check for $(), $[], or ${} inside quoted string. */
4243 if (open == ch) /* undo previous increment */
4245 if (ch == '(') /* ) */
4246 nestret = parse_matched_pair (0, '(', ')', &nestlen, 0);
4247 else if (ch == '{') /* } */
4248 nestret = parse_matched_pair (0, '{', '}', &nestlen, P_FIRSTCLOSE);
4249 else if (ch == '[') /* ] */
4250 nestret = parse_matched_pair (0, '[', ']', &nestlen, 0);
4251 if (nestret == &matched_pair_error)
4254 return &matched_pair_error;
4258 RESIZE_MALLOCED_BUFFER (ret, retind, nestlen, retsize, 64);
4259 strcpy (ret + retind, nestret);
4264 was_dollar = MBTEST(ch == '$');
4273 #if defined (DPAREN_ARITHMETIC) || defined (ARITH_FOR_COMMAND)
4274 /* Parse a double-paren construct. It can be either an arithmetic
4275 command, an arithmetic `for' command, or a nested subshell. Returns
4276 the parsed token, -1 on error, or -2 if we didn't do anything and
4277 should just go on. */
4282 int cmdtyp, len, sline;
4286 #if defined (ARITH_FOR_COMMAND)
4287 if (last_read_token == FOR)
4289 arith_for_lineno = line_number;
4290 cmdtyp = parse_arith_cmd (&wval);
4293 /* parse_arith_cmd adds quotes at the beginning and end
4294 of the string it returns; we need to take those out. */
4295 len = strlen (wval);
4296 wv2 = (char *)xmalloc (len);
4297 strncpy (wv2, wval + 1, len - 2);
4298 wv2[len - 2] = '\0';
4299 wd = make_word (wv2);
4300 yylval.word_list = make_word_list (wd, (WORD_LIST *)NULL);
4303 return (ARITH_FOR_EXPRS);
4306 return -1; /* ERROR */
4310 #if defined (DPAREN_ARITHMETIC)
4311 if (reserved_word_acceptable (last_read_token))
4313 sline = line_number;
4314 cmdtyp = parse_arith_cmd (&wval);
4315 if (cmdtyp == 1) /* arithmetic command */
4317 wd = make_word (wval);
4318 wd->flags = W_QUOTED;
4319 yylval.word_list = make_word_list (wd, (WORD_LIST *)NULL);
4320 free (wval); /* make_word copies it */
4323 else if (cmdtyp == 0) /* nested subshell */
4325 push_string (wval, 0, (alias_t *)NULL);
4326 if ((parser_state & PST_CASEPAT) == 0)
4327 parser_state |= PST_SUBSHELL;
4335 return -2; /* XXX */
4338 /* We've seen a `(('. Look for the matching `))'. If we get it, return 1.
4339 If not, assume it's a nested subshell for backwards compatibility and
4340 return 0. In any case, put the characters we've consumed into a locally-
4341 allocated buffer and make *ep point to that buffer. Return -1 on an
4342 error, for example EOF. */
4344 parse_arith_cmd (ep)
4347 int exp_lineno, rval, c;
4348 char *ttok, *tokstr;
4351 exp_lineno = line_number;
4352 ttok = parse_matched_pair (0, '(', ')', &ttoklen, 0);
4354 if (ttok == &matched_pair_error)
4356 /* Check that the next character is the closing right paren. If
4357 not, this is a syntax error. ( */
4362 tokstr = (char *)xmalloc (ttoklen + 4);
4364 /* (( ... )) -> "..." */
4365 tokstr[0] = (rval == 1) ? '"' : '(';
4366 strncpy (tokstr + 1, ttok, ttoklen - 1); /* don't copy the final `)' */
4369 tokstr[ttoklen] = '"';
4370 tokstr[ttoklen+1] = '\0';
4374 tokstr[ttoklen] = ')';
4375 tokstr[ttoklen+1] = c;
4376 tokstr[ttoklen+2] = '\0';
4382 #endif /* DPAREN_ARITHMETIC || ARITH_FOR_COMMAND */
4384 #if defined (COND_COMMAND)
4390 if (EOF_Reached && cond_token != COND_ERROR) /* [[ */
4391 parser_error (cond_lineno, "unexpected EOF while looking for `]]'");
4392 else if (cond_token != COND_ERROR)
4394 if (etext = error_token_from_token (cond_token))
4396 parser_error (cond_lineno, "syntax error in conditional expression: unexpected token `%s'", etext);
4400 parser_error (cond_lineno, "syntax error in conditional expression");
4407 return (cond_or ());
4416 if (cond_token == OR_OR)
4419 l = make_cond_node (COND_OR, (WORD_DESC *)NULL, l, r);
4430 if (cond_token == AND_AND)
4433 l = make_cond_node (COND_AND, (WORD_DESC *)NULL, l, r);
4439 cond_skip_newlines ()
4441 while ((cond_token = read_token (READ)) == '\n')
4443 if (interactive && (bash_input.type == st_stdin || bash_input.type == st_stream))
4446 return (cond_token);
4449 #define COND_RETURN_ERROR() \
4450 do { cond_token = COND_ERROR; return ((COND_COM *)NULL); } while (0)
4456 COND_COM *term, *tleft, *tright;
4460 /* Read a token. It can be a left paren, a `!', a unary operator, or a
4461 word that should be the first argument of a binary operator. Start by
4462 skipping newlines, since this is a compound command. */
4463 tok = cond_skip_newlines ();
4464 lineno = line_number;
4465 if (tok == COND_END)
4467 COND_RETURN_ERROR ();
4469 else if (tok == '(')
4471 term = cond_expr ();
4472 if (cond_token != ')')
4475 dispose_cond_node (term); /* ( */
4476 if (etext = error_token_from_token (cond_token))
4478 parser_error (lineno, "unexpected token `%s', expected `)'", etext);
4482 parser_error (lineno, "expected `)'");
4483 COND_RETURN_ERROR ();
4485 term = make_cond_node (COND_EXPR, (WORD_DESC *)NULL, term, (COND_COM *)NULL);
4486 (void)cond_skip_newlines ();
4488 else if (tok == BANG || (tok == WORD && (yylval.word->word[0] == '!' && yylval.word->word[1] == '\0')))
4491 dispose_word (yylval.word); /* not needed */
4492 term = cond_term ();
4494 term->flags |= CMD_INVERT_RETURN;
4496 else if (tok == WORD && test_unop (yylval.word->word))
4499 tok = read_token (READ);
4502 tleft = make_cond_node (COND_TERM, yylval.word, (COND_COM *)NULL, (COND_COM *)NULL);
4503 term = make_cond_node (COND_UNARY, op, tleft, (COND_COM *)NULL);
4508 if (etext = error_token_from_token (tok))
4510 parser_error (line_number, "unexpected argument `%s' to conditional unary operator", etext);
4514 parser_error (line_number, "unexpected argument to conditional unary operator");
4515 COND_RETURN_ERROR ();
4518 (void)cond_skip_newlines ();
4520 else if (tok == WORD) /* left argument to binary operator */
4523 tleft = make_cond_node (COND_TERM, yylval.word, (COND_COM *)NULL, (COND_COM *)NULL);
4526 tok = read_token (READ);
4527 if (tok == WORD && test_binop (yylval.word->word))
4529 else if (tok == '<' || tok == '>')
4530 op = make_word_from_token (tok); /* ( */
4531 /* There should be a check before blindly accepting the `)' that we have
4532 seen the opening `('. */
4533 else if (tok == COND_END || tok == AND_AND || tok == OR_OR || tok == ')')
4535 /* Special case. [[ x ]] is equivalent to [[ -n x ]], just like
4536 the test command. Similarly for [[ x && expr ]] or
4537 [[ x || expr ]] or [[ (x) ]]. */
4538 op = make_word ("-n");
4539 term = make_cond_node (COND_UNARY, op, tleft, (COND_COM *)NULL);
4545 if (etext = error_token_from_token (tok))
4547 parser_error (line_number, "unexpected token `%s', conditional binary operator expected", etext);
4551 parser_error (line_number, "conditional binary operator expected");
4552 dispose_cond_node (tleft);
4553 COND_RETURN_ERROR ();
4557 tok = read_token (READ);
4560 tright = make_cond_node (COND_TERM, yylval.word, (COND_COM *)NULL, (COND_COM *)NULL);
4561 term = make_cond_node (COND_BINARY, op, tleft, tright);
4565 if (etext = error_token_from_token (tok))
4567 parser_error (line_number, "unexpected argument `%s' to conditional binary operator", etext);
4571 parser_error (line_number, "unexpected argument to conditional binary operator");
4572 dispose_cond_node (tleft);
4574 COND_RETURN_ERROR ();
4577 (void)cond_skip_newlines ();
4582 parser_error (line_number, "unexpected token `%c' in conditional command", tok);
4583 else if (etext = error_token_from_token (tok))
4585 parser_error (line_number, "unexpected token `%s' in conditional command", etext);
4589 parser_error (line_number, "unexpected token %d in conditional command", tok);
4590 COND_RETURN_ERROR ();
4595 /* This is kind of bogus -- we slip a mini recursive-descent parser in
4596 here to handle the conditional statement syntax. */
4598 parse_cond_command ()
4602 cexp = cond_expr ();
4603 return (make_cond_command (cexp));
4607 #if defined (ARRAY_VARS)
4608 /* When this is called, it's guaranteed that we don't care about anything
4609 in t beyond i. We do save and restore the chars, though. */
4611 token_is_assignment (t, i)
4615 unsigned char c, c1;
4618 c = t[i]; c1 = t[i+1];
4619 t[i] = '='; t[i+1] = '\0';
4621 t[i] = c; t[i+1] = c1;
4626 token_is_ident (t, i)
4635 r = legal_identifier (t);
4642 read_token_word (character)
4645 /* The value for YYLVAL when a WORD is read. */
4646 WORD_DESC *the_word;
4648 /* Index into the token that we are building. */
4651 /* ALL_DIGITS becomes zero when we see a non-digit. */
4652 int all_digit_token;
4654 /* DOLLAR_PRESENT becomes non-zero if we see a `$'. */
4657 /* QUOTED becomes non-zero if we see one of ("), ('), (`), or (\). */
4660 /* Non-zero means to ignore the value of the next character, and just
4661 to add it no matter what. */
4662 int pass_next_character;
4664 /* The current delimiting character. */
4666 int result, peek_char;
4667 char *ttok, *ttrans;
4668 int ttoklen, ttranslen;
4671 if (token_buffer_size < TOKEN_DEFAULT_INITIAL_SIZE)
4672 token = (char *)xrealloc (token, token_buffer_size = TOKEN_DEFAULT_INITIAL_SIZE);
4675 all_digit_token = DIGIT (character);
4676 dollar_present = quoted = pass_next_character = 0;
4680 if (character == EOF)
4683 if (pass_next_character)
4685 pass_next_character = 0;
4689 cd = current_delimiter (dstack);
4691 /* Handle backslashes. Quote lots of things when not inside of
4692 double-quotes, quote some things inside of double-quotes. */
4693 if MBTEST(character == '\\')
4695 peek_char = shell_getc (0);
4697 /* Backslash-newline is ignored in all cases except
4698 when quoted with single quotes. */
4699 if (peek_char == '\n')
4702 goto next_character;
4706 shell_ungetc (peek_char);
4708 /* If the next character is to be quoted, note it now. */
4709 if (cd == 0 || cd == '`' ||
4710 (cd == '"' && peek_char >= 0 && (sh_syntaxtab[peek_char] & CBSDQUOTE)))
4711 pass_next_character++;
4718 /* Parse a matched pair of quote characters. */
4719 if MBTEST(shellquote (character))
4721 push_delimiter (dstack, character);
4722 ttok = parse_matched_pair (character, character, character, &ttoklen, 0);
4723 pop_delimiter (dstack);
4724 if (ttok == &matched_pair_error)
4725 return -1; /* Bail immediately. */
4726 RESIZE_MALLOCED_BUFFER (token, token_index, ttoklen + 2,
4727 token_buffer_size, TOKEN_DEFAULT_GROW_SIZE);
4728 token[token_index++] = character;
4729 strcpy (token + token_index, ttok);
4730 token_index += ttoklen;
4731 all_digit_token = 0;
4733 dollar_present |= (character == '"' && strchr (ttok, '$') != 0);
4735 goto next_character;
4738 #ifdef EXTENDED_GLOB
4739 /* Parse a ksh-style extended pattern matching specification. */
4740 if (extended_glob && PATTERN_CHAR (character))
4742 peek_char = shell_getc (1);
4743 if MBTEST(peek_char == '(') /* ) */
4745 push_delimiter (dstack, peek_char);
4746 ttok = parse_matched_pair (cd, '(', ')', &ttoklen, 0);
4747 pop_delimiter (dstack);
4748 if (ttok == &matched_pair_error)
4749 return -1; /* Bail immediately. */
4750 RESIZE_MALLOCED_BUFFER (token, token_index, ttoklen + 2,
4752 TOKEN_DEFAULT_GROW_SIZE);
4753 token[token_index++] = character;
4754 token[token_index++] = peek_char;
4755 strcpy (token + token_index, ttok);
4756 token_index += ttoklen;
4758 dollar_present = all_digit_token = 0;
4759 goto next_character;
4762 shell_ungetc (peek_char);
4764 #endif /* EXTENDED_GLOB */
4766 /* If the delimiter character is not single quote, parse some of
4767 the shell expansions that must be read as a single word. */
4768 if (shellexp (character))
4770 peek_char = shell_getc (1);
4771 /* $(...), <(...), >(...), $((...)), ${...}, and $[...] constructs */
4772 if MBTEST(peek_char == '(' || \
4773 ((peek_char == '{' || peek_char == '[') && character == '$')) /* ) ] } */
4775 if (peek_char == '{') /* } */
4776 ttok = parse_matched_pair (cd, '{', '}', &ttoklen, P_FIRSTCLOSE);
4777 else if (peek_char == '(') /* ) */
4779 /* XXX - push and pop the `(' as a delimiter for use by
4780 the command-oriented-history code. This way newlines
4781 appearing in the $(...) string get added to the
4782 history literally rather than causing a possibly-
4783 incorrect `;' to be added. ) */
4784 push_delimiter (dstack, peek_char);
4785 ttok = parse_matched_pair (cd, '(', ')', &ttoklen, 0);
4786 pop_delimiter (dstack);
4789 ttok = parse_matched_pair (cd, '[', ']', &ttoklen, 0);
4790 if (ttok == &matched_pair_error)
4791 return -1; /* Bail immediately. */
4792 RESIZE_MALLOCED_BUFFER (token, token_index, ttoklen + 2,
4794 TOKEN_DEFAULT_GROW_SIZE);
4795 token[token_index++] = character;
4796 token[token_index++] = peek_char;
4797 strcpy (token + token_index, ttok);
4798 token_index += ttoklen;
4801 all_digit_token = 0;
4802 goto next_character;
4804 /* This handles $'...' and $"..." new-style quoted strings. */
4805 else if MBTEST(character == '$' && (peek_char == '\'' || peek_char == '"'))
4809 first_line = line_number;
4810 push_delimiter (dstack, peek_char);
4811 ttok = parse_matched_pair (peek_char, peek_char, peek_char,
4813 (peek_char == '\'') ? P_ALLOWESC : 0);
4814 pop_delimiter (dstack);
4815 if (ttok == &matched_pair_error)
4817 if (peek_char == '\'')
4819 ttrans = ansiexpand (ttok, 0, ttoklen - 1, &ttranslen);
4821 /* Insert the single quotes and correctly quote any
4822 embedded single quotes (allowed because P_ALLOWESC was
4823 passed to parse_matched_pair). */
4824 ttok = sh_single_quote (ttrans);
4827 ttranslen = strlen (ttrans);
4831 /* Try to locale-expand the converted string. */
4832 ttrans = localeexpand (ttok, 0, ttoklen - 1, first_line, &ttranslen);
4835 /* Add the double quotes back */
4836 ttok = (char *)xmalloc (ttranslen + 3);
4838 strcpy (ttok + 1, ttrans);
4839 ttok[ttranslen + 1] = '"';
4840 ttok[ttranslen += 2] = '\0';
4845 RESIZE_MALLOCED_BUFFER (token, token_index, ttranslen + 2,
4847 TOKEN_DEFAULT_GROW_SIZE);
4848 strcpy (token + token_index, ttrans);
4849 token_index += ttranslen;
4852 all_digit_token = 0;
4853 goto next_character;
4855 /* This could eventually be extended to recognize all of the
4856 shell's single-character parameter expansions, and set flags.*/
4857 else if MBTEST(character == '$' && peek_char == '$')
4859 ttok = (char *)xmalloc (3);
4860 ttok[0] = ttok[1] = '$';
4862 RESIZE_MALLOCED_BUFFER (token, token_index, 3,
4864 TOKEN_DEFAULT_GROW_SIZE);
4865 strcpy (token + token_index, ttok);
4868 all_digit_token = 0;
4870 goto next_character;
4873 shell_ungetc (peek_char);
4876 #if defined (ARRAY_VARS)
4877 /* Identify possible array subscript assignment; match [...] */
4878 else if MBTEST(character == '[' && token_index > 0 && assignment_acceptable (last_read_token) && token_is_ident (token, token_index)) /* ] */
4880 ttok = parse_matched_pair (cd, '[', ']', &ttoklen, 0);
4881 if (ttok == &matched_pair_error)
4882 return -1; /* Bail immediately. */
4883 RESIZE_MALLOCED_BUFFER (token, token_index, ttoklen + 2,
4885 TOKEN_DEFAULT_GROW_SIZE);
4886 token[token_index++] = character;
4887 strcpy (token + token_index, ttok);
4888 token_index += ttoklen;
4890 all_digit_token = 0;
4891 goto next_character;
4893 /* Identify possible compound array variable assignment. */
4894 else if MBTEST(character == '=' && token_index > 0 && token_is_assignment (token, token_index))
4896 peek_char = shell_getc (1);
4897 if MBTEST(peek_char == '(') /* ) */
4899 ttok = parse_compound_assignment (&ttoklen);
4901 RESIZE_MALLOCED_BUFFER (token, token_index, ttoklen + 4,
4903 TOKEN_DEFAULT_GROW_SIZE);
4905 token[token_index++] = '=';
4906 token[token_index++] = '(';
4909 strcpy (token + token_index, ttok);
4910 token_index += ttoklen;
4912 token[token_index++] = ')';
4914 all_digit_token = 0;
4915 goto next_character;
4918 shell_ungetc (peek_char);
4922 /* When not parsing a multi-character word construct, shell meta-
4923 characters break words. */
4924 if MBTEST(shellbreak (character))
4926 shell_ungetc (character);
4932 all_digit_token &= DIGIT (character);
4933 dollar_present |= character == '$';
4935 if (character == CTLESC || character == CTLNUL)
4936 token[token_index++] = CTLESC;
4938 token[token_index++] = character;
4940 RESIZE_MALLOCED_BUFFER (token, token_index, 1, token_buffer_size,
4941 TOKEN_DEFAULT_GROW_SIZE);
4944 if (character == '\n' && interactive &&
4945 (bash_input.type == st_stdin || bash_input.type == st_stream))
4948 /* We want to remove quoted newlines (that is, a \<newline> pair)
4949 unless we are within single quotes or pass_next_character is
4950 set (the shell equivalent of literal-next). */
4951 cd = current_delimiter (dstack);
4952 character = shell_getc (cd != '\'' && pass_next_character == 0);
4953 } /* end for (;;) */
4957 token[token_index] = '\0';
4959 /* Check to see what thing we should return. If the last_read_token
4960 is a `<', or a `&', or the character which ended this token is
4961 a '>' or '<', then, and ONLY then, is this input token a NUMBER.
4962 Otherwise, it is just a word, and should be returned as such. */
4963 if MBTEST(all_digit_token && (character == '<' || character == '>' || \
4964 last_read_token == LESS_AND || \
4965 last_read_token == GREATER_AND))
4967 if (legal_number (token, &lvalue) && (int)lvalue == lvalue)
4968 yylval.number = lvalue;
4974 /* Check for special case tokens. */
4975 result = (last_shell_getc_is_singlebyte) ? special_case_tokens (token) : -1;
4980 /* Posix.2 does not allow reserved words to be aliased, so check for all
4981 of them, including special cases, before expanding the current token
4983 if MBTEST(posixly_correct)
4984 CHECK_FOR_RESERVED_WORD (token);
4986 /* Aliases are expanded iff EXPAND_ALIASES is non-zero, and quoting
4987 inhibits alias expansion. */
4988 if (expand_aliases && quoted == 0)
4990 result = alias_expand_token (token);
4991 if (result == RE_READ_TOKEN)
4992 return (RE_READ_TOKEN);
4993 else if (result == NO_EXPANSION)
4994 parser_state &= ~PST_ALEXPNEXT;
4997 /* If not in Posix.2 mode, check for reserved words after alias
4999 if MBTEST(posixly_correct == 0)
5001 CHECK_FOR_RESERVED_WORD (token);
5003 the_word = (WORD_DESC *)xmalloc (sizeof (WORD_DESC));
5004 the_word->word = (char *)xmalloc (1 + token_index);
5005 the_word->flags = 0;
5006 strcpy (the_word->word, token);
5008 the_word->flags |= W_HASDOLLAR;
5010 the_word->flags |= W_QUOTED;
5011 /* A word is an assignment if it appears at the beginning of a
5012 simple command, or after another assignment word. This is
5013 context-dependent, so it cannot be handled in the grammar. */
5014 if (assignment (token))
5016 the_word->flags |= W_ASSIGNMENT;
5017 /* Don't perform word splitting on assignment statements. */
5018 if (assignment_acceptable (last_read_token))
5019 the_word->flags |= W_NOSPLIT;
5022 yylval.word = the_word;
5024 result = ((the_word->flags & (W_ASSIGNMENT|W_NOSPLIT)) == (W_ASSIGNMENT|W_NOSPLIT))
5025 ? ASSIGNMENT_WORD : WORD;
5027 if (last_read_token == FUNCTION)
5029 parser_state |= PST_ALLOWOPNBRC;
5030 function_dstart = line_number;
5036 /* Return 1 if TOKSYM is a token that after being read would allow
5037 a reserved word to be seen, else 0. */
5039 reserved_word_acceptable (toksym)
5075 /* Return the index of TOKEN in the alist of reserved words, or -1 if
5076 TOKEN is not a shell reserved word. */
5078 find_reserved_word (tokstr)
5082 for (i = 0; word_token_alist[i].word; i++)
5083 if (STREQ (tokstr, word_token_alist[i].word))
5089 #if defined (READLINE)
5090 /* Called after each time readline is called. This insures that whatever
5091 the new prompt string is gets propagated to readline's local prompt
5094 reset_readline_prompt ()
5098 if (prompt_string_pointer)
5100 temp_prompt = (*prompt_string_pointer)
5101 ? decode_prompt_string (*prompt_string_pointer)
5104 if (temp_prompt == 0)
5106 temp_prompt = (char *)xmalloc (1);
5107 temp_prompt[0] = '\0';
5110 FREE (current_readline_prompt);
5111 current_readline_prompt = temp_prompt;
5114 #endif /* READLINE */
5117 #if defined (HISTORY)
5118 /* A list of tokens which can be followed by newlines, but not by
5119 semi-colons. When concatenating multiple lines of history, the
5120 newline separator for such tokens is replaced with a space. */
5121 static int no_semi_successors[] = {
5122 '\n', '{', '(', ')', ';', '&', '|',
5123 CASE, DO, ELSE, IF, SEMI_SEMI, THEN, UNTIL, WHILE, AND_AND, OR_OR, IN,
5127 /* If we are not within a delimited expression, try to be smart
5128 about which separators can be semi-colons and which must be
5129 newlines. Returns the string that should be added into the
5132 history_delimiting_chars ()
5136 if (dstack.delimiter_depth != 0)
5139 /* First, handle some special cases. */
5141 /* If we just read `()', assume it's a function definition, and don't
5142 add a semicolon. If the token before the `)' was not `(', and we're
5143 not in the midst of parsing a case statement, assume it's a
5144 parenthesized command and add the semicolon. */
5146 if (token_before_that == ')')
5148 if (two_tokens_ago == '(') /*)*/ /* function def */
5150 /* This does not work for subshells inside case statement
5151 command lists. It's a suboptimal solution. */
5152 else if (parser_state & PST_CASESTMT) /* case statement pattern */
5155 return "; "; /* (...) subshell */
5157 else if (token_before_that == WORD && two_tokens_ago == FUNCTION)
5158 return " "; /* function def using `function name' without `()' */
5160 else if (token_before_that == WORD && two_tokens_ago == FOR)
5162 /* Tricky. `for i\nin ...' should not have a semicolon, but
5163 `for i\ndo ...' should. We do what we can. */
5164 for (i = shell_input_line_index; whitespace(shell_input_line[i]); i++)
5166 if (shell_input_line[i] && shell_input_line[i] == 'i' && shell_input_line[i+1] == 'n')
5171 for (i = 0; no_semi_successors[i]; i++)
5173 if (token_before_that == no_semi_successors[i])
5179 #endif /* HISTORY */
5181 /* Issue a prompt, or prepare to issue a prompt when the next character
5188 if (!interactive) /* XXX */
5191 ps1_prompt = get_string_value ("PS1");
5192 ps2_prompt = get_string_value ("PS2");
5194 if (!prompt_string_pointer)
5195 prompt_string_pointer = &ps1_prompt;
5197 temp_prompt = *prompt_string_pointer
5198 ? decode_prompt_string (*prompt_string_pointer)
5201 if (temp_prompt == 0)
5203 temp_prompt = (char *)xmalloc (1);
5204 temp_prompt[0] = '\0';
5207 current_prompt_string = *prompt_string_pointer;
5208 prompt_string_pointer = &ps2_prompt;
5210 #if defined (READLINE)
5211 if (!no_line_editing)
5213 FREE (current_readline_prompt);
5214 current_readline_prompt = temp_prompt;
5217 #endif /* READLINE */
5219 FREE (current_decoded_prompt);
5220 current_decoded_prompt = temp_prompt;
5225 get_current_prompt_level ()
5227 return ((current_prompt_string && current_prompt_string == ps2_prompt) ? 2 : 1);
5231 set_current_prompt_level (x)
5234 prompt_string_pointer = (x == 2) ? &ps2_prompt : &ps1_prompt;
5235 current_prompt_string = *prompt_string_pointer;
5241 fprintf (stderr, "%s", current_decoded_prompt);
5245 /* Return a string which will be printed as a prompt. The string
5246 may contain special characters which are decoded as follows:
5249 \d the date in Day Mon Date format
5250 \e escape (ascii 033)
5251 \h the hostname up to the first `.'
5253 \j the number of active jobs
5254 \l the basename of the shell's tty device name
5257 \s the name of the shell
5258 \t the time in 24-hour hh:mm:ss format
5259 \T the time in 12-hour hh:mm:ss format
5260 \@ the time in 12-hour hh:mm am/pm format
5261 \A the time in 24-hour hh:mm format
5262 \D{fmt} the result of passing FMT to strftime(3)
5264 \v the version of bash (e.g., 2.00)
5265 \V the release of bash, version + patchlevel (e.g., 2.00.0)
5266 \w the current working directory
5267 \W the last element of $PWD
5268 \! the history number of this command
5269 \# the command number of this command
5270 \$ a $ or a # if you are root
5271 \nnn character code nnn in octal
5273 \[ begin a sequence of non-printing chars
5274 \] end a sequence of non-printing chars
5276 #define PROMPT_GROWTH 48
5278 decode_prompt_string (string)
5283 struct dstack save_dstack;
5284 int last_exit_value;
5285 #if defined (PROMPT_STRING_DECODE)
5286 int result_size, result_index;
5288 char *temp, octal_string[4];
5294 result = (char *)xmalloc (result_size = PROMPT_GROWTH);
5295 result[result_index = 0] = 0;
5296 temp = (char *)NULL;
5298 while (c = *string++)
5300 if (posixly_correct && c == '!')
5304 temp = savestring ("!");
5309 #if !defined (HISTORY)
5310 temp = savestring ("1");
5312 temp = itos (history_number ());
5313 #endif /* HISTORY */
5314 string--; /* add_string increments string again. */
5332 strncpy (octal_string, string, 3);
5333 octal_string[3] = '\0';
5335 n = read_octal (octal_string);
5336 temp = (char *)xmalloc (3);
5338 if (n == CTLESC || n == CTLNUL)
5355 for (c = 0; n != -1 && c < 3 && ISOCTAL (*string); c++)
5358 c = 0; /* tested at add_string: */
5366 /* Make the current time/date into a string. */
5367 (void) time (&the_time);
5368 tm = localtime (&the_time);
5371 n = strftime (timebuf, sizeof (timebuf), "%a %b %d", tm);
5373 n = strftime (timebuf, sizeof (timebuf), "%H:%M:%S", tm);
5375 n = strftime (timebuf, sizeof (timebuf), "%I:%M:%S", tm);
5377 n = strftime (timebuf, sizeof (timebuf), "%I:%M %p", tm);
5379 n = strftime (timebuf, sizeof (timebuf), "%H:%M", tm);
5381 timebuf[sizeof(timebuf) - 1] = '\0';
5382 temp = savestring (timebuf);
5385 case 'D': /* strftime format */
5386 if (string[1] != '{') /* } */
5389 (void) time (&the_time);
5390 tm = localtime (&the_time);
5391 string += 2; /* skip { */
5392 timefmt = xmalloc (strlen (string) + 3);
5393 for (t = timefmt; *string && *string != '}'; )
5396 c = *string; /* tested at add_string */
5397 if (timefmt[0] == '\0')
5400 timefmt[1] = 'X'; /* locale-specific current time */
5403 n = strftime (timebuf, sizeof (timebuf), timefmt, tm);
5406 timebuf[sizeof(timebuf) - 1] = '\0';
5407 if (promptvars || posixly_correct)
5408 /* Make sure that expand_prompt_string is called with a
5409 second argument of Q_DOUBLE_QUOTES if we use this
5411 temp = sh_backslash_quote_for_double_quotes (timebuf);
5413 temp = savestring (timebuf);
5417 temp = (char *)xmalloc (3);
5418 temp[0] = no_line_editing ? '\n' : '\r';
5419 temp[1] = no_line_editing ? '\0' : '\n';
5424 temp = base_pathname (shell_name);
5425 temp = savestring (temp);
5430 temp = (char *)xmalloc (16);
5432 strcpy (temp, dist_version);
5434 sprintf (temp, "%s.%d", dist_version, patch_level);
5440 /* Use the value of PWD because it is much more efficient. */
5441 char t_string[PATH_MAX];
5444 temp = get_string_value ("PWD");
5448 if (getcwd (t_string, sizeof(t_string)) == 0)
5454 tlen = strlen (t_string);
5458 tlen = sizeof (t_string) - 1;
5459 strncpy (t_string, temp, tlen);
5461 t_string[tlen] = '\0';
5463 #define ROOT_PATH(x) ((x)[0] == '/' && (x)[1] == 0)
5464 #define DOUBLE_SLASH_ROOT(x) ((x)[0] == '/' && (x)[1] == '/' && (x)[2] == 0)
5467 if (ROOT_PATH (t_string) == 0 && DOUBLE_SLASH_ROOT (t_string) == 0)
5469 t = strrchr (t_string, '/');
5471 strcpy (t_string, t + 1);
5475 #undef DOUBLE_SLASH_ROOT
5477 /* polite_directory_format is guaranteed to return a string
5478 no longer than PATH_MAX - 1 characters. */
5479 strcpy (t_string, polite_directory_format (t_string));
5481 /* If we're going to be expanding the prompt string later,
5482 quote the directory name. */
5483 if (promptvars || posixly_correct)
5484 /* Make sure that expand_prompt_string is called with a
5485 second argument of Q_DOUBLE_QUOTES if we use this
5487 temp = sh_backslash_quote_for_double_quotes (t_string);
5489 temp = savestring (t_string);
5495 if (current_user.user_name == 0)
5496 get_current_user_info ();
5497 temp = savestring (current_user.user_name);
5502 temp = savestring (current_host_name);
5503 if (c == 'h' && (t = (char *)strchr (temp, '.')))
5508 temp = itos (current_command_number);
5512 #if !defined (HISTORY)
5513 temp = savestring ("1");
5515 temp = itos (history_number ());
5516 #endif /* HISTORY */
5520 t = temp = (char *)xmalloc (3);
5521 if ((promptvars || posixly_correct) && (current_user.euid != 0))
5523 *t++ = current_user.euid == 0 ? '#' : '$';
5528 temp = itos (count_all_jobs ());
5532 #if defined (HAVE_TTYNAME)
5533 temp = (char *)ttyname (fileno (stdin));
5534 t = temp ? base_pathname (temp) : "tty";
5535 temp = savestring (t);
5537 temp = savestring ("tty");
5538 #endif /* !HAVE_TTYNAME */
5541 #if defined (READLINE)
5544 temp = (char *)xmalloc (3);
5546 temp[1] = (c == '[') ? RL_PROMPT_START_IGNORE : RL_PROMPT_END_IGNORE;
5549 #endif /* READLINE */
5555 temp = (char *)xmalloc (2);
5562 else /* (c == '\\') */
5569 temp = (char *)xmalloc (3);
5578 sub_append_string (temp, result, &result_index, &result_size);
5579 temp = (char *)NULL; /* Freed in sub_append_string (). */
5580 result[result_index] = '\0';
5586 RESIZE_MALLOCED_BUFFER (result, result_index, 3, result_size, PROMPT_GROWTH);
5587 result[result_index++] = c;
5588 result[result_index] = '\0';
5591 #else /* !PROMPT_STRING_DECODE */
5592 result = savestring (string);
5593 #endif /* !PROMPT_STRING_DECODE */
5595 /* Save the delimiter stack and point `dstack' to temp space so any
5596 command substitutions in the prompt string won't result in screwing
5597 up the parser's quoting state. */
5598 save_dstack = dstack;
5599 dstack = temp_dstack;
5600 dstack.delimiter_depth = 0;
5602 /* Perform variable and parameter expansion and command substitution on
5603 the prompt string. */
5604 if (promptvars || posixly_correct)
5606 last_exit_value = last_command_exit_value;
5607 list = expand_prompt_string (result, Q_DOUBLE_QUOTES);
5609 result = string_list (list);
5610 dispose_words (list);
5611 last_command_exit_value = last_exit_value;
5615 t = dequote_string (result);
5620 dstack = save_dstack;
5625 /************************************************
5629 ************************************************/
5631 /* Report a syntax error, and restart the parser. Call here for fatal
5637 report_syntax_error ((char *)NULL);
5643 error_token_from_token (token)
5648 if (t = find_token_in_alist (token, word_token_alist, 0))
5651 if (t = find_token_in_alist (token, other_token_alist, 0))
5655 /* This stuff is dicy and needs closer inspection */
5656 switch (current_token)
5659 case ASSIGNMENT_WORD:
5661 t = savestring (yylval.word->word);
5664 t = itos (yylval.number);
5667 if (yylval.word_list)
5668 t = string_list (yylval.word_list);
5670 case ARITH_FOR_EXPRS:
5671 if (yylval.word_list)
5672 t = string_list_internal (yylval.word_list, " ; ");
5675 t = (char *)NULL; /* punt */
5683 error_token_from_text ()
5688 t = shell_input_line;
5689 i = shell_input_line_index;
5693 if (i && t[i] == '\0')
5696 while (i && (whitespace (t[i]) || t[i] == '\n'))
5702 while (i && (member (t[i], " \n\t;|&") == 0))
5705 while (i != token_end && (whitespace (t[i]) || t[i] == '\n'))
5708 /* Return our idea of the offending token. */
5709 if (token_end || (i == 0 && token_end == 0))
5712 msg = substring (t, i, token_end);
5713 else /* one-character token */
5715 msg = (char *)xmalloc (2);
5725 print_offending_line ()
5730 msg = savestring (shell_input_line);
5731 token_end = strlen (msg);
5732 while (token_end && msg[token_end - 1] == '\n')
5733 msg[--token_end] = '\0';
5735 parser_error (line_number, "`%s'", msg);
5739 /* Report a syntax error with line numbers, etc.
5740 Call here for recoverable errors. If you have a message to print,
5741 then place it in MESSAGE, otherwise pass NULL and this will figure
5742 out an appropriate message for you. */
5744 report_syntax_error (message)
5751 parser_error (line_number, "%s", message);
5752 if (interactive && EOF_Reached)
5754 last_command_exit_value = EX_USAGE;
5758 /* If the line of input we're reading is not null, try to find the
5759 objectionable token. First, try to figure out what token the
5760 parser's complaining about by looking at current_token. */
5761 if (current_token != 0 && EOF_Reached == 0 && (msg = error_token_from_token (current_token)))
5763 parser_error (line_number, "syntax error near unexpected token `%s'", msg);
5766 if (interactive == 0)
5767 print_offending_line ();
5769 last_command_exit_value = EX_USAGE;
5773 /* If looking at the current token doesn't prove fruitful, try to find the
5774 offending token by analyzing the text of the input line near the current
5775 input line index and report what we find. */
5776 if (shell_input_line && *shell_input_line)
5778 msg = error_token_from_text ();
5781 parser_error (line_number, "syntax error near `%s'", msg);
5785 /* If not interactive, print the line containing the error. */
5786 if (interactive == 0)
5787 print_offending_line ();
5791 msg = EOF_Reached ? "syntax error: unexpected end of file" : "syntax error";
5792 parser_error (line_number, "%s", msg);
5793 /* When the shell is interactive, this file uses EOF_Reached
5794 only for error reporting. Other mechanisms are used to
5795 decide whether or not to exit. */
5796 if (interactive && EOF_Reached)
5800 last_command_exit_value = EX_USAGE;
5803 /* ??? Needed function. ??? We have to be able to discard the constructs
5804 created during parsing. In the case of error, we want to return
5805 allocated objects to the memory pool. In the case of no error, we want
5806 to throw away the information about where the allocated objects live.
5807 (dispose_command () will actually free the command.) */
5809 discard_parser_constructs (error_p)
5814 /************************************************
5818 ************************************************/
5820 /* Do that silly `type "bye" to exit' stuff. You know, "ignoreeof". */
5822 /* A flag denoting whether or not ignoreeof is set. */
5825 /* The number of times that we have encountered an EOF character without
5826 another character intervening. When this gets above the limit, the
5827 shell terminates. */
5828 int eof_encountered = 0;
5830 /* The limit for eof_encountered. */
5831 int eof_encountered_limit = 10;
5833 /* If we have EOF as the only input unit, this user wants to leave
5834 the shell. If the shell is not interactive, then just leave.
5835 Otherwise, if ignoreeof is set, and we haven't done this the
5836 required number of times in a row, print a message. */
5838 handle_eof_input_unit ()
5842 /* shell.c may use this to decide whether or not to write out the
5843 history, among other things. We use it only for error reporting
5848 /* If the user wants to "ignore" eof, then let her do so, kind of. */
5851 if (eof_encountered < eof_encountered_limit)
5853 fprintf (stderr, "Use \"%s\" to leave the shell.\n",
5854 login_shell ? "logout" : "exit");
5856 /* Reset the parsing state. */
5857 last_read_token = current_token = '\n';
5858 /* Reset the prompt string to be $PS1. */
5859 prompt_string_pointer = (char **)NULL;
5865 /* In this case EOF should exit the shell. Do it now. */
5867 exit_builtin ((WORD_LIST *)NULL);
5871 /* We don't write history files, etc., for non-interactive shells. */
5876 /************************************************
5878 * STRING PARSING FUNCTIONS *
5880 ************************************************/
5882 /* It's very important that these two functions treat the characters
5883 between ( and ) identically. */
5885 static WORD_LIST parse_string_error;
5887 /* Take a string and run it through the shell parser, returning the
5888 resultant word list. Used by compound array assignment. */
5890 parse_string_to_word_list (s, whom)
5895 int tok, orig_current_token, orig_line_number, orig_input_terminator;
5896 int orig_line_count;
5897 int old_echo_input, old_expand_aliases;
5898 #if defined (HISTORY)
5899 int old_remember_on_history, old_history_expansion_inhibited;
5902 #if defined (HISTORY)
5903 old_remember_on_history = remember_on_history;
5904 # if defined (BANG_HISTORY)
5905 old_history_expansion_inhibited = history_expansion_inhibited;
5907 bash_history_disable ();
5910 orig_line_number = line_number;
5911 orig_line_count = current_command_line_count;
5912 orig_input_terminator = shell_input_line_terminator;
5913 old_echo_input = echo_input_at_read;
5914 old_expand_aliases = expand_aliases;
5917 last_read_token = WORD; /* WORD to allow reserved words here */
5918 current_command_line_count = 0;
5919 echo_input_at_read = expand_aliases = 0;
5921 with_input_from_string (s, whom);
5922 wl = (WORD_LIST *)NULL;
5923 while ((tok = read_token (READ)) != yacc_EOF)
5925 if (tok == '\n' && *bash_input.location.string == '\0')
5927 if (tok == '\n') /* Allow newlines in compound assignments */
5929 if (tok != WORD && tok != ASSIGNMENT_WORD)
5931 line_number = orig_line_number + line_number - 1;
5932 orig_current_token = current_token;
5933 current_token = tok;
5934 yyerror ((char *)NULL); /* does the right thing */
5935 current_token = orig_current_token;
5938 wl = &parse_string_error;
5941 wl = make_word_list (yylval.word, wl);
5944 last_read_token = '\n';
5947 #if defined (HISTORY)
5948 remember_on_history = old_remember_on_history;
5949 # if defined (BANG_HISTORY)
5950 history_expansion_inhibited = old_history_expansion_inhibited;
5951 # endif /* BANG_HISTORY */
5952 #endif /* HISTORY */
5954 echo_input_at_read = old_echo_input;
5955 expand_aliases = old_expand_aliases;
5957 current_command_line_count = orig_line_count;
5958 shell_input_line_terminator = orig_input_terminator;
5960 if (wl == &parse_string_error)
5962 last_command_exit_value = EXECUTION_FAILURE;
5963 if (interactive_shell == 0 && posixly_correct)
5964 jump_to_top_level (FORCE_EOF);
5966 jump_to_top_level (DISCARD);
5969 return (REVERSE_LIST (wl, WORD_LIST *));
5973 parse_compound_assignment (retlenp)
5977 int tok, orig_line_number, orig_token_size;
5978 char *saved_token, *ret;
5980 saved_token = token;
5981 orig_token_size = token_buffer_size;
5982 orig_line_number = line_number;
5984 last_read_token = WORD; /* WORD to allow reserved words here */
5986 token = (char *)NULL;
5987 token_buffer_size = 0;
5989 wl = (WORD_LIST *)NULL; /* ( */
5990 while ((tok = read_token (READ)) != ')')
5992 if (tok == '\n') /* Allow newlines in compound assignments */
5994 if (tok != WORD && tok != ASSIGNMENT_WORD)
5996 current_token = tok; /* for error reporting */
5997 if (tok == yacc_EOF) /* ( */
5998 parser_error (orig_line_number, "unexpected EOF while looking for matching `)'");
6000 yyerror ((char *)NULL); /* does the right thing */
6003 wl = &parse_string_error;
6006 wl = make_word_list (yylval.word, wl);
6010 token = saved_token;
6011 token_buffer_size = orig_token_size;
6013 if (wl == &parse_string_error)
6015 last_command_exit_value = EXECUTION_FAILURE;
6016 last_read_token = '\n'; /* XXX */
6017 if (interactive_shell == 0 && posixly_correct)
6018 jump_to_top_level (FORCE_EOF);
6020 jump_to_top_level (DISCARD);
6023 last_read_token = WORD;
6026 rl = REVERSE_LIST (wl, WORD_LIST *);
6027 ret = string_list (rl);
6034 *retlenp = (ret && *ret) ? strlen (ret) : 0;
6038 /************************************************
6040 * MULTIBYTE CHARACTER HANDLING *
6042 ************************************************/
6044 #if defined (HANDLE_MULTIBYTE)
6049 mbstate_t mbs, prevs;
6052 if (shell_input_line == NULL)
6054 len = strlen (shell_input_line); /* XXX - shell_input_line_len ? */
6055 FREE (shell_input_line_property);
6056 shell_input_line_property = (char *)xmalloc (len + 1);
6058 memset (&prevs, '\0', sizeof (mbstate_t));
6059 for (i = previ = 0; i < len; i++)
6063 if (shell_input_line[i] == EOF)
6066 for (j = i; j < len; j++)
6067 shell_input_line_property[j] = 1;
6071 mbclen = mbrlen (shell_input_line + previ, i - previ + 1, &mbs);
6072 if (mbclen == 1 || mbclen == (size_t)-1)
6077 else if (mbclen == (size_t)-2)
6079 else if (mbclen > 1)
6087 /* mbrlen doesn't return any other values */
6090 shell_input_line_property[i] = mbclen;
6093 #endif /* HANDLE_MULTIBYTE */