2 /* A Bison parser, made from ./parse.y
3 by GNU Bison version 1.25
6 #define YYBISON 1 /* Identify Bison output. */
25 #define ASSIGNMENT_WORD 275
29 #define GREATER_GREATER 279
32 #define GREATER_AND 282
34 #define LESS_LESS_MINUS 284
35 #define AND_GREATER 285
36 #define LESS_GREATER 286
37 #define GREATER_BAR 287
43 #include "bashtypes.h"
50 #if defined (READLINE)
51 # include <readline/readline.h>
55 # include "bashhist.h"
56 # include <readline/history.h>
59 #if defined (JOB_CONTROL)
61 #endif /* JOB_CONTROL */
67 #if defined (PROMPT_STRING_DECODE)
68 #include <sys/param.h>
71 #endif /* PROMPT_STRING_DECODE */
74 extern int eof_encountered;
75 extern int no_line_editing;
76 extern int current_command_number;
77 extern int interactive, interactive_shell, login_shell;
78 extern int posixly_correct;
79 extern int last_command_exit_value;
80 extern int interrupt_immediately;
81 extern char *shell_name, *current_host_name;
82 extern Function *last_shell_builtin, *this_shell_builtin;
83 #if defined (READLINE)
84 extern int bash_readline_initialized;
86 #if defined (BUFFERED_INPUT)
87 extern int bash_input_fd_changed;
90 /* **************************************************************** */
92 /* "Forward" declarations */
94 /* **************************************************************** */
96 /* This is kind of sickening. In order to let these variables be seen by
97 all the functions that need them, I am forced to place their declarations
98 far away from the place where they should logically be found. */
100 static int reserved_word_acceptable ();
101 static int read_token ();
103 static void report_syntax_error ();
104 static void handle_eof_input_unit ();
105 static void prompt_again ();
106 static void reset_readline_prompt ();
107 static void print_prompt ();
109 /* PROMPT_STRING_POINTER points to one of these, never to an actual string. */
110 char *ps1_prompt, *ps2_prompt;
112 /* Handle on the current prompt string. Indirectly points through
113 ps1_ or ps2_prompt. */
114 char **prompt_string_pointer = (char **)NULL;
115 char *current_prompt_string;
117 /* The decoded prompt string. Used if READLINE is not defined or if
118 editing is turned off. Analogous to current_readline_prompt. */
119 static char *current_decoded_prompt;
121 /* The number of lines read from input while creating the current command. */
122 int current_command_line_count = 0;
124 /* Variables to manage the task of reading here documents, because we need to
125 defer the reading until after a complete command has been collected. */
126 static REDIRECT *redir_stack[10];
127 int need_here_doc = 0;
129 /* Where shell input comes from. History expansion is performed on each
130 line when the shell is interactive. */
131 static char *shell_input_line = (char *)NULL;
132 static int shell_input_line_index = 0;
133 static int shell_input_line_size = 0; /* Amount allocated for shell_input_line. */
134 static int shell_input_line_len = 0; /* strlen (shell_input_line) */
136 /* Either zero or EOF. */
137 static int shell_input_line_terminator = 0;
139 static REDIRECTEE redir;
141 #line 122 "./parse.y"
143 WORD_DESC *word; /* the word that we read. */
144 int number; /* the number that we read. */
145 WORD_LIST *word_list;
149 PATTERN_LIST *pattern;
162 #define YYFLAG -32768
165 #define YYTRANSLATE(x) ((unsigned)(x) <= 288 ? yytranslate[x] : 73)
167 static const char yytranslate[] = { 0,
168 2, 2, 2, 2, 2, 2, 2, 2, 2, 35,
169 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
170 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
171 2, 2, 2, 2, 2, 2, 2, 33, 2, 43,
172 44, 2, 2, 2, 40, 2, 2, 2, 2, 2,
173 2, 2, 2, 2, 2, 2, 2, 2, 34, 39,
174 2, 38, 2, 2, 2, 2, 2, 2, 2, 2,
175 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
176 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
177 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
178 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
179 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
180 2, 2, 41, 37, 42, 2, 2, 2, 2, 2,
181 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
182 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
183 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
184 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
185 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
186 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
187 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
188 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
189 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
190 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
191 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
192 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
193 2, 2, 2, 2, 2, 1, 2, 3, 4, 5,
194 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
195 16, 17, 18, 19, 20, 21, 22, 23, 24, 25,
196 26, 27, 28, 29, 30, 31, 32, 36
200 static const short yyprhs[] = { 0,
201 0, 3, 5, 8, 10, 11, 14, 17, 20, 24,
202 28, 31, 35, 38, 42, 45, 49, 52, 56, 59,
203 63, 66, 70, 73, 77, 80, 84, 87, 91, 94,
204 98, 101, 104, 108, 110, 112, 114, 116, 119, 121,
205 124, 126, 128, 130, 133, 140, 147, 155, 163, 174,
206 185, 192, 200, 207, 213, 219, 221, 223, 225, 227,
207 229, 236, 243, 251, 259, 270, 281, 287, 294, 301,
208 309, 314, 320, 324, 330, 338, 345, 349, 354, 361,
209 367, 369, 372, 377, 382, 388, 394, 396, 399, 405,
210 411, 418, 425, 427, 431, 434, 436, 440, 444, 448,
211 453, 458, 463, 468, 473, 475, 478, 480, 482, 484,
212 485, 488, 490, 493, 496, 501, 506, 510, 514, 516,
216 static const short yyrhs[] = { 70,
217 35, 0, 35, 0, 1, 35, 0, 36, 0, 0,
218 46, 19, 0, 38, 19, 0, 39, 19, 0, 21,
219 38, 19, 0, 21, 39, 19, 0, 24, 19, 0,
220 21, 24, 19, 0, 25, 19, 0, 21, 25, 19,
221 0, 26, 21, 0, 21, 26, 21, 0, 27, 21,
222 0, 21, 27, 21, 0, 26, 19, 0, 21, 26,
223 19, 0, 27, 19, 0, 21, 27, 19, 0, 29,
224 19, 0, 21, 29, 19, 0, 27, 40, 0, 21,
225 27, 40, 0, 26, 40, 0, 21, 26, 40, 0,
226 30, 19, 0, 21, 31, 19, 0, 31, 19, 0,
227 32, 19, 0, 21, 32, 19, 0, 19, 0, 20,
228 0, 47, 0, 47, 0, 49, 47, 0, 48, 0,
229 50, 48, 0, 50, 0, 52, 0, 53, 0, 53,
230 49, 0, 10, 19, 69, 14, 65, 15, 0, 10,
231 19, 69, 41, 65, 42, 0, 10, 19, 34, 69,
232 14, 65, 15, 0, 10, 19, 34, 69, 41, 65,
233 42, 0, 10, 19, 69, 17, 46, 68, 69, 14,
234 65, 15, 0, 10, 19, 69, 17, 46, 68, 69,
235 41, 65, 42, 0, 8, 19, 69, 17, 69, 9,
236 0, 8, 19, 69, 17, 62, 69, 9, 0, 8,
237 19, 69, 17, 60, 9, 0, 12, 65, 14, 65,
238 15, 0, 13, 65, 14, 65, 15, 0, 54, 0,
239 57, 0, 56, 0, 58, 0, 55, 0, 11, 19,
240 69, 14, 65, 15, 0, 11, 19, 69, 41, 65,
241 42, 0, 11, 19, 34, 69, 14, 65, 15, 0,
242 11, 19, 34, 69, 41, 65, 42, 0, 11, 19,
243 69, 17, 46, 68, 69, 14, 65, 15, 0, 11,
244 19, 69, 17, 46, 68, 69, 41, 65, 42, 0,
245 19, 43, 44, 69, 58, 0, 19, 43, 44, 69,
246 58, 49, 0, 16, 19, 43, 44, 69, 58, 0,
247 16, 19, 43, 44, 69, 58, 49, 0, 16, 19,
248 69, 58, 0, 16, 19, 69, 58, 49, 0, 43,
249 65, 44, 0, 3, 65, 4, 65, 7, 0, 3,
250 65, 4, 65, 5, 65, 7, 0, 3, 65, 4,
251 65, 59, 7, 0, 41, 65, 42, 0, 6, 65,
252 4, 65, 0, 6, 65, 4, 65, 5, 65, 0,
253 6, 65, 4, 65, 59, 0, 61, 0, 62, 61,
254 0, 69, 64, 44, 65, 0, 69, 64, 44, 69,
255 0, 69, 43, 64, 44, 65, 0, 69, 43, 64,
256 44, 69, 0, 63, 0, 62, 63, 0, 69, 64,
257 44, 65, 28, 0, 69, 64, 44, 69, 28, 0,
258 69, 43, 64, 44, 65, 28, 0, 69, 43, 64,
259 44, 69, 28, 0, 19, 0, 64, 37, 19, 0,
260 69, 66, 0, 67, 0, 67, 35, 69, 0, 67,
261 33, 69, 0, 67, 34, 69, 0, 67, 22, 69,
262 67, 0, 67, 23, 69, 67, 0, 67, 33, 69,
263 67, 0, 67, 34, 69, 67, 0, 67, 35, 69,
264 67, 0, 72, 0, 18, 72, 0, 35, 0, 34,
265 0, 36, 0, 0, 69, 35, 0, 71, 0, 71,
266 33, 0, 71, 34, 0, 71, 22, 69, 71, 0,
267 71, 23, 69, 71, 0, 71, 33, 71, 0, 71,
268 34, 71, 0, 72, 0, 18, 72, 0, 72, 37,
275 static const short yyrline[] = { 0,
276 163, 172, 179, 195, 205, 207, 211, 216, 221, 226,
277 231, 236, 241, 247, 253, 258, 263, 268, 273, 278,
278 283, 288, 293, 300, 307, 312, 317, 322, 327, 332,
279 337, 353, 358, 365, 367, 369, 373, 377, 388, 390,
280 394, 396, 400, 402, 417, 419, 421, 423, 425, 427,
281 430, 432, 434, 436, 438, 440, 442, 444, 446, 448,
282 452, 458, 464, 470, 476, 482, 490, 493, 496, 499,
283 502, 505, 509, 513, 515, 517, 522, 526, 528, 530,
284 534, 535, 539, 541, 543, 545, 549, 550, 554, 556,
285 558, 560, 564, 566, 575, 583, 584, 585, 592, 596,
286 598, 600, 607, 609, 611, 613, 620, 621, 622, 625,
287 626, 635, 641, 650, 658, 660, 662, 669, 671, 673,
293 #if YYDEBUG != 0 || defined (YYERROR_VERBOSE)
295 static const char * const yytname[] = { "$","error","$undefined.","IF","THEN",
296 "ELSE","ELIF","FI","CASE","ESAC","FOR","SELECT","WHILE","UNTIL","DO","DONE",
297 "FUNCTION","IN","BANG","WORD","ASSIGNMENT_WORD","NUMBER","AND_AND","OR_OR","GREATER_GREATER",
298 "LESS_LESS","LESS_AND","GREATER_AND","SEMI_SEMI","LESS_LESS_MINUS","AND_GREATER",
299 "LESS_GREATER","GREATER_BAR","'&'","';'","'\\n'","yacc_EOF","'|'","'>'","'<'",
300 "'-'","'{'","'}'","'('","')'","inputunit","words","redirection","simple_command_element",
301 "redirections","simple_command","command","shell_command","shell_command_1",
302 "select_command","function_def","subshell","if_command","group_command","elif_clause",
303 "case_clause_1","pattern_list_1","case_clause_sequence","pattern_list","pattern",
304 "list","list0","list1","list_terminator","newlines","simple_list","simple_list1",
309 static const short yyr1[] = { 0,
310 45, 45, 45, 45, 46, 46, 47, 47, 47, 47,
311 47, 47, 47, 47, 47, 47, 47, 47, 47, 47,
312 47, 47, 47, 47, 47, 47, 47, 47, 47, 47,
313 47, 47, 47, 48, 48, 48, 49, 49, 50, 50,
314 51, 51, 52, 52, 53, 53, 53, 53, 53, 53,
315 53, 53, 53, 53, 53, 53, 53, 53, 53, 53,
316 54, 54, 54, 54, 54, 54, 55, 55, 55, 55,
317 55, 55, 56, 57, 57, 57, 58, 59, 59, 59,
318 60, 60, 61, 61, 61, 61, 62, 62, 63, 63,
319 63, 63, 64, 64, 65, 66, 66, 66, 66, 67,
320 67, 67, 67, 67, 67, 67, 68, 68, 68, 69,
321 69, 70, 70, 70, 71, 71, 71, 71, 71, 71,
325 static const short yyr2[] = { 0,
326 2, 1, 2, 1, 0, 2, 2, 2, 3, 3,
327 2, 3, 2, 3, 2, 3, 2, 3, 2, 3,
328 2, 3, 2, 3, 2, 3, 2, 3, 2, 3,
329 2, 2, 3, 1, 1, 1, 1, 2, 1, 2,
330 1, 1, 1, 2, 6, 6, 7, 7, 10, 10,
331 6, 7, 6, 5, 5, 1, 1, 1, 1, 1,
332 6, 6, 7, 7, 10, 10, 5, 6, 6, 7,
333 4, 5, 3, 5, 7, 6, 3, 4, 6, 5,
334 1, 2, 4, 4, 5, 5, 1, 2, 5, 5,
335 6, 6, 1, 3, 2, 1, 3, 3, 3, 4,
336 4, 4, 4, 4, 1, 2, 1, 1, 1, 0,
337 2, 1, 2, 2, 4, 4, 3, 3, 1, 2,
341 static const short yydefact[] = { 0,
342 0, 110, 0, 0, 0, 110, 110, 0, 0, 34,
343 35, 0, 0, 0, 0, 0, 0, 0, 0, 0,
344 2, 4, 0, 0, 110, 110, 36, 39, 41, 122,
345 42, 43, 56, 60, 58, 57, 59, 0, 112, 119,
346 3, 0, 0, 110, 110, 110, 0, 0, 110, 120,
347 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
348 11, 13, 19, 15, 27, 21, 17, 25, 23, 29,
349 31, 32, 7, 8, 0, 0, 34, 40, 37, 44,
350 1, 110, 110, 113, 114, 110, 110, 0, 111, 95,
351 96, 105, 0, 110, 0, 110, 0, 110, 110, 0,
352 0, 110, 12, 14, 20, 16, 28, 22, 18, 26,
353 24, 30, 33, 9, 10, 77, 73, 38, 0, 0,
354 117, 118, 0, 0, 106, 110, 110, 110, 110, 110,
355 110, 0, 110, 5, 110, 0, 110, 5, 110, 0,
356 0, 110, 71, 0, 115, 116, 0, 0, 121, 110,
357 110, 74, 0, 0, 0, 98, 99, 97, 0, 81,
358 110, 87, 0, 110, 110, 0, 0, 0, 110, 110,
359 0, 0, 0, 54, 55, 0, 72, 67, 0, 0,
360 76, 100, 101, 102, 103, 104, 53, 82, 88, 0,
361 51, 93, 0, 0, 0, 0, 45, 6, 108, 107,
362 109, 110, 46, 0, 0, 61, 110, 62, 69, 68,
363 75, 110, 110, 110, 110, 52, 0, 0, 110, 47,
364 48, 0, 63, 64, 0, 70, 78, 0, 0, 0,
365 110, 94, 83, 84, 110, 110, 110, 110, 110, 80,
366 85, 86, 89, 90, 0, 0, 0, 0, 79, 91,
367 92, 49, 50, 65, 66, 0, 0, 0
370 static const short yydefgoto[] = { 256,
371 167, 27, 28, 80, 29, 30, 31, 32, 33, 34,
372 35, 36, 37, 153, 159, 160, 161, 162, 194, 42,
373 90, 91, 202, 43, 38, 121, 92
376 static const short yypact[] = { 233,
377 -28,-32768, 2, 10, 15,-32768,-32768, 32, 437, 19,
378 -32768, 494, 46, 52, -5, 39, 59, 61, 93, 95,
379 -32768,-32768, 102, 103,-32768,-32768,-32768,-32768, 462,-32768,
380 -32768, 478,-32768,-32768,-32768,-32768,-32768, 71, 116, 91,
381 -32768, 126, 301,-32768, 117, 118, 123, 139, 89, 91,
382 111, 137, 138, 75, 76, 141, 143, 146, 148, 149,
383 -32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,
384 -32768,-32768,-32768,-32768, 127, 131,-32768,-32768,-32768, 478,
385 -32768,-32768,-32768, 369, 369,-32768,-32768, 437,-32768,-32768,
386 101, 91, 37,-32768, -4,-32768, 22,-32768,-32768, 133,
387 -23,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,
388 -32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768, 335, 335,
389 60, 60, 403, 98, 91,-32768,-32768,-32768,-32768,-32768,
390 -32768, 3,-32768,-32768,-32768, 33,-32768,-32768,-32768, 167,
391 172,-32768, 478, -23,-32768,-32768, 369, 369, 91,-32768,
392 -32768,-32768, 181, 301, 301, 301, 301, 301, 186,-32768,
393 -32768,-32768, 21,-32768,-32768, 192, 83, 168,-32768,-32768,
394 194, 83, 175,-32768,-32768, -23, 478, 478, 208, 214,
395 -32768,-32768,-32768, 87, 87, 87,-32768,-32768,-32768, 24,
396 -32768,-32768, 200, -22, 205, 179,-32768,-32768,-32768,-32768,
397 -32768,-32768,-32768, 207, 182,-32768,-32768,-32768, 478, 478,
398 -32768,-32768,-32768,-32768,-32768,-32768, 29, 204,-32768,-32768,
399 -32768, 34,-32768,-32768, 35, 478, 135, 301, 301, 301,
400 -32768,-32768, 198, 173,-32768,-32768,-32768,-32768,-32768,-32768,
401 199, 267,-32768,-32768, 213, 193, 222, 196,-32768,-32768,
402 -32768,-32768,-32768,-32768,-32768, 239, 240,-32768
405 static const short yypgoto[] = {-32768,
406 104, -30, 218, -132,-32768,-32768,-32768,-32768,-32768,-32768,
407 -32768,-32768, -92, 28,-32768, 100,-32768, 105, 55, -6,
408 -32768, -130, 78, -41,-32768, 6, 23
415 static const short yytable[] = { 47,
416 48, 79, 93, 95, 97, 39, 41, 101, 143, 133,
417 177, 89, 134, 63, 218, 64, 164, 25, 75, 76,
418 44, 219, 40, 182, 183, 184, 185, 186, 45, 191,
419 89, 50, 216, 46, 65, 137, 135, 89, 138, 192,
420 119, 120, 192, 165, 123, 210, 169, 235, 237, 118,
421 49, 178, 132, 131, 136, 89, 89, 66, 89, 67,
422 144, 51, 139, 193, 61, 218, 193, 89, 89, 89,
423 62, 89, 231, 170, 236, 238, 226, 69, 68, 70,
424 124, 82, 83, 209, 154, 155, 156, 157, 158, 163,
425 122, 140, 141, 105, 108, 106, 109, 184, 185, 186,
426 176, 198, 150, 151, 152, 81, 40, 40, 126, 127,
427 125, 71, 79, 72, 107, 110, 199, 200, 201, 190,
428 73, 74, 126, 127, 145, 146, 166, 86, 168, 87,
429 171, 100, 173, 128, 129, 130, 98, 82, 83, 239,
430 151, 40, 40, 179, 180, 149, 118, 79, 84, 85,
431 94, 96, 99, 122, 102, 103, 104, 195, 196, 111,
432 222, 112, 204, 205, 113, 225, 114, 115, 116, 40,
433 40, 228, 229, 230, 117, 2, 142, 234, 79, 118,
434 3, 174, 4, 5, 6, 7, 175, 181, 8, 242,
435 88, 10, 11, 12, 187, 118, 13, 14, 15, 16,
436 244, 17, 18, 19, 20, 227, 197, 89, 206, 203,
437 23, 24, 233, 25, 211, 26, 208, 212, 192, 220,
438 221, 223, 232, 224, 241, 243, 250, 252, 245, 246,
439 247, 248, 249, 1, 253, 2, 254, 255, 257, 258,
440 3, 172, 4, 5, 6, 7, 78, 217, 8, 207,
441 9, 10, 11, 12, 240, 0, 13, 14, 15, 16,
442 188, 17, 18, 19, 20, 189, 0, 21, 22, 2,
443 23, 24, 0, 25, 3, 26, 4, 5, 6, 7,
444 0, 0, 8, 0, 88, 10, 11, 12, 0, 0,
445 13, 14, 15, 16, 251, 17, 18, 19, 20, 0,
446 0, 89, 0, 2, 23, 24, 0, 25, 3, 26,
447 4, 5, 6, 7, 0, 0, 8, 0, 88, 10,
448 11, 12, 0, 0, 13, 14, 15, 16, 0, 17,
449 18, 19, 20, 0, 0, 89, 0, 2, 23, 24,
450 0, 25, 3, 26, 4, 5, 6, 7, 0, 0,
451 8, 0, 9, 10, 11, 12, 0, 0, 13, 14,
452 15, 16, 0, 17, 18, 19, 20, 0, 0, 89,
453 0, 2, 23, 24, 0, 25, 3, 26, 4, 5,
454 6, 7, 0, 0, 8, 0, 9, 10, 11, 12,
455 0, 0, 13, 14, 15, 16, 0, 17, 18, 19,
456 20, 0, 0, 0, 0, 2, 23, 24, 0, 25,
457 3, 26, 4, 5, 6, 7, 0, 0, 8, 0,
458 0, 10, 11, 12, 0, 0, 13, 14, 15, 16,
459 0, 17, 18, 19, 20, 0, 0, 89, 0, 2,
460 23, 24, 0, 25, 3, 26, 4, 5, 6, 7,
461 0, 0, 8, 0, 0, 10, 11, 12, 0, 0,
462 13, 14, 15, 16, 0, 17, 18, 19, 20, 0,
463 0, 0, 0, 0, 23, 24, 0, 25, 0, 26,
464 77, 11, 12, 0, 0, 13, 14, 15, 16, 0,
465 17, 18, 19, 20, 0, 0, 0, 0, 12, 23,
466 24, 13, 14, 15, 16, 0, 17, 18, 19, 20,
467 0, 0, 0, 0, 0, 23, 24, 52, 53, 54,
468 55, 0, 56, 0, 57, 58, 0, 0, 0, 0,
472 static const short yycheck[] = { 6,
473 7, 32, 44, 45, 46, 0, 35, 49, 101, 14,
474 143, 35, 17, 19, 37, 21, 14, 41, 25, 26,
475 19, 44, 0, 154, 155, 156, 157, 158, 19, 9,
476 35, 9, 9, 19, 40, 14, 41, 35, 17, 19,
477 82, 83, 19, 41, 86, 178, 14, 14, 14, 80,
478 19, 144, 94, 17, 96, 35, 35, 19, 35, 21,
479 102, 43, 41, 43, 19, 37, 43, 35, 35, 35,
480 19, 35, 44, 41, 41, 41, 209, 19, 40, 19,
481 87, 22, 23, 176, 126, 127, 128, 129, 130, 131,
482 85, 98, 99, 19, 19, 21, 21, 228, 229, 230,
483 142, 19, 5, 6, 7, 35, 84, 85, 22, 23,
484 88, 19, 143, 19, 40, 40, 34, 35, 36, 161,
485 19, 19, 22, 23, 119, 120, 133, 37, 135, 4,
486 137, 43, 139, 33, 34, 35, 14, 22, 23, 5,
487 6, 119, 120, 150, 151, 123, 177, 178, 33, 34,
488 34, 34, 14, 148, 44, 19, 19, 164, 165, 19,
489 202, 19, 169, 170, 19, 207, 19, 19, 42, 147,
490 148, 213, 214, 215, 44, 3, 44, 219, 209, 210,
491 8, 15, 10, 11, 12, 13, 15, 7, 16, 231,
492 18, 19, 20, 21, 9, 226, 24, 25, 26, 27,
493 28, 29, 30, 31, 32, 212, 15, 35, 15, 42,
494 38, 39, 219, 41, 7, 43, 42, 4, 19, 15,
495 42, 15, 19, 42, 231, 28, 28, 15, 235, 236,
496 237, 238, 239, 1, 42, 3, 15, 42, 0, 0,
497 8, 138, 10, 11, 12, 13, 29, 193, 16, 172,
498 18, 19, 20, 21, 227, -1, 24, 25, 26, 27,
499 161, 29, 30, 31, 32, 161, -1, 35, 36, 3,
500 38, 39, -1, 41, 8, 43, 10, 11, 12, 13,
501 -1, -1, 16, -1, 18, 19, 20, 21, -1, -1,
502 24, 25, 26, 27, 28, 29, 30, 31, 32, -1,
503 -1, 35, -1, 3, 38, 39, -1, 41, 8, 43,
504 10, 11, 12, 13, -1, -1, 16, -1, 18, 19,
505 20, 21, -1, -1, 24, 25, 26, 27, -1, 29,
506 30, 31, 32, -1, -1, 35, -1, 3, 38, 39,
507 -1, 41, 8, 43, 10, 11, 12, 13, -1, -1,
508 16, -1, 18, 19, 20, 21, -1, -1, 24, 25,
509 26, 27, -1, 29, 30, 31, 32, -1, -1, 35,
510 -1, 3, 38, 39, -1, 41, 8, 43, 10, 11,
511 12, 13, -1, -1, 16, -1, 18, 19, 20, 21,
512 -1, -1, 24, 25, 26, 27, -1, 29, 30, 31,
513 32, -1, -1, -1, -1, 3, 38, 39, -1, 41,
514 8, 43, 10, 11, 12, 13, -1, -1, 16, -1,
515 -1, 19, 20, 21, -1, -1, 24, 25, 26, 27,
516 -1, 29, 30, 31, 32, -1, -1, 35, -1, 3,
517 38, 39, -1, 41, 8, 43, 10, 11, 12, 13,
518 -1, -1, 16, -1, -1, 19, 20, 21, -1, -1,
519 24, 25, 26, 27, -1, 29, 30, 31, 32, -1,
520 -1, -1, -1, -1, 38, 39, -1, 41, -1, 43,
521 19, 20, 21, -1, -1, 24, 25, 26, 27, -1,
522 29, 30, 31, 32, -1, -1, -1, -1, 21, 38,
523 39, 24, 25, 26, 27, -1, 29, 30, 31, 32,
524 -1, -1, -1, -1, -1, 38, 39, 24, 25, 26,
525 27, -1, 29, -1, 31, 32, -1, -1, -1, -1,
528 /* -*-C-*- Note some compilers choke on comments on `#line' lines. */
529 #line 3 "/usr/local/lib/bison.simple"
531 /* Skeleton output parser for bison,
532 Copyright (C) 1984, 1989, 1990 Free Software Foundation, Inc.
534 This program is free software; you can redistribute it and/or modify
535 it under the terms of the GNU General Public License as published by
536 the Free Software Foundation; either version 2, or (at your option)
539 This program is distributed in the hope that it will be useful,
540 but WITHOUT ANY WARRANTY; without even the implied warranty of
541 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
542 GNU General Public License for more details.
544 You should have received a copy of the GNU General Public License
545 along with this program; if not, write to the Free Software
546 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
548 /* As a special exception, when this file is copied by Bison into a
549 Bison output file, you may use that output file without restriction.
550 This special exception was added by the Free Software Foundation
551 in version 1.24 of Bison. */
555 #define alloca __builtin_alloca
556 #else /* not GNU C. */
557 #if (!defined (__STDC__) && defined (sparc)) || defined (__sparc__) || defined (__sparc) || defined (__sgi)
559 #else /* not sparc */
560 #if defined (MSDOS) && !defined (__TURBOC__)
562 #else /* not MSDOS, or __TURBOC__ */
566 #else /* not MSDOS, __TURBOC__, or _AIX */
570 void *alloca (unsigned int);
572 #else /* not __cplusplus */
574 #endif /* not __cplusplus */
576 #endif /* not _AIX */
577 #endif /* not MSDOS, or __TURBOC__ */
578 #endif /* not sparc. */
579 #endif /* not GNU C. */
580 #endif /* alloca not defined. */
582 /* This is the parser code that is written into each bison parser
583 when the %semantic_parser declaration is not specified in the grammar.
584 It was written by Richard Stallman by simplifying the hairy parser
585 used when %semantic_parser is specified. */
587 /* Note: there must be only one dollar sign in this file.
588 It is replaced by the list of actions, each action
589 as one case of the switch. */
591 #define yyerrok (yyerrstatus = 0)
592 #define yyclearin (yychar = YYEMPTY)
595 #define YYACCEPT return(0)
596 #define YYABORT return(1)
597 #define YYERROR goto yyerrlab1
598 /* Like YYERROR except do call yyerror.
599 This remains here temporarily to ease the
600 transition to the new meaning of YYERROR, for GCC.
601 Once GCC version 2 has supplanted version 1, this can go. */
602 #define YYFAIL goto yyerrlab
603 #define YYRECOVERING() (!!yyerrstatus)
604 #define YYBACKUP(token, value) \
606 if (yychar == YYEMPTY && yylen == 1) \
607 { yychar = (token), yylval = (value); \
608 yychar1 = YYTRANSLATE (yychar); \
613 { yyerror ("syntax error: cannot back up"); YYERROR; } \
617 #define YYERRCODE 256
620 #define YYLEX yylex()
626 #define YYLEX yylex(&yylval, &yylloc, YYLEX_PARAM)
628 #define YYLEX yylex(&yylval, &yylloc)
630 #else /* not YYLSP_NEEDED */
632 #define YYLEX yylex(&yylval, YYLEX_PARAM)
634 #define YYLEX yylex(&yylval)
636 #endif /* not YYLSP_NEEDED */
639 /* If nonreentrant, generate the variables here */
643 int yychar; /* the lookahead symbol */
644 YYSTYPE yylval; /* the semantic value of the */
645 /* lookahead symbol */
648 YYLTYPE yylloc; /* location data for the lookahead */
652 int yynerrs; /* number of parse errors so far */
653 #endif /* not YYPURE */
656 int yydebug; /* nonzero means print parse trace */
657 /* Since this is uninitialized, it does not stop multiple parsers
661 /* YYINITDEPTH indicates the initial size of the parser's stacks */
664 #define YYINITDEPTH 200
667 /* YYMAXDEPTH is the maximum size the stacks can grow to
668 (effective only if the built-in stack extension method is used). */
675 #define YYMAXDEPTH 10000
678 /* Prevent warning if -Wstrict-prototypes. */
683 #if __GNUC__ > 1 /* GNU C and GNU C++ define this. */
684 #define __yy_memcpy(TO,FROM,COUNT) __builtin_memcpy(TO,FROM,COUNT)
685 #else /* not GNU C or C++ */
688 /* This is the most reliable way to avoid incompatibilities
689 in available built-in functions on various systems. */
691 __yy_memcpy (to, from, count)
696 register char *f = from;
697 register char *t = to;
698 register int i = count;
704 #else /* __cplusplus */
706 /* This is the most reliable way to avoid incompatibilities
707 in available built-in functions on various systems. */
709 __yy_memcpy (char *to, char *from, int count)
711 register char *f = from;
712 register char *t = to;
713 register int i = count;
722 #line 196 "/usr/local/lib/bison.simple"
724 /* The user can define YYPARSE_PARAM as the name of an argument to be passed
725 into yyparse. The argument should have type void *.
726 It should actually point to an object.
727 Grammar actions can access the variable by casting it
728 to the proper pointer type. */
732 #define YYPARSE_PARAM_ARG void *YYPARSE_PARAM
733 #define YYPARSE_PARAM_DECL
734 #else /* not __cplusplus */
735 #define YYPARSE_PARAM_ARG YYPARSE_PARAM
736 #define YYPARSE_PARAM_DECL void *YYPARSE_PARAM;
737 #endif /* not __cplusplus */
738 #else /* not YYPARSE_PARAM */
739 #define YYPARSE_PARAM_ARG
740 #define YYPARSE_PARAM_DECL
741 #endif /* not YYPARSE_PARAM */
744 yyparse(YYPARSE_PARAM_ARG)
747 register int yystate;
749 register short *yyssp;
750 register YYSTYPE *yyvsp;
751 int yyerrstatus; /* number of tokens to shift before error messages enabled */
752 int yychar1 = 0; /* lookahead token as an internal (translated) token number */
754 short yyssa[YYINITDEPTH]; /* the state stack */
755 YYSTYPE yyvsa[YYINITDEPTH]; /* the semantic value stack */
757 short *yyss = yyssa; /* refer to the stacks thru separate pointers */
758 YYSTYPE *yyvs = yyvsa; /* to allow yyoverflow to reallocate them elsewhere */
761 YYLTYPE yylsa[YYINITDEPTH]; /* the location stack */
762 YYLTYPE *yyls = yylsa;
765 #define YYPOPSTACK (yyvsp--, yyssp--, yylsp--)
767 #define YYPOPSTACK (yyvsp--, yyssp--)
770 int yystacksize = YYINITDEPTH;
781 YYSTYPE yyval; /* the variable used to return */
782 /* semantic values from the action */
789 fprintf(stderr, "Starting parse\n");
795 yychar = YYEMPTY; /* Cause a token to be read. */
797 /* Initialize stack pointers.
798 Waste one element of value and location stack
799 so that they stay on the same level as the state stack.
800 The wasted elements are never initialized. */
808 /* Push a new state, which is found in yystate . */
809 /* In all cases, when you get here, the value and location stacks
810 have just been pushed. so pushing a state here evens the stacks. */
815 if (yyssp >= yyss + yystacksize - 1)
817 /* Give user a chance to reallocate the stack */
818 /* Use copies of these so that the &'s don't force the real ones into memory. */
819 YYSTYPE *yyvs1 = yyvs;
822 YYLTYPE *yyls1 = yyls;
825 /* Get the current used size of the three stacks, in elements. */
826 int size = yyssp - yyss + 1;
829 /* Each stack pointer address is followed by the size of
830 the data in use in that stack, in bytes. */
832 /* This used to be a conditional around just the two extra args,
833 but that might be undefined if yyoverflow is a macro. */
834 yyoverflow("parser stack overflow",
835 &yyss1, size * sizeof (*yyssp),
836 &yyvs1, size * sizeof (*yyvsp),
837 &yyls1, size * sizeof (*yylsp),
840 yyoverflow("parser stack overflow",
841 &yyss1, size * sizeof (*yyssp),
842 &yyvs1, size * sizeof (*yyvsp),
846 yyss = yyss1; yyvs = yyvs1;
850 #else /* no yyoverflow */
851 /* Extend the stack our own way. */
852 if (yystacksize >= YYMAXDEPTH)
854 yyerror("parser stack overflow");
858 if (yystacksize > YYMAXDEPTH)
859 yystacksize = YYMAXDEPTH;
860 yyss = (short *) alloca (yystacksize * sizeof (*yyssp));
861 __yy_memcpy ((char *)yyss, (char *)yyss1, size * sizeof (*yyssp));
862 yyvs = (YYSTYPE *) alloca (yystacksize * sizeof (*yyvsp));
863 __yy_memcpy ((char *)yyvs, (char *)yyvs1, size * sizeof (*yyvsp));
865 yyls = (YYLTYPE *) alloca (yystacksize * sizeof (*yylsp));
866 __yy_memcpy ((char *)yyls, (char *)yyls1, size * sizeof (*yylsp));
868 #endif /* no yyoverflow */
870 yyssp = yyss + size - 1;
871 yyvsp = yyvs + size - 1;
873 yylsp = yyls + size - 1;
878 fprintf(stderr, "Stack size increased to %d\n", yystacksize);
881 if (yyssp >= yyss + yystacksize - 1)
887 fprintf(stderr, "Entering state %d\n", yystate);
893 /* Do appropriate processing given the current state. */
894 /* Read a lookahead token if we need one and don't already have one. */
897 /* First try to decide what to do without reference to lookahead token. */
899 yyn = yypact[yystate];
903 /* Not known => get a lookahead token if don't already have one. */
905 /* yychar is either YYEMPTY or YYEOF
906 or a valid token in external form. */
908 if (yychar == YYEMPTY)
912 fprintf(stderr, "Reading a token: ");
917 /* Convert token to internal form (in yychar1) for indexing tables with */
919 if (yychar <= 0) /* This means end of input. */
922 yychar = YYEOF; /* Don't call YYLEX any more */
926 fprintf(stderr, "Now at end of input.\n");
931 yychar1 = YYTRANSLATE(yychar);
936 fprintf (stderr, "Next token is %d (%s", yychar, yytname[yychar1]);
937 /* Give the individual parser a way to print the precise meaning
938 of a token, for further debugging info. */
940 YYPRINT (stderr, yychar, yylval);
942 fprintf (stderr, ")\n");
948 if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != yychar1)
953 /* yyn is what to do for this token type in this state.
954 Negative => reduce, -yyn is rule number.
955 Positive => shift, yyn is new state.
956 New state is final state => don't bother to shift,
958 0, or most negative number => error. */
973 /* Shift the lookahead token. */
977 fprintf(stderr, "Shifting token %d (%s), ", yychar, yytname[yychar1]);
980 /* Discard the token being shifted unless it is eof. */
989 /* count tokens shifted since error; after three, turn off error status. */
990 if (yyerrstatus) yyerrstatus--;
995 /* Do the default action for the current state. */
998 yyn = yydefact[yystate];
1002 /* Do a reduction. yyn is the number of a rule to reduce with. */
1006 yyval = yyvsp[1-yylen]; /* implement default value of the action */
1013 fprintf (stderr, "Reducing via rule %d (line %d), ",
1016 /* Print the symbols being reduced, and their result. */
1017 for (i = yyprhs[yyn]; yyrhs[i] > 0; i++)
1018 fprintf (stderr, "%s ", yytname[yyrhs[i]]);
1019 fprintf (stderr, " -> %s\n", yytname[yyr1[yyn]]);
1027 #line 164 "./parse.y"
1029 /* Case of regular command. Discard the error
1030 safety net,and return the command just parsed. */
1031 global_command = yyvsp[-1].command;
1032 eof_encountered = 0;
1033 discard_parser_constructs (0);
1038 #line 173 "./parse.y"
1040 /* Case of regular command, but not a very
1041 interesting one. Return a NULL command. */
1042 global_command = (COMMAND *)NULL;
1047 #line 181 "./parse.y"
1049 /* Error during parsing. Return NULL command. */
1050 global_command = (COMMAND *)NULL;
1051 eof_encountered = 0;
1052 discard_parser_constructs (1);
1064 #line 196 "./parse.y"
1066 /* Case of EOF seen by itself. Do ignoreeof or
1068 global_command = (COMMAND *)NULL;
1069 handle_eof_input_unit ();
1074 #line 206 "./parse.y"
1075 { yyval.word_list = (WORD_LIST *)NULL; ;
1078 #line 208 "./parse.y"
1079 { yyval.word_list = make_word_list (yyvsp[0].word, yyvsp[-1].word_list); ;
1082 #line 212 "./parse.y"
1084 redir.filename = yyvsp[0].word;
1085 yyval.redirect = make_redirection (1, r_output_direction, redir);
1089 #line 217 "./parse.y"
1091 redir.filename = yyvsp[0].word;
1092 yyval.redirect = make_redirection (0, r_input_direction, redir);
1096 #line 222 "./parse.y"
1098 redir.filename = yyvsp[0].word;
1099 yyval.redirect = make_redirection (yyvsp[-2].number, r_output_direction, redir);
1103 #line 227 "./parse.y"
1105 redir.filename = yyvsp[0].word;
1106 yyval.redirect = make_redirection (yyvsp[-2].number, r_input_direction, redir);
1110 #line 232 "./parse.y"
1112 redir.filename = yyvsp[0].word;
1113 yyval.redirect = make_redirection (1, r_appending_to, redir);
1117 #line 237 "./parse.y"
1119 redir.filename = yyvsp[0].word;
1120 yyval.redirect = make_redirection (yyvsp[-2].number, r_appending_to, redir);
1124 #line 242 "./parse.y"
1126 redir.filename = yyvsp[0].word;
1127 yyval.redirect = make_redirection (0, r_reading_until, redir);
1128 redir_stack[need_here_doc++] = yyval.redirect;
1132 #line 248 "./parse.y"
1134 redir.filename = yyvsp[0].word;
1135 yyval.redirect = make_redirection (yyvsp[-2].number, r_reading_until, redir);
1136 redir_stack[need_here_doc++] = yyval.redirect;
1140 #line 254 "./parse.y"
1142 redir.dest = yyvsp[0].number;
1143 yyval.redirect = make_redirection (0, r_duplicating_input, redir);
1147 #line 259 "./parse.y"
1149 redir.dest = yyvsp[0].number;
1150 yyval.redirect = make_redirection (yyvsp[-2].number, r_duplicating_input, redir);
1154 #line 264 "./parse.y"
1156 redir.dest = yyvsp[0].number;
1157 yyval.redirect = make_redirection (1, r_duplicating_output, redir);
1161 #line 269 "./parse.y"
1163 redir.dest = yyvsp[0].number;
1164 yyval.redirect = make_redirection (yyvsp[-2].number, r_duplicating_output, redir);
1168 #line 274 "./parse.y"
1170 redir.filename = yyvsp[0].word;
1171 yyval.redirect = make_redirection (0, r_duplicating_input_word, redir);
1175 #line 279 "./parse.y"
1177 redir.filename = yyvsp[0].word;
1178 yyval.redirect = make_redirection (yyvsp[-2].number, r_duplicating_input_word, redir);
1182 #line 284 "./parse.y"
1184 redir.filename = yyvsp[0].word;
1185 yyval.redirect = make_redirection (1, r_duplicating_output_word, redir);
1189 #line 289 "./parse.y"
1191 redir.filename = yyvsp[0].word;
1192 yyval.redirect = make_redirection (yyvsp[-2].number, r_duplicating_output_word, redir);
1196 #line 294 "./parse.y"
1198 redir.filename = yyvsp[0].word;
1199 yyval.redirect = make_redirection
1200 (0, r_deblank_reading_until, redir);
1201 redir_stack[need_here_doc++] = yyval.redirect;
1205 #line 301 "./parse.y"
1207 redir.filename = yyvsp[0].word;
1208 yyval.redirect = make_redirection
1209 (yyvsp[-2].number, r_deblank_reading_until, redir);
1210 redir_stack[need_here_doc++] = yyval.redirect;
1214 #line 308 "./parse.y"
1217 yyval.redirect = make_redirection (1, r_close_this, redir);
1221 #line 313 "./parse.y"
1224 yyval.redirect = make_redirection (yyvsp[-2].number, r_close_this, redir);
1228 #line 318 "./parse.y"
1231 yyval.redirect = make_redirection (0, r_close_this, redir);
1235 #line 323 "./parse.y"
1238 yyval.redirect = make_redirection (yyvsp[-2].number, r_close_this, redir);
1242 #line 328 "./parse.y"
1244 redir.filename = yyvsp[0].word;
1245 yyval.redirect = make_redirection (1, r_err_and_out, redir);
1249 #line 333 "./parse.y"
1251 redir.filename = yyvsp[0].word;
1252 yyval.redirect = make_redirection (yyvsp[-2].number, r_input_output, redir);
1256 #line 338 "./parse.y"
1260 redir.filename = yyvsp[0].word;
1261 if (posixly_correct)
1262 yyval.redirect = make_redirection (0, r_input_output, redir);
1265 t1 = make_redirection (0, r_input_direction, redir);
1266 redir.filename = copy_word (yyvsp[0].word);
1267 t2 = make_redirection (1, r_output_direction, redir);
1269 yyval.redirect = t1;
1274 #line 354 "./parse.y"
1276 redir.filename = yyvsp[0].word;
1277 yyval.redirect = make_redirection (1, r_output_force, redir);
1281 #line 359 "./parse.y"
1283 redir.filename = yyvsp[0].word;
1284 yyval.redirect = make_redirection (yyvsp[-2].number, r_output_force, redir);
1288 #line 366 "./parse.y"
1289 { yyval.element.word = yyvsp[0].word; yyval.element.redirect = 0; ;
1292 #line 368 "./parse.y"
1293 { yyval.element.word = yyvsp[0].word; yyval.element.redirect = 0; ;
1296 #line 370 "./parse.y"
1297 { yyval.element.redirect = yyvsp[0].redirect; yyval.element.word = 0; ;
1300 #line 374 "./parse.y"
1302 yyval.redirect = yyvsp[0].redirect;
1306 #line 378 "./parse.y"
1308 register REDIRECT *t = yyvsp[-1].redirect;
1312 t->next = yyvsp[0].redirect;
1313 yyval.redirect = yyvsp[-1].redirect;
1317 #line 389 "./parse.y"
1318 { yyval.command = make_simple_command (yyvsp[0].element, (COMMAND *)NULL); ;
1321 #line 391 "./parse.y"
1322 { yyval.command = make_simple_command (yyvsp[0].element, yyvsp[-1].command); ;
1325 #line 395 "./parse.y"
1326 { yyval.command = clean_simple_command (yyvsp[0].command); ;
1329 #line 397 "./parse.y"
1330 { yyval.command = yyvsp[0].command; ;
1333 #line 401 "./parse.y"
1334 { yyval.command = yyvsp[0].command; ;
1337 #line 403 "./parse.y"
1339 if (yyvsp[-1].command->redirects)
1341 register REDIRECT *t;
1342 for (t = yyvsp[-1].command->redirects; t->next; t = t->next)
1344 t->next = yyvsp[0].redirect;
1347 yyvsp[-1].command->redirects = yyvsp[0].redirect;
1348 yyval.command = yyvsp[-1].command;
1352 #line 418 "./parse.y"
1353 { yyval.command = make_for_command (yyvsp[-4].word, add_string_to_list ("\"$@\"", (WORD_LIST *)NULL), yyvsp[-1].command); ;
1356 #line 420 "./parse.y"
1357 { yyval.command = make_for_command (yyvsp[-4].word, add_string_to_list ("$@", (WORD_LIST *)NULL), yyvsp[-1].command); ;
1360 #line 422 "./parse.y"
1361 { yyval.command = make_for_command (yyvsp[-5].word, add_string_to_list ("\"$@\"", (WORD_LIST *)NULL), yyvsp[-1].command); ;
1364 #line 424 "./parse.y"
1365 { yyval.command = make_for_command (yyvsp[-5].word, add_string_to_list ("\"$@\"", (WORD_LIST *)NULL), yyvsp[-1].command); ;
1368 #line 426 "./parse.y"
1369 { yyval.command = make_for_command (yyvsp[-8].word, REVERSE_LIST (yyvsp[-5].word_list, WORD_LIST *), yyvsp[-1].command); ;
1372 #line 428 "./parse.y"
1373 { yyval.command = make_for_command (yyvsp[-8].word, REVERSE_LIST (yyvsp[-5].word_list, WORD_LIST *), yyvsp[-1].command); ;
1376 #line 431 "./parse.y"
1377 { yyval.command = make_case_command (yyvsp[-4].word, (PATTERN_LIST *)NULL); ;
1380 #line 433 "./parse.y"
1381 { yyval.command = make_case_command (yyvsp[-5].word, yyvsp[-2].pattern); ;
1384 #line 435 "./parse.y"
1385 { yyval.command = make_case_command (yyvsp[-4].word, yyvsp[-1].pattern); ;
1388 #line 437 "./parse.y"
1389 { yyval.command = make_while_command (yyvsp[-3].command, yyvsp[-1].command); ;
1392 #line 439 "./parse.y"
1393 { yyval.command = make_until_command (yyvsp[-3].command, yyvsp[-1].command); ;
1396 #line 441 "./parse.y"
1397 { yyval.command = yyvsp[0].command; ;
1400 #line 443 "./parse.y"
1401 { yyval.command = yyvsp[0].command; ;
1404 #line 445 "./parse.y"
1405 { yyval.command = yyvsp[0].command; ;
1408 #line 447 "./parse.y"
1409 { yyval.command = yyvsp[0].command; ;
1412 #line 449 "./parse.y"
1413 { yyval.command = yyvsp[0].command; ;
1416 #line 453 "./parse.y"
1418 #if defined (SELECT_COMMAND)
1419 yyval.command = make_select_command (yyvsp[-4].word, add_string_to_list ("\"$@\"", (WORD_LIST *)NULL), yyvsp[-1].command);
1424 #line 459 "./parse.y"
1426 #if defined (SELECT_COMMAND)
1427 yyval.command = make_select_command (yyvsp[-4].word, add_string_to_list ("$@", (WORD_LIST *)NULL), yyvsp[-1].command);
1432 #line 465 "./parse.y"
1434 #if defined (SELECT_COMMAND)
1435 yyval.command = make_select_command (yyvsp[-5].word, add_string_to_list ("\"$@\"", (WORD_LIST *)NULL), yyvsp[-1].command);
1440 #line 471 "./parse.y"
1442 #if defined (SELECT_COMMAND)
1443 yyval.command = make_select_command (yyvsp[-5].word, add_string_to_list ("\"$@\"", (WORD_LIST *)NULL), yyvsp[-1].command);
1448 #line 477 "./parse.y"
1450 #if defined (SELECT_COMMAND)
1451 yyval.command = make_select_command (yyvsp[-8].word, (WORD_LIST *)reverse_list (yyvsp[-5].word_list), yyvsp[-1].command);
1456 #line 483 "./parse.y"
1458 #if defined (SELECT_COMMAND)
1459 yyval.command = make_select_command (yyvsp[-8].word, (WORD_LIST *)reverse_list (yyvsp[-5].word_list), yyvsp[-1].command);
1464 #line 491 "./parse.y"
1465 { yyval.command = make_function_def (yyvsp[-4].word, yyvsp[0].command); ;
1468 #line 494 "./parse.y"
1469 { yyvsp[-1].command->redirects = yyvsp[0].redirect; yyval.command = make_function_def (yyvsp[-5].word, yyvsp[-1].command); ;
1472 #line 497 "./parse.y"
1473 { yyval.command = make_function_def (yyvsp[-4].word, yyvsp[0].command); ;
1476 #line 500 "./parse.y"
1477 { yyvsp[-1].command->redirects = yyvsp[0].redirect; yyval.command = make_function_def (yyvsp[-5].word, yyvsp[-1].command); ;
1480 #line 503 "./parse.y"
1481 { yyval.command = make_function_def (yyvsp[-2].word, yyvsp[0].command); ;
1484 #line 506 "./parse.y"
1485 { yyvsp[-1].command->redirects = yyvsp[0].redirect; yyval.command = make_function_def (yyvsp[-3].word, yyvsp[-1].command); ;
1488 #line 510 "./parse.y"
1489 { yyvsp[-1].command->flags |= CMD_WANT_SUBSHELL; yyval.command = yyvsp[-1].command; ;
1492 #line 514 "./parse.y"
1493 { yyval.command = make_if_command (yyvsp[-3].command, yyvsp[-1].command, (COMMAND *)NULL); ;
1496 #line 516 "./parse.y"
1497 { yyval.command = make_if_command (yyvsp[-5].command, yyvsp[-3].command, yyvsp[-1].command); ;
1500 #line 518 "./parse.y"
1501 { yyval.command = make_if_command (yyvsp[-4].command, yyvsp[-2].command, yyvsp[-1].command); ;
1504 #line 523 "./parse.y"
1505 { yyval.command = make_group_command (yyvsp[-1].command); ;
1508 #line 527 "./parse.y"
1509 { yyval.command = make_if_command (yyvsp[-2].command, yyvsp[0].command, (COMMAND *)NULL); ;
1512 #line 529 "./parse.y"
1513 { yyval.command = make_if_command (yyvsp[-4].command, yyvsp[-2].command, yyvsp[0].command); ;
1516 #line 531 "./parse.y"
1517 { yyval.command = make_if_command (yyvsp[-3].command, yyvsp[-1].command, yyvsp[0].command); ;
1520 #line 536 "./parse.y"
1521 { yyvsp[0].pattern->next = yyvsp[-1].pattern; yyval.pattern = yyvsp[0].pattern; ;
1524 #line 540 "./parse.y"
1525 { yyval.pattern = make_pattern_list (yyvsp[-2].word_list, yyvsp[0].command); ;
1528 #line 542 "./parse.y"
1529 { yyval.pattern = make_pattern_list (yyvsp[-2].word_list, (COMMAND *)NULL); ;
1532 #line 544 "./parse.y"
1533 { yyval.pattern = make_pattern_list (yyvsp[-2].word_list, yyvsp[0].command); ;
1536 #line 546 "./parse.y"
1537 { yyval.pattern = make_pattern_list (yyvsp[-2].word_list, (COMMAND *)NULL); ;
1540 #line 551 "./parse.y"
1541 { yyvsp[0].pattern->next = yyvsp[-1].pattern; yyval.pattern = yyvsp[0].pattern; ;
1544 #line 555 "./parse.y"
1545 { yyval.pattern = make_pattern_list (yyvsp[-3].word_list, yyvsp[-1].command); ;
1548 #line 557 "./parse.y"
1549 { yyval.pattern = make_pattern_list (yyvsp[-3].word_list, (COMMAND *)NULL); ;
1552 #line 559 "./parse.y"
1553 { yyval.pattern = make_pattern_list (yyvsp[-3].word_list, yyvsp[-1].command); ;
1556 #line 561 "./parse.y"
1557 { yyval.pattern = make_pattern_list (yyvsp[-3].word_list, (COMMAND *)NULL); ;
1560 #line 565 "./parse.y"
1561 { yyval.word_list = make_word_list (yyvsp[0].word, (WORD_LIST *)NULL); ;
1564 #line 567 "./parse.y"
1565 { yyval.word_list = make_word_list (yyvsp[0].word, yyvsp[-2].word_list); ;
1568 #line 576 "./parse.y"
1570 yyval.command = yyvsp[0].command;
1572 gather_here_documents ();
1576 #line 586 "./parse.y"
1578 if (yyvsp[-2].command->type == cm_connection)
1579 yyval.command = connect_async_list (yyvsp[-2].command, (COMMAND *)NULL, '&');
1581 yyval.command = command_connect (yyvsp[-2].command, (COMMAND *)NULL, '&');
1585 #line 597 "./parse.y"
1586 { yyval.command = command_connect (yyvsp[-3].command, yyvsp[0].command, AND_AND); ;
1589 #line 599 "./parse.y"
1590 { yyval.command = command_connect (yyvsp[-3].command, yyvsp[0].command, OR_OR); ;
1593 #line 601 "./parse.y"
1595 if (yyvsp[-3].command->type == cm_connection)
1596 yyval.command = connect_async_list (yyvsp[-3].command, yyvsp[0].command, '&');
1598 yyval.command = command_connect (yyvsp[-3].command, yyvsp[0].command, '&');
1602 #line 608 "./parse.y"
1603 { yyval.command = command_connect (yyvsp[-3].command, yyvsp[0].command, ';'); ;
1606 #line 610 "./parse.y"
1607 { yyval.command = command_connect (yyvsp[-3].command, yyvsp[0].command, ';'); ;
1610 #line 612 "./parse.y"
1611 { yyval.command = yyvsp[0].command; ;
1614 #line 614 "./parse.y"
1616 yyvsp[0].command->flags |= CMD_INVERT_RETURN;
1617 yyval.command = yyvsp[0].command;
1621 #line 636 "./parse.y"
1623 yyval.command = yyvsp[0].command;
1625 gather_here_documents ();
1629 #line 642 "./parse.y"
1631 if (yyvsp[-1].command->type == cm_connection)
1632 yyval.command = connect_async_list (yyvsp[-1].command, (COMMAND *)NULL, '&');
1634 yyval.command = command_connect (yyvsp[-1].command, (COMMAND *)NULL, '&');
1636 gather_here_documents ();
1640 #line 651 "./parse.y"
1642 yyval.command = yyvsp[-1].command;
1644 gather_here_documents ();
1648 #line 659 "./parse.y"
1649 { yyval.command = command_connect (yyvsp[-3].command, yyvsp[0].command, AND_AND); ;
1652 #line 661 "./parse.y"
1653 { yyval.command = command_connect (yyvsp[-3].command, yyvsp[0].command, OR_OR); ;
1656 #line 663 "./parse.y"
1658 if (yyvsp[-2].command->type == cm_connection)
1659 yyval.command = connect_async_list (yyvsp[-2].command, yyvsp[0].command, '&');
1661 yyval.command = command_connect (yyvsp[-2].command, yyvsp[0].command, '&');
1665 #line 670 "./parse.y"
1666 { yyval.command = command_connect (yyvsp[-2].command, yyvsp[0].command, ';'); ;
1669 #line 672 "./parse.y"
1670 { yyval.command = yyvsp[0].command; ;
1673 #line 674 "./parse.y"
1675 yyvsp[0].command->flags |= CMD_INVERT_RETURN;
1676 yyval.command = yyvsp[0].command;
1680 #line 682 "./parse.y"
1681 { yyval.command = command_connect (yyvsp[-3].command, yyvsp[0].command, '|'); ;
1684 #line 684 "./parse.y"
1685 { yyval.command = yyvsp[0].command; ;
1688 /* the action file gets copied in in place of this dollarsign */
1689 #line 498 "/usr/local/lib/bison.simple"
1700 short *ssp1 = yyss - 1;
1701 fprintf (stderr, "state stack now");
1702 while (ssp1 != yyssp)
1703 fprintf (stderr, " %d", *++ssp1);
1704 fprintf (stderr, "\n");
1714 yylsp->first_line = yylloc.first_line;
1715 yylsp->first_column = yylloc.first_column;
1716 yylsp->last_line = (yylsp-1)->last_line;
1717 yylsp->last_column = (yylsp-1)->last_column;
1722 yylsp->last_line = (yylsp+yylen-1)->last_line;
1723 yylsp->last_column = (yylsp+yylen-1)->last_column;
1727 /* Now "shift" the result of the reduction.
1728 Determine what state that goes to,
1729 based on the state we popped back to
1730 and the rule number reduced by. */
1734 yystate = yypgoto[yyn - YYNTBASE] + *yyssp;
1735 if (yystate >= 0 && yystate <= YYLAST && yycheck[yystate] == *yyssp)
1736 yystate = yytable[yystate];
1738 yystate = yydefgoto[yyn - YYNTBASE];
1742 yyerrlab: /* here on detecting error */
1745 /* If not already recovering from an error, report this error. */
1749 #ifdef YYERROR_VERBOSE
1750 yyn = yypact[yystate];
1752 if (yyn > YYFLAG && yyn < YYLAST)
1759 /* Start X at -yyn if nec to avoid negative indexes in yycheck. */
1760 for (x = (yyn < 0 ? -yyn : 0);
1761 x < (sizeof(yytname) / sizeof(char *)); x++)
1762 if (yycheck[x + yyn] == x)
1763 size += strlen(yytname[x]) + 15, count++;
1764 msg = (char *) malloc(size + 15);
1767 strcpy(msg, "parse error");
1772 for (x = (yyn < 0 ? -yyn : 0);
1773 x < (sizeof(yytname) / sizeof(char *)); x++)
1774 if (yycheck[x + yyn] == x)
1776 strcat(msg, count == 0 ? ", expecting `" : " or `");
1777 strcat(msg, yytname[x]);
1786 yyerror ("parse error; also virtual memory exceeded");
1789 #endif /* YYERROR_VERBOSE */
1790 yyerror("parse error");
1794 yyerrlab1: /* here on error raised explicitly by an action */
1796 if (yyerrstatus == 3)
1798 /* if just tried and failed to reuse lookahead token after an error, discard it. */
1800 /* return failure if at end of input */
1801 if (yychar == YYEOF)
1806 fprintf(stderr, "Discarding token %d (%s).\n", yychar, yytname[yychar1]);
1812 /* Else will try to reuse lookahead token
1813 after shifting the error token. */
1815 yyerrstatus = 3; /* Each real token shifted decrements this */
1819 yyerrdefault: /* current state does not do anything special for the error token. */
1822 /* This is wrong; only states that explicitly want error tokens
1823 should shift them. */
1824 yyn = yydefact[yystate]; /* If its default is to accept any token, ok. Otherwise pop it.*/
1825 if (yyn) goto yydefault;
1828 yyerrpop: /* pop the current state because it cannot handle the error token */
1830 if (yyssp == yyss) YYABORT;
1840 short *ssp1 = yyss - 1;
1841 fprintf (stderr, "Error: state stack now");
1842 while (ssp1 != yyssp)
1843 fprintf (stderr, " %d", *++ssp1);
1844 fprintf (stderr, "\n");
1850 yyn = yypact[yystate];
1855 if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != YYTERROR)
1874 fprintf(stderr, "Shifting error token, ");
1885 #line 686 "./parse.y"
1888 /* Initial size to allocate for tokens, and the
1889 amount to grow them by. */
1890 #define TOKEN_DEFAULT_GROW_SIZE 512
1892 /* The token currently being read. */
1893 static int current_token = 0;
1895 /* The last read token, or NULL. read_token () uses this for context
1897 static int last_read_token = 0;
1899 /* The token read prior to last_read_token. */
1900 static int token_before_that = 0;
1902 /* If non-zero, it is the token that we want read_token to return
1903 regardless of what text is (or isn't) present to be read. This
1904 is reset by read_token. */
1905 static int token_to_read = 0;
1907 /* Global var is non-zero when end of file has been reached. */
1908 int EOF_Reached = 0;
1910 /* yy_getc () returns the next available character from input or EOF.
1911 yy_ungetc (c) makes `c' the next character to read.
1912 init_yy_io (get, unget, type, location) makes the function GET the
1913 installed function for getting the next character, makes UNGET the
1914 installed function for un-getting a character, sets the type of stream
1915 (either string or file) from TYPE, and makes LOCATION point to where
1916 the input is coming from. */
1918 /* Unconditionally returns end-of-file. */
1924 /* Variable containing the current get and unget functions.
1925 See ./input.h for a clearer description. */
1926 BASH_INPUT bash_input;
1928 /* Set all of the fields in BASH_INPUT to NULL. */
1930 initialize_bash_input ()
1932 bash_input.type = 0;
1933 bash_input.name = (char *)NULL;
1934 bash_input.location.file = (FILE *)NULL;
1935 bash_input.location.string = (char *)NULL;
1936 bash_input.getter = (Function *)NULL;
1937 bash_input.ungetter = (Function *)NULL;
1940 /* Set the contents of the current bash input stream from
1941 GET, UNGET, TYPE, NAME, and LOCATION. */
1943 init_yy_io (get, unget, type, name, location)
1944 Function *get, *unget;
1947 INPUT_STREAM location;
1949 bash_input.type = type;
1950 FREE (bash_input.name);
1953 bash_input.name = savestring (name);
1955 bash_input.name = (char *)NULL;
1958 memcpy((char *)&bash_input.location.string, (char *)&location.string, sizeof(location));
1960 bash_input.location = location;
1962 bash_input.getter = get;
1963 bash_input.ungetter = unget;
1966 /* Call this to get the next character of input. */
1969 return (*(bash_input.getter)) ();
1972 /* Call this to unget C. That is, to make C the next character
1977 return (*(bash_input.ungetter)) (c);
1980 #if defined (BUFFERED_INPUT)
1982 input_file_descriptor ()
1984 switch (bash_input.type)
1987 return (fileno (bash_input.location.file));
1989 return (bash_input.location.buffered_fd);
1991 return (fileno (stdin));
1994 #endif /* BUFFERED_INPUT */
1996 /* **************************************************************** */
1998 /* Let input be read from readline (). */
2000 /* **************************************************************** */
2002 #if defined (READLINE)
2003 char *current_readline_prompt = (char *)NULL;
2004 char *current_readline_line = (char *)NULL;
2005 int current_readline_line_index = 0;
2010 if (!current_readline_line)
2012 SigHandler *old_sigint;
2015 if (!bash_readline_initialized)
2016 initialize_readline ();
2018 #if defined (JOB_CONTROL)
2020 give_terminal_to (shell_pgrp);
2021 #endif /* JOB_CONTROL */
2023 if (signal_is_ignored (SIGINT) == 0)
2025 old_sigint = (SigHandler *)set_signal_handler (SIGINT, sigint_sighandler);
2026 interrupt_immediately++;
2029 if (!current_readline_prompt)
2030 current_readline_line = readline ("");
2032 current_readline_line = readline (current_readline_prompt);
2034 if (signal_is_ignored (SIGINT) == 0)
2036 interrupt_immediately--;
2037 set_signal_handler (SIGINT, old_sigint);
2040 /* Reset the prompt to whatever is in the decoded value of
2041 prompt_string_pointer. */
2042 reset_readline_prompt ();
2044 current_readline_line_index = 0;
2046 if (!current_readline_line)
2049 line_len = strlen (current_readline_line);
2050 current_readline_line = xrealloc (current_readline_line, 2 + line_len);
2051 current_readline_line[line_len++] = '\n';
2052 current_readline_line[line_len] = '\0';
2055 if (!current_readline_line[current_readline_line_index])
2057 free (current_readline_line);
2058 current_readline_line = (char *)NULL;
2059 return (yy_readline_get ());
2063 int c = (unsigned char)current_readline_line[current_readline_line_index++];
2069 yy_readline_unget (c)
2071 if (current_readline_line_index && current_readline_line)
2072 current_readline_line[--current_readline_line_index] = c;
2077 with_input_from_stdin ()
2079 INPUT_STREAM location;
2081 if (bash_input.type != st_stdin && stream_on_stack (st_stdin) == 0)
2083 location.string = current_readline_line;
2084 init_yy_io (yy_readline_get, yy_readline_unget,
2085 st_stdin, "readline stdin", location);
2089 #else /* !READLINE */
2092 with_input_from_stdin ()
2094 with_input_from_stream (stdin, "stdin");
2096 #endif /* !READLINE */
2098 /* **************************************************************** */
2100 /* Let input come from STRING. STRING is zero terminated. */
2102 /* **************************************************************** */
2107 register unsigned char *string;
2110 string = bash_input.location.string;
2113 /* If the string doesn't exist, or is empty, EOF found. */
2114 if (string && *string)
2117 bash_input.location.string = string;
2126 *(--bash_input.location.string) = c;
2131 with_input_from_string (string, name)
2135 INPUT_STREAM location;
2137 location.string = string;
2139 init_yy_io (yy_string_get, yy_string_unget, st_string, name, location);
2142 /* **************************************************************** */
2144 /* Let input come from STREAM. */
2146 /* **************************************************************** */
2153 if (bash_input.location.file)
2154 #if defined (NO_READ_RESTART_ON_SIGNAL)
2155 result = (unsigned char)getc_with_restart (bash_input.location.file);
2157 result = (unsigned char)getc (bash_input.location.file);
2158 #endif /* !NO_READ_RESTART_ON_SIGNAL */
2166 #if defined (NO_READ_RESTART_ON_SIGNAL)
2167 return (ungetc_with_restart (c, bash_input.location.file));
2169 return (ungetc (c, bash_input.location.file));
2174 with_input_from_stream (stream, name)
2178 INPUT_STREAM location;
2180 location.file = stream;
2181 init_yy_io (yy_stream_get, yy_stream_unget, st_stream, name, location);
2184 typedef struct stream_saver {
2185 struct stream_saver *next;
2186 BASH_INPUT bash_input;
2188 #if defined (BUFFERED_INPUT)
2189 BUFFERED_STREAM *bstream;
2190 #endif /* BUFFERED_INPUT */
2193 /* The globally known line number. */
2194 int line_number = 0;
2196 STREAM_SAVER *stream_list = (STREAM_SAVER *)NULL;
2200 STREAM_SAVER *saver = (STREAM_SAVER *)xmalloc (sizeof (STREAM_SAVER));
2202 xbcopy ((char *)&bash_input, (char *)&(saver->bash_input), sizeof (BASH_INPUT));
2204 #if defined (BUFFERED_INPUT)
2205 saver->bstream = (BUFFERED_STREAM *)NULL;
2206 /* If we have a buffered stream, clear out buffers[fd]. */
2207 if (bash_input.type == st_bstream && bash_input.location.buffered_fd >= 0)
2209 saver->bstream = buffers[bash_input.location.buffered_fd];
2210 buffers[bash_input.location.buffered_fd] = (BUFFERED_STREAM *)NULL;
2212 #endif /* BUFFERED_INPUT */
2214 saver->line = line_number;
2215 bash_input.name = (char *)NULL;
2216 saver->next = stream_list;
2217 stream_list = saver;
2218 EOF_Reached = line_number = 0;
2229 STREAM_SAVER *saver = stream_list;
2232 stream_list = stream_list->next;
2234 init_yy_io (saver->bash_input.getter,
2235 saver->bash_input.ungetter,
2236 saver->bash_input.type,
2237 saver->bash_input.name,
2238 saver->bash_input.location);
2240 #if defined (BUFFERED_INPUT)
2241 /* If we have a buffered stream, restore buffers[fd]. */
2242 /* If the input file descriptor was changed while this was on the
2243 save stack, update the buffered fd to the new file descriptor and
2244 re-establish the buffer <-> bash_input fd correspondence. */
2245 if (bash_input.type == st_bstream && bash_input.location.buffered_fd >= 0)
2247 if (bash_input_fd_changed)
2249 bash_input_fd_changed = 0;
2250 if (default_buffered_input >= 0)
2252 bash_input.location.buffered_fd = default_buffered_input;
2253 saver->bstream->b_fd = default_buffered_input;
2256 buffers[bash_input.location.buffered_fd] = saver->bstream;
2258 #endif /* BUFFERED_INPUT */
2260 line_number = saver->line;
2262 FREE (saver->bash_input.name);
2267 /* Return 1 if a stream of type TYPE is saved on the stack. */
2269 stream_on_stack (type)
2272 register STREAM_SAVER *s;
2274 for (s = stream_list; s; s = s->next)
2275 if (s->bash_input.type == type)
2282 * This is used to inhibit alias expansion and reserved word recognition
2283 * inside case statement pattern lists. A `case statement pattern list'
2285 * everything between the `in' in a `case word in' and the next ')'
2287 * everything between a `;;' and the next `)' or `esac'
2289 static int in_case_pattern_list = 0;
2293 * Pseudo-global variables used in implementing token-wise alias expansion.
2296 static int expand_next_token = 0;
2299 * Pushing and popping strings. This works together with shell_getc to
2300 * implement alias expansion on a per-token basis.
2303 typedef struct string_saver {
2304 struct string_saver *next;
2305 int expand_alias; /* Value to set expand_alias to when string is popped. */
2307 int saved_line_size, saved_line_index, saved_line_terminator;
2310 STRING_SAVER *pushed_string_list = (STRING_SAVER *)NULL;
2312 static void save_expansion ();
2315 * Push the current shell_input_line onto a stack of such lines and make S
2316 * the current input. Used when expanding aliases. EXPAND is used to set
2317 * the value of expand_next_token when the string is popped, so that the
2318 * word after the alias in the original line is handled correctly when the
2319 * alias expands to multiple words. TOKEN is the token that was expanded
2320 * into S; it is saved and used to prevent infinite recursive expansion.
2323 push_string (s, expand, token)
2328 STRING_SAVER *temp = (STRING_SAVER *) xmalloc (sizeof (STRING_SAVER));
2330 temp->expand_alias = expand;
2331 temp->saved_line = shell_input_line;
2332 temp->saved_line_size = shell_input_line_size;
2333 temp->saved_line_index = shell_input_line_index;
2334 temp->saved_line_terminator = shell_input_line_terminator;
2335 temp->next = pushed_string_list;
2336 pushed_string_list = temp;
2338 save_expansion (token);
2340 shell_input_line = s;
2341 shell_input_line_size = strlen (s);
2342 shell_input_line_index = 0;
2343 shell_input_line_terminator = '\0';
2344 expand_next_token = 0;
2348 * Make the top of the pushed_string stack be the current shell input.
2349 * Only called when there is something on the stack. Called from shell_getc
2350 * when it thinks it has consumed the string generated by an alias expansion
2351 * and needs to return to the original input line.
2358 FREE (shell_input_line);
2359 shell_input_line = pushed_string_list->saved_line;
2360 shell_input_line_index = pushed_string_list->saved_line_index;
2361 shell_input_line_size = pushed_string_list->saved_line_size;
2362 shell_input_line_terminator = pushed_string_list->saved_line_terminator;
2363 expand_next_token = pushed_string_list->expand_alias;
2365 t = pushed_string_list;
2366 pushed_string_list = pushed_string_list->next;
2373 register STRING_SAVER *t = pushed_string_list, *t1;
2378 FREE (t->saved_line);
2382 pushed_string_list = (STRING_SAVER *)NULL;
2385 /* This is a stack to save the values of all tokens for which alias
2386 expansion has been performed during the current call to read_token ().
2387 It is used to prevent alias expansion loops:
2393 Ideally this would be taken care of by push and pop string, but because
2394 of when strings are popped the stack will not contain the correct
2395 strings to test against. (The popping is done in shell_getc, so that when
2396 the current string is exhausted, shell_getc can simply pop that string off
2397 the stack, restore the previous string, and continue with the character
2398 following the token whose expansion was originally pushed on the stack.)
2400 What we really want is a record of all tokens that have been expanded for
2401 aliases during the `current' call to read_token(). This does that, at the
2402 cost of being somewhat special-purpose (OK, OK vile and unclean). */
2404 typedef struct _exp_saver {
2405 struct _exp_saver *next;
2409 EXPANSION_SAVER *expanded_token_stack = (EXPANSION_SAVER *)NULL;
2417 t = (EXPANSION_SAVER *) xmalloc (sizeof (EXPANSION_SAVER));
2418 t->saved_token = savestring (s);
2419 t->next = expanded_token_stack;
2420 expanded_token_stack = t;
2423 /* Return 1 if TOKEN has already been expanded in the current `stack' of
2424 expansions. If it has been expanded already, it will appear as the value
2425 of saved_token for some entry in the stack of expansions created for the
2426 current token being expanded. */
2428 token_has_been_expanded (token)
2431 register EXPANSION_SAVER *t = expanded_token_stack;
2435 if (STREQ (token, t->saved_token))
2443 free_expansion_stack ()
2445 register EXPANSION_SAVER *t = expanded_token_stack, *t1;
2450 free (t->saved_token);
2454 expanded_token_stack = (EXPANSION_SAVER *)NULL;
2459 /* Return a line of text, taken from wherever yylex () reads input.
2460 If there is no more input, then we return NULL. If REMOVE_QUOTED_NEWLINE
2461 is non-zero, we remove unquoted \<newline> pairs. This is used by
2462 read_secondary_line to read here documents. */
2464 read_a_line (remove_quoted_newline)
2465 int remove_quoted_newline;
2467 static char *line_buffer = (char *)NULL;
2468 static int buffer_size = 0;
2469 int indx = 0, c, peekc, pass_next;
2476 /* Allow immediate exit if interrupted during input. */
2482 /* If there is no more input, then we return NULL. */
2486 return ((char *)NULL);
2490 /* `+2' in case the final character in the buffer is a newline. */
2491 if (indx + 2 > buffer_size)
2493 line_buffer = xmalloc (buffer_size = 128);
2495 line_buffer = xrealloc (line_buffer, buffer_size += 128);
2497 /* IF REMOVE_QUOTED_NEWLINES is non-zero, we are reading a
2498 here document with an unquoted delimiter. In this case,
2499 the line will be expanded as if it were in double quotes.
2500 We allow a backslash to escape the next character, but we
2501 need to treat the backslash specially only if a backslash
2502 quoting a backslash-newline pair appears in the line. */
2505 line_buffer[indx++] = c;
2508 else if (c == '\\' && remove_quoted_newline)
2512 continue; /* Make the unquoted \<newline> pair disappear. */
2517 line_buffer[indx++] = c; /* Preserve the backslash. */
2521 line_buffer[indx++] = c;
2525 line_buffer[indx] = '\0';
2526 return (line_buffer);
2531 /* Return a line as in read_a_line (), but insure that the prompt is
2532 the secondary prompt. This is used to read the lines of a here
2533 document. REMOVE_QUOTED_NEWLINE is non-zero if we should remove
2534 newlines quoted with backslashes while reading the line. It is
2535 non-zero unless the delimiter of the here document was quoted. */
2537 read_secondary_line (remove_quoted_newline)
2538 int remove_quoted_newline;
2540 prompt_string_pointer = &ps2_prompt;
2542 return (read_a_line (remove_quoted_newline));
2546 /* **************************************************************** */
2550 /* **************************************************************** */
2552 /* Reserved words. These are only recognized as the first word of a
2554 STRING_INT_ALIST word_token_alist[] = {
2563 #if defined (SELECT_COMMAND)
2564 { "select", SELECT },
2571 { "function", FUNCTION },
2578 /* Return the next shell input character. This always reads characters
2579 from shell_input_line; when that line is exhausted, it is time to
2580 read the next line. This is called by read_token when the shell is
2581 processing normal command input. */
2583 shell_getc (remove_quoted_newline)
2584 int remove_quoted_newline;
2591 /* If shell_input_line[shell_input_line_index] == 0, but there is
2592 something on the pushed list of strings, then we don't want to go
2593 off and get another line. We let the code down below handle it. */
2595 if (!shell_input_line || ((!shell_input_line[shell_input_line_index]) &&
2596 (pushed_string_list == (STRING_SAVER *)NULL)))
2598 if (!shell_input_line || !shell_input_line[shell_input_line_index])
2603 restart_read_next_line:
2609 /* Allow immediate exit if interrupted during input. */
2613 shell_input_line_terminator = 0;
2615 #if defined (JOB_CONTROL)
2616 /* This can cause a problem when reading a command as the result
2617 of a trap, when the trap is called from flush_child. This call
2618 had better not cause jobs to disappear from the job table in
2619 that case, or we will have big trouble. */
2620 notify_and_cleanup ();
2621 #else /* !JOB_CONTROL */
2622 cleanup_dead_jobs ();
2623 #endif /* !JOB_CONTROL */
2625 #if defined (READLINE)
2626 if (interactive && bash_input.type != st_string && no_line_editing)
2628 if (interactive && bash_input.type != st_string)
2632 if (bash_input.type == st_stream)
2635 while (c = yy_getc ())
2637 /* Allow immediate exit if interrupted during input. */
2640 if (i + 2 > shell_input_line_size)
2642 xrealloc (shell_input_line, shell_input_line_size += 256);
2646 if (bash_input.type == st_stream)
2650 shell_input_line_terminator = EOF;
2652 shell_input_line[i] = '\0';
2656 shell_input_line[i++] = c;
2660 shell_input_line[--i] = '\0';
2661 current_command_line_count++;
2665 shell_input_line_index = 0;
2666 shell_input_line_len = i; /* == strlen (shell_input_line) */
2668 #if defined (HISTORY)
2669 if (interactive && shell_input_line && shell_input_line[0])
2673 expansions = pre_process_line (shell_input_line, 1, 1);
2675 free (shell_input_line);
2676 shell_input_line = expansions;
2677 shell_input_line_len = shell_input_line ?
2678 strlen (shell_input_line) :
2680 if (!shell_input_line_len)
2681 current_command_line_count--;
2683 /* We have to force the xrealloc below because we don't know the
2684 true allocated size of shell_input_line anymore. */
2685 shell_input_line_size = shell_input_line_len;
2687 #endif /* HISTORY */
2689 if (shell_input_line)
2691 /* Lines that signify the end of the shell's input should not be
2693 if (echo_input_at_read && (shell_input_line[0] ||
2694 shell_input_line_terminator != EOF))
2695 fprintf (stderr, "%s\n", shell_input_line);
2699 shell_input_line_size = 0;
2700 prompt_string_pointer = ¤t_prompt_string;
2705 /* Add the newline to the end of this string, iff the string does
2706 not already end in an EOF character. */
2707 if (shell_input_line_terminator != EOF)
2709 l = shell_input_line_len; /* was a call to strlen */
2711 if (l + 3 > shell_input_line_size)
2712 shell_input_line = xrealloc (shell_input_line,
2713 1 + (shell_input_line_size += 2));
2715 shell_input_line[l] = '\n';
2716 shell_input_line[l + 1] = '\0';
2720 c = shell_input_line[shell_input_line_index];
2723 shell_input_line_index++;
2725 if (c == '\\' && remove_quoted_newline &&
2726 shell_input_line[shell_input_line_index] == '\n')
2729 goto restart_read_next_line;
2733 /* If C is NULL, we have reached the end of the current input string. If
2734 pushed_string_list is non-empty, it's time to pop to the previous string
2735 because we have fully consumed the result of the last alias expansion.
2736 Do it transparently; just return the next character of the string popped
2738 if (!c && (pushed_string_list != (STRING_SAVER *)NULL))
2741 c = shell_input_line[shell_input_line_index];
2743 shell_input_line_index++;
2747 if (!c && shell_input_line_terminator == EOF)
2749 if (shell_input_line_index != 0)
2755 return ((unsigned char)c);
2758 /* Put C back into the input for the shell. */
2763 if (shell_input_line && shell_input_line_index)
2764 shell_input_line[--shell_input_line_index] = c;
2767 /* Discard input until CHARACTER is seen. */
2769 discard_until (character)
2774 while ((c = shell_getc (0)) != EOF && c != character)
2781 /* Place to remember the token. We try to keep the buffer
2782 at a reasonable size, but it can grow. */
2783 static char *token = (char *)NULL;
2785 /* Current size of the token buffer. */
2786 static int token_buffer_size = 0;
2789 execute_prompt_command (command)
2792 Function *temp_last, *temp_this;
2794 int temp_exit_value, temp_eof_encountered;
2796 temp_last = last_shell_builtin;
2797 temp_this = this_shell_builtin;
2798 temp_exit_value = last_command_exit_value;
2799 temp_eof_encountered = eof_encountered;
2800 last_lastarg = get_string_value ("_");
2802 last_lastarg = savestring (last_lastarg);
2804 parse_and_execute (savestring (command), "PROMPT_COMMAND", 0);
2806 last_shell_builtin = temp_last;
2807 this_shell_builtin = temp_this;
2808 last_command_exit_value = temp_exit_value;
2809 eof_encountered = temp_eof_encountered;
2811 bind_variable ("_", last_lastarg);
2812 FREE (last_lastarg);
2814 if (token_to_read == '\n')
2818 /* Command to read_token () explaining what we want it to do. */
2821 #define prompt_is_ps1 \
2822 (!prompt_string_pointer || prompt_string_pointer == &ps1_prompt)
2824 /* Function for yyparse to call. yylex keeps track of
2825 the last two tokens read, and calls read_token. */
2829 if (interactive && (!current_token || current_token == '\n'))
2831 /* Before we print a prompt, we might have to check mailboxes.
2832 We do this only if it is time to do so. Notice that only here
2833 is the mail alarm reset; nothing takes place in check_mail ()
2834 except the checking of mail. Please don't change this. */
2835 if (prompt_is_ps1 && time_to_check_mail ())
2838 reset_mail_timer ();
2841 /* Avoid printing a prompt if we're not going to read anything, e.g.
2842 after resetting the parser with read_token (RESET). */
2843 if (token_to_read == 0 && interactive)
2847 token_before_that = last_read_token;
2848 last_read_token = current_token;
2849 current_token = read_token (READ);
2850 return (current_token);
2853 /* Called from shell.c when Control-C is typed at top level. Or
2854 by the error rule at top level. */
2860 /* When non-zero, we have read the required tokens
2861 which allow ESAC to be the next one read. */
2862 static int allow_esac_as_next = 0;
2864 /* When non-zero, accept single '{' as a token itself. */
2865 static int allow_open_brace = 0;
2867 /* DELIMITERS is a stack of the nested delimiters that we have
2868 encountered so far. */
2869 static char *delimiters = (char *)NULL;
2871 /* Offset into the stack of delimiters. */
2872 int delimiter_depth = 0;
2874 /* How many slots are allocated to DELIMITERS. */
2875 static int delimiter_space = 0;
2878 gather_here_documents ()
2881 while (need_here_doc)
2883 make_here_document (redir_stack[r++]);
2888 /* Macro for accessing the top delimiter on the stack. Returns the
2889 delimiter or zero if none. */
2890 #define current_delimiter() \
2891 (delimiter_depth ? delimiters[delimiter_depth - 1] : 0)
2893 #define push_delimiter(character) \
2896 if (delimiter_depth + 2 > delimiter_space) \
2897 delimiters = xrealloc \
2898 (delimiters, (delimiter_space += 10) * sizeof (char)); \
2899 delimiters[delimiter_depth] = character; \
2900 delimiter_depth++; \
2904 /* When non-zero, an open-brace used to create a group is awaiting a close
2906 static int open_brace_awaiting_satisfaction = 0;
2908 #define command_token_position(token) \
2909 (((token) == ASSIGNMENT_WORD) || \
2910 ((token) != SEMI_SEMI && reserved_word_acceptable(token)))
2912 #define assignment_acceptable(token) command_token_position(token) && \
2913 (in_case_pattern_list == 0)
2915 /* Check to see if TOKEN is a reserved word and return the token
2917 #define CHECK_FOR_RESERVED_WORD(tok) \
2919 if (!dollar_present && !quoted && \
2920 reserved_word_acceptable (last_read_token)) \
2923 for (i = 0; word_token_alist[i].word != (char *)NULL; i++) \
2924 if (STREQ (tok, word_token_alist[i].word)) \
2926 if (in_case_pattern_list && (word_token_alist[i].token != ESAC)) \
2929 if (word_token_alist[i].token == ESAC) \
2930 in_case_pattern_list = 0; \
2932 if (word_token_alist[i].token == '{') \
2933 open_brace_awaiting_satisfaction++; \
2935 if (word_token_alist[i].token == '}' && open_brace_awaiting_satisfaction) \
2936 open_brace_awaiting_satisfaction--; \
2938 return (word_token_alist[i].token); \
2943 /* Read the next token. Command can be READ (normal operation) or
2944 RESET (to normalize state). */
2946 read_token (command)
2949 int character; /* Current character. */
2950 int peek_char; /* Temporary look-ahead character. */
2951 int result; /* The thing to return. */
2952 WORD_DESC *the_word; /* The value for YYLVAL when a WORD is read. */
2954 if (token_buffer_size < TOKEN_DEFAULT_GROW_SIZE)
2957 token = xmalloc (token_buffer_size = TOKEN_DEFAULT_GROW_SIZE);
2960 if (command == RESET)
2962 delimiter_depth = 0; /* No delimiters found so far. */
2963 open_brace_awaiting_satisfaction = 0;
2964 in_case_pattern_list = 0;
2967 if (pushed_string_list)
2969 free_string_list ();
2970 pushed_string_list = (STRING_SAVER *)NULL;
2973 if (expanded_token_stack)
2975 free_expansion_stack ();
2976 expanded_token_stack = (EXPANSION_SAVER *)NULL;
2979 expand_next_token = 0;
2982 if (shell_input_line)
2984 free (shell_input_line);
2985 shell_input_line = (char *)NULL;
2986 shell_input_line_size = shell_input_line_index = 0;
2988 last_read_token = '\n';
2989 token_to_read = '\n';
2995 int rt = token_to_read;
3001 /* If we hit read_token () and there are no saved strings on the
3002 pushed_string_list, then we are no longer currently expanding a
3003 token. This can't be done in pop_stream, because pop_stream
3004 may pop the stream before the current token has finished being
3005 completely expanded (consider what happens when we alias foo to foo,
3006 and then try to expand it). */
3007 if (!pushed_string_list && expanded_token_stack)
3009 free_expansion_stack ();
3010 expanded_token_stack = (EXPANSION_SAVER *)NULL;
3013 /* This is a place to jump back to once we have successfully expanded a
3014 token with an alias and pushed the string with push_string () */
3019 /* Read a single word from input. Start by skipping blanks. */
3020 while ((character = shell_getc (1)) != EOF && whitespace (character));
3022 if (character == EOF)
3028 if (character == '#' && (!interactive || interactive_comments))
3030 /* A comment. Discard until EOL or EOF, and then return a newline. */
3031 discard_until ('\n');
3034 /* If we're about to return an unquoted newline, we can go and collect
3035 the text of any pending here documents. */
3037 gather_here_documents ();
3040 expand_next_token = 0;
3046 if (character == '\n')
3048 /* If we're about to return an unquoted newline, we can go and collect
3049 the text of any pending here document. */
3051 gather_here_documents ();
3054 expand_next_token = 0;
3060 if (member (character, "()<>;&|"))
3063 /* Turn off alias tokenization iff this character sequence would
3064 not leave us ready to read a command. */
3065 if (character == '<' || character == '>')
3066 expand_next_token = 0;
3069 /* Please note that the shell does not allow whitespace to
3070 appear in between tokens which are character pairs, such as
3071 "<<" or ">>". I believe this is the correct behaviour. */
3072 if (character == (peek_char = shell_getc (1)))
3076 /* If '<' then we could be at "<<" or at "<<-". We have to
3077 look ahead one more character. */
3079 peek_char = shell_getc (1);
3080 if (peek_char == '-')
3081 return (LESS_LESS_MINUS);
3084 shell_ungetc (peek_char);
3089 return (GREATER_GREATER);
3092 in_case_pattern_list = 1;
3094 expand_next_token = 0;
3107 if (peek_char == '&')
3111 case '<': return (LESS_AND);
3112 case '>': return (GREATER_AND);
3115 if (character == '<' && peek_char == '>')
3116 return (LESS_GREATER);
3117 if (character == '>' && peek_char == '|')
3118 return (GREATER_BAR);
3119 if (peek_char == '>' && character == '&')
3120 return (AND_GREATER);
3122 shell_ungetc (peek_char);
3124 /* If we look like we are reading the start of a function
3125 definition, then let the reader know about it so that
3126 we will do the right thing with `{'. */
3127 if (character == ')' &&
3128 last_read_token == '(' && token_before_that == WORD)
3130 allow_open_brace = 1;
3132 expand_next_token = 0;
3136 if (in_case_pattern_list && (character == ')'))
3137 in_case_pattern_list = 0;
3139 #if defined (PROCESS_SUBSTITUTION)
3140 /* Check for the constructs which introduce process substitution.
3141 Shells running in `posix mode' don't do process substitution. */
3142 if (posixly_correct ||
3143 (((character == '>' || character == '<') && peek_char == '(') == 0))
3144 #endif /* PROCESS_SUBSTITUTION */
3148 /* Hack <&- (close stdin) case. */
3149 if (character == '-')
3151 switch (last_read_token)
3159 /* Okay, if we got this far, we have to read a word. Read one,
3160 and then check it against the known ones. */
3162 /* Index into the token that we are building. */
3163 int token_index = 0;
3165 /* ALL_DIGITS becomes zero when we see a non-digit. */
3166 int all_digits = digit (character);
3168 /* DOLLAR_PRESENT becomes non-zero if we see a `$'. */
3169 int dollar_present = 0;
3171 /* QUOTED becomes non-zero if we see one of ("), ('), (`), or (\). */
3174 /* Non-zero means to ignore the value of the next character, and just
3175 to add it no matter what. */
3176 int pass_next_character = 0;
3178 /* Non-zero means parsing a dollar-paren construct. It is the count of
3179 un-quoted closes we need to see. */
3180 int dollar_paren_level = 0;
3182 /* Non-zero means parsing a dollar-bracket construct ($[...]). It is
3183 the count of un-quoted `]' characters we need to see. */
3184 int dollar_bracket_level = 0;
3186 /* Non-zero means parsing a `${' construct. It is the count of
3187 un-quoted `}' we need to see. */
3188 int dollar_brace_level = 0;
3190 /* A level variable for parsing '${ ... }' constructs inside of double
3192 int delimited_brace_level = 0;
3194 /* A boolean variable denoting whether or not we are currently parsing
3195 a double-quoted string embedded in a $( ) or ${ } construct. */
3196 int embedded_quoted_string = 0;
3198 /* Another level variable. This one is for dollar_parens inside of
3200 int delimited_paren_level = 0;
3202 /* The current delimiting character. */
3207 if (character == EOF)
3210 if (pass_next_character)
3212 pass_next_character = 0;
3216 cd = current_delimiter ();
3218 if (cd && character == '\\' && cd != '\'')
3220 peek_char = shell_getc (0);
3221 if (peek_char != '\\')
3222 shell_ungetc (peek_char);
3225 token[token_index++] = character;
3230 /* Handle backslashes. Quote lots of things when not inside of
3231 double-quotes, quote some things inside of double-quotes. */
3233 if (character == '\\' && (!delimiter_depth || cd != '\''))
3235 peek_char = shell_getc (0);
3237 /* Backslash-newline is ignored in all cases excepting
3238 when quoted with single quotes. */
3239 if (peek_char == '\n')
3242 goto next_character;
3246 shell_ungetc (peek_char);
3248 /* If the next character is to be quoted, do it now. */
3249 if (!cd || cd == '`' ||
3250 (cd == '"' && member (peek_char, slashify_in_quotes)))
3252 pass_next_character++;
3259 /* This is a hack, in its present form. If a backquote substitution
3260 appears within double quotes, everything within the backquotes
3261 should be read as part of a single word. Jesus. Now I see why
3262 Korn introduced the $() form. */
3263 if (delimiter_depth && (cd == '"') && (character == '`'))
3265 push_delimiter (character);
3269 cd = current_delimiter (); /* XXX - may not need */
3270 if (delimiter_depth)
3272 if (character == cd)
3274 /* If we see a double quote while parsing a double-quoted
3275 $( ) or ${ }, and we have not seen ) or }, respectively,
3276 note that we are in the middle of reading an embedded
3278 if ((delimited_paren_level || delimited_brace_level) &&
3281 embedded_quoted_string = !embedded_quoted_string;
3292 #if defined (PROCESS_SUBSTITUTION)
3293 if (character == '$' || character == '<' || character == '>')
3295 if (character == '$')
3296 #endif /* !PROCESS_SUBSTITUTION */
3298 /* If we're in the middle of parsing a $( ) or ${ }
3299 construct with an embedded quoted string, don't
3300 bother looking at this character any further. */
3301 if (embedded_quoted_string)
3304 peek_char = shell_getc (1);
3305 shell_ungetc (peek_char);
3306 if (peek_char == '(')
3308 if (!delimiter_depth)
3309 dollar_paren_level++;
3311 delimited_paren_level++;
3313 pass_next_character++;
3316 else if (peek_char == '[' && character == '$')
3318 if (!delimiter_depth)
3319 dollar_bracket_level++;
3321 pass_next_character++;
3324 /* This handles ${...} constructs. */
3325 else if (peek_char == '{' && character == '$')
3327 if (!delimiter_depth)
3328 dollar_brace_level++;
3330 delimited_brace_level++;
3332 pass_next_character++;
3337 /* If we are parsing a $() or $[] construct, we need to balance
3338 parens and brackets inside the construct. This whole function
3339 could use a rewrite. */
3340 if (character == '(' && !embedded_quoted_string)
3342 if (delimiter_depth && delimited_paren_level)
3343 delimited_paren_level++;
3345 if (!delimiter_depth && dollar_paren_level)
3346 dollar_paren_level++;
3349 if (character == '[')
3351 if (!delimiter_depth && dollar_bracket_level)
3352 dollar_bracket_level++;
3355 if (character == '{' && !embedded_quoted_string)
3357 if (delimiter_depth && delimited_brace_level)
3358 delimited_brace_level++;
3360 if (!delimiter_depth && dollar_brace_level)
3361 dollar_brace_level++;
3364 /* This code needs to take into account whether we are inside a
3365 case statement pattern list, and whether this paren is supposed
3366 to terminate it (hey, it could happen). It's not as simple
3367 as just using in_case_pattern_list, because we're not parsing
3368 anything while we're reading a $( ) construct. Maybe we
3369 should move that whole mess into the yacc parser. */
3370 if (character == ')' && !embedded_quoted_string)
3372 if (delimiter_depth && delimited_paren_level)
3373 delimited_paren_level--;
3375 if (!delimiter_depth && dollar_paren_level)
3377 dollar_paren_level--;
3382 if (character == ']')
3384 if (!delimiter_depth && dollar_bracket_level)
3386 dollar_bracket_level--;
3391 if (character == '}' && !embedded_quoted_string)
3393 if (delimiter_depth && delimited_brace_level)
3394 delimited_brace_level--;
3396 if (!delimiter_depth && dollar_brace_level)
3398 dollar_brace_level--;
3404 if (!dollar_paren_level && !dollar_bracket_level &&
3405 !dollar_brace_level && !delimiter_depth &&
3406 member (character, " \t\n;&()|<>"))
3408 shell_ungetc (character);
3412 if (!delimiter_depth)
3414 if (character == '"' || character == '`' || character == '\'')
3416 push_delimiter (character);
3424 all_digits = digit (character);
3425 if (character == '$')
3430 if (character == CTLESC || character == CTLNUL)
3431 token[token_index++] = CTLESC;
3433 token[token_index++] = character;
3435 if (token_index == (token_buffer_size - 1))
3437 token_buffer_size += TOKEN_DEFAULT_GROW_SIZE;
3438 token = xrealloc (token, token_buffer_size);
3441 if (character == '\n' && interactive && bash_input.type != st_string)
3444 /* We want to remove quoted newlines (that is, a \<newline> pair)
3445 unless we are within single quotes or pass_next_character is
3446 set (the shell equivalent of literal-next). */
3447 character = shell_getc
3448 ((current_delimiter () != '\'') && (!pass_next_character));
3453 token[token_index] = '\0';
3455 if ((delimiter_depth || dollar_paren_level || dollar_bracket_level) &&
3458 char reporter = '\0';
3460 if (!delimiter_depth)
3462 if (dollar_paren_level)
3464 else if (dollar_bracket_level)
3469 reporter = current_delimiter ();
3471 report_error ("unexpected EOF while looking for `%c'", reporter);
3477 /* Check to see what thing we should return. If the last_read_token
3478 is a `<', or a `&', or the character which ended this token is
3479 a '>' or '<', then, and ONLY then, is this input token a NUMBER.
3480 Otherwise, it is just a word, and should be returned as such. */
3482 if (character == '<' || character == '>' ||
3483 last_read_token == LESS_AND || last_read_token == GREATER_AND)
3485 yylval.number = atoi (token);
3490 /* Handle special case. IN is recognized if the last token
3491 was WORD and the token before that was FOR or CASE. */
3492 if ((last_read_token == WORD) &&
3493 #if defined (SELECT_COMMAND)
3494 ((token_before_that == FOR) || (token_before_that == CASE) || (token_before_that == SELECT)) &&
3496 ((token_before_that == FOR) || (token_before_that == CASE)) &&
3498 (token[0] == 'i' && token[1] == 'n' && !token[2]))
3500 if (token_before_that == CASE)
3502 in_case_pattern_list = 1;
3503 allow_esac_as_next++;
3508 /* Ditto for DO in the FOR case. */
3509 #if defined (SELECT_COMMAND)
3510 if ((last_read_token == WORD) && ((token_before_that == FOR) || (token_before_that == SELECT)) &&
3512 if ((last_read_token == WORD) && (token_before_that == FOR) &&
3514 (token[0] == 'd' && token[1] == 'o' && !token[2]))
3517 /* Ditto for ESAC in the CASE case.
3518 Specifically, this handles "case word in esac", which is a legal
3519 construct, certainly because someone will pass an empty arg to the
3520 case construct, and we don't want it to barf. Of course, we should
3521 insist that the case construct has at least one pattern in it, but
3522 the designers disagree. */
3523 if (allow_esac_as_next)
3525 allow_esac_as_next--;
3526 if (STREQ (token, "esac"))
3528 in_case_pattern_list = 0;
3533 /* Ditto for `{' in the FUNCTION case. */
3534 if (allow_open_brace)
3536 allow_open_brace = 0;
3537 if (token[0] == '{' && !token[1])
3539 open_brace_awaiting_satisfaction++;
3544 if (posixly_correct)
3545 CHECK_FOR_RESERVED_WORD (token);
3548 /* OK, we have a token. Let's try to alias expand it, if (and only if)
3551 It is eligible for expansion if the shell is in interactive mode, and
3552 the token is unquoted and the last token read was a command
3553 separator (or expand_next_token is set), and we are currently
3554 processing an alias (pushed_string_list is non-empty) and this
3555 token is not the same as the current or any previously
3558 Special cases that disqualify:
3559 In a pattern list in a case statement (in_case_pattern_list). */
3560 if (interactive_shell && !quoted && !in_case_pattern_list &&
3561 (expand_next_token || command_token_position (last_read_token)))
3563 char *alias_expand_word (), *expanded;
3565 if (expanded_token_stack && token_has_been_expanded (token))
3568 expanded = alias_expand_word (token);
3571 int len = strlen (expanded), expand_next;
3573 /* Erase the current token. */
3576 expand_next = (expanded[len - 1] == ' ') ||
3577 (expanded[len - 1] == '\t');
3579 push_string (expanded, expand_next, token);
3583 /* This is an eligible token that does not have an expansion. */
3585 expand_next_token = 0;
3589 expand_next_token = 0;
3593 if (!posixly_correct)
3594 CHECK_FOR_RESERVED_WORD (token);
3596 /* What if we are attempting to satisfy an open-brace grouper? */
3597 if (open_brace_awaiting_satisfaction && token[0] == '}' && !token[1])
3599 open_brace_awaiting_satisfaction--;
3603 the_word = (WORD_DESC *)xmalloc (sizeof (WORD_DESC));
3604 the_word->word = xmalloc (1 + token_index);
3605 strcpy (the_word->word, token);
3606 the_word->dollar_present = dollar_present;
3607 the_word->quoted = quoted;
3608 the_word->assignment = assignment (token);
3610 yylval.word = the_word;
3613 /* A word is an assignment if it appears at the beginning of a
3614 simple command, or after another assignment word. This is
3615 context-dependent, so it cannot be handled in the grammar. */
3616 if (assignment_acceptable (last_read_token) && the_word->assignment)
3617 result = ASSIGNMENT_WORD;
3619 if (last_read_token == FUNCTION)
3620 allow_open_brace = 1;
3625 /* Return 1 if TOKEN is a token that after being read would allow
3626 a reserved word to be seen, else 0. */
3628 reserved_word_acceptable (token)
3632 if (member (token, "\n;()|&{") ||
3634 if (token == '\n' || token == ';' || token == '(' || token == ')' ||
3635 token == '|' || token == '&' || token == '{' ||
3637 token == '}' || /* XXX */
3646 token == SEMI_SEMI ||
3650 token == DONE || /* XXX these two are experimental */
3658 /* Return the index of TOKEN in the alist of reserved words, or -1 if
3659 TOKEN is not a shell reserved word. */
3661 find_reserved_word (token)
3665 for (i = 0; word_token_alist[i].word != (char *)NULL; i++)
3666 if (STREQ (token, word_token_alist[i].word))
3671 #if defined (READLINE)
3672 /* Called after each time readline is called. This insures that whatever
3673 the new prompt string is gets propagated to readline's local prompt
3676 reset_readline_prompt ()
3678 if (prompt_string_pointer)
3682 temp_prompt = *prompt_string_pointer
3683 ? decode_prompt_string (*prompt_string_pointer)
3686 if (temp_prompt == 0)
3688 temp_prompt = xmalloc (1);
3689 temp_prompt[0] = '\0';
3692 FREE (current_readline_prompt);
3694 current_readline_prompt = temp_prompt;
3697 #endif /* READLINE */
3699 #if defined (HISTORY)
3700 /* A list of tokens which can be followed by newlines, but not by
3701 semi-colons. When concatenating multiple lines of history, the
3702 newline separator for such tokens is replaced with a space. */
3703 static int no_semi_successors[] = {
3704 '\n', '{', '(', ')', ';', '&', '|',
3705 CASE, DO, ELSE, IF, IN, SEMI_SEMI, THEN, UNTIL, WHILE, AND_AND, OR_OR,
3709 /* If we are not within a delimited expression, try to be smart
3710 about which separators can be semi-colons and which must be
3713 history_delimiting_chars ()
3715 if (!delimiter_depth)
3719 for (i = 0; no_semi_successors[i]; i++)
3721 if (token_before_that == no_semi_successors[i])
3729 #endif /* HISTORY */
3731 /* Issue a prompt, or prepare to issue a prompt when the next character
3738 if (!interactive) /* XXX */
3741 ps1_prompt = get_string_value ("PS1");
3742 ps2_prompt = get_string_value ("PS2");
3744 if (!prompt_string_pointer)
3745 prompt_string_pointer = &ps1_prompt;
3747 temp_prompt = (*prompt_string_pointer)
3748 ? decode_prompt_string (*prompt_string_pointer)
3751 if (temp_prompt == 0)
3753 temp_prompt = xmalloc (1);
3754 temp_prompt[0] = '\0';
3757 current_prompt_string = *prompt_string_pointer;
3758 prompt_string_pointer = &ps2_prompt;
3760 #if defined (READLINE)
3761 if (!no_line_editing)
3763 FREE (current_readline_prompt);
3764 current_readline_prompt = temp_prompt;
3767 #endif /* READLINE */
3769 FREE (current_decoded_prompt);
3770 current_decoded_prompt = temp_prompt;
3777 fprintf (stderr, "%s", current_decoded_prompt);
3781 /* Return a string which will be printed as a prompt. The string
3782 may contain special characters which are decoded as follows:
3787 \s the name of the shell
3788 \w the current working directory
3789 \W the last element of PWD
3792 \# the command number of this command
3793 \! the history number of this command
3794 \$ a $ or a # if you are root
3795 \<octal> character code in octal
3798 #define PROMPT_GROWTH 50
3800 decode_prompt_string (string)
3803 int result_size = PROMPT_GROWTH;
3804 int result_index = 0;
3807 char *temp = (char *)NULL;
3810 #if defined (PROMPT_STRING_DECODE)
3812 result = xmalloc (PROMPT_GROWTH);
3815 while (c = *string++)
3817 if (posixly_correct && c == '!')
3821 temp = savestring ("!");
3826 #if !defined (HISTORY)
3827 temp = savestring ("1");
3829 temp = itos (history_number ());
3830 #endif /* HISTORY */
3831 string--; /* add_string increments string again. */
3850 char octal_string[4];
3853 strncpy (octal_string, string, 3);
3854 octal_string[3] = '\0';
3856 n = read_octal (octal_string);
3859 if (n == CTLESC || n == CTLNUL)
3884 /* Make the current time/date into a string. */
3886 time_t the_time = time (0);
3887 char *ttemp = ctime (&the_time);
3888 temp = savestring (ttemp);
3892 strcpy (temp, temp + 11);
3902 if (!no_line_editing)
3903 temp = savestring ("\r\n");
3905 temp = savestring ("\n");
3910 temp = base_pathname (shell_name);
3911 temp = savestring (temp);
3918 /* Use the value of PWD because it is much more effecient. */
3921 char *polite_directory_format (), t_string[MAXPATHLEN];
3923 temp = get_string_value ("PWD");
3928 strcpy (t_string, temp);
3931 #endif /* EFFICIENT */
3935 char *dir = (char *)strrchr (t_string, '/');
3936 if (dir && dir != t_string)
3937 strcpy (t_string, dir + 1);
3938 temp = savestring (t_string);
3941 temp = savestring (polite_directory_format (t_string));
3947 temp = savestring (current_user.user_name);
3955 temp = savestring (current_host_name);
3956 if (t_string = (char *)strchr (temp, '.'))
3963 temp = itos (current_command_number);
3969 #if !defined (HISTORY)
3970 temp = savestring ("1");
3972 temp = itos (history_number ());
3973 #endif /* HISTORY */
3978 temp = savestring (geteuid () == 0 ? "#" : "$");
3981 #if defined (READLINE)
3986 temp[1] = (c == '[') ? RL_PROMPT_START_IGNORE : RL_PROMPT_END_IGNORE;
3992 temp = savestring ("\\");
3996 temp = savestring ("\\ ");
4003 sub_append_string (temp, result, &result_index, &result_size);
4004 temp = (char *)NULL; /* Free ()'ed in sub_append_string (). */
4005 result[result_index] = '\0';
4011 while (3 + result_index > result_size)
4012 result = xrealloc (result, result_size += PROMPT_GROWTH);
4014 result[result_index++] = c;
4015 result[result_index] = '\0';
4018 #else /* !PROMPT_STRING_DECODE */
4019 result = savestring (string);
4020 #endif /* !PROMPT_STRING_DECODE */
4022 /* Perform variable and parameter expansion and command substitution on
4023 the prompt string. */
4024 list = expand_string_unsplit (result, 1);
4026 result = string_list (list);
4027 dispose_words (list);
4032 /* Report a syntax error, and restart the parser. Call here for fatal
4036 report_syntax_error ((char *)NULL);
4040 /* Report a syntax error with line numbers, etc.
4041 Call here for recoverable errors. If you have a message to print,
4042 then place it in MESSAGE, otherwise pass NULL and this will figure
4043 out an appropriate message for you. */
4045 report_syntax_error (message)
4052 char *name = bash_input.name ? bash_input.name : "stdin";
4053 report_error ("%s: line %d: `%s'", name, line_number, message);
4059 report_error ("%s", message);
4062 last_command_exit_value = EX_USAGE;
4066 if (shell_input_line && *shell_input_line)
4068 char *t = shell_input_line;
4069 register int i = shell_input_line_index;
4075 while (i && (t[i] == ' ' || t[i] == '\t' || t[i] == '\n'))
4081 while (i && !member (t[i], " \n\t;|&"))
4084 while (i != token_end && member (t[i], " \t\n"))
4090 error_token = xmalloc (1 + (token_end - i));
4091 strncpy (error_token, t + i, token_end - i);
4092 error_token[token_end - i] = '\0';
4094 report_error ("syntax error near unexpected token `%s'", error_token);
4097 else if ((i == 0) && (token_end == 0)) /* a 1-character token */
4103 report_error ("syntax error near unexpected token `%s'", etoken);
4108 char *temp = savestring (shell_input_line);
4109 char *name = bash_input.name ? bash_input.name : "stdin";
4110 int l = strlen (temp);
4112 while (l && temp[l - 1] == '\n')
4115 report_error ("%s: line %d: `%s'", name, line_number, temp);
4123 name = bash_input.name ? bash_input.name : "stdin";
4125 msg = "syntax error: unexpected end of file";
4127 msg = "syntax error";
4129 report_error ("%s: line %d: %s", name, line_number, msg);
4132 /* This file uses EOF_Reached only for error reporting
4133 when the shell is interactive. Other mechanisms are
4134 used to decide whether or not to exit. */
4139 last_command_exit_value = EX_USAGE;
4142 /* ??? Needed function. ??? We have to be able to discard the constructs
4143 created during parsing. In the case of error, we want to return
4144 allocated objects to the memory pool. In the case of no error, we want
4145 to throw away the information about where the allocated objects live.
4146 (dispose_command () will actually free the command. */
4147 discard_parser_constructs (error_p)
4152 /* Do that silly `type "bye" to exit' stuff. You know, "ignoreeof". */
4154 /* A flag denoting whether or not ignoreeof is set. */
4157 /* The number of times that we have encountered an EOF character without
4158 another character intervening. When this gets above the limit, the
4159 shell terminates. */
4160 int eof_encountered = 0;
4162 /* The limit for eof_encountered. */
4163 int eof_encountered_limit = 10;
4165 /* If we have EOF as the only input unit, this user wants to leave
4166 the shell. If the shell is not interactive, then just leave.
4167 Otherwise, if ignoreeof is set, and we haven't done this the
4168 required number of times in a row, print a message. */
4170 handle_eof_input_unit ()
4174 /* shell.c may use this to decide whether or not to write out the
4175 history, among other things. We use it only for error reporting
4180 /* If the user wants to "ignore" eof, then let her do so, kind of. */
4183 if (eof_encountered < eof_encountered_limit)
4185 fprintf (stderr, "Use \"%s\" to leave the shell.\n",
4186 login_shell ? "logout" : "exit");
4188 /* Reset the prompt string to be $PS1. */
4189 prompt_string_pointer = (char **)NULL;
4191 last_read_token = current_token = '\n';
4196 /* In this case EOF should exit the shell. Do it now. */
4198 exit_builtin ((WORD_LIST *)NULL);
4202 /* We don't write history files, etc., for non-interactive shells. */