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/homes/chet/src/bash/src/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 */
199 #include "typemax.h" /* SIZE_MAX if needed */
203 #include "mailcheck.h"
205 #include "builtins.h"
206 #include "builtins/common.h"
207 #include "builtins/builtext.h"
209 #include "shmbutil.h"
211 #if defined (READLINE)
212 # include "bashline.h"
213 # include <readline/readline.h>
214 #endif /* READLINE */
216 #if defined (HISTORY)
217 # include "bashhist.h"
218 # include <readline/history.h>
221 #if defined (JOB_CONTROL)
223 #endif /* JOB_CONTROL */
228 typedef void *alias_t;
231 #if defined (PROMPT_STRING_DECODE)
233 # include <sys/param.h>
236 # if defined (TM_IN_SYS_TIME)
237 # include <sys/types.h>
238 # include <sys/time.h>
239 # endif /* TM_IN_SYS_TIME */
240 # include "maxpath.h"
241 #endif /* PROMPT_STRING_DECODE */
243 #define RE_READ_TOKEN -99
244 #define NO_EXPANSION -100
252 #if defined (HANDLE_MULTIBYTE)
253 # define last_shell_getc_is_singlebyte \
254 ((shell_input_line_index > 1) \
255 ? shell_input_line_property[shell_input_line_index - 1] \
257 # define MBTEST(x) ((x) && last_shell_getc_is_singlebyte)
259 # define last_shell_getc_is_singlebyte 1
260 # define MBTEST(x) ((x))
263 #if defined (EXTENDED_GLOB)
264 extern int extended_glob;
267 extern int eof_encountered;
268 extern int no_line_editing, running_under_emacs;
269 extern int current_command_number;
270 extern int sourcelevel, parse_and_execute_level;
271 extern int posixly_correct;
272 extern int last_command_exit_value;
273 extern pid_t last_command_subst_pid;
274 extern char *shell_name, *current_host_name;
275 extern char *dist_version;
276 extern int patch_level;
277 extern int dump_translatable_strings, dump_po_strings;
278 extern sh_builtin_func_t *last_shell_builtin, *this_shell_builtin;
279 #if defined (BUFFERED_INPUT)
280 extern int bash_input_fd_changed;
284 /* **************************************************************** */
286 /* "Forward" declarations */
288 /* **************************************************************** */
291 static void debug_parser __P((int));
294 static int yy_getc __P((void));
295 static int yy_ungetc __P((int));
297 #if defined (READLINE)
298 static int yy_readline_get __P((void));
299 static int yy_readline_unget __P((int));
302 static int yy_string_get __P((void));
303 static int yy_string_unget __P((int));
304 static void rewind_input_string __P((void));
305 static int yy_stream_get __P((void));
306 static int yy_stream_unget __P((int));
308 static int shell_getc __P((int));
309 static void shell_ungetc __P((int));
310 static void discard_until __P((int));
312 #if defined (ALIAS) || defined (DPAREN_ARITHMETIC)
313 static void push_string __P((char *, int, alias_t *));
314 static void pop_string __P((void));
315 static void free_string_list __P((void));
318 static char *read_a_line __P((int));
320 static int reserved_word_acceptable __P((int));
321 static int yylex __P((void));
322 static int alias_expand_token __P((char *));
323 static int time_command_acceptable __P((void));
324 static int special_case_tokens __P((char *));
325 static int read_token __P((int));
326 static char *parse_matched_pair __P((int, int, int, int *, int));
327 static char *parse_comsub __P((int, int, int, int *, int));
328 #if defined (ARRAY_VARS)
329 static char *parse_compound_assignment __P((int *));
331 #if defined (DPAREN_ARITHMETIC) || defined (ARITH_FOR_COMMAND)
332 static int parse_dparen __P((int));
333 static int parse_arith_cmd __P((char **, int));
335 #if defined (COND_COMMAND)
336 static void cond_error __P((void));
337 static COND_COM *cond_expr __P((void));
338 static COND_COM *cond_or __P((void));
339 static COND_COM *cond_and __P((void));
340 static COND_COM *cond_term __P((void));
341 static int cond_skip_newlines __P((void));
342 static COMMAND *parse_cond_command __P((void));
344 #if defined (ARRAY_VARS)
345 static int token_is_assignment __P((char *, int));
346 static int token_is_ident __P((char *, int));
348 static int read_token_word __P((int));
349 static void discard_parser_constructs __P((int));
351 static char *error_token_from_token __P((int));
352 static char *error_token_from_text __P((void));
353 static void print_offending_line __P((void));
354 static void report_syntax_error __P((char *));
356 static void handle_eof_input_unit __P((void));
357 static void prompt_again __P((void));
359 static void reset_readline_prompt __P((void));
361 static void print_prompt __P((void));
363 #if defined (HANDLE_MULTIBYTE)
364 static void set_line_mbstate __P((void));
365 static char *shell_input_line_property = NULL;
367 # define set_line_mbstate()
370 extern int yyerror __P((const char *));
376 /* Default prompt strings */
377 char *primary_prompt = PPROMPT;
378 char *secondary_prompt = SPROMPT;
380 /* PROMPT_STRING_POINTER points to one of these, never to an actual string. */
381 char *ps1_prompt, *ps2_prompt;
383 /* Handle on the current prompt string. Indirectly points through
384 ps1_ or ps2_prompt. */
385 char **prompt_string_pointer = (char **)NULL;
386 char *current_prompt_string;
388 /* Non-zero means we expand aliases in commands. */
389 int expand_aliases = 0;
391 /* If non-zero, the decoded prompt string undergoes parameter and
392 variable substitution, command substitution, arithmetic substitution,
393 string expansion, process substitution, and quote removal in
394 decode_prompt_string. */
397 /* If non-zero, $'...' and $"..." are expanded when they appear within
398 a ${...} expansion, even when the expansion appears within double
400 int extended_quote = 1;
402 /* The number of lines read from input while creating the current command. */
403 int current_command_line_count;
405 /* The number of lines in a command saved while we run parse_and_execute */
406 int saved_command_line_count;
408 /* The token that currently denotes the end of parse. */
411 /* The token currently being read. */
414 /* The current parser state. */
417 /* Variables to manage the task of reading here documents, because we need to
418 defer the reading until after a complete command has been collected. */
419 static REDIRECT *redir_stack[10];
422 /* Where shell input comes from. History expansion is performed on each
423 line when the shell is interactive. */
424 static char *shell_input_line = (char *)NULL;
425 static size_t shell_input_line_index;
426 static size_t shell_input_line_size; /* Amount allocated for shell_input_line. */
427 static size_t shell_input_line_len; /* strlen (shell_input_line) */
429 /* Either zero or EOF. */
430 static int shell_input_line_terminator;
432 /* The line number in a script on which a function definition starts. */
433 static int function_dstart;
435 /* The line number in a script on which a function body starts. */
436 static int function_bstart;
438 /* The line number in a script at which an arithmetic for command starts. */
439 static int arith_for_lineno;
441 /* The decoded prompt string. Used if READLINE is not defined or if
442 editing is turned off. Analogous to current_readline_prompt. */
443 static char *current_decoded_prompt;
445 /* The last read token, or NULL. read_token () uses this for context
447 static int last_read_token;
449 /* The token read prior to last_read_token. */
450 static int token_before_that;
452 /* The token read prior to token_before_that. */
453 static int two_tokens_ago;
455 static int global_extglob;
457 /* The line number in a script where the word in a `case WORD', `select WORD'
458 or `for WORD' begins. This is a nested command maximum, since the array
459 index is decremented after a case, select, or for command is parsed. */
460 #define MAX_CASE_NEST 128
461 static int word_lineno[MAX_CASE_NEST];
462 static int word_top = -1;
464 /* If non-zero, it is the token that we want read_token to return
465 regardless of what text is (or isn't) present to be read. This
466 is reset by read_token. If token_to_read == WORD or
467 ASSIGNMENT_WORD, yylval.word should be set to word_desc_to_read. */
468 static int token_to_read;
469 static WORD_DESC *word_desc_to_read;
471 static REDIRECTEE source;
472 static REDIRECTEE redir;
475 /* Enabling traces. */
480 /* Enabling verbose error messages. */
481 #ifdef YYERROR_VERBOSE
482 # undef YYERROR_VERBOSE
483 # define YYERROR_VERBOSE 1
485 # define YYERROR_VERBOSE 0
488 /* Enabling the token table. */
489 #ifndef YYTOKEN_TABLE
490 # define YYTOKEN_TABLE 0
493 #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
494 typedef union YYSTYPE
495 #line 324 "/usr/homes/chet/src/bash/src/parse.y"
497 WORD_DESC *word; /* the word that we read. */
498 int number; /* the number that we read. */
499 WORD_LIST *word_list;
503 PATTERN_LIST *pattern;
505 /* Line 193 of yacc.c. */
508 # define yystype YYSTYPE /* obsolescent; will be withdrawn */
509 # define YYSTYPE_IS_DECLARED 1
510 # define YYSTYPE_IS_TRIVIAL 1
515 /* Copy the second part of user declarations. */
518 /* Line 216 of yacc.c. */
526 typedef YYTYPE_UINT8 yytype_uint8;
528 typedef unsigned char yytype_uint8;
532 typedef YYTYPE_INT8 yytype_int8;
533 #elif (defined __STDC__ || defined __C99__FUNC__ \
534 || defined __cplusplus || defined _MSC_VER)
535 typedef signed char yytype_int8;
537 typedef short int yytype_int8;
541 typedef YYTYPE_UINT16 yytype_uint16;
543 typedef unsigned short int yytype_uint16;
547 typedef YYTYPE_INT16 yytype_int16;
549 typedef short int yytype_int16;
553 # ifdef __SIZE_TYPE__
554 # define YYSIZE_T __SIZE_TYPE__
555 # elif defined size_t
556 # define YYSIZE_T size_t
557 # elif ! defined YYSIZE_T && (defined __STDC__ || defined __C99__FUNC__ \
558 || defined __cplusplus || defined _MSC_VER)
559 # include <stddef.h> /* INFRINGES ON USER NAME SPACE */
560 # define YYSIZE_T size_t
562 # define YYSIZE_T unsigned int
566 #define YYSIZE_MAXIMUM ((YYSIZE_T) -1)
569 # if defined YYENABLE_NLS && YYENABLE_NLS
571 # include <libintl.h> /* INFRINGES ON USER NAME SPACE */
572 # define YY_(msgid) dgettext ("bison-runtime", msgid)
576 # define YY_(msgid) msgid
580 /* Suppress unused-variable warnings by "using" E. */
581 #if ! defined lint || defined __GNUC__
582 # define YYUSE(e) ((void) (e))
584 # define YYUSE(e) /* empty */
587 /* Identity function, used to suppress warnings about constant conditions. */
591 #if (defined __STDC__ || defined __C99__FUNC__ \
592 || defined __cplusplus || defined _MSC_VER)
605 #if ! defined yyoverflow || YYERROR_VERBOSE
607 /* The parser invokes alloca or malloc; define the necessary symbols. */
609 # ifdef YYSTACK_USE_ALLOCA
610 # if YYSTACK_USE_ALLOCA
612 # define YYSTACK_ALLOC __builtin_alloca
613 # elif defined __BUILTIN_VA_ARG_INCR
614 # include <alloca.h> /* INFRINGES ON USER NAME SPACE */
616 # define YYSTACK_ALLOC __alloca
617 # elif defined _MSC_VER
618 # include <malloc.h> /* INFRINGES ON USER NAME SPACE */
619 # define alloca _alloca
621 # define YYSTACK_ALLOC alloca
622 # if ! defined _ALLOCA_H && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
623 || defined __cplusplus || defined _MSC_VER)
624 # include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
633 # ifdef YYSTACK_ALLOC
634 /* Pacify GCC's `empty if-body' warning. */
635 # define YYSTACK_FREE(Ptr) do { /* empty */; } while (YYID (0))
636 # ifndef YYSTACK_ALLOC_MAXIMUM
637 /* The OS might guarantee only one guard page at the bottom of the stack,
638 and a page size can be as small as 4096 bytes. So we cannot safely
639 invoke alloca (N) if N exceeds 4096. Use a slightly smaller number
640 to allow for a few compiler-allocated temporary stack slots. */
641 # define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */
644 # define YYSTACK_ALLOC YYMALLOC
645 # define YYSTACK_FREE YYFREE
646 # ifndef YYSTACK_ALLOC_MAXIMUM
647 # define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM
649 # if (defined __cplusplus && ! defined _STDLIB_H \
650 && ! ((defined YYMALLOC || defined malloc) \
651 && (defined YYFREE || defined free)))
652 # include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
658 # define YYMALLOC malloc
659 # if ! defined malloc && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
660 || defined __cplusplus || defined _MSC_VER)
661 void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */
666 # if ! defined free && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
667 || defined __cplusplus || defined _MSC_VER)
668 void free (void *); /* INFRINGES ON USER NAME SPACE */
672 #endif /* ! defined yyoverflow || YYERROR_VERBOSE */
675 #if (! defined yyoverflow \
676 && (! defined __cplusplus \
677 || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
679 /* A type that is properly aligned for any stack member. */
686 /* The size of the maximum gap between one aligned stack and the next. */
687 # define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1)
689 /* The size of an array large to enough to hold all stacks, each with
691 # define YYSTACK_BYTES(N) \
692 ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE)) \
693 + YYSTACK_GAP_MAXIMUM)
695 /* Copy COUNT objects from FROM to TO. The source and destination do
698 # if defined __GNUC__ && 1 < __GNUC__
699 # define YYCOPY(To, From, Count) \
700 __builtin_memcpy (To, From, (Count) * sizeof (*(From)))
702 # define YYCOPY(To, From, Count) \
706 for (yyi = 0; yyi < (Count); yyi++) \
707 (To)[yyi] = (From)[yyi]; \
713 /* Relocate STACK from its old location to the new one. The
714 local variables YYSIZE and YYSTACKSIZE give the old and new number of
715 elements in the stack, and YYPTR gives the new location of the
716 stack. Advance YYPTR to a properly aligned location for the next
718 # define YYSTACK_RELOCATE(Stack) \
721 YYSIZE_T yynewbytes; \
722 YYCOPY (&yyptr->Stack, Stack, yysize); \
723 Stack = &yyptr->Stack; \
724 yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \
725 yyptr += yynewbytes / sizeof (*yyptr); \
731 /* YYFINAL -- State number of the termination state. */
733 /* YYLAST -- Last index in YYTABLE. */
736 /* YYNTOKENS -- Number of terminals. */
738 /* YYNNTS -- Number of nonterminals. */
740 /* YYNRULES -- Number of rules. */
742 /* YYNRULES -- Number of states. */
743 #define YYNSTATES 342
745 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
747 #define YYMAXUTOK 304
749 #define YYTRANSLATE(YYX) \
750 ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
752 /* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */
753 static const yytype_uint8 yytranslate[] =
755 0, 2, 2, 2, 2, 2, 2, 2, 2, 2,
756 51, 2, 2, 2, 2, 2, 2, 2, 2, 2,
757 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
758 2, 2, 2, 2, 2, 2, 2, 2, 49, 2,
759 59, 60, 2, 2, 2, 56, 2, 2, 2, 2,
760 2, 2, 2, 2, 2, 2, 2, 2, 2, 50,
761 55, 2, 54, 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, 2, 2, 2, 2, 2, 2, 2,
767 2, 2, 2, 57, 53, 58, 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, 2, 2, 2, 2,
780 2, 2, 2, 2, 2, 2, 1, 2, 3, 4,
781 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
782 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
783 25, 26, 27, 28, 29, 30, 31, 32, 33, 34,
784 35, 36, 37, 38, 39, 40, 41, 42, 43, 44,
789 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
791 static const yytype_uint16 yyprhs[] =
793 0, 0, 3, 6, 8, 11, 13, 15, 18, 21,
794 24, 28, 32, 36, 40, 43, 47, 51, 54, 58,
795 62, 65, 69, 73, 76, 80, 84, 87, 91, 95,
796 98, 102, 106, 109, 113, 117, 120, 124, 128, 131,
797 135, 139, 142, 146, 150, 153, 157, 161, 164, 168,
798 172, 175, 178, 180, 182, 184, 186, 189, 191, 194,
799 196, 198, 201, 203, 205, 207, 209, 215, 221, 223,
800 225, 227, 229, 231, 233, 235, 242, 249, 257, 265,
801 276, 287, 297, 307, 315, 323, 329, 335, 342, 349,
802 357, 365, 376, 387, 394, 402, 409, 415, 422, 427,
803 429, 432, 436, 439, 443, 447, 452, 455, 461, 469,
804 476, 480, 482, 486, 491, 498, 504, 506, 509, 514,
805 519, 525, 531, 534, 538, 541, 545, 548, 552, 554,
806 558, 561, 563, 566, 570, 574, 578, 583, 588, 593,
807 598, 603, 605, 607, 609, 611, 613, 615, 616, 619,
808 621, 624, 627, 632, 637, 641, 645, 647, 649, 652,
809 655, 658, 661, 666, 671, 673, 675, 678
812 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
813 static const yytype_int8 yyrhs[] =
815 62, 0, -1, 94, 91, -1, 51, -1, 1, 51,
816 -1, 52, -1, 26, -1, 63, 26, -1, 54, 26,
817 -1, 55, 26, -1, 29, 54, 26, -1, 29, 55,
818 26, -1, 28, 54, 26, -1, 28, 55, 26, -1,
819 35, 26, -1, 29, 35, 26, -1, 28, 35, 26,
820 -1, 47, 26, -1, 29, 47, 26, -1, 28, 47,
821 26, -1, 46, 26, -1, 29, 46, 26, -1, 28,
822 46, 26, -1, 36, 26, -1, 29, 36, 26, -1,
823 28, 36, 26, -1, 43, 26, -1, 29, 43, 26,
824 -1, 28, 43, 26, -1, 38, 26, -1, 29, 38,
825 26, -1, 28, 38, 26, -1, 37, 29, -1, 29,
826 37, 29, -1, 28, 37, 29, -1, 39, 29, -1,
827 29, 39, 29, -1, 28, 39, 29, -1, 37, 26,
828 -1, 29, 37, 26, -1, 28, 37, 26, -1, 39,
829 26, -1, 29, 39, 26, -1, 28, 39, 26, -1,
830 39, 56, -1, 29, 39, 56, -1, 28, 39, 56,
831 -1, 37, 56, -1, 29, 37, 56, -1, 28, 37,
832 56, -1, 44, 26, -1, 45, 26, -1, 26, -1,
833 27, -1, 64, -1, 64, -1, 66, 64, -1, 65,
834 -1, 67, 65, -1, 67, -1, 69, -1, 69, 66,
835 -1, 74, -1, 77, -1, 70, -1, 73, -1, 12,
836 88, 14, 88, 15, -1, 13, 88, 14, 88, 15,
837 -1, 72, -1, 78, -1, 76, -1, 79, -1, 80,
838 -1, 81, -1, 71, -1, 10, 26, 93, 14, 88,
839 15, -1, 10, 26, 93, 57, 88, 58, -1, 10,
840 26, 50, 93, 14, 88, 15, -1, 10, 26, 50,
841 93, 57, 88, 58, -1, 10, 26, 93, 21, 63,
842 92, 93, 14, 88, 15, -1, 10, 26, 93, 21,
843 63, 92, 93, 57, 88, 58, -1, 10, 26, 93,
844 21, 92, 93, 14, 88, 15, -1, 10, 26, 93,
845 21, 92, 93, 57, 88, 58, -1, 10, 31, 92,
846 93, 14, 88, 15, -1, 10, 31, 92, 93, 57,
847 88, 58, -1, 10, 31, 14, 88, 15, -1, 10,
848 31, 57, 88, 58, -1, 11, 26, 93, 14, 87,
849 15, -1, 11, 26, 93, 57, 87, 58, -1, 11,
850 26, 50, 93, 14, 87, 15, -1, 11, 26, 50,
851 93, 57, 87, 58, -1, 11, 26, 93, 21, 63,
852 92, 93, 14, 87, 15, -1, 11, 26, 93, 21,
853 63, 92, 93, 57, 87, 58, -1, 8, 26, 93,
854 21, 93, 9, -1, 8, 26, 93, 21, 85, 93,
855 9, -1, 8, 26, 93, 21, 83, 9, -1, 26,
856 59, 60, 93, 75, -1, 16, 26, 59, 60, 93,
857 75, -1, 16, 26, 93, 75, -1, 69, -1, 69,
858 66, -1, 59, 88, 60, -1, 17, 69, -1, 17,
859 69, 66, -1, 17, 26, 69, -1, 17, 26, 69,
860 66, -1, 17, 67, -1, 3, 88, 4, 88, 7,
861 -1, 3, 88, 4, 88, 5, 88, 7, -1, 3,
862 88, 4, 88, 82, 7, -1, 57, 88, 58, -1,
863 30, -1, 18, 32, 19, -1, 6, 88, 4, 88,
864 -1, 6, 88, 4, 88, 5, 88, -1, 6, 88,
865 4, 88, 82, -1, 84, -1, 85, 84, -1, 93,
866 86, 60, 88, -1, 93, 86, 60, 93, -1, 93,
867 59, 86, 60, 88, -1, 93, 59, 86, 60, 93,
868 -1, 84, 40, -1, 85, 84, 40, -1, 84, 41,
869 -1, 85, 84, 41, -1, 84, 42, -1, 85, 84,
870 42, -1, 26, -1, 86, 53, 26, -1, 93, 89,
871 -1, 87, -1, 93, 90, -1, 90, 51, 93, -1,
872 90, 49, 93, -1, 90, 50, 93, -1, 90, 33,
873 93, 90, -1, 90, 34, 93, 90, -1, 90, 49,
874 93, 90, -1, 90, 50, 93, 90, -1, 90, 51,
875 93, 90, -1, 96, -1, 51, -1, 52, -1, 51,
876 -1, 50, -1, 52, -1, -1, 93, 51, -1, 95,
877 -1, 95, 49, -1, 95, 50, -1, 95, 33, 93,
878 95, -1, 95, 34, 93, 95, -1, 95, 49, 95,
879 -1, 95, 50, 95, -1, 96, -1, 97, -1, 22,
880 96, -1, 98, 96, -1, 98, 92, -1, 22, 92,
881 -1, 97, 53, 93, 97, -1, 97, 48, 93, 97,
882 -1, 68, -1, 23, -1, 23, 24, -1, 23, 24,
886 /* YYRLINE[YYN] -- source line where rule number YYN was defined. */
887 static const yytype_uint16 yyrline[] =
889 0, 377, 377, 388, 397, 412, 422, 424, 428, 434,
890 440, 446, 452, 458, 464, 470, 476, 482, 488, 494,
891 500, 506, 512, 518, 525, 532, 539, 546, 553, 560,
892 566, 572, 578, 584, 590, 596, 602, 608, 614, 620,
893 626, 632, 638, 644, 650, 656, 662, 668, 674, 680,
894 686, 692, 700, 702, 704, 708, 712, 723, 725, 729,
895 731, 733, 749, 751, 755, 757, 759, 761, 763, 765,
896 767, 769, 771, 773, 775, 779, 784, 789, 794, 799,
897 804, 809, 814, 821, 826, 831, 836, 843, 848, 853,
898 858, 863, 868, 875, 880, 885, 892, 895, 898, 902,
899 904, 935, 942, 947, 964, 969, 986, 993, 995, 997,
900 1002, 1006, 1010, 1014, 1016, 1018, 1022, 1023, 1027, 1029,
901 1031, 1033, 1037, 1039, 1041, 1043, 1045, 1047, 1051, 1053,
902 1062, 1070, 1071, 1077, 1078, 1085, 1089, 1091, 1093, 1100,
903 1102, 1104, 1108, 1109, 1112, 1114, 1116, 1120, 1121, 1130,
904 1143, 1159, 1174, 1176, 1178, 1185, 1188, 1192, 1194, 1200,
905 1206, 1223, 1243, 1245, 1268, 1272, 1274, 1276
909 #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
910 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
911 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
912 static const char *const yytname[] =
914 "$end", "error", "$undefined", "IF", "THEN", "ELSE", "ELIF", "FI",
915 "CASE", "ESAC", "FOR", "SELECT", "WHILE", "UNTIL", "DO", "DONE",
916 "FUNCTION", "COPROC", "COND_START", "COND_END", "COND_ERROR", "IN",
917 "BANG", "TIME", "TIMEOPT", "TIMEIGN", "WORD", "ASSIGNMENT_WORD",
918 "REDIR_WORD", "NUMBER", "ARITH_CMD", "ARITH_FOR_EXPRS", "COND_CMD",
919 "AND_AND", "OR_OR", "GREATER_GREATER", "LESS_LESS", "LESS_AND",
920 "LESS_LESS_LESS", "GREATER_AND", "SEMI_SEMI", "SEMI_AND",
921 "SEMI_SEMI_AND", "LESS_LESS_MINUS", "AND_GREATER", "AND_GREATER_GREATER",
922 "LESS_GREATER", "GREATER_BAR", "BAR_AND", "'&'", "';'", "'\\n'",
923 "yacc_EOF", "'|'", "'>'", "'<'", "'-'", "'{'", "'}'", "'('", "')'",
924 "$accept", "inputunit", "word_list", "redirection",
925 "simple_command_element", "redirection_list", "simple_command",
926 "command", "shell_command", "for_command", "arith_for_command",
927 "select_command", "case_command", "function_def", "function_body",
928 "subshell", "coproc", "if_command", "group_command", "arith_command",
929 "cond_command", "elif_clause", "case_clause", "pattern_list",
930 "case_clause_sequence", "pattern", "list", "compound_list", "list0",
931 "list1", "simple_list_terminator", "list_terminator", "newline_list",
932 "simple_list", "simple_list1", "pipeline_command", "pipeline",
938 /* YYTOKNUM[YYLEX-NUM] -- Internal token number corresponding to
940 static const yytype_uint16 yytoknum[] =
942 0, 256, 257, 258, 259, 260, 261, 262, 263, 264,
943 265, 266, 267, 268, 269, 270, 271, 272, 273, 274,
944 275, 276, 277, 278, 279, 280, 281, 282, 283, 284,
945 285, 286, 287, 288, 289, 290, 291, 292, 293, 294,
946 295, 296, 297, 298, 299, 300, 301, 302, 303, 38,
947 59, 10, 304, 124, 62, 60, 45, 123, 125, 40,
952 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
953 static const yytype_uint8 yyr1[] =
955 0, 61, 62, 62, 62, 62, 63, 63, 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, 64, 64, 64, 64, 64, 64, 64, 64,
960 64, 64, 65, 65, 65, 66, 66, 67, 67, 68,
961 68, 68, 68, 68, 69, 69, 69, 69, 69, 69,
962 69, 69, 69, 69, 69, 70, 70, 70, 70, 70,
963 70, 70, 70, 71, 71, 71, 71, 72, 72, 72,
964 72, 72, 72, 73, 73, 73, 74, 74, 74, 75,
965 75, 76, 77, 77, 77, 77, 77, 78, 78, 78,
966 79, 80, 81, 82, 82, 82, 83, 83, 84, 84,
967 84, 84, 85, 85, 85, 85, 85, 85, 86, 86,
968 87, 88, 88, 89, 89, 89, 90, 90, 90, 90,
969 90, 90, 91, 91, 92, 92, 92, 93, 93, 94,
970 94, 94, 95, 95, 95, 95, 95, 96, 96, 96,
971 96, 96, 97, 97, 97, 98, 98, 98
974 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
975 static const yytype_uint8 yyr2[] =
977 0, 2, 2, 1, 2, 1, 1, 2, 2, 2,
978 3, 3, 3, 3, 2, 3, 3, 2, 3, 3,
979 2, 3, 3, 2, 3, 3, 2, 3, 3, 2,
980 3, 3, 2, 3, 3, 2, 3, 3, 2, 3,
981 3, 2, 3, 3, 2, 3, 3, 2, 3, 3,
982 2, 2, 1, 1, 1, 1, 2, 1, 2, 1,
983 1, 2, 1, 1, 1, 1, 5, 5, 1, 1,
984 1, 1, 1, 1, 1, 6, 6, 7, 7, 10,
985 10, 9, 9, 7, 7, 5, 5, 6, 6, 7,
986 7, 10, 10, 6, 7, 6, 5, 6, 4, 1,
987 2, 3, 2, 3, 3, 4, 2, 5, 7, 6,
988 3, 1, 3, 4, 6, 5, 1, 2, 4, 4,
989 5, 5, 2, 3, 2, 3, 2, 3, 1, 3,
990 2, 1, 2, 3, 3, 3, 4, 4, 4, 4,
991 4, 1, 1, 1, 1, 1, 1, 0, 2, 1,
992 2, 2, 4, 4, 3, 3, 1, 1, 2, 2,
993 2, 2, 4, 4, 1, 1, 2, 3
996 /* YYDEFACT[STATE-NAME] -- Default rule to reduce with in state
997 STATE-NUM when YYTABLE doesn't specify something else to do. Zero
998 means the default is an error. */
999 static const yytype_uint8 yydefact[] =
1001 0, 0, 147, 0, 0, 0, 147, 147, 0, 0,
1002 0, 0, 165, 52, 53, 0, 0, 111, 0, 0,
1003 0, 0, 0, 0, 0, 0, 0, 0, 3, 5,
1004 0, 0, 147, 147, 0, 54, 57, 59, 164, 60,
1005 64, 74, 68, 65, 62, 70, 63, 69, 71, 72,
1006 73, 0, 149, 156, 157, 0, 4, 131, 0, 0,
1007 147, 147, 0, 147, 0, 0, 147, 52, 106, 102,
1008 0, 145, 144, 146, 161, 158, 166, 0, 0, 0,
1009 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1010 0, 0, 0, 0, 0, 0, 0, 0, 14, 23,
1011 38, 32, 47, 29, 41, 35, 44, 26, 50, 51,
1012 20, 17, 8, 9, 0, 0, 1, 52, 58, 55,
1013 61, 142, 143, 2, 147, 147, 150, 151, 147, 147,
1014 160, 159, 147, 148, 130, 132, 141, 0, 147, 0,
1015 147, 147, 147, 147, 0, 147, 147, 0, 0, 104,
1016 103, 112, 167, 147, 16, 25, 40, 34, 49, 31,
1017 43, 37, 46, 28, 22, 19, 12, 13, 15, 24,
1018 39, 33, 48, 30, 42, 36, 45, 27, 21, 18,
1019 10, 11, 110, 101, 56, 0, 0, 154, 155, 0,
1020 0, 0, 147, 147, 147, 147, 147, 147, 0, 147,
1021 0, 147, 0, 0, 0, 0, 147, 0, 147, 0,
1022 0, 147, 99, 98, 105, 0, 152, 153, 0, 0,
1023 163, 162, 147, 147, 107, 0, 0, 0, 134, 135,
1024 133, 0, 116, 147, 0, 147, 147, 0, 6, 0,
1025 147, 0, 85, 86, 147, 147, 147, 147, 0, 0,
1026 0, 0, 66, 67, 0, 100, 96, 0, 0, 109,
1027 136, 137, 138, 139, 140, 95, 122, 124, 126, 117,
1028 0, 93, 128, 0, 0, 0, 0, 75, 7, 147,
1029 0, 76, 0, 0, 0, 0, 87, 0, 147, 88,
1030 97, 108, 147, 147, 147, 147, 123, 125, 127, 94,
1031 0, 0, 147, 77, 78, 0, 147, 147, 83, 84,
1032 89, 90, 0, 113, 0, 0, 0, 147, 129, 118,
1033 119, 147, 147, 0, 0, 147, 147, 147, 115, 120,
1034 121, 0, 0, 81, 82, 0, 0, 114, 79, 80,
1038 /* YYDEFGOTO[NTERM-NUM]. */
1039 static const yytype_int16 yydefgoto[] =
1041 -1, 34, 239, 35, 36, 120, 37, 38, 39, 40,
1042 41, 42, 43, 44, 213, 45, 46, 47, 48, 49,
1043 50, 225, 231, 232, 233, 274, 57, 58, 134, 135,
1044 123, 74, 59, 51, 187, 136, 54, 55
1047 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
1049 #define YYPACT_NINF -208
1050 static const yytype_int16 yypact[] =
1052 296, -35, -208, -2, 38, 10, -208, -208, 24, 546,
1053 31, 346, 51, 47, -208, 591, 604, -208, 56, 71,
1054 -18, 112, 130, 115, 128, 136, 143, 154, -208, -208,
1055 157, 170, -208, -208, 111, -208, -208, 229, -208, 578,
1056 -208, -208, -208, -208, -208, -208, -208, -208, -208, -208,
1057 -208, -12, -3, -208, 48, 346, -208, -208, 208, 396,
1058 -208, 73, 15, 163, 190, 201, 160, 107, 229, 578,
1059 204, -208, -208, -208, -208, -208, 195, 165, 202, 215,
1060 152, 216, 153, 222, 227, 236, 237, 244, 245, 253,
1061 158, 254, 171, 255, 256, 259, 261, 262, -208, -208,
1062 -208, -208, -208, -208, -208, -208, -208, -208, -208, -208,
1063 -208, -208, -208, -208, 231, 230, -208, -208, -208, -208,
1064 578, -208, -208, -208, -208, -208, 446, 446, -208, -208,
1065 -208, -208, -208, -208, -208, 210, -208, 4, -208, 65,
1066 -208, -208, -208, -208, 70, -208, -208, 232, 41, 578,
1067 578, -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, -208, -208, -208, -208, -208,
1070 -208, -208, -208, -208, -208, 396, 396, 23, 23, 496,
1071 496, 97, -208, -208, -208, -208, -208, -208, 85, -208,
1072 185, -208, 276, 235, 100, 110, -208, 268, -208, 280,
1073 283, -208, 578, -208, 578, 41, -208, -208, 446, 446,
1074 48, 48, -208, -208, -208, 295, 396, 396, 396, 396,
1075 396, 294, 161, -208, 19, -208, -208, 290, -208, 200,
1076 -208, 252, -208, -208, -208, -208, -208, -208, 302, 396,
1077 200, 269, -208, -208, 41, 578, -208, 313, 324, -208,
1078 -208, -208, 55, 55, 55, -208, -208, -208, -208, 192,
1079 34, -208, -208, 303, -19, 315, 278, -208, -208, -208,
1080 114, -208, 322, 286, 323, 287, -208, 210, -208, -208,
1081 -208, -208, -208, -208, -208, -208, -208, -208, -208, -208,
1082 8, 320, -208, -208, -208, 117, -208, -208, -208, -208,
1083 -208, -208, 119, 167, 396, 396, 396, -208, -208, -208,
1084 396, -208, -208, 337, 307, -208, -208, -208, -208, -208,
1085 396, 345, 308, -208, -208, 352, 312, -208, -208, -208,
1089 /* YYPGOTO[NTERM-NUM]. */
1090 static const yytype_int16 yypgoto[] =
1092 -208, -208, 164, -37, -31, -62, 368, -208, -5, -208,
1093 -208, -208, -208, -208, -206, -208, -208, -208, -208, -208,
1094 -208, 66, -208, 145, -208, 88, -173, -6, -208, -207,
1095 -208, -45, -48, -208, 5, 3, 17, -208
1098 /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
1099 positive, shift that token. If negative, reduce the rule which
1100 number is the opposite. If zero, do what YYDEFACT says.
1101 If YYTABLE_NINF, syntax error. */
1102 #define YYTABLE_NINF -1
1103 static const yytype_uint16 yytable[] =
1105 64, 65, 119, 53, 69, 52, 118, 150, 100, 256,
1106 130, 101, 137, 139, 75, 144, 56, 142, 148, 260,
1107 261, 262, 263, 264, 60, 197, 114, 115, 271, 140,
1108 124, 125, 119, 248, 301, 251, 63, 118, 102, 121,
1109 122, 302, 287, 299, 2, 272, 126, 127, 290, 3,
1110 66, 4, 5, 6, 7, 133, 124, 125, 131, 10,
1111 272, 301, 149, 70, 61, 71, 72, 73, 317, 62,
1112 133, 17, 141, 284, 285, 76, 185, 186, 273, 199,
1113 189, 190, 98, 184, 206, 133, 200, 214, 192, 193,
1114 198, 207, 133, 273, 204, 205, 128, 99, 32, 235,
1115 33, 129, 222, 223, 224, 215, 77, 262, 263, 264,
1116 2, 116, 119, 184, 244, 3, 133, 4, 5, 6,
1117 7, 133, 201, 138, 246, 10, 191, 208, 306, 53,
1118 53, 321, 188, 325, 202, 203, 133, 17, 103, 209,
1119 210, 107, 236, 212, 226, 227, 228, 229, 230, 234,
1120 255, 133, 335, 336, 108, 240, 104, 245, 249, 105,
1121 249, 133, 109, 254, 32, 133, 33, 247, 133, 110,
1122 133, 307, 327, 223, 322, 119, 326, 184, 156, 160,
1123 111, 157, 161, 112, 170, 270, 106, 171, 53, 53,
1124 216, 217, 280, 237, 279, 241, 113, 174, 249, 249,
1125 175, 266, 267, 268, 145, 288, 220, 221, 158, 162,
1126 212, 238, 132, 143, 172, 146, 257, 258, 184, 147,
1127 152, 53, 53, 151, 188, 153, 278, 176, 154, 275,
1128 276, 305, 296, 297, 298, 71, 72, 73, 282, 283,
1129 312, 155, 159, 192, 193, 314, 315, 316, 163, 212,
1130 71, 72, 73, 164, 320, 117, 14, 15, 16, 194,
1131 195, 196, 165, 166, 18, 19, 20, 21, 22, 330,
1132 167, 168, 23, 24, 25, 26, 27, 249, 249, 169,
1133 173, 177, 178, 30, 31, 179, 313, 180, 181, 182,
1134 183, 242, 211, 243, 238, 252, 319, 1, 253, 2,
1135 323, 324, 259, 265, 3, 277, 4, 5, 6, 7,
1136 281, 329, 8, 9, 10, 331, 332, 286, 11, 12,
1137 291, 337, 13, 14, 15, 16, 17, 289, 292, 272,
1138 303, 18, 19, 20, 21, 22, 304, 308, 310, 23,
1139 24, 25, 26, 27, 309, 311, 318, 28, 29, 2,
1140 30, 31, 333, 32, 3, 33, 4, 5, 6, 7,
1141 338, 300, 8, 9, 10, 334, 339, 340, 11, 12,
1142 341, 250, 13, 14, 15, 16, 17, 68, 269, 328,
1143 0, 18, 19, 20, 21, 22, 0, 0, 0, 23,
1144 24, 25, 26, 27, 0, 0, 71, 72, 73, 2,
1145 30, 31, 0, 32, 3, 33, 4, 5, 6, 7,
1146 0, 0, 8, 9, 10, 0, 0, 0, 11, 12,
1147 0, 0, 13, 14, 15, 16, 17, 0, 0, 0,
1148 0, 18, 19, 20, 21, 22, 0, 0, 0, 23,
1149 24, 25, 26, 27, 0, 0, 0, 133, 0, 2,
1150 30, 31, 0, 32, 3, 33, 4, 5, 6, 7,
1151 0, 0, 8, 9, 10, 0, 0, 0, 11, 12,
1152 0, 0, 13, 14, 15, 16, 17, 0, 0, 0,
1153 0, 18, 19, 20, 21, 22, 0, 0, 0, 23,
1154 24, 25, 26, 27, 0, 0, 0, 0, 0, 2,
1155 30, 31, 0, 32, 3, 33, 4, 5, 6, 7,
1156 0, 0, 8, 9, 10, 0, 0, 0, 0, 0,
1157 0, 0, 13, 14, 15, 16, 17, 0, 0, 0,
1158 0, 18, 19, 20, 21, 22, 0, 0, 0, 23,
1159 24, 25, 26, 27, 0, 0, 0, 133, 0, 2,
1160 30, 31, 0, 32, 3, 33, 4, 5, 6, 7,
1161 0, 0, 0, 0, 10, 0, 0, 0, 0, 0,
1162 0, 0, 67, 14, 15, 16, 17, 0, 0, 0,
1163 0, 18, 19, 20, 21, 22, 0, 0, 0, 23,
1164 24, 25, 26, 27, 0, 0, 0, 0, 0, 0,
1165 30, 31, 0, 32, 0, 33, 15, 16, 0, 0,
1166 0, 0, 0, 18, 19, 20, 21, 22, 0, 0,
1167 0, 23, 24, 25, 26, 27, 78, 79, 80, 81,
1168 82, 0, 30, 31, 83, 0, 0, 84, 85, 88,
1169 89, 90, 91, 92, 0, 86, 87, 93, 0, 0,
1170 94, 95, 0, 0, 0, 0, 0, 0, 96, 97
1173 static const yytype_int16 yycheck[] =
1175 6, 7, 39, 0, 9, 0, 37, 69, 26, 215,
1176 55, 29, 60, 61, 11, 63, 51, 62, 66, 226,
1177 227, 228, 229, 230, 26, 21, 32, 33, 9, 14,
1178 33, 34, 69, 206, 53, 208, 26, 68, 56, 51,
1179 52, 60, 249, 9, 3, 26, 49, 50, 254, 8,
1180 26, 10, 11, 12, 13, 51, 33, 34, 55, 18,
1181 26, 53, 67, 32, 26, 50, 51, 52, 60, 31,
1182 51, 30, 57, 246, 247, 24, 124, 125, 59, 14,
1183 128, 129, 26, 120, 14, 51, 21, 149, 33, 34,
1184 138, 21, 51, 59, 142, 143, 48, 26, 57, 14,
1185 59, 53, 5, 6, 7, 153, 59, 314, 315, 316,
1186 3, 0, 149, 150, 14, 8, 51, 10, 11, 12,
1187 13, 51, 57, 50, 14, 18, 132, 57, 14, 126,
1188 127, 14, 127, 14, 140, 141, 51, 30, 26, 145,
1189 146, 26, 57, 148, 192, 193, 194, 195, 196, 197,
1190 212, 51, 325, 326, 26, 200, 26, 57, 206, 29,
1191 208, 51, 26, 211, 57, 51, 59, 57, 51, 26,
1192 51, 57, 5, 6, 57, 212, 57, 214, 26, 26,
1193 26, 29, 29, 26, 26, 233, 56, 29, 185, 186,
1194 185, 186, 240, 199, 239, 201, 26, 26, 246, 247,
1195 29, 40, 41, 42, 14, 250, 189, 190, 56, 56,
1196 215, 26, 4, 50, 56, 14, 222, 223, 255, 59,
1197 25, 218, 219, 19, 219, 60, 26, 56, 26, 235,
1198 236, 279, 40, 41, 42, 50, 51, 52, 244, 245,
1199 288, 26, 26, 33, 34, 293, 294, 295, 26, 254,
1200 50, 51, 52, 26, 302, 26, 27, 28, 29, 49,
1201 50, 51, 26, 26, 35, 36, 37, 38, 39, 317,
1202 26, 26, 43, 44, 45, 46, 47, 325, 326, 26,
1203 26, 26, 26, 54, 55, 26, 292, 26, 26, 58,
1204 60, 15, 60, 58, 26, 15, 302, 1, 15, 3,
1205 306, 307, 7, 9, 8, 15, 10, 11, 12, 13,
1206 58, 317, 16, 17, 18, 321, 322, 15, 22, 23,
1207 7, 327, 26, 27, 28, 29, 30, 58, 4, 26,
1208 15, 35, 36, 37, 38, 39, 58, 15, 15, 43,
1209 44, 45, 46, 47, 58, 58, 26, 51, 52, 3,
1210 54, 55, 15, 57, 8, 59, 10, 11, 12, 13,
1211 15, 273, 16, 17, 18, 58, 58, 15, 22, 23,
1212 58, 207, 26, 27, 28, 29, 30, 9, 233, 313,
1213 -1, 35, 36, 37, 38, 39, -1, -1, -1, 43,
1214 44, 45, 46, 47, -1, -1, 50, 51, 52, 3,
1215 54, 55, -1, 57, 8, 59, 10, 11, 12, 13,
1216 -1, -1, 16, 17, 18, -1, -1, -1, 22, 23,
1217 -1, -1, 26, 27, 28, 29, 30, -1, -1, -1,
1218 -1, 35, 36, 37, 38, 39, -1, -1, -1, 43,
1219 44, 45, 46, 47, -1, -1, -1, 51, -1, 3,
1220 54, 55, -1, 57, 8, 59, 10, 11, 12, 13,
1221 -1, -1, 16, 17, 18, -1, -1, -1, 22, 23,
1222 -1, -1, 26, 27, 28, 29, 30, -1, -1, -1,
1223 -1, 35, 36, 37, 38, 39, -1, -1, -1, 43,
1224 44, 45, 46, 47, -1, -1, -1, -1, -1, 3,
1225 54, 55, -1, 57, 8, 59, 10, 11, 12, 13,
1226 -1, -1, 16, 17, 18, -1, -1, -1, -1, -1,
1227 -1, -1, 26, 27, 28, 29, 30, -1, -1, -1,
1228 -1, 35, 36, 37, 38, 39, -1, -1, -1, 43,
1229 44, 45, 46, 47, -1, -1, -1, 51, -1, 3,
1230 54, 55, -1, 57, 8, 59, 10, 11, 12, 13,
1231 -1, -1, -1, -1, 18, -1, -1, -1, -1, -1,
1232 -1, -1, 26, 27, 28, 29, 30, -1, -1, -1,
1233 -1, 35, 36, 37, 38, 39, -1, -1, -1, 43,
1234 44, 45, 46, 47, -1, -1, -1, -1, -1, -1,
1235 54, 55, -1, 57, -1, 59, 28, 29, -1, -1,
1236 -1, -1, -1, 35, 36, 37, 38, 39, -1, -1,
1237 -1, 43, 44, 45, 46, 47, 35, 36, 37, 38,
1238 39, -1, 54, 55, 43, -1, -1, 46, 47, 35,
1239 36, 37, 38, 39, -1, 54, 55, 43, -1, -1,
1240 46, 47, -1, -1, -1, -1, -1, -1, 54, 55
1243 /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
1244 symbol of state STATE-NUM. */
1245 static const yytype_uint8 yystos[] =
1247 0, 1, 3, 8, 10, 11, 12, 13, 16, 17,
1248 18, 22, 23, 26, 27, 28, 29, 30, 35, 36,
1249 37, 38, 39, 43, 44, 45, 46, 47, 51, 52,
1250 54, 55, 57, 59, 62, 64, 65, 67, 68, 69,
1251 70, 71, 72, 73, 74, 76, 77, 78, 79, 80,
1252 81, 94, 95, 96, 97, 98, 51, 87, 88, 93,
1253 26, 26, 31, 26, 88, 88, 26, 26, 67, 69,
1254 32, 50, 51, 52, 92, 96, 24, 59, 35, 36,
1255 37, 38, 39, 43, 46, 47, 54, 55, 35, 36,
1256 37, 38, 39, 43, 46, 47, 54, 55, 26, 26,
1257 26, 29, 56, 26, 26, 29, 56, 26, 26, 26,
1258 26, 26, 26, 26, 88, 88, 0, 26, 65, 64,
1259 66, 51, 52, 91, 33, 34, 49, 50, 48, 53,
1260 92, 96, 4, 51, 89, 90, 96, 93, 50, 93,
1261 14, 57, 92, 50, 93, 14, 14, 59, 93, 69,
1262 66, 19, 25, 60, 26, 26, 26, 29, 56, 26,
1263 26, 29, 56, 26, 26, 26, 26, 26, 26, 26,
1264 26, 29, 56, 26, 26, 29, 56, 26, 26, 26,
1265 26, 26, 58, 60, 64, 93, 93, 95, 95, 93,
1266 93, 88, 33, 34, 49, 50, 51, 21, 93, 14,
1267 21, 57, 88, 88, 93, 93, 14, 21, 57, 88,
1268 88, 60, 69, 75, 66, 93, 95, 95, 49, 50,
1269 97, 97, 5, 6, 7, 82, 93, 93, 93, 93,
1270 93, 83, 84, 85, 93, 14, 57, 88, 26, 63,
1271 92, 88, 15, 58, 14, 57, 14, 57, 87, 93,
1272 63, 87, 15, 15, 93, 66, 75, 88, 88, 7,
1273 90, 90, 90, 90, 90, 9, 40, 41, 42, 84,
1274 93, 9, 26, 59, 86, 88, 88, 15, 26, 92,
1275 93, 58, 88, 88, 87, 87, 15, 90, 92, 58,
1276 75, 7, 4, 49, 50, 51, 40, 41, 42, 9,
1277 86, 53, 60, 15, 58, 93, 14, 57, 15, 58,
1278 15, 58, 93, 88, 93, 93, 93, 60, 26, 88,
1279 93, 14, 57, 88, 88, 14, 57, 5, 82, 88,
1280 93, 88, 88, 15, 58, 87, 87, 88, 15, 58,
1284 #define yyerrok (yyerrstatus = 0)
1285 #define yyclearin (yychar = YYEMPTY)
1286 #define YYEMPTY (-2)
1289 #define YYACCEPT goto yyacceptlab
1290 #define YYABORT goto yyabortlab
1291 #define YYERROR goto yyerrorlab
1294 /* Like YYERROR except do call yyerror. This remains here temporarily
1295 to ease the transition to the new meaning of YYERROR, for GCC.
1296 Once GCC version 2 has supplanted version 1, this can go. */
1298 #define YYFAIL goto yyerrlab
1300 #define YYRECOVERING() (!!yyerrstatus)
1302 #define YYBACKUP(Token, Value) \
1304 if (yychar == YYEMPTY && yylen == 1) \
1308 yytoken = YYTRANSLATE (yychar); \
1314 yyerror (YY_("syntax error: cannot back up")); \
1321 #define YYERRCODE 256
1324 /* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
1325 If N is 0, then set CURRENT to the empty location which ends
1326 the previous symbol: RHS[0] (always defined). */
1328 #define YYRHSLOC(Rhs, K) ((Rhs)[K])
1329 #ifndef YYLLOC_DEFAULT
1330 # define YYLLOC_DEFAULT(Current, Rhs, N) \
1334 (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \
1335 (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \
1336 (Current).last_line = YYRHSLOC (Rhs, N).last_line; \
1337 (Current).last_column = YYRHSLOC (Rhs, N).last_column; \
1341 (Current).first_line = (Current).last_line = \
1342 YYRHSLOC (Rhs, 0).last_line; \
1343 (Current).first_column = (Current).last_column = \
1344 YYRHSLOC (Rhs, 0).last_column; \
1350 /* YY_LOCATION_PRINT -- Print the location on the stream.
1351 This macro was not mandated originally: define only if we know
1352 we won't break user code: when these are the locations we know. */
1354 #ifndef YY_LOCATION_PRINT
1355 # if defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL
1356 # define YY_LOCATION_PRINT(File, Loc) \
1357 fprintf (File, "%d.%d-%d.%d", \
1358 (Loc).first_line, (Loc).first_column, \
1359 (Loc).last_line, (Loc).last_column)
1361 # define YY_LOCATION_PRINT(File, Loc) ((void) 0)
1366 /* YYLEX -- calling `yylex' with the right arguments. */
1369 # define YYLEX yylex (YYLEX_PARAM)
1371 # define YYLEX yylex ()
1374 /* Enable debugging if requested. */
1378 # include <stdio.h> /* INFRINGES ON USER NAME SPACE */
1379 # define YYFPRINTF fprintf
1382 # define YYDPRINTF(Args) \
1388 # define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
1392 YYFPRINTF (stderr, "%s ", Title); \
1393 yy_symbol_print (stderr, \
1395 YYFPRINTF (stderr, "\n"); \
1400 /*--------------------------------.
1401 | Print this symbol on YYOUTPUT. |
1402 `--------------------------------*/
1405 #if (defined __STDC__ || defined __C99__FUNC__ \
1406 || defined __cplusplus || defined _MSC_VER)
1408 yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep)
1411 yy_symbol_value_print (yyoutput, yytype, yyvaluep)
1414 YYSTYPE const * const yyvaluep;
1420 if (yytype < YYNTOKENS)
1421 YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep);
1433 /*--------------------------------.
1434 | Print this symbol on YYOUTPUT. |
1435 `--------------------------------*/
1437 #if (defined __STDC__ || defined __C99__FUNC__ \
1438 || defined __cplusplus || defined _MSC_VER)
1440 yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep)
1443 yy_symbol_print (yyoutput, yytype, yyvaluep)
1446 YYSTYPE const * const yyvaluep;
1449 if (yytype < YYNTOKENS)
1450 YYFPRINTF (yyoutput, "token %s (", yytname[yytype]);
1452 YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]);
1454 yy_symbol_value_print (yyoutput, yytype, yyvaluep);
1455 YYFPRINTF (yyoutput, ")");
1458 /*------------------------------------------------------------------.
1459 | yy_stack_print -- Print the state stack from its BOTTOM up to its |
1461 `------------------------------------------------------------------*/
1463 #if (defined __STDC__ || defined __C99__FUNC__ \
1464 || defined __cplusplus || defined _MSC_VER)
1466 yy_stack_print (yytype_int16 *bottom, yytype_int16 *top)
1469 yy_stack_print (bottom, top)
1470 yytype_int16 *bottom;
1474 YYFPRINTF (stderr, "Stack now");
1475 for (; bottom <= top; ++bottom)
1476 YYFPRINTF (stderr, " %d", *bottom);
1477 YYFPRINTF (stderr, "\n");
1480 # define YY_STACK_PRINT(Bottom, Top) \
1483 yy_stack_print ((Bottom), (Top)); \
1487 /*------------------------------------------------.
1488 | Report that the YYRULE is going to be reduced. |
1489 `------------------------------------------------*/
1491 #if (defined __STDC__ || defined __C99__FUNC__ \
1492 || defined __cplusplus || defined _MSC_VER)
1494 yy_reduce_print (YYSTYPE *yyvsp, int yyrule)
1497 yy_reduce_print (yyvsp, yyrule)
1502 int yynrhs = yyr2[yyrule];
1504 unsigned long int yylno = yyrline[yyrule];
1505 YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n",
1507 /* The symbols being reduced. */
1508 for (yyi = 0; yyi < yynrhs; yyi++)
1510 fprintf (stderr, " $%d = ", yyi + 1);
1511 yy_symbol_print (stderr, yyrhs[yyprhs[yyrule] + yyi],
1512 &(yyvsp[(yyi + 1) - (yynrhs)])
1514 fprintf (stderr, "\n");
1518 # define YY_REDUCE_PRINT(Rule) \
1521 yy_reduce_print (yyvsp, Rule); \
1524 /* Nonzero means print parse trace. It is left uninitialized so that
1525 multiple parsers can coexist. */
1527 #else /* !YYDEBUG */
1528 # define YYDPRINTF(Args)
1529 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
1530 # define YY_STACK_PRINT(Bottom, Top)
1531 # define YY_REDUCE_PRINT(Rule)
1532 #endif /* !YYDEBUG */
1535 /* YYINITDEPTH -- initial size of the parser's stacks. */
1537 # define YYINITDEPTH 200
1540 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
1541 if the built-in stack extension method is used).
1543 Do not make this value too large; the results are undefined if
1544 YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH)
1545 evaluated with infinite-precision integer arithmetic. */
1548 # define YYMAXDEPTH 10000
1556 # if defined __GLIBC__ && defined _STRING_H
1557 # define yystrlen strlen
1559 /* Return the length of YYSTR. */
1560 #if (defined __STDC__ || defined __C99__FUNC__ \
1561 || defined __cplusplus || defined _MSC_VER)
1563 yystrlen (const char *yystr)
1571 for (yylen = 0; yystr[yylen]; yylen++)
1579 # if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
1580 # define yystpcpy stpcpy
1582 /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
1584 #if (defined __STDC__ || defined __C99__FUNC__ \
1585 || defined __cplusplus || defined _MSC_VER)
1587 yystpcpy (char *yydest, const char *yysrc)
1590 yystpcpy (yydest, yysrc)
1596 const char *yys = yysrc;
1598 while ((*yyd++ = *yys++) != '\0')
1607 /* Copy to YYRES the contents of YYSTR after stripping away unnecessary
1608 quotes and backslashes, so that it's suitable for yyerror. The
1609 heuristic is that double-quoting is unnecessary unless the string
1610 contains an apostrophe, a comma, or backslash (other than
1611 backslash-backslash). YYSTR is taken from yytname. If YYRES is
1612 null, do not copy; instead, return the length of what the result
1615 yytnamerr (char *yyres, const char *yystr)
1620 char const *yyp = yystr;
1627 goto do_not_strip_quotes;
1631 goto do_not_strip_quotes;
1644 do_not_strip_quotes: ;
1648 return yystrlen (yystr);
1650 return yystpcpy (yyres, yystr) - yyres;
1654 /* Copy into YYRESULT an error message about the unexpected token
1655 YYCHAR while in state YYSTATE. Return the number of bytes copied,
1656 including the terminating null byte. If YYRESULT is null, do not
1657 copy anything; just return the number of bytes that would be
1658 copied. As a special case, return 0 if an ordinary "syntax error"
1659 message will do. Return YYSIZE_MAXIMUM if overflow occurs during
1660 size calculation. */
1662 yysyntax_error (char *yyresult, int yystate, int yychar)
1664 int yyn = yypact[yystate];
1666 if (! (YYPACT_NINF < yyn && yyn <= YYLAST))
1670 int yytype = YYTRANSLATE (yychar);
1671 YYSIZE_T yysize0 = yytnamerr (0, yytname[yytype]);
1672 YYSIZE_T yysize = yysize0;
1674 int yysize_overflow = 0;
1675 enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
1676 char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
1680 /* This is so xgettext sees the translatable formats that are
1681 constructed on the fly. */
1682 YY_("syntax error, unexpected %s");
1683 YY_("syntax error, unexpected %s, expecting %s");
1684 YY_("syntax error, unexpected %s, expecting %s or %s");
1685 YY_("syntax error, unexpected %s, expecting %s or %s or %s");
1686 YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s");
1690 static char const yyunexpected[] = "syntax error, unexpected %s";
1691 static char const yyexpecting[] = ", expecting %s";
1692 static char const yyor[] = " or %s";
1693 char yyformat[sizeof yyunexpected
1694 + sizeof yyexpecting - 1
1695 + ((YYERROR_VERBOSE_ARGS_MAXIMUM - 2)
1696 * (sizeof yyor - 1))];
1697 char const *yyprefix = yyexpecting;
1699 /* Start YYX at -YYN if negative to avoid negative indexes in
1701 int yyxbegin = yyn < 0 ? -yyn : 0;
1703 /* Stay within bounds of both yycheck and yytname. */
1704 int yychecklim = YYLAST - yyn + 1;
1705 int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
1708 yyarg[0] = yytname[yytype];
1709 yyfmt = yystpcpy (yyformat, yyunexpected);
1711 for (yyx = yyxbegin; yyx < yyxend; ++yyx)
1712 if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
1714 if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
1718 yyformat[sizeof yyunexpected - 1] = '\0';
1721 yyarg[yycount++] = yytname[yyx];
1722 yysize1 = yysize + yytnamerr (0, yytname[yyx]);
1723 yysize_overflow |= (yysize1 < yysize);
1725 yyfmt = yystpcpy (yyfmt, yyprefix);
1729 yyf = YY_(yyformat);
1730 yysize1 = yysize + yystrlen (yyf);
1731 yysize_overflow |= (yysize1 < yysize);
1734 if (yysize_overflow)
1735 return YYSIZE_MAXIMUM;
1739 /* Avoid sprintf, as that infringes on the user's name space.
1740 Don't have undefined behavior even if the translation
1741 produced a string with the wrong number of "%s"s. */
1742 char *yyp = yyresult;
1744 while ((*yyp = *yyf) != '\0')
1746 if (*yyp == '%' && yyf[1] == 's' && yyi < yycount)
1748 yyp += yytnamerr (yyp, yyarg[yyi++]);
1761 #endif /* YYERROR_VERBOSE */
1764 /*-----------------------------------------------.
1765 | Release the memory associated to this symbol. |
1766 `-----------------------------------------------*/
1769 #if (defined __STDC__ || defined __C99__FUNC__ \
1770 || defined __cplusplus || defined _MSC_VER)
1772 yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep)
1775 yydestruct (yymsg, yytype, yyvaluep)
1785 YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
1796 /* Prevent warnings from -Wmissing-prototypes. */
1798 #ifdef YYPARSE_PARAM
1799 #if defined __STDC__ || defined __cplusplus
1800 int yyparse (void *YYPARSE_PARAM);
1804 #else /* ! YYPARSE_PARAM */
1805 #if defined __STDC__ || defined __cplusplus
1810 #endif /* ! YYPARSE_PARAM */
1814 /* The look-ahead symbol. */
1817 /* The semantic value of the look-ahead symbol. */
1820 /* Number of syntax errors so far. */
1829 #ifdef YYPARSE_PARAM
1830 #if (defined __STDC__ || defined __C99__FUNC__ \
1831 || defined __cplusplus || defined _MSC_VER)
1833 yyparse (void *YYPARSE_PARAM)
1836 yyparse (YYPARSE_PARAM)
1837 void *YYPARSE_PARAM;
1839 #else /* ! YYPARSE_PARAM */
1840 #if (defined __STDC__ || defined __C99__FUNC__ \
1841 || defined __cplusplus || defined _MSC_VER)
1855 /* Number of tokens to shift before error messages enabled. */
1857 /* Look-ahead token as an internal (translated) token number. */
1860 /* Buffer for error messages, and its allocated size. */
1862 char *yymsg = yymsgbuf;
1863 YYSIZE_T yymsg_alloc = sizeof yymsgbuf;
1866 /* Three stacks and their tools:
1867 `yyss': related to states,
1868 `yyvs': related to semantic values,
1869 `yyls': related to locations.
1871 Refer to the stacks thru separate pointers, to allow yyoverflow
1872 to reallocate them elsewhere. */
1874 /* The state stack. */
1875 yytype_int16 yyssa[YYINITDEPTH];
1876 yytype_int16 *yyss = yyssa;
1877 yytype_int16 *yyssp;
1879 /* The semantic value stack. */
1880 YYSTYPE yyvsa[YYINITDEPTH];
1881 YYSTYPE *yyvs = yyvsa;
1886 #define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N))
1888 YYSIZE_T yystacksize = YYINITDEPTH;
1890 /* The variables used to return semantic value and location from the
1895 /* The number of symbols on the RHS of the reduced rule.
1896 Keep to zero when no symbol should be popped. */
1899 YYDPRINTF ((stderr, "Starting parse\n"));
1904 yychar = YYEMPTY; /* Cause a token to be read. */
1906 /* Initialize stack pointers.
1907 Waste one element of value and location stack
1908 so that they stay on the same level as the state stack.
1909 The wasted elements are never initialized. */
1916 /*------------------------------------------------------------.
1917 | yynewstate -- Push a new state, which is found in yystate. |
1918 `------------------------------------------------------------*/
1920 /* In all cases, when you get here, the value and location stacks
1921 have just been pushed. So pushing a state here evens the stacks. */
1927 if (yyss + yystacksize - 1 <= yyssp)
1929 /* Get the current used size of the three stacks, in elements. */
1930 YYSIZE_T yysize = yyssp - yyss + 1;
1934 /* Give user a chance to reallocate the stack. Use copies of
1935 these so that the &'s don't force the real ones into
1937 YYSTYPE *yyvs1 = yyvs;
1938 yytype_int16 *yyss1 = yyss;
1941 /* Each stack pointer address is followed by the size of the
1942 data in use in that stack, in bytes. This used to be a
1943 conditional around just the two extra args, but that might
1944 be undefined if yyoverflow is a macro. */
1945 yyoverflow (YY_("memory exhausted"),
1946 &yyss1, yysize * sizeof (*yyssp),
1947 &yyvs1, yysize * sizeof (*yyvsp),
1954 #else /* no yyoverflow */
1955 # ifndef YYSTACK_RELOCATE
1956 goto yyexhaustedlab;
1958 /* Extend the stack our own way. */
1959 if (YYMAXDEPTH <= yystacksize)
1960 goto yyexhaustedlab;
1962 if (YYMAXDEPTH < yystacksize)
1963 yystacksize = YYMAXDEPTH;
1966 yytype_int16 *yyss1 = yyss;
1967 union yyalloc *yyptr =
1968 (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
1970 goto yyexhaustedlab;
1971 YYSTACK_RELOCATE (yyss);
1972 YYSTACK_RELOCATE (yyvs);
1974 # undef YYSTACK_RELOCATE
1976 YYSTACK_FREE (yyss1);
1979 #endif /* no yyoverflow */
1981 yyssp = yyss + yysize - 1;
1982 yyvsp = yyvs + yysize - 1;
1985 YYDPRINTF ((stderr, "Stack size increased to %lu\n",
1986 (unsigned long int) yystacksize));
1988 if (yyss + yystacksize - 1 <= yyssp)
1992 YYDPRINTF ((stderr, "Entering state %d\n", yystate));
2001 /* Do appropriate processing given the current state. Read a
2002 look-ahead token if we need one and don't already have one. */
2004 /* First try to decide what to do without reference to look-ahead token. */
2005 yyn = yypact[yystate];
2006 if (yyn == YYPACT_NINF)
2009 /* Not known => get a look-ahead token if don't already have one. */
2011 /* YYCHAR is either YYEMPTY or YYEOF or a valid look-ahead symbol. */
2012 if (yychar == YYEMPTY)
2014 YYDPRINTF ((stderr, "Reading a token: "));
2018 if (yychar <= YYEOF)
2020 yychar = yytoken = YYEOF;
2021 YYDPRINTF ((stderr, "Now at end of input.\n"));
2025 yytoken = YYTRANSLATE (yychar);
2026 YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
2029 /* If the proper action on seeing token YYTOKEN is to reduce or to
2030 detect an error, take that action. */
2032 if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
2037 if (yyn == 0 || yyn == YYTABLE_NINF)
2046 /* Count tokens shifted since error; after three, turn off error
2051 /* Shift the look-ahead token. */
2052 YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
2054 /* Discard the shifted token unless it is eof. */
2055 if (yychar != YYEOF)
2064 /*-----------------------------------------------------------.
2065 | yydefault -- do the default action for the current state. |
2066 `-----------------------------------------------------------*/
2068 yyn = yydefact[yystate];
2074 /*-----------------------------.
2075 | yyreduce -- Do a reduction. |
2076 `-----------------------------*/
2078 /* yyn is the number of a rule to reduce with. */
2081 /* If YYLEN is nonzero, implement the default value of the action:
2084 Otherwise, the following line sets YYVAL to garbage.
2085 This behavior is undocumented and Bison
2086 users should not rely upon it. Assigning to YYVAL
2087 unconditionally makes the parser a bit smaller, and it avoids a
2088 GCC warning that YYVAL may be used uninitialized. */
2089 yyval = yyvsp[1-yylen];
2092 YY_REDUCE_PRINT (yyn);
2096 #line 378 "/usr/homes/chet/src/bash/src/parse.y"
2098 /* Case of regular command. Discard the error
2099 safety net,and return the command just parsed. */
2100 global_command = (yyvsp[(1) - (2)].command);
2101 eof_encountered = 0;
2102 /* discard_parser_constructs (0); */
2103 if (parser_state & PST_CMDSUBST)
2104 parser_state |= PST_EOFTOKEN;
2110 #line 389 "/usr/homes/chet/src/bash/src/parse.y"
2112 /* Case of regular command, but not a very
2113 interesting one. Return a NULL command. */
2114 global_command = (COMMAND *)NULL;
2115 if (parser_state & PST_CMDSUBST)
2116 parser_state |= PST_EOFTOKEN;
2122 #line 398 "/usr/homes/chet/src/bash/src/parse.y"
2124 /* Error during parsing. Return NULL command. */
2125 global_command = (COMMAND *)NULL;
2126 eof_encountered = 0;
2127 /* discard_parser_constructs (1); */
2128 if (interactive && parse_and_execute_level == 0)
2140 #line 413 "/usr/homes/chet/src/bash/src/parse.y"
2142 /* Case of EOF seen by itself. Do ignoreeof or
2144 global_command = (COMMAND *)NULL;
2145 handle_eof_input_unit ();
2151 #line 423 "/usr/homes/chet/src/bash/src/parse.y"
2152 { (yyval.word_list) = make_word_list ((yyvsp[(1) - (1)].word), (WORD_LIST *)NULL); }
2156 #line 425 "/usr/homes/chet/src/bash/src/parse.y"
2157 { (yyval.word_list) = make_word_list ((yyvsp[(2) - (2)].word), (yyvsp[(1) - (2)].word_list)); }
2161 #line 429 "/usr/homes/chet/src/bash/src/parse.y"
2164 redir.filename = (yyvsp[(2) - (2)].word);
2165 (yyval.redirect) = make_redirection (source, r_output_direction, redir, 0);
2170 #line 435 "/usr/homes/chet/src/bash/src/parse.y"
2173 redir.filename = (yyvsp[(2) - (2)].word);
2174 (yyval.redirect) = make_redirection (source, r_input_direction, redir, 0);
2179 #line 441 "/usr/homes/chet/src/bash/src/parse.y"
2181 source.dest = (yyvsp[(1) - (3)].number);
2182 redir.filename = (yyvsp[(3) - (3)].word);
2183 (yyval.redirect) = make_redirection (source, r_output_direction, redir, 0);
2188 #line 447 "/usr/homes/chet/src/bash/src/parse.y"
2190 source.dest = (yyvsp[(1) - (3)].number);
2191 redir.filename = (yyvsp[(3) - (3)].word);
2192 (yyval.redirect) = make_redirection (source, r_input_direction, redir, 0);
2197 #line 453 "/usr/homes/chet/src/bash/src/parse.y"
2199 source.filename = (yyvsp[(1) - (3)].word);
2200 redir.filename = (yyvsp[(3) - (3)].word);
2201 (yyval.redirect) = make_redirection (source, r_output_direction, redir, REDIR_VARASSIGN);
2206 #line 459 "/usr/homes/chet/src/bash/src/parse.y"
2208 source.filename = (yyvsp[(1) - (3)].word);
2209 redir.filename = (yyvsp[(3) - (3)].word);
2210 (yyval.redirect) = make_redirection (source, r_input_direction, redir, REDIR_VARASSIGN);
2215 #line 465 "/usr/homes/chet/src/bash/src/parse.y"
2218 redir.filename = (yyvsp[(2) - (2)].word);
2219 (yyval.redirect) = make_redirection (source, r_appending_to, redir, 0);
2224 #line 471 "/usr/homes/chet/src/bash/src/parse.y"
2226 source.dest = (yyvsp[(1) - (3)].number);
2227 redir.filename = (yyvsp[(3) - (3)].word);
2228 (yyval.redirect) = make_redirection (source, r_appending_to, redir, 0);
2233 #line 477 "/usr/homes/chet/src/bash/src/parse.y"
2235 source.filename = (yyvsp[(1) - (3)].word);
2236 redir.filename = (yyvsp[(3) - (3)].word);
2237 (yyval.redirect) = make_redirection (source, r_appending_to, redir, REDIR_VARASSIGN);
2242 #line 483 "/usr/homes/chet/src/bash/src/parse.y"
2245 redir.filename = (yyvsp[(2) - (2)].word);
2246 (yyval.redirect) = make_redirection (source, r_output_force, redir, 0);
2251 #line 489 "/usr/homes/chet/src/bash/src/parse.y"
2253 source.dest = (yyvsp[(1) - (3)].number);
2254 redir.filename = (yyvsp[(3) - (3)].word);
2255 (yyval.redirect) = make_redirection (source, r_output_force, redir, 0);
2260 #line 495 "/usr/homes/chet/src/bash/src/parse.y"
2262 source.filename = (yyvsp[(1) - (3)].word);
2263 redir.filename = (yyvsp[(3) - (3)].word);
2264 (yyval.redirect) = make_redirection (source, r_output_force, redir, REDIR_VARASSIGN);
2269 #line 501 "/usr/homes/chet/src/bash/src/parse.y"
2272 redir.filename = (yyvsp[(2) - (2)].word);
2273 (yyval.redirect) = make_redirection (source, r_input_output, redir, 0);
2278 #line 507 "/usr/homes/chet/src/bash/src/parse.y"
2280 source.dest = (yyvsp[(1) - (3)].number);
2281 redir.filename = (yyvsp[(3) - (3)].word);
2282 (yyval.redirect) = make_redirection (source, r_input_output, redir, 0);
2287 #line 513 "/usr/homes/chet/src/bash/src/parse.y"
2289 source.filename = (yyvsp[(1) - (3)].word);
2290 redir.filename = (yyvsp[(3) - (3)].word);
2291 (yyval.redirect) = make_redirection (source, r_input_output, redir, REDIR_VARASSIGN);
2296 #line 519 "/usr/homes/chet/src/bash/src/parse.y"
2299 redir.filename = (yyvsp[(2) - (2)].word);
2300 (yyval.redirect) = make_redirection (source, r_reading_until, redir, 0);
2301 redir_stack[need_here_doc++] = (yyval.redirect);
2306 #line 526 "/usr/homes/chet/src/bash/src/parse.y"
2308 source.dest = (yyvsp[(1) - (3)].number);
2309 redir.filename = (yyvsp[(3) - (3)].word);
2310 (yyval.redirect) = make_redirection (source, r_reading_until, redir, 0);
2311 redir_stack[need_here_doc++] = (yyval.redirect);
2316 #line 533 "/usr/homes/chet/src/bash/src/parse.y"
2318 source.filename = (yyvsp[(1) - (3)].word);
2319 redir.filename = (yyvsp[(3) - (3)].word);
2320 (yyval.redirect) = make_redirection (source, r_reading_until, redir, REDIR_VARASSIGN);
2321 redir_stack[need_here_doc++] = (yyval.redirect);
2326 #line 540 "/usr/homes/chet/src/bash/src/parse.y"
2329 redir.filename = (yyvsp[(2) - (2)].word);
2330 (yyval.redirect) = make_redirection (source, r_deblank_reading_until, redir, 0);
2331 redir_stack[need_here_doc++] = (yyval.redirect);
2336 #line 547 "/usr/homes/chet/src/bash/src/parse.y"
2338 source.dest = (yyvsp[(1) - (3)].number);
2339 redir.filename = (yyvsp[(3) - (3)].word);
2340 (yyval.redirect) = make_redirection (source, r_deblank_reading_until, redir, 0);
2341 redir_stack[need_here_doc++] = (yyval.redirect);
2346 #line 554 "/usr/homes/chet/src/bash/src/parse.y"
2348 source.filename = (yyvsp[(1) - (3)].word);
2349 redir.filename = (yyvsp[(3) - (3)].word);
2350 (yyval.redirect) = make_redirection (source, r_deblank_reading_until, redir, REDIR_VARASSIGN);
2351 redir_stack[need_here_doc++] = (yyval.redirect);
2356 #line 561 "/usr/homes/chet/src/bash/src/parse.y"
2359 redir.filename = (yyvsp[(2) - (2)].word);
2360 (yyval.redirect) = make_redirection (source, r_reading_string, redir, 0);
2365 #line 567 "/usr/homes/chet/src/bash/src/parse.y"
2367 source.dest = (yyvsp[(1) - (3)].number);
2368 redir.filename = (yyvsp[(3) - (3)].word);
2369 (yyval.redirect) = make_redirection (source, r_reading_string, redir, 0);
2374 #line 573 "/usr/homes/chet/src/bash/src/parse.y"
2376 source.filename = (yyvsp[(1) - (3)].word);
2377 redir.filename = (yyvsp[(3) - (3)].word);
2378 (yyval.redirect) = make_redirection (source, r_reading_string, redir, REDIR_VARASSIGN);
2383 #line 579 "/usr/homes/chet/src/bash/src/parse.y"
2386 redir.dest = (yyvsp[(2) - (2)].number);
2387 (yyval.redirect) = make_redirection (source, r_duplicating_input, redir, 0);
2392 #line 585 "/usr/homes/chet/src/bash/src/parse.y"
2394 source.dest = (yyvsp[(1) - (3)].number);
2395 redir.dest = (yyvsp[(3) - (3)].number);
2396 (yyval.redirect) = make_redirection (source, r_duplicating_input, redir, 0);
2401 #line 591 "/usr/homes/chet/src/bash/src/parse.y"
2403 source.filename = (yyvsp[(1) - (3)].word);
2404 redir.dest = (yyvsp[(3) - (3)].number);
2405 (yyval.redirect) = make_redirection (source, r_duplicating_input, redir, REDIR_VARASSIGN);
2410 #line 597 "/usr/homes/chet/src/bash/src/parse.y"
2413 redir.dest = (yyvsp[(2) - (2)].number);
2414 (yyval.redirect) = make_redirection (source, r_duplicating_output, redir, 0);
2419 #line 603 "/usr/homes/chet/src/bash/src/parse.y"
2421 source.dest = (yyvsp[(1) - (3)].number);
2422 redir.dest = (yyvsp[(3) - (3)].number);
2423 (yyval.redirect) = make_redirection (source, r_duplicating_output, redir, 0);
2428 #line 609 "/usr/homes/chet/src/bash/src/parse.y"
2430 source.filename = (yyvsp[(1) - (3)].word);
2431 redir.dest = (yyvsp[(3) - (3)].number);
2432 (yyval.redirect) = make_redirection (source, r_duplicating_output, redir, REDIR_VARASSIGN);
2437 #line 615 "/usr/homes/chet/src/bash/src/parse.y"
2440 redir.filename = (yyvsp[(2) - (2)].word);
2441 (yyval.redirect) = make_redirection (source, r_duplicating_input_word, redir, 0);
2446 #line 621 "/usr/homes/chet/src/bash/src/parse.y"
2448 source.dest = (yyvsp[(1) - (3)].number);
2449 redir.filename = (yyvsp[(3) - (3)].word);
2450 (yyval.redirect) = make_redirection (source, r_duplicating_input_word, redir, 0);
2455 #line 627 "/usr/homes/chet/src/bash/src/parse.y"
2457 source.filename = (yyvsp[(1) - (3)].word);
2458 redir.filename = (yyvsp[(3) - (3)].word);
2459 (yyval.redirect) = make_redirection (source, r_duplicating_input_word, redir, REDIR_VARASSIGN);
2464 #line 633 "/usr/homes/chet/src/bash/src/parse.y"
2467 redir.filename = (yyvsp[(2) - (2)].word);
2468 (yyval.redirect) = make_redirection (source, r_duplicating_output_word, redir, 0);
2473 #line 639 "/usr/homes/chet/src/bash/src/parse.y"
2475 source.dest = (yyvsp[(1) - (3)].number);
2476 redir.filename = (yyvsp[(3) - (3)].word);
2477 (yyval.redirect) = make_redirection (source, r_duplicating_output_word, redir, 0);
2482 #line 645 "/usr/homes/chet/src/bash/src/parse.y"
2484 source.filename = (yyvsp[(1) - (3)].word);
2485 redir.filename = (yyvsp[(3) - (3)].word);
2486 (yyval.redirect) = make_redirection (source, r_duplicating_output_word, redir, REDIR_VARASSIGN);
2491 #line 651 "/usr/homes/chet/src/bash/src/parse.y"
2495 (yyval.redirect) = make_redirection (source, r_close_this, redir, 0);
2500 #line 657 "/usr/homes/chet/src/bash/src/parse.y"
2502 source.dest = (yyvsp[(1) - (3)].number);
2504 (yyval.redirect) = make_redirection (source, r_close_this, redir, 0);
2509 #line 663 "/usr/homes/chet/src/bash/src/parse.y"
2511 source.filename = (yyvsp[(1) - (3)].word);
2513 (yyval.redirect) = make_redirection (source, r_close_this, redir, REDIR_VARASSIGN);
2518 #line 669 "/usr/homes/chet/src/bash/src/parse.y"
2522 (yyval.redirect) = make_redirection (source, r_close_this, redir, 0);
2527 #line 675 "/usr/homes/chet/src/bash/src/parse.y"
2529 source.dest = (yyvsp[(1) - (3)].number);
2531 (yyval.redirect) = make_redirection (source, r_close_this, redir, 0);
2536 #line 681 "/usr/homes/chet/src/bash/src/parse.y"
2538 source.filename = (yyvsp[(1) - (3)].word);
2540 (yyval.redirect) = make_redirection (source, r_close_this, redir, REDIR_VARASSIGN);
2545 #line 687 "/usr/homes/chet/src/bash/src/parse.y"
2548 redir.filename = (yyvsp[(2) - (2)].word);
2549 (yyval.redirect) = make_redirection (source, r_err_and_out, redir, 0);
2554 #line 693 "/usr/homes/chet/src/bash/src/parse.y"
2557 redir.filename = (yyvsp[(2) - (2)].word);
2558 (yyval.redirect) = make_redirection (source, r_append_err_and_out, redir, 0);
2563 #line 701 "/usr/homes/chet/src/bash/src/parse.y"
2564 { (yyval.element).word = (yyvsp[(1) - (1)].word); (yyval.element).redirect = 0; }
2568 #line 703 "/usr/homes/chet/src/bash/src/parse.y"
2569 { (yyval.element).word = (yyvsp[(1) - (1)].word); (yyval.element).redirect = 0; }
2573 #line 705 "/usr/homes/chet/src/bash/src/parse.y"
2574 { (yyval.element).redirect = (yyvsp[(1) - (1)].redirect); (yyval.element).word = 0; }
2578 #line 709 "/usr/homes/chet/src/bash/src/parse.y"
2580 (yyval.redirect) = (yyvsp[(1) - (1)].redirect);
2585 #line 713 "/usr/homes/chet/src/bash/src/parse.y"
2587 register REDIRECT *t;
2589 for (t = (yyvsp[(1) - (2)].redirect); t->next; t = t->next)
2591 t->next = (yyvsp[(2) - (2)].redirect);
2592 (yyval.redirect) = (yyvsp[(1) - (2)].redirect);
2597 #line 724 "/usr/homes/chet/src/bash/src/parse.y"
2598 { (yyval.command) = make_simple_command ((yyvsp[(1) - (1)].element), (COMMAND *)NULL); }
2602 #line 726 "/usr/homes/chet/src/bash/src/parse.y"
2603 { (yyval.command) = make_simple_command ((yyvsp[(2) - (2)].element), (yyvsp[(1) - (2)].command)); }
2607 #line 730 "/usr/homes/chet/src/bash/src/parse.y"
2608 { (yyval.command) = clean_simple_command ((yyvsp[(1) - (1)].command)); }
2612 #line 732 "/usr/homes/chet/src/bash/src/parse.y"
2613 { (yyval.command) = (yyvsp[(1) - (1)].command); }
2617 #line 734 "/usr/homes/chet/src/bash/src/parse.y"
2621 tc = (yyvsp[(1) - (2)].command);
2624 register REDIRECT *t;
2625 for (t = tc->redirects; t->next; t = t->next)
2627 t->next = (yyvsp[(2) - (2)].redirect);
2630 tc->redirects = (yyvsp[(2) - (2)].redirect);
2631 (yyval.command) = (yyvsp[(1) - (2)].command);
2636 #line 750 "/usr/homes/chet/src/bash/src/parse.y"
2637 { (yyval.command) = (yyvsp[(1) - (1)].command); }
2641 #line 752 "/usr/homes/chet/src/bash/src/parse.y"
2642 { (yyval.command) = (yyvsp[(1) - (1)].command); }
2646 #line 756 "/usr/homes/chet/src/bash/src/parse.y"
2647 { (yyval.command) = (yyvsp[(1) - (1)].command); }
2651 #line 758 "/usr/homes/chet/src/bash/src/parse.y"
2652 { (yyval.command) = (yyvsp[(1) - (1)].command); }
2656 #line 760 "/usr/homes/chet/src/bash/src/parse.y"
2657 { (yyval.command) = make_while_command ((yyvsp[(2) - (5)].command), (yyvsp[(4) - (5)].command)); }
2661 #line 762 "/usr/homes/chet/src/bash/src/parse.y"
2662 { (yyval.command) = make_until_command ((yyvsp[(2) - (5)].command), (yyvsp[(4) - (5)].command)); }
2666 #line 764 "/usr/homes/chet/src/bash/src/parse.y"
2667 { (yyval.command) = (yyvsp[(1) - (1)].command); }
2671 #line 766 "/usr/homes/chet/src/bash/src/parse.y"
2672 { (yyval.command) = (yyvsp[(1) - (1)].command); }
2676 #line 768 "/usr/homes/chet/src/bash/src/parse.y"
2677 { (yyval.command) = (yyvsp[(1) - (1)].command); }
2681 #line 770 "/usr/homes/chet/src/bash/src/parse.y"
2682 { (yyval.command) = (yyvsp[(1) - (1)].command); }
2686 #line 772 "/usr/homes/chet/src/bash/src/parse.y"
2687 { (yyval.command) = (yyvsp[(1) - (1)].command); }
2691 #line 774 "/usr/homes/chet/src/bash/src/parse.y"
2692 { (yyval.command) = (yyvsp[(1) - (1)].command); }
2696 #line 776 "/usr/homes/chet/src/bash/src/parse.y"
2697 { (yyval.command) = (yyvsp[(1) - (1)].command); }
2701 #line 780 "/usr/homes/chet/src/bash/src/parse.y"
2703 (yyval.command) = make_for_command ((yyvsp[(2) - (6)].word), add_string_to_list ("\"$@\"", (WORD_LIST *)NULL), (yyvsp[(5) - (6)].command), word_lineno[word_top]);
2704 if (word_top > 0) word_top--;
2709 #line 785 "/usr/homes/chet/src/bash/src/parse.y"
2711 (yyval.command) = make_for_command ((yyvsp[(2) - (6)].word), add_string_to_list ("\"$@\"", (WORD_LIST *)NULL), (yyvsp[(5) - (6)].command), word_lineno[word_top]);
2712 if (word_top > 0) word_top--;
2717 #line 790 "/usr/homes/chet/src/bash/src/parse.y"
2719 (yyval.command) = make_for_command ((yyvsp[(2) - (7)].word), add_string_to_list ("\"$@\"", (WORD_LIST *)NULL), (yyvsp[(6) - (7)].command), word_lineno[word_top]);
2720 if (word_top > 0) word_top--;
2725 #line 795 "/usr/homes/chet/src/bash/src/parse.y"
2727 (yyval.command) = make_for_command ((yyvsp[(2) - (7)].word), add_string_to_list ("\"$@\"", (WORD_LIST *)NULL), (yyvsp[(6) - (7)].command), word_lineno[word_top]);
2728 if (word_top > 0) word_top--;
2733 #line 800 "/usr/homes/chet/src/bash/src/parse.y"
2735 (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]);
2736 if (word_top > 0) word_top--;
2741 #line 805 "/usr/homes/chet/src/bash/src/parse.y"
2743 (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]);
2744 if (word_top > 0) word_top--;
2749 #line 810 "/usr/homes/chet/src/bash/src/parse.y"
2751 (yyval.command) = make_for_command ((yyvsp[(2) - (9)].word), (WORD_LIST *)NULL, (yyvsp[(8) - (9)].command), word_lineno[word_top]);
2752 if (word_top > 0) word_top--;
2757 #line 815 "/usr/homes/chet/src/bash/src/parse.y"
2759 (yyval.command) = make_for_command ((yyvsp[(2) - (9)].word), (WORD_LIST *)NULL, (yyvsp[(8) - (9)].command), word_lineno[word_top]);
2760 if (word_top > 0) word_top--;
2765 #line 822 "/usr/homes/chet/src/bash/src/parse.y"
2767 (yyval.command) = make_arith_for_command ((yyvsp[(2) - (7)].word_list), (yyvsp[(6) - (7)].command), arith_for_lineno);
2768 if (word_top > 0) word_top--;
2773 #line 827 "/usr/homes/chet/src/bash/src/parse.y"
2775 (yyval.command) = make_arith_for_command ((yyvsp[(2) - (7)].word_list), (yyvsp[(6) - (7)].command), arith_for_lineno);
2776 if (word_top > 0) word_top--;
2781 #line 832 "/usr/homes/chet/src/bash/src/parse.y"
2783 (yyval.command) = make_arith_for_command ((yyvsp[(2) - (5)].word_list), (yyvsp[(4) - (5)].command), arith_for_lineno);
2784 if (word_top > 0) word_top--;
2789 #line 837 "/usr/homes/chet/src/bash/src/parse.y"
2791 (yyval.command) = make_arith_for_command ((yyvsp[(2) - (5)].word_list), (yyvsp[(4) - (5)].command), arith_for_lineno);
2792 if (word_top > 0) word_top--;
2797 #line 844 "/usr/homes/chet/src/bash/src/parse.y"
2799 (yyval.command) = make_select_command ((yyvsp[(2) - (6)].word), add_string_to_list ("\"$@\"", (WORD_LIST *)NULL), (yyvsp[(5) - (6)].command), word_lineno[word_top]);
2800 if (word_top > 0) word_top--;
2805 #line 849 "/usr/homes/chet/src/bash/src/parse.y"
2807 (yyval.command) = make_select_command ((yyvsp[(2) - (6)].word), add_string_to_list ("\"$@\"", (WORD_LIST *)NULL), (yyvsp[(5) - (6)].command), word_lineno[word_top]);
2808 if (word_top > 0) word_top--;
2813 #line 854 "/usr/homes/chet/src/bash/src/parse.y"
2815 (yyval.command) = make_select_command ((yyvsp[(2) - (7)].word), add_string_to_list ("\"$@\"", (WORD_LIST *)NULL), (yyvsp[(6) - (7)].command), word_lineno[word_top]);
2816 if (word_top > 0) word_top--;
2821 #line 859 "/usr/homes/chet/src/bash/src/parse.y"
2823 (yyval.command) = make_select_command ((yyvsp[(2) - (7)].word), add_string_to_list ("\"$@\"", (WORD_LIST *)NULL), (yyvsp[(6) - (7)].command), word_lineno[word_top]);
2824 if (word_top > 0) word_top--;
2829 #line 864 "/usr/homes/chet/src/bash/src/parse.y"
2831 (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]);
2832 if (word_top > 0) word_top--;
2837 #line 869 "/usr/homes/chet/src/bash/src/parse.y"
2839 (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]);
2840 if (word_top > 0) word_top--;
2845 #line 876 "/usr/homes/chet/src/bash/src/parse.y"
2847 (yyval.command) = make_case_command ((yyvsp[(2) - (6)].word), (PATTERN_LIST *)NULL, word_lineno[word_top]);
2848 if (word_top > 0) word_top--;
2853 #line 881 "/usr/homes/chet/src/bash/src/parse.y"
2855 (yyval.command) = make_case_command ((yyvsp[(2) - (7)].word), (yyvsp[(5) - (7)].pattern), word_lineno[word_top]);
2856 if (word_top > 0) word_top--;
2861 #line 886 "/usr/homes/chet/src/bash/src/parse.y"
2863 (yyval.command) = make_case_command ((yyvsp[(2) - (6)].word), (yyvsp[(5) - (6)].pattern), word_lineno[word_top]);
2864 if (word_top > 0) word_top--;
2869 #line 893 "/usr/homes/chet/src/bash/src/parse.y"
2870 { (yyval.command) = make_function_def ((yyvsp[(1) - (5)].word), (yyvsp[(5) - (5)].command), function_dstart, function_bstart); }
2874 #line 896 "/usr/homes/chet/src/bash/src/parse.y"
2875 { (yyval.command) = make_function_def ((yyvsp[(2) - (6)].word), (yyvsp[(6) - (6)].command), function_dstart, function_bstart); }
2879 #line 899 "/usr/homes/chet/src/bash/src/parse.y"
2880 { (yyval.command) = make_function_def ((yyvsp[(2) - (4)].word), (yyvsp[(4) - (4)].command), function_dstart, function_bstart); }
2884 #line 903 "/usr/homes/chet/src/bash/src/parse.y"
2885 { (yyval.command) = (yyvsp[(1) - (1)].command); }
2889 #line 905 "/usr/homes/chet/src/bash/src/parse.y"
2893 tc = (yyvsp[(1) - (2)].command);
2894 /* According to Posix.2 3.9.5, redirections
2895 specified after the body of a function should
2896 be attached to the function and performed when
2897 the function is executed, not as part of the
2898 function definition command. */
2899 /* XXX - I don't think it matters, but we might
2900 want to change this in the future to avoid
2901 problems differentiating between a function
2902 definition with a redirection and a function
2903 definition containing a single command with a
2904 redirection. The two are semantically equivalent,
2905 though -- the only difference is in how the
2906 command printing code displays the redirections. */
2909 register REDIRECT *t;
2910 for (t = tc->redirects; t->next; t = t->next)
2912 t->next = (yyvsp[(2) - (2)].redirect);
2915 tc->redirects = (yyvsp[(2) - (2)].redirect);
2916 (yyval.command) = (yyvsp[(1) - (2)].command);
2921 #line 936 "/usr/homes/chet/src/bash/src/parse.y"
2923 (yyval.command) = make_subshell_command ((yyvsp[(2) - (3)].command));
2924 (yyval.command)->flags |= CMD_WANT_SUBSHELL;
2929 #line 943 "/usr/homes/chet/src/bash/src/parse.y"
2931 (yyval.command) = make_coproc_command ("COPROC", (yyvsp[(2) - (2)].command));
2932 (yyval.command)->flags |= CMD_WANT_SUBSHELL|CMD_COPROC_SUBSHELL;
2937 #line 948 "/usr/homes/chet/src/bash/src/parse.y"
2941 tc = (yyvsp[(2) - (3)].command);
2944 register REDIRECT *t;
2945 for (t = tc->redirects; t->next; t = t->next)
2947 t->next = (yyvsp[(3) - (3)].redirect);
2950 tc->redirects = (yyvsp[(3) - (3)].redirect);
2951 (yyval.command) = make_coproc_command ("COPROC", (yyvsp[(2) - (3)].command));
2952 (yyval.command)->flags |= CMD_WANT_SUBSHELL|CMD_COPROC_SUBSHELL;
2957 #line 965 "/usr/homes/chet/src/bash/src/parse.y"
2959 (yyval.command) = make_coproc_command ((yyvsp[(2) - (3)].word)->word, (yyvsp[(3) - (3)].command));
2960 (yyval.command)->flags |= CMD_WANT_SUBSHELL|CMD_COPROC_SUBSHELL;
2965 #line 970 "/usr/homes/chet/src/bash/src/parse.y"
2969 tc = (yyvsp[(3) - (4)].command);
2972 register REDIRECT *t;
2973 for (t = tc->redirects; t->next; t = t->next)
2975 t->next = (yyvsp[(4) - (4)].redirect);
2978 tc->redirects = (yyvsp[(4) - (4)].redirect);
2979 (yyval.command) = make_coproc_command ((yyvsp[(2) - (4)].word)->word, (yyvsp[(3) - (4)].command));
2980 (yyval.command)->flags |= CMD_WANT_SUBSHELL|CMD_COPROC_SUBSHELL;
2985 #line 987 "/usr/homes/chet/src/bash/src/parse.y"
2987 (yyval.command) = make_coproc_command ("COPROC", clean_simple_command ((yyvsp[(2) - (2)].command)));
2988 (yyval.command)->flags |= CMD_WANT_SUBSHELL|CMD_COPROC_SUBSHELL;
2993 #line 994 "/usr/homes/chet/src/bash/src/parse.y"
2994 { (yyval.command) = make_if_command ((yyvsp[(2) - (5)].command), (yyvsp[(4) - (5)].command), (COMMAND *)NULL); }
2998 #line 996 "/usr/homes/chet/src/bash/src/parse.y"
2999 { (yyval.command) = make_if_command ((yyvsp[(2) - (7)].command), (yyvsp[(4) - (7)].command), (yyvsp[(6) - (7)].command)); }
3003 #line 998 "/usr/homes/chet/src/bash/src/parse.y"
3004 { (yyval.command) = make_if_command ((yyvsp[(2) - (6)].command), (yyvsp[(4) - (6)].command), (yyvsp[(5) - (6)].command)); }
3008 #line 1003 "/usr/homes/chet/src/bash/src/parse.y"
3009 { (yyval.command) = make_group_command ((yyvsp[(2) - (3)].command)); }
3013 #line 1007 "/usr/homes/chet/src/bash/src/parse.y"
3014 { (yyval.command) = make_arith_command ((yyvsp[(1) - (1)].word_list)); }
3018 #line 1011 "/usr/homes/chet/src/bash/src/parse.y"
3019 { (yyval.command) = (yyvsp[(2) - (3)].command); }
3023 #line 1015 "/usr/homes/chet/src/bash/src/parse.y"
3024 { (yyval.command) = make_if_command ((yyvsp[(2) - (4)].command), (yyvsp[(4) - (4)].command), (COMMAND *)NULL); }
3028 #line 1017 "/usr/homes/chet/src/bash/src/parse.y"
3029 { (yyval.command) = make_if_command ((yyvsp[(2) - (6)].command), (yyvsp[(4) - (6)].command), (yyvsp[(6) - (6)].command)); }
3033 #line 1019 "/usr/homes/chet/src/bash/src/parse.y"
3034 { (yyval.command) = make_if_command ((yyvsp[(2) - (5)].command), (yyvsp[(4) - (5)].command), (yyvsp[(5) - (5)].command)); }
3038 #line 1024 "/usr/homes/chet/src/bash/src/parse.y"
3039 { (yyvsp[(2) - (2)].pattern)->next = (yyvsp[(1) - (2)].pattern); (yyval.pattern) = (yyvsp[(2) - (2)].pattern); }
3043 #line 1028 "/usr/homes/chet/src/bash/src/parse.y"
3044 { (yyval.pattern) = make_pattern_list ((yyvsp[(2) - (4)].word_list), (yyvsp[(4) - (4)].command)); }
3048 #line 1030 "/usr/homes/chet/src/bash/src/parse.y"
3049 { (yyval.pattern) = make_pattern_list ((yyvsp[(2) - (4)].word_list), (COMMAND *)NULL); }
3053 #line 1032 "/usr/homes/chet/src/bash/src/parse.y"
3054 { (yyval.pattern) = make_pattern_list ((yyvsp[(3) - (5)].word_list), (yyvsp[(5) - (5)].command)); }
3058 #line 1034 "/usr/homes/chet/src/bash/src/parse.y"
3059 { (yyval.pattern) = make_pattern_list ((yyvsp[(3) - (5)].word_list), (COMMAND *)NULL); }
3063 #line 1038 "/usr/homes/chet/src/bash/src/parse.y"
3064 { (yyval.pattern) = (yyvsp[(1) - (2)].pattern); }
3068 #line 1040 "/usr/homes/chet/src/bash/src/parse.y"
3069 { (yyvsp[(2) - (3)].pattern)->next = (yyvsp[(1) - (3)].pattern); (yyval.pattern) = (yyvsp[(2) - (3)].pattern); }
3073 #line 1042 "/usr/homes/chet/src/bash/src/parse.y"
3074 { (yyvsp[(1) - (2)].pattern)->flags |= CASEPAT_FALLTHROUGH; (yyval.pattern) = (yyvsp[(1) - (2)].pattern); }
3078 #line 1044 "/usr/homes/chet/src/bash/src/parse.y"
3079 { (yyvsp[(2) - (3)].pattern)->flags |= CASEPAT_FALLTHROUGH; (yyvsp[(2) - (3)].pattern)->next = (yyvsp[(1) - (3)].pattern); (yyval.pattern) = (yyvsp[(2) - (3)].pattern); }
3083 #line 1046 "/usr/homes/chet/src/bash/src/parse.y"
3084 { (yyvsp[(1) - (2)].pattern)->flags |= CASEPAT_TESTNEXT; (yyval.pattern) = (yyvsp[(1) - (2)].pattern); }
3088 #line 1048 "/usr/homes/chet/src/bash/src/parse.y"
3089 { (yyvsp[(2) - (3)].pattern)->flags |= CASEPAT_TESTNEXT; (yyvsp[(2) - (3)].pattern)->next = (yyvsp[(1) - (3)].pattern); (yyval.pattern) = (yyvsp[(2) - (3)].pattern); }
3093 #line 1052 "/usr/homes/chet/src/bash/src/parse.y"
3094 { (yyval.word_list) = make_word_list ((yyvsp[(1) - (1)].word), (WORD_LIST *)NULL); }
3098 #line 1054 "/usr/homes/chet/src/bash/src/parse.y"
3099 { (yyval.word_list) = make_word_list ((yyvsp[(3) - (3)].word), (yyvsp[(1) - (3)].word_list)); }
3103 #line 1063 "/usr/homes/chet/src/bash/src/parse.y"
3105 (yyval.command) = (yyvsp[(2) - (2)].command);
3107 gather_here_documents ();
3112 #line 1072 "/usr/homes/chet/src/bash/src/parse.y"
3114 (yyval.command) = (yyvsp[(2) - (2)].command);
3119 #line 1079 "/usr/homes/chet/src/bash/src/parse.y"
3121 if ((yyvsp[(1) - (3)].command)->type == cm_connection)
3122 (yyval.command) = connect_async_list ((yyvsp[(1) - (3)].command), (COMMAND *)NULL, '&');
3124 (yyval.command) = command_connect ((yyvsp[(1) - (3)].command), (COMMAND *)NULL, '&');
3129 #line 1090 "/usr/homes/chet/src/bash/src/parse.y"
3130 { (yyval.command) = command_connect ((yyvsp[(1) - (4)].command), (yyvsp[(4) - (4)].command), AND_AND); }
3134 #line 1092 "/usr/homes/chet/src/bash/src/parse.y"
3135 { (yyval.command) = command_connect ((yyvsp[(1) - (4)].command), (yyvsp[(4) - (4)].command), OR_OR); }
3139 #line 1094 "/usr/homes/chet/src/bash/src/parse.y"
3141 if ((yyvsp[(1) - (4)].command)->type == cm_connection)
3142 (yyval.command) = connect_async_list ((yyvsp[(1) - (4)].command), (yyvsp[(4) - (4)].command), '&');
3144 (yyval.command) = command_connect ((yyvsp[(1) - (4)].command), (yyvsp[(4) - (4)].command), '&');
3149 #line 1101 "/usr/homes/chet/src/bash/src/parse.y"
3150 { (yyval.command) = command_connect ((yyvsp[(1) - (4)].command), (yyvsp[(4) - (4)].command), ';'); }
3154 #line 1103 "/usr/homes/chet/src/bash/src/parse.y"
3155 { (yyval.command) = command_connect ((yyvsp[(1) - (4)].command), (yyvsp[(4) - (4)].command), ';'); }
3159 #line 1105 "/usr/homes/chet/src/bash/src/parse.y"
3160 { (yyval.command) = (yyvsp[(1) - (1)].command); }
3164 #line 1113 "/usr/homes/chet/src/bash/src/parse.y"
3165 { (yyval.number) = '\n'; }
3169 #line 1115 "/usr/homes/chet/src/bash/src/parse.y"
3170 { (yyval.number) = ';'; }
3174 #line 1117 "/usr/homes/chet/src/bash/src/parse.y"
3175 { (yyval.number) = yacc_EOF; }
3179 #line 1131 "/usr/homes/chet/src/bash/src/parse.y"
3181 (yyval.command) = (yyvsp[(1) - (1)].command);
3183 gather_here_documents ();
3184 if ((parser_state & PST_CMDSUBST) && current_token == shell_eof_token)
3186 global_command = (yyvsp[(1) - (1)].command);
3187 eof_encountered = 0;
3188 rewind_input_string ();
3195 #line 1144 "/usr/homes/chet/src/bash/src/parse.y"
3197 if ((yyvsp[(1) - (2)].command)->type == cm_connection)
3198 (yyval.command) = connect_async_list ((yyvsp[(1) - (2)].command), (COMMAND *)NULL, '&');
3200 (yyval.command) = command_connect ((yyvsp[(1) - (2)].command), (COMMAND *)NULL, '&');
3202 gather_here_documents ();
3203 if ((parser_state & PST_CMDSUBST) && current_token == shell_eof_token)
3205 global_command = (yyvsp[(1) - (2)].command);
3206 eof_encountered = 0;
3207 rewind_input_string ();
3214 #line 1160 "/usr/homes/chet/src/bash/src/parse.y"
3216 (yyval.command) = (yyvsp[(1) - (2)].command);
3218 gather_here_documents ();
3219 if ((parser_state & PST_CMDSUBST) && current_token == shell_eof_token)
3221 global_command = (yyvsp[(1) - (2)].command);
3222 eof_encountered = 0;
3223 rewind_input_string ();
3230 #line 1175 "/usr/homes/chet/src/bash/src/parse.y"
3231 { (yyval.command) = command_connect ((yyvsp[(1) - (4)].command), (yyvsp[(4) - (4)].command), AND_AND); }
3235 #line 1177 "/usr/homes/chet/src/bash/src/parse.y"
3236 { (yyval.command) = command_connect ((yyvsp[(1) - (4)].command), (yyvsp[(4) - (4)].command), OR_OR); }
3240 #line 1179 "/usr/homes/chet/src/bash/src/parse.y"
3242 if ((yyvsp[(1) - (3)].command)->type == cm_connection)
3243 (yyval.command) = connect_async_list ((yyvsp[(1) - (3)].command), (yyvsp[(3) - (3)].command), '&');
3245 (yyval.command) = command_connect ((yyvsp[(1) - (3)].command), (yyvsp[(3) - (3)].command), '&');
3250 #line 1186 "/usr/homes/chet/src/bash/src/parse.y"
3251 { (yyval.command) = command_connect ((yyvsp[(1) - (3)].command), (yyvsp[(3) - (3)].command), ';'); }
3255 #line 1189 "/usr/homes/chet/src/bash/src/parse.y"
3256 { (yyval.command) = (yyvsp[(1) - (1)].command); }
3260 #line 1193 "/usr/homes/chet/src/bash/src/parse.y"
3261 { (yyval.command) = (yyvsp[(1) - (1)].command); }
3265 #line 1195 "/usr/homes/chet/src/bash/src/parse.y"
3267 if ((yyvsp[(2) - (2)].command))
3268 (yyvsp[(2) - (2)].command)->flags ^= CMD_INVERT_RETURN; /* toggle */
3269 (yyval.command) = (yyvsp[(2) - (2)].command);
3274 #line 1201 "/usr/homes/chet/src/bash/src/parse.y"
3276 if ((yyvsp[(2) - (2)].command))
3277 (yyvsp[(2) - (2)].command)->flags |= (yyvsp[(1) - (2)].number);
3278 (yyval.command) = (yyvsp[(2) - (2)].command);
3283 #line 1207 "/usr/homes/chet/src/bash/src/parse.y"
3287 /* Boy, this is unclean. `time' by itself can
3288 time a null command. We cheat and push a
3289 newline back if the list_terminator was a newline
3290 to avoid the double-newline problem (one to
3291 terminate this, one to terminate the command) */
3294 (yyval.command) = make_simple_command (x, (COMMAND *)NULL);
3295 (yyval.command)->flags |= (yyvsp[(1) - (2)].number);
3296 /* XXX - let's cheat and push a newline back */
3297 if ((yyvsp[(2) - (2)].number) == '\n')
3298 token_to_read = '\n';
3303 #line 1224 "/usr/homes/chet/src/bash/src/parse.y"
3307 /* This is just as unclean. Posix says that `!'
3308 by itself should be equivalent to `false'.
3310 newline back if the list_terminator was a newline
3311 to avoid the double-newline problem (one to
3312 terminate this, one to terminate the command) */
3315 (yyval.command) = make_simple_command (x, (COMMAND *)NULL);
3316 (yyval.command)->flags |= CMD_INVERT_RETURN;
3317 /* XXX - let's cheat and push a newline back */
3318 if ((yyvsp[(2) - (2)].number) == '\n')
3319 token_to_read = '\n';
3324 #line 1244 "/usr/homes/chet/src/bash/src/parse.y"
3325 { (yyval.command) = command_connect ((yyvsp[(1) - (4)].command), (yyvsp[(4) - (4)].command), '|'); }
3329 #line 1246 "/usr/homes/chet/src/bash/src/parse.y"
3331 /* Make cmd1 |& cmd2 equivalent to cmd1 2>&1 | cmd2 */
3336 tc = (yyvsp[(1) - (4)].command)->type == cm_simple ? (COMMAND *)(yyvsp[(1) - (4)].command)->value.Simple : (yyvsp[(1) - (4)].command);
3339 r = make_redirection (sd, r_duplicating_output, rd, 0);
3342 register REDIRECT *t;
3343 for (t = tc->redirects; t->next; t = t->next)
3350 (yyval.command) = command_connect ((yyvsp[(1) - (4)].command), (yyvsp[(4) - (4)].command), '|');
3355 #line 1269 "/usr/homes/chet/src/bash/src/parse.y"
3356 { (yyval.command) = (yyvsp[(1) - (1)].command); }
3360 #line 1273 "/usr/homes/chet/src/bash/src/parse.y"
3361 { (yyval.number) = CMD_TIME_PIPELINE; }
3365 #line 1275 "/usr/homes/chet/src/bash/src/parse.y"
3366 { (yyval.number) = CMD_TIME_PIPELINE|CMD_TIME_POSIX; }
3370 #line 1277 "/usr/homes/chet/src/bash/src/parse.y"
3371 { (yyval.number) = CMD_TIME_PIPELINE|CMD_TIME_POSIX; }
3375 /* Line 1267 of yacc.c. */
3376 #line 3377 "y.tab.c"
3379 YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc);
3383 YY_STACK_PRINT (yyss, yyssp);
3388 /* Now `shift' the result of the reduction. Determine what state
3389 that goes to, based on the state we popped back to and the rule
3390 number reduced by. */
3394 yystate = yypgoto[yyn - YYNTOKENS] + *yyssp;
3395 if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp)
3396 yystate = yytable[yystate];
3398 yystate = yydefgoto[yyn - YYNTOKENS];
3403 /*------------------------------------.
3404 | yyerrlab -- here on detecting error |
3405 `------------------------------------*/
3407 /* If not already recovering from an error, report this error. */
3411 #if ! YYERROR_VERBOSE
3412 yyerror (YY_("syntax error"));
3415 YYSIZE_T yysize = yysyntax_error (0, yystate, yychar);
3416 if (yymsg_alloc < yysize && yymsg_alloc < YYSTACK_ALLOC_MAXIMUM)
3418 YYSIZE_T yyalloc = 2 * yysize;
3419 if (! (yysize <= yyalloc && yyalloc <= YYSTACK_ALLOC_MAXIMUM))
3420 yyalloc = YYSTACK_ALLOC_MAXIMUM;
3421 if (yymsg != yymsgbuf)
3422 YYSTACK_FREE (yymsg);
3423 yymsg = (char *) YYSTACK_ALLOC (yyalloc);
3425 yymsg_alloc = yyalloc;
3429 yymsg_alloc = sizeof yymsgbuf;
3433 if (0 < yysize && yysize <= yymsg_alloc)
3435 (void) yysyntax_error (yymsg, yystate, yychar);
3440 yyerror (YY_("syntax error"));
3442 goto yyexhaustedlab;
3450 if (yyerrstatus == 3)
3452 /* If just tried and failed to reuse look-ahead token after an
3453 error, discard it. */
3455 if (yychar <= YYEOF)
3457 /* Return failure if at end of input. */
3458 if (yychar == YYEOF)
3463 yydestruct ("Error: discarding",
3469 /* Else will try to reuse look-ahead token after shifting the error
3474 /*---------------------------------------------------.
3475 | yyerrorlab -- error raised explicitly by YYERROR. |
3476 `---------------------------------------------------*/
3479 /* Pacify compilers like GCC when the user code never invokes
3480 YYERROR and the label yyerrorlab therefore never appears in user
3482 if (/*CONSTCOND*/ 0)
3485 /* Do not reclaim the symbols of the rule which action triggered
3489 YY_STACK_PRINT (yyss, yyssp);
3494 /*-------------------------------------------------------------.
3495 | yyerrlab1 -- common code for both syntax error and YYERROR. |
3496 `-------------------------------------------------------------*/
3498 yyerrstatus = 3; /* Each real token shifted decrements this. */
3502 yyn = yypact[yystate];
3503 if (yyn != YYPACT_NINF)
3506 if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
3514 /* Pop the current state because it cannot handle the error token. */
3519 yydestruct ("Error: popping",
3520 yystos[yystate], yyvsp);
3523 YY_STACK_PRINT (yyss, yyssp);
3532 /* Shift the error token. */
3533 YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp);
3539 /*-------------------------------------.
3540 | yyacceptlab -- YYACCEPT comes here. |
3541 `-------------------------------------*/
3546 /*-----------------------------------.
3547 | yyabortlab -- YYABORT comes here. |
3548 `-----------------------------------*/
3554 /*-------------------------------------------------.
3555 | yyexhaustedlab -- memory exhaustion comes here. |
3556 `-------------------------------------------------*/
3558 yyerror (YY_("memory exhausted"));
3564 if (yychar != YYEOF && yychar != YYEMPTY)
3565 yydestruct ("Cleanup: discarding lookahead",
3567 /* Do not reclaim the symbols of the rule which action triggered
3568 this YYABORT or YYACCEPT. */
3570 YY_STACK_PRINT (yyss, yyssp);
3571 while (yyssp != yyss)
3573 yydestruct ("Cleanup: popping",
3574 yystos[*yyssp], yyvsp);
3579 YYSTACK_FREE (yyss);
3582 if (yymsg != yymsgbuf)
3583 YYSTACK_FREE (yymsg);
3585 /* Make sure YYID is used. */
3586 return YYID (yyresult);
3590 #line 1279 "/usr/homes/chet/src/bash/src/parse.y"
3593 /* Initial size to allocate for tokens, and the
3594 amount to grow them by. */
3595 #define TOKEN_DEFAULT_INITIAL_SIZE 496
3596 #define TOKEN_DEFAULT_GROW_SIZE 512
3598 /* Should we call prompt_again? */
3599 #define SHOULD_PROMPT() \
3600 (interactive && (bash_input.type == st_stdin || bash_input.type == st_stream))
3603 # define expanding_alias() (pushed_string_list && pushed_string_list->expander)
3605 # define expanding_alias() 0
3608 /* Global var is non-zero when end of file has been reached. */
3609 int EOF_Reached = 0;
3622 /* yy_getc () returns the next available character from input or EOF.
3623 yy_ungetc (c) makes `c' the next character to read.
3624 init_yy_io (get, unget, type, location) makes the function GET the
3625 installed function for getting the next character, makes UNGET the
3626 installed function for un-getting a character, sets the type of stream
3627 (either string or file) from TYPE, and makes LOCATION point to where
3628 the input is coming from. */
3630 /* Unconditionally returns end-of-file. */
3637 /* Variable containing the current get and unget functions.
3638 See ./input.h for a clearer description. */
3639 BASH_INPUT bash_input;
3641 /* Set all of the fields in BASH_INPUT to NULL. Free bash_input.name if it
3642 is non-null, avoiding a memory leak. */
3644 initialize_bash_input ()
3646 bash_input.type = st_none;
3647 FREE (bash_input.name);
3648 bash_input.name = (char *)NULL;
3649 bash_input.location.file = (FILE *)NULL;
3650 bash_input.location.string = (char *)NULL;
3651 bash_input.getter = (sh_cget_func_t *)NULL;
3652 bash_input.ungetter = (sh_cunget_func_t *)NULL;
3655 /* Set the contents of the current bash input stream from
3656 GET, UNGET, TYPE, NAME, and LOCATION. */
3658 init_yy_io (get, unget, type, name, location)
3659 sh_cget_func_t *get;
3660 sh_cunget_func_t *unget;
3661 enum stream_type type;
3663 INPUT_STREAM location;
3665 bash_input.type = type;
3666 FREE (bash_input.name);
3667 bash_input.name = name ? savestring (name) : (char *)NULL;
3671 memcpy((char *)&bash_input.location.string, (char *)&location.string, sizeof(location));
3673 bash_input.location = location;
3675 bash_input.getter = get;
3676 bash_input.ungetter = unget;
3682 return (bash_input.name ? bash_input.name : "stdin");
3685 /* Call this to get the next character of input. */
3689 return (*(bash_input.getter)) ();
3692 /* Call this to unget C. That is, to make C the next character
3698 return (*(bash_input.ungetter)) (c);
3701 #if defined (BUFFERED_INPUT)
3702 #ifdef INCLUDE_UNUSED
3704 input_file_descriptor ()
3706 switch (bash_input.type)
3709 return (fileno (bash_input.location.file));
3711 return (bash_input.location.buffered_fd);
3714 return (fileno (stdin));
3718 #endif /* BUFFERED_INPUT */
3720 /* **************************************************************** */
3722 /* Let input be read from readline (). */
3724 /* **************************************************************** */
3726 #if defined (READLINE)
3727 char *current_readline_prompt = (char *)NULL;
3728 char *current_readline_line = (char *)NULL;
3729 int current_readline_line_index = 0;
3734 SigHandler *old_sigint;
3738 if (!current_readline_line)
3740 if (!bash_readline_initialized)
3741 initialize_readline ();
3743 #if defined (JOB_CONTROL)
3745 give_terminal_to (shell_pgrp, 0);
3746 #endif /* JOB_CONTROL */
3748 old_sigint = (SigHandler *)IMPOSSIBLE_TRAP_HANDLER;
3749 if (signal_is_ignored (SIGINT) == 0)
3751 /* interrupt_immediately++; */
3752 old_sigint = (SigHandler *)set_signal_handler (SIGINT, sigint_sighandler);
3755 current_readline_line = readline (current_readline_prompt ?
3756 current_readline_prompt : "");
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++;
3922 /* XXX - don't need terminate_immediately; getc_with_restart checks
3923 for terminating signals itself if read returns < 0 */
3924 result = getc_with_restart (bash_input.location.file);
3928 interrupt_immediately--;
3938 return (ungetc_with_restart (c, bash_input.location.file));
3942 with_input_from_stream (stream, name)
3946 INPUT_STREAM location;
3948 location.file = stream;
3949 init_yy_io (yy_stream_get, yy_stream_unget, st_stream, name, location);
3952 typedef struct stream_saver {
3953 struct stream_saver *next;
3954 BASH_INPUT bash_input;
3956 #if defined (BUFFERED_INPUT)
3957 BUFFERED_STREAM *bstream;
3958 #endif /* BUFFERED_INPUT */
3961 /* The globally known line number. */
3962 int line_number = 0;
3964 /* The line number offset set by assigning to LINENO. Not currently used. */
3965 int line_number_base = 0;
3967 #if defined (COND_COMMAND)
3968 static int cond_lineno;
3969 static int cond_token;
3972 STREAM_SAVER *stream_list = (STREAM_SAVER *)NULL;
3975 push_stream (reset_lineno)
3978 STREAM_SAVER *saver = (STREAM_SAVER *)xmalloc (sizeof (STREAM_SAVER));
3980 xbcopy ((char *)&bash_input, (char *)&(saver->bash_input), sizeof (BASH_INPUT));
3982 #if defined (BUFFERED_INPUT)
3983 saver->bstream = (BUFFERED_STREAM *)NULL;
3984 /* If we have a buffered stream, clear out buffers[fd]. */
3985 if (bash_input.type == st_bstream && bash_input.location.buffered_fd >= 0)
3986 saver->bstream = set_buffered_stream (bash_input.location.buffered_fd,
3987 (BUFFERED_STREAM *)NULL);
3988 #endif /* BUFFERED_INPUT */
3990 saver->line = line_number;
3991 bash_input.name = (char *)NULL;
3992 saver->next = stream_list;
3993 stream_list = saver;
4006 STREAM_SAVER *saver = stream_list;
4009 stream_list = stream_list->next;
4011 init_yy_io (saver->bash_input.getter,
4012 saver->bash_input.ungetter,
4013 saver->bash_input.type,
4014 saver->bash_input.name,
4015 saver->bash_input.location);
4017 #if defined (BUFFERED_INPUT)
4018 /* If we have a buffered stream, restore buffers[fd]. */
4019 /* If the input file descriptor was changed while this was on the
4020 save stack, update the buffered fd to the new file descriptor and
4021 re-establish the buffer <-> bash_input fd correspondence. */
4022 if (bash_input.type == st_bstream && bash_input.location.buffered_fd >= 0)
4024 if (bash_input_fd_changed)
4026 bash_input_fd_changed = 0;
4027 if (default_buffered_input >= 0)
4029 bash_input.location.buffered_fd = default_buffered_input;
4030 saver->bstream->b_fd = default_buffered_input;
4031 SET_CLOSE_ON_EXEC (default_buffered_input);
4034 /* XXX could free buffered stream returned as result here. */
4035 set_buffered_stream (bash_input.location.buffered_fd, saver->bstream);
4037 #endif /* BUFFERED_INPUT */
4039 line_number = saver->line;
4041 FREE (saver->bash_input.name);
4046 /* Return 1 if a stream of type TYPE is saved on the stack. */
4048 stream_on_stack (type)
4049 enum stream_type type;
4051 register STREAM_SAVER *s;
4053 for (s = stream_list; s; s = s->next)
4054 if (s->bash_input.type == type)
4059 /* Save the current token state and return it in a malloced array. */
4065 ret = (int *)xmalloc (4 * sizeof (int));
4066 ret[0] = last_read_token;
4067 ret[1] = token_before_that;
4068 ret[2] = two_tokens_ago;
4069 ret[3] = current_token;
4074 restore_token_state (ts)
4079 last_read_token = ts[0];
4080 token_before_that = ts[1];
4081 two_tokens_ago = ts[2];
4082 current_token = ts[3];
4086 * This is used to inhibit alias expansion and reserved word recognition
4087 * inside case statement pattern lists. A `case statement pattern list' is:
4089 * everything between the `in' in a `case word in' and the next ')'
4091 * everything between a `;;' and the next `)' or `esac'
4094 #if defined (ALIAS) || defined (DPAREN_ARITHMETIC)
4096 #define END_OF_ALIAS 0
4099 * Pseudo-global variables used in implementing token-wise alias expansion.
4103 * Pushing and popping strings. This works together with shell_getc to
4104 * implement alias expansion on a per-token basis.
4107 #define PSH_ALIAS 0x01
4108 #define PSH_DPAREN 0x02
4109 #define PSH_SOURCE 0x04
4111 typedef struct string_saver {
4112 struct string_saver *next;
4113 int expand_alias; /* Value to set expand_alias to when string is popped. */
4116 alias_t *expander; /* alias that caused this line to be pushed. */
4118 size_t saved_line_size, saved_line_index;
4119 int saved_line_terminator;
4123 STRING_SAVER *pushed_string_list = (STRING_SAVER *)NULL;
4126 * Push the current shell_input_line onto a stack of such lines and make S
4127 * the current input. Used when expanding aliases. EXPAND is used to set
4128 * the value of expand_next_token when the string is popped, so that the
4129 * word after the alias in the original line is handled correctly when the
4130 * alias expands to multiple words. TOKEN is the token that was expanded
4131 * into S; it is saved and used to prevent infinite recursive expansion.
4134 push_string (s, expand, ap)
4139 STRING_SAVER *temp = (STRING_SAVER *)xmalloc (sizeof (STRING_SAVER));
4141 temp->expand_alias = expand;
4142 temp->saved_line = shell_input_line;
4143 temp->saved_line_size = shell_input_line_size;
4144 temp->saved_line_index = shell_input_line_index;
4145 temp->saved_line_terminator = shell_input_line_terminator;
4148 temp->expander = ap;
4150 temp->flags = PSH_ALIAS;
4152 temp->next = pushed_string_list;
4153 pushed_string_list = temp;
4157 ap->flags |= AL_BEINGEXPANDED;
4160 shell_input_line = s;
4161 shell_input_line_size = STRLEN (s);
4162 shell_input_line_index = 0;
4163 shell_input_line_terminator = '\0';
4165 parser_state &= ~PST_ALEXPNEXT; /* XXX */
4168 set_line_mbstate ();
4172 * Make the top of the pushed_string stack be the current shell input.
4173 * Only called when there is something on the stack. Called from shell_getc
4174 * when it thinks it has consumed the string generated by an alias expansion
4175 * and needs to return to the original input line.
4182 FREE (shell_input_line);
4183 shell_input_line = pushed_string_list->saved_line;
4184 shell_input_line_index = pushed_string_list->saved_line_index;
4185 shell_input_line_size = pushed_string_list->saved_line_size;
4186 shell_input_line_terminator = pushed_string_list->saved_line_terminator;
4188 if (pushed_string_list->expand_alias)
4189 parser_state |= PST_ALEXPNEXT;
4191 parser_state &= ~PST_ALEXPNEXT;
4193 t = pushed_string_list;
4194 pushed_string_list = pushed_string_list->next;
4198 t->expander->flags &= ~AL_BEINGEXPANDED;
4203 set_line_mbstate ();
4209 register STRING_SAVER *t, *t1;
4211 for (t = pushed_string_list; t; )
4214 FREE (t->saved_line);
4217 t->expander->flags &= ~AL_BEINGEXPANDED;
4222 pushed_string_list = (STRING_SAVER *)NULL;
4225 #endif /* ALIAS || DPAREN_ARITHMETIC */
4228 free_pushed_string_input ()
4230 #if defined (ALIAS) || defined (DPAREN_ARITHMETIC)
4231 free_string_list ();
4236 parser_expanding_alias ()
4238 return (expanding_alias ());
4242 parser_save_alias ()
4244 #if defined (ALIAS) || defined (DPAREN_ARITHMETIC)
4245 push_string ((char *)NULL, 0, (alias_t *)NULL);
4246 pushed_string_list->flags = PSH_SOURCE; /* XXX - for now */
4253 parser_restore_alias ()
4255 #if defined (ALIAS) || defined (DPAREN_ARITHMETIC)
4256 if (pushed_string_list)
4263 /* Return a line of text, taken from wherever yylex () reads input.
4264 If there is no more input, then we return NULL. If REMOVE_QUOTED_NEWLINE
4265 is non-zero, we remove unquoted \<newline> pairs. This is used by
4266 read_secondary_line to read here documents. */
4268 read_a_line (remove_quoted_newline)
4269 int remove_quoted_newline;
4271 static char *line_buffer = (char *)NULL;
4272 static int buffer_size = 0;
4273 int indx, c, peekc, pass_next;
4275 #if defined (READLINE)
4276 if (no_line_editing && SHOULD_PROMPT ())
4278 if (SHOULD_PROMPT ())
4282 pass_next = indx = 0;
4285 /* Allow immediate exit if interrupted during input. */
4290 /* Ignore null bytes in input. */
4294 internal_warning ("read_a_line: ignored null byte in input");
4299 /* If there is no more input, then we return NULL. */
4302 if (interactive && bash_input.type == st_stream)
4305 return ((char *)NULL);
4309 /* `+2' in case the final character in the buffer is a newline. */
4310 RESIZE_MALLOCED_BUFFER (line_buffer, indx, 2, buffer_size, 128);
4312 /* IF REMOVE_QUOTED_NEWLINES is non-zero, we are reading a
4313 here document with an unquoted delimiter. In this case,
4314 the line will be expanded as if it were in double quotes.
4315 We allow a backslash to escape the next character, but we
4316 need to treat the backslash specially only if a backslash
4317 quoting a backslash-newline pair appears in the line. */
4320 line_buffer[indx++] = c;
4323 else if (c == '\\' && remove_quoted_newline)
4330 continue; /* Make the unquoted \<newline> pair disappear. */
4336 line_buffer[indx++] = c; /* Preserve the backslash. */
4340 line_buffer[indx++] = c;
4344 line_buffer[indx] = '\0';
4345 return (line_buffer);
4350 /* Return a line as in read_a_line (), but insure that the prompt is
4351 the secondary prompt. This is used to read the lines of a here
4352 document. REMOVE_QUOTED_NEWLINE is non-zero if we should remove
4353 newlines quoted with backslashes while reading the line. It is
4354 non-zero unless the delimiter of the here document was quoted. */
4356 read_secondary_line (remove_quoted_newline)
4357 int remove_quoted_newline;
4362 prompt_string_pointer = &ps2_prompt;
4363 if (SHOULD_PROMPT())
4365 ret = read_a_line (remove_quoted_newline);
4366 #if defined (HISTORY)
4367 if (ret && remember_on_history && (parser_state & PST_HEREDOC))
4369 /* To make adding the the here-document body right, we need to rely
4370 on history_delimiting_chars() returning \n for the first line of
4371 the here-document body and the null string for the second and
4372 subsequent lines, so we avoid double newlines.
4373 current_command_line_count == 2 for the first line of the body. */
4375 current_command_line_count++;
4376 maybe_add_history (ret);
4378 #endif /* HISTORY */
4382 /* **************************************************************** */
4386 /* **************************************************************** */
4388 /* Reserved words. These are only recognized as the first word of a
4390 STRING_INT_ALIST word_token_alist[] = {
4399 #if defined (SELECT_COMMAND)
4400 { "select", SELECT },
4407 { "function", FUNCTION },
4408 #if defined (COMMAND_TIMING)
4414 #if defined (COND_COMMAND)
4415 { "[[", COND_START },
4418 #if defined (COPROCESS_SUPPORT)
4419 { "coproc", COPROC },
4424 /* other tokens that can be returned by read_token() */
4425 STRING_INT_ALIST other_token_alist[] = {
4426 /* Multiple-character tokens with special values */
4431 { ">>", GREATER_GREATER },
4432 { "<<", LESS_LESS },
4434 { ">&", GREATER_AND },
4435 { ";;", SEMI_SEMI },
4437 { ";;&", SEMI_SEMI_AND },
4438 { "<<-", LESS_LESS_MINUS },
4439 { "<<<", LESS_LESS_LESS },
4440 { "&>", AND_GREATER },
4441 { "&>>", AND_GREATER_GREATER },
4442 { "<>", LESS_GREATER },
4443 { ">|", GREATER_BAR },
4445 { "EOF", yacc_EOF },
4446 /* Tokens whose value is the character itself */
4457 { "newline", '\n' },
4461 /* others not listed here:
4462 WORD look at yylval.word
4463 ASSIGNMENT_WORD look at yylval.word
4464 NUMBER look at yylval.number
4465 ARITH_CMD look at yylval.word_list
4466 ARITH_FOR_EXPRS look at yylval.word_list
4467 COND_CMD look at yylval.command
4470 /* These are used by read_token_word, but appear up here so that shell_getc
4471 can use them to decide when to add otherwise blank lines to the history. */
4473 /* The primary delimiter stack. */
4474 struct dstack dstack = { (char *)NULL, 0, 0 };
4476 /* A temporary delimiter stack to be used when decoding prompt strings.
4477 This is needed because command substitutions in prompt strings (e.g., PS2)
4478 can screw up the parser's quoting state. */
4479 static struct dstack temp_dstack = { (char *)NULL, 0, 0 };
4481 /* Macro for accessing the top delimiter on the stack. Returns the
4482 delimiter or zero if none. */
4483 #define current_delimiter(ds) \
4484 (ds.delimiter_depth ? ds.delimiters[ds.delimiter_depth - 1] : 0)
4486 #define push_delimiter(ds, character) \
4489 if (ds.delimiter_depth + 2 > ds.delimiter_space) \
4490 ds.delimiters = (char *)xrealloc \
4491 (ds.delimiters, (ds.delimiter_space += 10) * sizeof (char)); \
4492 ds.delimiters[ds.delimiter_depth] = character; \
4493 ds.delimiter_depth++; \
4497 #define pop_delimiter(ds) ds.delimiter_depth--
4499 /* Return the next shell input character. This always reads characters
4500 from shell_input_line; when that line is exhausted, it is time to
4501 read the next line. This is called by read_token when the shell is
4502 processing normal command input. */
4504 /* This implements one-character lookahead/lookbehind across physical input
4505 lines, to avoid something being lost because it's pushed back with
4506 shell_ungetc when we're at the start of a line. */
4507 static int eol_ungetc_lookahead = 0;
4510 shell_getc (remove_quoted_newline)
4511 int remove_quoted_newline;
4519 if (sigwinch_received)
4521 sigwinch_received = 0;
4522 get_new_window_size (0, (int *)0, (int *)0);
4525 if (eol_ungetc_lookahead)
4527 c = eol_ungetc_lookahead;
4528 eol_ungetc_lookahead = 0;
4532 #if defined (ALIAS) || defined (DPAREN_ARITHMETIC)
4533 /* If shell_input_line[shell_input_line_index] == 0, but there is
4534 something on the pushed list of strings, then we don't want to go
4535 off and get another line. We let the code down below handle it. */
4537 if (!shell_input_line || ((!shell_input_line[shell_input_line_index]) &&
4538 (pushed_string_list == (STRING_SAVER *)NULL)))
4539 #else /* !ALIAS && !DPAREN_ARITHMETIC */
4540 if (!shell_input_line || !shell_input_line[shell_input_line_index])
4541 #endif /* !ALIAS && !DPAREN_ARITHMETIC */
4545 /* Let's not let one really really long line blow up memory allocation */
4546 if (shell_input_line && shell_input_line_size >= 32768)
4548 free (shell_input_line);
4549 shell_input_line = 0;
4550 shell_input_line_size = 0;
4555 /* Allow immediate exit if interrupted during input. */
4559 shell_input_line_terminator = 0;
4561 /* If the shell is interatctive, but not currently printing a prompt
4562 (interactive_shell && interactive == 0), we don't want to print
4563 notifies or cleanup the jobs -- we want to defer it until we do
4564 print the next prompt. */
4565 if (interactive_shell == 0 || SHOULD_PROMPT())
4567 #if defined (JOB_CONTROL)
4568 /* This can cause a problem when reading a command as the result
4569 of a trap, when the trap is called from flush_child. This call
4570 had better not cause jobs to disappear from the job table in
4571 that case, or we will have big trouble. */
4572 notify_and_cleanup ();
4573 #else /* !JOB_CONTROL */
4574 cleanup_dead_jobs ();
4575 #endif /* !JOB_CONTROL */
4578 #if defined (READLINE)
4579 if (no_line_editing && SHOULD_PROMPT())
4581 if (SHOULD_PROMPT())
4585 if (bash_input.type == st_stream)
4592 /* Allow immediate exit if interrupted during input. */
4598 internal_warning ("shell_getc: ignored null byte in input");
4603 /* Theoretical overflow */
4604 /* If we can't put 256 bytes more into the buffer, allocate
4605 everything we can and fill it as full as we can. */
4606 /* XXX - we ignore rest of line using `truncating' flag */
4607 if (shell_input_line_size > (SIZE_MAX - 256))
4611 n = SIZE_MAX - i; /* how much more can we put into the buffer? */
4612 if (n <= 2) /* we have to save 1 for the newline added below */
4614 if (truncating == 0)
4615 internal_warning("shell_getc: shell_input_line_size (%zu) exceeds SIZE_MAX (%llu): line truncated", shell_input_line_size, SIZE_MAX);
4616 shell_input_line[i] = '\0';
4619 if (shell_input_line_size < SIZE_MAX)
4621 shell_input_line_size = SIZE_MAX;
4622 shell_input_line = xrealloc (shell_input_line, shell_input_line_size);
4626 RESIZE_MALLOCED_BUFFER (shell_input_line, i, 2, shell_input_line_size, 256);
4630 if (bash_input.type == st_stream)
4634 shell_input_line_terminator = EOF;
4636 shell_input_line[i] = '\0';
4640 if (truncating == 0 || c == '\n')
4641 shell_input_line[i++] = c;
4645 shell_input_line[--i] = '\0';
4646 current_command_line_count++;
4651 shell_input_line_index = 0;
4652 shell_input_line_len = i; /* == strlen (shell_input_line) */
4654 set_line_mbstate ();
4656 #if defined (HISTORY)
4657 if (remember_on_history && shell_input_line && shell_input_line[0])
4660 # if defined (BANG_HISTORY)
4663 /* If the current delimiter is a single quote, we should not be
4664 performing history expansion, even if we're on a different
4665 line from the original single quote. */
4666 old_hist = history_expansion_inhibited;
4667 if (current_delimiter (dstack) == '\'')
4668 history_expansion_inhibited = 1;
4670 expansions = pre_process_line (shell_input_line, 1, 1);
4671 # if defined (BANG_HISTORY)
4672 history_expansion_inhibited = old_hist;
4674 if (expansions != shell_input_line)
4676 free (shell_input_line);
4677 shell_input_line = expansions;
4678 shell_input_line_len = shell_input_line ?
4679 strlen (shell_input_line) : 0;
4680 if (shell_input_line_len == 0)
4681 current_command_line_count--;
4683 /* We have to force the xrealloc below because we don't know
4684 the true allocated size of shell_input_line anymore. */
4685 shell_input_line_size = shell_input_line_len;
4687 set_line_mbstate ();
4690 /* Try to do something intelligent with blank lines encountered while
4691 entering multi-line commands. XXX - this is grotesque */
4692 else if (remember_on_history && shell_input_line &&
4693 shell_input_line[0] == '\0' &&
4694 current_command_line_count > 1)
4696 if (current_delimiter (dstack))
4697 /* We know shell_input_line[0] == 0 and we're reading some sort of
4698 quoted string. This means we've got a line consisting of only
4699 a newline in a quoted string. We want to make sure this line
4700 gets added to the history. */
4701 maybe_add_history (shell_input_line);
4705 hdcs = history_delimiting_chars (shell_input_line);
4706 if (hdcs && hdcs[0] == ';')
4707 maybe_add_history (shell_input_line);
4711 #endif /* HISTORY */
4713 if (shell_input_line)
4715 /* Lines that signify the end of the shell's input should not be
4716 echoed. We should not echo lines while parsing command
4717 substitutions with recursive calls into the parsing engine; those
4718 should only be echoed once when we read the word. That is the
4719 reason for the test against shell_eof_token, which is set to a
4720 right paren when parsing the contents of command substitutions. */
4721 if (echo_input_at_read && (shell_input_line[0] ||
4722 shell_input_line_terminator != EOF) &&
4723 shell_eof_token == 0)
4724 fprintf (stderr, "%s\n", shell_input_line);
4728 shell_input_line_size = 0;
4729 prompt_string_pointer = ¤t_prompt_string;
4730 if (SHOULD_PROMPT ())
4735 /* Add the newline to the end of this string, iff the string does
4736 not already end in an EOF character. */
4737 if (shell_input_line_terminator != EOF)
4739 if (shell_input_line_size < SIZE_MAX-3 && (shell_input_line_len+3 > shell_input_line_size))
4740 shell_input_line = (char *)xrealloc (shell_input_line,
4741 1 + (shell_input_line_size += 2));
4743 shell_input_line[shell_input_line_len] = '\n';
4744 shell_input_line[shell_input_line_len + 1] = '\0';
4746 set_line_mbstate ();
4751 uc = shell_input_line[shell_input_line_index];
4754 shell_input_line_index++;
4756 #if defined (ALIAS) || defined (DPAREN_ARITHMETIC)
4757 /* If UC is NULL, we have reached the end of the current input string. If
4758 pushed_string_list is non-empty, it's time to pop to the previous string
4759 because we have fully consumed the result of the last alias expansion.
4760 Do it transparently; just return the next character of the string popped
4762 /* If pushed_string_list != 0 but pushed_string_list->expander == 0 (not
4763 currently tested) and the flags value is not PSH_SOURCE, we are not
4764 parsing an alias, we have just saved one (push_string, when called by
4765 the parse_dparen code) In this case, just go on as well. The PSH_SOURCE
4766 case is handled below. */
4768 if (uc == 0 && pushed_string_list && pushed_string_list->flags != PSH_SOURCE)
4771 uc = shell_input_line[shell_input_line_index];
4773 shell_input_line_index++;
4775 #endif /* ALIAS || DPAREN_ARITHMETIC */
4777 if MBTEST(uc == '\\' && remove_quoted_newline && shell_input_line[shell_input_line_index] == '\n')
4779 if (SHOULD_PROMPT ())
4782 /* What do we do here if we're expanding an alias whose definition
4783 includes an escaped newline? If that's the last character in the
4784 alias expansion, we just pop the pushed string list (recall that
4785 we inhibit the appending of a space in mk_alexpansion() if newline
4786 is the last character). If it's not the last character, we need
4787 to consume the quoted newline and move to the next character in
4790 if (expanding_alias () && shell_input_line[shell_input_line_index+1] == '\0')
4795 else if (expanding_alias () && shell_input_line[shell_input_line_index+1] != '\0')
4797 shell_input_line_index++; /* skip newline */
4798 goto next_alias_char; /* and get next character */
4805 if (uc == 0 && shell_input_line_terminator == EOF)
4806 return ((shell_input_line_index != 0) ? '\n' : EOF);
4808 #if defined (ALIAS) || defined (DPAREN_ARITHMETIC)
4809 /* We already know that we are not parsing an alias expansion because of the
4810 check for expanding_alias() above. This knows how parse_and_execute
4811 handles switching to st_string input while an alias is being expanded,
4812 hence the check for pushed_string_list without pushed_string_list->expander
4813 and the check for PSH_SOURCE as pushed_string_list->flags.
4814 parse_and_execute and parse_string both change the input type to st_string
4815 and place the string to be parsed and executed into location.string, so
4816 we should not stop reading that until the pointer is '\0'.
4817 The check for shell_input_line_terminator may be superfluous.
4819 This solves the problem of `.' inside a multi-line alias with embedded
4820 newlines executing things out of order. */
4821 if (uc == 0 && bash_input.type == st_string && *bash_input.location.string &&
4822 pushed_string_list && pushed_string_list->flags == PSH_SOURCE &&
4823 shell_input_line_terminator == 0)
4825 shell_input_line_index = 0;
4833 /* Put C back into the input for the shell. This might need changes for
4834 HANDLE_MULTIBYTE around EOLs. Since we (currently) never push back a
4835 character different than we read, shell_input_line_property doesn't need
4836 to change when manipulating shell_input_line. The define for
4837 last_shell_getc_is_singlebyte should take care of it, though. */
4842 if (shell_input_line && shell_input_line_index)
4843 shell_input_line[--shell_input_line_index] = c;
4845 eol_ungetc_lookahead = c;
4848 #ifdef INCLUDE_UNUSED
4849 /* Back the input pointer up by one, effectively `ungetting' a character. */
4853 if (shell_input_line && shell_input_line_index)
4854 shell_input_line_index--;
4858 /* Discard input until CHARACTER is seen, then push that character back
4859 onto the input stream. */
4861 discard_until (character)
4866 while ((c = shell_getc (0)) != EOF && c != character)
4874 execute_variable_command (command, vname)
4875 char *command, *vname;
4878 sh_parser_state_t ps;
4880 save_parser_state (&ps);
4881 last_lastarg = get_string_value ("_");
4883 last_lastarg = savestring (last_lastarg);
4885 parse_and_execute (savestring (command), vname, SEVAL_NONINT|SEVAL_NOHIST);
4887 restore_parser_state (&ps);
4888 bind_variable ("_", last_lastarg, 0);
4889 FREE (last_lastarg);
4891 if (token_to_read == '\n') /* reset_parser was called */
4895 /* Place to remember the token. We try to keep the buffer
4896 at a reasonable size, but it can grow. */
4897 static char *token = (char *)NULL;
4899 /* Current size of the token buffer. */
4900 static int token_buffer_size;
4902 /* Command to read_token () explaining what we want it to do. */
4905 #define prompt_is_ps1 \
4906 (!prompt_string_pointer || prompt_string_pointer == &ps1_prompt)
4908 /* Function for yyparse to call. yylex keeps track of
4909 the last two tokens read, and calls read_token. */
4913 if (interactive && (current_token == 0 || current_token == '\n'))
4915 /* Before we print a prompt, we might have to check mailboxes.
4916 We do this only if it is time to do so. Notice that only here
4917 is the mail alarm reset; nothing takes place in check_mail ()
4918 except the checking of mail. Please don't change this. */
4919 if (prompt_is_ps1 && parse_and_execute_level == 0 && time_to_check_mail ())
4922 reset_mail_timer ();
4925 /* Avoid printing a prompt if we're not going to read anything, e.g.
4926 after resetting the parser with read_token (RESET). */
4927 if (token_to_read == 0 && SHOULD_PROMPT ())
4931 two_tokens_ago = token_before_that;
4932 token_before_that = last_read_token;
4933 last_read_token = current_token;
4934 current_token = read_token (READ);
4936 if ((parser_state & PST_EOFTOKEN) && current_token == shell_eof_token)
4938 current_token = yacc_EOF;
4939 if (bash_input.type == st_string)
4940 rewind_input_string ();
4942 parser_state &= ~PST_EOFTOKEN;
4944 return (current_token);
4947 /* When non-zero, we have read the required tokens
4948 which allow ESAC to be the next one read. */
4949 static int esacs_needed_count;
4952 gather_here_documents ()
4957 while (need_here_doc)
4959 parser_state |= PST_HEREDOC;
4960 make_here_document (redir_stack[r++], line_number);
4961 parser_state &= ~PST_HEREDOC;
4966 /* When non-zero, an open-brace used to create a group is awaiting a close
4968 static int open_brace_count;
4970 #define command_token_position(token) \
4971 (((token) == ASSIGNMENT_WORD) || (parser_state&PST_REDIRLIST) || \
4972 ((token) != SEMI_SEMI && (token) != SEMI_AND && (token) != SEMI_SEMI_AND && reserved_word_acceptable(token)))
4974 #define assignment_acceptable(token) \
4975 (command_token_position(token) && ((parser_state & PST_CASEPAT) == 0))
4977 /* Check to see if TOKEN is a reserved word and return the token
4979 #define CHECK_FOR_RESERVED_WORD(tok) \
4981 if (!dollar_present && !quoted && \
4982 reserved_word_acceptable (last_read_token)) \
4985 for (i = 0; word_token_alist[i].word != (char *)NULL; i++) \
4986 if (STREQ (tok, word_token_alist[i].word)) \
4988 if ((parser_state & PST_CASEPAT) && (word_token_alist[i].token != ESAC)) \
4990 if (word_token_alist[i].token == TIME && time_command_acceptable () == 0) \
4992 if (word_token_alist[i].token == ESAC) \
4993 parser_state &= ~(PST_CASEPAT|PST_CASESTMT); \
4994 else if (word_token_alist[i].token == CASE) \
4995 parser_state |= PST_CASESTMT; \
4996 else if (word_token_alist[i].token == COND_END) \
4997 parser_state &= ~(PST_CONDCMD|PST_CONDEXPR); \
4998 else if (word_token_alist[i].token == COND_START) \
4999 parser_state |= PST_CONDCMD; \
5000 else if (word_token_alist[i].token == '{') \
5001 open_brace_count++; \
5002 else if (word_token_alist[i].token == '}' && open_brace_count) \
5003 open_brace_count--; \
5004 return (word_token_alist[i].token); \
5011 /* OK, we have a token. Let's try to alias expand it, if (and only if)
5014 It is eligible for expansion if EXPAND_ALIASES is set, and
5015 the token is unquoted and the last token read was a command
5016 separator (or expand_next_token is set), and we are currently
5017 processing an alias (pushed_string_list is non-empty) and this
5018 token is not the same as the current or any previously
5021 Special cases that disqualify:
5022 In a pattern list in a case statement (parser_state & PST_CASEPAT). */
5032 r = xmalloc (l + 2);
5034 /* If the last character in the alias is a newline, don't add a trailing
5035 space to the expansion. Works with shell_getc above. */
5036 if (r[l - 1] != ' ' && r[l - 1] != '\n')
5043 alias_expand_token (tokstr)
5049 if (((parser_state & PST_ALEXPNEXT) || command_token_position (last_read_token)) &&
5050 (parser_state & PST_CASEPAT) == 0)
5052 ap = find_alias (tokstr);
5054 /* Currently expanding this token. */
5055 if (ap && (ap->flags & AL_BEINGEXPANDED))
5056 return (NO_EXPANSION);
5058 /* mk_alexpansion puts an extra space on the end of the alias expansion,
5059 so the lookahead by the parser works right. If this gets changed,
5060 make sure the code in shell_getc that deals with reaching the end of
5061 an expanded alias is changed with it. */
5062 expanded = ap ? mk_alexpansion (ap->value) : (char *)NULL;
5066 push_string (expanded, ap->flags & AL_EXPANDNEXT, ap);
5067 return (RE_READ_TOKEN);
5070 /* This is an eligible token that does not have an expansion. */
5071 return (NO_EXPANSION);
5073 return (NO_EXPANSION);
5078 time_command_acceptable ()
5080 #if defined (COMMAND_TIMING)
5083 if (posixly_correct && shell_compatibility_level > 41)
5085 /* Quick check of the rest of the line to find the next token. If it
5086 begins with a `-', Posix says to not return `time' as the token.
5087 This was interp 267. */
5088 i = shell_input_line_index;
5089 while (i < shell_input_line_len && (shell_input_line[i] == ' ' || shell_input_line[i] == '\t'))
5091 if (shell_input_line[i] == '-')
5095 switch (last_read_token)
5108 case BANG: /* ! time pipeline */
5109 case TIME: /* time time pipeline */
5110 case TIMEOPT: /* time -p time pipeline */
5111 case TIMEIGN: /* time -p -- ... */
5118 #endif /* COMMAND_TIMING */
5121 /* Handle special cases of token recognition:
5122 IN is recognized if the last token was WORD and the token
5123 before that was FOR or CASE or SELECT.
5125 DO is recognized if the last token was WORD and the token
5126 before that was FOR or SELECT.
5128 ESAC is recognized if the last token caused `esacs_needed_count'
5131 `{' is recognized if the last token as WORD and the token
5132 before that was FUNCTION, or if we just parsed an arithmetic
5135 `}' is recognized if there is an unclosed `{' present.
5137 `-p' is returned as TIMEOPT if the last read token was TIME.
5138 `--' is returned as TIMEIGN if the last read token was TIMEOPT.
5140 ']]' is returned as COND_END if the parser is currently parsing
5141 a conditional expression ((parser_state & PST_CONDEXPR) != 0)
5143 `time' is returned as TIME if and only if it is immediately
5144 preceded by one of `;', `\n', `||', `&&', or `&'.
5148 special_case_tokens (tokstr)
5151 if ((last_read_token == WORD) &&
5152 #if defined (SELECT_COMMAND)
5153 ((token_before_that == FOR) || (token_before_that == CASE) || (token_before_that == SELECT)) &&
5155 ((token_before_that == FOR) || (token_before_that == CASE)) &&
5157 (tokstr[0] == 'i' && tokstr[1] == 'n' && tokstr[2] == 0))
5159 if (token_before_that == CASE)
5161 parser_state |= PST_CASEPAT;
5162 esacs_needed_count++;
5167 if (last_read_token == WORD &&
5168 #if defined (SELECT_COMMAND)
5169 (token_before_that == FOR || token_before_that == SELECT) &&
5171 (token_before_that == FOR) &&
5173 (tokstr[0] == 'd' && tokstr[1] == 'o' && tokstr[2] == '\0'))
5176 /* Ditto for ESAC in the CASE case.
5177 Specifically, this handles "case word in esac", which is a legal
5178 construct, certainly because someone will pass an empty arg to the
5179 case construct, and we don't want it to barf. Of course, we should
5180 insist that the case construct has at least one pattern in it, but
5181 the designers disagree. */
5182 if (esacs_needed_count)
5184 esacs_needed_count--;
5185 if (STREQ (tokstr, "esac"))
5187 parser_state &= ~PST_CASEPAT;
5192 /* The start of a shell function definition. */
5193 if (parser_state & PST_ALLOWOPNBRC)
5195 parser_state &= ~PST_ALLOWOPNBRC;
5196 if (tokstr[0] == '{' && tokstr[1] == '\0') /* } */
5199 function_bstart = line_number;
5200 return ('{'); /* } */
5204 /* We allow a `do' after a for ((...)) without an intervening
5206 if (last_read_token == ARITH_FOR_EXPRS && tokstr[0] == 'd' && tokstr[1] == 'o' && !tokstr[2])
5208 if (last_read_token == ARITH_FOR_EXPRS && tokstr[0] == '{' && tokstr[1] == '\0') /* } */
5211 return ('{'); /* } */
5214 if (open_brace_count && reserved_word_acceptable (last_read_token) && tokstr[0] == '}' && !tokstr[1])
5216 open_brace_count--; /* { */
5220 #if defined (COMMAND_TIMING)
5221 /* Handle -p after `time'. */
5222 if (last_read_token == TIME && tokstr[0] == '-' && tokstr[1] == 'p' && !tokstr[2])
5224 /* Handle -- after `time -p'. */
5225 if (last_read_token == TIMEOPT && tokstr[0] == '-' && tokstr[1] == '-' && !tokstr[2])
5229 #if defined (COND_COMMAND) /* [[ */
5230 if ((parser_state & PST_CONDEXPR) && tokstr[0] == ']' && tokstr[1] == ']' && tokstr[2] == '\0')
5237 /* Called from shell.c when Control-C is typed at top level. Or
5238 by the error rule at top level. */
5242 dstack.delimiter_depth = 0; /* No delimiters found so far. */
5243 open_brace_count = 0;
5245 #if defined (EXTENDED_GLOB)
5246 /* Reset to global value of extended glob */
5247 if (parser_state & PST_EXTPAT)
5248 extended_glob = global_extglob;
5253 #if defined (ALIAS) || defined (DPAREN_ARITHMETIC)
5254 if (pushed_string_list)
5255 free_string_list ();
5256 #endif /* ALIAS || DPAREN_ARITHMETIC */
5258 if (shell_input_line)
5260 free (shell_input_line);
5261 shell_input_line = (char *)NULL;
5262 shell_input_line_size = shell_input_line_index = 0;
5265 FREE (word_desc_to_read);
5266 word_desc_to_read = (WORD_DESC *)NULL;
5268 current_token = '\n'; /* XXX */
5269 last_read_token = '\n';
5270 token_to_read = '\n';
5273 /* Read the next token. Command can be READ (normal operation) or
5274 RESET (to normalize state). */
5276 read_token (command)
5279 int character; /* Current character. */
5280 int peek_char; /* Temporary look-ahead character. */
5281 int result; /* The thing to return. */
5283 if (command == RESET)
5291 result = token_to_read;
5292 if (token_to_read == WORD || token_to_read == ASSIGNMENT_WORD)
5294 yylval.word = word_desc_to_read;
5295 word_desc_to_read = (WORD_DESC *)NULL;
5301 #if defined (COND_COMMAND)
5302 if ((parser_state & (PST_CONDCMD|PST_CONDEXPR)) == PST_CONDCMD)
5304 cond_lineno = line_number;
5305 parser_state |= PST_CONDEXPR;
5306 yylval.command = parse_cond_command ();
5307 if (cond_token != COND_END)
5312 token_to_read = COND_END;
5313 parser_state &= ~(PST_CONDEXPR|PST_CONDCMD);
5319 /* This is a place to jump back to once we have successfully expanded a
5320 token with an alias and pushed the string with push_string () */
5324 /* Read a single word from input. Start by skipping blanks. */
5325 while ((character = shell_getc (1)) != EOF && shellblank (character))
5328 if (character == EOF)
5334 if MBTEST(character == '#' && (!interactive || interactive_comments))
5336 /* A comment. Discard until EOL or EOF, and then return a newline. */
5337 discard_until ('\n');
5339 character = '\n'; /* this will take the next if statement and return. */
5342 if (character == '\n')
5344 /* If we're about to return an unquoted newline, we can go and collect
5345 the text of any pending here document. */
5347 gather_here_documents ();
5350 parser_state &= ~PST_ALEXPNEXT;
5353 parser_state &= ~PST_ASSIGNOK;
5358 if (parser_state & PST_REGEXP)
5361 /* Shell meta-characters. */
5362 if MBTEST(shellmeta (character) && ((parser_state & PST_DBLPAREN) == 0))
5365 /* Turn off alias tokenization iff this character sequence would
5366 not leave us ready to read a command. */
5367 if (character == '<' || character == '>')
5368 parser_state &= ~PST_ALEXPNEXT;
5371 parser_state &= ~PST_ASSIGNOK;
5373 peek_char = shell_getc (1);
5374 if (character == peek_char)
5379 /* If '<' then we could be at "<<" or at "<<-". We have to
5380 look ahead one more character. */
5381 peek_char = shell_getc (1);
5382 if MBTEST(peek_char == '-')
5383 return (LESS_LESS_MINUS);
5384 else if MBTEST(peek_char == '<')
5385 return (LESS_LESS_LESS);
5388 shell_ungetc (peek_char);
5393 return (GREATER_GREATER);
5396 parser_state |= PST_CASEPAT;
5398 parser_state &= ~PST_ALEXPNEXT;
5401 peek_char = shell_getc (1);
5402 if MBTEST(peek_char == '&')
5403 return (SEMI_SEMI_AND);
5406 shell_ungetc (peek_char);
5416 #if defined (DPAREN_ARITHMETIC) || defined (ARITH_FOR_COMMAND)
5418 result = parse_dparen (character);
5426 else if MBTEST(character == '<' && peek_char == '&')
5428 else if MBTEST(character == '>' && peek_char == '&')
5429 return (GREATER_AND);
5430 else if MBTEST(character == '<' && peek_char == '>')
5431 return (LESS_GREATER);
5432 else if MBTEST(character == '>' && peek_char == '|')
5433 return (GREATER_BAR);
5434 else if MBTEST(character == '&' && peek_char == '>')
5436 peek_char = shell_getc (1);
5437 if MBTEST(peek_char == '>')
5438 return (AND_GREATER_GREATER);
5441 shell_ungetc (peek_char);
5442 return (AND_GREATER);
5445 else if MBTEST(character == '|' && peek_char == '&')
5447 else if MBTEST(character == ';' && peek_char == '&')
5449 parser_state |= PST_CASEPAT;
5451 parser_state &= ~PST_ALEXPNEXT;
5456 shell_ungetc (peek_char);
5458 /* If we look like we are reading the start of a function
5459 definition, then let the reader know about it so that
5460 we will do the right thing with `{'. */
5461 if MBTEST(character == ')' && last_read_token == '(' && token_before_that == WORD)
5463 parser_state |= PST_ALLOWOPNBRC;
5465 parser_state &= ~PST_ALEXPNEXT;
5467 function_dstart = line_number;
5470 /* case pattern lists may be preceded by an optional left paren. If
5471 we're not trying to parse a case pattern list, the left paren
5472 indicates a subshell. */
5473 if MBTEST(character == '(' && (parser_state & PST_CASEPAT) == 0) /* ) */
5474 parser_state |= PST_SUBSHELL;
5476 else if MBTEST((parser_state & PST_CASEPAT) && character == ')')
5477 parser_state &= ~PST_CASEPAT;
5479 else if MBTEST((parser_state & PST_SUBSHELL) && character == ')')
5480 parser_state &= ~PST_SUBSHELL;
5482 #if defined (PROCESS_SUBSTITUTION)
5483 /* Check for the constructs which introduce process substitution.
5484 Shells running in `posix mode' don't do process substitution. */
5485 if MBTEST(posixly_correct || ((character != '>' && character != '<') || peek_char != '(')) /*)*/
5486 #endif /* PROCESS_SUBSTITUTION */
5490 /* Hack <&- (close stdin) case. Also <&N- (dup and close). */
5491 if MBTEST(character == '-' && (last_read_token == LESS_AND || last_read_token == GREATER_AND))
5495 /* Okay, if we got this far, we have to read a word. Read one,
5496 and then check it against the known ones. */
5497 result = read_token_word (character);
5499 if (result == RE_READ_TOKEN)
5506 * Match a $(...) or other grouping construct. This has to handle embedded
5507 * quoted strings ('', ``, "") and nested constructs. It also must handle
5508 * reprompting the user, if necessary, after reading a newline, and returning
5509 * correct error values if it reads EOF.
5511 #define P_FIRSTCLOSE 0x0001
5512 #define P_ALLOWESC 0x0002
5513 #define P_DQUOTE 0x0004
5514 #define P_COMMAND 0x0008 /* parsing a command, so look for comments */
5515 #define P_BACKQUOTE 0x0010 /* parsing a backquoted command substitution */
5516 #define P_ARRAYSUB 0x0020 /* parsing a [...] array subscript for assignment */
5517 #define P_DOLBRACE 0x0040 /* parsing a ${...} construct */
5519 /* Lexical state while parsing a grouping construct or $(...). */
5520 #define LEX_WASDOL 0x001
5521 #define LEX_CKCOMMENT 0x002
5522 #define LEX_INCOMMENT 0x004
5523 #define LEX_PASSNEXT 0x008
5524 #define LEX_RESWDOK 0x010
5525 #define LEX_CKCASE 0x020
5526 #define LEX_INCASE 0x040
5527 #define LEX_INHEREDOC 0x080
5528 #define LEX_HEREDELIM 0x100 /* reading here-doc delimiter */
5529 #define LEX_STRIPDOC 0x200 /* <<- strip tabs from here doc delim */
5530 #define LEX_INWORD 0x400
5532 #define COMSUB_META(ch) ((ch) == ';' || (ch) == '&' || (ch) == '|')
5534 #define CHECK_NESTRET_ERROR() \
5536 if (nestret == &matched_pair_error) \
5539 return &matched_pair_error; \
5543 #define APPEND_NESTRET() \
5547 RESIZE_MALLOCED_BUFFER (ret, retind, nestlen, retsize, 64); \
5548 strcpy (ret + retind, nestret); \
5549 retind += nestlen; \
5553 static char matched_pair_error;
5556 parse_matched_pair (qc, open, close, lenp, flags)
5557 int qc; /* `"' if this construct is within double quotes */
5561 int count, ch, tflags;
5562 int nestlen, ttranslen, start_lineno;
5563 char *ret, *nestret, *ttrans;
5564 int retind, retsize, rflags;
5567 dolbrace_state = (flags & P_DOLBRACE) ? DOLBRACE_PARAM : 0;
5569 /*itrace("parse_matched_pair[%d]: open = %c close = %c flags = %d", line_number, open, close, flags);*/
5573 if ((flags & P_COMMAND) && qc != '`' && qc != '\'' && qc != '"' && (flags & P_DQUOTE) == 0)
5574 tflags |= LEX_CKCOMMENT;
5576 /* RFLAGS is the set of flags we want to pass to recursive calls. */
5577 rflags = (qc == '"') ? P_DQUOTE : (flags & P_DQUOTE);
5579 ret = (char *)xmalloc (retsize = 64);
5582 start_lineno = line_number;
5585 ch = shell_getc (qc != '\'' && (tflags & (LEX_PASSNEXT)) == 0);
5590 parser_error (start_lineno, _("unexpected EOF while looking for matching `%c'"), close);
5591 EOF_Reached = 1; /* XXX */
5592 return (&matched_pair_error);
5595 /* Possible reprompting. */
5596 if (ch == '\n' && SHOULD_PROMPT ())
5599 /* Don't bother counting parens or doing anything else if in a comment
5600 or part of a case statement */
5601 if (tflags & LEX_INCOMMENT)
5603 /* Add this character. */
5604 RESIZE_MALLOCED_BUFFER (ret, retind, 1, retsize, 64);
5608 tflags &= ~LEX_INCOMMENT;
5613 /* Not exactly right yet, should handle shell metacharacters, too. If
5614 any changes are made to this test, make analogous changes to subst.c:
5615 extract_delimited_string(). */
5616 else if MBTEST((tflags & LEX_CKCOMMENT) && (tflags & LEX_INCOMMENT) == 0 && ch == '#' && (retind == 0 || ret[retind-1] == '\n' || shellblank (ret[retind - 1])))
5617 tflags |= LEX_INCOMMENT;
5619 if (tflags & LEX_PASSNEXT) /* last char was backslash */
5621 tflags &= ~LEX_PASSNEXT;
5622 if (qc != '\'' && ch == '\n') /* double-quoted \<newline> disappears. */
5625 retind--; /* swallow previously-added backslash */
5629 RESIZE_MALLOCED_BUFFER (ret, retind, 2, retsize, 64);
5630 if MBTEST(ch == CTLESC)
5631 ret[retind++] = CTLESC;
5635 /* If we're reparsing the input (e.g., from parse_string_to_word_list),
5636 we've already prepended CTLESC to single-quoted results of $'...'.
5637 We may want to do this for other CTLESC-quoted characters in
5639 else if MBTEST((parser_state & PST_REPARSE) && open == '\'' && (ch == CTLESC || ch == CTLNUL))
5641 RESIZE_MALLOCED_BUFFER (ret, retind, 1, retsize, 64);
5645 else if MBTEST(ch == CTLESC || ch == CTLNUL) /* special shell escapes */
5647 RESIZE_MALLOCED_BUFFER (ret, retind, 2, retsize, 64);
5648 ret[retind++] = CTLESC;
5652 else if MBTEST(ch == close) /* ending delimiter */
5654 /* handle nested ${...} specially. */
5655 else if MBTEST(open != close && (tflags & LEX_WASDOL) && open == '{' && ch == open) /* } */
5657 else if MBTEST(((flags & P_FIRSTCLOSE) == 0) && ch == open) /* nested begin */
5660 /* Add this character. */
5661 RESIZE_MALLOCED_BUFFER (ret, retind, 1, retsize, 64);
5664 /* If we just read the ending character, don't bother continuing. */
5668 if (open == '\'') /* '' inside grouping construct */
5670 if MBTEST((flags & P_ALLOWESC) && ch == '\\')
5671 tflags |= LEX_PASSNEXT;
5675 if MBTEST(ch == '\\') /* backslashes */
5676 tflags |= LEX_PASSNEXT;
5678 /* Based on which dolstate is currently in (param, op, or word),
5679 decide what the op is. We're really only concerned if it's % or
5680 #, so we can turn on a flag that says whether or not we should
5681 treat single quotes as special when inside a double-quoted
5682 ${...}. This logic must agree with subst.c:extract_dollar_brace_string
5683 since they share the same defines. */
5684 /* FLAG POSIX INTERP 221 */
5685 if (flags & P_DOLBRACE)
5687 /* ${param%[%]word} */
5688 if MBTEST(dolbrace_state == DOLBRACE_PARAM && ch == '%' && retind > 1)
5689 dolbrace_state = DOLBRACE_QUOTE;
5690 /* ${param#[#]word} */
5691 else if MBTEST(dolbrace_state == DOLBRACE_PARAM && ch == '#' && retind > 1)
5692 dolbrace_state = DOLBRACE_QUOTE;
5693 /* ${param/[/]pat/rep} */
5694 else if MBTEST(dolbrace_state == DOLBRACE_PARAM && ch == '/' && retind > 1)
5695 dolbrace_state = DOLBRACE_QUOTE2; /* XXX */
5696 /* ${param^[^]pat} */
5697 else if MBTEST(dolbrace_state == DOLBRACE_PARAM && ch == '^' && retind > 1)
5698 dolbrace_state = DOLBRACE_QUOTE;
5699 /* ${param,[,]pat} */
5700 else if MBTEST(dolbrace_state == DOLBRACE_PARAM && ch == ',' && retind > 1)
5701 dolbrace_state = DOLBRACE_QUOTE;
5702 else if MBTEST(dolbrace_state == DOLBRACE_PARAM && strchr ("#%^,~:-=?+/", ch) != 0)
5703 dolbrace_state = DOLBRACE_OP;
5704 else if MBTEST(dolbrace_state == DOLBRACE_OP && strchr ("#%^,~:-=?+/", ch) == 0)
5705 dolbrace_state = DOLBRACE_WORD;
5708 /* The big hammer. Single quotes aren't special in double quotes. The
5709 problem is that Posix used to say the single quotes are semi-special:
5710 within a double-quoted ${...} construct "an even number of
5711 unescaped double-quotes or single-quotes, if any, shall occur." */
5712 /* This was changed in Austin Group Interp 221 */
5713 if MBTEST(posixly_correct && shell_compatibility_level > 41 && dolbrace_state != DOLBRACE_QUOTE && dolbrace_state != DOLBRACE_QUOTE2 && (flags & P_DQUOTE) && (flags & P_DOLBRACE) && ch == '\'')
5716 /* Could also check open == '`' if we want to parse grouping constructs
5717 inside old-style command substitution. */
5718 if (open != close) /* a grouping construct */
5720 if MBTEST(shellquote (ch))
5722 /* '', ``, or "" inside $(...) or other grouping construct. */
5723 push_delimiter (dstack, ch);
5724 if MBTEST((tflags & LEX_WASDOL) && ch == '\'') /* $'...' inside group */
5725 nestret = parse_matched_pair (ch, ch, ch, &nestlen, P_ALLOWESC|rflags);
5727 nestret = parse_matched_pair (ch, ch, ch, &nestlen, rflags);
5728 pop_delimiter (dstack);
5729 CHECK_NESTRET_ERROR ();
5731 if MBTEST((tflags & LEX_WASDOL) && ch == '\'' && (extended_quote || (rflags & P_DQUOTE) == 0))
5733 /* Translate $'...' here. */
5734 ttrans = ansiexpand (nestret, 0, nestlen - 1, &ttranslen);
5737 /* If we're parsing a double-quoted brace expansion and we are
5738 not in a place where single quotes are treated specially,
5739 make sure we single-quote the results of the ansi
5740 expansion because quote removal should remove them later */
5741 /* FLAG POSIX INTERP 221 */
5742 if ((shell_compatibility_level > 42) && (rflags & P_DQUOTE) && (dolbrace_state == DOLBRACE_QUOTE2) && (flags & P_DOLBRACE))
5744 nestret = sh_single_quote (ttrans);
5746 nestlen = strlen (nestret);
5748 else if ((rflags & P_DQUOTE) == 0)
5750 nestret = sh_single_quote (ttrans);
5752 nestlen = strlen (nestret);
5757 nestlen = ttranslen;
5759 retind -= 2; /* back up before the $' */
5761 else if MBTEST((tflags & LEX_WASDOL) && ch == '"' && (extended_quote || (rflags & P_DQUOTE) == 0))
5763 /* Locale expand $"..." here. */
5764 ttrans = localeexpand (nestret, 0, nestlen - 1, start_lineno, &ttranslen);
5767 nestret = sh_mkdoublequoted (ttrans, ttranslen, 0);
5769 nestlen = ttranslen + 2;
5770 retind -= 2; /* back up before the $" */
5776 else if ((flags & P_ARRAYSUB) && (tflags & LEX_WASDOL) && (ch == '(' || ch == '{' || ch == '[')) /* ) } ] */
5777 goto parse_dollar_word;
5779 /* Parse an old-style command substitution within double quotes as a
5781 /* XXX - sh and ksh93 don't do this - XXX */
5782 else if MBTEST(open == '"' && ch == '`')
5784 nestret = parse_matched_pair (0, '`', '`', &nestlen, rflags);
5786 CHECK_NESTRET_ERROR ();
5791 else if MBTEST(open != '`' && (tflags & LEX_WASDOL) && (ch == '(' || ch == '{' || ch == '[')) /* ) } ] */
5792 /* check for $(), $[], or ${} inside quoted string. */
5795 if (open == ch) /* undo previous increment */
5797 if (ch == '(') /* ) */
5798 nestret = parse_comsub (0, '(', ')', &nestlen, (rflags|P_COMMAND) & ~P_DQUOTE);
5799 else if (ch == '{') /* } */
5800 nestret = parse_matched_pair (0, '{', '}', &nestlen, P_FIRSTCLOSE|P_DOLBRACE|rflags);
5801 else if (ch == '[') /* ] */
5802 nestret = parse_matched_pair (0, '[', ']', &nestlen, rflags);
5804 CHECK_NESTRET_ERROR ();
5809 if MBTEST(ch == '$')
5810 tflags |= LEX_WASDOL;
5812 tflags &= ~LEX_WASDOL;
5818 /*itrace("parse_matched_pair[%d]: returning %s", line_number, ret);*/
5822 /* Parse a $(...) command substitution. This is messier than I'd like, and
5823 reproduces a lot more of the token-reading code than I'd like. */
5825 parse_comsub (qc, open, close, lenp, flags)
5826 int qc; /* `"' if this construct is within double quotes */
5830 int count, ch, peekc, tflags, lex_rwlen, lex_wlen, lex_firstind;
5831 int nestlen, ttranslen, start_lineno;
5832 char *ret, *nestret, *ttrans, *heredelim;
5833 int retind, retsize, rflags, hdlen;
5835 /* Posix interp 217 says arithmetic expressions have precedence, so
5836 assume $(( introduces arithmetic expansion and parse accordingly. */
5837 peekc = shell_getc (0);
5838 shell_ungetc (peekc);
5840 return (parse_matched_pair (qc, open, close, lenp, 0));
5842 /*itrace("parse_comsub: qc = `%c' open = %c close = %c", qc, open, close);*/
5844 tflags = LEX_RESWDOK;
5846 if ((flags & P_COMMAND) && qc != '\'' && qc != '"' && (flags & P_DQUOTE) == 0)
5847 tflags |= LEX_CKCASE;
5848 if ((tflags & LEX_CKCASE) && (interactive == 0 || interactive_comments))
5849 tflags |= LEX_CKCOMMENT;
5851 /* RFLAGS is the set of flags we want to pass to recursive calls. */
5852 rflags = (flags & P_DQUOTE);
5854 ret = (char *)xmalloc (retsize = 64);
5857 start_lineno = line_number;
5858 lex_rwlen = lex_wlen = 0;
5866 ch = shell_getc (qc != '\'' && (tflags & (LEX_INCOMMENT|LEX_PASSNEXT)) == 0);
5873 parser_error (start_lineno, _("unexpected EOF while looking for matching `%c'"), close);
5874 EOF_Reached = 1; /* XXX */
5875 return (&matched_pair_error);
5878 /* If we hit the end of a line and are reading the contents of a here
5879 document, and it's not the same line that the document starts on,
5880 check for this line being the here doc delimiter. Otherwise, if
5881 we're in a here document, mark the next character as the beginning
5885 if ((tflags & LEX_HEREDELIM) && heredelim)
5887 tflags &= ~LEX_HEREDELIM;
5888 tflags |= LEX_INHEREDOC;
5889 lex_firstind = retind + 1;
5891 else if (tflags & LEX_INHEREDOC)
5894 tind = lex_firstind;
5895 while ((tflags & LEX_STRIPDOC) && ret[tind] == '\t')
5897 if (STREQN (ret + tind, heredelim, hdlen))
5899 tflags &= ~(LEX_STRIPDOC|LEX_INHEREDOC);
5900 /*itrace("parse_comsub:%d: found here doc end `%s'", line_number, ret + tind);*/
5906 lex_firstind = retind + 1;
5910 /* Possible reprompting. */
5911 if (ch == '\n' && SHOULD_PROMPT ())
5914 /* XXX -- possibly allow here doc to be delimited by ending right
5916 if ((tflags & LEX_INHEREDOC) && ch == close && count == 1)
5919 /*itrace("parse_comsub: in here doc, ch == close, retind - firstind = %d hdlen = %d retind = %d", retind-lex_firstind, hdlen, retind);*/
5920 tind = lex_firstind;
5921 while ((tflags & LEX_STRIPDOC) && ret[tind] == '\t')
5923 if (retind-tind == hdlen && STREQN (ret + tind, heredelim, hdlen))
5925 tflags &= ~(LEX_STRIPDOC|LEX_INHEREDOC);
5926 /*itrace("parse_comsub:%d: found here doc end `%s'", line_number, ret + tind);*/
5933 /* Don't bother counting parens or doing anything else if in a comment */
5934 if (tflags & (LEX_INCOMMENT|LEX_INHEREDOC))
5936 /* Add this character. */
5937 RESIZE_MALLOCED_BUFFER (ret, retind, 1, retsize, 64);
5940 if ((tflags & LEX_INCOMMENT) && ch == '\n')
5942 /*itrace("parse_comsub:%d: lex_incomment -> 0 ch = `%c'", line_number, ch);*/
5943 tflags &= ~LEX_INCOMMENT;
5949 if (tflags & LEX_PASSNEXT) /* last char was backslash */
5951 /*itrace("parse_comsub:%d: lex_passnext -> 0 ch = `%c' (%d)", line_number, ch, __LINE__);*/
5952 tflags &= ~LEX_PASSNEXT;
5953 if (qc != '\'' && ch == '\n') /* double-quoted \<newline> disappears. */
5956 retind--; /* swallow previously-added backslash */
5960 RESIZE_MALLOCED_BUFFER (ret, retind, 2, retsize, 64);
5961 if MBTEST(ch == CTLESC)
5962 ret[retind++] = CTLESC;
5967 /* If this is a shell break character, we are not in a word. If not,
5968 we either start or continue a word. */
5969 if MBTEST(shellbreak (ch))
5971 tflags &= ~LEX_INWORD;
5972 /*itrace("parse_comsub:%d: lex_inword -> 0 ch = `%c' (%d)", line_number, ch, __LINE__);*/
5976 if (tflags & LEX_INWORD)
5979 /*itrace("parse_comsub:%d: lex_inword == 1 ch = `%c' lex_wlen = %d (%d)", line_number, ch, lex_wlen, __LINE__);*/
5983 /*itrace("parse_comsub:%d: lex_inword -> 1 ch = `%c' (%d)", line_number, ch, __LINE__);*/
5984 tflags |= LEX_INWORD;
5989 /* Skip whitespace */
5990 if MBTEST(shellblank (ch) && (tflags & LEX_HEREDELIM) == 0 && lex_rwlen == 0)
5992 /* Add this character. */
5993 RESIZE_MALLOCED_BUFFER (ret, retind, 1, retsize, 64);
5998 /* Either we are looking for the start of the here-doc delimiter
5999 (lex_firstind == -1) or we are reading one (lex_firstind >= 0).
6000 If this character is a shell break character and we are reading
6001 the delimiter, save it and note that we are now reading a here
6002 document. If we've found the start of the delimiter, note it by
6003 setting lex_firstind. Backslashes can quote shell metacharacters
6004 in here-doc delimiters. */
6005 if (tflags & LEX_HEREDELIM)
6007 if (lex_firstind == -1 && shellbreak (ch) == 0)
6008 lex_firstind = retind;
6010 else if (heredelim && (tflags & LEX_PASSNEXT) == 0 && ch == '\n')
6012 tflags |= LEX_INHEREDOC;
6013 tflags &= ~LEX_HEREDELIM;
6014 lex_firstind = retind + 1;
6017 else if (lex_firstind >= 0 && (tflags & LEX_PASSNEXT) == 0 && shellbreak (ch))
6021 nestret = substring (ret, lex_firstind, retind);
6022 heredelim = string_quote_removal (nestret, 0);
6024 hdlen = STRLEN(heredelim);
6025 /*itrace("parse_comsub:%d: found here doc delimiter `%s' (%d)", line_number, heredelim, hdlen);*/
6029 tflags |= LEX_INHEREDOC;
6030 tflags &= ~LEX_HEREDELIM;
6031 lex_firstind = retind + 1;
6038 /* Meta-characters that can introduce a reserved word. Not perfect yet. */
6039 if MBTEST((tflags & LEX_RESWDOK) == 0 && (tflags & LEX_CKCASE) && (tflags & LEX_INCOMMENT) == 0 && (shellmeta(ch) || ch == '\n'))
6041 /* Add this character. */
6042 RESIZE_MALLOCED_BUFFER (ret, retind, 1, retsize, 64);
6044 peekc = shell_getc (1);
6045 if (ch == peekc && (ch == '&' || ch == '|' || ch == ';')) /* two-character tokens */
6047 RESIZE_MALLOCED_BUFFER (ret, retind, 1, retsize, 64);
6048 ret[retind++] = peekc;
6049 /*itrace("parse_comsub:%d: set lex_reswordok = 1, ch = `%c'", line_number, ch);*/
6050 tflags |= LEX_RESWDOK;
6054 else if (ch == '\n' || COMSUB_META(ch))
6056 shell_ungetc (peekc);
6057 /*itrace("parse_comsub:%d: set lex_reswordok = 1, ch = `%c'", line_number, ch);*/
6058 tflags |= LEX_RESWDOK;
6066 /* `unget' the character we just added and fall through */
6068 shell_ungetc (peekc);
6072 /* If we can read a reserved word, try to read one. */
6073 if (tflags & LEX_RESWDOK)
6075 if MBTEST(islower (ch))
6077 /* Add this character. */
6078 RESIZE_MALLOCED_BUFFER (ret, retind, 1, retsize, 64);
6083 else if MBTEST(lex_rwlen == 4 && shellbreak (ch))
6085 if (STREQN (ret + retind - 4, "case", 4))
6087 tflags |= LEX_INCASE;
6088 /*itrace("parse_comsub:%d: found `case', lex_incase -> 1 lex_reswdok -> 0", line_number);*/
6090 else if (STREQN (ret + retind - 4, "esac", 4))
6092 tflags &= ~LEX_INCASE;
6093 /*itrace("parse_comsub:%d: found `esac', lex_incase -> 0 lex_reswdok -> 0", line_number);*/
6095 tflags &= ~LEX_RESWDOK;
6097 else if MBTEST((tflags & LEX_CKCOMMENT) && ch == '#' && (lex_rwlen == 0 || ((tflags & LEX_INWORD) && lex_wlen == 0)))
6098 ; /* don't modify LEX_RESWDOK if we're starting a comment */
6099 /* Allow `do' followed by space, tab, or newline to preserve the
6100 RESWDOK flag, but reset the reserved word length counter so we
6101 can read another one. */
6102 else if MBTEST(((tflags & LEX_INCASE) == 0) &&
6103 (isblank(ch) || ch == '\n') &&
6105 STREQN (ret + retind - 2, "do", 2))
6107 /*itrace("parse_comsub:%d: lex_incase == 1 found `%c', found \"do\"", line_number, ch);*/
6110 else if MBTEST((tflags & LEX_INCASE) && ch != '\n')
6111 /* If we can read a reserved word and we're in case, we're at the
6112 point where we can read a new pattern list or an esac. We
6113 handle the esac case above. If we read a newline, we want to
6114 leave LEX_RESWDOK alone. If we read anything else, we want to
6115 turn off LEX_RESWDOK, since we're going to read a pattern list. */
6117 tflags &= ~LEX_RESWDOK;
6118 /*itrace("parse_comsub:%d: lex_incase == 1 found `%c', lex_reswordok -> 0", line_number, ch);*/
6120 else if MBTEST(shellbreak (ch) == 0)
6122 tflags &= ~LEX_RESWDOK;
6123 /*itrace("parse_comsub:%d: found `%c', lex_reswordok -> 0", line_number, ch);*/
6126 /* If we find a space or tab but have read something and it's not
6127 `do', turn off the reserved-word-ok flag */
6128 else if MBTEST(isblank (ch) && lex_rwlen > 0)
6130 tflags &= ~LEX_RESWDOK;
6131 /*itrace("parse_comsub:%d: found `%c', lex_reswordok -> 0", line_number, ch);*/
6136 /* Might be the start of a here-doc delimiter */
6137 if MBTEST((tflags & LEX_INCOMMENT) == 0 && (tflags & LEX_CKCASE) && ch == '<')
6139 /* Add this character. */
6140 RESIZE_MALLOCED_BUFFER (ret, retind, 1, retsize, 64);
6142 peekc = shell_getc (1);
6147 RESIZE_MALLOCED_BUFFER (ret, retind, 1, retsize, 64);
6148 ret[retind++] = peekc;
6149 peekc = shell_getc (1);
6154 RESIZE_MALLOCED_BUFFER (ret, retind, 1, retsize, 64);
6155 ret[retind++] = peekc;
6156 tflags |= LEX_STRIPDOC;
6159 shell_ungetc (peekc);
6162 tflags |= LEX_HEREDELIM;
6168 ch = peekc; /* fall through and continue XXX */
6170 else if MBTEST((tflags & LEX_CKCOMMENT) && (tflags & LEX_INCOMMENT) == 0 && ch == '#' && (((tflags & LEX_RESWDOK) && lex_rwlen == 0) || ((tflags & LEX_INWORD) && lex_wlen == 0)))
6172 /*itrace("parse_comsub:%d: lex_incomment -> 1 (%d)", line_number, __LINE__);*/
6173 tflags |= LEX_INCOMMENT;
6176 if MBTEST(ch == CTLESC || ch == CTLNUL) /* special shell escapes */
6178 RESIZE_MALLOCED_BUFFER (ret, retind, 2, retsize, 64);
6179 ret[retind++] = CTLESC;
6184 else if MBTEST((tflags & LEX_INCASE) && ch == close && close == ')')
6185 tflags &= ~LEX_INCASE; /* XXX */
6187 else if MBTEST(ch == close && (tflags & LEX_INCASE) == 0) /* ending delimiter */
6190 /*itrace("parse_comsub:%d: found close: count = %d", line_number, count);*/
6192 else if MBTEST(((flags & P_FIRSTCLOSE) == 0) && (tflags & LEX_INCASE) == 0 && ch == open) /* nested begin */
6195 /*itrace("parse_comsub:%d: found open: count = %d", line_number, count);*/
6198 /* Add this character. */
6199 RESIZE_MALLOCED_BUFFER (ret, retind, 1, retsize, 64);
6202 /* If we just read the ending character, don't bother continuing. */
6206 if MBTEST(ch == '\\') /* backslashes */
6207 tflags |= LEX_PASSNEXT;
6209 if MBTEST(shellquote (ch))
6211 /* '', ``, or "" inside $(...). */
6212 push_delimiter (dstack, ch);
6213 if MBTEST((tflags & LEX_WASDOL) && ch == '\'') /* $'...' inside group */
6214 nestret = parse_matched_pair (ch, ch, ch, &nestlen, P_ALLOWESC|rflags);
6216 nestret = parse_matched_pair (ch, ch, ch, &nestlen, rflags);
6217 pop_delimiter (dstack);
6218 CHECK_NESTRET_ERROR ();
6220 if MBTEST((tflags & LEX_WASDOL) && ch == '\'' && (extended_quote || (rflags & P_DQUOTE) == 0))
6222 /* Translate $'...' here. */
6223 ttrans = ansiexpand (nestret, 0, nestlen - 1, &ttranslen);
6226 if ((rflags & P_DQUOTE) == 0)
6228 nestret = sh_single_quote (ttrans);
6230 nestlen = strlen (nestret);
6235 nestlen = ttranslen;
6237 retind -= 2; /* back up before the $' */
6239 else if MBTEST((tflags & LEX_WASDOL) && ch == '"' && (extended_quote || (rflags & P_DQUOTE) == 0))
6241 /* Locale expand $"..." here. */
6242 ttrans = localeexpand (nestret, 0, nestlen - 1, start_lineno, &ttranslen);
6245 nestret = sh_mkdoublequoted (ttrans, ttranslen, 0);
6247 nestlen = ttranslen + 2;
6248 retind -= 2; /* back up before the $" */
6254 else if MBTEST((tflags & LEX_WASDOL) && (ch == '(' || ch == '{' || ch == '[')) /* ) } ] */
6255 /* check for $(), $[], or ${} inside command substitution. */
6257 if ((tflags & LEX_INCASE) == 0 && open == ch) /* undo previous increment */
6259 if (ch == '(') /* ) */
6260 nestret = parse_comsub (0, '(', ')', &nestlen, (rflags|P_COMMAND) & ~P_DQUOTE);
6261 else if (ch == '{') /* } */
6262 nestret = parse_matched_pair (0, '{', '}', &nestlen, P_FIRSTCLOSE|P_DOLBRACE|rflags);
6263 else if (ch == '[') /* ] */
6264 nestret = parse_matched_pair (0, '[', ']', &nestlen, rflags);
6266 CHECK_NESTRET_ERROR ();
6271 if MBTEST(ch == '$')
6272 tflags |= LEX_WASDOL;
6274 tflags &= ~LEX_WASDOL;
6281 /*itrace("parse_comsub:%d: returning `%s'", line_number, ret);*/
6285 /* Recursively call the parser to parse a $(...) command substitution. */
6287 xparse_dolparen (base, string, indp, flags)
6293 sh_parser_state_t ps;
6294 sh_input_line_state_t ls;
6295 int orig_ind, nc, sflags, orig_eof_token;
6296 char *ret, *s, *ep, *ostring;
6302 /*itrace("xparse_dolparen: size = %d shell_input_line = `%s'", shell_input_line_size, shell_input_line);*/
6303 sflags = SEVAL_NONINT|SEVAL_NOHIST|SEVAL_NOFREE;
6304 if (flags & SX_NOLONGJMP)
6305 sflags |= SEVAL_NOLONGJMP;
6306 save_parser_state (&ps);
6307 save_input_line_state (&ls);
6308 orig_eof_token = shell_eof_token;
6311 parser_state |= PST_CMDSUBST|PST_EOFTOKEN; /* allow instant ')' */ /*(*/
6312 shell_eof_token = ')';
6313 parse_string (string, "command substitution", sflags, &ep);
6315 shell_eof_token = orig_eof_token;
6316 restore_parser_state (&ps);
6318 /* reset_parser clears shell_input_line and associated variables */
6319 restore_input_line_state (&ls);
6323 /* Need to find how many characters parse_and_execute consumed, update
6324 *indp, if flags != 0, copy the portion of the string parsed into RET
6325 and return it. If flags & 1 (EX_NOALLOC) we can return NULL. */
6332 itrace("xparse_dolparen:%d: ep[-1] != RPAREN (%d), ep = `%s'", line_number, ep[-1], ep);
6334 while (ep > ostring && ep[-1] == '\n') ep--;
6338 *indp = ep - base - 1;
6342 if (base[*indp] != ')')
6343 itrace("xparse_dolparen:%d: base[%d] != RPAREN (%d), base = `%s'", line_number, *indp, base[*indp], base);
6346 if (flags & SX_NOALLOC)
6347 return (char *)NULL;
6355 ret = substring (ostring, 0, nc - 1);
6360 #if defined (DPAREN_ARITHMETIC) || defined (ARITH_FOR_COMMAND)
6361 /* Parse a double-paren construct. It can be either an arithmetic
6362 command, an arithmetic `for' command, or a nested subshell. Returns
6363 the parsed token, -1 on error, or -2 if we didn't do anything and
6364 should just go on. */
6373 #if defined (ARITH_FOR_COMMAND)
6374 if (last_read_token == FOR)
6376 arith_for_lineno = line_number;
6377 cmdtyp = parse_arith_cmd (&wval, 0);
6380 wd = alloc_word_desc ();
6382 yylval.word_list = make_word_list (wd, (WORD_LIST *)NULL);
6383 return (ARITH_FOR_EXPRS);
6386 return -1; /* ERROR */
6390 #if defined (DPAREN_ARITHMETIC)
6391 if (reserved_word_acceptable (last_read_token))
6393 sline = line_number;
6395 cmdtyp = parse_arith_cmd (&wval, 0);
6396 if (cmdtyp == 1) /* arithmetic command */
6398 wd = alloc_word_desc ();
6400 wd->flags = W_QUOTED|W_NOSPLIT|W_NOGLOB|W_DQUOTE;
6401 yylval.word_list = make_word_list (wd, (WORD_LIST *)NULL);
6404 else if (cmdtyp == 0) /* nested subshell */
6406 push_string (wval, 0, (alias_t *)NULL);
6407 pushed_string_list->flags = PSH_DPAREN;
6408 if ((parser_state & PST_CASEPAT) == 0)
6409 parser_state |= PST_SUBSHELL;
6417 return -2; /* XXX */
6420 /* We've seen a `(('. Look for the matching `))'. If we get it, return 1.
6421 If not, assume it's a nested subshell for backwards compatibility and
6422 return 0. In any case, put the characters we've consumed into a locally-
6423 allocated buffer and make *ep point to that buffer. Return -1 on an
6424 error, for example EOF. */
6426 parse_arith_cmd (ep, adddq)
6430 int exp_lineno, rval, c;
6431 char *ttok, *tokstr;
6434 exp_lineno = line_number;
6435 ttok = parse_matched_pair (0, '(', ')', &ttoklen, 0);
6437 if (ttok == &matched_pair_error)
6439 /* Check that the next character is the closing right paren. If
6440 not, this is a syntax error. ( */
6445 tokstr = (char *)xmalloc (ttoklen + 4);
6447 /* if ADDDQ != 0 then (( ... )) -> "..." */
6448 if (rval == 1 && adddq) /* arith cmd, add double quotes */
6451 strncpy (tokstr + 1, ttok, ttoklen - 1);
6452 tokstr[ttoklen] = '"';
6453 tokstr[ttoklen+1] = '\0';
6455 else if (rval == 1) /* arith cmd, don't add double quotes */
6457 strncpy (tokstr, ttok, ttoklen - 1);
6458 tokstr[ttoklen-1] = '\0';
6460 else /* nested subshell */
6463 strncpy (tokstr + 1, ttok, ttoklen - 1);
6464 tokstr[ttoklen] = ')';
6465 tokstr[ttoklen+1] = c;
6466 tokstr[ttoklen+2] = '\0';
6473 #endif /* DPAREN_ARITHMETIC || ARITH_FOR_COMMAND */
6475 #if defined (COND_COMMAND)
6481 if (EOF_Reached && cond_token != COND_ERROR) /* [[ */
6482 parser_error (cond_lineno, _("unexpected EOF while looking for `]]'"));
6483 else if (cond_token != COND_ERROR)
6485 if (etext = error_token_from_token (cond_token))
6487 parser_error (cond_lineno, _("syntax error in conditional expression: unexpected token `%s'"), etext);
6491 parser_error (cond_lineno, _("syntax error in conditional expression"));
6498 return (cond_or ());
6507 if (cond_token == OR_OR)
6510 l = make_cond_node (COND_OR, (WORD_DESC *)NULL, l, r);
6521 if (cond_token == AND_AND)
6524 l = make_cond_node (COND_AND, (WORD_DESC *)NULL, l, r);
6530 cond_skip_newlines ()
6532 while ((cond_token = read_token (READ)) == '\n')
6534 if (SHOULD_PROMPT ())
6537 return (cond_token);
6540 #define COND_RETURN_ERROR() \
6541 do { cond_token = COND_ERROR; return ((COND_COM *)NULL); } while (0)
6547 COND_COM *term, *tleft, *tright;
6551 /* Read a token. It can be a left paren, a `!', a unary operator, or a
6552 word that should be the first argument of a binary operator. Start by
6553 skipping newlines, since this is a compound command. */
6554 tok = cond_skip_newlines ();
6555 lineno = line_number;
6556 if (tok == COND_END)
6558 COND_RETURN_ERROR ();
6560 else if (tok == '(')
6562 term = cond_expr ();
6563 if (cond_token != ')')
6566 dispose_cond_node (term); /* ( */
6567 if (etext = error_token_from_token (cond_token))
6569 parser_error (lineno, _("unexpected token `%s', expected `)'"), etext);
6573 parser_error (lineno, _("expected `)'"));
6574 COND_RETURN_ERROR ();
6576 term = make_cond_node (COND_EXPR, (WORD_DESC *)NULL, term, (COND_COM *)NULL);
6577 (void)cond_skip_newlines ();
6579 else if (tok == BANG || (tok == WORD && (yylval.word->word[0] == '!' && yylval.word->word[1] == '\0')))
6582 dispose_word (yylval.word); /* not needed */
6583 term = cond_term ();
6585 term->flags |= CMD_INVERT_RETURN;
6587 else if (tok == WORD && yylval.word->word[0] == '-' && yylval.word->word[2] == 0 && test_unop (yylval.word->word))
6590 tok = read_token (READ);
6593 tleft = make_cond_node (COND_TERM, yylval.word, (COND_COM *)NULL, (COND_COM *)NULL);
6594 term = make_cond_node (COND_UNARY, op, tleft, (COND_COM *)NULL);
6599 if (etext = error_token_from_token (tok))
6601 parser_error (line_number, _("unexpected argument `%s' to conditional unary operator"), etext);
6605 parser_error (line_number, _("unexpected argument to conditional unary operator"));
6606 COND_RETURN_ERROR ();
6609 (void)cond_skip_newlines ();
6611 else if (tok == WORD) /* left argument to binary operator */
6614 tleft = make_cond_node (COND_TERM, yylval.word, (COND_COM *)NULL, (COND_COM *)NULL);
6617 tok = read_token (READ);
6618 if (tok == WORD && test_binop (yylval.word->word))
6621 if (op->word[0] == '=' && (op->word[1] == '\0' || (op->word[1] == '=' && op->word[2] == '\0')))
6622 parser_state |= PST_EXTPAT;
6623 else if (op->word[0] == '!' && op->word[1] == '=' && op->word[2] == '\0')
6624 parser_state |= PST_EXTPAT;
6626 #if defined (COND_REGEXP)
6627 else if (tok == WORD && STREQ (yylval.word->word, "=~"))
6630 parser_state |= PST_REGEXP;
6633 else if (tok == '<' || tok == '>')
6634 op = make_word_from_token (tok); /* ( */
6635 /* There should be a check before blindly accepting the `)' that we have
6636 seen the opening `('. */
6637 else if (tok == COND_END || tok == AND_AND || tok == OR_OR || tok == ')')
6639 /* Special case. [[ x ]] is equivalent to [[ -n x ]], just like
6640 the test command. Similarly for [[ x && expr ]] or
6641 [[ x || expr ]] or [[ (x) ]]. */
6642 op = make_word ("-n");
6643 term = make_cond_node (COND_UNARY, op, tleft, (COND_COM *)NULL);
6649 if (etext = error_token_from_token (tok))
6651 parser_error (line_number, _("unexpected token `%s', conditional binary operator expected"), etext);
6655 parser_error (line_number, _("conditional binary operator expected"));
6656 dispose_cond_node (tleft);
6657 COND_RETURN_ERROR ();
6661 if (parser_state & PST_EXTPAT)
6663 tok = read_token (READ);
6664 if (parser_state & PST_EXTPAT)
6665 extended_glob = global_extglob;
6666 parser_state &= ~(PST_REGEXP|PST_EXTPAT);
6670 tright = make_cond_node (COND_TERM, yylval.word, (COND_COM *)NULL, (COND_COM *)NULL);
6671 term = make_cond_node (COND_BINARY, op, tleft, tright);
6675 if (etext = error_token_from_token (tok))
6677 parser_error (line_number, _("unexpected argument `%s' to conditional binary operator"), etext);
6681 parser_error (line_number, _("unexpected argument to conditional binary operator"));
6682 dispose_cond_node (tleft);
6684 COND_RETURN_ERROR ();
6687 (void)cond_skip_newlines ();
6692 parser_error (line_number, _("unexpected token `%c' in conditional command"), tok);
6693 else if (etext = error_token_from_token (tok))
6695 parser_error (line_number, _("unexpected token `%s' in conditional command"), etext);
6699 parser_error (line_number, _("unexpected token %d in conditional command"), tok);
6700 COND_RETURN_ERROR ();
6705 /* This is kind of bogus -- we slip a mini recursive-descent parser in
6706 here to handle the conditional statement syntax. */
6708 parse_cond_command ()
6712 global_extglob = extended_glob;
6713 cexp = cond_expr ();
6714 return (make_cond_command (cexp));
6718 #if defined (ARRAY_VARS)
6719 /* When this is called, it's guaranteed that we don't care about anything
6720 in t beyond i. We do save and restore the chars, though. */
6722 token_is_assignment (t, i)
6726 unsigned char c, c1;
6729 c = t[i]; c1 = t[i+1];
6730 t[i] = '='; t[i+1] = '\0';
6731 r = assignment (t, (parser_state & PST_COMPASSIGN) != 0);
6732 t[i] = c; t[i+1] = c1;
6736 /* XXX - possible changes here for `+=' */
6738 token_is_ident (t, i)
6747 r = legal_identifier (t);
6754 read_token_word (character)
6757 /* The value for YYLVAL when a WORD is read. */
6758 WORD_DESC *the_word;
6760 /* Index into the token that we are building. */
6763 /* ALL_DIGITS becomes zero when we see a non-digit. */
6764 int all_digit_token;
6766 /* DOLLAR_PRESENT becomes non-zero if we see a `$'. */
6769 /* COMPOUND_ASSIGNMENT becomes non-zero if we are parsing a compound
6771 int compound_assignment;
6773 /* QUOTED becomes non-zero if we see one of ("), ('), (`), or (\). */
6776 /* Non-zero means to ignore the value of the next character, and just
6777 to add it no matter what. */
6778 int pass_next_character;
6780 /* The current delimiting character. */
6782 int result, peek_char;
6783 char *ttok, *ttrans;
6784 int ttoklen, ttranslen;
6787 if (token_buffer_size < TOKEN_DEFAULT_INITIAL_SIZE)
6788 token = (char *)xrealloc (token, token_buffer_size = TOKEN_DEFAULT_INITIAL_SIZE);
6791 all_digit_token = DIGIT (character);
6792 dollar_present = quoted = pass_next_character = compound_assignment = 0;
6796 if (character == EOF)
6799 if (pass_next_character)
6801 pass_next_character = 0;
6802 goto got_escaped_character;
6805 cd = current_delimiter (dstack);
6807 /* Handle backslashes. Quote lots of things when not inside of
6808 double-quotes, quote some things inside of double-quotes. */
6809 if MBTEST(character == '\\')
6811 peek_char = shell_getc (0);
6813 /* Backslash-newline is ignored in all cases except
6814 when quoted with single quotes. */
6815 if (peek_char == '\n')
6818 goto next_character;
6822 shell_ungetc (peek_char);
6824 /* If the next character is to be quoted, note it now. */
6825 if (cd == 0 || cd == '`' ||
6826 (cd == '"' && peek_char >= 0 && (sh_syntaxtab[peek_char] & CBSDQUOTE)))
6827 pass_next_character++;
6834 /* Parse a matched pair of quote characters. */
6835 if MBTEST(shellquote (character))
6837 push_delimiter (dstack, character);
6838 ttok = parse_matched_pair (character, character, character, &ttoklen, (character == '`') ? P_COMMAND : 0);
6839 pop_delimiter (dstack);
6840 if (ttok == &matched_pair_error)
6841 return -1; /* Bail immediately. */
6842 RESIZE_MALLOCED_BUFFER (token, token_index, ttoklen + 2,
6843 token_buffer_size, TOKEN_DEFAULT_GROW_SIZE);
6844 token[token_index++] = character;
6845 strcpy (token + token_index, ttok);
6846 token_index += ttoklen;
6847 all_digit_token = 0;
6849 dollar_present |= (character == '"' && strchr (ttok, '$') != 0);
6851 goto next_character;
6855 /* When parsing a regexp as a single word inside a conditional command,
6856 we need to special-case characters special to both the shell and
6857 regular expressions. Right now, that is only '(' and '|'. */ /*)*/
6858 if MBTEST((parser_state & PST_REGEXP) && (character == '(' || character == '|')) /*)*/
6860 if (character == '|')
6863 push_delimiter (dstack, character);
6864 ttok = parse_matched_pair (cd, '(', ')', &ttoklen, 0);
6865 pop_delimiter (dstack);
6866 if (ttok == &matched_pair_error)
6867 return -1; /* Bail immediately. */
6868 RESIZE_MALLOCED_BUFFER (token, token_index, ttoklen + 2,
6869 token_buffer_size, TOKEN_DEFAULT_GROW_SIZE);
6870 token[token_index++] = character;
6871 strcpy (token + token_index, ttok);
6872 token_index += ttoklen;
6874 dollar_present = all_digit_token = 0;
6875 goto next_character;
6877 #endif /* COND_REGEXP */
6879 #ifdef EXTENDED_GLOB
6880 /* Parse a ksh-style extended pattern matching specification. */
6881 if MBTEST(extended_glob && PATTERN_CHAR (character))
6883 peek_char = shell_getc (1);
6884 if MBTEST(peek_char == '(') /* ) */
6886 push_delimiter (dstack, peek_char);
6887 ttok = parse_matched_pair (cd, '(', ')', &ttoklen, 0);
6888 pop_delimiter (dstack);
6889 if (ttok == &matched_pair_error)
6890 return -1; /* Bail immediately. */
6891 RESIZE_MALLOCED_BUFFER (token, token_index, ttoklen + 3,
6893 TOKEN_DEFAULT_GROW_SIZE);
6894 token[token_index++] = character;
6895 token[token_index++] = peek_char;
6896 strcpy (token + token_index, ttok);
6897 token_index += ttoklen;
6899 dollar_present = all_digit_token = 0;
6900 goto next_character;
6903 shell_ungetc (peek_char);
6905 #endif /* EXTENDED_GLOB */
6907 /* If the delimiter character is not single quote, parse some of
6908 the shell expansions that must be read as a single word. */
6909 if (shellexp (character))
6911 peek_char = shell_getc (1);
6912 /* $(...), <(...), >(...), $((...)), ${...}, and $[...] constructs */
6913 if MBTEST(peek_char == '(' ||
6914 ((peek_char == '{' || peek_char == '[') && character == '$')) /* ) ] } */
6916 if (peek_char == '{') /* } */
6917 ttok = parse_matched_pair (cd, '{', '}', &ttoklen, P_FIRSTCLOSE|P_DOLBRACE);
6918 else if (peek_char == '(') /* ) */
6920 /* XXX - push and pop the `(' as a delimiter for use by
6921 the command-oriented-history code. This way newlines
6922 appearing in the $(...) string get added to the
6923 history literally rather than causing a possibly-
6924 incorrect `;' to be added. ) */
6925 push_delimiter (dstack, peek_char);
6926 ttok = parse_comsub (cd, '(', ')', &ttoklen, P_COMMAND);
6927 pop_delimiter (dstack);
6930 ttok = parse_matched_pair (cd, '[', ']', &ttoklen, 0);
6931 if (ttok == &matched_pair_error)
6932 return -1; /* Bail immediately. */
6933 RESIZE_MALLOCED_BUFFER (token, token_index, ttoklen + 3,
6935 TOKEN_DEFAULT_GROW_SIZE);
6936 token[token_index++] = character;
6937 token[token_index++] = peek_char;
6938 strcpy (token + token_index, ttok);
6939 token_index += ttoklen;
6942 all_digit_token = 0;
6943 goto next_character;
6945 /* This handles $'...' and $"..." new-style quoted strings. */
6946 else if MBTEST(character == '$' && (peek_char == '\'' || peek_char == '"'))
6950 first_line = line_number;
6951 push_delimiter (dstack, peek_char);
6952 ttok = parse_matched_pair (peek_char, peek_char, peek_char,
6954 (peek_char == '\'') ? P_ALLOWESC : 0);
6955 pop_delimiter (dstack);
6956 if (ttok == &matched_pair_error)
6958 if (peek_char == '\'')
6960 ttrans = ansiexpand (ttok, 0, ttoklen - 1, &ttranslen);
6963 /* Insert the single quotes and correctly quote any
6964 embedded single quotes (allowed because P_ALLOWESC was
6965 passed to parse_matched_pair). */
6966 ttok = sh_single_quote (ttrans);
6968 ttranslen = strlen (ttok);
6973 /* Try to locale-expand the converted string. */
6974 ttrans = localeexpand (ttok, 0, ttoklen - 1, first_line, &ttranslen);
6977 /* Add the double quotes back */
6978 ttok = sh_mkdoublequoted (ttrans, ttranslen, 0);
6984 RESIZE_MALLOCED_BUFFER (token, token_index, ttranslen + 1,
6986 TOKEN_DEFAULT_GROW_SIZE);
6987 strcpy (token + token_index, ttrans);
6988 token_index += ttranslen;
6991 all_digit_token = 0;
6992 goto next_character;
6994 /* This could eventually be extended to recognize all of the
6995 shell's single-character parameter expansions, and set flags.*/
6996 else if MBTEST(character == '$' && peek_char == '$')
6998 RESIZE_MALLOCED_BUFFER (token, token_index, 3,
7000 TOKEN_DEFAULT_GROW_SIZE);
7001 token[token_index++] = '$';
7002 token[token_index++] = peek_char;
7004 all_digit_token = 0;
7005 goto next_character;
7008 shell_ungetc (peek_char);
7011 #if defined (ARRAY_VARS)
7012 /* Identify possible array subscript assignment; match [...]. If
7013 parser_state&PST_COMPASSIGN, we need to parse [sub]=words treating
7014 `sub' as if it were enclosed in double quotes. */
7015 else if MBTEST(character == '[' && /* ] */
7016 ((token_index > 0 && assignment_acceptable (last_read_token) && token_is_ident (token, token_index)) ||
7017 (token_index == 0 && (parser_state&PST_COMPASSIGN))))
7019 ttok = parse_matched_pair (cd, '[', ']', &ttoklen, P_ARRAYSUB);
7020 if (ttok == &matched_pair_error)
7021 return -1; /* Bail immediately. */
7022 RESIZE_MALLOCED_BUFFER (token, token_index, ttoklen + 2,
7024 TOKEN_DEFAULT_GROW_SIZE);
7025 token[token_index++] = character;
7026 strcpy (token + token_index, ttok);
7027 token_index += ttoklen;
7029 all_digit_token = 0;
7030 goto next_character;
7032 /* Identify possible compound array variable assignment. */
7033 else if MBTEST(character == '=' && token_index > 0 && (assignment_acceptable (last_read_token) || (parser_state & PST_ASSIGNOK)) && token_is_assignment (token, token_index))
7035 peek_char = shell_getc (1);
7036 if MBTEST(peek_char == '(') /* ) */
7038 ttok = parse_compound_assignment (&ttoklen);
7040 RESIZE_MALLOCED_BUFFER (token, token_index, ttoklen + 4,
7042 TOKEN_DEFAULT_GROW_SIZE);
7044 token[token_index++] = '=';
7045 token[token_index++] = '(';
7048 strcpy (token + token_index, ttok);
7049 token_index += ttoklen;
7051 token[token_index++] = ')';
7053 all_digit_token = 0;
7054 compound_assignment = 1;
7056 goto next_character;
7058 goto got_token; /* ksh93 seems to do this */
7062 shell_ungetc (peek_char);
7066 /* When not parsing a multi-character word construct, shell meta-
7067 characters break words. */
7068 if MBTEST(shellbreak (character))
7070 shell_ungetc (character);
7076 if (character == CTLESC || character == CTLNUL)
7078 RESIZE_MALLOCED_BUFFER (token, token_index, 2, token_buffer_size,
7079 TOKEN_DEFAULT_GROW_SIZE);
7080 token[token_index++] = CTLESC;
7083 got_escaped_character:
7084 RESIZE_MALLOCED_BUFFER (token, token_index, 1, token_buffer_size,
7085 TOKEN_DEFAULT_GROW_SIZE);
7087 token[token_index++] = character;
7089 all_digit_token &= DIGIT (character);
7090 dollar_present |= character == '$';
7093 if (character == '\n' && SHOULD_PROMPT ())
7096 /* We want to remove quoted newlines (that is, a \<newline> pair)
7097 unless we are within single quotes or pass_next_character is
7098 set (the shell equivalent of literal-next). */
7099 cd = current_delimiter (dstack);
7100 character = shell_getc (cd != '\'' && pass_next_character == 0);
7101 } /* end for (;;) */
7105 /* Calls to RESIZE_MALLOCED_BUFFER ensure there is sufficient room. */
7106 token[token_index] = '\0';
7108 /* Check to see what thing we should return. If the last_read_token
7109 is a `<', or a `&', or the character which ended this token is
7110 a '>' or '<', then, and ONLY then, is this input token a NUMBER.
7111 Otherwise, it is just a word, and should be returned as such. */
7112 if MBTEST(all_digit_token && (character == '<' || character == '>' ||
7113 last_read_token == LESS_AND ||
7114 last_read_token == GREATER_AND))
7116 if (legal_number (token, &lvalue) && (int)lvalue == lvalue)
7118 yylval.number = lvalue;
7123 /* Check for special case tokens. */
7124 result = (last_shell_getc_is_singlebyte) ? special_case_tokens (token) : -1;
7129 /* Posix.2 does not allow reserved words to be aliased, so check for all
7130 of them, including special cases, before expanding the current token
7132 if MBTEST(posixly_correct)
7133 CHECK_FOR_RESERVED_WORD (token);
7135 /* Aliases are expanded iff EXPAND_ALIASES is non-zero, and quoting
7136 inhibits alias expansion. */
7137 if (expand_aliases && quoted == 0)
7139 result = alias_expand_token (token);
7140 if (result == RE_READ_TOKEN)
7141 return (RE_READ_TOKEN);
7142 else if (result == NO_EXPANSION)
7143 parser_state &= ~PST_ALEXPNEXT;
7146 /* If not in Posix.2 mode, check for reserved words after alias
7148 if MBTEST(posixly_correct == 0)
7150 CHECK_FOR_RESERVED_WORD (token);
7152 the_word = (WORD_DESC *)xmalloc (sizeof (WORD_DESC));
7153 the_word->word = (char *)xmalloc (1 + token_index);
7154 the_word->flags = 0;
7155 strcpy (the_word->word, token);
7157 the_word->flags |= W_HASDOLLAR;
7159 the_word->flags |= W_QUOTED; /*(*/
7160 if (compound_assignment && token[token_index-1] == ')')
7161 the_word->flags |= W_COMPASSIGN;
7162 /* A word is an assignment if it appears at the beginning of a
7163 simple command, or after another assignment word. This is
7164 context-dependent, so it cannot be handled in the grammar. */
7165 if (assignment (token, (parser_state & PST_COMPASSIGN) != 0))
7167 the_word->flags |= W_ASSIGNMENT;
7168 /* Don't perform word splitting on assignment statements. */
7169 if (assignment_acceptable (last_read_token) || (parser_state & PST_COMPASSIGN) != 0)
7171 the_word->flags |= W_NOSPLIT;
7172 if (parser_state & PST_COMPASSIGN)
7173 the_word->flags |= W_NOGLOB; /* XXX - W_NOBRACE? */
7177 if (command_token_position (last_read_token))
7180 b = builtin_address_internal (token, 0);
7181 if (b && (b->flags & ASSIGNMENT_BUILTIN))
7182 parser_state |= PST_ASSIGNOK;
7183 else if (STREQ (token, "eval") || STREQ (token, "let"))
7184 parser_state |= PST_ASSIGNOK;
7187 yylval.word = the_word;
7189 if (token[0] == '{' && token[token_index-1] == '}' &&
7190 (character == '<' || character == '>'))
7192 /* can use token; already copied to the_word */
7193 token[token_index-1] = '\0';
7194 #if defined (ARRAY_VARS)
7195 if (legal_identifier (token+1) || valid_array_reference (token+1))
7197 if (legal_identifier (token+1))
7200 strcpy (the_word->word, token+1);
7201 /*itrace("read_token_word: returning REDIR_WORD for %s", the_word->word);*/
7202 return (REDIR_WORD);
7206 result = ((the_word->flags & (W_ASSIGNMENT|W_NOSPLIT)) == (W_ASSIGNMENT|W_NOSPLIT))
7207 ? ASSIGNMENT_WORD : WORD;
7209 switch (last_read_token)
7212 parser_state |= PST_ALLOWOPNBRC;
7213 function_dstart = line_number;
7218 if (word_top < MAX_CASE_NEST)
7220 word_lineno[word_top] = line_number;
7227 /* Return 1 if TOKSYM is a token that after being read would allow
7228 a reserved word to be seen, else 0. */
7230 reserved_word_acceptable (toksym)
7267 #if defined (COPROCESS_SUPPORT)
7268 if (last_read_token == WORD && token_before_that == COPROC)
7271 if (last_read_token == WORD && token_before_that == FUNCTION)
7277 /* Return the index of TOKEN in the alist of reserved words, or -1 if
7278 TOKEN is not a shell reserved word. */
7280 find_reserved_word (tokstr)
7284 for (i = 0; word_token_alist[i].word; i++)
7285 if (STREQ (tokstr, word_token_alist[i].word))
7290 /* An interface to let the rest of the shell (primarily the completion
7291 system) know what the parser is expecting. */
7293 parser_in_command_position ()
7295 return (command_token_position (last_read_token));
7299 #if defined (READLINE)
7300 /* Called after each time readline is called. This insures that whatever
7301 the new prompt string is gets propagated to readline's local prompt
7304 reset_readline_prompt ()
7308 if (prompt_string_pointer)
7310 temp_prompt = (*prompt_string_pointer)
7311 ? decode_prompt_string (*prompt_string_pointer)
7314 if (temp_prompt == 0)
7316 temp_prompt = (char *)xmalloc (1);
7317 temp_prompt[0] = '\0';
7320 FREE (current_readline_prompt);
7321 current_readline_prompt = temp_prompt;
7324 #endif /* READLINE */
7327 #if defined (HISTORY)
7328 /* A list of tokens which can be followed by newlines, but not by
7329 semi-colons. When concatenating multiple lines of history, the
7330 newline separator for such tokens is replaced with a space. */
7331 static const int no_semi_successors[] = {
7332 '\n', '{', '(', ')', ';', '&', '|',
7333 CASE, DO, ELSE, IF, SEMI_SEMI, SEMI_AND, SEMI_SEMI_AND, THEN, UNTIL,
7334 WHILE, AND_AND, OR_OR, IN,
7338 /* If we are not within a delimited expression, try to be smart
7339 about which separators can be semi-colons and which must be
7340 newlines. Returns the string that should be added into the
7341 history entry. LINE is the line we're about to add; it helps
7342 make some more intelligent decisions in certain cases. */
7344 history_delimiting_chars (line)
7347 static int last_was_heredoc = 0; /* was the last entry the start of a here document? */
7350 if ((parser_state & PST_HEREDOC) == 0)
7351 last_was_heredoc = 0;
7353 if (dstack.delimiter_depth != 0)
7356 /* We look for current_command_line_count == 2 because we are looking to
7357 add the first line of the body of the here document (the second line
7358 of the command). We also keep LAST_WAS_HEREDOC as a private sentinel
7359 variable to note when we think we added the first line of a here doc
7360 (the one with a "<<" somewhere in it) */
7361 if (parser_state & PST_HEREDOC)
7363 if (last_was_heredoc)
7365 last_was_heredoc = 0;
7368 return (current_command_line_count == 2 ? "\n" : "");
7371 if (parser_state & PST_COMPASSIGN)
7374 /* First, handle some special cases. */
7376 /* If we just read `()', assume it's a function definition, and don't
7377 add a semicolon. If the token before the `)' was not `(', and we're
7378 not in the midst of parsing a case statement, assume it's a
7379 parenthesized command and add the semicolon. */
7381 if (token_before_that == ')')
7383 if (two_tokens_ago == '(') /*)*/ /* function def */
7385 /* This does not work for subshells inside case statement
7386 command lists. It's a suboptimal solution. */
7387 else if (parser_state & PST_CASESTMT) /* case statement pattern */
7390 return "; "; /* (...) subshell */
7392 else if (token_before_that == WORD && two_tokens_ago == FUNCTION)
7393 return " "; /* function def using `function name' without `()' */
7395 /* If we're not in a here document, but we think we're about to parse one,
7396 and we would otherwise return a `;', return a newline to delimit the
7397 line with the here-doc delimiter */
7398 else if ((parser_state & PST_HEREDOC) == 0 && current_command_line_count > 1 && last_read_token == '\n' && strstr (line, "<<"))
7400 last_was_heredoc = 1;
7404 else if (token_before_that == WORD && two_tokens_ago == FOR)
7406 /* Tricky. `for i\nin ...' should not have a semicolon, but
7407 `for i\ndo ...' should. We do what we can. */
7408 for (i = shell_input_line_index; whitespace (shell_input_line[i]); i++)
7410 if (shell_input_line[i] && shell_input_line[i] == 'i' && shell_input_line[i+1] == 'n')
7414 else if (two_tokens_ago == CASE && token_before_that == WORD && (parser_state & PST_CASESTMT))
7417 for (i = 0; no_semi_successors[i]; i++)
7419 if (token_before_that == no_semi_successors[i])
7425 #endif /* HISTORY */
7427 /* Issue a prompt, or prepare to issue a prompt when the next character
7434 if (interactive == 0 || expanding_alias ()) /* XXX */
7437 ps1_prompt = get_string_value ("PS1");
7438 ps2_prompt = get_string_value ("PS2");
7440 if (!prompt_string_pointer)
7441 prompt_string_pointer = &ps1_prompt;
7443 temp_prompt = *prompt_string_pointer
7444 ? decode_prompt_string (*prompt_string_pointer)
7447 if (temp_prompt == 0)
7449 temp_prompt = (char *)xmalloc (1);
7450 temp_prompt[0] = '\0';
7453 current_prompt_string = *prompt_string_pointer;
7454 prompt_string_pointer = &ps2_prompt;
7456 #if defined (READLINE)
7457 if (!no_line_editing)
7459 FREE (current_readline_prompt);
7460 current_readline_prompt = temp_prompt;
7463 #endif /* READLINE */
7465 FREE (current_decoded_prompt);
7466 current_decoded_prompt = temp_prompt;
7471 get_current_prompt_level ()
7473 return ((current_prompt_string && current_prompt_string == ps2_prompt) ? 2 : 1);
7477 set_current_prompt_level (x)
7480 prompt_string_pointer = (x == 2) ? &ps2_prompt : &ps1_prompt;
7481 current_prompt_string = *prompt_string_pointer;
7487 fprintf (stderr, "%s", current_decoded_prompt);
7491 /* Return a string which will be printed as a prompt. The string
7492 may contain special characters which are decoded as follows:
7495 \d the date in Day Mon Date format
7496 \e escape (ascii 033)
7497 \h the hostname up to the first `.'
7499 \j the number of active jobs
7500 \l the basename of the shell's tty device name
7503 \s the name of the shell
7504 \t the time in 24-hour hh:mm:ss format
7505 \T the time in 12-hour hh:mm:ss format
7506 \@ the time in 12-hour hh:mm am/pm format
7507 \A the time in 24-hour hh:mm format
7508 \D{fmt} the result of passing FMT to strftime(3)
7510 \v the version of bash (e.g., 2.00)
7511 \V the release of bash, version + patchlevel (e.g., 2.00.0)
7512 \w the current working directory
7513 \W the last element of $PWD
7514 \! the history number of this command
7515 \# the command number of this command
7516 \$ a $ or a # if you are root
7517 \nnn character code nnn in octal
7519 \[ begin a sequence of non-printing chars
7520 \] end a sequence of non-printing chars
7522 #define PROMPT_GROWTH 48
7524 decode_prompt_string (string)
7529 struct dstack save_dstack;
7530 int last_exit_value, last_comsub_pid;
7531 #if defined (PROMPT_STRING_DECODE)
7532 int result_size, result_index;
7534 char *temp, octal_string[4];
7540 result = (char *)xmalloc (result_size = PROMPT_GROWTH);
7541 result[result_index = 0] = 0;
7542 temp = (char *)NULL;
7544 while (c = *string++)
7546 if (posixly_correct && c == '!')
7550 temp = savestring ("!");
7555 #if !defined (HISTORY)
7556 temp = savestring ("1");
7558 temp = itos (history_number ());
7559 #endif /* HISTORY */
7560 string--; /* add_string increments string again. */
7578 strncpy (octal_string, string, 3);
7579 octal_string[3] = '\0';
7581 n = read_octal (octal_string);
7582 temp = (char *)xmalloc (3);
7584 if (n == CTLESC || n == CTLNUL)
7601 for (c = 0; n != -1 && c < 3 && ISOCTAL (*string); c++)
7604 c = 0; /* tested at add_string: */
7612 /* Make the current time/date into a string. */
7613 (void) time (&the_time);
7614 #if defined (HAVE_TZSET)
7615 sv_tz ("TZ"); /* XXX -- just make sure */
7617 tm = localtime (&the_time);
7620 n = strftime (timebuf, sizeof (timebuf), "%a %b %d", tm);
7622 n = strftime (timebuf, sizeof (timebuf), "%H:%M:%S", tm);
7624 n = strftime (timebuf, sizeof (timebuf), "%I:%M:%S", tm);
7626 n = strftime (timebuf, sizeof (timebuf), "%I:%M %p", tm);
7628 n = strftime (timebuf, sizeof (timebuf), "%H:%M", tm);
7633 timebuf[sizeof(timebuf) - 1] = '\0';
7635 temp = savestring (timebuf);
7638 case 'D': /* strftime format */
7639 if (string[1] != '{') /* } */
7642 (void) time (&the_time);
7643 tm = localtime (&the_time);
7644 string += 2; /* skip { */
7645 timefmt = xmalloc (strlen (string) + 3);
7646 for (t = timefmt; *string && *string != '}'; )
7649 c = *string; /* tested at add_string */
7650 if (timefmt[0] == '\0')
7653 timefmt[1] = 'X'; /* locale-specific current time */
7656 n = strftime (timebuf, sizeof (timebuf), timefmt, tm);
7662 timebuf[sizeof(timebuf) - 1] = '\0';
7664 if (promptvars || posixly_correct)
7665 /* Make sure that expand_prompt_string is called with a
7666 second argument of Q_DOUBLE_QUOTES if we use this
7668 temp = sh_backslash_quote_for_double_quotes (timebuf);
7670 temp = savestring (timebuf);
7674 temp = (char *)xmalloc (3);
7675 temp[0] = no_line_editing ? '\n' : '\r';
7676 temp[1] = no_line_editing ? '\0' : '\n';
7681 temp = base_pathname (shell_name);
7682 temp = savestring (temp);
7687 temp = (char *)xmalloc (16);
7689 strcpy (temp, dist_version);
7691 sprintf (temp, "%s.%d", dist_version, patch_level);
7697 /* Use the value of PWD because it is much more efficient. */
7698 char t_string[PATH_MAX];
7701 temp = get_string_value ("PWD");
7705 if (getcwd (t_string, sizeof(t_string)) == 0)
7711 tlen = strlen (t_string);
7715 tlen = sizeof (t_string) - 1;
7716 strncpy (t_string, temp, tlen);
7718 t_string[tlen] = '\0';
7720 #if defined (MACOSX)
7721 /* Convert from "fs" format to "input" format */
7722 temp = fnx_fromfs (t_string, strlen (t_string));
7723 if (temp != t_string)
7724 strcpy (t_string, temp);
7727 #define ROOT_PATH(x) ((x)[0] == '/' && (x)[1] == 0)
7728 #define DOUBLE_SLASH_ROOT(x) ((x)[0] == '/' && (x)[1] == '/' && (x)[2] == 0)
7729 /* Abbreviate \W as ~ if $PWD == $HOME */
7730 if (c == 'W' && (((t = get_string_value ("HOME")) == 0) || STREQ (t, t_string) == 0))
7732 if (ROOT_PATH (t_string) == 0 && DOUBLE_SLASH_ROOT (t_string) == 0)
7734 t = strrchr (t_string, '/');
7736 memmove (t_string, t + 1, strlen (t)); /* strlen(t) to copy NULL */
7740 #undef DOUBLE_SLASH_ROOT
7743 /* polite_directory_format is guaranteed to return a string
7744 no longer than PATH_MAX - 1 characters. */
7745 temp = polite_directory_format (t_string);
7746 if (temp != t_string)
7747 strcpy (t_string, temp);
7750 temp = trim_pathname (t_string, PATH_MAX - 1);
7751 /* If we're going to be expanding the prompt string later,
7752 quote the directory name. */
7753 if (promptvars || posixly_correct)
7754 /* Make sure that expand_prompt_string is called with a
7755 second argument of Q_DOUBLE_QUOTES if we use this
7757 temp = sh_backslash_quote_for_double_quotes (t_string);
7759 temp = savestring (t_string);
7765 if (current_user.user_name == 0)
7766 get_current_user_info ();
7767 temp = savestring (current_user.user_name);
7772 temp = savestring (current_host_name);
7773 if (c == 'h' && (t = (char *)strchr (temp, '.')))
7778 temp = itos (current_command_number);
7782 #if !defined (HISTORY)
7783 temp = savestring ("1");
7785 temp = itos (history_number ());
7786 #endif /* HISTORY */
7790 t = temp = (char *)xmalloc (3);
7791 if ((promptvars || posixly_correct) && (current_user.euid != 0))
7793 *t++ = current_user.euid == 0 ? '#' : '$';
7798 temp = itos (count_all_jobs ());
7802 #if defined (HAVE_TTYNAME)
7803 temp = (char *)ttyname (fileno (stdin));
7804 t = temp ? base_pathname (temp) : "tty";
7805 temp = savestring (t);
7807 temp = savestring ("tty");
7808 #endif /* !HAVE_TTYNAME */
7811 #if defined (READLINE)
7814 if (no_line_editing)
7819 temp = (char *)xmalloc (3);
7820 n = (c == '[') ? RL_PROMPT_START_IGNORE : RL_PROMPT_END_IGNORE;
7822 if (n == CTLESC || n == CTLNUL)
7827 #endif /* READLINE */
7833 temp = (char *)xmalloc (2);
7840 else /* (c == '\\') */
7847 temp = (char *)xmalloc (3);
7856 sub_append_string (temp, result, &result_index, &result_size);
7857 temp = (char *)NULL; /* Freed in sub_append_string (). */
7858 result[result_index] = '\0';
7864 RESIZE_MALLOCED_BUFFER (result, result_index, 3, result_size, PROMPT_GROWTH);
7865 result[result_index++] = c;
7866 result[result_index] = '\0';
7869 #else /* !PROMPT_STRING_DECODE */
7870 result = savestring (string);
7871 #endif /* !PROMPT_STRING_DECODE */
7873 /* Save the delimiter stack and point `dstack' to temp space so any
7874 command substitutions in the prompt string won't result in screwing
7875 up the parser's quoting state. */
7876 save_dstack = dstack;
7877 dstack = temp_dstack;
7878 dstack.delimiter_depth = 0;
7880 /* Perform variable and parameter expansion and command substitution on
7881 the prompt string. */
7882 if (promptvars || posixly_correct)
7884 last_exit_value = last_command_exit_value;
7885 last_comsub_pid = last_command_subst_pid;
7886 list = expand_prompt_string (result, Q_DOUBLE_QUOTES, 0);
7888 result = string_list (list);
7889 dispose_words (list);
7890 last_command_exit_value = last_exit_value;
7891 last_command_subst_pid = last_comsub_pid;
7895 t = dequote_string (result);
7900 dstack = save_dstack;
7905 /************************************************
7909 ************************************************/
7911 /* Report a syntax error, and restart the parser. Call here for fatal
7917 report_syntax_error ((char *)NULL);
7923 error_token_from_token (tok)
7928 if (t = find_token_in_alist (tok, word_token_alist, 0))
7931 if (t = find_token_in_alist (tok, other_token_alist, 0))
7935 /* This stuff is dicy and needs closer inspection */
7936 switch (current_token)
7939 case ASSIGNMENT_WORD:
7941 t = savestring (yylval.word->word);
7944 t = itos (yylval.number);
7947 if (yylval.word_list)
7948 t = string_list (yylval.word_list);
7950 case ARITH_FOR_EXPRS:
7951 if (yylval.word_list)
7952 t = string_list_internal (yylval.word_list, " ; ");
7955 t = (char *)NULL; /* punt */
7963 error_token_from_text ()
7968 t = shell_input_line;
7969 i = shell_input_line_index;
7973 if (i && t[i] == '\0')
7976 while (i && (whitespace (t[i]) || t[i] == '\n'))
7982 while (i && (member (t[i], " \n\t;|&") == 0))
7985 while (i != token_end && (whitespace (t[i]) || t[i] == '\n'))
7988 /* Return our idea of the offending token. */
7989 if (token_end || (i == 0 && token_end == 0))
7992 msg = substring (t, i, token_end);
7993 else /* one-character token */
7995 msg = (char *)xmalloc (2);
8005 print_offending_line ()
8010 msg = savestring (shell_input_line);
8011 token_end = strlen (msg);
8012 while (token_end && msg[token_end - 1] == '\n')
8013 msg[--token_end] = '\0';
8015 parser_error (line_number, "`%s'", msg);
8019 /* Report a syntax error with line numbers, etc.
8020 Call here for recoverable errors. If you have a message to print,
8021 then place it in MESSAGE, otherwise pass NULL and this will figure
8022 out an appropriate message for you. */
8024 report_syntax_error (message)
8031 parser_error (line_number, "%s", message);
8032 if (interactive && EOF_Reached)
8034 last_command_exit_value = parse_and_execute_level ? EX_BADSYNTAX : EX_BADUSAGE;
8038 /* If the line of input we're reading is not null, try to find the
8039 objectionable token. First, try to figure out what token the
8040 parser's complaining about by looking at current_token. */
8041 if (current_token != 0 && EOF_Reached == 0 && (msg = error_token_from_token (current_token)))
8043 if (ansic_shouldquote (msg))
8045 p = ansic_quote (msg, 0, NULL);
8049 parser_error (line_number, _("syntax error near unexpected token `%s'"), msg);
8052 if (interactive == 0)
8053 print_offending_line ();
8055 last_command_exit_value = parse_and_execute_level ? EX_BADSYNTAX : EX_BADUSAGE;
8059 /* If looking at the current token doesn't prove fruitful, try to find the
8060 offending token by analyzing the text of the input line near the current
8061 input line index and report what we find. */
8062 if (shell_input_line && *shell_input_line)
8064 msg = error_token_from_text ();
8067 parser_error (line_number, _("syntax error near `%s'"), msg);
8071 /* If not interactive, print the line containing the error. */
8072 if (interactive == 0)
8073 print_offending_line ();
8077 msg = EOF_Reached ? _("syntax error: unexpected end of file") : _("syntax error");
8078 parser_error (line_number, "%s", msg);
8079 /* When the shell is interactive, this file uses EOF_Reached
8080 only for error reporting. Other mechanisms are used to
8081 decide whether or not to exit. */
8082 if (interactive && EOF_Reached)
8086 last_command_exit_value = parse_and_execute_level ? EX_BADSYNTAX : EX_BADUSAGE;
8089 /* ??? Needed function. ??? We have to be able to discard the constructs
8090 created during parsing. In the case of error, we want to return
8091 allocated objects to the memory pool. In the case of no error, we want
8092 to throw away the information about where the allocated objects live.
8093 (dispose_command () will actually free the command.) */
8095 discard_parser_constructs (error_p)
8100 /************************************************
8104 ************************************************/
8106 /* Do that silly `type "bye" to exit' stuff. You know, "ignoreeof". */
8108 /* A flag denoting whether or not ignoreeof is set. */
8111 /* The number of times that we have encountered an EOF character without
8112 another character intervening. When this gets above the limit, the
8113 shell terminates. */
8114 int eof_encountered = 0;
8116 /* The limit for eof_encountered. */
8117 int eof_encountered_limit = 10;
8119 /* If we have EOF as the only input unit, this user wants to leave
8120 the shell. If the shell is not interactive, then just leave.
8121 Otherwise, if ignoreeof is set, and we haven't done this the
8122 required number of times in a row, print a message. */
8124 handle_eof_input_unit ()
8128 /* shell.c may use this to decide whether or not to write out the
8129 history, among other things. We use it only for error reporting
8134 /* If the user wants to "ignore" eof, then let her do so, kind of. */
8137 if (eof_encountered < eof_encountered_limit)
8139 fprintf (stderr, _("Use \"%s\" to leave the shell.\n"),
8140 login_shell ? "logout" : "exit");
8142 /* Reset the parsing state. */
8143 last_read_token = current_token = '\n';
8144 /* Reset the prompt string to be $PS1. */
8145 prompt_string_pointer = (char **)NULL;
8151 /* In this case EOF should exit the shell. Do it now. */
8153 exit_builtin ((WORD_LIST *)NULL);
8157 /* We don't write history files, etc., for non-interactive shells. */
8162 /************************************************
8164 * STRING PARSING FUNCTIONS *
8166 ************************************************/
8168 /* It's very important that these two functions treat the characters
8169 between ( and ) identically. */
8171 static WORD_LIST parse_string_error;
8173 /* Take a string and run it through the shell parser, returning the
8174 resultant word list. Used by compound array assignment. */
8176 parse_string_to_word_list (s, flags, whom)
8182 int tok, orig_current_token, orig_line_number, orig_input_terminator;
8183 int orig_line_count;
8184 int old_echo_input, old_expand_aliases;
8185 #if defined (HISTORY)
8186 int old_remember_on_history, old_history_expansion_inhibited;
8189 #if defined (HISTORY)
8190 old_remember_on_history = remember_on_history;
8191 # if defined (BANG_HISTORY)
8192 old_history_expansion_inhibited = history_expansion_inhibited;
8194 bash_history_disable ();
8197 orig_line_number = line_number;
8198 orig_line_count = current_command_line_count;
8199 orig_input_terminator = shell_input_line_terminator;
8200 old_echo_input = echo_input_at_read;
8201 old_expand_aliases = expand_aliases;
8204 last_read_token = WORD; /* WORD to allow reserved words here */
8205 current_command_line_count = 0;
8206 echo_input_at_read = expand_aliases = 0;
8208 with_input_from_string (s, whom);
8209 wl = (WORD_LIST *)NULL;
8212 parser_state |= PST_COMPASSIGN|PST_REPARSE;
8214 while ((tok = read_token (READ)) != yacc_EOF)
8216 if (tok == '\n' && *bash_input.location.string == '\0')
8218 if (tok == '\n') /* Allow newlines in compound assignments */
8220 if (tok != WORD && tok != ASSIGNMENT_WORD)
8222 line_number = orig_line_number + line_number - 1;
8223 orig_current_token = current_token;
8224 current_token = tok;
8225 yyerror (NULL); /* does the right thing */
8226 current_token = orig_current_token;
8229 wl = &parse_string_error;
8232 wl = make_word_list (yylval.word, wl);
8235 last_read_token = '\n';
8238 #if defined (HISTORY)
8239 remember_on_history = old_remember_on_history;
8240 # if defined (BANG_HISTORY)
8241 history_expansion_inhibited = old_history_expansion_inhibited;
8242 # endif /* BANG_HISTORY */
8243 #endif /* HISTORY */
8245 echo_input_at_read = old_echo_input;
8246 expand_aliases = old_expand_aliases;
8248 current_command_line_count = orig_line_count;
8249 shell_input_line_terminator = orig_input_terminator;
8252 parser_state &= ~(PST_COMPASSIGN|PST_REPARSE);
8254 if (wl == &parse_string_error)
8256 last_command_exit_value = EXECUTION_FAILURE;
8257 if (interactive_shell == 0 && posixly_correct)
8258 jump_to_top_level (FORCE_EOF);
8260 jump_to_top_level (DISCARD);
8263 return (REVERSE_LIST (wl, WORD_LIST *));
8267 parse_compound_assignment (retlenp)
8271 int tok, orig_line_number, orig_token_size, orig_last_token, assignok;
8272 char *saved_token, *ret;
8274 saved_token = token;
8275 orig_token_size = token_buffer_size;
8276 orig_line_number = line_number;
8277 orig_last_token = last_read_token;
8279 last_read_token = WORD; /* WORD to allow reserved words here */
8281 token = (char *)NULL;
8282 token_buffer_size = 0;
8284 assignok = parser_state&PST_ASSIGNOK; /* XXX */
8286 wl = (WORD_LIST *)NULL; /* ( */
8287 parser_state |= PST_COMPASSIGN;
8289 while ((tok = read_token (READ)) != ')')
8291 if (tok == '\n') /* Allow newlines in compound assignments */
8293 if (SHOULD_PROMPT ())
8297 if (tok != WORD && tok != ASSIGNMENT_WORD)
8299 current_token = tok; /* for error reporting */
8300 if (tok == yacc_EOF) /* ( */
8301 parser_error (orig_line_number, _("unexpected EOF while looking for matching `)'"));
8303 yyerror(NULL); /* does the right thing */
8306 wl = &parse_string_error;
8309 wl = make_word_list (yylval.word, wl);
8313 token = saved_token;
8314 token_buffer_size = orig_token_size;
8316 parser_state &= ~PST_COMPASSIGN;
8318 if (wl == &parse_string_error)
8320 last_command_exit_value = EXECUTION_FAILURE;
8321 last_read_token = '\n'; /* XXX */
8322 if (interactive_shell == 0 && posixly_correct)
8323 jump_to_top_level (FORCE_EOF);
8325 jump_to_top_level (DISCARD);
8328 last_read_token = orig_last_token; /* XXX - was WORD? */
8332 rl = REVERSE_LIST (wl, WORD_LIST *);
8333 ret = string_list (rl);
8340 *retlenp = (ret && *ret) ? strlen (ret) : 0;
8343 parser_state |= PST_ASSIGNOK;
8348 /************************************************
8350 * SAVING AND RESTORING PARTIAL PARSE STATE *
8352 ************************************************/
8355 save_parser_state (ps)
8356 sh_parser_state_t *ps;
8359 ps = (sh_parser_state_t *)xmalloc (sizeof (sh_parser_state_t));
8361 return ((sh_parser_state_t *)NULL);
8363 ps->parser_state = parser_state;
8364 ps->token_state = save_token_state ();
8366 ps->input_line_terminator = shell_input_line_terminator;
8367 ps->eof_encountered = eof_encountered;
8369 ps->prompt_string_pointer = prompt_string_pointer;
8371 ps->current_command_line_count = current_command_line_count;
8373 #if defined (HISTORY)
8374 ps->remember_on_history = remember_on_history;
8375 # if defined (BANG_HISTORY)
8376 ps->history_expansion_inhibited = history_expansion_inhibited;
8380 ps->last_command_exit_value = last_command_exit_value;
8381 #if defined (ARRAY_VARS)
8382 ps->pipestatus = save_pipestatus_array ();
8385 ps->last_shell_builtin = last_shell_builtin;
8386 ps->this_shell_builtin = this_shell_builtin;
8388 ps->expand_aliases = expand_aliases;
8389 ps->echo_input_at_read = echo_input_at_read;
8392 ps->token_buffer_size = token_buffer_size;
8393 /* Force reallocation on next call to read_token_word */
8395 token_buffer_size = 0;
8401 restore_parser_state (ps)
8402 sh_parser_state_t *ps;
8407 parser_state = ps->parser_state;
8408 if (ps->token_state)
8410 restore_token_state (ps->token_state);
8411 free (ps->token_state);
8414 shell_input_line_terminator = ps->input_line_terminator;
8415 eof_encountered = ps->eof_encountered;
8417 prompt_string_pointer = ps->prompt_string_pointer;
8419 current_command_line_count = ps->current_command_line_count;
8421 #if defined (HISTORY)
8422 remember_on_history = ps->remember_on_history;
8423 # if defined (BANG_HISTORY)
8424 history_expansion_inhibited = ps->history_expansion_inhibited;
8428 last_command_exit_value = ps->last_command_exit_value;
8429 #if defined (ARRAY_VARS)
8430 restore_pipestatus_array (ps->pipestatus);
8433 last_shell_builtin = ps->last_shell_builtin;
8434 this_shell_builtin = ps->this_shell_builtin;
8436 expand_aliases = ps->expand_aliases;
8437 echo_input_at_read = ps->echo_input_at_read;
8441 token_buffer_size = ps->token_buffer_size;
8444 sh_input_line_state_t *
8445 save_input_line_state (ls)
8446 sh_input_line_state_t *ls;
8449 ls = (sh_input_line_state_t *)xmalloc (sizeof (sh_input_line_state_t));
8451 return ((sh_input_line_state_t *)NULL);
8453 ls->input_line = shell_input_line;
8454 ls->input_line_size = shell_input_line_size;
8455 ls->input_line_len = shell_input_line_len;
8456 ls->input_line_index = shell_input_line_index;
8458 /* force reallocation */
8459 shell_input_line = 0;
8460 shell_input_line_size = shell_input_line_len = shell_input_line_index = 0;
8466 restore_input_line_state (ls)
8467 sh_input_line_state_t *ls;
8469 FREE (shell_input_line);
8470 shell_input_line = ls->input_line;
8471 shell_input_line_size = ls->input_line_size;
8472 shell_input_line_len = ls->input_line_len;
8473 shell_input_line_index = ls->input_line_index;
8475 set_line_mbstate ();
8478 /************************************************
8480 * MULTIBYTE CHARACTER HANDLING *
8482 ************************************************/
8484 #if defined (HANDLE_MULTIBYTE)
8489 size_t i, previ, len;
8490 mbstate_t mbs, prevs;
8493 if (shell_input_line == NULL)
8495 len = strlen (shell_input_line); /* XXX - shell_input_line_len ? */
8496 FREE (shell_input_line_property);
8497 shell_input_line_property = (char *)xmalloc (len + 1);
8499 memset (&prevs, '\0', sizeof (mbstate_t));
8500 for (i = previ = 0; i < len; i++)
8504 c = shell_input_line[i];
8508 for (j = i; j < len; j++)
8509 shell_input_line_property[j] = 1;
8513 mbclen = mbrlen (shell_input_line + previ, i - previ + 1, &mbs);
8514 if (mbclen == 1 || mbclen == (size_t)-1)
8519 else if (mbclen == (size_t)-2)
8521 else if (mbclen > 1)
8529 /* XXX - what to do if mbrlen returns 0? (null wide character) */
8531 for (j = i; j < len; j++)
8532 shell_input_line_property[j] = 1;
8536 shell_input_line_property[i] = mbclen;
8539 #endif /* HANDLE_MULTIBYTE */