]> git.ipfire.org Git - thirdparty/bash.git/blame - y.tab.c
fix for SIGINT in sourced script
[thirdparty/bash.git] / y.tab.c
CommitLineData
a0c0a00f 1/* A Bison parser, made by GNU Bison 3.0.4. */
b80f6443 2
a0c0a00f 3/* Bison implementation for Yacc-like parsers in C
b80f6443 4
a0c0a00f 5 Copyright (C) 1984, 1989-1990, 2000-2015 Free Software Foundation, Inc.
3185942a 6
a0c0a00f 7 This program is free software: you can redistribute it and/or modify
3185942a 8 it under the terms of the GNU General Public License as published by
a0c0a00f
CR
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
3185942a
JA
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
a0c0a00f 18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
3185942a
JA
19
20/* As a special exception, you may create a larger work that contains
21 part or all of the Bison parser skeleton and distribute that work
22 under terms of your choice, so long as that work isn't itself a
23 parser generator using the skeleton or a modified version thereof
24 as a parser skeleton. Alternatively, if you modify or redistribute
25 the parser skeleton itself, you may (at your option) remove this
26 special exception, which will cause the skeleton and the resulting
27 Bison output files to be licensed under the GNU General Public
28 License without this special exception.
29
30 This special exception was added by the Free Software Foundation in
31 version 2.2 of Bison. */
32
33/* C LALR(1) parser skeleton written by Richard Stallman, by
34 simplifying the original so-called "semantic" parser. */
35
36/* All symbols defined below should begin with yy or YY, to avoid
37 infringing on user name space. This should be done even for local
38 variables, as they might otherwise be expanded by user macros.
39 There are some unavoidable exceptions within include files to
40 define necessary library symbols; they are noted "INFRINGES ON
41 USER NAME SPACE" below. */
42
43/* Identify Bison output. */
44#define YYBISON 1
45
46/* Bison version. */
a0c0a00f 47#define YYBISON_VERSION "3.0.4"
3185942a
JA
48
49/* Skeleton name. */
50#define YYSKELETON_NAME "yacc.c"
51
52/* Pure parsers. */
53#define YYPURE 0
54
a0c0a00f
CR
55/* Push parsers. */
56#define YYPUSH 0
3185942a 57
a0c0a00f
CR
58/* Pull parsers. */
59#define YYPULL 1
3185942a
JA
60
61
62
63
64/* Copy the first part of user declarations. */
a0c0a00f 65#line 21 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:339 */
f73dda09 66
ccc6cda3
JA
67#include "config.h"
68
726f6388 69#include "bashtypes.h"
726f6388 70#include "bashansi.h"
ccc6cda3 71
28ef6c31
JA
72#include "filecntl.h"
73
ccc6cda3
JA
74#if defined (HAVE_UNISTD_H)
75# include <unistd.h>
76#endif
77
78#if defined (HAVE_LOCALE_H)
79# include <locale.h>
80#endif
81
82#include <stdio.h>
f73dda09 83#include "chartypes.h"
ccc6cda3
JA
84#include <signal.h>
85
86#include "memalloc.h"
87
b80f6443
JA
88#include "bashintl.h"
89
7117c2d2
JA
90#define NEED_STRFTIME_DECL /* used in externs.h */
91
726f6388 92#include "shell.h"
ac50fbac 93#include "typemax.h" /* SIZE_MAX if needed */
ccc6cda3 94#include "trap.h"
726f6388 95#include "flags.h"
ccc6cda3
JA
96#include "parser.h"
97#include "mailcheck.h"
f73dda09 98#include "test.h"
95732b49 99#include "builtins.h"
ccc6cda3
JA
100#include "builtins/common.h"
101#include "builtins/builtext.h"
726f6388 102
7117c2d2
JA
103#include "shmbutil.h"
104
726f6388 105#if defined (READLINE)
ccc6cda3 106# include "bashline.h"
726f6388
JA
107# include <readline/readline.h>
108#endif /* READLINE */
109
110#if defined (HISTORY)
111# include "bashhist.h"
112# include <readline/history.h>
113#endif /* HISTORY */
114
115#if defined (JOB_CONTROL)
116# include "jobs.h"
a0c0a00f
CR
117#else
118extern int cleanup_dead_jobs __P((void));
726f6388
JA
119#endif /* JOB_CONTROL */
120
121#if defined (ALIAS)
122# include "alias.h"
b80f6443
JA
123#else
124typedef void *alias_t;
726f6388
JA
125#endif /* ALIAS */
126
127#if defined (PROMPT_STRING_DECODE)
cce855bc
JA
128# ifndef _MINIX
129# include <sys/param.h>
130# endif
131# include <time.h>
7117c2d2
JA
132# if defined (TM_IN_SYS_TIME)
133# include <sys/types.h>
134# include <sys/time.h>
135# endif /* TM_IN_SYS_TIME */
cce855bc 136# include "maxpath.h"
726f6388
JA
137#endif /* PROMPT_STRING_DECODE */
138
ccc6cda3
JA
139#define RE_READ_TOKEN -99
140#define NO_EXPANSION -100
141
7117c2d2
JA
142#ifdef DEBUG
143# define YYDEBUG 1
144#else
145# define YYDEBUG 0
146#endif
147
148#if defined (HANDLE_MULTIBYTE)
149# define last_shell_getc_is_singlebyte \
150 ((shell_input_line_index > 1) \
151 ? shell_input_line_property[shell_input_line_index - 1] \
152 : 1)
153# define MBTEST(x) ((x) && last_shell_getc_is_singlebyte)
154#else
155# define last_shell_getc_is_singlebyte 1
156# define MBTEST(x) ((x))
157#endif
ccc6cda3 158
cce855bc 159#if defined (EXTENDED_GLOB)
cce855bc
JA
160extern int extended_glob;
161#endif
162
726f6388 163extern int eof_encountered;
ccc6cda3 164extern int no_line_editing, running_under_emacs;
726f6388 165extern int current_command_number;
3185942a 166extern int sourcelevel, parse_and_execute_level;
726f6388
JA
167extern int posixly_correct;
168extern int last_command_exit_value;
0001803f 169extern pid_t last_command_subst_pid;
726f6388 170extern char *shell_name, *current_host_name;
ccc6cda3
JA
171extern char *dist_version;
172extern int patch_level;
cce855bc 173extern int dump_translatable_strings, dump_po_strings;
f73dda09 174extern sh_builtin_func_t *last_shell_builtin, *this_shell_builtin;
a0c0a00f 175extern int here_doc_first_line;
726f6388
JA
176#if defined (BUFFERED_INPUT)
177extern int bash_input_fd_changed;
178#endif
179
bb70624e 180extern int errno;
726f6388
JA
181/* **************************************************************** */
182/* */
183/* "Forward" declarations */
184/* */
185/* **************************************************************** */
186
f73dda09
JA
187#ifdef DEBUG
188static void debug_parser __P((int));
189#endif
190
191static int yy_getc __P((void));
192static int yy_ungetc __P((int));
193
194#if defined (READLINE)
195static int yy_readline_get __P((void));
196static int yy_readline_unget __P((int));
197#endif
198
199static int yy_string_get __P((void));
200static int yy_string_unget __P((int));
3185942a 201static void rewind_input_string __P((void));
f73dda09
JA
202static int yy_stream_get __P((void));
203static int yy_stream_unget __P((int));
204
205static int shell_getc __P((int));
206static void shell_ungetc __P((int));
207static void discard_until __P((int));
208
209#if defined (ALIAS) || defined (DPAREN_ARITHMETIC)
210static void push_string __P((char *, int, alias_t *));
211static void pop_string __P((void));
212static void free_string_list __P((void));
213#endif
214
215static char *read_a_line __P((int));
216
f73dda09
JA
217static int reserved_word_acceptable __P((int));
218static int yylex __P((void));
90a39f32
CR
219
220static void push_heredoc __P((REDIRECT *));
221static char *mk_alexpansion __P((char *));
f73dda09
JA
222static int alias_expand_token __P((char *));
223static int time_command_acceptable __P((void));
224static int special_case_tokens __P((char *));
225static int read_token __P((int));
226static char *parse_matched_pair __P((int, int, int, int *, int));
3185942a 227static char *parse_comsub __P((int, int, int, int *, int));
7117c2d2
JA
228#if defined (ARRAY_VARS)
229static char *parse_compound_assignment __P((int *));
230#endif
f73dda09 231#if defined (DPAREN_ARITHMETIC) || defined (ARITH_FOR_COMMAND)
7117c2d2 232static int parse_dparen __P((int));
b80f6443 233static int parse_arith_cmd __P((char **, int));
f73dda09 234#endif
cce855bc 235#if defined (COND_COMMAND)
7117c2d2 236static void cond_error __P((void));
f73dda09
JA
237static COND_COM *cond_expr __P((void));
238static COND_COM *cond_or __P((void));
239static COND_COM *cond_and __P((void));
240static COND_COM *cond_term __P((void));
241static int cond_skip_newlines __P((void));
242static COMMAND *parse_cond_command __P((void));
cce855bc 243#endif
7117c2d2
JA
244#if defined (ARRAY_VARS)
245static int token_is_assignment __P((char *, int));
246static int token_is_ident __P((char *, int));
247#endif
f73dda09
JA
248static int read_token_word __P((int));
249static void discard_parser_constructs __P((int));
726f6388 250
7117c2d2
JA
251static char *error_token_from_token __P((int));
252static char *error_token_from_text __P((void));
253static void print_offending_line __P((void));
f73dda09 254static void report_syntax_error __P((char *));
7117c2d2 255
f73dda09
JA
256static void handle_eof_input_unit __P((void));
257static void prompt_again __P((void));
d166f048 258#if 0
f73dda09 259static void reset_readline_prompt __P((void));
d166f048 260#endif
f73dda09 261static void print_prompt __P((void));
726f6388 262
7117c2d2
JA
263#if defined (HANDLE_MULTIBYTE)
264static void set_line_mbstate __P((void));
265static char *shell_input_line_property = NULL;
266#else
267# define set_line_mbstate()
268#endif
269
f73dda09 270extern int yyerror __P((const char *));
d166f048 271
7117c2d2
JA
272#ifdef DEBUG
273extern int yydebug;
274#endif
275
ccc6cda3
JA
276/* Default prompt strings */
277char *primary_prompt = PPROMPT;
278char *secondary_prompt = SPROMPT;
279
726f6388
JA
280/* PROMPT_STRING_POINTER points to one of these, never to an actual string. */
281char *ps1_prompt, *ps2_prompt;
282
a0c0a00f
CR
283/* Displayed after reading a command but before executing it in an interactive shell */
284char *ps0_prompt;
285
726f6388
JA
286/* Handle on the current prompt string. Indirectly points through
287 ps1_ or ps2_prompt. */
288char **prompt_string_pointer = (char **)NULL;
289char *current_prompt_string;
290
ccc6cda3
JA
291/* Non-zero means we expand aliases in commands. */
292int expand_aliases = 0;
293
294/* If non-zero, the decoded prompt string undergoes parameter and
295 variable substitution, command substitution, arithmetic substitution,
296 string expansion, process substitution, and quote removal in
297 decode_prompt_string. */
298int promptvars = 1;
299
b80f6443
JA
300/* If non-zero, $'...' and $"..." are expanded when they appear within
301 a ${...} expansion, even when the expansion appears within double
302 quotes. */
303int extended_quote = 1;
304
726f6388 305/* The number of lines read from input while creating the current command. */
ccc6cda3 306int current_command_line_count;
726f6388 307
495aee44
CR
308/* The number of lines in a command saved while we run parse_and_execute */
309int saved_command_line_count;
310
3185942a
JA
311/* The token that currently denotes the end of parse. */
312int shell_eof_token;
313
314/* The token currently being read. */
315int current_token;
316
0001803f
CR
317/* The current parser state. */
318int parser_state;
319
726f6388
JA
320/* Variables to manage the task of reading here documents, because we need to
321 defer the reading until after a complete command has been collected. */
90a39f32 322static REDIRECT *redir_stack[HEREDOC_MAX];
ccc6cda3 323int need_here_doc;
726f6388
JA
324
325/* Where shell input comes from. History expansion is performed on each
326 line when the shell is interactive. */
327static char *shell_input_line = (char *)NULL;
ac50fbac
CR
328static size_t shell_input_line_index;
329static size_t shell_input_line_size; /* Amount allocated for shell_input_line. */
330static size_t shell_input_line_len; /* strlen (shell_input_line) */
726f6388
JA
331
332/* Either zero or EOF. */
ccc6cda3
JA
333static int shell_input_line_terminator;
334
335/* The line number in a script on which a function definition starts. */
336static int function_dstart;
337
338/* The line number in a script on which a function body starts. */
339static int function_bstart;
726f6388 340
bb70624e
JA
341/* The line number in a script at which an arithmetic for command starts. */
342static int arith_for_lineno;
343
0001803f
CR
344/* The decoded prompt string. Used if READLINE is not defined or if
345 editing is turned off. Analogous to current_readline_prompt. */
346static char *current_decoded_prompt;
3185942a
JA
347
348/* The last read token, or NULL. read_token () uses this for context
349 checking. */
350static int last_read_token;
351
352/* The token read prior to last_read_token. */
353static int token_before_that;
354
355/* The token read prior to token_before_that. */
356static int two_tokens_ago;
357
0001803f
CR
358static int global_extglob;
359
b80f6443
JA
360/* The line number in a script where the word in a `case WORD', `select WORD'
361 or `for WORD' begins. This is a nested command maximum, since the array
362 index is decremented after a case, select, or for command is parsed. */
363#define MAX_CASE_NEST 128
90a39f32 364static int word_lineno[MAX_CASE_NEST+1];
b80f6443
JA
365static int word_top = -1;
366
367/* If non-zero, it is the token that we want read_token to return
368 regardless of what text is (or isn't) present to be read. This
369 is reset by read_token. If token_to_read == WORD or
370 ASSIGNMENT_WORD, yylval.word should be set to word_desc_to_read. */
371static int token_to_read;
372static WORD_DESC *word_desc_to_read;
373
0001803f 374static REDIRECTEE source;
726f6388 375static REDIRECTEE redir;
f73dda09 376
a0c0a00f 377#line 378 "y.tab.c" /* yacc.c:339 */
3185942a 378
a0c0a00f
CR
379# ifndef YY_NULLPTR
380# if defined __cplusplus && 201103L <= __cplusplus
381# define YY_NULLPTR nullptr
382# else
383# define YY_NULLPTR 0
384# endif
385# endif
3185942a
JA
386
387/* Enabling verbose error messages. */
388#ifdef YYERROR_VERBOSE
389# undef YYERROR_VERBOSE
390# define YYERROR_VERBOSE 1
391#else
392# define YYERROR_VERBOSE 0
393#endif
394
a0c0a00f
CR
395/* In a future release of Bison, this section will be replaced
396 by #include "y.tab.h". */
397#ifndef YY_YY_Y_TAB_H_INCLUDED
398# define YY_YY_Y_TAB_H_INCLUDED
399/* Debug traces. */
400#ifndef YYDEBUG
401# define YYDEBUG 0
402#endif
403#if YYDEBUG
404extern int yydebug;
3185942a
JA
405#endif
406
a0c0a00f
CR
407/* Token type. */
408#ifndef YYTOKENTYPE
409# define YYTOKENTYPE
410 enum yytokentype
411 {
412 IF = 258,
413 THEN = 259,
414 ELSE = 260,
415 ELIF = 261,
416 FI = 262,
417 CASE = 263,
418 ESAC = 264,
419 FOR = 265,
420 SELECT = 266,
421 WHILE = 267,
422 UNTIL = 268,
423 DO = 269,
424 DONE = 270,
425 FUNCTION = 271,
426 COPROC = 272,
427 COND_START = 273,
428 COND_END = 274,
429 COND_ERROR = 275,
430 IN = 276,
431 BANG = 277,
432 TIME = 278,
433 TIMEOPT = 279,
434 TIMEIGN = 280,
435 WORD = 281,
436 ASSIGNMENT_WORD = 282,
437 REDIR_WORD = 283,
438 NUMBER = 284,
439 ARITH_CMD = 285,
440 ARITH_FOR_EXPRS = 286,
441 COND_CMD = 287,
442 AND_AND = 288,
443 OR_OR = 289,
444 GREATER_GREATER = 290,
445 LESS_LESS = 291,
446 LESS_AND = 292,
447 LESS_LESS_LESS = 293,
448 GREATER_AND = 294,
449 SEMI_SEMI = 295,
450 SEMI_AND = 296,
451 SEMI_SEMI_AND = 297,
452 LESS_LESS_MINUS = 298,
453 AND_GREATER = 299,
454 AND_GREATER_GREATER = 300,
455 LESS_GREATER = 301,
456 GREATER_BAR = 302,
457 BAR_AND = 303,
458 yacc_EOF = 304
459 };
460#endif
461/* Tokens. */
462#define IF 258
463#define THEN 259
464#define ELSE 260
465#define ELIF 261
466#define FI 262
467#define CASE 263
468#define ESAC 264
469#define FOR 265
470#define SELECT 266
471#define WHILE 267
472#define UNTIL 268
473#define DO 269
474#define DONE 270
475#define FUNCTION 271
476#define COPROC 272
477#define COND_START 273
478#define COND_END 274
479#define COND_ERROR 275
480#define IN 276
481#define BANG 277
482#define TIME 278
483#define TIMEOPT 279
484#define TIMEIGN 280
485#define WORD 281
486#define ASSIGNMENT_WORD 282
487#define REDIR_WORD 283
488#define NUMBER 284
489#define ARITH_CMD 285
490#define ARITH_FOR_EXPRS 286
491#define COND_CMD 287
492#define AND_AND 288
493#define OR_OR 289
494#define GREATER_GREATER 290
495#define LESS_LESS 291
496#define LESS_AND 292
497#define LESS_LESS_LESS 293
498#define GREATER_AND 294
499#define SEMI_SEMI 295
500#define SEMI_AND 296
501#define SEMI_SEMI_AND 297
502#define LESS_LESS_MINUS 298
503#define AND_GREATER 299
504#define AND_GREATER_GREATER 300
505#define LESS_GREATER 301
506#define GREATER_BAR 302
507#define BAR_AND 303
508#define yacc_EOF 304
509
510/* Value type. */
3185942a 511#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
a0c0a00f
CR
512
513union YYSTYPE
3185942a 514{
a0c0a00f
CR
515#line 333 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:355 */
516
726f6388
JA
517 WORD_DESC *word; /* the word that we read. */
518 int number; /* the number that we read. */
519 WORD_LIST *word_list;
520 COMMAND *command;
521 REDIRECT *redirect;
522 ELEMENT element;
523 PATTERN_LIST *pattern;
a0c0a00f
CR
524
525#line 526 "y.tab.c" /* yacc.c:355 */
526};
527
528typedef union YYSTYPE YYSTYPE;
3185942a 529# define YYSTYPE_IS_TRIVIAL 1
a0c0a00f 530# define YYSTYPE_IS_DECLARED 1
3185942a
JA
531#endif
532
533
a0c0a00f 534extern YYSTYPE yylval;
3185942a 535
a0c0a00f 536int yyparse (void);
3185942a 537
a0c0a00f 538#endif /* !YY_YY_Y_TAB_H_INCLUDED */
3185942a 539
a0c0a00f
CR
540/* Copy the second part of user declarations. */
541
542#line 543 "y.tab.c" /* yacc.c:358 */
b80f6443 543
3185942a
JA
544#ifdef short
545# undef short
f73dda09 546#endif
3185942a
JA
547
548#ifdef YYTYPE_UINT8
549typedef YYTYPE_UINT8 yytype_uint8;
550#else
551typedef unsigned char yytype_uint8;
f73dda09
JA
552#endif
553
3185942a
JA
554#ifdef YYTYPE_INT8
555typedef YYTYPE_INT8 yytype_int8;
3185942a 556#else
a0c0a00f 557typedef signed char yytype_int8;
3185942a 558#endif
f73dda09 559
3185942a
JA
560#ifdef YYTYPE_UINT16
561typedef YYTYPE_UINT16 yytype_uint16;
562#else
563typedef unsigned short int yytype_uint16;
564#endif
f73dda09 565
3185942a
JA
566#ifdef YYTYPE_INT16
567typedef YYTYPE_INT16 yytype_int16;
568#else
569typedef short int yytype_int16;
570#endif
f73dda09 571
3185942a
JA
572#ifndef YYSIZE_T
573# ifdef __SIZE_TYPE__
574# define YYSIZE_T __SIZE_TYPE__
575# elif defined size_t
576# define YYSIZE_T size_t
a0c0a00f 577# elif ! defined YYSIZE_T
3185942a
JA
578# include <stddef.h> /* INFRINGES ON USER NAME SPACE */
579# define YYSIZE_T size_t
580# else
581# define YYSIZE_T unsigned int
582# endif
583#endif
b80f6443 584
3185942a 585#define YYSIZE_MAXIMUM ((YYSIZE_T) -1)
f73dda09 586
3185942a 587#ifndef YY_
509a4430 588# if defined YYENABLE_NLS && YYENABLE_NLS
3185942a
JA
589# if ENABLE_NLS
590# include <libintl.h> /* INFRINGES ON USER NAME SPACE */
a0c0a00f 591# define YY_(Msgid) dgettext ("bison-runtime", Msgid)
3185942a
JA
592# endif
593# endif
594# ifndef YY_
a0c0a00f
CR
595# define YY_(Msgid) Msgid
596# endif
597#endif
598
599#ifndef YY_ATTRIBUTE
600# if (defined __GNUC__ \
601 && (2 < __GNUC__ || (__GNUC__ == 2 && 96 <= __GNUC_MINOR__))) \
602 || defined __SUNPRO_C && 0x5110 <= __SUNPRO_C
603# define YY_ATTRIBUTE(Spec) __attribute__(Spec)
604# else
605# define YY_ATTRIBUTE(Spec) /* empty */
606# endif
607#endif
608
609#ifndef YY_ATTRIBUTE_PURE
610# define YY_ATTRIBUTE_PURE YY_ATTRIBUTE ((__pure__))
611#endif
612
613#ifndef YY_ATTRIBUTE_UNUSED
614# define YY_ATTRIBUTE_UNUSED YY_ATTRIBUTE ((__unused__))
615#endif
616
617#if !defined _Noreturn \
618 && (!defined __STDC_VERSION__ || __STDC_VERSION__ < 201112)
619# if defined _MSC_VER && 1200 <= _MSC_VER
620# define _Noreturn __declspec (noreturn)
621# else
622# define _Noreturn YY_ATTRIBUTE ((__noreturn__))
3185942a 623# endif
f73dda09
JA
624#endif
625
3185942a
JA
626/* Suppress unused-variable warnings by "using" E. */
627#if ! defined lint || defined __GNUC__
a0c0a00f 628# define YYUSE(E) ((void) (E))
3185942a 629#else
a0c0a00f 630# define YYUSE(E) /* empty */
f73dda09
JA
631#endif
632
a0c0a00f
CR
633#if defined __GNUC__ && 407 <= __GNUC__ * 100 + __GNUC_MINOR__
634/* Suppress an incorrect diagnostic about yylval being uninitialized. */
635# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \
636 _Pragma ("GCC diagnostic push") \
637 _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"")\
638 _Pragma ("GCC diagnostic ignored \"-Wmaybe-uninitialized\"")
639# define YY_IGNORE_MAYBE_UNINITIALIZED_END \
640 _Pragma ("GCC diagnostic pop")
3185942a 641#else
a0c0a00f 642# define YY_INITIAL_VALUE(Value) Value
3185942a 643#endif
a0c0a00f
CR
644#ifndef YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
645# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
646# define YY_IGNORE_MAYBE_UNINITIALIZED_END
3185942a 647#endif
a0c0a00f
CR
648#ifndef YY_INITIAL_VALUE
649# define YY_INITIAL_VALUE(Value) /* Nothing. */
650#endif
651
3185942a
JA
652
653#if ! defined yyoverflow || YYERROR_VERBOSE
654
655/* The parser invokes alloca or malloc; define the necessary symbols. */
656
657# ifdef YYSTACK_USE_ALLOCA
658# if YYSTACK_USE_ALLOCA
659# ifdef __GNUC__
660# define YYSTACK_ALLOC __builtin_alloca
661# elif defined __BUILTIN_VA_ARG_INCR
662# include <alloca.h> /* INFRINGES ON USER NAME SPACE */
663# elif defined _AIX
664# define YYSTACK_ALLOC __alloca
665# elif defined _MSC_VER
666# include <malloc.h> /* INFRINGES ON USER NAME SPACE */
667# define alloca _alloca
668# else
669# define YYSTACK_ALLOC alloca
a0c0a00f 670# if ! defined _ALLOCA_H && ! defined EXIT_SUCCESS
3185942a 671# include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
a0c0a00f
CR
672 /* Use EXIT_SUCCESS as a witness for stdlib.h. */
673# ifndef EXIT_SUCCESS
674# define EXIT_SUCCESS 0
3185942a
JA
675# endif
676# endif
677# endif
678# endif
679# endif
680
681# ifdef YYSTACK_ALLOC
a0c0a00f
CR
682 /* Pacify GCC's 'empty if-body' warning. */
683# define YYSTACK_FREE(Ptr) do { /* empty */; } while (0)
3185942a
JA
684# ifndef YYSTACK_ALLOC_MAXIMUM
685 /* The OS might guarantee only one guard page at the bottom of the stack,
686 and a page size can be as small as 4096 bytes. So we cannot safely
687 invoke alloca (N) if N exceeds 4096. Use a slightly smaller number
688 to allow for a few compiler-allocated temporary stack slots. */
689# define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */
690# endif
691# else
692# define YYSTACK_ALLOC YYMALLOC
693# define YYSTACK_FREE YYFREE
694# ifndef YYSTACK_ALLOC_MAXIMUM
695# define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM
696# endif
a0c0a00f 697# if (defined __cplusplus && ! defined EXIT_SUCCESS \
3185942a 698 && ! ((defined YYMALLOC || defined malloc) \
a0c0a00f 699 && (defined YYFREE || defined free)))
3185942a 700# include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
a0c0a00f
CR
701# ifndef EXIT_SUCCESS
702# define EXIT_SUCCESS 0
3185942a
JA
703# endif
704# endif
705# ifndef YYMALLOC
706# define YYMALLOC malloc
a0c0a00f 707# if ! defined malloc && ! defined EXIT_SUCCESS
3185942a
JA
708void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */
709# endif
710# endif
711# ifndef YYFREE
712# define YYFREE free
a0c0a00f 713# if ! defined free && ! defined EXIT_SUCCESS
3185942a
JA
714void free (void *); /* INFRINGES ON USER NAME SPACE */
715# endif
716# endif
717# endif
718#endif /* ! defined yyoverflow || YYERROR_VERBOSE */
719
720
721#if (! defined yyoverflow \
722 && (! defined __cplusplus \
a0c0a00f 723 || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
3185942a
JA
724
725/* A type that is properly aligned for any stack member. */
726union yyalloc
727{
a0c0a00f
CR
728 yytype_int16 yyss_alloc;
729 YYSTYPE yyvs_alloc;
730};
3185942a
JA
731
732/* The size of the maximum gap between one aligned stack and the next. */
733# define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1)
734
735/* The size of an array large to enough to hold all stacks, each with
736 N elements. */
737# define YYSTACK_BYTES(N) \
738 ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE)) \
739 + YYSTACK_GAP_MAXIMUM)
740
a0c0a00f 741# define YYCOPY_NEEDED 1
3185942a
JA
742
743/* Relocate STACK from its old location to the new one. The
744 local variables YYSIZE and YYSTACKSIZE give the old and new number of
745 elements in the stack, and YYPTR gives the new location of the
746 stack. Advance YYPTR to a properly aligned location for the next
747 stack. */
a0c0a00f
CR
748# define YYSTACK_RELOCATE(Stack_alloc, Stack) \
749 do \
750 { \
751 YYSIZE_T yynewbytes; \
752 YYCOPY (&yyptr->Stack_alloc, Stack, yysize); \
753 Stack = &yyptr->Stack_alloc; \
754 yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \
755 yyptr += yynewbytes / sizeof (*yyptr); \
756 } \
757 while (0)
f73dda09 758
f73dda09
JA
759#endif
760
a0c0a00f
CR
761#if defined YYCOPY_NEEDED && YYCOPY_NEEDED
762/* Copy COUNT objects from SRC to DST. The source and destination do
763 not overlap. */
764# ifndef YYCOPY
765# if defined __GNUC__ && 1 < __GNUC__
766# define YYCOPY(Dst, Src, Count) \
767 __builtin_memcpy (Dst, Src, (Count) * sizeof (*(Src)))
768# else
769# define YYCOPY(Dst, Src, Count) \
770 do \
771 { \
772 YYSIZE_T yyi; \
773 for (yyi = 0; yyi < (Count); yyi++) \
774 (Dst)[yyi] = (Src)[yyi]; \
775 } \
776 while (0)
777# endif
778# endif
779#endif /* !YYCOPY_NEEDED */
780
3185942a 781/* YYFINAL -- State number of the termination state. */
495aee44 782#define YYFINAL 116
3185942a 783/* YYLAST -- Last index in YYTABLE. */
a0c0a00f 784#define YYLAST 638
3185942a
JA
785
786/* YYNTOKENS -- Number of terminals. */
495aee44 787#define YYNTOKENS 61
3185942a
JA
788/* YYNNTS -- Number of nonterminals. */
789#define YYNNTS 38
790/* YYNRULES -- Number of rules. */
0001803f 791#define YYNRULES 167
a0c0a00f
CR
792/* YYNSTATES -- Number of states. */
793#define YYNSTATES 334
3185942a 794
a0c0a00f
CR
795/* YYTRANSLATE[YYX] -- Symbol number corresponding to YYX as returned
796 by yylex, with out-of-bounds checking. */
3185942a 797#define YYUNDEFTOK 2
495aee44 798#define YYMAXUTOK 304
3185942a 799
a0c0a00f 800#define YYTRANSLATE(YYX) \
3185942a
JA
801 ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
802
a0c0a00f
CR
803/* YYTRANSLATE[TOKEN-NUM] -- Symbol number corresponding to TOKEN-NUM
804 as returned by yylex, without out-of-bounds checking. */
3185942a
JA
805static const yytype_uint8 yytranslate[] =
806{
807 0, 2, 2, 2, 2, 2, 2, 2, 2, 2,
495aee44 808 51, 2, 2, 2, 2, 2, 2, 2, 2, 2,
3185942a 809 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
495aee44
CR
810 2, 2, 2, 2, 2, 2, 2, 2, 49, 2,
811 59, 60, 2, 2, 2, 56, 2, 2, 2, 2,
812 2, 2, 2, 2, 2, 2, 2, 2, 2, 50,
813 55, 2, 54, 2, 2, 2, 2, 2, 2, 2,
3185942a
JA
814 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
815 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
816 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
817 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
818 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
495aee44 819 2, 2, 2, 57, 53, 58, 2, 2, 2, 2,
3185942a
JA
820 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
821 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
822 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
823 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
824 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
825 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
826 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
827 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
828 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
829 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
830 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
831 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
832 2, 2, 2, 2, 2, 2, 1, 2, 3, 4,
833 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
834 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
835 25, 26, 27, 28, 29, 30, 31, 32, 33, 34,
836 35, 36, 37, 38, 39, 40, 41, 42, 43, 44,
495aee44 837 45, 46, 47, 48, 52
726f6388 838};
f73dda09 839
3185942a 840#if YYDEBUG
a0c0a00f 841 /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */
3185942a
JA
842static const yytype_uint16 yyrline[] =
843{
a0c0a00f
CR
844 0, 386, 386, 397, 406, 421, 431, 433, 437, 443,
845 449, 455, 461, 467, 473, 479, 485, 491, 497, 503,
846 509, 515, 521, 527, 534, 541, 548, 555, 562, 569,
847 575, 581, 587, 593, 599, 605, 611, 617, 623, 629,
848 635, 641, 647, 653, 659, 665, 671, 677, 683, 689,
849 695, 701, 709, 711, 713, 717, 721, 732, 734, 738,
850 740, 742, 758, 760, 764, 766, 768, 770, 772, 774,
851 776, 778, 780, 782, 784, 788, 793, 798, 803, 808,
852 813, 818, 823, 830, 835, 840, 845, 852, 857, 862,
853 867, 872, 877, 884, 889, 894, 901, 904, 907, 911,
854 913, 944, 951, 956, 973, 978, 995, 1002, 1004, 1006,
855 1011, 1015, 1019, 1023, 1025, 1027, 1031, 1032, 1036, 1038,
856 1040, 1042, 1046, 1048, 1050, 1052, 1054, 1056, 1060, 1062,
857 1071, 1079, 1080, 1086, 1087, 1094, 1098, 1100, 1102, 1109,
858 1111, 1113, 1117, 1118, 1121, 1123, 1125, 1129, 1130, 1139,
859 1152, 1168, 1183, 1185, 1187, 1194, 1197, 1201, 1203, 1209,
860 1215, 1234, 1256, 1258, 1281, 1285, 1287, 1289
726f6388 861};
3185942a 862#endif
f73dda09 863
a0c0a00f 864#if YYDEBUG || YYERROR_VERBOSE || 0
3185942a
JA
865/* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
866 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
867static const char *const yytname[] =
868{
869 "$end", "error", "$undefined", "IF", "THEN", "ELSE", "ELIF", "FI",
870 "CASE", "ESAC", "FOR", "SELECT", "WHILE", "UNTIL", "DO", "DONE",
871 "FUNCTION", "COPROC", "COND_START", "COND_END", "COND_ERROR", "IN",
495aee44
CR
872 "BANG", "TIME", "TIMEOPT", "TIMEIGN", "WORD", "ASSIGNMENT_WORD",
873 "REDIR_WORD", "NUMBER", "ARITH_CMD", "ARITH_FOR_EXPRS", "COND_CMD",
874 "AND_AND", "OR_OR", "GREATER_GREATER", "LESS_LESS", "LESS_AND",
875 "LESS_LESS_LESS", "GREATER_AND", "SEMI_SEMI", "SEMI_AND",
876 "SEMI_SEMI_AND", "LESS_LESS_MINUS", "AND_GREATER", "AND_GREATER_GREATER",
877 "LESS_GREATER", "GREATER_BAR", "BAR_AND", "'&'", "';'", "'\\n'",
878 "yacc_EOF", "'|'", "'>'", "'<'", "'-'", "'{'", "'}'", "'('", "')'",
879 "$accept", "inputunit", "word_list", "redirection",
880 "simple_command_element", "redirection_list", "simple_command",
881 "command", "shell_command", "for_command", "arith_for_command",
882 "select_command", "case_command", "function_def", "function_body",
883 "subshell", "coproc", "if_command", "group_command", "arith_command",
884 "cond_command", "elif_clause", "case_clause", "pattern_list",
885 "case_clause_sequence", "pattern", "list", "compound_list", "list0",
886 "list1", "simple_list_terminator", "list_terminator", "newline_list",
887 "simple_list", "simple_list1", "pipeline_command", "pipeline",
a0c0a00f 888 "timespec", YY_NULLPTR
726f6388 889};
3185942a 890#endif
f73dda09 891
3185942a 892# ifdef YYPRINT
a0c0a00f
CR
893/* YYTOKNUM[NUM] -- (External) token number corresponding to the
894 (internal) symbol number NUM (which must be that of a token). */
3185942a
JA
895static const yytype_uint16 yytoknum[] =
896{
897 0, 256, 257, 258, 259, 260, 261, 262, 263, 264,
898 265, 266, 267, 268, 269, 270, 271, 272, 273, 274,
899 275, 276, 277, 278, 279, 280, 281, 282, 283, 284,
900 285, 286, 287, 288, 289, 290, 291, 292, 293, 294,
495aee44
CR
901 295, 296, 297, 298, 299, 300, 301, 302, 303, 38,
902 59, 10, 304, 124, 62, 60, 45, 123, 125, 40,
903 41
3185942a
JA
904};
905# endif
906
a0c0a00f 907#define YYPACT_NINF -205
f73dda09 908
a0c0a00f
CR
909#define yypact_value_is_default(Yystate) \
910 (!!((Yystate) == (-205)))
911
912#define YYTABLE_NINF -1
913
914#define yytable_value_is_error(Yytable_value) \
915 0
916
917 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
918 STATE-NUM. */
919static const yytype_int16 yypact[] =
3185942a 920{
a0c0a00f
CR
921 308, -28, -205, 6, -1, 37, -205, -205, 57, 558,
922 18, 358, 54, 45, -205, 251, 583, -205, 102, 104,
923 35, 107, 80, 112, 127, 140, 146, 147, -205, -205,
924 153, 154, -205, -205, 188, -205, -205, 196, -205, 219,
925 -205, -205, -205, -205, -205, -205, -205, -205, -205, -205,
926 -205, 17, 23, -205, -19, 358, -205, -205, 185, 408,
927 -205, 144, 51, 166, 189, 207, 133, 28, 196, 219,
928 211, -205, -205, -205, -205, -205, 201, 184, 220, 226,
929 81, 227, 126, 233, 234, 241, 242, 245, 246, 249,
930 142, 255, 148, 256, 257, 259, 266, 267, -205, -205,
931 -205, -205, -205, -205, -205, -205, -205, -205, -205, -205,
932 -205, -205, -205, -205, 243, 240, -205, -205, -205, -205,
933 219, -205, -205, -205, -205, -205, 458, 458, -205, -205,
934 -205, -205, -205, -205, -205, 299, -205, 68, -205, 61,
935 -205, -205, -205, -205, 72, -205, -205, 244, 41, 219,
936 219, -205, -205, -205, -205, -205, -205, -205, -205, -205,
937 -205, -205, -205, -205, -205, -205, -205, -205, -205, -205,
938 -205, -205, -205, -205, -205, -205, -205, -205, -205, -205,
939 -205, -205, -205, -205, -205, 408, 408, 63, 63, 508,
940 508, 179, -205, -205, -205, -205, -205, -205, 60, -205,
941 155, -205, 287, 252, 74, 108, -205, 286, -205, 300,
942 302, -205, 219, -205, 219, 41, -205, -205, -19, -19,
943 -205, -205, -205, 307, 408, 408, 408, 408, 408, 313,
944 159, -205, -4, -205, -205, 312, -205, 161, -205, 265,
945 -205, -205, -205, -205, -205, -205, 314, 408, 161, 270,
946 -205, -205, 41, 219, -205, 332, 336, -205, -205, -205,
947 87, 87, 87, -205, -205, -205, -205, 178, 11, -205,
948 -205, 315, -43, 327, 298, -205, -205, -205, 110, -205,
949 342, 306, 343, 319, -205, 299, -205, -205, -205, -205,
950 -205, -205, -205, -205, -205, -32, 346, -205, -205, -205,
951 113, -205, -205, -205, -205, -205, -205, 118, 137, -205,
952 -205, -205, 408, -205, -205, 363, 321, -205, -205, -205,
953 -205, -205, 408, 367, 325, -205, -205, 374, 333, -205,
954 -205, -205, -205, -205
3185942a 955};
f73dda09 956
a0c0a00f
CR
957 /* YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM.
958 Performed when YYTABLE does not specify something else to do. Zero
959 means the default is an error. */
3185942a
JA
960static const yytype_uint8 yydefact[] =
961{
0001803f 962 0, 0, 147, 0, 0, 0, 147, 147, 0, 0,
495aee44 963 0, 0, 165, 52, 53, 0, 0, 111, 0, 0,
0001803f 964 0, 0, 0, 0, 0, 0, 0, 0, 3, 5,
495aee44 965 0, 0, 147, 147, 0, 54, 57, 59, 164, 60,
0001803f
CR
966 64, 74, 68, 65, 62, 70, 63, 69, 71, 72,
967 73, 0, 149, 156, 157, 0, 4, 131, 0, 0,
968 147, 147, 0, 147, 0, 0, 147, 52, 106, 102,
495aee44 969 0, 145, 144, 146, 161, 158, 166, 0, 0, 0,
0001803f 970 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
495aee44
CR
971 0, 0, 0, 0, 0, 0, 0, 0, 14, 23,
972 38, 32, 47, 29, 41, 35, 44, 26, 50, 51,
973 20, 17, 8, 9, 0, 0, 1, 52, 58, 55,
974 61, 142, 143, 2, 147, 147, 150, 151, 147, 147,
975 160, 159, 147, 148, 130, 132, 141, 0, 147, 0,
976 147, 147, 147, 147, 0, 147, 147, 0, 0, 104,
977 103, 112, 167, 147, 16, 25, 40, 34, 49, 31,
978 43, 37, 46, 28, 22, 19, 12, 13, 15, 24,
979 39, 33, 48, 30, 42, 36, 45, 27, 21, 18,
980 10, 11, 110, 101, 56, 0, 0, 154, 155, 0,
981 0, 0, 147, 147, 147, 147, 147, 147, 0, 147,
982 0, 147, 0, 0, 0, 0, 147, 0, 147, 0,
a0c0a00f
CR
983 0, 147, 99, 98, 105, 0, 152, 153, 163, 162,
984 147, 147, 107, 0, 0, 0, 134, 135, 133, 0,
985 116, 147, 0, 147, 147, 0, 6, 0, 147, 0,
986 85, 86, 147, 147, 147, 147, 0, 0, 0, 0,
987 66, 67, 0, 100, 96, 0, 0, 109, 136, 137,
988 138, 139, 140, 95, 122, 124, 126, 117, 0, 93,
989 128, 0, 0, 0, 0, 75, 7, 147, 0, 76,
990 0, 0, 0, 0, 87, 0, 147, 88, 97, 108,
991 147, 123, 125, 127, 94, 0, 0, 147, 77, 78,
992 0, 147, 147, 83, 84, 89, 90, 0, 113, 147,
993 129, 118, 119, 147, 147, 0, 0, 147, 147, 147,
994 115, 120, 121, 0, 0, 81, 82, 0, 0, 114,
995 79, 80, 91, 92
726f6388 996};
f73dda09 997
a0c0a00f
CR
998 /* YYPGOTO[NTERM-NUM]. */
999static const yytype_int16 yypgoto[] =
3185942a 1000{
a0c0a00f
CR
1001 -205, -205, 183, -36, -23, -50, 364, -205, -7, -205,
1002 -205, -205, -205, -205, -204, -205, -205, -205, -205, -205,
1003 -205, 84, -205, 167, -205, 128, -202, -6, -205, 52,
1004 -205, -46, -48, -205, -119, 24, -33, -205
3185942a 1005};
f73dda09 1006
a0c0a00f
CR
1007 /* YYDEFGOTO[NTERM-NUM]. */
1008static const yytype_int16 yydefgoto[] =
3185942a 1009{
a0c0a00f
CR
1010 -1, 34, 237, 35, 36, 120, 37, 38, 39, 40,
1011 41, 42, 43, 44, 213, 45, 46, 47, 48, 49,
1012 50, 223, 229, 230, 231, 272, 57, 58, 134, 135,
1013 123, 74, 59, 51, 52, 136, 54, 55
3185942a 1014};
f73dda09 1015
a0c0a00f
CR
1016 /* YYTABLE[YYPACT[STATE-NUM]] -- What to do in state STATE-NUM. If
1017 positive, shift that token. If negative, reduce the rule whose
1018 number is the opposite. If YYTABLE_NINF, syntax error. */
3185942a
JA
1019static const yytype_uint16 yytable[] =
1020{
a0c0a00f
CR
1021 64, 65, 69, 119, 246, 269, 249, 187, 188, 130,
1022 296, 254, 137, 139, 118, 144, 142, 297, 148, 150,
1023 294, 296, 270, 56, 53, 61, 114, 115, 309, 128,
1024 62, 2, 60, 119, 129, 75, 3, 270, 4, 5,
1025 6, 7, 282, 283, 2, 118, 10, 133, 288, 3,
1026 70, 4, 5, 6, 7, 271, 124, 125, 17, 10,
1027 149, 100, 133, 63, 101, 140, 216, 217, 121, 122,
1028 271, 17, 126, 127, 233, 199, 185, 186, 76, 131,
1029 189, 190, 200, 66, 184, 32, 206, 33, 242, 197,
1030 198, 102, 133, 207, 204, 205, 124, 125, 32, 214,
1031 33, 71, 72, 73, 77, 215, 104, 156, 141, 105,
1032 157, 133, 133, 119, 184, 327, 328, 234, 201, 133,
1033 192, 193, 244, 133, 301, 133, 191, 313, 98, 208,
1034 99, 243, 317, 103, 202, 203, 106, 158, 107, 209,
1035 210, 212, 319, 221, 224, 225, 226, 227, 228, 232,
1036 53, 53, 160, 108, 238, 161, 218, 219, 247, 133,
1037 247, 133, 253, 252, 133, 245, 109, 302, 170, 133,
1038 314, 171, 110, 111, 174, 318, 119, 175, 184, 112,
1039 113, 236, 162, 268, 220, 221, 222, 276, 116, 132,
1040 278, 277, 147, 235, 138, 239, 247, 247, 172, 264,
1041 265, 266, 286, 145, 176, 71, 72, 73, 212, 53,
1042 53, 71, 72, 73, 255, 256, 143, 184, 291, 292,
1043 293, 146, 117, 14, 15, 16, 152, 273, 274, 300,
1044 151, 18, 19, 20, 21, 22, 280, 281, 307, 23,
1045 24, 25, 26, 27, 153, 212, 154, 15, 16, 312,
1046 30, 31, 155, 159, 18, 19, 20, 21, 22, 163,
1047 164, 322, 23, 24, 25, 26, 27, 165, 166, 247,
1048 247, 167, 168, 30, 31, 169, 258, 259, 260, 261,
1049 262, 173, 177, 178, 308, 179, 78, 79, 80, 81,
1050 82, 311, 180, 181, 83, 315, 316, 84, 85, 285,
1051 183, 182, 240, 321, 211, 86, 87, 323, 324, 1,
1052 241, 2, 236, 329, 257, 250, 3, 251, 4, 5,
1053 6, 7, 263, 279, 8, 9, 10, 275, 287, 284,
1054 11, 12, 192, 193, 13, 14, 15, 16, 17, 289,
1055 290, 270, 298, 18, 19, 20, 21, 22, 194, 195,
1056 196, 23, 24, 25, 26, 27, 299, 303, 305, 28,
1057 29, 2, 30, 31, 304, 32, 3, 33, 4, 5,
1058 6, 7, 310, 68, 8, 9, 10, 306, 325, 326,
1059 11, 12, 330, 331, 13, 14, 15, 16, 17, 332,
1060 248, 333, 320, 18, 19, 20, 21, 22, 267, 295,
1061 0, 23, 24, 25, 26, 27, 0, 0, 71, 72,
1062 73, 2, 30, 31, 0, 32, 3, 33, 4, 5,
1063 6, 7, 0, 0, 8, 9, 10, 0, 0, 0,
1064 11, 12, 0, 0, 13, 14, 15, 16, 17, 0,
1065 0, 0, 0, 18, 19, 20, 21, 22, 0, 0,
1066 0, 23, 24, 25, 26, 27, 0, 0, 0, 133,
1067 0, 2, 30, 31, 0, 32, 3, 33, 4, 5,
1068 6, 7, 0, 0, 8, 9, 10, 0, 0, 0,
1069 11, 12, 0, 0, 13, 14, 15, 16, 17, 0,
1070 0, 0, 0, 18, 19, 20, 21, 22, 0, 0,
1071 0, 23, 24, 25, 26, 27, 0, 0, 0, 0,
1072 0, 2, 30, 31, 0, 32, 3, 33, 4, 5,
1073 6, 7, 0, 0, 8, 9, 10, 0, 0, 0,
1074 0, 0, 0, 0, 13, 14, 15, 16, 17, 0,
1075 0, 0, 0, 18, 19, 20, 21, 22, 0, 0,
1076 0, 23, 24, 25, 26, 27, 0, 0, 0, 133,
1077 0, 2, 30, 31, 0, 32, 3, 33, 4, 5,
1078 6, 7, 0, 0, 0, 0, 10, 0, 0, 0,
1079 0, 0, 0, 0, 67, 14, 15, 16, 17, 0,
495aee44 1080 0, 0, 0, 18, 19, 20, 21, 22, 0, 0,
a0c0a00f
CR
1081 0, 23, 24, 25, 26, 27, 0, 0, 0, 0,
1082 0, 0, 30, 31, 0, 32, 0, 33, 88, 89,
1083 90, 91, 92, 0, 0, 0, 93, 0, 0, 94,
1084 95, 0, 0, 0, 0, 0, 0, 96, 97
3185942a 1085};
f73dda09 1086
3185942a
JA
1087static const yytype_int16 yycheck[] =
1088{
a0c0a00f
CR
1089 6, 7, 9, 39, 206, 9, 208, 126, 127, 55,
1090 53, 215, 60, 61, 37, 63, 62, 60, 66, 69,
1091 9, 53, 26, 51, 0, 26, 32, 33, 60, 48,
1092 31, 3, 26, 69, 53, 11, 8, 26, 10, 11,
1093 12, 13, 244, 245, 3, 68, 18, 51, 252, 8,
1094 32, 10, 11, 12, 13, 59, 33, 34, 30, 18,
1095 67, 26, 51, 26, 29, 14, 185, 186, 51, 52,
1096 59, 30, 49, 50, 14, 14, 124, 125, 24, 55,
1097 128, 129, 21, 26, 120, 57, 14, 59, 14, 21,
1098 138, 56, 51, 21, 142, 143, 33, 34, 57, 149,
1099 59, 50, 51, 52, 59, 153, 26, 26, 57, 29,
1100 29, 51, 51, 149, 150, 317, 318, 57, 57, 51,
1101 33, 34, 14, 51, 14, 51, 132, 14, 26, 57,
1102 26, 57, 14, 26, 140, 141, 56, 56, 26, 145,
1103 146, 148, 5, 6, 192, 193, 194, 195, 196, 197,
1104 126, 127, 26, 26, 200, 29, 189, 190, 206, 51,
1105 208, 51, 212, 211, 51, 57, 26, 57, 26, 51,
1106 57, 29, 26, 26, 26, 57, 212, 29, 214, 26,
1107 26, 26, 56, 231, 5, 6, 7, 26, 0, 4,
1108 238, 237, 59, 199, 50, 201, 244, 245, 56, 40,
1109 41, 42, 248, 14, 56, 50, 51, 52, 215, 185,
1110 186, 50, 51, 52, 220, 221, 50, 253, 40, 41,
1111 42, 14, 26, 27, 28, 29, 25, 233, 234, 277,
1112 19, 35, 36, 37, 38, 39, 242, 243, 286, 43,
1113 44, 45, 46, 47, 60, 252, 26, 28, 29, 297,
1114 54, 55, 26, 26, 35, 36, 37, 38, 39, 26,
1115 26, 309, 43, 44, 45, 46, 47, 26, 26, 317,
1116 318, 26, 26, 54, 55, 26, 224, 225, 226, 227,
1117 228, 26, 26, 26, 290, 26, 35, 36, 37, 38,
1118 39, 297, 26, 26, 43, 301, 302, 46, 47, 247,
1119 60, 58, 15, 309, 60, 54, 55, 313, 314, 1,
1120 58, 3, 26, 319, 7, 15, 8, 15, 10, 11,
1121 12, 13, 9, 58, 16, 17, 18, 15, 58, 15,
1122 22, 23, 33, 34, 26, 27, 28, 29, 30, 7,
1123 4, 26, 15, 35, 36, 37, 38, 39, 49, 50,
1124 51, 43, 44, 45, 46, 47, 58, 15, 15, 51,
1125 52, 3, 54, 55, 58, 57, 8, 59, 10, 11,
1126 12, 13, 26, 9, 16, 17, 18, 58, 15, 58,
1127 22, 23, 15, 58, 26, 27, 28, 29, 30, 15,
1128 207, 58, 308, 35, 36, 37, 38, 39, 231, 271,
1129 -1, 43, 44, 45, 46, 47, -1, -1, 50, 51,
1130 52, 3, 54, 55, -1, 57, 8, 59, 10, 11,
1131 12, 13, -1, -1, 16, 17, 18, -1, -1, -1,
1132 22, 23, -1, -1, 26, 27, 28, 29, 30, -1,
495aee44 1133 -1, -1, -1, 35, 36, 37, 38, 39, -1, -1,
a0c0a00f
CR
1134 -1, 43, 44, 45, 46, 47, -1, -1, -1, 51,
1135 -1, 3, 54, 55, -1, 57, 8, 59, 10, 11,
1136 12, 13, -1, -1, 16, 17, 18, -1, -1, -1,
1137 22, 23, -1, -1, 26, 27, 28, 29, 30, -1,
1138 -1, -1, -1, 35, 36, 37, 38, 39, -1, -1,
1139 -1, 43, 44, 45, 46, 47, -1, -1, -1, -1,
1140 -1, 3, 54, 55, -1, 57, 8, 59, 10, 11,
1141 12, 13, -1, -1, 16, 17, 18, -1, -1, -1,
1142 -1, -1, -1, -1, 26, 27, 28, 29, 30, -1,
1143 -1, -1, -1, 35, 36, 37, 38, 39, -1, -1,
1144 -1, 43, 44, 45, 46, 47, -1, -1, -1, 51,
1145 -1, 3, 54, 55, -1, 57, 8, 59, 10, 11,
1146 12, 13, -1, -1, -1, -1, 18, -1, -1, -1,
1147 -1, -1, -1, -1, 26, 27, 28, 29, 30, -1,
1148 -1, -1, -1, 35, 36, 37, 38, 39, -1, -1,
1149 -1, 43, 44, 45, 46, 47, -1, -1, -1, -1,
1150 -1, -1, 54, 55, -1, 57, -1, 59, 35, 36,
1151 37, 38, 39, -1, -1, -1, 43, -1, -1, 46,
1152 47, -1, -1, -1, -1, -1, -1, 54, 55
3185942a 1153};
f73dda09 1154
a0c0a00f
CR
1155 /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
1156 symbol of state STATE-NUM. */
3185942a
JA
1157static const yytype_uint8 yystos[] =
1158{
1159 0, 1, 3, 8, 10, 11, 12, 13, 16, 17,
495aee44
CR
1160 18, 22, 23, 26, 27, 28, 29, 30, 35, 36,
1161 37, 38, 39, 43, 44, 45, 46, 47, 51, 52,
1162 54, 55, 57, 59, 62, 64, 65, 67, 68, 69,
1163 70, 71, 72, 73, 74, 76, 77, 78, 79, 80,
1164 81, 94, 95, 96, 97, 98, 51, 87, 88, 93,
1165 26, 26, 31, 26, 88, 88, 26, 26, 67, 69,
1166 32, 50, 51, 52, 92, 96, 24, 59, 35, 36,
1167 37, 38, 39, 43, 46, 47, 54, 55, 35, 36,
1168 37, 38, 39, 43, 46, 47, 54, 55, 26, 26,
1169 26, 29, 56, 26, 26, 29, 56, 26, 26, 26,
1170 26, 26, 26, 26, 88, 88, 0, 26, 65, 64,
1171 66, 51, 52, 91, 33, 34, 49, 50, 48, 53,
1172 92, 96, 4, 51, 89, 90, 96, 93, 50, 93,
1173 14, 57, 92, 50, 93, 14, 14, 59, 93, 69,
1174 66, 19, 25, 60, 26, 26, 26, 29, 56, 26,
1175 26, 29, 56, 26, 26, 26, 26, 26, 26, 26,
1176 26, 29, 56, 26, 26, 29, 56, 26, 26, 26,
1177 26, 26, 58, 60, 64, 93, 93, 95, 95, 93,
1178 93, 88, 33, 34, 49, 50, 51, 21, 93, 14,
1179 21, 57, 88, 88, 93, 93, 14, 21, 57, 88,
a0c0a00f
CR
1180 88, 60, 69, 75, 66, 93, 95, 95, 97, 97,
1181 5, 6, 7, 82, 93, 93, 93, 93, 93, 83,
1182 84, 85, 93, 14, 57, 88, 26, 63, 92, 88,
1183 15, 58, 14, 57, 14, 57, 87, 93, 63, 87,
1184 15, 15, 93, 66, 75, 88, 88, 7, 90, 90,
1185 90, 90, 90, 9, 40, 41, 42, 84, 93, 9,
1186 26, 59, 86, 88, 88, 15, 26, 92, 93, 58,
1187 88, 88, 87, 87, 15, 90, 92, 58, 75, 7,
1188 4, 40, 41, 42, 9, 86, 53, 60, 15, 58,
1189 93, 14, 57, 15, 58, 15, 58, 93, 88, 60,
1190 26, 88, 93, 14, 57, 88, 88, 14, 57, 5,
1191 82, 88, 93, 88, 88, 15, 58, 87, 87, 88,
1192 15, 58, 15, 58
3185942a 1193};
b80f6443 1194
a0c0a00f
CR
1195 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
1196static const yytype_uint8 yyr1[] =
1197{
1198 0, 61, 62, 62, 62, 62, 63, 63, 64, 64,
1199 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
1200 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
1201 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
1202 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
1203 64, 64, 65, 65, 65, 66, 66, 67, 67, 68,
1204 68, 68, 68, 68, 69, 69, 69, 69, 69, 69,
1205 69, 69, 69, 69, 69, 70, 70, 70, 70, 70,
1206 70, 70, 70, 71, 71, 71, 71, 72, 72, 72,
1207 72, 72, 72, 73, 73, 73, 74, 74, 74, 75,
1208 75, 76, 77, 77, 77, 77, 77, 78, 78, 78,
1209 79, 80, 81, 82, 82, 82, 83, 83, 84, 84,
1210 84, 84, 85, 85, 85, 85, 85, 85, 86, 86,
1211 87, 88, 88, 89, 89, 89, 90, 90, 90, 90,
1212 90, 90, 91, 91, 92, 92, 92, 93, 93, 94,
1213 94, 94, 95, 95, 95, 95, 95, 96, 96, 96,
1214 96, 96, 97, 97, 97, 98, 98, 98
1215};
1216
1217 /* YYR2[YYN] -- Number of symbols on the right hand side of rule YYN. */
1218static const yytype_uint8 yyr2[] =
1219{
1220 0, 2, 2, 1, 2, 1, 1, 2, 2, 2,
1221 3, 3, 3, 3, 2, 3, 3, 2, 3, 3,
1222 2, 3, 3, 2, 3, 3, 2, 3, 3, 2,
1223 3, 3, 2, 3, 3, 2, 3, 3, 2, 3,
1224 3, 2, 3, 3, 2, 3, 3, 2, 3, 3,
1225 2, 2, 1, 1, 1, 1, 2, 1, 2, 1,
1226 1, 2, 1, 1, 1, 1, 5, 5, 1, 1,
1227 1, 1, 1, 1, 1, 6, 6, 7, 7, 10,
1228 10, 9, 9, 7, 7, 5, 5, 6, 6, 7,
1229 7, 10, 10, 6, 7, 6, 5, 6, 4, 1,
1230 2, 3, 2, 3, 3, 4, 2, 5, 7, 6,
1231 3, 1, 3, 4, 6, 5, 1, 2, 4, 4,
1232 5, 5, 2, 3, 2, 3, 2, 3, 1, 3,
1233 2, 1, 2, 3, 3, 3, 4, 4, 4, 4,
1234 4, 1, 1, 1, 1, 1, 1, 0, 2, 1,
1235 2, 2, 4, 4, 3, 3, 1, 1, 2, 2,
1236 2, 2, 4, 4, 1, 1, 2, 3
1237};
3185942a 1238
3185942a 1239
a0c0a00f
CR
1240#define yyerrok (yyerrstatus = 0)
1241#define yyclearin (yychar = YYEMPTY)
1242#define YYEMPTY (-2)
1243#define YYEOF 0
3185942a 1244
a0c0a00f
CR
1245#define YYACCEPT goto yyacceptlab
1246#define YYABORT goto yyabortlab
1247#define YYERROR goto yyerrorlab
3185942a 1248
3185942a 1249
f73dda09 1250#define YYRECOVERING() (!!yyerrstatus)
3185942a 1251
a0c0a00f
CR
1252#define YYBACKUP(Token, Value) \
1253do \
1254 if (yychar == YYEMPTY) \
1255 { \
1256 yychar = (Token); \
1257 yylval = (Value); \
1258 YYPOPSTACK (yylen); \
1259 yystate = *yyssp; \
1260 goto yybackup; \
1261 } \
1262 else \
1263 { \
3185942a 1264 yyerror (YY_("syntax error: cannot back up")); \
a0c0a00f
CR
1265 YYERROR; \
1266 } \
1267while (0)
f73dda09 1268
a0c0a00f
CR
1269/* Error token number */
1270#define YYTERROR 1
1271#define YYERRCODE 256
3185942a 1272
3185942a 1273
3185942a
JA
1274
1275/* Enable debugging if requested. */
1276#if YYDEBUG
1277
1278# ifndef YYFPRINTF
1279# include <stdio.h> /* INFRINGES ON USER NAME SPACE */
1280# define YYFPRINTF fprintf
1281# endif
1282
a0c0a00f
CR
1283# define YYDPRINTF(Args) \
1284do { \
1285 if (yydebug) \
1286 YYFPRINTF Args; \
1287} while (0)
1288
1289/* This macro is provided for backward compatibility. */
1290#ifndef YY_LOCATION_PRINT
1291# define YY_LOCATION_PRINT(File, Loc) ((void) 0)
1292#endif
3185942a 1293
3185942a 1294
a0c0a00f
CR
1295# define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
1296do { \
1297 if (yydebug) \
1298 { \
1299 YYFPRINTF (stderr, "%s ", Title); \
1300 yy_symbol_print (stderr, \
1301 Type, Value); \
1302 YYFPRINTF (stderr, "\n"); \
1303 } \
1304} while (0)
3185942a 1305
3185942a 1306
a0c0a00f
CR
1307/*----------------------------------------.
1308| Print this symbol's value on YYOUTPUT. |
1309`----------------------------------------*/
1310
3185942a 1311static void
a0c0a00f 1312yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep)
3185942a 1313{
a0c0a00f
CR
1314 FILE *yyo = yyoutput;
1315 YYUSE (yyo);
3185942a
JA
1316 if (!yyvaluep)
1317 return;
1318# ifdef YYPRINT
1319 if (yytype < YYNTOKENS)
1320 YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep);
3185942a 1321# endif
a0c0a00f 1322 YYUSE (yytype);
3185942a
JA
1323}
1324
1325
1326/*--------------------------------.
1327| Print this symbol on YYOUTPUT. |
1328`--------------------------------*/
b80f6443 1329
3185942a
JA
1330static void
1331yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep)
3185942a 1332{
a0c0a00f
CR
1333 YYFPRINTF (yyoutput, "%s %s (",
1334 yytype < YYNTOKENS ? "token" : "nterm", yytname[yytype]);
726f6388 1335
3185942a
JA
1336 yy_symbol_value_print (yyoutput, yytype, yyvaluep);
1337 YYFPRINTF (yyoutput, ")");
1338}
726f6388 1339
3185942a
JA
1340/*------------------------------------------------------------------.
1341| yy_stack_print -- Print the state stack from its BOTTOM up to its |
1342| TOP (included). |
1343`------------------------------------------------------------------*/
b80f6443 1344
3185942a 1345static void
a0c0a00f 1346yy_stack_print (yytype_int16 *yybottom, yytype_int16 *yytop)
3185942a
JA
1347{
1348 YYFPRINTF (stderr, "Stack now");
a0c0a00f
CR
1349 for (; yybottom <= yytop; yybottom++)
1350 {
1351 int yybot = *yybottom;
1352 YYFPRINTF (stderr, " %d", yybot);
1353 }
3185942a
JA
1354 YYFPRINTF (stderr, "\n");
1355}
726f6388 1356
a0c0a00f
CR
1357# define YY_STACK_PRINT(Bottom, Top) \
1358do { \
1359 if (yydebug) \
1360 yy_stack_print ((Bottom), (Top)); \
1361} while (0)
726f6388 1362
3185942a
JA
1363
1364/*------------------------------------------------.
1365| Report that the YYRULE is going to be reduced. |
1366`------------------------------------------------*/
1367
3185942a 1368static void
a0c0a00f 1369yy_reduce_print (yytype_int16 *yyssp, YYSTYPE *yyvsp, int yyrule)
3185942a 1370{
a0c0a00f 1371 unsigned long int yylno = yyrline[yyrule];
3185942a
JA
1372 int yynrhs = yyr2[yyrule];
1373 int yyi;
3185942a 1374 YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n",
a0c0a00f 1375 yyrule - 1, yylno);
3185942a
JA
1376 /* The symbols being reduced. */
1377 for (yyi = 0; yyi < yynrhs; yyi++)
1378 {
a0c0a00f
CR
1379 YYFPRINTF (stderr, " $%d = ", yyi + 1);
1380 yy_symbol_print (stderr,
1381 yystos[yyssp[yyi + 1 - yynrhs]],
1382 &(yyvsp[(yyi + 1) - (yynrhs)])
1383 );
1384 YYFPRINTF (stderr, "\n");
3185942a
JA
1385 }
1386}
1387
a0c0a00f
CR
1388# define YY_REDUCE_PRINT(Rule) \
1389do { \
1390 if (yydebug) \
1391 yy_reduce_print (yyssp, yyvsp, Rule); \
1392} while (0)
b80f6443 1393
3185942a
JA
1394/* Nonzero means print parse trace. It is left uninitialized so that
1395 multiple parsers can coexist. */
1396int yydebug;
1397#else /* !YYDEBUG */
1398# define YYDPRINTF(Args)
1399# define YY_SYMBOL_PRINT(Title, Type, Value, Location)
1400# define YY_STACK_PRINT(Bottom, Top)
1401# define YY_REDUCE_PRINT(Rule)
1402#endif /* !YYDEBUG */
726f6388 1403
3185942a
JA
1404
1405/* YYINITDEPTH -- initial size of the parser's stacks. */
a0c0a00f 1406#ifndef YYINITDEPTH
3185942a 1407# define YYINITDEPTH 200
f73dda09 1408#endif
726f6388 1409
3185942a
JA
1410/* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
1411 if the built-in stack extension method is used).
726f6388 1412
3185942a
JA
1413 Do not make this value too large; the results are undefined if
1414 YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH)
1415 evaluated with infinite-precision integer arithmetic. */
726f6388 1416
f73dda09 1417#ifndef YYMAXDEPTH
3185942a 1418# define YYMAXDEPTH 10000
f73dda09 1419#endif
3185942a 1420
3185942a
JA
1421
1422#if YYERROR_VERBOSE
1423
1424# ifndef yystrlen
1425# if defined __GLIBC__ && defined _STRING_H
1426# define yystrlen strlen
1427# else
1428/* Return the length of YYSTR. */
3185942a
JA
1429static YYSIZE_T
1430yystrlen (const char *yystr)
3185942a
JA
1431{
1432 YYSIZE_T yylen;
1433 for (yylen = 0; yystr[yylen]; yylen++)
1434 continue;
1435 return yylen;
1436}
1437# endif
1438# endif
1439
1440# ifndef yystpcpy
1441# if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
1442# define yystpcpy stpcpy
1443# else
1444/* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
1445 YYDEST. */
3185942a
JA
1446static char *
1447yystpcpy (char *yydest, const char *yysrc)
726f6388 1448{
3185942a
JA
1449 char *yyd = yydest;
1450 const char *yys = yysrc;
1451
1452 while ((*yyd++ = *yys++) != '\0')
1453 continue;
1454
1455 return yyd - 1;
1456}
1457# endif
1458# endif
1459
1460# ifndef yytnamerr
1461/* Copy to YYRES the contents of YYSTR after stripping away unnecessary
1462 quotes and backslashes, so that it's suitable for yyerror. The
1463 heuristic is that double-quoting is unnecessary unless the string
1464 contains an apostrophe, a comma, or backslash (other than
1465 backslash-backslash). YYSTR is taken from yytname. If YYRES is
1466 null, do not copy; instead, return the length of what the result
1467 would have been. */
1468static YYSIZE_T
1469yytnamerr (char *yyres, const char *yystr)
1470{
1471 if (*yystr == '"')
1472 {
1473 YYSIZE_T yyn = 0;
1474 char const *yyp = yystr;
1475
1476 for (;;)
a0c0a00f
CR
1477 switch (*++yyp)
1478 {
1479 case '\'':
1480 case ',':
1481 goto do_not_strip_quotes;
1482
1483 case '\\':
1484 if (*++yyp != '\\')
1485 goto do_not_strip_quotes;
1486 /* Fall through. */
1487 default:
1488 if (yyres)
1489 yyres[yyn] = *yyp;
1490 yyn++;
1491 break;
1492
1493 case '"':
1494 if (yyres)
1495 yyres[yyn] = '\0';
1496 return yyn;
1497 }
3185942a
JA
1498 do_not_strip_quotes: ;
1499 }
f73dda09 1500
3185942a
JA
1501 if (! yyres)
1502 return yystrlen (yystr);
1503
1504 return yystpcpy (yyres, yystr) - yyres;
1505}
1506# endif
1507
a0c0a00f
CR
1508/* Copy into *YYMSG, which is of size *YYMSG_ALLOC, an error message
1509 about the unexpected token YYTOKEN for the state stack whose top is
1510 YYSSP.
3185942a 1511
a0c0a00f
CR
1512 Return 0 if *YYMSG was successfully written. Return 1 if *YYMSG is
1513 not large enough to hold the message. In that case, also set
1514 *YYMSG_ALLOC to the required number of bytes. Return 2 if the
1515 required number of bytes is too large to store. */
1516static int
1517yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg,
1518 yytype_int16 *yyssp, int yytoken)
1519{
1520 YYSIZE_T yysize0 = yytnamerr (YY_NULLPTR, yytname[yytoken]);
1521 YYSIZE_T yysize = yysize0;
1522 enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
1523 /* Internationalized format string. */
1524 const char *yyformat = YY_NULLPTR;
1525 /* Arguments of yyformat. */
1526 char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
1527 /* Number of reported tokens (one for the "unexpected", one per
1528 "expected"). */
1529 int yycount = 0;
1530
1531 /* There are many possibilities here to consider:
1532 - If this state is a consistent state with a default action, then
1533 the only way this function was invoked is if the default action
1534 is an error action. In that case, don't check for expected
1535 tokens because there are none.
1536 - The only way there can be no lookahead present (in yychar) is if
1537 this state is a consistent state with a default action. Thus,
1538 detecting the absence of a lookahead is sufficient to determine
1539 that there is no unexpected or expected token to report. In that
1540 case, just report a simple "syntax error".
1541 - Don't assume there isn't a lookahead just because this state is a
1542 consistent state with a default action. There might have been a
1543 previous inconsistent state, consistent state with a non-default
1544 action, or user semantic action that manipulated yychar.
1545 - Of course, the expected token list depends on states to have
1546 correct lookahead information, and it depends on the parser not
1547 to perform extra reductions after fetching a lookahead from the
1548 scanner and before detecting a syntax error. Thus, state merging
1549 (from LALR or IELR) and default reductions corrupt the expected
1550 token list. However, the list is correct for canonical LR with
1551 one exception: it will still contain any token that will not be
1552 accepted due to an error action in a later state.
1553 */
1554 if (yytoken != YYEMPTY)
1555 {
1556 int yyn = yypact[*yyssp];
1557 yyarg[yycount++] = yytname[yytoken];
1558 if (!yypact_value_is_default (yyn))
1559 {
1560 /* Start YYX at -YYN if negative to avoid negative indexes in
1561 YYCHECK. In other words, skip the first -YYN actions for
1562 this state because they are default actions. */
1563 int yyxbegin = yyn < 0 ? -yyn : 0;
1564 /* Stay within bounds of both yycheck and yytname. */
1565 int yychecklim = YYLAST - yyn + 1;
1566 int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
1567 int yyx;
1568
1569 for (yyx = yyxbegin; yyx < yyxend; ++yyx)
1570 if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR
1571 && !yytable_value_is_error (yytable[yyx + yyn]))
1572 {
1573 if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
1574 {
1575 yycount = 1;
1576 yysize = yysize0;
1577 break;
1578 }
1579 yyarg[yycount++] = yytname[yyx];
1580 {
1581 YYSIZE_T yysize1 = yysize + yytnamerr (YY_NULLPTR, yytname[yyx]);
1582 if (! (yysize <= yysize1
1583 && yysize1 <= YYSTACK_ALLOC_MAXIMUM))
1584 return 2;
1585 yysize = yysize1;
1586 }
1587 }
1588 }
1589 }
3185942a 1590
a0c0a00f
CR
1591 switch (yycount)
1592 {
1593# define YYCASE_(N, S) \
1594 case N: \
1595 yyformat = S; \
1596 break
1597 YYCASE_(0, YY_("syntax error"));
1598 YYCASE_(1, YY_("syntax error, unexpected %s"));
1599 YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s"));
1600 YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s"));
1601 YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s"));
1602 YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"));
1603# undef YYCASE_
1604 }
3185942a 1605
a0c0a00f
CR
1606 {
1607 YYSIZE_T yysize1 = yysize + yystrlen (yyformat);
1608 if (! (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM))
1609 return 2;
1610 yysize = yysize1;
1611 }
3185942a 1612
a0c0a00f
CR
1613 if (*yymsg_alloc < yysize)
1614 {
1615 *yymsg_alloc = 2 * yysize;
1616 if (! (yysize <= *yymsg_alloc
1617 && *yymsg_alloc <= YYSTACK_ALLOC_MAXIMUM))
1618 *yymsg_alloc = YYSTACK_ALLOC_MAXIMUM;
1619 return 1;
3185942a 1620 }
a0c0a00f
CR
1621
1622 /* Avoid sprintf, as that infringes on the user's name space.
1623 Don't have undefined behavior even if the translation
1624 produced a string with the wrong number of "%s"s. */
1625 {
1626 char *yyp = *yymsg;
1627 int yyi = 0;
1628 while ((*yyp = *yyformat) != '\0')
1629 if (*yyp == '%' && yyformat[1] == 's' && yyi < yycount)
1630 {
1631 yyp += yytnamerr (yyp, yyarg[yyi++]);
1632 yyformat += 2;
1633 }
1634 else
1635 {
1636 yyp++;
1637 yyformat++;
1638 }
1639 }
1640 return 0;
726f6388 1641}
3185942a 1642#endif /* YYERROR_VERBOSE */
726f6388 1643
3185942a
JA
1644/*-----------------------------------------------.
1645| Release the memory associated to this symbol. |
1646`-----------------------------------------------*/
726f6388 1647
3185942a
JA
1648static void
1649yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep)
7117c2d2 1650{
3185942a 1651 YYUSE (yyvaluep);
3185942a
JA
1652 if (!yymsg)
1653 yymsg = "Deleting";
1654 YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
b80f6443 1655
a0c0a00f
CR
1656 YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
1657 YYUSE (yytype);
1658 YY_IGNORE_MAYBE_UNINITIALIZED_END
3185942a 1659}
f73dda09 1660
3185942a 1661
726f6388 1662
726f6388 1663
a0c0a00f 1664/* The lookahead symbol. */
3185942a 1665int yychar;
b80f6443 1666
a0c0a00f 1667/* The semantic value of the lookahead symbol. */
3185942a 1668YYSTYPE yylval;
3185942a
JA
1669/* Number of syntax errors so far. */
1670int yynerrs;
726f6388 1671
3185942a 1672
3185942a
JA
1673/*----------.
1674| yyparse. |
1675`----------*/
1676
3185942a
JA
1677int
1678yyparse (void)
3185942a 1679{
a0c0a00f
CR
1680 int yystate;
1681 /* Number of tokens to shift before error messages enabled. */
1682 int yyerrstatus;
1683
1684 /* The stacks and their tools:
1685 'yyss': related to states.
1686 'yyvs': related to semantic values.
1687
1688 Refer to the stacks through separate pointers, to allow yyoverflow
1689 to reallocate them elsewhere. */
1690
1691 /* The state stack. */
1692 yytype_int16 yyssa[YYINITDEPTH];
1693 yytype_int16 *yyss;
1694 yytype_int16 *yyssp;
1695
1696 /* The semantic value stack. */
1697 YYSTYPE yyvsa[YYINITDEPTH];
1698 YYSTYPE *yyvs;
1699 YYSTYPE *yyvsp;
1700
1701 YYSIZE_T yystacksize;
1702
3185942a
JA
1703 int yyn;
1704 int yyresult;
a0c0a00f 1705 /* Lookahead token as an internal (translated) token number. */
3185942a 1706 int yytoken = 0;
a0c0a00f
CR
1707 /* The variables used to return semantic value and location from the
1708 action routines. */
1709 YYSTYPE yyval;
1710
3185942a
JA
1711#if YYERROR_VERBOSE
1712 /* Buffer for error messages, and its allocated size. */
1713 char yymsgbuf[128];
1714 char *yymsg = yymsgbuf;
1715 YYSIZE_T yymsg_alloc = sizeof yymsgbuf;
7117c2d2 1716#endif
726f6388 1717
3185942a
JA
1718#define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N))
1719
3185942a
JA
1720 /* The number of symbols on the RHS of the reduced rule.
1721 Keep to zero when no symbol should be popped. */
1722 int yylen = 0;
1723
a0c0a00f
CR
1724 yyssp = yyss = yyssa;
1725 yyvsp = yyvs = yyvsa;
1726 yystacksize = YYINITDEPTH;
1727
3185942a 1728 YYDPRINTF ((stderr, "Starting parse\n"));
726f6388 1729
f73dda09
JA
1730 yystate = 0;
1731 yyerrstatus = 0;
1732 yynerrs = 0;
a0c0a00f 1733 yychar = YYEMPTY; /* Cause a token to be read. */
3185942a 1734 goto yysetstate;
f73dda09 1735
3185942a
JA
1736/*------------------------------------------------------------.
1737| yynewstate -- Push a new state, which is found in yystate. |
1738`------------------------------------------------------------*/
1739 yynewstate:
1740 /* In all cases, when you get here, the value and location stacks
1741 have just been pushed. So pushing a state here evens the stacks. */
1742 yyssp++;
f73dda09 1743
3185942a
JA
1744 yysetstate:
1745 *yyssp = yystate;
b80f6443 1746
3185942a
JA
1747 if (yyss + yystacksize - 1 <= yyssp)
1748 {
f73dda09 1749 /* Get the current used size of the three stacks, in elements. */
3185942a 1750 YYSIZE_T yysize = yyssp - yyss + 1;
f73dda09
JA
1751
1752#ifdef yyoverflow
3185942a 1753 {
a0c0a00f
CR
1754 /* Give user a chance to reallocate the stack. Use copies of
1755 these so that the &'s don't force the real ones into
1756 memory. */
1757 YYSTYPE *yyvs1 = yyvs;
1758 yytype_int16 *yyss1 = yyss;
1759
1760 /* Each stack pointer address is followed by the size of the
1761 data in use in that stack, in bytes. This used to be a
1762 conditional around just the two extra args, but that might
1763 be undefined if yyoverflow is a macro. */
1764 yyoverflow (YY_("memory exhausted"),
1765 &yyss1, yysize * sizeof (*yyssp),
1766 &yyvs1, yysize * sizeof (*yyvsp),
1767 &yystacksize);
1768
1769 yyss = yyss1;
1770 yyvs = yyvs1;
3185942a 1771 }
f73dda09 1772#else /* no yyoverflow */
3185942a
JA
1773# ifndef YYSTACK_RELOCATE
1774 goto yyexhaustedlab;
1775# else
f73dda09 1776 /* Extend the stack our own way. */
3185942a 1777 if (YYMAXDEPTH <= yystacksize)
a0c0a00f 1778 goto yyexhaustedlab;
f73dda09 1779 yystacksize *= 2;
3185942a 1780 if (YYMAXDEPTH < yystacksize)
a0c0a00f 1781 yystacksize = YYMAXDEPTH;
3185942a
JA
1782
1783 {
a0c0a00f
CR
1784 yytype_int16 *yyss1 = yyss;
1785 union yyalloc *yyptr =
1786 (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
1787 if (! yyptr)
1788 goto yyexhaustedlab;
1789 YYSTACK_RELOCATE (yyss_alloc, yyss);
1790 YYSTACK_RELOCATE (yyvs_alloc, yyvs);
3185942a 1791# undef YYSTACK_RELOCATE
a0c0a00f
CR
1792 if (yyss1 != yyssa)
1793 YYSTACK_FREE (yyss1);
3185942a
JA
1794 }
1795# endif
f73dda09 1796#endif /* no yyoverflow */
726f6388 1797
3185942a
JA
1798 yyssp = yyss + yysize - 1;
1799 yyvsp = yyvs + yysize - 1;
726f6388 1800
3185942a 1801 YYDPRINTF ((stderr, "Stack size increased to %lu\n",
a0c0a00f 1802 (unsigned long int) yystacksize));
3185942a
JA
1803
1804 if (yyss + yystacksize - 1 <= yyssp)
a0c0a00f 1805 YYABORT;
726f6388
JA
1806 }
1807
3185942a 1808 YYDPRINTF ((stderr, "Entering state %d\n", yystate));
28ef6c31 1809
a0c0a00f
CR
1810 if (yystate == YYFINAL)
1811 YYACCEPT;
1812
f73dda09 1813 goto yybackup;
28ef6c31 1814
3185942a
JA
1815/*-----------.
1816| yybackup. |
1817`-----------*/
1818yybackup:
28ef6c31 1819
3185942a 1820 /* Do appropriate processing given the current state. Read a
a0c0a00f 1821 lookahead token if we need one and don't already have one. */
726f6388 1822
a0c0a00f 1823 /* First try to decide what to do without reference to lookahead token. */
f73dda09 1824 yyn = yypact[yystate];
a0c0a00f 1825 if (yypact_value_is_default (yyn))
f73dda09 1826 goto yydefault;
726f6388 1827
a0c0a00f 1828 /* Not known => get a lookahead token if don't already have one. */
726f6388 1829
a0c0a00f 1830 /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol. */
f73dda09 1831 if (yychar == YYEMPTY)
726f6388 1832 {
3185942a 1833 YYDPRINTF ((stderr, "Reading a token: "));
a0c0a00f 1834 yychar = yylex ();
726f6388 1835 }
726f6388 1836
3185942a 1837 if (yychar <= YYEOF)
f73dda09 1838 {
3185942a
JA
1839 yychar = yytoken = YYEOF;
1840 YYDPRINTF ((stderr, "Now at end of input.\n"));
f73dda09
JA
1841 }
1842 else
1843 {
3185942a
JA
1844 yytoken = YYTRANSLATE (yychar);
1845 YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
f73dda09 1846 }
726f6388 1847
3185942a
JA
1848 /* If the proper action on seeing token YYTOKEN is to reduce or to
1849 detect an error, take that action. */
1850 yyn += yytoken;
1851 if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
f73dda09 1852 goto yydefault;
f73dda09 1853 yyn = yytable[yyn];
3185942a 1854 if (yyn <= 0)
f73dda09 1855 {
a0c0a00f
CR
1856 if (yytable_value_is_error (yyn))
1857 goto yyerrlab;
f73dda09
JA
1858 yyn = -yyn;
1859 goto yyreduce;
1860 }
726f6388 1861
3185942a
JA
1862 /* Count tokens shifted since error; after three, turn off error
1863 status. */
1864 if (yyerrstatus)
1865 yyerrstatus--;
b80f6443 1866
a0c0a00f 1867 /* Shift the lookahead token. */
3185942a 1868 YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
726f6388 1869
a0c0a00f
CR
1870 /* Discard the shifted token. */
1871 yychar = YYEMPTY;
28ef6c31 1872
3185942a 1873 yystate = yyn;
a0c0a00f 1874 YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
f73dda09 1875 *++yyvsp = yylval;
a0c0a00f 1876 YY_IGNORE_MAYBE_UNINITIALIZED_END
28ef6c31 1877
f73dda09 1878 goto yynewstate;
726f6388 1879
b80f6443 1880
3185942a
JA
1881/*-----------------------------------------------------------.
1882| yydefault -- do the default action for the current state. |
1883`-----------------------------------------------------------*/
1884yydefault:
f73dda09
JA
1885 yyn = yydefact[yystate];
1886 if (yyn == 0)
1887 goto yyerrlab;
3185942a 1888 goto yyreduce;
28ef6c31 1889
3185942a
JA
1890
1891/*-----------------------------.
1892| yyreduce -- Do a reduction. |
1893`-----------------------------*/
f73dda09 1894yyreduce:
3185942a 1895 /* yyn is the number of a rule to reduce with. */
f73dda09 1896 yylen = yyr2[yyn];
28ef6c31 1897
3185942a 1898 /* If YYLEN is nonzero, implement the default value of the action:
a0c0a00f 1899 '$$ = $1'.
28ef6c31 1900
3185942a
JA
1901 Otherwise, the following line sets YYVAL to garbage.
1902 This behavior is undocumented and Bison
1903 users should not rely upon it. Assigning to YYVAL
1904 unconditionally makes the parser a bit smaller, and it avoids a
1905 GCC warning that YYVAL may be used uninitialized. */
1906 yyval = yyvsp[1-yylen];
b80f6443 1907
28ef6c31 1908
3185942a
JA
1909 YY_REDUCE_PRINT (yyn);
1910 switch (yyn)
1911 {
1912 case 2:
a0c0a00f 1913#line 387 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3185942a 1914 {
f73dda09
JA
1915 /* Case of regular command. Discard the error
1916 safety net,and return the command just parsed. */
a0c0a00f 1917 global_command = (yyvsp[-1].command);
f73dda09 1918 eof_encountered = 0;
7117c2d2 1919 /* discard_parser_constructs (0); */
3185942a
JA
1920 if (parser_state & PST_CMDSUBST)
1921 parser_state |= PST_EOFTOKEN;
f73dda09 1922 YYACCEPT;
3185942a 1923 }
a0c0a00f 1924#line 1925 "y.tab.c" /* yacc.c:1646 */
3185942a
JA
1925 break;
1926
1927 case 3:
a0c0a00f 1928#line 398 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3185942a 1929 {
f73dda09
JA
1930 /* Case of regular command, but not a very
1931 interesting one. Return a NULL command. */
1932 global_command = (COMMAND *)NULL;
3185942a
JA
1933 if (parser_state & PST_CMDSUBST)
1934 parser_state |= PST_EOFTOKEN;
f73dda09 1935 YYACCEPT;
3185942a 1936 }
a0c0a00f 1937#line 1938 "y.tab.c" /* yacc.c:1646 */
3185942a
JA
1938 break;
1939
1940 case 4:
a0c0a00f 1941#line 407 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3185942a 1942 {
f73dda09
JA
1943 /* Error during parsing. Return NULL command. */
1944 global_command = (COMMAND *)NULL;
1945 eof_encountered = 0;
7117c2d2 1946 /* discard_parser_constructs (1); */
3185942a 1947 if (interactive && parse_and_execute_level == 0)
f73dda09
JA
1948 {
1949 YYACCEPT;
1950 }
1951 else
1952 {
1953 YYABORT;
1954 }
3185942a 1955 }
a0c0a00f 1956#line 1957 "y.tab.c" /* yacc.c:1646 */
3185942a
JA
1957 break;
1958
1959 case 5:
a0c0a00f 1960#line 422 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3185942a 1961 {
f73dda09
JA
1962 /* Case of EOF seen by itself. Do ignoreeof or
1963 not. */
1964 global_command = (COMMAND *)NULL;
1965 handle_eof_input_unit ();
1966 YYACCEPT;
3185942a 1967 }
a0c0a00f 1968#line 1969 "y.tab.c" /* yacc.c:1646 */
3185942a
JA
1969 break;
1970
1971 case 6:
a0c0a00f
CR
1972#line 432 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
1973 { (yyval.word_list) = make_word_list ((yyvsp[0].word), (WORD_LIST *)NULL); }
1974#line 1975 "y.tab.c" /* yacc.c:1646 */
3185942a
JA
1975 break;
1976
1977 case 7:
a0c0a00f
CR
1978#line 434 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
1979 { (yyval.word_list) = make_word_list ((yyvsp[0].word), (yyvsp[-1].word_list)); }
1980#line 1981 "y.tab.c" /* yacc.c:1646 */
3185942a
JA
1981 break;
1982
1983 case 8:
a0c0a00f 1984#line 438 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3185942a 1985 {
0001803f 1986 source.dest = 1;
a0c0a00f 1987 redir.filename = (yyvsp[0].word);
0001803f 1988 (yyval.redirect) = make_redirection (source, r_output_direction, redir, 0);
3185942a 1989 }
a0c0a00f 1990#line 1991 "y.tab.c" /* yacc.c:1646 */
3185942a
JA
1991 break;
1992
1993 case 9:
a0c0a00f 1994#line 444 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3185942a 1995 {
0001803f 1996 source.dest = 0;
a0c0a00f 1997 redir.filename = (yyvsp[0].word);
0001803f 1998 (yyval.redirect) = make_redirection (source, r_input_direction, redir, 0);
3185942a 1999 }
a0c0a00f 2000#line 2001 "y.tab.c" /* yacc.c:1646 */
3185942a
JA
2001 break;
2002
2003 case 10:
a0c0a00f 2004#line 450 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3185942a 2005 {
a0c0a00f
CR
2006 source.dest = (yyvsp[-2].number);
2007 redir.filename = (yyvsp[0].word);
0001803f 2008 (yyval.redirect) = make_redirection (source, r_output_direction, redir, 0);
3185942a 2009 }
a0c0a00f 2010#line 2011 "y.tab.c" /* yacc.c:1646 */
3185942a
JA
2011 break;
2012
2013 case 11:
a0c0a00f 2014#line 456 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3185942a 2015 {
a0c0a00f
CR
2016 source.dest = (yyvsp[-2].number);
2017 redir.filename = (yyvsp[0].word);
0001803f 2018 (yyval.redirect) = make_redirection (source, r_input_direction, redir, 0);
3185942a 2019 }
a0c0a00f 2020#line 2021 "y.tab.c" /* yacc.c:1646 */
3185942a
JA
2021 break;
2022
2023 case 12:
a0c0a00f 2024#line 462 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3185942a 2025 {
a0c0a00f
CR
2026 source.filename = (yyvsp[-2].word);
2027 redir.filename = (yyvsp[0].word);
0001803f 2028 (yyval.redirect) = make_redirection (source, r_output_direction, redir, REDIR_VARASSIGN);
3185942a 2029 }
a0c0a00f 2030#line 2031 "y.tab.c" /* yacc.c:1646 */
3185942a
JA
2031 break;
2032
2033 case 13:
a0c0a00f 2034#line 468 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3185942a 2035 {
a0c0a00f
CR
2036 source.filename = (yyvsp[-2].word);
2037 redir.filename = (yyvsp[0].word);
0001803f 2038 (yyval.redirect) = make_redirection (source, r_input_direction, redir, REDIR_VARASSIGN);
3185942a 2039 }
a0c0a00f 2040#line 2041 "y.tab.c" /* yacc.c:1646 */
3185942a
JA
2041 break;
2042
2043 case 14:
a0c0a00f 2044#line 474 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3185942a 2045 {
0001803f 2046 source.dest = 1;
a0c0a00f 2047 redir.filename = (yyvsp[0].word);
0001803f 2048 (yyval.redirect) = make_redirection (source, r_appending_to, redir, 0);
3185942a 2049 }
a0c0a00f 2050#line 2051 "y.tab.c" /* yacc.c:1646 */
3185942a
JA
2051 break;
2052
2053 case 15:
a0c0a00f 2054#line 480 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3185942a 2055 {
a0c0a00f
CR
2056 source.dest = (yyvsp[-2].number);
2057 redir.filename = (yyvsp[0].word);
0001803f 2058 (yyval.redirect) = make_redirection (source, r_appending_to, redir, 0);
3185942a 2059 }
a0c0a00f 2060#line 2061 "y.tab.c" /* yacc.c:1646 */
3185942a
JA
2061 break;
2062
2063 case 16:
a0c0a00f 2064#line 486 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3185942a 2065 {
a0c0a00f
CR
2066 source.filename = (yyvsp[-2].word);
2067 redir.filename = (yyvsp[0].word);
0001803f 2068 (yyval.redirect) = make_redirection (source, r_appending_to, redir, REDIR_VARASSIGN);
3185942a 2069 }
a0c0a00f 2070#line 2071 "y.tab.c" /* yacc.c:1646 */
3185942a
JA
2071 break;
2072
2073 case 17:
a0c0a00f 2074#line 492 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3185942a 2075 {
0001803f 2076 source.dest = 1;
a0c0a00f 2077 redir.filename = (yyvsp[0].word);
0001803f 2078 (yyval.redirect) = make_redirection (source, r_output_force, redir, 0);
3185942a 2079 }
a0c0a00f 2080#line 2081 "y.tab.c" /* yacc.c:1646 */
3185942a
JA
2081 break;
2082
2083 case 18:
a0c0a00f 2084#line 498 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3185942a 2085 {
a0c0a00f
CR
2086 source.dest = (yyvsp[-2].number);
2087 redir.filename = (yyvsp[0].word);
0001803f 2088 (yyval.redirect) = make_redirection (source, r_output_force, redir, 0);
3185942a 2089 }
a0c0a00f 2090#line 2091 "y.tab.c" /* yacc.c:1646 */
3185942a
JA
2091 break;
2092
2093 case 19:
a0c0a00f 2094#line 504 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3185942a 2095 {
a0c0a00f
CR
2096 source.filename = (yyvsp[-2].word);
2097 redir.filename = (yyvsp[0].word);
0001803f 2098 (yyval.redirect) = make_redirection (source, r_output_force, redir, REDIR_VARASSIGN);
3185942a 2099 }
a0c0a00f 2100#line 2101 "y.tab.c" /* yacc.c:1646 */
3185942a
JA
2101 break;
2102
2103 case 20:
a0c0a00f 2104#line 510 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3185942a 2105 {
0001803f 2106 source.dest = 0;
a0c0a00f 2107 redir.filename = (yyvsp[0].word);
0001803f 2108 (yyval.redirect) = make_redirection (source, r_input_output, redir, 0);
3185942a 2109 }
a0c0a00f 2110#line 2111 "y.tab.c" /* yacc.c:1646 */
3185942a
JA
2111 break;
2112
2113 case 21:
a0c0a00f 2114#line 516 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3185942a 2115 {
a0c0a00f
CR
2116 source.dest = (yyvsp[-2].number);
2117 redir.filename = (yyvsp[0].word);
0001803f 2118 (yyval.redirect) = make_redirection (source, r_input_output, redir, 0);
3185942a 2119 }
a0c0a00f 2120#line 2121 "y.tab.c" /* yacc.c:1646 */
3185942a
JA
2121 break;
2122
2123 case 22:
a0c0a00f 2124#line 522 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3185942a 2125 {
a0c0a00f
CR
2126 source.filename = (yyvsp[-2].word);
2127 redir.filename = (yyvsp[0].word);
0001803f 2128 (yyval.redirect) = make_redirection (source, r_input_output, redir, REDIR_VARASSIGN);
3185942a 2129 }
a0c0a00f 2130#line 2131 "y.tab.c" /* yacc.c:1646 */
3185942a
JA
2131 break;
2132
2133 case 23:
a0c0a00f 2134#line 528 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3185942a 2135 {
0001803f 2136 source.dest = 0;
a0c0a00f 2137 redir.filename = (yyvsp[0].word);
0001803f 2138 (yyval.redirect) = make_redirection (source, r_reading_until, redir, 0);
90a39f32 2139 push_heredoc ((yyval.redirect));
3185942a 2140 }
a0c0a00f 2141#line 2142 "y.tab.c" /* yacc.c:1646 */
3185942a
JA
2142 break;
2143
2144 case 24:
a0c0a00f 2145#line 535 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3185942a 2146 {
a0c0a00f
CR
2147 source.dest = (yyvsp[-2].number);
2148 redir.filename = (yyvsp[0].word);
0001803f 2149 (yyval.redirect) = make_redirection (source, r_reading_until, redir, 0);
90a39f32 2150 push_heredoc ((yyval.redirect));
3185942a 2151 }
a0c0a00f 2152#line 2153 "y.tab.c" /* yacc.c:1646 */
3185942a
JA
2153 break;
2154
2155 case 25:
a0c0a00f 2156#line 542 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3185942a 2157 {
a0c0a00f
CR
2158 source.filename = (yyvsp[-2].word);
2159 redir.filename = (yyvsp[0].word);
0001803f 2160 (yyval.redirect) = make_redirection (source, r_reading_until, redir, REDIR_VARASSIGN);
90a39f32 2161 push_heredoc ((yyval.redirect));
3185942a 2162 }
a0c0a00f 2163#line 2164 "y.tab.c" /* yacc.c:1646 */
3185942a
JA
2164 break;
2165
2166 case 26:
a0c0a00f 2167#line 549 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3185942a 2168 {
0001803f 2169 source.dest = 0;
a0c0a00f 2170 redir.filename = (yyvsp[0].word);
0001803f 2171 (yyval.redirect) = make_redirection (source, r_deblank_reading_until, redir, 0);
90a39f32 2172 push_heredoc ((yyval.redirect));
3185942a 2173 }
a0c0a00f 2174#line 2175 "y.tab.c" /* yacc.c:1646 */
3185942a
JA
2175 break;
2176
2177 case 27:
a0c0a00f 2178#line 556 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3185942a 2179 {
a0c0a00f
CR
2180 source.dest = (yyvsp[-2].number);
2181 redir.filename = (yyvsp[0].word);
0001803f 2182 (yyval.redirect) = make_redirection (source, r_deblank_reading_until, redir, 0);
90a39f32 2183 push_heredoc ((yyval.redirect));
3185942a 2184 }
a0c0a00f 2185#line 2186 "y.tab.c" /* yacc.c:1646 */
3185942a
JA
2186 break;
2187
2188 case 28:
a0c0a00f 2189#line 563 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3185942a 2190 {
a0c0a00f
CR
2191 source.filename = (yyvsp[-2].word);
2192 redir.filename = (yyvsp[0].word);
0001803f 2193 (yyval.redirect) = make_redirection (source, r_deblank_reading_until, redir, REDIR_VARASSIGN);
90a39f32 2194 push_heredoc ((yyval.redirect));
3185942a 2195 }
a0c0a00f 2196#line 2197 "y.tab.c" /* yacc.c:1646 */
3185942a
JA
2197 break;
2198
2199 case 29:
a0c0a00f 2200#line 570 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3185942a 2201 {
0001803f 2202 source.dest = 0;
a0c0a00f 2203 redir.filename = (yyvsp[0].word);
0001803f 2204 (yyval.redirect) = make_redirection (source, r_reading_string, redir, 0);
3185942a 2205 }
a0c0a00f 2206#line 2207 "y.tab.c" /* yacc.c:1646 */
3185942a
JA
2207 break;
2208
2209 case 30:
a0c0a00f 2210#line 576 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3185942a 2211 {
a0c0a00f
CR
2212 source.dest = (yyvsp[-2].number);
2213 redir.filename = (yyvsp[0].word);
0001803f 2214 (yyval.redirect) = make_redirection (source, r_reading_string, redir, 0);
3185942a 2215 }
a0c0a00f 2216#line 2217 "y.tab.c" /* yacc.c:1646 */
3185942a
JA
2217 break;
2218
2219 case 31:
a0c0a00f 2220#line 582 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3185942a 2221 {
a0c0a00f
CR
2222 source.filename = (yyvsp[-2].word);
2223 redir.filename = (yyvsp[0].word);
0001803f 2224 (yyval.redirect) = make_redirection (source, r_reading_string, redir, REDIR_VARASSIGN);
3185942a 2225 }
a0c0a00f 2226#line 2227 "y.tab.c" /* yacc.c:1646 */
3185942a
JA
2227 break;
2228
2229 case 32:
a0c0a00f 2230#line 588 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3185942a 2231 {
0001803f 2232 source.dest = 0;
a0c0a00f 2233 redir.dest = (yyvsp[0].number);
0001803f 2234 (yyval.redirect) = make_redirection (source, r_duplicating_input, redir, 0);
3185942a 2235 }
a0c0a00f 2236#line 2237 "y.tab.c" /* yacc.c:1646 */
3185942a
JA
2237 break;
2238
2239 case 33:
a0c0a00f 2240#line 594 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3185942a 2241 {
a0c0a00f
CR
2242 source.dest = (yyvsp[-2].number);
2243 redir.dest = (yyvsp[0].number);
0001803f 2244 (yyval.redirect) = make_redirection (source, r_duplicating_input, redir, 0);
3185942a 2245 }
a0c0a00f 2246#line 2247 "y.tab.c" /* yacc.c:1646 */
3185942a
JA
2247 break;
2248
2249 case 34:
a0c0a00f 2250#line 600 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3185942a 2251 {
a0c0a00f
CR
2252 source.filename = (yyvsp[-2].word);
2253 redir.dest = (yyvsp[0].number);
0001803f 2254 (yyval.redirect) = make_redirection (source, r_duplicating_input, redir, REDIR_VARASSIGN);
3185942a 2255 }
a0c0a00f 2256#line 2257 "y.tab.c" /* yacc.c:1646 */
3185942a
JA
2257 break;
2258
2259 case 35:
a0c0a00f 2260#line 606 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3185942a 2261 {
0001803f 2262 source.dest = 1;
a0c0a00f 2263 redir.dest = (yyvsp[0].number);
0001803f 2264 (yyval.redirect) = make_redirection (source, r_duplicating_output, redir, 0);
3185942a 2265 }
a0c0a00f 2266#line 2267 "y.tab.c" /* yacc.c:1646 */
3185942a
JA
2267 break;
2268
2269 case 36:
a0c0a00f 2270#line 612 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3185942a 2271 {
a0c0a00f
CR
2272 source.dest = (yyvsp[-2].number);
2273 redir.dest = (yyvsp[0].number);
0001803f 2274 (yyval.redirect) = make_redirection (source, r_duplicating_output, redir, 0);
3185942a 2275 }
a0c0a00f 2276#line 2277 "y.tab.c" /* yacc.c:1646 */
3185942a
JA
2277 break;
2278
2279 case 37:
a0c0a00f 2280#line 618 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3185942a 2281 {
a0c0a00f
CR
2282 source.filename = (yyvsp[-2].word);
2283 redir.dest = (yyvsp[0].number);
0001803f 2284 (yyval.redirect) = make_redirection (source, r_duplicating_output, redir, REDIR_VARASSIGN);
3185942a 2285 }
a0c0a00f 2286#line 2287 "y.tab.c" /* yacc.c:1646 */
3185942a
JA
2287 break;
2288
2289 case 38:
a0c0a00f 2290#line 624 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
0001803f
CR
2291 {
2292 source.dest = 0;
a0c0a00f 2293 redir.filename = (yyvsp[0].word);
0001803f
CR
2294 (yyval.redirect) = make_redirection (source, r_duplicating_input_word, redir, 0);
2295 }
a0c0a00f 2296#line 2297 "y.tab.c" /* yacc.c:1646 */
3185942a
JA
2297 break;
2298
2299 case 39:
a0c0a00f 2300#line 630 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
0001803f 2301 {
a0c0a00f
CR
2302 source.dest = (yyvsp[-2].number);
2303 redir.filename = (yyvsp[0].word);
0001803f
CR
2304 (yyval.redirect) = make_redirection (source, r_duplicating_input_word, redir, 0);
2305 }
a0c0a00f 2306#line 2307 "y.tab.c" /* yacc.c:1646 */
3185942a
JA
2307 break;
2308
2309 case 40:
a0c0a00f 2310#line 636 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
0001803f 2311 {
a0c0a00f
CR
2312 source.filename = (yyvsp[-2].word);
2313 redir.filename = (yyvsp[0].word);
0001803f
CR
2314 (yyval.redirect) = make_redirection (source, r_duplicating_input_word, redir, REDIR_VARASSIGN);
2315 }
a0c0a00f 2316#line 2317 "y.tab.c" /* yacc.c:1646 */
3185942a
JA
2317 break;
2318
2319 case 41:
a0c0a00f 2320#line 642 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3185942a 2321 {
0001803f 2322 source.dest = 1;
a0c0a00f 2323 redir.filename = (yyvsp[0].word);
0001803f 2324 (yyval.redirect) = make_redirection (source, r_duplicating_output_word, redir, 0);
3185942a 2325 }
a0c0a00f 2326#line 2327 "y.tab.c" /* yacc.c:1646 */
3185942a
JA
2327 break;
2328
2329 case 42:
a0c0a00f 2330#line 648 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
0001803f 2331 {
a0c0a00f
CR
2332 source.dest = (yyvsp[-2].number);
2333 redir.filename = (yyvsp[0].word);
0001803f
CR
2334 (yyval.redirect) = make_redirection (source, r_duplicating_output_word, redir, 0);
2335 }
a0c0a00f 2336#line 2337 "y.tab.c" /* yacc.c:1646 */
0001803f
CR
2337 break;
2338
2339 case 43:
a0c0a00f 2340#line 654 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
0001803f 2341 {
a0c0a00f
CR
2342 source.filename = (yyvsp[-2].word);
2343 redir.filename = (yyvsp[0].word);
0001803f
CR
2344 (yyval.redirect) = make_redirection (source, r_duplicating_output_word, redir, REDIR_VARASSIGN);
2345 }
a0c0a00f 2346#line 2347 "y.tab.c" /* yacc.c:1646 */
0001803f
CR
2347 break;
2348
2349 case 44:
a0c0a00f 2350#line 660 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
0001803f
CR
2351 {
2352 source.dest = 1;
2353 redir.dest = 0;
2354 (yyval.redirect) = make_redirection (source, r_close_this, redir, 0);
2355 }
a0c0a00f 2356#line 2357 "y.tab.c" /* yacc.c:1646 */
0001803f
CR
2357 break;
2358
2359 case 45:
a0c0a00f 2360#line 666 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
0001803f 2361 {
a0c0a00f 2362 source.dest = (yyvsp[-2].number);
0001803f
CR
2363 redir.dest = 0;
2364 (yyval.redirect) = make_redirection (source, r_close_this, redir, 0);
2365 }
a0c0a00f 2366#line 2367 "y.tab.c" /* yacc.c:1646 */
0001803f
CR
2367 break;
2368
2369 case 46:
a0c0a00f 2370#line 672 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
0001803f 2371 {
a0c0a00f 2372 source.filename = (yyvsp[-2].word);
0001803f
CR
2373 redir.dest = 0;
2374 (yyval.redirect) = make_redirection (source, r_close_this, redir, REDIR_VARASSIGN);
2375 }
a0c0a00f 2376#line 2377 "y.tab.c" /* yacc.c:1646 */
0001803f
CR
2377 break;
2378
2379 case 47:
a0c0a00f 2380#line 678 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
0001803f
CR
2381 {
2382 source.dest = 0;
2383 redir.dest = 0;
2384 (yyval.redirect) = make_redirection (source, r_close_this, redir, 0);
2385 }
a0c0a00f 2386#line 2387 "y.tab.c" /* yacc.c:1646 */
0001803f
CR
2387 break;
2388
2389 case 48:
a0c0a00f 2390#line 684 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
0001803f 2391 {
a0c0a00f 2392 source.dest = (yyvsp[-2].number);
0001803f
CR
2393 redir.dest = 0;
2394 (yyval.redirect) = make_redirection (source, r_close_this, redir, 0);
2395 }
a0c0a00f 2396#line 2397 "y.tab.c" /* yacc.c:1646 */
0001803f
CR
2397 break;
2398
2399 case 49:
a0c0a00f 2400#line 690 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
0001803f 2401 {
a0c0a00f 2402 source.filename = (yyvsp[-2].word);
0001803f
CR
2403 redir.dest = 0;
2404 (yyval.redirect) = make_redirection (source, r_close_this, redir, REDIR_VARASSIGN);
2405 }
a0c0a00f 2406#line 2407 "y.tab.c" /* yacc.c:1646 */
0001803f
CR
2407 break;
2408
2409 case 50:
a0c0a00f 2410#line 696 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
0001803f
CR
2411 {
2412 source.dest = 1;
a0c0a00f 2413 redir.filename = (yyvsp[0].word);
0001803f
CR
2414 (yyval.redirect) = make_redirection (source, r_err_and_out, redir, 0);
2415 }
a0c0a00f 2416#line 2417 "y.tab.c" /* yacc.c:1646 */
0001803f
CR
2417 break;
2418
2419 case 51:
a0c0a00f 2420#line 702 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
0001803f
CR
2421 {
2422 source.dest = 1;
a0c0a00f 2423 redir.filename = (yyvsp[0].word);
0001803f
CR
2424 (yyval.redirect) = make_redirection (source, r_append_err_and_out, redir, 0);
2425 }
a0c0a00f 2426#line 2427 "y.tab.c" /* yacc.c:1646 */
0001803f
CR
2427 break;
2428
2429 case 52:
a0c0a00f
CR
2430#line 710 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2431 { (yyval.element).word = (yyvsp[0].word); (yyval.element).redirect = 0; }
2432#line 2433 "y.tab.c" /* yacc.c:1646 */
0001803f
CR
2433 break;
2434
2435 case 53:
a0c0a00f
CR
2436#line 712 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2437 { (yyval.element).word = (yyvsp[0].word); (yyval.element).redirect = 0; }
2438#line 2439 "y.tab.c" /* yacc.c:1646 */
0001803f
CR
2439 break;
2440
2441 case 54:
a0c0a00f
CR
2442#line 714 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2443 { (yyval.element).redirect = (yyvsp[0].redirect); (yyval.element).word = 0; }
2444#line 2445 "y.tab.c" /* yacc.c:1646 */
0001803f
CR
2445 break;
2446
2447 case 55:
a0c0a00f 2448#line 718 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
0001803f 2449 {
a0c0a00f 2450 (yyval.redirect) = (yyvsp[0].redirect);
0001803f 2451 }
a0c0a00f 2452#line 2453 "y.tab.c" /* yacc.c:1646 */
0001803f
CR
2453 break;
2454
2455 case 56:
a0c0a00f 2456#line 722 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3185942a 2457 {
f73dda09
JA
2458 register REDIRECT *t;
2459
a0c0a00f 2460 for (t = (yyvsp[-1].redirect); t->next; t = t->next)
f73dda09 2461 ;
a0c0a00f
CR
2462 t->next = (yyvsp[0].redirect);
2463 (yyval.redirect) = (yyvsp[-1].redirect);
3185942a 2464 }
a0c0a00f 2465#line 2466 "y.tab.c" /* yacc.c:1646 */
3185942a
JA
2466 break;
2467
0001803f 2468 case 57:
a0c0a00f
CR
2469#line 733 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2470 { (yyval.command) = make_simple_command ((yyvsp[0].element), (COMMAND *)NULL); }
2471#line 2472 "y.tab.c" /* yacc.c:1646 */
3185942a
JA
2472 break;
2473
0001803f 2474 case 58:
a0c0a00f
CR
2475#line 735 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2476 { (yyval.command) = make_simple_command ((yyvsp[0].element), (yyvsp[-1].command)); }
2477#line 2478 "y.tab.c" /* yacc.c:1646 */
3185942a
JA
2478 break;
2479
0001803f 2480 case 59:
a0c0a00f
CR
2481#line 739 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2482 { (yyval.command) = clean_simple_command ((yyvsp[0].command)); }
2483#line 2484 "y.tab.c" /* yacc.c:1646 */
3185942a
JA
2484 break;
2485
0001803f 2486 case 60:
a0c0a00f
CR
2487#line 741 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2488 { (yyval.command) = (yyvsp[0].command); }
2489#line 2490 "y.tab.c" /* yacc.c:1646 */
3185942a
JA
2490 break;
2491
0001803f 2492 case 61:
a0c0a00f 2493#line 743 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3185942a 2494 {
f73dda09
JA
2495 COMMAND *tc;
2496
a0c0a00f 2497 tc = (yyvsp[-1].command);
f73dda09
JA
2498 if (tc->redirects)
2499 {
2500 register REDIRECT *t;
2501 for (t = tc->redirects; t->next; t = t->next)
2502 ;
a0c0a00f 2503 t->next = (yyvsp[0].redirect);
f73dda09
JA
2504 }
2505 else
a0c0a00f
CR
2506 tc->redirects = (yyvsp[0].redirect);
2507 (yyval.command) = (yyvsp[-1].command);
3185942a 2508 }
a0c0a00f 2509#line 2510 "y.tab.c" /* yacc.c:1646 */
3185942a
JA
2510 break;
2511
0001803f 2512 case 62:
a0c0a00f
CR
2513#line 759 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2514 { (yyval.command) = (yyvsp[0].command); }
2515#line 2516 "y.tab.c" /* yacc.c:1646 */
3185942a
JA
2516 break;
2517
0001803f 2518 case 63:
a0c0a00f
CR
2519#line 761 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2520 { (yyval.command) = (yyvsp[0].command); }
2521#line 2522 "y.tab.c" /* yacc.c:1646 */
3185942a
JA
2522 break;
2523
0001803f 2524 case 64:
a0c0a00f
CR
2525#line 765 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2526 { (yyval.command) = (yyvsp[0].command); }
2527#line 2528 "y.tab.c" /* yacc.c:1646 */
3185942a
JA
2528 break;
2529
0001803f 2530 case 65:
a0c0a00f
CR
2531#line 767 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2532 { (yyval.command) = (yyvsp[0].command); }
2533#line 2534 "y.tab.c" /* yacc.c:1646 */
3185942a
JA
2534 break;
2535
0001803f 2536 case 66:
a0c0a00f
CR
2537#line 769 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2538 { (yyval.command) = make_while_command ((yyvsp[-3].command), (yyvsp[-1].command)); }
2539#line 2540 "y.tab.c" /* yacc.c:1646 */
3185942a
JA
2540 break;
2541
0001803f 2542 case 67:
a0c0a00f
CR
2543#line 771 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2544 { (yyval.command) = make_until_command ((yyvsp[-3].command), (yyvsp[-1].command)); }
2545#line 2546 "y.tab.c" /* yacc.c:1646 */
3185942a
JA
2546 break;
2547
0001803f 2548 case 68:
a0c0a00f
CR
2549#line 773 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2550 { (yyval.command) = (yyvsp[0].command); }
2551#line 2552 "y.tab.c" /* yacc.c:1646 */
3185942a
JA
2552 break;
2553
0001803f 2554 case 69:
a0c0a00f
CR
2555#line 775 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2556 { (yyval.command) = (yyvsp[0].command); }
2557#line 2558 "y.tab.c" /* yacc.c:1646 */
3185942a
JA
2558 break;
2559
0001803f 2560 case 70:
a0c0a00f
CR
2561#line 777 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2562 { (yyval.command) = (yyvsp[0].command); }
2563#line 2564 "y.tab.c" /* yacc.c:1646 */
3185942a
JA
2564 break;
2565
0001803f 2566 case 71:
a0c0a00f
CR
2567#line 779 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2568 { (yyval.command) = (yyvsp[0].command); }
2569#line 2570 "y.tab.c" /* yacc.c:1646 */
3185942a
JA
2570 break;
2571
0001803f 2572 case 72:
a0c0a00f
CR
2573#line 781 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2574 { (yyval.command) = (yyvsp[0].command); }
2575#line 2576 "y.tab.c" /* yacc.c:1646 */
3185942a
JA
2576 break;
2577
0001803f 2578 case 73:
a0c0a00f
CR
2579#line 783 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2580 { (yyval.command) = (yyvsp[0].command); }
2581#line 2582 "y.tab.c" /* yacc.c:1646 */
3185942a
JA
2582 break;
2583
0001803f 2584 case 74:
a0c0a00f
CR
2585#line 785 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2586 { (yyval.command) = (yyvsp[0].command); }
2587#line 2588 "y.tab.c" /* yacc.c:1646 */
3185942a
JA
2588 break;
2589
0001803f 2590 case 75:
a0c0a00f 2591#line 789 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3185942a 2592 {
a0c0a00f 2593 (yyval.command) = make_for_command ((yyvsp[-4].word), add_string_to_list ("\"$@\"", (WORD_LIST *)NULL), (yyvsp[-1].command), word_lineno[word_top]);
b80f6443 2594 if (word_top > 0) word_top--;
3185942a 2595 }
a0c0a00f 2596#line 2597 "y.tab.c" /* yacc.c:1646 */
3185942a
JA
2597 break;
2598
0001803f 2599 case 76:
a0c0a00f 2600#line 794 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3185942a 2601 {
a0c0a00f 2602 (yyval.command) = make_for_command ((yyvsp[-4].word), add_string_to_list ("\"$@\"", (WORD_LIST *)NULL), (yyvsp[-1].command), word_lineno[word_top]);
b80f6443 2603 if (word_top > 0) word_top--;
3185942a 2604 }
a0c0a00f 2605#line 2606 "y.tab.c" /* yacc.c:1646 */
3185942a
JA
2606 break;
2607
0001803f 2608 case 77:
a0c0a00f 2609#line 799 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3185942a 2610 {
a0c0a00f 2611 (yyval.command) = make_for_command ((yyvsp[-5].word), add_string_to_list ("\"$@\"", (WORD_LIST *)NULL), (yyvsp[-1].command), word_lineno[word_top]);
b80f6443 2612 if (word_top > 0) word_top--;
3185942a 2613 }
a0c0a00f 2614#line 2615 "y.tab.c" /* yacc.c:1646 */
3185942a
JA
2615 break;
2616
0001803f 2617 case 78:
a0c0a00f 2618#line 804 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3185942a 2619 {
a0c0a00f 2620 (yyval.command) = make_for_command ((yyvsp[-5].word), add_string_to_list ("\"$@\"", (WORD_LIST *)NULL), (yyvsp[-1].command), word_lineno[word_top]);
b80f6443 2621 if (word_top > 0) word_top--;
3185942a 2622 }
a0c0a00f 2623#line 2624 "y.tab.c" /* yacc.c:1646 */
3185942a
JA
2624 break;
2625
0001803f 2626 case 79:
a0c0a00f 2627#line 809 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3185942a 2628 {
a0c0a00f 2629 (yyval.command) = make_for_command ((yyvsp[-8].word), REVERSE_LIST ((yyvsp[-5].word_list), WORD_LIST *), (yyvsp[-1].command), word_lineno[word_top]);
b80f6443 2630 if (word_top > 0) word_top--;
3185942a 2631 }
a0c0a00f 2632#line 2633 "y.tab.c" /* yacc.c:1646 */
3185942a
JA
2633 break;
2634
0001803f 2635 case 80:
a0c0a00f 2636#line 814 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3185942a 2637 {
a0c0a00f 2638 (yyval.command) = make_for_command ((yyvsp[-8].word), REVERSE_LIST ((yyvsp[-5].word_list), WORD_LIST *), (yyvsp[-1].command), word_lineno[word_top]);
b80f6443 2639 if (word_top > 0) word_top--;
3185942a 2640 }
a0c0a00f 2641#line 2642 "y.tab.c" /* yacc.c:1646 */
3185942a
JA
2642 break;
2643
0001803f 2644 case 81:
a0c0a00f 2645#line 819 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3185942a 2646 {
a0c0a00f 2647 (yyval.command) = make_for_command ((yyvsp[-7].word), (WORD_LIST *)NULL, (yyvsp[-1].command), word_lineno[word_top]);
b80f6443 2648 if (word_top > 0) word_top--;
3185942a 2649 }
a0c0a00f 2650#line 2651 "y.tab.c" /* yacc.c:1646 */
3185942a
JA
2651 break;
2652
0001803f 2653 case 82:
a0c0a00f 2654#line 824 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3185942a 2655 {
a0c0a00f 2656 (yyval.command) = make_for_command ((yyvsp[-7].word), (WORD_LIST *)NULL, (yyvsp[-1].command), word_lineno[word_top]);
b80f6443 2657 if (word_top > 0) word_top--;
3185942a 2658 }
a0c0a00f 2659#line 2660 "y.tab.c" /* yacc.c:1646 */
3185942a
JA
2660 break;
2661
0001803f 2662 case 83:
a0c0a00f 2663#line 831 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3185942a 2664 {
a0c0a00f 2665 (yyval.command) = make_arith_for_command ((yyvsp[-5].word_list), (yyvsp[-1].command), arith_for_lineno);
b80f6443 2666 if (word_top > 0) word_top--;
3185942a 2667 }
a0c0a00f 2668#line 2669 "y.tab.c" /* yacc.c:1646 */
3185942a
JA
2669 break;
2670
0001803f 2671 case 84:
a0c0a00f 2672#line 836 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3185942a 2673 {
a0c0a00f 2674 (yyval.command) = make_arith_for_command ((yyvsp[-5].word_list), (yyvsp[-1].command), arith_for_lineno);
b80f6443 2675 if (word_top > 0) word_top--;
3185942a 2676 }
a0c0a00f 2677#line 2678 "y.tab.c" /* yacc.c:1646 */
3185942a
JA
2678 break;
2679
0001803f 2680 case 85:
a0c0a00f 2681#line 841 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3185942a 2682 {
a0c0a00f 2683 (yyval.command) = make_arith_for_command ((yyvsp[-3].word_list), (yyvsp[-1].command), arith_for_lineno);
b80f6443 2684 if (word_top > 0) word_top--;
3185942a 2685 }
a0c0a00f 2686#line 2687 "y.tab.c" /* yacc.c:1646 */
3185942a
JA
2687 break;
2688
0001803f 2689 case 86:
a0c0a00f 2690#line 846 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3185942a 2691 {
a0c0a00f 2692 (yyval.command) = make_arith_for_command ((yyvsp[-3].word_list), (yyvsp[-1].command), arith_for_lineno);
b80f6443 2693 if (word_top > 0) word_top--;
3185942a 2694 }
a0c0a00f 2695#line 2696 "y.tab.c" /* yacc.c:1646 */
3185942a
JA
2696 break;
2697
0001803f 2698 case 87:
a0c0a00f 2699#line 853 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3185942a 2700 {
a0c0a00f 2701 (yyval.command) = make_select_command ((yyvsp[-4].word), add_string_to_list ("\"$@\"", (WORD_LIST *)NULL), (yyvsp[-1].command), word_lineno[word_top]);
b80f6443 2702 if (word_top > 0) word_top--;
3185942a 2703 }
a0c0a00f 2704#line 2705 "y.tab.c" /* yacc.c:1646 */
3185942a
JA
2705 break;
2706
0001803f 2707 case 88:
a0c0a00f 2708#line 858 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3185942a 2709 {
a0c0a00f 2710 (yyval.command) = make_select_command ((yyvsp[-4].word), add_string_to_list ("\"$@\"", (WORD_LIST *)NULL), (yyvsp[-1].command), word_lineno[word_top]);
b80f6443 2711 if (word_top > 0) word_top--;
3185942a 2712 }
a0c0a00f 2713#line 2714 "y.tab.c" /* yacc.c:1646 */
3185942a
JA
2714 break;
2715
0001803f 2716 case 89:
a0c0a00f 2717#line 863 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3185942a 2718 {
a0c0a00f 2719 (yyval.command) = make_select_command ((yyvsp[-5].word), add_string_to_list ("\"$@\"", (WORD_LIST *)NULL), (yyvsp[-1].command), word_lineno[word_top]);
b80f6443 2720 if (word_top > 0) word_top--;
3185942a 2721 }
a0c0a00f 2722#line 2723 "y.tab.c" /* yacc.c:1646 */
3185942a
JA
2723 break;
2724
0001803f 2725 case 90:
a0c0a00f 2726#line 868 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3185942a 2727 {
a0c0a00f 2728 (yyval.command) = make_select_command ((yyvsp[-5].word), add_string_to_list ("\"$@\"", (WORD_LIST *)NULL), (yyvsp[-1].command), word_lineno[word_top]);
b80f6443 2729 if (word_top > 0) word_top--;
3185942a 2730 }
a0c0a00f 2731#line 2732 "y.tab.c" /* yacc.c:1646 */
3185942a
JA
2732 break;
2733
0001803f 2734 case 91:
a0c0a00f 2735#line 873 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3185942a 2736 {
a0c0a00f 2737 (yyval.command) = make_select_command ((yyvsp[-8].word), REVERSE_LIST ((yyvsp[-5].word_list), WORD_LIST *), (yyvsp[-1].command), word_lineno[word_top]);
b80f6443 2738 if (word_top > 0) word_top--;
3185942a 2739 }
a0c0a00f 2740#line 2741 "y.tab.c" /* yacc.c:1646 */
3185942a
JA
2741 break;
2742
0001803f 2743 case 92:
a0c0a00f 2744#line 878 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3185942a 2745 {
a0c0a00f 2746 (yyval.command) = make_select_command ((yyvsp[-8].word), REVERSE_LIST ((yyvsp[-5].word_list), WORD_LIST *), (yyvsp[-1].command), word_lineno[word_top]);
b80f6443 2747 if (word_top > 0) word_top--;
3185942a 2748 }
a0c0a00f 2749#line 2750 "y.tab.c" /* yacc.c:1646 */
3185942a
JA
2750 break;
2751
0001803f 2752 case 93:
a0c0a00f 2753#line 885 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3185942a 2754 {
a0c0a00f 2755 (yyval.command) = make_case_command ((yyvsp[-4].word), (PATTERN_LIST *)NULL, word_lineno[word_top]);
b80f6443 2756 if (word_top > 0) word_top--;
3185942a 2757 }
a0c0a00f 2758#line 2759 "y.tab.c" /* yacc.c:1646 */
3185942a
JA
2759 break;
2760
0001803f 2761 case 94:
a0c0a00f 2762#line 890 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3185942a 2763 {
a0c0a00f 2764 (yyval.command) = make_case_command ((yyvsp[-5].word), (yyvsp[-2].pattern), word_lineno[word_top]);
b80f6443 2765 if (word_top > 0) word_top--;
3185942a 2766 }
a0c0a00f 2767#line 2768 "y.tab.c" /* yacc.c:1646 */
3185942a
JA
2768 break;
2769
0001803f 2770 case 95:
a0c0a00f 2771#line 895 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3185942a 2772 {
a0c0a00f 2773 (yyval.command) = make_case_command ((yyvsp[-4].word), (yyvsp[-1].pattern), word_lineno[word_top]);
b80f6443 2774 if (word_top > 0) word_top--;
3185942a 2775 }
a0c0a00f 2776#line 2777 "y.tab.c" /* yacc.c:1646 */
3185942a
JA
2777 break;
2778
0001803f 2779 case 96:
a0c0a00f
CR
2780#line 902 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2781 { (yyval.command) = make_function_def ((yyvsp[-4].word), (yyvsp[0].command), function_dstart, function_bstart); }
2782#line 2783 "y.tab.c" /* yacc.c:1646 */
3185942a
JA
2783 break;
2784
0001803f 2785 case 97:
a0c0a00f
CR
2786#line 905 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2787 { (yyval.command) = make_function_def ((yyvsp[-4].word), (yyvsp[0].command), function_dstart, function_bstart); }
2788#line 2789 "y.tab.c" /* yacc.c:1646 */
3185942a
JA
2789 break;
2790
0001803f 2791 case 98:
a0c0a00f
CR
2792#line 908 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2793 { (yyval.command) = make_function_def ((yyvsp[-2].word), (yyvsp[0].command), function_dstart, function_bstart); }
2794#line 2795 "y.tab.c" /* yacc.c:1646 */
3185942a
JA
2795 break;
2796
0001803f 2797 case 99:
a0c0a00f
CR
2798#line 912 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2799 { (yyval.command) = (yyvsp[0].command); }
2800#line 2801 "y.tab.c" /* yacc.c:1646 */
3185942a
JA
2801 break;
2802
0001803f 2803 case 100:
a0c0a00f 2804#line 914 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3185942a 2805 {
f73dda09
JA
2806 COMMAND *tc;
2807
a0c0a00f 2808 tc = (yyvsp[-1].command);
f73dda09
JA
2809 /* According to Posix.2 3.9.5, redirections
2810 specified after the body of a function should
2811 be attached to the function and performed when
2812 the function is executed, not as part of the
2813 function definition command. */
2814 /* XXX - I don't think it matters, but we might
2815 want to change this in the future to avoid
2816 problems differentiating between a function
2817 definition with a redirection and a function
2818 definition containing a single command with a
2819 redirection. The two are semantically equivalent,
2820 though -- the only difference is in how the
2821 command printing code displays the redirections. */
2822 if (tc->redirects)
2823 {
2824 register REDIRECT *t;
2825 for (t = tc->redirects; t->next; t = t->next)
2826 ;
a0c0a00f 2827 t->next = (yyvsp[0].redirect);
f73dda09
JA
2828 }
2829 else
a0c0a00f
CR
2830 tc->redirects = (yyvsp[0].redirect);
2831 (yyval.command) = (yyvsp[-1].command);
3185942a 2832 }
a0c0a00f 2833#line 2834 "y.tab.c" /* yacc.c:1646 */
3185942a
JA
2834 break;
2835
0001803f 2836 case 101:
a0c0a00f 2837#line 945 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3185942a 2838 {
a0c0a00f 2839 (yyval.command) = make_subshell_command ((yyvsp[-1].command));
3185942a
JA
2840 (yyval.command)->flags |= CMD_WANT_SUBSHELL;
2841 }
a0c0a00f 2842#line 2843 "y.tab.c" /* yacc.c:1646 */
3185942a
JA
2843 break;
2844
0001803f 2845 case 102:
a0c0a00f 2846#line 952 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3185942a 2847 {
a0c0a00f 2848 (yyval.command) = make_coproc_command ("COPROC", (yyvsp[0].command));
3185942a
JA
2849 (yyval.command)->flags |= CMD_WANT_SUBSHELL|CMD_COPROC_SUBSHELL;
2850 }
a0c0a00f 2851#line 2852 "y.tab.c" /* yacc.c:1646 */
3185942a
JA
2852 break;
2853
0001803f 2854 case 103:
a0c0a00f 2855#line 957 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3185942a
JA
2856 {
2857 COMMAND *tc;
2858
a0c0a00f 2859 tc = (yyvsp[-1].command);
3185942a
JA
2860 if (tc->redirects)
2861 {
2862 register REDIRECT *t;
2863 for (t = tc->redirects; t->next; t = t->next)
2864 ;
a0c0a00f 2865 t->next = (yyvsp[0].redirect);
3185942a
JA
2866 }
2867 else
a0c0a00f
CR
2868 tc->redirects = (yyvsp[0].redirect);
2869 (yyval.command) = make_coproc_command ("COPROC", (yyvsp[-1].command));
3185942a
JA
2870 (yyval.command)->flags |= CMD_WANT_SUBSHELL|CMD_COPROC_SUBSHELL;
2871 }
a0c0a00f 2872#line 2873 "y.tab.c" /* yacc.c:1646 */
3185942a
JA
2873 break;
2874
0001803f 2875 case 104:
a0c0a00f 2876#line 974 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3185942a 2877 {
a0c0a00f 2878 (yyval.command) = make_coproc_command ((yyvsp[-1].word)->word, (yyvsp[0].command));
3185942a
JA
2879 (yyval.command)->flags |= CMD_WANT_SUBSHELL|CMD_COPROC_SUBSHELL;
2880 }
a0c0a00f 2881#line 2882 "y.tab.c" /* yacc.c:1646 */
3185942a
JA
2882 break;
2883
0001803f 2884 case 105:
a0c0a00f 2885#line 979 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3185942a
JA
2886 {
2887 COMMAND *tc;
2888
a0c0a00f 2889 tc = (yyvsp[-1].command);
3185942a
JA
2890 if (tc->redirects)
2891 {
2892 register REDIRECT *t;
2893 for (t = tc->redirects; t->next; t = t->next)
2894 ;
a0c0a00f 2895 t->next = (yyvsp[0].redirect);
3185942a
JA
2896 }
2897 else
a0c0a00f
CR
2898 tc->redirects = (yyvsp[0].redirect);
2899 (yyval.command) = make_coproc_command ((yyvsp[-2].word)->word, (yyvsp[-1].command));
3185942a
JA
2900 (yyval.command)->flags |= CMD_WANT_SUBSHELL|CMD_COPROC_SUBSHELL;
2901 }
a0c0a00f 2902#line 2903 "y.tab.c" /* yacc.c:1646 */
3185942a
JA
2903 break;
2904
0001803f 2905 case 106:
a0c0a00f 2906#line 996 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3185942a 2907 {
a0c0a00f 2908 (yyval.command) = make_coproc_command ("COPROC", clean_simple_command ((yyvsp[0].command)));
3185942a
JA
2909 (yyval.command)->flags |= CMD_WANT_SUBSHELL|CMD_COPROC_SUBSHELL;
2910 }
a0c0a00f 2911#line 2912 "y.tab.c" /* yacc.c:1646 */
3185942a
JA
2912 break;
2913
0001803f 2914 case 107:
a0c0a00f
CR
2915#line 1003 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2916 { (yyval.command) = make_if_command ((yyvsp[-3].command), (yyvsp[-1].command), (COMMAND *)NULL); }
2917#line 2918 "y.tab.c" /* yacc.c:1646 */
3185942a
JA
2918 break;
2919
0001803f 2920 case 108:
a0c0a00f
CR
2921#line 1005 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2922 { (yyval.command) = make_if_command ((yyvsp[-5].command), (yyvsp[-3].command), (yyvsp[-1].command)); }
2923#line 2924 "y.tab.c" /* yacc.c:1646 */
3185942a
JA
2924 break;
2925
0001803f 2926 case 109:
a0c0a00f
CR
2927#line 1007 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2928 { (yyval.command) = make_if_command ((yyvsp[-4].command), (yyvsp[-2].command), (yyvsp[-1].command)); }
2929#line 2930 "y.tab.c" /* yacc.c:1646 */
3185942a
JA
2930 break;
2931
0001803f 2932 case 110:
a0c0a00f
CR
2933#line 1012 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2934 { (yyval.command) = make_group_command ((yyvsp[-1].command)); }
2935#line 2936 "y.tab.c" /* yacc.c:1646 */
3185942a
JA
2936 break;
2937
0001803f 2938 case 111:
a0c0a00f
CR
2939#line 1016 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2940 { (yyval.command) = make_arith_command ((yyvsp[0].word_list)); }
2941#line 2942 "y.tab.c" /* yacc.c:1646 */
3185942a
JA
2942 break;
2943
0001803f 2944 case 112:
a0c0a00f
CR
2945#line 1020 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2946 { (yyval.command) = (yyvsp[-1].command); }
2947#line 2948 "y.tab.c" /* yacc.c:1646 */
3185942a
JA
2948 break;
2949
0001803f 2950 case 113:
a0c0a00f
CR
2951#line 1024 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2952 { (yyval.command) = make_if_command ((yyvsp[-2].command), (yyvsp[0].command), (COMMAND *)NULL); }
2953#line 2954 "y.tab.c" /* yacc.c:1646 */
3185942a
JA
2954 break;
2955
0001803f 2956 case 114:
a0c0a00f
CR
2957#line 1026 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2958 { (yyval.command) = make_if_command ((yyvsp[-4].command), (yyvsp[-2].command), (yyvsp[0].command)); }
2959#line 2960 "y.tab.c" /* yacc.c:1646 */
3185942a
JA
2960 break;
2961
0001803f 2962 case 115:
a0c0a00f
CR
2963#line 1028 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2964 { (yyval.command) = make_if_command ((yyvsp[-3].command), (yyvsp[-1].command), (yyvsp[0].command)); }
2965#line 2966 "y.tab.c" /* yacc.c:1646 */
3185942a
JA
2966 break;
2967
0001803f 2968 case 117:
a0c0a00f
CR
2969#line 1033 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2970 { (yyvsp[0].pattern)->next = (yyvsp[-1].pattern); (yyval.pattern) = (yyvsp[0].pattern); }
2971#line 2972 "y.tab.c" /* yacc.c:1646 */
3185942a
JA
2972 break;
2973
0001803f 2974 case 118:
a0c0a00f
CR
2975#line 1037 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2976 { (yyval.pattern) = make_pattern_list ((yyvsp[-2].word_list), (yyvsp[0].command)); }
2977#line 2978 "y.tab.c" /* yacc.c:1646 */
3185942a
JA
2978 break;
2979
0001803f 2980 case 119:
a0c0a00f
CR
2981#line 1039 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2982 { (yyval.pattern) = make_pattern_list ((yyvsp[-2].word_list), (COMMAND *)NULL); }
2983#line 2984 "y.tab.c" /* yacc.c:1646 */
3185942a
JA
2984 break;
2985
0001803f 2986 case 120:
a0c0a00f
CR
2987#line 1041 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2988 { (yyval.pattern) = make_pattern_list ((yyvsp[-2].word_list), (yyvsp[0].command)); }
2989#line 2990 "y.tab.c" /* yacc.c:1646 */
3185942a
JA
2990 break;
2991
0001803f 2992 case 121:
a0c0a00f
CR
2993#line 1043 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2994 { (yyval.pattern) = make_pattern_list ((yyvsp[-2].word_list), (COMMAND *)NULL); }
2995#line 2996 "y.tab.c" /* yacc.c:1646 */
3185942a
JA
2996 break;
2997
0001803f 2998 case 122:
a0c0a00f
CR
2999#line 1047 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3000 { (yyval.pattern) = (yyvsp[-1].pattern); }
3001#line 3002 "y.tab.c" /* yacc.c:1646 */
3185942a
JA
3002 break;
3003
0001803f 3004 case 123:
a0c0a00f
CR
3005#line 1049 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3006 { (yyvsp[-1].pattern)->next = (yyvsp[-2].pattern); (yyval.pattern) = (yyvsp[-1].pattern); }
3007#line 3008 "y.tab.c" /* yacc.c:1646 */
3185942a
JA
3008 break;
3009
0001803f 3010 case 124:
a0c0a00f
CR
3011#line 1051 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3012 { (yyvsp[-1].pattern)->flags |= CASEPAT_FALLTHROUGH; (yyval.pattern) = (yyvsp[-1].pattern); }
3013#line 3014 "y.tab.c" /* yacc.c:1646 */
3185942a
JA
3014 break;
3015
0001803f 3016 case 125:
a0c0a00f
CR
3017#line 1053 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3018 { (yyvsp[-1].pattern)->flags |= CASEPAT_FALLTHROUGH; (yyvsp[-1].pattern)->next = (yyvsp[-2].pattern); (yyval.pattern) = (yyvsp[-1].pattern); }
3019#line 3020 "y.tab.c" /* yacc.c:1646 */
3185942a
JA
3020 break;
3021
0001803f 3022 case 126:
a0c0a00f
CR
3023#line 1055 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3024 { (yyvsp[-1].pattern)->flags |= CASEPAT_TESTNEXT; (yyval.pattern) = (yyvsp[-1].pattern); }
3025#line 3026 "y.tab.c" /* yacc.c:1646 */
3185942a
JA
3026 break;
3027
0001803f 3028 case 127:
a0c0a00f
CR
3029#line 1057 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3030 { (yyvsp[-1].pattern)->flags |= CASEPAT_TESTNEXT; (yyvsp[-1].pattern)->next = (yyvsp[-2].pattern); (yyval.pattern) = (yyvsp[-1].pattern); }
3031#line 3032 "y.tab.c" /* yacc.c:1646 */
3185942a
JA
3032 break;
3033
0001803f 3034 case 128:
a0c0a00f
CR
3035#line 1061 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3036 { (yyval.word_list) = make_word_list ((yyvsp[0].word), (WORD_LIST *)NULL); }
3037#line 3038 "y.tab.c" /* yacc.c:1646 */
3185942a
JA
3038 break;
3039
0001803f 3040 case 129:
a0c0a00f
CR
3041#line 1063 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3042 { (yyval.word_list) = make_word_list ((yyvsp[0].word), (yyvsp[-2].word_list)); }
3043#line 3044 "y.tab.c" /* yacc.c:1646 */
3185942a
JA
3044 break;
3045
0001803f 3046 case 130:
a0c0a00f 3047#line 1072 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3185942a 3048 {
a0c0a00f 3049 (yyval.command) = (yyvsp[0].command);
f73dda09
JA
3050 if (need_here_doc)
3051 gather_here_documents ();
3185942a 3052 }
a0c0a00f 3053#line 3054 "y.tab.c" /* yacc.c:1646 */
3185942a
JA
3054 break;
3055
0001803f 3056 case 132:
a0c0a00f 3057#line 1081 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3185942a 3058 {
a0c0a00f 3059 (yyval.command) = (yyvsp[0].command);
3185942a 3060 }
a0c0a00f 3061#line 3062 "y.tab.c" /* yacc.c:1646 */
3185942a
JA
3062 break;
3063
0001803f 3064 case 134:
a0c0a00f 3065#line 1088 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3185942a 3066 {
a0c0a00f
CR
3067 if ((yyvsp[-2].command)->type == cm_connection)
3068 (yyval.command) = connect_async_list ((yyvsp[-2].command), (COMMAND *)NULL, '&');
f73dda09 3069 else
a0c0a00f 3070 (yyval.command) = command_connect ((yyvsp[-2].command), (COMMAND *)NULL, '&');
3185942a 3071 }
a0c0a00f 3072#line 3073 "y.tab.c" /* yacc.c:1646 */
3185942a
JA
3073 break;
3074
0001803f 3075 case 136:
a0c0a00f
CR
3076#line 1099 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3077 { (yyval.command) = command_connect ((yyvsp[-3].command), (yyvsp[0].command), AND_AND); }
3078#line 3079 "y.tab.c" /* yacc.c:1646 */
3185942a
JA
3079 break;
3080
0001803f 3081 case 137:
a0c0a00f
CR
3082#line 1101 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3083 { (yyval.command) = command_connect ((yyvsp[-3].command), (yyvsp[0].command), OR_OR); }
3084#line 3085 "y.tab.c" /* yacc.c:1646 */
3185942a
JA
3085 break;
3086
0001803f 3087 case 138:
a0c0a00f 3088#line 1103 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3185942a 3089 {
a0c0a00f
CR
3090 if ((yyvsp[-3].command)->type == cm_connection)
3091 (yyval.command) = connect_async_list ((yyvsp[-3].command), (yyvsp[0].command), '&');
f73dda09 3092 else
a0c0a00f 3093 (yyval.command) = command_connect ((yyvsp[-3].command), (yyvsp[0].command), '&');
3185942a 3094 }
a0c0a00f 3095#line 3096 "y.tab.c" /* yacc.c:1646 */
3185942a
JA
3096 break;
3097
0001803f 3098 case 139:
a0c0a00f
CR
3099#line 1110 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3100 { (yyval.command) = command_connect ((yyvsp[-3].command), (yyvsp[0].command), ';'); }
3101#line 3102 "y.tab.c" /* yacc.c:1646 */
3185942a
JA
3102 break;
3103
0001803f 3104 case 140:
a0c0a00f
CR
3105#line 1112 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3106 { (yyval.command) = command_connect ((yyvsp[-3].command), (yyvsp[0].command), ';'); }
3107#line 3108 "y.tab.c" /* yacc.c:1646 */
3185942a
JA
3108 break;
3109
0001803f 3110 case 141:
a0c0a00f
CR
3111#line 1114 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3112 { (yyval.command) = (yyvsp[0].command); }
3113#line 3114 "y.tab.c" /* yacc.c:1646 */
3185942a
JA
3114 break;
3115
0001803f 3116 case 144:
a0c0a00f 3117#line 1122 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3185942a 3118 { (yyval.number) = '\n'; }
a0c0a00f 3119#line 3120 "y.tab.c" /* yacc.c:1646 */
3185942a
JA
3120 break;
3121
0001803f 3122 case 145:
a0c0a00f 3123#line 1124 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3185942a 3124 { (yyval.number) = ';'; }
a0c0a00f 3125#line 3126 "y.tab.c" /* yacc.c:1646 */
3185942a
JA
3126 break;
3127
0001803f 3128 case 146:
a0c0a00f 3129#line 1126 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3185942a 3130 { (yyval.number) = yacc_EOF; }
a0c0a00f 3131#line 3132 "y.tab.c" /* yacc.c:1646 */
3185942a
JA
3132 break;
3133
0001803f 3134 case 149:
a0c0a00f 3135#line 1140 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3185942a 3136 {
a0c0a00f 3137 (yyval.command) = (yyvsp[0].command);
f73dda09
JA
3138 if (need_here_doc)
3139 gather_here_documents ();
3185942a
JA
3140 if ((parser_state & PST_CMDSUBST) && current_token == shell_eof_token)
3141 {
a0c0a00f 3142 global_command = (yyvsp[0].command);
3185942a
JA
3143 eof_encountered = 0;
3144 rewind_input_string ();
3145 YYACCEPT;
3146 }
3147 }
a0c0a00f 3148#line 3149 "y.tab.c" /* yacc.c:1646 */
3185942a
JA
3149 break;
3150
0001803f 3151 case 150:
a0c0a00f 3152#line 1153 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3185942a 3153 {
a0c0a00f
CR
3154 if ((yyvsp[-1].command)->type == cm_connection)
3155 (yyval.command) = connect_async_list ((yyvsp[-1].command), (COMMAND *)NULL, '&');
f73dda09 3156 else
a0c0a00f 3157 (yyval.command) = command_connect ((yyvsp[-1].command), (COMMAND *)NULL, '&');
f73dda09
JA
3158 if (need_here_doc)
3159 gather_here_documents ();
3185942a
JA
3160 if ((parser_state & PST_CMDSUBST) && current_token == shell_eof_token)
3161 {
a0c0a00f 3162 global_command = (yyvsp[-1].command);
3185942a
JA
3163 eof_encountered = 0;
3164 rewind_input_string ();
3165 YYACCEPT;
3166 }
3167 }
a0c0a00f 3168#line 3169 "y.tab.c" /* yacc.c:1646 */
3185942a
JA
3169 break;
3170
0001803f 3171 case 151:
a0c0a00f 3172#line 1169 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3185942a 3173 {
a0c0a00f 3174 (yyval.command) = (yyvsp[-1].command);
f73dda09
JA
3175 if (need_here_doc)
3176 gather_here_documents ();
3185942a
JA
3177 if ((parser_state & PST_CMDSUBST) && current_token == shell_eof_token)
3178 {
a0c0a00f 3179 global_command = (yyvsp[-1].command);
3185942a
JA
3180 eof_encountered = 0;
3181 rewind_input_string ();
3182 YYACCEPT;
3183 }
3184 }
a0c0a00f 3185#line 3186 "y.tab.c" /* yacc.c:1646 */
3185942a
JA
3186 break;
3187
0001803f 3188 case 152:
a0c0a00f
CR
3189#line 1184 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3190 { (yyval.command) = command_connect ((yyvsp[-3].command), (yyvsp[0].command), AND_AND); }
3191#line 3192 "y.tab.c" /* yacc.c:1646 */
3185942a
JA
3192 break;
3193
0001803f 3194 case 153:
a0c0a00f
CR
3195#line 1186 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3196 { (yyval.command) = command_connect ((yyvsp[-3].command), (yyvsp[0].command), OR_OR); }
3197#line 3198 "y.tab.c" /* yacc.c:1646 */
3185942a
JA
3198 break;
3199
0001803f 3200 case 154:
a0c0a00f 3201#line 1188 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3185942a 3202 {
a0c0a00f
CR
3203 if ((yyvsp[-2].command)->type == cm_connection)
3204 (yyval.command) = connect_async_list ((yyvsp[-2].command), (yyvsp[0].command), '&');
f73dda09 3205 else
a0c0a00f 3206 (yyval.command) = command_connect ((yyvsp[-2].command), (yyvsp[0].command), '&');
3185942a 3207 }
a0c0a00f 3208#line 3209 "y.tab.c" /* yacc.c:1646 */
3185942a
JA
3209 break;
3210
0001803f 3211 case 155:
a0c0a00f
CR
3212#line 1195 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3213 { (yyval.command) = command_connect ((yyvsp[-2].command), (yyvsp[0].command), ';'); }
3214#line 3215 "y.tab.c" /* yacc.c:1646 */
3185942a
JA
3215 break;
3216
0001803f 3217 case 156:
a0c0a00f
CR
3218#line 1198 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3219 { (yyval.command) = (yyvsp[0].command); }
3220#line 3221 "y.tab.c" /* yacc.c:1646 */
3185942a
JA
3221 break;
3222
0001803f 3223 case 157:
a0c0a00f
CR
3224#line 1202 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3225 { (yyval.command) = (yyvsp[0].command); }
3226#line 3227 "y.tab.c" /* yacc.c:1646 */
3185942a
JA
3227 break;
3228
0001803f 3229 case 158:
a0c0a00f 3230#line 1204 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3185942a 3231 {
a0c0a00f
CR
3232 if ((yyvsp[0].command))
3233 (yyvsp[0].command)->flags ^= CMD_INVERT_RETURN; /* toggle */
3234 (yyval.command) = (yyvsp[0].command);
3185942a 3235 }
a0c0a00f 3236#line 3237 "y.tab.c" /* yacc.c:1646 */
3185942a
JA
3237 break;
3238
0001803f 3239 case 159:
a0c0a00f 3240#line 1210 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3185942a 3241 {
a0c0a00f
CR
3242 if ((yyvsp[0].command))
3243 (yyvsp[0].command)->flags |= (yyvsp[-1].number);
3244 (yyval.command) = (yyvsp[0].command);
3185942a 3245 }
a0c0a00f 3246#line 3247 "y.tab.c" /* yacc.c:1646 */
3185942a
JA
3247 break;
3248
0001803f 3249 case 160:
a0c0a00f 3250#line 1216 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3185942a 3251 {
495aee44 3252 ELEMENT x;
3185942a 3253
495aee44
CR
3254 /* Boy, this is unclean. `time' by itself can
3255 time a null command. We cheat and push a
3256 newline back if the list_terminator was a newline
3257 to avoid the double-newline problem (one to
3258 terminate this, one to terminate the command) */
3259 x.word = 0;
3260 x.redirect = 0;
3261 (yyval.command) = make_simple_command (x, (COMMAND *)NULL);
a0c0a00f 3262 (yyval.command)->flags |= (yyvsp[-1].number);
495aee44 3263 /* XXX - let's cheat and push a newline back */
a0c0a00f 3264 if ((yyvsp[0].number) == '\n')
495aee44 3265 token_to_read = '\n';
a0c0a00f
CR
3266 else if ((yyvsp[0].number) == ';')
3267 token_to_read = ';';
3185942a 3268 }
a0c0a00f 3269#line 3270 "y.tab.c" /* yacc.c:1646 */
3185942a
JA
3270 break;
3271
495aee44 3272 case 161:
a0c0a00f 3273#line 1235 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3185942a 3274 {
b80f6443
JA
3275 ELEMENT x;
3276
495aee44
CR
3277 /* This is just as unclean. Posix says that `!'
3278 by itself should be equivalent to `false'.
3279 We cheat and push a
b80f6443
JA
3280 newline back if the list_terminator was a newline
3281 to avoid the double-newline problem (one to
3282 terminate this, one to terminate the command) */
3283 x.word = 0;
3284 x.redirect = 0;
3185942a 3285 (yyval.command) = make_simple_command (x, (COMMAND *)NULL);
495aee44 3286 (yyval.command)->flags |= CMD_INVERT_RETURN;
b80f6443 3287 /* XXX - let's cheat and push a newline back */
a0c0a00f 3288 if ((yyvsp[0].number) == '\n')
b80f6443 3289 token_to_read = '\n';
a0c0a00f
CR
3290 if ((yyvsp[0].number) == ';')
3291 token_to_read = ';';
3185942a 3292 }
a0c0a00f 3293#line 3294 "y.tab.c" /* yacc.c:1646 */
3185942a 3294 break;
f73dda09 3295
495aee44 3296 case 162:
a0c0a00f
CR
3297#line 1257 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3298 { (yyval.command) = command_connect ((yyvsp[-3].command), (yyvsp[0].command), '|'); }
3299#line 3300 "y.tab.c" /* yacc.c:1646 */
3185942a
JA
3300 break;
3301
495aee44 3302 case 163:
a0c0a00f 3303#line 1259 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
f73dda09 3304 {
3185942a
JA
3305 /* Make cmd1 |& cmd2 equivalent to cmd1 2>&1 | cmd2 */
3306 COMMAND *tc;
0001803f 3307 REDIRECTEE rd, sd;
3185942a
JA
3308 REDIRECT *r;
3309
a0c0a00f 3310 tc = (yyvsp[-3].command)->type == cm_simple ? (COMMAND *)(yyvsp[-3].command)->value.Simple : (yyvsp[-3].command);
0001803f 3311 sd.dest = 2;
3185942a 3312 rd.dest = 1;
0001803f 3313 r = make_redirection (sd, r_duplicating_output, rd, 0);
3185942a
JA
3314 if (tc->redirects)
3315 {
3316 register REDIRECT *t;
3317 for (t = tc->redirects; t->next; t = t->next)
3318 ;
3319 t->next = r;
3320 }
3321 else
3322 tc->redirects = r;
3323
a0c0a00f 3324 (yyval.command) = command_connect ((yyvsp[-3].command), (yyvsp[0].command), '|');
3185942a 3325 }
a0c0a00f 3326#line 3327 "y.tab.c" /* yacc.c:1646 */
3185942a
JA
3327 break;
3328
495aee44 3329 case 164:
a0c0a00f
CR
3330#line 1282 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3331 { (yyval.command) = (yyvsp[0].command); }
3332#line 3333 "y.tab.c" /* yacc.c:1646 */
3185942a
JA
3333 break;
3334
495aee44 3335 case 165:
a0c0a00f 3336#line 1286 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3185942a 3337 { (yyval.number) = CMD_TIME_PIPELINE; }
a0c0a00f 3338#line 3339 "y.tab.c" /* yacc.c:1646 */
3185942a
JA
3339 break;
3340
495aee44 3341 case 166:
a0c0a00f 3342#line 1288 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
495aee44 3343 { (yyval.number) = CMD_TIME_PIPELINE|CMD_TIME_POSIX; }
a0c0a00f 3344#line 3345 "y.tab.c" /* yacc.c:1646 */
495aee44
CR
3345 break;
3346
0001803f 3347 case 167:
a0c0a00f 3348#line 1290 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3185942a 3349 { (yyval.number) = CMD_TIME_PIPELINE|CMD_TIME_POSIX; }
a0c0a00f 3350#line 3351 "y.tab.c" /* yacc.c:1646 */
3185942a
JA
3351 break;
3352
3353
a0c0a00f 3354#line 3355 "y.tab.c" /* yacc.c:1646 */
3185942a 3355 default: break;
f73dda09 3356 }
a0c0a00f
CR
3357 /* User semantic actions sometimes alter yychar, and that requires
3358 that yytoken be updated with the new translation. We take the
3359 approach of translating immediately before every use of yytoken.
3360 One alternative is translating here after every semantic action,
3361 but that translation would be missed if the semantic action invokes
3362 YYABORT, YYACCEPT, or YYERROR immediately after altering yychar or
3363 if it invokes YYBACKUP. In the case of YYABORT or YYACCEPT, an
3364 incorrect destructor might then be invoked immediately. In the
3365 case of YYERROR or YYBACKUP, subsequent parser actions might lead
3366 to an incorrect destructor call or verbose syntax error message
3367 before the lookahead is translated. */
3185942a
JA
3368 YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc);
3369
3370 YYPOPSTACK (yylen);
3371 yylen = 0;
3372 YY_STACK_PRINT (yyss, yyssp);
f73dda09
JA
3373
3374 *++yyvsp = yyval;
b80f6443 3375
a0c0a00f 3376 /* Now 'shift' the result of the reduction. Determine what state
3185942a
JA
3377 that goes to, based on the state we popped back to and the rule
3378 number reduced by. */
f73dda09
JA
3379
3380 yyn = yyr1[yyn];
3381
3185942a
JA
3382 yystate = yypgoto[yyn - YYNTOKENS] + *yyssp;
3383 if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp)
f73dda09
JA
3384 yystate = yytable[yystate];
3385 else
3185942a 3386 yystate = yydefgoto[yyn - YYNTOKENS];
f73dda09
JA
3387
3388 goto yynewstate;
3389
f73dda09 3390
a0c0a00f
CR
3391/*--------------------------------------.
3392| yyerrlab -- here on detecting error. |
3393`--------------------------------------*/
3185942a 3394yyerrlab:
a0c0a00f
CR
3395 /* Make sure we have latest lookahead translation. See comments at
3396 user semantic actions for why this is necessary. */
3397 yytoken = yychar == YYEMPTY ? YYEMPTY : YYTRANSLATE (yychar);
3398
3185942a
JA
3399 /* If not already recovering from an error, report this error. */
3400 if (!yyerrstatus)
f73dda09
JA
3401 {
3402 ++yynerrs;
3185942a
JA
3403#if ! YYERROR_VERBOSE
3404 yyerror (YY_("syntax error"));
3405#else
a0c0a00f
CR
3406# define YYSYNTAX_ERROR yysyntax_error (&yymsg_alloc, &yymsg, \
3407 yyssp, yytoken)
3185942a 3408 {
a0c0a00f
CR
3409 char const *yymsgp = YY_("syntax error");
3410 int yysyntax_error_status;
3411 yysyntax_error_status = YYSYNTAX_ERROR;
3412 if (yysyntax_error_status == 0)
3413 yymsgp = yymsg;
3414 else if (yysyntax_error_status == 1)
3415 {
3416 if (yymsg != yymsgbuf)
3417 YYSTACK_FREE (yymsg);
3418 yymsg = (char *) YYSTACK_ALLOC (yymsg_alloc);
3419 if (!yymsg)
3420 {
3421 yymsg = yymsgbuf;
3422 yymsg_alloc = sizeof yymsgbuf;
3423 yysyntax_error_status = 2;
3424 }
3425 else
3426 {
3427 yysyntax_error_status = YYSYNTAX_ERROR;
3428 yymsgp = yymsg;
3429 }
3430 }
3431 yyerror (yymsgp);
3432 if (yysyntax_error_status == 2)
3433 goto yyexhaustedlab;
3185942a 3434 }
a0c0a00f 3435# undef YYSYNTAX_ERROR
3185942a 3436#endif
f73dda09 3437 }
f73dda09 3438
3185942a 3439
7117c2d2 3440
f73dda09
JA
3441 if (yyerrstatus == 3)
3442 {
a0c0a00f
CR
3443 /* If just tried and failed to reuse lookahead token after an
3444 error, discard it. */
b80f6443 3445
3185942a 3446 if (yychar <= YYEOF)
a0c0a00f
CR
3447 {
3448 /* Return failure if at end of input. */
3449 if (yychar == YYEOF)
3450 YYABORT;
3451 }
3185942a 3452 else
a0c0a00f
CR
3453 {
3454 yydestruct ("Error: discarding",
3455 yytoken, &yylval);
3456 yychar = YYEMPTY;
3457 }
f73dda09
JA
3458 }
3459
a0c0a00f 3460 /* Else will try to reuse lookahead token after shifting the error
3185942a
JA
3461 token. */
3462 goto yyerrlab1;
f73dda09 3463
f73dda09 3464
3185942a
JA
3465/*---------------------------------------------------.
3466| yyerrorlab -- error raised explicitly by YYERROR. |
3467`---------------------------------------------------*/
3468yyerrorlab:
f73dda09 3469
3185942a
JA
3470 /* Pacify compilers like GCC when the user code never invokes
3471 YYERROR and the label yyerrorlab therefore never appears in user
3472 code. */
3473 if (/*CONSTCOND*/ 0)
3474 goto yyerrorlab;
f73dda09 3475
a0c0a00f 3476 /* Do not reclaim the symbols of the rule whose action triggered
3185942a
JA
3477 this YYERROR. */
3478 YYPOPSTACK (yylen);
3479 yylen = 0;
3480 YY_STACK_PRINT (yyss, yyssp);
3481 yystate = *yyssp;
3482 goto yyerrlab1;
f73dda09 3483
f73dda09 3484
3185942a
JA
3485/*-------------------------------------------------------------.
3486| yyerrlab1 -- common code for both syntax error and YYERROR. |
3487`-------------------------------------------------------------*/
3488yyerrlab1:
a0c0a00f 3489 yyerrstatus = 3; /* Each real token shifted decrements this. */
f73dda09 3490
3185942a 3491 for (;;)
f73dda09 3492 {
3185942a 3493 yyn = yypact[yystate];
a0c0a00f
CR
3494 if (!yypact_value_is_default (yyn))
3495 {
3496 yyn += YYTERROR;
3497 if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
3498 {
3499 yyn = yytable[yyn];
3500 if (0 < yyn)
3501 break;
3502 }
3503 }
b80f6443 3504
3185942a
JA
3505 /* Pop the current state because it cannot handle the error token. */
3506 if (yyssp == yyss)
a0c0a00f 3507 YYABORT;
f73dda09 3508
f73dda09 3509
3185942a 3510 yydestruct ("Error: popping",
a0c0a00f 3511 yystos[yystate], yyvsp);
3185942a
JA
3512 YYPOPSTACK (1);
3513 yystate = *yyssp;
3514 YY_STACK_PRINT (yyss, yyssp);
f73dda09 3515 }
f73dda09 3516
a0c0a00f 3517 YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
f73dda09 3518 *++yyvsp = yylval;
a0c0a00f 3519 YY_IGNORE_MAYBE_UNINITIALIZED_END
3185942a
JA
3520
3521
3522 /* Shift the error token. */
3523 YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp);
f73dda09
JA
3524
3525 yystate = yyn;
3526 goto yynewstate;
3527
3185942a
JA
3528
3529/*-------------------------------------.
3530| yyacceptlab -- YYACCEPT comes here. |
3531`-------------------------------------*/
3532yyacceptlab:
3533 yyresult = 0;
3534 goto yyreturn;
3535
3536/*-----------------------------------.
3537| yyabortlab -- YYABORT comes here. |
3538`-----------------------------------*/
3539yyabortlab:
3540 yyresult = 1;
3541 goto yyreturn;
3542
a0c0a00f 3543#if !defined yyoverflow || YYERROR_VERBOSE
3185942a
JA
3544/*-------------------------------------------------.
3545| yyexhaustedlab -- memory exhaustion comes here. |
3546`-------------------------------------------------*/
3547yyexhaustedlab:
3548 yyerror (YY_("memory exhausted"));
3549 yyresult = 2;
3550 /* Fall through. */
b80f6443 3551#endif
f73dda09 3552
3185942a 3553yyreturn:
a0c0a00f
CR
3554 if (yychar != YYEMPTY)
3555 {
3556 /* Make sure we have latest lookahead translation. See comments at
3557 user semantic actions for why this is necessary. */
3558 yytoken = YYTRANSLATE (yychar);
3559 yydestruct ("Cleanup: discarding lookahead",
3560 yytoken, &yylval);
3561 }
3562 /* Do not reclaim the symbols of the rule whose action triggered
3185942a
JA
3563 this YYABORT or YYACCEPT. */
3564 YYPOPSTACK (yylen);
3565 YY_STACK_PRINT (yyss, yyssp);
3566 while (yyssp != yyss)
b80f6443 3567 {
3185942a 3568 yydestruct ("Cleanup: popping",
a0c0a00f 3569 yystos[*yyssp], yyvsp);
3185942a 3570 YYPOPSTACK (1);
b80f6443 3571 }
3185942a
JA
3572#ifndef yyoverflow
3573 if (yyss != yyssa)
3574 YYSTACK_FREE (yyss);
3575#endif
3576#if YYERROR_VERBOSE
3577 if (yymsg != yymsgbuf)
3578 YYSTACK_FREE (yymsg);
3579#endif
a0c0a00f 3580 return yyresult;
f73dda09 3581}
a0c0a00f 3582#line 1292 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1906 */
3185942a 3583
f73dda09
JA
3584
3585/* Initial size to allocate for tokens, and the
3586 amount to grow them by. */
3587#define TOKEN_DEFAULT_INITIAL_SIZE 496
3588#define TOKEN_DEFAULT_GROW_SIZE 512
3589
b80f6443
JA
3590/* Should we call prompt_again? */
3591#define SHOULD_PROMPT() \
3592 (interactive && (bash_input.type == st_stdin || bash_input.type == st_stream))
3593
3594#if defined (ALIAS)
3595# define expanding_alias() (pushed_string_list && pushed_string_list->expander)
3596#else
3597# define expanding_alias() 0
3598#endif
3599
f73dda09
JA
3600/* Global var is non-zero when end of file has been reached. */
3601int EOF_Reached = 0;
3602
3603#ifdef DEBUG
3604static void
3605debug_parser (i)
3606 int i;
3607{
3608#if YYDEBUG != 0
3609 yydebug = i;
3610#endif
3611}
3612#endif
3613
3614/* yy_getc () returns the next available character from input or EOF.
3615 yy_ungetc (c) makes `c' the next character to read.
3616 init_yy_io (get, unget, type, location) makes the function GET the
3617 installed function for getting the next character, makes UNGET the
3618 installed function for un-getting a character, sets the type of stream
3619 (either string or file) from TYPE, and makes LOCATION point to where
3620 the input is coming from. */
3621
3622/* Unconditionally returns end-of-file. */
3623int
3624return_EOF ()
3625{
3626 return (EOF);
3627}
3628
3629/* Variable containing the current get and unget functions.
3630 See ./input.h for a clearer description. */
3631BASH_INPUT bash_input;
3632
3633/* Set all of the fields in BASH_INPUT to NULL. Free bash_input.name if it
3634 is non-null, avoiding a memory leak. */
3635void
3636initialize_bash_input ()
3637{
3638 bash_input.type = st_none;
3639 FREE (bash_input.name);
3640 bash_input.name = (char *)NULL;
3641 bash_input.location.file = (FILE *)NULL;
3642 bash_input.location.string = (char *)NULL;
3643 bash_input.getter = (sh_cget_func_t *)NULL;
3644 bash_input.ungetter = (sh_cunget_func_t *)NULL;
3645}
3646
3647/* Set the contents of the current bash input stream from
3648 GET, UNGET, TYPE, NAME, and LOCATION. */
3649void
3650init_yy_io (get, unget, type, name, location)
3651 sh_cget_func_t *get;
3652 sh_cunget_func_t *unget;
3653 enum stream_type type;
3654 const char *name;
3655 INPUT_STREAM location;
3656{
3657 bash_input.type = type;
3658 FREE (bash_input.name);
3659 bash_input.name = name ? savestring (name) : (char *)NULL;
3660
3661 /* XXX */
3662#if defined (CRAY)
3663 memcpy((char *)&bash_input.location.string, (char *)&location.string, sizeof(location));
3664#else
3665 bash_input.location = location;
3666#endif
3667 bash_input.getter = get;
3668 bash_input.ungetter = unget;
3669}
3670
7117c2d2
JA
3671char *
3672yy_input_name ()
3673{
3674 return (bash_input.name ? bash_input.name : "stdin");
3675}
3676
f73dda09
JA
3677/* Call this to get the next character of input. */
3678static int
3679yy_getc ()
3680{
3681 return (*(bash_input.getter)) ();
3682}
3683
3684/* Call this to unget C. That is, to make C the next character
3685 to be read. */
3686static int
3687yy_ungetc (c)
3688 int c;
3689{
3690 return (*(bash_input.ungetter)) (c);
3691}
3692
3693#if defined (BUFFERED_INPUT)
3694#ifdef INCLUDE_UNUSED
3695int
3696input_file_descriptor ()
3697{
3698 switch (bash_input.type)
3699 {
3700 case st_stream:
3701 return (fileno (bash_input.location.file));
3702 case st_bstream:
3703 return (bash_input.location.buffered_fd);
3704 case st_stdin:
3705 default:
3706 return (fileno (stdin));
3707 }
3708}
3709#endif
3710#endif /* BUFFERED_INPUT */
3711
3712/* **************************************************************** */
3713/* */
3714/* Let input be read from readline (). */
3715/* */
3716/* **************************************************************** */
3717
3718#if defined (READLINE)
3719char *current_readline_prompt = (char *)NULL;
3720char *current_readline_line = (char *)NULL;
3721int current_readline_line_index = 0;
3722
3723static int
3724yy_readline_get ()
3725{
3726 SigHandler *old_sigint;
3727 int line_len;
3728 unsigned char c;
3729
a0c0a00f 3730 if (current_readline_line == 0)
f73dda09 3731 {
a0c0a00f 3732 if (bash_readline_initialized == 0)
f73dda09
JA
3733 initialize_readline ();
3734
3735#if defined (JOB_CONTROL)
3736 if (job_control)
3737 give_terminal_to (shell_pgrp, 0);
3738#endif /* JOB_CONTROL */
3739
a0c0a00f 3740 old_sigint = IMPOSSIBLE_TRAP_HANDLER;
f73dda09
JA
3741 if (signal_is_ignored (SIGINT) == 0)
3742 {
ac50fbac 3743 /* interrupt_immediately++; */
495aee44 3744 old_sigint = (SigHandler *)set_signal_handler (SIGINT, sigint_sighandler);
f73dda09
JA
3745 }
3746
3747 current_readline_line = readline (current_readline_prompt ?
3748 current_readline_prompt : "");
3749
ac50fbac 3750 CHECK_TERMSIG;
495aee44 3751 if (signal_is_ignored (SIGINT) == 0)
f73dda09 3752 {
ac50fbac 3753 /* interrupt_immediately--; */
495aee44
CR
3754 if (old_sigint != IMPOSSIBLE_TRAP_HANDLER)
3755 set_signal_handler (SIGINT, old_sigint);
f73dda09
JA
3756 }
3757
3758#if 0
3759 /* Reset the prompt to the decoded value of prompt_string_pointer. */
3760 reset_readline_prompt ();
3761#endif
3762
3763 if (current_readline_line == 0)
3764 return (EOF);
3765
3766 current_readline_line_index = 0;
3767 line_len = strlen (current_readline_line);
3768
3769 current_readline_line = (char *)xrealloc (current_readline_line, 2 + line_len);
3770 current_readline_line[line_len++] = '\n';
3771 current_readline_line[line_len] = '\0';
3772 }
3773
3774 if (current_readline_line[current_readline_line_index] == 0)
3775 {
3776 free (current_readline_line);
3777 current_readline_line = (char *)NULL;
3778 return (yy_readline_get ());
3779 }
3780 else
3781 {
3782 c = current_readline_line[current_readline_line_index++];
3783 return (c);
3784 }
3785}
3786
3787static int
3788yy_readline_unget (c)
3789 int c;
3790{
3791 if (current_readline_line_index && current_readline_line)
3792 current_readline_line[--current_readline_line_index] = c;
3793 return (c);
3794}
3795
3796void
3797with_input_from_stdin ()
3798{
3799 INPUT_STREAM location;
3800
3801 if (bash_input.type != st_stdin && stream_on_stack (st_stdin) == 0)
3802 {
3803 location.string = current_readline_line;
3804 init_yy_io (yy_readline_get, yy_readline_unget,
3805 st_stdin, "readline stdin", location);
3806 }
3807}
3808
3809#else /* !READLINE */
3810
3811void
3812with_input_from_stdin ()
3813{
3814 with_input_from_stream (stdin, "stdin");
3815}
3816#endif /* !READLINE */
3817
3818/* **************************************************************** */
3819/* */
3820/* Let input come from STRING. STRING is zero terminated. */
3821/* */
3822/* **************************************************************** */
3823
3824static int
3825yy_string_get ()
3826{
3827 register char *string;
3828 register unsigned char c;
3829
3830 string = bash_input.location.string;
3831
3832 /* If the string doesn't exist, or is empty, EOF found. */
3833 if (string && *string)
3834 {
3835 c = *string++;
3836 bash_input.location.string = string;
3837 return (c);
3838 }
3839 else
3840 return (EOF);
3841}
3842
3843static int
3844yy_string_unget (c)
3845 int c;
3846{
3847 *(--bash_input.location.string) = c;
3848 return (c);
3849}
3850
3851void
3852with_input_from_string (string, name)
3853 char *string;
3854 const char *name;
3855{
3856 INPUT_STREAM location;
3857
3858 location.string = string;
3859 init_yy_io (yy_string_get, yy_string_unget, st_string, name, location);
3860}
3861
3185942a
JA
3862/* Count the number of characters we've consumed from bash_input.location.string
3863 and read into shell_input_line, but have not returned from shell_getc.
3864 That is the true input location. Rewind bash_input.location.string by
3865 that number of characters, so it points to the last character actually
3866 consumed by the parser. */
3867static void
3868rewind_input_string ()
3869{
3870 int xchars;
3871
3872 /* number of unconsumed characters in the input -- XXX need to take newlines
3873 into account, e.g., $(...\n) */
3874 xchars = shell_input_line_len - shell_input_line_index;
3875 if (bash_input.location.string[-1] == '\n')
3876 xchars++;
3877
3878 /* XXX - how to reflect bash_input.location.string back to string passed to
3879 parse_and_execute or xparse_dolparen? xparse_dolparen needs to know how
3880 far into the string we parsed. parse_and_execute knows where bash_input.
3881 location.string is, and how far from orig_string that is -- that's the
3882 number of characters the command consumed. */
3883
3884 /* bash_input.location.string - xchars should be where we parsed to */
3885 /* need to do more validation on xchars value for sanity -- test cases. */
3886 bash_input.location.string -= xchars;
3887}
3888
f73dda09
JA
3889/* **************************************************************** */
3890/* */
3891/* Let input come from STREAM. */
3892/* */
3893/* **************************************************************** */
3894
3895/* These two functions used to test the value of the HAVE_RESTARTABLE_SYSCALLS
3896 define, and just use getc/ungetc if it was defined, but since bash
3897 installs its signal handlers without the SA_RESTART flag, some signals
3898 (like SIGCHLD, SIGWINCH, etc.) received during a read(2) will not cause
3899 the read to be restarted. We need to restart it ourselves. */
3900
3901static int
3902yy_stream_get ()
3903{
3904 int result;
3905
3906 result = EOF;
3907 if (bash_input.location.file)
95732b49 3908 {
ac50fbac 3909#if 0
95732b49 3910 if (interactive)
ac50fbac
CR
3911 interrupt_immediately++;
3912#endif
3913
3914 /* XXX - don't need terminate_immediately; getc_with_restart checks
3915 for terminating signals itself if read returns < 0 */
95732b49 3916 result = getc_with_restart (bash_input.location.file);
ac50fbac
CR
3917
3918#if 0
95732b49 3919 if (interactive)
ac50fbac
CR
3920 interrupt_immediately--;
3921#endif
95732b49 3922 }
f73dda09
JA
3923 return (result);
3924}
3925
3926static int
3927yy_stream_unget (c)
3928 int c;
3929{
3930 return (ungetc_with_restart (c, bash_input.location.file));
3931}
3932
3933void
3934with_input_from_stream (stream, name)
3935 FILE *stream;
3936 const char *name;
3937{
3938 INPUT_STREAM location;
3939
3940 location.file = stream;
3941 init_yy_io (yy_stream_get, yy_stream_unget, st_stream, name, location);
3942}
3943
3944typedef struct stream_saver {
3945 struct stream_saver *next;
3946 BASH_INPUT bash_input;
3947 int line;
3948#if defined (BUFFERED_INPUT)
3949 BUFFERED_STREAM *bstream;
3950#endif /* BUFFERED_INPUT */
3951} STREAM_SAVER;
3952
3953/* The globally known line number. */
3954int line_number = 0;
3955
495aee44
CR
3956/* The line number offset set by assigning to LINENO. Not currently used. */
3957int line_number_base = 0;
3958
f73dda09
JA
3959#if defined (COND_COMMAND)
3960static int cond_lineno;
3961static int cond_token;
3962#endif
3963
3964STREAM_SAVER *stream_list = (STREAM_SAVER *)NULL;
3965
3966void
3967push_stream (reset_lineno)
3968 int reset_lineno;
3969{
3970 STREAM_SAVER *saver = (STREAM_SAVER *)xmalloc (sizeof (STREAM_SAVER));
3971
3972 xbcopy ((char *)&bash_input, (char *)&(saver->bash_input), sizeof (BASH_INPUT));
3973
3974#if defined (BUFFERED_INPUT)
3975 saver->bstream = (BUFFERED_STREAM *)NULL;
3976 /* If we have a buffered stream, clear out buffers[fd]. */
3977 if (bash_input.type == st_bstream && bash_input.location.buffered_fd >= 0)
3978 saver->bstream = set_buffered_stream (bash_input.location.buffered_fd,
3979 (BUFFERED_STREAM *)NULL);
3980#endif /* BUFFERED_INPUT */
3981
3982 saver->line = line_number;
3983 bash_input.name = (char *)NULL;
3984 saver->next = stream_list;
3985 stream_list = saver;
3986 EOF_Reached = 0;
3987 if (reset_lineno)
3988 line_number = 0;
3989}
3990
3991void
3992pop_stream ()
3993{
3994 if (!stream_list)
3995 EOF_Reached = 1;
3996 else
3997 {
3998 STREAM_SAVER *saver = stream_list;
3999
4000 EOF_Reached = 0;
4001 stream_list = stream_list->next;
4002
4003 init_yy_io (saver->bash_input.getter,
4004 saver->bash_input.ungetter,
4005 saver->bash_input.type,
4006 saver->bash_input.name,
4007 saver->bash_input.location);
4008
4009#if defined (BUFFERED_INPUT)
4010 /* If we have a buffered stream, restore buffers[fd]. */
4011 /* If the input file descriptor was changed while this was on the
4012 save stack, update the buffered fd to the new file descriptor and
4013 re-establish the buffer <-> bash_input fd correspondence. */
4014 if (bash_input.type == st_bstream && bash_input.location.buffered_fd >= 0)
4015 {
4016 if (bash_input_fd_changed)
4017 {
4018 bash_input_fd_changed = 0;
4019 if (default_buffered_input >= 0)
4020 {
4021 bash_input.location.buffered_fd = default_buffered_input;
4022 saver->bstream->b_fd = default_buffered_input;
4023 SET_CLOSE_ON_EXEC (default_buffered_input);
4024 }
4025 }
4026 /* XXX could free buffered stream returned as result here. */
4027 set_buffered_stream (bash_input.location.buffered_fd, saver->bstream);
4028 }
4029#endif /* BUFFERED_INPUT */
4030
4031 line_number = saver->line;
4032
4033 FREE (saver->bash_input.name);
4034 free (saver);
4035 }
4036}
4037
4038/* Return 1 if a stream of type TYPE is saved on the stack. */
4039int
4040stream_on_stack (type)
4041 enum stream_type type;
4042{
4043 register STREAM_SAVER *s;
4044
4045 for (s = stream_list; s; s = s->next)
4046 if (s->bash_input.type == type)
4047 return 1;
4048 return 0;
4049}
4050
4051/* Save the current token state and return it in a malloced array. */
4052int *
4053save_token_state ()
4054{
4055 int *ret;
4056
0001803f 4057 ret = (int *)xmalloc (4 * sizeof (int));
f73dda09
JA
4058 ret[0] = last_read_token;
4059 ret[1] = token_before_that;
4060 ret[2] = two_tokens_ago;
0001803f 4061 ret[3] = current_token;
f73dda09
JA
4062 return ret;
4063}
4064
4065void
4066restore_token_state (ts)
4067 int *ts;
4068{
4069 if (ts == 0)
4070 return;
4071 last_read_token = ts[0];
4072 token_before_that = ts[1];
4073 two_tokens_ago = ts[2];
0001803f 4074 current_token = ts[3];
f73dda09
JA
4075}
4076
4077/*
4078 * This is used to inhibit alias expansion and reserved word recognition
4079 * inside case statement pattern lists. A `case statement pattern list' is:
4080 *
4081 * everything between the `in' in a `case word in' and the next ')'
4082 * or `esac'
4083 * everything between a `;;' and the next `)' or `esac'
4084 */
4085
4086#if defined (ALIAS) || defined (DPAREN_ARITHMETIC)
4087
f73dda09
JA
4088#define END_OF_ALIAS 0
4089
4090/*
4091 * Pseudo-global variables used in implementing token-wise alias expansion.
4092 */
4093
4094/*
4095 * Pushing and popping strings. This works together with shell_getc to
4096 * implement alias expansion on a per-token basis.
4097 */
4098
ac50fbac
CR
4099#define PSH_ALIAS 0x01
4100#define PSH_DPAREN 0x02
4101#define PSH_SOURCE 0x04
4102
f73dda09
JA
4103typedef struct string_saver {
4104 struct string_saver *next;
4105 int expand_alias; /* Value to set expand_alias to when string is popped. */
4106 char *saved_line;
4107#if defined (ALIAS)
4108 alias_t *expander; /* alias that caused this line to be pushed. */
4109#endif
ac50fbac
CR
4110 size_t saved_line_size, saved_line_index;
4111 int saved_line_terminator;
4112 int flags;
f73dda09
JA
4113} STRING_SAVER;
4114
4115STRING_SAVER *pushed_string_list = (STRING_SAVER *)NULL;
4116
4117/*
4118 * Push the current shell_input_line onto a stack of such lines and make S
4119 * the current input. Used when expanding aliases. EXPAND is used to set
4120 * the value of expand_next_token when the string is popped, so that the
4121 * word after the alias in the original line is handled correctly when the
4122 * alias expands to multiple words. TOKEN is the token that was expanded
4123 * into S; it is saved and used to prevent infinite recursive expansion.
4124 */
4125static void
4126push_string (s, expand, ap)
4127 char *s;
4128 int expand;
4129 alias_t *ap;
4130{
4131 STRING_SAVER *temp = (STRING_SAVER *)xmalloc (sizeof (STRING_SAVER));
4132
4133 temp->expand_alias = expand;
4134 temp->saved_line = shell_input_line;
4135 temp->saved_line_size = shell_input_line_size;
4136 temp->saved_line_index = shell_input_line_index;
4137 temp->saved_line_terminator = shell_input_line_terminator;
ac50fbac 4138 temp->flags = 0;
f73dda09
JA
4139#if defined (ALIAS)
4140 temp->expander = ap;
ac50fbac
CR
4141 if (ap)
4142 temp->flags = PSH_ALIAS;
f73dda09
JA
4143#endif
4144 temp->next = pushed_string_list;
4145 pushed_string_list = temp;
4146
4147#if defined (ALIAS)
4148 if (ap)
4149 ap->flags |= AL_BEINGEXPANDED;
4150#endif
4151
4152 shell_input_line = s;
ac50fbac 4153 shell_input_line_size = STRLEN (s);
f73dda09
JA
4154 shell_input_line_index = 0;
4155 shell_input_line_terminator = '\0';
b80f6443
JA
4156#if 0
4157 parser_state &= ~PST_ALEXPNEXT; /* XXX */
4158#endif
7117c2d2
JA
4159
4160 set_line_mbstate ();
f73dda09
JA
4161}
4162
4163/*
4164 * Make the top of the pushed_string stack be the current shell input.
4165 * Only called when there is something on the stack. Called from shell_getc
4166 * when it thinks it has consumed the string generated by an alias expansion
4167 * and needs to return to the original input line.
4168 */
4169static void
4170pop_string ()
4171{
4172 STRING_SAVER *t;
4173
4174 FREE (shell_input_line);
4175 shell_input_line = pushed_string_list->saved_line;
4176 shell_input_line_index = pushed_string_list->saved_line_index;
4177 shell_input_line_size = pushed_string_list->saved_line_size;
4178 shell_input_line_terminator = pushed_string_list->saved_line_terminator;
4179
4180 if (pushed_string_list->expand_alias)
4181 parser_state |= PST_ALEXPNEXT;
4182 else
4183 parser_state &= ~PST_ALEXPNEXT;
4184
4185 t = pushed_string_list;
4186 pushed_string_list = pushed_string_list->next;
4187
4188#if defined (ALIAS)
4189 if (t->expander)
4190 t->expander->flags &= ~AL_BEINGEXPANDED;
4191#endif
4192
4193 free ((char *)t);
7117c2d2
JA
4194
4195 set_line_mbstate ();
f73dda09
JA
4196}
4197
4198static void
4199free_string_list ()
4200{
4201 register STRING_SAVER *t, *t1;
4202
4203 for (t = pushed_string_list; t; )
4204 {
4205 t1 = t->next;
4206 FREE (t->saved_line);
4207#if defined (ALIAS)
4208 if (t->expander)
4209 t->expander->flags &= ~AL_BEINGEXPANDED;
4210#endif
4211 free ((char *)t);
4212 t = t1;
4213 }
4214 pushed_string_list = (STRING_SAVER *)NULL;
4215}
4216
4217#endif /* ALIAS || DPAREN_ARITHMETIC */
4218
b80f6443
JA
4219void
4220free_pushed_string_input ()
4221{
4222#if defined (ALIAS) || defined (DPAREN_ARITHMETIC)
4223 free_string_list ();
4224#endif
4225}
4226
ac50fbac
CR
4227int
4228parser_expanding_alias ()
4229{
4230 return (expanding_alias ());
4231}
4232
4233void
4234parser_save_alias ()
4235{
4236#if defined (ALIAS) || defined (DPAREN_ARITHMETIC)
4237 push_string ((char *)NULL, 0, (alias_t *)NULL);
4238 pushed_string_list->flags = PSH_SOURCE; /* XXX - for now */
4239#else
4240 ;
4241#endif
4242}
4243
4244void
4245parser_restore_alias ()
4246{
4247#if defined (ALIAS) || defined (DPAREN_ARITHMETIC)
4248 if (pushed_string_list)
4249 pop_string ();
4250#else
4251 ;
4252#endif
4253}
4254
a0c0a00f
CR
4255void
4256clear_shell_input_line ()
4257{
4258 if (shell_input_line)
4259 shell_input_line[shell_input_line_index = 0] = '\0';
4260}
4261
f73dda09
JA
4262/* Return a line of text, taken from wherever yylex () reads input.
4263 If there is no more input, then we return NULL. If REMOVE_QUOTED_NEWLINE
4264 is non-zero, we remove unquoted \<newline> pairs. This is used by
4265 read_secondary_line to read here documents. */
4266static char *
4267read_a_line (remove_quoted_newline)
4268 int remove_quoted_newline;
4269{
4270 static char *line_buffer = (char *)NULL;
4271 static int buffer_size = 0;
0001803f 4272 int indx, c, peekc, pass_next;
f73dda09
JA
4273
4274#if defined (READLINE)
b80f6443 4275 if (no_line_editing && SHOULD_PROMPT ())
f73dda09 4276#else
b80f6443 4277 if (SHOULD_PROMPT ())
f73dda09
JA
4278#endif
4279 print_prompt ();
4280
0001803f 4281 pass_next = indx = 0;
f73dda09
JA
4282 while (1)
4283 {
f73dda09
JA
4284 /* Allow immediate exit if interrupted during input. */
4285 QUIT;
4286
95732b49
JA
4287 c = yy_getc ();
4288
f73dda09
JA
4289 /* Ignore null bytes in input. */
4290 if (c == 0)
4291 {
4292#if 0
4293 internal_warning ("read_a_line: ignored null byte in input");
4294#endif
4295 continue;
4296 }
4297
4298 /* If there is no more input, then we return NULL. */
4299 if (c == EOF)
4300 {
4301 if (interactive && bash_input.type == st_stream)
4302 clearerr (stdin);
4303 if (indx == 0)
4304 return ((char *)NULL);
4305 c = '\n';
4306 }
4307
4308 /* `+2' in case the final character in the buffer is a newline. */
4309 RESIZE_MALLOCED_BUFFER (line_buffer, indx, 2, buffer_size, 128);
4310
4311 /* IF REMOVE_QUOTED_NEWLINES is non-zero, we are reading a
4312 here document with an unquoted delimiter. In this case,
4313 the line will be expanded as if it were in double quotes.
4314 We allow a backslash to escape the next character, but we
4315 need to treat the backslash specially only if a backslash
4316 quoting a backslash-newline pair appears in the line. */
4317 if (pass_next)
4318 {
4319 line_buffer[indx++] = c;
4320 pass_next = 0;
4321 }
4322 else if (c == '\\' && remove_quoted_newline)
4323 {
495aee44 4324 QUIT;
f73dda09
JA
4325 peekc = yy_getc ();
4326 if (peekc == '\n')
b80f6443
JA
4327 {
4328 line_number++;
4329 continue; /* Make the unquoted \<newline> pair disappear. */
4330 }
f73dda09
JA
4331 else
4332 {
4333 yy_ungetc (peekc);
4334 pass_next = 1;
4335 line_buffer[indx++] = c; /* Preserve the backslash. */
4336 }
4337 }
4338 else
4339 line_buffer[indx++] = c;
4340
4341 if (c == '\n')
4342 {
4343 line_buffer[indx] = '\0';
4344 return (line_buffer);
4345 }
4346 }
4347}
4348
4349/* Return a line as in read_a_line (), but insure that the prompt is
4350 the secondary prompt. This is used to read the lines of a here
4351 document. REMOVE_QUOTED_NEWLINE is non-zero if we should remove
4352 newlines quoted with backslashes while reading the line. It is
4353 non-zero unless the delimiter of the here document was quoted. */
4354char *
4355read_secondary_line (remove_quoted_newline)
4356 int remove_quoted_newline;
4357{
3185942a
JA
4358 char *ret;
4359 int n, c;
4360
f73dda09 4361 prompt_string_pointer = &ps2_prompt;
b80f6443
JA
4362 if (SHOULD_PROMPT())
4363 prompt_again ();
3185942a
JA
4364 ret = read_a_line (remove_quoted_newline);
4365#if defined (HISTORY)
0001803f 4366 if (ret && remember_on_history && (parser_state & PST_HEREDOC))
3185942a 4367 {
a0c0a00f
CR
4368 /* To make adding the here-document body right, we need to rely on
4369 history_delimiting_chars() returning \n for the first line of the
4370 here-document body and the null string for the second and subsequent
4371 lines, so we avoid double newlines.
3185942a
JA
4372 current_command_line_count == 2 for the first line of the body. */
4373
4374 current_command_line_count++;
4375 maybe_add_history (ret);
4376 }
4377#endif /* HISTORY */
4378 return ret;
f73dda09
JA
4379}
4380
4381/* **************************************************************** */
4382/* */
4383/* YYLEX () */
4384/* */
4385/* **************************************************************** */
4386
4387/* Reserved words. These are only recognized as the first word of a
4388 command. */
4389STRING_INT_ALIST word_token_alist[] = {
4390 { "if", IF },
4391 { "then", THEN },
28ef6c31
JA
4392 { "else", ELSE },
4393 { "elif", ELIF },
4394 { "fi", FI },
4395 { "case", CASE },
4396 { "esac", ESAC },
4397 { "for", FOR },
4398#if defined (SELECT_COMMAND)
4399 { "select", SELECT },
726f6388 4400#endif
28ef6c31
JA
4401 { "while", WHILE },
4402 { "until", UNTIL },
4403 { "do", DO },
4404 { "done", DONE },
4405 { "in", IN },
4406 { "function", FUNCTION },
4407#if defined (COMMAND_TIMING)
4408 { "time", TIME },
4409#endif
4410 { "{", '{' },
4411 { "}", '}' },
4412 { "!", BANG },
4413#if defined (COND_COMMAND)
4414 { "[[", COND_START },
4415 { "]]", COND_END },
3185942a
JA
4416#endif
4417#if defined (COPROCESS_SUPPORT)
4418 { "coproc", COPROC },
726f6388 4419#endif
28ef6c31
JA
4420 { (char *)NULL, 0}
4421};
726f6388 4422
7117c2d2
JA
4423/* other tokens that can be returned by read_token() */
4424STRING_INT_ALIST other_token_alist[] = {
4425 /* Multiple-character tokens with special values */
495aee44 4426 { "--", TIMEIGN },
7117c2d2
JA
4427 { "-p", TIMEOPT },
4428 { "&&", AND_AND },
4429 { "||", OR_OR },
4430 { ">>", GREATER_GREATER },
4431 { "<<", LESS_LESS },
4432 { "<&", LESS_AND },
4433 { ">&", GREATER_AND },
4434 { ";;", SEMI_SEMI },
3185942a
JA
4435 { ";&", SEMI_AND },
4436 { ";;&", SEMI_SEMI_AND },
7117c2d2
JA
4437 { "<<-", LESS_LESS_MINUS },
4438 { "<<<", LESS_LESS_LESS },
4439 { "&>", AND_GREATER },
3185942a 4440 { "&>>", AND_GREATER_GREATER },
7117c2d2
JA
4441 { "<>", LESS_GREATER },
4442 { ">|", GREATER_BAR },
3185942a 4443 { "|&", BAR_AND },
7117c2d2
JA
4444 { "EOF", yacc_EOF },
4445 /* Tokens whose value is the character itself */
4446 { ">", '>' },
4447 { "<", '<' },
4448 { "-", '-' },
4449 { "{", '{' },
4450 { "}", '}' },
4451 { ";", ';' },
4452 { "(", '(' },
4453 { ")", ')' },
4454 { "|", '|' },
4455 { "&", '&' },
4456 { "newline", '\n' },
4457 { (char *)NULL, 0}
4458};
4459
4460/* others not listed here:
4461 WORD look at yylval.word
4462 ASSIGNMENT_WORD look at yylval.word
4463 NUMBER look at yylval.number
4464 ARITH_CMD look at yylval.word_list
4465 ARITH_FOR_EXPRS look at yylval.word_list
4466 COND_CMD look at yylval.command
4467*/
726f6388 4468
28ef6c31
JA
4469/* These are used by read_token_word, but appear up here so that shell_getc
4470 can use them to decide when to add otherwise blank lines to the history. */
726f6388 4471
28ef6c31
JA
4472/* The primary delimiter stack. */
4473struct dstack dstack = { (char *)NULL, 0, 0 };
726f6388 4474
28ef6c31
JA
4475/* A temporary delimiter stack to be used when decoding prompt strings.
4476 This is needed because command substitutions in prompt strings (e.g., PS2)
4477 can screw up the parser's quoting state. */
4478static struct dstack temp_dstack = { (char *)NULL, 0, 0 };
726f6388 4479
28ef6c31
JA
4480/* Macro for accessing the top delimiter on the stack. Returns the
4481 delimiter or zero if none. */
4482#define current_delimiter(ds) \
4483 (ds.delimiter_depth ? ds.delimiters[ds.delimiter_depth - 1] : 0)
726f6388 4484
28ef6c31
JA
4485#define push_delimiter(ds, character) \
4486 do \
4487 { \
4488 if (ds.delimiter_depth + 2 > ds.delimiter_space) \
f73dda09 4489 ds.delimiters = (char *)xrealloc \
28ef6c31
JA
4490 (ds.delimiters, (ds.delimiter_space += 10) * sizeof (char)); \
4491 ds.delimiters[ds.delimiter_depth] = character; \
4492 ds.delimiter_depth++; \
4493 } \
4494 while (0)
726f6388 4495
28ef6c31 4496#define pop_delimiter(ds) ds.delimiter_depth--
726f6388 4497
28ef6c31
JA
4498/* Return the next shell input character. This always reads characters
4499 from shell_input_line; when that line is exhausted, it is time to
4500 read the next line. This is called by read_token when the shell is
4501 processing normal command input. */
ccc6cda3 4502
28ef6c31
JA
4503/* This implements one-character lookahead/lookbehind across physical input
4504 lines, to avoid something being lost because it's pushed back with
4505 shell_ungetc when we're at the start of a line. */
4506static int eol_ungetc_lookahead = 0;
726f6388 4507
28ef6c31
JA
4508static int
4509shell_getc (remove_quoted_newline)
4510 int remove_quoted_newline;
4511{
4512 register int i;
a0c0a00f 4513 int c, truncating, last_was_backslash;
f73dda09 4514 unsigned char uc;
726f6388 4515
28ef6c31 4516 QUIT;
726f6388 4517
a0c0a00f 4518 last_was_backslash = 0;
95732b49
JA
4519 if (sigwinch_received)
4520 {
4521 sigwinch_received = 0;
4522 get_new_window_size (0, (int *)0, (int *)0);
4523 }
4524
28ef6c31
JA
4525 if (eol_ungetc_lookahead)
4526 {
4527 c = eol_ungetc_lookahead;
4528 eol_ungetc_lookahead = 0;
4529 return (c);
4530 }
ccc6cda3 4531
28ef6c31
JA
4532#if defined (ALIAS) || defined (DPAREN_ARITHMETIC)
4533 /* If shell_input_line[shell_input_line_index] == 0, but there is
4534 something on the pushed list of strings, then we don't want to go
4535 off and get another line. We let the code down below handle it. */
b72432fd 4536
28ef6c31
JA
4537 if (!shell_input_line || ((!shell_input_line[shell_input_line_index]) &&
4538 (pushed_string_list == (STRING_SAVER *)NULL)))
4539#else /* !ALIAS && !DPAREN_ARITHMETIC */
4540 if (!shell_input_line || !shell_input_line[shell_input_line_index])
4541#endif /* !ALIAS && !DPAREN_ARITHMETIC */
4542 {
4543 line_number++;
726f6388 4544
ac50fbac
CR
4545 /* Let's not let one really really long line blow up memory allocation */
4546 if (shell_input_line && shell_input_line_size >= 32768)
4547 {
4548 free (shell_input_line);
4549 shell_input_line = 0;
4550 shell_input_line_size = 0;
4551 }
4552
28ef6c31 4553 restart_read:
726f6388 4554
28ef6c31
JA
4555 /* Allow immediate exit if interrupted during input. */
4556 QUIT;
ccc6cda3 4557
ac50fbac 4558 i = truncating = 0;
28ef6c31 4559 shell_input_line_terminator = 0;
726f6388 4560
b80f6443
JA
4561 /* If the shell is interatctive, but not currently printing a prompt
4562 (interactive_shell && interactive == 0), we don't want to print
4563 notifies or cleanup the jobs -- we want to defer it until we do
4564 print the next prompt. */
4565 if (interactive_shell == 0 || SHOULD_PROMPT())
4566 {
28ef6c31
JA
4567#if defined (JOB_CONTROL)
4568 /* This can cause a problem when reading a command as the result
4569 of a trap, when the trap is called from flush_child. This call
4570 had better not cause jobs to disappear from the job table in
4571 that case, or we will have big trouble. */
b80f6443 4572 notify_and_cleanup ();
28ef6c31 4573#else /* !JOB_CONTROL */
b80f6443 4574 cleanup_dead_jobs ();
28ef6c31 4575#endif /* !JOB_CONTROL */
b80f6443 4576 }
ccc6cda3 4577
28ef6c31 4578#if defined (READLINE)
b80f6443 4579 if (no_line_editing && SHOULD_PROMPT())
28ef6c31 4580#else
b80f6443 4581 if (SHOULD_PROMPT())
28ef6c31
JA
4582#endif
4583 print_prompt ();
726f6388 4584
28ef6c31
JA
4585 if (bash_input.type == st_stream)
4586 clearerr (stdin);
726f6388 4587
28ef6c31
JA
4588 while (1)
4589 {
4590 c = yy_getc ();
4591
4592 /* Allow immediate exit if interrupted during input. */
4593 QUIT;
4594
4595 if (c == '\0')
4596 {
4597#if 0
4598 internal_warning ("shell_getc: ignored null byte in input");
ccc6cda3 4599#endif
28ef6c31
JA
4600 continue;
4601 }
ccc6cda3 4602
ac50fbac
CR
4603 /* Theoretical overflow */
4604 /* If we can't put 256 bytes more into the buffer, allocate
4605 everything we can and fill it as full as we can. */
4606 /* XXX - we ignore rest of line using `truncating' flag */
4607 if (shell_input_line_size > (SIZE_MAX - 256))
4608 {
4609 size_t n;
4610
4611 n = SIZE_MAX - i; /* how much more can we put into the buffer? */
4612 if (n <= 2) /* we have to save 1 for the newline added below */
4613 {
4614 if (truncating == 0)
a0c0a00f 4615 internal_warning(_("shell_getc: shell_input_line_size (%zu) exceeds SIZE_MAX (%lu): line truncated"), shell_input_line_size, (unsigned long)SIZE_MAX);
ac50fbac
CR
4616 shell_input_line[i] = '\0';
4617 truncating = 1;
4618 }
4619 if (shell_input_line_size < SIZE_MAX)
4620 {
4621 shell_input_line_size = SIZE_MAX;
4622 shell_input_line = xrealloc (shell_input_line, shell_input_line_size);
4623 }
4624 }
4625 else
4626 RESIZE_MALLOCED_BUFFER (shell_input_line, i, 2, shell_input_line_size, 256);
726f6388 4627
28ef6c31
JA
4628 if (c == EOF)
4629 {
4630 if (bash_input.type == st_stream)
4631 clearerr (stdin);
726f6388 4632
28ef6c31
JA
4633 if (i == 0)
4634 shell_input_line_terminator = EOF;
726f6388 4635
28ef6c31
JA
4636 shell_input_line[i] = '\0';
4637 break;
4638 }
726f6388 4639
ac50fbac
CR
4640 if (truncating == 0 || c == '\n')
4641 shell_input_line[i++] = c;
726f6388 4642
28ef6c31
JA
4643 if (c == '\n')
4644 {
4645 shell_input_line[--i] = '\0';
4646 current_command_line_count++;
4647 break;
4648 }
a0c0a00f
CR
4649
4650 last_was_backslash = last_was_backslash == 0 && c == '\\';
28ef6c31 4651 }
726f6388 4652
28ef6c31
JA
4653 shell_input_line_index = 0;
4654 shell_input_line_len = i; /* == strlen (shell_input_line) */
ccc6cda3 4655
7117c2d2
JA
4656 set_line_mbstate ();
4657
28ef6c31
JA
4658#if defined (HISTORY)
4659 if (remember_on_history && shell_input_line && shell_input_line[0])
4660 {
4661 char *expansions;
4662# if defined (BANG_HISTORY)
4663 int old_hist;
726f6388 4664
28ef6c31
JA
4665 /* If the current delimiter is a single quote, we should not be
4666 performing history expansion, even if we're on a different
4667 line from the original single quote. */
4668 old_hist = history_expansion_inhibited;
4669 if (current_delimiter (dstack) == '\'')
4670 history_expansion_inhibited = 1;
4671# endif
a0c0a00f
CR
4672 /* Calling with a third argument of 1 allows remember_on_history to
4673 determine whether or not the line is saved to the history list */
28ef6c31
JA
4674 expansions = pre_process_line (shell_input_line, 1, 1);
4675# if defined (BANG_HISTORY)
4676 history_expansion_inhibited = old_hist;
4677# endif
4678 if (expansions != shell_input_line)
4679 {
4680 free (shell_input_line);
4681 shell_input_line = expansions;
4682 shell_input_line_len = shell_input_line ?
4683 strlen (shell_input_line) : 0;
495aee44 4684 if (shell_input_line_len == 0)
28ef6c31 4685 current_command_line_count--;
726f6388 4686
28ef6c31
JA
4687 /* We have to force the xrealloc below because we don't know
4688 the true allocated size of shell_input_line anymore. */
4689 shell_input_line_size = shell_input_line_len;
7117c2d2
JA
4690
4691 set_line_mbstate ();
28ef6c31
JA
4692 }
4693 }
4694 /* Try to do something intelligent with blank lines encountered while
4695 entering multi-line commands. XXX - this is grotesque */
4696 else if (remember_on_history && shell_input_line &&
4697 shell_input_line[0] == '\0' &&
4698 current_command_line_count > 1)
726f6388 4699 {
28ef6c31
JA
4700 if (current_delimiter (dstack))
4701 /* We know shell_input_line[0] == 0 and we're reading some sort of
4702 quoted string. This means we've got a line consisting of only
4703 a newline in a quoted string. We want to make sure this line
4704 gets added to the history. */
4705 maybe_add_history (shell_input_line);
4706 else
4707 {
4708 char *hdcs;
495aee44 4709 hdcs = history_delimiting_chars (shell_input_line);
28ef6c31
JA
4710 if (hdcs && hdcs[0] == ';')
4711 maybe_add_history (shell_input_line);
4712 }
726f6388
JA
4713 }
4714
28ef6c31 4715#endif /* HISTORY */
726f6388 4716
28ef6c31 4717 if (shell_input_line)
726f6388 4718 {
28ef6c31 4719 /* Lines that signify the end of the shell's input should not be
ac50fbac
CR
4720 echoed. We should not echo lines while parsing command
4721 substitutions with recursive calls into the parsing engine; those
4722 should only be echoed once when we read the word. That is the
4723 reason for the test against shell_eof_token, which is set to a
4724 right paren when parsing the contents of command substitutions. */
28ef6c31 4725 if (echo_input_at_read && (shell_input_line[0] ||
ac50fbac
CR
4726 shell_input_line_terminator != EOF) &&
4727 shell_eof_token == 0)
28ef6c31
JA
4728 fprintf (stderr, "%s\n", shell_input_line);
4729 }
4730 else
4731 {
4732 shell_input_line_size = 0;
4733 prompt_string_pointer = &current_prompt_string;
b80f6443
JA
4734 if (SHOULD_PROMPT ())
4735 prompt_again ();
28ef6c31 4736 goto restart_read;
726f6388
JA
4737 }
4738
28ef6c31
JA
4739 /* Add the newline to the end of this string, iff the string does
4740 not already end in an EOF character. */
4741 if (shell_input_line_terminator != EOF)
4742 {
6ebbb24a 4743 if (shell_input_line_size < SIZE_MAX-3 && (shell_input_line_len+3 > shell_input_line_size))
f73dda09 4744 shell_input_line = (char *)xrealloc (shell_input_line,
28ef6c31 4745 1 + (shell_input_line_size += 2));
726f6388 4746
a0c0a00f
CR
4747 /* Don't add a newline to a string that ends with a backslash if we're
4748 going to be removing quoted newlines, since that will eat the
4749 backslash. Add another backslash instead (will be removed by
4750 word expansion). */
4751 if (bash_input.type == st_string && expanding_alias() == 0 && last_was_backslash && c == EOF && remove_quoted_newline)
4752 shell_input_line[shell_input_line_len] = '\\';
4753 else
4754 shell_input_line[shell_input_line_len] = '\n';
28ef6c31 4755 shell_input_line[shell_input_line_len + 1] = '\0';
7117c2d2
JA
4756
4757 set_line_mbstate ();
28ef6c31
JA
4758 }
4759 }
726f6388 4760
495aee44 4761next_alias_char:
f73dda09 4762 uc = shell_input_line[shell_input_line_index];
ccc6cda3 4763
f73dda09 4764 if (uc)
28ef6c31 4765 shell_input_line_index++;
726f6388 4766
28ef6c31 4767#if defined (ALIAS) || defined (DPAREN_ARITHMETIC)
f73dda09 4768 /* If UC is NULL, we have reached the end of the current input string. If
28ef6c31
JA
4769 pushed_string_list is non-empty, it's time to pop to the previous string
4770 because we have fully consumed the result of the last alias expansion.
4771 Do it transparently; just return the next character of the string popped
4772 to. */
ac50fbac
CR
4773 /* If pushed_string_list != 0 but pushed_string_list->expander == 0 (not
4774 currently tested) and the flags value is not PSH_SOURCE, we are not
4775 parsing an alias, we have just saved one (push_string, when called by
4776 the parse_dparen code) In this case, just go on as well. The PSH_SOURCE
4777 case is handled below. */
0001803f 4778pop_alias:
ac50fbac 4779 if (uc == 0 && pushed_string_list && pushed_string_list->flags != PSH_SOURCE)
726f6388 4780 {
b80f6443
JA
4781 pop_string ();
4782 uc = shell_input_line[shell_input_line_index];
4783 if (uc)
4784 shell_input_line_index++;
726f6388 4785 }
28ef6c31
JA
4786#endif /* ALIAS || DPAREN_ARITHMETIC */
4787
95732b49
JA
4788 if MBTEST(uc == '\\' && remove_quoted_newline && shell_input_line[shell_input_line_index] == '\n')
4789 {
4790 if (SHOULD_PROMPT ())
4791 prompt_again ();
4792 line_number++;
495aee44
CR
4793 /* What do we do here if we're expanding an alias whose definition
4794 includes an escaped newline? If that's the last character in the
4795 alias expansion, we just pop the pushed string list (recall that
4796 we inhibit the appending of a space in mk_alexpansion() if newline
4797 is the last character). If it's not the last character, we need
4798 to consume the quoted newline and move to the next character in
4799 the expansion. */
509a4430 4800#if defined (ALIAS)
0001803f
CR
4801 if (expanding_alias () && shell_input_line[shell_input_line_index+1] == '\0')
4802 {
4803 uc = 0;
4804 goto pop_alias;
4805 }
495aee44
CR
4806 else if (expanding_alias () && shell_input_line[shell_input_line_index+1] != '\0')
4807 {
4808 shell_input_line_index++; /* skip newline */
4809 goto next_alias_char; /* and get next character */
4810 }
509a4430
CR
4811 else
4812#endif
495aee44 4813 goto restart_read;
95732b49
JA
4814 }
4815
495aee44 4816 if (uc == 0 && shell_input_line_terminator == EOF)
28ef6c31
JA
4817 return ((shell_input_line_index != 0) ? '\n' : EOF);
4818
ac50fbac
CR
4819#if defined (ALIAS) || defined (DPAREN_ARITHMETIC)
4820 /* We already know that we are not parsing an alias expansion because of the
4821 check for expanding_alias() above. This knows how parse_and_execute
4822 handles switching to st_string input while an alias is being expanded,
4823 hence the check for pushed_string_list without pushed_string_list->expander
4824 and the check for PSH_SOURCE as pushed_string_list->flags.
4825 parse_and_execute and parse_string both change the input type to st_string
4826 and place the string to be parsed and executed into location.string, so
4827 we should not stop reading that until the pointer is '\0'.
4828 The check for shell_input_line_terminator may be superfluous.
4829
4830 This solves the problem of `.' inside a multi-line alias with embedded
4831 newlines executing things out of order. */
4832 if (uc == 0 && bash_input.type == st_string && *bash_input.location.string &&
4833 pushed_string_list && pushed_string_list->flags == PSH_SOURCE &&
4834 shell_input_line_terminator == 0)
4835 {
4836 shell_input_line_index = 0;
4837 goto restart_read;
4838 }
4839#endif
4840
f73dda09 4841 return (uc);
726f6388
JA
4842}
4843
7117c2d2
JA
4844/* Put C back into the input for the shell. This might need changes for
4845 HANDLE_MULTIBYTE around EOLs. Since we (currently) never push back a
4846 character different than we read, shell_input_line_property doesn't need
4847 to change when manipulating shell_input_line. The define for
4848 last_shell_getc_is_singlebyte should take care of it, though. */
28ef6c31
JA
4849static void
4850shell_ungetc (c)
ccc6cda3 4851 int c;
726f6388 4852{
28ef6c31
JA
4853 if (shell_input_line && shell_input_line_index)
4854 shell_input_line[--shell_input_line_index] = c;
4855 else
4856 eol_ungetc_lookahead = c;
726f6388
JA
4857}
4858
ca6a2ba4
CR
4859char *
4860parser_remaining_input ()
4861{
4862 if (shell_input_line == 0)
4863 return 0;
4864 if (shell_input_line_index < 0 || shell_input_line_index >= shell_input_line_len)
a0c0a00f 4865 return ""; /* XXX */
ca6a2ba4
CR
4866 return (shell_input_line + shell_input_line_index);
4867}
4868
f73dda09
JA
4869#ifdef INCLUDE_UNUSED
4870/* Back the input pointer up by one, effectively `ungetting' a character. */
28ef6c31
JA
4871static void
4872shell_ungetchar ()
726f6388 4873{
28ef6c31
JA
4874 if (shell_input_line && shell_input_line_index)
4875 shell_input_line_index--;
726f6388 4876}
f73dda09 4877#endif
726f6388 4878
28ef6c31
JA
4879/* Discard input until CHARACTER is seen, then push that character back
4880 onto the input stream. */
4881static void
4882discard_until (character)
4883 int character;
726f6388 4884{
28ef6c31 4885 int c;
726f6388 4886
28ef6c31
JA
4887 while ((c = shell_getc (0)) != EOF && c != character)
4888 ;
726f6388 4889
28ef6c31
JA
4890 if (c != EOF)
4891 shell_ungetc (c);
4892}
726f6388 4893
28ef6c31 4894void
0628567a
JA
4895execute_variable_command (command, vname)
4896 char *command, *vname;
28ef6c31 4897{
28ef6c31 4898 char *last_lastarg;
b80f6443 4899 sh_parser_state_t ps;
726f6388 4900
b80f6443 4901 save_parser_state (&ps);
28ef6c31
JA
4902 last_lastarg = get_string_value ("_");
4903 if (last_lastarg)
4904 last_lastarg = savestring (last_lastarg);
726f6388 4905
0628567a 4906 parse_and_execute (savestring (command), vname, SEVAL_NONINT|SEVAL_NOHIST);
726f6388 4907
b80f6443 4908 restore_parser_state (&ps);
95732b49 4909 bind_variable ("_", last_lastarg, 0);
28ef6c31
JA
4910 FREE (last_lastarg);
4911
4912 if (token_to_read == '\n') /* reset_parser was called */
4913 token_to_read = 0;
726f6388
JA
4914}
4915
a0c0a00f
CR
4916void
4917push_token (x)
4918 int x;
4919{
4920 two_tokens_ago = token_before_that;
4921 token_before_that = last_read_token;
4922 last_read_token = current_token;
4923
4924 current_token = x;
4925}
4926
28ef6c31
JA
4927/* Place to remember the token. We try to keep the buffer
4928 at a reasonable size, but it can grow. */
4929static char *token = (char *)NULL;
726f6388 4930
28ef6c31
JA
4931/* Current size of the token buffer. */
4932static int token_buffer_size;
4933
4934/* Command to read_token () explaining what we want it to do. */
4935#define READ 0
4936#define RESET 1
4937#define prompt_is_ps1 \
4938 (!prompt_string_pointer || prompt_string_pointer == &ps1_prompt)
bb70624e 4939
28ef6c31
JA
4940/* Function for yyparse to call. yylex keeps track of
4941 the last two tokens read, and calls read_token. */
726f6388 4942static int
28ef6c31 4943yylex ()
726f6388 4944{
28ef6c31
JA
4945 if (interactive && (current_token == 0 || current_token == '\n'))
4946 {
4947 /* Before we print a prompt, we might have to check mailboxes.
4948 We do this only if it is time to do so. Notice that only here
4949 is the mail alarm reset; nothing takes place in check_mail ()
4950 except the checking of mail. Please don't change this. */
509a4430 4951 if (prompt_is_ps1 && parse_and_execute_level == 0 && time_to_check_mail ())
28ef6c31
JA
4952 {
4953 check_mail ();
4954 reset_mail_timer ();
4955 }
726f6388 4956
28ef6c31
JA
4957 /* Avoid printing a prompt if we're not going to read anything, e.g.
4958 after resetting the parser with read_token (RESET). */
b80f6443 4959 if (token_to_read == 0 && SHOULD_PROMPT ())
28ef6c31
JA
4960 prompt_again ();
4961 }
bb70624e 4962
28ef6c31
JA
4963 two_tokens_ago = token_before_that;
4964 token_before_that = last_read_token;
4965 last_read_token = current_token;
4966 current_token = read_token (READ);
3185942a
JA
4967
4968 if ((parser_state & PST_EOFTOKEN) && current_token == shell_eof_token)
4969 {
4970 current_token = yacc_EOF;
4971 if (bash_input.type == st_string)
4972 rewind_input_string ();
4973 }
4974 parser_state &= ~PST_EOFTOKEN;
4975
28ef6c31 4976 return (current_token);
726f6388
JA
4977}
4978
28ef6c31
JA
4979/* When non-zero, we have read the required tokens
4980 which allow ESAC to be the next one read. */
4981static int esacs_needed_count;
726f6388 4982
90a39f32
CR
4983static void
4984push_heredoc (r)
4985 REDIRECT *r;
4986{
4987 if (need_here_doc >= HEREDOC_MAX)
4988 {
4989 last_command_exit_value = EX_BADUSAGE;
4990 need_here_doc = 0;
4991 report_syntax_error (_("maximum here-document count exceeded"));
4992 reset_parser ();
4993 exit_shell (last_command_exit_value);
4994 }
4995 redir_stack[need_here_doc++] = r;
4996}
4997
726f6388 4998void
28ef6c31 4999gather_here_documents ()
726f6388 5000{
3185942a
JA
5001 int r;
5002
5003 r = 0;
a0c0a00f 5004 here_doc_first_line = 1;
daefb2c5 5005 while (need_here_doc > 0)
28ef6c31 5006 {
3185942a
JA
5007 parser_state |= PST_HEREDOC;
5008 make_here_document (redir_stack[r++], line_number);
5009 parser_state &= ~PST_HEREDOC;
28ef6c31 5010 need_here_doc--;
a0c0a00f 5011 redir_stack[r - 1] = 0; /* XXX */
28ef6c31 5012 }
a0c0a00f 5013 here_doc_first_line = 0; /* just in case */
726f6388
JA
5014}
5015
28ef6c31
JA
5016/* When non-zero, an open-brace used to create a group is awaiting a close
5017 brace partner. */
5018static int open_brace_count;
726f6388 5019
a0c0a00f
CR
5020/* In the following three macros, `token' is always last_read_token */
5021
5022/* Are we in the middle of parsing a redirection where we are about to read
5023 a word? This is used to make sure alias expansion doesn't happen in the
5024 middle of a redirection, even though we're parsing a simple command. */
5025#define parsing_redirection(token) \
5026 (token == '<' || token == '>' || \
5027 token == GREATER_GREATER || token == GREATER_BAR || \
5028 token == LESS_GREATER || token == LESS_LESS_MINUS || \
5029 token == LESS_LESS || token == LESS_LESS_LESS || \
5030 token == LESS_AND || token == GREATER_AND || token == AND_GREATER)
5031
5032/* Is `token' one that will allow a WORD to be read in a command position?
5033 We can read a simple command name on which we should attempt alias expansion
5034 or we can read an assignment statement. */
28ef6c31 5035#define command_token_position(token) \
a0c0a00f
CR
5036 (((token) == ASSIGNMENT_WORD) || \
5037 ((parser_state&PST_REDIRLIST) && parsing_redirection(token) == 0) || \
3185942a 5038 ((token) != SEMI_SEMI && (token) != SEMI_AND && (token) != SEMI_SEMI_AND && reserved_word_acceptable(token)))
cce855bc 5039
a0c0a00f 5040/* Are we in a position where we can read an assignment statement? */
b80f6443
JA
5041#define assignment_acceptable(token) \
5042 (command_token_position(token) && ((parser_state & PST_CASEPAT) == 0))
726f6388 5043
28ef6c31
JA
5044/* Check to see if TOKEN is a reserved word and return the token
5045 value if it is. */
5046#define CHECK_FOR_RESERVED_WORD(tok) \
5047 do { \
5048 if (!dollar_present && !quoted && \
5049 reserved_word_acceptable (last_read_token)) \
5050 { \
5051 int i; \
5052 for (i = 0; word_token_alist[i].word != (char *)NULL; i++) \
5053 if (STREQ (tok, word_token_alist[i].word)) \
5054 { \
5055 if ((parser_state & PST_CASEPAT) && (word_token_alist[i].token != ESAC)) \
5056 break; \
b80f6443 5057 if (word_token_alist[i].token == TIME && time_command_acceptable () == 0) \
28ef6c31 5058 break; \
a0c0a00f
CR
5059 if ((parser_state & PST_CASEPAT) && last_read_token == '|' && word_token_alist[i].token == ESAC) \
5060 break; /* Posix grammar rule 4 */ \
28ef6c31
JA
5061 if (word_token_alist[i].token == ESAC) \
5062 parser_state &= ~(PST_CASEPAT|PST_CASESTMT); \
5063 else if (word_token_alist[i].token == CASE) \
5064 parser_state |= PST_CASESTMT; \
5065 else if (word_token_alist[i].token == COND_END) \
5066 parser_state &= ~(PST_CONDCMD|PST_CONDEXPR); \
5067 else if (word_token_alist[i].token == COND_START) \
5068 parser_state |= PST_CONDCMD; \
5069 else if (word_token_alist[i].token == '{') \
5070 open_brace_count++; \
5071 else if (word_token_alist[i].token == '}' && open_brace_count) \
5072 open_brace_count--; \
5073 return (word_token_alist[i].token); \
5074 } \
5075 } \
5076 } while (0)
726f6388 5077
28ef6c31 5078#if defined (ALIAS)
726f6388 5079
28ef6c31
JA
5080 /* OK, we have a token. Let's try to alias expand it, if (and only if)
5081 it's eligible.
726f6388 5082
7117c2d2 5083 It is eligible for expansion if EXPAND_ALIASES is set, and
28ef6c31
JA
5084 the token is unquoted and the last token read was a command
5085 separator (or expand_next_token is set), and we are currently
5086 processing an alias (pushed_string_list is non-empty) and this
5087 token is not the same as the current or any previously
5088 processed alias.
726f6388 5089
28ef6c31
JA
5090 Special cases that disqualify:
5091 In a pattern list in a case statement (parser_state & PST_CASEPAT). */
b80f6443
JA
5092
5093static char *
5094mk_alexpansion (s)
5095 char *s;
5096{
5097 int l;
5098 char *r;
5099
5100 l = strlen (s);
5101 r = xmalloc (l + 2);
5102 strcpy (r, s);
495aee44
CR
5103 /* If the last character in the alias is a newline, don't add a trailing
5104 space to the expansion. Works with shell_getc above. */
a0c0a00f 5105 if (r[l - 1] != ' ' && r[l - 1] != '\n' && shellmeta(r[l - 1]) == 0)
b80f6443
JA
5106 r[l++] = ' ';
5107 r[l] = '\0';
5108 return r;
5109}
5110
28ef6c31 5111static int
f73dda09
JA
5112alias_expand_token (tokstr)
5113 char *tokstr;
726f6388 5114{
28ef6c31
JA
5115 char *expanded;
5116 alias_t *ap;
5117
5118 if (((parser_state & PST_ALEXPNEXT) || command_token_position (last_read_token)) &&
5119 (parser_state & PST_CASEPAT) == 0)
726f6388 5120 {
f73dda09 5121 ap = find_alias (tokstr);
726f6388 5122
28ef6c31
JA
5123 /* Currently expanding this token. */
5124 if (ap && (ap->flags & AL_BEINGEXPANDED))
5125 return (NO_EXPANSION);
726f6388 5126
b80f6443
JA
5127 /* mk_alexpansion puts an extra space on the end of the alias expansion,
5128 so the lookahead by the parser works right. If this gets changed,
5129 make sure the code in shell_getc that deals with reaching the end of
5130 an expanded alias is changed with it. */
5131 expanded = ap ? mk_alexpansion (ap->value) : (char *)NULL;
5132
28ef6c31
JA
5133 if (expanded)
5134 {
5135 push_string (expanded, ap->flags & AL_EXPANDNEXT, ap);
5136 return (RE_READ_TOKEN);
5137 }
5138 else
5139 /* This is an eligible token that does not have an expansion. */
5140 return (NO_EXPANSION);
5141 }
5142 return (NO_EXPANSION);
5143}
5144#endif /* ALIAS */
726f6388 5145
28ef6c31
JA
5146static int
5147time_command_acceptable ()
726f6388 5148{
28ef6c31 5149#if defined (COMMAND_TIMING)
495aee44
CR
5150 int i;
5151
5152 if (posixly_correct && shell_compatibility_level > 41)
5153 {
5154 /* Quick check of the rest of the line to find the next token. If it
5155 begins with a `-', Posix says to not return `time' as the token.
5156 This was interp 267. */
5157 i = shell_input_line_index;
5158 while (i < shell_input_line_len && (shell_input_line[i] == ' ' || shell_input_line[i] == '\t'))
5159 i++;
5160 if (shell_input_line[i] == '-')
5161 return 0;
5162 }
5163
28ef6c31
JA
5164 switch (last_read_token)
5165 {
5166 case 0:
5167 case ';':
5168 case '\n':
a0c0a00f
CR
5169 if (token_before_that == '|')
5170 return (0);
5171 /* FALLTHROUGH */
28ef6c31
JA
5172 case AND_AND:
5173 case OR_OR:
5174 case '&':
af61c549 5175 case WHILE:
28ef6c31 5176 case DO:
af61c549
CR
5177 case UNTIL:
5178 case IF:
28ef6c31 5179 case THEN:
af61c549 5180 case ELIF:
28ef6c31
JA
5181 case ELSE:
5182 case '{': /* } */
af61c549
CR
5183 case '(': /* )( */
5184 case ')': /* only valid in case statement */
495aee44
CR
5185 case BANG: /* ! time pipeline */
5186 case TIME: /* time time pipeline */
5187 case TIMEOPT: /* time -p time pipeline */
5188 case TIMEIGN: /* time -p -- ... */
726f6388 5189 return 1;
28ef6c31
JA
5190 default:
5191 return 0;
5192 }
5193#else
726f6388 5194 return 0;
28ef6c31 5195#endif /* COMMAND_TIMING */
726f6388
JA
5196}
5197
28ef6c31
JA
5198/* Handle special cases of token recognition:
5199 IN is recognized if the last token was WORD and the token
5200 before that was FOR or CASE or SELECT.
726f6388 5201
28ef6c31
JA
5202 DO is recognized if the last token was WORD and the token
5203 before that was FOR or SELECT.
cce855bc 5204
28ef6c31
JA
5205 ESAC is recognized if the last token caused `esacs_needed_count'
5206 to be set
ccc6cda3 5207
28ef6c31
JA
5208 `{' is recognized if the last token as WORD and the token
5209 before that was FUNCTION, or if we just parsed an arithmetic
5210 `for' command.
ccc6cda3 5211
28ef6c31 5212 `}' is recognized if there is an unclosed `{' present.
726f6388 5213
28ef6c31 5214 `-p' is returned as TIMEOPT if the last read token was TIME.
495aee44 5215 `--' is returned as TIMEIGN if the last read token was TIMEOPT.
726f6388 5216
28ef6c31
JA
5217 ']]' is returned as COND_END if the parser is currently parsing
5218 a conditional expression ((parser_state & PST_CONDEXPR) != 0)
726f6388 5219
28ef6c31
JA
5220 `time' is returned as TIME if and only if it is immediately
5221 preceded by one of `;', `\n', `||', `&&', or `&'.
5222*/
726f6388 5223
28ef6c31 5224static int
f73dda09
JA
5225special_case_tokens (tokstr)
5226 char *tokstr;
726f6388 5227{
28ef6c31
JA
5228 if ((last_read_token == WORD) &&
5229#if defined (SELECT_COMMAND)
5230 ((token_before_that == FOR) || (token_before_that == CASE) || (token_before_that == SELECT)) &&
5231#else
5232 ((token_before_that == FOR) || (token_before_that == CASE)) &&
cce855bc 5233#endif
f73dda09 5234 (tokstr[0] == 'i' && tokstr[1] == 'n' && tokstr[2] == 0))
28ef6c31
JA
5235 {
5236 if (token_before_that == CASE)
5237 {
5238 parser_state |= PST_CASEPAT;
5239 esacs_needed_count++;
5240 }
5241 return (IN);
5242 }
726f6388 5243
28ef6c31
JA
5244 if (last_read_token == WORD &&
5245#if defined (SELECT_COMMAND)
5246 (token_before_that == FOR || token_before_that == SELECT) &&
5247#else
5248 (token_before_that == FOR) &&
cce855bc 5249#endif
f73dda09 5250 (tokstr[0] == 'd' && tokstr[1] == 'o' && tokstr[2] == '\0'))
28ef6c31 5251 return (DO);
726f6388 5252
28ef6c31
JA
5253 /* Ditto for ESAC in the CASE case.
5254 Specifically, this handles "case word in esac", which is a legal
5255 construct, certainly because someone will pass an empty arg to the
5256 case construct, and we don't want it to barf. Of course, we should
5257 insist that the case construct has at least one pattern in it, but
5258 the designers disagree. */
5259 if (esacs_needed_count)
5260 {
5261 esacs_needed_count--;
f73dda09 5262 if (STREQ (tokstr, "esac"))
28ef6c31
JA
5263 {
5264 parser_state &= ~PST_CASEPAT;
5265 return (ESAC);
5266 }
5267 }
726f6388 5268
28ef6c31
JA
5269 /* The start of a shell function definition. */
5270 if (parser_state & PST_ALLOWOPNBRC)
5271 {
5272 parser_state &= ~PST_ALLOWOPNBRC;
f73dda09 5273 if (tokstr[0] == '{' && tokstr[1] == '\0') /* } */
28ef6c31
JA
5274 {
5275 open_brace_count++;
5276 function_bstart = line_number;
5277 return ('{'); /* } */
5278 }
5279 }
726f6388 5280
28ef6c31
JA
5281 /* We allow a `do' after a for ((...)) without an intervening
5282 list_terminator */
f73dda09 5283 if (last_read_token == ARITH_FOR_EXPRS && tokstr[0] == 'd' && tokstr[1] == 'o' && !tokstr[2])
28ef6c31 5284 return (DO);
f73dda09 5285 if (last_read_token == ARITH_FOR_EXPRS && tokstr[0] == '{' && tokstr[1] == '\0') /* } */
28ef6c31
JA
5286 {
5287 open_brace_count++;
5288 return ('{'); /* } */
5289 }
726f6388 5290
f73dda09 5291 if (open_brace_count && reserved_word_acceptable (last_read_token) && tokstr[0] == '}' && !tokstr[1])
28ef6c31
JA
5292 {
5293 open_brace_count--; /* { */
5294 return ('}');
5295 }
ccc6cda3 5296
28ef6c31
JA
5297#if defined (COMMAND_TIMING)
5298 /* Handle -p after `time'. */
f73dda09 5299 if (last_read_token == TIME && tokstr[0] == '-' && tokstr[1] == 'p' && !tokstr[2])
28ef6c31 5300 return (TIMEOPT);
495aee44
CR
5301 /* Handle -- after `time -p'. */
5302 if (last_read_token == TIMEOPT && tokstr[0] == '-' && tokstr[1] == '-' && !tokstr[2])
5303 return (TIMEIGN);
b80f6443 5304#endif
28ef6c31
JA
5305
5306#if defined (COND_COMMAND) /* [[ */
f73dda09 5307 if ((parser_state & PST_CONDEXPR) && tokstr[0] == ']' && tokstr[1] == ']' && tokstr[2] == '\0')
28ef6c31 5308 return (COND_END);
cce855bc 5309#endif
ccc6cda3 5310
28ef6c31 5311 return (-1);
726f6388
JA
5312}
5313
28ef6c31
JA
5314/* Called from shell.c when Control-C is typed at top level. Or
5315 by the error rule at top level. */
5316void
5317reset_parser ()
726f6388 5318{
28ef6c31
JA
5319 dstack.delimiter_depth = 0; /* No delimiters found so far. */
5320 open_brace_count = 0;
726f6388 5321
0001803f
CR
5322#if defined (EXTENDED_GLOB)
5323 /* Reset to global value of extended glob */
5324 if (parser_state & PST_EXTPAT)
5325 extended_glob = global_extglob;
5326#endif
5327
28ef6c31 5328 parser_state = 0;
a0c0a00f 5329 here_doc_first_line = 0;
726f6388 5330
28ef6c31
JA
5331#if defined (ALIAS) || defined (DPAREN_ARITHMETIC)
5332 if (pushed_string_list)
5333 free_string_list ();
cce855bc 5334#endif /* ALIAS || DPAREN_ARITHMETIC */
ccc6cda3 5335
a0c0a00f 5336 /* This is where we resynchronize to the next newline on error/reset */
28ef6c31 5337 if (shell_input_line)
726f6388 5338 {
28ef6c31
JA
5339 free (shell_input_line);
5340 shell_input_line = (char *)NULL;
5341 shell_input_line_size = shell_input_line_index = 0;
5342 }
726f6388 5343
28ef6c31
JA
5344 FREE (word_desc_to_read);
5345 word_desc_to_read = (WORD_DESC *)NULL;
726f6388 5346
836a17be
CR
5347 eol_ungetc_lookahead = 0;
5348
0001803f 5349 current_token = '\n'; /* XXX */
28ef6c31
JA
5350 last_read_token = '\n';
5351 token_to_read = '\n';
5352}
726f6388 5353
28ef6c31
JA
5354/* Read the next token. Command can be READ (normal operation) or
5355 RESET (to normalize state). */
5356static int
5357read_token (command)
5358 int command;
5359{
5360 int character; /* Current character. */
5361 int peek_char; /* Temporary look-ahead character. */
5362 int result; /* The thing to return. */
726f6388 5363
28ef6c31
JA
5364 if (command == RESET)
5365 {
5366 reset_parser ();
5367 return ('\n');
5368 }
726f6388 5369
28ef6c31
JA
5370 if (token_to_read)
5371 {
5372 result = token_to_read;
5373 if (token_to_read == WORD || token_to_read == ASSIGNMENT_WORD)
726f6388 5374 {
28ef6c31
JA
5375 yylval.word = word_desc_to_read;
5376 word_desc_to_read = (WORD_DESC *)NULL;
726f6388 5377 }
28ef6c31
JA
5378 token_to_read = 0;
5379 return (result);
5380 }
726f6388 5381
28ef6c31
JA
5382#if defined (COND_COMMAND)
5383 if ((parser_state & (PST_CONDCMD|PST_CONDEXPR)) == PST_CONDCMD)
5384 {
5385 cond_lineno = line_number;
5386 parser_state |= PST_CONDEXPR;
5387 yylval.command = parse_cond_command ();
5388 if (cond_token != COND_END)
726f6388 5389 {
7117c2d2 5390 cond_error ();
28ef6c31 5391 return (-1);
726f6388 5392 }
28ef6c31
JA
5393 token_to_read = COND_END;
5394 parser_state &= ~(PST_CONDEXPR|PST_CONDCMD);
5395 return (COND_CMD);
726f6388 5396 }
cce855bc 5397#endif
726f6388 5398
28ef6c31
JA
5399#if defined (ALIAS)
5400 /* This is a place to jump back to once we have successfully expanded a
5401 token with an alias and pushed the string with push_string () */
5402 re_read_token:
5403#endif /* ALIAS */
ccc6cda3 5404
28ef6c31 5405 /* Read a single word from input. Start by skipping blanks. */
0628567a 5406 while ((character = shell_getc (1)) != EOF && shellblank (character))
28ef6c31 5407 ;
ccc6cda3 5408
28ef6c31
JA
5409 if (character == EOF)
5410 {
5411 EOF_Reached = 1;
5412 return (yacc_EOF);
5413 }
ccc6cda3 5414
7117c2d2 5415 if MBTEST(character == '#' && (!interactive || interactive_comments))
28ef6c31
JA
5416 {
5417 /* A comment. Discard until EOL or EOF, and then return a newline. */
5418 discard_until ('\n');
5419 shell_getc (0);
5420 character = '\n'; /* this will take the next if statement and return. */
5421 }
ccc6cda3 5422
28ef6c31
JA
5423 if (character == '\n')
5424 {
5425 /* If we're about to return an unquoted newline, we can go and collect
5426 the text of any pending here document. */
5427 if (need_here_doc)
5428 gather_here_documents ();
ccc6cda3 5429
28ef6c31
JA
5430#if defined (ALIAS)
5431 parser_state &= ~PST_ALEXPNEXT;
5432#endif /* ALIAS */
ccc6cda3 5433
95732b49
JA
5434 parser_state &= ~PST_ASSIGNOK;
5435
28ef6c31
JA
5436 return (character);
5437 }
726f6388 5438
3185942a
JA
5439 if (parser_state & PST_REGEXP)
5440 goto tokword;
5441
28ef6c31 5442 /* Shell meta-characters. */
7117c2d2 5443 if MBTEST(shellmeta (character) && ((parser_state & PST_DBLPAREN) == 0))
28ef6c31
JA
5444 {
5445#if defined (ALIAS)
5446 /* Turn off alias tokenization iff this character sequence would
5447 not leave us ready to read a command. */
5448 if (character == '<' || character == '>')
5449 parser_state &= ~PST_ALEXPNEXT;
5450#endif /* ALIAS */
726f6388 5451
95732b49
JA
5452 parser_state &= ~PST_ASSIGNOK;
5453
a0c0a00f
CR
5454 /* If we are parsing a command substitution and we have read a character
5455 that marks the end of it, don't bother to skip over quoted newlines
5456 when we read the next token. We're just interested in a character
5457 that will turn this into a two-character token, so we let the higher
5458 layers deal with quoted newlines following the command substitution. */
5459 if ((parser_state & PST_CMDSUBST) && character == shell_eof_token)
5460 peek_char = shell_getc (0);
5461 else
5462 peek_char = shell_getc (1);
5463
28ef6c31
JA
5464 if (character == peek_char)
5465 {
5466 switch (character)
5467 {
5468 case '<':
5469 /* If '<' then we could be at "<<" or at "<<-". We have to
5470 look ahead one more character. */
5471 peek_char = shell_getc (1);
3185942a 5472 if MBTEST(peek_char == '-')
28ef6c31 5473 return (LESS_LESS_MINUS);
3185942a 5474 else if MBTEST(peek_char == '<')
7117c2d2 5475 return (LESS_LESS_LESS);
28ef6c31
JA
5476 else
5477 {
5478 shell_ungetc (peek_char);
5479 return (LESS_LESS);
5480 }
726f6388 5481
28ef6c31
JA
5482 case '>':
5483 return (GREATER_GREATER);
726f6388 5484
28ef6c31
JA
5485 case ';':
5486 parser_state |= PST_CASEPAT;
5487#if defined (ALIAS)
5488 parser_state &= ~PST_ALEXPNEXT;
5489#endif /* ALIAS */
95732b49 5490
3185942a
JA
5491 peek_char = shell_getc (1);
5492 if MBTEST(peek_char == '&')
5493 return (SEMI_SEMI_AND);
5494 else
5495 {
5496 shell_ungetc (peek_char);
5497 return (SEMI_SEMI);
5498 }
726f6388 5499
28ef6c31
JA
5500 case '&':
5501 return (AND_AND);
726f6388 5502
28ef6c31
JA
5503 case '|':
5504 return (OR_OR);
726f6388 5505
28ef6c31
JA
5506#if defined (DPAREN_ARITHMETIC) || defined (ARITH_FOR_COMMAND)
5507 case '(': /* ) */
7117c2d2
JA
5508 result = parse_dparen (character);
5509 if (result == -2)
5510 break;
5511 else
5512 return result;
726f6388 5513#endif
28ef6c31
JA
5514 }
5515 }
7117c2d2 5516 else if MBTEST(character == '<' && peek_char == '&')
28ef6c31 5517 return (LESS_AND);
7117c2d2 5518 else if MBTEST(character == '>' && peek_char == '&')
28ef6c31 5519 return (GREATER_AND);
7117c2d2 5520 else if MBTEST(character == '<' && peek_char == '>')
28ef6c31 5521 return (LESS_GREATER);
7117c2d2 5522 else if MBTEST(character == '>' && peek_char == '|')
28ef6c31 5523 return (GREATER_BAR);
3185942a
JA
5524 else if MBTEST(character == '&' && peek_char == '>')
5525 {
5526 peek_char = shell_getc (1);
5527 if MBTEST(peek_char == '>')
5528 return (AND_GREATER_GREATER);
5529 else
5530 {
5531 shell_ungetc (peek_char);
5532 return (AND_GREATER);
5533 }
5534 }
5535 else if MBTEST(character == '|' && peek_char == '&')
5536 return (BAR_AND);
5537 else if MBTEST(character == ';' && peek_char == '&')
5538 {
5539 parser_state |= PST_CASEPAT;
5540#if defined (ALIAS)
5541 parser_state &= ~PST_ALEXPNEXT;
5542#endif /* ALIAS */
5543 return (SEMI_AND);
5544 }
726f6388 5545
28ef6c31 5546 shell_ungetc (peek_char);
726f6388 5547
28ef6c31
JA
5548 /* If we look like we are reading the start of a function
5549 definition, then let the reader know about it so that
5550 we will do the right thing with `{'. */
7117c2d2 5551 if MBTEST(character == ')' && last_read_token == '(' && token_before_that == WORD)
726f6388 5552 {
28ef6c31
JA
5553 parser_state |= PST_ALLOWOPNBRC;
5554#if defined (ALIAS)
5555 parser_state &= ~PST_ALEXPNEXT;
5556#endif /* ALIAS */
5557 function_dstart = line_number;
5558 }
726f6388 5559
28ef6c31
JA
5560 /* case pattern lists may be preceded by an optional left paren. If
5561 we're not trying to parse a case pattern list, the left paren
5562 indicates a subshell. */
7117c2d2 5563 if MBTEST(character == '(' && (parser_state & PST_CASEPAT) == 0) /* ) */
28ef6c31
JA
5564 parser_state |= PST_SUBSHELL;
5565 /*(*/
7117c2d2 5566 else if MBTEST((parser_state & PST_CASEPAT) && character == ')')
28ef6c31
JA
5567 parser_state &= ~PST_CASEPAT;
5568 /*(*/
7117c2d2 5569 else if MBTEST((parser_state & PST_SUBSHELL) && character == ')')
28ef6c31 5570 parser_state &= ~PST_SUBSHELL;
726f6388 5571
28ef6c31
JA
5572#if defined (PROCESS_SUBSTITUTION)
5573 /* Check for the constructs which introduce process substitution.
5574 Shells running in `posix mode' don't do process substitution. */
7117c2d2 5575 if MBTEST(posixly_correct || ((character != '>' && character != '<') || peek_char != '(')) /*)*/
28ef6c31
JA
5576#endif /* PROCESS_SUBSTITUTION */
5577 return (character);
5578 }
726f6388 5579
3185942a
JA
5580 /* Hack <&- (close stdin) case. Also <&N- (dup and close). */
5581 if MBTEST(character == '-' && (last_read_token == LESS_AND || last_read_token == GREATER_AND))
5582 return (character);
5583
5584tokword:
5585 /* Okay, if we got this far, we have to read a word. Read one,
5586 and then check it against the known ones. */
5587 result = read_token_word (character);
5588#if defined (ALIAS)
5589 if (result == RE_READ_TOKEN)
5590 goto re_read_token;
5591#endif
5592 return result;
5593}
5594
5595/*
5596 * Match a $(...) or other grouping construct. This has to handle embedded
5597 * quoted strings ('', ``, "") and nested constructs. It also must handle
5598 * reprompting the user, if necessary, after reading a newline, and returning
5599 * correct error values if it reads EOF.
5600 */
495aee44
CR
5601#define P_FIRSTCLOSE 0x0001
5602#define P_ALLOWESC 0x0002
5603#define P_DQUOTE 0x0004
5604#define P_COMMAND 0x0008 /* parsing a command, so look for comments */
5605#define P_BACKQUOTE 0x0010 /* parsing a backquoted command substitution */
5606#define P_ARRAYSUB 0x0020 /* parsing a [...] array subscript for assignment */
5607#define P_DOLBRACE 0x0040 /* parsing a ${...} construct */
3185942a
JA
5608
5609/* Lexical state while parsing a grouping construct or $(...). */
5610#define LEX_WASDOL 0x001
5611#define LEX_CKCOMMENT 0x002
5612#define LEX_INCOMMENT 0x004
5613#define LEX_PASSNEXT 0x008
5614#define LEX_RESWDOK 0x010
5615#define LEX_CKCASE 0x020
5616#define LEX_INCASE 0x040
5617#define LEX_INHEREDOC 0x080
5618#define LEX_HEREDELIM 0x100 /* reading here-doc delimiter */
5619#define LEX_STRIPDOC 0x200 /* <<- strip tabs from here doc delim */
a0c0a00f
CR
5620#define LEX_QUOTEDDOC 0x400 /* here doc with quoted delim */
5621#define LEX_INWORD 0x800
3185942a
JA
5622
5623#define COMSUB_META(ch) ((ch) == ';' || (ch) == '&' || (ch) == '|')
5624
5625#define CHECK_NESTRET_ERROR() \
5626 do { \
5627 if (nestret == &matched_pair_error) \
5628 { \
5629 free (ret); \
5630 return &matched_pair_error; \
5631 } \
5632 } while (0)
5633
5634#define APPEND_NESTRET() \
5635 do { \
5636 if (nestlen) \
5637 { \
5638 RESIZE_MALLOCED_BUFFER (ret, retind, nestlen, retsize, 64); \
5639 strcpy (ret + retind, nestret); \
5640 retind += nestlen; \
5641 } \
5642 } while (0)
5643
5644static char matched_pair_error;
5645
5646static char *
5647parse_matched_pair (qc, open, close, lenp, flags)
5648 int qc; /* `"' if this construct is within double quotes */
5649 int open, close;
5650 int *lenp, flags;
5651{
5652 int count, ch, tflags;
5653 int nestlen, ttranslen, start_lineno;
5654 char *ret, *nestret, *ttrans;
5655 int retind, retsize, rflags;
495aee44
CR
5656 int dolbrace_state;
5657
5658 dolbrace_state = (flags & P_DOLBRACE) ? DOLBRACE_PARAM : 0;
3185942a 5659
0001803f 5660/*itrace("parse_matched_pair[%d]: open = %c close = %c flags = %d", line_number, open, close, flags);*/
3185942a
JA
5661 count = 1;
5662 tflags = 0;
5663
5664 if ((flags & P_COMMAND) && qc != '`' && qc != '\'' && qc != '"' && (flags & P_DQUOTE) == 0)
5665 tflags |= LEX_CKCOMMENT;
5666
5667 /* RFLAGS is the set of flags we want to pass to recursive calls. */
5668 rflags = (qc == '"') ? P_DQUOTE : (flags & P_DQUOTE);
5669
5670 ret = (char *)xmalloc (retsize = 64);
5671 retind = 0;
5672
5673 start_lineno = line_number;
5674 while (count)
5675 {
495aee44 5676 ch = shell_getc (qc != '\'' && (tflags & (LEX_PASSNEXT)) == 0);
3185942a
JA
5677
5678 if (ch == EOF)
5679 {
5680 free (ret);
5681 parser_error (start_lineno, _("unexpected EOF while looking for matching `%c'"), close);
5682 EOF_Reached = 1; /* XXX */
5683 return (&matched_pair_error);
5684 }
5685
5686 /* Possible reprompting. */
5687 if (ch == '\n' && SHOULD_PROMPT ())
5688 prompt_again ();
5689
5690 /* Don't bother counting parens or doing anything else if in a comment
5691 or part of a case statement */
5692 if (tflags & LEX_INCOMMENT)
5693 {
5694 /* Add this character. */
5695 RESIZE_MALLOCED_BUFFER (ret, retind, 1, retsize, 64);
5696 ret[retind++] = ch;
5697
5698 if (ch == '\n')
5699 tflags &= ~LEX_INCOMMENT;
5700
5701 continue;
5702 }
5703
5704 /* Not exactly right yet, should handle shell metacharacters, too. If
5705 any changes are made to this test, make analogous changes to subst.c:
5706 extract_delimited_string(). */
5707 else if MBTEST((tflags & LEX_CKCOMMENT) && (tflags & LEX_INCOMMENT) == 0 && ch == '#' && (retind == 0 || ret[retind-1] == '\n' || shellblank (ret[retind - 1])))
5708 tflags |= LEX_INCOMMENT;
5709
5710 if (tflags & LEX_PASSNEXT) /* last char was backslash */
5711 {
5712 tflags &= ~LEX_PASSNEXT;
5713 if (qc != '\'' && ch == '\n') /* double-quoted \<newline> disappears. */
5714 {
5715 if (retind > 0)
5716 retind--; /* swallow previously-added backslash */
5717 continue;
5718 }
5719
5720 RESIZE_MALLOCED_BUFFER (ret, retind, 2, retsize, 64);
ac50fbac 5721 if MBTEST(ch == CTLESC)
3185942a
JA
5722 ret[retind++] = CTLESC;
5723 ret[retind++] = ch;
5724 continue;
5725 }
5726 /* If we're reparsing the input (e.g., from parse_string_to_word_list),
5727 we've already prepended CTLESC to single-quoted results of $'...'.
5728 We may want to do this for other CTLESC-quoted characters in
5729 reparse, too. */
5730 else if MBTEST((parser_state & PST_REPARSE) && open == '\'' && (ch == CTLESC || ch == CTLNUL))
5731 {
5732 RESIZE_MALLOCED_BUFFER (ret, retind, 1, retsize, 64);
5733 ret[retind++] = ch;
5734 continue;
5735 }
5736 else if MBTEST(ch == CTLESC || ch == CTLNUL) /* special shell escapes */
5737 {
5738 RESIZE_MALLOCED_BUFFER (ret, retind, 2, retsize, 64);
5739 ret[retind++] = CTLESC;
5740 ret[retind++] = ch;
5741 continue;
5742 }
5743 else if MBTEST(ch == close) /* ending delimiter */
5744 count--;
5745 /* handle nested ${...} specially. */
5746 else if MBTEST(open != close && (tflags & LEX_WASDOL) && open == '{' && ch == open) /* } */
5747 count++;
5748 else if MBTEST(((flags & P_FIRSTCLOSE) == 0) && ch == open) /* nested begin */
5749 count++;
5750
5751 /* Add this character. */
5752 RESIZE_MALLOCED_BUFFER (ret, retind, 1, retsize, 64);
5753 ret[retind++] = ch;
5754
5755 /* If we just read the ending character, don't bother continuing. */
5756 if (count == 0)
5757 break;
5758
5759 if (open == '\'') /* '' inside grouping construct */
5760 {
5761 if MBTEST((flags & P_ALLOWESC) && ch == '\\')
5762 tflags |= LEX_PASSNEXT;
5763 continue;
5764 }
5765
5766 if MBTEST(ch == '\\') /* backslashes */
5767 tflags |= LEX_PASSNEXT;
5768
495aee44
CR
5769 /* Based on which dolstate is currently in (param, op, or word),
5770 decide what the op is. We're really only concerned if it's % or
5771 #, so we can turn on a flag that says whether or not we should
5772 treat single quotes as special when inside a double-quoted
5773 ${...}. This logic must agree with subst.c:extract_dollar_brace_string
5774 since they share the same defines. */
ac50fbac 5775 /* FLAG POSIX INTERP 221 */
495aee44
CR
5776 if (flags & P_DOLBRACE)
5777 {
5778 /* ${param%[%]word} */
5779 if MBTEST(dolbrace_state == DOLBRACE_PARAM && ch == '%' && retind > 1)
5780 dolbrace_state = DOLBRACE_QUOTE;
5781 /* ${param#[#]word} */
5782 else if MBTEST(dolbrace_state == DOLBRACE_PARAM && ch == '#' && retind > 1)
5783 dolbrace_state = DOLBRACE_QUOTE;
5784 /* ${param/[/]pat/rep} */
5785 else if MBTEST(dolbrace_state == DOLBRACE_PARAM && ch == '/' && retind > 1)
ac50fbac 5786 dolbrace_state = DOLBRACE_QUOTE2; /* XXX */
495aee44
CR
5787 /* ${param^[^]pat} */
5788 else if MBTEST(dolbrace_state == DOLBRACE_PARAM && ch == '^' && retind > 1)
5789 dolbrace_state = DOLBRACE_QUOTE;
5790 /* ${param,[,]pat} */
5791 else if MBTEST(dolbrace_state == DOLBRACE_PARAM && ch == ',' && retind > 1)
5792 dolbrace_state = DOLBRACE_QUOTE;
5793 else if MBTEST(dolbrace_state == DOLBRACE_PARAM && strchr ("#%^,~:-=?+/", ch) != 0)
5794 dolbrace_state = DOLBRACE_OP;
5795 else if MBTEST(dolbrace_state == DOLBRACE_OP && strchr ("#%^,~:-=?+/", ch) == 0)
5796 dolbrace_state = DOLBRACE_WORD;
5797 }
5798
3185942a 5799 /* The big hammer. Single quotes aren't special in double quotes. The
495aee44 5800 problem is that Posix used to say the single quotes are semi-special:
3185942a
JA
5801 within a double-quoted ${...} construct "an even number of
5802 unescaped double-quotes or single-quotes, if any, shall occur." */
495aee44 5803 /* This was changed in Austin Group Interp 221 */
bc63a081 5804 if MBTEST(posixly_correct && shell_compatibility_level > 41 && dolbrace_state != DOLBRACE_QUOTE && dolbrace_state != DOLBRACE_QUOTE2 && (flags & P_DQUOTE) && (flags & P_DOLBRACE) && ch == '\'')
3185942a 5805 continue;
3185942a
JA
5806
5807 /* Could also check open == '`' if we want to parse grouping constructs
5808 inside old-style command substitution. */
5809 if (open != close) /* a grouping construct */
5810 {
5811 if MBTEST(shellquote (ch))
5812 {
5813 /* '', ``, or "" inside $(...) or other grouping construct. */
5814 push_delimiter (dstack, ch);
5815 if MBTEST((tflags & LEX_WASDOL) && ch == '\'') /* $'...' inside group */
5816 nestret = parse_matched_pair (ch, ch, ch, &nestlen, P_ALLOWESC|rflags);
5817 else
5818 nestret = parse_matched_pair (ch, ch, ch, &nestlen, rflags);
5819 pop_delimiter (dstack);
5820 CHECK_NESTRET_ERROR ();
5821
5822 if MBTEST((tflags & LEX_WASDOL) && ch == '\'' && (extended_quote || (rflags & P_DQUOTE) == 0))
5823 {
5824 /* Translate $'...' here. */
5825 ttrans = ansiexpand (nestret, 0, nestlen - 1, &ttranslen);
5826 xfree (nestret);
5827
ac50fbac
CR
5828 /* If we're parsing a double-quoted brace expansion and we are
5829 not in a place where single quotes are treated specially,
5830 make sure we single-quote the results of the ansi
5831 expansion because quote removal should remove them later */
5832 /* FLAG POSIX INTERP 221 */
5833 if ((shell_compatibility_level > 42) && (rflags & P_DQUOTE) && (dolbrace_state == DOLBRACE_QUOTE2) && (flags & P_DOLBRACE))
5834 {
5835 nestret = sh_single_quote (ttrans);
5836 free (ttrans);
5837 nestlen = strlen (nestret);
5838 }
5839 else if ((rflags & P_DQUOTE) == 0)
3185942a
JA
5840 {
5841 nestret = sh_single_quote (ttrans);
5842 free (ttrans);
5843 nestlen = strlen (nestret);
5844 }
5845 else
5846 {
5847 nestret = ttrans;
5848 nestlen = ttranslen;
5849 }
5850 retind -= 2; /* back up before the $' */
5851 }
5852 else if MBTEST((tflags & LEX_WASDOL) && ch == '"' && (extended_quote || (rflags & P_DQUOTE) == 0))
5853 {
5854 /* Locale expand $"..." here. */
5855 ttrans = localeexpand (nestret, 0, nestlen - 1, start_lineno, &ttranslen);
5856 xfree (nestret);
5857
5858 nestret = sh_mkdoublequoted (ttrans, ttranslen, 0);
5859 free (ttrans);
5860 nestlen = ttranslen + 2;
5861 retind -= 2; /* back up before the $" */
5862 }
5863
5864 APPEND_NESTRET ();
5865 FREE (nestret);
5866 }
a0c0a00f 5867 else if ((flags & (P_ARRAYSUB|P_DOLBRACE)) && (tflags & LEX_WASDOL) && (ch == '(' || ch == '{' || ch == '[')) /* ) } ] */
0001803f 5868 goto parse_dollar_word;
3185942a
JA
5869 }
5870 /* Parse an old-style command substitution within double quotes as a
5871 single word. */
5872 /* XXX - sh and ksh93 don't do this - XXX */
5873 else if MBTEST(open == '"' && ch == '`')
5874 {
5875 nestret = parse_matched_pair (0, '`', '`', &nestlen, rflags);
5876
5877 CHECK_NESTRET_ERROR ();
5878 APPEND_NESTRET ();
5879
5880 FREE (nestret);
5881 }
5882 else if MBTEST(open != '`' && (tflags & LEX_WASDOL) && (ch == '(' || ch == '{' || ch == '[')) /* ) } ] */
5883 /* check for $(), $[], or ${} inside quoted string. */
5884 {
0001803f 5885parse_dollar_word:
3185942a
JA
5886 if (open == ch) /* undo previous increment */
5887 count--;
5888 if (ch == '(') /* ) */
5889 nestret = parse_comsub (0, '(', ')', &nestlen, (rflags|P_COMMAND) & ~P_DQUOTE);
5890 else if (ch == '{') /* } */
495aee44 5891 nestret = parse_matched_pair (0, '{', '}', &nestlen, P_FIRSTCLOSE|P_DOLBRACE|rflags);
3185942a
JA
5892 else if (ch == '[') /* ] */
5893 nestret = parse_matched_pair (0, '[', ']', &nestlen, rflags);
5894
5895 CHECK_NESTRET_ERROR ();
5896 APPEND_NESTRET ();
726f6388 5897
3185942a
JA
5898 FREE (nestret);
5899 }
5900 if MBTEST(ch == '$')
5901 tflags |= LEX_WASDOL;
5902 else
5903 tflags &= ~LEX_WASDOL;
5904 }
726f6388 5905
3185942a
JA
5906 ret[retind] = '\0';
5907 if (lenp)
5908 *lenp = retind;
0001803f 5909/*itrace("parse_matched_pair[%d]: returning %s", line_number, ret);*/
3185942a
JA
5910 return ret;
5911}
726f6388 5912
a0c0a00f
CR
5913#if defined (DEBUG)
5914static void
5915dump_tflags (flags)
5916 int flags;
5917{
5918 int f;
5919
5920 f = flags;
5921 fprintf (stderr, "%d -> ", f);
5922 if (f & LEX_WASDOL)
5923 {
5924 f &= ~LEX_WASDOL;
5925 fprintf (stderr, "LEX_WASDOL%s", f ? "|" : "");
5926 }
5927 if (f & LEX_CKCOMMENT)
5928 {
5929 f &= ~LEX_CKCOMMENT;
5930 fprintf (stderr, "LEX_CKCOMMENT%s", f ? "|" : "");
5931 }
5932 if (f & LEX_INCOMMENT)
5933 {
5934 f &= ~LEX_INCOMMENT;
5935 fprintf (stderr, "LEX_INCOMMENT%s", f ? "|" : "");
5936 }
5937 if (f & LEX_PASSNEXT)
5938 {
5939 f &= ~LEX_PASSNEXT;
5940 fprintf (stderr, "LEX_PASSNEXT%s", f ? "|" : "");
5941 }
5942 if (f & LEX_RESWDOK)
5943 {
5944 f &= ~LEX_RESWDOK;
5945 fprintf (stderr, "LEX_RESWDOK%s", f ? "|" : "");
5946 }
5947 if (f & LEX_CKCASE)
5948 {
5949 f &= ~LEX_CKCASE;
5950 fprintf (stderr, "LEX_CKCASE%s", f ? "|" : "");
5951 }
5952 if (f & LEX_INCASE)
5953 {
5954 f &= ~LEX_INCASE;
5955 fprintf (stderr, "LEX_INCASE%s", f ? "|" : "");
5956 }
5957 if (f & LEX_INHEREDOC)
5958 {
5959 f &= ~LEX_INHEREDOC;
5960 fprintf (stderr, "LEX_INHEREDOC%s", f ? "|" : "");
5961 }
5962 if (f & LEX_HEREDELIM)
5963 {
5964 f &= ~LEX_HEREDELIM;
5965 fprintf (stderr, "LEX_HEREDELIM%s", f ? "|" : "");
5966 }
5967 if (f & LEX_STRIPDOC)
5968 {
5969 f &= ~LEX_STRIPDOC;
5970 fprintf (stderr, "LEX_WASDOL%s", f ? "|" : "");
5971 }
5972 if (f & LEX_QUOTEDDOC)
5973 {
5974 f &= ~LEX_QUOTEDDOC;
5975 fprintf (stderr, "LEX_QUOTEDDOC%s", f ? "|" : "");
5976 }
5977 if (f & LEX_INWORD)
5978 {
5979 f &= ~LEX_INWORD;
5980 fprintf (stderr, "LEX_INWORD%s", f ? "|" : "");
5981 }
5982
5983 fprintf (stderr, "\n");
5984 fflush (stderr);
5985}
5986#endif
5987
3185942a
JA
5988/* Parse a $(...) command substitution. This is messier than I'd like, and
5989 reproduces a lot more of the token-reading code than I'd like. */
28ef6c31 5990static char *
3185942a 5991parse_comsub (qc, open, close, lenp, flags)
28ef6c31
JA
5992 int qc; /* `"' if this construct is within double quotes */
5993 int open, close;
5994 int *lenp, flags;
5995{
0001803f 5996 int count, ch, peekc, tflags, lex_rwlen, lex_wlen, lex_firstind;
3185942a
JA
5997 int nestlen, ttranslen, start_lineno;
5998 char *ret, *nestret, *ttrans, *heredelim;
5999 int retind, retsize, rflags, hdlen;
ccc6cda3 6000
495aee44
CR
6001 /* Posix interp 217 says arithmetic expressions have precedence, so
6002 assume $(( introduces arithmetic expansion and parse accordingly. */
6003 peekc = shell_getc (0);
6004 shell_ungetc (peekc);
6005 if (peekc == '(')
6006 return (parse_matched_pair (qc, open, close, lenp, 0));
6007
3185942a 6008/*itrace("parse_comsub: qc = `%c' open = %c close = %c", qc, open, close);*/
28ef6c31 6009 count = 1;
3185942a
JA
6010 tflags = LEX_RESWDOK;
6011
6012 if ((flags & P_COMMAND) && qc != '\'' && qc != '"' && (flags & P_DQUOTE) == 0)
6013 tflags |= LEX_CKCASE;
6014 if ((tflags & LEX_CKCASE) && (interactive == 0 || interactive_comments))
6015 tflags |= LEX_CKCOMMENT;
d166f048 6016
b80f6443 6017 /* RFLAGS is the set of flags we want to pass to recursive calls. */
3185942a 6018 rflags = (flags & P_DQUOTE);
b80f6443 6019
f73dda09 6020 ret = (char *)xmalloc (retsize = 64);
28ef6c31
JA
6021 retind = 0;
6022
6023 start_lineno = line_number;
0001803f 6024 lex_rwlen = lex_wlen = 0;
3185942a
JA
6025
6026 heredelim = 0;
6027 lex_firstind = -1;
6028
28ef6c31
JA
6029 while (count)
6030 {
3185942a 6031comsub_readchar:
495aee44 6032 ch = shell_getc (qc != '\'' && (tflags & (LEX_INCOMMENT|LEX_PASSNEXT)) == 0);
0628567a 6033
28ef6c31 6034 if (ch == EOF)
ccc6cda3 6035 {
3185942a 6036eof_error:
28ef6c31 6037 free (ret);
3185942a 6038 FREE (heredelim);
b80f6443 6039 parser_error (start_lineno, _("unexpected EOF while looking for matching `%c'"), close);
28ef6c31
JA
6040 EOF_Reached = 1; /* XXX */
6041 return (&matched_pair_error);
ccc6cda3
JA
6042 }
6043
3185942a
JA
6044 /* If we hit the end of a line and are reading the contents of a here
6045 document, and it's not the same line that the document starts on,
6046 check for this line being the here doc delimiter. Otherwise, if
6047 we're in a here document, mark the next character as the beginning
6048 of a line. */
6049 if (ch == '\n')
6050 {
6051 if ((tflags & LEX_HEREDELIM) && heredelim)
6052 {
6053 tflags &= ~LEX_HEREDELIM;
6054 tflags |= LEX_INHEREDOC;
6055 lex_firstind = retind + 1;
6056 }
6057 else if (tflags & LEX_INHEREDOC)
6058 {
6059 int tind;
6060 tind = lex_firstind;
6061 while ((tflags & LEX_STRIPDOC) && ret[tind] == '\t')
6062 tind++;
6063 if (STREQN (ret + tind, heredelim, hdlen))
6064 {
a0c0a00f 6065 tflags &= ~(LEX_STRIPDOC|LEX_INHEREDOC|LEX_QUOTEDDOC);
3185942a 6066/*itrace("parse_comsub:%d: found here doc end `%s'", line_number, ret + tind);*/
0001803f
CR
6067 free (heredelim);
6068 heredelim = 0;
3185942a
JA
6069 lex_firstind = -1;
6070 }
6071 else
6072 lex_firstind = retind + 1;
6073 }
6074 }
6075
28ef6c31 6076 /* Possible reprompting. */
b80f6443 6077 if (ch == '\n' && SHOULD_PROMPT ())
28ef6c31 6078 prompt_again ();
726f6388 6079
0001803f
CR
6080 /* XXX -- possibly allow here doc to be delimited by ending right
6081 paren. */
6082 if ((tflags & LEX_INHEREDOC) && ch == close && count == 1)
6083 {
6084 int tind;
a0c0a00f 6085/*itrace("parse_comsub:%d: in here doc, ch == close, retind - firstind = %d hdlen = %d retind = %d", line_number, retind-lex_firstind, hdlen, retind);*/
0001803f
CR
6086 tind = lex_firstind;
6087 while ((tflags & LEX_STRIPDOC) && ret[tind] == '\t')
6088 tind++;
6089 if (retind-tind == hdlen && STREQN (ret + tind, heredelim, hdlen))
6090 {
a0c0a00f
CR
6091 tflags &= ~(LEX_STRIPDOC|LEX_INHEREDOC|LEX_QUOTEDDOC);
6092/*itrace("parse_comsub:%d: found here doc end `%*s'", line_number, hdlen, ret + tind);*/
0001803f
CR
6093 free (heredelim);
6094 heredelim = 0;
6095 lex_firstind = -1;
6096 }
6097 }
6098
a0c0a00f
CR
6099 /* Don't bother counting parens or doing anything else if in a comment or
6100 here document (not exactly right for here-docs -- if we want to allow
6101 recursive calls to parse_comsub to have their own here documents,
6102 change the LEX_INHEREDOC to LEX_QUOTEDDOC here and uncomment the next
6103 clause below. Note that to make this work completely, we need to make
6104 additional changes to allow xparse_dolparen to work right when the
6105 command substitution is parsed, because read_secondary_line doesn't know
6106 to recursively parse through command substitutions embedded in here-
6107 documents */
3185942a 6108 if (tflags & (LEX_INCOMMENT|LEX_INHEREDOC))
95732b49
JA
6109 {
6110 /* Add this character. */
6111 RESIZE_MALLOCED_BUFFER (ret, retind, 1, retsize, 64);
6112 ret[retind++] = ch;
6113
3185942a 6114 if ((tflags & LEX_INCOMMENT) && ch == '\n')
ac50fbac 6115 {
0001803f 6116/*itrace("parse_comsub:%d: lex_incomment -> 0 ch = `%c'", line_number, ch);*/
ac50fbac
CR
6117 tflags &= ~LEX_INCOMMENT;
6118 }
95732b49
JA
6119
6120 continue;
6121 }
a0c0a00f
CR
6122#if 0
6123 /* If we're going to recursively parse a command substitution inside a
6124 here-document, make sure we call parse_comsub recursively below. See
6125 above for additional caveats. */
6126 if ((tflags & LEX_INHEREDOC) && ((tflags & LEX_WASDOL) == 0 || ch != '(')) /*)*/
6127 {
6128 /* Add this character. */
6129 RESIZE_MALLOCED_BUFFER (ret, retind, 1, retsize, 64);
6130 ret[retind++] = ch;
6131 if MBTEST(ch == '$')
6132 tflags |= LEX_WASDOL;
6133 else
6134 tflags &= ~LEX_WASDOL;
6135 }
6136#endif
95732b49 6137
0001803f
CR
6138 if (tflags & LEX_PASSNEXT) /* last char was backslash */
6139 {
6140/*itrace("parse_comsub:%d: lex_passnext -> 0 ch = `%c' (%d)", line_number, ch, __LINE__);*/
6141 tflags &= ~LEX_PASSNEXT;
6142 if (qc != '\'' && ch == '\n') /* double-quoted \<newline> disappears. */
6143 {
6144 if (retind > 0)
6145 retind--; /* swallow previously-added backslash */
6146 continue;
6147 }
6148
6149 RESIZE_MALLOCED_BUFFER (ret, retind, 2, retsize, 64);
ac50fbac 6150 if MBTEST(ch == CTLESC)
0001803f
CR
6151 ret[retind++] = CTLESC;
6152 ret[retind++] = ch;
6153 continue;
6154 }
6155
6156 /* If this is a shell break character, we are not in a word. If not,
6157 we either start or continue a word. */
6158 if MBTEST(shellbreak (ch))
6159 {
6160 tflags &= ~LEX_INWORD;
6161/*itrace("parse_comsub:%d: lex_inword -> 0 ch = `%c' (%d)", line_number, ch, __LINE__);*/
6162 }
6163 else
6164 {
6165 if (tflags & LEX_INWORD)
6166 {
6167 lex_wlen++;
6168/*itrace("parse_comsub:%d: lex_inword == 1 ch = `%c' lex_wlen = %d (%d)", line_number, ch, lex_wlen, __LINE__);*/
6169 }
6170 else
6171 {
6172/*itrace("parse_comsub:%d: lex_inword -> 1 ch = `%c' (%d)", line_number, ch, __LINE__);*/
6173 tflags |= LEX_INWORD;
6174 lex_wlen = 0;
ae339e9c
CR
6175 if (tflags & LEX_RESWDOK)
6176 lex_rwlen = 0;
0001803f
CR
6177 }
6178 }
6179
3185942a 6180 /* Skip whitespace */
495aee44 6181 if MBTEST(shellblank (ch) && (tflags & LEX_HEREDELIM) == 0 && lex_rwlen == 0)
3185942a
JA
6182 {
6183 /* Add this character. */
6184 RESIZE_MALLOCED_BUFFER (ret, retind, 1, retsize, 64);
6185 ret[retind++] = ch;
6186 continue;
6187 }
6188
6189 /* Either we are looking for the start of the here-doc delimiter
6190 (lex_firstind == -1) or we are reading one (lex_firstind >= 0).
6191 If this character is a shell break character and we are reading
6192 the delimiter, save it and note that we are now reading a here
6193 document. If we've found the start of the delimiter, note it by
6194 setting lex_firstind. Backslashes can quote shell metacharacters
6195 in here-doc delimiters. */
6196 if (tflags & LEX_HEREDELIM)
0628567a 6197 {
3185942a
JA
6198 if (lex_firstind == -1 && shellbreak (ch) == 0)
6199 lex_firstind = retind;
0001803f
CR
6200#if 0
6201 else if (heredelim && (tflags & LEX_PASSNEXT) == 0 && ch == '\n')
6202 {
6203 tflags |= LEX_INHEREDOC;
6204 tflags &= ~LEX_HEREDELIM;
6205 lex_firstind = retind + 1;
6206 }
6207#endif
3185942a
JA
6208 else if (lex_firstind >= 0 && (tflags & LEX_PASSNEXT) == 0 && shellbreak (ch))
6209 {
0001803f
CR
6210 if (heredelim == 0)
6211 {
6212 nestret = substring (ret, lex_firstind, retind);
6213 heredelim = string_quote_removal (nestret, 0);
0001803f 6214 hdlen = STRLEN(heredelim);
3185942a 6215/*itrace("parse_comsub:%d: found here doc delimiter `%s' (%d)", line_number, heredelim, hdlen);*/
a0c0a00f
CR
6216 if (STREQ (heredelim, nestret) == 0)
6217 tflags |= LEX_QUOTEDDOC;
6218 free (nestret);
0001803f 6219 }
3185942a
JA
6220 if (ch == '\n')
6221 {
6222 tflags |= LEX_INHEREDOC;
6223 tflags &= ~LEX_HEREDELIM;
6224 lex_firstind = retind + 1;
6225 }
6226 else
6227 lex_firstind = -1;
6228 }
0628567a
JA
6229 }
6230
3185942a 6231 /* Meta-characters that can introduce a reserved word. Not perfect yet. */
0001803f 6232 if MBTEST((tflags & LEX_RESWDOK) == 0 && (tflags & LEX_CKCASE) && (tflags & LEX_INCOMMENT) == 0 && (shellmeta(ch) || ch == '\n'))
726f6388 6233 {
3185942a
JA
6234 /* Add this character. */
6235 RESIZE_MALLOCED_BUFFER (ret, retind, 1, retsize, 64);
6236 ret[retind++] = ch;
6237 peekc = shell_getc (1);
6238 if (ch == peekc && (ch == '&' || ch == '|' || ch == ';')) /* two-character tokens */
6239 {
6240 RESIZE_MALLOCED_BUFFER (ret, retind, 1, retsize, 64);
6241 ret[retind++] = peekc;
0001803f 6242/*itrace("parse_comsub:%d: set lex_reswordok = 1, ch = `%c'", line_number, ch);*/
3185942a
JA
6243 tflags |= LEX_RESWDOK;
6244 lex_rwlen = 0;
6245 continue;
6246 }
6247 else if (ch == '\n' || COMSUB_META(ch))
6248 {
6249 shell_ungetc (peekc);
3185942a 6250/*itrace("parse_comsub:%d: set lex_reswordok = 1, ch = `%c'", line_number, ch);*/
0001803f 6251 tflags |= LEX_RESWDOK;
3185942a
JA
6252 lex_rwlen = 0;
6253 continue;
6254 }
6255 else if (ch == EOF)
6256 goto eof_error;
6257 else
6258 {
6259 /* `unget' the character we just added and fall through */
6260 retind--;
6261 shell_ungetc (peekc);
6262 }
6263 }
6264
6265 /* If we can read a reserved word, try to read one. */
6266 if (tflags & LEX_RESWDOK)
6267 {
a0c0a00f 6268 if MBTEST(islower ((unsigned char)ch))
3185942a
JA
6269 {
6270 /* Add this character. */
6271 RESIZE_MALLOCED_BUFFER (ret, retind, 1, retsize, 64);
6272 ret[retind++] = ch;
6273 lex_rwlen++;
6274 continue;
6275 }
6276 else if MBTEST(lex_rwlen == 4 && shellbreak (ch))
6277 {
6278 if (STREQN (ret + retind - 4, "case", 4))
ac50fbac
CR
6279 {
6280 tflags |= LEX_INCASE;
a0c0a00f 6281 tflags &= ~LEX_RESWDOK;
0001803f 6282/*itrace("parse_comsub:%d: found `case', lex_incase -> 1 lex_reswdok -> 0", line_number);*/
ac50fbac 6283 }
3185942a 6284 else if (STREQN (ret + retind - 4, "esac", 4))
ac50fbac
CR
6285 {
6286 tflags &= ~LEX_INCASE;
a0c0a00f
CR
6287/*itrace("parse_comsub:%d: found `esac', lex_incase -> 0 lex_reswdok -> 1", line_number);*/
6288 tflags |= LEX_RESWDOK;
6289 lex_rwlen = 0;
6290 }
6291 else if (STREQN (ret + retind - 4, "done", 4) ||
6292 STREQN (ret + retind - 4, "then", 4) ||
6293 STREQN (ret + retind - 4, "else", 4) ||
6294 STREQN (ret + retind - 4, "elif", 4) ||
6295 STREQN (ret + retind - 4, "time", 4))
6296 {
6297 /* these are four-character reserved words that can be
6298 followed by a reserved word; anything else turns off
6299 the reserved-word-ok flag */
6300/*itrace("parse_comsub:%d: found `%.4s', lex_reswdok -> 1", line_number, ret+retind-4);*/
6301 tflags |= LEX_RESWDOK;
6302 lex_rwlen = 0;
6303 }
6304 else
6305 {
6306 tflags &= ~LEX_RESWDOK;
6307/*itrace("parse_comsub:%d: found `%.4s', lex_reswdok -> 0", line_number, ret+retind-4);*/
ac50fbac 6308 }
3185942a 6309 }
0001803f
CR
6310 else if MBTEST((tflags & LEX_CKCOMMENT) && ch == '#' && (lex_rwlen == 0 || ((tflags & LEX_INWORD) && lex_wlen == 0)))
6311 ; /* don't modify LEX_RESWDOK if we're starting a comment */
ac50fbac
CR
6312 /* Allow `do' followed by space, tab, or newline to preserve the
6313 RESWDOK flag, but reset the reserved word length counter so we
6314 can read another one. */
6315 else if MBTEST(((tflags & LEX_INCASE) == 0) &&
a0c0a00f 6316 (isblank((unsigned char)ch) || ch == '\n') &&
ac50fbac
CR
6317 lex_rwlen == 2 &&
6318 STREQN (ret + retind - 2, "do", 2))
6319 {
a0c0a00f 6320/*itrace("parse_comsub:%d: lex_incase == 0 found `%c', found \"do\"", line_number, ch);*/
ac50fbac
CR
6321 lex_rwlen = 0;
6322 }
0001803f
CR
6323 else if MBTEST((tflags & LEX_INCASE) && ch != '\n')
6324 /* If we can read a reserved word and we're in case, we're at the
6325 point where we can read a new pattern list or an esac. We
6326 handle the esac case above. If we read a newline, we want to
6327 leave LEX_RESWDOK alone. If we read anything else, we want to
6328 turn off LEX_RESWDOK, since we're going to read a pattern list. */
ac50fbac
CR
6329 {
6330 tflags &= ~LEX_RESWDOK;
0001803f 6331/*itrace("parse_comsub:%d: lex_incase == 1 found `%c', lex_reswordok -> 0", line_number, ch);*/
ac50fbac 6332 }
0001803f 6333 else if MBTEST(shellbreak (ch) == 0)
ac50fbac
CR
6334 {
6335 tflags &= ~LEX_RESWDOK;
3185942a 6336/*itrace("parse_comsub:%d: found `%c', lex_reswordok -> 0", line_number, ch);*/
ac50fbac
CR
6337 }
6338#if 0
6339 /* If we find a space or tab but have read something and it's not
6340 `do', turn off the reserved-word-ok flag */
a0c0a00f 6341 else if MBTEST(isblank ((unsigned char)ch) && lex_rwlen > 0)
ac50fbac
CR
6342 {
6343 tflags &= ~LEX_RESWDOK;
6344/*itrace("parse_comsub:%d: found `%c', lex_reswordok -> 0", line_number, ch);*/
6345 }
6346#endif
3185942a
JA
6347 }
6348
0001803f 6349 /* Might be the start of a here-doc delimiter */
3185942a
JA
6350 if MBTEST((tflags & LEX_INCOMMENT) == 0 && (tflags & LEX_CKCASE) && ch == '<')
6351 {
6352 /* Add this character. */
6353 RESIZE_MALLOCED_BUFFER (ret, retind, 1, retsize, 64);
6354 ret[retind++] = ch;
6355 peekc = shell_getc (1);
6356 if (peekc == EOF)
6357 goto eof_error;
6358 if (peekc == ch)
6359 {
6360 RESIZE_MALLOCED_BUFFER (ret, retind, 1, retsize, 64);
6361 ret[retind++] = peekc;
6362 peekc = shell_getc (1);
6363 if (peekc == EOF)
6364 goto eof_error;
6365 if (peekc == '-')
6366 {
6367 RESIZE_MALLOCED_BUFFER (ret, retind, 1, retsize, 64);
6368 ret[retind++] = peekc;
6369 tflags |= LEX_STRIPDOC;
6370 }
6371 else
6372 shell_ungetc (peekc);
0001803f
CR
6373 if (peekc != '<')
6374 {
6375 tflags |= LEX_HEREDELIM;
6376 lex_firstind = -1;
6377 }
3185942a
JA
6378 continue;
6379 }
6380 else
0001803f 6381 ch = peekc; /* fall through and continue XXX */
3185942a 6382 }
0001803f 6383 else if MBTEST((tflags & LEX_CKCOMMENT) && (tflags & LEX_INCOMMENT) == 0 && ch == '#' && (((tflags & LEX_RESWDOK) && lex_rwlen == 0) || ((tflags & LEX_INWORD) && lex_wlen == 0)))
ac50fbac 6384 {
0001803f 6385/*itrace("parse_comsub:%d: lex_incomment -> 1 (%d)", line_number, __LINE__);*/
ac50fbac
CR
6386 tflags |= LEX_INCOMMENT;
6387 }
3185942a 6388
0001803f 6389 if MBTEST(ch == CTLESC || ch == CTLNUL) /* special shell escapes */
726f6388 6390 {
28ef6c31
JA
6391 RESIZE_MALLOCED_BUFFER (ret, retind, 2, retsize, 64);
6392 ret[retind++] = CTLESC;
6393 ret[retind++] = ch;
6394 continue;
726f6388 6395 }
3185942a
JA
6396#if 0
6397 else if MBTEST((tflags & LEX_INCASE) && ch == close && close == ')')
6398 tflags &= ~LEX_INCASE; /* XXX */
6399#endif
6400 else if MBTEST(ch == close && (tflags & LEX_INCASE) == 0) /* ending delimiter */
ac50fbac
CR
6401 {
6402 count--;
3185942a 6403/*itrace("parse_comsub:%d: found close: count = %d", line_number, count);*/
ac50fbac 6404 }
3185942a 6405 else if MBTEST(((flags & P_FIRSTCLOSE) == 0) && (tflags & LEX_INCASE) == 0 && ch == open) /* nested begin */
ac50fbac
CR
6406 {
6407 count++;
0001803f 6408/*itrace("parse_comsub:%d: found open: count = %d", line_number, count);*/
ac50fbac 6409 }
726f6388 6410
28ef6c31
JA
6411 /* Add this character. */
6412 RESIZE_MALLOCED_BUFFER (ret, retind, 1, retsize, 64);
6413 ret[retind++] = ch;
6414
3185942a
JA
6415 /* If we just read the ending character, don't bother continuing. */
6416 if (count == 0)
6417 break;
726f6388 6418
7117c2d2 6419 if MBTEST(ch == '\\') /* backslashes */
3185942a 6420 tflags |= LEX_PASSNEXT;
28ef6c31 6421
3185942a
JA
6422 if MBTEST(shellquote (ch))
6423 {
6424 /* '', ``, or "" inside $(...). */
6425 push_delimiter (dstack, ch);
6426 if MBTEST((tflags & LEX_WASDOL) && ch == '\'') /* $'...' inside group */
6427 nestret = parse_matched_pair (ch, ch, ch, &nestlen, P_ALLOWESC|rflags);
6428 else
6429 nestret = parse_matched_pair (ch, ch, ch, &nestlen, rflags);
6430 pop_delimiter (dstack);
6431 CHECK_NESTRET_ERROR ();
6432
6433 if MBTEST((tflags & LEX_WASDOL) && ch == '\'' && (extended_quote || (rflags & P_DQUOTE) == 0))
28ef6c31 6434 {
3185942a
JA
6435 /* Translate $'...' here. */
6436 ttrans = ansiexpand (nestret, 0, nestlen - 1, &ttranslen);
6437 xfree (nestret);
95732b49 6438
3185942a 6439 if ((rflags & P_DQUOTE) == 0)
28ef6c31 6440 {
3185942a 6441 nestret = sh_single_quote (ttrans);
28ef6c31 6442 free (ttrans);
3185942a 6443 nestlen = strlen (nestret);
28ef6c31 6444 }
3185942a 6445 else
28ef6c31 6446 {
3185942a
JA
6447 nestret = ttrans;
6448 nestlen = ttranslen;
28ef6c31 6449 }
3185942a 6450 retind -= 2; /* back up before the $' */
28ef6c31 6451 }
3185942a 6452 else if MBTEST((tflags & LEX_WASDOL) && ch == '"' && (extended_quote || (rflags & P_DQUOTE) == 0))
28ef6c31 6453 {
3185942a
JA
6454 /* Locale expand $"..." here. */
6455 ttrans = localeexpand (nestret, 0, nestlen - 1, start_lineno, &ttranslen);
6456 xfree (nestret);
6457
6458 nestret = sh_mkdoublequoted (ttrans, ttranslen, 0);
6459 free (ttrans);
6460 nestlen = ttranslen + 2;
6461 retind -= 2; /* back up before the $" */
28ef6c31 6462 }
3185942a
JA
6463
6464 APPEND_NESTRET ();
28ef6c31
JA
6465 FREE (nestret);
6466 }
3185942a
JA
6467 else if MBTEST((tflags & LEX_WASDOL) && (ch == '(' || ch == '{' || ch == '[')) /* ) } ] */
6468 /* check for $(), $[], or ${} inside command substitution. */
28ef6c31 6469 {
3185942a 6470 if ((tflags & LEX_INCASE) == 0 && open == ch) /* undo previous increment */
28ef6c31
JA
6471 count--;
6472 if (ch == '(') /* ) */
3185942a 6473 nestret = parse_comsub (0, '(', ')', &nestlen, (rflags|P_COMMAND) & ~P_DQUOTE);
28ef6c31 6474 else if (ch == '{') /* } */
495aee44 6475 nestret = parse_matched_pair (0, '{', '}', &nestlen, P_FIRSTCLOSE|P_DOLBRACE|rflags);
28ef6c31 6476 else if (ch == '[') /* ] */
b80f6443 6477 nestret = parse_matched_pair (0, '[', ']', &nestlen, rflags);
95732b49 6478
3185942a
JA
6479 CHECK_NESTRET_ERROR ();
6480 APPEND_NESTRET ();
6481
6482 FREE (nestret);
726f6388 6483 }
3185942a
JA
6484 if MBTEST(ch == '$')
6485 tflags |= LEX_WASDOL;
6486 else
6487 tflags &= ~LEX_WASDOL;
726f6388 6488 }
ccc6cda3 6489
3185942a 6490 FREE (heredelim);
28ef6c31
JA
6491 ret[retind] = '\0';
6492 if (lenp)
6493 *lenp = retind;
3185942a
JA
6494/*itrace("parse_comsub:%d: returning `%s'", line_number, ret);*/
6495 return ret;
6496}
6497
495aee44 6498/* Recursively call the parser to parse a $(...) command substitution. */
3185942a
JA
6499char *
6500xparse_dolparen (base, string, indp, flags)
6501 char *base;
6502 char *string;
6503 int *indp;
6504 int flags;
6505{
6506 sh_parser_state_t ps;
509a4430 6507 sh_input_line_state_t ls;
ac50fbac 6508 int orig_ind, nc, sflags, orig_eof_token;
3185942a
JA
6509 char *ret, *s, *ep, *ostring;
6510
6511 /*yydebug = 1;*/
6512 orig_ind = *indp;
6513 ostring = string;
6514
509a4430 6515/*itrace("xparse_dolparen: size = %d shell_input_line = `%s'", shell_input_line_size, shell_input_line);*/
3185942a
JA
6516 sflags = SEVAL_NONINT|SEVAL_NOHIST|SEVAL_NOFREE;
6517 if (flags & SX_NOLONGJMP)
6518 sflags |= SEVAL_NOLONGJMP;
6519 save_parser_state (&ps);
509a4430 6520 save_input_line_state (&ls);
ac50fbac 6521 orig_eof_token = shell_eof_token;
3185942a
JA
6522
6523 /*(*/
6524 parser_state |= PST_CMDSUBST|PST_EOFTOKEN; /* allow instant ')' */ /*(*/
6525 shell_eof_token = ')';
a0c0a00f
CR
6526
6527 nc = parse_string (string, "command substitution", sflags, &ep);
3185942a 6528
ac50fbac 6529 shell_eof_token = orig_eof_token;
3185942a
JA
6530 restore_parser_state (&ps);
6531 reset_parser ();
509a4430
CR
6532 /* reset_parser clears shell_input_line and associated variables */
6533 restore_input_line_state (&ls);
ca6a2ba4
CR
6534
6535 token_to_read = 0;
3185942a 6536
a0c0a00f
CR
6537 /* If parse_string returns < 0, we need to jump to top level with the
6538 negative of the return value */
6539 if (nc < 0)
6540 jump_to_top_level (-nc); /* XXX */
6541
3185942a
JA
6542 /* Need to find how many characters parse_and_execute consumed, update
6543 *indp, if flags != 0, copy the portion of the string parsed into RET
6544 and return it. If flags & 1 (EX_NOALLOC) we can return NULL. */
6545
6546 /*(*/
6547 if (ep[-1] != ')')
6548 {
6549#if DEBUG
6550 if (ep[-1] != '\n')
6551 itrace("xparse_dolparen:%d: ep[-1] != RPAREN (%d), ep = `%s'", line_number, ep[-1], ep);
6552#endif
6553 while (ep > ostring && ep[-1] == '\n') ep--;
6554 }
6555
6556 nc = ep - ostring;
6557 *indp = ep - base - 1;
6558
6559 /*(*/
6560#if DEBUG
6561 if (base[*indp] != ')')
6562 itrace("xparse_dolparen:%d: base[%d] != RPAREN (%d), base = `%s'", line_number, *indp, base[*indp], base);
6563#endif
6564
6565 if (flags & SX_NOALLOC)
6566 return (char *)NULL;
6567
6568 if (nc == 0)
6569 {
6570 ret = xmalloc (1);
6571 ret[0] = '\0';
6572 }
6573 else
6574 ret = substring (ostring, 0, nc - 1);
6575
28ef6c31
JA
6576 return ret;
6577}
726f6388 6578
28ef6c31 6579#if defined (DPAREN_ARITHMETIC) || defined (ARITH_FOR_COMMAND)
7117c2d2
JA
6580/* Parse a double-paren construct. It can be either an arithmetic
6581 command, an arithmetic `for' command, or a nested subshell. Returns
6582 the parsed token, -1 on error, or -2 if we didn't do anything and
6583 should just go on. */
6584static int
6585parse_dparen (c)
6586 int c;
6587{
0628567a
JA
6588 int cmdtyp, sline;
6589 char *wval;
7117c2d2
JA
6590 WORD_DESC *wd;
6591
6592#if defined (ARITH_FOR_COMMAND)
6593 if (last_read_token == FOR)
6594 {
6595 arith_for_lineno = line_number;
b80f6443 6596 cmdtyp = parse_arith_cmd (&wval, 0);
7117c2d2
JA
6597 if (cmdtyp == 1)
6598 {
95732b49
JA
6599 wd = alloc_word_desc ();
6600 wd->word = wval;
7117c2d2 6601 yylval.word_list = make_word_list (wd, (WORD_LIST *)NULL);
7117c2d2
JA
6602 return (ARITH_FOR_EXPRS);
6603 }
6604 else
6605 return -1; /* ERROR */
6606 }
6607#endif
6608
6609#if defined (DPAREN_ARITHMETIC)
6610 if (reserved_word_acceptable (last_read_token))
6611 {
6612 sline = line_number;
95732b49 6613
b80f6443 6614 cmdtyp = parse_arith_cmd (&wval, 0);
7117c2d2
JA
6615 if (cmdtyp == 1) /* arithmetic command */
6616 {
95732b49
JA
6617 wd = alloc_word_desc ();
6618 wd->word = wval;
6619 wd->flags = W_QUOTED|W_NOSPLIT|W_NOGLOB|W_DQUOTE;
7117c2d2 6620 yylval.word_list = make_word_list (wd, (WORD_LIST *)NULL);
7117c2d2
JA
6621 return (ARITH_CMD);
6622 }
6623 else if (cmdtyp == 0) /* nested subshell */
6624 {
6625 push_string (wval, 0, (alias_t *)NULL);
ac50fbac 6626 pushed_string_list->flags = PSH_DPAREN;
7117c2d2
JA
6627 if ((parser_state & PST_CASEPAT) == 0)
6628 parser_state |= PST_SUBSHELL;
6629 return (c);
6630 }
6631 else /* ERROR */
6632 return -1;
6633 }
6634#endif
6635
6636 return -2; /* XXX */
6637}
6638
28ef6c31
JA
6639/* We've seen a `(('. Look for the matching `))'. If we get it, return 1.
6640 If not, assume it's a nested subshell for backwards compatibility and
6641 return 0. In any case, put the characters we've consumed into a locally-
6642 allocated buffer and make *ep point to that buffer. Return -1 on an
6643 error, for example EOF. */
6644static int
b80f6443 6645parse_arith_cmd (ep, adddq)
28ef6c31 6646 char **ep;
b80f6443 6647 int adddq;
28ef6c31
JA
6648{
6649 int exp_lineno, rval, c;
f73dda09 6650 char *ttok, *tokstr;
28ef6c31 6651 int ttoklen;
726f6388 6652
28ef6c31
JA
6653 exp_lineno = line_number;
6654 ttok = parse_matched_pair (0, '(', ')', &ttoklen, 0);
6655 rval = 1;
6656 if (ttok == &matched_pair_error)
6657 return -1;
6658 /* Check that the next character is the closing right paren. If
6659 not, this is a syntax error. ( */
7117c2d2
JA
6660 c = shell_getc (0);
6661 if MBTEST(c != ')')
28ef6c31
JA
6662 rval = 0;
6663
f73dda09 6664 tokstr = (char *)xmalloc (ttoklen + 4);
28ef6c31 6665
b80f6443
JA
6666 /* if ADDDQ != 0 then (( ... )) -> "..." */
6667 if (rval == 1 && adddq) /* arith cmd, add double quotes */
726f6388 6668 {
b80f6443
JA
6669 tokstr[0] = '"';
6670 strncpy (tokstr + 1, ttok, ttoklen - 1);
f73dda09
JA
6671 tokstr[ttoklen] = '"';
6672 tokstr[ttoklen+1] = '\0';
726f6388 6673 }
b80f6443
JA
6674 else if (rval == 1) /* arith cmd, don't add double quotes */
6675 {
6676 strncpy (tokstr, ttok, ttoklen - 1);
6677 tokstr[ttoklen-1] = '\0';
6678 }
6679 else /* nested subshell */
726f6388 6680 {
b80f6443
JA
6681 tokstr[0] = '(';
6682 strncpy (tokstr + 1, ttok, ttoklen - 1);
f73dda09
JA
6683 tokstr[ttoklen] = ')';
6684 tokstr[ttoklen+1] = c;
6685 tokstr[ttoklen+2] = '\0';
726f6388 6686 }
b80f6443 6687
f73dda09 6688 *ep = tokstr;
28ef6c31
JA
6689 FREE (ttok);
6690 return rval;
726f6388 6691}
28ef6c31 6692#endif /* DPAREN_ARITHMETIC || ARITH_FOR_COMMAND */
726f6388 6693
28ef6c31 6694#if defined (COND_COMMAND)
7117c2d2
JA
6695static void
6696cond_error ()
6697{
6698 char *etext;
6699
6700 if (EOF_Reached && cond_token != COND_ERROR) /* [[ */
b80f6443 6701 parser_error (cond_lineno, _("unexpected EOF while looking for `]]'"));
7117c2d2
JA
6702 else if (cond_token != COND_ERROR)
6703 {
6704 if (etext = error_token_from_token (cond_token))
6705 {
b80f6443 6706 parser_error (cond_lineno, _("syntax error in conditional expression: unexpected token `%s'"), etext);
7117c2d2
JA
6707 free (etext);
6708 }
6709 else
b80f6443 6710 parser_error (cond_lineno, _("syntax error in conditional expression"));
7117c2d2
JA
6711 }
6712}
6713
28ef6c31
JA
6714static COND_COM *
6715cond_expr ()
ccc6cda3 6716{
28ef6c31 6717 return (cond_or ());
ccc6cda3
JA
6718}
6719
28ef6c31
JA
6720static COND_COM *
6721cond_or ()
726f6388 6722{
28ef6c31 6723 COND_COM *l, *r;
726f6388 6724
28ef6c31
JA
6725 l = cond_and ();
6726 if (cond_token == OR_OR)
6727 {
6728 r = cond_or ();
6729 l = make_cond_node (COND_OR, (WORD_DESC *)NULL, l, r);
6730 }
6731 return l;
726f6388 6732}
726f6388 6733
28ef6c31
JA
6734static COND_COM *
6735cond_and ()
726f6388 6736{
28ef6c31 6737 COND_COM *l, *r;
726f6388 6738
28ef6c31
JA
6739 l = cond_term ();
6740 if (cond_token == AND_AND)
6741 {
6742 r = cond_and ();
6743 l = make_cond_node (COND_AND, (WORD_DESC *)NULL, l, r);
6744 }
6745 return l;
726f6388
JA
6746}
6747
ccc6cda3 6748static int
28ef6c31 6749cond_skip_newlines ()
726f6388 6750{
28ef6c31 6751 while ((cond_token = read_token (READ)) == '\n')
726f6388 6752 {
b80f6443 6753 if (SHOULD_PROMPT ())
726f6388
JA
6754 prompt_again ();
6755 }
28ef6c31 6756 return (cond_token);
726f6388
JA
6757}
6758
28ef6c31
JA
6759#define COND_RETURN_ERROR() \
6760 do { cond_token = COND_ERROR; return ((COND_COM *)NULL); } while (0)
726f6388 6761
28ef6c31
JA
6762static COND_COM *
6763cond_term ()
726f6388 6764{
28ef6c31
JA
6765 WORD_DESC *op;
6766 COND_COM *term, *tleft, *tright;
6767 int tok, lineno;
7117c2d2 6768 char *etext;
28ef6c31
JA
6769
6770 /* Read a token. It can be a left paren, a `!', a unary operator, or a
6771 word that should be the first argument of a binary operator. Start by
6772 skipping newlines, since this is a compound command. */
6773 tok = cond_skip_newlines ();
6774 lineno = line_number;
6775 if (tok == COND_END)
726f6388 6776 {
28ef6c31 6777 COND_RETURN_ERROR ();
726f6388 6778 }
28ef6c31
JA
6779 else if (tok == '(')
6780 {
6781 term = cond_expr ();
6782 if (cond_token != ')')
6783 {
6784 if (term)
6785 dispose_cond_node (term); /* ( */
7117c2d2
JA
6786 if (etext = error_token_from_token (cond_token))
6787 {
b80f6443 6788 parser_error (lineno, _("unexpected token `%s', expected `)'"), etext);
7117c2d2
JA
6789 free (etext);
6790 }
6791 else
b80f6443 6792 parser_error (lineno, _("expected `)'"));
28ef6c31
JA
6793 COND_RETURN_ERROR ();
6794 }
6795 term = make_cond_node (COND_EXPR, (WORD_DESC *)NULL, term, (COND_COM *)NULL);
6796 (void)cond_skip_newlines ();
6797 }
6798 else if (tok == BANG || (tok == WORD && (yylval.word->word[0] == '!' && yylval.word->word[1] == '\0')))
6799 {
6800 if (tok == WORD)
6801 dispose_word (yylval.word); /* not needed */
6802 term = cond_term ();
6803 if (term)
6804 term->flags |= CMD_INVERT_RETURN;
6805 }
3185942a 6806 else if (tok == WORD && yylval.word->word[0] == '-' && yylval.word->word[2] == 0 && test_unop (yylval.word->word))
28ef6c31
JA
6807 {
6808 op = yylval.word;
6809 tok = read_token (READ);
6810 if (tok == WORD)
6811 {
6812 tleft = make_cond_node (COND_TERM, yylval.word, (COND_COM *)NULL, (COND_COM *)NULL);
6813 term = make_cond_node (COND_UNARY, op, tleft, (COND_COM *)NULL);
6814 }
6815 else
6816 {
6817 dispose_word (op);
7117c2d2
JA
6818 if (etext = error_token_from_token (tok))
6819 {
b80f6443 6820 parser_error (line_number, _("unexpected argument `%s' to conditional unary operator"), etext);
7117c2d2
JA
6821 free (etext);
6822 }
6823 else
b80f6443 6824 parser_error (line_number, _("unexpected argument to conditional unary operator"));
28ef6c31
JA
6825 COND_RETURN_ERROR ();
6826 }
726f6388 6827
28ef6c31
JA
6828 (void)cond_skip_newlines ();
6829 }
6830 else if (tok == WORD) /* left argument to binary operator */
6831 {
6832 /* lhs */
6833 tleft = make_cond_node (COND_TERM, yylval.word, (COND_COM *)NULL, (COND_COM *)NULL);
726f6388 6834
28ef6c31
JA
6835 /* binop */
6836 tok = read_token (READ);
6837 if (tok == WORD && test_binop (yylval.word->word))
0001803f
CR
6838 {
6839 op = yylval.word;
6840 if (op->word[0] == '=' && (op->word[1] == '\0' || (op->word[1] == '=' && op->word[2] == '\0')))
6841 parser_state |= PST_EXTPAT;
6842 else if (op->word[0] == '!' && op->word[1] == '=' && op->word[2] == '\0')
6843 parser_state |= PST_EXTPAT;
6844 }
b80f6443 6845#if defined (COND_REGEXP)
3185942a
JA
6846 else if (tok == WORD && STREQ (yylval.word->word, "=~"))
6847 {
6848 op = yylval.word;
6849 parser_state |= PST_REGEXP;
6850 }
b80f6443 6851#endif
28ef6c31
JA
6852 else if (tok == '<' || tok == '>')
6853 op = make_word_from_token (tok); /* ( */
6854 /* There should be a check before blindly accepting the `)' that we have
6855 seen the opening `('. */
6856 else if (tok == COND_END || tok == AND_AND || tok == OR_OR || tok == ')')
6857 {
6858 /* Special case. [[ x ]] is equivalent to [[ -n x ]], just like
6859 the test command. Similarly for [[ x && expr ]] or
6860 [[ x || expr ]] or [[ (x) ]]. */
6861 op = make_word ("-n");
6862 term = make_cond_node (COND_UNARY, op, tleft, (COND_COM *)NULL);
6863 cond_token = tok;
6864 return (term);
6865 }
6866 else
6867 {
7117c2d2
JA
6868 if (etext = error_token_from_token (tok))
6869 {
b80f6443 6870 parser_error (line_number, _("unexpected token `%s', conditional binary operator expected"), etext);
7117c2d2
JA
6871 free (etext);
6872 }
6873 else
b80f6443 6874 parser_error (line_number, _("conditional binary operator expected"));
28ef6c31
JA
6875 dispose_cond_node (tleft);
6876 COND_RETURN_ERROR ();
6877 }
726f6388 6878
28ef6c31 6879 /* rhs */
0001803f
CR
6880 if (parser_state & PST_EXTPAT)
6881 extended_glob = 1;
28ef6c31 6882 tok = read_token (READ);
0001803f
CR
6883 if (parser_state & PST_EXTPAT)
6884 extended_glob = global_extglob;
6885 parser_state &= ~(PST_REGEXP|PST_EXTPAT);
6886
28ef6c31
JA
6887 if (tok == WORD)
6888 {
6889 tright = make_cond_node (COND_TERM, yylval.word, (COND_COM *)NULL, (COND_COM *)NULL);
6890 term = make_cond_node (COND_BINARY, op, tleft, tright);
6891 }
6892 else
6893 {
7117c2d2
JA
6894 if (etext = error_token_from_token (tok))
6895 {
b80f6443 6896 parser_error (line_number, _("unexpected argument `%s' to conditional binary operator"), etext);
7117c2d2
JA
6897 free (etext);
6898 }
6899 else
b80f6443 6900 parser_error (line_number, _("unexpected argument to conditional binary operator"));
28ef6c31
JA
6901 dispose_cond_node (tleft);
6902 dispose_word (op);
6903 COND_RETURN_ERROR ();
6904 }
726f6388 6905
28ef6c31
JA
6906 (void)cond_skip_newlines ();
6907 }
6908 else
6909 {
6910 if (tok < 256)
b80f6443 6911 parser_error (line_number, _("unexpected token `%c' in conditional command"), tok);
7117c2d2
JA
6912 else if (etext = error_token_from_token (tok))
6913 {
b80f6443 6914 parser_error (line_number, _("unexpected token `%s' in conditional command"), etext);
7117c2d2
JA
6915 free (etext);
6916 }
28ef6c31 6917 else
b80f6443 6918 parser_error (line_number, _("unexpected token %d in conditional command"), tok);
28ef6c31
JA
6919 COND_RETURN_ERROR ();
6920 }
6921 return (term);
6922}
ccc6cda3 6923
28ef6c31
JA
6924/* This is kind of bogus -- we slip a mini recursive-descent parser in
6925 here to handle the conditional statement syntax. */
6926static COMMAND *
6927parse_cond_command ()
6928{
6929 COND_COM *cexp;
ccc6cda3 6930
0001803f 6931 global_extglob = extended_glob;
28ef6c31
JA
6932 cexp = cond_expr ();
6933 return (make_cond_command (cexp));
6934}
6935#endif
ccc6cda3 6936
7117c2d2
JA
6937#if defined (ARRAY_VARS)
6938/* When this is called, it's guaranteed that we don't care about anything
6939 in t beyond i. We do save and restore the chars, though. */
6940static int
6941token_is_assignment (t, i)
6942 char *t;
6943 int i;
6944{
6945 unsigned char c, c1;
6946 int r;
6947
6948 c = t[i]; c1 = t[i+1];
6949 t[i] = '='; t[i+1] = '\0';
b80f6443 6950 r = assignment (t, (parser_state & PST_COMPASSIGN) != 0);
7117c2d2
JA
6951 t[i] = c; t[i+1] = c1;
6952 return r;
6953}
6954
95732b49 6955/* XXX - possible changes here for `+=' */
7117c2d2
JA
6956static int
6957token_is_ident (t, i)
6958 char *t;
6959 int i;
6960{
6961 unsigned char c;
6962 int r;
6963
6964 c = t[i];
6965 t[i] = '\0';
6966 r = legal_identifier (t);
6967 t[i] = c;
6968 return r;
6969}
6970#endif
6971
726f6388 6972static int
28ef6c31
JA
6973read_token_word (character)
6974 int character;
726f6388 6975{
28ef6c31
JA
6976 /* The value for YYLVAL when a WORD is read. */
6977 WORD_DESC *the_word;
726f6388 6978
28ef6c31
JA
6979 /* Index into the token that we are building. */
6980 int token_index;
ccc6cda3 6981
28ef6c31 6982 /* ALL_DIGITS becomes zero when we see a non-digit. */
f73dda09 6983 int all_digit_token;
ccc6cda3 6984
28ef6c31
JA
6985 /* DOLLAR_PRESENT becomes non-zero if we see a `$'. */
6986 int dollar_present;
cce855bc 6987
95732b49
JA
6988 /* COMPOUND_ASSIGNMENT becomes non-zero if we are parsing a compound
6989 assignment. */
6990 int compound_assignment;
6991
28ef6c31
JA
6992 /* QUOTED becomes non-zero if we see one of ("), ('), (`), or (\). */
6993 int quoted;
cce855bc 6994
28ef6c31
JA
6995 /* Non-zero means to ignore the value of the next character, and just
6996 to add it no matter what. */
a0c0a00f 6997 int pass_next_character;
cce855bc 6998
28ef6c31
JA
6999 /* The current delimiting character. */
7000 int cd;
7001 int result, peek_char;
7002 char *ttok, *ttrans;
7003 int ttoklen, ttranslen;
7117c2d2 7004 intmax_t lvalue;
ccc6cda3 7005
28ef6c31 7006 if (token_buffer_size < TOKEN_DEFAULT_INITIAL_SIZE)
f73dda09 7007 token = (char *)xrealloc (token, token_buffer_size = TOKEN_DEFAULT_INITIAL_SIZE);
726f6388 7008
28ef6c31 7009 token_index = 0;
f73dda09 7010 all_digit_token = DIGIT (character);
95732b49 7011 dollar_present = quoted = pass_next_character = compound_assignment = 0;
ccc6cda3 7012
28ef6c31 7013 for (;;)
ccc6cda3 7014 {
28ef6c31
JA
7015 if (character == EOF)
7016 goto got_token;
726f6388 7017
28ef6c31 7018 if (pass_next_character)
726f6388 7019 {
28ef6c31 7020 pass_next_character = 0;
3185942a 7021 goto got_escaped_character;
726f6388 7022 }
726f6388 7023
28ef6c31 7024 cd = current_delimiter (dstack);
ccc6cda3 7025
28ef6c31
JA
7026 /* Handle backslashes. Quote lots of things when not inside of
7027 double-quotes, quote some things inside of double-quotes. */
7117c2d2 7028 if MBTEST(character == '\\')
28ef6c31
JA
7029 {
7030 peek_char = shell_getc (0);
ccc6cda3 7031
28ef6c31
JA
7032 /* Backslash-newline is ignored in all cases except
7033 when quoted with single quotes. */
7034 if (peek_char == '\n')
7035 {
7036 character = '\n';
7037 goto next_character;
7038 }
7039 else
7040 {
7041 shell_ungetc (peek_char);
ccc6cda3 7042
28ef6c31
JA
7043 /* If the next character is to be quoted, note it now. */
7044 if (cd == 0 || cd == '`' ||
f73dda09 7045 (cd == '"' && peek_char >= 0 && (sh_syntaxtab[peek_char] & CBSDQUOTE)))
28ef6c31 7046 pass_next_character++;
ccc6cda3 7047
28ef6c31
JA
7048 quoted = 1;
7049 goto got_character;
7050 }
7051 }
726f6388 7052
28ef6c31 7053 /* Parse a matched pair of quote characters. */
7117c2d2 7054 if MBTEST(shellquote (character))
d166f048 7055 {
28ef6c31 7056 push_delimiter (dstack, character);
95732b49 7057 ttok = parse_matched_pair (character, character, character, &ttoklen, (character == '`') ? P_COMMAND : 0);
28ef6c31
JA
7058 pop_delimiter (dstack);
7059 if (ttok == &matched_pair_error)
7060 return -1; /* Bail immediately. */
7061 RESIZE_MALLOCED_BUFFER (token, token_index, ttoklen + 2,
7062 token_buffer_size, TOKEN_DEFAULT_GROW_SIZE);
7063 token[token_index++] = character;
7064 strcpy (token + token_index, ttok);
7065 token_index += ttoklen;
f73dda09 7066 all_digit_token = 0;
28ef6c31
JA
7067 quoted = 1;
7068 dollar_present |= (character == '"' && strchr (ttok, '$') != 0);
7069 FREE (ttok);
7070 goto next_character;
d166f048 7071 }
726f6388 7072
3185942a
JA
7073#ifdef COND_REGEXP
7074 /* When parsing a regexp as a single word inside a conditional command,
7075 we need to special-case characters special to both the shell and
7076 regular expressions. Right now, that is only '(' and '|'. */ /*)*/
7077 if MBTEST((parser_state & PST_REGEXP) && (character == '(' || character == '|')) /*)*/
7078 {
7079 if (character == '|')
7080 goto got_character;
7081
7082 push_delimiter (dstack, character);
7083 ttok = parse_matched_pair (cd, '(', ')', &ttoklen, 0);
7084 pop_delimiter (dstack);
7085 if (ttok == &matched_pair_error)
7086 return -1; /* Bail immediately. */
7087 RESIZE_MALLOCED_BUFFER (token, token_index, ttoklen + 2,
7088 token_buffer_size, TOKEN_DEFAULT_GROW_SIZE);
7089 token[token_index++] = character;
7090 strcpy (token + token_index, ttok);
7091 token_index += ttoklen;
7092 FREE (ttok);
7093 dollar_present = all_digit_token = 0;
7094 goto next_character;
7095 }
7096#endif /* COND_REGEXP */
7097
28ef6c31
JA
7098#ifdef EXTENDED_GLOB
7099 /* Parse a ksh-style extended pattern matching specification. */
3185942a 7100 if MBTEST(extended_glob && PATTERN_CHAR (character))
cce855bc 7101 {
28ef6c31 7102 peek_char = shell_getc (1);
7117c2d2 7103 if MBTEST(peek_char == '(') /* ) */
28ef6c31
JA
7104 {
7105 push_delimiter (dstack, peek_char);
7106 ttok = parse_matched_pair (cd, '(', ')', &ttoklen, 0);
7107 pop_delimiter (dstack);
7108 if (ttok == &matched_pair_error)
7109 return -1; /* Bail immediately. */
ac50fbac 7110 RESIZE_MALLOCED_BUFFER (token, token_index, ttoklen + 3,
28ef6c31
JA
7111 token_buffer_size,
7112 TOKEN_DEFAULT_GROW_SIZE);
7113 token[token_index++] = character;
7114 token[token_index++] = peek_char;
7115 strcpy (token + token_index, ttok);
7116 token_index += ttoklen;
7117 FREE (ttok);
f73dda09 7118 dollar_present = all_digit_token = 0;
28ef6c31
JA
7119 goto next_character;
7120 }
7121 else
7122 shell_ungetc (peek_char);
7123 }
7124#endif /* EXTENDED_GLOB */
726f6388 7125
28ef6c31
JA
7126 /* If the delimiter character is not single quote, parse some of
7127 the shell expansions that must be read as a single word. */
7128 if (shellexp (character))
7129 {
7130 peek_char = shell_getc (1);
7131 /* $(...), <(...), >(...), $((...)), ${...}, and $[...] constructs */
ac50fbac 7132 if MBTEST(peek_char == '(' ||
28ef6c31
JA
7133 ((peek_char == '{' || peek_char == '[') && character == '$')) /* ) ] } */
7134 {
7135 if (peek_char == '{') /* } */
495aee44 7136 ttok = parse_matched_pair (cd, '{', '}', &ttoklen, P_FIRSTCLOSE|P_DOLBRACE);
28ef6c31
JA
7137 else if (peek_char == '(') /* ) */
7138 {
7139 /* XXX - push and pop the `(' as a delimiter for use by
7140 the command-oriented-history code. This way newlines
7141 appearing in the $(...) string get added to the
7142 history literally rather than causing a possibly-
7143 incorrect `;' to be added. ) */
7144 push_delimiter (dstack, peek_char);
3185942a 7145 ttok = parse_comsub (cd, '(', ')', &ttoklen, P_COMMAND);
28ef6c31
JA
7146 pop_delimiter (dstack);
7147 }
7148 else
7149 ttok = parse_matched_pair (cd, '[', ']', &ttoklen, 0);
7150 if (ttok == &matched_pair_error)
7151 return -1; /* Bail immediately. */
ac50fbac 7152 RESIZE_MALLOCED_BUFFER (token, token_index, ttoklen + 3,
28ef6c31
JA
7153 token_buffer_size,
7154 TOKEN_DEFAULT_GROW_SIZE);
7155 token[token_index++] = character;
7156 token[token_index++] = peek_char;
7157 strcpy (token + token_index, ttok);
7158 token_index += ttoklen;
7159 FREE (ttok);
7160 dollar_present = 1;
f73dda09 7161 all_digit_token = 0;
28ef6c31
JA
7162 goto next_character;
7163 }
7164 /* This handles $'...' and $"..." new-style quoted strings. */
7117c2d2 7165 else if MBTEST(character == '$' && (peek_char == '\'' || peek_char == '"'))
28ef6c31
JA
7166 {
7167 int first_line;
726f6388 7168
28ef6c31
JA
7169 first_line = line_number;
7170 push_delimiter (dstack, peek_char);
7171 ttok = parse_matched_pair (peek_char, peek_char, peek_char,
7172 &ttoklen,
7173 (peek_char == '\'') ? P_ALLOWESC : 0);
7174 pop_delimiter (dstack);
7175 if (ttok == &matched_pair_error)
7176 return -1;
7177 if (peek_char == '\'')
7178 {
7179 ttrans = ansiexpand (ttok, 0, ttoklen - 1, &ttranslen);
7180 free (ttok);
95732b49 7181
28ef6c31
JA
7182 /* Insert the single quotes and correctly quote any
7183 embedded single quotes (allowed because P_ALLOWESC was
7184 passed to parse_matched_pair). */
7185 ttok = sh_single_quote (ttrans);
7186 free (ttrans);
95732b49 7187 ttranslen = strlen (ttok);
28ef6c31 7188 ttrans = ttok;
28ef6c31
JA
7189 }
7190 else
7191 {
0628567a 7192 /* Try to locale-expand the converted string. */
28ef6c31
JA
7193 ttrans = localeexpand (ttok, 0, ttoklen - 1, first_line, &ttranslen);
7194 free (ttok);
726f6388 7195
28ef6c31 7196 /* Add the double quotes back */
95732b49 7197 ttok = sh_mkdoublequoted (ttrans, ttranslen, 0);
28ef6c31 7198 free (ttrans);
95732b49 7199 ttranslen += 2;
28ef6c31
JA
7200 ttrans = ttok;
7201 }
726f6388 7202
ac50fbac 7203 RESIZE_MALLOCED_BUFFER (token, token_index, ttranslen + 1,
f73dda09
JA
7204 token_buffer_size,
7205 TOKEN_DEFAULT_GROW_SIZE);
7206 strcpy (token + token_index, ttrans);
7207 token_index += ttranslen;
7208 FREE (ttrans);
7209 quoted = 1;
7210 all_digit_token = 0;
7211 goto next_character;
7212 }
7213 /* This could eventually be extended to recognize all of the
7214 shell's single-character parameter expansions, and set flags.*/
7117c2d2 7215 else if MBTEST(character == '$' && peek_char == '$')
f73dda09 7216 {
f73dda09
JA
7217 RESIZE_MALLOCED_BUFFER (token, token_index, 3,
7218 token_buffer_size,
7219 TOKEN_DEFAULT_GROW_SIZE);
ac50fbac
CR
7220 token[token_index++] = '$';
7221 token[token_index++] = peek_char;
f73dda09
JA
7222 dollar_present = 1;
7223 all_digit_token = 0;
f73dda09
JA
7224 goto next_character;
7225 }
7226 else
7227 shell_ungetc (peek_char);
7228 }
28ef6c31 7229
f73dda09 7230#if defined (ARRAY_VARS)
3185942a
JA
7231 /* Identify possible array subscript assignment; match [...]. If
7232 parser_state&PST_COMPASSIGN, we need to parse [sub]=words treating
7233 `sub' as if it were enclosed in double quotes. */
7234 else if MBTEST(character == '[' && /* ] */
7235 ((token_index > 0 && assignment_acceptable (last_read_token) && token_is_ident (token, token_index)) ||
7236 (token_index == 0 && (parser_state&PST_COMPASSIGN))))
7117c2d2 7237 {
0001803f 7238 ttok = parse_matched_pair (cd, '[', ']', &ttoklen, P_ARRAYSUB);
7117c2d2
JA
7239 if (ttok == &matched_pair_error)
7240 return -1; /* Bail immediately. */
7241 RESIZE_MALLOCED_BUFFER (token, token_index, ttoklen + 2,
7242 token_buffer_size,
7243 TOKEN_DEFAULT_GROW_SIZE);
7244 token[token_index++] = character;
7245 strcpy (token + token_index, ttok);
7246 token_index += ttoklen;
7247 FREE (ttok);
7248 all_digit_token = 0;
7249 goto next_character;
7250 }
f73dda09 7251 /* Identify possible compound array variable assignment. */
95732b49 7252 else if MBTEST(character == '=' && token_index > 0 && (assignment_acceptable (last_read_token) || (parser_state & PST_ASSIGNOK)) && token_is_assignment (token, token_index))
ccc6cda3 7253 {
f73dda09 7254 peek_char = shell_getc (1);
7117c2d2 7255 if MBTEST(peek_char == '(') /* ) */
f73dda09 7256 {
7117c2d2
JA
7257 ttok = parse_compound_assignment (&ttoklen);
7258
7259 RESIZE_MALLOCED_BUFFER (token, token_index, ttoklen + 4,
f73dda09
JA
7260 token_buffer_size,
7261 TOKEN_DEFAULT_GROW_SIZE);
7117c2d2
JA
7262
7263 token[token_index++] = '=';
7264 token[token_index++] = '(';
7265 if (ttok)
7266 {
7267 strcpy (token + token_index, ttok);
7268 token_index += ttoklen;
7269 }
7270 token[token_index++] = ')';
f73dda09
JA
7271 FREE (ttok);
7272 all_digit_token = 0;
95732b49 7273 compound_assignment = 1;
0628567a 7274#if 1
f73dda09 7275 goto next_character;
95732b49
JA
7276#else
7277 goto got_token; /* ksh93 seems to do this */
7278#endif
f73dda09
JA
7279 }
7280 else
7281 shell_ungetc (peek_char);
ccc6cda3 7282 }
f73dda09 7283#endif
726f6388 7284
f73dda09
JA
7285 /* When not parsing a multi-character word construct, shell meta-
7286 characters break words. */
7117c2d2 7287 if MBTEST(shellbreak (character))
f73dda09
JA
7288 {
7289 shell_ungetc (character);
7290 goto got_token;
7291 }
726f6388 7292
ac50fbac 7293got_character:
f73dda09 7294 if (character == CTLESC || character == CTLNUL)
ac50fbac
CR
7295 {
7296 RESIZE_MALLOCED_BUFFER (token, token_index, 2, token_buffer_size,
7297 TOKEN_DEFAULT_GROW_SIZE);
7298 token[token_index++] = CTLESC;
7299 }
7300 else
7301got_escaped_character:
7302 RESIZE_MALLOCED_BUFFER (token, token_index, 1, token_buffer_size,
7303 TOKEN_DEFAULT_GROW_SIZE);
d166f048 7304
ac50fbac 7305 token[token_index++] = character;
3185942a
JA
7306
7307 all_digit_token &= DIGIT (character);
7308 dollar_present |= character == '$';
7309
f73dda09 7310 next_character:
b80f6443 7311 if (character == '\n' && SHOULD_PROMPT ())
f73dda09 7312 prompt_again ();
cce855bc 7313
f73dda09
JA
7314 /* We want to remove quoted newlines (that is, a \<newline> pair)
7315 unless we are within single quotes or pass_next_character is
7316 set (the shell equivalent of literal-next). */
7317 cd = current_delimiter (dstack);
7318 character = shell_getc (cd != '\'' && pass_next_character == 0);
7319 } /* end for (;;) */
cce855bc 7320
f73dda09 7321got_token:
cce855bc 7322
ac50fbac 7323 /* Calls to RESIZE_MALLOCED_BUFFER ensure there is sufficient room. */
f73dda09 7324 token[token_index] = '\0';
28ef6c31 7325
f73dda09
JA
7326 /* Check to see what thing we should return. If the last_read_token
7327 is a `<', or a `&', or the character which ended this token is
7328 a '>' or '<', then, and ONLY then, is this input token a NUMBER.
7329 Otherwise, it is just a word, and should be returned as such. */
ac50fbac
CR
7330 if MBTEST(all_digit_token && (character == '<' || character == '>' ||
7331 last_read_token == LESS_AND ||
f73dda09
JA
7332 last_read_token == GREATER_AND))
7333 {
7334 if (legal_number (token, &lvalue) && (int)lvalue == lvalue)
ac50fbac
CR
7335 {
7336 yylval.number = lvalue;
7337 return (NUMBER);
7338 }
f73dda09 7339 }
cce855bc 7340
f73dda09 7341 /* Check for special case tokens. */
7117c2d2 7342 result = (last_shell_getc_is_singlebyte) ? special_case_tokens (token) : -1;
f73dda09
JA
7343 if (result >= 0)
7344 return result;
cce855bc 7345
f73dda09
JA
7346#if defined (ALIAS)
7347 /* Posix.2 does not allow reserved words to be aliased, so check for all
7348 of them, including special cases, before expanding the current token
7349 as an alias. */
7117c2d2 7350 if MBTEST(posixly_correct)
f73dda09 7351 CHECK_FOR_RESERVED_WORD (token);
cce855bc 7352
f73dda09
JA
7353 /* Aliases are expanded iff EXPAND_ALIASES is non-zero, and quoting
7354 inhibits alias expansion. */
7355 if (expand_aliases && quoted == 0)
cce855bc 7356 {
f73dda09
JA
7357 result = alias_expand_token (token);
7358 if (result == RE_READ_TOKEN)
7359 return (RE_READ_TOKEN);
7360 else if (result == NO_EXPANSION)
7361 parser_state &= ~PST_ALEXPNEXT;
cce855bc 7362 }
28ef6c31 7363
f73dda09
JA
7364 /* If not in Posix.2 mode, check for reserved words after alias
7365 expansion. */
7117c2d2 7366 if MBTEST(posixly_correct == 0)
f73dda09
JA
7367#endif
7368 CHECK_FOR_RESERVED_WORD (token);
7369
a0c0a00f 7370 the_word = alloc_word_desc ();
f73dda09
JA
7371 the_word->word = (char *)xmalloc (1 + token_index);
7372 the_word->flags = 0;
7373 strcpy (the_word->word, token);
7374 if (dollar_present)
7375 the_word->flags |= W_HASDOLLAR;
7376 if (quoted)
0628567a
JA
7377 the_word->flags |= W_QUOTED; /*(*/
7378 if (compound_assignment && token[token_index-1] == ')')
95732b49 7379 the_word->flags |= W_COMPASSIGN;
f73dda09
JA
7380 /* A word is an assignment if it appears at the beginning of a
7381 simple command, or after another assignment word. This is
7382 context-dependent, so it cannot be handled in the grammar. */
b80f6443 7383 if (assignment (token, (parser_state & PST_COMPASSIGN) != 0))
cce855bc 7384 {
f73dda09
JA
7385 the_word->flags |= W_ASSIGNMENT;
7386 /* Don't perform word splitting on assignment statements. */
b80f6443 7387 if (assignment_acceptable (last_read_token) || (parser_state & PST_COMPASSIGN) != 0)
ac50fbac
CR
7388 {
7389 the_word->flags |= W_NOSPLIT;
7390 if (parser_state & PST_COMPASSIGN)
7391 the_word->flags |= W_NOGLOB; /* XXX - W_NOBRACE? */
7392 }
cce855bc 7393 }
28ef6c31 7394
95732b49
JA
7395 if (command_token_position (last_read_token))
7396 {
7397 struct builtin *b;
7398 b = builtin_address_internal (token, 0);
7399 if (b && (b->flags & ASSIGNMENT_BUILTIN))
0628567a
JA
7400 parser_state |= PST_ASSIGNOK;
7401 else if (STREQ (token, "eval") || STREQ (token, "let"))
7402 parser_state |= PST_ASSIGNOK;
95732b49
JA
7403 }
7404
f73dda09
JA
7405 yylval.word = the_word;
7406
0001803f
CR
7407 if (token[0] == '{' && token[token_index-1] == '}' &&
7408 (character == '<' || character == '>'))
7409 {
7410 /* can use token; already copied to the_word */
7411 token[token_index-1] = '\0';
ac50fbac 7412#if defined (ARRAY_VARS)
a0c0a00f 7413 if (legal_identifier (token+1) || valid_array_reference (token+1, 0))
ac50fbac 7414#else
0001803f 7415 if (legal_identifier (token+1))
ac50fbac 7416#endif
0001803f
CR
7417 {
7418 strcpy (the_word->word, token+1);
7419/*itrace("read_token_word: returning REDIR_WORD for %s", the_word->word);*/
7420 return (REDIR_WORD);
7421 }
7422 }
7423
f73dda09
JA
7424 result = ((the_word->flags & (W_ASSIGNMENT|W_NOSPLIT)) == (W_ASSIGNMENT|W_NOSPLIT))
7425 ? ASSIGNMENT_WORD : WORD;
7426
b80f6443 7427 switch (last_read_token)
cce855bc 7428 {
b80f6443 7429 case FUNCTION:
f73dda09
JA
7430 parser_state |= PST_ALLOWOPNBRC;
7431 function_dstart = line_number;
b80f6443
JA
7432 break;
7433 case CASE:
7434 case SELECT:
7435 case FOR:
7436 if (word_top < MAX_CASE_NEST)
7437 word_top++;
7438 word_lineno[word_top] = line_number;
7439 break;
cce855bc 7440 }
cce855bc 7441
f73dda09 7442 return (result);
28ef6c31 7443}
cce855bc 7444
f73dda09
JA
7445/* Return 1 if TOKSYM is a token that after being read would allow
7446 a reserved word to be seen, else 0. */
7447static int
7448reserved_word_acceptable (toksym)
7449 int toksym;
7450{
7117c2d2
JA
7451 switch (toksym)
7452 {
7453 case '\n':
7454 case ';':
7455 case '(':
7456 case ')':
7457 case '|':
7458 case '&':
7459 case '{':
7460 case '}': /* XXX */
7461 case AND_AND:
7462 case BANG:
0001803f 7463 case BAR_AND:
7117c2d2
JA
7464 case DO:
7465 case DONE:
7466 case ELIF:
7467 case ELSE:
7468 case ESAC:
7469 case FI:
7470 case IF:
7471 case OR_OR:
7472 case SEMI_SEMI:
3185942a
JA
7473 case SEMI_AND:
7474 case SEMI_SEMI_AND:
7117c2d2
JA
7475 case THEN:
7476 case TIME:
7477 case TIMEOPT:
495aee44 7478 case TIMEIGN:
3185942a 7479 case COPROC:
7117c2d2
JA
7480 case UNTIL:
7481 case WHILE:
7482 case 0:
7483 return 1;
7484 default:
3185942a
JA
7485#if defined (COPROCESS_SUPPORT)
7486 if (last_read_token == WORD && token_before_that == COPROC)
7487 return 1;
7488#endif
495aee44
CR
7489 if (last_read_token == WORD && token_before_that == FUNCTION)
7490 return 1;
7117c2d2
JA
7491 return 0;
7492 }
f73dda09 7493}
7117c2d2 7494
f73dda09
JA
7495/* Return the index of TOKEN in the alist of reserved words, or -1 if
7496 TOKEN is not a shell reserved word. */
7497int
7498find_reserved_word (tokstr)
7499 char *tokstr;
7500{
7501 int i;
7502 for (i = 0; word_token_alist[i].word; i++)
7503 if (STREQ (tokstr, word_token_alist[i].word))
7504 return i;
7505 return -1;
7506}
ccc6cda3 7507
ac50fbac
CR
7508/* An interface to let the rest of the shell (primarily the completion
7509 system) know what the parser is expecting. */
7510int
7511parser_in_command_position ()
7512{
7513 return (command_token_position (last_read_token));
7514}
7515
f73dda09
JA
7516#if 0
7517#if defined (READLINE)
7518/* Called after each time readline is called. This insures that whatever
7519 the new prompt string is gets propagated to readline's local prompt
7520 variable. */
7521static void
7522reset_readline_prompt ()
7523{
7524 char *temp_prompt;
726f6388 7525
f73dda09
JA
7526 if (prompt_string_pointer)
7527 {
7528 temp_prompt = (*prompt_string_pointer)
7529 ? decode_prompt_string (*prompt_string_pointer)
7530 : (char *)NULL;
726f6388 7531
f73dda09
JA
7532 if (temp_prompt == 0)
7533 {
7534 temp_prompt = (char *)xmalloc (1);
7535 temp_prompt[0] = '\0';
7536 }
ccc6cda3 7537
f73dda09
JA
7538 FREE (current_readline_prompt);
7539 current_readline_prompt = temp_prompt;
7540 }
7541}
7542#endif /* READLINE */
7543#endif /* 0 */
726f6388 7544
f73dda09
JA
7545#if defined (HISTORY)
7546/* A list of tokens which can be followed by newlines, but not by
7547 semi-colons. When concatenating multiple lines of history, the
7548 newline separator for such tokens is replaced with a space. */
3185942a 7549static const int no_semi_successors[] = {
f73dda09 7550 '\n', '{', '(', ')', ';', '&', '|',
3185942a
JA
7551 CASE, DO, ELSE, IF, SEMI_SEMI, SEMI_AND, SEMI_SEMI_AND, THEN, UNTIL,
7552 WHILE, AND_AND, OR_OR, IN,
f73dda09
JA
7553 0
7554};
ccc6cda3 7555
f73dda09
JA
7556/* If we are not within a delimited expression, try to be smart
7557 about which separators can be semi-colons and which must be
7558 newlines. Returns the string that should be added into the
495aee44
CR
7559 history entry. LINE is the line we're about to add; it helps
7560 make some more intelligent decisions in certain cases. */
f73dda09 7561char *
495aee44
CR
7562history_delimiting_chars (line)
7563 const char *line;
f73dda09 7564{
495aee44 7565 static int last_was_heredoc = 0; /* was the last entry the start of a here document? */
f73dda09 7566 register int i;
726f6388 7567
495aee44
CR
7568 if ((parser_state & PST_HEREDOC) == 0)
7569 last_was_heredoc = 0;
7570
f73dda09
JA
7571 if (dstack.delimiter_depth != 0)
7572 return ("\n");
3185942a
JA
7573
7574 /* We look for current_command_line_count == 2 because we are looking to
7575 add the first line of the body of the here document (the second line
495aee44
CR
7576 of the command). We also keep LAST_WAS_HEREDOC as a private sentinel
7577 variable to note when we think we added the first line of a here doc
7578 (the one with a "<<" somewhere in it) */
3185942a 7579 if (parser_state & PST_HEREDOC)
495aee44
CR
7580 {
7581 if (last_was_heredoc)
7582 {
7583 last_was_heredoc = 0;
7584 return "\n";
7585 }
a0c0a00f 7586 return (here_doc_first_line ? "\n" : "");
495aee44 7587 }
3185942a 7588
509a4430
CR
7589 if (parser_state & PST_COMPASSIGN)
7590 return (" ");
7591
f73dda09
JA
7592 /* First, handle some special cases. */
7593 /*(*/
7594 /* If we just read `()', assume it's a function definition, and don't
7595 add a semicolon. If the token before the `)' was not `(', and we're
7596 not in the midst of parsing a case statement, assume it's a
7597 parenthesized command and add the semicolon. */
7598 /*)(*/
7599 if (token_before_that == ')')
7600 {
7601 if (two_tokens_ago == '(') /*)*/ /* function def */
7602 return " ";
7603 /* This does not work for subshells inside case statement
7604 command lists. It's a suboptimal solution. */
7605 else if (parser_state & PST_CASESTMT) /* case statement pattern */
7606 return " ";
a0c0a00f 7607 else
f73dda09
JA
7608 return "; "; /* (...) subshell */
7609 }
7610 else if (token_before_that == WORD && two_tokens_ago == FUNCTION)
7611 return " "; /* function def using `function name' without `()' */
726f6388 7612
495aee44
CR
7613 /* If we're not in a here document, but we think we're about to parse one,
7614 and we would otherwise return a `;', return a newline to delimit the
7615 line with the here-doc delimiter */
7616 else if ((parser_state & PST_HEREDOC) == 0 && current_command_line_count > 1 && last_read_token == '\n' && strstr (line, "<<"))
7617 {
7618 last_was_heredoc = 1;
7619 return "\n";
7620 }
a0c0a00f
CR
7621 else if ((parser_state & PST_HEREDOC) == 0 && current_command_line_count > 1 && need_here_doc > 0)
7622 return "\n";
f73dda09
JA
7623 else if (token_before_that == WORD && two_tokens_ago == FOR)
7624 {
7625 /* Tricky. `for i\nin ...' should not have a semicolon, but
7626 `for i\ndo ...' should. We do what we can. */
3185942a 7627 for (i = shell_input_line_index; whitespace (shell_input_line[i]); i++)
f73dda09
JA
7628 ;
7629 if (shell_input_line[i] && shell_input_line[i] == 'i' && shell_input_line[i+1] == 'n')
7630 return " ";
7631 return ";";
7632 }
95732b49
JA
7633 else if (two_tokens_ago == CASE && token_before_that == WORD && (parser_state & PST_CASESTMT))
7634 return " ";
726f6388 7635
f73dda09
JA
7636 for (i = 0; no_semi_successors[i]; i++)
7637 {
7638 if (token_before_that == no_semi_successors[i])
7639 return (" ");
7640 }
726f6388 7641
f73dda09
JA
7642 return ("; ");
7643}
7644#endif /* HISTORY */
ccc6cda3 7645
f73dda09
JA
7646/* Issue a prompt, or prepare to issue a prompt when the next character
7647 is read. */
7648static void
7649prompt_again ()
7650{
7651 char *temp_prompt;
726f6388 7652
0001803f 7653 if (interactive == 0 || expanding_alias ()) /* XXX */
f73dda09 7654 return;
726f6388 7655
f73dda09
JA
7656 ps1_prompt = get_string_value ("PS1");
7657 ps2_prompt = get_string_value ("PS2");
28ef6c31 7658
a0c0a00f
CR
7659 ps0_prompt = get_string_value ("PS0");
7660
f73dda09
JA
7661 if (!prompt_string_pointer)
7662 prompt_string_pointer = &ps1_prompt;
28ef6c31 7663
f73dda09
JA
7664 temp_prompt = *prompt_string_pointer
7665 ? decode_prompt_string (*prompt_string_pointer)
7666 : (char *)NULL;
28ef6c31 7667
f73dda09
JA
7668 if (temp_prompt == 0)
7669 {
7670 temp_prompt = (char *)xmalloc (1);
7671 temp_prompt[0] = '\0';
28ef6c31 7672 }
28ef6c31 7673
f73dda09
JA
7674 current_prompt_string = *prompt_string_pointer;
7675 prompt_string_pointer = &ps2_prompt;
28ef6c31 7676
f73dda09
JA
7677#if defined (READLINE)
7678 if (!no_line_editing)
ccc6cda3 7679 {
f73dda09
JA
7680 FREE (current_readline_prompt);
7681 current_readline_prompt = temp_prompt;
ccc6cda3
JA
7682 }
7683 else
f73dda09 7684#endif /* READLINE */
ccc6cda3 7685 {
f73dda09
JA
7686 FREE (current_decoded_prompt);
7687 current_decoded_prompt = temp_prompt;
ccc6cda3
JA
7688 }
7689}
726f6388 7690
28ef6c31 7691int
f73dda09 7692get_current_prompt_level ()
bb70624e 7693{
f73dda09 7694 return ((current_prompt_string && current_prompt_string == ps2_prompt) ? 2 : 1);
28ef6c31 7695}
bb70624e 7696
f73dda09
JA
7697void
7698set_current_prompt_level (x)
7699 int x;
7700{
7701 prompt_string_pointer = (x == 2) ? &ps2_prompt : &ps1_prompt;
7702 current_prompt_string = *prompt_string_pointer;
7703}
7704
28ef6c31 7705static void
f73dda09 7706print_prompt ()
28ef6c31 7707{
f73dda09
JA
7708 fprintf (stderr, "%s", current_decoded_prompt);
7709 fflush (stderr);
7710}
bb70624e 7711
f73dda09
JA
7712/* Return a string which will be printed as a prompt. The string
7713 may contain special characters which are decoded as follows:
726f6388 7714
f73dda09 7715 \a bell (ascii 07)
f73dda09 7716 \d the date in Day Mon Date format
7117c2d2 7717 \e escape (ascii 033)
f73dda09
JA
7718 \h the hostname up to the first `.'
7719 \H the hostname
7720 \j the number of active jobs
7721 \l the basename of the shell's tty device name
7722 \n CRLF
7117c2d2 7723 \r CR
f73dda09
JA
7724 \s the name of the shell
7725 \t the time in 24-hour hh:mm:ss format
7726 \T the time in 12-hour hh:mm:ss format
7117c2d2
JA
7727 \@ the time in 12-hour hh:mm am/pm format
7728 \A the time in 24-hour hh:mm format
7729 \D{fmt} the result of passing FMT to strftime(3)
7730 \u your username
f73dda09
JA
7731 \v the version of bash (e.g., 2.00)
7732 \V the release of bash, version + patchlevel (e.g., 2.00.0)
7733 \w the current working directory
7734 \W the last element of $PWD
f73dda09 7735 \! the history number of this command
7117c2d2 7736 \# the command number of this command
f73dda09
JA
7737 \$ a $ or a # if you are root
7738 \nnn character code nnn in octal
7739 \\ a backslash
7740 \[ begin a sequence of non-printing chars
7741 \] end a sequence of non-printing chars
7742*/
7743#define PROMPT_GROWTH 48
7744char *
7745decode_prompt_string (string)
7746 char *string;
7747{
7748 WORD_LIST *list;
7749 char *result, *t;
7750 struct dstack save_dstack;
0001803f 7751 int last_exit_value, last_comsub_pid;
f73dda09 7752#if defined (PROMPT_STRING_DECODE)
a0c0a00f
CR
7753 size_t result_size;
7754 int result_index;
0628567a 7755 int c, n, i;
a0c0a00f 7756 char *temp, *t_host, octal_string[4];
7117c2d2 7757 struct tm *tm;
f73dda09 7758 time_t the_time;
7117c2d2
JA
7759 char timebuf[128];
7760 char *timefmt;
726f6388 7761
f73dda09
JA
7762 result = (char *)xmalloc (result_size = PROMPT_GROWTH);
7763 result[result_index = 0] = 0;
7764 temp = (char *)NULL;
28ef6c31 7765
f73dda09
JA
7766 while (c = *string++)
7767 {
7768 if (posixly_correct && c == '!')
bb70624e 7769 {
f73dda09 7770 if (*string == '!')
28ef6c31 7771 {
f73dda09
JA
7772 temp = savestring ("!");
7773 goto add_string;
7774 }
7775 else
7776 {
7777#if !defined (HISTORY)
7778 temp = savestring ("1");
7779#else /* HISTORY */
7780 temp = itos (history_number ());
7781#endif /* HISTORY */
7782 string--; /* add_string increments string again. */
7783 goto add_string;
28ef6c31 7784 }
28ef6c31 7785 }
f73dda09
JA
7786 if (c == '\\')
7787 {
7788 c = *string;
726f6388 7789
f73dda09
JA
7790 switch (c)
7791 {
7792 case '0':
7793 case '1':
7794 case '2':
7795 case '3':
7796 case '4':
7797 case '5':
7798 case '6':
7799 case '7':
7800 strncpy (octal_string, string, 3);
7801 octal_string[3] = '\0';
726f6388 7802
f73dda09
JA
7803 n = read_octal (octal_string);
7804 temp = (char *)xmalloc (3);
726f6388 7805
f73dda09
JA
7806 if (n == CTLESC || n == CTLNUL)
7807 {
7808 temp[0] = CTLESC;
7809 temp[1] = n;
7810 temp[2] = '\0';
7811 }
7812 else if (n == -1)
7813 {
7814 temp[0] = '\\';
7815 temp[1] = '\0';
7816 }
7817 else
7818 {
7819 temp[0] = n;
7820 temp[1] = '\0';
7821 }
28ef6c31 7822
f73dda09
JA
7823 for (c = 0; n != -1 && c < 3 && ISOCTAL (*string); c++)
7824 string++;
28ef6c31 7825
7117c2d2 7826 c = 0; /* tested at add_string: */
f73dda09 7827 goto add_string;
28ef6c31 7828
f73dda09 7829 case 'd':
7117c2d2 7830 case 't':
f73dda09
JA
7831 case 'T':
7832 case '@':
7833 case 'A':
7834 /* Make the current time/date into a string. */
7117c2d2 7835 (void) time (&the_time);
509a4430
CR
7836#if defined (HAVE_TZSET)
7837 sv_tz ("TZ"); /* XXX -- just make sure */
7838#endif
7117c2d2
JA
7839 tm = localtime (&the_time);
7840
7841 if (c == 'd')
7842 n = strftime (timebuf, sizeof (timebuf), "%a %b %d", tm);
7843 else if (c == 't')
7844 n = strftime (timebuf, sizeof (timebuf), "%H:%M:%S", tm);
7845 else if (c == 'T')
7846 n = strftime (timebuf, sizeof (timebuf), "%I:%M:%S", tm);
7847 else if (c == '@')
7848 n = strftime (timebuf, sizeof (timebuf), "%I:%M %p", tm);
7849 else if (c == 'A')
7850 n = strftime (timebuf, sizeof (timebuf), "%H:%M", tm);
7851
b80f6443
JA
7852 if (n == 0)
7853 timebuf[0] = '\0';
7854 else
7855 timebuf[sizeof(timebuf) - 1] = '\0';
7856
7117c2d2
JA
7857 temp = savestring (timebuf);
7858 goto add_string;
726f6388 7859
7117c2d2
JA
7860 case 'D': /* strftime format */
7861 if (string[1] != '{') /* } */
7862 goto not_escape;
726f6388 7863
7117c2d2
JA
7864 (void) time (&the_time);
7865 tm = localtime (&the_time);
7866 string += 2; /* skip { */
7867 timefmt = xmalloc (strlen (string) + 3);
7868 for (t = timefmt; *string && *string != '}'; )
7869 *t++ = *string++;
7870 *t = '\0';
7871 c = *string; /* tested at add_string */
7872 if (timefmt[0] == '\0')
f73dda09 7873 {
7117c2d2
JA
7874 timefmt[0] = '%';
7875 timefmt[1] = 'X'; /* locale-specific current time */
7876 timefmt[2] = '\0';
f73dda09 7877 }
7117c2d2
JA
7878 n = strftime (timebuf, sizeof (timebuf), timefmt, tm);
7879 free (timefmt);
7880
b80f6443
JA
7881 if (n == 0)
7882 timebuf[0] = '\0';
7883 else
7884 timebuf[sizeof(timebuf) - 1] = '\0';
7885
7117c2d2
JA
7886 if (promptvars || posixly_correct)
7887 /* Make sure that expand_prompt_string is called with a
7888 second argument of Q_DOUBLE_QUOTES if we use this
7889 function here. */
7890 temp = sh_backslash_quote_for_double_quotes (timebuf);
7891 else
7892 temp = savestring (timebuf);
f73dda09 7893 goto add_string;
7117c2d2 7894
f73dda09
JA
7895 case 'n':
7896 temp = (char *)xmalloc (3);
7897 temp[0] = no_line_editing ? '\n' : '\r';
7898 temp[1] = no_line_editing ? '\0' : '\n';
7899 temp[2] = '\0';
7900 goto add_string;
ccc6cda3 7901
f73dda09
JA
7902 case 's':
7903 temp = base_pathname (shell_name);
a0c0a00f
CR
7904 /* Try to quote anything the user can set in the file system */
7905 if (promptvars || posixly_correct)
7906 temp = sh_backslash_quote_for_double_quotes (temp);
7907 else
7908 temp = savestring (temp);
f73dda09 7909 goto add_string;
726f6388 7910
f73dda09
JA
7911 case 'v':
7912 case 'V':
7117c2d2 7913 temp = (char *)xmalloc (16);
f73dda09
JA
7914 if (c == 'v')
7915 strcpy (temp, dist_version);
7916 else
7917 sprintf (temp, "%s.%d", dist_version, patch_level);
7918 goto add_string;
bb70624e 7919
f73dda09
JA
7920 case 'w':
7921 case 'W':
7922 {
7923 /* Use the value of PWD because it is much more efficient. */
0628567a 7924 char t_string[PATH_MAX];
f73dda09 7925 int tlen;
28ef6c31 7926
f73dda09 7927 temp = get_string_value ("PWD");
ccc6cda3 7928
f73dda09
JA
7929 if (temp == 0)
7930 {
7931 if (getcwd (t_string, sizeof(t_string)) == 0)
7932 {
7933 t_string[0] = '.';
7934 tlen = 1;
7935 }
7936 else
7937 tlen = strlen (t_string);
7938 }
7939 else
7940 {
7941 tlen = sizeof (t_string) - 1;
7942 strncpy (t_string, temp, tlen);
7943 }
7944 t_string[tlen] = '\0';
726f6388 7945
0001803f
CR
7946#if defined (MACOSX)
7947 /* Convert from "fs" format to "input" format */
7948 temp = fnx_fromfs (t_string, strlen (t_string));
7949 if (temp != t_string)
7950 strcpy (t_string, temp);
7951#endif
7952
f73dda09
JA
7953#define ROOT_PATH(x) ((x)[0] == '/' && (x)[1] == 0)
7954#define DOUBLE_SLASH_ROOT(x) ((x)[0] == '/' && (x)[1] == '/' && (x)[2] == 0)
b80f6443 7955 /* Abbreviate \W as ~ if $PWD == $HOME */
95732b49 7956 if (c == 'W' && (((t = get_string_value ("HOME")) == 0) || STREQ (t, t_string) == 0))
f73dda09
JA
7957 {
7958 if (ROOT_PATH (t_string) == 0 && DOUBLE_SLASH_ROOT (t_string) == 0)
7959 {
7960 t = strrchr (t_string, '/');
7961 if (t)
495aee44 7962 memmove (t_string, t + 1, strlen (t)); /* strlen(t) to copy NULL */
f73dda09
JA
7963 }
7964 }
7965#undef ROOT_PATH
7966#undef DOUBLE_SLASH_ROOT
7967 else
ac50fbac
CR
7968 {
7969 /* polite_directory_format is guaranteed to return a string
7970 no longer than PATH_MAX - 1 characters. */
7971 temp = polite_directory_format (t_string);
7972 if (temp != t_string)
7973 strcpy (t_string, temp);
7974 }
726f6388 7975
3185942a 7976 temp = trim_pathname (t_string, PATH_MAX - 1);
f73dda09
JA
7977 /* If we're going to be expanding the prompt string later,
7978 quote the directory name. */
7979 if (promptvars || posixly_correct)
7980 /* Make sure that expand_prompt_string is called with a
7117c2d2 7981 second argument of Q_DOUBLE_QUOTES if we use this
f73dda09
JA
7982 function here. */
7983 temp = sh_backslash_quote_for_double_quotes (t_string);
7984 else
7985 temp = savestring (t_string);
726f6388 7986
f73dda09
JA
7987 goto add_string;
7988 }
726f6388 7989
f73dda09
JA
7990 case 'u':
7991 if (current_user.user_name == 0)
7992 get_current_user_info ();
7993 temp = savestring (current_user.user_name);
7994 goto add_string;
726f6388 7995
f73dda09
JA
7996 case 'h':
7997 case 'H':
a0c0a00f
CR
7998 t_host = savestring (current_host_name);
7999 if (c == 'h' && (t = (char *)strchr (t_host, '.')))
f73dda09 8000 *t = '\0';
a0c0a00f
CR
8001 if (promptvars || posixly_correct)
8002 /* Make sure that expand_prompt_string is called with a
8003 second argument of Q_DOUBLE_QUOTES if we use this
8004 function here. */
8005 temp = sh_backslash_quote_for_double_quotes (t_host);
8006 else
8007 temp = savestring (t_host);
8008 free (t_host);
f73dda09 8009 goto add_string;
726f6388 8010
f73dda09
JA
8011 case '#':
8012 temp = itos (current_command_number);
8013 goto add_string;
28ef6c31 8014
f73dda09
JA
8015 case '!':
8016#if !defined (HISTORY)
8017 temp = savestring ("1");
8018#else /* HISTORY */
8019 temp = itos (history_number ());
8020#endif /* HISTORY */
8021 goto add_string;
726f6388 8022
f73dda09
JA
8023 case '$':
8024 t = temp = (char *)xmalloc (3);
8025 if ((promptvars || posixly_correct) && (current_user.euid != 0))
8026 *t++ = '\\';
8027 *t++ = current_user.euid == 0 ? '#' : '$';
8028 *t = '\0';
8029 goto add_string;
726f6388 8030
f73dda09
JA
8031 case 'j':
8032 temp = itos (count_all_jobs ());
8033 goto add_string;
28ef6c31 8034
f73dda09
JA
8035 case 'l':
8036#if defined (HAVE_TTYNAME)
8037 temp = (char *)ttyname (fileno (stdin));
8038 t = temp ? base_pathname (temp) : "tty";
8039 temp = savestring (t);
8040#else
8041 temp = savestring ("tty");
8042#endif /* !HAVE_TTYNAME */
8043 goto add_string;
726f6388 8044
f73dda09
JA
8045#if defined (READLINE)
8046 case '[':
8047 case ']':
b80f6443
JA
8048 if (no_line_editing)
8049 {
8050 string++;
8051 break;
8052 }
f73dda09 8053 temp = (char *)xmalloc (3);
0628567a
JA
8054 n = (c == '[') ? RL_PROMPT_START_IGNORE : RL_PROMPT_END_IGNORE;
8055 i = 0;
8056 if (n == CTLESC || n == CTLNUL)
8057 temp[i++] = CTLESC;
8058 temp[i++] = n;
8059 temp[i] = '\0';
f73dda09
JA
8060 goto add_string;
8061#endif /* READLINE */
ccc6cda3 8062
f73dda09 8063 case '\\':
f73dda09
JA
8064 case 'a':
8065 case 'e':
7117c2d2 8066 case 'r':
f73dda09 8067 temp = (char *)xmalloc (2);
7117c2d2
JA
8068 if (c == 'a')
8069 temp[0] = '\07';
8070 else if (c == 'e')
8071 temp[0] = '\033';
8072 else if (c == 'r')
8073 temp[0] = '\r';
8074 else /* (c == '\\') */
8075 temp[0] = c;
f73dda09
JA
8076 temp[1] = '\0';
8077 goto add_string;
8078
8079 default:
7117c2d2 8080not_escape:
f73dda09
JA
8081 temp = (char *)xmalloc (3);
8082 temp[0] = '\\';
8083 temp[1] = c;
8084 temp[2] = '\0';
8085
8086 add_string:
8087 if (c)
8088 string++;
8089 result =
8090 sub_append_string (temp, result, &result_index, &result_size);
8091 temp = (char *)NULL; /* Freed in sub_append_string (). */
8092 result[result_index] = '\0';
8093 break;
8094 }
8095 }
8096 else
8097 {
8098 RESIZE_MALLOCED_BUFFER (result, result_index, 3, result_size, PROMPT_GROWTH);
a0c0a00f
CR
8099 /* dequote_string should take care of removing this if we are not
8100 performing the rest of the word expansions. */
8101 if (c == CTLESC || c == CTLNUL)
8102 result[result_index++] = CTLESC;
f73dda09
JA
8103 result[result_index++] = c;
8104 result[result_index] = '\0';
8105 }
8106 }
8107#else /* !PROMPT_STRING_DECODE */
8108 result = savestring (string);
8109#endif /* !PROMPT_STRING_DECODE */
8110
8111 /* Save the delimiter stack and point `dstack' to temp space so any
8112 command substitutions in the prompt string won't result in screwing
8113 up the parser's quoting state. */
8114 save_dstack = dstack;
8115 dstack = temp_dstack;
8116 dstack.delimiter_depth = 0;
8117
8118 /* Perform variable and parameter expansion and command substitution on
8119 the prompt string. */
8120 if (promptvars || posixly_correct)
8121 {
8122 last_exit_value = last_command_exit_value;
0001803f 8123 last_comsub_pid = last_command_subst_pid;
3185942a 8124 list = expand_prompt_string (result, Q_DOUBLE_QUOTES, 0);
f73dda09
JA
8125 free (result);
8126 result = string_list (list);
8127 dispose_words (list);
8128 last_command_exit_value = last_exit_value;
0001803f 8129 last_command_subst_pid = last_comsub_pid;
f73dda09
JA
8130 }
8131 else
8132 {
8133 t = dequote_string (result);
8134 free (result);
8135 result = t;
8136 }
8137
8138 dstack = save_dstack;
8139
8140 return (result);
8141}
8142
7117c2d2
JA
8143/************************************************
8144 * *
8145 * ERROR HANDLING *
8146 * *
8147 ************************************************/
8148
f73dda09
JA
8149/* Report a syntax error, and restart the parser. Call here for fatal
8150 errors. */
8151int
8152yyerror (msg)
8153 const char *msg;
726f6388 8154{
f73dda09
JA
8155 report_syntax_error ((char *)NULL);
8156 reset_parser ();
8157 return (0);
8158}
8159
7117c2d2 8160static char *
0628567a
JA
8161error_token_from_token (tok)
8162 int tok;
7117c2d2
JA
8163{
8164 char *t;
8165
0628567a 8166 if (t = find_token_in_alist (tok, word_token_alist, 0))
7117c2d2
JA
8167 return t;
8168
0628567a 8169 if (t = find_token_in_alist (tok, other_token_alist, 0))
7117c2d2
JA
8170 return t;
8171
8172 t = (char *)NULL;
8173 /* This stuff is dicy and needs closer inspection */
8174 switch (current_token)
8175 {
8176 case WORD:
8177 case ASSIGNMENT_WORD:
8178 if (yylval.word)
8179 t = savestring (yylval.word->word);
8180 break;
8181 case NUMBER:
8182 t = itos (yylval.number);
8183 break;
8184 case ARITH_CMD:
8185 if (yylval.word_list)
8186 t = string_list (yylval.word_list);
8187 break;
8188 case ARITH_FOR_EXPRS:
8189 if (yylval.word_list)
8190 t = string_list_internal (yylval.word_list, " ; ");
8191 break;
8192 case COND_CMD:
8193 t = (char *)NULL; /* punt */
8194 break;
8195 }
8196
8197 return t;
8198}
8199
8200static char *
8201error_token_from_text ()
8202{
8203 char *msg, *t;
8204 int token_end, i;
8205
8206 t = shell_input_line;
8207 i = shell_input_line_index;
8208 token_end = 0;
8209 msg = (char *)NULL;
8210
8211 if (i && t[i] == '\0')
8212 i--;
8213
8214 while (i && (whitespace (t[i]) || t[i] == '\n'))
8215 i--;
8216
8217 if (i)
8218 token_end = i + 1;
8219
8220 while (i && (member (t[i], " \n\t;|&") == 0))
8221 i--;
8222
8223 while (i != token_end && (whitespace (t[i]) || t[i] == '\n'))
8224 i++;
8225
8226 /* Return our idea of the offending token. */
8227 if (token_end || (i == 0 && token_end == 0))
8228 {
8229 if (token_end)
8230 msg = substring (t, i, token_end);
8231 else /* one-character token */
8232 {
8233 msg = (char *)xmalloc (2);
8234 msg[0] = t[i];
8235 msg[1] = '\0';
8236 }
8237 }
8238
8239 return (msg);
8240}
8241
8242static void
8243print_offending_line ()
8244{
8245 char *msg;
8246 int token_end;
8247
8248 msg = savestring (shell_input_line);
8249 token_end = strlen (msg);
8250 while (token_end && msg[token_end - 1] == '\n')
8251 msg[--token_end] = '\0';
8252
8253 parser_error (line_number, "`%s'", msg);
8254 free (msg);
8255}
8256
f73dda09
JA
8257/* Report a syntax error with line numbers, etc.
8258 Call here for recoverable errors. If you have a message to print,
8259 then place it in MESSAGE, otherwise pass NULL and this will figure
8260 out an appropriate message for you. */
8261static void
8262report_syntax_error (message)
8263 char *message;
726f6388 8264{
495aee44 8265 char *msg, *p;
f73dda09
JA
8266
8267 if (message)
8268 {
8269 parser_error (line_number, "%s", message);
8270 if (interactive && EOF_Reached)
8271 EOF_Reached = 0;
0001803f 8272 last_command_exit_value = parse_and_execute_level ? EX_BADSYNTAX : EX_BADUSAGE;
f73dda09
JA
8273 return;
8274 }
8275
8276 /* If the line of input we're reading is not null, try to find the
7117c2d2
JA
8277 objectionable token. First, try to figure out what token the
8278 parser's complaining about by looking at current_token. */
8279 if (current_token != 0 && EOF_Reached == 0 && (msg = error_token_from_token (current_token)))
f73dda09 8280 {
495aee44
CR
8281 if (ansic_shouldquote (msg))
8282 {
8283 p = ansic_quote (msg, 0, NULL);
8284 free (msg);
8285 msg = p;
8286 }
b80f6443 8287 parser_error (line_number, _("syntax error near unexpected token `%s'"), msg);
7117c2d2 8288 free (msg);
f73dda09 8289
7117c2d2
JA
8290 if (interactive == 0)
8291 print_offending_line ();
f73dda09 8292
0001803f 8293 last_command_exit_value = parse_and_execute_level ? EX_BADSYNTAX : EX_BADUSAGE;
7117c2d2
JA
8294 return;
8295 }
f73dda09 8296
7117c2d2
JA
8297 /* If looking at the current token doesn't prove fruitful, try to find the
8298 offending token by analyzing the text of the input line near the current
8299 input line index and report what we find. */
8300 if (shell_input_line && *shell_input_line)
8301 {
8302 msg = error_token_from_text ();
8303 if (msg)
f73dda09 8304 {
b80f6443 8305 parser_error (line_number, _("syntax error near `%s'"), msg);
7117c2d2 8306 free (msg);
f73dda09
JA
8307 }
8308
8309 /* If not interactive, print the line containing the error. */
8310 if (interactive == 0)
7117c2d2 8311 print_offending_line ();
f73dda09
JA
8312 }
8313 else
8314 {
b80f6443 8315 msg = EOF_Reached ? _("syntax error: unexpected end of file") : _("syntax error");
f73dda09
JA
8316 parser_error (line_number, "%s", msg);
8317 /* When the shell is interactive, this file uses EOF_Reached
8318 only for error reporting. Other mechanisms are used to
8319 decide whether or not to exit. */
8320 if (interactive && EOF_Reached)
8321 EOF_Reached = 0;
8322 }
7117c2d2 8323
0001803f 8324 last_command_exit_value = parse_and_execute_level ? EX_BADSYNTAX : EX_BADUSAGE;
f73dda09
JA
8325}
8326
8327/* ??? Needed function. ??? We have to be able to discard the constructs
8328 created during parsing. In the case of error, we want to return
8329 allocated objects to the memory pool. In the case of no error, we want
8330 to throw away the information about where the allocated objects live.
7117c2d2 8331 (dispose_command () will actually free the command.) */
f73dda09
JA
8332static void
8333discard_parser_constructs (error_p)
8334 int error_p;
28ef6c31 8335{
f73dda09
JA
8336}
8337
7117c2d2
JA
8338/************************************************
8339 * *
8340 * EOF HANDLING *
8341 * *
8342 ************************************************/
8343
f73dda09
JA
8344/* Do that silly `type "bye" to exit' stuff. You know, "ignoreeof". */
8345
8346/* A flag denoting whether or not ignoreeof is set. */
8347int ignoreeof = 0;
8348
8349/* The number of times that we have encountered an EOF character without
8350 another character intervening. When this gets above the limit, the
8351 shell terminates. */
8352int eof_encountered = 0;
8353
8354/* The limit for eof_encountered. */
8355int eof_encountered_limit = 10;
8356
8357/* If we have EOF as the only input unit, this user wants to leave
8358 the shell. If the shell is not interactive, then just leave.
8359 Otherwise, if ignoreeof is set, and we haven't done this the
8360 required number of times in a row, print a message. */
8361static void
8362handle_eof_input_unit ()
28ef6c31 8363{
f73dda09
JA
8364 if (interactive)
8365 {
8366 /* shell.c may use this to decide whether or not to write out the
8367 history, among other things. We use it only for error reporting
8368 in this file. */
8369 if (EOF_Reached)
8370 EOF_Reached = 0;
8371
8372 /* If the user wants to "ignore" eof, then let her do so, kind of. */
8373 if (ignoreeof)
8374 {
8375 if (eof_encountered < eof_encountered_limit)
8376 {
b80f6443 8377 fprintf (stderr, _("Use \"%s\" to leave the shell.\n"),
f73dda09
JA
8378 login_shell ? "logout" : "exit");
8379 eof_encountered++;
7117c2d2
JA
8380 /* Reset the parsing state. */
8381 last_read_token = current_token = '\n';
f73dda09
JA
8382 /* Reset the prompt string to be $PS1. */
8383 prompt_string_pointer = (char **)NULL;
8384 prompt_again ();
f73dda09
JA
8385 return;
8386 }
8387 }
8388
8389 /* In this case EOF should exit the shell. Do it now. */
8390 reset_parser ();
8391 exit_builtin ((WORD_LIST *)NULL);
726f6388 8392 }
f73dda09 8393 else
726f6388 8394 {
f73dda09
JA
8395 /* We don't write history files, etc., for non-interactive shells. */
8396 EOF_Reached = 1;
8397 }
8398}
8399
7117c2d2
JA
8400/************************************************
8401 * *
8402 * STRING PARSING FUNCTIONS *
8403 * *
8404 ************************************************/
8405
8406/* It's very important that these two functions treat the characters
8407 between ( and ) identically. */
8408
f73dda09
JA
8409static WORD_LIST parse_string_error;
8410
8411/* Take a string and run it through the shell parser, returning the
8412 resultant word list. Used by compound array assignment. */
8413WORD_LIST *
b80f6443 8414parse_string_to_word_list (s, flags, whom)
f73dda09 8415 char *s;
b80f6443 8416 int flags;
f73dda09
JA
8417 const char *whom;
8418{
8419 WORD_LIST *wl;
7117c2d2 8420 int tok, orig_current_token, orig_line_number, orig_input_terminator;
f73dda09 8421 int orig_line_count;
7117c2d2 8422 int old_echo_input, old_expand_aliases;
f73dda09
JA
8423#if defined (HISTORY)
8424 int old_remember_on_history, old_history_expansion_inhibited;
bb70624e 8425#endif
f73dda09
JA
8426
8427#if defined (HISTORY)
8428 old_remember_on_history = remember_on_history;
8429# if defined (BANG_HISTORY)
8430 old_history_expansion_inhibited = history_expansion_inhibited;
8431# endif
8432 bash_history_disable ();
bb70624e 8433#endif
f73dda09
JA
8434
8435 orig_line_number = line_number;
8436 orig_line_count = current_command_line_count;
8437 orig_input_terminator = shell_input_line_terminator;
7117c2d2
JA
8438 old_echo_input = echo_input_at_read;
8439 old_expand_aliases = expand_aliases;
f73dda09
JA
8440
8441 push_stream (1);
7117c2d2 8442 last_read_token = WORD; /* WORD to allow reserved words here */
f73dda09 8443 current_command_line_count = 0;
7117c2d2 8444 echo_input_at_read = expand_aliases = 0;
f73dda09
JA
8445
8446 with_input_from_string (s, whom);
8447 wl = (WORD_LIST *)NULL;
b80f6443
JA
8448
8449 if (flags & 1)
3185942a 8450 parser_state |= PST_COMPASSIGN|PST_REPARSE;
b80f6443 8451
f73dda09
JA
8452 while ((tok = read_token (READ)) != yacc_EOF)
8453 {
8454 if (tok == '\n' && *bash_input.location.string == '\0')
8455 break;
8456 if (tok == '\n') /* Allow newlines in compound assignments */
8457 continue;
8458 if (tok != WORD && tok != ASSIGNMENT_WORD)
8459 {
8460 line_number = orig_line_number + line_number - 1;
7117c2d2
JA
8461 orig_current_token = current_token;
8462 current_token = tok;
95732b49 8463 yyerror (NULL); /* does the right thing */
7117c2d2 8464 current_token = orig_current_token;
f73dda09
JA
8465 if (wl)
8466 dispose_words (wl);
8467 wl = &parse_string_error;
8468 break;
8469 }
8470 wl = make_word_list (yylval.word, wl);
bb70624e 8471 }
f73dda09
JA
8472
8473 last_read_token = '\n';
8474 pop_stream ();
8475
8476#if defined (HISTORY)
8477 remember_on_history = old_remember_on_history;
8478# if defined (BANG_HISTORY)
8479 history_expansion_inhibited = old_history_expansion_inhibited;
8480# endif /* BANG_HISTORY */
8481#endif /* HISTORY */
8482
7117c2d2
JA
8483 echo_input_at_read = old_echo_input;
8484 expand_aliases = old_expand_aliases;
8485
f73dda09
JA
8486 current_command_line_count = orig_line_count;
8487 shell_input_line_terminator = orig_input_terminator;
8488
b80f6443 8489 if (flags & 1)
3185942a 8490 parser_state &= ~(PST_COMPASSIGN|PST_REPARSE);
b80f6443 8491
f73dda09 8492 if (wl == &parse_string_error)
bb70624e 8493 {
f73dda09
JA
8494 last_command_exit_value = EXECUTION_FAILURE;
8495 if (interactive_shell == 0 && posixly_correct)
8496 jump_to_top_level (FORCE_EOF);
8497 else
8498 jump_to_top_level (DISCARD);
bb70624e 8499 }
f73dda09
JA
8500
8501 return (REVERSE_LIST (wl, WORD_LIST *));
bb70624e 8502}
7117c2d2
JA
8503
8504static char *
8505parse_compound_assignment (retlenp)
8506 int *retlenp;
8507{
8508 WORD_LIST *wl, *rl;
0628567a 8509 int tok, orig_line_number, orig_token_size, orig_last_token, assignok;
7117c2d2
JA
8510 char *saved_token, *ret;
8511
8512 saved_token = token;
8513 orig_token_size = token_buffer_size;
8514 orig_line_number = line_number;
0628567a 8515 orig_last_token = last_read_token;
7117c2d2
JA
8516
8517 last_read_token = WORD; /* WORD to allow reserved words here */
8518
8519 token = (char *)NULL;
8520 token_buffer_size = 0;
8521
0628567a
JA
8522 assignok = parser_state&PST_ASSIGNOK; /* XXX */
8523
7117c2d2 8524 wl = (WORD_LIST *)NULL; /* ( */
b80f6443
JA
8525 parser_state |= PST_COMPASSIGN;
8526
7117c2d2
JA
8527 while ((tok = read_token (READ)) != ')')
8528 {
8529 if (tok == '\n') /* Allow newlines in compound assignments */
b80f6443
JA
8530 {
8531 if (SHOULD_PROMPT ())
8532 prompt_again ();
8533 continue;
8534 }
7117c2d2
JA
8535 if (tok != WORD && tok != ASSIGNMENT_WORD)
8536 {
8537 current_token = tok; /* for error reporting */
8538 if (tok == yacc_EOF) /* ( */
b80f6443 8539 parser_error (orig_line_number, _("unexpected EOF while looking for matching `)'"));
7117c2d2 8540 else
95732b49 8541 yyerror(NULL); /* does the right thing */
7117c2d2
JA
8542 if (wl)
8543 dispose_words (wl);
8544 wl = &parse_string_error;
8545 break;
8546 }
8547 wl = make_word_list (yylval.word, wl);
8548 }
8549
8550 FREE (token);
8551 token = saved_token;
8552 token_buffer_size = orig_token_size;
8553
b80f6443
JA
8554 parser_state &= ~PST_COMPASSIGN;
8555
7117c2d2
JA
8556 if (wl == &parse_string_error)
8557 {
8558 last_command_exit_value = EXECUTION_FAILURE;
8559 last_read_token = '\n'; /* XXX */
8560 if (interactive_shell == 0 && posixly_correct)
8561 jump_to_top_level (FORCE_EOF);
8562 else
8563 jump_to_top_level (DISCARD);
8564 }
8565
0628567a
JA
8566 last_read_token = orig_last_token; /* XXX - was WORD? */
8567
7117c2d2
JA
8568 if (wl)
8569 {
8570 rl = REVERSE_LIST (wl, WORD_LIST *);
8571 ret = string_list (rl);
8572 dispose_words (rl);
8573 }
8574 else
8575 ret = (char *)NULL;
8576
8577 if (retlenp)
8578 *retlenp = (ret && *ret) ? strlen (ret) : 0;
0628567a
JA
8579
8580 if (assignok)
8581 parser_state |= PST_ASSIGNOK;
8582
7117c2d2
JA
8583 return ret;
8584}
8585
b80f6443
JA
8586/************************************************
8587 * *
8588 * SAVING AND RESTORING PARTIAL PARSE STATE *
8589 * *
8590 ************************************************/
8591
8592sh_parser_state_t *
8593save_parser_state (ps)
8594 sh_parser_state_t *ps;
8595{
a0c0a00f
CR
8596 int i;
8597
b80f6443 8598 if (ps == 0)
95732b49 8599 ps = (sh_parser_state_t *)xmalloc (sizeof (sh_parser_state_t));
b80f6443
JA
8600 if (ps == 0)
8601 return ((sh_parser_state_t *)NULL);
8602
8603 ps->parser_state = parser_state;
8604 ps->token_state = save_token_state ();
8605
8606 ps->input_line_terminator = shell_input_line_terminator;
8607 ps->eof_encountered = eof_encountered;
8608
495aee44
CR
8609 ps->prompt_string_pointer = prompt_string_pointer;
8610
b80f6443
JA
8611 ps->current_command_line_count = current_command_line_count;
8612
8613#if defined (HISTORY)
8614 ps->remember_on_history = remember_on_history;
8615# if defined (BANG_HISTORY)
8616 ps->history_expansion_inhibited = history_expansion_inhibited;
8617# endif
8618#endif
8619
8620 ps->last_command_exit_value = last_command_exit_value;
8621#if defined (ARRAY_VARS)
495aee44 8622 ps->pipestatus = save_pipestatus_array ();
b80f6443
JA
8623#endif
8624
8625 ps->last_shell_builtin = last_shell_builtin;
8626 ps->this_shell_builtin = this_shell_builtin;
8627
8628 ps->expand_aliases = expand_aliases;
8629 ps->echo_input_at_read = echo_input_at_read;
daefb2c5 8630 ps->need_here_doc = need_here_doc;
a0c0a00f
CR
8631 ps->here_doc_first_line = here_doc_first_line;
8632
8633#if 0
8634 for (i = 0; i < HEREDOC_MAX; i++)
8635 ps->redir_stack[i] = redir_stack[i];
8636#else
8637 if (need_here_doc == 0)
8638 ps->redir_stack[0] = 0;
8639 else
8640 memcpy (ps->redir_stack, redir_stack, sizeof (redir_stack[0]) * HEREDOC_MAX);
8641#endif
b80f6443 8642
509a4430
CR
8643 ps->token = token;
8644 ps->token_buffer_size = token_buffer_size;
8645 /* Force reallocation on next call to read_token_word */
8646 token = 0;
8647 token_buffer_size = 0;
8648
b80f6443
JA
8649 return (ps);
8650}
8651
8652void
8653restore_parser_state (ps)
8654 sh_parser_state_t *ps;
8655{
a0c0a00f
CR
8656 int i;
8657
b80f6443
JA
8658 if (ps == 0)
8659 return;
8660
8661 parser_state = ps->parser_state;
8662 if (ps->token_state)
8663 {
8664 restore_token_state (ps->token_state);
8665 free (ps->token_state);
8666 }
8667
8668 shell_input_line_terminator = ps->input_line_terminator;
8669 eof_encountered = ps->eof_encountered;
8670
495aee44
CR
8671 prompt_string_pointer = ps->prompt_string_pointer;
8672
b80f6443
JA
8673 current_command_line_count = ps->current_command_line_count;
8674
8675#if defined (HISTORY)
8676 remember_on_history = ps->remember_on_history;
8677# if defined (BANG_HISTORY)
8678 history_expansion_inhibited = ps->history_expansion_inhibited;
8679# endif
8680#endif
8681
8682 last_command_exit_value = ps->last_command_exit_value;
8683#if defined (ARRAY_VARS)
495aee44 8684 restore_pipestatus_array (ps->pipestatus);
b80f6443
JA
8685#endif
8686
8687 last_shell_builtin = ps->last_shell_builtin;
8688 this_shell_builtin = ps->this_shell_builtin;
8689
8690 expand_aliases = ps->expand_aliases;
8691 echo_input_at_read = ps->echo_input_at_read;
daefb2c5 8692 need_here_doc = ps->need_here_doc;
a0c0a00f
CR
8693 here_doc_first_line = ps->here_doc_first_line;
8694
8695#if 0
8696 for (i = 0; i < HEREDOC_MAX; i++)
8697 redir_stack[i] = ps->redir_stack[i];
8698#else
8699 if (need_here_doc == 0)
8700 redir_stack[0] = 0;
8701 else
8702 memcpy (redir_stack, ps->redir_stack, sizeof (redir_stack[0]) * HEREDOC_MAX);
8703#endif
509a4430
CR
8704
8705 FREE (token);
8706 token = ps->token;
8707 token_buffer_size = ps->token_buffer_size;
8708}
8709
8710sh_input_line_state_t *
8711save_input_line_state (ls)
8712 sh_input_line_state_t *ls;
8713{
8714 if (ls == 0)
8715 ls = (sh_input_line_state_t *)xmalloc (sizeof (sh_input_line_state_t));
8716 if (ls == 0)
8717 return ((sh_input_line_state_t *)NULL);
8718
8719 ls->input_line = shell_input_line;
8720 ls->input_line_size = shell_input_line_size;
8721 ls->input_line_len = shell_input_line_len;
8722 ls->input_line_index = shell_input_line_index;
8723
8724 /* force reallocation */
8725 shell_input_line = 0;
8726 shell_input_line_size = shell_input_line_len = shell_input_line_index = 0;
ac50fbac
CR
8727
8728 return ls;
509a4430
CR
8729}
8730
8731void
8732restore_input_line_state (ls)
8733 sh_input_line_state_t *ls;
8734{
8735 FREE (shell_input_line);
8736 shell_input_line = ls->input_line;
8737 shell_input_line_size = ls->input_line_size;
8738 shell_input_line_len = ls->input_line_len;
8739 shell_input_line_index = ls->input_line_index;
8740
8741 set_line_mbstate ();
b80f6443
JA
8742}
8743
7117c2d2
JA
8744/************************************************
8745 * *
8746 * MULTIBYTE CHARACTER HANDLING *
8747 * *
8748 ************************************************/
8749
8750#if defined (HANDLE_MULTIBYTE)
8751static void
8752set_line_mbstate ()
8753{
ac50fbac
CR
8754 int c;
8755 size_t i, previ, len;
7117c2d2
JA
8756 mbstate_t mbs, prevs;
8757 size_t mbclen;
8758
8759 if (shell_input_line == NULL)
8760 return;
8761 len = strlen (shell_input_line); /* XXX - shell_input_line_len ? */
a0c0a00f 8762 shell_input_line_property = (char *)xrealloc (shell_input_line_property, len + 1);
7117c2d2
JA
8763
8764 memset (&prevs, '\0', sizeof (mbstate_t));
8765 for (i = previ = 0; i < len; i++)
8766 {
8767 mbs = prevs;
8768
b80f6443
JA
8769 c = shell_input_line[i];
8770 if (c == EOF)
7117c2d2 8771 {
ac50fbac 8772 size_t j;
7117c2d2
JA
8773 for (j = i; j < len; j++)
8774 shell_input_line_property[j] = 1;
8775 break;
8776 }
8777
8778 mbclen = mbrlen (shell_input_line + previ, i - previ + 1, &mbs);
8779 if (mbclen == 1 || mbclen == (size_t)-1)
8780 {
8781 mbclen = 1;
8782 previ = i + 1;
8783 }
8784 else if (mbclen == (size_t)-2)
8785 mbclen = 0;
8786 else if (mbclen > 1)
8787 {
8788 mbclen = 0;
8789 previ = i + 1;
8790 prevs = mbs;
8791 }
8792 else
8793 {
b80f6443 8794 /* XXX - what to do if mbrlen returns 0? (null wide character) */
ac50fbac 8795 size_t j;
b80f6443
JA
8796 for (j = i; j < len; j++)
8797 shell_input_line_property[j] = 1;
8798 break;
7117c2d2
JA
8799 }
8800
8801 shell_input_line_property[i] = mbclen;
8802 }
8803}
8804#endif /* HANDLE_MULTIBYTE */