1 /* A Bison parser, made by GNU Bison 2.3. */
3 /* Skeleton implementation for Bison's Yacc-like parsers in C
5 Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006
6 Free Software Foundation, Inc.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 Boston, MA 02110-1301, USA. */
23 /* As a special exception, you may create a larger work that contains
24 part or all of the Bison parser skeleton and distribute that work
25 under terms of your choice, so long as that work isn't itself a
26 parser generator using the skeleton or a modified version thereof
27 as a parser skeleton. Alternatively, if you modify or redistribute
28 the parser skeleton itself, you may (at your option) remove this
29 special exception, which will cause the skeleton and the resulting
30 Bison output files to be licensed under the GNU General Public
31 License without this special exception.
33 This special exception was added by the Free Software Foundation in
34 version 2.2 of Bison. */
36 /* C LALR(1) parser skeleton written by Richard Stallman, by
37 simplifying the original so-called "semantic" parser. */
39 /* All symbols defined below should begin with yy or YY, to avoid
40 infringing on user name space. This should be done even for local
41 variables, as they might otherwise be expanded by user macros.
42 There are some unavoidable exceptions within include files to
43 define necessary library symbols; they are noted "INFRINGES ON
44 USER NAME SPACE" below. */
46 /* Identify Bison output. */
50 #define YYBISON_VERSION "2.3"
53 #define YYSKELETON_NAME "yacc.c"
58 /* Using locations. */
59 #define YYLSP_NEEDED 0
66 /* Put the tokens into the symbol table, so that GDB and other debuggers
92 ASSIGNMENT_WORD = 281,
95 ARITH_FOR_EXPRS = 284,
99 GREATER_GREATER = 288,
102 LESS_LESS_LESS = 291,
107 LESS_LESS_MINUS = 296,
109 AND_GREATER_GREATER = 298,
132 #define COND_START 273
134 #define COND_ERROR 275
140 #define ASSIGNMENT_WORD 281
142 #define ARITH_CMD 283
143 #define ARITH_FOR_EXPRS 284
147 #define GREATER_GREATER 288
148 #define LESS_LESS 289
150 #define LESS_LESS_LESS 291
151 #define GREATER_AND 292
152 #define SEMI_SEMI 293
154 #define SEMI_SEMI_AND 295
155 #define LESS_LESS_MINUS 296
156 #define AND_GREATER 297
157 #define AND_GREATER_GREATER 298
158 #define LESS_GREATER 299
159 #define GREATER_BAR 300
166 /* Copy the first part of user declarations. */
167 #line 21 "/Users/chet/src/bash/src/parse.y"
171 #include "bashtypes.h"
172 #include "bashansi.h"
174 #include "filecntl.h"
176 #if defined (HAVE_UNISTD_H)
180 #if defined (HAVE_LOCALE_H)
185 #include "chartypes.h"
188 #include "memalloc.h"
190 #include "bashintl.h"
192 #define NEED_STRFTIME_DECL /* used in externs.h */
198 #include "mailcheck.h"
200 #include "builtins.h"
201 #include "builtins/common.h"
202 #include "builtins/builtext.h"
204 #include "shmbutil.h"
206 #if defined (READLINE)
207 # include "bashline.h"
208 # include <readline/readline.h>
209 #endif /* READLINE */
211 #if defined (HISTORY)
212 # include "bashhist.h"
213 # include <readline/history.h>
216 #if defined (JOB_CONTROL)
218 #endif /* JOB_CONTROL */
223 typedef void *alias_t;
226 #if defined (PROMPT_STRING_DECODE)
228 # include <sys/param.h>
231 # if defined (TM_IN_SYS_TIME)
232 # include <sys/types.h>
233 # include <sys/time.h>
234 # endif /* TM_IN_SYS_TIME */
235 # include "maxpath.h"
236 #endif /* PROMPT_STRING_DECODE */
238 #define RE_READ_TOKEN -99
239 #define NO_EXPANSION -100
247 #if defined (HANDLE_MULTIBYTE)
248 # define last_shell_getc_is_singlebyte \
249 ((shell_input_line_index > 1) \
250 ? shell_input_line_property[shell_input_line_index - 1] \
252 # define MBTEST(x) ((x) && last_shell_getc_is_singlebyte)
254 # define last_shell_getc_is_singlebyte 1
255 # define MBTEST(x) ((x))
258 #if defined (EXTENDED_GLOB)
259 extern int extended_glob;
262 extern int eof_encountered;
263 extern int no_line_editing, running_under_emacs;
264 extern int current_command_number;
265 extern int sourcelevel, parse_and_execute_level;
266 extern int posixly_correct;
267 extern int last_command_exit_value;
268 extern char *shell_name, *current_host_name;
269 extern char *dist_version;
270 extern int patch_level;
271 extern int dump_translatable_strings, dump_po_strings;
272 extern sh_builtin_func_t *last_shell_builtin, *this_shell_builtin;
273 #if defined (BUFFERED_INPUT)
274 extern int bash_input_fd_changed;
278 /* **************************************************************** */
280 /* "Forward" declarations */
282 /* **************************************************************** */
285 static void debug_parser __P((int));
288 static int yy_getc __P((void));
289 static int yy_ungetc __P((int));
291 #if defined (READLINE)
292 static int yy_readline_get __P((void));
293 static int yy_readline_unget __P((int));
296 static int yy_string_get __P((void));
297 static int yy_string_unget __P((int));
298 static void rewind_input_string __P((void));
299 static int yy_stream_get __P((void));
300 static int yy_stream_unget __P((int));
302 static int shell_getc __P((int));
303 static void shell_ungetc __P((int));
304 static void discard_until __P((int));
306 #if defined (ALIAS) || defined (DPAREN_ARITHMETIC)
307 static void push_string __P((char *, int, alias_t *));
308 static void pop_string __P((void));
309 static void free_string_list __P((void));
312 static char *read_a_line __P((int));
314 static int reserved_word_acceptable __P((int));
315 static int yylex __P((void));
316 static int alias_expand_token __P((char *));
317 static int time_command_acceptable __P((void));
318 static int special_case_tokens __P((char *));
319 static int read_token __P((int));
320 static char *parse_matched_pair __P((int, int, int, int *, int));
321 static char *parse_comsub __P((int, int, int, int *, int));
322 #if defined (ARRAY_VARS)
323 static char *parse_compound_assignment __P((int *));
325 #if defined (DPAREN_ARITHMETIC) || defined (ARITH_FOR_COMMAND)
326 static int parse_dparen __P((int));
327 static int parse_arith_cmd __P((char **, int));
329 #if defined (COND_COMMAND)
330 static void cond_error __P((void));
331 static COND_COM *cond_expr __P((void));
332 static COND_COM *cond_or __P((void));
333 static COND_COM *cond_and __P((void));
334 static COND_COM *cond_term __P((void));
335 static int cond_skip_newlines __P((void));
336 static COMMAND *parse_cond_command __P((void));
338 #if defined (ARRAY_VARS)
339 static int token_is_assignment __P((char *, int));
340 static int token_is_ident __P((char *, int));
342 static int read_token_word __P((int));
343 static void discard_parser_constructs __P((int));
345 static char *error_token_from_token __P((int));
346 static char *error_token_from_text __P((void));
347 static void print_offending_line __P((void));
348 static void report_syntax_error __P((char *));
350 static void handle_eof_input_unit __P((void));
351 static void prompt_again __P((void));
353 static void reset_readline_prompt __P((void));
355 static void print_prompt __P((void));
357 #if defined (HANDLE_MULTIBYTE)
358 static void set_line_mbstate __P((void));
359 static char *shell_input_line_property = NULL;
361 # define set_line_mbstate()
364 extern int yyerror __P((const char *));
370 /* Default prompt strings */
371 char *primary_prompt = PPROMPT;
372 char *secondary_prompt = SPROMPT;
374 /* PROMPT_STRING_POINTER points to one of these, never to an actual string. */
375 char *ps1_prompt, *ps2_prompt;
377 /* Handle on the current prompt string. Indirectly points through
378 ps1_ or ps2_prompt. */
379 char **prompt_string_pointer = (char **)NULL;
380 char *current_prompt_string;
382 /* Non-zero means we expand aliases in commands. */
383 int expand_aliases = 0;
385 /* If non-zero, the decoded prompt string undergoes parameter and
386 variable substitution, command substitution, arithmetic substitution,
387 string expansion, process substitution, and quote removal in
388 decode_prompt_string. */
391 /* If non-zero, $'...' and $"..." are expanded when they appear within
392 a ${...} expansion, even when the expansion appears within double
394 int extended_quote = 1;
396 /* The decoded prompt string. Used if READLINE is not defined or if
397 editing is turned off. Analogous to current_readline_prompt. */
398 static char *current_decoded_prompt;
400 /* The number of lines read from input while creating the current command. */
401 int current_command_line_count;
403 /* The token that currently denotes the end of parse. */
406 /* The token currently being read. */
409 /* Variables to manage the task of reading here documents, because we need to
410 defer the reading until after a complete command has been collected. */
411 static REDIRECT *redir_stack[10];
414 /* Where shell input comes from. History expansion is performed on each
415 line when the shell is interactive. */
416 static char *shell_input_line = (char *)NULL;
417 static int shell_input_line_index;
418 static int shell_input_line_size; /* Amount allocated for shell_input_line. */
419 static int shell_input_line_len; /* strlen (shell_input_line) */
421 /* Either zero or EOF. */
422 static int shell_input_line_terminator;
424 /* The line number in a script on which a function definition starts. */
425 static int function_dstart;
427 /* The line number in a script on which a function body starts. */
428 static int function_bstart;
430 /* The line number in a script at which an arithmetic for command starts. */
431 static int arith_for_lineno;
433 /* The current parser state. */
434 static int parser_state;
436 /* The last read token, or NULL. read_token () uses this for context
438 static int last_read_token;
440 /* The token read prior to last_read_token. */
441 static int token_before_that;
443 /* The token read prior to token_before_that. */
444 static int two_tokens_ago;
446 /* The line number in a script where the word in a `case WORD', `select WORD'
447 or `for WORD' begins. This is a nested command maximum, since the array
448 index is decremented after a case, select, or for command is parsed. */
449 #define MAX_CASE_NEST 128
450 static int word_lineno[MAX_CASE_NEST];
451 static int word_top = -1;
453 /* If non-zero, it is the token that we want read_token to return
454 regardless of what text is (or isn't) present to be read. This
455 is reset by read_token. If token_to_read == WORD or
456 ASSIGNMENT_WORD, yylval.word should be set to word_desc_to_read. */
457 static int token_to_read;
458 static WORD_DESC *word_desc_to_read;
460 static REDIRECTEE redir;
463 /* Enabling traces. */
468 /* Enabling verbose error messages. */
469 #ifdef YYERROR_VERBOSE
470 # undef YYERROR_VERBOSE
471 # define YYERROR_VERBOSE 1
473 # define YYERROR_VERBOSE 0
476 /* Enabling the token table. */
477 #ifndef YYTOKEN_TABLE
478 # define YYTOKEN_TABLE 0
481 #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
482 typedef union YYSTYPE
483 #line 316 "/Users/chet/src/bash/src/parse.y"
485 WORD_DESC *word; /* the word that we read. */
486 int number; /* the number that we read. */
487 WORD_LIST *word_list;
491 PATTERN_LIST *pattern;
493 /* Line 187 of yacc.c. */
496 # define yystype YYSTYPE /* obsolescent; will be withdrawn */
497 # define YYSTYPE_IS_DECLARED 1
498 # define YYSTYPE_IS_TRIVIAL 1
503 /* Copy the second part of user declarations. */
506 /* Line 216 of yacc.c. */
514 typedef YYTYPE_UINT8 yytype_uint8;
516 typedef unsigned char yytype_uint8;
520 typedef YYTYPE_INT8 yytype_int8;
521 #elif (defined __STDC__ || defined __C99__FUNC__ \
522 || defined __cplusplus || defined _MSC_VER)
523 typedef signed char yytype_int8;
525 typedef short int yytype_int8;
529 typedef YYTYPE_UINT16 yytype_uint16;
531 typedef unsigned short int yytype_uint16;
535 typedef YYTYPE_INT16 yytype_int16;
537 typedef short int yytype_int16;
541 # ifdef __SIZE_TYPE__
542 # define YYSIZE_T __SIZE_TYPE__
543 # elif defined size_t
544 # define YYSIZE_T size_t
545 # elif ! defined YYSIZE_T && (defined __STDC__ || defined __C99__FUNC__ \
546 || defined __cplusplus || defined _MSC_VER)
547 # include <stddef.h> /* INFRINGES ON USER NAME SPACE */
548 # define YYSIZE_T size_t
550 # define YYSIZE_T unsigned int
554 #define YYSIZE_MAXIMUM ((YYSIZE_T) -1)
559 # include <libintl.h> /* INFRINGES ON USER NAME SPACE */
560 # define YY_(msgid) dgettext ("bison-runtime", msgid)
564 # define YY_(msgid) msgid
568 /* Suppress unused-variable warnings by "using" E. */
569 #if ! defined lint || defined __GNUC__
570 # define YYUSE(e) ((void) (e))
572 # define YYUSE(e) /* empty */
575 /* Identity function, used to suppress warnings about constant conditions. */
579 #if (defined __STDC__ || defined __C99__FUNC__ \
580 || defined __cplusplus || defined _MSC_VER)
593 #if ! defined yyoverflow || YYERROR_VERBOSE
595 /* The parser invokes alloca or malloc; define the necessary symbols. */
597 # ifdef YYSTACK_USE_ALLOCA
598 # if YYSTACK_USE_ALLOCA
600 # define YYSTACK_ALLOC __builtin_alloca
601 # elif defined __BUILTIN_VA_ARG_INCR
602 # include <alloca.h> /* INFRINGES ON USER NAME SPACE */
604 # define YYSTACK_ALLOC __alloca
605 # elif defined _MSC_VER
606 # include <malloc.h> /* INFRINGES ON USER NAME SPACE */
607 # define alloca _alloca
609 # define YYSTACK_ALLOC alloca
610 # if ! defined _ALLOCA_H && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
611 || defined __cplusplus || defined _MSC_VER)
612 # include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
621 # ifdef YYSTACK_ALLOC
622 /* Pacify GCC's `empty if-body' warning. */
623 # define YYSTACK_FREE(Ptr) do { /* empty */; } while (YYID (0))
624 # ifndef YYSTACK_ALLOC_MAXIMUM
625 /* The OS might guarantee only one guard page at the bottom of the stack,
626 and a page size can be as small as 4096 bytes. So we cannot safely
627 invoke alloca (N) if N exceeds 4096. Use a slightly smaller number
628 to allow for a few compiler-allocated temporary stack slots. */
629 # define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */
632 # define YYSTACK_ALLOC YYMALLOC
633 # define YYSTACK_FREE YYFREE
634 # ifndef YYSTACK_ALLOC_MAXIMUM
635 # define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM
637 # if (defined __cplusplus && ! defined _STDLIB_H \
638 && ! ((defined YYMALLOC || defined malloc) \
639 && (defined YYFREE || defined free)))
640 # include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
646 # define YYMALLOC malloc
647 # if ! defined malloc && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
648 || defined __cplusplus || defined _MSC_VER)
649 void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */
654 # if ! defined free && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
655 || defined __cplusplus || defined _MSC_VER)
656 void free (void *); /* INFRINGES ON USER NAME SPACE */
660 #endif /* ! defined yyoverflow || YYERROR_VERBOSE */
663 #if (! defined yyoverflow \
664 && (! defined __cplusplus \
665 || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
667 /* A type that is properly aligned for any stack member. */
674 /* The size of the maximum gap between one aligned stack and the next. */
675 # define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1)
677 /* The size of an array large to enough to hold all stacks, each with
679 # define YYSTACK_BYTES(N) \
680 ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE)) \
681 + YYSTACK_GAP_MAXIMUM)
683 /* Copy COUNT objects from FROM to TO. The source and destination do
686 # if defined __GNUC__ && 1 < __GNUC__
687 # define YYCOPY(To, From, Count) \
688 __builtin_memcpy (To, From, (Count) * sizeof (*(From)))
690 # define YYCOPY(To, From, Count) \
694 for (yyi = 0; yyi < (Count); yyi++) \
695 (To)[yyi] = (From)[yyi]; \
701 /* Relocate STACK from its old location to the new one. The
702 local variables YYSIZE and YYSTACKSIZE give the old and new number of
703 elements in the stack, and YYPTR gives the new location of the
704 stack. Advance YYPTR to a properly aligned location for the next
706 # define YYSTACK_RELOCATE(Stack) \
709 YYSIZE_T yynewbytes; \
710 YYCOPY (&yyptr->Stack, Stack, yysize); \
711 Stack = &yyptr->Stack; \
712 yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \
713 yyptr += yynewbytes / sizeof (*yyptr); \
719 /* YYFINAL -- State number of the termination state. */
721 /* YYLAST -- Last index in YYTABLE. */
724 /* YYNTOKENS -- Number of terminals. */
726 /* YYNNTS -- Number of nonterminals. */
728 /* YYNRULES -- Number of rules. */
730 /* YYNRULES -- Number of states. */
731 #define YYNSTATES 319
733 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
735 #define YYMAXUTOK 302
737 #define YYTRANSLATE(YYX) \
738 ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
740 /* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */
741 static const yytype_uint8 yytranslate[] =
743 0, 2, 2, 2, 2, 2, 2, 2, 2, 2,
744 49, 2, 2, 2, 2, 2, 2, 2, 2, 2,
745 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
746 2, 2, 2, 2, 2, 2, 2, 2, 47, 2,
747 57, 58, 2, 2, 2, 54, 2, 2, 2, 2,
748 2, 2, 2, 2, 2, 2, 2, 2, 2, 48,
749 53, 2, 52, 2, 2, 2, 2, 2, 2, 2,
750 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
751 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
752 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
753 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
754 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
755 2, 2, 2, 55, 51, 56, 2, 2, 2, 2,
756 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
757 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
758 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
759 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
760 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
761 2, 2, 2, 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, 2, 2, 2, 2, 2, 2, 2,
768 2, 2, 2, 2, 2, 2, 1, 2, 3, 4,
769 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
770 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
771 25, 26, 27, 28, 29, 30, 31, 32, 33, 34,
772 35, 36, 37, 38, 39, 40, 41, 42, 43, 44,
777 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
779 static const yytype_uint16 yyprhs[] =
781 0, 0, 3, 6, 8, 11, 13, 15, 18, 21,
782 24, 28, 32, 35, 39, 42, 46, 49, 53, 56,
783 60, 63, 67, 70, 74, 77, 81, 84, 88, 91,
784 95, 98, 102, 105, 108, 112, 115, 118, 122, 124,
785 126, 128, 130, 133, 135, 138, 140, 142, 145, 147,
786 149, 151, 153, 159, 165, 167, 169, 171, 173, 175,
787 177, 179, 186, 193, 201, 209, 220, 231, 241, 251,
788 259, 267, 273, 279, 286, 293, 301, 309, 320, 331,
789 338, 346, 353, 359, 366, 371, 373, 376, 380, 383,
790 387, 391, 396, 399, 405, 413, 420, 424, 426, 430,
791 435, 442, 448, 450, 453, 458, 463, 469, 475, 478,
792 482, 485, 489, 492, 496, 498, 502, 505, 507, 510,
793 514, 518, 522, 527, 532, 537, 542, 547, 549, 551,
794 553, 555, 557, 559, 560, 563, 565, 568, 571, 576,
795 581, 585, 589, 591, 593, 596, 599, 603, 607, 610,
799 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
800 static const yytype_int8 yyrhs[] =
802 60, 0, -1, 92, 89, -1, 49, -1, 1, 49,
803 -1, 50, -1, 25, -1, 61, 25, -1, 52, 25,
804 -1, 53, 25, -1, 27, 52, 25, -1, 27, 53,
805 25, -1, 33, 25, -1, 27, 33, 25, -1, 34,
806 25, -1, 27, 34, 25, -1, 36, 25, -1, 27,
807 36, 25, -1, 35, 27, -1, 27, 35, 27, -1,
808 37, 27, -1, 27, 37, 27, -1, 35, 25, -1,
809 27, 35, 25, -1, 37, 25, -1, 27, 37, 25,
810 -1, 41, 25, -1, 27, 41, 25, -1, 37, 54,
811 -1, 27, 37, 54, -1, 35, 54, -1, 27, 35,
812 54, -1, 42, 25, -1, 43, 25, -1, 27, 44,
813 25, -1, 44, 25, -1, 45, 25, -1, 27, 45,
814 25, -1, 25, -1, 26, -1, 62, -1, 62, -1,
815 64, 62, -1, 63, -1, 65, 63, -1, 65, -1,
816 67, -1, 67, 64, -1, 72, -1, 75, -1, 68,
817 -1, 71, -1, 12, 86, 14, 86, 15, -1, 13,
818 86, 14, 86, 15, -1, 70, -1, 76, -1, 74,
819 -1, 77, -1, 78, -1, 79, -1, 69, -1, 10,
820 25, 91, 14, 86, 15, -1, 10, 25, 91, 55,
821 86, 56, -1, 10, 25, 48, 91, 14, 86, 15,
822 -1, 10, 25, 48, 91, 55, 86, 56, -1, 10,
823 25, 91, 21, 61, 90, 91, 14, 86, 15, -1,
824 10, 25, 91, 21, 61, 90, 91, 55, 86, 56,
825 -1, 10, 25, 91, 21, 90, 91, 14, 86, 15,
826 -1, 10, 25, 91, 21, 90, 91, 55, 86, 56,
827 -1, 10, 29, 90, 91, 14, 86, 15, -1, 10,
828 29, 90, 91, 55, 86, 56, -1, 10, 29, 14,
829 86, 15, -1, 10, 29, 55, 86, 56, -1, 11,
830 25, 91, 14, 85, 15, -1, 11, 25, 91, 55,
831 85, 56, -1, 11, 25, 48, 91, 14, 85, 15,
832 -1, 11, 25, 48, 91, 55, 85, 56, -1, 11,
833 25, 91, 21, 61, 90, 91, 14, 85, 15, -1,
834 11, 25, 91, 21, 61, 90, 91, 55, 85, 56,
835 -1, 8, 25, 91, 21, 91, 9, -1, 8, 25,
836 91, 21, 83, 91, 9, -1, 8, 25, 91, 21,
837 81, 9, -1, 25, 57, 58, 91, 73, -1, 16,
838 25, 57, 58, 91, 73, -1, 16, 25, 91, 73,
839 -1, 67, -1, 67, 64, -1, 57, 86, 58, -1,
840 17, 67, -1, 17, 67, 64, -1, 17, 25, 67,
841 -1, 17, 25, 67, 64, -1, 17, 65, -1, 3,
842 86, 4, 86, 7, -1, 3, 86, 4, 86, 5,
843 86, 7, -1, 3, 86, 4, 86, 80, 7, -1,
844 55, 86, 56, -1, 28, -1, 18, 30, 19, -1,
845 6, 86, 4, 86, -1, 6, 86, 4, 86, 5,
846 86, -1, 6, 86, 4, 86, 80, -1, 82, -1,
847 83, 82, -1, 91, 84, 58, 86, -1, 91, 84,
848 58, 91, -1, 91, 57, 84, 58, 86, -1, 91,
849 57, 84, 58, 91, -1, 82, 38, -1, 83, 82,
850 38, -1, 82, 39, -1, 83, 82, 39, -1, 82,
851 40, -1, 83, 82, 40, -1, 25, -1, 84, 51,
852 25, -1, 91, 87, -1, 85, -1, 91, 88, -1,
853 88, 49, 91, -1, 88, 47, 91, -1, 88, 48,
854 91, -1, 88, 31, 91, 88, -1, 88, 32, 91,
855 88, -1, 88, 47, 91, 88, -1, 88, 48, 91,
856 88, -1, 88, 49, 91, 88, -1, 94, -1, 49,
857 -1, 50, -1, 49, -1, 48, -1, 50, -1, -1,
858 91, 49, -1, 93, -1, 93, 47, -1, 93, 48,
859 -1, 93, 31, 91, 93, -1, 93, 32, 91, 93,
860 -1, 93, 47, 93, -1, 93, 48, 93, -1, 94,
861 -1, 95, -1, 22, 95, -1, 96, 95, -1, 96,
862 22, 95, -1, 22, 96, 95, -1, 96, 90, -1,
863 95, 51, 91, 95, -1, 95, 46, 91, 95, -1,
864 66, -1, 23, -1, 23, 24, -1
867 /* YYRLINE[YYN] -- source line where rule number YYN was defined. */
868 static const yytype_uint16 yyrline[] =
870 0, 369, 369, 380, 389, 404, 414, 416, 420, 425,
871 430, 435, 440, 445, 450, 456, 462, 467, 472, 477,
872 482, 487, 492, 497, 502, 507, 512, 519, 526, 531,
873 536, 541, 546, 551, 556, 561, 566, 571, 578, 580,
874 582, 586, 590, 601, 603, 607, 609, 611, 627, 629,
875 633, 635, 637, 639, 641, 643, 645, 647, 649, 651,
876 653, 657, 662, 667, 672, 677, 682, 687, 692, 699,
877 704, 709, 714, 721, 726, 731, 736, 741, 746, 753,
878 758, 763, 770, 773, 776, 780, 782, 813, 820, 825,
879 842, 847, 864, 871, 873, 875, 880, 884, 888, 892,
880 894, 896, 900, 901, 905, 907, 909, 911, 915, 917,
881 919, 921, 923, 925, 929, 931, 940, 948, 949, 955,
882 956, 963, 967, 969, 971, 978, 980, 982, 986, 987,
883 990, 992, 994, 998, 999, 1008, 1021, 1037, 1052, 1054,
884 1056, 1063, 1066, 1070, 1072, 1078, 1084, 1090, 1096, 1116,
885 1118, 1140, 1144, 1146
889 #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
890 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
891 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
892 static const char *const yytname[] =
894 "$end", "error", "$undefined", "IF", "THEN", "ELSE", "ELIF", "FI",
895 "CASE", "ESAC", "FOR", "SELECT", "WHILE", "UNTIL", "DO", "DONE",
896 "FUNCTION", "COPROC", "COND_START", "COND_END", "COND_ERROR", "IN",
897 "BANG", "TIME", "TIMEOPT", "WORD", "ASSIGNMENT_WORD", "NUMBER",
898 "ARITH_CMD", "ARITH_FOR_EXPRS", "COND_CMD", "AND_AND", "OR_OR",
899 "GREATER_GREATER", "LESS_LESS", "LESS_AND", "LESS_LESS_LESS",
900 "GREATER_AND", "SEMI_SEMI", "SEMI_AND", "SEMI_SEMI_AND",
901 "LESS_LESS_MINUS", "AND_GREATER", "AND_GREATER_GREATER", "LESS_GREATER",
902 "GREATER_BAR", "BAR_AND", "'&'", "';'", "'\\n'", "yacc_EOF", "'|'",
903 "'>'", "'<'", "'-'", "'{'", "'}'", "'('", "')'", "$accept", "inputunit",
904 "word_list", "redirection", "simple_command_element", "redirection_list",
905 "simple_command", "command", "shell_command", "for_command",
906 "arith_for_command", "select_command", "case_command", "function_def",
907 "function_body", "subshell", "coproc", "if_command", "group_command",
908 "arith_command", "cond_command", "elif_clause", "case_clause",
909 "pattern_list", "case_clause_sequence", "pattern", "list",
910 "compound_list", "list0", "list1", "simple_list_terminator",
911 "list_terminator", "newline_list", "simple_list", "simple_list1",
912 "pipeline_command", "pipeline", "timespec", 0
917 /* YYTOKNUM[YYLEX-NUM] -- Internal token number corresponding to
919 static const yytype_uint16 yytoknum[] =
921 0, 256, 257, 258, 259, 260, 261, 262, 263, 264,
922 265, 266, 267, 268, 269, 270, 271, 272, 273, 274,
923 275, 276, 277, 278, 279, 280, 281, 282, 283, 284,
924 285, 286, 287, 288, 289, 290, 291, 292, 293, 294,
925 295, 296, 297, 298, 299, 300, 301, 38, 59, 10,
926 302, 124, 62, 60, 45, 123, 125, 40, 41
930 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
931 static const yytype_uint8 yyr1[] =
933 0, 59, 60, 60, 60, 60, 61, 61, 62, 62,
934 62, 62, 62, 62, 62, 62, 62, 62, 62, 62,
935 62, 62, 62, 62, 62, 62, 62, 62, 62, 62,
936 62, 62, 62, 62, 62, 62, 62, 62, 63, 63,
937 63, 64, 64, 65, 65, 66, 66, 66, 66, 66,
938 67, 67, 67, 67, 67, 67, 67, 67, 67, 67,
939 67, 68, 68, 68, 68, 68, 68, 68, 68, 69,
940 69, 69, 69, 70, 70, 70, 70, 70, 70, 71,
941 71, 71, 72, 72, 72, 73, 73, 74, 75, 75,
942 75, 75, 75, 76, 76, 76, 77, 78, 79, 80,
943 80, 80, 81, 81, 82, 82, 82, 82, 83, 83,
944 83, 83, 83, 83, 84, 84, 85, 86, 86, 87,
945 87, 87, 88, 88, 88, 88, 88, 88, 89, 89,
946 90, 90, 90, 91, 91, 92, 92, 92, 93, 93,
947 93, 93, 93, 94, 94, 94, 94, 94, 94, 95,
951 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
952 static const yytype_uint8 yyr2[] =
954 0, 2, 2, 1, 2, 1, 1, 2, 2, 2,
955 3, 3, 2, 3, 2, 3, 2, 3, 2, 3,
956 2, 3, 2, 3, 2, 3, 2, 3, 2, 3,
957 2, 3, 2, 2, 3, 2, 2, 3, 1, 1,
958 1, 1, 2, 1, 2, 1, 1, 2, 1, 1,
959 1, 1, 5, 5, 1, 1, 1, 1, 1, 1,
960 1, 6, 6, 7, 7, 10, 10, 9, 9, 7,
961 7, 5, 5, 6, 6, 7, 7, 10, 10, 6,
962 7, 6, 5, 6, 4, 1, 2, 3, 2, 3,
963 3, 4, 2, 5, 7, 6, 3, 1, 3, 4,
964 6, 5, 1, 2, 4, 4, 5, 5, 2, 3,
965 2, 3, 2, 3, 1, 3, 2, 1, 2, 3,
966 3, 3, 4, 4, 4, 4, 4, 1, 1, 1,
967 1, 1, 1, 0, 2, 1, 2, 2, 4, 4,
968 3, 3, 1, 1, 2, 2, 3, 3, 2, 4,
972 /* YYDEFACT[STATE-NAME] -- Default rule to reduce with in state
973 STATE-NUM when YYTABLE doesn't specify something else to do. Zero
974 means the default is an error. */
975 static const yytype_uint8 yydefact[] =
977 0, 0, 133, 0, 0, 0, 133, 133, 0, 0,
978 0, 0, 152, 38, 39, 0, 97, 0, 0, 0,
979 0, 0, 0, 0, 0, 0, 0, 3, 5, 0,
980 0, 133, 133, 0, 40, 43, 45, 151, 46, 50,
981 60, 54, 51, 48, 56, 49, 55, 57, 58, 59,
982 0, 135, 142, 143, 0, 4, 117, 0, 0, 133,
983 133, 0, 133, 0, 0, 133, 38, 92, 88, 0,
984 144, 0, 153, 0, 0, 0, 0, 0, 0, 0,
985 0, 0, 0, 0, 12, 14, 22, 18, 30, 16,
986 24, 20, 28, 26, 32, 33, 35, 36, 8, 9,
987 0, 0, 1, 38, 44, 41, 47, 128, 129, 2,
988 133, 133, 136, 137, 133, 133, 0, 131, 130, 132,
989 148, 145, 133, 134, 116, 118, 127, 0, 133, 0,
990 133, 133, 133, 133, 0, 133, 133, 0, 0, 90,
991 89, 98, 147, 133, 13, 15, 23, 19, 31, 17,
992 25, 21, 29, 27, 34, 37, 10, 11, 96, 87,
993 42, 0, 0, 140, 141, 0, 0, 146, 0, 133,
994 133, 133, 133, 133, 133, 0, 133, 0, 133, 0,
995 0, 0, 0, 133, 0, 133, 0, 0, 133, 85,
996 84, 91, 0, 138, 139, 0, 0, 150, 149, 133,
997 133, 93, 0, 0, 0, 120, 121, 119, 0, 102,
998 133, 0, 133, 133, 0, 6, 0, 133, 0, 71,
999 72, 133, 133, 133, 133, 0, 0, 0, 0, 52,
1000 53, 0, 86, 82, 0, 0, 95, 122, 123, 124,
1001 125, 126, 81, 108, 110, 112, 103, 0, 79, 114,
1002 0, 0, 0, 0, 61, 7, 133, 0, 62, 0,
1003 0, 0, 0, 73, 0, 133, 74, 83, 94, 133,
1004 133, 133, 133, 109, 111, 113, 80, 0, 0, 133,
1005 63, 64, 0, 133, 133, 69, 70, 75, 76, 0,
1006 99, 0, 0, 0, 133, 115, 104, 105, 133, 133,
1007 0, 0, 133, 133, 133, 101, 106, 107, 0, 0,
1008 67, 68, 0, 0, 100, 65, 66, 77, 78
1011 /* YYDEFGOTO[NTERM-NUM]. */
1012 static const yytype_int16 yydefgoto[] =
1014 -1, 33, 216, 34, 35, 106, 36, 37, 38, 39,
1015 40, 41, 42, 43, 190, 44, 45, 46, 47, 48,
1016 49, 202, 208, 209, 210, 251, 56, 57, 124, 125,
1017 109, 120, 58, 50, 163, 126, 53, 54
1020 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
1022 #define YYPACT_NINF -188
1023 static const yytype_int16 yypact[] =
1025 293, -26, -188, 7, 41, 43, -188, -188, 46, 629,
1026 -17, 485, 11, 23, -188, 675, -188, 65, 68, 96,
1027 77, 119, 92, 124, 127, 140, 143, -188, -188, 149,
1028 154, -188, -188, 98, -188, -188, 662, -188, 208, -188,
1029 -188, -188, -188, -188, -188, -188, -188, -188, -188, -188,
1030 24, 12, -188, -36, 341, -188, -188, 177, 389, -188,
1031 142, 8, 147, 169, 185, 148, 200, 662, 208, 181,
1032 -36, 581, -188, 146, 184, 189, 130, 192, 135, 197,
1033 198, 202, 207, 209, -188, -188, -188, -188, -188, -188,
1034 -188, -188, -188, -188, -188, -188, -188, -188, -188, -188,
1035 180, 167, -188, -188, -188, -188, 208, -188, -188, -188,
1036 -188, -188, 437, 437, -188, -188, 581, -188, -188, -188,
1037 -188, -36, -188, -188, -188, 227, -188, -12, -188, 20,
1038 -188, -188, -188, -188, 122, -188, -188, 179, 37, 208,
1039 208, -188, -36, -188, -188, -188, -188, -188, -188, -188,
1040 -188, -188, -188, -188, -188, -188, -188, -188, -188, -188,
1041 -188, 389, 389, 53, 53, 533, 533, -36, 224, -188,
1042 -188, -188, -188, -188, -188, 40, -188, 171, -188, 233,
1043 190, 48, 73, -188, 247, -188, 239, 267, -188, 208,
1044 -188, 208, 37, -188, -188, 437, 437, -36, -36, -188,
1045 -188, -188, 276, 389, 389, 389, 389, 389, 275, 226,
1046 -188, 42, -188, -188, 270, -188, 231, -188, 230, -188,
1047 -188, -188, -188, -188, -188, 272, 389, 231, 234, -188,
1048 -188, 37, 208, -188, 282, 287, -188, -188, -188, 76,
1049 76, 76, -188, -188, -188, -188, 229, 63, -188, -188,
1050 274, -27, 280, 241, -188, -188, -188, 99, -188, 285,
1051 246, 292, 252, -188, 227, -188, -188, -188, -188, -188,
1052 -188, -188, -188, -188, -188, -188, -188, -22, 288, -188,
1053 -188, -188, 131, -188, -188, -188, -188, -188, -188, 133,
1054 129, 389, 389, 389, -188, -188, -188, 389, -188, -188,
1055 297, 258, -188, -188, -188, -188, -188, 389, 302, 266,
1056 -188, -188, 308, 268, -188, -188, -188, -188, -188
1059 /* YYPGOTO[NTERM-NUM]. */
1060 static const yytype_int16 yypgoto[] =
1062 -188, -188, 141, -30, -25, -62, 322, -188, -5, -188,
1063 -188, -188, -188, -188, -185, -188, -188, -188, -188, -188,
1064 -188, 49, -188, 123, -188, 82, -171, -6, -188, -187,
1065 -188, -58, -32, -188, 5, 2, 10, 329
1068 /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
1069 positive, shift that token. If negative, reduce the rule which
1070 number is the opposite. If zero, do what YYDEFACT says.
1071 If YYTABLE_NINF, syntax error. */
1072 #define YYTABLE_NINF -1
1073 static const yytype_uint16 yytable[] =
1075 63, 64, 52, 132, 68, 51, 140, 233, 105, 174,
1076 114, 104, 225, 69, 228, 115, 237, 238, 239, 240,
1077 241, 70, 130, 55, 278, 100, 101, 127, 129, 278,
1078 134, 279, 59, 138, 176, 72, 294, 123, 105, 264,
1079 2, 177, 104, 110, 111, 3, 267, 4, 5, 6,
1080 7, 248, 261, 262, 212, 10, 117, 118, 119, 112,
1081 113, 139, 221, 131, 121, 16, 60, 249, 62, 123,
1082 61, 65, 276, 107, 108, 178, 160, 191, 161, 162,
1083 73, 142, 165, 166, 110, 111, 123, 223, 249, 123,
1084 84, 123, 31, 85, 32, 213, 175, 123, 102, 250,
1085 181, 182, 89, 222, 239, 240, 241, 169, 170, 105,
1086 160, 192, 123, 283, 52, 52, 168, 93, 164, 217,
1087 250, 86, 123, 87, 179, 180, 167, 232, 224, 186,
1088 187, 312, 313, 189, 304, 200, 183, 203, 204, 205,
1089 206, 207, 211, 184, 90, 298, 91, 302, 123, 94,
1090 88, 226, 95, 226, 284, 146, 231, 147, 256, 105,
1091 150, 160, 151, 52, 52, 96, 193, 194, 97, 265,
1092 214, 123, 218, 92, 98, 197, 198, 185, 247, 99,
1093 123, 122, 123, 135, 148, 257, 299, 189, 303, 152,
1094 128, 226, 226, 234, 235, 133, 215, 52, 52, 136,
1095 141, 164, 160, 2, 143, 137, 252, 253, 3, 144,
1096 4, 5, 6, 7, 145, 259, 260, 149, 10, 117,
1097 118, 119, 153, 154, 282, 159, 189, 155, 16, 199,
1098 200, 201, 156, 289, 157, 15, 158, 188, 291, 292,
1099 293, 17, 18, 19, 20, 21, 220, 297, 219, 22,
1100 23, 24, 25, 26, 229, 31, 255, 32, 169, 170,
1101 29, 30, 307, 290, 243, 244, 245, 273, 274, 275,
1102 226, 226, 215, 296, 171, 172, 173, 300, 301, 117,
1103 118, 119, 230, 236, 242, 254, 258, 263, 306, 268,
1104 266, 269, 308, 309, 1, 280, 2, 281, 314, 249,
1105 285, 3, 286, 4, 5, 6, 7, 287, 288, 8,
1106 9, 10, 310, 295, 311, 11, 12, 315, 13, 14,
1107 15, 16, 316, 317, 318, 227, 17, 18, 19, 20,
1108 21, 67, 277, 246, 22, 23, 24, 25, 26, 305,
1109 71, 0, 27, 28, 2, 29, 30, 0, 31, 3,
1110 32, 4, 5, 6, 7, 0, 0, 8, 9, 10,
1111 0, 0, 0, 116, 0, 0, 13, 14, 15, 16,
1112 0, 0, 0, 0, 17, 18, 19, 20, 21, 0,
1113 0, 0, 22, 23, 24, 25, 26, 0, 0, 117,
1114 118, 119, 2, 29, 30, 0, 31, 3, 32, 4,
1115 5, 6, 7, 0, 0, 8, 9, 10, 0, 0,
1116 0, 11, 12, 0, 13, 14, 15, 16, 0, 0,
1117 0, 0, 17, 18, 19, 20, 21, 0, 0, 0,
1118 22, 23, 24, 25, 26, 0, 0, 0, 123, 0,
1119 2, 29, 30, 0, 31, 3, 32, 4, 5, 6,
1120 7, 0, 0, 8, 9, 10, 0, 0, 0, 11,
1121 12, 0, 13, 14, 15, 16, 0, 0, 0, 0,
1122 17, 18, 19, 20, 21, 0, 0, 0, 22, 23,
1123 24, 25, 26, 0, 0, 0, 0, 0, 2, 29,
1124 30, 0, 31, 3, 32, 4, 5, 6, 7, 0,
1125 0, 8, 9, 10, 0, 0, 0, 0, 12, 0,
1126 13, 14, 15, 16, 0, 0, 0, 0, 17, 18,
1127 19, 20, 21, 0, 0, 0, 22, 23, 24, 25,
1128 26, 0, 0, 0, 0, 0, 2, 29, 30, 0,
1129 31, 3, 32, 4, 5, 6, 7, 0, 0, 8,
1130 9, 10, 0, 0, 0, 0, 0, 0, 13, 14,
1131 15, 16, 0, 0, 0, 0, 17, 18, 19, 20,
1132 21, 0, 0, 0, 22, 23, 24, 25, 26, 0,
1133 0, 0, 123, 0, 2, 29, 30, 0, 31, 3,
1134 32, 4, 5, 6, 7, 0, 0, 8, 9, 10,
1135 0, 0, 0, 0, 0, 0, 13, 14, 15, 16,
1136 0, 0, 0, 0, 17, 18, 19, 20, 21, 0,
1137 0, 0, 22, 23, 24, 25, 26, 0, 0, 0,
1138 0, 0, 2, 29, 30, 0, 31, 3, 32, 4,
1139 5, 6, 7, 0, 0, 0, 0, 10, 0, 0,
1140 0, 0, 0, 0, 66, 14, 15, 16, 0, 0,
1141 0, 0, 17, 18, 19, 20, 21, 0, 0, 0,
1142 22, 23, 24, 25, 26, 0, 0, 0, 0, 0,
1143 0, 29, 30, 0, 31, 0, 32, 103, 14, 15,
1144 0, 0, 0, 0, 0, 17, 18, 19, 20, 21,
1145 0, 0, 0, 22, 23, 24, 25, 26, 74, 75,
1146 76, 77, 78, 0, 29, 30, 79, 0, 0, 80,
1147 81, 0, 0, 0, 0, 0, 0, 82, 83
1150 static const yytype_int16 yycheck[] =
1152 6, 7, 0, 61, 9, 0, 68, 192, 38, 21,
1153 46, 36, 183, 30, 185, 51, 203, 204, 205, 206,
1154 207, 11, 14, 49, 51, 31, 32, 59, 60, 51,
1155 62, 58, 25, 65, 14, 24, 58, 49, 68, 226,
1156 3, 21, 67, 31, 32, 8, 231, 10, 11, 12,
1157 13, 9, 223, 224, 14, 18, 48, 49, 50, 47,
1158 48, 66, 14, 55, 54, 28, 25, 25, 25, 49,
1159 29, 25, 9, 49, 50, 55, 106, 139, 110, 111,
1160 57, 71, 114, 115, 31, 32, 49, 14, 25, 49,
1161 25, 49, 55, 25, 57, 55, 128, 49, 0, 57,
1162 132, 133, 25, 55, 291, 292, 293, 31, 32, 139,
1163 140, 143, 49, 14, 112, 113, 122, 25, 113, 177,
1164 57, 25, 49, 27, 130, 131, 116, 189, 55, 135,
1165 136, 302, 303, 138, 5, 6, 14, 169, 170, 171,
1166 172, 173, 174, 21, 25, 14, 27, 14, 49, 25,
1167 54, 183, 25, 185, 55, 25, 188, 27, 216, 189,
1168 25, 191, 27, 161, 162, 25, 161, 162, 25, 227,
1169 176, 49, 178, 54, 25, 165, 166, 55, 210, 25,
1170 49, 4, 49, 14, 54, 217, 55, 192, 55, 54,
1171 48, 223, 224, 199, 200, 48, 25, 195, 196, 14,
1172 19, 196, 232, 3, 58, 57, 212, 213, 8, 25,
1173 10, 11, 12, 13, 25, 221, 222, 25, 18, 48,
1174 49, 50, 25, 25, 256, 58, 231, 25, 28, 5,
1175 6, 7, 25, 265, 25, 27, 56, 58, 270, 271,
1176 272, 33, 34, 35, 36, 37, 56, 279, 15, 41,
1177 42, 43, 44, 45, 15, 55, 25, 57, 31, 32,
1178 52, 53, 294, 269, 38, 39, 40, 38, 39, 40,
1179 302, 303, 25, 279, 47, 48, 49, 283, 284, 48,
1180 49, 50, 15, 7, 9, 15, 56, 15, 294, 7,
1181 56, 4, 298, 299, 1, 15, 3, 56, 304, 25,
1182 15, 8, 56, 10, 11, 12, 13, 15, 56, 16,
1183 17, 18, 15, 25, 56, 22, 23, 15, 25, 26,
1184 27, 28, 56, 15, 56, 184, 33, 34, 35, 36,
1185 37, 9, 250, 210, 41, 42, 43, 44, 45, 290,
1186 11, -1, 49, 50, 3, 52, 53, -1, 55, 8,
1187 57, 10, 11, 12, 13, -1, -1, 16, 17, 18,
1188 -1, -1, -1, 22, -1, -1, 25, 26, 27, 28,
1189 -1, -1, -1, -1, 33, 34, 35, 36, 37, -1,
1190 -1, -1, 41, 42, 43, 44, 45, -1, -1, 48,
1191 49, 50, 3, 52, 53, -1, 55, 8, 57, 10,
1192 11, 12, 13, -1, -1, 16, 17, 18, -1, -1,
1193 -1, 22, 23, -1, 25, 26, 27, 28, -1, -1,
1194 -1, -1, 33, 34, 35, 36, 37, -1, -1, -1,
1195 41, 42, 43, 44, 45, -1, -1, -1, 49, -1,
1196 3, 52, 53, -1, 55, 8, 57, 10, 11, 12,
1197 13, -1, -1, 16, 17, 18, -1, -1, -1, 22,
1198 23, -1, 25, 26, 27, 28, -1, -1, -1, -1,
1199 33, 34, 35, 36, 37, -1, -1, -1, 41, 42,
1200 43, 44, 45, -1, -1, -1, -1, -1, 3, 52,
1201 53, -1, 55, 8, 57, 10, 11, 12, 13, -1,
1202 -1, 16, 17, 18, -1, -1, -1, -1, 23, -1,
1203 25, 26, 27, 28, -1, -1, -1, -1, 33, 34,
1204 35, 36, 37, -1, -1, -1, 41, 42, 43, 44,
1205 45, -1, -1, -1, -1, -1, 3, 52, 53, -1,
1206 55, 8, 57, 10, 11, 12, 13, -1, -1, 16,
1207 17, 18, -1, -1, -1, -1, -1, -1, 25, 26,
1208 27, 28, -1, -1, -1, -1, 33, 34, 35, 36,
1209 37, -1, -1, -1, 41, 42, 43, 44, 45, -1,
1210 -1, -1, 49, -1, 3, 52, 53, -1, 55, 8,
1211 57, 10, 11, 12, 13, -1, -1, 16, 17, 18,
1212 -1, -1, -1, -1, -1, -1, 25, 26, 27, 28,
1213 -1, -1, -1, -1, 33, 34, 35, 36, 37, -1,
1214 -1, -1, 41, 42, 43, 44, 45, -1, -1, -1,
1215 -1, -1, 3, 52, 53, -1, 55, 8, 57, 10,
1216 11, 12, 13, -1, -1, -1, -1, 18, -1, -1,
1217 -1, -1, -1, -1, 25, 26, 27, 28, -1, -1,
1218 -1, -1, 33, 34, 35, 36, 37, -1, -1, -1,
1219 41, 42, 43, 44, 45, -1, -1, -1, -1, -1,
1220 -1, 52, 53, -1, 55, -1, 57, 25, 26, 27,
1221 -1, -1, -1, -1, -1, 33, 34, 35, 36, 37,
1222 -1, -1, -1, 41, 42, 43, 44, 45, 33, 34,
1223 35, 36, 37, -1, 52, 53, 41, -1, -1, 44,
1224 45, -1, -1, -1, -1, -1, -1, 52, 53
1227 /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
1228 symbol of state STATE-NUM. */
1229 static const yytype_uint8 yystos[] =
1231 0, 1, 3, 8, 10, 11, 12, 13, 16, 17,
1232 18, 22, 23, 25, 26, 27, 28, 33, 34, 35,
1233 36, 37, 41, 42, 43, 44, 45, 49, 50, 52,
1234 53, 55, 57, 60, 62, 63, 65, 66, 67, 68,
1235 69, 70, 71, 72, 74, 75, 76, 77, 78, 79,
1236 92, 93, 94, 95, 96, 49, 85, 86, 91, 25,
1237 25, 29, 25, 86, 86, 25, 25, 65, 67, 30,
1238 95, 96, 24, 57, 33, 34, 35, 36, 37, 41,
1239 44, 45, 52, 53, 25, 25, 25, 27, 54, 25,
1240 25, 27, 54, 25, 25, 25, 25, 25, 25, 25,
1241 86, 86, 0, 25, 63, 62, 64, 49, 50, 89,
1242 31, 32, 47, 48, 46, 51, 22, 48, 49, 50,
1243 90, 95, 4, 49, 87, 88, 94, 91, 48, 91,
1244 14, 55, 90, 48, 91, 14, 14, 57, 91, 67,
1245 64, 19, 95, 58, 25, 25, 25, 27, 54, 25,
1246 25, 27, 54, 25, 25, 25, 25, 25, 56, 58,
1247 62, 91, 91, 93, 93, 91, 91, 95, 86, 31,
1248 32, 47, 48, 49, 21, 91, 14, 21, 55, 86,
1249 86, 91, 91, 14, 21, 55, 86, 86, 58, 67,
1250 73, 64, 91, 93, 93, 47, 48, 95, 95, 5,
1251 6, 7, 80, 91, 91, 91, 91, 91, 81, 82,
1252 83, 91, 14, 55, 86, 25, 61, 90, 86, 15,
1253 56, 14, 55, 14, 55, 85, 91, 61, 85, 15,
1254 15, 91, 64, 73, 86, 86, 7, 88, 88, 88,
1255 88, 88, 9, 38, 39, 40, 82, 91, 9, 25,
1256 57, 84, 86, 86, 15, 25, 90, 91, 56, 86,
1257 86, 85, 85, 15, 88, 90, 56, 73, 7, 4,
1258 47, 48, 49, 38, 39, 40, 9, 84, 51, 58,
1259 15, 56, 91, 14, 55, 15, 56, 15, 56, 91,
1260 86, 91, 91, 91, 58, 25, 86, 91, 14, 55,
1261 86, 86, 14, 55, 5, 80, 86, 91, 86, 86,
1262 15, 56, 85, 85, 86, 15, 56, 15, 56
1265 #define yyerrok (yyerrstatus = 0)
1266 #define yyclearin (yychar = YYEMPTY)
1267 #define YYEMPTY (-2)
1270 #define YYACCEPT goto yyacceptlab
1271 #define YYABORT goto yyabortlab
1272 #define YYERROR goto yyerrorlab
1275 /* Like YYERROR except do call yyerror. This remains here temporarily
1276 to ease the transition to the new meaning of YYERROR, for GCC.
1277 Once GCC version 2 has supplanted version 1, this can go. */
1279 #define YYFAIL goto yyerrlab
1281 #define YYRECOVERING() (!!yyerrstatus)
1283 #define YYBACKUP(Token, Value) \
1285 if (yychar == YYEMPTY && yylen == 1) \
1289 yytoken = YYTRANSLATE (yychar); \
1295 yyerror (YY_("syntax error: cannot back up")); \
1302 #define YYERRCODE 256
1305 /* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
1306 If N is 0, then set CURRENT to the empty location which ends
1307 the previous symbol: RHS[0] (always defined). */
1309 #define YYRHSLOC(Rhs, K) ((Rhs)[K])
1310 #ifndef YYLLOC_DEFAULT
1311 # define YYLLOC_DEFAULT(Current, Rhs, N) \
1315 (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \
1316 (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \
1317 (Current).last_line = YYRHSLOC (Rhs, N).last_line; \
1318 (Current).last_column = YYRHSLOC (Rhs, N).last_column; \
1322 (Current).first_line = (Current).last_line = \
1323 YYRHSLOC (Rhs, 0).last_line; \
1324 (Current).first_column = (Current).last_column = \
1325 YYRHSLOC (Rhs, 0).last_column; \
1331 /* YY_LOCATION_PRINT -- Print the location on the stream.
1332 This macro was not mandated originally: define only if we know
1333 we won't break user code: when these are the locations we know. */
1335 #ifndef YY_LOCATION_PRINT
1336 # if YYLTYPE_IS_TRIVIAL
1337 # define YY_LOCATION_PRINT(File, Loc) \
1338 fprintf (File, "%d.%d-%d.%d", \
1339 (Loc).first_line, (Loc).first_column, \
1340 (Loc).last_line, (Loc).last_column)
1342 # define YY_LOCATION_PRINT(File, Loc) ((void) 0)
1347 /* YYLEX -- calling `yylex' with the right arguments. */
1350 # define YYLEX yylex (YYLEX_PARAM)
1352 # define YYLEX yylex ()
1355 /* Enable debugging if requested. */
1359 # include <stdio.h> /* INFRINGES ON USER NAME SPACE */
1360 # define YYFPRINTF fprintf
1363 # define YYDPRINTF(Args) \
1369 # define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
1373 YYFPRINTF (stderr, "%s ", Title); \
1374 yy_symbol_print (stderr, \
1376 YYFPRINTF (stderr, "\n"); \
1381 /*--------------------------------.
1382 | Print this symbol on YYOUTPUT. |
1383 `--------------------------------*/
1386 #if (defined __STDC__ || defined __C99__FUNC__ \
1387 || defined __cplusplus || defined _MSC_VER)
1389 yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep)
1392 yy_symbol_value_print (yyoutput, yytype, yyvaluep)
1395 YYSTYPE const * const yyvaluep;
1401 if (yytype < YYNTOKENS)
1402 YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep);
1414 /*--------------------------------.
1415 | Print this symbol on YYOUTPUT. |
1416 `--------------------------------*/
1418 #if (defined __STDC__ || defined __C99__FUNC__ \
1419 || defined __cplusplus || defined _MSC_VER)
1421 yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep)
1424 yy_symbol_print (yyoutput, yytype, yyvaluep)
1427 YYSTYPE const * const yyvaluep;
1430 if (yytype < YYNTOKENS)
1431 YYFPRINTF (yyoutput, "token %s (", yytname[yytype]);
1433 YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]);
1435 yy_symbol_value_print (yyoutput, yytype, yyvaluep);
1436 YYFPRINTF (yyoutput, ")");
1439 /*------------------------------------------------------------------.
1440 | yy_stack_print -- Print the state stack from its BOTTOM up to its |
1442 `------------------------------------------------------------------*/
1444 #if (defined __STDC__ || defined __C99__FUNC__ \
1445 || defined __cplusplus || defined _MSC_VER)
1447 yy_stack_print (yytype_int16 *bottom, yytype_int16 *top)
1450 yy_stack_print (bottom, top)
1451 yytype_int16 *bottom;
1455 YYFPRINTF (stderr, "Stack now");
1456 for (; bottom <= top; ++bottom)
1457 YYFPRINTF (stderr, " %d", *bottom);
1458 YYFPRINTF (stderr, "\n");
1461 # define YY_STACK_PRINT(Bottom, Top) \
1464 yy_stack_print ((Bottom), (Top)); \
1468 /*------------------------------------------------.
1469 | Report that the YYRULE is going to be reduced. |
1470 `------------------------------------------------*/
1472 #if (defined __STDC__ || defined __C99__FUNC__ \
1473 || defined __cplusplus || defined _MSC_VER)
1475 yy_reduce_print (YYSTYPE *yyvsp, int yyrule)
1478 yy_reduce_print (yyvsp, yyrule)
1483 int yynrhs = yyr2[yyrule];
1485 unsigned long int yylno = yyrline[yyrule];
1486 YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n",
1488 /* The symbols being reduced. */
1489 for (yyi = 0; yyi < yynrhs; yyi++)
1491 fprintf (stderr, " $%d = ", yyi + 1);
1492 yy_symbol_print (stderr, yyrhs[yyprhs[yyrule] + yyi],
1493 &(yyvsp[(yyi + 1) - (yynrhs)])
1495 fprintf (stderr, "\n");
1499 # define YY_REDUCE_PRINT(Rule) \
1502 yy_reduce_print (yyvsp, Rule); \
1505 /* Nonzero means print parse trace. It is left uninitialized so that
1506 multiple parsers can coexist. */
1508 #else /* !YYDEBUG */
1509 # define YYDPRINTF(Args)
1510 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
1511 # define YY_STACK_PRINT(Bottom, Top)
1512 # define YY_REDUCE_PRINT(Rule)
1513 #endif /* !YYDEBUG */
1516 /* YYINITDEPTH -- initial size of the parser's stacks. */
1518 # define YYINITDEPTH 200
1521 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
1522 if the built-in stack extension method is used).
1524 Do not make this value too large; the results are undefined if
1525 YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH)
1526 evaluated with infinite-precision integer arithmetic. */
1529 # define YYMAXDEPTH 10000
1537 # if defined __GLIBC__ && defined _STRING_H
1538 # define yystrlen strlen
1540 /* Return the length of YYSTR. */
1541 #if (defined __STDC__ || defined __C99__FUNC__ \
1542 || defined __cplusplus || defined _MSC_VER)
1544 yystrlen (const char *yystr)
1552 for (yylen = 0; yystr[yylen]; yylen++)
1560 # if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
1561 # define yystpcpy stpcpy
1563 /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
1565 #if (defined __STDC__ || defined __C99__FUNC__ \
1566 || defined __cplusplus || defined _MSC_VER)
1568 yystpcpy (char *yydest, const char *yysrc)
1571 yystpcpy (yydest, yysrc)
1577 const char *yys = yysrc;
1579 while ((*yyd++ = *yys++) != '\0')
1588 /* Copy to YYRES the contents of YYSTR after stripping away unnecessary
1589 quotes and backslashes, so that it's suitable for yyerror. The
1590 heuristic is that double-quoting is unnecessary unless the string
1591 contains an apostrophe, a comma, or backslash (other than
1592 backslash-backslash). YYSTR is taken from yytname. If YYRES is
1593 null, do not copy; instead, return the length of what the result
1596 yytnamerr (char *yyres, const char *yystr)
1601 char const *yyp = yystr;
1608 goto do_not_strip_quotes;
1612 goto do_not_strip_quotes;
1625 do_not_strip_quotes: ;
1629 return yystrlen (yystr);
1631 return yystpcpy (yyres, yystr) - yyres;
1635 /* Copy into YYRESULT an error message about the unexpected token
1636 YYCHAR while in state YYSTATE. Return the number of bytes copied,
1637 including the terminating null byte. If YYRESULT is null, do not
1638 copy anything; just return the number of bytes that would be
1639 copied. As a special case, return 0 if an ordinary "syntax error"
1640 message will do. Return YYSIZE_MAXIMUM if overflow occurs during
1641 size calculation. */
1643 yysyntax_error (char *yyresult, int yystate, int yychar)
1645 int yyn = yypact[yystate];
1647 if (! (YYPACT_NINF < yyn && yyn <= YYLAST))
1651 int yytype = YYTRANSLATE (yychar);
1652 YYSIZE_T yysize0 = yytnamerr (0, yytname[yytype]);
1653 YYSIZE_T yysize = yysize0;
1655 int yysize_overflow = 0;
1656 enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
1657 char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
1661 /* This is so xgettext sees the translatable formats that are
1662 constructed on the fly. */
1663 YY_("syntax error, unexpected %s");
1664 YY_("syntax error, unexpected %s, expecting %s");
1665 YY_("syntax error, unexpected %s, expecting %s or %s");
1666 YY_("syntax error, unexpected %s, expecting %s or %s or %s");
1667 YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s");
1671 static char const yyunexpected[] = "syntax error, unexpected %s";
1672 static char const yyexpecting[] = ", expecting %s";
1673 static char const yyor[] = " or %s";
1674 char yyformat[sizeof yyunexpected
1675 + sizeof yyexpecting - 1
1676 + ((YYERROR_VERBOSE_ARGS_MAXIMUM - 2)
1677 * (sizeof yyor - 1))];
1678 char const *yyprefix = yyexpecting;
1680 /* Start YYX at -YYN if negative to avoid negative indexes in
1682 int yyxbegin = yyn < 0 ? -yyn : 0;
1684 /* Stay within bounds of both yycheck and yytname. */
1685 int yychecklim = YYLAST - yyn + 1;
1686 int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
1689 yyarg[0] = yytname[yytype];
1690 yyfmt = yystpcpy (yyformat, yyunexpected);
1692 for (yyx = yyxbegin; yyx < yyxend; ++yyx)
1693 if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
1695 if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
1699 yyformat[sizeof yyunexpected - 1] = '\0';
1702 yyarg[yycount++] = yytname[yyx];
1703 yysize1 = yysize + yytnamerr (0, yytname[yyx]);
1704 yysize_overflow |= (yysize1 < yysize);
1706 yyfmt = yystpcpy (yyfmt, yyprefix);
1710 yyf = YY_(yyformat);
1711 yysize1 = yysize + yystrlen (yyf);
1712 yysize_overflow |= (yysize1 < yysize);
1715 if (yysize_overflow)
1716 return YYSIZE_MAXIMUM;
1720 /* Avoid sprintf, as that infringes on the user's name space.
1721 Don't have undefined behavior even if the translation
1722 produced a string with the wrong number of "%s"s. */
1723 char *yyp = yyresult;
1725 while ((*yyp = *yyf) != '\0')
1727 if (*yyp == '%' && yyf[1] == 's' && yyi < yycount)
1729 yyp += yytnamerr (yyp, yyarg[yyi++]);
1742 #endif /* YYERROR_VERBOSE */
1745 /*-----------------------------------------------.
1746 | Release the memory associated to this symbol. |
1747 `-----------------------------------------------*/
1750 #if (defined __STDC__ || defined __C99__FUNC__ \
1751 || defined __cplusplus || defined _MSC_VER)
1753 yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep)
1756 yydestruct (yymsg, yytype, yyvaluep)
1766 YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
1777 /* Prevent warnings from -Wmissing-prototypes. */
1779 #ifdef YYPARSE_PARAM
1780 #if defined __STDC__ || defined __cplusplus
1781 int yyparse (void *YYPARSE_PARAM);
1785 #else /* ! YYPARSE_PARAM */
1786 #if defined __STDC__ || defined __cplusplus
1791 #endif /* ! YYPARSE_PARAM */
1795 /* The look-ahead symbol. */
1798 /* The semantic value of the look-ahead symbol. */
1801 /* Number of syntax errors so far. */
1810 #ifdef YYPARSE_PARAM
1811 #if (defined __STDC__ || defined __C99__FUNC__ \
1812 || defined __cplusplus || defined _MSC_VER)
1814 yyparse (void *YYPARSE_PARAM)
1817 yyparse (YYPARSE_PARAM)
1818 void *YYPARSE_PARAM;
1820 #else /* ! YYPARSE_PARAM */
1821 #if (defined __STDC__ || defined __C99__FUNC__ \
1822 || defined __cplusplus || defined _MSC_VER)
1836 /* Number of tokens to shift before error messages enabled. */
1838 /* Look-ahead token as an internal (translated) token number. */
1841 /* Buffer for error messages, and its allocated size. */
1843 char *yymsg = yymsgbuf;
1844 YYSIZE_T yymsg_alloc = sizeof yymsgbuf;
1847 /* Three stacks and their tools:
1848 `yyss': related to states,
1849 `yyvs': related to semantic values,
1850 `yyls': related to locations.
1852 Refer to the stacks thru separate pointers, to allow yyoverflow
1853 to reallocate them elsewhere. */
1855 /* The state stack. */
1856 yytype_int16 yyssa[YYINITDEPTH];
1857 yytype_int16 *yyss = yyssa;
1858 yytype_int16 *yyssp;
1860 /* The semantic value stack. */
1861 YYSTYPE yyvsa[YYINITDEPTH];
1862 YYSTYPE *yyvs = yyvsa;
1867 #define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N))
1869 YYSIZE_T yystacksize = YYINITDEPTH;
1871 /* The variables used to return semantic value and location from the
1876 /* The number of symbols on the RHS of the reduced rule.
1877 Keep to zero when no symbol should be popped. */
1880 YYDPRINTF ((stderr, "Starting parse\n"));
1885 yychar = YYEMPTY; /* Cause a token to be read. */
1887 /* Initialize stack pointers.
1888 Waste one element of value and location stack
1889 so that they stay on the same level as the state stack.
1890 The wasted elements are never initialized. */
1897 /*------------------------------------------------------------.
1898 | yynewstate -- Push a new state, which is found in yystate. |
1899 `------------------------------------------------------------*/
1901 /* In all cases, when you get here, the value and location stacks
1902 have just been pushed. So pushing a state here evens the stacks. */
1908 if (yyss + yystacksize - 1 <= yyssp)
1910 /* Get the current used size of the three stacks, in elements. */
1911 YYSIZE_T yysize = yyssp - yyss + 1;
1915 /* Give user a chance to reallocate the stack. Use copies of
1916 these so that the &'s don't force the real ones into
1918 YYSTYPE *yyvs1 = yyvs;
1919 yytype_int16 *yyss1 = yyss;
1922 /* Each stack pointer address is followed by the size of the
1923 data in use in that stack, in bytes. This used to be a
1924 conditional around just the two extra args, but that might
1925 be undefined if yyoverflow is a macro. */
1926 yyoverflow (YY_("memory exhausted"),
1927 &yyss1, yysize * sizeof (*yyssp),
1928 &yyvs1, yysize * sizeof (*yyvsp),
1935 #else /* no yyoverflow */
1936 # ifndef YYSTACK_RELOCATE
1937 goto yyexhaustedlab;
1939 /* Extend the stack our own way. */
1940 if (YYMAXDEPTH <= yystacksize)
1941 goto yyexhaustedlab;
1943 if (YYMAXDEPTH < yystacksize)
1944 yystacksize = YYMAXDEPTH;
1947 yytype_int16 *yyss1 = yyss;
1948 union yyalloc *yyptr =
1949 (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
1951 goto yyexhaustedlab;
1952 YYSTACK_RELOCATE (yyss);
1953 YYSTACK_RELOCATE (yyvs);
1955 # undef YYSTACK_RELOCATE
1957 YYSTACK_FREE (yyss1);
1960 #endif /* no yyoverflow */
1962 yyssp = yyss + yysize - 1;
1963 yyvsp = yyvs + yysize - 1;
1966 YYDPRINTF ((stderr, "Stack size increased to %lu\n",
1967 (unsigned long int) yystacksize));
1969 if (yyss + yystacksize - 1 <= yyssp)
1973 YYDPRINTF ((stderr, "Entering state %d\n", yystate));
1982 /* Do appropriate processing given the current state. Read a
1983 look-ahead token if we need one and don't already have one. */
1985 /* First try to decide what to do without reference to look-ahead token. */
1986 yyn = yypact[yystate];
1987 if (yyn == YYPACT_NINF)
1990 /* Not known => get a look-ahead token if don't already have one. */
1992 /* YYCHAR is either YYEMPTY or YYEOF or a valid look-ahead symbol. */
1993 if (yychar == YYEMPTY)
1995 YYDPRINTF ((stderr, "Reading a token: "));
1999 if (yychar <= YYEOF)
2001 yychar = yytoken = YYEOF;
2002 YYDPRINTF ((stderr, "Now at end of input.\n"));
2006 yytoken = YYTRANSLATE (yychar);
2007 YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
2010 /* If the proper action on seeing token YYTOKEN is to reduce or to
2011 detect an error, take that action. */
2013 if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
2018 if (yyn == 0 || yyn == YYTABLE_NINF)
2027 /* Count tokens shifted since error; after three, turn off error
2032 /* Shift the look-ahead token. */
2033 YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
2035 /* Discard the shifted token unless it is eof. */
2036 if (yychar != YYEOF)
2045 /*-----------------------------------------------------------.
2046 | yydefault -- do the default action for the current state. |
2047 `-----------------------------------------------------------*/
2049 yyn = yydefact[yystate];
2055 /*-----------------------------.
2056 | yyreduce -- Do a reduction. |
2057 `-----------------------------*/
2059 /* yyn is the number of a rule to reduce with. */
2062 /* If YYLEN is nonzero, implement the default value of the action:
2065 Otherwise, the following line sets YYVAL to garbage.
2066 This behavior is undocumented and Bison
2067 users should not rely upon it. Assigning to YYVAL
2068 unconditionally makes the parser a bit smaller, and it avoids a
2069 GCC warning that YYVAL may be used uninitialized. */
2070 yyval = yyvsp[1-yylen];
2073 YY_REDUCE_PRINT (yyn);
2077 #line 370 "/Users/chet/src/bash/src/parse.y"
2079 /* Case of regular command. Discard the error
2080 safety net,and return the command just parsed. */
2081 global_command = (yyvsp[(1) - (2)].command);
2082 eof_encountered = 0;
2083 /* discard_parser_constructs (0); */
2084 if (parser_state & PST_CMDSUBST)
2085 parser_state |= PST_EOFTOKEN;
2091 #line 381 "/Users/chet/src/bash/src/parse.y"
2093 /* Case of regular command, but not a very
2094 interesting one. Return a NULL command. */
2095 global_command = (COMMAND *)NULL;
2096 if (parser_state & PST_CMDSUBST)
2097 parser_state |= PST_EOFTOKEN;
2103 #line 390 "/Users/chet/src/bash/src/parse.y"
2105 /* Error during parsing. Return NULL command. */
2106 global_command = (COMMAND *)NULL;
2107 eof_encountered = 0;
2108 /* discard_parser_constructs (1); */
2109 if (interactive && parse_and_execute_level == 0)
2121 #line 405 "/Users/chet/src/bash/src/parse.y"
2123 /* Case of EOF seen by itself. Do ignoreeof or
2125 global_command = (COMMAND *)NULL;
2126 handle_eof_input_unit ();
2132 #line 415 "/Users/chet/src/bash/src/parse.y"
2133 { (yyval.word_list) = make_word_list ((yyvsp[(1) - (1)].word), (WORD_LIST *)NULL); }
2137 #line 417 "/Users/chet/src/bash/src/parse.y"
2138 { (yyval.word_list) = make_word_list ((yyvsp[(2) - (2)].word), (yyvsp[(1) - (2)].word_list)); }
2142 #line 421 "/Users/chet/src/bash/src/parse.y"
2144 redir.filename = (yyvsp[(2) - (2)].word);
2145 (yyval.redirect) = make_redirection (1, r_output_direction, redir);
2150 #line 426 "/Users/chet/src/bash/src/parse.y"
2152 redir.filename = (yyvsp[(2) - (2)].word);
2153 (yyval.redirect) = make_redirection (0, r_input_direction, redir);
2158 #line 431 "/Users/chet/src/bash/src/parse.y"
2160 redir.filename = (yyvsp[(3) - (3)].word);
2161 (yyval.redirect) = make_redirection ((yyvsp[(1) - (3)].number), r_output_direction, redir);
2166 #line 436 "/Users/chet/src/bash/src/parse.y"
2168 redir.filename = (yyvsp[(3) - (3)].word);
2169 (yyval.redirect) = make_redirection ((yyvsp[(1) - (3)].number), r_input_direction, redir);
2174 #line 441 "/Users/chet/src/bash/src/parse.y"
2176 redir.filename = (yyvsp[(2) - (2)].word);
2177 (yyval.redirect) = make_redirection (1, r_appending_to, redir);
2182 #line 446 "/Users/chet/src/bash/src/parse.y"
2184 redir.filename = (yyvsp[(3) - (3)].word);
2185 (yyval.redirect) = make_redirection ((yyvsp[(1) - (3)].number), r_appending_to, redir);
2190 #line 451 "/Users/chet/src/bash/src/parse.y"
2192 redir.filename = (yyvsp[(2) - (2)].word);
2193 (yyval.redirect) = make_redirection (0, r_reading_until, redir);
2194 redir_stack[need_here_doc++] = (yyval.redirect);
2199 #line 457 "/Users/chet/src/bash/src/parse.y"
2201 redir.filename = (yyvsp[(3) - (3)].word);
2202 (yyval.redirect) = make_redirection ((yyvsp[(1) - (3)].number), r_reading_until, redir);
2203 redir_stack[need_here_doc++] = (yyval.redirect);
2208 #line 463 "/Users/chet/src/bash/src/parse.y"
2210 redir.filename = (yyvsp[(2) - (2)].word);
2211 (yyval.redirect) = make_redirection (0, r_reading_string, redir);
2216 #line 468 "/Users/chet/src/bash/src/parse.y"
2218 redir.filename = (yyvsp[(3) - (3)].word);
2219 (yyval.redirect) = make_redirection ((yyvsp[(1) - (3)].number), r_reading_string, redir);
2224 #line 473 "/Users/chet/src/bash/src/parse.y"
2226 redir.dest = (yyvsp[(2) - (2)].number);
2227 (yyval.redirect) = make_redirection (0, r_duplicating_input, redir);
2232 #line 478 "/Users/chet/src/bash/src/parse.y"
2234 redir.dest = (yyvsp[(3) - (3)].number);
2235 (yyval.redirect) = make_redirection ((yyvsp[(1) - (3)].number), r_duplicating_input, redir);
2240 #line 483 "/Users/chet/src/bash/src/parse.y"
2242 redir.dest = (yyvsp[(2) - (2)].number);
2243 (yyval.redirect) = make_redirection (1, r_duplicating_output, redir);
2248 #line 488 "/Users/chet/src/bash/src/parse.y"
2250 redir.dest = (yyvsp[(3) - (3)].number);
2251 (yyval.redirect) = make_redirection ((yyvsp[(1) - (3)].number), r_duplicating_output, redir);
2256 #line 493 "/Users/chet/src/bash/src/parse.y"
2258 redir.filename = (yyvsp[(2) - (2)].word);
2259 (yyval.redirect) = make_redirection (0, r_duplicating_input_word, redir);
2264 #line 498 "/Users/chet/src/bash/src/parse.y"
2266 redir.filename = (yyvsp[(3) - (3)].word);
2267 (yyval.redirect) = make_redirection ((yyvsp[(1) - (3)].number), r_duplicating_input_word, redir);
2272 #line 503 "/Users/chet/src/bash/src/parse.y"
2274 redir.filename = (yyvsp[(2) - (2)].word);
2275 (yyval.redirect) = make_redirection (1, r_duplicating_output_word, redir);
2280 #line 508 "/Users/chet/src/bash/src/parse.y"
2282 redir.filename = (yyvsp[(3) - (3)].word);
2283 (yyval.redirect) = make_redirection ((yyvsp[(1) - (3)].number), r_duplicating_output_word, redir);
2288 #line 513 "/Users/chet/src/bash/src/parse.y"
2290 redir.filename = (yyvsp[(2) - (2)].word);
2291 (yyval.redirect) = make_redirection
2292 (0, r_deblank_reading_until, redir);
2293 redir_stack[need_here_doc++] = (yyval.redirect);
2298 #line 520 "/Users/chet/src/bash/src/parse.y"
2300 redir.filename = (yyvsp[(3) - (3)].word);
2301 (yyval.redirect) = make_redirection
2302 ((yyvsp[(1) - (3)].number), r_deblank_reading_until, redir);
2303 redir_stack[need_here_doc++] = (yyval.redirect);
2308 #line 527 "/Users/chet/src/bash/src/parse.y"
2311 (yyval.redirect) = make_redirection (1, r_close_this, redir);
2316 #line 532 "/Users/chet/src/bash/src/parse.y"
2319 (yyval.redirect) = make_redirection ((yyvsp[(1) - (3)].number), r_close_this, redir);
2324 #line 537 "/Users/chet/src/bash/src/parse.y"
2327 (yyval.redirect) = make_redirection (0, r_close_this, redir);
2332 #line 542 "/Users/chet/src/bash/src/parse.y"
2335 (yyval.redirect) = make_redirection ((yyvsp[(1) - (3)].number), r_close_this, redir);
2340 #line 547 "/Users/chet/src/bash/src/parse.y"
2342 redir.filename = (yyvsp[(2) - (2)].word);
2343 (yyval.redirect) = make_redirection (1, r_err_and_out, redir);
2348 #line 552 "/Users/chet/src/bash/src/parse.y"
2350 redir.filename = (yyvsp[(2) - (2)].word);
2351 (yyval.redirect) = make_redirection (1, r_append_err_and_out, redir);
2356 #line 557 "/Users/chet/src/bash/src/parse.y"
2358 redir.filename = (yyvsp[(3) - (3)].word);
2359 (yyval.redirect) = make_redirection ((yyvsp[(1) - (3)].number), r_input_output, redir);
2364 #line 562 "/Users/chet/src/bash/src/parse.y"
2366 redir.filename = (yyvsp[(2) - (2)].word);
2367 (yyval.redirect) = make_redirection (0, r_input_output, redir);
2372 #line 567 "/Users/chet/src/bash/src/parse.y"
2374 redir.filename = (yyvsp[(2) - (2)].word);
2375 (yyval.redirect) = make_redirection (1, r_output_force, redir);
2380 #line 572 "/Users/chet/src/bash/src/parse.y"
2382 redir.filename = (yyvsp[(3) - (3)].word);
2383 (yyval.redirect) = make_redirection ((yyvsp[(1) - (3)].number), r_output_force, redir);
2388 #line 579 "/Users/chet/src/bash/src/parse.y"
2389 { (yyval.element).word = (yyvsp[(1) - (1)].word); (yyval.element).redirect = 0; }
2393 #line 581 "/Users/chet/src/bash/src/parse.y"
2394 { (yyval.element).word = (yyvsp[(1) - (1)].word); (yyval.element).redirect = 0; }
2398 #line 583 "/Users/chet/src/bash/src/parse.y"
2399 { (yyval.element).redirect = (yyvsp[(1) - (1)].redirect); (yyval.element).word = 0; }
2403 #line 587 "/Users/chet/src/bash/src/parse.y"
2405 (yyval.redirect) = (yyvsp[(1) - (1)].redirect);
2410 #line 591 "/Users/chet/src/bash/src/parse.y"
2412 register REDIRECT *t;
2414 for (t = (yyvsp[(1) - (2)].redirect); t->next; t = t->next)
2416 t->next = (yyvsp[(2) - (2)].redirect);
2417 (yyval.redirect) = (yyvsp[(1) - (2)].redirect);
2422 #line 602 "/Users/chet/src/bash/src/parse.y"
2423 { (yyval.command) = make_simple_command ((yyvsp[(1) - (1)].element), (COMMAND *)NULL); }
2427 #line 604 "/Users/chet/src/bash/src/parse.y"
2428 { (yyval.command) = make_simple_command ((yyvsp[(2) - (2)].element), (yyvsp[(1) - (2)].command)); }
2432 #line 608 "/Users/chet/src/bash/src/parse.y"
2433 { (yyval.command) = clean_simple_command ((yyvsp[(1) - (1)].command)); }
2437 #line 610 "/Users/chet/src/bash/src/parse.y"
2438 { (yyval.command) = (yyvsp[(1) - (1)].command); }
2442 #line 612 "/Users/chet/src/bash/src/parse.y"
2446 tc = (yyvsp[(1) - (2)].command);
2449 register REDIRECT *t;
2450 for (t = tc->redirects; t->next; t = t->next)
2452 t->next = (yyvsp[(2) - (2)].redirect);
2455 tc->redirects = (yyvsp[(2) - (2)].redirect);
2456 (yyval.command) = (yyvsp[(1) - (2)].command);
2461 #line 628 "/Users/chet/src/bash/src/parse.y"
2462 { (yyval.command) = (yyvsp[(1) - (1)].command); }
2466 #line 630 "/Users/chet/src/bash/src/parse.y"
2467 { (yyval.command) = (yyvsp[(1) - (1)].command); }
2471 #line 634 "/Users/chet/src/bash/src/parse.y"
2472 { (yyval.command) = (yyvsp[(1) - (1)].command); }
2476 #line 636 "/Users/chet/src/bash/src/parse.y"
2477 { (yyval.command) = (yyvsp[(1) - (1)].command); }
2481 #line 638 "/Users/chet/src/bash/src/parse.y"
2482 { (yyval.command) = make_while_command ((yyvsp[(2) - (5)].command), (yyvsp[(4) - (5)].command)); }
2486 #line 640 "/Users/chet/src/bash/src/parse.y"
2487 { (yyval.command) = make_until_command ((yyvsp[(2) - (5)].command), (yyvsp[(4) - (5)].command)); }
2491 #line 642 "/Users/chet/src/bash/src/parse.y"
2492 { (yyval.command) = (yyvsp[(1) - (1)].command); }
2496 #line 644 "/Users/chet/src/bash/src/parse.y"
2497 { (yyval.command) = (yyvsp[(1) - (1)].command); }
2501 #line 646 "/Users/chet/src/bash/src/parse.y"
2502 { (yyval.command) = (yyvsp[(1) - (1)].command); }
2506 #line 648 "/Users/chet/src/bash/src/parse.y"
2507 { (yyval.command) = (yyvsp[(1) - (1)].command); }
2511 #line 650 "/Users/chet/src/bash/src/parse.y"
2512 { (yyval.command) = (yyvsp[(1) - (1)].command); }
2516 #line 652 "/Users/chet/src/bash/src/parse.y"
2517 { (yyval.command) = (yyvsp[(1) - (1)].command); }
2521 #line 654 "/Users/chet/src/bash/src/parse.y"
2522 { (yyval.command) = (yyvsp[(1) - (1)].command); }
2526 #line 658 "/Users/chet/src/bash/src/parse.y"
2528 (yyval.command) = make_for_command ((yyvsp[(2) - (6)].word), add_string_to_list ("\"$@\"", (WORD_LIST *)NULL), (yyvsp[(5) - (6)].command), word_lineno[word_top]);
2529 if (word_top > 0) word_top--;
2534 #line 663 "/Users/chet/src/bash/src/parse.y"
2536 (yyval.command) = make_for_command ((yyvsp[(2) - (6)].word), add_string_to_list ("\"$@\"", (WORD_LIST *)NULL), (yyvsp[(5) - (6)].command), word_lineno[word_top]);
2537 if (word_top > 0) word_top--;
2542 #line 668 "/Users/chet/src/bash/src/parse.y"
2544 (yyval.command) = make_for_command ((yyvsp[(2) - (7)].word), add_string_to_list ("\"$@\"", (WORD_LIST *)NULL), (yyvsp[(6) - (7)].command), word_lineno[word_top]);
2545 if (word_top > 0) word_top--;
2550 #line 673 "/Users/chet/src/bash/src/parse.y"
2552 (yyval.command) = make_for_command ((yyvsp[(2) - (7)].word), add_string_to_list ("\"$@\"", (WORD_LIST *)NULL), (yyvsp[(6) - (7)].command), word_lineno[word_top]);
2553 if (word_top > 0) word_top--;
2558 #line 678 "/Users/chet/src/bash/src/parse.y"
2560 (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]);
2561 if (word_top > 0) word_top--;
2566 #line 683 "/Users/chet/src/bash/src/parse.y"
2568 (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]);
2569 if (word_top > 0) word_top--;
2574 #line 688 "/Users/chet/src/bash/src/parse.y"
2576 (yyval.command) = make_for_command ((yyvsp[(2) - (9)].word), (WORD_LIST *)NULL, (yyvsp[(8) - (9)].command), word_lineno[word_top]);
2577 if (word_top > 0) word_top--;
2582 #line 693 "/Users/chet/src/bash/src/parse.y"
2584 (yyval.command) = make_for_command ((yyvsp[(2) - (9)].word), (WORD_LIST *)NULL, (yyvsp[(8) - (9)].command), word_lineno[word_top]);
2585 if (word_top > 0) word_top--;
2590 #line 700 "/Users/chet/src/bash/src/parse.y"
2592 (yyval.command) = make_arith_for_command ((yyvsp[(2) - (7)].word_list), (yyvsp[(6) - (7)].command), arith_for_lineno);
2593 if (word_top > 0) word_top--;
2598 #line 705 "/Users/chet/src/bash/src/parse.y"
2600 (yyval.command) = make_arith_for_command ((yyvsp[(2) - (7)].word_list), (yyvsp[(6) - (7)].command), arith_for_lineno);
2601 if (word_top > 0) word_top--;
2606 #line 710 "/Users/chet/src/bash/src/parse.y"
2608 (yyval.command) = make_arith_for_command ((yyvsp[(2) - (5)].word_list), (yyvsp[(4) - (5)].command), arith_for_lineno);
2609 if (word_top > 0) word_top--;
2614 #line 715 "/Users/chet/src/bash/src/parse.y"
2616 (yyval.command) = make_arith_for_command ((yyvsp[(2) - (5)].word_list), (yyvsp[(4) - (5)].command), arith_for_lineno);
2617 if (word_top > 0) word_top--;
2622 #line 722 "/Users/chet/src/bash/src/parse.y"
2624 (yyval.command) = make_select_command ((yyvsp[(2) - (6)].word), add_string_to_list ("\"$@\"", (WORD_LIST *)NULL), (yyvsp[(5) - (6)].command), word_lineno[word_top]);
2625 if (word_top > 0) word_top--;
2630 #line 727 "/Users/chet/src/bash/src/parse.y"
2632 (yyval.command) = make_select_command ((yyvsp[(2) - (6)].word), add_string_to_list ("\"$@\"", (WORD_LIST *)NULL), (yyvsp[(5) - (6)].command), word_lineno[word_top]);
2633 if (word_top > 0) word_top--;
2638 #line 732 "/Users/chet/src/bash/src/parse.y"
2640 (yyval.command) = make_select_command ((yyvsp[(2) - (7)].word), add_string_to_list ("\"$@\"", (WORD_LIST *)NULL), (yyvsp[(6) - (7)].command), word_lineno[word_top]);
2641 if (word_top > 0) word_top--;
2646 #line 737 "/Users/chet/src/bash/src/parse.y"
2648 (yyval.command) = make_select_command ((yyvsp[(2) - (7)].word), add_string_to_list ("\"$@\"", (WORD_LIST *)NULL), (yyvsp[(6) - (7)].command), word_lineno[word_top]);
2649 if (word_top > 0) word_top--;
2654 #line 742 "/Users/chet/src/bash/src/parse.y"
2656 (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]);
2657 if (word_top > 0) word_top--;
2662 #line 747 "/Users/chet/src/bash/src/parse.y"
2664 (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]);
2665 if (word_top > 0) word_top--;
2670 #line 754 "/Users/chet/src/bash/src/parse.y"
2672 (yyval.command) = make_case_command ((yyvsp[(2) - (6)].word), (PATTERN_LIST *)NULL, word_lineno[word_top]);
2673 if (word_top > 0) word_top--;
2678 #line 759 "/Users/chet/src/bash/src/parse.y"
2680 (yyval.command) = make_case_command ((yyvsp[(2) - (7)].word), (yyvsp[(5) - (7)].pattern), word_lineno[word_top]);
2681 if (word_top > 0) word_top--;
2686 #line 764 "/Users/chet/src/bash/src/parse.y"
2688 (yyval.command) = make_case_command ((yyvsp[(2) - (6)].word), (yyvsp[(5) - (6)].pattern), word_lineno[word_top]);
2689 if (word_top > 0) word_top--;
2694 #line 771 "/Users/chet/src/bash/src/parse.y"
2695 { (yyval.command) = make_function_def ((yyvsp[(1) - (5)].word), (yyvsp[(5) - (5)].command), function_dstart, function_bstart); }
2699 #line 774 "/Users/chet/src/bash/src/parse.y"
2700 { (yyval.command) = make_function_def ((yyvsp[(2) - (6)].word), (yyvsp[(6) - (6)].command), function_dstart, function_bstart); }
2704 #line 777 "/Users/chet/src/bash/src/parse.y"
2705 { (yyval.command) = make_function_def ((yyvsp[(2) - (4)].word), (yyvsp[(4) - (4)].command), function_dstart, function_bstart); }
2709 #line 781 "/Users/chet/src/bash/src/parse.y"
2710 { (yyval.command) = (yyvsp[(1) - (1)].command); }
2714 #line 783 "/Users/chet/src/bash/src/parse.y"
2718 tc = (yyvsp[(1) - (2)].command);
2719 /* According to Posix.2 3.9.5, redirections
2720 specified after the body of a function should
2721 be attached to the function and performed when
2722 the function is executed, not as part of the
2723 function definition command. */
2724 /* XXX - I don't think it matters, but we might
2725 want to change this in the future to avoid
2726 problems differentiating between a function
2727 definition with a redirection and a function
2728 definition containing a single command with a
2729 redirection. The two are semantically equivalent,
2730 though -- the only difference is in how the
2731 command printing code displays the redirections. */
2734 register REDIRECT *t;
2735 for (t = tc->redirects; t->next; t = t->next)
2737 t->next = (yyvsp[(2) - (2)].redirect);
2740 tc->redirects = (yyvsp[(2) - (2)].redirect);
2741 (yyval.command) = (yyvsp[(1) - (2)].command);
2746 #line 814 "/Users/chet/src/bash/src/parse.y"
2748 (yyval.command) = make_subshell_command ((yyvsp[(2) - (3)].command));
2749 (yyval.command)->flags |= CMD_WANT_SUBSHELL;
2754 #line 821 "/Users/chet/src/bash/src/parse.y"
2756 (yyval.command) = make_coproc_command ("COPROC", (yyvsp[(2) - (2)].command));
2757 (yyval.command)->flags |= CMD_WANT_SUBSHELL|CMD_COPROC_SUBSHELL;
2762 #line 826 "/Users/chet/src/bash/src/parse.y"
2766 tc = (yyvsp[(2) - (3)].command);
2769 register REDIRECT *t;
2770 for (t = tc->redirects; t->next; t = t->next)
2772 t->next = (yyvsp[(3) - (3)].redirect);
2775 tc->redirects = (yyvsp[(3) - (3)].redirect);
2776 (yyval.command) = make_coproc_command ("COPROC", (yyvsp[(2) - (3)].command));
2777 (yyval.command)->flags |= CMD_WANT_SUBSHELL|CMD_COPROC_SUBSHELL;
2782 #line 843 "/Users/chet/src/bash/src/parse.y"
2784 (yyval.command) = make_coproc_command ((yyvsp[(2) - (3)].word)->word, (yyvsp[(3) - (3)].command));
2785 (yyval.command)->flags |= CMD_WANT_SUBSHELL|CMD_COPROC_SUBSHELL;
2790 #line 848 "/Users/chet/src/bash/src/parse.y"
2794 tc = (yyvsp[(3) - (4)].command);
2797 register REDIRECT *t;
2798 for (t = tc->redirects; t->next; t = t->next)
2800 t->next = (yyvsp[(4) - (4)].redirect);
2803 tc->redirects = (yyvsp[(4) - (4)].redirect);
2804 (yyval.command) = make_coproc_command ((yyvsp[(2) - (4)].word)->word, (yyvsp[(3) - (4)].command));
2805 (yyval.command)->flags |= CMD_WANT_SUBSHELL|CMD_COPROC_SUBSHELL;
2810 #line 865 "/Users/chet/src/bash/src/parse.y"
2812 (yyval.command) = make_coproc_command ("COPROC", clean_simple_command ((yyvsp[(2) - (2)].command)));
2813 (yyval.command)->flags |= CMD_WANT_SUBSHELL|CMD_COPROC_SUBSHELL;
2818 #line 872 "/Users/chet/src/bash/src/parse.y"
2819 { (yyval.command) = make_if_command ((yyvsp[(2) - (5)].command), (yyvsp[(4) - (5)].command), (COMMAND *)NULL); }
2823 #line 874 "/Users/chet/src/bash/src/parse.y"
2824 { (yyval.command) = make_if_command ((yyvsp[(2) - (7)].command), (yyvsp[(4) - (7)].command), (yyvsp[(6) - (7)].command)); }
2828 #line 876 "/Users/chet/src/bash/src/parse.y"
2829 { (yyval.command) = make_if_command ((yyvsp[(2) - (6)].command), (yyvsp[(4) - (6)].command), (yyvsp[(5) - (6)].command)); }
2833 #line 881 "/Users/chet/src/bash/src/parse.y"
2834 { (yyval.command) = make_group_command ((yyvsp[(2) - (3)].command)); }
2838 #line 885 "/Users/chet/src/bash/src/parse.y"
2839 { (yyval.command) = make_arith_command ((yyvsp[(1) - (1)].word_list)); }
2843 #line 889 "/Users/chet/src/bash/src/parse.y"
2844 { (yyval.command) = (yyvsp[(2) - (3)].command); }
2848 #line 893 "/Users/chet/src/bash/src/parse.y"
2849 { (yyval.command) = make_if_command ((yyvsp[(2) - (4)].command), (yyvsp[(4) - (4)].command), (COMMAND *)NULL); }
2853 #line 895 "/Users/chet/src/bash/src/parse.y"
2854 { (yyval.command) = make_if_command ((yyvsp[(2) - (6)].command), (yyvsp[(4) - (6)].command), (yyvsp[(6) - (6)].command)); }
2858 #line 897 "/Users/chet/src/bash/src/parse.y"
2859 { (yyval.command) = make_if_command ((yyvsp[(2) - (5)].command), (yyvsp[(4) - (5)].command), (yyvsp[(5) - (5)].command)); }
2863 #line 902 "/Users/chet/src/bash/src/parse.y"
2864 { (yyvsp[(2) - (2)].pattern)->next = (yyvsp[(1) - (2)].pattern); (yyval.pattern) = (yyvsp[(2) - (2)].pattern); }
2868 #line 906 "/Users/chet/src/bash/src/parse.y"
2869 { (yyval.pattern) = make_pattern_list ((yyvsp[(2) - (4)].word_list), (yyvsp[(4) - (4)].command)); }
2873 #line 908 "/Users/chet/src/bash/src/parse.y"
2874 { (yyval.pattern) = make_pattern_list ((yyvsp[(2) - (4)].word_list), (COMMAND *)NULL); }
2878 #line 910 "/Users/chet/src/bash/src/parse.y"
2879 { (yyval.pattern) = make_pattern_list ((yyvsp[(3) - (5)].word_list), (yyvsp[(5) - (5)].command)); }
2883 #line 912 "/Users/chet/src/bash/src/parse.y"
2884 { (yyval.pattern) = make_pattern_list ((yyvsp[(3) - (5)].word_list), (COMMAND *)NULL); }
2888 #line 916 "/Users/chet/src/bash/src/parse.y"
2889 { (yyval.pattern) = (yyvsp[(1) - (2)].pattern); }
2893 #line 918 "/Users/chet/src/bash/src/parse.y"
2894 { (yyvsp[(2) - (3)].pattern)->next = (yyvsp[(1) - (3)].pattern); (yyval.pattern) = (yyvsp[(2) - (3)].pattern); }
2898 #line 920 "/Users/chet/src/bash/src/parse.y"
2899 { (yyvsp[(1) - (2)].pattern)->flags |= CASEPAT_FALLTHROUGH; (yyval.pattern) = (yyvsp[(1) - (2)].pattern); }
2903 #line 922 "/Users/chet/src/bash/src/parse.y"
2904 { (yyvsp[(2) - (3)].pattern)->flags |= CASEPAT_FALLTHROUGH; (yyvsp[(2) - (3)].pattern)->next = (yyvsp[(1) - (3)].pattern); (yyval.pattern) = (yyvsp[(2) - (3)].pattern); }
2908 #line 924 "/Users/chet/src/bash/src/parse.y"
2909 { (yyvsp[(1) - (2)].pattern)->flags |= CASEPAT_TESTNEXT; (yyval.pattern) = (yyvsp[(1) - (2)].pattern); }
2913 #line 926 "/Users/chet/src/bash/src/parse.y"
2914 { (yyvsp[(2) - (3)].pattern)->flags |= CASEPAT_TESTNEXT; (yyvsp[(2) - (3)].pattern)->next = (yyvsp[(1) - (3)].pattern); (yyval.pattern) = (yyvsp[(2) - (3)].pattern); }
2918 #line 930 "/Users/chet/src/bash/src/parse.y"
2919 { (yyval.word_list) = make_word_list ((yyvsp[(1) - (1)].word), (WORD_LIST *)NULL); }
2923 #line 932 "/Users/chet/src/bash/src/parse.y"
2924 { (yyval.word_list) = make_word_list ((yyvsp[(3) - (3)].word), (yyvsp[(1) - (3)].word_list)); }
2928 #line 941 "/Users/chet/src/bash/src/parse.y"
2930 (yyval.command) = (yyvsp[(2) - (2)].command);
2932 gather_here_documents ();
2937 #line 950 "/Users/chet/src/bash/src/parse.y"
2939 (yyval.command) = (yyvsp[(2) - (2)].command);
2944 #line 957 "/Users/chet/src/bash/src/parse.y"
2946 if ((yyvsp[(1) - (3)].command)->type == cm_connection)
2947 (yyval.command) = connect_async_list ((yyvsp[(1) - (3)].command), (COMMAND *)NULL, '&');
2949 (yyval.command) = command_connect ((yyvsp[(1) - (3)].command), (COMMAND *)NULL, '&');
2954 #line 968 "/Users/chet/src/bash/src/parse.y"
2955 { (yyval.command) = command_connect ((yyvsp[(1) - (4)].command), (yyvsp[(4) - (4)].command), AND_AND); }
2959 #line 970 "/Users/chet/src/bash/src/parse.y"
2960 { (yyval.command) = command_connect ((yyvsp[(1) - (4)].command), (yyvsp[(4) - (4)].command), OR_OR); }
2964 #line 972 "/Users/chet/src/bash/src/parse.y"
2966 if ((yyvsp[(1) - (4)].command)->type == cm_connection)
2967 (yyval.command) = connect_async_list ((yyvsp[(1) - (4)].command), (yyvsp[(4) - (4)].command), '&');
2969 (yyval.command) = command_connect ((yyvsp[(1) - (4)].command), (yyvsp[(4) - (4)].command), '&');
2974 #line 979 "/Users/chet/src/bash/src/parse.y"
2975 { (yyval.command) = command_connect ((yyvsp[(1) - (4)].command), (yyvsp[(4) - (4)].command), ';'); }
2979 #line 981 "/Users/chet/src/bash/src/parse.y"
2980 { (yyval.command) = command_connect ((yyvsp[(1) - (4)].command), (yyvsp[(4) - (4)].command), ';'); }
2984 #line 983 "/Users/chet/src/bash/src/parse.y"
2985 { (yyval.command) = (yyvsp[(1) - (1)].command); }
2989 #line 991 "/Users/chet/src/bash/src/parse.y"
2990 { (yyval.number) = '\n'; }
2994 #line 993 "/Users/chet/src/bash/src/parse.y"
2995 { (yyval.number) = ';'; }
2999 #line 995 "/Users/chet/src/bash/src/parse.y"
3000 { (yyval.number) = yacc_EOF; }
3004 #line 1009 "/Users/chet/src/bash/src/parse.y"
3006 (yyval.command) = (yyvsp[(1) - (1)].command);
3008 gather_here_documents ();
3009 if ((parser_state & PST_CMDSUBST) && current_token == shell_eof_token)
3011 global_command = (yyvsp[(1) - (1)].command);
3012 eof_encountered = 0;
3013 rewind_input_string ();
3020 #line 1022 "/Users/chet/src/bash/src/parse.y"
3022 if ((yyvsp[(1) - (2)].command)->type == cm_connection)
3023 (yyval.command) = connect_async_list ((yyvsp[(1) - (2)].command), (COMMAND *)NULL, '&');
3025 (yyval.command) = command_connect ((yyvsp[(1) - (2)].command), (COMMAND *)NULL, '&');
3027 gather_here_documents ();
3028 if ((parser_state & PST_CMDSUBST) && current_token == shell_eof_token)
3030 global_command = (yyvsp[(1) - (2)].command);
3031 eof_encountered = 0;
3032 rewind_input_string ();
3039 #line 1038 "/Users/chet/src/bash/src/parse.y"
3041 (yyval.command) = (yyvsp[(1) - (2)].command);
3043 gather_here_documents ();
3044 if ((parser_state & PST_CMDSUBST) && current_token == shell_eof_token)
3046 global_command = (yyvsp[(1) - (2)].command);
3047 eof_encountered = 0;
3048 rewind_input_string ();
3055 #line 1053 "/Users/chet/src/bash/src/parse.y"
3056 { (yyval.command) = command_connect ((yyvsp[(1) - (4)].command), (yyvsp[(4) - (4)].command), AND_AND); }
3060 #line 1055 "/Users/chet/src/bash/src/parse.y"
3061 { (yyval.command) = command_connect ((yyvsp[(1) - (4)].command), (yyvsp[(4) - (4)].command), OR_OR); }
3065 #line 1057 "/Users/chet/src/bash/src/parse.y"
3067 if ((yyvsp[(1) - (3)].command)->type == cm_connection)
3068 (yyval.command) = connect_async_list ((yyvsp[(1) - (3)].command), (yyvsp[(3) - (3)].command), '&');
3070 (yyval.command) = command_connect ((yyvsp[(1) - (3)].command), (yyvsp[(3) - (3)].command), '&');
3075 #line 1064 "/Users/chet/src/bash/src/parse.y"
3076 { (yyval.command) = command_connect ((yyvsp[(1) - (3)].command), (yyvsp[(3) - (3)].command), ';'); }
3080 #line 1067 "/Users/chet/src/bash/src/parse.y"
3081 { (yyval.command) = (yyvsp[(1) - (1)].command); }
3085 #line 1071 "/Users/chet/src/bash/src/parse.y"
3086 { (yyval.command) = (yyvsp[(1) - (1)].command); }
3090 #line 1073 "/Users/chet/src/bash/src/parse.y"
3092 if ((yyvsp[(2) - (2)].command))
3093 (yyvsp[(2) - (2)].command)->flags |= CMD_INVERT_RETURN;
3094 (yyval.command) = (yyvsp[(2) - (2)].command);
3099 #line 1079 "/Users/chet/src/bash/src/parse.y"
3101 if ((yyvsp[(2) - (2)].command))
3102 (yyvsp[(2) - (2)].command)->flags |= (yyvsp[(1) - (2)].number);
3103 (yyval.command) = (yyvsp[(2) - (2)].command);
3108 #line 1085 "/Users/chet/src/bash/src/parse.y"
3110 if ((yyvsp[(3) - (3)].command))
3111 (yyvsp[(3) - (3)].command)->flags |= (yyvsp[(1) - (3)].number)|CMD_INVERT_RETURN;
3112 (yyval.command) = (yyvsp[(3) - (3)].command);
3117 #line 1091 "/Users/chet/src/bash/src/parse.y"
3119 if ((yyvsp[(3) - (3)].command))
3120 (yyvsp[(3) - (3)].command)->flags |= (yyvsp[(2) - (3)].number)|CMD_INVERT_RETURN;
3121 (yyval.command) = (yyvsp[(3) - (3)].command);
3126 #line 1097 "/Users/chet/src/bash/src/parse.y"
3130 /* Boy, this is unclean. `time' by itself can
3131 time a null command. We cheat and push a
3132 newline back if the list_terminator was a newline
3133 to avoid the double-newline problem (one to
3134 terminate this, one to terminate the command) */
3137 (yyval.command) = make_simple_command (x, (COMMAND *)NULL);
3138 (yyval.command)->flags |= (yyvsp[(1) - (2)].number);
3139 /* XXX - let's cheat and push a newline back */
3140 if ((yyvsp[(2) - (2)].number) == '\n')
3141 token_to_read = '\n';
3146 #line 1117 "/Users/chet/src/bash/src/parse.y"
3147 { (yyval.command) = command_connect ((yyvsp[(1) - (4)].command), (yyvsp[(4) - (4)].command), '|'); }
3151 #line 1119 "/Users/chet/src/bash/src/parse.y"
3153 /* Make cmd1 |& cmd2 equivalent to cmd1 2>&1 | cmd2 */
3158 tc = (yyvsp[(1) - (4)].command);
3160 r = make_redirection (2, r_duplicating_output, rd);
3163 register REDIRECT *t;
3164 for (t = tc->redirects; t->next; t = t->next)
3171 (yyval.command) = command_connect ((yyvsp[(1) - (4)].command), (yyvsp[(4) - (4)].command), '|');
3176 #line 1141 "/Users/chet/src/bash/src/parse.y"
3177 { (yyval.command) = (yyvsp[(1) - (1)].command); }
3181 #line 1145 "/Users/chet/src/bash/src/parse.y"
3182 { (yyval.number) = CMD_TIME_PIPELINE; }
3186 #line 1147 "/Users/chet/src/bash/src/parse.y"
3187 { (yyval.number) = CMD_TIME_PIPELINE|CMD_TIME_POSIX; }
3191 /* Line 1267 of yacc.c. */
3192 #line 3193 "y.tab.c"
3195 YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc);
3199 YY_STACK_PRINT (yyss, yyssp);
3204 /* Now `shift' the result of the reduction. Determine what state
3205 that goes to, based on the state we popped back to and the rule
3206 number reduced by. */
3210 yystate = yypgoto[yyn - YYNTOKENS] + *yyssp;
3211 if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp)
3212 yystate = yytable[yystate];
3214 yystate = yydefgoto[yyn - YYNTOKENS];
3219 /*------------------------------------.
3220 | yyerrlab -- here on detecting error |
3221 `------------------------------------*/
3223 /* If not already recovering from an error, report this error. */
3227 #if ! YYERROR_VERBOSE
3228 yyerror (YY_("syntax error"));
3231 YYSIZE_T yysize = yysyntax_error (0, yystate, yychar);
3232 if (yymsg_alloc < yysize && yymsg_alloc < YYSTACK_ALLOC_MAXIMUM)
3234 YYSIZE_T yyalloc = 2 * yysize;
3235 if (! (yysize <= yyalloc && yyalloc <= YYSTACK_ALLOC_MAXIMUM))
3236 yyalloc = YYSTACK_ALLOC_MAXIMUM;
3237 if (yymsg != yymsgbuf)
3238 YYSTACK_FREE (yymsg);
3239 yymsg = (char *) YYSTACK_ALLOC (yyalloc);
3241 yymsg_alloc = yyalloc;
3245 yymsg_alloc = sizeof yymsgbuf;
3249 if (0 < yysize && yysize <= yymsg_alloc)
3251 (void) yysyntax_error (yymsg, yystate, yychar);
3256 yyerror (YY_("syntax error"));
3258 goto yyexhaustedlab;
3266 if (yyerrstatus == 3)
3268 /* If just tried and failed to reuse look-ahead token after an
3269 error, discard it. */
3271 if (yychar <= YYEOF)
3273 /* Return failure if at end of input. */
3274 if (yychar == YYEOF)
3279 yydestruct ("Error: discarding",
3285 /* Else will try to reuse look-ahead token after shifting the error
3290 /*---------------------------------------------------.
3291 | yyerrorlab -- error raised explicitly by YYERROR. |
3292 `---------------------------------------------------*/
3295 /* Pacify compilers like GCC when the user code never invokes
3296 YYERROR and the label yyerrorlab therefore never appears in user
3298 if (/*CONSTCOND*/ 0)
3301 /* Do not reclaim the symbols of the rule which action triggered
3305 YY_STACK_PRINT (yyss, yyssp);
3310 /*-------------------------------------------------------------.
3311 | yyerrlab1 -- common code for both syntax error and YYERROR. |
3312 `-------------------------------------------------------------*/
3314 yyerrstatus = 3; /* Each real token shifted decrements this. */
3318 yyn = yypact[yystate];
3319 if (yyn != YYPACT_NINF)
3322 if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
3330 /* Pop the current state because it cannot handle the error token. */
3335 yydestruct ("Error: popping",
3336 yystos[yystate], yyvsp);
3339 YY_STACK_PRINT (yyss, yyssp);
3348 /* Shift the error token. */
3349 YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp);
3355 /*-------------------------------------.
3356 | yyacceptlab -- YYACCEPT comes here. |
3357 `-------------------------------------*/
3362 /*-----------------------------------.
3363 | yyabortlab -- YYABORT comes here. |
3364 `-----------------------------------*/
3370 /*-------------------------------------------------.
3371 | yyexhaustedlab -- memory exhaustion comes here. |
3372 `-------------------------------------------------*/
3374 yyerror (YY_("memory exhausted"));
3380 if (yychar != YYEOF && yychar != YYEMPTY)
3381 yydestruct ("Cleanup: discarding lookahead",
3383 /* Do not reclaim the symbols of the rule which action triggered
3384 this YYABORT or YYACCEPT. */
3386 YY_STACK_PRINT (yyss, yyssp);
3387 while (yyssp != yyss)
3389 yydestruct ("Cleanup: popping",
3390 yystos[*yyssp], yyvsp);
3395 YYSTACK_FREE (yyss);
3398 if (yymsg != yymsgbuf)
3399 YYSTACK_FREE (yymsg);
3401 /* Make sure YYID is used. */
3402 return YYID (yyresult);
3406 #line 1149 "/Users/chet/src/bash/src/parse.y"
3409 /* Initial size to allocate for tokens, and the
3410 amount to grow them by. */
3411 #define TOKEN_DEFAULT_INITIAL_SIZE 496
3412 #define TOKEN_DEFAULT_GROW_SIZE 512
3414 /* Should we call prompt_again? */
3415 #define SHOULD_PROMPT() \
3416 (interactive && (bash_input.type == st_stdin || bash_input.type == st_stream))
3419 # define expanding_alias() (pushed_string_list && pushed_string_list->expander)
3421 # define expanding_alias() 0
3424 /* Global var is non-zero when end of file has been reached. */
3425 int EOF_Reached = 0;
3438 /* yy_getc () returns the next available character from input or EOF.
3439 yy_ungetc (c) makes `c' the next character to read.
3440 init_yy_io (get, unget, type, location) makes the function GET the
3441 installed function for getting the next character, makes UNGET the
3442 installed function for un-getting a character, sets the type of stream
3443 (either string or file) from TYPE, and makes LOCATION point to where
3444 the input is coming from. */
3446 /* Unconditionally returns end-of-file. */
3453 /* Variable containing the current get and unget functions.
3454 See ./input.h for a clearer description. */
3455 BASH_INPUT bash_input;
3457 /* Set all of the fields in BASH_INPUT to NULL. Free bash_input.name if it
3458 is non-null, avoiding a memory leak. */
3460 initialize_bash_input ()
3462 bash_input.type = st_none;
3463 FREE (bash_input.name);
3464 bash_input.name = (char *)NULL;
3465 bash_input.location.file = (FILE *)NULL;
3466 bash_input.location.string = (char *)NULL;
3467 bash_input.getter = (sh_cget_func_t *)NULL;
3468 bash_input.ungetter = (sh_cunget_func_t *)NULL;
3471 /* Set the contents of the current bash input stream from
3472 GET, UNGET, TYPE, NAME, and LOCATION. */
3474 init_yy_io (get, unget, type, name, location)
3475 sh_cget_func_t *get;
3476 sh_cunget_func_t *unget;
3477 enum stream_type type;
3479 INPUT_STREAM location;
3481 bash_input.type = type;
3482 FREE (bash_input.name);
3483 bash_input.name = name ? savestring (name) : (char *)NULL;
3487 memcpy((char *)&bash_input.location.string, (char *)&location.string, sizeof(location));
3489 bash_input.location = location;
3491 bash_input.getter = get;
3492 bash_input.ungetter = unget;
3498 return (bash_input.name ? bash_input.name : "stdin");
3501 /* Call this to get the next character of input. */
3505 return (*(bash_input.getter)) ();
3508 /* Call this to unget C. That is, to make C the next character
3514 return (*(bash_input.ungetter)) (c);
3517 #if defined (BUFFERED_INPUT)
3518 #ifdef INCLUDE_UNUSED
3520 input_file_descriptor ()
3522 switch (bash_input.type)
3525 return (fileno (bash_input.location.file));
3527 return (bash_input.location.buffered_fd);
3530 return (fileno (stdin));
3534 #endif /* BUFFERED_INPUT */
3536 /* **************************************************************** */
3538 /* Let input be read from readline (). */
3540 /* **************************************************************** */
3542 #if defined (READLINE)
3543 char *current_readline_prompt = (char *)NULL;
3544 char *current_readline_line = (char *)NULL;
3545 int current_readline_line_index = 0;
3550 SigHandler *old_sigint;
3554 if (!current_readline_line)
3556 if (!bash_readline_initialized)
3557 initialize_readline ();
3559 #if defined (JOB_CONTROL)
3561 give_terminal_to (shell_pgrp, 0);
3562 #endif /* JOB_CONTROL */
3564 old_sigint = (SigHandler *)NULL;
3565 if (signal_is_ignored (SIGINT) == 0)
3567 old_sigint = (SigHandler *)set_signal_handler (SIGINT, sigint_sighandler);
3568 interrupt_immediately++;
3570 terminate_immediately = 1;
3572 current_readline_line = readline (current_readline_prompt ?
3573 current_readline_prompt : "");
3575 terminate_immediately = 0;
3576 if (signal_is_ignored (SIGINT) == 0 && old_sigint)
3578 interrupt_immediately--;
3579 set_signal_handler (SIGINT, old_sigint);
3583 /* Reset the prompt to the decoded value of prompt_string_pointer. */
3584 reset_readline_prompt ();
3587 if (current_readline_line == 0)
3590 current_readline_line_index = 0;
3591 line_len = strlen (current_readline_line);
3593 current_readline_line = (char *)xrealloc (current_readline_line, 2 + line_len);
3594 current_readline_line[line_len++] = '\n';
3595 current_readline_line[line_len] = '\0';
3598 if (current_readline_line[current_readline_line_index] == 0)
3600 free (current_readline_line);
3601 current_readline_line = (char *)NULL;
3602 return (yy_readline_get ());
3606 c = current_readline_line[current_readline_line_index++];
3612 yy_readline_unget (c)
3615 if (current_readline_line_index && current_readline_line)
3616 current_readline_line[--current_readline_line_index] = c;
3621 with_input_from_stdin ()
3623 INPUT_STREAM location;
3625 if (bash_input.type != st_stdin && stream_on_stack (st_stdin) == 0)
3627 location.string = current_readline_line;
3628 init_yy_io (yy_readline_get, yy_readline_unget,
3629 st_stdin, "readline stdin", location);
3633 #else /* !READLINE */
3636 with_input_from_stdin ()
3638 with_input_from_stream (stdin, "stdin");
3640 #endif /* !READLINE */
3642 /* **************************************************************** */
3644 /* Let input come from STRING. STRING is zero terminated. */
3646 /* **************************************************************** */
3651 register char *string;
3652 register unsigned char c;
3654 string = bash_input.location.string;
3656 /* If the string doesn't exist, or is empty, EOF found. */
3657 if (string && *string)
3660 bash_input.location.string = string;
3671 *(--bash_input.location.string) = c;
3676 with_input_from_string (string, name)
3680 INPUT_STREAM location;
3682 location.string = string;
3683 init_yy_io (yy_string_get, yy_string_unget, st_string, name, location);
3686 /* Count the number of characters we've consumed from bash_input.location.string
3687 and read into shell_input_line, but have not returned from shell_getc.
3688 That is the true input location. Rewind bash_input.location.string by
3689 that number of characters, so it points to the last character actually
3690 consumed by the parser. */
3692 rewind_input_string ()
3696 /* number of unconsumed characters in the input -- XXX need to take newlines
3697 into account, e.g., $(...\n) */
3698 xchars = shell_input_line_len - shell_input_line_index;
3699 if (bash_input.location.string[-1] == '\n')
3702 /* XXX - how to reflect bash_input.location.string back to string passed to
3703 parse_and_execute or xparse_dolparen? xparse_dolparen needs to know how
3704 far into the string we parsed. parse_and_execute knows where bash_input.
3705 location.string is, and how far from orig_string that is -- that's the
3706 number of characters the command consumed. */
3708 /* bash_input.location.string - xchars should be where we parsed to */
3709 /* need to do more validation on xchars value for sanity -- test cases. */
3710 bash_input.location.string -= xchars;
3713 /* **************************************************************** */
3715 /* Let input come from STREAM. */
3717 /* **************************************************************** */
3719 /* These two functions used to test the value of the HAVE_RESTARTABLE_SYSCALLS
3720 define, and just use getc/ungetc if it was defined, but since bash
3721 installs its signal handlers without the SA_RESTART flag, some signals
3722 (like SIGCHLD, SIGWINCH, etc.) received during a read(2) will not cause
3723 the read to be restarted. We need to restart it ourselves. */
3731 if (bash_input.location.file)
3735 interrupt_immediately++;
3736 terminate_immediately++;
3738 result = getc_with_restart (bash_input.location.file);
3741 interrupt_immediately--;
3742 terminate_immediately--;
3752 return (ungetc_with_restart (c, bash_input.location.file));
3756 with_input_from_stream (stream, name)
3760 INPUT_STREAM location;
3762 location.file = stream;
3763 init_yy_io (yy_stream_get, yy_stream_unget, st_stream, name, location);
3766 typedef struct stream_saver {
3767 struct stream_saver *next;
3768 BASH_INPUT bash_input;
3770 #if defined (BUFFERED_INPUT)
3771 BUFFERED_STREAM *bstream;
3772 #endif /* BUFFERED_INPUT */
3775 /* The globally known line number. */
3776 int line_number = 0;
3778 #if defined (COND_COMMAND)
3779 static int cond_lineno;
3780 static int cond_token;
3783 STREAM_SAVER *stream_list = (STREAM_SAVER *)NULL;
3786 push_stream (reset_lineno)
3789 STREAM_SAVER *saver = (STREAM_SAVER *)xmalloc (sizeof (STREAM_SAVER));
3791 xbcopy ((char *)&bash_input, (char *)&(saver->bash_input), sizeof (BASH_INPUT));
3793 #if defined (BUFFERED_INPUT)
3794 saver->bstream = (BUFFERED_STREAM *)NULL;
3795 /* If we have a buffered stream, clear out buffers[fd]. */
3796 if (bash_input.type == st_bstream && bash_input.location.buffered_fd >= 0)
3797 saver->bstream = set_buffered_stream (bash_input.location.buffered_fd,
3798 (BUFFERED_STREAM *)NULL);
3799 #endif /* BUFFERED_INPUT */
3801 saver->line = line_number;
3802 bash_input.name = (char *)NULL;
3803 saver->next = stream_list;
3804 stream_list = saver;
3817 STREAM_SAVER *saver = stream_list;
3820 stream_list = stream_list->next;
3822 init_yy_io (saver->bash_input.getter,
3823 saver->bash_input.ungetter,
3824 saver->bash_input.type,
3825 saver->bash_input.name,
3826 saver->bash_input.location);
3828 #if defined (BUFFERED_INPUT)
3829 /* If we have a buffered stream, restore buffers[fd]. */
3830 /* If the input file descriptor was changed while this was on the
3831 save stack, update the buffered fd to the new file descriptor and
3832 re-establish the buffer <-> bash_input fd correspondence. */
3833 if (bash_input.type == st_bstream && bash_input.location.buffered_fd >= 0)
3835 if (bash_input_fd_changed)
3837 bash_input_fd_changed = 0;
3838 if (default_buffered_input >= 0)
3840 bash_input.location.buffered_fd = default_buffered_input;
3841 saver->bstream->b_fd = default_buffered_input;
3842 SET_CLOSE_ON_EXEC (default_buffered_input);
3845 /* XXX could free buffered stream returned as result here. */
3846 set_buffered_stream (bash_input.location.buffered_fd, saver->bstream);
3848 #endif /* BUFFERED_INPUT */
3850 line_number = saver->line;
3852 FREE (saver->bash_input.name);
3857 /* Return 1 if a stream of type TYPE is saved on the stack. */
3859 stream_on_stack (type)
3860 enum stream_type type;
3862 register STREAM_SAVER *s;
3864 for (s = stream_list; s; s = s->next)
3865 if (s->bash_input.type == type)
3870 /* Save the current token state and return it in a malloced array. */
3876 ret = (int *)xmalloc (3 * sizeof (int));
3877 ret[0] = last_read_token;
3878 ret[1] = token_before_that;
3879 ret[2] = two_tokens_ago;
3884 restore_token_state (ts)
3889 last_read_token = ts[0];
3890 token_before_that = ts[1];
3891 two_tokens_ago = ts[2];
3895 * This is used to inhibit alias expansion and reserved word recognition
3896 * inside case statement pattern lists. A `case statement pattern list' is:
3898 * everything between the `in' in a `case word in' and the next ')'
3900 * everything between a `;;' and the next `)' or `esac'
3903 #if defined (ALIAS) || defined (DPAREN_ARITHMETIC)
3905 #define END_OF_ALIAS 0
3908 * Pseudo-global variables used in implementing token-wise alias expansion.
3912 * Pushing and popping strings. This works together with shell_getc to
3913 * implement alias expansion on a per-token basis.
3916 typedef struct string_saver {
3917 struct string_saver *next;
3918 int expand_alias; /* Value to set expand_alias to when string is popped. */
3921 alias_t *expander; /* alias that caused this line to be pushed. */
3923 int saved_line_size, saved_line_index, saved_line_terminator;
3926 STRING_SAVER *pushed_string_list = (STRING_SAVER *)NULL;
3929 * Push the current shell_input_line onto a stack of such lines and make S
3930 * the current input. Used when expanding aliases. EXPAND is used to set
3931 * the value of expand_next_token when the string is popped, so that the
3932 * word after the alias in the original line is handled correctly when the
3933 * alias expands to multiple words. TOKEN is the token that was expanded
3934 * into S; it is saved and used to prevent infinite recursive expansion.
3937 push_string (s, expand, ap)
3942 STRING_SAVER *temp = (STRING_SAVER *)xmalloc (sizeof (STRING_SAVER));
3944 temp->expand_alias = expand;
3945 temp->saved_line = shell_input_line;
3946 temp->saved_line_size = shell_input_line_size;
3947 temp->saved_line_index = shell_input_line_index;
3948 temp->saved_line_terminator = shell_input_line_terminator;
3950 temp->expander = ap;
3952 temp->next = pushed_string_list;
3953 pushed_string_list = temp;
3957 ap->flags |= AL_BEINGEXPANDED;
3960 shell_input_line = s;
3961 shell_input_line_size = strlen (s);
3962 shell_input_line_index = 0;
3963 shell_input_line_terminator = '\0';
3965 parser_state &= ~PST_ALEXPNEXT; /* XXX */
3968 set_line_mbstate ();
3972 * Make the top of the pushed_string stack be the current shell input.
3973 * Only called when there is something on the stack. Called from shell_getc
3974 * when it thinks it has consumed the string generated by an alias expansion
3975 * and needs to return to the original input line.
3982 FREE (shell_input_line);
3983 shell_input_line = pushed_string_list->saved_line;
3984 shell_input_line_index = pushed_string_list->saved_line_index;
3985 shell_input_line_size = pushed_string_list->saved_line_size;
3986 shell_input_line_terminator = pushed_string_list->saved_line_terminator;
3988 if (pushed_string_list->expand_alias)
3989 parser_state |= PST_ALEXPNEXT;
3991 parser_state &= ~PST_ALEXPNEXT;
3993 t = pushed_string_list;
3994 pushed_string_list = pushed_string_list->next;
3998 t->expander->flags &= ~AL_BEINGEXPANDED;
4003 set_line_mbstate ();
4009 register STRING_SAVER *t, *t1;
4011 for (t = pushed_string_list; t; )
4014 FREE (t->saved_line);
4017 t->expander->flags &= ~AL_BEINGEXPANDED;
4022 pushed_string_list = (STRING_SAVER *)NULL;
4025 #endif /* ALIAS || DPAREN_ARITHMETIC */
4028 free_pushed_string_input ()
4030 #if defined (ALIAS) || defined (DPAREN_ARITHMETIC)
4031 free_string_list ();
4035 /* Return a line of text, taken from wherever yylex () reads input.
4036 If there is no more input, then we return NULL. If REMOVE_QUOTED_NEWLINE
4037 is non-zero, we remove unquoted \<newline> pairs. This is used by
4038 read_secondary_line to read here documents. */
4040 read_a_line (remove_quoted_newline)
4041 int remove_quoted_newline;
4043 static char *line_buffer = (char *)NULL;
4044 static int buffer_size = 0;
4045 int indx = 0, c, peekc, pass_next;
4047 #if defined (READLINE)
4048 if (no_line_editing && SHOULD_PROMPT ())
4050 if (SHOULD_PROMPT ())
4057 /* Allow immediate exit if interrupted during input. */
4062 /* Ignore null bytes in input. */
4066 internal_warning ("read_a_line: ignored null byte in input");
4071 /* If there is no more input, then we return NULL. */
4074 if (interactive && bash_input.type == st_stream)
4077 return ((char *)NULL);
4081 /* `+2' in case the final character in the buffer is a newline. */
4082 RESIZE_MALLOCED_BUFFER (line_buffer, indx, 2, buffer_size, 128);
4084 /* IF REMOVE_QUOTED_NEWLINES is non-zero, we are reading a
4085 here document with an unquoted delimiter. In this case,
4086 the line will be expanded as if it were in double quotes.
4087 We allow a backslash to escape the next character, but we
4088 need to treat the backslash specially only if a backslash
4089 quoting a backslash-newline pair appears in the line. */
4092 line_buffer[indx++] = c;
4095 else if (c == '\\' && remove_quoted_newline)
4101 continue; /* Make the unquoted \<newline> pair disappear. */
4107 line_buffer[indx++] = c; /* Preserve the backslash. */
4111 line_buffer[indx++] = c;
4115 line_buffer[indx] = '\0';
4116 return (line_buffer);
4121 /* Return a line as in read_a_line (), but insure that the prompt is
4122 the secondary prompt. This is used to read the lines of a here
4123 document. REMOVE_QUOTED_NEWLINE is non-zero if we should remove
4124 newlines quoted with backslashes while reading the line. It is
4125 non-zero unless the delimiter of the here document was quoted. */
4127 read_secondary_line (remove_quoted_newline)
4128 int remove_quoted_newline;
4133 prompt_string_pointer = &ps2_prompt;
4134 if (SHOULD_PROMPT())
4136 ret = read_a_line (remove_quoted_newline);
4137 #if defined (HISTORY)
4138 if (remember_on_history && (parser_state & PST_HEREDOC))
4140 /* To make adding the the here-document body right, we need to rely
4141 on history_delimiting_chars() returning \n for the first line of
4142 the here-document body and the null string for the second and
4143 subsequent lines, so we avoid double newlines.
4144 current_command_line_count == 2 for the first line of the body. */
4146 current_command_line_count++;
4147 maybe_add_history (ret);
4149 #endif /* HISTORY */
4153 /* **************************************************************** */
4157 /* **************************************************************** */
4159 /* Reserved words. These are only recognized as the first word of a
4161 STRING_INT_ALIST word_token_alist[] = {
4170 #if defined (SELECT_COMMAND)
4171 { "select", SELECT },
4178 { "function", FUNCTION },
4179 #if defined (COMMAND_TIMING)
4185 #if defined (COND_COMMAND)
4186 { "[[", COND_START },
4189 #if defined (COPROCESS_SUPPORT)
4190 { "coproc", COPROC },
4195 /* other tokens that can be returned by read_token() */
4196 STRING_INT_ALIST other_token_alist[] = {
4197 /* Multiple-character tokens with special values */
4201 { ">>", GREATER_GREATER },
4202 { "<<", LESS_LESS },
4204 { ">&", GREATER_AND },
4205 { ";;", SEMI_SEMI },
4207 { ";;&", SEMI_SEMI_AND },
4208 { "<<-", LESS_LESS_MINUS },
4209 { "<<<", LESS_LESS_LESS },
4210 { "&>", AND_GREATER },
4211 { "&>>", AND_GREATER_GREATER },
4212 { "<>", LESS_GREATER },
4213 { ">|", GREATER_BAR },
4215 { "EOF", yacc_EOF },
4216 /* Tokens whose value is the character itself */
4227 { "newline", '\n' },
4231 /* others not listed here:
4232 WORD look at yylval.word
4233 ASSIGNMENT_WORD look at yylval.word
4234 NUMBER look at yylval.number
4235 ARITH_CMD look at yylval.word_list
4236 ARITH_FOR_EXPRS look at yylval.word_list
4237 COND_CMD look at yylval.command
4240 /* These are used by read_token_word, but appear up here so that shell_getc
4241 can use them to decide when to add otherwise blank lines to the history. */
4243 /* The primary delimiter stack. */
4244 struct dstack dstack = { (char *)NULL, 0, 0 };
4246 /* A temporary delimiter stack to be used when decoding prompt strings.
4247 This is needed because command substitutions in prompt strings (e.g., PS2)
4248 can screw up the parser's quoting state. */
4249 static struct dstack temp_dstack = { (char *)NULL, 0, 0 };
4251 /* Macro for accessing the top delimiter on the stack. Returns the
4252 delimiter or zero if none. */
4253 #define current_delimiter(ds) \
4254 (ds.delimiter_depth ? ds.delimiters[ds.delimiter_depth - 1] : 0)
4256 #define push_delimiter(ds, character) \
4259 if (ds.delimiter_depth + 2 > ds.delimiter_space) \
4260 ds.delimiters = (char *)xrealloc \
4261 (ds.delimiters, (ds.delimiter_space += 10) * sizeof (char)); \
4262 ds.delimiters[ds.delimiter_depth] = character; \
4263 ds.delimiter_depth++; \
4267 #define pop_delimiter(ds) ds.delimiter_depth--
4269 /* Return the next shell input character. This always reads characters
4270 from shell_input_line; when that line is exhausted, it is time to
4271 read the next line. This is called by read_token when the shell is
4272 processing normal command input. */
4274 /* This implements one-character lookahead/lookbehind across physical input
4275 lines, to avoid something being lost because it's pushed back with
4276 shell_ungetc when we're at the start of a line. */
4277 static int eol_ungetc_lookahead = 0;
4280 shell_getc (remove_quoted_newline)
4281 int remove_quoted_newline;
4289 if (sigwinch_received)
4291 sigwinch_received = 0;
4292 get_new_window_size (0, (int *)0, (int *)0);
4295 if (eol_ungetc_lookahead)
4297 c = eol_ungetc_lookahead;
4298 eol_ungetc_lookahead = 0;
4302 #if defined (ALIAS) || defined (DPAREN_ARITHMETIC)
4303 /* If shell_input_line[shell_input_line_index] == 0, but there is
4304 something on the pushed list of strings, then we don't want to go
4305 off and get another line. We let the code down below handle it. */
4307 if (!shell_input_line || ((!shell_input_line[shell_input_line_index]) &&
4308 (pushed_string_list == (STRING_SAVER *)NULL)))
4309 #else /* !ALIAS && !DPAREN_ARITHMETIC */
4310 if (!shell_input_line || !shell_input_line[shell_input_line_index])
4311 #endif /* !ALIAS && !DPAREN_ARITHMETIC */
4317 /* Allow immediate exit if interrupted during input. */
4321 shell_input_line_terminator = 0;
4323 /* If the shell is interatctive, but not currently printing a prompt
4324 (interactive_shell && interactive == 0), we don't want to print
4325 notifies or cleanup the jobs -- we want to defer it until we do
4326 print the next prompt. */
4327 if (interactive_shell == 0 || SHOULD_PROMPT())
4329 #if defined (JOB_CONTROL)
4330 /* This can cause a problem when reading a command as the result
4331 of a trap, when the trap is called from flush_child. This call
4332 had better not cause jobs to disappear from the job table in
4333 that case, or we will have big trouble. */
4334 notify_and_cleanup ();
4335 #else /* !JOB_CONTROL */
4336 cleanup_dead_jobs ();
4337 #endif /* !JOB_CONTROL */
4340 #if defined (READLINE)
4341 if (no_line_editing && SHOULD_PROMPT())
4343 if (SHOULD_PROMPT())
4347 if (bash_input.type == st_stream)
4354 /* Allow immediate exit if interrupted during input. */
4360 internal_warning ("shell_getc: ignored null byte in input");
4365 RESIZE_MALLOCED_BUFFER (shell_input_line, i, 2, shell_input_line_size, 256);
4369 if (bash_input.type == st_stream)
4373 shell_input_line_terminator = EOF;
4375 shell_input_line[i] = '\0';
4379 shell_input_line[i++] = c;
4383 shell_input_line[--i] = '\0';
4384 current_command_line_count++;
4389 shell_input_line_index = 0;
4390 shell_input_line_len = i; /* == strlen (shell_input_line) */
4392 set_line_mbstate ();
4394 #if defined (HISTORY)
4395 if (remember_on_history && shell_input_line && shell_input_line[0])
4398 # if defined (BANG_HISTORY)
4401 /* If the current delimiter is a single quote, we should not be
4402 performing history expansion, even if we're on a different
4403 line from the original single quote. */
4404 old_hist = history_expansion_inhibited;
4405 if (current_delimiter (dstack) == '\'')
4406 history_expansion_inhibited = 1;
4408 expansions = pre_process_line (shell_input_line, 1, 1);
4409 # if defined (BANG_HISTORY)
4410 history_expansion_inhibited = old_hist;
4412 if (expansions != shell_input_line)
4414 free (shell_input_line);
4415 shell_input_line = expansions;
4416 shell_input_line_len = shell_input_line ?
4417 strlen (shell_input_line) : 0;
4418 if (!shell_input_line_len)
4419 current_command_line_count--;
4421 /* We have to force the xrealloc below because we don't know
4422 the true allocated size of shell_input_line anymore. */
4423 shell_input_line_size = shell_input_line_len;
4425 set_line_mbstate ();
4428 /* Try to do something intelligent with blank lines encountered while
4429 entering multi-line commands. XXX - this is grotesque */
4430 else if (remember_on_history && shell_input_line &&
4431 shell_input_line[0] == '\0' &&
4432 current_command_line_count > 1)
4434 if (current_delimiter (dstack))
4435 /* We know shell_input_line[0] == 0 and we're reading some sort of
4436 quoted string. This means we've got a line consisting of only
4437 a newline in a quoted string. We want to make sure this line
4438 gets added to the history. */
4439 maybe_add_history (shell_input_line);
4443 hdcs = history_delimiting_chars ();
4444 if (hdcs && hdcs[0] == ';')
4445 maybe_add_history (shell_input_line);
4449 #endif /* HISTORY */
4451 if (shell_input_line)
4453 /* Lines that signify the end of the shell's input should not be
4455 if (echo_input_at_read && (shell_input_line[0] ||
4456 shell_input_line_terminator != EOF))
4457 fprintf (stderr, "%s\n", shell_input_line);
4461 shell_input_line_size = 0;
4462 prompt_string_pointer = ¤t_prompt_string;
4463 if (SHOULD_PROMPT ())
4468 /* Add the newline to the end of this string, iff the string does
4469 not already end in an EOF character. */
4470 if (shell_input_line_terminator != EOF)
4472 if (shell_input_line_len + 3 > shell_input_line_size)
4473 shell_input_line = (char *)xrealloc (shell_input_line,
4474 1 + (shell_input_line_size += 2));
4476 shell_input_line[shell_input_line_len] = '\n';
4477 shell_input_line[shell_input_line_len + 1] = '\0';
4479 set_line_mbstate ();
4483 uc = shell_input_line[shell_input_line_index];
4486 shell_input_line_index++;
4488 #if defined (ALIAS) || defined (DPAREN_ARITHMETIC)
4489 /* If UC is NULL, we have reached the end of the current input string. If
4490 pushed_string_list is non-empty, it's time to pop to the previous string
4491 because we have fully consumed the result of the last alias expansion.
4492 Do it transparently; just return the next character of the string popped
4494 if (!uc && (pushed_string_list != (STRING_SAVER *)NULL))
4497 uc = shell_input_line[shell_input_line_index];
4499 shell_input_line_index++;
4501 #endif /* ALIAS || DPAREN_ARITHMETIC */
4503 if MBTEST(uc == '\\' && remove_quoted_newline && shell_input_line[shell_input_line_index] == '\n')
4505 if (SHOULD_PROMPT ())
4511 if (!uc && shell_input_line_terminator == EOF)
4512 return ((shell_input_line_index != 0) ? '\n' : EOF);
4517 /* Put C back into the input for the shell. This might need changes for
4518 HANDLE_MULTIBYTE around EOLs. Since we (currently) never push back a
4519 character different than we read, shell_input_line_property doesn't need
4520 to change when manipulating shell_input_line. The define for
4521 last_shell_getc_is_singlebyte should take care of it, though. */
4526 if (shell_input_line && shell_input_line_index)
4527 shell_input_line[--shell_input_line_index] = c;
4529 eol_ungetc_lookahead = c;
4532 #ifdef INCLUDE_UNUSED
4533 /* Back the input pointer up by one, effectively `ungetting' a character. */
4537 if (shell_input_line && shell_input_line_index)
4538 shell_input_line_index--;
4542 /* Discard input until CHARACTER is seen, then push that character back
4543 onto the input stream. */
4545 discard_until (character)
4550 while ((c = shell_getc (0)) != EOF && c != character)
4558 execute_variable_command (command, vname)
4559 char *command, *vname;
4562 sh_parser_state_t ps;
4564 save_parser_state (&ps);
4565 last_lastarg = get_string_value ("_");
4567 last_lastarg = savestring (last_lastarg);
4569 parse_and_execute (savestring (command), vname, SEVAL_NONINT|SEVAL_NOHIST);
4571 restore_parser_state (&ps);
4572 bind_variable ("_", last_lastarg, 0);
4573 FREE (last_lastarg);
4575 if (token_to_read == '\n') /* reset_parser was called */
4579 /* Place to remember the token. We try to keep the buffer
4580 at a reasonable size, but it can grow. */
4581 static char *token = (char *)NULL;
4583 /* Current size of the token buffer. */
4584 static int token_buffer_size;
4586 /* Command to read_token () explaining what we want it to do. */
4589 #define prompt_is_ps1 \
4590 (!prompt_string_pointer || prompt_string_pointer == &ps1_prompt)
4592 /* Function for yyparse to call. yylex keeps track of
4593 the last two tokens read, and calls read_token. */
4597 if (interactive && (current_token == 0 || current_token == '\n'))
4599 /* Before we print a prompt, we might have to check mailboxes.
4600 We do this only if it is time to do so. Notice that only here
4601 is the mail alarm reset; nothing takes place in check_mail ()
4602 except the checking of mail. Please don't change this. */
4603 if (prompt_is_ps1 && time_to_check_mail ())
4606 reset_mail_timer ();
4609 /* Avoid printing a prompt if we're not going to read anything, e.g.
4610 after resetting the parser with read_token (RESET). */
4611 if (token_to_read == 0 && SHOULD_PROMPT ())
4615 two_tokens_ago = token_before_that;
4616 token_before_that = last_read_token;
4617 last_read_token = current_token;
4618 current_token = read_token (READ);
4620 if ((parser_state & PST_EOFTOKEN) && current_token == shell_eof_token)
4622 current_token = yacc_EOF;
4623 if (bash_input.type == st_string)
4624 rewind_input_string ();
4626 parser_state &= ~PST_EOFTOKEN;
4628 return (current_token);
4631 /* When non-zero, we have read the required tokens
4632 which allow ESAC to be the next one read. */
4633 static int esacs_needed_count;
4636 gather_here_documents ()
4641 while (need_here_doc)
4643 parser_state |= PST_HEREDOC;
4644 make_here_document (redir_stack[r++], line_number);
4645 parser_state &= ~PST_HEREDOC;
4650 /* When non-zero, an open-brace used to create a group is awaiting a close
4652 static int open_brace_count;
4654 #define command_token_position(token) \
4655 (((token) == ASSIGNMENT_WORD) || \
4656 ((token) != SEMI_SEMI && (token) != SEMI_AND && (token) != SEMI_SEMI_AND && reserved_word_acceptable(token)))
4658 #define assignment_acceptable(token) \
4659 (command_token_position(token) && ((parser_state & PST_CASEPAT) == 0))
4661 /* Check to see if TOKEN is a reserved word and return the token
4663 #define CHECK_FOR_RESERVED_WORD(tok) \
4665 if (!dollar_present && !quoted && \
4666 reserved_word_acceptable (last_read_token)) \
4669 for (i = 0; word_token_alist[i].word != (char *)NULL; i++) \
4670 if (STREQ (tok, word_token_alist[i].word)) \
4672 if ((parser_state & PST_CASEPAT) && (word_token_alist[i].token != ESAC)) \
4674 if (word_token_alist[i].token == TIME && time_command_acceptable () == 0) \
4676 if (word_token_alist[i].token == ESAC) \
4677 parser_state &= ~(PST_CASEPAT|PST_CASESTMT); \
4678 else if (word_token_alist[i].token == CASE) \
4679 parser_state |= PST_CASESTMT; \
4680 else if (word_token_alist[i].token == COND_END) \
4681 parser_state &= ~(PST_CONDCMD|PST_CONDEXPR); \
4682 else if (word_token_alist[i].token == COND_START) \
4683 parser_state |= PST_CONDCMD; \
4684 else if (word_token_alist[i].token == '{') \
4685 open_brace_count++; \
4686 else if (word_token_alist[i].token == '}' && open_brace_count) \
4687 open_brace_count--; \
4688 return (word_token_alist[i].token); \
4695 /* OK, we have a token. Let's try to alias expand it, if (and only if)
4698 It is eligible for expansion if EXPAND_ALIASES is set, and
4699 the token is unquoted and the last token read was a command
4700 separator (or expand_next_token is set), and we are currently
4701 processing an alias (pushed_string_list is non-empty) and this
4702 token is not the same as the current or any previously
4705 Special cases that disqualify:
4706 In a pattern list in a case statement (parser_state & PST_CASEPAT). */
4716 r = xmalloc (l + 2);
4725 alias_expand_token (tokstr)
4731 if (((parser_state & PST_ALEXPNEXT) || command_token_position (last_read_token)) &&
4732 (parser_state & PST_CASEPAT) == 0)
4734 ap = find_alias (tokstr);
4736 /* Currently expanding this token. */
4737 if (ap && (ap->flags & AL_BEINGEXPANDED))
4738 return (NO_EXPANSION);
4740 /* mk_alexpansion puts an extra space on the end of the alias expansion,
4741 so the lookahead by the parser works right. If this gets changed,
4742 make sure the code in shell_getc that deals with reaching the end of
4743 an expanded alias is changed with it. */
4744 expanded = ap ? mk_alexpansion (ap->value) : (char *)NULL;
4748 push_string (expanded, ap->flags & AL_EXPANDNEXT, ap);
4749 return (RE_READ_TOKEN);
4752 /* This is an eligible token that does not have an expansion. */
4753 return (NO_EXPANSION);
4755 return (NO_EXPANSION);
4760 time_command_acceptable ()
4762 #if defined (COMMAND_TIMING)
4763 switch (last_read_token)
4782 #endif /* COMMAND_TIMING */
4785 /* Handle special cases of token recognition:
4786 IN is recognized if the last token was WORD and the token
4787 before that was FOR or CASE or SELECT.
4789 DO is recognized if the last token was WORD and the token
4790 before that was FOR or SELECT.
4792 ESAC is recognized if the last token caused `esacs_needed_count'
4795 `{' is recognized if the last token as WORD and the token
4796 before that was FUNCTION, or if we just parsed an arithmetic
4799 `}' is recognized if there is an unclosed `{' present.
4801 `-p' is returned as TIMEOPT if the last read token was TIME.
4803 ']]' is returned as COND_END if the parser is currently parsing
4804 a conditional expression ((parser_state & PST_CONDEXPR) != 0)
4806 `time' is returned as TIME if and only if it is immediately
4807 preceded by one of `;', `\n', `||', `&&', or `&'.
4811 special_case_tokens (tokstr)
4814 if ((last_read_token == WORD) &&
4815 #if defined (SELECT_COMMAND)
4816 ((token_before_that == FOR) || (token_before_that == CASE) || (token_before_that == SELECT)) &&
4818 ((token_before_that == FOR) || (token_before_that == CASE)) &&
4820 (tokstr[0] == 'i' && tokstr[1] == 'n' && tokstr[2] == 0))
4822 if (token_before_that == CASE)
4824 parser_state |= PST_CASEPAT;
4825 esacs_needed_count++;
4830 if (last_read_token == WORD &&
4831 #if defined (SELECT_COMMAND)
4832 (token_before_that == FOR || token_before_that == SELECT) &&
4834 (token_before_that == FOR) &&
4836 (tokstr[0] == 'd' && tokstr[1] == 'o' && tokstr[2] == '\0'))
4839 /* Ditto for ESAC in the CASE case.
4840 Specifically, this handles "case word in esac", which is a legal
4841 construct, certainly because someone will pass an empty arg to the
4842 case construct, and we don't want it to barf. Of course, we should
4843 insist that the case construct has at least one pattern in it, but
4844 the designers disagree. */
4845 if (esacs_needed_count)
4847 esacs_needed_count--;
4848 if (STREQ (tokstr, "esac"))
4850 parser_state &= ~PST_CASEPAT;
4855 /* The start of a shell function definition. */
4856 if (parser_state & PST_ALLOWOPNBRC)
4858 parser_state &= ~PST_ALLOWOPNBRC;
4859 if (tokstr[0] == '{' && tokstr[1] == '\0') /* } */
4862 function_bstart = line_number;
4863 return ('{'); /* } */
4867 /* We allow a `do' after a for ((...)) without an intervening
4869 if (last_read_token == ARITH_FOR_EXPRS && tokstr[0] == 'd' && tokstr[1] == 'o' && !tokstr[2])
4871 if (last_read_token == ARITH_FOR_EXPRS && tokstr[0] == '{' && tokstr[1] == '\0') /* } */
4874 return ('{'); /* } */
4877 if (open_brace_count && reserved_word_acceptable (last_read_token) && tokstr[0] == '}' && !tokstr[1])
4879 open_brace_count--; /* { */
4883 #if defined (COMMAND_TIMING)
4884 /* Handle -p after `time'. */
4885 if (last_read_token == TIME && tokstr[0] == '-' && tokstr[1] == 'p' && !tokstr[2])
4890 #if defined (COMMAND_TIMING)
4891 if (STREQ (token, "time") && ((parser_state & PST_CASEPAT) == 0) && time_command_acceptable ())
4893 #endif /* COMMAND_TIMING */
4896 #if defined (COND_COMMAND) /* [[ */
4897 if ((parser_state & PST_CONDEXPR) && tokstr[0] == ']' && tokstr[1] == ']' && tokstr[2] == '\0')
4904 /* Called from shell.c when Control-C is typed at top level. Or
4905 by the error rule at top level. */
4909 dstack.delimiter_depth = 0; /* No delimiters found so far. */
4910 open_brace_count = 0;
4914 #if defined (ALIAS) || defined (DPAREN_ARITHMETIC)
4915 if (pushed_string_list)
4916 free_string_list ();
4917 #endif /* ALIAS || DPAREN_ARITHMETIC */
4919 if (shell_input_line)
4921 free (shell_input_line);
4922 shell_input_line = (char *)NULL;
4923 shell_input_line_size = shell_input_line_index = 0;
4926 FREE (word_desc_to_read);
4927 word_desc_to_read = (WORD_DESC *)NULL;
4929 last_read_token = '\n';
4930 token_to_read = '\n';
4933 /* Read the next token. Command can be READ (normal operation) or
4934 RESET (to normalize state). */
4936 read_token (command)
4939 int character; /* Current character. */
4940 int peek_char; /* Temporary look-ahead character. */
4941 int result; /* The thing to return. */
4943 if (command == RESET)
4951 result = token_to_read;
4952 if (token_to_read == WORD || token_to_read == ASSIGNMENT_WORD)
4954 yylval.word = word_desc_to_read;
4955 word_desc_to_read = (WORD_DESC *)NULL;
4961 #if defined (COND_COMMAND)
4962 if ((parser_state & (PST_CONDCMD|PST_CONDEXPR)) == PST_CONDCMD)
4964 cond_lineno = line_number;
4965 parser_state |= PST_CONDEXPR;
4966 yylval.command = parse_cond_command ();
4967 if (cond_token != COND_END)
4972 token_to_read = COND_END;
4973 parser_state &= ~(PST_CONDEXPR|PST_CONDCMD);
4979 /* This is a place to jump back to once we have successfully expanded a
4980 token with an alias and pushed the string with push_string () */
4984 /* Read a single word from input. Start by skipping blanks. */
4985 while ((character = shell_getc (1)) != EOF && shellblank (character))
4988 if (character == EOF)
4994 if MBTEST(character == '#' && (!interactive || interactive_comments))
4996 /* A comment. Discard until EOL or EOF, and then return a newline. */
4997 discard_until ('\n');
4999 character = '\n'; /* this will take the next if statement and return. */
5002 if (character == '\n')
5004 /* If we're about to return an unquoted newline, we can go and collect
5005 the text of any pending here document. */
5007 gather_here_documents ();
5010 parser_state &= ~PST_ALEXPNEXT;
5013 parser_state &= ~PST_ASSIGNOK;
5018 if (parser_state & PST_REGEXP)
5021 /* Shell meta-characters. */
5022 if MBTEST(shellmeta (character) && ((parser_state & PST_DBLPAREN) == 0))
5025 /* Turn off alias tokenization iff this character sequence would
5026 not leave us ready to read a command. */
5027 if (character == '<' || character == '>')
5028 parser_state &= ~PST_ALEXPNEXT;
5031 parser_state &= ~PST_ASSIGNOK;
5033 peek_char = shell_getc (1);
5034 if (character == peek_char)
5039 /* If '<' then we could be at "<<" or at "<<-". We have to
5040 look ahead one more character. */
5041 peek_char = shell_getc (1);
5042 if MBTEST(peek_char == '-')
5043 return (LESS_LESS_MINUS);
5044 else if MBTEST(peek_char == '<')
5045 return (LESS_LESS_LESS);
5048 shell_ungetc (peek_char);
5053 return (GREATER_GREATER);
5056 parser_state |= PST_CASEPAT;
5058 parser_state &= ~PST_ALEXPNEXT;
5061 peek_char = shell_getc (1);
5062 if MBTEST(peek_char == '&')
5063 return (SEMI_SEMI_AND);
5066 shell_ungetc (peek_char);
5076 #if defined (DPAREN_ARITHMETIC) || defined (ARITH_FOR_COMMAND)
5078 result = parse_dparen (character);
5086 else if MBTEST(character == '<' && peek_char == '&')
5088 else if MBTEST(character == '>' && peek_char == '&')
5089 return (GREATER_AND);
5090 else if MBTEST(character == '<' && peek_char == '>')
5091 return (LESS_GREATER);
5092 else if MBTEST(character == '>' && peek_char == '|')
5093 return (GREATER_BAR);
5094 else if MBTEST(character == '&' && peek_char == '>')
5096 peek_char = shell_getc (1);
5097 if MBTEST(peek_char == '>')
5098 return (AND_GREATER_GREATER);
5101 shell_ungetc (peek_char);
5102 return (AND_GREATER);
5105 else if MBTEST(character == '|' && peek_char == '&')
5107 else if MBTEST(character == ';' && peek_char == '&')
5109 parser_state |= PST_CASEPAT;
5111 parser_state &= ~PST_ALEXPNEXT;
5116 shell_ungetc (peek_char);
5118 /* If we look like we are reading the start of a function
5119 definition, then let the reader know about it so that
5120 we will do the right thing with `{'. */
5121 if MBTEST(character == ')' && last_read_token == '(' && token_before_that == WORD)
5123 parser_state |= PST_ALLOWOPNBRC;
5125 parser_state &= ~PST_ALEXPNEXT;
5127 function_dstart = line_number;
5130 /* case pattern lists may be preceded by an optional left paren. If
5131 we're not trying to parse a case pattern list, the left paren
5132 indicates a subshell. */
5133 if MBTEST(character == '(' && (parser_state & PST_CASEPAT) == 0) /* ) */
5134 parser_state |= PST_SUBSHELL;
5136 else if MBTEST((parser_state & PST_CASEPAT) && character == ')')
5137 parser_state &= ~PST_CASEPAT;
5139 else if MBTEST((parser_state & PST_SUBSHELL) && character == ')')
5140 parser_state &= ~PST_SUBSHELL;
5142 #if defined (PROCESS_SUBSTITUTION)
5143 /* Check for the constructs which introduce process substitution.
5144 Shells running in `posix mode' don't do process substitution. */
5145 if MBTEST(posixly_correct || ((character != '>' && character != '<') || peek_char != '(')) /*)*/
5146 #endif /* PROCESS_SUBSTITUTION */
5150 /* Hack <&- (close stdin) case. Also <&N- (dup and close). */
5151 if MBTEST(character == '-' && (last_read_token == LESS_AND || last_read_token == GREATER_AND))
5155 /* Okay, if we got this far, we have to read a word. Read one,
5156 and then check it against the known ones. */
5157 result = read_token_word (character);
5159 if (result == RE_READ_TOKEN)
5166 * Match a $(...) or other grouping construct. This has to handle embedded
5167 * quoted strings ('', ``, "") and nested constructs. It also must handle
5168 * reprompting the user, if necessary, after reading a newline, and returning
5169 * correct error values if it reads EOF.
5171 #define P_FIRSTCLOSE 0x01
5172 #define P_ALLOWESC 0x02
5173 #define P_DQUOTE 0x04
5174 #define P_COMMAND 0x08 /* parsing a command, so look for comments */
5175 #define P_BACKQUOTE 0x10 /* parsing a backquoted command substitution */
5177 /* Lexical state while parsing a grouping construct or $(...). */
5178 #define LEX_WASDOL 0x001
5179 #define LEX_CKCOMMENT 0x002
5180 #define LEX_INCOMMENT 0x004
5181 #define LEX_PASSNEXT 0x008
5182 #define LEX_RESWDOK 0x010
5183 #define LEX_CKCASE 0x020
5184 #define LEX_INCASE 0x040
5185 #define LEX_INHEREDOC 0x080
5186 #define LEX_HEREDELIM 0x100 /* reading here-doc delimiter */
5187 #define LEX_STRIPDOC 0x200 /* <<- strip tabs from here doc delim */
5189 #define COMSUB_META(ch) ((ch) == ';' || (ch) == '&' || (ch) == '|')
5191 #define CHECK_NESTRET_ERROR() \
5193 if (nestret == &matched_pair_error) \
5196 return &matched_pair_error; \
5200 #define APPEND_NESTRET() \
5204 RESIZE_MALLOCED_BUFFER (ret, retind, nestlen, retsize, 64); \
5205 strcpy (ret + retind, nestret); \
5206 retind += nestlen; \
5210 static char matched_pair_error;
5213 parse_matched_pair (qc, open, close, lenp, flags)
5214 int qc; /* `"' if this construct is within double quotes */
5218 int count, ch, tflags;
5219 int nestlen, ttranslen, start_lineno;
5220 char *ret, *nestret, *ttrans;
5221 int retind, retsize, rflags;
5223 /* itrace("parse_matched_pair: open = %c close = %c flags = %d", open, close, flags); */
5227 if ((flags & P_COMMAND) && qc != '`' && qc != '\'' && qc != '"' && (flags & P_DQUOTE) == 0)
5228 tflags |= LEX_CKCOMMENT;
5230 /* RFLAGS is the set of flags we want to pass to recursive calls. */
5231 rflags = (qc == '"') ? P_DQUOTE : (flags & P_DQUOTE);
5233 ret = (char *)xmalloc (retsize = 64);
5236 start_lineno = line_number;
5239 ch = shell_getc (qc != '\'' && (tflags & LEX_PASSNEXT) == 0);
5244 parser_error (start_lineno, _("unexpected EOF while looking for matching `%c'"), close);
5245 EOF_Reached = 1; /* XXX */
5246 return (&matched_pair_error);
5249 /* Possible reprompting. */
5250 if (ch == '\n' && SHOULD_PROMPT ())
5253 /* Don't bother counting parens or doing anything else if in a comment
5254 or part of a case statement */
5255 if (tflags & LEX_INCOMMENT)
5257 /* Add this character. */
5258 RESIZE_MALLOCED_BUFFER (ret, retind, 1, retsize, 64);
5262 tflags &= ~LEX_INCOMMENT;
5267 /* Not exactly right yet, should handle shell metacharacters, too. If
5268 any changes are made to this test, make analogous changes to subst.c:
5269 extract_delimited_string(). */
5270 else if MBTEST((tflags & LEX_CKCOMMENT) && (tflags & LEX_INCOMMENT) == 0 && ch == '#' && (retind == 0 || ret[retind-1] == '\n' || shellblank (ret[retind - 1])))
5271 tflags |= LEX_INCOMMENT;
5273 if (tflags & LEX_PASSNEXT) /* last char was backslash */
5275 tflags &= ~LEX_PASSNEXT;
5276 if (qc != '\'' && ch == '\n') /* double-quoted \<newline> disappears. */
5279 retind--; /* swallow previously-added backslash */
5283 RESIZE_MALLOCED_BUFFER (ret, retind, 2, retsize, 64);
5284 if MBTEST(ch == CTLESC || ch == CTLNUL)
5285 ret[retind++] = CTLESC;
5289 /* If we're reparsing the input (e.g., from parse_string_to_word_list),
5290 we've already prepended CTLESC to single-quoted results of $'...'.
5291 We may want to do this for other CTLESC-quoted characters in
5293 else if MBTEST((parser_state & PST_REPARSE) && open == '\'' && (ch == CTLESC || ch == CTLNUL))
5295 RESIZE_MALLOCED_BUFFER (ret, retind, 1, retsize, 64);
5299 else if MBTEST(ch == CTLESC || ch == CTLNUL) /* special shell escapes */
5301 RESIZE_MALLOCED_BUFFER (ret, retind, 2, retsize, 64);
5302 ret[retind++] = CTLESC;
5306 else if MBTEST(ch == close) /* ending delimiter */
5308 /* handle nested ${...} specially. */
5309 else if MBTEST(open != close && (tflags & LEX_WASDOL) && open == '{' && ch == open) /* } */
5311 else if MBTEST(((flags & P_FIRSTCLOSE) == 0) && ch == open) /* nested begin */
5314 /* Add this character. */
5315 RESIZE_MALLOCED_BUFFER (ret, retind, 1, retsize, 64);
5318 /* If we just read the ending character, don't bother continuing. */
5322 if (open == '\'') /* '' inside grouping construct */
5324 if MBTEST((flags & P_ALLOWESC) && ch == '\\')
5325 tflags |= LEX_PASSNEXT;
5329 if MBTEST(ch == '\\') /* backslashes */
5330 tflags |= LEX_PASSNEXT;
5333 /* The big hammer. Single quotes aren't special in double quotes. The
5334 problem is that Posix says the single quotes are semi-special:
5335 within a double-quoted ${...} construct "an even number of
5336 unescaped double-quotes or single-quotes, if any, shall occur." */
5337 if MBTEST(open == '{' && (flags & P_DQUOTE) && ch == '\'') /* } */
5341 /* Could also check open == '`' if we want to parse grouping constructs
5342 inside old-style command substitution. */
5343 if (open != close) /* a grouping construct */
5345 if MBTEST(shellquote (ch))
5347 /* '', ``, or "" inside $(...) or other grouping construct. */
5348 push_delimiter (dstack, ch);
5349 if MBTEST((tflags & LEX_WASDOL) && ch == '\'') /* $'...' inside group */
5350 nestret = parse_matched_pair (ch, ch, ch, &nestlen, P_ALLOWESC|rflags);
5352 nestret = parse_matched_pair (ch, ch, ch, &nestlen, rflags);
5353 pop_delimiter (dstack);
5354 CHECK_NESTRET_ERROR ();
5356 if MBTEST((tflags & LEX_WASDOL) && ch == '\'' && (extended_quote || (rflags & P_DQUOTE) == 0))
5358 /* Translate $'...' here. */
5359 ttrans = ansiexpand (nestret, 0, nestlen - 1, &ttranslen);
5362 if ((rflags & P_DQUOTE) == 0)
5364 nestret = sh_single_quote (ttrans);
5366 nestlen = strlen (nestret);
5371 nestlen = ttranslen;
5373 retind -= 2; /* back up before the $' */
5375 else if MBTEST((tflags & LEX_WASDOL) && ch == '"' && (extended_quote || (rflags & P_DQUOTE) == 0))
5377 /* Locale expand $"..." here. */
5378 ttrans = localeexpand (nestret, 0, nestlen - 1, start_lineno, &ttranslen);
5381 nestret = sh_mkdoublequoted (ttrans, ttranslen, 0);
5383 nestlen = ttranslen + 2;
5384 retind -= 2; /* back up before the $" */
5391 /* Parse an old-style command substitution within double quotes as a
5393 /* XXX - sh and ksh93 don't do this - XXX */
5394 else if MBTEST(open == '"' && ch == '`')
5396 nestret = parse_matched_pair (0, '`', '`', &nestlen, rflags);
5398 CHECK_NESTRET_ERROR ();
5403 else if MBTEST(open != '`' && (tflags & LEX_WASDOL) && (ch == '(' || ch == '{' || ch == '[')) /* ) } ] */
5404 /* check for $(), $[], or ${} inside quoted string. */
5406 if (open == ch) /* undo previous increment */
5408 if (ch == '(') /* ) */
5409 nestret = parse_comsub (0, '(', ')', &nestlen, (rflags|P_COMMAND) & ~P_DQUOTE);
5410 else if (ch == '{') /* } */
5411 nestret = parse_matched_pair (0, '{', '}', &nestlen, P_FIRSTCLOSE|rflags);
5412 else if (ch == '[') /* ] */
5413 nestret = parse_matched_pair (0, '[', ']', &nestlen, rflags);
5415 CHECK_NESTRET_ERROR ();
5420 if MBTEST(ch == '$')
5421 tflags |= LEX_WASDOL;
5423 tflags &= ~LEX_WASDOL;
5432 /* Parse a $(...) command substitution. This is messier than I'd like, and
5433 reproduces a lot more of the token-reading code than I'd like. */
5435 parse_comsub (qc, open, close, lenp, flags)
5436 int qc; /* `"' if this construct is within double quotes */
5440 int count, ch, peekc, tflags, lex_rwlen, lex_firstind;
5441 int nestlen, ttranslen, start_lineno;
5442 char *ret, *nestret, *ttrans, *heredelim;
5443 int retind, retsize, rflags, hdlen;
5445 /*itrace("parse_comsub: qc = `%c' open = %c close = %c", qc, open, close);*/
5447 tflags = LEX_RESWDOK;
5449 if ((flags & P_COMMAND) && qc != '\'' && qc != '"' && (flags & P_DQUOTE) == 0)
5450 tflags |= LEX_CKCASE;
5451 if ((tflags & LEX_CKCASE) && (interactive == 0 || interactive_comments))
5452 tflags |= LEX_CKCOMMENT;
5454 /* RFLAGS is the set of flags we want to pass to recursive calls. */
5455 rflags = (flags & P_DQUOTE);
5457 ret = (char *)xmalloc (retsize = 64);
5460 start_lineno = line_number;
5469 ch = shell_getc (qc != '\'' && (tflags & LEX_PASSNEXT) == 0);
5476 parser_error (start_lineno, _("unexpected EOF while looking for matching `%c'"), close);
5477 EOF_Reached = 1; /* XXX */
5478 return (&matched_pair_error);
5481 /* If we hit the end of a line and are reading the contents of a here
5482 document, and it's not the same line that the document starts on,
5483 check for this line being the here doc delimiter. Otherwise, if
5484 we're in a here document, mark the next character as the beginning
5488 if ((tflags & LEX_HEREDELIM) && heredelim)
5490 tflags &= ~LEX_HEREDELIM;
5491 tflags |= LEX_INHEREDOC;
5492 lex_firstind = retind + 1;
5494 else if (tflags & LEX_INHEREDOC)
5497 tind = lex_firstind;
5498 while ((tflags & LEX_STRIPDOC) && ret[tind] == '\t')
5500 if (STREQN (ret + tind, heredelim, hdlen))
5502 tflags &= ~(LEX_STRIPDOC|LEX_INHEREDOC);
5503 /*itrace("parse_comsub:%d: found here doc end `%s'", line_number, ret + tind);*/
5507 lex_firstind = retind + 1;
5511 /* Possible reprompting. */
5512 if (ch == '\n' && SHOULD_PROMPT ())
5515 /* Don't bother counting parens or doing anything else if in a comment */
5516 if (tflags & (LEX_INCOMMENT|LEX_INHEREDOC))
5518 /* Add this character. */
5519 RESIZE_MALLOCED_BUFFER (ret, retind, 1, retsize, 64);
5522 if ((tflags & LEX_INCOMMENT) && ch == '\n')
5523 tflags &= ~LEX_INCOMMENT;
5528 /* Skip whitespace */
5529 if MBTEST(shellblank (ch) && lex_rwlen == 0)
5531 /* Add this character. */
5532 RESIZE_MALLOCED_BUFFER (ret, retind, 1, retsize, 64);
5537 /* Either we are looking for the start of the here-doc delimiter
5538 (lex_firstind == -1) or we are reading one (lex_firstind >= 0).
5539 If this character is a shell break character and we are reading
5540 the delimiter, save it and note that we are now reading a here
5541 document. If we've found the start of the delimiter, note it by
5542 setting lex_firstind. Backslashes can quote shell metacharacters
5543 in here-doc delimiters. */
5544 if (tflags & LEX_HEREDELIM)
5546 if (lex_firstind == -1 && shellbreak (ch) == 0)
5547 lex_firstind = retind;
5548 else if (lex_firstind >= 0 && (tflags & LEX_PASSNEXT) == 0 && shellbreak (ch))
5550 nestret = substring (ret, lex_firstind, retind);
5551 heredelim = string_quote_removal (nestret, 0);
5553 hdlen = STRLEN(heredelim);
5554 /*itrace("parse_comsub:%d: found here doc delimiter `%s' (%d)", line_number, heredelim, hdlen);*/
5557 tflags |= LEX_INHEREDOC;
5558 tflags &= ~LEX_HEREDELIM;
5559 lex_firstind = retind + 1;
5566 /* Meta-characters that can introduce a reserved word. Not perfect yet. */
5567 if MBTEST((tflags & LEX_RESWDOK) == 0 && (tflags & LEX_CKCASE) && (tflags & LEX_INCOMMENT) == 0 && shellmeta(ch))
5569 /* Add this character. */
5570 RESIZE_MALLOCED_BUFFER (ret, retind, 1, retsize, 64);
5572 peekc = shell_getc (1);
5573 if (ch == peekc && (ch == '&' || ch == '|' || ch == ';')) /* two-character tokens */
5575 RESIZE_MALLOCED_BUFFER (ret, retind, 1, retsize, 64);
5576 ret[retind++] = peekc;
5577 /*itrace("parse_comsub:%d: set lex_reswordok = 1, ch = `%c'", line_number, ch); */
5578 tflags |= LEX_RESWDOK;
5582 else if (ch == '\n' || COMSUB_META(ch))
5584 shell_ungetc (peekc);
5585 tflags |= LEX_RESWDOK;
5586 /*itrace("parse_comsub:%d: set lex_reswordok = 1, ch = `%c'", line_number, ch);*/
5594 /* `unget' the character we just added and fall through */
5596 shell_ungetc (peekc);
5600 /* If we can read a reserved word, try to read one. */
5601 if (tflags & LEX_RESWDOK)
5603 if MBTEST(islower (ch))
5605 /* Add this character. */
5606 RESIZE_MALLOCED_BUFFER (ret, retind, 1, retsize, 64);
5611 else if MBTEST(lex_rwlen == 4 && shellbreak (ch))
5613 if (STREQN (ret + retind - 4, "case", 4))
5615 tflags |= LEX_INCASE;
5616 /*itrace("parse_comsub:%d: found `case', lex_incase -> 1", line_number);*/
5618 else if (STREQN (ret + retind - 4, "esac", 4))
5620 tflags &= ~LEX_INCASE;
5621 /*itrace("parse_comsub:%d: found `esac', lex_incase -> 0", line_number);*/
5623 tflags &= ~LEX_RESWDOK;
5625 else if (shellbreak (ch) == 0)
5627 tflags &= ~LEX_RESWDOK;
5628 /*itrace("parse_comsub:%d: found `%c', lex_reswordok -> 0", line_number, ch);*/
5632 if MBTEST((tflags & LEX_INCOMMENT) == 0 && (tflags & LEX_CKCASE) && ch == '<')
5634 /* Add this character. */
5635 RESIZE_MALLOCED_BUFFER (ret, retind, 1, retsize, 64);
5637 peekc = shell_getc (1);
5642 RESIZE_MALLOCED_BUFFER (ret, retind, 1, retsize, 64);
5643 ret[retind++] = peekc;
5644 peekc = shell_getc (1);
5649 RESIZE_MALLOCED_BUFFER (ret, retind, 1, retsize, 64);
5650 ret[retind++] = peekc;
5651 tflags |= LEX_STRIPDOC;
5654 shell_ungetc (peekc);
5655 tflags |= LEX_HEREDELIM;
5660 ch = peekc; /* fall through and continue XXX - this skips comments if peekc == '#' */
5662 /* Not exactly right yet, should handle shell metacharacters, too. If
5663 any changes are made to this test, make analogous changes to subst.c:
5664 extract_delimited_string(). */
5665 else if MBTEST((tflags & LEX_CKCOMMENT) && (tflags & LEX_INCOMMENT) == 0 && ch == '#' && (retind == 0 || ret[retind-1] == '\n' || shellblank (ret[retind - 1])))
5666 tflags |= LEX_INCOMMENT;
5668 if (tflags & LEX_PASSNEXT) /* last char was backslash */
5670 tflags &= ~LEX_PASSNEXT;
5671 if (qc != '\'' && ch == '\n') /* double-quoted \<newline> disappears. */
5674 retind--; /* swallow previously-added backslash */
5678 RESIZE_MALLOCED_BUFFER (ret, retind, 2, retsize, 64);
5679 if MBTEST(ch == CTLESC || ch == CTLNUL)
5680 ret[retind++] = CTLESC;
5684 else if MBTEST(ch == CTLESC || ch == CTLNUL) /* special shell escapes */
5686 RESIZE_MALLOCED_BUFFER (ret, retind, 2, retsize, 64);
5687 ret[retind++] = CTLESC;
5692 else if MBTEST((tflags & LEX_INCASE) && ch == close && close == ')')
5693 tflags &= ~LEX_INCASE; /* XXX */
5695 else if MBTEST(ch == close && (tflags & LEX_INCASE) == 0) /* ending delimiter */
5698 /*itrace("parse_comsub:%d: found close: count = %d", line_number, count);*/
5700 else if MBTEST(((flags & P_FIRSTCLOSE) == 0) && (tflags & LEX_INCASE) == 0 && ch == open) /* nested begin */
5703 /* Add this character. */
5704 RESIZE_MALLOCED_BUFFER (ret, retind, 1, retsize, 64);
5707 /* If we just read the ending character, don't bother continuing. */
5711 if MBTEST(ch == '\\') /* backslashes */
5712 tflags |= LEX_PASSNEXT;
5714 if MBTEST(shellquote (ch))
5716 /* '', ``, or "" inside $(...). */
5717 push_delimiter (dstack, ch);
5718 if MBTEST((tflags & LEX_WASDOL) && ch == '\'') /* $'...' inside group */
5719 nestret = parse_matched_pair (ch, ch, ch, &nestlen, P_ALLOWESC|rflags);
5721 nestret = parse_matched_pair (ch, ch, ch, &nestlen, rflags);
5722 pop_delimiter (dstack);
5723 CHECK_NESTRET_ERROR ();
5725 if MBTEST((tflags & LEX_WASDOL) && ch == '\'' && (extended_quote || (rflags & P_DQUOTE) == 0))
5727 /* Translate $'...' here. */
5728 ttrans = ansiexpand (nestret, 0, nestlen - 1, &ttranslen);
5731 if ((rflags & P_DQUOTE) == 0)
5733 nestret = sh_single_quote (ttrans);
5735 nestlen = strlen (nestret);
5740 nestlen = ttranslen;
5742 retind -= 2; /* back up before the $' */
5744 else if MBTEST((tflags & LEX_WASDOL) && ch == '"' && (extended_quote || (rflags & P_DQUOTE) == 0))
5746 /* Locale expand $"..." here. */
5747 ttrans = localeexpand (nestret, 0, nestlen - 1, start_lineno, &ttranslen);
5750 nestret = sh_mkdoublequoted (ttrans, ttranslen, 0);
5752 nestlen = ttranslen + 2;
5753 retind -= 2; /* back up before the $" */
5759 else if MBTEST((tflags & LEX_WASDOL) && (ch == '(' || ch == '{' || ch == '[')) /* ) } ] */
5760 /* check for $(), $[], or ${} inside command substitution. */
5762 if ((tflags & LEX_INCASE) == 0 && open == ch) /* undo previous increment */
5764 if (ch == '(') /* ) */
5765 nestret = parse_comsub (0, '(', ')', &nestlen, (rflags|P_COMMAND) & ~P_DQUOTE);
5766 else if (ch == '{') /* } */
5767 nestret = parse_matched_pair (0, '{', '}', &nestlen, P_FIRSTCLOSE|rflags);
5768 else if (ch == '[') /* ] */
5769 nestret = parse_matched_pair (0, '[', ']', &nestlen, rflags);
5771 CHECK_NESTRET_ERROR ();
5776 if MBTEST(ch == '$')
5777 tflags |= LEX_WASDOL;
5779 tflags &= ~LEX_WASDOL;
5786 /*itrace("parse_comsub:%d: returning `%s'", line_number, ret);*/
5790 /* XXX - this needs to handle functionality like subst.c:no_longjmp_on_fatal_error;
5791 maybe extract_command_subst should handle it. */
5793 xparse_dolparen (base, string, indp, flags)
5799 sh_parser_state_t ps;
5800 int orig_ind, nc, sflags;
5801 char *ret, *s, *ep, *ostring;
5807 sflags = SEVAL_NONINT|SEVAL_NOHIST|SEVAL_NOFREE;
5808 if (flags & SX_NOLONGJMP)
5809 sflags |= SEVAL_NOLONGJMP;
5810 save_parser_state (&ps);
5813 parser_state |= PST_CMDSUBST|PST_EOFTOKEN; /* allow instant ')' */ /*(*/
5814 shell_eof_token = ')';
5815 parse_string (string, "command substitution", sflags, &ep);
5817 restore_parser_state (&ps);
5822 /* Need to find how many characters parse_and_execute consumed, update
5823 *indp, if flags != 0, copy the portion of the string parsed into RET
5824 and return it. If flags & 1 (EX_NOALLOC) we can return NULL. */
5831 itrace("xparse_dolparen:%d: ep[-1] != RPAREN (%d), ep = `%s'", line_number, ep[-1], ep);
5833 while (ep > ostring && ep[-1] == '\n') ep--;
5837 *indp = ep - base - 1;
5841 if (base[*indp] != ')')
5842 itrace("xparse_dolparen:%d: base[%d] != RPAREN (%d), base = `%s'", line_number, *indp, base[*indp], base);
5845 if (flags & SX_NOALLOC)
5846 return (char *)NULL;
5854 ret = substring (ostring, 0, nc - 1);
5859 #if defined (DPAREN_ARITHMETIC) || defined (ARITH_FOR_COMMAND)
5860 /* Parse a double-paren construct. It can be either an arithmetic
5861 command, an arithmetic `for' command, or a nested subshell. Returns
5862 the parsed token, -1 on error, or -2 if we didn't do anything and
5863 should just go on. */
5872 #if defined (ARITH_FOR_COMMAND)
5873 if (last_read_token == FOR)
5875 arith_for_lineno = line_number;
5876 cmdtyp = parse_arith_cmd (&wval, 0);
5879 wd = alloc_word_desc ();
5881 yylval.word_list = make_word_list (wd, (WORD_LIST *)NULL);
5882 return (ARITH_FOR_EXPRS);
5885 return -1; /* ERROR */
5889 #if defined (DPAREN_ARITHMETIC)
5890 if (reserved_word_acceptable (last_read_token))
5892 sline = line_number;
5894 cmdtyp = parse_arith_cmd (&wval, 0);
5895 if (cmdtyp == 1) /* arithmetic command */
5897 wd = alloc_word_desc ();
5899 wd->flags = W_QUOTED|W_NOSPLIT|W_NOGLOB|W_DQUOTE;
5900 yylval.word_list = make_word_list (wd, (WORD_LIST *)NULL);
5903 else if (cmdtyp == 0) /* nested subshell */
5905 push_string (wval, 0, (alias_t *)NULL);
5906 if ((parser_state & PST_CASEPAT) == 0)
5907 parser_state |= PST_SUBSHELL;
5915 return -2; /* XXX */
5918 /* We've seen a `(('. Look for the matching `))'. If we get it, return 1.
5919 If not, assume it's a nested subshell for backwards compatibility and
5920 return 0. In any case, put the characters we've consumed into a locally-
5921 allocated buffer and make *ep point to that buffer. Return -1 on an
5922 error, for example EOF. */
5924 parse_arith_cmd (ep, adddq)
5928 int exp_lineno, rval, c;
5929 char *ttok, *tokstr;
5932 exp_lineno = line_number;
5933 ttok = parse_matched_pair (0, '(', ')', &ttoklen, 0);
5935 if (ttok == &matched_pair_error)
5937 /* Check that the next character is the closing right paren. If
5938 not, this is a syntax error. ( */
5943 tokstr = (char *)xmalloc (ttoklen + 4);
5945 /* if ADDDQ != 0 then (( ... )) -> "..." */
5946 if (rval == 1 && adddq) /* arith cmd, add double quotes */
5949 strncpy (tokstr + 1, ttok, ttoklen - 1);
5950 tokstr[ttoklen] = '"';
5951 tokstr[ttoklen+1] = '\0';
5953 else if (rval == 1) /* arith cmd, don't add double quotes */
5955 strncpy (tokstr, ttok, ttoklen - 1);
5956 tokstr[ttoklen-1] = '\0';
5958 else /* nested subshell */
5961 strncpy (tokstr + 1, ttok, ttoklen - 1);
5962 tokstr[ttoklen] = ')';
5963 tokstr[ttoklen+1] = c;
5964 tokstr[ttoklen+2] = '\0';
5971 #endif /* DPAREN_ARITHMETIC || ARITH_FOR_COMMAND */
5973 #if defined (COND_COMMAND)
5979 if (EOF_Reached && cond_token != COND_ERROR) /* [[ */
5980 parser_error (cond_lineno, _("unexpected EOF while looking for `]]'"));
5981 else if (cond_token != COND_ERROR)
5983 if (etext = error_token_from_token (cond_token))
5985 parser_error (cond_lineno, _("syntax error in conditional expression: unexpected token `%s'"), etext);
5989 parser_error (cond_lineno, _("syntax error in conditional expression"));
5996 return (cond_or ());
6005 if (cond_token == OR_OR)
6008 l = make_cond_node (COND_OR, (WORD_DESC *)NULL, l, r);
6019 if (cond_token == AND_AND)
6022 l = make_cond_node (COND_AND, (WORD_DESC *)NULL, l, r);
6028 cond_skip_newlines ()
6030 while ((cond_token = read_token (READ)) == '\n')
6032 if (SHOULD_PROMPT ())
6035 return (cond_token);
6038 #define COND_RETURN_ERROR() \
6039 do { cond_token = COND_ERROR; return ((COND_COM *)NULL); } while (0)
6045 COND_COM *term, *tleft, *tright;
6049 /* Read a token. It can be a left paren, a `!', a unary operator, or a
6050 word that should be the first argument of a binary operator. Start by
6051 skipping newlines, since this is a compound command. */
6052 tok = cond_skip_newlines ();
6053 lineno = line_number;
6054 if (tok == COND_END)
6056 COND_RETURN_ERROR ();
6058 else if (tok == '(')
6060 term = cond_expr ();
6061 if (cond_token != ')')
6064 dispose_cond_node (term); /* ( */
6065 if (etext = error_token_from_token (cond_token))
6067 parser_error (lineno, _("unexpected token `%s', expected `)'"), etext);
6071 parser_error (lineno, _("expected `)'"));
6072 COND_RETURN_ERROR ();
6074 term = make_cond_node (COND_EXPR, (WORD_DESC *)NULL, term, (COND_COM *)NULL);
6075 (void)cond_skip_newlines ();
6077 else if (tok == BANG || (tok == WORD && (yylval.word->word[0] == '!' && yylval.word->word[1] == '\0')))
6080 dispose_word (yylval.word); /* not needed */
6081 term = cond_term ();
6083 term->flags |= CMD_INVERT_RETURN;
6085 else if (tok == WORD && yylval.word->word[0] == '-' && yylval.word->word[2] == 0 && test_unop (yylval.word->word))
6088 tok = read_token (READ);
6091 tleft = make_cond_node (COND_TERM, yylval.word, (COND_COM *)NULL, (COND_COM *)NULL);
6092 term = make_cond_node (COND_UNARY, op, tleft, (COND_COM *)NULL);
6097 if (etext = error_token_from_token (tok))
6099 parser_error (line_number, _("unexpected argument `%s' to conditional unary operator"), etext);
6103 parser_error (line_number, _("unexpected argument to conditional unary operator"));
6104 COND_RETURN_ERROR ();
6107 (void)cond_skip_newlines ();
6109 else if (tok == WORD) /* left argument to binary operator */
6112 tleft = make_cond_node (COND_TERM, yylval.word, (COND_COM *)NULL, (COND_COM *)NULL);
6115 tok = read_token (READ);
6116 if (tok == WORD && test_binop (yylval.word->word))
6118 #if defined (COND_REGEXP)
6119 else if (tok == WORD && STREQ (yylval.word->word, "=~"))
6122 parser_state |= PST_REGEXP;
6125 else if (tok == '<' || tok == '>')
6126 op = make_word_from_token (tok); /* ( */
6127 /* There should be a check before blindly accepting the `)' that we have
6128 seen the opening `('. */
6129 else if (tok == COND_END || tok == AND_AND || tok == OR_OR || tok == ')')
6131 /* Special case. [[ x ]] is equivalent to [[ -n x ]], just like
6132 the test command. Similarly for [[ x && expr ]] or
6133 [[ x || expr ]] or [[ (x) ]]. */
6134 op = make_word ("-n");
6135 term = make_cond_node (COND_UNARY, op, tleft, (COND_COM *)NULL);
6141 if (etext = error_token_from_token (tok))
6143 parser_error (line_number, _("unexpected token `%s', conditional binary operator expected"), etext);
6147 parser_error (line_number, _("conditional binary operator expected"));
6148 dispose_cond_node (tleft);
6149 COND_RETURN_ERROR ();
6153 tok = read_token (READ);
6154 parser_state &= ~PST_REGEXP;
6157 tright = make_cond_node (COND_TERM, yylval.word, (COND_COM *)NULL, (COND_COM *)NULL);
6158 term = make_cond_node (COND_BINARY, op, tleft, tright);
6162 if (etext = error_token_from_token (tok))
6164 parser_error (line_number, _("unexpected argument `%s' to conditional binary operator"), etext);
6168 parser_error (line_number, _("unexpected argument to conditional binary operator"));
6169 dispose_cond_node (tleft);
6171 COND_RETURN_ERROR ();
6174 (void)cond_skip_newlines ();
6179 parser_error (line_number, _("unexpected token `%c' in conditional command"), tok);
6180 else if (etext = error_token_from_token (tok))
6182 parser_error (line_number, _("unexpected token `%s' in conditional command"), etext);
6186 parser_error (line_number, _("unexpected token %d in conditional command"), tok);
6187 COND_RETURN_ERROR ();
6192 /* This is kind of bogus -- we slip a mini recursive-descent parser in
6193 here to handle the conditional statement syntax. */
6195 parse_cond_command ()
6199 cexp = cond_expr ();
6200 return (make_cond_command (cexp));
6204 #if defined (ARRAY_VARS)
6205 /* When this is called, it's guaranteed that we don't care about anything
6206 in t beyond i. We do save and restore the chars, though. */
6208 token_is_assignment (t, i)
6212 unsigned char c, c1;
6215 c = t[i]; c1 = t[i+1];
6216 t[i] = '='; t[i+1] = '\0';
6217 r = assignment (t, (parser_state & PST_COMPASSIGN) != 0);
6218 t[i] = c; t[i+1] = c1;
6222 /* XXX - possible changes here for `+=' */
6224 token_is_ident (t, i)
6233 r = legal_identifier (t);
6240 read_token_word (character)
6243 /* The value for YYLVAL when a WORD is read. */
6244 WORD_DESC *the_word;
6246 /* Index into the token that we are building. */
6249 /* ALL_DIGITS becomes zero when we see a non-digit. */
6250 int all_digit_token;
6252 /* DOLLAR_PRESENT becomes non-zero if we see a `$'. */
6255 /* COMPOUND_ASSIGNMENT becomes non-zero if we are parsing a compound
6257 int compound_assignment;
6259 /* QUOTED becomes non-zero if we see one of ("), ('), (`), or (\). */
6262 /* Non-zero means to ignore the value of the next character, and just
6263 to add it no matter what. */
6264 int pass_next_character;
6266 /* The current delimiting character. */
6268 int result, peek_char;
6269 char *ttok, *ttrans;
6270 int ttoklen, ttranslen;
6273 if (token_buffer_size < TOKEN_DEFAULT_INITIAL_SIZE)
6274 token = (char *)xrealloc (token, token_buffer_size = TOKEN_DEFAULT_INITIAL_SIZE);
6277 all_digit_token = DIGIT (character);
6278 dollar_present = quoted = pass_next_character = compound_assignment = 0;
6282 if (character == EOF)
6285 if (pass_next_character)
6287 pass_next_character = 0;
6288 goto got_escaped_character;
6291 cd = current_delimiter (dstack);
6293 /* Handle backslashes. Quote lots of things when not inside of
6294 double-quotes, quote some things inside of double-quotes. */
6295 if MBTEST(character == '\\')
6297 peek_char = shell_getc (0);
6299 /* Backslash-newline is ignored in all cases except
6300 when quoted with single quotes. */
6301 if (peek_char == '\n')
6304 goto next_character;
6308 shell_ungetc (peek_char);
6310 /* If the next character is to be quoted, note it now. */
6311 if (cd == 0 || cd == '`' ||
6312 (cd == '"' && peek_char >= 0 && (sh_syntaxtab[peek_char] & CBSDQUOTE)))
6313 pass_next_character++;
6320 /* Parse a matched pair of quote characters. */
6321 if MBTEST(shellquote (character))
6323 push_delimiter (dstack, character);
6324 ttok = parse_matched_pair (character, character, character, &ttoklen, (character == '`') ? P_COMMAND : 0);
6325 pop_delimiter (dstack);
6326 if (ttok == &matched_pair_error)
6327 return -1; /* Bail immediately. */
6328 RESIZE_MALLOCED_BUFFER (token, token_index, ttoklen + 2,
6329 token_buffer_size, TOKEN_DEFAULT_GROW_SIZE);
6330 token[token_index++] = character;
6331 strcpy (token + token_index, ttok);
6332 token_index += ttoklen;
6333 all_digit_token = 0;
6335 dollar_present |= (character == '"' && strchr (ttok, '$') != 0);
6337 goto next_character;
6341 /* When parsing a regexp as a single word inside a conditional command,
6342 we need to special-case characters special to both the shell and
6343 regular expressions. Right now, that is only '(' and '|'. */ /*)*/
6344 if MBTEST((parser_state & PST_REGEXP) && (character == '(' || character == '|')) /*)*/
6346 if (character == '|')
6349 push_delimiter (dstack, character);
6350 ttok = parse_matched_pair (cd, '(', ')', &ttoklen, 0);
6351 pop_delimiter (dstack);
6352 if (ttok == &matched_pair_error)
6353 return -1; /* Bail immediately. */
6354 RESIZE_MALLOCED_BUFFER (token, token_index, ttoklen + 2,
6355 token_buffer_size, TOKEN_DEFAULT_GROW_SIZE);
6356 token[token_index++] = character;
6357 strcpy (token + token_index, ttok);
6358 token_index += ttoklen;
6360 dollar_present = all_digit_token = 0;
6361 goto next_character;
6363 #endif /* COND_REGEXP */
6365 #ifdef EXTENDED_GLOB
6366 /* Parse a ksh-style extended pattern matching specification. */
6367 if MBTEST(extended_glob && PATTERN_CHAR (character))
6369 peek_char = shell_getc (1);
6370 if MBTEST(peek_char == '(') /* ) */
6372 push_delimiter (dstack, peek_char);
6373 ttok = parse_matched_pair (cd, '(', ')', &ttoklen, 0);
6374 pop_delimiter (dstack);
6375 if (ttok == &matched_pair_error)
6376 return -1; /* Bail immediately. */
6377 RESIZE_MALLOCED_BUFFER (token, token_index, ttoklen + 2,
6379 TOKEN_DEFAULT_GROW_SIZE);
6380 token[token_index++] = character;
6381 token[token_index++] = peek_char;
6382 strcpy (token + token_index, ttok);
6383 token_index += ttoklen;
6385 dollar_present = all_digit_token = 0;
6386 goto next_character;
6389 shell_ungetc (peek_char);
6391 #endif /* EXTENDED_GLOB */
6393 /* If the delimiter character is not single quote, parse some of
6394 the shell expansions that must be read as a single word. */
6395 if (shellexp (character))
6397 peek_char = shell_getc (1);
6398 /* $(...), <(...), >(...), $((...)), ${...}, and $[...] constructs */
6399 if MBTEST(peek_char == '(' || \
6400 ((peek_char == '{' || peek_char == '[') && character == '$')) /* ) ] } */
6402 if (peek_char == '{') /* } */
6403 ttok = parse_matched_pair (cd, '{', '}', &ttoklen, P_FIRSTCLOSE);
6404 else if (peek_char == '(') /* ) */
6406 /* XXX - push and pop the `(' as a delimiter for use by
6407 the command-oriented-history code. This way newlines
6408 appearing in the $(...) string get added to the
6409 history literally rather than causing a possibly-
6410 incorrect `;' to be added. ) */
6411 push_delimiter (dstack, peek_char);
6412 ttok = parse_comsub (cd, '(', ')', &ttoklen, P_COMMAND);
6413 pop_delimiter (dstack);
6416 ttok = parse_matched_pair (cd, '[', ']', &ttoklen, 0);
6417 if (ttok == &matched_pair_error)
6418 return -1; /* Bail immediately. */
6419 RESIZE_MALLOCED_BUFFER (token, token_index, ttoklen + 2,
6421 TOKEN_DEFAULT_GROW_SIZE);
6422 token[token_index++] = character;
6423 token[token_index++] = peek_char;
6424 strcpy (token + token_index, ttok);
6425 token_index += ttoklen;
6428 all_digit_token = 0;
6429 goto next_character;
6431 /* This handles $'...' and $"..." new-style quoted strings. */
6432 else if MBTEST(character == '$' && (peek_char == '\'' || peek_char == '"'))
6436 first_line = line_number;
6437 push_delimiter (dstack, peek_char);
6438 ttok = parse_matched_pair (peek_char, peek_char, peek_char,
6440 (peek_char == '\'') ? P_ALLOWESC : 0);
6441 pop_delimiter (dstack);
6442 if (ttok == &matched_pair_error)
6444 if (peek_char == '\'')
6446 ttrans = ansiexpand (ttok, 0, ttoklen - 1, &ttranslen);
6449 /* Insert the single quotes and correctly quote any
6450 embedded single quotes (allowed because P_ALLOWESC was
6451 passed to parse_matched_pair). */
6452 ttok = sh_single_quote (ttrans);
6454 ttranslen = strlen (ttok);
6459 /* Try to locale-expand the converted string. */
6460 ttrans = localeexpand (ttok, 0, ttoklen - 1, first_line, &ttranslen);
6463 /* Add the double quotes back */
6464 ttok = sh_mkdoublequoted (ttrans, ttranslen, 0);
6470 RESIZE_MALLOCED_BUFFER (token, token_index, ttranslen + 2,
6472 TOKEN_DEFAULT_GROW_SIZE);
6473 strcpy (token + token_index, ttrans);
6474 token_index += ttranslen;
6477 all_digit_token = 0;
6478 goto next_character;
6480 /* This could eventually be extended to recognize all of the
6481 shell's single-character parameter expansions, and set flags.*/
6482 else if MBTEST(character == '$' && peek_char == '$')
6484 ttok = (char *)xmalloc (3);
6485 ttok[0] = ttok[1] = '$';
6487 RESIZE_MALLOCED_BUFFER (token, token_index, 3,
6489 TOKEN_DEFAULT_GROW_SIZE);
6490 strcpy (token + token_index, ttok);
6493 all_digit_token = 0;
6495 goto next_character;
6498 shell_ungetc (peek_char);
6501 #if defined (ARRAY_VARS)
6502 /* Identify possible array subscript assignment; match [...]. If
6503 parser_state&PST_COMPASSIGN, we need to parse [sub]=words treating
6504 `sub' as if it were enclosed in double quotes. */
6505 else if MBTEST(character == '[' && /* ] */
6506 ((token_index > 0 && assignment_acceptable (last_read_token) && token_is_ident (token, token_index)) ||
6507 (token_index == 0 && (parser_state&PST_COMPASSIGN))))
6509 ttok = parse_matched_pair (cd, '[', ']', &ttoklen, 0);
6510 if (ttok == &matched_pair_error)
6511 return -1; /* Bail immediately. */
6512 RESIZE_MALLOCED_BUFFER (token, token_index, ttoklen + 2,
6514 TOKEN_DEFAULT_GROW_SIZE);
6515 token[token_index++] = character;
6516 strcpy (token + token_index, ttok);
6517 token_index += ttoklen;
6519 all_digit_token = 0;
6520 goto next_character;
6522 /* Identify possible compound array variable assignment. */
6523 else if MBTEST(character == '=' && token_index > 0 && (assignment_acceptable (last_read_token) || (parser_state & PST_ASSIGNOK)) && token_is_assignment (token, token_index))
6525 peek_char = shell_getc (1);
6526 if MBTEST(peek_char == '(') /* ) */
6528 ttok = parse_compound_assignment (&ttoklen);
6530 RESIZE_MALLOCED_BUFFER (token, token_index, ttoklen + 4,
6532 TOKEN_DEFAULT_GROW_SIZE);
6534 token[token_index++] = '=';
6535 token[token_index++] = '(';
6538 strcpy (token + token_index, ttok);
6539 token_index += ttoklen;
6541 token[token_index++] = ')';
6543 all_digit_token = 0;
6544 compound_assignment = 1;
6546 goto next_character;
6548 goto got_token; /* ksh93 seems to do this */
6552 shell_ungetc (peek_char);
6556 /* When not parsing a multi-character word construct, shell meta-
6557 characters break words. */
6558 if MBTEST(shellbreak (character))
6560 shell_ungetc (character);
6566 if (character == CTLESC || character == CTLNUL)
6567 token[token_index++] = CTLESC;
6569 got_escaped_character:
6571 all_digit_token &= DIGIT (character);
6572 dollar_present |= character == '$';
6574 token[token_index++] = character;
6576 RESIZE_MALLOCED_BUFFER (token, token_index, 1, token_buffer_size,
6577 TOKEN_DEFAULT_GROW_SIZE);
6580 if (character == '\n' && SHOULD_PROMPT ())
6583 /* We want to remove quoted newlines (that is, a \<newline> pair)
6584 unless we are within single quotes or pass_next_character is
6585 set (the shell equivalent of literal-next). */
6586 cd = current_delimiter (dstack);
6587 character = shell_getc (cd != '\'' && pass_next_character == 0);
6588 } /* end for (;;) */
6592 token[token_index] = '\0';
6594 /* Check to see what thing we should return. If the last_read_token
6595 is a `<', or a `&', or the character which ended this token is
6596 a '>' or '<', then, and ONLY then, is this input token a NUMBER.
6597 Otherwise, it is just a word, and should be returned as such. */
6598 if MBTEST(all_digit_token && (character == '<' || character == '>' || \
6599 last_read_token == LESS_AND || \
6600 last_read_token == GREATER_AND))
6602 if (legal_number (token, &lvalue) && (int)lvalue == lvalue)
6603 yylval.number = lvalue;
6609 /* Check for special case tokens. */
6610 result = (last_shell_getc_is_singlebyte) ? special_case_tokens (token) : -1;
6615 /* Posix.2 does not allow reserved words to be aliased, so check for all
6616 of them, including special cases, before expanding the current token
6618 if MBTEST(posixly_correct)
6619 CHECK_FOR_RESERVED_WORD (token);
6621 /* Aliases are expanded iff EXPAND_ALIASES is non-zero, and quoting
6622 inhibits alias expansion. */
6623 if (expand_aliases && quoted == 0)
6625 result = alias_expand_token (token);
6626 if (result == RE_READ_TOKEN)
6627 return (RE_READ_TOKEN);
6628 else if (result == NO_EXPANSION)
6629 parser_state &= ~PST_ALEXPNEXT;
6632 /* If not in Posix.2 mode, check for reserved words after alias
6634 if MBTEST(posixly_correct == 0)
6636 CHECK_FOR_RESERVED_WORD (token);
6638 the_word = (WORD_DESC *)xmalloc (sizeof (WORD_DESC));
6639 the_word->word = (char *)xmalloc (1 + token_index);
6640 the_word->flags = 0;
6641 strcpy (the_word->word, token);
6643 the_word->flags |= W_HASDOLLAR;
6645 the_word->flags |= W_QUOTED; /*(*/
6646 if (compound_assignment && token[token_index-1] == ')')
6647 the_word->flags |= W_COMPASSIGN;
6648 /* A word is an assignment if it appears at the beginning of a
6649 simple command, or after another assignment word. This is
6650 context-dependent, so it cannot be handled in the grammar. */
6651 if (assignment (token, (parser_state & PST_COMPASSIGN) != 0))
6653 the_word->flags |= W_ASSIGNMENT;
6654 /* Don't perform word splitting on assignment statements. */
6655 if (assignment_acceptable (last_read_token) || (parser_state & PST_COMPASSIGN) != 0)
6656 the_word->flags |= W_NOSPLIT;
6659 if (command_token_position (last_read_token))
6662 b = builtin_address_internal (token, 0);
6663 if (b && (b->flags & ASSIGNMENT_BUILTIN))
6664 parser_state |= PST_ASSIGNOK;
6665 else if (STREQ (token, "eval") || STREQ (token, "let"))
6666 parser_state |= PST_ASSIGNOK;
6669 yylval.word = the_word;
6671 result = ((the_word->flags & (W_ASSIGNMENT|W_NOSPLIT)) == (W_ASSIGNMENT|W_NOSPLIT))
6672 ? ASSIGNMENT_WORD : WORD;
6674 switch (last_read_token)
6677 parser_state |= PST_ALLOWOPNBRC;
6678 function_dstart = line_number;
6683 if (word_top < MAX_CASE_NEST)
6685 word_lineno[word_top] = line_number;
6692 /* Return 1 if TOKSYM is a token that after being read would allow
6693 a reserved word to be seen, else 0. */
6695 reserved_word_acceptable (toksym)
6730 #if defined (COPROCESS_SUPPORT)
6731 if (last_read_token == WORD && token_before_that == COPROC)
6738 /* Return the index of TOKEN in the alist of reserved words, or -1 if
6739 TOKEN is not a shell reserved word. */
6741 find_reserved_word (tokstr)
6745 for (i = 0; word_token_alist[i].word; i++)
6746 if (STREQ (tokstr, word_token_alist[i].word))
6752 #if defined (READLINE)
6753 /* Called after each time readline is called. This insures that whatever
6754 the new prompt string is gets propagated to readline's local prompt
6757 reset_readline_prompt ()
6761 if (prompt_string_pointer)
6763 temp_prompt = (*prompt_string_pointer)
6764 ? decode_prompt_string (*prompt_string_pointer)
6767 if (temp_prompt == 0)
6769 temp_prompt = (char *)xmalloc (1);
6770 temp_prompt[0] = '\0';
6773 FREE (current_readline_prompt);
6774 current_readline_prompt = temp_prompt;
6777 #endif /* READLINE */
6780 #if defined (HISTORY)
6781 /* A list of tokens which can be followed by newlines, but not by
6782 semi-colons. When concatenating multiple lines of history, the
6783 newline separator for such tokens is replaced with a space. */
6784 static const int no_semi_successors[] = {
6785 '\n', '{', '(', ')', ';', '&', '|',
6786 CASE, DO, ELSE, IF, SEMI_SEMI, SEMI_AND, SEMI_SEMI_AND, THEN, UNTIL,
6787 WHILE, AND_AND, OR_OR, IN,
6791 /* If we are not within a delimited expression, try to be smart
6792 about which separators can be semi-colons and which must be
6793 newlines. Returns the string that should be added into the
6796 history_delimiting_chars ()
6800 if (dstack.delimiter_depth != 0)
6803 /* We look for current_command_line_count == 2 because we are looking to
6804 add the first line of the body of the here document (the second line
6806 if (parser_state & PST_HEREDOC)
6807 return (current_command_line_count == 2 ? "\n" : "");
6809 /* First, handle some special cases. */
6811 /* If we just read `()', assume it's a function definition, and don't
6812 add a semicolon. If the token before the `)' was not `(', and we're
6813 not in the midst of parsing a case statement, assume it's a
6814 parenthesized command and add the semicolon. */
6816 if (token_before_that == ')')
6818 if (two_tokens_ago == '(') /*)*/ /* function def */
6820 /* This does not work for subshells inside case statement
6821 command lists. It's a suboptimal solution. */
6822 else if (parser_state & PST_CASESTMT) /* case statement pattern */
6825 return "; "; /* (...) subshell */
6827 else if (token_before_that == WORD && two_tokens_ago == FUNCTION)
6828 return " "; /* function def using `function name' without `()' */
6830 else if (token_before_that == WORD && two_tokens_ago == FOR)
6832 /* Tricky. `for i\nin ...' should not have a semicolon, but
6833 `for i\ndo ...' should. We do what we can. */
6834 for (i = shell_input_line_index; whitespace (shell_input_line[i]); i++)
6836 if (shell_input_line[i] && shell_input_line[i] == 'i' && shell_input_line[i+1] == 'n')
6840 else if (two_tokens_ago == CASE && token_before_that == WORD && (parser_state & PST_CASESTMT))
6843 for (i = 0; no_semi_successors[i]; i++)
6845 if (token_before_that == no_semi_successors[i])
6851 #endif /* HISTORY */
6853 /* Issue a prompt, or prepare to issue a prompt when the next character
6860 if (interactive == 0 || expanding_alias()) /* XXX */
6863 ps1_prompt = get_string_value ("PS1");
6864 ps2_prompt = get_string_value ("PS2");
6866 if (!prompt_string_pointer)
6867 prompt_string_pointer = &ps1_prompt;
6869 temp_prompt = *prompt_string_pointer
6870 ? decode_prompt_string (*prompt_string_pointer)
6873 if (temp_prompt == 0)
6875 temp_prompt = (char *)xmalloc (1);
6876 temp_prompt[0] = '\0';
6879 current_prompt_string = *prompt_string_pointer;
6880 prompt_string_pointer = &ps2_prompt;
6882 #if defined (READLINE)
6883 if (!no_line_editing)
6885 FREE (current_readline_prompt);
6886 current_readline_prompt = temp_prompt;
6889 #endif /* READLINE */
6891 FREE (current_decoded_prompt);
6892 current_decoded_prompt = temp_prompt;
6897 get_current_prompt_level ()
6899 return ((current_prompt_string && current_prompt_string == ps2_prompt) ? 2 : 1);
6903 set_current_prompt_level (x)
6906 prompt_string_pointer = (x == 2) ? &ps2_prompt : &ps1_prompt;
6907 current_prompt_string = *prompt_string_pointer;
6913 fprintf (stderr, "%s", current_decoded_prompt);
6917 /* Return a string which will be printed as a prompt. The string
6918 may contain special characters which are decoded as follows:
6921 \d the date in Day Mon Date format
6922 \e escape (ascii 033)
6923 \h the hostname up to the first `.'
6925 \j the number of active jobs
6926 \l the basename of the shell's tty device name
6929 \s the name of the shell
6930 \t the time in 24-hour hh:mm:ss format
6931 \T the time in 12-hour hh:mm:ss format
6932 \@ the time in 12-hour hh:mm am/pm format
6933 \A the time in 24-hour hh:mm format
6934 \D{fmt} the result of passing FMT to strftime(3)
6936 \v the version of bash (e.g., 2.00)
6937 \V the release of bash, version + patchlevel (e.g., 2.00.0)
6938 \w the current working directory
6939 \W the last element of $PWD
6940 \! the history number of this command
6941 \# the command number of this command
6942 \$ a $ or a # if you are root
6943 \nnn character code nnn in octal
6945 \[ begin a sequence of non-printing chars
6946 \] end a sequence of non-printing chars
6948 #define PROMPT_GROWTH 48
6950 decode_prompt_string (string)
6955 struct dstack save_dstack;
6956 int last_exit_value;
6957 #if defined (PROMPT_STRING_DECODE)
6958 int result_size, result_index;
6960 char *temp, octal_string[4];
6966 result = (char *)xmalloc (result_size = PROMPT_GROWTH);
6967 result[result_index = 0] = 0;
6968 temp = (char *)NULL;
6970 while (c = *string++)
6972 if (posixly_correct && c == '!')
6976 temp = savestring ("!");
6981 #if !defined (HISTORY)
6982 temp = savestring ("1");
6984 temp = itos (history_number ());
6985 #endif /* HISTORY */
6986 string--; /* add_string increments string again. */
7004 strncpy (octal_string, string, 3);
7005 octal_string[3] = '\0';
7007 n = read_octal (octal_string);
7008 temp = (char *)xmalloc (3);
7010 if (n == CTLESC || n == CTLNUL)
7027 for (c = 0; n != -1 && c < 3 && ISOCTAL (*string); c++)
7030 c = 0; /* tested at add_string: */
7038 /* Make the current time/date into a string. */
7039 (void) time (&the_time);
7040 tm = localtime (&the_time);
7043 n = strftime (timebuf, sizeof (timebuf), "%a %b %d", tm);
7045 n = strftime (timebuf, sizeof (timebuf), "%H:%M:%S", tm);
7047 n = strftime (timebuf, sizeof (timebuf), "%I:%M:%S", tm);
7049 n = strftime (timebuf, sizeof (timebuf), "%I:%M %p", tm);
7051 n = strftime (timebuf, sizeof (timebuf), "%H:%M", tm);
7056 timebuf[sizeof(timebuf) - 1] = '\0';
7058 temp = savestring (timebuf);
7061 case 'D': /* strftime format */
7062 if (string[1] != '{') /* } */
7065 (void) time (&the_time);
7066 tm = localtime (&the_time);
7067 string += 2; /* skip { */
7068 timefmt = xmalloc (strlen (string) + 3);
7069 for (t = timefmt; *string && *string != '}'; )
7072 c = *string; /* tested at add_string */
7073 if (timefmt[0] == '\0')
7076 timefmt[1] = 'X'; /* locale-specific current time */
7079 n = strftime (timebuf, sizeof (timebuf), timefmt, tm);
7085 timebuf[sizeof(timebuf) - 1] = '\0';
7087 if (promptvars || posixly_correct)
7088 /* Make sure that expand_prompt_string is called with a
7089 second argument of Q_DOUBLE_QUOTES if we use this
7091 temp = sh_backslash_quote_for_double_quotes (timebuf);
7093 temp = savestring (timebuf);
7097 temp = (char *)xmalloc (3);
7098 temp[0] = no_line_editing ? '\n' : '\r';
7099 temp[1] = no_line_editing ? '\0' : '\n';
7104 temp = base_pathname (shell_name);
7105 temp = savestring (temp);
7110 temp = (char *)xmalloc (16);
7112 strcpy (temp, dist_version);
7114 sprintf (temp, "%s.%d", dist_version, patch_level);
7120 /* Use the value of PWD because it is much more efficient. */
7121 char t_string[PATH_MAX];
7124 temp = get_string_value ("PWD");
7128 if (getcwd (t_string, sizeof(t_string)) == 0)
7134 tlen = strlen (t_string);
7138 tlen = sizeof (t_string) - 1;
7139 strncpy (t_string, temp, tlen);
7141 t_string[tlen] = '\0';
7143 #define ROOT_PATH(x) ((x)[0] == '/' && (x)[1] == 0)
7144 #define DOUBLE_SLASH_ROOT(x) ((x)[0] == '/' && (x)[1] == '/' && (x)[2] == 0)
7145 /* Abbreviate \W as ~ if $PWD == $HOME */
7146 if (c == 'W' && (((t = get_string_value ("HOME")) == 0) || STREQ (t, t_string) == 0))
7148 if (ROOT_PATH (t_string) == 0 && DOUBLE_SLASH_ROOT (t_string) == 0)
7150 t = strrchr (t_string, '/');
7152 strcpy (t_string, t + 1);
7156 #undef DOUBLE_SLASH_ROOT
7158 /* polite_directory_format is guaranteed to return a string
7159 no longer than PATH_MAX - 1 characters. */
7160 strcpy (t_string, polite_directory_format (t_string));
7162 temp = trim_pathname (t_string, PATH_MAX - 1);
7163 /* If we're going to be expanding the prompt string later,
7164 quote the directory name. */
7165 if (promptvars || posixly_correct)
7166 /* Make sure that expand_prompt_string is called with a
7167 second argument of Q_DOUBLE_QUOTES if we use this
7169 temp = sh_backslash_quote_for_double_quotes (t_string);
7171 temp = savestring (t_string);
7177 if (current_user.user_name == 0)
7178 get_current_user_info ();
7179 temp = savestring (current_user.user_name);
7184 temp = savestring (current_host_name);
7185 if (c == 'h' && (t = (char *)strchr (temp, '.')))
7190 temp = itos (current_command_number);
7194 #if !defined (HISTORY)
7195 temp = savestring ("1");
7197 temp = itos (history_number ());
7198 #endif /* HISTORY */
7202 t = temp = (char *)xmalloc (3);
7203 if ((promptvars || posixly_correct) && (current_user.euid != 0))
7205 *t++ = current_user.euid == 0 ? '#' : '$';
7210 temp = itos (count_all_jobs ());
7214 #if defined (HAVE_TTYNAME)
7215 temp = (char *)ttyname (fileno (stdin));
7216 t = temp ? base_pathname (temp) : "tty";
7217 temp = savestring (t);
7219 temp = savestring ("tty");
7220 #endif /* !HAVE_TTYNAME */
7223 #if defined (READLINE)
7226 if (no_line_editing)
7231 temp = (char *)xmalloc (3);
7232 n = (c == '[') ? RL_PROMPT_START_IGNORE : RL_PROMPT_END_IGNORE;
7234 if (n == CTLESC || n == CTLNUL)
7239 #endif /* READLINE */
7245 temp = (char *)xmalloc (2);
7252 else /* (c == '\\') */
7259 temp = (char *)xmalloc (3);
7268 sub_append_string (temp, result, &result_index, &result_size);
7269 temp = (char *)NULL; /* Freed in sub_append_string (). */
7270 result[result_index] = '\0';
7276 RESIZE_MALLOCED_BUFFER (result, result_index, 3, result_size, PROMPT_GROWTH);
7277 result[result_index++] = c;
7278 result[result_index] = '\0';
7281 #else /* !PROMPT_STRING_DECODE */
7282 result = savestring (string);
7283 #endif /* !PROMPT_STRING_DECODE */
7285 /* Save the delimiter stack and point `dstack' to temp space so any
7286 command substitutions in the prompt string won't result in screwing
7287 up the parser's quoting state. */
7288 save_dstack = dstack;
7289 dstack = temp_dstack;
7290 dstack.delimiter_depth = 0;
7292 /* Perform variable and parameter expansion and command substitution on
7293 the prompt string. */
7294 if (promptvars || posixly_correct)
7296 last_exit_value = last_command_exit_value;
7297 list = expand_prompt_string (result, Q_DOUBLE_QUOTES, 0);
7299 result = string_list (list);
7300 dispose_words (list);
7301 last_command_exit_value = last_exit_value;
7305 t = dequote_string (result);
7310 dstack = save_dstack;
7315 /************************************************
7319 ************************************************/
7321 /* Report a syntax error, and restart the parser. Call here for fatal
7327 report_syntax_error ((char *)NULL);
7333 error_token_from_token (tok)
7338 if (t = find_token_in_alist (tok, word_token_alist, 0))
7341 if (t = find_token_in_alist (tok, other_token_alist, 0))
7345 /* This stuff is dicy and needs closer inspection */
7346 switch (current_token)
7349 case ASSIGNMENT_WORD:
7351 t = savestring (yylval.word->word);
7354 t = itos (yylval.number);
7357 if (yylval.word_list)
7358 t = string_list (yylval.word_list);
7360 case ARITH_FOR_EXPRS:
7361 if (yylval.word_list)
7362 t = string_list_internal (yylval.word_list, " ; ");
7365 t = (char *)NULL; /* punt */
7373 error_token_from_text ()
7378 t = shell_input_line;
7379 i = shell_input_line_index;
7383 if (i && t[i] == '\0')
7386 while (i && (whitespace (t[i]) || t[i] == '\n'))
7392 while (i && (member (t[i], " \n\t;|&") == 0))
7395 while (i != token_end && (whitespace (t[i]) || t[i] == '\n'))
7398 /* Return our idea of the offending token. */
7399 if (token_end || (i == 0 && token_end == 0))
7402 msg = substring (t, i, token_end);
7403 else /* one-character token */
7405 msg = (char *)xmalloc (2);
7415 print_offending_line ()
7420 msg = savestring (shell_input_line);
7421 token_end = strlen (msg);
7422 while (token_end && msg[token_end - 1] == '\n')
7423 msg[--token_end] = '\0';
7425 parser_error (line_number, "`%s'", msg);
7429 /* Report a syntax error with line numbers, etc.
7430 Call here for recoverable errors. If you have a message to print,
7431 then place it in MESSAGE, otherwise pass NULL and this will figure
7432 out an appropriate message for you. */
7434 report_syntax_error (message)
7441 parser_error (line_number, "%s", message);
7442 if (interactive && EOF_Reached)
7444 last_command_exit_value = EX_USAGE;
7448 /* If the line of input we're reading is not null, try to find the
7449 objectionable token. First, try to figure out what token the
7450 parser's complaining about by looking at current_token. */
7451 if (current_token != 0 && EOF_Reached == 0 && (msg = error_token_from_token (current_token)))
7453 parser_error (line_number, _("syntax error near unexpected token `%s'"), msg);
7456 if (interactive == 0)
7457 print_offending_line ();
7459 last_command_exit_value = EX_USAGE;
7463 /* If looking at the current token doesn't prove fruitful, try to find the
7464 offending token by analyzing the text of the input line near the current
7465 input line index and report what we find. */
7466 if (shell_input_line && *shell_input_line)
7468 msg = error_token_from_text ();
7471 parser_error (line_number, _("syntax error near `%s'"), msg);
7475 /* If not interactive, print the line containing the error. */
7476 if (interactive == 0)
7477 print_offending_line ();
7481 msg = EOF_Reached ? _("syntax error: unexpected end of file") : _("syntax error");
7482 parser_error (line_number, "%s", msg);
7483 /* When the shell is interactive, this file uses EOF_Reached
7484 only for error reporting. Other mechanisms are used to
7485 decide whether or not to exit. */
7486 if (interactive && EOF_Reached)
7490 last_command_exit_value = EX_USAGE;
7493 /* ??? Needed function. ??? We have to be able to discard the constructs
7494 created during parsing. In the case of error, we want to return
7495 allocated objects to the memory pool. In the case of no error, we want
7496 to throw away the information about where the allocated objects live.
7497 (dispose_command () will actually free the command.) */
7499 discard_parser_constructs (error_p)
7504 /************************************************
7508 ************************************************/
7510 /* Do that silly `type "bye" to exit' stuff. You know, "ignoreeof". */
7512 /* A flag denoting whether or not ignoreeof is set. */
7515 /* The number of times that we have encountered an EOF character without
7516 another character intervening. When this gets above the limit, the
7517 shell terminates. */
7518 int eof_encountered = 0;
7520 /* The limit for eof_encountered. */
7521 int eof_encountered_limit = 10;
7523 /* If we have EOF as the only input unit, this user wants to leave
7524 the shell. If the shell is not interactive, then just leave.
7525 Otherwise, if ignoreeof is set, and we haven't done this the
7526 required number of times in a row, print a message. */
7528 handle_eof_input_unit ()
7532 /* shell.c may use this to decide whether or not to write out the
7533 history, among other things. We use it only for error reporting
7538 /* If the user wants to "ignore" eof, then let her do so, kind of. */
7541 if (eof_encountered < eof_encountered_limit)
7543 fprintf (stderr, _("Use \"%s\" to leave the shell.\n"),
7544 login_shell ? "logout" : "exit");
7546 /* Reset the parsing state. */
7547 last_read_token = current_token = '\n';
7548 /* Reset the prompt string to be $PS1. */
7549 prompt_string_pointer = (char **)NULL;
7555 /* In this case EOF should exit the shell. Do it now. */
7557 exit_builtin ((WORD_LIST *)NULL);
7561 /* We don't write history files, etc., for non-interactive shells. */
7566 /************************************************
7568 * STRING PARSING FUNCTIONS *
7570 ************************************************/
7572 /* It's very important that these two functions treat the characters
7573 between ( and ) identically. */
7575 static WORD_LIST parse_string_error;
7577 /* Take a string and run it through the shell parser, returning the
7578 resultant word list. Used by compound array assignment. */
7580 parse_string_to_word_list (s, flags, whom)
7586 int tok, orig_current_token, orig_line_number, orig_input_terminator;
7587 int orig_line_count;
7588 int old_echo_input, old_expand_aliases;
7589 #if defined (HISTORY)
7590 int old_remember_on_history, old_history_expansion_inhibited;
7593 #if defined (HISTORY)
7594 old_remember_on_history = remember_on_history;
7595 # if defined (BANG_HISTORY)
7596 old_history_expansion_inhibited = history_expansion_inhibited;
7598 bash_history_disable ();
7601 orig_line_number = line_number;
7602 orig_line_count = current_command_line_count;
7603 orig_input_terminator = shell_input_line_terminator;
7604 old_echo_input = echo_input_at_read;
7605 old_expand_aliases = expand_aliases;
7608 last_read_token = WORD; /* WORD to allow reserved words here */
7609 current_command_line_count = 0;
7610 echo_input_at_read = expand_aliases = 0;
7612 with_input_from_string (s, whom);
7613 wl = (WORD_LIST *)NULL;
7616 parser_state |= PST_COMPASSIGN|PST_REPARSE;
7618 while ((tok = read_token (READ)) != yacc_EOF)
7620 if (tok == '\n' && *bash_input.location.string == '\0')
7622 if (tok == '\n') /* Allow newlines in compound assignments */
7624 if (tok != WORD && tok != ASSIGNMENT_WORD)
7626 line_number = orig_line_number + line_number - 1;
7627 orig_current_token = current_token;
7628 current_token = tok;
7629 yyerror (NULL); /* does the right thing */
7630 current_token = orig_current_token;
7633 wl = &parse_string_error;
7636 wl = make_word_list (yylval.word, wl);
7639 last_read_token = '\n';
7642 #if defined (HISTORY)
7643 remember_on_history = old_remember_on_history;
7644 # if defined (BANG_HISTORY)
7645 history_expansion_inhibited = old_history_expansion_inhibited;
7646 # endif /* BANG_HISTORY */
7647 #endif /* HISTORY */
7649 echo_input_at_read = old_echo_input;
7650 expand_aliases = old_expand_aliases;
7652 current_command_line_count = orig_line_count;
7653 shell_input_line_terminator = orig_input_terminator;
7656 parser_state &= ~(PST_COMPASSIGN|PST_REPARSE);
7658 if (wl == &parse_string_error)
7660 last_command_exit_value = EXECUTION_FAILURE;
7661 if (interactive_shell == 0 && posixly_correct)
7662 jump_to_top_level (FORCE_EOF);
7664 jump_to_top_level (DISCARD);
7667 return (REVERSE_LIST (wl, WORD_LIST *));
7671 parse_compound_assignment (retlenp)
7675 int tok, orig_line_number, orig_token_size, orig_last_token, assignok;
7676 char *saved_token, *ret;
7678 saved_token = token;
7679 orig_token_size = token_buffer_size;
7680 orig_line_number = line_number;
7681 orig_last_token = last_read_token;
7683 last_read_token = WORD; /* WORD to allow reserved words here */
7685 token = (char *)NULL;
7686 token_buffer_size = 0;
7688 assignok = parser_state&PST_ASSIGNOK; /* XXX */
7690 wl = (WORD_LIST *)NULL; /* ( */
7691 parser_state |= PST_COMPASSIGN;
7693 while ((tok = read_token (READ)) != ')')
7695 if (tok == '\n') /* Allow newlines in compound assignments */
7697 if (SHOULD_PROMPT ())
7701 if (tok != WORD && tok != ASSIGNMENT_WORD)
7703 current_token = tok; /* for error reporting */
7704 if (tok == yacc_EOF) /* ( */
7705 parser_error (orig_line_number, _("unexpected EOF while looking for matching `)'"));
7707 yyerror(NULL); /* does the right thing */
7710 wl = &parse_string_error;
7713 wl = make_word_list (yylval.word, wl);
7717 token = saved_token;
7718 token_buffer_size = orig_token_size;
7720 parser_state &= ~PST_COMPASSIGN;
7722 if (wl == &parse_string_error)
7724 last_command_exit_value = EXECUTION_FAILURE;
7725 last_read_token = '\n'; /* XXX */
7726 if (interactive_shell == 0 && posixly_correct)
7727 jump_to_top_level (FORCE_EOF);
7729 jump_to_top_level (DISCARD);
7732 last_read_token = orig_last_token; /* XXX - was WORD? */
7736 rl = REVERSE_LIST (wl, WORD_LIST *);
7737 ret = string_list (rl);
7744 *retlenp = (ret && *ret) ? strlen (ret) : 0;
7747 parser_state |= PST_ASSIGNOK;
7752 /************************************************
7754 * SAVING AND RESTORING PARTIAL PARSE STATE *
7756 ************************************************/
7759 save_parser_state (ps)
7760 sh_parser_state_t *ps;
7762 #if defined (ARRAY_VARS)
7767 ps = (sh_parser_state_t *)xmalloc (sizeof (sh_parser_state_t));
7769 return ((sh_parser_state_t *)NULL);
7771 ps->parser_state = parser_state;
7772 ps->token_state = save_token_state ();
7774 ps->input_line_terminator = shell_input_line_terminator;
7775 ps->eof_encountered = eof_encountered;
7777 ps->current_command_line_count = current_command_line_count;
7779 #if defined (HISTORY)
7780 ps->remember_on_history = remember_on_history;
7781 # if defined (BANG_HISTORY)
7782 ps->history_expansion_inhibited = history_expansion_inhibited;
7786 ps->last_command_exit_value = last_command_exit_value;
7787 #if defined (ARRAY_VARS)
7788 v = find_variable ("PIPESTATUS");
7789 if (v && array_p (v) && array_cell (v))
7790 ps->pipestatus = array_copy (array_cell (v));
7792 ps->pipestatus = (ARRAY *)NULL;
7795 ps->last_shell_builtin = last_shell_builtin;
7796 ps->this_shell_builtin = this_shell_builtin;
7798 ps->expand_aliases = expand_aliases;
7799 ps->echo_input_at_read = echo_input_at_read;
7805 restore_parser_state (ps)
7806 sh_parser_state_t *ps;
7808 #if defined (ARRAY_VARS)
7815 parser_state = ps->parser_state;
7816 if (ps->token_state)
7818 restore_token_state (ps->token_state);
7819 free (ps->token_state);
7822 shell_input_line_terminator = ps->input_line_terminator;
7823 eof_encountered = ps->eof_encountered;
7825 current_command_line_count = ps->current_command_line_count;
7827 #if defined (HISTORY)
7828 remember_on_history = ps->remember_on_history;
7829 # if defined (BANG_HISTORY)
7830 history_expansion_inhibited = ps->history_expansion_inhibited;
7834 last_command_exit_value = ps->last_command_exit_value;
7835 #if defined (ARRAY_VARS)
7836 v = find_variable ("PIPESTATUS");
7837 if (v && array_p (v) && array_cell (v))
7839 array_dispose (array_cell (v));
7840 var_setarray (v, ps->pipestatus);
7844 last_shell_builtin = ps->last_shell_builtin;
7845 this_shell_builtin = ps->this_shell_builtin;
7847 expand_aliases = ps->expand_aliases;
7848 echo_input_at_read = ps->echo_input_at_read;
7851 /************************************************
7853 * MULTIBYTE CHARACTER HANDLING *
7855 ************************************************/
7857 #if defined (HANDLE_MULTIBYTE)
7861 int i, previ, len, c;
7862 mbstate_t mbs, prevs;
7865 if (shell_input_line == NULL)
7867 len = strlen (shell_input_line); /* XXX - shell_input_line_len ? */
7868 FREE (shell_input_line_property);
7869 shell_input_line_property = (char *)xmalloc (len + 1);
7871 memset (&prevs, '\0', sizeof (mbstate_t));
7872 for (i = previ = 0; i < len; i++)
7876 c = shell_input_line[i];
7880 for (j = i; j < len; j++)
7881 shell_input_line_property[j] = 1;
7885 mbclen = mbrlen (shell_input_line + previ, i - previ + 1, &mbs);
7886 if (mbclen == 1 || mbclen == (size_t)-1)
7891 else if (mbclen == (size_t)-2)
7893 else if (mbclen > 1)
7901 /* XXX - what to do if mbrlen returns 0? (null wide character) */
7903 for (j = i; j < len; j++)
7904 shell_input_line_property[j] = 1;
7908 shell_input_line_property[i] = mbclen;
7911 #endif /* HANDLE_MULTIBYTE */