1 /* A Bison parser, made by GNU Bison 3.0.4. */
3 /* Bison implementation for Yacc-like parsers in C
5 Copyright (C) 1984, 1989-1990, 2000-2015 Free Software Foundation, Inc.
7 This program is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20 /* As a special exception, you may create a larger work that contains
21 part or all of the Bison parser skeleton and distribute that work
22 under terms of your choice, so long as that work isn't itself a
23 parser generator using the skeleton or a modified version thereof
24 as a parser skeleton. Alternatively, if you modify or redistribute
25 the parser skeleton itself, you may (at your option) remove this
26 special exception, which will cause the skeleton and the resulting
27 Bison output files to be licensed under the GNU General Public
28 License without this special exception.
30 This special exception was added by the Free Software Foundation in
31 version 2.2 of Bison. */
33 /* C LALR(1) parser skeleton written by Richard Stallman, by
34 simplifying the original so-called "semantic" parser. */
36 /* All symbols defined below should begin with yy or YY, to avoid
37 infringing on user name space. This should be done even for local
38 variables, as they might otherwise be expanded by user macros.
39 There are some unavoidable exceptions within include files to
40 define necessary library symbols; they are noted "INFRINGES ON
41 USER NAME SPACE" below. */
43 /* Identify Bison output. */
47 #define YYBISON_VERSION "3.0.4"
50 #define YYSKELETON_NAME "yacc.c"
64 /* Copy the first part of user declarations. */
65 #line 21 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:339 */
69 #include "bashtypes.h"
74 #if defined (HAVE_UNISTD_H)
78 #if defined (HAVE_LOCALE_H)
83 #include "chartypes.h"
90 #define NEED_STRFTIME_DECL /* used in externs.h */
93 #include "typemax.h" /* SIZE_MAX if needed */
97 #include "mailcheck.h"
100 #include "builtins/common.h"
101 #include "builtins/builtext.h"
103 #include "shmbutil.h"
105 #if defined (READLINE)
106 # include "bashline.h"
107 # include <readline/readline.h>
108 #endif /* READLINE */
110 #if defined (HISTORY)
111 # include "bashhist.h"
112 # include <readline/history.h>
115 #if defined (JOB_CONTROL)
118 extern int cleanup_dead_jobs
__P((void));
119 #endif /* JOB_CONTROL */
124 typedef void *alias_t
;
127 #if defined (PROMPT_STRING_DECODE)
129 # include <sys/param.h>
132 # if defined (TM_IN_SYS_TIME)
133 # include <sys/types.h>
134 # include <sys/time.h>
135 # endif /* TM_IN_SYS_TIME */
136 # include "maxpath.h"
137 #endif /* PROMPT_STRING_DECODE */
139 #define RE_READ_TOKEN -99
140 #define NO_EXPANSION -100
148 #if defined (HANDLE_MULTIBYTE)
149 # define last_shell_getc_is_singlebyte \
150 ((shell_input_line_index > 1) \
151 ? shell_input_line_property[shell_input_line_index - 1] \
153 # define MBTEST(x) ((x) && last_shell_getc_is_singlebyte)
155 # define last_shell_getc_is_singlebyte 1
156 # define MBTEST(x) ((x))
159 #if defined (EXTENDED_GLOB)
160 extern int extended_glob
;
163 extern int eof_encountered
;
164 extern int no_line_editing
, running_under_emacs
;
165 extern int current_command_number
;
166 extern int sourcelevel
, parse_and_execute_level
;
167 extern int posixly_correct
;
168 extern int last_command_exit_value
;
169 extern pid_t last_command_subst_pid
;
170 extern char *shell_name
, *current_host_name
;
171 extern char *dist_version
;
172 extern int patch_level
;
173 extern int dump_translatable_strings
, dump_po_strings
;
174 extern sh_builtin_func_t
*last_shell_builtin
, *this_shell_builtin
;
175 extern int here_doc_first_line
;
176 #if defined (BUFFERED_INPUT)
177 extern int bash_input_fd_changed
;
181 /* **************************************************************** */
183 /* "Forward" declarations */
185 /* **************************************************************** */
188 static void debug_parser
__P((int));
191 static int yy_getc
__P((void));
192 static int yy_ungetc
__P((int));
194 #if defined (READLINE)
195 static int yy_readline_get
__P((void));
196 static int yy_readline_unget
__P((int));
199 static int yy_string_get
__P((void));
200 static int yy_string_unget
__P((int));
201 static void rewind_input_string
__P((void));
202 static int yy_stream_get
__P((void));
203 static int yy_stream_unget
__P((int));
205 static int shell_getc
__P((int));
206 static void shell_ungetc
__P((int));
207 static void discard_until
__P((int));
209 #if defined (ALIAS) || defined (DPAREN_ARITHMETIC)
210 static void push_string
__P((char *, int, alias_t
*));
211 static void pop_string
__P((void));
212 static void free_string_list
__P((void));
215 static char *read_a_line
__P((int));
217 static int reserved_word_acceptable
__P((int));
218 static int yylex
__P((void));
220 static void push_heredoc
__P((REDIRECT
*));
221 static char *mk_alexpansion
__P((char *));
222 static int alias_expand_token
__P((char *));
223 static int time_command_acceptable
__P((void));
224 static int special_case_tokens
__P((char *));
225 static int read_token
__P((int));
226 static char *parse_matched_pair
__P((int, int, int, int *, int));
227 static char *parse_comsub
__P((int, int, int, int *, int));
228 #if defined (ARRAY_VARS)
229 static char *parse_compound_assignment
__P((int *));
231 #if defined (DPAREN_ARITHMETIC) || defined (ARITH_FOR_COMMAND)
232 static int parse_dparen
__P((int));
233 static int parse_arith_cmd
__P((char **, int));
235 #if defined (COND_COMMAND)
236 static void cond_error
__P((void));
237 static COND_COM
*cond_expr
__P((void));
238 static COND_COM
*cond_or
__P((void));
239 static COND_COM
*cond_and
__P((void));
240 static COND_COM
*cond_term
__P((void));
241 static int cond_skip_newlines
__P((void));
242 static COMMAND
*parse_cond_command
__P((void));
244 #if defined (ARRAY_VARS)
245 static int token_is_assignment
__P((char *, int));
246 static int token_is_ident
__P((char *, int));
248 static int read_token_word
__P((int));
249 static void discard_parser_constructs
__P((int));
251 static char *error_token_from_token
__P((int));
252 static char *error_token_from_text
__P((void));
253 static void print_offending_line
__P((void));
254 static void report_syntax_error
__P((char *));
256 static void handle_eof_input_unit
__P((void));
257 static void prompt_again
__P((void));
259 static void reset_readline_prompt
__P((void));
261 static void print_prompt
__P((void));
263 #if defined (HANDLE_MULTIBYTE)
264 static void set_line_mbstate
__P((void));
265 static char *shell_input_line_property
= NULL
;
267 # define set_line_mbstate()
270 extern int yyerror
__P((const char *));
276 /* Default prompt strings */
277 char *primary_prompt
= PPROMPT
;
278 char *secondary_prompt
= SPROMPT
;
280 /* PROMPT_STRING_POINTER points to one of these, never to an actual string. */
281 char *ps1_prompt
, *ps2_prompt
;
283 /* Displayed after reading a command but before executing it in an interactive shell */
286 /* Handle on the current prompt string. Indirectly points through
287 ps1_ or ps2_prompt. */
288 char **prompt_string_pointer
= (char **)NULL
;
289 char *current_prompt_string
;
291 /* Non-zero means we expand aliases in commands. */
292 int expand_aliases
= 0;
294 /* If non-zero, the decoded prompt string undergoes parameter and
295 variable substitution, command substitution, arithmetic substitution,
296 string expansion, process substitution, and quote removal in
297 decode_prompt_string. */
300 /* If non-zero, $'...' and $"..." are expanded when they appear within
301 a ${...} expansion, even when the expansion appears within double
303 int extended_quote
= 1;
305 /* The number of lines read from input while creating the current command. */
306 int current_command_line_count
;
308 /* The number of lines in a command saved while we run parse_and_execute */
309 int saved_command_line_count
;
311 /* The token that currently denotes the end of parse. */
314 /* The token currently being read. */
317 /* The current parser state. */
320 /* Variables to manage the task of reading here documents, because we need to
321 defer the reading until after a complete command has been collected. */
322 static REDIRECT
*redir_stack
[HEREDOC_MAX
];
325 /* Where shell input comes from. History expansion is performed on each
326 line when the shell is interactive. */
327 static char *shell_input_line
= (char *)NULL
;
328 static size_t shell_input_line_index
;
329 static size_t shell_input_line_size
; /* Amount allocated for shell_input_line. */
330 static size_t shell_input_line_len
; /* strlen (shell_input_line) */
332 /* Either zero or EOF. */
333 static int shell_input_line_terminator
;
335 /* The line number in a script on which a function definition starts. */
336 static int function_dstart
;
338 /* The line number in a script on which a function body starts. */
339 static int function_bstart
;
341 /* The line number in a script at which an arithmetic for command starts. */
342 static int arith_for_lineno
;
344 /* The decoded prompt string. Used if READLINE is not defined or if
345 editing is turned off. Analogous to current_readline_prompt. */
346 static char *current_decoded_prompt
;
348 /* The last read token, or NULL. read_token () uses this for context
350 static int last_read_token
;
352 /* The token read prior to last_read_token. */
353 static int token_before_that
;
355 /* The token read prior to token_before_that. */
356 static int two_tokens_ago
;
358 static int global_extglob
;
360 /* The line number in a script where the word in a `case WORD', `select WORD'
361 or `for WORD' begins. This is a nested command maximum, since the array
362 index is decremented after a case, select, or for command is parsed. */
363 #define MAX_CASE_NEST 128
364 static int word_lineno
[MAX_CASE_NEST
+1];
365 static int word_top
= -1;
367 /* If non-zero, it is the token that we want read_token to return
368 regardless of what text is (or isn't) present to be read. This
369 is reset by read_token. If token_to_read == WORD or
370 ASSIGNMENT_WORD, yylval.word should be set to word_desc_to_read. */
371 static int token_to_read
;
372 static WORD_DESC
*word_desc_to_read
;
374 static REDIRECTEE source
;
375 static REDIRECTEE redir
;
377 #line 378 "y.tab.c" /* yacc.c:339 */
380 # if defined __cplusplus && 201103L <= __cplusplus
381 # define YY_NULLPTR nullptr
383 # define YY_NULLPTR 0
387 /* Enabling verbose error messages. */
388 #ifdef YYERROR_VERBOSE
389 # undef YYERROR_VERBOSE
390 # define YYERROR_VERBOSE 1
392 # define YYERROR_VERBOSE 0
395 /* In a future release of Bison, this section will be replaced
396 by #include "y.tab.h". */
397 #ifndef YY_YY_Y_TAB_H_INCLUDED
398 # define YY_YY_Y_TAB_H_INCLUDED
436 ASSIGNMENT_WORD
= 282,
440 ARITH_FOR_EXPRS
= 286,
444 GREATER_GREATER
= 290,
447 LESS_LESS_LESS
= 293,
452 LESS_LESS_MINUS
= 298,
454 AND_GREATER_GREATER
= 300,
477 #define COND_START 273
479 #define COND_ERROR 275
486 #define ASSIGNMENT_WORD 282
487 #define REDIR_WORD 283
489 #define ARITH_CMD 285
490 #define ARITH_FOR_EXPRS 286
494 #define GREATER_GREATER 290
495 #define LESS_LESS 291
497 #define LESS_LESS_LESS 293
498 #define GREATER_AND 294
499 #define SEMI_SEMI 295
501 #define SEMI_SEMI_AND 297
502 #define LESS_LESS_MINUS 298
503 #define AND_GREATER 299
504 #define AND_GREATER_GREATER 300
505 #define LESS_GREATER 301
506 #define GREATER_BAR 302
511 #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
515 #line 333 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:355 */
517 WORD_DESC
*word
; /* the word that we read. */
518 int number
; /* the number that we read. */
519 WORD_LIST
*word_list
;
523 PATTERN_LIST
*pattern
;
525 #line 526 "y.tab.c" /* yacc.c:355 */
528 typedef union YYSTYPE YYSTYPE
;
529 # define YYSTYPE_IS_TRIVIAL 1
530 # define YYSTYPE_IS_DECLARED 1
534 extern YYSTYPE yylval
;
538 #endif /* !YY_YY_Y_TAB_H_INCLUDED */
540 /* Copy the second part of user declarations. */
542 #line 543 "y.tab.c" /* yacc.c:358 */
549 typedef YYTYPE_UINT8 yytype_uint8
;
551 typedef unsigned char yytype_uint8
;
555 typedef YYTYPE_INT8 yytype_int8
;
557 typedef signed char yytype_int8
;
561 typedef YYTYPE_UINT16 yytype_uint16
;
563 typedef unsigned short int yytype_uint16
;
567 typedef YYTYPE_INT16 yytype_int16
;
569 typedef short int yytype_int16
;
573 # ifdef __SIZE_TYPE__
574 # define YYSIZE_T __SIZE_TYPE__
575 # elif defined size_t
576 # define YYSIZE_T size_t
577 # elif ! defined YYSIZE_T
578 # include <stddef.h> /* INFRINGES ON USER NAME SPACE */
579 # define YYSIZE_T size_t
581 # define YYSIZE_T unsigned int
585 #define YYSIZE_MAXIMUM ((YYSIZE_T) -1)
588 # if defined YYENABLE_NLS && YYENABLE_NLS
590 # include <libintl.h> /* INFRINGES ON USER NAME SPACE */
591 # define YY_(Msgid) dgettext ("bison-runtime", Msgid)
595 # define YY_(Msgid) Msgid
600 # if (defined __GNUC__ \
601 && (2 < __GNUC__ || (__GNUC__ == 2 && 96 <= __GNUC_MINOR__))) \
602 || defined __SUNPRO_C && 0x5110 <= __SUNPRO_C
603 # define YY_ATTRIBUTE(Spec) __attribute__(Spec)
605 # define YY_ATTRIBUTE(Spec) /* empty */
609 #ifndef YY_ATTRIBUTE_PURE
610 # define YY_ATTRIBUTE_PURE YY_ATTRIBUTE ((__pure__))
613 #ifndef YY_ATTRIBUTE_UNUSED
614 # define YY_ATTRIBUTE_UNUSED YY_ATTRIBUTE ((__unused__))
617 #if !defined _Noreturn \
618 && (!defined __STDC_VERSION__ || __STDC_VERSION__ < 201112)
619 # if defined _MSC_VER && 1200 <= _MSC_VER
620 # define _Noreturn __declspec (noreturn)
622 # define _Noreturn YY_ATTRIBUTE ((__noreturn__))
626 /* Suppress unused-variable warnings by "using" E. */
627 #if ! defined lint || defined __GNUC__
628 # define YYUSE(E) ((void) (E))
630 # define YYUSE(E) /* empty */
633 #if defined __GNUC__ && 407 <= __GNUC__ * 100 + __GNUC_MINOR__
634 /* Suppress an incorrect diagnostic about yylval being uninitialized. */
635 # define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \
636 _Pragma ("GCC diagnostic push") \
637 _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"")\
638 _Pragma ("GCC diagnostic ignored \"-Wmaybe-uninitialized\"")
639 # define YY_IGNORE_MAYBE_UNINITIALIZED_END \
640 _Pragma ("GCC diagnostic pop")
642 # define YY_INITIAL_VALUE(Value) Value
644 #ifndef YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
645 # define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
646 # define YY_IGNORE_MAYBE_UNINITIALIZED_END
648 #ifndef YY_INITIAL_VALUE
649 # define YY_INITIAL_VALUE(Value) /* Nothing. */
653 #if ! defined yyoverflow || YYERROR_VERBOSE
655 /* The parser invokes alloca or malloc; define the necessary symbols. */
657 # ifdef YYSTACK_USE_ALLOCA
658 # if YYSTACK_USE_ALLOCA
660 # define YYSTACK_ALLOC __builtin_alloca
661 # elif defined __BUILTIN_VA_ARG_INCR
662 # include <alloca.h> /* INFRINGES ON USER NAME SPACE */
664 # define YYSTACK_ALLOC __alloca
665 # elif defined _MSC_VER
666 # include <malloc.h> /* INFRINGES ON USER NAME SPACE */
667 # define alloca _alloca
669 # define YYSTACK_ALLOC alloca
670 # if ! defined _ALLOCA_H && ! defined EXIT_SUCCESS
671 # include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
672 /* Use EXIT_SUCCESS as a witness for stdlib.h. */
673 # ifndef EXIT_SUCCESS
674 # define EXIT_SUCCESS 0
681 # ifdef YYSTACK_ALLOC
682 /* Pacify GCC's 'empty if-body' warning. */
683 # define YYSTACK_FREE(Ptr) do { /* empty */; } while (0)
684 # ifndef YYSTACK_ALLOC_MAXIMUM
685 /* The OS might guarantee only one guard page at the bottom of the stack,
686 and a page size can be as small as 4096 bytes. So we cannot safely
687 invoke alloca (N) if N exceeds 4096. Use a slightly smaller number
688 to allow for a few compiler-allocated temporary stack slots. */
689 # define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */
692 # define YYSTACK_ALLOC YYMALLOC
693 # define YYSTACK_FREE YYFREE
694 # ifndef YYSTACK_ALLOC_MAXIMUM
695 # define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM
697 # if (defined __cplusplus && ! defined EXIT_SUCCESS \
698 && ! ((defined YYMALLOC || defined malloc) \
699 && (defined YYFREE || defined free)))
700 # include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
701 # ifndef EXIT_SUCCESS
702 # define EXIT_SUCCESS 0
706 # define YYMALLOC malloc
707 # if ! defined malloc && ! defined EXIT_SUCCESS
708 void *malloc (YYSIZE_T
); /* INFRINGES ON USER NAME SPACE */
713 # if ! defined free && ! defined EXIT_SUCCESS
714 void free (void *); /* INFRINGES ON USER NAME SPACE */
718 #endif /* ! defined yyoverflow || YYERROR_VERBOSE */
721 #if (! defined yyoverflow \
722 && (! defined __cplusplus \
723 || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
725 /* A type that is properly aligned for any stack member. */
728 yytype_int16 yyss_alloc
;
732 /* The size of the maximum gap between one aligned stack and the next. */
733 # define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1)
735 /* The size of an array large to enough to hold all stacks, each with
737 # define YYSTACK_BYTES(N) \
738 ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE)) \
739 + YYSTACK_GAP_MAXIMUM)
741 # define YYCOPY_NEEDED 1
743 /* Relocate STACK from its old location to the new one. The
744 local variables YYSIZE and YYSTACKSIZE give the old and new number of
745 elements in the stack, and YYPTR gives the new location of the
746 stack. Advance YYPTR to a properly aligned location for the next
748 # define YYSTACK_RELOCATE(Stack_alloc, Stack) \
751 YYSIZE_T yynewbytes; \
752 YYCOPY (&yyptr->Stack_alloc, Stack, yysize); \
753 Stack = &yyptr->Stack_alloc; \
754 yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \
755 yyptr += yynewbytes / sizeof (*yyptr); \
761 #if defined YYCOPY_NEEDED && YYCOPY_NEEDED
762 /* Copy COUNT objects from SRC to DST. The source and destination do
765 # if defined __GNUC__ && 1 < __GNUC__
766 # define YYCOPY(Dst, Src, Count) \
767 __builtin_memcpy (Dst, Src, (Count) * sizeof (*(Src)))
769 # define YYCOPY(Dst, Src, Count) \
773 for (yyi = 0; yyi < (Count); yyi++) \
774 (Dst)[yyi] = (Src)[yyi]; \
779 #endif /* !YYCOPY_NEEDED */
781 /* YYFINAL -- State number of the termination state. */
783 /* YYLAST -- Last index in YYTABLE. */
786 /* YYNTOKENS -- Number of terminals. */
788 /* YYNNTS -- Number of nonterminals. */
790 /* YYNRULES -- Number of rules. */
792 /* YYNSTATES -- Number of states. */
793 #define YYNSTATES 334
795 /* YYTRANSLATE[YYX] -- Symbol number corresponding to YYX as returned
796 by yylex, with out-of-bounds checking. */
798 #define YYMAXUTOK 304
800 #define YYTRANSLATE(YYX) \
801 ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
803 /* YYTRANSLATE[TOKEN-NUM] -- Symbol number corresponding to TOKEN-NUM
804 as returned by yylex, without out-of-bounds checking. */
805 static const yytype_uint8 yytranslate
[] =
807 0, 2, 2, 2, 2, 2, 2, 2, 2, 2,
808 51, 2, 2, 2, 2, 2, 2, 2, 2, 2,
809 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
810 2, 2, 2, 2, 2, 2, 2, 2, 49, 2,
811 59, 60, 2, 2, 2, 56, 2, 2, 2, 2,
812 2, 2, 2, 2, 2, 2, 2, 2, 2, 50,
813 55, 2, 54, 2, 2, 2, 2, 2, 2, 2,
814 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
815 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
816 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
817 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
818 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
819 2, 2, 2, 57, 53, 58, 2, 2, 2, 2,
820 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
821 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
822 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
823 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
824 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
825 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
826 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
827 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
828 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
829 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
830 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
831 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
832 2, 2, 2, 2, 2, 2, 1, 2, 3, 4,
833 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
834 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
835 25, 26, 27, 28, 29, 30, 31, 32, 33, 34,
836 35, 36, 37, 38, 39, 40, 41, 42, 43, 44,
841 /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */
842 static const yytype_uint16 yyrline
[] =
844 0, 386, 386, 397, 406, 421, 431, 433, 437, 443,
845 449, 455, 461, 467, 473, 479, 485, 491, 497, 503,
846 509, 515, 521, 527, 534, 541, 548, 555, 562, 569,
847 575, 581, 587, 593, 599, 605, 611, 617, 623, 629,
848 635, 641, 647, 653, 659, 665, 671, 677, 683, 689,
849 695, 701, 709, 711, 713, 717, 721, 732, 734, 738,
850 740, 742, 758, 760, 764, 766, 768, 770, 772, 774,
851 776, 778, 780, 782, 784, 788, 793, 798, 803, 808,
852 813, 818, 823, 830, 835, 840, 845, 852, 857, 862,
853 867, 872, 877, 884, 889, 894, 901, 904, 907, 911,
854 913, 944, 951, 956, 973, 978, 995, 1002, 1004, 1006,
855 1011, 1015, 1019, 1023, 1025, 1027, 1031, 1032, 1036, 1038,
856 1040, 1042, 1046, 1048, 1050, 1052, 1054, 1056, 1060, 1062,
857 1071, 1079, 1080, 1086, 1087, 1094, 1098, 1100, 1102, 1109,
858 1111, 1113, 1117, 1118, 1121, 1123, 1125, 1129, 1130, 1139,
859 1152, 1168, 1183, 1185, 1187, 1194, 1197, 1201, 1203, 1209,
860 1215, 1234, 1256, 1258, 1281, 1285, 1287, 1289
864 #if YYDEBUG || YYERROR_VERBOSE || 0
865 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
866 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
867 static const char *const yytname
[] =
869 "$end", "error", "$undefined", "IF", "THEN", "ELSE", "ELIF", "FI",
870 "CASE", "ESAC", "FOR", "SELECT", "WHILE", "UNTIL", "DO", "DONE",
871 "FUNCTION", "COPROC", "COND_START", "COND_END", "COND_ERROR", "IN",
872 "BANG", "TIME", "TIMEOPT", "TIMEIGN", "WORD", "ASSIGNMENT_WORD",
873 "REDIR_WORD", "NUMBER", "ARITH_CMD", "ARITH_FOR_EXPRS", "COND_CMD",
874 "AND_AND", "OR_OR", "GREATER_GREATER", "LESS_LESS", "LESS_AND",
875 "LESS_LESS_LESS", "GREATER_AND", "SEMI_SEMI", "SEMI_AND",
876 "SEMI_SEMI_AND", "LESS_LESS_MINUS", "AND_GREATER", "AND_GREATER_GREATER",
877 "LESS_GREATER", "GREATER_BAR", "BAR_AND", "'&'", "';'", "'\\n'",
878 "yacc_EOF", "'|'", "'>'", "'<'", "'-'", "'{'", "'}'", "'('", "')'",
879 "$accept", "inputunit", "word_list", "redirection",
880 "simple_command_element", "redirection_list", "simple_command",
881 "command", "shell_command", "for_command", "arith_for_command",
882 "select_command", "case_command", "function_def", "function_body",
883 "subshell", "coproc", "if_command", "group_command", "arith_command",
884 "cond_command", "elif_clause", "case_clause", "pattern_list",
885 "case_clause_sequence", "pattern", "list", "compound_list", "list0",
886 "list1", "simple_list_terminator", "list_terminator", "newline_list",
887 "simple_list", "simple_list1", "pipeline_command", "pipeline",
888 "timespec", YY_NULLPTR
893 /* YYTOKNUM[NUM] -- (External) token number corresponding to the
894 (internal) symbol number NUM (which must be that of a token). */
895 static const yytype_uint16 yytoknum
[] =
897 0, 256, 257, 258, 259, 260, 261, 262, 263, 264,
898 265, 266, 267, 268, 269, 270, 271, 272, 273, 274,
899 275, 276, 277, 278, 279, 280, 281, 282, 283, 284,
900 285, 286, 287, 288, 289, 290, 291, 292, 293, 294,
901 295, 296, 297, 298, 299, 300, 301, 302, 303, 38,
902 59, 10, 304, 124, 62, 60, 45, 123, 125, 40,
907 #define YYPACT_NINF -205
909 #define yypact_value_is_default(Yystate) \
910 (!!((Yystate) == (-205)))
912 #define YYTABLE_NINF -1
914 #define yytable_value_is_error(Yytable_value) \
917 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
919 static const yytype_int16 yypact
[] =
921 308, -28, -205, 6, -1, 37, -205, -205, 57, 558,
922 18, 358, 54, 45, -205, 251, 583, -205, 102, 104,
923 35, 107, 80, 112, 127, 140, 146, 147, -205, -205,
924 153, 154, -205, -205, 188, -205, -205, 196, -205, 219,
925 -205, -205, -205, -205, -205, -205, -205, -205, -205, -205,
926 -205, 17, 23, -205, -19, 358, -205, -205, 185, 408,
927 -205, 144, 51, 166, 189, 207, 133, 28, 196, 219,
928 211, -205, -205, -205, -205, -205, 201, 184, 220, 226,
929 81, 227, 126, 233, 234, 241, 242, 245, 246, 249,
930 142, 255, 148, 256, 257, 259, 266, 267, -205, -205,
931 -205, -205, -205, -205, -205, -205, -205, -205, -205, -205,
932 -205, -205, -205, -205, 243, 240, -205, -205, -205, -205,
933 219, -205, -205, -205, -205, -205, 458, 458, -205, -205,
934 -205, -205, -205, -205, -205, 299, -205, 68, -205, 61,
935 -205, -205, -205, -205, 72, -205, -205, 244, 41, 219,
936 219, -205, -205, -205, -205, -205, -205, -205, -205, -205,
937 -205, -205, -205, -205, -205, -205, -205, -205, -205, -205,
938 -205, -205, -205, -205, -205, -205, -205, -205, -205, -205,
939 -205, -205, -205, -205, -205, 408, 408, 63, 63, 508,
940 508, 179, -205, -205, -205, -205, -205, -205, 60, -205,
941 155, -205, 287, 252, 74, 108, -205, 286, -205, 300,
942 302, -205, 219, -205, 219, 41, -205, -205, -19, -19,
943 -205, -205, -205, 307, 408, 408, 408, 408, 408, 313,
944 159, -205, -4, -205, -205, 312, -205, 161, -205, 265,
945 -205, -205, -205, -205, -205, -205, 314, 408, 161, 270,
946 -205, -205, 41, 219, -205, 332, 336, -205, -205, -205,
947 87, 87, 87, -205, -205, -205, -205, 178, 11, -205,
948 -205, 315, -43, 327, 298, -205, -205, -205, 110, -205,
949 342, 306, 343, 319, -205, 299, -205, -205, -205, -205,
950 -205, -205, -205, -205, -205, -32, 346, -205, -205, -205,
951 113, -205, -205, -205, -205, -205, -205, 118, 137, -205,
952 -205, -205, 408, -205, -205, 363, 321, -205, -205, -205,
953 -205, -205, 408, 367, 325, -205, -205, 374, 333, -205,
954 -205, -205, -205, -205
957 /* YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM.
958 Performed when YYTABLE does not specify something else to do. Zero
959 means the default is an error. */
960 static const yytype_uint8 yydefact
[] =
962 0, 0, 147, 0, 0, 0, 147, 147, 0, 0,
963 0, 0, 165, 52, 53, 0, 0, 111, 0, 0,
964 0, 0, 0, 0, 0, 0, 0, 0, 3, 5,
965 0, 0, 147, 147, 0, 54, 57, 59, 164, 60,
966 64, 74, 68, 65, 62, 70, 63, 69, 71, 72,
967 73, 0, 149, 156, 157, 0, 4, 131, 0, 0,
968 147, 147, 0, 147, 0, 0, 147, 52, 106, 102,
969 0, 145, 144, 146, 161, 158, 166, 0, 0, 0,
970 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
971 0, 0, 0, 0, 0, 0, 0, 0, 14, 23,
972 38, 32, 47, 29, 41, 35, 44, 26, 50, 51,
973 20, 17, 8, 9, 0, 0, 1, 52, 58, 55,
974 61, 142, 143, 2, 147, 147, 150, 151, 147, 147,
975 160, 159, 147, 148, 130, 132, 141, 0, 147, 0,
976 147, 147, 147, 147, 0, 147, 147, 0, 0, 104,
977 103, 112, 167, 147, 16, 25, 40, 34, 49, 31,
978 43, 37, 46, 28, 22, 19, 12, 13, 15, 24,
979 39, 33, 48, 30, 42, 36, 45, 27, 21, 18,
980 10, 11, 110, 101, 56, 0, 0, 154, 155, 0,
981 0, 0, 147, 147, 147, 147, 147, 147, 0, 147,
982 0, 147, 0, 0, 0, 0, 147, 0, 147, 0,
983 0, 147, 99, 98, 105, 0, 152, 153, 163, 162,
984 147, 147, 107, 0, 0, 0, 134, 135, 133, 0,
985 116, 147, 0, 147, 147, 0, 6, 0, 147, 0,
986 85, 86, 147, 147, 147, 147, 0, 0, 0, 0,
987 66, 67, 0, 100, 96, 0, 0, 109, 136, 137,
988 138, 139, 140, 95, 122, 124, 126, 117, 0, 93,
989 128, 0, 0, 0, 0, 75, 7, 147, 0, 76,
990 0, 0, 0, 0, 87, 0, 147, 88, 97, 108,
991 147, 123, 125, 127, 94, 0, 0, 147, 77, 78,
992 0, 147, 147, 83, 84, 89, 90, 0, 113, 147,
993 129, 118, 119, 147, 147, 0, 0, 147, 147, 147,
994 115, 120, 121, 0, 0, 81, 82, 0, 0, 114,
998 /* YYPGOTO[NTERM-NUM]. */
999 static const yytype_int16 yypgoto
[] =
1001 -205, -205, 183, -36, -23, -50, 364, -205, -7, -205,
1002 -205, -205, -205, -205, -204, -205, -205, -205, -205, -205,
1003 -205, 84, -205, 167, -205, 128, -202, -6, -205, 52,
1004 -205, -46, -48, -205, -119, 24, -33, -205
1007 /* YYDEFGOTO[NTERM-NUM]. */
1008 static const yytype_int16 yydefgoto
[] =
1010 -1, 34, 237, 35, 36, 120, 37, 38, 39, 40,
1011 41, 42, 43, 44, 213, 45, 46, 47, 48, 49,
1012 50, 223, 229, 230, 231, 272, 57, 58, 134, 135,
1013 123, 74, 59, 51, 52, 136, 54, 55
1016 /* YYTABLE[YYPACT[STATE-NUM]] -- What to do in state STATE-NUM. If
1017 positive, shift that token. If negative, reduce the rule whose
1018 number is the opposite. If YYTABLE_NINF, syntax error. */
1019 static const yytype_uint16 yytable
[] =
1021 64, 65, 69, 119, 246, 269, 249, 187, 188, 130,
1022 296, 254, 137, 139, 118, 144, 142, 297, 148, 150,
1023 294, 296, 270, 56, 53, 61, 114, 115, 309, 128,
1024 62, 2, 60, 119, 129, 75, 3, 270, 4, 5,
1025 6, 7, 282, 283, 2, 118, 10, 133, 288, 3,
1026 70, 4, 5, 6, 7, 271, 124, 125, 17, 10,
1027 149, 100, 133, 63, 101, 140, 216, 217, 121, 122,
1028 271, 17, 126, 127, 233, 199, 185, 186, 76, 131,
1029 189, 190, 200, 66, 184, 32, 206, 33, 242, 197,
1030 198, 102, 133, 207, 204, 205, 124, 125, 32, 214,
1031 33, 71, 72, 73, 77, 215, 104, 156, 141, 105,
1032 157, 133, 133, 119, 184, 327, 328, 234, 201, 133,
1033 192, 193, 244, 133, 301, 133, 191, 313, 98, 208,
1034 99, 243, 317, 103, 202, 203, 106, 158, 107, 209,
1035 210, 212, 319, 221, 224, 225, 226, 227, 228, 232,
1036 53, 53, 160, 108, 238, 161, 218, 219, 247, 133,
1037 247, 133, 253, 252, 133, 245, 109, 302, 170, 133,
1038 314, 171, 110, 111, 174, 318, 119, 175, 184, 112,
1039 113, 236, 162, 268, 220, 221, 222, 276, 116, 132,
1040 278, 277, 147, 235, 138, 239, 247, 247, 172, 264,
1041 265, 266, 286, 145, 176, 71, 72, 73, 212, 53,
1042 53, 71, 72, 73, 255, 256, 143, 184, 291, 292,
1043 293, 146, 117, 14, 15, 16, 152, 273, 274, 300,
1044 151, 18, 19, 20, 21, 22, 280, 281, 307, 23,
1045 24, 25, 26, 27, 153, 212, 154, 15, 16, 312,
1046 30, 31, 155, 159, 18, 19, 20, 21, 22, 163,
1047 164, 322, 23, 24, 25, 26, 27, 165, 166, 247,
1048 247, 167, 168, 30, 31, 169, 258, 259, 260, 261,
1049 262, 173, 177, 178, 308, 179, 78, 79, 80, 81,
1050 82, 311, 180, 181, 83, 315, 316, 84, 85, 285,
1051 183, 182, 240, 321, 211, 86, 87, 323, 324, 1,
1052 241, 2, 236, 329, 257, 250, 3, 251, 4, 5,
1053 6, 7, 263, 279, 8, 9, 10, 275, 287, 284,
1054 11, 12, 192, 193, 13, 14, 15, 16, 17, 289,
1055 290, 270, 298, 18, 19, 20, 21, 22, 194, 195,
1056 196, 23, 24, 25, 26, 27, 299, 303, 305, 28,
1057 29, 2, 30, 31, 304, 32, 3, 33, 4, 5,
1058 6, 7, 310, 68, 8, 9, 10, 306, 325, 326,
1059 11, 12, 330, 331, 13, 14, 15, 16, 17, 332,
1060 248, 333, 320, 18, 19, 20, 21, 22, 267, 295,
1061 0, 23, 24, 25, 26, 27, 0, 0, 71, 72,
1062 73, 2, 30, 31, 0, 32, 3, 33, 4, 5,
1063 6, 7, 0, 0, 8, 9, 10, 0, 0, 0,
1064 11, 12, 0, 0, 13, 14, 15, 16, 17, 0,
1065 0, 0, 0, 18, 19, 20, 21, 22, 0, 0,
1066 0, 23, 24, 25, 26, 27, 0, 0, 0, 133,
1067 0, 2, 30, 31, 0, 32, 3, 33, 4, 5,
1068 6, 7, 0, 0, 8, 9, 10, 0, 0, 0,
1069 11, 12, 0, 0, 13, 14, 15, 16, 17, 0,
1070 0, 0, 0, 18, 19, 20, 21, 22, 0, 0,
1071 0, 23, 24, 25, 26, 27, 0, 0, 0, 0,
1072 0, 2, 30, 31, 0, 32, 3, 33, 4, 5,
1073 6, 7, 0, 0, 8, 9, 10, 0, 0, 0,
1074 0, 0, 0, 0, 13, 14, 15, 16, 17, 0,
1075 0, 0, 0, 18, 19, 20, 21, 22, 0, 0,
1076 0, 23, 24, 25, 26, 27, 0, 0, 0, 133,
1077 0, 2, 30, 31, 0, 32, 3, 33, 4, 5,
1078 6, 7, 0, 0, 0, 0, 10, 0, 0, 0,
1079 0, 0, 0, 0, 67, 14, 15, 16, 17, 0,
1080 0, 0, 0, 18, 19, 20, 21, 22, 0, 0,
1081 0, 23, 24, 25, 26, 27, 0, 0, 0, 0,
1082 0, 0, 30, 31, 0, 32, 0, 33, 88, 89,
1083 90, 91, 92, 0, 0, 0, 93, 0, 0, 94,
1084 95, 0, 0, 0, 0, 0, 0, 96, 97
1087 static const yytype_int16 yycheck
[] =
1089 6, 7, 9, 39, 206, 9, 208, 126, 127, 55,
1090 53, 215, 60, 61, 37, 63, 62, 60, 66, 69,
1091 9, 53, 26, 51, 0, 26, 32, 33, 60, 48,
1092 31, 3, 26, 69, 53, 11, 8, 26, 10, 11,
1093 12, 13, 244, 245, 3, 68, 18, 51, 252, 8,
1094 32, 10, 11, 12, 13, 59, 33, 34, 30, 18,
1095 67, 26, 51, 26, 29, 14, 185, 186, 51, 52,
1096 59, 30, 49, 50, 14, 14, 124, 125, 24, 55,
1097 128, 129, 21, 26, 120, 57, 14, 59, 14, 21,
1098 138, 56, 51, 21, 142, 143, 33, 34, 57, 149,
1099 59, 50, 51, 52, 59, 153, 26, 26, 57, 29,
1100 29, 51, 51, 149, 150, 317, 318, 57, 57, 51,
1101 33, 34, 14, 51, 14, 51, 132, 14, 26, 57,
1102 26, 57, 14, 26, 140, 141, 56, 56, 26, 145,
1103 146, 148, 5, 6, 192, 193, 194, 195, 196, 197,
1104 126, 127, 26, 26, 200, 29, 189, 190, 206, 51,
1105 208, 51, 212, 211, 51, 57, 26, 57, 26, 51,
1106 57, 29, 26, 26, 26, 57, 212, 29, 214, 26,
1107 26, 26, 56, 231, 5, 6, 7, 26, 0, 4,
1108 238, 237, 59, 199, 50, 201, 244, 245, 56, 40,
1109 41, 42, 248, 14, 56, 50, 51, 52, 215, 185,
1110 186, 50, 51, 52, 220, 221, 50, 253, 40, 41,
1111 42, 14, 26, 27, 28, 29, 25, 233, 234, 277,
1112 19, 35, 36, 37, 38, 39, 242, 243, 286, 43,
1113 44, 45, 46, 47, 60, 252, 26, 28, 29, 297,
1114 54, 55, 26, 26, 35, 36, 37, 38, 39, 26,
1115 26, 309, 43, 44, 45, 46, 47, 26, 26, 317,
1116 318, 26, 26, 54, 55, 26, 224, 225, 226, 227,
1117 228, 26, 26, 26, 290, 26, 35, 36, 37, 38,
1118 39, 297, 26, 26, 43, 301, 302, 46, 47, 247,
1119 60, 58, 15, 309, 60, 54, 55, 313, 314, 1,
1120 58, 3, 26, 319, 7, 15, 8, 15, 10, 11,
1121 12, 13, 9, 58, 16, 17, 18, 15, 58, 15,
1122 22, 23, 33, 34, 26, 27, 28, 29, 30, 7,
1123 4, 26, 15, 35, 36, 37, 38, 39, 49, 50,
1124 51, 43, 44, 45, 46, 47, 58, 15, 15, 51,
1125 52, 3, 54, 55, 58, 57, 8, 59, 10, 11,
1126 12, 13, 26, 9, 16, 17, 18, 58, 15, 58,
1127 22, 23, 15, 58, 26, 27, 28, 29, 30, 15,
1128 207, 58, 308, 35, 36, 37, 38, 39, 231, 271,
1129 -1, 43, 44, 45, 46, 47, -1, -1, 50, 51,
1130 52, 3, 54, 55, -1, 57, 8, 59, 10, 11,
1131 12, 13, -1, -1, 16, 17, 18, -1, -1, -1,
1132 22, 23, -1, -1, 26, 27, 28, 29, 30, -1,
1133 -1, -1, -1, 35, 36, 37, 38, 39, -1, -1,
1134 -1, 43, 44, 45, 46, 47, -1, -1, -1, 51,
1135 -1, 3, 54, 55, -1, 57, 8, 59, 10, 11,
1136 12, 13, -1, -1, 16, 17, 18, -1, -1, -1,
1137 22, 23, -1, -1, 26, 27, 28, 29, 30, -1,
1138 -1, -1, -1, 35, 36, 37, 38, 39, -1, -1,
1139 -1, 43, 44, 45, 46, 47, -1, -1, -1, -1,
1140 -1, 3, 54, 55, -1, 57, 8, 59, 10, 11,
1141 12, 13, -1, -1, 16, 17, 18, -1, -1, -1,
1142 -1, -1, -1, -1, 26, 27, 28, 29, 30, -1,
1143 -1, -1, -1, 35, 36, 37, 38, 39, -1, -1,
1144 -1, 43, 44, 45, 46, 47, -1, -1, -1, 51,
1145 -1, 3, 54, 55, -1, 57, 8, 59, 10, 11,
1146 12, 13, -1, -1, -1, -1, 18, -1, -1, -1,
1147 -1, -1, -1, -1, 26, 27, 28, 29, 30, -1,
1148 -1, -1, -1, 35, 36, 37, 38, 39, -1, -1,
1149 -1, 43, 44, 45, 46, 47, -1, -1, -1, -1,
1150 -1, -1, 54, 55, -1, 57, -1, 59, 35, 36,
1151 37, 38, 39, -1, -1, -1, 43, -1, -1, 46,
1152 47, -1, -1, -1, -1, -1, -1, 54, 55
1155 /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
1156 symbol of state STATE-NUM. */
1157 static const yytype_uint8 yystos
[] =
1159 0, 1, 3, 8, 10, 11, 12, 13, 16, 17,
1160 18, 22, 23, 26, 27, 28, 29, 30, 35, 36,
1161 37, 38, 39, 43, 44, 45, 46, 47, 51, 52,
1162 54, 55, 57, 59, 62, 64, 65, 67, 68, 69,
1163 70, 71, 72, 73, 74, 76, 77, 78, 79, 80,
1164 81, 94, 95, 96, 97, 98, 51, 87, 88, 93,
1165 26, 26, 31, 26, 88, 88, 26, 26, 67, 69,
1166 32, 50, 51, 52, 92, 96, 24, 59, 35, 36,
1167 37, 38, 39, 43, 46, 47, 54, 55, 35, 36,
1168 37, 38, 39, 43, 46, 47, 54, 55, 26, 26,
1169 26, 29, 56, 26, 26, 29, 56, 26, 26, 26,
1170 26, 26, 26, 26, 88, 88, 0, 26, 65, 64,
1171 66, 51, 52, 91, 33, 34, 49, 50, 48, 53,
1172 92, 96, 4, 51, 89, 90, 96, 93, 50, 93,
1173 14, 57, 92, 50, 93, 14, 14, 59, 93, 69,
1174 66, 19, 25, 60, 26, 26, 26, 29, 56, 26,
1175 26, 29, 56, 26, 26, 26, 26, 26, 26, 26,
1176 26, 29, 56, 26, 26, 29, 56, 26, 26, 26,
1177 26, 26, 58, 60, 64, 93, 93, 95, 95, 93,
1178 93, 88, 33, 34, 49, 50, 51, 21, 93, 14,
1179 21, 57, 88, 88, 93, 93, 14, 21, 57, 88,
1180 88, 60, 69, 75, 66, 93, 95, 95, 97, 97,
1181 5, 6, 7, 82, 93, 93, 93, 93, 93, 83,
1182 84, 85, 93, 14, 57, 88, 26, 63, 92, 88,
1183 15, 58, 14, 57, 14, 57, 87, 93, 63, 87,
1184 15, 15, 93, 66, 75, 88, 88, 7, 90, 90,
1185 90, 90, 90, 9, 40, 41, 42, 84, 93, 9,
1186 26, 59, 86, 88, 88, 15, 26, 92, 93, 58,
1187 88, 88, 87, 87, 15, 90, 92, 58, 75, 7,
1188 4, 40, 41, 42, 9, 86, 53, 60, 15, 58,
1189 93, 14, 57, 15, 58, 15, 58, 93, 88, 60,
1190 26, 88, 93, 14, 57, 88, 88, 14, 57, 5,
1191 82, 88, 93, 88, 88, 15, 58, 87, 87, 88,
1195 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
1196 static const yytype_uint8 yyr1
[] =
1198 0, 61, 62, 62, 62, 62, 63, 63, 64, 64,
1199 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
1200 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
1201 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
1202 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
1203 64, 64, 65, 65, 65, 66, 66, 67, 67, 68,
1204 68, 68, 68, 68, 69, 69, 69, 69, 69, 69,
1205 69, 69, 69, 69, 69, 70, 70, 70, 70, 70,
1206 70, 70, 70, 71, 71, 71, 71, 72, 72, 72,
1207 72, 72, 72, 73, 73, 73, 74, 74, 74, 75,
1208 75, 76, 77, 77, 77, 77, 77, 78, 78, 78,
1209 79, 80, 81, 82, 82, 82, 83, 83, 84, 84,
1210 84, 84, 85, 85, 85, 85, 85, 85, 86, 86,
1211 87, 88, 88, 89, 89, 89, 90, 90, 90, 90,
1212 90, 90, 91, 91, 92, 92, 92, 93, 93, 94,
1213 94, 94, 95, 95, 95, 95, 95, 96, 96, 96,
1214 96, 96, 97, 97, 97, 98, 98, 98
1217 /* YYR2[YYN] -- Number of symbols on the right hand side of rule YYN. */
1218 static const yytype_uint8 yyr2
[] =
1220 0, 2, 2, 1, 2, 1, 1, 2, 2, 2,
1221 3, 3, 3, 3, 2, 3, 3, 2, 3, 3,
1222 2, 3, 3, 2, 3, 3, 2, 3, 3, 2,
1223 3, 3, 2, 3, 3, 2, 3, 3, 2, 3,
1224 3, 2, 3, 3, 2, 3, 3, 2, 3, 3,
1225 2, 2, 1, 1, 1, 1, 2, 1, 2, 1,
1226 1, 2, 1, 1, 1, 1, 5, 5, 1, 1,
1227 1, 1, 1, 1, 1, 6, 6, 7, 7, 10,
1228 10, 9, 9, 7, 7, 5, 5, 6, 6, 7,
1229 7, 10, 10, 6, 7, 6, 5, 6, 4, 1,
1230 2, 3, 2, 3, 3, 4, 2, 5, 7, 6,
1231 3, 1, 3, 4, 6, 5, 1, 2, 4, 4,
1232 5, 5, 2, 3, 2, 3, 2, 3, 1, 3,
1233 2, 1, 2, 3, 3, 3, 4, 4, 4, 4,
1234 4, 1, 1, 1, 1, 1, 1, 0, 2, 1,
1235 2, 2, 4, 4, 3, 3, 1, 1, 2, 2,
1236 2, 2, 4, 4, 1, 1, 2, 3
1240 #define yyerrok (yyerrstatus = 0)
1241 #define yyclearin (yychar = YYEMPTY)
1242 #define YYEMPTY (-2)
1245 #define YYACCEPT goto yyacceptlab
1246 #define YYABORT goto yyabortlab
1247 #define YYERROR goto yyerrorlab
1250 #define YYRECOVERING() (!!yyerrstatus)
1252 #define YYBACKUP(Token, Value) \
1254 if (yychar == YYEMPTY) \
1258 YYPOPSTACK (yylen); \
1264 yyerror (YY_("syntax error: cannot back up")); \
1269 /* Error token number */
1271 #define YYERRCODE 256
1275 /* Enable debugging if requested. */
1279 # include <stdio.h> /* INFRINGES ON USER NAME SPACE */
1280 # define YYFPRINTF fprintf
1283 # define YYDPRINTF(Args) \
1289 /* This macro is provided for backward compatibility. */
1290 #ifndef YY_LOCATION_PRINT
1291 # define YY_LOCATION_PRINT(File, Loc) ((void) 0)
1295 # define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
1299 YYFPRINTF (stderr, "%s ", Title); \
1300 yy_symbol_print (stderr, \
1302 YYFPRINTF (stderr, "\n"); \
1307 /*----------------------------------------.
1308 | Print this symbol's value on YYOUTPUT. |
1309 `----------------------------------------*/
1312 yy_symbol_value_print (FILE *yyoutput
, int yytype
, YYSTYPE
const * const yyvaluep
)
1314 FILE *yyo
= yyoutput
;
1319 if (yytype
< YYNTOKENS
)
1320 YYPRINT (yyoutput
, yytoknum
[yytype
], *yyvaluep
);
1326 /*--------------------------------.
1327 | Print this symbol on YYOUTPUT. |
1328 `--------------------------------*/
1331 yy_symbol_print (FILE *yyoutput
, int yytype
, YYSTYPE
const * const yyvaluep
)
1333 YYFPRINTF (yyoutput
, "%s %s (",
1334 yytype
< YYNTOKENS
? "token" : "nterm", yytname
[yytype
]);
1336 yy_symbol_value_print (yyoutput
, yytype
, yyvaluep
);
1337 YYFPRINTF (yyoutput
, ")");
1340 /*------------------------------------------------------------------.
1341 | yy_stack_print -- Print the state stack from its BOTTOM up to its |
1343 `------------------------------------------------------------------*/
1346 yy_stack_print (yytype_int16
*yybottom
, yytype_int16
*yytop
)
1348 YYFPRINTF (stderr
, "Stack now");
1349 for (; yybottom
<= yytop
; yybottom
++)
1351 int yybot
= *yybottom
;
1352 YYFPRINTF (stderr
, " %d", yybot
);
1354 YYFPRINTF (stderr
, "\n");
1357 # define YY_STACK_PRINT(Bottom, Top) \
1360 yy_stack_print ((Bottom), (Top)); \
1364 /*------------------------------------------------.
1365 | Report that the YYRULE is going to be reduced. |
1366 `------------------------------------------------*/
1369 yy_reduce_print (yytype_int16
*yyssp
, YYSTYPE
*yyvsp
, int yyrule
)
1371 unsigned long int yylno
= yyrline
[yyrule
];
1372 int yynrhs
= yyr2
[yyrule
];
1374 YYFPRINTF (stderr
, "Reducing stack by rule %d (line %lu):\n",
1376 /* The symbols being reduced. */
1377 for (yyi
= 0; yyi
< yynrhs
; yyi
++)
1379 YYFPRINTF (stderr
, " $%d = ", yyi
+ 1);
1380 yy_symbol_print (stderr
,
1381 yystos
[yyssp
[yyi
+ 1 - yynrhs
]],
1382 &(yyvsp
[(yyi
+ 1) - (yynrhs
)])
1384 YYFPRINTF (stderr
, "\n");
1388 # define YY_REDUCE_PRINT(Rule) \
1391 yy_reduce_print (yyssp, yyvsp, Rule); \
1394 /* Nonzero means print parse trace. It is left uninitialized so that
1395 multiple parsers can coexist. */
1397 #else /* !YYDEBUG */
1398 # define YYDPRINTF(Args)
1399 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
1400 # define YY_STACK_PRINT(Bottom, Top)
1401 # define YY_REDUCE_PRINT(Rule)
1402 #endif /* !YYDEBUG */
1405 /* YYINITDEPTH -- initial size of the parser's stacks. */
1407 # define YYINITDEPTH 200
1410 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
1411 if the built-in stack extension method is used).
1413 Do not make this value too large; the results are undefined if
1414 YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH)
1415 evaluated with infinite-precision integer arithmetic. */
1418 # define YYMAXDEPTH 10000
1425 # if defined __GLIBC__ && defined _STRING_H
1426 # define yystrlen strlen
1428 /* Return the length of YYSTR. */
1430 yystrlen (const char *yystr
)
1433 for (yylen
= 0; yystr
[yylen
]; yylen
++)
1441 # if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
1442 # define yystpcpy stpcpy
1444 /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
1447 yystpcpy (char *yydest
, const char *yysrc
)
1450 const char *yys
= yysrc
;
1452 while ((*yyd
++ = *yys
++) != '\0')
1461 /* Copy to YYRES the contents of YYSTR after stripping away unnecessary
1462 quotes and backslashes, so that it's suitable for yyerror. The
1463 heuristic is that double-quoting is unnecessary unless the string
1464 contains an apostrophe, a comma, or backslash (other than
1465 backslash-backslash). YYSTR is taken from yytname. If YYRES is
1466 null, do not copy; instead, return the length of what the result
1469 yytnamerr (char *yyres
, const char *yystr
)
1474 char const *yyp
= yystr
;
1481 goto do_not_strip_quotes
;
1485 goto do_not_strip_quotes
;
1498 do_not_strip_quotes
: ;
1502 return yystrlen (yystr
);
1504 return yystpcpy (yyres
, yystr
) - yyres
;
1508 /* Copy into *YYMSG, which is of size *YYMSG_ALLOC, an error message
1509 about the unexpected token YYTOKEN for the state stack whose top is
1512 Return 0 if *YYMSG was successfully written. Return 1 if *YYMSG is
1513 not large enough to hold the message. In that case, also set
1514 *YYMSG_ALLOC to the required number of bytes. Return 2 if the
1515 required number of bytes is too large to store. */
1517 yysyntax_error (YYSIZE_T
*yymsg_alloc
, char **yymsg
,
1518 yytype_int16
*yyssp
, int yytoken
)
1520 YYSIZE_T yysize0
= yytnamerr (YY_NULLPTR
, yytname
[yytoken
]);
1521 YYSIZE_T yysize
= yysize0
;
1522 enum { YYERROR_VERBOSE_ARGS_MAXIMUM
= 5 };
1523 /* Internationalized format string. */
1524 const char *yyformat
= YY_NULLPTR
;
1525 /* Arguments of yyformat. */
1526 char const *yyarg
[YYERROR_VERBOSE_ARGS_MAXIMUM
];
1527 /* Number of reported tokens (one for the "unexpected", one per
1531 /* There are many possibilities here to consider:
1532 - If this state is a consistent state with a default action, then
1533 the only way this function was invoked is if the default action
1534 is an error action. In that case, don't check for expected
1535 tokens because there are none.
1536 - The only way there can be no lookahead present (in yychar) is if
1537 this state is a consistent state with a default action. Thus,
1538 detecting the absence of a lookahead is sufficient to determine
1539 that there is no unexpected or expected token to report. In that
1540 case, just report a simple "syntax error".
1541 - Don't assume there isn't a lookahead just because this state is a
1542 consistent state with a default action. There might have been a
1543 previous inconsistent state, consistent state with a non-default
1544 action, or user semantic action that manipulated yychar.
1545 - Of course, the expected token list depends on states to have
1546 correct lookahead information, and it depends on the parser not
1547 to perform extra reductions after fetching a lookahead from the
1548 scanner and before detecting a syntax error. Thus, state merging
1549 (from LALR or IELR) and default reductions corrupt the expected
1550 token list. However, the list is correct for canonical LR with
1551 one exception: it will still contain any token that will not be
1552 accepted due to an error action in a later state.
1554 if (yytoken
!= YYEMPTY
)
1556 int yyn
= yypact
[*yyssp
];
1557 yyarg
[yycount
++] = yytname
[yytoken
];
1558 if (!yypact_value_is_default (yyn
))
1560 /* Start YYX at -YYN if negative to avoid negative indexes in
1561 YYCHECK. In other words, skip the first -YYN actions for
1562 this state because they are default actions. */
1563 int yyxbegin
= yyn
< 0 ? -yyn
: 0;
1564 /* Stay within bounds of both yycheck and yytname. */
1565 int yychecklim
= YYLAST
- yyn
+ 1;
1566 int yyxend
= yychecklim
< YYNTOKENS
? yychecklim
: YYNTOKENS
;
1569 for (yyx
= yyxbegin
; yyx
< yyxend
; ++yyx
)
1570 if (yycheck
[yyx
+ yyn
] == yyx
&& yyx
!= YYTERROR
1571 && !yytable_value_is_error (yytable
[yyx
+ yyn
]))
1573 if (yycount
== YYERROR_VERBOSE_ARGS_MAXIMUM
)
1579 yyarg
[yycount
++] = yytname
[yyx
];
1581 YYSIZE_T yysize1
= yysize
+ yytnamerr (YY_NULLPTR
, yytname
[yyx
]);
1582 if (! (yysize
<= yysize1
1583 && yysize1
<= YYSTACK_ALLOC_MAXIMUM
))
1593 # define YYCASE_(N, S) \
1597 YYCASE_(0, YY_("syntax error"));
1598 YYCASE_(1, YY_("syntax error, unexpected %s"));
1599 YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s"));
1600 YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s"));
1601 YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s"));
1602 YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"));
1607 YYSIZE_T yysize1
= yysize
+ yystrlen (yyformat
);
1608 if (! (yysize
<= yysize1
&& yysize1
<= YYSTACK_ALLOC_MAXIMUM
))
1613 if (*yymsg_alloc
< yysize
)
1615 *yymsg_alloc
= 2 * yysize
;
1616 if (! (yysize
<= *yymsg_alloc
1617 && *yymsg_alloc
<= YYSTACK_ALLOC_MAXIMUM
))
1618 *yymsg_alloc
= YYSTACK_ALLOC_MAXIMUM
;
1622 /* Avoid sprintf, as that infringes on the user's name space.
1623 Don't have undefined behavior even if the translation
1624 produced a string with the wrong number of "%s"s. */
1628 while ((*yyp
= *yyformat
) != '\0')
1629 if (*yyp
== '%' && yyformat
[1] == 's' && yyi
< yycount
)
1631 yyp
+= yytnamerr (yyp
, yyarg
[yyi
++]);
1642 #endif /* YYERROR_VERBOSE */
1644 /*-----------------------------------------------.
1645 | Release the memory associated to this symbol. |
1646 `-----------------------------------------------*/
1649 yydestruct (const char *yymsg
, int yytype
, YYSTYPE
*yyvaluep
)
1654 YY_SYMBOL_PRINT (yymsg
, yytype
, yyvaluep
, yylocationp
);
1656 YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
1658 YY_IGNORE_MAYBE_UNINITIALIZED_END
1664 /* The lookahead symbol. */
1667 /* The semantic value of the lookahead symbol. */
1669 /* Number of syntax errors so far. */
1681 /* Number of tokens to shift before error messages enabled. */
1684 /* The stacks and their tools:
1685 'yyss': related to states.
1686 'yyvs': related to semantic values.
1688 Refer to the stacks through separate pointers, to allow yyoverflow
1689 to reallocate them elsewhere. */
1691 /* The state stack. */
1692 yytype_int16 yyssa
[YYINITDEPTH
];
1694 yytype_int16
*yyssp
;
1696 /* The semantic value stack. */
1697 YYSTYPE yyvsa
[YYINITDEPTH
];
1701 YYSIZE_T yystacksize
;
1705 /* Lookahead token as an internal (translated) token number. */
1707 /* The variables used to return semantic value and location from the
1712 /* Buffer for error messages, and its allocated size. */
1714 char *yymsg
= yymsgbuf
;
1715 YYSIZE_T yymsg_alloc
= sizeof yymsgbuf
;
1718 #define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N))
1720 /* The number of symbols on the RHS of the reduced rule.
1721 Keep to zero when no symbol should be popped. */
1724 yyssp
= yyss
= yyssa
;
1725 yyvsp
= yyvs
= yyvsa
;
1726 yystacksize
= YYINITDEPTH
;
1728 YYDPRINTF ((stderr
, "Starting parse\n"));
1733 yychar
= YYEMPTY
; /* Cause a token to be read. */
1736 /*------------------------------------------------------------.
1737 | yynewstate -- Push a new state, which is found in yystate. |
1738 `------------------------------------------------------------*/
1740 /* In all cases, when you get here, the value and location stacks
1741 have just been pushed. So pushing a state here evens the stacks. */
1747 if (yyss
+ yystacksize
- 1 <= yyssp
)
1749 /* Get the current used size of the three stacks, in elements. */
1750 YYSIZE_T yysize
= yyssp
- yyss
+ 1;
1754 /* Give user a chance to reallocate the stack. Use copies of
1755 these so that the &'s don't force the real ones into
1757 YYSTYPE
*yyvs1
= yyvs
;
1758 yytype_int16
*yyss1
= yyss
;
1760 /* Each stack pointer address is followed by the size of the
1761 data in use in that stack, in bytes. This used to be a
1762 conditional around just the two extra args, but that might
1763 be undefined if yyoverflow is a macro. */
1764 yyoverflow (YY_("memory exhausted"),
1765 &yyss1
, yysize
* sizeof (*yyssp
),
1766 &yyvs1
, yysize
* sizeof (*yyvsp
),
1772 #else /* no yyoverflow */
1773 # ifndef YYSTACK_RELOCATE
1774 goto yyexhaustedlab
;
1776 /* Extend the stack our own way. */
1777 if (YYMAXDEPTH
<= yystacksize
)
1778 goto yyexhaustedlab
;
1780 if (YYMAXDEPTH
< yystacksize
)
1781 yystacksize
= YYMAXDEPTH
;
1784 yytype_int16
*yyss1
= yyss
;
1785 union yyalloc
*yyptr
=
1786 (union yyalloc
*) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize
));
1788 goto yyexhaustedlab
;
1789 YYSTACK_RELOCATE (yyss_alloc
, yyss
);
1790 YYSTACK_RELOCATE (yyvs_alloc
, yyvs
);
1791 # undef YYSTACK_RELOCATE
1793 YYSTACK_FREE (yyss1
);
1796 #endif /* no yyoverflow */
1798 yyssp
= yyss
+ yysize
- 1;
1799 yyvsp
= yyvs
+ yysize
- 1;
1801 YYDPRINTF ((stderr
, "Stack size increased to %lu\n",
1802 (unsigned long int) yystacksize
));
1804 if (yyss
+ yystacksize
- 1 <= yyssp
)
1808 YYDPRINTF ((stderr
, "Entering state %d\n", yystate
));
1810 if (yystate
== YYFINAL
)
1820 /* Do appropriate processing given the current state. Read a
1821 lookahead token if we need one and don't already have one. */
1823 /* First try to decide what to do without reference to lookahead token. */
1824 yyn
= yypact
[yystate
];
1825 if (yypact_value_is_default (yyn
))
1828 /* Not known => get a lookahead token if don't already have one. */
1830 /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol. */
1831 if (yychar
== YYEMPTY
)
1833 YYDPRINTF ((stderr
, "Reading a token: "));
1837 if (yychar
<= YYEOF
)
1839 yychar
= yytoken
= YYEOF
;
1840 YYDPRINTF ((stderr
, "Now at end of input.\n"));
1844 yytoken
= YYTRANSLATE (yychar
);
1845 YY_SYMBOL_PRINT ("Next token is", yytoken
, &yylval
, &yylloc
);
1848 /* If the proper action on seeing token YYTOKEN is to reduce or to
1849 detect an error, take that action. */
1851 if (yyn
< 0 || YYLAST
< yyn
|| yycheck
[yyn
] != yytoken
)
1856 if (yytable_value_is_error (yyn
))
1862 /* Count tokens shifted since error; after three, turn off error
1867 /* Shift the lookahead token. */
1868 YY_SYMBOL_PRINT ("Shifting", yytoken
, &yylval
, &yylloc
);
1870 /* Discard the shifted token. */
1874 YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
1876 YY_IGNORE_MAYBE_UNINITIALIZED_END
1881 /*-----------------------------------------------------------.
1882 | yydefault -- do the default action for the current state. |
1883 `-----------------------------------------------------------*/
1885 yyn
= yydefact
[yystate
];
1891 /*-----------------------------.
1892 | yyreduce -- Do a reduction. |
1893 `-----------------------------*/
1895 /* yyn is the number of a rule to reduce with. */
1898 /* If YYLEN is nonzero, implement the default value of the action:
1901 Otherwise, the following line sets YYVAL to garbage.
1902 This behavior is undocumented and Bison
1903 users should not rely upon it. Assigning to YYVAL
1904 unconditionally makes the parser a bit smaller, and it avoids a
1905 GCC warning that YYVAL may be used uninitialized. */
1906 yyval
= yyvsp
[1-yylen
];
1909 YY_REDUCE_PRINT (yyn
);
1913 #line 387 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
1915 /* Case of regular command. Discard the error
1916 safety net,and return the command just parsed. */
1917 global_command
= (yyvsp
[-1].command
);
1918 eof_encountered
= 0;
1919 /* discard_parser_constructs (0); */
1920 if (parser_state
& PST_CMDSUBST
)
1921 parser_state
|= PST_EOFTOKEN
;
1924 #line 1925 "y.tab.c" /* yacc.c:1646 */
1928 #line 398 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
1930 /* Case of regular command, but not a very
1931 interesting one. Return a NULL command. */
1932 global_command
= (COMMAND
*)NULL
;
1933 if (parser_state
& PST_CMDSUBST
)
1934 parser_state
|= PST_EOFTOKEN
;
1937 #line 1938 "y.tab.c" /* yacc.c:1646 */
1941 #line 407 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
1943 /* Error during parsing. Return NULL command. */
1944 global_command
= (COMMAND
*)NULL
;
1945 eof_encountered
= 0;
1946 /* discard_parser_constructs (1); */
1947 if (interactive
&& parse_and_execute_level
== 0)
1956 #line 1957 "y.tab.c" /* yacc.c:1646 */
1960 #line 422 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
1962 /* Case of EOF seen by itself. Do ignoreeof or
1964 global_command
= (COMMAND
*)NULL
;
1965 handle_eof_input_unit ();
1968 #line 1969 "y.tab.c" /* yacc.c:1646 */
1972 #line 432 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
1973 { (yyval
.word_list
) = make_word_list ((yyvsp
[0].word
), (WORD_LIST
*)NULL
); }
1974 #line 1975 "y.tab.c" /* yacc.c:1646 */
1978 #line 434 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
1979 { (yyval
.word_list
) = make_word_list ((yyvsp
[0].word
), (yyvsp
[-1].word_list
)); }
1980 #line 1981 "y.tab.c" /* yacc.c:1646 */
1984 #line 438 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
1987 redir
.filename
= (yyvsp
[0].word
);
1988 (yyval
.redirect
) = make_redirection (source
, r_output_direction
, redir
, 0);
1990 #line 1991 "y.tab.c" /* yacc.c:1646 */
1994 #line 444 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
1997 redir
.filename
= (yyvsp
[0].word
);
1998 (yyval
.redirect
) = make_redirection (source
, r_input_direction
, redir
, 0);
2000 #line 2001 "y.tab.c" /* yacc.c:1646 */
2004 #line 450 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2006 source
.dest
= (yyvsp
[-2].number
);
2007 redir
.filename
= (yyvsp
[0].word
);
2008 (yyval
.redirect
) = make_redirection (source
, r_output_direction
, redir
, 0);
2010 #line 2011 "y.tab.c" /* yacc.c:1646 */
2014 #line 456 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2016 source
.dest
= (yyvsp
[-2].number
);
2017 redir
.filename
= (yyvsp
[0].word
);
2018 (yyval
.redirect
) = make_redirection (source
, r_input_direction
, redir
, 0);
2020 #line 2021 "y.tab.c" /* yacc.c:1646 */
2024 #line 462 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2026 source
.filename
= (yyvsp
[-2].word
);
2027 redir
.filename
= (yyvsp
[0].word
);
2028 (yyval
.redirect
) = make_redirection (source
, r_output_direction
, redir
, REDIR_VARASSIGN
);
2030 #line 2031 "y.tab.c" /* yacc.c:1646 */
2034 #line 468 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2036 source
.filename
= (yyvsp
[-2].word
);
2037 redir
.filename
= (yyvsp
[0].word
);
2038 (yyval
.redirect
) = make_redirection (source
, r_input_direction
, redir
, REDIR_VARASSIGN
);
2040 #line 2041 "y.tab.c" /* yacc.c:1646 */
2044 #line 474 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2047 redir
.filename
= (yyvsp
[0].word
);
2048 (yyval
.redirect
) = make_redirection (source
, r_appending_to
, redir
, 0);
2050 #line 2051 "y.tab.c" /* yacc.c:1646 */
2054 #line 480 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2056 source
.dest
= (yyvsp
[-2].number
);
2057 redir
.filename
= (yyvsp
[0].word
);
2058 (yyval
.redirect
) = make_redirection (source
, r_appending_to
, redir
, 0);
2060 #line 2061 "y.tab.c" /* yacc.c:1646 */
2064 #line 486 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2066 source
.filename
= (yyvsp
[-2].word
);
2067 redir
.filename
= (yyvsp
[0].word
);
2068 (yyval
.redirect
) = make_redirection (source
, r_appending_to
, redir
, REDIR_VARASSIGN
);
2070 #line 2071 "y.tab.c" /* yacc.c:1646 */
2074 #line 492 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2077 redir
.filename
= (yyvsp
[0].word
);
2078 (yyval
.redirect
) = make_redirection (source
, r_output_force
, redir
, 0);
2080 #line 2081 "y.tab.c" /* yacc.c:1646 */
2084 #line 498 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2086 source
.dest
= (yyvsp
[-2].number
);
2087 redir
.filename
= (yyvsp
[0].word
);
2088 (yyval
.redirect
) = make_redirection (source
, r_output_force
, redir
, 0);
2090 #line 2091 "y.tab.c" /* yacc.c:1646 */
2094 #line 504 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2096 source
.filename
= (yyvsp
[-2].word
);
2097 redir
.filename
= (yyvsp
[0].word
);
2098 (yyval
.redirect
) = make_redirection (source
, r_output_force
, redir
, REDIR_VARASSIGN
);
2100 #line 2101 "y.tab.c" /* yacc.c:1646 */
2104 #line 510 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2107 redir
.filename
= (yyvsp
[0].word
);
2108 (yyval
.redirect
) = make_redirection (source
, r_input_output
, redir
, 0);
2110 #line 2111 "y.tab.c" /* yacc.c:1646 */
2114 #line 516 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2116 source
.dest
= (yyvsp
[-2].number
);
2117 redir
.filename
= (yyvsp
[0].word
);
2118 (yyval
.redirect
) = make_redirection (source
, r_input_output
, redir
, 0);
2120 #line 2121 "y.tab.c" /* yacc.c:1646 */
2124 #line 522 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2126 source
.filename
= (yyvsp
[-2].word
);
2127 redir
.filename
= (yyvsp
[0].word
);
2128 (yyval
.redirect
) = make_redirection (source
, r_input_output
, redir
, REDIR_VARASSIGN
);
2130 #line 2131 "y.tab.c" /* yacc.c:1646 */
2134 #line 528 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2137 redir
.filename
= (yyvsp
[0].word
);
2138 (yyval
.redirect
) = make_redirection (source
, r_reading_until
, redir
, 0);
2139 push_heredoc ((yyval
.redirect
));
2141 #line 2142 "y.tab.c" /* yacc.c:1646 */
2145 #line 535 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2147 source
.dest
= (yyvsp
[-2].number
);
2148 redir
.filename
= (yyvsp
[0].word
);
2149 (yyval
.redirect
) = make_redirection (source
, r_reading_until
, redir
, 0);
2150 push_heredoc ((yyval
.redirect
));
2152 #line 2153 "y.tab.c" /* yacc.c:1646 */
2156 #line 542 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2158 source
.filename
= (yyvsp
[-2].word
);
2159 redir
.filename
= (yyvsp
[0].word
);
2160 (yyval
.redirect
) = make_redirection (source
, r_reading_until
, redir
, REDIR_VARASSIGN
);
2161 push_heredoc ((yyval
.redirect
));
2163 #line 2164 "y.tab.c" /* yacc.c:1646 */
2167 #line 549 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2170 redir
.filename
= (yyvsp
[0].word
);
2171 (yyval
.redirect
) = make_redirection (source
, r_deblank_reading_until
, redir
, 0);
2172 push_heredoc ((yyval
.redirect
));
2174 #line 2175 "y.tab.c" /* yacc.c:1646 */
2178 #line 556 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2180 source
.dest
= (yyvsp
[-2].number
);
2181 redir
.filename
= (yyvsp
[0].word
);
2182 (yyval
.redirect
) = make_redirection (source
, r_deblank_reading_until
, redir
, 0);
2183 push_heredoc ((yyval
.redirect
));
2185 #line 2186 "y.tab.c" /* yacc.c:1646 */
2189 #line 563 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2191 source
.filename
= (yyvsp
[-2].word
);
2192 redir
.filename
= (yyvsp
[0].word
);
2193 (yyval
.redirect
) = make_redirection (source
, r_deblank_reading_until
, redir
, REDIR_VARASSIGN
);
2194 push_heredoc ((yyval
.redirect
));
2196 #line 2197 "y.tab.c" /* yacc.c:1646 */
2200 #line 570 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2203 redir
.filename
= (yyvsp
[0].word
);
2204 (yyval
.redirect
) = make_redirection (source
, r_reading_string
, redir
, 0);
2206 #line 2207 "y.tab.c" /* yacc.c:1646 */
2210 #line 576 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2212 source
.dest
= (yyvsp
[-2].number
);
2213 redir
.filename
= (yyvsp
[0].word
);
2214 (yyval
.redirect
) = make_redirection (source
, r_reading_string
, redir
, 0);
2216 #line 2217 "y.tab.c" /* yacc.c:1646 */
2220 #line 582 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2222 source
.filename
= (yyvsp
[-2].word
);
2223 redir
.filename
= (yyvsp
[0].word
);
2224 (yyval
.redirect
) = make_redirection (source
, r_reading_string
, redir
, REDIR_VARASSIGN
);
2226 #line 2227 "y.tab.c" /* yacc.c:1646 */
2230 #line 588 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2233 redir
.dest
= (yyvsp
[0].number
);
2234 (yyval
.redirect
) = make_redirection (source
, r_duplicating_input
, redir
, 0);
2236 #line 2237 "y.tab.c" /* yacc.c:1646 */
2240 #line 594 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2242 source
.dest
= (yyvsp
[-2].number
);
2243 redir
.dest
= (yyvsp
[0].number
);
2244 (yyval
.redirect
) = make_redirection (source
, r_duplicating_input
, redir
, 0);
2246 #line 2247 "y.tab.c" /* yacc.c:1646 */
2250 #line 600 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2252 source
.filename
= (yyvsp
[-2].word
);
2253 redir
.dest
= (yyvsp
[0].number
);
2254 (yyval
.redirect
) = make_redirection (source
, r_duplicating_input
, redir
, REDIR_VARASSIGN
);
2256 #line 2257 "y.tab.c" /* yacc.c:1646 */
2260 #line 606 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2263 redir
.dest
= (yyvsp
[0].number
);
2264 (yyval
.redirect
) = make_redirection (source
, r_duplicating_output
, redir
, 0);
2266 #line 2267 "y.tab.c" /* yacc.c:1646 */
2270 #line 612 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2272 source
.dest
= (yyvsp
[-2].number
);
2273 redir
.dest
= (yyvsp
[0].number
);
2274 (yyval
.redirect
) = make_redirection (source
, r_duplicating_output
, redir
, 0);
2276 #line 2277 "y.tab.c" /* yacc.c:1646 */
2280 #line 618 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2282 source
.filename
= (yyvsp
[-2].word
);
2283 redir
.dest
= (yyvsp
[0].number
);
2284 (yyval
.redirect
) = make_redirection (source
, r_duplicating_output
, redir
, REDIR_VARASSIGN
);
2286 #line 2287 "y.tab.c" /* yacc.c:1646 */
2290 #line 624 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2293 redir
.filename
= (yyvsp
[0].word
);
2294 (yyval
.redirect
) = make_redirection (source
, r_duplicating_input_word
, redir
, 0);
2296 #line 2297 "y.tab.c" /* yacc.c:1646 */
2300 #line 630 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2302 source
.dest
= (yyvsp
[-2].number
);
2303 redir
.filename
= (yyvsp
[0].word
);
2304 (yyval
.redirect
) = make_redirection (source
, r_duplicating_input_word
, redir
, 0);
2306 #line 2307 "y.tab.c" /* yacc.c:1646 */
2310 #line 636 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2312 source
.filename
= (yyvsp
[-2].word
);
2313 redir
.filename
= (yyvsp
[0].word
);
2314 (yyval
.redirect
) = make_redirection (source
, r_duplicating_input_word
, redir
, REDIR_VARASSIGN
);
2316 #line 2317 "y.tab.c" /* yacc.c:1646 */
2320 #line 642 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2323 redir
.filename
= (yyvsp
[0].word
);
2324 (yyval
.redirect
) = make_redirection (source
, r_duplicating_output_word
, redir
, 0);
2326 #line 2327 "y.tab.c" /* yacc.c:1646 */
2330 #line 648 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2332 source
.dest
= (yyvsp
[-2].number
);
2333 redir
.filename
= (yyvsp
[0].word
);
2334 (yyval
.redirect
) = make_redirection (source
, r_duplicating_output_word
, redir
, 0);
2336 #line 2337 "y.tab.c" /* yacc.c:1646 */
2340 #line 654 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2342 source
.filename
= (yyvsp
[-2].word
);
2343 redir
.filename
= (yyvsp
[0].word
);
2344 (yyval
.redirect
) = make_redirection (source
, r_duplicating_output_word
, redir
, REDIR_VARASSIGN
);
2346 #line 2347 "y.tab.c" /* yacc.c:1646 */
2350 #line 660 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2354 (yyval
.redirect
) = make_redirection (source
, r_close_this
, redir
, 0);
2356 #line 2357 "y.tab.c" /* yacc.c:1646 */
2360 #line 666 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2362 source
.dest
= (yyvsp
[-2].number
);
2364 (yyval
.redirect
) = make_redirection (source
, r_close_this
, redir
, 0);
2366 #line 2367 "y.tab.c" /* yacc.c:1646 */
2370 #line 672 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2372 source
.filename
= (yyvsp
[-2].word
);
2374 (yyval
.redirect
) = make_redirection (source
, r_close_this
, redir
, REDIR_VARASSIGN
);
2376 #line 2377 "y.tab.c" /* yacc.c:1646 */
2380 #line 678 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2384 (yyval
.redirect
) = make_redirection (source
, r_close_this
, redir
, 0);
2386 #line 2387 "y.tab.c" /* yacc.c:1646 */
2390 #line 684 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2392 source
.dest
= (yyvsp
[-2].number
);
2394 (yyval
.redirect
) = make_redirection (source
, r_close_this
, redir
, 0);
2396 #line 2397 "y.tab.c" /* yacc.c:1646 */
2400 #line 690 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2402 source
.filename
= (yyvsp
[-2].word
);
2404 (yyval
.redirect
) = make_redirection (source
, r_close_this
, redir
, REDIR_VARASSIGN
);
2406 #line 2407 "y.tab.c" /* yacc.c:1646 */
2410 #line 696 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2413 redir
.filename
= (yyvsp
[0].word
);
2414 (yyval
.redirect
) = make_redirection (source
, r_err_and_out
, redir
, 0);
2416 #line 2417 "y.tab.c" /* yacc.c:1646 */
2420 #line 702 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2423 redir
.filename
= (yyvsp
[0].word
);
2424 (yyval
.redirect
) = make_redirection (source
, r_append_err_and_out
, redir
, 0);
2426 #line 2427 "y.tab.c" /* yacc.c:1646 */
2430 #line 710 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2431 { (yyval
.element
).word
= (yyvsp
[0].word
); (yyval
.element
).redirect
= 0; }
2432 #line 2433 "y.tab.c" /* yacc.c:1646 */
2436 #line 712 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2437 { (yyval
.element
).word
= (yyvsp
[0].word
); (yyval
.element
).redirect
= 0; }
2438 #line 2439 "y.tab.c" /* yacc.c:1646 */
2442 #line 714 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2443 { (yyval
.element
).redirect
= (yyvsp
[0].redirect
); (yyval
.element
).word
= 0; }
2444 #line 2445 "y.tab.c" /* yacc.c:1646 */
2448 #line 718 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2450 (yyval
.redirect
) = (yyvsp
[0].redirect
);
2452 #line 2453 "y.tab.c" /* yacc.c:1646 */
2456 #line 722 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2458 register REDIRECT
*t
;
2460 for (t
= (yyvsp
[-1].redirect
); t
->next
; t
= t
->next
)
2462 t
->next
= (yyvsp
[0].redirect
);
2463 (yyval
.redirect
) = (yyvsp
[-1].redirect
);
2465 #line 2466 "y.tab.c" /* yacc.c:1646 */
2469 #line 733 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2470 { (yyval
.command
) = make_simple_command ((yyvsp
[0].element
), (COMMAND
*)NULL
); }
2471 #line 2472 "y.tab.c" /* yacc.c:1646 */
2475 #line 735 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2476 { (yyval
.command
) = make_simple_command ((yyvsp
[0].element
), (yyvsp
[-1].command
)); }
2477 #line 2478 "y.tab.c" /* yacc.c:1646 */
2481 #line 739 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2482 { (yyval
.command
) = clean_simple_command ((yyvsp
[0].command
)); }
2483 #line 2484 "y.tab.c" /* yacc.c:1646 */
2487 #line 741 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2488 { (yyval
.command
) = (yyvsp
[0].command
); }
2489 #line 2490 "y.tab.c" /* yacc.c:1646 */
2493 #line 743 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2497 tc
= (yyvsp
[-1].command
);
2500 register REDIRECT
*t
;
2501 for (t
= tc
->redirects
; t
->next
; t
= t
->next
)
2503 t
->next
= (yyvsp
[0].redirect
);
2506 tc
->redirects
= (yyvsp
[0].redirect
);
2507 (yyval
.command
) = (yyvsp
[-1].command
);
2509 #line 2510 "y.tab.c" /* yacc.c:1646 */
2513 #line 759 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2514 { (yyval
.command
) = (yyvsp
[0].command
); }
2515 #line 2516 "y.tab.c" /* yacc.c:1646 */
2519 #line 761 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2520 { (yyval
.command
) = (yyvsp
[0].command
); }
2521 #line 2522 "y.tab.c" /* yacc.c:1646 */
2525 #line 765 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2526 { (yyval
.command
) = (yyvsp
[0].command
); }
2527 #line 2528 "y.tab.c" /* yacc.c:1646 */
2531 #line 767 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2532 { (yyval
.command
) = (yyvsp
[0].command
); }
2533 #line 2534 "y.tab.c" /* yacc.c:1646 */
2537 #line 769 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2538 { (yyval
.command
) = make_while_command ((yyvsp
[-3].command
), (yyvsp
[-1].command
)); }
2539 #line 2540 "y.tab.c" /* yacc.c:1646 */
2543 #line 771 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2544 { (yyval
.command
) = make_until_command ((yyvsp
[-3].command
), (yyvsp
[-1].command
)); }
2545 #line 2546 "y.tab.c" /* yacc.c:1646 */
2549 #line 773 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2550 { (yyval
.command
) = (yyvsp
[0].command
); }
2551 #line 2552 "y.tab.c" /* yacc.c:1646 */
2555 #line 775 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2556 { (yyval
.command
) = (yyvsp
[0].command
); }
2557 #line 2558 "y.tab.c" /* yacc.c:1646 */
2561 #line 777 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2562 { (yyval
.command
) = (yyvsp
[0].command
); }
2563 #line 2564 "y.tab.c" /* yacc.c:1646 */
2567 #line 779 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2568 { (yyval
.command
) = (yyvsp
[0].command
); }
2569 #line 2570 "y.tab.c" /* yacc.c:1646 */
2573 #line 781 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2574 { (yyval
.command
) = (yyvsp
[0].command
); }
2575 #line 2576 "y.tab.c" /* yacc.c:1646 */
2579 #line 783 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2580 { (yyval
.command
) = (yyvsp
[0].command
); }
2581 #line 2582 "y.tab.c" /* yacc.c:1646 */
2585 #line 785 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2586 { (yyval
.command
) = (yyvsp
[0].command
); }
2587 #line 2588 "y.tab.c" /* yacc.c:1646 */
2591 #line 789 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2593 (yyval
.command
) = make_for_command ((yyvsp
[-4].word
), add_string_to_list ("\"$@\"", (WORD_LIST
*)NULL
), (yyvsp
[-1].command
), word_lineno
[word_top
]);
2594 if (word_top
> 0) word_top
--;
2596 #line 2597 "y.tab.c" /* yacc.c:1646 */
2600 #line 794 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2602 (yyval
.command
) = make_for_command ((yyvsp
[-4].word
), add_string_to_list ("\"$@\"", (WORD_LIST
*)NULL
), (yyvsp
[-1].command
), word_lineno
[word_top
]);
2603 if (word_top
> 0) word_top
--;
2605 #line 2606 "y.tab.c" /* yacc.c:1646 */
2609 #line 799 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2611 (yyval
.command
) = make_for_command ((yyvsp
[-5].word
), add_string_to_list ("\"$@\"", (WORD_LIST
*)NULL
), (yyvsp
[-1].command
), word_lineno
[word_top
]);
2612 if (word_top
> 0) word_top
--;
2614 #line 2615 "y.tab.c" /* yacc.c:1646 */
2618 #line 804 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2620 (yyval
.command
) = make_for_command ((yyvsp
[-5].word
), add_string_to_list ("\"$@\"", (WORD_LIST
*)NULL
), (yyvsp
[-1].command
), word_lineno
[word_top
]);
2621 if (word_top
> 0) word_top
--;
2623 #line 2624 "y.tab.c" /* yacc.c:1646 */
2627 #line 809 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2629 (yyval
.command
) = make_for_command ((yyvsp
[-8].word
), REVERSE_LIST ((yyvsp
[-5].word_list
), WORD_LIST
*), (yyvsp
[-1].command
), word_lineno
[word_top
]);
2630 if (word_top
> 0) word_top
--;
2632 #line 2633 "y.tab.c" /* yacc.c:1646 */
2636 #line 814 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2638 (yyval
.command
) = make_for_command ((yyvsp
[-8].word
), REVERSE_LIST ((yyvsp
[-5].word_list
), WORD_LIST
*), (yyvsp
[-1].command
), word_lineno
[word_top
]);
2639 if (word_top
> 0) word_top
--;
2641 #line 2642 "y.tab.c" /* yacc.c:1646 */
2645 #line 819 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2647 (yyval
.command
) = make_for_command ((yyvsp
[-7].word
), (WORD_LIST
*)NULL
, (yyvsp
[-1].command
), word_lineno
[word_top
]);
2648 if (word_top
> 0) word_top
--;
2650 #line 2651 "y.tab.c" /* yacc.c:1646 */
2654 #line 824 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2656 (yyval
.command
) = make_for_command ((yyvsp
[-7].word
), (WORD_LIST
*)NULL
, (yyvsp
[-1].command
), word_lineno
[word_top
]);
2657 if (word_top
> 0) word_top
--;
2659 #line 2660 "y.tab.c" /* yacc.c:1646 */
2663 #line 831 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2665 (yyval
.command
) = make_arith_for_command ((yyvsp
[-5].word_list
), (yyvsp
[-1].command
), arith_for_lineno
);
2666 if (word_top
> 0) word_top
--;
2668 #line 2669 "y.tab.c" /* yacc.c:1646 */
2672 #line 836 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2674 (yyval
.command
) = make_arith_for_command ((yyvsp
[-5].word_list
), (yyvsp
[-1].command
), arith_for_lineno
);
2675 if (word_top
> 0) word_top
--;
2677 #line 2678 "y.tab.c" /* yacc.c:1646 */
2681 #line 841 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2683 (yyval
.command
) = make_arith_for_command ((yyvsp
[-3].word_list
), (yyvsp
[-1].command
), arith_for_lineno
);
2684 if (word_top
> 0) word_top
--;
2686 #line 2687 "y.tab.c" /* yacc.c:1646 */
2690 #line 846 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2692 (yyval
.command
) = make_arith_for_command ((yyvsp
[-3].word_list
), (yyvsp
[-1].command
), arith_for_lineno
);
2693 if (word_top
> 0) word_top
--;
2695 #line 2696 "y.tab.c" /* yacc.c:1646 */
2699 #line 853 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2701 (yyval
.command
) = make_select_command ((yyvsp
[-4].word
), add_string_to_list ("\"$@\"", (WORD_LIST
*)NULL
), (yyvsp
[-1].command
), word_lineno
[word_top
]);
2702 if (word_top
> 0) word_top
--;
2704 #line 2705 "y.tab.c" /* yacc.c:1646 */
2708 #line 858 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2710 (yyval
.command
) = make_select_command ((yyvsp
[-4].word
), add_string_to_list ("\"$@\"", (WORD_LIST
*)NULL
), (yyvsp
[-1].command
), word_lineno
[word_top
]);
2711 if (word_top
> 0) word_top
--;
2713 #line 2714 "y.tab.c" /* yacc.c:1646 */
2717 #line 863 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2719 (yyval
.command
) = make_select_command ((yyvsp
[-5].word
), add_string_to_list ("\"$@\"", (WORD_LIST
*)NULL
), (yyvsp
[-1].command
), word_lineno
[word_top
]);
2720 if (word_top
> 0) word_top
--;
2722 #line 2723 "y.tab.c" /* yacc.c:1646 */
2726 #line 868 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2728 (yyval
.command
) = make_select_command ((yyvsp
[-5].word
), add_string_to_list ("\"$@\"", (WORD_LIST
*)NULL
), (yyvsp
[-1].command
), word_lineno
[word_top
]);
2729 if (word_top
> 0) word_top
--;
2731 #line 2732 "y.tab.c" /* yacc.c:1646 */
2735 #line 873 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2737 (yyval
.command
) = make_select_command ((yyvsp
[-8].word
), REVERSE_LIST ((yyvsp
[-5].word_list
), WORD_LIST
*), (yyvsp
[-1].command
), word_lineno
[word_top
]);
2738 if (word_top
> 0) word_top
--;
2740 #line 2741 "y.tab.c" /* yacc.c:1646 */
2744 #line 878 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2746 (yyval
.command
) = make_select_command ((yyvsp
[-8].word
), REVERSE_LIST ((yyvsp
[-5].word_list
), WORD_LIST
*), (yyvsp
[-1].command
), word_lineno
[word_top
]);
2747 if (word_top
> 0) word_top
--;
2749 #line 2750 "y.tab.c" /* yacc.c:1646 */
2753 #line 885 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2755 (yyval
.command
) = make_case_command ((yyvsp
[-4].word
), (PATTERN_LIST
*)NULL
, word_lineno
[word_top
]);
2756 if (word_top
> 0) word_top
--;
2758 #line 2759 "y.tab.c" /* yacc.c:1646 */
2762 #line 890 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2764 (yyval
.command
) = make_case_command ((yyvsp
[-5].word
), (yyvsp
[-2].pattern
), word_lineno
[word_top
]);
2765 if (word_top
> 0) word_top
--;
2767 #line 2768 "y.tab.c" /* yacc.c:1646 */
2771 #line 895 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2773 (yyval
.command
) = make_case_command ((yyvsp
[-4].word
), (yyvsp
[-1].pattern
), word_lineno
[word_top
]);
2774 if (word_top
> 0) word_top
--;
2776 #line 2777 "y.tab.c" /* yacc.c:1646 */
2780 #line 902 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2781 { (yyval
.command
) = make_function_def ((yyvsp
[-4].word
), (yyvsp
[0].command
), function_dstart
, function_bstart
); }
2782 #line 2783 "y.tab.c" /* yacc.c:1646 */
2786 #line 905 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2787 { (yyval
.command
) = make_function_def ((yyvsp
[-4].word
), (yyvsp
[0].command
), function_dstart
, function_bstart
); }
2788 #line 2789 "y.tab.c" /* yacc.c:1646 */
2792 #line 908 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2793 { (yyval
.command
) = make_function_def ((yyvsp
[-2].word
), (yyvsp
[0].command
), function_dstart
, function_bstart
); }
2794 #line 2795 "y.tab.c" /* yacc.c:1646 */
2798 #line 912 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2799 { (yyval
.command
) = (yyvsp
[0].command
); }
2800 #line 2801 "y.tab.c" /* yacc.c:1646 */
2804 #line 914 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2808 tc
= (yyvsp
[-1].command
);
2809 /* According to Posix.2 3.9.5, redirections
2810 specified after the body of a function should
2811 be attached to the function and performed when
2812 the function is executed, not as part of the
2813 function definition command. */
2814 /* XXX - I don't think it matters, but we might
2815 want to change this in the future to avoid
2816 problems differentiating between a function
2817 definition with a redirection and a function
2818 definition containing a single command with a
2819 redirection. The two are semantically equivalent,
2820 though -- the only difference is in how the
2821 command printing code displays the redirections. */
2824 register REDIRECT
*t
;
2825 for (t
= tc
->redirects
; t
->next
; t
= t
->next
)
2827 t
->next
= (yyvsp
[0].redirect
);
2830 tc
->redirects
= (yyvsp
[0].redirect
);
2831 (yyval
.command
) = (yyvsp
[-1].command
);
2833 #line 2834 "y.tab.c" /* yacc.c:1646 */
2837 #line 945 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2839 (yyval
.command
) = make_subshell_command ((yyvsp
[-1].command
));
2840 (yyval
.command
)->flags
|= CMD_WANT_SUBSHELL
;
2842 #line 2843 "y.tab.c" /* yacc.c:1646 */
2846 #line 952 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2848 (yyval
.command
) = make_coproc_command ("COPROC", (yyvsp
[0].command
));
2849 (yyval
.command
)->flags
|= CMD_WANT_SUBSHELL
|CMD_COPROC_SUBSHELL
;
2851 #line 2852 "y.tab.c" /* yacc.c:1646 */
2855 #line 957 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2859 tc
= (yyvsp
[-1].command
);
2862 register REDIRECT
*t
;
2863 for (t
= tc
->redirects
; t
->next
; t
= t
->next
)
2865 t
->next
= (yyvsp
[0].redirect
);
2868 tc
->redirects
= (yyvsp
[0].redirect
);
2869 (yyval
.command
) = make_coproc_command ("COPROC", (yyvsp
[-1].command
));
2870 (yyval
.command
)->flags
|= CMD_WANT_SUBSHELL
|CMD_COPROC_SUBSHELL
;
2872 #line 2873 "y.tab.c" /* yacc.c:1646 */
2876 #line 974 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2878 (yyval
.command
) = make_coproc_command ((yyvsp
[-1].word
)->word
, (yyvsp
[0].command
));
2879 (yyval
.command
)->flags
|= CMD_WANT_SUBSHELL
|CMD_COPROC_SUBSHELL
;
2881 #line 2882 "y.tab.c" /* yacc.c:1646 */
2885 #line 979 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2889 tc
= (yyvsp
[-1].command
);
2892 register REDIRECT
*t
;
2893 for (t
= tc
->redirects
; t
->next
; t
= t
->next
)
2895 t
->next
= (yyvsp
[0].redirect
);
2898 tc
->redirects
= (yyvsp
[0].redirect
);
2899 (yyval
.command
) = make_coproc_command ((yyvsp
[-2].word
)->word
, (yyvsp
[-1].command
));
2900 (yyval
.command
)->flags
|= CMD_WANT_SUBSHELL
|CMD_COPROC_SUBSHELL
;
2902 #line 2903 "y.tab.c" /* yacc.c:1646 */
2906 #line 996 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2908 (yyval
.command
) = make_coproc_command ("COPROC", clean_simple_command ((yyvsp
[0].command
)));
2909 (yyval
.command
)->flags
|= CMD_WANT_SUBSHELL
|CMD_COPROC_SUBSHELL
;
2911 #line 2912 "y.tab.c" /* yacc.c:1646 */
2915 #line 1003 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2916 { (yyval
.command
) = make_if_command ((yyvsp
[-3].command
), (yyvsp
[-1].command
), (COMMAND
*)NULL
); }
2917 #line 2918 "y.tab.c" /* yacc.c:1646 */
2921 #line 1005 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2922 { (yyval
.command
) = make_if_command ((yyvsp
[-5].command
), (yyvsp
[-3].command
), (yyvsp
[-1].command
)); }
2923 #line 2924 "y.tab.c" /* yacc.c:1646 */
2927 #line 1007 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2928 { (yyval
.command
) = make_if_command ((yyvsp
[-4].command
), (yyvsp
[-2].command
), (yyvsp
[-1].command
)); }
2929 #line 2930 "y.tab.c" /* yacc.c:1646 */
2933 #line 1012 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2934 { (yyval
.command
) = make_group_command ((yyvsp
[-1].command
)); }
2935 #line 2936 "y.tab.c" /* yacc.c:1646 */
2939 #line 1016 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2940 { (yyval
.command
) = make_arith_command ((yyvsp
[0].word_list
)); }
2941 #line 2942 "y.tab.c" /* yacc.c:1646 */
2945 #line 1020 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2946 { (yyval
.command
) = (yyvsp
[-1].command
); }
2947 #line 2948 "y.tab.c" /* yacc.c:1646 */
2951 #line 1024 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2952 { (yyval
.command
) = make_if_command ((yyvsp
[-2].command
), (yyvsp
[0].command
), (COMMAND
*)NULL
); }
2953 #line 2954 "y.tab.c" /* yacc.c:1646 */
2957 #line 1026 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2958 { (yyval
.command
) = make_if_command ((yyvsp
[-4].command
), (yyvsp
[-2].command
), (yyvsp
[0].command
)); }
2959 #line 2960 "y.tab.c" /* yacc.c:1646 */
2963 #line 1028 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2964 { (yyval
.command
) = make_if_command ((yyvsp
[-3].command
), (yyvsp
[-1].command
), (yyvsp
[0].command
)); }
2965 #line 2966 "y.tab.c" /* yacc.c:1646 */
2969 #line 1033 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2970 { (yyvsp
[0].pattern
)->next
= (yyvsp
[-1].pattern
); (yyval
.pattern
) = (yyvsp
[0].pattern
); }
2971 #line 2972 "y.tab.c" /* yacc.c:1646 */
2975 #line 1037 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2976 { (yyval
.pattern
) = make_pattern_list ((yyvsp
[-2].word_list
), (yyvsp
[0].command
)); }
2977 #line 2978 "y.tab.c" /* yacc.c:1646 */
2981 #line 1039 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2982 { (yyval
.pattern
) = make_pattern_list ((yyvsp
[-2].word_list
), (COMMAND
*)NULL
); }
2983 #line 2984 "y.tab.c" /* yacc.c:1646 */
2987 #line 1041 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2988 { (yyval
.pattern
) = make_pattern_list ((yyvsp
[-2].word_list
), (yyvsp
[0].command
)); }
2989 #line 2990 "y.tab.c" /* yacc.c:1646 */
2993 #line 1043 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2994 { (yyval
.pattern
) = make_pattern_list ((yyvsp
[-2].word_list
), (COMMAND
*)NULL
); }
2995 #line 2996 "y.tab.c" /* yacc.c:1646 */
2999 #line 1047 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3000 { (yyval
.pattern
) = (yyvsp
[-1].pattern
); }
3001 #line 3002 "y.tab.c" /* yacc.c:1646 */
3005 #line 1049 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3006 { (yyvsp
[-1].pattern
)->next
= (yyvsp
[-2].pattern
); (yyval
.pattern
) = (yyvsp
[-1].pattern
); }
3007 #line 3008 "y.tab.c" /* yacc.c:1646 */
3011 #line 1051 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3012 { (yyvsp
[-1].pattern
)->flags
|= CASEPAT_FALLTHROUGH
; (yyval
.pattern
) = (yyvsp
[-1].pattern
); }
3013 #line 3014 "y.tab.c" /* yacc.c:1646 */
3017 #line 1053 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3018 { (yyvsp
[-1].pattern
)->flags
|= CASEPAT_FALLTHROUGH
; (yyvsp
[-1].pattern
)->next
= (yyvsp
[-2].pattern
); (yyval
.pattern
) = (yyvsp
[-1].pattern
); }
3019 #line 3020 "y.tab.c" /* yacc.c:1646 */
3023 #line 1055 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3024 { (yyvsp
[-1].pattern
)->flags
|= CASEPAT_TESTNEXT
; (yyval
.pattern
) = (yyvsp
[-1].pattern
); }
3025 #line 3026 "y.tab.c" /* yacc.c:1646 */
3029 #line 1057 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3030 { (yyvsp
[-1].pattern
)->flags
|= CASEPAT_TESTNEXT
; (yyvsp
[-1].pattern
)->next
= (yyvsp
[-2].pattern
); (yyval
.pattern
) = (yyvsp
[-1].pattern
); }
3031 #line 3032 "y.tab.c" /* yacc.c:1646 */
3035 #line 1061 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3036 { (yyval
.word_list
) = make_word_list ((yyvsp
[0].word
), (WORD_LIST
*)NULL
); }
3037 #line 3038 "y.tab.c" /* yacc.c:1646 */
3041 #line 1063 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3042 { (yyval
.word_list
) = make_word_list ((yyvsp
[0].word
), (yyvsp
[-2].word_list
)); }
3043 #line 3044 "y.tab.c" /* yacc.c:1646 */
3047 #line 1072 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3049 (yyval
.command
) = (yyvsp
[0].command
);
3051 gather_here_documents ();
3053 #line 3054 "y.tab.c" /* yacc.c:1646 */
3057 #line 1081 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3059 (yyval
.command
) = (yyvsp
[0].command
);
3061 #line 3062 "y.tab.c" /* yacc.c:1646 */
3065 #line 1088 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3067 if ((yyvsp
[-2].command
)->type
== cm_connection
)
3068 (yyval
.command
) = connect_async_list ((yyvsp
[-2].command
), (COMMAND
*)NULL
, '&');
3070 (yyval
.command
) = command_connect ((yyvsp
[-2].command
), (COMMAND
*)NULL
, '&');
3072 #line 3073 "y.tab.c" /* yacc.c:1646 */
3076 #line 1099 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3077 { (yyval
.command
) = command_connect ((yyvsp
[-3].command
), (yyvsp
[0].command
), AND_AND
); }
3078 #line 3079 "y.tab.c" /* yacc.c:1646 */
3082 #line 1101 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3083 { (yyval
.command
) = command_connect ((yyvsp
[-3].command
), (yyvsp
[0].command
), OR_OR
); }
3084 #line 3085 "y.tab.c" /* yacc.c:1646 */
3088 #line 1103 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3090 if ((yyvsp
[-3].command
)->type
== cm_connection
)
3091 (yyval
.command
) = connect_async_list ((yyvsp
[-3].command
), (yyvsp
[0].command
), '&');
3093 (yyval
.command
) = command_connect ((yyvsp
[-3].command
), (yyvsp
[0].command
), '&');
3095 #line 3096 "y.tab.c" /* yacc.c:1646 */
3099 #line 1110 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3100 { (yyval
.command
) = command_connect ((yyvsp
[-3].command
), (yyvsp
[0].command
), ';'); }
3101 #line 3102 "y.tab.c" /* yacc.c:1646 */
3105 #line 1112 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3106 { (yyval
.command
) = command_connect ((yyvsp
[-3].command
), (yyvsp
[0].command
), ';'); }
3107 #line 3108 "y.tab.c" /* yacc.c:1646 */
3111 #line 1114 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3112 { (yyval
.command
) = (yyvsp
[0].command
); }
3113 #line 3114 "y.tab.c" /* yacc.c:1646 */
3117 #line 1122 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3118 { (yyval
.number
) = '\n'; }
3119 #line 3120 "y.tab.c" /* yacc.c:1646 */
3123 #line 1124 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3124 { (yyval
.number
) = ';'; }
3125 #line 3126 "y.tab.c" /* yacc.c:1646 */
3129 #line 1126 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3130 { (yyval
.number
) = yacc_EOF
; }
3131 #line 3132 "y.tab.c" /* yacc.c:1646 */
3135 #line 1140 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3137 (yyval
.command
) = (yyvsp
[0].command
);
3139 gather_here_documents ();
3140 if ((parser_state
& PST_CMDSUBST
) && current_token
== shell_eof_token
)
3142 global_command
= (yyvsp
[0].command
);
3143 eof_encountered
= 0;
3144 rewind_input_string ();
3148 #line 3149 "y.tab.c" /* yacc.c:1646 */
3152 #line 1153 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3154 if ((yyvsp
[-1].command
)->type
== cm_connection
)
3155 (yyval
.command
) = connect_async_list ((yyvsp
[-1].command
), (COMMAND
*)NULL
, '&');
3157 (yyval
.command
) = command_connect ((yyvsp
[-1].command
), (COMMAND
*)NULL
, '&');
3159 gather_here_documents ();
3160 if ((parser_state
& PST_CMDSUBST
) && current_token
== shell_eof_token
)
3162 global_command
= (yyvsp
[-1].command
);
3163 eof_encountered
= 0;
3164 rewind_input_string ();
3168 #line 3169 "y.tab.c" /* yacc.c:1646 */
3172 #line 1169 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3174 (yyval
.command
) = (yyvsp
[-1].command
);
3176 gather_here_documents ();
3177 if ((parser_state
& PST_CMDSUBST
) && current_token
== shell_eof_token
)
3179 global_command
= (yyvsp
[-1].command
);
3180 eof_encountered
= 0;
3181 rewind_input_string ();
3185 #line 3186 "y.tab.c" /* yacc.c:1646 */
3189 #line 1184 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3190 { (yyval
.command
) = command_connect ((yyvsp
[-3].command
), (yyvsp
[0].command
), AND_AND
); }
3191 #line 3192 "y.tab.c" /* yacc.c:1646 */
3195 #line 1186 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3196 { (yyval
.command
) = command_connect ((yyvsp
[-3].command
), (yyvsp
[0].command
), OR_OR
); }
3197 #line 3198 "y.tab.c" /* yacc.c:1646 */
3201 #line 1188 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3203 if ((yyvsp
[-2].command
)->type
== cm_connection
)
3204 (yyval
.command
) = connect_async_list ((yyvsp
[-2].command
), (yyvsp
[0].command
), '&');
3206 (yyval
.command
) = command_connect ((yyvsp
[-2].command
), (yyvsp
[0].command
), '&');
3208 #line 3209 "y.tab.c" /* yacc.c:1646 */
3212 #line 1195 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3213 { (yyval
.command
) = command_connect ((yyvsp
[-2].command
), (yyvsp
[0].command
), ';'); }
3214 #line 3215 "y.tab.c" /* yacc.c:1646 */
3218 #line 1198 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3219 { (yyval
.command
) = (yyvsp
[0].command
); }
3220 #line 3221 "y.tab.c" /* yacc.c:1646 */
3224 #line 1202 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3225 { (yyval
.command
) = (yyvsp
[0].command
); }
3226 #line 3227 "y.tab.c" /* yacc.c:1646 */
3230 #line 1204 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3232 if ((yyvsp
[0].command
))
3233 (yyvsp
[0].command
)->flags
^= CMD_INVERT_RETURN
; /* toggle */
3234 (yyval
.command
) = (yyvsp
[0].command
);
3236 #line 3237 "y.tab.c" /* yacc.c:1646 */
3240 #line 1210 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3242 if ((yyvsp
[0].command
))
3243 (yyvsp
[0].command
)->flags
|= (yyvsp
[-1].number
);
3244 (yyval
.command
) = (yyvsp
[0].command
);
3246 #line 3247 "y.tab.c" /* yacc.c:1646 */
3250 #line 1216 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3254 /* Boy, this is unclean. `time' by itself can
3255 time a null command. We cheat and push a
3256 newline back if the list_terminator was a newline
3257 to avoid the double-newline problem (one to
3258 terminate this, one to terminate the command) */
3261 (yyval
.command
) = make_simple_command (x
, (COMMAND
*)NULL
);
3262 (yyval
.command
)->flags
|= (yyvsp
[-1].number
);
3263 /* XXX - let's cheat and push a newline back */
3264 if ((yyvsp
[0].number
) == '\n')
3265 token_to_read
= '\n';
3266 else if ((yyvsp
[0].number
) == ';')
3267 token_to_read
= ';';
3269 #line 3270 "y.tab.c" /* yacc.c:1646 */
3273 #line 1235 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3277 /* This is just as unclean. Posix says that `!'
3278 by itself should be equivalent to `false'.
3280 newline back if the list_terminator was a newline
3281 to avoid the double-newline problem (one to
3282 terminate this, one to terminate the command) */
3285 (yyval
.command
) = make_simple_command (x
, (COMMAND
*)NULL
);
3286 (yyval
.command
)->flags
|= CMD_INVERT_RETURN
;
3287 /* XXX - let's cheat and push a newline back */
3288 if ((yyvsp
[0].number
) == '\n')
3289 token_to_read
= '\n';
3290 if ((yyvsp
[0].number
) == ';')
3291 token_to_read
= ';';
3293 #line 3294 "y.tab.c" /* yacc.c:1646 */
3297 #line 1257 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3298 { (yyval
.command
) = command_connect ((yyvsp
[-3].command
), (yyvsp
[0].command
), '|'); }
3299 #line 3300 "y.tab.c" /* yacc.c:1646 */
3303 #line 1259 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3305 /* Make cmd1 |& cmd2 equivalent to cmd1 2>&1 | cmd2 */
3310 tc
= (yyvsp
[-3].command
)->type
== cm_simple
? (COMMAND
*)(yyvsp
[-3].command
)->value
.Simple
: (yyvsp
[-3].command
);
3313 r
= make_redirection (sd
, r_duplicating_output
, rd
, 0);
3316 register REDIRECT
*t
;
3317 for (t
= tc
->redirects
; t
->next
; t
= t
->next
)
3324 (yyval
.command
) = command_connect ((yyvsp
[-3].command
), (yyvsp
[0].command
), '|');
3326 #line 3327 "y.tab.c" /* yacc.c:1646 */
3330 #line 1282 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3331 { (yyval
.command
) = (yyvsp
[0].command
); }
3332 #line 3333 "y.tab.c" /* yacc.c:1646 */
3336 #line 1286 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3337 { (yyval
.number
) = CMD_TIME_PIPELINE
; }
3338 #line 3339 "y.tab.c" /* yacc.c:1646 */
3342 #line 1288 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3343 { (yyval
.number
) = CMD_TIME_PIPELINE
|CMD_TIME_POSIX
; }
3344 #line 3345 "y.tab.c" /* yacc.c:1646 */
3348 #line 1290 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3349 { (yyval
.number
) = CMD_TIME_PIPELINE
|CMD_TIME_POSIX
; }
3350 #line 3351 "y.tab.c" /* yacc.c:1646 */
3354 #line 3355 "y.tab.c" /* yacc.c:1646 */
3357 /* User semantic actions sometimes alter yychar, and that requires
3358 that yytoken be updated with the new translation. We take the
3359 approach of translating immediately before every use of yytoken.
3360 One alternative is translating here after every semantic action,
3361 but that translation would be missed if the semantic action invokes
3362 YYABORT, YYACCEPT, or YYERROR immediately after altering yychar or
3363 if it invokes YYBACKUP. In the case of YYABORT or YYACCEPT, an
3364 incorrect destructor might then be invoked immediately. In the
3365 case of YYERROR or YYBACKUP, subsequent parser actions might lead
3366 to an incorrect destructor call or verbose syntax error message
3367 before the lookahead is translated. */
3368 YY_SYMBOL_PRINT ("-> $$ =", yyr1
[yyn
], &yyval
, &yyloc
);
3372 YY_STACK_PRINT (yyss
, yyssp
);
3376 /* Now 'shift' the result of the reduction. Determine what state
3377 that goes to, based on the state we popped back to and the rule
3378 number reduced by. */
3382 yystate
= yypgoto
[yyn
- YYNTOKENS
] + *yyssp
;
3383 if (0 <= yystate
&& yystate
<= YYLAST
&& yycheck
[yystate
] == *yyssp
)
3384 yystate
= yytable
[yystate
];
3386 yystate
= yydefgoto
[yyn
- YYNTOKENS
];
3391 /*--------------------------------------.
3392 | yyerrlab -- here on detecting error. |
3393 `--------------------------------------*/
3395 /* Make sure we have latest lookahead translation. See comments at
3396 user semantic actions for why this is necessary. */
3397 yytoken
= yychar
== YYEMPTY
? YYEMPTY
: YYTRANSLATE (yychar
);
3399 /* If not already recovering from an error, report this error. */
3403 #if ! YYERROR_VERBOSE
3404 yyerror (YY_("syntax error"));
3406 # define YYSYNTAX_ERROR yysyntax_error (&yymsg_alloc, &yymsg, \
3409 char const *yymsgp
= YY_("syntax error");
3410 int yysyntax_error_status
;
3411 yysyntax_error_status
= YYSYNTAX_ERROR
;
3412 if (yysyntax_error_status
== 0)
3414 else if (yysyntax_error_status
== 1)
3416 if (yymsg
!= yymsgbuf
)
3417 YYSTACK_FREE (yymsg
);
3418 yymsg
= (char *) YYSTACK_ALLOC (yymsg_alloc
);
3422 yymsg_alloc
= sizeof yymsgbuf
;
3423 yysyntax_error_status
= 2;
3427 yysyntax_error_status
= YYSYNTAX_ERROR
;
3432 if (yysyntax_error_status
== 2)
3433 goto yyexhaustedlab
;
3435 # undef YYSYNTAX_ERROR
3441 if (yyerrstatus
== 3)
3443 /* If just tried and failed to reuse lookahead token after an
3444 error, discard it. */
3446 if (yychar
<= YYEOF
)
3448 /* Return failure if at end of input. */
3449 if (yychar
== YYEOF
)
3454 yydestruct ("Error: discarding",
3460 /* Else will try to reuse lookahead token after shifting the error
3465 /*---------------------------------------------------.
3466 | yyerrorlab -- error raised explicitly by YYERROR. |
3467 `---------------------------------------------------*/
3470 /* Pacify compilers like GCC when the user code never invokes
3471 YYERROR and the label yyerrorlab therefore never appears in user
3473 if (/*CONSTCOND*/ 0)
3476 /* Do not reclaim the symbols of the rule whose action triggered
3480 YY_STACK_PRINT (yyss
, yyssp
);
3485 /*-------------------------------------------------------------.
3486 | yyerrlab1 -- common code for both syntax error and YYERROR. |
3487 `-------------------------------------------------------------*/
3489 yyerrstatus
= 3; /* Each real token shifted decrements this. */
3493 yyn
= yypact
[yystate
];
3494 if (!yypact_value_is_default (yyn
))
3497 if (0 <= yyn
&& yyn
<= YYLAST
&& yycheck
[yyn
] == YYTERROR
)
3505 /* Pop the current state because it cannot handle the error token. */
3510 yydestruct ("Error: popping",
3511 yystos
[yystate
], yyvsp
);
3514 YY_STACK_PRINT (yyss
, yyssp
);
3517 YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
3519 YY_IGNORE_MAYBE_UNINITIALIZED_END
3522 /* Shift the error token. */
3523 YY_SYMBOL_PRINT ("Shifting", yystos
[yyn
], yyvsp
, yylsp
);
3529 /*-------------------------------------.
3530 | yyacceptlab -- YYACCEPT comes here. |
3531 `-------------------------------------*/
3536 /*-----------------------------------.
3537 | yyabortlab -- YYABORT comes here. |
3538 `-----------------------------------*/
3543 #if !defined yyoverflow || YYERROR_VERBOSE
3544 /*-------------------------------------------------.
3545 | yyexhaustedlab -- memory exhaustion comes here. |
3546 `-------------------------------------------------*/
3548 yyerror (YY_("memory exhausted"));
3554 if (yychar
!= YYEMPTY
)
3556 /* Make sure we have latest lookahead translation. See comments at
3557 user semantic actions for why this is necessary. */
3558 yytoken
= YYTRANSLATE (yychar
);
3559 yydestruct ("Cleanup: discarding lookahead",
3562 /* Do not reclaim the symbols of the rule whose action triggered
3563 this YYABORT or YYACCEPT. */
3565 YY_STACK_PRINT (yyss
, yyssp
);
3566 while (yyssp
!= yyss
)
3568 yydestruct ("Cleanup: popping",
3569 yystos
[*yyssp
], yyvsp
);
3574 YYSTACK_FREE (yyss
);
3577 if (yymsg
!= yymsgbuf
)
3578 YYSTACK_FREE (yymsg
);
3582 #line 1292 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1906 */
3585 /* Initial size to allocate for tokens, and the
3586 amount to grow them by. */
3587 #define TOKEN_DEFAULT_INITIAL_SIZE 496
3588 #define TOKEN_DEFAULT_GROW_SIZE 512
3590 /* Should we call prompt_again? */
3591 #define SHOULD_PROMPT() \
3592 (interactive && (bash_input.type == st_stdin || bash_input.type == st_stream))
3595 # define expanding_alias() (pushed_string_list && pushed_string_list->expander)
3597 # define expanding_alias() 0
3600 /* Global var is non-zero when end of file has been reached. */
3601 int EOF_Reached
= 0;
3614 /* yy_getc () returns the next available character from input or EOF.
3615 yy_ungetc (c) makes `c' the next character to read.
3616 init_yy_io (get, unget, type, location) makes the function GET the
3617 installed function for getting the next character, makes UNGET the
3618 installed function for un-getting a character, sets the type of stream
3619 (either string or file) from TYPE, and makes LOCATION point to where
3620 the input is coming from. */
3622 /* Unconditionally returns end-of-file. */
3629 /* Variable containing the current get and unget functions.
3630 See ./input.h for a clearer description. */
3631 BASH_INPUT bash_input
;
3633 /* Set all of the fields in BASH_INPUT to NULL. Free bash_input.name if it
3634 is non-null, avoiding a memory leak. */
3636 initialize_bash_input ()
3638 bash_input
.type
= st_none
;
3639 FREE (bash_input
.name
);
3640 bash_input
.name
= (char *)NULL
;
3641 bash_input
.location
.file
= (FILE *)NULL
;
3642 bash_input
.location
.string
= (char *)NULL
;
3643 bash_input
.getter
= (sh_cget_func_t
*)NULL
;
3644 bash_input
.ungetter
= (sh_cunget_func_t
*)NULL
;
3647 /* Set the contents of the current bash input stream from
3648 GET, UNGET, TYPE, NAME, and LOCATION. */
3650 init_yy_io (get
, unget
, type
, name
, location
)
3651 sh_cget_func_t
*get
;
3652 sh_cunget_func_t
*unget
;
3653 enum stream_type type
;
3655 INPUT_STREAM location
;
3657 bash_input
.type
= type
;
3658 FREE (bash_input
.name
);
3659 bash_input
.name
= name
? savestring (name
) : (char *)NULL
;
3663 memcpy((char *)&bash_input
.location
.string
, (char *)&location
.string
, sizeof(location
));
3665 bash_input
.location
= location
;
3667 bash_input
.getter
= get
;
3668 bash_input
.ungetter
= unget
;
3674 return (bash_input
.name
? bash_input
.name
: "stdin");
3677 /* Call this to get the next character of input. */
3681 return (*(bash_input
.getter
)) ();
3684 /* Call this to unget C. That is, to make C the next character
3690 return (*(bash_input
.ungetter
)) (c
);
3693 #if defined (BUFFERED_INPUT)
3694 #ifdef INCLUDE_UNUSED
3696 input_file_descriptor ()
3698 switch (bash_input
.type
)
3701 return (fileno (bash_input
.location
.file
));
3703 return (bash_input
.location
.buffered_fd
);
3706 return (fileno (stdin
));
3710 #endif /* BUFFERED_INPUT */
3712 /* **************************************************************** */
3714 /* Let input be read from readline (). */
3716 /* **************************************************************** */
3718 #if defined (READLINE)
3719 char *current_readline_prompt
= (char *)NULL
;
3720 char *current_readline_line
= (char *)NULL
;
3721 int current_readline_line_index
= 0;
3726 SigHandler
*old_sigint
;
3730 if (current_readline_line
== 0)
3732 if (bash_readline_initialized
== 0)
3733 initialize_readline ();
3735 #if defined (JOB_CONTROL)
3737 give_terminal_to (shell_pgrp
, 0);
3738 #endif /* JOB_CONTROL */
3740 old_sigint
= IMPOSSIBLE_TRAP_HANDLER
;
3741 if (signal_is_ignored (SIGINT
) == 0)
3743 /* interrupt_immediately++; */
3744 old_sigint
= (SigHandler
*)set_signal_handler (SIGINT
, sigint_sighandler
);
3747 current_readline_line
= readline (current_readline_prompt
?
3748 current_readline_prompt
: "");
3751 if (signal_is_ignored (SIGINT
) == 0)
3753 /* interrupt_immediately--; */
3754 if (old_sigint
!= IMPOSSIBLE_TRAP_HANDLER
)
3755 set_signal_handler (SIGINT
, old_sigint
);
3759 /* Reset the prompt to the decoded value of prompt_string_pointer. */
3760 reset_readline_prompt ();
3763 if (current_readline_line
== 0)
3766 current_readline_line_index
= 0;
3767 line_len
= strlen (current_readline_line
);
3769 current_readline_line
= (char *)xrealloc (current_readline_line
, 2 + line_len
);
3770 current_readline_line
[line_len
++] = '\n';
3771 current_readline_line
[line_len
] = '\0';
3774 if (current_readline_line
[current_readline_line_index
] == 0)
3776 free (current_readline_line
);
3777 current_readline_line
= (char *)NULL
;
3778 return (yy_readline_get ());
3782 c
= current_readline_line
[current_readline_line_index
++];
3788 yy_readline_unget (c
)
3791 if (current_readline_line_index
&& current_readline_line
)
3792 current_readline_line
[--current_readline_line_index
] = c
;
3797 with_input_from_stdin ()
3799 INPUT_STREAM location
;
3801 if (bash_input
.type
!= st_stdin
&& stream_on_stack (st_stdin
) == 0)
3803 location
.string
= current_readline_line
;
3804 init_yy_io (yy_readline_get
, yy_readline_unget
,
3805 st_stdin
, "readline stdin", location
);
3809 #else /* !READLINE */
3812 with_input_from_stdin ()
3814 with_input_from_stream (stdin
, "stdin");
3816 #endif /* !READLINE */
3818 /* **************************************************************** */
3820 /* Let input come from STRING. STRING is zero terminated. */
3822 /* **************************************************************** */
3827 register char *string
;
3828 register unsigned char c
;
3830 string
= bash_input
.location
.string
;
3832 /* If the string doesn't exist, or is empty, EOF found. */
3833 if (string
&& *string
)
3836 bash_input
.location
.string
= string
;
3847 *(--bash_input
.location
.string
) = c
;
3852 with_input_from_string (string
, name
)
3856 INPUT_STREAM location
;
3858 location
.string
= string
;
3859 init_yy_io (yy_string_get
, yy_string_unget
, st_string
, name
, location
);
3862 /* Count the number of characters we've consumed from bash_input.location.string
3863 and read into shell_input_line, but have not returned from shell_getc.
3864 That is the true input location. Rewind bash_input.location.string by
3865 that number of characters, so it points to the last character actually
3866 consumed by the parser. */
3868 rewind_input_string ()
3872 /* number of unconsumed characters in the input -- XXX need to take newlines
3873 into account, e.g., $(...\n) */
3874 xchars
= shell_input_line_len
- shell_input_line_index
;
3875 if (bash_input
.location
.string
[-1] == '\n')
3878 /* XXX - how to reflect bash_input.location.string back to string passed to
3879 parse_and_execute or xparse_dolparen? xparse_dolparen needs to know how
3880 far into the string we parsed. parse_and_execute knows where bash_input.
3881 location.string is, and how far from orig_string that is -- that's the
3882 number of characters the command consumed. */
3884 /* bash_input.location.string - xchars should be where we parsed to */
3885 /* need to do more validation on xchars value for sanity -- test cases. */
3886 bash_input
.location
.string
-= xchars
;
3889 /* **************************************************************** */
3891 /* Let input come from STREAM. */
3893 /* **************************************************************** */
3895 /* These two functions used to test the value of the HAVE_RESTARTABLE_SYSCALLS
3896 define, and just use getc/ungetc if it was defined, but since bash
3897 installs its signal handlers without the SA_RESTART flag, some signals
3898 (like SIGCHLD, SIGWINCH, etc.) received during a read(2) will not cause
3899 the read to be restarted. We need to restart it ourselves. */
3907 if (bash_input
.location
.file
)
3911 interrupt_immediately
++;
3914 /* XXX - don't need terminate_immediately; getc_with_restart checks
3915 for terminating signals itself if read returns < 0 */
3916 result
= getc_with_restart (bash_input
.location
.file
);
3920 interrupt_immediately
--;
3930 return (ungetc_with_restart (c
, bash_input
.location
.file
));
3934 with_input_from_stream (stream
, name
)
3938 INPUT_STREAM location
;
3940 location
.file
= stream
;
3941 init_yy_io (yy_stream_get
, yy_stream_unget
, st_stream
, name
, location
);
3944 typedef struct stream_saver
{
3945 struct stream_saver
*next
;
3946 BASH_INPUT bash_input
;
3948 #if defined (BUFFERED_INPUT)
3949 BUFFERED_STREAM
*bstream
;
3950 #endif /* BUFFERED_INPUT */
3953 /* The globally known line number. */
3954 int line_number
= 0;
3956 /* The line number offset set by assigning to LINENO. Not currently used. */
3957 int line_number_base
= 0;
3959 #if defined (COND_COMMAND)
3960 static int cond_lineno
;
3961 static int cond_token
;
3964 STREAM_SAVER
*stream_list
= (STREAM_SAVER
*)NULL
;
3967 push_stream (reset_lineno
)
3970 STREAM_SAVER
*saver
= (STREAM_SAVER
*)xmalloc (sizeof (STREAM_SAVER
));
3972 xbcopy ((char *)&bash_input
, (char *)&(saver
->bash_input
), sizeof (BASH_INPUT
));
3974 #if defined (BUFFERED_INPUT)
3975 saver
->bstream
= (BUFFERED_STREAM
*)NULL
;
3976 /* If we have a buffered stream, clear out buffers[fd]. */
3977 if (bash_input
.type
== st_bstream
&& bash_input
.location
.buffered_fd
>= 0)
3978 saver
->bstream
= set_buffered_stream (bash_input
.location
.buffered_fd
,
3979 (BUFFERED_STREAM
*)NULL
);
3980 #endif /* BUFFERED_INPUT */
3982 saver
->line
= line_number
;
3983 bash_input
.name
= (char *)NULL
;
3984 saver
->next
= stream_list
;
3985 stream_list
= saver
;
3998 STREAM_SAVER
*saver
= stream_list
;
4001 stream_list
= stream_list
->next
;
4003 init_yy_io (saver
->bash_input
.getter
,
4004 saver
->bash_input
.ungetter
,
4005 saver
->bash_input
.type
,
4006 saver
->bash_input
.name
,
4007 saver
->bash_input
.location
);
4009 #if defined (BUFFERED_INPUT)
4010 /* If we have a buffered stream, restore buffers[fd]. */
4011 /* If the input file descriptor was changed while this was on the
4012 save stack, update the buffered fd to the new file descriptor and
4013 re-establish the buffer <-> bash_input fd correspondence. */
4014 if (bash_input
.type
== st_bstream
&& bash_input
.location
.buffered_fd
>= 0)
4016 if (bash_input_fd_changed
)
4018 bash_input_fd_changed
= 0;
4019 if (default_buffered_input
>= 0)
4021 bash_input
.location
.buffered_fd
= default_buffered_input
;
4022 saver
->bstream
->b_fd
= default_buffered_input
;
4023 SET_CLOSE_ON_EXEC (default_buffered_input
);
4026 /* XXX could free buffered stream returned as result here. */
4027 set_buffered_stream (bash_input
.location
.buffered_fd
, saver
->bstream
);
4029 #endif /* BUFFERED_INPUT */
4031 line_number
= saver
->line
;
4033 FREE (saver
->bash_input
.name
);
4038 /* Return 1 if a stream of type TYPE is saved on the stack. */
4040 stream_on_stack (type
)
4041 enum stream_type type
;
4043 register STREAM_SAVER
*s
;
4045 for (s
= stream_list
; s
; s
= s
->next
)
4046 if (s
->bash_input
.type
== type
)
4051 /* Save the current token state and return it in a malloced array. */
4057 ret
= (int *)xmalloc (4 * sizeof (int));
4058 ret
[0] = last_read_token
;
4059 ret
[1] = token_before_that
;
4060 ret
[2] = two_tokens_ago
;
4061 ret
[3] = current_token
;
4066 restore_token_state (ts
)
4071 last_read_token
= ts
[0];
4072 token_before_that
= ts
[1];
4073 two_tokens_ago
= ts
[2];
4074 current_token
= ts
[3];
4078 * This is used to inhibit alias expansion and reserved word recognition
4079 * inside case statement pattern lists. A `case statement pattern list' is:
4081 * everything between the `in' in a `case word in' and the next ')'
4083 * everything between a `;;' and the next `)' or `esac'
4086 #if defined (ALIAS) || defined (DPAREN_ARITHMETIC)
4088 #define END_OF_ALIAS 0
4091 * Pseudo-global variables used in implementing token-wise alias expansion.
4095 * Pushing and popping strings. This works together with shell_getc to
4096 * implement alias expansion on a per-token basis.
4099 #define PSH_ALIAS 0x01
4100 #define PSH_DPAREN 0x02
4101 #define PSH_SOURCE 0x04
4103 typedef struct string_saver
{
4104 struct string_saver
*next
;
4105 int expand_alias
; /* Value to set expand_alias to when string is popped. */
4108 alias_t
*expander
; /* alias that caused this line to be pushed. */
4110 size_t saved_line_size
, saved_line_index
;
4111 int saved_line_terminator
;
4115 STRING_SAVER
*pushed_string_list
= (STRING_SAVER
*)NULL
;
4118 * Push the current shell_input_line onto a stack of such lines and make S
4119 * the current input. Used when expanding aliases. EXPAND is used to set
4120 * the value of expand_next_token when the string is popped, so that the
4121 * word after the alias in the original line is handled correctly when the
4122 * alias expands to multiple words. TOKEN is the token that was expanded
4123 * into S; it is saved and used to prevent infinite recursive expansion.
4126 push_string (s
, expand
, ap
)
4131 STRING_SAVER
*temp
= (STRING_SAVER
*)xmalloc (sizeof (STRING_SAVER
));
4133 temp
->expand_alias
= expand
;
4134 temp
->saved_line
= shell_input_line
;
4135 temp
->saved_line_size
= shell_input_line_size
;
4136 temp
->saved_line_index
= shell_input_line_index
;
4137 temp
->saved_line_terminator
= shell_input_line_terminator
;
4140 temp
->expander
= ap
;
4142 temp
->flags
= PSH_ALIAS
;
4144 temp
->next
= pushed_string_list
;
4145 pushed_string_list
= temp
;
4149 ap
->flags
|= AL_BEINGEXPANDED
;
4152 shell_input_line
= s
;
4153 shell_input_line_size
= STRLEN (s
);
4154 shell_input_line_index
= 0;
4155 shell_input_line_terminator
= '\0';
4157 parser_state
&= ~PST_ALEXPNEXT
; /* XXX */
4160 set_line_mbstate ();
4164 * Make the top of the pushed_string stack be the current shell input.
4165 * Only called when there is something on the stack. Called from shell_getc
4166 * when it thinks it has consumed the string generated by an alias expansion
4167 * and needs to return to the original input line.
4174 FREE (shell_input_line
);
4175 shell_input_line
= pushed_string_list
->saved_line
;
4176 shell_input_line_index
= pushed_string_list
->saved_line_index
;
4177 shell_input_line_size
= pushed_string_list
->saved_line_size
;
4178 shell_input_line_terminator
= pushed_string_list
->saved_line_terminator
;
4180 if (pushed_string_list
->expand_alias
)
4181 parser_state
|= PST_ALEXPNEXT
;
4183 parser_state
&= ~PST_ALEXPNEXT
;
4185 t
= pushed_string_list
;
4186 pushed_string_list
= pushed_string_list
->next
;
4190 t
->expander
->flags
&= ~AL_BEINGEXPANDED
;
4195 set_line_mbstate ();
4201 register STRING_SAVER
*t
, *t1
;
4203 for (t
= pushed_string_list
; t
; )
4206 FREE (t
->saved_line
);
4209 t
->expander
->flags
&= ~AL_BEINGEXPANDED
;
4214 pushed_string_list
= (STRING_SAVER
*)NULL
;
4217 #endif /* ALIAS || DPAREN_ARITHMETIC */
4220 free_pushed_string_input ()
4222 #if defined (ALIAS) || defined (DPAREN_ARITHMETIC)
4223 free_string_list ();
4228 parser_expanding_alias ()
4230 return (expanding_alias ());
4234 parser_save_alias ()
4236 #if defined (ALIAS) || defined (DPAREN_ARITHMETIC)
4237 push_string ((char *)NULL
, 0, (alias_t
*)NULL
);
4238 pushed_string_list
->flags
= PSH_SOURCE
; /* XXX - for now */
4245 parser_restore_alias ()
4247 #if defined (ALIAS) || defined (DPAREN_ARITHMETIC)
4248 if (pushed_string_list
)
4256 clear_shell_input_line ()
4258 if (shell_input_line
)
4259 shell_input_line
[shell_input_line_index
= 0] = '\0';
4262 /* Return a line of text, taken from wherever yylex () reads input.
4263 If there is no more input, then we return NULL. If REMOVE_QUOTED_NEWLINE
4264 is non-zero, we remove unquoted \<newline> pairs. This is used by
4265 read_secondary_line to read here documents. */
4267 read_a_line (remove_quoted_newline
)
4268 int remove_quoted_newline
;
4270 static char *line_buffer
= (char *)NULL
;
4271 static int buffer_size
= 0;
4272 int indx
, c
, peekc
, pass_next
;
4274 #if defined (READLINE)
4275 if (no_line_editing
&& SHOULD_PROMPT ())
4277 if (SHOULD_PROMPT ())
4281 pass_next
= indx
= 0;
4284 /* Allow immediate exit if interrupted during input. */
4289 /* Ignore null bytes in input. */
4293 internal_warning ("read_a_line: ignored null byte in input");
4298 /* If there is no more input, then we return NULL. */
4301 if (interactive
&& bash_input
.type
== st_stream
)
4304 return ((char *)NULL
);
4308 /* `+2' in case the final character in the buffer is a newline. */
4309 RESIZE_MALLOCED_BUFFER (line_buffer
, indx
, 2, buffer_size
, 128);
4311 /* IF REMOVE_QUOTED_NEWLINES is non-zero, we are reading a
4312 here document with an unquoted delimiter. In this case,
4313 the line will be expanded as if it were in double quotes.
4314 We allow a backslash to escape the next character, but we
4315 need to treat the backslash specially only if a backslash
4316 quoting a backslash-newline pair appears in the line. */
4319 line_buffer
[indx
++] = c
;
4322 else if (c
== '\\' && remove_quoted_newline
)
4329 continue; /* Make the unquoted \<newline> pair disappear. */
4335 line_buffer
[indx
++] = c
; /* Preserve the backslash. */
4339 line_buffer
[indx
++] = c
;
4343 line_buffer
[indx
] = '\0';
4344 return (line_buffer
);
4349 /* Return a line as in read_a_line (), but insure that the prompt is
4350 the secondary prompt. This is used to read the lines of a here
4351 document. REMOVE_QUOTED_NEWLINE is non-zero if we should remove
4352 newlines quoted with backslashes while reading the line. It is
4353 non-zero unless the delimiter of the here document was quoted. */
4355 read_secondary_line (remove_quoted_newline
)
4356 int remove_quoted_newline
;
4361 prompt_string_pointer
= &ps2_prompt
;
4362 if (SHOULD_PROMPT())
4364 ret
= read_a_line (remove_quoted_newline
);
4365 #if defined (HISTORY)
4366 if (ret
&& remember_on_history
&& (parser_state
& PST_HEREDOC
))
4368 /* To make adding the here-document body right, we need to rely on
4369 history_delimiting_chars() returning \n for the first line of the
4370 here-document body and the null string for the second and subsequent
4371 lines, so we avoid double newlines.
4372 current_command_line_count == 2 for the first line of the body. */
4374 current_command_line_count
++;
4375 maybe_add_history (ret
);
4377 #endif /* HISTORY */
4381 /* **************************************************************** */
4385 /* **************************************************************** */
4387 /* Reserved words. These are only recognized as the first word of a
4389 STRING_INT_ALIST word_token_alist
[] = {
4398 #if defined (SELECT_COMMAND)
4399 { "select", SELECT
},
4406 { "function", FUNCTION
},
4407 #if defined (COMMAND_TIMING)
4413 #if defined (COND_COMMAND)
4414 { "[[", COND_START
},
4417 #if defined (COPROCESS_SUPPORT)
4418 { "coproc", COPROC
},
4423 /* other tokens that can be returned by read_token() */
4424 STRING_INT_ALIST other_token_alist
[] = {
4425 /* Multiple-character tokens with special values */
4430 { ">>", GREATER_GREATER
},
4431 { "<<", LESS_LESS
},
4433 { ">&", GREATER_AND
},
4434 { ";;", SEMI_SEMI
},
4436 { ";;&", SEMI_SEMI_AND
},
4437 { "<<-", LESS_LESS_MINUS
},
4438 { "<<<", LESS_LESS_LESS
},
4439 { "&>", AND_GREATER
},
4440 { "&>>", AND_GREATER_GREATER
},
4441 { "<>", LESS_GREATER
},
4442 { ">|", GREATER_BAR
},
4444 { "EOF", yacc_EOF
},
4445 /* Tokens whose value is the character itself */
4456 { "newline", '\n' },
4460 /* others not listed here:
4461 WORD look at yylval.word
4462 ASSIGNMENT_WORD look at yylval.word
4463 NUMBER look at yylval.number
4464 ARITH_CMD look at yylval.word_list
4465 ARITH_FOR_EXPRS look at yylval.word_list
4466 COND_CMD look at yylval.command
4469 /* These are used by read_token_word, but appear up here so that shell_getc
4470 can use them to decide when to add otherwise blank lines to the history. */
4472 /* The primary delimiter stack. */
4473 struct dstack dstack
= { (char *)NULL
, 0, 0 };
4475 /* A temporary delimiter stack to be used when decoding prompt strings.
4476 This is needed because command substitutions in prompt strings (e.g., PS2)
4477 can screw up the parser's quoting state. */
4478 static struct dstack temp_dstack
= { (char *)NULL
, 0, 0 };
4480 /* Macro for accessing the top delimiter on the stack. Returns the
4481 delimiter or zero if none. */
4482 #define current_delimiter(ds) \
4483 (ds.delimiter_depth ? ds.delimiters[ds.delimiter_depth - 1] : 0)
4485 #define push_delimiter(ds, character) \
4488 if (ds.delimiter_depth + 2 > ds.delimiter_space) \
4489 ds.delimiters = (char *)xrealloc \
4490 (ds.delimiters, (ds.delimiter_space += 10) * sizeof (char)); \
4491 ds.delimiters[ds.delimiter_depth] = character; \
4492 ds.delimiter_depth++; \
4496 #define pop_delimiter(ds) ds.delimiter_depth--
4498 /* Return the next shell input character. This always reads characters
4499 from shell_input_line; when that line is exhausted, it is time to
4500 read the next line. This is called by read_token when the shell is
4501 processing normal command input. */
4503 /* This implements one-character lookahead/lookbehind across physical input
4504 lines, to avoid something being lost because it's pushed back with
4505 shell_ungetc when we're at the start of a line. */
4506 static int eol_ungetc_lookahead
= 0;
4509 shell_getc (remove_quoted_newline
)
4510 int remove_quoted_newline
;
4513 int c
, truncating
, last_was_backslash
;
4518 last_was_backslash
= 0;
4519 if (sigwinch_received
)
4521 sigwinch_received
= 0;
4522 get_new_window_size (0, (int *)0, (int *)0);
4525 if (eol_ungetc_lookahead
)
4527 c
= eol_ungetc_lookahead
;
4528 eol_ungetc_lookahead
= 0;
4532 #if defined (ALIAS) || defined (DPAREN_ARITHMETIC)
4533 /* If shell_input_line[shell_input_line_index] == 0, but there is
4534 something on the pushed list of strings, then we don't want to go
4535 off and get another line. We let the code down below handle it. */
4537 if (!shell_input_line
|| ((!shell_input_line
[shell_input_line_index
]) &&
4538 (pushed_string_list
== (STRING_SAVER
*)NULL
)))
4539 #else /* !ALIAS && !DPAREN_ARITHMETIC */
4540 if (!shell_input_line
|| !shell_input_line
[shell_input_line_index
])
4541 #endif /* !ALIAS && !DPAREN_ARITHMETIC */
4545 /* Let's not let one really really long line blow up memory allocation */
4546 if (shell_input_line
&& shell_input_line_size
>= 32768)
4548 free (shell_input_line
);
4549 shell_input_line
= 0;
4550 shell_input_line_size
= 0;
4555 /* Allow immediate exit if interrupted during input. */
4559 shell_input_line_terminator
= 0;
4561 /* If the shell is interatctive, but not currently printing a prompt
4562 (interactive_shell && interactive == 0), we don't want to print
4563 notifies or cleanup the jobs -- we want to defer it until we do
4564 print the next prompt. */
4565 if (interactive_shell
== 0 || SHOULD_PROMPT())
4567 #if defined (JOB_CONTROL)
4568 /* This can cause a problem when reading a command as the result
4569 of a trap, when the trap is called from flush_child. This call
4570 had better not cause jobs to disappear from the job table in
4571 that case, or we will have big trouble. */
4572 notify_and_cleanup ();
4573 #else /* !JOB_CONTROL */
4574 cleanup_dead_jobs ();
4575 #endif /* !JOB_CONTROL */
4578 #if defined (READLINE)
4579 if (no_line_editing
&& SHOULD_PROMPT())
4581 if (SHOULD_PROMPT())
4585 if (bash_input
.type
== st_stream
)
4592 /* Allow immediate exit if interrupted during input. */
4598 internal_warning ("shell_getc: ignored null byte in input");
4603 /* Theoretical overflow */
4604 /* If we can't put 256 bytes more into the buffer, allocate
4605 everything we can and fill it as full as we can. */
4606 /* XXX - we ignore rest of line using `truncating' flag */
4607 if (shell_input_line_size
> (SIZE_MAX
- 256))
4611 n
= SIZE_MAX
- i
; /* how much more can we put into the buffer? */
4612 if (n
<= 2) /* we have to save 1 for the newline added below */
4614 if (truncating
== 0)
4615 internal_warning(_("shell_getc: shell_input_line_size (%zu) exceeds SIZE_MAX (%lu): line truncated"), shell_input_line_size
, (unsigned long)SIZE_MAX
);
4616 shell_input_line
[i
] = '\0';
4619 if (shell_input_line_size
< SIZE_MAX
)
4621 shell_input_line_size
= SIZE_MAX
;
4622 shell_input_line
= xrealloc (shell_input_line
, shell_input_line_size
);
4626 RESIZE_MALLOCED_BUFFER (shell_input_line
, i
, 2, shell_input_line_size
, 256);
4630 if (bash_input
.type
== st_stream
)
4634 shell_input_line_terminator
= EOF
;
4636 shell_input_line
[i
] = '\0';
4640 if (truncating
== 0 || c
== '\n')
4641 shell_input_line
[i
++] = c
;
4645 shell_input_line
[--i
] = '\0';
4646 current_command_line_count
++;
4650 last_was_backslash
= last_was_backslash
== 0 && c
== '\\';
4653 shell_input_line_index
= 0;
4654 shell_input_line_len
= i
; /* == strlen (shell_input_line) */
4656 set_line_mbstate ();
4658 #if defined (HISTORY)
4659 if (remember_on_history
&& shell_input_line
&& shell_input_line
[0])
4662 # if defined (BANG_HISTORY)
4665 /* If the current delimiter is a single quote, we should not be
4666 performing history expansion, even if we're on a different
4667 line from the original single quote. */
4668 old_hist
= history_expansion_inhibited
;
4669 if (current_delimiter (dstack
) == '\'')
4670 history_expansion_inhibited
= 1;
4672 /* Calling with a third argument of 1 allows remember_on_history to
4673 determine whether or not the line is saved to the history list */
4674 expansions
= pre_process_line (shell_input_line
, 1, 1);
4675 # if defined (BANG_HISTORY)
4676 history_expansion_inhibited
= old_hist
;
4678 if (expansions
!= shell_input_line
)
4680 free (shell_input_line
);
4681 shell_input_line
= expansions
;
4682 shell_input_line_len
= shell_input_line
?
4683 strlen (shell_input_line
) : 0;
4684 if (shell_input_line_len
== 0)
4685 current_command_line_count
--;
4687 /* We have to force the xrealloc below because we don't know
4688 the true allocated size of shell_input_line anymore. */
4689 shell_input_line_size
= shell_input_line_len
;
4691 set_line_mbstate ();
4694 /* Try to do something intelligent with blank lines encountered while
4695 entering multi-line commands. XXX - this is grotesque */
4696 else if (remember_on_history
&& shell_input_line
&&
4697 shell_input_line
[0] == '\0' &&
4698 current_command_line_count
> 1)
4700 if (current_delimiter (dstack
))
4701 /* We know shell_input_line[0] == 0 and we're reading some sort of
4702 quoted string. This means we've got a line consisting of only
4703 a newline in a quoted string. We want to make sure this line
4704 gets added to the history. */
4705 maybe_add_history (shell_input_line
);
4709 hdcs
= history_delimiting_chars (shell_input_line
);
4710 if (hdcs
&& hdcs
[0] == ';')
4711 maybe_add_history (shell_input_line
);
4715 #endif /* HISTORY */
4717 if (shell_input_line
)
4719 /* Lines that signify the end of the shell's input should not be
4720 echoed. We should not echo lines while parsing command
4721 substitutions with recursive calls into the parsing engine; those
4722 should only be echoed once when we read the word. That is the
4723 reason for the test against shell_eof_token, which is set to a
4724 right paren when parsing the contents of command substitutions. */
4725 if (echo_input_at_read
&& (shell_input_line
[0] ||
4726 shell_input_line_terminator
!= EOF
) &&
4727 shell_eof_token
== 0)
4728 fprintf (stderr
, "%s\n", shell_input_line
);
4732 shell_input_line_size
= 0;
4733 prompt_string_pointer
= ¤t_prompt_string
;
4734 if (SHOULD_PROMPT ())
4739 /* Add the newline to the end of this string, iff the string does
4740 not already end in an EOF character. */
4741 if (shell_input_line_terminator
!= EOF
)
4743 if (shell_input_line_size
< SIZE_MAX
-3 && (shell_input_line_len
+3 > shell_input_line_size
))
4744 shell_input_line
= (char *)xrealloc (shell_input_line
,
4745 1 + (shell_input_line_size
+= 2));
4747 /* Don't add a newline to a string that ends with a backslash if we're
4748 going to be removing quoted newlines, since that will eat the
4749 backslash. Add another backslash instead (will be removed by
4751 if (bash_input
.type
== st_string
&& expanding_alias() == 0 && last_was_backslash
&& c
== EOF
&& remove_quoted_newline
)
4752 shell_input_line
[shell_input_line_len
] = '\\';
4754 shell_input_line
[shell_input_line_len
] = '\n';
4755 shell_input_line
[shell_input_line_len
+ 1] = '\0';
4757 set_line_mbstate ();
4762 uc
= shell_input_line
[shell_input_line_index
];
4765 shell_input_line_index
++;
4767 #if defined (ALIAS) || defined (DPAREN_ARITHMETIC)
4768 /* If UC is NULL, we have reached the end of the current input string. If
4769 pushed_string_list is non-empty, it's time to pop to the previous string
4770 because we have fully consumed the result of the last alias expansion.
4771 Do it transparently; just return the next character of the string popped
4773 /* If pushed_string_list != 0 but pushed_string_list->expander == 0 (not
4774 currently tested) and the flags value is not PSH_SOURCE, we are not
4775 parsing an alias, we have just saved one (push_string, when called by
4776 the parse_dparen code) In this case, just go on as well. The PSH_SOURCE
4777 case is handled below. */
4779 if (uc
== 0 && pushed_string_list
&& pushed_string_list
->flags
!= PSH_SOURCE
)
4782 uc
= shell_input_line
[shell_input_line_index
];
4784 shell_input_line_index
++;
4786 #endif /* ALIAS || DPAREN_ARITHMETIC */
4788 if MBTEST(uc
== '\\' && remove_quoted_newline
&& shell_input_line
[shell_input_line_index
] == '\n')
4790 if (SHOULD_PROMPT ())
4793 /* What do we do here if we're expanding an alias whose definition
4794 includes an escaped newline? If that's the last character in the
4795 alias expansion, we just pop the pushed string list (recall that
4796 we inhibit the appending of a space in mk_alexpansion() if newline
4797 is the last character). If it's not the last character, we need
4798 to consume the quoted newline and move to the next character in
4801 if (expanding_alias () && shell_input_line
[shell_input_line_index
+1] == '\0')
4806 else if (expanding_alias () && shell_input_line
[shell_input_line_index
+1] != '\0')
4808 shell_input_line_index
++; /* skip newline */
4809 goto next_alias_char
; /* and get next character */
4816 if (uc
== 0 && shell_input_line_terminator
== EOF
)
4817 return ((shell_input_line_index
!= 0) ? '\n' : EOF
);
4819 #if defined (ALIAS) || defined (DPAREN_ARITHMETIC)
4820 /* We already know that we are not parsing an alias expansion because of the
4821 check for expanding_alias() above. This knows how parse_and_execute
4822 handles switching to st_string input while an alias is being expanded,
4823 hence the check for pushed_string_list without pushed_string_list->expander
4824 and the check for PSH_SOURCE as pushed_string_list->flags.
4825 parse_and_execute and parse_string both change the input type to st_string
4826 and place the string to be parsed and executed into location.string, so
4827 we should not stop reading that until the pointer is '\0'.
4828 The check for shell_input_line_terminator may be superfluous.
4830 This solves the problem of `.' inside a multi-line alias with embedded
4831 newlines executing things out of order. */
4832 if (uc
== 0 && bash_input
.type
== st_string
&& *bash_input
.location
.string
&&
4833 pushed_string_list
&& pushed_string_list
->flags
== PSH_SOURCE
&&
4834 shell_input_line_terminator
== 0)
4836 shell_input_line_index
= 0;
4844 /* Put C back into the input for the shell. This might need changes for
4845 HANDLE_MULTIBYTE around EOLs. Since we (currently) never push back a
4846 character different than we read, shell_input_line_property doesn't need
4847 to change when manipulating shell_input_line. The define for
4848 last_shell_getc_is_singlebyte should take care of it, though. */
4853 if (shell_input_line
&& shell_input_line_index
)
4854 shell_input_line
[--shell_input_line_index
] = c
;
4856 eol_ungetc_lookahead
= c
;
4860 parser_remaining_input ()
4862 if (shell_input_line
== 0)
4864 if (shell_input_line_index
< 0 || shell_input_line_index
>= shell_input_line_len
)
4865 return ""; /* XXX */
4866 return (shell_input_line
+ shell_input_line_index
);
4869 #ifdef INCLUDE_UNUSED
4870 /* Back the input pointer up by one, effectively `ungetting' a character. */
4874 if (shell_input_line
&& shell_input_line_index
)
4875 shell_input_line_index
--;
4879 /* Discard input until CHARACTER is seen, then push that character back
4880 onto the input stream. */
4882 discard_until (character
)
4887 while ((c
= shell_getc (0)) != EOF
&& c
!= character
)
4895 execute_variable_command (command
, vname
)
4896 char *command
, *vname
;
4899 sh_parser_state_t ps
;
4901 save_parser_state (&ps
);
4902 last_lastarg
= get_string_value ("_");
4904 last_lastarg
= savestring (last_lastarg
);
4906 parse_and_execute (savestring (command
), vname
, SEVAL_NONINT
|SEVAL_NOHIST
);
4908 restore_parser_state (&ps
);
4909 bind_variable ("_", last_lastarg
, 0);
4910 FREE (last_lastarg
);
4912 if (token_to_read
== '\n') /* reset_parser was called */
4920 two_tokens_ago
= token_before_that
;
4921 token_before_that
= last_read_token
;
4922 last_read_token
= current_token
;
4927 /* Place to remember the token. We try to keep the buffer
4928 at a reasonable size, but it can grow. */
4929 static char *token
= (char *)NULL
;
4931 /* Current size of the token buffer. */
4932 static int token_buffer_size
;
4934 /* Command to read_token () explaining what we want it to do. */
4937 #define prompt_is_ps1 \
4938 (!prompt_string_pointer || prompt_string_pointer == &ps1_prompt)
4940 /* Function for yyparse to call. yylex keeps track of
4941 the last two tokens read, and calls read_token. */
4945 if (interactive
&& (current_token
== 0 || current_token
== '\n'))
4947 /* Before we print a prompt, we might have to check mailboxes.
4948 We do this only if it is time to do so. Notice that only here
4949 is the mail alarm reset; nothing takes place in check_mail ()
4950 except the checking of mail. Please don't change this. */
4951 if (prompt_is_ps1
&& parse_and_execute_level
== 0 && time_to_check_mail ())
4954 reset_mail_timer ();
4957 /* Avoid printing a prompt if we're not going to read anything, e.g.
4958 after resetting the parser with read_token (RESET). */
4959 if (token_to_read
== 0 && SHOULD_PROMPT ())
4963 two_tokens_ago
= token_before_that
;
4964 token_before_that
= last_read_token
;
4965 last_read_token
= current_token
;
4966 current_token
= read_token (READ
);
4968 if ((parser_state
& PST_EOFTOKEN
) && current_token
== shell_eof_token
)
4970 current_token
= yacc_EOF
;
4971 if (bash_input
.type
== st_string
)
4972 rewind_input_string ();
4974 parser_state
&= ~PST_EOFTOKEN
;
4976 return (current_token
);
4979 /* When non-zero, we have read the required tokens
4980 which allow ESAC to be the next one read. */
4981 static int esacs_needed_count
;
4987 if (need_here_doc
>= HEREDOC_MAX
)
4989 last_command_exit_value
= EX_BADUSAGE
;
4991 report_syntax_error (_("maximum here-document count exceeded"));
4993 exit_shell (last_command_exit_value
);
4995 redir_stack
[need_here_doc
++] = r
;
4999 gather_here_documents ()
5004 here_doc_first_line
= 1;
5005 while (need_here_doc
> 0)
5007 parser_state
|= PST_HEREDOC
;
5008 make_here_document (redir_stack
[r
++], line_number
);
5009 parser_state
&= ~PST_HEREDOC
;
5011 redir_stack
[r
- 1] = 0; /* XXX */
5013 here_doc_first_line
= 0; /* just in case */
5016 /* When non-zero, an open-brace used to create a group is awaiting a close
5018 static int open_brace_count
;
5020 /* In the following three macros, `token' is always last_read_token */
5022 /* Are we in the middle of parsing a redirection where we are about to read
5023 a word? This is used to make sure alias expansion doesn't happen in the
5024 middle of a redirection, even though we're parsing a simple command. */
5025 #define parsing_redirection(token) \
5026 (token == '<' || token == '>' || \
5027 token == GREATER_GREATER || token == GREATER_BAR || \
5028 token == LESS_GREATER || token == LESS_LESS_MINUS || \
5029 token == LESS_LESS || token == LESS_LESS_LESS || \
5030 token == LESS_AND || token == GREATER_AND || token == AND_GREATER)
5032 /* Is `token' one that will allow a WORD to be read in a command position?
5033 We can read a simple command name on which we should attempt alias expansion
5034 or we can read an assignment statement. */
5035 #define command_token_position(token) \
5036 (((token) == ASSIGNMENT_WORD) || \
5037 ((parser_state&PST_REDIRLIST) && parsing_redirection(token) == 0) || \
5038 ((token) != SEMI_SEMI && (token) != SEMI_AND && (token) != SEMI_SEMI_AND && reserved_word_acceptable(token)))
5040 /* Are we in a position where we can read an assignment statement? */
5041 #define assignment_acceptable(token) \
5042 (command_token_position(token) && ((parser_state & PST_CASEPAT) == 0))
5044 /* Check to see if TOKEN is a reserved word and return the token
5046 #define CHECK_FOR_RESERVED_WORD(tok) \
5048 if (!dollar_present && !quoted && \
5049 reserved_word_acceptable (last_read_token)) \
5052 for (i = 0; word_token_alist[i].word != (char *)NULL; i++) \
5053 if (STREQ (tok, word_token_alist[i].word)) \
5055 if ((parser_state & PST_CASEPAT) && (word_token_alist[i].token != ESAC)) \
5057 if (word_token_alist[i].token == TIME && time_command_acceptable () == 0) \
5059 if ((parser_state & PST_CASEPAT) && last_read_token == '|' && word_token_alist[i].token == ESAC) \
5060 break; /* Posix grammar rule 4 */ \
5061 if (word_token_alist[i].token == ESAC) \
5062 parser_state &= ~(PST_CASEPAT|PST_CASESTMT); \
5063 else if (word_token_alist[i].token == CASE) \
5064 parser_state |= PST_CASESTMT; \
5065 else if (word_token_alist[i].token == COND_END) \
5066 parser_state &= ~(PST_CONDCMD|PST_CONDEXPR); \
5067 else if (word_token_alist[i].token == COND_START) \
5068 parser_state |= PST_CONDCMD; \
5069 else if (word_token_alist[i].token == '{') \
5070 open_brace_count++; \
5071 else if (word_token_alist[i].token == '}' && open_brace_count) \
5072 open_brace_count--; \
5073 return (word_token_alist[i].token); \
5080 /* OK, we have a token. Let's try to alias expand it, if (and only if)
5083 It is eligible for expansion if EXPAND_ALIASES is set, and
5084 the token is unquoted and the last token read was a command
5085 separator (or expand_next_token is set), and we are currently
5086 processing an alias (pushed_string_list is non-empty) and this
5087 token is not the same as the current or any previously
5090 Special cases that disqualify:
5091 In a pattern list in a case statement (parser_state & PST_CASEPAT). */
5101 r
= xmalloc (l
+ 2);
5103 /* If the last character in the alias is a newline, don't add a trailing
5104 space to the expansion. Works with shell_getc above. */
5105 if (r
[l
- 1] != ' ' && r
[l
- 1] != '\n' && shellmeta(r
[l
- 1]) == 0)
5112 alias_expand_token (tokstr
)
5118 if (((parser_state
& PST_ALEXPNEXT
) || command_token_position (last_read_token
)) &&
5119 (parser_state
& PST_CASEPAT
) == 0)
5121 ap
= find_alias (tokstr
);
5123 /* Currently expanding this token. */
5124 if (ap
&& (ap
->flags
& AL_BEINGEXPANDED
))
5125 return (NO_EXPANSION
);
5127 /* mk_alexpansion puts an extra space on the end of the alias expansion,
5128 so the lookahead by the parser works right. If this gets changed,
5129 make sure the code in shell_getc that deals with reaching the end of
5130 an expanded alias is changed with it. */
5131 expanded
= ap
? mk_alexpansion (ap
->value
) : (char *)NULL
;
5135 push_string (expanded
, ap
->flags
& AL_EXPANDNEXT
, ap
);
5136 return (RE_READ_TOKEN
);
5139 /* This is an eligible token that does not have an expansion. */
5140 return (NO_EXPANSION
);
5142 return (NO_EXPANSION
);
5147 time_command_acceptable ()
5149 #if defined (COMMAND_TIMING)
5152 if (posixly_correct
&& shell_compatibility_level
> 41)
5154 /* Quick check of the rest of the line to find the next token. If it
5155 begins with a `-', Posix says to not return `time' as the token.
5156 This was interp 267. */
5157 i
= shell_input_line_index
;
5158 while (i
< shell_input_line_len
&& (shell_input_line
[i
] == ' ' || shell_input_line
[i
] == '\t'))
5160 if (shell_input_line
[i
] == '-')
5164 switch (last_read_token
)
5169 if (token_before_that
== '|')
5184 case ')': /* only valid in case statement */
5185 case BANG
: /* ! time pipeline */
5186 case TIME
: /* time time pipeline */
5187 case TIMEOPT
: /* time -p time pipeline */
5188 case TIMEIGN
: /* time -p -- ... */
5195 #endif /* COMMAND_TIMING */
5198 /* Handle special cases of token recognition:
5199 IN is recognized if the last token was WORD and the token
5200 before that was FOR or CASE or SELECT.
5202 DO is recognized if the last token was WORD and the token
5203 before that was FOR or SELECT.
5205 ESAC is recognized if the last token caused `esacs_needed_count'
5208 `{' is recognized if the last token as WORD and the token
5209 before that was FUNCTION, or if we just parsed an arithmetic
5212 `}' is recognized if there is an unclosed `{' present.
5214 `-p' is returned as TIMEOPT if the last read token was TIME.
5215 `--' is returned as TIMEIGN if the last read token was TIMEOPT.
5217 ']]' is returned as COND_END if the parser is currently parsing
5218 a conditional expression ((parser_state & PST_CONDEXPR) != 0)
5220 `time' is returned as TIME if and only if it is immediately
5221 preceded by one of `;', `\n', `||', `&&', or `&'.
5225 special_case_tokens (tokstr
)
5228 if ((last_read_token
== WORD
) &&
5229 #if defined (SELECT_COMMAND)
5230 ((token_before_that
== FOR
) || (token_before_that
== CASE
) || (token_before_that
== SELECT
)) &&
5232 ((token_before_that
== FOR
) || (token_before_that
== CASE
)) &&
5234 (tokstr
[0] == 'i' && tokstr
[1] == 'n' && tokstr
[2] == 0))
5236 if (token_before_that
== CASE
)
5238 parser_state
|= PST_CASEPAT
;
5239 esacs_needed_count
++;
5244 if (last_read_token
== WORD
&&
5245 #if defined (SELECT_COMMAND)
5246 (token_before_that
== FOR
|| token_before_that
== SELECT
) &&
5248 (token_before_that
== FOR
) &&
5250 (tokstr
[0] == 'd' && tokstr
[1] == 'o' && tokstr
[2] == '\0'))
5253 /* Ditto for ESAC in the CASE case.
5254 Specifically, this handles "case word in esac", which is a legal
5255 construct, certainly because someone will pass an empty arg to the
5256 case construct, and we don't want it to barf. Of course, we should
5257 insist that the case construct has at least one pattern in it, but
5258 the designers disagree. */
5259 if (esacs_needed_count
)
5261 esacs_needed_count
--;
5262 if (STREQ (tokstr
, "esac"))
5264 parser_state
&= ~PST_CASEPAT
;
5269 /* The start of a shell function definition. */
5270 if (parser_state
& PST_ALLOWOPNBRC
)
5272 parser_state
&= ~PST_ALLOWOPNBRC
;
5273 if (tokstr
[0] == '{' && tokstr
[1] == '\0') /* } */
5276 function_bstart
= line_number
;
5277 return ('{'); /* } */
5281 /* We allow a `do' after a for ((...)) without an intervening
5283 if (last_read_token
== ARITH_FOR_EXPRS
&& tokstr
[0] == 'd' && tokstr
[1] == 'o' && !tokstr
[2])
5285 if (last_read_token
== ARITH_FOR_EXPRS
&& tokstr
[0] == '{' && tokstr
[1] == '\0') /* } */
5288 return ('{'); /* } */
5291 if (open_brace_count
&& reserved_word_acceptable (last_read_token
) && tokstr
[0] == '}' && !tokstr
[1])
5293 open_brace_count
--; /* { */
5297 #if defined (COMMAND_TIMING)
5298 /* Handle -p after `time'. */
5299 if (last_read_token
== TIME
&& tokstr
[0] == '-' && tokstr
[1] == 'p' && !tokstr
[2])
5301 /* Handle -- after `time -p'. */
5302 if (last_read_token
== TIMEOPT
&& tokstr
[0] == '-' && tokstr
[1] == '-' && !tokstr
[2])
5306 #if defined (COND_COMMAND) /* [[ */
5307 if ((parser_state
& PST_CONDEXPR
) && tokstr
[0] == ']' && tokstr
[1] == ']' && tokstr
[2] == '\0')
5314 /* Called from shell.c when Control-C is typed at top level. Or
5315 by the error rule at top level. */
5319 dstack
.delimiter_depth
= 0; /* No delimiters found so far. */
5320 open_brace_count
= 0;
5322 #if defined (EXTENDED_GLOB)
5323 /* Reset to global value of extended glob */
5324 if (parser_state
& PST_EXTPAT
)
5325 extended_glob
= global_extglob
;
5329 here_doc_first_line
= 0;
5331 #if defined (ALIAS) || defined (DPAREN_ARITHMETIC)
5332 if (pushed_string_list
)
5333 free_string_list ();
5334 #endif /* ALIAS || DPAREN_ARITHMETIC */
5336 /* This is where we resynchronize to the next newline on error/reset */
5337 if (shell_input_line
)
5339 free (shell_input_line
);
5340 shell_input_line
= (char *)NULL
;
5341 shell_input_line_size
= shell_input_line_index
= 0;
5344 FREE (word_desc_to_read
);
5345 word_desc_to_read
= (WORD_DESC
*)NULL
;
5347 eol_ungetc_lookahead
= 0;
5349 current_token
= '\n'; /* XXX */
5350 last_read_token
= '\n';
5351 token_to_read
= '\n';
5354 /* Read the next token. Command can be READ (normal operation) or
5355 RESET (to normalize state). */
5357 read_token (command
)
5360 int character
; /* Current character. */
5361 int peek_char
; /* Temporary look-ahead character. */
5362 int result
; /* The thing to return. */
5364 if (command
== RESET
)
5372 result
= token_to_read
;
5373 if (token_to_read
== WORD
|| token_to_read
== ASSIGNMENT_WORD
)
5375 yylval
.word
= word_desc_to_read
;
5376 word_desc_to_read
= (WORD_DESC
*)NULL
;
5382 #if defined (COND_COMMAND)
5383 if ((parser_state
& (PST_CONDCMD
|PST_CONDEXPR
)) == PST_CONDCMD
)
5385 cond_lineno
= line_number
;
5386 parser_state
|= PST_CONDEXPR
;
5387 yylval
.command
= parse_cond_command ();
5388 if (cond_token
!= COND_END
)
5393 token_to_read
= COND_END
;
5394 parser_state
&= ~(PST_CONDEXPR
|PST_CONDCMD
);
5400 /* This is a place to jump back to once we have successfully expanded a
5401 token with an alias and pushed the string with push_string () */
5405 /* Read a single word from input. Start by skipping blanks. */
5406 while ((character
= shell_getc (1)) != EOF
&& shellblank (character
))
5409 if (character
== EOF
)
5415 if MBTEST(character
== '#' && (!interactive
|| interactive_comments
))
5417 /* A comment. Discard until EOL or EOF, and then return a newline. */
5418 discard_until ('\n');
5420 character
= '\n'; /* this will take the next if statement and return. */
5423 if (character
== '\n')
5425 /* If we're about to return an unquoted newline, we can go and collect
5426 the text of any pending here document. */
5428 gather_here_documents ();
5431 parser_state
&= ~PST_ALEXPNEXT
;
5434 parser_state
&= ~PST_ASSIGNOK
;
5439 if (parser_state
& PST_REGEXP
)
5442 /* Shell meta-characters. */
5443 if MBTEST(shellmeta (character
) && ((parser_state
& PST_DBLPAREN
) == 0))
5446 /* Turn off alias tokenization iff this character sequence would
5447 not leave us ready to read a command. */
5448 if (character
== '<' || character
== '>')
5449 parser_state
&= ~PST_ALEXPNEXT
;
5452 parser_state
&= ~PST_ASSIGNOK
;
5454 /* If we are parsing a command substitution and we have read a character
5455 that marks the end of it, don't bother to skip over quoted newlines
5456 when we read the next token. We're just interested in a character
5457 that will turn this into a two-character token, so we let the higher
5458 layers deal with quoted newlines following the command substitution. */
5459 if ((parser_state
& PST_CMDSUBST
) && character
== shell_eof_token
)
5460 peek_char
= shell_getc (0);
5462 peek_char
= shell_getc (1);
5464 if (character
== peek_char
)
5469 /* If '<' then we could be at "<<" or at "<<-". We have to
5470 look ahead one more character. */
5471 peek_char
= shell_getc (1);
5472 if MBTEST(peek_char
== '-')
5473 return (LESS_LESS_MINUS
);
5474 else if MBTEST(peek_char
== '<')
5475 return (LESS_LESS_LESS
);
5478 shell_ungetc (peek_char
);
5483 return (GREATER_GREATER
);
5486 parser_state
|= PST_CASEPAT
;
5488 parser_state
&= ~PST_ALEXPNEXT
;
5491 peek_char
= shell_getc (1);
5492 if MBTEST(peek_char
== '&')
5493 return (SEMI_SEMI_AND
);
5496 shell_ungetc (peek_char
);
5506 #if defined (DPAREN_ARITHMETIC) || defined (ARITH_FOR_COMMAND)
5508 result
= parse_dparen (character
);
5516 else if MBTEST(character
== '<' && peek_char
== '&')
5518 else if MBTEST(character
== '>' && peek_char
== '&')
5519 return (GREATER_AND
);
5520 else if MBTEST(character
== '<' && peek_char
== '>')
5521 return (LESS_GREATER
);
5522 else if MBTEST(character
== '>' && peek_char
== '|')
5523 return (GREATER_BAR
);
5524 else if MBTEST(character
== '&' && peek_char
== '>')
5526 peek_char
= shell_getc (1);
5527 if MBTEST(peek_char
== '>')
5528 return (AND_GREATER_GREATER
);
5531 shell_ungetc (peek_char
);
5532 return (AND_GREATER
);
5535 else if MBTEST(character
== '|' && peek_char
== '&')
5537 else if MBTEST(character
== ';' && peek_char
== '&')
5539 parser_state
|= PST_CASEPAT
;
5541 parser_state
&= ~PST_ALEXPNEXT
;
5546 shell_ungetc (peek_char
);
5548 /* If we look like we are reading the start of a function
5549 definition, then let the reader know about it so that
5550 we will do the right thing with `{'. */
5551 if MBTEST(character
== ')' && last_read_token
== '(' && token_before_that
== WORD
)
5553 parser_state
|= PST_ALLOWOPNBRC
;
5555 parser_state
&= ~PST_ALEXPNEXT
;
5557 function_dstart
= line_number
;
5560 /* case pattern lists may be preceded by an optional left paren. If
5561 we're not trying to parse a case pattern list, the left paren
5562 indicates a subshell. */
5563 if MBTEST(character
== '(' && (parser_state
& PST_CASEPAT
) == 0) /* ) */
5564 parser_state
|= PST_SUBSHELL
;
5566 else if MBTEST((parser_state
& PST_CASEPAT
) && character
== ')')
5567 parser_state
&= ~PST_CASEPAT
;
5569 else if MBTEST((parser_state
& PST_SUBSHELL
) && character
== ')')
5570 parser_state
&= ~PST_SUBSHELL
;
5572 #if defined (PROCESS_SUBSTITUTION)
5573 /* Check for the constructs which introduce process substitution.
5574 Shells running in `posix mode' don't do process substitution. */
5575 if MBTEST(posixly_correct
|| ((character
!= '>' && character
!= '<') || peek_char
!= '(')) /*)*/
5576 #endif /* PROCESS_SUBSTITUTION */
5580 /* Hack <&- (close stdin) case. Also <&N- (dup and close). */
5581 if MBTEST(character
== '-' && (last_read_token
== LESS_AND
|| last_read_token
== GREATER_AND
))
5585 /* Okay, if we got this far, we have to read a word. Read one,
5586 and then check it against the known ones. */
5587 result
= read_token_word (character
);
5589 if (result
== RE_READ_TOKEN
)
5596 * Match a $(...) or other grouping construct. This has to handle embedded
5597 * quoted strings ('', ``, "") and nested constructs. It also must handle
5598 * reprompting the user, if necessary, after reading a newline, and returning
5599 * correct error values if it reads EOF.
5601 #define P_FIRSTCLOSE 0x0001
5602 #define P_ALLOWESC 0x0002
5603 #define P_DQUOTE 0x0004
5604 #define P_COMMAND 0x0008 /* parsing a command, so look for comments */
5605 #define P_BACKQUOTE 0x0010 /* parsing a backquoted command substitution */
5606 #define P_ARRAYSUB 0x0020 /* parsing a [...] array subscript for assignment */
5607 #define P_DOLBRACE 0x0040 /* parsing a ${...} construct */
5609 /* Lexical state while parsing a grouping construct or $(...). */
5610 #define LEX_WASDOL 0x001
5611 #define LEX_CKCOMMENT 0x002
5612 #define LEX_INCOMMENT 0x004
5613 #define LEX_PASSNEXT 0x008
5614 #define LEX_RESWDOK 0x010
5615 #define LEX_CKCASE 0x020
5616 #define LEX_INCASE 0x040
5617 #define LEX_INHEREDOC 0x080
5618 #define LEX_HEREDELIM 0x100 /* reading here-doc delimiter */
5619 #define LEX_STRIPDOC 0x200 /* <<- strip tabs from here doc delim */
5620 #define LEX_QUOTEDDOC 0x400 /* here doc with quoted delim */
5621 #define LEX_INWORD 0x800
5623 #define COMSUB_META(ch) ((ch) == ';' || (ch) == '&' || (ch) == '|')
5625 #define CHECK_NESTRET_ERROR() \
5627 if (nestret == &matched_pair_error) \
5630 return &matched_pair_error; \
5634 #define APPEND_NESTRET() \
5638 RESIZE_MALLOCED_BUFFER (ret, retind, nestlen, retsize, 64); \
5639 strcpy (ret + retind, nestret); \
5640 retind += nestlen; \
5644 static char matched_pair_error
;
5647 parse_matched_pair (qc
, open
, close
, lenp
, flags
)
5648 int qc
; /* `"' if this construct is within double quotes */
5652 int count
, ch
, tflags
;
5653 int nestlen
, ttranslen
, start_lineno
;
5654 char *ret
, *nestret
, *ttrans
;
5655 int retind
, retsize
, rflags
;
5658 dolbrace_state
= (flags
& P_DOLBRACE
) ? DOLBRACE_PARAM
: 0;
5660 /*itrace("parse_matched_pair[%d]: open = %c close = %c flags = %d", line_number, open, close, flags);*/
5664 if ((flags
& P_COMMAND
) && qc
!= '`' && qc
!= '\'' && qc
!= '"' && (flags
& P_DQUOTE
) == 0)
5665 tflags
|= LEX_CKCOMMENT
;
5667 /* RFLAGS is the set of flags we want to pass to recursive calls. */
5668 rflags
= (qc
== '"') ? P_DQUOTE
: (flags
& P_DQUOTE
);
5670 ret
= (char *)xmalloc (retsize
= 64);
5673 start_lineno
= line_number
;
5676 ch
= shell_getc (qc
!= '\'' && (tflags
& (LEX_PASSNEXT
)) == 0);
5681 parser_error (start_lineno
, _("unexpected EOF while looking for matching `%c'"), close
);
5682 EOF_Reached
= 1; /* XXX */
5683 return (&matched_pair_error
);
5686 /* Possible reprompting. */
5687 if (ch
== '\n' && SHOULD_PROMPT ())
5690 /* Don't bother counting parens or doing anything else if in a comment
5691 or part of a case statement */
5692 if (tflags
& LEX_INCOMMENT
)
5694 /* Add this character. */
5695 RESIZE_MALLOCED_BUFFER (ret
, retind
, 1, retsize
, 64);
5699 tflags
&= ~LEX_INCOMMENT
;
5704 /* Not exactly right yet, should handle shell metacharacters, too. If
5705 any changes are made to this test, make analogous changes to subst.c:
5706 extract_delimited_string(). */
5707 else if MBTEST((tflags
& LEX_CKCOMMENT
) && (tflags
& LEX_INCOMMENT
) == 0 && ch
== '#' && (retind
== 0 || ret
[retind
-1] == '\n' || shellblank (ret
[retind
- 1])))
5708 tflags
|= LEX_INCOMMENT
;
5710 if (tflags
& LEX_PASSNEXT
) /* last char was backslash */
5712 tflags
&= ~LEX_PASSNEXT
;
5713 if (qc
!= '\'' && ch
== '\n') /* double-quoted \<newline> disappears. */
5716 retind
--; /* swallow previously-added backslash */
5720 RESIZE_MALLOCED_BUFFER (ret
, retind
, 2, retsize
, 64);
5721 if MBTEST(ch
== CTLESC
)
5722 ret
[retind
++] = CTLESC
;
5726 /* If we're reparsing the input (e.g., from parse_string_to_word_list),
5727 we've already prepended CTLESC to single-quoted results of $'...'.
5728 We may want to do this for other CTLESC-quoted characters in
5730 else if MBTEST((parser_state
& PST_REPARSE
) && open
== '\'' && (ch
== CTLESC
|| ch
== CTLNUL
))
5732 RESIZE_MALLOCED_BUFFER (ret
, retind
, 1, retsize
, 64);
5736 else if MBTEST(ch
== CTLESC
|| ch
== CTLNUL
) /* special shell escapes */
5738 RESIZE_MALLOCED_BUFFER (ret
, retind
, 2, retsize
, 64);
5739 ret
[retind
++] = CTLESC
;
5743 else if MBTEST(ch
== close
) /* ending delimiter */
5745 /* handle nested ${...} specially. */
5746 else if MBTEST(open
!= close
&& (tflags
& LEX_WASDOL
) && open
== '{' && ch
== open
) /* } */
5748 else if MBTEST(((flags
& P_FIRSTCLOSE
) == 0) && ch
== open
) /* nested begin */
5751 /* Add this character. */
5752 RESIZE_MALLOCED_BUFFER (ret
, retind
, 1, retsize
, 64);
5755 /* If we just read the ending character, don't bother continuing. */
5759 if (open
== '\'') /* '' inside grouping construct */
5761 if MBTEST((flags
& P_ALLOWESC
) && ch
== '\\')
5762 tflags
|= LEX_PASSNEXT
;
5766 if MBTEST(ch
== '\\') /* backslashes */
5767 tflags
|= LEX_PASSNEXT
;
5769 /* Based on which dolstate is currently in (param, op, or word),
5770 decide what the op is. We're really only concerned if it's % or
5771 #, so we can turn on a flag that says whether or not we should
5772 treat single quotes as special when inside a double-quoted
5773 ${...}. This logic must agree with subst.c:extract_dollar_brace_string
5774 since they share the same defines. */
5775 /* FLAG POSIX INTERP 221 */
5776 if (flags
& P_DOLBRACE
)
5778 /* ${param%[%]word} */
5779 if MBTEST(dolbrace_state
== DOLBRACE_PARAM
&& ch
== '%' && retind
> 1)
5780 dolbrace_state
= DOLBRACE_QUOTE
;
5781 /* ${param#[#]word} */
5782 else if MBTEST(dolbrace_state
== DOLBRACE_PARAM
&& ch
== '#' && retind
> 1)
5783 dolbrace_state
= DOLBRACE_QUOTE
;
5784 /* ${param/[/]pat/rep} */
5785 else if MBTEST(dolbrace_state
== DOLBRACE_PARAM
&& ch
== '/' && retind
> 1)
5786 dolbrace_state
= DOLBRACE_QUOTE2
; /* XXX */
5787 /* ${param^[^]pat} */
5788 else if MBTEST(dolbrace_state
== DOLBRACE_PARAM
&& ch
== '^' && retind
> 1)
5789 dolbrace_state
= DOLBRACE_QUOTE
;
5790 /* ${param,[,]pat} */
5791 else if MBTEST(dolbrace_state
== DOLBRACE_PARAM
&& ch
== ',' && retind
> 1)
5792 dolbrace_state
= DOLBRACE_QUOTE
;
5793 else if MBTEST(dolbrace_state
== DOLBRACE_PARAM
&& strchr ("#%^,~:-=?+/", ch
) != 0)
5794 dolbrace_state
= DOLBRACE_OP
;
5795 else if MBTEST(dolbrace_state
== DOLBRACE_OP
&& strchr ("#%^,~:-=?+/", ch
) == 0)
5796 dolbrace_state
= DOLBRACE_WORD
;
5799 /* The big hammer. Single quotes aren't special in double quotes. The
5800 problem is that Posix used to say the single quotes are semi-special:
5801 within a double-quoted ${...} construct "an even number of
5802 unescaped double-quotes or single-quotes, if any, shall occur." */
5803 /* This was changed in Austin Group Interp 221 */
5804 if MBTEST(posixly_correct
&& shell_compatibility_level
> 41 && dolbrace_state
!= DOLBRACE_QUOTE
&& dolbrace_state
!= DOLBRACE_QUOTE2
&& (flags
& P_DQUOTE
) && (flags
& P_DOLBRACE
) && ch
== '\'')
5807 /* Could also check open == '`' if we want to parse grouping constructs
5808 inside old-style command substitution. */
5809 if (open
!= close
) /* a grouping construct */
5811 if MBTEST(shellquote (ch
))
5813 /* '', ``, or "" inside $(...) or other grouping construct. */
5814 push_delimiter (dstack
, ch
);
5815 if MBTEST((tflags
& LEX_WASDOL
) && ch
== '\'') /* $'...' inside group */
5816 nestret
= parse_matched_pair (ch
, ch
, ch
, &nestlen
, P_ALLOWESC
|rflags
);
5818 nestret
= parse_matched_pair (ch
, ch
, ch
, &nestlen
, rflags
);
5819 pop_delimiter (dstack
);
5820 CHECK_NESTRET_ERROR ();
5822 if MBTEST((tflags
& LEX_WASDOL
) && ch
== '\'' && (extended_quote
|| (rflags
& P_DQUOTE
) == 0))
5824 /* Translate $'...' here. */
5825 ttrans
= ansiexpand (nestret
, 0, nestlen
- 1, &ttranslen
);
5828 /* If we're parsing a double-quoted brace expansion and we are
5829 not in a place where single quotes are treated specially,
5830 make sure we single-quote the results of the ansi
5831 expansion because quote removal should remove them later */
5832 /* FLAG POSIX INTERP 221 */
5833 if ((shell_compatibility_level
> 42) && (rflags
& P_DQUOTE
) && (dolbrace_state
== DOLBRACE_QUOTE2
) && (flags
& P_DOLBRACE
))
5835 nestret
= sh_single_quote (ttrans
);
5837 nestlen
= strlen (nestret
);
5839 else if ((rflags
& P_DQUOTE
) == 0)
5841 nestret
= sh_single_quote (ttrans
);
5843 nestlen
= strlen (nestret
);
5848 nestlen
= ttranslen
;
5850 retind
-= 2; /* back up before the $' */
5852 else if MBTEST((tflags
& LEX_WASDOL
) && ch
== '"' && (extended_quote
|| (rflags
& P_DQUOTE
) == 0))
5854 /* Locale expand $"..." here. */
5855 ttrans
= localeexpand (nestret
, 0, nestlen
- 1, start_lineno
, &ttranslen
);
5858 nestret
= sh_mkdoublequoted (ttrans
, ttranslen
, 0);
5860 nestlen
= ttranslen
+ 2;
5861 retind
-= 2; /* back up before the $" */
5867 else if ((flags
& (P_ARRAYSUB
|P_DOLBRACE
)) && (tflags
& LEX_WASDOL
) && (ch
== '(' || ch
== '{' || ch
== '[')) /* ) } ] */
5868 goto parse_dollar_word
;
5870 /* Parse an old-style command substitution within double quotes as a
5872 /* XXX - sh and ksh93 don't do this - XXX */
5873 else if MBTEST(open
== '"' && ch
== '`')
5875 nestret
= parse_matched_pair (0, '`', '`', &nestlen
, rflags
);
5877 CHECK_NESTRET_ERROR ();
5882 else if MBTEST(open
!= '`' && (tflags
& LEX_WASDOL
) && (ch
== '(' || ch
== '{' || ch
== '[')) /* ) } ] */
5883 /* check for $(), $[], or ${} inside quoted string. */
5886 if (open
== ch
) /* undo previous increment */
5888 if (ch
== '(') /* ) */
5889 nestret
= parse_comsub (0, '(', ')', &nestlen
, (rflags
|P_COMMAND
) & ~P_DQUOTE
);
5890 else if (ch
== '{') /* } */
5891 nestret
= parse_matched_pair (0, '{', '}', &nestlen
, P_FIRSTCLOSE
|P_DOLBRACE
|rflags
);
5892 else if (ch
== '[') /* ] */
5893 nestret
= parse_matched_pair (0, '[', ']', &nestlen
, rflags
);
5895 CHECK_NESTRET_ERROR ();
5900 if MBTEST(ch
== '$')
5901 tflags
|= LEX_WASDOL
;
5903 tflags
&= ~LEX_WASDOL
;
5909 /*itrace("parse_matched_pair[%d]: returning %s", line_number, ret);*/
5921 fprintf (stderr
, "%d -> ", f
);
5925 fprintf (stderr
, "LEX_WASDOL%s", f
? "|" : "");
5927 if (f
& LEX_CKCOMMENT
)
5929 f
&= ~LEX_CKCOMMENT
;
5930 fprintf (stderr
, "LEX_CKCOMMENT%s", f
? "|" : "");
5932 if (f
& LEX_INCOMMENT
)
5934 f
&= ~LEX_INCOMMENT
;
5935 fprintf (stderr
, "LEX_INCOMMENT%s", f
? "|" : "");
5937 if (f
& LEX_PASSNEXT
)
5940 fprintf (stderr
, "LEX_PASSNEXT%s", f
? "|" : "");
5942 if (f
& LEX_RESWDOK
)
5945 fprintf (stderr
, "LEX_RESWDOK%s", f
? "|" : "");
5950 fprintf (stderr
, "LEX_CKCASE%s", f
? "|" : "");
5955 fprintf (stderr
, "LEX_INCASE%s", f
? "|" : "");
5957 if (f
& LEX_INHEREDOC
)
5959 f
&= ~LEX_INHEREDOC
;
5960 fprintf (stderr
, "LEX_INHEREDOC%s", f
? "|" : "");
5962 if (f
& LEX_HEREDELIM
)
5964 f
&= ~LEX_HEREDELIM
;
5965 fprintf (stderr
, "LEX_HEREDELIM%s", f
? "|" : "");
5967 if (f
& LEX_STRIPDOC
)
5970 fprintf (stderr
, "LEX_WASDOL%s", f
? "|" : "");
5972 if (f
& LEX_QUOTEDDOC
)
5974 f
&= ~LEX_QUOTEDDOC
;
5975 fprintf (stderr
, "LEX_QUOTEDDOC%s", f
? "|" : "");
5980 fprintf (stderr
, "LEX_INWORD%s", f
? "|" : "");
5983 fprintf (stderr
, "\n");
5988 /* Parse a $(...) command substitution. This is messier than I'd like, and
5989 reproduces a lot more of the token-reading code than I'd like. */
5991 parse_comsub (qc
, open
, close
, lenp
, flags
)
5992 int qc
; /* `"' if this construct is within double quotes */
5996 int count
, ch
, peekc
, tflags
, lex_rwlen
, lex_wlen
, lex_firstind
;
5997 int nestlen
, ttranslen
, start_lineno
;
5998 char *ret
, *nestret
, *ttrans
, *heredelim
;
5999 int retind
, retsize
, rflags
, hdlen
;
6001 /* Posix interp 217 says arithmetic expressions have precedence, so
6002 assume $(( introduces arithmetic expansion and parse accordingly. */
6003 peekc
= shell_getc (0);
6004 shell_ungetc (peekc
);
6006 return (parse_matched_pair (qc
, open
, close
, lenp
, 0));
6008 /*itrace("parse_comsub: qc = `%c' open = %c close = %c", qc, open, close);*/
6010 tflags
= LEX_RESWDOK
;
6012 if ((flags
& P_COMMAND
) && qc
!= '\'' && qc
!= '"' && (flags
& P_DQUOTE
) == 0)
6013 tflags
|= LEX_CKCASE
;
6014 if ((tflags
& LEX_CKCASE
) && (interactive
== 0 || interactive_comments
))
6015 tflags
|= LEX_CKCOMMENT
;
6017 /* RFLAGS is the set of flags we want to pass to recursive calls. */
6018 rflags
= (flags
& P_DQUOTE
);
6020 ret
= (char *)xmalloc (retsize
= 64);
6023 start_lineno
= line_number
;
6024 lex_rwlen
= lex_wlen
= 0;
6032 ch
= shell_getc (qc
!= '\'' && (tflags
& (LEX_INCOMMENT
|LEX_PASSNEXT
)) == 0);
6039 parser_error (start_lineno
, _("unexpected EOF while looking for matching `%c'"), close
);
6040 EOF_Reached
= 1; /* XXX */
6041 return (&matched_pair_error
);
6044 /* If we hit the end of a line and are reading the contents of a here
6045 document, and it's not the same line that the document starts on,
6046 check for this line being the here doc delimiter. Otherwise, if
6047 we're in a here document, mark the next character as the beginning
6051 if ((tflags
& LEX_HEREDELIM
) && heredelim
)
6053 tflags
&= ~LEX_HEREDELIM
;
6054 tflags
|= LEX_INHEREDOC
;
6055 lex_firstind
= retind
+ 1;
6057 else if (tflags
& LEX_INHEREDOC
)
6060 tind
= lex_firstind
;
6061 while ((tflags
& LEX_STRIPDOC
) && ret
[tind
] == '\t')
6063 if (STREQN (ret
+ tind
, heredelim
, hdlen
))
6065 tflags
&= ~(LEX_STRIPDOC
|LEX_INHEREDOC
|LEX_QUOTEDDOC
);
6066 /*itrace("parse_comsub:%d: found here doc end `%s'", line_number, ret + tind);*/
6072 lex_firstind
= retind
+ 1;
6076 /* Possible reprompting. */
6077 if (ch
== '\n' && SHOULD_PROMPT ())
6080 /* XXX -- possibly allow here doc to be delimited by ending right
6082 if ((tflags
& LEX_INHEREDOC
) && ch
== close
&& count
== 1)
6085 /*itrace("parse_comsub:%d: in here doc, ch == close, retind - firstind = %d hdlen = %d retind = %d", line_number, retind-lex_firstind, hdlen, retind);*/
6086 tind
= lex_firstind
;
6087 while ((tflags
& LEX_STRIPDOC
) && ret
[tind
] == '\t')
6089 if (retind
-tind
== hdlen
&& STREQN (ret
+ tind
, heredelim
, hdlen
))
6091 tflags
&= ~(LEX_STRIPDOC
|LEX_INHEREDOC
|LEX_QUOTEDDOC
);
6092 /*itrace("parse_comsub:%d: found here doc end `%*s'", line_number, hdlen, ret + tind);*/
6099 /* Don't bother counting parens or doing anything else if in a comment or
6100 here document (not exactly right for here-docs -- if we want to allow
6101 recursive calls to parse_comsub to have their own here documents,
6102 change the LEX_INHEREDOC to LEX_QUOTEDDOC here and uncomment the next
6103 clause below. Note that to make this work completely, we need to make
6104 additional changes to allow xparse_dolparen to work right when the
6105 command substitution is parsed, because read_secondary_line doesn't know
6106 to recursively parse through command substitutions embedded in here-
6108 if (tflags
& (LEX_INCOMMENT
|LEX_INHEREDOC
))
6110 /* Add this character. */
6111 RESIZE_MALLOCED_BUFFER (ret
, retind
, 1, retsize
, 64);
6114 if ((tflags
& LEX_INCOMMENT
) && ch
== '\n')
6116 /*itrace("parse_comsub:%d: lex_incomment -> 0 ch = `%c'", line_number, ch);*/
6117 tflags
&= ~LEX_INCOMMENT
;
6123 /* If we're going to recursively parse a command substitution inside a
6124 here-document, make sure we call parse_comsub recursively below. See
6125 above for additional caveats. */
6126 if ((tflags
& LEX_INHEREDOC
) && ((tflags
& LEX_WASDOL
) == 0 || ch
!= '(')) /*)*/
6128 /* Add this character. */
6129 RESIZE_MALLOCED_BUFFER (ret
, retind
, 1, retsize
, 64);
6131 if MBTEST(ch
== '$')
6132 tflags
|= LEX_WASDOL
;
6134 tflags
&= ~LEX_WASDOL
;
6138 if (tflags
& LEX_PASSNEXT
) /* last char was backslash */
6140 /*itrace("parse_comsub:%d: lex_passnext -> 0 ch = `%c' (%d)", line_number, ch, __LINE__);*/
6141 tflags
&= ~LEX_PASSNEXT
;
6142 if (qc
!= '\'' && ch
== '\n') /* double-quoted \<newline> disappears. */
6145 retind
--; /* swallow previously-added backslash */
6149 RESIZE_MALLOCED_BUFFER (ret
, retind
, 2, retsize
, 64);
6150 if MBTEST(ch
== CTLESC
)
6151 ret
[retind
++] = CTLESC
;
6156 /* If this is a shell break character, we are not in a word. If not,
6157 we either start or continue a word. */
6158 if MBTEST(shellbreak (ch
))
6160 tflags
&= ~LEX_INWORD
;
6161 /*itrace("parse_comsub:%d: lex_inword -> 0 ch = `%c' (%d)", line_number, ch, __LINE__);*/
6165 if (tflags
& LEX_INWORD
)
6168 /*itrace("parse_comsub:%d: lex_inword == 1 ch = `%c' lex_wlen = %d (%d)", line_number, ch, lex_wlen, __LINE__);*/
6172 /*itrace("parse_comsub:%d: lex_inword -> 1 ch = `%c' (%d)", line_number, ch, __LINE__);*/
6173 tflags
|= LEX_INWORD
;
6175 if (tflags
& LEX_RESWDOK
)
6180 /* Skip whitespace */
6181 if MBTEST(shellblank (ch
) && (tflags
& LEX_HEREDELIM
) == 0 && lex_rwlen
== 0)
6183 /* Add this character. */
6184 RESIZE_MALLOCED_BUFFER (ret
, retind
, 1, retsize
, 64);
6189 /* Either we are looking for the start of the here-doc delimiter
6190 (lex_firstind == -1) or we are reading one (lex_firstind >= 0).
6191 If this character is a shell break character and we are reading
6192 the delimiter, save it and note that we are now reading a here
6193 document. If we've found the start of the delimiter, note it by
6194 setting lex_firstind. Backslashes can quote shell metacharacters
6195 in here-doc delimiters. */
6196 if (tflags
& LEX_HEREDELIM
)
6198 if (lex_firstind
== -1 && shellbreak (ch
) == 0)
6199 lex_firstind
= retind
;
6201 else if (heredelim
&& (tflags
& LEX_PASSNEXT
) == 0 && ch
== '\n')
6203 tflags
|= LEX_INHEREDOC
;
6204 tflags
&= ~LEX_HEREDELIM
;
6205 lex_firstind
= retind
+ 1;
6208 else if (lex_firstind
>= 0 && (tflags
& LEX_PASSNEXT
) == 0 && shellbreak (ch
))
6212 nestret
= substring (ret
, lex_firstind
, retind
);
6213 heredelim
= string_quote_removal (nestret
, 0);
6214 hdlen
= STRLEN(heredelim
);
6215 /*itrace("parse_comsub:%d: found here doc delimiter `%s' (%d)", line_number, heredelim, hdlen);*/
6216 if (STREQ (heredelim
, nestret
) == 0)
6217 tflags
|= LEX_QUOTEDDOC
;
6222 tflags
|= LEX_INHEREDOC
;
6223 tflags
&= ~LEX_HEREDELIM
;
6224 lex_firstind
= retind
+ 1;
6231 /* Meta-characters that can introduce a reserved word. Not perfect yet. */
6232 if MBTEST((tflags
& LEX_RESWDOK
) == 0 && (tflags
& LEX_CKCASE
) && (tflags
& LEX_INCOMMENT
) == 0 && (shellmeta(ch
) || ch
== '\n'))
6234 /* Add this character. */
6235 RESIZE_MALLOCED_BUFFER (ret
, retind
, 1, retsize
, 64);
6237 peekc
= shell_getc (1);
6238 if (ch
== peekc
&& (ch
== '&' || ch
== '|' || ch
== ';')) /* two-character tokens */
6240 RESIZE_MALLOCED_BUFFER (ret
, retind
, 1, retsize
, 64);
6241 ret
[retind
++] = peekc
;
6242 /*itrace("parse_comsub:%d: set lex_reswordok = 1, ch = `%c'", line_number, ch);*/
6243 tflags
|= LEX_RESWDOK
;
6247 else if (ch
== '\n' || COMSUB_META(ch
))
6249 shell_ungetc (peekc
);
6250 /*itrace("parse_comsub:%d: set lex_reswordok = 1, ch = `%c'", line_number, ch);*/
6251 tflags
|= LEX_RESWDOK
;
6259 /* `unget' the character we just added and fall through */
6261 shell_ungetc (peekc
);
6265 /* If we can read a reserved word, try to read one. */
6266 if (tflags
& LEX_RESWDOK
)
6268 if MBTEST(islower ((unsigned char)ch
))
6270 /* Add this character. */
6271 RESIZE_MALLOCED_BUFFER (ret
, retind
, 1, retsize
, 64);
6276 else if MBTEST(lex_rwlen
== 4 && shellbreak (ch
))
6278 if (STREQN (ret
+ retind
- 4, "case", 4))
6280 tflags
|= LEX_INCASE
;
6281 tflags
&= ~LEX_RESWDOK
;
6282 /*itrace("parse_comsub:%d: found `case', lex_incase -> 1 lex_reswdok -> 0", line_number);*/
6284 else if (STREQN (ret
+ retind
- 4, "esac", 4))
6286 tflags
&= ~LEX_INCASE
;
6287 /*itrace("parse_comsub:%d: found `esac', lex_incase -> 0 lex_reswdok -> 1", line_number);*/
6288 tflags
|= LEX_RESWDOK
;
6291 else if (STREQN (ret
+ retind
- 4, "done", 4) ||
6292 STREQN (ret
+ retind
- 4, "then", 4) ||
6293 STREQN (ret
+ retind
- 4, "else", 4) ||
6294 STREQN (ret
+ retind
- 4, "elif", 4) ||
6295 STREQN (ret
+ retind
- 4, "time", 4))
6297 /* these are four-character reserved words that can be
6298 followed by a reserved word; anything else turns off
6299 the reserved-word-ok flag */
6300 /*itrace("parse_comsub:%d: found `%.4s', lex_reswdok -> 1", line_number, ret+retind-4);*/
6301 tflags
|= LEX_RESWDOK
;
6306 tflags
&= ~LEX_RESWDOK
;
6307 /*itrace("parse_comsub:%d: found `%.4s', lex_reswdok -> 0", line_number, ret+retind-4);*/
6310 else if MBTEST((tflags
& LEX_CKCOMMENT
) && ch
== '#' && (lex_rwlen
== 0 || ((tflags
& LEX_INWORD
) && lex_wlen
== 0)))
6311 ; /* don't modify LEX_RESWDOK if we're starting a comment */
6312 /* Allow `do' followed by space, tab, or newline to preserve the
6313 RESWDOK flag, but reset the reserved word length counter so we
6314 can read another one. */
6315 else if MBTEST(((tflags
& LEX_INCASE
) == 0) &&
6316 (isblank((unsigned char)ch
) || ch
== '\n') &&
6318 STREQN (ret
+ retind
- 2, "do", 2))
6320 /*itrace("parse_comsub:%d: lex_incase == 0 found `%c', found \"do\"", line_number, ch);*/
6323 else if MBTEST((tflags
& LEX_INCASE
) && ch
!= '\n')
6324 /* If we can read a reserved word and we're in case, we're at the
6325 point where we can read a new pattern list or an esac. We
6326 handle the esac case above. If we read a newline, we want to
6327 leave LEX_RESWDOK alone. If we read anything else, we want to
6328 turn off LEX_RESWDOK, since we're going to read a pattern list. */
6330 tflags
&= ~LEX_RESWDOK
;
6331 /*itrace("parse_comsub:%d: lex_incase == 1 found `%c', lex_reswordok -> 0", line_number, ch);*/
6333 else if MBTEST(shellbreak (ch
) == 0)
6335 tflags
&= ~LEX_RESWDOK
;
6336 /*itrace("parse_comsub:%d: found `%c', lex_reswordok -> 0", line_number, ch);*/
6339 /* If we find a space or tab but have read something and it's not
6340 `do', turn off the reserved-word-ok flag */
6341 else if MBTEST(isblank ((unsigned char)ch
) && lex_rwlen
> 0)
6343 tflags
&= ~LEX_RESWDOK
;
6344 /*itrace("parse_comsub:%d: found `%c', lex_reswordok -> 0", line_number, ch);*/
6349 /* Might be the start of a here-doc delimiter */
6350 if MBTEST((tflags
& LEX_INCOMMENT
) == 0 && (tflags
& LEX_CKCASE
) && ch
== '<')
6352 /* Add this character. */
6353 RESIZE_MALLOCED_BUFFER (ret
, retind
, 1, retsize
, 64);
6355 peekc
= shell_getc (1);
6360 RESIZE_MALLOCED_BUFFER (ret
, retind
, 1, retsize
, 64);
6361 ret
[retind
++] = peekc
;
6362 peekc
= shell_getc (1);
6367 RESIZE_MALLOCED_BUFFER (ret
, retind
, 1, retsize
, 64);
6368 ret
[retind
++] = peekc
;
6369 tflags
|= LEX_STRIPDOC
;
6372 shell_ungetc (peekc
);
6375 tflags
|= LEX_HEREDELIM
;
6381 ch
= peekc
; /* fall through and continue XXX */
6383 else if MBTEST((tflags
& LEX_CKCOMMENT
) && (tflags
& LEX_INCOMMENT
) == 0 && ch
== '#' && (((tflags
& LEX_RESWDOK
) && lex_rwlen
== 0) || ((tflags
& LEX_INWORD
) && lex_wlen
== 0)))
6385 /*itrace("parse_comsub:%d: lex_incomment -> 1 (%d)", line_number, __LINE__);*/
6386 tflags
|= LEX_INCOMMENT
;
6389 if MBTEST(ch
== CTLESC
|| ch
== CTLNUL
) /* special shell escapes */
6391 RESIZE_MALLOCED_BUFFER (ret
, retind
, 2, retsize
, 64);
6392 ret
[retind
++] = CTLESC
;
6397 else if MBTEST((tflags
& LEX_INCASE
) && ch
== close
&& close
== ')')
6398 tflags
&= ~LEX_INCASE
; /* XXX */
6400 else if MBTEST(ch
== close
&& (tflags
& LEX_INCASE
) == 0) /* ending delimiter */
6403 /*itrace("parse_comsub:%d: found close: count = %d", line_number, count);*/
6405 else if MBTEST(((flags
& P_FIRSTCLOSE
) == 0) && (tflags
& LEX_INCASE
) == 0 && ch
== open
) /* nested begin */
6408 /*itrace("parse_comsub:%d: found open: count = %d", line_number, count);*/
6411 /* Add this character. */
6412 RESIZE_MALLOCED_BUFFER (ret
, retind
, 1, retsize
, 64);
6415 /* If we just read the ending character, don't bother continuing. */
6419 if MBTEST(ch
== '\\') /* backslashes */
6420 tflags
|= LEX_PASSNEXT
;
6422 if MBTEST(shellquote (ch
))
6424 /* '', ``, or "" inside $(...). */
6425 push_delimiter (dstack
, ch
);
6426 if MBTEST((tflags
& LEX_WASDOL
) && ch
== '\'') /* $'...' inside group */
6427 nestret
= parse_matched_pair (ch
, ch
, ch
, &nestlen
, P_ALLOWESC
|rflags
);
6429 nestret
= parse_matched_pair (ch
, ch
, ch
, &nestlen
, rflags
);
6430 pop_delimiter (dstack
);
6431 CHECK_NESTRET_ERROR ();
6433 if MBTEST((tflags
& LEX_WASDOL
) && ch
== '\'' && (extended_quote
|| (rflags
& P_DQUOTE
) == 0))
6435 /* Translate $'...' here. */
6436 ttrans
= ansiexpand (nestret
, 0, nestlen
- 1, &ttranslen
);
6439 if ((rflags
& P_DQUOTE
) == 0)
6441 nestret
= sh_single_quote (ttrans
);
6443 nestlen
= strlen (nestret
);
6448 nestlen
= ttranslen
;
6450 retind
-= 2; /* back up before the $' */
6452 else if MBTEST((tflags
& LEX_WASDOL
) && ch
== '"' && (extended_quote
|| (rflags
& P_DQUOTE
) == 0))
6454 /* Locale expand $"..." here. */
6455 ttrans
= localeexpand (nestret
, 0, nestlen
- 1, start_lineno
, &ttranslen
);
6458 nestret
= sh_mkdoublequoted (ttrans
, ttranslen
, 0);
6460 nestlen
= ttranslen
+ 2;
6461 retind
-= 2; /* back up before the $" */
6467 else if MBTEST((tflags
& LEX_WASDOL
) && (ch
== '(' || ch
== '{' || ch
== '[')) /* ) } ] */
6468 /* check for $(), $[], or ${} inside command substitution. */
6470 if ((tflags
& LEX_INCASE
) == 0 && open
== ch
) /* undo previous increment */
6472 if (ch
== '(') /* ) */
6473 nestret
= parse_comsub (0, '(', ')', &nestlen
, (rflags
|P_COMMAND
) & ~P_DQUOTE
);
6474 else if (ch
== '{') /* } */
6475 nestret
= parse_matched_pair (0, '{', '}', &nestlen
, P_FIRSTCLOSE
|P_DOLBRACE
|rflags
);
6476 else if (ch
== '[') /* ] */
6477 nestret
= parse_matched_pair (0, '[', ']', &nestlen
, rflags
);
6479 CHECK_NESTRET_ERROR ();
6484 if MBTEST(ch
== '$')
6485 tflags
|= LEX_WASDOL
;
6487 tflags
&= ~LEX_WASDOL
;
6494 /*itrace("parse_comsub:%d: returning `%s'", line_number, ret);*/
6498 /* Recursively call the parser to parse a $(...) command substitution. */
6500 xparse_dolparen (base
, string
, indp
, flags
)
6506 sh_parser_state_t ps
;
6507 sh_input_line_state_t ls
;
6508 int orig_ind
, nc
, sflags
, orig_eof_token
;
6509 char *ret
, *s
, *ep
, *ostring
;
6515 /*itrace("xparse_dolparen: size = %d shell_input_line = `%s'", shell_input_line_size, shell_input_line);*/
6516 sflags
= SEVAL_NONINT
|SEVAL_NOHIST
|SEVAL_NOFREE
;
6517 if (flags
& SX_NOLONGJMP
)
6518 sflags
|= SEVAL_NOLONGJMP
;
6519 save_parser_state (&ps
);
6520 save_input_line_state (&ls
);
6521 orig_eof_token
= shell_eof_token
;
6524 parser_state
|= PST_CMDSUBST
|PST_EOFTOKEN
; /* allow instant ')' */ /*(*/
6525 shell_eof_token
= ')';
6527 nc
= parse_string (string
, "command substitution", sflags
, &ep
);
6529 shell_eof_token
= orig_eof_token
;
6530 restore_parser_state (&ps
);
6532 /* reset_parser clears shell_input_line and associated variables */
6533 restore_input_line_state (&ls
);
6537 /* If parse_string returns < 0, we need to jump to top level with the
6538 negative of the return value */
6540 jump_to_top_level (-nc
); /* XXX */
6542 /* Need to find how many characters parse_and_execute consumed, update
6543 *indp, if flags != 0, copy the portion of the string parsed into RET
6544 and return it. If flags & 1 (EX_NOALLOC) we can return NULL. */
6551 itrace("xparse_dolparen:%d: ep[-1] != RPAREN (%d), ep = `%s'", line_number
, ep
[-1], ep
);
6553 while (ep
> ostring
&& ep
[-1] == '\n') ep
--;
6557 *indp
= ep
- base
- 1;
6561 if (base
[*indp
] != ')')
6562 itrace("xparse_dolparen:%d: base[%d] != RPAREN (%d), base = `%s'", line_number
, *indp
, base
[*indp
], base
);
6565 if (flags
& SX_NOALLOC
)
6566 return (char *)NULL
;
6574 ret
= substring (ostring
, 0, nc
- 1);
6579 #if defined (DPAREN_ARITHMETIC) || defined (ARITH_FOR_COMMAND)
6580 /* Parse a double-paren construct. It can be either an arithmetic
6581 command, an arithmetic `for' command, or a nested subshell. Returns
6582 the parsed token, -1 on error, or -2 if we didn't do anything and
6583 should just go on. */
6592 #if defined (ARITH_FOR_COMMAND)
6593 if (last_read_token
== FOR
)
6595 arith_for_lineno
= line_number
;
6596 cmdtyp
= parse_arith_cmd (&wval
, 0);
6599 wd
= alloc_word_desc ();
6601 yylval
.word_list
= make_word_list (wd
, (WORD_LIST
*)NULL
);
6602 return (ARITH_FOR_EXPRS
);
6605 return -1; /* ERROR */
6609 #if defined (DPAREN_ARITHMETIC)
6610 if (reserved_word_acceptable (last_read_token
))
6612 sline
= line_number
;
6614 cmdtyp
= parse_arith_cmd (&wval
, 0);
6615 if (cmdtyp
== 1) /* arithmetic command */
6617 wd
= alloc_word_desc ();
6619 wd
->flags
= W_QUOTED
|W_NOSPLIT
|W_NOGLOB
|W_DQUOTE
;
6620 yylval
.word_list
= make_word_list (wd
, (WORD_LIST
*)NULL
);
6623 else if (cmdtyp
== 0) /* nested subshell */
6625 push_string (wval
, 0, (alias_t
*)NULL
);
6626 pushed_string_list
->flags
= PSH_DPAREN
;
6627 if ((parser_state
& PST_CASEPAT
) == 0)
6628 parser_state
|= PST_SUBSHELL
;
6636 return -2; /* XXX */
6639 /* We've seen a `(('. Look for the matching `))'. If we get it, return 1.
6640 If not, assume it's a nested subshell for backwards compatibility and
6641 return 0. In any case, put the characters we've consumed into a locally-
6642 allocated buffer and make *ep point to that buffer. Return -1 on an
6643 error, for example EOF. */
6645 parse_arith_cmd (ep
, adddq
)
6649 int exp_lineno
, rval
, c
;
6650 char *ttok
, *tokstr
;
6653 exp_lineno
= line_number
;
6654 ttok
= parse_matched_pair (0, '(', ')', &ttoklen
, 0);
6656 if (ttok
== &matched_pair_error
)
6658 /* Check that the next character is the closing right paren. If
6659 not, this is a syntax error. ( */
6664 tokstr
= (char *)xmalloc (ttoklen
+ 4);
6666 /* if ADDDQ != 0 then (( ... )) -> "..." */
6667 if (rval
== 1 && adddq
) /* arith cmd, add double quotes */
6670 strncpy (tokstr
+ 1, ttok
, ttoklen
- 1);
6671 tokstr
[ttoklen
] = '"';
6672 tokstr
[ttoklen
+1] = '\0';
6674 else if (rval
== 1) /* arith cmd, don't add double quotes */
6676 strncpy (tokstr
, ttok
, ttoklen
- 1);
6677 tokstr
[ttoklen
-1] = '\0';
6679 else /* nested subshell */
6682 strncpy (tokstr
+ 1, ttok
, ttoklen
- 1);
6683 tokstr
[ttoklen
] = ')';
6684 tokstr
[ttoklen
+1] = c
;
6685 tokstr
[ttoklen
+2] = '\0';
6692 #endif /* DPAREN_ARITHMETIC || ARITH_FOR_COMMAND */
6694 #if defined (COND_COMMAND)
6700 if (EOF_Reached
&& cond_token
!= COND_ERROR
) /* [[ */
6701 parser_error (cond_lineno
, _("unexpected EOF while looking for `]]'"));
6702 else if (cond_token
!= COND_ERROR
)
6704 if (etext
= error_token_from_token (cond_token
))
6706 parser_error (cond_lineno
, _("syntax error in conditional expression: unexpected token `%s'"), etext
);
6710 parser_error (cond_lineno
, _("syntax error in conditional expression"));
6717 return (cond_or ());
6726 if (cond_token
== OR_OR
)
6729 l
= make_cond_node (COND_OR
, (WORD_DESC
*)NULL
, l
, r
);
6740 if (cond_token
== AND_AND
)
6743 l
= make_cond_node (COND_AND
, (WORD_DESC
*)NULL
, l
, r
);
6749 cond_skip_newlines ()
6751 while ((cond_token
= read_token (READ
)) == '\n')
6753 if (SHOULD_PROMPT ())
6756 return (cond_token
);
6759 #define COND_RETURN_ERROR() \
6760 do { cond_token = COND_ERROR; return ((COND_COM *)NULL); } while (0)
6766 COND_COM
*term
, *tleft
, *tright
;
6770 /* Read a token. It can be a left paren, a `!', a unary operator, or a
6771 word that should be the first argument of a binary operator. Start by
6772 skipping newlines, since this is a compound command. */
6773 tok
= cond_skip_newlines ();
6774 lineno
= line_number
;
6775 if (tok
== COND_END
)
6777 COND_RETURN_ERROR ();
6779 else if (tok
== '(')
6781 term
= cond_expr ();
6782 if (cond_token
!= ')')
6785 dispose_cond_node (term
); /* ( */
6786 if (etext
= error_token_from_token (cond_token
))
6788 parser_error (lineno
, _("unexpected token `%s', expected `)'"), etext
);
6792 parser_error (lineno
, _("expected `)'"));
6793 COND_RETURN_ERROR ();
6795 term
= make_cond_node (COND_EXPR
, (WORD_DESC
*)NULL
, term
, (COND_COM
*)NULL
);
6796 (void)cond_skip_newlines ();
6798 else if (tok
== BANG
|| (tok
== WORD
&& (yylval
.word
->word
[0] == '!' && yylval
.word
->word
[1] == '\0')))
6801 dispose_word (yylval
.word
); /* not needed */
6802 term
= cond_term ();
6804 term
->flags
|= CMD_INVERT_RETURN
;
6806 else if (tok
== WORD
&& yylval
.word
->word
[0] == '-' && yylval
.word
->word
[2] == 0 && test_unop (yylval
.word
->word
))
6809 tok
= read_token (READ
);
6812 tleft
= make_cond_node (COND_TERM
, yylval
.word
, (COND_COM
*)NULL
, (COND_COM
*)NULL
);
6813 term
= make_cond_node (COND_UNARY
, op
, tleft
, (COND_COM
*)NULL
);
6818 if (etext
= error_token_from_token (tok
))
6820 parser_error (line_number
, _("unexpected argument `%s' to conditional unary operator"), etext
);
6824 parser_error (line_number
, _("unexpected argument to conditional unary operator"));
6825 COND_RETURN_ERROR ();
6828 (void)cond_skip_newlines ();
6830 else if (tok
== WORD
) /* left argument to binary operator */
6833 tleft
= make_cond_node (COND_TERM
, yylval
.word
, (COND_COM
*)NULL
, (COND_COM
*)NULL
);
6836 tok
= read_token (READ
);
6837 if (tok
== WORD
&& test_binop (yylval
.word
->word
))
6840 if (op
->word
[0] == '=' && (op
->word
[1] == '\0' || (op
->word
[1] == '=' && op
->word
[2] == '\0')))
6841 parser_state
|= PST_EXTPAT
;
6842 else if (op
->word
[0] == '!' && op
->word
[1] == '=' && op
->word
[2] == '\0')
6843 parser_state
|= PST_EXTPAT
;
6845 #if defined (COND_REGEXP)
6846 else if (tok
== WORD
&& STREQ (yylval
.word
->word
, "=~"))
6849 parser_state
|= PST_REGEXP
;
6852 else if (tok
== '<' || tok
== '>')
6853 op
= make_word_from_token (tok
); /* ( */
6854 /* There should be a check before blindly accepting the `)' that we have
6855 seen the opening `('. */
6856 else if (tok
== COND_END
|| tok
== AND_AND
|| tok
== OR_OR
|| tok
== ')')
6858 /* Special case. [[ x ]] is equivalent to [[ -n x ]], just like
6859 the test command. Similarly for [[ x && expr ]] or
6860 [[ x || expr ]] or [[ (x) ]]. */
6861 op
= make_word ("-n");
6862 term
= make_cond_node (COND_UNARY
, op
, tleft
, (COND_COM
*)NULL
);
6868 if (etext
= error_token_from_token (tok
))
6870 parser_error (line_number
, _("unexpected token `%s', conditional binary operator expected"), etext
);
6874 parser_error (line_number
, _("conditional binary operator expected"));
6875 dispose_cond_node (tleft
);
6876 COND_RETURN_ERROR ();
6880 if (parser_state
& PST_EXTPAT
)
6882 tok
= read_token (READ
);
6883 if (parser_state
& PST_EXTPAT
)
6884 extended_glob
= global_extglob
;
6885 parser_state
&= ~(PST_REGEXP
|PST_EXTPAT
);
6889 tright
= make_cond_node (COND_TERM
, yylval
.word
, (COND_COM
*)NULL
, (COND_COM
*)NULL
);
6890 term
= make_cond_node (COND_BINARY
, op
, tleft
, tright
);
6894 if (etext
= error_token_from_token (tok
))
6896 parser_error (line_number
, _("unexpected argument `%s' to conditional binary operator"), etext
);
6900 parser_error (line_number
, _("unexpected argument to conditional binary operator"));
6901 dispose_cond_node (tleft
);
6903 COND_RETURN_ERROR ();
6906 (void)cond_skip_newlines ();
6911 parser_error (line_number
, _("unexpected token `%c' in conditional command"), tok
);
6912 else if (etext
= error_token_from_token (tok
))
6914 parser_error (line_number
, _("unexpected token `%s' in conditional command"), etext
);
6918 parser_error (line_number
, _("unexpected token %d in conditional command"), tok
);
6919 COND_RETURN_ERROR ();
6924 /* This is kind of bogus -- we slip a mini recursive-descent parser in
6925 here to handle the conditional statement syntax. */
6927 parse_cond_command ()
6931 global_extglob
= extended_glob
;
6932 cexp
= cond_expr ();
6933 return (make_cond_command (cexp
));
6937 #if defined (ARRAY_VARS)
6938 /* When this is called, it's guaranteed that we don't care about anything
6939 in t beyond i. We do save and restore the chars, though. */
6941 token_is_assignment (t
, i
)
6945 unsigned char c
, c1
;
6948 c
= t
[i
]; c1
= t
[i
+1];
6949 t
[i
] = '='; t
[i
+1] = '\0';
6950 r
= assignment (t
, (parser_state
& PST_COMPASSIGN
) != 0);
6951 t
[i
] = c
; t
[i
+1] = c1
;
6955 /* XXX - possible changes here for `+=' */
6957 token_is_ident (t
, i
)
6966 r
= legal_identifier (t
);
6973 read_token_word (character
)
6976 /* The value for YYLVAL when a WORD is read. */
6977 WORD_DESC
*the_word
;
6979 /* Index into the token that we are building. */
6982 /* ALL_DIGITS becomes zero when we see a non-digit. */
6983 int all_digit_token
;
6985 /* DOLLAR_PRESENT becomes non-zero if we see a `$'. */
6988 /* COMPOUND_ASSIGNMENT becomes non-zero if we are parsing a compound
6990 int compound_assignment
;
6992 /* QUOTED becomes non-zero if we see one of ("), ('), (`), or (\). */
6995 /* Non-zero means to ignore the value of the next character, and just
6996 to add it no matter what. */
6997 int pass_next_character
;
6999 /* The current delimiting character. */
7001 int result
, peek_char
;
7002 char *ttok
, *ttrans
;
7003 int ttoklen
, ttranslen
;
7006 if (token_buffer_size
< TOKEN_DEFAULT_INITIAL_SIZE
)
7007 token
= (char *)xrealloc (token
, token_buffer_size
= TOKEN_DEFAULT_INITIAL_SIZE
);
7010 all_digit_token
= DIGIT (character
);
7011 dollar_present
= quoted
= pass_next_character
= compound_assignment
= 0;
7015 if (character
== EOF
)
7018 if (pass_next_character
)
7020 pass_next_character
= 0;
7021 goto got_escaped_character
;
7024 cd
= current_delimiter (dstack
);
7026 /* Handle backslashes. Quote lots of things when not inside of
7027 double-quotes, quote some things inside of double-quotes. */
7028 if MBTEST(character
== '\\')
7030 peek_char
= shell_getc (0);
7032 /* Backslash-newline is ignored in all cases except
7033 when quoted with single quotes. */
7034 if (peek_char
== '\n')
7037 goto next_character
;
7041 shell_ungetc (peek_char
);
7043 /* If the next character is to be quoted, note it now. */
7044 if (cd
== 0 || cd
== '`' ||
7045 (cd
== '"' && peek_char
>= 0 && (sh_syntaxtab
[peek_char
] & CBSDQUOTE
)))
7046 pass_next_character
++;
7053 /* Parse a matched pair of quote characters. */
7054 if MBTEST(shellquote (character
))
7056 push_delimiter (dstack
, character
);
7057 ttok
= parse_matched_pair (character
, character
, character
, &ttoklen
, (character
== '`') ? P_COMMAND
: 0);
7058 pop_delimiter (dstack
);
7059 if (ttok
== &matched_pair_error
)
7060 return -1; /* Bail immediately. */
7061 RESIZE_MALLOCED_BUFFER (token
, token_index
, ttoklen
+ 2,
7062 token_buffer_size
, TOKEN_DEFAULT_GROW_SIZE
);
7063 token
[token_index
++] = character
;
7064 strcpy (token
+ token_index
, ttok
);
7065 token_index
+= ttoklen
;
7066 all_digit_token
= 0;
7068 dollar_present
|= (character
== '"' && strchr (ttok
, '$') != 0);
7070 goto next_character
;
7074 /* When parsing a regexp as a single word inside a conditional command,
7075 we need to special-case characters special to both the shell and
7076 regular expressions. Right now, that is only '(' and '|'. */ /*)*/
7077 if MBTEST((parser_state
& PST_REGEXP
) && (character
== '(' || character
== '|')) /*)*/
7079 if (character
== '|')
7082 push_delimiter (dstack
, character
);
7083 ttok
= parse_matched_pair (cd
, '(', ')', &ttoklen
, 0);
7084 pop_delimiter (dstack
);
7085 if (ttok
== &matched_pair_error
)
7086 return -1; /* Bail immediately. */
7087 RESIZE_MALLOCED_BUFFER (token
, token_index
, ttoklen
+ 2,
7088 token_buffer_size
, TOKEN_DEFAULT_GROW_SIZE
);
7089 token
[token_index
++] = character
;
7090 strcpy (token
+ token_index
, ttok
);
7091 token_index
+= ttoklen
;
7093 dollar_present
= all_digit_token
= 0;
7094 goto next_character
;
7096 #endif /* COND_REGEXP */
7098 #ifdef EXTENDED_GLOB
7099 /* Parse a ksh-style extended pattern matching specification. */
7100 if MBTEST(extended_glob
&& PATTERN_CHAR (character
))
7102 peek_char
= shell_getc (1);
7103 if MBTEST(peek_char
== '(') /* ) */
7105 push_delimiter (dstack
, peek_char
);
7106 ttok
= parse_matched_pair (cd
, '(', ')', &ttoklen
, 0);
7107 pop_delimiter (dstack
);
7108 if (ttok
== &matched_pair_error
)
7109 return -1; /* Bail immediately. */
7110 RESIZE_MALLOCED_BUFFER (token
, token_index
, ttoklen
+ 3,
7112 TOKEN_DEFAULT_GROW_SIZE
);
7113 token
[token_index
++] = character
;
7114 token
[token_index
++] = peek_char
;
7115 strcpy (token
+ token_index
, ttok
);
7116 token_index
+= ttoklen
;
7118 dollar_present
= all_digit_token
= 0;
7119 goto next_character
;
7122 shell_ungetc (peek_char
);
7124 #endif /* EXTENDED_GLOB */
7126 /* If the delimiter character is not single quote, parse some of
7127 the shell expansions that must be read as a single word. */
7128 if (shellexp (character
))
7130 peek_char
= shell_getc (1);
7131 /* $(...), <(...), >(...), $((...)), ${...}, and $[...] constructs */
7132 if MBTEST(peek_char
== '(' ||
7133 ((peek_char
== '{' || peek_char
== '[') && character
== '$')) /* ) ] } */
7135 if (peek_char
== '{') /* } */
7136 ttok
= parse_matched_pair (cd
, '{', '}', &ttoklen
, P_FIRSTCLOSE
|P_DOLBRACE
);
7137 else if (peek_char
== '(') /* ) */
7139 /* XXX - push and pop the `(' as a delimiter for use by
7140 the command-oriented-history code. This way newlines
7141 appearing in the $(...) string get added to the
7142 history literally rather than causing a possibly-
7143 incorrect `;' to be added. ) */
7144 push_delimiter (dstack
, peek_char
);
7145 ttok
= parse_comsub (cd
, '(', ')', &ttoklen
, P_COMMAND
);
7146 pop_delimiter (dstack
);
7149 ttok
= parse_matched_pair (cd
, '[', ']', &ttoklen
, 0);
7150 if (ttok
== &matched_pair_error
)
7151 return -1; /* Bail immediately. */
7152 RESIZE_MALLOCED_BUFFER (token
, token_index
, ttoklen
+ 3,
7154 TOKEN_DEFAULT_GROW_SIZE
);
7155 token
[token_index
++] = character
;
7156 token
[token_index
++] = peek_char
;
7157 strcpy (token
+ token_index
, ttok
);
7158 token_index
+= ttoklen
;
7161 all_digit_token
= 0;
7162 goto next_character
;
7164 /* This handles $'...' and $"..." new-style quoted strings. */
7165 else if MBTEST(character
== '$' && (peek_char
== '\'' || peek_char
== '"'))
7169 first_line
= line_number
;
7170 push_delimiter (dstack
, peek_char
);
7171 ttok
= parse_matched_pair (peek_char
, peek_char
, peek_char
,
7173 (peek_char
== '\'') ? P_ALLOWESC
: 0);
7174 pop_delimiter (dstack
);
7175 if (ttok
== &matched_pair_error
)
7177 if (peek_char
== '\'')
7179 ttrans
= ansiexpand (ttok
, 0, ttoklen
- 1, &ttranslen
);
7182 /* Insert the single quotes and correctly quote any
7183 embedded single quotes (allowed because P_ALLOWESC was
7184 passed to parse_matched_pair). */
7185 ttok
= sh_single_quote (ttrans
);
7187 ttranslen
= strlen (ttok
);
7192 /* Try to locale-expand the converted string. */
7193 ttrans
= localeexpand (ttok
, 0, ttoklen
- 1, first_line
, &ttranslen
);
7196 /* Add the double quotes back */
7197 ttok
= sh_mkdoublequoted (ttrans
, ttranslen
, 0);
7203 RESIZE_MALLOCED_BUFFER (token
, token_index
, ttranslen
+ 1,
7205 TOKEN_DEFAULT_GROW_SIZE
);
7206 strcpy (token
+ token_index
, ttrans
);
7207 token_index
+= ttranslen
;
7210 all_digit_token
= 0;
7211 goto next_character
;
7213 /* This could eventually be extended to recognize all of the
7214 shell's single-character parameter expansions, and set flags.*/
7215 else if MBTEST(character
== '$' && peek_char
== '$')
7217 RESIZE_MALLOCED_BUFFER (token
, token_index
, 3,
7219 TOKEN_DEFAULT_GROW_SIZE
);
7220 token
[token_index
++] = '$';
7221 token
[token_index
++] = peek_char
;
7223 all_digit_token
= 0;
7224 goto next_character
;
7227 shell_ungetc (peek_char
);
7230 #if defined (ARRAY_VARS)
7231 /* Identify possible array subscript assignment; match [...]. If
7232 parser_state&PST_COMPASSIGN, we need to parse [sub]=words treating
7233 `sub' as if it were enclosed in double quotes. */
7234 else if MBTEST(character
== '[' && /* ] */
7235 ((token_index
> 0 && assignment_acceptable (last_read_token
) && token_is_ident (token
, token_index
)) ||
7236 (token_index
== 0 && (parser_state
&PST_COMPASSIGN
))))
7238 ttok
= parse_matched_pair (cd
, '[', ']', &ttoklen
, P_ARRAYSUB
);
7239 if (ttok
== &matched_pair_error
)
7240 return -1; /* Bail immediately. */
7241 RESIZE_MALLOCED_BUFFER (token
, token_index
, ttoklen
+ 2,
7243 TOKEN_DEFAULT_GROW_SIZE
);
7244 token
[token_index
++] = character
;
7245 strcpy (token
+ token_index
, ttok
);
7246 token_index
+= ttoklen
;
7248 all_digit_token
= 0;
7249 goto next_character
;
7251 /* Identify possible compound array variable assignment. */
7252 else if MBTEST(character
== '=' && token_index
> 0 && (assignment_acceptable (last_read_token
) || (parser_state
& PST_ASSIGNOK
)) && token_is_assignment (token
, token_index
))
7254 peek_char
= shell_getc (1);
7255 if MBTEST(peek_char
== '(') /* ) */
7257 ttok
= parse_compound_assignment (&ttoklen
);
7259 RESIZE_MALLOCED_BUFFER (token
, token_index
, ttoklen
+ 4,
7261 TOKEN_DEFAULT_GROW_SIZE
);
7263 token
[token_index
++] = '=';
7264 token
[token_index
++] = '(';
7267 strcpy (token
+ token_index
, ttok
);
7268 token_index
+= ttoklen
;
7270 token
[token_index
++] = ')';
7272 all_digit_token
= 0;
7273 compound_assignment
= 1;
7275 goto next_character
;
7277 goto got_token
; /* ksh93 seems to do this */
7281 shell_ungetc (peek_char
);
7285 /* When not parsing a multi-character word construct, shell meta-
7286 characters break words. */
7287 if MBTEST(shellbreak (character
))
7289 shell_ungetc (character
);
7294 if (character
== CTLESC
|| character
== CTLNUL
)
7296 RESIZE_MALLOCED_BUFFER (token
, token_index
, 2, token_buffer_size
,
7297 TOKEN_DEFAULT_GROW_SIZE
);
7298 token
[token_index
++] = CTLESC
;
7301 got_escaped_character
:
7302 RESIZE_MALLOCED_BUFFER (token
, token_index
, 1, token_buffer_size
,
7303 TOKEN_DEFAULT_GROW_SIZE
);
7305 token
[token_index
++] = character
;
7307 all_digit_token
&= DIGIT (character
);
7308 dollar_present
|= character
== '$';
7311 if (character
== '\n' && SHOULD_PROMPT ())
7314 /* We want to remove quoted newlines (that is, a \<newline> pair)
7315 unless we are within single quotes or pass_next_character is
7316 set (the shell equivalent of literal-next). */
7317 cd
= current_delimiter (dstack
);
7318 character
= shell_getc (cd
!= '\'' && pass_next_character
== 0);
7319 } /* end for (;;) */
7323 /* Calls to RESIZE_MALLOCED_BUFFER ensure there is sufficient room. */
7324 token
[token_index
] = '\0';
7326 /* Check to see what thing we should return. If the last_read_token
7327 is a `<', or a `&', or the character which ended this token is
7328 a '>' or '<', then, and ONLY then, is this input token a NUMBER.
7329 Otherwise, it is just a word, and should be returned as such. */
7330 if MBTEST(all_digit_token
&& (character
== '<' || character
== '>' ||
7331 last_read_token
== LESS_AND
||
7332 last_read_token
== GREATER_AND
))
7334 if (legal_number (token
, &lvalue
) && (int)lvalue
== lvalue
)
7336 yylval
.number
= lvalue
;
7341 /* Check for special case tokens. */
7342 result
= (last_shell_getc_is_singlebyte
) ? special_case_tokens (token
) : -1;
7347 /* Posix.2 does not allow reserved words to be aliased, so check for all
7348 of them, including special cases, before expanding the current token
7350 if MBTEST(posixly_correct
)
7351 CHECK_FOR_RESERVED_WORD (token
);
7353 /* Aliases are expanded iff EXPAND_ALIASES is non-zero, and quoting
7354 inhibits alias expansion. */
7355 if (expand_aliases
&& quoted
== 0)
7357 result
= alias_expand_token (token
);
7358 if (result
== RE_READ_TOKEN
)
7359 return (RE_READ_TOKEN
);
7360 else if (result
== NO_EXPANSION
)
7361 parser_state
&= ~PST_ALEXPNEXT
;
7364 /* If not in Posix.2 mode, check for reserved words after alias
7366 if MBTEST(posixly_correct
== 0)
7368 CHECK_FOR_RESERVED_WORD (token
);
7370 the_word
= alloc_word_desc ();
7371 the_word
->word
= (char *)xmalloc (1 + token_index
);
7372 the_word
->flags
= 0;
7373 strcpy (the_word
->word
, token
);
7375 the_word
->flags
|= W_HASDOLLAR
;
7377 the_word
->flags
|= W_QUOTED
; /*(*/
7378 if (compound_assignment
&& token
[token_index
-1] == ')')
7379 the_word
->flags
|= W_COMPASSIGN
;
7380 /* A word is an assignment if it appears at the beginning of a
7381 simple command, or after another assignment word. This is
7382 context-dependent, so it cannot be handled in the grammar. */
7383 if (assignment (token
, (parser_state
& PST_COMPASSIGN
) != 0))
7385 the_word
->flags
|= W_ASSIGNMENT
;
7386 /* Don't perform word splitting on assignment statements. */
7387 if (assignment_acceptable (last_read_token
) || (parser_state
& PST_COMPASSIGN
) != 0)
7389 the_word
->flags
|= W_NOSPLIT
;
7390 if (parser_state
& PST_COMPASSIGN
)
7391 the_word
->flags
|= W_NOGLOB
; /* XXX - W_NOBRACE? */
7395 if (command_token_position (last_read_token
))
7398 b
= builtin_address_internal (token
, 0);
7399 if (b
&& (b
->flags
& ASSIGNMENT_BUILTIN
))
7400 parser_state
|= PST_ASSIGNOK
;
7401 else if (STREQ (token
, "eval") || STREQ (token
, "let"))
7402 parser_state
|= PST_ASSIGNOK
;
7405 yylval
.word
= the_word
;
7407 if (token
[0] == '{' && token
[token_index
-1] == '}' &&
7408 (character
== '<' || character
== '>'))
7410 /* can use token; already copied to the_word */
7411 token
[token_index
-1] = '\0';
7412 #if defined (ARRAY_VARS)
7413 if (legal_identifier (token
+1) || valid_array_reference (token
+1, 0))
7415 if (legal_identifier (token
+1))
7418 strcpy (the_word
->word
, token
+1);
7419 /*itrace("read_token_word: returning REDIR_WORD for %s", the_word->word);*/
7420 return (REDIR_WORD
);
7424 result
= ((the_word
->flags
& (W_ASSIGNMENT
|W_NOSPLIT
)) == (W_ASSIGNMENT
|W_NOSPLIT
))
7425 ? ASSIGNMENT_WORD
: WORD
;
7427 switch (last_read_token
)
7430 parser_state
|= PST_ALLOWOPNBRC
;
7431 function_dstart
= line_number
;
7436 if (word_top
< MAX_CASE_NEST
)
7438 word_lineno
[word_top
] = line_number
;
7445 /* Return 1 if TOKSYM is a token that after being read would allow
7446 a reserved word to be seen, else 0. */
7448 reserved_word_acceptable (toksym
)
7485 #if defined (COPROCESS_SUPPORT)
7486 if (last_read_token
== WORD
&& token_before_that
== COPROC
)
7489 if (last_read_token
== WORD
&& token_before_that
== FUNCTION
)
7495 /* Return the index of TOKEN in the alist of reserved words, or -1 if
7496 TOKEN is not a shell reserved word. */
7498 find_reserved_word (tokstr
)
7502 for (i
= 0; word_token_alist
[i
].word
; i
++)
7503 if (STREQ (tokstr
, word_token_alist
[i
].word
))
7508 /* An interface to let the rest of the shell (primarily the completion
7509 system) know what the parser is expecting. */
7511 parser_in_command_position ()
7513 return (command_token_position (last_read_token
));
7517 #if defined (READLINE)
7518 /* Called after each time readline is called. This insures that whatever
7519 the new prompt string is gets propagated to readline's local prompt
7522 reset_readline_prompt ()
7526 if (prompt_string_pointer
)
7528 temp_prompt
= (*prompt_string_pointer
)
7529 ? decode_prompt_string (*prompt_string_pointer
)
7532 if (temp_prompt
== 0)
7534 temp_prompt
= (char *)xmalloc (1);
7535 temp_prompt
[0] = '\0';
7538 FREE (current_readline_prompt
);
7539 current_readline_prompt
= temp_prompt
;
7542 #endif /* READLINE */
7545 #if defined (HISTORY)
7546 /* A list of tokens which can be followed by newlines, but not by
7547 semi-colons. When concatenating multiple lines of history, the
7548 newline separator for such tokens is replaced with a space. */
7549 static const int no_semi_successors
[] = {
7550 '\n', '{', '(', ')', ';', '&', '|',
7551 CASE
, DO
, ELSE
, IF
, SEMI_SEMI
, SEMI_AND
, SEMI_SEMI_AND
, THEN
, UNTIL
,
7552 WHILE
, AND_AND
, OR_OR
, IN
,
7556 /* If we are not within a delimited expression, try to be smart
7557 about which separators can be semi-colons and which must be
7558 newlines. Returns the string that should be added into the
7559 history entry. LINE is the line we're about to add; it helps
7560 make some more intelligent decisions in certain cases. */
7562 history_delimiting_chars (line
)
7565 static int last_was_heredoc
= 0; /* was the last entry the start of a here document? */
7568 if ((parser_state
& PST_HEREDOC
) == 0)
7569 last_was_heredoc
= 0;
7571 if (dstack
.delimiter_depth
!= 0)
7574 /* We look for current_command_line_count == 2 because we are looking to
7575 add the first line of the body of the here document (the second line
7576 of the command). We also keep LAST_WAS_HEREDOC as a private sentinel
7577 variable to note when we think we added the first line of a here doc
7578 (the one with a "<<" somewhere in it) */
7579 if (parser_state
& PST_HEREDOC
)
7581 if (last_was_heredoc
)
7583 last_was_heredoc
= 0;
7586 return (here_doc_first_line
? "\n" : "");
7589 if (parser_state
& PST_COMPASSIGN
)
7592 /* First, handle some special cases. */
7594 /* If we just read `()', assume it's a function definition, and don't
7595 add a semicolon. If the token before the `)' was not `(', and we're
7596 not in the midst of parsing a case statement, assume it's a
7597 parenthesized command and add the semicolon. */
7599 if (token_before_that
== ')')
7601 if (two_tokens_ago
== '(') /*)*/ /* function def */
7603 /* This does not work for subshells inside case statement
7604 command lists. It's a suboptimal solution. */
7605 else if (parser_state
& PST_CASESTMT
) /* case statement pattern */
7608 return "; "; /* (...) subshell */
7610 else if (token_before_that
== WORD
&& two_tokens_ago
== FUNCTION
)
7611 return " "; /* function def using `function name' without `()' */
7613 /* If we're not in a here document, but we think we're about to parse one,
7614 and we would otherwise return a `;', return a newline to delimit the
7615 line with the here-doc delimiter */
7616 else if ((parser_state
& PST_HEREDOC
) == 0 && current_command_line_count
> 1 && last_read_token
== '\n' && strstr (line
, "<<"))
7618 last_was_heredoc
= 1;
7621 else if ((parser_state
& PST_HEREDOC
) == 0 && current_command_line_count
> 1 && need_here_doc
> 0)
7623 else if (token_before_that
== WORD
&& two_tokens_ago
== FOR
)
7625 /* Tricky. `for i\nin ...' should not have a semicolon, but
7626 `for i\ndo ...' should. We do what we can. */
7627 for (i
= shell_input_line_index
; whitespace (shell_input_line
[i
]); i
++)
7629 if (shell_input_line
[i
] && shell_input_line
[i
] == 'i' && shell_input_line
[i
+1] == 'n')
7633 else if (two_tokens_ago
== CASE
&& token_before_that
== WORD
&& (parser_state
& PST_CASESTMT
))
7636 for (i
= 0; no_semi_successors
[i
]; i
++)
7638 if (token_before_that
== no_semi_successors
[i
])
7644 #endif /* HISTORY */
7646 /* Issue a prompt, or prepare to issue a prompt when the next character
7653 if (interactive
== 0 || expanding_alias ()) /* XXX */
7656 ps1_prompt
= get_string_value ("PS1");
7657 ps2_prompt
= get_string_value ("PS2");
7659 ps0_prompt
= get_string_value ("PS0");
7661 if (!prompt_string_pointer
)
7662 prompt_string_pointer
= &ps1_prompt
;
7664 temp_prompt
= *prompt_string_pointer
7665 ? decode_prompt_string (*prompt_string_pointer
)
7668 if (temp_prompt
== 0)
7670 temp_prompt
= (char *)xmalloc (1);
7671 temp_prompt
[0] = '\0';
7674 current_prompt_string
= *prompt_string_pointer
;
7675 prompt_string_pointer
= &ps2_prompt
;
7677 #if defined (READLINE)
7678 if (!no_line_editing
)
7680 FREE (current_readline_prompt
);
7681 current_readline_prompt
= temp_prompt
;
7684 #endif /* READLINE */
7686 FREE (current_decoded_prompt
);
7687 current_decoded_prompt
= temp_prompt
;
7692 get_current_prompt_level ()
7694 return ((current_prompt_string
&& current_prompt_string
== ps2_prompt
) ? 2 : 1);
7698 set_current_prompt_level (x
)
7701 prompt_string_pointer
= (x
== 2) ? &ps2_prompt
: &ps1_prompt
;
7702 current_prompt_string
= *prompt_string_pointer
;
7708 fprintf (stderr
, "%s", current_decoded_prompt
);
7712 /* Return a string which will be printed as a prompt. The string
7713 may contain special characters which are decoded as follows:
7716 \d the date in Day Mon Date format
7717 \e escape (ascii 033)
7718 \h the hostname up to the first `.'
7720 \j the number of active jobs
7721 \l the basename of the shell's tty device name
7724 \s the name of the shell
7725 \t the time in 24-hour hh:mm:ss format
7726 \T the time in 12-hour hh:mm:ss format
7727 \@ the time in 12-hour hh:mm am/pm format
7728 \A the time in 24-hour hh:mm format
7729 \D{fmt} the result of passing FMT to strftime(3)
7731 \v the version of bash (e.g., 2.00)
7732 \V the release of bash, version + patchlevel (e.g., 2.00.0)
7733 \w the current working directory
7734 \W the last element of $PWD
7735 \! the history number of this command
7736 \# the command number of this command
7737 \$ a $ or a # if you are root
7738 \nnn character code nnn in octal
7740 \[ begin a sequence of non-printing chars
7741 \] end a sequence of non-printing chars
7743 #define PROMPT_GROWTH 48
7745 decode_prompt_string (string
)
7750 struct dstack save_dstack
;
7751 int last_exit_value
, last_comsub_pid
;
7752 #if defined (PROMPT_STRING_DECODE)
7756 char *temp
, *t_host
, octal_string
[4];
7762 result
= (char *)xmalloc (result_size
= PROMPT_GROWTH
);
7763 result
[result_index
= 0] = 0;
7764 temp
= (char *)NULL
;
7766 while (c
= *string
++)
7768 if (posixly_correct
&& c
== '!')
7772 temp
= savestring ("!");
7777 #if !defined (HISTORY)
7778 temp
= savestring ("1");
7780 temp
= itos (history_number ());
7781 #endif /* HISTORY */
7782 string
--; /* add_string increments string again. */
7800 strncpy (octal_string
, string
, 3);
7801 octal_string
[3] = '\0';
7803 n
= read_octal (octal_string
);
7804 temp
= (char *)xmalloc (3);
7806 if (n
== CTLESC
|| n
== CTLNUL
)
7823 for (c
= 0; n
!= -1 && c
< 3 && ISOCTAL (*string
); c
++)
7826 c
= 0; /* tested at add_string: */
7834 /* Make the current time/date into a string. */
7835 (void) time (&the_time
);
7836 #if defined (HAVE_TZSET)
7837 sv_tz ("TZ"); /* XXX -- just make sure */
7839 tm
= localtime (&the_time
);
7842 n
= strftime (timebuf
, sizeof (timebuf
), "%a %b %d", tm
);
7844 n
= strftime (timebuf
, sizeof (timebuf
), "%H:%M:%S", tm
);
7846 n
= strftime (timebuf
, sizeof (timebuf
), "%I:%M:%S", tm
);
7848 n
= strftime (timebuf
, sizeof (timebuf
), "%I:%M %p", tm
);
7850 n
= strftime (timebuf
, sizeof (timebuf
), "%H:%M", tm
);
7855 timebuf
[sizeof(timebuf
) - 1] = '\0';
7857 temp
= savestring (timebuf
);
7860 case 'D': /* strftime format */
7861 if (string
[1] != '{') /* } */
7864 (void) time (&the_time
);
7865 tm
= localtime (&the_time
);
7866 string
+= 2; /* skip { */
7867 timefmt
= xmalloc (strlen (string
) + 3);
7868 for (t
= timefmt
; *string
&& *string
!= '}'; )
7871 c
= *string
; /* tested at add_string */
7872 if (timefmt
[0] == '\0')
7875 timefmt
[1] = 'X'; /* locale-specific current time */
7878 n
= strftime (timebuf
, sizeof (timebuf
), timefmt
, tm
);
7884 timebuf
[sizeof(timebuf
) - 1] = '\0';
7886 if (promptvars
|| posixly_correct
)
7887 /* Make sure that expand_prompt_string is called with a
7888 second argument of Q_DOUBLE_QUOTES if we use this
7890 temp
= sh_backslash_quote_for_double_quotes (timebuf
);
7892 temp
= savestring (timebuf
);
7896 temp
= (char *)xmalloc (3);
7897 temp
[0] = no_line_editing
? '\n' : '\r';
7898 temp
[1] = no_line_editing
? '\0' : '\n';
7903 temp
= base_pathname (shell_name
);
7904 /* Try to quote anything the user can set in the file system */
7905 if (promptvars
|| posixly_correct
)
7906 temp
= sh_backslash_quote_for_double_quotes (temp
);
7908 temp
= savestring (temp
);
7913 temp
= (char *)xmalloc (16);
7915 strcpy (temp
, dist_version
);
7917 sprintf (temp
, "%s.%d", dist_version
, patch_level
);
7923 /* Use the value of PWD because it is much more efficient. */
7924 char t_string
[PATH_MAX
];
7927 temp
= get_string_value ("PWD");
7931 if (getcwd (t_string
, sizeof(t_string
)) == 0)
7937 tlen
= strlen (t_string
);
7941 tlen
= sizeof (t_string
) - 1;
7942 strncpy (t_string
, temp
, tlen
);
7944 t_string
[tlen
] = '\0';
7946 #if defined (MACOSX)
7947 /* Convert from "fs" format to "input" format */
7948 temp
= fnx_fromfs (t_string
, strlen (t_string
));
7949 if (temp
!= t_string
)
7950 strcpy (t_string
, temp
);
7953 #define ROOT_PATH(x) ((x)[0] == '/' && (x)[1] == 0)
7954 #define DOUBLE_SLASH_ROOT(x) ((x)[0] == '/' && (x)[1] == '/' && (x)[2] == 0)
7955 /* Abbreviate \W as ~ if $PWD == $HOME */
7956 if (c
== 'W' && (((t
= get_string_value ("HOME")) == 0) || STREQ (t
, t_string
) == 0))
7958 if (ROOT_PATH (t_string
) == 0 && DOUBLE_SLASH_ROOT (t_string
) == 0)
7960 t
= strrchr (t_string
, '/');
7962 memmove (t_string
, t
+ 1, strlen (t
)); /* strlen(t) to copy NULL */
7966 #undef DOUBLE_SLASH_ROOT
7969 /* polite_directory_format is guaranteed to return a string
7970 no longer than PATH_MAX - 1 characters. */
7971 temp
= polite_directory_format (t_string
);
7972 if (temp
!= t_string
)
7973 strcpy (t_string
, temp
);
7976 temp
= trim_pathname (t_string
, PATH_MAX
- 1);
7977 /* If we're going to be expanding the prompt string later,
7978 quote the directory name. */
7979 if (promptvars
|| posixly_correct
)
7980 /* Make sure that expand_prompt_string is called with a
7981 second argument of Q_DOUBLE_QUOTES if we use this
7983 temp
= sh_backslash_quote_for_double_quotes (t_string
);
7985 temp
= savestring (t_string
);
7991 if (current_user
.user_name
== 0)
7992 get_current_user_info ();
7993 temp
= savestring (current_user
.user_name
);
7998 t_host
= savestring (current_host_name
);
7999 if (c
== 'h' && (t
= (char *)strchr (t_host
, '.')))
8001 if (promptvars
|| posixly_correct
)
8002 /* Make sure that expand_prompt_string is called with a
8003 second argument of Q_DOUBLE_QUOTES if we use this
8005 temp
= sh_backslash_quote_for_double_quotes (t_host
);
8007 temp
= savestring (t_host
);
8012 temp
= itos (current_command_number
);
8016 #if !defined (HISTORY)
8017 temp
= savestring ("1");
8019 temp
= itos (history_number ());
8020 #endif /* HISTORY */
8024 t
= temp
= (char *)xmalloc (3);
8025 if ((promptvars
|| posixly_correct
) && (current_user
.euid
!= 0))
8027 *t
++ = current_user
.euid
== 0 ? '#' : '$';
8032 temp
= itos (count_all_jobs ());
8036 #if defined (HAVE_TTYNAME)
8037 temp
= (char *)ttyname (fileno (stdin
));
8038 t
= temp
? base_pathname (temp
) : "tty";
8039 temp
= savestring (t
);
8041 temp
= savestring ("tty");
8042 #endif /* !HAVE_TTYNAME */
8045 #if defined (READLINE)
8048 if (no_line_editing
)
8053 temp
= (char *)xmalloc (3);
8054 n
= (c
== '[') ? RL_PROMPT_START_IGNORE
: RL_PROMPT_END_IGNORE
;
8056 if (n
== CTLESC
|| n
== CTLNUL
)
8061 #endif /* READLINE */
8067 temp
= (char *)xmalloc (2);
8074 else /* (c == '\\') */
8081 temp
= (char *)xmalloc (3);
8090 sub_append_string (temp
, result
, &result_index
, &result_size
);
8091 temp
= (char *)NULL
; /* Freed in sub_append_string (). */
8092 result
[result_index
] = '\0';
8098 RESIZE_MALLOCED_BUFFER (result
, result_index
, 3, result_size
, PROMPT_GROWTH
);
8099 /* dequote_string should take care of removing this if we are not
8100 performing the rest of the word expansions. */
8101 if (c
== CTLESC
|| c
== CTLNUL
)
8102 result
[result_index
++] = CTLESC
;
8103 result
[result_index
++] = c
;
8104 result
[result_index
] = '\0';
8107 #else /* !PROMPT_STRING_DECODE */
8108 result
= savestring (string
);
8109 #endif /* !PROMPT_STRING_DECODE */
8111 /* Save the delimiter stack and point `dstack' to temp space so any
8112 command substitutions in the prompt string won't result in screwing
8113 up the parser's quoting state. */
8114 save_dstack
= dstack
;
8115 dstack
= temp_dstack
;
8116 dstack
.delimiter_depth
= 0;
8118 /* Perform variable and parameter expansion and command substitution on
8119 the prompt string. */
8120 if (promptvars
|| posixly_correct
)
8122 last_exit_value
= last_command_exit_value
;
8123 last_comsub_pid
= last_command_subst_pid
;
8124 list
= expand_prompt_string (result
, Q_DOUBLE_QUOTES
, 0);
8126 result
= string_list (list
);
8127 dispose_words (list
);
8128 last_command_exit_value
= last_exit_value
;
8129 last_command_subst_pid
= last_comsub_pid
;
8133 t
= dequote_string (result
);
8138 dstack
= save_dstack
;
8143 /************************************************
8147 ************************************************/
8149 /* Report a syntax error, and restart the parser. Call here for fatal
8155 report_syntax_error ((char *)NULL
);
8161 error_token_from_token (tok
)
8166 if (t
= find_token_in_alist (tok
, word_token_alist
, 0))
8169 if (t
= find_token_in_alist (tok
, other_token_alist
, 0))
8173 /* This stuff is dicy and needs closer inspection */
8174 switch (current_token
)
8177 case ASSIGNMENT_WORD
:
8179 t
= savestring (yylval
.word
->word
);
8182 t
= itos (yylval
.number
);
8185 if (yylval
.word_list
)
8186 t
= string_list (yylval
.word_list
);
8188 case ARITH_FOR_EXPRS
:
8189 if (yylval
.word_list
)
8190 t
= string_list_internal (yylval
.word_list
, " ; ");
8193 t
= (char *)NULL
; /* punt */
8201 error_token_from_text ()
8206 t
= shell_input_line
;
8207 i
= shell_input_line_index
;
8211 if (i
&& t
[i
] == '\0')
8214 while (i
&& (whitespace (t
[i
]) || t
[i
] == '\n'))
8220 while (i
&& (member (t
[i
], " \n\t;|&") == 0))
8223 while (i
!= token_end
&& (whitespace (t
[i
]) || t
[i
] == '\n'))
8226 /* Return our idea of the offending token. */
8227 if (token_end
|| (i
== 0 && token_end
== 0))
8230 msg
= substring (t
, i
, token_end
);
8231 else /* one-character token */
8233 msg
= (char *)xmalloc (2);
8243 print_offending_line ()
8248 msg
= savestring (shell_input_line
);
8249 token_end
= strlen (msg
);
8250 while (token_end
&& msg
[token_end
- 1] == '\n')
8251 msg
[--token_end
] = '\0';
8253 parser_error (line_number
, "`%s'", msg
);
8257 /* Report a syntax error with line numbers, etc.
8258 Call here for recoverable errors. If you have a message to print,
8259 then place it in MESSAGE, otherwise pass NULL and this will figure
8260 out an appropriate message for you. */
8262 report_syntax_error (message
)
8269 parser_error (line_number
, "%s", message
);
8270 if (interactive
&& EOF_Reached
)
8272 last_command_exit_value
= parse_and_execute_level
? EX_BADSYNTAX
: EX_BADUSAGE
;
8276 /* If the line of input we're reading is not null, try to find the
8277 objectionable token. First, try to figure out what token the
8278 parser's complaining about by looking at current_token. */
8279 if (current_token
!= 0 && EOF_Reached
== 0 && (msg
= error_token_from_token (current_token
)))
8281 if (ansic_shouldquote (msg
))
8283 p
= ansic_quote (msg
, 0, NULL
);
8287 parser_error (line_number
, _("syntax error near unexpected token `%s'"), msg
);
8290 if (interactive
== 0)
8291 print_offending_line ();
8293 last_command_exit_value
= parse_and_execute_level
? EX_BADSYNTAX
: EX_BADUSAGE
;
8297 /* If looking at the current token doesn't prove fruitful, try to find the
8298 offending token by analyzing the text of the input line near the current
8299 input line index and report what we find. */
8300 if (shell_input_line
&& *shell_input_line
)
8302 msg
= error_token_from_text ();
8305 parser_error (line_number
, _("syntax error near `%s'"), msg
);
8309 /* If not interactive, print the line containing the error. */
8310 if (interactive
== 0)
8311 print_offending_line ();
8315 msg
= EOF_Reached
? _("syntax error: unexpected end of file") : _("syntax error");
8316 parser_error (line_number
, "%s", msg
);
8317 /* When the shell is interactive, this file uses EOF_Reached
8318 only for error reporting. Other mechanisms are used to
8319 decide whether or not to exit. */
8320 if (interactive
&& EOF_Reached
)
8324 last_command_exit_value
= parse_and_execute_level
? EX_BADSYNTAX
: EX_BADUSAGE
;
8327 /* ??? Needed function. ??? We have to be able to discard the constructs
8328 created during parsing. In the case of error, we want to return
8329 allocated objects to the memory pool. In the case of no error, we want
8330 to throw away the information about where the allocated objects live.
8331 (dispose_command () will actually free the command.) */
8333 discard_parser_constructs (error_p
)
8338 /************************************************
8342 ************************************************/
8344 /* Do that silly `type "bye" to exit' stuff. You know, "ignoreeof". */
8346 /* A flag denoting whether or not ignoreeof is set. */
8349 /* The number of times that we have encountered an EOF character without
8350 another character intervening. When this gets above the limit, the
8351 shell terminates. */
8352 int eof_encountered
= 0;
8354 /* The limit for eof_encountered. */
8355 int eof_encountered_limit
= 10;
8357 /* If we have EOF as the only input unit, this user wants to leave
8358 the shell. If the shell is not interactive, then just leave.
8359 Otherwise, if ignoreeof is set, and we haven't done this the
8360 required number of times in a row, print a message. */
8362 handle_eof_input_unit ()
8366 /* shell.c may use this to decide whether or not to write out the
8367 history, among other things. We use it only for error reporting
8372 /* If the user wants to "ignore" eof, then let her do so, kind of. */
8375 if (eof_encountered
< eof_encountered_limit
)
8377 fprintf (stderr
, _("Use \"%s\" to leave the shell.\n"),
8378 login_shell
? "logout" : "exit");
8380 /* Reset the parsing state. */
8381 last_read_token
= current_token
= '\n';
8382 /* Reset the prompt string to be $PS1. */
8383 prompt_string_pointer
= (char **)NULL
;
8389 /* In this case EOF should exit the shell. Do it now. */
8391 exit_builtin ((WORD_LIST
*)NULL
);
8395 /* We don't write history files, etc., for non-interactive shells. */
8400 /************************************************
8402 * STRING PARSING FUNCTIONS *
8404 ************************************************/
8406 /* It's very important that these two functions treat the characters
8407 between ( and ) identically. */
8409 static WORD_LIST parse_string_error
;
8411 /* Take a string and run it through the shell parser, returning the
8412 resultant word list. Used by compound array assignment. */
8414 parse_string_to_word_list (s
, flags
, whom
)
8420 int tok
, orig_current_token
, orig_line_number
, orig_input_terminator
;
8421 int orig_line_count
;
8422 int old_echo_input
, old_expand_aliases
;
8423 #if defined (HISTORY)
8424 int old_remember_on_history
, old_history_expansion_inhibited
;
8427 #if defined (HISTORY)
8428 old_remember_on_history
= remember_on_history
;
8429 # if defined (BANG_HISTORY)
8430 old_history_expansion_inhibited
= history_expansion_inhibited
;
8432 bash_history_disable ();
8435 orig_line_number
= line_number
;
8436 orig_line_count
= current_command_line_count
;
8437 orig_input_terminator
= shell_input_line_terminator
;
8438 old_echo_input
= echo_input_at_read
;
8439 old_expand_aliases
= expand_aliases
;
8442 last_read_token
= WORD
; /* WORD to allow reserved words here */
8443 current_command_line_count
= 0;
8444 echo_input_at_read
= expand_aliases
= 0;
8446 with_input_from_string (s
, whom
);
8447 wl
= (WORD_LIST
*)NULL
;
8450 parser_state
|= PST_COMPASSIGN
|PST_REPARSE
;
8452 while ((tok
= read_token (READ
)) != yacc_EOF
)
8454 if (tok
== '\n' && *bash_input
.location
.string
== '\0')
8456 if (tok
== '\n') /* Allow newlines in compound assignments */
8458 if (tok
!= WORD
&& tok
!= ASSIGNMENT_WORD
)
8460 line_number
= orig_line_number
+ line_number
- 1;
8461 orig_current_token
= current_token
;
8462 current_token
= tok
;
8463 yyerror (NULL
); /* does the right thing */
8464 current_token
= orig_current_token
;
8467 wl
= &parse_string_error
;
8470 wl
= make_word_list (yylval
.word
, wl
);
8473 last_read_token
= '\n';
8476 #if defined (HISTORY)
8477 remember_on_history
= old_remember_on_history
;
8478 # if defined (BANG_HISTORY)
8479 history_expansion_inhibited
= old_history_expansion_inhibited
;
8480 # endif /* BANG_HISTORY */
8481 #endif /* HISTORY */
8483 echo_input_at_read
= old_echo_input
;
8484 expand_aliases
= old_expand_aliases
;
8486 current_command_line_count
= orig_line_count
;
8487 shell_input_line_terminator
= orig_input_terminator
;
8490 parser_state
&= ~(PST_COMPASSIGN
|PST_REPARSE
);
8492 if (wl
== &parse_string_error
)
8494 last_command_exit_value
= EXECUTION_FAILURE
;
8495 if (interactive_shell
== 0 && posixly_correct
)
8496 jump_to_top_level (FORCE_EOF
);
8498 jump_to_top_level (DISCARD
);
8501 return (REVERSE_LIST (wl
, WORD_LIST
*));
8505 parse_compound_assignment (retlenp
)
8509 int tok
, orig_line_number
, orig_token_size
, orig_last_token
, assignok
;
8510 char *saved_token
, *ret
;
8512 saved_token
= token
;
8513 orig_token_size
= token_buffer_size
;
8514 orig_line_number
= line_number
;
8515 orig_last_token
= last_read_token
;
8517 last_read_token
= WORD
; /* WORD to allow reserved words here */
8519 token
= (char *)NULL
;
8520 token_buffer_size
= 0;
8522 assignok
= parser_state
&PST_ASSIGNOK
; /* XXX */
8524 wl
= (WORD_LIST
*)NULL
; /* ( */
8525 parser_state
|= PST_COMPASSIGN
;
8527 while ((tok
= read_token (READ
)) != ')')
8529 if (tok
== '\n') /* Allow newlines in compound assignments */
8531 if (SHOULD_PROMPT ())
8535 if (tok
!= WORD
&& tok
!= ASSIGNMENT_WORD
)
8537 current_token
= tok
; /* for error reporting */
8538 if (tok
== yacc_EOF
) /* ( */
8539 parser_error (orig_line_number
, _("unexpected EOF while looking for matching `)'"));
8541 yyerror(NULL
); /* does the right thing */
8544 wl
= &parse_string_error
;
8547 wl
= make_word_list (yylval
.word
, wl
);
8551 token
= saved_token
;
8552 token_buffer_size
= orig_token_size
;
8554 parser_state
&= ~PST_COMPASSIGN
;
8556 if (wl
== &parse_string_error
)
8558 last_command_exit_value
= EXECUTION_FAILURE
;
8559 last_read_token
= '\n'; /* XXX */
8560 if (interactive_shell
== 0 && posixly_correct
)
8561 jump_to_top_level (FORCE_EOF
);
8563 jump_to_top_level (DISCARD
);
8566 last_read_token
= orig_last_token
; /* XXX - was WORD? */
8570 rl
= REVERSE_LIST (wl
, WORD_LIST
*);
8571 ret
= string_list (rl
);
8578 *retlenp
= (ret
&& *ret
) ? strlen (ret
) : 0;
8581 parser_state
|= PST_ASSIGNOK
;
8586 /************************************************
8588 * SAVING AND RESTORING PARTIAL PARSE STATE *
8590 ************************************************/
8593 save_parser_state (ps
)
8594 sh_parser_state_t
*ps
;
8599 ps
= (sh_parser_state_t
*)xmalloc (sizeof (sh_parser_state_t
));
8601 return ((sh_parser_state_t
*)NULL
);
8603 ps
->parser_state
= parser_state
;
8604 ps
->token_state
= save_token_state ();
8606 ps
->input_line_terminator
= shell_input_line_terminator
;
8607 ps
->eof_encountered
= eof_encountered
;
8609 ps
->prompt_string_pointer
= prompt_string_pointer
;
8611 ps
->current_command_line_count
= current_command_line_count
;
8613 #if defined (HISTORY)
8614 ps
->remember_on_history
= remember_on_history
;
8615 # if defined (BANG_HISTORY)
8616 ps
->history_expansion_inhibited
= history_expansion_inhibited
;
8620 ps
->last_command_exit_value
= last_command_exit_value
;
8621 #if defined (ARRAY_VARS)
8622 ps
->pipestatus
= save_pipestatus_array ();
8625 ps
->last_shell_builtin
= last_shell_builtin
;
8626 ps
->this_shell_builtin
= this_shell_builtin
;
8628 ps
->expand_aliases
= expand_aliases
;
8629 ps
->echo_input_at_read
= echo_input_at_read
;
8630 ps
->need_here_doc
= need_here_doc
;
8631 ps
->here_doc_first_line
= here_doc_first_line
;
8634 for (i
= 0; i
< HEREDOC_MAX
; i
++)
8635 ps
->redir_stack
[i
] = redir_stack
[i
];
8637 if (need_here_doc
== 0)
8638 ps
->redir_stack
[0] = 0;
8640 memcpy (ps
->redir_stack
, redir_stack
, sizeof (redir_stack
[0]) * HEREDOC_MAX
);
8644 ps
->token_buffer_size
= token_buffer_size
;
8645 /* Force reallocation on next call to read_token_word */
8647 token_buffer_size
= 0;
8653 restore_parser_state (ps
)
8654 sh_parser_state_t
*ps
;
8661 parser_state
= ps
->parser_state
;
8662 if (ps
->token_state
)
8664 restore_token_state (ps
->token_state
);
8665 free (ps
->token_state
);
8668 shell_input_line_terminator
= ps
->input_line_terminator
;
8669 eof_encountered
= ps
->eof_encountered
;
8671 prompt_string_pointer
= ps
->prompt_string_pointer
;
8673 current_command_line_count
= ps
->current_command_line_count
;
8675 #if defined (HISTORY)
8676 remember_on_history
= ps
->remember_on_history
;
8677 # if defined (BANG_HISTORY)
8678 history_expansion_inhibited
= ps
->history_expansion_inhibited
;
8682 last_command_exit_value
= ps
->last_command_exit_value
;
8683 #if defined (ARRAY_VARS)
8684 restore_pipestatus_array (ps
->pipestatus
);
8687 last_shell_builtin
= ps
->last_shell_builtin
;
8688 this_shell_builtin
= ps
->this_shell_builtin
;
8690 expand_aliases
= ps
->expand_aliases
;
8691 echo_input_at_read
= ps
->echo_input_at_read
;
8692 need_here_doc
= ps
->need_here_doc
;
8693 here_doc_first_line
= ps
->here_doc_first_line
;
8696 for (i
= 0; i
< HEREDOC_MAX
; i
++)
8697 redir_stack
[i
] = ps
->redir_stack
[i
];
8699 if (need_here_doc
== 0)
8702 memcpy (redir_stack
, ps
->redir_stack
, sizeof (redir_stack
[0]) * HEREDOC_MAX
);
8707 token_buffer_size
= ps
->token_buffer_size
;
8710 sh_input_line_state_t
*
8711 save_input_line_state (ls
)
8712 sh_input_line_state_t
*ls
;
8715 ls
= (sh_input_line_state_t
*)xmalloc (sizeof (sh_input_line_state_t
));
8717 return ((sh_input_line_state_t
*)NULL
);
8719 ls
->input_line
= shell_input_line
;
8720 ls
->input_line_size
= shell_input_line_size
;
8721 ls
->input_line_len
= shell_input_line_len
;
8722 ls
->input_line_index
= shell_input_line_index
;
8724 /* force reallocation */
8725 shell_input_line
= 0;
8726 shell_input_line_size
= shell_input_line_len
= shell_input_line_index
= 0;
8732 restore_input_line_state (ls
)
8733 sh_input_line_state_t
*ls
;
8735 FREE (shell_input_line
);
8736 shell_input_line
= ls
->input_line
;
8737 shell_input_line_size
= ls
->input_line_size
;
8738 shell_input_line_len
= ls
->input_line_len
;
8739 shell_input_line_index
= ls
->input_line_index
;
8741 set_line_mbstate ();
8744 /************************************************
8746 * MULTIBYTE CHARACTER HANDLING *
8748 ************************************************/
8750 #if defined (HANDLE_MULTIBYTE)
8755 size_t i
, previ
, len
;
8756 mbstate_t mbs
, prevs
;
8759 if (shell_input_line
== NULL
)
8761 len
= strlen (shell_input_line
); /* XXX - shell_input_line_len ? */
8762 shell_input_line_property
= (char *)xrealloc (shell_input_line_property
, len
+ 1);
8764 memset (&prevs
, '\0', sizeof (mbstate_t));
8765 for (i
= previ
= 0; i
< len
; i
++)
8769 c
= shell_input_line
[i
];
8773 for (j
= i
; j
< len
; j
++)
8774 shell_input_line_property
[j
] = 1;
8778 mbclen
= mbrlen (shell_input_line
+ previ
, i
- previ
+ 1, &mbs
);
8779 if (mbclen
== 1 || mbclen
== (size_t)-1)
8784 else if (mbclen
== (size_t)-2)
8786 else if (mbclen
> 1)
8794 /* XXX - what to do if mbrlen returns 0? (null wide character) */
8796 for (j
= i
; j
< len
; j
++)
8797 shell_input_line_property
[j
] = 1;
8801 shell_input_line_property
[i
] = mbclen
;
8804 #endif /* HANDLE_MULTIBYTE */