0b1fd0900b0b88e5e050d34447f3951f473953f1
[platform/upstream/bash.git] / y.tab.c
1
2 /*  A Bison parser, made from ./parse.y
3  by  GNU Bison version 1.25
4   */
5
6 #define YYBISON 1  /* Identify Bison output.  */
7
8 #define IF      258
9 #define THEN    259
10 #define ELSE    260
11 #define ELIF    261
12 #define FI      262
13 #define CASE    263
14 #define ESAC    264
15 #define FOR     265
16 #define SELECT  266
17 #define WHILE   267
18 #define UNTIL   268
19 #define DO      269
20 #define DONE    270
21 #define FUNCTION        271
22 #define IN      272
23 #define BANG    273
24 #define WORD    274
25 #define ASSIGNMENT_WORD 275
26 #define NUMBER  276
27 #define AND_AND 277
28 #define OR_OR   278
29 #define GREATER_GREATER 279
30 #define LESS_LESS       280
31 #define LESS_AND        281
32 #define GREATER_AND     282
33 #define SEMI_SEMI       283
34 #define LESS_LESS_MINUS 284
35 #define AND_GREATER     285
36 #define LESS_GREATER    286
37 #define GREATER_BAR     287
38 #define yacc_EOF        288
39
40 #line 21 "./parse.y"
41
42 #include <stdio.h>
43 #include "bashtypes.h"
44 #include <signal.h>
45 #include "bashansi.h"
46 #include "shell.h"
47 #include "flags.h"
48 #include "input.h"
49
50 #if defined (READLINE)
51 #  include <readline/readline.h>
52 #endif /* READLINE */
53
54 #if defined (HISTORY)
55 #  include "bashhist.h"
56 #  include <readline/history.h>
57 #endif /* HISTORY */
58
59 #if defined (JOB_CONTROL)
60 #  include "jobs.h"
61 #endif /* JOB_CONTROL */
62
63 #if defined (ALIAS)
64 #  include "alias.h"
65 #endif /* ALIAS */
66
67 #if defined (PROMPT_STRING_DECODE)
68 #include <sys/param.h>
69 #include <time.h>
70 #include "maxpath.h"
71 #endif /* PROMPT_STRING_DECODE */
72
73 #define YYDEBUG 1
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;
85 #endif
86 #if defined (BUFFERED_INPUT)
87 extern int bash_input_fd_changed;
88 #endif
89
90 /* **************************************************************** */
91 /*                                                                  */
92 /*                  "Forward" declarations                          */
93 /*                                                                  */
94 /* **************************************************************** */
95
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. */
99
100 static int reserved_word_acceptable ();
101 static int read_token ();
102
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 ();
108
109 /* PROMPT_STRING_POINTER points to one of these, never to an actual string. */
110 char *ps1_prompt, *ps2_prompt;
111
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;
116
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;
120
121 /* The number of lines read from input while creating the current command. */
122 int current_command_line_count = 0;
123
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;
128
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) */
135
136 /* Either zero or EOF. */
137 static int shell_input_line_terminator = 0;
138
139 static REDIRECTEE redir;
140
141 #line 122 "./parse.y"
142 typedef union {
143   WORD_DESC *word;              /* the word that we read. */
144   int number;                   /* the number that we read. */
145   WORD_LIST *word_list;
146   COMMAND *command;
147   REDIRECT *redirect;
148   ELEMENT element;
149   PATTERN_LIST *pattern;
150 } YYSTYPE;
151 #include <stdio.h>
152
153 #ifndef __cplusplus
154 #ifndef __STDC__
155 #define const
156 #endif
157 #endif
158
159
160
161 #define YYFINAL         258
162 #define YYFLAG          -32768
163 #define YYNTBASE        45
164
165 #define YYTRANSLATE(x) ((unsigned)(x) <= 288 ? yytranslate[x] : 73)
166
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
197 };
198
199 #if YYDEBUG != 0
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,
213    519,   524
214 };
215
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,
269     69,    72,     0,    51,     0
270 };
271
272 #endif
273
274 #if YYDEBUG != 0
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,
288    680,   683
289 };
290 #endif
291
292
293 #if YYDEBUG != 0 || defined (YYERROR_VERBOSE)
294
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",
305 "pipeline", NULL
306 };
307 #endif
308
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,
322     72,    72
323 };
324
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,
338      4,     1
339 };
340
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
368 };
369
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
374 };
375
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
403 };
404
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
409 };
410
411
412 #define YYLAST          533
413
414
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,
469      0,    59,    60
470 };
471
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,
526     -1,    38,    39
527 };
528 /* -*-C-*-  Note some compilers choke on comments on `#line' lines.  */
529 #line 3 "/usr/local/lib/bison.simple"
530
531 /* Skeleton output parser for bison,
532    Copyright (C) 1984, 1989, 1990 Free Software Foundation, Inc.
533
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)
537    any later version.
538
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.
543
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.  */
547
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.  */
552
553 #ifndef alloca
554 #ifdef __GNUC__
555 #define alloca __builtin_alloca
556 #else /* not GNU C.  */
557 #if (!defined (__STDC__) && defined (sparc)) || defined (__sparc__) || defined (__sparc) || defined (__sgi)
558 #include <alloca.h>
559 #else /* not sparc */
560 #if defined (MSDOS) && !defined (__TURBOC__)
561 #include <malloc.h>
562 #else /* not MSDOS, or __TURBOC__ */
563 #if defined(_AIX)
564 #include <malloc.h>
565  #pragma alloca
566 #else /* not MSDOS, __TURBOC__, or _AIX */
567 #ifdef __hpux
568 #ifdef __cplusplus
569 extern "C" {
570 void *alloca (unsigned int);
571 };
572 #else /* not __cplusplus */
573 void *alloca ();
574 #endif /* not __cplusplus */
575 #endif /* __hpux */
576 #endif /* not _AIX */
577 #endif /* not MSDOS, or __TURBOC__ */
578 #endif /* not sparc.  */
579 #endif /* not GNU C.  */
580 #endif /* alloca not defined.  */
581
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.  */
586
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.  */
590
591 #define yyerrok         (yyerrstatus = 0)
592 #define yyclearin       (yychar = YYEMPTY)
593 #define YYEMPTY         -2
594 #define YYEOF           0
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) \
605 do                                                              \
606   if (yychar == YYEMPTY && yylen == 1)                          \
607     { yychar = (token), yylval = (value);                       \
608       yychar1 = YYTRANSLATE (yychar);                           \
609       YYPOPSTACK;                                               \
610       goto yybackup;                                            \
611     }                                                           \
612   else                                                          \
613     { yyerror ("syntax error: cannot back up"); YYERROR; }      \
614 while (0)
615
616 #define YYTERROR        1
617 #define YYERRCODE       256
618
619 #ifndef YYPURE
620 #define YYLEX           yylex()
621 #endif
622
623 #ifdef YYPURE
624 #ifdef YYLSP_NEEDED
625 #ifdef YYLEX_PARAM
626 #define YYLEX           yylex(&yylval, &yylloc, YYLEX_PARAM)
627 #else
628 #define YYLEX           yylex(&yylval, &yylloc)
629 #endif
630 #else /* not YYLSP_NEEDED */
631 #ifdef YYLEX_PARAM
632 #define YYLEX           yylex(&yylval, YYLEX_PARAM)
633 #else
634 #define YYLEX           yylex(&yylval)
635 #endif
636 #endif /* not YYLSP_NEEDED */
637 #endif
638
639 /* If nonreentrant, generate the variables here */
640
641 #ifndef YYPURE
642
643 int     yychar;                 /*  the lookahead symbol                */
644 YYSTYPE yylval;                 /*  the semantic value of the           */
645                                 /*  lookahead symbol                    */
646
647 #ifdef YYLSP_NEEDED
648 YYLTYPE yylloc;                 /*  location data for the lookahead     */
649                                 /*  symbol                              */
650 #endif
651
652 int yynerrs;                    /*  number of parse errors so far       */
653 #endif  /* not YYPURE */
654
655 #if YYDEBUG != 0
656 int yydebug;                    /*  nonzero means print parse trace     */
657 /* Since this is uninitialized, it does not stop multiple parsers
658    from coexisting.  */
659 #endif
660
661 /*  YYINITDEPTH indicates the initial size of the parser's stacks       */
662
663 #ifndef YYINITDEPTH
664 #define YYINITDEPTH 200
665 #endif
666
667 /*  YYMAXDEPTH is the maximum size the stacks can grow to
668     (effective only if the built-in stack extension method is used).  */
669
670 #if YYMAXDEPTH == 0
671 #undef YYMAXDEPTH
672 #endif
673
674 #ifndef YYMAXDEPTH
675 #define YYMAXDEPTH 10000
676 #endif
677
678 /* Prevent warning if -Wstrict-prototypes.  */
679 #ifdef __GNUC__
680 int yyparse (void);
681 #endif
682 \f
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++ */
686 #ifndef __cplusplus
687
688 /* This is the most reliable way to avoid incompatibilities
689    in available built-in functions on various systems.  */
690 static void
691 __yy_memcpy (to, from, count)
692      char *to;
693      char *from;
694      int count;
695 {
696   register char *f = from;
697   register char *t = to;
698   register int i = count;
699
700   while (i-- > 0)
701     *t++ = *f++;
702 }
703
704 #else /* __cplusplus */
705
706 /* This is the most reliable way to avoid incompatibilities
707    in available built-in functions on various systems.  */
708 static void
709 __yy_memcpy (char *to, char *from, int count)
710 {
711   register char *f = from;
712   register char *t = to;
713   register int i = count;
714
715   while (i-- > 0)
716     *t++ = *f++;
717 }
718
719 #endif
720 #endif
721 \f
722 #line 196 "/usr/local/lib/bison.simple"
723
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.  */
729
730 #ifdef YYPARSE_PARAM
731 #ifdef __cplusplus
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 */
742
743 int
744 yyparse(YYPARSE_PARAM_ARG)
745      YYPARSE_PARAM_DECL
746 {
747   register int yystate;
748   register int yyn;
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 */
753
754   short yyssa[YYINITDEPTH];     /*  the state stack                     */
755   YYSTYPE yyvsa[YYINITDEPTH];   /*  the semantic value stack            */
756
757   short *yyss = yyssa;          /*  refer to the stacks thru separate pointers */
758   YYSTYPE *yyvs = yyvsa;        /*  to allow yyoverflow to reallocate them elsewhere */
759
760 #ifdef YYLSP_NEEDED
761   YYLTYPE yylsa[YYINITDEPTH];   /*  the location stack                  */
762   YYLTYPE *yyls = yylsa;
763   YYLTYPE *yylsp;
764
765 #define YYPOPSTACK   (yyvsp--, yyssp--, yylsp--)
766 #else
767 #define YYPOPSTACK   (yyvsp--, yyssp--)
768 #endif
769
770   int yystacksize = YYINITDEPTH;
771
772 #ifdef YYPURE
773   int yychar;
774   YYSTYPE yylval;
775   int yynerrs;
776 #ifdef YYLSP_NEEDED
777   YYLTYPE yylloc;
778 #endif
779 #endif
780
781   YYSTYPE yyval;                /*  the variable used to return         */
782                                 /*  semantic values from the action     */
783                                 /*  routines                            */
784
785   int yylen;
786
787 #if YYDEBUG != 0
788   if (yydebug)
789     fprintf(stderr, "Starting parse\n");
790 #endif
791
792   yystate = 0;
793   yyerrstatus = 0;
794   yynerrs = 0;
795   yychar = YYEMPTY;             /* Cause a token to be read.  */
796
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.  */
801
802   yyssp = yyss - 1;
803   yyvsp = yyvs;
804 #ifdef YYLSP_NEEDED
805   yylsp = yyls;
806 #endif
807
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.  */
811 yynewstate:
812
813   *++yyssp = yystate;
814
815   if (yyssp >= yyss + yystacksize - 1)
816     {
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;
820       short *yyss1 = yyss;
821 #ifdef YYLSP_NEEDED
822       YYLTYPE *yyls1 = yyls;
823 #endif
824
825       /* Get the current used size of the three stacks, in elements.  */
826       int size = yyssp - yyss + 1;
827
828 #ifdef yyoverflow
829       /* Each stack pointer address is followed by the size of
830          the data in use in that stack, in bytes.  */
831 #ifdef YYLSP_NEEDED
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),
838                  &yystacksize);
839 #else
840       yyoverflow("parser stack overflow",
841                  &yyss1, size * sizeof (*yyssp),
842                  &yyvs1, size * sizeof (*yyvsp),
843                  &yystacksize);
844 #endif
845
846       yyss = yyss1; yyvs = yyvs1;
847 #ifdef YYLSP_NEEDED
848       yyls = yyls1;
849 #endif
850 #else /* no yyoverflow */
851       /* Extend the stack our own way.  */
852       if (yystacksize >= YYMAXDEPTH)
853         {
854           yyerror("parser stack overflow");
855           return 2;
856         }
857       yystacksize *= 2;
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));
864 #ifdef YYLSP_NEEDED
865       yyls = (YYLTYPE *) alloca (yystacksize * sizeof (*yylsp));
866       __yy_memcpy ((char *)yyls, (char *)yyls1, size * sizeof (*yylsp));
867 #endif
868 #endif /* no yyoverflow */
869
870       yyssp = yyss + size - 1;
871       yyvsp = yyvs + size - 1;
872 #ifdef YYLSP_NEEDED
873       yylsp = yyls + size - 1;
874 #endif
875
876 #if YYDEBUG != 0
877       if (yydebug)
878         fprintf(stderr, "Stack size increased to %d\n", yystacksize);
879 #endif
880
881       if (yyssp >= yyss + yystacksize - 1)
882         YYABORT;
883     }
884
885 #if YYDEBUG != 0
886   if (yydebug)
887     fprintf(stderr, "Entering state %d\n", yystate);
888 #endif
889
890   goto yybackup;
891  yybackup:
892
893 /* Do appropriate processing given the current state.  */
894 /* Read a lookahead token if we need one and don't already have one.  */
895 /* yyresume: */
896
897   /* First try to decide what to do without reference to lookahead token.  */
898
899   yyn = yypact[yystate];
900   if (yyn == YYFLAG)
901     goto yydefault;
902
903   /* Not known => get a lookahead token if don't already have one.  */
904
905   /* yychar is either YYEMPTY or YYEOF
906      or a valid token in external form.  */
907
908   if (yychar == YYEMPTY)
909     {
910 #if YYDEBUG != 0
911       if (yydebug)
912         fprintf(stderr, "Reading a token: ");
913 #endif
914       yychar = YYLEX;
915     }
916
917   /* Convert token to internal form (in yychar1) for indexing tables with */
918
919   if (yychar <= 0)              /* This means end of input. */
920     {
921       yychar1 = 0;
922       yychar = YYEOF;           /* Don't call YYLEX any more */
923
924 #if YYDEBUG != 0
925       if (yydebug)
926         fprintf(stderr, "Now at end of input.\n");
927 #endif
928     }
929   else
930     {
931       yychar1 = YYTRANSLATE(yychar);
932
933 #if YYDEBUG != 0
934       if (yydebug)
935         {
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.  */
939 #ifdef YYPRINT
940           YYPRINT (stderr, yychar, yylval);
941 #endif
942           fprintf (stderr, ")\n");
943         }
944 #endif
945     }
946
947   yyn += yychar1;
948   if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != yychar1)
949     goto yydefault;
950
951   yyn = yytable[yyn];
952
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,
957        just return success.
958      0, or most negative number => error.  */
959
960   if (yyn < 0)
961     {
962       if (yyn == YYFLAG)
963         goto yyerrlab;
964       yyn = -yyn;
965       goto yyreduce;
966     }
967   else if (yyn == 0)
968     goto yyerrlab;
969
970   if (yyn == YYFINAL)
971     YYACCEPT;
972
973   /* Shift the lookahead token.  */
974
975 #if YYDEBUG != 0
976   if (yydebug)
977     fprintf(stderr, "Shifting token %d (%s), ", yychar, yytname[yychar1]);
978 #endif
979
980   /* Discard the token being shifted unless it is eof.  */
981   if (yychar != YYEOF)
982     yychar = YYEMPTY;
983
984   *++yyvsp = yylval;
985 #ifdef YYLSP_NEEDED
986   *++yylsp = yylloc;
987 #endif
988
989   /* count tokens shifted since error; after three, turn off error status.  */
990   if (yyerrstatus) yyerrstatus--;
991
992   yystate = yyn;
993   goto yynewstate;
994
995 /* Do the default action for the current state.  */
996 yydefault:
997
998   yyn = yydefact[yystate];
999   if (yyn == 0)
1000     goto yyerrlab;
1001
1002 /* Do a reduction.  yyn is the number of a rule to reduce with.  */
1003 yyreduce:
1004   yylen = yyr2[yyn];
1005   if (yylen > 0)
1006     yyval = yyvsp[1-yylen]; /* implement default value of the action */
1007
1008 #if YYDEBUG != 0
1009   if (yydebug)
1010     {
1011       int i;
1012
1013       fprintf (stderr, "Reducing via rule %d (line %d), ",
1014                yyn, yyrline[yyn]);
1015
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]]);
1020     }
1021 #endif
1022
1023
1024   switch (yyn) {
1025
1026 case 1:
1027 #line 164 "./parse.y"
1028 {
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);
1034                           YYACCEPT;
1035                         ;
1036     break;}
1037 case 2:
1038 #line 173 "./parse.y"
1039 {
1040                           /* Case of regular command, but not a very
1041                              interesting one.  Return a NULL command. */
1042                           global_command = (COMMAND *)NULL;
1043                           YYACCEPT;
1044                         ;
1045     break;}
1046 case 3:
1047 #line 181 "./parse.y"
1048 {
1049                           /* Error during parsing.  Return NULL command. */
1050                           global_command = (COMMAND *)NULL;
1051                           eof_encountered = 0;
1052                           discard_parser_constructs (1);
1053                           if (interactive)
1054                             {
1055                               YYACCEPT;
1056                             }
1057                           else
1058                             {
1059                               YYABORT;
1060                             }
1061                         ;
1062     break;}
1063 case 4:
1064 #line 196 "./parse.y"
1065 {
1066                           /* Case of EOF seen by itself.  Do ignoreeof or 
1067                              not. */
1068                           global_command = (COMMAND *)NULL;
1069                           handle_eof_input_unit ();
1070                           YYACCEPT;
1071                         ;
1072     break;}
1073 case 5:
1074 #line 206 "./parse.y"
1075 { yyval.word_list = (WORD_LIST *)NULL; ;
1076     break;}
1077 case 6:
1078 #line 208 "./parse.y"
1079 { yyval.word_list = make_word_list (yyvsp[0].word, yyvsp[-1].word_list); ;
1080     break;}
1081 case 7:
1082 #line 212 "./parse.y"
1083 {
1084                           redir.filename = yyvsp[0].word;
1085                           yyval.redirect = make_redirection (1, r_output_direction, redir);
1086                         ;
1087     break;}
1088 case 8:
1089 #line 217 "./parse.y"
1090 {
1091                           redir.filename = yyvsp[0].word;
1092                           yyval.redirect = make_redirection (0, r_input_direction, redir);
1093                         ;
1094     break;}
1095 case 9:
1096 #line 222 "./parse.y"
1097 {
1098                           redir.filename = yyvsp[0].word;
1099                           yyval.redirect = make_redirection (yyvsp[-2].number, r_output_direction, redir);
1100                         ;
1101     break;}
1102 case 10:
1103 #line 227 "./parse.y"
1104 {
1105                           redir.filename = yyvsp[0].word;
1106                           yyval.redirect = make_redirection (yyvsp[-2].number, r_input_direction, redir);
1107                         ;
1108     break;}
1109 case 11:
1110 #line 232 "./parse.y"
1111 {
1112                           redir.filename = yyvsp[0].word;
1113                           yyval.redirect = make_redirection (1, r_appending_to, redir);
1114                         ;
1115     break;}
1116 case 12:
1117 #line 237 "./parse.y"
1118 {
1119                           redir.filename = yyvsp[0].word;
1120                           yyval.redirect = make_redirection (yyvsp[-2].number, r_appending_to, redir);
1121                         ;
1122     break;}
1123 case 13:
1124 #line 242 "./parse.y"
1125 {
1126                           redir.filename = yyvsp[0].word;
1127                           yyval.redirect = make_redirection (0, r_reading_until, redir);
1128                           redir_stack[need_here_doc++] = yyval.redirect;
1129                         ;
1130     break;}
1131 case 14:
1132 #line 248 "./parse.y"
1133 {
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;
1137                         ;
1138     break;}
1139 case 15:
1140 #line 254 "./parse.y"
1141 {
1142                           redir.dest = yyvsp[0].number;
1143                           yyval.redirect = make_redirection (0, r_duplicating_input, redir);
1144                         ;
1145     break;}
1146 case 16:
1147 #line 259 "./parse.y"
1148 {
1149                           redir.dest = yyvsp[0].number;
1150                           yyval.redirect = make_redirection (yyvsp[-2].number, r_duplicating_input, redir);
1151                         ;
1152     break;}
1153 case 17:
1154 #line 264 "./parse.y"
1155 {
1156                           redir.dest = yyvsp[0].number;
1157                           yyval.redirect = make_redirection (1, r_duplicating_output, redir);
1158                         ;
1159     break;}
1160 case 18:
1161 #line 269 "./parse.y"
1162 {
1163                           redir.dest = yyvsp[0].number;
1164                           yyval.redirect = make_redirection (yyvsp[-2].number, r_duplicating_output, redir);
1165                         ;
1166     break;}
1167 case 19:
1168 #line 274 "./parse.y"
1169 {
1170                           redir.filename = yyvsp[0].word;
1171                           yyval.redirect = make_redirection (0, r_duplicating_input_word, redir);
1172                         ;
1173     break;}
1174 case 20:
1175 #line 279 "./parse.y"
1176 {
1177                           redir.filename = yyvsp[0].word;
1178                           yyval.redirect = make_redirection (yyvsp[-2].number, r_duplicating_input_word, redir);
1179                         ;
1180     break;}
1181 case 21:
1182 #line 284 "./parse.y"
1183 {
1184                           redir.filename = yyvsp[0].word;
1185                           yyval.redirect = make_redirection (1, r_duplicating_output_word, redir);
1186                         ;
1187     break;}
1188 case 22:
1189 #line 289 "./parse.y"
1190 {
1191                           redir.filename = yyvsp[0].word;
1192                           yyval.redirect = make_redirection (yyvsp[-2].number, r_duplicating_output_word, redir);
1193                         ;
1194     break;}
1195 case 23:
1196 #line 294 "./parse.y"
1197 {
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;
1202                         ;
1203     break;}
1204 case 24:
1205 #line 301 "./parse.y"
1206 {
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;
1211                         ;
1212     break;}
1213 case 25:
1214 #line 308 "./parse.y"
1215 {
1216                           redir.dest = 0L;
1217                           yyval.redirect = make_redirection (1, r_close_this, redir);
1218                         ;
1219     break;}
1220 case 26:
1221 #line 313 "./parse.y"
1222 {
1223                           redir.dest = 0L;
1224                           yyval.redirect = make_redirection (yyvsp[-2].number, r_close_this, redir);
1225                         ;
1226     break;}
1227 case 27:
1228 #line 318 "./parse.y"
1229 {
1230                           redir.dest = 0L;
1231                           yyval.redirect = make_redirection (0, r_close_this, redir);
1232                         ;
1233     break;}
1234 case 28:
1235 #line 323 "./parse.y"
1236 {
1237                           redir.dest = 0L;
1238                           yyval.redirect = make_redirection (yyvsp[-2].number, r_close_this, redir);
1239                         ;
1240     break;}
1241 case 29:
1242 #line 328 "./parse.y"
1243 {
1244                           redir.filename = yyvsp[0].word;
1245                           yyval.redirect = make_redirection (1, r_err_and_out, redir);
1246                         ;
1247     break;}
1248 case 30:
1249 #line 333 "./parse.y"
1250 {
1251                           redir.filename = yyvsp[0].word;
1252                           yyval.redirect = make_redirection (yyvsp[-2].number, r_input_output, redir);
1253                         ;
1254     break;}
1255 case 31:
1256 #line 338 "./parse.y"
1257 {
1258                           REDIRECT *t1, *t2;
1259
1260                           redir.filename = yyvsp[0].word;
1261                           if (posixly_correct)
1262                             yyval.redirect = make_redirection (0, r_input_output, redir);
1263                           else
1264                             {
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);
1268                               t1->next = t2;
1269                               yyval.redirect = t1;
1270                             }
1271                         ;
1272     break;}
1273 case 32:
1274 #line 354 "./parse.y"
1275 {
1276                           redir.filename = yyvsp[0].word;
1277                           yyval.redirect = make_redirection (1, r_output_force, redir);
1278                         ;
1279     break;}
1280 case 33:
1281 #line 359 "./parse.y"
1282 {
1283                           redir.filename = yyvsp[0].word;
1284                           yyval.redirect = make_redirection (yyvsp[-2].number, r_output_force, redir);
1285                         ;
1286     break;}
1287 case 34:
1288 #line 366 "./parse.y"
1289 { yyval.element.word = yyvsp[0].word; yyval.element.redirect = 0; ;
1290     break;}
1291 case 35:
1292 #line 368 "./parse.y"
1293 { yyval.element.word = yyvsp[0].word; yyval.element.redirect = 0; ;
1294     break;}
1295 case 36:
1296 #line 370 "./parse.y"
1297 { yyval.element.redirect = yyvsp[0].redirect; yyval.element.word = 0; ;
1298     break;}
1299 case 37:
1300 #line 374 "./parse.y"
1301 {
1302                           yyval.redirect = yyvsp[0].redirect;
1303                         ;
1304     break;}
1305 case 38:
1306 #line 378 "./parse.y"
1307
1308                           register REDIRECT *t = yyvsp[-1].redirect;
1309
1310                           while (t->next)
1311                             t = t->next;
1312                           t->next = yyvsp[0].redirect; 
1313                           yyval.redirect = yyvsp[-1].redirect;
1314                         ;
1315     break;}
1316 case 39:
1317 #line 389 "./parse.y"
1318 { yyval.command = make_simple_command (yyvsp[0].element, (COMMAND *)NULL); ;
1319     break;}
1320 case 40:
1321 #line 391 "./parse.y"
1322 { yyval.command = make_simple_command (yyvsp[0].element, yyvsp[-1].command); ;
1323     break;}
1324 case 41:
1325 #line 395 "./parse.y"
1326 { yyval.command = clean_simple_command (yyvsp[0].command); ;
1327     break;}
1328 case 42:
1329 #line 397 "./parse.y"
1330 { yyval.command = yyvsp[0].command; ;
1331     break;}
1332 case 43:
1333 #line 401 "./parse.y"
1334 { yyval.command = yyvsp[0].command; ;
1335     break;}
1336 case 44:
1337 #line 403 "./parse.y"
1338 {
1339                           if (yyvsp[-1].command->redirects)
1340                             {
1341                               register REDIRECT *t;
1342                               for (t = yyvsp[-1].command->redirects; t->next; t = t->next)
1343                                 ;
1344                               t->next = yyvsp[0].redirect;
1345                             }
1346                           else
1347                             yyvsp[-1].command->redirects = yyvsp[0].redirect;
1348                           yyval.command = yyvsp[-1].command;
1349                         ;
1350     break;}
1351 case 45:
1352 #line 418 "./parse.y"
1353 { yyval.command = make_for_command (yyvsp[-4].word, add_string_to_list ("\"$@\"", (WORD_LIST *)NULL), yyvsp[-1].command); ;
1354     break;}
1355 case 46:
1356 #line 420 "./parse.y"
1357 { yyval.command = make_for_command (yyvsp[-4].word, add_string_to_list ("$@", (WORD_LIST *)NULL), yyvsp[-1].command); ;
1358     break;}
1359 case 47:
1360 #line 422 "./parse.y"
1361 { yyval.command = make_for_command (yyvsp[-5].word, add_string_to_list ("\"$@\"", (WORD_LIST *)NULL), yyvsp[-1].command); ;
1362     break;}
1363 case 48:
1364 #line 424 "./parse.y"
1365 { yyval.command = make_for_command (yyvsp[-5].word, add_string_to_list ("\"$@\"", (WORD_LIST *)NULL), yyvsp[-1].command); ;
1366     break;}
1367 case 49:
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); ;
1370     break;}
1371 case 50:
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); ;
1374     break;}
1375 case 51:
1376 #line 431 "./parse.y"
1377 { yyval.command = make_case_command (yyvsp[-4].word, (PATTERN_LIST *)NULL); ;
1378     break;}
1379 case 52:
1380 #line 433 "./parse.y"
1381 { yyval.command = make_case_command (yyvsp[-5].word, yyvsp[-2].pattern); ;
1382     break;}
1383 case 53:
1384 #line 435 "./parse.y"
1385 { yyval.command = make_case_command (yyvsp[-4].word, yyvsp[-1].pattern); ;
1386     break;}
1387 case 54:
1388 #line 437 "./parse.y"
1389 { yyval.command = make_while_command (yyvsp[-3].command, yyvsp[-1].command); ;
1390     break;}
1391 case 55:
1392 #line 439 "./parse.y"
1393 { yyval.command = make_until_command (yyvsp[-3].command, yyvsp[-1].command); ;
1394     break;}
1395 case 56:
1396 #line 441 "./parse.y"
1397 { yyval.command = yyvsp[0].command; ;
1398     break;}
1399 case 57:
1400 #line 443 "./parse.y"
1401 { yyval.command = yyvsp[0].command; ;
1402     break;}
1403 case 58:
1404 #line 445 "./parse.y"
1405 { yyval.command = yyvsp[0].command; ;
1406     break;}
1407 case 59:
1408 #line 447 "./parse.y"
1409 { yyval.command = yyvsp[0].command; ;
1410     break;}
1411 case 60:
1412 #line 449 "./parse.y"
1413 { yyval.command = yyvsp[0].command; ;
1414     break;}
1415 case 61:
1416 #line 453 "./parse.y"
1417 {
1418 #if defined (SELECT_COMMAND)
1419                           yyval.command = make_select_command (yyvsp[-4].word, add_string_to_list ("\"$@\"", (WORD_LIST *)NULL), yyvsp[-1].command);
1420 #endif
1421                         ;
1422     break;}
1423 case 62:
1424 #line 459 "./parse.y"
1425 {
1426 #if defined (SELECT_COMMAND)
1427                           yyval.command = make_select_command (yyvsp[-4].word, add_string_to_list ("$@", (WORD_LIST *)NULL), yyvsp[-1].command);
1428 #endif
1429                         ;
1430     break;}
1431 case 63:
1432 #line 465 "./parse.y"
1433 {
1434 #if defined (SELECT_COMMAND)
1435                           yyval.command = make_select_command (yyvsp[-5].word, add_string_to_list ("\"$@\"", (WORD_LIST *)NULL), yyvsp[-1].command);
1436 #endif
1437                         ;
1438     break;}
1439 case 64:
1440 #line 471 "./parse.y"
1441 {
1442 #if defined (SELECT_COMMAND)
1443                           yyval.command = make_select_command (yyvsp[-5].word, add_string_to_list ("\"$@\"", (WORD_LIST *)NULL), yyvsp[-1].command);
1444 #endif
1445                         ;
1446     break;}
1447 case 65:
1448 #line 477 "./parse.y"
1449 {
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);
1452 #endif
1453                         ;
1454     break;}
1455 case 66:
1456 #line 483 "./parse.y"
1457 {
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);
1460 #endif
1461                         ;
1462     break;}
1463 case 67:
1464 #line 491 "./parse.y"
1465 { yyval.command = make_function_def (yyvsp[-4].word, yyvsp[0].command); ;
1466     break;}
1467 case 68:
1468 #line 494 "./parse.y"
1469 { yyvsp[-1].command->redirects = yyvsp[0].redirect; yyval.command = make_function_def (yyvsp[-5].word, yyvsp[-1].command); ;
1470     break;}
1471 case 69:
1472 #line 497 "./parse.y"
1473 { yyval.command = make_function_def (yyvsp[-4].word, yyvsp[0].command); ;
1474     break;}
1475 case 70:
1476 #line 500 "./parse.y"
1477 { yyvsp[-1].command->redirects = yyvsp[0].redirect; yyval.command = make_function_def (yyvsp[-5].word, yyvsp[-1].command); ;
1478     break;}
1479 case 71:
1480 #line 503 "./parse.y"
1481 { yyval.command = make_function_def (yyvsp[-2].word, yyvsp[0].command); ;
1482     break;}
1483 case 72:
1484 #line 506 "./parse.y"
1485 { yyvsp[-1].command->redirects = yyvsp[0].redirect; yyval.command = make_function_def (yyvsp[-3].word, yyvsp[-1].command); ;
1486     break;}
1487 case 73:
1488 #line 510 "./parse.y"
1489 { yyvsp[-1].command->flags |= CMD_WANT_SUBSHELL; yyval.command = yyvsp[-1].command; ;
1490     break;}
1491 case 74:
1492 #line 514 "./parse.y"
1493 { yyval.command = make_if_command (yyvsp[-3].command, yyvsp[-1].command, (COMMAND *)NULL); ;
1494     break;}
1495 case 75:
1496 #line 516 "./parse.y"
1497 { yyval.command = make_if_command (yyvsp[-5].command, yyvsp[-3].command, yyvsp[-1].command); ;
1498     break;}
1499 case 76:
1500 #line 518 "./parse.y"
1501 { yyval.command = make_if_command (yyvsp[-4].command, yyvsp[-2].command, yyvsp[-1].command); ;
1502     break;}
1503 case 77:
1504 #line 523 "./parse.y"
1505 { yyval.command = make_group_command (yyvsp[-1].command); ;
1506     break;}
1507 case 78:
1508 #line 527 "./parse.y"
1509 { yyval.command = make_if_command (yyvsp[-2].command, yyvsp[0].command, (COMMAND *)NULL); ;
1510     break;}
1511 case 79:
1512 #line 529 "./parse.y"
1513 { yyval.command = make_if_command (yyvsp[-4].command, yyvsp[-2].command, yyvsp[0].command); ;
1514     break;}
1515 case 80:
1516 #line 531 "./parse.y"
1517 { yyval.command = make_if_command (yyvsp[-3].command, yyvsp[-1].command, yyvsp[0].command); ;
1518     break;}
1519 case 82:
1520 #line 536 "./parse.y"
1521 { yyvsp[0].pattern->next = yyvsp[-1].pattern; yyval.pattern = yyvsp[0].pattern; ;
1522     break;}
1523 case 83:
1524 #line 540 "./parse.y"
1525 { yyval.pattern = make_pattern_list (yyvsp[-2].word_list, yyvsp[0].command); ;
1526     break;}
1527 case 84:
1528 #line 542 "./parse.y"
1529 { yyval.pattern = make_pattern_list (yyvsp[-2].word_list, (COMMAND *)NULL); ;
1530     break;}
1531 case 85:
1532 #line 544 "./parse.y"
1533 { yyval.pattern = make_pattern_list (yyvsp[-2].word_list, yyvsp[0].command); ;
1534     break;}
1535 case 86:
1536 #line 546 "./parse.y"
1537 { yyval.pattern = make_pattern_list (yyvsp[-2].word_list, (COMMAND *)NULL); ;
1538     break;}
1539 case 88:
1540 #line 551 "./parse.y"
1541 { yyvsp[0].pattern->next = yyvsp[-1].pattern; yyval.pattern = yyvsp[0].pattern; ;
1542     break;}
1543 case 89:
1544 #line 555 "./parse.y"
1545 { yyval.pattern = make_pattern_list (yyvsp[-3].word_list, yyvsp[-1].command); ;
1546     break;}
1547 case 90:
1548 #line 557 "./parse.y"
1549 { yyval.pattern = make_pattern_list (yyvsp[-3].word_list, (COMMAND *)NULL); ;
1550     break;}
1551 case 91:
1552 #line 559 "./parse.y"
1553 { yyval.pattern = make_pattern_list (yyvsp[-3].word_list, yyvsp[-1].command); ;
1554     break;}
1555 case 92:
1556 #line 561 "./parse.y"
1557 { yyval.pattern = make_pattern_list (yyvsp[-3].word_list, (COMMAND *)NULL); ;
1558     break;}
1559 case 93:
1560 #line 565 "./parse.y"
1561 { yyval.word_list = make_word_list (yyvsp[0].word, (WORD_LIST *)NULL); ;
1562     break;}
1563 case 94:
1564 #line 567 "./parse.y"
1565 { yyval.word_list = make_word_list (yyvsp[0].word, yyvsp[-2].word_list); ;
1566     break;}
1567 case 95:
1568 #line 576 "./parse.y"
1569 {
1570                           yyval.command = yyvsp[0].command;
1571                           if (need_here_doc)
1572                             gather_here_documents ();
1573                          ;
1574     break;}
1575 case 98:
1576 #line 586 "./parse.y"
1577 {
1578                           if (yyvsp[-2].command->type == cm_connection)
1579                             yyval.command = connect_async_list (yyvsp[-2].command, (COMMAND *)NULL, '&');
1580                           else
1581                             yyval.command = command_connect (yyvsp[-2].command, (COMMAND *)NULL, '&');
1582                         ;
1583     break;}
1584 case 100:
1585 #line 597 "./parse.y"
1586 { yyval.command = command_connect (yyvsp[-3].command, yyvsp[0].command, AND_AND); ;
1587     break;}
1588 case 101:
1589 #line 599 "./parse.y"
1590 { yyval.command = command_connect (yyvsp[-3].command, yyvsp[0].command, OR_OR); ;
1591     break;}
1592 case 102:
1593 #line 601 "./parse.y"
1594 {
1595                           if (yyvsp[-3].command->type == cm_connection)
1596                             yyval.command = connect_async_list (yyvsp[-3].command, yyvsp[0].command, '&');
1597                           else
1598                             yyval.command = command_connect (yyvsp[-3].command, yyvsp[0].command, '&');
1599                         ;
1600     break;}
1601 case 103:
1602 #line 608 "./parse.y"
1603 { yyval.command = command_connect (yyvsp[-3].command, yyvsp[0].command, ';'); ;
1604     break;}
1605 case 104:
1606 #line 610 "./parse.y"
1607 { yyval.command = command_connect (yyvsp[-3].command, yyvsp[0].command, ';'); ;
1608     break;}
1609 case 105:
1610 #line 612 "./parse.y"
1611 { yyval.command = yyvsp[0].command; ;
1612     break;}
1613 case 106:
1614 #line 614 "./parse.y"
1615 {
1616                           yyvsp[0].command->flags |= CMD_INVERT_RETURN;
1617                           yyval.command = yyvsp[0].command;
1618                         ;
1619     break;}
1620 case 112:
1621 #line 636 "./parse.y"
1622 {
1623                           yyval.command = yyvsp[0].command;
1624                           if (need_here_doc)
1625                             gather_here_documents ();
1626                         ;
1627     break;}
1628 case 113:
1629 #line 642 "./parse.y"
1630 {
1631                           if (yyvsp[-1].command->type == cm_connection)
1632                             yyval.command = connect_async_list (yyvsp[-1].command, (COMMAND *)NULL, '&');
1633                           else
1634                             yyval.command = command_connect (yyvsp[-1].command, (COMMAND *)NULL, '&');
1635                           if (need_here_doc)
1636                             gather_here_documents ();
1637                         ;
1638     break;}
1639 case 114:
1640 #line 651 "./parse.y"
1641 {
1642                           yyval.command = yyvsp[-1].command;
1643                           if (need_here_doc)
1644                             gather_here_documents ();
1645                         ;
1646     break;}
1647 case 115:
1648 #line 659 "./parse.y"
1649 { yyval.command = command_connect (yyvsp[-3].command, yyvsp[0].command, AND_AND); ;
1650     break;}
1651 case 116:
1652 #line 661 "./parse.y"
1653 { yyval.command = command_connect (yyvsp[-3].command, yyvsp[0].command, OR_OR); ;
1654     break;}
1655 case 117:
1656 #line 663 "./parse.y"
1657 {
1658                           if (yyvsp[-2].command->type == cm_connection)
1659                             yyval.command = connect_async_list (yyvsp[-2].command, yyvsp[0].command, '&');
1660                           else
1661                             yyval.command = command_connect (yyvsp[-2].command, yyvsp[0].command, '&');
1662                         ;
1663     break;}
1664 case 118:
1665 #line 670 "./parse.y"
1666 { yyval.command = command_connect (yyvsp[-2].command, yyvsp[0].command, ';'); ;
1667     break;}
1668 case 119:
1669 #line 672 "./parse.y"
1670 { yyval.command = yyvsp[0].command; ;
1671     break;}
1672 case 120:
1673 #line 674 "./parse.y"
1674 {
1675                           yyvsp[0].command->flags |= CMD_INVERT_RETURN;
1676                           yyval.command = yyvsp[0].command;
1677                         ;
1678     break;}
1679 case 121:
1680 #line 682 "./parse.y"
1681 { yyval.command = command_connect (yyvsp[-3].command, yyvsp[0].command, '|'); ;
1682     break;}
1683 case 122:
1684 #line 684 "./parse.y"
1685 { yyval.command = yyvsp[0].command; ;
1686     break;}
1687 }
1688    /* the action file gets copied in in place of this dollarsign */
1689 #line 498 "/usr/local/lib/bison.simple"
1690 \f
1691   yyvsp -= yylen;
1692   yyssp -= yylen;
1693 #ifdef YYLSP_NEEDED
1694   yylsp -= yylen;
1695 #endif
1696
1697 #if YYDEBUG != 0
1698   if (yydebug)
1699     {
1700       short *ssp1 = yyss - 1;
1701       fprintf (stderr, "state stack now");
1702       while (ssp1 != yyssp)
1703         fprintf (stderr, " %d", *++ssp1);
1704       fprintf (stderr, "\n");
1705     }
1706 #endif
1707
1708   *++yyvsp = yyval;
1709
1710 #ifdef YYLSP_NEEDED
1711   yylsp++;
1712   if (yylen == 0)
1713     {
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;
1718       yylsp->text = 0;
1719     }
1720   else
1721     {
1722       yylsp->last_line = (yylsp+yylen-1)->last_line;
1723       yylsp->last_column = (yylsp+yylen-1)->last_column;
1724     }
1725 #endif
1726
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.  */
1731
1732   yyn = yyr1[yyn];
1733
1734   yystate = yypgoto[yyn - YYNTBASE] + *yyssp;
1735   if (yystate >= 0 && yystate <= YYLAST && yycheck[yystate] == *yyssp)
1736     yystate = yytable[yystate];
1737   else
1738     yystate = yydefgoto[yyn - YYNTBASE];
1739
1740   goto yynewstate;
1741
1742 yyerrlab:   /* here on detecting error */
1743
1744   if (! yyerrstatus)
1745     /* If not already recovering from an error, report this error.  */
1746     {
1747       ++yynerrs;
1748
1749 #ifdef YYERROR_VERBOSE
1750       yyn = yypact[yystate];
1751
1752       if (yyn > YYFLAG && yyn < YYLAST)
1753         {
1754           int size = 0;
1755           char *msg;
1756           int x, count;
1757
1758           count = 0;
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);
1765           if (msg != 0)
1766             {
1767               strcpy(msg, "parse error");
1768
1769               if (count < 5)
1770                 {
1771                   count = 0;
1772                   for (x = (yyn < 0 ? -yyn : 0);
1773                        x < (sizeof(yytname) / sizeof(char *)); x++)
1774                     if (yycheck[x + yyn] == x)
1775                       {
1776                         strcat(msg, count == 0 ? ", expecting `" : " or `");
1777                         strcat(msg, yytname[x]);
1778                         strcat(msg, "'");
1779                         count++;
1780                       }
1781                 }
1782               yyerror(msg);
1783               free(msg);
1784             }
1785           else
1786             yyerror ("parse error; also virtual memory exceeded");
1787         }
1788       else
1789 #endif /* YYERROR_VERBOSE */
1790         yyerror("parse error");
1791     }
1792
1793   goto yyerrlab1;
1794 yyerrlab1:   /* here on error raised explicitly by an action */
1795
1796   if (yyerrstatus == 3)
1797     {
1798       /* if just tried and failed to reuse lookahead token after an error, discard it.  */
1799
1800       /* return failure if at end of input */
1801       if (yychar == YYEOF)
1802         YYABORT;
1803
1804 #if YYDEBUG != 0
1805       if (yydebug)
1806         fprintf(stderr, "Discarding token %d (%s).\n", yychar, yytname[yychar1]);
1807 #endif
1808
1809       yychar = YYEMPTY;
1810     }
1811
1812   /* Else will try to reuse lookahead token
1813      after shifting the error token.  */
1814
1815   yyerrstatus = 3;              /* Each real token shifted decrements this */
1816
1817   goto yyerrhandle;
1818
1819 yyerrdefault:  /* current state does not do anything special for the error token. */
1820
1821 #if 0
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;
1826 #endif
1827
1828 yyerrpop:   /* pop the current state because it cannot handle the error token */
1829
1830   if (yyssp == yyss) YYABORT;
1831   yyvsp--;
1832   yystate = *--yyssp;
1833 #ifdef YYLSP_NEEDED
1834   yylsp--;
1835 #endif
1836
1837 #if YYDEBUG != 0
1838   if (yydebug)
1839     {
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");
1845     }
1846 #endif
1847
1848 yyerrhandle:
1849
1850   yyn = yypact[yystate];
1851   if (yyn == YYFLAG)
1852     goto yyerrdefault;
1853
1854   yyn += YYTERROR;
1855   if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != YYTERROR)
1856     goto yyerrdefault;
1857
1858   yyn = yytable[yyn];
1859   if (yyn < 0)
1860     {
1861       if (yyn == YYFLAG)
1862         goto yyerrpop;
1863       yyn = -yyn;
1864       goto yyreduce;
1865     }
1866   else if (yyn == 0)
1867     goto yyerrpop;
1868
1869   if (yyn == YYFINAL)
1870     YYACCEPT;
1871
1872 #if YYDEBUG != 0
1873   if (yydebug)
1874     fprintf(stderr, "Shifting error token, ");
1875 #endif
1876
1877   *++yyvsp = yylval;
1878 #ifdef YYLSP_NEEDED
1879   *++yylsp = yylloc;
1880 #endif
1881
1882   yystate = yyn;
1883   goto yynewstate;
1884 }
1885 #line 686 "./parse.y"
1886
1887
1888 /* Initial size to allocate for tokens, and the
1889    amount to grow them by. */
1890 #define TOKEN_DEFAULT_GROW_SIZE 512
1891
1892 /* The token currently being read. */
1893 static int current_token = 0;
1894
1895 /* The last read token, or NULL.  read_token () uses this for context
1896    checking. */
1897 static int last_read_token = 0;
1898
1899 /* The token read prior to last_read_token. */
1900 static int token_before_that = 0;
1901
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;
1906
1907 /* Global var is non-zero when end of file has been reached. */
1908 int EOF_Reached = 0;
1909
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. */
1917
1918 /* Unconditionally returns end-of-file. */
1919 return_EOF ()
1920 {
1921   return (EOF);
1922 }
1923
1924 /* Variable containing the current get and unget functions.
1925    See ./input.h for a clearer description. */
1926 BASH_INPUT bash_input;
1927
1928 /* Set all of the fields in BASH_INPUT to NULL. */
1929 void
1930 initialize_bash_input ()
1931 {
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;
1938 }
1939
1940 /* Set the contents of the current bash input stream from
1941    GET, UNGET, TYPE, NAME, and LOCATION. */
1942 void
1943 init_yy_io (get, unget, type, name, location)
1944      Function *get, *unget;
1945      int type;
1946      char *name;
1947      INPUT_STREAM location;
1948 {
1949   bash_input.type = type;
1950   FREE (bash_input.name);
1951
1952   if (name)
1953     bash_input.name = savestring (name);
1954   else
1955     bash_input.name = (char *)NULL;
1956
1957 #if defined (CRAY)
1958   memcpy((char *)&bash_input.location.string, (char *)&location.string, sizeof(location));
1959 #else
1960   bash_input.location = location;
1961 #endif
1962   bash_input.getter = get;
1963   bash_input.ungetter = unget;
1964 }
1965
1966 /* Call this to get the next character of input. */
1967 yy_getc ()
1968 {
1969   return (*(bash_input.getter)) ();
1970 }
1971
1972 /* Call this to unget C.  That is, to make C the next character
1973    to be read. */
1974 yy_ungetc (c)
1975      int c;
1976 {
1977   return (*(bash_input.ungetter)) (c);
1978 }
1979
1980 #if defined (BUFFERED_INPUT)
1981 int
1982 input_file_descriptor ()
1983 {
1984   switch (bash_input.type)
1985     {
1986     case st_stream:
1987       return (fileno (bash_input.location.file));
1988     case st_bstream:
1989       return (bash_input.location.buffered_fd);
1990     default:
1991       return (fileno (stdin));
1992     }
1993 }
1994 #endif /* BUFFERED_INPUT */
1995
1996 /* **************************************************************** */
1997 /*                                                                  */
1998 /*                Let input be read from readline ().               */
1999 /*                                                                  */
2000 /* **************************************************************** */
2001
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;
2006
2007 static int
2008 yy_readline_get ()
2009 {
2010   if (!current_readline_line)
2011     {
2012       SigHandler *old_sigint;
2013       int line_len;
2014
2015       if (!bash_readline_initialized)
2016         initialize_readline ();
2017
2018 #if defined (JOB_CONTROL)
2019       if (job_control)
2020         give_terminal_to (shell_pgrp);
2021 #endif /* JOB_CONTROL */
2022
2023       if (signal_is_ignored (SIGINT) == 0)
2024         {
2025           old_sigint = (SigHandler *)set_signal_handler (SIGINT, sigint_sighandler);
2026           interrupt_immediately++;
2027         }
2028
2029       if (!current_readline_prompt)
2030         current_readline_line = readline ("");
2031       else
2032         current_readline_line = readline (current_readline_prompt);
2033
2034       if (signal_is_ignored (SIGINT) == 0)
2035         {
2036           interrupt_immediately--;
2037           set_signal_handler (SIGINT, old_sigint);
2038         }
2039
2040       /* Reset the prompt to whatever is in the decoded value of
2041          prompt_string_pointer. */
2042       reset_readline_prompt ();
2043
2044       current_readline_line_index = 0;
2045
2046       if (!current_readline_line)
2047         return (EOF);
2048
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';
2053     }
2054
2055   if (!current_readline_line[current_readline_line_index])
2056     {
2057       free (current_readline_line);
2058       current_readline_line = (char *)NULL;
2059       return (yy_readline_get ());
2060     }
2061   else
2062     {
2063       int c = (unsigned char)current_readline_line[current_readline_line_index++];
2064       return (c);
2065     }
2066 }
2067
2068 static int
2069 yy_readline_unget (c)
2070 {
2071   if (current_readline_line_index && current_readline_line)
2072     current_readline_line[--current_readline_line_index] = c;
2073   return (c);
2074 }
2075
2076 void  
2077 with_input_from_stdin ()
2078 {
2079   INPUT_STREAM location;
2080
2081   if (bash_input.type != st_stdin && stream_on_stack (st_stdin) == 0)
2082     {
2083       location.string = current_readline_line;
2084       init_yy_io (yy_readline_get, yy_readline_unget,
2085                   st_stdin, "readline stdin", location);
2086     }
2087 }
2088
2089 #else  /* !READLINE */
2090
2091 void
2092 with_input_from_stdin ()
2093 {
2094   with_input_from_stream (stdin, "stdin");
2095 }
2096 #endif  /* !READLINE */
2097
2098 /* **************************************************************** */
2099 /*                                                                  */
2100 /*   Let input come from STRING.  STRING is zero terminated.        */
2101 /*                                                                  */
2102 /* **************************************************************** */
2103
2104 static int
2105 yy_string_get ()
2106 {
2107   register unsigned char *string;
2108   register int c;
2109
2110   string = bash_input.location.string;
2111   c = EOF;
2112
2113   /* If the string doesn't exist, or is empty, EOF found. */
2114   if (string && *string)
2115     {
2116       c = *string++;
2117       bash_input.location.string = string;
2118     }
2119   return (c);
2120 }
2121
2122 static int
2123 yy_string_unget (c)
2124      int c;
2125 {
2126   *(--bash_input.location.string) = c;
2127   return (c);
2128 }
2129
2130 void
2131 with_input_from_string (string, name)
2132      char *string;
2133      char *name;
2134 {
2135   INPUT_STREAM location;
2136
2137   location.string = string;
2138
2139   init_yy_io (yy_string_get, yy_string_unget, st_string, name, location);
2140 }
2141
2142 /* **************************************************************** */
2143 /*                                                                  */
2144 /*                   Let input come from STREAM.                    */
2145 /*                                                                  */
2146 /* **************************************************************** */
2147
2148 static int
2149 yy_stream_get ()
2150 {
2151   int result = EOF;
2152
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);
2156 #else
2157     result = (unsigned char)getc (bash_input.location.file);
2158 #endif /* !NO_READ_RESTART_ON_SIGNAL */
2159   return (result);
2160 }
2161
2162 static int
2163 yy_stream_unget (c)
2164      int c;
2165 {
2166 #if defined (NO_READ_RESTART_ON_SIGNAL)
2167   return (ungetc_with_restart (c, bash_input.location.file));
2168 #else
2169   return (ungetc (c, bash_input.location.file));
2170 #endif
2171 }
2172
2173 void
2174 with_input_from_stream (stream, name)
2175      FILE *stream;
2176      char *name;
2177 {
2178   INPUT_STREAM location;
2179
2180   location.file = stream;
2181   init_yy_io (yy_stream_get, yy_stream_unget, st_stream, name, location);
2182 }
2183
2184 typedef struct stream_saver {
2185   struct stream_saver *next;
2186   BASH_INPUT bash_input;
2187   int line;
2188 #if defined (BUFFERED_INPUT)
2189   BUFFERED_STREAM *bstream;
2190 #endif /* BUFFERED_INPUT */
2191 } STREAM_SAVER;
2192
2193 /* The globally known line number. */
2194 int line_number = 0;
2195
2196 STREAM_SAVER *stream_list = (STREAM_SAVER *)NULL;
2197
2198 push_stream ()
2199 {
2200   STREAM_SAVER *saver = (STREAM_SAVER *)xmalloc (sizeof (STREAM_SAVER));
2201
2202   xbcopy ((char *)&bash_input, (char *)&(saver->bash_input), sizeof (BASH_INPUT));
2203
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)
2208     {
2209       saver->bstream = buffers[bash_input.location.buffered_fd];
2210       buffers[bash_input.location.buffered_fd] = (BUFFERED_STREAM *)NULL;
2211     }
2212 #endif /* BUFFERED_INPUT */
2213
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;
2219 }
2220
2221 pop_stream ()
2222 {
2223   int temp;
2224
2225   if (!stream_list)
2226     EOF_Reached = 1;
2227   else
2228     {
2229       STREAM_SAVER *saver = stream_list;
2230
2231       EOF_Reached = 0;
2232       stream_list = stream_list->next;
2233
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);
2239
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)
2246         {
2247           if (bash_input_fd_changed)
2248             {
2249               bash_input_fd_changed = 0;
2250               if (default_buffered_input >= 0)
2251                 {
2252                   bash_input.location.buffered_fd = default_buffered_input;
2253                   saver->bstream->b_fd = default_buffered_input;
2254                 }
2255             }
2256           buffers[bash_input.location.buffered_fd] = saver->bstream;
2257         }
2258 #endif /* BUFFERED_INPUT */
2259
2260       line_number = saver->line;
2261
2262       FREE (saver->bash_input.name);
2263       free (saver);
2264     }
2265 }
2266
2267 /* Return 1 if a stream of type TYPE is saved on the stack. */
2268 int
2269 stream_on_stack (type)
2270      int type;
2271 {
2272   register STREAM_SAVER *s;
2273  
2274   for (s = stream_list; s; s = s->next)
2275     if (s->bash_input.type == type)
2276       return 1;
2277   return 0;
2278 }
2279
2280 \f
2281 /*
2282  * This is used to inhibit alias expansion and reserved word recognition
2283  * inside case statement pattern lists.  A `case statement pattern list'
2284  * is:
2285  *      everything between the `in' in a `case word in' and the next ')'
2286  *      or `esac'
2287  *      everything between a `;;' and the next `)' or `esac'
2288  */
2289 static int in_case_pattern_list = 0;
2290
2291 #if defined (ALIAS)
2292 /*
2293  * Pseudo-global variables used in implementing token-wise alias expansion.
2294  */
2295
2296 static int expand_next_token = 0;
2297
2298 /*
2299  * Pushing and popping strings.  This works together with shell_getc to 
2300  * implement alias expansion on a per-token basis.
2301  */
2302
2303 typedef struct string_saver {
2304   struct string_saver *next;
2305   int expand_alias;  /* Value to set expand_alias to when string is popped. */
2306   char *saved_line;
2307   int saved_line_size, saved_line_index, saved_line_terminator;
2308 } STRING_SAVER;
2309
2310 STRING_SAVER *pushed_string_list = (STRING_SAVER *)NULL;
2311
2312 static void save_expansion ();
2313
2314 /*
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.
2321  */
2322 static void
2323 push_string (s, expand, token)
2324      char *s;
2325      int expand;
2326      char *token;
2327 {
2328   STRING_SAVER *temp = (STRING_SAVER *) xmalloc (sizeof (STRING_SAVER));
2329
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;
2337
2338   save_expansion (token);
2339
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;
2345 }
2346
2347 /*
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.
2352  */
2353 static void
2354 pop_string ()
2355 {
2356   STRING_SAVER *t;
2357
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;
2364
2365   t = pushed_string_list;
2366   pushed_string_list = pushed_string_list->next;
2367   free((char *)t);
2368 }
2369
2370 static void
2371 free_string_list ()
2372 {
2373   register STRING_SAVER *t = pushed_string_list, *t1;
2374
2375   while (t)
2376     {
2377       t1 = t->next;
2378       FREE (t->saved_line);
2379       free ((char *)t);
2380       t = t1;
2381     }
2382   pushed_string_list = (STRING_SAVER *)NULL;
2383 }
2384
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:
2388
2389       alias foo=bar
2390       alias bar=baz
2391       alias baz=foo
2392
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.)
2399
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). */
2403
2404 typedef struct _exp_saver {
2405       struct _exp_saver *next;
2406       char *saved_token;
2407 } EXPANSION_SAVER;
2408
2409 EXPANSION_SAVER *expanded_token_stack = (EXPANSION_SAVER *)NULL;
2410
2411 static void
2412 save_expansion (s)
2413      char *s;
2414 {
2415   EXPANSION_SAVER *t;
2416
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;
2421 }
2422
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. */
2427 static int
2428 token_has_been_expanded (token)
2429      char *token;
2430 {
2431   register EXPANSION_SAVER *t = expanded_token_stack;
2432
2433   while (t)
2434     {
2435       if (STREQ (token, t->saved_token))
2436         return (1);
2437       t = t->next;
2438     }
2439   return (0);
2440 }
2441
2442 static void
2443 free_expansion_stack ()
2444 {
2445   register EXPANSION_SAVER *t = expanded_token_stack, *t1;
2446
2447   while (t)
2448     {
2449       t1 = t->next;
2450       free (t->saved_token);
2451       free (t);
2452       t = t1;
2453     }
2454   expanded_token_stack = (EXPANSION_SAVER *)NULL;
2455 }
2456
2457 #endif /* ALIAS */
2458 \f
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. */
2463 static char *
2464 read_a_line (remove_quoted_newline)
2465      int remove_quoted_newline;
2466 {
2467   static char *line_buffer = (char *)NULL;
2468   static int buffer_size = 0;
2469   int indx = 0, c, peekc, pass_next;
2470
2471   pass_next = 0;
2472   while (1)
2473     {
2474       c = yy_getc ();
2475
2476       /* Allow immediate exit if interrupted during input. */
2477       QUIT;
2478
2479       if (c == 0)
2480         continue;
2481
2482       /* If there is no more input, then we return NULL. */
2483       if (c == EOF)
2484         {
2485           if (indx == 0)
2486             return ((char *)NULL);
2487           c = '\n';
2488         }
2489
2490       /* `+2' in case the final character in the buffer is a newline. */
2491       if (indx + 2 > buffer_size)
2492         if (!buffer_size)
2493           line_buffer = xmalloc (buffer_size = 128);
2494         else
2495           line_buffer = xrealloc (line_buffer, buffer_size += 128);
2496
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. */
2503       if (pass_next)
2504         {
2505           line_buffer[indx++] = c;
2506           pass_next = 0;
2507         }
2508       else if (c == '\\' && remove_quoted_newline)
2509         {
2510           peekc = yy_getc ();
2511           if (peekc == '\n')
2512             continue;   /* Make the unquoted \<newline> pair disappear. */
2513           else
2514             {
2515               yy_ungetc (peekc);
2516               pass_next = 1;
2517               line_buffer[indx++] = c;          /* Preserve the backslash. */
2518             }
2519         }
2520       else
2521         line_buffer[indx++] = c;
2522
2523       if (c == '\n')
2524         {
2525           line_buffer[indx] = '\0';
2526           return (line_buffer);
2527         }
2528     }
2529 }
2530
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. */
2536 char *
2537 read_secondary_line (remove_quoted_newline)
2538      int remove_quoted_newline;
2539 {
2540   prompt_string_pointer = &ps2_prompt;
2541   prompt_again ();
2542   return (read_a_line (remove_quoted_newline));
2543 }
2544
2545 \f
2546 /* **************************************************************** */
2547 /*                                                                  */
2548 /*                              YYLEX ()                            */
2549 /*                                                                  */
2550 /* **************************************************************** */
2551
2552 /* Reserved words.  These are only recognized as the first word of a
2553    command. */
2554 STRING_INT_ALIST word_token_alist[] = {
2555   { "if", IF },
2556   { "then", THEN },
2557   { "else", ELSE },
2558   { "elif", ELIF },
2559   { "fi", FI },
2560   { "case", CASE },
2561   { "esac", ESAC },
2562   { "for", FOR },
2563 #if defined (SELECT_COMMAND)
2564   { "select", SELECT },
2565 #endif
2566   { "while", WHILE },
2567   { "until", UNTIL },
2568   { "do", DO },
2569   { "done", DONE },
2570   { "in", IN },
2571   { "function", FUNCTION },
2572   { "{", '{' },
2573   { "}", '}' },
2574   { "!", BANG },
2575   { (char *)NULL, 0}
2576 };
2577
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. */
2582 static int
2583 shell_getc (remove_quoted_newline)
2584      int remove_quoted_newline;
2585 {
2586   int c;
2587
2588   QUIT;
2589
2590 #if defined (ALIAS)
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. */
2594
2595   if (!shell_input_line || ((!shell_input_line[shell_input_line_index]) &&
2596                             (pushed_string_list == (STRING_SAVER *)NULL)))
2597 #else /* !ALIAS */
2598   if (!shell_input_line || !shell_input_line[shell_input_line_index])
2599 #endif /* !ALIAS */
2600     {
2601       register int i, l;
2602
2603       restart_read_next_line:
2604
2605       line_number++;
2606
2607     restart_read:
2608
2609       /* Allow immediate exit if interrupted during input. */
2610       QUIT;
2611
2612       i = 0;
2613       shell_input_line_terminator = 0;
2614
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 */
2624
2625 #if defined (READLINE)
2626       if (interactive && bash_input.type != st_string && no_line_editing)
2627 #else
2628       if (interactive && bash_input.type != st_string)
2629 #endif
2630         print_prompt ();
2631
2632       if (bash_input.type == st_stream)
2633         clearerr (stdin);
2634
2635       while (c = yy_getc ())
2636         {
2637           /* Allow immediate exit if interrupted during input. */
2638           QUIT;
2639
2640           if (i + 2 > shell_input_line_size)
2641             shell_input_line =
2642               xrealloc (shell_input_line, shell_input_line_size += 256);
2643
2644           if (c == EOF)
2645             {
2646               if (bash_input.type == st_stream)
2647                 clearerr (stdin);
2648
2649               if (!i)
2650                 shell_input_line_terminator = EOF;
2651
2652               shell_input_line[i] = '\0';
2653               break;
2654             }
2655
2656           shell_input_line[i++] = c;
2657
2658           if (c == '\n')
2659             {
2660               shell_input_line[--i] = '\0';
2661               current_command_line_count++;
2662               break;
2663             }
2664         }
2665       shell_input_line_index = 0;
2666       shell_input_line_len = i;         /* == strlen (shell_input_line) */
2667
2668 #if defined (HISTORY)
2669       if (interactive && shell_input_line && shell_input_line[0])
2670         {
2671           char *expansions;
2672
2673           expansions = pre_process_line (shell_input_line, 1, 1);
2674
2675           free (shell_input_line);
2676           shell_input_line = expansions;
2677           shell_input_line_len = shell_input_line ?
2678                                  strlen (shell_input_line) :
2679                                  0;
2680           if (!shell_input_line_len)
2681             current_command_line_count--;
2682
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;
2686         }
2687 #endif /* HISTORY */
2688
2689       if (shell_input_line)
2690         {
2691           /* Lines that signify the end of the shell's input should not be
2692              echoed. */
2693           if (echo_input_at_read && (shell_input_line[0] ||
2694                                      shell_input_line_terminator != EOF))
2695             fprintf (stderr, "%s\n", shell_input_line);
2696         }
2697       else
2698         {
2699           shell_input_line_size = 0;
2700           prompt_string_pointer = &current_prompt_string;
2701           prompt_again ();
2702           goto restart_read;
2703         }
2704
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)
2708         {
2709           l = shell_input_line_len;     /* was a call to strlen */
2710
2711           if (l + 3 > shell_input_line_size)
2712             shell_input_line = xrealloc (shell_input_line,
2713                                         1 + (shell_input_line_size += 2));
2714
2715           shell_input_line[l] = '\n';
2716           shell_input_line[l + 1] = '\0';
2717         }
2718     }
2719   
2720   c = shell_input_line[shell_input_line_index];
2721
2722   if (c)
2723     shell_input_line_index++;
2724
2725   if (c == '\\' && remove_quoted_newline &&
2726       shell_input_line[shell_input_line_index] == '\n')
2727     {
2728         prompt_again ();
2729         goto restart_read_next_line;
2730     }
2731
2732 #if defined (ALIAS)
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
2737      to. */
2738   if (!c && (pushed_string_list != (STRING_SAVER *)NULL))
2739     {
2740       pop_string ();
2741       c = shell_input_line[shell_input_line_index];
2742       if (c)
2743         shell_input_line_index++;
2744     }
2745 #endif /* ALIAS */
2746
2747   if (!c && shell_input_line_terminator == EOF)
2748     {
2749       if (shell_input_line_index != 0)
2750         return ('\n');
2751       else
2752         return (EOF);
2753     }
2754
2755   return ((unsigned char)c);
2756 }
2757
2758 /* Put C back into the input for the shell. */
2759 static void
2760 shell_ungetc (c)
2761      int c;
2762 {
2763   if (shell_input_line && shell_input_line_index)
2764     shell_input_line[--shell_input_line_index] = c;
2765 }
2766
2767 /* Discard input until CHARACTER is seen. */
2768 static void
2769 discard_until (character)
2770      int character;
2771 {
2772   int c;
2773
2774   while ((c = shell_getc (0)) != EOF && c != character)
2775     ;
2776
2777   if (c != EOF)
2778     shell_ungetc (c);
2779 }
2780 \f
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;
2784
2785 /* Current size of the token buffer. */
2786 static int token_buffer_size = 0;
2787
2788 void
2789 execute_prompt_command (command)
2790      char *command;
2791 {
2792   Function *temp_last, *temp_this;
2793   char *last_lastarg;
2794   int temp_exit_value, temp_eof_encountered;
2795
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 ("_");
2801   if (last_lastarg)
2802     last_lastarg = savestring (last_lastarg);
2803
2804   parse_and_execute (savestring (command), "PROMPT_COMMAND", 0);
2805
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;
2810
2811   bind_variable ("_", last_lastarg);
2812   FREE (last_lastarg);
2813
2814   if (token_to_read == '\n')
2815     token_to_read = 0;
2816 }
2817
2818 /* Command to read_token () explaining what we want it to do. */
2819 #define READ 0
2820 #define RESET 1
2821 #define prompt_is_ps1 \
2822       (!prompt_string_pointer || prompt_string_pointer == &ps1_prompt)
2823
2824 /* Function for yyparse to call.  yylex keeps track of
2825    the last two tokens read, and calls read_token.  */
2826
2827 yylex ()
2828 {
2829   if (interactive && (!current_token || current_token == '\n'))
2830     {
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 ())
2836         {
2837           check_mail ();
2838           reset_mail_timer ();
2839         }
2840
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)
2844         prompt_again ();
2845     }
2846
2847   token_before_that = last_read_token;
2848   last_read_token = current_token;
2849   current_token = read_token (READ);
2850   return (current_token);
2851 }
2852
2853 /* Called from shell.c when Control-C is typed at top level.  Or
2854    by the error rule at top level. */
2855 reset_parser ()
2856 {
2857   read_token (RESET);
2858 }
2859   
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;
2863
2864 /* When non-zero, accept single '{' as a token itself. */
2865 static int allow_open_brace = 0;
2866
2867 /* DELIMITERS is a stack of the nested delimiters that we have
2868    encountered so far. */
2869 static char *delimiters = (char *)NULL;
2870
2871 /* Offset into the stack of delimiters. */
2872 int delimiter_depth = 0;
2873
2874 /* How many slots are allocated to DELIMITERS. */
2875 static int delimiter_space = 0;
2876
2877 void
2878 gather_here_documents ()
2879 {
2880   int r = 0;
2881   while (need_here_doc)
2882     {
2883       make_here_document (redir_stack[r++]);
2884       need_here_doc--;
2885     }
2886 }
2887
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)
2892
2893 #define push_delimiter(character) \
2894   do \
2895     { \
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++; \
2901     } \
2902   while (0)
2903
2904 /* When non-zero, an open-brace used to create a group is awaiting a close
2905    brace partner. */
2906 static int open_brace_awaiting_satisfaction = 0;
2907
2908 #define command_token_position(token) \
2909   (((token) == ASSIGNMENT_WORD) || \
2910    ((token) != SEMI_SEMI && reserved_word_acceptable(token)))
2911
2912 #define assignment_acceptable(token) command_token_position(token) && \
2913                                         (in_case_pattern_list == 0)
2914
2915 /* Check to see if TOKEN is a reserved word and return the token
2916    value if it is. */
2917 #define CHECK_FOR_RESERVED_WORD(tok) \
2918   do { \
2919     if (!dollar_present && !quoted && \
2920         reserved_word_acceptable (last_read_token)) \
2921       { \
2922         int i; \
2923         for (i = 0; word_token_alist[i].word != (char *)NULL; i++) \
2924           if (STREQ (tok, word_token_alist[i].word)) \
2925             { \
2926               if (in_case_pattern_list && (word_token_alist[i].token != ESAC)) \
2927                 break; \
2928 \
2929               if (word_token_alist[i].token == ESAC) \
2930                 in_case_pattern_list = 0; \
2931 \
2932               if (word_token_alist[i].token == '{') \
2933                 open_brace_awaiting_satisfaction++; \
2934 \
2935               if (word_token_alist[i].token == '}' && open_brace_awaiting_satisfaction) \
2936                 open_brace_awaiting_satisfaction--; \
2937 \
2938               return (word_token_alist[i].token); \
2939             } \
2940       } \
2941   } while (0)
2942
2943 /* Read the next token.  Command can be READ (normal operation) or 
2944    RESET (to normalize state). */
2945 static int
2946 read_token (command)
2947      int command;
2948 {
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. */
2953
2954   if (token_buffer_size < TOKEN_DEFAULT_GROW_SIZE)
2955     {
2956       FREE (token);
2957       token = xmalloc (token_buffer_size = TOKEN_DEFAULT_GROW_SIZE);
2958     }
2959
2960   if (command == RESET)
2961     {
2962       delimiter_depth = 0;      /* No delimiters found so far. */
2963       open_brace_awaiting_satisfaction = 0;
2964       in_case_pattern_list = 0;
2965
2966 #if defined (ALIAS)
2967       if (pushed_string_list)
2968         {
2969           free_string_list ();
2970           pushed_string_list = (STRING_SAVER *)NULL;
2971         }
2972
2973       if (expanded_token_stack)
2974         {
2975           free_expansion_stack ();
2976           expanded_token_stack = (EXPANSION_SAVER *)NULL;
2977         }
2978
2979       expand_next_token = 0;
2980 #endif /* ALIAS */
2981
2982       if (shell_input_line)
2983         {
2984           free (shell_input_line);
2985           shell_input_line = (char *)NULL;
2986           shell_input_line_size = shell_input_line_index = 0;
2987         }
2988       last_read_token = '\n';
2989       token_to_read = '\n';
2990       return ('\n');
2991     }
2992
2993   if (token_to_read)
2994     {
2995       int rt = token_to_read;
2996       token_to_read = 0;
2997       return (rt);
2998     }
2999
3000 #if defined (ALIAS)
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)
3008     {
3009       free_expansion_stack ();
3010       expanded_token_stack = (EXPANSION_SAVER *)NULL;
3011     }
3012
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 () */
3015  re_read_token:
3016
3017 #endif /* ALIAS */
3018
3019   /* Read a single word from input.  Start by skipping blanks. */
3020   while ((character = shell_getc (1)) != EOF && whitespace (character));
3021
3022   if (character == EOF)
3023     {
3024       EOF_Reached = 1;
3025       return (yacc_EOF);
3026     }
3027
3028   if (character == '#' && (!interactive || interactive_comments))
3029     {
3030       /* A comment.  Discard until EOL or EOF, and then return a newline. */
3031       discard_until ('\n');
3032       shell_getc (0);
3033
3034       /* If we're about to return an unquoted newline, we can go and collect
3035          the text of any pending here documents. */
3036       if (need_here_doc)
3037         gather_here_documents ();
3038
3039 #if defined (ALIAS)
3040       expand_next_token = 0;
3041 #endif /* ALIAS */
3042
3043       return ('\n');
3044     }
3045
3046   if (character == '\n')
3047     {
3048       /* If we're about to return an unquoted newline, we can go and collect
3049          the text of any pending here document. */
3050       if (need_here_doc)
3051         gather_here_documents ();
3052
3053 #if defined (ALIAS)
3054       expand_next_token = 0;
3055 #endif /* ALIAS */
3056
3057       return (character);
3058     }
3059
3060   if (member (character, "()<>;&|"))
3061     {
3062 #if defined (ALIAS)
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;
3067 #endif /* ALIAS */
3068
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)))
3073         {
3074           switch (character)
3075             {
3076               /* If '<' then we could be at "<<" or at "<<-".  We have to
3077                  look ahead one more character. */
3078             case '<':
3079               peek_char = shell_getc (1);
3080               if (peek_char == '-')
3081                 return (LESS_LESS_MINUS);
3082               else
3083                 {
3084                   shell_ungetc (peek_char);
3085                   return (LESS_LESS);
3086                 }
3087
3088             case '>':
3089               return (GREATER_GREATER);
3090
3091             case ';':
3092               in_case_pattern_list = 1;
3093 #if defined (ALIAS)
3094               expand_next_token = 0;
3095 #endif /* ALIAS */
3096               return (SEMI_SEMI);
3097
3098             case '&':
3099               return (AND_AND);
3100
3101             case '|':
3102               return (OR_OR);
3103             }
3104         }
3105       else
3106         {
3107           if (peek_char == '&')
3108             {
3109               switch (character)
3110                 {
3111                 case '<': return (LESS_AND);
3112                 case '>': return (GREATER_AND);
3113                 }
3114             }
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);
3121         }
3122       shell_ungetc (peek_char);
3123
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)
3129         {
3130           allow_open_brace = 1;
3131 #if defined (ALIAS)
3132           expand_next_token = 0;
3133 #endif /* ALIAS */
3134         }
3135
3136       if (in_case_pattern_list && (character == ')'))
3137         in_case_pattern_list = 0;
3138
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 */
3145         return (character);
3146     }
3147
3148   /* Hack <&- (close stdin) case. */
3149   if (character == '-')
3150     {
3151       switch (last_read_token)
3152         {
3153         case LESS_AND:
3154         case GREATER_AND:
3155           return (character);
3156         }
3157     }
3158   
3159   /* Okay, if we got this far, we have to read a word.  Read one,
3160      and then check it against the known ones. */
3161   {
3162     /* Index into the token that we are building. */
3163     int token_index = 0;
3164
3165     /* ALL_DIGITS becomes zero when we see a non-digit. */
3166     int all_digits = digit (character);
3167
3168     /* DOLLAR_PRESENT becomes non-zero if we see a `$'. */
3169     int dollar_present = 0;
3170
3171     /* QUOTED becomes non-zero if we see one of ("), ('), (`), or (\). */
3172     int quoted = 0;
3173
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;
3177
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;
3181
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;
3185
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;
3189
3190     /* A level variable for parsing '${ ... }' constructs inside of double
3191        quotes. */
3192     int delimited_brace_level = 0;
3193
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;
3197
3198     /* Another level variable.  This one is for dollar_parens inside of
3199        double-quotes. */
3200     int delimited_paren_level = 0;
3201
3202     /* The current delimiting character. */
3203     int cd;
3204
3205     for (;;)
3206       {
3207         if (character == EOF)
3208           goto got_token;
3209
3210         if (pass_next_character)
3211           {
3212             pass_next_character = 0;
3213             goto got_character;
3214           }
3215
3216         cd = current_delimiter ();
3217
3218         if (cd && character == '\\' && cd != '\'')
3219           {
3220             peek_char = shell_getc (0);
3221             if (peek_char != '\\')
3222               shell_ungetc (peek_char);
3223             else
3224               {
3225                 token[token_index++] = character;
3226                 goto got_character;
3227               }
3228           }
3229
3230         /* Handle backslashes.  Quote lots of things when not inside of
3231            double-quotes, quote some things inside of double-quotes. */
3232            
3233         if (character == '\\' && (!delimiter_depth || cd != '\''))
3234           {
3235             peek_char = shell_getc (0);
3236
3237             /* Backslash-newline is ignored in all cases excepting
3238                when quoted with single quotes. */
3239             if (peek_char == '\n')
3240               {
3241                 character = '\n';
3242                 goto next_character;
3243               }
3244             else
3245               {
3246                 shell_ungetc (peek_char);
3247
3248                 /* If the next character is to be quoted, do it now. */
3249                 if (!cd || cd == '`' ||
3250                     (cd == '"' && member (peek_char, slashify_in_quotes)))
3251                   {
3252                     pass_next_character++;
3253                     quoted = 1;
3254                     goto got_character;
3255                   }
3256               }
3257           }
3258
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 == '`'))
3264           {
3265             push_delimiter (character);
3266             goto got_character;
3267           }
3268
3269         cd = current_delimiter ();              /* XXX - may not need */
3270         if (delimiter_depth)
3271           {
3272             if (character == cd)
3273               {
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
3277                    quoted string. */
3278                 if ((delimited_paren_level || delimited_brace_level) &&
3279                     (character == '"'))
3280                   {
3281                     embedded_quoted_string = !embedded_quoted_string;
3282                     goto got_character;
3283                   }
3284                 
3285                 delimiter_depth--;
3286                 goto got_character;
3287               }
3288           }
3289
3290         if (cd != '\'')
3291           {
3292 #if defined (PROCESS_SUBSTITUTION)
3293             if (character == '$' || character == '<' || character == '>')
3294 #else
3295             if (character == '$')
3296 #endif /* !PROCESS_SUBSTITUTION */
3297               {
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)
3302                   goto got_character;
3303
3304                 peek_char = shell_getc (1);
3305                 shell_ungetc (peek_char);
3306                 if (peek_char == '(')
3307                   {
3308                     if (!delimiter_depth)
3309                       dollar_paren_level++;
3310                     else
3311                       delimited_paren_level++;
3312
3313                     pass_next_character++;
3314                     goto got_character;
3315                   }
3316                 else if (peek_char == '[' && character == '$')
3317                   {
3318                     if (!delimiter_depth)
3319                       dollar_bracket_level++;
3320
3321                     pass_next_character++;
3322                     goto got_character;
3323                   }
3324                 /* This handles ${...} constructs. */
3325                 else if (peek_char == '{' && character == '$')
3326                   {
3327                     if (!delimiter_depth)
3328                       dollar_brace_level++;
3329                     else
3330                       delimited_brace_level++;
3331
3332                     pass_next_character++;
3333                     goto got_character;
3334                   }
3335               }
3336
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)
3341               {
3342                 if (delimiter_depth && delimited_paren_level)
3343                   delimited_paren_level++;
3344
3345                 if (!delimiter_depth && dollar_paren_level)
3346                   dollar_paren_level++;
3347               }
3348
3349             if (character == '[')
3350               {
3351                 if (!delimiter_depth && dollar_bracket_level)
3352                   dollar_bracket_level++;
3353               }
3354
3355             if (character == '{' && !embedded_quoted_string)
3356               {
3357                 if (delimiter_depth && delimited_brace_level)
3358                   delimited_brace_level++;
3359
3360                 if (!delimiter_depth && dollar_brace_level)
3361                   dollar_brace_level++;
3362               }
3363
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)
3371               {
3372                 if (delimiter_depth && delimited_paren_level)
3373                   delimited_paren_level--;
3374
3375                 if (!delimiter_depth && dollar_paren_level)
3376                   {
3377                     dollar_paren_level--;
3378                     goto got_character;
3379                   }
3380               }
3381
3382             if (character == ']')
3383               {
3384                 if (!delimiter_depth && dollar_bracket_level)
3385                   {
3386                     dollar_bracket_level--;
3387                     goto got_character;
3388                   }
3389               }
3390
3391             if (character == '}' && !embedded_quoted_string)
3392               {
3393                 if (delimiter_depth && delimited_brace_level)
3394                   delimited_brace_level--;
3395
3396                 if (!delimiter_depth && dollar_brace_level)
3397                   {
3398                     dollar_brace_level--;
3399                     goto got_character;
3400                   }
3401               }
3402           }
3403
3404         if (!dollar_paren_level && !dollar_bracket_level &&
3405             !dollar_brace_level && !delimiter_depth &&
3406             member (character, " \t\n;&()|<>"))
3407           {
3408             shell_ungetc (character);
3409             goto got_token;
3410           }
3411     
3412         if (!delimiter_depth)
3413           {
3414             if (character == '"' || character == '`' || character == '\'')
3415               {
3416                 push_delimiter (character);
3417
3418                 quoted = 1;
3419                 goto got_character;
3420               }
3421           }
3422
3423         if (all_digits)
3424           all_digits = digit (character);
3425         if (character == '$')
3426           dollar_present = 1;
3427
3428       got_character:
3429
3430         if (character == CTLESC || character == CTLNUL)
3431           token[token_index++] = CTLESC;
3432
3433         token[token_index++] = character;
3434
3435         if (token_index == (token_buffer_size - 1))
3436           {
3437             token_buffer_size += TOKEN_DEFAULT_GROW_SIZE;
3438             token = xrealloc (token, token_buffer_size);
3439           }
3440         next_character:
3441         if (character == '\n' && interactive && bash_input.type != st_string)
3442           prompt_again ();
3443
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));
3449       }
3450
3451   got_token:
3452
3453     token[token_index] = '\0';
3454         
3455     if ((delimiter_depth || dollar_paren_level || dollar_bracket_level) &&
3456         character == EOF)
3457       {
3458         char reporter = '\0';
3459
3460         if (!delimiter_depth)
3461           {
3462             if (dollar_paren_level)
3463               reporter = ')';
3464             else if (dollar_bracket_level)
3465               reporter = ']';
3466           }
3467
3468         if (!reporter)
3469           reporter = current_delimiter ();
3470
3471         report_error ("unexpected EOF while looking for `%c'", reporter);
3472         return (-1);
3473       }
3474
3475     if (all_digits)
3476       {
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. */
3481
3482         if (character == '<' || character == '>' ||
3483             last_read_token == LESS_AND || last_read_token == GREATER_AND)
3484           {
3485             yylval.number = atoi (token);
3486             return (NUMBER);
3487           }
3488       }
3489
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)) &&
3495 #else
3496         ((token_before_that == FOR) || (token_before_that == CASE)) &&
3497 #endif
3498         (token[0] == 'i' && token[1] == 'n' && !token[2]))
3499       {
3500         if (token_before_that == CASE)
3501           {
3502             in_case_pattern_list = 1;
3503             allow_esac_as_next++;
3504           }
3505         return (IN);
3506       }
3507
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)) &&
3511 #else
3512     if ((last_read_token == WORD) && (token_before_that == FOR) &&
3513 #endif
3514         (token[0] == 'd' && token[1] == 'o' && !token[2]))
3515       return (DO);
3516
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)
3524       {
3525         allow_esac_as_next--;
3526         if (STREQ (token, "esac"))
3527           {
3528             in_case_pattern_list = 0;
3529             return (ESAC);
3530           }
3531       }
3532
3533     /* Ditto for `{' in the FUNCTION case. */
3534     if (allow_open_brace)
3535       {
3536         allow_open_brace = 0;
3537         if (token[0] == '{' && !token[1])
3538           {
3539             open_brace_awaiting_satisfaction++;
3540             return ('{');
3541           }
3542       }
3543
3544     if (posixly_correct)
3545       CHECK_FOR_RESERVED_WORD (token);
3546
3547 #if defined (ALIAS)
3548     /* OK, we have a token.  Let's try to alias expand it, if (and only if)
3549        it's eligible. 
3550
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
3556        processed alias.
3557
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)))
3562       {
3563         char *alias_expand_word (), *expanded;
3564
3565         if (expanded_token_stack && token_has_been_expanded (token))
3566           goto no_expansion;
3567
3568         expanded = alias_expand_word (token);
3569         if (expanded)
3570           {
3571             int len = strlen (expanded), expand_next;
3572
3573             /* Erase the current token. */
3574             token_index = 0;
3575
3576             expand_next = (expanded[len - 1] == ' ') ||
3577                           (expanded[len - 1] == '\t');
3578
3579             push_string (expanded, expand_next, token);
3580             goto re_read_token;
3581           }
3582         else
3583           /* This is an eligible token that does not have an expansion. */
3584 no_expansion:
3585           expand_next_token = 0;
3586       }
3587     else
3588       {
3589         expand_next_token = 0;
3590       }
3591 #endif /* ALIAS */
3592
3593     if (!posixly_correct)
3594       CHECK_FOR_RESERVED_WORD (token);
3595
3596     /* What if we are attempting to satisfy an open-brace grouper? */
3597     if (open_brace_awaiting_satisfaction && token[0] == '}' && !token[1])
3598       {
3599         open_brace_awaiting_satisfaction--;
3600         return ('}');
3601       }
3602
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);
3609
3610     yylval.word = the_word;
3611     result = WORD;
3612
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;
3618
3619     if (last_read_token == FUNCTION)
3620       allow_open_brace = 1;
3621   }
3622   return (result);
3623 }
3624
3625 /* Return 1 if TOKEN is a token that after being read would allow
3626    a reserved word to be seen, else 0. */
3627 static int
3628 reserved_word_acceptable (token)
3629      int token;
3630 {
3631 #if 0
3632   if (member (token, "\n;()|&{") ||
3633 #else
3634   if (token == '\n' || token == ';' || token == '(' || token == ')' ||
3635       token == '|' || token == '&' || token == '{' ||
3636 #endif
3637       token == '}' ||                   /* XXX */
3638       token == AND_AND ||
3639       token == BANG ||
3640       token == DO ||
3641       token == ELIF ||
3642       token == ELSE ||
3643       token == FI ||
3644       token == IF ||
3645       token == OR_OR ||
3646       token == SEMI_SEMI ||
3647       token == THEN ||
3648       token == UNTIL ||
3649       token == WHILE ||
3650       token == DONE ||          /* XXX these two are experimental */
3651       token == ESAC ||
3652       token == 0)
3653     return (1);
3654   else
3655     return (0);
3656 }
3657
3658 /* Return the index of TOKEN in the alist of reserved words, or -1 if
3659    TOKEN is not a shell reserved word. */
3660 int
3661 find_reserved_word (token)
3662      char *token;
3663 {
3664   int i;
3665   for (i = 0; word_token_alist[i].word != (char *)NULL; i++)
3666     if (STREQ (token, word_token_alist[i].word))
3667       return i;
3668   return -1;
3669 }
3670
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
3674    variable. */
3675 static void
3676 reset_readline_prompt ()
3677 {
3678   if (prompt_string_pointer)
3679     {
3680       char *temp_prompt;
3681
3682       temp_prompt = *prompt_string_pointer
3683                         ? decode_prompt_string (*prompt_string_pointer)
3684                         : (char *)NULL;
3685
3686       if (temp_prompt == 0)
3687         {
3688           temp_prompt = xmalloc (1);
3689           temp_prompt[0] = '\0';
3690         }
3691
3692       FREE (current_readline_prompt);
3693
3694       current_readline_prompt = temp_prompt;
3695     }
3696 }
3697 #endif /* READLINE */
3698
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,
3706   0
3707 };
3708
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
3711    newlines. */
3712 char *
3713 history_delimiting_chars ()
3714 {
3715   if (!delimiter_depth)
3716     {
3717       register int i;
3718
3719       for (i = 0; no_semi_successors[i]; i++)
3720         {
3721           if (token_before_that == no_semi_successors[i])
3722             return (" ");
3723         }
3724       return ("; ");
3725     }
3726   else
3727     return ("\n");
3728 }
3729 #endif /* HISTORY */
3730
3731 /* Issue a prompt, or prepare to issue a prompt when the next character
3732    is read. */
3733 static void
3734 prompt_again ()
3735 {
3736   char *temp_prompt;
3737
3738   if (!interactive)     /* XXX */
3739     return;
3740
3741   ps1_prompt = get_string_value ("PS1");
3742   ps2_prompt = get_string_value ("PS2");
3743
3744   if (!prompt_string_pointer)
3745     prompt_string_pointer = &ps1_prompt;
3746
3747   temp_prompt = (*prompt_string_pointer)
3748                         ? decode_prompt_string (*prompt_string_pointer)
3749                         : (char *)NULL;
3750
3751   if (temp_prompt == 0)
3752     {
3753       temp_prompt = xmalloc (1);
3754       temp_prompt[0] = '\0';
3755     }
3756
3757   current_prompt_string = *prompt_string_pointer;
3758   prompt_string_pointer = &ps2_prompt;
3759
3760 #if defined (READLINE)
3761   if (!no_line_editing)
3762     {
3763       FREE (current_readline_prompt);
3764       current_readline_prompt = temp_prompt;
3765     }
3766   else
3767 #endif  /* READLINE */
3768     {
3769       FREE (current_decoded_prompt);
3770       current_decoded_prompt = temp_prompt;
3771     }
3772 }
3773
3774 static void
3775 print_prompt ()
3776 {
3777   fprintf (stderr, "%s", current_decoded_prompt);
3778   fflush (stderr);
3779 }
3780
3781 /* Return a string which will be printed as a prompt.  The string
3782    may contain special characters which are decoded as follows:
3783    
3784         \t      the time
3785         \d      the date
3786         \n      CRLF
3787         \s      the name of the shell
3788         \w      the current working directory
3789         \W      the last element of PWD
3790         \u      your username
3791         \h      the hostname
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
3796         \\      a backslash
3797 */
3798 #define PROMPT_GROWTH 50
3799 char *
3800 decode_prompt_string (string)
3801      char *string;
3802 {
3803   int result_size = PROMPT_GROWTH;
3804   int result_index = 0;
3805   char *result;
3806   int c;
3807   char *temp = (char *)NULL;
3808   WORD_LIST *list;
3809
3810 #if defined (PROMPT_STRING_DECODE)
3811
3812   result = xmalloc (PROMPT_GROWTH);
3813   result[0] = 0;
3814
3815   while (c = *string++)
3816     {
3817       if (posixly_correct && c == '!')
3818         {
3819           if (*string == '!')
3820             {
3821               temp = savestring ("!");
3822               goto add_string;
3823             }
3824           else
3825             {
3826 #if !defined (HISTORY)
3827                 temp = savestring ("1");
3828 #else /* HISTORY */
3829                 temp = itos (history_number ());
3830 #endif /* HISTORY */
3831                 string--;       /* add_string increments string again. */
3832                 goto add_string;
3833             }
3834         } 
3835       if (c == '\\')
3836         {
3837           c = *string;
3838
3839           switch (c)
3840             {
3841             case '0':
3842             case '1':
3843             case '2':
3844             case '3':
3845             case '4':
3846             case '5':
3847             case '6':
3848             case '7':
3849               {
3850                 char octal_string[4];
3851                 int n;
3852
3853                 strncpy (octal_string, string, 3);
3854                 octal_string[3] = '\0';
3855
3856                 n = read_octal (octal_string);
3857                 temp = xmalloc (3);
3858
3859                 if (n == CTLESC || n == CTLNUL)
3860                   {
3861                     string += 3;
3862                     temp[0] = CTLESC;
3863                     temp[1] = n;
3864                     temp[2] = '\0';
3865                   }
3866                 else if (n == -1)
3867                   {
3868                     temp[0] = '\\';
3869                     temp[1] = '\0';
3870                   }
3871                 else
3872                   {
3873                     string += 3;
3874                     temp[0] = n;
3875                     temp[1] = '\0';
3876                   }
3877
3878                 c = 0;
3879                 goto add_string;
3880               }
3881           
3882             case 't':
3883             case 'd':
3884               /* Make the current time/date into a string. */
3885               {
3886                 time_t the_time = time (0);
3887                 char *ttemp = ctime (&the_time);
3888                 temp = savestring (ttemp);
3889
3890                 if (c == 't')
3891                   {
3892                     strcpy (temp, temp + 11);
3893                     temp[8] = '\0';
3894                   }
3895                 else
3896                   temp[10] = '\0';
3897
3898                 goto add_string;
3899               }
3900
3901             case 'n':
3902               if (!no_line_editing)
3903                 temp = savestring ("\r\n");
3904               else
3905                 temp = savestring ("\n");
3906               goto add_string;
3907
3908             case 's':
3909               {
3910                 temp = base_pathname (shell_name);
3911                 temp = savestring (temp);
3912                 goto add_string;
3913               }
3914         
3915             case 'w':
3916             case 'W':
3917               {
3918                 /* Use the value of PWD because it is much more effecient. */
3919 #define EFFICIENT
3920 #ifdef EFFICIENT
3921                 char *polite_directory_format (), t_string[MAXPATHLEN];
3922
3923                 temp = get_string_value ("PWD");
3924
3925                 if (!temp)
3926                   getwd (t_string);
3927                 else
3928                   strcpy (t_string, temp);
3929 #else
3930                 getwd (t_string);
3931 #endif  /* EFFICIENT */
3932
3933                 if (c == 'W')
3934                   {
3935                     char *dir = (char *)strrchr (t_string, '/');
3936                     if (dir && dir != t_string)
3937                       strcpy (t_string, dir + 1);
3938                     temp = savestring (t_string);
3939                   }
3940                 else
3941                   temp = savestring (polite_directory_format (t_string));
3942                 goto add_string;
3943               }
3944       
3945             case 'u':
3946               {
3947                 temp = savestring (current_user.user_name);
3948                 goto add_string;
3949               }
3950
3951             case 'h':
3952               {
3953                 char *t_string;
3954
3955                 temp = savestring (current_host_name);
3956                 if (t_string = (char *)strchr (temp, '.'))
3957                   *t_string = '\0';
3958                 goto add_string;
3959               }
3960
3961             case '#':
3962               {
3963                 temp = itos (current_command_number);
3964                 goto add_string;
3965               }
3966
3967             case '!':
3968               {
3969 #if !defined (HISTORY)
3970                 temp = savestring ("1");
3971 #else /* HISTORY */
3972                 temp = itos (history_number ());
3973 #endif /* HISTORY */
3974                 goto add_string;
3975               }
3976
3977             case '$':
3978               temp = savestring (geteuid () == 0 ? "#" : "$");
3979               goto add_string;
3980
3981 #if defined (READLINE)
3982             case '[':
3983             case ']':
3984               temp = xmalloc(3);
3985               temp[0] = '\001';
3986               temp[1] = (c == '[') ? RL_PROMPT_START_IGNORE : RL_PROMPT_END_IGNORE;
3987               temp[2] = '\0';
3988               goto add_string;
3989 #endif
3990
3991             case '\\':
3992               temp = savestring ("\\");
3993               goto add_string;
3994
3995             default:
3996               temp = savestring ("\\ ");
3997               temp[1] = c;
3998
3999             add_string:
4000               if (c)
4001                 string++;
4002               result =
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';
4006               break;
4007             }
4008         }
4009       else
4010         {
4011           while (3 + result_index > result_size)
4012             result = xrealloc (result, result_size += PROMPT_GROWTH);
4013
4014           result[result_index++] = c;
4015           result[result_index] = '\0';
4016         }
4017     }
4018 #else /* !PROMPT_STRING_DECODE */
4019   result = savestring (string);
4020 #endif /* !PROMPT_STRING_DECODE */
4021
4022   /* Perform variable and parameter expansion and command substitution on
4023      the prompt string. */
4024   list = expand_string_unsplit (result, 1);
4025   free (result);
4026   result = string_list (list);
4027   dispose_words (list);
4028
4029   return (result);
4030 }
4031
4032 /* Report a syntax error, and restart the parser.  Call here for fatal
4033    errors. */
4034 yyerror ()
4035 {
4036   report_syntax_error ((char *)NULL);
4037   reset_parser ();
4038 }
4039
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. */
4044 static void
4045 report_syntax_error (message)
4046      char *message;
4047 {
4048   if (message)
4049     {
4050       if (!interactive)
4051         {
4052           char *name = bash_input.name ? bash_input.name : "stdin";
4053           report_error ("%s: line %d: `%s'", name, line_number, message);
4054         }
4055       else
4056         {
4057           if (EOF_Reached)
4058             EOF_Reached = 0;
4059           report_error ("%s", message);
4060         }
4061
4062       last_command_exit_value = EX_USAGE;
4063       return;
4064     }
4065
4066   if (shell_input_line && *shell_input_line)
4067     {
4068       char *t = shell_input_line;
4069       register int i = shell_input_line_index;
4070       int token_end = 0;
4071
4072       if (!t[i] && i)
4073         i--;
4074
4075       while (i && (t[i] == ' ' || t[i] == '\t' || t[i] == '\n'))
4076         i--;
4077
4078       if (i)
4079         token_end = i + 1;
4080
4081       while (i && !member (t[i], " \n\t;|&"))
4082         i--;
4083
4084       while (i != token_end && member (t[i], " \t\n"))
4085         i++;
4086
4087       if (token_end)
4088         {
4089           char *error_token;
4090           error_token = xmalloc (1 + (token_end - i));
4091           strncpy (error_token, t + i, token_end - i);
4092           error_token[token_end - i] = '\0';
4093
4094           report_error ("syntax error near unexpected token `%s'", error_token);
4095           free (error_token);
4096         }
4097       else if ((i == 0) && (token_end == 0))    /* a 1-character token */
4098         {
4099           char etoken[2];
4100           etoken[0] = t[i];
4101           etoken[1] = '\0';
4102
4103           report_error ("syntax error near unexpected token `%s'", etoken);
4104         }
4105
4106       if (!interactive)
4107         {
4108           char *temp = savestring (shell_input_line);
4109           char *name = bash_input.name ? bash_input.name : "stdin";
4110           int l = strlen (temp);
4111
4112           while (l && temp[l - 1] == '\n')
4113             temp[--l] = '\0';
4114
4115           report_error ("%s: line %d: `%s'", name, line_number, temp);
4116           free (temp);
4117         }
4118     }
4119   else
4120     {
4121       char *name, *msg;
4122       if (!interactive)
4123         name = bash_input.name ? bash_input.name : "stdin";
4124       if (EOF_Reached)
4125         msg = "syntax error: unexpected end of file";
4126       else
4127         msg = "syntax error";
4128       if (!interactive)
4129         report_error ("%s: line %d: %s", name, line_number, msg);
4130       else
4131         {
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. */
4135           EOF_Reached = 0;
4136           report_error (msg);
4137         }
4138     }
4139   last_command_exit_value = EX_USAGE;
4140 }
4141
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)
4148      int error_p;
4149 {
4150 }
4151    
4152 /* Do that silly `type "bye" to exit' stuff.  You know, "ignoreeof". */
4153
4154 /* A flag denoting whether or not ignoreeof is set. */
4155 int ignoreeof = 0;
4156
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;
4161
4162 /* The limit for eof_encountered. */
4163 int eof_encountered_limit = 10;
4164
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. */
4169 static void
4170 handle_eof_input_unit ()
4171 {
4172   if (interactive)
4173     {
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
4176          in this file. */
4177       if (EOF_Reached)
4178         EOF_Reached = 0;
4179
4180       /* If the user wants to "ignore" eof, then let her do so, kind of. */
4181       if (ignoreeof)
4182         {
4183           if (eof_encountered < eof_encountered_limit)
4184             {
4185               fprintf (stderr, "Use \"%s\" to leave the shell.\n",
4186                        login_shell ? "logout" : "exit");
4187               eof_encountered++;
4188               /* Reset the prompt string to be $PS1. */
4189               prompt_string_pointer = (char **)NULL;
4190               prompt_again ();
4191               last_read_token = current_token = '\n';
4192               return;
4193             } 
4194         }
4195
4196       /* In this case EOF should exit the shell.  Do it now. */
4197       reset_parser ();
4198       exit_builtin ((WORD_LIST *)NULL);
4199     }
4200   else
4201     {
4202       /* We don't write history files, etc., for non-interactive shells. */
4203       EOF_Reached = 1;
4204     }
4205 }