1 /* A Bison parser, made by GNU Bison 2.3. */
3 /* Skeleton implementation for Bison's Yacc-like parsers in C
5 Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006
6 Free Software Foundation, Inc.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 Boston, MA 02110-1301, USA. */
23 /* As a special exception, you may create a larger work that contains
24 part or all of the Bison parser skeleton and distribute that work
25 under terms of your choice, so long as that work isn't itself a
26 parser generator using the skeleton or a modified version thereof
27 as a parser skeleton. Alternatively, if you modify or redistribute
28 the parser skeleton itself, you may (at your option) remove this
29 special exception, which will cause the skeleton and the resulting
30 Bison output files to be licensed under the GNU General Public
31 License without this special exception.
33 This special exception was added by the Free Software Foundation in
34 version 2.2 of Bison. */
36 /* C LALR(1) parser skeleton written by Richard Stallman, by
37 simplifying the original so-called "semantic" parser. */
39 /* All symbols defined below should begin with yy or YY, to avoid
40 infringing on user name space. This should be done even for local
41 variables, as they might otherwise be expanded by user macros.
42 There are some unavoidable exceptions within include files to
43 define necessary library symbols; they are noted "INFRINGES ON
44 USER NAME SPACE" below. */
46 /* Identify Bison output. */
50 #define YYBISON_VERSION "2.3"
53 #define YYSKELETON_NAME "yacc.c"
58 /* Using locations. */
59 #define YYLSP_NEEDED 0
66 /* Put the tokens into the symbol table, so that GDB and other debuggers
92 ASSIGNMENT_WORD = 281,
96 ARITH_FOR_EXPRS = 285,
100 GREATER_GREATER = 289,
103 LESS_LESS_LESS = 292,
108 LESS_LESS_MINUS = 297,
110 AND_GREATER_GREATER = 299,
133 #define COND_START 273
135 #define COND_ERROR 275
141 #define ASSIGNMENT_WORD 281
142 #define REDIR_WORD 282
144 #define ARITH_CMD 284
145 #define ARITH_FOR_EXPRS 285
149 #define GREATER_GREATER 289
150 #define LESS_LESS 290
152 #define LESS_LESS_LESS 292
153 #define GREATER_AND 293
154 #define SEMI_SEMI 294
156 #define SEMI_SEMI_AND 296
157 #define LESS_LESS_MINUS 297
158 #define AND_GREATER 298
159 #define AND_GREATER_GREATER 299
160 #define LESS_GREATER 300
161 #define GREATER_BAR 301
168 /* Copy the first part of user declarations. */
169 #line 21 "/Users/chet/src/bash/src/parse.y"
173 #include "bashtypes.h"
174 #include "bashansi.h"
176 #include "filecntl.h"
178 #if defined (HAVE_UNISTD_H)
182 #if defined (HAVE_LOCALE_H)
187 #include "chartypes.h"
190 #include "memalloc.h"
192 #include "bashintl.h"
194 #define NEED_STRFTIME_DECL /* used in externs.h */
200 #include "mailcheck.h"
202 #include "builtins.h"
203 #include "builtins/common.h"
204 #include "builtins/builtext.h"
206 #include "shmbutil.h"
208 #if defined (READLINE)
209 # include "bashline.h"
210 # include <readline/readline.h>
211 #endif /* READLINE */
213 #if defined (HISTORY)
214 # include "bashhist.h"
215 # include <readline/history.h>
218 #if defined (JOB_CONTROL)
220 #endif /* JOB_CONTROL */
225 typedef void *alias_t;
228 #if defined (PROMPT_STRING_DECODE)
230 # include <sys/param.h>
233 # if defined (TM_IN_SYS_TIME)
234 # include <sys/types.h>
235 # include <sys/time.h>
236 # endif /* TM_IN_SYS_TIME */
237 # include "maxpath.h"
238 #endif /* PROMPT_STRING_DECODE */
240 #define RE_READ_TOKEN -99
241 #define NO_EXPANSION -100
249 #if defined (HANDLE_MULTIBYTE)
250 # define last_shell_getc_is_singlebyte \
251 ((shell_input_line_index > 1) \
252 ? shell_input_line_property[shell_input_line_index - 1] \
254 # define MBTEST(x) ((x) && last_shell_getc_is_singlebyte)
256 # define last_shell_getc_is_singlebyte 1
257 # define MBTEST(x) ((x))
260 #if defined (EXTENDED_GLOB)
261 extern int extended_glob;
264 extern int eof_encountered;
265 extern int no_line_editing, running_under_emacs;
266 extern int current_command_number;
267 extern int sourcelevel, parse_and_execute_level;
268 extern int posixly_correct;
269 extern int last_command_exit_value;
270 extern pid_t last_command_subst_pid;
271 extern char *shell_name, *current_host_name;
272 extern char *dist_version;
273 extern int patch_level;
274 extern int dump_translatable_strings, dump_po_strings;
275 extern sh_builtin_func_t *last_shell_builtin, *this_shell_builtin;
276 #if defined (BUFFERED_INPUT)
277 extern int bash_input_fd_changed;
281 /* **************************************************************** */
283 /* "Forward" declarations */
285 /* **************************************************************** */
288 static void debug_parser __P((int));
291 static int yy_getc __P((void));
292 static int yy_ungetc __P((int));
294 #if defined (READLINE)
295 static int yy_readline_get __P((void));
296 static int yy_readline_unget __P((int));
299 static int yy_string_get __P((void));
300 static int yy_string_unget __P((int));
301 static void rewind_input_string __P((void));
302 static int yy_stream_get __P((void));
303 static int yy_stream_unget __P((int));
305 static int shell_getc __P((int));
306 static void shell_ungetc __P((int));
307 static void discard_until __P((int));
309 #if defined (ALIAS) || defined (DPAREN_ARITHMETIC)
310 static void push_string __P((char *, int, alias_t *));
311 static void pop_string __P((void));
312 static void free_string_list __P((void));
315 static char *read_a_line __P((int));
317 static int reserved_word_acceptable __P((int));
318 static int yylex __P((void));
319 static int alias_expand_token __P((char *));
320 static int time_command_acceptable __P((void));
321 static int special_case_tokens __P((char *));
322 static int read_token __P((int));
323 static char *parse_matched_pair __P((int, int, int, int *, int));
324 static char *parse_comsub __P((int, int, int, int *, int));
325 #if defined (ARRAY_VARS)
326 static char *parse_compound_assignment __P((int *));
328 #if defined (DPAREN_ARITHMETIC) || defined (ARITH_FOR_COMMAND)
329 static int parse_dparen __P((int));
330 static int parse_arith_cmd __P((char **, int));
332 #if defined (COND_COMMAND)
333 static void cond_error __P((void));
334 static COND_COM *cond_expr __P((void));
335 static COND_COM *cond_or __P((void));
336 static COND_COM *cond_and __P((void));
337 static COND_COM *cond_term __P((void));
338 static int cond_skip_newlines __P((void));
339 static COMMAND *parse_cond_command __P((void));
341 #if defined (ARRAY_VARS)
342 static int token_is_assignment __P((char *, int));
343 static int token_is_ident __P((char *, int));
345 static int read_token_word __P((int));
346 static void discard_parser_constructs __P((int));
348 static char *error_token_from_token __P((int));
349 static char *error_token_from_text __P((void));
350 static void print_offending_line __P((void));
351 static void report_syntax_error __P((char *));
353 static void handle_eof_input_unit __P((void));
354 static void prompt_again __P((void));
356 static void reset_readline_prompt __P((void));
358 static void print_prompt __P((void));
360 #if defined (HANDLE_MULTIBYTE)
361 static void set_line_mbstate __P((void));
362 static char *shell_input_line_property = NULL;
364 # define set_line_mbstate()
367 extern int yyerror __P((const char *));
373 /* Default prompt strings */
374 char *primary_prompt = PPROMPT;
375 char *secondary_prompt = SPROMPT;
377 /* PROMPT_STRING_POINTER points to one of these, never to an actual string. */
378 char *ps1_prompt, *ps2_prompt;
380 /* Handle on the current prompt string. Indirectly points through
381 ps1_ or ps2_prompt. */
382 char **prompt_string_pointer = (char **)NULL;
383 char *current_prompt_string;
385 /* Non-zero means we expand aliases in commands. */
386 int expand_aliases = 0;
388 /* If non-zero, the decoded prompt string undergoes parameter and
389 variable substitution, command substitution, arithmetic substitution,
390 string expansion, process substitution, and quote removal in
391 decode_prompt_string. */
394 /* If non-zero, $'...' and $"..." are expanded when they appear within
395 a ${...} expansion, even when the expansion appears within double
397 int extended_quote = 1;
399 /* The number of lines read from input while creating the current command. */
400 int current_command_line_count;
402 /* The token that currently denotes the end of parse. */
405 /* The token currently being read. */
408 /* The current parser state. */
411 /* Variables to manage the task of reading here documents, because we need to
412 defer the reading until after a complete command has been collected. */
413 static REDIRECT *redir_stack[10];
416 /* Where shell input comes from. History expansion is performed on each
417 line when the shell is interactive. */
418 static char *shell_input_line = (char *)NULL;
419 static int shell_input_line_index;
420 static int shell_input_line_size; /* Amount allocated for shell_input_line. */
421 static int shell_input_line_len; /* strlen (shell_input_line) */
423 /* Either zero or EOF. */
424 static int shell_input_line_terminator;
426 /* The line number in a script on which a function definition starts. */
427 static int function_dstart;
429 /* The line number in a script on which a function body starts. */
430 static int function_bstart;
432 /* The line number in a script at which an arithmetic for command starts. */
433 static int arith_for_lineno;
435 /* The decoded prompt string. Used if READLINE is not defined or if
436 editing is turned off. Analogous to current_readline_prompt. */
437 static char *current_decoded_prompt;
439 /* The last read token, or NULL. read_token () uses this for context
441 static int last_read_token;
443 /* The token read prior to last_read_token. */
444 static int token_before_that;
446 /* The token read prior to token_before_that. */
447 static int two_tokens_ago;
449 static int global_extglob;
451 /* The line number in a script where the word in a `case WORD', `select WORD'
452 or `for WORD' begins. This is a nested command maximum, since the array
453 index is decremented after a case, select, or for command is parsed. */
454 #define MAX_CASE_NEST 128
455 static int word_lineno[MAX_CASE_NEST];
456 static int word_top = -1;
458 /* If non-zero, it is the token that we want read_token to return
459 regardless of what text is (or isn't) present to be read. This
460 is reset by read_token. If token_to_read == WORD or
461 ASSIGNMENT_WORD, yylval.word should be set to word_desc_to_read. */
462 static int token_to_read;
463 static WORD_DESC *word_desc_to_read;
465 static REDIRECTEE source;
466 static REDIRECTEE redir;
469 /* Enabling traces. */
474 /* Enabling verbose error messages. */
475 #ifdef YYERROR_VERBOSE
476 # undef YYERROR_VERBOSE
477 # define YYERROR_VERBOSE 1
479 # define YYERROR_VERBOSE 0
482 /* Enabling the token table. */
483 #ifndef YYTOKEN_TABLE
484 # define YYTOKEN_TABLE 0
487 #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
488 typedef union YYSTYPE
489 #line 320 "/Users/chet/src/bash/src/parse.y"
491 WORD_DESC *word; /* the word that we read. */
492 int number; /* the number that we read. */
493 WORD_LIST *word_list;
497 PATTERN_LIST *pattern;
499 /* Line 187 of yacc.c. */
502 # define yystype YYSTYPE /* obsolescent; will be withdrawn */
503 # define YYSTYPE_IS_DECLARED 1
504 # define YYSTYPE_IS_TRIVIAL 1
509 /* Copy the second part of user declarations. */
512 /* Line 216 of yacc.c. */
520 typedef YYTYPE_UINT8 yytype_uint8;
522 typedef unsigned char yytype_uint8;
526 typedef YYTYPE_INT8 yytype_int8;
527 #elif (defined __STDC__ || defined __C99__FUNC__ \
528 || defined __cplusplus || defined _MSC_VER)
529 typedef signed char yytype_int8;
531 typedef short int yytype_int8;
535 typedef YYTYPE_UINT16 yytype_uint16;
537 typedef unsigned short int yytype_uint16;
541 typedef YYTYPE_INT16 yytype_int16;
543 typedef short int yytype_int16;
547 # ifdef __SIZE_TYPE__
548 # define YYSIZE_T __SIZE_TYPE__
549 # elif defined size_t
550 # define YYSIZE_T size_t
551 # elif ! defined YYSIZE_T && (defined __STDC__ || defined __C99__FUNC__ \
552 || defined __cplusplus || defined _MSC_VER)
553 # include <stddef.h> /* INFRINGES ON USER NAME SPACE */
554 # define YYSIZE_T size_t
556 # define YYSIZE_T unsigned int
560 #define YYSIZE_MAXIMUM ((YYSIZE_T) -1)
565 # include <libintl.h> /* INFRINGES ON USER NAME SPACE */
566 # define YY_(msgid) dgettext ("bison-runtime", msgid)
570 # define YY_(msgid) msgid
574 /* Suppress unused-variable warnings by "using" E. */
575 #if ! defined lint || defined __GNUC__
576 # define YYUSE(e) ((void) (e))
578 # define YYUSE(e) /* empty */
581 /* Identity function, used to suppress warnings about constant conditions. */
585 #if (defined __STDC__ || defined __C99__FUNC__ \
586 || defined __cplusplus || defined _MSC_VER)
599 #if ! defined yyoverflow || YYERROR_VERBOSE
601 /* The parser invokes alloca or malloc; define the necessary symbols. */
603 # ifdef YYSTACK_USE_ALLOCA
604 # if YYSTACK_USE_ALLOCA
606 # define YYSTACK_ALLOC __builtin_alloca
607 # elif defined __BUILTIN_VA_ARG_INCR
608 # include <alloca.h> /* INFRINGES ON USER NAME SPACE */
610 # define YYSTACK_ALLOC __alloca
611 # elif defined _MSC_VER
612 # include <malloc.h> /* INFRINGES ON USER NAME SPACE */
613 # define alloca _alloca
615 # define YYSTACK_ALLOC alloca
616 # if ! defined _ALLOCA_H && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
617 || defined __cplusplus || defined _MSC_VER)
618 # include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
627 # ifdef YYSTACK_ALLOC
628 /* Pacify GCC's `empty if-body' warning. */
629 # define YYSTACK_FREE(Ptr) do { /* empty */; } while (YYID (0))
630 # ifndef YYSTACK_ALLOC_MAXIMUM
631 /* The OS might guarantee only one guard page at the bottom of the stack,
632 and a page size can be as small as 4096 bytes. So we cannot safely
633 invoke alloca (N) if N exceeds 4096. Use a slightly smaller number
634 to allow for a few compiler-allocated temporary stack slots. */
635 # define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */
638 # define YYSTACK_ALLOC YYMALLOC
639 # define YYSTACK_FREE YYFREE
640 # ifndef YYSTACK_ALLOC_MAXIMUM
641 # define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM
643 # if (defined __cplusplus && ! defined _STDLIB_H \
644 && ! ((defined YYMALLOC || defined malloc) \
645 && (defined YYFREE || defined free)))
646 # include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
652 # define YYMALLOC malloc
653 # if ! defined malloc && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
654 || defined __cplusplus || defined _MSC_VER)
655 void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */
660 # if ! defined free && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
661 || defined __cplusplus || defined _MSC_VER)
662 void free (void *); /* INFRINGES ON USER NAME SPACE */
666 #endif /* ! defined yyoverflow || YYERROR_VERBOSE */
669 #if (! defined yyoverflow \
670 && (! defined __cplusplus \
671 || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
673 /* A type that is properly aligned for any stack member. */
680 /* The size of the maximum gap between one aligned stack and the next. */
681 # define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1)
683 /* The size of an array large to enough to hold all stacks, each with
685 # define YYSTACK_BYTES(N) \
686 ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE)) \
687 + YYSTACK_GAP_MAXIMUM)
689 /* Copy COUNT objects from FROM to TO. The source and destination do
692 # if defined __GNUC__ && 1 < __GNUC__
693 # define YYCOPY(To, From, Count) \
694 __builtin_memcpy (To, From, (Count) * sizeof (*(From)))
696 # define YYCOPY(To, From, Count) \
700 for (yyi = 0; yyi < (Count); yyi++) \
701 (To)[yyi] = (From)[yyi]; \
707 /* Relocate STACK from its old location to the new one. The
708 local variables YYSIZE and YYSTACKSIZE give the old and new number of
709 elements in the stack, and YYPTR gives the new location of the
710 stack. Advance YYPTR to a properly aligned location for the next
712 # define YYSTACK_RELOCATE(Stack) \
715 YYSIZE_T yynewbytes; \
716 YYCOPY (&yyptr->Stack, Stack, yysize); \
717 Stack = &yyptr->Stack; \
718 yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \
719 yyptr += yynewbytes / sizeof (*yyptr); \
725 /* YYFINAL -- State number of the termination state. */
727 /* YYLAST -- Last index in YYTABLE. */
730 /* YYNTOKENS -- Number of terminals. */
732 /* YYNNTS -- Number of nonterminals. */
734 /* YYNRULES -- Number of rules. */
736 /* YYNRULES -- Number of states. */
737 #define YYNSTATES 344
739 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
741 #define YYMAXUTOK 303
743 #define YYTRANSLATE(YYX) \
744 ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
746 /* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */
747 static const yytype_uint8 yytranslate[] =
749 0, 2, 2, 2, 2, 2, 2, 2, 2, 2,
750 50, 2, 2, 2, 2, 2, 2, 2, 2, 2,
751 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
752 2, 2, 2, 2, 2, 2, 2, 2, 48, 2,
753 58, 59, 2, 2, 2, 55, 2, 2, 2, 2,
754 2, 2, 2, 2, 2, 2, 2, 2, 2, 49,
755 54, 2, 53, 2, 2, 2, 2, 2, 2, 2,
756 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
757 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
758 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
759 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
760 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
761 2, 2, 2, 56, 52, 57, 2, 2, 2, 2,
762 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
763 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
764 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
765 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
766 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
767 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
768 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
769 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
770 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
771 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
772 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
773 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
774 2, 2, 2, 2, 2, 2, 1, 2, 3, 4,
775 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
776 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
777 25, 26, 27, 28, 29, 30, 31, 32, 33, 34,
778 35, 36, 37, 38, 39, 40, 41, 42, 43, 44,
783 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
785 static const yytype_uint16 yyprhs[] =
787 0, 0, 3, 6, 8, 11, 13, 15, 18, 21,
788 24, 28, 32, 36, 40, 43, 47, 51, 54, 58,
789 62, 65, 69, 73, 76, 80, 84, 87, 91, 95,
790 98, 102, 106, 109, 113, 117, 120, 124, 128, 131,
791 135, 139, 142, 146, 150, 153, 157, 161, 164, 168,
792 172, 175, 178, 180, 182, 184, 186, 189, 191, 194,
793 196, 198, 201, 203, 205, 207, 209, 215, 221, 223,
794 225, 227, 229, 231, 233, 235, 242, 249, 257, 265,
795 276, 287, 297, 307, 315, 323, 329, 335, 342, 349,
796 357, 365, 376, 387, 394, 402, 409, 415, 422, 427,
797 429, 432, 436, 439, 443, 447, 452, 455, 461, 469,
798 476, 480, 482, 486, 491, 498, 504, 506, 509, 514,
799 519, 525, 531, 534, 538, 541, 545, 548, 552, 554,
800 558, 561, 563, 566, 570, 574, 578, 583, 588, 593,
801 598, 603, 605, 607, 609, 611, 613, 615, 616, 619,
802 621, 624, 627, 632, 637, 641, 645, 647, 649, 652,
803 655, 659, 663, 666, 671, 676, 678, 680
806 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
807 static const yytype_int8 yyrhs[] =
809 61, 0, -1, 93, 90, -1, 50, -1, 1, 50,
810 -1, 51, -1, 25, -1, 62, 25, -1, 53, 25,
811 -1, 54, 25, -1, 28, 53, 25, -1, 28, 54,
812 25, -1, 27, 53, 25, -1, 27, 54, 25, -1,
813 34, 25, -1, 28, 34, 25, -1, 27, 34, 25,
814 -1, 46, 25, -1, 28, 46, 25, -1, 27, 46,
815 25, -1, 45, 25, -1, 28, 45, 25, -1, 27,
816 45, 25, -1, 35, 25, -1, 28, 35, 25, -1,
817 27, 35, 25, -1, 42, 25, -1, 28, 42, 25,
818 -1, 27, 42, 25, -1, 37, 25, -1, 28, 37,
819 25, -1, 27, 37, 25, -1, 36, 28, -1, 28,
820 36, 28, -1, 27, 36, 28, -1, 38, 28, -1,
821 28, 38, 28, -1, 27, 38, 28, -1, 36, 25,
822 -1, 28, 36, 25, -1, 27, 36, 25, -1, 38,
823 25, -1, 28, 38, 25, -1, 27, 38, 25, -1,
824 38, 55, -1, 28, 38, 55, -1, 27, 38, 55,
825 -1, 36, 55, -1, 28, 36, 55, -1, 27, 36,
826 55, -1, 43, 25, -1, 44, 25, -1, 25, -1,
827 26, -1, 63, -1, 63, -1, 65, 63, -1, 64,
828 -1, 66, 64, -1, 66, -1, 68, -1, 68, 65,
829 -1, 73, -1, 76, -1, 69, -1, 72, -1, 12,
830 87, 14, 87, 15, -1, 13, 87, 14, 87, 15,
831 -1, 71, -1, 77, -1, 75, -1, 78, -1, 79,
832 -1, 80, -1, 70, -1, 10, 25, 92, 14, 87,
833 15, -1, 10, 25, 92, 56, 87, 57, -1, 10,
834 25, 49, 92, 14, 87, 15, -1, 10, 25, 49,
835 92, 56, 87, 57, -1, 10, 25, 92, 21, 62,
836 91, 92, 14, 87, 15, -1, 10, 25, 92, 21,
837 62, 91, 92, 56, 87, 57, -1, 10, 25, 92,
838 21, 91, 92, 14, 87, 15, -1, 10, 25, 92,
839 21, 91, 92, 56, 87, 57, -1, 10, 30, 91,
840 92, 14, 87, 15, -1, 10, 30, 91, 92, 56,
841 87, 57, -1, 10, 30, 14, 87, 15, -1, 10,
842 30, 56, 87, 57, -1, 11, 25, 92, 14, 86,
843 15, -1, 11, 25, 92, 56, 86, 57, -1, 11,
844 25, 49, 92, 14, 86, 15, -1, 11, 25, 49,
845 92, 56, 86, 57, -1, 11, 25, 92, 21, 62,
846 91, 92, 14, 86, 15, -1, 11, 25, 92, 21,
847 62, 91, 92, 56, 86, 57, -1, 8, 25, 92,
848 21, 92, 9, -1, 8, 25, 92, 21, 84, 92,
849 9, -1, 8, 25, 92, 21, 82, 9, -1, 25,
850 58, 59, 92, 74, -1, 16, 25, 58, 59, 92,
851 74, -1, 16, 25, 92, 74, -1, 68, -1, 68,
852 65, -1, 58, 87, 59, -1, 17, 68, -1, 17,
853 68, 65, -1, 17, 25, 68, -1, 17, 25, 68,
854 65, -1, 17, 66, -1, 3, 87, 4, 87, 7,
855 -1, 3, 87, 4, 87, 5, 87, 7, -1, 3,
856 87, 4, 87, 81, 7, -1, 56, 87, 57, -1,
857 29, -1, 18, 31, 19, -1, 6, 87, 4, 87,
858 -1, 6, 87, 4, 87, 5, 87, -1, 6, 87,
859 4, 87, 81, -1, 83, -1, 84, 83, -1, 92,
860 85, 59, 87, -1, 92, 85, 59, 92, -1, 92,
861 58, 85, 59, 87, -1, 92, 58, 85, 59, 92,
862 -1, 83, 39, -1, 84, 83, 39, -1, 83, 40,
863 -1, 84, 83, 40, -1, 83, 41, -1, 84, 83,
864 41, -1, 25, -1, 85, 52, 25, -1, 92, 88,
865 -1, 86, -1, 92, 89, -1, 89, 50, 92, -1,
866 89, 48, 92, -1, 89, 49, 92, -1, 89, 32,
867 92, 89, -1, 89, 33, 92, 89, -1, 89, 48,
868 92, 89, -1, 89, 49, 92, 89, -1, 89, 50,
869 92, 89, -1, 95, -1, 50, -1, 51, -1, 50,
870 -1, 49, -1, 51, -1, -1, 92, 50, -1, 94,
871 -1, 94, 48, -1, 94, 49, -1, 94, 32, 92,
872 94, -1, 94, 33, 92, 94, -1, 94, 48, 94,
873 -1, 94, 49, 94, -1, 95, -1, 96, -1, 22,
874 96, -1, 97, 96, -1, 97, 22, 96, -1, 22,
875 97, 96, -1, 97, 91, -1, 96, 52, 92, 96,
876 -1, 96, 47, 92, 96, -1, 67, -1, 23, -1,
880 /* YYRLINE[YYN] -- source line where rule number YYN was defined. */
881 static const yytype_uint16 yyrline[] =
883 0, 373, 373, 384, 393, 408, 418, 420, 424, 430,
884 436, 442, 448, 454, 460, 466, 472, 478, 484, 490,
885 496, 502, 508, 514, 521, 528, 535, 542, 549, 556,
886 562, 568, 574, 580, 586, 592, 598, 604, 610, 616,
887 622, 628, 634, 640, 646, 652, 658, 664, 670, 676,
888 682, 688, 696, 698, 700, 704, 708, 719, 721, 725,
889 727, 729, 745, 747, 751, 753, 755, 757, 759, 761,
890 763, 765, 767, 769, 771, 775, 780, 785, 790, 795,
891 800, 805, 810, 817, 822, 827, 832, 839, 844, 849,
892 854, 859, 864, 871, 876, 881, 888, 891, 894, 898,
893 900, 931, 938, 943, 960, 965, 982, 989, 991, 993,
894 998, 1002, 1006, 1010, 1012, 1014, 1018, 1019, 1023, 1025,
895 1027, 1029, 1033, 1035, 1037, 1039, 1041, 1043, 1047, 1049,
896 1058, 1066, 1067, 1073, 1074, 1081, 1085, 1087, 1089, 1096,
897 1098, 1100, 1104, 1105, 1108, 1110, 1112, 1116, 1117, 1126,
898 1139, 1155, 1170, 1172, 1174, 1181, 1184, 1188, 1190, 1196,
899 1202, 1208, 1214, 1234, 1236, 1259, 1263, 1265
903 #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
904 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
905 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
906 static const char *const yytname[] =
908 "$end", "error", "$undefined", "IF", "THEN", "ELSE", "ELIF", "FI",
909 "CASE", "ESAC", "FOR", "SELECT", "WHILE", "UNTIL", "DO", "DONE",
910 "FUNCTION", "COPROC", "COND_START", "COND_END", "COND_ERROR", "IN",
911 "BANG", "TIME", "TIMEOPT", "WORD", "ASSIGNMENT_WORD", "REDIR_WORD",
912 "NUMBER", "ARITH_CMD", "ARITH_FOR_EXPRS", "COND_CMD", "AND_AND", "OR_OR",
913 "GREATER_GREATER", "LESS_LESS", "LESS_AND", "LESS_LESS_LESS",
914 "GREATER_AND", "SEMI_SEMI", "SEMI_AND", "SEMI_SEMI_AND",
915 "LESS_LESS_MINUS", "AND_GREATER", "AND_GREATER_GREATER", "LESS_GREATER",
916 "GREATER_BAR", "BAR_AND", "'&'", "';'", "'\\n'", "yacc_EOF", "'|'",
917 "'>'", "'<'", "'-'", "'{'", "'}'", "'('", "')'", "$accept", "inputunit",
918 "word_list", "redirection", "simple_command_element", "redirection_list",
919 "simple_command", "command", "shell_command", "for_command",
920 "arith_for_command", "select_command", "case_command", "function_def",
921 "function_body", "subshell", "coproc", "if_command", "group_command",
922 "arith_command", "cond_command", "elif_clause", "case_clause",
923 "pattern_list", "case_clause_sequence", "pattern", "list",
924 "compound_list", "list0", "list1", "simple_list_terminator",
925 "list_terminator", "newline_list", "simple_list", "simple_list1",
926 "pipeline_command", "pipeline", "timespec", 0
931 /* YYTOKNUM[YYLEX-NUM] -- Internal token number corresponding to
933 static const yytype_uint16 yytoknum[] =
935 0, 256, 257, 258, 259, 260, 261, 262, 263, 264,
936 265, 266, 267, 268, 269, 270, 271, 272, 273, 274,
937 275, 276, 277, 278, 279, 280, 281, 282, 283, 284,
938 285, 286, 287, 288, 289, 290, 291, 292, 293, 294,
939 295, 296, 297, 298, 299, 300, 301, 302, 38, 59,
940 10, 303, 124, 62, 60, 45, 123, 125, 40, 41
944 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
945 static const yytype_uint8 yyr1[] =
947 0, 60, 61, 61, 61, 61, 62, 62, 63, 63,
948 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
949 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
950 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
951 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
952 63, 63, 64, 64, 64, 65, 65, 66, 66, 67,
953 67, 67, 67, 67, 68, 68, 68, 68, 68, 68,
954 68, 68, 68, 68, 68, 69, 69, 69, 69, 69,
955 69, 69, 69, 70, 70, 70, 70, 71, 71, 71,
956 71, 71, 71, 72, 72, 72, 73, 73, 73, 74,
957 74, 75, 76, 76, 76, 76, 76, 77, 77, 77,
958 78, 79, 80, 81, 81, 81, 82, 82, 83, 83,
959 83, 83, 84, 84, 84, 84, 84, 84, 85, 85,
960 86, 87, 87, 88, 88, 88, 89, 89, 89, 89,
961 89, 89, 90, 90, 91, 91, 91, 92, 92, 93,
962 93, 93, 94, 94, 94, 94, 94, 95, 95, 95,
963 95, 95, 95, 96, 96, 96, 97, 97
966 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
967 static const yytype_uint8 yyr2[] =
969 0, 2, 2, 1, 2, 1, 1, 2, 2, 2,
970 3, 3, 3, 3, 2, 3, 3, 2, 3, 3,
971 2, 3, 3, 2, 3, 3, 2, 3, 3, 2,
972 3, 3, 2, 3, 3, 2, 3, 3, 2, 3,
973 3, 2, 3, 3, 2, 3, 3, 2, 3, 3,
974 2, 2, 1, 1, 1, 1, 2, 1, 2, 1,
975 1, 2, 1, 1, 1, 1, 5, 5, 1, 1,
976 1, 1, 1, 1, 1, 6, 6, 7, 7, 10,
977 10, 9, 9, 7, 7, 5, 5, 6, 6, 7,
978 7, 10, 10, 6, 7, 6, 5, 6, 4, 1,
979 2, 3, 2, 3, 3, 4, 2, 5, 7, 6,
980 3, 1, 3, 4, 6, 5, 1, 2, 4, 4,
981 5, 5, 2, 3, 2, 3, 2, 3, 1, 3,
982 2, 1, 2, 3, 3, 3, 4, 4, 4, 4,
983 4, 1, 1, 1, 1, 1, 1, 0, 2, 1,
984 2, 2, 4, 4, 3, 3, 1, 1, 2, 2,
985 3, 3, 2, 4, 4, 1, 1, 2
988 /* YYDEFACT[STATE-NAME] -- Default rule to reduce with in state
989 STATE-NUM when YYTABLE doesn't specify something else to do. Zero
990 means the default is an error. */
991 static const yytype_uint8 yydefact[] =
993 0, 0, 147, 0, 0, 0, 147, 147, 0, 0,
994 0, 0, 166, 52, 53, 0, 0, 111, 0, 0,
995 0, 0, 0, 0, 0, 0, 0, 0, 3, 5,
996 0, 0, 147, 147, 0, 54, 57, 59, 165, 60,
997 64, 74, 68, 65, 62, 70, 63, 69, 71, 72,
998 73, 0, 149, 156, 157, 0, 4, 131, 0, 0,
999 147, 147, 0, 147, 0, 0, 147, 52, 106, 102,
1000 0, 158, 0, 167, 0, 0, 0, 0, 0, 0,
1001 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1002 0, 0, 0, 0, 0, 14, 23, 38, 32, 47,
1003 29, 41, 35, 44, 26, 50, 51, 20, 17, 8,
1004 9, 0, 0, 1, 52, 58, 55, 61, 142, 143,
1005 2, 147, 147, 150, 151, 147, 147, 0, 145, 144,
1006 146, 162, 159, 147, 148, 130, 132, 141, 0, 147,
1007 0, 147, 147, 147, 147, 0, 147, 147, 0, 0,
1008 104, 103, 112, 161, 147, 16, 25, 40, 34, 49,
1009 31, 43, 37, 46, 28, 22, 19, 12, 13, 15,
1010 24, 39, 33, 48, 30, 42, 36, 45, 27, 21,
1011 18, 10, 11, 110, 101, 56, 0, 0, 154, 155,
1012 0, 0, 160, 0, 147, 147, 147, 147, 147, 147,
1013 0, 147, 0, 147, 0, 0, 0, 0, 147, 0,
1014 147, 0, 0, 147, 99, 98, 105, 0, 152, 153,
1015 0, 0, 164, 163, 147, 147, 107, 0, 0, 0,
1016 134, 135, 133, 0, 116, 147, 0, 147, 147, 0,
1017 6, 0, 147, 0, 85, 86, 147, 147, 147, 147,
1018 0, 0, 0, 0, 66, 67, 0, 100, 96, 0,
1019 0, 109, 136, 137, 138, 139, 140, 95, 122, 124,
1020 126, 117, 0, 93, 128, 0, 0, 0, 0, 75,
1021 7, 147, 0, 76, 0, 0, 0, 0, 87, 0,
1022 147, 88, 97, 108, 147, 147, 147, 147, 123, 125,
1023 127, 94, 0, 0, 147, 77, 78, 0, 147, 147,
1024 83, 84, 89, 90, 0, 113, 0, 0, 0, 147,
1025 129, 118, 119, 147, 147, 0, 0, 147, 147, 147,
1026 115, 120, 121, 0, 0, 81, 82, 0, 0, 114,
1030 /* YYDEFGOTO[NTERM-NUM]. */
1031 static const yytype_int16 yydefgoto[] =
1033 -1, 34, 241, 35, 36, 117, 37, 38, 39, 40,
1034 41, 42, 43, 44, 215, 45, 46, 47, 48, 49,
1035 50, 227, 233, 234, 235, 276, 57, 58, 135, 136,
1036 120, 131, 59, 51, 188, 137, 54, 55
1039 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
1041 #define YYPACT_NINF -212
1042 static const yytype_int16 yypact[] =
1044 318, -40, -212, 11, 10, 32, -212, -212, 34, 661,
1045 39, 514, 52, 21, -212, 255, 706, -212, 65, 79,
1046 47, 98, 55, 133, 134, 139, 151, 152, -212, -212,
1047 156, 157, -212, -212, 142, -212, -212, 232, -212, 693,
1048 -212, -212, -212, -212, -212, -212, -212, -212, -212, -212,
1049 -212, 49, 213, -212, -28, 367, -212, -212, 150, 416,
1050 -212, 135, -3, 137, 184, 194, 158, 31, 232, 693,
1051 191, -28, 612, -212, 166, 199, 202, 69, 209, 128,
1052 210, 214, 218, 219, 225, 227, 247, 165, 248, 181,
1053 256, 257, 258, 259, 262, -212, -212, -212, -212, -212,
1054 -212, -212, -212, -212, -212, -212, -212, -212, -212, -212,
1055 -212, 237, 236, -212, -212, -212, -212, 693, -212, -212,
1056 -212, -212, -212, 465, 465, -212, -212, 612, -212, -212,
1057 -212, -212, -28, -212, -212, -212, 205, -212, -13, -212,
1058 116, -212, -212, -212, -212, 117, -212, -212, 240, 53,
1059 693, 693, -212, -28, -212, -212, -212, -212, -212, -212,
1060 -212, -212, -212, -212, -212, -212, -212, -212, -212, -212,
1061 -212, -212, -212, -212, -212, -212, -212, -212, -212, -212,
1062 -212, -212, -212, -212, -212, -212, 416, 416, 75, 75,
1063 563, 563, -28, 15, -212, -212, -212, -212, -212, -212,
1064 72, -212, 120, -212, 281, 249, 105, 118, -212, 279,
1065 -212, 290, 292, -212, 693, -212, 693, 53, -212, -212,
1066 465, 465, -28, -28, -212, -212, -212, 303, 416, 416,
1067 416, 416, 416, 302, 174, -212, 0, -212, -212, 297,
1068 -212, 179, -212, 263, -212, -212, -212, -212, -212, -212,
1069 299, 416, 179, 265, -212, -212, 53, 693, -212, 308,
1070 312, -212, -212, -212, 80, 80, 80, -212, -212, -212,
1071 -212, 224, 43, -212, -212, 300, 33, 309, 270, -212,
1072 -212, -212, 129, -212, 317, 276, 322, 282, -212, 205,
1073 -212, -212, -212, -212, -212, -212, -212, -212, -212, -212,
1074 -212, -212, 46, 313, -212, -212, -212, 149, -212, -212,
1075 -212, -212, -212, -212, 161, 115, 416, 416, 416, -212,
1076 -212, -212, 416, -212, -212, 327, 291, -212, -212, -212,
1077 -212, -212, 416, 334, 293, -212, -212, 336, 301, -212,
1078 -212, -212, -212, -212
1081 /* YYPGOTO[NTERM-NUM]. */
1082 static const yytype_int16 yypgoto[] =
1084 -212, -212, 148, -36, 1, -62, 350, -212, -5, -212,
1085 -212, -212, -212, -212, -211, -212, -212, -212, -212, -212,
1086 -212, 50, -212, 131, -212, 92, -194, -6, -212, -200,
1087 -212, -45, -48, -212, 5, 2, 12, 362
1090 /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
1091 positive, shift that token. If negative, reduce the rule which
1092 number is the opposite. If zero, do what YYDEFACT says.
1093 If YYTABLE_NINF, syntax error. */
1094 #define YYTABLE_NINF -1
1095 static const yytype_uint16 yytable[] =
1097 64, 65, 53, 116, 69, 52, 258, 151, 199, 273,
1098 56, 141, 138, 140, 250, 145, 253, 143, 149, 125,
1099 224, 225, 226, 71, 126, 274, 111, 112, 262, 263,
1100 264, 265, 266, 116, 2, 61, 60, 134, 115, 3,
1101 62, 4, 5, 6, 7, 292, 128, 129, 130, 10,
1102 134, 289, 301, 142, 286, 287, 2, 63, 275, 66,
1103 17, 3, 150, 4, 5, 6, 7, 132, 274, 115,
1104 70, 10, 97, 186, 187, 98, 73, 190, 191, 74,
1105 101, 185, 17, 102, 153, 303, 237, 32, 216, 33,
1106 95, 200, 304, 134, 157, 206, 207, 158, 303, 118,
1107 119, 275, 99, 134, 96, 319, 217, 121, 122, 32,
1108 103, 33, 194, 195, 116, 185, 264, 265, 266, 246,
1109 329, 225, 134, 100, 159, 53, 53, 193, 238, 189,
1110 201, 208, 248, 337, 338, 204, 205, 202, 209, 192,
1111 211, 212, 113, 308, 214, 240, 228, 229, 230, 231,
1112 232, 236, 257, 161, 133, 134, 162, 242, 104, 105,
1113 251, 247, 251, 323, 106, 256, 134, 134, 134, 128,
1114 129, 130, 203, 210, 249, 327, 107, 108, 116, 134,
1115 185, 109, 110, 163, 139, 309, 144, 272, 53, 53,
1116 171, 218, 219, 172, 282, 239, 281, 243, 146, 134,
1117 251, 251, 222, 223, 280, 324, 175, 290, 147, 176,
1118 152, 134, 214, 268, 269, 270, 148, 328, 259, 260,
1119 173, 185, 53, 53, 155, 154, 189, 156, 128, 129,
1120 130, 277, 278, 307, 160, 164, 177, 194, 195, 165,
1121 284, 285, 314, 166, 167, 121, 122, 316, 317, 318,
1122 168, 214, 169, 196, 197, 198, 322, 114, 14, 15,
1123 16, 123, 124, 298, 299, 300, 18, 19, 20, 21,
1124 22, 332, 170, 174, 23, 24, 25, 26, 27, 251,
1125 251, 178, 179, 180, 181, 30, 31, 182, 315, 75,
1126 76, 77, 78, 79, 183, 184, 244, 80, 321, 213,
1127 81, 82, 325, 326, 240, 254, 245, 255, 83, 84,
1128 261, 267, 279, 331, 288, 293, 294, 333, 334, 1,
1129 283, 2, 291, 339, 305, 274, 3, 306, 4, 5,
1130 6, 7, 310, 311, 8, 9, 10, 312, 320, 313,
1131 11, 12, 335, 13, 14, 15, 16, 17, 336, 340,
1132 341, 342, 18, 19, 20, 21, 22, 252, 343, 68,
1133 23, 24, 25, 26, 27, 330, 271, 302, 28, 29,
1134 2, 30, 31, 72, 32, 3, 33, 4, 5, 6,
1135 7, 0, 0, 8, 9, 10, 0, 0, 0, 127,
1136 0, 0, 13, 14, 15, 16, 17, 0, 0, 0,
1137 0, 18, 19, 20, 21, 22, 0, 0, 0, 23,
1138 24, 25, 26, 27, 0, 0, 128, 129, 130, 2,
1139 30, 31, 0, 32, 3, 33, 4, 5, 6, 7,
1140 0, 0, 8, 9, 10, 0, 0, 0, 11, 12,
1141 0, 13, 14, 15, 16, 17, 0, 0, 0, 0,
1142 18, 19, 20, 21, 22, 0, 0, 0, 23, 24,
1143 25, 26, 27, 0, 0, 0, 134, 0, 2, 30,
1144 31, 0, 32, 3, 33, 4, 5, 6, 7, 0,
1145 0, 8, 9, 10, 0, 0, 0, 11, 12, 0,
1146 13, 14, 15, 16, 17, 0, 0, 0, 0, 18,
1147 19, 20, 21, 22, 0, 0, 0, 23, 24, 25,
1148 26, 27, 0, 0, 0, 0, 0, 2, 30, 31,
1149 0, 32, 3, 33, 4, 5, 6, 7, 0, 0,
1150 8, 9, 10, 0, 0, 0, 0, 12, 0, 13,
1151 14, 15, 16, 17, 0, 0, 0, 0, 18, 19,
1152 20, 21, 22, 0, 0, 0, 23, 24, 25, 26,
1153 27, 0, 0, 0, 0, 0, 2, 30, 31, 0,
1154 32, 3, 33, 4, 5, 6, 7, 0, 0, 8,
1155 9, 10, 0, 0, 0, 0, 0, 0, 13, 14,
1156 15, 16, 17, 0, 0, 0, 0, 18, 19, 20,
1157 21, 22, 0, 0, 0, 23, 24, 25, 26, 27,
1158 0, 0, 0, 134, 0, 2, 30, 31, 0, 32,
1159 3, 33, 4, 5, 6, 7, 0, 0, 8, 9,
1160 10, 0, 0, 0, 0, 0, 0, 13, 14, 15,
1161 16, 17, 0, 0, 0, 0, 18, 19, 20, 21,
1162 22, 0, 0, 0, 23, 24, 25, 26, 27, 0,
1163 0, 0, 0, 0, 2, 30, 31, 0, 32, 3,
1164 33, 4, 5, 6, 7, 0, 0, 0, 0, 10,
1165 0, 0, 0, 0, 0, 0, 67, 14, 15, 16,
1166 17, 0, 0, 0, 0, 18, 19, 20, 21, 22,
1167 0, 0, 0, 23, 24, 25, 26, 27, 0, 0,
1168 0, 0, 0, 0, 30, 31, 0, 32, 0, 33,
1169 15, 16, 0, 0, 0, 0, 0, 18, 19, 20,
1170 21, 22, 0, 0, 0, 23, 24, 25, 26, 27,
1171 85, 86, 87, 88, 89, 0, 30, 31, 90, 0,
1172 0, 91, 92, 0, 0, 0, 0, 0, 0, 93,
1176 static const yytype_int16 yycheck[] =
1178 6, 7, 0, 39, 9, 0, 217, 69, 21, 9,
1179 50, 14, 60, 61, 208, 63, 210, 62, 66, 47,
1180 5, 6, 7, 11, 52, 25, 32, 33, 228, 229,
1181 230, 231, 232, 69, 3, 25, 25, 50, 37, 8,
1182 30, 10, 11, 12, 13, 256, 49, 50, 51, 18,
1183 50, 251, 9, 56, 248, 249, 3, 25, 58, 25,
1184 29, 8, 67, 10, 11, 12, 13, 55, 25, 68,
1185 31, 18, 25, 121, 122, 28, 24, 125, 126, 58,
1186 25, 117, 29, 28, 72, 52, 14, 56, 150, 58,
1187 25, 139, 59, 50, 25, 143, 144, 28, 52, 50,
1188 51, 58, 55, 50, 25, 59, 154, 32, 33, 56,
1189 55, 58, 32, 33, 150, 151, 316, 317, 318, 14,
1190 5, 6, 50, 25, 55, 123, 124, 133, 56, 124,
1191 14, 14, 14, 327, 328, 141, 142, 21, 21, 127,
1192 146, 147, 0, 14, 149, 25, 194, 195, 196, 197,
1193 198, 199, 214, 25, 4, 50, 28, 202, 25, 25,
1194 208, 56, 210, 14, 25, 213, 50, 50, 50, 49,
1195 50, 51, 56, 56, 56, 14, 25, 25, 214, 50,
1196 216, 25, 25, 55, 49, 56, 49, 235, 186, 187,
1197 25, 186, 187, 28, 242, 201, 241, 203, 14, 50,
1198 248, 249, 190, 191, 25, 56, 25, 252, 14, 28,
1199 19, 50, 217, 39, 40, 41, 58, 56, 224, 225,
1200 55, 257, 220, 221, 25, 59, 221, 25, 49, 50,
1201 51, 237, 238, 281, 25, 25, 55, 32, 33, 25,
1202 246, 247, 290, 25, 25, 32, 33, 295, 296, 297,
1203 25, 256, 25, 48, 49, 50, 304, 25, 26, 27,
1204 28, 48, 49, 39, 40, 41, 34, 35, 36, 37,
1205 38, 319, 25, 25, 42, 43, 44, 45, 46, 327,
1206 328, 25, 25, 25, 25, 53, 54, 25, 294, 34,
1207 35, 36, 37, 38, 57, 59, 15, 42, 304, 59,
1208 45, 46, 308, 309, 25, 15, 57, 15, 53, 54,
1209 7, 9, 15, 319, 15, 7, 4, 323, 324, 1,
1210 57, 3, 57, 329, 15, 25, 8, 57, 10, 11,
1211 12, 13, 15, 57, 16, 17, 18, 15, 25, 57,
1212 22, 23, 15, 25, 26, 27, 28, 29, 57, 15,
1213 57, 15, 34, 35, 36, 37, 38, 209, 57, 9,
1214 42, 43, 44, 45, 46, 315, 235, 275, 50, 51,
1215 3, 53, 54, 11, 56, 8, 58, 10, 11, 12,
1216 13, -1, -1, 16, 17, 18, -1, -1, -1, 22,
1217 -1, -1, 25, 26, 27, 28, 29, -1, -1, -1,
1218 -1, 34, 35, 36, 37, 38, -1, -1, -1, 42,
1219 43, 44, 45, 46, -1, -1, 49, 50, 51, 3,
1220 53, 54, -1, 56, 8, 58, 10, 11, 12, 13,
1221 -1, -1, 16, 17, 18, -1, -1, -1, 22, 23,
1222 -1, 25, 26, 27, 28, 29, -1, -1, -1, -1,
1223 34, 35, 36, 37, 38, -1, -1, -1, 42, 43,
1224 44, 45, 46, -1, -1, -1, 50, -1, 3, 53,
1225 54, -1, 56, 8, 58, 10, 11, 12, 13, -1,
1226 -1, 16, 17, 18, -1, -1, -1, 22, 23, -1,
1227 25, 26, 27, 28, 29, -1, -1, -1, -1, 34,
1228 35, 36, 37, 38, -1, -1, -1, 42, 43, 44,
1229 45, 46, -1, -1, -1, -1, -1, 3, 53, 54,
1230 -1, 56, 8, 58, 10, 11, 12, 13, -1, -1,
1231 16, 17, 18, -1, -1, -1, -1, 23, -1, 25,
1232 26, 27, 28, 29, -1, -1, -1, -1, 34, 35,
1233 36, 37, 38, -1, -1, -1, 42, 43, 44, 45,
1234 46, -1, -1, -1, -1, -1, 3, 53, 54, -1,
1235 56, 8, 58, 10, 11, 12, 13, -1, -1, 16,
1236 17, 18, -1, -1, -1, -1, -1, -1, 25, 26,
1237 27, 28, 29, -1, -1, -1, -1, 34, 35, 36,
1238 37, 38, -1, -1, -1, 42, 43, 44, 45, 46,
1239 -1, -1, -1, 50, -1, 3, 53, 54, -1, 56,
1240 8, 58, 10, 11, 12, 13, -1, -1, 16, 17,
1241 18, -1, -1, -1, -1, -1, -1, 25, 26, 27,
1242 28, 29, -1, -1, -1, -1, 34, 35, 36, 37,
1243 38, -1, -1, -1, 42, 43, 44, 45, 46, -1,
1244 -1, -1, -1, -1, 3, 53, 54, -1, 56, 8,
1245 58, 10, 11, 12, 13, -1, -1, -1, -1, 18,
1246 -1, -1, -1, -1, -1, -1, 25, 26, 27, 28,
1247 29, -1, -1, -1, -1, 34, 35, 36, 37, 38,
1248 -1, -1, -1, 42, 43, 44, 45, 46, -1, -1,
1249 -1, -1, -1, -1, 53, 54, -1, 56, -1, 58,
1250 27, 28, -1, -1, -1, -1, -1, 34, 35, 36,
1251 37, 38, -1, -1, -1, 42, 43, 44, 45, 46,
1252 34, 35, 36, 37, 38, -1, 53, 54, 42, -1,
1253 -1, 45, 46, -1, -1, -1, -1, -1, -1, 53,
1257 /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
1258 symbol of state STATE-NUM. */
1259 static const yytype_uint8 yystos[] =
1261 0, 1, 3, 8, 10, 11, 12, 13, 16, 17,
1262 18, 22, 23, 25, 26, 27, 28, 29, 34, 35,
1263 36, 37, 38, 42, 43, 44, 45, 46, 50, 51,
1264 53, 54, 56, 58, 61, 63, 64, 66, 67, 68,
1265 69, 70, 71, 72, 73, 75, 76, 77, 78, 79,
1266 80, 93, 94, 95, 96, 97, 50, 86, 87, 92,
1267 25, 25, 30, 25, 87, 87, 25, 25, 66, 68,
1268 31, 96, 97, 24, 58, 34, 35, 36, 37, 38,
1269 42, 45, 46, 53, 54, 34, 35, 36, 37, 38,
1270 42, 45, 46, 53, 54, 25, 25, 25, 28, 55,
1271 25, 25, 28, 55, 25, 25, 25, 25, 25, 25,
1272 25, 87, 87, 0, 25, 64, 63, 65, 50, 51,
1273 90, 32, 33, 48, 49, 47, 52, 22, 49, 50,
1274 51, 91, 96, 4, 50, 88, 89, 95, 92, 49,
1275 92, 14, 56, 91, 49, 92, 14, 14, 58, 92,
1276 68, 65, 19, 96, 59, 25, 25, 25, 28, 55,
1277 25, 25, 28, 55, 25, 25, 25, 25, 25, 25,
1278 25, 25, 28, 55, 25, 25, 28, 55, 25, 25,
1279 25, 25, 25, 57, 59, 63, 92, 92, 94, 94,
1280 92, 92, 96, 87, 32, 33, 48, 49, 50, 21,
1281 92, 14, 21, 56, 87, 87, 92, 92, 14, 21,
1282 56, 87, 87, 59, 68, 74, 65, 92, 94, 94,
1283 48, 49, 96, 96, 5, 6, 7, 81, 92, 92,
1284 92, 92, 92, 82, 83, 84, 92, 14, 56, 87,
1285 25, 62, 91, 87, 15, 57, 14, 56, 14, 56,
1286 86, 92, 62, 86, 15, 15, 92, 65, 74, 87,
1287 87, 7, 89, 89, 89, 89, 89, 9, 39, 40,
1288 41, 83, 92, 9, 25, 58, 85, 87, 87, 15,
1289 25, 91, 92, 57, 87, 87, 86, 86, 15, 89,
1290 91, 57, 74, 7, 4, 48, 49, 50, 39, 40,
1291 41, 9, 85, 52, 59, 15, 57, 92, 14, 56,
1292 15, 57, 15, 57, 92, 87, 92, 92, 92, 59,
1293 25, 87, 92, 14, 56, 87, 87, 14, 56, 5,
1294 81, 87, 92, 87, 87, 15, 57, 86, 86, 87,
1298 #define yyerrok (yyerrstatus = 0)
1299 #define yyclearin (yychar = YYEMPTY)
1300 #define YYEMPTY (-2)
1303 #define YYACCEPT goto yyacceptlab
1304 #define YYABORT goto yyabortlab
1305 #define YYERROR goto yyerrorlab
1308 /* Like YYERROR except do call yyerror. This remains here temporarily
1309 to ease the transition to the new meaning of YYERROR, for GCC.
1310 Once GCC version 2 has supplanted version 1, this can go. */
1312 #define YYFAIL goto yyerrlab
1314 #define YYRECOVERING() (!!yyerrstatus)
1316 #define YYBACKUP(Token, Value) \
1318 if (yychar == YYEMPTY && yylen == 1) \
1322 yytoken = YYTRANSLATE (yychar); \
1328 yyerror (YY_("syntax error: cannot back up")); \
1335 #define YYERRCODE 256
1338 /* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
1339 If N is 0, then set CURRENT to the empty location which ends
1340 the previous symbol: RHS[0] (always defined). */
1342 #define YYRHSLOC(Rhs, K) ((Rhs)[K])
1343 #ifndef YYLLOC_DEFAULT
1344 # define YYLLOC_DEFAULT(Current, Rhs, N) \
1348 (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \
1349 (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \
1350 (Current).last_line = YYRHSLOC (Rhs, N).last_line; \
1351 (Current).last_column = YYRHSLOC (Rhs, N).last_column; \
1355 (Current).first_line = (Current).last_line = \
1356 YYRHSLOC (Rhs, 0).last_line; \
1357 (Current).first_column = (Current).last_column = \
1358 YYRHSLOC (Rhs, 0).last_column; \
1364 /* YY_LOCATION_PRINT -- Print the location on the stream.
1365 This macro was not mandated originally: define only if we know
1366 we won't break user code: when these are the locations we know. */
1368 #ifndef YY_LOCATION_PRINT
1369 # if YYLTYPE_IS_TRIVIAL
1370 # define YY_LOCATION_PRINT(File, Loc) \
1371 fprintf (File, "%d.%d-%d.%d", \
1372 (Loc).first_line, (Loc).first_column, \
1373 (Loc).last_line, (Loc).last_column)
1375 # define YY_LOCATION_PRINT(File, Loc) ((void) 0)
1380 /* YYLEX -- calling `yylex' with the right arguments. */
1383 # define YYLEX yylex (YYLEX_PARAM)
1385 # define YYLEX yylex ()
1388 /* Enable debugging if requested. */
1392 # include <stdio.h> /* INFRINGES ON USER NAME SPACE */
1393 # define YYFPRINTF fprintf
1396 # define YYDPRINTF(Args) \
1402 # define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
1406 YYFPRINTF (stderr, "%s ", Title); \
1407 yy_symbol_print (stderr, \
1409 YYFPRINTF (stderr, "\n"); \
1414 /*--------------------------------.
1415 | Print this symbol on YYOUTPUT. |
1416 `--------------------------------*/
1419 #if (defined __STDC__ || defined __C99__FUNC__ \
1420 || defined __cplusplus || defined _MSC_VER)
1422 yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep)
1425 yy_symbol_value_print (yyoutput, yytype, yyvaluep)
1428 YYSTYPE const * const yyvaluep;
1434 if (yytype < YYNTOKENS)
1435 YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep);
1447 /*--------------------------------.
1448 | Print this symbol on YYOUTPUT. |
1449 `--------------------------------*/
1451 #if (defined __STDC__ || defined __C99__FUNC__ \
1452 || defined __cplusplus || defined _MSC_VER)
1454 yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep)
1457 yy_symbol_print (yyoutput, yytype, yyvaluep)
1460 YYSTYPE const * const yyvaluep;
1463 if (yytype < YYNTOKENS)
1464 YYFPRINTF (yyoutput, "token %s (", yytname[yytype]);
1466 YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]);
1468 yy_symbol_value_print (yyoutput, yytype, yyvaluep);
1469 YYFPRINTF (yyoutput, ")");
1472 /*------------------------------------------------------------------.
1473 | yy_stack_print -- Print the state stack from its BOTTOM up to its |
1475 `------------------------------------------------------------------*/
1477 #if (defined __STDC__ || defined __C99__FUNC__ \
1478 || defined __cplusplus || defined _MSC_VER)
1480 yy_stack_print (yytype_int16 *bottom, yytype_int16 *top)
1483 yy_stack_print (bottom, top)
1484 yytype_int16 *bottom;
1488 YYFPRINTF (stderr, "Stack now");
1489 for (; bottom <= top; ++bottom)
1490 YYFPRINTF (stderr, " %d", *bottom);
1491 YYFPRINTF (stderr, "\n");
1494 # define YY_STACK_PRINT(Bottom, Top) \
1497 yy_stack_print ((Bottom), (Top)); \
1501 /*------------------------------------------------.
1502 | Report that the YYRULE is going to be reduced. |
1503 `------------------------------------------------*/
1505 #if (defined __STDC__ || defined __C99__FUNC__ \
1506 || defined __cplusplus || defined _MSC_VER)
1508 yy_reduce_print (YYSTYPE *yyvsp, int yyrule)
1511 yy_reduce_print (yyvsp, yyrule)
1516 int yynrhs = yyr2[yyrule];
1518 unsigned long int yylno = yyrline[yyrule];
1519 YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n",
1521 /* The symbols being reduced. */
1522 for (yyi = 0; yyi < yynrhs; yyi++)
1524 fprintf (stderr, " $%d = ", yyi + 1);
1525 yy_symbol_print (stderr, yyrhs[yyprhs[yyrule] + yyi],
1526 &(yyvsp[(yyi + 1) - (yynrhs)])
1528 fprintf (stderr, "\n");
1532 # define YY_REDUCE_PRINT(Rule) \
1535 yy_reduce_print (yyvsp, Rule); \
1538 /* Nonzero means print parse trace. It is left uninitialized so that
1539 multiple parsers can coexist. */
1541 #else /* !YYDEBUG */
1542 # define YYDPRINTF(Args)
1543 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
1544 # define YY_STACK_PRINT(Bottom, Top)
1545 # define YY_REDUCE_PRINT(Rule)
1546 #endif /* !YYDEBUG */
1549 /* YYINITDEPTH -- initial size of the parser's stacks. */
1551 # define YYINITDEPTH 200
1554 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
1555 if the built-in stack extension method is used).
1557 Do not make this value too large; the results are undefined if
1558 YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH)
1559 evaluated with infinite-precision integer arithmetic. */
1562 # define YYMAXDEPTH 10000
1570 # if defined __GLIBC__ && defined _STRING_H
1571 # define yystrlen strlen
1573 /* Return the length of YYSTR. */
1574 #if (defined __STDC__ || defined __C99__FUNC__ \
1575 || defined __cplusplus || defined _MSC_VER)
1577 yystrlen (const char *yystr)
1585 for (yylen = 0; yystr[yylen]; yylen++)
1593 # if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
1594 # define yystpcpy stpcpy
1596 /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
1598 #if (defined __STDC__ || defined __C99__FUNC__ \
1599 || defined __cplusplus || defined _MSC_VER)
1601 yystpcpy (char *yydest, const char *yysrc)
1604 yystpcpy (yydest, yysrc)
1610 const char *yys = yysrc;
1612 while ((*yyd++ = *yys++) != '\0')
1621 /* Copy to YYRES the contents of YYSTR after stripping away unnecessary
1622 quotes and backslashes, so that it's suitable for yyerror. The
1623 heuristic is that double-quoting is unnecessary unless the string
1624 contains an apostrophe, a comma, or backslash (other than
1625 backslash-backslash). YYSTR is taken from yytname. If YYRES is
1626 null, do not copy; instead, return the length of what the result
1629 yytnamerr (char *yyres, const char *yystr)
1634 char const *yyp = yystr;
1641 goto do_not_strip_quotes;
1645 goto do_not_strip_quotes;
1658 do_not_strip_quotes: ;
1662 return yystrlen (yystr);
1664 return yystpcpy (yyres, yystr) - yyres;
1668 /* Copy into YYRESULT an error message about the unexpected token
1669 YYCHAR while in state YYSTATE. Return the number of bytes copied,
1670 including the terminating null byte. If YYRESULT is null, do not
1671 copy anything; just return the number of bytes that would be
1672 copied. As a special case, return 0 if an ordinary "syntax error"
1673 message will do. Return YYSIZE_MAXIMUM if overflow occurs during
1674 size calculation. */
1676 yysyntax_error (char *yyresult, int yystate, int yychar)
1678 int yyn = yypact[yystate];
1680 if (! (YYPACT_NINF < yyn && yyn <= YYLAST))
1684 int yytype = YYTRANSLATE (yychar);
1685 YYSIZE_T yysize0 = yytnamerr (0, yytname[yytype]);
1686 YYSIZE_T yysize = yysize0;
1688 int yysize_overflow = 0;
1689 enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
1690 char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
1694 /* This is so xgettext sees the translatable formats that are
1695 constructed on the fly. */
1696 YY_("syntax error, unexpected %s");
1697 YY_("syntax error, unexpected %s, expecting %s");
1698 YY_("syntax error, unexpected %s, expecting %s or %s");
1699 YY_("syntax error, unexpected %s, expecting %s or %s or %s");
1700 YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s");
1704 static char const yyunexpected[] = "syntax error, unexpected %s";
1705 static char const yyexpecting[] = ", expecting %s";
1706 static char const yyor[] = " or %s";
1707 char yyformat[sizeof yyunexpected
1708 + sizeof yyexpecting - 1
1709 + ((YYERROR_VERBOSE_ARGS_MAXIMUM - 2)
1710 * (sizeof yyor - 1))];
1711 char const *yyprefix = yyexpecting;
1713 /* Start YYX at -YYN if negative to avoid negative indexes in
1715 int yyxbegin = yyn < 0 ? -yyn : 0;
1717 /* Stay within bounds of both yycheck and yytname. */
1718 int yychecklim = YYLAST - yyn + 1;
1719 int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
1722 yyarg[0] = yytname[yytype];
1723 yyfmt = yystpcpy (yyformat, yyunexpected);
1725 for (yyx = yyxbegin; yyx < yyxend; ++yyx)
1726 if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
1728 if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
1732 yyformat[sizeof yyunexpected - 1] = '\0';
1735 yyarg[yycount++] = yytname[yyx];
1736 yysize1 = yysize + yytnamerr (0, yytname[yyx]);
1737 yysize_overflow |= (yysize1 < yysize);
1739 yyfmt = yystpcpy (yyfmt, yyprefix);
1743 yyf = YY_(yyformat);
1744 yysize1 = yysize + yystrlen (yyf);
1745 yysize_overflow |= (yysize1 < yysize);
1748 if (yysize_overflow)
1749 return YYSIZE_MAXIMUM;
1753 /* Avoid sprintf, as that infringes on the user's name space.
1754 Don't have undefined behavior even if the translation
1755 produced a string with the wrong number of "%s"s. */
1756 char *yyp = yyresult;
1758 while ((*yyp = *yyf) != '\0')
1760 if (*yyp == '%' && yyf[1] == 's' && yyi < yycount)
1762 yyp += yytnamerr (yyp, yyarg[yyi++]);
1775 #endif /* YYERROR_VERBOSE */
1778 /*-----------------------------------------------.
1779 | Release the memory associated to this symbol. |
1780 `-----------------------------------------------*/
1783 #if (defined __STDC__ || defined __C99__FUNC__ \
1784 || defined __cplusplus || defined _MSC_VER)
1786 yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep)
1789 yydestruct (yymsg, yytype, yyvaluep)
1799 YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
1810 /* Prevent warnings from -Wmissing-prototypes. */
1812 #ifdef YYPARSE_PARAM
1813 #if defined __STDC__ || defined __cplusplus
1814 int yyparse (void *YYPARSE_PARAM);
1818 #else /* ! YYPARSE_PARAM */
1819 #if defined __STDC__ || defined __cplusplus
1824 #endif /* ! YYPARSE_PARAM */
1828 /* The look-ahead symbol. */
1831 /* The semantic value of the look-ahead symbol. */
1834 /* Number of syntax errors so far. */
1843 #ifdef YYPARSE_PARAM
1844 #if (defined __STDC__ || defined __C99__FUNC__ \
1845 || defined __cplusplus || defined _MSC_VER)
1847 yyparse (void *YYPARSE_PARAM)
1850 yyparse (YYPARSE_PARAM)
1851 void *YYPARSE_PARAM;
1853 #else /* ! YYPARSE_PARAM */
1854 #if (defined __STDC__ || defined __C99__FUNC__ \
1855 || defined __cplusplus || defined _MSC_VER)
1869 /* Number of tokens to shift before error messages enabled. */
1871 /* Look-ahead token as an internal (translated) token number. */
1874 /* Buffer for error messages, and its allocated size. */
1876 char *yymsg = yymsgbuf;
1877 YYSIZE_T yymsg_alloc = sizeof yymsgbuf;
1880 /* Three stacks and their tools:
1881 `yyss': related to states,
1882 `yyvs': related to semantic values,
1883 `yyls': related to locations.
1885 Refer to the stacks thru separate pointers, to allow yyoverflow
1886 to reallocate them elsewhere. */
1888 /* The state stack. */
1889 yytype_int16 yyssa[YYINITDEPTH];
1890 yytype_int16 *yyss = yyssa;
1891 yytype_int16 *yyssp;
1893 /* The semantic value stack. */
1894 YYSTYPE yyvsa[YYINITDEPTH];
1895 YYSTYPE *yyvs = yyvsa;
1900 #define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N))
1902 YYSIZE_T yystacksize = YYINITDEPTH;
1904 /* The variables used to return semantic value and location from the
1909 /* The number of symbols on the RHS of the reduced rule.
1910 Keep to zero when no symbol should be popped. */
1913 YYDPRINTF ((stderr, "Starting parse\n"));
1918 yychar = YYEMPTY; /* Cause a token to be read. */
1920 /* Initialize stack pointers.
1921 Waste one element of value and location stack
1922 so that they stay on the same level as the state stack.
1923 The wasted elements are never initialized. */
1930 /*------------------------------------------------------------.
1931 | yynewstate -- Push a new state, which is found in yystate. |
1932 `------------------------------------------------------------*/
1934 /* In all cases, when you get here, the value and location stacks
1935 have just been pushed. So pushing a state here evens the stacks. */
1941 if (yyss + yystacksize - 1 <= yyssp)
1943 /* Get the current used size of the three stacks, in elements. */
1944 YYSIZE_T yysize = yyssp - yyss + 1;
1948 /* Give user a chance to reallocate the stack. Use copies of
1949 these so that the &'s don't force the real ones into
1951 YYSTYPE *yyvs1 = yyvs;
1952 yytype_int16 *yyss1 = yyss;
1955 /* Each stack pointer address is followed by the size of the
1956 data in use in that stack, in bytes. This used to be a
1957 conditional around just the two extra args, but that might
1958 be undefined if yyoverflow is a macro. */
1959 yyoverflow (YY_("memory exhausted"),
1960 &yyss1, yysize * sizeof (*yyssp),
1961 &yyvs1, yysize * sizeof (*yyvsp),
1968 #else /* no yyoverflow */
1969 # ifndef YYSTACK_RELOCATE
1970 goto yyexhaustedlab;
1972 /* Extend the stack our own way. */
1973 if (YYMAXDEPTH <= yystacksize)
1974 goto yyexhaustedlab;
1976 if (YYMAXDEPTH < yystacksize)
1977 yystacksize = YYMAXDEPTH;
1980 yytype_int16 *yyss1 = yyss;
1981 union yyalloc *yyptr =
1982 (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
1984 goto yyexhaustedlab;
1985 YYSTACK_RELOCATE (yyss);
1986 YYSTACK_RELOCATE (yyvs);
1988 # undef YYSTACK_RELOCATE
1990 YYSTACK_FREE (yyss1);
1993 #endif /* no yyoverflow */
1995 yyssp = yyss + yysize - 1;
1996 yyvsp = yyvs + yysize - 1;
1999 YYDPRINTF ((stderr, "Stack size increased to %lu\n",
2000 (unsigned long int) yystacksize));
2002 if (yyss + yystacksize - 1 <= yyssp)
2006 YYDPRINTF ((stderr, "Entering state %d\n", yystate));
2015 /* Do appropriate processing given the current state. Read a
2016 look-ahead token if we need one and don't already have one. */
2018 /* First try to decide what to do without reference to look-ahead token. */
2019 yyn = yypact[yystate];
2020 if (yyn == YYPACT_NINF)
2023 /* Not known => get a look-ahead token if don't already have one. */
2025 /* YYCHAR is either YYEMPTY or YYEOF or a valid look-ahead symbol. */
2026 if (yychar == YYEMPTY)
2028 YYDPRINTF ((stderr, "Reading a token: "));
2032 if (yychar <= YYEOF)
2034 yychar = yytoken = YYEOF;
2035 YYDPRINTF ((stderr, "Now at end of input.\n"));
2039 yytoken = YYTRANSLATE (yychar);
2040 YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
2043 /* If the proper action on seeing token YYTOKEN is to reduce or to
2044 detect an error, take that action. */
2046 if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
2051 if (yyn == 0 || yyn == YYTABLE_NINF)
2060 /* Count tokens shifted since error; after three, turn off error
2065 /* Shift the look-ahead token. */
2066 YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
2068 /* Discard the shifted token unless it is eof. */
2069 if (yychar != YYEOF)
2078 /*-----------------------------------------------------------.
2079 | yydefault -- do the default action for the current state. |
2080 `-----------------------------------------------------------*/
2082 yyn = yydefact[yystate];
2088 /*-----------------------------.
2089 | yyreduce -- Do a reduction. |
2090 `-----------------------------*/
2092 /* yyn is the number of a rule to reduce with. */
2095 /* If YYLEN is nonzero, implement the default value of the action:
2098 Otherwise, the following line sets YYVAL to garbage.
2099 This behavior is undocumented and Bison
2100 users should not rely upon it. Assigning to YYVAL
2101 unconditionally makes the parser a bit smaller, and it avoids a
2102 GCC warning that YYVAL may be used uninitialized. */
2103 yyval = yyvsp[1-yylen];
2106 YY_REDUCE_PRINT (yyn);
2110 #line 374 "/Users/chet/src/bash/src/parse.y"
2112 /* Case of regular command. Discard the error
2113 safety net,and return the command just parsed. */
2114 global_command = (yyvsp[(1) - (2)].command);
2115 eof_encountered = 0;
2116 /* discard_parser_constructs (0); */
2117 if (parser_state & PST_CMDSUBST)
2118 parser_state |= PST_EOFTOKEN;
2124 #line 385 "/Users/chet/src/bash/src/parse.y"
2126 /* Case of regular command, but not a very
2127 interesting one. Return a NULL command. */
2128 global_command = (COMMAND *)NULL;
2129 if (parser_state & PST_CMDSUBST)
2130 parser_state |= PST_EOFTOKEN;
2136 #line 394 "/Users/chet/src/bash/src/parse.y"
2138 /* Error during parsing. Return NULL command. */
2139 global_command = (COMMAND *)NULL;
2140 eof_encountered = 0;
2141 /* discard_parser_constructs (1); */
2142 if (interactive && parse_and_execute_level == 0)
2154 #line 409 "/Users/chet/src/bash/src/parse.y"
2156 /* Case of EOF seen by itself. Do ignoreeof or
2158 global_command = (COMMAND *)NULL;
2159 handle_eof_input_unit ();
2165 #line 419 "/Users/chet/src/bash/src/parse.y"
2166 { (yyval.word_list) = make_word_list ((yyvsp[(1) - (1)].word), (WORD_LIST *)NULL); }
2170 #line 421 "/Users/chet/src/bash/src/parse.y"
2171 { (yyval.word_list) = make_word_list ((yyvsp[(2) - (2)].word), (yyvsp[(1) - (2)].word_list)); }
2175 #line 425 "/Users/chet/src/bash/src/parse.y"
2178 redir.filename = (yyvsp[(2) - (2)].word);
2179 (yyval.redirect) = make_redirection (source, r_output_direction, redir, 0);
2184 #line 431 "/Users/chet/src/bash/src/parse.y"
2187 redir.filename = (yyvsp[(2) - (2)].word);
2188 (yyval.redirect) = make_redirection (source, r_input_direction, redir, 0);
2193 #line 437 "/Users/chet/src/bash/src/parse.y"
2195 source.dest = (yyvsp[(1) - (3)].number);
2196 redir.filename = (yyvsp[(3) - (3)].word);
2197 (yyval.redirect) = make_redirection (source, r_output_direction, redir, 0);
2202 #line 443 "/Users/chet/src/bash/src/parse.y"
2204 source.dest = (yyvsp[(1) - (3)].number);
2205 redir.filename = (yyvsp[(3) - (3)].word);
2206 (yyval.redirect) = make_redirection (source, r_input_direction, redir, 0);
2211 #line 449 "/Users/chet/src/bash/src/parse.y"
2213 source.filename = (yyvsp[(1) - (3)].word);
2214 redir.filename = (yyvsp[(3) - (3)].word);
2215 (yyval.redirect) = make_redirection (source, r_output_direction, redir, REDIR_VARASSIGN);
2220 #line 455 "/Users/chet/src/bash/src/parse.y"
2222 source.filename = (yyvsp[(1) - (3)].word);
2223 redir.filename = (yyvsp[(3) - (3)].word);
2224 (yyval.redirect) = make_redirection (source, r_input_direction, redir, REDIR_VARASSIGN);
2229 #line 461 "/Users/chet/src/bash/src/parse.y"
2232 redir.filename = (yyvsp[(2) - (2)].word);
2233 (yyval.redirect) = make_redirection (source, r_appending_to, redir, 0);
2238 #line 467 "/Users/chet/src/bash/src/parse.y"
2240 source.dest = (yyvsp[(1) - (3)].number);
2241 redir.filename = (yyvsp[(3) - (3)].word);
2242 (yyval.redirect) = make_redirection (source, r_appending_to, redir, 0);
2247 #line 473 "/Users/chet/src/bash/src/parse.y"
2249 source.filename = (yyvsp[(1) - (3)].word);
2250 redir.filename = (yyvsp[(3) - (3)].word);
2251 (yyval.redirect) = make_redirection (source, r_appending_to, redir, REDIR_VARASSIGN);
2256 #line 479 "/Users/chet/src/bash/src/parse.y"
2259 redir.filename = (yyvsp[(2) - (2)].word);
2260 (yyval.redirect) = make_redirection (source, r_output_force, redir, 0);
2265 #line 485 "/Users/chet/src/bash/src/parse.y"
2267 source.dest = (yyvsp[(1) - (3)].number);
2268 redir.filename = (yyvsp[(3) - (3)].word);
2269 (yyval.redirect) = make_redirection (source, r_output_force, redir, 0);
2274 #line 491 "/Users/chet/src/bash/src/parse.y"
2276 source.filename = (yyvsp[(1) - (3)].word);
2277 redir.filename = (yyvsp[(3) - (3)].word);
2278 (yyval.redirect) = make_redirection (source, r_output_force, redir, REDIR_VARASSIGN);
2283 #line 497 "/Users/chet/src/bash/src/parse.y"
2286 redir.filename = (yyvsp[(2) - (2)].word);
2287 (yyval.redirect) = make_redirection (source, r_input_output, redir, 0);
2292 #line 503 "/Users/chet/src/bash/src/parse.y"
2294 source.dest = (yyvsp[(1) - (3)].number);
2295 redir.filename = (yyvsp[(3) - (3)].word);
2296 (yyval.redirect) = make_redirection (source, r_input_output, redir, 0);
2301 #line 509 "/Users/chet/src/bash/src/parse.y"
2303 source.filename = (yyvsp[(1) - (3)].word);
2304 redir.filename = (yyvsp[(3) - (3)].word);
2305 (yyval.redirect) = make_redirection (source, r_input_output, redir, REDIR_VARASSIGN);
2310 #line 515 "/Users/chet/src/bash/src/parse.y"
2313 redir.filename = (yyvsp[(2) - (2)].word);
2314 (yyval.redirect) = make_redirection (source, r_reading_until, redir, 0);
2315 redir_stack[need_here_doc++] = (yyval.redirect);
2320 #line 522 "/Users/chet/src/bash/src/parse.y"
2322 source.dest = (yyvsp[(1) - (3)].number);
2323 redir.filename = (yyvsp[(3) - (3)].word);
2324 (yyval.redirect) = make_redirection (source, r_reading_until, redir, 0);
2325 redir_stack[need_here_doc++] = (yyval.redirect);
2330 #line 529 "/Users/chet/src/bash/src/parse.y"
2332 source.filename = (yyvsp[(1) - (3)].word);
2333 redir.filename = (yyvsp[(3) - (3)].word);
2334 (yyval.redirect) = make_redirection (source, r_reading_until, redir, REDIR_VARASSIGN);
2335 redir_stack[need_here_doc++] = (yyval.redirect);
2340 #line 536 "/Users/chet/src/bash/src/parse.y"
2343 redir.filename = (yyvsp[(2) - (2)].word);
2344 (yyval.redirect) = make_redirection (source, r_deblank_reading_until, redir, 0);
2345 redir_stack[need_here_doc++] = (yyval.redirect);
2350 #line 543 "/Users/chet/src/bash/src/parse.y"
2352 source.dest = (yyvsp[(1) - (3)].number);
2353 redir.filename = (yyvsp[(3) - (3)].word);
2354 (yyval.redirect) = make_redirection (source, r_deblank_reading_until, redir, 0);
2355 redir_stack[need_here_doc++] = (yyval.redirect);
2360 #line 550 "/Users/chet/src/bash/src/parse.y"
2362 source.filename = (yyvsp[(1) - (3)].word);
2363 redir.filename = (yyvsp[(3) - (3)].word);
2364 (yyval.redirect) = make_redirection (source, r_deblank_reading_until, redir, REDIR_VARASSIGN);
2365 redir_stack[need_here_doc++] = (yyval.redirect);
2370 #line 557 "/Users/chet/src/bash/src/parse.y"
2373 redir.filename = (yyvsp[(2) - (2)].word);
2374 (yyval.redirect) = make_redirection (source, r_reading_string, redir, 0);
2379 #line 563 "/Users/chet/src/bash/src/parse.y"
2381 source.dest = (yyvsp[(1) - (3)].number);
2382 redir.filename = (yyvsp[(3) - (3)].word);
2383 (yyval.redirect) = make_redirection (source, r_reading_string, redir, 0);
2388 #line 569 "/Users/chet/src/bash/src/parse.y"
2390 source.filename = (yyvsp[(1) - (3)].word);
2391 redir.filename = (yyvsp[(3) - (3)].word);
2392 (yyval.redirect) = make_redirection (source, r_reading_string, redir, REDIR_VARASSIGN);
2397 #line 575 "/Users/chet/src/bash/src/parse.y"
2400 redir.dest = (yyvsp[(2) - (2)].number);
2401 (yyval.redirect) = make_redirection (source, r_duplicating_input, redir, 0);
2406 #line 581 "/Users/chet/src/bash/src/parse.y"
2408 source.dest = (yyvsp[(1) - (3)].number);
2409 redir.dest = (yyvsp[(3) - (3)].number);
2410 (yyval.redirect) = make_redirection (source, r_duplicating_input, redir, 0);
2415 #line 587 "/Users/chet/src/bash/src/parse.y"
2417 source.filename = (yyvsp[(1) - (3)].word);
2418 redir.dest = (yyvsp[(3) - (3)].number);
2419 (yyval.redirect) = make_redirection (source, r_duplicating_input, redir, REDIR_VARASSIGN);
2424 #line 593 "/Users/chet/src/bash/src/parse.y"
2427 redir.dest = (yyvsp[(2) - (2)].number);
2428 (yyval.redirect) = make_redirection (source, r_duplicating_output, redir, 0);
2433 #line 599 "/Users/chet/src/bash/src/parse.y"
2435 source.dest = (yyvsp[(1) - (3)].number);
2436 redir.dest = (yyvsp[(3) - (3)].number);
2437 (yyval.redirect) = make_redirection (source, r_duplicating_output, redir, 0);
2442 #line 605 "/Users/chet/src/bash/src/parse.y"
2444 source.filename = (yyvsp[(1) - (3)].word);
2445 redir.dest = (yyvsp[(3) - (3)].number);
2446 (yyval.redirect) = make_redirection (source, r_duplicating_output, redir, REDIR_VARASSIGN);
2451 #line 611 "/Users/chet/src/bash/src/parse.y"
2454 redir.filename = (yyvsp[(2) - (2)].word);
2455 (yyval.redirect) = make_redirection (source, r_duplicating_input_word, redir, 0);
2460 #line 617 "/Users/chet/src/bash/src/parse.y"
2462 source.dest = (yyvsp[(1) - (3)].number);
2463 redir.filename = (yyvsp[(3) - (3)].word);
2464 (yyval.redirect) = make_redirection (source, r_duplicating_input_word, redir, 0);
2469 #line 623 "/Users/chet/src/bash/src/parse.y"
2471 source.filename = (yyvsp[(1) - (3)].word);
2472 redir.filename = (yyvsp[(3) - (3)].word);
2473 (yyval.redirect) = make_redirection (source, r_duplicating_input_word, redir, REDIR_VARASSIGN);
2478 #line 629 "/Users/chet/src/bash/src/parse.y"
2481 redir.filename = (yyvsp[(2) - (2)].word);
2482 (yyval.redirect) = make_redirection (source, r_duplicating_output_word, redir, 0);
2487 #line 635 "/Users/chet/src/bash/src/parse.y"
2489 source.dest = (yyvsp[(1) - (3)].number);
2490 redir.filename = (yyvsp[(3) - (3)].word);
2491 (yyval.redirect) = make_redirection (source, r_duplicating_output_word, redir, 0);
2496 #line 641 "/Users/chet/src/bash/src/parse.y"
2498 source.filename = (yyvsp[(1) - (3)].word);
2499 redir.filename = (yyvsp[(3) - (3)].word);
2500 (yyval.redirect) = make_redirection (source, r_duplicating_output_word, redir, REDIR_VARASSIGN);
2505 #line 647 "/Users/chet/src/bash/src/parse.y"
2509 (yyval.redirect) = make_redirection (source, r_close_this, redir, 0);
2514 #line 653 "/Users/chet/src/bash/src/parse.y"
2516 source.dest = (yyvsp[(1) - (3)].number);
2518 (yyval.redirect) = make_redirection (source, r_close_this, redir, 0);
2523 #line 659 "/Users/chet/src/bash/src/parse.y"
2525 source.filename = (yyvsp[(1) - (3)].word);
2527 (yyval.redirect) = make_redirection (source, r_close_this, redir, REDIR_VARASSIGN);
2532 #line 665 "/Users/chet/src/bash/src/parse.y"
2536 (yyval.redirect) = make_redirection (source, r_close_this, redir, 0);
2541 #line 671 "/Users/chet/src/bash/src/parse.y"
2543 source.dest = (yyvsp[(1) - (3)].number);
2545 (yyval.redirect) = make_redirection (source, r_close_this, redir, 0);
2550 #line 677 "/Users/chet/src/bash/src/parse.y"
2552 source.filename = (yyvsp[(1) - (3)].word);
2554 (yyval.redirect) = make_redirection (source, r_close_this, redir, REDIR_VARASSIGN);
2559 #line 683 "/Users/chet/src/bash/src/parse.y"
2562 redir.filename = (yyvsp[(2) - (2)].word);
2563 (yyval.redirect) = make_redirection (source, r_err_and_out, redir, 0);
2568 #line 689 "/Users/chet/src/bash/src/parse.y"
2571 redir.filename = (yyvsp[(2) - (2)].word);
2572 (yyval.redirect) = make_redirection (source, r_append_err_and_out, redir, 0);
2577 #line 697 "/Users/chet/src/bash/src/parse.y"
2578 { (yyval.element).word = (yyvsp[(1) - (1)].word); (yyval.element).redirect = 0; }
2582 #line 699 "/Users/chet/src/bash/src/parse.y"
2583 { (yyval.element).word = (yyvsp[(1) - (1)].word); (yyval.element).redirect = 0; }
2587 #line 701 "/Users/chet/src/bash/src/parse.y"
2588 { (yyval.element).redirect = (yyvsp[(1) - (1)].redirect); (yyval.element).word = 0; }
2592 #line 705 "/Users/chet/src/bash/src/parse.y"
2594 (yyval.redirect) = (yyvsp[(1) - (1)].redirect);
2599 #line 709 "/Users/chet/src/bash/src/parse.y"
2601 register REDIRECT *t;
2603 for (t = (yyvsp[(1) - (2)].redirect); t->next; t = t->next)
2605 t->next = (yyvsp[(2) - (2)].redirect);
2606 (yyval.redirect) = (yyvsp[(1) - (2)].redirect);
2611 #line 720 "/Users/chet/src/bash/src/parse.y"
2612 { (yyval.command) = make_simple_command ((yyvsp[(1) - (1)].element), (COMMAND *)NULL); }
2616 #line 722 "/Users/chet/src/bash/src/parse.y"
2617 { (yyval.command) = make_simple_command ((yyvsp[(2) - (2)].element), (yyvsp[(1) - (2)].command)); }
2621 #line 726 "/Users/chet/src/bash/src/parse.y"
2622 { (yyval.command) = clean_simple_command ((yyvsp[(1) - (1)].command)); }
2626 #line 728 "/Users/chet/src/bash/src/parse.y"
2627 { (yyval.command) = (yyvsp[(1) - (1)].command); }
2631 #line 730 "/Users/chet/src/bash/src/parse.y"
2635 tc = (yyvsp[(1) - (2)].command);
2638 register REDIRECT *t;
2639 for (t = tc->redirects; t->next; t = t->next)
2641 t->next = (yyvsp[(2) - (2)].redirect);
2644 tc->redirects = (yyvsp[(2) - (2)].redirect);
2645 (yyval.command) = (yyvsp[(1) - (2)].command);
2650 #line 746 "/Users/chet/src/bash/src/parse.y"
2651 { (yyval.command) = (yyvsp[(1) - (1)].command); }
2655 #line 748 "/Users/chet/src/bash/src/parse.y"
2656 { (yyval.command) = (yyvsp[(1) - (1)].command); }
2660 #line 752 "/Users/chet/src/bash/src/parse.y"
2661 { (yyval.command) = (yyvsp[(1) - (1)].command); }
2665 #line 754 "/Users/chet/src/bash/src/parse.y"
2666 { (yyval.command) = (yyvsp[(1) - (1)].command); }
2670 #line 756 "/Users/chet/src/bash/src/parse.y"
2671 { (yyval.command) = make_while_command ((yyvsp[(2) - (5)].command), (yyvsp[(4) - (5)].command)); }
2675 #line 758 "/Users/chet/src/bash/src/parse.y"
2676 { (yyval.command) = make_until_command ((yyvsp[(2) - (5)].command), (yyvsp[(4) - (5)].command)); }
2680 #line 760 "/Users/chet/src/bash/src/parse.y"
2681 { (yyval.command) = (yyvsp[(1) - (1)].command); }
2685 #line 762 "/Users/chet/src/bash/src/parse.y"
2686 { (yyval.command) = (yyvsp[(1) - (1)].command); }
2690 #line 764 "/Users/chet/src/bash/src/parse.y"
2691 { (yyval.command) = (yyvsp[(1) - (1)].command); }
2695 #line 766 "/Users/chet/src/bash/src/parse.y"
2696 { (yyval.command) = (yyvsp[(1) - (1)].command); }
2700 #line 768 "/Users/chet/src/bash/src/parse.y"
2701 { (yyval.command) = (yyvsp[(1) - (1)].command); }
2705 #line 770 "/Users/chet/src/bash/src/parse.y"
2706 { (yyval.command) = (yyvsp[(1) - (1)].command); }
2710 #line 772 "/Users/chet/src/bash/src/parse.y"
2711 { (yyval.command) = (yyvsp[(1) - (1)].command); }
2715 #line 776 "/Users/chet/src/bash/src/parse.y"
2717 (yyval.command) = make_for_command ((yyvsp[(2) - (6)].word), add_string_to_list ("\"$@\"", (WORD_LIST *)NULL), (yyvsp[(5) - (6)].command), word_lineno[word_top]);
2718 if (word_top > 0) word_top--;
2723 #line 781 "/Users/chet/src/bash/src/parse.y"
2725 (yyval.command) = make_for_command ((yyvsp[(2) - (6)].word), add_string_to_list ("\"$@\"", (WORD_LIST *)NULL), (yyvsp[(5) - (6)].command), word_lineno[word_top]);
2726 if (word_top > 0) word_top--;
2731 #line 786 "/Users/chet/src/bash/src/parse.y"
2733 (yyval.command) = make_for_command ((yyvsp[(2) - (7)].word), add_string_to_list ("\"$@\"", (WORD_LIST *)NULL), (yyvsp[(6) - (7)].command), word_lineno[word_top]);
2734 if (word_top > 0) word_top--;
2739 #line 791 "/Users/chet/src/bash/src/parse.y"
2741 (yyval.command) = make_for_command ((yyvsp[(2) - (7)].word), add_string_to_list ("\"$@\"", (WORD_LIST *)NULL), (yyvsp[(6) - (7)].command), word_lineno[word_top]);
2742 if (word_top > 0) word_top--;
2747 #line 796 "/Users/chet/src/bash/src/parse.y"
2749 (yyval.command) = make_for_command ((yyvsp[(2) - (10)].word), REVERSE_LIST ((yyvsp[(5) - (10)].word_list), WORD_LIST *), (yyvsp[(9) - (10)].command), word_lineno[word_top]);
2750 if (word_top > 0) word_top--;
2755 #line 801 "/Users/chet/src/bash/src/parse.y"
2757 (yyval.command) = make_for_command ((yyvsp[(2) - (10)].word), REVERSE_LIST ((yyvsp[(5) - (10)].word_list), WORD_LIST *), (yyvsp[(9) - (10)].command), word_lineno[word_top]);
2758 if (word_top > 0) word_top--;
2763 #line 806 "/Users/chet/src/bash/src/parse.y"
2765 (yyval.command) = make_for_command ((yyvsp[(2) - (9)].word), (WORD_LIST *)NULL, (yyvsp[(8) - (9)].command), word_lineno[word_top]);
2766 if (word_top > 0) word_top--;
2771 #line 811 "/Users/chet/src/bash/src/parse.y"
2773 (yyval.command) = make_for_command ((yyvsp[(2) - (9)].word), (WORD_LIST *)NULL, (yyvsp[(8) - (9)].command), word_lineno[word_top]);
2774 if (word_top > 0) word_top--;
2779 #line 818 "/Users/chet/src/bash/src/parse.y"
2781 (yyval.command) = make_arith_for_command ((yyvsp[(2) - (7)].word_list), (yyvsp[(6) - (7)].command), arith_for_lineno);
2782 if (word_top > 0) word_top--;
2787 #line 823 "/Users/chet/src/bash/src/parse.y"
2789 (yyval.command) = make_arith_for_command ((yyvsp[(2) - (7)].word_list), (yyvsp[(6) - (7)].command), arith_for_lineno);
2790 if (word_top > 0) word_top--;
2795 #line 828 "/Users/chet/src/bash/src/parse.y"
2797 (yyval.command) = make_arith_for_command ((yyvsp[(2) - (5)].word_list), (yyvsp[(4) - (5)].command), arith_for_lineno);
2798 if (word_top > 0) word_top--;
2803 #line 833 "/Users/chet/src/bash/src/parse.y"
2805 (yyval.command) = make_arith_for_command ((yyvsp[(2) - (5)].word_list), (yyvsp[(4) - (5)].command), arith_for_lineno);
2806 if (word_top > 0) word_top--;
2811 #line 840 "/Users/chet/src/bash/src/parse.y"
2813 (yyval.command) = make_select_command ((yyvsp[(2) - (6)].word), add_string_to_list ("\"$@\"", (WORD_LIST *)NULL), (yyvsp[(5) - (6)].command), word_lineno[word_top]);
2814 if (word_top > 0) word_top--;
2819 #line 845 "/Users/chet/src/bash/src/parse.y"
2821 (yyval.command) = make_select_command ((yyvsp[(2) - (6)].word), add_string_to_list ("\"$@\"", (WORD_LIST *)NULL), (yyvsp[(5) - (6)].command), word_lineno[word_top]);
2822 if (word_top > 0) word_top--;
2827 #line 850 "/Users/chet/src/bash/src/parse.y"
2829 (yyval.command) = make_select_command ((yyvsp[(2) - (7)].word), add_string_to_list ("\"$@\"", (WORD_LIST *)NULL), (yyvsp[(6) - (7)].command), word_lineno[word_top]);
2830 if (word_top > 0) word_top--;
2835 #line 855 "/Users/chet/src/bash/src/parse.y"
2837 (yyval.command) = make_select_command ((yyvsp[(2) - (7)].word), add_string_to_list ("\"$@\"", (WORD_LIST *)NULL), (yyvsp[(6) - (7)].command), word_lineno[word_top]);
2838 if (word_top > 0) word_top--;
2843 #line 860 "/Users/chet/src/bash/src/parse.y"
2845 (yyval.command) = make_select_command ((yyvsp[(2) - (10)].word), REVERSE_LIST ((yyvsp[(5) - (10)].word_list), WORD_LIST *), (yyvsp[(9) - (10)].command), word_lineno[word_top]);
2846 if (word_top > 0) word_top--;
2851 #line 865 "/Users/chet/src/bash/src/parse.y"
2853 (yyval.command) = make_select_command ((yyvsp[(2) - (10)].word), REVERSE_LIST ((yyvsp[(5) - (10)].word_list), WORD_LIST *), (yyvsp[(9) - (10)].command), word_lineno[word_top]);
2854 if (word_top > 0) word_top--;
2859 #line 872 "/Users/chet/src/bash/src/parse.y"
2861 (yyval.command) = make_case_command ((yyvsp[(2) - (6)].word), (PATTERN_LIST *)NULL, word_lineno[word_top]);
2862 if (word_top > 0) word_top--;
2867 #line 877 "/Users/chet/src/bash/src/parse.y"
2869 (yyval.command) = make_case_command ((yyvsp[(2) - (7)].word), (yyvsp[(5) - (7)].pattern), word_lineno[word_top]);
2870 if (word_top > 0) word_top--;
2875 #line 882 "/Users/chet/src/bash/src/parse.y"
2877 (yyval.command) = make_case_command ((yyvsp[(2) - (6)].word), (yyvsp[(5) - (6)].pattern), word_lineno[word_top]);
2878 if (word_top > 0) word_top--;
2883 #line 889 "/Users/chet/src/bash/src/parse.y"
2884 { (yyval.command) = make_function_def ((yyvsp[(1) - (5)].word), (yyvsp[(5) - (5)].command), function_dstart, function_bstart); }
2888 #line 892 "/Users/chet/src/bash/src/parse.y"
2889 { (yyval.command) = make_function_def ((yyvsp[(2) - (6)].word), (yyvsp[(6) - (6)].command), function_dstart, function_bstart); }
2893 #line 895 "/Users/chet/src/bash/src/parse.y"
2894 { (yyval.command) = make_function_def ((yyvsp[(2) - (4)].word), (yyvsp[(4) - (4)].command), function_dstart, function_bstart); }
2898 #line 899 "/Users/chet/src/bash/src/parse.y"
2899 { (yyval.command) = (yyvsp[(1) - (1)].command); }
2903 #line 901 "/Users/chet/src/bash/src/parse.y"
2907 tc = (yyvsp[(1) - (2)].command);
2908 /* According to Posix.2 3.9.5, redirections
2909 specified after the body of a function should
2910 be attached to the function and performed when
2911 the function is executed, not as part of the
2912 function definition command. */
2913 /* XXX - I don't think it matters, but we might
2914 want to change this in the future to avoid
2915 problems differentiating between a function
2916 definition with a redirection and a function
2917 definition containing a single command with a
2918 redirection. The two are semantically equivalent,
2919 though -- the only difference is in how the
2920 command printing code displays the redirections. */
2923 register REDIRECT *t;
2924 for (t = tc->redirects; t->next; t = t->next)
2926 t->next = (yyvsp[(2) - (2)].redirect);
2929 tc->redirects = (yyvsp[(2) - (2)].redirect);
2930 (yyval.command) = (yyvsp[(1) - (2)].command);
2935 #line 932 "/Users/chet/src/bash/src/parse.y"
2937 (yyval.command) = make_subshell_command ((yyvsp[(2) - (3)].command));
2938 (yyval.command)->flags |= CMD_WANT_SUBSHELL;
2943 #line 939 "/Users/chet/src/bash/src/parse.y"
2945 (yyval.command) = make_coproc_command ("COPROC", (yyvsp[(2) - (2)].command));
2946 (yyval.command)->flags |= CMD_WANT_SUBSHELL|CMD_COPROC_SUBSHELL;
2951 #line 944 "/Users/chet/src/bash/src/parse.y"
2955 tc = (yyvsp[(2) - (3)].command);
2958 register REDIRECT *t;
2959 for (t = tc->redirects; t->next; t = t->next)
2961 t->next = (yyvsp[(3) - (3)].redirect);
2964 tc->redirects = (yyvsp[(3) - (3)].redirect);
2965 (yyval.command) = make_coproc_command ("COPROC", (yyvsp[(2) - (3)].command));
2966 (yyval.command)->flags |= CMD_WANT_SUBSHELL|CMD_COPROC_SUBSHELL;
2971 #line 961 "/Users/chet/src/bash/src/parse.y"
2973 (yyval.command) = make_coproc_command ((yyvsp[(2) - (3)].word)->word, (yyvsp[(3) - (3)].command));
2974 (yyval.command)->flags |= CMD_WANT_SUBSHELL|CMD_COPROC_SUBSHELL;
2979 #line 966 "/Users/chet/src/bash/src/parse.y"
2983 tc = (yyvsp[(3) - (4)].command);
2986 register REDIRECT *t;
2987 for (t = tc->redirects; t->next; t = t->next)
2989 t->next = (yyvsp[(4) - (4)].redirect);
2992 tc->redirects = (yyvsp[(4) - (4)].redirect);
2993 (yyval.command) = make_coproc_command ((yyvsp[(2) - (4)].word)->word, (yyvsp[(3) - (4)].command));
2994 (yyval.command)->flags |= CMD_WANT_SUBSHELL|CMD_COPROC_SUBSHELL;
2999 #line 983 "/Users/chet/src/bash/src/parse.y"
3001 (yyval.command) = make_coproc_command ("COPROC", clean_simple_command ((yyvsp[(2) - (2)].command)));
3002 (yyval.command)->flags |= CMD_WANT_SUBSHELL|CMD_COPROC_SUBSHELL;
3007 #line 990 "/Users/chet/src/bash/src/parse.y"
3008 { (yyval.command) = make_if_command ((yyvsp[(2) - (5)].command), (yyvsp[(4) - (5)].command), (COMMAND *)NULL); }
3012 #line 992 "/Users/chet/src/bash/src/parse.y"
3013 { (yyval.command) = make_if_command ((yyvsp[(2) - (7)].command), (yyvsp[(4) - (7)].command), (yyvsp[(6) - (7)].command)); }
3017 #line 994 "/Users/chet/src/bash/src/parse.y"
3018 { (yyval.command) = make_if_command ((yyvsp[(2) - (6)].command), (yyvsp[(4) - (6)].command), (yyvsp[(5) - (6)].command)); }
3022 #line 999 "/Users/chet/src/bash/src/parse.y"
3023 { (yyval.command) = make_group_command ((yyvsp[(2) - (3)].command)); }
3027 #line 1003 "/Users/chet/src/bash/src/parse.y"
3028 { (yyval.command) = make_arith_command ((yyvsp[(1) - (1)].word_list)); }
3032 #line 1007 "/Users/chet/src/bash/src/parse.y"
3033 { (yyval.command) = (yyvsp[(2) - (3)].command); }
3037 #line 1011 "/Users/chet/src/bash/src/parse.y"
3038 { (yyval.command) = make_if_command ((yyvsp[(2) - (4)].command), (yyvsp[(4) - (4)].command), (COMMAND *)NULL); }
3042 #line 1013 "/Users/chet/src/bash/src/parse.y"
3043 { (yyval.command) = make_if_command ((yyvsp[(2) - (6)].command), (yyvsp[(4) - (6)].command), (yyvsp[(6) - (6)].command)); }
3047 #line 1015 "/Users/chet/src/bash/src/parse.y"
3048 { (yyval.command) = make_if_command ((yyvsp[(2) - (5)].command), (yyvsp[(4) - (5)].command), (yyvsp[(5) - (5)].command)); }
3052 #line 1020 "/Users/chet/src/bash/src/parse.y"
3053 { (yyvsp[(2) - (2)].pattern)->next = (yyvsp[(1) - (2)].pattern); (yyval.pattern) = (yyvsp[(2) - (2)].pattern); }
3057 #line 1024 "/Users/chet/src/bash/src/parse.y"
3058 { (yyval.pattern) = make_pattern_list ((yyvsp[(2) - (4)].word_list), (yyvsp[(4) - (4)].command)); }
3062 #line 1026 "/Users/chet/src/bash/src/parse.y"
3063 { (yyval.pattern) = make_pattern_list ((yyvsp[(2) - (4)].word_list), (COMMAND *)NULL); }
3067 #line 1028 "/Users/chet/src/bash/src/parse.y"
3068 { (yyval.pattern) = make_pattern_list ((yyvsp[(3) - (5)].word_list), (yyvsp[(5) - (5)].command)); }
3072 #line 1030 "/Users/chet/src/bash/src/parse.y"
3073 { (yyval.pattern) = make_pattern_list ((yyvsp[(3) - (5)].word_list), (COMMAND *)NULL); }
3077 #line 1034 "/Users/chet/src/bash/src/parse.y"
3078 { (yyval.pattern) = (yyvsp[(1) - (2)].pattern); }
3082 #line 1036 "/Users/chet/src/bash/src/parse.y"
3083 { (yyvsp[(2) - (3)].pattern)->next = (yyvsp[(1) - (3)].pattern); (yyval.pattern) = (yyvsp[(2) - (3)].pattern); }
3087 #line 1038 "/Users/chet/src/bash/src/parse.y"
3088 { (yyvsp[(1) - (2)].pattern)->flags |= CASEPAT_FALLTHROUGH; (yyval.pattern) = (yyvsp[(1) - (2)].pattern); }
3092 #line 1040 "/Users/chet/src/bash/src/parse.y"
3093 { (yyvsp[(2) - (3)].pattern)->flags |= CASEPAT_FALLTHROUGH; (yyvsp[(2) - (3)].pattern)->next = (yyvsp[(1) - (3)].pattern); (yyval.pattern) = (yyvsp[(2) - (3)].pattern); }
3097 #line 1042 "/Users/chet/src/bash/src/parse.y"
3098 { (yyvsp[(1) - (2)].pattern)->flags |= CASEPAT_TESTNEXT; (yyval.pattern) = (yyvsp[(1) - (2)].pattern); }
3102 #line 1044 "/Users/chet/src/bash/src/parse.y"
3103 { (yyvsp[(2) - (3)].pattern)->flags |= CASEPAT_TESTNEXT; (yyvsp[(2) - (3)].pattern)->next = (yyvsp[(1) - (3)].pattern); (yyval.pattern) = (yyvsp[(2) - (3)].pattern); }
3107 #line 1048 "/Users/chet/src/bash/src/parse.y"
3108 { (yyval.word_list) = make_word_list ((yyvsp[(1) - (1)].word), (WORD_LIST *)NULL); }
3112 #line 1050 "/Users/chet/src/bash/src/parse.y"
3113 { (yyval.word_list) = make_word_list ((yyvsp[(3) - (3)].word), (yyvsp[(1) - (3)].word_list)); }
3117 #line 1059 "/Users/chet/src/bash/src/parse.y"
3119 (yyval.command) = (yyvsp[(2) - (2)].command);
3121 gather_here_documents ();
3126 #line 1068 "/Users/chet/src/bash/src/parse.y"
3128 (yyval.command) = (yyvsp[(2) - (2)].command);
3133 #line 1075 "/Users/chet/src/bash/src/parse.y"
3135 if ((yyvsp[(1) - (3)].command)->type == cm_connection)
3136 (yyval.command) = connect_async_list ((yyvsp[(1) - (3)].command), (COMMAND *)NULL, '&');
3138 (yyval.command) = command_connect ((yyvsp[(1) - (3)].command), (COMMAND *)NULL, '&');
3143 #line 1086 "/Users/chet/src/bash/src/parse.y"
3144 { (yyval.command) = command_connect ((yyvsp[(1) - (4)].command), (yyvsp[(4) - (4)].command), AND_AND); }
3148 #line 1088 "/Users/chet/src/bash/src/parse.y"
3149 { (yyval.command) = command_connect ((yyvsp[(1) - (4)].command), (yyvsp[(4) - (4)].command), OR_OR); }
3153 #line 1090 "/Users/chet/src/bash/src/parse.y"
3155 if ((yyvsp[(1) - (4)].command)->type == cm_connection)
3156 (yyval.command) = connect_async_list ((yyvsp[(1) - (4)].command), (yyvsp[(4) - (4)].command), '&');
3158 (yyval.command) = command_connect ((yyvsp[(1) - (4)].command), (yyvsp[(4) - (4)].command), '&');
3163 #line 1097 "/Users/chet/src/bash/src/parse.y"
3164 { (yyval.command) = command_connect ((yyvsp[(1) - (4)].command), (yyvsp[(4) - (4)].command), ';'); }
3168 #line 1099 "/Users/chet/src/bash/src/parse.y"
3169 { (yyval.command) = command_connect ((yyvsp[(1) - (4)].command), (yyvsp[(4) - (4)].command), ';'); }
3173 #line 1101 "/Users/chet/src/bash/src/parse.y"
3174 { (yyval.command) = (yyvsp[(1) - (1)].command); }
3178 #line 1109 "/Users/chet/src/bash/src/parse.y"
3179 { (yyval.number) = '\n'; }
3183 #line 1111 "/Users/chet/src/bash/src/parse.y"
3184 { (yyval.number) = ';'; }
3188 #line 1113 "/Users/chet/src/bash/src/parse.y"
3189 { (yyval.number) = yacc_EOF; }
3193 #line 1127 "/Users/chet/src/bash/src/parse.y"
3195 (yyval.command) = (yyvsp[(1) - (1)].command);
3197 gather_here_documents ();
3198 if ((parser_state & PST_CMDSUBST) && current_token == shell_eof_token)
3200 global_command = (yyvsp[(1) - (1)].command);
3201 eof_encountered = 0;
3202 rewind_input_string ();
3209 #line 1140 "/Users/chet/src/bash/src/parse.y"
3211 if ((yyvsp[(1) - (2)].command)->type == cm_connection)
3212 (yyval.command) = connect_async_list ((yyvsp[(1) - (2)].command), (COMMAND *)NULL, '&');
3214 (yyval.command) = command_connect ((yyvsp[(1) - (2)].command), (COMMAND *)NULL, '&');
3216 gather_here_documents ();
3217 if ((parser_state & PST_CMDSUBST) && current_token == shell_eof_token)
3219 global_command = (yyvsp[(1) - (2)].command);
3220 eof_encountered = 0;
3221 rewind_input_string ();
3228 #line 1156 "/Users/chet/src/bash/src/parse.y"
3230 (yyval.command) = (yyvsp[(1) - (2)].command);
3232 gather_here_documents ();
3233 if ((parser_state & PST_CMDSUBST) && current_token == shell_eof_token)
3235 global_command = (yyvsp[(1) - (2)].command);
3236 eof_encountered = 0;
3237 rewind_input_string ();
3244 #line 1171 "/Users/chet/src/bash/src/parse.y"
3245 { (yyval.command) = command_connect ((yyvsp[(1) - (4)].command), (yyvsp[(4) - (4)].command), AND_AND); }
3249 #line 1173 "/Users/chet/src/bash/src/parse.y"
3250 { (yyval.command) = command_connect ((yyvsp[(1) - (4)].command), (yyvsp[(4) - (4)].command), OR_OR); }
3254 #line 1175 "/Users/chet/src/bash/src/parse.y"
3256 if ((yyvsp[(1) - (3)].command)->type == cm_connection)
3257 (yyval.command) = connect_async_list ((yyvsp[(1) - (3)].command), (yyvsp[(3) - (3)].command), '&');
3259 (yyval.command) = command_connect ((yyvsp[(1) - (3)].command), (yyvsp[(3) - (3)].command), '&');
3264 #line 1182 "/Users/chet/src/bash/src/parse.y"
3265 { (yyval.command) = command_connect ((yyvsp[(1) - (3)].command), (yyvsp[(3) - (3)].command), ';'); }
3269 #line 1185 "/Users/chet/src/bash/src/parse.y"
3270 { (yyval.command) = (yyvsp[(1) - (1)].command); }
3274 #line 1189 "/Users/chet/src/bash/src/parse.y"
3275 { (yyval.command) = (yyvsp[(1) - (1)].command); }
3279 #line 1191 "/Users/chet/src/bash/src/parse.y"
3281 if ((yyvsp[(2) - (2)].command))
3282 (yyvsp[(2) - (2)].command)->flags |= CMD_INVERT_RETURN;
3283 (yyval.command) = (yyvsp[(2) - (2)].command);
3288 #line 1197 "/Users/chet/src/bash/src/parse.y"
3290 if ((yyvsp[(2) - (2)].command))
3291 (yyvsp[(2) - (2)].command)->flags |= (yyvsp[(1) - (2)].number);
3292 (yyval.command) = (yyvsp[(2) - (2)].command);
3297 #line 1203 "/Users/chet/src/bash/src/parse.y"
3299 if ((yyvsp[(3) - (3)].command))
3300 (yyvsp[(3) - (3)].command)->flags |= (yyvsp[(1) - (3)].number)|CMD_INVERT_RETURN;
3301 (yyval.command) = (yyvsp[(3) - (3)].command);
3306 #line 1209 "/Users/chet/src/bash/src/parse.y"
3308 if ((yyvsp[(3) - (3)].command))
3309 (yyvsp[(3) - (3)].command)->flags |= (yyvsp[(2) - (3)].number)|CMD_INVERT_RETURN;
3310 (yyval.command) = (yyvsp[(3) - (3)].command);
3315 #line 1215 "/Users/chet/src/bash/src/parse.y"
3319 /* Boy, this is unclean. `time' by itself can
3320 time a null command. We cheat and push a
3321 newline back if the list_terminator was a newline
3322 to avoid the double-newline problem (one to
3323 terminate this, one to terminate the command) */
3326 (yyval.command) = make_simple_command (x, (COMMAND *)NULL);
3327 (yyval.command)->flags |= (yyvsp[(1) - (2)].number);
3328 /* XXX - let's cheat and push a newline back */
3329 if ((yyvsp[(2) - (2)].number) == '\n')
3330 token_to_read = '\n';
3335 #line 1235 "/Users/chet/src/bash/src/parse.y"
3336 { (yyval.command) = command_connect ((yyvsp[(1) - (4)].command), (yyvsp[(4) - (4)].command), '|'); }
3340 #line 1237 "/Users/chet/src/bash/src/parse.y"
3342 /* Make cmd1 |& cmd2 equivalent to cmd1 2>&1 | cmd2 */
3347 tc = (yyvsp[(1) - (4)].command)->type == cm_simple ? (COMMAND *)(yyvsp[(1) - (4)].command)->value.Simple : (yyvsp[(1) - (4)].command);
3350 r = make_redirection (sd, r_duplicating_output, rd, 0);
3353 register REDIRECT *t;
3354 for (t = tc->redirects; t->next; t = t->next)
3361 (yyval.command) = command_connect ((yyvsp[(1) - (4)].command), (yyvsp[(4) - (4)].command), '|');
3366 #line 1260 "/Users/chet/src/bash/src/parse.y"
3367 { (yyval.command) = (yyvsp[(1) - (1)].command); }
3371 #line 1264 "/Users/chet/src/bash/src/parse.y"
3372 { (yyval.number) = CMD_TIME_PIPELINE; }
3376 #line 1266 "/Users/chet/src/bash/src/parse.y"
3377 { (yyval.number) = CMD_TIME_PIPELINE|CMD_TIME_POSIX; }
3381 /* Line 1267 of yacc.c. */
3382 #line 3383 "y.tab.c"
3385 YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc);
3389 YY_STACK_PRINT (yyss, yyssp);
3394 /* Now `shift' the result of the reduction. Determine what state
3395 that goes to, based on the state we popped back to and the rule
3396 number reduced by. */
3400 yystate = yypgoto[yyn - YYNTOKENS] + *yyssp;
3401 if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp)
3402 yystate = yytable[yystate];
3404 yystate = yydefgoto[yyn - YYNTOKENS];
3409 /*------------------------------------.
3410 | yyerrlab -- here on detecting error |
3411 `------------------------------------*/
3413 /* If not already recovering from an error, report this error. */
3417 #if ! YYERROR_VERBOSE
3418 yyerror (YY_("syntax error"));
3421 YYSIZE_T yysize = yysyntax_error (0, yystate, yychar);
3422 if (yymsg_alloc < yysize && yymsg_alloc < YYSTACK_ALLOC_MAXIMUM)
3424 YYSIZE_T yyalloc = 2 * yysize;
3425 if (! (yysize <= yyalloc && yyalloc <= YYSTACK_ALLOC_MAXIMUM))
3426 yyalloc = YYSTACK_ALLOC_MAXIMUM;
3427 if (yymsg != yymsgbuf)
3428 YYSTACK_FREE (yymsg);
3429 yymsg = (char *) YYSTACK_ALLOC (yyalloc);
3431 yymsg_alloc = yyalloc;
3435 yymsg_alloc = sizeof yymsgbuf;
3439 if (0 < yysize && yysize <= yymsg_alloc)
3441 (void) yysyntax_error (yymsg, yystate, yychar);
3446 yyerror (YY_("syntax error"));
3448 goto yyexhaustedlab;
3456 if (yyerrstatus == 3)
3458 /* If just tried and failed to reuse look-ahead token after an
3459 error, discard it. */
3461 if (yychar <= YYEOF)
3463 /* Return failure if at end of input. */
3464 if (yychar == YYEOF)
3469 yydestruct ("Error: discarding",
3475 /* Else will try to reuse look-ahead token after shifting the error
3480 /*---------------------------------------------------.
3481 | yyerrorlab -- error raised explicitly by YYERROR. |
3482 `---------------------------------------------------*/
3485 /* Pacify compilers like GCC when the user code never invokes
3486 YYERROR and the label yyerrorlab therefore never appears in user
3488 if (/*CONSTCOND*/ 0)
3491 /* Do not reclaim the symbols of the rule which action triggered
3495 YY_STACK_PRINT (yyss, yyssp);
3500 /*-------------------------------------------------------------.
3501 | yyerrlab1 -- common code for both syntax error and YYERROR. |
3502 `-------------------------------------------------------------*/
3504 yyerrstatus = 3; /* Each real token shifted decrements this. */
3508 yyn = yypact[yystate];
3509 if (yyn != YYPACT_NINF)
3512 if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
3520 /* Pop the current state because it cannot handle the error token. */
3525 yydestruct ("Error: popping",
3526 yystos[yystate], yyvsp);
3529 YY_STACK_PRINT (yyss, yyssp);
3538 /* Shift the error token. */
3539 YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp);
3545 /*-------------------------------------.
3546 | yyacceptlab -- YYACCEPT comes here. |
3547 `-------------------------------------*/
3552 /*-----------------------------------.
3553 | yyabortlab -- YYABORT comes here. |
3554 `-----------------------------------*/
3560 /*-------------------------------------------------.
3561 | yyexhaustedlab -- memory exhaustion comes here. |
3562 `-------------------------------------------------*/
3564 yyerror (YY_("memory exhausted"));
3570 if (yychar != YYEOF && yychar != YYEMPTY)
3571 yydestruct ("Cleanup: discarding lookahead",
3573 /* Do not reclaim the symbols of the rule which action triggered
3574 this YYABORT or YYACCEPT. */
3576 YY_STACK_PRINT (yyss, yyssp);
3577 while (yyssp != yyss)
3579 yydestruct ("Cleanup: popping",
3580 yystos[*yyssp], yyvsp);
3585 YYSTACK_FREE (yyss);
3588 if (yymsg != yymsgbuf)
3589 YYSTACK_FREE (yymsg);
3591 /* Make sure YYID is used. */
3592 return YYID (yyresult);
3596 #line 1268 "/Users/chet/src/bash/src/parse.y"
3599 /* Initial size to allocate for tokens, and the
3600 amount to grow them by. */
3601 #define TOKEN_DEFAULT_INITIAL_SIZE 496
3602 #define TOKEN_DEFAULT_GROW_SIZE 512
3604 /* Should we call prompt_again? */
3605 #define SHOULD_PROMPT() \
3606 (interactive && (bash_input.type == st_stdin || bash_input.type == st_stream))
3609 # define expanding_alias() (pushed_string_list && pushed_string_list->expander)
3611 # define expanding_alias() 0
3614 /* Global var is non-zero when end of file has been reached. */
3615 int EOF_Reached = 0;
3628 /* yy_getc () returns the next available character from input or EOF.
3629 yy_ungetc (c) makes `c' the next character to read.
3630 init_yy_io (get, unget, type, location) makes the function GET the
3631 installed function for getting the next character, makes UNGET the
3632 installed function for un-getting a character, sets the type of stream
3633 (either string or file) from TYPE, and makes LOCATION point to where
3634 the input is coming from. */
3636 /* Unconditionally returns end-of-file. */
3643 /* Variable containing the current get and unget functions.
3644 See ./input.h for a clearer description. */
3645 BASH_INPUT bash_input;
3647 /* Set all of the fields in BASH_INPUT to NULL. Free bash_input.name if it
3648 is non-null, avoiding a memory leak. */
3650 initialize_bash_input ()
3652 bash_input.type = st_none;
3653 FREE (bash_input.name);
3654 bash_input.name = (char *)NULL;
3655 bash_input.location.file = (FILE *)NULL;
3656 bash_input.location.string = (char *)NULL;
3657 bash_input.getter = (sh_cget_func_t *)NULL;
3658 bash_input.ungetter = (sh_cunget_func_t *)NULL;
3661 /* Set the contents of the current bash input stream from
3662 GET, UNGET, TYPE, NAME, and LOCATION. */
3664 init_yy_io (get, unget, type, name, location)
3665 sh_cget_func_t *get;
3666 sh_cunget_func_t *unget;
3667 enum stream_type type;
3669 INPUT_STREAM location;
3671 bash_input.type = type;
3672 FREE (bash_input.name);
3673 bash_input.name = name ? savestring (name) : (char *)NULL;
3677 memcpy((char *)&bash_input.location.string, (char *)&location.string, sizeof(location));
3679 bash_input.location = location;
3681 bash_input.getter = get;
3682 bash_input.ungetter = unget;
3688 return (bash_input.name ? bash_input.name : "stdin");
3691 /* Call this to get the next character of input. */
3695 return (*(bash_input.getter)) ();
3698 /* Call this to unget C. That is, to make C the next character
3704 return (*(bash_input.ungetter)) (c);
3707 #if defined (BUFFERED_INPUT)
3708 #ifdef INCLUDE_UNUSED
3710 input_file_descriptor ()
3712 switch (bash_input.type)
3715 return (fileno (bash_input.location.file));
3717 return (bash_input.location.buffered_fd);
3720 return (fileno (stdin));
3724 #endif /* BUFFERED_INPUT */
3726 /* **************************************************************** */
3728 /* Let input be read from readline (). */
3730 /* **************************************************************** */
3732 #if defined (READLINE)
3733 char *current_readline_prompt = (char *)NULL;
3734 char *current_readline_line = (char *)NULL;
3735 int current_readline_line_index = 0;
3740 SigHandler *old_sigint;
3744 if (!current_readline_line)
3746 if (!bash_readline_initialized)
3747 initialize_readline ();
3749 #if defined (JOB_CONTROL)
3751 give_terminal_to (shell_pgrp, 0);
3752 #endif /* JOB_CONTROL */
3754 old_sigint = (SigHandler *)NULL;
3755 if (signal_is_ignored (SIGINT) == 0)
3757 old_sigint = (SigHandler *)set_signal_handler (SIGINT, sigint_sighandler);
3758 interrupt_immediately++;
3760 terminate_immediately = 1;
3762 current_readline_line = readline (current_readline_prompt ?
3763 current_readline_prompt : "");
3765 terminate_immediately = 0;
3766 if (signal_is_ignored (SIGINT) == 0 && old_sigint)
3768 interrupt_immediately--;
3769 set_signal_handler (SIGINT, old_sigint);
3773 /* Reset the prompt to the decoded value of prompt_string_pointer. */
3774 reset_readline_prompt ();
3777 if (current_readline_line == 0)
3780 current_readline_line_index = 0;
3781 line_len = strlen (current_readline_line);
3783 current_readline_line = (char *)xrealloc (current_readline_line, 2 + line_len);
3784 current_readline_line[line_len++] = '\n';
3785 current_readline_line[line_len] = '\0';
3788 if (current_readline_line[current_readline_line_index] == 0)
3790 free (current_readline_line);
3791 current_readline_line = (char *)NULL;
3792 return (yy_readline_get ());
3796 c = current_readline_line[current_readline_line_index++];
3802 yy_readline_unget (c)
3805 if (current_readline_line_index && current_readline_line)
3806 current_readline_line[--current_readline_line_index] = c;
3811 with_input_from_stdin ()
3813 INPUT_STREAM location;
3815 if (bash_input.type != st_stdin && stream_on_stack (st_stdin) == 0)
3817 location.string = current_readline_line;
3818 init_yy_io (yy_readline_get, yy_readline_unget,
3819 st_stdin, "readline stdin", location);
3823 #else /* !READLINE */
3826 with_input_from_stdin ()
3828 with_input_from_stream (stdin, "stdin");
3830 #endif /* !READLINE */
3832 /* **************************************************************** */
3834 /* Let input come from STRING. STRING is zero terminated. */
3836 /* **************************************************************** */
3841 register char *string;
3842 register unsigned char c;
3844 string = bash_input.location.string;
3846 /* If the string doesn't exist, or is empty, EOF found. */
3847 if (string && *string)
3850 bash_input.location.string = string;
3861 *(--bash_input.location.string) = c;
3866 with_input_from_string (string, name)
3870 INPUT_STREAM location;
3872 location.string = string;
3873 init_yy_io (yy_string_get, yy_string_unget, st_string, name, location);
3876 /* Count the number of characters we've consumed from bash_input.location.string
3877 and read into shell_input_line, but have not returned from shell_getc.
3878 That is the true input location. Rewind bash_input.location.string by
3879 that number of characters, so it points to the last character actually
3880 consumed by the parser. */
3882 rewind_input_string ()
3886 /* number of unconsumed characters in the input -- XXX need to take newlines
3887 into account, e.g., $(...\n) */
3888 xchars = shell_input_line_len - shell_input_line_index;
3889 if (bash_input.location.string[-1] == '\n')
3892 /* XXX - how to reflect bash_input.location.string back to string passed to
3893 parse_and_execute or xparse_dolparen? xparse_dolparen needs to know how
3894 far into the string we parsed. parse_and_execute knows where bash_input.
3895 location.string is, and how far from orig_string that is -- that's the
3896 number of characters the command consumed. */
3898 /* bash_input.location.string - xchars should be where we parsed to */
3899 /* need to do more validation on xchars value for sanity -- test cases. */
3900 bash_input.location.string -= xchars;
3903 /* **************************************************************** */
3905 /* Let input come from STREAM. */
3907 /* **************************************************************** */
3909 /* These two functions used to test the value of the HAVE_RESTARTABLE_SYSCALLS
3910 define, and just use getc/ungetc if it was defined, but since bash
3911 installs its signal handlers without the SA_RESTART flag, some signals
3912 (like SIGCHLD, SIGWINCH, etc.) received during a read(2) will not cause
3913 the read to be restarted. We need to restart it ourselves. */
3921 if (bash_input.location.file)
3925 interrupt_immediately++;
3926 terminate_immediately++;
3928 result = getc_with_restart (bash_input.location.file);
3931 interrupt_immediately--;
3932 terminate_immediately--;
3942 return (ungetc_with_restart (c, bash_input.location.file));
3946 with_input_from_stream (stream, name)
3950 INPUT_STREAM location;
3952 location.file = stream;
3953 init_yy_io (yy_stream_get, yy_stream_unget, st_stream, name, location);
3956 typedef struct stream_saver {
3957 struct stream_saver *next;
3958 BASH_INPUT bash_input;
3960 #if defined (BUFFERED_INPUT)
3961 BUFFERED_STREAM *bstream;
3962 #endif /* BUFFERED_INPUT */
3965 /* The globally known line number. */
3966 int line_number = 0;
3968 #if defined (COND_COMMAND)
3969 static int cond_lineno;
3970 static int cond_token;
3973 STREAM_SAVER *stream_list = (STREAM_SAVER *)NULL;
3976 push_stream (reset_lineno)
3979 STREAM_SAVER *saver = (STREAM_SAVER *)xmalloc (sizeof (STREAM_SAVER));
3981 xbcopy ((char *)&bash_input, (char *)&(saver->bash_input), sizeof (BASH_INPUT));
3983 #if defined (BUFFERED_INPUT)
3984 saver->bstream = (BUFFERED_STREAM *)NULL;
3985 /* If we have a buffered stream, clear out buffers[fd]. */
3986 if (bash_input.type == st_bstream && bash_input.location.buffered_fd >= 0)
3987 saver->bstream = set_buffered_stream (bash_input.location.buffered_fd,
3988 (BUFFERED_STREAM *)NULL);
3989 #endif /* BUFFERED_INPUT */
3991 saver->line = line_number;
3992 bash_input.name = (char *)NULL;
3993 saver->next = stream_list;
3994 stream_list = saver;
4007 STREAM_SAVER *saver = stream_list;
4010 stream_list = stream_list->next;
4012 init_yy_io (saver->bash_input.getter,
4013 saver->bash_input.ungetter,
4014 saver->bash_input.type,
4015 saver->bash_input.name,
4016 saver->bash_input.location);
4018 #if defined (BUFFERED_INPUT)
4019 /* If we have a buffered stream, restore buffers[fd]. */
4020 /* If the input file descriptor was changed while this was on the
4021 save stack, update the buffered fd to the new file descriptor and
4022 re-establish the buffer <-> bash_input fd correspondence. */
4023 if (bash_input.type == st_bstream && bash_input.location.buffered_fd >= 0)
4025 if (bash_input_fd_changed)
4027 bash_input_fd_changed = 0;
4028 if (default_buffered_input >= 0)
4030 bash_input.location.buffered_fd = default_buffered_input;
4031 saver->bstream->b_fd = default_buffered_input;
4032 SET_CLOSE_ON_EXEC (default_buffered_input);
4035 /* XXX could free buffered stream returned as result here. */
4036 set_buffered_stream (bash_input.location.buffered_fd, saver->bstream);
4038 #endif /* BUFFERED_INPUT */
4040 line_number = saver->line;
4042 FREE (saver->bash_input.name);
4047 /* Return 1 if a stream of type TYPE is saved on the stack. */
4049 stream_on_stack (type)
4050 enum stream_type type;
4052 register STREAM_SAVER *s;
4054 for (s = stream_list; s; s = s->next)
4055 if (s->bash_input.type == type)
4060 /* Save the current token state and return it in a malloced array. */
4066 ret = (int *)xmalloc (4 * sizeof (int));
4067 ret[0] = last_read_token;
4068 ret[1] = token_before_that;
4069 ret[2] = two_tokens_ago;
4070 ret[3] = current_token;
4075 restore_token_state (ts)
4080 last_read_token = ts[0];
4081 token_before_that = ts[1];
4082 two_tokens_ago = ts[2];
4083 current_token = ts[3];
4087 * This is used to inhibit alias expansion and reserved word recognition
4088 * inside case statement pattern lists. A `case statement pattern list' is:
4090 * everything between the `in' in a `case word in' and the next ')'
4092 * everything between a `;;' and the next `)' or `esac'
4095 #if defined (ALIAS) || defined (DPAREN_ARITHMETIC)
4097 #define END_OF_ALIAS 0
4100 * Pseudo-global variables used in implementing token-wise alias expansion.
4104 * Pushing and popping strings. This works together with shell_getc to
4105 * implement alias expansion on a per-token basis.
4108 typedef struct string_saver {
4109 struct string_saver *next;
4110 int expand_alias; /* Value to set expand_alias to when string is popped. */
4113 alias_t *expander; /* alias that caused this line to be pushed. */
4115 int saved_line_size, saved_line_index, saved_line_terminator;
4118 STRING_SAVER *pushed_string_list = (STRING_SAVER *)NULL;
4121 * Push the current shell_input_line onto a stack of such lines and make S
4122 * the current input. Used when expanding aliases. EXPAND is used to set
4123 * the value of expand_next_token when the string is popped, so that the
4124 * word after the alias in the original line is handled correctly when the
4125 * alias expands to multiple words. TOKEN is the token that was expanded
4126 * into S; it is saved and used to prevent infinite recursive expansion.
4129 push_string (s, expand, ap)
4134 STRING_SAVER *temp = (STRING_SAVER *)xmalloc (sizeof (STRING_SAVER));
4136 temp->expand_alias = expand;
4137 temp->saved_line = shell_input_line;
4138 temp->saved_line_size = shell_input_line_size;
4139 temp->saved_line_index = shell_input_line_index;
4140 temp->saved_line_terminator = shell_input_line_terminator;
4142 temp->expander = ap;
4144 temp->next = pushed_string_list;
4145 pushed_string_list = temp;
4149 ap->flags |= AL_BEINGEXPANDED;
4152 shell_input_line = s;
4153 shell_input_line_size = strlen (s);
4154 shell_input_line_index = 0;
4155 shell_input_line_terminator = '\0';
4157 parser_state &= ~PST_ALEXPNEXT; /* XXX */
4160 set_line_mbstate ();
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.
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;
4180 if (pushed_string_list->expand_alias)
4181 parser_state |= PST_ALEXPNEXT;
4183 parser_state &= ~PST_ALEXPNEXT;
4185 t = pushed_string_list;
4186 pushed_string_list = pushed_string_list->next;
4190 t->expander->flags &= ~AL_BEINGEXPANDED;
4195 set_line_mbstate ();
4201 register STRING_SAVER *t, *t1;
4203 for (t = pushed_string_list; t; )
4206 FREE (t->saved_line);
4209 t->expander->flags &= ~AL_BEINGEXPANDED;
4214 pushed_string_list = (STRING_SAVER *)NULL;
4217 #endif /* ALIAS || DPAREN_ARITHMETIC */
4220 free_pushed_string_input ()
4222 #if defined (ALIAS) || defined (DPAREN_ARITHMETIC)
4223 free_string_list ();
4227 /* Return a line of text, taken from wherever yylex () reads input.
4228 If there is no more input, then we return NULL. If REMOVE_QUOTED_NEWLINE
4229 is non-zero, we remove unquoted \<newline> pairs. This is used by
4230 read_secondary_line to read here documents. */
4232 read_a_line (remove_quoted_newline)
4233 int remove_quoted_newline;
4235 static char *line_buffer = (char *)NULL;
4236 static int buffer_size = 0;
4237 int indx, c, peekc, pass_next;
4239 #if defined (READLINE)
4240 if (no_line_editing && SHOULD_PROMPT ())
4242 if (SHOULD_PROMPT ())
4246 pass_next = indx = 0;
4249 /* Allow immediate exit if interrupted during input. */
4254 /* Ignore null bytes in input. */
4258 internal_warning ("read_a_line: ignored null byte in input");
4263 /* If there is no more input, then we return NULL. */
4266 if (interactive && bash_input.type == st_stream)
4269 return ((char *)NULL);
4273 /* `+2' in case the final character in the buffer is a newline. */
4274 RESIZE_MALLOCED_BUFFER (line_buffer, indx, 2, buffer_size, 128);
4276 /* IF REMOVE_QUOTED_NEWLINES is non-zero, we are reading a
4277 here document with an unquoted delimiter. In this case,
4278 the line will be expanded as if it were in double quotes.
4279 We allow a backslash to escape the next character, but we
4280 need to treat the backslash specially only if a backslash
4281 quoting a backslash-newline pair appears in the line. */
4284 line_buffer[indx++] = c;
4287 else if (c == '\\' && remove_quoted_newline)
4293 continue; /* Make the unquoted \<newline> pair disappear. */
4299 line_buffer[indx++] = c; /* Preserve the backslash. */
4303 line_buffer[indx++] = c;
4307 line_buffer[indx] = '\0';
4308 return (line_buffer);
4313 /* Return a line as in read_a_line (), but insure that the prompt is
4314 the secondary prompt. This is used to read the lines of a here
4315 document. REMOVE_QUOTED_NEWLINE is non-zero if we should remove
4316 newlines quoted with backslashes while reading the line. It is
4317 non-zero unless the delimiter of the here document was quoted. */
4319 read_secondary_line (remove_quoted_newline)
4320 int remove_quoted_newline;
4325 prompt_string_pointer = &ps2_prompt;
4326 if (SHOULD_PROMPT())
4328 ret = read_a_line (remove_quoted_newline);
4329 #if defined (HISTORY)
4330 if (ret && remember_on_history && (parser_state & PST_HEREDOC))
4332 /* To make adding the the here-document body right, we need to rely
4333 on history_delimiting_chars() returning \n for the first line of
4334 the here-document body and the null string for the second and
4335 subsequent lines, so we avoid double newlines.
4336 current_command_line_count == 2 for the first line of the body. */
4338 current_command_line_count++;
4339 maybe_add_history (ret);
4341 #endif /* HISTORY */
4345 /* **************************************************************** */
4349 /* **************************************************************** */
4351 /* Reserved words. These are only recognized as the first word of a
4353 STRING_INT_ALIST word_token_alist[] = {
4362 #if defined (SELECT_COMMAND)
4363 { "select", SELECT },
4370 { "function", FUNCTION },
4371 #if defined (COMMAND_TIMING)
4377 #if defined (COND_COMMAND)
4378 { "[[", COND_START },
4381 #if defined (COPROCESS_SUPPORT)
4382 { "coproc", COPROC },
4387 /* other tokens that can be returned by read_token() */
4388 STRING_INT_ALIST other_token_alist[] = {
4389 /* Multiple-character tokens with special values */
4393 { ">>", GREATER_GREATER },
4394 { "<<", LESS_LESS },
4396 { ">&", GREATER_AND },
4397 { ";;", SEMI_SEMI },
4399 { ";;&", SEMI_SEMI_AND },
4400 { "<<-", LESS_LESS_MINUS },
4401 { "<<<", LESS_LESS_LESS },
4402 { "&>", AND_GREATER },
4403 { "&>>", AND_GREATER_GREATER },
4404 { "<>", LESS_GREATER },
4405 { ">|", GREATER_BAR },
4407 { "EOF", yacc_EOF },
4408 /* Tokens whose value is the character itself */
4419 { "newline", '\n' },
4423 /* others not listed here:
4424 WORD look at yylval.word
4425 ASSIGNMENT_WORD look at yylval.word
4426 NUMBER look at yylval.number
4427 ARITH_CMD look at yylval.word_list
4428 ARITH_FOR_EXPRS look at yylval.word_list
4429 COND_CMD look at yylval.command
4432 /* These are used by read_token_word, but appear up here so that shell_getc
4433 can use them to decide when to add otherwise blank lines to the history. */
4435 /* The primary delimiter stack. */
4436 struct dstack dstack = { (char *)NULL, 0, 0 };
4438 /* A temporary delimiter stack to be used when decoding prompt strings.
4439 This is needed because command substitutions in prompt strings (e.g., PS2)
4440 can screw up the parser's quoting state. */
4441 static struct dstack temp_dstack = { (char *)NULL, 0, 0 };
4443 /* Macro for accessing the top delimiter on the stack. Returns the
4444 delimiter or zero if none. */
4445 #define current_delimiter(ds) \
4446 (ds.delimiter_depth ? ds.delimiters[ds.delimiter_depth - 1] : 0)
4448 #define push_delimiter(ds, character) \
4451 if (ds.delimiter_depth + 2 > ds.delimiter_space) \
4452 ds.delimiters = (char *)xrealloc \
4453 (ds.delimiters, (ds.delimiter_space += 10) * sizeof (char)); \
4454 ds.delimiters[ds.delimiter_depth] = character; \
4455 ds.delimiter_depth++; \
4459 #define pop_delimiter(ds) ds.delimiter_depth--
4461 /* Return the next shell input character. This always reads characters
4462 from shell_input_line; when that line is exhausted, it is time to
4463 read the next line. This is called by read_token when the shell is
4464 processing normal command input. */
4466 /* This implements one-character lookahead/lookbehind across physical input
4467 lines, to avoid something being lost because it's pushed back with
4468 shell_ungetc when we're at the start of a line. */
4469 static int eol_ungetc_lookahead = 0;
4472 shell_getc (remove_quoted_newline)
4473 int remove_quoted_newline;
4481 if (sigwinch_received)
4483 sigwinch_received = 0;
4484 get_new_window_size (0, (int *)0, (int *)0);
4487 if (eol_ungetc_lookahead)
4489 c = eol_ungetc_lookahead;
4490 eol_ungetc_lookahead = 0;
4494 #if defined (ALIAS) || defined (DPAREN_ARITHMETIC)
4495 /* If shell_input_line[shell_input_line_index] == 0, but there is
4496 something on the pushed list of strings, then we don't want to go
4497 off and get another line. We let the code down below handle it. */
4499 if (!shell_input_line || ((!shell_input_line[shell_input_line_index]) &&
4500 (pushed_string_list == (STRING_SAVER *)NULL)))
4501 #else /* !ALIAS && !DPAREN_ARITHMETIC */
4502 if (!shell_input_line || !shell_input_line[shell_input_line_index])
4503 #endif /* !ALIAS && !DPAREN_ARITHMETIC */
4509 /* Allow immediate exit if interrupted during input. */
4513 shell_input_line_terminator = 0;
4515 /* If the shell is interatctive, but not currently printing a prompt
4516 (interactive_shell && interactive == 0), we don't want to print
4517 notifies or cleanup the jobs -- we want to defer it until we do
4518 print the next prompt. */
4519 if (interactive_shell == 0 || SHOULD_PROMPT())
4521 #if defined (JOB_CONTROL)
4522 /* This can cause a problem when reading a command as the result
4523 of a trap, when the trap is called from flush_child. This call
4524 had better not cause jobs to disappear from the job table in
4525 that case, or we will have big trouble. */
4526 notify_and_cleanup ();
4527 #else /* !JOB_CONTROL */
4528 cleanup_dead_jobs ();
4529 #endif /* !JOB_CONTROL */
4532 #if defined (READLINE)
4533 if (no_line_editing && SHOULD_PROMPT())
4535 if (SHOULD_PROMPT())
4539 if (bash_input.type == st_stream)
4546 /* Allow immediate exit if interrupted during input. */
4552 internal_warning ("shell_getc: ignored null byte in input");
4557 RESIZE_MALLOCED_BUFFER (shell_input_line, i, 2, shell_input_line_size, 256);
4561 if (bash_input.type == st_stream)
4565 shell_input_line_terminator = EOF;
4567 shell_input_line[i] = '\0';
4571 shell_input_line[i++] = c;
4575 shell_input_line[--i] = '\0';
4576 current_command_line_count++;
4581 shell_input_line_index = 0;
4582 shell_input_line_len = i; /* == strlen (shell_input_line) */
4584 set_line_mbstate ();
4586 #if defined (HISTORY)
4587 if (remember_on_history && shell_input_line && shell_input_line[0])
4590 # if defined (BANG_HISTORY)
4593 /* If the current delimiter is a single quote, we should not be
4594 performing history expansion, even if we're on a different
4595 line from the original single quote. */
4596 old_hist = history_expansion_inhibited;
4597 if (current_delimiter (dstack) == '\'')
4598 history_expansion_inhibited = 1;
4600 expansions = pre_process_line (shell_input_line, 1, 1);
4601 # if defined (BANG_HISTORY)
4602 history_expansion_inhibited = old_hist;
4604 if (expansions != shell_input_line)
4606 free (shell_input_line);
4607 shell_input_line = expansions;
4608 shell_input_line_len = shell_input_line ?
4609 strlen (shell_input_line) : 0;
4610 if (!shell_input_line_len)
4611 current_command_line_count--;
4613 /* We have to force the xrealloc below because we don't know
4614 the true allocated size of shell_input_line anymore. */
4615 shell_input_line_size = shell_input_line_len;
4617 set_line_mbstate ();
4620 /* Try to do something intelligent with blank lines encountered while
4621 entering multi-line commands. XXX - this is grotesque */
4622 else if (remember_on_history && shell_input_line &&
4623 shell_input_line[0] == '\0' &&
4624 current_command_line_count > 1)
4626 if (current_delimiter (dstack))
4627 /* We know shell_input_line[0] == 0 and we're reading some sort of
4628 quoted string. This means we've got a line consisting of only
4629 a newline in a quoted string. We want to make sure this line
4630 gets added to the history. */
4631 maybe_add_history (shell_input_line);
4635 hdcs = history_delimiting_chars ();
4636 if (hdcs && hdcs[0] == ';')
4637 maybe_add_history (shell_input_line);
4641 #endif /* HISTORY */
4643 if (shell_input_line)
4645 /* Lines that signify the end of the shell's input should not be
4647 if (echo_input_at_read && (shell_input_line[0] ||
4648 shell_input_line_terminator != EOF))
4649 fprintf (stderr, "%s\n", shell_input_line);
4653 shell_input_line_size = 0;
4654 prompt_string_pointer = ¤t_prompt_string;
4655 if (SHOULD_PROMPT ())
4660 /* Add the newline to the end of this string, iff the string does
4661 not already end in an EOF character. */
4662 if (shell_input_line_terminator != EOF)
4664 if (shell_input_line_len + 3 > shell_input_line_size)
4665 shell_input_line = (char *)xrealloc (shell_input_line,
4666 1 + (shell_input_line_size += 2));
4668 shell_input_line[shell_input_line_len] = '\n';
4669 shell_input_line[shell_input_line_len + 1] = '\0';
4671 set_line_mbstate ();
4675 uc = shell_input_line[shell_input_line_index];
4678 shell_input_line_index++;
4680 #if defined (ALIAS) || defined (DPAREN_ARITHMETIC)
4681 /* If UC is NULL, we have reached the end of the current input string. If
4682 pushed_string_list is non-empty, it's time to pop to the previous string
4683 because we have fully consumed the result of the last alias expansion.
4684 Do it transparently; just return the next character of the string popped
4687 if (!uc && (pushed_string_list != (STRING_SAVER *)NULL))
4690 uc = shell_input_line[shell_input_line_index];
4692 shell_input_line_index++;
4694 #endif /* ALIAS || DPAREN_ARITHMETIC */
4696 if MBTEST(uc == '\\' && remove_quoted_newline && shell_input_line[shell_input_line_index] == '\n')
4698 if (SHOULD_PROMPT ())
4701 /* XXX - what do we do here if we're expanding an alias whose definition
4702 ends with a newline? Recall that we inhibit the appending of a
4703 space in mk_alexpansion() if newline is the last character. */
4704 #if 0 /* XXX - bash-4.2 (jonathan@claggett.org) */
4705 if (expanding_alias () && shell_input_line[shell_input_line_index+1] == '\0')
4715 if (!uc && shell_input_line_terminator == EOF)
4716 return ((shell_input_line_index != 0) ? '\n' : EOF);
4721 /* Put C back into the input for the shell. This might need changes for
4722 HANDLE_MULTIBYTE around EOLs. Since we (currently) never push back a
4723 character different than we read, shell_input_line_property doesn't need
4724 to change when manipulating shell_input_line. The define for
4725 last_shell_getc_is_singlebyte should take care of it, though. */
4730 if (shell_input_line && shell_input_line_index)
4731 shell_input_line[--shell_input_line_index] = c;
4733 eol_ungetc_lookahead = c;
4736 #ifdef INCLUDE_UNUSED
4737 /* Back the input pointer up by one, effectively `ungetting' a character. */
4741 if (shell_input_line && shell_input_line_index)
4742 shell_input_line_index--;
4746 /* Discard input until CHARACTER is seen, then push that character back
4747 onto the input stream. */
4749 discard_until (character)
4754 while ((c = shell_getc (0)) != EOF && c != character)
4762 execute_variable_command (command, vname)
4763 char *command, *vname;
4766 sh_parser_state_t ps;
4768 save_parser_state (&ps);
4769 last_lastarg = get_string_value ("_");
4771 last_lastarg = savestring (last_lastarg);
4773 parse_and_execute (savestring (command), vname, SEVAL_NONINT|SEVAL_NOHIST);
4775 restore_parser_state (&ps);
4776 bind_variable ("_", last_lastarg, 0);
4777 FREE (last_lastarg);
4779 if (token_to_read == '\n') /* reset_parser was called */
4783 /* Place to remember the token. We try to keep the buffer
4784 at a reasonable size, but it can grow. */
4785 static char *token = (char *)NULL;
4787 /* Current size of the token buffer. */
4788 static int token_buffer_size;
4790 /* Command to read_token () explaining what we want it to do. */
4793 #define prompt_is_ps1 \
4794 (!prompt_string_pointer || prompt_string_pointer == &ps1_prompt)
4796 /* Function for yyparse to call. yylex keeps track of
4797 the last two tokens read, and calls read_token. */
4801 if (interactive && (current_token == 0 || current_token == '\n'))
4803 /* Before we print a prompt, we might have to check mailboxes.
4804 We do this only if it is time to do so. Notice that only here
4805 is the mail alarm reset; nothing takes place in check_mail ()
4806 except the checking of mail. Please don't change this. */
4807 if (prompt_is_ps1 && time_to_check_mail ())
4810 reset_mail_timer ();
4813 /* Avoid printing a prompt if we're not going to read anything, e.g.
4814 after resetting the parser with read_token (RESET). */
4815 if (token_to_read == 0 && SHOULD_PROMPT ())
4819 two_tokens_ago = token_before_that;
4820 token_before_that = last_read_token;
4821 last_read_token = current_token;
4822 current_token = read_token (READ);
4824 if ((parser_state & PST_EOFTOKEN) && current_token == shell_eof_token)
4826 current_token = yacc_EOF;
4827 if (bash_input.type == st_string)
4828 rewind_input_string ();
4830 parser_state &= ~PST_EOFTOKEN;
4832 return (current_token);
4835 /* When non-zero, we have read the required tokens
4836 which allow ESAC to be the next one read. */
4837 static int esacs_needed_count;
4840 gather_here_documents ()
4845 while (need_here_doc)
4847 parser_state |= PST_HEREDOC;
4848 make_here_document (redir_stack[r++], line_number);
4849 parser_state &= ~PST_HEREDOC;
4854 /* When non-zero, an open-brace used to create a group is awaiting a close
4856 static int open_brace_count;
4858 #define command_token_position(token) \
4859 (((token) == ASSIGNMENT_WORD) || (parser_state&PST_REDIRLIST) || \
4860 ((token) != SEMI_SEMI && (token) != SEMI_AND && (token) != SEMI_SEMI_AND && reserved_word_acceptable(token)))
4862 #define assignment_acceptable(token) \
4863 (command_token_position(token) && ((parser_state & PST_CASEPAT) == 0))
4865 /* Check to see if TOKEN is a reserved word and return the token
4867 #define CHECK_FOR_RESERVED_WORD(tok) \
4869 if (!dollar_present && !quoted && \
4870 reserved_word_acceptable (last_read_token)) \
4873 for (i = 0; word_token_alist[i].word != (char *)NULL; i++) \
4874 if (STREQ (tok, word_token_alist[i].word)) \
4876 if ((parser_state & PST_CASEPAT) && (word_token_alist[i].token != ESAC)) \
4878 if (word_token_alist[i].token == TIME && time_command_acceptable () == 0) \
4880 if (word_token_alist[i].token == ESAC) \
4881 parser_state &= ~(PST_CASEPAT|PST_CASESTMT); \
4882 else if (word_token_alist[i].token == CASE) \
4883 parser_state |= PST_CASESTMT; \
4884 else if (word_token_alist[i].token == COND_END) \
4885 parser_state &= ~(PST_CONDCMD|PST_CONDEXPR); \
4886 else if (word_token_alist[i].token == COND_START) \
4887 parser_state |= PST_CONDCMD; \
4888 else if (word_token_alist[i].token == '{') \
4889 open_brace_count++; \
4890 else if (word_token_alist[i].token == '}' && open_brace_count) \
4891 open_brace_count--; \
4892 return (word_token_alist[i].token); \
4899 /* OK, we have a token. Let's try to alias expand it, if (and only if)
4902 It is eligible for expansion if EXPAND_ALIASES is set, and
4903 the token is unquoted and the last token read was a command
4904 separator (or expand_next_token is set), and we are currently
4905 processing an alias (pushed_string_list is non-empty) and this
4906 token is not the same as the current or any previously
4909 Special cases that disqualify:
4910 In a pattern list in a case statement (parser_state & PST_CASEPAT). */
4920 r = xmalloc (l + 2);
4922 #if 0 /* XXX - bash-4.2 */
4923 if (r[l -1] != ' ' && r[l -1] != '\n')
4933 alias_expand_token (tokstr)
4939 if (((parser_state & PST_ALEXPNEXT) || command_token_position (last_read_token)) &&
4940 (parser_state & PST_CASEPAT) == 0)
4942 ap = find_alias (tokstr);
4944 /* Currently expanding this token. */
4945 if (ap && (ap->flags & AL_BEINGEXPANDED))
4946 return (NO_EXPANSION);
4948 /* mk_alexpansion puts an extra space on the end of the alias expansion,
4949 so the lookahead by the parser works right. If this gets changed,
4950 make sure the code in shell_getc that deals with reaching the end of
4951 an expanded alias is changed with it. */
4952 expanded = ap ? mk_alexpansion (ap->value) : (char *)NULL;
4956 push_string (expanded, ap->flags & AL_EXPANDNEXT, ap);
4957 return (RE_READ_TOKEN);
4960 /* This is an eligible token that does not have an expansion. */
4961 return (NO_EXPANSION);
4963 return (NO_EXPANSION);
4968 time_command_acceptable ()
4970 #if defined (COMMAND_TIMING)
4971 switch (last_read_token)
4990 #endif /* COMMAND_TIMING */
4993 /* Handle special cases of token recognition:
4994 IN is recognized if the last token was WORD and the token
4995 before that was FOR or CASE or SELECT.
4997 DO is recognized if the last token was WORD and the token
4998 before that was FOR or SELECT.
5000 ESAC is recognized if the last token caused `esacs_needed_count'
5003 `{' is recognized if the last token as WORD and the token
5004 before that was FUNCTION, or if we just parsed an arithmetic
5007 `}' is recognized if there is an unclosed `{' present.
5009 `-p' is returned as TIMEOPT if the last read token was TIME.
5011 ']]' is returned as COND_END if the parser is currently parsing
5012 a conditional expression ((parser_state & PST_CONDEXPR) != 0)
5014 `time' is returned as TIME if and only if it is immediately
5015 preceded by one of `;', `\n', `||', `&&', or `&'.
5019 special_case_tokens (tokstr)
5022 if ((last_read_token == WORD) &&
5023 #if defined (SELECT_COMMAND)
5024 ((token_before_that == FOR) || (token_before_that == CASE) || (token_before_that == SELECT)) &&
5026 ((token_before_that == FOR) || (token_before_that == CASE)) &&
5028 (tokstr[0] == 'i' && tokstr[1] == 'n' && tokstr[2] == 0))
5030 if (token_before_that == CASE)
5032 parser_state |= PST_CASEPAT;
5033 esacs_needed_count++;
5038 if (last_read_token == WORD &&
5039 #if defined (SELECT_COMMAND)
5040 (token_before_that == FOR || token_before_that == SELECT) &&
5042 (token_before_that == FOR) &&
5044 (tokstr[0] == 'd' && tokstr[1] == 'o' && tokstr[2] == '\0'))
5047 /* Ditto for ESAC in the CASE case.
5048 Specifically, this handles "case word in esac", which is a legal
5049 construct, certainly because someone will pass an empty arg to the
5050 case construct, and we don't want it to barf. Of course, we should
5051 insist that the case construct has at least one pattern in it, but
5052 the designers disagree. */
5053 if (esacs_needed_count)
5055 esacs_needed_count--;
5056 if (STREQ (tokstr, "esac"))
5058 parser_state &= ~PST_CASEPAT;
5063 /* The start of a shell function definition. */
5064 if (parser_state & PST_ALLOWOPNBRC)
5066 parser_state &= ~PST_ALLOWOPNBRC;
5067 if (tokstr[0] == '{' && tokstr[1] == '\0') /* } */
5070 function_bstart = line_number;
5071 return ('{'); /* } */
5075 /* We allow a `do' after a for ((...)) without an intervening
5077 if (last_read_token == ARITH_FOR_EXPRS && tokstr[0] == 'd' && tokstr[1] == 'o' && !tokstr[2])
5079 if (last_read_token == ARITH_FOR_EXPRS && tokstr[0] == '{' && tokstr[1] == '\0') /* } */
5082 return ('{'); /* } */
5085 if (open_brace_count && reserved_word_acceptable (last_read_token) && tokstr[0] == '}' && !tokstr[1])
5087 open_brace_count--; /* { */
5091 #if defined (COMMAND_TIMING)
5092 /* Handle -p after `time'. */
5093 if (last_read_token == TIME && tokstr[0] == '-' && tokstr[1] == 'p' && !tokstr[2])
5098 #if defined (COMMAND_TIMING)
5099 if (STREQ (token, "time") && ((parser_state & PST_CASEPAT) == 0) && time_command_acceptable ())
5101 #endif /* COMMAND_TIMING */
5104 #if defined (COND_COMMAND) /* [[ */
5105 if ((parser_state & PST_CONDEXPR) && tokstr[0] == ']' && tokstr[1] == ']' && tokstr[2] == '\0')
5112 /* Called from shell.c when Control-C is typed at top level. Or
5113 by the error rule at top level. */
5117 dstack.delimiter_depth = 0; /* No delimiters found so far. */
5118 open_brace_count = 0;
5120 #if defined (EXTENDED_GLOB)
5121 /* Reset to global value of extended glob */
5122 if (parser_state & PST_EXTPAT)
5123 extended_glob = global_extglob;
5128 #if defined (ALIAS) || defined (DPAREN_ARITHMETIC)
5129 if (pushed_string_list)
5130 free_string_list ();
5131 #endif /* ALIAS || DPAREN_ARITHMETIC */
5133 if (shell_input_line)
5135 free (shell_input_line);
5136 shell_input_line = (char *)NULL;
5137 shell_input_line_size = shell_input_line_index = 0;
5140 FREE (word_desc_to_read);
5141 word_desc_to_read = (WORD_DESC *)NULL;
5143 current_token = '\n'; /* XXX */
5144 last_read_token = '\n';
5145 token_to_read = '\n';
5148 /* Read the next token. Command can be READ (normal operation) or
5149 RESET (to normalize state). */
5151 read_token (command)
5154 int character; /* Current character. */
5155 int peek_char; /* Temporary look-ahead character. */
5156 int result; /* The thing to return. */
5158 if (command == RESET)
5166 result = token_to_read;
5167 if (token_to_read == WORD || token_to_read == ASSIGNMENT_WORD)
5169 yylval.word = word_desc_to_read;
5170 word_desc_to_read = (WORD_DESC *)NULL;
5176 #if defined (COND_COMMAND)
5177 if ((parser_state & (PST_CONDCMD|PST_CONDEXPR)) == PST_CONDCMD)
5179 cond_lineno = line_number;
5180 parser_state |= PST_CONDEXPR;
5181 yylval.command = parse_cond_command ();
5182 if (cond_token != COND_END)
5187 token_to_read = COND_END;
5188 parser_state &= ~(PST_CONDEXPR|PST_CONDCMD);
5194 /* This is a place to jump back to once we have successfully expanded a
5195 token with an alias and pushed the string with push_string () */
5199 /* Read a single word from input. Start by skipping blanks. */
5200 while ((character = shell_getc (1)) != EOF && shellblank (character))
5203 if (character == EOF)
5209 if MBTEST(character == '#' && (!interactive || interactive_comments))
5211 /* A comment. Discard until EOL or EOF, and then return a newline. */
5212 discard_until ('\n');
5214 character = '\n'; /* this will take the next if statement and return. */
5217 if (character == '\n')
5219 /* If we're about to return an unquoted newline, we can go and collect
5220 the text of any pending here document. */
5222 gather_here_documents ();
5225 parser_state &= ~PST_ALEXPNEXT;
5228 parser_state &= ~PST_ASSIGNOK;
5233 if (parser_state & PST_REGEXP)
5236 /* Shell meta-characters. */
5237 if MBTEST(shellmeta (character) && ((parser_state & PST_DBLPAREN) == 0))
5240 /* Turn off alias tokenization iff this character sequence would
5241 not leave us ready to read a command. */
5242 if (character == '<' || character == '>')
5243 parser_state &= ~PST_ALEXPNEXT;
5246 parser_state &= ~PST_ASSIGNOK;
5248 peek_char = shell_getc (1);
5249 if (character == peek_char)
5254 /* If '<' then we could be at "<<" or at "<<-". We have to
5255 look ahead one more character. */
5256 peek_char = shell_getc (1);
5257 if MBTEST(peek_char == '-')
5258 return (LESS_LESS_MINUS);
5259 else if MBTEST(peek_char == '<')
5260 return (LESS_LESS_LESS);
5263 shell_ungetc (peek_char);
5268 return (GREATER_GREATER);
5271 parser_state |= PST_CASEPAT;
5273 parser_state &= ~PST_ALEXPNEXT;
5276 peek_char = shell_getc (1);
5277 if MBTEST(peek_char == '&')
5278 return (SEMI_SEMI_AND);
5281 shell_ungetc (peek_char);
5291 #if defined (DPAREN_ARITHMETIC) || defined (ARITH_FOR_COMMAND)
5293 result = parse_dparen (character);
5301 else if MBTEST(character == '<' && peek_char == '&')
5303 else if MBTEST(character == '>' && peek_char == '&')
5304 return (GREATER_AND);
5305 else if MBTEST(character == '<' && peek_char == '>')
5306 return (LESS_GREATER);
5307 else if MBTEST(character == '>' && peek_char == '|')
5308 return (GREATER_BAR);
5309 else if MBTEST(character == '&' && peek_char == '>')
5311 peek_char = shell_getc (1);
5312 if MBTEST(peek_char == '>')
5313 return (AND_GREATER_GREATER);
5316 shell_ungetc (peek_char);
5317 return (AND_GREATER);
5320 else if MBTEST(character == '|' && peek_char == '&')
5322 else if MBTEST(character == ';' && peek_char == '&')
5324 parser_state |= PST_CASEPAT;
5326 parser_state &= ~PST_ALEXPNEXT;
5331 shell_ungetc (peek_char);
5333 /* If we look like we are reading the start of a function
5334 definition, then let the reader know about it so that
5335 we will do the right thing with `{'. */
5336 if MBTEST(character == ')' && last_read_token == '(' && token_before_that == WORD)
5338 parser_state |= PST_ALLOWOPNBRC;
5340 parser_state &= ~PST_ALEXPNEXT;
5342 function_dstart = line_number;
5345 /* case pattern lists may be preceded by an optional left paren. If
5346 we're not trying to parse a case pattern list, the left paren
5347 indicates a subshell. */
5348 if MBTEST(character == '(' && (parser_state & PST_CASEPAT) == 0) /* ) */
5349 parser_state |= PST_SUBSHELL;
5351 else if MBTEST((parser_state & PST_CASEPAT) && character == ')')
5352 parser_state &= ~PST_CASEPAT;
5354 else if MBTEST((parser_state & PST_SUBSHELL) && character == ')')
5355 parser_state &= ~PST_SUBSHELL;
5357 #if defined (PROCESS_SUBSTITUTION)
5358 /* Check for the constructs which introduce process substitution.
5359 Shells running in `posix mode' don't do process substitution. */
5360 if MBTEST(posixly_correct || ((character != '>' && character != '<') || peek_char != '(')) /*)*/
5361 #endif /* PROCESS_SUBSTITUTION */
5365 /* Hack <&- (close stdin) case. Also <&N- (dup and close). */
5366 if MBTEST(character == '-' && (last_read_token == LESS_AND || last_read_token == GREATER_AND))
5370 /* Okay, if we got this far, we have to read a word. Read one,
5371 and then check it against the known ones. */
5372 result = read_token_word (character);
5374 if (result == RE_READ_TOKEN)
5381 * Match a $(...) or other grouping construct. This has to handle embedded
5382 * quoted strings ('', ``, "") and nested constructs. It also must handle
5383 * reprompting the user, if necessary, after reading a newline, and returning
5384 * correct error values if it reads EOF.
5386 #define P_FIRSTCLOSE 0x01
5387 #define P_ALLOWESC 0x02
5388 #define P_DQUOTE 0x04
5389 #define P_COMMAND 0x08 /* parsing a command, so look for comments */
5390 #define P_BACKQUOTE 0x10 /* parsing a backquoted command substitution */
5391 #define P_ARRAYSUB 0x20 /* parsing a [...] array subscript for assignment */
5393 /* Lexical state while parsing a grouping construct or $(...). */
5394 #define LEX_WASDOL 0x001
5395 #define LEX_CKCOMMENT 0x002
5396 #define LEX_INCOMMENT 0x004
5397 #define LEX_PASSNEXT 0x008
5398 #define LEX_RESWDOK 0x010
5399 #define LEX_CKCASE 0x020
5400 #define LEX_INCASE 0x040
5401 #define LEX_INHEREDOC 0x080
5402 #define LEX_HEREDELIM 0x100 /* reading here-doc delimiter */
5403 #define LEX_STRIPDOC 0x200 /* <<- strip tabs from here doc delim */
5404 #define LEX_INWORD 0x400
5406 #define COMSUB_META(ch) ((ch) == ';' || (ch) == '&' || (ch) == '|')
5408 #define CHECK_NESTRET_ERROR() \
5410 if (nestret == &matched_pair_error) \
5413 return &matched_pair_error; \
5417 #define APPEND_NESTRET() \
5421 RESIZE_MALLOCED_BUFFER (ret, retind, nestlen, retsize, 64); \
5422 strcpy (ret + retind, nestret); \
5423 retind += nestlen; \
5427 static char matched_pair_error;
5430 parse_matched_pair (qc, open, close, lenp, flags)
5431 int qc; /* `"' if this construct is within double quotes */
5435 int count, ch, tflags;
5436 int nestlen, ttranslen, start_lineno;
5437 char *ret, *nestret, *ttrans;
5438 int retind, retsize, rflags;
5440 /*itrace("parse_matched_pair[%d]: open = %c close = %c flags = %d", line_number, open, close, flags);*/
5444 if ((flags & P_COMMAND) && qc != '`' && qc != '\'' && qc != '"' && (flags & P_DQUOTE) == 0)
5445 tflags |= LEX_CKCOMMENT;
5447 /* RFLAGS is the set of flags we want to pass to recursive calls. */
5448 rflags = (qc == '"') ? P_DQUOTE : (flags & P_DQUOTE);
5450 ret = (char *)xmalloc (retsize = 64);
5453 start_lineno = line_number;
5456 ch = shell_getc (qc != '\'' && (tflags & LEX_PASSNEXT) == 0);
5461 parser_error (start_lineno, _("unexpected EOF while looking for matching `%c'"), close);
5462 EOF_Reached = 1; /* XXX */
5463 return (&matched_pair_error);
5466 /* Possible reprompting. */
5467 if (ch == '\n' && SHOULD_PROMPT ())
5470 /* Don't bother counting parens or doing anything else if in a comment
5471 or part of a case statement */
5472 if (tflags & LEX_INCOMMENT)
5474 /* Add this character. */
5475 RESIZE_MALLOCED_BUFFER (ret, retind, 1, retsize, 64);
5479 tflags &= ~LEX_INCOMMENT;
5484 /* Not exactly right yet, should handle shell metacharacters, too. If
5485 any changes are made to this test, make analogous changes to subst.c:
5486 extract_delimited_string(). */
5487 else if MBTEST((tflags & LEX_CKCOMMENT) && (tflags & LEX_INCOMMENT) == 0 && ch == '#' && (retind == 0 || ret[retind-1] == '\n' || shellblank (ret[retind - 1])))
5488 tflags |= LEX_INCOMMENT;
5490 if (tflags & LEX_PASSNEXT) /* last char was backslash */
5492 tflags &= ~LEX_PASSNEXT;
5493 if (qc != '\'' && ch == '\n') /* double-quoted \<newline> disappears. */
5496 retind--; /* swallow previously-added backslash */
5500 RESIZE_MALLOCED_BUFFER (ret, retind, 2, retsize, 64);
5501 if MBTEST(ch == CTLESC || ch == CTLNUL)
5502 ret[retind++] = CTLESC;
5506 /* If we're reparsing the input (e.g., from parse_string_to_word_list),
5507 we've already prepended CTLESC to single-quoted results of $'...'.
5508 We may want to do this for other CTLESC-quoted characters in
5510 else if MBTEST((parser_state & PST_REPARSE) && open == '\'' && (ch == CTLESC || ch == CTLNUL))
5512 RESIZE_MALLOCED_BUFFER (ret, retind, 1, retsize, 64);
5516 else if MBTEST(ch == CTLESC || ch == CTLNUL) /* special shell escapes */
5518 RESIZE_MALLOCED_BUFFER (ret, retind, 2, retsize, 64);
5519 ret[retind++] = CTLESC;
5523 else if MBTEST(ch == close) /* ending delimiter */
5525 /* handle nested ${...} specially. */
5526 else if MBTEST(open != close && (tflags & LEX_WASDOL) && open == '{' && ch == open) /* } */
5528 else if MBTEST(((flags & P_FIRSTCLOSE) == 0) && ch == open) /* nested begin */
5531 /* Add this character. */
5532 RESIZE_MALLOCED_BUFFER (ret, retind, 1, retsize, 64);
5535 /* If we just read the ending character, don't bother continuing. */
5539 if (open == '\'') /* '' inside grouping construct */
5541 if MBTEST((flags & P_ALLOWESC) && ch == '\\')
5542 tflags |= LEX_PASSNEXT;
5546 if MBTEST(ch == '\\') /* backslashes */
5547 tflags |= LEX_PASSNEXT;
5550 /* The big hammer. Single quotes aren't special in double quotes. The
5551 problem is that Posix says the single quotes are semi-special:
5552 within a double-quoted ${...} construct "an even number of
5553 unescaped double-quotes or single-quotes, if any, shall occur." */
5554 if MBTEST(open == '{' && (flags & P_DQUOTE) && ch == '\'') /* } */
5558 /* Could also check open == '`' if we want to parse grouping constructs
5559 inside old-style command substitution. */
5560 if (open != close) /* a grouping construct */
5562 if MBTEST(shellquote (ch))
5564 /* '', ``, or "" inside $(...) or other grouping construct. */
5565 push_delimiter (dstack, ch);
5566 if MBTEST((tflags & LEX_WASDOL) && ch == '\'') /* $'...' inside group */
5567 nestret = parse_matched_pair (ch, ch, ch, &nestlen, P_ALLOWESC|rflags);
5569 nestret = parse_matched_pair (ch, ch, ch, &nestlen, rflags);
5570 pop_delimiter (dstack);
5571 CHECK_NESTRET_ERROR ();
5573 if MBTEST((tflags & LEX_WASDOL) && ch == '\'' && (extended_quote || (rflags & P_DQUOTE) == 0))
5575 /* Translate $'...' here. */
5576 ttrans = ansiexpand (nestret, 0, nestlen - 1, &ttranslen);
5579 if ((rflags & P_DQUOTE) == 0)
5581 nestret = sh_single_quote (ttrans);
5583 nestlen = strlen (nestret);
5588 nestlen = ttranslen;
5590 retind -= 2; /* back up before the $' */
5592 else if MBTEST((tflags & LEX_WASDOL) && ch == '"' && (extended_quote || (rflags & P_DQUOTE) == 0))
5594 /* Locale expand $"..." here. */
5595 ttrans = localeexpand (nestret, 0, nestlen - 1, start_lineno, &ttranslen);
5598 nestret = sh_mkdoublequoted (ttrans, ttranslen, 0);
5600 nestlen = ttranslen + 2;
5601 retind -= 2; /* back up before the $" */
5607 else if ((flags & P_ARRAYSUB) && (tflags & LEX_WASDOL) && (ch == '(' || ch == '{' || ch == '[')) /* ) } ] */
5608 goto parse_dollar_word;
5610 /* Parse an old-style command substitution within double quotes as a
5612 /* XXX - sh and ksh93 don't do this - XXX */
5613 else if MBTEST(open == '"' && ch == '`')
5615 nestret = parse_matched_pair (0, '`', '`', &nestlen, rflags);
5617 CHECK_NESTRET_ERROR ();
5622 else if MBTEST(open != '`' && (tflags & LEX_WASDOL) && (ch == '(' || ch == '{' || ch == '[')) /* ) } ] */
5623 /* check for $(), $[], or ${} inside quoted string. */
5626 if (open == ch) /* undo previous increment */
5628 if (ch == '(') /* ) */
5629 nestret = parse_comsub (0, '(', ')', &nestlen, (rflags|P_COMMAND) & ~P_DQUOTE);
5630 else if (ch == '{') /* } */
5631 nestret = parse_matched_pair (0, '{', '}', &nestlen, P_FIRSTCLOSE|rflags);
5632 else if (ch == '[') /* ] */
5633 nestret = parse_matched_pair (0, '[', ']', &nestlen, rflags);
5635 CHECK_NESTRET_ERROR ();
5640 if MBTEST(ch == '$')
5641 tflags |= LEX_WASDOL;
5643 tflags &= ~LEX_WASDOL;
5649 /*itrace("parse_matched_pair[%d]: returning %s", line_number, ret);*/
5653 /* Parse a $(...) command substitution. This is messier than I'd like, and
5654 reproduces a lot more of the token-reading code than I'd like. */
5656 parse_comsub (qc, open, close, lenp, flags)
5657 int qc; /* `"' if this construct is within double quotes */
5661 int count, ch, peekc, tflags, lex_rwlen, lex_wlen, lex_firstind;
5662 int nestlen, ttranslen, start_lineno;
5663 char *ret, *nestret, *ttrans, *heredelim;
5664 int retind, retsize, rflags, hdlen;
5666 /*itrace("parse_comsub: qc = `%c' open = %c close = %c", qc, open, close);*/
5668 tflags = LEX_RESWDOK;
5670 if ((flags & P_COMMAND) && qc != '\'' && qc != '"' && (flags & P_DQUOTE) == 0)
5671 tflags |= LEX_CKCASE;
5672 if ((tflags & LEX_CKCASE) && (interactive == 0 || interactive_comments))
5673 tflags |= LEX_CKCOMMENT;
5675 /* RFLAGS is the set of flags we want to pass to recursive calls. */
5676 rflags = (flags & P_DQUOTE);
5678 ret = (char *)xmalloc (retsize = 64);
5681 start_lineno = line_number;
5682 lex_rwlen = lex_wlen = 0;
5690 ch = shell_getc (qc != '\'' && (tflags & LEX_PASSNEXT) == 0);
5697 parser_error (start_lineno, _("unexpected EOF while looking for matching `%c'"), close);
5698 EOF_Reached = 1; /* XXX */
5699 return (&matched_pair_error);
5702 /* If we hit the end of a line and are reading the contents of a here
5703 document, and it's not the same line that the document starts on,
5704 check for this line being the here doc delimiter. Otherwise, if
5705 we're in a here document, mark the next character as the beginning
5709 if ((tflags & LEX_HEREDELIM) && heredelim)
5711 tflags &= ~LEX_HEREDELIM;
5712 tflags |= LEX_INHEREDOC;
5713 lex_firstind = retind + 1;
5715 else if (tflags & LEX_INHEREDOC)
5718 tind = lex_firstind;
5719 while ((tflags & LEX_STRIPDOC) && ret[tind] == '\t')
5721 if (STREQN (ret + tind, heredelim, hdlen))
5723 tflags &= ~(LEX_STRIPDOC|LEX_INHEREDOC);
5724 /*itrace("parse_comsub:%d: found here doc end `%s'", line_number, ret + tind);*/
5730 lex_firstind = retind + 1;
5734 /* Possible reprompting. */
5735 if (ch == '\n' && SHOULD_PROMPT ())
5738 /* XXX -- possibly allow here doc to be delimited by ending right
5740 if ((tflags & LEX_INHEREDOC) && ch == close && count == 1)
5743 /*itrace("parse_comsub: in here doc, ch == close, retind - firstind = %d hdlen = %d retind = %d", retind-lex_firstind, hdlen, retind);*/
5744 tind = lex_firstind;
5745 while ((tflags & LEX_STRIPDOC) && ret[tind] == '\t')
5747 if (retind-tind == hdlen && STREQN (ret + tind, heredelim, hdlen))
5749 tflags &= ~(LEX_STRIPDOC|LEX_INHEREDOC);
5750 /*itrace("parse_comsub:%d: found here doc end `%s'", line_number, ret + tind);*/
5757 /* Don't bother counting parens or doing anything else if in a comment */
5758 if (tflags & (LEX_INCOMMENT|LEX_INHEREDOC))
5760 /* Add this character. */
5761 RESIZE_MALLOCED_BUFFER (ret, retind, 1, retsize, 64);
5764 if ((tflags & LEX_INCOMMENT) && ch == '\n')
5766 /*itrace("parse_comsub:%d: lex_incomment -> 0 ch = `%c'", line_number, ch);*/
5767 tflags &= ~LEX_INCOMMENT;
5773 if (tflags & LEX_PASSNEXT) /* last char was backslash */
5775 /*itrace("parse_comsub:%d: lex_passnext -> 0 ch = `%c' (%d)", line_number, ch, __LINE__);*/
5776 tflags &= ~LEX_PASSNEXT;
5777 if (qc != '\'' && ch == '\n') /* double-quoted \<newline> disappears. */
5780 retind--; /* swallow previously-added backslash */
5784 RESIZE_MALLOCED_BUFFER (ret, retind, 2, retsize, 64);
5785 if MBTEST(ch == CTLESC || ch == CTLNUL)
5786 ret[retind++] = CTLESC;
5791 /* If this is a shell break character, we are not in a word. If not,
5792 we either start or continue a word. */
5793 if MBTEST(shellbreak (ch))
5795 tflags &= ~LEX_INWORD;
5796 /*itrace("parse_comsub:%d: lex_inword -> 0 ch = `%c' (%d)", line_number, ch, __LINE__);*/
5800 if (tflags & LEX_INWORD)
5803 /*itrace("parse_comsub:%d: lex_inword == 1 ch = `%c' lex_wlen = %d (%d)", line_number, ch, lex_wlen, __LINE__);*/
5807 /*itrace("parse_comsub:%d: lex_inword -> 1 ch = `%c' (%d)", line_number, ch, __LINE__);*/
5808 tflags |= LEX_INWORD;
5813 /* Skip whitespace */
5814 if MBTEST(shellblank (ch) && lex_rwlen == 0)
5816 /* Add this character. */
5817 RESIZE_MALLOCED_BUFFER (ret, retind, 1, retsize, 64);
5822 /* Either we are looking for the start of the here-doc delimiter
5823 (lex_firstind == -1) or we are reading one (lex_firstind >= 0).
5824 If this character is a shell break character and we are reading
5825 the delimiter, save it and note that we are now reading a here
5826 document. If we've found the start of the delimiter, note it by
5827 setting lex_firstind. Backslashes can quote shell metacharacters
5828 in here-doc delimiters. */
5829 if (tflags & LEX_HEREDELIM)
5831 if (lex_firstind == -1 && shellbreak (ch) == 0)
5832 lex_firstind = retind;
5834 else if (heredelim && (tflags & LEX_PASSNEXT) == 0 && ch == '\n')
5836 tflags |= LEX_INHEREDOC;
5837 tflags &= ~LEX_HEREDELIM;
5838 lex_firstind = retind + 1;
5841 else if (lex_firstind >= 0 && (tflags & LEX_PASSNEXT) == 0 && shellbreak (ch))
5845 nestret = substring (ret, lex_firstind, retind);
5846 heredelim = string_quote_removal (nestret, 0);
5848 hdlen = STRLEN(heredelim);
5849 /*itrace("parse_comsub:%d: found here doc delimiter `%s' (%d)", line_number, heredelim, hdlen);*/
5853 tflags |= LEX_INHEREDOC;
5854 tflags &= ~LEX_HEREDELIM;
5855 lex_firstind = retind + 1;
5862 /* Meta-characters that can introduce a reserved word. Not perfect yet. */
5863 if MBTEST((tflags & LEX_RESWDOK) == 0 && (tflags & LEX_CKCASE) && (tflags & LEX_INCOMMENT) == 0 && (shellmeta(ch) || ch == '\n'))
5865 /* Add this character. */
5866 RESIZE_MALLOCED_BUFFER (ret, retind, 1, retsize, 64);
5868 peekc = shell_getc (1);
5869 if (ch == peekc && (ch == '&' || ch == '|' || ch == ';')) /* two-character tokens */
5871 RESIZE_MALLOCED_BUFFER (ret, retind, 1, retsize, 64);
5872 ret[retind++] = peekc;
5873 /*itrace("parse_comsub:%d: set lex_reswordok = 1, ch = `%c'", line_number, ch);*/
5874 tflags |= LEX_RESWDOK;
5878 else if (ch == '\n' || COMSUB_META(ch))
5880 shell_ungetc (peekc);
5881 /*itrace("parse_comsub:%d: set lex_reswordok = 1, ch = `%c'", line_number, ch);*/
5882 tflags |= LEX_RESWDOK;
5890 /* `unget' the character we just added and fall through */
5892 shell_ungetc (peekc);
5896 /* If we can read a reserved word, try to read one. */
5897 if (tflags & LEX_RESWDOK)
5899 if MBTEST(islower (ch))
5901 /* Add this character. */
5902 RESIZE_MALLOCED_BUFFER (ret, retind, 1, retsize, 64);
5907 else if MBTEST(lex_rwlen == 4 && shellbreak (ch))
5909 if (STREQN (ret + retind - 4, "case", 4))
5911 tflags |= LEX_INCASE;
5912 /*itrace("parse_comsub:%d: found `case', lex_incase -> 1 lex_reswdok -> 0", line_number);*/
5914 else if (STREQN (ret + retind - 4, "esac", 4))
5916 tflags &= ~LEX_INCASE;
5917 /*itrace("parse_comsub:%d: found `esac', lex_incase -> 0 lex_reswdok -> 0", line_number);*/
5919 tflags &= ~LEX_RESWDOK;
5921 else if MBTEST((tflags & LEX_CKCOMMENT) && ch == '#' && (lex_rwlen == 0 || ((tflags & LEX_INWORD) && lex_wlen == 0)))
5922 ; /* don't modify LEX_RESWDOK if we're starting a comment */
5923 else if MBTEST((tflags & LEX_INCASE) && ch != '\n')
5924 /* If we can read a reserved word and we're in case, we're at the
5925 point where we can read a new pattern list or an esac. We
5926 handle the esac case above. If we read a newline, we want to
5927 leave LEX_RESWDOK alone. If we read anything else, we want to
5928 turn off LEX_RESWDOK, since we're going to read a pattern list. */
5930 tflags &= ~LEX_RESWDOK;
5931 /*itrace("parse_comsub:%d: lex_incase == 1 found `%c', lex_reswordok -> 0", line_number, ch);*/
5933 else if MBTEST(shellbreak (ch) == 0)
5935 tflags &= ~LEX_RESWDOK;
5936 /*itrace("parse_comsub:%d: found `%c', lex_reswordok -> 0", line_number, ch);*/
5940 /* Might be the start of a here-doc delimiter */
5941 if MBTEST((tflags & LEX_INCOMMENT) == 0 && (tflags & LEX_CKCASE) && ch == '<')
5943 /* Add this character. */
5944 RESIZE_MALLOCED_BUFFER (ret, retind, 1, retsize, 64);
5946 peekc = shell_getc (1);
5951 RESIZE_MALLOCED_BUFFER (ret, retind, 1, retsize, 64);
5952 ret[retind++] = peekc;
5953 peekc = shell_getc (1);
5958 RESIZE_MALLOCED_BUFFER (ret, retind, 1, retsize, 64);
5959 ret[retind++] = peekc;
5960 tflags |= LEX_STRIPDOC;
5963 shell_ungetc (peekc);
5966 tflags |= LEX_HEREDELIM;
5972 ch = peekc; /* fall through and continue XXX */
5974 else if MBTEST((tflags & LEX_CKCOMMENT) && (tflags & LEX_INCOMMENT) == 0 && ch == '#' && (((tflags & LEX_RESWDOK) && lex_rwlen == 0) || ((tflags & LEX_INWORD) && lex_wlen == 0)))
5976 /*itrace("parse_comsub:%d: lex_incomment -> 1 (%d)", line_number, __LINE__);*/
5977 tflags |= LEX_INCOMMENT;
5980 if MBTEST(ch == CTLESC || ch == CTLNUL) /* special shell escapes */
5982 RESIZE_MALLOCED_BUFFER (ret, retind, 2, retsize, 64);
5983 ret[retind++] = CTLESC;
5988 else if MBTEST((tflags & LEX_INCASE) && ch == close && close == ')')
5989 tflags &= ~LEX_INCASE; /* XXX */
5991 else if MBTEST(ch == close && (tflags & LEX_INCASE) == 0) /* ending delimiter */
5994 /*itrace("parse_comsub:%d: found close: count = %d", line_number, count);*/
5996 else if MBTEST(((flags & P_FIRSTCLOSE) == 0) && (tflags & LEX_INCASE) == 0 && ch == open) /* nested begin */
5999 /*itrace("parse_comsub:%d: found open: count = %d", line_number, count);*/
6002 /* Add this character. */
6003 RESIZE_MALLOCED_BUFFER (ret, retind, 1, retsize, 64);
6006 /* If we just read the ending character, don't bother continuing. */
6010 if MBTEST(ch == '\\') /* backslashes */
6011 tflags |= LEX_PASSNEXT;
6013 if MBTEST(shellquote (ch))
6015 /* '', ``, or "" inside $(...). */
6016 push_delimiter (dstack, ch);
6017 if MBTEST((tflags & LEX_WASDOL) && ch == '\'') /* $'...' inside group */
6018 nestret = parse_matched_pair (ch, ch, ch, &nestlen, P_ALLOWESC|rflags);
6020 nestret = parse_matched_pair (ch, ch, ch, &nestlen, rflags);
6021 pop_delimiter (dstack);
6022 CHECK_NESTRET_ERROR ();
6024 if MBTEST((tflags & LEX_WASDOL) && ch == '\'' && (extended_quote || (rflags & P_DQUOTE) == 0))
6026 /* Translate $'...' here. */
6027 ttrans = ansiexpand (nestret, 0, nestlen - 1, &ttranslen);
6030 if ((rflags & P_DQUOTE) == 0)
6032 nestret = sh_single_quote (ttrans);
6034 nestlen = strlen (nestret);
6039 nestlen = ttranslen;
6041 retind -= 2; /* back up before the $' */
6043 else if MBTEST((tflags & LEX_WASDOL) && ch == '"' && (extended_quote || (rflags & P_DQUOTE) == 0))
6045 /* Locale expand $"..." here. */
6046 ttrans = localeexpand (nestret, 0, nestlen - 1, start_lineno, &ttranslen);
6049 nestret = sh_mkdoublequoted (ttrans, ttranslen, 0);
6051 nestlen = ttranslen + 2;
6052 retind -= 2; /* back up before the $" */
6058 else if MBTEST((tflags & LEX_WASDOL) && (ch == '(' || ch == '{' || ch == '[')) /* ) } ] */
6059 /* check for $(), $[], or ${} inside command substitution. */
6061 if ((tflags & LEX_INCASE) == 0 && open == ch) /* undo previous increment */
6063 if (ch == '(') /* ) */
6064 nestret = parse_comsub (0, '(', ')', &nestlen, (rflags|P_COMMAND) & ~P_DQUOTE);
6065 else if (ch == '{') /* } */
6066 nestret = parse_matched_pair (0, '{', '}', &nestlen, P_FIRSTCLOSE|rflags);
6067 else if (ch == '[') /* ] */
6068 nestret = parse_matched_pair (0, '[', ']', &nestlen, rflags);
6070 CHECK_NESTRET_ERROR ();
6075 if MBTEST(ch == '$')
6076 tflags |= LEX_WASDOL;
6078 tflags &= ~LEX_WASDOL;
6085 /*itrace("parse_comsub:%d: returning `%s'", line_number, ret);*/
6089 /* XXX - this needs to handle functionality like subst.c:no_longjmp_on_fatal_error;
6090 maybe extract_command_subst should handle it. */
6092 xparse_dolparen (base, string, indp, flags)
6098 sh_parser_state_t ps;
6099 int orig_ind, nc, sflags;
6100 char *ret, *s, *ep, *ostring;
6106 sflags = SEVAL_NONINT|SEVAL_NOHIST|SEVAL_NOFREE;
6107 if (flags & SX_NOLONGJMP)
6108 sflags |= SEVAL_NOLONGJMP;
6109 save_parser_state (&ps);
6112 parser_state |= PST_CMDSUBST|PST_EOFTOKEN; /* allow instant ')' */ /*(*/
6113 shell_eof_token = ')';
6114 parse_string (string, "command substitution", sflags, &ep);
6116 restore_parser_state (&ps);
6121 /* Need to find how many characters parse_and_execute consumed, update
6122 *indp, if flags != 0, copy the portion of the string parsed into RET
6123 and return it. If flags & 1 (EX_NOALLOC) we can return NULL. */
6130 itrace("xparse_dolparen:%d: ep[-1] != RPAREN (%d), ep = `%s'", line_number, ep[-1], ep);
6132 while (ep > ostring && ep[-1] == '\n') ep--;
6136 *indp = ep - base - 1;
6140 if (base[*indp] != ')')
6141 itrace("xparse_dolparen:%d: base[%d] != RPAREN (%d), base = `%s'", line_number, *indp, base[*indp], base);
6144 if (flags & SX_NOALLOC)
6145 return (char *)NULL;
6153 ret = substring (ostring, 0, nc - 1);
6158 #if defined (DPAREN_ARITHMETIC) || defined (ARITH_FOR_COMMAND)
6159 /* Parse a double-paren construct. It can be either an arithmetic
6160 command, an arithmetic `for' command, or a nested subshell. Returns
6161 the parsed token, -1 on error, or -2 if we didn't do anything and
6162 should just go on. */
6171 #if defined (ARITH_FOR_COMMAND)
6172 if (last_read_token == FOR)
6174 arith_for_lineno = line_number;
6175 cmdtyp = parse_arith_cmd (&wval, 0);
6178 wd = alloc_word_desc ();
6180 yylval.word_list = make_word_list (wd, (WORD_LIST *)NULL);
6181 return (ARITH_FOR_EXPRS);
6184 return -1; /* ERROR */
6188 #if defined (DPAREN_ARITHMETIC)
6189 if (reserved_word_acceptable (last_read_token))
6191 sline = line_number;
6193 cmdtyp = parse_arith_cmd (&wval, 0);
6194 if (cmdtyp == 1) /* arithmetic command */
6196 wd = alloc_word_desc ();
6198 wd->flags = W_QUOTED|W_NOSPLIT|W_NOGLOB|W_DQUOTE;
6199 yylval.word_list = make_word_list (wd, (WORD_LIST *)NULL);
6202 else if (cmdtyp == 0) /* nested subshell */
6204 push_string (wval, 0, (alias_t *)NULL);
6205 if ((parser_state & PST_CASEPAT) == 0)
6206 parser_state |= PST_SUBSHELL;
6214 return -2; /* XXX */
6217 /* We've seen a `(('. Look for the matching `))'. If we get it, return 1.
6218 If not, assume it's a nested subshell for backwards compatibility and
6219 return 0. In any case, put the characters we've consumed into a locally-
6220 allocated buffer and make *ep point to that buffer. Return -1 on an
6221 error, for example EOF. */
6223 parse_arith_cmd (ep, adddq)
6227 int exp_lineno, rval, c;
6228 char *ttok, *tokstr;
6231 exp_lineno = line_number;
6232 ttok = parse_matched_pair (0, '(', ')', &ttoklen, 0);
6234 if (ttok == &matched_pair_error)
6236 /* Check that the next character is the closing right paren. If
6237 not, this is a syntax error. ( */
6242 tokstr = (char *)xmalloc (ttoklen + 4);
6244 /* if ADDDQ != 0 then (( ... )) -> "..." */
6245 if (rval == 1 && adddq) /* arith cmd, add double quotes */
6248 strncpy (tokstr + 1, ttok, ttoklen - 1);
6249 tokstr[ttoklen] = '"';
6250 tokstr[ttoklen+1] = '\0';
6252 else if (rval == 1) /* arith cmd, don't add double quotes */
6254 strncpy (tokstr, ttok, ttoklen - 1);
6255 tokstr[ttoklen-1] = '\0';
6257 else /* nested subshell */
6260 strncpy (tokstr + 1, ttok, ttoklen - 1);
6261 tokstr[ttoklen] = ')';
6262 tokstr[ttoklen+1] = c;
6263 tokstr[ttoklen+2] = '\0';
6270 #endif /* DPAREN_ARITHMETIC || ARITH_FOR_COMMAND */
6272 #if defined (COND_COMMAND)
6278 if (EOF_Reached && cond_token != COND_ERROR) /* [[ */
6279 parser_error (cond_lineno, _("unexpected EOF while looking for `]]'"));
6280 else if (cond_token != COND_ERROR)
6282 if (etext = error_token_from_token (cond_token))
6284 parser_error (cond_lineno, _("syntax error in conditional expression: unexpected token `%s'"), etext);
6288 parser_error (cond_lineno, _("syntax error in conditional expression"));
6295 return (cond_or ());
6304 if (cond_token == OR_OR)
6307 l = make_cond_node (COND_OR, (WORD_DESC *)NULL, l, r);
6318 if (cond_token == AND_AND)
6321 l = make_cond_node (COND_AND, (WORD_DESC *)NULL, l, r);
6327 cond_skip_newlines ()
6329 while ((cond_token = read_token (READ)) == '\n')
6331 if (SHOULD_PROMPT ())
6334 return (cond_token);
6337 #define COND_RETURN_ERROR() \
6338 do { cond_token = COND_ERROR; return ((COND_COM *)NULL); } while (0)
6344 COND_COM *term, *tleft, *tright;
6348 /* Read a token. It can be a left paren, a `!', a unary operator, or a
6349 word that should be the first argument of a binary operator. Start by
6350 skipping newlines, since this is a compound command. */
6351 tok = cond_skip_newlines ();
6352 lineno = line_number;
6353 if (tok == COND_END)
6355 COND_RETURN_ERROR ();
6357 else if (tok == '(')
6359 term = cond_expr ();
6360 if (cond_token != ')')
6363 dispose_cond_node (term); /* ( */
6364 if (etext = error_token_from_token (cond_token))
6366 parser_error (lineno, _("unexpected token `%s', expected `)'"), etext);
6370 parser_error (lineno, _("expected `)'"));
6371 COND_RETURN_ERROR ();
6373 term = make_cond_node (COND_EXPR, (WORD_DESC *)NULL, term, (COND_COM *)NULL);
6374 (void)cond_skip_newlines ();
6376 else if (tok == BANG || (tok == WORD && (yylval.word->word[0] == '!' && yylval.word->word[1] == '\0')))
6379 dispose_word (yylval.word); /* not needed */
6380 term = cond_term ();
6382 term->flags |= CMD_INVERT_RETURN;
6384 else if (tok == WORD && yylval.word->word[0] == '-' && yylval.word->word[2] == 0 && test_unop (yylval.word->word))
6387 tok = read_token (READ);
6390 tleft = make_cond_node (COND_TERM, yylval.word, (COND_COM *)NULL, (COND_COM *)NULL);
6391 term = make_cond_node (COND_UNARY, op, tleft, (COND_COM *)NULL);
6396 if (etext = error_token_from_token (tok))
6398 parser_error (line_number, _("unexpected argument `%s' to conditional unary operator"), etext);
6402 parser_error (line_number, _("unexpected argument to conditional unary operator"));
6403 COND_RETURN_ERROR ();
6406 (void)cond_skip_newlines ();
6408 else if (tok == WORD) /* left argument to binary operator */
6411 tleft = make_cond_node (COND_TERM, yylval.word, (COND_COM *)NULL, (COND_COM *)NULL);
6414 tok = read_token (READ);
6415 if (tok == WORD && test_binop (yylval.word->word))
6418 if (op->word[0] == '=' && (op->word[1] == '\0' || (op->word[1] == '=' && op->word[2] == '\0')))
6419 parser_state |= PST_EXTPAT;
6420 else if (op->word[0] == '!' && op->word[1] == '=' && op->word[2] == '\0')
6421 parser_state |= PST_EXTPAT;
6423 #if defined (COND_REGEXP)
6424 else if (tok == WORD && STREQ (yylval.word->word, "=~"))
6427 parser_state |= PST_REGEXP;
6430 else if (tok == '<' || tok == '>')
6431 op = make_word_from_token (tok); /* ( */
6432 /* There should be a check before blindly accepting the `)' that we have
6433 seen the opening `('. */
6434 else if (tok == COND_END || tok == AND_AND || tok == OR_OR || tok == ')')
6436 /* Special case. [[ x ]] is equivalent to [[ -n x ]], just like
6437 the test command. Similarly for [[ x && expr ]] or
6438 [[ x || expr ]] or [[ (x) ]]. */
6439 op = make_word ("-n");
6440 term = make_cond_node (COND_UNARY, op, tleft, (COND_COM *)NULL);
6446 if (etext = error_token_from_token (tok))
6448 parser_error (line_number, _("unexpected token `%s', conditional binary operator expected"), etext);
6452 parser_error (line_number, _("conditional binary operator expected"));
6453 dispose_cond_node (tleft);
6454 COND_RETURN_ERROR ();
6458 if (parser_state & PST_EXTPAT)
6460 tok = read_token (READ);
6461 if (parser_state & PST_EXTPAT)
6462 extended_glob = global_extglob;
6463 parser_state &= ~(PST_REGEXP|PST_EXTPAT);
6467 tright = make_cond_node (COND_TERM, yylval.word, (COND_COM *)NULL, (COND_COM *)NULL);
6468 term = make_cond_node (COND_BINARY, op, tleft, tright);
6472 if (etext = error_token_from_token (tok))
6474 parser_error (line_number, _("unexpected argument `%s' to conditional binary operator"), etext);
6478 parser_error (line_number, _("unexpected argument to conditional binary operator"));
6479 dispose_cond_node (tleft);
6481 COND_RETURN_ERROR ();
6484 (void)cond_skip_newlines ();
6489 parser_error (line_number, _("unexpected token `%c' in conditional command"), tok);
6490 else if (etext = error_token_from_token (tok))
6492 parser_error (line_number, _("unexpected token `%s' in conditional command"), etext);
6496 parser_error (line_number, _("unexpected token %d in conditional command"), tok);
6497 COND_RETURN_ERROR ();
6502 /* This is kind of bogus -- we slip a mini recursive-descent parser in
6503 here to handle the conditional statement syntax. */
6505 parse_cond_command ()
6509 global_extglob = extended_glob;
6510 cexp = cond_expr ();
6511 return (make_cond_command (cexp));
6515 #if defined (ARRAY_VARS)
6516 /* When this is called, it's guaranteed that we don't care about anything
6517 in t beyond i. We do save and restore the chars, though. */
6519 token_is_assignment (t, i)
6523 unsigned char c, c1;
6526 c = t[i]; c1 = t[i+1];
6527 t[i] = '='; t[i+1] = '\0';
6528 r = assignment (t, (parser_state & PST_COMPASSIGN) != 0);
6529 t[i] = c; t[i+1] = c1;
6533 /* XXX - possible changes here for `+=' */
6535 token_is_ident (t, i)
6544 r = legal_identifier (t);
6551 read_token_word (character)
6554 /* The value for YYLVAL when a WORD is read. */
6555 WORD_DESC *the_word;
6557 /* Index into the token that we are building. */
6560 /* ALL_DIGITS becomes zero when we see a non-digit. */
6561 int all_digit_token;
6563 /* DOLLAR_PRESENT becomes non-zero if we see a `$'. */
6566 /* COMPOUND_ASSIGNMENT becomes non-zero if we are parsing a compound
6568 int compound_assignment;
6570 /* QUOTED becomes non-zero if we see one of ("), ('), (`), or (\). */
6573 /* Non-zero means to ignore the value of the next character, and just
6574 to add it no matter what. */
6575 int pass_next_character;
6577 /* The current delimiting character. */
6579 int result, peek_char;
6580 char *ttok, *ttrans;
6581 int ttoklen, ttranslen;
6584 if (token_buffer_size < TOKEN_DEFAULT_INITIAL_SIZE)
6585 token = (char *)xrealloc (token, token_buffer_size = TOKEN_DEFAULT_INITIAL_SIZE);
6588 all_digit_token = DIGIT (character);
6589 dollar_present = quoted = pass_next_character = compound_assignment = 0;
6593 if (character == EOF)
6596 if (pass_next_character)
6598 pass_next_character = 0;
6599 goto got_escaped_character;
6602 cd = current_delimiter (dstack);
6604 /* Handle backslashes. Quote lots of things when not inside of
6605 double-quotes, quote some things inside of double-quotes. */
6606 if MBTEST(character == '\\')
6608 peek_char = shell_getc (0);
6610 /* Backslash-newline is ignored in all cases except
6611 when quoted with single quotes. */
6612 if (peek_char == '\n')
6615 goto next_character;
6619 shell_ungetc (peek_char);
6621 /* If the next character is to be quoted, note it now. */
6622 if (cd == 0 || cd == '`' ||
6623 (cd == '"' && peek_char >= 0 && (sh_syntaxtab[peek_char] & CBSDQUOTE)))
6624 pass_next_character++;
6631 /* Parse a matched pair of quote characters. */
6632 if MBTEST(shellquote (character))
6634 push_delimiter (dstack, character);
6635 ttok = parse_matched_pair (character, character, character, &ttoklen, (character == '`') ? P_COMMAND : 0);
6636 pop_delimiter (dstack);
6637 if (ttok == &matched_pair_error)
6638 return -1; /* Bail immediately. */
6639 RESIZE_MALLOCED_BUFFER (token, token_index, ttoklen + 2,
6640 token_buffer_size, TOKEN_DEFAULT_GROW_SIZE);
6641 token[token_index++] = character;
6642 strcpy (token + token_index, ttok);
6643 token_index += ttoklen;
6644 all_digit_token = 0;
6646 dollar_present |= (character == '"' && strchr (ttok, '$') != 0);
6648 goto next_character;
6652 /* When parsing a regexp as a single word inside a conditional command,
6653 we need to special-case characters special to both the shell and
6654 regular expressions. Right now, that is only '(' and '|'. */ /*)*/
6655 if MBTEST((parser_state & PST_REGEXP) && (character == '(' || character == '|')) /*)*/
6657 if (character == '|')
6660 push_delimiter (dstack, character);
6661 ttok = parse_matched_pair (cd, '(', ')', &ttoklen, 0);
6662 pop_delimiter (dstack);
6663 if (ttok == &matched_pair_error)
6664 return -1; /* Bail immediately. */
6665 RESIZE_MALLOCED_BUFFER (token, token_index, ttoklen + 2,
6666 token_buffer_size, TOKEN_DEFAULT_GROW_SIZE);
6667 token[token_index++] = character;
6668 strcpy (token + token_index, ttok);
6669 token_index += ttoklen;
6671 dollar_present = all_digit_token = 0;
6672 goto next_character;
6674 #endif /* COND_REGEXP */
6676 #ifdef EXTENDED_GLOB
6677 /* Parse a ksh-style extended pattern matching specification. */
6678 if MBTEST(extended_glob && PATTERN_CHAR (character))
6680 peek_char = shell_getc (1);
6681 if MBTEST(peek_char == '(') /* ) */
6683 push_delimiter (dstack, peek_char);
6684 ttok = parse_matched_pair (cd, '(', ')', &ttoklen, 0);
6685 pop_delimiter (dstack);
6686 if (ttok == &matched_pair_error)
6687 return -1; /* Bail immediately. */
6688 RESIZE_MALLOCED_BUFFER (token, token_index, ttoklen + 2,
6690 TOKEN_DEFAULT_GROW_SIZE);
6691 token[token_index++] = character;
6692 token[token_index++] = peek_char;
6693 strcpy (token + token_index, ttok);
6694 token_index += ttoklen;
6696 dollar_present = all_digit_token = 0;
6697 goto next_character;
6700 shell_ungetc (peek_char);
6702 #endif /* EXTENDED_GLOB */
6704 /* If the delimiter character is not single quote, parse some of
6705 the shell expansions that must be read as a single word. */
6706 if (shellexp (character))
6708 peek_char = shell_getc (1);
6709 /* $(...), <(...), >(...), $((...)), ${...}, and $[...] constructs */
6710 if MBTEST(peek_char == '(' || \
6711 ((peek_char == '{' || peek_char == '[') && character == '$')) /* ) ] } */
6713 if (peek_char == '{') /* } */
6714 ttok = parse_matched_pair (cd, '{', '}', &ttoklen, P_FIRSTCLOSE);
6715 else if (peek_char == '(') /* ) */
6717 /* XXX - push and pop the `(' as a delimiter for use by
6718 the command-oriented-history code. This way newlines
6719 appearing in the $(...) string get added to the
6720 history literally rather than causing a possibly-
6721 incorrect `;' to be added. ) */
6722 push_delimiter (dstack, peek_char);
6723 ttok = parse_comsub (cd, '(', ')', &ttoklen, P_COMMAND);
6724 pop_delimiter (dstack);
6727 ttok = parse_matched_pair (cd, '[', ']', &ttoklen, 0);
6728 if (ttok == &matched_pair_error)
6729 return -1; /* Bail immediately. */
6730 RESIZE_MALLOCED_BUFFER (token, token_index, ttoklen + 2,
6732 TOKEN_DEFAULT_GROW_SIZE);
6733 token[token_index++] = character;
6734 token[token_index++] = peek_char;
6735 strcpy (token + token_index, ttok);
6736 token_index += ttoklen;
6739 all_digit_token = 0;
6740 goto next_character;
6742 /* This handles $'...' and $"..." new-style quoted strings. */
6743 else if MBTEST(character == '$' && (peek_char == '\'' || peek_char == '"'))
6747 first_line = line_number;
6748 push_delimiter (dstack, peek_char);
6749 ttok = parse_matched_pair (peek_char, peek_char, peek_char,
6751 (peek_char == '\'') ? P_ALLOWESC : 0);
6752 pop_delimiter (dstack);
6753 if (ttok == &matched_pair_error)
6755 if (peek_char == '\'')
6757 ttrans = ansiexpand (ttok, 0, ttoklen - 1, &ttranslen);
6760 /* Insert the single quotes and correctly quote any
6761 embedded single quotes (allowed because P_ALLOWESC was
6762 passed to parse_matched_pair). */
6763 ttok = sh_single_quote (ttrans);
6765 ttranslen = strlen (ttok);
6770 /* Try to locale-expand the converted string. */
6771 ttrans = localeexpand (ttok, 0, ttoklen - 1, first_line, &ttranslen);
6774 /* Add the double quotes back */
6775 ttok = sh_mkdoublequoted (ttrans, ttranslen, 0);
6781 RESIZE_MALLOCED_BUFFER (token, token_index, ttranslen + 2,
6783 TOKEN_DEFAULT_GROW_SIZE);
6784 strcpy (token + token_index, ttrans);
6785 token_index += ttranslen;
6788 all_digit_token = 0;
6789 goto next_character;
6791 /* This could eventually be extended to recognize all of the
6792 shell's single-character parameter expansions, and set flags.*/
6793 else if MBTEST(character == '$' && peek_char == '$')
6795 ttok = (char *)xmalloc (3);
6796 ttok[0] = ttok[1] = '$';
6798 RESIZE_MALLOCED_BUFFER (token, token_index, 3,
6800 TOKEN_DEFAULT_GROW_SIZE);
6801 strcpy (token + token_index, ttok);
6804 all_digit_token = 0;
6806 goto next_character;
6809 shell_ungetc (peek_char);
6812 #if defined (ARRAY_VARS)
6813 /* Identify possible array subscript assignment; match [...]. If
6814 parser_state&PST_COMPASSIGN, we need to parse [sub]=words treating
6815 `sub' as if it were enclosed in double quotes. */
6816 else if MBTEST(character == '[' && /* ] */
6817 ((token_index > 0 && assignment_acceptable (last_read_token) && token_is_ident (token, token_index)) ||
6818 (token_index == 0 && (parser_state&PST_COMPASSIGN))))
6820 ttok = parse_matched_pair (cd, '[', ']', &ttoklen, P_ARRAYSUB);
6821 if (ttok == &matched_pair_error)
6822 return -1; /* Bail immediately. */
6823 RESIZE_MALLOCED_BUFFER (token, token_index, ttoklen + 2,
6825 TOKEN_DEFAULT_GROW_SIZE);
6826 token[token_index++] = character;
6827 strcpy (token + token_index, ttok);
6828 token_index += ttoklen;
6830 all_digit_token = 0;
6831 goto next_character;
6833 /* Identify possible compound array variable assignment. */
6834 else if MBTEST(character == '=' && token_index > 0 && (assignment_acceptable (last_read_token) || (parser_state & PST_ASSIGNOK)) && token_is_assignment (token, token_index))
6836 peek_char = shell_getc (1);
6837 if MBTEST(peek_char == '(') /* ) */
6839 ttok = parse_compound_assignment (&ttoklen);
6841 RESIZE_MALLOCED_BUFFER (token, token_index, ttoklen + 4,
6843 TOKEN_DEFAULT_GROW_SIZE);
6845 token[token_index++] = '=';
6846 token[token_index++] = '(';
6849 strcpy (token + token_index, ttok);
6850 token_index += ttoklen;
6852 token[token_index++] = ')';
6854 all_digit_token = 0;
6855 compound_assignment = 1;
6857 goto next_character;
6859 goto got_token; /* ksh93 seems to do this */
6863 shell_ungetc (peek_char);
6867 /* When not parsing a multi-character word construct, shell meta-
6868 characters break words. */
6869 if MBTEST(shellbreak (character))
6871 shell_ungetc (character);
6877 if (character == CTLESC || character == CTLNUL)
6878 token[token_index++] = CTLESC;
6880 got_escaped_character:
6882 all_digit_token &= DIGIT (character);
6883 dollar_present |= character == '$';
6885 token[token_index++] = character;
6887 RESIZE_MALLOCED_BUFFER (token, token_index, 1, token_buffer_size,
6888 TOKEN_DEFAULT_GROW_SIZE);
6891 if (character == '\n' && SHOULD_PROMPT ())
6894 /* We want to remove quoted newlines (that is, a \<newline> pair)
6895 unless we are within single quotes or pass_next_character is
6896 set (the shell equivalent of literal-next). */
6897 cd = current_delimiter (dstack);
6898 character = shell_getc (cd != '\'' && pass_next_character == 0);
6899 } /* end for (;;) */
6903 token[token_index] = '\0';
6905 /* Check to see what thing we should return. If the last_read_token
6906 is a `<', or a `&', or the character which ended this token is
6907 a '>' or '<', then, and ONLY then, is this input token a NUMBER.
6908 Otherwise, it is just a word, and should be returned as such. */
6909 if MBTEST(all_digit_token && (character == '<' || character == '>' || \
6910 last_read_token == LESS_AND || \
6911 last_read_token == GREATER_AND))
6913 if (legal_number (token, &lvalue) && (int)lvalue == lvalue)
6914 yylval.number = lvalue;
6920 /* Check for special case tokens. */
6921 result = (last_shell_getc_is_singlebyte) ? special_case_tokens (token) : -1;
6926 /* Posix.2 does not allow reserved words to be aliased, so check for all
6927 of them, including special cases, before expanding the current token
6929 if MBTEST(posixly_correct)
6930 CHECK_FOR_RESERVED_WORD (token);
6932 /* Aliases are expanded iff EXPAND_ALIASES is non-zero, and quoting
6933 inhibits alias expansion. */
6934 if (expand_aliases && quoted == 0)
6936 result = alias_expand_token (token);
6937 if (result == RE_READ_TOKEN)
6938 return (RE_READ_TOKEN);
6939 else if (result == NO_EXPANSION)
6940 parser_state &= ~PST_ALEXPNEXT;
6943 /* If not in Posix.2 mode, check for reserved words after alias
6945 if MBTEST(posixly_correct == 0)
6947 CHECK_FOR_RESERVED_WORD (token);
6949 the_word = (WORD_DESC *)xmalloc (sizeof (WORD_DESC));
6950 the_word->word = (char *)xmalloc (1 + token_index);
6951 the_word->flags = 0;
6952 strcpy (the_word->word, token);
6954 the_word->flags |= W_HASDOLLAR;
6956 the_word->flags |= W_QUOTED; /*(*/
6957 if (compound_assignment && token[token_index-1] == ')')
6958 the_word->flags |= W_COMPASSIGN;
6959 /* A word is an assignment if it appears at the beginning of a
6960 simple command, or after another assignment word. This is
6961 context-dependent, so it cannot be handled in the grammar. */
6962 if (assignment (token, (parser_state & PST_COMPASSIGN) != 0))
6964 the_word->flags |= W_ASSIGNMENT;
6965 /* Don't perform word splitting on assignment statements. */
6966 if (assignment_acceptable (last_read_token) || (parser_state & PST_COMPASSIGN) != 0)
6967 the_word->flags |= W_NOSPLIT;
6970 if (command_token_position (last_read_token))
6973 b = builtin_address_internal (token, 0);
6974 if (b && (b->flags & ASSIGNMENT_BUILTIN))
6975 parser_state |= PST_ASSIGNOK;
6976 else if (STREQ (token, "eval") || STREQ (token, "let"))
6977 parser_state |= PST_ASSIGNOK;
6980 yylval.word = the_word;
6982 if (token[0] == '{' && token[token_index-1] == '}' &&
6983 (character == '<' || character == '>'))
6985 /* can use token; already copied to the_word */
6986 token[token_index-1] = '\0';
6987 if (legal_identifier (token+1))
6989 strcpy (the_word->word, token+1);
6990 /*itrace("read_token_word: returning REDIR_WORD for %s", the_word->word);*/
6991 return (REDIR_WORD);
6995 result = ((the_word->flags & (W_ASSIGNMENT|W_NOSPLIT)) == (W_ASSIGNMENT|W_NOSPLIT))
6996 ? ASSIGNMENT_WORD : WORD;
6998 switch (last_read_token)
7001 parser_state |= PST_ALLOWOPNBRC;
7002 function_dstart = line_number;
7007 if (word_top < MAX_CASE_NEST)
7009 word_lineno[word_top] = line_number;
7016 /* Return 1 if TOKSYM is a token that after being read would allow
7017 a reserved word to be seen, else 0. */
7019 reserved_word_acceptable (toksym)
7055 #if defined (COPROCESS_SUPPORT)
7056 if (last_read_token == WORD && token_before_that == COPROC)
7063 /* Return the index of TOKEN in the alist of reserved words, or -1 if
7064 TOKEN is not a shell reserved word. */
7066 find_reserved_word (tokstr)
7070 for (i = 0; word_token_alist[i].word; i++)
7071 if (STREQ (tokstr, word_token_alist[i].word))
7077 #if defined (READLINE)
7078 /* Called after each time readline is called. This insures that whatever
7079 the new prompt string is gets propagated to readline's local prompt
7082 reset_readline_prompt ()
7086 if (prompt_string_pointer)
7088 temp_prompt = (*prompt_string_pointer)
7089 ? decode_prompt_string (*prompt_string_pointer)
7092 if (temp_prompt == 0)
7094 temp_prompt = (char *)xmalloc (1);
7095 temp_prompt[0] = '\0';
7098 FREE (current_readline_prompt);
7099 current_readline_prompt = temp_prompt;
7102 #endif /* READLINE */
7105 #if defined (HISTORY)
7106 /* A list of tokens which can be followed by newlines, but not by
7107 semi-colons. When concatenating multiple lines of history, the
7108 newline separator for such tokens is replaced with a space. */
7109 static const int no_semi_successors[] = {
7110 '\n', '{', '(', ')', ';', '&', '|',
7111 CASE, DO, ELSE, IF, SEMI_SEMI, SEMI_AND, SEMI_SEMI_AND, THEN, UNTIL,
7112 WHILE, AND_AND, OR_OR, IN,
7116 /* If we are not within a delimited expression, try to be smart
7117 about which separators can be semi-colons and which must be
7118 newlines. Returns the string that should be added into the
7121 history_delimiting_chars ()
7125 if (dstack.delimiter_depth != 0)
7128 /* We look for current_command_line_count == 2 because we are looking to
7129 add the first line of the body of the here document (the second line
7131 if (parser_state & PST_HEREDOC)
7132 return (current_command_line_count == 2 ? "\n" : "");
7134 /* First, handle some special cases. */
7136 /* If we just read `()', assume it's a function definition, and don't
7137 add a semicolon. If the token before the `)' was not `(', and we're
7138 not in the midst of parsing a case statement, assume it's a
7139 parenthesized command and add the semicolon. */
7141 if (token_before_that == ')')
7143 if (two_tokens_ago == '(') /*)*/ /* function def */
7145 /* This does not work for subshells inside case statement
7146 command lists. It's a suboptimal solution. */
7147 else if (parser_state & PST_CASESTMT) /* case statement pattern */
7150 return "; "; /* (...) subshell */
7152 else if (token_before_that == WORD && two_tokens_ago == FUNCTION)
7153 return " "; /* function def using `function name' without `()' */
7155 else if (token_before_that == WORD && two_tokens_ago == FOR)
7157 /* Tricky. `for i\nin ...' should not have a semicolon, but
7158 `for i\ndo ...' should. We do what we can. */
7159 for (i = shell_input_line_index; whitespace (shell_input_line[i]); i++)
7161 if (shell_input_line[i] && shell_input_line[i] == 'i' && shell_input_line[i+1] == 'n')
7165 else if (two_tokens_ago == CASE && token_before_that == WORD && (parser_state & PST_CASESTMT))
7168 for (i = 0; no_semi_successors[i]; i++)
7170 if (token_before_that == no_semi_successors[i])
7176 #endif /* HISTORY */
7178 /* Issue a prompt, or prepare to issue a prompt when the next character
7185 if (interactive == 0 || expanding_alias ()) /* XXX */
7188 ps1_prompt = get_string_value ("PS1");
7189 ps2_prompt = get_string_value ("PS2");
7191 if (!prompt_string_pointer)
7192 prompt_string_pointer = &ps1_prompt;
7194 temp_prompt = *prompt_string_pointer
7195 ? decode_prompt_string (*prompt_string_pointer)
7198 if (temp_prompt == 0)
7200 temp_prompt = (char *)xmalloc (1);
7201 temp_prompt[0] = '\0';
7204 current_prompt_string = *prompt_string_pointer;
7205 prompt_string_pointer = &ps2_prompt;
7207 #if defined (READLINE)
7208 if (!no_line_editing)
7210 FREE (current_readline_prompt);
7211 current_readline_prompt = temp_prompt;
7214 #endif /* READLINE */
7216 FREE (current_decoded_prompt);
7217 current_decoded_prompt = temp_prompt;
7222 get_current_prompt_level ()
7224 return ((current_prompt_string && current_prompt_string == ps2_prompt) ? 2 : 1);
7228 set_current_prompt_level (x)
7231 prompt_string_pointer = (x == 2) ? &ps2_prompt : &ps1_prompt;
7232 current_prompt_string = *prompt_string_pointer;
7238 fprintf (stderr, "%s", current_decoded_prompt);
7242 /* Return a string which will be printed as a prompt. The string
7243 may contain special characters which are decoded as follows:
7246 \d the date in Day Mon Date format
7247 \e escape (ascii 033)
7248 \h the hostname up to the first `.'
7250 \j the number of active jobs
7251 \l the basename of the shell's tty device name
7254 \s the name of the shell
7255 \t the time in 24-hour hh:mm:ss format
7256 \T the time in 12-hour hh:mm:ss format
7257 \@ the time in 12-hour hh:mm am/pm format
7258 \A the time in 24-hour hh:mm format
7259 \D{fmt} the result of passing FMT to strftime(3)
7261 \v the version of bash (e.g., 2.00)
7262 \V the release of bash, version + patchlevel (e.g., 2.00.0)
7263 \w the current working directory
7264 \W the last element of $PWD
7265 \! the history number of this command
7266 \# the command number of this command
7267 \$ a $ or a # if you are root
7268 \nnn character code nnn in octal
7270 \[ begin a sequence of non-printing chars
7271 \] end a sequence of non-printing chars
7273 #define PROMPT_GROWTH 48
7275 decode_prompt_string (string)
7280 struct dstack save_dstack;
7281 int last_exit_value, last_comsub_pid;
7282 #if defined (PROMPT_STRING_DECODE)
7283 int result_size, result_index;
7285 char *temp, octal_string[4];
7291 result = (char *)xmalloc (result_size = PROMPT_GROWTH);
7292 result[result_index = 0] = 0;
7293 temp = (char *)NULL;
7295 while (c = *string++)
7297 if (posixly_correct && c == '!')
7301 temp = savestring ("!");
7306 #if !defined (HISTORY)
7307 temp = savestring ("1");
7309 temp = itos (history_number ());
7310 #endif /* HISTORY */
7311 string--; /* add_string increments string again. */
7329 strncpy (octal_string, string, 3);
7330 octal_string[3] = '\0';
7332 n = read_octal (octal_string);
7333 temp = (char *)xmalloc (3);
7335 if (n == CTLESC || n == CTLNUL)
7352 for (c = 0; n != -1 && c < 3 && ISOCTAL (*string); c++)
7355 c = 0; /* tested at add_string: */
7363 /* Make the current time/date into a string. */
7364 (void) time (&the_time);
7365 tm = localtime (&the_time);
7368 n = strftime (timebuf, sizeof (timebuf), "%a %b %d", tm);
7370 n = strftime (timebuf, sizeof (timebuf), "%H:%M:%S", tm);
7372 n = strftime (timebuf, sizeof (timebuf), "%I:%M:%S", tm);
7374 n = strftime (timebuf, sizeof (timebuf), "%I:%M %p", tm);
7376 n = strftime (timebuf, sizeof (timebuf), "%H:%M", tm);
7381 timebuf[sizeof(timebuf) - 1] = '\0';
7383 temp = savestring (timebuf);
7386 case 'D': /* strftime format */
7387 if (string[1] != '{') /* } */
7390 (void) time (&the_time);
7391 tm = localtime (&the_time);
7392 string += 2; /* skip { */
7393 timefmt = xmalloc (strlen (string) + 3);
7394 for (t = timefmt; *string && *string != '}'; )
7397 c = *string; /* tested at add_string */
7398 if (timefmt[0] == '\0')
7401 timefmt[1] = 'X'; /* locale-specific current time */
7404 n = strftime (timebuf, sizeof (timebuf), timefmt, tm);
7410 timebuf[sizeof(timebuf) - 1] = '\0';
7412 if (promptvars || posixly_correct)
7413 /* Make sure that expand_prompt_string is called with a
7414 second argument of Q_DOUBLE_QUOTES if we use this
7416 temp = sh_backslash_quote_for_double_quotes (timebuf);
7418 temp = savestring (timebuf);
7422 temp = (char *)xmalloc (3);
7423 temp[0] = no_line_editing ? '\n' : '\r';
7424 temp[1] = no_line_editing ? '\0' : '\n';
7429 temp = base_pathname (shell_name);
7430 temp = savestring (temp);
7435 temp = (char *)xmalloc (16);
7437 strcpy (temp, dist_version);
7439 sprintf (temp, "%s.%d", dist_version, patch_level);
7445 /* Use the value of PWD because it is much more efficient. */
7446 char t_string[PATH_MAX];
7449 temp = get_string_value ("PWD");
7453 if (getcwd (t_string, sizeof(t_string)) == 0)
7459 tlen = strlen (t_string);
7463 tlen = sizeof (t_string) - 1;
7464 strncpy (t_string, temp, tlen);
7466 t_string[tlen] = '\0';
7468 #if defined (MACOSX)
7469 /* Convert from "fs" format to "input" format */
7470 temp = fnx_fromfs (t_string, strlen (t_string));
7471 if (temp != t_string)
7472 strcpy (t_string, temp);
7475 #define ROOT_PATH(x) ((x)[0] == '/' && (x)[1] == 0)
7476 #define DOUBLE_SLASH_ROOT(x) ((x)[0] == '/' && (x)[1] == '/' && (x)[2] == 0)
7477 /* Abbreviate \W as ~ if $PWD == $HOME */
7478 if (c == 'W' && (((t = get_string_value ("HOME")) == 0) || STREQ (t, t_string) == 0))
7480 if (ROOT_PATH (t_string) == 0 && DOUBLE_SLASH_ROOT (t_string) == 0)
7482 t = strrchr (t_string, '/');
7484 memmove (t_string, t + 1, strlen (t));
7488 #undef DOUBLE_SLASH_ROOT
7490 /* polite_directory_format is guaranteed to return a string
7491 no longer than PATH_MAX - 1 characters. */
7492 strcpy (t_string, polite_directory_format (t_string));
7494 temp = trim_pathname (t_string, PATH_MAX - 1);
7495 /* If we're going to be expanding the prompt string later,
7496 quote the directory name. */
7497 if (promptvars || posixly_correct)
7498 /* Make sure that expand_prompt_string is called with a
7499 second argument of Q_DOUBLE_QUOTES if we use this
7501 temp = sh_backslash_quote_for_double_quotes (t_string);
7503 temp = savestring (t_string);
7509 if (current_user.user_name == 0)
7510 get_current_user_info ();
7511 temp = savestring (current_user.user_name);
7516 temp = savestring (current_host_name);
7517 if (c == 'h' && (t = (char *)strchr (temp, '.')))
7522 temp = itos (current_command_number);
7526 #if !defined (HISTORY)
7527 temp = savestring ("1");
7529 temp = itos (history_number ());
7530 #endif /* HISTORY */
7534 t = temp = (char *)xmalloc (3);
7535 if ((promptvars || posixly_correct) && (current_user.euid != 0))
7537 *t++ = current_user.euid == 0 ? '#' : '$';
7542 temp = itos (count_all_jobs ());
7546 #if defined (HAVE_TTYNAME)
7547 temp = (char *)ttyname (fileno (stdin));
7548 t = temp ? base_pathname (temp) : "tty";
7549 temp = savestring (t);
7551 temp = savestring ("tty");
7552 #endif /* !HAVE_TTYNAME */
7555 #if defined (READLINE)
7558 if (no_line_editing)
7563 temp = (char *)xmalloc (3);
7564 n = (c == '[') ? RL_PROMPT_START_IGNORE : RL_PROMPT_END_IGNORE;
7566 if (n == CTLESC || n == CTLNUL)
7571 #endif /* READLINE */
7577 temp = (char *)xmalloc (2);
7584 else /* (c == '\\') */
7591 temp = (char *)xmalloc (3);
7600 sub_append_string (temp, result, &result_index, &result_size);
7601 temp = (char *)NULL; /* Freed in sub_append_string (). */
7602 result[result_index] = '\0';
7608 RESIZE_MALLOCED_BUFFER (result, result_index, 3, result_size, PROMPT_GROWTH);
7609 result[result_index++] = c;
7610 result[result_index] = '\0';
7613 #else /* !PROMPT_STRING_DECODE */
7614 result = savestring (string);
7615 #endif /* !PROMPT_STRING_DECODE */
7617 /* Save the delimiter stack and point `dstack' to temp space so any
7618 command substitutions in the prompt string won't result in screwing
7619 up the parser's quoting state. */
7620 save_dstack = dstack;
7621 dstack = temp_dstack;
7622 dstack.delimiter_depth = 0;
7624 /* Perform variable and parameter expansion and command substitution on
7625 the prompt string. */
7626 if (promptvars || posixly_correct)
7628 last_exit_value = last_command_exit_value;
7629 last_comsub_pid = last_command_subst_pid;
7630 list = expand_prompt_string (result, Q_DOUBLE_QUOTES, 0);
7632 result = string_list (list);
7633 dispose_words (list);
7634 last_command_exit_value = last_exit_value;
7635 last_command_subst_pid = last_comsub_pid;
7639 t = dequote_string (result);
7644 dstack = save_dstack;
7649 /************************************************
7653 ************************************************/
7655 /* Report a syntax error, and restart the parser. Call here for fatal
7661 report_syntax_error ((char *)NULL);
7667 error_token_from_token (tok)
7672 if (t = find_token_in_alist (tok, word_token_alist, 0))
7675 if (t = find_token_in_alist (tok, other_token_alist, 0))
7679 /* This stuff is dicy and needs closer inspection */
7680 switch (current_token)
7683 case ASSIGNMENT_WORD:
7685 t = savestring (yylval.word->word);
7688 t = itos (yylval.number);
7691 if (yylval.word_list)
7692 t = string_list (yylval.word_list);
7694 case ARITH_FOR_EXPRS:
7695 if (yylval.word_list)
7696 t = string_list_internal (yylval.word_list, " ; ");
7699 t = (char *)NULL; /* punt */
7707 error_token_from_text ()
7712 t = shell_input_line;
7713 i = shell_input_line_index;
7717 if (i && t[i] == '\0')
7720 while (i && (whitespace (t[i]) || t[i] == '\n'))
7726 while (i && (member (t[i], " \n\t;|&") == 0))
7729 while (i != token_end && (whitespace (t[i]) || t[i] == '\n'))
7732 /* Return our idea of the offending token. */
7733 if (token_end || (i == 0 && token_end == 0))
7736 msg = substring (t, i, token_end);
7737 else /* one-character token */
7739 msg = (char *)xmalloc (2);
7749 print_offending_line ()
7754 msg = savestring (shell_input_line);
7755 token_end = strlen (msg);
7756 while (token_end && msg[token_end - 1] == '\n')
7757 msg[--token_end] = '\0';
7759 parser_error (line_number, "`%s'", msg);
7763 /* Report a syntax error with line numbers, etc.
7764 Call here for recoverable errors. If you have a message to print,
7765 then place it in MESSAGE, otherwise pass NULL and this will figure
7766 out an appropriate message for you. */
7768 report_syntax_error (message)
7775 parser_error (line_number, "%s", message);
7776 if (interactive && EOF_Reached)
7778 last_command_exit_value = parse_and_execute_level ? EX_BADSYNTAX : EX_BADUSAGE;
7782 /* If the line of input we're reading is not null, try to find the
7783 objectionable token. First, try to figure out what token the
7784 parser's complaining about by looking at current_token. */
7785 if (current_token != 0 && EOF_Reached == 0 && (msg = error_token_from_token (current_token)))
7787 parser_error (line_number, _("syntax error near unexpected token `%s'"), msg);
7790 if (interactive == 0)
7791 print_offending_line ();
7793 last_command_exit_value = parse_and_execute_level ? EX_BADSYNTAX : EX_BADUSAGE;
7797 /* If looking at the current token doesn't prove fruitful, try to find the
7798 offending token by analyzing the text of the input line near the current
7799 input line index and report what we find. */
7800 if (shell_input_line && *shell_input_line)
7802 msg = error_token_from_text ();
7805 parser_error (line_number, _("syntax error near `%s'"), msg);
7809 /* If not interactive, print the line containing the error. */
7810 if (interactive == 0)
7811 print_offending_line ();
7815 msg = EOF_Reached ? _("syntax error: unexpected end of file") : _("syntax error");
7816 parser_error (line_number, "%s", msg);
7817 /* When the shell is interactive, this file uses EOF_Reached
7818 only for error reporting. Other mechanisms are used to
7819 decide whether or not to exit. */
7820 if (interactive && EOF_Reached)
7824 last_command_exit_value = parse_and_execute_level ? EX_BADSYNTAX : EX_BADUSAGE;
7827 /* ??? Needed function. ??? We have to be able to discard the constructs
7828 created during parsing. In the case of error, we want to return
7829 allocated objects to the memory pool. In the case of no error, we want
7830 to throw away the information about where the allocated objects live.
7831 (dispose_command () will actually free the command.) */
7833 discard_parser_constructs (error_p)
7838 /************************************************
7842 ************************************************/
7844 /* Do that silly `type "bye" to exit' stuff. You know, "ignoreeof". */
7846 /* A flag denoting whether or not ignoreeof is set. */
7849 /* The number of times that we have encountered an EOF character without
7850 another character intervening. When this gets above the limit, the
7851 shell terminates. */
7852 int eof_encountered = 0;
7854 /* The limit for eof_encountered. */
7855 int eof_encountered_limit = 10;
7857 /* If we have EOF as the only input unit, this user wants to leave
7858 the shell. If the shell is not interactive, then just leave.
7859 Otherwise, if ignoreeof is set, and we haven't done this the
7860 required number of times in a row, print a message. */
7862 handle_eof_input_unit ()
7866 /* shell.c may use this to decide whether or not to write out the
7867 history, among other things. We use it only for error reporting
7872 /* If the user wants to "ignore" eof, then let her do so, kind of. */
7875 if (eof_encountered < eof_encountered_limit)
7877 fprintf (stderr, _("Use \"%s\" to leave the shell.\n"),
7878 login_shell ? "logout" : "exit");
7880 /* Reset the parsing state. */
7881 last_read_token = current_token = '\n';
7882 /* Reset the prompt string to be $PS1. */
7883 prompt_string_pointer = (char **)NULL;
7889 /* In this case EOF should exit the shell. Do it now. */
7891 exit_builtin ((WORD_LIST *)NULL);
7895 /* We don't write history files, etc., for non-interactive shells. */
7900 /************************************************
7902 * STRING PARSING FUNCTIONS *
7904 ************************************************/
7906 /* It's very important that these two functions treat the characters
7907 between ( and ) identically. */
7909 static WORD_LIST parse_string_error;
7911 /* Take a string and run it through the shell parser, returning the
7912 resultant word list. Used by compound array assignment. */
7914 parse_string_to_word_list (s, flags, whom)
7920 int tok, orig_current_token, orig_line_number, orig_input_terminator;
7921 int orig_line_count;
7922 int old_echo_input, old_expand_aliases;
7923 #if defined (HISTORY)
7924 int old_remember_on_history, old_history_expansion_inhibited;
7927 #if defined (HISTORY)
7928 old_remember_on_history = remember_on_history;
7929 # if defined (BANG_HISTORY)
7930 old_history_expansion_inhibited = history_expansion_inhibited;
7932 bash_history_disable ();
7935 orig_line_number = line_number;
7936 orig_line_count = current_command_line_count;
7937 orig_input_terminator = shell_input_line_terminator;
7938 old_echo_input = echo_input_at_read;
7939 old_expand_aliases = expand_aliases;
7942 last_read_token = WORD; /* WORD to allow reserved words here */
7943 current_command_line_count = 0;
7944 echo_input_at_read = expand_aliases = 0;
7946 with_input_from_string (s, whom);
7947 wl = (WORD_LIST *)NULL;
7950 parser_state |= PST_COMPASSIGN|PST_REPARSE;
7952 while ((tok = read_token (READ)) != yacc_EOF)
7954 if (tok == '\n' && *bash_input.location.string == '\0')
7956 if (tok == '\n') /* Allow newlines in compound assignments */
7958 if (tok != WORD && tok != ASSIGNMENT_WORD)
7960 line_number = orig_line_number + line_number - 1;
7961 orig_current_token = current_token;
7962 current_token = tok;
7963 yyerror (NULL); /* does the right thing */
7964 current_token = orig_current_token;
7967 wl = &parse_string_error;
7970 wl = make_word_list (yylval.word, wl);
7973 last_read_token = '\n';
7976 #if defined (HISTORY)
7977 remember_on_history = old_remember_on_history;
7978 # if defined (BANG_HISTORY)
7979 history_expansion_inhibited = old_history_expansion_inhibited;
7980 # endif /* BANG_HISTORY */
7981 #endif /* HISTORY */
7983 echo_input_at_read = old_echo_input;
7984 expand_aliases = old_expand_aliases;
7986 current_command_line_count = orig_line_count;
7987 shell_input_line_terminator = orig_input_terminator;
7990 parser_state &= ~(PST_COMPASSIGN|PST_REPARSE);
7992 if (wl == &parse_string_error)
7994 last_command_exit_value = EXECUTION_FAILURE;
7995 if (interactive_shell == 0 && posixly_correct)
7996 jump_to_top_level (FORCE_EOF);
7998 jump_to_top_level (DISCARD);
8001 return (REVERSE_LIST (wl, WORD_LIST *));
8005 parse_compound_assignment (retlenp)
8009 int tok, orig_line_number, orig_token_size, orig_last_token, assignok;
8010 char *saved_token, *ret;
8012 saved_token = token;
8013 orig_token_size = token_buffer_size;
8014 orig_line_number = line_number;
8015 orig_last_token = last_read_token;
8017 last_read_token = WORD; /* WORD to allow reserved words here */
8019 token = (char *)NULL;
8020 token_buffer_size = 0;
8022 assignok = parser_state&PST_ASSIGNOK; /* XXX */
8024 wl = (WORD_LIST *)NULL; /* ( */
8025 parser_state |= PST_COMPASSIGN;
8027 while ((tok = read_token (READ)) != ')')
8029 if (tok == '\n') /* Allow newlines in compound assignments */
8031 if (SHOULD_PROMPT ())
8035 if (tok != WORD && tok != ASSIGNMENT_WORD)
8037 current_token = tok; /* for error reporting */
8038 if (tok == yacc_EOF) /* ( */
8039 parser_error (orig_line_number, _("unexpected EOF while looking for matching `)'"));
8041 yyerror(NULL); /* does the right thing */
8044 wl = &parse_string_error;
8047 wl = make_word_list (yylval.word, wl);
8051 token = saved_token;
8052 token_buffer_size = orig_token_size;
8054 parser_state &= ~PST_COMPASSIGN;
8056 if (wl == &parse_string_error)
8058 last_command_exit_value = EXECUTION_FAILURE;
8059 last_read_token = '\n'; /* XXX */
8060 if (interactive_shell == 0 && posixly_correct)
8061 jump_to_top_level (FORCE_EOF);
8063 jump_to_top_level (DISCARD);
8066 last_read_token = orig_last_token; /* XXX - was WORD? */
8070 rl = REVERSE_LIST (wl, WORD_LIST *);
8071 ret = string_list (rl);
8078 *retlenp = (ret && *ret) ? strlen (ret) : 0;
8081 parser_state |= PST_ASSIGNOK;
8086 /************************************************
8088 * SAVING AND RESTORING PARTIAL PARSE STATE *
8090 ************************************************/
8093 save_parser_state (ps)
8094 sh_parser_state_t *ps;
8096 #if defined (ARRAY_VARS)
8101 ps = (sh_parser_state_t *)xmalloc (sizeof (sh_parser_state_t));
8103 return ((sh_parser_state_t *)NULL);
8105 ps->parser_state = parser_state;
8106 ps->token_state = save_token_state ();
8108 ps->input_line_terminator = shell_input_line_terminator;
8109 ps->eof_encountered = eof_encountered;
8111 ps->current_command_line_count = current_command_line_count;
8113 #if defined (HISTORY)
8114 ps->remember_on_history = remember_on_history;
8115 # if defined (BANG_HISTORY)
8116 ps->history_expansion_inhibited = history_expansion_inhibited;
8120 ps->last_command_exit_value = last_command_exit_value;
8121 #if defined (ARRAY_VARS)
8122 v = find_variable ("PIPESTATUS");
8123 if (v && array_p (v) && array_cell (v))
8124 ps->pipestatus = array_copy (array_cell (v));
8126 ps->pipestatus = (ARRAY *)NULL;
8129 ps->last_shell_builtin = last_shell_builtin;
8130 ps->this_shell_builtin = this_shell_builtin;
8132 ps->expand_aliases = expand_aliases;
8133 ps->echo_input_at_read = echo_input_at_read;
8139 restore_parser_state (ps)
8140 sh_parser_state_t *ps;
8142 #if defined (ARRAY_VARS)
8149 parser_state = ps->parser_state;
8150 if (ps->token_state)
8152 restore_token_state (ps->token_state);
8153 free (ps->token_state);
8156 shell_input_line_terminator = ps->input_line_terminator;
8157 eof_encountered = ps->eof_encountered;
8159 current_command_line_count = ps->current_command_line_count;
8161 #if defined (HISTORY)
8162 remember_on_history = ps->remember_on_history;
8163 # if defined (BANG_HISTORY)
8164 history_expansion_inhibited = ps->history_expansion_inhibited;
8168 last_command_exit_value = ps->last_command_exit_value;
8169 #if defined (ARRAY_VARS)
8170 v = find_variable ("PIPESTATUS");
8171 if (v && array_p (v) && array_cell (v))
8173 array_dispose (array_cell (v));
8174 var_setarray (v, ps->pipestatus);
8178 last_shell_builtin = ps->last_shell_builtin;
8179 this_shell_builtin = ps->this_shell_builtin;
8181 expand_aliases = ps->expand_aliases;
8182 echo_input_at_read = ps->echo_input_at_read;
8185 /************************************************
8187 * MULTIBYTE CHARACTER HANDLING *
8189 ************************************************/
8191 #if defined (HANDLE_MULTIBYTE)
8195 int i, previ, len, c;
8196 mbstate_t mbs, prevs;
8199 if (shell_input_line == NULL)
8201 len = strlen (shell_input_line); /* XXX - shell_input_line_len ? */
8202 FREE (shell_input_line_property);
8203 shell_input_line_property = (char *)xmalloc (len + 1);
8205 memset (&prevs, '\0', sizeof (mbstate_t));
8206 for (i = previ = 0; i < len; i++)
8210 c = shell_input_line[i];
8214 for (j = i; j < len; j++)
8215 shell_input_line_property[j] = 1;
8219 mbclen = mbrlen (shell_input_line + previ, i - previ + 1, &mbs);
8220 if (mbclen == 1 || mbclen == (size_t)-1)
8225 else if (mbclen == (size_t)-2)
8227 else if (mbclen > 1)
8235 /* XXX - what to do if mbrlen returns 0? (null wide character) */
8237 for (j = i; j < len; j++)
8238 shell_input_line_property[j] = 1;
8242 shell_input_line_property[i] = mbclen;
8245 #endif /* HANDLE_MULTIBYTE */