1 /* A Bison parser, made by GNU Bison 3.6.4. */
3 /* Bison implementation for Yacc-like parsers in C
5 Copyright (C) 1984, 1989-1990, 2000-2015, 2018-2020 Free Software Foundation,
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 3 of the License, or
11 (at your option) any later version.
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, see <http://www.gnu.org/licenses/>. */
21 /* As a special exception, you may create a larger work that contains
22 part or all of the Bison parser skeleton and distribute that work
23 under terms of your choice, so long as that work isn't itself a
24 parser generator using the skeleton or a modified version thereof
25 as a parser skeleton. Alternatively, if you modify or redistribute
26 the parser skeleton itself, you may (at your option) remove this
27 special exception, which will cause the skeleton and the resulting
28 Bison output files to be licensed under the GNU General Public
29 License without this special exception.
31 This special exception was added by the Free Software Foundation in
32 version 2.2 of Bison. */
34 /* C LALR(1) parser skeleton written by Richard Stallman, by
35 simplifying the original so-called "semantic" parser. */
37 /* DO NOT RELY ON FEATURES THAT ARE NOT DOCUMENTED in the manual,
38 especially those whose name start with YY_ or yy_. They are
39 private implementation details that can be changed or removed. */
41 /* All symbols defined below should begin with yy or YY, to avoid
42 infringing on user name space. This should be done even for local
43 variables, as they might otherwise be expanded by user macros.
44 There are some unavoidable exceptions within include files to
45 define necessary library symbols; they are noted "INFRINGES ON
46 USER NAME SPACE" below. */
48 /* Identify Bison output. */
52 #define YYBISON_VERSION "3.6.4"
55 #define YYSKELETON_NAME "yacc.c"
69 /* First part of user prologue. */
70 #line 21 "/Users/chet/src/bash/src/parse.y"
74 #include "bashtypes.h"
79 #if defined (HAVE_UNISTD_H)
83 #if defined (HAVE_LOCALE_H)
88 #include "chartypes.h"
95 #define NEED_STRFTIME_DECL /* used in externs.h */
98 #include "execute_cmd.h"
99 #include "typemax.h" /* SIZE_MAX if needed */
103 #include "mailcheck.h"
105 #include "builtins.h"
106 #include "builtins/common.h"
107 #include "builtins/builtext.h"
109 #include "shmbutil.h"
111 #if defined (READLINE)
112 # include "bashline.h"
113 # include <readline/readline.h>
114 #endif /* READLINE */
116 #if defined (HISTORY)
117 # include "bashhist.h"
118 # include <readline/history.h>
121 #if defined (JOB_CONTROL)
124 extern int cleanup_dead_jobs
PARAMS((void));
125 #endif /* JOB_CONTROL */
130 typedef void *alias_t
;
133 #if defined (PROMPT_STRING_DECODE)
135 # include <sys/param.h>
138 # if defined (TM_IN_SYS_TIME)
139 # include <sys/types.h>
140 # include <sys/time.h>
141 # endif /* TM_IN_SYS_TIME */
142 # include "maxpath.h"
143 #endif /* PROMPT_STRING_DECODE */
145 #define RE_READ_TOKEN -99
146 #define NO_EXPANSION -100
156 #if defined (HANDLE_MULTIBYTE)
157 # define last_shell_getc_is_singlebyte \
158 ((shell_input_line_index > 1) \
159 ? shell_input_line_property[shell_input_line_index - 1] \
161 # define MBTEST(x) ((x) && last_shell_getc_is_singlebyte)
163 # define last_shell_getc_is_singlebyte 1
164 # define MBTEST(x) ((x))
167 #if defined (EXTENDED_GLOB)
168 extern int extended_glob
;
171 extern int dump_translatable_strings
, dump_po_strings
;
177 /* **************************************************************** */
179 /* "Forward" declarations */
181 /* **************************************************************** */
184 static void debug_parser
PARAMS((int));
187 static int yy_getc
PARAMS((void));
188 static int yy_ungetc
PARAMS((int));
190 #if defined (READLINE)
191 static int yy_readline_get
PARAMS((void));
192 static int yy_readline_unget
PARAMS((int));
195 static int yy_string_get
PARAMS((void));
196 static int yy_string_unget
PARAMS((int));
197 static void rewind_input_string
PARAMS((void));
198 static int yy_stream_get
PARAMS((void));
199 static int yy_stream_unget
PARAMS((int));
201 static int shell_getc
PARAMS((int));
202 static void shell_ungetc
PARAMS((int));
203 static void discard_until
PARAMS((int));
205 #if defined (ALIAS) || defined (DPAREN_ARITHMETIC)
206 static void push_string
PARAMS((char *, int, alias_t
*));
207 static void pop_string
PARAMS((void));
208 static void free_string_list
PARAMS((void));
211 static char *read_a_line
PARAMS((int));
213 static int reserved_word_acceptable
PARAMS((int));
214 static int yylex
PARAMS((void));
216 static void push_heredoc
PARAMS((REDIRECT
*));
217 static char *mk_alexpansion
PARAMS((char *));
218 static int alias_expand_token
PARAMS((char *));
219 static int time_command_acceptable
PARAMS((void));
220 static int special_case_tokens
PARAMS((char *));
221 static int read_token
PARAMS((int));
222 static char *parse_matched_pair
PARAMS((int, int, int, int *, int));
223 static char *parse_comsub
PARAMS((int, int, int, int *, int));
224 #if defined (ARRAY_VARS)
225 static char *parse_compound_assignment
PARAMS((int *));
227 #if defined (DPAREN_ARITHMETIC) || defined (ARITH_FOR_COMMAND)
228 static int parse_dparen
PARAMS((int));
229 static int parse_arith_cmd
PARAMS((char **, int));
231 #if defined (COND_COMMAND)
232 static void cond_error
PARAMS((void));
233 static COND_COM
*cond_expr
PARAMS((void));
234 static COND_COM
*cond_or
PARAMS((void));
235 static COND_COM
*cond_and
PARAMS((void));
236 static COND_COM
*cond_term
PARAMS((void));
237 static int cond_skip_newlines
PARAMS((void));
238 static COMMAND
*parse_cond_command
PARAMS((void));
240 #if defined (ARRAY_VARS)
241 static int token_is_assignment
PARAMS((char *, int));
242 static int token_is_ident
PARAMS((char *, int));
244 static int read_token_word
PARAMS((int));
245 static void discard_parser_constructs
PARAMS((int));
247 static char *error_token_from_token
PARAMS((int));
248 static char *error_token_from_text
PARAMS((void));
249 static void print_offending_line
PARAMS((void));
250 static void report_syntax_error
PARAMS((char *));
252 static void handle_eof_input_unit
PARAMS((void));
253 static void prompt_again
PARAMS((void));
255 static void reset_readline_prompt
PARAMS((void));
257 static void print_prompt
PARAMS((void));
259 #if defined (HANDLE_MULTIBYTE)
260 static void set_line_mbstate
PARAMS((void));
261 static char *shell_input_line_property
= NULL
;
262 static size_t shell_input_line_propsize
= 0;
264 # define set_line_mbstate()
267 extern int yyerror
PARAMS((const char *));
273 /* Default prompt strings */
274 char *primary_prompt
= PPROMPT
;
275 char *secondary_prompt
= SPROMPT
;
277 /* PROMPT_STRING_POINTER points to one of these, never to an actual string. */
278 char *ps1_prompt
, *ps2_prompt
;
280 /* Displayed after reading a command but before executing it in an interactive shell */
283 /* Handle on the current prompt string. Indirectly points through
284 ps1_ or ps2_prompt. */
285 char **prompt_string_pointer
= (char **)NULL
;
286 char *current_prompt_string
;
288 /* Non-zero means we expand aliases in commands. */
289 int expand_aliases
= 0;
291 /* If non-zero, the decoded prompt string undergoes parameter and
292 variable substitution, command substitution, arithmetic substitution,
293 string expansion, process substitution, and quote removal in
294 decode_prompt_string. */
297 /* If non-zero, $'...' and $"..." are expanded when they appear within
298 a ${...} expansion, even when the expansion appears within double
300 int extended_quote
= 1;
302 /* The number of lines read from input while creating the current command. */
303 int current_command_line_count
;
305 /* The number of lines in a command saved while we run parse_and_execute */
306 int saved_command_line_count
;
308 /* The token that currently denotes the end of parse. */
311 /* The token currently being read. */
314 /* The current parser state. */
317 /* Variables to manage the task of reading here documents, because we need to
318 defer the reading until after a complete command has been collected. */
319 static REDIRECT
*redir_stack
[HEREDOC_MAX
];
322 /* Where shell input comes from. History expansion is performed on each
323 line when the shell is interactive. */
324 static char *shell_input_line
= (char *)NULL
;
325 static size_t shell_input_line_index
;
326 static size_t shell_input_line_size
; /* Amount allocated for shell_input_line. */
327 static size_t shell_input_line_len
; /* strlen (shell_input_line) */
329 /* Either zero or EOF. */
330 static int shell_input_line_terminator
;
332 /* The line number in a script on which a function definition starts. */
333 static int function_dstart
;
335 /* The line number in a script on which a function body starts. */
336 static int function_bstart
;
338 /* The line number in a script at which an arithmetic for command starts. */
339 static int arith_for_lineno
;
341 /* The decoded prompt string. Used if READLINE is not defined or if
342 editing is turned off. Analogous to current_readline_prompt. */
343 static char *current_decoded_prompt
;
345 /* The last read token, or NULL. read_token () uses this for context
347 static int last_read_token
;
349 /* The token read prior to last_read_token. */
350 static int token_before_that
;
352 /* The token read prior to token_before_that. */
353 static int two_tokens_ago
;
355 static int global_extglob
;
357 /* The line number in a script where the word in a `case WORD', `select WORD'
358 or `for WORD' begins. This is a nested command maximum, since the array
359 index is decremented after a case, select, or for command is parsed. */
360 #define MAX_CASE_NEST 128
361 static int word_lineno
[MAX_CASE_NEST
+1];
362 static int word_top
= -1;
364 /* If non-zero, it is the token that we want read_token to return
365 regardless of what text is (or isn't) present to be read. This
366 is reset by read_token. If token_to_read == WORD or
367 ASSIGNMENT_WORD, yylval.word should be set to word_desc_to_read. */
368 static int token_to_read
;
369 static WORD_DESC
*word_desc_to_read
;
371 static REDIRECTEE source
;
372 static REDIRECTEE redir
;
374 static FILE *yyoutstream
;
375 static FILE *yyerrstream
;
381 # define YY_CAST(Type, Val) static_cast<Type> (Val)
382 # define YY_REINTERPRET_CAST(Type, Val) reinterpret_cast<Type> (Val)
384 # define YY_CAST(Type, Val) ((Type) (Val))
385 # define YY_REINTERPRET_CAST(Type, Val) ((Type) (Val))
389 # if defined __cplusplus
390 # if 201103L <= __cplusplus
391 # define YY_NULLPTR nullptr
393 # define YY_NULLPTR 0
396 # define YY_NULLPTR ((void*)0)
400 /* Use api.header.include to #include this header
401 instead of duplicating it here. */
402 #ifndef YY_YY_Y_TAB_H_INCLUDED
403 # define YY_YY_Y_TAB_H_INCLUDED
418 YYEOF
= 0, /* "end of file" */
419 YYerror
= 256, /* error */
420 YYUNDEF
= 257, /* "invalid token" */
422 THEN
= 259, /* THEN */
423 ELSE
= 260, /* ELSE */
424 ELIF
= 261, /* ELIF */
426 CASE
= 263, /* CASE */
427 ESAC
= 264, /* ESAC */
429 SELECT
= 266, /* SELECT */
430 WHILE
= 267, /* WHILE */
431 UNTIL
= 268, /* UNTIL */
433 DONE
= 270, /* DONE */
434 FUNCTION
= 271, /* FUNCTION */
435 COPROC
= 272, /* COPROC */
436 COND_START
= 273, /* COND_START */
437 COND_END
= 274, /* COND_END */
438 COND_ERROR
= 275, /* COND_ERROR */
440 BANG
= 277, /* BANG */
441 TIME
= 278, /* TIME */
442 TIMEOPT
= 279, /* TIMEOPT */
443 TIMEIGN
= 280, /* TIMEIGN */
444 WORD
= 281, /* WORD */
445 ASSIGNMENT_WORD
= 282, /* ASSIGNMENT_WORD */
446 REDIR_WORD
= 283, /* REDIR_WORD */
447 NUMBER
= 284, /* NUMBER */
448 ARITH_CMD
= 285, /* ARITH_CMD */
449 ARITH_FOR_EXPRS
= 286, /* ARITH_FOR_EXPRS */
450 COND_CMD
= 287, /* COND_CMD */
451 AND_AND
= 288, /* AND_AND */
452 OR_OR
= 289, /* OR_OR */
453 GREATER_GREATER
= 290, /* GREATER_GREATER */
454 LESS_LESS
= 291, /* LESS_LESS */
455 LESS_AND
= 292, /* LESS_AND */
456 LESS_LESS_LESS
= 293, /* LESS_LESS_LESS */
457 GREATER_AND
= 294, /* GREATER_AND */
458 SEMI_SEMI
= 295, /* SEMI_SEMI */
459 SEMI_AND
= 296, /* SEMI_AND */
460 SEMI_SEMI_AND
= 297, /* SEMI_SEMI_AND */
461 LESS_LESS_MINUS
= 298, /* LESS_LESS_MINUS */
462 AND_GREATER
= 299, /* AND_GREATER */
463 AND_GREATER_GREATER
= 300, /* AND_GREATER_GREATER */
464 LESS_GREATER
= 301, /* LESS_GREATER */
465 GREATER_BAR
= 302, /* GREATER_BAR */
466 BAR_AND
= 303, /* BAR_AND */
467 yacc_EOF
= 304 /* yacc_EOF */
469 typedef enum yytokentype yytoken_kind_t
;
490 #define COND_START 273
492 #define COND_ERROR 275
499 #define ASSIGNMENT_WORD 282
500 #define REDIR_WORD 283
502 #define ARITH_CMD 285
503 #define ARITH_FOR_EXPRS 286
507 #define GREATER_GREATER 290
508 #define LESS_LESS 291
510 #define LESS_LESS_LESS 293
511 #define GREATER_AND 294
512 #define SEMI_SEMI 295
514 #define SEMI_SEMI_AND 297
515 #define LESS_LESS_MINUS 298
516 #define AND_GREATER 299
517 #define AND_GREATER_GREATER 300
518 #define LESS_GREATER 301
519 #define GREATER_BAR 302
524 #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
527 #line 328 "/Users/chet/src/bash/src/parse.y"
529 WORD_DESC
*word
; /* the word that we read. */
530 int number
; /* the number that we read. */
531 WORD_LIST
*word_list
;
535 PATTERN_LIST
*pattern
;
540 typedef union YYSTYPE YYSTYPE
;
541 # define YYSTYPE_IS_TRIVIAL 1
542 # define YYSTYPE_IS_DECLARED 1
546 extern YYSTYPE yylval
;
550 #endif /* !YY_YY_Y_TAB_H_INCLUDED */
554 YYSYMBOL_YYEMPTY
= -2,
555 YYSYMBOL_YYEOF
= 0, /* "end of file" */
556 YYSYMBOL_YYerror
= 1, /* error */
557 YYSYMBOL_YYUNDEF
= 2, /* "invalid token" */
558 YYSYMBOL_IF
= 3, /* IF */
559 YYSYMBOL_THEN
= 4, /* THEN */
560 YYSYMBOL_ELSE
= 5, /* ELSE */
561 YYSYMBOL_ELIF
= 6, /* ELIF */
562 YYSYMBOL_FI
= 7, /* FI */
563 YYSYMBOL_CASE
= 8, /* CASE */
564 YYSYMBOL_ESAC
= 9, /* ESAC */
565 YYSYMBOL_FOR
= 10, /* FOR */
566 YYSYMBOL_SELECT
= 11, /* SELECT */
567 YYSYMBOL_WHILE
= 12, /* WHILE */
568 YYSYMBOL_UNTIL
= 13, /* UNTIL */
569 YYSYMBOL_DO
= 14, /* DO */
570 YYSYMBOL_DONE
= 15, /* DONE */
571 YYSYMBOL_FUNCTION
= 16, /* FUNCTION */
572 YYSYMBOL_COPROC
= 17, /* COPROC */
573 YYSYMBOL_COND_START
= 18, /* COND_START */
574 YYSYMBOL_COND_END
= 19, /* COND_END */
575 YYSYMBOL_COND_ERROR
= 20, /* COND_ERROR */
576 YYSYMBOL_IN
= 21, /* IN */
577 YYSYMBOL_BANG
= 22, /* BANG */
578 YYSYMBOL_TIME
= 23, /* TIME */
579 YYSYMBOL_TIMEOPT
= 24, /* TIMEOPT */
580 YYSYMBOL_TIMEIGN
= 25, /* TIMEIGN */
581 YYSYMBOL_WORD
= 26, /* WORD */
582 YYSYMBOL_ASSIGNMENT_WORD
= 27, /* ASSIGNMENT_WORD */
583 YYSYMBOL_REDIR_WORD
= 28, /* REDIR_WORD */
584 YYSYMBOL_NUMBER
= 29, /* NUMBER */
585 YYSYMBOL_ARITH_CMD
= 30, /* ARITH_CMD */
586 YYSYMBOL_ARITH_FOR_EXPRS
= 31, /* ARITH_FOR_EXPRS */
587 YYSYMBOL_COND_CMD
= 32, /* COND_CMD */
588 YYSYMBOL_AND_AND
= 33, /* AND_AND */
589 YYSYMBOL_OR_OR
= 34, /* OR_OR */
590 YYSYMBOL_GREATER_GREATER
= 35, /* GREATER_GREATER */
591 YYSYMBOL_LESS_LESS
= 36, /* LESS_LESS */
592 YYSYMBOL_LESS_AND
= 37, /* LESS_AND */
593 YYSYMBOL_LESS_LESS_LESS
= 38, /* LESS_LESS_LESS */
594 YYSYMBOL_GREATER_AND
= 39, /* GREATER_AND */
595 YYSYMBOL_SEMI_SEMI
= 40, /* SEMI_SEMI */
596 YYSYMBOL_SEMI_AND
= 41, /* SEMI_AND */
597 YYSYMBOL_SEMI_SEMI_AND
= 42, /* SEMI_SEMI_AND */
598 YYSYMBOL_LESS_LESS_MINUS
= 43, /* LESS_LESS_MINUS */
599 YYSYMBOL_AND_GREATER
= 44, /* AND_GREATER */
600 YYSYMBOL_AND_GREATER_GREATER
= 45, /* AND_GREATER_GREATER */
601 YYSYMBOL_LESS_GREATER
= 46, /* LESS_GREATER */
602 YYSYMBOL_GREATER_BAR
= 47, /* GREATER_BAR */
603 YYSYMBOL_BAR_AND
= 48, /* BAR_AND */
604 YYSYMBOL_49_
= 49, /* '&' */
605 YYSYMBOL_50_
= 50, /* ';' */
606 YYSYMBOL_51_n_
= 51, /* '\n' */
607 YYSYMBOL_yacc_EOF
= 52, /* yacc_EOF */
608 YYSYMBOL_53_
= 53, /* '|' */
609 YYSYMBOL_54_
= 54, /* '>' */
610 YYSYMBOL_55_
= 55, /* '<' */
611 YYSYMBOL_56_
= 56, /* '-' */
612 YYSYMBOL_57_
= 57, /* '{' */
613 YYSYMBOL_58_
= 58, /* '}' */
614 YYSYMBOL_59_
= 59, /* '(' */
615 YYSYMBOL_60_
= 60, /* ')' */
616 YYSYMBOL_YYACCEPT
= 61, /* $accept */
617 YYSYMBOL_inputunit
= 62, /* inputunit */
618 YYSYMBOL_word_list
= 63, /* word_list */
619 YYSYMBOL_redirection
= 64, /* redirection */
620 YYSYMBOL_simple_command_element
= 65, /* simple_command_element */
621 YYSYMBOL_redirection_list
= 66, /* redirection_list */
622 YYSYMBOL_simple_command
= 67, /* simple_command */
623 YYSYMBOL_command
= 68, /* command */
624 YYSYMBOL_shell_command
= 69, /* shell_command */
625 YYSYMBOL_for_command
= 70, /* for_command */
626 YYSYMBOL_arith_for_command
= 71, /* arith_for_command */
627 YYSYMBOL_select_command
= 72, /* select_command */
628 YYSYMBOL_case_command
= 73, /* case_command */
629 YYSYMBOL_function_def
= 74, /* function_def */
630 YYSYMBOL_function_body
= 75, /* function_body */
631 YYSYMBOL_subshell
= 76, /* subshell */
632 YYSYMBOL_coproc
= 77, /* coproc */
633 YYSYMBOL_if_command
= 78, /* if_command */
634 YYSYMBOL_group_command
= 79, /* group_command */
635 YYSYMBOL_arith_command
= 80, /* arith_command */
636 YYSYMBOL_cond_command
= 81, /* cond_command */
637 YYSYMBOL_elif_clause
= 82, /* elif_clause */
638 YYSYMBOL_case_clause
= 83, /* case_clause */
639 YYSYMBOL_pattern_list
= 84, /* pattern_list */
640 YYSYMBOL_case_clause_sequence
= 85, /* case_clause_sequence */
641 YYSYMBOL_pattern
= 86, /* pattern */
642 YYSYMBOL_list
= 87, /* list */
643 YYSYMBOL_compound_list
= 88, /* compound_list */
644 YYSYMBOL_list0
= 89, /* list0 */
645 YYSYMBOL_list1
= 90, /* list1 */
646 YYSYMBOL_simple_list_terminator
= 91, /* simple_list_terminator */
647 YYSYMBOL_list_terminator
= 92, /* list_terminator */
648 YYSYMBOL_newline_list
= 93, /* newline_list */
649 YYSYMBOL_simple_list
= 94, /* simple_list */
650 YYSYMBOL_simple_list1
= 95, /* simple_list1 */
651 YYSYMBOL_pipeline_command
= 96, /* pipeline_command */
652 YYSYMBOL_pipeline
= 97, /* pipeline */
653 YYSYMBOL_timespec
= 98 /* timespec */
655 typedef enum yysymbol_kind_t yysymbol_kind_t
;
664 /* On compilers that do not define __PTRDIFF_MAX__ etc., make sure
665 <limits.h> and (if available) <stdint.h> are included
666 so that the code can choose integer types of a good width. */
668 #ifndef __PTRDIFF_MAX__
669 # include <limits.h> /* INFRINGES ON USER NAME SPACE */
670 # if defined __STDC_VERSION__ && 199901 <= __STDC_VERSION__
671 # include <stdint.h> /* INFRINGES ON USER NAME SPACE */
676 /* Narrow types that promote to a signed type and that can represent a
677 signed or unsigned integer of at least N bits. In tables they can
678 save space and decrease cache pressure. Promoting to a signed type
679 helps avoid bugs in integer arithmetic. */
681 #ifdef __INT_LEAST8_MAX__
682 typedef __INT_LEAST8_TYPE__ yytype_int8
;
683 #elif defined YY_STDINT_H
684 typedef int_least8_t yytype_int8
;
686 typedef signed char yytype_int8
;
689 #ifdef __INT_LEAST16_MAX__
690 typedef __INT_LEAST16_TYPE__ yytype_int16
;
691 #elif defined YY_STDINT_H
692 typedef int_least16_t yytype_int16
;
694 typedef short yytype_int16
;
697 #if defined __UINT_LEAST8_MAX__ && __UINT_LEAST8_MAX__ <= __INT_MAX__
698 typedef __UINT_LEAST8_TYPE__ yytype_uint8
;
699 #elif (!defined __UINT_LEAST8_MAX__ && defined YY_STDINT_H \
700 && UINT_LEAST8_MAX <= INT_MAX)
701 typedef uint_least8_t yytype_uint8
;
702 #elif !defined __UINT_LEAST8_MAX__ && UCHAR_MAX <= INT_MAX
703 typedef unsigned char yytype_uint8
;
705 typedef short yytype_uint8
;
708 #if defined __UINT_LEAST16_MAX__ && __UINT_LEAST16_MAX__ <= __INT_MAX__
709 typedef __UINT_LEAST16_TYPE__ yytype_uint16
;
710 #elif (!defined __UINT_LEAST16_MAX__ && defined YY_STDINT_H \
711 && UINT_LEAST16_MAX <= INT_MAX)
712 typedef uint_least16_t yytype_uint16
;
713 #elif !defined __UINT_LEAST16_MAX__ && USHRT_MAX <= INT_MAX
714 typedef unsigned short yytype_uint16
;
716 typedef int yytype_uint16
;
720 # if defined __PTRDIFF_TYPE__ && defined __PTRDIFF_MAX__
721 # define YYPTRDIFF_T __PTRDIFF_TYPE__
722 # define YYPTRDIFF_MAXIMUM __PTRDIFF_MAX__
723 # elif defined PTRDIFF_MAX
725 # include <stddef.h> /* INFRINGES ON USER NAME SPACE */
727 # define YYPTRDIFF_T ptrdiff_t
728 # define YYPTRDIFF_MAXIMUM PTRDIFF_MAX
730 # define YYPTRDIFF_T long
731 # define YYPTRDIFF_MAXIMUM LONG_MAX
736 # ifdef __SIZE_TYPE__
737 # define YYSIZE_T __SIZE_TYPE__
738 # elif defined size_t
739 # define YYSIZE_T size_t
740 # elif defined __STDC_VERSION__ && 199901 <= __STDC_VERSION__
741 # include <stddef.h> /* INFRINGES ON USER NAME SPACE */
742 # define YYSIZE_T size_t
744 # define YYSIZE_T unsigned
748 #define YYSIZE_MAXIMUM \
749 YY_CAST (YYPTRDIFF_T, \
750 (YYPTRDIFF_MAXIMUM < YY_CAST (YYSIZE_T, -1) \
751 ? YYPTRDIFF_MAXIMUM \
752 : YY_CAST (YYSIZE_T, -1)))
754 #define YYSIZEOF(X) YY_CAST (YYPTRDIFF_T, sizeof (X))
757 /* Stored state numbers (used for stacks). */
758 typedef yytype_int16 yy_state_t
;
760 /* State numbers in computations. */
761 typedef int yy_state_fast_t
;
764 # if defined YYENABLE_NLS && YYENABLE_NLS
766 # include <libintl.h> /* INFRINGES ON USER NAME SPACE */
767 # define YY_(Msgid) dgettext ("bison-runtime", Msgid)
771 # define YY_(Msgid) Msgid
776 #ifndef YY_ATTRIBUTE_PURE
777 # if defined __GNUC__ && 2 < __GNUC__ + (96 <= __GNUC_MINOR__)
778 # define YY_ATTRIBUTE_PURE __attribute__ ((__pure__))
780 # define YY_ATTRIBUTE_PURE
784 #ifndef YY_ATTRIBUTE_UNUSED
785 # if defined __GNUC__ && 2 < __GNUC__ + (7 <= __GNUC_MINOR__)
786 # define YY_ATTRIBUTE_UNUSED __attribute__ ((__unused__))
788 # define YY_ATTRIBUTE_UNUSED
792 /* Suppress unused-variable warnings by "using" E. */
793 #if ! defined lint || defined __GNUC__
794 # define YYUSE(E) ((void) (E))
796 # define YYUSE(E) /* empty */
799 #if defined __GNUC__ && ! defined __ICC && 407 <= __GNUC__ * 100 + __GNUC_MINOR__
800 /* Suppress an incorrect diagnostic about yylval being uninitialized. */
801 # define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \
802 _Pragma ("GCC diagnostic push") \
803 _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"") \
804 _Pragma ("GCC diagnostic ignored \"-Wmaybe-uninitialized\"")
805 # define YY_IGNORE_MAYBE_UNINITIALIZED_END \
806 _Pragma ("GCC diagnostic pop")
808 # define YY_INITIAL_VALUE(Value) Value
810 #ifndef YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
811 # define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
812 # define YY_IGNORE_MAYBE_UNINITIALIZED_END
814 #ifndef YY_INITIAL_VALUE
815 # define YY_INITIAL_VALUE(Value) /* Nothing. */
818 #if defined __cplusplus && defined __GNUC__ && ! defined __ICC && 6 <= __GNUC__
819 # define YY_IGNORE_USELESS_CAST_BEGIN \
820 _Pragma ("GCC diagnostic push") \
821 _Pragma ("GCC diagnostic ignored \"-Wuseless-cast\"")
822 # define YY_IGNORE_USELESS_CAST_END \
823 _Pragma ("GCC diagnostic pop")
825 #ifndef YY_IGNORE_USELESS_CAST_BEGIN
826 # define YY_IGNORE_USELESS_CAST_BEGIN
827 # define YY_IGNORE_USELESS_CAST_END
831 #define YY_ASSERT(E) ((void) (0 && (E)))
833 #if !defined yyoverflow
835 /* The parser invokes alloca or malloc; define the necessary symbols. */
837 # ifdef YYSTACK_USE_ALLOCA
838 # if YYSTACK_USE_ALLOCA
840 # define YYSTACK_ALLOC __builtin_alloca
841 # elif defined __BUILTIN_VA_ARG_INCR
842 # include <alloca.h> /* INFRINGES ON USER NAME SPACE */
844 # define YYSTACK_ALLOC __alloca
845 # elif defined _MSC_VER
846 # include <malloc.h> /* INFRINGES ON USER NAME SPACE */
847 # define alloca _alloca
849 # define YYSTACK_ALLOC alloca
850 # if ! defined _ALLOCA_H && ! defined EXIT_SUCCESS
851 # include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
852 /* Use EXIT_SUCCESS as a witness for stdlib.h. */
853 # ifndef EXIT_SUCCESS
854 # define EXIT_SUCCESS 0
861 # ifdef YYSTACK_ALLOC
862 /* Pacify GCC's 'empty if-body' warning. */
863 # define YYSTACK_FREE(Ptr) do { /* empty */; } while (0)
864 # ifndef YYSTACK_ALLOC_MAXIMUM
865 /* The OS might guarantee only one guard page at the bottom of the stack,
866 and a page size can be as small as 4096 bytes. So we cannot safely
867 invoke alloca (N) if N exceeds 4096. Use a slightly smaller number
868 to allow for a few compiler-allocated temporary stack slots. */
869 # define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */
872 # define YYSTACK_ALLOC YYMALLOC
873 # define YYSTACK_FREE YYFREE
874 # ifndef YYSTACK_ALLOC_MAXIMUM
875 # define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM
877 # if (defined __cplusplus && ! defined EXIT_SUCCESS \
878 && ! ((defined YYMALLOC || defined malloc) \
879 && (defined YYFREE || defined free)))
880 # include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
881 # ifndef EXIT_SUCCESS
882 # define EXIT_SUCCESS 0
886 # define YYMALLOC malloc
887 # if ! defined malloc && ! defined EXIT_SUCCESS
888 void *malloc (YYSIZE_T
); /* INFRINGES ON USER NAME SPACE */
893 # if ! defined free && ! defined EXIT_SUCCESS
894 void free (void *); /* INFRINGES ON USER NAME SPACE */
898 #endif /* !defined yyoverflow */
900 #if (! defined yyoverflow \
901 && (! defined __cplusplus \
902 || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
904 /* A type that is properly aligned for any stack member. */
907 yy_state_t yyss_alloc
;
911 /* The size of the maximum gap between one aligned stack and the next. */
912 # define YYSTACK_GAP_MAXIMUM (YYSIZEOF (union yyalloc) - 1)
914 /* The size of an array large to enough to hold all stacks, each with
916 # define YYSTACK_BYTES(N) \
917 ((N) * (YYSIZEOF (yy_state_t) + YYSIZEOF (YYSTYPE)) \
918 + YYSTACK_GAP_MAXIMUM)
920 # define YYCOPY_NEEDED 1
922 /* Relocate STACK from its old location to the new one. The
923 local variables YYSIZE and YYSTACKSIZE give the old and new number of
924 elements in the stack, and YYPTR gives the new location of the
925 stack. Advance YYPTR to a properly aligned location for the next
927 # define YYSTACK_RELOCATE(Stack_alloc, Stack) \
930 YYPTRDIFF_T yynewbytes; \
931 YYCOPY (&yyptr->Stack_alloc, Stack, yysize); \
932 Stack = &yyptr->Stack_alloc; \
933 yynewbytes = yystacksize * YYSIZEOF (*Stack) + YYSTACK_GAP_MAXIMUM; \
934 yyptr += yynewbytes / YYSIZEOF (*yyptr); \
940 #if defined YYCOPY_NEEDED && YYCOPY_NEEDED
941 /* Copy COUNT objects from SRC to DST. The source and destination do
944 # if defined __GNUC__ && 1 < __GNUC__
945 # define YYCOPY(Dst, Src, Count) \
946 __builtin_memcpy (Dst, Src, YY_CAST (YYSIZE_T, (Count)) * sizeof (*(Src)))
948 # define YYCOPY(Dst, Src, Count) \
952 for (yyi = 0; yyi < (Count); yyi++) \
953 (Dst)[yyi] = (Src)[yyi]; \
958 #endif /* !YYCOPY_NEEDED */
960 /* YYFINAL -- State number of the termination state. */
962 /* YYLAST -- Last index in YYTABLE. */
965 /* YYNTOKENS -- Number of terminals. */
967 /* YYNNTS -- Number of nonterminals. */
969 /* YYNRULES -- Number of rules. */
971 /* YYNSTATES -- Number of states. */
972 #define YYNSTATES 346
974 #define YYMAXUTOK 304
977 /* YYTRANSLATE(TOKEN-NUM) -- Symbol number corresponding to TOKEN-NUM
978 as returned by yylex, with out-of-bounds checking. */
979 #define YYTRANSLATE(YYX) \
980 (0 <= (YYX) && (YYX) <= YYMAXUTOK \
981 ? YY_CAST (yysymbol_kind_t, yytranslate[YYX]) \
984 /* YYTRANSLATE[TOKEN-NUM] -- Symbol number corresponding to TOKEN-NUM
985 as returned by yylex. */
986 static const yytype_int8 yytranslate
[] =
988 0, 2, 2, 2, 2, 2, 2, 2, 2, 2,
989 51, 2, 2, 2, 2, 2, 2, 2, 2, 2,
990 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
991 2, 2, 2, 2, 2, 2, 2, 2, 49, 2,
992 59, 60, 2, 2, 2, 56, 2, 2, 2, 2,
993 2, 2, 2, 2, 2, 2, 2, 2, 2, 50,
994 55, 2, 54, 2, 2, 2, 2, 2, 2, 2,
995 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
996 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
997 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
998 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
999 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1000 2, 2, 2, 57, 53, 58, 2, 2, 2, 2,
1001 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1002 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1003 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1004 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1005 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1006 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1007 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1008 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1009 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1010 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1011 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1012 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1013 2, 2, 2, 2, 2, 2, 1, 2, 3, 4,
1014 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
1015 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
1016 25, 26, 27, 28, 29, 30, 31, 32, 33, 34,
1017 35, 36, 37, 38, 39, 40, 41, 42, 43, 44,
1022 /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */
1023 static const yytype_int16 yyrline
[] =
1025 0, 381, 381, 392, 401, 416, 433, 443, 445, 449,
1026 455, 461, 467, 473, 479, 485, 491, 497, 503, 509,
1027 515, 521, 527, 533, 539, 546, 553, 560, 567, 574,
1028 581, 587, 593, 599, 605, 611, 617, 623, 629, 635,
1029 641, 647, 653, 659, 665, 671, 677, 683, 689, 695,
1030 701, 707, 713, 721, 723, 725, 729, 733, 744, 746,
1031 750, 752, 754, 770, 772, 776, 778, 780, 782, 784,
1032 786, 788, 790, 792, 794, 796, 800, 805, 810, 815,
1033 820, 825, 830, 835, 842, 848, 854, 860, 868, 873,
1034 878, 883, 888, 893, 898, 903, 910, 915, 920, 927,
1035 929, 931, 933, 937, 939, 970, 977, 982, 999, 1004,
1036 1021, 1028, 1030, 1032, 1037, 1041, 1045, 1049, 1051, 1053,
1037 1057, 1058, 1062, 1064, 1066, 1068, 1072, 1074, 1076, 1078,
1038 1080, 1082, 1086, 1088, 1097, 1105, 1106, 1112, 1113, 1120,
1039 1124, 1126, 1128, 1135, 1137, 1139, 1143, 1144, 1147, 1149,
1040 1151, 1155, 1156, 1165, 1178, 1194, 1209, 1211, 1213, 1220,
1041 1223, 1227, 1229, 1235, 1241, 1261, 1284, 1286, 1309, 1313,
1046 /** Accessing symbol of state STATE. */
1047 #define YY_ACCESSING_SYMBOL(State) YY_CAST (yysymbol_kind_t, yystos[State])
1050 /* The user-facing name of the symbol whose (internal) number is
1051 YYSYMBOL. No bounds checking. */
1052 static const char *yysymbol_name (yysymbol_kind_t yysymbol
) YY_ATTRIBUTE_UNUSED
;
1054 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
1055 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
1056 static const char *const yytname
[] =
1058 "\"end of file\"", "error", "\"invalid token\"", "IF", "THEN", "ELSE",
1059 "ELIF", "FI", "CASE", "ESAC", "FOR", "SELECT", "WHILE", "UNTIL", "DO",
1060 "DONE", "FUNCTION", "COPROC", "COND_START", "COND_END", "COND_ERROR",
1061 "IN", "BANG", "TIME", "TIMEOPT", "TIMEIGN", "WORD", "ASSIGNMENT_WORD",
1062 "REDIR_WORD", "NUMBER", "ARITH_CMD", "ARITH_FOR_EXPRS", "COND_CMD",
1063 "AND_AND", "OR_OR", "GREATER_GREATER", "LESS_LESS", "LESS_AND",
1064 "LESS_LESS_LESS", "GREATER_AND", "SEMI_SEMI", "SEMI_AND",
1065 "SEMI_SEMI_AND", "LESS_LESS_MINUS", "AND_GREATER", "AND_GREATER_GREATER",
1066 "LESS_GREATER", "GREATER_BAR", "BAR_AND", "'&'", "';'", "'\\n'",
1067 "yacc_EOF", "'|'", "'>'", "'<'", "'-'", "'{'", "'}'", "'('", "')'",
1068 "$accept", "inputunit", "word_list", "redirection",
1069 "simple_command_element", "redirection_list", "simple_command",
1070 "command", "shell_command", "for_command", "arith_for_command",
1071 "select_command", "case_command", "function_def", "function_body",
1072 "subshell", "coproc", "if_command", "group_command", "arith_command",
1073 "cond_command", "elif_clause", "case_clause", "pattern_list",
1074 "case_clause_sequence", "pattern", "list", "compound_list", "list0",
1075 "list1", "simple_list_terminator", "list_terminator", "newline_list",
1076 "simple_list", "simple_list1", "pipeline_command", "pipeline",
1077 "timespec", YY_NULLPTR
1081 yysymbol_name (yysymbol_kind_t yysymbol
)
1083 return yytname
[yysymbol
];
1088 /* YYTOKNUM[NUM] -- (External) token number corresponding to the
1089 (internal) symbol number NUM (which must be that of a token). */
1090 static const yytype_int16 yytoknum
[] =
1092 0, 256, 257, 258, 259, 260, 261, 262, 263, 264,
1093 265, 266, 267, 268, 269, 270, 271, 272, 273, 274,
1094 275, 276, 277, 278, 279, 280, 281, 282, 283, 284,
1095 285, 286, 287, 288, 289, 290, 291, 292, 293, 294,
1096 295, 296, 297, 298, 299, 300, 301, 302, 303, 38,
1097 59, 10, 304, 124, 62, 60, 45, 123, 125, 40,
1102 #define YYPACT_NINF (-204)
1104 #define yypact_value_is_default(Yyn) \
1105 ((Yyn) == YYPACT_NINF)
1107 #define YYTABLE_NINF (-1)
1109 #define yytable_value_is_error(Yyn) \
1112 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
1114 static const yytype_int16 yypact
[] =
1116 313, 108, -204, -6, 8, 2, -204, -204, 10, 513,
1117 17, 363, 153, -21, -204, 593, 606, -204, 14, 26,
1118 113, 41, 127, 72, 85, 92, 95, 98, -204, -204,
1119 100, 105, -204, -204, 65, -204, -204, 551, -204, 572,
1120 -204, -204, -204, -204, -204, -204, -204, -204, -204, -204,
1121 -204, 146, 140, -204, 67, 363, -204, -204, -204, 133,
1122 413, -204, 93, 55, 104, 156, 161, 11, 45, 551,
1123 572, 163, -204, -204, -204, -204, -204, 167, -204, 152,
1124 208, 217, 129, 220, 150, 221, 223, 225, 233, 234,
1125 238, 239, 158, 240, 162, 241, 243, 244, 252, 253,
1126 -204, -204, -204, -204, -204, -204, -204, -204, -204, -204,
1127 -204, -204, -204, -204, -204, -204, 194, 227, -204, -204,
1128 -204, -204, 572, -204, -204, -204, -204, -204, 463, 463,
1129 -204, -204, -204, -204, -204, -204, -204, -7, -204, 59,
1130 -204, 52, -204, -204, -204, -204, 62, -204, -204, -204,
1131 235, 572, -204, 572, 572, -204, -204, -204, -204, -204,
1132 -204, -204, -204, -204, -204, -204, -204, -204, -204, -204,
1133 -204, -204, -204, -204, -204, -204, -204, -204, -204, -204,
1134 -204, -204, -204, -204, -204, -204, -204, -204, -204, 413,
1135 413, 191, 191, 245, 245, 203, -204, -204, -204, -204,
1136 -204, -204, 37, -204, 176, -204, 270, 228, 76, 79,
1137 -204, 176, -204, 278, 282, 563, -204, 572, 572, 563,
1138 -204, -204, 67, 67, -204, -204, -204, 291, 413, 413,
1139 413, 413, 413, 294, 175, -204, 28, -204, -204, 292,
1140 -204, 187, -204, 250, -204, -204, -204, -204, -204, -204,
1141 295, 413, 187, -204, 251, -204, -204, -204, 563, -204,
1142 304, 314, -204, -204, -204, 196, 196, 196, -204, -204,
1143 -204, -204, 179, 38, -204, -204, 296, -28, 302, 274,
1144 -204, -204, -204, 87, -204, 318, 276, 322, 280, -204,
1145 -7, -204, 111, -204, -204, -204, -204, -204, -204, -204,
1146 -204, 39, 319, -204, -204, -204, 114, -204, -204, -204,
1147 -204, -204, -204, 115, -204, -204, 226, -204, -204, -204,
1148 413, -204, -204, 329, 288, -204, -204, 332, 297, -204,
1149 -204, -204, 413, 338, 303, -204, -204, 339, 305, -204,
1150 -204, -204, -204, -204, -204, -204
1153 /* YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM.
1154 Performed when YYTABLE does not specify something else to do. Zero
1155 means the default is an error. */
1156 static const yytype_uint8 yydefact
[] =
1158 0, 0, 151, 0, 0, 0, 151, 151, 0, 0,
1159 0, 0, 169, 53, 54, 0, 0, 115, 0, 0,
1160 0, 0, 0, 0, 0, 0, 0, 0, 3, 6,
1161 0, 0, 151, 151, 0, 55, 58, 60, 168, 61,
1162 65, 75, 69, 66, 63, 71, 64, 70, 72, 73,
1163 74, 0, 153, 160, 161, 0, 4, 5, 135, 0,
1164 0, 151, 151, 0, 151, 0, 0, 0, 53, 110,
1165 106, 0, 149, 148, 150, 165, 162, 170, 171, 0,
1166 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1167 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1168 15, 24, 39, 33, 48, 30, 42, 36, 45, 27,
1169 51, 52, 21, 18, 9, 10, 0, 0, 1, 53,
1170 59, 56, 62, 146, 147, 2, 151, 151, 154, 155,
1171 151, 151, 164, 163, 151, 152, 134, 136, 145, 0,
1172 151, 0, 151, 151, 151, 151, 0, 151, 151, 151,
1173 151, 103, 101, 108, 107, 116, 172, 151, 17, 26,
1174 41, 35, 50, 32, 44, 38, 47, 29, 23, 20,
1175 13, 14, 16, 25, 40, 34, 49, 31, 43, 37,
1176 46, 28, 22, 19, 11, 12, 114, 105, 57, 0,
1177 0, 158, 159, 0, 0, 0, 151, 151, 151, 151,
1178 151, 151, 0, 151, 0, 151, 0, 0, 0, 0,
1179 151, 0, 151, 0, 0, 0, 151, 104, 109, 0,
1180 156, 157, 167, 166, 151, 151, 111, 0, 0, 0,
1181 138, 139, 137, 0, 120, 151, 0, 151, 151, 0,
1182 7, 0, 151, 0, 86, 87, 151, 151, 151, 151,
1183 0, 0, 0, 151, 0, 67, 68, 102, 0, 99,
1184 0, 0, 113, 140, 141, 142, 143, 144, 98, 126,
1185 128, 130, 121, 0, 96, 132, 0, 0, 0, 0,
1186 76, 8, 151, 0, 77, 0, 0, 0, 0, 88,
1187 0, 151, 0, 89, 100, 112, 151, 127, 129, 131,
1188 97, 0, 0, 151, 78, 79, 0, 151, 151, 84,
1189 85, 90, 91, 0, 151, 151, 117, 151, 133, 122,
1190 123, 151, 151, 0, 0, 151, 151, 0, 0, 151,
1191 119, 124, 125, 0, 0, 82, 83, 0, 0, 94,
1192 95, 118, 80, 81, 92, 93
1195 /* YYPGOTO[NTERM-NUM]. */
1196 static const yytype_int16 yypgoto
[] =
1198 -204, -204, 117, -37, -19, -67, 353, -204, -8, -204,
1199 -204, -204, -204, -204, -184, -204, -204, -204, -204, -204,
1200 -204, 53, -204, 142, -204, 102, -203, -2, -204, 283,
1201 -204, -47, -49, -204, -118, 6, 47, -204
1204 /* YYDEFGOTO[NTERM-NUM]. */
1205 static const yytype_int16 yydefgoto
[] =
1207 -1, 34, 241, 35, 36, 122, 37, 38, 39, 40,
1208 41, 42, 43, 44, 152, 45, 46, 47, 48, 49,
1209 50, 227, 233, 234, 235, 277, 58, 117, 136, 137,
1210 125, 75, 60, 51, 52, 138, 54, 55
1213 /* YYTABLE[YYPACT[STATE-NUM]] -- What to do in state STATE-NUM. If
1214 positive, shift that token. If negative, reduce the rule whose
1215 number is the opposite. If YYTABLE_NINF, syntax error. */
1216 static const yytype_int16 yytable
[] =
1218 59, 70, 121, 154, 65, 66, 53, 250, 132, 254,
1219 191, 192, 139, 141, 2, 146, 144, 76, 120, 3,
1220 61, 4, 5, 6, 7, 302, 196, 197, 64, 10,
1221 116, 257, 303, 121, 62, 259, 67, 274, 79, 63,
1222 100, 17, 198, 199, 200, 287, 288, 300, 2, 71,
1223 120, 237, 101, 3, 275, 4, 5, 6, 7, 151,
1224 153, 133, 149, 10, 275, 118, 203, 105, 32, 142,
1225 150, 220, 221, 204, 294, 17, 210, 189, 190, 135,
1226 201, 193, 194, 211, 217, 188, 218, 276, 135, 135,
1227 246, 202, 302, 248, 238, 208, 209, 276, 109, 317,
1228 215, 307, 32, 135, 33, 72, 73, 74, 219, 205,
1229 135, 110, 143, 135, 121, 130, 121, 188, 111, 212,
1230 131, 112, 337, 338, 113, 314, 114, 135, 321, 325,
1231 135, 115, 195, 247, 53, 53, 249, 134, 135, 102,
1232 206, 207, 103, 140, 308, 213, 214, 228, 229, 230,
1233 231, 232, 236, 106, 145, 160, 107, 242, 161, 56,
1234 57, 251, 135, 251, 253, 135, 135, 258, 315, 104,
1235 147, 322, 326, 126, 127, 148, 164, 77, 78, 165,
1236 188, 188, 155, 108, 174, 162, 273, 175, 178, 128,
1237 129, 179, 156, 283, 282, 53, 53, 123, 124, 251,
1238 251, 239, 240, 243, 292, 291, 166, 151, 224, 225,
1239 226, 151, 157, 281, 176, 269, 270, 271, 180, 297,
1240 298, 299, 260, 261, 126, 127, 72, 73, 74, 196,
1241 197, 329, 225, 306, 158, 278, 279, 72, 73, 74,
1242 222, 223, 313, 159, 285, 286, 163, 167, 2, 168,
1243 151, 169, 186, 3, 320, 4, 5, 6, 7, 170,
1244 171, 8, 9, 10, 172, 173, 177, 181, 332, 182,
1245 183, 13, 14, 15, 16, 17, 251, 251, 184, 185,
1246 18, 19, 20, 21, 22, 244, 245, 187, 23, 24,
1247 25, 26, 27, 255, 316, 216, 135, 256, 262, 30,
1248 31, 319, 32, 268, 33, 323, 324, 280, 284, 293,
1249 289, 295, 327, 328, 1, 331, 2, 304, 296, 333,
1250 334, 3, 275, 4, 5, 6, 7, 341, 252, 8,
1251 9, 10, 305, 309, 310, 11, 12, 311, 312, 13,
1252 14, 15, 16, 17, 335, 318, 336, 339, 18, 19,
1253 20, 21, 22, 342, 344, 340, 23, 24, 25, 26,
1254 27, 343, 69, 345, 28, 29, 2, 30, 31, 330,
1255 32, 3, 33, 4, 5, 6, 7, 272, 301, 8,
1256 9, 10, 0, 0, 0, 11, 12, 0, 0, 13,
1257 14, 15, 16, 17, 0, 0, 0, 0, 18, 19,
1258 20, 21, 22, 0, 0, 0, 23, 24, 25, 26,
1259 27, 0, 0, 72, 73, 74, 2, 30, 31, 0,
1260 32, 3, 33, 4, 5, 6, 7, 0, 0, 8,
1261 9, 10, 0, 0, 0, 11, 12, 0, 0, 13,
1262 14, 15, 16, 17, 0, 0, 0, 0, 18, 19,
1263 20, 21, 22, 0, 0, 0, 23, 24, 25, 26,
1264 27, 0, 0, 0, 135, 0, 2, 30, 31, 0,
1265 32, 3, 33, 4, 5, 6, 7, 0, 0, 8,
1266 9, 10, 0, 0, 0, 11, 12, 0, 0, 13,
1267 14, 15, 16, 17, 0, 0, 0, 0, 18, 19,
1268 20, 21, 22, 0, 0, 0, 23, 24, 25, 26,
1269 27, 263, 264, 265, 266, 267, 2, 30, 31, 0,
1270 32, 3, 33, 4, 5, 6, 7, 0, 0, 0,
1271 0, 10, 0, 0, 290, 0, 0, 0, 0, 68,
1272 14, 15, 16, 17, 0, 0, 0, 0, 18, 19,
1273 20, 21, 22, 0, 0, 0, 23, 24, 25, 26,
1274 27, 0, 0, 0, 0, 0, 2, 30, 31, 0,
1275 32, 3, 33, 4, 5, 6, 7, 119, 14, 15,
1276 16, 10, 0, 0, 0, 0, 18, 19, 20, 21,
1277 22, 0, 0, 17, 23, 24, 25, 26, 27, 0,
1278 15, 16, 0, 0, 0, 30, 31, 18, 19, 20,
1279 21, 22, 0, 0, 135, 23, 24, 25, 26, 27,
1280 32, 0, 33, 0, 0, 0, 30, 31, 80, 81,
1281 82, 83, 84, 0, 0, 0, 85, 0, 0, 86,
1282 87, 90, 91, 92, 93, 94, 0, 88, 89, 95,
1283 0, 0, 96, 97, 0, 0, 0, 0, 0, 0,
1287 static const yytype_int16 yycheck
[] =
1289 2, 9, 39, 70, 6, 7, 0, 210, 55, 212,
1290 128, 129, 61, 62, 3, 64, 63, 11, 37, 8,
1291 26, 10, 11, 12, 13, 53, 33, 34, 26, 18,
1292 32, 215, 60, 70, 26, 219, 26, 9, 59, 31,
1293 26, 30, 49, 50, 51, 248, 249, 9, 3, 32,
1294 69, 14, 26, 8, 26, 10, 11, 12, 13, 67,
1295 68, 55, 51, 18, 26, 0, 14, 26, 57, 14,
1296 59, 189, 190, 21, 258, 30, 14, 126, 127, 51,
1297 21, 130, 131, 21, 151, 122, 153, 59, 51, 51,
1298 14, 140, 53, 14, 57, 144, 145, 59, 26, 60,
1299 149, 14, 57, 51, 59, 50, 51, 52, 157, 57,
1300 51, 26, 57, 51, 151, 48, 153, 154, 26, 57,
1301 53, 26, 325, 326, 26, 14, 26, 51, 14, 14,
1302 51, 26, 134, 57, 128, 129, 57, 4, 51, 26,
1303 142, 143, 29, 50, 57, 147, 148, 196, 197, 198,
1304 199, 200, 201, 26, 50, 26, 29, 204, 29, 51,
1305 52, 210, 51, 212, 211, 51, 51, 216, 57, 56,
1306 14, 57, 57, 33, 34, 14, 26, 24, 25, 29,
1307 217, 218, 19, 56, 26, 56, 235, 29, 26, 49,
1308 50, 29, 25, 242, 241, 189, 190, 51, 52, 248,
1309 249, 203, 26, 205, 253, 252, 56, 215, 5, 6,
1310 7, 219, 60, 26, 56, 40, 41, 42, 56, 40,
1311 41, 42, 224, 225, 33, 34, 50, 51, 52, 33,
1312 34, 5, 6, 282, 26, 237, 238, 50, 51, 52,
1313 193, 194, 291, 26, 246, 247, 26, 26, 3, 26,
1314 258, 26, 58, 8, 303, 10, 11, 12, 13, 26,
1315 26, 16, 17, 18, 26, 26, 26, 26, 317, 26,
1316 26, 26, 27, 28, 29, 30, 325, 326, 26, 26,
1317 35, 36, 37, 38, 39, 15, 58, 60, 43, 44,
1318 45, 46, 47, 15, 296, 60, 51, 15, 7, 54,
1319 55, 303, 57, 9, 59, 307, 308, 15, 58, 58,
1320 15, 7, 314, 315, 1, 317, 3, 15, 4, 321,
1321 322, 8, 26, 10, 11, 12, 13, 329, 211, 16,
1322 17, 18, 58, 15, 58, 22, 23, 15, 58, 26,
1323 27, 28, 29, 30, 15, 26, 58, 15, 35, 36,
1324 37, 38, 39, 15, 15, 58, 43, 44, 45, 46,
1325 47, 58, 9, 58, 51, 52, 3, 54, 55, 316,
1326 57, 8, 59, 10, 11, 12, 13, 235, 276, 16,
1327 17, 18, -1, -1, -1, 22, 23, -1, -1, 26,
1328 27, 28, 29, 30, -1, -1, -1, -1, 35, 36,
1329 37, 38, 39, -1, -1, -1, 43, 44, 45, 46,
1330 47, -1, -1, 50, 51, 52, 3, 54, 55, -1,
1331 57, 8, 59, 10, 11, 12, 13, -1, -1, 16,
1332 17, 18, -1, -1, -1, 22, 23, -1, -1, 26,
1333 27, 28, 29, 30, -1, -1, -1, -1, 35, 36,
1334 37, 38, 39, -1, -1, -1, 43, 44, 45, 46,
1335 47, -1, -1, -1, 51, -1, 3, 54, 55, -1,
1336 57, 8, 59, 10, 11, 12, 13, -1, -1, 16,
1337 17, 18, -1, -1, -1, 22, 23, -1, -1, 26,
1338 27, 28, 29, 30, -1, -1, -1, -1, 35, 36,
1339 37, 38, 39, -1, -1, -1, 43, 44, 45, 46,
1340 47, 228, 229, 230, 231, 232, 3, 54, 55, -1,
1341 57, 8, 59, 10, 11, 12, 13, -1, -1, -1,
1342 -1, 18, -1, -1, 251, -1, -1, -1, -1, 26,
1343 27, 28, 29, 30, -1, -1, -1, -1, 35, 36,
1344 37, 38, 39, -1, -1, -1, 43, 44, 45, 46,
1345 47, -1, -1, -1, -1, -1, 3, 54, 55, -1,
1346 57, 8, 59, 10, 11, 12, 13, 26, 27, 28,
1347 29, 18, -1, -1, -1, -1, 35, 36, 37, 38,
1348 39, -1, -1, 30, 43, 44, 45, 46, 47, -1,
1349 28, 29, -1, -1, -1, 54, 55, 35, 36, 37,
1350 38, 39, -1, -1, 51, 43, 44, 45, 46, 47,
1351 57, -1, 59, -1, -1, -1, 54, 55, 35, 36,
1352 37, 38, 39, -1, -1, -1, 43, -1, -1, 46,
1353 47, 35, 36, 37, 38, 39, -1, 54, 55, 43,
1354 -1, -1, 46, 47, -1, -1, -1, -1, -1, -1,
1358 /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
1359 symbol of state STATE-NUM. */
1360 static const yytype_int8 yystos
[] =
1362 0, 1, 3, 8, 10, 11, 12, 13, 16, 17,
1363 18, 22, 23, 26, 27, 28, 29, 30, 35, 36,
1364 37, 38, 39, 43, 44, 45, 46, 47, 51, 52,
1365 54, 55, 57, 59, 62, 64, 65, 67, 68, 69,
1366 70, 71, 72, 73, 74, 76, 77, 78, 79, 80,
1367 81, 94, 95, 96, 97, 98, 51, 52, 87, 88,
1368 93, 26, 26, 31, 26, 88, 88, 26, 26, 67,
1369 69, 32, 50, 51, 52, 92, 96, 24, 25, 59,
1370 35, 36, 37, 38, 39, 43, 46, 47, 54, 55,
1371 35, 36, 37, 38, 39, 43, 46, 47, 54, 55,
1372 26, 26, 26, 29, 56, 26, 26, 29, 56, 26,
1373 26, 26, 26, 26, 26, 26, 88, 88, 0, 26,
1374 65, 64, 66, 51, 52, 91, 33, 34, 49, 50,
1375 48, 53, 92, 96, 4, 51, 89, 90, 96, 93,
1376 50, 93, 14, 57, 92, 50, 93, 14, 14, 51,
1377 59, 69, 75, 69, 66, 19, 25, 60, 26, 26,
1378 26, 29, 56, 26, 26, 29, 56, 26, 26, 26,
1379 26, 26, 26, 26, 26, 29, 56, 26, 26, 29,
1380 56, 26, 26, 26, 26, 26, 58, 60, 64, 93,
1381 93, 95, 95, 93, 93, 88, 33, 34, 49, 50,
1382 51, 21, 93, 14, 21, 57, 88, 88, 93, 93,
1383 14, 21, 57, 88, 88, 93, 60, 66, 66, 93,
1384 95, 95, 97, 97, 5, 6, 7, 82, 93, 93,
1385 93, 93, 93, 83, 84, 85, 93, 14, 57, 88,
1386 26, 63, 92, 88, 15, 58, 14, 57, 14, 57,
1387 87, 93, 63, 92, 87, 15, 15, 75, 93, 75,
1388 88, 88, 7, 90, 90, 90, 90, 90, 9, 40,
1389 41, 42, 84, 93, 9, 26, 59, 86, 88, 88,
1390 15, 26, 92, 93, 58, 88, 88, 87, 87, 15,
1391 90, 92, 93, 58, 75, 7, 4, 40, 41, 42,
1392 9, 86, 53, 60, 15, 58, 93, 14, 57, 15,
1393 58, 15, 58, 93, 14, 57, 88, 60, 26, 88,
1394 93, 14, 57, 88, 88, 14, 57, 88, 88, 5,
1395 82, 88, 93, 88, 88, 15, 58, 87, 87, 15,
1396 58, 88, 15, 58, 15, 58
1399 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
1400 static const yytype_int8 yyr1
[] =
1402 0, 61, 62, 62, 62, 62, 62, 63, 63, 64,
1403 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
1404 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
1405 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
1406 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
1407 64, 64, 64, 65, 65, 65, 66, 66, 67, 67,
1408 68, 68, 68, 68, 68, 69, 69, 69, 69, 69,
1409 69, 69, 69, 69, 69, 69, 70, 70, 70, 70,
1410 70, 70, 70, 70, 71, 71, 71, 71, 72, 72,
1411 72, 72, 72, 72, 72, 72, 73, 73, 73, 74,
1412 74, 74, 74, 75, 75, 76, 77, 77, 77, 77,
1413 77, 78, 78, 78, 79, 80, 81, 82, 82, 82,
1414 83, 83, 84, 84, 84, 84, 85, 85, 85, 85,
1415 85, 85, 86, 86, 87, 88, 88, 89, 89, 89,
1416 90, 90, 90, 90, 90, 90, 91, 91, 92, 92,
1417 92, 93, 93, 94, 94, 94, 95, 95, 95, 95,
1418 95, 96, 96, 96, 96, 96, 97, 97, 97, 98,
1422 /* YYR2[YYN] -- Number of symbols on the right hand side of rule YYN. */
1423 static const yytype_int8 yyr2
[] =
1425 0, 2, 2, 1, 2, 2, 1, 1, 2, 2,
1426 2, 3, 3, 3, 3, 2, 3, 3, 2, 3,
1427 3, 2, 3, 3, 2, 3, 3, 2, 3, 3,
1428 2, 3, 3, 2, 3, 3, 2, 3, 3, 2,
1429 3, 3, 2, 3, 3, 2, 3, 3, 2, 3,
1430 3, 2, 2, 1, 1, 1, 1, 2, 1, 2,
1431 1, 1, 2, 1, 1, 1, 1, 5, 5, 1,
1432 1, 1, 1, 1, 1, 1, 6, 6, 7, 7,
1433 10, 10, 9, 9, 7, 7, 5, 5, 6, 6,
1434 7, 7, 10, 10, 9, 9, 6, 7, 6, 5,
1435 6, 3, 5, 1, 2, 3, 2, 3, 3, 4,
1436 2, 5, 7, 6, 3, 1, 3, 4, 6, 5,
1437 1, 2, 4, 4, 5, 5, 2, 3, 2, 3,
1438 2, 3, 1, 3, 2, 1, 2, 3, 3, 3,
1439 4, 4, 4, 4, 4, 1, 1, 1, 1, 1,
1440 1, 0, 2, 1, 2, 2, 4, 4, 3, 3,
1441 1, 1, 2, 2, 2, 2, 4, 4, 1, 1,
1446 enum { YYENOMEM
= -2 };
1448 #define yyerrok (yyerrstatus = 0)
1449 #define yyclearin (yychar = YYEMPTY)
1451 #define YYACCEPT goto yyacceptlab
1452 #define YYABORT goto yyabortlab
1453 #define YYERROR goto yyerrorlab
1456 #define YYRECOVERING() (!!yyerrstatus)
1458 #define YYBACKUP(Token, Value) \
1460 if (yychar == YYEMPTY) \
1464 YYPOPSTACK (yylen); \
1470 yyerror (YY_("syntax error: cannot back up")); \
1475 /* Backward compatibility with an undocumented macro.
1476 Use YYerror or YYUNDEF. */
1477 #define YYERRCODE YYUNDEF
1480 /* Enable debugging if requested. */
1484 # include <stdio.h> /* INFRINGES ON USER NAME SPACE */
1485 # define YYFPRINTF fprintf
1488 # define YYDPRINTF(Args) \
1494 /* This macro is provided for backward compatibility. */
1495 # ifndef YY_LOCATION_PRINT
1496 # define YY_LOCATION_PRINT(File, Loc) ((void) 0)
1500 # define YY_SYMBOL_PRINT(Title, Kind, Value, Location) \
1504 YYFPRINTF (stderr, "%s ", Title); \
1505 yy_symbol_print (stderr, \
1507 YYFPRINTF (stderr, "\n"); \
1512 /*-----------------------------------.
1513 | Print this symbol's value on YYO. |
1514 `-----------------------------------*/
1517 yy_symbol_value_print (FILE *yyo
,
1518 yysymbol_kind_t yykind
, YYSTYPE
const * const yyvaluep
)
1520 FILE *yyoutput
= yyo
;
1525 if (yykind
< YYNTOKENS
)
1526 YYPRINT (yyo
, yytoknum
[yykind
], *yyvaluep
);
1528 YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
1530 YY_IGNORE_MAYBE_UNINITIALIZED_END
1534 /*---------------------------.
1535 | Print this symbol on YYO. |
1536 `---------------------------*/
1539 yy_symbol_print (FILE *yyo
,
1540 yysymbol_kind_t yykind
, YYSTYPE
const * const yyvaluep
)
1542 YYFPRINTF (yyo
, "%s %s (",
1543 yykind
< YYNTOKENS
? "token" : "nterm", yysymbol_name (yykind
));
1545 yy_symbol_value_print (yyo
, yykind
, yyvaluep
);
1546 YYFPRINTF (yyo
, ")");
1549 /*------------------------------------------------------------------.
1550 | yy_stack_print -- Print the state stack from its BOTTOM up to its |
1552 `------------------------------------------------------------------*/
1555 yy_stack_print (yy_state_t
*yybottom
, yy_state_t
*yytop
)
1557 YYFPRINTF (stderr
, "Stack now");
1558 for (; yybottom
<= yytop
; yybottom
++)
1560 int yybot
= *yybottom
;
1561 YYFPRINTF (stderr
, " %d", yybot
);
1563 YYFPRINTF (stderr
, "\n");
1566 # define YY_STACK_PRINT(Bottom, Top) \
1569 yy_stack_print ((Bottom), (Top)); \
1573 /*------------------------------------------------.
1574 | Report that the YYRULE is going to be reduced. |
1575 `------------------------------------------------*/
1578 yy_reduce_print (yy_state_t
*yyssp
, YYSTYPE
*yyvsp
,
1581 int yylno
= yyrline
[yyrule
];
1582 int yynrhs
= yyr2
[yyrule
];
1584 YYFPRINTF (stderr
, "Reducing stack by rule %d (line %d):\n",
1586 /* The symbols being reduced. */
1587 for (yyi
= 0; yyi
< yynrhs
; yyi
++)
1589 YYFPRINTF (stderr
, " $%d = ", yyi
+ 1);
1590 yy_symbol_print (stderr
,
1591 YY_ACCESSING_SYMBOL (+yyssp
[yyi
+ 1 - yynrhs
]),
1592 &yyvsp
[(yyi
+ 1) - (yynrhs
)]);
1593 YYFPRINTF (stderr
, "\n");
1597 # define YY_REDUCE_PRINT(Rule) \
1600 yy_reduce_print (yyssp, yyvsp, Rule); \
1603 /* Nonzero means print parse trace. It is left uninitialized so that
1604 multiple parsers can coexist. */
1606 #else /* !YYDEBUG */
1607 # define YYDPRINTF(Args) ((void) 0)
1608 # define YY_SYMBOL_PRINT(Title, Kind, Value, Location)
1609 # define YY_STACK_PRINT(Bottom, Top)
1610 # define YY_REDUCE_PRINT(Rule)
1611 #endif /* !YYDEBUG */
1614 /* YYINITDEPTH -- initial size of the parser's stacks. */
1616 # define YYINITDEPTH 200
1619 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
1620 if the built-in stack extension method is used).
1622 Do not make this value too large; the results are undefined if
1623 YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH)
1624 evaluated with infinite-precision integer arithmetic. */
1627 # define YYMAXDEPTH 10000
1635 /*-----------------------------------------------.
1636 | Release the memory associated to this symbol. |
1637 `-----------------------------------------------*/
1640 yydestruct (const char *yymsg
,
1641 yysymbol_kind_t yykind
, YYSTYPE
*yyvaluep
)
1646 YY_SYMBOL_PRINT (yymsg
, yykind
, yyvaluep
, yylocationp
);
1648 YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
1650 YY_IGNORE_MAYBE_UNINITIALIZED_END
1654 /* The lookahead symbol. */
1657 /* The semantic value of the lookahead symbol. */
1659 /* Number of syntax errors so far. */
1672 yy_state_fast_t yystate
;
1673 /* Number of tokens to shift before error messages enabled. */
1676 /* The stacks and their tools:
1677 'yyss': related to states.
1678 'yyvs': related to semantic values.
1680 Refer to the stacks through separate pointers, to allow yyoverflow
1681 to reallocate them elsewhere. */
1684 YYPTRDIFF_T yystacksize
;
1686 /* The state stack. */
1687 yy_state_t yyssa
[YYINITDEPTH
];
1691 /* The semantic value stack. */
1692 YYSTYPE yyvsa
[YYINITDEPTH
];
1697 /* The return value of yyparse. */
1699 /* Lookahead token as an internal (translated) token number. */
1700 yysymbol_kind_t yytoken
= YYSYMBOL_YYEMPTY
;
1701 /* The variables used to return semantic value and location from the
1707 #define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N))
1709 /* The number of symbols on the RHS of the reduced rule.
1710 Keep to zero when no symbol should be popped. */
1717 yystacksize
= YYINITDEPTH
;
1718 yyssp
= yyss
= yyssa
;
1719 yyvsp
= yyvs
= yyvsa
;
1722 YYDPRINTF ((stderr
, "Starting parse\n"));
1724 yychar
= YYEMPTY
; /* Cause a token to be read. */
1728 /*------------------------------------------------------------.
1729 | yynewstate -- push a new state, which is found in yystate. |
1730 `------------------------------------------------------------*/
1732 /* In all cases, when you get here, the value and location stacks
1733 have just been pushed. So pushing a state here evens the stacks. */
1737 /*--------------------------------------------------------------------.
1738 | yysetstate -- set current state (the top of the stack) to yystate. |
1739 `--------------------------------------------------------------------*/
1741 YYDPRINTF ((stderr
, "Entering state %d\n", yystate
));
1742 YY_ASSERT (0 <= yystate
&& yystate
< YYNSTATES
);
1743 YY_IGNORE_USELESS_CAST_BEGIN
1744 *yyssp
= YY_CAST (yy_state_t
, yystate
);
1745 YY_IGNORE_USELESS_CAST_END
1746 YY_STACK_PRINT (yyss
, yyssp
);
1748 if (yyss
+ yystacksize
- 1 <= yyssp
)
1749 #if !defined yyoverflow && !defined YYSTACK_RELOCATE
1750 goto yyexhaustedlab
;
1753 /* Get the current used size of the three stacks, in elements. */
1754 YYPTRDIFF_T yysize
= yyssp
- yyss
+ 1;
1756 # if defined yyoverflow
1758 /* Give user a chance to reallocate the stack. Use copies of
1759 these so that the &'s don't force the real ones into
1761 yy_state_t
*yyss1
= yyss
;
1762 YYSTYPE
*yyvs1
= yyvs
;
1764 /* Each stack pointer address is followed by the size of the
1765 data in use in that stack, in bytes. This used to be a
1766 conditional around just the two extra args, but that might
1767 be undefined if yyoverflow is a macro. */
1768 yyoverflow (YY_("memory exhausted"),
1769 &yyss1
, yysize
* YYSIZEOF (*yyssp
),
1770 &yyvs1
, yysize
* YYSIZEOF (*yyvsp
),
1775 # else /* defined YYSTACK_RELOCATE */
1776 /* Extend the stack our own way. */
1777 if (YYMAXDEPTH
<= yystacksize
)
1778 goto yyexhaustedlab
;
1780 if (YYMAXDEPTH
< yystacksize
)
1781 yystacksize
= YYMAXDEPTH
;
1784 yy_state_t
*yyss1
= yyss
;
1785 union yyalloc
*yyptr
=
1786 YY_CAST (union yyalloc
*,
1787 YYSTACK_ALLOC (YY_CAST (YYSIZE_T
, YYSTACK_BYTES (yystacksize
))));
1789 goto yyexhaustedlab
;
1790 YYSTACK_RELOCATE (yyss_alloc
, yyss
);
1791 YYSTACK_RELOCATE (yyvs_alloc
, yyvs
);
1792 # undef YYSTACK_RELOCATE
1794 YYSTACK_FREE (yyss1
);
1798 yyssp
= yyss
+ yysize
- 1;
1799 yyvsp
= yyvs
+ yysize
- 1;
1801 YY_IGNORE_USELESS_CAST_BEGIN
1802 YYDPRINTF ((stderr
, "Stack size increased to %ld\n",
1803 YY_CAST (long, yystacksize
)));
1804 YY_IGNORE_USELESS_CAST_END
1806 if (yyss
+ yystacksize
- 1 <= yyssp
)
1809 #endif /* !defined yyoverflow && !defined YYSTACK_RELOCATE */
1811 if (yystate
== YYFINAL
)
1821 /* Do appropriate processing given the current state. Read a
1822 lookahead token if we need one and don't already have one. */
1824 /* First try to decide what to do without reference to lookahead token. */
1825 yyn
= yypact
[yystate
];
1826 if (yypact_value_is_default (yyn
))
1829 /* Not known => get a lookahead token if don't already have one. */
1831 /* YYCHAR is either empty, or end-of-input, or a valid lookahead. */
1832 if (yychar
== YYEMPTY
)
1834 YYDPRINTF ((stderr
, "Reading a token\n"));
1838 if (yychar
<= YYEOF
)
1841 yytoken
= YYSYMBOL_YYEOF
;
1842 YYDPRINTF ((stderr
, "Now at end of input.\n"));
1844 else if (yychar
== YYerror
)
1846 /* The scanner already issued an error message, process directly
1847 to error recovery. But do not keep the error token as
1848 lookahead, it is too special and may lead us to an endless
1849 loop in error recovery. */
1851 yytoken
= YYSYMBOL_YYerror
;
1856 yytoken
= YYTRANSLATE (yychar
);
1857 YY_SYMBOL_PRINT ("Next token is", yytoken
, &yylval
, &yylloc
);
1860 /* If the proper action on seeing token YYTOKEN is to reduce or to
1861 detect an error, take that action. */
1863 if (yyn
< 0 || YYLAST
< yyn
|| yycheck
[yyn
] != yytoken
)
1868 if (yytable_value_is_error (yyn
))
1874 /* Count tokens shifted since error; after three, turn off error
1879 /* Shift the lookahead token. */
1880 YY_SYMBOL_PRINT ("Shifting", yytoken
, &yylval
, &yylloc
);
1882 YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
1884 YY_IGNORE_MAYBE_UNINITIALIZED_END
1886 /* Discard the shifted token. */
1891 /*-----------------------------------------------------------.
1892 | yydefault -- do the default action for the current state. |
1893 `-----------------------------------------------------------*/
1895 yyn
= yydefact
[yystate
];
1901 /*-----------------------------.
1902 | yyreduce -- do a reduction. |
1903 `-----------------------------*/
1905 /* yyn is the number of a rule to reduce with. */
1908 /* If YYLEN is nonzero, implement the default value of the action:
1911 Otherwise, the following line sets YYVAL to garbage.
1912 This behavior is undocumented and Bison
1913 users should not rely upon it. Assigning to YYVAL
1914 unconditionally makes the parser a bit smaller, and it avoids a
1915 GCC warning that YYVAL may be used uninitialized. */
1916 yyval
= yyvsp
[1-yylen
];
1919 YY_REDUCE_PRINT (yyn
);
1923 #line 382 "/Users/chet/src/bash/src/parse.y"
1925 /* Case of regular command. Discard the error
1926 safety net,and return the command just parsed. */
1927 global_command
= (yyvsp
[-1].command
);
1928 eof_encountered
= 0;
1929 /* discard_parser_constructs (0); */
1930 if (parser_state
& PST_CMDSUBST
)
1931 parser_state
|= PST_EOFTOKEN
;
1934 #line 1935 "y.tab.c"
1938 #line 393 "/Users/chet/src/bash/src/parse.y"
1940 /* Case of regular command, but not a very
1941 interesting one. Return a NULL command. */
1942 global_command
= (COMMAND
*)NULL
;
1943 if (parser_state
& PST_CMDSUBST
)
1944 parser_state
|= PST_EOFTOKEN
;
1947 #line 1948 "y.tab.c"
1951 #line 402 "/Users/chet/src/bash/src/parse.y"
1953 /* Error during parsing. Return NULL command. */
1954 global_command
= (COMMAND
*)NULL
;
1955 eof_encountered
= 0;
1956 /* discard_parser_constructs (1); */
1957 if (interactive
&& parse_and_execute_level
== 0)
1966 #line 1967 "y.tab.c"
1970 #line 417 "/Users/chet/src/bash/src/parse.y"
1972 /* EOF after an error. Do ignoreeof or not. Really
1973 only interesting in non-interactive shells */
1974 global_command
= (COMMAND
*)NULL
;
1975 if (last_command_exit_value
== 0)
1976 last_command_exit_value
= EX_BADUSAGE
; /* force error return */
1977 if (interactive
&& parse_and_execute_level
== 0)
1979 handle_eof_input_unit ();
1987 #line 1988 "y.tab.c"
1991 #line 434 "/Users/chet/src/bash/src/parse.y"
1993 /* Case of EOF seen by itself. Do ignoreeof or
1995 global_command
= (COMMAND
*)NULL
;
1996 handle_eof_input_unit ();
1999 #line 2000 "y.tab.c"
2003 #line 444 "/Users/chet/src/bash/src/parse.y"
2004 { (yyval
.word_list
) = make_word_list ((yyvsp
[0].word
), (WORD_LIST
*)NULL
); }
2005 #line 2006 "y.tab.c"
2009 #line 446 "/Users/chet/src/bash/src/parse.y"
2010 { (yyval
.word_list
) = make_word_list ((yyvsp
[0].word
), (yyvsp
[-1].word_list
)); }
2011 #line 2012 "y.tab.c"
2015 #line 450 "/Users/chet/src/bash/src/parse.y"
2018 redir
.filename
= (yyvsp
[0].word
);
2019 (yyval
.redirect
) = make_redirection (source
, r_output_direction
, redir
, 0);
2021 #line 2022 "y.tab.c"
2025 #line 456 "/Users/chet/src/bash/src/parse.y"
2028 redir
.filename
= (yyvsp
[0].word
);
2029 (yyval
.redirect
) = make_redirection (source
, r_input_direction
, redir
, 0);
2031 #line 2032 "y.tab.c"
2035 #line 462 "/Users/chet/src/bash/src/parse.y"
2037 source
.dest
= (yyvsp
[-2].number
);
2038 redir
.filename
= (yyvsp
[0].word
);
2039 (yyval
.redirect
) = make_redirection (source
, r_output_direction
, redir
, 0);
2041 #line 2042 "y.tab.c"
2045 #line 468 "/Users/chet/src/bash/src/parse.y"
2047 source
.dest
= (yyvsp
[-2].number
);
2048 redir
.filename
= (yyvsp
[0].word
);
2049 (yyval
.redirect
) = make_redirection (source
, r_input_direction
, redir
, 0);
2051 #line 2052 "y.tab.c"
2055 #line 474 "/Users/chet/src/bash/src/parse.y"
2057 source
.filename
= (yyvsp
[-2].word
);
2058 redir
.filename
= (yyvsp
[0].word
);
2059 (yyval
.redirect
) = make_redirection (source
, r_output_direction
, redir
, REDIR_VARASSIGN
);
2061 #line 2062 "y.tab.c"
2065 #line 480 "/Users/chet/src/bash/src/parse.y"
2067 source
.filename
= (yyvsp
[-2].word
);
2068 redir
.filename
= (yyvsp
[0].word
);
2069 (yyval
.redirect
) = make_redirection (source
, r_input_direction
, redir
, REDIR_VARASSIGN
);
2071 #line 2072 "y.tab.c"
2075 #line 486 "/Users/chet/src/bash/src/parse.y"
2078 redir
.filename
= (yyvsp
[0].word
);
2079 (yyval
.redirect
) = make_redirection (source
, r_appending_to
, redir
, 0);
2081 #line 2082 "y.tab.c"
2085 #line 492 "/Users/chet/src/bash/src/parse.y"
2087 source
.dest
= (yyvsp
[-2].number
);
2088 redir
.filename
= (yyvsp
[0].word
);
2089 (yyval
.redirect
) = make_redirection (source
, r_appending_to
, redir
, 0);
2091 #line 2092 "y.tab.c"
2095 #line 498 "/Users/chet/src/bash/src/parse.y"
2097 source
.filename
= (yyvsp
[-2].word
);
2098 redir
.filename
= (yyvsp
[0].word
);
2099 (yyval
.redirect
) = make_redirection (source
, r_appending_to
, redir
, REDIR_VARASSIGN
);
2101 #line 2102 "y.tab.c"
2105 #line 504 "/Users/chet/src/bash/src/parse.y"
2108 redir
.filename
= (yyvsp
[0].word
);
2109 (yyval
.redirect
) = make_redirection (source
, r_output_force
, redir
, 0);
2111 #line 2112 "y.tab.c"
2115 #line 510 "/Users/chet/src/bash/src/parse.y"
2117 source
.dest
= (yyvsp
[-2].number
);
2118 redir
.filename
= (yyvsp
[0].word
);
2119 (yyval
.redirect
) = make_redirection (source
, r_output_force
, redir
, 0);
2121 #line 2122 "y.tab.c"
2125 #line 516 "/Users/chet/src/bash/src/parse.y"
2127 source
.filename
= (yyvsp
[-2].word
);
2128 redir
.filename
= (yyvsp
[0].word
);
2129 (yyval
.redirect
) = make_redirection (source
, r_output_force
, redir
, REDIR_VARASSIGN
);
2131 #line 2132 "y.tab.c"
2135 #line 522 "/Users/chet/src/bash/src/parse.y"
2138 redir
.filename
= (yyvsp
[0].word
);
2139 (yyval
.redirect
) = make_redirection (source
, r_input_output
, redir
, 0);
2141 #line 2142 "y.tab.c"
2145 #line 528 "/Users/chet/src/bash/src/parse.y"
2147 source
.dest
= (yyvsp
[-2].number
);
2148 redir
.filename
= (yyvsp
[0].word
);
2149 (yyval
.redirect
) = make_redirection (source
, r_input_output
, redir
, 0);
2151 #line 2152 "y.tab.c"
2155 #line 534 "/Users/chet/src/bash/src/parse.y"
2157 source
.filename
= (yyvsp
[-2].word
);
2158 redir
.filename
= (yyvsp
[0].word
);
2159 (yyval
.redirect
) = make_redirection (source
, r_input_output
, redir
, REDIR_VARASSIGN
);
2161 #line 2162 "y.tab.c"
2165 #line 540 "/Users/chet/src/bash/src/parse.y"
2168 redir
.filename
= (yyvsp
[0].word
);
2169 (yyval
.redirect
) = make_redirection (source
, r_reading_until
, redir
, 0);
2170 push_heredoc ((yyval
.redirect
));
2172 #line 2173 "y.tab.c"
2176 #line 547 "/Users/chet/src/bash/src/parse.y"
2178 source
.dest
= (yyvsp
[-2].number
);
2179 redir
.filename
= (yyvsp
[0].word
);
2180 (yyval
.redirect
) = make_redirection (source
, r_reading_until
, redir
, 0);
2181 push_heredoc ((yyval
.redirect
));
2183 #line 2184 "y.tab.c"
2187 #line 554 "/Users/chet/src/bash/src/parse.y"
2189 source
.filename
= (yyvsp
[-2].word
);
2190 redir
.filename
= (yyvsp
[0].word
);
2191 (yyval
.redirect
) = make_redirection (source
, r_reading_until
, redir
, REDIR_VARASSIGN
);
2192 push_heredoc ((yyval
.redirect
));
2194 #line 2195 "y.tab.c"
2198 #line 561 "/Users/chet/src/bash/src/parse.y"
2201 redir
.filename
= (yyvsp
[0].word
);
2202 (yyval
.redirect
) = make_redirection (source
, r_deblank_reading_until
, redir
, 0);
2203 push_heredoc ((yyval
.redirect
));
2205 #line 2206 "y.tab.c"
2209 #line 568 "/Users/chet/src/bash/src/parse.y"
2211 source
.dest
= (yyvsp
[-2].number
);
2212 redir
.filename
= (yyvsp
[0].word
);
2213 (yyval
.redirect
) = make_redirection (source
, r_deblank_reading_until
, redir
, 0);
2214 push_heredoc ((yyval
.redirect
));
2216 #line 2217 "y.tab.c"
2220 #line 575 "/Users/chet/src/bash/src/parse.y"
2222 source
.filename
= (yyvsp
[-2].word
);
2223 redir
.filename
= (yyvsp
[0].word
);
2224 (yyval
.redirect
) = make_redirection (source
, r_deblank_reading_until
, redir
, REDIR_VARASSIGN
);
2225 push_heredoc ((yyval
.redirect
));
2227 #line 2228 "y.tab.c"
2231 #line 582 "/Users/chet/src/bash/src/parse.y"
2234 redir
.filename
= (yyvsp
[0].word
);
2235 (yyval
.redirect
) = make_redirection (source
, r_reading_string
, redir
, 0);
2237 #line 2238 "y.tab.c"
2241 #line 588 "/Users/chet/src/bash/src/parse.y"
2243 source
.dest
= (yyvsp
[-2].number
);
2244 redir
.filename
= (yyvsp
[0].word
);
2245 (yyval
.redirect
) = make_redirection (source
, r_reading_string
, redir
, 0);
2247 #line 2248 "y.tab.c"
2251 #line 594 "/Users/chet/src/bash/src/parse.y"
2253 source
.filename
= (yyvsp
[-2].word
);
2254 redir
.filename
= (yyvsp
[0].word
);
2255 (yyval
.redirect
) = make_redirection (source
, r_reading_string
, redir
, REDIR_VARASSIGN
);
2257 #line 2258 "y.tab.c"
2261 #line 600 "/Users/chet/src/bash/src/parse.y"
2264 redir
.dest
= (yyvsp
[0].number
);
2265 (yyval
.redirect
) = make_redirection (source
, r_duplicating_input
, redir
, 0);
2267 #line 2268 "y.tab.c"
2271 #line 606 "/Users/chet/src/bash/src/parse.y"
2273 source
.dest
= (yyvsp
[-2].number
);
2274 redir
.dest
= (yyvsp
[0].number
);
2275 (yyval
.redirect
) = make_redirection (source
, r_duplicating_input
, redir
, 0);
2277 #line 2278 "y.tab.c"
2281 #line 612 "/Users/chet/src/bash/src/parse.y"
2283 source
.filename
= (yyvsp
[-2].word
);
2284 redir
.dest
= (yyvsp
[0].number
);
2285 (yyval
.redirect
) = make_redirection (source
, r_duplicating_input
, redir
, REDIR_VARASSIGN
);
2287 #line 2288 "y.tab.c"
2291 #line 618 "/Users/chet/src/bash/src/parse.y"
2294 redir
.dest
= (yyvsp
[0].number
);
2295 (yyval
.redirect
) = make_redirection (source
, r_duplicating_output
, redir
, 0);
2297 #line 2298 "y.tab.c"
2301 #line 624 "/Users/chet/src/bash/src/parse.y"
2303 source
.dest
= (yyvsp
[-2].number
);
2304 redir
.dest
= (yyvsp
[0].number
);
2305 (yyval
.redirect
) = make_redirection (source
, r_duplicating_output
, redir
, 0);
2307 #line 2308 "y.tab.c"
2311 #line 630 "/Users/chet/src/bash/src/parse.y"
2313 source
.filename
= (yyvsp
[-2].word
);
2314 redir
.dest
= (yyvsp
[0].number
);
2315 (yyval
.redirect
) = make_redirection (source
, r_duplicating_output
, redir
, REDIR_VARASSIGN
);
2317 #line 2318 "y.tab.c"
2321 #line 636 "/Users/chet/src/bash/src/parse.y"
2324 redir
.filename
= (yyvsp
[0].word
);
2325 (yyval
.redirect
) = make_redirection (source
, r_duplicating_input_word
, redir
, 0);
2327 #line 2328 "y.tab.c"
2331 #line 642 "/Users/chet/src/bash/src/parse.y"
2333 source
.dest
= (yyvsp
[-2].number
);
2334 redir
.filename
= (yyvsp
[0].word
);
2335 (yyval
.redirect
) = make_redirection (source
, r_duplicating_input_word
, redir
, 0);
2337 #line 2338 "y.tab.c"
2341 #line 648 "/Users/chet/src/bash/src/parse.y"
2343 source
.filename
= (yyvsp
[-2].word
);
2344 redir
.filename
= (yyvsp
[0].word
);
2345 (yyval
.redirect
) = make_redirection (source
, r_duplicating_input_word
, redir
, REDIR_VARASSIGN
);
2347 #line 2348 "y.tab.c"
2351 #line 654 "/Users/chet/src/bash/src/parse.y"
2354 redir
.filename
= (yyvsp
[0].word
);
2355 (yyval
.redirect
) = make_redirection (source
, r_duplicating_output_word
, redir
, 0);
2357 #line 2358 "y.tab.c"
2361 #line 660 "/Users/chet/src/bash/src/parse.y"
2363 source
.dest
= (yyvsp
[-2].number
);
2364 redir
.filename
= (yyvsp
[0].word
);
2365 (yyval
.redirect
) = make_redirection (source
, r_duplicating_output_word
, redir
, 0);
2367 #line 2368 "y.tab.c"
2371 #line 666 "/Users/chet/src/bash/src/parse.y"
2373 source
.filename
= (yyvsp
[-2].word
);
2374 redir
.filename
= (yyvsp
[0].word
);
2375 (yyval
.redirect
) = make_redirection (source
, r_duplicating_output_word
, redir
, REDIR_VARASSIGN
);
2377 #line 2378 "y.tab.c"
2381 #line 672 "/Users/chet/src/bash/src/parse.y"
2385 (yyval
.redirect
) = make_redirection (source
, r_close_this
, redir
, 0);
2387 #line 2388 "y.tab.c"
2391 #line 678 "/Users/chet/src/bash/src/parse.y"
2393 source
.dest
= (yyvsp
[-2].number
);
2395 (yyval
.redirect
) = make_redirection (source
, r_close_this
, redir
, 0);
2397 #line 2398 "y.tab.c"
2401 #line 684 "/Users/chet/src/bash/src/parse.y"
2403 source
.filename
= (yyvsp
[-2].word
);
2405 (yyval
.redirect
) = make_redirection (source
, r_close_this
, redir
, REDIR_VARASSIGN
);
2407 #line 2408 "y.tab.c"
2411 #line 690 "/Users/chet/src/bash/src/parse.y"
2415 (yyval
.redirect
) = make_redirection (source
, r_close_this
, redir
, 0);
2417 #line 2418 "y.tab.c"
2421 #line 696 "/Users/chet/src/bash/src/parse.y"
2423 source
.dest
= (yyvsp
[-2].number
);
2425 (yyval
.redirect
) = make_redirection (source
, r_close_this
, redir
, 0);
2427 #line 2428 "y.tab.c"
2431 #line 702 "/Users/chet/src/bash/src/parse.y"
2433 source
.filename
= (yyvsp
[-2].word
);
2435 (yyval
.redirect
) = make_redirection (source
, r_close_this
, redir
, REDIR_VARASSIGN
);
2437 #line 2438 "y.tab.c"
2441 #line 708 "/Users/chet/src/bash/src/parse.y"
2444 redir
.filename
= (yyvsp
[0].word
);
2445 (yyval
.redirect
) = make_redirection (source
, r_err_and_out
, redir
, 0);
2447 #line 2448 "y.tab.c"
2451 #line 714 "/Users/chet/src/bash/src/parse.y"
2454 redir
.filename
= (yyvsp
[0].word
);
2455 (yyval
.redirect
) = make_redirection (source
, r_append_err_and_out
, redir
, 0);
2457 #line 2458 "y.tab.c"
2461 #line 722 "/Users/chet/src/bash/src/parse.y"
2462 { (yyval
.element
).word
= (yyvsp
[0].word
); (yyval
.element
).redirect
= 0; }
2463 #line 2464 "y.tab.c"
2467 #line 724 "/Users/chet/src/bash/src/parse.y"
2468 { (yyval
.element
).word
= (yyvsp
[0].word
); (yyval
.element
).redirect
= 0; }
2469 #line 2470 "y.tab.c"
2473 #line 726 "/Users/chet/src/bash/src/parse.y"
2474 { (yyval
.element
).redirect
= (yyvsp
[0].redirect
); (yyval
.element
).word
= 0; }
2475 #line 2476 "y.tab.c"
2479 #line 730 "/Users/chet/src/bash/src/parse.y"
2481 (yyval
.redirect
) = (yyvsp
[0].redirect
);
2483 #line 2484 "y.tab.c"
2487 #line 734 "/Users/chet/src/bash/src/parse.y"
2489 register REDIRECT
*t
;
2491 for (t
= (yyvsp
[-1].redirect
); t
->next
; t
= t
->next
)
2493 t
->next
= (yyvsp
[0].redirect
);
2494 (yyval
.redirect
) = (yyvsp
[-1].redirect
);
2496 #line 2497 "y.tab.c"
2500 #line 745 "/Users/chet/src/bash/src/parse.y"
2501 { (yyval
.command
) = make_simple_command ((yyvsp
[0].element
), (COMMAND
*)NULL
); }
2502 #line 2503 "y.tab.c"
2506 #line 747 "/Users/chet/src/bash/src/parse.y"
2507 { (yyval
.command
) = make_simple_command ((yyvsp
[0].element
), (yyvsp
[-1].command
)); }
2508 #line 2509 "y.tab.c"
2512 #line 751 "/Users/chet/src/bash/src/parse.y"
2513 { (yyval
.command
) = clean_simple_command ((yyvsp
[0].command
)); }
2514 #line 2515 "y.tab.c"
2518 #line 753 "/Users/chet/src/bash/src/parse.y"
2519 { (yyval
.command
) = (yyvsp
[0].command
); }
2520 #line 2521 "y.tab.c"
2524 #line 755 "/Users/chet/src/bash/src/parse.y"
2528 tc
= (yyvsp
[-1].command
);
2529 if (tc
&& tc
->redirects
)
2531 register REDIRECT
*t
;
2532 for (t
= tc
->redirects
; t
->next
; t
= t
->next
)
2534 t
->next
= (yyvsp
[0].redirect
);
2537 tc
->redirects
= (yyvsp
[0].redirect
);
2538 (yyval
.command
) = (yyvsp
[-1].command
);
2540 #line 2541 "y.tab.c"
2544 #line 771 "/Users/chet/src/bash/src/parse.y"
2545 { (yyval
.command
) = (yyvsp
[0].command
); }
2546 #line 2547 "y.tab.c"
2550 #line 773 "/Users/chet/src/bash/src/parse.y"
2551 { (yyval
.command
) = (yyvsp
[0].command
); }
2552 #line 2553 "y.tab.c"
2556 #line 777 "/Users/chet/src/bash/src/parse.y"
2557 { (yyval
.command
) = (yyvsp
[0].command
); }
2558 #line 2559 "y.tab.c"
2562 #line 779 "/Users/chet/src/bash/src/parse.y"
2563 { (yyval
.command
) = (yyvsp
[0].command
); }
2564 #line 2565 "y.tab.c"
2568 #line 781 "/Users/chet/src/bash/src/parse.y"
2569 { (yyval
.command
) = make_while_command ((yyvsp
[-3].command
), (yyvsp
[-1].command
)); }
2570 #line 2571 "y.tab.c"
2574 #line 783 "/Users/chet/src/bash/src/parse.y"
2575 { (yyval
.command
) = make_until_command ((yyvsp
[-3].command
), (yyvsp
[-1].command
)); }
2576 #line 2577 "y.tab.c"
2580 #line 785 "/Users/chet/src/bash/src/parse.y"
2581 { (yyval
.command
) = (yyvsp
[0].command
); }
2582 #line 2583 "y.tab.c"
2586 #line 787 "/Users/chet/src/bash/src/parse.y"
2587 { (yyval
.command
) = (yyvsp
[0].command
); }
2588 #line 2589 "y.tab.c"
2592 #line 789 "/Users/chet/src/bash/src/parse.y"
2593 { (yyval
.command
) = (yyvsp
[0].command
); }
2594 #line 2595 "y.tab.c"
2598 #line 791 "/Users/chet/src/bash/src/parse.y"
2599 { (yyval
.command
) = (yyvsp
[0].command
); }
2600 #line 2601 "y.tab.c"
2604 #line 793 "/Users/chet/src/bash/src/parse.y"
2605 { (yyval
.command
) = (yyvsp
[0].command
); }
2606 #line 2607 "y.tab.c"
2610 #line 795 "/Users/chet/src/bash/src/parse.y"
2611 { (yyval
.command
) = (yyvsp
[0].command
); }
2612 #line 2613 "y.tab.c"
2616 #line 797 "/Users/chet/src/bash/src/parse.y"
2617 { (yyval
.command
) = (yyvsp
[0].command
); }
2618 #line 2619 "y.tab.c"
2622 #line 801 "/Users/chet/src/bash/src/parse.y"
2624 (yyval
.command
) = make_for_command ((yyvsp
[-4].word
), add_string_to_list ("\"$@\"", (WORD_LIST
*)NULL
), (yyvsp
[-1].command
), word_lineno
[word_top
]);
2625 if (word_top
> 0) word_top
--;
2627 #line 2628 "y.tab.c"
2631 #line 806 "/Users/chet/src/bash/src/parse.y"
2633 (yyval
.command
) = make_for_command ((yyvsp
[-4].word
), add_string_to_list ("\"$@\"", (WORD_LIST
*)NULL
), (yyvsp
[-1].command
), word_lineno
[word_top
]);
2634 if (word_top
> 0) word_top
--;
2636 #line 2637 "y.tab.c"
2640 #line 811 "/Users/chet/src/bash/src/parse.y"
2642 (yyval
.command
) = make_for_command ((yyvsp
[-5].word
), add_string_to_list ("\"$@\"", (WORD_LIST
*)NULL
), (yyvsp
[-1].command
), word_lineno
[word_top
]);
2643 if (word_top
> 0) word_top
--;
2645 #line 2646 "y.tab.c"
2649 #line 816 "/Users/chet/src/bash/src/parse.y"
2651 (yyval
.command
) = make_for_command ((yyvsp
[-5].word
), add_string_to_list ("\"$@\"", (WORD_LIST
*)NULL
), (yyvsp
[-1].command
), word_lineno
[word_top
]);
2652 if (word_top
> 0) word_top
--;
2654 #line 2655 "y.tab.c"
2658 #line 821 "/Users/chet/src/bash/src/parse.y"
2660 (yyval
.command
) = make_for_command ((yyvsp
[-8].word
), REVERSE_LIST ((yyvsp
[-5].word_list
), WORD_LIST
*), (yyvsp
[-1].command
), word_lineno
[word_top
]);
2661 if (word_top
> 0) word_top
--;
2663 #line 2664 "y.tab.c"
2667 #line 826 "/Users/chet/src/bash/src/parse.y"
2669 (yyval
.command
) = make_for_command ((yyvsp
[-8].word
), REVERSE_LIST ((yyvsp
[-5].word_list
), WORD_LIST
*), (yyvsp
[-1].command
), word_lineno
[word_top
]);
2670 if (word_top
> 0) word_top
--;
2672 #line 2673 "y.tab.c"
2676 #line 831 "/Users/chet/src/bash/src/parse.y"
2678 (yyval
.command
) = make_for_command ((yyvsp
[-7].word
), (WORD_LIST
*)NULL
, (yyvsp
[-1].command
), word_lineno
[word_top
]);
2679 if (word_top
> 0) word_top
--;
2681 #line 2682 "y.tab.c"
2685 #line 836 "/Users/chet/src/bash/src/parse.y"
2687 (yyval
.command
) = make_for_command ((yyvsp
[-7].word
), (WORD_LIST
*)NULL
, (yyvsp
[-1].command
), word_lineno
[word_top
]);
2688 if (word_top
> 0) word_top
--;
2690 #line 2691 "y.tab.c"
2694 #line 843 "/Users/chet/src/bash/src/parse.y"
2696 (yyval
.command
) = make_arith_for_command ((yyvsp
[-5].word_list
), (yyvsp
[-1].command
), arith_for_lineno
);
2697 if ((yyval
.command
) == 0) YYERROR
;
2698 if (word_top
> 0) word_top
--;
2700 #line 2701 "y.tab.c"
2704 #line 849 "/Users/chet/src/bash/src/parse.y"
2706 (yyval
.command
) = make_arith_for_command ((yyvsp
[-5].word_list
), (yyvsp
[-1].command
), arith_for_lineno
);
2707 if ((yyval
.command
) == 0) YYERROR
;
2708 if (word_top
> 0) word_top
--;
2710 #line 2711 "y.tab.c"
2714 #line 855 "/Users/chet/src/bash/src/parse.y"
2716 (yyval
.command
) = make_arith_for_command ((yyvsp
[-3].word_list
), (yyvsp
[-1].command
), arith_for_lineno
);
2717 if ((yyval
.command
) == 0) YYERROR
;
2718 if (word_top
> 0) word_top
--;
2720 #line 2721 "y.tab.c"
2724 #line 861 "/Users/chet/src/bash/src/parse.y"
2726 (yyval
.command
) = make_arith_for_command ((yyvsp
[-3].word_list
), (yyvsp
[-1].command
), arith_for_lineno
);
2727 if ((yyval
.command
) == 0) YYERROR
;
2728 if (word_top
> 0) word_top
--;
2730 #line 2731 "y.tab.c"
2734 #line 869 "/Users/chet/src/bash/src/parse.y"
2736 (yyval
.command
) = make_select_command ((yyvsp
[-4].word
), add_string_to_list ("\"$@\"", (WORD_LIST
*)NULL
), (yyvsp
[-1].command
), word_lineno
[word_top
]);
2737 if (word_top
> 0) word_top
--;
2739 #line 2740 "y.tab.c"
2743 #line 874 "/Users/chet/src/bash/src/parse.y"
2745 (yyval
.command
) = make_select_command ((yyvsp
[-4].word
), add_string_to_list ("\"$@\"", (WORD_LIST
*)NULL
), (yyvsp
[-1].command
), word_lineno
[word_top
]);
2746 if (word_top
> 0) word_top
--;
2748 #line 2749 "y.tab.c"
2752 #line 879 "/Users/chet/src/bash/src/parse.y"
2754 (yyval
.command
) = make_select_command ((yyvsp
[-5].word
), add_string_to_list ("\"$@\"", (WORD_LIST
*)NULL
), (yyvsp
[-1].command
), word_lineno
[word_top
]);
2755 if (word_top
> 0) word_top
--;
2757 #line 2758 "y.tab.c"
2761 #line 884 "/Users/chet/src/bash/src/parse.y"
2763 (yyval
.command
) = make_select_command ((yyvsp
[-5].word
), add_string_to_list ("\"$@\"", (WORD_LIST
*)NULL
), (yyvsp
[-1].command
), word_lineno
[word_top
]);
2764 if (word_top
> 0) word_top
--;
2766 #line 2767 "y.tab.c"
2770 #line 889 "/Users/chet/src/bash/src/parse.y"
2772 (yyval
.command
) = make_select_command ((yyvsp
[-8].word
), REVERSE_LIST ((yyvsp
[-5].word_list
), WORD_LIST
*), (yyvsp
[-1].command
), word_lineno
[word_top
]);
2773 if (word_top
> 0) word_top
--;
2775 #line 2776 "y.tab.c"
2779 #line 894 "/Users/chet/src/bash/src/parse.y"
2781 (yyval
.command
) = make_select_command ((yyvsp
[-8].word
), REVERSE_LIST ((yyvsp
[-5].word_list
), WORD_LIST
*), (yyvsp
[-1].command
), word_lineno
[word_top
]);
2782 if (word_top
> 0) word_top
--;
2784 #line 2785 "y.tab.c"
2788 #line 899 "/Users/chet/src/bash/src/parse.y"
2790 (yyval
.command
) = make_select_command ((yyvsp
[-7].word
), (WORD_LIST
*)NULL
, (yyvsp
[-1].command
), word_lineno
[word_top
]);
2791 if (word_top
> 0) word_top
--;
2793 #line 2794 "y.tab.c"
2797 #line 904 "/Users/chet/src/bash/src/parse.y"
2799 (yyval
.command
) = make_select_command ((yyvsp
[-7].word
), (WORD_LIST
*)NULL
, (yyvsp
[-1].command
), word_lineno
[word_top
]);
2800 if (word_top
> 0) word_top
--;
2802 #line 2803 "y.tab.c"
2806 #line 911 "/Users/chet/src/bash/src/parse.y"
2808 (yyval
.command
) = make_case_command ((yyvsp
[-4].word
), (PATTERN_LIST
*)NULL
, word_lineno
[word_top
]);
2809 if (word_top
> 0) word_top
--;
2811 #line 2812 "y.tab.c"
2815 #line 916 "/Users/chet/src/bash/src/parse.y"
2817 (yyval
.command
) = make_case_command ((yyvsp
[-5].word
), (yyvsp
[-2].pattern
), word_lineno
[word_top
]);
2818 if (word_top
> 0) word_top
--;
2820 #line 2821 "y.tab.c"
2824 #line 921 "/Users/chet/src/bash/src/parse.y"
2826 (yyval
.command
) = make_case_command ((yyvsp
[-4].word
), (yyvsp
[-1].pattern
), word_lineno
[word_top
]);
2827 if (word_top
> 0) word_top
--;
2829 #line 2830 "y.tab.c"
2833 #line 928 "/Users/chet/src/bash/src/parse.y"
2834 { (yyval
.command
) = make_function_def ((yyvsp
[-4].word
), (yyvsp
[0].command
), function_dstart
, function_bstart
); }
2835 #line 2836 "y.tab.c"
2839 #line 930 "/Users/chet/src/bash/src/parse.y"
2840 { (yyval
.command
) = make_function_def ((yyvsp
[-4].word
), (yyvsp
[0].command
), function_dstart
, function_bstart
); }
2841 #line 2842 "y.tab.c"
2845 #line 932 "/Users/chet/src/bash/src/parse.y"
2846 { (yyval
.command
) = make_function_def ((yyvsp
[-1].word
), (yyvsp
[0].command
), function_dstart
, function_bstart
); }
2847 #line 2848 "y.tab.c"
2851 #line 934 "/Users/chet/src/bash/src/parse.y"
2852 { (yyval
.command
) = make_function_def ((yyvsp
[-3].word
), (yyvsp
[0].command
), function_dstart
, function_bstart
); }
2853 #line 2854 "y.tab.c"
2857 #line 938 "/Users/chet/src/bash/src/parse.y"
2858 { (yyval
.command
) = (yyvsp
[0].command
); }
2859 #line 2860 "y.tab.c"
2863 #line 940 "/Users/chet/src/bash/src/parse.y"
2867 tc
= (yyvsp
[-1].command
);
2868 /* According to Posix.2 3.9.5, redirections
2869 specified after the body of a function should
2870 be attached to the function and performed when
2871 the function is executed, not as part of the
2872 function definition command. */
2873 /* XXX - I don't think it matters, but we might
2874 want to change this in the future to avoid
2875 problems differentiating between a function
2876 definition with a redirection and a function
2877 definition containing a single command with a
2878 redirection. The two are semantically equivalent,
2879 though -- the only difference is in how the
2880 command printing code displays the redirections. */
2881 if (tc
&& tc
->redirects
)
2883 register REDIRECT
*t
;
2884 for (t
= tc
->redirects
; t
->next
; t
= t
->next
)
2886 t
->next
= (yyvsp
[0].redirect
);
2889 tc
->redirects
= (yyvsp
[0].redirect
);
2890 (yyval
.command
) = (yyvsp
[-1].command
);
2892 #line 2893 "y.tab.c"
2896 #line 971 "/Users/chet/src/bash/src/parse.y"
2898 (yyval
.command
) = make_subshell_command ((yyvsp
[-1].command
));
2899 (yyval
.command
)->flags
|= CMD_WANT_SUBSHELL
;
2901 #line 2902 "y.tab.c"
2905 #line 978 "/Users/chet/src/bash/src/parse.y"
2907 (yyval
.command
) = make_coproc_command ("COPROC", (yyvsp
[0].command
));
2908 (yyval
.command
)->flags
|= CMD_WANT_SUBSHELL
|CMD_COPROC_SUBSHELL
;
2910 #line 2911 "y.tab.c"
2914 #line 983 "/Users/chet/src/bash/src/parse.y"
2918 tc
= (yyvsp
[-1].command
);
2919 if (tc
&& tc
->redirects
)
2921 register REDIRECT
*t
;
2922 for (t
= tc
->redirects
; t
->next
; t
= t
->next
)
2924 t
->next
= (yyvsp
[0].redirect
);
2927 tc
->redirects
= (yyvsp
[0].redirect
);
2928 (yyval
.command
) = make_coproc_command ("COPROC", (yyvsp
[-1].command
));
2929 (yyval
.command
)->flags
|= CMD_WANT_SUBSHELL
|CMD_COPROC_SUBSHELL
;
2931 #line 2932 "y.tab.c"
2935 #line 1000 "/Users/chet/src/bash/src/parse.y"
2937 (yyval
.command
) = make_coproc_command ((yyvsp
[-1].word
)->word
, (yyvsp
[0].command
));
2938 (yyval
.command
)->flags
|= CMD_WANT_SUBSHELL
|CMD_COPROC_SUBSHELL
;
2940 #line 2941 "y.tab.c"
2944 #line 1005 "/Users/chet/src/bash/src/parse.y"
2948 tc
= (yyvsp
[-1].command
);
2949 if (tc
&& tc
->redirects
)
2951 register REDIRECT
*t
;
2952 for (t
= tc
->redirects
; t
->next
; t
= t
->next
)
2954 t
->next
= (yyvsp
[0].redirect
);
2957 tc
->redirects
= (yyvsp
[0].redirect
);
2958 (yyval
.command
) = make_coproc_command ((yyvsp
[-2].word
)->word
, (yyvsp
[-1].command
));
2959 (yyval
.command
)->flags
|= CMD_WANT_SUBSHELL
|CMD_COPROC_SUBSHELL
;
2961 #line 2962 "y.tab.c"
2965 #line 1022 "/Users/chet/src/bash/src/parse.y"
2967 (yyval
.command
) = make_coproc_command ("COPROC", clean_simple_command ((yyvsp
[0].command
)));
2968 (yyval
.command
)->flags
|= CMD_WANT_SUBSHELL
|CMD_COPROC_SUBSHELL
;
2970 #line 2971 "y.tab.c"
2974 #line 1029 "/Users/chet/src/bash/src/parse.y"
2975 { (yyval
.command
) = make_if_command ((yyvsp
[-3].command
), (yyvsp
[-1].command
), (COMMAND
*)NULL
); }
2976 #line 2977 "y.tab.c"
2980 #line 1031 "/Users/chet/src/bash/src/parse.y"
2981 { (yyval
.command
) = make_if_command ((yyvsp
[-5].command
), (yyvsp
[-3].command
), (yyvsp
[-1].command
)); }
2982 #line 2983 "y.tab.c"
2986 #line 1033 "/Users/chet/src/bash/src/parse.y"
2987 { (yyval
.command
) = make_if_command ((yyvsp
[-4].command
), (yyvsp
[-2].command
), (yyvsp
[-1].command
)); }
2988 #line 2989 "y.tab.c"
2992 #line 1038 "/Users/chet/src/bash/src/parse.y"
2993 { (yyval
.command
) = make_group_command ((yyvsp
[-1].command
)); }
2994 #line 2995 "y.tab.c"
2998 #line 1042 "/Users/chet/src/bash/src/parse.y"
2999 { (yyval
.command
) = make_arith_command ((yyvsp
[0].word_list
)); }
3000 #line 3001 "y.tab.c"
3004 #line 1046 "/Users/chet/src/bash/src/parse.y"
3005 { (yyval
.command
) = (yyvsp
[-1].command
); }
3006 #line 3007 "y.tab.c"
3010 #line 1050 "/Users/chet/src/bash/src/parse.y"
3011 { (yyval
.command
) = make_if_command ((yyvsp
[-2].command
), (yyvsp
[0].command
), (COMMAND
*)NULL
); }
3012 #line 3013 "y.tab.c"
3016 #line 1052 "/Users/chet/src/bash/src/parse.y"
3017 { (yyval
.command
) = make_if_command ((yyvsp
[-4].command
), (yyvsp
[-2].command
), (yyvsp
[0].command
)); }
3018 #line 3019 "y.tab.c"
3022 #line 1054 "/Users/chet/src/bash/src/parse.y"
3023 { (yyval
.command
) = make_if_command ((yyvsp
[-3].command
), (yyvsp
[-1].command
), (yyvsp
[0].command
)); }
3024 #line 3025 "y.tab.c"
3028 #line 1059 "/Users/chet/src/bash/src/parse.y"
3029 { (yyvsp
[0].pattern
)->next
= (yyvsp
[-1].pattern
); (yyval
.pattern
) = (yyvsp
[0].pattern
); }
3030 #line 3031 "y.tab.c"
3034 #line 1063 "/Users/chet/src/bash/src/parse.y"
3035 { (yyval
.pattern
) = make_pattern_list ((yyvsp
[-2].word_list
), (yyvsp
[0].command
)); }
3036 #line 3037 "y.tab.c"
3040 #line 1065 "/Users/chet/src/bash/src/parse.y"
3041 { (yyval
.pattern
) = make_pattern_list ((yyvsp
[-2].word_list
), (COMMAND
*)NULL
); }
3042 #line 3043 "y.tab.c"
3046 #line 1067 "/Users/chet/src/bash/src/parse.y"
3047 { (yyval
.pattern
) = make_pattern_list ((yyvsp
[-2].word_list
), (yyvsp
[0].command
)); }
3048 #line 3049 "y.tab.c"
3052 #line 1069 "/Users/chet/src/bash/src/parse.y"
3053 { (yyval
.pattern
) = make_pattern_list ((yyvsp
[-2].word_list
), (COMMAND
*)NULL
); }
3054 #line 3055 "y.tab.c"
3058 #line 1073 "/Users/chet/src/bash/src/parse.y"
3059 { (yyval
.pattern
) = (yyvsp
[-1].pattern
); }
3060 #line 3061 "y.tab.c"
3064 #line 1075 "/Users/chet/src/bash/src/parse.y"
3065 { (yyvsp
[-1].pattern
)->next
= (yyvsp
[-2].pattern
); (yyval
.pattern
) = (yyvsp
[-1].pattern
); }
3066 #line 3067 "y.tab.c"
3070 #line 1077 "/Users/chet/src/bash/src/parse.y"
3071 { (yyvsp
[-1].pattern
)->flags
|= CASEPAT_FALLTHROUGH
; (yyval
.pattern
) = (yyvsp
[-1].pattern
); }
3072 #line 3073 "y.tab.c"
3076 #line 1079 "/Users/chet/src/bash/src/parse.y"
3077 { (yyvsp
[-1].pattern
)->flags
|= CASEPAT_FALLTHROUGH
; (yyvsp
[-1].pattern
)->next
= (yyvsp
[-2].pattern
); (yyval
.pattern
) = (yyvsp
[-1].pattern
); }
3078 #line 3079 "y.tab.c"
3082 #line 1081 "/Users/chet/src/bash/src/parse.y"
3083 { (yyvsp
[-1].pattern
)->flags
|= CASEPAT_TESTNEXT
; (yyval
.pattern
) = (yyvsp
[-1].pattern
); }
3084 #line 3085 "y.tab.c"
3088 #line 1083 "/Users/chet/src/bash/src/parse.y"
3089 { (yyvsp
[-1].pattern
)->flags
|= CASEPAT_TESTNEXT
; (yyvsp
[-1].pattern
)->next
= (yyvsp
[-2].pattern
); (yyval
.pattern
) = (yyvsp
[-1].pattern
); }
3090 #line 3091 "y.tab.c"
3094 #line 1087 "/Users/chet/src/bash/src/parse.y"
3095 { (yyval
.word_list
) = make_word_list ((yyvsp
[0].word
), (WORD_LIST
*)NULL
); }
3096 #line 3097 "y.tab.c"
3100 #line 1089 "/Users/chet/src/bash/src/parse.y"
3101 { (yyval
.word_list
) = make_word_list ((yyvsp
[0].word
), (yyvsp
[-2].word_list
)); }
3102 #line 3103 "y.tab.c"
3106 #line 1098 "/Users/chet/src/bash/src/parse.y"
3108 (yyval
.command
) = (yyvsp
[0].command
);
3110 gather_here_documents ();
3112 #line 3113 "y.tab.c"
3116 #line 1107 "/Users/chet/src/bash/src/parse.y"
3118 (yyval
.command
) = (yyvsp
[0].command
);
3120 #line 3121 "y.tab.c"
3124 #line 1114 "/Users/chet/src/bash/src/parse.y"
3126 if ((yyvsp
[-2].command
)->type
== cm_connection
)
3127 (yyval
.command
) = connect_async_list ((yyvsp
[-2].command
), (COMMAND
*)NULL
, '&');
3129 (yyval
.command
) = command_connect ((yyvsp
[-2].command
), (COMMAND
*)NULL
, '&');
3131 #line 3132 "y.tab.c"
3135 #line 1125 "/Users/chet/src/bash/src/parse.y"
3136 { (yyval
.command
) = command_connect ((yyvsp
[-3].command
), (yyvsp
[0].command
), AND_AND
); }
3137 #line 3138 "y.tab.c"
3141 #line 1127 "/Users/chet/src/bash/src/parse.y"
3142 { (yyval
.command
) = command_connect ((yyvsp
[-3].command
), (yyvsp
[0].command
), OR_OR
); }
3143 #line 3144 "y.tab.c"
3147 #line 1129 "/Users/chet/src/bash/src/parse.y"
3149 if ((yyvsp
[-3].command
)->type
== cm_connection
)
3150 (yyval
.command
) = connect_async_list ((yyvsp
[-3].command
), (yyvsp
[0].command
), '&');
3152 (yyval
.command
) = command_connect ((yyvsp
[-3].command
), (yyvsp
[0].command
), '&');
3154 #line 3155 "y.tab.c"
3158 #line 1136 "/Users/chet/src/bash/src/parse.y"
3159 { (yyval
.command
) = command_connect ((yyvsp
[-3].command
), (yyvsp
[0].command
), ';'); }
3160 #line 3161 "y.tab.c"
3164 #line 1138 "/Users/chet/src/bash/src/parse.y"
3165 { (yyval
.command
) = command_connect ((yyvsp
[-3].command
), (yyvsp
[0].command
), ';'); }
3166 #line 3167 "y.tab.c"
3170 #line 1140 "/Users/chet/src/bash/src/parse.y"
3171 { (yyval
.command
) = (yyvsp
[0].command
); }
3172 #line 3173 "y.tab.c"
3176 #line 1148 "/Users/chet/src/bash/src/parse.y"
3177 { (yyval
.number
) = '\n'; }
3178 #line 3179 "y.tab.c"
3182 #line 1150 "/Users/chet/src/bash/src/parse.y"
3183 { (yyval
.number
) = ';'; }
3184 #line 3185 "y.tab.c"
3188 #line 1152 "/Users/chet/src/bash/src/parse.y"
3189 { (yyval
.number
) = yacc_EOF
; }
3190 #line 3191 "y.tab.c"
3194 #line 1166 "/Users/chet/src/bash/src/parse.y"
3196 (yyval
.command
) = (yyvsp
[0].command
);
3198 gather_here_documents ();
3199 if ((parser_state
& PST_CMDSUBST
) && current_token
== shell_eof_token
)
3201 global_command
= (yyvsp
[0].command
);
3202 eof_encountered
= 0;
3203 rewind_input_string ();
3207 #line 3208 "y.tab.c"
3211 #line 1179 "/Users/chet/src/bash/src/parse.y"
3213 if ((yyvsp
[-1].command
)->type
== cm_connection
)
3214 (yyval
.command
) = connect_async_list ((yyvsp
[-1].command
), (COMMAND
*)NULL
, '&');
3216 (yyval
.command
) = command_connect ((yyvsp
[-1].command
), (COMMAND
*)NULL
, '&');
3218 gather_here_documents ();
3219 if ((parser_state
& PST_CMDSUBST
) && current_token
== shell_eof_token
)
3221 global_command
= (yyvsp
[-1].command
);
3222 eof_encountered
= 0;
3223 rewind_input_string ();
3227 #line 3228 "y.tab.c"
3231 #line 1195 "/Users/chet/src/bash/src/parse.y"
3233 (yyval
.command
) = (yyvsp
[-1].command
);
3235 gather_here_documents ();
3236 if ((parser_state
& PST_CMDSUBST
) && current_token
== shell_eof_token
)
3238 global_command
= (yyvsp
[-1].command
);
3239 eof_encountered
= 0;
3240 rewind_input_string ();
3244 #line 3245 "y.tab.c"
3248 #line 1210 "/Users/chet/src/bash/src/parse.y"
3249 { (yyval
.command
) = command_connect ((yyvsp
[-3].command
), (yyvsp
[0].command
), AND_AND
); }
3250 #line 3251 "y.tab.c"
3254 #line 1212 "/Users/chet/src/bash/src/parse.y"
3255 { (yyval
.command
) = command_connect ((yyvsp
[-3].command
), (yyvsp
[0].command
), OR_OR
); }
3256 #line 3257 "y.tab.c"
3260 #line 1214 "/Users/chet/src/bash/src/parse.y"
3262 if ((yyvsp
[-2].command
)->type
== cm_connection
)
3263 (yyval
.command
) = connect_async_list ((yyvsp
[-2].command
), (yyvsp
[0].command
), '&');
3265 (yyval
.command
) = command_connect ((yyvsp
[-2].command
), (yyvsp
[0].command
), '&');
3267 #line 3268 "y.tab.c"
3271 #line 1221 "/Users/chet/src/bash/src/parse.y"
3272 { (yyval
.command
) = command_connect ((yyvsp
[-2].command
), (yyvsp
[0].command
), ';'); }
3273 #line 3274 "y.tab.c"
3277 #line 1224 "/Users/chet/src/bash/src/parse.y"
3278 { (yyval
.command
) = (yyvsp
[0].command
); }
3279 #line 3280 "y.tab.c"
3283 #line 1228 "/Users/chet/src/bash/src/parse.y"
3284 { (yyval
.command
) = (yyvsp
[0].command
); }
3285 #line 3286 "y.tab.c"
3289 #line 1230 "/Users/chet/src/bash/src/parse.y"
3291 if ((yyvsp
[0].command
))
3292 (yyvsp
[0].command
)->flags
^= CMD_INVERT_RETURN
; /* toggle */
3293 (yyval
.command
) = (yyvsp
[0].command
);
3295 #line 3296 "y.tab.c"
3299 #line 1236 "/Users/chet/src/bash/src/parse.y"
3301 if ((yyvsp
[0].command
))
3302 (yyvsp
[0].command
)->flags
|= (yyvsp
[-1].number
);
3303 (yyval
.command
) = (yyvsp
[0].command
);
3305 #line 3306 "y.tab.c"
3309 #line 1242 "/Users/chet/src/bash/src/parse.y"
3313 /* Boy, this is unclean. `time' by itself can
3314 time a null command. We cheat and push a
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
|= (yyvsp
[-1].number
);
3322 /* XXX - let's cheat and push a newline back */
3323 if ((yyvsp
[0].number
) == '\n')
3324 token_to_read
= '\n';
3325 else if ((yyvsp
[0].number
) == ';')
3326 token_to_read
= ';';
3327 parser_state
&= ~PST_REDIRLIST
; /* make_simple_command sets this */
3329 #line 3330 "y.tab.c"
3333 #line 1262 "/Users/chet/src/bash/src/parse.y"
3337 /* This is just as unclean. Posix says that `!'
3338 by itself should be equivalent to `false'.
3340 newline back if the list_terminator was a newline
3341 to avoid the double-newline problem (one to
3342 terminate this, one to terminate the command) */
3345 (yyval
.command
) = make_simple_command (x
, (COMMAND
*)NULL
);
3346 (yyval
.command
)->flags
|= CMD_INVERT_RETURN
;
3347 /* XXX - let's cheat and push a newline back */
3348 if ((yyvsp
[0].number
) == '\n')
3349 token_to_read
= '\n';
3350 if ((yyvsp
[0].number
) == ';')
3351 token_to_read
= ';';
3352 parser_state
&= ~PST_REDIRLIST
; /* make_simple_command sets this */
3354 #line 3355 "y.tab.c"
3358 #line 1285 "/Users/chet/src/bash/src/parse.y"
3359 { (yyval
.command
) = command_connect ((yyvsp
[-3].command
), (yyvsp
[0].command
), '|'); }
3360 #line 3361 "y.tab.c"
3364 #line 1287 "/Users/chet/src/bash/src/parse.y"
3366 /* Make cmd1 |& cmd2 equivalent to cmd1 2>&1 | cmd2 */
3371 tc
= (yyvsp
[-3].command
)->type
== cm_simple
? (COMMAND
*)(yyvsp
[-3].command
)->value
.Simple
: (yyvsp
[-3].command
);
3374 r
= make_redirection (sd
, r_duplicating_output
, rd
, 0);
3377 register REDIRECT
*t
;
3378 for (t
= tc
->redirects
; t
->next
; t
= t
->next
)
3385 (yyval
.command
) = command_connect ((yyvsp
[-3].command
), (yyvsp
[0].command
), '|');
3387 #line 3388 "y.tab.c"
3391 #line 1310 "/Users/chet/src/bash/src/parse.y"
3392 { (yyval
.command
) = (yyvsp
[0].command
); }
3393 #line 3394 "y.tab.c"
3397 #line 1314 "/Users/chet/src/bash/src/parse.y"
3398 { (yyval
.number
) = CMD_TIME_PIPELINE
; }
3399 #line 3400 "y.tab.c"
3403 #line 1316 "/Users/chet/src/bash/src/parse.y"
3404 { (yyval
.number
) = CMD_TIME_PIPELINE
|CMD_TIME_POSIX
; }
3405 #line 3406 "y.tab.c"
3409 #line 1318 "/Users/chet/src/bash/src/parse.y"
3410 { (yyval
.number
) = CMD_TIME_PIPELINE
|CMD_TIME_POSIX
; }
3411 #line 3412 "y.tab.c"
3415 #line 1320 "/Users/chet/src/bash/src/parse.y"
3416 { (yyval
.number
) = CMD_TIME_PIPELINE
|CMD_TIME_POSIX
; }
3417 #line 3418 "y.tab.c"
3421 #line 3422 "y.tab.c"
3425 /* User semantic actions sometimes alter yychar, and that requires
3426 that yytoken be updated with the new translation. We take the
3427 approach of translating immediately before every use of yytoken.
3428 One alternative is translating here after every semantic action,
3429 but that translation would be missed if the semantic action invokes
3430 YYABORT, YYACCEPT, or YYERROR immediately after altering yychar or
3431 if it invokes YYBACKUP. In the case of YYABORT or YYACCEPT, an
3432 incorrect destructor might then be invoked immediately. In the
3433 case of YYERROR or YYBACKUP, subsequent parser actions might lead
3434 to an incorrect destructor call or verbose syntax error message
3435 before the lookahead is translated. */
3436 YY_SYMBOL_PRINT ("-> $$ =", YY_CAST (yysymbol_kind_t
, yyr1
[yyn
]), &yyval
, &yyloc
);
3443 /* Now 'shift' the result of the reduction. Determine what state
3444 that goes to, based on the state we popped back to and the rule
3445 number reduced by. */
3447 const int yylhs
= yyr1
[yyn
] - YYNTOKENS
;
3448 const int yyi
= yypgoto
[yylhs
] + *yyssp
;
3449 yystate
= (0 <= yyi
&& yyi
<= YYLAST
&& yycheck
[yyi
] == *yyssp
3451 : yydefgoto
[yylhs
]);
3457 /*--------------------------------------.
3458 | yyerrlab -- here on detecting error. |
3459 `--------------------------------------*/
3461 /* Make sure we have latest lookahead translation. See comments at
3462 user semantic actions for why this is necessary. */
3463 yytoken
= yychar
== YYEMPTY
? YYSYMBOL_YYEMPTY
: YYTRANSLATE (yychar
);
3464 /* If not already recovering from an error, report this error. */
3468 yyerror (YY_("syntax error"));
3471 if (yyerrstatus
== 3)
3473 /* If just tried and failed to reuse lookahead token after an
3474 error, discard it. */
3476 if (yychar
<= YYEOF
)
3478 /* Return failure if at end of input. */
3479 if (yychar
== YYEOF
)
3484 yydestruct ("Error: discarding",
3490 /* Else will try to reuse lookahead token after shifting the error
3495 /*---------------------------------------------------.
3496 | yyerrorlab -- error raised explicitly by YYERROR. |
3497 `---------------------------------------------------*/
3499 /* Pacify compilers when the user code never invokes YYERROR and the
3500 label yyerrorlab therefore never appears in user code. */
3504 /* Do not reclaim the symbols of the rule whose action triggered
3508 YY_STACK_PRINT (yyss
, yyssp
);
3513 /*-------------------------------------------------------------.
3514 | yyerrlab1 -- common code for both syntax error and YYERROR. |
3515 `-------------------------------------------------------------*/
3517 yyerrstatus
= 3; /* Each real token shifted decrements this. */
3519 /* Pop stack until we find a state that shifts the error token. */
3522 yyn
= yypact
[yystate
];
3523 if (!yypact_value_is_default (yyn
))
3525 yyn
+= YYSYMBOL_YYerror
;
3526 if (0 <= yyn
&& yyn
<= YYLAST
&& yycheck
[yyn
] == YYSYMBOL_YYerror
)
3534 /* Pop the current state because it cannot handle the error token. */
3539 yydestruct ("Error: popping",
3540 YY_ACCESSING_SYMBOL (yystate
), yyvsp
);
3543 YY_STACK_PRINT (yyss
, yyssp
);
3546 YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
3548 YY_IGNORE_MAYBE_UNINITIALIZED_END
3551 /* Shift the error token. */
3552 YY_SYMBOL_PRINT ("Shifting", YY_ACCESSING_SYMBOL (yyn
), yyvsp
, yylsp
);
3558 /*-------------------------------------.
3559 | yyacceptlab -- YYACCEPT comes here. |
3560 `-------------------------------------*/
3566 /*-----------------------------------.
3567 | yyabortlab -- YYABORT comes here. |
3568 `-----------------------------------*/
3574 #if !defined yyoverflow
3575 /*-------------------------------------------------.
3576 | yyexhaustedlab -- memory exhaustion comes here. |
3577 `-------------------------------------------------*/
3579 yyerror (YY_("memory exhausted"));
3585 /*-----------------------------------------------------.
3586 | yyreturn -- parsing is finished, return the result. |
3587 `-----------------------------------------------------*/
3589 if (yychar
!= YYEMPTY
)
3591 /* Make sure we have latest lookahead translation. See comments at
3592 user semantic actions for why this is necessary. */
3593 yytoken
= YYTRANSLATE (yychar
);
3594 yydestruct ("Cleanup: discarding lookahead",
3597 /* Do not reclaim the symbols of the rule whose action triggered
3598 this YYABORT or YYACCEPT. */
3600 YY_STACK_PRINT (yyss
, yyssp
);
3601 while (yyssp
!= yyss
)
3603 yydestruct ("Cleanup: popping",
3604 YY_ACCESSING_SYMBOL (+*yyssp
), yyvsp
);
3609 YYSTACK_FREE (yyss
);
3615 #line 1322 "/Users/chet/src/bash/src/parse.y"
3618 /* Initial size to allocate for tokens, and the
3619 amount to grow them by. */
3620 #define TOKEN_DEFAULT_INITIAL_SIZE 496
3621 #define TOKEN_DEFAULT_GROW_SIZE 512
3623 /* Should we call prompt_again? */
3624 #define SHOULD_PROMPT() \
3625 (interactive && (bash_input.type == st_stdin || bash_input.type == st_stream))
3628 # define expanding_alias() (pushed_string_list && pushed_string_list->expander)
3630 # define expanding_alias() 0
3633 /* Global var is non-zero when end of file has been reached. */
3634 int EOF_Reached
= 0;
3643 yyoutstream
= stdout
;
3644 yyerrstream
= stderr
;
3649 /* yy_getc () returns the next available character from input or EOF.
3650 yy_ungetc (c) makes `c' the next character to read.
3651 init_yy_io (get, unget, type, location) makes the function GET the
3652 installed function for getting the next character, makes UNGET the
3653 installed function for un-getting a character, sets the type of stream
3654 (either string or file) from TYPE, and makes LOCATION point to where
3655 the input is coming from. */
3657 /* Unconditionally returns end-of-file. */
3664 /* Variable containing the current get and unget functions.
3665 See ./input.h for a clearer description. */
3666 BASH_INPUT bash_input
;
3668 /* Set all of the fields in BASH_INPUT to NULL. Free bash_input.name if it
3669 is non-null, avoiding a memory leak. */
3671 initialize_bash_input ()
3673 bash_input
.type
= st_none
;
3674 FREE (bash_input
.name
);
3675 bash_input
.name
= (char *)NULL
;
3676 bash_input
.location
.file
= (FILE *)NULL
;
3677 bash_input
.location
.string
= (char *)NULL
;
3678 bash_input
.getter
= (sh_cget_func_t
*)NULL
;
3679 bash_input
.ungetter
= (sh_cunget_func_t
*)NULL
;
3682 /* Set the contents of the current bash input stream from
3683 GET, UNGET, TYPE, NAME, and LOCATION. */
3685 init_yy_io (get
, unget
, type
, name
, location
)
3686 sh_cget_func_t
*get
;
3687 sh_cunget_func_t
*unget
;
3688 enum stream_type type
;
3690 INPUT_STREAM location
;
3692 bash_input
.type
= type
;
3693 FREE (bash_input
.name
);
3694 bash_input
.name
= name
? savestring (name
) : (char *)NULL
;
3698 memcpy((char *)&bash_input
.location
.string
, (char *)&location
.string
, sizeof(location
));
3700 bash_input
.location
= location
;
3702 bash_input
.getter
= get
;
3703 bash_input
.ungetter
= unget
;
3709 return (bash_input
.name
? bash_input
.name
: "stdin");
3712 /* Call this to get the next character of input. */
3716 return (*(bash_input
.getter
)) ();
3719 /* Call this to unget C. That is, to make C the next character
3725 return (*(bash_input
.ungetter
)) (c
);
3728 #if defined (BUFFERED_INPUT)
3729 #ifdef INCLUDE_UNUSED
3731 input_file_descriptor ()
3733 switch (bash_input
.type
)
3736 return (fileno (bash_input
.location
.file
));
3738 return (bash_input
.location
.buffered_fd
);
3741 return (fileno (stdin
));
3745 #endif /* BUFFERED_INPUT */
3747 /* **************************************************************** */
3749 /* Let input be read from readline (). */
3751 /* **************************************************************** */
3753 #if defined (READLINE)
3754 char *current_readline_prompt
= (char *)NULL
;
3755 char *current_readline_line
= (char *)NULL
;
3756 int current_readline_line_index
= 0;
3761 SigHandler
*old_sigint
;
3765 if (current_readline_line
== 0)
3767 if (bash_readline_initialized
== 0)
3768 initialize_readline ();
3770 #if defined (JOB_CONTROL)
3772 give_terminal_to (shell_pgrp
, 0);
3773 #endif /* JOB_CONTROL */
3775 old_sigint
= IMPOSSIBLE_TRAP_HANDLER
;
3776 if (signal_is_ignored (SIGINT
) == 0)
3778 old_sigint
= (SigHandler
*)set_signal_handler (SIGINT
, sigint_sighandler
);
3781 sh_unset_nodelay_mode (fileno (rl_instream
)); /* just in case */
3782 current_readline_line
= readline (current_readline_prompt
?
3783 current_readline_prompt
: "");
3786 if (signal_is_ignored (SIGINT
) == 0)
3788 if (old_sigint
!= IMPOSSIBLE_TRAP_HANDLER
)
3789 set_signal_handler (SIGINT
, old_sigint
);
3793 /* Reset the prompt to the decoded value of prompt_string_pointer. */
3794 reset_readline_prompt ();
3797 if (current_readline_line
== 0)
3800 current_readline_line_index
= 0;
3801 line_len
= strlen (current_readline_line
);
3803 current_readline_line
= (char *)xrealloc (current_readline_line
, 2 + line_len
);
3804 current_readline_line
[line_len
++] = '\n';
3805 current_readline_line
[line_len
] = '\0';
3808 if (current_readline_line
[current_readline_line_index
] == 0)
3810 free (current_readline_line
);
3811 current_readline_line
= (char *)NULL
;
3812 return (yy_readline_get ());
3816 c
= current_readline_line
[current_readline_line_index
++];
3822 yy_readline_unget (c
)
3825 if (current_readline_line_index
&& current_readline_line
)
3826 current_readline_line
[--current_readline_line_index
] = c
;
3831 with_input_from_stdin ()
3833 INPUT_STREAM location
;
3835 if (bash_input
.type
!= st_stdin
&& stream_on_stack (st_stdin
) == 0)
3837 location
.string
= current_readline_line
;
3838 init_yy_io (yy_readline_get
, yy_readline_unget
,
3839 st_stdin
, "readline stdin", location
);
3843 /* Will we be collecting another input line and printing a prompt? This uses
3844 different conditions than SHOULD_PROMPT(), since readline allows a user to
3845 embed a newline in the middle of the line it collects, which the parser
3846 will interpret as a line break and command delimiter. */
3848 parser_will_prompt ()
3850 return (current_readline_line
== 0 || current_readline_line
[current_readline_line_index
] == 0);
3853 #else /* !READLINE */
3856 with_input_from_stdin ()
3858 with_input_from_stream (stdin
, "stdin");
3860 #endif /* !READLINE */
3862 /* **************************************************************** */
3864 /* Let input come from STRING. STRING is zero terminated. */
3866 /* **************************************************************** */
3871 register char *string
;
3872 register unsigned char c
;
3874 string
= bash_input
.location
.string
;
3876 /* If the string doesn't exist, or is empty, EOF found. */
3877 if (string
&& *string
)
3880 bash_input
.location
.string
= string
;
3891 *(--bash_input
.location
.string
) = c
;
3896 with_input_from_string (string
, name
)
3900 INPUT_STREAM location
;
3902 location
.string
= string
;
3903 init_yy_io (yy_string_get
, yy_string_unget
, st_string
, name
, location
);
3906 /* Count the number of characters we've consumed from bash_input.location.string
3907 and read into shell_input_line, but have not returned from shell_getc.
3908 That is the true input location. Rewind bash_input.location.string by
3909 that number of characters, so it points to the last character actually
3910 consumed by the parser. */
3912 rewind_input_string ()
3916 /* number of unconsumed characters in the input -- XXX need to take newlines
3917 into account, e.g., $(...\n) */
3918 xchars
= shell_input_line_len
- shell_input_line_index
;
3919 if (bash_input
.location
.string
[-1] == '\n')
3922 /* XXX - how to reflect bash_input.location.string back to string passed to
3923 parse_and_execute or xparse_dolparen? xparse_dolparen needs to know how
3924 far into the string we parsed. parse_and_execute knows where bash_input.
3925 location.string is, and how far from orig_string that is -- that's the
3926 number of characters the command consumed. */
3928 /* bash_input.location.string - xchars should be where we parsed to */
3929 /* need to do more validation on xchars value for sanity -- test cases. */
3930 bash_input
.location
.string
-= xchars
;
3933 /* **************************************************************** */
3935 /* Let input come from STREAM. */
3937 /* **************************************************************** */
3939 /* These two functions used to test the value of the HAVE_RESTARTABLE_SYSCALLS
3940 define, and just use getc/ungetc if it was defined, but since bash
3941 installs most of its signal handlers without the SA_RESTART flag, some
3942 signals received during a read(2) will not cause the read to be restarted.
3943 We will need to restart it ourselves. */
3951 if (bash_input
.location
.file
)
3953 /* XXX - don't need terminate_immediately; getc_with_restart checks
3954 for terminating signals itself if read returns < 0 */
3955 result
= getc_with_restart (bash_input
.location
.file
);
3964 return (ungetc_with_restart (c
, bash_input
.location
.file
));
3968 with_input_from_stream (stream
, name
)
3972 INPUT_STREAM location
;
3974 location
.file
= stream
;
3975 init_yy_io (yy_stream_get
, yy_stream_unget
, st_stream
, name
, location
);
3978 typedef struct stream_saver
{
3979 struct stream_saver
*next
;
3980 BASH_INPUT bash_input
;
3982 #if defined (BUFFERED_INPUT)
3983 BUFFERED_STREAM
*bstream
;
3984 #endif /* BUFFERED_INPUT */
3987 /* The globally known line number. */
3988 int line_number
= 0;
3990 /* The line number offset set by assigning to LINENO. Not currently used. */
3991 int line_number_base
= 0;
3993 #if defined (COND_COMMAND)
3994 static int cond_lineno
;
3995 static int cond_token
;
3998 STREAM_SAVER
*stream_list
= (STREAM_SAVER
*)NULL
;
4001 push_stream (reset_lineno
)
4004 STREAM_SAVER
*saver
= (STREAM_SAVER
*)xmalloc (sizeof (STREAM_SAVER
));
4006 xbcopy ((char *)&bash_input
, (char *)&(saver
->bash_input
), sizeof (BASH_INPUT
));
4008 #if defined (BUFFERED_INPUT)
4009 saver
->bstream
= (BUFFERED_STREAM
*)NULL
;
4010 /* If we have a buffered stream, clear out buffers[fd]. */
4011 if (bash_input
.type
== st_bstream
&& bash_input
.location
.buffered_fd
>= 0)
4012 saver
->bstream
= set_buffered_stream (bash_input
.location
.buffered_fd
,
4013 (BUFFERED_STREAM
*)NULL
);
4014 #endif /* BUFFERED_INPUT */
4016 saver
->line
= line_number
;
4017 bash_input
.name
= (char *)NULL
;
4018 saver
->next
= stream_list
;
4019 stream_list
= saver
;
4032 STREAM_SAVER
*saver
= stream_list
;
4035 stream_list
= stream_list
->next
;
4037 init_yy_io (saver
->bash_input
.getter
,
4038 saver
->bash_input
.ungetter
,
4039 saver
->bash_input
.type
,
4040 saver
->bash_input
.name
,
4041 saver
->bash_input
.location
);
4043 #if defined (BUFFERED_INPUT)
4044 /* If we have a buffered stream, restore buffers[fd]. */
4045 /* If the input file descriptor was changed while this was on the
4046 save stack, update the buffered fd to the new file descriptor and
4047 re-establish the buffer <-> bash_input fd correspondence. */
4048 if (bash_input
.type
== st_bstream
&& bash_input
.location
.buffered_fd
>= 0)
4050 if (bash_input_fd_changed
)
4052 bash_input_fd_changed
= 0;
4053 if (default_buffered_input
>= 0)
4055 bash_input
.location
.buffered_fd
= default_buffered_input
;
4056 saver
->bstream
->b_fd
= default_buffered_input
;
4057 SET_CLOSE_ON_EXEC (default_buffered_input
);
4060 /* XXX could free buffered stream returned as result here. */
4061 set_buffered_stream (bash_input
.location
.buffered_fd
, saver
->bstream
);
4063 #endif /* BUFFERED_INPUT */
4065 line_number
= saver
->line
;
4067 FREE (saver
->bash_input
.name
);
4072 /* Return 1 if a stream of type TYPE is saved on the stack. */
4074 stream_on_stack (type
)
4075 enum stream_type type
;
4077 register STREAM_SAVER
*s
;
4079 for (s
= stream_list
; s
; s
= s
->next
)
4080 if (s
->bash_input
.type
== type
)
4085 /* Save the current token state and return it in a malloced array. */
4091 ret
= (int *)xmalloc (4 * sizeof (int));
4092 ret
[0] = last_read_token
;
4093 ret
[1] = token_before_that
;
4094 ret
[2] = two_tokens_ago
;
4095 ret
[3] = current_token
;
4100 restore_token_state (ts
)
4105 last_read_token
= ts
[0];
4106 token_before_that
= ts
[1];
4107 two_tokens_ago
= ts
[2];
4108 current_token
= ts
[3];
4112 * This is used to inhibit alias expansion and reserved word recognition
4113 * inside case statement pattern lists. A `case statement pattern list' is:
4115 * everything between the `in' in a `case word in' and the next ')'
4117 * everything between a `;;' and the next `)' or `esac'
4120 #if defined (ALIAS) || defined (DPAREN_ARITHMETIC)
4122 #define END_OF_ALIAS 0
4125 * Pseudo-global variables used in implementing token-wise alias expansion.
4129 * Pushing and popping strings. This works together with shell_getc to
4130 * implement alias expansion on a per-token basis.
4133 #define PSH_ALIAS 0x01
4134 #define PSH_DPAREN 0x02
4135 #define PSH_SOURCE 0x04
4136 #define PSH_ARRAY 0x08
4138 typedef struct string_saver
{
4139 struct string_saver
*next
;
4140 int expand_alias
; /* Value to set expand_alias to when string is popped. */
4143 alias_t
*expander
; /* alias that caused this line to be pushed. */
4145 size_t saved_line_size
, saved_line_index
;
4146 int saved_line_terminator
;
4150 STRING_SAVER
*pushed_string_list
= (STRING_SAVER
*)NULL
;
4153 * Push the current shell_input_line onto a stack of such lines and make S
4154 * the current input. Used when expanding aliases. EXPAND is used to set
4155 * the value of expand_next_token when the string is popped, so that the
4156 * word after the alias in the original line is handled correctly when the
4157 * alias expands to multiple words. TOKEN is the token that was expanded
4158 * into S; it is saved and used to prevent infinite recursive expansion.
4161 push_string (s
, expand
, ap
)
4166 STRING_SAVER
*temp
= (STRING_SAVER
*)xmalloc (sizeof (STRING_SAVER
));
4168 temp
->expand_alias
= expand
;
4169 temp
->saved_line
= shell_input_line
;
4170 temp
->saved_line_size
= shell_input_line_size
;
4171 temp
->saved_line_index
= shell_input_line_index
;
4172 temp
->saved_line_terminator
= shell_input_line_terminator
;
4175 temp
->expander
= ap
;
4177 temp
->flags
= PSH_ALIAS
;
4179 temp
->next
= pushed_string_list
;
4180 pushed_string_list
= temp
;
4184 ap
->flags
|= AL_BEINGEXPANDED
;
4187 shell_input_line
= s
;
4188 shell_input_line_size
= STRLEN (s
);
4189 shell_input_line_index
= 0;
4190 shell_input_line_terminator
= '\0';
4192 parser_state
&= ~PST_ALEXPNEXT
; /* XXX */
4195 set_line_mbstate ();
4199 * Make the top of the pushed_string stack be the current shell input.
4200 * Only called when there is something on the stack. Called from shell_getc
4201 * when it thinks it has consumed the string generated by an alias expansion
4202 * and needs to return to the original input line.
4209 FREE (shell_input_line
);
4210 shell_input_line
= pushed_string_list
->saved_line
;
4211 shell_input_line_index
= pushed_string_list
->saved_line_index
;
4212 shell_input_line_size
= pushed_string_list
->saved_line_size
;
4213 shell_input_line_terminator
= pushed_string_list
->saved_line_terminator
;
4215 if (pushed_string_list
->expand_alias
)
4216 parser_state
|= PST_ALEXPNEXT
;
4218 parser_state
&= ~PST_ALEXPNEXT
;
4220 t
= pushed_string_list
;
4221 pushed_string_list
= pushed_string_list
->next
;
4225 t
->expander
->flags
&= ~AL_BEINGEXPANDED
;
4230 set_line_mbstate ();
4236 register STRING_SAVER
*t
, *t1
;
4238 for (t
= pushed_string_list
; t
; )
4241 FREE (t
->saved_line
);
4244 t
->expander
->flags
&= ~AL_BEINGEXPANDED
;
4249 pushed_string_list
= (STRING_SAVER
*)NULL
;
4252 #endif /* ALIAS || DPAREN_ARITHMETIC */
4255 free_pushed_string_input ()
4257 #if defined (ALIAS) || defined (DPAREN_ARITHMETIC)
4258 free_string_list ();
4263 parser_expanding_alias ()
4265 return (expanding_alias ());
4269 parser_save_alias ()
4271 #if defined (ALIAS) || defined (DPAREN_ARITHMETIC)
4272 push_string ((char *)NULL
, 0, (alias_t
*)NULL
);
4273 pushed_string_list
->flags
= PSH_SOURCE
; /* XXX - for now */
4280 parser_restore_alias ()
4282 #if defined (ALIAS) || defined (DPAREN_ARITHMETIC)
4283 if (pushed_string_list
)
4291 /* Before freeing AP, make sure that there aren't any cases of pointer
4292 aliasing that could cause us to reference freed memory later on. */
4294 clear_string_list_expander (ap
)
4297 register STRING_SAVER
*t
;
4299 for (t
= pushed_string_list
; t
; t
= t
->next
)
4301 if (t
->expander
&& t
->expander
== ap
)
4308 clear_shell_input_line ()
4310 if (shell_input_line
)
4311 shell_input_line
[shell_input_line_index
= 0] = '\0';
4314 /* Return a line of text, taken from wherever yylex () reads input.
4315 If there is no more input, then we return NULL. If REMOVE_QUOTED_NEWLINE
4316 is non-zero, we remove unquoted \<newline> pairs. This is used by
4317 read_secondary_line to read here documents. */
4319 read_a_line (remove_quoted_newline
)
4320 int remove_quoted_newline
;
4322 static char *line_buffer
= (char *)NULL
;
4323 static int buffer_size
= 0;
4324 int indx
, c
, peekc
, pass_next
;
4326 #if defined (READLINE)
4327 if (no_line_editing
&& SHOULD_PROMPT ())
4329 if (SHOULD_PROMPT ())
4333 pass_next
= indx
= 0;
4336 /* Allow immediate exit if interrupted during input. */
4341 /* Ignore null bytes in input. */
4345 internal_warning ("read_a_line: ignored null byte in input");
4350 /* If there is no more input, then we return NULL. */
4353 if (interactive
&& bash_input
.type
== st_stream
)
4356 return ((char *)NULL
);
4360 /* `+2' in case the final character in the buffer is a newline or we
4361 have to handle CTLESC or CTLNUL. */
4362 RESIZE_MALLOCED_BUFFER (line_buffer
, indx
, 2, buffer_size
, 128);
4364 /* IF REMOVE_QUOTED_NEWLINES is non-zero, we are reading a
4365 here document with an unquoted delimiter. In this case,
4366 the line will be expanded as if it were in double quotes.
4367 We allow a backslash to escape the next character, but we
4368 need to treat the backslash specially only if a backslash
4369 quoting a backslash-newline pair appears in the line. */
4372 line_buffer
[indx
++] = c
;
4375 else if (c
== '\\' && remove_quoted_newline
)
4382 continue; /* Make the unquoted \<newline> pair disappear. */
4388 line_buffer
[indx
++] = c
; /* Preserve the backslash. */
4393 /* remove_quoted_newline is non-zero if the here-document delimiter
4394 is unquoted. In this case, we will be expanding the lines and
4395 need to make sure CTLESC and CTLNUL in the input are quoted. */
4396 if (remove_quoted_newline
&& (c
== CTLESC
|| c
== CTLNUL
))
4397 line_buffer
[indx
++] = CTLESC
;
4398 line_buffer
[indx
++] = c
;
4403 line_buffer
[indx
] = '\0';
4404 return (line_buffer
);
4409 /* Return a line as in read_a_line (), but insure that the prompt is
4410 the secondary prompt. This is used to read the lines of a here
4411 document. REMOVE_QUOTED_NEWLINE is non-zero if we should remove
4412 newlines quoted with backslashes while reading the line. It is
4413 non-zero unless the delimiter of the here document was quoted. */
4415 read_secondary_line (remove_quoted_newline
)
4416 int remove_quoted_newline
;
4421 prompt_string_pointer
= &ps2_prompt
;
4422 if (SHOULD_PROMPT())
4424 ret
= read_a_line (remove_quoted_newline
);
4425 #if defined (HISTORY)
4426 if (ret
&& remember_on_history
&& (parser_state
& PST_HEREDOC
))
4428 /* To make adding the here-document body right, we need to rely on
4429 history_delimiting_chars() returning \n for the first line of the
4430 here-document body and the null string for the second and subsequent
4431 lines, so we avoid double newlines.
4432 current_command_line_count == 2 for the first line of the body. */
4434 current_command_line_count
++;
4435 maybe_add_history (ret
);
4437 #endif /* HISTORY */
4441 /* **************************************************************** */
4445 /* **************************************************************** */
4447 /* Reserved words. These are only recognized as the first word of a
4449 STRING_INT_ALIST word_token_alist
[] = {
4458 #if defined (SELECT_COMMAND)
4459 { "select", SELECT
},
4466 { "function", FUNCTION
},
4467 #if defined (COMMAND_TIMING)
4473 #if defined (COND_COMMAND)
4474 { "[[", COND_START
},
4477 #if defined (COPROCESS_SUPPORT)
4478 { "coproc", COPROC
},
4483 /* other tokens that can be returned by read_token() */
4484 STRING_INT_ALIST other_token_alist
[] = {
4485 /* Multiple-character tokens with special values */
4490 { ">>", GREATER_GREATER
},
4491 { "<<", LESS_LESS
},
4493 { ">&", GREATER_AND
},
4494 { ";;", SEMI_SEMI
},
4496 { ";;&", SEMI_SEMI_AND
},
4497 { "<<-", LESS_LESS_MINUS
},
4498 { "<<<", LESS_LESS_LESS
},
4499 { "&>", AND_GREATER
},
4500 { "&>>", AND_GREATER_GREATER
},
4501 { "<>", LESS_GREATER
},
4502 { ">|", GREATER_BAR
},
4504 { "EOF", yacc_EOF
},
4505 /* Tokens whose value is the character itself */
4516 { "newline", '\n' },
4520 /* others not listed here:
4521 WORD look at yylval.word
4522 ASSIGNMENT_WORD look at yylval.word
4523 NUMBER look at yylval.number
4524 ARITH_CMD look at yylval.word_list
4525 ARITH_FOR_EXPRS look at yylval.word_list
4526 COND_CMD look at yylval.command
4529 /* These are used by read_token_word, but appear up here so that shell_getc
4530 can use them to decide when to add otherwise blank lines to the history. */
4532 /* The primary delimiter stack. */
4533 struct dstack dstack
= { (char *)NULL
, 0, 0 };
4535 /* A temporary delimiter stack to be used when decoding prompt strings.
4536 This is needed because command substitutions in prompt strings (e.g., PS2)
4537 can screw up the parser's quoting state. */
4538 static struct dstack temp_dstack
= { (char *)NULL
, 0, 0 };
4540 /* Macro for accessing the top delimiter on the stack. Returns the
4541 delimiter or zero if none. */
4542 #define current_delimiter(ds) \
4543 (ds.delimiter_depth ? ds.delimiters[ds.delimiter_depth - 1] : 0)
4545 #define push_delimiter(ds, character) \
4548 if (ds.delimiter_depth + 2 > ds.delimiter_space) \
4549 ds.delimiters = (char *)xrealloc \
4550 (ds.delimiters, (ds.delimiter_space += 10) * sizeof (char)); \
4551 ds.delimiters[ds.delimiter_depth] = character; \
4552 ds.delimiter_depth++; \
4556 #define pop_delimiter(ds) ds.delimiter_depth--
4558 /* Return the next shell input character. This always reads characters
4559 from shell_input_line; when that line is exhausted, it is time to
4560 read the next line. This is called by read_token when the shell is
4561 processing normal command input. */
4563 /* This implements one-character lookahead/lookbehind across physical input
4564 lines, to avoid something being lost because it's pushed back with
4565 shell_ungetc when we're at the start of a line. */
4566 static int eol_ungetc_lookahead
= 0;
4568 static int unquoted_backslash
= 0;
4571 shell_getc (remove_quoted_newline
)
4572 int remove_quoted_newline
;
4575 int c
, truncating
, last_was_backslash
;
4580 last_was_backslash
= 0;
4581 if (sigwinch_received
)
4583 sigwinch_received
= 0;
4584 get_new_window_size (0, (int *)0, (int *)0);
4587 if (eol_ungetc_lookahead
)
4589 c
= eol_ungetc_lookahead
;
4590 eol_ungetc_lookahead
= 0;
4594 #if defined (ALIAS) || defined (DPAREN_ARITHMETIC)
4595 /* If shell_input_line[shell_input_line_index] == 0, but there is
4596 something on the pushed list of strings, then we don't want to go
4597 off and get another line. We let the code down below handle it. */
4599 if (!shell_input_line
|| ((!shell_input_line
[shell_input_line_index
]) &&
4600 (pushed_string_list
== (STRING_SAVER
*)NULL
)))
4601 #else /* !ALIAS && !DPAREN_ARITHMETIC */
4602 if (!shell_input_line
|| !shell_input_line
[shell_input_line_index
])
4603 #endif /* !ALIAS && !DPAREN_ARITHMETIC */
4607 /* Let's not let one really really long line blow up memory allocation */
4608 if (shell_input_line
&& shell_input_line_size
>= 32768)
4610 free (shell_input_line
);
4611 shell_input_line
= 0;
4612 shell_input_line_size
= 0;
4617 /* Allow immediate exit if interrupted during input. */
4621 shell_input_line_terminator
= 0;
4623 /* If the shell is interactive, but not currently printing a prompt
4624 (interactive_shell && interactive == 0), we don't want to print
4625 notifies or cleanup the jobs -- we want to defer it until we do
4626 print the next prompt. */
4627 if (interactive_shell
== 0 || SHOULD_PROMPT())
4629 #if defined (JOB_CONTROL)
4630 /* This can cause a problem when reading a command as the result
4631 of a trap, when the trap is called from flush_child. This call
4632 had better not cause jobs to disappear from the job table in
4633 that case, or we will have big trouble. */
4634 notify_and_cleanup ();
4635 #else /* !JOB_CONTROL */
4636 cleanup_dead_jobs ();
4637 #endif /* !JOB_CONTROL */
4640 #if defined (READLINE)
4641 if (no_line_editing
&& SHOULD_PROMPT())
4643 if (SHOULD_PROMPT())
4647 if (bash_input
.type
== st_stream
)
4654 /* Allow immediate exit if interrupted during input. */
4660 internal_warning ("shell_getc: ignored null byte in input");
4662 /* If we get EOS while parsing a string, treat it as EOF so we
4663 don't just keep looping. Happens very rarely */
4664 if (bash_input
.type
== st_string
)
4667 shell_input_line_terminator
= EOF
;
4668 shell_input_line
[i
] = '\0';
4675 /* Theoretical overflow */
4676 /* If we can't put 256 bytes more into the buffer, allocate
4677 everything we can and fill it as full as we can. */
4678 /* XXX - we ignore rest of line using `truncating' flag */
4679 if (shell_input_line_size
> (SIZE_MAX
- 256))
4683 n
= SIZE_MAX
- i
; /* how much more can we put into the buffer? */
4684 if (n
<= 2) /* we have to save 1 for the newline added below */
4686 if (truncating
== 0)
4687 internal_warning(_("shell_getc: shell_input_line_size (%zu) exceeds SIZE_MAX (%lu): line truncated"), shell_input_line_size
, (unsigned long)SIZE_MAX
);
4688 shell_input_line
[i
] = '\0';
4691 if (shell_input_line_size
< SIZE_MAX
)
4693 shell_input_line_size
= SIZE_MAX
;
4694 shell_input_line
= xrealloc (shell_input_line
, shell_input_line_size
);
4698 RESIZE_MALLOCED_BUFFER (shell_input_line
, i
, 2, shell_input_line_size
, 256);
4702 if (bash_input
.type
== st_stream
)
4706 shell_input_line_terminator
= EOF
;
4708 shell_input_line
[i
] = '\0';
4712 if (truncating
== 0 || c
== '\n')
4713 shell_input_line
[i
++] = c
;
4717 shell_input_line
[--i
] = '\0';
4718 current_command_line_count
++;
4722 last_was_backslash
= last_was_backslash
== 0 && c
== '\\';
4725 shell_input_line_index
= 0;
4726 shell_input_line_len
= i
; /* == strlen (shell_input_line) */
4728 set_line_mbstate ();
4730 #if defined (HISTORY)
4731 if (remember_on_history
&& shell_input_line
&& shell_input_line
[0])
4734 # if defined (BANG_HISTORY)
4735 /* If the current delimiter is a single quote, we should not be
4736 performing history expansion, even if we're on a different
4737 line from the original single quote. */
4738 if (current_delimiter (dstack
) == '\'')
4739 history_quoting_state
= '\'';
4740 else if (current_delimiter (dstack
) == '"')
4741 history_quoting_state
= '"';
4743 history_quoting_state
= 0;
4745 /* Calling with a third argument of 1 allows remember_on_history to
4746 determine whether or not the line is saved to the history list */
4747 expansions
= pre_process_line (shell_input_line
, 1, 1);
4748 # if defined (BANG_HISTORY)
4749 history_quoting_state
= 0;
4751 if (expansions
!= shell_input_line
)
4753 free (shell_input_line
);
4754 shell_input_line
= expansions
;
4755 shell_input_line_len
= shell_input_line
?
4756 strlen (shell_input_line
) : 0;
4757 if (shell_input_line_len
== 0)
4758 current_command_line_count
--;
4760 /* We have to force the xrealloc below because we don't know
4761 the true allocated size of shell_input_line anymore. */
4762 shell_input_line_size
= shell_input_line_len
;
4764 set_line_mbstate ();
4767 /* Try to do something intelligent with blank lines encountered while
4768 entering multi-line commands. XXX - this is grotesque */
4769 else if (remember_on_history
&& shell_input_line
&&
4770 shell_input_line
[0] == '\0' &&
4771 current_command_line_count
> 1)
4773 if (current_delimiter (dstack
))
4774 /* We know shell_input_line[0] == 0 and we're reading some sort of
4775 quoted string. This means we've got a line consisting of only
4776 a newline in a quoted string. We want to make sure this line
4777 gets added to the history. */
4778 maybe_add_history (shell_input_line
);
4782 hdcs
= history_delimiting_chars (shell_input_line
);
4783 if (hdcs
&& hdcs
[0] == ';')
4784 maybe_add_history (shell_input_line
);
4788 #endif /* HISTORY */
4790 if (shell_input_line
)
4792 /* Lines that signify the end of the shell's input should not be
4793 echoed. We should not echo lines while parsing command
4794 substitutions with recursive calls into the parsing engine; those
4795 should only be echoed once when we read the word. That is the
4796 reason for the test against shell_eof_token, which is set to a
4797 right paren when parsing the contents of command substitutions. */
4798 if (echo_input_at_read
&& (shell_input_line
[0] ||
4799 shell_input_line_terminator
!= EOF
) &&
4800 shell_eof_token
== 0)
4801 fprintf (stderr
, "%s\n", shell_input_line
);
4805 shell_input_line_size
= 0;
4806 prompt_string_pointer
= ¤t_prompt_string
;
4807 if (SHOULD_PROMPT ())
4812 /* Add the newline to the end of this string, iff the string does
4813 not already end in an EOF character. */
4814 if (shell_input_line_terminator
!= EOF
)
4816 if (shell_input_line_size
< SIZE_MAX
-3 && (shell_input_line_len
+3 > shell_input_line_size
))
4817 shell_input_line
= (char *)xrealloc (shell_input_line
,
4818 1 + (shell_input_line_size
+= 2));
4820 /* Don't add a newline to a string that ends with a backslash if we're
4821 going to be removing quoted newlines, since that will eat the
4822 backslash. Add another backslash instead (will be removed by
4824 if (bash_input
.type
== st_string
&& expanding_alias() == 0 && last_was_backslash
&& c
== EOF
&& remove_quoted_newline
)
4825 shell_input_line
[shell_input_line_len
] = '\\';
4827 shell_input_line
[shell_input_line_len
] = '\n';
4828 shell_input_line
[shell_input_line_len
+ 1] = '\0';
4831 set_line_mbstate (); /* XXX - this is wasteful */
4833 # if defined (HANDLE_MULTIBYTE)
4834 /* This is kind of an abstraction violation, but there's no need to
4835 go through the entire shell_input_line again with a call to
4836 set_line_mbstate(). */
4837 if (shell_input_line_len
+ 2 > shell_input_line_propsize
)
4839 shell_input_line_propsize
= shell_input_line_len
+ 2;
4840 shell_input_line_property
= (char *)xrealloc (shell_input_line_property
,
4841 shell_input_line_propsize
);
4843 shell_input_line_property
[shell_input_line_len
] = 1;
4850 if (shell_input_line_index
== 0)
4851 unquoted_backslash
= 0;
4853 uc
= shell_input_line
[shell_input_line_index
];
4857 unquoted_backslash
= unquoted_backslash
== 0 && uc
== '\\';
4858 shell_input_line_index
++;
4861 #if defined (ALIAS) || defined (DPAREN_ARITHMETIC)
4862 /* If UC is NULL, we have reached the end of the current input string. If
4863 pushed_string_list is non-empty, it's time to pop to the previous string
4864 because we have fully consumed the result of the last alias expansion.
4865 Do it transparently; just return the next character of the string popped
4867 /* If pushed_string_list != 0 but pushed_string_list->expander == 0 (not
4868 currently tested) and the flags value is not PSH_SOURCE, we are not
4869 parsing an alias, we have just saved one (push_string, when called by
4870 the parse_dparen code) In this case, just go on as well. The PSH_SOURCE
4871 case is handled below. */
4873 /* If we're at the end of an alias expansion add a space to make sure that
4874 the alias remains marked as being in use while we expand its last word.
4875 This makes sure that pop_string doesn't mark the alias as not in use
4876 before the string resulting from the alias expansion is tokenized and
4877 checked for alias expansion, preventing recursion. At this point, the
4878 last character in shell_input_line is the last character of the alias
4879 expansion. We test that last character to determine whether or not to
4880 return the space that will delimit the token and postpone the pop_string.
4881 This set of conditions duplicates what used to be in mk_alexpansion ()
4882 below, with the addition that we don't add a space if we're currently
4883 reading a quoted string or in a shell comment. */
4884 #ifndef OLD_ALIAS_HACK
4885 if (uc
== 0 && pushed_string_list
&& pushed_string_list
->flags
!= PSH_SOURCE
&&
4886 pushed_string_list
->flags
!= PSH_DPAREN
&&
4887 (parser_state
& PST_COMMENT
) == 0 &&
4888 (parser_state
& PST_ENDALIAS
) == 0 && /* only once */
4889 shell_input_line_index
> 0 &&
4890 shellblank (shell_input_line
[shell_input_line_index
-1]) == 0 &&
4891 shell_input_line
[shell_input_line_index
-1] != '\n' &&
4892 unquoted_backslash
== 0 &&
4893 shellmeta (shell_input_line
[shell_input_line_index
-1]) == 0 &&
4894 (current_delimiter (dstack
) != '\'' && current_delimiter (dstack
) != '"'))
4896 parser_state
|= PST_ENDALIAS
;
4897 return ' '; /* END_ALIAS */
4902 /* This case works for PSH_DPAREN as well */
4903 if (uc
== 0 && pushed_string_list
&& pushed_string_list
->flags
!= PSH_SOURCE
)
4905 parser_state
&= ~PST_ENDALIAS
;
4907 uc
= shell_input_line
[shell_input_line_index
];
4909 shell_input_line_index
++;
4911 #endif /* ALIAS || DPAREN_ARITHMETIC */
4913 if MBTEST(uc
== '\\' && remove_quoted_newline
&& shell_input_line
[shell_input_line_index
] == '\n')
4915 if (SHOULD_PROMPT ())
4919 /* What do we do here if we're expanding an alias whose definition
4920 includes an escaped newline? If that's the last character in the
4921 alias expansion, we just pop the pushed string list (recall that
4922 we inhibit the appending of a space if newline is the last
4923 character). If it's not the last character, we need to consume the
4924 quoted newline and move to the next character in the expansion. */
4926 if (expanding_alias () && shell_input_line
[shell_input_line_index
+1] == '\0')
4931 else if (expanding_alias () && shell_input_line
[shell_input_line_index
+1] != '\0')
4933 shell_input_line_index
++; /* skip newline */
4934 goto next_alias_char
; /* and get next character */
4941 if (uc
== 0 && shell_input_line_terminator
== EOF
)
4942 return ((shell_input_line_index
!= 0) ? '\n' : EOF
);
4944 #if defined (ALIAS) || defined (DPAREN_ARITHMETIC)
4945 /* We already know that we are not parsing an alias expansion because of the
4946 check for expanding_alias() above. This knows how parse_and_execute
4947 handles switching to st_string input while an alias is being expanded,
4948 hence the check for pushed_string_list without pushed_string_list->expander
4949 and the check for PSH_SOURCE as pushed_string_list->flags.
4950 parse_and_execute and parse_string both change the input type to st_string
4951 and place the string to be parsed and executed into location.string, so
4952 we should not stop reading that until the pointer is '\0'.
4953 The check for shell_input_line_terminator may be superfluous.
4955 This solves the problem of `.' inside a multi-line alias with embedded
4956 newlines executing things out of order. */
4957 if (uc
== 0 && bash_input
.type
== st_string
&& *bash_input
.location
.string
&&
4958 pushed_string_list
&& pushed_string_list
->flags
== PSH_SOURCE
&&
4959 shell_input_line_terminator
== 0)
4961 shell_input_line_index
= 0;
4969 /* Put C back into the input for the shell. This might need changes for
4970 HANDLE_MULTIBYTE around EOLs. Since we (currently) never push back a
4971 character different than we read, shell_input_line_property doesn't need
4972 to change when manipulating shell_input_line. The define for
4973 last_shell_getc_is_singlebyte should take care of it, though. */
4978 if (shell_input_line
&& shell_input_line_index
)
4979 shell_input_line
[--shell_input_line_index
] = c
;
4981 eol_ungetc_lookahead
= c
;
4985 parser_remaining_input ()
4987 if (shell_input_line
== 0)
4989 if ((int)shell_input_line_index
< 0 || shell_input_line_index
>= shell_input_line_len
)
4990 return ""; /* XXX */
4991 return (shell_input_line
+ shell_input_line_index
);
4994 #ifdef INCLUDE_UNUSED
4995 /* Back the input pointer up by one, effectively `ungetting' a character. */
4999 if (shell_input_line
&& shell_input_line_index
)
5000 shell_input_line_index
--;
5004 /* Discard input until CHARACTER is seen, then push that character back
5005 onto the input stream. */
5007 discard_until (character
)
5012 while ((c
= shell_getc (0)) != EOF
&& c
!= character
)
5020 execute_variable_command (command
, vname
)
5021 char *command
, *vname
;
5024 sh_parser_state_t ps
;
5026 save_parser_state (&ps
);
5027 last_lastarg
= get_string_value ("_");
5029 last_lastarg
= savestring (last_lastarg
);
5031 parse_and_execute (savestring (command
), vname
, SEVAL_NONINT
|SEVAL_NOHIST
);
5033 restore_parser_state (&ps
);
5034 bind_variable ("_", last_lastarg
, 0);
5035 FREE (last_lastarg
);
5037 if (token_to_read
== '\n') /* reset_parser was called */
5045 two_tokens_ago
= token_before_that
;
5046 token_before_that
= last_read_token
;
5047 last_read_token
= current_token
;
5052 /* Place to remember the token. We try to keep the buffer
5053 at a reasonable size, but it can grow. */
5054 static char *token
= (char *)NULL
;
5056 /* Current size of the token buffer. */
5057 static int token_buffer_size
;
5059 /* Command to read_token () explaining what we want it to do. */
5062 #define prompt_is_ps1 \
5063 (!prompt_string_pointer || prompt_string_pointer == &ps1_prompt)
5065 /* Function for yyparse to call. yylex keeps track of
5066 the last two tokens read, and calls read_token. */
5070 if (interactive
&& (current_token
== 0 || current_token
== '\n'))
5072 /* Before we print a prompt, we might have to check mailboxes.
5073 We do this only if it is time to do so. Notice that only here
5074 is the mail alarm reset; nothing takes place in check_mail ()
5075 except the checking of mail. Please don't change this. */
5076 if (prompt_is_ps1
&& parse_and_execute_level
== 0 && time_to_check_mail ())
5079 reset_mail_timer ();
5082 /* Avoid printing a prompt if we're not going to read anything, e.g.
5083 after resetting the parser with read_token (RESET). */
5084 if (token_to_read
== 0 && SHOULD_PROMPT ())
5088 two_tokens_ago
= token_before_that
;
5089 token_before_that
= last_read_token
;
5090 last_read_token
= current_token
;
5091 current_token
= read_token (READ
);
5093 if ((parser_state
& PST_EOFTOKEN
) && current_token
== shell_eof_token
)
5095 current_token
= yacc_EOF
;
5096 if (bash_input
.type
== st_string
)
5097 rewind_input_string ();
5099 parser_state
&= ~PST_EOFTOKEN
; /* ??? */
5101 return (current_token
);
5104 /* When non-zero, we have read the required tokens
5105 which allow ESAC to be the next one read. */
5106 static int esacs_needed_count
;
5108 /* When non-zero, we can read IN as an acceptable token, regardless of how
5109 many newlines we read. */
5110 static int expecting_in_token
;
5116 if (need_here_doc
>= HEREDOC_MAX
)
5118 last_command_exit_value
= EX_BADUSAGE
;
5120 report_syntax_error (_("maximum here-document count exceeded"));
5122 exit_shell (last_command_exit_value
);
5124 redir_stack
[need_here_doc
++] = r
;
5128 gather_here_documents ()
5133 here_doc_first_line
= 1;
5134 while (need_here_doc
> 0)
5136 parser_state
|= PST_HEREDOC
;
5137 make_here_document (redir_stack
[r
++], line_number
);
5138 parser_state
&= ~PST_HEREDOC
;
5140 redir_stack
[r
- 1] = 0; /* XXX */
5142 here_doc_first_line
= 0; /* just in case */
5145 /* When non-zero, an open-brace used to create a group is awaiting a close
5147 static int open_brace_count
;
5149 /* In the following three macros, `token' is always last_read_token */
5151 /* Are we in the middle of parsing a redirection where we are about to read
5152 a word? This is used to make sure alias expansion doesn't happen in the
5153 middle of a redirection, even though we're parsing a simple command. */
5154 #define parsing_redirection(token) \
5155 (token == '<' || token == '>' || \
5156 token == GREATER_GREATER || token == GREATER_BAR || \
5157 token == LESS_GREATER || token == LESS_LESS_MINUS || \
5158 token == LESS_LESS || token == LESS_LESS_LESS || \
5159 token == LESS_AND || token == GREATER_AND || token == AND_GREATER)
5161 /* Is `token' one that will allow a WORD to be read in a command position?
5162 We can read a simple command name on which we should attempt alias expansion
5163 or we can read an assignment statement. */
5164 #define command_token_position(token) \
5165 (((token) == ASSIGNMENT_WORD) || \
5166 ((parser_state&PST_REDIRLIST) && parsing_redirection(token) == 0) || \
5167 ((token) != SEMI_SEMI && (token) != SEMI_AND && (token) != SEMI_SEMI_AND && reserved_word_acceptable(token)))
5169 /* Are we in a position where we can read an assignment statement? */
5170 #define assignment_acceptable(token) \
5171 (command_token_position(token) && ((parser_state & PST_CASEPAT) == 0))
5173 /* Check to see if TOKEN is a reserved word and return the token
5175 #define CHECK_FOR_RESERVED_WORD(tok) \
5177 if (!dollar_present && !quoted && \
5178 reserved_word_acceptable (last_read_token)) \
5181 for (i = 0; word_token_alist[i].word != (char *)NULL; i++) \
5182 if (STREQ (tok, word_token_alist[i].word)) \
5184 if ((parser_state & PST_CASEPAT) && (word_token_alist[i].token != ESAC)) \
5186 if (word_token_alist[i].token == TIME && time_command_acceptable () == 0) \
5188 if ((parser_state & PST_CASEPAT) && last_read_token == '|' && word_token_alist[i].token == ESAC) \
5189 break; /* Posix grammar rule 4 */ \
5190 if (word_token_alist[i].token == ESAC) \
5191 parser_state &= ~(PST_CASEPAT|PST_CASESTMT); \
5192 else if (word_token_alist[i].token == CASE) \
5193 parser_state |= PST_CASESTMT; \
5194 else if (word_token_alist[i].token == COND_END) \
5195 parser_state &= ~(PST_CONDCMD|PST_CONDEXPR); \
5196 else if (word_token_alist[i].token == COND_START) \
5197 parser_state |= PST_CONDCMD; \
5198 else if (word_token_alist[i].token == '{') \
5199 open_brace_count++; \
5200 else if (word_token_alist[i].token == '}' && open_brace_count) \
5201 open_brace_count--; \
5202 return (word_token_alist[i].token); \
5209 /* OK, we have a token. Let's try to alias expand it, if (and only if)
5212 It is eligible for expansion if EXPAND_ALIASES is set, and
5213 the token is unquoted and the last token read was a command
5214 separator (or expand_next_token is set), and we are currently
5215 processing an alias (pushed_string_list is non-empty) and this
5216 token is not the same as the current or any previously
5219 Special cases that disqualify:
5220 In a pattern list in a case statement (parser_state & PST_CASEPAT). */
5230 r
= xmalloc (l
+ 2);
5232 #ifdef OLD_ALIAS_HACK
5233 /* If the last character in the alias is a newline, don't add a trailing
5234 space to the expansion. Works with shell_getc above. */
5235 /* Need to do something about the case where the alias expansion contains
5236 an unmatched quoted string, since appending this space affects the
5237 subsequent output. */
5238 if (l
> 0 && r
[l
- 1] != ' ' && r
[l
- 1] != '\n' && shellmeta(r
[l
- 1]) == 0)
5246 alias_expand_token (tokstr
)
5252 if (((parser_state
& PST_ALEXPNEXT
) || command_token_position (last_read_token
)) &&
5253 (parser_state
& PST_CASEPAT
) == 0)
5255 ap
= find_alias (tokstr
);
5257 /* Currently expanding this token. */
5258 if (ap
&& (ap
->flags
& AL_BEINGEXPANDED
))
5259 return (NO_EXPANSION
);
5261 #ifdef OLD_ALIAS_HACK
5262 /* mk_alexpansion puts an extra space on the end of the alias expansion,
5263 so the lookahead by the parser works right (the alias needs to remain
5264 `in use' while parsing its last word to avoid alias recursion for
5265 something like "alias echo=echo"). If this gets changed, make sure
5266 the code in shell_getc that deals with reaching the end of an
5267 expanded alias is changed with it. */
5269 expanded
= ap
? mk_alexpansion (ap
->value
) : (char *)NULL
;
5273 push_string (expanded
, ap
->flags
& AL_EXPANDNEXT
, ap
);
5274 return (RE_READ_TOKEN
);
5277 /* This is an eligible token that does not have an expansion. */
5278 return (NO_EXPANSION
);
5280 return (NO_EXPANSION
);
5285 time_command_acceptable ()
5287 #if defined (COMMAND_TIMING)
5290 if (posixly_correct
&& shell_compatibility_level
> 41)
5292 /* Quick check of the rest of the line to find the next token. If it
5293 begins with a `-', Posix says to not return `time' as the token.
5294 This was interp 267. */
5295 i
= shell_input_line_index
;
5296 while (i
< shell_input_line_len
&& (shell_input_line
[i
] == ' ' || shell_input_line
[i
] == '\t'))
5298 if (shell_input_line
[i
] == '-')
5302 switch (last_read_token
)
5307 if (token_before_that
== '|')
5322 case ')': /* only valid in case statement */
5323 case BANG
: /* ! time pipeline */
5324 case TIME
: /* time time pipeline */
5325 case TIMEOPT
: /* time -p time pipeline */
5326 case TIMEIGN
: /* time -p -- ... */
5333 #endif /* COMMAND_TIMING */
5336 /* Handle special cases of token recognition:
5337 IN is recognized if the last token was WORD and the token
5338 before that was FOR or CASE or SELECT.
5340 DO is recognized if the last token was WORD and the token
5341 before that was FOR or SELECT.
5343 ESAC is recognized if the last token caused `esacs_needed_count'
5346 `{' is recognized if the last token as WORD and the token
5347 before that was FUNCTION, or if we just parsed an arithmetic
5350 `}' is recognized if there is an unclosed `{' present.
5352 `-p' is returned as TIMEOPT if the last read token was TIME.
5353 `--' is returned as TIMEIGN if the last read token was TIME or TIMEOPT.
5355 ']]' is returned as COND_END if the parser is currently parsing
5356 a conditional expression ((parser_state & PST_CONDEXPR) != 0)
5358 `time' is returned as TIME if and only if it is immediately
5359 preceded by one of `;', `\n', `||', `&&', or `&'.
5363 special_case_tokens (tokstr
)
5366 /* Posix grammar rule 6 */
5367 if ((last_read_token
== WORD
) &&
5368 #if defined (SELECT_COMMAND)
5369 ((token_before_that
== FOR
) || (token_before_that
== CASE
) || (token_before_that
== SELECT
)) &&
5371 ((token_before_that
== FOR
) || (token_before_that
== CASE
)) &&
5373 (tokstr
[0] == 'i' && tokstr
[1] == 'n' && tokstr
[2] == 0))
5375 if (token_before_that
== CASE
)
5377 parser_state
|= PST_CASEPAT
;
5378 esacs_needed_count
++;
5380 if (expecting_in_token
)
5381 expecting_in_token
--;
5385 /* XXX - leaving above code intact for now, but it should eventually be
5386 removed in favor of this clause. */
5387 /* Posix grammar rule 6 */
5388 if (expecting_in_token
&& (last_read_token
== WORD
|| last_read_token
== '\n') &&
5389 (tokstr
[0] == 'i' && tokstr
[1] == 'n' && tokstr
[2] == 0))
5391 if (parser_state
& PST_CASESTMT
)
5393 parser_state
|= PST_CASEPAT
;
5394 esacs_needed_count
++;
5396 expecting_in_token
--;
5399 /* Posix grammar rule 6, third word in FOR: for i; do command-list; done */
5400 else if (expecting_in_token
&& (last_read_token
== '\n' || last_read_token
== ';') &&
5401 (tokstr
[0] == 'd' && tokstr
[1] == 'o' && tokstr
[2] == '\0'))
5403 expecting_in_token
--;
5407 /* for i do; command-list; done */
5408 if (last_read_token
== WORD
&&
5409 #if defined (SELECT_COMMAND)
5410 (token_before_that
== FOR
|| token_before_that
== SELECT
) &&
5412 (token_before_that
== FOR
) &&
5414 (tokstr
[0] == 'd' && tokstr
[1] == 'o' && tokstr
[2] == '\0'))
5416 if (expecting_in_token
)
5417 expecting_in_token
--;
5421 /* Ditto for ESAC in the CASE case.
5422 Specifically, this handles "case word in esac", which is a legal
5423 construct, certainly because someone will pass an empty arg to the
5424 case construct, and we don't want it to barf. Of course, we should
5425 insist that the case construct has at least one pattern in it, but
5426 the designers disagree. */
5427 if (esacs_needed_count
)
5429 if (last_read_token
== IN
&& STREQ (tokstr
, "esac"))
5431 esacs_needed_count
--;
5432 parser_state
&= ~PST_CASEPAT
;
5437 /* The start of a shell function definition. */
5438 if (parser_state
& PST_ALLOWOPNBRC
)
5440 parser_state
&= ~PST_ALLOWOPNBRC
;
5441 if (tokstr
[0] == '{' && tokstr
[1] == '\0') /* } */
5444 function_bstart
= line_number
;
5445 return ('{'); /* } */
5449 /* We allow a `do' after a for ((...)) without an intervening
5451 if (last_read_token
== ARITH_FOR_EXPRS
&& tokstr
[0] == 'd' && tokstr
[1] == 'o' && !tokstr
[2])
5453 if (last_read_token
== ARITH_FOR_EXPRS
&& tokstr
[0] == '{' && tokstr
[1] == '\0') /* } */
5456 return ('{'); /* } */
5459 if (open_brace_count
&& reserved_word_acceptable (last_read_token
) && tokstr
[0] == '}' && !tokstr
[1])
5461 open_brace_count
--; /* { */
5465 #if defined (COMMAND_TIMING)
5466 /* Handle -p after `time'. */
5467 if (last_read_token
== TIME
&& tokstr
[0] == '-' && tokstr
[1] == 'p' && !tokstr
[2])
5469 /* Handle -- after `time'. */
5470 if (last_read_token
== TIME
&& tokstr
[0] == '-' && tokstr
[1] == '-' && !tokstr
[2])
5472 /* Handle -- after `time -p'. */
5473 if (last_read_token
== TIMEOPT
&& tokstr
[0] == '-' && tokstr
[1] == '-' && !tokstr
[2])
5477 #if defined (COND_COMMAND) /* [[ */
5478 if ((parser_state
& PST_CONDEXPR
) && tokstr
[0] == ']' && tokstr
[1] == ']' && tokstr
[2] == '\0')
5485 /* Called from shell.c when Control-C is typed at top level. Or
5486 by the error rule at top level. */
5490 dstack
.delimiter_depth
= 0; /* No delimiters found so far. */
5491 open_brace_count
= 0;
5493 #if defined (EXTENDED_GLOB)
5494 /* Reset to global value of extended glob */
5495 if (parser_state
& PST_EXTPAT
)
5496 extended_glob
= global_extglob
;
5500 here_doc_first_line
= 0;
5502 #if defined (ALIAS) || defined (DPAREN_ARITHMETIC)
5503 if (pushed_string_list
)
5504 free_string_list ();
5505 #endif /* ALIAS || DPAREN_ARITHMETIC */
5507 /* This is where we resynchronize to the next newline on error/reset */
5508 if (shell_input_line
)
5510 free (shell_input_line
);
5511 shell_input_line
= (char *)NULL
;
5512 shell_input_line_size
= shell_input_line_index
= 0;
5515 FREE (word_desc_to_read
);
5516 word_desc_to_read
= (WORD_DESC
*)NULL
;
5518 eol_ungetc_lookahead
= 0;
5520 current_token
= '\n'; /* XXX */
5521 last_read_token
= '\n';
5522 token_to_read
= '\n';
5526 reset_readahead_token ()
5528 if (token_to_read
== '\n')
5532 /* Read the next token. Command can be READ (normal operation) or
5533 RESET (to normalize state). */
5535 read_token (command
)
5538 int character
; /* Current character. */
5539 int peek_char
; /* Temporary look-ahead character. */
5540 int result
; /* The thing to return. */
5542 if (command
== RESET
)
5550 result
= token_to_read
;
5551 if (token_to_read
== WORD
|| token_to_read
== ASSIGNMENT_WORD
)
5553 yylval
.word
= word_desc_to_read
;
5554 word_desc_to_read
= (WORD_DESC
*)NULL
;
5560 #if defined (COND_COMMAND)
5561 if ((parser_state
& (PST_CONDCMD
|PST_CONDEXPR
)) == PST_CONDCMD
)
5563 cond_lineno
= line_number
;
5564 parser_state
|= PST_CONDEXPR
;
5565 yylval
.command
= parse_cond_command ();
5566 if (cond_token
!= COND_END
)
5571 token_to_read
= COND_END
;
5572 parser_state
&= ~(PST_CONDEXPR
|PST_CONDCMD
);
5578 /* This is a place to jump back to once we have successfully expanded a
5579 token with an alias and pushed the string with push_string () */
5583 /* Read a single word from input. Start by skipping blanks. */
5584 while ((character
= shell_getc (1)) != EOF
&& shellblank (character
))
5587 if (character
== EOF
)
5593 /* If we hit the end of the string and we're not expanding an alias (e.g.,
5594 we are eval'ing a string that is an incomplete command), return EOF */
5595 if (character
== '\0' && bash_input
.type
== st_string
&& expanding_alias() == 0)
5598 itrace("shell_getc: bash_input.location.string = `%s'", bash_input
.location
.string
);
5604 if MBTEST(character
== '#' && (!interactive
|| interactive_comments
))
5606 /* A comment. Discard until EOL or EOF, and then return a newline. */
5607 parser_state
|= PST_COMMENT
;
5608 discard_until ('\n');
5610 parser_state
&= ~PST_COMMENT
;
5611 character
= '\n'; /* this will take the next if statement and return. */
5614 if (character
== '\n')
5616 /* If we're about to return an unquoted newline, we can go and collect
5617 the text of any pending here document. */
5619 gather_here_documents ();
5622 parser_state
&= ~PST_ALEXPNEXT
;
5625 parser_state
&= ~PST_ASSIGNOK
;
5630 if (parser_state
& PST_REGEXP
)
5633 /* Shell meta-characters. */
5634 if MBTEST(shellmeta (character
) && ((parser_state
& PST_DBLPAREN
) == 0))
5637 /* Turn off alias tokenization iff this character sequence would
5638 not leave us ready to read a command. */
5639 if (character
== '<' || character
== '>')
5640 parser_state
&= ~PST_ALEXPNEXT
;
5643 parser_state
&= ~PST_ASSIGNOK
;
5645 /* If we are parsing a command substitution and we have read a character
5646 that marks the end of it, don't bother to skip over quoted newlines
5647 when we read the next token. We're just interested in a character
5648 that will turn this into a two-character token, so we let the higher
5649 layers deal with quoted newlines following the command substitution. */
5650 if ((parser_state
& PST_CMDSUBST
) && character
== shell_eof_token
)
5651 peek_char
= shell_getc (0);
5653 peek_char
= shell_getc (1);
5655 if (character
== peek_char
)
5660 /* If '<' then we could be at "<<" or at "<<-". We have to
5661 look ahead one more character. */
5662 peek_char
= shell_getc (1);
5663 if MBTEST(peek_char
== '-')
5664 return (LESS_LESS_MINUS
);
5665 else if MBTEST(peek_char
== '<')
5666 return (LESS_LESS_LESS
);
5669 shell_ungetc (peek_char
);
5674 return (GREATER_GREATER
);
5677 parser_state
|= PST_CASEPAT
;
5679 parser_state
&= ~PST_ALEXPNEXT
;
5682 peek_char
= shell_getc (1);
5683 if MBTEST(peek_char
== '&')
5684 return (SEMI_SEMI_AND
);
5687 shell_ungetc (peek_char
);
5697 #if defined (DPAREN_ARITHMETIC) || defined (ARITH_FOR_COMMAND)
5699 result
= parse_dparen (character
);
5707 else if MBTEST(character
== '<' && peek_char
== '&')
5709 else if MBTEST(character
== '>' && peek_char
== '&')
5710 return (GREATER_AND
);
5711 else if MBTEST(character
== '<' && peek_char
== '>')
5712 return (LESS_GREATER
);
5713 else if MBTEST(character
== '>' && peek_char
== '|')
5714 return (GREATER_BAR
);
5715 else if MBTEST(character
== '&' && peek_char
== '>')
5717 peek_char
= shell_getc (1);
5718 if MBTEST(peek_char
== '>')
5719 return (AND_GREATER_GREATER
);
5722 shell_ungetc (peek_char
);
5723 return (AND_GREATER
);
5726 else if MBTEST(character
== '|' && peek_char
== '&')
5728 else if MBTEST(character
== ';' && peek_char
== '&')
5730 parser_state
|= PST_CASEPAT
;
5732 parser_state
&= ~PST_ALEXPNEXT
;
5737 shell_ungetc (peek_char
);
5739 /* If we look like we are reading the start of a function
5740 definition, then let the reader know about it so that
5741 we will do the right thing with `{'. */
5742 if MBTEST(character
== ')' && last_read_token
== '(' && token_before_that
== WORD
)
5744 parser_state
|= PST_ALLOWOPNBRC
;
5746 parser_state
&= ~PST_ALEXPNEXT
;
5748 function_dstart
= line_number
;
5751 /* case pattern lists may be preceded by an optional left paren. If
5752 we're not trying to parse a case pattern list, the left paren
5753 indicates a subshell. */
5754 if MBTEST(character
== '(' && (parser_state
& PST_CASEPAT
) == 0) /* ) */
5755 parser_state
|= PST_SUBSHELL
;
5757 else if MBTEST((parser_state
& PST_CASEPAT
) && character
== ')')
5758 parser_state
&= ~PST_CASEPAT
;
5760 else if MBTEST((parser_state
& PST_SUBSHELL
) && character
== ')')
5761 parser_state
&= ~PST_SUBSHELL
;
5763 #if defined (PROCESS_SUBSTITUTION)
5764 /* Check for the constructs which introduce process substitution.
5765 Shells running in `posix mode' don't do process substitution. */
5766 if MBTEST((character
!= '>' && character
!= '<') || peek_char
!= '(') /*)*/
5767 #endif /* PROCESS_SUBSTITUTION */
5771 /* Hack <&- (close stdin) case. Also <&N- (dup and close). */
5772 if MBTEST(character
== '-' && (last_read_token
== LESS_AND
|| last_read_token
== GREATER_AND
))
5776 /* Okay, if we got this far, we have to read a word. Read one,
5777 and then check it against the known ones. */
5778 result
= read_token_word (character
);
5780 if (result
== RE_READ_TOKEN
)
5787 * Match a $(...) or other grouping construct. This has to handle embedded
5788 * quoted strings ('', ``, "") and nested constructs. It also must handle
5789 * reprompting the user, if necessary, after reading a newline, and returning
5790 * correct error values if it reads EOF.
5792 #define P_FIRSTCLOSE 0x0001
5793 #define P_ALLOWESC 0x0002
5794 #define P_DQUOTE 0x0004
5795 #define P_COMMAND 0x0008 /* parsing a command, so look for comments */
5796 #define P_BACKQUOTE 0x0010 /* parsing a backquoted command substitution */
5797 #define P_ARRAYSUB 0x0020 /* parsing a [...] array subscript for assignment */
5798 #define P_DOLBRACE 0x0040 /* parsing a ${...} construct */
5800 /* Lexical state while parsing a grouping construct or $(...). */
5801 #define LEX_WASDOL 0x0001
5802 #define LEX_CKCOMMENT 0x0002
5803 #define LEX_INCOMMENT 0x0004
5804 #define LEX_PASSNEXT 0x0008
5805 #define LEX_RESWDOK 0x0010
5806 #define LEX_CKCASE 0x0020
5807 #define LEX_INCASE 0x0040
5808 #define LEX_INHEREDOC 0x0080
5809 #define LEX_HEREDELIM 0x0100 /* reading here-doc delimiter */
5810 #define LEX_STRIPDOC 0x0200 /* <<- strip tabs from here doc delim */
5811 #define LEX_QUOTEDDOC 0x0400 /* here doc with quoted delim */
5812 #define LEX_INWORD 0x0800
5813 #define LEX_GTLT 0x1000
5815 #define COMSUB_META(ch) ((ch) == ';' || (ch) == '&' || (ch) == '|')
5817 #define CHECK_NESTRET_ERROR() \
5819 if (nestret == &matched_pair_error) \
5822 return &matched_pair_error; \
5826 #define APPEND_NESTRET() \
5830 RESIZE_MALLOCED_BUFFER (ret, retind, nestlen, retsize, 64); \
5831 strcpy (ret + retind, nestret); \
5832 retind += nestlen; \
5836 static char matched_pair_error
;
5839 parse_matched_pair (qc
, open
, close
, lenp
, flags
)
5840 int qc
; /* `"' if this construct is within double quotes */
5844 int count
, ch
, prevch
, tflags
;
5845 int nestlen
, ttranslen
, start_lineno
;
5846 char *ret
, *nestret
, *ttrans
;
5847 int retind
, retsize
, rflags
;
5850 dolbrace_state
= (flags
& P_DOLBRACE
) ? DOLBRACE_PARAM
: 0;
5852 /*itrace("parse_matched_pair[%d]: open = %c close = %c flags = %d", line_number, open, close, flags);*/
5856 if ((flags
& P_COMMAND
) && qc
!= '`' && qc
!= '\'' && qc
!= '"' && (flags
& P_DQUOTE
) == 0)
5857 tflags
|= LEX_CKCOMMENT
;
5859 /* RFLAGS is the set of flags we want to pass to recursive calls. */
5860 rflags
= (qc
== '"') ? P_DQUOTE
: (flags
& P_DQUOTE
);
5862 ret
= (char *)xmalloc (retsize
= 64);
5865 start_lineno
= line_number
;
5866 ch
= EOF
; /* just in case */
5870 ch
= shell_getc (qc
!= '\'' && (tflags
& (LEX_PASSNEXT
)) == 0);
5875 parser_error (start_lineno
, _("unexpected EOF while looking for matching `%c'"), close
);
5876 EOF_Reached
= 1; /* XXX */
5877 return (&matched_pair_error
);
5880 /* Possible reprompting. */
5881 if (ch
== '\n' && SHOULD_PROMPT ())
5884 /* Don't bother counting parens or doing anything else if in a comment
5885 or part of a case statement */
5886 if (tflags
& LEX_INCOMMENT
)
5888 /* Add this character. */
5889 RESIZE_MALLOCED_BUFFER (ret
, retind
, 1, retsize
, 64);
5893 tflags
&= ~LEX_INCOMMENT
;
5898 /* Not exactly right yet, should handle shell metacharacters, too. If
5899 any changes are made to this test, make analogous changes to subst.c:
5900 extract_delimited_string(). */
5901 else if MBTEST((tflags
& LEX_CKCOMMENT
) && (tflags
& LEX_INCOMMENT
) == 0 && ch
== '#' && (retind
== 0 || ret
[retind
-1] == '\n' || shellblank (ret
[retind
- 1])))
5902 tflags
|= LEX_INCOMMENT
;
5904 if (tflags
& LEX_PASSNEXT
) /* last char was backslash */
5906 tflags
&= ~LEX_PASSNEXT
;
5907 if (qc
!= '\'' && ch
== '\n') /* double-quoted \<newline> disappears. */
5910 retind
--; /* swallow previously-added backslash */
5914 RESIZE_MALLOCED_BUFFER (ret
, retind
, 2, retsize
, 64);
5915 if MBTEST(ch
== CTLESC
)
5916 ret
[retind
++] = CTLESC
;
5920 /* If we're reparsing the input (e.g., from parse_string_to_word_list),
5921 we've already prepended CTLESC to single-quoted results of $'...'.
5922 We may want to do this for other CTLESC-quoted characters in
5924 else if MBTEST((parser_state
& PST_REPARSE
) && open
== '\'' && (ch
== CTLESC
|| ch
== CTLNUL
))
5926 RESIZE_MALLOCED_BUFFER (ret
, retind
, 1, retsize
, 64);
5930 else if MBTEST(ch
== CTLESC
|| ch
== CTLNUL
) /* special shell escapes */
5932 RESIZE_MALLOCED_BUFFER (ret
, retind
, 2, retsize
, 64);
5933 ret
[retind
++] = CTLESC
;
5937 else if MBTEST(ch
== close
) /* ending delimiter */
5939 /* handle nested ${...} specially. */
5940 else if MBTEST(open
!= close
&& (tflags
& LEX_WASDOL
) && open
== '{' && ch
== open
) /* } */
5942 else if MBTEST(((flags
& P_FIRSTCLOSE
) == 0) && ch
== open
) /* nested begin */
5945 /* Add this character. */
5946 RESIZE_MALLOCED_BUFFER (ret
, retind
, 1, retsize
, 64);
5949 /* If we just read the ending character, don't bother continuing. */
5953 if (open
== '\'') /* '' inside grouping construct */
5955 if MBTEST((flags
& P_ALLOWESC
) && ch
== '\\')
5956 tflags
|= LEX_PASSNEXT
;
5960 if MBTEST(ch
== '\\') /* backslashes */
5961 tflags
|= LEX_PASSNEXT
;
5963 /* Based on which dolstate is currently in (param, op, or word),
5964 decide what the op is. We're really only concerned if it's % or
5965 #, so we can turn on a flag that says whether or not we should
5966 treat single quotes as special when inside a double-quoted
5967 ${...}. This logic must agree with subst.c:extract_dollar_brace_string
5968 since they share the same defines. */
5969 /* FLAG POSIX INTERP 221 */
5970 if (flags
& P_DOLBRACE
)
5972 /* ${param%[%]word} */
5973 if MBTEST(dolbrace_state
== DOLBRACE_PARAM
&& ch
== '%' && retind
> 1)
5974 dolbrace_state
= DOLBRACE_QUOTE
;
5975 /* ${param#[#]word} */
5976 else if MBTEST(dolbrace_state
== DOLBRACE_PARAM
&& ch
== '#' && retind
> 1)
5977 dolbrace_state
= DOLBRACE_QUOTE
;
5978 /* ${param/[/]pat/rep} */
5979 else if MBTEST(dolbrace_state
== DOLBRACE_PARAM
&& ch
== '/' && retind
> 1)
5980 dolbrace_state
= DOLBRACE_QUOTE2
; /* XXX */
5981 /* ${param^[^]pat} */
5982 else if MBTEST(dolbrace_state
== DOLBRACE_PARAM
&& ch
== '^' && retind
> 1)
5983 dolbrace_state
= DOLBRACE_QUOTE
;
5984 /* ${param,[,]pat} */
5985 else if MBTEST(dolbrace_state
== DOLBRACE_PARAM
&& ch
== ',' && retind
> 1)
5986 dolbrace_state
= DOLBRACE_QUOTE
;
5987 else if MBTEST(dolbrace_state
== DOLBRACE_PARAM
&& strchr ("#%^,~:-=?+/", ch
) != 0)
5988 dolbrace_state
= DOLBRACE_OP
;
5989 else if MBTEST(dolbrace_state
== DOLBRACE_OP
&& strchr ("#%^,~:-=?+/", ch
) == 0)
5990 dolbrace_state
= DOLBRACE_WORD
;
5993 /* The big hammer. Single quotes aren't special in double quotes. The
5994 problem is that Posix used to say the single quotes are semi-special:
5995 within a double-quoted ${...} construct "an even number of
5996 unescaped double-quotes or single-quotes, if any, shall occur." */
5997 /* This was changed in Austin Group Interp 221 */
5998 if MBTEST(posixly_correct
&& shell_compatibility_level
> 41 && dolbrace_state
!= DOLBRACE_QUOTE
&& dolbrace_state
!= DOLBRACE_QUOTE2
&& (flags
& P_DQUOTE
) && (flags
& P_DOLBRACE
) && ch
== '\'')
6001 /* Could also check open == '`' if we want to parse grouping constructs
6002 inside old-style command substitution. */
6003 if (open
!= close
) /* a grouping construct */
6005 if MBTEST(shellquote (ch
))
6007 /* '', ``, or "" inside $(...) or other grouping construct. */
6008 push_delimiter (dstack
, ch
);
6009 if MBTEST((tflags
& LEX_WASDOL
) && ch
== '\'') /* $'...' inside group */
6010 nestret
= parse_matched_pair (ch
, ch
, ch
, &nestlen
, P_ALLOWESC
|rflags
);
6012 nestret
= parse_matched_pair (ch
, ch
, ch
, &nestlen
, rflags
);
6013 pop_delimiter (dstack
);
6014 CHECK_NESTRET_ERROR ();
6016 if MBTEST((tflags
& LEX_WASDOL
) && ch
== '\'' && (extended_quote
|| (rflags
& P_DQUOTE
) == 0))
6018 /* Translate $'...' here. */
6019 ttrans
= ansiexpand (nestret
, 0, nestlen
- 1, &ttranslen
);
6022 /* If we're parsing a double-quoted brace expansion and we are
6023 not in a place where single quotes are treated specially,
6024 make sure we single-quote the results of the ansi
6025 expansion because quote removal should remove them later */
6026 /* FLAG POSIX INTERP 221 */
6027 if ((shell_compatibility_level
> 42) && (rflags
& P_DQUOTE
) && (dolbrace_state
== DOLBRACE_QUOTE2
) && (flags
& P_DOLBRACE
))
6029 nestret
= sh_single_quote (ttrans
);
6031 nestlen
= strlen (nestret
);
6033 else if ((rflags
& P_DQUOTE
) == 0)
6035 nestret
= sh_single_quote (ttrans
);
6037 nestlen
= strlen (nestret
);
6042 nestlen
= ttranslen
;
6044 retind
-= 2; /* back up before the $' */
6046 else if MBTEST((tflags
& LEX_WASDOL
) && ch
== '"' && (extended_quote
|| (rflags
& P_DQUOTE
) == 0))
6048 /* Locale expand $"..." here. */
6049 ttrans
= localeexpand (nestret
, 0, nestlen
- 1, start_lineno
, &ttranslen
);
6052 nestret
= sh_mkdoublequoted (ttrans
, ttranslen
, 0);
6054 nestlen
= ttranslen
+ 2;
6055 retind
-= 2; /* back up before the $" */
6061 else if ((flags
& (P_ARRAYSUB
|P_DOLBRACE
)) && (tflags
& LEX_WASDOL
) && (ch
== '(' || ch
== '{' || ch
== '[')) /* ) } ] */
6062 goto parse_dollar_word
;
6063 #if defined (PROCESS_SUBSTITUTION)
6064 /* XXX - technically this should only be recognized at the start of
6066 else if ((flags
& (P_ARRAYSUB
|P_DOLBRACE
)) && (tflags
& LEX_GTLT
) && (ch
== '(')) /* ) */
6067 goto parse_dollar_word
;
6070 /* Parse an old-style command substitution within double quotes as a
6072 /* XXX - sh and ksh93 don't do this - XXX */
6073 else if MBTEST(open
== '"' && ch
== '`')
6075 nestret
= parse_matched_pair (0, '`', '`', &nestlen
, rflags
);
6077 CHECK_NESTRET_ERROR ();
6082 else if MBTEST(open
!= '`' && (tflags
& LEX_WASDOL
) && (ch
== '(' || ch
== '{' || ch
== '[')) /* ) } ] */
6083 /* check for $(), $[], or ${} inside quoted string. */
6086 if (open
== ch
) /* undo previous increment */
6088 if (ch
== '(') /* ) */
6089 nestret
= parse_comsub (0, '(', ')', &nestlen
, (rflags
|P_COMMAND
) & ~P_DQUOTE
);
6090 else if (ch
== '{') /* } */
6091 nestret
= parse_matched_pair (0, '{', '}', &nestlen
, P_FIRSTCLOSE
|P_DOLBRACE
|rflags
);
6092 else if (ch
== '[') /* ] */
6093 nestret
= parse_matched_pair (0, '[', ']', &nestlen
, rflags
);
6095 CHECK_NESTRET_ERROR ();
6100 #if defined (PROCESS_SUBSTITUTION)
6101 if MBTEST((ch
== '<' || ch
== '>') && (tflags
& LEX_GTLT
) == 0)
6104 tflags
&= ~LEX_GTLT
;
6106 if MBTEST(ch
== '$' && (tflags
& LEX_WASDOL
) == 0)
6107 tflags
|= LEX_WASDOL
;
6109 tflags
&= ~LEX_WASDOL
;
6115 /*itrace("parse_matched_pair[%d]: returning %s", line_number, ret);*/
6127 fprintf (stderr
, "%d -> ", f
);
6131 fprintf (stderr
, "LEX_WASDOL%s", f
? "|" : "");
6133 if (f
& LEX_CKCOMMENT
)
6135 f
&= ~LEX_CKCOMMENT
;
6136 fprintf (stderr
, "LEX_CKCOMMENT%s", f
? "|" : "");
6138 if (f
& LEX_INCOMMENT
)
6140 f
&= ~LEX_INCOMMENT
;
6141 fprintf (stderr
, "LEX_INCOMMENT%s", f
? "|" : "");
6143 if (f
& LEX_PASSNEXT
)
6146 fprintf (stderr
, "LEX_PASSNEXT%s", f
? "|" : "");
6148 if (f
& LEX_RESWDOK
)
6151 fprintf (stderr
, "LEX_RESWDOK%s", f
? "|" : "");
6156 fprintf (stderr
, "LEX_CKCASE%s", f
? "|" : "");
6161 fprintf (stderr
, "LEX_INCASE%s", f
? "|" : "");
6163 if (f
& LEX_INHEREDOC
)
6165 f
&= ~LEX_INHEREDOC
;
6166 fprintf (stderr
, "LEX_INHEREDOC%s", f
? "|" : "");
6168 if (f
& LEX_HEREDELIM
)
6170 f
&= ~LEX_HEREDELIM
;
6171 fprintf (stderr
, "LEX_HEREDELIM%s", f
? "|" : "");
6173 if (f
& LEX_STRIPDOC
)
6176 fprintf (stderr
, "LEX_WASDOL%s", f
? "|" : "");
6178 if (f
& LEX_QUOTEDDOC
)
6180 f
&= ~LEX_QUOTEDDOC
;
6181 fprintf (stderr
, "LEX_QUOTEDDOC%s", f
? "|" : "");
6186 fprintf (stderr
, "LEX_INWORD%s", f
? "|" : "");
6189 fprintf (stderr
, "\n");
6194 /* Parse a $(...) command substitution. This is messier than I'd like, and
6195 reproduces a lot more of the token-reading code than I'd like. */
6197 parse_comsub (qc
, open
, close
, lenp
, flags
)
6198 int qc
; /* `"' if this construct is within double quotes */
6202 int count
, ch
, peekc
, tflags
, lex_rwlen
, lex_wlen
, lex_firstind
;
6203 int nestlen
, ttranslen
, start_lineno
, orig_histexp
;
6204 char *ret
, *nestret
, *ttrans
, *heredelim
;
6205 int retind
, retsize
, rflags
, hdlen
;
6207 /* Posix interp 217 says arithmetic expressions have precedence, so
6208 assume $(( introduces arithmetic expansion and parse accordingly. */
6209 peekc
= shell_getc (0);
6210 shell_ungetc (peekc
);
6212 return (parse_matched_pair (qc
, open
, close
, lenp
, 0));
6214 /*itrace("parse_comsub: qc = `%c' open = %c close = %c", qc, open, close);*/
6216 tflags
= LEX_RESWDOK
;
6217 #if defined (BANG_HISTORY)
6218 orig_histexp
= history_expansion_inhibited
;
6221 if ((flags
& P_COMMAND
) && qc
!= '\'' && qc
!= '"' && (flags
& P_DQUOTE
) == 0)
6222 tflags
|= LEX_CKCASE
;
6223 if ((tflags
& LEX_CKCASE
) && (interactive
== 0 || interactive_comments
))
6224 tflags
|= LEX_CKCOMMENT
;
6226 /* RFLAGS is the set of flags we want to pass to recursive calls. */
6227 rflags
= (flags
& P_DQUOTE
);
6229 ret
= (char *)xmalloc (retsize
= 64);
6232 start_lineno
= line_number
;
6233 lex_rwlen
= lex_wlen
= 0;
6241 ch
= shell_getc (qc
!= '\'' && (tflags
& (LEX_INCOMMENT
|LEX_PASSNEXT
|LEX_QUOTEDDOC
)) == 0);
6246 #if defined (BANG_HISTORY)
6247 history_expansion_inhibited
= orig_histexp
;
6251 parser_error (start_lineno
, _("unexpected EOF while looking for matching `%c'"), close
);
6252 EOF_Reached
= 1; /* XXX */
6253 return (&matched_pair_error
);
6256 /* If we hit the end of a line and are reading the contents of a here
6257 document, and it's not the same line that the document starts on,
6258 check for this line being the here doc delimiter. Otherwise, if
6259 we're in a here document, mark the next character as the beginning
6263 if ((tflags
& LEX_HEREDELIM
) && heredelim
)
6265 tflags
&= ~LEX_HEREDELIM
;
6266 tflags
|= LEX_INHEREDOC
;
6267 #if defined (BANG_HISTORY)
6268 history_expansion_inhibited
= 1;
6270 lex_firstind
= retind
+ 1;
6272 else if (tflags
& LEX_INHEREDOC
)
6275 tind
= lex_firstind
;
6276 while ((tflags
& LEX_STRIPDOC
) && ret
[tind
] == '\t')
6278 if (retind
-tind
== hdlen
&& STREQN (ret
+ tind
, heredelim
, hdlen
))
6280 tflags
&= ~(LEX_STRIPDOC
|LEX_INHEREDOC
|LEX_QUOTEDDOC
);
6281 /*itrace("parse_comsub:%d: found here doc end `%s'", line_number, ret + tind);*/
6285 #if defined (BANG_HISTORY)
6286 history_expansion_inhibited
= orig_histexp
;
6290 lex_firstind
= retind
+ 1;
6294 /* Possible reprompting. */
6295 if (ch
== '\n' && SHOULD_PROMPT ())
6298 /* XXX -- we currently allow here doc to be delimited by ending right
6299 paren in default mode and posix mode. To change posix mode, change
6300 the #if 1 to #if 0 below */
6301 if ((tflags
& LEX_INHEREDOC
) && ch
== close
&& count
== 1)
6304 /*itrace("parse_comsub:%d: in here doc, ch == close, retind - firstind = %d hdlen = %d retind = %d", line_number, retind-lex_firstind, hdlen, retind);*/
6305 tind
= lex_firstind
;
6306 while ((tflags
& LEX_STRIPDOC
) && ret
[tind
] == '\t')
6309 if (retind
-tind
== hdlen
&& STREQN (ret
+ tind
, heredelim
, hdlen
))
6311 /* Posix-mode shells require the newline after the here-document
6313 if (retind
-tind
== hdlen
&& STREQN (ret
+ tind
, heredelim
, hdlen
) &&
6314 posixly_correct
== 0)
6317 tflags
&= ~(LEX_STRIPDOC
|LEX_INHEREDOC
|LEX_QUOTEDDOC
);
6318 /*itrace("parse_comsub:%d: found here doc end `%*s'", line_number, hdlen, ret + tind);*/
6322 #if defined (BANG_HISTORY)
6323 history_expansion_inhibited
= orig_histexp
;
6328 /* Don't bother counting parens or doing anything else if in a comment or
6329 here document (not exactly right for here-docs -- if we want to allow
6330 recursive calls to parse_comsub to have their own here documents,
6331 change the LEX_INHEREDOC to LEX_QUOTEDDOC here and uncomment the next
6332 clause below. Note that to make this work completely, we need to make
6333 additional changes to allow xparse_dolparen to work right when the
6334 command substitution is parsed, because read_secondary_line doesn't know
6335 to recursively parse through command substitutions embedded in here-
6337 if (tflags
& (LEX_INCOMMENT
|LEX_INHEREDOC
))
6339 /* Add this character. */
6340 RESIZE_MALLOCED_BUFFER (ret
, retind
, 1, retsize
, 64);
6343 if ((tflags
& LEX_INCOMMENT
) && ch
== '\n')
6345 /*itrace("parse_comsub:%d: lex_incomment -> 0 ch = `%c'", line_number, ch);*/
6346 tflags
&= ~LEX_INCOMMENT
;
6352 /* If we're going to recursively parse a command substitution inside a
6353 here-document, make sure we call parse_comsub recursively below. See
6354 above for additional caveats. */
6355 if ((tflags
& LEX_INHEREDOC
) && ((tflags
& LEX_WASDOL
) == 0 || ch
!= '(')) /*)*/
6357 /* Add this character. */
6358 RESIZE_MALLOCED_BUFFER (ret
, retind
, 1, retsize
, 64);
6360 if MBTEST(ch
== '$')
6361 tflags
|= LEX_WASDOL
;
6363 tflags
&= ~LEX_WASDOL
;
6367 if (tflags
& LEX_PASSNEXT
) /* last char was backslash */
6369 /*itrace("parse_comsub:%d: lex_passnext -> 0 ch = `%c' (%d)", line_number, ch, __LINE__);*/
6370 tflags
&= ~LEX_PASSNEXT
;
6371 if (qc
!= '\'' && ch
== '\n') /* double-quoted \<newline> disappears. */
6374 retind
--; /* swallow previously-added backslash */
6378 RESIZE_MALLOCED_BUFFER (ret
, retind
, 2, retsize
, 64);
6379 if MBTEST(ch
== CTLESC
)
6380 ret
[retind
++] = CTLESC
;
6385 /* If this is a shell break character, we are not in a word. If not,
6386 we either start or continue a word. */
6387 if MBTEST(shellbreak (ch
))
6389 tflags
&= ~LEX_INWORD
;
6390 /*itrace("parse_comsub:%d: lex_inword -> 0 ch = `%c' (%d)", line_number, ch, __LINE__);*/
6394 if (tflags
& LEX_INWORD
)
6397 /*itrace("parse_comsub:%d: lex_inword == 1 ch = `%c' lex_wlen = %d (%d)", line_number, ch, lex_wlen, __LINE__);*/
6401 /*itrace("parse_comsub:%d: lex_inword -> 1 ch = `%c' (%d)", line_number, ch, __LINE__);*/
6402 tflags
|= LEX_INWORD
;
6404 if (tflags
& LEX_RESWDOK
)
6409 /* Skip whitespace */
6410 if MBTEST(shellblank (ch
) && (tflags
& LEX_HEREDELIM
) == 0 && lex_rwlen
== 0)
6412 /* Add this character. */
6413 RESIZE_MALLOCED_BUFFER (ret
, retind
, 1, retsize
, 64);
6418 /* Either we are looking for the start of the here-doc delimiter
6419 (lex_firstind == -1) or we are reading one (lex_firstind >= 0).
6420 If this character is a shell break character and we are reading
6421 the delimiter, save it and note that we are now reading a here
6422 document. If we've found the start of the delimiter, note it by
6423 setting lex_firstind. Backslashes can quote shell metacharacters
6424 in here-doc delimiters. */
6425 if (tflags
& LEX_HEREDELIM
)
6427 if (lex_firstind
== -1 && shellbreak (ch
) == 0)
6428 lex_firstind
= retind
;
6430 else if (heredelim
&& (tflags
& LEX_PASSNEXT
) == 0 && ch
== '\n')
6432 tflags
|= LEX_INHEREDOC
;
6433 tflags
&= ~LEX_HEREDELIM
;
6434 lex_firstind
= retind
+ 1;
6435 #if defined (BANG_HISTORY)
6436 history_expansion_inhibited
= 1;
6440 else if (lex_firstind
>= 0 && (tflags
& LEX_PASSNEXT
) == 0 && shellbreak (ch
))
6444 nestret
= substring (ret
, lex_firstind
, retind
);
6445 heredelim
= string_quote_removal (nestret
, 0);
6446 hdlen
= STRLEN(heredelim
);
6447 /*itrace("parse_comsub:%d: found here doc delimiter `%s' (%d)", line_number, heredelim, hdlen);*/
6448 if (STREQ (heredelim
, nestret
) == 0)
6449 tflags
|= LEX_QUOTEDDOC
;
6454 tflags
|= LEX_INHEREDOC
;
6455 tflags
&= ~LEX_HEREDELIM
;
6456 lex_firstind
= retind
+ 1;
6457 #if defined (BANG_HISTORY)
6458 history_expansion_inhibited
= 1;
6466 /* Meta-characters that can introduce a reserved word. Not perfect yet. */
6467 if MBTEST((tflags
& LEX_RESWDOK
) == 0 && (tflags
& LEX_CKCASE
) && (tflags
& LEX_INCOMMENT
) == 0 && (shellmeta(ch
) || ch
== '\n'))
6469 /* Add this character. */
6470 RESIZE_MALLOCED_BUFFER (ret
, retind
, 1, retsize
, 64);
6472 peekc
= shell_getc (1);
6473 if (ch
== peekc
&& (ch
== '&' || ch
== '|' || ch
== ';')) /* two-character tokens */
6475 RESIZE_MALLOCED_BUFFER (ret
, retind
, 1, retsize
, 64);
6476 ret
[retind
++] = peekc
;
6477 /*itrace("parse_comsub:%d: set lex_reswordok = 1, ch = `%c'", line_number, ch);*/
6478 tflags
|= LEX_RESWDOK
;
6482 else if (ch
== '\n' || COMSUB_META(ch
))
6484 shell_ungetc (peekc
);
6485 /*itrace("parse_comsub:%d: set lex_reswordok = 1, ch = `%c'", line_number, ch);*/
6486 tflags
|= LEX_RESWDOK
;
6494 /* `unget' the character we just added and fall through */
6496 shell_ungetc (peekc
);
6500 /* If we can read a reserved word, try to read one. */
6501 if (tflags
& LEX_RESWDOK
)
6503 if MBTEST(islower ((unsigned char)ch
))
6505 /* Add this character. */
6506 RESIZE_MALLOCED_BUFFER (ret
, retind
, 1, retsize
, 64);
6511 else if MBTEST(lex_rwlen
== 4 && shellbreak (ch
))
6513 if (STREQN (ret
+ retind
- 4, "case", 4))
6515 tflags
|= LEX_INCASE
;
6516 tflags
&= ~LEX_RESWDOK
;
6517 /*itrace("parse_comsub:%d: found `case', lex_incase -> 1 lex_reswdok -> 0", line_number);*/
6519 else if (STREQN (ret
+ retind
- 4, "esac", 4))
6521 tflags
&= ~LEX_INCASE
;
6522 /*itrace("parse_comsub:%d: found `esac', lex_incase -> 0 lex_reswdok -> 1", line_number);*/
6523 tflags
|= LEX_RESWDOK
;
6526 else if (STREQN (ret
+ retind
- 4, "done", 4) ||
6527 STREQN (ret
+ retind
- 4, "then", 4) ||
6528 STREQN (ret
+ retind
- 4, "else", 4) ||
6529 STREQN (ret
+ retind
- 4, "elif", 4) ||
6530 STREQN (ret
+ retind
- 4, "time", 4))
6532 /* these are four-character reserved words that can be
6533 followed by a reserved word; anything else turns off
6534 the reserved-word-ok flag */
6535 /*itrace("parse_comsub:%d: found `%.4s', lex_reswdok -> 1", line_number, ret+retind-4);*/
6536 tflags
|= LEX_RESWDOK
;
6539 else if (shellmeta (ch
) == 0)
6541 tflags
&= ~LEX_RESWDOK
;
6542 /*itrace("parse_comsub:%d: found `%.4s', lex_reswdok -> 0", line_number, ret+retind-4);*/
6544 else /* can't be in a reserved word any more */
6547 else if MBTEST((tflags
& LEX_CKCOMMENT
) && ch
== '#' && (lex_rwlen
== 0 || ((tflags
& LEX_INWORD
) && lex_wlen
== 0)))
6548 ; /* don't modify LEX_RESWDOK if we're starting a comment */
6549 /* Allow `do' followed by space, tab, or newline to preserve the
6550 RESWDOK flag, but reset the reserved word length counter so we
6551 can read another one. */
6552 else if MBTEST(((tflags
& LEX_INCASE
) == 0) &&
6553 (isblank((unsigned char)ch
) || ch
== '\n') &&
6555 STREQN (ret
+ retind
- 2, "do", 2))
6557 /*itrace("parse_comsub:%d: lex_incase == 0 found `%c', found \"do\"", line_number, ch);*/
6560 else if MBTEST((tflags
& LEX_INCASE
) && ch
!= '\n')
6561 /* If we can read a reserved word and we're in case, we're at the
6562 point where we can read a new pattern list or an esac. We
6563 handle the esac case above. If we read a newline, we want to
6564 leave LEX_RESWDOK alone. If we read anything else, we want to
6565 turn off LEX_RESWDOK, since we're going to read a pattern list. */
6567 tflags
&= ~LEX_RESWDOK
;
6568 /*itrace("parse_comsub:%d: lex_incase == 1 found `%c', lex_reswordok -> 0", line_number, ch);*/
6570 else if MBTEST(shellbreak (ch
) == 0)
6572 tflags
&= ~LEX_RESWDOK
;
6573 /*itrace("parse_comsub:%d: found `%c', lex_reswordok -> 0", line_number, ch);*/
6576 /* If we find a space or tab but have read something and it's not
6577 `do', turn off the reserved-word-ok flag */
6578 else if MBTEST(isblank ((unsigned char)ch
) && lex_rwlen
> 0)
6580 tflags
&= ~LEX_RESWDOK
;
6581 /*itrace("parse_comsub:%d: found `%c', lex_reswordok -> 0", line_number, ch);*/
6586 /* Might be the start of a here-doc delimiter */
6587 if MBTEST((tflags
& LEX_INCOMMENT
) == 0 && (tflags
& LEX_CKCASE
) && ch
== '<')
6589 /* Add this character. */
6590 RESIZE_MALLOCED_BUFFER (ret
, retind
, 1, retsize
, 64);
6592 peekc
= shell_getc (1);
6597 RESIZE_MALLOCED_BUFFER (ret
, retind
, 1, retsize
, 64);
6598 ret
[retind
++] = peekc
;
6599 peekc
= shell_getc (1);
6604 RESIZE_MALLOCED_BUFFER (ret
, retind
, 1, retsize
, 64);
6605 ret
[retind
++] = peekc
;
6606 tflags
|= LEX_STRIPDOC
;
6609 shell_ungetc (peekc
);
6612 tflags
|= LEX_HEREDELIM
;
6619 shell_ungetc (peekc
); /* not a here-doc, start over */
6623 else if MBTEST((tflags
& LEX_CKCOMMENT
) && (tflags
& LEX_INCOMMENT
) == 0 && ch
== '#' && (((tflags
& LEX_RESWDOK
) && lex_rwlen
== 0) || ((tflags
& LEX_INWORD
) && lex_wlen
== 0)))
6625 /*itrace("parse_comsub:%d: lex_incomment -> 1 (%d)", line_number, __LINE__);*/
6626 tflags
|= LEX_INCOMMENT
;
6629 if MBTEST(ch
== CTLESC
|| ch
== CTLNUL
) /* special shell escapes */
6631 RESIZE_MALLOCED_BUFFER (ret
, retind
, 2, retsize
, 64);
6632 ret
[retind
++] = CTLESC
;
6637 else if MBTEST((tflags
& LEX_INCASE
) && ch
== close
&& close
== ')')
6638 tflags
&= ~LEX_INCASE
; /* XXX */
6640 else if MBTEST(ch
== close
&& (tflags
& LEX_INCASE
) == 0) /* ending delimiter */
6643 /*itrace("parse_comsub:%d: found close: count = %d", line_number, count);*/
6645 else if MBTEST(((flags
& P_FIRSTCLOSE
) == 0) && (tflags
& LEX_INCASE
) == 0 && ch
== open
) /* nested begin */
6648 /*itrace("parse_comsub:%d: found open: count = %d", line_number, count);*/
6651 /* Add this character. */
6652 RESIZE_MALLOCED_BUFFER (ret
, retind
, 1, retsize
, 64);
6655 /* If we just read the ending character, don't bother continuing. */
6659 if MBTEST(ch
== '\\') /* backslashes */
6660 tflags
|= LEX_PASSNEXT
;
6662 if MBTEST(shellquote (ch
))
6664 /* '', ``, or "" inside $(...). */
6665 push_delimiter (dstack
, ch
);
6666 if MBTEST((tflags
& LEX_WASDOL
) && ch
== '\'') /* $'...' inside group */
6667 nestret
= parse_matched_pair (ch
, ch
, ch
, &nestlen
, P_ALLOWESC
|rflags
);
6669 nestret
= parse_matched_pair (ch
, ch
, ch
, &nestlen
, rflags
);
6670 pop_delimiter (dstack
);
6671 CHECK_NESTRET_ERROR ();
6673 if MBTEST((tflags
& LEX_WASDOL
) && ch
== '\'' && (extended_quote
|| (rflags
& P_DQUOTE
) == 0))
6675 /* Translate $'...' here. */
6676 ttrans
= ansiexpand (nestret
, 0, nestlen
- 1, &ttranslen
);
6679 if ((rflags
& P_DQUOTE
) == 0)
6681 nestret
= sh_single_quote (ttrans
);
6683 nestlen
= strlen (nestret
);
6688 nestlen
= ttranslen
;
6690 retind
-= 2; /* back up before the $' */
6692 else if MBTEST((tflags
& LEX_WASDOL
) && ch
== '"' && (extended_quote
|| (rflags
& P_DQUOTE
) == 0))
6694 /* Locale expand $"..." here. */
6695 ttrans
= localeexpand (nestret
, 0, nestlen
- 1, start_lineno
, &ttranslen
);
6698 nestret
= sh_mkdoublequoted (ttrans
, ttranslen
, 0);
6700 nestlen
= ttranslen
+ 2;
6701 retind
-= 2; /* back up before the $" */
6707 else if MBTEST((tflags
& LEX_WASDOL
) && (ch
== '(' || ch
== '{' || ch
== '[')) /* ) } ] */
6708 /* check for $(), $[], or ${} inside command substitution. */
6710 if ((tflags
& LEX_INCASE
) == 0 && open
== ch
) /* undo previous increment */
6712 if (ch
== '(') /* ) */
6713 nestret
= parse_comsub (0, '(', ')', &nestlen
, (rflags
|P_COMMAND
) & ~P_DQUOTE
);
6714 else if (ch
== '{') /* } */
6715 nestret
= parse_matched_pair (0, '{', '}', &nestlen
, P_FIRSTCLOSE
|P_DOLBRACE
|rflags
);
6716 else if (ch
== '[') /* ] */
6717 nestret
= parse_matched_pair (0, '[', ']', &nestlen
, rflags
);
6719 CHECK_NESTRET_ERROR ();
6724 if MBTEST(ch
== '$' && (tflags
& LEX_WASDOL
) == 0)
6725 tflags
|= LEX_WASDOL
;
6727 tflags
&= ~LEX_WASDOL
;
6730 #if defined (BANG_HISTORY)
6731 history_expansion_inhibited
= orig_histexp
;
6737 /*itrace("parse_comsub:%d: returning `%s'", line_number, ret);*/
6741 /* Recursively call the parser to parse a $(...) command substitution. */
6743 xparse_dolparen (base
, string
, indp
, flags
)
6749 sh_parser_state_t ps
;
6750 sh_input_line_state_t ls
;
6751 int orig_ind
, nc
, sflags
, orig_eof_token
, start_lineno
;
6752 char *ret
, *ep
, *ostring
;
6753 #if defined (ALIAS) || defined (DPAREN_ARITHMETIC)
6754 STRING_SAVER
*saved_pushed_strings
;
6757 /*debug_parser(1);*/
6760 start_lineno
= line_number
;
6764 if (flags
& SX_NOALLOC
)
6765 return (char *)NULL
;
6772 /*itrace("xparse_dolparen: size = %d shell_input_line = `%s' string=`%s'", shell_input_line_size, shell_input_line, string);*/
6773 sflags
= SEVAL_NONINT
|SEVAL_NOHIST
|SEVAL_NOFREE
;
6774 if (flags
& SX_NOLONGJMP
)
6775 sflags
|= SEVAL_NOLONGJMP
;
6776 save_parser_state (&ps
);
6777 save_input_line_state (&ls
);
6778 orig_eof_token
= shell_eof_token
;
6779 #if defined (ALIAS) || defined (DPAREN_ARITHMETIC)
6780 saved_pushed_strings
= pushed_string_list
; /* separate parsing context */
6781 pushed_string_list
= (STRING_SAVER
*)NULL
;
6785 parser_state
|= PST_CMDSUBST
|PST_EOFTOKEN
; /* allow instant ')' */ /*(*/
6786 shell_eof_token
= ')';
6788 /* Should we save and restore the bison/yacc lookahead token (yychar) here?
6789 Or only if it's not YYEMPTY? */
6791 nc
= parse_string (string
, "command substitution", sflags
, &ep
);
6793 if (current_token
== shell_eof_token
)
6794 yyclearin
; /* might want to clear lookahead token unconditionally */
6797 /* reset_parser() clears shell_input_line and associated variables, including
6798 parser_state, so we want to reset things, then restore what we need. */
6799 restore_input_line_state (&ls
);
6801 shell_eof_token
= orig_eof_token
;
6802 restore_parser_state (&ps
);
6804 #if defined (ALIAS) || defined (DPAREN_ARITHMETIC)
6805 pushed_string_list
= saved_pushed_strings
;
6810 /* If parse_string returns < 0, we need to jump to top level with the
6811 negative of the return value. We abandon the rest of this input line
6815 clear_shell_input_line (); /* XXX */
6816 if (bash_input
.type
!= st_string
) /* paranoia */
6817 parser_state
&= ~(PST_CMDSUBST
|PST_EOFTOKEN
);
6818 jump_to_top_level (-nc
); /* XXX */
6821 /* Need to find how many characters parse_and_execute consumed, update
6822 *indp, if flags != 0, copy the portion of the string parsed into RET
6823 and return it. If flags & 1 (SX_NOALLOC) we can return NULL. */
6830 itrace("xparse_dolparen:%d: ep[-1] != RPAREN (%d), ep = `%s'", line_number
, ep
[-1], ep
);
6833 while (ep
> ostring
&& ep
[-1] == '\n') ep
--;
6837 *indp
= ep
- base
- 1;
6841 if (base
[*indp
] != ')')
6842 itrace("xparse_dolparen:%d: base[%d] != RPAREN (%d), base = `%s'", line_number
, *indp
, base
[*indp
], base
);
6843 if (*indp
< orig_ind
)
6844 itrace("xparse_dolparen:%d: *indp (%d) < orig_ind (%d), orig_string = `%s'", line_number
, *indp
, orig_ind
, ostring
);
6847 if (base
[*indp
] != ')')
6850 parser_error (start_lineno
, _("unexpected EOF while looking for matching `%c'"), ')');
6851 jump_to_top_level (DISCARD
);
6854 if (flags
& SX_NOALLOC
)
6855 return (char *)NULL
;
6863 ret
= substring (ostring
, 0, nc
- 1);
6868 #if defined (DPAREN_ARITHMETIC) || defined (ARITH_FOR_COMMAND)
6869 /* Parse a double-paren construct. It can be either an arithmetic
6870 command, an arithmetic `for' command, or a nested subshell. Returns
6871 the parsed token, -1 on error, or -2 if we didn't do anything and
6872 should just go on. */
6881 #if defined (ARITH_FOR_COMMAND)
6882 if (last_read_token
== FOR
)
6884 arith_for_lineno
= line_number
;
6885 cmdtyp
= parse_arith_cmd (&wval
, 0);
6888 wd
= alloc_word_desc ();
6890 yylval
.word_list
= make_word_list (wd
, (WORD_LIST
*)NULL
);
6891 return (ARITH_FOR_EXPRS
);
6894 return -1; /* ERROR */
6898 #if defined (DPAREN_ARITHMETIC)
6899 if (reserved_word_acceptable (last_read_token
))
6901 sline
= line_number
;
6903 cmdtyp
= parse_arith_cmd (&wval
, 0);
6904 if (cmdtyp
== 1) /* arithmetic command */
6906 wd
= alloc_word_desc ();
6908 wd
->flags
= W_QUOTED
|W_NOSPLIT
|W_NOGLOB
|W_DQUOTE
;
6909 yylval
.word_list
= make_word_list (wd
, (WORD_LIST
*)NULL
);
6912 else if (cmdtyp
== 0) /* nested subshell */
6914 push_string (wval
, 0, (alias_t
*)NULL
);
6915 pushed_string_list
->flags
= PSH_DPAREN
;
6916 if ((parser_state
& PST_CASEPAT
) == 0)
6917 parser_state
|= PST_SUBSHELL
;
6925 return -2; /* XXX */
6928 /* We've seen a `(('. Look for the matching `))'. If we get it, return 1.
6929 If not, assume it's a nested subshell for backwards compatibility and
6930 return 0. In any case, put the characters we've consumed into a locally-
6931 allocated buffer and make *ep point to that buffer. Return -1 on an
6932 error, for example EOF. */
6934 parse_arith_cmd (ep
, adddq
)
6938 int exp_lineno
, rval
, c
;
6939 char *ttok
, *tokstr
;
6942 exp_lineno
= line_number
;
6943 ttok
= parse_matched_pair (0, '(', ')', &ttoklen
, 0);
6945 if (ttok
== &matched_pair_error
)
6947 /* Check that the next character is the closing right paren. If
6948 not, this is a syntax error. ( */
6953 tokstr
= (char *)xmalloc (ttoklen
+ 4);
6955 /* if ADDDQ != 0 then (( ... )) -> "..." */
6956 if (rval
== 1 && adddq
) /* arith cmd, add double quotes */
6959 strncpy (tokstr
+ 1, ttok
, ttoklen
- 1);
6960 tokstr
[ttoklen
] = '"';
6961 tokstr
[ttoklen
+1] = '\0';
6963 else if (rval
== 1) /* arith cmd, don't add double quotes */
6965 strncpy (tokstr
, ttok
, ttoklen
- 1);
6966 tokstr
[ttoklen
-1] = '\0';
6968 else /* nested subshell */
6971 strncpy (tokstr
+ 1, ttok
, ttoklen
- 1);
6972 tokstr
[ttoklen
] = ')';
6973 tokstr
[ttoklen
+1] = c
;
6974 tokstr
[ttoklen
+2] = '\0';
6981 #endif /* DPAREN_ARITHMETIC || ARITH_FOR_COMMAND */
6983 #if defined (COND_COMMAND)
6989 if (EOF_Reached
&& cond_token
!= COND_ERROR
) /* [[ */
6990 parser_error (cond_lineno
, _("unexpected EOF while looking for `]]'"));
6991 else if (cond_token
!= COND_ERROR
)
6993 if (etext
= error_token_from_token (cond_token
))
6995 parser_error (cond_lineno
, _("syntax error in conditional expression: unexpected token `%s'"), etext
);
6999 parser_error (cond_lineno
, _("syntax error in conditional expression"));
7006 return (cond_or ());
7015 if (cond_token
== OR_OR
)
7018 l
= make_cond_node (COND_OR
, (WORD_DESC
*)NULL
, l
, r
);
7029 if (cond_token
== AND_AND
)
7032 l
= make_cond_node (COND_AND
, (WORD_DESC
*)NULL
, l
, r
);
7038 cond_skip_newlines ()
7040 while ((cond_token
= read_token (READ
)) == '\n')
7042 if (SHOULD_PROMPT ())
7045 return (cond_token
);
7048 #define COND_RETURN_ERROR() \
7049 do { cond_token = COND_ERROR; return ((COND_COM *)NULL); } while (0)
7055 COND_COM
*term
, *tleft
, *tright
;
7059 /* Read a token. It can be a left paren, a `!', a unary operator, or a
7060 word that should be the first argument of a binary operator. Start by
7061 skipping newlines, since this is a compound command. */
7062 tok
= cond_skip_newlines ();
7063 lineno
= line_number
;
7064 if (tok
== COND_END
)
7066 COND_RETURN_ERROR ();
7068 else if (tok
== '(')
7070 term
= cond_expr ();
7071 if (cond_token
!= ')')
7074 dispose_cond_node (term
); /* ( */
7075 if (etext
= error_token_from_token (cond_token
))
7077 parser_error (lineno
, _("unexpected token `%s', expected `)'"), etext
);
7081 parser_error (lineno
, _("expected `)'"));
7082 COND_RETURN_ERROR ();
7084 term
= make_cond_node (COND_EXPR
, (WORD_DESC
*)NULL
, term
, (COND_COM
*)NULL
);
7085 (void)cond_skip_newlines ();
7087 else if (tok
== BANG
|| (tok
== WORD
&& (yylval
.word
->word
[0] == '!' && yylval
.word
->word
[1] == '\0')))
7090 dispose_word (yylval
.word
); /* not needed */
7091 term
= cond_term ();
7093 term
->flags
|= CMD_INVERT_RETURN
;
7095 else if (tok
== WORD
&& yylval
.word
->word
[0] == '-' && yylval
.word
->word
[1] && yylval
.word
->word
[2] == 0 && test_unop (yylval
.word
->word
))
7098 tok
= read_token (READ
);
7101 tleft
= make_cond_node (COND_TERM
, yylval
.word
, (COND_COM
*)NULL
, (COND_COM
*)NULL
);
7102 term
= make_cond_node (COND_UNARY
, op
, tleft
, (COND_COM
*)NULL
);
7107 if (etext
= error_token_from_token (tok
))
7109 parser_error (line_number
, _("unexpected argument `%s' to conditional unary operator"), etext
);
7113 parser_error (line_number
, _("unexpected argument to conditional unary operator"));
7114 COND_RETURN_ERROR ();
7117 (void)cond_skip_newlines ();
7119 else if (tok
== WORD
) /* left argument to binary operator */
7122 tleft
= make_cond_node (COND_TERM
, yylval
.word
, (COND_COM
*)NULL
, (COND_COM
*)NULL
);
7125 tok
= read_token (READ
);
7126 if (tok
== WORD
&& test_binop (yylval
.word
->word
))
7129 if (op
->word
[0] == '=' && (op
->word
[1] == '\0' || (op
->word
[1] == '=' && op
->word
[2] == '\0')))
7130 parser_state
|= PST_EXTPAT
;
7131 else if (op
->word
[0] == '!' && op
->word
[1] == '=' && op
->word
[2] == '\0')
7132 parser_state
|= PST_EXTPAT
;
7134 #if defined (COND_REGEXP)
7135 else if (tok
== WORD
&& STREQ (yylval
.word
->word
, "=~"))
7138 parser_state
|= PST_REGEXP
;
7141 else if (tok
== '<' || tok
== '>')
7142 op
= make_word_from_token (tok
); /* ( */
7143 /* There should be a check before blindly accepting the `)' that we have
7144 seen the opening `('. */
7145 else if (tok
== COND_END
|| tok
== AND_AND
|| tok
== OR_OR
|| tok
== ')')
7147 /* Special case. [[ x ]] is equivalent to [[ -n x ]], just like
7148 the test command. Similarly for [[ x && expr ]] or
7149 [[ x || expr ]] or [[ (x) ]]. */
7150 op
= make_word ("-n");
7151 term
= make_cond_node (COND_UNARY
, op
, tleft
, (COND_COM
*)NULL
);
7157 if (etext
= error_token_from_token (tok
))
7159 parser_error (line_number
, _("unexpected token `%s', conditional binary operator expected"), etext
);
7163 parser_error (line_number
, _("conditional binary operator expected"));
7164 dispose_cond_node (tleft
);
7165 COND_RETURN_ERROR ();
7169 if (parser_state
& PST_EXTPAT
)
7171 tok
= read_token (READ
);
7172 if (parser_state
& PST_EXTPAT
)
7173 extended_glob
= global_extglob
;
7174 parser_state
&= ~(PST_REGEXP
|PST_EXTPAT
);
7178 tright
= make_cond_node (COND_TERM
, yylval
.word
, (COND_COM
*)NULL
, (COND_COM
*)NULL
);
7179 term
= make_cond_node (COND_BINARY
, op
, tleft
, tright
);
7183 if (etext
= error_token_from_token (tok
))
7185 parser_error (line_number
, _("unexpected argument `%s' to conditional binary operator"), etext
);
7189 parser_error (line_number
, _("unexpected argument to conditional binary operator"));
7190 dispose_cond_node (tleft
);
7192 COND_RETURN_ERROR ();
7195 (void)cond_skip_newlines ();
7200 parser_error (line_number
, _("unexpected token `%c' in conditional command"), tok
);
7201 else if (etext
= error_token_from_token (tok
))
7203 parser_error (line_number
, _("unexpected token `%s' in conditional command"), etext
);
7207 parser_error (line_number
, _("unexpected token %d in conditional command"), tok
);
7208 COND_RETURN_ERROR ();
7213 /* This is kind of bogus -- we slip a mini recursive-descent parser in
7214 here to handle the conditional statement syntax. */
7216 parse_cond_command ()
7220 global_extglob
= extended_glob
;
7221 cexp
= cond_expr ();
7222 return (make_cond_command (cexp
));
7226 #if defined (ARRAY_VARS)
7227 /* When this is called, it's guaranteed that we don't care about anything
7228 in t beyond i. We use a buffer with room for the characters we add just
7229 in case assignment() ends up doing something like parsing a command
7230 substitution that will reallocate atoken. We don't want to write beyond
7231 the end of an allocated buffer. */
7233 token_is_assignment (t
, i
)
7240 atoken
= xmalloc (i
+ 3);
7241 memcpy (atoken
, t
, i
);
7245 r
= assignment (atoken
, (parser_state
& PST_COMPASSIGN
) != 0);
7249 /* XXX - check that r == i to avoid returning false positive for
7250 t containing `=' before t[i]. */
7251 return (r
> 0 && r
== i
);
7254 /* XXX - possible changes here for `+=' */
7256 token_is_ident (t
, i
)
7265 r
= legal_identifier (t
);
7272 read_token_word (character
)
7275 /* The value for YYLVAL when a WORD is read. */
7276 WORD_DESC
*the_word
;
7278 /* Index into the token that we are building. */
7281 /* ALL_DIGITS becomes zero when we see a non-digit. */
7282 int all_digit_token
;
7284 /* DOLLAR_PRESENT becomes non-zero if we see a `$'. */
7287 /* COMPOUND_ASSIGNMENT becomes non-zero if we are parsing a compound
7289 int compound_assignment
;
7291 /* QUOTED becomes non-zero if we see one of ("), ('), (`), or (\). */
7294 /* Non-zero means to ignore the value of the next character, and just
7295 to add it no matter what. */
7296 int pass_next_character
;
7298 /* The current delimiting character. */
7300 int result
, peek_char
;
7301 char *ttok
, *ttrans
;
7302 int ttoklen
, ttranslen
;
7305 if (token_buffer_size
< TOKEN_DEFAULT_INITIAL_SIZE
)
7306 token
= (char *)xrealloc (token
, token_buffer_size
= TOKEN_DEFAULT_INITIAL_SIZE
);
7309 all_digit_token
= DIGIT (character
);
7310 dollar_present
= quoted
= pass_next_character
= compound_assignment
= 0;
7314 if (character
== EOF
)
7317 if (pass_next_character
)
7319 pass_next_character
= 0;
7320 goto got_escaped_character
;
7323 cd
= current_delimiter (dstack
);
7325 /* Handle backslashes. Quote lots of things when not inside of
7326 double-quotes, quote some things inside of double-quotes. */
7327 if MBTEST(character
== '\\')
7329 peek_char
= shell_getc (0);
7331 /* Backslash-newline is ignored in all cases except
7332 when quoted with single quotes. */
7333 if (peek_char
== '\n')
7336 goto next_character
;
7340 shell_ungetc (peek_char
);
7342 /* If the next character is to be quoted, note it now. */
7343 if (cd
== 0 || cd
== '`' ||
7344 (cd
== '"' && peek_char
>= 0 && (sh_syntaxtab
[peek_char
] & CBSDQUOTE
)))
7345 pass_next_character
++;
7352 /* Parse a matched pair of quote characters. */
7353 if MBTEST(shellquote (character
))
7355 push_delimiter (dstack
, character
);
7356 ttok
= parse_matched_pair (character
, character
, character
, &ttoklen
, (character
== '`') ? P_COMMAND
: 0);
7357 pop_delimiter (dstack
);
7358 if (ttok
== &matched_pair_error
)
7359 return -1; /* Bail immediately. */
7360 RESIZE_MALLOCED_BUFFER (token
, token_index
, ttoklen
+ 2,
7361 token_buffer_size
, TOKEN_DEFAULT_GROW_SIZE
);
7362 token
[token_index
++] = character
;
7363 strcpy (token
+ token_index
, ttok
);
7364 token_index
+= ttoklen
;
7365 all_digit_token
= 0;
7366 if (character
!= '`')
7368 dollar_present
|= (character
== '"' && strchr (ttok
, '$') != 0);
7370 goto next_character
;
7374 /* When parsing a regexp as a single word inside a conditional command,
7375 we need to special-case characters special to both the shell and
7376 regular expressions. Right now, that is only '(' and '|'. */ /*)*/
7377 if MBTEST((parser_state
& PST_REGEXP
) && (character
== '(' || character
== '|')) /*)*/
7379 if (character
== '|')
7382 push_delimiter (dstack
, character
);
7383 ttok
= parse_matched_pair (cd
, '(', ')', &ttoklen
, 0);
7384 pop_delimiter (dstack
);
7385 if (ttok
== &matched_pair_error
)
7386 return -1; /* Bail immediately. */
7387 RESIZE_MALLOCED_BUFFER (token
, token_index
, ttoklen
+ 2,
7388 token_buffer_size
, TOKEN_DEFAULT_GROW_SIZE
);
7389 token
[token_index
++] = character
;
7390 strcpy (token
+ token_index
, ttok
);
7391 token_index
+= ttoklen
;
7393 dollar_present
= all_digit_token
= 0;
7394 goto next_character
;
7396 #endif /* COND_REGEXP */
7398 #ifdef EXTENDED_GLOB
7399 /* Parse a ksh-style extended pattern matching specification. */
7400 if MBTEST(extended_glob
&& PATTERN_CHAR (character
))
7402 peek_char
= shell_getc (1);
7403 if MBTEST(peek_char
== '(') /* ) */
7405 push_delimiter (dstack
, peek_char
);
7406 ttok
= parse_matched_pair (cd
, '(', ')', &ttoklen
, 0);
7407 pop_delimiter (dstack
);
7408 if (ttok
== &matched_pair_error
)
7409 return -1; /* Bail immediately. */
7410 RESIZE_MALLOCED_BUFFER (token
, token_index
, ttoklen
+ 3,
7412 TOKEN_DEFAULT_GROW_SIZE
);
7413 token
[token_index
++] = character
;
7414 token
[token_index
++] = peek_char
;
7415 strcpy (token
+ token_index
, ttok
);
7416 token_index
+= ttoklen
;
7418 dollar_present
= all_digit_token
= 0;
7419 goto next_character
;
7422 shell_ungetc (peek_char
);
7424 #endif /* EXTENDED_GLOB */
7426 /* If the delimiter character is not single quote, parse some of
7427 the shell expansions that must be read as a single word. */
7428 if (shellexp (character
))
7430 peek_char
= shell_getc (1);
7431 /* $(...), <(...), >(...), $((...)), ${...}, and $[...] constructs */
7432 if MBTEST(peek_char
== '(' ||
7433 ((peek_char
== '{' || peek_char
== '[') && character
== '$')) /* ) ] } */
7435 if (peek_char
== '{') /* } */
7436 ttok
= parse_matched_pair (cd
, '{', '}', &ttoklen
, P_FIRSTCLOSE
|P_DOLBRACE
);
7437 else if (peek_char
== '(') /* ) */
7439 /* XXX - push and pop the `(' as a delimiter for use by
7440 the command-oriented-history code. This way newlines
7441 appearing in the $(...) string get added to the
7442 history literally rather than causing a possibly-
7443 incorrect `;' to be added. ) */
7444 push_delimiter (dstack
, peek_char
);
7445 ttok
= parse_comsub (cd
, '(', ')', &ttoklen
, P_COMMAND
);
7446 pop_delimiter (dstack
);
7449 ttok
= parse_matched_pair (cd
, '[', ']', &ttoklen
, 0);
7450 if (ttok
== &matched_pair_error
)
7451 return -1; /* Bail immediately. */
7452 RESIZE_MALLOCED_BUFFER (token
, token_index
, ttoklen
+ 3,
7454 TOKEN_DEFAULT_GROW_SIZE
);
7455 token
[token_index
++] = character
;
7456 token
[token_index
++] = peek_char
;
7457 strcpy (token
+ token_index
, ttok
);
7458 token_index
+= ttoklen
;
7461 all_digit_token
= 0;
7462 goto next_character
;
7464 /* This handles $'...' and $"..." new-style quoted strings. */
7465 else if MBTEST(character
== '$' && (peek_char
== '\'' || peek_char
== '"'))
7469 first_line
= line_number
;
7470 push_delimiter (dstack
, peek_char
);
7471 ttok
= parse_matched_pair (peek_char
, peek_char
, peek_char
,
7473 (peek_char
== '\'') ? P_ALLOWESC
: 0);
7474 pop_delimiter (dstack
);
7475 if (ttok
== &matched_pair_error
)
7477 if (peek_char
== '\'')
7479 ttrans
= ansiexpand (ttok
, 0, ttoklen
- 1, &ttranslen
);
7482 /* Insert the single quotes and correctly quote any
7483 embedded single quotes (allowed because P_ALLOWESC was
7484 passed to parse_matched_pair). */
7485 ttok
= sh_single_quote (ttrans
);
7487 ttranslen
= strlen (ttok
);
7492 /* Try to locale-expand the converted string. */
7493 ttrans
= localeexpand (ttok
, 0, ttoklen
- 1, first_line
, &ttranslen
);
7496 /* Add the double quotes back */
7497 ttok
= sh_mkdoublequoted (ttrans
, ttranslen
, 0);
7503 RESIZE_MALLOCED_BUFFER (token
, token_index
, ttranslen
+ 1,
7505 TOKEN_DEFAULT_GROW_SIZE
);
7506 strcpy (token
+ token_index
, ttrans
);
7507 token_index
+= ttranslen
;
7510 all_digit_token
= 0;
7511 goto next_character
;
7513 /* This could eventually be extended to recognize all of the
7514 shell's single-character parameter expansions, and set flags.*/
7515 else if MBTEST(character
== '$' && peek_char
== '$')
7517 RESIZE_MALLOCED_BUFFER (token
, token_index
, 3,
7519 TOKEN_DEFAULT_GROW_SIZE
);
7520 token
[token_index
++] = '$';
7521 token
[token_index
++] = peek_char
;
7523 all_digit_token
= 0;
7524 goto next_character
;
7527 shell_ungetc (peek_char
);
7530 #if defined (ARRAY_VARS)
7531 /* Identify possible array subscript assignment; match [...]. If
7532 parser_state&PST_COMPASSIGN, we need to parse [sub]=words treating
7533 `sub' as if it were enclosed in double quotes. */
7534 else if MBTEST(character
== '[' && /* ] */
7535 ((token_index
> 0 && assignment_acceptable (last_read_token
) && token_is_ident (token
, token_index
)) ||
7536 (token_index
== 0 && (parser_state
&PST_COMPASSIGN
))))
7538 ttok
= parse_matched_pair (cd
, '[', ']', &ttoklen
, P_ARRAYSUB
);
7539 if (ttok
== &matched_pair_error
)
7540 return -1; /* Bail immediately. */
7541 RESIZE_MALLOCED_BUFFER (token
, token_index
, ttoklen
+ 2,
7543 TOKEN_DEFAULT_GROW_SIZE
);
7544 token
[token_index
++] = character
;
7545 strcpy (token
+ token_index
, ttok
);
7546 token_index
+= ttoklen
;
7548 all_digit_token
= 0;
7549 goto next_character
;
7551 /* Identify possible compound array variable assignment. */
7552 else if MBTEST(character
== '=' && token_index
> 0 && (assignment_acceptable (last_read_token
) || (parser_state
& PST_ASSIGNOK
)) && token_is_assignment (token
, token_index
))
7554 peek_char
= shell_getc (1);
7555 if MBTEST(peek_char
== '(') /* ) */
7557 ttok
= parse_compound_assignment (&ttoklen
);
7559 RESIZE_MALLOCED_BUFFER (token
, token_index
, ttoklen
+ 4,
7561 TOKEN_DEFAULT_GROW_SIZE
);
7563 token
[token_index
++] = '=';
7564 token
[token_index
++] = '(';
7567 strcpy (token
+ token_index
, ttok
);
7568 token_index
+= ttoklen
;
7570 token
[token_index
++] = ')';
7572 all_digit_token
= 0;
7573 compound_assignment
= 1;
7575 goto next_character
;
7577 goto got_token
; /* ksh93 seems to do this */
7581 shell_ungetc (peek_char
);
7585 /* When not parsing a multi-character word construct, shell meta-
7586 characters break words. */
7587 if MBTEST(shellbreak (character
))
7589 shell_ungetc (character
);
7594 if (character
== CTLESC
|| character
== CTLNUL
)
7596 RESIZE_MALLOCED_BUFFER (token
, token_index
, 2, token_buffer_size
,
7597 TOKEN_DEFAULT_GROW_SIZE
);
7598 token
[token_index
++] = CTLESC
;
7601 got_escaped_character
:
7602 RESIZE_MALLOCED_BUFFER (token
, token_index
, 1, token_buffer_size
,
7603 TOKEN_DEFAULT_GROW_SIZE
);
7605 token
[token_index
++] = character
;
7607 all_digit_token
&= DIGIT (character
);
7608 dollar_present
|= character
== '$';
7611 if (character
== '\n' && SHOULD_PROMPT ())
7614 /* We want to remove quoted newlines (that is, a \<newline> pair)
7615 unless we are within single quotes or pass_next_character is
7616 set (the shell equivalent of literal-next). */
7617 cd
= current_delimiter (dstack
);
7618 character
= shell_getc (cd
!= '\'' && pass_next_character
== 0);
7619 } /* end for (;;) */
7623 /* Calls to RESIZE_MALLOCED_BUFFER ensure there is sufficient room. */
7624 token
[token_index
] = '\0';
7626 /* Check to see what thing we should return. If the last_read_token
7627 is a `<', or a `&', or the character which ended this token is
7628 a '>' or '<', then, and ONLY then, is this input token a NUMBER.
7629 Otherwise, it is just a word, and should be returned as such. */
7630 if MBTEST(all_digit_token
&& (character
== '<' || character
== '>' ||
7631 last_read_token
== LESS_AND
||
7632 last_read_token
== GREATER_AND
))
7634 if (legal_number (token
, &lvalue
) && (int)lvalue
== lvalue
)
7636 yylval
.number
= lvalue
;
7641 /* Check for special case tokens. */
7642 result
= (last_shell_getc_is_singlebyte
) ? special_case_tokens (token
) : -1;
7647 /* Posix.2 does not allow reserved words to be aliased, so check for all
7648 of them, including special cases, before expanding the current token
7650 if MBTEST(posixly_correct
)
7651 CHECK_FOR_RESERVED_WORD (token
);
7653 /* Aliases are expanded iff EXPAND_ALIASES is non-zero, and quoting
7654 inhibits alias expansion. */
7655 if (expand_aliases
&& quoted
== 0)
7657 result
= alias_expand_token (token
);
7658 if (result
== RE_READ_TOKEN
)
7659 return (RE_READ_TOKEN
);
7660 else if (result
== NO_EXPANSION
)
7661 parser_state
&= ~PST_ALEXPNEXT
;
7664 /* If not in Posix.2 mode, check for reserved words after alias
7666 if MBTEST(posixly_correct
== 0)
7668 CHECK_FOR_RESERVED_WORD (token
);
7670 the_word
= alloc_word_desc ();
7671 the_word
->word
= (char *)xmalloc (1 + token_index
);
7672 the_word
->flags
= 0;
7673 strcpy (the_word
->word
, token
);
7675 the_word
->flags
|= W_HASDOLLAR
;
7677 the_word
->flags
|= W_QUOTED
; /*(*/
7678 if (compound_assignment
&& token
[token_index
-1] == ')')
7679 the_word
->flags
|= W_COMPASSIGN
;
7680 /* A word is an assignment if it appears at the beginning of a
7681 simple command, or after another assignment word. This is
7682 context-dependent, so it cannot be handled in the grammar. */
7683 if (assignment (token
, (parser_state
& PST_COMPASSIGN
) != 0))
7685 the_word
->flags
|= W_ASSIGNMENT
;
7686 /* Don't perform word splitting on assignment statements. */
7687 if (assignment_acceptable (last_read_token
) || (parser_state
& PST_COMPASSIGN
) != 0)
7689 the_word
->flags
|= W_NOSPLIT
;
7690 if (parser_state
& PST_COMPASSIGN
)
7691 the_word
->flags
|= W_NOGLOB
; /* XXX - W_NOBRACE? */
7695 if (command_token_position (last_read_token
))
7698 b
= builtin_address_internal (token
, 0);
7699 if (b
&& (b
->flags
& ASSIGNMENT_BUILTIN
))
7700 parser_state
|= PST_ASSIGNOK
;
7701 else if (STREQ (token
, "eval") || STREQ (token
, "let"))
7702 parser_state
|= PST_ASSIGNOK
;
7705 yylval
.word
= the_word
;
7707 /* should we check that quoted == 0 as well? */
7708 if (token
[0] == '{' && token
[token_index
-1] == '}' &&
7709 (character
== '<' || character
== '>'))
7711 /* can use token; already copied to the_word */
7712 token
[token_index
-1] = '\0';
7713 #if defined (ARRAY_VARS)
7714 if (legal_identifier (token
+1) || valid_array_reference (token
+1, 0))
7716 if (legal_identifier (token
+1))
7719 strcpy (the_word
->word
, token
+1);
7720 /* itrace("read_token_word: returning REDIR_WORD for %s", the_word->word); */
7721 yylval
.word
= the_word
; /* accommodate recursive call */
7722 return (REDIR_WORD
);
7725 /* valid_array_reference can call the parser recursively; need to
7726 make sure that yylval.word doesn't change if we are going to
7727 return WORD or ASSIGNMENT_WORD */
7728 yylval
.word
= the_word
;
7731 result
= ((the_word
->flags
& (W_ASSIGNMENT
|W_NOSPLIT
)) == (W_ASSIGNMENT
|W_NOSPLIT
))
7732 ? ASSIGNMENT_WORD
: WORD
;
7734 switch (last_read_token
)
7737 parser_state
|= PST_ALLOWOPNBRC
;
7738 function_dstart
= line_number
;
7743 if (word_top
< MAX_CASE_NEST
)
7745 word_lineno
[word_top
] = line_number
;
7746 expecting_in_token
++;
7753 /* Return 1 if TOKSYM is a token that after being read would allow
7754 a reserved word to be seen, else 0. */
7756 reserved_word_acceptable (toksym
)
7793 #if defined (COPROCESS_SUPPORT)
7794 if (last_read_token
== WORD
&& token_before_that
== COPROC
)
7797 if (last_read_token
== WORD
&& token_before_that
== FUNCTION
)
7803 /* Return the index of TOKEN in the alist of reserved words, or -1 if
7804 TOKEN is not a shell reserved word. */
7806 find_reserved_word (tokstr
)
7810 for (i
= 0; word_token_alist
[i
].word
; i
++)
7811 if (STREQ (tokstr
, word_token_alist
[i
].word
))
7816 /* An interface to let the rest of the shell (primarily the completion
7817 system) know what the parser is expecting. */
7819 parser_in_command_position ()
7821 return (command_token_position (last_read_token
));
7825 #if defined (READLINE)
7826 /* Called after each time readline is called. This insures that whatever
7827 the new prompt string is gets propagated to readline's local prompt
7830 reset_readline_prompt ()
7834 if (prompt_string_pointer
)
7836 temp_prompt
= (*prompt_string_pointer
)
7837 ? decode_prompt_string (*prompt_string_pointer
)
7840 if (temp_prompt
== 0)
7842 temp_prompt
= (char *)xmalloc (1);
7843 temp_prompt
[0] = '\0';
7846 FREE (current_readline_prompt
);
7847 current_readline_prompt
= temp_prompt
;
7850 #endif /* READLINE */
7853 #if defined (HISTORY)
7854 /* A list of tokens which can be followed by newlines, but not by
7855 semi-colons. When concatenating multiple lines of history, the
7856 newline separator for such tokens is replaced with a space. */
7857 static const int no_semi_successors
[] = {
7858 '\n', '{', '(', ')', ';', '&', '|',
7859 CASE
, DO
, ELSE
, IF
, SEMI_SEMI
, SEMI_AND
, SEMI_SEMI_AND
, THEN
, UNTIL
,
7860 WHILE
, AND_AND
, OR_OR
, IN
,
7864 /* If we are not within a delimited expression, try to be smart
7865 about which separators can be semi-colons and which must be
7866 newlines. Returns the string that should be added into the
7867 history entry. LINE is the line we're about to add; it helps
7868 make some more intelligent decisions in certain cases. */
7870 history_delimiting_chars (line
)
7873 static int last_was_heredoc
= 0; /* was the last entry the start of a here document? */
7876 if ((parser_state
& PST_HEREDOC
) == 0)
7877 last_was_heredoc
= 0;
7879 if (dstack
.delimiter_depth
!= 0)
7882 /* We look for current_command_line_count == 2 because we are looking to
7883 add the first line of the body of the here document (the second line
7884 of the command). We also keep LAST_WAS_HEREDOC as a private sentinel
7885 variable to note when we think we added the first line of a here doc
7886 (the one with a "<<" somewhere in it) */
7887 if (parser_state
& PST_HEREDOC
)
7889 if (last_was_heredoc
)
7891 last_was_heredoc
= 0;
7894 return (here_doc_first_line
? "\n" : "");
7897 if (parser_state
& PST_COMPASSIGN
)
7900 /* First, handle some special cases. */
7902 /* If we just read `()', assume it's a function definition, and don't
7903 add a semicolon. If the token before the `)' was not `(', and we're
7904 not in the midst of parsing a case statement, assume it's a
7905 parenthesized command and add the semicolon. */
7907 if (token_before_that
== ')')
7909 if (two_tokens_ago
== '(') /*)*/ /* function def */
7911 /* This does not work for subshells inside case statement
7912 command lists. It's a suboptimal solution. */
7913 else if (parser_state
& PST_CASESTMT
) /* case statement pattern */
7916 return "; "; /* (...) subshell */
7918 else if (token_before_that
== WORD
&& two_tokens_ago
== FUNCTION
)
7919 return " "; /* function def using `function name' without `()' */
7921 /* If we're not in a here document, but we think we're about to parse one,
7922 and we would otherwise return a `;', return a newline to delimit the
7923 line with the here-doc delimiter */
7924 else if ((parser_state
& PST_HEREDOC
) == 0 && current_command_line_count
> 1 && last_read_token
== '\n' && strstr (line
, "<<"))
7926 last_was_heredoc
= 1;
7929 else if ((parser_state
& PST_HEREDOC
) == 0 && current_command_line_count
> 1 && need_here_doc
> 0)
7931 else if (token_before_that
== WORD
&& two_tokens_ago
== FOR
)
7933 /* Tricky. `for i\nin ...' should not have a semicolon, but
7934 `for i\ndo ...' should. We do what we can. */
7935 for (i
= shell_input_line_index
; whitespace (shell_input_line
[i
]); i
++)
7937 if (shell_input_line
[i
] && shell_input_line
[i
] == 'i' && shell_input_line
[i
+1] == 'n')
7941 else if (two_tokens_ago
== CASE
&& token_before_that
== WORD
&& (parser_state
& PST_CASESTMT
))
7944 for (i
= 0; no_semi_successors
[i
]; i
++)
7946 if (token_before_that
== no_semi_successors
[i
])
7950 if (line_isblank (line
))
7955 #endif /* HISTORY */
7957 /* Issue a prompt, or prepare to issue a prompt when the next character
7964 if (interactive
== 0 || expanding_alias ()) /* XXX */
7967 ps1_prompt
= get_string_value ("PS1");
7968 ps2_prompt
= get_string_value ("PS2");
7970 ps0_prompt
= get_string_value ("PS0");
7972 if (!prompt_string_pointer
)
7973 prompt_string_pointer
= &ps1_prompt
;
7975 temp_prompt
= *prompt_string_pointer
7976 ? decode_prompt_string (*prompt_string_pointer
)
7979 if (temp_prompt
== 0)
7981 temp_prompt
= (char *)xmalloc (1);
7982 temp_prompt
[0] = '\0';
7985 current_prompt_string
= *prompt_string_pointer
;
7986 prompt_string_pointer
= &ps2_prompt
;
7988 #if defined (READLINE)
7989 if (!no_line_editing
)
7991 FREE (current_readline_prompt
);
7992 current_readline_prompt
= temp_prompt
;
7995 #endif /* READLINE */
7997 FREE (current_decoded_prompt
);
7998 current_decoded_prompt
= temp_prompt
;
8003 get_current_prompt_level ()
8005 return ((current_prompt_string
&& current_prompt_string
== ps2_prompt
) ? 2 : 1);
8009 set_current_prompt_level (x
)
8012 prompt_string_pointer
= (x
== 2) ? &ps2_prompt
: &ps1_prompt
;
8013 current_prompt_string
= *prompt_string_pointer
;
8019 fprintf (stderr
, "%s", current_decoded_prompt
);
8023 #if defined (HISTORY)
8024 /* The history library increments the history offset as soon as it stores
8025 the first line of a potentially multi-line command, so we compensate
8026 here by returning one fewer when appropriate. */
8028 prompt_history_number (pmt
)
8033 ret
= history_number ();
8037 if (pmt
== ps1_prompt
) /* are we expanding $PS1? */
8039 else if (pmt
== ps2_prompt
&& command_oriented_history
== 0)
8040 return ret
; /* not command oriented history */
8041 else if (pmt
== ps2_prompt
&& command_oriented_history
&& current_command_first_line_saved
)
8044 return ret
- 1; /* PS0, PS4, ${var@P}, PS2 other cases */
8048 /* Return a string which will be printed as a prompt. The string
8049 may contain special characters which are decoded as follows:
8052 \d the date in Day Mon Date format
8053 \e escape (ascii 033)
8054 \h the hostname up to the first `.'
8056 \j the number of active jobs
8057 \l the basename of the shell's tty device name
8060 \s the name of the shell
8061 \t the time in 24-hour hh:mm:ss format
8062 \T the time in 12-hour hh:mm:ss format
8063 \@ the time in 12-hour hh:mm am/pm format
8064 \A the time in 24-hour hh:mm format
8065 \D{fmt} the result of passing FMT to strftime(3)
8067 \v the version of bash (e.g., 2.00)
8068 \V the release of bash, version + patchlevel (e.g., 2.00.0)
8069 \w the current working directory
8070 \W the last element of $PWD
8071 \! the history number of this command
8072 \# the command number of this command
8073 \$ a $ or a # if you are root
8074 \nnn character code nnn in octal
8076 \[ begin a sequence of non-printing chars
8077 \] end a sequence of non-printing chars
8079 #define PROMPT_GROWTH 48
8081 decode_prompt_string (string
)
8085 char *result
, *t
, *orig_string
;
8086 struct dstack save_dstack
;
8087 int last_exit_value
, last_comsub_pid
;
8088 #if defined (PROMPT_STRING_DECODE)
8092 char *temp
, *t_host
, octal_string
[4];
8098 result
= (char *)xmalloc (result_size
= PROMPT_GROWTH
);
8099 result
[result_index
= 0] = 0;
8100 temp
= (char *)NULL
;
8101 orig_string
= string
;
8103 while (c
= *string
++)
8105 if (posixly_correct
&& c
== '!')
8109 temp
= savestring ("!");
8114 #if !defined (HISTORY)
8115 temp
= savestring ("1");
8117 temp
= itos (prompt_history_number (orig_string
));
8118 #endif /* HISTORY */
8119 string
--; /* add_string increments string again. */
8137 strncpy (octal_string
, string
, 3);
8138 octal_string
[3] = '\0';
8140 n
= read_octal (octal_string
);
8141 temp
= (char *)xmalloc (3);
8143 if (n
== CTLESC
|| n
== CTLNUL
)
8160 for (c
= 0; n
!= -1 && c
< 3 && ISOCTAL (*string
); c
++)
8163 c
= 0; /* tested at add_string: */
8171 /* Make the current time/date into a string. */
8172 (void) time (&the_time
);
8173 #if defined (HAVE_TZSET)
8174 sv_tz ("TZ"); /* XXX -- just make sure */
8176 tm
= localtime (&the_time
);
8179 n
= strftime (timebuf
, sizeof (timebuf
), "%a %b %d", tm
);
8181 n
= strftime (timebuf
, sizeof (timebuf
), "%H:%M:%S", tm
);
8183 n
= strftime (timebuf
, sizeof (timebuf
), "%I:%M:%S", tm
);
8185 n
= strftime (timebuf
, sizeof (timebuf
), "%I:%M %p", tm
);
8187 n
= strftime (timebuf
, sizeof (timebuf
), "%H:%M", tm
);
8192 timebuf
[sizeof(timebuf
) - 1] = '\0';
8194 temp
= savestring (timebuf
);
8197 case 'D': /* strftime format */
8198 if (string
[1] != '{') /* } */
8201 (void) time (&the_time
);
8202 tm
= localtime (&the_time
);
8203 string
+= 2; /* skip { */
8204 timefmt
= xmalloc (strlen (string
) + 3);
8205 for (t
= timefmt
; *string
&& *string
!= '}'; )
8208 c
= *string
; /* tested at add_string */
8209 if (timefmt
[0] == '\0')
8212 timefmt
[1] = 'X'; /* locale-specific current time */
8215 n
= strftime (timebuf
, sizeof (timebuf
), timefmt
, tm
);
8221 timebuf
[sizeof(timebuf
) - 1] = '\0';
8223 if (promptvars
|| posixly_correct
)
8224 /* Make sure that expand_prompt_string is called with a
8225 second argument of Q_DOUBLE_QUOTES if we use this
8227 temp
= sh_backslash_quote_for_double_quotes (timebuf
);
8229 temp
= savestring (timebuf
);
8233 temp
= (char *)xmalloc (3);
8234 temp
[0] = no_line_editing
? '\n' : '\r';
8235 temp
[1] = no_line_editing
? '\0' : '\n';
8240 temp
= base_pathname (shell_name
);
8241 /* Try to quote anything the user can set in the file system */
8242 if (promptvars
|| posixly_correct
)
8243 temp
= sh_backslash_quote_for_double_quotes (temp
);
8245 temp
= savestring (temp
);
8250 temp
= (char *)xmalloc (16);
8252 strcpy (temp
, dist_version
);
8254 sprintf (temp
, "%s.%d", dist_version
, patch_level
);
8260 /* Use the value of PWD because it is much more efficient. */
8261 char t_string
[PATH_MAX
];
8264 temp
= get_string_value ("PWD");
8268 if (getcwd (t_string
, sizeof(t_string
)) == 0)
8274 tlen
= strlen (t_string
);
8278 tlen
= sizeof (t_string
) - 1;
8279 strncpy (t_string
, temp
, tlen
);
8281 t_string
[tlen
] = '\0';
8283 #if defined (MACOSX)
8284 /* Convert from "fs" format to "input" format */
8285 temp
= fnx_fromfs (t_string
, strlen (t_string
));
8286 if (temp
!= t_string
)
8287 strcpy (t_string
, temp
);
8290 #define ROOT_PATH(x) ((x)[0] == '/' && (x)[1] == 0)
8291 #define DOUBLE_SLASH_ROOT(x) ((x)[0] == '/' && (x)[1] == '/' && (x)[2] == 0)
8292 /* Abbreviate \W as ~ if $PWD == $HOME */
8293 if (c
== 'W' && (((t
= get_string_value ("HOME")) == 0) || STREQ (t
, t_string
) == 0))
8295 if (ROOT_PATH (t_string
) == 0 && DOUBLE_SLASH_ROOT (t_string
) == 0)
8297 t
= strrchr (t_string
, '/');
8299 memmove (t_string
, t
+ 1, strlen (t
)); /* strlen(t) to copy NULL */
8303 #undef DOUBLE_SLASH_ROOT
8306 /* polite_directory_format is guaranteed to return a string
8307 no longer than PATH_MAX - 1 characters. */
8308 temp
= polite_directory_format (t_string
);
8309 if (temp
!= t_string
)
8310 strcpy (t_string
, temp
);
8313 temp
= trim_pathname (t_string
, PATH_MAX
- 1);
8314 /* If we're going to be expanding the prompt string later,
8315 quote the directory name. */
8316 if (promptvars
|| posixly_correct
)
8317 /* Make sure that expand_prompt_string is called with a
8318 second argument of Q_DOUBLE_QUOTES if we use this
8320 temp
= sh_backslash_quote_for_double_quotes (t_string
);
8322 temp
= savestring (t_string
);
8328 if (current_user
.user_name
== 0)
8329 get_current_user_info ();
8330 temp
= savestring (current_user
.user_name
);
8335 t_host
= savestring (current_host_name
);
8336 if (c
== 'h' && (t
= (char *)strchr (t_host
, '.')))
8338 if (promptvars
|| posixly_correct
)
8339 /* Make sure that expand_prompt_string is called with a
8340 second argument of Q_DOUBLE_QUOTES if we use this
8342 temp
= sh_backslash_quote_for_double_quotes (t_host
);
8344 temp
= savestring (t_host
);
8349 n
= current_command_number
;
8350 /* If we have already incremented current_command_number (PS4,
8351 ${var@P}), compensate */
8352 if (orig_string
!= ps0_prompt
&& orig_string
!= ps1_prompt
&& orig_string
!= ps2_prompt
)
8358 #if !defined (HISTORY)
8359 temp
= savestring ("1");
8361 temp
= itos (prompt_history_number (orig_string
));
8362 #endif /* HISTORY */
8366 t
= temp
= (char *)xmalloc (3);
8367 if ((promptvars
|| posixly_correct
) && (current_user
.euid
!= 0))
8369 *t
++ = current_user
.euid
== 0 ? '#' : '$';
8374 temp
= itos (count_all_jobs ());
8378 #if defined (HAVE_TTYNAME)
8379 temp
= (char *)ttyname (fileno (stdin
));
8380 t
= temp
? base_pathname (temp
) : "tty";
8381 temp
= savestring (t
);
8383 temp
= savestring ("tty");
8384 #endif /* !HAVE_TTYNAME */
8387 #if defined (READLINE)
8390 if (no_line_editing
)
8395 temp
= (char *)xmalloc (3);
8396 n
= (c
== '[') ? RL_PROMPT_START_IGNORE
: RL_PROMPT_END_IGNORE
;
8398 if (n
== CTLESC
|| n
== CTLNUL
)
8403 #endif /* READLINE */
8409 temp
= (char *)xmalloc (2);
8416 else /* (c == '\\') */
8423 temp
= (char *)xmalloc (3);
8432 sub_append_string (temp
, result
, &result_index
, &result_size
);
8433 temp
= (char *)NULL
; /* Freed in sub_append_string (). */
8434 result
[result_index
] = '\0';
8440 RESIZE_MALLOCED_BUFFER (result
, result_index
, 3, result_size
, PROMPT_GROWTH
);
8441 /* dequote_string should take care of removing this if we are not
8442 performing the rest of the word expansions. */
8443 if (c
== CTLESC
|| c
== CTLNUL
)
8444 result
[result_index
++] = CTLESC
;
8445 result
[result_index
++] = c
;
8446 result
[result_index
] = '\0';
8449 #else /* !PROMPT_STRING_DECODE */
8450 result
= savestring (string
);
8451 #endif /* !PROMPT_STRING_DECODE */
8453 /* Save the delimiter stack and point `dstack' to temp space so any
8454 command substitutions in the prompt string won't result in screwing
8455 up the parser's quoting state. */
8456 save_dstack
= dstack
;
8457 dstack
= temp_dstack
;
8458 dstack
.delimiter_depth
= 0;
8460 /* Perform variable and parameter expansion and command substitution on
8461 the prompt string. */
8462 if (promptvars
|| posixly_correct
)
8464 last_exit_value
= last_command_exit_value
;
8465 last_comsub_pid
= last_command_subst_pid
;
8466 list
= expand_prompt_string (result
, Q_DOUBLE_QUOTES
, 0);
8468 result
= string_list (list
);
8469 dispose_words (list
);
8470 last_command_exit_value
= last_exit_value
;
8471 last_command_subst_pid
= last_comsub_pid
;
8475 t
= dequote_string (result
);
8480 dstack
= save_dstack
;
8485 /************************************************
8489 ************************************************/
8491 /* Report a syntax error, and restart the parser. Call here for fatal
8497 report_syntax_error ((char *)NULL
);
8503 error_token_from_token (tok
)
8508 if (t
= find_token_in_alist (tok
, word_token_alist
, 0))
8511 if (t
= find_token_in_alist (tok
, other_token_alist
, 0))
8515 /* This stuff is dicy and needs closer inspection */
8516 switch (current_token
)
8519 case ASSIGNMENT_WORD
:
8521 t
= savestring (yylval
.word
->word
);
8524 t
= itos (yylval
.number
);
8527 if (yylval
.word_list
)
8528 t
= string_list (yylval
.word_list
);
8530 case ARITH_FOR_EXPRS
:
8531 if (yylval
.word_list
)
8532 t
= string_list_internal (yylval
.word_list
, " ; ");
8535 t
= (char *)NULL
; /* punt */
8543 error_token_from_text ()
8548 t
= shell_input_line
;
8549 i
= shell_input_line_index
;
8553 if (i
&& t
[i
] == '\0')
8556 while (i
&& (whitespace (t
[i
]) || t
[i
] == '\n'))
8562 while (i
&& (member (t
[i
], " \n\t;|&") == 0))
8565 while (i
!= token_end
&& (whitespace (t
[i
]) || t
[i
] == '\n'))
8568 /* Return our idea of the offending token. */
8569 if (token_end
|| (i
== 0 && token_end
== 0))
8572 msg
= substring (t
, i
, token_end
);
8573 else /* one-character token */
8575 msg
= (char *)xmalloc (2);
8585 print_offending_line ()
8590 msg
= savestring (shell_input_line
);
8591 token_end
= strlen (msg
);
8592 while (token_end
&& msg
[token_end
- 1] == '\n')
8593 msg
[--token_end
] = '\0';
8595 parser_error (line_number
, "`%s'", msg
);
8599 /* Report a syntax error with line numbers, etc.
8600 Call here for recoverable errors. If you have a message to print,
8601 then place it in MESSAGE, otherwise pass NULL and this will figure
8602 out an appropriate message for you. */
8604 report_syntax_error (message
)
8611 parser_error (line_number
, "%s", message
);
8612 if (interactive
&& EOF_Reached
)
8614 last_command_exit_value
= (executing_builtin
&& parse_and_execute_level
) ? EX_BADSYNTAX
: EX_BADUSAGE
;
8615 set_pipestatus_from_exit (last_command_exit_value
);
8619 /* If the line of input we're reading is not null, try to find the
8620 objectionable token. First, try to figure out what token the
8621 parser's complaining about by looking at current_token. */
8622 if (current_token
!= 0 && EOF_Reached
== 0 && (msg
= error_token_from_token (current_token
)))
8624 if (ansic_shouldquote (msg
))
8626 p
= ansic_quote (msg
, 0, NULL
);
8630 parser_error (line_number
, _("syntax error near unexpected token `%s'"), msg
);
8633 if (interactive
== 0)
8634 print_offending_line ();
8636 last_command_exit_value
= (executing_builtin
&& parse_and_execute_level
) ? EX_BADSYNTAX
: EX_BADUSAGE
;
8637 set_pipestatus_from_exit (last_command_exit_value
);
8641 /* If looking at the current token doesn't prove fruitful, try to find the
8642 offending token by analyzing the text of the input line near the current
8643 input line index and report what we find. */
8644 if (shell_input_line
&& *shell_input_line
)
8646 msg
= error_token_from_text ();
8649 parser_error (line_number
, _("syntax error near `%s'"), msg
);
8653 /* If not interactive, print the line containing the error. */
8654 if (interactive
== 0)
8655 print_offending_line ();
8659 msg
= EOF_Reached
? _("syntax error: unexpected end of file") : _("syntax error");
8660 parser_error (line_number
, "%s", msg
);
8661 /* When the shell is interactive, this file uses EOF_Reached
8662 only for error reporting. Other mechanisms are used to
8663 decide whether or not to exit. */
8664 if (interactive
&& EOF_Reached
)
8668 last_command_exit_value
= (executing_builtin
&& parse_and_execute_level
) ? EX_BADSYNTAX
: EX_BADUSAGE
;
8669 set_pipestatus_from_exit (last_command_exit_value
);
8672 /* ??? Needed function. ??? We have to be able to discard the constructs
8673 created during parsing. In the case of error, we want to return
8674 allocated objects to the memory pool. In the case of no error, we want
8675 to throw away the information about where the allocated objects live.
8676 (dispose_command () will actually free the command.) */
8678 discard_parser_constructs (error_p
)
8683 /************************************************
8687 ************************************************/
8689 /* Do that silly `type "bye" to exit' stuff. You know, "ignoreeof". */
8691 /* A flag denoting whether or not ignoreeof is set. */
8694 /* The number of times that we have encountered an EOF character without
8695 another character intervening. When this gets above the limit, the
8696 shell terminates. */
8697 int eof_encountered
= 0;
8699 /* The limit for eof_encountered. */
8700 int eof_encountered_limit
= 10;
8702 /* If we have EOF as the only input unit, this user wants to leave
8703 the shell. If the shell is not interactive, then just leave.
8704 Otherwise, if ignoreeof is set, and we haven't done this the
8705 required number of times in a row, print a message. */
8707 handle_eof_input_unit ()
8711 /* shell.c may use this to decide whether or not to write out the
8712 history, among other things. We use it only for error reporting
8717 /* If the user wants to "ignore" eof, then let her do so, kind of. */
8720 if (eof_encountered
< eof_encountered_limit
)
8722 fprintf (stderr
, _("Use \"%s\" to leave the shell.\n"),
8723 login_shell
? "logout" : "exit");
8725 /* Reset the parsing state. */
8726 last_read_token
= current_token
= '\n';
8727 /* Reset the prompt string to be $PS1. */
8728 prompt_string_pointer
= (char **)NULL
;
8734 /* In this case EOF should exit the shell. Do it now. */
8737 last_shell_builtin
= this_shell_builtin
;
8738 this_shell_builtin
= exit_builtin
;
8739 exit_builtin ((WORD_LIST
*)NULL
);
8743 /* We don't write history files, etc., for non-interactive shells. */
8748 /************************************************
8750 * STRING PARSING FUNCTIONS *
8752 ************************************************/
8754 /* It's very important that these two functions treat the characters
8755 between ( and ) identically. */
8757 static WORD_LIST parse_string_error
;
8759 /* Take a string and run it through the shell parser, returning the
8760 resultant word list. Used by compound array assignment. */
8762 parse_string_to_word_list (s
, flags
, whom
)
8768 int tok
, orig_current_token
, orig_line_number
, orig_input_terminator
;
8769 int orig_line_count
;
8770 int old_echo_input
, old_expand_aliases
, ea
;
8771 #if defined (HISTORY)
8772 int old_remember_on_history
, old_history_expansion_inhibited
;
8775 #if defined (HISTORY)
8776 old_remember_on_history
= remember_on_history
;
8777 # if defined (BANG_HISTORY)
8778 old_history_expansion_inhibited
= history_expansion_inhibited
;
8780 bash_history_disable ();
8783 orig_line_number
= line_number
;
8784 orig_line_count
= current_command_line_count
;
8785 orig_input_terminator
= shell_input_line_terminator
;
8786 old_echo_input
= echo_input_at_read
;
8787 old_expand_aliases
= expand_aliases
;
8790 #if 0 /* TAG: bash-5.2 Alex fxmbsw7 Ratchev <fxmbsw7@gmail.com> 11/17/2020 */
8791 if (ea
= expanding_alias ())
8792 parser_save_alias ();
8794 last_read_token
= WORD
; /* WORD to allow reserved words here */
8795 current_command_line_count
= 0;
8796 echo_input_at_read
= expand_aliases
= 0;
8798 with_input_from_string (s
, whom
);
8799 wl
= (WORD_LIST
*)NULL
;
8802 parser_state
|= PST_COMPASSIGN
|PST_REPARSE
;
8804 while ((tok
= read_token (READ
)) != yacc_EOF
)
8806 if (tok
== '\n' && *bash_input
.location
.string
== '\0')
8808 if (tok
== '\n') /* Allow newlines in compound assignments */
8810 if (tok
!= WORD
&& tok
!= ASSIGNMENT_WORD
)
8812 line_number
= orig_line_number
+ line_number
- 1;
8813 orig_current_token
= current_token
;
8814 current_token
= tok
;
8815 yyerror (NULL
); /* does the right thing */
8816 current_token
= orig_current_token
;
8819 wl
= &parse_string_error
;
8822 wl
= make_word_list (yylval
.word
, wl
);
8825 last_read_token
= '\n';
8828 #if 0 /* TAG: bash-5.2 */
8830 parser_restore_alias ();
8833 #if defined (HISTORY)
8834 remember_on_history
= old_remember_on_history
;
8835 # if defined (BANG_HISTORY)
8836 history_expansion_inhibited
= old_history_expansion_inhibited
;
8837 # endif /* BANG_HISTORY */
8838 #endif /* HISTORY */
8840 echo_input_at_read
= old_echo_input
;
8841 expand_aliases
= old_expand_aliases
;
8843 current_command_line_count
= orig_line_count
;
8844 shell_input_line_terminator
= orig_input_terminator
;
8847 parser_state
&= ~(PST_COMPASSIGN
|PST_REPARSE
);
8849 if (wl
== &parse_string_error
)
8851 set_exit_status (EXECUTION_FAILURE
);
8852 if (interactive_shell
== 0 && posixly_correct
)
8853 jump_to_top_level (FORCE_EOF
);
8855 jump_to_top_level (DISCARD
);
8858 return (REVERSE_LIST (wl
, WORD_LIST
*));
8862 parse_compound_assignment (retlenp
)
8866 int tok
, orig_line_number
, orig_token_size
, orig_last_token
, assignok
;
8867 char *saved_token
, *ret
;
8869 saved_token
= token
;
8870 orig_token_size
= token_buffer_size
;
8871 orig_line_number
= line_number
;
8872 orig_last_token
= last_read_token
;
8874 last_read_token
= WORD
; /* WORD to allow reserved words here */
8876 token
= (char *)NULL
;
8877 token_buffer_size
= 0;
8879 assignok
= parser_state
&PST_ASSIGNOK
; /* XXX */
8881 wl
= (WORD_LIST
*)NULL
; /* ( */
8882 parser_state
|= PST_COMPASSIGN
;
8884 while ((tok
= read_token (READ
)) != ')')
8886 if (tok
== '\n') /* Allow newlines in compound assignments */
8888 if (SHOULD_PROMPT ())
8892 if (tok
!= WORD
&& tok
!= ASSIGNMENT_WORD
)
8894 current_token
= tok
; /* for error reporting */
8895 if (tok
== yacc_EOF
) /* ( */
8896 parser_error (orig_line_number
, _("unexpected EOF while looking for matching `)'"));
8898 yyerror(NULL
); /* does the right thing */
8901 wl
= &parse_string_error
;
8904 wl
= make_word_list (yylval
.word
, wl
);
8908 token
= saved_token
;
8909 token_buffer_size
= orig_token_size
;
8911 parser_state
&= ~PST_COMPASSIGN
;
8913 if (wl
== &parse_string_error
)
8915 set_exit_status (EXECUTION_FAILURE
);
8916 last_read_token
= '\n'; /* XXX */
8917 if (interactive_shell
== 0 && posixly_correct
)
8918 jump_to_top_level (FORCE_EOF
);
8920 jump_to_top_level (DISCARD
);
8923 last_read_token
= orig_last_token
; /* XXX - was WORD? */
8927 rl
= REVERSE_LIST (wl
, WORD_LIST
*);
8928 ret
= string_list (rl
);
8935 *retlenp
= (ret
&& *ret
) ? strlen (ret
) : 0;
8938 parser_state
|= PST_ASSIGNOK
;
8943 /************************************************
8945 * SAVING AND RESTORING PARTIAL PARSE STATE *
8947 ************************************************/
8950 save_parser_state (ps
)
8951 sh_parser_state_t
*ps
;
8954 ps
= (sh_parser_state_t
*)xmalloc (sizeof (sh_parser_state_t
));
8956 return ((sh_parser_state_t
*)NULL
);
8958 ps
->parser_state
= parser_state
;
8959 ps
->token_state
= save_token_state ();
8961 ps
->input_line_terminator
= shell_input_line_terminator
;
8962 ps
->eof_encountered
= eof_encountered
;
8964 ps
->prompt_string_pointer
= prompt_string_pointer
;
8966 ps
->current_command_line_count
= current_command_line_count
;
8968 #if defined (HISTORY)
8969 ps
->remember_on_history
= remember_on_history
;
8970 # if defined (BANG_HISTORY)
8971 ps
->history_expansion_inhibited
= history_expansion_inhibited
;
8975 ps
->last_command_exit_value
= last_command_exit_value
;
8976 #if defined (ARRAY_VARS)
8977 ps
->pipestatus
= save_pipestatus_array ();
8980 ps
->last_shell_builtin
= last_shell_builtin
;
8981 ps
->this_shell_builtin
= this_shell_builtin
;
8983 ps
->expand_aliases
= expand_aliases
;
8984 ps
->echo_input_at_read
= echo_input_at_read
;
8985 ps
->need_here_doc
= need_here_doc
;
8986 ps
->here_doc_first_line
= here_doc_first_line
;
8988 if (need_here_doc
== 0)
8989 ps
->redir_stack
[0] = 0;
8991 memcpy (ps
->redir_stack
, redir_stack
, sizeof (redir_stack
[0]) * HEREDOC_MAX
);
8994 ps
->token_buffer_size
= token_buffer_size
;
8995 /* Force reallocation on next call to read_token_word */
8997 token_buffer_size
= 0;
9003 restore_parser_state (ps
)
9004 sh_parser_state_t
*ps
;
9011 parser_state
= ps
->parser_state
;
9012 if (ps
->token_state
)
9014 restore_token_state (ps
->token_state
);
9015 free (ps
->token_state
);
9018 shell_input_line_terminator
= ps
->input_line_terminator
;
9019 eof_encountered
= ps
->eof_encountered
;
9021 prompt_string_pointer
= ps
->prompt_string_pointer
;
9023 current_command_line_count
= ps
->current_command_line_count
;
9025 #if defined (HISTORY)
9026 remember_on_history
= ps
->remember_on_history
;
9027 # if defined (BANG_HISTORY)
9028 history_expansion_inhibited
= ps
->history_expansion_inhibited
;
9032 last_command_exit_value
= ps
->last_command_exit_value
;
9033 #if defined (ARRAY_VARS)
9034 restore_pipestatus_array (ps
->pipestatus
);
9037 last_shell_builtin
= ps
->last_shell_builtin
;
9038 this_shell_builtin
= ps
->this_shell_builtin
;
9040 expand_aliases
= ps
->expand_aliases
;
9041 echo_input_at_read
= ps
->echo_input_at_read
;
9042 need_here_doc
= ps
->need_here_doc
;
9043 here_doc_first_line
= ps
->here_doc_first_line
;
9046 for (i
= 0; i
< HEREDOC_MAX
; i
++)
9047 redir_stack
[i
] = ps
->redir_stack
[i
];
9049 if (need_here_doc
== 0)
9052 memcpy (redir_stack
, ps
->redir_stack
, sizeof (redir_stack
[0]) * HEREDOC_MAX
);
9057 token_buffer_size
= ps
->token_buffer_size
;
9060 sh_input_line_state_t
*
9061 save_input_line_state (ls
)
9062 sh_input_line_state_t
*ls
;
9065 ls
= (sh_input_line_state_t
*)xmalloc (sizeof (sh_input_line_state_t
));
9067 return ((sh_input_line_state_t
*)NULL
);
9069 ls
->input_line
= shell_input_line
;
9070 ls
->input_line_size
= shell_input_line_size
;
9071 ls
->input_line_len
= shell_input_line_len
;
9072 ls
->input_line_index
= shell_input_line_index
;
9074 #if defined (HANDLE_MULTIBYTE)
9075 ls
->input_property
= shell_input_line_property
;
9076 ls
->input_propsize
= shell_input_line_propsize
;
9079 /* force reallocation */
9080 shell_input_line
= 0;
9081 shell_input_line_size
= shell_input_line_len
= shell_input_line_index
= 0;
9083 #if defined (HANDLE_MULTIBYTE)
9084 shell_input_line_property
= 0;
9085 shell_input_line_propsize
= 0;
9092 restore_input_line_state (ls
)
9093 sh_input_line_state_t
*ls
;
9095 FREE (shell_input_line
);
9096 shell_input_line
= ls
->input_line
;
9097 shell_input_line_size
= ls
->input_line_size
;
9098 shell_input_line_len
= ls
->input_line_len
;
9099 shell_input_line_index
= ls
->input_line_index
;
9101 #if defined (HANDLE_MULTIBYTE)
9102 FREE (shell_input_line_property
);
9103 shell_input_line_property
= ls
->input_property
;
9104 shell_input_line_propsize
= ls
->input_propsize
;
9108 set_line_mbstate ();
9112 /************************************************
9114 * MULTIBYTE CHARACTER HANDLING *
9116 ************************************************/
9118 #if defined (HANDLE_MULTIBYTE)
9120 /* We don't let the property buffer get larger than this unless the line is */
9121 #define MAX_PROPSIZE 32768
9127 size_t i
, previ
, len
;
9128 mbstate_t mbs
, prevs
;
9132 if (shell_input_line
== NULL
)
9134 len
= STRLEN (shell_input_line
); /* XXX - shell_input_line_len ? */
9137 if (shell_input_line_propsize
>= MAX_PROPSIZE
&& len
< MAX_PROPSIZE
>>1)
9139 free (shell_input_line_property
);
9140 shell_input_line_property
= 0;
9141 shell_input_line_propsize
= 0;
9143 if (len
+1 > shell_input_line_propsize
)
9145 shell_input_line_propsize
= len
+ 1;
9146 shell_input_line_property
= (char *)xrealloc (shell_input_line_property
, shell_input_line_propsize
);
9149 if (locale_mb_cur_max
== 1)
9151 memset (shell_input_line_property
, 1, len
);
9155 /* XXX - use whether or not we are in a UTF-8 locale to avoid calls to
9157 if (locale_utf8locale
== 0)
9158 memset (&prevs
, '\0', sizeof (mbstate_t));
9160 for (i
= previ
= 0; i
< len
; i
++)
9162 if (locale_utf8locale
== 0)
9165 c
= shell_input_line
[i
];
9169 for (j
= i
; j
< len
; j
++)
9170 shell_input_line_property
[j
] = 1;
9174 if (locale_utf8locale
)
9176 if ((unsigned char)shell_input_line
[previ
] < 128) /* i != previ */
9180 ilen
= utf8_mblen (shell_input_line
+ previ
, i
- previ
+ 1);
9181 mbclen
= (ilen
== -1) ? (size_t)-1
9182 : ((ilen
== -2) ? (size_t)-2 : (size_t)ilen
);
9186 mbclen
= mbrlen (shell_input_line
+ previ
, i
- previ
+ 1, &mbs
);
9188 if (mbclen
== 1 || mbclen
== (size_t)-1)
9193 else if (mbclen
== (size_t)-2)
9195 else if (mbclen
> 1)
9199 if (locale_utf8locale
== 0)
9205 for (j
= i
; j
< len
; j
++)
9206 shell_input_line_property
[j
] = 1;
9210 shell_input_line_property
[i
] = mbclen
;
9213 #endif /* HANDLE_MULTIBYTE */