1 /* A Bison parser, made by GNU Bison 2.3. */
3 /* Skeleton implementation for Bison's Yacc-like parsers in C
5 Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006
6 Free Software Foundation, Inc.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 Boston, MA 02110-1301, USA. */
23 /* As a special exception, you may create a larger work that contains
24 part or all of the Bison parser skeleton and distribute that work
25 under terms of your choice, so long as that work isn't itself a
26 parser generator using the skeleton or a modified version thereof
27 as a parser skeleton. Alternatively, if you modify or redistribute
28 the parser skeleton itself, you may (at your option) remove this
29 special exception, which will cause the skeleton and the resulting
30 Bison output files to be licensed under the GNU General Public
31 License without this special exception.
33 This special exception was added by the Free Software Foundation in
34 version 2.2 of Bison. */
36 /* C LALR(1) parser skeleton written by Richard Stallman, by
37 simplifying the original so-called "semantic" parser. */
39 /* All symbols defined below should begin with yy or YY, to avoid
40 infringing on user name space. This should be done even for local
41 variables, as they might otherwise be expanded by user macros.
42 There are some unavoidable exceptions within include files to
43 define necessary library symbols; they are noted "INFRINGES ON
44 USER NAME SPACE" below. */
46 /* Identify Bison output. */
50 #define YYBISON_VERSION "2.3"
53 #define YYSKELETON_NAME "yacc.c"
58 /* Using locations. */
59 #define YYLSP_NEEDED 0
66 /* Put the tokens into the symbol table, so that GDB and other debuggers
93 ASSIGNMENT_WORD
= 282,
97 ARITH_FOR_EXPRS
= 286,
101 GREATER_GREATER
= 290,
104 LESS_LESS_LESS
= 293,
109 LESS_LESS_MINUS
= 298,
111 AND_GREATER_GREATER
= 300,
134 #define COND_START 273
136 #define COND_ERROR 275
143 #define ASSIGNMENT_WORD 282
144 #define REDIR_WORD 283
146 #define ARITH_CMD 285
147 #define ARITH_FOR_EXPRS 286
151 #define GREATER_GREATER 290
152 #define LESS_LESS 291
154 #define LESS_LESS_LESS 293
155 #define GREATER_AND 294
156 #define SEMI_SEMI 295
158 #define SEMI_SEMI_AND 297
159 #define LESS_LESS_MINUS 298
160 #define AND_GREATER 299
161 #define AND_GREATER_GREATER 300
162 #define LESS_GREATER 301
163 #define GREATER_BAR 302
170 /* Copy the first part of user declarations. */
171 #line 21 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
175 #include "bashtypes.h"
176 #include "bashansi.h"
178 #include "filecntl.h"
180 #if defined (HAVE_UNISTD_H)
184 #if defined (HAVE_LOCALE_H)
189 #include "chartypes.h"
192 #include "memalloc.h"
194 #include "bashintl.h"
196 #define NEED_STRFTIME_DECL /* used in externs.h */
199 #include "typemax.h" /* SIZE_MAX if needed */
203 #include "mailcheck.h"
205 #include "builtins.h"
206 #include "builtins/common.h"
207 #include "builtins/builtext.h"
209 #include "shmbutil.h"
211 #if defined (READLINE)
212 # include "bashline.h"
213 # include <readline/readline.h>
214 #endif /* READLINE */
216 #if defined (HISTORY)
217 # include "bashhist.h"
218 # include <readline/history.h>
221 #if defined (JOB_CONTROL)
223 #endif /* JOB_CONTROL */
228 typedef void *alias_t
;
231 #if defined (PROMPT_STRING_DECODE)
233 # include <sys/param.h>
236 # if defined (TM_IN_SYS_TIME)
237 # include <sys/types.h>
238 # include <sys/time.h>
239 # endif /* TM_IN_SYS_TIME */
240 # include "maxpath.h"
241 #endif /* PROMPT_STRING_DECODE */
243 #define RE_READ_TOKEN -99
244 #define NO_EXPANSION -100
252 #if defined (HANDLE_MULTIBYTE)
253 # define last_shell_getc_is_singlebyte \
254 ((shell_input_line_index > 1) \
255 ? shell_input_line_property[shell_input_line_index - 1] \
257 # define MBTEST(x) ((x) && last_shell_getc_is_singlebyte)
259 # define last_shell_getc_is_singlebyte 1
260 # define MBTEST(x) ((x))
263 #if defined (EXTENDED_GLOB)
264 extern int extended_glob
;
267 extern int eof_encountered
;
268 extern int no_line_editing
, running_under_emacs
;
269 extern int current_command_number
;
270 extern int sourcelevel
, parse_and_execute_level
;
271 extern int posixly_correct
;
272 extern int last_command_exit_value
;
273 extern pid_t last_command_subst_pid
;
274 extern char *shell_name
, *current_host_name
;
275 extern char *dist_version
;
276 extern int patch_level
;
277 extern int dump_translatable_strings
, dump_po_strings
;
278 extern sh_builtin_func_t
*last_shell_builtin
, *this_shell_builtin
;
279 #if defined (BUFFERED_INPUT)
280 extern int bash_input_fd_changed
;
284 /* **************************************************************** */
286 /* "Forward" declarations */
288 /* **************************************************************** */
291 static void debug_parser
__P((int));
294 static int yy_getc
__P((void));
295 static int yy_ungetc
__P((int));
297 #if defined (READLINE)
298 static int yy_readline_get
__P((void));
299 static int yy_readline_unget
__P((int));
302 static int yy_string_get
__P((void));
303 static int yy_string_unget
__P((int));
304 static void rewind_input_string
__P((void));
305 static int yy_stream_get
__P((void));
306 static int yy_stream_unget
__P((int));
308 static int shell_getc
__P((int));
309 static void shell_ungetc
__P((int));
310 static void discard_until
__P((int));
312 #if defined (ALIAS) || defined (DPAREN_ARITHMETIC)
313 static void push_string
__P((char *, int, alias_t
*));
314 static void pop_string
__P((void));
315 static void free_string_list
__P((void));
318 static char *read_a_line
__P((int));
320 static int reserved_word_acceptable
__P((int));
321 static int yylex
__P((void));
323 static void push_heredoc
__P((REDIRECT
*));
324 static char *mk_alexpansion
__P((char *));
325 static int alias_expand_token
__P((char *));
326 static int time_command_acceptable
__P((void));
327 static int special_case_tokens
__P((char *));
328 static int read_token
__P((int));
329 static char *parse_matched_pair
__P((int, int, int, int *, int));
330 static char *parse_comsub
__P((int, int, int, int *, int));
331 #if defined (ARRAY_VARS)
332 static char *parse_compound_assignment
__P((int *));
334 #if defined (DPAREN_ARITHMETIC) || defined (ARITH_FOR_COMMAND)
335 static int parse_dparen
__P((int));
336 static int parse_arith_cmd
__P((char **, int));
338 #if defined (COND_COMMAND)
339 static void cond_error
__P((void));
340 static COND_COM
*cond_expr
__P((void));
341 static COND_COM
*cond_or
__P((void));
342 static COND_COM
*cond_and
__P((void));
343 static COND_COM
*cond_term
__P((void));
344 static int cond_skip_newlines
__P((void));
345 static COMMAND
*parse_cond_command
__P((void));
347 #if defined (ARRAY_VARS)
348 static int token_is_assignment
__P((char *, int));
349 static int token_is_ident
__P((char *, int));
351 static int read_token_word
__P((int));
352 static void discard_parser_constructs
__P((int));
354 static char *error_token_from_token
__P((int));
355 static char *error_token_from_text
__P((void));
356 static void print_offending_line
__P((void));
357 static void report_syntax_error
__P((char *));
359 static void handle_eof_input_unit
__P((void));
360 static void prompt_again
__P((void));
362 static void reset_readline_prompt
__P((void));
364 static void print_prompt
__P((void));
366 #if defined (HANDLE_MULTIBYTE)
367 static void set_line_mbstate
__P((void));
368 static char *shell_input_line_property
= NULL
;
370 # define set_line_mbstate()
373 extern int yyerror
__P((const char *));
379 /* Default prompt strings */
380 char *primary_prompt
= PPROMPT
;
381 char *secondary_prompt
= SPROMPT
;
383 /* PROMPT_STRING_POINTER points to one of these, never to an actual string. */
384 char *ps1_prompt
, *ps2_prompt
;
386 /* Handle on the current prompt string. Indirectly points through
387 ps1_ or ps2_prompt. */
388 char **prompt_string_pointer
= (char **)NULL
;
389 char *current_prompt_string
;
391 /* Non-zero means we expand aliases in commands. */
392 int expand_aliases
= 0;
394 /* If non-zero, the decoded prompt string undergoes parameter and
395 variable substitution, command substitution, arithmetic substitution,
396 string expansion, process substitution, and quote removal in
397 decode_prompt_string. */
400 /* If non-zero, $'...' and $"..." are expanded when they appear within
401 a ${...} expansion, even when the expansion appears within double
403 int extended_quote
= 1;
405 /* The number of lines read from input while creating the current command. */
406 int current_command_line_count
;
408 /* The number of lines in a command saved while we run parse_and_execute */
409 int saved_command_line_count
;
411 /* The token that currently denotes the end of parse. */
414 /* The token currently being read. */
417 /* The current parser state. */
420 /* Variables to manage the task of reading here documents, because we need to
421 defer the reading until after a complete command has been collected. */
422 #define HEREDOC_MAX 16
424 static REDIRECT
*redir_stack
[HEREDOC_MAX
];
427 /* Where shell input comes from. History expansion is performed on each
428 line when the shell is interactive. */
429 static char *shell_input_line
= (char *)NULL
;
430 static size_t shell_input_line_index
;
431 static size_t shell_input_line_size
; /* Amount allocated for shell_input_line. */
432 static size_t shell_input_line_len
; /* strlen (shell_input_line) */
434 /* Either zero or EOF. */
435 static int shell_input_line_terminator
;
437 /* The line number in a script on which a function definition starts. */
438 static int function_dstart
;
440 /* The line number in a script on which a function body starts. */
441 static int function_bstart
;
443 /* The line number in a script at which an arithmetic for command starts. */
444 static int arith_for_lineno
;
446 /* The decoded prompt string. Used if READLINE is not defined or if
447 editing is turned off. Analogous to current_readline_prompt. */
448 static char *current_decoded_prompt
;
450 /* The last read token, or NULL. read_token () uses this for context
452 static int last_read_token
;
454 /* The token read prior to last_read_token. */
455 static int token_before_that
;
457 /* The token read prior to token_before_that. */
458 static int two_tokens_ago
;
460 static int global_extglob
;
462 /* The line number in a script where the word in a `case WORD', `select WORD'
463 or `for WORD' begins. This is a nested command maximum, since the array
464 index is decremented after a case, select, or for command is parsed. */
465 #define MAX_CASE_NEST 128
466 static int word_lineno
[MAX_CASE_NEST
+1];
467 static int word_top
= -1;
469 /* If non-zero, it is the token that we want read_token to return
470 regardless of what text is (or isn't) present to be read. This
471 is reset by read_token. If token_to_read == WORD or
472 ASSIGNMENT_WORD, yylval.word should be set to word_desc_to_read. */
473 static int token_to_read
;
474 static WORD_DESC
*word_desc_to_read
;
476 static REDIRECTEE source
;
477 static REDIRECTEE redir
;
480 /* Enabling traces. */
485 /* Enabling verbose error messages. */
486 #ifdef YYERROR_VERBOSE
487 # undef YYERROR_VERBOSE
488 # define YYERROR_VERBOSE 1
490 # define YYERROR_VERBOSE 0
493 /* Enabling the token table. */
494 #ifndef YYTOKEN_TABLE
495 # define YYTOKEN_TABLE 0
498 #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
499 typedef union YYSTYPE
500 #line 329 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
502 WORD_DESC
*word
; /* the word that we read. */
503 int number
; /* the number that we read. */
504 WORD_LIST
*word_list
;
508 PATTERN_LIST
*pattern
;
510 /* Line 193 of yacc.c. */
513 # define yystype YYSTYPE /* obsolescent; will be withdrawn */
514 # define YYSTYPE_IS_DECLARED 1
515 # define YYSTYPE_IS_TRIVIAL 1
520 /* Copy the second part of user declarations. */
523 /* Line 216 of yacc.c. */
531 typedef YYTYPE_UINT8 yytype_uint8
;
533 typedef unsigned char yytype_uint8
;
537 typedef YYTYPE_INT8 yytype_int8
;
538 #elif (defined __STDC__ || defined __C99__FUNC__ \
539 || defined __cplusplus || defined _MSC_VER)
540 typedef signed char yytype_int8
;
542 typedef short int yytype_int8
;
546 typedef YYTYPE_UINT16 yytype_uint16
;
548 typedef unsigned short int yytype_uint16
;
552 typedef YYTYPE_INT16 yytype_int16
;
554 typedef short int yytype_int16
;
558 # ifdef __SIZE_TYPE__
559 # define YYSIZE_T __SIZE_TYPE__
560 # elif defined size_t
561 # define YYSIZE_T size_t
562 # elif ! defined YYSIZE_T && (defined __STDC__ || defined __C99__FUNC__ \
563 || defined __cplusplus || defined _MSC_VER)
564 # include <stddef.h> /* INFRINGES ON USER NAME SPACE */
565 # define YYSIZE_T size_t
567 # define YYSIZE_T unsigned int
571 #define YYSIZE_MAXIMUM ((YYSIZE_T) -1)
574 # if defined YYENABLE_NLS && YYENABLE_NLS
576 # include <libintl.h> /* INFRINGES ON USER NAME SPACE */
577 # define YY_(msgid) dgettext ("bison-runtime", msgid)
581 # define YY_(msgid) msgid
585 /* Suppress unused-variable warnings by "using" E. */
586 #if ! defined lint || defined __GNUC__
587 # define YYUSE(e) ((void) (e))
589 # define YYUSE(e) /* empty */
592 /* Identity function, used to suppress warnings about constant conditions. */
596 #if (defined __STDC__ || defined __C99__FUNC__ \
597 || defined __cplusplus || defined _MSC_VER)
610 #if ! defined yyoverflow || YYERROR_VERBOSE
612 /* The parser invokes alloca or malloc; define the necessary symbols. */
614 # ifdef YYSTACK_USE_ALLOCA
615 # if YYSTACK_USE_ALLOCA
617 # define YYSTACK_ALLOC __builtin_alloca
618 # elif defined __BUILTIN_VA_ARG_INCR
619 # include <alloca.h> /* INFRINGES ON USER NAME SPACE */
621 # define YYSTACK_ALLOC __alloca
622 # elif defined _MSC_VER
623 # include <malloc.h> /* INFRINGES ON USER NAME SPACE */
624 # define alloca _alloca
626 # define YYSTACK_ALLOC alloca
627 # if ! defined _ALLOCA_H && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
628 || defined __cplusplus || defined _MSC_VER)
629 # include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
638 # ifdef YYSTACK_ALLOC
639 /* Pacify GCC's `empty if-body' warning. */
640 # define YYSTACK_FREE(Ptr) do { /* empty */; } while (YYID (0))
641 # ifndef YYSTACK_ALLOC_MAXIMUM
642 /* The OS might guarantee only one guard page at the bottom of the stack,
643 and a page size can be as small as 4096 bytes. So we cannot safely
644 invoke alloca (N) if N exceeds 4096. Use a slightly smaller number
645 to allow for a few compiler-allocated temporary stack slots. */
646 # define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */
649 # define YYSTACK_ALLOC YYMALLOC
650 # define YYSTACK_FREE YYFREE
651 # ifndef YYSTACK_ALLOC_MAXIMUM
652 # define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM
654 # if (defined __cplusplus && ! defined _STDLIB_H \
655 && ! ((defined YYMALLOC || defined malloc) \
656 && (defined YYFREE || defined free)))
657 # include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
663 # define YYMALLOC malloc
664 # if ! defined malloc && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
665 || defined __cplusplus || defined _MSC_VER)
666 void *malloc (YYSIZE_T
); /* INFRINGES ON USER NAME SPACE */
671 # if ! defined free && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
672 || defined __cplusplus || defined _MSC_VER)
673 void free (void *); /* INFRINGES ON USER NAME SPACE */
677 #endif /* ! defined yyoverflow || YYERROR_VERBOSE */
680 #if (! defined yyoverflow \
681 && (! defined __cplusplus \
682 || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
684 /* A type that is properly aligned for any stack member. */
691 /* The size of the maximum gap between one aligned stack and the next. */
692 # define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1)
694 /* The size of an array large to enough to hold all stacks, each with
696 # define YYSTACK_BYTES(N) \
697 ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE)) \
698 + YYSTACK_GAP_MAXIMUM)
700 /* Copy COUNT objects from FROM to TO. The source and destination do
703 # if defined __GNUC__ && 1 < __GNUC__
704 # define YYCOPY(To, From, Count) \
705 __builtin_memcpy (To, From, (Count) * sizeof (*(From)))
707 # define YYCOPY(To, From, Count) \
711 for (yyi = 0; yyi < (Count); yyi++) \
712 (To)[yyi] = (From)[yyi]; \
718 /* Relocate STACK from its old location to the new one. The
719 local variables YYSIZE and YYSTACKSIZE give the old and new number of
720 elements in the stack, and YYPTR gives the new location of the
721 stack. Advance YYPTR to a properly aligned location for the next
723 # define YYSTACK_RELOCATE(Stack) \
726 YYSIZE_T yynewbytes; \
727 YYCOPY (&yyptr->Stack, Stack, yysize); \
728 Stack = &yyptr->Stack; \
729 yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \
730 yyptr += yynewbytes / sizeof (*yyptr); \
736 /* YYFINAL -- State number of the termination state. */
738 /* YYLAST -- Last index in YYTABLE. */
741 /* YYNTOKENS -- Number of terminals. */
743 /* YYNNTS -- Number of nonterminals. */
745 /* YYNRULES -- Number of rules. */
747 /* YYNRULES -- Number of states. */
748 #define YYNSTATES 342
750 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
752 #define YYMAXUTOK 304
754 #define YYTRANSLATE(YYX) \
755 ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
757 /* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */
758 static const yytype_uint8 yytranslate
[] =
760 0, 2, 2, 2, 2, 2, 2, 2, 2, 2,
761 51, 2, 2, 2, 2, 2, 2, 2, 2, 2,
762 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
763 2, 2, 2, 2, 2, 2, 2, 2, 49, 2,
764 59, 60, 2, 2, 2, 56, 2, 2, 2, 2,
765 2, 2, 2, 2, 2, 2, 2, 2, 2, 50,
766 55, 2, 54, 2, 2, 2, 2, 2, 2, 2,
767 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
768 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
769 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
770 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
771 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
772 2, 2, 2, 57, 53, 58, 2, 2, 2, 2,
773 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
774 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
775 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
776 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
777 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
778 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
779 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
780 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
781 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
782 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
783 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
784 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
785 2, 2, 2, 2, 2, 2, 1, 2, 3, 4,
786 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
787 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
788 25, 26, 27, 28, 29, 30, 31, 32, 33, 34,
789 35, 36, 37, 38, 39, 40, 41, 42, 43, 44,
794 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
796 static const yytype_uint16 yyprhs
[] =
798 0, 0, 3, 6, 8, 11, 13, 15, 18, 21,
799 24, 28, 32, 36, 40, 43, 47, 51, 54, 58,
800 62, 65, 69, 73, 76, 80, 84, 87, 91, 95,
801 98, 102, 106, 109, 113, 117, 120, 124, 128, 131,
802 135, 139, 142, 146, 150, 153, 157, 161, 164, 168,
803 172, 175, 178, 180, 182, 184, 186, 189, 191, 194,
804 196, 198, 201, 203, 205, 207, 209, 215, 221, 223,
805 225, 227, 229, 231, 233, 235, 242, 249, 257, 265,
806 276, 287, 297, 307, 315, 323, 329, 335, 342, 349,
807 357, 365, 376, 387, 394, 402, 409, 415, 422, 427,
808 429, 432, 436, 439, 443, 447, 452, 455, 461, 469,
809 476, 480, 482, 486, 491, 498, 504, 506, 509, 514,
810 519, 525, 531, 534, 538, 541, 545, 548, 552, 554,
811 558, 561, 563, 566, 570, 574, 578, 583, 588, 593,
812 598, 603, 605, 607, 609, 611, 613, 615, 616, 619,
813 621, 624, 627, 632, 637, 641, 645, 647, 649, 652,
814 655, 658, 661, 666, 671, 673, 675, 678
817 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
818 static const yytype_int8 yyrhs
[] =
820 62, 0, -1, 94, 91, -1, 51, -1, 1, 51,
821 -1, 52, -1, 26, -1, 63, 26, -1, 54, 26,
822 -1, 55, 26, -1, 29, 54, 26, -1, 29, 55,
823 26, -1, 28, 54, 26, -1, 28, 55, 26, -1,
824 35, 26, -1, 29, 35, 26, -1, 28, 35, 26,
825 -1, 47, 26, -1, 29, 47, 26, -1, 28, 47,
826 26, -1, 46, 26, -1, 29, 46, 26, -1, 28,
827 46, 26, -1, 36, 26, -1, 29, 36, 26, -1,
828 28, 36, 26, -1, 43, 26, -1, 29, 43, 26,
829 -1, 28, 43, 26, -1, 38, 26, -1, 29, 38,
830 26, -1, 28, 38, 26, -1, 37, 29, -1, 29,
831 37, 29, -1, 28, 37, 29, -1, 39, 29, -1,
832 29, 39, 29, -1, 28, 39, 29, -1, 37, 26,
833 -1, 29, 37, 26, -1, 28, 37, 26, -1, 39,
834 26, -1, 29, 39, 26, -1, 28, 39, 26, -1,
835 39, 56, -1, 29, 39, 56, -1, 28, 39, 56,
836 -1, 37, 56, -1, 29, 37, 56, -1, 28, 37,
837 56, -1, 44, 26, -1, 45, 26, -1, 26, -1,
838 27, -1, 64, -1, 64, -1, 66, 64, -1, 65,
839 -1, 67, 65, -1, 67, -1, 69, -1, 69, 66,
840 -1, 74, -1, 77, -1, 70, -1, 73, -1, 12,
841 88, 14, 88, 15, -1, 13, 88, 14, 88, 15,
842 -1, 72, -1, 78, -1, 76, -1, 79, -1, 80,
843 -1, 81, -1, 71, -1, 10, 26, 93, 14, 88,
844 15, -1, 10, 26, 93, 57, 88, 58, -1, 10,
845 26, 50, 93, 14, 88, 15, -1, 10, 26, 50,
846 93, 57, 88, 58, -1, 10, 26, 93, 21, 63,
847 92, 93, 14, 88, 15, -1, 10, 26, 93, 21,
848 63, 92, 93, 57, 88, 58, -1, 10, 26, 93,
849 21, 92, 93, 14, 88, 15, -1, 10, 26, 93,
850 21, 92, 93, 57, 88, 58, -1, 10, 31, 92,
851 93, 14, 88, 15, -1, 10, 31, 92, 93, 57,
852 88, 58, -1, 10, 31, 14, 88, 15, -1, 10,
853 31, 57, 88, 58, -1, 11, 26, 93, 14, 87,
854 15, -1, 11, 26, 93, 57, 87, 58, -1, 11,
855 26, 50, 93, 14, 87, 15, -1, 11, 26, 50,
856 93, 57, 87, 58, -1, 11, 26, 93, 21, 63,
857 92, 93, 14, 87, 15, -1, 11, 26, 93, 21,
858 63, 92, 93, 57, 87, 58, -1, 8, 26, 93,
859 21, 93, 9, -1, 8, 26, 93, 21, 85, 93,
860 9, -1, 8, 26, 93, 21, 83, 9, -1, 26,
861 59, 60, 93, 75, -1, 16, 26, 59, 60, 93,
862 75, -1, 16, 26, 93, 75, -1, 69, -1, 69,
863 66, -1, 59, 88, 60, -1, 17, 69, -1, 17,
864 69, 66, -1, 17, 26, 69, -1, 17, 26, 69,
865 66, -1, 17, 67, -1, 3, 88, 4, 88, 7,
866 -1, 3, 88, 4, 88, 5, 88, 7, -1, 3,
867 88, 4, 88, 82, 7, -1, 57, 88, 58, -1,
868 30, -1, 18, 32, 19, -1, 6, 88, 4, 88,
869 -1, 6, 88, 4, 88, 5, 88, -1, 6, 88,
870 4, 88, 82, -1, 84, -1, 85, 84, -1, 93,
871 86, 60, 88, -1, 93, 86, 60, 93, -1, 93,
872 59, 86, 60, 88, -1, 93, 59, 86, 60, 93,
873 -1, 84, 40, -1, 85, 84, 40, -1, 84, 41,
874 -1, 85, 84, 41, -1, 84, 42, -1, 85, 84,
875 42, -1, 26, -1, 86, 53, 26, -1, 93, 89,
876 -1, 87, -1, 93, 90, -1, 90, 51, 93, -1,
877 90, 49, 93, -1, 90, 50, 93, -1, 90, 33,
878 93, 90, -1, 90, 34, 93, 90, -1, 90, 49,
879 93, 90, -1, 90, 50, 93, 90, -1, 90, 51,
880 93, 90, -1, 96, -1, 51, -1, 52, -1, 51,
881 -1, 50, -1, 52, -1, -1, 93, 51, -1, 95,
882 -1, 95, 49, -1, 95, 50, -1, 95, 33, 93,
883 95, -1, 95, 34, 93, 95, -1, 95, 49, 95,
884 -1, 95, 50, 95, -1, 96, -1, 97, -1, 22,
885 96, -1, 98, 96, -1, 98, 92, -1, 22, 92,
886 -1, 97, 53, 93, 97, -1, 97, 48, 93, 97,
887 -1, 68, -1, 23, -1, 23, 24, -1, 23, 24,
891 /* YYRLINE[YYN] -- source line where rule number YYN was defined. */
892 static const yytype_uint16 yyrline
[] =
894 0, 382, 382, 393, 402, 417, 427, 429, 433, 439,
895 445, 451, 457, 463, 469, 475, 481, 487, 493, 499,
896 505, 511, 517, 523, 530, 537, 544, 551, 558, 565,
897 571, 577, 583, 589, 595, 601, 607, 613, 619, 625,
898 631, 637, 643, 649, 655, 661, 667, 673, 679, 685,
899 691, 697, 705, 707, 709, 713, 717, 728, 730, 734,
900 736, 738, 754, 756, 760, 762, 764, 766, 768, 770,
901 772, 774, 776, 778, 780, 784, 789, 794, 799, 804,
902 809, 814, 819, 826, 831, 836, 841, 848, 853, 858,
903 863, 868, 873, 880, 885, 890, 897, 900, 903, 907,
904 909, 940, 947, 952, 969, 974, 991, 998, 1000, 1002,
905 1007, 1011, 1015, 1019, 1021, 1023, 1027, 1028, 1032, 1034,
906 1036, 1038, 1042, 1044, 1046, 1048, 1050, 1052, 1056, 1058,
907 1067, 1075, 1076, 1082, 1083, 1090, 1094, 1096, 1098, 1105,
908 1107, 1109, 1113, 1114, 1117, 1119, 1121, 1125, 1126, 1135,
909 1148, 1164, 1179, 1181, 1183, 1190, 1193, 1197, 1199, 1205,
910 1211, 1228, 1248, 1250, 1273, 1277, 1279, 1281
914 #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
915 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
916 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
917 static const char *const yytname
[] =
919 "$end", "error", "$undefined", "IF", "THEN", "ELSE", "ELIF", "FI",
920 "CASE", "ESAC", "FOR", "SELECT", "WHILE", "UNTIL", "DO", "DONE",
921 "FUNCTION", "COPROC", "COND_START", "COND_END", "COND_ERROR", "IN",
922 "BANG", "TIME", "TIMEOPT", "TIMEIGN", "WORD", "ASSIGNMENT_WORD",
923 "REDIR_WORD", "NUMBER", "ARITH_CMD", "ARITH_FOR_EXPRS", "COND_CMD",
924 "AND_AND", "OR_OR", "GREATER_GREATER", "LESS_LESS", "LESS_AND",
925 "LESS_LESS_LESS", "GREATER_AND", "SEMI_SEMI", "SEMI_AND",
926 "SEMI_SEMI_AND", "LESS_LESS_MINUS", "AND_GREATER", "AND_GREATER_GREATER",
927 "LESS_GREATER", "GREATER_BAR", "BAR_AND", "'&'", "';'", "'\\n'",
928 "yacc_EOF", "'|'", "'>'", "'<'", "'-'", "'{'", "'}'", "'('", "')'",
929 "$accept", "inputunit", "word_list", "redirection",
930 "simple_command_element", "redirection_list", "simple_command",
931 "command", "shell_command", "for_command", "arith_for_command",
932 "select_command", "case_command", "function_def", "function_body",
933 "subshell", "coproc", "if_command", "group_command", "arith_command",
934 "cond_command", "elif_clause", "case_clause", "pattern_list",
935 "case_clause_sequence", "pattern", "list", "compound_list", "list0",
936 "list1", "simple_list_terminator", "list_terminator", "newline_list",
937 "simple_list", "simple_list1", "pipeline_command", "pipeline",
943 /* YYTOKNUM[YYLEX-NUM] -- Internal token number corresponding to
945 static const yytype_uint16 yytoknum
[] =
947 0, 256, 257, 258, 259, 260, 261, 262, 263, 264,
948 265, 266, 267, 268, 269, 270, 271, 272, 273, 274,
949 275, 276, 277, 278, 279, 280, 281, 282, 283, 284,
950 285, 286, 287, 288, 289, 290, 291, 292, 293, 294,
951 295, 296, 297, 298, 299, 300, 301, 302, 303, 38,
952 59, 10, 304, 124, 62, 60, 45, 123, 125, 40,
957 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
958 static const yytype_uint8 yyr1
[] =
960 0, 61, 62, 62, 62, 62, 63, 63, 64, 64,
961 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
962 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
963 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
964 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
965 64, 64, 65, 65, 65, 66, 66, 67, 67, 68,
966 68, 68, 68, 68, 69, 69, 69, 69, 69, 69,
967 69, 69, 69, 69, 69, 70, 70, 70, 70, 70,
968 70, 70, 70, 71, 71, 71, 71, 72, 72, 72,
969 72, 72, 72, 73, 73, 73, 74, 74, 74, 75,
970 75, 76, 77, 77, 77, 77, 77, 78, 78, 78,
971 79, 80, 81, 82, 82, 82, 83, 83, 84, 84,
972 84, 84, 85, 85, 85, 85, 85, 85, 86, 86,
973 87, 88, 88, 89, 89, 89, 90, 90, 90, 90,
974 90, 90, 91, 91, 92, 92, 92, 93, 93, 94,
975 94, 94, 95, 95, 95, 95, 95, 96, 96, 96,
976 96, 96, 97, 97, 97, 98, 98, 98
979 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
980 static const yytype_uint8 yyr2
[] =
982 0, 2, 2, 1, 2, 1, 1, 2, 2, 2,
983 3, 3, 3, 3, 2, 3, 3, 2, 3, 3,
984 2, 3, 3, 2, 3, 3, 2, 3, 3, 2,
985 3, 3, 2, 3, 3, 2, 3, 3, 2, 3,
986 3, 2, 3, 3, 2, 3, 3, 2, 3, 3,
987 2, 2, 1, 1, 1, 1, 2, 1, 2, 1,
988 1, 2, 1, 1, 1, 1, 5, 5, 1, 1,
989 1, 1, 1, 1, 1, 6, 6, 7, 7, 10,
990 10, 9, 9, 7, 7, 5, 5, 6, 6, 7,
991 7, 10, 10, 6, 7, 6, 5, 6, 4, 1,
992 2, 3, 2, 3, 3, 4, 2, 5, 7, 6,
993 3, 1, 3, 4, 6, 5, 1, 2, 4, 4,
994 5, 5, 2, 3, 2, 3, 2, 3, 1, 3,
995 2, 1, 2, 3, 3, 3, 4, 4, 4, 4,
996 4, 1, 1, 1, 1, 1, 1, 0, 2, 1,
997 2, 2, 4, 4, 3, 3, 1, 1, 2, 2,
998 2, 2, 4, 4, 1, 1, 2, 3
1001 /* YYDEFACT[STATE-NAME] -- Default rule to reduce with in state
1002 STATE-NUM when YYTABLE doesn't specify something else to do. Zero
1003 means the default is an error. */
1004 static const yytype_uint8 yydefact
[] =
1006 0, 0, 147, 0, 0, 0, 147, 147, 0, 0,
1007 0, 0, 165, 52, 53, 0, 0, 111, 0, 0,
1008 0, 0, 0, 0, 0, 0, 0, 0, 3, 5,
1009 0, 0, 147, 147, 0, 54, 57, 59, 164, 60,
1010 64, 74, 68, 65, 62, 70, 63, 69, 71, 72,
1011 73, 0, 149, 156, 157, 0, 4, 131, 0, 0,
1012 147, 147, 0, 147, 0, 0, 147, 52, 106, 102,
1013 0, 145, 144, 146, 161, 158, 166, 0, 0, 0,
1014 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1015 0, 0, 0, 0, 0, 0, 0, 0, 14, 23,
1016 38, 32, 47, 29, 41, 35, 44, 26, 50, 51,
1017 20, 17, 8, 9, 0, 0, 1, 52, 58, 55,
1018 61, 142, 143, 2, 147, 147, 150, 151, 147, 147,
1019 160, 159, 147, 148, 130, 132, 141, 0, 147, 0,
1020 147, 147, 147, 147, 0, 147, 147, 0, 0, 104,
1021 103, 112, 167, 147, 16, 25, 40, 34, 49, 31,
1022 43, 37, 46, 28, 22, 19, 12, 13, 15, 24,
1023 39, 33, 48, 30, 42, 36, 45, 27, 21, 18,
1024 10, 11, 110, 101, 56, 0, 0, 154, 155, 0,
1025 0, 0, 147, 147, 147, 147, 147, 147, 0, 147,
1026 0, 147, 0, 0, 0, 0, 147, 0, 147, 0,
1027 0, 147, 99, 98, 105, 0, 152, 153, 0, 0,
1028 163, 162, 147, 147, 107, 0, 0, 0, 134, 135,
1029 133, 0, 116, 147, 0, 147, 147, 0, 6, 0,
1030 147, 0, 85, 86, 147, 147, 147, 147, 0, 0,
1031 0, 0, 66, 67, 0, 100, 96, 0, 0, 109,
1032 136, 137, 138, 139, 140, 95, 122, 124, 126, 117,
1033 0, 93, 128, 0, 0, 0, 0, 75, 7, 147,
1034 0, 76, 0, 0, 0, 0, 87, 0, 147, 88,
1035 97, 108, 147, 147, 147, 147, 123, 125, 127, 94,
1036 0, 0, 147, 77, 78, 0, 147, 147, 83, 84,
1037 89, 90, 0, 113, 0, 0, 0, 147, 129, 118,
1038 119, 147, 147, 0, 0, 147, 147, 147, 115, 120,
1039 121, 0, 0, 81, 82, 0, 0, 114, 79, 80,
1043 /* YYDEFGOTO[NTERM-NUM]. */
1044 static const yytype_int16 yydefgoto
[] =
1046 -1, 34, 239, 35, 36, 120, 37, 38, 39, 40,
1047 41, 42, 43, 44, 213, 45, 46, 47, 48, 49,
1048 50, 225, 231, 232, 233, 274, 57, 58, 134, 135,
1049 123, 74, 59, 51, 187, 136, 54, 55
1052 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
1054 #define YYPACT_NINF -208
1055 static const yytype_int16 yypact
[] =
1057 296, -35, -208, -2, 38, 10, -208, -208, 24, 546,
1058 31, 346, 51, 47, -208, 591, 604, -208, 56, 71,
1059 -18, 112, 130, 115, 128, 136, 143, 154, -208, -208,
1060 157, 170, -208, -208, 111, -208, -208, 229, -208, 578,
1061 -208, -208, -208, -208, -208, -208, -208, -208, -208, -208,
1062 -208, -12, -3, -208, 48, 346, -208, -208, 208, 396,
1063 -208, 73, 15, 163, 190, 201, 160, 107, 229, 578,
1064 204, -208, -208, -208, -208, -208, 195, 165, 202, 215,
1065 152, 216, 153, 222, 227, 236, 237, 244, 245, 253,
1066 158, 254, 171, 255, 256, 259, 261, 262, -208, -208,
1067 -208, -208, -208, -208, -208, -208, -208, -208, -208, -208,
1068 -208, -208, -208, -208, 231, 230, -208, -208, -208, -208,
1069 578, -208, -208, -208, -208, -208, 446, 446, -208, -208,
1070 -208, -208, -208, -208, -208, 210, -208, 4, -208, 65,
1071 -208, -208, -208, -208, 70, -208, -208, 232, 41, 578,
1072 578, -208, -208, -208, -208, -208, -208, -208, -208, -208,
1073 -208, -208, -208, -208, -208, -208, -208, -208, -208, -208,
1074 -208, -208, -208, -208, -208, -208, -208, -208, -208, -208,
1075 -208, -208, -208, -208, -208, 396, 396, 23, 23, 496,
1076 496, 97, -208, -208, -208, -208, -208, -208, 85, -208,
1077 185, -208, 276, 235, 100, 110, -208, 268, -208, 280,
1078 283, -208, 578, -208, 578, 41, -208, -208, 446, 446,
1079 48, 48, -208, -208, -208, 295, 396, 396, 396, 396,
1080 396, 294, 161, -208, 19, -208, -208, 290, -208, 200,
1081 -208, 252, -208, -208, -208, -208, -208, -208, 302, 396,
1082 200, 269, -208, -208, 41, 578, -208, 313, 324, -208,
1083 -208, -208, 55, 55, 55, -208, -208, -208, -208, 192,
1084 34, -208, -208, 303, -19, 315, 278, -208, -208, -208,
1085 114, -208, 322, 286, 323, 287, -208, 210, -208, -208,
1086 -208, -208, -208, -208, -208, -208, -208, -208, -208, -208,
1087 8, 320, -208, -208, -208, 117, -208, -208, -208, -208,
1088 -208, -208, 119, 167, 396, 396, 396, -208, -208, -208,
1089 396, -208, -208, 337, 307, -208, -208, -208, -208, -208,
1090 396, 345, 308, -208, -208, 352, 312, -208, -208, -208,
1094 /* YYPGOTO[NTERM-NUM]. */
1095 static const yytype_int16 yypgoto
[] =
1097 -208, -208, 164, -37, -31, -62, 368, -208, -5, -208,
1098 -208, -208, -208, -208, -206, -208, -208, -208, -208, -208,
1099 -208, 66, -208, 145, -208, 88, -173, -6, -208, -207,
1100 -208, -45, -48, -208, 5, 3, 17, -208
1103 /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
1104 positive, shift that token. If negative, reduce the rule which
1105 number is the opposite. If zero, do what YYDEFACT says.
1106 If YYTABLE_NINF, syntax error. */
1107 #define YYTABLE_NINF -1
1108 static const yytype_uint16 yytable
[] =
1110 64, 65, 119, 53, 69, 52, 118, 150, 100, 256,
1111 130, 101, 137, 139, 75, 144, 56, 142, 148, 260,
1112 261, 262, 263, 264, 60, 197, 114, 115, 271, 140,
1113 124, 125, 119, 248, 301, 251, 63, 118, 102, 121,
1114 122, 302, 287, 299, 2, 272, 126, 127, 290, 3,
1115 66, 4, 5, 6, 7, 133, 124, 125, 131, 10,
1116 272, 301, 149, 70, 61, 71, 72, 73, 317, 62,
1117 133, 17, 141, 284, 285, 76, 185, 186, 273, 199,
1118 189, 190, 98, 184, 206, 133, 200, 214, 192, 193,
1119 198, 207, 133, 273, 204, 205, 128, 99, 32, 235,
1120 33, 129, 222, 223, 224, 215, 77, 262, 263, 264,
1121 2, 116, 119, 184, 244, 3, 133, 4, 5, 6,
1122 7, 133, 201, 138, 246, 10, 191, 208, 306, 53,
1123 53, 321, 188, 325, 202, 203, 133, 17, 103, 209,
1124 210, 107, 236, 212, 226, 227, 228, 229, 230, 234,
1125 255, 133, 335, 336, 108, 240, 104, 245, 249, 105,
1126 249, 133, 109, 254, 32, 133, 33, 247, 133, 110,
1127 133, 307, 327, 223, 322, 119, 326, 184, 156, 160,
1128 111, 157, 161, 112, 170, 270, 106, 171, 53, 53,
1129 216, 217, 280, 237, 279, 241, 113, 174, 249, 249,
1130 175, 266, 267, 268, 145, 288, 220, 221, 158, 162,
1131 212, 238, 132, 143, 172, 146, 257, 258, 184, 147,
1132 152, 53, 53, 151, 188, 153, 278, 176, 154, 275,
1133 276, 305, 296, 297, 298, 71, 72, 73, 282, 283,
1134 312, 155, 159, 192, 193, 314, 315, 316, 163, 212,
1135 71, 72, 73, 164, 320, 117, 14, 15, 16, 194,
1136 195, 196, 165, 166, 18, 19, 20, 21, 22, 330,
1137 167, 168, 23, 24, 25, 26, 27, 249, 249, 169,
1138 173, 177, 178, 30, 31, 179, 313, 180, 181, 182,
1139 183, 242, 211, 243, 238, 252, 319, 1, 253, 2,
1140 323, 324, 259, 265, 3, 277, 4, 5, 6, 7,
1141 281, 329, 8, 9, 10, 331, 332, 286, 11, 12,
1142 291, 337, 13, 14, 15, 16, 17, 289, 292, 272,
1143 303, 18, 19, 20, 21, 22, 304, 308, 310, 23,
1144 24, 25, 26, 27, 309, 311, 318, 28, 29, 2,
1145 30, 31, 333, 32, 3, 33, 4, 5, 6, 7,
1146 338, 300, 8, 9, 10, 334, 339, 340, 11, 12,
1147 341, 250, 13, 14, 15, 16, 17, 68, 269, 328,
1148 0, 18, 19, 20, 21, 22, 0, 0, 0, 23,
1149 24, 25, 26, 27, 0, 0, 71, 72, 73, 2,
1150 30, 31, 0, 32, 3, 33, 4, 5, 6, 7,
1151 0, 0, 8, 9, 10, 0, 0, 0, 11, 12,
1152 0, 0, 13, 14, 15, 16, 17, 0, 0, 0,
1153 0, 18, 19, 20, 21, 22, 0, 0, 0, 23,
1154 24, 25, 26, 27, 0, 0, 0, 133, 0, 2,
1155 30, 31, 0, 32, 3, 33, 4, 5, 6, 7,
1156 0, 0, 8, 9, 10, 0, 0, 0, 11, 12,
1157 0, 0, 13, 14, 15, 16, 17, 0, 0, 0,
1158 0, 18, 19, 20, 21, 22, 0, 0, 0, 23,
1159 24, 25, 26, 27, 0, 0, 0, 0, 0, 2,
1160 30, 31, 0, 32, 3, 33, 4, 5, 6, 7,
1161 0, 0, 8, 9, 10, 0, 0, 0, 0, 0,
1162 0, 0, 13, 14, 15, 16, 17, 0, 0, 0,
1163 0, 18, 19, 20, 21, 22, 0, 0, 0, 23,
1164 24, 25, 26, 27, 0, 0, 0, 133, 0, 2,
1165 30, 31, 0, 32, 3, 33, 4, 5, 6, 7,
1166 0, 0, 0, 0, 10, 0, 0, 0, 0, 0,
1167 0, 0, 67, 14, 15, 16, 17, 0, 0, 0,
1168 0, 18, 19, 20, 21, 22, 0, 0, 0, 23,
1169 24, 25, 26, 27, 0, 0, 0, 0, 0, 0,
1170 30, 31, 0, 32, 0, 33, 15, 16, 0, 0,
1171 0, 0, 0, 18, 19, 20, 21, 22, 0, 0,
1172 0, 23, 24, 25, 26, 27, 78, 79, 80, 81,
1173 82, 0, 30, 31, 83, 0, 0, 84, 85, 88,
1174 89, 90, 91, 92, 0, 86, 87, 93, 0, 0,
1175 94, 95, 0, 0, 0, 0, 0, 0, 96, 97
1178 static const yytype_int16 yycheck
[] =
1180 6, 7, 39, 0, 9, 0, 37, 69, 26, 215,
1181 55, 29, 60, 61, 11, 63, 51, 62, 66, 226,
1182 227, 228, 229, 230, 26, 21, 32, 33, 9, 14,
1183 33, 34, 69, 206, 53, 208, 26, 68, 56, 51,
1184 52, 60, 249, 9, 3, 26, 49, 50, 254, 8,
1185 26, 10, 11, 12, 13, 51, 33, 34, 55, 18,
1186 26, 53, 67, 32, 26, 50, 51, 52, 60, 31,
1187 51, 30, 57, 246, 247, 24, 124, 125, 59, 14,
1188 128, 129, 26, 120, 14, 51, 21, 149, 33, 34,
1189 138, 21, 51, 59, 142, 143, 48, 26, 57, 14,
1190 59, 53, 5, 6, 7, 153, 59, 314, 315, 316,
1191 3, 0, 149, 150, 14, 8, 51, 10, 11, 12,
1192 13, 51, 57, 50, 14, 18, 132, 57, 14, 126,
1193 127, 14, 127, 14, 140, 141, 51, 30, 26, 145,
1194 146, 26, 57, 148, 192, 193, 194, 195, 196, 197,
1195 212, 51, 325, 326, 26, 200, 26, 57, 206, 29,
1196 208, 51, 26, 211, 57, 51, 59, 57, 51, 26,
1197 51, 57, 5, 6, 57, 212, 57, 214, 26, 26,
1198 26, 29, 29, 26, 26, 233, 56, 29, 185, 186,
1199 185, 186, 240, 199, 239, 201, 26, 26, 246, 247,
1200 29, 40, 41, 42, 14, 250, 189, 190, 56, 56,
1201 215, 26, 4, 50, 56, 14, 222, 223, 255, 59,
1202 25, 218, 219, 19, 219, 60, 26, 56, 26, 235,
1203 236, 279, 40, 41, 42, 50, 51, 52, 244, 245,
1204 288, 26, 26, 33, 34, 293, 294, 295, 26, 254,
1205 50, 51, 52, 26, 302, 26, 27, 28, 29, 49,
1206 50, 51, 26, 26, 35, 36, 37, 38, 39, 317,
1207 26, 26, 43, 44, 45, 46, 47, 325, 326, 26,
1208 26, 26, 26, 54, 55, 26, 292, 26, 26, 58,
1209 60, 15, 60, 58, 26, 15, 302, 1, 15, 3,
1210 306, 307, 7, 9, 8, 15, 10, 11, 12, 13,
1211 58, 317, 16, 17, 18, 321, 322, 15, 22, 23,
1212 7, 327, 26, 27, 28, 29, 30, 58, 4, 26,
1213 15, 35, 36, 37, 38, 39, 58, 15, 15, 43,
1214 44, 45, 46, 47, 58, 58, 26, 51, 52, 3,
1215 54, 55, 15, 57, 8, 59, 10, 11, 12, 13,
1216 15, 273, 16, 17, 18, 58, 58, 15, 22, 23,
1217 58, 207, 26, 27, 28, 29, 30, 9, 233, 313,
1218 -1, 35, 36, 37, 38, 39, -1, -1, -1, 43,
1219 44, 45, 46, 47, -1, -1, 50, 51, 52, 3,
1220 54, 55, -1, 57, 8, 59, 10, 11, 12, 13,
1221 -1, -1, 16, 17, 18, -1, -1, -1, 22, 23,
1222 -1, -1, 26, 27, 28, 29, 30, -1, -1, -1,
1223 -1, 35, 36, 37, 38, 39, -1, -1, -1, 43,
1224 44, 45, 46, 47, -1, -1, -1, 51, -1, 3,
1225 54, 55, -1, 57, 8, 59, 10, 11, 12, 13,
1226 -1, -1, 16, 17, 18, -1, -1, -1, 22, 23,
1227 -1, -1, 26, 27, 28, 29, 30, -1, -1, -1,
1228 -1, 35, 36, 37, 38, 39, -1, -1, -1, 43,
1229 44, 45, 46, 47, -1, -1, -1, -1, -1, 3,
1230 54, 55, -1, 57, 8, 59, 10, 11, 12, 13,
1231 -1, -1, 16, 17, 18, -1, -1, -1, -1, -1,
1232 -1, -1, 26, 27, 28, 29, 30, -1, -1, -1,
1233 -1, 35, 36, 37, 38, 39, -1, -1, -1, 43,
1234 44, 45, 46, 47, -1, -1, -1, 51, -1, 3,
1235 54, 55, -1, 57, 8, 59, 10, 11, 12, 13,
1236 -1, -1, -1, -1, 18, -1, -1, -1, -1, -1,
1237 -1, -1, 26, 27, 28, 29, 30, -1, -1, -1,
1238 -1, 35, 36, 37, 38, 39, -1, -1, -1, 43,
1239 44, 45, 46, 47, -1, -1, -1, -1, -1, -1,
1240 54, 55, -1, 57, -1, 59, 28, 29, -1, -1,
1241 -1, -1, -1, 35, 36, 37, 38, 39, -1, -1,
1242 -1, 43, 44, 45, 46, 47, 35, 36, 37, 38,
1243 39, -1, 54, 55, 43, -1, -1, 46, 47, 35,
1244 36, 37, 38, 39, -1, 54, 55, 43, -1, -1,
1245 46, 47, -1, -1, -1, -1, -1, -1, 54, 55
1248 /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
1249 symbol of state STATE-NUM. */
1250 static const yytype_uint8 yystos
[] =
1252 0, 1, 3, 8, 10, 11, 12, 13, 16, 17,
1253 18, 22, 23, 26, 27, 28, 29, 30, 35, 36,
1254 37, 38, 39, 43, 44, 45, 46, 47, 51, 52,
1255 54, 55, 57, 59, 62, 64, 65, 67, 68, 69,
1256 70, 71, 72, 73, 74, 76, 77, 78, 79, 80,
1257 81, 94, 95, 96, 97, 98, 51, 87, 88, 93,
1258 26, 26, 31, 26, 88, 88, 26, 26, 67, 69,
1259 32, 50, 51, 52, 92, 96, 24, 59, 35, 36,
1260 37, 38, 39, 43, 46, 47, 54, 55, 35, 36,
1261 37, 38, 39, 43, 46, 47, 54, 55, 26, 26,
1262 26, 29, 56, 26, 26, 29, 56, 26, 26, 26,
1263 26, 26, 26, 26, 88, 88, 0, 26, 65, 64,
1264 66, 51, 52, 91, 33, 34, 49, 50, 48, 53,
1265 92, 96, 4, 51, 89, 90, 96, 93, 50, 93,
1266 14, 57, 92, 50, 93, 14, 14, 59, 93, 69,
1267 66, 19, 25, 60, 26, 26, 26, 29, 56, 26,
1268 26, 29, 56, 26, 26, 26, 26, 26, 26, 26,
1269 26, 29, 56, 26, 26, 29, 56, 26, 26, 26,
1270 26, 26, 58, 60, 64, 93, 93, 95, 95, 93,
1271 93, 88, 33, 34, 49, 50, 51, 21, 93, 14,
1272 21, 57, 88, 88, 93, 93, 14, 21, 57, 88,
1273 88, 60, 69, 75, 66, 93, 95, 95, 49, 50,
1274 97, 97, 5, 6, 7, 82, 93, 93, 93, 93,
1275 93, 83, 84, 85, 93, 14, 57, 88, 26, 63,
1276 92, 88, 15, 58, 14, 57, 14, 57, 87, 93,
1277 63, 87, 15, 15, 93, 66, 75, 88, 88, 7,
1278 90, 90, 90, 90, 90, 9, 40, 41, 42, 84,
1279 93, 9, 26, 59, 86, 88, 88, 15, 26, 92,
1280 93, 58, 88, 88, 87, 87, 15, 90, 92, 58,
1281 75, 7, 4, 49, 50, 51, 40, 41, 42, 9,
1282 86, 53, 60, 15, 58, 93, 14, 57, 15, 58,
1283 15, 58, 93, 88, 93, 93, 93, 60, 26, 88,
1284 93, 14, 57, 88, 88, 14, 57, 5, 82, 88,
1285 93, 88, 88, 15, 58, 87, 87, 88, 15, 58,
1289 #define yyerrok (yyerrstatus = 0)
1290 #define yyclearin (yychar = YYEMPTY)
1291 #define YYEMPTY (-2)
1294 #define YYACCEPT goto yyacceptlab
1295 #define YYABORT goto yyabortlab
1296 #define YYERROR goto yyerrorlab
1299 /* Like YYERROR except do call yyerror. This remains here temporarily
1300 to ease the transition to the new meaning of YYERROR, for GCC.
1301 Once GCC version 2 has supplanted version 1, this can go. */
1303 #define YYFAIL goto yyerrlab
1305 #define YYRECOVERING() (!!yyerrstatus)
1307 #define YYBACKUP(Token, Value) \
1309 if (yychar == YYEMPTY && yylen == 1) \
1313 yytoken = YYTRANSLATE (yychar); \
1319 yyerror (YY_("syntax error: cannot back up")); \
1326 #define YYERRCODE 256
1329 /* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
1330 If N is 0, then set CURRENT to the empty location which ends
1331 the previous symbol: RHS[0] (always defined). */
1333 #define YYRHSLOC(Rhs, K) ((Rhs)[K])
1334 #ifndef YYLLOC_DEFAULT
1335 # define YYLLOC_DEFAULT(Current, Rhs, N) \
1339 (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \
1340 (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \
1341 (Current).last_line = YYRHSLOC (Rhs, N).last_line; \
1342 (Current).last_column = YYRHSLOC (Rhs, N).last_column; \
1346 (Current).first_line = (Current).last_line = \
1347 YYRHSLOC (Rhs, 0).last_line; \
1348 (Current).first_column = (Current).last_column = \
1349 YYRHSLOC (Rhs, 0).last_column; \
1355 /* YY_LOCATION_PRINT -- Print the location on the stream.
1356 This macro was not mandated originally: define only if we know
1357 we won't break user code: when these are the locations we know. */
1359 #ifndef YY_LOCATION_PRINT
1360 # if defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL
1361 # define YY_LOCATION_PRINT(File, Loc) \
1362 fprintf (File, "%d.%d-%d.%d", \
1363 (Loc).first_line, (Loc).first_column, \
1364 (Loc).last_line, (Loc).last_column)
1366 # define YY_LOCATION_PRINT(File, Loc) ((void) 0)
1371 /* YYLEX -- calling `yylex' with the right arguments. */
1374 # define YYLEX yylex (YYLEX_PARAM)
1376 # define YYLEX yylex ()
1379 /* Enable debugging if requested. */
1383 # include <stdio.h> /* INFRINGES ON USER NAME SPACE */
1384 # define YYFPRINTF fprintf
1387 # define YYDPRINTF(Args) \
1393 # define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
1397 YYFPRINTF (stderr, "%s ", Title); \
1398 yy_symbol_print (stderr, \
1400 YYFPRINTF (stderr, "\n"); \
1405 /*--------------------------------.
1406 | Print this symbol on YYOUTPUT. |
1407 `--------------------------------*/
1410 #if (defined __STDC__ || defined __C99__FUNC__ \
1411 || defined __cplusplus || defined _MSC_VER)
1413 yy_symbol_value_print (FILE *yyoutput
, int yytype
, YYSTYPE
const * const yyvaluep
)
1416 yy_symbol_value_print (yyoutput
, yytype
, yyvaluep
)
1419 YYSTYPE
const * const yyvaluep
;
1425 if (yytype
< YYNTOKENS
)
1426 YYPRINT (yyoutput
, yytoknum
[yytype
], *yyvaluep
);
1438 /*--------------------------------.
1439 | Print this symbol on YYOUTPUT. |
1440 `--------------------------------*/
1442 #if (defined __STDC__ || defined __C99__FUNC__ \
1443 || defined __cplusplus || defined _MSC_VER)
1445 yy_symbol_print (FILE *yyoutput
, int yytype
, YYSTYPE
const * const yyvaluep
)
1448 yy_symbol_print (yyoutput
, yytype
, yyvaluep
)
1451 YYSTYPE
const * const yyvaluep
;
1454 if (yytype
< YYNTOKENS
)
1455 YYFPRINTF (yyoutput
, "token %s (", yytname
[yytype
]);
1457 YYFPRINTF (yyoutput
, "nterm %s (", yytname
[yytype
]);
1459 yy_symbol_value_print (yyoutput
, yytype
, yyvaluep
);
1460 YYFPRINTF (yyoutput
, ")");
1463 /*------------------------------------------------------------------.
1464 | yy_stack_print -- Print the state stack from its BOTTOM up to its |
1466 `------------------------------------------------------------------*/
1468 #if (defined __STDC__ || defined __C99__FUNC__ \
1469 || defined __cplusplus || defined _MSC_VER)
1471 yy_stack_print (yytype_int16
*bottom
, yytype_int16
*top
)
1474 yy_stack_print (bottom
, top
)
1475 yytype_int16
*bottom
;
1479 YYFPRINTF (stderr
, "Stack now");
1480 for (; bottom
<= top
; ++bottom
)
1481 YYFPRINTF (stderr
, " %d", *bottom
);
1482 YYFPRINTF (stderr
, "\n");
1485 # define YY_STACK_PRINT(Bottom, Top) \
1488 yy_stack_print ((Bottom), (Top)); \
1492 /*------------------------------------------------.
1493 | Report that the YYRULE is going to be reduced. |
1494 `------------------------------------------------*/
1496 #if (defined __STDC__ || defined __C99__FUNC__ \
1497 || defined __cplusplus || defined _MSC_VER)
1499 yy_reduce_print (YYSTYPE
*yyvsp
, int yyrule
)
1502 yy_reduce_print (yyvsp
, yyrule
)
1507 int yynrhs
= yyr2
[yyrule
];
1509 unsigned long int yylno
= yyrline
[yyrule
];
1510 YYFPRINTF (stderr
, "Reducing stack by rule %d (line %lu):\n",
1512 /* The symbols being reduced. */
1513 for (yyi
= 0; yyi
< yynrhs
; yyi
++)
1515 fprintf (stderr
, " $%d = ", yyi
+ 1);
1516 yy_symbol_print (stderr
, yyrhs
[yyprhs
[yyrule
] + yyi
],
1517 &(yyvsp
[(yyi
+ 1) - (yynrhs
)])
1519 fprintf (stderr
, "\n");
1523 # define YY_REDUCE_PRINT(Rule) \
1526 yy_reduce_print (yyvsp, Rule); \
1529 /* Nonzero means print parse trace. It is left uninitialized so that
1530 multiple parsers can coexist. */
1532 #else /* !YYDEBUG */
1533 # define YYDPRINTF(Args)
1534 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
1535 # define YY_STACK_PRINT(Bottom, Top)
1536 # define YY_REDUCE_PRINT(Rule)
1537 #endif /* !YYDEBUG */
1540 /* YYINITDEPTH -- initial size of the parser's stacks. */
1542 # define YYINITDEPTH 200
1545 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
1546 if the built-in stack extension method is used).
1548 Do not make this value too large; the results are undefined if
1549 YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH)
1550 evaluated with infinite-precision integer arithmetic. */
1553 # define YYMAXDEPTH 10000
1561 # if defined __GLIBC__ && defined _STRING_H
1562 # define yystrlen strlen
1564 /* Return the length of YYSTR. */
1565 #if (defined __STDC__ || defined __C99__FUNC__ \
1566 || defined __cplusplus || defined _MSC_VER)
1568 yystrlen (const char *yystr
)
1576 for (yylen
= 0; yystr
[yylen
]; yylen
++)
1584 # if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
1585 # define yystpcpy stpcpy
1587 /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
1589 #if (defined __STDC__ || defined __C99__FUNC__ \
1590 || defined __cplusplus || defined _MSC_VER)
1592 yystpcpy (char *yydest
, const char *yysrc
)
1595 yystpcpy (yydest
, yysrc
)
1601 const char *yys
= yysrc
;
1603 while ((*yyd
++ = *yys
++) != '\0')
1612 /* Copy to YYRES the contents of YYSTR after stripping away unnecessary
1613 quotes and backslashes, so that it's suitable for yyerror. The
1614 heuristic is that double-quoting is unnecessary unless the string
1615 contains an apostrophe, a comma, or backslash (other than
1616 backslash-backslash). YYSTR is taken from yytname. If YYRES is
1617 null, do not copy; instead, return the length of what the result
1620 yytnamerr (char *yyres
, const char *yystr
)
1625 char const *yyp
= yystr
;
1632 goto do_not_strip_quotes
;
1636 goto do_not_strip_quotes
;
1649 do_not_strip_quotes
: ;
1653 return yystrlen (yystr
);
1655 return yystpcpy (yyres
, yystr
) - yyres
;
1659 /* Copy into YYRESULT an error message about the unexpected token
1660 YYCHAR while in state YYSTATE. Return the number of bytes copied,
1661 including the terminating null byte. If YYRESULT is null, do not
1662 copy anything; just return the number of bytes that would be
1663 copied. As a special case, return 0 if an ordinary "syntax error"
1664 message will do. Return YYSIZE_MAXIMUM if overflow occurs during
1665 size calculation. */
1667 yysyntax_error (char *yyresult
, int yystate
, int yychar
)
1669 int yyn
= yypact
[yystate
];
1671 if (! (YYPACT_NINF
< yyn
&& yyn
<= YYLAST
))
1675 int yytype
= YYTRANSLATE (yychar
);
1676 YYSIZE_T yysize0
= yytnamerr (0, yytname
[yytype
]);
1677 YYSIZE_T yysize
= yysize0
;
1679 int yysize_overflow
= 0;
1680 enum { YYERROR_VERBOSE_ARGS_MAXIMUM
= 5 };
1681 char const *yyarg
[YYERROR_VERBOSE_ARGS_MAXIMUM
];
1685 /* This is so xgettext sees the translatable formats that are
1686 constructed on the fly. */
1687 YY_("syntax error, unexpected %s");
1688 YY_("syntax error, unexpected %s, expecting %s");
1689 YY_("syntax error, unexpected %s, expecting %s or %s");
1690 YY_("syntax error, unexpected %s, expecting %s or %s or %s");
1691 YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s");
1695 static char const yyunexpected
[] = "syntax error, unexpected %s";
1696 static char const yyexpecting
[] = ", expecting %s";
1697 static char const yyor
[] = " or %s";
1698 char yyformat
[sizeof yyunexpected
1699 + sizeof yyexpecting
- 1
1700 + ((YYERROR_VERBOSE_ARGS_MAXIMUM
- 2)
1701 * (sizeof yyor
- 1))];
1702 char const *yyprefix
= yyexpecting
;
1704 /* Start YYX at -YYN if negative to avoid negative indexes in
1706 int yyxbegin
= yyn
< 0 ? -yyn
: 0;
1708 /* Stay within bounds of both yycheck and yytname. */
1709 int yychecklim
= YYLAST
- yyn
+ 1;
1710 int yyxend
= yychecklim
< YYNTOKENS
? yychecklim
: YYNTOKENS
;
1713 yyarg
[0] = yytname
[yytype
];
1714 yyfmt
= yystpcpy (yyformat
, yyunexpected
);
1716 for (yyx
= yyxbegin
; yyx
< yyxend
; ++yyx
)
1717 if (yycheck
[yyx
+ yyn
] == yyx
&& yyx
!= YYTERROR
)
1719 if (yycount
== YYERROR_VERBOSE_ARGS_MAXIMUM
)
1723 yyformat
[sizeof yyunexpected
- 1] = '\0';
1726 yyarg
[yycount
++] = yytname
[yyx
];
1727 yysize1
= yysize
+ yytnamerr (0, yytname
[yyx
]);
1728 yysize_overflow
|= (yysize1
< yysize
);
1730 yyfmt
= yystpcpy (yyfmt
, yyprefix
);
1734 yyf
= YY_(yyformat
);
1735 yysize1
= yysize
+ yystrlen (yyf
);
1736 yysize_overflow
|= (yysize1
< yysize
);
1739 if (yysize_overflow
)
1740 return YYSIZE_MAXIMUM
;
1744 /* Avoid sprintf, as that infringes on the user's name space.
1745 Don't have undefined behavior even if the translation
1746 produced a string with the wrong number of "%s"s. */
1747 char *yyp
= yyresult
;
1749 while ((*yyp
= *yyf
) != '\0')
1751 if (*yyp
== '%' && yyf
[1] == 's' && yyi
< yycount
)
1753 yyp
+= yytnamerr (yyp
, yyarg
[yyi
++]);
1766 #endif /* YYERROR_VERBOSE */
1769 /*-----------------------------------------------.
1770 | Release the memory associated to this symbol. |
1771 `-----------------------------------------------*/
1774 #if (defined __STDC__ || defined __C99__FUNC__ \
1775 || defined __cplusplus || defined _MSC_VER)
1777 yydestruct (const char *yymsg
, int yytype
, YYSTYPE
*yyvaluep
)
1780 yydestruct (yymsg
, yytype
, yyvaluep
)
1790 YY_SYMBOL_PRINT (yymsg
, yytype
, yyvaluep
, yylocationp
);
1801 /* Prevent warnings from -Wmissing-prototypes. */
1803 #ifdef YYPARSE_PARAM
1804 #if defined __STDC__ || defined __cplusplus
1805 int yyparse (void *YYPARSE_PARAM
);
1809 #else /* ! YYPARSE_PARAM */
1810 #if defined __STDC__ || defined __cplusplus
1815 #endif /* ! YYPARSE_PARAM */
1819 /* The look-ahead symbol. */
1822 /* The semantic value of the look-ahead symbol. */
1825 /* Number of syntax errors so far. */
1834 #ifdef YYPARSE_PARAM
1835 #if (defined __STDC__ || defined __C99__FUNC__ \
1836 || defined __cplusplus || defined _MSC_VER)
1838 yyparse (void *YYPARSE_PARAM
)
1841 yyparse (YYPARSE_PARAM
)
1842 void *YYPARSE_PARAM
;
1844 #else /* ! YYPARSE_PARAM */
1845 #if (defined __STDC__ || defined __C99__FUNC__ \
1846 || defined __cplusplus || defined _MSC_VER)
1860 /* Number of tokens to shift before error messages enabled. */
1862 /* Look-ahead token as an internal (translated) token number. */
1865 /* Buffer for error messages, and its allocated size. */
1867 char *yymsg
= yymsgbuf
;
1868 YYSIZE_T yymsg_alloc
= sizeof yymsgbuf
;
1871 /* Three stacks and their tools:
1872 `yyss': related to states,
1873 `yyvs': related to semantic values,
1874 `yyls': related to locations.
1876 Refer to the stacks thru separate pointers, to allow yyoverflow
1877 to reallocate them elsewhere. */
1879 /* The state stack. */
1880 yytype_int16 yyssa
[YYINITDEPTH
];
1881 yytype_int16
*yyss
= yyssa
;
1882 yytype_int16
*yyssp
;
1884 /* The semantic value stack. */
1885 YYSTYPE yyvsa
[YYINITDEPTH
];
1886 YYSTYPE
*yyvs
= yyvsa
;
1891 #define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N))
1893 YYSIZE_T yystacksize
= YYINITDEPTH
;
1895 /* The variables used to return semantic value and location from the
1900 /* The number of symbols on the RHS of the reduced rule.
1901 Keep to zero when no symbol should be popped. */
1904 YYDPRINTF ((stderr
, "Starting parse\n"));
1909 yychar
= YYEMPTY
; /* Cause a token to be read. */
1911 /* Initialize stack pointers.
1912 Waste one element of value and location stack
1913 so that they stay on the same level as the state stack.
1914 The wasted elements are never initialized. */
1921 /*------------------------------------------------------------.
1922 | yynewstate -- Push a new state, which is found in yystate. |
1923 `------------------------------------------------------------*/
1925 /* In all cases, when you get here, the value and location stacks
1926 have just been pushed. So pushing a state here evens the stacks. */
1932 if (yyss
+ yystacksize
- 1 <= yyssp
)
1934 /* Get the current used size of the three stacks, in elements. */
1935 YYSIZE_T yysize
= yyssp
- yyss
+ 1;
1939 /* Give user a chance to reallocate the stack. Use copies of
1940 these so that the &'s don't force the real ones into
1942 YYSTYPE
*yyvs1
= yyvs
;
1943 yytype_int16
*yyss1
= yyss
;
1946 /* Each stack pointer address is followed by the size of the
1947 data in use in that stack, in bytes. This used to be a
1948 conditional around just the two extra args, but that might
1949 be undefined if yyoverflow is a macro. */
1950 yyoverflow (YY_("memory exhausted"),
1951 &yyss1
, yysize
* sizeof (*yyssp
),
1952 &yyvs1
, yysize
* sizeof (*yyvsp
),
1959 #else /* no yyoverflow */
1960 # ifndef YYSTACK_RELOCATE
1961 goto yyexhaustedlab
;
1963 /* Extend the stack our own way. */
1964 if (YYMAXDEPTH
<= yystacksize
)
1965 goto yyexhaustedlab
;
1967 if (YYMAXDEPTH
< yystacksize
)
1968 yystacksize
= YYMAXDEPTH
;
1971 yytype_int16
*yyss1
= yyss
;
1972 union yyalloc
*yyptr
=
1973 (union yyalloc
*) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize
));
1975 goto yyexhaustedlab
;
1976 YYSTACK_RELOCATE (yyss
);
1977 YYSTACK_RELOCATE (yyvs
);
1979 # undef YYSTACK_RELOCATE
1981 YYSTACK_FREE (yyss1
);
1984 #endif /* no yyoverflow */
1986 yyssp
= yyss
+ yysize
- 1;
1987 yyvsp
= yyvs
+ yysize
- 1;
1990 YYDPRINTF ((stderr
, "Stack size increased to %lu\n",
1991 (unsigned long int) yystacksize
));
1993 if (yyss
+ yystacksize
- 1 <= yyssp
)
1997 YYDPRINTF ((stderr
, "Entering state %d\n", yystate
));
2006 /* Do appropriate processing given the current state. Read a
2007 look-ahead token if we need one and don't already have one. */
2009 /* First try to decide what to do without reference to look-ahead token. */
2010 yyn
= yypact
[yystate
];
2011 if (yyn
== YYPACT_NINF
)
2014 /* Not known => get a look-ahead token if don't already have one. */
2016 /* YYCHAR is either YYEMPTY or YYEOF or a valid look-ahead symbol. */
2017 if (yychar
== YYEMPTY
)
2019 YYDPRINTF ((stderr
, "Reading a token: "));
2023 if (yychar
<= YYEOF
)
2025 yychar
= yytoken
= YYEOF
;
2026 YYDPRINTF ((stderr
, "Now at end of input.\n"));
2030 yytoken
= YYTRANSLATE (yychar
);
2031 YY_SYMBOL_PRINT ("Next token is", yytoken
, &yylval
, &yylloc
);
2034 /* If the proper action on seeing token YYTOKEN is to reduce or to
2035 detect an error, take that action. */
2037 if (yyn
< 0 || YYLAST
< yyn
|| yycheck
[yyn
] != yytoken
)
2042 if (yyn
== 0 || yyn
== YYTABLE_NINF
)
2051 /* Count tokens shifted since error; after three, turn off error
2056 /* Shift the look-ahead token. */
2057 YY_SYMBOL_PRINT ("Shifting", yytoken
, &yylval
, &yylloc
);
2059 /* Discard the shifted token unless it is eof. */
2060 if (yychar
!= YYEOF
)
2069 /*-----------------------------------------------------------.
2070 | yydefault -- do the default action for the current state. |
2071 `-----------------------------------------------------------*/
2073 yyn
= yydefact
[yystate
];
2079 /*-----------------------------.
2080 | yyreduce -- Do a reduction. |
2081 `-----------------------------*/
2083 /* yyn is the number of a rule to reduce with. */
2086 /* If YYLEN is nonzero, implement the default value of the action:
2089 Otherwise, the following line sets YYVAL to garbage.
2090 This behavior is undocumented and Bison
2091 users should not rely upon it. Assigning to YYVAL
2092 unconditionally makes the parser a bit smaller, and it avoids a
2093 GCC warning that YYVAL may be used uninitialized. */
2094 yyval
= yyvsp
[1-yylen
];
2097 YY_REDUCE_PRINT (yyn
);
2101 #line 383 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
2103 /* Case of regular command. Discard the error
2104 safety net,and return the command just parsed. */
2105 global_command
= (yyvsp
[(1) - (2)].command
);
2106 eof_encountered
= 0;
2107 /* discard_parser_constructs (0); */
2108 if (parser_state
& PST_CMDSUBST
)
2109 parser_state
|= PST_EOFTOKEN
;
2115 #line 394 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
2117 /* Case of regular command, but not a very
2118 interesting one. Return a NULL command. */
2119 global_command
= (COMMAND
*)NULL
;
2120 if (parser_state
& PST_CMDSUBST
)
2121 parser_state
|= PST_EOFTOKEN
;
2127 #line 403 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
2129 /* Error during parsing. Return NULL command. */
2130 global_command
= (COMMAND
*)NULL
;
2131 eof_encountered
= 0;
2132 /* discard_parser_constructs (1); */
2133 if (interactive
&& parse_and_execute_level
== 0)
2145 #line 418 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
2147 /* Case of EOF seen by itself. Do ignoreeof or
2149 global_command
= (COMMAND
*)NULL
;
2150 handle_eof_input_unit ();
2156 #line 428 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
2157 { (yyval
.word_list
) = make_word_list ((yyvsp
[(1) - (1)].word
), (WORD_LIST
*)NULL
); }
2161 #line 430 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
2162 { (yyval
.word_list
) = make_word_list ((yyvsp
[(2) - (2)].word
), (yyvsp
[(1) - (2)].word_list
)); }
2166 #line 434 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
2169 redir
.filename
= (yyvsp
[(2) - (2)].word
);
2170 (yyval
.redirect
) = make_redirection (source
, r_output_direction
, redir
, 0);
2175 #line 440 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
2178 redir
.filename
= (yyvsp
[(2) - (2)].word
);
2179 (yyval
.redirect
) = make_redirection (source
, r_input_direction
, redir
, 0);
2184 #line 446 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
2186 source
.dest
= (yyvsp
[(1) - (3)].number
);
2187 redir
.filename
= (yyvsp
[(3) - (3)].word
);
2188 (yyval
.redirect
) = make_redirection (source
, r_output_direction
, redir
, 0);
2193 #line 452 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
2195 source
.dest
= (yyvsp
[(1) - (3)].number
);
2196 redir
.filename
= (yyvsp
[(3) - (3)].word
);
2197 (yyval
.redirect
) = make_redirection (source
, r_input_direction
, redir
, 0);
2202 #line 458 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
2204 source
.filename
= (yyvsp
[(1) - (3)].word
);
2205 redir
.filename
= (yyvsp
[(3) - (3)].word
);
2206 (yyval
.redirect
) = make_redirection (source
, r_output_direction
, redir
, REDIR_VARASSIGN
);
2211 #line 464 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
2213 source
.filename
= (yyvsp
[(1) - (3)].word
);
2214 redir
.filename
= (yyvsp
[(3) - (3)].word
);
2215 (yyval
.redirect
) = make_redirection (source
, r_input_direction
, redir
, REDIR_VARASSIGN
);
2220 #line 470 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
2223 redir
.filename
= (yyvsp
[(2) - (2)].word
);
2224 (yyval
.redirect
) = make_redirection (source
, r_appending_to
, redir
, 0);
2229 #line 476 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
2231 source
.dest
= (yyvsp
[(1) - (3)].number
);
2232 redir
.filename
= (yyvsp
[(3) - (3)].word
);
2233 (yyval
.redirect
) = make_redirection (source
, r_appending_to
, redir
, 0);
2238 #line 482 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
2240 source
.filename
= (yyvsp
[(1) - (3)].word
);
2241 redir
.filename
= (yyvsp
[(3) - (3)].word
);
2242 (yyval
.redirect
) = make_redirection (source
, r_appending_to
, redir
, REDIR_VARASSIGN
);
2247 #line 488 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
2250 redir
.filename
= (yyvsp
[(2) - (2)].word
);
2251 (yyval
.redirect
) = make_redirection (source
, r_output_force
, redir
, 0);
2256 #line 494 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
2258 source
.dest
= (yyvsp
[(1) - (3)].number
);
2259 redir
.filename
= (yyvsp
[(3) - (3)].word
);
2260 (yyval
.redirect
) = make_redirection (source
, r_output_force
, redir
, 0);
2265 #line 500 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
2267 source
.filename
= (yyvsp
[(1) - (3)].word
);
2268 redir
.filename
= (yyvsp
[(3) - (3)].word
);
2269 (yyval
.redirect
) = make_redirection (source
, r_output_force
, redir
, REDIR_VARASSIGN
);
2274 #line 506 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
2277 redir
.filename
= (yyvsp
[(2) - (2)].word
);
2278 (yyval
.redirect
) = make_redirection (source
, r_input_output
, redir
, 0);
2283 #line 512 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
2285 source
.dest
= (yyvsp
[(1) - (3)].number
);
2286 redir
.filename
= (yyvsp
[(3) - (3)].word
);
2287 (yyval
.redirect
) = make_redirection (source
, r_input_output
, redir
, 0);
2292 #line 518 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
2294 source
.filename
= (yyvsp
[(1) - (3)].word
);
2295 redir
.filename
= (yyvsp
[(3) - (3)].word
);
2296 (yyval
.redirect
) = make_redirection (source
, r_input_output
, redir
, REDIR_VARASSIGN
);
2301 #line 524 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
2304 redir
.filename
= (yyvsp
[(2) - (2)].word
);
2305 (yyval
.redirect
) = make_redirection (source
, r_reading_until
, redir
, 0);
2306 push_heredoc ((yyval
.redirect
));
2311 #line 531 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
2313 source
.dest
= (yyvsp
[(1) - (3)].number
);
2314 redir
.filename
= (yyvsp
[(3) - (3)].word
);
2315 (yyval
.redirect
) = make_redirection (source
, r_reading_until
, redir
, 0);
2316 push_heredoc ((yyval
.redirect
));
2321 #line 538 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
2323 source
.filename
= (yyvsp
[(1) - (3)].word
);
2324 redir
.filename
= (yyvsp
[(3) - (3)].word
);
2325 (yyval
.redirect
) = make_redirection (source
, r_reading_until
, redir
, REDIR_VARASSIGN
);
2326 push_heredoc ((yyval
.redirect
));
2331 #line 545 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
2334 redir
.filename
= (yyvsp
[(2) - (2)].word
);
2335 (yyval
.redirect
) = make_redirection (source
, r_deblank_reading_until
, redir
, 0);
2336 push_heredoc ((yyval
.redirect
));
2341 #line 552 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
2343 source
.dest
= (yyvsp
[(1) - (3)].number
);
2344 redir
.filename
= (yyvsp
[(3) - (3)].word
);
2345 (yyval
.redirect
) = make_redirection (source
, r_deblank_reading_until
, redir
, 0);
2346 push_heredoc ((yyval
.redirect
));
2351 #line 559 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
2353 source
.filename
= (yyvsp
[(1) - (3)].word
);
2354 redir
.filename
= (yyvsp
[(3) - (3)].word
);
2355 (yyval
.redirect
) = make_redirection (source
, r_deblank_reading_until
, redir
, REDIR_VARASSIGN
);
2356 push_heredoc ((yyval
.redirect
));
2361 #line 566 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
2364 redir
.filename
= (yyvsp
[(2) - (2)].word
);
2365 (yyval
.redirect
) = make_redirection (source
, r_reading_string
, redir
, 0);
2370 #line 572 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
2372 source
.dest
= (yyvsp
[(1) - (3)].number
);
2373 redir
.filename
= (yyvsp
[(3) - (3)].word
);
2374 (yyval
.redirect
) = make_redirection (source
, r_reading_string
, redir
, 0);
2379 #line 578 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
2381 source
.filename
= (yyvsp
[(1) - (3)].word
);
2382 redir
.filename
= (yyvsp
[(3) - (3)].word
);
2383 (yyval
.redirect
) = make_redirection (source
, r_reading_string
, redir
, REDIR_VARASSIGN
);
2388 #line 584 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
2391 redir
.dest
= (yyvsp
[(2) - (2)].number
);
2392 (yyval
.redirect
) = make_redirection (source
, r_duplicating_input
, redir
, 0);
2397 #line 590 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
2399 source
.dest
= (yyvsp
[(1) - (3)].number
);
2400 redir
.dest
= (yyvsp
[(3) - (3)].number
);
2401 (yyval
.redirect
) = make_redirection (source
, r_duplicating_input
, redir
, 0);
2406 #line 596 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
2408 source
.filename
= (yyvsp
[(1) - (3)].word
);
2409 redir
.dest
= (yyvsp
[(3) - (3)].number
);
2410 (yyval
.redirect
) = make_redirection (source
, r_duplicating_input
, redir
, REDIR_VARASSIGN
);
2415 #line 602 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
2418 redir
.dest
= (yyvsp
[(2) - (2)].number
);
2419 (yyval
.redirect
) = make_redirection (source
, r_duplicating_output
, redir
, 0);
2424 #line 608 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
2426 source
.dest
= (yyvsp
[(1) - (3)].number
);
2427 redir
.dest
= (yyvsp
[(3) - (3)].number
);
2428 (yyval
.redirect
) = make_redirection (source
, r_duplicating_output
, redir
, 0);
2433 #line 614 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
2435 source
.filename
= (yyvsp
[(1) - (3)].word
);
2436 redir
.dest
= (yyvsp
[(3) - (3)].number
);
2437 (yyval
.redirect
) = make_redirection (source
, r_duplicating_output
, redir
, REDIR_VARASSIGN
);
2442 #line 620 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
2445 redir
.filename
= (yyvsp
[(2) - (2)].word
);
2446 (yyval
.redirect
) = make_redirection (source
, r_duplicating_input_word
, redir
, 0);
2451 #line 626 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
2453 source
.dest
= (yyvsp
[(1) - (3)].number
);
2454 redir
.filename
= (yyvsp
[(3) - (3)].word
);
2455 (yyval
.redirect
) = make_redirection (source
, r_duplicating_input_word
, redir
, 0);
2460 #line 632 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
2462 source
.filename
= (yyvsp
[(1) - (3)].word
);
2463 redir
.filename
= (yyvsp
[(3) - (3)].word
);
2464 (yyval
.redirect
) = make_redirection (source
, r_duplicating_input_word
, redir
, REDIR_VARASSIGN
);
2469 #line 638 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
2472 redir
.filename
= (yyvsp
[(2) - (2)].word
);
2473 (yyval
.redirect
) = make_redirection (source
, r_duplicating_output_word
, redir
, 0);
2478 #line 644 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
2480 source
.dest
= (yyvsp
[(1) - (3)].number
);
2481 redir
.filename
= (yyvsp
[(3) - (3)].word
);
2482 (yyval
.redirect
) = make_redirection (source
, r_duplicating_output_word
, redir
, 0);
2487 #line 650 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
2489 source
.filename
= (yyvsp
[(1) - (3)].word
);
2490 redir
.filename
= (yyvsp
[(3) - (3)].word
);
2491 (yyval
.redirect
) = make_redirection (source
, r_duplicating_output_word
, redir
, REDIR_VARASSIGN
);
2496 #line 656 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
2500 (yyval
.redirect
) = make_redirection (source
, r_close_this
, redir
, 0);
2505 #line 662 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
2507 source
.dest
= (yyvsp
[(1) - (3)].number
);
2509 (yyval
.redirect
) = make_redirection (source
, r_close_this
, redir
, 0);
2514 #line 668 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
2516 source
.filename
= (yyvsp
[(1) - (3)].word
);
2518 (yyval
.redirect
) = make_redirection (source
, r_close_this
, redir
, REDIR_VARASSIGN
);
2523 #line 674 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
2527 (yyval
.redirect
) = make_redirection (source
, r_close_this
, redir
, 0);
2532 #line 680 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
2534 source
.dest
= (yyvsp
[(1) - (3)].number
);
2536 (yyval
.redirect
) = make_redirection (source
, r_close_this
, redir
, 0);
2541 #line 686 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
2543 source
.filename
= (yyvsp
[(1) - (3)].word
);
2545 (yyval
.redirect
) = make_redirection (source
, r_close_this
, redir
, REDIR_VARASSIGN
);
2550 #line 692 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
2553 redir
.filename
= (yyvsp
[(2) - (2)].word
);
2554 (yyval
.redirect
) = make_redirection (source
, r_err_and_out
, redir
, 0);
2559 #line 698 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
2562 redir
.filename
= (yyvsp
[(2) - (2)].word
);
2563 (yyval
.redirect
) = make_redirection (source
, r_append_err_and_out
, redir
, 0);
2568 #line 706 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
2569 { (yyval
.element
).word
= (yyvsp
[(1) - (1)].word
); (yyval
.element
).redirect
= 0; }
2573 #line 708 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
2574 { (yyval
.element
).word
= (yyvsp
[(1) - (1)].word
); (yyval
.element
).redirect
= 0; }
2578 #line 710 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
2579 { (yyval
.element
).redirect
= (yyvsp
[(1) - (1)].redirect
); (yyval
.element
).word
= 0; }
2583 #line 714 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
2585 (yyval
.redirect
) = (yyvsp
[(1) - (1)].redirect
);
2590 #line 718 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
2592 register REDIRECT
*t
;
2594 for (t
= (yyvsp
[(1) - (2)].redirect
); t
->next
; t
= t
->next
)
2596 t
->next
= (yyvsp
[(2) - (2)].redirect
);
2597 (yyval
.redirect
) = (yyvsp
[(1) - (2)].redirect
);
2602 #line 729 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
2603 { (yyval
.command
) = make_simple_command ((yyvsp
[(1) - (1)].element
), (COMMAND
*)NULL
); }
2607 #line 731 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
2608 { (yyval
.command
) = make_simple_command ((yyvsp
[(2) - (2)].element
), (yyvsp
[(1) - (2)].command
)); }
2612 #line 735 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
2613 { (yyval
.command
) = clean_simple_command ((yyvsp
[(1) - (1)].command
)); }
2617 #line 737 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
2618 { (yyval
.command
) = (yyvsp
[(1) - (1)].command
); }
2622 #line 739 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
2626 tc
= (yyvsp
[(1) - (2)].command
);
2629 register REDIRECT
*t
;
2630 for (t
= tc
->redirects
; t
->next
; t
= t
->next
)
2632 t
->next
= (yyvsp
[(2) - (2)].redirect
);
2635 tc
->redirects
= (yyvsp
[(2) - (2)].redirect
);
2636 (yyval
.command
) = (yyvsp
[(1) - (2)].command
);
2641 #line 755 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
2642 { (yyval
.command
) = (yyvsp
[(1) - (1)].command
); }
2646 #line 757 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
2647 { (yyval
.command
) = (yyvsp
[(1) - (1)].command
); }
2651 #line 761 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
2652 { (yyval
.command
) = (yyvsp
[(1) - (1)].command
); }
2656 #line 763 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
2657 { (yyval
.command
) = (yyvsp
[(1) - (1)].command
); }
2661 #line 765 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
2662 { (yyval
.command
) = make_while_command ((yyvsp
[(2) - (5)].command
), (yyvsp
[(4) - (5)].command
)); }
2666 #line 767 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
2667 { (yyval
.command
) = make_until_command ((yyvsp
[(2) - (5)].command
), (yyvsp
[(4) - (5)].command
)); }
2671 #line 769 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
2672 { (yyval
.command
) = (yyvsp
[(1) - (1)].command
); }
2676 #line 771 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
2677 { (yyval
.command
) = (yyvsp
[(1) - (1)].command
); }
2681 #line 773 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
2682 { (yyval
.command
) = (yyvsp
[(1) - (1)].command
); }
2686 #line 775 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
2687 { (yyval
.command
) = (yyvsp
[(1) - (1)].command
); }
2691 #line 777 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
2692 { (yyval
.command
) = (yyvsp
[(1) - (1)].command
); }
2696 #line 779 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
2697 { (yyval
.command
) = (yyvsp
[(1) - (1)].command
); }
2701 #line 781 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
2702 { (yyval
.command
) = (yyvsp
[(1) - (1)].command
); }
2706 #line 785 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
2708 (yyval
.command
) = make_for_command ((yyvsp
[(2) - (6)].word
), add_string_to_list ("\"$@\"", (WORD_LIST
*)NULL
), (yyvsp
[(5) - (6)].command
), word_lineno
[word_top
]);
2709 if (word_top
> 0) word_top
--;
2714 #line 790 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
2716 (yyval
.command
) = make_for_command ((yyvsp
[(2) - (6)].word
), add_string_to_list ("\"$@\"", (WORD_LIST
*)NULL
), (yyvsp
[(5) - (6)].command
), word_lineno
[word_top
]);
2717 if (word_top
> 0) word_top
--;
2722 #line 795 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
2724 (yyval
.command
) = make_for_command ((yyvsp
[(2) - (7)].word
), add_string_to_list ("\"$@\"", (WORD_LIST
*)NULL
), (yyvsp
[(6) - (7)].command
), word_lineno
[word_top
]);
2725 if (word_top
> 0) word_top
--;
2730 #line 800 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
2732 (yyval
.command
) = make_for_command ((yyvsp
[(2) - (7)].word
), add_string_to_list ("\"$@\"", (WORD_LIST
*)NULL
), (yyvsp
[(6) - (7)].command
), word_lineno
[word_top
]);
2733 if (word_top
> 0) word_top
--;
2738 #line 805 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
2740 (yyval
.command
) = make_for_command ((yyvsp
[(2) - (10)].word
), REVERSE_LIST ((yyvsp
[(5) - (10)].word_list
), WORD_LIST
*), (yyvsp
[(9) - (10)].command
), word_lineno
[word_top
]);
2741 if (word_top
> 0) word_top
--;
2746 #line 810 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
2748 (yyval
.command
) = make_for_command ((yyvsp
[(2) - (10)].word
), REVERSE_LIST ((yyvsp
[(5) - (10)].word_list
), WORD_LIST
*), (yyvsp
[(9) - (10)].command
), word_lineno
[word_top
]);
2749 if (word_top
> 0) word_top
--;
2754 #line 815 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
2756 (yyval
.command
) = make_for_command ((yyvsp
[(2) - (9)].word
), (WORD_LIST
*)NULL
, (yyvsp
[(8) - (9)].command
), word_lineno
[word_top
]);
2757 if (word_top
> 0) word_top
--;
2762 #line 820 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
2764 (yyval
.command
) = make_for_command ((yyvsp
[(2) - (9)].word
), (WORD_LIST
*)NULL
, (yyvsp
[(8) - (9)].command
), word_lineno
[word_top
]);
2765 if (word_top
> 0) word_top
--;
2770 #line 827 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
2772 (yyval
.command
) = make_arith_for_command ((yyvsp
[(2) - (7)].word_list
), (yyvsp
[(6) - (7)].command
), arith_for_lineno
);
2773 if (word_top
> 0) word_top
--;
2778 #line 832 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
2780 (yyval
.command
) = make_arith_for_command ((yyvsp
[(2) - (7)].word_list
), (yyvsp
[(6) - (7)].command
), arith_for_lineno
);
2781 if (word_top
> 0) word_top
--;
2786 #line 837 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
2788 (yyval
.command
) = make_arith_for_command ((yyvsp
[(2) - (5)].word_list
), (yyvsp
[(4) - (5)].command
), arith_for_lineno
);
2789 if (word_top
> 0) word_top
--;
2794 #line 842 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
2796 (yyval
.command
) = make_arith_for_command ((yyvsp
[(2) - (5)].word_list
), (yyvsp
[(4) - (5)].command
), arith_for_lineno
);
2797 if (word_top
> 0) word_top
--;
2802 #line 849 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
2804 (yyval
.command
) = make_select_command ((yyvsp
[(2) - (6)].word
), add_string_to_list ("\"$@\"", (WORD_LIST
*)NULL
), (yyvsp
[(5) - (6)].command
), word_lineno
[word_top
]);
2805 if (word_top
> 0) word_top
--;
2810 #line 854 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
2812 (yyval
.command
) = make_select_command ((yyvsp
[(2) - (6)].word
), add_string_to_list ("\"$@\"", (WORD_LIST
*)NULL
), (yyvsp
[(5) - (6)].command
), word_lineno
[word_top
]);
2813 if (word_top
> 0) word_top
--;
2818 #line 859 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
2820 (yyval
.command
) = make_select_command ((yyvsp
[(2) - (7)].word
), add_string_to_list ("\"$@\"", (WORD_LIST
*)NULL
), (yyvsp
[(6) - (7)].command
), word_lineno
[word_top
]);
2821 if (word_top
> 0) word_top
--;
2826 #line 864 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
2828 (yyval
.command
) = make_select_command ((yyvsp
[(2) - (7)].word
), add_string_to_list ("\"$@\"", (WORD_LIST
*)NULL
), (yyvsp
[(6) - (7)].command
), word_lineno
[word_top
]);
2829 if (word_top
> 0) word_top
--;
2834 #line 869 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
2836 (yyval
.command
) = make_select_command ((yyvsp
[(2) - (10)].word
), REVERSE_LIST ((yyvsp
[(5) - (10)].word_list
), WORD_LIST
*), (yyvsp
[(9) - (10)].command
), word_lineno
[word_top
]);
2837 if (word_top
> 0) word_top
--;
2842 #line 874 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
2844 (yyval
.command
) = make_select_command ((yyvsp
[(2) - (10)].word
), REVERSE_LIST ((yyvsp
[(5) - (10)].word_list
), WORD_LIST
*), (yyvsp
[(9) - (10)].command
), word_lineno
[word_top
]);
2845 if (word_top
> 0) word_top
--;
2850 #line 881 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
2852 (yyval
.command
) = make_case_command ((yyvsp
[(2) - (6)].word
), (PATTERN_LIST
*)NULL
, word_lineno
[word_top
]);
2853 if (word_top
> 0) word_top
--;
2858 #line 886 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
2860 (yyval
.command
) = make_case_command ((yyvsp
[(2) - (7)].word
), (yyvsp
[(5) - (7)].pattern
), word_lineno
[word_top
]);
2861 if (word_top
> 0) word_top
--;
2866 #line 891 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
2868 (yyval
.command
) = make_case_command ((yyvsp
[(2) - (6)].word
), (yyvsp
[(5) - (6)].pattern
), word_lineno
[word_top
]);
2869 if (word_top
> 0) word_top
--;
2874 #line 898 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
2875 { (yyval
.command
) = make_function_def ((yyvsp
[(1) - (5)].word
), (yyvsp
[(5) - (5)].command
), function_dstart
, function_bstart
); }
2879 #line 901 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
2880 { (yyval
.command
) = make_function_def ((yyvsp
[(2) - (6)].word
), (yyvsp
[(6) - (6)].command
), function_dstart
, function_bstart
); }
2884 #line 904 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
2885 { (yyval
.command
) = make_function_def ((yyvsp
[(2) - (4)].word
), (yyvsp
[(4) - (4)].command
), function_dstart
, function_bstart
); }
2889 #line 908 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
2890 { (yyval
.command
) = (yyvsp
[(1) - (1)].command
); }
2894 #line 910 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
2898 tc
= (yyvsp
[(1) - (2)].command
);
2899 /* According to Posix.2 3.9.5, redirections
2900 specified after the body of a function should
2901 be attached to the function and performed when
2902 the function is executed, not as part of the
2903 function definition command. */
2904 /* XXX - I don't think it matters, but we might
2905 want to change this in the future to avoid
2906 problems differentiating between a function
2907 definition with a redirection and a function
2908 definition containing a single command with a
2909 redirection. The two are semantically equivalent,
2910 though -- the only difference is in how the
2911 command printing code displays the redirections. */
2914 register REDIRECT
*t
;
2915 for (t
= tc
->redirects
; t
->next
; t
= t
->next
)
2917 t
->next
= (yyvsp
[(2) - (2)].redirect
);
2920 tc
->redirects
= (yyvsp
[(2) - (2)].redirect
);
2921 (yyval
.command
) = (yyvsp
[(1) - (2)].command
);
2926 #line 941 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
2928 (yyval
.command
) = make_subshell_command ((yyvsp
[(2) - (3)].command
));
2929 (yyval
.command
)->flags
|= CMD_WANT_SUBSHELL
;
2934 #line 948 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
2936 (yyval
.command
) = make_coproc_command ("COPROC", (yyvsp
[(2) - (2)].command
));
2937 (yyval
.command
)->flags
|= CMD_WANT_SUBSHELL
|CMD_COPROC_SUBSHELL
;
2942 #line 953 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
2946 tc
= (yyvsp
[(2) - (3)].command
);
2949 register REDIRECT
*t
;
2950 for (t
= tc
->redirects
; t
->next
; t
= t
->next
)
2952 t
->next
= (yyvsp
[(3) - (3)].redirect
);
2955 tc
->redirects
= (yyvsp
[(3) - (3)].redirect
);
2956 (yyval
.command
) = make_coproc_command ("COPROC", (yyvsp
[(2) - (3)].command
));
2957 (yyval
.command
)->flags
|= CMD_WANT_SUBSHELL
|CMD_COPROC_SUBSHELL
;
2962 #line 970 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
2964 (yyval
.command
) = make_coproc_command ((yyvsp
[(2) - (3)].word
)->word
, (yyvsp
[(3) - (3)].command
));
2965 (yyval
.command
)->flags
|= CMD_WANT_SUBSHELL
|CMD_COPROC_SUBSHELL
;
2970 #line 975 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
2974 tc
= (yyvsp
[(3) - (4)].command
);
2977 register REDIRECT
*t
;
2978 for (t
= tc
->redirects
; t
->next
; t
= t
->next
)
2980 t
->next
= (yyvsp
[(4) - (4)].redirect
);
2983 tc
->redirects
= (yyvsp
[(4) - (4)].redirect
);
2984 (yyval
.command
) = make_coproc_command ((yyvsp
[(2) - (4)].word
)->word
, (yyvsp
[(3) - (4)].command
));
2985 (yyval
.command
)->flags
|= CMD_WANT_SUBSHELL
|CMD_COPROC_SUBSHELL
;
2990 #line 992 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
2992 (yyval
.command
) = make_coproc_command ("COPROC", clean_simple_command ((yyvsp
[(2) - (2)].command
)));
2993 (yyval
.command
)->flags
|= CMD_WANT_SUBSHELL
|CMD_COPROC_SUBSHELL
;
2998 #line 999 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
2999 { (yyval
.command
) = make_if_command ((yyvsp
[(2) - (5)].command
), (yyvsp
[(4) - (5)].command
), (COMMAND
*)NULL
); }
3003 #line 1001 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
3004 { (yyval
.command
) = make_if_command ((yyvsp
[(2) - (7)].command
), (yyvsp
[(4) - (7)].command
), (yyvsp
[(6) - (7)].command
)); }
3008 #line 1003 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
3009 { (yyval
.command
) = make_if_command ((yyvsp
[(2) - (6)].command
), (yyvsp
[(4) - (6)].command
), (yyvsp
[(5) - (6)].command
)); }
3013 #line 1008 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
3014 { (yyval
.command
) = make_group_command ((yyvsp
[(2) - (3)].command
)); }
3018 #line 1012 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
3019 { (yyval
.command
) = make_arith_command ((yyvsp
[(1) - (1)].word_list
)); }
3023 #line 1016 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
3024 { (yyval
.command
) = (yyvsp
[(2) - (3)].command
); }
3028 #line 1020 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
3029 { (yyval
.command
) = make_if_command ((yyvsp
[(2) - (4)].command
), (yyvsp
[(4) - (4)].command
), (COMMAND
*)NULL
); }
3033 #line 1022 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
3034 { (yyval
.command
) = make_if_command ((yyvsp
[(2) - (6)].command
), (yyvsp
[(4) - (6)].command
), (yyvsp
[(6) - (6)].command
)); }
3038 #line 1024 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
3039 { (yyval
.command
) = make_if_command ((yyvsp
[(2) - (5)].command
), (yyvsp
[(4) - (5)].command
), (yyvsp
[(5) - (5)].command
)); }
3043 #line 1029 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
3044 { (yyvsp
[(2) - (2)].pattern
)->next
= (yyvsp
[(1) - (2)].pattern
); (yyval
.pattern
) = (yyvsp
[(2) - (2)].pattern
); }
3048 #line 1033 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
3049 { (yyval
.pattern
) = make_pattern_list ((yyvsp
[(2) - (4)].word_list
), (yyvsp
[(4) - (4)].command
)); }
3053 #line 1035 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
3054 { (yyval
.pattern
) = make_pattern_list ((yyvsp
[(2) - (4)].word_list
), (COMMAND
*)NULL
); }
3058 #line 1037 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
3059 { (yyval
.pattern
) = make_pattern_list ((yyvsp
[(3) - (5)].word_list
), (yyvsp
[(5) - (5)].command
)); }
3063 #line 1039 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
3064 { (yyval
.pattern
) = make_pattern_list ((yyvsp
[(3) - (5)].word_list
), (COMMAND
*)NULL
); }
3068 #line 1043 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
3069 { (yyval
.pattern
) = (yyvsp
[(1) - (2)].pattern
); }
3073 #line 1045 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
3074 { (yyvsp
[(2) - (3)].pattern
)->next
= (yyvsp
[(1) - (3)].pattern
); (yyval
.pattern
) = (yyvsp
[(2) - (3)].pattern
); }
3078 #line 1047 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
3079 { (yyvsp
[(1) - (2)].pattern
)->flags
|= CASEPAT_FALLTHROUGH
; (yyval
.pattern
) = (yyvsp
[(1) - (2)].pattern
); }
3083 #line 1049 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
3084 { (yyvsp
[(2) - (3)].pattern
)->flags
|= CASEPAT_FALLTHROUGH
; (yyvsp
[(2) - (3)].pattern
)->next
= (yyvsp
[(1) - (3)].pattern
); (yyval
.pattern
) = (yyvsp
[(2) - (3)].pattern
); }
3088 #line 1051 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
3089 { (yyvsp
[(1) - (2)].pattern
)->flags
|= CASEPAT_TESTNEXT
; (yyval
.pattern
) = (yyvsp
[(1) - (2)].pattern
); }
3093 #line 1053 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
3094 { (yyvsp
[(2) - (3)].pattern
)->flags
|= CASEPAT_TESTNEXT
; (yyvsp
[(2) - (3)].pattern
)->next
= (yyvsp
[(1) - (3)].pattern
); (yyval
.pattern
) = (yyvsp
[(2) - (3)].pattern
); }
3098 #line 1057 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
3099 { (yyval
.word_list
) = make_word_list ((yyvsp
[(1) - (1)].word
), (WORD_LIST
*)NULL
); }
3103 #line 1059 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
3104 { (yyval
.word_list
) = make_word_list ((yyvsp
[(3) - (3)].word
), (yyvsp
[(1) - (3)].word_list
)); }
3108 #line 1068 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
3110 (yyval
.command
) = (yyvsp
[(2) - (2)].command
);
3112 gather_here_documents ();
3117 #line 1077 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
3119 (yyval
.command
) = (yyvsp
[(2) - (2)].command
);
3124 #line 1084 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
3126 if ((yyvsp
[(1) - (3)].command
)->type
== cm_connection
)
3127 (yyval
.command
) = connect_async_list ((yyvsp
[(1) - (3)].command
), (COMMAND
*)NULL
, '&');
3129 (yyval
.command
) = command_connect ((yyvsp
[(1) - (3)].command
), (COMMAND
*)NULL
, '&');
3134 #line 1095 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
3135 { (yyval
.command
) = command_connect ((yyvsp
[(1) - (4)].command
), (yyvsp
[(4) - (4)].command
), AND_AND
); }
3139 #line 1097 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
3140 { (yyval
.command
) = command_connect ((yyvsp
[(1) - (4)].command
), (yyvsp
[(4) - (4)].command
), OR_OR
); }
3144 #line 1099 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
3146 if ((yyvsp
[(1) - (4)].command
)->type
== cm_connection
)
3147 (yyval
.command
) = connect_async_list ((yyvsp
[(1) - (4)].command
), (yyvsp
[(4) - (4)].command
), '&');
3149 (yyval
.command
) = command_connect ((yyvsp
[(1) - (4)].command
), (yyvsp
[(4) - (4)].command
), '&');
3154 #line 1106 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
3155 { (yyval
.command
) = command_connect ((yyvsp
[(1) - (4)].command
), (yyvsp
[(4) - (4)].command
), ';'); }
3159 #line 1108 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
3160 { (yyval
.command
) = command_connect ((yyvsp
[(1) - (4)].command
), (yyvsp
[(4) - (4)].command
), ';'); }
3164 #line 1110 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
3165 { (yyval
.command
) = (yyvsp
[(1) - (1)].command
); }
3169 #line 1118 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
3170 { (yyval
.number
) = '\n'; }
3174 #line 1120 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
3175 { (yyval
.number
) = ';'; }
3179 #line 1122 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
3180 { (yyval
.number
) = yacc_EOF
; }
3184 #line 1136 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
3186 (yyval
.command
) = (yyvsp
[(1) - (1)].command
);
3188 gather_here_documents ();
3189 if ((parser_state
& PST_CMDSUBST
) && current_token
== shell_eof_token
)
3191 global_command
= (yyvsp
[(1) - (1)].command
);
3192 eof_encountered
= 0;
3193 rewind_input_string ();
3200 #line 1149 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
3202 if ((yyvsp
[(1) - (2)].command
)->type
== cm_connection
)
3203 (yyval
.command
) = connect_async_list ((yyvsp
[(1) - (2)].command
), (COMMAND
*)NULL
, '&');
3205 (yyval
.command
) = command_connect ((yyvsp
[(1) - (2)].command
), (COMMAND
*)NULL
, '&');
3207 gather_here_documents ();
3208 if ((parser_state
& PST_CMDSUBST
) && current_token
== shell_eof_token
)
3210 global_command
= (yyvsp
[(1) - (2)].command
);
3211 eof_encountered
= 0;
3212 rewind_input_string ();
3219 #line 1165 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
3221 (yyval
.command
) = (yyvsp
[(1) - (2)].command
);
3223 gather_here_documents ();
3224 if ((parser_state
& PST_CMDSUBST
) && current_token
== shell_eof_token
)
3226 global_command
= (yyvsp
[(1) - (2)].command
);
3227 eof_encountered
= 0;
3228 rewind_input_string ();
3235 #line 1180 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
3236 { (yyval
.command
) = command_connect ((yyvsp
[(1) - (4)].command
), (yyvsp
[(4) - (4)].command
), AND_AND
); }
3240 #line 1182 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
3241 { (yyval
.command
) = command_connect ((yyvsp
[(1) - (4)].command
), (yyvsp
[(4) - (4)].command
), OR_OR
); }
3245 #line 1184 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
3247 if ((yyvsp
[(1) - (3)].command
)->type
== cm_connection
)
3248 (yyval
.command
) = connect_async_list ((yyvsp
[(1) - (3)].command
), (yyvsp
[(3) - (3)].command
), '&');
3250 (yyval
.command
) = command_connect ((yyvsp
[(1) - (3)].command
), (yyvsp
[(3) - (3)].command
), '&');
3255 #line 1191 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
3256 { (yyval
.command
) = command_connect ((yyvsp
[(1) - (3)].command
), (yyvsp
[(3) - (3)].command
), ';'); }
3260 #line 1194 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
3261 { (yyval
.command
) = (yyvsp
[(1) - (1)].command
); }
3265 #line 1198 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
3266 { (yyval
.command
) = (yyvsp
[(1) - (1)].command
); }
3270 #line 1200 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
3272 if ((yyvsp
[(2) - (2)].command
))
3273 (yyvsp
[(2) - (2)].command
)->flags
^= CMD_INVERT_RETURN
; /* toggle */
3274 (yyval
.command
) = (yyvsp
[(2) - (2)].command
);
3279 #line 1206 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
3281 if ((yyvsp
[(2) - (2)].command
))
3282 (yyvsp
[(2) - (2)].command
)->flags
|= (yyvsp
[(1) - (2)].number
);
3283 (yyval
.command
) = (yyvsp
[(2) - (2)].command
);
3288 #line 1212 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
3292 /* Boy, this is unclean. `time' by itself can
3293 time a null command. We cheat and push a
3294 newline back if the list_terminator was a newline
3295 to avoid the double-newline problem (one to
3296 terminate this, one to terminate the command) */
3299 (yyval
.command
) = make_simple_command (x
, (COMMAND
*)NULL
);
3300 (yyval
.command
)->flags
|= (yyvsp
[(1) - (2)].number
);
3301 /* XXX - let's cheat and push a newline back */
3302 if ((yyvsp
[(2) - (2)].number
) == '\n')
3303 token_to_read
= '\n';
3308 #line 1229 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
3312 /* This is just as unclean. Posix says that `!'
3313 by itself should be equivalent to `false'.
3315 newline back if the list_terminator was a newline
3316 to avoid the double-newline problem (one to
3317 terminate this, one to terminate the command) */
3320 (yyval
.command
) = make_simple_command (x
, (COMMAND
*)NULL
);
3321 (yyval
.command
)->flags
|= CMD_INVERT_RETURN
;
3322 /* XXX - let's cheat and push a newline back */
3323 if ((yyvsp
[(2) - (2)].number
) == '\n')
3324 token_to_read
= '\n';
3329 #line 1249 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
3330 { (yyval
.command
) = command_connect ((yyvsp
[(1) - (4)].command
), (yyvsp
[(4) - (4)].command
), '|'); }
3334 #line 1251 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
3336 /* Make cmd1 |& cmd2 equivalent to cmd1 2>&1 | cmd2 */
3341 tc
= (yyvsp
[(1) - (4)].command
)->type
== cm_simple
? (COMMAND
*)(yyvsp
[(1) - (4)].command
)->value
.Simple
: (yyvsp
[(1) - (4)].command
);
3344 r
= make_redirection (sd
, r_duplicating_output
, rd
, 0);
3347 register REDIRECT
*t
;
3348 for (t
= tc
->redirects
; t
->next
; t
= t
->next
)
3355 (yyval
.command
) = command_connect ((yyvsp
[(1) - (4)].command
), (yyvsp
[(4) - (4)].command
), '|');
3360 #line 1274 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
3361 { (yyval
.command
) = (yyvsp
[(1) - (1)].command
); }
3365 #line 1278 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
3366 { (yyval
.number
) = CMD_TIME_PIPELINE
; }
3370 #line 1280 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
3371 { (yyval
.number
) = CMD_TIME_PIPELINE
|CMD_TIME_POSIX
; }
3375 #line 1282 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
3376 { (yyval
.number
) = CMD_TIME_PIPELINE
|CMD_TIME_POSIX
; }
3380 /* Line 1267 of yacc.c. */
3381 #line 3382 "y.tab.c"
3384 YY_SYMBOL_PRINT ("-> $$ =", yyr1
[yyn
], &yyval
, &yyloc
);
3388 YY_STACK_PRINT (yyss
, yyssp
);
3393 /* Now `shift' the result of the reduction. Determine what state
3394 that goes to, based on the state we popped back to and the rule
3395 number reduced by. */
3399 yystate
= yypgoto
[yyn
- YYNTOKENS
] + *yyssp
;
3400 if (0 <= yystate
&& yystate
<= YYLAST
&& yycheck
[yystate
] == *yyssp
)
3401 yystate
= yytable
[yystate
];
3403 yystate
= yydefgoto
[yyn
- YYNTOKENS
];
3408 /*------------------------------------.
3409 | yyerrlab -- here on detecting error |
3410 `------------------------------------*/
3412 /* If not already recovering from an error, report this error. */
3416 #if ! YYERROR_VERBOSE
3417 yyerror (YY_("syntax error"));
3420 YYSIZE_T yysize
= yysyntax_error (0, yystate
, yychar
);
3421 if (yymsg_alloc
< yysize
&& yymsg_alloc
< YYSTACK_ALLOC_MAXIMUM
)
3423 YYSIZE_T yyalloc
= 2 * yysize
;
3424 if (! (yysize
<= yyalloc
&& yyalloc
<= YYSTACK_ALLOC_MAXIMUM
))
3425 yyalloc
= YYSTACK_ALLOC_MAXIMUM
;
3426 if (yymsg
!= yymsgbuf
)
3427 YYSTACK_FREE (yymsg
);
3428 yymsg
= (char *) YYSTACK_ALLOC (yyalloc
);
3430 yymsg_alloc
= yyalloc
;
3434 yymsg_alloc
= sizeof yymsgbuf
;
3438 if (0 < yysize
&& yysize
<= yymsg_alloc
)
3440 (void) yysyntax_error (yymsg
, yystate
, yychar
);
3445 yyerror (YY_("syntax error"));
3447 goto yyexhaustedlab
;
3455 if (yyerrstatus
== 3)
3457 /* If just tried and failed to reuse look-ahead token after an
3458 error, discard it. */
3460 if (yychar
<= YYEOF
)
3462 /* Return failure if at end of input. */
3463 if (yychar
== YYEOF
)
3468 yydestruct ("Error: discarding",
3474 /* Else will try to reuse look-ahead token after shifting the error
3479 /*---------------------------------------------------.
3480 | yyerrorlab -- error raised explicitly by YYERROR. |
3481 `---------------------------------------------------*/
3484 /* Pacify compilers like GCC when the user code never invokes
3485 YYERROR and the label yyerrorlab therefore never appears in user
3487 if (/*CONSTCOND*/ 0)
3490 /* Do not reclaim the symbols of the rule which action triggered
3494 YY_STACK_PRINT (yyss
, yyssp
);
3499 /*-------------------------------------------------------------.
3500 | yyerrlab1 -- common code for both syntax error and YYERROR. |
3501 `-------------------------------------------------------------*/
3503 yyerrstatus
= 3; /* Each real token shifted decrements this. */
3507 yyn
= yypact
[yystate
];
3508 if (yyn
!= YYPACT_NINF
)
3511 if (0 <= yyn
&& yyn
<= YYLAST
&& yycheck
[yyn
] == YYTERROR
)
3519 /* Pop the current state because it cannot handle the error token. */
3524 yydestruct ("Error: popping",
3525 yystos
[yystate
], yyvsp
);
3528 YY_STACK_PRINT (yyss
, yyssp
);
3537 /* Shift the error token. */
3538 YY_SYMBOL_PRINT ("Shifting", yystos
[yyn
], yyvsp
, yylsp
);
3544 /*-------------------------------------.
3545 | yyacceptlab -- YYACCEPT comes here. |
3546 `-------------------------------------*/
3551 /*-----------------------------------.
3552 | yyabortlab -- YYABORT comes here. |
3553 `-----------------------------------*/
3559 /*-------------------------------------------------.
3560 | yyexhaustedlab -- memory exhaustion comes here. |
3561 `-------------------------------------------------*/
3563 yyerror (YY_("memory exhausted"));
3569 if (yychar
!= YYEOF
&& yychar
!= YYEMPTY
)
3570 yydestruct ("Cleanup: discarding lookahead",
3572 /* Do not reclaim the symbols of the rule which action triggered
3573 this YYABORT or YYACCEPT. */
3575 YY_STACK_PRINT (yyss
, yyssp
);
3576 while (yyssp
!= yyss
)
3578 yydestruct ("Cleanup: popping",
3579 yystos
[*yyssp
], yyvsp
);
3584 YYSTACK_FREE (yyss
);
3587 if (yymsg
!= yymsgbuf
)
3588 YYSTACK_FREE (yymsg
);
3590 /* Make sure YYID is used. */
3591 return YYID (yyresult
);
3595 #line 1284 "/usr/src/local/chet/src/bash/bash-4.3.28/parse.y"
3598 /* Initial size to allocate for tokens, and the
3599 amount to grow them by. */
3600 #define TOKEN_DEFAULT_INITIAL_SIZE 496
3601 #define TOKEN_DEFAULT_GROW_SIZE 512
3603 /* Should we call prompt_again? */
3604 #define SHOULD_PROMPT() \
3605 (interactive && (bash_input.type == st_stdin || bash_input.type == st_stream))
3608 # define expanding_alias() (pushed_string_list && pushed_string_list->expander)
3610 # define expanding_alias() 0
3613 /* Global var is non-zero when end of file has been reached. */
3614 int EOF_Reached
= 0;
3627 /* yy_getc () returns the next available character from input or EOF.
3628 yy_ungetc (c) makes `c' the next character to read.
3629 init_yy_io (get, unget, type, location) makes the function GET the
3630 installed function for getting the next character, makes UNGET the
3631 installed function for un-getting a character, sets the type of stream
3632 (either string or file) from TYPE, and makes LOCATION point to where
3633 the input is coming from. */
3635 /* Unconditionally returns end-of-file. */
3642 /* Variable containing the current get and unget functions.
3643 See ./input.h for a clearer description. */
3644 BASH_INPUT bash_input
;
3646 /* Set all of the fields in BASH_INPUT to NULL. Free bash_input.name if it
3647 is non-null, avoiding a memory leak. */
3649 initialize_bash_input ()
3651 bash_input
.type
= st_none
;
3652 FREE (bash_input
.name
);
3653 bash_input
.name
= (char *)NULL
;
3654 bash_input
.location
.file
= (FILE *)NULL
;
3655 bash_input
.location
.string
= (char *)NULL
;
3656 bash_input
.getter
= (sh_cget_func_t
*)NULL
;
3657 bash_input
.ungetter
= (sh_cunget_func_t
*)NULL
;
3660 /* Set the contents of the current bash input stream from
3661 GET, UNGET, TYPE, NAME, and LOCATION. */
3663 init_yy_io (get
, unget
, type
, name
, location
)
3664 sh_cget_func_t
*get
;
3665 sh_cunget_func_t
*unget
;
3666 enum stream_type type
;
3668 INPUT_STREAM location
;
3670 bash_input
.type
= type
;
3671 FREE (bash_input
.name
);
3672 bash_input
.name
= name
? savestring (name
) : (char *)NULL
;
3676 memcpy((char *)&bash_input
.location
.string
, (char *)&location
.string
, sizeof(location
));
3678 bash_input
.location
= location
;
3680 bash_input
.getter
= get
;
3681 bash_input
.ungetter
= unget
;
3687 return (bash_input
.name
? bash_input
.name
: "stdin");
3690 /* Call this to get the next character of input. */
3694 return (*(bash_input
.getter
)) ();
3697 /* Call this to unget C. That is, to make C the next character
3703 return (*(bash_input
.ungetter
)) (c
);
3706 #if defined (BUFFERED_INPUT)
3707 #ifdef INCLUDE_UNUSED
3709 input_file_descriptor ()
3711 switch (bash_input
.type
)
3714 return (fileno (bash_input
.location
.file
));
3716 return (bash_input
.location
.buffered_fd
);
3719 return (fileno (stdin
));
3723 #endif /* BUFFERED_INPUT */
3725 /* **************************************************************** */
3727 /* Let input be read from readline (). */
3729 /* **************************************************************** */
3731 #if defined (READLINE)
3732 char *current_readline_prompt
= (char *)NULL
;
3733 char *current_readline_line
= (char *)NULL
;
3734 int current_readline_line_index
= 0;
3739 SigHandler
*old_sigint
;
3743 if (!current_readline_line
)
3745 if (!bash_readline_initialized
)
3746 initialize_readline ();
3748 #if defined (JOB_CONTROL)
3750 give_terminal_to (shell_pgrp
, 0);
3751 #endif /* JOB_CONTROL */
3753 old_sigint
= (SigHandler
*)IMPOSSIBLE_TRAP_HANDLER
;
3754 if (signal_is_ignored (SIGINT
) == 0)
3756 /* interrupt_immediately++; */
3757 old_sigint
= (SigHandler
*)set_signal_handler (SIGINT
, sigint_sighandler
);
3760 current_readline_line
= readline (current_readline_prompt
?
3761 current_readline_prompt
: "");
3764 if (signal_is_ignored (SIGINT
) == 0)
3766 /* interrupt_immediately--; */
3767 if (old_sigint
!= IMPOSSIBLE_TRAP_HANDLER
)
3768 set_signal_handler (SIGINT
, old_sigint
);
3772 /* Reset the prompt to the decoded value of prompt_string_pointer. */
3773 reset_readline_prompt ();
3776 if (current_readline_line
== 0)
3779 current_readline_line_index
= 0;
3780 line_len
= strlen (current_readline_line
);
3782 current_readline_line
= (char *)xrealloc (current_readline_line
, 2 + line_len
);
3783 current_readline_line
[line_len
++] = '\n';
3784 current_readline_line
[line_len
] = '\0';
3787 if (current_readline_line
[current_readline_line_index
] == 0)
3789 free (current_readline_line
);
3790 current_readline_line
= (char *)NULL
;
3791 return (yy_readline_get ());
3795 c
= current_readline_line
[current_readline_line_index
++];
3801 yy_readline_unget (c
)
3804 if (current_readline_line_index
&& current_readline_line
)
3805 current_readline_line
[--current_readline_line_index
] = c
;
3810 with_input_from_stdin ()
3812 INPUT_STREAM location
;
3814 if (bash_input
.type
!= st_stdin
&& stream_on_stack (st_stdin
) == 0)
3816 location
.string
= current_readline_line
;
3817 init_yy_io (yy_readline_get
, yy_readline_unget
,
3818 st_stdin
, "readline stdin", location
);
3822 #else /* !READLINE */
3825 with_input_from_stdin ()
3827 with_input_from_stream (stdin
, "stdin");
3829 #endif /* !READLINE */
3831 /* **************************************************************** */
3833 /* Let input come from STRING. STRING is zero terminated. */
3835 /* **************************************************************** */
3840 register char *string
;
3841 register unsigned char c
;
3843 string
= bash_input
.location
.string
;
3845 /* If the string doesn't exist, or is empty, EOF found. */
3846 if (string
&& *string
)
3849 bash_input
.location
.string
= string
;
3860 *(--bash_input
.location
.string
) = c
;
3865 with_input_from_string (string
, name
)
3869 INPUT_STREAM location
;
3871 location
.string
= string
;
3872 init_yy_io (yy_string_get
, yy_string_unget
, st_string
, name
, location
);
3875 /* Count the number of characters we've consumed from bash_input.location.string
3876 and read into shell_input_line, but have not returned from shell_getc.
3877 That is the true input location. Rewind bash_input.location.string by
3878 that number of characters, so it points to the last character actually
3879 consumed by the parser. */
3881 rewind_input_string ()
3885 /* number of unconsumed characters in the input -- XXX need to take newlines
3886 into account, e.g., $(...\n) */
3887 xchars
= shell_input_line_len
- shell_input_line_index
;
3888 if (bash_input
.location
.string
[-1] == '\n')
3891 /* XXX - how to reflect bash_input.location.string back to string passed to
3892 parse_and_execute or xparse_dolparen? xparse_dolparen needs to know how
3893 far into the string we parsed. parse_and_execute knows where bash_input.
3894 location.string is, and how far from orig_string that is -- that's the
3895 number of characters the command consumed. */
3897 /* bash_input.location.string - xchars should be where we parsed to */
3898 /* need to do more validation on xchars value for sanity -- test cases. */
3899 bash_input
.location
.string
-= xchars
;
3902 /* **************************************************************** */
3904 /* Let input come from STREAM. */
3906 /* **************************************************************** */
3908 /* These two functions used to test the value of the HAVE_RESTARTABLE_SYSCALLS
3909 define, and just use getc/ungetc if it was defined, but since bash
3910 installs its signal handlers without the SA_RESTART flag, some signals
3911 (like SIGCHLD, SIGWINCH, etc.) received during a read(2) will not cause
3912 the read to be restarted. We need to restart it ourselves. */
3920 if (bash_input
.location
.file
)
3924 interrupt_immediately
++;
3927 /* XXX - don't need terminate_immediately; getc_with_restart checks
3928 for terminating signals itself if read returns < 0 */
3929 result
= getc_with_restart (bash_input
.location
.file
);
3933 interrupt_immediately
--;
3943 return (ungetc_with_restart (c
, bash_input
.location
.file
));
3947 with_input_from_stream (stream
, name
)
3951 INPUT_STREAM location
;
3953 location
.file
= stream
;
3954 init_yy_io (yy_stream_get
, yy_stream_unget
, st_stream
, name
, location
);
3957 typedef struct stream_saver
{
3958 struct stream_saver
*next
;
3959 BASH_INPUT bash_input
;
3961 #if defined (BUFFERED_INPUT)
3962 BUFFERED_STREAM
*bstream
;
3963 #endif /* BUFFERED_INPUT */
3966 /* The globally known line number. */
3967 int line_number
= 0;
3969 /* The line number offset set by assigning to LINENO. Not currently used. */
3970 int line_number_base
= 0;
3972 #if defined (COND_COMMAND)
3973 static int cond_lineno
;
3974 static int cond_token
;
3977 STREAM_SAVER
*stream_list
= (STREAM_SAVER
*)NULL
;
3980 push_stream (reset_lineno
)
3983 STREAM_SAVER
*saver
= (STREAM_SAVER
*)xmalloc (sizeof (STREAM_SAVER
));
3985 xbcopy ((char *)&bash_input
, (char *)&(saver
->bash_input
), sizeof (BASH_INPUT
));
3987 #if defined (BUFFERED_INPUT)
3988 saver
->bstream
= (BUFFERED_STREAM
*)NULL
;
3989 /* If we have a buffered stream, clear out buffers[fd]. */
3990 if (bash_input
.type
== st_bstream
&& bash_input
.location
.buffered_fd
>= 0)
3991 saver
->bstream
= set_buffered_stream (bash_input
.location
.buffered_fd
,
3992 (BUFFERED_STREAM
*)NULL
);
3993 #endif /* BUFFERED_INPUT */
3995 saver
->line
= line_number
;
3996 bash_input
.name
= (char *)NULL
;
3997 saver
->next
= stream_list
;
3998 stream_list
= saver
;
4011 STREAM_SAVER
*saver
= stream_list
;
4014 stream_list
= stream_list
->next
;
4016 init_yy_io (saver
->bash_input
.getter
,
4017 saver
->bash_input
.ungetter
,
4018 saver
->bash_input
.type
,
4019 saver
->bash_input
.name
,
4020 saver
->bash_input
.location
);
4022 #if defined (BUFFERED_INPUT)
4023 /* If we have a buffered stream, restore buffers[fd]. */
4024 /* If the input file descriptor was changed while this was on the
4025 save stack, update the buffered fd to the new file descriptor and
4026 re-establish the buffer <-> bash_input fd correspondence. */
4027 if (bash_input
.type
== st_bstream
&& bash_input
.location
.buffered_fd
>= 0)
4029 if (bash_input_fd_changed
)
4031 bash_input_fd_changed
= 0;
4032 if (default_buffered_input
>= 0)
4034 bash_input
.location
.buffered_fd
= default_buffered_input
;
4035 saver
->bstream
->b_fd
= default_buffered_input
;
4036 SET_CLOSE_ON_EXEC (default_buffered_input
);
4039 /* XXX could free buffered stream returned as result here. */
4040 set_buffered_stream (bash_input
.location
.buffered_fd
, saver
->bstream
);
4042 #endif /* BUFFERED_INPUT */
4044 line_number
= saver
->line
;
4046 FREE (saver
->bash_input
.name
);
4051 /* Return 1 if a stream of type TYPE is saved on the stack. */
4053 stream_on_stack (type
)
4054 enum stream_type type
;
4056 register STREAM_SAVER
*s
;
4058 for (s
= stream_list
; s
; s
= s
->next
)
4059 if (s
->bash_input
.type
== type
)
4064 /* Save the current token state and return it in a malloced array. */
4070 ret
= (int *)xmalloc (4 * sizeof (int));
4071 ret
[0] = last_read_token
;
4072 ret
[1] = token_before_that
;
4073 ret
[2] = two_tokens_ago
;
4074 ret
[3] = current_token
;
4079 restore_token_state (ts
)
4084 last_read_token
= ts
[0];
4085 token_before_that
= ts
[1];
4086 two_tokens_ago
= ts
[2];
4087 current_token
= ts
[3];
4091 * This is used to inhibit alias expansion and reserved word recognition
4092 * inside case statement pattern lists. A `case statement pattern list' is:
4094 * everything between the `in' in a `case word in' and the next ')'
4096 * everything between a `;;' and the next `)' or `esac'
4099 #if defined (ALIAS) || defined (DPAREN_ARITHMETIC)
4101 #define END_OF_ALIAS 0
4104 * Pseudo-global variables used in implementing token-wise alias expansion.
4108 * Pushing and popping strings. This works together with shell_getc to
4109 * implement alias expansion on a per-token basis.
4112 #define PSH_ALIAS 0x01
4113 #define PSH_DPAREN 0x02
4114 #define PSH_SOURCE 0x04
4116 typedef struct string_saver
{
4117 struct string_saver
*next
;
4118 int expand_alias
; /* Value to set expand_alias to when string is popped. */
4121 alias_t
*expander
; /* alias that caused this line to be pushed. */
4123 size_t saved_line_size
, saved_line_index
;
4124 int saved_line_terminator
;
4128 STRING_SAVER
*pushed_string_list
= (STRING_SAVER
*)NULL
;
4131 * Push the current shell_input_line onto a stack of such lines and make S
4132 * the current input. Used when expanding aliases. EXPAND is used to set
4133 * the value of expand_next_token when the string is popped, so that the
4134 * word after the alias in the original line is handled correctly when the
4135 * alias expands to multiple words. TOKEN is the token that was expanded
4136 * into S; it is saved and used to prevent infinite recursive expansion.
4139 push_string (s
, expand
, ap
)
4144 STRING_SAVER
*temp
= (STRING_SAVER
*)xmalloc (sizeof (STRING_SAVER
));
4146 temp
->expand_alias
= expand
;
4147 temp
->saved_line
= shell_input_line
;
4148 temp
->saved_line_size
= shell_input_line_size
;
4149 temp
->saved_line_index
= shell_input_line_index
;
4150 temp
->saved_line_terminator
= shell_input_line_terminator
;
4153 temp
->expander
= ap
;
4155 temp
->flags
= PSH_ALIAS
;
4157 temp
->next
= pushed_string_list
;
4158 pushed_string_list
= temp
;
4162 ap
->flags
|= AL_BEINGEXPANDED
;
4165 shell_input_line
= s
;
4166 shell_input_line_size
= STRLEN (s
);
4167 shell_input_line_index
= 0;
4168 shell_input_line_terminator
= '\0';
4170 parser_state
&= ~PST_ALEXPNEXT
; /* XXX */
4173 set_line_mbstate ();
4177 * Make the top of the pushed_string stack be the current shell input.
4178 * Only called when there is something on the stack. Called from shell_getc
4179 * when it thinks it has consumed the string generated by an alias expansion
4180 * and needs to return to the original input line.
4187 FREE (shell_input_line
);
4188 shell_input_line
= pushed_string_list
->saved_line
;
4189 shell_input_line_index
= pushed_string_list
->saved_line_index
;
4190 shell_input_line_size
= pushed_string_list
->saved_line_size
;
4191 shell_input_line_terminator
= pushed_string_list
->saved_line_terminator
;
4193 if (pushed_string_list
->expand_alias
)
4194 parser_state
|= PST_ALEXPNEXT
;
4196 parser_state
&= ~PST_ALEXPNEXT
;
4198 t
= pushed_string_list
;
4199 pushed_string_list
= pushed_string_list
->next
;
4203 t
->expander
->flags
&= ~AL_BEINGEXPANDED
;
4208 set_line_mbstate ();
4214 register STRING_SAVER
*t
, *t1
;
4216 for (t
= pushed_string_list
; t
; )
4219 FREE (t
->saved_line
);
4222 t
->expander
->flags
&= ~AL_BEINGEXPANDED
;
4227 pushed_string_list
= (STRING_SAVER
*)NULL
;
4230 #endif /* ALIAS || DPAREN_ARITHMETIC */
4233 free_pushed_string_input ()
4235 #if defined (ALIAS) || defined (DPAREN_ARITHMETIC)
4236 free_string_list ();
4241 parser_expanding_alias ()
4243 return (expanding_alias ());
4247 parser_save_alias ()
4249 #if defined (ALIAS) || defined (DPAREN_ARITHMETIC)
4250 push_string ((char *)NULL
, 0, (alias_t
*)NULL
);
4251 pushed_string_list
->flags
= PSH_SOURCE
; /* XXX - for now */
4258 parser_restore_alias ()
4260 #if defined (ALIAS) || defined (DPAREN_ARITHMETIC)
4261 if (pushed_string_list
)
4268 /* Return a line of text, taken from wherever yylex () reads input.
4269 If there is no more input, then we return NULL. If REMOVE_QUOTED_NEWLINE
4270 is non-zero, we remove unquoted \<newline> pairs. This is used by
4271 read_secondary_line to read here documents. */
4273 read_a_line (remove_quoted_newline
)
4274 int remove_quoted_newline
;
4276 static char *line_buffer
= (char *)NULL
;
4277 static int buffer_size
= 0;
4278 int indx
, c
, peekc
, pass_next
;
4280 #if defined (READLINE)
4281 if (no_line_editing
&& SHOULD_PROMPT ())
4283 if (SHOULD_PROMPT ())
4287 pass_next
= indx
= 0;
4290 /* Allow immediate exit if interrupted during input. */
4295 /* Ignore null bytes in input. */
4299 internal_warning ("read_a_line: ignored null byte in input");
4304 /* If there is no more input, then we return NULL. */
4307 if (interactive
&& bash_input
.type
== st_stream
)
4310 return ((char *)NULL
);
4314 /* `+2' in case the final character in the buffer is a newline. */
4315 RESIZE_MALLOCED_BUFFER (line_buffer
, indx
, 2, buffer_size
, 128);
4317 /* IF REMOVE_QUOTED_NEWLINES is non-zero, we are reading a
4318 here document with an unquoted delimiter. In this case,
4319 the line will be expanded as if it were in double quotes.
4320 We allow a backslash to escape the next character, but we
4321 need to treat the backslash specially only if a backslash
4322 quoting a backslash-newline pair appears in the line. */
4325 line_buffer
[indx
++] = c
;
4328 else if (c
== '\\' && remove_quoted_newline
)
4335 continue; /* Make the unquoted \<newline> pair disappear. */
4341 line_buffer
[indx
++] = c
; /* Preserve the backslash. */
4345 line_buffer
[indx
++] = c
;
4349 line_buffer
[indx
] = '\0';
4350 return (line_buffer
);
4355 /* Return a line as in read_a_line (), but insure that the prompt is
4356 the secondary prompt. This is used to read the lines of a here
4357 document. REMOVE_QUOTED_NEWLINE is non-zero if we should remove
4358 newlines quoted with backslashes while reading the line. It is
4359 non-zero unless the delimiter of the here document was quoted. */
4361 read_secondary_line (remove_quoted_newline
)
4362 int remove_quoted_newline
;
4367 prompt_string_pointer
= &ps2_prompt
;
4368 if (SHOULD_PROMPT())
4370 ret
= read_a_line (remove_quoted_newline
);
4371 #if defined (HISTORY)
4372 if (ret
&& remember_on_history
&& (parser_state
& PST_HEREDOC
))
4374 /* To make adding the the here-document body right, we need to rely
4375 on history_delimiting_chars() returning \n for the first line of
4376 the here-document body and the null string for the second and
4377 subsequent lines, so we avoid double newlines.
4378 current_command_line_count == 2 for the first line of the body. */
4380 current_command_line_count
++;
4381 maybe_add_history (ret
);
4383 #endif /* HISTORY */
4387 /* **************************************************************** */
4391 /* **************************************************************** */
4393 /* Reserved words. These are only recognized as the first word of a
4395 STRING_INT_ALIST word_token_alist
[] = {
4404 #if defined (SELECT_COMMAND)
4405 { "select", SELECT
},
4412 { "function", FUNCTION
},
4413 #if defined (COMMAND_TIMING)
4419 #if defined (COND_COMMAND)
4420 { "[[", COND_START
},
4423 #if defined (COPROCESS_SUPPORT)
4424 { "coproc", COPROC
},
4429 /* other tokens that can be returned by read_token() */
4430 STRING_INT_ALIST other_token_alist
[] = {
4431 /* Multiple-character tokens with special values */
4436 { ">>", GREATER_GREATER
},
4437 { "<<", LESS_LESS
},
4439 { ">&", GREATER_AND
},
4440 { ";;", SEMI_SEMI
},
4442 { ";;&", SEMI_SEMI_AND
},
4443 { "<<-", LESS_LESS_MINUS
},
4444 { "<<<", LESS_LESS_LESS
},
4445 { "&>", AND_GREATER
},
4446 { "&>>", AND_GREATER_GREATER
},
4447 { "<>", LESS_GREATER
},
4448 { ">|", GREATER_BAR
},
4450 { "EOF", yacc_EOF
},
4451 /* Tokens whose value is the character itself */
4462 { "newline", '\n' },
4466 /* others not listed here:
4467 WORD look at yylval.word
4468 ASSIGNMENT_WORD look at yylval.word
4469 NUMBER look at yylval.number
4470 ARITH_CMD look at yylval.word_list
4471 ARITH_FOR_EXPRS look at yylval.word_list
4472 COND_CMD look at yylval.command
4475 /* These are used by read_token_word, but appear up here so that shell_getc
4476 can use them to decide when to add otherwise blank lines to the history. */
4478 /* The primary delimiter stack. */
4479 struct dstack dstack
= { (char *)NULL
, 0, 0 };
4481 /* A temporary delimiter stack to be used when decoding prompt strings.
4482 This is needed because command substitutions in prompt strings (e.g., PS2)
4483 can screw up the parser's quoting state. */
4484 static struct dstack temp_dstack
= { (char *)NULL
, 0, 0 };
4486 /* Macro for accessing the top delimiter on the stack. Returns the
4487 delimiter or zero if none. */
4488 #define current_delimiter(ds) \
4489 (ds.delimiter_depth ? ds.delimiters[ds.delimiter_depth - 1] : 0)
4491 #define push_delimiter(ds, character) \
4494 if (ds.delimiter_depth + 2 > ds.delimiter_space) \
4495 ds.delimiters = (char *)xrealloc \
4496 (ds.delimiters, (ds.delimiter_space += 10) * sizeof (char)); \
4497 ds.delimiters[ds.delimiter_depth] = character; \
4498 ds.delimiter_depth++; \
4502 #define pop_delimiter(ds) ds.delimiter_depth--
4504 /* Return the next shell input character. This always reads characters
4505 from shell_input_line; when that line is exhausted, it is time to
4506 read the next line. This is called by read_token when the shell is
4507 processing normal command input. */
4509 /* This implements one-character lookahead/lookbehind across physical input
4510 lines, to avoid something being lost because it's pushed back with
4511 shell_ungetc when we're at the start of a line. */
4512 static int eol_ungetc_lookahead
= 0;
4515 shell_getc (remove_quoted_newline
)
4516 int remove_quoted_newline
;
4524 if (sigwinch_received
)
4526 sigwinch_received
= 0;
4527 get_new_window_size (0, (int *)0, (int *)0);
4530 if (eol_ungetc_lookahead
)
4532 c
= eol_ungetc_lookahead
;
4533 eol_ungetc_lookahead
= 0;
4537 #if defined (ALIAS) || defined (DPAREN_ARITHMETIC)
4538 /* If shell_input_line[shell_input_line_index] == 0, but there is
4539 something on the pushed list of strings, then we don't want to go
4540 off and get another line. We let the code down below handle it. */
4542 if (!shell_input_line
|| ((!shell_input_line
[shell_input_line_index
]) &&
4543 (pushed_string_list
== (STRING_SAVER
*)NULL
)))
4544 #else /* !ALIAS && !DPAREN_ARITHMETIC */
4545 if (!shell_input_line
|| !shell_input_line
[shell_input_line_index
])
4546 #endif /* !ALIAS && !DPAREN_ARITHMETIC */
4550 /* Let's not let one really really long line blow up memory allocation */
4551 if (shell_input_line
&& shell_input_line_size
>= 32768)
4553 free (shell_input_line
);
4554 shell_input_line
= 0;
4555 shell_input_line_size
= 0;
4560 /* Allow immediate exit if interrupted during input. */
4564 shell_input_line_terminator
= 0;
4566 /* If the shell is interatctive, but not currently printing a prompt
4567 (interactive_shell && interactive == 0), we don't want to print
4568 notifies or cleanup the jobs -- we want to defer it until we do
4569 print the next prompt. */
4570 if (interactive_shell
== 0 || SHOULD_PROMPT())
4572 #if defined (JOB_CONTROL)
4573 /* This can cause a problem when reading a command as the result
4574 of a trap, when the trap is called from flush_child. This call
4575 had better not cause jobs to disappear from the job table in
4576 that case, or we will have big trouble. */
4577 notify_and_cleanup ();
4578 #else /* !JOB_CONTROL */
4579 cleanup_dead_jobs ();
4580 #endif /* !JOB_CONTROL */
4583 #if defined (READLINE)
4584 if (no_line_editing
&& SHOULD_PROMPT())
4586 if (SHOULD_PROMPT())
4590 if (bash_input
.type
== st_stream
)
4597 /* Allow immediate exit if interrupted during input. */
4603 internal_warning ("shell_getc: ignored null byte in input");
4608 /* Theoretical overflow */
4609 /* If we can't put 256 bytes more into the buffer, allocate
4610 everything we can and fill it as full as we can. */
4611 /* XXX - we ignore rest of line using `truncating' flag */
4612 if (shell_input_line_size
> (SIZE_MAX
- 256))
4616 n
= SIZE_MAX
- i
; /* how much more can we put into the buffer? */
4617 if (n
<= 2) /* we have to save 1 for the newline added below */
4619 if (truncating
== 0)
4620 internal_warning("shell_getc: shell_input_line_size (%zu) exceeds SIZE_MAX (%llu): line truncated", shell_input_line_size
, SIZE_MAX
);
4621 shell_input_line
[i
] = '\0';
4624 if (shell_input_line_size
< SIZE_MAX
)
4626 shell_input_line_size
= SIZE_MAX
;
4627 shell_input_line
= xrealloc (shell_input_line
, shell_input_line_size
);
4631 RESIZE_MALLOCED_BUFFER (shell_input_line
, i
, 2, shell_input_line_size
, 256);
4635 if (bash_input
.type
== st_stream
)
4639 shell_input_line_terminator
= EOF
;
4641 shell_input_line
[i
] = '\0';
4645 if (truncating
== 0 || c
== '\n')
4646 shell_input_line
[i
++] = c
;
4650 shell_input_line
[--i
] = '\0';
4651 current_command_line_count
++;
4656 shell_input_line_index
= 0;
4657 shell_input_line_len
= i
; /* == strlen (shell_input_line) */
4659 set_line_mbstate ();
4661 #if defined (HISTORY)
4662 if (remember_on_history
&& shell_input_line
&& shell_input_line
[0])
4665 # if defined (BANG_HISTORY)
4668 /* If the current delimiter is a single quote, we should not be
4669 performing history expansion, even if we're on a different
4670 line from the original single quote. */
4671 old_hist
= history_expansion_inhibited
;
4672 if (current_delimiter (dstack
) == '\'')
4673 history_expansion_inhibited
= 1;
4675 expansions
= pre_process_line (shell_input_line
, 1, 1);
4676 # if defined (BANG_HISTORY)
4677 history_expansion_inhibited
= old_hist
;
4679 if (expansions
!= shell_input_line
)
4681 free (shell_input_line
);
4682 shell_input_line
= expansions
;
4683 shell_input_line_len
= shell_input_line
?
4684 strlen (shell_input_line
) : 0;
4685 if (shell_input_line_len
== 0)
4686 current_command_line_count
--;
4688 /* We have to force the xrealloc below because we don't know
4689 the true allocated size of shell_input_line anymore. */
4690 shell_input_line_size
= shell_input_line_len
;
4692 set_line_mbstate ();
4695 /* Try to do something intelligent with blank lines encountered while
4696 entering multi-line commands. XXX - this is grotesque */
4697 else if (remember_on_history
&& shell_input_line
&&
4698 shell_input_line
[0] == '\0' &&
4699 current_command_line_count
> 1)
4701 if (current_delimiter (dstack
))
4702 /* We know shell_input_line[0] == 0 and we're reading some sort of
4703 quoted string. This means we've got a line consisting of only
4704 a newline in a quoted string. We want to make sure this line
4705 gets added to the history. */
4706 maybe_add_history (shell_input_line
);
4710 hdcs
= history_delimiting_chars (shell_input_line
);
4711 if (hdcs
&& hdcs
[0] == ';')
4712 maybe_add_history (shell_input_line
);
4716 #endif /* HISTORY */
4718 if (shell_input_line
)
4720 /* Lines that signify the end of the shell's input should not be
4721 echoed. We should not echo lines while parsing command
4722 substitutions with recursive calls into the parsing engine; those
4723 should only be echoed once when we read the word. That is the
4724 reason for the test against shell_eof_token, which is set to a
4725 right paren when parsing the contents of command substitutions. */
4726 if (echo_input_at_read
&& (shell_input_line
[0] ||
4727 shell_input_line_terminator
!= EOF
) &&
4728 shell_eof_token
== 0)
4729 fprintf (stderr
, "%s\n", shell_input_line
);
4733 shell_input_line_size
= 0;
4734 prompt_string_pointer
= ¤t_prompt_string
;
4735 if (SHOULD_PROMPT ())
4740 /* Add the newline to the end of this string, iff the string does
4741 not already end in an EOF character. */
4742 if (shell_input_line_terminator
!= EOF
)
4744 if (shell_input_line_size
< SIZE_MAX
-3 && (shell_input_line_len
+3 > shell_input_line_size
))
4745 shell_input_line
= (char *)xrealloc (shell_input_line
,
4746 1 + (shell_input_line_size
+= 2));
4748 shell_input_line
[shell_input_line_len
] = '\n';
4749 shell_input_line
[shell_input_line_len
+ 1] = '\0';
4751 set_line_mbstate ();
4756 uc
= shell_input_line
[shell_input_line_index
];
4759 shell_input_line_index
++;
4761 #if defined (ALIAS) || defined (DPAREN_ARITHMETIC)
4762 /* If UC is NULL, we have reached the end of the current input string. If
4763 pushed_string_list is non-empty, it's time to pop to the previous string
4764 because we have fully consumed the result of the last alias expansion.
4765 Do it transparently; just return the next character of the string popped
4767 /* If pushed_string_list != 0 but pushed_string_list->expander == 0 (not
4768 currently tested) and the flags value is not PSH_SOURCE, we are not
4769 parsing an alias, we have just saved one (push_string, when called by
4770 the parse_dparen code) In this case, just go on as well. The PSH_SOURCE
4771 case is handled below. */
4773 if (uc
== 0 && pushed_string_list
&& pushed_string_list
->flags
!= PSH_SOURCE
)
4776 uc
= shell_input_line
[shell_input_line_index
];
4778 shell_input_line_index
++;
4780 #endif /* ALIAS || DPAREN_ARITHMETIC */
4782 if MBTEST(uc
== '\\' && remove_quoted_newline
&& shell_input_line
[shell_input_line_index
] == '\n')
4784 if (SHOULD_PROMPT ())
4787 /* What do we do here if we're expanding an alias whose definition
4788 includes an escaped newline? If that's the last character in the
4789 alias expansion, we just pop the pushed string list (recall that
4790 we inhibit the appending of a space in mk_alexpansion() if newline
4791 is the last character). If it's not the last character, we need
4792 to consume the quoted newline and move to the next character in
4795 if (expanding_alias () && shell_input_line
[shell_input_line_index
+1] == '\0')
4800 else if (expanding_alias () && shell_input_line
[shell_input_line_index
+1] != '\0')
4802 shell_input_line_index
++; /* skip newline */
4803 goto next_alias_char
; /* and get next character */
4810 if (uc
== 0 && shell_input_line_terminator
== EOF
)
4811 return ((shell_input_line_index
!= 0) ? '\n' : EOF
);
4813 #if defined (ALIAS) || defined (DPAREN_ARITHMETIC)
4814 /* We already know that we are not parsing an alias expansion because of the
4815 check for expanding_alias() above. This knows how parse_and_execute
4816 handles switching to st_string input while an alias is being expanded,
4817 hence the check for pushed_string_list without pushed_string_list->expander
4818 and the check for PSH_SOURCE as pushed_string_list->flags.
4819 parse_and_execute and parse_string both change the input type to st_string
4820 and place the string to be parsed and executed into location.string, so
4821 we should not stop reading that until the pointer is '\0'.
4822 The check for shell_input_line_terminator may be superfluous.
4824 This solves the problem of `.' inside a multi-line alias with embedded
4825 newlines executing things out of order. */
4826 if (uc
== 0 && bash_input
.type
== st_string
&& *bash_input
.location
.string
&&
4827 pushed_string_list
&& pushed_string_list
->flags
== PSH_SOURCE
&&
4828 shell_input_line_terminator
== 0)
4830 shell_input_line_index
= 0;
4838 /* Put C back into the input for the shell. This might need changes for
4839 HANDLE_MULTIBYTE around EOLs. Since we (currently) never push back a
4840 character different than we read, shell_input_line_property doesn't need
4841 to change when manipulating shell_input_line. The define for
4842 last_shell_getc_is_singlebyte should take care of it, though. */
4847 if (shell_input_line
&& shell_input_line_index
)
4848 shell_input_line
[--shell_input_line_index
] = c
;
4850 eol_ungetc_lookahead
= c
;
4853 #ifdef INCLUDE_UNUSED
4854 /* Back the input pointer up by one, effectively `ungetting' a character. */
4858 if (shell_input_line
&& shell_input_line_index
)
4859 shell_input_line_index
--;
4863 /* Discard input until CHARACTER is seen, then push that character back
4864 onto the input stream. */
4866 discard_until (character
)
4871 while ((c
= shell_getc (0)) != EOF
&& c
!= character
)
4879 execute_variable_command (command
, vname
)
4880 char *command
, *vname
;
4883 sh_parser_state_t ps
;
4885 save_parser_state (&ps
);
4886 last_lastarg
= get_string_value ("_");
4888 last_lastarg
= savestring (last_lastarg
);
4890 parse_and_execute (savestring (command
), vname
, SEVAL_NONINT
|SEVAL_NOHIST
);
4892 restore_parser_state (&ps
);
4893 bind_variable ("_", last_lastarg
, 0);
4894 FREE (last_lastarg
);
4896 if (token_to_read
== '\n') /* reset_parser was called */
4900 /* Place to remember the token. We try to keep the buffer
4901 at a reasonable size, but it can grow. */
4902 static char *token
= (char *)NULL
;
4904 /* Current size of the token buffer. */
4905 static int token_buffer_size
;
4907 /* Command to read_token () explaining what we want it to do. */
4910 #define prompt_is_ps1 \
4911 (!prompt_string_pointer || prompt_string_pointer == &ps1_prompt)
4913 /* Function for yyparse to call. yylex keeps track of
4914 the last two tokens read, and calls read_token. */
4918 if (interactive
&& (current_token
== 0 || current_token
== '\n'))
4920 /* Before we print a prompt, we might have to check mailboxes.
4921 We do this only if it is time to do so. Notice that only here
4922 is the mail alarm reset; nothing takes place in check_mail ()
4923 except the checking of mail. Please don't change this. */
4924 if (prompt_is_ps1
&& parse_and_execute_level
== 0 && time_to_check_mail ())
4927 reset_mail_timer ();
4930 /* Avoid printing a prompt if we're not going to read anything, e.g.
4931 after resetting the parser with read_token (RESET). */
4932 if (token_to_read
== 0 && SHOULD_PROMPT ())
4936 two_tokens_ago
= token_before_that
;
4937 token_before_that
= last_read_token
;
4938 last_read_token
= current_token
;
4939 current_token
= read_token (READ
);
4941 if ((parser_state
& PST_EOFTOKEN
) && current_token
== shell_eof_token
)
4943 current_token
= yacc_EOF
;
4944 if (bash_input
.type
== st_string
)
4945 rewind_input_string ();
4947 parser_state
&= ~PST_EOFTOKEN
;
4949 return (current_token
);
4952 /* When non-zero, we have read the required tokens
4953 which allow ESAC to be the next one read. */
4954 static int esacs_needed_count
;
4960 if (need_here_doc
>= HEREDOC_MAX
)
4962 last_command_exit_value
= EX_BADUSAGE
;
4964 report_syntax_error (_("maximum here-document count exceeded"));
4966 exit_shell (last_command_exit_value
);
4968 redir_stack
[need_here_doc
++] = r
;
4972 gather_here_documents ()
4977 while (need_here_doc
> 0)
4979 parser_state
|= PST_HEREDOC
;
4980 make_here_document (redir_stack
[r
++], line_number
);
4981 parser_state
&= ~PST_HEREDOC
;
4986 /* When non-zero, an open-brace used to create a group is awaiting a close
4988 static int open_brace_count
;
4990 #define command_token_position(token) \
4991 (((token) == ASSIGNMENT_WORD) || (parser_state&PST_REDIRLIST) || \
4992 ((token) != SEMI_SEMI && (token) != SEMI_AND && (token) != SEMI_SEMI_AND && reserved_word_acceptable(token)))
4994 #define assignment_acceptable(token) \
4995 (command_token_position(token) && ((parser_state & PST_CASEPAT) == 0))
4997 /* Check to see if TOKEN is a reserved word and return the token
4999 #define CHECK_FOR_RESERVED_WORD(tok) \
5001 if (!dollar_present && !quoted && \
5002 reserved_word_acceptable (last_read_token)) \
5005 for (i = 0; word_token_alist[i].word != (char *)NULL; i++) \
5006 if (STREQ (tok, word_token_alist[i].word)) \
5008 if ((parser_state & PST_CASEPAT) && (word_token_alist[i].token != ESAC)) \
5010 if (word_token_alist[i].token == TIME && time_command_acceptable () == 0) \
5012 if (word_token_alist[i].token == ESAC) \
5013 parser_state &= ~(PST_CASEPAT|PST_CASESTMT); \
5014 else if (word_token_alist[i].token == CASE) \
5015 parser_state |= PST_CASESTMT; \
5016 else if (word_token_alist[i].token == COND_END) \
5017 parser_state &= ~(PST_CONDCMD|PST_CONDEXPR); \
5018 else if (word_token_alist[i].token == COND_START) \
5019 parser_state |= PST_CONDCMD; \
5020 else if (word_token_alist[i].token == '{') \
5021 open_brace_count++; \
5022 else if (word_token_alist[i].token == '}' && open_brace_count) \
5023 open_brace_count--; \
5024 return (word_token_alist[i].token); \
5031 /* OK, we have a token. Let's try to alias expand it, if (and only if)
5034 It is eligible for expansion if EXPAND_ALIASES is set, and
5035 the token is unquoted and the last token read was a command
5036 separator (or expand_next_token is set), and we are currently
5037 processing an alias (pushed_string_list is non-empty) and this
5038 token is not the same as the current or any previously
5041 Special cases that disqualify:
5042 In a pattern list in a case statement (parser_state & PST_CASEPAT). */
5052 r
= xmalloc (l
+ 2);
5054 /* If the last character in the alias is a newline, don't add a trailing
5055 space to the expansion. Works with shell_getc above. */
5056 if (r
[l
- 1] != ' ' && r
[l
- 1] != '\n')
5063 alias_expand_token (tokstr
)
5069 if (((parser_state
& PST_ALEXPNEXT
) || command_token_position (last_read_token
)) &&
5070 (parser_state
& PST_CASEPAT
) == 0)
5072 ap
= find_alias (tokstr
);
5074 /* Currently expanding this token. */
5075 if (ap
&& (ap
->flags
& AL_BEINGEXPANDED
))
5076 return (NO_EXPANSION
);
5078 /* mk_alexpansion puts an extra space on the end of the alias expansion,
5079 so the lookahead by the parser works right. If this gets changed,
5080 make sure the code in shell_getc that deals with reaching the end of
5081 an expanded alias is changed with it. */
5082 expanded
= ap
? mk_alexpansion (ap
->value
) : (char *)NULL
;
5086 push_string (expanded
, ap
->flags
& AL_EXPANDNEXT
, ap
);
5087 return (RE_READ_TOKEN
);
5090 /* This is an eligible token that does not have an expansion. */
5091 return (NO_EXPANSION
);
5093 return (NO_EXPANSION
);
5098 time_command_acceptable ()
5100 #if defined (COMMAND_TIMING)
5103 if (posixly_correct
&& shell_compatibility_level
> 41)
5105 /* Quick check of the rest of the line to find the next token. If it
5106 begins with a `-', Posix says to not return `time' as the token.
5107 This was interp 267. */
5108 i
= shell_input_line_index
;
5109 while (i
< shell_input_line_len
&& (shell_input_line
[i
] == ' ' || shell_input_line
[i
] == '\t'))
5111 if (shell_input_line
[i
] == '-')
5115 switch (last_read_token
)
5128 case BANG
: /* ! time pipeline */
5129 case TIME
: /* time time pipeline */
5130 case TIMEOPT
: /* time -p time pipeline */
5131 case TIMEIGN
: /* time -p -- ... */
5138 #endif /* COMMAND_TIMING */
5141 /* Handle special cases of token recognition:
5142 IN is recognized if the last token was WORD and the token
5143 before that was FOR or CASE or SELECT.
5145 DO is recognized if the last token was WORD and the token
5146 before that was FOR or SELECT.
5148 ESAC is recognized if the last token caused `esacs_needed_count'
5151 `{' is recognized if the last token as WORD and the token
5152 before that was FUNCTION, or if we just parsed an arithmetic
5155 `}' is recognized if there is an unclosed `{' present.
5157 `-p' is returned as TIMEOPT if the last read token was TIME.
5158 `--' is returned as TIMEIGN if the last read token was TIMEOPT.
5160 ']]' is returned as COND_END if the parser is currently parsing
5161 a conditional expression ((parser_state & PST_CONDEXPR) != 0)
5163 `time' is returned as TIME if and only if it is immediately
5164 preceded by one of `;', `\n', `||', `&&', or `&'.
5168 special_case_tokens (tokstr
)
5171 if ((last_read_token
== WORD
) &&
5172 #if defined (SELECT_COMMAND)
5173 ((token_before_that
== FOR
) || (token_before_that
== CASE
) || (token_before_that
== SELECT
)) &&
5175 ((token_before_that
== FOR
) || (token_before_that
== CASE
)) &&
5177 (tokstr
[0] == 'i' && tokstr
[1] == 'n' && tokstr
[2] == 0))
5179 if (token_before_that
== CASE
)
5181 parser_state
|= PST_CASEPAT
;
5182 esacs_needed_count
++;
5187 if (last_read_token
== WORD
&&
5188 #if defined (SELECT_COMMAND)
5189 (token_before_that
== FOR
|| token_before_that
== SELECT
) &&
5191 (token_before_that
== FOR
) &&
5193 (tokstr
[0] == 'd' && tokstr
[1] == 'o' && tokstr
[2] == '\0'))
5196 /* Ditto for ESAC in the CASE case.
5197 Specifically, this handles "case word in esac", which is a legal
5198 construct, certainly because someone will pass an empty arg to the
5199 case construct, and we don't want it to barf. Of course, we should
5200 insist that the case construct has at least one pattern in it, but
5201 the designers disagree. */
5202 if (esacs_needed_count
)
5204 esacs_needed_count
--;
5205 if (STREQ (tokstr
, "esac"))
5207 parser_state
&= ~PST_CASEPAT
;
5212 /* The start of a shell function definition. */
5213 if (parser_state
& PST_ALLOWOPNBRC
)
5215 parser_state
&= ~PST_ALLOWOPNBRC
;
5216 if (tokstr
[0] == '{' && tokstr
[1] == '\0') /* } */
5219 function_bstart
= line_number
;
5220 return ('{'); /* } */
5224 /* We allow a `do' after a for ((...)) without an intervening
5226 if (last_read_token
== ARITH_FOR_EXPRS
&& tokstr
[0] == 'd' && tokstr
[1] == 'o' && !tokstr
[2])
5228 if (last_read_token
== ARITH_FOR_EXPRS
&& tokstr
[0] == '{' && tokstr
[1] == '\0') /* } */
5231 return ('{'); /* } */
5234 if (open_brace_count
&& reserved_word_acceptable (last_read_token
) && tokstr
[0] == '}' && !tokstr
[1])
5236 open_brace_count
--; /* { */
5240 #if defined (COMMAND_TIMING)
5241 /* Handle -p after `time'. */
5242 if (last_read_token
== TIME
&& tokstr
[0] == '-' && tokstr
[1] == 'p' && !tokstr
[2])
5244 /* Handle -- after `time -p'. */
5245 if (last_read_token
== TIMEOPT
&& tokstr
[0] == '-' && tokstr
[1] == '-' && !tokstr
[2])
5249 #if defined (COND_COMMAND) /* [[ */
5250 if ((parser_state
& PST_CONDEXPR
) && tokstr
[0] == ']' && tokstr
[1] == ']' && tokstr
[2] == '\0')
5257 /* Called from shell.c when Control-C is typed at top level. Or
5258 by the error rule at top level. */
5262 dstack
.delimiter_depth
= 0; /* No delimiters found so far. */
5263 open_brace_count
= 0;
5265 #if defined (EXTENDED_GLOB)
5266 /* Reset to global value of extended glob */
5267 if (parser_state
& PST_EXTPAT
)
5268 extended_glob
= global_extglob
;
5273 #if defined (ALIAS) || defined (DPAREN_ARITHMETIC)
5274 if (pushed_string_list
)
5275 free_string_list ();
5276 #endif /* ALIAS || DPAREN_ARITHMETIC */
5278 if (shell_input_line
)
5280 free (shell_input_line
);
5281 shell_input_line
= (char *)NULL
;
5282 shell_input_line_size
= shell_input_line_index
= 0;
5285 FREE (word_desc_to_read
);
5286 word_desc_to_read
= (WORD_DESC
*)NULL
;
5288 eol_ungetc_lookahead
= 0;
5290 current_token
= '\n'; /* XXX */
5291 last_read_token
= '\n';
5292 token_to_read
= '\n';
5295 /* Read the next token. Command can be READ (normal operation) or
5296 RESET (to normalize state). */
5298 read_token (command
)
5301 int character
; /* Current character. */
5302 int peek_char
; /* Temporary look-ahead character. */
5303 int result
; /* The thing to return. */
5305 if (command
== RESET
)
5313 result
= token_to_read
;
5314 if (token_to_read
== WORD
|| token_to_read
== ASSIGNMENT_WORD
)
5316 yylval
.word
= word_desc_to_read
;
5317 word_desc_to_read
= (WORD_DESC
*)NULL
;
5323 #if defined (COND_COMMAND)
5324 if ((parser_state
& (PST_CONDCMD
|PST_CONDEXPR
)) == PST_CONDCMD
)
5326 cond_lineno
= line_number
;
5327 parser_state
|= PST_CONDEXPR
;
5328 yylval
.command
= parse_cond_command ();
5329 if (cond_token
!= COND_END
)
5334 token_to_read
= COND_END
;
5335 parser_state
&= ~(PST_CONDEXPR
|PST_CONDCMD
);
5341 /* This is a place to jump back to once we have successfully expanded a
5342 token with an alias and pushed the string with push_string () */
5346 /* Read a single word from input. Start by skipping blanks. */
5347 while ((character
= shell_getc (1)) != EOF
&& shellblank (character
))
5350 if (character
== EOF
)
5356 if MBTEST(character
== '#' && (!interactive
|| interactive_comments
))
5358 /* A comment. Discard until EOL or EOF, and then return a newline. */
5359 discard_until ('\n');
5361 character
= '\n'; /* this will take the next if statement and return. */
5364 if (character
== '\n')
5366 /* If we're about to return an unquoted newline, we can go and collect
5367 the text of any pending here document. */
5369 gather_here_documents ();
5372 parser_state
&= ~PST_ALEXPNEXT
;
5375 parser_state
&= ~PST_ASSIGNOK
;
5380 if (parser_state
& PST_REGEXP
)
5383 /* Shell meta-characters. */
5384 if MBTEST(shellmeta (character
) && ((parser_state
& PST_DBLPAREN
) == 0))
5387 /* Turn off alias tokenization iff this character sequence would
5388 not leave us ready to read a command. */
5389 if (character
== '<' || character
== '>')
5390 parser_state
&= ~PST_ALEXPNEXT
;
5393 parser_state
&= ~PST_ASSIGNOK
;
5395 peek_char
= shell_getc (1);
5396 if (character
== peek_char
)
5401 /* If '<' then we could be at "<<" or at "<<-". We have to
5402 look ahead one more character. */
5403 peek_char
= shell_getc (1);
5404 if MBTEST(peek_char
== '-')
5405 return (LESS_LESS_MINUS
);
5406 else if MBTEST(peek_char
== '<')
5407 return (LESS_LESS_LESS
);
5410 shell_ungetc (peek_char
);
5415 return (GREATER_GREATER
);
5418 parser_state
|= PST_CASEPAT
;
5420 parser_state
&= ~PST_ALEXPNEXT
;
5423 peek_char
= shell_getc (1);
5424 if MBTEST(peek_char
== '&')
5425 return (SEMI_SEMI_AND
);
5428 shell_ungetc (peek_char
);
5438 #if defined (DPAREN_ARITHMETIC) || defined (ARITH_FOR_COMMAND)
5440 result
= parse_dparen (character
);
5448 else if MBTEST(character
== '<' && peek_char
== '&')
5450 else if MBTEST(character
== '>' && peek_char
== '&')
5451 return (GREATER_AND
);
5452 else if MBTEST(character
== '<' && peek_char
== '>')
5453 return (LESS_GREATER
);
5454 else if MBTEST(character
== '>' && peek_char
== '|')
5455 return (GREATER_BAR
);
5456 else if MBTEST(character
== '&' && peek_char
== '>')
5458 peek_char
= shell_getc (1);
5459 if MBTEST(peek_char
== '>')
5460 return (AND_GREATER_GREATER
);
5463 shell_ungetc (peek_char
);
5464 return (AND_GREATER
);
5467 else if MBTEST(character
== '|' && peek_char
== '&')
5469 else if MBTEST(character
== ';' && peek_char
== '&')
5471 parser_state
|= PST_CASEPAT
;
5473 parser_state
&= ~PST_ALEXPNEXT
;
5478 shell_ungetc (peek_char
);
5480 /* If we look like we are reading the start of a function
5481 definition, then let the reader know about it so that
5482 we will do the right thing with `{'. */
5483 if MBTEST(character
== ')' && last_read_token
== '(' && token_before_that
== WORD
)
5485 parser_state
|= PST_ALLOWOPNBRC
;
5487 parser_state
&= ~PST_ALEXPNEXT
;
5489 function_dstart
= line_number
;
5492 /* case pattern lists may be preceded by an optional left paren. If
5493 we're not trying to parse a case pattern list, the left paren
5494 indicates a subshell. */
5495 if MBTEST(character
== '(' && (parser_state
& PST_CASEPAT
) == 0) /* ) */
5496 parser_state
|= PST_SUBSHELL
;
5498 else if MBTEST((parser_state
& PST_CASEPAT
) && character
== ')')
5499 parser_state
&= ~PST_CASEPAT
;
5501 else if MBTEST((parser_state
& PST_SUBSHELL
) && character
== ')')
5502 parser_state
&= ~PST_SUBSHELL
;
5504 #if defined (PROCESS_SUBSTITUTION)
5505 /* Check for the constructs which introduce process substitution.
5506 Shells running in `posix mode' don't do process substitution. */
5507 if MBTEST(posixly_correct
|| ((character
!= '>' && character
!= '<') || peek_char
!= '(')) /*)*/
5508 #endif /* PROCESS_SUBSTITUTION */
5512 /* Hack <&- (close stdin) case. Also <&N- (dup and close). */
5513 if MBTEST(character
== '-' && (last_read_token
== LESS_AND
|| last_read_token
== GREATER_AND
))
5517 /* Okay, if we got this far, we have to read a word. Read one,
5518 and then check it against the known ones. */
5519 result
= read_token_word (character
);
5521 if (result
== RE_READ_TOKEN
)
5528 * Match a $(...) or other grouping construct. This has to handle embedded
5529 * quoted strings ('', ``, "") and nested constructs. It also must handle
5530 * reprompting the user, if necessary, after reading a newline, and returning
5531 * correct error values if it reads EOF.
5533 #define P_FIRSTCLOSE 0x0001
5534 #define P_ALLOWESC 0x0002
5535 #define P_DQUOTE 0x0004
5536 #define P_COMMAND 0x0008 /* parsing a command, so look for comments */
5537 #define P_BACKQUOTE 0x0010 /* parsing a backquoted command substitution */
5538 #define P_ARRAYSUB 0x0020 /* parsing a [...] array subscript for assignment */
5539 #define P_DOLBRACE 0x0040 /* parsing a ${...} construct */
5541 /* Lexical state while parsing a grouping construct or $(...). */
5542 #define LEX_WASDOL 0x001
5543 #define LEX_CKCOMMENT 0x002
5544 #define LEX_INCOMMENT 0x004
5545 #define LEX_PASSNEXT 0x008
5546 #define LEX_RESWDOK 0x010
5547 #define LEX_CKCASE 0x020
5548 #define LEX_INCASE 0x040
5549 #define LEX_INHEREDOC 0x080
5550 #define LEX_HEREDELIM 0x100 /* reading here-doc delimiter */
5551 #define LEX_STRIPDOC 0x200 /* <<- strip tabs from here doc delim */
5552 #define LEX_INWORD 0x400
5554 #define COMSUB_META(ch) ((ch) == ';' || (ch) == '&' || (ch) == '|')
5556 #define CHECK_NESTRET_ERROR() \
5558 if (nestret == &matched_pair_error) \
5561 return &matched_pair_error; \
5565 #define APPEND_NESTRET() \
5569 RESIZE_MALLOCED_BUFFER (ret, retind, nestlen, retsize, 64); \
5570 strcpy (ret + retind, nestret); \
5571 retind += nestlen; \
5575 static char matched_pair_error
;
5578 parse_matched_pair (qc
, open
, close
, lenp
, flags
)
5579 int qc
; /* `"' if this construct is within double quotes */
5583 int count
, ch
, tflags
;
5584 int nestlen
, ttranslen
, start_lineno
;
5585 char *ret
, *nestret
, *ttrans
;
5586 int retind
, retsize
, rflags
;
5589 dolbrace_state
= (flags
& P_DOLBRACE
) ? DOLBRACE_PARAM
: 0;
5591 /*itrace("parse_matched_pair[%d]: open = %c close = %c flags = %d", line_number, open, close, flags);*/
5595 if ((flags
& P_COMMAND
) && qc
!= '`' && qc
!= '\'' && qc
!= '"' && (flags
& P_DQUOTE
) == 0)
5596 tflags
|= LEX_CKCOMMENT
;
5598 /* RFLAGS is the set of flags we want to pass to recursive calls. */
5599 rflags
= (qc
== '"') ? P_DQUOTE
: (flags
& P_DQUOTE
);
5601 ret
= (char *)xmalloc (retsize
= 64);
5604 start_lineno
= line_number
;
5607 ch
= shell_getc (qc
!= '\'' && (tflags
& (LEX_PASSNEXT
)) == 0);
5612 parser_error (start_lineno
, _("unexpected EOF while looking for matching `%c'"), close
);
5613 EOF_Reached
= 1; /* XXX */
5614 return (&matched_pair_error
);
5617 /* Possible reprompting. */
5618 if (ch
== '\n' && SHOULD_PROMPT ())
5621 /* Don't bother counting parens or doing anything else if in a comment
5622 or part of a case statement */
5623 if (tflags
& LEX_INCOMMENT
)
5625 /* Add this character. */
5626 RESIZE_MALLOCED_BUFFER (ret
, retind
, 1, retsize
, 64);
5630 tflags
&= ~LEX_INCOMMENT
;
5635 /* Not exactly right yet, should handle shell metacharacters, too. If
5636 any changes are made to this test, make analogous changes to subst.c:
5637 extract_delimited_string(). */
5638 else if MBTEST((tflags
& LEX_CKCOMMENT
) && (tflags
& LEX_INCOMMENT
) == 0 && ch
== '#' && (retind
== 0 || ret
[retind
-1] == '\n' || shellblank (ret
[retind
- 1])))
5639 tflags
|= LEX_INCOMMENT
;
5641 if (tflags
& LEX_PASSNEXT
) /* last char was backslash */
5643 tflags
&= ~LEX_PASSNEXT
;
5644 if (qc
!= '\'' && ch
== '\n') /* double-quoted \<newline> disappears. */
5647 retind
--; /* swallow previously-added backslash */
5651 RESIZE_MALLOCED_BUFFER (ret
, retind
, 2, retsize
, 64);
5652 if MBTEST(ch
== CTLESC
)
5653 ret
[retind
++] = CTLESC
;
5657 /* If we're reparsing the input (e.g., from parse_string_to_word_list),
5658 we've already prepended CTLESC to single-quoted results of $'...'.
5659 We may want to do this for other CTLESC-quoted characters in
5661 else if MBTEST((parser_state
& PST_REPARSE
) && open
== '\'' && (ch
== CTLESC
|| ch
== CTLNUL
))
5663 RESIZE_MALLOCED_BUFFER (ret
, retind
, 1, retsize
, 64);
5667 else if MBTEST(ch
== CTLESC
|| ch
== CTLNUL
) /* special shell escapes */
5669 RESIZE_MALLOCED_BUFFER (ret
, retind
, 2, retsize
, 64);
5670 ret
[retind
++] = CTLESC
;
5674 else if MBTEST(ch
== close
) /* ending delimiter */
5676 /* handle nested ${...} specially. */
5677 else if MBTEST(open
!= close
&& (tflags
& LEX_WASDOL
) && open
== '{' && ch
== open
) /* } */
5679 else if MBTEST(((flags
& P_FIRSTCLOSE
) == 0) && ch
== open
) /* nested begin */
5682 /* Add this character. */
5683 RESIZE_MALLOCED_BUFFER (ret
, retind
, 1, retsize
, 64);
5686 /* If we just read the ending character, don't bother continuing. */
5690 if (open
== '\'') /* '' inside grouping construct */
5692 if MBTEST((flags
& P_ALLOWESC
) && ch
== '\\')
5693 tflags
|= LEX_PASSNEXT
;
5697 if MBTEST(ch
== '\\') /* backslashes */
5698 tflags
|= LEX_PASSNEXT
;
5700 /* Based on which dolstate is currently in (param, op, or word),
5701 decide what the op is. We're really only concerned if it's % or
5702 #, so we can turn on a flag that says whether or not we should
5703 treat single quotes as special when inside a double-quoted
5704 ${...}. This logic must agree with subst.c:extract_dollar_brace_string
5705 since they share the same defines. */
5706 /* FLAG POSIX INTERP 221 */
5707 if (flags
& P_DOLBRACE
)
5709 /* ${param%[%]word} */
5710 if MBTEST(dolbrace_state
== DOLBRACE_PARAM
&& ch
== '%' && retind
> 1)
5711 dolbrace_state
= DOLBRACE_QUOTE
;
5712 /* ${param#[#]word} */
5713 else if MBTEST(dolbrace_state
== DOLBRACE_PARAM
&& ch
== '#' && retind
> 1)
5714 dolbrace_state
= DOLBRACE_QUOTE
;
5715 /* ${param/[/]pat/rep} */
5716 else if MBTEST(dolbrace_state
== DOLBRACE_PARAM
&& ch
== '/' && retind
> 1)
5717 dolbrace_state
= DOLBRACE_QUOTE2
; /* XXX */
5718 /* ${param^[^]pat} */
5719 else if MBTEST(dolbrace_state
== DOLBRACE_PARAM
&& ch
== '^' && retind
> 1)
5720 dolbrace_state
= DOLBRACE_QUOTE
;
5721 /* ${param,[,]pat} */
5722 else if MBTEST(dolbrace_state
== DOLBRACE_PARAM
&& ch
== ',' && retind
> 1)
5723 dolbrace_state
= DOLBRACE_QUOTE
;
5724 else if MBTEST(dolbrace_state
== DOLBRACE_PARAM
&& strchr ("#%^,~:-=?+/", ch
) != 0)
5725 dolbrace_state
= DOLBRACE_OP
;
5726 else if MBTEST(dolbrace_state
== DOLBRACE_OP
&& strchr ("#%^,~:-=?+/", ch
) == 0)
5727 dolbrace_state
= DOLBRACE_WORD
;
5730 /* The big hammer. Single quotes aren't special in double quotes. The
5731 problem is that Posix used to say the single quotes are semi-special:
5732 within a double-quoted ${...} construct "an even number of
5733 unescaped double-quotes or single-quotes, if any, shall occur." */
5734 /* This was changed in Austin Group Interp 221 */
5735 if MBTEST(posixly_correct
&& shell_compatibility_level
> 41 && dolbrace_state
!= DOLBRACE_QUOTE
&& dolbrace_state
!= DOLBRACE_QUOTE2
&& (flags
& P_DQUOTE
) && (flags
& P_DOLBRACE
) && ch
== '\'')
5738 /* Could also check open == '`' if we want to parse grouping constructs
5739 inside old-style command substitution. */
5740 if (open
!= close
) /* a grouping construct */
5742 if MBTEST(shellquote (ch
))
5744 /* '', ``, or "" inside $(...) or other grouping construct. */
5745 push_delimiter (dstack
, ch
);
5746 if MBTEST((tflags
& LEX_WASDOL
) && ch
== '\'') /* $'...' inside group */
5747 nestret
= parse_matched_pair (ch
, ch
, ch
, &nestlen
, P_ALLOWESC
|rflags
);
5749 nestret
= parse_matched_pair (ch
, ch
, ch
, &nestlen
, rflags
);
5750 pop_delimiter (dstack
);
5751 CHECK_NESTRET_ERROR ();
5753 if MBTEST((tflags
& LEX_WASDOL
) && ch
== '\'' && (extended_quote
|| (rflags
& P_DQUOTE
) == 0))
5755 /* Translate $'...' here. */
5756 ttrans
= ansiexpand (nestret
, 0, nestlen
- 1, &ttranslen
);
5759 /* If we're parsing a double-quoted brace expansion and we are
5760 not in a place where single quotes are treated specially,
5761 make sure we single-quote the results of the ansi
5762 expansion because quote removal should remove them later */
5763 /* FLAG POSIX INTERP 221 */
5764 if ((shell_compatibility_level
> 42) && (rflags
& P_DQUOTE
) && (dolbrace_state
== DOLBRACE_QUOTE2
) && (flags
& P_DOLBRACE
))
5766 nestret
= sh_single_quote (ttrans
);
5768 nestlen
= strlen (nestret
);
5770 else if ((rflags
& P_DQUOTE
) == 0)
5772 nestret
= sh_single_quote (ttrans
);
5774 nestlen
= strlen (nestret
);
5779 nestlen
= ttranslen
;
5781 retind
-= 2; /* back up before the $' */
5783 else if MBTEST((tflags
& LEX_WASDOL
) && ch
== '"' && (extended_quote
|| (rflags
& P_DQUOTE
) == 0))
5785 /* Locale expand $"..." here. */
5786 ttrans
= localeexpand (nestret
, 0, nestlen
- 1, start_lineno
, &ttranslen
);
5789 nestret
= sh_mkdoublequoted (ttrans
, ttranslen
, 0);
5791 nestlen
= ttranslen
+ 2;
5792 retind
-= 2; /* back up before the $" */
5798 else if ((flags
& P_ARRAYSUB
) && (tflags
& LEX_WASDOL
) && (ch
== '(' || ch
== '{' || ch
== '[')) /* ) } ] */
5799 goto parse_dollar_word
;
5801 /* Parse an old-style command substitution within double quotes as a
5803 /* XXX - sh and ksh93 don't do this - XXX */
5804 else if MBTEST(open
== '"' && ch
== '`')
5806 nestret
= parse_matched_pair (0, '`', '`', &nestlen
, rflags
);
5808 CHECK_NESTRET_ERROR ();
5813 else if MBTEST(open
!= '`' && (tflags
& LEX_WASDOL
) && (ch
== '(' || ch
== '{' || ch
== '[')) /* ) } ] */
5814 /* check for $(), $[], or ${} inside quoted string. */
5817 if (open
== ch
) /* undo previous increment */
5819 if (ch
== '(') /* ) */
5820 nestret
= parse_comsub (0, '(', ')', &nestlen
, (rflags
|P_COMMAND
) & ~P_DQUOTE
);
5821 else if (ch
== '{') /* } */
5822 nestret
= parse_matched_pair (0, '{', '}', &nestlen
, P_FIRSTCLOSE
|P_DOLBRACE
|rflags
);
5823 else if (ch
== '[') /* ] */
5824 nestret
= parse_matched_pair (0, '[', ']', &nestlen
, rflags
);
5826 CHECK_NESTRET_ERROR ();
5831 if MBTEST(ch
== '$')
5832 tflags
|= LEX_WASDOL
;
5834 tflags
&= ~LEX_WASDOL
;
5840 /*itrace("parse_matched_pair[%d]: returning %s", line_number, ret);*/
5844 /* Parse a $(...) command substitution. This is messier than I'd like, and
5845 reproduces a lot more of the token-reading code than I'd like. */
5847 parse_comsub (qc
, open
, close
, lenp
, flags
)
5848 int qc
; /* `"' if this construct is within double quotes */
5852 int count
, ch
, peekc
, tflags
, lex_rwlen
, lex_wlen
, lex_firstind
;
5853 int nestlen
, ttranslen
, start_lineno
;
5854 char *ret
, *nestret
, *ttrans
, *heredelim
;
5855 int retind
, retsize
, rflags
, hdlen
;
5857 /* Posix interp 217 says arithmetic expressions have precedence, so
5858 assume $(( introduces arithmetic expansion and parse accordingly. */
5859 peekc
= shell_getc (0);
5860 shell_ungetc (peekc
);
5862 return (parse_matched_pair (qc
, open
, close
, lenp
, 0));
5864 /*itrace("parse_comsub: qc = `%c' open = %c close = %c", qc, open, close);*/
5866 tflags
= LEX_RESWDOK
;
5868 if ((flags
& P_COMMAND
) && qc
!= '\'' && qc
!= '"' && (flags
& P_DQUOTE
) == 0)
5869 tflags
|= LEX_CKCASE
;
5870 if ((tflags
& LEX_CKCASE
) && (interactive
== 0 || interactive_comments
))
5871 tflags
|= LEX_CKCOMMENT
;
5873 /* RFLAGS is the set of flags we want to pass to recursive calls. */
5874 rflags
= (flags
& P_DQUOTE
);
5876 ret
= (char *)xmalloc (retsize
= 64);
5879 start_lineno
= line_number
;
5880 lex_rwlen
= lex_wlen
= 0;
5888 ch
= shell_getc (qc
!= '\'' && (tflags
& (LEX_INCOMMENT
|LEX_PASSNEXT
)) == 0);
5895 parser_error (start_lineno
, _("unexpected EOF while looking for matching `%c'"), close
);
5896 EOF_Reached
= 1; /* XXX */
5897 return (&matched_pair_error
);
5900 /* If we hit the end of a line and are reading the contents of a here
5901 document, and it's not the same line that the document starts on,
5902 check for this line being the here doc delimiter. Otherwise, if
5903 we're in a here document, mark the next character as the beginning
5907 if ((tflags
& LEX_HEREDELIM
) && heredelim
)
5909 tflags
&= ~LEX_HEREDELIM
;
5910 tflags
|= LEX_INHEREDOC
;
5911 lex_firstind
= retind
+ 1;
5913 else if (tflags
& LEX_INHEREDOC
)
5916 tind
= lex_firstind
;
5917 while ((tflags
& LEX_STRIPDOC
) && ret
[tind
] == '\t')
5919 if (STREQN (ret
+ tind
, heredelim
, hdlen
))
5921 tflags
&= ~(LEX_STRIPDOC
|LEX_INHEREDOC
);
5922 /*itrace("parse_comsub:%d: found here doc end `%s'", line_number, ret + tind);*/
5928 lex_firstind
= retind
+ 1;
5932 /* Possible reprompting. */
5933 if (ch
== '\n' && SHOULD_PROMPT ())
5936 /* XXX -- possibly allow here doc to be delimited by ending right
5938 if ((tflags
& LEX_INHEREDOC
) && ch
== close
&& count
== 1)
5941 /*itrace("parse_comsub: in here doc, ch == close, retind - firstind = %d hdlen = %d retind = %d", retind-lex_firstind, hdlen, retind);*/
5942 tind
= lex_firstind
;
5943 while ((tflags
& LEX_STRIPDOC
) && ret
[tind
] == '\t')
5945 if (retind
-tind
== hdlen
&& STREQN (ret
+ tind
, heredelim
, hdlen
))
5947 tflags
&= ~(LEX_STRIPDOC
|LEX_INHEREDOC
);
5948 /*itrace("parse_comsub:%d: found here doc end `%s'", line_number, ret + tind);*/
5955 /* Don't bother counting parens or doing anything else if in a comment */
5956 if (tflags
& (LEX_INCOMMENT
|LEX_INHEREDOC
))
5958 /* Add this character. */
5959 RESIZE_MALLOCED_BUFFER (ret
, retind
, 1, retsize
, 64);
5962 if ((tflags
& LEX_INCOMMENT
) && ch
== '\n')
5964 /*itrace("parse_comsub:%d: lex_incomment -> 0 ch = `%c'", line_number, ch);*/
5965 tflags
&= ~LEX_INCOMMENT
;
5971 if (tflags
& LEX_PASSNEXT
) /* last char was backslash */
5973 /*itrace("parse_comsub:%d: lex_passnext -> 0 ch = `%c' (%d)", line_number, ch, __LINE__);*/
5974 tflags
&= ~LEX_PASSNEXT
;
5975 if (qc
!= '\'' && ch
== '\n') /* double-quoted \<newline> disappears. */
5978 retind
--; /* swallow previously-added backslash */
5982 RESIZE_MALLOCED_BUFFER (ret
, retind
, 2, retsize
, 64);
5983 if MBTEST(ch
== CTLESC
)
5984 ret
[retind
++] = CTLESC
;
5989 /* If this is a shell break character, we are not in a word. If not,
5990 we either start or continue a word. */
5991 if MBTEST(shellbreak (ch
))
5993 tflags
&= ~LEX_INWORD
;
5994 /*itrace("parse_comsub:%d: lex_inword -> 0 ch = `%c' (%d)", line_number, ch, __LINE__);*/
5998 if (tflags
& LEX_INWORD
)
6001 /*itrace("parse_comsub:%d: lex_inword == 1 ch = `%c' lex_wlen = %d (%d)", line_number, ch, lex_wlen, __LINE__);*/
6005 /*itrace("parse_comsub:%d: lex_inword -> 1 ch = `%c' (%d)", line_number, ch, __LINE__);*/
6006 tflags
|= LEX_INWORD
;
6011 /* Skip whitespace */
6012 if MBTEST(shellblank (ch
) && (tflags
& LEX_HEREDELIM
) == 0 && lex_rwlen
== 0)
6014 /* Add this character. */
6015 RESIZE_MALLOCED_BUFFER (ret
, retind
, 1, retsize
, 64);
6020 /* Either we are looking for the start of the here-doc delimiter
6021 (lex_firstind == -1) or we are reading one (lex_firstind >= 0).
6022 If this character is a shell break character and we are reading
6023 the delimiter, save it and note that we are now reading a here
6024 document. If we've found the start of the delimiter, note it by
6025 setting lex_firstind. Backslashes can quote shell metacharacters
6026 in here-doc delimiters. */
6027 if (tflags
& LEX_HEREDELIM
)
6029 if (lex_firstind
== -1 && shellbreak (ch
) == 0)
6030 lex_firstind
= retind
;
6032 else if (heredelim
&& (tflags
& LEX_PASSNEXT
) == 0 && ch
== '\n')
6034 tflags
|= LEX_INHEREDOC
;
6035 tflags
&= ~LEX_HEREDELIM
;
6036 lex_firstind
= retind
+ 1;
6039 else if (lex_firstind
>= 0 && (tflags
& LEX_PASSNEXT
) == 0 && shellbreak (ch
))
6043 nestret
= substring (ret
, lex_firstind
, retind
);
6044 heredelim
= string_quote_removal (nestret
, 0);
6046 hdlen
= STRLEN(heredelim
);
6047 /*itrace("parse_comsub:%d: found here doc delimiter `%s' (%d)", line_number, heredelim, hdlen);*/
6051 tflags
|= LEX_INHEREDOC
;
6052 tflags
&= ~LEX_HEREDELIM
;
6053 lex_firstind
= retind
+ 1;
6060 /* Meta-characters that can introduce a reserved word. Not perfect yet. */
6061 if MBTEST((tflags
& LEX_RESWDOK
) == 0 && (tflags
& LEX_CKCASE
) && (tflags
& LEX_INCOMMENT
) == 0 && (shellmeta(ch
) || ch
== '\n'))
6063 /* Add this character. */
6064 RESIZE_MALLOCED_BUFFER (ret
, retind
, 1, retsize
, 64);
6066 peekc
= shell_getc (1);
6067 if (ch
== peekc
&& (ch
== '&' || ch
== '|' || ch
== ';')) /* two-character tokens */
6069 RESIZE_MALLOCED_BUFFER (ret
, retind
, 1, retsize
, 64);
6070 ret
[retind
++] = peekc
;
6071 /*itrace("parse_comsub:%d: set lex_reswordok = 1, ch = `%c'", line_number, ch);*/
6072 tflags
|= LEX_RESWDOK
;
6076 else if (ch
== '\n' || COMSUB_META(ch
))
6078 shell_ungetc (peekc
);
6079 /*itrace("parse_comsub:%d: set lex_reswordok = 1, ch = `%c'", line_number, ch);*/
6080 tflags
|= LEX_RESWDOK
;
6088 /* `unget' the character we just added and fall through */
6090 shell_ungetc (peekc
);
6094 /* If we can read a reserved word, try to read one. */
6095 if (tflags
& LEX_RESWDOK
)
6097 if MBTEST(islower (ch
))
6099 /* Add this character. */
6100 RESIZE_MALLOCED_BUFFER (ret
, retind
, 1, retsize
, 64);
6105 else if MBTEST(lex_rwlen
== 4 && shellbreak (ch
))
6107 if (STREQN (ret
+ retind
- 4, "case", 4))
6109 tflags
|= LEX_INCASE
;
6110 /*itrace("parse_comsub:%d: found `case', lex_incase -> 1 lex_reswdok -> 0", line_number);*/
6112 else if (STREQN (ret
+ retind
- 4, "esac", 4))
6114 tflags
&= ~LEX_INCASE
;
6115 /*itrace("parse_comsub:%d: found `esac', lex_incase -> 0 lex_reswdok -> 0", line_number);*/
6117 tflags
&= ~LEX_RESWDOK
;
6119 else if MBTEST((tflags
& LEX_CKCOMMENT
) && ch
== '#' && (lex_rwlen
== 0 || ((tflags
& LEX_INWORD
) && lex_wlen
== 0)))
6120 ; /* don't modify LEX_RESWDOK if we're starting a comment */
6121 /* Allow `do' followed by space, tab, or newline to preserve the
6122 RESWDOK flag, but reset the reserved word length counter so we
6123 can read another one. */
6124 else if MBTEST(((tflags
& LEX_INCASE
) == 0) &&
6125 (isblank(ch
) || ch
== '\n') &&
6127 STREQN (ret
+ retind
- 2, "do", 2))
6129 /*itrace("parse_comsub:%d: lex_incase == 1 found `%c', found \"do\"", line_number, ch);*/
6132 else if MBTEST((tflags
& LEX_INCASE
) && ch
!= '\n')
6133 /* If we can read a reserved word and we're in case, we're at the
6134 point where we can read a new pattern list or an esac. We
6135 handle the esac case above. If we read a newline, we want to
6136 leave LEX_RESWDOK alone. If we read anything else, we want to
6137 turn off LEX_RESWDOK, since we're going to read a pattern list. */
6139 tflags
&= ~LEX_RESWDOK
;
6140 /*itrace("parse_comsub:%d: lex_incase == 1 found `%c', lex_reswordok -> 0", line_number, ch);*/
6142 else if MBTEST(shellbreak (ch
) == 0)
6144 tflags
&= ~LEX_RESWDOK
;
6145 /*itrace("parse_comsub:%d: found `%c', lex_reswordok -> 0", line_number, ch);*/
6148 /* If we find a space or tab but have read something and it's not
6149 `do', turn off the reserved-word-ok flag */
6150 else if MBTEST(isblank (ch
) && lex_rwlen
> 0)
6152 tflags
&= ~LEX_RESWDOK
;
6153 /*itrace("parse_comsub:%d: found `%c', lex_reswordok -> 0", line_number, ch);*/
6158 /* Might be the start of a here-doc delimiter */
6159 if MBTEST((tflags
& LEX_INCOMMENT
) == 0 && (tflags
& LEX_CKCASE
) && ch
== '<')
6161 /* Add this character. */
6162 RESIZE_MALLOCED_BUFFER (ret
, retind
, 1, retsize
, 64);
6164 peekc
= shell_getc (1);
6169 RESIZE_MALLOCED_BUFFER (ret
, retind
, 1, retsize
, 64);
6170 ret
[retind
++] = peekc
;
6171 peekc
= shell_getc (1);
6176 RESIZE_MALLOCED_BUFFER (ret
, retind
, 1, retsize
, 64);
6177 ret
[retind
++] = peekc
;
6178 tflags
|= LEX_STRIPDOC
;
6181 shell_ungetc (peekc
);
6184 tflags
|= LEX_HEREDELIM
;
6190 ch
= peekc
; /* fall through and continue XXX */
6192 else if MBTEST((tflags
& LEX_CKCOMMENT
) && (tflags
& LEX_INCOMMENT
) == 0 && ch
== '#' && (((tflags
& LEX_RESWDOK
) && lex_rwlen
== 0) || ((tflags
& LEX_INWORD
) && lex_wlen
== 0)))
6194 /*itrace("parse_comsub:%d: lex_incomment -> 1 (%d)", line_number, __LINE__);*/
6195 tflags
|= LEX_INCOMMENT
;
6198 if MBTEST(ch
== CTLESC
|| ch
== CTLNUL
) /* special shell escapes */
6200 RESIZE_MALLOCED_BUFFER (ret
, retind
, 2, retsize
, 64);
6201 ret
[retind
++] = CTLESC
;
6206 else if MBTEST((tflags
& LEX_INCASE
) && ch
== close
&& close
== ')')
6207 tflags
&= ~LEX_INCASE
; /* XXX */
6209 else if MBTEST(ch
== close
&& (tflags
& LEX_INCASE
) == 0) /* ending delimiter */
6212 /*itrace("parse_comsub:%d: found close: count = %d", line_number, count);*/
6214 else if MBTEST(((flags
& P_FIRSTCLOSE
) == 0) && (tflags
& LEX_INCASE
) == 0 && ch
== open
) /* nested begin */
6217 /*itrace("parse_comsub:%d: found open: count = %d", line_number, count);*/
6220 /* Add this character. */
6221 RESIZE_MALLOCED_BUFFER (ret
, retind
, 1, retsize
, 64);
6224 /* If we just read the ending character, don't bother continuing. */
6228 if MBTEST(ch
== '\\') /* backslashes */
6229 tflags
|= LEX_PASSNEXT
;
6231 if MBTEST(shellquote (ch
))
6233 /* '', ``, or "" inside $(...). */
6234 push_delimiter (dstack
, ch
);
6235 if MBTEST((tflags
& LEX_WASDOL
) && ch
== '\'') /* $'...' inside group */
6236 nestret
= parse_matched_pair (ch
, ch
, ch
, &nestlen
, P_ALLOWESC
|rflags
);
6238 nestret
= parse_matched_pair (ch
, ch
, ch
, &nestlen
, rflags
);
6239 pop_delimiter (dstack
);
6240 CHECK_NESTRET_ERROR ();
6242 if MBTEST((tflags
& LEX_WASDOL
) && ch
== '\'' && (extended_quote
|| (rflags
& P_DQUOTE
) == 0))
6244 /* Translate $'...' here. */
6245 ttrans
= ansiexpand (nestret
, 0, nestlen
- 1, &ttranslen
);
6248 if ((rflags
& P_DQUOTE
) == 0)
6250 nestret
= sh_single_quote (ttrans
);
6252 nestlen
= strlen (nestret
);
6257 nestlen
= ttranslen
;
6259 retind
-= 2; /* back up before the $' */
6261 else if MBTEST((tflags
& LEX_WASDOL
) && ch
== '"' && (extended_quote
|| (rflags
& P_DQUOTE
) == 0))
6263 /* Locale expand $"..." here. */
6264 ttrans
= localeexpand (nestret
, 0, nestlen
- 1, start_lineno
, &ttranslen
);
6267 nestret
= sh_mkdoublequoted (ttrans
, ttranslen
, 0);
6269 nestlen
= ttranslen
+ 2;
6270 retind
-= 2; /* back up before the $" */
6276 else if MBTEST((tflags
& LEX_WASDOL
) && (ch
== '(' || ch
== '{' || ch
== '[')) /* ) } ] */
6277 /* check for $(), $[], or ${} inside command substitution. */
6279 if ((tflags
& LEX_INCASE
) == 0 && open
== ch
) /* undo previous increment */
6281 if (ch
== '(') /* ) */
6282 nestret
= parse_comsub (0, '(', ')', &nestlen
, (rflags
|P_COMMAND
) & ~P_DQUOTE
);
6283 else if (ch
== '{') /* } */
6284 nestret
= parse_matched_pair (0, '{', '}', &nestlen
, P_FIRSTCLOSE
|P_DOLBRACE
|rflags
);
6285 else if (ch
== '[') /* ] */
6286 nestret
= parse_matched_pair (0, '[', ']', &nestlen
, rflags
);
6288 CHECK_NESTRET_ERROR ();
6293 if MBTEST(ch
== '$')
6294 tflags
|= LEX_WASDOL
;
6296 tflags
&= ~LEX_WASDOL
;
6303 /*itrace("parse_comsub:%d: returning `%s'", line_number, ret);*/
6307 /* Recursively call the parser to parse a $(...) command substitution. */
6309 xparse_dolparen (base
, string
, indp
, flags
)
6315 sh_parser_state_t ps
;
6316 sh_input_line_state_t ls
;
6317 int orig_ind
, nc
, sflags
, orig_eof_token
;
6318 char *ret
, *s
, *ep
, *ostring
;
6324 /*itrace("xparse_dolparen: size = %d shell_input_line = `%s'", shell_input_line_size, shell_input_line);*/
6325 sflags
= SEVAL_NONINT
|SEVAL_NOHIST
|SEVAL_NOFREE
;
6326 if (flags
& SX_NOLONGJMP
)
6327 sflags
|= SEVAL_NOLONGJMP
;
6328 save_parser_state (&ps
);
6329 save_input_line_state (&ls
);
6330 orig_eof_token
= shell_eof_token
;
6333 parser_state
|= PST_CMDSUBST
|PST_EOFTOKEN
; /* allow instant ')' */ /*(*/
6334 shell_eof_token
= ')';
6335 parse_string (string
, "command substitution", sflags
, &ep
);
6337 shell_eof_token
= orig_eof_token
;
6338 restore_parser_state (&ps
);
6340 /* reset_parser clears shell_input_line and associated variables */
6341 restore_input_line_state (&ls
);
6345 /* Need to find how many characters parse_and_execute consumed, update
6346 *indp, if flags != 0, copy the portion of the string parsed into RET
6347 and return it. If flags & 1 (EX_NOALLOC) we can return NULL. */
6354 itrace("xparse_dolparen:%d: ep[-1] != RPAREN (%d), ep = `%s'", line_number
, ep
[-1], ep
);
6356 while (ep
> ostring
&& ep
[-1] == '\n') ep
--;
6360 *indp
= ep
- base
- 1;
6364 if (base
[*indp
] != ')')
6365 itrace("xparse_dolparen:%d: base[%d] != RPAREN (%d), base = `%s'", line_number
, *indp
, base
[*indp
], base
);
6368 if (flags
& SX_NOALLOC
)
6369 return (char *)NULL
;
6377 ret
= substring (ostring
, 0, nc
- 1);
6382 #if defined (DPAREN_ARITHMETIC) || defined (ARITH_FOR_COMMAND)
6383 /* Parse a double-paren construct. It can be either an arithmetic
6384 command, an arithmetic `for' command, or a nested subshell. Returns
6385 the parsed token, -1 on error, or -2 if we didn't do anything and
6386 should just go on. */
6395 #if defined (ARITH_FOR_COMMAND)
6396 if (last_read_token
== FOR
)
6398 arith_for_lineno
= line_number
;
6399 cmdtyp
= parse_arith_cmd (&wval
, 0);
6402 wd
= alloc_word_desc ();
6404 yylval
.word_list
= make_word_list (wd
, (WORD_LIST
*)NULL
);
6405 return (ARITH_FOR_EXPRS
);
6408 return -1; /* ERROR */
6412 #if defined (DPAREN_ARITHMETIC)
6413 if (reserved_word_acceptable (last_read_token
))
6415 sline
= line_number
;
6417 cmdtyp
= parse_arith_cmd (&wval
, 0);
6418 if (cmdtyp
== 1) /* arithmetic command */
6420 wd
= alloc_word_desc ();
6422 wd
->flags
= W_QUOTED
|W_NOSPLIT
|W_NOGLOB
|W_DQUOTE
;
6423 yylval
.word_list
= make_word_list (wd
, (WORD_LIST
*)NULL
);
6426 else if (cmdtyp
== 0) /* nested subshell */
6428 push_string (wval
, 0, (alias_t
*)NULL
);
6429 pushed_string_list
->flags
= PSH_DPAREN
;
6430 if ((parser_state
& PST_CASEPAT
) == 0)
6431 parser_state
|= PST_SUBSHELL
;
6439 return -2; /* XXX */
6442 /* We've seen a `(('. Look for the matching `))'. If we get it, return 1.
6443 If not, assume it's a nested subshell for backwards compatibility and
6444 return 0. In any case, put the characters we've consumed into a locally-
6445 allocated buffer and make *ep point to that buffer. Return -1 on an
6446 error, for example EOF. */
6448 parse_arith_cmd (ep
, adddq
)
6452 int exp_lineno
, rval
, c
;
6453 char *ttok
, *tokstr
;
6456 exp_lineno
= line_number
;
6457 ttok
= parse_matched_pair (0, '(', ')', &ttoklen
, 0);
6459 if (ttok
== &matched_pair_error
)
6461 /* Check that the next character is the closing right paren. If
6462 not, this is a syntax error. ( */
6467 tokstr
= (char *)xmalloc (ttoklen
+ 4);
6469 /* if ADDDQ != 0 then (( ... )) -> "..." */
6470 if (rval
== 1 && adddq
) /* arith cmd, add double quotes */
6473 strncpy (tokstr
+ 1, ttok
, ttoklen
- 1);
6474 tokstr
[ttoklen
] = '"';
6475 tokstr
[ttoklen
+1] = '\0';
6477 else if (rval
== 1) /* arith cmd, don't add double quotes */
6479 strncpy (tokstr
, ttok
, ttoklen
- 1);
6480 tokstr
[ttoklen
-1] = '\0';
6482 else /* nested subshell */
6485 strncpy (tokstr
+ 1, ttok
, ttoklen
- 1);
6486 tokstr
[ttoklen
] = ')';
6487 tokstr
[ttoklen
+1] = c
;
6488 tokstr
[ttoklen
+2] = '\0';
6495 #endif /* DPAREN_ARITHMETIC || ARITH_FOR_COMMAND */
6497 #if defined (COND_COMMAND)
6503 if (EOF_Reached
&& cond_token
!= COND_ERROR
) /* [[ */
6504 parser_error (cond_lineno
, _("unexpected EOF while looking for `]]'"));
6505 else if (cond_token
!= COND_ERROR
)
6507 if (etext
= error_token_from_token (cond_token
))
6509 parser_error (cond_lineno
, _("syntax error in conditional expression: unexpected token `%s'"), etext
);
6513 parser_error (cond_lineno
, _("syntax error in conditional expression"));
6520 return (cond_or ());
6529 if (cond_token
== OR_OR
)
6532 l
= make_cond_node (COND_OR
, (WORD_DESC
*)NULL
, l
, r
);
6543 if (cond_token
== AND_AND
)
6546 l
= make_cond_node (COND_AND
, (WORD_DESC
*)NULL
, l
, r
);
6552 cond_skip_newlines ()
6554 while ((cond_token
= read_token (READ
)) == '\n')
6556 if (SHOULD_PROMPT ())
6559 return (cond_token
);
6562 #define COND_RETURN_ERROR() \
6563 do { cond_token = COND_ERROR; return ((COND_COM *)NULL); } while (0)
6569 COND_COM
*term
, *tleft
, *tright
;
6573 /* Read a token. It can be a left paren, a `!', a unary operator, or a
6574 word that should be the first argument of a binary operator. Start by
6575 skipping newlines, since this is a compound command. */
6576 tok
= cond_skip_newlines ();
6577 lineno
= line_number
;
6578 if (tok
== COND_END
)
6580 COND_RETURN_ERROR ();
6582 else if (tok
== '(')
6584 term
= cond_expr ();
6585 if (cond_token
!= ')')
6588 dispose_cond_node (term
); /* ( */
6589 if (etext
= error_token_from_token (cond_token
))
6591 parser_error (lineno
, _("unexpected token `%s', expected `)'"), etext
);
6595 parser_error (lineno
, _("expected `)'"));
6596 COND_RETURN_ERROR ();
6598 term
= make_cond_node (COND_EXPR
, (WORD_DESC
*)NULL
, term
, (COND_COM
*)NULL
);
6599 (void)cond_skip_newlines ();
6601 else if (tok
== BANG
|| (tok
== WORD
&& (yylval
.word
->word
[0] == '!' && yylval
.word
->word
[1] == '\0')))
6604 dispose_word (yylval
.word
); /* not needed */
6605 term
= cond_term ();
6607 term
->flags
|= CMD_INVERT_RETURN
;
6609 else if (tok
== WORD
&& yylval
.word
->word
[0] == '-' && yylval
.word
->word
[2] == 0 && test_unop (yylval
.word
->word
))
6612 tok
= read_token (READ
);
6615 tleft
= make_cond_node (COND_TERM
, yylval
.word
, (COND_COM
*)NULL
, (COND_COM
*)NULL
);
6616 term
= make_cond_node (COND_UNARY
, op
, tleft
, (COND_COM
*)NULL
);
6621 if (etext
= error_token_from_token (tok
))
6623 parser_error (line_number
, _("unexpected argument `%s' to conditional unary operator"), etext
);
6627 parser_error (line_number
, _("unexpected argument to conditional unary operator"));
6628 COND_RETURN_ERROR ();
6631 (void)cond_skip_newlines ();
6633 else if (tok
== WORD
) /* left argument to binary operator */
6636 tleft
= make_cond_node (COND_TERM
, yylval
.word
, (COND_COM
*)NULL
, (COND_COM
*)NULL
);
6639 tok
= read_token (READ
);
6640 if (tok
== WORD
&& test_binop (yylval
.word
->word
))
6643 if (op
->word
[0] == '=' && (op
->word
[1] == '\0' || (op
->word
[1] == '=' && op
->word
[2] == '\0')))
6644 parser_state
|= PST_EXTPAT
;
6645 else if (op
->word
[0] == '!' && op
->word
[1] == '=' && op
->word
[2] == '\0')
6646 parser_state
|= PST_EXTPAT
;
6648 #if defined (COND_REGEXP)
6649 else if (tok
== WORD
&& STREQ (yylval
.word
->word
, "=~"))
6652 parser_state
|= PST_REGEXP
;
6655 else if (tok
== '<' || tok
== '>')
6656 op
= make_word_from_token (tok
); /* ( */
6657 /* There should be a check before blindly accepting the `)' that we have
6658 seen the opening `('. */
6659 else if (tok
== COND_END
|| tok
== AND_AND
|| tok
== OR_OR
|| tok
== ')')
6661 /* Special case. [[ x ]] is equivalent to [[ -n x ]], just like
6662 the test command. Similarly for [[ x && expr ]] or
6663 [[ x || expr ]] or [[ (x) ]]. */
6664 op
= make_word ("-n");
6665 term
= make_cond_node (COND_UNARY
, op
, tleft
, (COND_COM
*)NULL
);
6671 if (etext
= error_token_from_token (tok
))
6673 parser_error (line_number
, _("unexpected token `%s', conditional binary operator expected"), etext
);
6677 parser_error (line_number
, _("conditional binary operator expected"));
6678 dispose_cond_node (tleft
);
6679 COND_RETURN_ERROR ();
6683 if (parser_state
& PST_EXTPAT
)
6685 tok
= read_token (READ
);
6686 if (parser_state
& PST_EXTPAT
)
6687 extended_glob
= global_extglob
;
6688 parser_state
&= ~(PST_REGEXP
|PST_EXTPAT
);
6692 tright
= make_cond_node (COND_TERM
, yylval
.word
, (COND_COM
*)NULL
, (COND_COM
*)NULL
);
6693 term
= make_cond_node (COND_BINARY
, op
, tleft
, tright
);
6697 if (etext
= error_token_from_token (tok
))
6699 parser_error (line_number
, _("unexpected argument `%s' to conditional binary operator"), etext
);
6703 parser_error (line_number
, _("unexpected argument to conditional binary operator"));
6704 dispose_cond_node (tleft
);
6706 COND_RETURN_ERROR ();
6709 (void)cond_skip_newlines ();
6714 parser_error (line_number
, _("unexpected token `%c' in conditional command"), tok
);
6715 else if (etext
= error_token_from_token (tok
))
6717 parser_error (line_number
, _("unexpected token `%s' in conditional command"), etext
);
6721 parser_error (line_number
, _("unexpected token %d in conditional command"), tok
);
6722 COND_RETURN_ERROR ();
6727 /* This is kind of bogus -- we slip a mini recursive-descent parser in
6728 here to handle the conditional statement syntax. */
6730 parse_cond_command ()
6734 global_extglob
= extended_glob
;
6735 cexp
= cond_expr ();
6736 return (make_cond_command (cexp
));
6740 #if defined (ARRAY_VARS)
6741 /* When this is called, it's guaranteed that we don't care about anything
6742 in t beyond i. We do save and restore the chars, though. */
6744 token_is_assignment (t
, i
)
6748 unsigned char c
, c1
;
6751 c
= t
[i
]; c1
= t
[i
+1];
6752 t
[i
] = '='; t
[i
+1] = '\0';
6753 r
= assignment (t
, (parser_state
& PST_COMPASSIGN
) != 0);
6754 t
[i
] = c
; t
[i
+1] = c1
;
6758 /* XXX - possible changes here for `+=' */
6760 token_is_ident (t
, i
)
6769 r
= legal_identifier (t
);
6776 read_token_word (character
)
6779 /* The value for YYLVAL when a WORD is read. */
6780 WORD_DESC
*the_word
;
6782 /* Index into the token that we are building. */
6785 /* ALL_DIGITS becomes zero when we see a non-digit. */
6786 int all_digit_token
;
6788 /* DOLLAR_PRESENT becomes non-zero if we see a `$'. */
6791 /* COMPOUND_ASSIGNMENT becomes non-zero if we are parsing a compound
6793 int compound_assignment
;
6795 /* QUOTED becomes non-zero if we see one of ("), ('), (`), or (\). */
6798 /* Non-zero means to ignore the value of the next character, and just
6799 to add it no matter what. */
6800 int pass_next_character
;
6802 /* The current delimiting character. */
6804 int result
, peek_char
;
6805 char *ttok
, *ttrans
;
6806 int ttoklen
, ttranslen
;
6809 if (token_buffer_size
< TOKEN_DEFAULT_INITIAL_SIZE
)
6810 token
= (char *)xrealloc (token
, token_buffer_size
= TOKEN_DEFAULT_INITIAL_SIZE
);
6813 all_digit_token
= DIGIT (character
);
6814 dollar_present
= quoted
= pass_next_character
= compound_assignment
= 0;
6818 if (character
== EOF
)
6821 if (pass_next_character
)
6823 pass_next_character
= 0;
6824 goto got_escaped_character
;
6827 cd
= current_delimiter (dstack
);
6829 /* Handle backslashes. Quote lots of things when not inside of
6830 double-quotes, quote some things inside of double-quotes. */
6831 if MBTEST(character
== '\\')
6833 peek_char
= shell_getc (0);
6835 /* Backslash-newline is ignored in all cases except
6836 when quoted with single quotes. */
6837 if (peek_char
== '\n')
6840 goto next_character
;
6844 shell_ungetc (peek_char
);
6846 /* If the next character is to be quoted, note it now. */
6847 if (cd
== 0 || cd
== '`' ||
6848 (cd
== '"' && peek_char
>= 0 && (sh_syntaxtab
[peek_char
] & CBSDQUOTE
)))
6849 pass_next_character
++;
6856 /* Parse a matched pair of quote characters. */
6857 if MBTEST(shellquote (character
))
6859 push_delimiter (dstack
, character
);
6860 ttok
= parse_matched_pair (character
, character
, character
, &ttoklen
, (character
== '`') ? P_COMMAND
: 0);
6861 pop_delimiter (dstack
);
6862 if (ttok
== &matched_pair_error
)
6863 return -1; /* Bail immediately. */
6864 RESIZE_MALLOCED_BUFFER (token
, token_index
, ttoklen
+ 2,
6865 token_buffer_size
, TOKEN_DEFAULT_GROW_SIZE
);
6866 token
[token_index
++] = character
;
6867 strcpy (token
+ token_index
, ttok
);
6868 token_index
+= ttoklen
;
6869 all_digit_token
= 0;
6871 dollar_present
|= (character
== '"' && strchr (ttok
, '$') != 0);
6873 goto next_character
;
6877 /* When parsing a regexp as a single word inside a conditional command,
6878 we need to special-case characters special to both the shell and
6879 regular expressions. Right now, that is only '(' and '|'. */ /*)*/
6880 if MBTEST((parser_state
& PST_REGEXP
) && (character
== '(' || character
== '|')) /*)*/
6882 if (character
== '|')
6885 push_delimiter (dstack
, character
);
6886 ttok
= parse_matched_pair (cd
, '(', ')', &ttoklen
, 0);
6887 pop_delimiter (dstack
);
6888 if (ttok
== &matched_pair_error
)
6889 return -1; /* Bail immediately. */
6890 RESIZE_MALLOCED_BUFFER (token
, token_index
, ttoklen
+ 2,
6891 token_buffer_size
, TOKEN_DEFAULT_GROW_SIZE
);
6892 token
[token_index
++] = character
;
6893 strcpy (token
+ token_index
, ttok
);
6894 token_index
+= ttoklen
;
6896 dollar_present
= all_digit_token
= 0;
6897 goto next_character
;
6899 #endif /* COND_REGEXP */
6901 #ifdef EXTENDED_GLOB
6902 /* Parse a ksh-style extended pattern matching specification. */
6903 if MBTEST(extended_glob
&& PATTERN_CHAR (character
))
6905 peek_char
= shell_getc (1);
6906 if MBTEST(peek_char
== '(') /* ) */
6908 push_delimiter (dstack
, peek_char
);
6909 ttok
= parse_matched_pair (cd
, '(', ')', &ttoklen
, 0);
6910 pop_delimiter (dstack
);
6911 if (ttok
== &matched_pair_error
)
6912 return -1; /* Bail immediately. */
6913 RESIZE_MALLOCED_BUFFER (token
, token_index
, ttoklen
+ 3,
6915 TOKEN_DEFAULT_GROW_SIZE
);
6916 token
[token_index
++] = character
;
6917 token
[token_index
++] = peek_char
;
6918 strcpy (token
+ token_index
, ttok
);
6919 token_index
+= ttoklen
;
6921 dollar_present
= all_digit_token
= 0;
6922 goto next_character
;
6925 shell_ungetc (peek_char
);
6927 #endif /* EXTENDED_GLOB */
6929 /* If the delimiter character is not single quote, parse some of
6930 the shell expansions that must be read as a single word. */
6931 if (shellexp (character
))
6933 peek_char
= shell_getc (1);
6934 /* $(...), <(...), >(...), $((...)), ${...}, and $[...] constructs */
6935 if MBTEST(peek_char
== '(' ||
6936 ((peek_char
== '{' || peek_char
== '[') && character
== '$')) /* ) ] } */
6938 if (peek_char
== '{') /* } */
6939 ttok
= parse_matched_pair (cd
, '{', '}', &ttoklen
, P_FIRSTCLOSE
|P_DOLBRACE
);
6940 else if (peek_char
== '(') /* ) */
6942 /* XXX - push and pop the `(' as a delimiter for use by
6943 the command-oriented-history code. This way newlines
6944 appearing in the $(...) string get added to the
6945 history literally rather than causing a possibly-
6946 incorrect `;' to be added. ) */
6947 push_delimiter (dstack
, peek_char
);
6948 ttok
= parse_comsub (cd
, '(', ')', &ttoklen
, P_COMMAND
);
6949 pop_delimiter (dstack
);
6952 ttok
= parse_matched_pair (cd
, '[', ']', &ttoklen
, 0);
6953 if (ttok
== &matched_pair_error
)
6954 return -1; /* Bail immediately. */
6955 RESIZE_MALLOCED_BUFFER (token
, token_index
, ttoklen
+ 3,
6957 TOKEN_DEFAULT_GROW_SIZE
);
6958 token
[token_index
++] = character
;
6959 token
[token_index
++] = peek_char
;
6960 strcpy (token
+ token_index
, ttok
);
6961 token_index
+= ttoklen
;
6964 all_digit_token
= 0;
6965 goto next_character
;
6967 /* This handles $'...' and $"..." new-style quoted strings. */
6968 else if MBTEST(character
== '$' && (peek_char
== '\'' || peek_char
== '"'))
6972 first_line
= line_number
;
6973 push_delimiter (dstack
, peek_char
);
6974 ttok
= parse_matched_pair (peek_char
, peek_char
, peek_char
,
6976 (peek_char
== '\'') ? P_ALLOWESC
: 0);
6977 pop_delimiter (dstack
);
6978 if (ttok
== &matched_pair_error
)
6980 if (peek_char
== '\'')
6982 ttrans
= ansiexpand (ttok
, 0, ttoklen
- 1, &ttranslen
);
6985 /* Insert the single quotes and correctly quote any
6986 embedded single quotes (allowed because P_ALLOWESC was
6987 passed to parse_matched_pair). */
6988 ttok
= sh_single_quote (ttrans
);
6990 ttranslen
= strlen (ttok
);
6995 /* Try to locale-expand the converted string. */
6996 ttrans
= localeexpand (ttok
, 0, ttoklen
- 1, first_line
, &ttranslen
);
6999 /* Add the double quotes back */
7000 ttok
= sh_mkdoublequoted (ttrans
, ttranslen
, 0);
7006 RESIZE_MALLOCED_BUFFER (token
, token_index
, ttranslen
+ 1,
7008 TOKEN_DEFAULT_GROW_SIZE
);
7009 strcpy (token
+ token_index
, ttrans
);
7010 token_index
+= ttranslen
;
7013 all_digit_token
= 0;
7014 goto next_character
;
7016 /* This could eventually be extended to recognize all of the
7017 shell's single-character parameter expansions, and set flags.*/
7018 else if MBTEST(character
== '$' && peek_char
== '$')
7020 RESIZE_MALLOCED_BUFFER (token
, token_index
, 3,
7022 TOKEN_DEFAULT_GROW_SIZE
);
7023 token
[token_index
++] = '$';
7024 token
[token_index
++] = peek_char
;
7026 all_digit_token
= 0;
7027 goto next_character
;
7030 shell_ungetc (peek_char
);
7033 #if defined (ARRAY_VARS)
7034 /* Identify possible array subscript assignment; match [...]. If
7035 parser_state&PST_COMPASSIGN, we need to parse [sub]=words treating
7036 `sub' as if it were enclosed in double quotes. */
7037 else if MBTEST(character
== '[' && /* ] */
7038 ((token_index
> 0 && assignment_acceptable (last_read_token
) && token_is_ident (token
, token_index
)) ||
7039 (token_index
== 0 && (parser_state
&PST_COMPASSIGN
))))
7041 ttok
= parse_matched_pair (cd
, '[', ']', &ttoklen
, P_ARRAYSUB
);
7042 if (ttok
== &matched_pair_error
)
7043 return -1; /* Bail immediately. */
7044 RESIZE_MALLOCED_BUFFER (token
, token_index
, ttoklen
+ 2,
7046 TOKEN_DEFAULT_GROW_SIZE
);
7047 token
[token_index
++] = character
;
7048 strcpy (token
+ token_index
, ttok
);
7049 token_index
+= ttoklen
;
7051 all_digit_token
= 0;
7052 goto next_character
;
7054 /* Identify possible compound array variable assignment. */
7055 else if MBTEST(character
== '=' && token_index
> 0 && (assignment_acceptable (last_read_token
) || (parser_state
& PST_ASSIGNOK
)) && token_is_assignment (token
, token_index
))
7057 peek_char
= shell_getc (1);
7058 if MBTEST(peek_char
== '(') /* ) */
7060 ttok
= parse_compound_assignment (&ttoklen
);
7062 RESIZE_MALLOCED_BUFFER (token
, token_index
, ttoklen
+ 4,
7064 TOKEN_DEFAULT_GROW_SIZE
);
7066 token
[token_index
++] = '=';
7067 token
[token_index
++] = '(';
7070 strcpy (token
+ token_index
, ttok
);
7071 token_index
+= ttoklen
;
7073 token
[token_index
++] = ')';
7075 all_digit_token
= 0;
7076 compound_assignment
= 1;
7078 goto next_character
;
7080 goto got_token
; /* ksh93 seems to do this */
7084 shell_ungetc (peek_char
);
7088 /* When not parsing a multi-character word construct, shell meta-
7089 characters break words. */
7090 if MBTEST(shellbreak (character
))
7092 shell_ungetc (character
);
7098 if (character
== CTLESC
|| character
== CTLNUL
)
7100 RESIZE_MALLOCED_BUFFER (token
, token_index
, 2, token_buffer_size
,
7101 TOKEN_DEFAULT_GROW_SIZE
);
7102 token
[token_index
++] = CTLESC
;
7105 got_escaped_character
:
7106 RESIZE_MALLOCED_BUFFER (token
, token_index
, 1, token_buffer_size
,
7107 TOKEN_DEFAULT_GROW_SIZE
);
7109 token
[token_index
++] = character
;
7111 all_digit_token
&= DIGIT (character
);
7112 dollar_present
|= character
== '$';
7115 if (character
== '\n' && SHOULD_PROMPT ())
7118 /* We want to remove quoted newlines (that is, a \<newline> pair)
7119 unless we are within single quotes or pass_next_character is
7120 set (the shell equivalent of literal-next). */
7121 cd
= current_delimiter (dstack
);
7122 character
= shell_getc (cd
!= '\'' && pass_next_character
== 0);
7123 } /* end for (;;) */
7127 /* Calls to RESIZE_MALLOCED_BUFFER ensure there is sufficient room. */
7128 token
[token_index
] = '\0';
7130 /* Check to see what thing we should return. If the last_read_token
7131 is a `<', or a `&', or the character which ended this token is
7132 a '>' or '<', then, and ONLY then, is this input token a NUMBER.
7133 Otherwise, it is just a word, and should be returned as such. */
7134 if MBTEST(all_digit_token
&& (character
== '<' || character
== '>' ||
7135 last_read_token
== LESS_AND
||
7136 last_read_token
== GREATER_AND
))
7138 if (legal_number (token
, &lvalue
) && (int)lvalue
== lvalue
)
7140 yylval
.number
= lvalue
;
7145 /* Check for special case tokens. */
7146 result
= (last_shell_getc_is_singlebyte
) ? special_case_tokens (token
) : -1;
7151 /* Posix.2 does not allow reserved words to be aliased, so check for all
7152 of them, including special cases, before expanding the current token
7154 if MBTEST(posixly_correct
)
7155 CHECK_FOR_RESERVED_WORD (token
);
7157 /* Aliases are expanded iff EXPAND_ALIASES is non-zero, and quoting
7158 inhibits alias expansion. */
7159 if (expand_aliases
&& quoted
== 0)
7161 result
= alias_expand_token (token
);
7162 if (result
== RE_READ_TOKEN
)
7163 return (RE_READ_TOKEN
);
7164 else if (result
== NO_EXPANSION
)
7165 parser_state
&= ~PST_ALEXPNEXT
;
7168 /* If not in Posix.2 mode, check for reserved words after alias
7170 if MBTEST(posixly_correct
== 0)
7172 CHECK_FOR_RESERVED_WORD (token
);
7174 the_word
= (WORD_DESC
*)xmalloc (sizeof (WORD_DESC
));
7175 the_word
->word
= (char *)xmalloc (1 + token_index
);
7176 the_word
->flags
= 0;
7177 strcpy (the_word
->word
, token
);
7179 the_word
->flags
|= W_HASDOLLAR
;
7181 the_word
->flags
|= W_QUOTED
; /*(*/
7182 if (compound_assignment
&& token
[token_index
-1] == ')')
7183 the_word
->flags
|= W_COMPASSIGN
;
7184 /* A word is an assignment if it appears at the beginning of a
7185 simple command, or after another assignment word. This is
7186 context-dependent, so it cannot be handled in the grammar. */
7187 if (assignment (token
, (parser_state
& PST_COMPASSIGN
) != 0))
7189 the_word
->flags
|= W_ASSIGNMENT
;
7190 /* Don't perform word splitting on assignment statements. */
7191 if (assignment_acceptable (last_read_token
) || (parser_state
& PST_COMPASSIGN
) != 0)
7193 the_word
->flags
|= W_NOSPLIT
;
7194 if (parser_state
& PST_COMPASSIGN
)
7195 the_word
->flags
|= W_NOGLOB
; /* XXX - W_NOBRACE? */
7199 if (command_token_position (last_read_token
))
7202 b
= builtin_address_internal (token
, 0);
7203 if (b
&& (b
->flags
& ASSIGNMENT_BUILTIN
))
7204 parser_state
|= PST_ASSIGNOK
;
7205 else if (STREQ (token
, "eval") || STREQ (token
, "let"))
7206 parser_state
|= PST_ASSIGNOK
;
7209 yylval
.word
= the_word
;
7211 if (token
[0] == '{' && token
[token_index
-1] == '}' &&
7212 (character
== '<' || character
== '>'))
7214 /* can use token; already copied to the_word */
7215 token
[token_index
-1] = '\0';
7216 #if defined (ARRAY_VARS)
7217 if (legal_identifier (token
+1) || valid_array_reference (token
+1))
7219 if (legal_identifier (token
+1))
7222 strcpy (the_word
->word
, token
+1);
7223 /*itrace("read_token_word: returning REDIR_WORD for %s", the_word->word);*/
7224 return (REDIR_WORD
);
7228 result
= ((the_word
->flags
& (W_ASSIGNMENT
|W_NOSPLIT
)) == (W_ASSIGNMENT
|W_NOSPLIT
))
7229 ? ASSIGNMENT_WORD
: WORD
;
7231 switch (last_read_token
)
7234 parser_state
|= PST_ALLOWOPNBRC
;
7235 function_dstart
= line_number
;
7240 if (word_top
< MAX_CASE_NEST
)
7242 word_lineno
[word_top
] = line_number
;
7249 /* Return 1 if TOKSYM is a token that after being read would allow
7250 a reserved word to be seen, else 0. */
7252 reserved_word_acceptable (toksym
)
7289 #if defined (COPROCESS_SUPPORT)
7290 if (last_read_token
== WORD
&& token_before_that
== COPROC
)
7293 if (last_read_token
== WORD
&& token_before_that
== FUNCTION
)
7299 /* Return the index of TOKEN in the alist of reserved words, or -1 if
7300 TOKEN is not a shell reserved word. */
7302 find_reserved_word (tokstr
)
7306 for (i
= 0; word_token_alist
[i
].word
; i
++)
7307 if (STREQ (tokstr
, word_token_alist
[i
].word
))
7312 /* An interface to let the rest of the shell (primarily the completion
7313 system) know what the parser is expecting. */
7315 parser_in_command_position ()
7317 return (command_token_position (last_read_token
));
7321 #if defined (READLINE)
7322 /* Called after each time readline is called. This insures that whatever
7323 the new prompt string is gets propagated to readline's local prompt
7326 reset_readline_prompt ()
7330 if (prompt_string_pointer
)
7332 temp_prompt
= (*prompt_string_pointer
)
7333 ? decode_prompt_string (*prompt_string_pointer
)
7336 if (temp_prompt
== 0)
7338 temp_prompt
= (char *)xmalloc (1);
7339 temp_prompt
[0] = '\0';
7342 FREE (current_readline_prompt
);
7343 current_readline_prompt
= temp_prompt
;
7346 #endif /* READLINE */
7349 #if defined (HISTORY)
7350 /* A list of tokens which can be followed by newlines, but not by
7351 semi-colons. When concatenating multiple lines of history, the
7352 newline separator for such tokens is replaced with a space. */
7353 static const int no_semi_successors
[] = {
7354 '\n', '{', '(', ')', ';', '&', '|',
7355 CASE
, DO
, ELSE
, IF
, SEMI_SEMI
, SEMI_AND
, SEMI_SEMI_AND
, THEN
, UNTIL
,
7356 WHILE
, AND_AND
, OR_OR
, IN
,
7360 /* If we are not within a delimited expression, try to be smart
7361 about which separators can be semi-colons and which must be
7362 newlines. Returns the string that should be added into the
7363 history entry. LINE is the line we're about to add; it helps
7364 make some more intelligent decisions in certain cases. */
7366 history_delimiting_chars (line
)
7369 static int last_was_heredoc
= 0; /* was the last entry the start of a here document? */
7372 if ((parser_state
& PST_HEREDOC
) == 0)
7373 last_was_heredoc
= 0;
7375 if (dstack
.delimiter_depth
!= 0)
7378 /* We look for current_command_line_count == 2 because we are looking to
7379 add the first line of the body of the here document (the second line
7380 of the command). We also keep LAST_WAS_HEREDOC as a private sentinel
7381 variable to note when we think we added the first line of a here doc
7382 (the one with a "<<" somewhere in it) */
7383 if (parser_state
& PST_HEREDOC
)
7385 if (last_was_heredoc
)
7387 last_was_heredoc
= 0;
7390 return (current_command_line_count
== 2 ? "\n" : "");
7393 if (parser_state
& PST_COMPASSIGN
)
7396 /* First, handle some special cases. */
7398 /* If we just read `()', assume it's a function definition, and don't
7399 add a semicolon. If the token before the `)' was not `(', and we're
7400 not in the midst of parsing a case statement, assume it's a
7401 parenthesized command and add the semicolon. */
7403 if (token_before_that
== ')')
7405 if (two_tokens_ago
== '(') /*)*/ /* function def */
7407 /* This does not work for subshells inside case statement
7408 command lists. It's a suboptimal solution. */
7409 else if (parser_state
& PST_CASESTMT
) /* case statement pattern */
7412 return "; "; /* (...) subshell */
7414 else if (token_before_that
== WORD
&& two_tokens_ago
== FUNCTION
)
7415 return " "; /* function def using `function name' without `()' */
7417 /* If we're not in a here document, but we think we're about to parse one,
7418 and we would otherwise return a `;', return a newline to delimit the
7419 line with the here-doc delimiter */
7420 else if ((parser_state
& PST_HEREDOC
) == 0 && current_command_line_count
> 1 && last_read_token
== '\n' && strstr (line
, "<<"))
7422 last_was_heredoc
= 1;
7426 else if (token_before_that
== WORD
&& two_tokens_ago
== FOR
)
7428 /* Tricky. `for i\nin ...' should not have a semicolon, but
7429 `for i\ndo ...' should. We do what we can. */
7430 for (i
= shell_input_line_index
; whitespace (shell_input_line
[i
]); i
++)
7432 if (shell_input_line
[i
] && shell_input_line
[i
] == 'i' && shell_input_line
[i
+1] == 'n')
7436 else if (two_tokens_ago
== CASE
&& token_before_that
== WORD
&& (parser_state
& PST_CASESTMT
))
7439 for (i
= 0; no_semi_successors
[i
]; i
++)
7441 if (token_before_that
== no_semi_successors
[i
])
7447 #endif /* HISTORY */
7449 /* Issue a prompt, or prepare to issue a prompt when the next character
7456 if (interactive
== 0 || expanding_alias ()) /* XXX */
7459 ps1_prompt
= get_string_value ("PS1");
7460 ps2_prompt
= get_string_value ("PS2");
7462 if (!prompt_string_pointer
)
7463 prompt_string_pointer
= &ps1_prompt
;
7465 temp_prompt
= *prompt_string_pointer
7466 ? decode_prompt_string (*prompt_string_pointer
)
7469 if (temp_prompt
== 0)
7471 temp_prompt
= (char *)xmalloc (1);
7472 temp_prompt
[0] = '\0';
7475 current_prompt_string
= *prompt_string_pointer
;
7476 prompt_string_pointer
= &ps2_prompt
;
7478 #if defined (READLINE)
7479 if (!no_line_editing
)
7481 FREE (current_readline_prompt
);
7482 current_readline_prompt
= temp_prompt
;
7485 #endif /* READLINE */
7487 FREE (current_decoded_prompt
);
7488 current_decoded_prompt
= temp_prompt
;
7493 get_current_prompt_level ()
7495 return ((current_prompt_string
&& current_prompt_string
== ps2_prompt
) ? 2 : 1);
7499 set_current_prompt_level (x
)
7502 prompt_string_pointer
= (x
== 2) ? &ps2_prompt
: &ps1_prompt
;
7503 current_prompt_string
= *prompt_string_pointer
;
7509 fprintf (stderr
, "%s", current_decoded_prompt
);
7513 /* Return a string which will be printed as a prompt. The string
7514 may contain special characters which are decoded as follows:
7517 \d the date in Day Mon Date format
7518 \e escape (ascii 033)
7519 \h the hostname up to the first `.'
7521 \j the number of active jobs
7522 \l the basename of the shell's tty device name
7525 \s the name of the shell
7526 \t the time in 24-hour hh:mm:ss format
7527 \T the time in 12-hour hh:mm:ss format
7528 \@ the time in 12-hour hh:mm am/pm format
7529 \A the time in 24-hour hh:mm format
7530 \D{fmt} the result of passing FMT to strftime(3)
7532 \v the version of bash (e.g., 2.00)
7533 \V the release of bash, version + patchlevel (e.g., 2.00.0)
7534 \w the current working directory
7535 \W the last element of $PWD
7536 \! the history number of this command
7537 \# the command number of this command
7538 \$ a $ or a # if you are root
7539 \nnn character code nnn in octal
7541 \[ begin a sequence of non-printing chars
7542 \] end a sequence of non-printing chars
7544 #define PROMPT_GROWTH 48
7546 decode_prompt_string (string
)
7551 struct dstack save_dstack
;
7552 int last_exit_value
, last_comsub_pid
;
7553 #if defined (PROMPT_STRING_DECODE)
7554 int result_size
, result_index
;
7556 char *temp
, octal_string
[4];
7562 result
= (char *)xmalloc (result_size
= PROMPT_GROWTH
);
7563 result
[result_index
= 0] = 0;
7564 temp
= (char *)NULL
;
7566 while (c
= *string
++)
7568 if (posixly_correct
&& c
== '!')
7572 temp
= savestring ("!");
7577 #if !defined (HISTORY)
7578 temp
= savestring ("1");
7580 temp
= itos (history_number ());
7581 #endif /* HISTORY */
7582 string
--; /* add_string increments string again. */
7600 strncpy (octal_string
, string
, 3);
7601 octal_string
[3] = '\0';
7603 n
= read_octal (octal_string
);
7604 temp
= (char *)xmalloc (3);
7606 if (n
== CTLESC
|| n
== CTLNUL
)
7623 for (c
= 0; n
!= -1 && c
< 3 && ISOCTAL (*string
); c
++)
7626 c
= 0; /* tested at add_string: */
7634 /* Make the current time/date into a string. */
7635 (void) time (&the_time
);
7636 #if defined (HAVE_TZSET)
7637 sv_tz ("TZ"); /* XXX -- just make sure */
7639 tm
= localtime (&the_time
);
7642 n
= strftime (timebuf
, sizeof (timebuf
), "%a %b %d", tm
);
7644 n
= strftime (timebuf
, sizeof (timebuf
), "%H:%M:%S", tm
);
7646 n
= strftime (timebuf
, sizeof (timebuf
), "%I:%M:%S", tm
);
7648 n
= strftime (timebuf
, sizeof (timebuf
), "%I:%M %p", tm
);
7650 n
= strftime (timebuf
, sizeof (timebuf
), "%H:%M", tm
);
7655 timebuf
[sizeof(timebuf
) - 1] = '\0';
7657 temp
= savestring (timebuf
);
7660 case 'D': /* strftime format */
7661 if (string
[1] != '{') /* } */
7664 (void) time (&the_time
);
7665 tm
= localtime (&the_time
);
7666 string
+= 2; /* skip { */
7667 timefmt
= xmalloc (strlen (string
) + 3);
7668 for (t
= timefmt
; *string
&& *string
!= '}'; )
7671 c
= *string
; /* tested at add_string */
7672 if (timefmt
[0] == '\0')
7675 timefmt
[1] = 'X'; /* locale-specific current time */
7678 n
= strftime (timebuf
, sizeof (timebuf
), timefmt
, tm
);
7684 timebuf
[sizeof(timebuf
) - 1] = '\0';
7686 if (promptvars
|| posixly_correct
)
7687 /* Make sure that expand_prompt_string is called with a
7688 second argument of Q_DOUBLE_QUOTES if we use this
7690 temp
= sh_backslash_quote_for_double_quotes (timebuf
);
7692 temp
= savestring (timebuf
);
7696 temp
= (char *)xmalloc (3);
7697 temp
[0] = no_line_editing
? '\n' : '\r';
7698 temp
[1] = no_line_editing
? '\0' : '\n';
7703 temp
= base_pathname (shell_name
);
7704 temp
= savestring (temp
);
7709 temp
= (char *)xmalloc (16);
7711 strcpy (temp
, dist_version
);
7713 sprintf (temp
, "%s.%d", dist_version
, patch_level
);
7719 /* Use the value of PWD because it is much more efficient. */
7720 char t_string
[PATH_MAX
];
7723 temp
= get_string_value ("PWD");
7727 if (getcwd (t_string
, sizeof(t_string
)) == 0)
7733 tlen
= strlen (t_string
);
7737 tlen
= sizeof (t_string
) - 1;
7738 strncpy (t_string
, temp
, tlen
);
7740 t_string
[tlen
] = '\0';
7742 #if defined (MACOSX)
7743 /* Convert from "fs" format to "input" format */
7744 temp
= fnx_fromfs (t_string
, strlen (t_string
));
7745 if (temp
!= t_string
)
7746 strcpy (t_string
, temp
);
7749 #define ROOT_PATH(x) ((x)[0] == '/' && (x)[1] == 0)
7750 #define DOUBLE_SLASH_ROOT(x) ((x)[0] == '/' && (x)[1] == '/' && (x)[2] == 0)
7751 /* Abbreviate \W as ~ if $PWD == $HOME */
7752 if (c
== 'W' && (((t
= get_string_value ("HOME")) == 0) || STREQ (t
, t_string
) == 0))
7754 if (ROOT_PATH (t_string
) == 0 && DOUBLE_SLASH_ROOT (t_string
) == 0)
7756 t
= strrchr (t_string
, '/');
7758 memmove (t_string
, t
+ 1, strlen (t
)); /* strlen(t) to copy NULL */
7762 #undef DOUBLE_SLASH_ROOT
7765 /* polite_directory_format is guaranteed to return a string
7766 no longer than PATH_MAX - 1 characters. */
7767 temp
= polite_directory_format (t_string
);
7768 if (temp
!= t_string
)
7769 strcpy (t_string
, temp
);
7772 temp
= trim_pathname (t_string
, PATH_MAX
- 1);
7773 /* If we're going to be expanding the prompt string later,
7774 quote the directory name. */
7775 if (promptvars
|| posixly_correct
)
7776 /* Make sure that expand_prompt_string is called with a
7777 second argument of Q_DOUBLE_QUOTES if we use this
7779 temp
= sh_backslash_quote_for_double_quotes (t_string
);
7781 temp
= savestring (t_string
);
7787 if (current_user
.user_name
== 0)
7788 get_current_user_info ();
7789 temp
= savestring (current_user
.user_name
);
7794 temp
= savestring (current_host_name
);
7795 if (c
== 'h' && (t
= (char *)strchr (temp
, '.')))
7800 temp
= itos (current_command_number
);
7804 #if !defined (HISTORY)
7805 temp
= savestring ("1");
7807 temp
= itos (history_number ());
7808 #endif /* HISTORY */
7812 t
= temp
= (char *)xmalloc (3);
7813 if ((promptvars
|| posixly_correct
) && (current_user
.euid
!= 0))
7815 *t
++ = current_user
.euid
== 0 ? '#' : '$';
7820 temp
= itos (count_all_jobs ());
7824 #if defined (HAVE_TTYNAME)
7825 temp
= (char *)ttyname (fileno (stdin
));
7826 t
= temp
? base_pathname (temp
) : "tty";
7827 temp
= savestring (t
);
7829 temp
= savestring ("tty");
7830 #endif /* !HAVE_TTYNAME */
7833 #if defined (READLINE)
7836 if (no_line_editing
)
7841 temp
= (char *)xmalloc (3);
7842 n
= (c
== '[') ? RL_PROMPT_START_IGNORE
: RL_PROMPT_END_IGNORE
;
7844 if (n
== CTLESC
|| n
== CTLNUL
)
7849 #endif /* READLINE */
7855 temp
= (char *)xmalloc (2);
7862 else /* (c == '\\') */
7869 temp
= (char *)xmalloc (3);
7878 sub_append_string (temp
, result
, &result_index
, &result_size
);
7879 temp
= (char *)NULL
; /* Freed in sub_append_string (). */
7880 result
[result_index
] = '\0';
7886 RESIZE_MALLOCED_BUFFER (result
, result_index
, 3, result_size
, PROMPT_GROWTH
);
7887 result
[result_index
++] = c
;
7888 result
[result_index
] = '\0';
7891 #else /* !PROMPT_STRING_DECODE */
7892 result
= savestring (string
);
7893 #endif /* !PROMPT_STRING_DECODE */
7895 /* Save the delimiter stack and point `dstack' to temp space so any
7896 command substitutions in the prompt string won't result in screwing
7897 up the parser's quoting state. */
7898 save_dstack
= dstack
;
7899 dstack
= temp_dstack
;
7900 dstack
.delimiter_depth
= 0;
7902 /* Perform variable and parameter expansion and command substitution on
7903 the prompt string. */
7904 if (promptvars
|| posixly_correct
)
7906 last_exit_value
= last_command_exit_value
;
7907 last_comsub_pid
= last_command_subst_pid
;
7908 list
= expand_prompt_string (result
, Q_DOUBLE_QUOTES
, 0);
7910 result
= string_list (list
);
7911 dispose_words (list
);
7912 last_command_exit_value
= last_exit_value
;
7913 last_command_subst_pid
= last_comsub_pid
;
7917 t
= dequote_string (result
);
7922 dstack
= save_dstack
;
7927 /************************************************
7931 ************************************************/
7933 /* Report a syntax error, and restart the parser. Call here for fatal
7939 report_syntax_error ((char *)NULL
);
7945 error_token_from_token (tok
)
7950 if (t
= find_token_in_alist (tok
, word_token_alist
, 0))
7953 if (t
= find_token_in_alist (tok
, other_token_alist
, 0))
7957 /* This stuff is dicy and needs closer inspection */
7958 switch (current_token
)
7961 case ASSIGNMENT_WORD
:
7963 t
= savestring (yylval
.word
->word
);
7966 t
= itos (yylval
.number
);
7969 if (yylval
.word_list
)
7970 t
= string_list (yylval
.word_list
);
7972 case ARITH_FOR_EXPRS
:
7973 if (yylval
.word_list
)
7974 t
= string_list_internal (yylval
.word_list
, " ; ");
7977 t
= (char *)NULL
; /* punt */
7985 error_token_from_text ()
7990 t
= shell_input_line
;
7991 i
= shell_input_line_index
;
7995 if (i
&& t
[i
] == '\0')
7998 while (i
&& (whitespace (t
[i
]) || t
[i
] == '\n'))
8004 while (i
&& (member (t
[i
], " \n\t;|&") == 0))
8007 while (i
!= token_end
&& (whitespace (t
[i
]) || t
[i
] == '\n'))
8010 /* Return our idea of the offending token. */
8011 if (token_end
|| (i
== 0 && token_end
== 0))
8014 msg
= substring (t
, i
, token_end
);
8015 else /* one-character token */
8017 msg
= (char *)xmalloc (2);
8027 print_offending_line ()
8032 msg
= savestring (shell_input_line
);
8033 token_end
= strlen (msg
);
8034 while (token_end
&& msg
[token_end
- 1] == '\n')
8035 msg
[--token_end
] = '\0';
8037 parser_error (line_number
, "`%s'", msg
);
8041 /* Report a syntax error with line numbers, etc.
8042 Call here for recoverable errors. If you have a message to print,
8043 then place it in MESSAGE, otherwise pass NULL and this will figure
8044 out an appropriate message for you. */
8046 report_syntax_error (message
)
8053 parser_error (line_number
, "%s", message
);
8054 if (interactive
&& EOF_Reached
)
8056 last_command_exit_value
= parse_and_execute_level
? EX_BADSYNTAX
: EX_BADUSAGE
;
8060 /* If the line of input we're reading is not null, try to find the
8061 objectionable token. First, try to figure out what token the
8062 parser's complaining about by looking at current_token. */
8063 if (current_token
!= 0 && EOF_Reached
== 0 && (msg
= error_token_from_token (current_token
)))
8065 if (ansic_shouldquote (msg
))
8067 p
= ansic_quote (msg
, 0, NULL
);
8071 parser_error (line_number
, _("syntax error near unexpected token `%s'"), msg
);
8074 if (interactive
== 0)
8075 print_offending_line ();
8077 last_command_exit_value
= parse_and_execute_level
? EX_BADSYNTAX
: EX_BADUSAGE
;
8081 /* If looking at the current token doesn't prove fruitful, try to find the
8082 offending token by analyzing the text of the input line near the current
8083 input line index and report what we find. */
8084 if (shell_input_line
&& *shell_input_line
)
8086 msg
= error_token_from_text ();
8089 parser_error (line_number
, _("syntax error near `%s'"), msg
);
8093 /* If not interactive, print the line containing the error. */
8094 if (interactive
== 0)
8095 print_offending_line ();
8099 msg
= EOF_Reached
? _("syntax error: unexpected end of file") : _("syntax error");
8100 parser_error (line_number
, "%s", msg
);
8101 /* When the shell is interactive, this file uses EOF_Reached
8102 only for error reporting. Other mechanisms are used to
8103 decide whether or not to exit. */
8104 if (interactive
&& EOF_Reached
)
8108 last_command_exit_value
= parse_and_execute_level
? EX_BADSYNTAX
: EX_BADUSAGE
;
8111 /* ??? Needed function. ??? We have to be able to discard the constructs
8112 created during parsing. In the case of error, we want to return
8113 allocated objects to the memory pool. In the case of no error, we want
8114 to throw away the information about where the allocated objects live.
8115 (dispose_command () will actually free the command.) */
8117 discard_parser_constructs (error_p
)
8122 /************************************************
8126 ************************************************/
8128 /* Do that silly `type "bye" to exit' stuff. You know, "ignoreeof". */
8130 /* A flag denoting whether or not ignoreeof is set. */
8133 /* The number of times that we have encountered an EOF character without
8134 another character intervening. When this gets above the limit, the
8135 shell terminates. */
8136 int eof_encountered
= 0;
8138 /* The limit for eof_encountered. */
8139 int eof_encountered_limit
= 10;
8141 /* If we have EOF as the only input unit, this user wants to leave
8142 the shell. If the shell is not interactive, then just leave.
8143 Otherwise, if ignoreeof is set, and we haven't done this the
8144 required number of times in a row, print a message. */
8146 handle_eof_input_unit ()
8150 /* shell.c may use this to decide whether or not to write out the
8151 history, among other things. We use it only for error reporting
8156 /* If the user wants to "ignore" eof, then let her do so, kind of. */
8159 if (eof_encountered
< eof_encountered_limit
)
8161 fprintf (stderr
, _("Use \"%s\" to leave the shell.\n"),
8162 login_shell
? "logout" : "exit");
8164 /* Reset the parsing state. */
8165 last_read_token
= current_token
= '\n';
8166 /* Reset the prompt string to be $PS1. */
8167 prompt_string_pointer
= (char **)NULL
;
8173 /* In this case EOF should exit the shell. Do it now. */
8175 exit_builtin ((WORD_LIST
*)NULL
);
8179 /* We don't write history files, etc., for non-interactive shells. */
8184 /************************************************
8186 * STRING PARSING FUNCTIONS *
8188 ************************************************/
8190 /* It's very important that these two functions treat the characters
8191 between ( and ) identically. */
8193 static WORD_LIST parse_string_error
;
8195 /* Take a string and run it through the shell parser, returning the
8196 resultant word list. Used by compound array assignment. */
8198 parse_string_to_word_list (s
, flags
, whom
)
8204 int tok
, orig_current_token
, orig_line_number
, orig_input_terminator
;
8205 int orig_line_count
;
8206 int old_echo_input
, old_expand_aliases
;
8207 #if defined (HISTORY)
8208 int old_remember_on_history
, old_history_expansion_inhibited
;
8211 #if defined (HISTORY)
8212 old_remember_on_history
= remember_on_history
;
8213 # if defined (BANG_HISTORY)
8214 old_history_expansion_inhibited
= history_expansion_inhibited
;
8216 bash_history_disable ();
8219 orig_line_number
= line_number
;
8220 orig_line_count
= current_command_line_count
;
8221 orig_input_terminator
= shell_input_line_terminator
;
8222 old_echo_input
= echo_input_at_read
;
8223 old_expand_aliases
= expand_aliases
;
8226 last_read_token
= WORD
; /* WORD to allow reserved words here */
8227 current_command_line_count
= 0;
8228 echo_input_at_read
= expand_aliases
= 0;
8230 with_input_from_string (s
, whom
);
8231 wl
= (WORD_LIST
*)NULL
;
8234 parser_state
|= PST_COMPASSIGN
|PST_REPARSE
;
8236 while ((tok
= read_token (READ
)) != yacc_EOF
)
8238 if (tok
== '\n' && *bash_input
.location
.string
== '\0')
8240 if (tok
== '\n') /* Allow newlines in compound assignments */
8242 if (tok
!= WORD
&& tok
!= ASSIGNMENT_WORD
)
8244 line_number
= orig_line_number
+ line_number
- 1;
8245 orig_current_token
= current_token
;
8246 current_token
= tok
;
8247 yyerror (NULL
); /* does the right thing */
8248 current_token
= orig_current_token
;
8251 wl
= &parse_string_error
;
8254 wl
= make_word_list (yylval
.word
, wl
);
8257 last_read_token
= '\n';
8260 #if defined (HISTORY)
8261 remember_on_history
= old_remember_on_history
;
8262 # if defined (BANG_HISTORY)
8263 history_expansion_inhibited
= old_history_expansion_inhibited
;
8264 # endif /* BANG_HISTORY */
8265 #endif /* HISTORY */
8267 echo_input_at_read
= old_echo_input
;
8268 expand_aliases
= old_expand_aliases
;
8270 current_command_line_count
= orig_line_count
;
8271 shell_input_line_terminator
= orig_input_terminator
;
8274 parser_state
&= ~(PST_COMPASSIGN
|PST_REPARSE
);
8276 if (wl
== &parse_string_error
)
8278 last_command_exit_value
= EXECUTION_FAILURE
;
8279 if (interactive_shell
== 0 && posixly_correct
)
8280 jump_to_top_level (FORCE_EOF
);
8282 jump_to_top_level (DISCARD
);
8285 return (REVERSE_LIST (wl
, WORD_LIST
*));
8289 parse_compound_assignment (retlenp
)
8293 int tok
, orig_line_number
, orig_token_size
, orig_last_token
, assignok
;
8294 char *saved_token
, *ret
;
8296 saved_token
= token
;
8297 orig_token_size
= token_buffer_size
;
8298 orig_line_number
= line_number
;
8299 orig_last_token
= last_read_token
;
8301 last_read_token
= WORD
; /* WORD to allow reserved words here */
8303 token
= (char *)NULL
;
8304 token_buffer_size
= 0;
8306 assignok
= parser_state
&PST_ASSIGNOK
; /* XXX */
8308 wl
= (WORD_LIST
*)NULL
; /* ( */
8309 parser_state
|= PST_COMPASSIGN
;
8311 while ((tok
= read_token (READ
)) != ')')
8313 if (tok
== '\n') /* Allow newlines in compound assignments */
8315 if (SHOULD_PROMPT ())
8319 if (tok
!= WORD
&& tok
!= ASSIGNMENT_WORD
)
8321 current_token
= tok
; /* for error reporting */
8322 if (tok
== yacc_EOF
) /* ( */
8323 parser_error (orig_line_number
, _("unexpected EOF while looking for matching `)'"));
8325 yyerror(NULL
); /* does the right thing */
8328 wl
= &parse_string_error
;
8331 wl
= make_word_list (yylval
.word
, wl
);
8335 token
= saved_token
;
8336 token_buffer_size
= orig_token_size
;
8338 parser_state
&= ~PST_COMPASSIGN
;
8340 if (wl
== &parse_string_error
)
8342 last_command_exit_value
= EXECUTION_FAILURE
;
8343 last_read_token
= '\n'; /* XXX */
8344 if (interactive_shell
== 0 && posixly_correct
)
8345 jump_to_top_level (FORCE_EOF
);
8347 jump_to_top_level (DISCARD
);
8350 last_read_token
= orig_last_token
; /* XXX - was WORD? */
8354 rl
= REVERSE_LIST (wl
, WORD_LIST
*);
8355 ret
= string_list (rl
);
8362 *retlenp
= (ret
&& *ret
) ? strlen (ret
) : 0;
8365 parser_state
|= PST_ASSIGNOK
;
8370 /************************************************
8372 * SAVING AND RESTORING PARTIAL PARSE STATE *
8374 ************************************************/
8377 save_parser_state (ps
)
8378 sh_parser_state_t
*ps
;
8381 ps
= (sh_parser_state_t
*)xmalloc (sizeof (sh_parser_state_t
));
8383 return ((sh_parser_state_t
*)NULL
);
8385 ps
->parser_state
= parser_state
;
8386 ps
->token_state
= save_token_state ();
8388 ps
->input_line_terminator
= shell_input_line_terminator
;
8389 ps
->eof_encountered
= eof_encountered
;
8391 ps
->prompt_string_pointer
= prompt_string_pointer
;
8393 ps
->current_command_line_count
= current_command_line_count
;
8395 #if defined (HISTORY)
8396 ps
->remember_on_history
= remember_on_history
;
8397 # if defined (BANG_HISTORY)
8398 ps
->history_expansion_inhibited
= history_expansion_inhibited
;
8402 ps
->last_command_exit_value
= last_command_exit_value
;
8403 #if defined (ARRAY_VARS)
8404 ps
->pipestatus
= save_pipestatus_array ();
8407 ps
->last_shell_builtin
= last_shell_builtin
;
8408 ps
->this_shell_builtin
= this_shell_builtin
;
8410 ps
->expand_aliases
= expand_aliases
;
8411 ps
->echo_input_at_read
= echo_input_at_read
;
8412 ps
->need_here_doc
= need_here_doc
;
8415 ps
->token_buffer_size
= token_buffer_size
;
8416 /* Force reallocation on next call to read_token_word */
8418 token_buffer_size
= 0;
8424 restore_parser_state (ps
)
8425 sh_parser_state_t
*ps
;
8430 parser_state
= ps
->parser_state
;
8431 if (ps
->token_state
)
8433 restore_token_state (ps
->token_state
);
8434 free (ps
->token_state
);
8437 shell_input_line_terminator
= ps
->input_line_terminator
;
8438 eof_encountered
= ps
->eof_encountered
;
8440 prompt_string_pointer
= ps
->prompt_string_pointer
;
8442 current_command_line_count
= ps
->current_command_line_count
;
8444 #if defined (HISTORY)
8445 remember_on_history
= ps
->remember_on_history
;
8446 # if defined (BANG_HISTORY)
8447 history_expansion_inhibited
= ps
->history_expansion_inhibited
;
8451 last_command_exit_value
= ps
->last_command_exit_value
;
8452 #if defined (ARRAY_VARS)
8453 restore_pipestatus_array (ps
->pipestatus
);
8456 last_shell_builtin
= ps
->last_shell_builtin
;
8457 this_shell_builtin
= ps
->this_shell_builtin
;
8459 expand_aliases
= ps
->expand_aliases
;
8460 echo_input_at_read
= ps
->echo_input_at_read
;
8461 need_here_doc
= ps
->need_here_doc
;
8465 token_buffer_size
= ps
->token_buffer_size
;
8468 sh_input_line_state_t
*
8469 save_input_line_state (ls
)
8470 sh_input_line_state_t
*ls
;
8473 ls
= (sh_input_line_state_t
*)xmalloc (sizeof (sh_input_line_state_t
));
8475 return ((sh_input_line_state_t
*)NULL
);
8477 ls
->input_line
= shell_input_line
;
8478 ls
->input_line_size
= shell_input_line_size
;
8479 ls
->input_line_len
= shell_input_line_len
;
8480 ls
->input_line_index
= shell_input_line_index
;
8482 /* force reallocation */
8483 shell_input_line
= 0;
8484 shell_input_line_size
= shell_input_line_len
= shell_input_line_index
= 0;
8490 restore_input_line_state (ls
)
8491 sh_input_line_state_t
*ls
;
8493 FREE (shell_input_line
);
8494 shell_input_line
= ls
->input_line
;
8495 shell_input_line_size
= ls
->input_line_size
;
8496 shell_input_line_len
= ls
->input_line_len
;
8497 shell_input_line_index
= ls
->input_line_index
;
8499 set_line_mbstate ();
8502 /************************************************
8504 * MULTIBYTE CHARACTER HANDLING *
8506 ************************************************/
8508 #if defined (HANDLE_MULTIBYTE)
8513 size_t i
, previ
, len
;
8514 mbstate_t mbs
, prevs
;
8517 if (shell_input_line
== NULL
)
8519 len
= strlen (shell_input_line
); /* XXX - shell_input_line_len ? */
8520 FREE (shell_input_line_property
);
8521 shell_input_line_property
= (char *)xmalloc (len
+ 1);
8523 memset (&prevs
, '\0', sizeof (mbstate_t));
8524 for (i
= previ
= 0; i
< len
; i
++)
8528 c
= shell_input_line
[i
];
8532 for (j
= i
; j
< len
; j
++)
8533 shell_input_line_property
[j
] = 1;
8537 mbclen
= mbrlen (shell_input_line
+ previ
, i
- previ
+ 1, &mbs
);
8538 if (mbclen
== 1 || mbclen
== (size_t)-1)
8543 else if (mbclen
== (size_t)-2)
8545 else if (mbclen
> 1)
8553 /* XXX - what to do if mbrlen returns 0? (null wide character) */
8555 for (j
= i
; j
< len
; j
++)
8556 shell_input_line_property
[j
] = 1;
8560 shell_input_line_property
[i
] = mbclen
;
8563 #endif /* HANDLE_MULTIBYTE */