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
93 ASSIGNMENT_WORD = 282,
97 ARITH_FOR_EXPRS = 286,
101 GREATER_GREATER = 290,
104 LESS_LESS_LESS = 293,
109 LESS_LESS_MINUS = 298,
111 AND_GREATER_GREATER = 300,
134 #define COND_START 273
136 #define COND_ERROR 275
143 #define ASSIGNMENT_WORD 282
144 #define REDIR_WORD 283
146 #define ARITH_CMD 285
147 #define ARITH_FOR_EXPRS 286
151 #define GREATER_GREATER 290
152 #define LESS_LESS 291
154 #define LESS_LESS_LESS 293
155 #define GREATER_AND 294
156 #define SEMI_SEMI 295
158 #define SEMI_SEMI_AND 297
159 #define LESS_LESS_MINUS 298
160 #define AND_GREATER 299
161 #define AND_GREATER_GREATER 300
162 #define LESS_GREATER 301
163 #define GREATER_BAR 302
170 /* Copy the first part of user declarations. */
171 #line 21 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
175 #include "bashtypes.h"
176 #include "bashansi.h"
178 #include "filecntl.h"
180 #if defined (HAVE_UNISTD_H)
184 #if defined (HAVE_LOCALE_H)
189 #include "chartypes.h"
192 #include "memalloc.h"
194 #include "bashintl.h"
196 #define NEED_STRFTIME_DECL /* used in externs.h */
202 #include "mailcheck.h"
204 #include "builtins.h"
205 #include "builtins/common.h"
206 #include "builtins/builtext.h"
208 #include "shmbutil.h"
210 #if defined (READLINE)
211 # include "bashline.h"
212 # include <readline/readline.h>
213 #endif /* READLINE */
215 #if defined (HISTORY)
216 # include "bashhist.h"
217 # include <readline/history.h>
220 #if defined (JOB_CONTROL)
222 #endif /* JOB_CONTROL */
227 typedef void *alias_t;
230 #if defined (PROMPT_STRING_DECODE)
232 # include <sys/param.h>
235 # if defined (TM_IN_SYS_TIME)
236 # include <sys/types.h>
237 # include <sys/time.h>
238 # endif /* TM_IN_SYS_TIME */
239 # include "maxpath.h"
240 #endif /* PROMPT_STRING_DECODE */
242 #define RE_READ_TOKEN -99
243 #define NO_EXPANSION -100
251 #if defined (HANDLE_MULTIBYTE)
252 # define last_shell_getc_is_singlebyte \
253 ((shell_input_line_index > 1) \
254 ? shell_input_line_property[shell_input_line_index - 1] \
256 # define MBTEST(x) ((x) && last_shell_getc_is_singlebyte)
258 # define last_shell_getc_is_singlebyte 1
259 # define MBTEST(x) ((x))
262 #if defined (EXTENDED_GLOB)
263 extern int extended_glob;
266 extern int eof_encountered;
267 extern int no_line_editing, running_under_emacs;
268 extern int current_command_number;
269 extern int sourcelevel, parse_and_execute_level;
270 extern int posixly_correct;
271 extern int last_command_exit_value;
272 extern pid_t last_command_subst_pid;
273 extern char *shell_name, *current_host_name;
274 extern char *dist_version;
275 extern int patch_level;
276 extern int dump_translatable_strings, dump_po_strings;
277 extern sh_builtin_func_t *last_shell_builtin, *this_shell_builtin;
278 #if defined (BUFFERED_INPUT)
279 extern int bash_input_fd_changed;
283 /* **************************************************************** */
285 /* "Forward" declarations */
287 /* **************************************************************** */
290 static void debug_parser __P((int));
293 static int yy_getc __P((void));
294 static int yy_ungetc __P((int));
296 #if defined (READLINE)
297 static int yy_readline_get __P((void));
298 static int yy_readline_unget __P((int));
301 static int yy_string_get __P((void));
302 static int yy_string_unget __P((int));
303 static void rewind_input_string __P((void));
304 static int yy_stream_get __P((void));
305 static int yy_stream_unget __P((int));
307 static int shell_getc __P((int));
308 static void shell_ungetc __P((int));
309 static void discard_until __P((int));
311 #if defined (ALIAS) || defined (DPAREN_ARITHMETIC)
312 static void push_string __P((char *, int, alias_t *));
313 static void pop_string __P((void));
314 static void free_string_list __P((void));
317 static char *read_a_line __P((int));
319 static int reserved_word_acceptable __P((int));
320 static int yylex __P((void));
321 static int alias_expand_token __P((char *));
322 static int time_command_acceptable __P((void));
323 static int special_case_tokens __P((char *));
324 static int read_token __P((int));
325 static char *parse_matched_pair __P((int, int, int, int *, int));
326 static char *parse_comsub __P((int, int, int, int *, int));
327 #if defined (ARRAY_VARS)
328 static char *parse_compound_assignment __P((int *));
330 #if defined (DPAREN_ARITHMETIC) || defined (ARITH_FOR_COMMAND)
331 static int parse_dparen __P((int));
332 static int parse_arith_cmd __P((char **, int));
334 #if defined (COND_COMMAND)
335 static void cond_error __P((void));
336 static COND_COM *cond_expr __P((void));
337 static COND_COM *cond_or __P((void));
338 static COND_COM *cond_and __P((void));
339 static COND_COM *cond_term __P((void));
340 static int cond_skip_newlines __P((void));
341 static COMMAND *parse_cond_command __P((void));
343 #if defined (ARRAY_VARS)
344 static int token_is_assignment __P((char *, int));
345 static int token_is_ident __P((char *, int));
347 static int read_token_word __P((int));
348 static void discard_parser_constructs __P((int));
350 static char *error_token_from_token __P((int));
351 static char *error_token_from_text __P((void));
352 static void print_offending_line __P((void));
353 static void report_syntax_error __P((char *));
355 static void handle_eof_input_unit __P((void));
356 static void prompt_again __P((void));
358 static void reset_readline_prompt __P((void));
360 static void print_prompt __P((void));
362 #if defined (HANDLE_MULTIBYTE)
363 static void set_line_mbstate __P((void));
364 static char *shell_input_line_property = NULL;
366 # define set_line_mbstate()
369 extern int yyerror __P((const char *));
375 /* Default prompt strings */
376 char *primary_prompt = PPROMPT;
377 char *secondary_prompt = SPROMPT;
379 /* PROMPT_STRING_POINTER points to one of these, never to an actual string. */
380 char *ps1_prompt, *ps2_prompt;
382 /* Handle on the current prompt string. Indirectly points through
383 ps1_ or ps2_prompt. */
384 char **prompt_string_pointer = (char **)NULL;
385 char *current_prompt_string;
387 /* Non-zero means we expand aliases in commands. */
388 int expand_aliases = 0;
390 /* If non-zero, the decoded prompt string undergoes parameter and
391 variable substitution, command substitution, arithmetic substitution,
392 string expansion, process substitution, and quote removal in
393 decode_prompt_string. */
396 /* If non-zero, $'...' and $"..." are expanded when they appear within
397 a ${...} expansion, even when the expansion appears within double
399 int extended_quote = 1;
401 /* The number of lines read from input while creating the current command. */
402 int current_command_line_count;
404 /* The number of lines in a command saved while we run parse_and_execute */
405 int saved_command_line_count;
407 /* The token that currently denotes the end of parse. */
410 /* The token currently being read. */
413 /* The current parser state. */
416 /* Variables to manage the task of reading here documents, because we need to
417 defer the reading until after a complete command has been collected. */
418 static REDIRECT *redir_stack[10];
421 /* Where shell input comes from. History expansion is performed on each
422 line when the shell is interactive. */
423 static char *shell_input_line = (char *)NULL;
424 static int shell_input_line_index;
425 static int shell_input_line_size; /* Amount allocated for shell_input_line. */
426 static int shell_input_line_len; /* strlen (shell_input_line) */
428 /* Either zero or EOF. */
429 static int shell_input_line_terminator;
431 /* The line number in a script on which a function definition starts. */
432 static int function_dstart;
434 /* The line number in a script on which a function body starts. */
435 static int function_bstart;
437 /* The line number in a script at which an arithmetic for command starts. */
438 static int arith_for_lineno;
440 /* The decoded prompt string. Used if READLINE is not defined or if
441 editing is turned off. Analogous to current_readline_prompt. */
442 static char *current_decoded_prompt;
444 /* The last read token, or NULL. read_token () uses this for context
446 static int last_read_token;
448 /* The token read prior to last_read_token. */
449 static int token_before_that;
451 /* The token read prior to token_before_that. */
452 static int two_tokens_ago;
454 static int global_extglob;
456 /* The line number in a script where the word in a `case WORD', `select WORD'
457 or `for WORD' begins. This is a nested command maximum, since the array
458 index is decremented after a case, select, or for command is parsed. */
459 #define MAX_CASE_NEST 128
460 static int word_lineno[MAX_CASE_NEST];
461 static int word_top = -1;
463 /* If non-zero, it is the token that we want read_token to return
464 regardless of what text is (or isn't) present to be read. This
465 is reset by read_token. If token_to_read == WORD or
466 ASSIGNMENT_WORD, yylval.word should be set to word_desc_to_read. */
467 static int token_to_read;
468 static WORD_DESC *word_desc_to_read;
470 static REDIRECTEE source;
471 static REDIRECTEE redir;
474 /* Enabling traces. */
479 /* Enabling verbose error messages. */
480 #ifdef YYERROR_VERBOSE
481 # undef YYERROR_VERBOSE
482 # define YYERROR_VERBOSE 1
484 # define YYERROR_VERBOSE 0
487 /* Enabling the token table. */
488 #ifndef YYTOKEN_TABLE
489 # define YYTOKEN_TABLE 0
492 #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
493 typedef union YYSTYPE
494 #line 323 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
496 WORD_DESC *word; /* the word that we read. */
497 int number; /* the number that we read. */
498 WORD_LIST *word_list;
502 PATTERN_LIST *pattern;
504 /* Line 193 of yacc.c. */
507 # define yystype YYSTYPE /* obsolescent; will be withdrawn */
508 # define YYSTYPE_IS_DECLARED 1
509 # define YYSTYPE_IS_TRIVIAL 1
514 /* Copy the second part of user declarations. */
517 /* Line 216 of yacc.c. */
525 typedef YYTYPE_UINT8 yytype_uint8;
527 typedef unsigned char yytype_uint8;
531 typedef YYTYPE_INT8 yytype_int8;
532 #elif (defined __STDC__ || defined __C99__FUNC__ \
533 || defined __cplusplus || defined _MSC_VER)
534 typedef signed char yytype_int8;
536 typedef short int yytype_int8;
540 typedef YYTYPE_UINT16 yytype_uint16;
542 typedef unsigned short int yytype_uint16;
546 typedef YYTYPE_INT16 yytype_int16;
548 typedef short int yytype_int16;
552 # ifdef __SIZE_TYPE__
553 # define YYSIZE_T __SIZE_TYPE__
554 # elif defined size_t
555 # define YYSIZE_T size_t
556 # elif ! defined YYSIZE_T && (defined __STDC__ || defined __C99__FUNC__ \
557 || defined __cplusplus || defined _MSC_VER)
558 # include <stddef.h> /* INFRINGES ON USER NAME SPACE */
559 # define YYSIZE_T size_t
561 # define YYSIZE_T unsigned int
565 #define YYSIZE_MAXIMUM ((YYSIZE_T) -1)
568 # if defined YYENABLE_NLS && YYENABLE_NLS
570 # include <libintl.h> /* INFRINGES ON USER NAME SPACE */
571 # define YY_(msgid) dgettext ("bison-runtime", msgid)
575 # define YY_(msgid) msgid
579 /* Suppress unused-variable warnings by "using" E. */
580 #if ! defined lint || defined __GNUC__
581 # define YYUSE(e) ((void) (e))
583 # define YYUSE(e) /* empty */
586 /* Identity function, used to suppress warnings about constant conditions. */
590 #if (defined __STDC__ || defined __C99__FUNC__ \
591 || defined __cplusplus || defined _MSC_VER)
604 #if ! defined yyoverflow || YYERROR_VERBOSE
606 /* The parser invokes alloca or malloc; define the necessary symbols. */
608 # ifdef YYSTACK_USE_ALLOCA
609 # if YYSTACK_USE_ALLOCA
611 # define YYSTACK_ALLOC __builtin_alloca
612 # elif defined __BUILTIN_VA_ARG_INCR
613 # include <alloca.h> /* INFRINGES ON USER NAME SPACE */
615 # define YYSTACK_ALLOC __alloca
616 # elif defined _MSC_VER
617 # include <malloc.h> /* INFRINGES ON USER NAME SPACE */
618 # define alloca _alloca
620 # define YYSTACK_ALLOC alloca
621 # if ! defined _ALLOCA_H && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
622 || defined __cplusplus || defined _MSC_VER)
623 # include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
632 # ifdef YYSTACK_ALLOC
633 /* Pacify GCC's `empty if-body' warning. */
634 # define YYSTACK_FREE(Ptr) do { /* empty */; } while (YYID (0))
635 # ifndef YYSTACK_ALLOC_MAXIMUM
636 /* The OS might guarantee only one guard page at the bottom of the stack,
637 and a page size can be as small as 4096 bytes. So we cannot safely
638 invoke alloca (N) if N exceeds 4096. Use a slightly smaller number
639 to allow for a few compiler-allocated temporary stack slots. */
640 # define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */
643 # define YYSTACK_ALLOC YYMALLOC
644 # define YYSTACK_FREE YYFREE
645 # ifndef YYSTACK_ALLOC_MAXIMUM
646 # define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM
648 # if (defined __cplusplus && ! defined _STDLIB_H \
649 && ! ((defined YYMALLOC || defined malloc) \
650 && (defined YYFREE || defined free)))
651 # include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
657 # define YYMALLOC malloc
658 # if ! defined malloc && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
659 || defined __cplusplus || defined _MSC_VER)
660 void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */
665 # if ! defined free && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
666 || defined __cplusplus || defined _MSC_VER)
667 void free (void *); /* INFRINGES ON USER NAME SPACE */
671 #endif /* ! defined yyoverflow || YYERROR_VERBOSE */
674 #if (! defined yyoverflow \
675 && (! defined __cplusplus \
676 || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
678 /* A type that is properly aligned for any stack member. */
685 /* The size of the maximum gap between one aligned stack and the next. */
686 # define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1)
688 /* The size of an array large to enough to hold all stacks, each with
690 # define YYSTACK_BYTES(N) \
691 ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE)) \
692 + YYSTACK_GAP_MAXIMUM)
694 /* Copy COUNT objects from FROM to TO. The source and destination do
697 # if defined __GNUC__ && 1 < __GNUC__
698 # define YYCOPY(To, From, Count) \
699 __builtin_memcpy (To, From, (Count) * sizeof (*(From)))
701 # define YYCOPY(To, From, Count) \
705 for (yyi = 0; yyi < (Count); yyi++) \
706 (To)[yyi] = (From)[yyi]; \
712 /* Relocate STACK from its old location to the new one. The
713 local variables YYSIZE and YYSTACKSIZE give the old and new number of
714 elements in the stack, and YYPTR gives the new location of the
715 stack. Advance YYPTR to a properly aligned location for the next
717 # define YYSTACK_RELOCATE(Stack) \
720 YYSIZE_T yynewbytes; \
721 YYCOPY (&yyptr->Stack, Stack, yysize); \
722 Stack = &yyptr->Stack; \
723 yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \
724 yyptr += yynewbytes / sizeof (*yyptr); \
730 /* YYFINAL -- State number of the termination state. */
732 /* YYLAST -- Last index in YYTABLE. */
735 /* YYNTOKENS -- Number of terminals. */
737 /* YYNNTS -- Number of nonterminals. */
739 /* YYNRULES -- Number of rules. */
741 /* YYNRULES -- Number of states. */
742 #define YYNSTATES 342
744 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
746 #define YYMAXUTOK 304
748 #define YYTRANSLATE(YYX) \
749 ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
751 /* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */
752 static const yytype_uint8 yytranslate[] =
754 0, 2, 2, 2, 2, 2, 2, 2, 2, 2,
755 51, 2, 2, 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, 49, 2,
758 59, 60, 2, 2, 2, 56, 2, 2, 2, 2,
759 2, 2, 2, 2, 2, 2, 2, 2, 2, 50,
760 55, 2, 54, 2, 2, 2, 2, 2, 2, 2,
761 2, 2, 2, 2, 2, 2, 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, 57, 53, 58, 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, 2, 2, 2, 2,
775 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
776 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
777 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
778 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
779 2, 2, 2, 2, 2, 2, 1, 2, 3, 4,
780 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
781 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
782 25, 26, 27, 28, 29, 30, 31, 32, 33, 34,
783 35, 36, 37, 38, 39, 40, 41, 42, 43, 44,
788 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
790 static const yytype_uint16 yyprhs[] =
792 0, 0, 3, 6, 8, 11, 13, 15, 18, 21,
793 24, 28, 32, 36, 40, 43, 47, 51, 54, 58,
794 62, 65, 69, 73, 76, 80, 84, 87, 91, 95,
795 98, 102, 106, 109, 113, 117, 120, 124, 128, 131,
796 135, 139, 142, 146, 150, 153, 157, 161, 164, 168,
797 172, 175, 178, 180, 182, 184, 186, 189, 191, 194,
798 196, 198, 201, 203, 205, 207, 209, 215, 221, 223,
799 225, 227, 229, 231, 233, 235, 242, 249, 257, 265,
800 276, 287, 297, 307, 315, 323, 329, 335, 342, 349,
801 357, 365, 376, 387, 394, 402, 409, 415, 422, 427,
802 429, 432, 436, 439, 443, 447, 452, 455, 461, 469,
803 476, 480, 482, 486, 491, 498, 504, 506, 509, 514,
804 519, 525, 531, 534, 538, 541, 545, 548, 552, 554,
805 558, 561, 563, 566, 570, 574, 578, 583, 588, 593,
806 598, 603, 605, 607, 609, 611, 613, 615, 616, 619,
807 621, 624, 627, 632, 637, 641, 645, 647, 649, 652,
808 655, 658, 661, 666, 671, 673, 675, 678
811 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
812 static const yytype_int8 yyrhs[] =
814 62, 0, -1, 94, 91, -1, 51, -1, 1, 51,
815 -1, 52, -1, 26, -1, 63, 26, -1, 54, 26,
816 -1, 55, 26, -1, 29, 54, 26, -1, 29, 55,
817 26, -1, 28, 54, 26, -1, 28, 55, 26, -1,
818 35, 26, -1, 29, 35, 26, -1, 28, 35, 26,
819 -1, 47, 26, -1, 29, 47, 26, -1, 28, 47,
820 26, -1, 46, 26, -1, 29, 46, 26, -1, 28,
821 46, 26, -1, 36, 26, -1, 29, 36, 26, -1,
822 28, 36, 26, -1, 43, 26, -1, 29, 43, 26,
823 -1, 28, 43, 26, -1, 38, 26, -1, 29, 38,
824 26, -1, 28, 38, 26, -1, 37, 29, -1, 29,
825 37, 29, -1, 28, 37, 29, -1, 39, 29, -1,
826 29, 39, 29, -1, 28, 39, 29, -1, 37, 26,
827 -1, 29, 37, 26, -1, 28, 37, 26, -1, 39,
828 26, -1, 29, 39, 26, -1, 28, 39, 26, -1,
829 39, 56, -1, 29, 39, 56, -1, 28, 39, 56,
830 -1, 37, 56, -1, 29, 37, 56, -1, 28, 37,
831 56, -1, 44, 26, -1, 45, 26, -1, 26, -1,
832 27, -1, 64, -1, 64, -1, 66, 64, -1, 65,
833 -1, 67, 65, -1, 67, -1, 69, -1, 69, 66,
834 -1, 74, -1, 77, -1, 70, -1, 73, -1, 12,
835 88, 14, 88, 15, -1, 13, 88, 14, 88, 15,
836 -1, 72, -1, 78, -1, 76, -1, 79, -1, 80,
837 -1, 81, -1, 71, -1, 10, 26, 93, 14, 88,
838 15, -1, 10, 26, 93, 57, 88, 58, -1, 10,
839 26, 50, 93, 14, 88, 15, -1, 10, 26, 50,
840 93, 57, 88, 58, -1, 10, 26, 93, 21, 63,
841 92, 93, 14, 88, 15, -1, 10, 26, 93, 21,
842 63, 92, 93, 57, 88, 58, -1, 10, 26, 93,
843 21, 92, 93, 14, 88, 15, -1, 10, 26, 93,
844 21, 92, 93, 57, 88, 58, -1, 10, 31, 92,
845 93, 14, 88, 15, -1, 10, 31, 92, 93, 57,
846 88, 58, -1, 10, 31, 14, 88, 15, -1, 10,
847 31, 57, 88, 58, -1, 11, 26, 93, 14, 87,
848 15, -1, 11, 26, 93, 57, 87, 58, -1, 11,
849 26, 50, 93, 14, 87, 15, -1, 11, 26, 50,
850 93, 57, 87, 58, -1, 11, 26, 93, 21, 63,
851 92, 93, 14, 87, 15, -1, 11, 26, 93, 21,
852 63, 92, 93, 57, 87, 58, -1, 8, 26, 93,
853 21, 93, 9, -1, 8, 26, 93, 21, 85, 93,
854 9, -1, 8, 26, 93, 21, 83, 9, -1, 26,
855 59, 60, 93, 75, -1, 16, 26, 59, 60, 93,
856 75, -1, 16, 26, 93, 75, -1, 69, -1, 69,
857 66, -1, 59, 88, 60, -1, 17, 69, -1, 17,
858 69, 66, -1, 17, 26, 69, -1, 17, 26, 69,
859 66, -1, 17, 67, -1, 3, 88, 4, 88, 7,
860 -1, 3, 88, 4, 88, 5, 88, 7, -1, 3,
861 88, 4, 88, 82, 7, -1, 57, 88, 58, -1,
862 30, -1, 18, 32, 19, -1, 6, 88, 4, 88,
863 -1, 6, 88, 4, 88, 5, 88, -1, 6, 88,
864 4, 88, 82, -1, 84, -1, 85, 84, -1, 93,
865 86, 60, 88, -1, 93, 86, 60, 93, -1, 93,
866 59, 86, 60, 88, -1, 93, 59, 86, 60, 93,
867 -1, 84, 40, -1, 85, 84, 40, -1, 84, 41,
868 -1, 85, 84, 41, -1, 84, 42, -1, 85, 84,
869 42, -1, 26, -1, 86, 53, 26, -1, 93, 89,
870 -1, 87, -1, 93, 90, -1, 90, 51, 93, -1,
871 90, 49, 93, -1, 90, 50, 93, -1, 90, 33,
872 93, 90, -1, 90, 34, 93, 90, -1, 90, 49,
873 93, 90, -1, 90, 50, 93, 90, -1, 90, 51,
874 93, 90, -1, 96, -1, 51, -1, 52, -1, 51,
875 -1, 50, -1, 52, -1, -1, 93, 51, -1, 95,
876 -1, 95, 49, -1, 95, 50, -1, 95, 33, 93,
877 95, -1, 95, 34, 93, 95, -1, 95, 49, 95,
878 -1, 95, 50, 95, -1, 96, -1, 97, -1, 22,
879 96, -1, 98, 96, -1, 98, 92, -1, 22, 92,
880 -1, 97, 53, 93, 97, -1, 97, 48, 93, 97,
881 -1, 68, -1, 23, -1, 23, 24, -1, 23, 24,
885 /* YYRLINE[YYN] -- source line where rule number YYN was defined. */
886 static const yytype_uint16 yyrline[] =
888 0, 376, 376, 387, 396, 411, 421, 423, 427, 433,
889 439, 445, 451, 457, 463, 469, 475, 481, 487, 493,
890 499, 505, 511, 517, 524, 531, 538, 545, 552, 559,
891 565, 571, 577, 583, 589, 595, 601, 607, 613, 619,
892 625, 631, 637, 643, 649, 655, 661, 667, 673, 679,
893 685, 691, 699, 701, 703, 707, 711, 722, 724, 728,
894 730, 732, 748, 750, 754, 756, 758, 760, 762, 764,
895 766, 768, 770, 772, 774, 778, 783, 788, 793, 798,
896 803, 808, 813, 820, 825, 830, 835, 842, 847, 852,
897 857, 862, 867, 874, 879, 884, 891, 894, 897, 901,
898 903, 934, 941, 946, 963, 968, 985, 992, 994, 996,
899 1001, 1005, 1009, 1013, 1015, 1017, 1021, 1022, 1026, 1028,
900 1030, 1032, 1036, 1038, 1040, 1042, 1044, 1046, 1050, 1052,
901 1061, 1069, 1070, 1076, 1077, 1084, 1088, 1090, 1092, 1099,
902 1101, 1103, 1107, 1108, 1111, 1113, 1115, 1119, 1120, 1129,
903 1142, 1158, 1173, 1175, 1177, 1184, 1187, 1191, 1193, 1199,
904 1205, 1222, 1242, 1244, 1267, 1271, 1273, 1275
908 #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
909 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
910 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
911 static const char *const yytname[] =
913 "$end", "error", "$undefined", "IF", "THEN", "ELSE", "ELIF", "FI",
914 "CASE", "ESAC", "FOR", "SELECT", "WHILE", "UNTIL", "DO", "DONE",
915 "FUNCTION", "COPROC", "COND_START", "COND_END", "COND_ERROR", "IN",
916 "BANG", "TIME", "TIMEOPT", "TIMEIGN", "WORD", "ASSIGNMENT_WORD",
917 "REDIR_WORD", "NUMBER", "ARITH_CMD", "ARITH_FOR_EXPRS", "COND_CMD",
918 "AND_AND", "OR_OR", "GREATER_GREATER", "LESS_LESS", "LESS_AND",
919 "LESS_LESS_LESS", "GREATER_AND", "SEMI_SEMI", "SEMI_AND",
920 "SEMI_SEMI_AND", "LESS_LESS_MINUS", "AND_GREATER", "AND_GREATER_GREATER",
921 "LESS_GREATER", "GREATER_BAR", "BAR_AND", "'&'", "';'", "'\\n'",
922 "yacc_EOF", "'|'", "'>'", "'<'", "'-'", "'{'", "'}'", "'('", "')'",
923 "$accept", "inputunit", "word_list", "redirection",
924 "simple_command_element", "redirection_list", "simple_command",
925 "command", "shell_command", "for_command", "arith_for_command",
926 "select_command", "case_command", "function_def", "function_body",
927 "subshell", "coproc", "if_command", "group_command", "arith_command",
928 "cond_command", "elif_clause", "case_clause", "pattern_list",
929 "case_clause_sequence", "pattern", "list", "compound_list", "list0",
930 "list1", "simple_list_terminator", "list_terminator", "newline_list",
931 "simple_list", "simple_list1", "pipeline_command", "pipeline",
937 /* YYTOKNUM[YYLEX-NUM] -- Internal token number corresponding to
939 static const yytype_uint16 yytoknum[] =
941 0, 256, 257, 258, 259, 260, 261, 262, 263, 264,
942 265, 266, 267, 268, 269, 270, 271, 272, 273, 274,
943 275, 276, 277, 278, 279, 280, 281, 282, 283, 284,
944 285, 286, 287, 288, 289, 290, 291, 292, 293, 294,
945 295, 296, 297, 298, 299, 300, 301, 302, 303, 38,
946 59, 10, 304, 124, 62, 60, 45, 123, 125, 40,
951 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
952 static const yytype_uint8 yyr1[] =
954 0, 61, 62, 62, 62, 62, 63, 63, 64, 64,
955 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
956 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
957 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
958 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
959 64, 64, 65, 65, 65, 66, 66, 67, 67, 68,
960 68, 68, 68, 68, 69, 69, 69, 69, 69, 69,
961 69, 69, 69, 69, 69, 70, 70, 70, 70, 70,
962 70, 70, 70, 71, 71, 71, 71, 72, 72, 72,
963 72, 72, 72, 73, 73, 73, 74, 74, 74, 75,
964 75, 76, 77, 77, 77, 77, 77, 78, 78, 78,
965 79, 80, 81, 82, 82, 82, 83, 83, 84, 84,
966 84, 84, 85, 85, 85, 85, 85, 85, 86, 86,
967 87, 88, 88, 89, 89, 89, 90, 90, 90, 90,
968 90, 90, 91, 91, 92, 92, 92, 93, 93, 94,
969 94, 94, 95, 95, 95, 95, 95, 96, 96, 96,
970 96, 96, 97, 97, 97, 98, 98, 98
973 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
974 static const yytype_uint8 yyr2[] =
976 0, 2, 2, 1, 2, 1, 1, 2, 2, 2,
977 3, 3, 3, 3, 2, 3, 3, 2, 3, 3,
978 2, 3, 3, 2, 3, 3, 2, 3, 3, 2,
979 3, 3, 2, 3, 3, 2, 3, 3, 2, 3,
980 3, 2, 3, 3, 2, 3, 3, 2, 3, 3,
981 2, 2, 1, 1, 1, 1, 2, 1, 2, 1,
982 1, 2, 1, 1, 1, 1, 5, 5, 1, 1,
983 1, 1, 1, 1, 1, 6, 6, 7, 7, 10,
984 10, 9, 9, 7, 7, 5, 5, 6, 6, 7,
985 7, 10, 10, 6, 7, 6, 5, 6, 4, 1,
986 2, 3, 2, 3, 3, 4, 2, 5, 7, 6,
987 3, 1, 3, 4, 6, 5, 1, 2, 4, 4,
988 5, 5, 2, 3, 2, 3, 2, 3, 1, 3,
989 2, 1, 2, 3, 3, 3, 4, 4, 4, 4,
990 4, 1, 1, 1, 1, 1, 1, 0, 2, 1,
991 2, 2, 4, 4, 3, 3, 1, 1, 2, 2,
992 2, 2, 4, 4, 1, 1, 2, 3
995 /* YYDEFACT[STATE-NAME] -- Default rule to reduce with in state
996 STATE-NUM when YYTABLE doesn't specify something else to do. Zero
997 means the default is an error. */
998 static const yytype_uint8 yydefact[] =
1000 0, 0, 147, 0, 0, 0, 147, 147, 0, 0,
1001 0, 0, 165, 52, 53, 0, 0, 111, 0, 0,
1002 0, 0, 0, 0, 0, 0, 0, 0, 3, 5,
1003 0, 0, 147, 147, 0, 54, 57, 59, 164, 60,
1004 64, 74, 68, 65, 62, 70, 63, 69, 71, 72,
1005 73, 0, 149, 156, 157, 0, 4, 131, 0, 0,
1006 147, 147, 0, 147, 0, 0, 147, 52, 106, 102,
1007 0, 145, 144, 146, 161, 158, 166, 0, 0, 0,
1008 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1009 0, 0, 0, 0, 0, 0, 0, 0, 14, 23,
1010 38, 32, 47, 29, 41, 35, 44, 26, 50, 51,
1011 20, 17, 8, 9, 0, 0, 1, 52, 58, 55,
1012 61, 142, 143, 2, 147, 147, 150, 151, 147, 147,
1013 160, 159, 147, 148, 130, 132, 141, 0, 147, 0,
1014 147, 147, 147, 147, 0, 147, 147, 0, 0, 104,
1015 103, 112, 167, 147, 16, 25, 40, 34, 49, 31,
1016 43, 37, 46, 28, 22, 19, 12, 13, 15, 24,
1017 39, 33, 48, 30, 42, 36, 45, 27, 21, 18,
1018 10, 11, 110, 101, 56, 0, 0, 154, 155, 0,
1019 0, 0, 147, 147, 147, 147, 147, 147, 0, 147,
1020 0, 147, 0, 0, 0, 0, 147, 0, 147, 0,
1021 0, 147, 99, 98, 105, 0, 152, 153, 0, 0,
1022 163, 162, 147, 147, 107, 0, 0, 0, 134, 135,
1023 133, 0, 116, 147, 0, 147, 147, 0, 6, 0,
1024 147, 0, 85, 86, 147, 147, 147, 147, 0, 0,
1025 0, 0, 66, 67, 0, 100, 96, 0, 0, 109,
1026 136, 137, 138, 139, 140, 95, 122, 124, 126, 117,
1027 0, 93, 128, 0, 0, 0, 0, 75, 7, 147,
1028 0, 76, 0, 0, 0, 0, 87, 0, 147, 88,
1029 97, 108, 147, 147, 147, 147, 123, 125, 127, 94,
1030 0, 0, 147, 77, 78, 0, 147, 147, 83, 84,
1031 89, 90, 0, 113, 0, 0, 0, 147, 129, 118,
1032 119, 147, 147, 0, 0, 147, 147, 147, 115, 120,
1033 121, 0, 0, 81, 82, 0, 0, 114, 79, 80,
1037 /* YYDEFGOTO[NTERM-NUM]. */
1038 static const yytype_int16 yydefgoto[] =
1040 -1, 34, 239, 35, 36, 120, 37, 38, 39, 40,
1041 41, 42, 43, 44, 213, 45, 46, 47, 48, 49,
1042 50, 225, 231, 232, 233, 274, 57, 58, 134, 135,
1043 123, 74, 59, 51, 187, 136, 54, 55
1046 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
1048 #define YYPACT_NINF -208
1049 static const yytype_int16 yypact[] =
1051 296, -35, -208, -2, 38, 10, -208, -208, 24, 546,
1052 31, 346, 51, 47, -208, 591, 604, -208, 56, 71,
1053 -18, 112, 130, 115, 128, 136, 143, 154, -208, -208,
1054 157, 170, -208, -208, 111, -208, -208, 229, -208, 578,
1055 -208, -208, -208, -208, -208, -208, -208, -208, -208, -208,
1056 -208, -12, -3, -208, 48, 346, -208, -208, 208, 396,
1057 -208, 73, 15, 163, 190, 201, 160, 107, 229, 578,
1058 204, -208, -208, -208, -208, -208, 195, 165, 202, 215,
1059 152, 216, 153, 222, 227, 236, 237, 244, 245, 253,
1060 158, 254, 171, 255, 256, 259, 261, 262, -208, -208,
1061 -208, -208, -208, -208, -208, -208, -208, -208, -208, -208,
1062 -208, -208, -208, -208, 231, 230, -208, -208, -208, -208,
1063 578, -208, -208, -208, -208, -208, 446, 446, -208, -208,
1064 -208, -208, -208, -208, -208, 210, -208, 4, -208, 65,
1065 -208, -208, -208, -208, 70, -208, -208, 232, 41, 578,
1066 578, -208, -208, -208, -208, -208, -208, -208, -208, -208,
1067 -208, -208, -208, -208, -208, -208, -208, -208, -208, -208,
1068 -208, -208, -208, -208, -208, -208, -208, -208, -208, -208,
1069 -208, -208, -208, -208, -208, 396, 396, 23, 23, 496,
1070 496, 97, -208, -208, -208, -208, -208, -208, 85, -208,
1071 185, -208, 276, 235, 100, 110, -208, 268, -208, 280,
1072 283, -208, 578, -208, 578, 41, -208, -208, 446, 446,
1073 48, 48, -208, -208, -208, 295, 396, 396, 396, 396,
1074 396, 294, 161, -208, 19, -208, -208, 290, -208, 200,
1075 -208, 252, -208, -208, -208, -208, -208, -208, 302, 396,
1076 200, 269, -208, -208, 41, 578, -208, 313, 324, -208,
1077 -208, -208, 55, 55, 55, -208, -208, -208, -208, 192,
1078 34, -208, -208, 303, -19, 315, 278, -208, -208, -208,
1079 114, -208, 322, 286, 323, 287, -208, 210, -208, -208,
1080 -208, -208, -208, -208, -208, -208, -208, -208, -208, -208,
1081 8, 320, -208, -208, -208, 117, -208, -208, -208, -208,
1082 -208, -208, 119, 167, 396, 396, 396, -208, -208, -208,
1083 396, -208, -208, 337, 307, -208, -208, -208, -208, -208,
1084 396, 345, 308, -208, -208, 352, 312, -208, -208, -208,
1088 /* YYPGOTO[NTERM-NUM]. */
1089 static const yytype_int16 yypgoto[] =
1091 -208, -208, 164, -37, -31, -62, 368, -208, -5, -208,
1092 -208, -208, -208, -208, -206, -208, -208, -208, -208, -208,
1093 -208, 66, -208, 145, -208, 88, -173, -6, -208, -207,
1094 -208, -45, -48, -208, 5, 3, 17, -208
1097 /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
1098 positive, shift that token. If negative, reduce the rule which
1099 number is the opposite. If zero, do what YYDEFACT says.
1100 If YYTABLE_NINF, syntax error. */
1101 #define YYTABLE_NINF -1
1102 static const yytype_uint16 yytable[] =
1104 64, 65, 119, 53, 69, 52, 118, 150, 100, 256,
1105 130, 101, 137, 139, 75, 144, 56, 142, 148, 260,
1106 261, 262, 263, 264, 60, 197, 114, 115, 271, 140,
1107 124, 125, 119, 248, 301, 251, 63, 118, 102, 121,
1108 122, 302, 287, 299, 2, 272, 126, 127, 290, 3,
1109 66, 4, 5, 6, 7, 133, 124, 125, 131, 10,
1110 272, 301, 149, 70, 61, 71, 72, 73, 317, 62,
1111 133, 17, 141, 284, 285, 76, 185, 186, 273, 199,
1112 189, 190, 98, 184, 206, 133, 200, 214, 192, 193,
1113 198, 207, 133, 273, 204, 205, 128, 99, 32, 235,
1114 33, 129, 222, 223, 224, 215, 77, 262, 263, 264,
1115 2, 116, 119, 184, 244, 3, 133, 4, 5, 6,
1116 7, 133, 201, 138, 246, 10, 191, 208, 306, 53,
1117 53, 321, 188, 325, 202, 203, 133, 17, 103, 209,
1118 210, 107, 236, 212, 226, 227, 228, 229, 230, 234,
1119 255, 133, 335, 336, 108, 240, 104, 245, 249, 105,
1120 249, 133, 109, 254, 32, 133, 33, 247, 133, 110,
1121 133, 307, 327, 223, 322, 119, 326, 184, 156, 160,
1122 111, 157, 161, 112, 170, 270, 106, 171, 53, 53,
1123 216, 217, 280, 237, 279, 241, 113, 174, 249, 249,
1124 175, 266, 267, 268, 145, 288, 220, 221, 158, 162,
1125 212, 238, 132, 143, 172, 146, 257, 258, 184, 147,
1126 152, 53, 53, 151, 188, 153, 278, 176, 154, 275,
1127 276, 305, 296, 297, 298, 71, 72, 73, 282, 283,
1128 312, 155, 159, 192, 193, 314, 315, 316, 163, 212,
1129 71, 72, 73, 164, 320, 117, 14, 15, 16, 194,
1130 195, 196, 165, 166, 18, 19, 20, 21, 22, 330,
1131 167, 168, 23, 24, 25, 26, 27, 249, 249, 169,
1132 173, 177, 178, 30, 31, 179, 313, 180, 181, 182,
1133 183, 242, 211, 243, 238, 252, 319, 1, 253, 2,
1134 323, 324, 259, 265, 3, 277, 4, 5, 6, 7,
1135 281, 329, 8, 9, 10, 331, 332, 286, 11, 12,
1136 291, 337, 13, 14, 15, 16, 17, 289, 292, 272,
1137 303, 18, 19, 20, 21, 22, 304, 308, 310, 23,
1138 24, 25, 26, 27, 309, 311, 318, 28, 29, 2,
1139 30, 31, 333, 32, 3, 33, 4, 5, 6, 7,
1140 338, 300, 8, 9, 10, 334, 339, 340, 11, 12,
1141 341, 250, 13, 14, 15, 16, 17, 68, 269, 328,
1142 0, 18, 19, 20, 21, 22, 0, 0, 0, 23,
1143 24, 25, 26, 27, 0, 0, 71, 72, 73, 2,
1144 30, 31, 0, 32, 3, 33, 4, 5, 6, 7,
1145 0, 0, 8, 9, 10, 0, 0, 0, 11, 12,
1146 0, 0, 13, 14, 15, 16, 17, 0, 0, 0,
1147 0, 18, 19, 20, 21, 22, 0, 0, 0, 23,
1148 24, 25, 26, 27, 0, 0, 0, 133, 0, 2,
1149 30, 31, 0, 32, 3, 33, 4, 5, 6, 7,
1150 0, 0, 8, 9, 10, 0, 0, 0, 11, 12,
1151 0, 0, 13, 14, 15, 16, 17, 0, 0, 0,
1152 0, 18, 19, 20, 21, 22, 0, 0, 0, 23,
1153 24, 25, 26, 27, 0, 0, 0, 0, 0, 2,
1154 30, 31, 0, 32, 3, 33, 4, 5, 6, 7,
1155 0, 0, 8, 9, 10, 0, 0, 0, 0, 0,
1156 0, 0, 13, 14, 15, 16, 17, 0, 0, 0,
1157 0, 18, 19, 20, 21, 22, 0, 0, 0, 23,
1158 24, 25, 26, 27, 0, 0, 0, 133, 0, 2,
1159 30, 31, 0, 32, 3, 33, 4, 5, 6, 7,
1160 0, 0, 0, 0, 10, 0, 0, 0, 0, 0,
1161 0, 0, 67, 14, 15, 16, 17, 0, 0, 0,
1162 0, 18, 19, 20, 21, 22, 0, 0, 0, 23,
1163 24, 25, 26, 27, 0, 0, 0, 0, 0, 0,
1164 30, 31, 0, 32, 0, 33, 15, 16, 0, 0,
1165 0, 0, 0, 18, 19, 20, 21, 22, 0, 0,
1166 0, 23, 24, 25, 26, 27, 78, 79, 80, 81,
1167 82, 0, 30, 31, 83, 0, 0, 84, 85, 88,
1168 89, 90, 91, 92, 0, 86, 87, 93, 0, 0,
1169 94, 95, 0, 0, 0, 0, 0, 0, 96, 97
1172 static const yytype_int16 yycheck[] =
1174 6, 7, 39, 0, 9, 0, 37, 69, 26, 215,
1175 55, 29, 60, 61, 11, 63, 51, 62, 66, 226,
1176 227, 228, 229, 230, 26, 21, 32, 33, 9, 14,
1177 33, 34, 69, 206, 53, 208, 26, 68, 56, 51,
1178 52, 60, 249, 9, 3, 26, 49, 50, 254, 8,
1179 26, 10, 11, 12, 13, 51, 33, 34, 55, 18,
1180 26, 53, 67, 32, 26, 50, 51, 52, 60, 31,
1181 51, 30, 57, 246, 247, 24, 124, 125, 59, 14,
1182 128, 129, 26, 120, 14, 51, 21, 149, 33, 34,
1183 138, 21, 51, 59, 142, 143, 48, 26, 57, 14,
1184 59, 53, 5, 6, 7, 153, 59, 314, 315, 316,
1185 3, 0, 149, 150, 14, 8, 51, 10, 11, 12,
1186 13, 51, 57, 50, 14, 18, 132, 57, 14, 126,
1187 127, 14, 127, 14, 140, 141, 51, 30, 26, 145,
1188 146, 26, 57, 148, 192, 193, 194, 195, 196, 197,
1189 212, 51, 325, 326, 26, 200, 26, 57, 206, 29,
1190 208, 51, 26, 211, 57, 51, 59, 57, 51, 26,
1191 51, 57, 5, 6, 57, 212, 57, 214, 26, 26,
1192 26, 29, 29, 26, 26, 233, 56, 29, 185, 186,
1193 185, 186, 240, 199, 239, 201, 26, 26, 246, 247,
1194 29, 40, 41, 42, 14, 250, 189, 190, 56, 56,
1195 215, 26, 4, 50, 56, 14, 222, 223, 255, 59,
1196 25, 218, 219, 19, 219, 60, 26, 56, 26, 235,
1197 236, 279, 40, 41, 42, 50, 51, 52, 244, 245,
1198 288, 26, 26, 33, 34, 293, 294, 295, 26, 254,
1199 50, 51, 52, 26, 302, 26, 27, 28, 29, 49,
1200 50, 51, 26, 26, 35, 36, 37, 38, 39, 317,
1201 26, 26, 43, 44, 45, 46, 47, 325, 326, 26,
1202 26, 26, 26, 54, 55, 26, 292, 26, 26, 58,
1203 60, 15, 60, 58, 26, 15, 302, 1, 15, 3,
1204 306, 307, 7, 9, 8, 15, 10, 11, 12, 13,
1205 58, 317, 16, 17, 18, 321, 322, 15, 22, 23,
1206 7, 327, 26, 27, 28, 29, 30, 58, 4, 26,
1207 15, 35, 36, 37, 38, 39, 58, 15, 15, 43,
1208 44, 45, 46, 47, 58, 58, 26, 51, 52, 3,
1209 54, 55, 15, 57, 8, 59, 10, 11, 12, 13,
1210 15, 273, 16, 17, 18, 58, 58, 15, 22, 23,
1211 58, 207, 26, 27, 28, 29, 30, 9, 233, 313,
1212 -1, 35, 36, 37, 38, 39, -1, -1, -1, 43,
1213 44, 45, 46, 47, -1, -1, 50, 51, 52, 3,
1214 54, 55, -1, 57, 8, 59, 10, 11, 12, 13,
1215 -1, -1, 16, 17, 18, -1, -1, -1, 22, 23,
1216 -1, -1, 26, 27, 28, 29, 30, -1, -1, -1,
1217 -1, 35, 36, 37, 38, 39, -1, -1, -1, 43,
1218 44, 45, 46, 47, -1, -1, -1, 51, -1, 3,
1219 54, 55, -1, 57, 8, 59, 10, 11, 12, 13,
1220 -1, -1, 16, 17, 18, -1, -1, -1, 22, 23,
1221 -1, -1, 26, 27, 28, 29, 30, -1, -1, -1,
1222 -1, 35, 36, 37, 38, 39, -1, -1, -1, 43,
1223 44, 45, 46, 47, -1, -1, -1, -1, -1, 3,
1224 54, 55, -1, 57, 8, 59, 10, 11, 12, 13,
1225 -1, -1, 16, 17, 18, -1, -1, -1, -1, -1,
1226 -1, -1, 26, 27, 28, 29, 30, -1, -1, -1,
1227 -1, 35, 36, 37, 38, 39, -1, -1, -1, 43,
1228 44, 45, 46, 47, -1, -1, -1, 51, -1, 3,
1229 54, 55, -1, 57, 8, 59, 10, 11, 12, 13,
1230 -1, -1, -1, -1, 18, -1, -1, -1, -1, -1,
1231 -1, -1, 26, 27, 28, 29, 30, -1, -1, -1,
1232 -1, 35, 36, 37, 38, 39, -1, -1, -1, 43,
1233 44, 45, 46, 47, -1, -1, -1, -1, -1, -1,
1234 54, 55, -1, 57, -1, 59, 28, 29, -1, -1,
1235 -1, -1, -1, 35, 36, 37, 38, 39, -1, -1,
1236 -1, 43, 44, 45, 46, 47, 35, 36, 37, 38,
1237 39, -1, 54, 55, 43, -1, -1, 46, 47, 35,
1238 36, 37, 38, 39, -1, 54, 55, 43, -1, -1,
1239 46, 47, -1, -1, -1, -1, -1, -1, 54, 55
1242 /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
1243 symbol of state STATE-NUM. */
1244 static const yytype_uint8 yystos[] =
1246 0, 1, 3, 8, 10, 11, 12, 13, 16, 17,
1247 18, 22, 23, 26, 27, 28, 29, 30, 35, 36,
1248 37, 38, 39, 43, 44, 45, 46, 47, 51, 52,
1249 54, 55, 57, 59, 62, 64, 65, 67, 68, 69,
1250 70, 71, 72, 73, 74, 76, 77, 78, 79, 80,
1251 81, 94, 95, 96, 97, 98, 51, 87, 88, 93,
1252 26, 26, 31, 26, 88, 88, 26, 26, 67, 69,
1253 32, 50, 51, 52, 92, 96, 24, 59, 35, 36,
1254 37, 38, 39, 43, 46, 47, 54, 55, 35, 36,
1255 37, 38, 39, 43, 46, 47, 54, 55, 26, 26,
1256 26, 29, 56, 26, 26, 29, 56, 26, 26, 26,
1257 26, 26, 26, 26, 88, 88, 0, 26, 65, 64,
1258 66, 51, 52, 91, 33, 34, 49, 50, 48, 53,
1259 92, 96, 4, 51, 89, 90, 96, 93, 50, 93,
1260 14, 57, 92, 50, 93, 14, 14, 59, 93, 69,
1261 66, 19, 25, 60, 26, 26, 26, 29, 56, 26,
1262 26, 29, 56, 26, 26, 26, 26, 26, 26, 26,
1263 26, 29, 56, 26, 26, 29, 56, 26, 26, 26,
1264 26, 26, 58, 60, 64, 93, 93, 95, 95, 93,
1265 93, 88, 33, 34, 49, 50, 51, 21, 93, 14,
1266 21, 57, 88, 88, 93, 93, 14, 21, 57, 88,
1267 88, 60, 69, 75, 66, 93, 95, 95, 49, 50,
1268 97, 97, 5, 6, 7, 82, 93, 93, 93, 93,
1269 93, 83, 84, 85, 93, 14, 57, 88, 26, 63,
1270 92, 88, 15, 58, 14, 57, 14, 57, 87, 93,
1271 63, 87, 15, 15, 93, 66, 75, 88, 88, 7,
1272 90, 90, 90, 90, 90, 9, 40, 41, 42, 84,
1273 93, 9, 26, 59, 86, 88, 88, 15, 26, 92,
1274 93, 58, 88, 88, 87, 87, 15, 90, 92, 58,
1275 75, 7, 4, 49, 50, 51, 40, 41, 42, 9,
1276 86, 53, 60, 15, 58, 93, 14, 57, 15, 58,
1277 15, 58, 93, 88, 93, 93, 93, 60, 26, 88,
1278 93, 14, 57, 88, 88, 14, 57, 5, 82, 88,
1279 93, 88, 88, 15, 58, 87, 87, 88, 15, 58,
1283 #define yyerrok (yyerrstatus = 0)
1284 #define yyclearin (yychar = YYEMPTY)
1285 #define YYEMPTY (-2)
1288 #define YYACCEPT goto yyacceptlab
1289 #define YYABORT goto yyabortlab
1290 #define YYERROR goto yyerrorlab
1293 /* Like YYERROR except do call yyerror. This remains here temporarily
1294 to ease the transition to the new meaning of YYERROR, for GCC.
1295 Once GCC version 2 has supplanted version 1, this can go. */
1297 #define YYFAIL goto yyerrlab
1299 #define YYRECOVERING() (!!yyerrstatus)
1301 #define YYBACKUP(Token, Value) \
1303 if (yychar == YYEMPTY && yylen == 1) \
1307 yytoken = YYTRANSLATE (yychar); \
1313 yyerror (YY_("syntax error: cannot back up")); \
1320 #define YYERRCODE 256
1323 /* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
1324 If N is 0, then set CURRENT to the empty location which ends
1325 the previous symbol: RHS[0] (always defined). */
1327 #define YYRHSLOC(Rhs, K) ((Rhs)[K])
1328 #ifndef YYLLOC_DEFAULT
1329 # define YYLLOC_DEFAULT(Current, Rhs, N) \
1333 (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \
1334 (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \
1335 (Current).last_line = YYRHSLOC (Rhs, N).last_line; \
1336 (Current).last_column = YYRHSLOC (Rhs, N).last_column; \
1340 (Current).first_line = (Current).last_line = \
1341 YYRHSLOC (Rhs, 0).last_line; \
1342 (Current).first_column = (Current).last_column = \
1343 YYRHSLOC (Rhs, 0).last_column; \
1349 /* YY_LOCATION_PRINT -- Print the location on the stream.
1350 This macro was not mandated originally: define only if we know
1351 we won't break user code: when these are the locations we know. */
1353 #ifndef YY_LOCATION_PRINT
1354 # if defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL
1355 # define YY_LOCATION_PRINT(File, Loc) \
1356 fprintf (File, "%d.%d-%d.%d", \
1357 (Loc).first_line, (Loc).first_column, \
1358 (Loc).last_line, (Loc).last_column)
1360 # define YY_LOCATION_PRINT(File, Loc) ((void) 0)
1365 /* YYLEX -- calling `yylex' with the right arguments. */
1368 # define YYLEX yylex (YYLEX_PARAM)
1370 # define YYLEX yylex ()
1373 /* Enable debugging if requested. */
1377 # include <stdio.h> /* INFRINGES ON USER NAME SPACE */
1378 # define YYFPRINTF fprintf
1381 # define YYDPRINTF(Args) \
1387 # define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
1391 YYFPRINTF (stderr, "%s ", Title); \
1392 yy_symbol_print (stderr, \
1394 YYFPRINTF (stderr, "\n"); \
1399 /*--------------------------------.
1400 | Print this symbol on YYOUTPUT. |
1401 `--------------------------------*/
1404 #if (defined __STDC__ || defined __C99__FUNC__ \
1405 || defined __cplusplus || defined _MSC_VER)
1407 yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep)
1410 yy_symbol_value_print (yyoutput, yytype, yyvaluep)
1413 YYSTYPE const * const yyvaluep;
1419 if (yytype < YYNTOKENS)
1420 YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep);
1432 /*--------------------------------.
1433 | Print this symbol on YYOUTPUT. |
1434 `--------------------------------*/
1436 #if (defined __STDC__ || defined __C99__FUNC__ \
1437 || defined __cplusplus || defined _MSC_VER)
1439 yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep)
1442 yy_symbol_print (yyoutput, yytype, yyvaluep)
1445 YYSTYPE const * const yyvaluep;
1448 if (yytype < YYNTOKENS)
1449 YYFPRINTF (yyoutput, "token %s (", yytname[yytype]);
1451 YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]);
1453 yy_symbol_value_print (yyoutput, yytype, yyvaluep);
1454 YYFPRINTF (yyoutput, ")");
1457 /*------------------------------------------------------------------.
1458 | yy_stack_print -- Print the state stack from its BOTTOM up to its |
1460 `------------------------------------------------------------------*/
1462 #if (defined __STDC__ || defined __C99__FUNC__ \
1463 || defined __cplusplus || defined _MSC_VER)
1465 yy_stack_print (yytype_int16 *bottom, yytype_int16 *top)
1468 yy_stack_print (bottom, top)
1469 yytype_int16 *bottom;
1473 YYFPRINTF (stderr, "Stack now");
1474 for (; bottom <= top; ++bottom)
1475 YYFPRINTF (stderr, " %d", *bottom);
1476 YYFPRINTF (stderr, "\n");
1479 # define YY_STACK_PRINT(Bottom, Top) \
1482 yy_stack_print ((Bottom), (Top)); \
1486 /*------------------------------------------------.
1487 | Report that the YYRULE is going to be reduced. |
1488 `------------------------------------------------*/
1490 #if (defined __STDC__ || defined __C99__FUNC__ \
1491 || defined __cplusplus || defined _MSC_VER)
1493 yy_reduce_print (YYSTYPE *yyvsp, int yyrule)
1496 yy_reduce_print (yyvsp, yyrule)
1501 int yynrhs = yyr2[yyrule];
1503 unsigned long int yylno = yyrline[yyrule];
1504 YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n",
1506 /* The symbols being reduced. */
1507 for (yyi = 0; yyi < yynrhs; yyi++)
1509 fprintf (stderr, " $%d = ", yyi + 1);
1510 yy_symbol_print (stderr, yyrhs[yyprhs[yyrule] + yyi],
1511 &(yyvsp[(yyi + 1) - (yynrhs)])
1513 fprintf (stderr, "\n");
1517 # define YY_REDUCE_PRINT(Rule) \
1520 yy_reduce_print (yyvsp, Rule); \
1523 /* Nonzero means print parse trace. It is left uninitialized so that
1524 multiple parsers can coexist. */
1526 #else /* !YYDEBUG */
1527 # define YYDPRINTF(Args)
1528 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
1529 # define YY_STACK_PRINT(Bottom, Top)
1530 # define YY_REDUCE_PRINT(Rule)
1531 #endif /* !YYDEBUG */
1534 /* YYINITDEPTH -- initial size of the parser's stacks. */
1536 # define YYINITDEPTH 200
1539 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
1540 if the built-in stack extension method is used).
1542 Do not make this value too large; the results are undefined if
1543 YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH)
1544 evaluated with infinite-precision integer arithmetic. */
1547 # define YYMAXDEPTH 10000
1555 # if defined __GLIBC__ && defined _STRING_H
1556 # define yystrlen strlen
1558 /* Return the length of YYSTR. */
1559 #if (defined __STDC__ || defined __C99__FUNC__ \
1560 || defined __cplusplus || defined _MSC_VER)
1562 yystrlen (const char *yystr)
1570 for (yylen = 0; yystr[yylen]; yylen++)
1578 # if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
1579 # define yystpcpy stpcpy
1581 /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
1583 #if (defined __STDC__ || defined __C99__FUNC__ \
1584 || defined __cplusplus || defined _MSC_VER)
1586 yystpcpy (char *yydest, const char *yysrc)
1589 yystpcpy (yydest, yysrc)
1595 const char *yys = yysrc;
1597 while ((*yyd++ = *yys++) != '\0')
1606 /* Copy to YYRES the contents of YYSTR after stripping away unnecessary
1607 quotes and backslashes, so that it's suitable for yyerror. The
1608 heuristic is that double-quoting is unnecessary unless the string
1609 contains an apostrophe, a comma, or backslash (other than
1610 backslash-backslash). YYSTR is taken from yytname. If YYRES is
1611 null, do not copy; instead, return the length of what the result
1614 yytnamerr (char *yyres, const char *yystr)
1619 char const *yyp = yystr;
1626 goto do_not_strip_quotes;
1630 goto do_not_strip_quotes;
1643 do_not_strip_quotes: ;
1647 return yystrlen (yystr);
1649 return yystpcpy (yyres, yystr) - yyres;
1653 /* Copy into YYRESULT an error message about the unexpected token
1654 YYCHAR while in state YYSTATE. Return the number of bytes copied,
1655 including the terminating null byte. If YYRESULT is null, do not
1656 copy anything; just return the number of bytes that would be
1657 copied. As a special case, return 0 if an ordinary "syntax error"
1658 message will do. Return YYSIZE_MAXIMUM if overflow occurs during
1659 size calculation. */
1661 yysyntax_error (char *yyresult, int yystate, int yychar)
1663 int yyn = yypact[yystate];
1665 if (! (YYPACT_NINF < yyn && yyn <= YYLAST))
1669 int yytype = YYTRANSLATE (yychar);
1670 YYSIZE_T yysize0 = yytnamerr (0, yytname[yytype]);
1671 YYSIZE_T yysize = yysize0;
1673 int yysize_overflow = 0;
1674 enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
1675 char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
1679 /* This is so xgettext sees the translatable formats that are
1680 constructed on the fly. */
1681 YY_("syntax error, unexpected %s");
1682 YY_("syntax error, unexpected %s, expecting %s");
1683 YY_("syntax error, unexpected %s, expecting %s or %s");
1684 YY_("syntax error, unexpected %s, expecting %s or %s or %s");
1685 YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s");
1689 static char const yyunexpected[] = "syntax error, unexpected %s";
1690 static char const yyexpecting[] = ", expecting %s";
1691 static char const yyor[] = " or %s";
1692 char yyformat[sizeof yyunexpected
1693 + sizeof yyexpecting - 1
1694 + ((YYERROR_VERBOSE_ARGS_MAXIMUM - 2)
1695 * (sizeof yyor - 1))];
1696 char const *yyprefix = yyexpecting;
1698 /* Start YYX at -YYN if negative to avoid negative indexes in
1700 int yyxbegin = yyn < 0 ? -yyn : 0;
1702 /* Stay within bounds of both yycheck and yytname. */
1703 int yychecklim = YYLAST - yyn + 1;
1704 int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
1707 yyarg[0] = yytname[yytype];
1708 yyfmt = yystpcpy (yyformat, yyunexpected);
1710 for (yyx = yyxbegin; yyx < yyxend; ++yyx)
1711 if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
1713 if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
1717 yyformat[sizeof yyunexpected - 1] = '\0';
1720 yyarg[yycount++] = yytname[yyx];
1721 yysize1 = yysize + yytnamerr (0, yytname[yyx]);
1722 yysize_overflow |= (yysize1 < yysize);
1724 yyfmt = yystpcpy (yyfmt, yyprefix);
1728 yyf = YY_(yyformat);
1729 yysize1 = yysize + yystrlen (yyf);
1730 yysize_overflow |= (yysize1 < yysize);
1733 if (yysize_overflow)
1734 return YYSIZE_MAXIMUM;
1738 /* Avoid sprintf, as that infringes on the user's name space.
1739 Don't have undefined behavior even if the translation
1740 produced a string with the wrong number of "%s"s. */
1741 char *yyp = yyresult;
1743 while ((*yyp = *yyf) != '\0')
1745 if (*yyp == '%' && yyf[1] == 's' && yyi < yycount)
1747 yyp += yytnamerr (yyp, yyarg[yyi++]);
1760 #endif /* YYERROR_VERBOSE */
1763 /*-----------------------------------------------.
1764 | Release the memory associated to this symbol. |
1765 `-----------------------------------------------*/
1768 #if (defined __STDC__ || defined __C99__FUNC__ \
1769 || defined __cplusplus || defined _MSC_VER)
1771 yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep)
1774 yydestruct (yymsg, yytype, yyvaluep)
1784 YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
1795 /* Prevent warnings from -Wmissing-prototypes. */
1797 #ifdef YYPARSE_PARAM
1798 #if defined __STDC__ || defined __cplusplus
1799 int yyparse (void *YYPARSE_PARAM);
1803 #else /* ! YYPARSE_PARAM */
1804 #if defined __STDC__ || defined __cplusplus
1809 #endif /* ! YYPARSE_PARAM */
1813 /* The look-ahead symbol. */
1816 /* The semantic value of the look-ahead symbol. */
1819 /* Number of syntax errors so far. */
1828 #ifdef YYPARSE_PARAM
1829 #if (defined __STDC__ || defined __C99__FUNC__ \
1830 || defined __cplusplus || defined _MSC_VER)
1832 yyparse (void *YYPARSE_PARAM)
1835 yyparse (YYPARSE_PARAM)
1836 void *YYPARSE_PARAM;
1838 #else /* ! YYPARSE_PARAM */
1839 #if (defined __STDC__ || defined __C99__FUNC__ \
1840 || defined __cplusplus || defined _MSC_VER)
1854 /* Number of tokens to shift before error messages enabled. */
1856 /* Look-ahead token as an internal (translated) token number. */
1859 /* Buffer for error messages, and its allocated size. */
1861 char *yymsg = yymsgbuf;
1862 YYSIZE_T yymsg_alloc = sizeof yymsgbuf;
1865 /* Three stacks and their tools:
1866 `yyss': related to states,
1867 `yyvs': related to semantic values,
1868 `yyls': related to locations.
1870 Refer to the stacks thru separate pointers, to allow yyoverflow
1871 to reallocate them elsewhere. */
1873 /* The state stack. */
1874 yytype_int16 yyssa[YYINITDEPTH];
1875 yytype_int16 *yyss = yyssa;
1876 yytype_int16 *yyssp;
1878 /* The semantic value stack. */
1879 YYSTYPE yyvsa[YYINITDEPTH];
1880 YYSTYPE *yyvs = yyvsa;
1885 #define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N))
1887 YYSIZE_T yystacksize = YYINITDEPTH;
1889 /* The variables used to return semantic value and location from the
1894 /* The number of symbols on the RHS of the reduced rule.
1895 Keep to zero when no symbol should be popped. */
1898 YYDPRINTF ((stderr, "Starting parse\n"));
1903 yychar = YYEMPTY; /* Cause a token to be read. */
1905 /* Initialize stack pointers.
1906 Waste one element of value and location stack
1907 so that they stay on the same level as the state stack.
1908 The wasted elements are never initialized. */
1915 /*------------------------------------------------------------.
1916 | yynewstate -- Push a new state, which is found in yystate. |
1917 `------------------------------------------------------------*/
1919 /* In all cases, when you get here, the value and location stacks
1920 have just been pushed. So pushing a state here evens the stacks. */
1926 if (yyss + yystacksize - 1 <= yyssp)
1928 /* Get the current used size of the three stacks, in elements. */
1929 YYSIZE_T yysize = yyssp - yyss + 1;
1933 /* Give user a chance to reallocate the stack. Use copies of
1934 these so that the &'s don't force the real ones into
1936 YYSTYPE *yyvs1 = yyvs;
1937 yytype_int16 *yyss1 = yyss;
1940 /* Each stack pointer address is followed by the size of the
1941 data in use in that stack, in bytes. This used to be a
1942 conditional around just the two extra args, but that might
1943 be undefined if yyoverflow is a macro. */
1944 yyoverflow (YY_("memory exhausted"),
1945 &yyss1, yysize * sizeof (*yyssp),
1946 &yyvs1, yysize * sizeof (*yyvsp),
1953 #else /* no yyoverflow */
1954 # ifndef YYSTACK_RELOCATE
1955 goto yyexhaustedlab;
1957 /* Extend the stack our own way. */
1958 if (YYMAXDEPTH <= yystacksize)
1959 goto yyexhaustedlab;
1961 if (YYMAXDEPTH < yystacksize)
1962 yystacksize = YYMAXDEPTH;
1965 yytype_int16 *yyss1 = yyss;
1966 union yyalloc *yyptr =
1967 (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
1969 goto yyexhaustedlab;
1970 YYSTACK_RELOCATE (yyss);
1971 YYSTACK_RELOCATE (yyvs);
1973 # undef YYSTACK_RELOCATE
1975 YYSTACK_FREE (yyss1);
1978 #endif /* no yyoverflow */
1980 yyssp = yyss + yysize - 1;
1981 yyvsp = yyvs + yysize - 1;
1984 YYDPRINTF ((stderr, "Stack size increased to %lu\n",
1985 (unsigned long int) yystacksize));
1987 if (yyss + yystacksize - 1 <= yyssp)
1991 YYDPRINTF ((stderr, "Entering state %d\n", yystate));
2000 /* Do appropriate processing given the current state. Read a
2001 look-ahead token if we need one and don't already have one. */
2003 /* First try to decide what to do without reference to look-ahead token. */
2004 yyn = yypact[yystate];
2005 if (yyn == YYPACT_NINF)
2008 /* Not known => get a look-ahead token if don't already have one. */
2010 /* YYCHAR is either YYEMPTY or YYEOF or a valid look-ahead symbol. */
2011 if (yychar == YYEMPTY)
2013 YYDPRINTF ((stderr, "Reading a token: "));
2017 if (yychar <= YYEOF)
2019 yychar = yytoken = YYEOF;
2020 YYDPRINTF ((stderr, "Now at end of input.\n"));
2024 yytoken = YYTRANSLATE (yychar);
2025 YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
2028 /* If the proper action on seeing token YYTOKEN is to reduce or to
2029 detect an error, take that action. */
2031 if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
2036 if (yyn == 0 || yyn == YYTABLE_NINF)
2045 /* Count tokens shifted since error; after three, turn off error
2050 /* Shift the look-ahead token. */
2051 YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
2053 /* Discard the shifted token unless it is eof. */
2054 if (yychar != YYEOF)
2063 /*-----------------------------------------------------------.
2064 | yydefault -- do the default action for the current state. |
2065 `-----------------------------------------------------------*/
2067 yyn = yydefact[yystate];
2073 /*-----------------------------.
2074 | yyreduce -- Do a reduction. |
2075 `-----------------------------*/
2077 /* yyn is the number of a rule to reduce with. */
2080 /* If YYLEN is nonzero, implement the default value of the action:
2083 Otherwise, the following line sets YYVAL to garbage.
2084 This behavior is undocumented and Bison
2085 users should not rely upon it. Assigning to YYVAL
2086 unconditionally makes the parser a bit smaller, and it avoids a
2087 GCC warning that YYVAL may be used uninitialized. */
2088 yyval = yyvsp[1-yylen];
2091 YY_REDUCE_PRINT (yyn);
2095 #line 377 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
2097 /* Case of regular command. Discard the error
2098 safety net,and return the command just parsed. */
2099 global_command = (yyvsp[(1) - (2)].command);
2100 eof_encountered = 0;
2101 /* discard_parser_constructs (0); */
2102 if (parser_state & PST_CMDSUBST)
2103 parser_state |= PST_EOFTOKEN;
2109 #line 388 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
2111 /* Case of regular command, but not a very
2112 interesting one. Return a NULL command. */
2113 global_command = (COMMAND *)NULL;
2114 if (parser_state & PST_CMDSUBST)
2115 parser_state |= PST_EOFTOKEN;
2121 #line 397 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
2123 /* Error during parsing. Return NULL command. */
2124 global_command = (COMMAND *)NULL;
2125 eof_encountered = 0;
2126 /* discard_parser_constructs (1); */
2127 if (interactive && parse_and_execute_level == 0)
2139 #line 412 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
2141 /* Case of EOF seen by itself. Do ignoreeof or
2143 global_command = (COMMAND *)NULL;
2144 handle_eof_input_unit ();
2150 #line 422 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
2151 { (yyval.word_list) = make_word_list ((yyvsp[(1) - (1)].word), (WORD_LIST *)NULL); }
2155 #line 424 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
2156 { (yyval.word_list) = make_word_list ((yyvsp[(2) - (2)].word), (yyvsp[(1) - (2)].word_list)); }
2160 #line 428 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
2163 redir.filename = (yyvsp[(2) - (2)].word);
2164 (yyval.redirect) = make_redirection (source, r_output_direction, redir, 0);
2169 #line 434 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
2172 redir.filename = (yyvsp[(2) - (2)].word);
2173 (yyval.redirect) = make_redirection (source, r_input_direction, redir, 0);
2178 #line 440 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
2180 source.dest = (yyvsp[(1) - (3)].number);
2181 redir.filename = (yyvsp[(3) - (3)].word);
2182 (yyval.redirect) = make_redirection (source, r_output_direction, redir, 0);
2187 #line 446 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
2189 source.dest = (yyvsp[(1) - (3)].number);
2190 redir.filename = (yyvsp[(3) - (3)].word);
2191 (yyval.redirect) = make_redirection (source, r_input_direction, redir, 0);
2196 #line 452 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
2198 source.filename = (yyvsp[(1) - (3)].word);
2199 redir.filename = (yyvsp[(3) - (3)].word);
2200 (yyval.redirect) = make_redirection (source, r_output_direction, redir, REDIR_VARASSIGN);
2205 #line 458 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
2207 source.filename = (yyvsp[(1) - (3)].word);
2208 redir.filename = (yyvsp[(3) - (3)].word);
2209 (yyval.redirect) = make_redirection (source, r_input_direction, redir, REDIR_VARASSIGN);
2214 #line 464 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
2217 redir.filename = (yyvsp[(2) - (2)].word);
2218 (yyval.redirect) = make_redirection (source, r_appending_to, redir, 0);
2223 #line 470 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
2225 source.dest = (yyvsp[(1) - (3)].number);
2226 redir.filename = (yyvsp[(3) - (3)].word);
2227 (yyval.redirect) = make_redirection (source, r_appending_to, redir, 0);
2232 #line 476 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
2234 source.filename = (yyvsp[(1) - (3)].word);
2235 redir.filename = (yyvsp[(3) - (3)].word);
2236 (yyval.redirect) = make_redirection (source, r_appending_to, redir, REDIR_VARASSIGN);
2241 #line 482 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
2244 redir.filename = (yyvsp[(2) - (2)].word);
2245 (yyval.redirect) = make_redirection (source, r_output_force, redir, 0);
2250 #line 488 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
2252 source.dest = (yyvsp[(1) - (3)].number);
2253 redir.filename = (yyvsp[(3) - (3)].word);
2254 (yyval.redirect) = make_redirection (source, r_output_force, redir, 0);
2259 #line 494 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
2261 source.filename = (yyvsp[(1) - (3)].word);
2262 redir.filename = (yyvsp[(3) - (3)].word);
2263 (yyval.redirect) = make_redirection (source, r_output_force, redir, REDIR_VARASSIGN);
2268 #line 500 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
2271 redir.filename = (yyvsp[(2) - (2)].word);
2272 (yyval.redirect) = make_redirection (source, r_input_output, redir, 0);
2277 #line 506 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
2279 source.dest = (yyvsp[(1) - (3)].number);
2280 redir.filename = (yyvsp[(3) - (3)].word);
2281 (yyval.redirect) = make_redirection (source, r_input_output, redir, 0);
2286 #line 512 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
2288 source.filename = (yyvsp[(1) - (3)].word);
2289 redir.filename = (yyvsp[(3) - (3)].word);
2290 (yyval.redirect) = make_redirection (source, r_input_output, redir, REDIR_VARASSIGN);
2295 #line 518 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
2298 redir.filename = (yyvsp[(2) - (2)].word);
2299 (yyval.redirect) = make_redirection (source, r_reading_until, redir, 0);
2300 redir_stack[need_here_doc++] = (yyval.redirect);
2305 #line 525 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
2307 source.dest = (yyvsp[(1) - (3)].number);
2308 redir.filename = (yyvsp[(3) - (3)].word);
2309 (yyval.redirect) = make_redirection (source, r_reading_until, redir, 0);
2310 redir_stack[need_here_doc++] = (yyval.redirect);
2315 #line 532 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
2317 source.filename = (yyvsp[(1) - (3)].word);
2318 redir.filename = (yyvsp[(3) - (3)].word);
2319 (yyval.redirect) = make_redirection (source, r_reading_until, redir, REDIR_VARASSIGN);
2320 redir_stack[need_here_doc++] = (yyval.redirect);
2325 #line 539 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
2328 redir.filename = (yyvsp[(2) - (2)].word);
2329 (yyval.redirect) = make_redirection (source, r_deblank_reading_until, redir, 0);
2330 redir_stack[need_here_doc++] = (yyval.redirect);
2335 #line 546 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
2337 source.dest = (yyvsp[(1) - (3)].number);
2338 redir.filename = (yyvsp[(3) - (3)].word);
2339 (yyval.redirect) = make_redirection (source, r_deblank_reading_until, redir, 0);
2340 redir_stack[need_here_doc++] = (yyval.redirect);
2345 #line 553 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
2347 source.filename = (yyvsp[(1) - (3)].word);
2348 redir.filename = (yyvsp[(3) - (3)].word);
2349 (yyval.redirect) = make_redirection (source, r_deblank_reading_until, redir, REDIR_VARASSIGN);
2350 redir_stack[need_here_doc++] = (yyval.redirect);
2355 #line 560 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
2358 redir.filename = (yyvsp[(2) - (2)].word);
2359 (yyval.redirect) = make_redirection (source, r_reading_string, redir, 0);
2364 #line 566 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
2366 source.dest = (yyvsp[(1) - (3)].number);
2367 redir.filename = (yyvsp[(3) - (3)].word);
2368 (yyval.redirect) = make_redirection (source, r_reading_string, redir, 0);
2373 #line 572 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
2375 source.filename = (yyvsp[(1) - (3)].word);
2376 redir.filename = (yyvsp[(3) - (3)].word);
2377 (yyval.redirect) = make_redirection (source, r_reading_string, redir, REDIR_VARASSIGN);
2382 #line 578 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
2385 redir.dest = (yyvsp[(2) - (2)].number);
2386 (yyval.redirect) = make_redirection (source, r_duplicating_input, redir, 0);
2391 #line 584 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
2393 source.dest = (yyvsp[(1) - (3)].number);
2394 redir.dest = (yyvsp[(3) - (3)].number);
2395 (yyval.redirect) = make_redirection (source, r_duplicating_input, redir, 0);
2400 #line 590 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
2402 source.filename = (yyvsp[(1) - (3)].word);
2403 redir.dest = (yyvsp[(3) - (3)].number);
2404 (yyval.redirect) = make_redirection (source, r_duplicating_input, redir, REDIR_VARASSIGN);
2409 #line 596 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
2412 redir.dest = (yyvsp[(2) - (2)].number);
2413 (yyval.redirect) = make_redirection (source, r_duplicating_output, redir, 0);
2418 #line 602 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
2420 source.dest = (yyvsp[(1) - (3)].number);
2421 redir.dest = (yyvsp[(3) - (3)].number);
2422 (yyval.redirect) = make_redirection (source, r_duplicating_output, redir, 0);
2427 #line 608 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
2429 source.filename = (yyvsp[(1) - (3)].word);
2430 redir.dest = (yyvsp[(3) - (3)].number);
2431 (yyval.redirect) = make_redirection (source, r_duplicating_output, redir, REDIR_VARASSIGN);
2436 #line 614 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
2439 redir.filename = (yyvsp[(2) - (2)].word);
2440 (yyval.redirect) = make_redirection (source, r_duplicating_input_word, redir, 0);
2445 #line 620 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
2447 source.dest = (yyvsp[(1) - (3)].number);
2448 redir.filename = (yyvsp[(3) - (3)].word);
2449 (yyval.redirect) = make_redirection (source, r_duplicating_input_word, redir, 0);
2454 #line 626 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
2456 source.filename = (yyvsp[(1) - (3)].word);
2457 redir.filename = (yyvsp[(3) - (3)].word);
2458 (yyval.redirect) = make_redirection (source, r_duplicating_input_word, redir, REDIR_VARASSIGN);
2463 #line 632 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
2466 redir.filename = (yyvsp[(2) - (2)].word);
2467 (yyval.redirect) = make_redirection (source, r_duplicating_output_word, redir, 0);
2472 #line 638 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
2474 source.dest = (yyvsp[(1) - (3)].number);
2475 redir.filename = (yyvsp[(3) - (3)].word);
2476 (yyval.redirect) = make_redirection (source, r_duplicating_output_word, redir, 0);
2481 #line 644 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
2483 source.filename = (yyvsp[(1) - (3)].word);
2484 redir.filename = (yyvsp[(3) - (3)].word);
2485 (yyval.redirect) = make_redirection (source, r_duplicating_output_word, redir, REDIR_VARASSIGN);
2490 #line 650 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
2494 (yyval.redirect) = make_redirection (source, r_close_this, redir, 0);
2499 #line 656 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
2501 source.dest = (yyvsp[(1) - (3)].number);
2503 (yyval.redirect) = make_redirection (source, r_close_this, redir, 0);
2508 #line 662 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
2510 source.filename = (yyvsp[(1) - (3)].word);
2512 (yyval.redirect) = make_redirection (source, r_close_this, redir, REDIR_VARASSIGN);
2517 #line 668 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
2521 (yyval.redirect) = make_redirection (source, r_close_this, redir, 0);
2526 #line 674 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
2528 source.dest = (yyvsp[(1) - (3)].number);
2530 (yyval.redirect) = make_redirection (source, r_close_this, redir, 0);
2535 #line 680 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
2537 source.filename = (yyvsp[(1) - (3)].word);
2539 (yyval.redirect) = make_redirection (source, r_close_this, redir, REDIR_VARASSIGN);
2544 #line 686 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
2547 redir.filename = (yyvsp[(2) - (2)].word);
2548 (yyval.redirect) = make_redirection (source, r_err_and_out, redir, 0);
2553 #line 692 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
2556 redir.filename = (yyvsp[(2) - (2)].word);
2557 (yyval.redirect) = make_redirection (source, r_append_err_and_out, redir, 0);
2562 #line 700 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
2563 { (yyval.element).word = (yyvsp[(1) - (1)].word); (yyval.element).redirect = 0; }
2567 #line 702 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
2568 { (yyval.element).word = (yyvsp[(1) - (1)].word); (yyval.element).redirect = 0; }
2572 #line 704 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
2573 { (yyval.element).redirect = (yyvsp[(1) - (1)].redirect); (yyval.element).word = 0; }
2577 #line 708 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
2579 (yyval.redirect) = (yyvsp[(1) - (1)].redirect);
2584 #line 712 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
2586 register REDIRECT *t;
2588 for (t = (yyvsp[(1) - (2)].redirect); t->next; t = t->next)
2590 t->next = (yyvsp[(2) - (2)].redirect);
2591 (yyval.redirect) = (yyvsp[(1) - (2)].redirect);
2596 #line 723 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
2597 { (yyval.command) = make_simple_command ((yyvsp[(1) - (1)].element), (COMMAND *)NULL); }
2601 #line 725 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
2602 { (yyval.command) = make_simple_command ((yyvsp[(2) - (2)].element), (yyvsp[(1) - (2)].command)); }
2606 #line 729 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
2607 { (yyval.command) = clean_simple_command ((yyvsp[(1) - (1)].command)); }
2611 #line 731 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
2612 { (yyval.command) = (yyvsp[(1) - (1)].command); }
2616 #line 733 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
2620 tc = (yyvsp[(1) - (2)].command);
2623 register REDIRECT *t;
2624 for (t = tc->redirects; t->next; t = t->next)
2626 t->next = (yyvsp[(2) - (2)].redirect);
2629 tc->redirects = (yyvsp[(2) - (2)].redirect);
2630 (yyval.command) = (yyvsp[(1) - (2)].command);
2635 #line 749 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
2636 { (yyval.command) = (yyvsp[(1) - (1)].command); }
2640 #line 751 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
2641 { (yyval.command) = (yyvsp[(1) - (1)].command); }
2645 #line 755 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
2646 { (yyval.command) = (yyvsp[(1) - (1)].command); }
2650 #line 757 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
2651 { (yyval.command) = (yyvsp[(1) - (1)].command); }
2655 #line 759 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
2656 { (yyval.command) = make_while_command ((yyvsp[(2) - (5)].command), (yyvsp[(4) - (5)].command)); }
2660 #line 761 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
2661 { (yyval.command) = make_until_command ((yyvsp[(2) - (5)].command), (yyvsp[(4) - (5)].command)); }
2665 #line 763 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
2666 { (yyval.command) = (yyvsp[(1) - (1)].command); }
2670 #line 765 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
2671 { (yyval.command) = (yyvsp[(1) - (1)].command); }
2675 #line 767 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
2676 { (yyval.command) = (yyvsp[(1) - (1)].command); }
2680 #line 769 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
2681 { (yyval.command) = (yyvsp[(1) - (1)].command); }
2685 #line 771 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
2686 { (yyval.command) = (yyvsp[(1) - (1)].command); }
2690 #line 773 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
2691 { (yyval.command) = (yyvsp[(1) - (1)].command); }
2695 #line 775 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
2696 { (yyval.command) = (yyvsp[(1) - (1)].command); }
2700 #line 779 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
2702 (yyval.command) = make_for_command ((yyvsp[(2) - (6)].word), add_string_to_list ("\"$@\"", (WORD_LIST *)NULL), (yyvsp[(5) - (6)].command), word_lineno[word_top]);
2703 if (word_top > 0) word_top--;
2708 #line 784 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
2710 (yyval.command) = make_for_command ((yyvsp[(2) - (6)].word), add_string_to_list ("\"$@\"", (WORD_LIST *)NULL), (yyvsp[(5) - (6)].command), word_lineno[word_top]);
2711 if (word_top > 0) word_top--;
2716 #line 789 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
2718 (yyval.command) = make_for_command ((yyvsp[(2) - (7)].word), add_string_to_list ("\"$@\"", (WORD_LIST *)NULL), (yyvsp[(6) - (7)].command), word_lineno[word_top]);
2719 if (word_top > 0) word_top--;
2724 #line 794 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
2726 (yyval.command) = make_for_command ((yyvsp[(2) - (7)].word), add_string_to_list ("\"$@\"", (WORD_LIST *)NULL), (yyvsp[(6) - (7)].command), word_lineno[word_top]);
2727 if (word_top > 0) word_top--;
2732 #line 799 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
2734 (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]);
2735 if (word_top > 0) word_top--;
2740 #line 804 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
2742 (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]);
2743 if (word_top > 0) word_top--;
2748 #line 809 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
2750 (yyval.command) = make_for_command ((yyvsp[(2) - (9)].word), (WORD_LIST *)NULL, (yyvsp[(8) - (9)].command), word_lineno[word_top]);
2751 if (word_top > 0) word_top--;
2756 #line 814 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
2758 (yyval.command) = make_for_command ((yyvsp[(2) - (9)].word), (WORD_LIST *)NULL, (yyvsp[(8) - (9)].command), word_lineno[word_top]);
2759 if (word_top > 0) word_top--;
2764 #line 821 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
2766 (yyval.command) = make_arith_for_command ((yyvsp[(2) - (7)].word_list), (yyvsp[(6) - (7)].command), arith_for_lineno);
2767 if (word_top > 0) word_top--;
2772 #line 826 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
2774 (yyval.command) = make_arith_for_command ((yyvsp[(2) - (7)].word_list), (yyvsp[(6) - (7)].command), arith_for_lineno);
2775 if (word_top > 0) word_top--;
2780 #line 831 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
2782 (yyval.command) = make_arith_for_command ((yyvsp[(2) - (5)].word_list), (yyvsp[(4) - (5)].command), arith_for_lineno);
2783 if (word_top > 0) word_top--;
2788 #line 836 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
2790 (yyval.command) = make_arith_for_command ((yyvsp[(2) - (5)].word_list), (yyvsp[(4) - (5)].command), arith_for_lineno);
2791 if (word_top > 0) word_top--;
2796 #line 843 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
2798 (yyval.command) = make_select_command ((yyvsp[(2) - (6)].word), add_string_to_list ("\"$@\"", (WORD_LIST *)NULL), (yyvsp[(5) - (6)].command), word_lineno[word_top]);
2799 if (word_top > 0) word_top--;
2804 #line 848 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
2806 (yyval.command) = make_select_command ((yyvsp[(2) - (6)].word), add_string_to_list ("\"$@\"", (WORD_LIST *)NULL), (yyvsp[(5) - (6)].command), word_lineno[word_top]);
2807 if (word_top > 0) word_top--;
2812 #line 853 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
2814 (yyval.command) = make_select_command ((yyvsp[(2) - (7)].word), add_string_to_list ("\"$@\"", (WORD_LIST *)NULL), (yyvsp[(6) - (7)].command), word_lineno[word_top]);
2815 if (word_top > 0) word_top--;
2820 #line 858 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
2822 (yyval.command) = make_select_command ((yyvsp[(2) - (7)].word), add_string_to_list ("\"$@\"", (WORD_LIST *)NULL), (yyvsp[(6) - (7)].command), word_lineno[word_top]);
2823 if (word_top > 0) word_top--;
2828 #line 863 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
2830 (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]);
2831 if (word_top > 0) word_top--;
2836 #line 868 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
2838 (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]);
2839 if (word_top > 0) word_top--;
2844 #line 875 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
2846 (yyval.command) = make_case_command ((yyvsp[(2) - (6)].word), (PATTERN_LIST *)NULL, word_lineno[word_top]);
2847 if (word_top > 0) word_top--;
2852 #line 880 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
2854 (yyval.command) = make_case_command ((yyvsp[(2) - (7)].word), (yyvsp[(5) - (7)].pattern), word_lineno[word_top]);
2855 if (word_top > 0) word_top--;
2860 #line 885 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
2862 (yyval.command) = make_case_command ((yyvsp[(2) - (6)].word), (yyvsp[(5) - (6)].pattern), word_lineno[word_top]);
2863 if (word_top > 0) word_top--;
2868 #line 892 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
2869 { (yyval.command) = make_function_def ((yyvsp[(1) - (5)].word), (yyvsp[(5) - (5)].command), function_dstart, function_bstart); }
2873 #line 895 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
2874 { (yyval.command) = make_function_def ((yyvsp[(2) - (6)].word), (yyvsp[(6) - (6)].command), function_dstart, function_bstart); }
2878 #line 898 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
2879 { (yyval.command) = make_function_def ((yyvsp[(2) - (4)].word), (yyvsp[(4) - (4)].command), function_dstart, function_bstart); }
2883 #line 902 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
2884 { (yyval.command) = (yyvsp[(1) - (1)].command); }
2888 #line 904 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
2892 tc = (yyvsp[(1) - (2)].command);
2893 /* According to Posix.2 3.9.5, redirections
2894 specified after the body of a function should
2895 be attached to the function and performed when
2896 the function is executed, not as part of the
2897 function definition command. */
2898 /* XXX - I don't think it matters, but we might
2899 want to change this in the future to avoid
2900 problems differentiating between a function
2901 definition with a redirection and a function
2902 definition containing a single command with a
2903 redirection. The two are semantically equivalent,
2904 though -- the only difference is in how the
2905 command printing code displays the redirections. */
2908 register REDIRECT *t;
2909 for (t = tc->redirects; t->next; t = t->next)
2911 t->next = (yyvsp[(2) - (2)].redirect);
2914 tc->redirects = (yyvsp[(2) - (2)].redirect);
2915 (yyval.command) = (yyvsp[(1) - (2)].command);
2920 #line 935 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
2922 (yyval.command) = make_subshell_command ((yyvsp[(2) - (3)].command));
2923 (yyval.command)->flags |= CMD_WANT_SUBSHELL;
2928 #line 942 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
2930 (yyval.command) = make_coproc_command ("COPROC", (yyvsp[(2) - (2)].command));
2931 (yyval.command)->flags |= CMD_WANT_SUBSHELL|CMD_COPROC_SUBSHELL;
2936 #line 947 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
2940 tc = (yyvsp[(2) - (3)].command);
2943 register REDIRECT *t;
2944 for (t = tc->redirects; t->next; t = t->next)
2946 t->next = (yyvsp[(3) - (3)].redirect);
2949 tc->redirects = (yyvsp[(3) - (3)].redirect);
2950 (yyval.command) = make_coproc_command ("COPROC", (yyvsp[(2) - (3)].command));
2951 (yyval.command)->flags |= CMD_WANT_SUBSHELL|CMD_COPROC_SUBSHELL;
2956 #line 964 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
2958 (yyval.command) = make_coproc_command ((yyvsp[(2) - (3)].word)->word, (yyvsp[(3) - (3)].command));
2959 (yyval.command)->flags |= CMD_WANT_SUBSHELL|CMD_COPROC_SUBSHELL;
2964 #line 969 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
2968 tc = (yyvsp[(3) - (4)].command);
2971 register REDIRECT *t;
2972 for (t = tc->redirects; t->next; t = t->next)
2974 t->next = (yyvsp[(4) - (4)].redirect);
2977 tc->redirects = (yyvsp[(4) - (4)].redirect);
2978 (yyval.command) = make_coproc_command ((yyvsp[(2) - (4)].word)->word, (yyvsp[(3) - (4)].command));
2979 (yyval.command)->flags |= CMD_WANT_SUBSHELL|CMD_COPROC_SUBSHELL;
2984 #line 986 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
2986 (yyval.command) = make_coproc_command ("COPROC", clean_simple_command ((yyvsp[(2) - (2)].command)));
2987 (yyval.command)->flags |= CMD_WANT_SUBSHELL|CMD_COPROC_SUBSHELL;
2992 #line 993 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
2993 { (yyval.command) = make_if_command ((yyvsp[(2) - (5)].command), (yyvsp[(4) - (5)].command), (COMMAND *)NULL); }
2997 #line 995 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
2998 { (yyval.command) = make_if_command ((yyvsp[(2) - (7)].command), (yyvsp[(4) - (7)].command), (yyvsp[(6) - (7)].command)); }
3002 #line 997 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
3003 { (yyval.command) = make_if_command ((yyvsp[(2) - (6)].command), (yyvsp[(4) - (6)].command), (yyvsp[(5) - (6)].command)); }
3007 #line 1002 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
3008 { (yyval.command) = make_group_command ((yyvsp[(2) - (3)].command)); }
3012 #line 1006 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
3013 { (yyval.command) = make_arith_command ((yyvsp[(1) - (1)].word_list)); }
3017 #line 1010 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
3018 { (yyval.command) = (yyvsp[(2) - (3)].command); }
3022 #line 1014 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
3023 { (yyval.command) = make_if_command ((yyvsp[(2) - (4)].command), (yyvsp[(4) - (4)].command), (COMMAND *)NULL); }
3027 #line 1016 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
3028 { (yyval.command) = make_if_command ((yyvsp[(2) - (6)].command), (yyvsp[(4) - (6)].command), (yyvsp[(6) - (6)].command)); }
3032 #line 1018 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
3033 { (yyval.command) = make_if_command ((yyvsp[(2) - (5)].command), (yyvsp[(4) - (5)].command), (yyvsp[(5) - (5)].command)); }
3037 #line 1023 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
3038 { (yyvsp[(2) - (2)].pattern)->next = (yyvsp[(1) - (2)].pattern); (yyval.pattern) = (yyvsp[(2) - (2)].pattern); }
3042 #line 1027 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
3043 { (yyval.pattern) = make_pattern_list ((yyvsp[(2) - (4)].word_list), (yyvsp[(4) - (4)].command)); }
3047 #line 1029 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
3048 { (yyval.pattern) = make_pattern_list ((yyvsp[(2) - (4)].word_list), (COMMAND *)NULL); }
3052 #line 1031 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
3053 { (yyval.pattern) = make_pattern_list ((yyvsp[(3) - (5)].word_list), (yyvsp[(5) - (5)].command)); }
3057 #line 1033 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
3058 { (yyval.pattern) = make_pattern_list ((yyvsp[(3) - (5)].word_list), (COMMAND *)NULL); }
3062 #line 1037 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
3063 { (yyval.pattern) = (yyvsp[(1) - (2)].pattern); }
3067 #line 1039 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
3068 { (yyvsp[(2) - (3)].pattern)->next = (yyvsp[(1) - (3)].pattern); (yyval.pattern) = (yyvsp[(2) - (3)].pattern); }
3072 #line 1041 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
3073 { (yyvsp[(1) - (2)].pattern)->flags |= CASEPAT_FALLTHROUGH; (yyval.pattern) = (yyvsp[(1) - (2)].pattern); }
3077 #line 1043 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
3078 { (yyvsp[(2) - (3)].pattern)->flags |= CASEPAT_FALLTHROUGH; (yyvsp[(2) - (3)].pattern)->next = (yyvsp[(1) - (3)].pattern); (yyval.pattern) = (yyvsp[(2) - (3)].pattern); }
3082 #line 1045 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
3083 { (yyvsp[(1) - (2)].pattern)->flags |= CASEPAT_TESTNEXT; (yyval.pattern) = (yyvsp[(1) - (2)].pattern); }
3087 #line 1047 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
3088 { (yyvsp[(2) - (3)].pattern)->flags |= CASEPAT_TESTNEXT; (yyvsp[(2) - (3)].pattern)->next = (yyvsp[(1) - (3)].pattern); (yyval.pattern) = (yyvsp[(2) - (3)].pattern); }
3092 #line 1051 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
3093 { (yyval.word_list) = make_word_list ((yyvsp[(1) - (1)].word), (WORD_LIST *)NULL); }
3097 #line 1053 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
3098 { (yyval.word_list) = make_word_list ((yyvsp[(3) - (3)].word), (yyvsp[(1) - (3)].word_list)); }
3102 #line 1062 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
3104 (yyval.command) = (yyvsp[(2) - (2)].command);
3106 gather_here_documents ();
3111 #line 1071 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
3113 (yyval.command) = (yyvsp[(2) - (2)].command);
3118 #line 1078 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
3120 if ((yyvsp[(1) - (3)].command)->type == cm_connection)
3121 (yyval.command) = connect_async_list ((yyvsp[(1) - (3)].command), (COMMAND *)NULL, '&');
3123 (yyval.command) = command_connect ((yyvsp[(1) - (3)].command), (COMMAND *)NULL, '&');
3128 #line 1089 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
3129 { (yyval.command) = command_connect ((yyvsp[(1) - (4)].command), (yyvsp[(4) - (4)].command), AND_AND); }
3133 #line 1091 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
3134 { (yyval.command) = command_connect ((yyvsp[(1) - (4)].command), (yyvsp[(4) - (4)].command), OR_OR); }
3138 #line 1093 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
3140 if ((yyvsp[(1) - (4)].command)->type == cm_connection)
3141 (yyval.command) = connect_async_list ((yyvsp[(1) - (4)].command), (yyvsp[(4) - (4)].command), '&');
3143 (yyval.command) = command_connect ((yyvsp[(1) - (4)].command), (yyvsp[(4) - (4)].command), '&');
3148 #line 1100 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
3149 { (yyval.command) = command_connect ((yyvsp[(1) - (4)].command), (yyvsp[(4) - (4)].command), ';'); }
3153 #line 1102 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
3154 { (yyval.command) = command_connect ((yyvsp[(1) - (4)].command), (yyvsp[(4) - (4)].command), ';'); }
3158 #line 1104 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
3159 { (yyval.command) = (yyvsp[(1) - (1)].command); }
3163 #line 1112 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
3164 { (yyval.number) = '\n'; }
3168 #line 1114 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
3169 { (yyval.number) = ';'; }
3173 #line 1116 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
3174 { (yyval.number) = yacc_EOF; }
3178 #line 1130 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
3180 (yyval.command) = (yyvsp[(1) - (1)].command);
3182 gather_here_documents ();
3183 if ((parser_state & PST_CMDSUBST) && current_token == shell_eof_token)
3185 global_command = (yyvsp[(1) - (1)].command);
3186 eof_encountered = 0;
3187 rewind_input_string ();
3194 #line 1143 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
3196 if ((yyvsp[(1) - (2)].command)->type == cm_connection)
3197 (yyval.command) = connect_async_list ((yyvsp[(1) - (2)].command), (COMMAND *)NULL, '&');
3199 (yyval.command) = command_connect ((yyvsp[(1) - (2)].command), (COMMAND *)NULL, '&');
3201 gather_here_documents ();
3202 if ((parser_state & PST_CMDSUBST) && current_token == shell_eof_token)
3204 global_command = (yyvsp[(1) - (2)].command);
3205 eof_encountered = 0;
3206 rewind_input_string ();
3213 #line 1159 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
3215 (yyval.command) = (yyvsp[(1) - (2)].command);
3217 gather_here_documents ();
3218 if ((parser_state & PST_CMDSUBST) && current_token == shell_eof_token)
3220 global_command = (yyvsp[(1) - (2)].command);
3221 eof_encountered = 0;
3222 rewind_input_string ();
3229 #line 1174 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
3230 { (yyval.command) = command_connect ((yyvsp[(1) - (4)].command), (yyvsp[(4) - (4)].command), AND_AND); }
3234 #line 1176 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
3235 { (yyval.command) = command_connect ((yyvsp[(1) - (4)].command), (yyvsp[(4) - (4)].command), OR_OR); }
3239 #line 1178 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
3241 if ((yyvsp[(1) - (3)].command)->type == cm_connection)
3242 (yyval.command) = connect_async_list ((yyvsp[(1) - (3)].command), (yyvsp[(3) - (3)].command), '&');
3244 (yyval.command) = command_connect ((yyvsp[(1) - (3)].command), (yyvsp[(3) - (3)].command), '&');
3249 #line 1185 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
3250 { (yyval.command) = command_connect ((yyvsp[(1) - (3)].command), (yyvsp[(3) - (3)].command), ';'); }
3254 #line 1188 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
3255 { (yyval.command) = (yyvsp[(1) - (1)].command); }
3259 #line 1192 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
3260 { (yyval.command) = (yyvsp[(1) - (1)].command); }
3264 #line 1194 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
3266 if ((yyvsp[(2) - (2)].command))
3267 (yyvsp[(2) - (2)].command)->flags ^= CMD_INVERT_RETURN; /* toggle */
3268 (yyval.command) = (yyvsp[(2) - (2)].command);
3273 #line 1200 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
3275 if ((yyvsp[(2) - (2)].command))
3276 (yyvsp[(2) - (2)].command)->flags |= (yyvsp[(1) - (2)].number);
3277 (yyval.command) = (yyvsp[(2) - (2)].command);
3282 #line 1206 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
3286 /* Boy, this is unclean. `time' by itself can
3287 time a null command. We cheat and push a
3288 newline back if the list_terminator was a newline
3289 to avoid the double-newline problem (one to
3290 terminate this, one to terminate the command) */
3293 (yyval.command) = make_simple_command (x, (COMMAND *)NULL);
3294 (yyval.command)->flags |= (yyvsp[(1) - (2)].number);
3295 /* XXX - let's cheat and push a newline back */
3296 if ((yyvsp[(2) - (2)].number) == '\n')
3297 token_to_read = '\n';
3302 #line 1223 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
3306 /* This is just as unclean. Posix says that `!'
3307 by itself should be equivalent to `false'.
3309 newline back if the list_terminator was a newline
3310 to avoid the double-newline problem (one to
3311 terminate this, one to terminate the command) */
3314 (yyval.command) = make_simple_command (x, (COMMAND *)NULL);
3315 (yyval.command)->flags |= CMD_INVERT_RETURN;
3316 /* XXX - let's cheat and push a newline back */
3317 if ((yyvsp[(2) - (2)].number) == '\n')
3318 token_to_read = '\n';
3323 #line 1243 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
3324 { (yyval.command) = command_connect ((yyvsp[(1) - (4)].command), (yyvsp[(4) - (4)].command), '|'); }
3328 #line 1245 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
3330 /* Make cmd1 |& cmd2 equivalent to cmd1 2>&1 | cmd2 */
3335 tc = (yyvsp[(1) - (4)].command)->type == cm_simple ? (COMMAND *)(yyvsp[(1) - (4)].command)->value.Simple : (yyvsp[(1) - (4)].command);
3338 r = make_redirection (sd, r_duplicating_output, rd, 0);
3341 register REDIRECT *t;
3342 for (t = tc->redirects; t->next; t = t->next)
3349 (yyval.command) = command_connect ((yyvsp[(1) - (4)].command), (yyvsp[(4) - (4)].command), '|');
3354 #line 1268 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
3355 { (yyval.command) = (yyvsp[(1) - (1)].command); }
3359 #line 1272 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
3360 { (yyval.number) = CMD_TIME_PIPELINE; }
3364 #line 1274 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
3365 { (yyval.number) = CMD_TIME_PIPELINE|CMD_TIME_POSIX; }
3369 #line 1276 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
3370 { (yyval.number) = CMD_TIME_PIPELINE|CMD_TIME_POSIX; }
3374 /* Line 1267 of yacc.c. */
3375 #line 3376 "y.tab.c"
3378 YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc);
3382 YY_STACK_PRINT (yyss, yyssp);
3387 /* Now `shift' the result of the reduction. Determine what state
3388 that goes to, based on the state we popped back to and the rule
3389 number reduced by. */
3393 yystate = yypgoto[yyn - YYNTOKENS] + *yyssp;
3394 if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp)
3395 yystate = yytable[yystate];
3397 yystate = yydefgoto[yyn - YYNTOKENS];
3402 /*------------------------------------.
3403 | yyerrlab -- here on detecting error |
3404 `------------------------------------*/
3406 /* If not already recovering from an error, report this error. */
3410 #if ! YYERROR_VERBOSE
3411 yyerror (YY_("syntax error"));
3414 YYSIZE_T yysize = yysyntax_error (0, yystate, yychar);
3415 if (yymsg_alloc < yysize && yymsg_alloc < YYSTACK_ALLOC_MAXIMUM)
3417 YYSIZE_T yyalloc = 2 * yysize;
3418 if (! (yysize <= yyalloc && yyalloc <= YYSTACK_ALLOC_MAXIMUM))
3419 yyalloc = YYSTACK_ALLOC_MAXIMUM;
3420 if (yymsg != yymsgbuf)
3421 YYSTACK_FREE (yymsg);
3422 yymsg = (char *) YYSTACK_ALLOC (yyalloc);
3424 yymsg_alloc = yyalloc;
3428 yymsg_alloc = sizeof yymsgbuf;
3432 if (0 < yysize && yysize <= yymsg_alloc)
3434 (void) yysyntax_error (yymsg, yystate, yychar);
3439 yyerror (YY_("syntax error"));
3441 goto yyexhaustedlab;
3449 if (yyerrstatus == 3)
3451 /* If just tried and failed to reuse look-ahead token after an
3452 error, discard it. */
3454 if (yychar <= YYEOF)
3456 /* Return failure if at end of input. */
3457 if (yychar == YYEOF)
3462 yydestruct ("Error: discarding",
3468 /* Else will try to reuse look-ahead token after shifting the error
3473 /*---------------------------------------------------.
3474 | yyerrorlab -- error raised explicitly by YYERROR. |
3475 `---------------------------------------------------*/
3478 /* Pacify compilers like GCC when the user code never invokes
3479 YYERROR and the label yyerrorlab therefore never appears in user
3481 if (/*CONSTCOND*/ 0)
3484 /* Do not reclaim the symbols of the rule which action triggered
3488 YY_STACK_PRINT (yyss, yyssp);
3493 /*-------------------------------------------------------------.
3494 | yyerrlab1 -- common code for both syntax error and YYERROR. |
3495 `-------------------------------------------------------------*/
3497 yyerrstatus = 3; /* Each real token shifted decrements this. */
3501 yyn = yypact[yystate];
3502 if (yyn != YYPACT_NINF)
3505 if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
3513 /* Pop the current state because it cannot handle the error token. */
3518 yydestruct ("Error: popping",
3519 yystos[yystate], yyvsp);
3522 YY_STACK_PRINT (yyss, yyssp);
3531 /* Shift the error token. */
3532 YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp);
3538 /*-------------------------------------.
3539 | yyacceptlab -- YYACCEPT comes here. |
3540 `-------------------------------------*/
3545 /*-----------------------------------.
3546 | yyabortlab -- YYABORT comes here. |
3547 `-----------------------------------*/
3553 /*-------------------------------------------------.
3554 | yyexhaustedlab -- memory exhaustion comes here. |
3555 `-------------------------------------------------*/
3557 yyerror (YY_("memory exhausted"));
3563 if (yychar != YYEOF && yychar != YYEMPTY)
3564 yydestruct ("Cleanup: discarding lookahead",
3566 /* Do not reclaim the symbols of the rule which action triggered
3567 this YYABORT or YYACCEPT. */
3569 YY_STACK_PRINT (yyss, yyssp);
3570 while (yyssp != yyss)
3572 yydestruct ("Cleanup: popping",
3573 yystos[*yyssp], yyvsp);
3578 YYSTACK_FREE (yyss);
3581 if (yymsg != yymsgbuf)
3582 YYSTACK_FREE (yymsg);
3584 /* Make sure YYID is used. */
3585 return YYID (yyresult);
3589 #line 1278 "/usr/src/local/chet/src/bash/bash-4.2-patched/parse.y"
3592 /* Initial size to allocate for tokens, and the
3593 amount to grow them by. */
3594 #define TOKEN_DEFAULT_INITIAL_SIZE 496
3595 #define TOKEN_DEFAULT_GROW_SIZE 512
3597 /* Should we call prompt_again? */
3598 #define SHOULD_PROMPT() \
3599 (interactive && (bash_input.type == st_stdin || bash_input.type == st_stream))
3602 # define expanding_alias() (pushed_string_list && pushed_string_list->expander)
3604 # define expanding_alias() 0
3607 /* Global var is non-zero when end of file has been reached. */
3608 int EOF_Reached = 0;
3621 /* yy_getc () returns the next available character from input or EOF.
3622 yy_ungetc (c) makes `c' the next character to read.
3623 init_yy_io (get, unget, type, location) makes the function GET the
3624 installed function for getting the next character, makes UNGET the
3625 installed function for un-getting a character, sets the type of stream
3626 (either string or file) from TYPE, and makes LOCATION point to where
3627 the input is coming from. */
3629 /* Unconditionally returns end-of-file. */
3636 /* Variable containing the current get and unget functions.
3637 See ./input.h for a clearer description. */
3638 BASH_INPUT bash_input;
3640 /* Set all of the fields in BASH_INPUT to NULL. Free bash_input.name if it
3641 is non-null, avoiding a memory leak. */
3643 initialize_bash_input ()
3645 bash_input.type = st_none;
3646 FREE (bash_input.name);
3647 bash_input.name = (char *)NULL;
3648 bash_input.location.file = (FILE *)NULL;
3649 bash_input.location.string = (char *)NULL;
3650 bash_input.getter = (sh_cget_func_t *)NULL;
3651 bash_input.ungetter = (sh_cunget_func_t *)NULL;
3654 /* Set the contents of the current bash input stream from
3655 GET, UNGET, TYPE, NAME, and LOCATION. */
3657 init_yy_io (get, unget, type, name, location)
3658 sh_cget_func_t *get;
3659 sh_cunget_func_t *unget;
3660 enum stream_type type;
3662 INPUT_STREAM location;
3664 bash_input.type = type;
3665 FREE (bash_input.name);
3666 bash_input.name = name ? savestring (name) : (char *)NULL;
3670 memcpy((char *)&bash_input.location.string, (char *)&location.string, sizeof(location));
3672 bash_input.location = location;
3674 bash_input.getter = get;
3675 bash_input.ungetter = unget;
3681 return (bash_input.name ? bash_input.name : "stdin");
3684 /* Call this to get the next character of input. */
3688 return (*(bash_input.getter)) ();
3691 /* Call this to unget C. That is, to make C the next character
3697 return (*(bash_input.ungetter)) (c);
3700 #if defined (BUFFERED_INPUT)
3701 #ifdef INCLUDE_UNUSED
3703 input_file_descriptor ()
3705 switch (bash_input.type)
3708 return (fileno (bash_input.location.file));
3710 return (bash_input.location.buffered_fd);
3713 return (fileno (stdin));
3717 #endif /* BUFFERED_INPUT */
3719 /* **************************************************************** */
3721 /* Let input be read from readline (). */
3723 /* **************************************************************** */
3725 #if defined (READLINE)
3726 char *current_readline_prompt = (char *)NULL;
3727 char *current_readline_line = (char *)NULL;
3728 int current_readline_line_index = 0;
3733 SigHandler *old_sigint;
3737 if (!current_readline_line)
3739 if (!bash_readline_initialized)
3740 initialize_readline ();
3742 #if defined (JOB_CONTROL)
3744 give_terminal_to (shell_pgrp, 0);
3745 #endif /* JOB_CONTROL */
3747 old_sigint = (SigHandler *)IMPOSSIBLE_TRAP_HANDLER;
3748 if (signal_is_ignored (SIGINT) == 0)
3750 interrupt_immediately++;
3751 old_sigint = (SigHandler *)set_signal_handler (SIGINT, sigint_sighandler);
3753 terminate_immediately = 1;
3755 current_readline_line = readline (current_readline_prompt ?
3756 current_readline_prompt : "");
3758 terminate_immediately = 0;
3759 if (signal_is_ignored (SIGINT) == 0)
3761 interrupt_immediately--;
3762 if (old_sigint != IMPOSSIBLE_TRAP_HANDLER)
3763 set_signal_handler (SIGINT, old_sigint);
3767 /* Reset the prompt to the decoded value of prompt_string_pointer. */
3768 reset_readline_prompt ();
3771 if (current_readline_line == 0)
3774 current_readline_line_index = 0;
3775 line_len = strlen (current_readline_line);
3777 current_readline_line = (char *)xrealloc (current_readline_line, 2 + line_len);
3778 current_readline_line[line_len++] = '\n';
3779 current_readline_line[line_len] = '\0';
3782 if (current_readline_line[current_readline_line_index] == 0)
3784 free (current_readline_line);
3785 current_readline_line = (char *)NULL;
3786 return (yy_readline_get ());
3790 c = current_readline_line[current_readline_line_index++];
3796 yy_readline_unget (c)
3799 if (current_readline_line_index && current_readline_line)
3800 current_readline_line[--current_readline_line_index] = c;
3805 with_input_from_stdin ()
3807 INPUT_STREAM location;
3809 if (bash_input.type != st_stdin && stream_on_stack (st_stdin) == 0)
3811 location.string = current_readline_line;
3812 init_yy_io (yy_readline_get, yy_readline_unget,
3813 st_stdin, "readline stdin", location);
3817 #else /* !READLINE */
3820 with_input_from_stdin ()
3822 with_input_from_stream (stdin, "stdin");
3824 #endif /* !READLINE */
3826 /* **************************************************************** */
3828 /* Let input come from STRING. STRING is zero terminated. */
3830 /* **************************************************************** */
3835 register char *string;
3836 register unsigned char c;
3838 string = bash_input.location.string;
3840 /* If the string doesn't exist, or is empty, EOF found. */
3841 if (string && *string)
3844 bash_input.location.string = string;
3855 *(--bash_input.location.string) = c;
3860 with_input_from_string (string, name)
3864 INPUT_STREAM location;
3866 location.string = string;
3867 init_yy_io (yy_string_get, yy_string_unget, st_string, name, location);
3870 /* Count the number of characters we've consumed from bash_input.location.string
3871 and read into shell_input_line, but have not returned from shell_getc.
3872 That is the true input location. Rewind bash_input.location.string by
3873 that number of characters, so it points to the last character actually
3874 consumed by the parser. */
3876 rewind_input_string ()
3880 /* number of unconsumed characters in the input -- XXX need to take newlines
3881 into account, e.g., $(...\n) */
3882 xchars = shell_input_line_len - shell_input_line_index;
3883 if (bash_input.location.string[-1] == '\n')
3886 /* XXX - how to reflect bash_input.location.string back to string passed to
3887 parse_and_execute or xparse_dolparen? xparse_dolparen needs to know how
3888 far into the string we parsed. parse_and_execute knows where bash_input.
3889 location.string is, and how far from orig_string that is -- that's the
3890 number of characters the command consumed. */
3892 /* bash_input.location.string - xchars should be where we parsed to */
3893 /* need to do more validation on xchars value for sanity -- test cases. */
3894 bash_input.location.string -= xchars;
3897 /* **************************************************************** */
3899 /* Let input come from STREAM. */
3901 /* **************************************************************** */
3903 /* These two functions used to test the value of the HAVE_RESTARTABLE_SYSCALLS
3904 define, and just use getc/ungetc if it was defined, but since bash
3905 installs its signal handlers without the SA_RESTART flag, some signals
3906 (like SIGCHLD, SIGWINCH, etc.) received during a read(2) will not cause
3907 the read to be restarted. We need to restart it ourselves. */
3915 if (bash_input.location.file)
3919 interrupt_immediately++;
3920 terminate_immediately++;
3922 result = getc_with_restart (bash_input.location.file);
3925 interrupt_immediately--;
3926 terminate_immediately--;
3936 return (ungetc_with_restart (c, bash_input.location.file));
3940 with_input_from_stream (stream, name)
3944 INPUT_STREAM location;
3946 location.file = stream;
3947 init_yy_io (yy_stream_get, yy_stream_unget, st_stream, name, location);
3950 typedef struct stream_saver {
3951 struct stream_saver *next;
3952 BASH_INPUT bash_input;
3954 #if defined (BUFFERED_INPUT)
3955 BUFFERED_STREAM *bstream;
3956 #endif /* BUFFERED_INPUT */
3959 /* The globally known line number. */
3960 int line_number = 0;
3962 /* The line number offset set by assigning to LINENO. Not currently used. */
3963 int line_number_base = 0;
3965 #if defined (COND_COMMAND)
3966 static int cond_lineno;
3967 static int cond_token;
3970 STREAM_SAVER *stream_list = (STREAM_SAVER *)NULL;
3973 push_stream (reset_lineno)
3976 STREAM_SAVER *saver = (STREAM_SAVER *)xmalloc (sizeof (STREAM_SAVER));
3978 xbcopy ((char *)&bash_input, (char *)&(saver->bash_input), sizeof (BASH_INPUT));
3980 #if defined (BUFFERED_INPUT)
3981 saver->bstream = (BUFFERED_STREAM *)NULL;
3982 /* If we have a buffered stream, clear out buffers[fd]. */
3983 if (bash_input.type == st_bstream && bash_input.location.buffered_fd >= 0)
3984 saver->bstream = set_buffered_stream (bash_input.location.buffered_fd,
3985 (BUFFERED_STREAM *)NULL);
3986 #endif /* BUFFERED_INPUT */
3988 saver->line = line_number;
3989 bash_input.name = (char *)NULL;
3990 saver->next = stream_list;
3991 stream_list = saver;
4004 STREAM_SAVER *saver = stream_list;
4007 stream_list = stream_list->next;
4009 init_yy_io (saver->bash_input.getter,
4010 saver->bash_input.ungetter,
4011 saver->bash_input.type,
4012 saver->bash_input.name,
4013 saver->bash_input.location);
4015 #if defined (BUFFERED_INPUT)
4016 /* If we have a buffered stream, restore buffers[fd]. */
4017 /* If the input file descriptor was changed while this was on the
4018 save stack, update the buffered fd to the new file descriptor and
4019 re-establish the buffer <-> bash_input fd correspondence. */
4020 if (bash_input.type == st_bstream && bash_input.location.buffered_fd >= 0)
4022 if (bash_input_fd_changed)
4024 bash_input_fd_changed = 0;
4025 if (default_buffered_input >= 0)
4027 bash_input.location.buffered_fd = default_buffered_input;
4028 saver->bstream->b_fd = default_buffered_input;
4029 SET_CLOSE_ON_EXEC (default_buffered_input);
4032 /* XXX could free buffered stream returned as result here. */
4033 set_buffered_stream (bash_input.location.buffered_fd, saver->bstream);
4035 #endif /* BUFFERED_INPUT */
4037 line_number = saver->line;
4039 FREE (saver->bash_input.name);
4044 /* Return 1 if a stream of type TYPE is saved on the stack. */
4046 stream_on_stack (type)
4047 enum stream_type type;
4049 register STREAM_SAVER *s;
4051 for (s = stream_list; s; s = s->next)
4052 if (s->bash_input.type == type)
4057 /* Save the current token state and return it in a malloced array. */
4063 ret = (int *)xmalloc (4 * sizeof (int));
4064 ret[0] = last_read_token;
4065 ret[1] = token_before_that;
4066 ret[2] = two_tokens_ago;
4067 ret[3] = current_token;
4072 restore_token_state (ts)
4077 last_read_token = ts[0];
4078 token_before_that = ts[1];
4079 two_tokens_ago = ts[2];
4080 current_token = ts[3];
4084 * This is used to inhibit alias expansion and reserved word recognition
4085 * inside case statement pattern lists. A `case statement pattern list' is:
4087 * everything between the `in' in a `case word in' and the next ')'
4089 * everything between a `;;' and the next `)' or `esac'
4092 #if defined (ALIAS) || defined (DPAREN_ARITHMETIC)
4094 #define END_OF_ALIAS 0
4097 * Pseudo-global variables used in implementing token-wise alias expansion.
4101 * Pushing and popping strings. This works together with shell_getc to
4102 * implement alias expansion on a per-token basis.
4105 typedef struct string_saver {
4106 struct string_saver *next;
4107 int expand_alias; /* Value to set expand_alias to when string is popped. */
4110 alias_t *expander; /* alias that caused this line to be pushed. */
4112 int saved_line_size, saved_line_index, saved_line_terminator;
4115 STRING_SAVER *pushed_string_list = (STRING_SAVER *)NULL;
4118 * Push the current shell_input_line onto a stack of such lines and make S
4119 * the current input. Used when expanding aliases. EXPAND is used to set
4120 * the value of expand_next_token when the string is popped, so that the
4121 * word after the alias in the original line is handled correctly when the
4122 * alias expands to multiple words. TOKEN is the token that was expanded
4123 * into S; it is saved and used to prevent infinite recursive expansion.
4126 push_string (s, expand, ap)
4131 STRING_SAVER *temp = (STRING_SAVER *)xmalloc (sizeof (STRING_SAVER));
4133 temp->expand_alias = expand;
4134 temp->saved_line = shell_input_line;
4135 temp->saved_line_size = shell_input_line_size;
4136 temp->saved_line_index = shell_input_line_index;
4137 temp->saved_line_terminator = shell_input_line_terminator;
4139 temp->expander = ap;
4141 temp->next = pushed_string_list;
4142 pushed_string_list = temp;
4146 ap->flags |= AL_BEINGEXPANDED;
4149 shell_input_line = s;
4150 shell_input_line_size = strlen (s);
4151 shell_input_line_index = 0;
4152 shell_input_line_terminator = '\0';
4154 parser_state &= ~PST_ALEXPNEXT; /* XXX */
4157 set_line_mbstate ();
4161 * Make the top of the pushed_string stack be the current shell input.
4162 * Only called when there is something on the stack. Called from shell_getc
4163 * when it thinks it has consumed the string generated by an alias expansion
4164 * and needs to return to the original input line.
4171 FREE (shell_input_line);
4172 shell_input_line = pushed_string_list->saved_line;
4173 shell_input_line_index = pushed_string_list->saved_line_index;
4174 shell_input_line_size = pushed_string_list->saved_line_size;
4175 shell_input_line_terminator = pushed_string_list->saved_line_terminator;
4177 if (pushed_string_list->expand_alias)
4178 parser_state |= PST_ALEXPNEXT;
4180 parser_state &= ~PST_ALEXPNEXT;
4182 t = pushed_string_list;
4183 pushed_string_list = pushed_string_list->next;
4187 t->expander->flags &= ~AL_BEINGEXPANDED;
4192 set_line_mbstate ();
4198 register STRING_SAVER *t, *t1;
4200 for (t = pushed_string_list; t; )
4203 FREE (t->saved_line);
4206 t->expander->flags &= ~AL_BEINGEXPANDED;
4211 pushed_string_list = (STRING_SAVER *)NULL;
4214 #endif /* ALIAS || DPAREN_ARITHMETIC */
4217 free_pushed_string_input ()
4219 #if defined (ALIAS) || defined (DPAREN_ARITHMETIC)
4220 free_string_list ();
4224 /* Return a line of text, taken from wherever yylex () reads input.
4225 If there is no more input, then we return NULL. If REMOVE_QUOTED_NEWLINE
4226 is non-zero, we remove unquoted \<newline> pairs. This is used by
4227 read_secondary_line to read here documents. */
4229 read_a_line (remove_quoted_newline)
4230 int remove_quoted_newline;
4232 static char *line_buffer = (char *)NULL;
4233 static int buffer_size = 0;
4234 int indx, c, peekc, pass_next;
4236 #if defined (READLINE)
4237 if (no_line_editing && SHOULD_PROMPT ())
4239 if (SHOULD_PROMPT ())
4243 pass_next = indx = 0;
4246 /* Allow immediate exit if interrupted during input. */
4251 /* Ignore null bytes in input. */
4255 internal_warning ("read_a_line: ignored null byte in input");
4260 /* If there is no more input, then we return NULL. */
4263 if (interactive && bash_input.type == st_stream)
4266 return ((char *)NULL);
4270 /* `+2' in case the final character in the buffer is a newline. */
4271 RESIZE_MALLOCED_BUFFER (line_buffer, indx, 2, buffer_size, 128);
4273 /* IF REMOVE_QUOTED_NEWLINES is non-zero, we are reading a
4274 here document with an unquoted delimiter. In this case,
4275 the line will be expanded as if it were in double quotes.
4276 We allow a backslash to escape the next character, but we
4277 need to treat the backslash specially only if a backslash
4278 quoting a backslash-newline pair appears in the line. */
4281 line_buffer[indx++] = c;
4284 else if (c == '\\' && remove_quoted_newline)
4291 continue; /* Make the unquoted \<newline> pair disappear. */
4297 line_buffer[indx++] = c; /* Preserve the backslash. */
4301 line_buffer[indx++] = c;
4305 line_buffer[indx] = '\0';
4306 return (line_buffer);
4311 /* Return a line as in read_a_line (), but insure that the prompt is
4312 the secondary prompt. This is used to read the lines of a here
4313 document. REMOVE_QUOTED_NEWLINE is non-zero if we should remove
4314 newlines quoted with backslashes while reading the line. It is
4315 non-zero unless the delimiter of the here document was quoted. */
4317 read_secondary_line (remove_quoted_newline)
4318 int remove_quoted_newline;
4323 prompt_string_pointer = &ps2_prompt;
4324 if (SHOULD_PROMPT())
4326 ret = read_a_line (remove_quoted_newline);
4327 #if defined (HISTORY)
4328 if (ret && remember_on_history && (parser_state & PST_HEREDOC))
4330 /* To make adding the the here-document body right, we need to rely
4331 on history_delimiting_chars() returning \n for the first line of
4332 the here-document body and the null string for the second and
4333 subsequent lines, so we avoid double newlines.
4334 current_command_line_count == 2 for the first line of the body. */
4336 current_command_line_count++;
4337 maybe_add_history (ret);
4339 #endif /* HISTORY */
4343 /* **************************************************************** */
4347 /* **************************************************************** */
4349 /* Reserved words. These are only recognized as the first word of a
4351 STRING_INT_ALIST word_token_alist[] = {
4360 #if defined (SELECT_COMMAND)
4361 { "select", SELECT },
4368 { "function", FUNCTION },
4369 #if defined (COMMAND_TIMING)
4375 #if defined (COND_COMMAND)
4376 { "[[", COND_START },
4379 #if defined (COPROCESS_SUPPORT)
4380 { "coproc", COPROC },
4385 /* other tokens that can be returned by read_token() */
4386 STRING_INT_ALIST other_token_alist[] = {
4387 /* Multiple-character tokens with special values */
4392 { ">>", GREATER_GREATER },
4393 { "<<", LESS_LESS },
4395 { ">&", GREATER_AND },
4396 { ";;", SEMI_SEMI },
4398 { ";;&", SEMI_SEMI_AND },
4399 { "<<-", LESS_LESS_MINUS },
4400 { "<<<", LESS_LESS_LESS },
4401 { "&>", AND_GREATER },
4402 { "&>>", AND_GREATER_GREATER },
4403 { "<>", LESS_GREATER },
4404 { ">|", GREATER_BAR },
4406 { "EOF", yacc_EOF },
4407 /* Tokens whose value is the character itself */
4418 { "newline", '\n' },
4422 /* others not listed here:
4423 WORD look at yylval.word
4424 ASSIGNMENT_WORD look at yylval.word
4425 NUMBER look at yylval.number
4426 ARITH_CMD look at yylval.word_list
4427 ARITH_FOR_EXPRS look at yylval.word_list
4428 COND_CMD look at yylval.command
4431 /* These are used by read_token_word, but appear up here so that shell_getc
4432 can use them to decide when to add otherwise blank lines to the history. */
4434 /* The primary delimiter stack. */
4435 struct dstack dstack = { (char *)NULL, 0, 0 };
4437 /* A temporary delimiter stack to be used when decoding prompt strings.
4438 This is needed because command substitutions in prompt strings (e.g., PS2)
4439 can screw up the parser's quoting state. */
4440 static struct dstack temp_dstack = { (char *)NULL, 0, 0 };
4442 /* Macro for accessing the top delimiter on the stack. Returns the
4443 delimiter or zero if none. */
4444 #define current_delimiter(ds) \
4445 (ds.delimiter_depth ? ds.delimiters[ds.delimiter_depth - 1] : 0)
4447 #define push_delimiter(ds, character) \
4450 if (ds.delimiter_depth + 2 > ds.delimiter_space) \
4451 ds.delimiters = (char *)xrealloc \
4452 (ds.delimiters, (ds.delimiter_space += 10) * sizeof (char)); \
4453 ds.delimiters[ds.delimiter_depth] = character; \
4454 ds.delimiter_depth++; \
4458 #define pop_delimiter(ds) ds.delimiter_depth--
4460 /* Return the next shell input character. This always reads characters
4461 from shell_input_line; when that line is exhausted, it is time to
4462 read the next line. This is called by read_token when the shell is
4463 processing normal command input. */
4465 /* This implements one-character lookahead/lookbehind across physical input
4466 lines, to avoid something being lost because it's pushed back with
4467 shell_ungetc when we're at the start of a line. */
4468 static int eol_ungetc_lookahead = 0;
4471 shell_getc (remove_quoted_newline)
4472 int remove_quoted_newline;
4480 if (sigwinch_received)
4482 sigwinch_received = 0;
4483 get_new_window_size (0, (int *)0, (int *)0);
4486 if (eol_ungetc_lookahead)
4488 c = eol_ungetc_lookahead;
4489 eol_ungetc_lookahead = 0;
4493 #if defined (ALIAS) || defined (DPAREN_ARITHMETIC)
4494 /* If shell_input_line[shell_input_line_index] == 0, but there is
4495 something on the pushed list of strings, then we don't want to go
4496 off and get another line. We let the code down below handle it. */
4498 if (!shell_input_line || ((!shell_input_line[shell_input_line_index]) &&
4499 (pushed_string_list == (STRING_SAVER *)NULL)))
4500 #else /* !ALIAS && !DPAREN_ARITHMETIC */
4501 if (!shell_input_line || !shell_input_line[shell_input_line_index])
4502 #endif /* !ALIAS && !DPAREN_ARITHMETIC */
4508 /* Allow immediate exit if interrupted during input. */
4512 shell_input_line_terminator = 0;
4514 /* If the shell is interatctive, but not currently printing a prompt
4515 (interactive_shell && interactive == 0), we don't want to print
4516 notifies or cleanup the jobs -- we want to defer it until we do
4517 print the next prompt. */
4518 if (interactive_shell == 0 || SHOULD_PROMPT())
4520 #if defined (JOB_CONTROL)
4521 /* This can cause a problem when reading a command as the result
4522 of a trap, when the trap is called from flush_child. This call
4523 had better not cause jobs to disappear from the job table in
4524 that case, or we will have big trouble. */
4525 notify_and_cleanup ();
4526 #else /* !JOB_CONTROL */
4527 cleanup_dead_jobs ();
4528 #endif /* !JOB_CONTROL */
4531 #if defined (READLINE)
4532 if (no_line_editing && SHOULD_PROMPT())
4534 if (SHOULD_PROMPT())
4538 if (bash_input.type == st_stream)
4545 /* Allow immediate exit if interrupted during input. */
4551 internal_warning ("shell_getc: ignored null byte in input");
4556 RESIZE_MALLOCED_BUFFER (shell_input_line, i, 2, shell_input_line_size, 256);
4560 if (bash_input.type == st_stream)
4564 shell_input_line_terminator = EOF;
4566 shell_input_line[i] = '\0';
4570 shell_input_line[i++] = c;
4574 shell_input_line[--i] = '\0';
4575 current_command_line_count++;
4580 shell_input_line_index = 0;
4581 shell_input_line_len = i; /* == strlen (shell_input_line) */
4583 set_line_mbstate ();
4585 #if defined (HISTORY)
4586 if (remember_on_history && shell_input_line && shell_input_line[0])
4589 # if defined (BANG_HISTORY)
4592 /* If the current delimiter is a single quote, we should not be
4593 performing history expansion, even if we're on a different
4594 line from the original single quote. */
4595 old_hist = history_expansion_inhibited;
4596 if (current_delimiter (dstack) == '\'')
4597 history_expansion_inhibited = 1;
4599 expansions = pre_process_line (shell_input_line, 1, 1);
4600 # if defined (BANG_HISTORY)
4601 history_expansion_inhibited = old_hist;
4603 if (expansions != shell_input_line)
4605 free (shell_input_line);
4606 shell_input_line = expansions;
4607 shell_input_line_len = shell_input_line ?
4608 strlen (shell_input_line) : 0;
4609 if (shell_input_line_len == 0)
4610 current_command_line_count--;
4612 /* We have to force the xrealloc below because we don't know
4613 the true allocated size of shell_input_line anymore. */
4614 shell_input_line_size = shell_input_line_len;
4616 set_line_mbstate ();
4619 /* Try to do something intelligent with blank lines encountered while
4620 entering multi-line commands. XXX - this is grotesque */
4621 else if (remember_on_history && shell_input_line &&
4622 shell_input_line[0] == '\0' &&
4623 current_command_line_count > 1)
4625 if (current_delimiter (dstack))
4626 /* We know shell_input_line[0] == 0 and we're reading some sort of
4627 quoted string. This means we've got a line consisting of only
4628 a newline in a quoted string. We want to make sure this line
4629 gets added to the history. */
4630 maybe_add_history (shell_input_line);
4634 hdcs = history_delimiting_chars (shell_input_line);
4635 if (hdcs && hdcs[0] == ';')
4636 maybe_add_history (shell_input_line);
4640 #endif /* HISTORY */
4642 if (shell_input_line)
4644 /* Lines that signify the end of the shell's input should not be
4646 if (echo_input_at_read && (shell_input_line[0] ||
4647 shell_input_line_terminator != EOF))
4648 fprintf (stderr, "%s\n", shell_input_line);
4652 shell_input_line_size = 0;
4653 prompt_string_pointer = ¤t_prompt_string;
4654 if (SHOULD_PROMPT ())
4659 /* Add the newline to the end of this string, iff the string does
4660 not already end in an EOF character. */
4661 if (shell_input_line_terminator != EOF)
4663 if (shell_input_line_len + 3 > shell_input_line_size)
4664 shell_input_line = (char *)xrealloc (shell_input_line,
4665 1 + (shell_input_line_size += 2));
4667 shell_input_line[shell_input_line_len] = '\n';
4668 shell_input_line[shell_input_line_len + 1] = '\0';
4670 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 == 0 && (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 /* What do we do here if we're expanding an alias whose definition
4702 includes an escaped newline? If that's the last character in the
4703 alias expansion, we just pop the pushed string list (recall that
4704 we inhibit the appending of a space in mk_alexpansion() if newline
4705 is the last character). If it's not the last character, we need
4706 to consume the quoted newline and move to the next character in
4709 if (expanding_alias () && shell_input_line[shell_input_line_index+1] == '\0')
4714 else if (expanding_alias () && shell_input_line[shell_input_line_index+1] != '\0')
4716 shell_input_line_index++; /* skip newline */
4717 goto next_alias_char; /* and get next character */
4724 if (uc == 0 && shell_input_line_terminator == EOF)
4725 return ((shell_input_line_index != 0) ? '\n' : EOF);
4730 /* Put C back into the input for the shell. This might need changes for
4731 HANDLE_MULTIBYTE around EOLs. Since we (currently) never push back a
4732 character different than we read, shell_input_line_property doesn't need
4733 to change when manipulating shell_input_line. The define for
4734 last_shell_getc_is_singlebyte should take care of it, though. */
4739 if (shell_input_line && shell_input_line_index)
4740 shell_input_line[--shell_input_line_index] = c;
4742 eol_ungetc_lookahead = c;
4745 #ifdef INCLUDE_UNUSED
4746 /* Back the input pointer up by one, effectively `ungetting' a character. */
4750 if (shell_input_line && shell_input_line_index)
4751 shell_input_line_index--;
4755 /* Discard input until CHARACTER is seen, then push that character back
4756 onto the input stream. */
4758 discard_until (character)
4763 while ((c = shell_getc (0)) != EOF && c != character)
4771 execute_variable_command (command, vname)
4772 char *command, *vname;
4775 sh_parser_state_t ps;
4777 save_parser_state (&ps);
4778 last_lastarg = get_string_value ("_");
4780 last_lastarg = savestring (last_lastarg);
4782 parse_and_execute (savestring (command), vname, SEVAL_NONINT|SEVAL_NOHIST);
4784 restore_parser_state (&ps);
4785 bind_variable ("_", last_lastarg, 0);
4786 FREE (last_lastarg);
4788 if (token_to_read == '\n') /* reset_parser was called */
4792 /* Place to remember the token. We try to keep the buffer
4793 at a reasonable size, but it can grow. */
4794 static char *token = (char *)NULL;
4796 /* Current size of the token buffer. */
4797 static int token_buffer_size;
4799 /* Command to read_token () explaining what we want it to do. */
4802 #define prompt_is_ps1 \
4803 (!prompt_string_pointer || prompt_string_pointer == &ps1_prompt)
4805 /* Function for yyparse to call. yylex keeps track of
4806 the last two tokens read, and calls read_token. */
4810 if (interactive && (current_token == 0 || current_token == '\n'))
4812 /* Before we print a prompt, we might have to check mailboxes.
4813 We do this only if it is time to do so. Notice that only here
4814 is the mail alarm reset; nothing takes place in check_mail ()
4815 except the checking of mail. Please don't change this. */
4816 if (prompt_is_ps1 && parse_and_execute_level == 0 && time_to_check_mail ())
4819 reset_mail_timer ();
4822 /* Avoid printing a prompt if we're not going to read anything, e.g.
4823 after resetting the parser with read_token (RESET). */
4824 if (token_to_read == 0 && SHOULD_PROMPT ())
4828 two_tokens_ago = token_before_that;
4829 token_before_that = last_read_token;
4830 last_read_token = current_token;
4831 current_token = read_token (READ);
4833 if ((parser_state & PST_EOFTOKEN) && current_token == shell_eof_token)
4835 current_token = yacc_EOF;
4836 if (bash_input.type == st_string)
4837 rewind_input_string ();
4839 parser_state &= ~PST_EOFTOKEN;
4841 return (current_token);
4844 /* When non-zero, we have read the required tokens
4845 which allow ESAC to be the next one read. */
4846 static int esacs_needed_count;
4849 gather_here_documents ()
4854 while (need_here_doc)
4856 parser_state |= PST_HEREDOC;
4857 make_here_document (redir_stack[r++], line_number);
4858 parser_state &= ~PST_HEREDOC;
4863 /* When non-zero, an open-brace used to create a group is awaiting a close
4865 static int open_brace_count;
4867 #define command_token_position(token) \
4868 (((token) == ASSIGNMENT_WORD) || (parser_state&PST_REDIRLIST) || \
4869 ((token) != SEMI_SEMI && (token) != SEMI_AND && (token) != SEMI_SEMI_AND && reserved_word_acceptable(token)))
4871 #define assignment_acceptable(token) \
4872 (command_token_position(token) && ((parser_state & PST_CASEPAT) == 0))
4874 /* Check to see if TOKEN is a reserved word and return the token
4876 #define CHECK_FOR_RESERVED_WORD(tok) \
4878 if (!dollar_present && !quoted && \
4879 reserved_word_acceptable (last_read_token)) \
4882 for (i = 0; word_token_alist[i].word != (char *)NULL; i++) \
4883 if (STREQ (tok, word_token_alist[i].word)) \
4885 if ((parser_state & PST_CASEPAT) && (word_token_alist[i].token != ESAC)) \
4887 if (word_token_alist[i].token == TIME && time_command_acceptable () == 0) \
4889 if (word_token_alist[i].token == ESAC) \
4890 parser_state &= ~(PST_CASEPAT|PST_CASESTMT); \
4891 else if (word_token_alist[i].token == CASE) \
4892 parser_state |= PST_CASESTMT; \
4893 else if (word_token_alist[i].token == COND_END) \
4894 parser_state &= ~(PST_CONDCMD|PST_CONDEXPR); \
4895 else if (word_token_alist[i].token == COND_START) \
4896 parser_state |= PST_CONDCMD; \
4897 else if (word_token_alist[i].token == '{') \
4898 open_brace_count++; \
4899 else if (word_token_alist[i].token == '}' && open_brace_count) \
4900 open_brace_count--; \
4901 return (word_token_alist[i].token); \
4908 /* OK, we have a token. Let's try to alias expand it, if (and only if)
4911 It is eligible for expansion if EXPAND_ALIASES is set, and
4912 the token is unquoted and the last token read was a command
4913 separator (or expand_next_token is set), and we are currently
4914 processing an alias (pushed_string_list is non-empty) and this
4915 token is not the same as the current or any previously
4918 Special cases that disqualify:
4919 In a pattern list in a case statement (parser_state & PST_CASEPAT). */
4929 r = xmalloc (l + 2);
4931 /* If the last character in the alias is a newline, don't add a trailing
4932 space to the expansion. Works with shell_getc above. */
4933 if (r[l - 1] != ' ' && r[l - 1] != '\n')
4940 alias_expand_token (tokstr)
4946 if (((parser_state & PST_ALEXPNEXT) || command_token_position (last_read_token)) &&
4947 (parser_state & PST_CASEPAT) == 0)
4949 ap = find_alias (tokstr);
4951 /* Currently expanding this token. */
4952 if (ap && (ap->flags & AL_BEINGEXPANDED))
4953 return (NO_EXPANSION);
4955 /* mk_alexpansion puts an extra space on the end of the alias expansion,
4956 so the lookahead by the parser works right. If this gets changed,
4957 make sure the code in shell_getc that deals with reaching the end of
4958 an expanded alias is changed with it. */
4959 expanded = ap ? mk_alexpansion (ap->value) : (char *)NULL;
4963 push_string (expanded, ap->flags & AL_EXPANDNEXT, ap);
4964 return (RE_READ_TOKEN);
4967 /* This is an eligible token that does not have an expansion. */
4968 return (NO_EXPANSION);
4970 return (NO_EXPANSION);
4975 time_command_acceptable ()
4977 #if defined (COMMAND_TIMING)
4980 if (posixly_correct && shell_compatibility_level > 41)
4982 /* Quick check of the rest of the line to find the next token. If it
4983 begins with a `-', Posix says to not return `time' as the token.
4984 This was interp 267. */
4985 i = shell_input_line_index;
4986 while (i < shell_input_line_len && (shell_input_line[i] == ' ' || shell_input_line[i] == '\t'))
4988 if (shell_input_line[i] == '-')
4992 switch (last_read_token)
5005 case BANG: /* ! time pipeline */
5006 case TIME: /* time time pipeline */
5007 case TIMEOPT: /* time -p time pipeline */
5008 case TIMEIGN: /* time -p -- ... */
5015 #endif /* COMMAND_TIMING */
5018 /* Handle special cases of token recognition:
5019 IN is recognized if the last token was WORD and the token
5020 before that was FOR or CASE or SELECT.
5022 DO is recognized if the last token was WORD and the token
5023 before that was FOR or SELECT.
5025 ESAC is recognized if the last token caused `esacs_needed_count'
5028 `{' is recognized if the last token as WORD and the token
5029 before that was FUNCTION, or if we just parsed an arithmetic
5032 `}' is recognized if there is an unclosed `{' present.
5034 `-p' is returned as TIMEOPT if the last read token was TIME.
5035 `--' is returned as TIMEIGN if the last read token was TIMEOPT.
5037 ']]' is returned as COND_END if the parser is currently parsing
5038 a conditional expression ((parser_state & PST_CONDEXPR) != 0)
5040 `time' is returned as TIME if and only if it is immediately
5041 preceded by one of `;', `\n', `||', `&&', or `&'.
5045 special_case_tokens (tokstr)
5048 if ((last_read_token == WORD) &&
5049 #if defined (SELECT_COMMAND)
5050 ((token_before_that == FOR) || (token_before_that == CASE) || (token_before_that == SELECT)) &&
5052 ((token_before_that == FOR) || (token_before_that == CASE)) &&
5054 (tokstr[0] == 'i' && tokstr[1] == 'n' && tokstr[2] == 0))
5056 if (token_before_that == CASE)
5058 parser_state |= PST_CASEPAT;
5059 esacs_needed_count++;
5064 if (last_read_token == WORD &&
5065 #if defined (SELECT_COMMAND)
5066 (token_before_that == FOR || token_before_that == SELECT) &&
5068 (token_before_that == FOR) &&
5070 (tokstr[0] == 'd' && tokstr[1] == 'o' && tokstr[2] == '\0'))
5073 /* Ditto for ESAC in the CASE case.
5074 Specifically, this handles "case word in esac", which is a legal
5075 construct, certainly because someone will pass an empty arg to the
5076 case construct, and we don't want it to barf. Of course, we should
5077 insist that the case construct has at least one pattern in it, but
5078 the designers disagree. */
5079 if (esacs_needed_count)
5081 esacs_needed_count--;
5082 if (STREQ (tokstr, "esac"))
5084 parser_state &= ~PST_CASEPAT;
5089 /* The start of a shell function definition. */
5090 if (parser_state & PST_ALLOWOPNBRC)
5092 parser_state &= ~PST_ALLOWOPNBRC;
5093 if (tokstr[0] == '{' && tokstr[1] == '\0') /* } */
5096 function_bstart = line_number;
5097 return ('{'); /* } */
5101 /* We allow a `do' after a for ((...)) without an intervening
5103 if (last_read_token == ARITH_FOR_EXPRS && tokstr[0] == 'd' && tokstr[1] == 'o' && !tokstr[2])
5105 if (last_read_token == ARITH_FOR_EXPRS && tokstr[0] == '{' && tokstr[1] == '\0') /* } */
5108 return ('{'); /* } */
5111 if (open_brace_count && reserved_word_acceptable (last_read_token) && tokstr[0] == '}' && !tokstr[1])
5113 open_brace_count--; /* { */
5117 #if defined (COMMAND_TIMING)
5118 /* Handle -p after `time'. */
5119 if (last_read_token == TIME && tokstr[0] == '-' && tokstr[1] == 'p' && !tokstr[2])
5121 /* Handle -- after `time -p'. */
5122 if (last_read_token == TIMEOPT && tokstr[0] == '-' && tokstr[1] == '-' && !tokstr[2])
5126 #if defined (COND_COMMAND) /* [[ */
5127 if ((parser_state & PST_CONDEXPR) && tokstr[0] == ']' && tokstr[1] == ']' && tokstr[2] == '\0')
5134 /* Called from shell.c when Control-C is typed at top level. Or
5135 by the error rule at top level. */
5139 dstack.delimiter_depth = 0; /* No delimiters found so far. */
5140 open_brace_count = 0;
5142 #if defined (EXTENDED_GLOB)
5143 /* Reset to global value of extended glob */
5144 if (parser_state & PST_EXTPAT)
5145 extended_glob = global_extglob;
5150 #if defined (ALIAS) || defined (DPAREN_ARITHMETIC)
5151 if (pushed_string_list)
5152 free_string_list ();
5153 #endif /* ALIAS || DPAREN_ARITHMETIC */
5155 if (shell_input_line)
5157 free (shell_input_line);
5158 shell_input_line = (char *)NULL;
5159 shell_input_line_size = shell_input_line_index = 0;
5162 FREE (word_desc_to_read);
5163 word_desc_to_read = (WORD_DESC *)NULL;
5165 current_token = '\n'; /* XXX */
5166 last_read_token = '\n';
5167 token_to_read = '\n';
5170 /* Read the next token. Command can be READ (normal operation) or
5171 RESET (to normalize state). */
5173 read_token (command)
5176 int character; /* Current character. */
5177 int peek_char; /* Temporary look-ahead character. */
5178 int result; /* The thing to return. */
5180 if (command == RESET)
5188 result = token_to_read;
5189 if (token_to_read == WORD || token_to_read == ASSIGNMENT_WORD)
5191 yylval.word = word_desc_to_read;
5192 word_desc_to_read = (WORD_DESC *)NULL;
5198 #if defined (COND_COMMAND)
5199 if ((parser_state & (PST_CONDCMD|PST_CONDEXPR)) == PST_CONDCMD)
5201 cond_lineno = line_number;
5202 parser_state |= PST_CONDEXPR;
5203 yylval.command = parse_cond_command ();
5204 if (cond_token != COND_END)
5209 token_to_read = COND_END;
5210 parser_state &= ~(PST_CONDEXPR|PST_CONDCMD);
5216 /* This is a place to jump back to once we have successfully expanded a
5217 token with an alias and pushed the string with push_string () */
5221 /* Read a single word from input. Start by skipping blanks. */
5222 while ((character = shell_getc (1)) != EOF && shellblank (character))
5225 if (character == EOF)
5231 if MBTEST(character == '#' && (!interactive || interactive_comments))
5233 /* A comment. Discard until EOL or EOF, and then return a newline. */
5234 discard_until ('\n');
5236 character = '\n'; /* this will take the next if statement and return. */
5239 if (character == '\n')
5241 /* If we're about to return an unquoted newline, we can go and collect
5242 the text of any pending here document. */
5244 gather_here_documents ();
5247 parser_state &= ~PST_ALEXPNEXT;
5250 parser_state &= ~PST_ASSIGNOK;
5255 if (parser_state & PST_REGEXP)
5258 /* Shell meta-characters. */
5259 if MBTEST(shellmeta (character) && ((parser_state & PST_DBLPAREN) == 0))
5262 /* Turn off alias tokenization iff this character sequence would
5263 not leave us ready to read a command. */
5264 if (character == '<' || character == '>')
5265 parser_state &= ~PST_ALEXPNEXT;
5268 parser_state &= ~PST_ASSIGNOK;
5270 peek_char = shell_getc (1);
5271 if (character == peek_char)
5276 /* If '<' then we could be at "<<" or at "<<-". We have to
5277 look ahead one more character. */
5278 peek_char = shell_getc (1);
5279 if MBTEST(peek_char == '-')
5280 return (LESS_LESS_MINUS);
5281 else if MBTEST(peek_char == '<')
5282 return (LESS_LESS_LESS);
5285 shell_ungetc (peek_char);
5290 return (GREATER_GREATER);
5293 parser_state |= PST_CASEPAT;
5295 parser_state &= ~PST_ALEXPNEXT;
5298 peek_char = shell_getc (1);
5299 if MBTEST(peek_char == '&')
5300 return (SEMI_SEMI_AND);
5303 shell_ungetc (peek_char);
5313 #if defined (DPAREN_ARITHMETIC) || defined (ARITH_FOR_COMMAND)
5315 result = parse_dparen (character);
5323 else if MBTEST(character == '<' && peek_char == '&')
5325 else if MBTEST(character == '>' && peek_char == '&')
5326 return (GREATER_AND);
5327 else if MBTEST(character == '<' && peek_char == '>')
5328 return (LESS_GREATER);
5329 else if MBTEST(character == '>' && peek_char == '|')
5330 return (GREATER_BAR);
5331 else if MBTEST(character == '&' && peek_char == '>')
5333 peek_char = shell_getc (1);
5334 if MBTEST(peek_char == '>')
5335 return (AND_GREATER_GREATER);
5338 shell_ungetc (peek_char);
5339 return (AND_GREATER);
5342 else if MBTEST(character == '|' && peek_char == '&')
5344 else if MBTEST(character == ';' && peek_char == '&')
5346 parser_state |= PST_CASEPAT;
5348 parser_state &= ~PST_ALEXPNEXT;
5353 shell_ungetc (peek_char);
5355 /* If we look like we are reading the start of a function
5356 definition, then let the reader know about it so that
5357 we will do the right thing with `{'. */
5358 if MBTEST(character == ')' && last_read_token == '(' && token_before_that == WORD)
5360 parser_state |= PST_ALLOWOPNBRC;
5362 parser_state &= ~PST_ALEXPNEXT;
5364 function_dstart = line_number;
5367 /* case pattern lists may be preceded by an optional left paren. If
5368 we're not trying to parse a case pattern list, the left paren
5369 indicates a subshell. */
5370 if MBTEST(character == '(' && (parser_state & PST_CASEPAT) == 0) /* ) */
5371 parser_state |= PST_SUBSHELL;
5373 else if MBTEST((parser_state & PST_CASEPAT) && character == ')')
5374 parser_state &= ~PST_CASEPAT;
5376 else if MBTEST((parser_state & PST_SUBSHELL) && character == ')')
5377 parser_state &= ~PST_SUBSHELL;
5379 #if defined (PROCESS_SUBSTITUTION)
5380 /* Check for the constructs which introduce process substitution.
5381 Shells running in `posix mode' don't do process substitution. */
5382 if MBTEST(posixly_correct || ((character != '>' && character != '<') || peek_char != '(')) /*)*/
5383 #endif /* PROCESS_SUBSTITUTION */
5387 /* Hack <&- (close stdin) case. Also <&N- (dup and close). */
5388 if MBTEST(character == '-' && (last_read_token == LESS_AND || last_read_token == GREATER_AND))
5392 /* Okay, if we got this far, we have to read a word. Read one,
5393 and then check it against the known ones. */
5394 result = read_token_word (character);
5396 if (result == RE_READ_TOKEN)
5403 * Match a $(...) or other grouping construct. This has to handle embedded
5404 * quoted strings ('', ``, "") and nested constructs. It also must handle
5405 * reprompting the user, if necessary, after reading a newline, and returning
5406 * correct error values if it reads EOF.
5408 #define P_FIRSTCLOSE 0x0001
5409 #define P_ALLOWESC 0x0002
5410 #define P_DQUOTE 0x0004
5411 #define P_COMMAND 0x0008 /* parsing a command, so look for comments */
5412 #define P_BACKQUOTE 0x0010 /* parsing a backquoted command substitution */
5413 #define P_ARRAYSUB 0x0020 /* parsing a [...] array subscript for assignment */
5414 #define P_DOLBRACE 0x0040 /* parsing a ${...} construct */
5416 /* Lexical state while parsing a grouping construct or $(...). */
5417 #define LEX_WASDOL 0x001
5418 #define LEX_CKCOMMENT 0x002
5419 #define LEX_INCOMMENT 0x004
5420 #define LEX_PASSNEXT 0x008
5421 #define LEX_RESWDOK 0x010
5422 #define LEX_CKCASE 0x020
5423 #define LEX_INCASE 0x040
5424 #define LEX_INHEREDOC 0x080
5425 #define LEX_HEREDELIM 0x100 /* reading here-doc delimiter */
5426 #define LEX_STRIPDOC 0x200 /* <<- strip tabs from here doc delim */
5427 #define LEX_INWORD 0x400
5429 #define COMSUB_META(ch) ((ch) == ';' || (ch) == '&' || (ch) == '|')
5431 #define CHECK_NESTRET_ERROR() \
5433 if (nestret == &matched_pair_error) \
5436 return &matched_pair_error; \
5440 #define APPEND_NESTRET() \
5444 RESIZE_MALLOCED_BUFFER (ret, retind, nestlen, retsize, 64); \
5445 strcpy (ret + retind, nestret); \
5446 retind += nestlen; \
5450 static char matched_pair_error;
5453 parse_matched_pair (qc, open, close, lenp, flags)
5454 int qc; /* `"' if this construct is within double quotes */
5458 int count, ch, tflags;
5459 int nestlen, ttranslen, start_lineno;
5460 char *ret, *nestret, *ttrans;
5461 int retind, retsize, rflags;
5464 dolbrace_state = (flags & P_DOLBRACE) ? DOLBRACE_PARAM : 0;
5466 /*itrace("parse_matched_pair[%d]: open = %c close = %c flags = %d", line_number, open, close, flags);*/
5470 if ((flags & P_COMMAND) && qc != '`' && qc != '\'' && qc != '"' && (flags & P_DQUOTE) == 0)
5471 tflags |= LEX_CKCOMMENT;
5473 /* RFLAGS is the set of flags we want to pass to recursive calls. */
5474 rflags = (qc == '"') ? P_DQUOTE : (flags & P_DQUOTE);
5476 ret = (char *)xmalloc (retsize = 64);
5479 start_lineno = line_number;
5482 ch = shell_getc (qc != '\'' && (tflags & (LEX_PASSNEXT)) == 0);
5487 parser_error (start_lineno, _("unexpected EOF while looking for matching `%c'"), close);
5488 EOF_Reached = 1; /* XXX */
5489 return (&matched_pair_error);
5492 /* Possible reprompting. */
5493 if (ch == '\n' && SHOULD_PROMPT ())
5496 /* Don't bother counting parens or doing anything else if in a comment
5497 or part of a case statement */
5498 if (tflags & LEX_INCOMMENT)
5500 /* Add this character. */
5501 RESIZE_MALLOCED_BUFFER (ret, retind, 1, retsize, 64);
5505 tflags &= ~LEX_INCOMMENT;
5510 /* Not exactly right yet, should handle shell metacharacters, too. If
5511 any changes are made to this test, make analogous changes to subst.c:
5512 extract_delimited_string(). */
5513 else if MBTEST((tflags & LEX_CKCOMMENT) && (tflags & LEX_INCOMMENT) == 0 && ch == '#' && (retind == 0 || ret[retind-1] == '\n' || shellblank (ret[retind - 1])))
5514 tflags |= LEX_INCOMMENT;
5516 if (tflags & LEX_PASSNEXT) /* last char was backslash */
5518 tflags &= ~LEX_PASSNEXT;
5519 if (qc != '\'' && ch == '\n') /* double-quoted \<newline> disappears. */
5522 retind--; /* swallow previously-added backslash */
5526 RESIZE_MALLOCED_BUFFER (ret, retind, 2, retsize, 64);
5527 if MBTEST(ch == CTLESC || ch == CTLNUL)
5528 ret[retind++] = CTLESC;
5532 /* If we're reparsing the input (e.g., from parse_string_to_word_list),
5533 we've already prepended CTLESC to single-quoted results of $'...'.
5534 We may want to do this for other CTLESC-quoted characters in
5536 else if MBTEST((parser_state & PST_REPARSE) && open == '\'' && (ch == CTLESC || ch == CTLNUL))
5538 RESIZE_MALLOCED_BUFFER (ret, retind, 1, retsize, 64);
5542 else if MBTEST(ch == CTLESC || ch == CTLNUL) /* special shell escapes */
5544 RESIZE_MALLOCED_BUFFER (ret, retind, 2, retsize, 64);
5545 ret[retind++] = CTLESC;
5549 else if MBTEST(ch == close) /* ending delimiter */
5551 /* handle nested ${...} specially. */
5552 else if MBTEST(open != close && (tflags & LEX_WASDOL) && open == '{' && ch == open) /* } */
5554 else if MBTEST(((flags & P_FIRSTCLOSE) == 0) && ch == open) /* nested begin */
5557 /* Add this character. */
5558 RESIZE_MALLOCED_BUFFER (ret, retind, 1, retsize, 64);
5561 /* If we just read the ending character, don't bother continuing. */
5565 if (open == '\'') /* '' inside grouping construct */
5567 if MBTEST((flags & P_ALLOWESC) && ch == '\\')
5568 tflags |= LEX_PASSNEXT;
5572 if MBTEST(ch == '\\') /* backslashes */
5573 tflags |= LEX_PASSNEXT;
5575 /* Based on which dolstate is currently in (param, op, or word),
5576 decide what the op is. We're really only concerned if it's % or
5577 #, so we can turn on a flag that says whether or not we should
5578 treat single quotes as special when inside a double-quoted
5579 ${...}. This logic must agree with subst.c:extract_dollar_brace_string
5580 since they share the same defines. */
5581 if (flags & P_DOLBRACE)
5583 /* ${param%[%]word} */
5584 if MBTEST(dolbrace_state == DOLBRACE_PARAM && ch == '%' && retind > 1)
5585 dolbrace_state = DOLBRACE_QUOTE;
5586 /* ${param#[#]word} */
5587 else if MBTEST(dolbrace_state == DOLBRACE_PARAM && ch == '#' && retind > 1)
5588 dolbrace_state = DOLBRACE_QUOTE;
5589 /* ${param/[/]pat/rep} */
5590 else if MBTEST(dolbrace_state == DOLBRACE_PARAM && ch == '/' && retind > 1)
5591 dolbrace_state = DOLBRACE_QUOTE;
5592 /* ${param^[^]pat} */
5593 else if MBTEST(dolbrace_state == DOLBRACE_PARAM && ch == '^' && retind > 1)
5594 dolbrace_state = DOLBRACE_QUOTE;
5595 /* ${param,[,]pat} */
5596 else if MBTEST(dolbrace_state == DOLBRACE_PARAM && ch == ',' && retind > 1)
5597 dolbrace_state = DOLBRACE_QUOTE;
5598 else if MBTEST(dolbrace_state == DOLBRACE_PARAM && strchr ("#%^,~:-=?+/", ch) != 0)
5599 dolbrace_state = DOLBRACE_OP;
5600 else if MBTEST(dolbrace_state == DOLBRACE_OP && strchr ("#%^,~:-=?+/", ch) == 0)
5601 dolbrace_state = DOLBRACE_WORD;
5604 /* The big hammer. Single quotes aren't special in double quotes. The
5605 problem is that Posix used to say the single quotes are semi-special:
5606 within a double-quoted ${...} construct "an even number of
5607 unescaped double-quotes or single-quotes, if any, shall occur." */
5608 /* This was changed in Austin Group Interp 221 */
5609 if MBTEST(posixly_correct && shell_compatibility_level > 41 && dolbrace_state != DOLBRACE_QUOTE && (flags & P_DQUOTE) && (flags & P_DOLBRACE) && ch == '\'')
5612 /* Could also check open == '`' if we want to parse grouping constructs
5613 inside old-style command substitution. */
5614 if (open != close) /* a grouping construct */
5616 if MBTEST(shellquote (ch))
5618 /* '', ``, or "" inside $(...) or other grouping construct. */
5619 push_delimiter (dstack, ch);
5620 if MBTEST((tflags & LEX_WASDOL) && ch == '\'') /* $'...' inside group */
5621 nestret = parse_matched_pair (ch, ch, ch, &nestlen, P_ALLOWESC|rflags);
5623 nestret = parse_matched_pair (ch, ch, ch, &nestlen, rflags);
5624 pop_delimiter (dstack);
5625 CHECK_NESTRET_ERROR ();
5627 if MBTEST((tflags & LEX_WASDOL) && ch == '\'' && (extended_quote || (rflags & P_DQUOTE) == 0))
5629 /* Translate $'...' here. */
5630 ttrans = ansiexpand (nestret, 0, nestlen - 1, &ttranslen);
5633 if ((rflags & P_DQUOTE) == 0)
5635 nestret = sh_single_quote (ttrans);
5637 nestlen = strlen (nestret);
5642 nestlen = ttranslen;
5644 retind -= 2; /* back up before the $' */
5646 else if MBTEST((tflags & LEX_WASDOL) && ch == '"' && (extended_quote || (rflags & P_DQUOTE) == 0))
5648 /* Locale expand $"..." here. */
5649 ttrans = localeexpand (nestret, 0, nestlen - 1, start_lineno, &ttranslen);
5652 nestret = sh_mkdoublequoted (ttrans, ttranslen, 0);
5654 nestlen = ttranslen + 2;
5655 retind -= 2; /* back up before the $" */
5661 else if ((flags & P_ARRAYSUB) && (tflags & LEX_WASDOL) && (ch == '(' || ch == '{' || ch == '[')) /* ) } ] */
5662 goto parse_dollar_word;
5664 /* Parse an old-style command substitution within double quotes as a
5666 /* XXX - sh and ksh93 don't do this - XXX */
5667 else if MBTEST(open == '"' && ch == '`')
5669 nestret = parse_matched_pair (0, '`', '`', &nestlen, rflags);
5671 CHECK_NESTRET_ERROR ();
5676 else if MBTEST(open != '`' && (tflags & LEX_WASDOL) && (ch == '(' || ch == '{' || ch == '[')) /* ) } ] */
5677 /* check for $(), $[], or ${} inside quoted string. */
5680 if (open == ch) /* undo previous increment */
5682 if (ch == '(') /* ) */
5683 nestret = parse_comsub (0, '(', ')', &nestlen, (rflags|P_COMMAND) & ~P_DQUOTE);
5684 else if (ch == '{') /* } */
5685 nestret = parse_matched_pair (0, '{', '}', &nestlen, P_FIRSTCLOSE|P_DOLBRACE|rflags);
5686 else if (ch == '[') /* ] */
5687 nestret = parse_matched_pair (0, '[', ']', &nestlen, rflags);
5689 CHECK_NESTRET_ERROR ();
5694 if MBTEST(ch == '$')
5695 tflags |= LEX_WASDOL;
5697 tflags &= ~LEX_WASDOL;
5703 /*itrace("parse_matched_pair[%d]: returning %s", line_number, ret);*/
5707 /* Parse a $(...) command substitution. This is messier than I'd like, and
5708 reproduces a lot more of the token-reading code than I'd like. */
5710 parse_comsub (qc, open, close, lenp, flags)
5711 int qc; /* `"' if this construct is within double quotes */
5715 int count, ch, peekc, tflags, lex_rwlen, lex_wlen, lex_firstind;
5716 int nestlen, ttranslen, start_lineno;
5717 char *ret, *nestret, *ttrans, *heredelim;
5718 int retind, retsize, rflags, hdlen;
5720 /* Posix interp 217 says arithmetic expressions have precedence, so
5721 assume $(( introduces arithmetic expansion and parse accordingly. */
5722 peekc = shell_getc (0);
5723 shell_ungetc (peekc);
5725 return (parse_matched_pair (qc, open, close, lenp, 0));
5727 /*itrace("parse_comsub: qc = `%c' open = %c close = %c", qc, open, close);*/
5729 tflags = LEX_RESWDOK;
5731 if ((flags & P_COMMAND) && qc != '\'' && qc != '"' && (flags & P_DQUOTE) == 0)
5732 tflags |= LEX_CKCASE;
5733 if ((tflags & LEX_CKCASE) && (interactive == 0 || interactive_comments))
5734 tflags |= LEX_CKCOMMENT;
5736 /* RFLAGS is the set of flags we want to pass to recursive calls. */
5737 rflags = (flags & P_DQUOTE);
5739 ret = (char *)xmalloc (retsize = 64);
5742 start_lineno = line_number;
5743 lex_rwlen = lex_wlen = 0;
5751 ch = shell_getc (qc != '\'' && (tflags & (LEX_INCOMMENT|LEX_PASSNEXT)) == 0);
5758 parser_error (start_lineno, _("unexpected EOF while looking for matching `%c'"), close);
5759 EOF_Reached = 1; /* XXX */
5760 return (&matched_pair_error);
5763 /* If we hit the end of a line and are reading the contents of a here
5764 document, and it's not the same line that the document starts on,
5765 check for this line being the here doc delimiter. Otherwise, if
5766 we're in a here document, mark the next character as the beginning
5770 if ((tflags & LEX_HEREDELIM) && heredelim)
5772 tflags &= ~LEX_HEREDELIM;
5773 tflags |= LEX_INHEREDOC;
5774 lex_firstind = retind + 1;
5776 else if (tflags & LEX_INHEREDOC)
5779 tind = lex_firstind;
5780 while ((tflags & LEX_STRIPDOC) && ret[tind] == '\t')
5782 if (STREQN (ret + tind, heredelim, hdlen))
5784 tflags &= ~(LEX_STRIPDOC|LEX_INHEREDOC);
5785 /*itrace("parse_comsub:%d: found here doc end `%s'", line_number, ret + tind);*/
5791 lex_firstind = retind + 1;
5795 /* Possible reprompting. */
5796 if (ch == '\n' && SHOULD_PROMPT ())
5799 /* XXX -- possibly allow here doc to be delimited by ending right
5801 if ((tflags & LEX_INHEREDOC) && ch == close && count == 1)
5804 /*itrace("parse_comsub: in here doc, ch == close, retind - firstind = %d hdlen = %d retind = %d", retind-lex_firstind, hdlen, retind);*/
5805 tind = lex_firstind;
5806 while ((tflags & LEX_STRIPDOC) && ret[tind] == '\t')
5808 if (retind-tind == hdlen && STREQN (ret + tind, heredelim, hdlen))
5810 tflags &= ~(LEX_STRIPDOC|LEX_INHEREDOC);
5811 /*itrace("parse_comsub:%d: found here doc end `%s'", line_number, ret + tind);*/
5818 /* Don't bother counting parens or doing anything else if in a comment */
5819 if (tflags & (LEX_INCOMMENT|LEX_INHEREDOC))
5821 /* Add this character. */
5822 RESIZE_MALLOCED_BUFFER (ret, retind, 1, retsize, 64);
5825 if ((tflags & LEX_INCOMMENT) && ch == '\n')
5827 /*itrace("parse_comsub:%d: lex_incomment -> 0 ch = `%c'", line_number, ch);*/
5828 tflags &= ~LEX_INCOMMENT;
5834 if (tflags & LEX_PASSNEXT) /* last char was backslash */
5836 /*itrace("parse_comsub:%d: lex_passnext -> 0 ch = `%c' (%d)", line_number, ch, __LINE__);*/
5837 tflags &= ~LEX_PASSNEXT;
5838 if (qc != '\'' && ch == '\n') /* double-quoted \<newline> disappears. */
5841 retind--; /* swallow previously-added backslash */
5845 RESIZE_MALLOCED_BUFFER (ret, retind, 2, retsize, 64);
5846 if MBTEST(ch == CTLESC || ch == CTLNUL)
5847 ret[retind++] = CTLESC;
5852 /* If this is a shell break character, we are not in a word. If not,
5853 we either start or continue a word. */
5854 if MBTEST(shellbreak (ch))
5856 tflags &= ~LEX_INWORD;
5857 /*itrace("parse_comsub:%d: lex_inword -> 0 ch = `%c' (%d)", line_number, ch, __LINE__);*/
5861 if (tflags & LEX_INWORD)
5864 /*itrace("parse_comsub:%d: lex_inword == 1 ch = `%c' lex_wlen = %d (%d)", line_number, ch, lex_wlen, __LINE__);*/
5868 /*itrace("parse_comsub:%d: lex_inword -> 1 ch = `%c' (%d)", line_number, ch, __LINE__);*/
5869 tflags |= LEX_INWORD;
5874 /* Skip whitespace */
5875 if MBTEST(shellblank (ch) && (tflags & LEX_HEREDELIM) == 0 && lex_rwlen == 0)
5877 /* Add this character. */
5878 RESIZE_MALLOCED_BUFFER (ret, retind, 1, retsize, 64);
5883 /* Either we are looking for the start of the here-doc delimiter
5884 (lex_firstind == -1) or we are reading one (lex_firstind >= 0).
5885 If this character is a shell break character and we are reading
5886 the delimiter, save it and note that we are now reading a here
5887 document. If we've found the start of the delimiter, note it by
5888 setting lex_firstind. Backslashes can quote shell metacharacters
5889 in here-doc delimiters. */
5890 if (tflags & LEX_HEREDELIM)
5892 if (lex_firstind == -1 && shellbreak (ch) == 0)
5893 lex_firstind = retind;
5895 else if (heredelim && (tflags & LEX_PASSNEXT) == 0 && ch == '\n')
5897 tflags |= LEX_INHEREDOC;
5898 tflags &= ~LEX_HEREDELIM;
5899 lex_firstind = retind + 1;
5902 else if (lex_firstind >= 0 && (tflags & LEX_PASSNEXT) == 0 && shellbreak (ch))
5906 nestret = substring (ret, lex_firstind, retind);
5907 heredelim = string_quote_removal (nestret, 0);
5909 hdlen = STRLEN(heredelim);
5910 /*itrace("parse_comsub:%d: found here doc delimiter `%s' (%d)", line_number, heredelim, hdlen);*/
5914 tflags |= LEX_INHEREDOC;
5915 tflags &= ~LEX_HEREDELIM;
5916 lex_firstind = retind + 1;
5923 /* Meta-characters that can introduce a reserved word. Not perfect yet. */
5924 if MBTEST((tflags & LEX_RESWDOK) == 0 && (tflags & LEX_CKCASE) && (tflags & LEX_INCOMMENT) == 0 && (shellmeta(ch) || ch == '\n'))
5926 /* Add this character. */
5927 RESIZE_MALLOCED_BUFFER (ret, retind, 1, retsize, 64);
5929 peekc = shell_getc (1);
5930 if (ch == peekc && (ch == '&' || ch == '|' || ch == ';')) /* two-character tokens */
5932 RESIZE_MALLOCED_BUFFER (ret, retind, 1, retsize, 64);
5933 ret[retind++] = peekc;
5934 /*itrace("parse_comsub:%d: set lex_reswordok = 1, ch = `%c'", line_number, ch);*/
5935 tflags |= LEX_RESWDOK;
5939 else if (ch == '\n' || COMSUB_META(ch))
5941 shell_ungetc (peekc);
5942 /*itrace("parse_comsub:%d: set lex_reswordok = 1, ch = `%c'", line_number, ch);*/
5943 tflags |= LEX_RESWDOK;
5951 /* `unget' the character we just added and fall through */
5953 shell_ungetc (peekc);
5957 /* If we can read a reserved word, try to read one. */
5958 if (tflags & LEX_RESWDOK)
5960 if MBTEST(islower (ch))
5962 /* Add this character. */
5963 RESIZE_MALLOCED_BUFFER (ret, retind, 1, retsize, 64);
5968 else if MBTEST(lex_rwlen == 4 && shellbreak (ch))
5970 if (STREQN (ret + retind - 4, "case", 4))
5972 tflags |= LEX_INCASE;
5973 /*itrace("parse_comsub:%d: found `case', lex_incase -> 1 lex_reswdok -> 0", line_number);*/
5975 else if (STREQN (ret + retind - 4, "esac", 4))
5977 tflags &= ~LEX_INCASE;
5978 /*itrace("parse_comsub:%d: found `esac', lex_incase -> 0 lex_reswdok -> 0", line_number);*/
5980 tflags &= ~LEX_RESWDOK;
5982 else if MBTEST((tflags & LEX_CKCOMMENT) && ch == '#' && (lex_rwlen == 0 || ((tflags & LEX_INWORD) && lex_wlen == 0)))
5983 ; /* don't modify LEX_RESWDOK if we're starting a comment */
5984 else if MBTEST((tflags & LEX_INCASE) && ch != '\n')
5985 /* If we can read a reserved word and we're in case, we're at the
5986 point where we can read a new pattern list or an esac. We
5987 handle the esac case above. If we read a newline, we want to
5988 leave LEX_RESWDOK alone. If we read anything else, we want to
5989 turn off LEX_RESWDOK, since we're going to read a pattern list. */
5991 tflags &= ~LEX_RESWDOK;
5992 /*itrace("parse_comsub:%d: lex_incase == 1 found `%c', lex_reswordok -> 0", line_number, ch);*/
5994 else if MBTEST(shellbreak (ch) == 0)
5996 tflags &= ~LEX_RESWDOK;
5997 /*itrace("parse_comsub:%d: found `%c', lex_reswordok -> 0", line_number, ch);*/
6001 /* Might be the start of a here-doc delimiter */
6002 if MBTEST((tflags & LEX_INCOMMENT) == 0 && (tflags & LEX_CKCASE) && ch == '<')
6004 /* Add this character. */
6005 RESIZE_MALLOCED_BUFFER (ret, retind, 1, retsize, 64);
6007 peekc = shell_getc (1);
6012 RESIZE_MALLOCED_BUFFER (ret, retind, 1, retsize, 64);
6013 ret[retind++] = peekc;
6014 peekc = shell_getc (1);
6019 RESIZE_MALLOCED_BUFFER (ret, retind, 1, retsize, 64);
6020 ret[retind++] = peekc;
6021 tflags |= LEX_STRIPDOC;
6024 shell_ungetc (peekc);
6027 tflags |= LEX_HEREDELIM;
6033 ch = peekc; /* fall through and continue XXX */
6035 else if MBTEST((tflags & LEX_CKCOMMENT) && (tflags & LEX_INCOMMENT) == 0 && ch == '#' && (((tflags & LEX_RESWDOK) && lex_rwlen == 0) || ((tflags & LEX_INWORD) && lex_wlen == 0)))
6037 /*itrace("parse_comsub:%d: lex_incomment -> 1 (%d)", line_number, __LINE__);*/
6038 tflags |= LEX_INCOMMENT;
6041 if MBTEST(ch == CTLESC || ch == CTLNUL) /* special shell escapes */
6043 RESIZE_MALLOCED_BUFFER (ret, retind, 2, retsize, 64);
6044 ret[retind++] = CTLESC;
6049 else if MBTEST((tflags & LEX_INCASE) && ch == close && close == ')')
6050 tflags &= ~LEX_INCASE; /* XXX */
6052 else if MBTEST(ch == close && (tflags & LEX_INCASE) == 0) /* ending delimiter */
6055 /*itrace("parse_comsub:%d: found close: count = %d", line_number, count);*/
6057 else if MBTEST(((flags & P_FIRSTCLOSE) == 0) && (tflags & LEX_INCASE) == 0 && ch == open) /* nested begin */
6060 /*itrace("parse_comsub:%d: found open: count = %d", line_number, count);*/
6063 /* Add this character. */
6064 RESIZE_MALLOCED_BUFFER (ret, retind, 1, retsize, 64);
6067 /* If we just read the ending character, don't bother continuing. */
6071 if MBTEST(ch == '\\') /* backslashes */
6072 tflags |= LEX_PASSNEXT;
6074 if MBTEST(shellquote (ch))
6076 /* '', ``, or "" inside $(...). */
6077 push_delimiter (dstack, ch);
6078 if MBTEST((tflags & LEX_WASDOL) && ch == '\'') /* $'...' inside group */
6079 nestret = parse_matched_pair (ch, ch, ch, &nestlen, P_ALLOWESC|rflags);
6081 nestret = parse_matched_pair (ch, ch, ch, &nestlen, rflags);
6082 pop_delimiter (dstack);
6083 CHECK_NESTRET_ERROR ();
6085 if MBTEST((tflags & LEX_WASDOL) && ch == '\'' && (extended_quote || (rflags & P_DQUOTE) == 0))
6087 /* Translate $'...' here. */
6088 ttrans = ansiexpand (nestret, 0, nestlen - 1, &ttranslen);
6091 if ((rflags & P_DQUOTE) == 0)
6093 nestret = sh_single_quote (ttrans);
6095 nestlen = strlen (nestret);
6100 nestlen = ttranslen;
6102 retind -= 2; /* back up before the $' */
6104 else if MBTEST((tflags & LEX_WASDOL) && ch == '"' && (extended_quote || (rflags & P_DQUOTE) == 0))
6106 /* Locale expand $"..." here. */
6107 ttrans = localeexpand (nestret, 0, nestlen - 1, start_lineno, &ttranslen);
6110 nestret = sh_mkdoublequoted (ttrans, ttranslen, 0);
6112 nestlen = ttranslen + 2;
6113 retind -= 2; /* back up before the $" */
6119 else if MBTEST((tflags & LEX_WASDOL) && (ch == '(' || ch == '{' || ch == '[')) /* ) } ] */
6120 /* check for $(), $[], or ${} inside command substitution. */
6122 if ((tflags & LEX_INCASE) == 0 && open == ch) /* undo previous increment */
6124 if (ch == '(') /* ) */
6125 nestret = parse_comsub (0, '(', ')', &nestlen, (rflags|P_COMMAND) & ~P_DQUOTE);
6126 else if (ch == '{') /* } */
6127 nestret = parse_matched_pair (0, '{', '}', &nestlen, P_FIRSTCLOSE|P_DOLBRACE|rflags);
6128 else if (ch == '[') /* ] */
6129 nestret = parse_matched_pair (0, '[', ']', &nestlen, rflags);
6131 CHECK_NESTRET_ERROR ();
6136 if MBTEST(ch == '$')
6137 tflags |= LEX_WASDOL;
6139 tflags &= ~LEX_WASDOL;
6146 /*itrace("parse_comsub:%d: returning `%s'", line_number, ret);*/
6150 /* Recursively call the parser to parse a $(...) command substitution. */
6152 xparse_dolparen (base, string, indp, flags)
6158 sh_parser_state_t ps;
6159 sh_input_line_state_t ls;
6160 int orig_ind, nc, sflags;
6161 char *ret, *s, *ep, *ostring;
6167 /*itrace("xparse_dolparen: size = %d shell_input_line = `%s'", shell_input_line_size, shell_input_line);*/
6168 sflags = SEVAL_NONINT|SEVAL_NOHIST|SEVAL_NOFREE;
6169 if (flags & SX_NOLONGJMP)
6170 sflags |= SEVAL_NOLONGJMP;
6171 save_parser_state (&ps);
6172 save_input_line_state (&ls);
6175 parser_state |= PST_CMDSUBST|PST_EOFTOKEN; /* allow instant ')' */ /*(*/
6176 shell_eof_token = ')';
6177 parse_string (string, "command substitution", sflags, &ep);
6179 restore_parser_state (&ps);
6181 /* reset_parser clears shell_input_line and associated variables */
6182 restore_input_line_state (&ls);
6186 /* Need to find how many characters parse_and_execute consumed, update
6187 *indp, if flags != 0, copy the portion of the string parsed into RET
6188 and return it. If flags & 1 (EX_NOALLOC) we can return NULL. */
6195 itrace("xparse_dolparen:%d: ep[-1] != RPAREN (%d), ep = `%s'", line_number, ep[-1], ep);
6197 while (ep > ostring && ep[-1] == '\n') ep--;
6201 *indp = ep - base - 1;
6205 if (base[*indp] != ')')
6206 itrace("xparse_dolparen:%d: base[%d] != RPAREN (%d), base = `%s'", line_number, *indp, base[*indp], base);
6209 if (flags & SX_NOALLOC)
6210 return (char *)NULL;
6218 ret = substring (ostring, 0, nc - 1);
6223 #if defined (DPAREN_ARITHMETIC) || defined (ARITH_FOR_COMMAND)
6224 /* Parse a double-paren construct. It can be either an arithmetic
6225 command, an arithmetic `for' command, or a nested subshell. Returns
6226 the parsed token, -1 on error, or -2 if we didn't do anything and
6227 should just go on. */
6236 #if defined (ARITH_FOR_COMMAND)
6237 if (last_read_token == FOR)
6239 arith_for_lineno = line_number;
6240 cmdtyp = parse_arith_cmd (&wval, 0);
6243 wd = alloc_word_desc ();
6245 yylval.word_list = make_word_list (wd, (WORD_LIST *)NULL);
6246 return (ARITH_FOR_EXPRS);
6249 return -1; /* ERROR */
6253 #if defined (DPAREN_ARITHMETIC)
6254 if (reserved_word_acceptable (last_read_token))
6256 sline = line_number;
6258 cmdtyp = parse_arith_cmd (&wval, 0);
6259 if (cmdtyp == 1) /* arithmetic command */
6261 wd = alloc_word_desc ();
6263 wd->flags = W_QUOTED|W_NOSPLIT|W_NOGLOB|W_DQUOTE;
6264 yylval.word_list = make_word_list (wd, (WORD_LIST *)NULL);
6267 else if (cmdtyp == 0) /* nested subshell */
6269 push_string (wval, 0, (alias_t *)NULL);
6270 if ((parser_state & PST_CASEPAT) == 0)
6271 parser_state |= PST_SUBSHELL;
6279 return -2; /* XXX */
6282 /* We've seen a `(('. Look for the matching `))'. If we get it, return 1.
6283 If not, assume it's a nested subshell for backwards compatibility and
6284 return 0. In any case, put the characters we've consumed into a locally-
6285 allocated buffer and make *ep point to that buffer. Return -1 on an
6286 error, for example EOF. */
6288 parse_arith_cmd (ep, adddq)
6292 int exp_lineno, rval, c;
6293 char *ttok, *tokstr;
6296 exp_lineno = line_number;
6297 ttok = parse_matched_pair (0, '(', ')', &ttoklen, 0);
6299 if (ttok == &matched_pair_error)
6301 /* Check that the next character is the closing right paren. If
6302 not, this is a syntax error. ( */
6307 tokstr = (char *)xmalloc (ttoklen + 4);
6309 /* if ADDDQ != 0 then (( ... )) -> "..." */
6310 if (rval == 1 && adddq) /* arith cmd, add double quotes */
6313 strncpy (tokstr + 1, ttok, ttoklen - 1);
6314 tokstr[ttoklen] = '"';
6315 tokstr[ttoklen+1] = '\0';
6317 else if (rval == 1) /* arith cmd, don't add double quotes */
6319 strncpy (tokstr, ttok, ttoklen - 1);
6320 tokstr[ttoklen-1] = '\0';
6322 else /* nested subshell */
6325 strncpy (tokstr + 1, ttok, ttoklen - 1);
6326 tokstr[ttoklen] = ')';
6327 tokstr[ttoklen+1] = c;
6328 tokstr[ttoklen+2] = '\0';
6335 #endif /* DPAREN_ARITHMETIC || ARITH_FOR_COMMAND */
6337 #if defined (COND_COMMAND)
6343 if (EOF_Reached && cond_token != COND_ERROR) /* [[ */
6344 parser_error (cond_lineno, _("unexpected EOF while looking for `]]'"));
6345 else if (cond_token != COND_ERROR)
6347 if (etext = error_token_from_token (cond_token))
6349 parser_error (cond_lineno, _("syntax error in conditional expression: unexpected token `%s'"), etext);
6353 parser_error (cond_lineno, _("syntax error in conditional expression"));
6360 return (cond_or ());
6369 if (cond_token == OR_OR)
6372 l = make_cond_node (COND_OR, (WORD_DESC *)NULL, l, r);
6383 if (cond_token == AND_AND)
6386 l = make_cond_node (COND_AND, (WORD_DESC *)NULL, l, r);
6392 cond_skip_newlines ()
6394 while ((cond_token = read_token (READ)) == '\n')
6396 if (SHOULD_PROMPT ())
6399 return (cond_token);
6402 #define COND_RETURN_ERROR() \
6403 do { cond_token = COND_ERROR; return ((COND_COM *)NULL); } while (0)
6409 COND_COM *term, *tleft, *tright;
6413 /* Read a token. It can be a left paren, a `!', a unary operator, or a
6414 word that should be the first argument of a binary operator. Start by
6415 skipping newlines, since this is a compound command. */
6416 tok = cond_skip_newlines ();
6417 lineno = line_number;
6418 if (tok == COND_END)
6420 COND_RETURN_ERROR ();
6422 else if (tok == '(')
6424 term = cond_expr ();
6425 if (cond_token != ')')
6428 dispose_cond_node (term); /* ( */
6429 if (etext = error_token_from_token (cond_token))
6431 parser_error (lineno, _("unexpected token `%s', expected `)'"), etext);
6435 parser_error (lineno, _("expected `)'"));
6436 COND_RETURN_ERROR ();
6438 term = make_cond_node (COND_EXPR, (WORD_DESC *)NULL, term, (COND_COM *)NULL);
6439 (void)cond_skip_newlines ();
6441 else if (tok == BANG || (tok == WORD && (yylval.word->word[0] == '!' && yylval.word->word[1] == '\0')))
6444 dispose_word (yylval.word); /* not needed */
6445 term = cond_term ();
6447 term->flags |= CMD_INVERT_RETURN;
6449 else if (tok == WORD && yylval.word->word[0] == '-' && yylval.word->word[2] == 0 && test_unop (yylval.word->word))
6452 tok = read_token (READ);
6455 tleft = make_cond_node (COND_TERM, yylval.word, (COND_COM *)NULL, (COND_COM *)NULL);
6456 term = make_cond_node (COND_UNARY, op, tleft, (COND_COM *)NULL);
6461 if (etext = error_token_from_token (tok))
6463 parser_error (line_number, _("unexpected argument `%s' to conditional unary operator"), etext);
6467 parser_error (line_number, _("unexpected argument to conditional unary operator"));
6468 COND_RETURN_ERROR ();
6471 (void)cond_skip_newlines ();
6473 else if (tok == WORD) /* left argument to binary operator */
6476 tleft = make_cond_node (COND_TERM, yylval.word, (COND_COM *)NULL, (COND_COM *)NULL);
6479 tok = read_token (READ);
6480 if (tok == WORD && test_binop (yylval.word->word))
6483 if (op->word[0] == '=' && (op->word[1] == '\0' || (op->word[1] == '=' && op->word[2] == '\0')))
6484 parser_state |= PST_EXTPAT;
6485 else if (op->word[0] == '!' && op->word[1] == '=' && op->word[2] == '\0')
6486 parser_state |= PST_EXTPAT;
6488 #if defined (COND_REGEXP)
6489 else if (tok == WORD && STREQ (yylval.word->word, "=~"))
6492 parser_state |= PST_REGEXP;
6495 else if (tok == '<' || tok == '>')
6496 op = make_word_from_token (tok); /* ( */
6497 /* There should be a check before blindly accepting the `)' that we have
6498 seen the opening `('. */
6499 else if (tok == COND_END || tok == AND_AND || tok == OR_OR || tok == ')')
6501 /* Special case. [[ x ]] is equivalent to [[ -n x ]], just like
6502 the test command. Similarly for [[ x && expr ]] or
6503 [[ x || expr ]] or [[ (x) ]]. */
6504 op = make_word ("-n");
6505 term = make_cond_node (COND_UNARY, op, tleft, (COND_COM *)NULL);
6511 if (etext = error_token_from_token (tok))
6513 parser_error (line_number, _("unexpected token `%s', conditional binary operator expected"), etext);
6517 parser_error (line_number, _("conditional binary operator expected"));
6518 dispose_cond_node (tleft);
6519 COND_RETURN_ERROR ();
6523 if (parser_state & PST_EXTPAT)
6525 tok = read_token (READ);
6526 if (parser_state & PST_EXTPAT)
6527 extended_glob = global_extglob;
6528 parser_state &= ~(PST_REGEXP|PST_EXTPAT);
6532 tright = make_cond_node (COND_TERM, yylval.word, (COND_COM *)NULL, (COND_COM *)NULL);
6533 term = make_cond_node (COND_BINARY, op, tleft, tright);
6537 if (etext = error_token_from_token (tok))
6539 parser_error (line_number, _("unexpected argument `%s' to conditional binary operator"), etext);
6543 parser_error (line_number, _("unexpected argument to conditional binary operator"));
6544 dispose_cond_node (tleft);
6546 COND_RETURN_ERROR ();
6549 (void)cond_skip_newlines ();
6554 parser_error (line_number, _("unexpected token `%c' in conditional command"), tok);
6555 else if (etext = error_token_from_token (tok))
6557 parser_error (line_number, _("unexpected token `%s' in conditional command"), etext);
6561 parser_error (line_number, _("unexpected token %d in conditional command"), tok);
6562 COND_RETURN_ERROR ();
6567 /* This is kind of bogus -- we slip a mini recursive-descent parser in
6568 here to handle the conditional statement syntax. */
6570 parse_cond_command ()
6574 global_extglob = extended_glob;
6575 cexp = cond_expr ();
6576 return (make_cond_command (cexp));
6580 #if defined (ARRAY_VARS)
6581 /* When this is called, it's guaranteed that we don't care about anything
6582 in t beyond i. We do save and restore the chars, though. */
6584 token_is_assignment (t, i)
6588 unsigned char c, c1;
6591 c = t[i]; c1 = t[i+1];
6592 t[i] = '='; t[i+1] = '\0';
6593 r = assignment (t, (parser_state & PST_COMPASSIGN) != 0);
6594 t[i] = c; t[i+1] = c1;
6598 /* XXX - possible changes here for `+=' */
6600 token_is_ident (t, i)
6609 r = legal_identifier (t);
6616 read_token_word (character)
6619 /* The value for YYLVAL when a WORD is read. */
6620 WORD_DESC *the_word;
6622 /* Index into the token that we are building. */
6625 /* ALL_DIGITS becomes zero when we see a non-digit. */
6626 int all_digit_token;
6628 /* DOLLAR_PRESENT becomes non-zero if we see a `$'. */
6631 /* COMPOUND_ASSIGNMENT becomes non-zero if we are parsing a compound
6633 int compound_assignment;
6635 /* QUOTED becomes non-zero if we see one of ("), ('), (`), or (\). */
6638 /* Non-zero means to ignore the value of the next character, and just
6639 to add it no matter what. */
6640 int pass_next_character;
6642 /* The current delimiting character. */
6644 int result, peek_char;
6645 char *ttok, *ttrans;
6646 int ttoklen, ttranslen;
6649 if (token_buffer_size < TOKEN_DEFAULT_INITIAL_SIZE)
6650 token = (char *)xrealloc (token, token_buffer_size = TOKEN_DEFAULT_INITIAL_SIZE);
6653 all_digit_token = DIGIT (character);
6654 dollar_present = quoted = pass_next_character = compound_assignment = 0;
6658 if (character == EOF)
6661 if (pass_next_character)
6663 pass_next_character = 0;
6664 goto got_escaped_character;
6667 cd = current_delimiter (dstack);
6669 /* Handle backslashes. Quote lots of things when not inside of
6670 double-quotes, quote some things inside of double-quotes. */
6671 if MBTEST(character == '\\')
6673 peek_char = shell_getc (0);
6675 /* Backslash-newline is ignored in all cases except
6676 when quoted with single quotes. */
6677 if (peek_char == '\n')
6680 goto next_character;
6684 shell_ungetc (peek_char);
6686 /* If the next character is to be quoted, note it now. */
6687 if (cd == 0 || cd == '`' ||
6688 (cd == '"' && peek_char >= 0 && (sh_syntaxtab[peek_char] & CBSDQUOTE)))
6689 pass_next_character++;
6696 /* Parse a matched pair of quote characters. */
6697 if MBTEST(shellquote (character))
6699 push_delimiter (dstack, character);
6700 ttok = parse_matched_pair (character, character, character, &ttoklen, (character == '`') ? P_COMMAND : 0);
6701 pop_delimiter (dstack);
6702 if (ttok == &matched_pair_error)
6703 return -1; /* Bail immediately. */
6704 RESIZE_MALLOCED_BUFFER (token, token_index, ttoklen + 2,
6705 token_buffer_size, TOKEN_DEFAULT_GROW_SIZE);
6706 token[token_index++] = character;
6707 strcpy (token + token_index, ttok);
6708 token_index += ttoklen;
6709 all_digit_token = 0;
6711 dollar_present |= (character == '"' && strchr (ttok, '$') != 0);
6713 goto next_character;
6717 /* When parsing a regexp as a single word inside a conditional command,
6718 we need to special-case characters special to both the shell and
6719 regular expressions. Right now, that is only '(' and '|'. */ /*)*/
6720 if MBTEST((parser_state & PST_REGEXP) && (character == '(' || character == '|')) /*)*/
6722 if (character == '|')
6725 push_delimiter (dstack, character);
6726 ttok = parse_matched_pair (cd, '(', ')', &ttoklen, 0);
6727 pop_delimiter (dstack);
6728 if (ttok == &matched_pair_error)
6729 return -1; /* Bail immediately. */
6730 RESIZE_MALLOCED_BUFFER (token, token_index, ttoklen + 2,
6731 token_buffer_size, TOKEN_DEFAULT_GROW_SIZE);
6732 token[token_index++] = character;
6733 strcpy (token + token_index, ttok);
6734 token_index += ttoklen;
6736 dollar_present = all_digit_token = 0;
6737 goto next_character;
6739 #endif /* COND_REGEXP */
6741 #ifdef EXTENDED_GLOB
6742 /* Parse a ksh-style extended pattern matching specification. */
6743 if MBTEST(extended_glob && PATTERN_CHAR (character))
6745 peek_char = shell_getc (1);
6746 if MBTEST(peek_char == '(') /* ) */
6748 push_delimiter (dstack, peek_char);
6749 ttok = parse_matched_pair (cd, '(', ')', &ttoklen, 0);
6750 pop_delimiter (dstack);
6751 if (ttok == &matched_pair_error)
6752 return -1; /* Bail immediately. */
6753 RESIZE_MALLOCED_BUFFER (token, token_index, ttoklen + 2,
6755 TOKEN_DEFAULT_GROW_SIZE);
6756 token[token_index++] = character;
6757 token[token_index++] = peek_char;
6758 strcpy (token + token_index, ttok);
6759 token_index += ttoklen;
6761 dollar_present = all_digit_token = 0;
6762 goto next_character;
6765 shell_ungetc (peek_char);
6767 #endif /* EXTENDED_GLOB */
6769 /* If the delimiter character is not single quote, parse some of
6770 the shell expansions that must be read as a single word. */
6771 if (shellexp (character))
6773 peek_char = shell_getc (1);
6774 /* $(...), <(...), >(...), $((...)), ${...}, and $[...] constructs */
6775 if MBTEST(peek_char == '(' || \
6776 ((peek_char == '{' || peek_char == '[') && character == '$')) /* ) ] } */
6778 if (peek_char == '{') /* } */
6779 ttok = parse_matched_pair (cd, '{', '}', &ttoklen, P_FIRSTCLOSE|P_DOLBRACE);
6780 else if (peek_char == '(') /* ) */
6782 /* XXX - push and pop the `(' as a delimiter for use by
6783 the command-oriented-history code. This way newlines
6784 appearing in the $(...) string get added to the
6785 history literally rather than causing a possibly-
6786 incorrect `;' to be added. ) */
6787 push_delimiter (dstack, peek_char);
6788 ttok = parse_comsub (cd, '(', ')', &ttoklen, P_COMMAND);
6789 pop_delimiter (dstack);
6792 ttok = parse_matched_pair (cd, '[', ']', &ttoklen, 0);
6793 if (ttok == &matched_pair_error)
6794 return -1; /* Bail immediately. */
6795 RESIZE_MALLOCED_BUFFER (token, token_index, ttoklen + 2,
6797 TOKEN_DEFAULT_GROW_SIZE);
6798 token[token_index++] = character;
6799 token[token_index++] = peek_char;
6800 strcpy (token + token_index, ttok);
6801 token_index += ttoklen;
6804 all_digit_token = 0;
6805 goto next_character;
6807 /* This handles $'...' and $"..." new-style quoted strings. */
6808 else if MBTEST(character == '$' && (peek_char == '\'' || peek_char == '"'))
6812 first_line = line_number;
6813 push_delimiter (dstack, peek_char);
6814 ttok = parse_matched_pair (peek_char, peek_char, peek_char,
6816 (peek_char == '\'') ? P_ALLOWESC : 0);
6817 pop_delimiter (dstack);
6818 if (ttok == &matched_pair_error)
6820 if (peek_char == '\'')
6822 ttrans = ansiexpand (ttok, 0, ttoklen - 1, &ttranslen);
6825 /* Insert the single quotes and correctly quote any
6826 embedded single quotes (allowed because P_ALLOWESC was
6827 passed to parse_matched_pair). */
6828 ttok = sh_single_quote (ttrans);
6830 ttranslen = strlen (ttok);
6835 /* Try to locale-expand the converted string. */
6836 ttrans = localeexpand (ttok, 0, ttoklen - 1, first_line, &ttranslen);
6839 /* Add the double quotes back */
6840 ttok = sh_mkdoublequoted (ttrans, ttranslen, 0);
6846 RESIZE_MALLOCED_BUFFER (token, token_index, ttranslen + 2,
6848 TOKEN_DEFAULT_GROW_SIZE);
6849 strcpy (token + token_index, ttrans);
6850 token_index += ttranslen;
6853 all_digit_token = 0;
6854 goto next_character;
6856 /* This could eventually be extended to recognize all of the
6857 shell's single-character parameter expansions, and set flags.*/
6858 else if MBTEST(character == '$' && peek_char == '$')
6860 ttok = (char *)xmalloc (3);
6861 ttok[0] = ttok[1] = '$';
6863 RESIZE_MALLOCED_BUFFER (token, token_index, 3,
6865 TOKEN_DEFAULT_GROW_SIZE);
6866 strcpy (token + token_index, ttok);
6869 all_digit_token = 0;
6871 goto next_character;
6874 shell_ungetc (peek_char);
6877 #if defined (ARRAY_VARS)
6878 /* Identify possible array subscript assignment; match [...]. If
6879 parser_state&PST_COMPASSIGN, we need to parse [sub]=words treating
6880 `sub' as if it were enclosed in double quotes. */
6881 else if MBTEST(character == '[' && /* ] */
6882 ((token_index > 0 && assignment_acceptable (last_read_token) && token_is_ident (token, token_index)) ||
6883 (token_index == 0 && (parser_state&PST_COMPASSIGN))))
6885 ttok = parse_matched_pair (cd, '[', ']', &ttoklen, P_ARRAYSUB);
6886 if (ttok == &matched_pair_error)
6887 return -1; /* Bail immediately. */
6888 RESIZE_MALLOCED_BUFFER (token, token_index, ttoklen + 2,
6890 TOKEN_DEFAULT_GROW_SIZE);
6891 token[token_index++] = character;
6892 strcpy (token + token_index, ttok);
6893 token_index += ttoklen;
6895 all_digit_token = 0;
6896 goto next_character;
6898 /* Identify possible compound array variable assignment. */
6899 else if MBTEST(character == '=' && token_index > 0 && (assignment_acceptable (last_read_token) || (parser_state & PST_ASSIGNOK)) && token_is_assignment (token, token_index))
6901 peek_char = shell_getc (1);
6902 if MBTEST(peek_char == '(') /* ) */
6904 ttok = parse_compound_assignment (&ttoklen);
6906 RESIZE_MALLOCED_BUFFER (token, token_index, ttoklen + 4,
6908 TOKEN_DEFAULT_GROW_SIZE);
6910 token[token_index++] = '=';
6911 token[token_index++] = '(';
6914 strcpy (token + token_index, ttok);
6915 token_index += ttoklen;
6917 token[token_index++] = ')';
6919 all_digit_token = 0;
6920 compound_assignment = 1;
6922 goto next_character;
6924 goto got_token; /* ksh93 seems to do this */
6928 shell_ungetc (peek_char);
6932 /* When not parsing a multi-character word construct, shell meta-
6933 characters break words. */
6934 if MBTEST(shellbreak (character))
6936 shell_ungetc (character);
6942 if (character == CTLESC || character == CTLNUL)
6943 token[token_index++] = CTLESC;
6945 got_escaped_character:
6947 all_digit_token &= DIGIT (character);
6948 dollar_present |= character == '$';
6950 token[token_index++] = character;
6952 RESIZE_MALLOCED_BUFFER (token, token_index, 1, token_buffer_size,
6953 TOKEN_DEFAULT_GROW_SIZE);
6956 if (character == '\n' && SHOULD_PROMPT ())
6959 /* We want to remove quoted newlines (that is, a \<newline> pair)
6960 unless we are within single quotes or pass_next_character is
6961 set (the shell equivalent of literal-next). */
6962 cd = current_delimiter (dstack);
6963 character = shell_getc (cd != '\'' && pass_next_character == 0);
6964 } /* end for (;;) */
6968 token[token_index] = '\0';
6970 /* Check to see what thing we should return. If the last_read_token
6971 is a `<', or a `&', or the character which ended this token is
6972 a '>' or '<', then, and ONLY then, is this input token a NUMBER.
6973 Otherwise, it is just a word, and should be returned as such. */
6974 if MBTEST(all_digit_token && (character == '<' || character == '>' || \
6975 last_read_token == LESS_AND || \
6976 last_read_token == GREATER_AND))
6978 if (legal_number (token, &lvalue) && (int)lvalue == lvalue)
6979 yylval.number = lvalue;
6985 /* Check for special case tokens. */
6986 result = (last_shell_getc_is_singlebyte) ? special_case_tokens (token) : -1;
6991 /* Posix.2 does not allow reserved words to be aliased, so check for all
6992 of them, including special cases, before expanding the current token
6994 if MBTEST(posixly_correct)
6995 CHECK_FOR_RESERVED_WORD (token);
6997 /* Aliases are expanded iff EXPAND_ALIASES is non-zero, and quoting
6998 inhibits alias expansion. */
6999 if (expand_aliases && quoted == 0)
7001 result = alias_expand_token (token);
7002 if (result == RE_READ_TOKEN)
7003 return (RE_READ_TOKEN);
7004 else if (result == NO_EXPANSION)
7005 parser_state &= ~PST_ALEXPNEXT;
7008 /* If not in Posix.2 mode, check for reserved words after alias
7010 if MBTEST(posixly_correct == 0)
7012 CHECK_FOR_RESERVED_WORD (token);
7014 the_word = (WORD_DESC *)xmalloc (sizeof (WORD_DESC));
7015 the_word->word = (char *)xmalloc (1 + token_index);
7016 the_word->flags = 0;
7017 strcpy (the_word->word, token);
7019 the_word->flags |= W_HASDOLLAR;
7021 the_word->flags |= W_QUOTED; /*(*/
7022 if (compound_assignment && token[token_index-1] == ')')
7023 the_word->flags |= W_COMPASSIGN;
7024 /* A word is an assignment if it appears at the beginning of a
7025 simple command, or after another assignment word. This is
7026 context-dependent, so it cannot be handled in the grammar. */
7027 if (assignment (token, (parser_state & PST_COMPASSIGN) != 0))
7029 the_word->flags |= W_ASSIGNMENT;
7030 /* Don't perform word splitting on assignment statements. */
7031 if (assignment_acceptable (last_read_token) || (parser_state & PST_COMPASSIGN) != 0)
7032 the_word->flags |= W_NOSPLIT;
7035 if (command_token_position (last_read_token))
7038 b = builtin_address_internal (token, 0);
7039 if (b && (b->flags & ASSIGNMENT_BUILTIN))
7040 parser_state |= PST_ASSIGNOK;
7041 else if (STREQ (token, "eval") || STREQ (token, "let"))
7042 parser_state |= PST_ASSIGNOK;
7045 yylval.word = the_word;
7047 if (token[0] == '{' && token[token_index-1] == '}' &&
7048 (character == '<' || character == '>'))
7050 /* can use token; already copied to the_word */
7051 token[token_index-1] = '\0';
7052 if (legal_identifier (token+1))
7054 strcpy (the_word->word, token+1);
7055 /*itrace("read_token_word: returning REDIR_WORD for %s", the_word->word);*/
7056 return (REDIR_WORD);
7060 result = ((the_word->flags & (W_ASSIGNMENT|W_NOSPLIT)) == (W_ASSIGNMENT|W_NOSPLIT))
7061 ? ASSIGNMENT_WORD : WORD;
7063 switch (last_read_token)
7066 parser_state |= PST_ALLOWOPNBRC;
7067 function_dstart = line_number;
7072 if (word_top < MAX_CASE_NEST)
7074 word_lineno[word_top] = line_number;
7081 /* Return 1 if TOKSYM is a token that after being read would allow
7082 a reserved word to be seen, else 0. */
7084 reserved_word_acceptable (toksym)
7121 #if defined (COPROCESS_SUPPORT)
7122 if (last_read_token == WORD && token_before_that == COPROC)
7125 if (last_read_token == WORD && token_before_that == FUNCTION)
7131 /* Return the index of TOKEN in the alist of reserved words, or -1 if
7132 TOKEN is not a shell reserved word. */
7134 find_reserved_word (tokstr)
7138 for (i = 0; word_token_alist[i].word; i++)
7139 if (STREQ (tokstr, word_token_alist[i].word))
7145 #if defined (READLINE)
7146 /* Called after each time readline is called. This insures that whatever
7147 the new prompt string is gets propagated to readline's local prompt
7150 reset_readline_prompt ()
7154 if (prompt_string_pointer)
7156 temp_prompt = (*prompt_string_pointer)
7157 ? decode_prompt_string (*prompt_string_pointer)
7160 if (temp_prompt == 0)
7162 temp_prompt = (char *)xmalloc (1);
7163 temp_prompt[0] = '\0';
7166 FREE (current_readline_prompt);
7167 current_readline_prompt = temp_prompt;
7170 #endif /* READLINE */
7173 #if defined (HISTORY)
7174 /* A list of tokens which can be followed by newlines, but not by
7175 semi-colons. When concatenating multiple lines of history, the
7176 newline separator for such tokens is replaced with a space. */
7177 static const int no_semi_successors[] = {
7178 '\n', '{', '(', ')', ';', '&', '|',
7179 CASE, DO, ELSE, IF, SEMI_SEMI, SEMI_AND, SEMI_SEMI_AND, THEN, UNTIL,
7180 WHILE, AND_AND, OR_OR, IN,
7184 /* If we are not within a delimited expression, try to be smart
7185 about which separators can be semi-colons and which must be
7186 newlines. Returns the string that should be added into the
7187 history entry. LINE is the line we're about to add; it helps
7188 make some more intelligent decisions in certain cases. */
7190 history_delimiting_chars (line)
7193 static int last_was_heredoc = 0; /* was the last entry the start of a here document? */
7196 if ((parser_state & PST_HEREDOC) == 0)
7197 last_was_heredoc = 0;
7199 if (dstack.delimiter_depth != 0)
7202 /* We look for current_command_line_count == 2 because we are looking to
7203 add the first line of the body of the here document (the second line
7204 of the command). We also keep LAST_WAS_HEREDOC as a private sentinel
7205 variable to note when we think we added the first line of a here doc
7206 (the one with a "<<" somewhere in it) */
7207 if (parser_state & PST_HEREDOC)
7209 if (last_was_heredoc)
7211 last_was_heredoc = 0;
7214 return (current_command_line_count == 2 ? "\n" : "");
7217 if (parser_state & PST_COMPASSIGN)
7220 /* First, handle some special cases. */
7222 /* If we just read `()', assume it's a function definition, and don't
7223 add a semicolon. If the token before the `)' was not `(', and we're
7224 not in the midst of parsing a case statement, assume it's a
7225 parenthesized command and add the semicolon. */
7227 if (token_before_that == ')')
7229 if (two_tokens_ago == '(') /*)*/ /* function def */
7231 /* This does not work for subshells inside case statement
7232 command lists. It's a suboptimal solution. */
7233 else if (parser_state & PST_CASESTMT) /* case statement pattern */
7236 return "; "; /* (...) subshell */
7238 else if (token_before_that == WORD && two_tokens_ago == FUNCTION)
7239 return " "; /* function def using `function name' without `()' */
7241 /* If we're not in a here document, but we think we're about to parse one,
7242 and we would otherwise return a `;', return a newline to delimit the
7243 line with the here-doc delimiter */
7244 else if ((parser_state & PST_HEREDOC) == 0 && current_command_line_count > 1 && last_read_token == '\n' && strstr (line, "<<"))
7246 last_was_heredoc = 1;
7250 else if (token_before_that == WORD && two_tokens_ago == FOR)
7252 /* Tricky. `for i\nin ...' should not have a semicolon, but
7253 `for i\ndo ...' should. We do what we can. */
7254 for (i = shell_input_line_index; whitespace (shell_input_line[i]); i++)
7256 if (shell_input_line[i] && shell_input_line[i] == 'i' && shell_input_line[i+1] == 'n')
7260 else if (two_tokens_ago == CASE && token_before_that == WORD && (parser_state & PST_CASESTMT))
7263 for (i = 0; no_semi_successors[i]; i++)
7265 if (token_before_that == no_semi_successors[i])
7271 #endif /* HISTORY */
7273 /* Issue a prompt, or prepare to issue a prompt when the next character
7280 if (interactive == 0 || expanding_alias ()) /* XXX */
7283 ps1_prompt = get_string_value ("PS1");
7284 ps2_prompt = get_string_value ("PS2");
7286 if (!prompt_string_pointer)
7287 prompt_string_pointer = &ps1_prompt;
7289 temp_prompt = *prompt_string_pointer
7290 ? decode_prompt_string (*prompt_string_pointer)
7293 if (temp_prompt == 0)
7295 temp_prompt = (char *)xmalloc (1);
7296 temp_prompt[0] = '\0';
7299 current_prompt_string = *prompt_string_pointer;
7300 prompt_string_pointer = &ps2_prompt;
7302 #if defined (READLINE)
7303 if (!no_line_editing)
7305 FREE (current_readline_prompt);
7306 current_readline_prompt = temp_prompt;
7309 #endif /* READLINE */
7311 FREE (current_decoded_prompt);
7312 current_decoded_prompt = temp_prompt;
7317 get_current_prompt_level ()
7319 return ((current_prompt_string && current_prompt_string == ps2_prompt) ? 2 : 1);
7323 set_current_prompt_level (x)
7326 prompt_string_pointer = (x == 2) ? &ps2_prompt : &ps1_prompt;
7327 current_prompt_string = *prompt_string_pointer;
7333 fprintf (stderr, "%s", current_decoded_prompt);
7337 /* Return a string which will be printed as a prompt. The string
7338 may contain special characters which are decoded as follows:
7341 \d the date in Day Mon Date format
7342 \e escape (ascii 033)
7343 \h the hostname up to the first `.'
7345 \j the number of active jobs
7346 \l the basename of the shell's tty device name
7349 \s the name of the shell
7350 \t the time in 24-hour hh:mm:ss format
7351 \T the time in 12-hour hh:mm:ss format
7352 \@ the time in 12-hour hh:mm am/pm format
7353 \A the time in 24-hour hh:mm format
7354 \D{fmt} the result of passing FMT to strftime(3)
7356 \v the version of bash (e.g., 2.00)
7357 \V the release of bash, version + patchlevel (e.g., 2.00.0)
7358 \w the current working directory
7359 \W the last element of $PWD
7360 \! the history number of this command
7361 \# the command number of this command
7362 \$ a $ or a # if you are root
7363 \nnn character code nnn in octal
7365 \[ begin a sequence of non-printing chars
7366 \] end a sequence of non-printing chars
7368 #define PROMPT_GROWTH 48
7370 decode_prompt_string (string)
7375 struct dstack save_dstack;
7376 int last_exit_value, last_comsub_pid;
7377 #if defined (PROMPT_STRING_DECODE)
7378 int result_size, result_index;
7380 char *temp, octal_string[4];
7386 result = (char *)xmalloc (result_size = PROMPT_GROWTH);
7387 result[result_index = 0] = 0;
7388 temp = (char *)NULL;
7390 while (c = *string++)
7392 if (posixly_correct && c == '!')
7396 temp = savestring ("!");
7401 #if !defined (HISTORY)
7402 temp = savestring ("1");
7404 temp = itos (history_number ());
7405 #endif /* HISTORY */
7406 string--; /* add_string increments string again. */
7424 strncpy (octal_string, string, 3);
7425 octal_string[3] = '\0';
7427 n = read_octal (octal_string);
7428 temp = (char *)xmalloc (3);
7430 if (n == CTLESC || n == CTLNUL)
7447 for (c = 0; n != -1 && c < 3 && ISOCTAL (*string); c++)
7450 c = 0; /* tested at add_string: */
7458 /* Make the current time/date into a string. */
7459 (void) time (&the_time);
7460 #if defined (HAVE_TZSET)
7461 sv_tz ("TZ"); /* XXX -- just make sure */
7463 tm = localtime (&the_time);
7466 n = strftime (timebuf, sizeof (timebuf), "%a %b %d", tm);
7468 n = strftime (timebuf, sizeof (timebuf), "%H:%M:%S", tm);
7470 n = strftime (timebuf, sizeof (timebuf), "%I:%M:%S", tm);
7472 n = strftime (timebuf, sizeof (timebuf), "%I:%M %p", tm);
7474 n = strftime (timebuf, sizeof (timebuf), "%H:%M", tm);
7479 timebuf[sizeof(timebuf) - 1] = '\0';
7481 temp = savestring (timebuf);
7484 case 'D': /* strftime format */
7485 if (string[1] != '{') /* } */
7488 (void) time (&the_time);
7489 tm = localtime (&the_time);
7490 string += 2; /* skip { */
7491 timefmt = xmalloc (strlen (string) + 3);
7492 for (t = timefmt; *string && *string != '}'; )
7495 c = *string; /* tested at add_string */
7496 if (timefmt[0] == '\0')
7499 timefmt[1] = 'X'; /* locale-specific current time */
7502 n = strftime (timebuf, sizeof (timebuf), timefmt, tm);
7508 timebuf[sizeof(timebuf) - 1] = '\0';
7510 if (promptvars || posixly_correct)
7511 /* Make sure that expand_prompt_string is called with a
7512 second argument of Q_DOUBLE_QUOTES if we use this
7514 temp = sh_backslash_quote_for_double_quotes (timebuf);
7516 temp = savestring (timebuf);
7520 temp = (char *)xmalloc (3);
7521 temp[0] = no_line_editing ? '\n' : '\r';
7522 temp[1] = no_line_editing ? '\0' : '\n';
7527 temp = base_pathname (shell_name);
7528 temp = savestring (temp);
7533 temp = (char *)xmalloc (16);
7535 strcpy (temp, dist_version);
7537 sprintf (temp, "%s.%d", dist_version, patch_level);
7543 /* Use the value of PWD because it is much more efficient. */
7544 char t_string[PATH_MAX];
7547 temp = get_string_value ("PWD");
7551 if (getcwd (t_string, sizeof(t_string)) == 0)
7557 tlen = strlen (t_string);
7561 tlen = sizeof (t_string) - 1;
7562 strncpy (t_string, temp, tlen);
7564 t_string[tlen] = '\0';
7566 #if defined (MACOSX)
7567 /* Convert from "fs" format to "input" format */
7568 temp = fnx_fromfs (t_string, strlen (t_string));
7569 if (temp != t_string)
7570 strcpy (t_string, temp);
7573 #define ROOT_PATH(x) ((x)[0] == '/' && (x)[1] == 0)
7574 #define DOUBLE_SLASH_ROOT(x) ((x)[0] == '/' && (x)[1] == '/' && (x)[2] == 0)
7575 /* Abbreviate \W as ~ if $PWD == $HOME */
7576 if (c == 'W' && (((t = get_string_value ("HOME")) == 0) || STREQ (t, t_string) == 0))
7578 if (ROOT_PATH (t_string) == 0 && DOUBLE_SLASH_ROOT (t_string) == 0)
7580 t = strrchr (t_string, '/');
7582 memmove (t_string, t + 1, strlen (t)); /* strlen(t) to copy NULL */
7586 #undef DOUBLE_SLASH_ROOT
7588 /* polite_directory_format is guaranteed to return a string
7589 no longer than PATH_MAX - 1 characters. */
7590 strcpy (t_string, polite_directory_format (t_string));
7592 temp = trim_pathname (t_string, PATH_MAX - 1);
7593 /* If we're going to be expanding the prompt string later,
7594 quote the directory name. */
7595 if (promptvars || posixly_correct)
7596 /* Make sure that expand_prompt_string is called with a
7597 second argument of Q_DOUBLE_QUOTES if we use this
7599 temp = sh_backslash_quote_for_double_quotes (t_string);
7601 temp = savestring (t_string);
7607 if (current_user.user_name == 0)
7608 get_current_user_info ();
7609 temp = savestring (current_user.user_name);
7614 temp = savestring (current_host_name);
7615 if (c == 'h' && (t = (char *)strchr (temp, '.')))
7620 temp = itos (current_command_number);
7624 #if !defined (HISTORY)
7625 temp = savestring ("1");
7627 temp = itos (history_number ());
7628 #endif /* HISTORY */
7632 t = temp = (char *)xmalloc (3);
7633 if ((promptvars || posixly_correct) && (current_user.euid != 0))
7635 *t++ = current_user.euid == 0 ? '#' : '$';
7640 temp = itos (count_all_jobs ());
7644 #if defined (HAVE_TTYNAME)
7645 temp = (char *)ttyname (fileno (stdin));
7646 t = temp ? base_pathname (temp) : "tty";
7647 temp = savestring (t);
7649 temp = savestring ("tty");
7650 #endif /* !HAVE_TTYNAME */
7653 #if defined (READLINE)
7656 if (no_line_editing)
7661 temp = (char *)xmalloc (3);
7662 n = (c == '[') ? RL_PROMPT_START_IGNORE : RL_PROMPT_END_IGNORE;
7664 if (n == CTLESC || n == CTLNUL)
7669 #endif /* READLINE */
7675 temp = (char *)xmalloc (2);
7682 else /* (c == '\\') */
7689 temp = (char *)xmalloc (3);
7698 sub_append_string (temp, result, &result_index, &result_size);
7699 temp = (char *)NULL; /* Freed in sub_append_string (). */
7700 result[result_index] = '\0';
7706 RESIZE_MALLOCED_BUFFER (result, result_index, 3, result_size, PROMPT_GROWTH);
7707 result[result_index++] = c;
7708 result[result_index] = '\0';
7711 #else /* !PROMPT_STRING_DECODE */
7712 result = savestring (string);
7713 #endif /* !PROMPT_STRING_DECODE */
7715 /* Save the delimiter stack and point `dstack' to temp space so any
7716 command substitutions in the prompt string won't result in screwing
7717 up the parser's quoting state. */
7718 save_dstack = dstack;
7719 dstack = temp_dstack;
7720 dstack.delimiter_depth = 0;
7722 /* Perform variable and parameter expansion and command substitution on
7723 the prompt string. */
7724 if (promptvars || posixly_correct)
7726 last_exit_value = last_command_exit_value;
7727 last_comsub_pid = last_command_subst_pid;
7728 list = expand_prompt_string (result, Q_DOUBLE_QUOTES, 0);
7730 result = string_list (list);
7731 dispose_words (list);
7732 last_command_exit_value = last_exit_value;
7733 last_command_subst_pid = last_comsub_pid;
7737 t = dequote_string (result);
7742 dstack = save_dstack;
7747 /************************************************
7751 ************************************************/
7753 /* Report a syntax error, and restart the parser. Call here for fatal
7759 report_syntax_error ((char *)NULL);
7765 error_token_from_token (tok)
7770 if (t = find_token_in_alist (tok, word_token_alist, 0))
7773 if (t = find_token_in_alist (tok, other_token_alist, 0))
7777 /* This stuff is dicy and needs closer inspection */
7778 switch (current_token)
7781 case ASSIGNMENT_WORD:
7783 t = savestring (yylval.word->word);
7786 t = itos (yylval.number);
7789 if (yylval.word_list)
7790 t = string_list (yylval.word_list);
7792 case ARITH_FOR_EXPRS:
7793 if (yylval.word_list)
7794 t = string_list_internal (yylval.word_list, " ; ");
7797 t = (char *)NULL; /* punt */
7805 error_token_from_text ()
7810 t = shell_input_line;
7811 i = shell_input_line_index;
7815 if (i && t[i] == '\0')
7818 while (i && (whitespace (t[i]) || t[i] == '\n'))
7824 while (i && (member (t[i], " \n\t;|&") == 0))
7827 while (i != token_end && (whitespace (t[i]) || t[i] == '\n'))
7830 /* Return our idea of the offending token. */
7831 if (token_end || (i == 0 && token_end == 0))
7834 msg = substring (t, i, token_end);
7835 else /* one-character token */
7837 msg = (char *)xmalloc (2);
7847 print_offending_line ()
7852 msg = savestring (shell_input_line);
7853 token_end = strlen (msg);
7854 while (token_end && msg[token_end - 1] == '\n')
7855 msg[--token_end] = '\0';
7857 parser_error (line_number, "`%s'", msg);
7861 /* Report a syntax error with line numbers, etc.
7862 Call here for recoverable errors. If you have a message to print,
7863 then place it in MESSAGE, otherwise pass NULL and this will figure
7864 out an appropriate message for you. */
7866 report_syntax_error (message)
7873 parser_error (line_number, "%s", message);
7874 if (interactive && EOF_Reached)
7876 last_command_exit_value = parse_and_execute_level ? EX_BADSYNTAX : EX_BADUSAGE;
7880 /* If the line of input we're reading is not null, try to find the
7881 objectionable token. First, try to figure out what token the
7882 parser's complaining about by looking at current_token. */
7883 if (current_token != 0 && EOF_Reached == 0 && (msg = error_token_from_token (current_token)))
7885 if (ansic_shouldquote (msg))
7887 p = ansic_quote (msg, 0, NULL);
7891 parser_error (line_number, _("syntax error near unexpected token `%s'"), msg);
7894 if (interactive == 0)
7895 print_offending_line ();
7897 last_command_exit_value = parse_and_execute_level ? EX_BADSYNTAX : EX_BADUSAGE;
7901 /* If looking at the current token doesn't prove fruitful, try to find the
7902 offending token by analyzing the text of the input line near the current
7903 input line index and report what we find. */
7904 if (shell_input_line && *shell_input_line)
7906 msg = error_token_from_text ();
7909 parser_error (line_number, _("syntax error near `%s'"), msg);
7913 /* If not interactive, print the line containing the error. */
7914 if (interactive == 0)
7915 print_offending_line ();
7919 msg = EOF_Reached ? _("syntax error: unexpected end of file") : _("syntax error");
7920 parser_error (line_number, "%s", msg);
7921 /* When the shell is interactive, this file uses EOF_Reached
7922 only for error reporting. Other mechanisms are used to
7923 decide whether or not to exit. */
7924 if (interactive && EOF_Reached)
7928 last_command_exit_value = parse_and_execute_level ? EX_BADSYNTAX : EX_BADUSAGE;
7931 /* ??? Needed function. ??? We have to be able to discard the constructs
7932 created during parsing. In the case of error, we want to return
7933 allocated objects to the memory pool. In the case of no error, we want
7934 to throw away the information about where the allocated objects live.
7935 (dispose_command () will actually free the command.) */
7937 discard_parser_constructs (error_p)
7942 /************************************************
7946 ************************************************/
7948 /* Do that silly `type "bye" to exit' stuff. You know, "ignoreeof". */
7950 /* A flag denoting whether or not ignoreeof is set. */
7953 /* The number of times that we have encountered an EOF character without
7954 another character intervening. When this gets above the limit, the
7955 shell terminates. */
7956 int eof_encountered = 0;
7958 /* The limit for eof_encountered. */
7959 int eof_encountered_limit = 10;
7961 /* If we have EOF as the only input unit, this user wants to leave
7962 the shell. If the shell is not interactive, then just leave.
7963 Otherwise, if ignoreeof is set, and we haven't done this the
7964 required number of times in a row, print a message. */
7966 handle_eof_input_unit ()
7970 /* shell.c may use this to decide whether or not to write out the
7971 history, among other things. We use it only for error reporting
7976 /* If the user wants to "ignore" eof, then let her do so, kind of. */
7979 if (eof_encountered < eof_encountered_limit)
7981 fprintf (stderr, _("Use \"%s\" to leave the shell.\n"),
7982 login_shell ? "logout" : "exit");
7984 /* Reset the parsing state. */
7985 last_read_token = current_token = '\n';
7986 /* Reset the prompt string to be $PS1. */
7987 prompt_string_pointer = (char **)NULL;
7993 /* In this case EOF should exit the shell. Do it now. */
7995 exit_builtin ((WORD_LIST *)NULL);
7999 /* We don't write history files, etc., for non-interactive shells. */
8004 /************************************************
8006 * STRING PARSING FUNCTIONS *
8008 ************************************************/
8010 /* It's very important that these two functions treat the characters
8011 between ( and ) identically. */
8013 static WORD_LIST parse_string_error;
8015 /* Take a string and run it through the shell parser, returning the
8016 resultant word list. Used by compound array assignment. */
8018 parse_string_to_word_list (s, flags, whom)
8024 int tok, orig_current_token, orig_line_number, orig_input_terminator;
8025 int orig_line_count;
8026 int old_echo_input, old_expand_aliases;
8027 #if defined (HISTORY)
8028 int old_remember_on_history, old_history_expansion_inhibited;
8031 #if defined (HISTORY)
8032 old_remember_on_history = remember_on_history;
8033 # if defined (BANG_HISTORY)
8034 old_history_expansion_inhibited = history_expansion_inhibited;
8036 bash_history_disable ();
8039 orig_line_number = line_number;
8040 orig_line_count = current_command_line_count;
8041 orig_input_terminator = shell_input_line_terminator;
8042 old_echo_input = echo_input_at_read;
8043 old_expand_aliases = expand_aliases;
8046 last_read_token = WORD; /* WORD to allow reserved words here */
8047 current_command_line_count = 0;
8048 echo_input_at_read = expand_aliases = 0;
8050 with_input_from_string (s, whom);
8051 wl = (WORD_LIST *)NULL;
8054 parser_state |= PST_COMPASSIGN|PST_REPARSE;
8056 while ((tok = read_token (READ)) != yacc_EOF)
8058 if (tok == '\n' && *bash_input.location.string == '\0')
8060 if (tok == '\n') /* Allow newlines in compound assignments */
8062 if (tok != WORD && tok != ASSIGNMENT_WORD)
8064 line_number = orig_line_number + line_number - 1;
8065 orig_current_token = current_token;
8066 current_token = tok;
8067 yyerror (NULL); /* does the right thing */
8068 current_token = orig_current_token;
8071 wl = &parse_string_error;
8074 wl = make_word_list (yylval.word, wl);
8077 last_read_token = '\n';
8080 #if defined (HISTORY)
8081 remember_on_history = old_remember_on_history;
8082 # if defined (BANG_HISTORY)
8083 history_expansion_inhibited = old_history_expansion_inhibited;
8084 # endif /* BANG_HISTORY */
8085 #endif /* HISTORY */
8087 echo_input_at_read = old_echo_input;
8088 expand_aliases = old_expand_aliases;
8090 current_command_line_count = orig_line_count;
8091 shell_input_line_terminator = orig_input_terminator;
8094 parser_state &= ~(PST_COMPASSIGN|PST_REPARSE);
8096 if (wl == &parse_string_error)
8098 last_command_exit_value = EXECUTION_FAILURE;
8099 if (interactive_shell == 0 && posixly_correct)
8100 jump_to_top_level (FORCE_EOF);
8102 jump_to_top_level (DISCARD);
8105 return (REVERSE_LIST (wl, WORD_LIST *));
8109 parse_compound_assignment (retlenp)
8113 int tok, orig_line_number, orig_token_size, orig_last_token, assignok;
8114 char *saved_token, *ret;
8116 saved_token = token;
8117 orig_token_size = token_buffer_size;
8118 orig_line_number = line_number;
8119 orig_last_token = last_read_token;
8121 last_read_token = WORD; /* WORD to allow reserved words here */
8123 token = (char *)NULL;
8124 token_buffer_size = 0;
8126 assignok = parser_state&PST_ASSIGNOK; /* XXX */
8128 wl = (WORD_LIST *)NULL; /* ( */
8129 parser_state |= PST_COMPASSIGN;
8131 while ((tok = read_token (READ)) != ')')
8133 if (tok == '\n') /* Allow newlines in compound assignments */
8135 if (SHOULD_PROMPT ())
8139 if (tok != WORD && tok != ASSIGNMENT_WORD)
8141 current_token = tok; /* for error reporting */
8142 if (tok == yacc_EOF) /* ( */
8143 parser_error (orig_line_number, _("unexpected EOF while looking for matching `)'"));
8145 yyerror(NULL); /* does the right thing */
8148 wl = &parse_string_error;
8151 wl = make_word_list (yylval.word, wl);
8155 token = saved_token;
8156 token_buffer_size = orig_token_size;
8158 parser_state &= ~PST_COMPASSIGN;
8160 if (wl == &parse_string_error)
8162 last_command_exit_value = EXECUTION_FAILURE;
8163 last_read_token = '\n'; /* XXX */
8164 if (interactive_shell == 0 && posixly_correct)
8165 jump_to_top_level (FORCE_EOF);
8167 jump_to_top_level (DISCARD);
8170 last_read_token = orig_last_token; /* XXX - was WORD? */
8174 rl = REVERSE_LIST (wl, WORD_LIST *);
8175 ret = string_list (rl);
8182 *retlenp = (ret && *ret) ? strlen (ret) : 0;
8185 parser_state |= PST_ASSIGNOK;
8190 /************************************************
8192 * SAVING AND RESTORING PARTIAL PARSE STATE *
8194 ************************************************/
8197 save_parser_state (ps)
8198 sh_parser_state_t *ps;
8201 ps = (sh_parser_state_t *)xmalloc (sizeof (sh_parser_state_t));
8203 return ((sh_parser_state_t *)NULL);
8205 ps->parser_state = parser_state;
8206 ps->token_state = save_token_state ();
8208 ps->input_line_terminator = shell_input_line_terminator;
8209 ps->eof_encountered = eof_encountered;
8211 ps->prompt_string_pointer = prompt_string_pointer;
8213 ps->current_command_line_count = current_command_line_count;
8215 #if defined (HISTORY)
8216 ps->remember_on_history = remember_on_history;
8217 # if defined (BANG_HISTORY)
8218 ps->history_expansion_inhibited = history_expansion_inhibited;
8222 ps->last_command_exit_value = last_command_exit_value;
8223 #if defined (ARRAY_VARS)
8224 ps->pipestatus = save_pipestatus_array ();
8227 ps->last_shell_builtin = last_shell_builtin;
8228 ps->this_shell_builtin = this_shell_builtin;
8230 ps->expand_aliases = expand_aliases;
8231 ps->echo_input_at_read = echo_input_at_read;
8234 ps->token_buffer_size = token_buffer_size;
8235 /* Force reallocation on next call to read_token_word */
8237 token_buffer_size = 0;
8243 restore_parser_state (ps)
8244 sh_parser_state_t *ps;
8249 parser_state = ps->parser_state;
8250 if (ps->token_state)
8252 restore_token_state (ps->token_state);
8253 free (ps->token_state);
8256 shell_input_line_terminator = ps->input_line_terminator;
8257 eof_encountered = ps->eof_encountered;
8259 prompt_string_pointer = ps->prompt_string_pointer;
8261 current_command_line_count = ps->current_command_line_count;
8263 #if defined (HISTORY)
8264 remember_on_history = ps->remember_on_history;
8265 # if defined (BANG_HISTORY)
8266 history_expansion_inhibited = ps->history_expansion_inhibited;
8270 last_command_exit_value = ps->last_command_exit_value;
8271 #if defined (ARRAY_VARS)
8272 restore_pipestatus_array (ps->pipestatus);
8275 last_shell_builtin = ps->last_shell_builtin;
8276 this_shell_builtin = ps->this_shell_builtin;
8278 expand_aliases = ps->expand_aliases;
8279 echo_input_at_read = ps->echo_input_at_read;
8283 token_buffer_size = ps->token_buffer_size;
8286 sh_input_line_state_t *
8287 save_input_line_state (ls)
8288 sh_input_line_state_t *ls;
8291 ls = (sh_input_line_state_t *)xmalloc (sizeof (sh_input_line_state_t));
8293 return ((sh_input_line_state_t *)NULL);
8295 ls->input_line = shell_input_line;
8296 ls->input_line_size = shell_input_line_size;
8297 ls->input_line_len = shell_input_line_len;
8298 ls->input_line_index = shell_input_line_index;
8300 /* force reallocation */
8301 shell_input_line = 0;
8302 shell_input_line_size = shell_input_line_len = shell_input_line_index = 0;
8306 restore_input_line_state (ls)
8307 sh_input_line_state_t *ls;
8309 FREE (shell_input_line);
8310 shell_input_line = ls->input_line;
8311 shell_input_line_size = ls->input_line_size;
8312 shell_input_line_len = ls->input_line_len;
8313 shell_input_line_index = ls->input_line_index;
8315 set_line_mbstate ();
8318 /************************************************
8320 * MULTIBYTE CHARACTER HANDLING *
8322 ************************************************/
8324 #if defined (HANDLE_MULTIBYTE)
8328 int i, previ, len, c;
8329 mbstate_t mbs, prevs;
8332 if (shell_input_line == NULL)
8334 len = strlen (shell_input_line); /* XXX - shell_input_line_len ? */
8335 FREE (shell_input_line_property);
8336 shell_input_line_property = (char *)xmalloc (len + 1);
8338 memset (&prevs, '\0', sizeof (mbstate_t));
8339 for (i = previ = 0; i < len; i++)
8343 c = shell_input_line[i];
8347 for (j = i; j < len; j++)
8348 shell_input_line_property[j] = 1;
8352 mbclen = mbrlen (shell_input_line + previ, i - previ + 1, &mbs);
8353 if (mbclen == 1 || mbclen == (size_t)-1)
8358 else if (mbclen == (size_t)-2)
8360 else if (mbclen > 1)
8368 /* XXX - what to do if mbrlen returns 0? (null wide character) */
8370 for (j = i; j < len; j++)
8371 shell_input_line_property[j] = 1;
8375 shell_input_line_property[i] = mbclen;
8378 #endif /* HANDLE_MULTIBYTE */