2 /* A Bison parser, made from ./parse.y
3 by GNU Bison version 1.25
6 #define YYBISON 1 /* Identify Bison output. */
27 #define ASSIGNMENT_WORD 277
31 #define GREATER_GREATER 281
34 #define GREATER_AND 284
36 #define LESS_LESS_MINUS 286
37 #define AND_GREATER 287
38 #define LESS_GREATER 288
39 #define GREATER_BAR 289
46 #include "bashtypes.h"
49 #if defined (HAVE_UNISTD_H)
53 #if defined (HAVE_LOCALE_H)
66 #include "mailcheck.h"
67 #include "builtins/common.h"
68 #include "builtins/builtext.h"
70 #if defined (READLINE)
71 # include "bashline.h"
72 # include <readline/readline.h>
76 # include "bashhist.h"
77 # include <readline/history.h>
80 #if defined (JOB_CONTROL)
82 #endif /* JOB_CONTROL */
88 #if defined (PROMPT_STRING_DECODE)
89 #include <sys/param.h>
92 #endif /* PROMPT_STRING_DECODE */
94 #define RE_READ_TOKEN -99
95 #define NO_EXPANSION -100
99 extern int eof_encountered
;
100 extern int no_line_editing
, running_under_emacs
;
101 extern int current_command_number
;
102 extern int interactive
, interactive_shell
, login_shell
;
103 extern int sourcelevel
;
104 extern int posixly_correct
;
105 extern int last_command_exit_value
;
106 extern int interrupt_immediately
;
107 extern char *shell_name
, *current_host_name
;
108 extern char *dist_version
;
109 extern int patch_level
;
110 extern int dump_translatable_strings
;
111 extern Function
*last_shell_builtin
, *this_shell_builtin
;
112 #if defined (BUFFERED_INPUT)
113 extern int bash_input_fd_changed
;
116 /* **************************************************************** */
118 /* "Forward" declarations */
120 /* **************************************************************** */
122 static char *ansiexpand ();
123 static char *localeexpand ();
124 static int reserved_word_acceptable ();
125 static int read_token ();
127 static int read_token_word ();
128 static void discard_parser_constructs ();
130 static void report_syntax_error ();
131 static void handle_eof_input_unit ();
132 static void prompt_again ();
133 static void reset_readline_prompt ();
134 static void print_prompt ();
136 /* Default prompt strings */
137 char *primary_prompt
= PPROMPT
;
138 char *secondary_prompt
= SPROMPT
;
140 /* PROMPT_STRING_POINTER points to one of these, never to an actual string. */
141 char *ps1_prompt
, *ps2_prompt
;
143 /* Handle on the current prompt string. Indirectly points through
144 ps1_ or ps2_prompt. */
145 char **prompt_string_pointer
= (char **)NULL
;
146 char *current_prompt_string
;
148 /* Non-zero means we expand aliases in commands. */
149 int expand_aliases
= 0;
151 /* If non-zero, the decoded prompt string undergoes parameter and
152 variable substitution, command substitution, arithmetic substitution,
153 string expansion, process substitution, and quote removal in
154 decode_prompt_string. */
157 /* The decoded prompt string. Used if READLINE is not defined or if
158 editing is turned off. Analogous to current_readline_prompt. */
159 static char *current_decoded_prompt
;
161 /* The number of lines read from input while creating the current command. */
162 int current_command_line_count
;
164 /* Variables to manage the task of reading here documents, because we need to
165 defer the reading until after a complete command has been collected. */
166 static REDIRECT
*redir_stack
[10];
169 /* Where shell input comes from. History expansion is performed on each
170 line when the shell is interactive. */
171 static char *shell_input_line
= (char *)NULL
;
172 static int shell_input_line_index
;
173 static int shell_input_line_size
; /* Amount allocated for shell_input_line. */
174 static int shell_input_line_len
; /* strlen (shell_input_line) */
176 /* Either zero or EOF. */
177 static int shell_input_line_terminator
;
179 /* The line number in a script on which a function definition starts. */
180 static int function_dstart
;
182 /* The line number in a script on which a function body starts. */
183 static int function_bstart
;
185 static REDIRECTEE redir
;
187 #line 166 "./parse.y"
189 WORD_DESC
*word
; /* the word that we read. */
190 int number
; /* the number that we read. */
191 WORD_LIST
*word_list
;
195 PATTERN_LIST
*pattern
;
208 #define YYFLAG -32768
211 #define YYTRANSLATE(x) ((unsigned)(x) <= 290 ? yytranslate[x] : 78)
213 static const char yytranslate
[] = { 0,
214 2, 2, 2, 2, 2, 2, 2, 2, 2, 37,
215 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
216 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
217 2, 2, 2, 2, 2, 2, 2, 35, 2, 45,
218 46, 2, 2, 2, 42, 2, 2, 2, 2, 2,
219 2, 2, 2, 2, 2, 2, 2, 2, 36, 41,
220 2, 40, 2, 2, 2, 2, 2, 2, 2, 2,
221 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
222 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
223 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
224 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
225 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
226 2, 2, 43, 39, 44, 2, 2, 2, 2, 2,
227 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
228 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
229 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
230 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
231 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
232 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
233 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
234 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
235 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
236 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
237 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
238 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
239 2, 2, 2, 2, 2, 1, 2, 3, 4, 5,
240 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
241 16, 17, 18, 19, 20, 21, 22, 23, 24, 25,
242 26, 27, 28, 29, 30, 31, 32, 33, 34, 38
246 static const short yyprhs
[] = { 0,
247 0, 3, 5, 8, 10, 12, 15, 18, 21, 25,
248 29, 32, 36, 39, 43, 46, 50, 53, 57, 60,
249 64, 67, 71, 74, 78, 81, 85, 88, 92, 95,
250 99, 102, 105, 109, 111, 113, 115, 117, 120, 122,
251 125, 127, 129, 132, 134, 136, 142, 148, 150, 152,
252 154, 156, 158, 165, 172, 180, 188, 199, 210, 217,
253 224, 232, 240, 251, 262, 269, 277, 284, 290, 297,
254 302, 306, 312, 320, 327, 331, 336, 343, 349, 351,
255 354, 359, 364, 370, 376, 379, 383, 385, 389, 392,
256 394, 397, 401, 405, 409, 414, 419, 424, 429, 434,
257 436, 438, 440, 442, 443, 446, 448, 451, 454, 459,
258 464, 468, 472, 474, 476, 479, 482, 486, 490, 495,
262 static const short yyrhs
[] = { 73,
263 37, 0, 37, 0, 1, 37, 0, 38, 0, 21,
264 0, 48, 21, 0, 40, 21, 0, 41, 21, 0,
265 23, 40, 21, 0, 23, 41, 21, 0, 26, 21,
266 0, 23, 26, 21, 0, 27, 21, 0, 23, 27,
267 21, 0, 28, 23, 0, 23, 28, 23, 0, 29,
268 23, 0, 23, 29, 23, 0, 28, 21, 0, 23,
269 28, 21, 0, 29, 21, 0, 23, 29, 21, 0,
270 31, 21, 0, 23, 31, 21, 0, 29, 42, 0,
271 23, 29, 42, 0, 28, 42, 0, 23, 28, 42,
272 0, 32, 21, 0, 23, 33, 21, 0, 33, 21,
273 0, 34, 21, 0, 23, 34, 21, 0, 21, 0,
274 22, 0, 49, 0, 49, 0, 51, 49, 0, 50,
275 0, 52, 50, 0, 52, 0, 54, 0, 54, 51,
276 0, 55, 0, 57, 0, 12, 68, 14, 68, 15,
277 0, 13, 68, 14, 68, 15, 0, 56, 0, 60,
278 0, 59, 0, 61, 0, 58, 0, 10, 21, 72,
279 14, 67, 15, 0, 10, 21, 72, 43, 67, 44,
280 0, 10, 21, 36, 72, 14, 67, 15, 0, 10,
281 21, 36, 72, 43, 67, 44, 0, 10, 21, 72,
282 17, 48, 71, 72, 14, 67, 15, 0, 10, 21,
283 72, 17, 48, 71, 72, 43, 67, 44, 0, 11,
284 21, 72, 14, 67, 15, 0, 11, 21, 72, 43,
285 67, 44, 0, 11, 21, 36, 72, 14, 67, 15,
286 0, 11, 21, 36, 72, 43, 67, 44, 0, 11,
287 21, 72, 17, 48, 71, 72, 14, 67, 15, 0,
288 11, 21, 72, 17, 48, 71, 72, 43, 67, 44,
289 0, 8, 21, 72, 17, 72, 9, 0, 8, 21,
290 72, 17, 65, 72, 9, 0, 8, 21, 72, 17,
291 63, 9, 0, 21, 45, 46, 72, 61, 0, 16,
292 21, 45, 46, 72, 61, 0, 16, 21, 72, 61,
293 0, 45, 68, 46, 0, 3, 68, 4, 68, 7,
294 0, 3, 68, 4, 68, 5, 68, 7, 0, 3,
295 68, 4, 68, 62, 7, 0, 43, 67, 44, 0,
296 6, 68, 4, 68, 0, 6, 68, 4, 68, 5,
297 68, 0, 6, 68, 4, 68, 62, 0, 64, 0,
298 65, 64, 0, 72, 66, 46, 68, 0, 72, 66,
299 46, 72, 0, 72, 45, 66, 46, 68, 0, 72,
300 45, 66, 46, 72, 0, 64, 30, 0, 65, 64,
301 30, 0, 21, 0, 66, 39, 21, 0, 72, 69,
302 0, 67, 0, 72, 70, 0, 70, 37, 72, 0,
303 70, 35, 72, 0, 70, 36, 72, 0, 70, 24,
304 72, 70, 0, 70, 25, 72, 70, 0, 70, 35,
305 72, 70, 0, 70, 36, 72, 70, 0, 70, 37,
306 72, 70, 0, 75, 0, 37, 0, 36, 0, 38,
307 0, 0, 72, 37, 0, 74, 0, 74, 35, 0,
308 74, 36, 0, 74, 24, 72, 74, 0, 74, 25,
309 72, 74, 0, 74, 35, 74, 0, 74, 36, 74,
310 0, 75, 0, 76, 0, 18, 76, 0, 77, 76,
311 0, 77, 18, 76, 0, 18, 77, 76, 0, 76,
312 39, 72, 76, 0, 53, 0, 19, 0, 19, 20,
319 static const short yyrline
[] = { 0,
320 209, 218, 225, 240, 250, 252, 256, 261, 266, 271,
321 276, 281, 286, 292, 298, 303, 308, 313, 318, 323,
322 328, 333, 338, 345, 352, 357, 362, 367, 372, 377,
323 382, 387, 392, 399, 401, 403, 407, 411, 422, 424,
324 428, 430, 432, 461, 463, 465, 467, 469, 471, 473,
325 475, 477, 481, 483, 485, 487, 489, 491, 495, 499,
326 503, 507, 511, 515, 521, 523, 525, 529, 533, 536,
327 540, 544, 546, 548, 553, 557, 559, 561, 565, 566,
328 570, 572, 574, 576, 580, 581, 585, 587, 596, 604,
329 605, 611, 612, 619, 623, 625, 627, 634, 636, 638,
330 642, 643, 644, 647, 648, 657, 663, 672, 680, 682,
331 684, 691, 694, 698, 700, 705, 710, 715, 722, 725,
337 #if YYDEBUG != 0 || defined (YYERROR_VERBOSE)
339 static const char * const yytname
[] = { "$","error","$undefined.","IF","THEN",
340 "ELSE","ELIF","FI","CASE","ESAC","FOR","SELECT","WHILE","UNTIL","DO","DONE",
341 "FUNCTION","IN","BANG","TIME","TIMEOPT","WORD","ASSIGNMENT_WORD","NUMBER","AND_AND",
342 "OR_OR","GREATER_GREATER","LESS_LESS","LESS_AND","GREATER_AND","SEMI_SEMI","LESS_LESS_MINUS",
343 "AND_GREATER","LESS_GREATER","GREATER_BAR","'&'","';'","'\\n'","yacc_EOF","'|'",
344 "'>'","'<'","'-'","'{'","'}'","'('","')'","inputunit","word_list","redirection",
345 "simple_command_element","redirection_list","simple_command","command","shell_command",
346 "for_command","select_command","case_command","function_def","subshell","if_command",
347 "group_command","elif_clause","case_clause","pattern_list","case_clause_sequence",
348 "pattern","list","compound_list","list0","list1","list_terminator","newline_list",
349 "simple_list","simple_list1","pipeline_command","pipeline","timespec", NULL
353 static const short yyr1
[] = { 0,
354 47, 47, 47, 47, 48, 48, 49, 49, 49, 49,
355 49, 49, 49, 49, 49, 49, 49, 49, 49, 49,
356 49, 49, 49, 49, 49, 49, 49, 49, 49, 49,
357 49, 49, 49, 50, 50, 50, 51, 51, 52, 52,
358 53, 53, 53, 54, 54, 54, 54, 54, 54, 54,
359 54, 54, 55, 55, 55, 55, 55, 55, 56, 56,
360 56, 56, 56, 56, 57, 57, 57, 58, 58, 58,
361 59, 60, 60, 60, 61, 62, 62, 62, 63, 63,
362 64, 64, 64, 64, 65, 65, 66, 66, 67, 68,
363 68, 69, 69, 69, 70, 70, 70, 70, 70, 70,
364 71, 71, 71, 72, 72, 73, 73, 73, 74, 74,
365 74, 74, 74, 75, 75, 75, 75, 75, 76, 76,
369 static const short yyr2
[] = { 0,
370 2, 1, 2, 1, 1, 2, 2, 2, 3, 3,
371 2, 3, 2, 3, 2, 3, 2, 3, 2, 3,
372 2, 3, 2, 3, 2, 3, 2, 3, 2, 3,
373 2, 2, 3, 1, 1, 1, 1, 2, 1, 2,
374 1, 1, 2, 1, 1, 5, 5, 1, 1, 1,
375 1, 1, 6, 6, 7, 7, 10, 10, 6, 6,
376 7, 7, 10, 10, 6, 7, 6, 5, 6, 4,
377 3, 5, 7, 6, 3, 4, 6, 5, 1, 2,
378 4, 4, 5, 5, 2, 3, 1, 3, 2, 1,
379 2, 3, 3, 3, 4, 4, 4, 4, 4, 1,
380 1, 1, 1, 0, 2, 1, 2, 2, 4, 4,
381 3, 3, 1, 1, 2, 2, 3, 3, 4, 1,
385 static const short yydefact
[] = { 0,
386 0, 104, 0, 0, 0, 104, 104, 0, 0, 121,
387 34, 35, 0, 0, 0, 0, 0, 0, 0, 0,
388 0, 2, 4, 0, 0, 104, 104, 36, 39, 41,
389 120, 42, 44, 48, 45, 52, 50, 49, 51, 0,
390 106, 113, 114, 0, 3, 90, 0, 0, 104, 104,
391 104, 0, 0, 104, 115, 0, 122, 0, 0, 0,
392 0, 0, 0, 0, 0, 0, 0, 11, 13, 19,
393 15, 27, 21, 17, 25, 23, 29, 31, 32, 7,
394 8, 0, 0, 0, 34, 40, 37, 43, 1, 104,
395 104, 107, 108, 104, 0, 116, 104, 105, 89, 91,
396 100, 0, 104, 0, 104, 0, 104, 104, 0, 0,
397 118, 104, 12, 14, 20, 16, 28, 22, 18, 26,
398 24, 30, 33, 9, 10, 75, 0, 71, 38, 0,
399 0, 111, 112, 0, 117, 0, 104, 104, 104, 104,
400 104, 104, 0, 104, 0, 104, 0, 104, 0, 104,
401 0, 0, 104, 70, 0, 109, 110, 0, 0, 119,
402 104, 104, 72, 0, 0, 0, 93, 94, 92, 0,
403 79, 104, 0, 104, 104, 0, 5, 0, 0, 104,
404 104, 0, 0, 0, 46, 47, 0, 68, 0, 0,
405 74, 95, 96, 97, 98, 99, 67, 85, 80, 0,
406 65, 87, 0, 0, 0, 0, 53, 6, 102, 101,
407 103, 104, 54, 0, 0, 59, 104, 60, 69, 73,
408 104, 104, 104, 104, 86, 66, 0, 0, 104, 55,
409 56, 0, 61, 62, 0, 76, 0, 0, 0, 104,
410 88, 81, 82, 104, 104, 104, 104, 104, 78, 83,
411 84, 0, 0, 0, 0, 77, 57, 58, 63, 64,
415 static const short yydefgoto
[] = { 261,
416 178, 28, 29, 88, 30, 31, 32, 33, 34, 35,
417 36, 37, 38, 39, 164, 170, 171, 172, 204, 46,
418 47, 99, 100, 212, 83, 40, 132, 101, 43, 44
421 static const short yypact
[] = { 246,
422 -19,-32768, 8, 25, 29,-32768,-32768, 33, 354, 4,
423 34,-32768, 499, 46, 51, 32, 38, 56, 70, 72,
424 90,-32768,-32768, 97, 101,-32768,-32768,-32768,-32768, 161,
425 -32768, 483,-32768,-32768,-32768,-32768,-32768,-32768,-32768, 6,
426 139,-32768, 84, 390,-32768,-32768, 120, 282,-32768, 89,
427 94, 112, 117, 87, 84, 462,-32768, 96, 123, 127,
428 52, 55, 128, 129, 133, 137, 140,-32768,-32768,-32768,
429 -32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,
430 -32768, 121, 282, 122,-32768,-32768,-32768, 483,-32768,-32768,
431 -32768, 318, 318,-32768, 462, 84,-32768,-32768,-32768, 92,
432 -32768, -10,-32768, 2,-32768, 14,-32768,-32768, 130, -28,
433 84,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,
434 -32768,-32768,-32768,-32768,-32768,-32768, 92,-32768,-32768, 282,
435 282, 10, 10, 426, 84, 93,-32768,-32768,-32768,-32768,
436 -32768,-32768, 23,-32768, 148,-32768, 26,-32768, 148,-32768,
437 158, 164,-32768,-32768, -28,-32768,-32768, 318, 318, 84,
438 -32768,-32768,-32768, 178, 282, 282, 282, 282, 282, 177,
439 166,-32768, -7,-32768,-32768, 176,-32768, 83, 153,-32768,
440 -32768, 183, 83, 155,-32768,-32768, -28,-32768, 193, 199,
441 -32768,-32768,-32768, 57, 57, 57,-32768,-32768, 174, -1,
442 -32768,-32768, 184, -29, 191, 163,-32768,-32768,-32768,-32768,
443 -32768,-32768,-32768, 194, 167,-32768,-32768,-32768,-32768,-32768,
444 -32768,-32768,-32768,-32768,-32768,-32768, -13, 187,-32768,-32768,
445 -32768, 27,-32768,-32768, 28, 103, 282, 282, 282,-32768,
446 -32768,-32768, 282,-32768,-32768,-32768,-32768,-32768,-32768,-32768,
447 282, 197, 169, 201, 170,-32768,-32768,-32768,-32768,-32768,
451 static const short yypgoto
[] = {-32768,
452 74, -26, 195,-32768,-32768,-32768,-32768,-32768,-32768,-32768,
453 -32768,-32768,-32768, -97, -12,-32768, 58,-32768, 30, -3,
454 5,-32768, -82, 45, -2,-32768, 3, 22, 12, 220
461 static const short yytable
[] = { 48,
462 127, 201, 41, 48, 48, 87, 142, 226, 98, 228,
463 52, 53, 154, 202, 26, 144, 229, 45, 145, 202,
464 55, 42, 82, 57, 48, 228, 98, 148, 49, 98,
465 149, 84, 240, 90, 91, 98, 174, 203, 98, 180,
466 244, 246, 89, 203, 146, 50, 102, 104, 106, 51,
467 98, 110, 70, 54, 71, 96, 150, 188, 73, 98,
468 74, 129, 98, 98, 98, 175, 68, 111, 181, 245,
469 247, 69, 115, 72, 116, 118, 76, 119, 58, 75,
470 137, 138, 192, 193, 194, 195, 196, 130, 131, 219,
471 77, 134, 78, 117, 48, 133, 120, 161, 162, 163,
472 143, 136, 147, 208, 48, 48, 135, 248, 162, 155,
473 79, 151, 152, 42, 42, 137, 138, 80, 209, 210,
474 211, 81, 94, 97, 103, 107, 139, 140, 141, 105,
475 108, 109, 156, 157, 165, 166, 167, 168, 169, 173,
476 176, 112, 179, 113, 182, 160, 184, 114, 121, 122,
477 187, 42, 42, 123, 194, 195, 196, 124, 48, 48,
478 125, 133, 90, 91, 126, 189, 190, 128, 177, 200,
479 205, 206, 185, 92, 93, 153, 214, 215, 186, 42,
480 42, 85, 12, 13, 191, 197, 14, 15, 16, 17,
481 207, 18, 19, 20, 21, 198, 213, 216, 218, 220,
482 24, 25, 221, 225, 202, 230, 231, 241, 233, 232,
483 234, 257, 258, 260, 235, 259, 262, 263, 48, 237,
484 238, 239, 183, 249, 86, 236, 243, 217, 56, 199,
485 0, 0, 227, 242, 0, 0, 0, 251, 0, 0,
486 252, 253, 254, 255, 250, 48, 1, 0, 2, 0,
487 0, 0, 256, 3, 0, 4, 5, 6, 7, 0,
488 0, 8, 0, 9, 10, 0, 11, 12, 13, 0,
489 0, 14, 15, 16, 17, 0, 18, 19, 20, 21,
490 0, 0, 22, 23, 2, 24, 25, 0, 26, 3,
491 27, 4, 5, 6, 7, 0, 0, 8, 0, 9,
492 10, 0, 11, 12, 13, 0, 0, 14, 15, 16,
493 17, 0, 18, 19, 20, 21, 0, 0, 98, 0,
494 2, 24, 25, 0, 26, 3, 27, 4, 5, 6,
495 7, 0, 0, 8, 0, 9, 10, 0, 11, 12,
496 13, 0, 0, 14, 15, 16, 17, 0, 18, 19,
497 20, 21, 0, 0, 0, 0, 2, 24, 25, 0,
498 26, 3, 27, 4, 5, 6, 7, 0, 0, 8,
499 0, 0, 10, 0, 11, 12, 13, 0, 0, 14,
500 15, 16, 17, 0, 18, 19, 20, 21, 0, 0,
501 0, 0, 2, 24, 25, 0, 26, 3, 27, 4,
502 5, 6, 7, 0, 0, 8, 0, 95, 0, 0,
503 11, 12, 13, 0, 0, 14, 15, 16, 17, 0,
504 18, 19, 20, 21, 0, 0, 0, 0, 2, 24,
505 25, 0, 26, 3, 27, 4, 5, 6, 7, 0,
506 0, 8, 0, 0, 0, 0, 11, 12, 13, 0,
507 0, 14, 15, 16, 17, 0, 18, 19, 20, 21,
508 0, 0, 98, 0, 2, 24, 25, 0, 26, 3,
509 27, 4, 5, 6, 7, 0, 0, 8, 0, 0,
510 0, 0, 11, 12, 13, 0, 0, 14, 15, 16,
511 17, 0, 18, 19, 20, 21, 0, 0, 0, 0,
512 0, 24, 25, 0, 26, 13, 27, 0, 14, 15,
513 16, 17, 0, 18, 19, 20, 21, 0, 0, 0,
514 0, 0, 24, 25, 59, 60, 61, 62, 0, 63,
515 0, 64, 65, 0, 0, 0, 0, 0, 66, 67
518 static const short yycheck
[] = { 2,
519 83, 9, 0, 6, 7, 32, 17, 9, 37, 39,
520 6, 7, 110, 21, 43, 14, 46, 37, 17, 21,
521 9, 0, 26, 20, 27, 39, 37, 14, 21, 37,
522 17, 27, 46, 24, 25, 37, 14, 45, 37, 14,
523 14, 14, 37, 45, 43, 21, 49, 50, 51, 21,
524 37, 54, 21, 21, 23, 44, 43, 155, 21, 37,
525 23, 88, 37, 37, 37, 43, 21, 56, 43, 43,
526 43, 21, 21, 42, 23, 21, 21, 23, 45, 42,
527 24, 25, 165, 166, 167, 168, 169, 90, 91, 187,
528 21, 94, 21, 42, 97, 93, 42, 5, 6, 7,
529 103, 97, 105, 21, 107, 108, 95, 5, 6, 112,
530 21, 107, 108, 92, 93, 24, 25, 21, 36, 37,
531 38, 21, 39, 4, 36, 14, 35, 36, 37, 36,
532 14, 45, 130, 131, 137, 138, 139, 140, 141, 142,
533 144, 46, 146, 21, 148, 134, 150, 21, 21, 21,
534 153, 130, 131, 21, 237, 238, 239, 21, 161, 162,
535 21, 159, 24, 25, 44, 161, 162, 46, 21, 172,
536 174, 175, 15, 35, 36, 46, 180, 181, 15, 158,
537 159, 21, 22, 23, 7, 9, 26, 27, 28, 29,
538 15, 31, 32, 33, 34, 30, 44, 15, 44, 7,
539 40, 41, 4, 30, 21, 15, 44, 21, 15, 212,
540 44, 15, 44, 44, 217, 15, 0, 0, 221, 222,
541 223, 224, 149, 236, 30, 221, 229, 183, 9, 172,
542 -1, -1, 203, 229, -1, -1, -1, 240, -1, -1,
543 244, 245, 246, 247, 240, 248, 1, -1, 3, -1,
544 -1, -1, 248, 8, -1, 10, 11, 12, 13, -1,
545 -1, 16, -1, 18, 19, -1, 21, 22, 23, -1,
546 -1, 26, 27, 28, 29, -1, 31, 32, 33, 34,
547 -1, -1, 37, 38, 3, 40, 41, -1, 43, 8,
548 45, 10, 11, 12, 13, -1, -1, 16, -1, 18,
549 19, -1, 21, 22, 23, -1, -1, 26, 27, 28,
550 29, -1, 31, 32, 33, 34, -1, -1, 37, -1,
551 3, 40, 41, -1, 43, 8, 45, 10, 11, 12,
552 13, -1, -1, 16, -1, 18, 19, -1, 21, 22,
553 23, -1, -1, 26, 27, 28, 29, -1, 31, 32,
554 33, 34, -1, -1, -1, -1, 3, 40, 41, -1,
555 43, 8, 45, 10, 11, 12, 13, -1, -1, 16,
556 -1, -1, 19, -1, 21, 22, 23, -1, -1, 26,
557 27, 28, 29, -1, 31, 32, 33, 34, -1, -1,
558 -1, -1, 3, 40, 41, -1, 43, 8, 45, 10,
559 11, 12, 13, -1, -1, 16, -1, 18, -1, -1,
560 21, 22, 23, -1, -1, 26, 27, 28, 29, -1,
561 31, 32, 33, 34, -1, -1, -1, -1, 3, 40,
562 41, -1, 43, 8, 45, 10, 11, 12, 13, -1,
563 -1, 16, -1, -1, -1, -1, 21, 22, 23, -1,
564 -1, 26, 27, 28, 29, -1, 31, 32, 33, 34,
565 -1, -1, 37, -1, 3, 40, 41, -1, 43, 8,
566 45, 10, 11, 12, 13, -1, -1, 16, -1, -1,
567 -1, -1, 21, 22, 23, -1, -1, 26, 27, 28,
568 29, -1, 31, 32, 33, 34, -1, -1, -1, -1,
569 -1, 40, 41, -1, 43, 23, 45, -1, 26, 27,
570 28, 29, -1, 31, 32, 33, 34, -1, -1, -1,
571 -1, -1, 40, 41, 26, 27, 28, 29, -1, 31,
572 -1, 33, 34, -1, -1, -1, -1, -1, 40, 41
574 /* -*-C-*- Note some compilers choke on comments on `#line' lines. */
575 #line 3 "/usr/local/lib/bison.simple"
577 /* Skeleton output parser for bison,
578 Copyright (C) 1984, 1989, 1990 Free Software Foundation, Inc.
580 This program is free software; you can redistribute it and/or modify
581 it under the terms of the GNU General Public License as published by
582 the Free Software Foundation; either version 2, or (at your option)
585 This program is distributed in the hope that it will be useful,
586 but WITHOUT ANY WARRANTY; without even the implied warranty of
587 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
588 GNU General Public License for more details.
590 You should have received a copy of the GNU General Public License
591 along with this program; if not, write to the Free Software
592 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
594 /* As a special exception, when this file is copied by Bison into a
595 Bison output file, you may use that output file without restriction.
596 This special exception was added by the Free Software Foundation
597 in version 1.24 of Bison. */
601 #define alloca __builtin_alloca
602 #else /* not GNU C. */
603 #if (!defined (__STDC__) && defined (sparc)) || defined (__sparc__) || defined (__sparc) || defined (__sgi)
605 #else /* not sparc */
606 #if defined (MSDOS) && !defined (__TURBOC__)
608 #else /* not MSDOS, or __TURBOC__ */
612 #else /* not MSDOS, __TURBOC__, or _AIX */
616 void *alloca (unsigned int);
618 #else /* not __cplusplus */
620 #endif /* not __cplusplus */
622 #endif /* not _AIX */
623 #endif /* not MSDOS, or __TURBOC__ */
624 #endif /* not sparc. */
625 #endif /* not GNU C. */
626 #endif /* alloca not defined. */
628 /* This is the parser code that is written into each bison parser
629 when the %semantic_parser declaration is not specified in the grammar.
630 It was written by Richard Stallman by simplifying the hairy parser
631 used when %semantic_parser is specified. */
633 /* Note: there must be only one dollar sign in this file.
634 It is replaced by the list of actions, each action
635 as one case of the switch. */
637 #define yyerrok (yyerrstatus = 0)
638 #define yyclearin (yychar = YYEMPTY)
641 #define YYACCEPT return(0)
642 #define YYABORT return(1)
643 #define YYERROR goto yyerrlab1
644 /* Like YYERROR except do call yyerror.
645 This remains here temporarily to ease the
646 transition to the new meaning of YYERROR, for GCC.
647 Once GCC version 2 has supplanted version 1, this can go. */
648 #define YYFAIL goto yyerrlab
649 #define YYRECOVERING() (!!yyerrstatus)
650 #define YYBACKUP(token, value) \
652 if (yychar == YYEMPTY && yylen == 1) \
653 { yychar = (token), yylval = (value); \
654 yychar1 = YYTRANSLATE (yychar); \
659 { yyerror ("syntax error: cannot back up"); YYERROR; } \
663 #define YYERRCODE 256
666 #define YYLEX yylex()
672 #define YYLEX yylex(&yylval, &yylloc, YYLEX_PARAM)
674 #define YYLEX yylex(&yylval, &yylloc)
676 #else /* not YYLSP_NEEDED */
678 #define YYLEX yylex(&yylval, YYLEX_PARAM)
680 #define YYLEX yylex(&yylval)
682 #endif /* not YYLSP_NEEDED */
685 /* If nonreentrant, generate the variables here */
689 int yychar
; /* the lookahead symbol */
690 YYSTYPE yylval
; /* the semantic value of the */
691 /* lookahead symbol */
694 YYLTYPE yylloc
; /* location data for the lookahead */
698 int yynerrs
; /* number of parse errors so far */
699 #endif /* not YYPURE */
702 int yydebug
; /* nonzero means print parse trace */
703 /* Since this is uninitialized, it does not stop multiple parsers
707 /* YYINITDEPTH indicates the initial size of the parser's stacks */
710 #define YYINITDEPTH 200
713 /* YYMAXDEPTH is the maximum size the stacks can grow to
714 (effective only if the built-in stack extension method is used). */
721 #define YYMAXDEPTH 10000
724 /* Prevent warning if -Wstrict-prototypes. */
729 #if __GNUC__ > 1 /* GNU C and GNU C++ define this. */
730 #define __yy_memcpy(TO,FROM,COUNT) __builtin_memcpy(TO,FROM,COUNT)
731 #else /* not GNU C or C++ */
734 /* This is the most reliable way to avoid incompatibilities
735 in available built-in functions on various systems. */
737 __yy_memcpy (to
, from
, count
)
742 register char *f
= from
;
743 register char *t
= to
;
744 register int i
= count
;
750 #else /* __cplusplus */
752 /* This is the most reliable way to avoid incompatibilities
753 in available built-in functions on various systems. */
755 __yy_memcpy (char *to
, char *from
, int count
)
757 register char *f
= from
;
758 register char *t
= to
;
759 register int i
= count
;
768 #line 196 "/usr/local/lib/bison.simple"
770 /* The user can define YYPARSE_PARAM as the name of an argument to be passed
771 into yyparse. The argument should have type void *.
772 It should actually point to an object.
773 Grammar actions can access the variable by casting it
774 to the proper pointer type. */
778 #define YYPARSE_PARAM_ARG void *YYPARSE_PARAM
779 #define YYPARSE_PARAM_DECL
780 #else /* not __cplusplus */
781 #define YYPARSE_PARAM_ARG YYPARSE_PARAM
782 #define YYPARSE_PARAM_DECL void *YYPARSE_PARAM;
783 #endif /* not __cplusplus */
784 #else /* not YYPARSE_PARAM */
785 #define YYPARSE_PARAM_ARG
786 #define YYPARSE_PARAM_DECL
787 #endif /* not YYPARSE_PARAM */
790 yyparse(YYPARSE_PARAM_ARG
)
793 register int yystate
;
795 register short *yyssp
;
796 register YYSTYPE
*yyvsp
;
797 int yyerrstatus
; /* number of tokens to shift before error messages enabled */
798 int yychar1
= 0; /* lookahead token as an internal (translated) token number */
800 short yyssa
[YYINITDEPTH
]; /* the state stack */
801 YYSTYPE yyvsa
[YYINITDEPTH
]; /* the semantic value stack */
803 short *yyss
= yyssa
; /* refer to the stacks thru separate pointers */
804 YYSTYPE
*yyvs
= yyvsa
; /* to allow yyoverflow to reallocate them elsewhere */
807 YYLTYPE yylsa
[YYINITDEPTH
]; /* the location stack */
808 YYLTYPE
*yyls
= yylsa
;
811 #define YYPOPSTACK (yyvsp--, yyssp--, yylsp--)
813 #define YYPOPSTACK (yyvsp--, yyssp--)
816 int yystacksize
= YYINITDEPTH
;
827 YYSTYPE yyval
; /* the variable used to return */
828 /* semantic values from the action */
835 fprintf(stderr
, "Starting parse\n");
841 yychar
= YYEMPTY
; /* Cause a token to be read. */
843 /* Initialize stack pointers.
844 Waste one element of value and location stack
845 so that they stay on the same level as the state stack.
846 The wasted elements are never initialized. */
854 /* Push a new state, which is found in yystate . */
855 /* In all cases, when you get here, the value and location stacks
856 have just been pushed. so pushing a state here evens the stacks. */
861 if (yyssp
>= yyss
+ yystacksize
- 1)
863 /* Give user a chance to reallocate the stack */
864 /* Use copies of these so that the &'s don't force the real ones into memory. */
865 YYSTYPE
*yyvs1
= yyvs
;
868 YYLTYPE
*yyls1
= yyls
;
871 /* Get the current used size of the three stacks, in elements. */
872 int size
= yyssp
- yyss
+ 1;
875 /* Each stack pointer address is followed by the size of
876 the data in use in that stack, in bytes. */
878 /* This used to be a conditional around just the two extra args,
879 but that might be undefined if yyoverflow is a macro. */
880 yyoverflow("parser stack overflow",
881 &yyss1
, size
* sizeof (*yyssp
),
882 &yyvs1
, size
* sizeof (*yyvsp
),
883 &yyls1
, size
* sizeof (*yylsp
),
886 yyoverflow("parser stack overflow",
887 &yyss1
, size
* sizeof (*yyssp
),
888 &yyvs1
, size
* sizeof (*yyvsp
),
892 yyss
= yyss1
; yyvs
= yyvs1
;
896 #else /* no yyoverflow */
897 /* Extend the stack our own way. */
898 if (yystacksize
>= YYMAXDEPTH
)
900 yyerror("parser stack overflow");
904 if (yystacksize
> YYMAXDEPTH
)
905 yystacksize
= YYMAXDEPTH
;
906 yyss
= (short *) alloca (yystacksize
* sizeof (*yyssp
));
907 __yy_memcpy ((char *)yyss
, (char *)yyss1
, size
* sizeof (*yyssp
));
908 yyvs
= (YYSTYPE
*) alloca (yystacksize
* sizeof (*yyvsp
));
909 __yy_memcpy ((char *)yyvs
, (char *)yyvs1
, size
* sizeof (*yyvsp
));
911 yyls
= (YYLTYPE
*) alloca (yystacksize
* sizeof (*yylsp
));
912 __yy_memcpy ((char *)yyls
, (char *)yyls1
, size
* sizeof (*yylsp
));
914 #endif /* no yyoverflow */
916 yyssp
= yyss
+ size
- 1;
917 yyvsp
= yyvs
+ size
- 1;
919 yylsp
= yyls
+ size
- 1;
924 fprintf(stderr
, "Stack size increased to %d\n", yystacksize
);
927 if (yyssp
>= yyss
+ yystacksize
- 1)
933 fprintf(stderr
, "Entering state %d\n", yystate
);
939 /* Do appropriate processing given the current state. */
940 /* Read a lookahead token if we need one and don't already have one. */
943 /* First try to decide what to do without reference to lookahead token. */
945 yyn
= yypact
[yystate
];
949 /* Not known => get a lookahead token if don't already have one. */
951 /* yychar is either YYEMPTY or YYEOF
952 or a valid token in external form. */
954 if (yychar
== YYEMPTY
)
958 fprintf(stderr
, "Reading a token: ");
963 /* Convert token to internal form (in yychar1) for indexing tables with */
965 if (yychar
<= 0) /* This means end of input. */
968 yychar
= YYEOF
; /* Don't call YYLEX any more */
972 fprintf(stderr
, "Now at end of input.\n");
977 yychar1
= YYTRANSLATE(yychar
);
982 fprintf (stderr
, "Next token is %d (%s", yychar
, yytname
[yychar1
]);
983 /* Give the individual parser a way to print the precise meaning
984 of a token, for further debugging info. */
986 YYPRINT (stderr
, yychar
, yylval
);
988 fprintf (stderr
, ")\n");
994 if (yyn
< 0 || yyn
> YYLAST
|| yycheck
[yyn
] != yychar1
)
999 /* yyn is what to do for this token type in this state.
1000 Negative => reduce, -yyn is rule number.
1001 Positive => shift, yyn is new state.
1002 New state is final state => don't bother to shift,
1003 just return success.
1004 0, or most negative number => error. */
1019 /* Shift the lookahead token. */
1023 fprintf(stderr
, "Shifting token %d (%s), ", yychar
, yytname
[yychar1
]);
1026 /* Discard the token being shifted unless it is eof. */
1027 if (yychar
!= YYEOF
)
1035 /* count tokens shifted since error; after three, turn off error status. */
1036 if (yyerrstatus
) yyerrstatus
--;
1041 /* Do the default action for the current state. */
1044 yyn
= yydefact
[yystate
];
1048 /* Do a reduction. yyn is the number of a rule to reduce with. */
1052 yyval
= yyvsp
[1-yylen
]; /* implement default value of the action */
1059 fprintf (stderr
, "Reducing via rule %d (line %d), ",
1062 /* Print the symbols being reduced, and their result. */
1063 for (i
= yyprhs
[yyn
]; yyrhs
[i
] > 0; i
++)
1064 fprintf (stderr
, "%s ", yytname
[yyrhs
[i
]]);
1065 fprintf (stderr
, " -> %s\n", yytname
[yyr1
[yyn
]]);
1073 #line 210 "./parse.y"
1075 /* Case of regular command. Discard the error
1076 safety net,and return the command just parsed. */
1077 global_command
= yyvsp
[-1].command
;
1078 eof_encountered
= 0;
1079 discard_parser_constructs (0);
1084 #line 219 "./parse.y"
1086 /* Case of regular command, but not a very
1087 interesting one. Return a NULL command. */
1088 global_command
= (COMMAND
*)NULL
;
1093 #line 226 "./parse.y"
1095 /* Error during parsing. Return NULL command. */
1096 global_command
= (COMMAND
*)NULL
;
1097 eof_encountered
= 0;
1098 discard_parser_constructs (1);
1110 #line 241 "./parse.y"
1112 /* Case of EOF seen by itself. Do ignoreeof or
1114 global_command
= (COMMAND
*)NULL
;
1115 handle_eof_input_unit ();
1120 #line 251 "./parse.y"
1121 { yyval
.word_list
= make_word_list (yyvsp
[0].word
, (WORD_LIST
*)NULL
); ;
1124 #line 253 "./parse.y"
1125 { yyval
.word_list
= make_word_list (yyvsp
[0].word
, yyvsp
[-1].word_list
); ;
1128 #line 257 "./parse.y"
1130 redir
.filename
= yyvsp
[0].word
;
1131 yyval
.redirect
= make_redirection (1, r_output_direction
, redir
);
1135 #line 262 "./parse.y"
1137 redir
.filename
= yyvsp
[0].word
;
1138 yyval
.redirect
= make_redirection (0, r_input_direction
, redir
);
1142 #line 267 "./parse.y"
1144 redir
.filename
= yyvsp
[0].word
;
1145 yyval
.redirect
= make_redirection (yyvsp
[-2].number
, r_output_direction
, redir
);
1149 #line 272 "./parse.y"
1151 redir
.filename
= yyvsp
[0].word
;
1152 yyval
.redirect
= make_redirection (yyvsp
[-2].number
, r_input_direction
, redir
);
1156 #line 277 "./parse.y"
1158 redir
.filename
= yyvsp
[0].word
;
1159 yyval
.redirect
= make_redirection (1, r_appending_to
, redir
);
1163 #line 282 "./parse.y"
1165 redir
.filename
= yyvsp
[0].word
;
1166 yyval
.redirect
= make_redirection (yyvsp
[-2].number
, r_appending_to
, redir
);
1170 #line 287 "./parse.y"
1172 redir
.filename
= yyvsp
[0].word
;
1173 yyval
.redirect
= make_redirection (0, r_reading_until
, redir
);
1174 redir_stack
[need_here_doc
++] = yyval
.redirect
;
1178 #line 293 "./parse.y"
1180 redir
.filename
= yyvsp
[0].word
;
1181 yyval
.redirect
= make_redirection (yyvsp
[-2].number
, r_reading_until
, redir
);
1182 redir_stack
[need_here_doc
++] = yyval
.redirect
;
1186 #line 299 "./parse.y"
1188 redir
.dest
= yyvsp
[0].number
;
1189 yyval
.redirect
= make_redirection (0, r_duplicating_input
, redir
);
1193 #line 304 "./parse.y"
1195 redir
.dest
= yyvsp
[0].number
;
1196 yyval
.redirect
= make_redirection (yyvsp
[-2].number
, r_duplicating_input
, redir
);
1200 #line 309 "./parse.y"
1202 redir
.dest
= yyvsp
[0].number
;
1203 yyval
.redirect
= make_redirection (1, r_duplicating_output
, redir
);
1207 #line 314 "./parse.y"
1209 redir
.dest
= yyvsp
[0].number
;
1210 yyval
.redirect
= make_redirection (yyvsp
[-2].number
, r_duplicating_output
, redir
);
1214 #line 319 "./parse.y"
1216 redir
.filename
= yyvsp
[0].word
;
1217 yyval
.redirect
= make_redirection (0, r_duplicating_input_word
, redir
);
1221 #line 324 "./parse.y"
1223 redir
.filename
= yyvsp
[0].word
;
1224 yyval
.redirect
= make_redirection (yyvsp
[-2].number
, r_duplicating_input_word
, redir
);
1228 #line 329 "./parse.y"
1230 redir
.filename
= yyvsp
[0].word
;
1231 yyval
.redirect
= make_redirection (1, r_duplicating_output_word
, redir
);
1235 #line 334 "./parse.y"
1237 redir
.filename
= yyvsp
[0].word
;
1238 yyval
.redirect
= make_redirection (yyvsp
[-2].number
, r_duplicating_output_word
, redir
);
1242 #line 339 "./parse.y"
1244 redir
.filename
= yyvsp
[0].word
;
1245 yyval
.redirect
= make_redirection
1246 (0, r_deblank_reading_until
, redir
);
1247 redir_stack
[need_here_doc
++] = yyval
.redirect
;
1251 #line 346 "./parse.y"
1253 redir
.filename
= yyvsp
[0].word
;
1254 yyval
.redirect
= make_redirection
1255 (yyvsp
[-2].number
, r_deblank_reading_until
, redir
);
1256 redir_stack
[need_here_doc
++] = yyval
.redirect
;
1260 #line 353 "./parse.y"
1263 yyval
.redirect
= make_redirection (1, r_close_this
, redir
);
1267 #line 358 "./parse.y"
1270 yyval
.redirect
= make_redirection (yyvsp
[-2].number
, r_close_this
, redir
);
1274 #line 363 "./parse.y"
1277 yyval
.redirect
= make_redirection (0, r_close_this
, redir
);
1281 #line 368 "./parse.y"
1284 yyval
.redirect
= make_redirection (yyvsp
[-2].number
, r_close_this
, redir
);
1288 #line 373 "./parse.y"
1290 redir
.filename
= yyvsp
[0].word
;
1291 yyval
.redirect
= make_redirection (1, r_err_and_out
, redir
);
1295 #line 378 "./parse.y"
1297 redir
.filename
= yyvsp
[0].word
;
1298 yyval
.redirect
= make_redirection (yyvsp
[-2].number
, r_input_output
, redir
);
1302 #line 383 "./parse.y"
1304 redir
.filename
= yyvsp
[0].word
;
1305 yyval
.redirect
= make_redirection (0, r_input_output
, redir
);
1309 #line 388 "./parse.y"
1311 redir
.filename
= yyvsp
[0].word
;
1312 yyval
.redirect
= make_redirection (1, r_output_force
, redir
);
1316 #line 393 "./parse.y"
1318 redir
.filename
= yyvsp
[0].word
;
1319 yyval
.redirect
= make_redirection (yyvsp
[-2].number
, r_output_force
, redir
);
1323 #line 400 "./parse.y"
1324 { yyval
.element
.word
= yyvsp
[0].word
; yyval
.element
.redirect
= 0; ;
1327 #line 402 "./parse.y"
1328 { yyval
.element
.word
= yyvsp
[0].word
; yyval
.element
.redirect
= 0; ;
1331 #line 404 "./parse.y"
1332 { yyval
.element
.redirect
= yyvsp
[0].redirect
; yyval
.element
.word
= 0; ;
1335 #line 408 "./parse.y"
1337 yyval
.redirect
= yyvsp
[0].redirect
;
1341 #line 412 "./parse.y"
1343 register REDIRECT
*t
;
1345 for (t
= yyvsp
[-1].redirect
; t
->next
; t
= t
->next
)
1347 t
->next
= yyvsp
[0].redirect
;
1348 yyval
.redirect
= yyvsp
[-1].redirect
;
1352 #line 423 "./parse.y"
1353 { yyval
.command
= make_simple_command (yyvsp
[0].element
, (COMMAND
*)NULL
); ;
1356 #line 425 "./parse.y"
1357 { yyval
.command
= make_simple_command (yyvsp
[0].element
, yyvsp
[-1].command
); ;
1360 #line 429 "./parse.y"
1361 { yyval
.command
= clean_simple_command (yyvsp
[0].command
); ;
1364 #line 431 "./parse.y"
1365 { yyval
.command
= yyvsp
[0].command
; ;
1368 #line 433 "./parse.y"
1372 tc
= yyvsp
[-1].command
;
1373 /* According to Posix.2 3.9.5, redirections
1374 specified after the body of a function should
1375 be attached to the function and performed when
1376 the function is executed, not as part of the
1377 function definition command. */
1378 if (tc
->type
== cm_function_def
)
1380 tc
= tc
->value
.Function_def
->command
;
1381 if (tc
->type
== cm_group
)
1382 tc
= tc
->value
.Group
->command
;
1386 register REDIRECT
*t
;
1387 for (t
= tc
->redirects
; t
->next
; t
= t
->next
)
1389 t
->next
= yyvsp
[0].redirect
;
1392 tc
->redirects
= yyvsp
[0].redirect
;
1393 yyval
.command
= yyvsp
[-1].command
;
1397 #line 462 "./parse.y"
1398 { yyval
.command
= yyvsp
[0].command
; ;
1401 #line 464 "./parse.y"
1402 { yyval
.command
= yyvsp
[0].command
; ;
1405 #line 466 "./parse.y"
1406 { yyval
.command
= make_while_command (yyvsp
[-3].command
, yyvsp
[-1].command
); ;
1409 #line 468 "./parse.y"
1410 { yyval
.command
= make_until_command (yyvsp
[-3].command
, yyvsp
[-1].command
); ;
1413 #line 470 "./parse.y"
1414 { yyval
.command
= yyvsp
[0].command
; ;
1417 #line 472 "./parse.y"
1418 { yyval
.command
= yyvsp
[0].command
; ;
1421 #line 474 "./parse.y"
1422 { yyval
.command
= yyvsp
[0].command
; ;
1425 #line 476 "./parse.y"
1426 { yyval
.command
= yyvsp
[0].command
; ;
1429 #line 478 "./parse.y"
1430 { yyval
.command
= yyvsp
[0].command
; ;
1433 #line 482 "./parse.y"
1434 { yyval
.command
= make_for_command (yyvsp
[-4].word
, add_string_to_list ("\"$@\"", (WORD_LIST
*)NULL
), yyvsp
[-1].command
); ;
1437 #line 484 "./parse.y"
1438 { yyval
.command
= make_for_command (yyvsp
[-4].word
, add_string_to_list ("$@", (WORD_LIST
*)NULL
), yyvsp
[-1].command
); ;
1441 #line 486 "./parse.y"
1442 { yyval
.command
= make_for_command (yyvsp
[-5].word
, add_string_to_list ("\"$@\"", (WORD_LIST
*)NULL
), yyvsp
[-1].command
); ;
1445 #line 488 "./parse.y"
1446 { yyval
.command
= make_for_command (yyvsp
[-5].word
, add_string_to_list ("\"$@\"", (WORD_LIST
*)NULL
), yyvsp
[-1].command
); ;
1449 #line 490 "./parse.y"
1450 { yyval
.command
= make_for_command (yyvsp
[-8].word
, REVERSE_LIST (yyvsp
[-5].word_list
, WORD_LIST
*), yyvsp
[-1].command
); ;
1453 #line 492 "./parse.y"
1454 { yyval
.command
= make_for_command (yyvsp
[-8].word
, REVERSE_LIST (yyvsp
[-5].word_list
, WORD_LIST
*), yyvsp
[-1].command
); ;
1457 #line 496 "./parse.y"
1459 yyval
.command
= make_select_command (yyvsp
[-4].word
, add_string_to_list ("\"$@\"", (WORD_LIST
*)NULL
), yyvsp
[-1].command
);
1463 #line 500 "./parse.y"
1465 yyval
.command
= make_select_command (yyvsp
[-4].word
, add_string_to_list ("$@", (WORD_LIST
*)NULL
), yyvsp
[-1].command
);
1469 #line 504 "./parse.y"
1471 yyval
.command
= make_select_command (yyvsp
[-5].word
, add_string_to_list ("\"$@\"", (WORD_LIST
*)NULL
), yyvsp
[-1].command
);
1475 #line 508 "./parse.y"
1477 yyval
.command
= make_select_command (yyvsp
[-5].word
, add_string_to_list ("\"$@\"", (WORD_LIST
*)NULL
), yyvsp
[-1].command
);
1481 #line 512 "./parse.y"
1483 yyval
.command
= make_select_command (yyvsp
[-8].word
, (WORD_LIST
*)reverse_list (yyvsp
[-5].word_list
), yyvsp
[-1].command
);
1487 #line 516 "./parse.y"
1489 yyval
.command
= make_select_command (yyvsp
[-8].word
, (WORD_LIST
*)reverse_list (yyvsp
[-5].word_list
), yyvsp
[-1].command
);
1493 #line 522 "./parse.y"
1494 { yyval
.command
= make_case_command (yyvsp
[-4].word
, (PATTERN_LIST
*)NULL
); ;
1497 #line 524 "./parse.y"
1498 { yyval
.command
= make_case_command (yyvsp
[-5].word
, yyvsp
[-2].pattern
); ;
1501 #line 526 "./parse.y"
1502 { yyval
.command
= make_case_command (yyvsp
[-4].word
, yyvsp
[-1].pattern
); ;
1505 #line 530 "./parse.y"
1506 { yyval
.command
= make_function_def (yyvsp
[-4].word
, yyvsp
[0].command
, function_dstart
, function_bstart
); ;
1509 #line 534 "./parse.y"
1510 { yyval
.command
= make_function_def (yyvsp
[-4].word
, yyvsp
[0].command
, function_dstart
, function_bstart
); ;
1513 #line 537 "./parse.y"
1514 { yyval
.command
= make_function_def (yyvsp
[-2].word
, yyvsp
[0].command
, function_dstart
, function_bstart
); ;
1517 #line 541 "./parse.y"
1518 { yyvsp
[-1].command
->flags
|= CMD_WANT_SUBSHELL
; yyval
.command
= yyvsp
[-1].command
; ;
1521 #line 545 "./parse.y"
1522 { yyval
.command
= make_if_command (yyvsp
[-3].command
, yyvsp
[-1].command
, (COMMAND
*)NULL
); ;
1525 #line 547 "./parse.y"
1526 { yyval
.command
= make_if_command (yyvsp
[-5].command
, yyvsp
[-3].command
, yyvsp
[-1].command
); ;
1529 #line 549 "./parse.y"
1530 { yyval
.command
= make_if_command (yyvsp
[-4].command
, yyvsp
[-2].command
, yyvsp
[-1].command
); ;
1533 #line 554 "./parse.y"
1534 { yyval
.command
= make_group_command (yyvsp
[-1].command
); ;
1537 #line 558 "./parse.y"
1538 { yyval
.command
= make_if_command (yyvsp
[-2].command
, yyvsp
[0].command
, (COMMAND
*)NULL
); ;
1541 #line 560 "./parse.y"
1542 { yyval
.command
= make_if_command (yyvsp
[-4].command
, yyvsp
[-2].command
, yyvsp
[0].command
); ;
1545 #line 562 "./parse.y"
1546 { yyval
.command
= make_if_command (yyvsp
[-3].command
, yyvsp
[-1].command
, yyvsp
[0].command
); ;
1549 #line 567 "./parse.y"
1550 { yyvsp
[0].pattern
->next
= yyvsp
[-1].pattern
; yyval
.pattern
= yyvsp
[0].pattern
; ;
1553 #line 571 "./parse.y"
1554 { yyval
.pattern
= make_pattern_list (yyvsp
[-2].word_list
, yyvsp
[0].command
); ;
1557 #line 573 "./parse.y"
1558 { yyval
.pattern
= make_pattern_list (yyvsp
[-2].word_list
, (COMMAND
*)NULL
); ;
1561 #line 575 "./parse.y"
1562 { yyval
.pattern
= make_pattern_list (yyvsp
[-2].word_list
, yyvsp
[0].command
); ;
1565 #line 577 "./parse.y"
1566 { yyval
.pattern
= make_pattern_list (yyvsp
[-2].word_list
, (COMMAND
*)NULL
); ;
1569 #line 582 "./parse.y"
1570 { yyvsp
[-1].pattern
->next
= yyvsp
[-2].pattern
; yyval
.pattern
= yyvsp
[-1].pattern
; ;
1573 #line 586 "./parse.y"
1574 { yyval
.word_list
= make_word_list (yyvsp
[0].word
, (WORD_LIST
*)NULL
); ;
1577 #line 588 "./parse.y"
1578 { yyval
.word_list
= make_word_list (yyvsp
[0].word
, yyvsp
[-2].word_list
); ;
1581 #line 597 "./parse.y"
1583 yyval
.command
= yyvsp
[0].command
;
1585 gather_here_documents ();
1589 #line 606 "./parse.y"
1591 yyval
.command
= yyvsp
[0].command
;
1595 #line 613 "./parse.y"
1597 if (yyvsp
[-2].command
->type
== cm_connection
)
1598 yyval
.command
= connect_async_list (yyvsp
[-2].command
, (COMMAND
*)NULL
, '&');
1600 yyval
.command
= command_connect (yyvsp
[-2].command
, (COMMAND
*)NULL
, '&');
1604 #line 624 "./parse.y"
1605 { yyval
.command
= command_connect (yyvsp
[-3].command
, yyvsp
[0].command
, AND_AND
); ;
1608 #line 626 "./parse.y"
1609 { yyval
.command
= command_connect (yyvsp
[-3].command
, yyvsp
[0].command
, OR_OR
); ;
1612 #line 628 "./parse.y"
1614 if (yyvsp
[-3].command
->type
== cm_connection
)
1615 yyval
.command
= connect_async_list (yyvsp
[-3].command
, yyvsp
[0].command
, '&');
1617 yyval
.command
= command_connect (yyvsp
[-3].command
, yyvsp
[0].command
, '&');
1621 #line 635 "./parse.y"
1622 { yyval
.command
= command_connect (yyvsp
[-3].command
, yyvsp
[0].command
, ';'); ;
1625 #line 637 "./parse.y"
1626 { yyval
.command
= command_connect (yyvsp
[-3].command
, yyvsp
[0].command
, ';'); ;
1629 #line 639 "./parse.y"
1630 { yyval
.command
= yyvsp
[0].command
; ;
1633 #line 658 "./parse.y"
1635 yyval
.command
= yyvsp
[0].command
;
1637 gather_here_documents ();
1641 #line 664 "./parse.y"
1643 if (yyvsp
[-1].command
->type
== cm_connection
)
1644 yyval
.command
= connect_async_list (yyvsp
[-1].command
, (COMMAND
*)NULL
, '&');
1646 yyval
.command
= command_connect (yyvsp
[-1].command
, (COMMAND
*)NULL
, '&');
1648 gather_here_documents ();
1652 #line 673 "./parse.y"
1654 yyval
.command
= yyvsp
[-1].command
;
1656 gather_here_documents ();
1660 #line 681 "./parse.y"
1661 { yyval
.command
= command_connect (yyvsp
[-3].command
, yyvsp
[0].command
, AND_AND
); ;
1664 #line 683 "./parse.y"
1665 { yyval
.command
= command_connect (yyvsp
[-3].command
, yyvsp
[0].command
, OR_OR
); ;
1668 #line 685 "./parse.y"
1670 if (yyvsp
[-2].command
->type
== cm_connection
)
1671 yyval
.command
= connect_async_list (yyvsp
[-2].command
, yyvsp
[0].command
, '&');
1673 yyval
.command
= command_connect (yyvsp
[-2].command
, yyvsp
[0].command
, '&');
1677 #line 692 "./parse.y"
1678 { yyval
.command
= command_connect (yyvsp
[-2].command
, yyvsp
[0].command
, ';'); ;
1681 #line 695 "./parse.y"
1682 { yyval
.command
= yyvsp
[0].command
; ;
1685 #line 699 "./parse.y"
1686 { yyval
.command
= yyvsp
[0].command
; ;
1689 #line 701 "./parse.y"
1691 yyvsp
[0].command
->flags
|= CMD_INVERT_RETURN
;
1692 yyval
.command
= yyvsp
[0].command
;
1696 #line 706 "./parse.y"
1698 yyvsp
[0].command
->flags
|= yyvsp
[-1].number
;
1699 yyval
.command
= yyvsp
[0].command
;
1703 #line 711 "./parse.y"
1705 yyvsp
[0].command
->flags
|= yyvsp
[-2].number
;
1706 yyval
.command
= yyvsp
[0].command
;
1710 #line 716 "./parse.y"
1712 yyvsp
[0].command
->flags
|= yyvsp
[-1].number
|CMD_INVERT_RETURN
;
1713 yyval
.command
= yyvsp
[0].command
;
1717 #line 724 "./parse.y"
1718 { yyval
.command
= command_connect (yyvsp
[-3].command
, yyvsp
[0].command
, '|'); ;
1721 #line 726 "./parse.y"
1722 { yyval
.command
= yyvsp
[0].command
; ;
1725 #line 730 "./parse.y"
1726 { yyval
.number
= CMD_TIME_PIPELINE
; ;
1729 #line 732 "./parse.y"
1730 { yyval
.number
= CMD_TIME_PIPELINE
|CMD_TIME_POSIX
; ;
1733 /* the action file gets copied in in place of this dollarsign */
1734 #line 498 "/usr/local/lib/bison.simple"
1745 short *ssp1
= yyss
- 1;
1746 fprintf (stderr
, "state stack now");
1747 while (ssp1
!= yyssp
)
1748 fprintf (stderr
, " %d", *++ssp1
);
1749 fprintf (stderr
, "\n");
1759 yylsp
->first_line
= yylloc
.first_line
;
1760 yylsp
->first_column
= yylloc
.first_column
;
1761 yylsp
->last_line
= (yylsp
-1)->last_line
;
1762 yylsp
->last_column
= (yylsp
-1)->last_column
;
1767 yylsp
->last_line
= (yylsp
+yylen
-1)->last_line
;
1768 yylsp
->last_column
= (yylsp
+yylen
-1)->last_column
;
1772 /* Now "shift" the result of the reduction.
1773 Determine what state that goes to,
1774 based on the state we popped back to
1775 and the rule number reduced by. */
1779 yystate
= yypgoto
[yyn
- YYNTBASE
] + *yyssp
;
1780 if (yystate
>= 0 && yystate
<= YYLAST
&& yycheck
[yystate
] == *yyssp
)
1781 yystate
= yytable
[yystate
];
1783 yystate
= yydefgoto
[yyn
- YYNTBASE
];
1787 yyerrlab
: /* here on detecting error */
1790 /* If not already recovering from an error, report this error. */
1794 #ifdef YYERROR_VERBOSE
1795 yyn
= yypact
[yystate
];
1797 if (yyn
> YYFLAG
&& yyn
< YYLAST
)
1804 /* Start X at -yyn if nec to avoid negative indexes in yycheck. */
1805 for (x
= (yyn
< 0 ? -yyn
: 0);
1806 x
< (sizeof(yytname
) / sizeof(char *)); x
++)
1807 if (yycheck
[x
+ yyn
] == x
)
1808 size
+= strlen(yytname
[x
]) + 15, count
++;
1809 msg
= (char *) malloc(size
+ 15);
1812 strcpy(msg
, "parse error");
1817 for (x
= (yyn
< 0 ? -yyn
: 0);
1818 x
< (sizeof(yytname
) / sizeof(char *)); x
++)
1819 if (yycheck
[x
+ yyn
] == x
)
1821 strcat(msg
, count
== 0 ? ", expecting `" : " or `");
1822 strcat(msg
, yytname
[x
]);
1831 yyerror ("parse error; also virtual memory exceeded");
1834 #endif /* YYERROR_VERBOSE */
1835 yyerror("parse error");
1839 yyerrlab1
: /* here on error raised explicitly by an action */
1841 if (yyerrstatus
== 3)
1843 /* if just tried and failed to reuse lookahead token after an error, discard it. */
1845 /* return failure if at end of input */
1846 if (yychar
== YYEOF
)
1851 fprintf(stderr
, "Discarding token %d (%s).\n", yychar
, yytname
[yychar1
]);
1857 /* Else will try to reuse lookahead token
1858 after shifting the error token. */
1860 yyerrstatus
= 3; /* Each real token shifted decrements this */
1864 yyerrdefault
: /* current state does not do anything special for the error token. */
1867 /* This is wrong; only states that explicitly want error tokens
1868 should shift them. */
1869 yyn
= yydefact
[yystate
]; /* If its default is to accept any token, ok. Otherwise pop it.*/
1870 if (yyn
) goto yydefault
;
1873 yyerrpop
: /* pop the current state because it cannot handle the error token */
1875 if (yyssp
== yyss
) YYABORT
;
1885 short *ssp1
= yyss
- 1;
1886 fprintf (stderr
, "Error: state stack now");
1887 while (ssp1
!= yyssp
)
1888 fprintf (stderr
, " %d", *++ssp1
);
1889 fprintf (stderr
, "\n");
1895 yyn
= yypact
[yystate
];
1900 if (yyn
< 0 || yyn
> YYLAST
|| yycheck
[yyn
] != YYTERROR
)
1919 fprintf(stderr
, "Shifting error token, ");
1930 #line 734 "./parse.y"
1933 /* Possible states for the parser that require it to do special things. */
1934 #define PST_CASEPAT 0x001 /* in a case pattern list */
1935 #define PST_ALEXPNEXT 0x002 /* expand next word for aliases */
1936 #define PST_ALLOWOPNBRC 0x004 /* allow open brace for function def */
1937 #define PST_NEEDCLOSBRC 0x008 /* need close brace */
1938 #define PST_DBLPAREN 0x010 /* double-paren parsing */
1939 #define PST_SUBSHELL 0x020 /* ( ... ) subshell */
1940 #define PST_CMDSUBST 0x040 /* $( ... ) command substitution */
1941 #define PST_CASESTMT 0x080 /* parsing a case statement */
1943 /* Initial size to allocate for tokens, and the
1944 amount to grow them by. */
1945 #define TOKEN_DEFAULT_GROW_SIZE 512
1947 /* Shell meta-characters that, when unquoted, separate words. */
1948 #define shellmeta(c) (strchr ("()<>;&|", (c)) != 0)
1949 #define shellbreak(c) (strchr ("()<>;&| \t\n", (c)) != 0)
1950 #define shellquote(c) ((c) == '"' || (c) == '`' || (c) == '\'')
1951 #define shellexp(c) ((c) == '$' || (c) == '<' || (c) == '>')
1953 /* The token currently being read. */
1954 static int current_token
;
1956 /* The last read token, or NULL. read_token () uses this for context
1958 static int last_read_token
;
1960 /* The token read prior to last_read_token. */
1961 static int token_before_that
;
1963 /* The token read prior to token_before_that. */
1964 static int two_tokens_ago
;
1966 /* If non-zero, it is the token that we want read_token to return
1967 regardless of what text is (or isn't) present to be read. This
1968 is reset by read_token. If token_to_read == WORD or
1969 ASSIGNMENT_WORD, yylval.word should be set to word_desc_to_read. */
1970 static int token_to_read
;
1971 static WORD_DESC
*word_desc_to_read
;
1973 /* The current parser state. */
1974 static int parser_state
;
1976 /* Global var is non-zero when end of file has been reached. */
1977 int EOF_Reached
= 0;
1988 /* yy_getc () returns the next available character from input or EOF.
1989 yy_ungetc (c) makes `c' the next character to read.
1990 init_yy_io (get, unget, type, location) makes the function GET the
1991 installed function for getting the next character, makes UNGET the
1992 installed function for un-getting a character, sets the type of stream
1993 (either string or file) from TYPE, and makes LOCATION point to where
1994 the input is coming from. */
1996 /* Unconditionally returns end-of-file. */
2003 /* Variable containing the current get and unget functions.
2004 See ./input.h for a clearer description. */
2005 BASH_INPUT bash_input
;
2007 /* Set all of the fields in BASH_INPUT to NULL. Free bash_input.name if it
2008 is non-null, avoiding a memory leak. */
2010 initialize_bash_input ()
2012 bash_input
.type
= st_none
;
2013 FREE (bash_input
.name
);
2014 bash_input
.name
= (char *)NULL
;
2015 bash_input
.location
.file
= (FILE *)NULL
;
2016 bash_input
.location
.string
= (char *)NULL
;
2017 bash_input
.getter
= (Function
*)NULL
;
2018 bash_input
.ungetter
= (Function
*)NULL
;
2021 /* Set the contents of the current bash input stream from
2022 GET, UNGET, TYPE, NAME, and LOCATION. */
2024 init_yy_io (get
, unget
, type
, name
, location
)
2025 Function
*get
, *unget
;
2028 INPUT_STREAM location
;
2030 bash_input
.type
= type
;
2031 FREE (bash_input
.name
);
2032 bash_input
.name
= name
? savestring (name
) : (char *)NULL
;
2036 memcpy((char *)&bash_input
.location
.string
, (char *)&location
.string
, sizeof(location
));
2038 bash_input
.location
= location
;
2040 bash_input
.getter
= get
;
2041 bash_input
.ungetter
= unget
;
2044 /* Call this to get the next character of input. */
2048 return (*(bash_input
.getter
)) ();
2051 /* Call this to unget C. That is, to make C the next character
2057 return (*(bash_input
.ungetter
)) (c
);
2060 #if defined (BUFFERED_INPUT)
2062 input_file_descriptor ()
2064 switch (bash_input
.type
)
2067 return (fileno (bash_input
.location
.file
));
2069 return (bash_input
.location
.buffered_fd
);
2072 return (fileno (stdin
));
2075 #endif /* BUFFERED_INPUT */
2077 /* **************************************************************** */
2079 /* Let input be read from readline (). */
2081 /* **************************************************************** */
2083 #if defined (READLINE)
2084 char *current_readline_prompt
= (char *)NULL
;
2085 char *current_readline_line
= (char *)NULL
;
2086 int current_readline_line_index
= 0;
2091 SigHandler
*old_sigint
;
2094 if (!current_readline_line
)
2096 if (!bash_readline_initialized
)
2097 initialize_readline ();
2099 #if defined (JOB_CONTROL)
2101 give_terminal_to (shell_pgrp
);
2102 #endif /* JOB_CONTROL */
2104 if (signal_is_ignored (SIGINT
) == 0)
2106 old_sigint
= (SigHandler
*)set_signal_handler (SIGINT
, sigint_sighandler
);
2107 interrupt_immediately
++;
2110 current_readline_line
= readline (current_readline_prompt
?
2111 current_readline_prompt
: "");
2113 if (signal_is_ignored (SIGINT
) == 0)
2115 interrupt_immediately
--;
2116 set_signal_handler (SIGINT
, old_sigint
);
2120 /* Reset the prompt to the decoded value of prompt_string_pointer. */
2121 reset_readline_prompt ();
2124 if (current_readline_line
== 0)
2127 current_readline_line_index
= 0;
2128 line_len
= strlen (current_readline_line
);
2130 current_readline_line
= xrealloc (current_readline_line
, 2 + line_len
);
2131 current_readline_line
[line_len
++] = '\n';
2132 current_readline_line
[line_len
] = '\0';
2135 if (current_readline_line
[current_readline_line_index
] == 0)
2137 free (current_readline_line
);
2138 current_readline_line
= (char *)NULL
;
2139 return (yy_readline_get ());
2143 c
= (unsigned char)current_readline_line
[current_readline_line_index
++];
2149 yy_readline_unget (c
)
2152 if (current_readline_line_index
&& current_readline_line
)
2153 current_readline_line
[--current_readline_line_index
] = c
;
2158 with_input_from_stdin ()
2160 INPUT_STREAM location
;
2162 if (bash_input
.type
!= st_stdin
&& stream_on_stack (st_stdin
) == 0)
2164 location
.string
= current_readline_line
;
2165 init_yy_io (yy_readline_get
, yy_readline_unget
,
2166 st_stdin
, "readline stdin", location
);
2170 #else /* !READLINE */
2173 with_input_from_stdin ()
2175 with_input_from_stream (stdin
, "stdin");
2177 #endif /* !READLINE */
2179 /* **************************************************************** */
2181 /* Let input come from STRING. STRING is zero terminated. */
2183 /* **************************************************************** */
2188 register char *string
;
2191 string
= bash_input
.location
.string
;
2194 /* If the string doesn't exist, or is empty, EOF found. */
2195 if (string
&& *string
)
2197 c
= *(unsigned char *)string
++;
2198 bash_input
.location
.string
= string
;
2207 *(--bash_input
.location
.string
) = c
;
2212 with_input_from_string (string
, name
)
2213 char *string
, *name
;
2215 INPUT_STREAM location
;
2217 location
.string
= string
;
2218 init_yy_io (yy_string_get
, yy_string_unget
, st_string
, name
, location
);
2221 /* **************************************************************** */
2223 /* Let input come from STREAM. */
2225 /* **************************************************************** */
2232 if (bash_input
.location
.file
)
2234 #if !defined (HAVE_RESTARTABLE_SYSCALLS)
2235 result
= getc_with_restart (bash_input
.location
.file
);
2236 #else /* HAVE_RESTARTABLE_SYSCALLS */
2237 result
= getc (bash_input
.location
.file
);
2238 result
= (feof (bash_input
.location
.file
)) ? EOF
: (unsigned char)result
;
2239 #endif /* HAVE_RESTARTABLE_SYSCALLS */
2248 #if !defined (HAVE_RESTARTABLE_SYSCALLS)
2249 return (ungetc_with_restart (c
, bash_input
.location
.file
));
2250 #else /* HAVE_RESTARTABLE_SYSCALLS */
2251 return (ungetc (c
, bash_input
.location
.file
));
2252 #endif /* HAVE_RESTARTABLE_SYSCALLS */
2256 with_input_from_stream (stream
, name
)
2260 INPUT_STREAM location
;
2262 location
.file
= stream
;
2263 init_yy_io (yy_stream_get
, yy_stream_unget
, st_stream
, name
, location
);
2266 typedef struct stream_saver
{
2267 struct stream_saver
*next
;
2268 BASH_INPUT bash_input
;
2270 #if defined (BUFFERED_INPUT)
2271 BUFFERED_STREAM
*bstream
;
2272 #endif /* BUFFERED_INPUT */
2275 /* The globally known line number. */
2276 int line_number
= 0;
2278 STREAM_SAVER
*stream_list
= (STREAM_SAVER
*)NULL
;
2281 push_stream (reset_lineno
)
2284 STREAM_SAVER
*saver
= (STREAM_SAVER
*)xmalloc (sizeof (STREAM_SAVER
));
2286 xbcopy ((char *)&bash_input
, (char *)&(saver
->bash_input
), sizeof (BASH_INPUT
));
2288 #if defined (BUFFERED_INPUT)
2289 saver
->bstream
= (BUFFERED_STREAM
*)NULL
;
2290 /* If we have a buffered stream, clear out buffers[fd]. */
2291 if (bash_input
.type
== st_bstream
&& bash_input
.location
.buffered_fd
>= 0)
2293 saver
->bstream
= buffers
[bash_input
.location
.buffered_fd
];
2294 buffers
[bash_input
.location
.buffered_fd
] = (BUFFERED_STREAM
*)NULL
;
2296 #endif /* BUFFERED_INPUT */
2298 saver
->line
= line_number
;
2299 bash_input
.name
= (char *)NULL
;
2300 saver
->next
= stream_list
;
2301 stream_list
= saver
;
2314 STREAM_SAVER
*saver
= stream_list
;
2317 stream_list
= stream_list
->next
;
2319 init_yy_io (saver
->bash_input
.getter
,
2320 saver
->bash_input
.ungetter
,
2321 saver
->bash_input
.type
,
2322 saver
->bash_input
.name
,
2323 saver
->bash_input
.location
);
2325 #if defined (BUFFERED_INPUT)
2326 /* If we have a buffered stream, restore buffers[fd]. */
2327 /* If the input file descriptor was changed while this was on the
2328 save stack, update the buffered fd to the new file descriptor and
2329 re-establish the buffer <-> bash_input fd correspondence. */
2330 if (bash_input
.type
== st_bstream
&& bash_input
.location
.buffered_fd
>= 0)
2332 if (bash_input_fd_changed
)
2334 bash_input_fd_changed
= 0;
2335 if (default_buffered_input
>= 0)
2337 bash_input
.location
.buffered_fd
= default_buffered_input
;
2338 saver
->bstream
->b_fd
= default_buffered_input
;
2341 buffers
[bash_input
.location
.buffered_fd
] = saver
->bstream
;
2343 #endif /* BUFFERED_INPUT */
2345 line_number
= saver
->line
;
2347 FREE (saver
->bash_input
.name
);
2352 /* Return 1 if a stream of type TYPE is saved on the stack. */
2354 stream_on_stack (type
)
2355 enum stream_type type
;
2357 register STREAM_SAVER
*s
;
2359 for (s
= stream_list
; s
; s
= s
->next
)
2360 if (s
->bash_input
.type
== type
)
2366 * This is used to inhibit alias expansion and reserved word recognition
2367 * inside case statement pattern lists. A `case statement pattern list' is:
2369 * everything between the `in' in a `case word in' and the next ')'
2371 * everything between a `;;' and the next `)' or `esac'
2376 #define END_OF_ALIAS 0
2379 * Pseudo-global variables used in implementing token-wise alias expansion.
2383 * Pushing and popping strings. This works together with shell_getc to
2384 * implement alias expansion on a per-token basis.
2387 typedef struct string_saver
{
2388 struct string_saver
*next
;
2389 int expand_alias
; /* Value to set expand_alias to when string is popped. */
2391 alias_t
*expander
; /* alias that caused this line to be pushed. */
2392 int saved_line_size
, saved_line_index
, saved_line_terminator
;
2395 STRING_SAVER
*pushed_string_list
= (STRING_SAVER
*)NULL
;
2398 * Push the current shell_input_line onto a stack of such lines and make S
2399 * the current input. Used when expanding aliases. EXPAND is used to set
2400 * the value of expand_next_token when the string is popped, so that the
2401 * word after the alias in the original line is handled correctly when the
2402 * alias expands to multiple words. TOKEN is the token that was expanded
2403 * into S; it is saved and used to prevent infinite recursive expansion.
2406 push_string (s
, expand
, ap
)
2411 STRING_SAVER
*temp
= (STRING_SAVER
*) xmalloc (sizeof (STRING_SAVER
));
2413 temp
->expand_alias
= expand
;
2414 temp
->saved_line
= shell_input_line
;
2415 temp
->saved_line_size
= shell_input_line_size
;
2416 temp
->saved_line_index
= shell_input_line_index
;
2417 temp
->saved_line_terminator
= shell_input_line_terminator
;
2418 temp
->expander
= ap
;
2419 temp
->next
= pushed_string_list
;
2420 pushed_string_list
= temp
;
2422 ap
->flags
|= AL_BEINGEXPANDED
;
2424 shell_input_line
= s
;
2425 shell_input_line_size
= strlen (s
);
2426 shell_input_line_index
= 0;
2427 shell_input_line_terminator
= '\0';
2428 parser_state
&= ~PST_ALEXPNEXT
;
2432 * Make the top of the pushed_string stack be the current shell input.
2433 * Only called when there is something on the stack. Called from shell_getc
2434 * when it thinks it has consumed the string generated by an alias expansion
2435 * and needs to return to the original input line.
2442 FREE (shell_input_line
);
2443 shell_input_line
= pushed_string_list
->saved_line
;
2444 shell_input_line_index
= pushed_string_list
->saved_line_index
;
2445 shell_input_line_size
= pushed_string_list
->saved_line_size
;
2446 shell_input_line_terminator
= pushed_string_list
->saved_line_terminator
;
2448 if (pushed_string_list
->expand_alias
)
2449 parser_state
|= PST_ALEXPNEXT
;
2451 parser_state
&= ~PST_ALEXPNEXT
;
2453 t
= pushed_string_list
;
2454 pushed_string_list
= pushed_string_list
->next
;
2456 t
->expander
->flags
&= ~AL_BEINGEXPANDED
;
2464 register STRING_SAVER
*t
, *t1
;
2466 for (t
= pushed_string_list
; t
; )
2469 FREE (t
->saved_line
);
2470 t
->expander
->flags
&= ~AL_BEINGEXPANDED
;
2474 pushed_string_list
= (STRING_SAVER
*)NULL
;
2479 /* Return a line of text, taken from wherever yylex () reads input.
2480 If there is no more input, then we return NULL. If REMOVE_QUOTED_NEWLINE
2481 is non-zero, we remove unquoted \<newline> pairs. This is used by
2482 read_secondary_line to read here documents. */
2484 read_a_line (remove_quoted_newline
)
2485 int remove_quoted_newline
;
2487 static char *line_buffer
= (char *)NULL
;
2488 static int buffer_size
= 0;
2489 int indx
= 0, c
, peekc
, pass_next
;
2491 #if defined (READLINE)
2492 if (interactive
&& bash_input
.type
!= st_string
&& no_line_editing
)
2494 if (interactive
&& bash_input
.type
!= st_string
)
2503 /* Allow immediate exit if interrupted during input. */
2509 /* If there is no more input, then we return NULL. */
2512 if (interactive
&& bash_input
.type
== st_stream
)
2515 return ((char *)NULL
);
2519 /* `+2' in case the final character in the buffer is a newline. */
2520 RESIZE_MALLOCED_BUFFER (line_buffer
, indx
, 2, buffer_size
, 128);
2522 /* IF REMOVE_QUOTED_NEWLINES is non-zero, we are reading a
2523 here document with an unquoted delimiter. In this case,
2524 the line will be expanded as if it were in double quotes.
2525 We allow a backslash to escape the next character, but we
2526 need to treat the backslash specially only if a backslash
2527 quoting a backslash-newline pair appears in the line. */
2530 line_buffer
[indx
++] = c
;
2533 else if (c
== '\\' && remove_quoted_newline
)
2537 continue; /* Make the unquoted \<newline> pair disappear. */
2542 line_buffer
[indx
++] = c
; /* Preserve the backslash. */
2546 line_buffer
[indx
++] = c
;
2550 line_buffer
[indx
] = '\0';
2551 return (line_buffer
);
2556 /* Return a line as in read_a_line (), but insure that the prompt is
2557 the secondary prompt. This is used to read the lines of a here
2558 document. REMOVE_QUOTED_NEWLINE is non-zero if we should remove
2559 newlines quoted with backslashes while reading the line. It is
2560 non-zero unless the delimiter of the here document was quoted. */
2562 read_secondary_line (remove_quoted_newline
)
2563 int remove_quoted_newline
;
2565 prompt_string_pointer
= &ps2_prompt
;
2567 return (read_a_line (remove_quoted_newline
));
2570 /* **************************************************************** */
2574 /* **************************************************************** */
2576 /* Reserved words. These are only recognized as the first word of a
2578 STRING_INT_ALIST word_token_alist
[] = {
2587 #if defined (SELECT_COMMAND)
2588 { "select", SELECT
},
2595 { "function", FUNCTION
},
2596 #if defined (COMMAND_TIMING)
2605 /* These are used by read_token_word, but appear up here so that shell_getc
2606 can use them to decide when to add otherwise blank lines to the history. */
2608 /* The primary delimiter stack. */
2609 struct dstack dstack
= { (char *)NULL
, 0, 0 };
2611 /* A temporary delimiter stack to be used when decoding prompt strings.
2612 This is needed because command substitutions in prompt strings (e.g., PS2)
2613 can screw up the parser's quoting state. */
2614 static struct dstack temp_dstack
= { (char *)NULL
, 0, 0 };
2616 /* Macro for accessing the top delimiter on the stack. Returns the
2617 delimiter or zero if none. */
2618 #define current_delimiter(ds) \
2619 (ds.delimiter_depth ? ds.delimiters[ds.delimiter_depth - 1] : 0)
2621 #define push_delimiter(ds, character) \
2624 if (ds.delimiter_depth + 2 > ds.delimiter_space) \
2625 ds.delimiters = xrealloc \
2626 (ds.delimiters, (ds.delimiter_space += 10) * sizeof (char)); \
2627 ds.delimiters[ds.delimiter_depth] = character; \
2628 ds.delimiter_depth++; \
2632 #define pop_delimiter(ds) ds.delimiter_depth--
2634 /* Return the next shell input character. This always reads characters
2635 from shell_input_line; when that line is exhausted, it is time to
2636 read the next line. This is called by read_token when the shell is
2637 processing normal command input. */
2640 shell_getc (remove_quoted_newline
)
2641 int remove_quoted_newline
;
2645 static int mustpop
= 0;
2650 /* If shell_input_line[shell_input_line_index] == 0, but there is
2651 something on the pushed list of strings, then we don't want to go
2652 off and get another line. We let the code down below handle it. */
2654 if (!shell_input_line
|| ((!shell_input_line
[shell_input_line_index
]) &&
2655 (pushed_string_list
== (STRING_SAVER
*)NULL
)))
2657 if (!shell_input_line
|| !shell_input_line
[shell_input_line_index
])
2664 /* Allow immediate exit if interrupted during input. */
2668 shell_input_line_terminator
= 0;
2670 #if defined (JOB_CONTROL)
2671 /* This can cause a problem when reading a command as the result
2672 of a trap, when the trap is called from flush_child. This call
2673 had better not cause jobs to disappear from the job table in
2674 that case, or we will have big trouble. */
2675 notify_and_cleanup ();
2676 #else /* !JOB_CONTROL */
2677 cleanup_dead_jobs ();
2678 #endif /* !JOB_CONTROL */
2680 #if defined (READLINE)
2681 if (interactive
&& bash_input
.type
!= st_string
&& no_line_editing
)
2683 if (interactive
&& bash_input
.type
!= st_string
)
2687 if (bash_input
.type
== st_stream
)
2690 while (c
= yy_getc ())
2692 /* Allow immediate exit if interrupted during input. */
2695 RESIZE_MALLOCED_BUFFER (shell_input_line
, i
, 2, shell_input_line_size
, 256);
2699 if (bash_input
.type
== st_stream
)
2703 shell_input_line_terminator
= EOF
;
2705 shell_input_line
[i
] = '\0';
2709 shell_input_line
[i
++] = c
;
2713 shell_input_line
[--i
] = '\0';
2714 current_command_line_count
++;
2718 shell_input_line_index
= 0;
2719 shell_input_line_len
= i
; /* == strlen (shell_input_line) */
2721 #if defined (HISTORY)
2722 if (remember_on_history
&& shell_input_line
&& shell_input_line
[0])
2725 # if defined (BANG_HISTORY)
2728 /* If the current delimiter is a single quote, we should not be
2729 performing history expansion, even if we're on a different
2730 line from the original single quote. */
2731 old_hist
= history_expansion_inhibited
;
2732 if (current_delimiter (dstack
) == '\'')
2733 history_expansion_inhibited
= 1;
2735 expansions
= pre_process_line (shell_input_line
, 1, 1);
2736 # if defined (BANG_HISTORY)
2737 history_expansion_inhibited
= old_hist
;
2740 free (shell_input_line
);
2741 shell_input_line
= expansions
;
2742 shell_input_line_len
= shell_input_line
?
2743 strlen (shell_input_line
) :
2745 if (!shell_input_line_len
)
2746 current_command_line_count
--;
2748 /* We have to force the xrealloc below because we don't know the
2749 true allocated size of shell_input_line anymore. */
2750 shell_input_line_size
= shell_input_line_len
;
2752 /* XXX - this is grotesque */
2753 else if (remember_on_history
&& shell_input_line
&&
2754 shell_input_line
[0] == '\0' &&
2755 current_command_line_count
> 1 && current_delimiter (dstack
))
2757 /* We know shell_input_line[0] == 0 and we're reading some sort of
2758 quoted string. This means we've got a line consisting of only
2759 a newline in a quoted string. We want to make sure this line
2760 gets added to the history. */
2761 maybe_add_history (shell_input_line
);
2764 #endif /* HISTORY */
2766 if (shell_input_line
)
2768 /* Lines that signify the end of the shell's input should not be
2770 if (echo_input_at_read
&& (shell_input_line
[0] ||
2771 shell_input_line_terminator
!= EOF
))
2772 fprintf (stderr
, "%s\n", shell_input_line
);
2776 shell_input_line_size
= 0;
2777 prompt_string_pointer
= ¤t_prompt_string
;
2782 /* Add the newline to the end of this string, iff the string does
2783 not already end in an EOF character. */
2784 if (shell_input_line_terminator
!= EOF
)
2786 if (shell_input_line_len
+ 3 > shell_input_line_size
)
2787 shell_input_line
= xrealloc (shell_input_line
,
2788 1 + (shell_input_line_size
+= 2));
2790 shell_input_line
[shell_input_line_len
] = '\n';
2791 shell_input_line
[shell_input_line_len
+ 1] = '\0';
2795 c
= shell_input_line
[shell_input_line_index
];
2798 shell_input_line_index
++;
2800 if (c
== '\\' && remove_quoted_newline
&&
2801 shell_input_line
[shell_input_line_index
] == '\n')
2809 /* If C is NULL, we have reached the end of the current input string. If
2810 pushed_string_list is non-empty, it's time to pop to the previous string
2811 because we have fully consumed the result of the last alias expansion.
2812 Do it transparently; just return the next character of the string popped
2814 if (!c
&& (pushed_string_list
!= (STRING_SAVER
*)NULL
))
2819 c
= shell_input_line
[shell_input_line_index
];
2821 shell_input_line_index
++;
2832 if (!c
&& shell_input_line_terminator
== EOF
)
2833 return ((shell_input_line_index
!= 0) ? '\n' : EOF
);
2835 return ((unsigned char)c
);
2838 /* Put C back into the input for the shell. */
2843 if (shell_input_line
&& shell_input_line_index
)
2844 shell_input_line
[--shell_input_line_index
] = c
;
2850 if (shell_input_line
&& shell_input_line_index
)
2851 shell_input_line_index
--;
2854 /* Discard input until CHARACTER is seen, then push that character back
2855 onto the input stream. */
2857 discard_until (character
)
2862 while ((c
= shell_getc (0)) != EOF
&& c
!= character
)
2870 execute_prompt_command (command
)
2873 Function
*temp_last
, *temp_this
;
2875 int temp_exit_value
, temp_eof_encountered
;
2877 temp_last
= last_shell_builtin
;
2878 temp_this
= this_shell_builtin
;
2879 temp_exit_value
= last_command_exit_value
;
2880 temp_eof_encountered
= eof_encountered
;
2881 last_lastarg
= get_string_value ("_");
2883 last_lastarg
= savestring (last_lastarg
);
2885 parse_and_execute (savestring (command
), "PROMPT_COMMAND", 0);
2887 last_shell_builtin
= temp_last
;
2888 this_shell_builtin
= temp_this
;
2889 last_command_exit_value
= temp_exit_value
;
2890 eof_encountered
= temp_eof_encountered
;
2892 bind_variable ("_", last_lastarg
);
2893 FREE (last_lastarg
);
2895 if (token_to_read
== '\n') /* reset_parser was called */
2899 /* Place to remember the token. We try to keep the buffer
2900 at a reasonable size, but it can grow. */
2901 static char *token
= (char *)NULL
;
2903 /* Current size of the token buffer. */
2904 static int token_buffer_size
;
2906 /* Command to read_token () explaining what we want it to do. */
2909 #define prompt_is_ps1 \
2910 (!prompt_string_pointer || prompt_string_pointer == &ps1_prompt)
2912 /* Function for yyparse to call. yylex keeps track of
2913 the last two tokens read, and calls read_token. */
2917 if (interactive
&& (current_token
== 0 || current_token
== '\n'))
2919 /* Before we print a prompt, we might have to check mailboxes.
2920 We do this only if it is time to do so. Notice that only here
2921 is the mail alarm reset; nothing takes place in check_mail ()
2922 except the checking of mail. Please don't change this. */
2923 if (prompt_is_ps1
&& time_to_check_mail ())
2926 reset_mail_timer ();
2929 /* Avoid printing a prompt if we're not going to read anything, e.g.
2930 after resetting the parser with read_token (RESET). */
2931 if (token_to_read
== 0 && interactive
)
2935 two_tokens_ago
= token_before_that
;
2936 token_before_that
= last_read_token
;
2937 last_read_token
= current_token
;
2938 current_token
= read_token (READ
);
2939 return (current_token
);
2942 /* When non-zero, we have read the required tokens
2943 which allow ESAC to be the next one read. */
2944 static int esacs_needed_count
;
2947 gather_here_documents ()
2950 while (need_here_doc
)
2952 make_here_document (redir_stack
[r
++]);
2957 /* When non-zero, an open-brace used to create a group is awaiting a close
2959 static int open_brace_count
;
2961 #define command_token_position(token) \
2962 (((token) == ASSIGNMENT_WORD) || \
2963 ((token) != SEMI_SEMI && reserved_word_acceptable(token)))
2965 #define assignment_acceptable(token) command_token_position(token) && \
2966 ((parser_state & PST_CASEPAT) == 0)
2968 /* Check to see if TOKEN is a reserved word and return the token
2970 #define CHECK_FOR_RESERVED_WORD(tok) \
2972 if (!dollar_present && !quoted && \
2973 reserved_word_acceptable (last_read_token)) \
2976 for (i = 0; word_token_alist[i].word != (char *)NULL; i++) \
2977 if (STREQ (tok, word_token_alist[i].word)) \
2979 if ((parser_state & PST_CASEPAT) && (word_token_alist[i].token != ESAC)) \
2981 if (word_token_alist[i].token == ESAC) \
2982 parser_state &= ~(PST_CASEPAT|PST_CASESTMT); \
2983 else if (word_token_alist[i].token == CASE) \
2984 parser_state |= PST_CASESTMT; \
2985 else if (word_token_alist[i].token == '{') \
2986 open_brace_count++; \
2987 else if (word_token_alist[i].token == '}' && open_brace_count) \
2988 open_brace_count--; \
2989 return (word_token_alist[i].token); \
2996 /* OK, we have a token. Let's try to alias expand it, if (and only if)
2999 It is eligible for expansion if the shell is in interactive mode, and
3000 the token is unquoted and the last token read was a command
3001 separator (or expand_next_token is set), and we are currently
3002 processing an alias (pushed_string_list is non-empty) and this
3003 token is not the same as the current or any previously
3006 Special cases that disqualify:
3007 In a pattern list in a case statement (parser_state & PST_CASEPAT). */
3009 alias_expand_token (token
)
3015 if (((parser_state
& PST_ALEXPNEXT
) || command_token_position (last_read_token
)) &&
3016 (parser_state
& PST_CASEPAT
) == 0)
3018 ap
= find_alias (token
);
3020 /* Currently expanding this token. */
3021 if (ap
&& (ap
->flags
& AL_BEINGEXPANDED
))
3022 return (NO_EXPANSION
);
3024 expanded
= ap
? savestring (ap
->value
) : (char *)NULL
;
3027 push_string (expanded
, ap
->flags
& AL_EXPANDNEXT
, ap
);
3028 return (RE_READ_TOKEN
);
3031 /* This is an eligible token that does not have an expansion. */
3032 return (NO_EXPANSION
);
3034 return (NO_EXPANSION
);
3038 /* Handle special cases of token recognition:
3039 IN is recognized if the last token was WORD and the token
3040 before that was FOR or CASE or SELECT.
3042 DO is recognized if the last token was WORD and the token
3043 before that was FOR or SELECT.
3045 ESAC is recognized if the last token caused `esacs_needed_count'
3048 `{' is recognized if the last token as WORD and the token
3049 before that was FUNCTION.
3051 `}' is recognized if there is an unclosed `{' prsent.
3055 special_case_tokens (token
)
3058 if ((last_read_token
== WORD
) &&
3059 #if defined (SELECT_COMMAND)
3060 ((token_before_that
== FOR
) || (token_before_that
== CASE
) || (token_before_that
== SELECT
)) &&
3062 ((token_before_that
== FOR
) || (token_before_that
== CASE
)) &&
3064 (token
[0] == 'i' && token
[1] == 'n' && token
[2] == 0))
3066 if (token_before_that
== CASE
)
3068 parser_state
|= PST_CASEPAT
;
3069 esacs_needed_count
++;
3074 if (last_read_token
== WORD
&&
3075 #if defined (SELECT_COMMAND)
3076 (token_before_that
== FOR
|| token_before_that
== SELECT
) &&
3078 (token_before_that
== FOR
) &&
3080 (token
[0] == 'd' && token
[1] == 'o' && token
[2] == '\0'))
3083 /* Ditto for ESAC in the CASE case.
3084 Specifically, this handles "case word in esac", which is a legal
3085 construct, certainly because someone will pass an empty arg to the
3086 case construct, and we don't want it to barf. Of course, we should
3087 insist that the case construct has at least one pattern in it, but
3088 the designers disagree. */
3089 if (esacs_needed_count
)
3091 esacs_needed_count
--;
3092 if (STREQ (token
, "esac"))
3094 parser_state
&= ~PST_CASEPAT
;
3099 /* The start of a shell function definition. */
3100 if (parser_state
& PST_ALLOWOPNBRC
)
3102 parser_state
&= ~PST_ALLOWOPNBRC
;
3103 if (token
[0] == '{' && token
[1] == '\0') /* } */
3106 function_bstart
= line_number
;
3107 return ('{'); /* } */
3111 if (open_brace_count
&& reserved_word_acceptable (last_read_token
) && token
[0] == '}' && !token
[1])
3113 open_brace_count
--; /* { */
3117 /* Handle -p after `time'. */
3118 if (last_read_token
== TIME
&& token
[0] == '-' && token
[1] == 'p' && !token
[2])
3124 /* Called from shell.c when Control-C is typed at top level. Or
3125 by the error rule at top level. */
3129 dstack
.delimiter_depth
= 0; /* No delimiters found so far. */
3130 open_brace_count
= 0;
3135 if (pushed_string_list
)
3137 free_string_list ();
3138 pushed_string_list
= (STRING_SAVER
*)NULL
;
3142 if (shell_input_line
)
3144 free (shell_input_line
);
3145 shell_input_line
= (char *)NULL
;
3146 shell_input_line_size
= shell_input_line_index
= 0;
3149 FREE (word_desc_to_read
);
3150 word_desc_to_read
= (WORD_DESC
*)NULL
;
3152 last_read_token
= '\n';
3153 token_to_read
= '\n';
3156 /* Read the next token. Command can be READ (normal operation) or
3157 RESET (to normalize state). */
3159 read_token (command
)
3162 int character
; /* Current character. */
3163 int peek_char
; /* Temporary look-ahead character. */
3164 int result
; /* The thing to return. */
3166 if (command
== RESET
)
3174 result
= token_to_read
;
3175 if (token_to_read
== WORD
|| token_to_read
== ASSIGNMENT_WORD
)
3176 yylval
.word
= word_desc_to_read
;
3182 /* This is a place to jump back to once we have successfully expanded a
3183 token with an alias and pushed the string with push_string () */
3187 /* Read a single word from input. Start by skipping blanks. */
3188 while ((character
= shell_getc (1)) != EOF
&& whitespace (character
))
3191 if (character
== EOF
)
3197 if (character
== '#' && (!interactive
|| interactive_comments
))
3199 /* A comment. Discard until EOL or EOF, and then return a newline. */
3200 discard_until ('\n');
3202 character
= '\n'; /* this will take the next if statement and return. */
3205 if (character
== '\n')
3207 /* If we're about to return an unquoted newline, we can go and collect
3208 the text of any pending here document. */
3210 gather_here_documents ();
3213 parser_state
&= ~PST_ALEXPNEXT
;
3219 /* Shell meta-characters. */
3220 if (shellmeta (character
) && ((parser_state
& PST_DBLPAREN
) == 0))
3223 /* Turn off alias tokenization iff this character sequence would
3224 not leave us ready to read a command. */
3225 if (character
== '<' || character
== '>')
3226 parser_state
&= ~PST_ALEXPNEXT
;
3229 peek_char
= shell_getc (1);
3230 if (character
== peek_char
)
3235 /* If '<' then we could be at "<<" or at "<<-". We have to
3236 look ahead one more character. */
3237 peek_char
= shell_getc (1);
3238 if (peek_char
== '-')
3239 return (LESS_LESS_MINUS
);
3242 shell_ungetc (peek_char
);
3247 return (GREATER_GREATER
);
3250 parser_state
|= PST_CASEPAT
;
3252 parser_state
&= ~PST_ALEXPNEXT
;
3262 #if defined (DPAREN_ARITHMETIC)
3264 if (reserved_word_acceptable (last_read_token
))
3266 parser_state
|= PST_DBLPAREN
;
3267 yylval
.word
= make_word ("let");
3274 else if (character
== '<' && peek_char
== '&')
3276 else if (character
== '>' && peek_char
== '&')
3277 return (GREATER_AND
);
3278 else if (character
== '<' && peek_char
== '>')
3279 return (LESS_GREATER
);
3280 else if (character
== '>' && peek_char
== '|')
3281 return (GREATER_BAR
);
3282 else if (peek_char
== '>' && character
== '&')
3283 return (AND_GREATER
);
3285 shell_ungetc (peek_char
);
3287 /* If we look like we are reading the start of a function
3288 definition, then let the reader know about it so that
3289 we will do the right thing with `{'. */
3290 if (character
== ')' && last_read_token
== '(' && token_before_that
== WORD
)
3292 parser_state
|= PST_ALLOWOPNBRC
;
3294 parser_state
&= ~PST_ALEXPNEXT
;
3296 function_dstart
= line_number
;
3299 /* case pattern lists may be preceded by an optional left paren. If
3300 we're not trying to parse a case pattern list, the left paren
3301 indicates a subshell. */
3302 if (character
== '(' && (parser_state
& PST_CASEPAT
) == 0) /* ) */
3303 parser_state
|= PST_SUBSHELL
;
3305 else if ((parser_state
& PST_CASEPAT
) && character
== ')')
3306 parser_state
&= ~PST_CASEPAT
;
3308 else if ((parser_state
& PST_SUBSHELL
) && character
== ')')
3309 parser_state
&= ~PST_SUBSHELL
;
3311 #if defined (PROCESS_SUBSTITUTION)
3312 /* Check for the constructs which introduce process substitution.
3313 Shells running in `posix mode' don't do process substitution. */
3314 if (posixly_correct
||
3315 ((character
!= '>' && character
!= '<') || peek_char
!= '('))
3316 #endif /* PROCESS_SUBSTITUTION */
3320 /* Hack <&- (close stdin) case. */
3321 if (character
== '-' && (last_read_token
== LESS_AND
|| last_read_token
== GREATER_AND
))
3324 /* Okay, if we got this far, we have to read a word. Read one,
3325 and then check it against the known ones. */
3326 result
= read_token_word (character
);
3328 if (result
== RE_READ_TOKEN
)
3334 /* Match a $(...) or other grouping construct. This has to handle embedded
3335 quoted strings ('', ``, "") and nested constructs. It also must handle
3336 reprompting the user, if necessary, after reading a newline, and returning
3337 correct error values if it reads EOF. */
3338 static char matched_pair_error
;
3340 parse_matched_pair (qc
, open
, close
, lenp
, flags
)
3341 int qc
; /* `"' if this construct is within double quotes */
3345 int count
, ch
, was_dollar
;
3346 int pass_next_character
, nestlen
, start_lineno
;
3347 char *ret
, *nestret
;
3348 int retind
, retsize
;
3351 pass_next_character
= was_dollar
= 0;
3353 ret
= xmalloc (retsize
= 64);
3356 start_lineno
= line_number
;
3359 ch
= shell_getc (qc
!= '\'' && pass_next_character
== 0);
3363 parser_error (start_lineno
, "unexpected EOF while looking for matching `%c'", close
);
3364 EOF_Reached
= 1; /* XXX */
3365 return (&matched_pair_error
);
3368 /* Possible reprompting. */
3369 if (ch
== '\n' && interactive
&&
3370 (bash_input
.type
== st_stdin
|| bash_input
.type
== st_stream
))
3373 if (pass_next_character
) /* last char was backslash */
3375 pass_next_character
= 0;
3376 if (qc
!= '\'' && ch
== '\n') /* double-quoted \<newline> disappears. */
3378 if (retind
> 0) retind
--; /* swallow previously-added backslash */
3382 RESIZE_MALLOCED_BUFFER (ret
, retind
, 2, retsize
, 64);
3383 if (ch
== CTLESC
|| ch
== CTLNUL
)
3384 ret
[retind
++] = CTLESC
;
3388 else if (ch
== CTLESC
|| ch
== CTLNUL
) /* special shell escapes */
3390 RESIZE_MALLOCED_BUFFER (ret
, retind
, 2, retsize
, 64);
3391 ret
[retind
++] = CTLESC
;
3395 else if (ch
== close
) /* ending delimiter */
3397 else if (ch
== open
) /* nested begin */
3400 /* Add this character. */
3401 RESIZE_MALLOCED_BUFFER (ret
, retind
, 1, retsize
, 64);
3404 if (open
== '\'') /* '' inside grouping construct */
3407 if (ch
== '\\') /* backslashes */
3408 pass_next_character
++;
3410 if (open
!= close
) /* a grouping construct */
3412 if (shellquote (ch
))
3414 /* '', ``, or "" inside $(...) or other grouping construct. */
3415 push_delimiter (dstack
, ch
);
3416 nestret
= parse_matched_pair (ch
, ch
, ch
, &nestlen
, 0);
3417 pop_delimiter (dstack
);
3418 if (nestret
== &matched_pair_error
)
3421 return &matched_pair_error
;
3425 RESIZE_MALLOCED_BUFFER (ret
, retind
, nestlen
, retsize
, 64);
3426 strcpy (ret
+ retind
, nestret
);
3432 /* Parse an old-style command substitution within double quotes as a
3434 /* XXX - sh and ksh93 don't do this - XXX */
3435 else if (open
== '"' && ch
== '`')
3437 nestret
= parse_matched_pair (0, '`', '`', &nestlen
, 0);
3438 if (nestret
== &matched_pair_error
)
3441 return &matched_pair_error
;
3445 RESIZE_MALLOCED_BUFFER (ret
, retind
, nestlen
, retsize
, 64);
3446 strcpy (ret
+ retind
, nestret
);
3451 else if (was_dollar
&& (ch
== '(' || ch
== '{' || ch
== '[')) /* ) } ] */
3452 /* check for $(), $[], or ${} inside quoted string. */
3454 if (open
== ch
) /* undo previous increment */
3456 if (ch
== '(') /* ) */
3457 nestret
= parse_matched_pair (0, '(', ')', &nestlen
, 0);
3458 else if (ch
== '{') /* } */
3459 nestret
= parse_matched_pair (0, '{', '}', &nestlen
, 0);
3460 else if (ch
== '[') /* ] */
3461 nestret
= parse_matched_pair (0, '[', ']', &nestlen
, 0);
3462 if (nestret
== &matched_pair_error
)
3465 return &matched_pair_error
;
3469 RESIZE_MALLOCED_BUFFER (ret
, retind
, nestlen
, retsize
, 64);
3470 strcpy (ret
+ retind
, nestret
);
3475 was_dollar
= (ch
== '$');
3485 read_token_word (character
)
3488 /* The value for YYLVAL when a WORD is read. */
3489 WORD_DESC
*the_word
;
3491 /* Index into the token that we are building. */
3494 /* ALL_DIGITS becomes zero when we see a non-digit. */
3497 /* DOLLAR_PRESENT becomes non-zero if we see a `$'. */
3500 /* QUOTED becomes non-zero if we see one of ("), ('), (`), or (\). */
3503 /* Non-zero means to ignore the value of the next character, and just
3504 to add it no matter what. */
3505 int pass_next_character
;
3507 /* The current delimiting character. */
3509 int result
, peek_char
;
3510 char *ttok
, *ttrans
;
3511 int ttoklen
, ttranslen
;
3513 if (token_buffer_size
< TOKEN_DEFAULT_GROW_SIZE
)
3516 token
= xmalloc (token_buffer_size
= TOKEN_DEFAULT_GROW_SIZE
);
3520 all_digits
= digit (character
);
3521 dollar_present
= quoted
= pass_next_character
= 0;
3525 if (character
== EOF
)
3528 if (pass_next_character
)
3530 pass_next_character
= 0;
3534 cd
= current_delimiter (dstack
);
3536 /* Handle backslashes. Quote lots of things when not inside of
3537 double-quotes, quote some things inside of double-quotes. */
3538 if (character
== '\\')
3540 peek_char
= shell_getc (0);
3542 /* Backslash-newline is ignored in all cases except
3543 when quoted with single quotes. */
3544 if (peek_char
== '\n')
3547 goto next_character
;
3551 shell_ungetc (peek_char
);
3553 /* If the next character is to be quoted, note it now. */
3554 if (cd
== 0 || cd
== '`' ||
3555 (cd
== '"' && member (peek_char
, slashify_in_quotes
)))
3556 pass_next_character
++;
3563 #if defined (DPAREN_ARITHMETIC)
3564 /* Parse a ksh-style ((...)) expression. */
3565 if (parser_state
& PST_DBLPAREN
)
3569 /* If we've already consumed a right paren that should be part of
3570 the expression, push it back so the paren matching code won't
3571 return prematurely. */
3572 if (character
== '(') /* ) */
3573 shell_ungetc (character
);
3574 exp_lineno
= line_number
;
3575 ttok
= parse_matched_pair (0, '(', ')', &ttoklen
, 0);
3576 parser_state
&= ~PST_DBLPAREN
;
3577 if (ttok
== &matched_pair_error
)
3579 /* Check that the next character is the closing right paren. If
3580 not, this is a syntax error. ( */
3581 if (shell_getc (0) != ')')
3583 FREE (ttok
); /* ( */
3584 parser_error (exp_lineno
, "missing closing `)' for arithmetic expression");
3587 RESIZE_MALLOCED_BUFFER (token
, token_index
, ttoklen
+ 4,
3588 token_buffer_size
, TOKEN_DEFAULT_GROW_SIZE
);
3589 token
[token_index
++] = '"';
3590 if (character
!= '(') /* ) */
3591 token
[token_index
++] = character
;
3592 strncpy (token
+ token_index
, ttok
, ttoklen
- 1);
3593 token_index
+= ttoklen
- 1;
3594 token
[token_index
++] = '"';
3596 dollar_present
= all_digits
= 0;
3600 #endif /* DPAREN_ARITHMETIC */
3602 /* Parse a matched pair of quote characters. */
3603 if (shellquote (character
))
3605 push_delimiter (dstack
, character
);
3606 ttok
= parse_matched_pair (character
, character
, character
, &ttoklen
, 0);
3607 pop_delimiter (dstack
);
3608 if (ttok
== &matched_pair_error
)
3609 return -1; /* Bail immediately. */
3610 RESIZE_MALLOCED_BUFFER (token
, token_index
, ttoklen
+ 2,
3611 token_buffer_size
, TOKEN_DEFAULT_GROW_SIZE
);
3612 token
[token_index
++] = character
;
3613 strcpy (token
+ token_index
, ttok
);
3614 token_index
+= ttoklen
;
3617 dollar_present
|= (character
== '"' && strchr (ttok
, '$') != 0);
3619 goto next_character
;
3622 /* If the delimiter character is not single quote, parse some of
3623 the shell expansions that must be read as a single word. */
3624 #if defined (PROCESS_SUBSTITUTION)
3625 if (character
== '$' || character
== '<' || character
== '>')
3627 if (character
== '$')
3628 #endif /* !PROCESS_SUBSTITUTION */
3630 peek_char
= shell_getc (1);
3631 /* $(...), <(...), >(...), $((...)), ${...}, and $[...] constructs */
3632 if (peek_char
== '(' ||
3633 ((peek_char
== '{' || peek_char
== '[') && character
== '$')) /* ) ] } */
3635 if (peek_char
== '{') /* } */
3636 ttok
= parse_matched_pair (cd
, '{', '}', &ttoklen
, 0);
3637 else if (peek_char
== '(') /* ) */
3638 ttok
= parse_matched_pair (cd
, '(', ')', &ttoklen
, 0);
3640 ttok
= parse_matched_pair (cd
, '[', ']', &ttoklen
, 0);
3641 if (ttok
== &matched_pair_error
)
3642 return -1; /* Bail immediately. */
3643 RESIZE_MALLOCED_BUFFER (token
, token_index
, ttoklen
+ 2,
3645 TOKEN_DEFAULT_GROW_SIZE
);
3646 token
[token_index
++] = character
;
3647 token
[token_index
++] = peek_char
;
3648 strcpy (token
+ token_index
, ttok
);
3649 token_index
+= ttoklen
;
3653 goto next_character
;
3655 /* This handles $'...' and $"..." new-style quoted strings. */
3656 else if (character
== '$' && (peek_char
== '\'' || peek_char
== '"'))
3658 ttok
= parse_matched_pair (peek_char
, peek_char
, peek_char
, &ttoklen
, 0);
3659 if (ttok
== &matched_pair_error
)
3661 if (peek_char
== '\'')
3662 ttrans
= ansiexpand (ttok
, 0, ttoklen
- 1, &ttranslen
);
3664 ttrans
= localeexpand (ttok
, 0, ttoklen
- 1, &ttranslen
);
3666 RESIZE_MALLOCED_BUFFER (token
, token_index
, ttranslen
+ 2,
3668 TOKEN_DEFAULT_GROW_SIZE
);
3669 token
[token_index
++] = peek_char
;
3670 strcpy (token
+ token_index
, ttrans
);
3671 token_index
+= ttranslen
;
3672 token
[token_index
++] = peek_char
;
3676 goto next_character
;
3679 shell_ungetc (peek_char
);
3682 #if defined (ARRAY_VARS)
3683 /* Identify possible compound array variable assignment. */
3684 else if (character
== '=')
3686 peek_char
= shell_getc (1);
3687 if (peek_char
== '(') /* ) */
3689 ttok
= parse_matched_pair (cd
, '(', ')', &ttoklen
, 0);
3690 if (ttok
== &matched_pair_error
)
3691 return -1; /* Bail immediately. */
3692 RESIZE_MALLOCED_BUFFER (token
, token_index
, ttoklen
+ 2,
3694 TOKEN_DEFAULT_GROW_SIZE
);
3695 token
[token_index
++] = character
;
3696 token
[token_index
++] = peek_char
;
3697 strcpy (token
+ token_index
, ttok
);
3698 token_index
+= ttoklen
;
3701 goto next_character
;
3704 shell_ungetc (peek_char
);
3708 /* When not parsing a multi-character word construct, shell meta-
3709 characters break words. */
3710 if (shellbreak (character
))
3712 shell_ungetc (character
);
3718 all_digits
&= digit (character
);
3719 dollar_present
|= character
== '$';
3721 if (character
== CTLESC
|| character
== CTLNUL
)
3722 token
[token_index
++] = CTLESC
;
3724 token
[token_index
++] = character
;
3726 RESIZE_MALLOCED_BUFFER (token
, token_index
, 1, token_buffer_size
,
3727 TOKEN_DEFAULT_GROW_SIZE
);
3730 if (character
== '\n' && interactive
&&
3731 (bash_input
.type
== st_stdin
|| bash_input
.type
== st_stream
))
3734 /* We want to remove quoted newlines (that is, a \<newline> pair)
3735 unless we are within single quotes or pass_next_character is
3736 set (the shell equivalent of literal-next). */
3737 cd
= current_delimiter (dstack
);
3738 character
= shell_getc (cd
!= '\'' && pass_next_character
== 0);
3739 } /* end for (;;) */
3743 token
[token_index
] = '\0';
3745 /* Check to see what thing we should return. If the last_read_token
3746 is a `<', or a `&', or the character which ended this token is
3747 a '>' or '<', then, and ONLY then, is this input token a NUMBER.
3748 Otherwise, it is just a word, and should be returned as such. */
3749 if (all_digits
&& (character
== '<' || character
== '>' ||
3750 last_read_token
== LESS_AND
||
3751 last_read_token
== GREATER_AND
))
3753 yylval
.number
= atoi (token
);
3757 /* Check for special case tokens. */
3758 result
= special_case_tokens (token
);
3763 /* Posix.2 does not allow reserved words to be aliased, so check for all
3764 of them, including special cases, before expanding the current token
3766 if (posixly_correct
)
3767 CHECK_FOR_RESERVED_WORD (token
);
3769 /* Aliases are expanded iff EXPAND_ALIASES is non-zero, and quoting
3770 inhibits alias expansion. */
3771 if (expand_aliases
&& quoted
== 0)
3773 result
= alias_expand_token (token
);
3774 if (result
== RE_READ_TOKEN
)
3775 return (RE_READ_TOKEN
);
3776 else if (result
== NO_EXPANSION
)
3777 parser_state
&= ~PST_ALEXPNEXT
;
3780 /* If not in Posix.2 mode, check for reserved words after alias
3782 if (posixly_correct
== 0)
3784 CHECK_FOR_RESERVED_WORD (token
);
3786 the_word
= (WORD_DESC
*)xmalloc (sizeof (WORD_DESC
));
3787 the_word
->word
= xmalloc (1 + token_index
);
3788 the_word
->flags
= 0;
3789 strcpy (the_word
->word
, token
);
3791 the_word
->flags
|= W_HASDOLLAR
;
3793 the_word
->flags
|= W_QUOTED
;
3794 /* A word is an assignment if it appears at the beginning of a
3795 simple command, or after another assignment word. This is
3796 context-dependent, so it cannot be handled in the grammar. */
3797 if (assignment (token
))
3799 the_word
->flags
|= W_ASSIGNMENT
;
3800 /* Don't perform word splitting on assignment statements. */
3801 if (assignment_acceptable (last_read_token
))
3802 the_word
->flags
|= W_NOSPLIT
;
3805 yylval
.word
= the_word
;
3807 result
= ((the_word
->flags
& (W_ASSIGNMENT
|W_NOSPLIT
)) == (W_ASSIGNMENT
|W_NOSPLIT
))
3808 ? ASSIGNMENT_WORD
: WORD
;
3810 if (last_read_token
== FUNCTION
)
3812 parser_state
|= PST_ALLOWOPNBRC
;
3813 function_dstart
= line_number
;
3819 /* $'...' ANSI-C expand the portion of STRING between START and END and
3820 return the result. The result cannot be longer than the input string. */
3822 ansiexpand (string
, start
, end
, lenp
)
3824 int start
, end
, *lenp
;
3829 temp
= xmalloc (end
- start
+ 1);
3830 for (tlen
= 0, len
= start
; len
< end
; )
3831 temp
[tlen
++] = string
[len
++];
3836 t
= ansicstr (temp
, tlen
, (int *)NULL
);
3850 /* $"..." -- Translate the portion of STRING between START and END
3851 according to current locale using gettext (if available) and return
3852 the result. The caller will take care of leaving the quotes intact.
3853 The string will be left without the leading `$' by the caller.
3854 If translation is performed, the translated string will be double-quoted
3855 by the caller. The length of the translated string is returned in LENP,
3858 localeexpand (string
, start
, end
, lenp
)
3860 int start
, end
, *lenp
;
3865 temp
= xmalloc (end
- start
+ 1);
3866 for (tlen
= 0, len
= start
; len
< end
; )
3867 temp
[tlen
++] = string
[len
++];
3870 /* If we're just dumping translatable strings, don't do anything. */
3871 if (dump_translatable_strings
)
3873 printf ("\"%s\"\n", temp
);
3880 t
= localetrans (temp
, tlen
, &len
);
3894 /* Return 1 if TOKEN is a token that after being read would allow
3895 a reserved word to be seen, else 0. */
3897 reserved_word_acceptable (token
)
3900 if (token
== '\n' || token
== ';' || token
== '(' || token
== ')' ||
3901 token
== '|' || token
== '&' || token
== '{' ||
3902 token
== '}' || /* XXX */
3905 token
== TIME
|| token
== TIMEOPT
||
3912 token
== SEMI_SEMI
||
3916 token
== DONE
|| /* XXX these two are experimental */
3924 /* Return the index of TOKEN in the alist of reserved words, or -1 if
3925 TOKEN is not a shell reserved word. */
3927 find_reserved_word (token
)
3931 for (i
= 0; word_token_alist
[i
].word
; i
++)
3932 if (STREQ (token
, word_token_alist
[i
].word
))
3938 #if defined (READLINE)
3939 /* Called after each time readline is called. This insures that whatever
3940 the new prompt string is gets propagated to readline's local prompt
3943 reset_readline_prompt ()
3947 if (prompt_string_pointer
)
3949 temp_prompt
= (*prompt_string_pointer
)
3950 ? decode_prompt_string (*prompt_string_pointer
)
3953 if (temp_prompt
== 0)
3955 temp_prompt
= xmalloc (1);
3956 temp_prompt
[0] = '\0';
3959 FREE (current_readline_prompt
);
3960 current_readline_prompt
= temp_prompt
;
3963 #endif /* READLINE */
3966 #if defined (HISTORY)
3967 /* A list of tokens which can be followed by newlines, but not by
3968 semi-colons. When concatenating multiple lines of history, the
3969 newline separator for such tokens is replaced with a space. */
3970 static int no_semi_successors
[] = {
3971 '\n', '{', '(', ')', ';', '&', '|',
3972 CASE
, DO
, ELSE
, IF
, SEMI_SEMI
, THEN
, UNTIL
, WHILE
, AND_AND
, OR_OR
, IN
,
3976 /* If we are not within a delimited expression, try to be smart
3977 about which separators can be semi-colons and which must be
3978 newlines. Returns the string that should be added into the
3981 history_delimiting_chars ()
3985 if (dstack
.delimiter_depth
!= 0)
3988 /* First, handle some special cases. */
3990 /* If we just read `()', assume it's a function definition, and don't
3991 add a semicolon. If the token before the `)' was not `(', and we're
3992 not in the midst of parsing a case statement, assume it's a
3993 parenthesized command and add the semicolon. */
3995 if (token_before_that
== ')')
3997 if (two_tokens_ago
== '(') /*)*/ /* function def */
3999 /* This does not work for subshells inside case statement
4000 command lists. It's a suboptimal solution. */
4001 else if (parser_state
& PST_CASESTMT
) /* case statement pattern */
4004 return "; "; /* (...) subshell */
4007 for (i
= 0; no_semi_successors
[i
]; i
++)
4009 if (token_before_that
== no_semi_successors
[i
])
4015 #endif /* HISTORY */
4017 /* Issue a prompt, or prepare to issue a prompt when the next character
4024 if (!interactive
) /* XXX */
4027 ps1_prompt
= get_string_value ("PS1");
4028 ps2_prompt
= get_string_value ("PS2");
4030 if (!prompt_string_pointer
)
4031 prompt_string_pointer
= &ps1_prompt
;
4033 temp_prompt
= *prompt_string_pointer
4034 ? decode_prompt_string (*prompt_string_pointer
)
4037 if (temp_prompt
== 0)
4039 temp_prompt
= xmalloc (1);
4040 temp_prompt
[0] = '\0';
4043 current_prompt_string
= *prompt_string_pointer
;
4044 prompt_string_pointer
= &ps2_prompt
;
4046 #if defined (READLINE)
4047 if (!no_line_editing
)
4049 FREE (current_readline_prompt
);
4050 current_readline_prompt
= temp_prompt
;
4053 #endif /* READLINE */
4055 FREE (current_decoded_prompt
);
4056 current_decoded_prompt
= temp_prompt
;
4063 fprintf (stderr
, "%s", current_decoded_prompt
);
4067 /* Return a string which will be printed as a prompt. The string
4068 may contain special characters which are decoded as follows:
4071 \e escape (ascii 033)
4072 \d the date in Day Mon Date format
4073 \h the hostname up to the first `.'
4076 \s the name of the shell
4077 \t the time in 24-hour hh:mm:ss format
4078 \T the time in 12-hour hh:mm:ss format
4079 \@ the time in 12-hour am/pm format
4080 \v the version of bash (e.g., 2.00)
4081 \V the release of bash, version + patchlevel (e.g., 2.00.0)
4082 \w the current working directory
4083 \W the last element of $PWD
4085 \# the command number of this command
4086 \! the history number of this command
4087 \$ a $ or a # if you are root
4088 \nnn character code nnn in octal
4090 \[ begin a sequence of non-printing chars
4091 \] end a sequence of non-printing chars
4093 #define PROMPT_GROWTH 50
4095 decode_prompt_string (string
)
4100 struct dstack save_dstack
;
4101 #if defined (PROMPT_STRING_DECODE)
4102 int result_size
, result_index
;
4104 char *temp
, octal_string
[4];
4107 result
= xmalloc (result_size
= PROMPT_GROWTH
);
4108 result
[result_index
= 0] = 0;
4109 temp
= (char *)NULL
;
4111 while (c
= *string
++)
4113 if (posixly_correct
&& c
== '!')
4117 temp
= savestring ("!");
4122 #if !defined (HISTORY)
4123 temp
= savestring ("1");
4125 temp
= itos (history_number ());
4126 #endif /* HISTORY */
4127 string
--; /* add_string increments string again. */
4145 strncpy (octal_string
, string
, 3);
4146 octal_string
[3] = '\0';
4148 n
= read_octal (octal_string
);
4151 if (n
== CTLESC
|| n
== CTLNUL
)
4177 /* Make the current time/date into a string. */
4178 the_time
= time (0);
4179 temp
= ctime (&the_time
);
4181 temp
= (c
!= 'd') ? savestring (temp
+ 11) : savestring (temp
);
4182 temp
[(c
!= 'd') ? 8 : 10] = '\0';
4184 /* quick and dirty conversion to 12-hour time */
4185 if (c
== 'T' || c
== '@')
4189 temp
[5] = 'a'; /* am/pm format */
4200 temp
[0] = (n
/ 10) + '0';
4201 temp
[1] = (n
% 10) + '0';
4203 if (n
>= 0 && temp
[5] == 'a')
4210 temp
[0] = no_line_editing
? '\n' : '\r';
4211 temp
[1] = no_line_editing
? '\0' : '\n';
4216 temp
= base_pathname (shell_name
);
4217 temp
= savestring (temp
);
4224 strcpy (temp
, dist_version
);
4226 sprintf (temp
, "%s.%d", dist_version
, patch_level
);
4232 /* Use the value of PWD because it is much more efficient. */
4233 char t_string
[PATH_MAX
];
4235 temp
= get_string_value ("PWD");
4239 if (getcwd (t_string
, sizeof(t_string
)) == 0)
4246 strcpy (t_string
, temp
);
4250 t
= strrchr (t_string
, '/');
4251 if (t
&& t
!= t_string
)
4252 strcpy (t_string
, t
+ 1);
4255 strcpy (t_string
, polite_directory_format (t_string
));
4257 /* If we're going to be expanding the prompt string later,
4258 quote the directory name. */
4259 if (promptvars
|| posixly_correct
)
4260 temp
= backslash_quote (t_string
);
4262 temp
= savestring (t_string
);
4268 temp
= savestring (current_user
.user_name
);
4273 temp
= savestring (current_host_name
);
4274 if (c
== 'h' && (t
= (char *)strchr (temp
, '.')))
4279 temp
= itos (current_command_number
);
4283 #if !defined (HISTORY)
4284 temp
= savestring ("1");
4286 temp
= itos (history_number ());
4287 #endif /* HISTORY */
4292 temp
[0] = current_user
.euid
== 0 ? '#' : '$';
4296 #if defined (READLINE)
4301 temp
[1] = (c
== '[') ? RL_PROMPT_START_IGNORE
: RL_PROMPT_END_IGNORE
;
4304 #endif /* READLINE */
4315 temp
[0] = (c
== 'a') ? '\07' : '\033';
4329 sub_append_string (temp
, result
, &result_index
, &result_size
);
4330 temp
= (char *)NULL
; /* Freed in sub_append_string (). */
4331 result
[result_index
] = '\0';
4337 RESIZE_MALLOCED_BUFFER (result
, result_index
, 3, result_size
, PROMPT_GROWTH
);
4338 result
[result_index
++] = c
;
4339 result
[result_index
] = '\0';
4342 #else /* !PROMPT_STRING_DECODE */
4343 result
= savestring (string
);
4344 #endif /* !PROMPT_STRING_DECODE */
4346 /* Save the delimiter stack and point `dstack' to temp space so any
4347 command substitutions in the prompt string won't result in screwing
4348 up the parser's quoting state. */
4349 save_dstack
= dstack
;
4350 dstack
= temp_dstack
;
4351 dstack
.delimiter_depth
= 0;
4353 /* Perform variable and parameter expansion and command substitution on
4354 the prompt string. */
4355 if (promptvars
|| posixly_correct
)
4357 list
= expand_string_unsplit (result
, Q_DOUBLE_QUOTES
);
4359 result
= string_list (list
);
4360 dispose_words (list
);
4364 t
= dequote_string (result
);
4369 dstack
= save_dstack
;
4374 /* Report a syntax error, and restart the parser. Call here for fatal
4379 report_syntax_error ((char *)NULL
);
4384 /* Report a syntax error with line numbers, etc.
4385 Call here for recoverable errors. If you have a message to print,
4386 then place it in MESSAGE, otherwise pass NULL and this will figure
4387 out an appropriate message for you. */
4389 report_syntax_error (message
)
4398 parser_error (line_number
, "%s", message
);
4399 if (interactive
&& EOF_Reached
)
4401 last_command_exit_value
= EX_USAGE
;
4405 /* If the line of input we're reading is not null, try to find the
4406 objectionable token. */
4407 if (shell_input_line
&& *shell_input_line
)
4409 t
= shell_input_line
;
4410 i
= shell_input_line_index
;
4413 if (i
&& t
[i
] == '\0')
4416 while (i
&& (whitespace (t
[i
]) || t
[i
] == '\n'))
4422 while (i
&& (member (t
[i
], " \n\t;|&") == 0))
4425 while (i
!= token_end
&& (whitespace (t
[i
]) || t
[i
] == '\n'))
4428 /* Print the offending token. */
4429 if (token_end
|| (i
== 0 && token_end
== 0))
4433 msg
= xmalloc (1 + (token_end
- i
));
4434 strncpy (msg
, t
+ i
, token_end
- i
);
4435 msg
[token_end
- i
] = '\0';
4437 else /* one-character token */
4444 parser_error (line_number
, "syntax error near unexpected token `%s'", msg
);
4450 /* If not interactive, print the line containing the error. */
4451 if (interactive
== 0)
4453 msg
= savestring (shell_input_line
);
4454 token_end
= strlen (msg
);
4455 while (token_end
&& msg
[token_end
- 1] == '\n')
4456 msg
[--token_end
] = '\0';
4458 parser_error (line_number
, "`%s'", msg
);
4464 msg
= EOF_Reached
? "syntax error: unexpected end of file" : "syntax error";
4465 parser_error (line_number
, "%s", msg
);
4466 /* When the shell is interactive, this file uses EOF_Reached
4467 only for error reporting. Other mechanisms are used to
4468 decide whether or not to exit. */
4469 if (interactive
&& EOF_Reached
)
4472 last_command_exit_value
= EX_USAGE
;
4475 /* ??? Needed function. ??? We have to be able to discard the constructs
4476 created during parsing. In the case of error, we want to return
4477 allocated objects to the memory pool. In the case of no error, we want
4478 to throw away the information about where the allocated objects live.
4479 (dispose_command () will actually free the command. */
4481 discard_parser_constructs (error_p
)
4486 /* Do that silly `type "bye" to exit' stuff. You know, "ignoreeof". */
4488 /* A flag denoting whether or not ignoreeof is set. */
4491 /* The number of times that we have encountered an EOF character without
4492 another character intervening. When this gets above the limit, the
4493 shell terminates. */
4494 int eof_encountered
= 0;
4496 /* The limit for eof_encountered. */
4497 int eof_encountered_limit
= 10;
4499 /* If we have EOF as the only input unit, this user wants to leave
4500 the shell. If the shell is not interactive, then just leave.
4501 Otherwise, if ignoreeof is set, and we haven't done this the
4502 required number of times in a row, print a message. */
4504 handle_eof_input_unit ()
4508 /* shell.c may use this to decide whether or not to write out the
4509 history, among other things. We use it only for error reporting
4514 /* If the user wants to "ignore" eof, then let her do so, kind of. */
4517 if (eof_encountered
< eof_encountered_limit
)
4519 fprintf (stderr
, "Use \"%s\" to leave the shell.\n",
4520 login_shell
? "logout" : "exit");
4522 /* Reset the prompt string to be $PS1. */
4523 prompt_string_pointer
= (char **)NULL
;
4525 last_read_token
= current_token
= '\n';
4530 /* In this case EOF should exit the shell. Do it now. */
4532 exit_builtin ((WORD_LIST
*)NULL
);
4536 /* We don't write history files, etc., for non-interactive shells. */