2 /* A Bison parser, made from /Users/chet/src/bash/src/parse.y
3 by GNU Bison version 1.28 */
5 #define YYBISON 1 /* Identify Bison output. */
21 #define COND_START 271
23 #define COND_ERROR 273
29 #define ASSIGNMENT_WORD 279
32 #define ARITH_FOR_EXPRS 282
36 #define GREATER_GREATER 286
39 #define LESS_LESS_LESS 289
40 #define GREATER_AND 290
42 #define LESS_LESS_MINUS 292
43 #define AND_GREATER 293
44 #define LESS_GREATER 294
45 #define GREATER_BAR 295
48 #line 21 "/Users/chet/src/bash/src/parse.y"
52 #include "bashtypes.h"
57 #if defined (HAVE_UNISTD_H)
61 #if defined (HAVE_LOCALE_H)
66 #include "chartypes.h"
73 #define NEED_STRFTIME_DECL /* used in externs.h */
79 #include "mailcheck.h"
82 #include "builtins/common.h"
83 #include "builtins/builtext.h"
87 #if defined (READLINE)
88 # include "bashline.h"
89 # include <readline/readline.h>
93 # include "bashhist.h"
94 # include <readline/history.h>
97 #if defined (JOB_CONTROL)
99 #endif /* JOB_CONTROL */
104 typedef void *alias_t
;
107 #if defined (PROMPT_STRING_DECODE)
109 # include <sys/param.h>
112 # if defined (TM_IN_SYS_TIME)
113 # include <sys/types.h>
114 # include <sys/time.h>
115 # endif /* TM_IN_SYS_TIME */
116 # include "maxpath.h"
117 #endif /* PROMPT_STRING_DECODE */
119 #define RE_READ_TOKEN -99
120 #define NO_EXPANSION -100
128 #if defined (HANDLE_MULTIBYTE)
129 # define last_shell_getc_is_singlebyte \
130 ((shell_input_line_index > 1) \
131 ? shell_input_line_property[shell_input_line_index - 1] \
133 # define MBTEST(x) ((x) && last_shell_getc_is_singlebyte)
135 # define last_shell_getc_is_singlebyte 1
136 # define MBTEST(x) ((x))
139 #if defined (EXTENDED_GLOB)
140 extern int extended_glob
;
143 extern int eof_encountered
;
144 extern int no_line_editing
, running_under_emacs
;
145 extern int current_command_number
;
146 extern int sourcelevel
;
147 extern int posixly_correct
;
148 extern int last_command_exit_value
;
149 extern char *shell_name
, *current_host_name
;
150 extern char *dist_version
;
151 extern int patch_level
;
152 extern int dump_translatable_strings
, dump_po_strings
;
153 extern sh_builtin_func_t
*last_shell_builtin
, *this_shell_builtin
;
154 #if defined (BUFFERED_INPUT)
155 extern int bash_input_fd_changed
;
159 /* **************************************************************** */
161 /* "Forward" declarations */
163 /* **************************************************************** */
166 static void debug_parser
__P((int));
169 static int yy_getc
__P((void));
170 static int yy_ungetc
__P((int));
172 #if defined (READLINE)
173 static int yy_readline_get
__P((void));
174 static int yy_readline_unget
__P((int));
177 static int yy_string_get
__P((void));
178 static int yy_string_unget
__P((int));
179 static int yy_stream_get
__P((void));
180 static int yy_stream_unget
__P((int));
182 static int shell_getc
__P((int));
183 static void shell_ungetc
__P((int));
184 static void discard_until
__P((int));
186 #if defined (ALIAS) || defined (DPAREN_ARITHMETIC)
187 static void push_string
__P((char *, int, alias_t
*));
188 static void pop_string
__P((void));
189 static void free_string_list
__P((void));
192 static char *read_a_line
__P((int));
194 static int reserved_word_acceptable
__P((int));
195 static int yylex
__P((void));
196 static int alias_expand_token
__P((char *));
197 static int time_command_acceptable
__P((void));
198 static int special_case_tokens
__P((char *));
199 static int read_token
__P((int));
200 static char *parse_matched_pair
__P((int, int, int, int *, int));
201 #if defined (ARRAY_VARS)
202 static char *parse_compound_assignment
__P((int *));
204 #if defined (DPAREN_ARITHMETIC) || defined (ARITH_FOR_COMMAND)
205 static int parse_dparen
__P((int));
206 static int parse_arith_cmd
__P((char **, int));
208 #if defined (COND_COMMAND)
209 static void cond_error
__P((void));
210 static COND_COM
*cond_expr
__P((void));
211 static COND_COM
*cond_or
__P((void));
212 static COND_COM
*cond_and
__P((void));
213 static COND_COM
*cond_term
__P((void));
214 static int cond_skip_newlines
__P((void));
215 static COMMAND
*parse_cond_command
__P((void));
217 #if defined (ARRAY_VARS)
218 static int token_is_assignment
__P((char *, int));
219 static int token_is_ident
__P((char *, int));
221 static int read_token_word
__P((int));
222 static void discard_parser_constructs
__P((int));
224 static char *error_token_from_token
__P((int));
225 static char *error_token_from_text
__P((void));
226 static void print_offending_line
__P((void));
227 static void report_syntax_error
__P((char *));
229 static void handle_eof_input_unit
__P((void));
230 static void prompt_again
__P((void));
232 static void reset_readline_prompt
__P((void));
234 static void print_prompt
__P((void));
236 #if defined (HANDLE_MULTIBYTE)
237 static void set_line_mbstate
__P((void));
238 static char *shell_input_line_property
= NULL
;
240 # define set_line_mbstate()
243 extern int yyerror
__P((const char *));
249 /* Default prompt strings */
250 char *primary_prompt
= PPROMPT
;
251 char *secondary_prompt
= SPROMPT
;
253 /* PROMPT_STRING_POINTER points to one of these, never to an actual string. */
254 char *ps1_prompt
, *ps2_prompt
;
256 /* Handle on the current prompt string. Indirectly points through
257 ps1_ or ps2_prompt. */
258 char **prompt_string_pointer
= (char **)NULL
;
259 char *current_prompt_string
;
261 /* Non-zero means we expand aliases in commands. */
262 int expand_aliases
= 0;
264 /* If non-zero, the decoded prompt string undergoes parameter and
265 variable substitution, command substitution, arithmetic substitution,
266 string expansion, process substitution, and quote removal in
267 decode_prompt_string. */
270 /* If non-zero, $'...' and $"..." are expanded when they appear within
271 a ${...} expansion, even when the expansion appears within double
273 int extended_quote
= 1;
275 /* The decoded prompt string. Used if READLINE is not defined or if
276 editing is turned off. Analogous to current_readline_prompt. */
277 static char *current_decoded_prompt
;
279 /* The number of lines read from input while creating the current command. */
280 int current_command_line_count
;
282 /* Variables to manage the task of reading here documents, because we need to
283 defer the reading until after a complete command has been collected. */
284 static REDIRECT
*redir_stack
[10];
287 /* Where shell input comes from. History expansion is performed on each
288 line when the shell is interactive. */
289 static char *shell_input_line
= (char *)NULL
;
290 static int shell_input_line_index
;
291 static int shell_input_line_size
; /* Amount allocated for shell_input_line. */
292 static int shell_input_line_len
; /* strlen (shell_input_line) */
294 /* Either zero or EOF. */
295 static int shell_input_line_terminator
;
297 /* The line number in a script on which a function definition starts. */
298 static int function_dstart
;
300 /* The line number in a script on which a function body starts. */
301 static int function_bstart
;
303 /* The line number in a script at which an arithmetic for command starts. */
304 static int arith_for_lineno
;
306 /* The line number in a script where the word in a `case WORD', `select WORD'
307 or `for WORD' begins. This is a nested command maximum, since the array
308 index is decremented after a case, select, or for command is parsed. */
309 #define MAX_CASE_NEST 128
310 static int word_lineno
[MAX_CASE_NEST
];
311 static int word_top
= -1;
313 /* If non-zero, it is the token that we want read_token to return
314 regardless of what text is (or isn't) present to be read. This
315 is reset by read_token. If token_to_read == WORD or
316 ASSIGNMENT_WORD, yylval.word should be set to word_desc_to_read. */
317 static int token_to_read
;
318 static WORD_DESC
*word_desc_to_read
;
320 static REDIRECTEE redir
;
322 #line 295 "/Users/chet/src/bash/src/parse.y"
324 WORD_DESC
*word
; /* the word that we read. */
325 int number
; /* the number that we read. */
326 WORD_LIST
*word_list
;
330 PATTERN_LIST
*pattern
;
343 #define YYFLAG -32768
346 #define YYTRANSLATE(x) ((unsigned)(x) <= 296 ? yytranslate[x] : 90)
348 static const char yytranslate
[] = { 0,
349 2, 2, 2, 2, 2, 2, 2, 2, 2, 44,
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, 42, 2, 52,
353 53, 2, 2, 2, 49, 2, 2, 2, 2, 2,
354 2, 2, 2, 2, 2, 2, 2, 2, 43, 48,
355 2, 47, 2, 2, 2, 2, 2, 2, 2, 2,
356 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
357 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
358 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
359 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
360 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
361 2, 2, 50, 46, 51, 2, 2, 2, 2, 2,
362 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
363 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
364 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
365 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
366 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
367 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
368 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
369 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
370 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
371 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
372 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
373 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
374 2, 2, 2, 2, 2, 1, 3, 4, 5, 6,
375 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
376 17, 18, 19, 20, 21, 22, 23, 24, 25, 26,
377 27, 28, 29, 30, 31, 32, 33, 34, 35, 36,
378 37, 38, 39, 40, 41, 45
382 static const short yyprhs
[] = { 0,
383 0, 3, 5, 8, 10, 12, 15, 18, 21, 25,
384 29, 32, 36, 39, 43, 46, 50, 53, 57, 60,
385 64, 67, 71, 74, 78, 81, 85, 88, 92, 95,
386 99, 102, 106, 109, 112, 116, 118, 120, 122, 124,
387 127, 129, 132, 134, 136, 139, 141, 143, 145, 151,
388 157, 159, 161, 163, 165, 167, 169, 171, 178, 185,
389 193, 201, 212, 223, 233, 243, 251, 259, 265, 271,
390 278, 285, 293, 301, 312, 323, 330, 338, 345, 351,
391 358, 363, 365, 368, 372, 378, 386, 393, 397, 399,
392 403, 408, 415, 421, 423, 426, 431, 436, 442, 448,
393 451, 455, 457, 461, 464, 466, 469, 473, 477, 481,
394 486, 491, 496, 501, 506, 508, 510, 512, 514, 516,
395 518, 519, 522, 524, 527, 530, 535, 540, 544, 548,
396 550, 552, 555, 558, 562, 566, 569, 574, 576, 578
399 static const short yyrhs
[] = { 85,
400 82, 0, 44, 0, 1, 44, 0, 45, 0, 24,
401 0, 55, 24, 0, 47, 24, 0, 48, 24, 0,
402 26, 47, 24, 0, 26, 48, 24, 0, 32, 24,
403 0, 26, 32, 24, 0, 33, 24, 0, 26, 33,
404 24, 0, 35, 24, 0, 26, 35, 24, 0, 34,
405 26, 0, 26, 34, 26, 0, 36, 26, 0, 26,
406 36, 26, 0, 34, 24, 0, 26, 34, 24, 0,
407 36, 24, 0, 26, 36, 24, 0, 38, 24, 0,
408 26, 38, 24, 0, 36, 49, 0, 26, 36, 49,
409 0, 34, 49, 0, 26, 34, 49, 0, 39, 24,
410 0, 26, 40, 24, 0, 40, 24, 0, 41, 24,
411 0, 26, 41, 24, 0, 24, 0, 25, 0, 56,
412 0, 56, 0, 58, 56, 0, 57, 0, 59, 57,
413 0, 59, 0, 61, 0, 61, 58, 0, 66, 0,
414 62, 0, 65, 0, 12, 79, 14, 79, 15, 0,
415 13, 79, 14, 79, 15, 0, 64, 0, 69, 0,
416 68, 0, 70, 0, 71, 0, 72, 0, 63, 0,
417 10, 24, 84, 14, 79, 15, 0, 10, 24, 84,
418 50, 79, 51, 0, 10, 24, 43, 84, 14, 79,
419 15, 0, 10, 24, 43, 84, 50, 79, 51, 0,
420 10, 24, 84, 20, 55, 83, 84, 14, 79, 15,
421 0, 10, 24, 84, 20, 55, 83, 84, 50, 79,
422 51, 0, 10, 24, 84, 20, 83, 84, 14, 79,
423 15, 0, 10, 24, 84, 20, 83, 84, 50, 79,
424 51, 0, 10, 28, 83, 84, 14, 79, 15, 0,
425 10, 28, 83, 84, 50, 79, 51, 0, 10, 28,
426 14, 79, 15, 0, 10, 28, 50, 79, 51, 0,
427 11, 24, 84, 14, 78, 15, 0, 11, 24, 84,
428 50, 78, 51, 0, 11, 24, 43, 84, 14, 78,
429 15, 0, 11, 24, 43, 84, 50, 78, 51, 0,
430 11, 24, 84, 20, 55, 83, 84, 14, 78, 15,
431 0, 11, 24, 84, 20, 55, 83, 84, 50, 78,
432 51, 0, 8, 24, 84, 20, 84, 9, 0, 8,
433 24, 84, 20, 76, 84, 9, 0, 8, 24, 84,
434 20, 74, 9, 0, 24, 52, 53, 84, 67, 0,
435 16, 24, 52, 53, 84, 67, 0, 16, 24, 84,
436 67, 0, 61, 0, 61, 58, 0, 52, 79, 53,
437 0, 3, 79, 4, 79, 7, 0, 3, 79, 4,
438 79, 5, 79, 7, 0, 3, 79, 4, 79, 73,
439 7, 0, 50, 79, 51, 0, 27, 0, 17, 29,
440 18, 0, 6, 79, 4, 79, 0, 6, 79, 4,
441 79, 5, 79, 0, 6, 79, 4, 79, 73, 0,
442 75, 0, 76, 75, 0, 84, 77, 53, 79, 0,
443 84, 77, 53, 84, 0, 84, 52, 77, 53, 79,
444 0, 84, 52, 77, 53, 84, 0, 75, 37, 0,
445 76, 75, 37, 0, 24, 0, 77, 46, 24, 0,
446 84, 80, 0, 78, 0, 84, 81, 0, 81, 44,
447 84, 0, 81, 42, 84, 0, 81, 43, 84, 0,
448 81, 30, 84, 81, 0, 81, 31, 84, 81, 0,
449 81, 42, 84, 81, 0, 81, 43, 84, 81, 0,
450 81, 44, 84, 81, 0, 87, 0, 44, 0, 45,
451 0, 44, 0, 43, 0, 45, 0, 0, 84, 44,
452 0, 86, 0, 86, 42, 0, 86, 43, 0, 86,
453 30, 84, 86, 0, 86, 31, 84, 86, 0, 86,
454 42, 86, 0, 86, 43, 86, 0, 87, 0, 88,
455 0, 21, 88, 0, 89, 88, 0, 89, 21, 88,
456 0, 21, 89, 88, 0, 89, 83, 0, 88, 46,
457 84, 88, 0, 60, 0, 22, 0, 22, 23, 0
463 static const short yyrline
[] = { 0,
464 346, 355, 362, 377, 387, 389, 393, 398, 403, 408,
465 413, 418, 423, 429, 435, 440, 445, 450, 455, 460,
466 465, 470, 475, 480, 485, 492, 499, 504, 509, 514,
467 519, 524, 529, 534, 539, 546, 548, 550, 554, 558,
468 569, 571, 575, 577, 579, 595, 599, 601, 603, 605,
469 607, 609, 611, 613, 615, 617, 619, 623, 628, 633,
470 638, 643, 648, 653, 658, 665, 670, 675, 680, 687,
471 692, 697, 702, 707, 712, 719, 724, 729, 736, 739,
472 742, 747, 749, 780, 787, 789, 791, 796, 800, 804,
473 808, 810, 812, 816, 817, 821, 823, 825, 827, 831,
474 832, 836, 838, 847, 855, 856, 862, 863, 870, 874,
475 876, 878, 885, 887, 889, 893, 894, 897, 899, 901,
476 905, 906, 915, 921, 930, 938, 940, 942, 949, 952,
477 956, 958, 964, 970, 976, 982, 1002, 1005, 1009, 1011
482 #if YYDEBUG != 0 || defined (YYERROR_VERBOSE)
484 static const char * const yytname
[] = { "$","error","$undefined.","IF","THEN",
485 "ELSE","ELIF","FI","CASE","ESAC","FOR","SELECT","WHILE","UNTIL","DO","DONE",
486 "FUNCTION","COND_START","COND_END","COND_ERROR","IN","BANG","TIME","TIMEOPT",
487 "WORD","ASSIGNMENT_WORD","NUMBER","ARITH_CMD","ARITH_FOR_EXPRS","COND_CMD","AND_AND",
488 "OR_OR","GREATER_GREATER","LESS_LESS","LESS_AND","LESS_LESS_LESS","GREATER_AND",
489 "SEMI_SEMI","LESS_LESS_MINUS","AND_GREATER","LESS_GREATER","GREATER_BAR","'&'",
490 "';'","'\\n'","yacc_EOF","'|'","'>'","'<'","'-'","'{'","'}'","'('","')'","inputunit",
491 "word_list","redirection","simple_command_element","redirection_list","simple_command",
492 "command","shell_command","for_command","arith_for_command","select_command",
493 "case_command","function_def","function_body","subshell","if_command","group_command",
494 "arith_command","cond_command","elif_clause","case_clause","pattern_list","case_clause_sequence",
495 "pattern","list","compound_list","list0","list1","simple_list_terminator","list_terminator",
496 "newline_list","simple_list","simple_list1","pipeline_command","pipeline","timespec", NULL
500 static const short yyr1
[] = { 0,
501 54, 54, 54, 54, 55, 55, 56, 56, 56, 56,
502 56, 56, 56, 56, 56, 56, 56, 56, 56, 56,
503 56, 56, 56, 56, 56, 56, 56, 56, 56, 56,
504 56, 56, 56, 56, 56, 57, 57, 57, 58, 58,
505 59, 59, 60, 60, 60, 60, 61, 61, 61, 61,
506 61, 61, 61, 61, 61, 61, 61, 62, 62, 62,
507 62, 62, 62, 62, 62, 63, 63, 63, 63, 64,
508 64, 64, 64, 64, 64, 65, 65, 65, 66, 66,
509 66, 67, 67, 68, 69, 69, 69, 70, 71, 72,
510 73, 73, 73, 74, 74, 75, 75, 75, 75, 76,
511 76, 77, 77, 78, 79, 79, 80, 80, 80, 81,
512 81, 81, 81, 81, 81, 82, 82, 83, 83, 83,
513 84, 84, 85, 85, 85, 86, 86, 86, 86, 86,
514 87, 87, 87, 87, 87, 87, 88, 88, 89, 89
517 static const short yyr2
[] = { 0,
518 2, 1, 2, 1, 1, 2, 2, 2, 3, 3,
519 2, 3, 2, 3, 2, 3, 2, 3, 2, 3,
520 2, 3, 2, 3, 2, 3, 2, 3, 2, 3,
521 2, 3, 2, 2, 3, 1, 1, 1, 1, 2,
522 1, 2, 1, 1, 2, 1, 1, 1, 5, 5,
523 1, 1, 1, 1, 1, 1, 1, 6, 6, 7,
524 7, 10, 10, 9, 9, 7, 7, 5, 5, 6,
525 6, 7, 7, 10, 10, 6, 7, 6, 5, 6,
526 4, 1, 2, 3, 5, 7, 6, 3, 1, 3,
527 4, 6, 5, 1, 2, 4, 4, 5, 5, 2,
528 3, 1, 3, 2, 1, 2, 3, 3, 3, 4,
529 4, 4, 4, 4, 1, 1, 1, 1, 1, 1,
530 0, 2, 1, 2, 2, 4, 4, 3, 3, 1,
531 1, 2, 2, 3, 3, 2, 4, 1, 1, 2
534 static const short yydefact
[] = { 0,
535 0, 121, 0, 0, 0, 121, 121, 0, 0, 0,
536 139, 36, 37, 0, 89, 0, 0, 0, 0, 0,
537 0, 0, 0, 0, 2, 4, 0, 0, 121, 121,
538 38, 41, 43, 138, 44, 47, 57, 51, 48, 46,
539 53, 52, 54, 55, 56, 0, 123, 130, 131, 0,
540 3, 105, 0, 0, 121, 121, 0, 121, 0, 0,
541 121, 0, 132, 0, 140, 0, 0, 0, 0, 0,
542 0, 0, 0, 0, 0, 0, 11, 13, 21, 17,
543 29, 15, 23, 19, 27, 25, 31, 33, 34, 7,
544 8, 0, 0, 36, 42, 39, 45, 116, 117, 1,
545 121, 121, 124, 125, 121, 0, 119, 118, 120, 136,
546 133, 121, 122, 104, 106, 115, 0, 121, 0, 121,
547 121, 121, 121, 0, 121, 121, 0, 0, 90, 135,
548 121, 12, 14, 22, 18, 30, 16, 24, 20, 28,
549 26, 32, 35, 9, 10, 88, 84, 40, 0, 0,
550 128, 129, 0, 134, 0, 121, 121, 121, 121, 121,
551 121, 0, 121, 0, 121, 0, 0, 0, 0, 121,
552 0, 121, 0, 0, 121, 82, 81, 0, 126, 127,
553 0, 0, 137, 121, 121, 85, 0, 0, 0, 108,
554 109, 107, 0, 94, 121, 0, 121, 121, 0, 5,
555 0, 121, 0, 68, 69, 121, 121, 121, 121, 0,
556 0, 0, 0, 49, 50, 0, 83, 79, 0, 0,
557 87, 110, 111, 112, 113, 114, 78, 100, 95, 0,
558 76, 102, 0, 0, 0, 0, 58, 6, 121, 0,
559 59, 0, 0, 0, 0, 70, 0, 121, 71, 80,
560 86, 121, 121, 121, 121, 101, 77, 0, 0, 121,
561 60, 61, 0, 121, 121, 66, 67, 72, 73, 0,
562 91, 0, 0, 0, 121, 103, 96, 97, 121, 121,
563 0, 0, 121, 121, 121, 93, 98, 99, 0, 0,
564 64, 65, 0, 0, 92, 62, 63, 74, 75, 0,
568 static const short yydefgoto
[] = { 300,
569 201, 31, 32, 97, 33, 34, 35, 36, 37, 38,
570 39, 40, 177, 41, 42, 43, 44, 45, 187, 193,
571 194, 195, 234, 52, 53, 114, 115, 100, 110, 54,
575 static const short yypact
[] = { 274,
576 -23,-32768, 5, 55, 10,-32768,-32768, 21, 31, 446,
577 32, 19,-32768, 553,-32768, 56, 72, -12, 89, -11,
578 92, 102, 111, 113,-32768,-32768, 117, 124,-32768,-32768,
579 -32768,-32768, 183,-32768, 202,-32768,-32768,-32768,-32768,-32768,
580 -32768,-32768,-32768,-32768,-32768, -13, 134,-32768, 52, 317,
581 -32768,-32768, 148, 360,-32768, 115, 22, 120, 154, 173,
582 114, 155, 52, 532,-32768, 140, 180, 181, 101, 182,
583 112, 186, 188, 189, 190, 205,-32768,-32768,-32768,-32768,
584 -32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,
585 -32768, 193, 195,-32768,-32768,-32768, 202,-32768,-32768,-32768,
586 -32768,-32768, 403, 403,-32768, 532,-32768,-32768,-32768,-32768,
587 52,-32768,-32768,-32768, 221,-32768, -9,-32768, 42,-32768,
588 -32768,-32768,-32768, 61,-32768,-32768, 200, 41,-32768, 52,
589 -32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,
590 -32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768, 360, 360,
591 152, 152, 489, 52, 192,-32768,-32768,-32768,-32768,-32768,
592 -32768, 26,-32768, 127,-32768, 218, 194, 34, 73,-32768,
593 215,-32768, 242, 245,-32768, 202,-32768, 41,-32768,-32768,
594 403, 403, 52,-32768,-32768,-32768, 254, 360, 360, 360,
595 360, 360, 253, 229,-32768, -2,-32768,-32768, 252,-32768,
596 151,-32768, 217,-32768,-32768,-32768,-32768,-32768,-32768, 255,
597 360, 151, 220,-32768,-32768, 41, 202,-32768, 265, 272,
598 -32768,-32768,-32768, 159, 159, 159,-32768,-32768, 241, 17,
599 -32768,-32768, 256, 36, 266, 232,-32768,-32768,-32768, 74,
600 -32768, 273, 238, 277, 243,-32768, 221,-32768,-32768,-32768,
601 -32768,-32768,-32768,-32768,-32768,-32768,-32768, 116, 269,-32768,
602 -32768,-32768, 90,-32768,-32768,-32768,-32768,-32768,-32768, 95,
603 197, 360, 360, 360,-32768,-32768,-32768, 360,-32768,-32768,
604 282, 251,-32768,-32768,-32768,-32768,-32768, 360, 288, 260,
605 -32768,-32768, 289, 280,-32768,-32768,-32768,-32768,-32768, 305,
609 static const short yypgoto
[] = {-32768,
610 146, -33, 290, 156,-32768,-32768, -119,-32768,-32768,-32768,
611 -32768,-32768, -153,-32768,-32768,-32768,-32768,-32768, 64,-32768,
612 141,-32768, 104, -162, -6,-32768, -172,-32768, -52, -28,
613 -32768, 6, 4, -7, 329
620 static const short yytable
[] = { 59,
621 60, 96, 63, 48, 122, 47, 231, 210, 176, 213,
622 161, 79, 83, 80, 84, 222, 223, 224, 225, 226,
623 51, 232, 92, 93, 218, 257, 117, 119, 55, 124,
624 98, 99, 128, 58, 113, 120, 81, 85, 247, 197,
625 232, 113, 111, 2, 61, 244, 245, 206, 3, 233,
626 4, 5, 6, 7, 65, 163, 130, 9, 176, 62,
627 113, 164, 250, 148, 107, 108, 109, 15, 233, 113,
628 66, 121, 149, 150, 170, 198, 153, 113, 56, 77,
629 171, 259, 57, 207, 113, 113, 208, 264, 260, 162,
630 29, 165, 30, 168, 169, 78, 176, 105, 154, 224,
631 225, 226, 178, 279, 113, 155, 48, 48, 283, 152,
632 172, 202, 82, 166, 167, 86, 113, 113, 173, 174,
633 293, 294, 209, 265, 134, 87, 135, 188, 189, 190,
634 191, 192, 196, 113, 88, 138, 89, 139, 113, 280,
635 90, 211, 96, 211, 284, 183, 216, 91, 239, 136,
636 200, 112, 48, 48, 179, 180, 199, 118, 203, 248,
637 140, 259, 123, 101, 102, 127, 230, 125, 275, 107,
638 108, 109, 129, 240, 238, 103, 104, 219, 220, 211,
639 211, 101, 102, 148, 48, 48, 126, 152, 156, 157,
640 235, 236, 131, 107, 108, 109, 184, 185, 186, 242,
641 243, 285, 185, 132, 133, 137, 94, 13, 14, 141,
642 263, 142, 143, 144, 16, 17, 18, 19, 20, 270,
643 21, 22, 23, 24, 272, 273, 274, 14, 145, 27,
644 28, 278, 204, 16, 17, 18, 19, 20, 200, 21,
645 22, 23, 24, 146, 205, 271, 288, 147, 27, 28,
646 156, 157, 175, 277, 211, 211, 214, 281, 282, 215,
647 221, 227, 158, 159, 160, 228, 237, 241, 287, 246,
648 249, 251, 289, 290, 1, 252, 2, 256, 295, 232,
649 261, 3, 262, 4, 5, 6, 7, 266, 267, 8,
650 9, 268, 276, 269, 10, 11, 291, 12, 13, 14,
651 15, 292, 296, 298, 301, 16, 17, 18, 19, 20,
652 297, 21, 22, 23, 24, 302, 212, 25, 26, 2,
653 27, 28, 95, 29, 3, 30, 4, 5, 6, 7,
654 299, 217, 8, 9, 286, 229, 258, 106, 64, 0,
655 12, 13, 14, 15, 0, 0, 0, 0, 16, 17,
656 18, 19, 20, 0, 21, 22, 23, 24, 0, 107,
657 108, 109, 2, 27, 28, 0, 29, 3, 30, 4,
658 5, 6, 7, 0, 0, 8, 9, 0, 0, 0,
659 10, 11, 0, 12, 13, 14, 15, 0, 0, 0,
660 0, 16, 17, 18, 19, 20, 0, 21, 22, 23,
661 24, 0, 0, 113, 0, 2, 27, 28, 0, 29,
662 3, 30, 4, 5, 6, 7, 0, 0, 8, 9,
663 0, 0, 0, 10, 11, 0, 12, 13, 14, 15,
664 0, 0, 0, 0, 16, 17, 18, 19, 20, 0,
665 21, 22, 23, 24, 0, 0, 0, 0, 2, 27,
666 28, 0, 29, 3, 30, 4, 5, 6, 7, 0,
667 0, 8, 9, 0, 0, 0, 0, 11, 0, 12,
668 13, 14, 15, 0, 0, 0, 0, 16, 17, 18,
669 19, 20, 0, 21, 22, 23, 24, 0, 0, 0,
670 0, 2, 27, 28, 0, 29, 3, 30, 4, 5,
671 6, 7, 0, 0, 8, 9, 0, 0, 0, 0,
672 0, 0, 12, 13, 14, 15, 0, 0, 0, 0,
673 16, 17, 18, 19, 20, 0, 21, 22, 23, 24,
674 0, 0, 113, 0, 2, 27, 28, 0, 29, 3,
675 30, 4, 5, 6, 7, 0, 0, 8, 9, 0,
676 0, 0, 0, 0, 0, 12, 13, 14, 15, 0,
677 0, 0, 0, 16, 17, 18, 19, 20, 0, 21,
678 22, 23, 24, 0, 0, 0, 0, 0, 27, 28,
679 0, 29, 0, 30, 67, 68, 69, 70, 71, 0,
680 72, 0, 73, 74, 0, 0, 0, 0, 0, 75,
684 static const short yycheck
[] = { 6,
685 7, 35, 10, 0, 57, 0, 9, 170, 128, 172,
686 20, 24, 24, 26, 26, 188, 189, 190, 191, 192,
687 44, 24, 29, 30, 178, 9, 55, 56, 24, 58,
688 44, 45, 61, 24, 44, 14, 49, 49, 211, 14,
689 24, 44, 50, 3, 24, 208, 209, 14, 8, 52,
690 10, 11, 12, 13, 23, 14, 64, 17, 178, 29,
691 44, 20, 216, 97, 43, 44, 45, 27, 52, 44,
692 52, 50, 101, 102, 14, 50, 105, 44, 24, 24,
693 20, 46, 28, 50, 44, 44, 14, 14, 53, 118,
694 50, 50, 52, 122, 123, 24, 216, 46, 106, 272,
695 273, 274, 131, 14, 44, 112, 103, 104, 14, 104,
696 50, 164, 24, 120, 121, 24, 44, 44, 125, 126,
697 283, 284, 50, 50, 24, 24, 26, 156, 157, 158,
698 159, 160, 161, 44, 24, 24, 24, 26, 44, 50,
699 24, 170, 176, 172, 50, 153, 175, 24, 201, 49,
700 24, 4, 149, 150, 149, 150, 163, 43, 165, 212,
701 49, 46, 43, 30, 31, 52, 195, 14, 53, 43,
702 44, 45, 18, 202, 24, 42, 43, 184, 185, 208,
703 209, 30, 31, 217, 181, 182, 14, 182, 30, 31,
704 197, 198, 53, 43, 44, 45, 5, 6, 7, 206,
705 207, 5, 6, 24, 24, 24, 24, 25, 26, 24,
706 239, 24, 24, 24, 32, 33, 34, 35, 36, 248,
707 38, 39, 40, 41, 253, 254, 255, 26, 24, 47,
708 48, 260, 15, 32, 33, 34, 35, 36, 24, 38,
709 39, 40, 41, 51, 51, 252, 275, 53, 47, 48,
710 30, 31, 53, 260, 283, 284, 15, 264, 265, 15,
711 7, 9, 42, 43, 44, 37, 15, 51, 275, 15,
712 51, 7, 279, 280, 1, 4, 3, 37, 285, 24,
713 15, 8, 51, 10, 11, 12, 13, 15, 51, 16,
714 17, 15, 24, 51, 21, 22, 15, 24, 25, 26,
715 27, 51, 15, 15, 0, 32, 33, 34, 35, 36,
716 51, 38, 39, 40, 41, 0, 171, 44, 45, 3,
717 47, 48, 33, 50, 8, 52, 10, 11, 12, 13,
718 51, 176, 16, 17, 271, 195, 233, 21, 10, -1,
719 24, 25, 26, 27, -1, -1, -1, -1, 32, 33,
720 34, 35, 36, -1, 38, 39, 40, 41, -1, 43,
721 44, 45, 3, 47, 48, -1, 50, 8, 52, 10,
722 11, 12, 13, -1, -1, 16, 17, -1, -1, -1,
723 21, 22, -1, 24, 25, 26, 27, -1, -1, -1,
724 -1, 32, 33, 34, 35, 36, -1, 38, 39, 40,
725 41, -1, -1, 44, -1, 3, 47, 48, -1, 50,
726 8, 52, 10, 11, 12, 13, -1, -1, 16, 17,
727 -1, -1, -1, 21, 22, -1, 24, 25, 26, 27,
728 -1, -1, -1, -1, 32, 33, 34, 35, 36, -1,
729 38, 39, 40, 41, -1, -1, -1, -1, 3, 47,
730 48, -1, 50, 8, 52, 10, 11, 12, 13, -1,
731 -1, 16, 17, -1, -1, -1, -1, 22, -1, 24,
732 25, 26, 27, -1, -1, -1, -1, 32, 33, 34,
733 35, 36, -1, 38, 39, 40, 41, -1, -1, -1,
734 -1, 3, 47, 48, -1, 50, 8, 52, 10, 11,
735 12, 13, -1, -1, 16, 17, -1, -1, -1, -1,
736 -1, -1, 24, 25, 26, 27, -1, -1, -1, -1,
737 32, 33, 34, 35, 36, -1, 38, 39, 40, 41,
738 -1, -1, 44, -1, 3, 47, 48, -1, 50, 8,
739 52, 10, 11, 12, 13, -1, -1, 16, 17, -1,
740 -1, -1, -1, -1, -1, 24, 25, 26, 27, -1,
741 -1, -1, -1, 32, 33, 34, 35, 36, -1, 38,
742 39, 40, 41, -1, -1, -1, -1, -1, 47, 48,
743 -1, 50, -1, 52, 32, 33, 34, 35, 36, -1,
744 38, -1, 40, 41, -1, -1, -1, -1, -1, 47,
747 /* -*-C-*- Note some compilers choke on comments on `#line' lines. */
748 #line 3 "/usr/share/bison.simple"
749 /* This file comes from bison-1.28. */
751 /* Skeleton output parser for bison,
752 Copyright (C) 1984, 1989, 1990 Free Software Foundation, Inc.
754 This program is free software; you can redistribute it and/or modify
755 it under the terms of the GNU General Public License as published by
756 the Free Software Foundation; either version 2, or (at your option)
759 This program is distributed in the hope that it will be useful,
760 but WITHOUT ANY WARRANTY; without even the implied warranty of
761 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
762 GNU General Public License for more details.
764 You should have received a copy of the GNU General Public License
765 along with this program; if not, write to the Free Software
766 Foundation, Inc., 59 Temple Place - Suite 330,
767 Boston, MA 02111-1307, USA. */
769 /* As a special exception, when this file is copied by Bison into a
770 Bison output file, you may use that output file without restriction.
771 This special exception was added by the Free Software Foundation
772 in version 1.24 of Bison. */
774 /* This is the parser code that is written into each bison parser
775 when the %semantic_parser declaration is not specified in the grammar.
776 It was written by Richard Stallman by simplifying the hairy parser
777 used when %semantic_parser is specified. */
779 #ifndef YYSTACK_USE_ALLOCA
781 #define YYSTACK_USE_ALLOCA
782 #else /* alloca not defined */
784 #define YYSTACK_USE_ALLOCA
785 #define alloca __builtin_alloca
786 #else /* not GNU C. */
787 #if (!defined (__STDC__) && defined (sparc)) || defined (__sparc__) || defined (__sparc) || defined (__sgi) || (defined (__sun) && defined (__i386))
788 #define YYSTACK_USE_ALLOCA
790 #else /* not sparc */
791 /* We think this test detects Watcom and Microsoft C. */
792 /* This used to test MSDOS, but that is a bad idea
793 since that symbol is in the user namespace. */
794 #if (defined (_MSDOS) || defined (_MSDOS_)) && !defined (__TURBOC__)
795 #if 0 /* No need for malloc.h, which pollutes the namespace;
796 instead, just don't use alloca. */
799 #else /* not MSDOS, or __TURBOC__ */
801 /* I don't know what this was needed for, but it pollutes the namespace.
802 So I turned it off. rms, 2 May 1997. */
803 /* #include <malloc.h> */
805 #define YYSTACK_USE_ALLOCA
806 #else /* not MSDOS, or __TURBOC__, or _AIX */
808 #ifdef __hpux /* haible@ilog.fr says this works for HPUX 9.05 and up,
809 and on HPUX 10. Eventually we can turn this on. */
810 #define YYSTACK_USE_ALLOCA
811 #define alloca __builtin_alloca
814 #endif /* not _AIX */
815 #endif /* not MSDOS, or __TURBOC__ */
816 #endif /* not sparc */
817 #endif /* not GNU C */
818 #endif /* alloca not defined */
819 #endif /* YYSTACK_USE_ALLOCA not defined */
821 #ifdef YYSTACK_USE_ALLOCA
822 #define YYSTACK_ALLOC alloca
824 #define YYSTACK_ALLOC malloc
827 /* Note: there must be only one dollar sign in this file.
828 It is replaced by the list of actions, each action
829 as one case of the switch. */
831 #define yyerrok (yyerrstatus = 0)
832 #define yyclearin (yychar = YYEMPTY)
835 #define YYACCEPT goto yyacceptlab
836 #define YYABORT goto yyabortlab
837 #define YYERROR goto yyerrlab1
838 /* Like YYERROR except do call yyerror.
839 This remains here temporarily to ease the
840 transition to the new meaning of YYERROR, for GCC.
841 Once GCC version 2 has supplanted version 1, this can go. */
842 #define YYFAIL goto yyerrlab
843 #define YYRECOVERING() (!!yyerrstatus)
844 #define YYBACKUP(token, value) \
846 if (yychar == YYEMPTY && yylen == 1) \
847 { yychar = (token), yylval = (value); \
848 yychar1 = YYTRANSLATE (yychar); \
853 { yyerror ("syntax error: cannot back up"); YYERROR; } \
857 #define YYERRCODE 256
860 #define YYLEX yylex()
866 #define YYLEX yylex(&yylval, &yylloc, YYLEX_PARAM)
868 #define YYLEX yylex(&yylval, &yylloc)
870 #else /* not YYLSP_NEEDED */
872 #define YYLEX yylex(&yylval, YYLEX_PARAM)
874 #define YYLEX yylex(&yylval)
876 #endif /* not YYLSP_NEEDED */
879 /* If nonreentrant, generate the variables here */
883 int yychar
; /* the lookahead symbol */
884 YYSTYPE yylval
; /* the semantic value of the */
885 /* lookahead symbol */
888 YYLTYPE yylloc
; /* location data for the lookahead */
892 int yynerrs
; /* number of parse errors so far */
893 #endif /* not YYPURE */
896 int yydebug
; /* nonzero means print parse trace */
897 /* Since this is uninitialized, it does not stop multiple parsers
901 /* YYINITDEPTH indicates the initial size of the parser's stacks */
904 #define YYINITDEPTH 200
907 /* YYMAXDEPTH is the maximum size the stacks can grow to
908 (effective only if the built-in stack extension method is used). */
915 #define YYMAXDEPTH 10000
918 /* Define __yy_memcpy. Note that the size argument
919 should be passed with type unsigned int, because that is what the non-GCC
920 definitions require. With GCC, __builtin_memcpy takes an arg
921 of type size_t, but it can handle unsigned int. */
923 #if __GNUC__ > 1 /* GNU C and GNU C++ define this. */
924 #define __yy_memcpy(TO,FROM,COUNT) __builtin_memcpy(TO,FROM,COUNT)
925 #else /* not GNU C or C++ */
928 /* This is the most reliable way to avoid incompatibilities
929 in available built-in functions on various systems. */
931 __yy_memcpy (to
, from
, count
)
936 register char *f
= from
;
937 register char *t
= to
;
938 register int i
= count
;
944 #else /* __cplusplus */
946 /* This is the most reliable way to avoid incompatibilities
947 in available built-in functions on various systems. */
949 __yy_memcpy (char *to
, char *from
, unsigned int count
)
951 register char *t
= to
;
952 register char *f
= from
;
953 register int i
= count
;
962 #line 217 "/usr/share/bison.simple"
964 /* The user can define YYPARSE_PARAM as the name of an argument to be passed
965 into yyparse. The argument should have type void *.
966 It should actually point to an object.
967 Grammar actions can access the variable by casting it
968 to the proper pointer type. */
972 #define YYPARSE_PARAM_ARG void *YYPARSE_PARAM
973 #define YYPARSE_PARAM_DECL
974 #else /* not __cplusplus */
975 #define YYPARSE_PARAM_ARG YYPARSE_PARAM
976 #define YYPARSE_PARAM_DECL void *YYPARSE_PARAM;
977 #endif /* not __cplusplus */
978 #else /* not YYPARSE_PARAM */
979 #define YYPARSE_PARAM_ARG
980 #define YYPARSE_PARAM_DECL
981 #endif /* not YYPARSE_PARAM */
983 /* Prevent warning if -Wstrict-prototypes. */
986 int yyparse (void *);
993 yyparse(YYPARSE_PARAM_ARG
)
996 register int yystate
;
998 register short *yyssp
;
999 register YYSTYPE
*yyvsp
;
1000 int yyerrstatus
; /* number of tokens to shift before error messages enabled */
1001 int yychar1
= 0; /* lookahead token as an internal (translated) token number */
1003 short yyssa
[YYINITDEPTH
]; /* the state stack */
1004 YYSTYPE yyvsa
[YYINITDEPTH
]; /* the semantic value stack */
1006 short *yyss
= yyssa
; /* refer to the stacks thru separate pointers */
1007 YYSTYPE
*yyvs
= yyvsa
; /* to allow yyoverflow to reallocate them elsewhere */
1010 YYLTYPE yylsa
[YYINITDEPTH
]; /* the location stack */
1011 YYLTYPE
*yyls
= yylsa
;
1014 #define YYPOPSTACK (yyvsp--, yyssp--, yylsp--)
1016 #define YYPOPSTACK (yyvsp--, yyssp--)
1019 int yystacksize
= YYINITDEPTH
;
1020 int yyfree_stacks
= 0;
1031 YYSTYPE yyval
; /* the variable used to return */
1032 /* semantic values from the action */
1039 fprintf(stderr
, "Starting parse\n");
1045 yychar
= YYEMPTY
; /* Cause a token to be read. */
1047 /* Initialize stack pointers.
1048 Waste one element of value and location stack
1049 so that they stay on the same level as the state stack.
1050 The wasted elements are never initialized. */
1058 /* Push a new state, which is found in yystate . */
1059 /* In all cases, when you get here, the value and location stacks
1060 have just been pushed. so pushing a state here evens the stacks. */
1065 if (yyssp
>= yyss
+ yystacksize
- 1)
1067 /* Give user a chance to reallocate the stack */
1068 /* Use copies of these so that the &'s don't force the real ones into memory. */
1069 YYSTYPE
*yyvs1
= yyvs
;
1070 short *yyss1
= yyss
;
1072 YYLTYPE
*yyls1
= yyls
;
1075 /* Get the current used size of the three stacks, in elements. */
1076 int size
= yyssp
- yyss
+ 1;
1079 /* Each stack pointer address is followed by the size of
1080 the data in use in that stack, in bytes. */
1082 /* This used to be a conditional around just the two extra args,
1083 but that might be undefined if yyoverflow is a macro. */
1084 yyoverflow("parser stack overflow",
1085 &yyss1
, size
* sizeof (*yyssp
),
1086 &yyvs1
, size
* sizeof (*yyvsp
),
1087 &yyls1
, size
* sizeof (*yylsp
),
1090 yyoverflow("parser stack overflow",
1091 &yyss1
, size
* sizeof (*yyssp
),
1092 &yyvs1
, size
* sizeof (*yyvsp
),
1096 yyss
= yyss1
; yyvs
= yyvs1
;
1100 #else /* no yyoverflow */
1101 /* Extend the stack our own way. */
1102 if (yystacksize
>= YYMAXDEPTH
)
1104 yyerror("parser stack overflow");
1116 if (yystacksize
> YYMAXDEPTH
)
1117 yystacksize
= YYMAXDEPTH
;
1118 #ifndef YYSTACK_USE_ALLOCA
1121 yyss
= (short *) YYSTACK_ALLOC (yystacksize
* sizeof (*yyssp
));
1122 __yy_memcpy ((char *)yyss
, (char *)yyss1
,
1123 size
* (unsigned int) sizeof (*yyssp
));
1124 yyvs
= (YYSTYPE
*) YYSTACK_ALLOC (yystacksize
* sizeof (*yyvsp
));
1125 __yy_memcpy ((char *)yyvs
, (char *)yyvs1
,
1126 size
* (unsigned int) sizeof (*yyvsp
));
1128 yyls
= (YYLTYPE
*) YYSTACK_ALLOC (yystacksize
* sizeof (*yylsp
));
1129 __yy_memcpy ((char *)yyls
, (char *)yyls1
,
1130 size
* (unsigned int) sizeof (*yylsp
));
1132 #endif /* no yyoverflow */
1134 yyssp
= yyss
+ size
- 1;
1135 yyvsp
= yyvs
+ size
- 1;
1137 yylsp
= yyls
+ size
- 1;
1142 fprintf(stderr
, "Stack size increased to %d\n", yystacksize
);
1145 if (yyssp
>= yyss
+ yystacksize
- 1)
1151 fprintf(stderr
, "Entering state %d\n", yystate
);
1157 /* Do appropriate processing given the current state. */
1158 /* Read a lookahead token if we need one and don't already have one. */
1161 /* First try to decide what to do without reference to lookahead token. */
1163 yyn
= yypact
[yystate
];
1167 /* Not known => get a lookahead token if don't already have one. */
1169 /* yychar is either YYEMPTY or YYEOF
1170 or a valid token in external form. */
1172 if (yychar
== YYEMPTY
)
1176 fprintf(stderr
, "Reading a token: ");
1181 /* Convert token to internal form (in yychar1) for indexing tables with */
1183 if (yychar
<= 0) /* This means end of input. */
1186 yychar
= YYEOF
; /* Don't call YYLEX any more */
1190 fprintf(stderr
, "Now at end of input.\n");
1195 yychar1
= YYTRANSLATE(yychar
);
1200 fprintf (stderr
, "Next token is %d (%s", yychar
, yytname
[yychar1
]);
1201 /* Give the individual parser a way to print the precise meaning
1202 of a token, for further debugging info. */
1204 YYPRINT (stderr
, yychar
, yylval
);
1206 fprintf (stderr
, ")\n");
1212 if (yyn
< 0 || yyn
> YYLAST
|| yycheck
[yyn
] != yychar1
)
1217 /* yyn is what to do for this token type in this state.
1218 Negative => reduce, -yyn is rule number.
1219 Positive => shift, yyn is new state.
1220 New state is final state => don't bother to shift,
1221 just return success.
1222 0, or most negative number => error. */
1237 /* Shift the lookahead token. */
1241 fprintf(stderr
, "Shifting token %d (%s), ", yychar
, yytname
[yychar1
]);
1244 /* Discard the token being shifted unless it is eof. */
1245 if (yychar
!= YYEOF
)
1253 /* count tokens shifted since error; after three, turn off error status. */
1254 if (yyerrstatus
) yyerrstatus
--;
1259 /* Do the default action for the current state. */
1262 yyn
= yydefact
[yystate
];
1266 /* Do a reduction. yyn is the number of a rule to reduce with. */
1270 yyval
= yyvsp
[1-yylen
]; /* implement default value of the action */
1277 fprintf (stderr
, "Reducing via rule %d (line %d), ",
1280 /* Print the symbols being reduced, and their result. */
1281 for (i
= yyprhs
[yyn
]; yyrhs
[i
] > 0; i
++)
1282 fprintf (stderr
, "%s ", yytname
[yyrhs
[i
]]);
1283 fprintf (stderr
, " -> %s\n", yytname
[yyr1
[yyn
]]);
1291 #line 347 "/Users/chet/src/bash/src/parse.y"
1293 /* Case of regular command. Discard the error
1294 safety net,and return the command just parsed. */
1295 global_command
= yyvsp
[-1].command
;
1296 eof_encountered
= 0;
1297 /* discard_parser_constructs (0); */
1302 #line 356 "/Users/chet/src/bash/src/parse.y"
1304 /* Case of regular command, but not a very
1305 interesting one. Return a NULL command. */
1306 global_command
= (COMMAND
*)NULL
;
1311 #line 363 "/Users/chet/src/bash/src/parse.y"
1313 /* Error during parsing. Return NULL command. */
1314 global_command
= (COMMAND
*)NULL
;
1315 eof_encountered
= 0;
1316 /* discard_parser_constructs (1); */
1328 #line 378 "/Users/chet/src/bash/src/parse.y"
1330 /* Case of EOF seen by itself. Do ignoreeof or
1332 global_command
= (COMMAND
*)NULL
;
1333 handle_eof_input_unit ();
1338 #line 388 "/Users/chet/src/bash/src/parse.y"
1339 { yyval
.word_list
= make_word_list (yyvsp
[0].word
, (WORD_LIST
*)NULL
); ;
1342 #line 390 "/Users/chet/src/bash/src/parse.y"
1343 { yyval
.word_list
= make_word_list (yyvsp
[0].word
, yyvsp
[-1].word_list
); ;
1346 #line 394 "/Users/chet/src/bash/src/parse.y"
1348 redir
.filename
= yyvsp
[0].word
;
1349 yyval
.redirect
= make_redirection (1, r_output_direction
, redir
);
1353 #line 399 "/Users/chet/src/bash/src/parse.y"
1355 redir
.filename
= yyvsp
[0].word
;
1356 yyval
.redirect
= make_redirection (0, r_input_direction
, redir
);
1360 #line 404 "/Users/chet/src/bash/src/parse.y"
1362 redir
.filename
= yyvsp
[0].word
;
1363 yyval
.redirect
= make_redirection (yyvsp
[-2].number
, r_output_direction
, redir
);
1367 #line 409 "/Users/chet/src/bash/src/parse.y"
1369 redir
.filename
= yyvsp
[0].word
;
1370 yyval
.redirect
= make_redirection (yyvsp
[-2].number
, r_input_direction
, redir
);
1374 #line 414 "/Users/chet/src/bash/src/parse.y"
1376 redir
.filename
= yyvsp
[0].word
;
1377 yyval
.redirect
= make_redirection (1, r_appending_to
, redir
);
1381 #line 419 "/Users/chet/src/bash/src/parse.y"
1383 redir
.filename
= yyvsp
[0].word
;
1384 yyval
.redirect
= make_redirection (yyvsp
[-2].number
, r_appending_to
, redir
);
1388 #line 424 "/Users/chet/src/bash/src/parse.y"
1390 redir
.filename
= yyvsp
[0].word
;
1391 yyval
.redirect
= make_redirection (0, r_reading_until
, redir
);
1392 redir_stack
[need_here_doc
++] = yyval
.redirect
;
1396 #line 430 "/Users/chet/src/bash/src/parse.y"
1398 redir
.filename
= yyvsp
[0].word
;
1399 yyval
.redirect
= make_redirection (yyvsp
[-2].number
, r_reading_until
, redir
);
1400 redir_stack
[need_here_doc
++] = yyval
.redirect
;
1404 #line 436 "/Users/chet/src/bash/src/parse.y"
1406 redir
.filename
= yyvsp
[0].word
;
1407 yyval
.redirect
= make_redirection (0, r_reading_string
, redir
);
1411 #line 441 "/Users/chet/src/bash/src/parse.y"
1413 redir
.filename
= yyvsp
[0].word
;
1414 yyval
.redirect
= make_redirection (yyvsp
[-2].number
, r_reading_string
, redir
);
1418 #line 446 "/Users/chet/src/bash/src/parse.y"
1420 redir
.dest
= yyvsp
[0].number
;
1421 yyval
.redirect
= make_redirection (0, r_duplicating_input
, redir
);
1425 #line 451 "/Users/chet/src/bash/src/parse.y"
1427 redir
.dest
= yyvsp
[0].number
;
1428 yyval
.redirect
= make_redirection (yyvsp
[-2].number
, r_duplicating_input
, redir
);
1432 #line 456 "/Users/chet/src/bash/src/parse.y"
1434 redir
.dest
= yyvsp
[0].number
;
1435 yyval
.redirect
= make_redirection (1, r_duplicating_output
, redir
);
1439 #line 461 "/Users/chet/src/bash/src/parse.y"
1441 redir
.dest
= yyvsp
[0].number
;
1442 yyval
.redirect
= make_redirection (yyvsp
[-2].number
, r_duplicating_output
, redir
);
1446 #line 466 "/Users/chet/src/bash/src/parse.y"
1448 redir
.filename
= yyvsp
[0].word
;
1449 yyval
.redirect
= make_redirection (0, r_duplicating_input_word
, redir
);
1453 #line 471 "/Users/chet/src/bash/src/parse.y"
1455 redir
.filename
= yyvsp
[0].word
;
1456 yyval
.redirect
= make_redirection (yyvsp
[-2].number
, r_duplicating_input_word
, redir
);
1460 #line 476 "/Users/chet/src/bash/src/parse.y"
1462 redir
.filename
= yyvsp
[0].word
;
1463 yyval
.redirect
= make_redirection (1, r_duplicating_output_word
, redir
);
1467 #line 481 "/Users/chet/src/bash/src/parse.y"
1469 redir
.filename
= yyvsp
[0].word
;
1470 yyval
.redirect
= make_redirection (yyvsp
[-2].number
, r_duplicating_output_word
, redir
);
1474 #line 486 "/Users/chet/src/bash/src/parse.y"
1476 redir
.filename
= yyvsp
[0].word
;
1477 yyval
.redirect
= make_redirection
1478 (0, r_deblank_reading_until
, redir
);
1479 redir_stack
[need_here_doc
++] = yyval
.redirect
;
1483 #line 493 "/Users/chet/src/bash/src/parse.y"
1485 redir
.filename
= yyvsp
[0].word
;
1486 yyval
.redirect
= make_redirection
1487 (yyvsp
[-2].number
, r_deblank_reading_until
, redir
);
1488 redir_stack
[need_here_doc
++] = yyval
.redirect
;
1492 #line 500 "/Users/chet/src/bash/src/parse.y"
1495 yyval
.redirect
= make_redirection (1, r_close_this
, redir
);
1499 #line 505 "/Users/chet/src/bash/src/parse.y"
1502 yyval
.redirect
= make_redirection (yyvsp
[-2].number
, r_close_this
, redir
);
1506 #line 510 "/Users/chet/src/bash/src/parse.y"
1509 yyval
.redirect
= make_redirection (0, r_close_this
, redir
);
1513 #line 515 "/Users/chet/src/bash/src/parse.y"
1516 yyval
.redirect
= make_redirection (yyvsp
[-2].number
, r_close_this
, redir
);
1520 #line 520 "/Users/chet/src/bash/src/parse.y"
1522 redir
.filename
= yyvsp
[0].word
;
1523 yyval
.redirect
= make_redirection (1, r_err_and_out
, redir
);
1527 #line 525 "/Users/chet/src/bash/src/parse.y"
1529 redir
.filename
= yyvsp
[0].word
;
1530 yyval
.redirect
= make_redirection (yyvsp
[-2].number
, r_input_output
, redir
);
1534 #line 530 "/Users/chet/src/bash/src/parse.y"
1536 redir
.filename
= yyvsp
[0].word
;
1537 yyval
.redirect
= make_redirection (0, r_input_output
, redir
);
1541 #line 535 "/Users/chet/src/bash/src/parse.y"
1543 redir
.filename
= yyvsp
[0].word
;
1544 yyval
.redirect
= make_redirection (1, r_output_force
, redir
);
1548 #line 540 "/Users/chet/src/bash/src/parse.y"
1550 redir
.filename
= yyvsp
[0].word
;
1551 yyval
.redirect
= make_redirection (yyvsp
[-2].number
, r_output_force
, redir
);
1555 #line 547 "/Users/chet/src/bash/src/parse.y"
1556 { yyval
.element
.word
= yyvsp
[0].word
; yyval
.element
.redirect
= 0; ;
1559 #line 549 "/Users/chet/src/bash/src/parse.y"
1560 { yyval
.element
.word
= yyvsp
[0].word
; yyval
.element
.redirect
= 0; ;
1563 #line 551 "/Users/chet/src/bash/src/parse.y"
1564 { yyval
.element
.redirect
= yyvsp
[0].redirect
; yyval
.element
.word
= 0; ;
1567 #line 555 "/Users/chet/src/bash/src/parse.y"
1569 yyval
.redirect
= yyvsp
[0].redirect
;
1573 #line 559 "/Users/chet/src/bash/src/parse.y"
1575 register REDIRECT
*t
;
1577 for (t
= yyvsp
[-1].redirect
; t
->next
; t
= t
->next
)
1579 t
->next
= yyvsp
[0].redirect
;
1580 yyval
.redirect
= yyvsp
[-1].redirect
;
1584 #line 570 "/Users/chet/src/bash/src/parse.y"
1585 { yyval
.command
= make_simple_command (yyvsp
[0].element
, (COMMAND
*)NULL
); ;
1588 #line 572 "/Users/chet/src/bash/src/parse.y"
1589 { yyval
.command
= make_simple_command (yyvsp
[0].element
, yyvsp
[-1].command
); ;
1592 #line 576 "/Users/chet/src/bash/src/parse.y"
1593 { yyval
.command
= clean_simple_command (yyvsp
[0].command
); ;
1596 #line 578 "/Users/chet/src/bash/src/parse.y"
1597 { yyval
.command
= yyvsp
[0].command
; ;
1600 #line 580 "/Users/chet/src/bash/src/parse.y"
1604 tc
= yyvsp
[-1].command
;
1607 register REDIRECT
*t
;
1608 for (t
= tc
->redirects
; t
->next
; t
= t
->next
)
1610 t
->next
= yyvsp
[0].redirect
;
1613 tc
->redirects
= yyvsp
[0].redirect
;
1614 yyval
.command
= yyvsp
[-1].command
;
1618 #line 596 "/Users/chet/src/bash/src/parse.y"
1619 { yyval
.command
= yyvsp
[0].command
; ;
1622 #line 600 "/Users/chet/src/bash/src/parse.y"
1623 { yyval
.command
= yyvsp
[0].command
; ;
1626 #line 602 "/Users/chet/src/bash/src/parse.y"
1627 { yyval
.command
= yyvsp
[0].command
; ;
1630 #line 604 "/Users/chet/src/bash/src/parse.y"
1631 { yyval
.command
= make_while_command (yyvsp
[-3].command
, yyvsp
[-1].command
); ;
1634 #line 606 "/Users/chet/src/bash/src/parse.y"
1635 { yyval
.command
= make_until_command (yyvsp
[-3].command
, yyvsp
[-1].command
); ;
1638 #line 608 "/Users/chet/src/bash/src/parse.y"
1639 { yyval
.command
= yyvsp
[0].command
; ;
1642 #line 610 "/Users/chet/src/bash/src/parse.y"
1643 { yyval
.command
= yyvsp
[0].command
; ;
1646 #line 612 "/Users/chet/src/bash/src/parse.y"
1647 { yyval
.command
= yyvsp
[0].command
; ;
1650 #line 614 "/Users/chet/src/bash/src/parse.y"
1651 { yyval
.command
= yyvsp
[0].command
; ;
1654 #line 616 "/Users/chet/src/bash/src/parse.y"
1655 { yyval
.command
= yyvsp
[0].command
; ;
1658 #line 618 "/Users/chet/src/bash/src/parse.y"
1659 { yyval
.command
= yyvsp
[0].command
; ;
1662 #line 620 "/Users/chet/src/bash/src/parse.y"
1663 { yyval
.command
= yyvsp
[0].command
; ;
1666 #line 624 "/Users/chet/src/bash/src/parse.y"
1668 yyval
.command
= make_for_command (yyvsp
[-4].word
, add_string_to_list ("\"$@\"", (WORD_LIST
*)NULL
), yyvsp
[-1].command
, word_lineno
[word_top
]);
1669 if (word_top
> 0) word_top
--;
1673 #line 629 "/Users/chet/src/bash/src/parse.y"
1675 yyval
.command
= make_for_command (yyvsp
[-4].word
, add_string_to_list ("\"$@\"", (WORD_LIST
*)NULL
), yyvsp
[-1].command
, word_lineno
[word_top
]);
1676 if (word_top
> 0) word_top
--;
1680 #line 634 "/Users/chet/src/bash/src/parse.y"
1682 yyval
.command
= make_for_command (yyvsp
[-5].word
, add_string_to_list ("\"$@\"", (WORD_LIST
*)NULL
), yyvsp
[-1].command
, word_lineno
[word_top
]);
1683 if (word_top
> 0) word_top
--;
1687 #line 639 "/Users/chet/src/bash/src/parse.y"
1689 yyval
.command
= make_for_command (yyvsp
[-5].word
, add_string_to_list ("\"$@\"", (WORD_LIST
*)NULL
), yyvsp
[-1].command
, word_lineno
[word_top
]);
1690 if (word_top
> 0) word_top
--;
1694 #line 644 "/Users/chet/src/bash/src/parse.y"
1696 yyval
.command
= make_for_command (yyvsp
[-8].word
, REVERSE_LIST (yyvsp
[-5].word_list
, WORD_LIST
*), yyvsp
[-1].command
, word_lineno
[word_top
]);
1697 if (word_top
> 0) word_top
--;
1701 #line 649 "/Users/chet/src/bash/src/parse.y"
1703 yyval
.command
= make_for_command (yyvsp
[-8].word
, REVERSE_LIST (yyvsp
[-5].word_list
, WORD_LIST
*), yyvsp
[-1].command
, word_lineno
[word_top
]);
1704 if (word_top
> 0) word_top
--;
1708 #line 654 "/Users/chet/src/bash/src/parse.y"
1710 yyval
.command
= make_for_command (yyvsp
[-7].word
, (WORD_LIST
*)NULL
, yyvsp
[-1].command
, word_lineno
[word_top
]);
1711 if (word_top
> 0) word_top
--;
1715 #line 659 "/Users/chet/src/bash/src/parse.y"
1717 yyval
.command
= make_for_command (yyvsp
[-7].word
, (WORD_LIST
*)NULL
, yyvsp
[-1].command
, word_lineno
[word_top
]);
1718 if (word_top
> 0) word_top
--;
1722 #line 666 "/Users/chet/src/bash/src/parse.y"
1724 yyval
.command
= make_arith_for_command (yyvsp
[-5].word_list
, yyvsp
[-1].command
, arith_for_lineno
);
1725 if (word_top
> 0) word_top
--;
1729 #line 671 "/Users/chet/src/bash/src/parse.y"
1731 yyval
.command
= make_arith_for_command (yyvsp
[-5].word_list
, yyvsp
[-1].command
, arith_for_lineno
);
1732 if (word_top
> 0) word_top
--;
1736 #line 676 "/Users/chet/src/bash/src/parse.y"
1738 yyval
.command
= make_arith_for_command (yyvsp
[-3].word_list
, yyvsp
[-1].command
, arith_for_lineno
);
1739 if (word_top
> 0) word_top
--;
1743 #line 681 "/Users/chet/src/bash/src/parse.y"
1745 yyval
.command
= make_arith_for_command (yyvsp
[-3].word_list
, yyvsp
[-1].command
, arith_for_lineno
);
1746 if (word_top
> 0) word_top
--;
1750 #line 688 "/Users/chet/src/bash/src/parse.y"
1752 yyval
.command
= make_select_command (yyvsp
[-4].word
, add_string_to_list ("\"$@\"", (WORD_LIST
*)NULL
), yyvsp
[-1].command
, word_lineno
[word_top
]);
1753 if (word_top
> 0) word_top
--;
1757 #line 693 "/Users/chet/src/bash/src/parse.y"
1759 yyval
.command
= make_select_command (yyvsp
[-4].word
, add_string_to_list ("\"$@\"", (WORD_LIST
*)NULL
), yyvsp
[-1].command
, word_lineno
[word_top
]);
1760 if (word_top
> 0) word_top
--;
1764 #line 698 "/Users/chet/src/bash/src/parse.y"
1766 yyval
.command
= make_select_command (yyvsp
[-5].word
, add_string_to_list ("\"$@\"", (WORD_LIST
*)NULL
), yyvsp
[-1].command
, word_lineno
[word_top
]);
1767 if (word_top
> 0) word_top
--;
1771 #line 703 "/Users/chet/src/bash/src/parse.y"
1773 yyval
.command
= make_select_command (yyvsp
[-5].word
, add_string_to_list ("\"$@\"", (WORD_LIST
*)NULL
), yyvsp
[-1].command
, word_lineno
[word_top
]);
1774 if (word_top
> 0) word_top
--;
1778 #line 708 "/Users/chet/src/bash/src/parse.y"
1780 yyval
.command
= make_select_command (yyvsp
[-8].word
, REVERSE_LIST (yyvsp
[-5].word_list
, WORD_LIST
*), yyvsp
[-1].command
, word_lineno
[word_top
]);
1781 if (word_top
> 0) word_top
--;
1785 #line 713 "/Users/chet/src/bash/src/parse.y"
1787 yyval
.command
= make_select_command (yyvsp
[-8].word
, REVERSE_LIST (yyvsp
[-5].word_list
, WORD_LIST
*), yyvsp
[-1].command
, word_lineno
[word_top
]);
1788 if (word_top
> 0) word_top
--;
1792 #line 720 "/Users/chet/src/bash/src/parse.y"
1794 yyval
.command
= make_case_command (yyvsp
[-4].word
, (PATTERN_LIST
*)NULL
, word_lineno
[word_top
]);
1795 if (word_top
> 0) word_top
--;
1799 #line 725 "/Users/chet/src/bash/src/parse.y"
1801 yyval
.command
= make_case_command (yyvsp
[-5].word
, yyvsp
[-2].pattern
, word_lineno
[word_top
]);
1802 if (word_top
> 0) word_top
--;
1806 #line 730 "/Users/chet/src/bash/src/parse.y"
1808 yyval
.command
= make_case_command (yyvsp
[-4].word
, yyvsp
[-1].pattern
, word_lineno
[word_top
]);
1809 if (word_top
> 0) word_top
--;
1813 #line 737 "/Users/chet/src/bash/src/parse.y"
1814 { yyval
.command
= make_function_def (yyvsp
[-4].word
, yyvsp
[0].command
, function_dstart
, function_bstart
); ;
1817 #line 740 "/Users/chet/src/bash/src/parse.y"
1818 { yyval
.command
= make_function_def (yyvsp
[-4].word
, yyvsp
[0].command
, function_dstart
, function_bstart
); ;
1821 #line 743 "/Users/chet/src/bash/src/parse.y"
1822 { yyval
.command
= make_function_def (yyvsp
[-2].word
, yyvsp
[0].command
, function_dstart
, function_bstart
); ;
1825 #line 748 "/Users/chet/src/bash/src/parse.y"
1826 { yyval
.command
= yyvsp
[0].command
; ;
1829 #line 750 "/Users/chet/src/bash/src/parse.y"
1833 tc
= yyvsp
[-1].command
;
1834 /* According to Posix.2 3.9.5, redirections
1835 specified after the body of a function should
1836 be attached to the function and performed when
1837 the function is executed, not as part of the
1838 function definition command. */
1839 /* XXX - I don't think it matters, but we might
1840 want to change this in the future to avoid
1841 problems differentiating between a function
1842 definition with a redirection and a function
1843 definition containing a single command with a
1844 redirection. The two are semantically equivalent,
1845 though -- the only difference is in how the
1846 command printing code displays the redirections. */
1849 register REDIRECT
*t
;
1850 for (t
= tc
->redirects
; t
->next
; t
= t
->next
)
1852 t
->next
= yyvsp
[0].redirect
;
1855 tc
->redirects
= yyvsp
[0].redirect
;
1856 yyval
.command
= yyvsp
[-1].command
;
1860 #line 781 "/Users/chet/src/bash/src/parse.y"
1862 yyval
.command
= make_subshell_command (yyvsp
[-1].command
);
1863 yyval
.command
->flags
|= CMD_WANT_SUBSHELL
;
1867 #line 788 "/Users/chet/src/bash/src/parse.y"
1868 { yyval
.command
= make_if_command (yyvsp
[-3].command
, yyvsp
[-1].command
, (COMMAND
*)NULL
); ;
1871 #line 790 "/Users/chet/src/bash/src/parse.y"
1872 { yyval
.command
= make_if_command (yyvsp
[-5].command
, yyvsp
[-3].command
, yyvsp
[-1].command
); ;
1875 #line 792 "/Users/chet/src/bash/src/parse.y"
1876 { yyval
.command
= make_if_command (yyvsp
[-4].command
, yyvsp
[-2].command
, yyvsp
[-1].command
); ;
1879 #line 797 "/Users/chet/src/bash/src/parse.y"
1880 { yyval
.command
= make_group_command (yyvsp
[-1].command
); ;
1883 #line 801 "/Users/chet/src/bash/src/parse.y"
1884 { yyval
.command
= make_arith_command (yyvsp
[0].word_list
); ;
1887 #line 805 "/Users/chet/src/bash/src/parse.y"
1888 { yyval
.command
= yyvsp
[-1].command
; ;
1891 #line 809 "/Users/chet/src/bash/src/parse.y"
1892 { yyval
.command
= make_if_command (yyvsp
[-2].command
, yyvsp
[0].command
, (COMMAND
*)NULL
); ;
1895 #line 811 "/Users/chet/src/bash/src/parse.y"
1896 { yyval
.command
= make_if_command (yyvsp
[-4].command
, yyvsp
[-2].command
, yyvsp
[0].command
); ;
1899 #line 813 "/Users/chet/src/bash/src/parse.y"
1900 { yyval
.command
= make_if_command (yyvsp
[-3].command
, yyvsp
[-1].command
, yyvsp
[0].command
); ;
1903 #line 818 "/Users/chet/src/bash/src/parse.y"
1904 { yyvsp
[0].pattern
->next
= yyvsp
[-1].pattern
; yyval
.pattern
= yyvsp
[0].pattern
; ;
1907 #line 822 "/Users/chet/src/bash/src/parse.y"
1908 { yyval
.pattern
= make_pattern_list (yyvsp
[-2].word_list
, yyvsp
[0].command
); ;
1911 #line 824 "/Users/chet/src/bash/src/parse.y"
1912 { yyval
.pattern
= make_pattern_list (yyvsp
[-2].word_list
, (COMMAND
*)NULL
); ;
1915 #line 826 "/Users/chet/src/bash/src/parse.y"
1916 { yyval
.pattern
= make_pattern_list (yyvsp
[-2].word_list
, yyvsp
[0].command
); ;
1919 #line 828 "/Users/chet/src/bash/src/parse.y"
1920 { yyval
.pattern
= make_pattern_list (yyvsp
[-2].word_list
, (COMMAND
*)NULL
); ;
1923 #line 833 "/Users/chet/src/bash/src/parse.y"
1924 { yyvsp
[-1].pattern
->next
= yyvsp
[-2].pattern
; yyval
.pattern
= yyvsp
[-1].pattern
; ;
1927 #line 837 "/Users/chet/src/bash/src/parse.y"
1928 { yyval
.word_list
= make_word_list (yyvsp
[0].word
, (WORD_LIST
*)NULL
); ;
1931 #line 839 "/Users/chet/src/bash/src/parse.y"
1932 { yyval
.word_list
= make_word_list (yyvsp
[0].word
, yyvsp
[-2].word_list
); ;
1935 #line 848 "/Users/chet/src/bash/src/parse.y"
1937 yyval
.command
= yyvsp
[0].command
;
1939 gather_here_documents ();
1943 #line 857 "/Users/chet/src/bash/src/parse.y"
1945 yyval
.command
= yyvsp
[0].command
;
1949 #line 864 "/Users/chet/src/bash/src/parse.y"
1951 if (yyvsp
[-2].command
->type
== cm_connection
)
1952 yyval
.command
= connect_async_list (yyvsp
[-2].command
, (COMMAND
*)NULL
, '&');
1954 yyval
.command
= command_connect (yyvsp
[-2].command
, (COMMAND
*)NULL
, '&');
1958 #line 875 "/Users/chet/src/bash/src/parse.y"
1959 { yyval
.command
= command_connect (yyvsp
[-3].command
, yyvsp
[0].command
, AND_AND
); ;
1962 #line 877 "/Users/chet/src/bash/src/parse.y"
1963 { yyval
.command
= command_connect (yyvsp
[-3].command
, yyvsp
[0].command
, OR_OR
); ;
1966 #line 879 "/Users/chet/src/bash/src/parse.y"
1968 if (yyvsp
[-3].command
->type
== cm_connection
)
1969 yyval
.command
= connect_async_list (yyvsp
[-3].command
, yyvsp
[0].command
, '&');
1971 yyval
.command
= command_connect (yyvsp
[-3].command
, yyvsp
[0].command
, '&');
1975 #line 886 "/Users/chet/src/bash/src/parse.y"
1976 { yyval
.command
= command_connect (yyvsp
[-3].command
, yyvsp
[0].command
, ';'); ;
1979 #line 888 "/Users/chet/src/bash/src/parse.y"
1980 { yyval
.command
= command_connect (yyvsp
[-3].command
, yyvsp
[0].command
, ';'); ;
1983 #line 890 "/Users/chet/src/bash/src/parse.y"
1984 { yyval
.command
= yyvsp
[0].command
; ;
1987 #line 898 "/Users/chet/src/bash/src/parse.y"
1988 { yyval
.number
= '\n'; ;
1991 #line 900 "/Users/chet/src/bash/src/parse.y"
1992 { yyval
.number
= ';'; ;
1995 #line 902 "/Users/chet/src/bash/src/parse.y"
1996 { yyval
.number
= yacc_EOF
; ;
1999 #line 916 "/Users/chet/src/bash/src/parse.y"
2001 yyval
.command
= yyvsp
[0].command
;
2003 gather_here_documents ();
2007 #line 922 "/Users/chet/src/bash/src/parse.y"
2009 if (yyvsp
[-1].command
->type
== cm_connection
)
2010 yyval
.command
= connect_async_list (yyvsp
[-1].command
, (COMMAND
*)NULL
, '&');
2012 yyval
.command
= command_connect (yyvsp
[-1].command
, (COMMAND
*)NULL
, '&');
2014 gather_here_documents ();
2018 #line 931 "/Users/chet/src/bash/src/parse.y"
2020 yyval
.command
= yyvsp
[-1].command
;
2022 gather_here_documents ();
2026 #line 939 "/Users/chet/src/bash/src/parse.y"
2027 { yyval
.command
= command_connect (yyvsp
[-3].command
, yyvsp
[0].command
, AND_AND
); ;
2030 #line 941 "/Users/chet/src/bash/src/parse.y"
2031 { yyval
.command
= command_connect (yyvsp
[-3].command
, yyvsp
[0].command
, OR_OR
); ;
2034 #line 943 "/Users/chet/src/bash/src/parse.y"
2036 if (yyvsp
[-2].command
->type
== cm_connection
)
2037 yyval
.command
= connect_async_list (yyvsp
[-2].command
, yyvsp
[0].command
, '&');
2039 yyval
.command
= command_connect (yyvsp
[-2].command
, yyvsp
[0].command
, '&');
2043 #line 950 "/Users/chet/src/bash/src/parse.y"
2044 { yyval
.command
= command_connect (yyvsp
[-2].command
, yyvsp
[0].command
, ';'); ;
2047 #line 953 "/Users/chet/src/bash/src/parse.y"
2048 { yyval
.command
= yyvsp
[0].command
; ;
2051 #line 957 "/Users/chet/src/bash/src/parse.y"
2052 { yyval
.command
= yyvsp
[0].command
; ;
2055 #line 959 "/Users/chet/src/bash/src/parse.y"
2057 if (yyvsp
[0].command
)
2058 yyvsp
[0].command
->flags
|= CMD_INVERT_RETURN
;
2059 yyval
.command
= yyvsp
[0].command
;
2063 #line 965 "/Users/chet/src/bash/src/parse.y"
2065 if (yyvsp
[0].command
)
2066 yyvsp
[0].command
->flags
|= yyvsp
[-1].number
;
2067 yyval
.command
= yyvsp
[0].command
;
2071 #line 971 "/Users/chet/src/bash/src/parse.y"
2073 if (yyvsp
[0].command
)
2074 yyvsp
[0].command
->flags
|= yyvsp
[-2].number
|CMD_INVERT_RETURN
;
2075 yyval
.command
= yyvsp
[0].command
;
2079 #line 977 "/Users/chet/src/bash/src/parse.y"
2081 if (yyvsp
[0].command
)
2082 yyvsp
[0].command
->flags
|= yyvsp
[-1].number
|CMD_INVERT_RETURN
;
2083 yyval
.command
= yyvsp
[0].command
;
2087 #line 983 "/Users/chet/src/bash/src/parse.y"
2091 /* Boy, this is unclean. `time' by itself can
2092 time a null command. We cheat and push a
2093 newline back if the list_terminator was a newline
2094 to avoid the double-newline problem (one to
2095 terminate this, one to terminate the command) */
2098 yyval
.command
= make_simple_command (x
, (COMMAND
*)NULL
);
2099 yyval
.command
->flags
|= yyvsp
[-1].number
;
2100 /* XXX - let's cheat and push a newline back */
2101 if (yyvsp
[0].number
== '\n')
2102 token_to_read
= '\n';
2106 #line 1004 "/Users/chet/src/bash/src/parse.y"
2107 { yyval
.command
= command_connect (yyvsp
[-3].command
, yyvsp
[0].command
, '|'); ;
2110 #line 1006 "/Users/chet/src/bash/src/parse.y"
2111 { yyval
.command
= yyvsp
[0].command
; ;
2114 #line 1010 "/Users/chet/src/bash/src/parse.y"
2115 { yyval
.number
= CMD_TIME_PIPELINE
; ;
2118 #line 1012 "/Users/chet/src/bash/src/parse.y"
2119 { yyval
.number
= CMD_TIME_PIPELINE
|CMD_TIME_POSIX
; ;
2122 /* the action file gets copied in in place of this dollarsign */
2123 #line 543 "/usr/share/bison.simple"
2134 short *ssp1
= yyss
- 1;
2135 fprintf (stderr
, "state stack now");
2136 while (ssp1
!= yyssp
)
2137 fprintf (stderr
, " %d", *++ssp1
);
2138 fprintf (stderr
, "\n");
2148 yylsp
->first_line
= yylloc
.first_line
;
2149 yylsp
->first_column
= yylloc
.first_column
;
2150 yylsp
->last_line
= (yylsp
-1)->last_line
;
2151 yylsp
->last_column
= (yylsp
-1)->last_column
;
2156 yylsp
->last_line
= (yylsp
+yylen
-1)->last_line
;
2157 yylsp
->last_column
= (yylsp
+yylen
-1)->last_column
;
2161 /* Now "shift" the result of the reduction.
2162 Determine what state that goes to,
2163 based on the state we popped back to
2164 and the rule number reduced by. */
2168 yystate
= yypgoto
[yyn
- YYNTBASE
] + *yyssp
;
2169 if (yystate
>= 0 && yystate
<= YYLAST
&& yycheck
[yystate
] == *yyssp
)
2170 yystate
= yytable
[yystate
];
2172 yystate
= yydefgoto
[yyn
- YYNTBASE
];
2176 yyerrlab
: /* here on detecting error */
2179 /* If not already recovering from an error, report this error. */
2183 #ifdef YYERROR_VERBOSE
2184 yyn
= yypact
[yystate
];
2186 if (yyn
> YYFLAG
&& yyn
< YYLAST
)
2193 /* Start X at -yyn if nec to avoid negative indexes in yycheck. */
2194 for (x
= (yyn
< 0 ? -yyn
: 0);
2195 x
< (sizeof(yytname
) / sizeof(char *)); x
++)
2196 if (yycheck
[x
+ yyn
] == x
)
2197 size
+= strlen(yytname
[x
]) + 15, count
++;
2198 msg
= (char *) malloc(size
+ 15);
2201 strcpy(msg
, "parse error");
2206 for (x
= (yyn
< 0 ? -yyn
: 0);
2207 x
< (sizeof(yytname
) / sizeof(char *)); x
++)
2208 if (yycheck
[x
+ yyn
] == x
)
2210 strcat(msg
, count
== 0 ? ", expecting `" : " or `");
2211 strcat(msg
, yytname
[x
]);
2220 yyerror ("parse error; also virtual memory exceeded");
2223 #endif /* YYERROR_VERBOSE */
2224 yyerror("parse error");
2228 yyerrlab1
: /* here on error raised explicitly by an action */
2230 if (yyerrstatus
== 3)
2232 /* if just tried and failed to reuse lookahead token after an error, discard it. */
2234 /* return failure if at end of input */
2235 if (yychar
== YYEOF
)
2240 fprintf(stderr
, "Discarding token %d (%s).\n", yychar
, yytname
[yychar1
]);
2246 /* Else will try to reuse lookahead token
2247 after shifting the error token. */
2249 yyerrstatus
= 3; /* Each real token shifted decrements this */
2253 yyerrdefault
: /* current state does not do anything special for the error token. */
2256 /* This is wrong; only states that explicitly want error tokens
2257 should shift them. */
2258 yyn
= yydefact
[yystate
]; /* If its default is to accept any token, ok. Otherwise pop it.*/
2259 if (yyn
) goto yydefault
;
2262 yyerrpop
: /* pop the current state because it cannot handle the error token */
2264 if (yyssp
== yyss
) YYABORT
;
2274 short *ssp1
= yyss
- 1;
2275 fprintf (stderr
, "Error: state stack now");
2276 while (ssp1
!= yyssp
)
2277 fprintf (stderr
, " %d", *++ssp1
);
2278 fprintf (stderr
, "\n");
2284 yyn
= yypact
[yystate
];
2289 if (yyn
< 0 || yyn
> YYLAST
|| yycheck
[yyn
] != YYTERROR
)
2308 fprintf(stderr
, "Shifting error token, ");
2320 /* YYACCEPT comes here. */
2332 /* YYABORT comes here. */
2343 #line 1014 "/Users/chet/src/bash/src/parse.y"
2346 /* Possible states for the parser that require it to do special things. */
2347 #define PST_CASEPAT 0x0001 /* in a case pattern list */
2348 #define PST_ALEXPNEXT 0x0002 /* expand next word for aliases */
2349 #define PST_ALLOWOPNBRC 0x0004 /* allow open brace for function def */
2350 #define PST_NEEDCLOSBRC 0x0008 /* need close brace */
2351 #define PST_DBLPAREN 0x0010 /* double-paren parsing */
2352 #define PST_SUBSHELL 0x0020 /* ( ... ) subshell */
2353 #define PST_CMDSUBST 0x0040 /* $( ... ) command substitution */
2354 #define PST_CASESTMT 0x0080 /* parsing a case statement */
2355 #define PST_CONDCMD 0x0100 /* parsing a [[...]] command */
2356 #define PST_CONDEXPR 0x0200 /* parsing the guts of [[...]] */
2357 #define PST_ARITHFOR 0x0400 /* parsing an arithmetic for command */
2358 #define PST_ALEXPAND 0x0800 /* OK to expand aliases - unused */
2359 #define PST_CMDTOKEN 0x1000 /* command token OK - unused */
2360 #define PST_COMPASSIGN 0x2000 /* parsing x=(...) compound assignment */
2361 #define PST_ASSIGNOK 0x4000 /* assignment statement ok in this context */
2363 /* Initial size to allocate for tokens, and the
2364 amount to grow them by. */
2365 #define TOKEN_DEFAULT_INITIAL_SIZE 496
2366 #define TOKEN_DEFAULT_GROW_SIZE 512
2368 /* Should we call prompt_again? */
2369 #define SHOULD_PROMPT() \
2370 (interactive && (bash_input.type == st_stdin || bash_input.type == st_stream))
2373 # define expanding_alias() (pushed_string_list && pushed_string_list->expander)
2375 # define expanding_alias() 0
2378 /* The token currently being read. */
2379 static int current_token
;
2381 /* The last read token, or NULL. read_token () uses this for context
2383 static int last_read_token
;
2385 /* The token read prior to last_read_token. */
2386 static int token_before_that
;
2388 /* The token read prior to token_before_that. */
2389 static int two_tokens_ago
;
2391 /* The current parser state. */
2392 static int parser_state
;
2394 /* Global var is non-zero when end of file has been reached. */
2395 int EOF_Reached
= 0;
2408 /* yy_getc () returns the next available character from input or EOF.
2409 yy_ungetc (c) makes `c' the next character to read.
2410 init_yy_io (get, unget, type, location) makes the function GET the
2411 installed function for getting the next character, makes UNGET the
2412 installed function for un-getting a character, sets the type of stream
2413 (either string or file) from TYPE, and makes LOCATION point to where
2414 the input is coming from. */
2416 /* Unconditionally returns end-of-file. */
2423 /* Variable containing the current get and unget functions.
2424 See ./input.h for a clearer description. */
2425 BASH_INPUT bash_input
;
2427 /* Set all of the fields in BASH_INPUT to NULL. Free bash_input.name if it
2428 is non-null, avoiding a memory leak. */
2430 initialize_bash_input ()
2432 bash_input
.type
= st_none
;
2433 FREE (bash_input
.name
);
2434 bash_input
.name
= (char *)NULL
;
2435 bash_input
.location
.file
= (FILE *)NULL
;
2436 bash_input
.location
.string
= (char *)NULL
;
2437 bash_input
.getter
= (sh_cget_func_t
*)NULL
;
2438 bash_input
.ungetter
= (sh_cunget_func_t
*)NULL
;
2441 /* Set the contents of the current bash input stream from
2442 GET, UNGET, TYPE, NAME, and LOCATION. */
2444 init_yy_io (get
, unget
, type
, name
, location
)
2445 sh_cget_func_t
*get
;
2446 sh_cunget_func_t
*unget
;
2447 enum stream_type type
;
2449 INPUT_STREAM location
;
2451 bash_input
.type
= type
;
2452 FREE (bash_input
.name
);
2453 bash_input
.name
= name
? savestring (name
) : (char *)NULL
;
2457 memcpy((char *)&bash_input
.location
.string
, (char *)&location
.string
, sizeof(location
));
2459 bash_input
.location
= location
;
2461 bash_input
.getter
= get
;
2462 bash_input
.ungetter
= unget
;
2468 return (bash_input
.name
? bash_input
.name
: "stdin");
2471 /* Call this to get the next character of input. */
2475 return (*(bash_input
.getter
)) ();
2478 /* Call this to unget C. That is, to make C the next character
2484 return (*(bash_input
.ungetter
)) (c
);
2487 #if defined (BUFFERED_INPUT)
2488 #ifdef INCLUDE_UNUSED
2490 input_file_descriptor ()
2492 switch (bash_input
.type
)
2495 return (fileno (bash_input
.location
.file
));
2497 return (bash_input
.location
.buffered_fd
);
2500 return (fileno (stdin
));
2504 #endif /* BUFFERED_INPUT */
2506 /* **************************************************************** */
2508 /* Let input be read from readline (). */
2510 /* **************************************************************** */
2512 #if defined (READLINE)
2513 char *current_readline_prompt
= (char *)NULL
;
2514 char *current_readline_line
= (char *)NULL
;
2515 int current_readline_line_index
= 0;
2520 SigHandler
*old_sigint
;
2524 if (!current_readline_line
)
2526 if (!bash_readline_initialized
)
2527 initialize_readline ();
2529 #if defined (JOB_CONTROL)
2531 give_terminal_to (shell_pgrp
, 0);
2532 #endif /* JOB_CONTROL */
2534 old_sigint
= (SigHandler
*)NULL
;
2535 if (signal_is_ignored (SIGINT
) == 0)
2537 old_sigint
= (SigHandler
*)set_signal_handler (SIGINT
, sigint_sighandler
);
2538 interrupt_immediately
++;
2540 terminate_immediately
= 1;
2542 current_readline_line
= readline (current_readline_prompt
?
2543 current_readline_prompt
: "");
2545 terminate_immediately
= 0;
2546 if (signal_is_ignored (SIGINT
) == 0 && old_sigint
)
2548 interrupt_immediately
--;
2549 set_signal_handler (SIGINT
, old_sigint
);
2553 /* Reset the prompt to the decoded value of prompt_string_pointer. */
2554 reset_readline_prompt ();
2557 if (current_readline_line
== 0)
2560 current_readline_line_index
= 0;
2561 line_len
= strlen (current_readline_line
);
2563 current_readline_line
= (char *)xrealloc (current_readline_line
, 2 + line_len
);
2564 current_readline_line
[line_len
++] = '\n';
2565 current_readline_line
[line_len
] = '\0';
2568 if (current_readline_line
[current_readline_line_index
] == 0)
2570 free (current_readline_line
);
2571 current_readline_line
= (char *)NULL
;
2572 return (yy_readline_get ());
2576 c
= current_readline_line
[current_readline_line_index
++];
2582 yy_readline_unget (c
)
2585 if (current_readline_line_index
&& current_readline_line
)
2586 current_readline_line
[--current_readline_line_index
] = c
;
2591 with_input_from_stdin ()
2593 INPUT_STREAM location
;
2595 if (bash_input
.type
!= st_stdin
&& stream_on_stack (st_stdin
) == 0)
2597 location
.string
= current_readline_line
;
2598 init_yy_io (yy_readline_get
, yy_readline_unget
,
2599 st_stdin
, "readline stdin", location
);
2603 #else /* !READLINE */
2606 with_input_from_stdin ()
2608 with_input_from_stream (stdin
, "stdin");
2610 #endif /* !READLINE */
2612 /* **************************************************************** */
2614 /* Let input come from STRING. STRING is zero terminated. */
2616 /* **************************************************************** */
2621 register char *string
;
2622 register unsigned char c
;
2624 string
= bash_input
.location
.string
;
2626 /* If the string doesn't exist, or is empty, EOF found. */
2627 if (string
&& *string
)
2630 bash_input
.location
.string
= string
;
2641 *(--bash_input
.location
.string
) = c
;
2646 with_input_from_string (string
, name
)
2650 INPUT_STREAM location
;
2652 location
.string
= string
;
2653 init_yy_io (yy_string_get
, yy_string_unget
, st_string
, name
, location
);
2656 /* **************************************************************** */
2658 /* Let input come from STREAM. */
2660 /* **************************************************************** */
2662 /* These two functions used to test the value of the HAVE_RESTARTABLE_SYSCALLS
2663 define, and just use getc/ungetc if it was defined, but since bash
2664 installs its signal handlers without the SA_RESTART flag, some signals
2665 (like SIGCHLD, SIGWINCH, etc.) received during a read(2) will not cause
2666 the read to be restarted. We need to restart it ourselves. */
2674 if (bash_input
.location
.file
)
2678 interrupt_immediately
++;
2679 terminate_immediately
++;
2681 result
= getc_with_restart (bash_input
.location
.file
);
2684 interrupt_immediately
--;
2685 terminate_immediately
--;
2695 return (ungetc_with_restart (c
, bash_input
.location
.file
));
2699 with_input_from_stream (stream
, name
)
2703 INPUT_STREAM location
;
2705 location
.file
= stream
;
2706 init_yy_io (yy_stream_get
, yy_stream_unget
, st_stream
, name
, location
);
2709 typedef struct stream_saver
{
2710 struct stream_saver
*next
;
2711 BASH_INPUT bash_input
;
2713 #if defined (BUFFERED_INPUT)
2714 BUFFERED_STREAM
*bstream
;
2715 #endif /* BUFFERED_INPUT */
2718 /* The globally known line number. */
2719 int line_number
= 0;
2721 #if defined (COND_COMMAND)
2722 static int cond_lineno
;
2723 static int cond_token
;
2726 STREAM_SAVER
*stream_list
= (STREAM_SAVER
*)NULL
;
2729 push_stream (reset_lineno
)
2732 STREAM_SAVER
*saver
= (STREAM_SAVER
*)xmalloc (sizeof (STREAM_SAVER
));
2734 xbcopy ((char *)&bash_input
, (char *)&(saver
->bash_input
), sizeof (BASH_INPUT
));
2736 #if defined (BUFFERED_INPUT)
2737 saver
->bstream
= (BUFFERED_STREAM
*)NULL
;
2738 /* If we have a buffered stream, clear out buffers[fd]. */
2739 if (bash_input
.type
== st_bstream
&& bash_input
.location
.buffered_fd
>= 0)
2740 saver
->bstream
= set_buffered_stream (bash_input
.location
.buffered_fd
,
2741 (BUFFERED_STREAM
*)NULL
);
2742 #endif /* BUFFERED_INPUT */
2744 saver
->line
= line_number
;
2745 bash_input
.name
= (char *)NULL
;
2746 saver
->next
= stream_list
;
2747 stream_list
= saver
;
2760 STREAM_SAVER
*saver
= stream_list
;
2763 stream_list
= stream_list
->next
;
2765 init_yy_io (saver
->bash_input
.getter
,
2766 saver
->bash_input
.ungetter
,
2767 saver
->bash_input
.type
,
2768 saver
->bash_input
.name
,
2769 saver
->bash_input
.location
);
2771 #if defined (BUFFERED_INPUT)
2772 /* If we have a buffered stream, restore buffers[fd]. */
2773 /* If the input file descriptor was changed while this was on the
2774 save stack, update the buffered fd to the new file descriptor and
2775 re-establish the buffer <-> bash_input fd correspondence. */
2776 if (bash_input
.type
== st_bstream
&& bash_input
.location
.buffered_fd
>= 0)
2778 if (bash_input_fd_changed
)
2780 bash_input_fd_changed
= 0;
2781 if (default_buffered_input
>= 0)
2783 bash_input
.location
.buffered_fd
= default_buffered_input
;
2784 saver
->bstream
->b_fd
= default_buffered_input
;
2785 SET_CLOSE_ON_EXEC (default_buffered_input
);
2788 /* XXX could free buffered stream returned as result here. */
2789 set_buffered_stream (bash_input
.location
.buffered_fd
, saver
->bstream
);
2791 #endif /* BUFFERED_INPUT */
2793 line_number
= saver
->line
;
2795 FREE (saver
->bash_input
.name
);
2800 /* Return 1 if a stream of type TYPE is saved on the stack. */
2802 stream_on_stack (type
)
2803 enum stream_type type
;
2805 register STREAM_SAVER
*s
;
2807 for (s
= stream_list
; s
; s
= s
->next
)
2808 if (s
->bash_input
.type
== type
)
2813 /* Save the current token state and return it in a malloced array. */
2819 ret
= (int *)xmalloc (3 * sizeof (int));
2820 ret
[0] = last_read_token
;
2821 ret
[1] = token_before_that
;
2822 ret
[2] = two_tokens_ago
;
2827 restore_token_state (ts
)
2832 last_read_token
= ts
[0];
2833 token_before_that
= ts
[1];
2834 two_tokens_ago
= ts
[2];
2838 * This is used to inhibit alias expansion and reserved word recognition
2839 * inside case statement pattern lists. A `case statement pattern list' is:
2841 * everything between the `in' in a `case word in' and the next ')'
2843 * everything between a `;;' and the next `)' or `esac'
2846 #if defined (ALIAS) || defined (DPAREN_ARITHMETIC)
2848 #define END_OF_ALIAS 0
2851 * Pseudo-global variables used in implementing token-wise alias expansion.
2855 * Pushing and popping strings. This works together with shell_getc to
2856 * implement alias expansion on a per-token basis.
2859 typedef struct string_saver
{
2860 struct string_saver
*next
;
2861 int expand_alias
; /* Value to set expand_alias to when string is popped. */
2864 alias_t
*expander
; /* alias that caused this line to be pushed. */
2866 int saved_line_size
, saved_line_index
, saved_line_terminator
;
2869 STRING_SAVER
*pushed_string_list
= (STRING_SAVER
*)NULL
;
2872 * Push the current shell_input_line onto a stack of such lines and make S
2873 * the current input. Used when expanding aliases. EXPAND is used to set
2874 * the value of expand_next_token when the string is popped, so that the
2875 * word after the alias in the original line is handled correctly when the
2876 * alias expands to multiple words. TOKEN is the token that was expanded
2877 * into S; it is saved and used to prevent infinite recursive expansion.
2880 push_string (s
, expand
, ap
)
2885 STRING_SAVER
*temp
= (STRING_SAVER
*)xmalloc (sizeof (STRING_SAVER
));
2887 temp
->expand_alias
= expand
;
2888 temp
->saved_line
= shell_input_line
;
2889 temp
->saved_line_size
= shell_input_line_size
;
2890 temp
->saved_line_index
= shell_input_line_index
;
2891 temp
->saved_line_terminator
= shell_input_line_terminator
;
2893 temp
->expander
= ap
;
2895 temp
->next
= pushed_string_list
;
2896 pushed_string_list
= temp
;
2900 ap
->flags
|= AL_BEINGEXPANDED
;
2903 shell_input_line
= s
;
2904 shell_input_line_size
= strlen (s
);
2905 shell_input_line_index
= 0;
2906 shell_input_line_terminator
= '\0';
2908 parser_state
&= ~PST_ALEXPNEXT
; /* XXX */
2911 set_line_mbstate ();
2915 * Make the top of the pushed_string stack be the current shell input.
2916 * Only called when there is something on the stack. Called from shell_getc
2917 * when it thinks it has consumed the string generated by an alias expansion
2918 * and needs to return to the original input line.
2925 FREE (shell_input_line
);
2926 shell_input_line
= pushed_string_list
->saved_line
;
2927 shell_input_line_index
= pushed_string_list
->saved_line_index
;
2928 shell_input_line_size
= pushed_string_list
->saved_line_size
;
2929 shell_input_line_terminator
= pushed_string_list
->saved_line_terminator
;
2931 if (pushed_string_list
->expand_alias
)
2932 parser_state
|= PST_ALEXPNEXT
;
2934 parser_state
&= ~PST_ALEXPNEXT
;
2936 t
= pushed_string_list
;
2937 pushed_string_list
= pushed_string_list
->next
;
2941 t
->expander
->flags
&= ~AL_BEINGEXPANDED
;
2946 set_line_mbstate ();
2952 register STRING_SAVER
*t
, *t1
;
2954 for (t
= pushed_string_list
; t
; )
2957 FREE (t
->saved_line
);
2960 t
->expander
->flags
&= ~AL_BEINGEXPANDED
;
2965 pushed_string_list
= (STRING_SAVER
*)NULL
;
2968 #endif /* ALIAS || DPAREN_ARITHMETIC */
2971 free_pushed_string_input ()
2973 #if defined (ALIAS) || defined (DPAREN_ARITHMETIC)
2974 free_string_list ();
2978 /* Return a line of text, taken from wherever yylex () reads input.
2979 If there is no more input, then we return NULL. If REMOVE_QUOTED_NEWLINE
2980 is non-zero, we remove unquoted \<newline> pairs. This is used by
2981 read_secondary_line to read here documents. */
2983 read_a_line (remove_quoted_newline
)
2984 int remove_quoted_newline
;
2986 static char *line_buffer
= (char *)NULL
;
2987 static int buffer_size
= 0;
2988 int indx
= 0, c
, peekc
, pass_next
;
2990 #if defined (READLINE)
2991 if (no_line_editing
&& SHOULD_PROMPT ())
2993 if (SHOULD_PROMPT ())
3000 /* Allow immediate exit if interrupted during input. */
3005 /* Ignore null bytes in input. */
3009 internal_warning ("read_a_line: ignored null byte in input");
3014 /* If there is no more input, then we return NULL. */
3017 if (interactive
&& bash_input
.type
== st_stream
)
3020 return ((char *)NULL
);
3024 /* `+2' in case the final character in the buffer is a newline. */
3025 RESIZE_MALLOCED_BUFFER (line_buffer
, indx
, 2, buffer_size
, 128);
3027 /* IF REMOVE_QUOTED_NEWLINES is non-zero, we are reading a
3028 here document with an unquoted delimiter. In this case,
3029 the line will be expanded as if it were in double quotes.
3030 We allow a backslash to escape the next character, but we
3031 need to treat the backslash specially only if a backslash
3032 quoting a backslash-newline pair appears in the line. */
3035 line_buffer
[indx
++] = c
;
3038 else if (c
== '\\' && remove_quoted_newline
)
3044 continue; /* Make the unquoted \<newline> pair disappear. */
3050 line_buffer
[indx
++] = c
; /* Preserve the backslash. */
3054 line_buffer
[indx
++] = c
;
3058 line_buffer
[indx
] = '\0';
3059 return (line_buffer
);
3064 /* Return a line as in read_a_line (), but insure that the prompt is
3065 the secondary prompt. This is used to read the lines of a here
3066 document. REMOVE_QUOTED_NEWLINE is non-zero if we should remove
3067 newlines quoted with backslashes while reading the line. It is
3068 non-zero unless the delimiter of the here document was quoted. */
3070 read_secondary_line (remove_quoted_newline
)
3071 int remove_quoted_newline
;
3073 prompt_string_pointer
= &ps2_prompt
;
3074 if (SHOULD_PROMPT())
3076 return (read_a_line (remove_quoted_newline
));
3079 /* **************************************************************** */
3083 /* **************************************************************** */
3085 /* Reserved words. These are only recognized as the first word of a
3087 STRING_INT_ALIST word_token_alist
[] = {
3096 #if defined (SELECT_COMMAND)
3097 { "select", SELECT
},
3104 { "function", FUNCTION
},
3105 #if defined (COMMAND_TIMING)
3111 #if defined (COND_COMMAND)
3112 { "[[", COND_START
},
3118 /* other tokens that can be returned by read_token() */
3119 STRING_INT_ALIST other_token_alist
[] = {
3120 /* Multiple-character tokens with special values */
3124 { ">>", GREATER_GREATER
},
3125 { "<<", LESS_LESS
},
3127 { ">&", GREATER_AND
},
3128 { ";;", SEMI_SEMI
},
3129 { "<<-", LESS_LESS_MINUS
},
3130 { "<<<", LESS_LESS_LESS
},
3131 { "&>", AND_GREATER
},
3132 { "<>", LESS_GREATER
},
3133 { ">|", GREATER_BAR
},
3134 { "EOF", yacc_EOF
},
3135 /* Tokens whose value is the character itself */
3146 { "newline", '\n' },
3150 /* others not listed here:
3151 WORD look at yylval.word
3152 ASSIGNMENT_WORD look at yylval.word
3153 NUMBER look at yylval.number
3154 ARITH_CMD look at yylval.word_list
3155 ARITH_FOR_EXPRS look at yylval.word_list
3156 COND_CMD look at yylval.command
3159 /* These are used by read_token_word, but appear up here so that shell_getc
3160 can use them to decide when to add otherwise blank lines to the history. */
3162 /* The primary delimiter stack. */
3163 struct dstack dstack
= { (char *)NULL
, 0, 0 };
3165 /* A temporary delimiter stack to be used when decoding prompt strings.
3166 This is needed because command substitutions in prompt strings (e.g., PS2)
3167 can screw up the parser's quoting state. */
3168 static struct dstack temp_dstack
= { (char *)NULL
, 0, 0 };
3170 /* Macro for accessing the top delimiter on the stack. Returns the
3171 delimiter or zero if none. */
3172 #define current_delimiter(ds) \
3173 (ds.delimiter_depth ? ds.delimiters[ds.delimiter_depth - 1] : 0)
3175 #define push_delimiter(ds, character) \
3178 if (ds.delimiter_depth + 2 > ds.delimiter_space) \
3179 ds.delimiters = (char *)xrealloc \
3180 (ds.delimiters, (ds.delimiter_space += 10) * sizeof (char)); \
3181 ds.delimiters[ds.delimiter_depth] = character; \
3182 ds.delimiter_depth++; \
3186 #define pop_delimiter(ds) ds.delimiter_depth--
3188 /* Return the next shell input character. This always reads characters
3189 from shell_input_line; when that line is exhausted, it is time to
3190 read the next line. This is called by read_token when the shell is
3191 processing normal command input. */
3193 /* This implements one-character lookahead/lookbehind across physical input
3194 lines, to avoid something being lost because it's pushed back with
3195 shell_ungetc when we're at the start of a line. */
3196 static int eol_ungetc_lookahead
= 0;
3199 shell_getc (remove_quoted_newline
)
3200 int remove_quoted_newline
;
3208 if (sigwinch_received
)
3210 sigwinch_received
= 0;
3211 get_new_window_size (0, (int *)0, (int *)0);
3214 if (eol_ungetc_lookahead
)
3216 c
= eol_ungetc_lookahead
;
3217 eol_ungetc_lookahead
= 0;
3221 #if defined (ALIAS) || defined (DPAREN_ARITHMETIC)
3222 /* If shell_input_line[shell_input_line_index] == 0, but there is
3223 something on the pushed list of strings, then we don't want to go
3224 off and get another line. We let the code down below handle it. */
3226 if (!shell_input_line
|| ((!shell_input_line
[shell_input_line_index
]) &&
3227 (pushed_string_list
== (STRING_SAVER
*)NULL
)))
3228 #else /* !ALIAS && !DPAREN_ARITHMETIC */
3229 if (!shell_input_line
|| !shell_input_line
[shell_input_line_index
])
3230 #endif /* !ALIAS && !DPAREN_ARITHMETIC */
3236 /* Allow immediate exit if interrupted during input. */
3240 shell_input_line_terminator
= 0;
3242 /* If the shell is interatctive, but not currently printing a prompt
3243 (interactive_shell && interactive == 0), we don't want to print
3244 notifies or cleanup the jobs -- we want to defer it until we do
3245 print the next prompt. */
3246 if (interactive_shell
== 0 || SHOULD_PROMPT())
3248 #if defined (JOB_CONTROL)
3249 /* This can cause a problem when reading a command as the result
3250 of a trap, when the trap is called from flush_child. This call
3251 had better not cause jobs to disappear from the job table in
3252 that case, or we will have big trouble. */
3253 notify_and_cleanup ();
3254 #else /* !JOB_CONTROL */
3255 cleanup_dead_jobs ();
3256 #endif /* !JOB_CONTROL */
3259 #if defined (READLINE)
3260 if (no_line_editing
&& SHOULD_PROMPT())
3262 if (SHOULD_PROMPT())
3266 if (bash_input
.type
== st_stream
)
3273 /* Allow immediate exit if interrupted during input. */
3279 internal_warning ("shell_getc: ignored null byte in input");
3284 RESIZE_MALLOCED_BUFFER (shell_input_line
, i
, 2, shell_input_line_size
, 256);
3288 if (bash_input
.type
== st_stream
)
3292 shell_input_line_terminator
= EOF
;
3294 shell_input_line
[i
] = '\0';
3298 shell_input_line
[i
++] = c
;
3302 shell_input_line
[--i
] = '\0';
3303 current_command_line_count
++;
3308 shell_input_line_index
= 0;
3309 shell_input_line_len
= i
; /* == strlen (shell_input_line) */
3311 set_line_mbstate ();
3313 #if defined (HISTORY)
3314 if (remember_on_history
&& shell_input_line
&& shell_input_line
[0])
3317 # if defined (BANG_HISTORY)
3320 /* If the current delimiter is a single quote, we should not be
3321 performing history expansion, even if we're on a different
3322 line from the original single quote. */
3323 old_hist
= history_expansion_inhibited
;
3324 if (current_delimiter (dstack
) == '\'')
3325 history_expansion_inhibited
= 1;
3327 expansions
= pre_process_line (shell_input_line
, 1, 1);
3328 # if defined (BANG_HISTORY)
3329 history_expansion_inhibited
= old_hist
;
3331 if (expansions
!= shell_input_line
)
3333 free (shell_input_line
);
3334 shell_input_line
= expansions
;
3335 shell_input_line_len
= shell_input_line
?
3336 strlen (shell_input_line
) : 0;
3337 if (!shell_input_line_len
)
3338 current_command_line_count
--;
3340 /* We have to force the xrealloc below because we don't know
3341 the true allocated size of shell_input_line anymore. */
3342 shell_input_line_size
= shell_input_line_len
;
3344 set_line_mbstate ();
3347 /* Try to do something intelligent with blank lines encountered while
3348 entering multi-line commands. XXX - this is grotesque */
3349 else if (remember_on_history
&& shell_input_line
&&
3350 shell_input_line
[0] == '\0' &&
3351 current_command_line_count
> 1)
3353 if (current_delimiter (dstack
))
3354 /* We know shell_input_line[0] == 0 and we're reading some sort of
3355 quoted string. This means we've got a line consisting of only
3356 a newline in a quoted string. We want to make sure this line
3357 gets added to the history. */
3358 maybe_add_history (shell_input_line
);
3362 hdcs
= history_delimiting_chars ();
3363 if (hdcs
&& hdcs
[0] == ';')
3364 maybe_add_history (shell_input_line
);
3368 #endif /* HISTORY */
3370 if (shell_input_line
)
3372 /* Lines that signify the end of the shell's input should not be
3374 if (echo_input_at_read
&& (shell_input_line
[0] ||
3375 shell_input_line_terminator
!= EOF
))
3376 fprintf (stderr
, "%s\n", shell_input_line
);
3380 shell_input_line_size
= 0;
3381 prompt_string_pointer
= ¤t_prompt_string
;
3382 if (SHOULD_PROMPT ())
3387 /* Add the newline to the end of this string, iff the string does
3388 not already end in an EOF character. */
3389 if (shell_input_line_terminator
!= EOF
)
3391 if (shell_input_line_len
+ 3 > shell_input_line_size
)
3392 shell_input_line
= (char *)xrealloc (shell_input_line
,
3393 1 + (shell_input_line_size
+= 2));
3395 shell_input_line
[shell_input_line_len
] = '\n';
3396 shell_input_line
[shell_input_line_len
+ 1] = '\0';
3398 set_line_mbstate ();
3402 uc
= shell_input_line
[shell_input_line_index
];
3405 shell_input_line_index
++;
3407 #if defined (ALIAS) || defined (DPAREN_ARITHMETIC)
3408 /* If UC is NULL, we have reached the end of the current input string. If
3409 pushed_string_list is non-empty, it's time to pop to the previous string
3410 because we have fully consumed the result of the last alias expansion.
3411 Do it transparently; just return the next character of the string popped
3413 if (!uc
&& (pushed_string_list
!= (STRING_SAVER
*)NULL
))
3416 uc
= shell_input_line
[shell_input_line_index
];
3418 shell_input_line_index
++;
3420 #endif /* ALIAS || DPAREN_ARITHMETIC */
3422 if MBTEST(uc
== '\\' && remove_quoted_newline
&& shell_input_line
[shell_input_line_index
] == '\n')
3424 if (SHOULD_PROMPT ())
3430 if (!uc
&& shell_input_line_terminator
== EOF
)
3431 return ((shell_input_line_index
!= 0) ? '\n' : EOF
);
3436 /* Put C back into the input for the shell. This might need changes for
3437 HANDLE_MULTIBYTE around EOLs. Since we (currently) never push back a
3438 character different than we read, shell_input_line_property doesn't need
3439 to change when manipulating shell_input_line. The define for
3440 last_shell_getc_is_singlebyte should take care of it, though. */
3445 if (shell_input_line
&& shell_input_line_index
)
3446 shell_input_line
[--shell_input_line_index
] = c
;
3448 eol_ungetc_lookahead
= c
;
3451 #ifdef INCLUDE_UNUSED
3452 /* Back the input pointer up by one, effectively `ungetting' a character. */
3456 if (shell_input_line
&& shell_input_line_index
)
3457 shell_input_line_index
--;
3461 /* Discard input until CHARACTER is seen, then push that character back
3462 onto the input stream. */
3464 discard_until (character
)
3469 while ((c
= shell_getc (0)) != EOF
&& c
!= character
)
3477 execute_variable_command (command
, vname
)
3478 char *command
, *vname
;
3481 sh_parser_state_t ps
;
3483 save_parser_state (&ps
);
3484 last_lastarg
= get_string_value ("_");
3486 last_lastarg
= savestring (last_lastarg
);
3488 parse_and_execute (savestring (command
), vname
, SEVAL_NONINT
|SEVAL_NOHIST
);
3490 restore_parser_state (&ps
);
3491 bind_variable ("_", last_lastarg
, 0);
3492 FREE (last_lastarg
);
3494 if (token_to_read
== '\n') /* reset_parser was called */
3498 /* Place to remember the token. We try to keep the buffer
3499 at a reasonable size, but it can grow. */
3500 static char *token
= (char *)NULL
;
3502 /* Current size of the token buffer. */
3503 static int token_buffer_size
;
3505 /* Command to read_token () explaining what we want it to do. */
3508 #define prompt_is_ps1 \
3509 (!prompt_string_pointer || prompt_string_pointer == &ps1_prompt)
3511 /* Function for yyparse to call. yylex keeps track of
3512 the last two tokens read, and calls read_token. */
3516 if (interactive
&& (current_token
== 0 || current_token
== '\n'))
3518 /* Before we print a prompt, we might have to check mailboxes.
3519 We do this only if it is time to do so. Notice that only here
3520 is the mail alarm reset; nothing takes place in check_mail ()
3521 except the checking of mail. Please don't change this. */
3522 if (prompt_is_ps1
&& time_to_check_mail ())
3525 reset_mail_timer ();
3528 /* Avoid printing a prompt if we're not going to read anything, e.g.
3529 after resetting the parser with read_token (RESET). */
3530 if (token_to_read
== 0 && SHOULD_PROMPT ())
3534 two_tokens_ago
= token_before_that
;
3535 token_before_that
= last_read_token
;
3536 last_read_token
= current_token
;
3537 current_token
= read_token (READ
);
3538 return (current_token
);
3541 /* When non-zero, we have read the required tokens
3542 which allow ESAC to be the next one read. */
3543 static int esacs_needed_count
;
3546 gather_here_documents ()
3549 while (need_here_doc
)
3551 make_here_document (redir_stack
[r
++]);
3556 /* When non-zero, an open-brace used to create a group is awaiting a close
3558 static int open_brace_count
;
3560 #define command_token_position(token) \
3561 (((token) == ASSIGNMENT_WORD) || \
3562 ((token) != SEMI_SEMI && reserved_word_acceptable(token)))
3564 #define assignment_acceptable(token) \
3565 (command_token_position(token) && ((parser_state & PST_CASEPAT) == 0))
3567 /* Check to see if TOKEN is a reserved word and return the token
3569 #define CHECK_FOR_RESERVED_WORD(tok) \
3571 if (!dollar_present && !quoted && \
3572 reserved_word_acceptable (last_read_token)) \
3575 for (i = 0; word_token_alist[i].word != (char *)NULL; i++) \
3576 if (STREQ (tok, word_token_alist[i].word)) \
3578 if ((parser_state & PST_CASEPAT) && (word_token_alist[i].token != ESAC)) \
3580 if (word_token_alist[i].token == TIME && time_command_acceptable () == 0) \
3582 if (word_token_alist[i].token == ESAC) \
3583 parser_state &= ~(PST_CASEPAT|PST_CASESTMT); \
3584 else if (word_token_alist[i].token == CASE) \
3585 parser_state |= PST_CASESTMT; \
3586 else if (word_token_alist[i].token == COND_END) \
3587 parser_state &= ~(PST_CONDCMD|PST_CONDEXPR); \
3588 else if (word_token_alist[i].token == COND_START) \
3589 parser_state |= PST_CONDCMD; \
3590 else if (word_token_alist[i].token == '{') \
3591 open_brace_count++; \
3592 else if (word_token_alist[i].token == '}' && open_brace_count) \
3593 open_brace_count--; \
3594 return (word_token_alist[i].token); \
3601 /* OK, we have a token. Let's try to alias expand it, if (and only if)
3604 It is eligible for expansion if EXPAND_ALIASES is set, and
3605 the token is unquoted and the last token read was a command
3606 separator (or expand_next_token is set), and we are currently
3607 processing an alias (pushed_string_list is non-empty) and this
3608 token is not the same as the current or any previously
3611 Special cases that disqualify:
3612 In a pattern list in a case statement (parser_state & PST_CASEPAT). */
3622 r
= xmalloc (l
+ 2);
3631 alias_expand_token (tokstr
)
3637 if (((parser_state
& PST_ALEXPNEXT
) || command_token_position (last_read_token
)) &&
3638 (parser_state
& PST_CASEPAT
) == 0)
3640 ap
= find_alias (tokstr
);
3642 /* Currently expanding this token. */
3643 if (ap
&& (ap
->flags
& AL_BEINGEXPANDED
))
3644 return (NO_EXPANSION
);
3646 /* mk_alexpansion puts an extra space on the end of the alias expansion,
3647 so the lookahead by the parser works right. If this gets changed,
3648 make sure the code in shell_getc that deals with reaching the end of
3649 an expanded alias is changed with it. */
3650 expanded
= ap
? mk_alexpansion (ap
->value
) : (char *)NULL
;
3654 push_string (expanded
, ap
->flags
& AL_EXPANDNEXT
, ap
);
3655 return (RE_READ_TOKEN
);
3658 /* This is an eligible token that does not have an expansion. */
3659 return (NO_EXPANSION
);
3661 return (NO_EXPANSION
);
3666 time_command_acceptable ()
3668 #if defined (COMMAND_TIMING)
3669 switch (last_read_token
)
3688 #endif /* COMMAND_TIMING */
3691 /* Handle special cases of token recognition:
3692 IN is recognized if the last token was WORD and the token
3693 before that was FOR or CASE or SELECT.
3695 DO is recognized if the last token was WORD and the token
3696 before that was FOR or SELECT.
3698 ESAC is recognized if the last token caused `esacs_needed_count'
3701 `{' is recognized if the last token as WORD and the token
3702 before that was FUNCTION, or if we just parsed an arithmetic
3705 `}' is recognized if there is an unclosed `{' present.
3707 `-p' is returned as TIMEOPT if the last read token was TIME.
3709 ']]' is returned as COND_END if the parser is currently parsing
3710 a conditional expression ((parser_state & PST_CONDEXPR) != 0)
3712 `time' is returned as TIME if and only if it is immediately
3713 preceded by one of `;', `\n', `||', `&&', or `&'.
3717 special_case_tokens (tokstr
)
3720 if ((last_read_token
== WORD
) &&
3721 #if defined (SELECT_COMMAND)
3722 ((token_before_that
== FOR
) || (token_before_that
== CASE
) || (token_before_that
== SELECT
)) &&
3724 ((token_before_that
== FOR
) || (token_before_that
== CASE
)) &&
3726 (tokstr
[0] == 'i' && tokstr
[1] == 'n' && tokstr
[2] == 0))
3728 if (token_before_that
== CASE
)
3730 parser_state
|= PST_CASEPAT
;
3731 esacs_needed_count
++;
3736 if (last_read_token
== WORD
&&
3737 #if defined (SELECT_COMMAND)
3738 (token_before_that
== FOR
|| token_before_that
== SELECT
) &&
3740 (token_before_that
== FOR
) &&
3742 (tokstr
[0] == 'd' && tokstr
[1] == 'o' && tokstr
[2] == '\0'))
3745 /* Ditto for ESAC in the CASE case.
3746 Specifically, this handles "case word in esac", which is a legal
3747 construct, certainly because someone will pass an empty arg to the
3748 case construct, and we don't want it to barf. Of course, we should
3749 insist that the case construct has at least one pattern in it, but
3750 the designers disagree. */
3751 if (esacs_needed_count
)
3753 esacs_needed_count
--;
3754 if (STREQ (tokstr
, "esac"))
3756 parser_state
&= ~PST_CASEPAT
;
3761 /* The start of a shell function definition. */
3762 if (parser_state
& PST_ALLOWOPNBRC
)
3764 parser_state
&= ~PST_ALLOWOPNBRC
;
3765 if (tokstr
[0] == '{' && tokstr
[1] == '\0') /* } */
3768 function_bstart
= line_number
;
3769 return ('{'); /* } */
3773 /* We allow a `do' after a for ((...)) without an intervening
3775 if (last_read_token
== ARITH_FOR_EXPRS
&& tokstr
[0] == 'd' && tokstr
[1] == 'o' && !tokstr
[2])
3777 if (last_read_token
== ARITH_FOR_EXPRS
&& tokstr
[0] == '{' && tokstr
[1] == '\0') /* } */
3780 return ('{'); /* } */
3783 if (open_brace_count
&& reserved_word_acceptable (last_read_token
) && tokstr
[0] == '}' && !tokstr
[1])
3785 open_brace_count
--; /* { */
3789 #if defined (COMMAND_TIMING)
3790 /* Handle -p after `time'. */
3791 if (last_read_token
== TIME
&& tokstr
[0] == '-' && tokstr
[1] == 'p' && !tokstr
[2])
3796 #if defined (COMMAND_TIMING)
3797 if (STREQ (token
, "time") && ((parser_state
& PST_CASEPAT
) == 0) && time_command_acceptable ())
3799 #endif /* COMMAND_TIMING */
3802 #if defined (COND_COMMAND) /* [[ */
3803 if ((parser_state
& PST_CONDEXPR
) && tokstr
[0] == ']' && tokstr
[1] == ']' && tokstr
[2] == '\0')
3810 /* Called from shell.c when Control-C is typed at top level. Or
3811 by the error rule at top level. */
3815 dstack
.delimiter_depth
= 0; /* No delimiters found so far. */
3816 open_brace_count
= 0;
3820 #if defined (ALIAS) || defined (DPAREN_ARITHMETIC)
3821 if (pushed_string_list
)
3822 free_string_list ();
3823 #endif /* ALIAS || DPAREN_ARITHMETIC */
3825 if (shell_input_line
)
3827 free (shell_input_line
);
3828 shell_input_line
= (char *)NULL
;
3829 shell_input_line_size
= shell_input_line_index
= 0;
3832 FREE (word_desc_to_read
);
3833 word_desc_to_read
= (WORD_DESC
*)NULL
;
3835 last_read_token
= '\n';
3836 token_to_read
= '\n';
3839 /* Read the next token. Command can be READ (normal operation) or
3840 RESET (to normalize state). */
3842 read_token (command
)
3845 int character
; /* Current character. */
3846 int peek_char
; /* Temporary look-ahead character. */
3847 int result
; /* The thing to return. */
3849 if (command
== RESET
)
3857 result
= token_to_read
;
3858 if (token_to_read
== WORD
|| token_to_read
== ASSIGNMENT_WORD
)
3860 yylval
.word
= word_desc_to_read
;
3861 word_desc_to_read
= (WORD_DESC
*)NULL
;
3867 #if defined (COND_COMMAND)
3868 if ((parser_state
& (PST_CONDCMD
|PST_CONDEXPR
)) == PST_CONDCMD
)
3870 cond_lineno
= line_number
;
3871 parser_state
|= PST_CONDEXPR
;
3872 yylval
.command
= parse_cond_command ();
3873 if (cond_token
!= COND_END
)
3878 token_to_read
= COND_END
;
3879 parser_state
&= ~(PST_CONDEXPR
|PST_CONDCMD
);
3885 /* This is a place to jump back to once we have successfully expanded a
3886 token with an alias and pushed the string with push_string () */
3890 /* Read a single word from input. Start by skipping blanks. */
3891 while ((character
= shell_getc (1)) != EOF
&& shellblank (character
))
3894 if (character
== EOF
)
3900 if MBTEST(character
== '#' && (!interactive
|| interactive_comments
))
3902 /* A comment. Discard until EOL or EOF, and then return a newline. */
3903 discard_until ('\n');
3905 character
= '\n'; /* this will take the next if statement and return. */
3908 if (character
== '\n')
3910 /* If we're about to return an unquoted newline, we can go and collect
3911 the text of any pending here document. */
3913 gather_here_documents ();
3916 parser_state
&= ~PST_ALEXPNEXT
;
3919 parser_state
&= ~PST_ASSIGNOK
;
3924 /* Shell meta-characters. */
3925 if MBTEST(shellmeta (character
) && ((parser_state
& PST_DBLPAREN
) == 0))
3928 /* Turn off alias tokenization iff this character sequence would
3929 not leave us ready to read a command. */
3930 if (character
== '<' || character
== '>')
3931 parser_state
&= ~PST_ALEXPNEXT
;
3934 parser_state
&= ~PST_ASSIGNOK
;
3936 peek_char
= shell_getc (1);
3937 if (character
== peek_char
)
3942 /* If '<' then we could be at "<<" or at "<<-". We have to
3943 look ahead one more character. */
3944 peek_char
= shell_getc (1);
3945 if (peek_char
== '-')
3946 return (LESS_LESS_MINUS
);
3947 else if (peek_char
== '<')
3948 return (LESS_LESS_LESS
);
3951 shell_ungetc (peek_char
);
3956 return (GREATER_GREATER
);
3959 parser_state
|= PST_CASEPAT
;
3961 parser_state
&= ~PST_ALEXPNEXT
;
3972 #if defined (DPAREN_ARITHMETIC) || defined (ARITH_FOR_COMMAND)
3974 result
= parse_dparen (character
);
3982 else if MBTEST(character
== '<' && peek_char
== '&')
3984 else if MBTEST(character
== '>' && peek_char
== '&')
3985 return (GREATER_AND
);
3986 else if MBTEST(character
== '<' && peek_char
== '>')
3987 return (LESS_GREATER
);
3988 else if MBTEST(character
== '>' && peek_char
== '|')
3989 return (GREATER_BAR
);
3990 else if MBTEST(peek_char
== '>' && character
== '&')
3991 return (AND_GREATER
);
3993 shell_ungetc (peek_char
);
3995 /* If we look like we are reading the start of a function
3996 definition, then let the reader know about it so that
3997 we will do the right thing with `{'. */
3998 if MBTEST(character
== ')' && last_read_token
== '(' && token_before_that
== WORD
)
4000 parser_state
|= PST_ALLOWOPNBRC
;
4002 parser_state
&= ~PST_ALEXPNEXT
;
4004 function_dstart
= line_number
;
4007 /* case pattern lists may be preceded by an optional left paren. If
4008 we're not trying to parse a case pattern list, the left paren
4009 indicates a subshell. */
4010 if MBTEST(character
== '(' && (parser_state
& PST_CASEPAT
) == 0) /* ) */
4011 parser_state
|= PST_SUBSHELL
;
4013 else if MBTEST((parser_state
& PST_CASEPAT
) && character
== ')')
4014 parser_state
&= ~PST_CASEPAT
;
4016 else if MBTEST((parser_state
& PST_SUBSHELL
) && character
== ')')
4017 parser_state
&= ~PST_SUBSHELL
;
4019 #if defined (PROCESS_SUBSTITUTION)
4020 /* Check for the constructs which introduce process substitution.
4021 Shells running in `posix mode' don't do process substitution. */
4022 if MBTEST(posixly_correct
|| ((character
!= '>' && character
!= '<') || peek_char
!= '(')) /*)*/
4023 #endif /* PROCESS_SUBSTITUTION */
4027 /* Hack <&- (close stdin) case. Also <&N- (dup and close). */
4028 if MBTEST(character
== '-' && (last_read_token
== LESS_AND
|| last_read_token
== GREATER_AND
))
4031 /* Okay, if we got this far, we have to read a word. Read one,
4032 and then check it against the known ones. */
4033 result
= read_token_word (character
);
4035 if (result
== RE_READ_TOKEN
)
4042 * Match a $(...) or other grouping construct. This has to handle embedded
4043 * quoted strings ('', ``, "") and nested constructs. It also must handle
4044 * reprompting the user, if necessary, after reading a newline, and returning
4045 * correct error values if it reads EOF.
4047 #define P_FIRSTCLOSE 0x01
4048 #define P_ALLOWESC 0x02
4049 #define P_DQUOTE 0x04
4050 #define P_COMMAND 0x08 /* parsing a command, so look for comments */
4051 #define P_BACKQUOTE 0x10 /* parsing a backquoted command substitution */
4053 static char matched_pair_error
;
4055 parse_matched_pair (qc
, open
, close
, lenp
, flags
)
4056 int qc
; /* `"' if this construct is within double quotes */
4060 int count
, ch
, was_dollar
, in_comment
, check_comment
;
4061 int pass_next_character
, backq_backslash
, nestlen
, ttranslen
, start_lineno
;
4062 char *ret
, *nestret
, *ttrans
;
4063 int retind
, retsize
, rflags
;
4065 /* itrace("parse_matched_pair: open = %c close = %c", open, close); */
4067 pass_next_character
= backq_backslash
= was_dollar
= in_comment
= 0;
4068 check_comment
= (flags
& P_COMMAND
) && qc
!= '\'' && qc
!= '"' && (flags
& P_DQUOTE
) == 0;
4070 /* RFLAGS is the set of flags we want to pass to recursive calls. */
4071 rflags
= (qc
== '"') ? P_DQUOTE
: (flags
& P_DQUOTE
);
4073 ret
= (char *)xmalloc (retsize
= 64);
4076 start_lineno
= line_number
;
4079 ch
= shell_getc (qc
!= '\'' && pass_next_character
== 0 && backq_backslash
== 0);
4084 parser_error (start_lineno
, _("unexpected EOF while looking for matching `%c'"), close
);
4085 EOF_Reached
= 1; /* XXX */
4086 return (&matched_pair_error
);
4089 /* Possible reprompting. */
4090 if (ch
== '\n' && SHOULD_PROMPT ())
4095 /* Add this character. */
4096 RESIZE_MALLOCED_BUFFER (ret
, retind
, 1, retsize
, 64);
4104 /* Not exactly right yet, should handle shell metacharacters, too. If
4105 any changes are made to this test, make analogous changes to subst.c:
4106 extract_delimited_string(). */
4107 else if MBTEST(check_comment
&& in_comment
== 0 && ch
== '#' && (retind
== 0 || ret
[retind
-1] == '\n' || whitespace (ret
[retind
- 1])))
4110 /* last char was backslash inside backquoted command substitution */
4111 if (backq_backslash
)
4113 backq_backslash
= 0;
4114 /* Placeholder for adding special characters */
4117 if (pass_next_character
) /* last char was backslash */
4119 pass_next_character
= 0;
4120 if (qc
!= '\'' && ch
== '\n') /* double-quoted \<newline> disappears. */
4122 if (retind
> 0) retind
--; /* swallow previously-added backslash */
4126 RESIZE_MALLOCED_BUFFER (ret
, retind
, 2, retsize
, 64);
4127 if MBTEST(ch
== CTLESC
|| ch
== CTLNUL
)
4128 ret
[retind
++] = CTLESC
;
4132 else if MBTEST(ch
== CTLESC
|| ch
== CTLNUL
) /* special shell escapes */
4134 RESIZE_MALLOCED_BUFFER (ret
, retind
, 2, retsize
, 64);
4135 ret
[retind
++] = CTLESC
;
4139 else if MBTEST(ch
== close
) /* ending delimiter */
4141 /* handle nested ${...} specially. */
4142 else if MBTEST(open
!= close
&& was_dollar
&& open
== '{' && ch
== open
) /* } */
4144 else if MBTEST(((flags
& P_FIRSTCLOSE
) == 0) && ch
== open
) /* nested begin */
4147 /* Add this character. */
4148 RESIZE_MALLOCED_BUFFER (ret
, retind
, 1, retsize
, 64);
4151 if (open
== '\'') /* '' inside grouping construct */
4153 if MBTEST((flags
& P_ALLOWESC
) && ch
== '\\')
4154 pass_next_character
++;
4156 else if MBTEST((flags
& P_BACKQUOTE
) && ch
== '\\')
4162 if MBTEST(ch
== '\\') /* backslashes */
4163 pass_next_character
++;
4165 if (open
!= close
) /* a grouping construct */
4167 if MBTEST(shellquote (ch
))
4169 /* '', ``, or "" inside $(...) or other grouping construct. */
4170 push_delimiter (dstack
, ch
);
4171 if MBTEST(was_dollar
&& ch
== '\'') /* $'...' inside group */
4172 nestret
= parse_matched_pair (ch
, ch
, ch
, &nestlen
, P_ALLOWESC
|rflags
);
4174 nestret
= parse_matched_pair (ch
, ch
, ch
, &nestlen
, rflags
);
4175 pop_delimiter (dstack
);
4176 if (nestret
== &matched_pair_error
)
4179 return &matched_pair_error
;
4181 if MBTEST(was_dollar
&& ch
== '\'' && (extended_quote
|| (rflags
& P_DQUOTE
) == 0))
4183 /* Translate $'...' here. */
4184 ttrans
= ansiexpand (nestret
, 0, nestlen
- 1, &ttranslen
);
4187 if ((rflags
& P_DQUOTE
) == 0)
4189 nestret
= sh_single_quote (ttrans
);
4191 nestlen
= strlen (nestret
);
4196 nestlen
= ttranslen
;
4198 retind
-= 2; /* back up before the $' */
4200 else if MBTEST(was_dollar
&& ch
== '"' && (extended_quote
|| (rflags
& P_DQUOTE
) == 0))
4202 /* Locale expand $"..." here. */
4203 ttrans
= localeexpand (nestret
, 0, nestlen
- 1, start_lineno
, &ttranslen
);
4206 nestret
= sh_mkdoublequoted (ttrans
, ttranslen
, 0);
4208 nestlen
= ttranslen
+ 2;
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
, rflags
);
4228 if (nestret
== &matched_pair_error
)
4231 return &matched_pair_error
;
4235 RESIZE_MALLOCED_BUFFER (ret
, retind
, nestlen
, retsize
, 64);
4236 strcpy (ret
+ retind
, nestret
);
4242 else if MBTEST(qc
== '`' && (ch
== '"' || ch
== '\'') && in_comment
== 0)
4244 /* Add P_BACKQUOTE so backslash quotes the next character and
4245 shell_getc does the right thing with \<newline>. We do this for
4246 a measure of backwards compatibility -- it's not strictly the
4247 right POSIX thing. */
4248 nestret
= parse_matched_pair (0, ch
, ch
, &nestlen
, rflags
|P_BACKQUOTE
);
4252 else if MBTEST(open
!= '`' && was_dollar
&& (ch
== '(' || ch
== '{' || ch
== '[')) /* ) } ] */
4253 /* check for $(), $[], or ${} inside quoted string. */
4255 if (open
== ch
) /* undo previous increment */
4257 if (ch
== '(') /* ) */
4258 nestret
= parse_matched_pair (0, '(', ')', &nestlen
, rflags
& ~P_DQUOTE
);
4259 else if (ch
== '{') /* } */
4260 nestret
= parse_matched_pair (0, '{', '}', &nestlen
, P_FIRSTCLOSE
|rflags
);
4261 else if (ch
== '[') /* ] */
4262 nestret
= parse_matched_pair (0, '[', ']', &nestlen
, rflags
);
4266 was_dollar
= MBTEST(ch
== '$');
4275 #if defined (DPAREN_ARITHMETIC) || defined (ARITH_FOR_COMMAND)
4276 /* Parse a double-paren construct. It can be either an arithmetic
4277 command, an arithmetic `for' command, or a nested subshell. Returns
4278 the parsed token, -1 on error, or -2 if we didn't do anything and
4279 should just go on. */
4288 #if defined (ARITH_FOR_COMMAND)
4289 if (last_read_token
== FOR
)
4291 arith_for_lineno
= line_number
;
4292 cmdtyp
= parse_arith_cmd (&wval
, 0);
4295 wd
= alloc_word_desc ();
4297 yylval
.word_list
= make_word_list (wd
, (WORD_LIST
*)NULL
);
4298 return (ARITH_FOR_EXPRS
);
4301 return -1; /* ERROR */
4305 #if defined (DPAREN_ARITHMETIC)
4306 if (reserved_word_acceptable (last_read_token
))
4308 sline
= line_number
;
4310 cmdtyp
= parse_arith_cmd (&wval
, 0);
4311 if (cmdtyp
== 1) /* arithmetic command */
4313 wd
= alloc_word_desc ();
4315 wd
->flags
= W_QUOTED
|W_NOSPLIT
|W_NOGLOB
|W_DQUOTE
;
4316 yylval
.word_list
= make_word_list (wd
, (WORD_LIST
*)NULL
);
4319 else if (cmdtyp
== 0) /* nested subshell */
4321 push_string (wval
, 0, (alias_t
*)NULL
);
4322 if ((parser_state
& PST_CASEPAT
) == 0)
4323 parser_state
|= PST_SUBSHELL
;
4331 return -2; /* XXX */
4334 /* We've seen a `(('. Look for the matching `))'. If we get it, return 1.
4335 If not, assume it's a nested subshell for backwards compatibility and
4336 return 0. In any case, put the characters we've consumed into a locally-
4337 allocated buffer and make *ep point to that buffer. Return -1 on an
4338 error, for example EOF. */
4340 parse_arith_cmd (ep
, adddq
)
4344 int exp_lineno
, rval
, c
;
4345 char *ttok
, *tokstr
;
4348 exp_lineno
= line_number
;
4349 ttok
= parse_matched_pair (0, '(', ')', &ttoklen
, 0);
4351 if (ttok
== &matched_pair_error
)
4353 /* Check that the next character is the closing right paren. If
4354 not, this is a syntax error. ( */
4359 tokstr
= (char *)xmalloc (ttoklen
+ 4);
4361 /* if ADDDQ != 0 then (( ... )) -> "..." */
4362 if (rval
== 1 && adddq
) /* arith cmd, add double quotes */
4365 strncpy (tokstr
+ 1, ttok
, ttoklen
- 1);
4366 tokstr
[ttoklen
] = '"';
4367 tokstr
[ttoklen
+1] = '\0';
4369 else if (rval
== 1) /* arith cmd, don't add double quotes */
4371 strncpy (tokstr
, ttok
, ttoklen
- 1);
4372 tokstr
[ttoklen
-1] = '\0';
4374 else /* nested subshell */
4377 strncpy (tokstr
+ 1, ttok
, ttoklen
- 1);
4378 tokstr
[ttoklen
] = ')';
4379 tokstr
[ttoklen
+1] = c
;
4380 tokstr
[ttoklen
+2] = '\0';
4387 #endif /* DPAREN_ARITHMETIC || ARITH_FOR_COMMAND */
4389 #if defined (COND_COMMAND)
4395 if (EOF_Reached
&& cond_token
!= COND_ERROR
) /* [[ */
4396 parser_error (cond_lineno
, _("unexpected EOF while looking for `]]'"));
4397 else if (cond_token
!= COND_ERROR
)
4399 if (etext
= error_token_from_token (cond_token
))
4401 parser_error (cond_lineno
, _("syntax error in conditional expression: unexpected token `%s'"), etext
);
4405 parser_error (cond_lineno
, _("syntax error in conditional expression"));
4412 return (cond_or ());
4421 if (cond_token
== OR_OR
)
4424 l
= make_cond_node (COND_OR
, (WORD_DESC
*)NULL
, l
, r
);
4435 if (cond_token
== AND_AND
)
4438 l
= make_cond_node (COND_AND
, (WORD_DESC
*)NULL
, l
, r
);
4444 cond_skip_newlines ()
4446 while ((cond_token
= read_token (READ
)) == '\n')
4448 if (SHOULD_PROMPT ())
4451 return (cond_token
);
4454 #define COND_RETURN_ERROR() \
4455 do { cond_token = COND_ERROR; return ((COND_COM *)NULL); } while (0)
4461 COND_COM
*term
, *tleft
, *tright
;
4465 /* Read a token. It can be a left paren, a `!', a unary operator, or a
4466 word that should be the first argument of a binary operator. Start by
4467 skipping newlines, since this is a compound command. */
4468 tok
= cond_skip_newlines ();
4469 lineno
= line_number
;
4470 if (tok
== COND_END
)
4472 COND_RETURN_ERROR ();
4474 else if (tok
== '(')
4476 term
= cond_expr ();
4477 if (cond_token
!= ')')
4480 dispose_cond_node (term
); /* ( */
4481 if (etext
= error_token_from_token (cond_token
))
4483 parser_error (lineno
, _("unexpected token `%s', expected `)'"), etext
);
4487 parser_error (lineno
, _("expected `)'"));
4488 COND_RETURN_ERROR ();
4490 term
= make_cond_node (COND_EXPR
, (WORD_DESC
*)NULL
, term
, (COND_COM
*)NULL
);
4491 (void)cond_skip_newlines ();
4493 else if (tok
== BANG
|| (tok
== WORD
&& (yylval
.word
->word
[0] == '!' && yylval
.word
->word
[1] == '\0')))
4496 dispose_word (yylval
.word
); /* not needed */
4497 term
= cond_term ();
4499 term
->flags
|= CMD_INVERT_RETURN
;
4501 else if (tok
== WORD
&& test_unop (yylval
.word
->word
))
4504 tok
= read_token (READ
);
4507 tleft
= make_cond_node (COND_TERM
, yylval
.word
, (COND_COM
*)NULL
, (COND_COM
*)NULL
);
4508 term
= make_cond_node (COND_UNARY
, op
, tleft
, (COND_COM
*)NULL
);
4513 if (etext
= error_token_from_token (tok
))
4515 parser_error (line_number
, _("unexpected argument `%s' to conditional unary operator"), etext
);
4519 parser_error (line_number
, _("unexpected argument to conditional unary operator"));
4520 COND_RETURN_ERROR ();
4523 (void)cond_skip_newlines ();
4525 else if (tok
== WORD
) /* left argument to binary operator */
4528 tleft
= make_cond_node (COND_TERM
, yylval
.word
, (COND_COM
*)NULL
, (COND_COM
*)NULL
);
4531 tok
= read_token (READ
);
4532 if (tok
== WORD
&& test_binop (yylval
.word
->word
))
4534 #if defined (COND_REGEXP)
4535 else if (tok
== WORD
&& STREQ (yylval
.word
->word
,"=~"))
4538 else if (tok
== '<' || tok
== '>')
4539 op
= make_word_from_token (tok
); /* ( */
4540 /* There should be a check before blindly accepting the `)' that we have
4541 seen the opening `('. */
4542 else if (tok
== COND_END
|| tok
== AND_AND
|| tok
== OR_OR
|| tok
== ')')
4544 /* Special case. [[ x ]] is equivalent to [[ -n x ]], just like
4545 the test command. Similarly for [[ x && expr ]] or
4546 [[ x || expr ]] or [[ (x) ]]. */
4547 op
= make_word ("-n");
4548 term
= make_cond_node (COND_UNARY
, op
, tleft
, (COND_COM
*)NULL
);
4554 if (etext
= error_token_from_token (tok
))
4556 parser_error (line_number
, _("unexpected token `%s', conditional binary operator expected"), etext
);
4560 parser_error (line_number
, _("conditional binary operator expected"));
4561 dispose_cond_node (tleft
);
4562 COND_RETURN_ERROR ();
4566 tok
= read_token (READ
);
4569 tright
= make_cond_node (COND_TERM
, yylval
.word
, (COND_COM
*)NULL
, (COND_COM
*)NULL
);
4570 term
= make_cond_node (COND_BINARY
, op
, tleft
, tright
);
4574 if (etext
= error_token_from_token (tok
))
4576 parser_error (line_number
, _("unexpected argument `%s' to conditional binary operator"), etext
);
4580 parser_error (line_number
, _("unexpected argument to conditional binary operator"));
4581 dispose_cond_node (tleft
);
4583 COND_RETURN_ERROR ();
4586 (void)cond_skip_newlines ();
4591 parser_error (line_number
, _("unexpected token `%c' in conditional command"), tok
);
4592 else if (etext
= error_token_from_token (tok
))
4594 parser_error (line_number
, _("unexpected token `%s' in conditional command"), etext
);
4598 parser_error (line_number
, _("unexpected token %d in conditional command"), tok
);
4599 COND_RETURN_ERROR ();
4604 /* This is kind of bogus -- we slip a mini recursive-descent parser in
4605 here to handle the conditional statement syntax. */
4607 parse_cond_command ()
4611 cexp
= cond_expr ();
4612 return (make_cond_command (cexp
));
4616 #if defined (ARRAY_VARS)
4617 /* When this is called, it's guaranteed that we don't care about anything
4618 in t beyond i. We do save and restore the chars, though. */
4620 token_is_assignment (t
, i
)
4624 unsigned char c
, c1
;
4627 c
= t
[i
]; c1
= t
[i
+1];
4628 t
[i
] = '='; t
[i
+1] = '\0';
4629 r
= assignment (t
, (parser_state
& PST_COMPASSIGN
) != 0);
4630 t
[i
] = c
; t
[i
+1] = c1
;
4634 /* XXX - possible changes here for `+=' */
4636 token_is_ident (t
, i
)
4645 r
= legal_identifier (t
);
4652 read_token_word (character
)
4655 /* The value for YYLVAL when a WORD is read. */
4656 WORD_DESC
*the_word
;
4658 /* Index into the token that we are building. */
4661 /* ALL_DIGITS becomes zero when we see a non-digit. */
4662 int all_digit_token
;
4664 /* DOLLAR_PRESENT becomes non-zero if we see a `$'. */
4667 /* COMPOUND_ASSIGNMENT becomes non-zero if we are parsing a compound
4669 int compound_assignment
;
4671 /* QUOTED becomes non-zero if we see one of ("), ('), (`), or (\). */
4674 /* Non-zero means to ignore the value of the next character, and just
4675 to add it no matter what. */
4676 int pass_next_character
;
4678 /* The current delimiting character. */
4680 int result
, peek_char
;
4681 char *ttok
, *ttrans
;
4682 int ttoklen
, ttranslen
;
4685 if (token_buffer_size
< TOKEN_DEFAULT_INITIAL_SIZE
)
4686 token
= (char *)xrealloc (token
, token_buffer_size
= TOKEN_DEFAULT_INITIAL_SIZE
);
4689 all_digit_token
= DIGIT (character
);
4690 dollar_present
= quoted
= pass_next_character
= compound_assignment
= 0;
4694 if (character
== EOF
)
4697 if (pass_next_character
)
4699 pass_next_character
= 0;
4703 cd
= current_delimiter (dstack
);
4705 /* Handle backslashes. Quote lots of things when not inside of
4706 double-quotes, quote some things inside of double-quotes. */
4707 if MBTEST(character
== '\\')
4709 peek_char
= shell_getc (0);
4711 /* Backslash-newline is ignored in all cases except
4712 when quoted with single quotes. */
4713 if (peek_char
== '\n')
4716 goto next_character
;
4720 shell_ungetc (peek_char
);
4722 /* If the next character is to be quoted, note it now. */
4723 if (cd
== 0 || cd
== '`' ||
4724 (cd
== '"' && peek_char
>= 0 && (sh_syntaxtab
[peek_char
] & CBSDQUOTE
)))
4725 pass_next_character
++;
4732 /* Parse a matched pair of quote characters. */
4733 if MBTEST(shellquote (character
))
4735 push_delimiter (dstack
, character
);
4736 ttok
= parse_matched_pair (character
, character
, character
, &ttoklen
, (character
== '`') ? P_COMMAND
: 0);
4737 pop_delimiter (dstack
);
4738 if (ttok
== &matched_pair_error
)
4739 return -1; /* Bail immediately. */
4740 RESIZE_MALLOCED_BUFFER (token
, token_index
, ttoklen
+ 2,
4741 token_buffer_size
, TOKEN_DEFAULT_GROW_SIZE
);
4742 token
[token_index
++] = character
;
4743 strcpy (token
+ token_index
, ttok
);
4744 token_index
+= ttoklen
;
4745 all_digit_token
= 0;
4747 dollar_present
|= (character
== '"' && strchr (ttok
, '$') != 0);
4749 goto next_character
;
4752 #ifdef EXTENDED_GLOB
4753 /* Parse a ksh-style extended pattern matching specification. */
4754 if (extended_glob
&& PATTERN_CHAR (character
))
4756 peek_char
= shell_getc (1);
4757 if MBTEST(peek_char
== '(') /* ) */
4759 push_delimiter (dstack
, peek_char
);
4760 ttok
= parse_matched_pair (cd
, '(', ')', &ttoklen
, 0);
4761 pop_delimiter (dstack
);
4762 if (ttok
== &matched_pair_error
)
4763 return -1; /* Bail immediately. */
4764 RESIZE_MALLOCED_BUFFER (token
, token_index
, ttoklen
+ 2,
4766 TOKEN_DEFAULT_GROW_SIZE
);
4767 token
[token_index
++] = character
;
4768 token
[token_index
++] = peek_char
;
4769 strcpy (token
+ token_index
, ttok
);
4770 token_index
+= ttoklen
;
4772 dollar_present
= all_digit_token
= 0;
4773 goto next_character
;
4776 shell_ungetc (peek_char
);
4778 #endif /* EXTENDED_GLOB */
4780 /* If the delimiter character is not single quote, parse some of
4781 the shell expansions that must be read as a single word. */
4782 if (shellexp (character
))
4784 peek_char
= shell_getc (1);
4785 /* $(...), <(...), >(...), $((...)), ${...}, and $[...] constructs */
4786 if MBTEST(peek_char
== '(' || \
4787 ((peek_char
== '{' || peek_char
== '[') && character
== '$')) /* ) ] } */
4789 if (peek_char
== '{') /* } */
4790 ttok
= parse_matched_pair (cd
, '{', '}', &ttoklen
, P_FIRSTCLOSE
);
4791 else if (peek_char
== '(') /* ) */
4793 /* XXX - push and pop the `(' as a delimiter for use by
4794 the command-oriented-history code. This way newlines
4795 appearing in the $(...) string get added to the
4796 history literally rather than causing a possibly-
4797 incorrect `;' to be added. ) */
4798 push_delimiter (dstack
, peek_char
);
4799 ttok
= parse_matched_pair (cd
, '(', ')', &ttoklen
, P_COMMAND
);
4800 pop_delimiter (dstack
);
4803 ttok
= parse_matched_pair (cd
, '[', ']', &ttoklen
, 0);
4804 if (ttok
== &matched_pair_error
)
4805 return -1; /* Bail immediately. */
4806 RESIZE_MALLOCED_BUFFER (token
, token_index
, ttoklen
+ 2,
4808 TOKEN_DEFAULT_GROW_SIZE
);
4809 token
[token_index
++] = character
;
4810 token
[token_index
++] = peek_char
;
4811 strcpy (token
+ token_index
, ttok
);
4812 token_index
+= ttoklen
;
4815 all_digit_token
= 0;
4816 goto next_character
;
4818 /* This handles $'...' and $"..." new-style quoted strings. */
4819 else if MBTEST(character
== '$' && (peek_char
== '\'' || peek_char
== '"'))
4823 first_line
= line_number
;
4824 push_delimiter (dstack
, peek_char
);
4825 ttok
= parse_matched_pair (peek_char
, peek_char
, peek_char
,
4827 (peek_char
== '\'') ? P_ALLOWESC
: 0);
4828 pop_delimiter (dstack
);
4829 if (ttok
== &matched_pair_error
)
4831 if (peek_char
== '\'')
4833 ttrans
= ansiexpand (ttok
, 0, ttoklen
- 1, &ttranslen
);
4836 /* Insert the single quotes and correctly quote any
4837 embedded single quotes (allowed because P_ALLOWESC was
4838 passed to parse_matched_pair). */
4839 ttok
= sh_single_quote (ttrans
);
4841 ttranslen
= strlen (ttok
);
4846 /* Try to locale-expand the converted string. */
4847 ttrans
= localeexpand (ttok
, 0, ttoklen
- 1, first_line
, &ttranslen
);
4850 /* Add the double quotes back */
4851 ttok
= sh_mkdoublequoted (ttrans
, ttranslen
, 0);
4857 RESIZE_MALLOCED_BUFFER (token
, token_index
, ttranslen
+ 2,
4859 TOKEN_DEFAULT_GROW_SIZE
);
4860 strcpy (token
+ token_index
, ttrans
);
4861 token_index
+= ttranslen
;
4864 all_digit_token
= 0;
4865 goto next_character
;
4867 /* This could eventually be extended to recognize all of the
4868 shell's single-character parameter expansions, and set flags.*/
4869 else if MBTEST(character
== '$' && peek_char
== '$')
4871 ttok
= (char *)xmalloc (3);
4872 ttok
[0] = ttok
[1] = '$';
4874 RESIZE_MALLOCED_BUFFER (token
, token_index
, 3,
4876 TOKEN_DEFAULT_GROW_SIZE
);
4877 strcpy (token
+ token_index
, ttok
);
4880 all_digit_token
= 0;
4882 goto next_character
;
4885 shell_ungetc (peek_char
);
4888 #if defined (ARRAY_VARS)
4889 /* Identify possible array subscript assignment; match [...] */
4890 else if MBTEST(character
== '[' && token_index
> 0 && assignment_acceptable (last_read_token
) && token_is_ident (token
, token_index
)) /* ] */
4892 ttok
= parse_matched_pair (cd
, '[', ']', &ttoklen
, 0);
4893 if (ttok
== &matched_pair_error
)
4894 return -1; /* Bail immediately. */
4895 RESIZE_MALLOCED_BUFFER (token
, token_index
, ttoklen
+ 2,
4897 TOKEN_DEFAULT_GROW_SIZE
);
4898 token
[token_index
++] = character
;
4899 strcpy (token
+ token_index
, ttok
);
4900 token_index
+= ttoklen
;
4902 all_digit_token
= 0;
4903 goto next_character
;
4905 /* Identify possible compound array variable assignment. */
4906 else if MBTEST(character
== '=' && token_index
> 0 && (assignment_acceptable (last_read_token
) || (parser_state
& PST_ASSIGNOK
)) && token_is_assignment (token
, token_index
))
4908 peek_char
= shell_getc (1);
4909 if MBTEST(peek_char
== '(') /* ) */
4911 ttok
= parse_compound_assignment (&ttoklen
);
4913 RESIZE_MALLOCED_BUFFER (token
, token_index
, ttoklen
+ 4,
4915 TOKEN_DEFAULT_GROW_SIZE
);
4917 token
[token_index
++] = '=';
4918 token
[token_index
++] = '(';
4921 strcpy (token
+ token_index
, ttok
);
4922 token_index
+= ttoklen
;
4924 token
[token_index
++] = ')';
4926 all_digit_token
= 0;
4927 compound_assignment
= 1;
4929 goto next_character
;
4931 goto got_token
; /* ksh93 seems to do this */
4935 shell_ungetc (peek_char
);
4939 /* When not parsing a multi-character word construct, shell meta-
4940 characters break words. */
4941 if MBTEST(shellbreak (character
))
4943 shell_ungetc (character
);
4949 all_digit_token
&= DIGIT (character
);
4950 dollar_present
|= character
== '$';
4952 if (character
== CTLESC
|| character
== CTLNUL
)
4953 token
[token_index
++] = CTLESC
;
4955 token
[token_index
++] = character
;
4957 RESIZE_MALLOCED_BUFFER (token
, token_index
, 1, token_buffer_size
,
4958 TOKEN_DEFAULT_GROW_SIZE
);
4961 if (character
== '\n' && SHOULD_PROMPT ())
4964 /* We want to remove quoted newlines (that is, a \<newline> pair)
4965 unless we are within single quotes or pass_next_character is
4966 set (the shell equivalent of literal-next). */
4967 cd
= current_delimiter (dstack
);
4968 character
= shell_getc (cd
!= '\'' && pass_next_character
== 0);
4969 } /* end for (;;) */
4973 token
[token_index
] = '\0';
4975 /* Check to see what thing we should return. If the last_read_token
4976 is a `<', or a `&', or the character which ended this token is
4977 a '>' or '<', then, and ONLY then, is this input token a NUMBER.
4978 Otherwise, it is just a word, and should be returned as such. */
4979 if MBTEST(all_digit_token
&& (character
== '<' || character
== '>' || \
4980 last_read_token
== LESS_AND
|| \
4981 last_read_token
== GREATER_AND
))
4983 if (legal_number (token
, &lvalue
) && (int)lvalue
== lvalue
)
4984 yylval
.number
= lvalue
;
4990 /* Check for special case tokens. */
4991 result
= (last_shell_getc_is_singlebyte
) ? special_case_tokens (token
) : -1;
4996 /* Posix.2 does not allow reserved words to be aliased, so check for all
4997 of them, including special cases, before expanding the current token
4999 if MBTEST(posixly_correct
)
5000 CHECK_FOR_RESERVED_WORD (token
);
5002 /* Aliases are expanded iff EXPAND_ALIASES is non-zero, and quoting
5003 inhibits alias expansion. */
5004 if (expand_aliases
&& quoted
== 0)
5006 result
= alias_expand_token (token
);
5007 if (result
== RE_READ_TOKEN
)
5008 return (RE_READ_TOKEN
);
5009 else if (result
== NO_EXPANSION
)
5010 parser_state
&= ~PST_ALEXPNEXT
;
5013 /* If not in Posix.2 mode, check for reserved words after alias
5015 if MBTEST(posixly_correct
== 0)
5017 CHECK_FOR_RESERVED_WORD (token
);
5019 the_word
= (WORD_DESC
*)xmalloc (sizeof (WORD_DESC
));
5020 the_word
->word
= (char *)xmalloc (1 + token_index
);
5021 the_word
->flags
= 0;
5022 strcpy (the_word
->word
, token
);
5024 the_word
->flags
|= W_HASDOLLAR
;
5026 the_word
->flags
|= W_QUOTED
; /*(*/
5027 if (compound_assignment
&& token
[token_index
-1] == ')')
5028 the_word
->flags
|= W_COMPASSIGN
;
5029 /* A word is an assignment if it appears at the beginning of a
5030 simple command, or after another assignment word. This is
5031 context-dependent, so it cannot be handled in the grammar. */
5032 if (assignment (token
, (parser_state
& PST_COMPASSIGN
) != 0))
5034 the_word
->flags
|= W_ASSIGNMENT
;
5035 /* Don't perform word splitting on assignment statements. */
5036 if (assignment_acceptable (last_read_token
) || (parser_state
& PST_COMPASSIGN
) != 0)
5037 the_word
->flags
|= W_NOSPLIT
;
5040 if (command_token_position (last_read_token
))
5043 b
= builtin_address_internal (token
, 0);
5044 if (b
&& (b
->flags
& ASSIGNMENT_BUILTIN
))
5045 parser_state
|= PST_ASSIGNOK
;
5046 else if (STREQ (token
, "eval") || STREQ (token
, "let"))
5047 parser_state
|= PST_ASSIGNOK
;
5050 yylval
.word
= the_word
;
5052 result
= ((the_word
->flags
& (W_ASSIGNMENT
|W_NOSPLIT
)) == (W_ASSIGNMENT
|W_NOSPLIT
))
5053 ? ASSIGNMENT_WORD
: WORD
;
5055 switch (last_read_token
)
5058 parser_state
|= PST_ALLOWOPNBRC
;
5059 function_dstart
= line_number
;
5064 if (word_top
< MAX_CASE_NEST
)
5066 word_lineno
[word_top
] = line_number
;
5073 /* Return 1 if TOKSYM is a token that after being read would allow
5074 a reserved word to be seen, else 0. */
5076 reserved_word_acceptable (toksym
)
5112 /* Return the index of TOKEN in the alist of reserved words, or -1 if
5113 TOKEN is not a shell reserved word. */
5115 find_reserved_word (tokstr
)
5119 for (i
= 0; word_token_alist
[i
].word
; i
++)
5120 if (STREQ (tokstr
, word_token_alist
[i
].word
))
5126 #if defined (READLINE)
5127 /* Called after each time readline is called. This insures that whatever
5128 the new prompt string is gets propagated to readline's local prompt
5131 reset_readline_prompt ()
5135 if (prompt_string_pointer
)
5137 temp_prompt
= (*prompt_string_pointer
)
5138 ? decode_prompt_string (*prompt_string_pointer
)
5141 if (temp_prompt
== 0)
5143 temp_prompt
= (char *)xmalloc (1);
5144 temp_prompt
[0] = '\0';
5147 FREE (current_readline_prompt
);
5148 current_readline_prompt
= temp_prompt
;
5151 #endif /* READLINE */
5154 #if defined (HISTORY)
5155 /* A list of tokens which can be followed by newlines, but not by
5156 semi-colons. When concatenating multiple lines of history, the
5157 newline separator for such tokens is replaced with a space. */
5158 static int no_semi_successors
[] = {
5159 '\n', '{', '(', ')', ';', '&', '|',
5160 CASE
, DO
, ELSE
, IF
, SEMI_SEMI
, THEN
, UNTIL
, WHILE
, AND_AND
, OR_OR
, IN
,
5164 /* If we are not within a delimited expression, try to be smart
5165 about which separators can be semi-colons and which must be
5166 newlines. Returns the string that should be added into the
5169 history_delimiting_chars ()
5173 if (dstack
.delimiter_depth
!= 0)
5176 /* First, handle some special cases. */
5178 /* If we just read `()', assume it's a function definition, and don't
5179 add a semicolon. If the token before the `)' was not `(', and we're
5180 not in the midst of parsing a case statement, assume it's a
5181 parenthesized command and add the semicolon. */
5183 if (token_before_that
== ')')
5185 if (two_tokens_ago
== '(') /*)*/ /* function def */
5187 /* This does not work for subshells inside case statement
5188 command lists. It's a suboptimal solution. */
5189 else if (parser_state
& PST_CASESTMT
) /* case statement pattern */
5192 return "; "; /* (...) subshell */
5194 else if (token_before_that
== WORD
&& two_tokens_ago
== FUNCTION
)
5195 return " "; /* function def using `function name' without `()' */
5197 else if (token_before_that
== WORD
&& two_tokens_ago
== FOR
)
5199 /* Tricky. `for i\nin ...' should not have a semicolon, but
5200 `for i\ndo ...' should. We do what we can. */
5201 for (i
= shell_input_line_index
; whitespace(shell_input_line
[i
]); i
++)
5203 if (shell_input_line
[i
] && shell_input_line
[i
] == 'i' && shell_input_line
[i
+1] == 'n')
5207 else if (two_tokens_ago
== CASE
&& token_before_that
== WORD
&& (parser_state
& PST_CASESTMT
))
5210 for (i
= 0; no_semi_successors
[i
]; i
++)
5212 if (token_before_that
== no_semi_successors
[i
])
5218 #endif /* HISTORY */
5220 /* Issue a prompt, or prepare to issue a prompt when the next character
5227 if (interactive
== 0 || expanding_alias()) /* XXX */
5230 ps1_prompt
= get_string_value ("PS1");
5231 ps2_prompt
= get_string_value ("PS2");
5233 if (!prompt_string_pointer
)
5234 prompt_string_pointer
= &ps1_prompt
;
5236 temp_prompt
= *prompt_string_pointer
5237 ? decode_prompt_string (*prompt_string_pointer
)
5240 if (temp_prompt
== 0)
5242 temp_prompt
= (char *)xmalloc (1);
5243 temp_prompt
[0] = '\0';
5246 current_prompt_string
= *prompt_string_pointer
;
5247 prompt_string_pointer
= &ps2_prompt
;
5249 #if defined (READLINE)
5250 if (!no_line_editing
)
5252 FREE (current_readline_prompt
);
5253 current_readline_prompt
= temp_prompt
;
5256 #endif /* READLINE */
5258 FREE (current_decoded_prompt
);
5259 current_decoded_prompt
= temp_prompt
;
5264 get_current_prompt_level ()
5266 return ((current_prompt_string
&& current_prompt_string
== ps2_prompt
) ? 2 : 1);
5270 set_current_prompt_level (x
)
5273 prompt_string_pointer
= (x
== 2) ? &ps2_prompt
: &ps1_prompt
;
5274 current_prompt_string
= *prompt_string_pointer
;
5280 fprintf (stderr
, "%s", current_decoded_prompt
);
5284 /* Return a string which will be printed as a prompt. The string
5285 may contain special characters which are decoded as follows:
5288 \d the date in Day Mon Date format
5289 \e escape (ascii 033)
5290 \h the hostname up to the first `.'
5292 \j the number of active jobs
5293 \l the basename of the shell's tty device name
5296 \s the name of the shell
5297 \t the time in 24-hour hh:mm:ss format
5298 \T the time in 12-hour hh:mm:ss format
5299 \@ the time in 12-hour hh:mm am/pm format
5300 \A the time in 24-hour hh:mm format
5301 \D{fmt} the result of passing FMT to strftime(3)
5303 \v the version of bash (e.g., 2.00)
5304 \V the release of bash, version + patchlevel (e.g., 2.00.0)
5305 \w the current working directory
5306 \W the last element of $PWD
5307 \! the history number of this command
5308 \# the command number of this command
5309 \$ a $ or a # if you are root
5310 \nnn character code nnn in octal
5312 \[ begin a sequence of non-printing chars
5313 \] end a sequence of non-printing chars
5315 #define PROMPT_GROWTH 48
5317 decode_prompt_string (string
)
5322 struct dstack save_dstack
;
5323 int last_exit_value
;
5324 #if defined (PROMPT_STRING_DECODE)
5325 int result_size
, result_index
;
5327 char *temp
, octal_string
[4];
5333 result
= (char *)xmalloc (result_size
= PROMPT_GROWTH
);
5334 result
[result_index
= 0] = 0;
5335 temp
= (char *)NULL
;
5337 while (c
= *string
++)
5339 if (posixly_correct
&& c
== '!')
5343 temp
= savestring ("!");
5348 #if !defined (HISTORY)
5349 temp
= savestring ("1");
5351 temp
= itos (history_number ());
5352 #endif /* HISTORY */
5353 string
--; /* add_string increments string again. */
5371 strncpy (octal_string
, string
, 3);
5372 octal_string
[3] = '\0';
5374 n
= read_octal (octal_string
);
5375 temp
= (char *)xmalloc (3);
5377 if (n
== CTLESC
|| n
== CTLNUL
)
5394 for (c
= 0; n
!= -1 && c
< 3 && ISOCTAL (*string
); c
++)
5397 c
= 0; /* tested at add_string: */
5405 /* Make the current time/date into a string. */
5406 (void) time (&the_time
);
5407 tm
= localtime (&the_time
);
5410 n
= strftime (timebuf
, sizeof (timebuf
), "%a %b %d", tm
);
5412 n
= strftime (timebuf
, sizeof (timebuf
), "%H:%M:%S", tm
);
5414 n
= strftime (timebuf
, sizeof (timebuf
), "%I:%M:%S", tm
);
5416 n
= strftime (timebuf
, sizeof (timebuf
), "%I:%M %p", tm
);
5418 n
= strftime (timebuf
, sizeof (timebuf
), "%H:%M", tm
);
5423 timebuf
[sizeof(timebuf
) - 1] = '\0';
5425 temp
= savestring (timebuf
);
5428 case 'D': /* strftime format */
5429 if (string
[1] != '{') /* } */
5432 (void) time (&the_time
);
5433 tm
= localtime (&the_time
);
5434 string
+= 2; /* skip { */
5435 timefmt
= xmalloc (strlen (string
) + 3);
5436 for (t
= timefmt
; *string
&& *string
!= '}'; )
5439 c
= *string
; /* tested at add_string */
5440 if (timefmt
[0] == '\0')
5443 timefmt
[1] = 'X'; /* locale-specific current time */
5446 n
= strftime (timebuf
, sizeof (timebuf
), timefmt
, tm
);
5452 timebuf
[sizeof(timebuf
) - 1] = '\0';
5454 if (promptvars
|| posixly_correct
)
5455 /* Make sure that expand_prompt_string is called with a
5456 second argument of Q_DOUBLE_QUOTES if we use this
5458 temp
= sh_backslash_quote_for_double_quotes (timebuf
);
5460 temp
= savestring (timebuf
);
5464 temp
= (char *)xmalloc (3);
5465 temp
[0] = no_line_editing
? '\n' : '\r';
5466 temp
[1] = no_line_editing
? '\0' : '\n';
5471 temp
= base_pathname (shell_name
);
5472 temp
= savestring (temp
);
5477 temp
= (char *)xmalloc (16);
5479 strcpy (temp
, dist_version
);
5481 sprintf (temp
, "%s.%d", dist_version
, patch_level
);
5487 /* Use the value of PWD because it is much more efficient. */
5488 char t_string
[PATH_MAX
];
5491 temp
= get_string_value ("PWD");
5495 if (getcwd (t_string
, sizeof(t_string
)) == 0)
5501 tlen
= strlen (t_string
);
5505 tlen
= sizeof (t_string
) - 1;
5506 strncpy (t_string
, temp
, tlen
);
5508 t_string
[tlen
] = '\0';
5510 #define ROOT_PATH(x) ((x)[0] == '/' && (x)[1] == 0)
5511 #define DOUBLE_SLASH_ROOT(x) ((x)[0] == '/' && (x)[1] == '/' && (x)[2] == 0)
5512 /* Abbreviate \W as ~ if $PWD == $HOME */
5513 if (c
== 'W' && (((t
= get_string_value ("HOME")) == 0) || STREQ (t
, t_string
) == 0))
5515 if (ROOT_PATH (t_string
) == 0 && DOUBLE_SLASH_ROOT (t_string
) == 0)
5517 t
= strrchr (t_string
, '/');
5519 strcpy (t_string
, t
+ 1);
5523 #undef DOUBLE_SLASH_ROOT
5525 /* polite_directory_format is guaranteed to return a string
5526 no longer than PATH_MAX - 1 characters. */
5527 strcpy (t_string
, polite_directory_format (t_string
));
5529 /* If we're going to be expanding the prompt string later,
5530 quote the directory name. */
5531 if (promptvars
|| posixly_correct
)
5532 /* Make sure that expand_prompt_string is called with a
5533 second argument of Q_DOUBLE_QUOTES if we use this
5535 temp
= sh_backslash_quote_for_double_quotes (t_string
);
5537 temp
= savestring (t_string
);
5543 if (current_user
.user_name
== 0)
5544 get_current_user_info ();
5545 temp
= savestring (current_user
.user_name
);
5550 temp
= savestring (current_host_name
);
5551 if (c
== 'h' && (t
= (char *)strchr (temp
, '.')))
5556 temp
= itos (current_command_number
);
5560 #if !defined (HISTORY)
5561 temp
= savestring ("1");
5563 temp
= itos (history_number ());
5564 #endif /* HISTORY */
5568 t
= temp
= (char *)xmalloc (3);
5569 if ((promptvars
|| posixly_correct
) && (current_user
.euid
!= 0))
5571 *t
++ = current_user
.euid
== 0 ? '#' : '$';
5576 temp
= itos (count_all_jobs ());
5580 #if defined (HAVE_TTYNAME)
5581 temp
= (char *)ttyname (fileno (stdin
));
5582 t
= temp
? base_pathname (temp
) : "tty";
5583 temp
= savestring (t
);
5585 temp
= savestring ("tty");
5586 #endif /* !HAVE_TTYNAME */
5589 #if defined (READLINE)
5592 if (no_line_editing
)
5597 temp
= (char *)xmalloc (3);
5598 n
= (c
== '[') ? RL_PROMPT_START_IGNORE
: RL_PROMPT_END_IGNORE
;
5600 if (n
== CTLESC
|| n
== CTLNUL
)
5605 #endif /* READLINE */
5611 temp
= (char *)xmalloc (2);
5618 else /* (c == '\\') */
5625 temp
= (char *)xmalloc (3);
5634 sub_append_string (temp
, result
, &result_index
, &result_size
);
5635 temp
= (char *)NULL
; /* Freed in sub_append_string (). */
5636 result
[result_index
] = '\0';
5642 RESIZE_MALLOCED_BUFFER (result
, result_index
, 3, result_size
, PROMPT_GROWTH
);
5643 result
[result_index
++] = c
;
5644 result
[result_index
] = '\0';
5647 #else /* !PROMPT_STRING_DECODE */
5648 result
= savestring (string
);
5649 #endif /* !PROMPT_STRING_DECODE */
5651 /* Save the delimiter stack and point `dstack' to temp space so any
5652 command substitutions in the prompt string won't result in screwing
5653 up the parser's quoting state. */
5654 save_dstack
= dstack
;
5655 dstack
= temp_dstack
;
5656 dstack
.delimiter_depth
= 0;
5658 /* Perform variable and parameter expansion and command substitution on
5659 the prompt string. */
5660 if (promptvars
|| posixly_correct
)
5662 last_exit_value
= last_command_exit_value
;
5663 list
= expand_prompt_string (result
, Q_DOUBLE_QUOTES
);
5665 result
= string_list (list
);
5666 dispose_words (list
);
5667 last_command_exit_value
= last_exit_value
;
5671 t
= dequote_string (result
);
5676 dstack
= save_dstack
;
5681 /************************************************
5685 ************************************************/
5687 /* Report a syntax error, and restart the parser. Call here for fatal
5693 report_syntax_error ((char *)NULL
);
5699 error_token_from_token (tok
)
5704 if (t
= find_token_in_alist (tok
, word_token_alist
, 0))
5707 if (t
= find_token_in_alist (tok
, other_token_alist
, 0))
5711 /* This stuff is dicy and needs closer inspection */
5712 switch (current_token
)
5715 case ASSIGNMENT_WORD
:
5717 t
= savestring (yylval
.word
->word
);
5720 t
= itos (yylval
.number
);
5723 if (yylval
.word_list
)
5724 t
= string_list (yylval
.word_list
);
5726 case ARITH_FOR_EXPRS
:
5727 if (yylval
.word_list
)
5728 t
= string_list_internal (yylval
.word_list
, " ; ");
5731 t
= (char *)NULL
; /* punt */
5739 error_token_from_text ()
5744 t
= shell_input_line
;
5745 i
= shell_input_line_index
;
5749 if (i
&& t
[i
] == '\0')
5752 while (i
&& (whitespace (t
[i
]) || t
[i
] == '\n'))
5758 while (i
&& (member (t
[i
], " \n\t;|&") == 0))
5761 while (i
!= token_end
&& (whitespace (t
[i
]) || t
[i
] == '\n'))
5764 /* Return our idea of the offending token. */
5765 if (token_end
|| (i
== 0 && token_end
== 0))
5768 msg
= substring (t
, i
, token_end
);
5769 else /* one-character token */
5771 msg
= (char *)xmalloc (2);
5781 print_offending_line ()
5786 msg
= savestring (shell_input_line
);
5787 token_end
= strlen (msg
);
5788 while (token_end
&& msg
[token_end
- 1] == '\n')
5789 msg
[--token_end
] = '\0';
5791 parser_error (line_number
, "`%s'", msg
);
5795 /* Report a syntax error with line numbers, etc.
5796 Call here for recoverable errors. If you have a message to print,
5797 then place it in MESSAGE, otherwise pass NULL and this will figure
5798 out an appropriate message for you. */
5800 report_syntax_error (message
)
5807 parser_error (line_number
, "%s", message
);
5808 if (interactive
&& EOF_Reached
)
5810 last_command_exit_value
= EX_USAGE
;
5814 /* If the line of input we're reading is not null, try to find the
5815 objectionable token. First, try to figure out what token the
5816 parser's complaining about by looking at current_token. */
5817 if (current_token
!= 0 && EOF_Reached
== 0 && (msg
= error_token_from_token (current_token
)))
5819 parser_error (line_number
, _("syntax error near unexpected token `%s'"), msg
);
5822 if (interactive
== 0)
5823 print_offending_line ();
5825 last_command_exit_value
= EX_USAGE
;
5829 /* If looking at the current token doesn't prove fruitful, try to find the
5830 offending token by analyzing the text of the input line near the current
5831 input line index and report what we find. */
5832 if (shell_input_line
&& *shell_input_line
)
5834 msg
= error_token_from_text ();
5837 parser_error (line_number
, _("syntax error near `%s'"), msg
);
5841 /* If not interactive, print the line containing the error. */
5842 if (interactive
== 0)
5843 print_offending_line ();
5847 msg
= EOF_Reached
? _("syntax error: unexpected end of file") : _("syntax error");
5848 parser_error (line_number
, "%s", msg
);
5849 /* When the shell is interactive, this file uses EOF_Reached
5850 only for error reporting. Other mechanisms are used to
5851 decide whether or not to exit. */
5852 if (interactive
&& EOF_Reached
)
5856 last_command_exit_value
= EX_USAGE
;
5859 /* ??? Needed function. ??? We have to be able to discard the constructs
5860 created during parsing. In the case of error, we want to return
5861 allocated objects to the memory pool. In the case of no error, we want
5862 to throw away the information about where the allocated objects live.
5863 (dispose_command () will actually free the command.) */
5865 discard_parser_constructs (error_p
)
5870 /************************************************
5874 ************************************************/
5876 /* Do that silly `type "bye" to exit' stuff. You know, "ignoreeof". */
5878 /* A flag denoting whether or not ignoreeof is set. */
5881 /* The number of times that we have encountered an EOF character without
5882 another character intervening. When this gets above the limit, the
5883 shell terminates. */
5884 int eof_encountered
= 0;
5886 /* The limit for eof_encountered. */
5887 int eof_encountered_limit
= 10;
5889 /* If we have EOF as the only input unit, this user wants to leave
5890 the shell. If the shell is not interactive, then just leave.
5891 Otherwise, if ignoreeof is set, and we haven't done this the
5892 required number of times in a row, print a message. */
5894 handle_eof_input_unit ()
5898 /* shell.c may use this to decide whether or not to write out the
5899 history, among other things. We use it only for error reporting
5904 /* If the user wants to "ignore" eof, then let her do so, kind of. */
5907 if (eof_encountered
< eof_encountered_limit
)
5909 fprintf (stderr
, _("Use \"%s\" to leave the shell.\n"),
5910 login_shell
? "logout" : "exit");
5912 /* Reset the parsing state. */
5913 last_read_token
= current_token
= '\n';
5914 /* Reset the prompt string to be $PS1. */
5915 prompt_string_pointer
= (char **)NULL
;
5921 /* In this case EOF should exit the shell. Do it now. */
5923 exit_builtin ((WORD_LIST
*)NULL
);
5927 /* We don't write history files, etc., for non-interactive shells. */
5932 /************************************************
5934 * STRING PARSING FUNCTIONS *
5936 ************************************************/
5938 /* It's very important that these two functions treat the characters
5939 between ( and ) identically. */
5941 static WORD_LIST parse_string_error
;
5943 /* Take a string and run it through the shell parser, returning the
5944 resultant word list. Used by compound array assignment. */
5946 parse_string_to_word_list (s
, flags
, whom
)
5952 int tok
, orig_current_token
, orig_line_number
, orig_input_terminator
;
5953 int orig_line_count
;
5954 int old_echo_input
, old_expand_aliases
;
5955 #if defined (HISTORY)
5956 int old_remember_on_history
, old_history_expansion_inhibited
;
5959 #if defined (HISTORY)
5960 old_remember_on_history
= remember_on_history
;
5961 # if defined (BANG_HISTORY)
5962 old_history_expansion_inhibited
= history_expansion_inhibited
;
5964 bash_history_disable ();
5967 orig_line_number
= line_number
;
5968 orig_line_count
= current_command_line_count
;
5969 orig_input_terminator
= shell_input_line_terminator
;
5970 old_echo_input
= echo_input_at_read
;
5971 old_expand_aliases
= expand_aliases
;
5974 last_read_token
= WORD
; /* WORD to allow reserved words here */
5975 current_command_line_count
= 0;
5976 echo_input_at_read
= expand_aliases
= 0;
5978 with_input_from_string (s
, whom
);
5979 wl
= (WORD_LIST
*)NULL
;
5982 parser_state
|= PST_COMPASSIGN
;
5984 while ((tok
= read_token (READ
)) != yacc_EOF
)
5986 if (tok
== '\n' && *bash_input
.location
.string
== '\0')
5988 if (tok
== '\n') /* Allow newlines in compound assignments */
5990 if (tok
!= WORD
&& tok
!= ASSIGNMENT_WORD
)
5992 line_number
= orig_line_number
+ line_number
- 1;
5993 orig_current_token
= current_token
;
5994 current_token
= tok
;
5995 yyerror (NULL
); /* does the right thing */
5996 current_token
= orig_current_token
;
5999 wl
= &parse_string_error
;
6002 wl
= make_word_list (yylval
.word
, wl
);
6005 last_read_token
= '\n';
6008 #if defined (HISTORY)
6009 remember_on_history
= old_remember_on_history
;
6010 # if defined (BANG_HISTORY)
6011 history_expansion_inhibited
= old_history_expansion_inhibited
;
6012 # endif /* BANG_HISTORY */
6013 #endif /* HISTORY */
6015 echo_input_at_read
= old_echo_input
;
6016 expand_aliases
= old_expand_aliases
;
6018 current_command_line_count
= orig_line_count
;
6019 shell_input_line_terminator
= orig_input_terminator
;
6022 parser_state
&= ~PST_COMPASSIGN
;
6024 if (wl
== &parse_string_error
)
6026 last_command_exit_value
= EXECUTION_FAILURE
;
6027 if (interactive_shell
== 0 && posixly_correct
)
6028 jump_to_top_level (FORCE_EOF
);
6030 jump_to_top_level (DISCARD
);
6033 return (REVERSE_LIST (wl
, WORD_LIST
*));
6037 parse_compound_assignment (retlenp
)
6041 int tok
, orig_line_number
, orig_token_size
, orig_last_token
, assignok
;
6042 char *saved_token
, *ret
;
6044 saved_token
= token
;
6045 orig_token_size
= token_buffer_size
;
6046 orig_line_number
= line_number
;
6047 orig_last_token
= last_read_token
;
6049 last_read_token
= WORD
; /* WORD to allow reserved words here */
6051 token
= (char *)NULL
;
6052 token_buffer_size
= 0;
6054 assignok
= parser_state
&PST_ASSIGNOK
; /* XXX */
6056 wl
= (WORD_LIST
*)NULL
; /* ( */
6057 parser_state
|= PST_COMPASSIGN
;
6059 while ((tok
= read_token (READ
)) != ')')
6061 if (tok
== '\n') /* Allow newlines in compound assignments */
6063 if (SHOULD_PROMPT ())
6067 if (tok
!= WORD
&& tok
!= ASSIGNMENT_WORD
)
6069 current_token
= tok
; /* for error reporting */
6070 if (tok
== yacc_EOF
) /* ( */
6071 parser_error (orig_line_number
, _("unexpected EOF while looking for matching `)'"));
6073 yyerror(NULL
); /* does the right thing */
6076 wl
= &parse_string_error
;
6079 wl
= make_word_list (yylval
.word
, wl
);
6083 token
= saved_token
;
6084 token_buffer_size
= orig_token_size
;
6086 parser_state
&= ~PST_COMPASSIGN
;
6088 if (wl
== &parse_string_error
)
6090 last_command_exit_value
= EXECUTION_FAILURE
;
6091 last_read_token
= '\n'; /* XXX */
6092 if (interactive_shell
== 0 && posixly_correct
)
6093 jump_to_top_level (FORCE_EOF
);
6095 jump_to_top_level (DISCARD
);
6098 last_read_token
= orig_last_token
; /* XXX - was WORD? */
6102 rl
= REVERSE_LIST (wl
, WORD_LIST
*);
6103 ret
= string_list (rl
);
6110 *retlenp
= (ret
&& *ret
) ? strlen (ret
) : 0;
6113 parser_state
|= PST_ASSIGNOK
;
6118 /************************************************
6120 * SAVING AND RESTORING PARTIAL PARSE STATE *
6122 ************************************************/
6125 save_parser_state (ps
)
6126 sh_parser_state_t
*ps
;
6128 #if defined (ARRAY_VARS)
6133 ps
= (sh_parser_state_t
*)xmalloc (sizeof (sh_parser_state_t
));
6135 return ((sh_parser_state_t
*)NULL
);
6137 ps
->parser_state
= parser_state
;
6138 ps
->token_state
= save_token_state ();
6140 ps
->input_line_terminator
= shell_input_line_terminator
;
6141 ps
->eof_encountered
= eof_encountered
;
6143 ps
->current_command_line_count
= current_command_line_count
;
6145 #if defined (HISTORY)
6146 ps
->remember_on_history
= remember_on_history
;
6147 # if defined (BANG_HISTORY)
6148 ps
->history_expansion_inhibited
= history_expansion_inhibited
;
6152 ps
->last_command_exit_value
= last_command_exit_value
;
6153 #if defined (ARRAY_VARS)
6154 v
= find_variable ("PIPESTATUS");
6155 if (v
&& array_p (v
) && array_cell (v
))
6156 ps
->pipestatus
= array_copy (array_cell (v
));
6158 ps
->pipestatus
= (ARRAY
*)NULL
;
6161 ps
->last_shell_builtin
= last_shell_builtin
;
6162 ps
->this_shell_builtin
= this_shell_builtin
;
6164 ps
->expand_aliases
= expand_aliases
;
6165 ps
->echo_input_at_read
= echo_input_at_read
;
6171 restore_parser_state (ps
)
6172 sh_parser_state_t
*ps
;
6174 #if defined (ARRAY_VARS)
6181 parser_state
= ps
->parser_state
;
6182 if (ps
->token_state
)
6184 restore_token_state (ps
->token_state
);
6185 free (ps
->token_state
);
6188 shell_input_line_terminator
= ps
->input_line_terminator
;
6189 eof_encountered
= ps
->eof_encountered
;
6191 current_command_line_count
= ps
->current_command_line_count
;
6193 #if defined (HISTORY)
6194 remember_on_history
= ps
->remember_on_history
;
6195 # if defined (BANG_HISTORY)
6196 history_expansion_inhibited
= ps
->history_expansion_inhibited
;
6200 last_command_exit_value
= ps
->last_command_exit_value
;
6201 #if defined (ARRAY_VARS)
6202 v
= find_variable ("PIPESTATUS");
6203 if (v
&& array_p (v
) && array_cell (v
))
6205 array_dispose (array_cell (v
));
6206 var_setarray (v
, ps
->pipestatus
);
6210 last_shell_builtin
= ps
->last_shell_builtin
;
6211 this_shell_builtin
= ps
->this_shell_builtin
;
6213 expand_aliases
= ps
->expand_aliases
;
6214 echo_input_at_read
= ps
->echo_input_at_read
;
6217 /************************************************
6219 * MULTIBYTE CHARACTER HANDLING *
6221 ************************************************/
6223 #if defined (HANDLE_MULTIBYTE)
6227 int i
, previ
, len
, c
;
6228 mbstate_t mbs
, prevs
;
6231 if (shell_input_line
== NULL
)
6233 len
= strlen (shell_input_line
); /* XXX - shell_input_line_len ? */
6234 FREE (shell_input_line_property
);
6235 shell_input_line_property
= (char *)xmalloc (len
+ 1);
6237 memset (&prevs
, '\0', sizeof (mbstate_t));
6238 for (i
= previ
= 0; i
< len
; i
++)
6242 c
= shell_input_line
[i
];
6246 for (j
= i
; j
< len
; j
++)
6247 shell_input_line_property
[j
] = 1;
6251 mbclen
= mbrlen (shell_input_line
+ previ
, i
- previ
+ 1, &mbs
);
6252 if (mbclen
== 1 || mbclen
== (size_t)-1)
6257 else if (mbclen
== (size_t)-2)
6259 else if (mbclen
> 1)
6267 /* XXX - what to do if mbrlen returns 0? (null wide character) */
6269 for (j
= i
; j
< len
; j
++)
6270 shell_input_line_property
[j
] = 1;
6274 shell_input_line_property
[i
] = mbclen
;
6277 #endif /* HANDLE_MULTIBYTE */