]> git.ipfire.org Git - thirdparty/bash.git/blob - y.tab.c
fix for SIGINT in sourced script
[thirdparty/bash.git] / y.tab.c
1 /* A Bison parser, made by GNU Bison 3.0.4. */
2
3 /* Bison implementation for Yacc-like parsers in C
4
5 Copyright (C) 1984, 1989-1990, 2000-2015 Free Software Foundation, Inc.
6
7 This program is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
19
20 /* As a special exception, you may create a larger work that contains
21 part or all of the Bison parser skeleton and distribute that work
22 under terms of your choice, so long as that work isn't itself a
23 parser generator using the skeleton or a modified version thereof
24 as a parser skeleton. Alternatively, if you modify or redistribute
25 the parser skeleton itself, you may (at your option) remove this
26 special exception, which will cause the skeleton and the resulting
27 Bison output files to be licensed under the GNU General Public
28 License without this special exception.
29
30 This special exception was added by the Free Software Foundation in
31 version 2.2 of Bison. */
32
33 /* C LALR(1) parser skeleton written by Richard Stallman, by
34 simplifying the original so-called "semantic" parser. */
35
36 /* All symbols defined below should begin with yy or YY, to avoid
37 infringing on user name space. This should be done even for local
38 variables, as they might otherwise be expanded by user macros.
39 There are some unavoidable exceptions within include files to
40 define necessary library symbols; they are noted "INFRINGES ON
41 USER NAME SPACE" below. */
42
43 /* Identify Bison output. */
44 #define YYBISON 1
45
46 /* Bison version. */
47 #define YYBISON_VERSION "3.0.4"
48
49 /* Skeleton name. */
50 #define YYSKELETON_NAME "yacc.c"
51
52 /* Pure parsers. */
53 #define YYPURE 0
54
55 /* Push parsers. */
56 #define YYPUSH 0
57
58 /* Pull parsers. */
59 #define YYPULL 1
60
61
62
63
64 /* Copy the first part of user declarations. */
65 #line 21 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:339 */
66
67 #include "config.h"
68
69 #include "bashtypes.h"
70 #include "bashansi.h"
71
72 #include "filecntl.h"
73
74 #if defined (HAVE_UNISTD_H)
75 # include <unistd.h>
76 #endif
77
78 #if defined (HAVE_LOCALE_H)
79 # include <locale.h>
80 #endif
81
82 #include <stdio.h>
83 #include "chartypes.h"
84 #include <signal.h>
85
86 #include "memalloc.h"
87
88 #include "bashintl.h"
89
90 #define NEED_STRFTIME_DECL /* used in externs.h */
91
92 #include "shell.h"
93 #include "typemax.h" /* SIZE_MAX if needed */
94 #include "trap.h"
95 #include "flags.h"
96 #include "parser.h"
97 #include "mailcheck.h"
98 #include "test.h"
99 #include "builtins.h"
100 #include "builtins/common.h"
101 #include "builtins/builtext.h"
102
103 #include "shmbutil.h"
104
105 #if defined (READLINE)
106 # include "bashline.h"
107 # include <readline/readline.h>
108 #endif /* READLINE */
109
110 #if defined (HISTORY)
111 # include "bashhist.h"
112 # include <readline/history.h>
113 #endif /* HISTORY */
114
115 #if defined (JOB_CONTROL)
116 # include "jobs.h"
117 #else
118 extern int cleanup_dead_jobs __P((void));
119 #endif /* JOB_CONTROL */
120
121 #if defined (ALIAS)
122 # include "alias.h"
123 #else
124 typedef void *alias_t;
125 #endif /* ALIAS */
126
127 #if defined (PROMPT_STRING_DECODE)
128 # ifndef _MINIX
129 # include <sys/param.h>
130 # endif
131 # include <time.h>
132 # if defined (TM_IN_SYS_TIME)
133 # include <sys/types.h>
134 # include <sys/time.h>
135 # endif /* TM_IN_SYS_TIME */
136 # include "maxpath.h"
137 #endif /* PROMPT_STRING_DECODE */
138
139 #define RE_READ_TOKEN -99
140 #define NO_EXPANSION -100
141
142 #ifdef DEBUG
143 # define YYDEBUG 1
144 #else
145 # define YYDEBUG 0
146 #endif
147
148 #if defined (HANDLE_MULTIBYTE)
149 # define last_shell_getc_is_singlebyte \
150 ((shell_input_line_index > 1) \
151 ? shell_input_line_property[shell_input_line_index - 1] \
152 : 1)
153 # define MBTEST(x) ((x) && last_shell_getc_is_singlebyte)
154 #else
155 # define last_shell_getc_is_singlebyte 1
156 # define MBTEST(x) ((x))
157 #endif
158
159 #if defined (EXTENDED_GLOB)
160 extern int extended_glob;
161 #endif
162
163 extern int eof_encountered;
164 extern int no_line_editing, running_under_emacs;
165 extern int current_command_number;
166 extern int sourcelevel, parse_and_execute_level;
167 extern int posixly_correct;
168 extern int last_command_exit_value;
169 extern pid_t last_command_subst_pid;
170 extern char *shell_name, *current_host_name;
171 extern char *dist_version;
172 extern int patch_level;
173 extern int dump_translatable_strings, dump_po_strings;
174 extern sh_builtin_func_t *last_shell_builtin, *this_shell_builtin;
175 extern int here_doc_first_line;
176 #if defined (BUFFERED_INPUT)
177 extern int bash_input_fd_changed;
178 #endif
179
180 extern int errno;
181 /* **************************************************************** */
182 /* */
183 /* "Forward" declarations */
184 /* */
185 /* **************************************************************** */
186
187 #ifdef DEBUG
188 static void debug_parser __P((int));
189 #endif
190
191 static int yy_getc __P((void));
192 static int yy_ungetc __P((int));
193
194 #if defined (READLINE)
195 static int yy_readline_get __P((void));
196 static int yy_readline_unget __P((int));
197 #endif
198
199 static int yy_string_get __P((void));
200 static int yy_string_unget __P((int));
201 static void rewind_input_string __P((void));
202 static int yy_stream_get __P((void));
203 static int yy_stream_unget __P((int));
204
205 static int shell_getc __P((int));
206 static void shell_ungetc __P((int));
207 static void discard_until __P((int));
208
209 #if defined (ALIAS) || defined (DPAREN_ARITHMETIC)
210 static void push_string __P((char *, int, alias_t *));
211 static void pop_string __P((void));
212 static void free_string_list __P((void));
213 #endif
214
215 static char *read_a_line __P((int));
216
217 static int reserved_word_acceptable __P((int));
218 static int yylex __P((void));
219
220 static void push_heredoc __P((REDIRECT *));
221 static char *mk_alexpansion __P((char *));
222 static int alias_expand_token __P((char *));
223 static int time_command_acceptable __P((void));
224 static int special_case_tokens __P((char *));
225 static int read_token __P((int));
226 static char *parse_matched_pair __P((int, int, int, int *, int));
227 static char *parse_comsub __P((int, int, int, int *, int));
228 #if defined (ARRAY_VARS)
229 static char *parse_compound_assignment __P((int *));
230 #endif
231 #if defined (DPAREN_ARITHMETIC) || defined (ARITH_FOR_COMMAND)
232 static int parse_dparen __P((int));
233 static int parse_arith_cmd __P((char **, int));
234 #endif
235 #if defined (COND_COMMAND)
236 static void cond_error __P((void));
237 static COND_COM *cond_expr __P((void));
238 static COND_COM *cond_or __P((void));
239 static COND_COM *cond_and __P((void));
240 static COND_COM *cond_term __P((void));
241 static int cond_skip_newlines __P((void));
242 static COMMAND *parse_cond_command __P((void));
243 #endif
244 #if defined (ARRAY_VARS)
245 static int token_is_assignment __P((char *, int));
246 static int token_is_ident __P((char *, int));
247 #endif
248 static int read_token_word __P((int));
249 static void discard_parser_constructs __P((int));
250
251 static char *error_token_from_token __P((int));
252 static char *error_token_from_text __P((void));
253 static void print_offending_line __P((void));
254 static void report_syntax_error __P((char *));
255
256 static void handle_eof_input_unit __P((void));
257 static void prompt_again __P((void));
258 #if 0
259 static void reset_readline_prompt __P((void));
260 #endif
261 static void print_prompt __P((void));
262
263 #if defined (HANDLE_MULTIBYTE)
264 static void set_line_mbstate __P((void));
265 static char *shell_input_line_property = NULL;
266 #else
267 # define set_line_mbstate()
268 #endif
269
270 extern int yyerror __P((const char *));
271
272 #ifdef DEBUG
273 extern int yydebug;
274 #endif
275
276 /* Default prompt strings */
277 char *primary_prompt = PPROMPT;
278 char *secondary_prompt = SPROMPT;
279
280 /* PROMPT_STRING_POINTER points to one of these, never to an actual string. */
281 char *ps1_prompt, *ps2_prompt;
282
283 /* Displayed after reading a command but before executing it in an interactive shell */
284 char *ps0_prompt;
285
286 /* Handle on the current prompt string. Indirectly points through
287 ps1_ or ps2_prompt. */
288 char **prompt_string_pointer = (char **)NULL;
289 char *current_prompt_string;
290
291 /* Non-zero means we expand aliases in commands. */
292 int expand_aliases = 0;
293
294 /* If non-zero, the decoded prompt string undergoes parameter and
295 variable substitution, command substitution, arithmetic substitution,
296 string expansion, process substitution, and quote removal in
297 decode_prompt_string. */
298 int promptvars = 1;
299
300 /* If non-zero, $'...' and $"..." are expanded when they appear within
301 a ${...} expansion, even when the expansion appears within double
302 quotes. */
303 int extended_quote = 1;
304
305 /* The number of lines read from input while creating the current command. */
306 int current_command_line_count;
307
308 /* The number of lines in a command saved while we run parse_and_execute */
309 int saved_command_line_count;
310
311 /* The token that currently denotes the end of parse. */
312 int shell_eof_token;
313
314 /* The token currently being read. */
315 int current_token;
316
317 /* The current parser state. */
318 int parser_state;
319
320 /* Variables to manage the task of reading here documents, because we need to
321 defer the reading until after a complete command has been collected. */
322 static REDIRECT *redir_stack[HEREDOC_MAX];
323 int need_here_doc;
324
325 /* Where shell input comes from. History expansion is performed on each
326 line when the shell is interactive. */
327 static char *shell_input_line = (char *)NULL;
328 static size_t shell_input_line_index;
329 static size_t shell_input_line_size; /* Amount allocated for shell_input_line. */
330 static size_t shell_input_line_len; /* strlen (shell_input_line) */
331
332 /* Either zero or EOF. */
333 static int shell_input_line_terminator;
334
335 /* The line number in a script on which a function definition starts. */
336 static int function_dstart;
337
338 /* The line number in a script on which a function body starts. */
339 static int function_bstart;
340
341 /* The line number in a script at which an arithmetic for command starts. */
342 static int arith_for_lineno;
343
344 /* The decoded prompt string. Used if READLINE is not defined or if
345 editing is turned off. Analogous to current_readline_prompt. */
346 static char *current_decoded_prompt;
347
348 /* The last read token, or NULL. read_token () uses this for context
349 checking. */
350 static int last_read_token;
351
352 /* The token read prior to last_read_token. */
353 static int token_before_that;
354
355 /* The token read prior to token_before_that. */
356 static int two_tokens_ago;
357
358 static int global_extglob;
359
360 /* The line number in a script where the word in a `case WORD', `select WORD'
361 or `for WORD' begins. This is a nested command maximum, since the array
362 index is decremented after a case, select, or for command is parsed. */
363 #define MAX_CASE_NEST 128
364 static int word_lineno[MAX_CASE_NEST+1];
365 static int word_top = -1;
366
367 /* If non-zero, it is the token that we want read_token to return
368 regardless of what text is (or isn't) present to be read. This
369 is reset by read_token. If token_to_read == WORD or
370 ASSIGNMENT_WORD, yylval.word should be set to word_desc_to_read. */
371 static int token_to_read;
372 static WORD_DESC *word_desc_to_read;
373
374 static REDIRECTEE source;
375 static REDIRECTEE redir;
376
377 #line 378 "y.tab.c" /* yacc.c:339 */
378
379 # ifndef YY_NULLPTR
380 # if defined __cplusplus && 201103L <= __cplusplus
381 # define YY_NULLPTR nullptr
382 # else
383 # define YY_NULLPTR 0
384 # endif
385 # endif
386
387 /* Enabling verbose error messages. */
388 #ifdef YYERROR_VERBOSE
389 # undef YYERROR_VERBOSE
390 # define YYERROR_VERBOSE 1
391 #else
392 # define YYERROR_VERBOSE 0
393 #endif
394
395 /* In a future release of Bison, this section will be replaced
396 by #include "y.tab.h". */
397 #ifndef YY_YY_Y_TAB_H_INCLUDED
398 # define YY_YY_Y_TAB_H_INCLUDED
399 /* Debug traces. */
400 #ifndef YYDEBUG
401 # define YYDEBUG 0
402 #endif
403 #if YYDEBUG
404 extern int yydebug;
405 #endif
406
407 /* Token type. */
408 #ifndef YYTOKENTYPE
409 # define YYTOKENTYPE
410 enum yytokentype
411 {
412 IF = 258,
413 THEN = 259,
414 ELSE = 260,
415 ELIF = 261,
416 FI = 262,
417 CASE = 263,
418 ESAC = 264,
419 FOR = 265,
420 SELECT = 266,
421 WHILE = 267,
422 UNTIL = 268,
423 DO = 269,
424 DONE = 270,
425 FUNCTION = 271,
426 COPROC = 272,
427 COND_START = 273,
428 COND_END = 274,
429 COND_ERROR = 275,
430 IN = 276,
431 BANG = 277,
432 TIME = 278,
433 TIMEOPT = 279,
434 TIMEIGN = 280,
435 WORD = 281,
436 ASSIGNMENT_WORD = 282,
437 REDIR_WORD = 283,
438 NUMBER = 284,
439 ARITH_CMD = 285,
440 ARITH_FOR_EXPRS = 286,
441 COND_CMD = 287,
442 AND_AND = 288,
443 OR_OR = 289,
444 GREATER_GREATER = 290,
445 LESS_LESS = 291,
446 LESS_AND = 292,
447 LESS_LESS_LESS = 293,
448 GREATER_AND = 294,
449 SEMI_SEMI = 295,
450 SEMI_AND = 296,
451 SEMI_SEMI_AND = 297,
452 LESS_LESS_MINUS = 298,
453 AND_GREATER = 299,
454 AND_GREATER_GREATER = 300,
455 LESS_GREATER = 301,
456 GREATER_BAR = 302,
457 BAR_AND = 303,
458 yacc_EOF = 304
459 };
460 #endif
461 /* Tokens. */
462 #define IF 258
463 #define THEN 259
464 #define ELSE 260
465 #define ELIF 261
466 #define FI 262
467 #define CASE 263
468 #define ESAC 264
469 #define FOR 265
470 #define SELECT 266
471 #define WHILE 267
472 #define UNTIL 268
473 #define DO 269
474 #define DONE 270
475 #define FUNCTION 271
476 #define COPROC 272
477 #define COND_START 273
478 #define COND_END 274
479 #define COND_ERROR 275
480 #define IN 276
481 #define BANG 277
482 #define TIME 278
483 #define TIMEOPT 279
484 #define TIMEIGN 280
485 #define WORD 281
486 #define ASSIGNMENT_WORD 282
487 #define REDIR_WORD 283
488 #define NUMBER 284
489 #define ARITH_CMD 285
490 #define ARITH_FOR_EXPRS 286
491 #define COND_CMD 287
492 #define AND_AND 288
493 #define OR_OR 289
494 #define GREATER_GREATER 290
495 #define LESS_LESS 291
496 #define LESS_AND 292
497 #define LESS_LESS_LESS 293
498 #define GREATER_AND 294
499 #define SEMI_SEMI 295
500 #define SEMI_AND 296
501 #define SEMI_SEMI_AND 297
502 #define LESS_LESS_MINUS 298
503 #define AND_GREATER 299
504 #define AND_GREATER_GREATER 300
505 #define LESS_GREATER 301
506 #define GREATER_BAR 302
507 #define BAR_AND 303
508 #define yacc_EOF 304
509
510 /* Value type. */
511 #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
512
513 union YYSTYPE
514 {
515 #line 333 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:355 */
516
517 WORD_DESC *word; /* the word that we read. */
518 int number; /* the number that we read. */
519 WORD_LIST *word_list;
520 COMMAND *command;
521 REDIRECT *redirect;
522 ELEMENT element;
523 PATTERN_LIST *pattern;
524
525 #line 526 "y.tab.c" /* yacc.c:355 */
526 };
527
528 typedef union YYSTYPE YYSTYPE;
529 # define YYSTYPE_IS_TRIVIAL 1
530 # define YYSTYPE_IS_DECLARED 1
531 #endif
532
533
534 extern YYSTYPE yylval;
535
536 int yyparse (void);
537
538 #endif /* !YY_YY_Y_TAB_H_INCLUDED */
539
540 /* Copy the second part of user declarations. */
541
542 #line 543 "y.tab.c" /* yacc.c:358 */
543
544 #ifdef short
545 # undef short
546 #endif
547
548 #ifdef YYTYPE_UINT8
549 typedef YYTYPE_UINT8 yytype_uint8;
550 #else
551 typedef unsigned char yytype_uint8;
552 #endif
553
554 #ifdef YYTYPE_INT8
555 typedef YYTYPE_INT8 yytype_int8;
556 #else
557 typedef signed char yytype_int8;
558 #endif
559
560 #ifdef YYTYPE_UINT16
561 typedef YYTYPE_UINT16 yytype_uint16;
562 #else
563 typedef unsigned short int yytype_uint16;
564 #endif
565
566 #ifdef YYTYPE_INT16
567 typedef YYTYPE_INT16 yytype_int16;
568 #else
569 typedef short int yytype_int16;
570 #endif
571
572 #ifndef YYSIZE_T
573 # ifdef __SIZE_TYPE__
574 # define YYSIZE_T __SIZE_TYPE__
575 # elif defined size_t
576 # define YYSIZE_T size_t
577 # elif ! defined YYSIZE_T
578 # include <stddef.h> /* INFRINGES ON USER NAME SPACE */
579 # define YYSIZE_T size_t
580 # else
581 # define YYSIZE_T unsigned int
582 # endif
583 #endif
584
585 #define YYSIZE_MAXIMUM ((YYSIZE_T) -1)
586
587 #ifndef YY_
588 # if defined YYENABLE_NLS && YYENABLE_NLS
589 # if ENABLE_NLS
590 # include <libintl.h> /* INFRINGES ON USER NAME SPACE */
591 # define YY_(Msgid) dgettext ("bison-runtime", Msgid)
592 # endif
593 # endif
594 # ifndef YY_
595 # define YY_(Msgid) Msgid
596 # endif
597 #endif
598
599 #ifndef YY_ATTRIBUTE
600 # if (defined __GNUC__ \
601 && (2 < __GNUC__ || (__GNUC__ == 2 && 96 <= __GNUC_MINOR__))) \
602 || defined __SUNPRO_C && 0x5110 <= __SUNPRO_C
603 # define YY_ATTRIBUTE(Spec) __attribute__(Spec)
604 # else
605 # define YY_ATTRIBUTE(Spec) /* empty */
606 # endif
607 #endif
608
609 #ifndef YY_ATTRIBUTE_PURE
610 # define YY_ATTRIBUTE_PURE YY_ATTRIBUTE ((__pure__))
611 #endif
612
613 #ifndef YY_ATTRIBUTE_UNUSED
614 # define YY_ATTRIBUTE_UNUSED YY_ATTRIBUTE ((__unused__))
615 #endif
616
617 #if !defined _Noreturn \
618 && (!defined __STDC_VERSION__ || __STDC_VERSION__ < 201112)
619 # if defined _MSC_VER && 1200 <= _MSC_VER
620 # define _Noreturn __declspec (noreturn)
621 # else
622 # define _Noreturn YY_ATTRIBUTE ((__noreturn__))
623 # endif
624 #endif
625
626 /* Suppress unused-variable warnings by "using" E. */
627 #if ! defined lint || defined __GNUC__
628 # define YYUSE(E) ((void) (E))
629 #else
630 # define YYUSE(E) /* empty */
631 #endif
632
633 #if defined __GNUC__ && 407 <= __GNUC__ * 100 + __GNUC_MINOR__
634 /* Suppress an incorrect diagnostic about yylval being uninitialized. */
635 # define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \
636 _Pragma ("GCC diagnostic push") \
637 _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"")\
638 _Pragma ("GCC diagnostic ignored \"-Wmaybe-uninitialized\"")
639 # define YY_IGNORE_MAYBE_UNINITIALIZED_END \
640 _Pragma ("GCC diagnostic pop")
641 #else
642 # define YY_INITIAL_VALUE(Value) Value
643 #endif
644 #ifndef YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
645 # define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
646 # define YY_IGNORE_MAYBE_UNINITIALIZED_END
647 #endif
648 #ifndef YY_INITIAL_VALUE
649 # define YY_INITIAL_VALUE(Value) /* Nothing. */
650 #endif
651
652
653 #if ! defined yyoverflow || YYERROR_VERBOSE
654
655 /* The parser invokes alloca or malloc; define the necessary symbols. */
656
657 # ifdef YYSTACK_USE_ALLOCA
658 # if YYSTACK_USE_ALLOCA
659 # ifdef __GNUC__
660 # define YYSTACK_ALLOC __builtin_alloca
661 # elif defined __BUILTIN_VA_ARG_INCR
662 # include <alloca.h> /* INFRINGES ON USER NAME SPACE */
663 # elif defined _AIX
664 # define YYSTACK_ALLOC __alloca
665 # elif defined _MSC_VER
666 # include <malloc.h> /* INFRINGES ON USER NAME SPACE */
667 # define alloca _alloca
668 # else
669 # define YYSTACK_ALLOC alloca
670 # if ! defined _ALLOCA_H && ! defined EXIT_SUCCESS
671 # include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
672 /* Use EXIT_SUCCESS as a witness for stdlib.h. */
673 # ifndef EXIT_SUCCESS
674 # define EXIT_SUCCESS 0
675 # endif
676 # endif
677 # endif
678 # endif
679 # endif
680
681 # ifdef YYSTACK_ALLOC
682 /* Pacify GCC's 'empty if-body' warning. */
683 # define YYSTACK_FREE(Ptr) do { /* empty */; } while (0)
684 # ifndef YYSTACK_ALLOC_MAXIMUM
685 /* The OS might guarantee only one guard page at the bottom of the stack,
686 and a page size can be as small as 4096 bytes. So we cannot safely
687 invoke alloca (N) if N exceeds 4096. Use a slightly smaller number
688 to allow for a few compiler-allocated temporary stack slots. */
689 # define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */
690 # endif
691 # else
692 # define YYSTACK_ALLOC YYMALLOC
693 # define YYSTACK_FREE YYFREE
694 # ifndef YYSTACK_ALLOC_MAXIMUM
695 # define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM
696 # endif
697 # if (defined __cplusplus && ! defined EXIT_SUCCESS \
698 && ! ((defined YYMALLOC || defined malloc) \
699 && (defined YYFREE || defined free)))
700 # include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
701 # ifndef EXIT_SUCCESS
702 # define EXIT_SUCCESS 0
703 # endif
704 # endif
705 # ifndef YYMALLOC
706 # define YYMALLOC malloc
707 # if ! defined malloc && ! defined EXIT_SUCCESS
708 void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */
709 # endif
710 # endif
711 # ifndef YYFREE
712 # define YYFREE free
713 # if ! defined free && ! defined EXIT_SUCCESS
714 void free (void *); /* INFRINGES ON USER NAME SPACE */
715 # endif
716 # endif
717 # endif
718 #endif /* ! defined yyoverflow || YYERROR_VERBOSE */
719
720
721 #if (! defined yyoverflow \
722 && (! defined __cplusplus \
723 || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
724
725 /* A type that is properly aligned for any stack member. */
726 union yyalloc
727 {
728 yytype_int16 yyss_alloc;
729 YYSTYPE yyvs_alloc;
730 };
731
732 /* The size of the maximum gap between one aligned stack and the next. */
733 # define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1)
734
735 /* The size of an array large to enough to hold all stacks, each with
736 N elements. */
737 # define YYSTACK_BYTES(N) \
738 ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE)) \
739 + YYSTACK_GAP_MAXIMUM)
740
741 # define YYCOPY_NEEDED 1
742
743 /* Relocate STACK from its old location to the new one. The
744 local variables YYSIZE and YYSTACKSIZE give the old and new number of
745 elements in the stack, and YYPTR gives the new location of the
746 stack. Advance YYPTR to a properly aligned location for the next
747 stack. */
748 # define YYSTACK_RELOCATE(Stack_alloc, Stack) \
749 do \
750 { \
751 YYSIZE_T yynewbytes; \
752 YYCOPY (&yyptr->Stack_alloc, Stack, yysize); \
753 Stack = &yyptr->Stack_alloc; \
754 yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \
755 yyptr += yynewbytes / sizeof (*yyptr); \
756 } \
757 while (0)
758
759 #endif
760
761 #if defined YYCOPY_NEEDED && YYCOPY_NEEDED
762 /* Copy COUNT objects from SRC to DST. The source and destination do
763 not overlap. */
764 # ifndef YYCOPY
765 # if defined __GNUC__ && 1 < __GNUC__
766 # define YYCOPY(Dst, Src, Count) \
767 __builtin_memcpy (Dst, Src, (Count) * sizeof (*(Src)))
768 # else
769 # define YYCOPY(Dst, Src, Count) \
770 do \
771 { \
772 YYSIZE_T yyi; \
773 for (yyi = 0; yyi < (Count); yyi++) \
774 (Dst)[yyi] = (Src)[yyi]; \
775 } \
776 while (0)
777 # endif
778 # endif
779 #endif /* !YYCOPY_NEEDED */
780
781 /* YYFINAL -- State number of the termination state. */
782 #define YYFINAL 116
783 /* YYLAST -- Last index in YYTABLE. */
784 #define YYLAST 638
785
786 /* YYNTOKENS -- Number of terminals. */
787 #define YYNTOKENS 61
788 /* YYNNTS -- Number of nonterminals. */
789 #define YYNNTS 38
790 /* YYNRULES -- Number of rules. */
791 #define YYNRULES 167
792 /* YYNSTATES -- Number of states. */
793 #define YYNSTATES 334
794
795 /* YYTRANSLATE[YYX] -- Symbol number corresponding to YYX as returned
796 by yylex, with out-of-bounds checking. */
797 #define YYUNDEFTOK 2
798 #define YYMAXUTOK 304
799
800 #define YYTRANSLATE(YYX) \
801 ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
802
803 /* YYTRANSLATE[TOKEN-NUM] -- Symbol number corresponding to TOKEN-NUM
804 as returned by yylex, without out-of-bounds checking. */
805 static const yytype_uint8 yytranslate[] =
806 {
807 0, 2, 2, 2, 2, 2, 2, 2, 2, 2,
808 51, 2, 2, 2, 2, 2, 2, 2, 2, 2,
809 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
810 2, 2, 2, 2, 2, 2, 2, 2, 49, 2,
811 59, 60, 2, 2, 2, 56, 2, 2, 2, 2,
812 2, 2, 2, 2, 2, 2, 2, 2, 2, 50,
813 55, 2, 54, 2, 2, 2, 2, 2, 2, 2,
814 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
815 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
816 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
817 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
818 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
819 2, 2, 2, 57, 53, 58, 2, 2, 2, 2,
820 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
821 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
822 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
823 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
824 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
825 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
826 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
827 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
828 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
829 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
830 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
831 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
832 2, 2, 2, 2, 2, 2, 1, 2, 3, 4,
833 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
834 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
835 25, 26, 27, 28, 29, 30, 31, 32, 33, 34,
836 35, 36, 37, 38, 39, 40, 41, 42, 43, 44,
837 45, 46, 47, 48, 52
838 };
839
840 #if YYDEBUG
841 /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */
842 static const yytype_uint16 yyrline[] =
843 {
844 0, 386, 386, 397, 406, 421, 431, 433, 437, 443,
845 449, 455, 461, 467, 473, 479, 485, 491, 497, 503,
846 509, 515, 521, 527, 534, 541, 548, 555, 562, 569,
847 575, 581, 587, 593, 599, 605, 611, 617, 623, 629,
848 635, 641, 647, 653, 659, 665, 671, 677, 683, 689,
849 695, 701, 709, 711, 713, 717, 721, 732, 734, 738,
850 740, 742, 758, 760, 764, 766, 768, 770, 772, 774,
851 776, 778, 780, 782, 784, 788, 793, 798, 803, 808,
852 813, 818, 823, 830, 835, 840, 845, 852, 857, 862,
853 867, 872, 877, 884, 889, 894, 901, 904, 907, 911,
854 913, 944, 951, 956, 973, 978, 995, 1002, 1004, 1006,
855 1011, 1015, 1019, 1023, 1025, 1027, 1031, 1032, 1036, 1038,
856 1040, 1042, 1046, 1048, 1050, 1052, 1054, 1056, 1060, 1062,
857 1071, 1079, 1080, 1086, 1087, 1094, 1098, 1100, 1102, 1109,
858 1111, 1113, 1117, 1118, 1121, 1123, 1125, 1129, 1130, 1139,
859 1152, 1168, 1183, 1185, 1187, 1194, 1197, 1201, 1203, 1209,
860 1215, 1234, 1256, 1258, 1281, 1285, 1287, 1289
861 };
862 #endif
863
864 #if YYDEBUG || YYERROR_VERBOSE || 0
865 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
866 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
867 static const char *const yytname[] =
868 {
869 "$end", "error", "$undefined", "IF", "THEN", "ELSE", "ELIF", "FI",
870 "CASE", "ESAC", "FOR", "SELECT", "WHILE", "UNTIL", "DO", "DONE",
871 "FUNCTION", "COPROC", "COND_START", "COND_END", "COND_ERROR", "IN",
872 "BANG", "TIME", "TIMEOPT", "TIMEIGN", "WORD", "ASSIGNMENT_WORD",
873 "REDIR_WORD", "NUMBER", "ARITH_CMD", "ARITH_FOR_EXPRS", "COND_CMD",
874 "AND_AND", "OR_OR", "GREATER_GREATER", "LESS_LESS", "LESS_AND",
875 "LESS_LESS_LESS", "GREATER_AND", "SEMI_SEMI", "SEMI_AND",
876 "SEMI_SEMI_AND", "LESS_LESS_MINUS", "AND_GREATER", "AND_GREATER_GREATER",
877 "LESS_GREATER", "GREATER_BAR", "BAR_AND", "'&'", "';'", "'\\n'",
878 "yacc_EOF", "'|'", "'>'", "'<'", "'-'", "'{'", "'}'", "'('", "')'",
879 "$accept", "inputunit", "word_list", "redirection",
880 "simple_command_element", "redirection_list", "simple_command",
881 "command", "shell_command", "for_command", "arith_for_command",
882 "select_command", "case_command", "function_def", "function_body",
883 "subshell", "coproc", "if_command", "group_command", "arith_command",
884 "cond_command", "elif_clause", "case_clause", "pattern_list",
885 "case_clause_sequence", "pattern", "list", "compound_list", "list0",
886 "list1", "simple_list_terminator", "list_terminator", "newline_list",
887 "simple_list", "simple_list1", "pipeline_command", "pipeline",
888 "timespec", YY_NULLPTR
889 };
890 #endif
891
892 # ifdef YYPRINT
893 /* YYTOKNUM[NUM] -- (External) token number corresponding to the
894 (internal) symbol number NUM (which must be that of a token). */
895 static const yytype_uint16 yytoknum[] =
896 {
897 0, 256, 257, 258, 259, 260, 261, 262, 263, 264,
898 265, 266, 267, 268, 269, 270, 271, 272, 273, 274,
899 275, 276, 277, 278, 279, 280, 281, 282, 283, 284,
900 285, 286, 287, 288, 289, 290, 291, 292, 293, 294,
901 295, 296, 297, 298, 299, 300, 301, 302, 303, 38,
902 59, 10, 304, 124, 62, 60, 45, 123, 125, 40,
903 41
904 };
905 # endif
906
907 #define YYPACT_NINF -205
908
909 #define yypact_value_is_default(Yystate) \
910 (!!((Yystate) == (-205)))
911
912 #define YYTABLE_NINF -1
913
914 #define yytable_value_is_error(Yytable_value) \
915 0
916
917 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
918 STATE-NUM. */
919 static const yytype_int16 yypact[] =
920 {
921 308, -28, -205, 6, -1, 37, -205, -205, 57, 558,
922 18, 358, 54, 45, -205, 251, 583, -205, 102, 104,
923 35, 107, 80, 112, 127, 140, 146, 147, -205, -205,
924 153, 154, -205, -205, 188, -205, -205, 196, -205, 219,
925 -205, -205, -205, -205, -205, -205, -205, -205, -205, -205,
926 -205, 17, 23, -205, -19, 358, -205, -205, 185, 408,
927 -205, 144, 51, 166, 189, 207, 133, 28, 196, 219,
928 211, -205, -205, -205, -205, -205, 201, 184, 220, 226,
929 81, 227, 126, 233, 234, 241, 242, 245, 246, 249,
930 142, 255, 148, 256, 257, 259, 266, 267, -205, -205,
931 -205, -205, -205, -205, -205, -205, -205, -205, -205, -205,
932 -205, -205, -205, -205, 243, 240, -205, -205, -205, -205,
933 219, -205, -205, -205, -205, -205, 458, 458, -205, -205,
934 -205, -205, -205, -205, -205, 299, -205, 68, -205, 61,
935 -205, -205, -205, -205, 72, -205, -205, 244, 41, 219,
936 219, -205, -205, -205, -205, -205, -205, -205, -205, -205,
937 -205, -205, -205, -205, -205, -205, -205, -205, -205, -205,
938 -205, -205, -205, -205, -205, -205, -205, -205, -205, -205,
939 -205, -205, -205, -205, -205, 408, 408, 63, 63, 508,
940 508, 179, -205, -205, -205, -205, -205, -205, 60, -205,
941 155, -205, 287, 252, 74, 108, -205, 286, -205, 300,
942 302, -205, 219, -205, 219, 41, -205, -205, -19, -19,
943 -205, -205, -205, 307, 408, 408, 408, 408, 408, 313,
944 159, -205, -4, -205, -205, 312, -205, 161, -205, 265,
945 -205, -205, -205, -205, -205, -205, 314, 408, 161, 270,
946 -205, -205, 41, 219, -205, 332, 336, -205, -205, -205,
947 87, 87, 87, -205, -205, -205, -205, 178, 11, -205,
948 -205, 315, -43, 327, 298, -205, -205, -205, 110, -205,
949 342, 306, 343, 319, -205, 299, -205, -205, -205, -205,
950 -205, -205, -205, -205, -205, -32, 346, -205, -205, -205,
951 113, -205, -205, -205, -205, -205, -205, 118, 137, -205,
952 -205, -205, 408, -205, -205, 363, 321, -205, -205, -205,
953 -205, -205, 408, 367, 325, -205, -205, 374, 333, -205,
954 -205, -205, -205, -205
955 };
956
957 /* YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM.
958 Performed when YYTABLE does not specify something else to do. Zero
959 means the default is an error. */
960 static const yytype_uint8 yydefact[] =
961 {
962 0, 0, 147, 0, 0, 0, 147, 147, 0, 0,
963 0, 0, 165, 52, 53, 0, 0, 111, 0, 0,
964 0, 0, 0, 0, 0, 0, 0, 0, 3, 5,
965 0, 0, 147, 147, 0, 54, 57, 59, 164, 60,
966 64, 74, 68, 65, 62, 70, 63, 69, 71, 72,
967 73, 0, 149, 156, 157, 0, 4, 131, 0, 0,
968 147, 147, 0, 147, 0, 0, 147, 52, 106, 102,
969 0, 145, 144, 146, 161, 158, 166, 0, 0, 0,
970 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
971 0, 0, 0, 0, 0, 0, 0, 0, 14, 23,
972 38, 32, 47, 29, 41, 35, 44, 26, 50, 51,
973 20, 17, 8, 9, 0, 0, 1, 52, 58, 55,
974 61, 142, 143, 2, 147, 147, 150, 151, 147, 147,
975 160, 159, 147, 148, 130, 132, 141, 0, 147, 0,
976 147, 147, 147, 147, 0, 147, 147, 0, 0, 104,
977 103, 112, 167, 147, 16, 25, 40, 34, 49, 31,
978 43, 37, 46, 28, 22, 19, 12, 13, 15, 24,
979 39, 33, 48, 30, 42, 36, 45, 27, 21, 18,
980 10, 11, 110, 101, 56, 0, 0, 154, 155, 0,
981 0, 0, 147, 147, 147, 147, 147, 147, 0, 147,
982 0, 147, 0, 0, 0, 0, 147, 0, 147, 0,
983 0, 147, 99, 98, 105, 0, 152, 153, 163, 162,
984 147, 147, 107, 0, 0, 0, 134, 135, 133, 0,
985 116, 147, 0, 147, 147, 0, 6, 0, 147, 0,
986 85, 86, 147, 147, 147, 147, 0, 0, 0, 0,
987 66, 67, 0, 100, 96, 0, 0, 109, 136, 137,
988 138, 139, 140, 95, 122, 124, 126, 117, 0, 93,
989 128, 0, 0, 0, 0, 75, 7, 147, 0, 76,
990 0, 0, 0, 0, 87, 0, 147, 88, 97, 108,
991 147, 123, 125, 127, 94, 0, 0, 147, 77, 78,
992 0, 147, 147, 83, 84, 89, 90, 0, 113, 147,
993 129, 118, 119, 147, 147, 0, 0, 147, 147, 147,
994 115, 120, 121, 0, 0, 81, 82, 0, 0, 114,
995 79, 80, 91, 92
996 };
997
998 /* YYPGOTO[NTERM-NUM]. */
999 static const yytype_int16 yypgoto[] =
1000 {
1001 -205, -205, 183, -36, -23, -50, 364, -205, -7, -205,
1002 -205, -205, -205, -205, -204, -205, -205, -205, -205, -205,
1003 -205, 84, -205, 167, -205, 128, -202, -6, -205, 52,
1004 -205, -46, -48, -205, -119, 24, -33, -205
1005 };
1006
1007 /* YYDEFGOTO[NTERM-NUM]. */
1008 static const yytype_int16 yydefgoto[] =
1009 {
1010 -1, 34, 237, 35, 36, 120, 37, 38, 39, 40,
1011 41, 42, 43, 44, 213, 45, 46, 47, 48, 49,
1012 50, 223, 229, 230, 231, 272, 57, 58, 134, 135,
1013 123, 74, 59, 51, 52, 136, 54, 55
1014 };
1015
1016 /* YYTABLE[YYPACT[STATE-NUM]] -- What to do in state STATE-NUM. If
1017 positive, shift that token. If negative, reduce the rule whose
1018 number is the opposite. If YYTABLE_NINF, syntax error. */
1019 static const yytype_uint16 yytable[] =
1020 {
1021 64, 65, 69, 119, 246, 269, 249, 187, 188, 130,
1022 296, 254, 137, 139, 118, 144, 142, 297, 148, 150,
1023 294, 296, 270, 56, 53, 61, 114, 115, 309, 128,
1024 62, 2, 60, 119, 129, 75, 3, 270, 4, 5,
1025 6, 7, 282, 283, 2, 118, 10, 133, 288, 3,
1026 70, 4, 5, 6, 7, 271, 124, 125, 17, 10,
1027 149, 100, 133, 63, 101, 140, 216, 217, 121, 122,
1028 271, 17, 126, 127, 233, 199, 185, 186, 76, 131,
1029 189, 190, 200, 66, 184, 32, 206, 33, 242, 197,
1030 198, 102, 133, 207, 204, 205, 124, 125, 32, 214,
1031 33, 71, 72, 73, 77, 215, 104, 156, 141, 105,
1032 157, 133, 133, 119, 184, 327, 328, 234, 201, 133,
1033 192, 193, 244, 133, 301, 133, 191, 313, 98, 208,
1034 99, 243, 317, 103, 202, 203, 106, 158, 107, 209,
1035 210, 212, 319, 221, 224, 225, 226, 227, 228, 232,
1036 53, 53, 160, 108, 238, 161, 218, 219, 247, 133,
1037 247, 133, 253, 252, 133, 245, 109, 302, 170, 133,
1038 314, 171, 110, 111, 174, 318, 119, 175, 184, 112,
1039 113, 236, 162, 268, 220, 221, 222, 276, 116, 132,
1040 278, 277, 147, 235, 138, 239, 247, 247, 172, 264,
1041 265, 266, 286, 145, 176, 71, 72, 73, 212, 53,
1042 53, 71, 72, 73, 255, 256, 143, 184, 291, 292,
1043 293, 146, 117, 14, 15, 16, 152, 273, 274, 300,
1044 151, 18, 19, 20, 21, 22, 280, 281, 307, 23,
1045 24, 25, 26, 27, 153, 212, 154, 15, 16, 312,
1046 30, 31, 155, 159, 18, 19, 20, 21, 22, 163,
1047 164, 322, 23, 24, 25, 26, 27, 165, 166, 247,
1048 247, 167, 168, 30, 31, 169, 258, 259, 260, 261,
1049 262, 173, 177, 178, 308, 179, 78, 79, 80, 81,
1050 82, 311, 180, 181, 83, 315, 316, 84, 85, 285,
1051 183, 182, 240, 321, 211, 86, 87, 323, 324, 1,
1052 241, 2, 236, 329, 257, 250, 3, 251, 4, 5,
1053 6, 7, 263, 279, 8, 9, 10, 275, 287, 284,
1054 11, 12, 192, 193, 13, 14, 15, 16, 17, 289,
1055 290, 270, 298, 18, 19, 20, 21, 22, 194, 195,
1056 196, 23, 24, 25, 26, 27, 299, 303, 305, 28,
1057 29, 2, 30, 31, 304, 32, 3, 33, 4, 5,
1058 6, 7, 310, 68, 8, 9, 10, 306, 325, 326,
1059 11, 12, 330, 331, 13, 14, 15, 16, 17, 332,
1060 248, 333, 320, 18, 19, 20, 21, 22, 267, 295,
1061 0, 23, 24, 25, 26, 27, 0, 0, 71, 72,
1062 73, 2, 30, 31, 0, 32, 3, 33, 4, 5,
1063 6, 7, 0, 0, 8, 9, 10, 0, 0, 0,
1064 11, 12, 0, 0, 13, 14, 15, 16, 17, 0,
1065 0, 0, 0, 18, 19, 20, 21, 22, 0, 0,
1066 0, 23, 24, 25, 26, 27, 0, 0, 0, 133,
1067 0, 2, 30, 31, 0, 32, 3, 33, 4, 5,
1068 6, 7, 0, 0, 8, 9, 10, 0, 0, 0,
1069 11, 12, 0, 0, 13, 14, 15, 16, 17, 0,
1070 0, 0, 0, 18, 19, 20, 21, 22, 0, 0,
1071 0, 23, 24, 25, 26, 27, 0, 0, 0, 0,
1072 0, 2, 30, 31, 0, 32, 3, 33, 4, 5,
1073 6, 7, 0, 0, 8, 9, 10, 0, 0, 0,
1074 0, 0, 0, 0, 13, 14, 15, 16, 17, 0,
1075 0, 0, 0, 18, 19, 20, 21, 22, 0, 0,
1076 0, 23, 24, 25, 26, 27, 0, 0, 0, 133,
1077 0, 2, 30, 31, 0, 32, 3, 33, 4, 5,
1078 6, 7, 0, 0, 0, 0, 10, 0, 0, 0,
1079 0, 0, 0, 0, 67, 14, 15, 16, 17, 0,
1080 0, 0, 0, 18, 19, 20, 21, 22, 0, 0,
1081 0, 23, 24, 25, 26, 27, 0, 0, 0, 0,
1082 0, 0, 30, 31, 0, 32, 0, 33, 88, 89,
1083 90, 91, 92, 0, 0, 0, 93, 0, 0, 94,
1084 95, 0, 0, 0, 0, 0, 0, 96, 97
1085 };
1086
1087 static const yytype_int16 yycheck[] =
1088 {
1089 6, 7, 9, 39, 206, 9, 208, 126, 127, 55,
1090 53, 215, 60, 61, 37, 63, 62, 60, 66, 69,
1091 9, 53, 26, 51, 0, 26, 32, 33, 60, 48,
1092 31, 3, 26, 69, 53, 11, 8, 26, 10, 11,
1093 12, 13, 244, 245, 3, 68, 18, 51, 252, 8,
1094 32, 10, 11, 12, 13, 59, 33, 34, 30, 18,
1095 67, 26, 51, 26, 29, 14, 185, 186, 51, 52,
1096 59, 30, 49, 50, 14, 14, 124, 125, 24, 55,
1097 128, 129, 21, 26, 120, 57, 14, 59, 14, 21,
1098 138, 56, 51, 21, 142, 143, 33, 34, 57, 149,
1099 59, 50, 51, 52, 59, 153, 26, 26, 57, 29,
1100 29, 51, 51, 149, 150, 317, 318, 57, 57, 51,
1101 33, 34, 14, 51, 14, 51, 132, 14, 26, 57,
1102 26, 57, 14, 26, 140, 141, 56, 56, 26, 145,
1103 146, 148, 5, 6, 192, 193, 194, 195, 196, 197,
1104 126, 127, 26, 26, 200, 29, 189, 190, 206, 51,
1105 208, 51, 212, 211, 51, 57, 26, 57, 26, 51,
1106 57, 29, 26, 26, 26, 57, 212, 29, 214, 26,
1107 26, 26, 56, 231, 5, 6, 7, 26, 0, 4,
1108 238, 237, 59, 199, 50, 201, 244, 245, 56, 40,
1109 41, 42, 248, 14, 56, 50, 51, 52, 215, 185,
1110 186, 50, 51, 52, 220, 221, 50, 253, 40, 41,
1111 42, 14, 26, 27, 28, 29, 25, 233, 234, 277,
1112 19, 35, 36, 37, 38, 39, 242, 243, 286, 43,
1113 44, 45, 46, 47, 60, 252, 26, 28, 29, 297,
1114 54, 55, 26, 26, 35, 36, 37, 38, 39, 26,
1115 26, 309, 43, 44, 45, 46, 47, 26, 26, 317,
1116 318, 26, 26, 54, 55, 26, 224, 225, 226, 227,
1117 228, 26, 26, 26, 290, 26, 35, 36, 37, 38,
1118 39, 297, 26, 26, 43, 301, 302, 46, 47, 247,
1119 60, 58, 15, 309, 60, 54, 55, 313, 314, 1,
1120 58, 3, 26, 319, 7, 15, 8, 15, 10, 11,
1121 12, 13, 9, 58, 16, 17, 18, 15, 58, 15,
1122 22, 23, 33, 34, 26, 27, 28, 29, 30, 7,
1123 4, 26, 15, 35, 36, 37, 38, 39, 49, 50,
1124 51, 43, 44, 45, 46, 47, 58, 15, 15, 51,
1125 52, 3, 54, 55, 58, 57, 8, 59, 10, 11,
1126 12, 13, 26, 9, 16, 17, 18, 58, 15, 58,
1127 22, 23, 15, 58, 26, 27, 28, 29, 30, 15,
1128 207, 58, 308, 35, 36, 37, 38, 39, 231, 271,
1129 -1, 43, 44, 45, 46, 47, -1, -1, 50, 51,
1130 52, 3, 54, 55, -1, 57, 8, 59, 10, 11,
1131 12, 13, -1, -1, 16, 17, 18, -1, -1, -1,
1132 22, 23, -1, -1, 26, 27, 28, 29, 30, -1,
1133 -1, -1, -1, 35, 36, 37, 38, 39, -1, -1,
1134 -1, 43, 44, 45, 46, 47, -1, -1, -1, 51,
1135 -1, 3, 54, 55, -1, 57, 8, 59, 10, 11,
1136 12, 13, -1, -1, 16, 17, 18, -1, -1, -1,
1137 22, 23, -1, -1, 26, 27, 28, 29, 30, -1,
1138 -1, -1, -1, 35, 36, 37, 38, 39, -1, -1,
1139 -1, 43, 44, 45, 46, 47, -1, -1, -1, -1,
1140 -1, 3, 54, 55, -1, 57, 8, 59, 10, 11,
1141 12, 13, -1, -1, 16, 17, 18, -1, -1, -1,
1142 -1, -1, -1, -1, 26, 27, 28, 29, 30, -1,
1143 -1, -1, -1, 35, 36, 37, 38, 39, -1, -1,
1144 -1, 43, 44, 45, 46, 47, -1, -1, -1, 51,
1145 -1, 3, 54, 55, -1, 57, 8, 59, 10, 11,
1146 12, 13, -1, -1, -1, -1, 18, -1, -1, -1,
1147 -1, -1, -1, -1, 26, 27, 28, 29, 30, -1,
1148 -1, -1, -1, 35, 36, 37, 38, 39, -1, -1,
1149 -1, 43, 44, 45, 46, 47, -1, -1, -1, -1,
1150 -1, -1, 54, 55, -1, 57, -1, 59, 35, 36,
1151 37, 38, 39, -1, -1, -1, 43, -1, -1, 46,
1152 47, -1, -1, -1, -1, -1, -1, 54, 55
1153 };
1154
1155 /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
1156 symbol of state STATE-NUM. */
1157 static const yytype_uint8 yystos[] =
1158 {
1159 0, 1, 3, 8, 10, 11, 12, 13, 16, 17,
1160 18, 22, 23, 26, 27, 28, 29, 30, 35, 36,
1161 37, 38, 39, 43, 44, 45, 46, 47, 51, 52,
1162 54, 55, 57, 59, 62, 64, 65, 67, 68, 69,
1163 70, 71, 72, 73, 74, 76, 77, 78, 79, 80,
1164 81, 94, 95, 96, 97, 98, 51, 87, 88, 93,
1165 26, 26, 31, 26, 88, 88, 26, 26, 67, 69,
1166 32, 50, 51, 52, 92, 96, 24, 59, 35, 36,
1167 37, 38, 39, 43, 46, 47, 54, 55, 35, 36,
1168 37, 38, 39, 43, 46, 47, 54, 55, 26, 26,
1169 26, 29, 56, 26, 26, 29, 56, 26, 26, 26,
1170 26, 26, 26, 26, 88, 88, 0, 26, 65, 64,
1171 66, 51, 52, 91, 33, 34, 49, 50, 48, 53,
1172 92, 96, 4, 51, 89, 90, 96, 93, 50, 93,
1173 14, 57, 92, 50, 93, 14, 14, 59, 93, 69,
1174 66, 19, 25, 60, 26, 26, 26, 29, 56, 26,
1175 26, 29, 56, 26, 26, 26, 26, 26, 26, 26,
1176 26, 29, 56, 26, 26, 29, 56, 26, 26, 26,
1177 26, 26, 58, 60, 64, 93, 93, 95, 95, 93,
1178 93, 88, 33, 34, 49, 50, 51, 21, 93, 14,
1179 21, 57, 88, 88, 93, 93, 14, 21, 57, 88,
1180 88, 60, 69, 75, 66, 93, 95, 95, 97, 97,
1181 5, 6, 7, 82, 93, 93, 93, 93, 93, 83,
1182 84, 85, 93, 14, 57, 88, 26, 63, 92, 88,
1183 15, 58, 14, 57, 14, 57, 87, 93, 63, 87,
1184 15, 15, 93, 66, 75, 88, 88, 7, 90, 90,
1185 90, 90, 90, 9, 40, 41, 42, 84, 93, 9,
1186 26, 59, 86, 88, 88, 15, 26, 92, 93, 58,
1187 88, 88, 87, 87, 15, 90, 92, 58, 75, 7,
1188 4, 40, 41, 42, 9, 86, 53, 60, 15, 58,
1189 93, 14, 57, 15, 58, 15, 58, 93, 88, 60,
1190 26, 88, 93, 14, 57, 88, 88, 14, 57, 5,
1191 82, 88, 93, 88, 88, 15, 58, 87, 87, 88,
1192 15, 58, 15, 58
1193 };
1194
1195 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
1196 static const yytype_uint8 yyr1[] =
1197 {
1198 0, 61, 62, 62, 62, 62, 63, 63, 64, 64,
1199 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
1200 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
1201 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
1202 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
1203 64, 64, 65, 65, 65, 66, 66, 67, 67, 68,
1204 68, 68, 68, 68, 69, 69, 69, 69, 69, 69,
1205 69, 69, 69, 69, 69, 70, 70, 70, 70, 70,
1206 70, 70, 70, 71, 71, 71, 71, 72, 72, 72,
1207 72, 72, 72, 73, 73, 73, 74, 74, 74, 75,
1208 75, 76, 77, 77, 77, 77, 77, 78, 78, 78,
1209 79, 80, 81, 82, 82, 82, 83, 83, 84, 84,
1210 84, 84, 85, 85, 85, 85, 85, 85, 86, 86,
1211 87, 88, 88, 89, 89, 89, 90, 90, 90, 90,
1212 90, 90, 91, 91, 92, 92, 92, 93, 93, 94,
1213 94, 94, 95, 95, 95, 95, 95, 96, 96, 96,
1214 96, 96, 97, 97, 97, 98, 98, 98
1215 };
1216
1217 /* YYR2[YYN] -- Number of symbols on the right hand side of rule YYN. */
1218 static const yytype_uint8 yyr2[] =
1219 {
1220 0, 2, 2, 1, 2, 1, 1, 2, 2, 2,
1221 3, 3, 3, 3, 2, 3, 3, 2, 3, 3,
1222 2, 3, 3, 2, 3, 3, 2, 3, 3, 2,
1223 3, 3, 2, 3, 3, 2, 3, 3, 2, 3,
1224 3, 2, 3, 3, 2, 3, 3, 2, 3, 3,
1225 2, 2, 1, 1, 1, 1, 2, 1, 2, 1,
1226 1, 2, 1, 1, 1, 1, 5, 5, 1, 1,
1227 1, 1, 1, 1, 1, 6, 6, 7, 7, 10,
1228 10, 9, 9, 7, 7, 5, 5, 6, 6, 7,
1229 7, 10, 10, 6, 7, 6, 5, 6, 4, 1,
1230 2, 3, 2, 3, 3, 4, 2, 5, 7, 6,
1231 3, 1, 3, 4, 6, 5, 1, 2, 4, 4,
1232 5, 5, 2, 3, 2, 3, 2, 3, 1, 3,
1233 2, 1, 2, 3, 3, 3, 4, 4, 4, 4,
1234 4, 1, 1, 1, 1, 1, 1, 0, 2, 1,
1235 2, 2, 4, 4, 3, 3, 1, 1, 2, 2,
1236 2, 2, 4, 4, 1, 1, 2, 3
1237 };
1238
1239
1240 #define yyerrok (yyerrstatus = 0)
1241 #define yyclearin (yychar = YYEMPTY)
1242 #define YYEMPTY (-2)
1243 #define YYEOF 0
1244
1245 #define YYACCEPT goto yyacceptlab
1246 #define YYABORT goto yyabortlab
1247 #define YYERROR goto yyerrorlab
1248
1249
1250 #define YYRECOVERING() (!!yyerrstatus)
1251
1252 #define YYBACKUP(Token, Value) \
1253 do \
1254 if (yychar == YYEMPTY) \
1255 { \
1256 yychar = (Token); \
1257 yylval = (Value); \
1258 YYPOPSTACK (yylen); \
1259 yystate = *yyssp; \
1260 goto yybackup; \
1261 } \
1262 else \
1263 { \
1264 yyerror (YY_("syntax error: cannot back up")); \
1265 YYERROR; \
1266 } \
1267 while (0)
1268
1269 /* Error token number */
1270 #define YYTERROR 1
1271 #define YYERRCODE 256
1272
1273
1274
1275 /* Enable debugging if requested. */
1276 #if YYDEBUG
1277
1278 # ifndef YYFPRINTF
1279 # include <stdio.h> /* INFRINGES ON USER NAME SPACE */
1280 # define YYFPRINTF fprintf
1281 # endif
1282
1283 # define YYDPRINTF(Args) \
1284 do { \
1285 if (yydebug) \
1286 YYFPRINTF Args; \
1287 } while (0)
1288
1289 /* This macro is provided for backward compatibility. */
1290 #ifndef YY_LOCATION_PRINT
1291 # define YY_LOCATION_PRINT(File, Loc) ((void) 0)
1292 #endif
1293
1294
1295 # define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
1296 do { \
1297 if (yydebug) \
1298 { \
1299 YYFPRINTF (stderr, "%s ", Title); \
1300 yy_symbol_print (stderr, \
1301 Type, Value); \
1302 YYFPRINTF (stderr, "\n"); \
1303 } \
1304 } while (0)
1305
1306
1307 /*----------------------------------------.
1308 | Print this symbol's value on YYOUTPUT. |
1309 `----------------------------------------*/
1310
1311 static void
1312 yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep)
1313 {
1314 FILE *yyo = yyoutput;
1315 YYUSE (yyo);
1316 if (!yyvaluep)
1317 return;
1318 # ifdef YYPRINT
1319 if (yytype < YYNTOKENS)
1320 YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep);
1321 # endif
1322 YYUSE (yytype);
1323 }
1324
1325
1326 /*--------------------------------.
1327 | Print this symbol on YYOUTPUT. |
1328 `--------------------------------*/
1329
1330 static void
1331 yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep)
1332 {
1333 YYFPRINTF (yyoutput, "%s %s (",
1334 yytype < YYNTOKENS ? "token" : "nterm", yytname[yytype]);
1335
1336 yy_symbol_value_print (yyoutput, yytype, yyvaluep);
1337 YYFPRINTF (yyoutput, ")");
1338 }
1339
1340 /*------------------------------------------------------------------.
1341 | yy_stack_print -- Print the state stack from its BOTTOM up to its |
1342 | TOP (included). |
1343 `------------------------------------------------------------------*/
1344
1345 static void
1346 yy_stack_print (yytype_int16 *yybottom, yytype_int16 *yytop)
1347 {
1348 YYFPRINTF (stderr, "Stack now");
1349 for (; yybottom <= yytop; yybottom++)
1350 {
1351 int yybot = *yybottom;
1352 YYFPRINTF (stderr, " %d", yybot);
1353 }
1354 YYFPRINTF (stderr, "\n");
1355 }
1356
1357 # define YY_STACK_PRINT(Bottom, Top) \
1358 do { \
1359 if (yydebug) \
1360 yy_stack_print ((Bottom), (Top)); \
1361 } while (0)
1362
1363
1364 /*------------------------------------------------.
1365 | Report that the YYRULE is going to be reduced. |
1366 `------------------------------------------------*/
1367
1368 static void
1369 yy_reduce_print (yytype_int16 *yyssp, YYSTYPE *yyvsp, int yyrule)
1370 {
1371 unsigned long int yylno = yyrline[yyrule];
1372 int yynrhs = yyr2[yyrule];
1373 int yyi;
1374 YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n",
1375 yyrule - 1, yylno);
1376 /* The symbols being reduced. */
1377 for (yyi = 0; yyi < yynrhs; yyi++)
1378 {
1379 YYFPRINTF (stderr, " $%d = ", yyi + 1);
1380 yy_symbol_print (stderr,
1381 yystos[yyssp[yyi + 1 - yynrhs]],
1382 &(yyvsp[(yyi + 1) - (yynrhs)])
1383 );
1384 YYFPRINTF (stderr, "\n");
1385 }
1386 }
1387
1388 # define YY_REDUCE_PRINT(Rule) \
1389 do { \
1390 if (yydebug) \
1391 yy_reduce_print (yyssp, yyvsp, Rule); \
1392 } while (0)
1393
1394 /* Nonzero means print parse trace. It is left uninitialized so that
1395 multiple parsers can coexist. */
1396 int yydebug;
1397 #else /* !YYDEBUG */
1398 # define YYDPRINTF(Args)
1399 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
1400 # define YY_STACK_PRINT(Bottom, Top)
1401 # define YY_REDUCE_PRINT(Rule)
1402 #endif /* !YYDEBUG */
1403
1404
1405 /* YYINITDEPTH -- initial size of the parser's stacks. */
1406 #ifndef YYINITDEPTH
1407 # define YYINITDEPTH 200
1408 #endif
1409
1410 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
1411 if the built-in stack extension method is used).
1412
1413 Do not make this value too large; the results are undefined if
1414 YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH)
1415 evaluated with infinite-precision integer arithmetic. */
1416
1417 #ifndef YYMAXDEPTH
1418 # define YYMAXDEPTH 10000
1419 #endif
1420
1421
1422 #if YYERROR_VERBOSE
1423
1424 # ifndef yystrlen
1425 # if defined __GLIBC__ && defined _STRING_H
1426 # define yystrlen strlen
1427 # else
1428 /* Return the length of YYSTR. */
1429 static YYSIZE_T
1430 yystrlen (const char *yystr)
1431 {
1432 YYSIZE_T yylen;
1433 for (yylen = 0; yystr[yylen]; yylen++)
1434 continue;
1435 return yylen;
1436 }
1437 # endif
1438 # endif
1439
1440 # ifndef yystpcpy
1441 # if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
1442 # define yystpcpy stpcpy
1443 # else
1444 /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
1445 YYDEST. */
1446 static char *
1447 yystpcpy (char *yydest, const char *yysrc)
1448 {
1449 char *yyd = yydest;
1450 const char *yys = yysrc;
1451
1452 while ((*yyd++ = *yys++) != '\0')
1453 continue;
1454
1455 return yyd - 1;
1456 }
1457 # endif
1458 # endif
1459
1460 # ifndef yytnamerr
1461 /* Copy to YYRES the contents of YYSTR after stripping away unnecessary
1462 quotes and backslashes, so that it's suitable for yyerror. The
1463 heuristic is that double-quoting is unnecessary unless the string
1464 contains an apostrophe, a comma, or backslash (other than
1465 backslash-backslash). YYSTR is taken from yytname. If YYRES is
1466 null, do not copy; instead, return the length of what the result
1467 would have been. */
1468 static YYSIZE_T
1469 yytnamerr (char *yyres, const char *yystr)
1470 {
1471 if (*yystr == '"')
1472 {
1473 YYSIZE_T yyn = 0;
1474 char const *yyp = yystr;
1475
1476 for (;;)
1477 switch (*++yyp)
1478 {
1479 case '\'':
1480 case ',':
1481 goto do_not_strip_quotes;
1482
1483 case '\\':
1484 if (*++yyp != '\\')
1485 goto do_not_strip_quotes;
1486 /* Fall through. */
1487 default:
1488 if (yyres)
1489 yyres[yyn] = *yyp;
1490 yyn++;
1491 break;
1492
1493 case '"':
1494 if (yyres)
1495 yyres[yyn] = '\0';
1496 return yyn;
1497 }
1498 do_not_strip_quotes: ;
1499 }
1500
1501 if (! yyres)
1502 return yystrlen (yystr);
1503
1504 return yystpcpy (yyres, yystr) - yyres;
1505 }
1506 # endif
1507
1508 /* Copy into *YYMSG, which is of size *YYMSG_ALLOC, an error message
1509 about the unexpected token YYTOKEN for the state stack whose top is
1510 YYSSP.
1511
1512 Return 0 if *YYMSG was successfully written. Return 1 if *YYMSG is
1513 not large enough to hold the message. In that case, also set
1514 *YYMSG_ALLOC to the required number of bytes. Return 2 if the
1515 required number of bytes is too large to store. */
1516 static int
1517 yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg,
1518 yytype_int16 *yyssp, int yytoken)
1519 {
1520 YYSIZE_T yysize0 = yytnamerr (YY_NULLPTR, yytname[yytoken]);
1521 YYSIZE_T yysize = yysize0;
1522 enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
1523 /* Internationalized format string. */
1524 const char *yyformat = YY_NULLPTR;
1525 /* Arguments of yyformat. */
1526 char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
1527 /* Number of reported tokens (one for the "unexpected", one per
1528 "expected"). */
1529 int yycount = 0;
1530
1531 /* There are many possibilities here to consider:
1532 - If this state is a consistent state with a default action, then
1533 the only way this function was invoked is if the default action
1534 is an error action. In that case, don't check for expected
1535 tokens because there are none.
1536 - The only way there can be no lookahead present (in yychar) is if
1537 this state is a consistent state with a default action. Thus,
1538 detecting the absence of a lookahead is sufficient to determine
1539 that there is no unexpected or expected token to report. In that
1540 case, just report a simple "syntax error".
1541 - Don't assume there isn't a lookahead just because this state is a
1542 consistent state with a default action. There might have been a
1543 previous inconsistent state, consistent state with a non-default
1544 action, or user semantic action that manipulated yychar.
1545 - Of course, the expected token list depends on states to have
1546 correct lookahead information, and it depends on the parser not
1547 to perform extra reductions after fetching a lookahead from the
1548 scanner and before detecting a syntax error. Thus, state merging
1549 (from LALR or IELR) and default reductions corrupt the expected
1550 token list. However, the list is correct for canonical LR with
1551 one exception: it will still contain any token that will not be
1552 accepted due to an error action in a later state.
1553 */
1554 if (yytoken != YYEMPTY)
1555 {
1556 int yyn = yypact[*yyssp];
1557 yyarg[yycount++] = yytname[yytoken];
1558 if (!yypact_value_is_default (yyn))
1559 {
1560 /* Start YYX at -YYN if negative to avoid negative indexes in
1561 YYCHECK. In other words, skip the first -YYN actions for
1562 this state because they are default actions. */
1563 int yyxbegin = yyn < 0 ? -yyn : 0;
1564 /* Stay within bounds of both yycheck and yytname. */
1565 int yychecklim = YYLAST - yyn + 1;
1566 int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
1567 int yyx;
1568
1569 for (yyx = yyxbegin; yyx < yyxend; ++yyx)
1570 if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR
1571 && !yytable_value_is_error (yytable[yyx + yyn]))
1572 {
1573 if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
1574 {
1575 yycount = 1;
1576 yysize = yysize0;
1577 break;
1578 }
1579 yyarg[yycount++] = yytname[yyx];
1580 {
1581 YYSIZE_T yysize1 = yysize + yytnamerr (YY_NULLPTR, yytname[yyx]);
1582 if (! (yysize <= yysize1
1583 && yysize1 <= YYSTACK_ALLOC_MAXIMUM))
1584 return 2;
1585 yysize = yysize1;
1586 }
1587 }
1588 }
1589 }
1590
1591 switch (yycount)
1592 {
1593 # define YYCASE_(N, S) \
1594 case N: \
1595 yyformat = S; \
1596 break
1597 YYCASE_(0, YY_("syntax error"));
1598 YYCASE_(1, YY_("syntax error, unexpected %s"));
1599 YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s"));
1600 YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s"));
1601 YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s"));
1602 YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"));
1603 # undef YYCASE_
1604 }
1605
1606 {
1607 YYSIZE_T yysize1 = yysize + yystrlen (yyformat);
1608 if (! (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM))
1609 return 2;
1610 yysize = yysize1;
1611 }
1612
1613 if (*yymsg_alloc < yysize)
1614 {
1615 *yymsg_alloc = 2 * yysize;
1616 if (! (yysize <= *yymsg_alloc
1617 && *yymsg_alloc <= YYSTACK_ALLOC_MAXIMUM))
1618 *yymsg_alloc = YYSTACK_ALLOC_MAXIMUM;
1619 return 1;
1620 }
1621
1622 /* Avoid sprintf, as that infringes on the user's name space.
1623 Don't have undefined behavior even if the translation
1624 produced a string with the wrong number of "%s"s. */
1625 {
1626 char *yyp = *yymsg;
1627 int yyi = 0;
1628 while ((*yyp = *yyformat) != '\0')
1629 if (*yyp == '%' && yyformat[1] == 's' && yyi < yycount)
1630 {
1631 yyp += yytnamerr (yyp, yyarg[yyi++]);
1632 yyformat += 2;
1633 }
1634 else
1635 {
1636 yyp++;
1637 yyformat++;
1638 }
1639 }
1640 return 0;
1641 }
1642 #endif /* YYERROR_VERBOSE */
1643
1644 /*-----------------------------------------------.
1645 | Release the memory associated to this symbol. |
1646 `-----------------------------------------------*/
1647
1648 static void
1649 yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep)
1650 {
1651 YYUSE (yyvaluep);
1652 if (!yymsg)
1653 yymsg = "Deleting";
1654 YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
1655
1656 YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
1657 YYUSE (yytype);
1658 YY_IGNORE_MAYBE_UNINITIALIZED_END
1659 }
1660
1661
1662
1663
1664 /* The lookahead symbol. */
1665 int yychar;
1666
1667 /* The semantic value of the lookahead symbol. */
1668 YYSTYPE yylval;
1669 /* Number of syntax errors so far. */
1670 int yynerrs;
1671
1672
1673 /*----------.
1674 | yyparse. |
1675 `----------*/
1676
1677 int
1678 yyparse (void)
1679 {
1680 int yystate;
1681 /* Number of tokens to shift before error messages enabled. */
1682 int yyerrstatus;
1683
1684 /* The stacks and their tools:
1685 'yyss': related to states.
1686 'yyvs': related to semantic values.
1687
1688 Refer to the stacks through separate pointers, to allow yyoverflow
1689 to reallocate them elsewhere. */
1690
1691 /* The state stack. */
1692 yytype_int16 yyssa[YYINITDEPTH];
1693 yytype_int16 *yyss;
1694 yytype_int16 *yyssp;
1695
1696 /* The semantic value stack. */
1697 YYSTYPE yyvsa[YYINITDEPTH];
1698 YYSTYPE *yyvs;
1699 YYSTYPE *yyvsp;
1700
1701 YYSIZE_T yystacksize;
1702
1703 int yyn;
1704 int yyresult;
1705 /* Lookahead token as an internal (translated) token number. */
1706 int yytoken = 0;
1707 /* The variables used to return semantic value and location from the
1708 action routines. */
1709 YYSTYPE yyval;
1710
1711 #if YYERROR_VERBOSE
1712 /* Buffer for error messages, and its allocated size. */
1713 char yymsgbuf[128];
1714 char *yymsg = yymsgbuf;
1715 YYSIZE_T yymsg_alloc = sizeof yymsgbuf;
1716 #endif
1717
1718 #define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N))
1719
1720 /* The number of symbols on the RHS of the reduced rule.
1721 Keep to zero when no symbol should be popped. */
1722 int yylen = 0;
1723
1724 yyssp = yyss = yyssa;
1725 yyvsp = yyvs = yyvsa;
1726 yystacksize = YYINITDEPTH;
1727
1728 YYDPRINTF ((stderr, "Starting parse\n"));
1729
1730 yystate = 0;
1731 yyerrstatus = 0;
1732 yynerrs = 0;
1733 yychar = YYEMPTY; /* Cause a token to be read. */
1734 goto yysetstate;
1735
1736 /*------------------------------------------------------------.
1737 | yynewstate -- Push a new state, which is found in yystate. |
1738 `------------------------------------------------------------*/
1739 yynewstate:
1740 /* In all cases, when you get here, the value and location stacks
1741 have just been pushed. So pushing a state here evens the stacks. */
1742 yyssp++;
1743
1744 yysetstate:
1745 *yyssp = yystate;
1746
1747 if (yyss + yystacksize - 1 <= yyssp)
1748 {
1749 /* Get the current used size of the three stacks, in elements. */
1750 YYSIZE_T yysize = yyssp - yyss + 1;
1751
1752 #ifdef yyoverflow
1753 {
1754 /* Give user a chance to reallocate the stack. Use copies of
1755 these so that the &'s don't force the real ones into
1756 memory. */
1757 YYSTYPE *yyvs1 = yyvs;
1758 yytype_int16 *yyss1 = yyss;
1759
1760 /* Each stack pointer address is followed by the size of the
1761 data in use in that stack, in bytes. This used to be a
1762 conditional around just the two extra args, but that might
1763 be undefined if yyoverflow is a macro. */
1764 yyoverflow (YY_("memory exhausted"),
1765 &yyss1, yysize * sizeof (*yyssp),
1766 &yyvs1, yysize * sizeof (*yyvsp),
1767 &yystacksize);
1768
1769 yyss = yyss1;
1770 yyvs = yyvs1;
1771 }
1772 #else /* no yyoverflow */
1773 # ifndef YYSTACK_RELOCATE
1774 goto yyexhaustedlab;
1775 # else
1776 /* Extend the stack our own way. */
1777 if (YYMAXDEPTH <= yystacksize)
1778 goto yyexhaustedlab;
1779 yystacksize *= 2;
1780 if (YYMAXDEPTH < yystacksize)
1781 yystacksize = YYMAXDEPTH;
1782
1783 {
1784 yytype_int16 *yyss1 = yyss;
1785 union yyalloc *yyptr =
1786 (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
1787 if (! yyptr)
1788 goto yyexhaustedlab;
1789 YYSTACK_RELOCATE (yyss_alloc, yyss);
1790 YYSTACK_RELOCATE (yyvs_alloc, yyvs);
1791 # undef YYSTACK_RELOCATE
1792 if (yyss1 != yyssa)
1793 YYSTACK_FREE (yyss1);
1794 }
1795 # endif
1796 #endif /* no yyoverflow */
1797
1798 yyssp = yyss + yysize - 1;
1799 yyvsp = yyvs + yysize - 1;
1800
1801 YYDPRINTF ((stderr, "Stack size increased to %lu\n",
1802 (unsigned long int) yystacksize));
1803
1804 if (yyss + yystacksize - 1 <= yyssp)
1805 YYABORT;
1806 }
1807
1808 YYDPRINTF ((stderr, "Entering state %d\n", yystate));
1809
1810 if (yystate == YYFINAL)
1811 YYACCEPT;
1812
1813 goto yybackup;
1814
1815 /*-----------.
1816 | yybackup. |
1817 `-----------*/
1818 yybackup:
1819
1820 /* Do appropriate processing given the current state. Read a
1821 lookahead token if we need one and don't already have one. */
1822
1823 /* First try to decide what to do without reference to lookahead token. */
1824 yyn = yypact[yystate];
1825 if (yypact_value_is_default (yyn))
1826 goto yydefault;
1827
1828 /* Not known => get a lookahead token if don't already have one. */
1829
1830 /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol. */
1831 if (yychar == YYEMPTY)
1832 {
1833 YYDPRINTF ((stderr, "Reading a token: "));
1834 yychar = yylex ();
1835 }
1836
1837 if (yychar <= YYEOF)
1838 {
1839 yychar = yytoken = YYEOF;
1840 YYDPRINTF ((stderr, "Now at end of input.\n"));
1841 }
1842 else
1843 {
1844 yytoken = YYTRANSLATE (yychar);
1845 YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
1846 }
1847
1848 /* If the proper action on seeing token YYTOKEN is to reduce or to
1849 detect an error, take that action. */
1850 yyn += yytoken;
1851 if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
1852 goto yydefault;
1853 yyn = yytable[yyn];
1854 if (yyn <= 0)
1855 {
1856 if (yytable_value_is_error (yyn))
1857 goto yyerrlab;
1858 yyn = -yyn;
1859 goto yyreduce;
1860 }
1861
1862 /* Count tokens shifted since error; after three, turn off error
1863 status. */
1864 if (yyerrstatus)
1865 yyerrstatus--;
1866
1867 /* Shift the lookahead token. */
1868 YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
1869
1870 /* Discard the shifted token. */
1871 yychar = YYEMPTY;
1872
1873 yystate = yyn;
1874 YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
1875 *++yyvsp = yylval;
1876 YY_IGNORE_MAYBE_UNINITIALIZED_END
1877
1878 goto yynewstate;
1879
1880
1881 /*-----------------------------------------------------------.
1882 | yydefault -- do the default action for the current state. |
1883 `-----------------------------------------------------------*/
1884 yydefault:
1885 yyn = yydefact[yystate];
1886 if (yyn == 0)
1887 goto yyerrlab;
1888 goto yyreduce;
1889
1890
1891 /*-----------------------------.
1892 | yyreduce -- Do a reduction. |
1893 `-----------------------------*/
1894 yyreduce:
1895 /* yyn is the number of a rule to reduce with. */
1896 yylen = yyr2[yyn];
1897
1898 /* If YYLEN is nonzero, implement the default value of the action:
1899 '$$ = $1'.
1900
1901 Otherwise, the following line sets YYVAL to garbage.
1902 This behavior is undocumented and Bison
1903 users should not rely upon it. Assigning to YYVAL
1904 unconditionally makes the parser a bit smaller, and it avoids a
1905 GCC warning that YYVAL may be used uninitialized. */
1906 yyval = yyvsp[1-yylen];
1907
1908
1909 YY_REDUCE_PRINT (yyn);
1910 switch (yyn)
1911 {
1912 case 2:
1913 #line 387 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
1914 {
1915 /* Case of regular command. Discard the error
1916 safety net,and return the command just parsed. */
1917 global_command = (yyvsp[-1].command);
1918 eof_encountered = 0;
1919 /* discard_parser_constructs (0); */
1920 if (parser_state & PST_CMDSUBST)
1921 parser_state |= PST_EOFTOKEN;
1922 YYACCEPT;
1923 }
1924 #line 1925 "y.tab.c" /* yacc.c:1646 */
1925 break;
1926
1927 case 3:
1928 #line 398 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
1929 {
1930 /* Case of regular command, but not a very
1931 interesting one. Return a NULL command. */
1932 global_command = (COMMAND *)NULL;
1933 if (parser_state & PST_CMDSUBST)
1934 parser_state |= PST_EOFTOKEN;
1935 YYACCEPT;
1936 }
1937 #line 1938 "y.tab.c" /* yacc.c:1646 */
1938 break;
1939
1940 case 4:
1941 #line 407 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
1942 {
1943 /* Error during parsing. Return NULL command. */
1944 global_command = (COMMAND *)NULL;
1945 eof_encountered = 0;
1946 /* discard_parser_constructs (1); */
1947 if (interactive && parse_and_execute_level == 0)
1948 {
1949 YYACCEPT;
1950 }
1951 else
1952 {
1953 YYABORT;
1954 }
1955 }
1956 #line 1957 "y.tab.c" /* yacc.c:1646 */
1957 break;
1958
1959 case 5:
1960 #line 422 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
1961 {
1962 /* Case of EOF seen by itself. Do ignoreeof or
1963 not. */
1964 global_command = (COMMAND *)NULL;
1965 handle_eof_input_unit ();
1966 YYACCEPT;
1967 }
1968 #line 1969 "y.tab.c" /* yacc.c:1646 */
1969 break;
1970
1971 case 6:
1972 #line 432 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
1973 { (yyval.word_list) = make_word_list ((yyvsp[0].word), (WORD_LIST *)NULL); }
1974 #line 1975 "y.tab.c" /* yacc.c:1646 */
1975 break;
1976
1977 case 7:
1978 #line 434 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
1979 { (yyval.word_list) = make_word_list ((yyvsp[0].word), (yyvsp[-1].word_list)); }
1980 #line 1981 "y.tab.c" /* yacc.c:1646 */
1981 break;
1982
1983 case 8:
1984 #line 438 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
1985 {
1986 source.dest = 1;
1987 redir.filename = (yyvsp[0].word);
1988 (yyval.redirect) = make_redirection (source, r_output_direction, redir, 0);
1989 }
1990 #line 1991 "y.tab.c" /* yacc.c:1646 */
1991 break;
1992
1993 case 9:
1994 #line 444 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
1995 {
1996 source.dest = 0;
1997 redir.filename = (yyvsp[0].word);
1998 (yyval.redirect) = make_redirection (source, r_input_direction, redir, 0);
1999 }
2000 #line 2001 "y.tab.c" /* yacc.c:1646 */
2001 break;
2002
2003 case 10:
2004 #line 450 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2005 {
2006 source.dest = (yyvsp[-2].number);
2007 redir.filename = (yyvsp[0].word);
2008 (yyval.redirect) = make_redirection (source, r_output_direction, redir, 0);
2009 }
2010 #line 2011 "y.tab.c" /* yacc.c:1646 */
2011 break;
2012
2013 case 11:
2014 #line 456 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2015 {
2016 source.dest = (yyvsp[-2].number);
2017 redir.filename = (yyvsp[0].word);
2018 (yyval.redirect) = make_redirection (source, r_input_direction, redir, 0);
2019 }
2020 #line 2021 "y.tab.c" /* yacc.c:1646 */
2021 break;
2022
2023 case 12:
2024 #line 462 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2025 {
2026 source.filename = (yyvsp[-2].word);
2027 redir.filename = (yyvsp[0].word);
2028 (yyval.redirect) = make_redirection (source, r_output_direction, redir, REDIR_VARASSIGN);
2029 }
2030 #line 2031 "y.tab.c" /* yacc.c:1646 */
2031 break;
2032
2033 case 13:
2034 #line 468 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2035 {
2036 source.filename = (yyvsp[-2].word);
2037 redir.filename = (yyvsp[0].word);
2038 (yyval.redirect) = make_redirection (source, r_input_direction, redir, REDIR_VARASSIGN);
2039 }
2040 #line 2041 "y.tab.c" /* yacc.c:1646 */
2041 break;
2042
2043 case 14:
2044 #line 474 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2045 {
2046 source.dest = 1;
2047 redir.filename = (yyvsp[0].word);
2048 (yyval.redirect) = make_redirection (source, r_appending_to, redir, 0);
2049 }
2050 #line 2051 "y.tab.c" /* yacc.c:1646 */
2051 break;
2052
2053 case 15:
2054 #line 480 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2055 {
2056 source.dest = (yyvsp[-2].number);
2057 redir.filename = (yyvsp[0].word);
2058 (yyval.redirect) = make_redirection (source, r_appending_to, redir, 0);
2059 }
2060 #line 2061 "y.tab.c" /* yacc.c:1646 */
2061 break;
2062
2063 case 16:
2064 #line 486 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2065 {
2066 source.filename = (yyvsp[-2].word);
2067 redir.filename = (yyvsp[0].word);
2068 (yyval.redirect) = make_redirection (source, r_appending_to, redir, REDIR_VARASSIGN);
2069 }
2070 #line 2071 "y.tab.c" /* yacc.c:1646 */
2071 break;
2072
2073 case 17:
2074 #line 492 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2075 {
2076 source.dest = 1;
2077 redir.filename = (yyvsp[0].word);
2078 (yyval.redirect) = make_redirection (source, r_output_force, redir, 0);
2079 }
2080 #line 2081 "y.tab.c" /* yacc.c:1646 */
2081 break;
2082
2083 case 18:
2084 #line 498 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2085 {
2086 source.dest = (yyvsp[-2].number);
2087 redir.filename = (yyvsp[0].word);
2088 (yyval.redirect) = make_redirection (source, r_output_force, redir, 0);
2089 }
2090 #line 2091 "y.tab.c" /* yacc.c:1646 */
2091 break;
2092
2093 case 19:
2094 #line 504 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2095 {
2096 source.filename = (yyvsp[-2].word);
2097 redir.filename = (yyvsp[0].word);
2098 (yyval.redirect) = make_redirection (source, r_output_force, redir, REDIR_VARASSIGN);
2099 }
2100 #line 2101 "y.tab.c" /* yacc.c:1646 */
2101 break;
2102
2103 case 20:
2104 #line 510 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2105 {
2106 source.dest = 0;
2107 redir.filename = (yyvsp[0].word);
2108 (yyval.redirect) = make_redirection (source, r_input_output, redir, 0);
2109 }
2110 #line 2111 "y.tab.c" /* yacc.c:1646 */
2111 break;
2112
2113 case 21:
2114 #line 516 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2115 {
2116 source.dest = (yyvsp[-2].number);
2117 redir.filename = (yyvsp[0].word);
2118 (yyval.redirect) = make_redirection (source, r_input_output, redir, 0);
2119 }
2120 #line 2121 "y.tab.c" /* yacc.c:1646 */
2121 break;
2122
2123 case 22:
2124 #line 522 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2125 {
2126 source.filename = (yyvsp[-2].word);
2127 redir.filename = (yyvsp[0].word);
2128 (yyval.redirect) = make_redirection (source, r_input_output, redir, REDIR_VARASSIGN);
2129 }
2130 #line 2131 "y.tab.c" /* yacc.c:1646 */
2131 break;
2132
2133 case 23:
2134 #line 528 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2135 {
2136 source.dest = 0;
2137 redir.filename = (yyvsp[0].word);
2138 (yyval.redirect) = make_redirection (source, r_reading_until, redir, 0);
2139 push_heredoc ((yyval.redirect));
2140 }
2141 #line 2142 "y.tab.c" /* yacc.c:1646 */
2142 break;
2143
2144 case 24:
2145 #line 535 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2146 {
2147 source.dest = (yyvsp[-2].number);
2148 redir.filename = (yyvsp[0].word);
2149 (yyval.redirect) = make_redirection (source, r_reading_until, redir, 0);
2150 push_heredoc ((yyval.redirect));
2151 }
2152 #line 2153 "y.tab.c" /* yacc.c:1646 */
2153 break;
2154
2155 case 25:
2156 #line 542 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2157 {
2158 source.filename = (yyvsp[-2].word);
2159 redir.filename = (yyvsp[0].word);
2160 (yyval.redirect) = make_redirection (source, r_reading_until, redir, REDIR_VARASSIGN);
2161 push_heredoc ((yyval.redirect));
2162 }
2163 #line 2164 "y.tab.c" /* yacc.c:1646 */
2164 break;
2165
2166 case 26:
2167 #line 549 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2168 {
2169 source.dest = 0;
2170 redir.filename = (yyvsp[0].word);
2171 (yyval.redirect) = make_redirection (source, r_deblank_reading_until, redir, 0);
2172 push_heredoc ((yyval.redirect));
2173 }
2174 #line 2175 "y.tab.c" /* yacc.c:1646 */
2175 break;
2176
2177 case 27:
2178 #line 556 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2179 {
2180 source.dest = (yyvsp[-2].number);
2181 redir.filename = (yyvsp[0].word);
2182 (yyval.redirect) = make_redirection (source, r_deblank_reading_until, redir, 0);
2183 push_heredoc ((yyval.redirect));
2184 }
2185 #line 2186 "y.tab.c" /* yacc.c:1646 */
2186 break;
2187
2188 case 28:
2189 #line 563 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2190 {
2191 source.filename = (yyvsp[-2].word);
2192 redir.filename = (yyvsp[0].word);
2193 (yyval.redirect) = make_redirection (source, r_deblank_reading_until, redir, REDIR_VARASSIGN);
2194 push_heredoc ((yyval.redirect));
2195 }
2196 #line 2197 "y.tab.c" /* yacc.c:1646 */
2197 break;
2198
2199 case 29:
2200 #line 570 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2201 {
2202 source.dest = 0;
2203 redir.filename = (yyvsp[0].word);
2204 (yyval.redirect) = make_redirection (source, r_reading_string, redir, 0);
2205 }
2206 #line 2207 "y.tab.c" /* yacc.c:1646 */
2207 break;
2208
2209 case 30:
2210 #line 576 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2211 {
2212 source.dest = (yyvsp[-2].number);
2213 redir.filename = (yyvsp[0].word);
2214 (yyval.redirect) = make_redirection (source, r_reading_string, redir, 0);
2215 }
2216 #line 2217 "y.tab.c" /* yacc.c:1646 */
2217 break;
2218
2219 case 31:
2220 #line 582 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2221 {
2222 source.filename = (yyvsp[-2].word);
2223 redir.filename = (yyvsp[0].word);
2224 (yyval.redirect) = make_redirection (source, r_reading_string, redir, REDIR_VARASSIGN);
2225 }
2226 #line 2227 "y.tab.c" /* yacc.c:1646 */
2227 break;
2228
2229 case 32:
2230 #line 588 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2231 {
2232 source.dest = 0;
2233 redir.dest = (yyvsp[0].number);
2234 (yyval.redirect) = make_redirection (source, r_duplicating_input, redir, 0);
2235 }
2236 #line 2237 "y.tab.c" /* yacc.c:1646 */
2237 break;
2238
2239 case 33:
2240 #line 594 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2241 {
2242 source.dest = (yyvsp[-2].number);
2243 redir.dest = (yyvsp[0].number);
2244 (yyval.redirect) = make_redirection (source, r_duplicating_input, redir, 0);
2245 }
2246 #line 2247 "y.tab.c" /* yacc.c:1646 */
2247 break;
2248
2249 case 34:
2250 #line 600 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2251 {
2252 source.filename = (yyvsp[-2].word);
2253 redir.dest = (yyvsp[0].number);
2254 (yyval.redirect) = make_redirection (source, r_duplicating_input, redir, REDIR_VARASSIGN);
2255 }
2256 #line 2257 "y.tab.c" /* yacc.c:1646 */
2257 break;
2258
2259 case 35:
2260 #line 606 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2261 {
2262 source.dest = 1;
2263 redir.dest = (yyvsp[0].number);
2264 (yyval.redirect) = make_redirection (source, r_duplicating_output, redir, 0);
2265 }
2266 #line 2267 "y.tab.c" /* yacc.c:1646 */
2267 break;
2268
2269 case 36:
2270 #line 612 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2271 {
2272 source.dest = (yyvsp[-2].number);
2273 redir.dest = (yyvsp[0].number);
2274 (yyval.redirect) = make_redirection (source, r_duplicating_output, redir, 0);
2275 }
2276 #line 2277 "y.tab.c" /* yacc.c:1646 */
2277 break;
2278
2279 case 37:
2280 #line 618 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2281 {
2282 source.filename = (yyvsp[-2].word);
2283 redir.dest = (yyvsp[0].number);
2284 (yyval.redirect) = make_redirection (source, r_duplicating_output, redir, REDIR_VARASSIGN);
2285 }
2286 #line 2287 "y.tab.c" /* yacc.c:1646 */
2287 break;
2288
2289 case 38:
2290 #line 624 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2291 {
2292 source.dest = 0;
2293 redir.filename = (yyvsp[0].word);
2294 (yyval.redirect) = make_redirection (source, r_duplicating_input_word, redir, 0);
2295 }
2296 #line 2297 "y.tab.c" /* yacc.c:1646 */
2297 break;
2298
2299 case 39:
2300 #line 630 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2301 {
2302 source.dest = (yyvsp[-2].number);
2303 redir.filename = (yyvsp[0].word);
2304 (yyval.redirect) = make_redirection (source, r_duplicating_input_word, redir, 0);
2305 }
2306 #line 2307 "y.tab.c" /* yacc.c:1646 */
2307 break;
2308
2309 case 40:
2310 #line 636 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2311 {
2312 source.filename = (yyvsp[-2].word);
2313 redir.filename = (yyvsp[0].word);
2314 (yyval.redirect) = make_redirection (source, r_duplicating_input_word, redir, REDIR_VARASSIGN);
2315 }
2316 #line 2317 "y.tab.c" /* yacc.c:1646 */
2317 break;
2318
2319 case 41:
2320 #line 642 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2321 {
2322 source.dest = 1;
2323 redir.filename = (yyvsp[0].word);
2324 (yyval.redirect) = make_redirection (source, r_duplicating_output_word, redir, 0);
2325 }
2326 #line 2327 "y.tab.c" /* yacc.c:1646 */
2327 break;
2328
2329 case 42:
2330 #line 648 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2331 {
2332 source.dest = (yyvsp[-2].number);
2333 redir.filename = (yyvsp[0].word);
2334 (yyval.redirect) = make_redirection (source, r_duplicating_output_word, redir, 0);
2335 }
2336 #line 2337 "y.tab.c" /* yacc.c:1646 */
2337 break;
2338
2339 case 43:
2340 #line 654 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2341 {
2342 source.filename = (yyvsp[-2].word);
2343 redir.filename = (yyvsp[0].word);
2344 (yyval.redirect) = make_redirection (source, r_duplicating_output_word, redir, REDIR_VARASSIGN);
2345 }
2346 #line 2347 "y.tab.c" /* yacc.c:1646 */
2347 break;
2348
2349 case 44:
2350 #line 660 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2351 {
2352 source.dest = 1;
2353 redir.dest = 0;
2354 (yyval.redirect) = make_redirection (source, r_close_this, redir, 0);
2355 }
2356 #line 2357 "y.tab.c" /* yacc.c:1646 */
2357 break;
2358
2359 case 45:
2360 #line 666 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2361 {
2362 source.dest = (yyvsp[-2].number);
2363 redir.dest = 0;
2364 (yyval.redirect) = make_redirection (source, r_close_this, redir, 0);
2365 }
2366 #line 2367 "y.tab.c" /* yacc.c:1646 */
2367 break;
2368
2369 case 46:
2370 #line 672 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2371 {
2372 source.filename = (yyvsp[-2].word);
2373 redir.dest = 0;
2374 (yyval.redirect) = make_redirection (source, r_close_this, redir, REDIR_VARASSIGN);
2375 }
2376 #line 2377 "y.tab.c" /* yacc.c:1646 */
2377 break;
2378
2379 case 47:
2380 #line 678 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2381 {
2382 source.dest = 0;
2383 redir.dest = 0;
2384 (yyval.redirect) = make_redirection (source, r_close_this, redir, 0);
2385 }
2386 #line 2387 "y.tab.c" /* yacc.c:1646 */
2387 break;
2388
2389 case 48:
2390 #line 684 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2391 {
2392 source.dest = (yyvsp[-2].number);
2393 redir.dest = 0;
2394 (yyval.redirect) = make_redirection (source, r_close_this, redir, 0);
2395 }
2396 #line 2397 "y.tab.c" /* yacc.c:1646 */
2397 break;
2398
2399 case 49:
2400 #line 690 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2401 {
2402 source.filename = (yyvsp[-2].word);
2403 redir.dest = 0;
2404 (yyval.redirect) = make_redirection (source, r_close_this, redir, REDIR_VARASSIGN);
2405 }
2406 #line 2407 "y.tab.c" /* yacc.c:1646 */
2407 break;
2408
2409 case 50:
2410 #line 696 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2411 {
2412 source.dest = 1;
2413 redir.filename = (yyvsp[0].word);
2414 (yyval.redirect) = make_redirection (source, r_err_and_out, redir, 0);
2415 }
2416 #line 2417 "y.tab.c" /* yacc.c:1646 */
2417 break;
2418
2419 case 51:
2420 #line 702 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2421 {
2422 source.dest = 1;
2423 redir.filename = (yyvsp[0].word);
2424 (yyval.redirect) = make_redirection (source, r_append_err_and_out, redir, 0);
2425 }
2426 #line 2427 "y.tab.c" /* yacc.c:1646 */
2427 break;
2428
2429 case 52:
2430 #line 710 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2431 { (yyval.element).word = (yyvsp[0].word); (yyval.element).redirect = 0; }
2432 #line 2433 "y.tab.c" /* yacc.c:1646 */
2433 break;
2434
2435 case 53:
2436 #line 712 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2437 { (yyval.element).word = (yyvsp[0].word); (yyval.element).redirect = 0; }
2438 #line 2439 "y.tab.c" /* yacc.c:1646 */
2439 break;
2440
2441 case 54:
2442 #line 714 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2443 { (yyval.element).redirect = (yyvsp[0].redirect); (yyval.element).word = 0; }
2444 #line 2445 "y.tab.c" /* yacc.c:1646 */
2445 break;
2446
2447 case 55:
2448 #line 718 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2449 {
2450 (yyval.redirect) = (yyvsp[0].redirect);
2451 }
2452 #line 2453 "y.tab.c" /* yacc.c:1646 */
2453 break;
2454
2455 case 56:
2456 #line 722 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2457 {
2458 register REDIRECT *t;
2459
2460 for (t = (yyvsp[-1].redirect); t->next; t = t->next)
2461 ;
2462 t->next = (yyvsp[0].redirect);
2463 (yyval.redirect) = (yyvsp[-1].redirect);
2464 }
2465 #line 2466 "y.tab.c" /* yacc.c:1646 */
2466 break;
2467
2468 case 57:
2469 #line 733 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2470 { (yyval.command) = make_simple_command ((yyvsp[0].element), (COMMAND *)NULL); }
2471 #line 2472 "y.tab.c" /* yacc.c:1646 */
2472 break;
2473
2474 case 58:
2475 #line 735 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2476 { (yyval.command) = make_simple_command ((yyvsp[0].element), (yyvsp[-1].command)); }
2477 #line 2478 "y.tab.c" /* yacc.c:1646 */
2478 break;
2479
2480 case 59:
2481 #line 739 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2482 { (yyval.command) = clean_simple_command ((yyvsp[0].command)); }
2483 #line 2484 "y.tab.c" /* yacc.c:1646 */
2484 break;
2485
2486 case 60:
2487 #line 741 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2488 { (yyval.command) = (yyvsp[0].command); }
2489 #line 2490 "y.tab.c" /* yacc.c:1646 */
2490 break;
2491
2492 case 61:
2493 #line 743 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2494 {
2495 COMMAND *tc;
2496
2497 tc = (yyvsp[-1].command);
2498 if (tc->redirects)
2499 {
2500 register REDIRECT *t;
2501 for (t = tc->redirects; t->next; t = t->next)
2502 ;
2503 t->next = (yyvsp[0].redirect);
2504 }
2505 else
2506 tc->redirects = (yyvsp[0].redirect);
2507 (yyval.command) = (yyvsp[-1].command);
2508 }
2509 #line 2510 "y.tab.c" /* yacc.c:1646 */
2510 break;
2511
2512 case 62:
2513 #line 759 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2514 { (yyval.command) = (yyvsp[0].command); }
2515 #line 2516 "y.tab.c" /* yacc.c:1646 */
2516 break;
2517
2518 case 63:
2519 #line 761 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2520 { (yyval.command) = (yyvsp[0].command); }
2521 #line 2522 "y.tab.c" /* yacc.c:1646 */
2522 break;
2523
2524 case 64:
2525 #line 765 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2526 { (yyval.command) = (yyvsp[0].command); }
2527 #line 2528 "y.tab.c" /* yacc.c:1646 */
2528 break;
2529
2530 case 65:
2531 #line 767 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2532 { (yyval.command) = (yyvsp[0].command); }
2533 #line 2534 "y.tab.c" /* yacc.c:1646 */
2534 break;
2535
2536 case 66:
2537 #line 769 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2538 { (yyval.command) = make_while_command ((yyvsp[-3].command), (yyvsp[-1].command)); }
2539 #line 2540 "y.tab.c" /* yacc.c:1646 */
2540 break;
2541
2542 case 67:
2543 #line 771 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2544 { (yyval.command) = make_until_command ((yyvsp[-3].command), (yyvsp[-1].command)); }
2545 #line 2546 "y.tab.c" /* yacc.c:1646 */
2546 break;
2547
2548 case 68:
2549 #line 773 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2550 { (yyval.command) = (yyvsp[0].command); }
2551 #line 2552 "y.tab.c" /* yacc.c:1646 */
2552 break;
2553
2554 case 69:
2555 #line 775 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2556 { (yyval.command) = (yyvsp[0].command); }
2557 #line 2558 "y.tab.c" /* yacc.c:1646 */
2558 break;
2559
2560 case 70:
2561 #line 777 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2562 { (yyval.command) = (yyvsp[0].command); }
2563 #line 2564 "y.tab.c" /* yacc.c:1646 */
2564 break;
2565
2566 case 71:
2567 #line 779 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2568 { (yyval.command) = (yyvsp[0].command); }
2569 #line 2570 "y.tab.c" /* yacc.c:1646 */
2570 break;
2571
2572 case 72:
2573 #line 781 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2574 { (yyval.command) = (yyvsp[0].command); }
2575 #line 2576 "y.tab.c" /* yacc.c:1646 */
2576 break;
2577
2578 case 73:
2579 #line 783 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2580 { (yyval.command) = (yyvsp[0].command); }
2581 #line 2582 "y.tab.c" /* yacc.c:1646 */
2582 break;
2583
2584 case 74:
2585 #line 785 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2586 { (yyval.command) = (yyvsp[0].command); }
2587 #line 2588 "y.tab.c" /* yacc.c:1646 */
2588 break;
2589
2590 case 75:
2591 #line 789 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2592 {
2593 (yyval.command) = make_for_command ((yyvsp[-4].word), add_string_to_list ("\"$@\"", (WORD_LIST *)NULL), (yyvsp[-1].command), word_lineno[word_top]);
2594 if (word_top > 0) word_top--;
2595 }
2596 #line 2597 "y.tab.c" /* yacc.c:1646 */
2597 break;
2598
2599 case 76:
2600 #line 794 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2601 {
2602 (yyval.command) = make_for_command ((yyvsp[-4].word), add_string_to_list ("\"$@\"", (WORD_LIST *)NULL), (yyvsp[-1].command), word_lineno[word_top]);
2603 if (word_top > 0) word_top--;
2604 }
2605 #line 2606 "y.tab.c" /* yacc.c:1646 */
2606 break;
2607
2608 case 77:
2609 #line 799 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2610 {
2611 (yyval.command) = make_for_command ((yyvsp[-5].word), add_string_to_list ("\"$@\"", (WORD_LIST *)NULL), (yyvsp[-1].command), word_lineno[word_top]);
2612 if (word_top > 0) word_top--;
2613 }
2614 #line 2615 "y.tab.c" /* yacc.c:1646 */
2615 break;
2616
2617 case 78:
2618 #line 804 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2619 {
2620 (yyval.command) = make_for_command ((yyvsp[-5].word), add_string_to_list ("\"$@\"", (WORD_LIST *)NULL), (yyvsp[-1].command), word_lineno[word_top]);
2621 if (word_top > 0) word_top--;
2622 }
2623 #line 2624 "y.tab.c" /* yacc.c:1646 */
2624 break;
2625
2626 case 79:
2627 #line 809 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2628 {
2629 (yyval.command) = make_for_command ((yyvsp[-8].word), REVERSE_LIST ((yyvsp[-5].word_list), WORD_LIST *), (yyvsp[-1].command), word_lineno[word_top]);
2630 if (word_top > 0) word_top--;
2631 }
2632 #line 2633 "y.tab.c" /* yacc.c:1646 */
2633 break;
2634
2635 case 80:
2636 #line 814 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2637 {
2638 (yyval.command) = make_for_command ((yyvsp[-8].word), REVERSE_LIST ((yyvsp[-5].word_list), WORD_LIST *), (yyvsp[-1].command), word_lineno[word_top]);
2639 if (word_top > 0) word_top--;
2640 }
2641 #line 2642 "y.tab.c" /* yacc.c:1646 */
2642 break;
2643
2644 case 81:
2645 #line 819 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2646 {
2647 (yyval.command) = make_for_command ((yyvsp[-7].word), (WORD_LIST *)NULL, (yyvsp[-1].command), word_lineno[word_top]);
2648 if (word_top > 0) word_top--;
2649 }
2650 #line 2651 "y.tab.c" /* yacc.c:1646 */
2651 break;
2652
2653 case 82:
2654 #line 824 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2655 {
2656 (yyval.command) = make_for_command ((yyvsp[-7].word), (WORD_LIST *)NULL, (yyvsp[-1].command), word_lineno[word_top]);
2657 if (word_top > 0) word_top--;
2658 }
2659 #line 2660 "y.tab.c" /* yacc.c:1646 */
2660 break;
2661
2662 case 83:
2663 #line 831 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2664 {
2665 (yyval.command) = make_arith_for_command ((yyvsp[-5].word_list), (yyvsp[-1].command), arith_for_lineno);
2666 if (word_top > 0) word_top--;
2667 }
2668 #line 2669 "y.tab.c" /* yacc.c:1646 */
2669 break;
2670
2671 case 84:
2672 #line 836 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2673 {
2674 (yyval.command) = make_arith_for_command ((yyvsp[-5].word_list), (yyvsp[-1].command), arith_for_lineno);
2675 if (word_top > 0) word_top--;
2676 }
2677 #line 2678 "y.tab.c" /* yacc.c:1646 */
2678 break;
2679
2680 case 85:
2681 #line 841 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2682 {
2683 (yyval.command) = make_arith_for_command ((yyvsp[-3].word_list), (yyvsp[-1].command), arith_for_lineno);
2684 if (word_top > 0) word_top--;
2685 }
2686 #line 2687 "y.tab.c" /* yacc.c:1646 */
2687 break;
2688
2689 case 86:
2690 #line 846 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2691 {
2692 (yyval.command) = make_arith_for_command ((yyvsp[-3].word_list), (yyvsp[-1].command), arith_for_lineno);
2693 if (word_top > 0) word_top--;
2694 }
2695 #line 2696 "y.tab.c" /* yacc.c:1646 */
2696 break;
2697
2698 case 87:
2699 #line 853 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2700 {
2701 (yyval.command) = make_select_command ((yyvsp[-4].word), add_string_to_list ("\"$@\"", (WORD_LIST *)NULL), (yyvsp[-1].command), word_lineno[word_top]);
2702 if (word_top > 0) word_top--;
2703 }
2704 #line 2705 "y.tab.c" /* yacc.c:1646 */
2705 break;
2706
2707 case 88:
2708 #line 858 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2709 {
2710 (yyval.command) = make_select_command ((yyvsp[-4].word), add_string_to_list ("\"$@\"", (WORD_LIST *)NULL), (yyvsp[-1].command), word_lineno[word_top]);
2711 if (word_top > 0) word_top--;
2712 }
2713 #line 2714 "y.tab.c" /* yacc.c:1646 */
2714 break;
2715
2716 case 89:
2717 #line 863 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2718 {
2719 (yyval.command) = make_select_command ((yyvsp[-5].word), add_string_to_list ("\"$@\"", (WORD_LIST *)NULL), (yyvsp[-1].command), word_lineno[word_top]);
2720 if (word_top > 0) word_top--;
2721 }
2722 #line 2723 "y.tab.c" /* yacc.c:1646 */
2723 break;
2724
2725 case 90:
2726 #line 868 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2727 {
2728 (yyval.command) = make_select_command ((yyvsp[-5].word), add_string_to_list ("\"$@\"", (WORD_LIST *)NULL), (yyvsp[-1].command), word_lineno[word_top]);
2729 if (word_top > 0) word_top--;
2730 }
2731 #line 2732 "y.tab.c" /* yacc.c:1646 */
2732 break;
2733
2734 case 91:
2735 #line 873 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2736 {
2737 (yyval.command) = make_select_command ((yyvsp[-8].word), REVERSE_LIST ((yyvsp[-5].word_list), WORD_LIST *), (yyvsp[-1].command), word_lineno[word_top]);
2738 if (word_top > 0) word_top--;
2739 }
2740 #line 2741 "y.tab.c" /* yacc.c:1646 */
2741 break;
2742
2743 case 92:
2744 #line 878 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2745 {
2746 (yyval.command) = make_select_command ((yyvsp[-8].word), REVERSE_LIST ((yyvsp[-5].word_list), WORD_LIST *), (yyvsp[-1].command), word_lineno[word_top]);
2747 if (word_top > 0) word_top--;
2748 }
2749 #line 2750 "y.tab.c" /* yacc.c:1646 */
2750 break;
2751
2752 case 93:
2753 #line 885 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2754 {
2755 (yyval.command) = make_case_command ((yyvsp[-4].word), (PATTERN_LIST *)NULL, word_lineno[word_top]);
2756 if (word_top > 0) word_top--;
2757 }
2758 #line 2759 "y.tab.c" /* yacc.c:1646 */
2759 break;
2760
2761 case 94:
2762 #line 890 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2763 {
2764 (yyval.command) = make_case_command ((yyvsp[-5].word), (yyvsp[-2].pattern), word_lineno[word_top]);
2765 if (word_top > 0) word_top--;
2766 }
2767 #line 2768 "y.tab.c" /* yacc.c:1646 */
2768 break;
2769
2770 case 95:
2771 #line 895 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2772 {
2773 (yyval.command) = make_case_command ((yyvsp[-4].word), (yyvsp[-1].pattern), word_lineno[word_top]);
2774 if (word_top > 0) word_top--;
2775 }
2776 #line 2777 "y.tab.c" /* yacc.c:1646 */
2777 break;
2778
2779 case 96:
2780 #line 902 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2781 { (yyval.command) = make_function_def ((yyvsp[-4].word), (yyvsp[0].command), function_dstart, function_bstart); }
2782 #line 2783 "y.tab.c" /* yacc.c:1646 */
2783 break;
2784
2785 case 97:
2786 #line 905 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2787 { (yyval.command) = make_function_def ((yyvsp[-4].word), (yyvsp[0].command), function_dstart, function_bstart); }
2788 #line 2789 "y.tab.c" /* yacc.c:1646 */
2789 break;
2790
2791 case 98:
2792 #line 908 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2793 { (yyval.command) = make_function_def ((yyvsp[-2].word), (yyvsp[0].command), function_dstart, function_bstart); }
2794 #line 2795 "y.tab.c" /* yacc.c:1646 */
2795 break;
2796
2797 case 99:
2798 #line 912 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2799 { (yyval.command) = (yyvsp[0].command); }
2800 #line 2801 "y.tab.c" /* yacc.c:1646 */
2801 break;
2802
2803 case 100:
2804 #line 914 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2805 {
2806 COMMAND *tc;
2807
2808 tc = (yyvsp[-1].command);
2809 /* According to Posix.2 3.9.5, redirections
2810 specified after the body of a function should
2811 be attached to the function and performed when
2812 the function is executed, not as part of the
2813 function definition command. */
2814 /* XXX - I don't think it matters, but we might
2815 want to change this in the future to avoid
2816 problems differentiating between a function
2817 definition with a redirection and a function
2818 definition containing a single command with a
2819 redirection. The two are semantically equivalent,
2820 though -- the only difference is in how the
2821 command printing code displays the redirections. */
2822 if (tc->redirects)
2823 {
2824 register REDIRECT *t;
2825 for (t = tc->redirects; t->next; t = t->next)
2826 ;
2827 t->next = (yyvsp[0].redirect);
2828 }
2829 else
2830 tc->redirects = (yyvsp[0].redirect);
2831 (yyval.command) = (yyvsp[-1].command);
2832 }
2833 #line 2834 "y.tab.c" /* yacc.c:1646 */
2834 break;
2835
2836 case 101:
2837 #line 945 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2838 {
2839 (yyval.command) = make_subshell_command ((yyvsp[-1].command));
2840 (yyval.command)->flags |= CMD_WANT_SUBSHELL;
2841 }
2842 #line 2843 "y.tab.c" /* yacc.c:1646 */
2843 break;
2844
2845 case 102:
2846 #line 952 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2847 {
2848 (yyval.command) = make_coproc_command ("COPROC", (yyvsp[0].command));
2849 (yyval.command)->flags |= CMD_WANT_SUBSHELL|CMD_COPROC_SUBSHELL;
2850 }
2851 #line 2852 "y.tab.c" /* yacc.c:1646 */
2852 break;
2853
2854 case 103:
2855 #line 957 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2856 {
2857 COMMAND *tc;
2858
2859 tc = (yyvsp[-1].command);
2860 if (tc->redirects)
2861 {
2862 register REDIRECT *t;
2863 for (t = tc->redirects; t->next; t = t->next)
2864 ;
2865 t->next = (yyvsp[0].redirect);
2866 }
2867 else
2868 tc->redirects = (yyvsp[0].redirect);
2869 (yyval.command) = make_coproc_command ("COPROC", (yyvsp[-1].command));
2870 (yyval.command)->flags |= CMD_WANT_SUBSHELL|CMD_COPROC_SUBSHELL;
2871 }
2872 #line 2873 "y.tab.c" /* yacc.c:1646 */
2873 break;
2874
2875 case 104:
2876 #line 974 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2877 {
2878 (yyval.command) = make_coproc_command ((yyvsp[-1].word)->word, (yyvsp[0].command));
2879 (yyval.command)->flags |= CMD_WANT_SUBSHELL|CMD_COPROC_SUBSHELL;
2880 }
2881 #line 2882 "y.tab.c" /* yacc.c:1646 */
2882 break;
2883
2884 case 105:
2885 #line 979 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2886 {
2887 COMMAND *tc;
2888
2889 tc = (yyvsp[-1].command);
2890 if (tc->redirects)
2891 {
2892 register REDIRECT *t;
2893 for (t = tc->redirects; t->next; t = t->next)
2894 ;
2895 t->next = (yyvsp[0].redirect);
2896 }
2897 else
2898 tc->redirects = (yyvsp[0].redirect);
2899 (yyval.command) = make_coproc_command ((yyvsp[-2].word)->word, (yyvsp[-1].command));
2900 (yyval.command)->flags |= CMD_WANT_SUBSHELL|CMD_COPROC_SUBSHELL;
2901 }
2902 #line 2903 "y.tab.c" /* yacc.c:1646 */
2903 break;
2904
2905 case 106:
2906 #line 996 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2907 {
2908 (yyval.command) = make_coproc_command ("COPROC", clean_simple_command ((yyvsp[0].command)));
2909 (yyval.command)->flags |= CMD_WANT_SUBSHELL|CMD_COPROC_SUBSHELL;
2910 }
2911 #line 2912 "y.tab.c" /* yacc.c:1646 */
2912 break;
2913
2914 case 107:
2915 #line 1003 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2916 { (yyval.command) = make_if_command ((yyvsp[-3].command), (yyvsp[-1].command), (COMMAND *)NULL); }
2917 #line 2918 "y.tab.c" /* yacc.c:1646 */
2918 break;
2919
2920 case 108:
2921 #line 1005 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2922 { (yyval.command) = make_if_command ((yyvsp[-5].command), (yyvsp[-3].command), (yyvsp[-1].command)); }
2923 #line 2924 "y.tab.c" /* yacc.c:1646 */
2924 break;
2925
2926 case 109:
2927 #line 1007 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2928 { (yyval.command) = make_if_command ((yyvsp[-4].command), (yyvsp[-2].command), (yyvsp[-1].command)); }
2929 #line 2930 "y.tab.c" /* yacc.c:1646 */
2930 break;
2931
2932 case 110:
2933 #line 1012 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2934 { (yyval.command) = make_group_command ((yyvsp[-1].command)); }
2935 #line 2936 "y.tab.c" /* yacc.c:1646 */
2936 break;
2937
2938 case 111:
2939 #line 1016 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2940 { (yyval.command) = make_arith_command ((yyvsp[0].word_list)); }
2941 #line 2942 "y.tab.c" /* yacc.c:1646 */
2942 break;
2943
2944 case 112:
2945 #line 1020 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2946 { (yyval.command) = (yyvsp[-1].command); }
2947 #line 2948 "y.tab.c" /* yacc.c:1646 */
2948 break;
2949
2950 case 113:
2951 #line 1024 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2952 { (yyval.command) = make_if_command ((yyvsp[-2].command), (yyvsp[0].command), (COMMAND *)NULL); }
2953 #line 2954 "y.tab.c" /* yacc.c:1646 */
2954 break;
2955
2956 case 114:
2957 #line 1026 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2958 { (yyval.command) = make_if_command ((yyvsp[-4].command), (yyvsp[-2].command), (yyvsp[0].command)); }
2959 #line 2960 "y.tab.c" /* yacc.c:1646 */
2960 break;
2961
2962 case 115:
2963 #line 1028 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2964 { (yyval.command) = make_if_command ((yyvsp[-3].command), (yyvsp[-1].command), (yyvsp[0].command)); }
2965 #line 2966 "y.tab.c" /* yacc.c:1646 */
2966 break;
2967
2968 case 117:
2969 #line 1033 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2970 { (yyvsp[0].pattern)->next = (yyvsp[-1].pattern); (yyval.pattern) = (yyvsp[0].pattern); }
2971 #line 2972 "y.tab.c" /* yacc.c:1646 */
2972 break;
2973
2974 case 118:
2975 #line 1037 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2976 { (yyval.pattern) = make_pattern_list ((yyvsp[-2].word_list), (yyvsp[0].command)); }
2977 #line 2978 "y.tab.c" /* yacc.c:1646 */
2978 break;
2979
2980 case 119:
2981 #line 1039 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2982 { (yyval.pattern) = make_pattern_list ((yyvsp[-2].word_list), (COMMAND *)NULL); }
2983 #line 2984 "y.tab.c" /* yacc.c:1646 */
2984 break;
2985
2986 case 120:
2987 #line 1041 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2988 { (yyval.pattern) = make_pattern_list ((yyvsp[-2].word_list), (yyvsp[0].command)); }
2989 #line 2990 "y.tab.c" /* yacc.c:1646 */
2990 break;
2991
2992 case 121:
2993 #line 1043 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
2994 { (yyval.pattern) = make_pattern_list ((yyvsp[-2].word_list), (COMMAND *)NULL); }
2995 #line 2996 "y.tab.c" /* yacc.c:1646 */
2996 break;
2997
2998 case 122:
2999 #line 1047 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3000 { (yyval.pattern) = (yyvsp[-1].pattern); }
3001 #line 3002 "y.tab.c" /* yacc.c:1646 */
3002 break;
3003
3004 case 123:
3005 #line 1049 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3006 { (yyvsp[-1].pattern)->next = (yyvsp[-2].pattern); (yyval.pattern) = (yyvsp[-1].pattern); }
3007 #line 3008 "y.tab.c" /* yacc.c:1646 */
3008 break;
3009
3010 case 124:
3011 #line 1051 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3012 { (yyvsp[-1].pattern)->flags |= CASEPAT_FALLTHROUGH; (yyval.pattern) = (yyvsp[-1].pattern); }
3013 #line 3014 "y.tab.c" /* yacc.c:1646 */
3014 break;
3015
3016 case 125:
3017 #line 1053 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3018 { (yyvsp[-1].pattern)->flags |= CASEPAT_FALLTHROUGH; (yyvsp[-1].pattern)->next = (yyvsp[-2].pattern); (yyval.pattern) = (yyvsp[-1].pattern); }
3019 #line 3020 "y.tab.c" /* yacc.c:1646 */
3020 break;
3021
3022 case 126:
3023 #line 1055 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3024 { (yyvsp[-1].pattern)->flags |= CASEPAT_TESTNEXT; (yyval.pattern) = (yyvsp[-1].pattern); }
3025 #line 3026 "y.tab.c" /* yacc.c:1646 */
3026 break;
3027
3028 case 127:
3029 #line 1057 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3030 { (yyvsp[-1].pattern)->flags |= CASEPAT_TESTNEXT; (yyvsp[-1].pattern)->next = (yyvsp[-2].pattern); (yyval.pattern) = (yyvsp[-1].pattern); }
3031 #line 3032 "y.tab.c" /* yacc.c:1646 */
3032 break;
3033
3034 case 128:
3035 #line 1061 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3036 { (yyval.word_list) = make_word_list ((yyvsp[0].word), (WORD_LIST *)NULL); }
3037 #line 3038 "y.tab.c" /* yacc.c:1646 */
3038 break;
3039
3040 case 129:
3041 #line 1063 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3042 { (yyval.word_list) = make_word_list ((yyvsp[0].word), (yyvsp[-2].word_list)); }
3043 #line 3044 "y.tab.c" /* yacc.c:1646 */
3044 break;
3045
3046 case 130:
3047 #line 1072 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3048 {
3049 (yyval.command) = (yyvsp[0].command);
3050 if (need_here_doc)
3051 gather_here_documents ();
3052 }
3053 #line 3054 "y.tab.c" /* yacc.c:1646 */
3054 break;
3055
3056 case 132:
3057 #line 1081 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3058 {
3059 (yyval.command) = (yyvsp[0].command);
3060 }
3061 #line 3062 "y.tab.c" /* yacc.c:1646 */
3062 break;
3063
3064 case 134:
3065 #line 1088 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3066 {
3067 if ((yyvsp[-2].command)->type == cm_connection)
3068 (yyval.command) = connect_async_list ((yyvsp[-2].command), (COMMAND *)NULL, '&');
3069 else
3070 (yyval.command) = command_connect ((yyvsp[-2].command), (COMMAND *)NULL, '&');
3071 }
3072 #line 3073 "y.tab.c" /* yacc.c:1646 */
3073 break;
3074
3075 case 136:
3076 #line 1099 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3077 { (yyval.command) = command_connect ((yyvsp[-3].command), (yyvsp[0].command), AND_AND); }
3078 #line 3079 "y.tab.c" /* yacc.c:1646 */
3079 break;
3080
3081 case 137:
3082 #line 1101 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3083 { (yyval.command) = command_connect ((yyvsp[-3].command), (yyvsp[0].command), OR_OR); }
3084 #line 3085 "y.tab.c" /* yacc.c:1646 */
3085 break;
3086
3087 case 138:
3088 #line 1103 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3089 {
3090 if ((yyvsp[-3].command)->type == cm_connection)
3091 (yyval.command) = connect_async_list ((yyvsp[-3].command), (yyvsp[0].command), '&');
3092 else
3093 (yyval.command) = command_connect ((yyvsp[-3].command), (yyvsp[0].command), '&');
3094 }
3095 #line 3096 "y.tab.c" /* yacc.c:1646 */
3096 break;
3097
3098 case 139:
3099 #line 1110 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3100 { (yyval.command) = command_connect ((yyvsp[-3].command), (yyvsp[0].command), ';'); }
3101 #line 3102 "y.tab.c" /* yacc.c:1646 */
3102 break;
3103
3104 case 140:
3105 #line 1112 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3106 { (yyval.command) = command_connect ((yyvsp[-3].command), (yyvsp[0].command), ';'); }
3107 #line 3108 "y.tab.c" /* yacc.c:1646 */
3108 break;
3109
3110 case 141:
3111 #line 1114 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3112 { (yyval.command) = (yyvsp[0].command); }
3113 #line 3114 "y.tab.c" /* yacc.c:1646 */
3114 break;
3115
3116 case 144:
3117 #line 1122 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3118 { (yyval.number) = '\n'; }
3119 #line 3120 "y.tab.c" /* yacc.c:1646 */
3120 break;
3121
3122 case 145:
3123 #line 1124 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3124 { (yyval.number) = ';'; }
3125 #line 3126 "y.tab.c" /* yacc.c:1646 */
3126 break;
3127
3128 case 146:
3129 #line 1126 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3130 { (yyval.number) = yacc_EOF; }
3131 #line 3132 "y.tab.c" /* yacc.c:1646 */
3132 break;
3133
3134 case 149:
3135 #line 1140 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3136 {
3137 (yyval.command) = (yyvsp[0].command);
3138 if (need_here_doc)
3139 gather_here_documents ();
3140 if ((parser_state & PST_CMDSUBST) && current_token == shell_eof_token)
3141 {
3142 global_command = (yyvsp[0].command);
3143 eof_encountered = 0;
3144 rewind_input_string ();
3145 YYACCEPT;
3146 }
3147 }
3148 #line 3149 "y.tab.c" /* yacc.c:1646 */
3149 break;
3150
3151 case 150:
3152 #line 1153 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3153 {
3154 if ((yyvsp[-1].command)->type == cm_connection)
3155 (yyval.command) = connect_async_list ((yyvsp[-1].command), (COMMAND *)NULL, '&');
3156 else
3157 (yyval.command) = command_connect ((yyvsp[-1].command), (COMMAND *)NULL, '&');
3158 if (need_here_doc)
3159 gather_here_documents ();
3160 if ((parser_state & PST_CMDSUBST) && current_token == shell_eof_token)
3161 {
3162 global_command = (yyvsp[-1].command);
3163 eof_encountered = 0;
3164 rewind_input_string ();
3165 YYACCEPT;
3166 }
3167 }
3168 #line 3169 "y.tab.c" /* yacc.c:1646 */
3169 break;
3170
3171 case 151:
3172 #line 1169 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3173 {
3174 (yyval.command) = (yyvsp[-1].command);
3175 if (need_here_doc)
3176 gather_here_documents ();
3177 if ((parser_state & PST_CMDSUBST) && current_token == shell_eof_token)
3178 {
3179 global_command = (yyvsp[-1].command);
3180 eof_encountered = 0;
3181 rewind_input_string ();
3182 YYACCEPT;
3183 }
3184 }
3185 #line 3186 "y.tab.c" /* yacc.c:1646 */
3186 break;
3187
3188 case 152:
3189 #line 1184 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3190 { (yyval.command) = command_connect ((yyvsp[-3].command), (yyvsp[0].command), AND_AND); }
3191 #line 3192 "y.tab.c" /* yacc.c:1646 */
3192 break;
3193
3194 case 153:
3195 #line 1186 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3196 { (yyval.command) = command_connect ((yyvsp[-3].command), (yyvsp[0].command), OR_OR); }
3197 #line 3198 "y.tab.c" /* yacc.c:1646 */
3198 break;
3199
3200 case 154:
3201 #line 1188 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3202 {
3203 if ((yyvsp[-2].command)->type == cm_connection)
3204 (yyval.command) = connect_async_list ((yyvsp[-2].command), (yyvsp[0].command), '&');
3205 else
3206 (yyval.command) = command_connect ((yyvsp[-2].command), (yyvsp[0].command), '&');
3207 }
3208 #line 3209 "y.tab.c" /* yacc.c:1646 */
3209 break;
3210
3211 case 155:
3212 #line 1195 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3213 { (yyval.command) = command_connect ((yyvsp[-2].command), (yyvsp[0].command), ';'); }
3214 #line 3215 "y.tab.c" /* yacc.c:1646 */
3215 break;
3216
3217 case 156:
3218 #line 1198 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3219 { (yyval.command) = (yyvsp[0].command); }
3220 #line 3221 "y.tab.c" /* yacc.c:1646 */
3221 break;
3222
3223 case 157:
3224 #line 1202 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3225 { (yyval.command) = (yyvsp[0].command); }
3226 #line 3227 "y.tab.c" /* yacc.c:1646 */
3227 break;
3228
3229 case 158:
3230 #line 1204 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3231 {
3232 if ((yyvsp[0].command))
3233 (yyvsp[0].command)->flags ^= CMD_INVERT_RETURN; /* toggle */
3234 (yyval.command) = (yyvsp[0].command);
3235 }
3236 #line 3237 "y.tab.c" /* yacc.c:1646 */
3237 break;
3238
3239 case 159:
3240 #line 1210 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3241 {
3242 if ((yyvsp[0].command))
3243 (yyvsp[0].command)->flags |= (yyvsp[-1].number);
3244 (yyval.command) = (yyvsp[0].command);
3245 }
3246 #line 3247 "y.tab.c" /* yacc.c:1646 */
3247 break;
3248
3249 case 160:
3250 #line 1216 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3251 {
3252 ELEMENT x;
3253
3254 /* Boy, this is unclean. `time' by itself can
3255 time a null command. We cheat and push a
3256 newline back if the list_terminator was a newline
3257 to avoid the double-newline problem (one to
3258 terminate this, one to terminate the command) */
3259 x.word = 0;
3260 x.redirect = 0;
3261 (yyval.command) = make_simple_command (x, (COMMAND *)NULL);
3262 (yyval.command)->flags |= (yyvsp[-1].number);
3263 /* XXX - let's cheat and push a newline back */
3264 if ((yyvsp[0].number) == '\n')
3265 token_to_read = '\n';
3266 else if ((yyvsp[0].number) == ';')
3267 token_to_read = ';';
3268 }
3269 #line 3270 "y.tab.c" /* yacc.c:1646 */
3270 break;
3271
3272 case 161:
3273 #line 1235 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3274 {
3275 ELEMENT x;
3276
3277 /* This is just as unclean. Posix says that `!'
3278 by itself should be equivalent to `false'.
3279 We cheat and push a
3280 newline back if the list_terminator was a newline
3281 to avoid the double-newline problem (one to
3282 terminate this, one to terminate the command) */
3283 x.word = 0;
3284 x.redirect = 0;
3285 (yyval.command) = make_simple_command (x, (COMMAND *)NULL);
3286 (yyval.command)->flags |= CMD_INVERT_RETURN;
3287 /* XXX - let's cheat and push a newline back */
3288 if ((yyvsp[0].number) == '\n')
3289 token_to_read = '\n';
3290 if ((yyvsp[0].number) == ';')
3291 token_to_read = ';';
3292 }
3293 #line 3294 "y.tab.c" /* yacc.c:1646 */
3294 break;
3295
3296 case 162:
3297 #line 1257 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3298 { (yyval.command) = command_connect ((yyvsp[-3].command), (yyvsp[0].command), '|'); }
3299 #line 3300 "y.tab.c" /* yacc.c:1646 */
3300 break;
3301
3302 case 163:
3303 #line 1259 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3304 {
3305 /* Make cmd1 |& cmd2 equivalent to cmd1 2>&1 | cmd2 */
3306 COMMAND *tc;
3307 REDIRECTEE rd, sd;
3308 REDIRECT *r;
3309
3310 tc = (yyvsp[-3].command)->type == cm_simple ? (COMMAND *)(yyvsp[-3].command)->value.Simple : (yyvsp[-3].command);
3311 sd.dest = 2;
3312 rd.dest = 1;
3313 r = make_redirection (sd, r_duplicating_output, rd, 0);
3314 if (tc->redirects)
3315 {
3316 register REDIRECT *t;
3317 for (t = tc->redirects; t->next; t = t->next)
3318 ;
3319 t->next = r;
3320 }
3321 else
3322 tc->redirects = r;
3323
3324 (yyval.command) = command_connect ((yyvsp[-3].command), (yyvsp[0].command), '|');
3325 }
3326 #line 3327 "y.tab.c" /* yacc.c:1646 */
3327 break;
3328
3329 case 164:
3330 #line 1282 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3331 { (yyval.command) = (yyvsp[0].command); }
3332 #line 3333 "y.tab.c" /* yacc.c:1646 */
3333 break;
3334
3335 case 165:
3336 #line 1286 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3337 { (yyval.number) = CMD_TIME_PIPELINE; }
3338 #line 3339 "y.tab.c" /* yacc.c:1646 */
3339 break;
3340
3341 case 166:
3342 #line 1288 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3343 { (yyval.number) = CMD_TIME_PIPELINE|CMD_TIME_POSIX; }
3344 #line 3345 "y.tab.c" /* yacc.c:1646 */
3345 break;
3346
3347 case 167:
3348 #line 1290 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1646 */
3349 { (yyval.number) = CMD_TIME_PIPELINE|CMD_TIME_POSIX; }
3350 #line 3351 "y.tab.c" /* yacc.c:1646 */
3351 break;
3352
3353
3354 #line 3355 "y.tab.c" /* yacc.c:1646 */
3355 default: break;
3356 }
3357 /* User semantic actions sometimes alter yychar, and that requires
3358 that yytoken be updated with the new translation. We take the
3359 approach of translating immediately before every use of yytoken.
3360 One alternative is translating here after every semantic action,
3361 but that translation would be missed if the semantic action invokes
3362 YYABORT, YYACCEPT, or YYERROR immediately after altering yychar or
3363 if it invokes YYBACKUP. In the case of YYABORT or YYACCEPT, an
3364 incorrect destructor might then be invoked immediately. In the
3365 case of YYERROR or YYBACKUP, subsequent parser actions might lead
3366 to an incorrect destructor call or verbose syntax error message
3367 before the lookahead is translated. */
3368 YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc);
3369
3370 YYPOPSTACK (yylen);
3371 yylen = 0;
3372 YY_STACK_PRINT (yyss, yyssp);
3373
3374 *++yyvsp = yyval;
3375
3376 /* Now 'shift' the result of the reduction. Determine what state
3377 that goes to, based on the state we popped back to and the rule
3378 number reduced by. */
3379
3380 yyn = yyr1[yyn];
3381
3382 yystate = yypgoto[yyn - YYNTOKENS] + *yyssp;
3383 if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp)
3384 yystate = yytable[yystate];
3385 else
3386 yystate = yydefgoto[yyn - YYNTOKENS];
3387
3388 goto yynewstate;
3389
3390
3391 /*--------------------------------------.
3392 | yyerrlab -- here on detecting error. |
3393 `--------------------------------------*/
3394 yyerrlab:
3395 /* Make sure we have latest lookahead translation. See comments at
3396 user semantic actions for why this is necessary. */
3397 yytoken = yychar == YYEMPTY ? YYEMPTY : YYTRANSLATE (yychar);
3398
3399 /* If not already recovering from an error, report this error. */
3400 if (!yyerrstatus)
3401 {
3402 ++yynerrs;
3403 #if ! YYERROR_VERBOSE
3404 yyerror (YY_("syntax error"));
3405 #else
3406 # define YYSYNTAX_ERROR yysyntax_error (&yymsg_alloc, &yymsg, \
3407 yyssp, yytoken)
3408 {
3409 char const *yymsgp = YY_("syntax error");
3410 int yysyntax_error_status;
3411 yysyntax_error_status = YYSYNTAX_ERROR;
3412 if (yysyntax_error_status == 0)
3413 yymsgp = yymsg;
3414 else if (yysyntax_error_status == 1)
3415 {
3416 if (yymsg != yymsgbuf)
3417 YYSTACK_FREE (yymsg);
3418 yymsg = (char *) YYSTACK_ALLOC (yymsg_alloc);
3419 if (!yymsg)
3420 {
3421 yymsg = yymsgbuf;
3422 yymsg_alloc = sizeof yymsgbuf;
3423 yysyntax_error_status = 2;
3424 }
3425 else
3426 {
3427 yysyntax_error_status = YYSYNTAX_ERROR;
3428 yymsgp = yymsg;
3429 }
3430 }
3431 yyerror (yymsgp);
3432 if (yysyntax_error_status == 2)
3433 goto yyexhaustedlab;
3434 }
3435 # undef YYSYNTAX_ERROR
3436 #endif
3437 }
3438
3439
3440
3441 if (yyerrstatus == 3)
3442 {
3443 /* If just tried and failed to reuse lookahead token after an
3444 error, discard it. */
3445
3446 if (yychar <= YYEOF)
3447 {
3448 /* Return failure if at end of input. */
3449 if (yychar == YYEOF)
3450 YYABORT;
3451 }
3452 else
3453 {
3454 yydestruct ("Error: discarding",
3455 yytoken, &yylval);
3456 yychar = YYEMPTY;
3457 }
3458 }
3459
3460 /* Else will try to reuse lookahead token after shifting the error
3461 token. */
3462 goto yyerrlab1;
3463
3464
3465 /*---------------------------------------------------.
3466 | yyerrorlab -- error raised explicitly by YYERROR. |
3467 `---------------------------------------------------*/
3468 yyerrorlab:
3469
3470 /* Pacify compilers like GCC when the user code never invokes
3471 YYERROR and the label yyerrorlab therefore never appears in user
3472 code. */
3473 if (/*CONSTCOND*/ 0)
3474 goto yyerrorlab;
3475
3476 /* Do not reclaim the symbols of the rule whose action triggered
3477 this YYERROR. */
3478 YYPOPSTACK (yylen);
3479 yylen = 0;
3480 YY_STACK_PRINT (yyss, yyssp);
3481 yystate = *yyssp;
3482 goto yyerrlab1;
3483
3484
3485 /*-------------------------------------------------------------.
3486 | yyerrlab1 -- common code for both syntax error and YYERROR. |
3487 `-------------------------------------------------------------*/
3488 yyerrlab1:
3489 yyerrstatus = 3; /* Each real token shifted decrements this. */
3490
3491 for (;;)
3492 {
3493 yyn = yypact[yystate];
3494 if (!yypact_value_is_default (yyn))
3495 {
3496 yyn += YYTERROR;
3497 if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
3498 {
3499 yyn = yytable[yyn];
3500 if (0 < yyn)
3501 break;
3502 }
3503 }
3504
3505 /* Pop the current state because it cannot handle the error token. */
3506 if (yyssp == yyss)
3507 YYABORT;
3508
3509
3510 yydestruct ("Error: popping",
3511 yystos[yystate], yyvsp);
3512 YYPOPSTACK (1);
3513 yystate = *yyssp;
3514 YY_STACK_PRINT (yyss, yyssp);
3515 }
3516
3517 YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
3518 *++yyvsp = yylval;
3519 YY_IGNORE_MAYBE_UNINITIALIZED_END
3520
3521
3522 /* Shift the error token. */
3523 YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp);
3524
3525 yystate = yyn;
3526 goto yynewstate;
3527
3528
3529 /*-------------------------------------.
3530 | yyacceptlab -- YYACCEPT comes here. |
3531 `-------------------------------------*/
3532 yyacceptlab:
3533 yyresult = 0;
3534 goto yyreturn;
3535
3536 /*-----------------------------------.
3537 | yyabortlab -- YYABORT comes here. |
3538 `-----------------------------------*/
3539 yyabortlab:
3540 yyresult = 1;
3541 goto yyreturn;
3542
3543 #if !defined yyoverflow || YYERROR_VERBOSE
3544 /*-------------------------------------------------.
3545 | yyexhaustedlab -- memory exhaustion comes here. |
3546 `-------------------------------------------------*/
3547 yyexhaustedlab:
3548 yyerror (YY_("memory exhausted"));
3549 yyresult = 2;
3550 /* Fall through. */
3551 #endif
3552
3553 yyreturn:
3554 if (yychar != YYEMPTY)
3555 {
3556 /* Make sure we have latest lookahead translation. See comments at
3557 user semantic actions for why this is necessary. */
3558 yytoken = YYTRANSLATE (yychar);
3559 yydestruct ("Cleanup: discarding lookahead",
3560 yytoken, &yylval);
3561 }
3562 /* Do not reclaim the symbols of the rule whose action triggered
3563 this YYABORT or YYACCEPT. */
3564 YYPOPSTACK (yylen);
3565 YY_STACK_PRINT (yyss, yyssp);
3566 while (yyssp != yyss)
3567 {
3568 yydestruct ("Cleanup: popping",
3569 yystos[*yyssp], yyvsp);
3570 YYPOPSTACK (1);
3571 }
3572 #ifndef yyoverflow
3573 if (yyss != yyssa)
3574 YYSTACK_FREE (yyss);
3575 #endif
3576 #if YYERROR_VERBOSE
3577 if (yymsg != yymsgbuf)
3578 YYSTACK_FREE (yymsg);
3579 #endif
3580 return yyresult;
3581 }
3582 #line 1292 "/usr/homes/chet/src/bash/src/parse.y" /* yacc.c:1906 */
3583
3584
3585 /* Initial size to allocate for tokens, and the
3586 amount to grow them by. */
3587 #define TOKEN_DEFAULT_INITIAL_SIZE 496
3588 #define TOKEN_DEFAULT_GROW_SIZE 512
3589
3590 /* Should we call prompt_again? */
3591 #define SHOULD_PROMPT() \
3592 (interactive && (bash_input.type == st_stdin || bash_input.type == st_stream))
3593
3594 #if defined (ALIAS)
3595 # define expanding_alias() (pushed_string_list && pushed_string_list->expander)
3596 #else
3597 # define expanding_alias() 0
3598 #endif
3599
3600 /* Global var is non-zero when end of file has been reached. */
3601 int EOF_Reached = 0;
3602
3603 #ifdef DEBUG
3604 static void
3605 debug_parser (i)
3606 int i;
3607 {
3608 #if YYDEBUG != 0
3609 yydebug = i;
3610 #endif
3611 }
3612 #endif
3613
3614 /* yy_getc () returns the next available character from input or EOF.
3615 yy_ungetc (c) makes `c' the next character to read.
3616 init_yy_io (get, unget, type, location) makes the function GET the
3617 installed function for getting the next character, makes UNGET the
3618 installed function for un-getting a character, sets the type of stream
3619 (either string or file) from TYPE, and makes LOCATION point to where
3620 the input is coming from. */
3621
3622 /* Unconditionally returns end-of-file. */
3623 int
3624 return_EOF ()
3625 {
3626 return (EOF);
3627 }
3628
3629 /* Variable containing the current get and unget functions.
3630 See ./input.h for a clearer description. */
3631 BASH_INPUT bash_input;
3632
3633 /* Set all of the fields in BASH_INPUT to NULL. Free bash_input.name if it
3634 is non-null, avoiding a memory leak. */
3635 void
3636 initialize_bash_input ()
3637 {
3638 bash_input.type = st_none;
3639 FREE (bash_input.name);
3640 bash_input.name = (char *)NULL;
3641 bash_input.location.file = (FILE *)NULL;
3642 bash_input.location.string = (char *)NULL;
3643 bash_input.getter = (sh_cget_func_t *)NULL;
3644 bash_input.ungetter = (sh_cunget_func_t *)NULL;
3645 }
3646
3647 /* Set the contents of the current bash input stream from
3648 GET, UNGET, TYPE, NAME, and LOCATION. */
3649 void
3650 init_yy_io (get, unget, type, name, location)
3651 sh_cget_func_t *get;
3652 sh_cunget_func_t *unget;
3653 enum stream_type type;
3654 const char *name;
3655 INPUT_STREAM location;
3656 {
3657 bash_input.type = type;
3658 FREE (bash_input.name);
3659 bash_input.name = name ? savestring (name) : (char *)NULL;
3660
3661 /* XXX */
3662 #if defined (CRAY)
3663 memcpy((char *)&bash_input.location.string, (char *)&location.string, sizeof(location));
3664 #else
3665 bash_input.location = location;
3666 #endif
3667 bash_input.getter = get;
3668 bash_input.ungetter = unget;
3669 }
3670
3671 char *
3672 yy_input_name ()
3673 {
3674 return (bash_input.name ? bash_input.name : "stdin");
3675 }
3676
3677 /* Call this to get the next character of input. */
3678 static int
3679 yy_getc ()
3680 {
3681 return (*(bash_input.getter)) ();
3682 }
3683
3684 /* Call this to unget C. That is, to make C the next character
3685 to be read. */
3686 static int
3687 yy_ungetc (c)
3688 int c;
3689 {
3690 return (*(bash_input.ungetter)) (c);
3691 }
3692
3693 #if defined (BUFFERED_INPUT)
3694 #ifdef INCLUDE_UNUSED
3695 int
3696 input_file_descriptor ()
3697 {
3698 switch (bash_input.type)
3699 {
3700 case st_stream:
3701 return (fileno (bash_input.location.file));
3702 case st_bstream:
3703 return (bash_input.location.buffered_fd);
3704 case st_stdin:
3705 default:
3706 return (fileno (stdin));
3707 }
3708 }
3709 #endif
3710 #endif /* BUFFERED_INPUT */
3711
3712 /* **************************************************************** */
3713 /* */
3714 /* Let input be read from readline (). */
3715 /* */
3716 /* **************************************************************** */
3717
3718 #if defined (READLINE)
3719 char *current_readline_prompt = (char *)NULL;
3720 char *current_readline_line = (char *)NULL;
3721 int current_readline_line_index = 0;
3722
3723 static int
3724 yy_readline_get ()
3725 {
3726 SigHandler *old_sigint;
3727 int line_len;
3728 unsigned char c;
3729
3730 if (current_readline_line == 0)
3731 {
3732 if (bash_readline_initialized == 0)
3733 initialize_readline ();
3734
3735 #if defined (JOB_CONTROL)
3736 if (job_control)
3737 give_terminal_to (shell_pgrp, 0);
3738 #endif /* JOB_CONTROL */
3739
3740 old_sigint = IMPOSSIBLE_TRAP_HANDLER;
3741 if (signal_is_ignored (SIGINT) == 0)
3742 {
3743 /* interrupt_immediately++; */
3744 old_sigint = (SigHandler *)set_signal_handler (SIGINT, sigint_sighandler);
3745 }
3746
3747 current_readline_line = readline (current_readline_prompt ?
3748 current_readline_prompt : "");
3749
3750 CHECK_TERMSIG;
3751 if (signal_is_ignored (SIGINT) == 0)
3752 {
3753 /* interrupt_immediately--; */
3754 if (old_sigint != IMPOSSIBLE_TRAP_HANDLER)
3755 set_signal_handler (SIGINT, old_sigint);
3756 }
3757
3758 #if 0
3759 /* Reset the prompt to the decoded value of prompt_string_pointer. */
3760 reset_readline_prompt ();
3761 #endif
3762
3763 if (current_readline_line == 0)
3764 return (EOF);
3765
3766 current_readline_line_index = 0;
3767 line_len = strlen (current_readline_line);
3768
3769 current_readline_line = (char *)xrealloc (current_readline_line, 2 + line_len);
3770 current_readline_line[line_len++] = '\n';
3771 current_readline_line[line_len] = '\0';
3772 }
3773
3774 if (current_readline_line[current_readline_line_index] == 0)
3775 {
3776 free (current_readline_line);
3777 current_readline_line = (char *)NULL;
3778 return (yy_readline_get ());
3779 }
3780 else
3781 {
3782 c = current_readline_line[current_readline_line_index++];
3783 return (c);
3784 }
3785 }
3786
3787 static int
3788 yy_readline_unget (c)
3789 int c;
3790 {
3791 if (current_readline_line_index && current_readline_line)
3792 current_readline_line[--current_readline_line_index] = c;
3793 return (c);
3794 }
3795
3796 void
3797 with_input_from_stdin ()
3798 {
3799 INPUT_STREAM location;
3800
3801 if (bash_input.type != st_stdin && stream_on_stack (st_stdin) == 0)
3802 {
3803 location.string = current_readline_line;
3804 init_yy_io (yy_readline_get, yy_readline_unget,
3805 st_stdin, "readline stdin", location);
3806 }
3807 }
3808
3809 #else /* !READLINE */
3810
3811 void
3812 with_input_from_stdin ()
3813 {
3814 with_input_from_stream (stdin, "stdin");
3815 }
3816 #endif /* !READLINE */
3817
3818 /* **************************************************************** */
3819 /* */
3820 /* Let input come from STRING. STRING is zero terminated. */
3821 /* */
3822 /* **************************************************************** */
3823
3824 static int
3825 yy_string_get ()
3826 {
3827 register char *string;
3828 register unsigned char c;
3829
3830 string = bash_input.location.string;
3831
3832 /* If the string doesn't exist, or is empty, EOF found. */
3833 if (string && *string)
3834 {
3835 c = *string++;
3836 bash_input.location.string = string;
3837 return (c);
3838 }
3839 else
3840 return (EOF);
3841 }
3842
3843 static int
3844 yy_string_unget (c)
3845 int c;
3846 {
3847 *(--bash_input.location.string) = c;
3848 return (c);
3849 }
3850
3851 void
3852 with_input_from_string (string, name)
3853 char *string;
3854 const char *name;
3855 {
3856 INPUT_STREAM location;
3857
3858 location.string = string;
3859 init_yy_io (yy_string_get, yy_string_unget, st_string, name, location);
3860 }
3861
3862 /* Count the number of characters we've consumed from bash_input.location.string
3863 and read into shell_input_line, but have not returned from shell_getc.
3864 That is the true input location. Rewind bash_input.location.string by
3865 that number of characters, so it points to the last character actually
3866 consumed by the parser. */
3867 static void
3868 rewind_input_string ()
3869 {
3870 int xchars;
3871
3872 /* number of unconsumed characters in the input -- XXX need to take newlines
3873 into account, e.g., $(...\n) */
3874 xchars = shell_input_line_len - shell_input_line_index;
3875 if (bash_input.location.string[-1] == '\n')
3876 xchars++;
3877
3878 /* XXX - how to reflect bash_input.location.string back to string passed to
3879 parse_and_execute or xparse_dolparen? xparse_dolparen needs to know how
3880 far into the string we parsed. parse_and_execute knows where bash_input.
3881 location.string is, and how far from orig_string that is -- that's the
3882 number of characters the command consumed. */
3883
3884 /* bash_input.location.string - xchars should be where we parsed to */
3885 /* need to do more validation on xchars value for sanity -- test cases. */
3886 bash_input.location.string -= xchars;
3887 }
3888
3889 /* **************************************************************** */
3890 /* */
3891 /* Let input come from STREAM. */
3892 /* */
3893 /* **************************************************************** */
3894
3895 /* These two functions used to test the value of the HAVE_RESTARTABLE_SYSCALLS
3896 define, and just use getc/ungetc if it was defined, but since bash
3897 installs its signal handlers without the SA_RESTART flag, some signals
3898 (like SIGCHLD, SIGWINCH, etc.) received during a read(2) will not cause
3899 the read to be restarted. We need to restart it ourselves. */
3900
3901 static int
3902 yy_stream_get ()
3903 {
3904 int result;
3905
3906 result = EOF;
3907 if (bash_input.location.file)
3908 {
3909 #if 0
3910 if (interactive)
3911 interrupt_immediately++;
3912 #endif
3913
3914 /* XXX - don't need terminate_immediately; getc_with_restart checks
3915 for terminating signals itself if read returns < 0 */
3916 result = getc_with_restart (bash_input.location.file);
3917
3918 #if 0
3919 if (interactive)
3920 interrupt_immediately--;
3921 #endif
3922 }
3923 return (result);
3924 }
3925
3926 static int
3927 yy_stream_unget (c)
3928 int c;
3929 {
3930 return (ungetc_with_restart (c, bash_input.location.file));
3931 }
3932
3933 void
3934 with_input_from_stream (stream, name)
3935 FILE *stream;
3936 const char *name;
3937 {
3938 INPUT_STREAM location;
3939
3940 location.file = stream;
3941 init_yy_io (yy_stream_get, yy_stream_unget, st_stream, name, location);
3942 }
3943
3944 typedef struct stream_saver {
3945 struct stream_saver *next;
3946 BASH_INPUT bash_input;
3947 int line;
3948 #if defined (BUFFERED_INPUT)
3949 BUFFERED_STREAM *bstream;
3950 #endif /* BUFFERED_INPUT */
3951 } STREAM_SAVER;
3952
3953 /* The globally known line number. */
3954 int line_number = 0;
3955
3956 /* The line number offset set by assigning to LINENO. Not currently used. */
3957 int line_number_base = 0;
3958
3959 #if defined (COND_COMMAND)
3960 static int cond_lineno;
3961 static int cond_token;
3962 #endif
3963
3964 STREAM_SAVER *stream_list = (STREAM_SAVER *)NULL;
3965
3966 void
3967 push_stream (reset_lineno)
3968 int reset_lineno;
3969 {
3970 STREAM_SAVER *saver = (STREAM_SAVER *)xmalloc (sizeof (STREAM_SAVER));
3971
3972 xbcopy ((char *)&bash_input, (char *)&(saver->bash_input), sizeof (BASH_INPUT));
3973
3974 #if defined (BUFFERED_INPUT)
3975 saver->bstream = (BUFFERED_STREAM *)NULL;
3976 /* If we have a buffered stream, clear out buffers[fd]. */
3977 if (bash_input.type == st_bstream && bash_input.location.buffered_fd >= 0)
3978 saver->bstream = set_buffered_stream (bash_input.location.buffered_fd,
3979 (BUFFERED_STREAM *)NULL);
3980 #endif /* BUFFERED_INPUT */
3981
3982 saver->line = line_number;
3983 bash_input.name = (char *)NULL;
3984 saver->next = stream_list;
3985 stream_list = saver;
3986 EOF_Reached = 0;
3987 if (reset_lineno)
3988 line_number = 0;
3989 }
3990
3991 void
3992 pop_stream ()
3993 {
3994 if (!stream_list)
3995 EOF_Reached = 1;
3996 else
3997 {
3998 STREAM_SAVER *saver = stream_list;
3999
4000 EOF_Reached = 0;
4001 stream_list = stream_list->next;
4002
4003 init_yy_io (saver->bash_input.getter,
4004 saver->bash_input.ungetter,
4005 saver->bash_input.type,
4006 saver->bash_input.name,
4007 saver->bash_input.location);
4008
4009 #if defined (BUFFERED_INPUT)
4010 /* If we have a buffered stream, restore buffers[fd]. */
4011 /* If the input file descriptor was changed while this was on the
4012 save stack, update the buffered fd to the new file descriptor and
4013 re-establish the buffer <-> bash_input fd correspondence. */
4014 if (bash_input.type == st_bstream && bash_input.location.buffered_fd >= 0)
4015 {
4016 if (bash_input_fd_changed)
4017 {
4018 bash_input_fd_changed = 0;
4019 if (default_buffered_input >= 0)
4020 {
4021 bash_input.location.buffered_fd = default_buffered_input;
4022 saver->bstream->b_fd = default_buffered_input;
4023 SET_CLOSE_ON_EXEC (default_buffered_input);
4024 }
4025 }
4026 /* XXX could free buffered stream returned as result here. */
4027 set_buffered_stream (bash_input.location.buffered_fd, saver->bstream);
4028 }
4029 #endif /* BUFFERED_INPUT */
4030
4031 line_number = saver->line;
4032
4033 FREE (saver->bash_input.name);
4034 free (saver);
4035 }
4036 }
4037
4038 /* Return 1 if a stream of type TYPE is saved on the stack. */
4039 int
4040 stream_on_stack (type)
4041 enum stream_type type;
4042 {
4043 register STREAM_SAVER *s;
4044
4045 for (s = stream_list; s; s = s->next)
4046 if (s->bash_input.type == type)
4047 return 1;
4048 return 0;
4049 }
4050
4051 /* Save the current token state and return it in a malloced array. */
4052 int *
4053 save_token_state ()
4054 {
4055 int *ret;
4056
4057 ret = (int *)xmalloc (4 * sizeof (int));
4058 ret[0] = last_read_token;
4059 ret[1] = token_before_that;
4060 ret[2] = two_tokens_ago;
4061 ret[3] = current_token;
4062 return ret;
4063 }
4064
4065 void
4066 restore_token_state (ts)
4067 int *ts;
4068 {
4069 if (ts == 0)
4070 return;
4071 last_read_token = ts[0];
4072 token_before_that = ts[1];
4073 two_tokens_ago = ts[2];
4074 current_token = ts[3];
4075 }
4076
4077 /*
4078 * This is used to inhibit alias expansion and reserved word recognition
4079 * inside case statement pattern lists. A `case statement pattern list' is:
4080 *
4081 * everything between the `in' in a `case word in' and the next ')'
4082 * or `esac'
4083 * everything between a `;;' and the next `)' or `esac'
4084 */
4085
4086 #if defined (ALIAS) || defined (DPAREN_ARITHMETIC)
4087
4088 #define END_OF_ALIAS 0
4089
4090 /*
4091 * Pseudo-global variables used in implementing token-wise alias expansion.
4092 */
4093
4094 /*
4095 * Pushing and popping strings. This works together with shell_getc to
4096 * implement alias expansion on a per-token basis.
4097 */
4098
4099 #define PSH_ALIAS 0x01
4100 #define PSH_DPAREN 0x02
4101 #define PSH_SOURCE 0x04
4102
4103 typedef struct string_saver {
4104 struct string_saver *next;
4105 int expand_alias; /* Value to set expand_alias to when string is popped. */
4106 char *saved_line;
4107 #if defined (ALIAS)
4108 alias_t *expander; /* alias that caused this line to be pushed. */
4109 #endif
4110 size_t saved_line_size, saved_line_index;
4111 int saved_line_terminator;
4112 int flags;
4113 } STRING_SAVER;
4114
4115 STRING_SAVER *pushed_string_list = (STRING_SAVER *)NULL;
4116
4117 /*
4118 * Push the current shell_input_line onto a stack of such lines and make S
4119 * the current input. Used when expanding aliases. EXPAND is used to set
4120 * the value of expand_next_token when the string is popped, so that the
4121 * word after the alias in the original line is handled correctly when the
4122 * alias expands to multiple words. TOKEN is the token that was expanded
4123 * into S; it is saved and used to prevent infinite recursive expansion.
4124 */
4125 static void
4126 push_string (s, expand, ap)
4127 char *s;
4128 int expand;
4129 alias_t *ap;
4130 {
4131 STRING_SAVER *temp = (STRING_SAVER *)xmalloc (sizeof (STRING_SAVER));
4132
4133 temp->expand_alias = expand;
4134 temp->saved_line = shell_input_line;
4135 temp->saved_line_size = shell_input_line_size;
4136 temp->saved_line_index = shell_input_line_index;
4137 temp->saved_line_terminator = shell_input_line_terminator;
4138 temp->flags = 0;
4139 #if defined (ALIAS)
4140 temp->expander = ap;
4141 if (ap)
4142 temp->flags = PSH_ALIAS;
4143 #endif
4144 temp->next = pushed_string_list;
4145 pushed_string_list = temp;
4146
4147 #if defined (ALIAS)
4148 if (ap)
4149 ap->flags |= AL_BEINGEXPANDED;
4150 #endif
4151
4152 shell_input_line = s;
4153 shell_input_line_size = STRLEN (s);
4154 shell_input_line_index = 0;
4155 shell_input_line_terminator = '\0';
4156 #if 0
4157 parser_state &= ~PST_ALEXPNEXT; /* XXX */
4158 #endif
4159
4160 set_line_mbstate ();
4161 }
4162
4163 /*
4164 * Make the top of the pushed_string stack be the current shell input.
4165 * Only called when there is something on the stack. Called from shell_getc
4166 * when it thinks it has consumed the string generated by an alias expansion
4167 * and needs to return to the original input line.
4168 */
4169 static void
4170 pop_string ()
4171 {
4172 STRING_SAVER *t;
4173
4174 FREE (shell_input_line);
4175 shell_input_line = pushed_string_list->saved_line;
4176 shell_input_line_index = pushed_string_list->saved_line_index;
4177 shell_input_line_size = pushed_string_list->saved_line_size;
4178 shell_input_line_terminator = pushed_string_list->saved_line_terminator;
4179
4180 if (pushed_string_list->expand_alias)
4181 parser_state |= PST_ALEXPNEXT;
4182 else
4183 parser_state &= ~PST_ALEXPNEXT;
4184
4185 t = pushed_string_list;
4186 pushed_string_list = pushed_string_list->next;
4187
4188 #if defined (ALIAS)
4189 if (t->expander)
4190 t->expander->flags &= ~AL_BEINGEXPANDED;
4191 #endif
4192
4193 free ((char *)t);
4194
4195 set_line_mbstate ();
4196 }
4197
4198 static void
4199 free_string_list ()
4200 {
4201 register STRING_SAVER *t, *t1;
4202
4203 for (t = pushed_string_list; t; )
4204 {
4205 t1 = t->next;
4206 FREE (t->saved_line);
4207 #if defined (ALIAS)
4208 if (t->expander)
4209 t->expander->flags &= ~AL_BEINGEXPANDED;
4210 #endif
4211 free ((char *)t);
4212 t = t1;
4213 }
4214 pushed_string_list = (STRING_SAVER *)NULL;
4215 }
4216
4217 #endif /* ALIAS || DPAREN_ARITHMETIC */
4218
4219 void
4220 free_pushed_string_input ()
4221 {
4222 #if defined (ALIAS) || defined (DPAREN_ARITHMETIC)
4223 free_string_list ();
4224 #endif
4225 }
4226
4227 int
4228 parser_expanding_alias ()
4229 {
4230 return (expanding_alias ());
4231 }
4232
4233 void
4234 parser_save_alias ()
4235 {
4236 #if defined (ALIAS) || defined (DPAREN_ARITHMETIC)
4237 push_string ((char *)NULL, 0, (alias_t *)NULL);
4238 pushed_string_list->flags = PSH_SOURCE; /* XXX - for now */
4239 #else
4240 ;
4241 #endif
4242 }
4243
4244 void
4245 parser_restore_alias ()
4246 {
4247 #if defined (ALIAS) || defined (DPAREN_ARITHMETIC)
4248 if (pushed_string_list)
4249 pop_string ();
4250 #else
4251 ;
4252 #endif
4253 }
4254
4255 void
4256 clear_shell_input_line ()
4257 {
4258 if (shell_input_line)
4259 shell_input_line[shell_input_line_index = 0] = '\0';
4260 }
4261
4262 /* Return a line of text, taken from wherever yylex () reads input.
4263 If there is no more input, then we return NULL. If REMOVE_QUOTED_NEWLINE
4264 is non-zero, we remove unquoted \<newline> pairs. This is used by
4265 read_secondary_line to read here documents. */
4266 static char *
4267 read_a_line (remove_quoted_newline)
4268 int remove_quoted_newline;
4269 {
4270 static char *line_buffer = (char *)NULL;
4271 static int buffer_size = 0;
4272 int indx, c, peekc, pass_next;
4273
4274 #if defined (READLINE)
4275 if (no_line_editing && SHOULD_PROMPT ())
4276 #else
4277 if (SHOULD_PROMPT ())
4278 #endif
4279 print_prompt ();
4280
4281 pass_next = indx = 0;
4282 while (1)
4283 {
4284 /* Allow immediate exit if interrupted during input. */
4285 QUIT;
4286
4287 c = yy_getc ();
4288
4289 /* Ignore null bytes in input. */
4290 if (c == 0)
4291 {
4292 #if 0
4293 internal_warning ("read_a_line: ignored null byte in input");
4294 #endif
4295 continue;
4296 }
4297
4298 /* If there is no more input, then we return NULL. */
4299 if (c == EOF)
4300 {
4301 if (interactive && bash_input.type == st_stream)
4302 clearerr (stdin);
4303 if (indx == 0)
4304 return ((char *)NULL);
4305 c = '\n';
4306 }
4307
4308 /* `+2' in case the final character in the buffer is a newline. */
4309 RESIZE_MALLOCED_BUFFER (line_buffer, indx, 2, buffer_size, 128);
4310
4311 /* IF REMOVE_QUOTED_NEWLINES is non-zero, we are reading a
4312 here document with an unquoted delimiter. In this case,
4313 the line will be expanded as if it were in double quotes.
4314 We allow a backslash to escape the next character, but we
4315 need to treat the backslash specially only if a backslash
4316 quoting a backslash-newline pair appears in the line. */
4317 if (pass_next)
4318 {
4319 line_buffer[indx++] = c;
4320 pass_next = 0;
4321 }
4322 else if (c == '\\' && remove_quoted_newline)
4323 {
4324 QUIT;
4325 peekc = yy_getc ();
4326 if (peekc == '\n')
4327 {
4328 line_number++;
4329 continue; /* Make the unquoted \<newline> pair disappear. */
4330 }
4331 else
4332 {
4333 yy_ungetc (peekc);
4334 pass_next = 1;
4335 line_buffer[indx++] = c; /* Preserve the backslash. */
4336 }
4337 }
4338 else
4339 line_buffer[indx++] = c;
4340
4341 if (c == '\n')
4342 {
4343 line_buffer[indx] = '\0';
4344 return (line_buffer);
4345 }
4346 }
4347 }
4348
4349 /* Return a line as in read_a_line (), but insure that the prompt is
4350 the secondary prompt. This is used to read the lines of a here
4351 document. REMOVE_QUOTED_NEWLINE is non-zero if we should remove
4352 newlines quoted with backslashes while reading the line. It is
4353 non-zero unless the delimiter of the here document was quoted. */
4354 char *
4355 read_secondary_line (remove_quoted_newline)
4356 int remove_quoted_newline;
4357 {
4358 char *ret;
4359 int n, c;
4360
4361 prompt_string_pointer = &ps2_prompt;
4362 if (SHOULD_PROMPT())
4363 prompt_again ();
4364 ret = read_a_line (remove_quoted_newline);
4365 #if defined (HISTORY)
4366 if (ret && remember_on_history && (parser_state & PST_HEREDOC))
4367 {
4368 /* To make adding the here-document body right, we need to rely on
4369 history_delimiting_chars() returning \n for the first line of the
4370 here-document body and the null string for the second and subsequent
4371 lines, so we avoid double newlines.
4372 current_command_line_count == 2 for the first line of the body. */
4373
4374 current_command_line_count++;
4375 maybe_add_history (ret);
4376 }
4377 #endif /* HISTORY */
4378 return ret;
4379 }
4380
4381 /* **************************************************************** */
4382 /* */
4383 /* YYLEX () */
4384 /* */
4385 /* **************************************************************** */
4386
4387 /* Reserved words. These are only recognized as the first word of a
4388 command. */
4389 STRING_INT_ALIST word_token_alist[] = {
4390 { "if", IF },
4391 { "then", THEN },
4392 { "else", ELSE },
4393 { "elif", ELIF },
4394 { "fi", FI },
4395 { "case", CASE },
4396 { "esac", ESAC },
4397 { "for", FOR },
4398 #if defined (SELECT_COMMAND)
4399 { "select", SELECT },
4400 #endif
4401 { "while", WHILE },
4402 { "until", UNTIL },
4403 { "do", DO },
4404 { "done", DONE },
4405 { "in", IN },
4406 { "function", FUNCTION },
4407 #if defined (COMMAND_TIMING)
4408 { "time", TIME },
4409 #endif
4410 { "{", '{' },
4411 { "}", '}' },
4412 { "!", BANG },
4413 #if defined (COND_COMMAND)
4414 { "[[", COND_START },
4415 { "]]", COND_END },
4416 #endif
4417 #if defined (COPROCESS_SUPPORT)
4418 { "coproc", COPROC },
4419 #endif
4420 { (char *)NULL, 0}
4421 };
4422
4423 /* other tokens that can be returned by read_token() */
4424 STRING_INT_ALIST other_token_alist[] = {
4425 /* Multiple-character tokens with special values */
4426 { "--", TIMEIGN },
4427 { "-p", TIMEOPT },
4428 { "&&", AND_AND },
4429 { "||", OR_OR },
4430 { ">>", GREATER_GREATER },
4431 { "<<", LESS_LESS },
4432 { "<&", LESS_AND },
4433 { ">&", GREATER_AND },
4434 { ";;", SEMI_SEMI },
4435 { ";&", SEMI_AND },
4436 { ";;&", SEMI_SEMI_AND },
4437 { "<<-", LESS_LESS_MINUS },
4438 { "<<<", LESS_LESS_LESS },
4439 { "&>", AND_GREATER },
4440 { "&>>", AND_GREATER_GREATER },
4441 { "<>", LESS_GREATER },
4442 { ">|", GREATER_BAR },
4443 { "|&", BAR_AND },
4444 { "EOF", yacc_EOF },
4445 /* Tokens whose value is the character itself */
4446 { ">", '>' },
4447 { "<", '<' },
4448 { "-", '-' },
4449 { "{", '{' },
4450 { "}", '}' },
4451 { ";", ';' },
4452 { "(", '(' },
4453 { ")", ')' },
4454 { "|", '|' },
4455 { "&", '&' },
4456 { "newline", '\n' },
4457 { (char *)NULL, 0}
4458 };
4459
4460 /* others not listed here:
4461 WORD look at yylval.word
4462 ASSIGNMENT_WORD look at yylval.word
4463 NUMBER look at yylval.number
4464 ARITH_CMD look at yylval.word_list
4465 ARITH_FOR_EXPRS look at yylval.word_list
4466 COND_CMD look at yylval.command
4467 */
4468
4469 /* These are used by read_token_word, but appear up here so that shell_getc
4470 can use them to decide when to add otherwise blank lines to the history. */
4471
4472 /* The primary delimiter stack. */
4473 struct dstack dstack = { (char *)NULL, 0, 0 };
4474
4475 /* A temporary delimiter stack to be used when decoding prompt strings.
4476 This is needed because command substitutions in prompt strings (e.g., PS2)
4477 can screw up the parser's quoting state. */
4478 static struct dstack temp_dstack = { (char *)NULL, 0, 0 };
4479
4480 /* Macro for accessing the top delimiter on the stack. Returns the
4481 delimiter or zero if none. */
4482 #define current_delimiter(ds) \
4483 (ds.delimiter_depth ? ds.delimiters[ds.delimiter_depth - 1] : 0)
4484
4485 #define push_delimiter(ds, character) \
4486 do \
4487 { \
4488 if (ds.delimiter_depth + 2 > ds.delimiter_space) \
4489 ds.delimiters = (char *)xrealloc \
4490 (ds.delimiters, (ds.delimiter_space += 10) * sizeof (char)); \
4491 ds.delimiters[ds.delimiter_depth] = character; \
4492 ds.delimiter_depth++; \
4493 } \
4494 while (0)
4495
4496 #define pop_delimiter(ds) ds.delimiter_depth--
4497
4498 /* Return the next shell input character. This always reads characters
4499 from shell_input_line; when that line is exhausted, it is time to
4500 read the next line. This is called by read_token when the shell is
4501 processing normal command input. */
4502
4503 /* This implements one-character lookahead/lookbehind across physical input
4504 lines, to avoid something being lost because it's pushed back with
4505 shell_ungetc when we're at the start of a line. */
4506 static int eol_ungetc_lookahead = 0;
4507
4508 static int
4509 shell_getc (remove_quoted_newline)
4510 int remove_quoted_newline;
4511 {
4512 register int i;
4513 int c, truncating, last_was_backslash;
4514 unsigned char uc;
4515
4516 QUIT;
4517
4518 last_was_backslash = 0;
4519 if (sigwinch_received)
4520 {
4521 sigwinch_received = 0;
4522 get_new_window_size (0, (int *)0, (int *)0);
4523 }
4524
4525 if (eol_ungetc_lookahead)
4526 {
4527 c = eol_ungetc_lookahead;
4528 eol_ungetc_lookahead = 0;
4529 return (c);
4530 }
4531
4532 #if defined (ALIAS) || defined (DPAREN_ARITHMETIC)
4533 /* If shell_input_line[shell_input_line_index] == 0, but there is
4534 something on the pushed list of strings, then we don't want to go
4535 off and get another line. We let the code down below handle it. */
4536
4537 if (!shell_input_line || ((!shell_input_line[shell_input_line_index]) &&
4538 (pushed_string_list == (STRING_SAVER *)NULL)))
4539 #else /* !ALIAS && !DPAREN_ARITHMETIC */
4540 if (!shell_input_line || !shell_input_line[shell_input_line_index])
4541 #endif /* !ALIAS && !DPAREN_ARITHMETIC */
4542 {
4543 line_number++;
4544
4545 /* Let's not let one really really long line blow up memory allocation */
4546 if (shell_input_line && shell_input_line_size >= 32768)
4547 {
4548 free (shell_input_line);
4549 shell_input_line = 0;
4550 shell_input_line_size = 0;
4551 }
4552
4553 restart_read:
4554
4555 /* Allow immediate exit if interrupted during input. */
4556 QUIT;
4557
4558 i = truncating = 0;
4559 shell_input_line_terminator = 0;
4560
4561 /* If the shell is interatctive, but not currently printing a prompt
4562 (interactive_shell && interactive == 0), we don't want to print
4563 notifies or cleanup the jobs -- we want to defer it until we do
4564 print the next prompt. */
4565 if (interactive_shell == 0 || SHOULD_PROMPT())
4566 {
4567 #if defined (JOB_CONTROL)
4568 /* This can cause a problem when reading a command as the result
4569 of a trap, when the trap is called from flush_child. This call
4570 had better not cause jobs to disappear from the job table in
4571 that case, or we will have big trouble. */
4572 notify_and_cleanup ();
4573 #else /* !JOB_CONTROL */
4574 cleanup_dead_jobs ();
4575 #endif /* !JOB_CONTROL */
4576 }
4577
4578 #if defined (READLINE)
4579 if (no_line_editing && SHOULD_PROMPT())
4580 #else
4581 if (SHOULD_PROMPT())
4582 #endif
4583 print_prompt ();
4584
4585 if (bash_input.type == st_stream)
4586 clearerr (stdin);
4587
4588 while (1)
4589 {
4590 c = yy_getc ();
4591
4592 /* Allow immediate exit if interrupted during input. */
4593 QUIT;
4594
4595 if (c == '\0')
4596 {
4597 #if 0
4598 internal_warning ("shell_getc: ignored null byte in input");
4599 #endif
4600 continue;
4601 }
4602
4603 /* Theoretical overflow */
4604 /* If we can't put 256 bytes more into the buffer, allocate
4605 everything we can and fill it as full as we can. */
4606 /* XXX - we ignore rest of line using `truncating' flag */
4607 if (shell_input_line_size > (SIZE_MAX - 256))
4608 {
4609 size_t n;
4610
4611 n = SIZE_MAX - i; /* how much more can we put into the buffer? */
4612 if (n <= 2) /* we have to save 1 for the newline added below */
4613 {
4614 if (truncating == 0)
4615 internal_warning(_("shell_getc: shell_input_line_size (%zu) exceeds SIZE_MAX (%lu): line truncated"), shell_input_line_size, (unsigned long)SIZE_MAX);
4616 shell_input_line[i] = '\0';
4617 truncating = 1;
4618 }
4619 if (shell_input_line_size < SIZE_MAX)
4620 {
4621 shell_input_line_size = SIZE_MAX;
4622 shell_input_line = xrealloc (shell_input_line, shell_input_line_size);
4623 }
4624 }
4625 else
4626 RESIZE_MALLOCED_BUFFER (shell_input_line, i, 2, shell_input_line_size, 256);
4627
4628 if (c == EOF)
4629 {
4630 if (bash_input.type == st_stream)
4631 clearerr (stdin);
4632
4633 if (i == 0)
4634 shell_input_line_terminator = EOF;
4635
4636 shell_input_line[i] = '\0';
4637 break;
4638 }
4639
4640 if (truncating == 0 || c == '\n')
4641 shell_input_line[i++] = c;
4642
4643 if (c == '\n')
4644 {
4645 shell_input_line[--i] = '\0';
4646 current_command_line_count++;
4647 break;
4648 }
4649
4650 last_was_backslash = last_was_backslash == 0 && c == '\\';
4651 }
4652
4653 shell_input_line_index = 0;
4654 shell_input_line_len = i; /* == strlen (shell_input_line) */
4655
4656 set_line_mbstate ();
4657
4658 #if defined (HISTORY)
4659 if (remember_on_history && shell_input_line && shell_input_line[0])
4660 {
4661 char *expansions;
4662 # if defined (BANG_HISTORY)
4663 int old_hist;
4664
4665 /* If the current delimiter is a single quote, we should not be
4666 performing history expansion, even if we're on a different
4667 line from the original single quote. */
4668 old_hist = history_expansion_inhibited;
4669 if (current_delimiter (dstack) == '\'')
4670 history_expansion_inhibited = 1;
4671 # endif
4672 /* Calling with a third argument of 1 allows remember_on_history to
4673 determine whether or not the line is saved to the history list */
4674 expansions = pre_process_line (shell_input_line, 1, 1);
4675 # if defined (BANG_HISTORY)
4676 history_expansion_inhibited = old_hist;
4677 # endif
4678 if (expansions != shell_input_line)
4679 {
4680 free (shell_input_line);
4681 shell_input_line = expansions;
4682 shell_input_line_len = shell_input_line ?
4683 strlen (shell_input_line) : 0;
4684 if (shell_input_line_len == 0)
4685 current_command_line_count--;
4686
4687 /* We have to force the xrealloc below because we don't know
4688 the true allocated size of shell_input_line anymore. */
4689 shell_input_line_size = shell_input_line_len;
4690
4691 set_line_mbstate ();
4692 }
4693 }
4694 /* Try to do something intelligent with blank lines encountered while
4695 entering multi-line commands. XXX - this is grotesque */
4696 else if (remember_on_history && shell_input_line &&
4697 shell_input_line[0] == '\0' &&
4698 current_command_line_count > 1)
4699 {
4700 if (current_delimiter (dstack))
4701 /* We know shell_input_line[0] == 0 and we're reading some sort of
4702 quoted string. This means we've got a line consisting of only
4703 a newline in a quoted string. We want to make sure this line
4704 gets added to the history. */
4705 maybe_add_history (shell_input_line);
4706 else
4707 {
4708 char *hdcs;
4709 hdcs = history_delimiting_chars (shell_input_line);
4710 if (hdcs && hdcs[0] == ';')
4711 maybe_add_history (shell_input_line);
4712 }
4713 }
4714
4715 #endif /* HISTORY */
4716
4717 if (shell_input_line)
4718 {
4719 /* Lines that signify the end of the shell's input should not be
4720 echoed. We should not echo lines while parsing command
4721 substitutions with recursive calls into the parsing engine; those
4722 should only be echoed once when we read the word. That is the
4723 reason for the test against shell_eof_token, which is set to a
4724 right paren when parsing the contents of command substitutions. */
4725 if (echo_input_at_read && (shell_input_line[0] ||
4726 shell_input_line_terminator != EOF) &&
4727 shell_eof_token == 0)
4728 fprintf (stderr, "%s\n", shell_input_line);
4729 }
4730 else
4731 {
4732 shell_input_line_size = 0;
4733 prompt_string_pointer = &current_prompt_string;
4734 if (SHOULD_PROMPT ())
4735 prompt_again ();
4736 goto restart_read;
4737 }
4738
4739 /* Add the newline to the end of this string, iff the string does
4740 not already end in an EOF character. */
4741 if (shell_input_line_terminator != EOF)
4742 {
4743 if (shell_input_line_size < SIZE_MAX-3 && (shell_input_line_len+3 > shell_input_line_size))
4744 shell_input_line = (char *)xrealloc (shell_input_line,
4745 1 + (shell_input_line_size += 2));
4746
4747 /* Don't add a newline to a string that ends with a backslash if we're
4748 going to be removing quoted newlines, since that will eat the
4749 backslash. Add another backslash instead (will be removed by
4750 word expansion). */
4751 if (bash_input.type == st_string && expanding_alias() == 0 && last_was_backslash && c == EOF && remove_quoted_newline)
4752 shell_input_line[shell_input_line_len] = '\\';
4753 else
4754 shell_input_line[shell_input_line_len] = '\n';
4755 shell_input_line[shell_input_line_len + 1] = '\0';
4756
4757 set_line_mbstate ();
4758 }
4759 }
4760
4761 next_alias_char:
4762 uc = shell_input_line[shell_input_line_index];
4763
4764 if (uc)
4765 shell_input_line_index++;
4766
4767 #if defined (ALIAS) || defined (DPAREN_ARITHMETIC)
4768 /* If UC is NULL, we have reached the end of the current input string. If
4769 pushed_string_list is non-empty, it's time to pop to the previous string
4770 because we have fully consumed the result of the last alias expansion.
4771 Do it transparently; just return the next character of the string popped
4772 to. */
4773 /* If pushed_string_list != 0 but pushed_string_list->expander == 0 (not
4774 currently tested) and the flags value is not PSH_SOURCE, we are not
4775 parsing an alias, we have just saved one (push_string, when called by
4776 the parse_dparen code) In this case, just go on as well. The PSH_SOURCE
4777 case is handled below. */
4778 pop_alias:
4779 if (uc == 0 && pushed_string_list && pushed_string_list->flags != PSH_SOURCE)
4780 {
4781 pop_string ();
4782 uc = shell_input_line[shell_input_line_index];
4783 if (uc)
4784 shell_input_line_index++;
4785 }
4786 #endif /* ALIAS || DPAREN_ARITHMETIC */
4787
4788 if MBTEST(uc == '\\' && remove_quoted_newline && shell_input_line[shell_input_line_index] == '\n')
4789 {
4790 if (SHOULD_PROMPT ())
4791 prompt_again ();
4792 line_number++;
4793 /* What do we do here if we're expanding an alias whose definition
4794 includes an escaped newline? If that's the last character in the
4795 alias expansion, we just pop the pushed string list (recall that
4796 we inhibit the appending of a space in mk_alexpansion() if newline
4797 is the last character). If it's not the last character, we need
4798 to consume the quoted newline and move to the next character in
4799 the expansion. */
4800 #if defined (ALIAS)
4801 if (expanding_alias () && shell_input_line[shell_input_line_index+1] == '\0')
4802 {
4803 uc = 0;
4804 goto pop_alias;
4805 }
4806 else if (expanding_alias () && shell_input_line[shell_input_line_index+1] != '\0')
4807 {
4808 shell_input_line_index++; /* skip newline */
4809 goto next_alias_char; /* and get next character */
4810 }
4811 else
4812 #endif
4813 goto restart_read;
4814 }
4815
4816 if (uc == 0 && shell_input_line_terminator == EOF)
4817 return ((shell_input_line_index != 0) ? '\n' : EOF);
4818
4819 #if defined (ALIAS) || defined (DPAREN_ARITHMETIC)
4820 /* We already know that we are not parsing an alias expansion because of the
4821 check for expanding_alias() above. This knows how parse_and_execute
4822 handles switching to st_string input while an alias is being expanded,
4823 hence the check for pushed_string_list without pushed_string_list->expander
4824 and the check for PSH_SOURCE as pushed_string_list->flags.
4825 parse_and_execute and parse_string both change the input type to st_string
4826 and place the string to be parsed and executed into location.string, so
4827 we should not stop reading that until the pointer is '\0'.
4828 The check for shell_input_line_terminator may be superfluous.
4829
4830 This solves the problem of `.' inside a multi-line alias with embedded
4831 newlines executing things out of order. */
4832 if (uc == 0 && bash_input.type == st_string && *bash_input.location.string &&
4833 pushed_string_list && pushed_string_list->flags == PSH_SOURCE &&
4834 shell_input_line_terminator == 0)
4835 {
4836 shell_input_line_index = 0;
4837 goto restart_read;
4838 }
4839 #endif
4840
4841 return (uc);
4842 }
4843
4844 /* Put C back into the input for the shell. This might need changes for
4845 HANDLE_MULTIBYTE around EOLs. Since we (currently) never push back a
4846 character different than we read, shell_input_line_property doesn't need
4847 to change when manipulating shell_input_line. The define for
4848 last_shell_getc_is_singlebyte should take care of it, though. */
4849 static void
4850 shell_ungetc (c)
4851 int c;
4852 {
4853 if (shell_input_line && shell_input_line_index)
4854 shell_input_line[--shell_input_line_index] = c;
4855 else
4856 eol_ungetc_lookahead = c;
4857 }
4858
4859 char *
4860 parser_remaining_input ()
4861 {
4862 if (shell_input_line == 0)
4863 return 0;
4864 if (shell_input_line_index < 0 || shell_input_line_index >= shell_input_line_len)
4865 return ""; /* XXX */
4866 return (shell_input_line + shell_input_line_index);
4867 }
4868
4869 #ifdef INCLUDE_UNUSED
4870 /* Back the input pointer up by one, effectively `ungetting' a character. */
4871 static void
4872 shell_ungetchar ()
4873 {
4874 if (shell_input_line && shell_input_line_index)
4875 shell_input_line_index--;
4876 }
4877 #endif
4878
4879 /* Discard input until CHARACTER is seen, then push that character back
4880 onto the input stream. */
4881 static void
4882 discard_until (character)
4883 int character;
4884 {
4885 int c;
4886
4887 while ((c = shell_getc (0)) != EOF && c != character)
4888 ;
4889
4890 if (c != EOF)
4891 shell_ungetc (c);
4892 }
4893
4894 void
4895 execute_variable_command (command, vname)
4896 char *command, *vname;
4897 {
4898 char *last_lastarg;
4899 sh_parser_state_t ps;
4900
4901 save_parser_state (&ps);
4902 last_lastarg = get_string_value ("_");
4903 if (last_lastarg)
4904 last_lastarg = savestring (last_lastarg);
4905
4906 parse_and_execute (savestring (command), vname, SEVAL_NONINT|SEVAL_NOHIST);
4907
4908 restore_parser_state (&ps);
4909 bind_variable ("_", last_lastarg, 0);
4910 FREE (last_lastarg);
4911
4912 if (token_to_read == '\n') /* reset_parser was called */
4913 token_to_read = 0;
4914 }
4915
4916 void
4917 push_token (x)
4918 int x;
4919 {
4920 two_tokens_ago = token_before_that;
4921 token_before_that = last_read_token;
4922 last_read_token = current_token;
4923
4924 current_token = x;
4925 }
4926
4927 /* Place to remember the token. We try to keep the buffer
4928 at a reasonable size, but it can grow. */
4929 static char *token = (char *)NULL;
4930
4931 /* Current size of the token buffer. */
4932 static int token_buffer_size;
4933
4934 /* Command to read_token () explaining what we want it to do. */
4935 #define READ 0
4936 #define RESET 1
4937 #define prompt_is_ps1 \
4938 (!prompt_string_pointer || prompt_string_pointer == &ps1_prompt)
4939
4940 /* Function for yyparse to call. yylex keeps track of
4941 the last two tokens read, and calls read_token. */
4942 static int
4943 yylex ()
4944 {
4945 if (interactive && (current_token == 0 || current_token == '\n'))
4946 {
4947 /* Before we print a prompt, we might have to check mailboxes.
4948 We do this only if it is time to do so. Notice that only here
4949 is the mail alarm reset; nothing takes place in check_mail ()
4950 except the checking of mail. Please don't change this. */
4951 if (prompt_is_ps1 && parse_and_execute_level == 0 && time_to_check_mail ())
4952 {
4953 check_mail ();
4954 reset_mail_timer ();
4955 }
4956
4957 /* Avoid printing a prompt if we're not going to read anything, e.g.
4958 after resetting the parser with read_token (RESET). */
4959 if (token_to_read == 0 && SHOULD_PROMPT ())
4960 prompt_again ();
4961 }
4962
4963 two_tokens_ago = token_before_that;
4964 token_before_that = last_read_token;
4965 last_read_token = current_token;
4966 current_token = read_token (READ);
4967
4968 if ((parser_state & PST_EOFTOKEN) && current_token == shell_eof_token)
4969 {
4970 current_token = yacc_EOF;
4971 if (bash_input.type == st_string)
4972 rewind_input_string ();
4973 }
4974 parser_state &= ~PST_EOFTOKEN;
4975
4976 return (current_token);
4977 }
4978
4979 /* When non-zero, we have read the required tokens
4980 which allow ESAC to be the next one read. */
4981 static int esacs_needed_count;
4982
4983 static void
4984 push_heredoc (r)
4985 REDIRECT *r;
4986 {
4987 if (need_here_doc >= HEREDOC_MAX)
4988 {
4989 last_command_exit_value = EX_BADUSAGE;
4990 need_here_doc = 0;
4991 report_syntax_error (_("maximum here-document count exceeded"));
4992 reset_parser ();
4993 exit_shell (last_command_exit_value);
4994 }
4995 redir_stack[need_here_doc++] = r;
4996 }
4997
4998 void
4999 gather_here_documents ()
5000 {
5001 int r;
5002
5003 r = 0;
5004 here_doc_first_line = 1;
5005 while (need_here_doc > 0)
5006 {
5007 parser_state |= PST_HEREDOC;
5008 make_here_document (redir_stack[r++], line_number);
5009 parser_state &= ~PST_HEREDOC;
5010 need_here_doc--;
5011 redir_stack[r - 1] = 0; /* XXX */
5012 }
5013 here_doc_first_line = 0; /* just in case */
5014 }
5015
5016 /* When non-zero, an open-brace used to create a group is awaiting a close
5017 brace partner. */
5018 static int open_brace_count;
5019
5020 /* In the following three macros, `token' is always last_read_token */
5021
5022 /* Are we in the middle of parsing a redirection where we are about to read
5023 a word? This is used to make sure alias expansion doesn't happen in the
5024 middle of a redirection, even though we're parsing a simple command. */
5025 #define parsing_redirection(token) \
5026 (token == '<' || token == '>' || \
5027 token == GREATER_GREATER || token == GREATER_BAR || \
5028 token == LESS_GREATER || token == LESS_LESS_MINUS || \
5029 token == LESS_LESS || token == LESS_LESS_LESS || \
5030 token == LESS_AND || token == GREATER_AND || token == AND_GREATER)
5031
5032 /* Is `token' one that will allow a WORD to be read in a command position?
5033 We can read a simple command name on which we should attempt alias expansion
5034 or we can read an assignment statement. */
5035 #define command_token_position(token) \
5036 (((token) == ASSIGNMENT_WORD) || \
5037 ((parser_state&PST_REDIRLIST) && parsing_redirection(token) == 0) || \
5038 ((token) != SEMI_SEMI && (token) != SEMI_AND && (token) != SEMI_SEMI_AND && reserved_word_acceptable(token)))
5039
5040 /* Are we in a position where we can read an assignment statement? */
5041 #define assignment_acceptable(token) \
5042 (command_token_position(token) && ((parser_state & PST_CASEPAT) == 0))
5043
5044 /* Check to see if TOKEN is a reserved word and return the token
5045 value if it is. */
5046 #define CHECK_FOR_RESERVED_WORD(tok) \
5047 do { \
5048 if (!dollar_present && !quoted && \
5049 reserved_word_acceptable (last_read_token)) \
5050 { \
5051 int i; \
5052 for (i = 0; word_token_alist[i].word != (char *)NULL; i++) \
5053 if (STREQ (tok, word_token_alist[i].word)) \
5054 { \
5055 if ((parser_state & PST_CASEPAT) && (word_token_alist[i].token != ESAC)) \
5056 break; \
5057 if (word_token_alist[i].token == TIME && time_command_acceptable () == 0) \
5058 break; \
5059 if ((parser_state & PST_CASEPAT) && last_read_token == '|' && word_token_alist[i].token == ESAC) \
5060 break; /* Posix grammar rule 4 */ \
5061 if (word_token_alist[i].token == ESAC) \
5062 parser_state &= ~(PST_CASEPAT|PST_CASESTMT); \
5063 else if (word_token_alist[i].token == CASE) \
5064 parser_state |= PST_CASESTMT; \
5065 else if (word_token_alist[i].token == COND_END) \
5066 parser_state &= ~(PST_CONDCMD|PST_CONDEXPR); \
5067 else if (word_token_alist[i].token == COND_START) \
5068 parser_state |= PST_CONDCMD; \
5069 else if (word_token_alist[i].token == '{') \
5070 open_brace_count++; \
5071 else if (word_token_alist[i].token == '}' && open_brace_count) \
5072 open_brace_count--; \
5073 return (word_token_alist[i].token); \
5074 } \
5075 } \
5076 } while (0)
5077
5078 #if defined (ALIAS)
5079
5080 /* OK, we have a token. Let's try to alias expand it, if (and only if)
5081 it's eligible.
5082
5083 It is eligible for expansion if EXPAND_ALIASES is set, and
5084 the token is unquoted and the last token read was a command
5085 separator (or expand_next_token is set), and we are currently
5086 processing an alias (pushed_string_list is non-empty) and this
5087 token is not the same as the current or any previously
5088 processed alias.
5089
5090 Special cases that disqualify:
5091 In a pattern list in a case statement (parser_state & PST_CASEPAT). */
5092
5093 static char *
5094 mk_alexpansion (s)
5095 char *s;
5096 {
5097 int l;
5098 char *r;
5099
5100 l = strlen (s);
5101 r = xmalloc (l + 2);
5102 strcpy (r, s);
5103 /* If the last character in the alias is a newline, don't add a trailing
5104 space to the expansion. Works with shell_getc above. */
5105 if (r[l - 1] != ' ' && r[l - 1] != '\n' && shellmeta(r[l - 1]) == 0)
5106 r[l++] = ' ';
5107 r[l] = '\0';
5108 return r;
5109 }
5110
5111 static int
5112 alias_expand_token (tokstr)
5113 char *tokstr;
5114 {
5115 char *expanded;
5116 alias_t *ap;
5117
5118 if (((parser_state & PST_ALEXPNEXT) || command_token_position (last_read_token)) &&
5119 (parser_state & PST_CASEPAT) == 0)
5120 {
5121 ap = find_alias (tokstr);
5122
5123 /* Currently expanding this token. */
5124 if (ap && (ap->flags & AL_BEINGEXPANDED))
5125 return (NO_EXPANSION);
5126
5127 /* mk_alexpansion puts an extra space on the end of the alias expansion,
5128 so the lookahead by the parser works right. If this gets changed,
5129 make sure the code in shell_getc that deals with reaching the end of
5130 an expanded alias is changed with it. */
5131 expanded = ap ? mk_alexpansion (ap->value) : (char *)NULL;
5132
5133 if (expanded)
5134 {
5135 push_string (expanded, ap->flags & AL_EXPANDNEXT, ap);
5136 return (RE_READ_TOKEN);
5137 }
5138 else
5139 /* This is an eligible token that does not have an expansion. */
5140 return (NO_EXPANSION);
5141 }
5142 return (NO_EXPANSION);
5143 }
5144 #endif /* ALIAS */
5145
5146 static int
5147 time_command_acceptable ()
5148 {
5149 #if defined (COMMAND_TIMING)
5150 int i;
5151
5152 if (posixly_correct && shell_compatibility_level > 41)
5153 {
5154 /* Quick check of the rest of the line to find the next token. If it
5155 begins with a `-', Posix says to not return `time' as the token.
5156 This was interp 267. */
5157 i = shell_input_line_index;
5158 while (i < shell_input_line_len && (shell_input_line[i] == ' ' || shell_input_line[i] == '\t'))
5159 i++;
5160 if (shell_input_line[i] == '-')
5161 return 0;
5162 }
5163
5164 switch (last_read_token)
5165 {
5166 case 0:
5167 case ';':
5168 case '\n':
5169 if (token_before_that == '|')
5170 return (0);
5171 /* FALLTHROUGH */
5172 case AND_AND:
5173 case OR_OR:
5174 case '&':
5175 case WHILE:
5176 case DO:
5177 case UNTIL:
5178 case IF:
5179 case THEN:
5180 case ELIF:
5181 case ELSE:
5182 case '{': /* } */
5183 case '(': /* )( */
5184 case ')': /* only valid in case statement */
5185 case BANG: /* ! time pipeline */
5186 case TIME: /* time time pipeline */
5187 case TIMEOPT: /* time -p time pipeline */
5188 case TIMEIGN: /* time -p -- ... */
5189 return 1;
5190 default:
5191 return 0;
5192 }
5193 #else
5194 return 0;
5195 #endif /* COMMAND_TIMING */
5196 }
5197
5198 /* Handle special cases of token recognition:
5199 IN is recognized if the last token was WORD and the token
5200 before that was FOR or CASE or SELECT.
5201
5202 DO is recognized if the last token was WORD and the token
5203 before that was FOR or SELECT.
5204
5205 ESAC is recognized if the last token caused `esacs_needed_count'
5206 to be set
5207
5208 `{' is recognized if the last token as WORD and the token
5209 before that was FUNCTION, or if we just parsed an arithmetic
5210 `for' command.
5211
5212 `}' is recognized if there is an unclosed `{' present.
5213
5214 `-p' is returned as TIMEOPT if the last read token was TIME.
5215 `--' is returned as TIMEIGN if the last read token was TIMEOPT.
5216
5217 ']]' is returned as COND_END if the parser is currently parsing
5218 a conditional expression ((parser_state & PST_CONDEXPR) != 0)
5219
5220 `time' is returned as TIME if and only if it is immediately
5221 preceded by one of `;', `\n', `||', `&&', or `&'.
5222 */
5223
5224 static int
5225 special_case_tokens (tokstr)
5226 char *tokstr;
5227 {
5228 if ((last_read_token == WORD) &&
5229 #if defined (SELECT_COMMAND)
5230 ((token_before_that == FOR) || (token_before_that == CASE) || (token_before_that == SELECT)) &&
5231 #else
5232 ((token_before_that == FOR) || (token_before_that == CASE)) &&
5233 #endif
5234 (tokstr[0] == 'i' && tokstr[1] == 'n' && tokstr[2] == 0))
5235 {
5236 if (token_before_that == CASE)
5237 {
5238 parser_state |= PST_CASEPAT;
5239 esacs_needed_count++;
5240 }
5241 return (IN);
5242 }
5243
5244 if (last_read_token == WORD &&
5245 #if defined (SELECT_COMMAND)
5246 (token_before_that == FOR || token_before_that == SELECT) &&
5247 #else
5248 (token_before_that == FOR) &&
5249 #endif
5250 (tokstr[0] == 'd' && tokstr[1] == 'o' && tokstr[2] == '\0'))
5251 return (DO);
5252
5253 /* Ditto for ESAC in the CASE case.
5254 Specifically, this handles "case word in esac", which is a legal
5255 construct, certainly because someone will pass an empty arg to the
5256 case construct, and we don't want it to barf. Of course, we should
5257 insist that the case construct has at least one pattern in it, but
5258 the designers disagree. */
5259 if (esacs_needed_count)
5260 {
5261 esacs_needed_count--;
5262 if (STREQ (tokstr, "esac"))
5263 {
5264 parser_state &= ~PST_CASEPAT;
5265 return (ESAC);
5266 }
5267 }
5268
5269 /* The start of a shell function definition. */
5270 if (parser_state & PST_ALLOWOPNBRC)
5271 {
5272 parser_state &= ~PST_ALLOWOPNBRC;
5273 if (tokstr[0] == '{' && tokstr[1] == '\0') /* } */
5274 {
5275 open_brace_count++;
5276 function_bstart = line_number;
5277 return ('{'); /* } */
5278 }
5279 }
5280
5281 /* We allow a `do' after a for ((...)) without an intervening
5282 list_terminator */
5283 if (last_read_token == ARITH_FOR_EXPRS && tokstr[0] == 'd' && tokstr[1] == 'o' && !tokstr[2])
5284 return (DO);
5285 if (last_read_token == ARITH_FOR_EXPRS && tokstr[0] == '{' && tokstr[1] == '\0') /* } */
5286 {
5287 open_brace_count++;
5288 return ('{'); /* } */
5289 }
5290
5291 if (open_brace_count && reserved_word_acceptable (last_read_token) && tokstr[0] == '}' && !tokstr[1])
5292 {
5293 open_brace_count--; /* { */
5294 return ('}');
5295 }
5296
5297 #if defined (COMMAND_TIMING)
5298 /* Handle -p after `time'. */
5299 if (last_read_token == TIME && tokstr[0] == '-' && tokstr[1] == 'p' && !tokstr[2])
5300 return (TIMEOPT);
5301 /* Handle -- after `time -p'. */
5302 if (last_read_token == TIMEOPT && tokstr[0] == '-' && tokstr[1] == '-' && !tokstr[2])
5303 return (TIMEIGN);
5304 #endif
5305
5306 #if defined (COND_COMMAND) /* [[ */
5307 if ((parser_state & PST_CONDEXPR) && tokstr[0] == ']' && tokstr[1] == ']' && tokstr[2] == '\0')
5308 return (COND_END);
5309 #endif
5310
5311 return (-1);
5312 }
5313
5314 /* Called from shell.c when Control-C is typed at top level. Or
5315 by the error rule at top level. */
5316 void
5317 reset_parser ()
5318 {
5319 dstack.delimiter_depth = 0; /* No delimiters found so far. */
5320 open_brace_count = 0;
5321
5322 #if defined (EXTENDED_GLOB)
5323 /* Reset to global value of extended glob */
5324 if (parser_state & PST_EXTPAT)
5325 extended_glob = global_extglob;
5326 #endif
5327
5328 parser_state = 0;
5329 here_doc_first_line = 0;
5330
5331 #if defined (ALIAS) || defined (DPAREN_ARITHMETIC)
5332 if (pushed_string_list)
5333 free_string_list ();
5334 #endif /* ALIAS || DPAREN_ARITHMETIC */
5335
5336 /* This is where we resynchronize to the next newline on error/reset */
5337 if (shell_input_line)
5338 {
5339 free (shell_input_line);
5340 shell_input_line = (char *)NULL;
5341 shell_input_line_size = shell_input_line_index = 0;
5342 }
5343
5344 FREE (word_desc_to_read);
5345 word_desc_to_read = (WORD_DESC *)NULL;
5346
5347 eol_ungetc_lookahead = 0;
5348
5349 current_token = '\n'; /* XXX */
5350 last_read_token = '\n';
5351 token_to_read = '\n';
5352 }
5353
5354 /* Read the next token. Command can be READ (normal operation) or
5355 RESET (to normalize state). */
5356 static int
5357 read_token (command)
5358 int command;
5359 {
5360 int character; /* Current character. */
5361 int peek_char; /* Temporary look-ahead character. */
5362 int result; /* The thing to return. */
5363
5364 if (command == RESET)
5365 {
5366 reset_parser ();
5367 return ('\n');
5368 }
5369
5370 if (token_to_read)
5371 {
5372 result = token_to_read;
5373 if (token_to_read == WORD || token_to_read == ASSIGNMENT_WORD)
5374 {
5375 yylval.word = word_desc_to_read;
5376 word_desc_to_read = (WORD_DESC *)NULL;
5377 }
5378 token_to_read = 0;
5379 return (result);
5380 }
5381
5382 #if defined (COND_COMMAND)
5383 if ((parser_state & (PST_CONDCMD|PST_CONDEXPR)) == PST_CONDCMD)
5384 {
5385 cond_lineno = line_number;
5386 parser_state |= PST_CONDEXPR;
5387 yylval.command = parse_cond_command ();
5388 if (cond_token != COND_END)
5389 {
5390 cond_error ();
5391 return (-1);
5392 }
5393 token_to_read = COND_END;
5394 parser_state &= ~(PST_CONDEXPR|PST_CONDCMD);
5395 return (COND_CMD);
5396 }
5397 #endif
5398
5399 #if defined (ALIAS)
5400 /* This is a place to jump back to once we have successfully expanded a
5401 token with an alias and pushed the string with push_string () */
5402 re_read_token:
5403 #endif /* ALIAS */
5404
5405 /* Read a single word from input. Start by skipping blanks. */
5406 while ((character = shell_getc (1)) != EOF && shellblank (character))
5407 ;
5408
5409 if (character == EOF)
5410 {
5411 EOF_Reached = 1;
5412 return (yacc_EOF);
5413 }
5414
5415 if MBTEST(character == '#' && (!interactive || interactive_comments))
5416 {
5417 /* A comment. Discard until EOL or EOF, and then return a newline. */
5418 discard_until ('\n');
5419 shell_getc (0);
5420 character = '\n'; /* this will take the next if statement and return. */
5421 }
5422
5423 if (character == '\n')
5424 {
5425 /* If we're about to return an unquoted newline, we can go and collect
5426 the text of any pending here document. */
5427 if (need_here_doc)
5428 gather_here_documents ();
5429
5430 #if defined (ALIAS)
5431 parser_state &= ~PST_ALEXPNEXT;
5432 #endif /* ALIAS */
5433
5434 parser_state &= ~PST_ASSIGNOK;
5435
5436 return (character);
5437 }
5438
5439 if (parser_state & PST_REGEXP)
5440 goto tokword;
5441
5442 /* Shell meta-characters. */
5443 if MBTEST(shellmeta (character) && ((parser_state & PST_DBLPAREN) == 0))
5444 {
5445 #if defined (ALIAS)
5446 /* Turn off alias tokenization iff this character sequence would
5447 not leave us ready to read a command. */
5448 if (character == '<' || character == '>')
5449 parser_state &= ~PST_ALEXPNEXT;
5450 #endif /* ALIAS */
5451
5452 parser_state &= ~PST_ASSIGNOK;
5453
5454 /* If we are parsing a command substitution and we have read a character
5455 that marks the end of it, don't bother to skip over quoted newlines
5456 when we read the next token. We're just interested in a character
5457 that will turn this into a two-character token, so we let the higher
5458 layers deal with quoted newlines following the command substitution. */
5459 if ((parser_state & PST_CMDSUBST) && character == shell_eof_token)
5460 peek_char = shell_getc (0);
5461 else
5462 peek_char = shell_getc (1);
5463
5464 if (character == peek_char)
5465 {
5466 switch (character)
5467 {
5468 case '<':
5469 /* If '<' then we could be at "<<" or at "<<-". We have to
5470 look ahead one more character. */
5471 peek_char = shell_getc (1);
5472 if MBTEST(peek_char == '-')
5473 return (LESS_LESS_MINUS);
5474 else if MBTEST(peek_char == '<')
5475 return (LESS_LESS_LESS);
5476 else
5477 {
5478 shell_ungetc (peek_char);
5479 return (LESS_LESS);
5480 }
5481
5482 case '>':
5483 return (GREATER_GREATER);
5484
5485 case ';':
5486 parser_state |= PST_CASEPAT;
5487 #if defined (ALIAS)
5488 parser_state &= ~PST_ALEXPNEXT;
5489 #endif /* ALIAS */
5490
5491 peek_char = shell_getc (1);
5492 if MBTEST(peek_char == '&')
5493 return (SEMI_SEMI_AND);
5494 else
5495 {
5496 shell_ungetc (peek_char);
5497 return (SEMI_SEMI);
5498 }
5499
5500 case '&':
5501 return (AND_AND);
5502
5503 case '|':
5504 return (OR_OR);
5505
5506 #if defined (DPAREN_ARITHMETIC) || defined (ARITH_FOR_COMMAND)
5507 case '(': /* ) */
5508 result = parse_dparen (character);
5509 if (result == -2)
5510 break;
5511 else
5512 return result;
5513 #endif
5514 }
5515 }
5516 else if MBTEST(character == '<' && peek_char == '&')
5517 return (LESS_AND);
5518 else if MBTEST(character == '>' && peek_char == '&')
5519 return (GREATER_AND);
5520 else if MBTEST(character == '<' && peek_char == '>')
5521 return (LESS_GREATER);
5522 else if MBTEST(character == '>' && peek_char == '|')
5523 return (GREATER_BAR);
5524 else if MBTEST(character == '&' && peek_char == '>')
5525 {
5526 peek_char = shell_getc (1);
5527 if MBTEST(peek_char == '>')
5528 return (AND_GREATER_GREATER);
5529 else
5530 {
5531 shell_ungetc (peek_char);
5532 return (AND_GREATER);
5533 }
5534 }
5535 else if MBTEST(character == '|' && peek_char == '&')
5536 return (BAR_AND);
5537 else if MBTEST(character == ';' && peek_char == '&')
5538 {
5539 parser_state |= PST_CASEPAT;
5540 #if defined (ALIAS)
5541 parser_state &= ~PST_ALEXPNEXT;
5542 #endif /* ALIAS */
5543 return (SEMI_AND);
5544 }
5545
5546 shell_ungetc (peek_char);
5547
5548 /* If we look like we are reading the start of a function
5549 definition, then let the reader know about it so that
5550 we will do the right thing with `{'. */
5551 if MBTEST(character == ')' && last_read_token == '(' && token_before_that == WORD)
5552 {
5553 parser_state |= PST_ALLOWOPNBRC;
5554 #if defined (ALIAS)
5555 parser_state &= ~PST_ALEXPNEXT;
5556 #endif /* ALIAS */
5557 function_dstart = line_number;
5558 }
5559
5560 /* case pattern lists may be preceded by an optional left paren. If
5561 we're not trying to parse a case pattern list, the left paren
5562 indicates a subshell. */
5563 if MBTEST(character == '(' && (parser_state & PST_CASEPAT) == 0) /* ) */
5564 parser_state |= PST_SUBSHELL;
5565 /*(*/
5566 else if MBTEST((parser_state & PST_CASEPAT) && character == ')')
5567 parser_state &= ~PST_CASEPAT;
5568 /*(*/
5569 else if MBTEST((parser_state & PST_SUBSHELL) && character == ')')
5570 parser_state &= ~PST_SUBSHELL;
5571
5572 #if defined (PROCESS_SUBSTITUTION)
5573 /* Check for the constructs which introduce process substitution.
5574 Shells running in `posix mode' don't do process substitution. */
5575 if MBTEST(posixly_correct || ((character != '>' && character != '<') || peek_char != '(')) /*)*/
5576 #endif /* PROCESS_SUBSTITUTION */
5577 return (character);
5578 }
5579
5580 /* Hack <&- (close stdin) case. Also <&N- (dup and close). */
5581 if MBTEST(character == '-' && (last_read_token == LESS_AND || last_read_token == GREATER_AND))
5582 return (character);
5583
5584 tokword:
5585 /* Okay, if we got this far, we have to read a word. Read one,
5586 and then check it against the known ones. */
5587 result = read_token_word (character);
5588 #if defined (ALIAS)
5589 if (result == RE_READ_TOKEN)
5590 goto re_read_token;
5591 #endif
5592 return result;
5593 }
5594
5595 /*
5596 * Match a $(...) or other grouping construct. This has to handle embedded
5597 * quoted strings ('', ``, "") and nested constructs. It also must handle
5598 * reprompting the user, if necessary, after reading a newline, and returning
5599 * correct error values if it reads EOF.
5600 */
5601 #define P_FIRSTCLOSE 0x0001
5602 #define P_ALLOWESC 0x0002
5603 #define P_DQUOTE 0x0004
5604 #define P_COMMAND 0x0008 /* parsing a command, so look for comments */
5605 #define P_BACKQUOTE 0x0010 /* parsing a backquoted command substitution */
5606 #define P_ARRAYSUB 0x0020 /* parsing a [...] array subscript for assignment */
5607 #define P_DOLBRACE 0x0040 /* parsing a ${...} construct */
5608
5609 /* Lexical state while parsing a grouping construct or $(...). */
5610 #define LEX_WASDOL 0x001
5611 #define LEX_CKCOMMENT 0x002
5612 #define LEX_INCOMMENT 0x004
5613 #define LEX_PASSNEXT 0x008
5614 #define LEX_RESWDOK 0x010
5615 #define LEX_CKCASE 0x020
5616 #define LEX_INCASE 0x040
5617 #define LEX_INHEREDOC 0x080
5618 #define LEX_HEREDELIM 0x100 /* reading here-doc delimiter */
5619 #define LEX_STRIPDOC 0x200 /* <<- strip tabs from here doc delim */
5620 #define LEX_QUOTEDDOC 0x400 /* here doc with quoted delim */
5621 #define LEX_INWORD 0x800
5622
5623 #define COMSUB_META(ch) ((ch) == ';' || (ch) == '&' || (ch) == '|')
5624
5625 #define CHECK_NESTRET_ERROR() \
5626 do { \
5627 if (nestret == &matched_pair_error) \
5628 { \
5629 free (ret); \
5630 return &matched_pair_error; \
5631 } \
5632 } while (0)
5633
5634 #define APPEND_NESTRET() \
5635 do { \
5636 if (nestlen) \
5637 { \
5638 RESIZE_MALLOCED_BUFFER (ret, retind, nestlen, retsize, 64); \
5639 strcpy (ret + retind, nestret); \
5640 retind += nestlen; \
5641 } \
5642 } while (0)
5643
5644 static char matched_pair_error;
5645
5646 static char *
5647 parse_matched_pair (qc, open, close, lenp, flags)
5648 int qc; /* `"' if this construct is within double quotes */
5649 int open, close;
5650 int *lenp, flags;
5651 {
5652 int count, ch, tflags;
5653 int nestlen, ttranslen, start_lineno;
5654 char *ret, *nestret, *ttrans;
5655 int retind, retsize, rflags;
5656 int dolbrace_state;
5657
5658 dolbrace_state = (flags & P_DOLBRACE) ? DOLBRACE_PARAM : 0;
5659
5660 /*itrace("parse_matched_pair[%d]: open = %c close = %c flags = %d", line_number, open, close, flags);*/
5661 count = 1;
5662 tflags = 0;
5663
5664 if ((flags & P_COMMAND) && qc != '`' && qc != '\'' && qc != '"' && (flags & P_DQUOTE) == 0)
5665 tflags |= LEX_CKCOMMENT;
5666
5667 /* RFLAGS is the set of flags we want to pass to recursive calls. */
5668 rflags = (qc == '"') ? P_DQUOTE : (flags & P_DQUOTE);
5669
5670 ret = (char *)xmalloc (retsize = 64);
5671 retind = 0;
5672
5673 start_lineno = line_number;
5674 while (count)
5675 {
5676 ch = shell_getc (qc != '\'' && (tflags & (LEX_PASSNEXT)) == 0);
5677
5678 if (ch == EOF)
5679 {
5680 free (ret);
5681 parser_error (start_lineno, _("unexpected EOF while looking for matching `%c'"), close);
5682 EOF_Reached = 1; /* XXX */
5683 return (&matched_pair_error);
5684 }
5685
5686 /* Possible reprompting. */
5687 if (ch == '\n' && SHOULD_PROMPT ())
5688 prompt_again ();
5689
5690 /* Don't bother counting parens or doing anything else if in a comment
5691 or part of a case statement */
5692 if (tflags & LEX_INCOMMENT)
5693 {
5694 /* Add this character. */
5695 RESIZE_MALLOCED_BUFFER (ret, retind, 1, retsize, 64);
5696 ret[retind++] = ch;
5697
5698 if (ch == '\n')
5699 tflags &= ~LEX_INCOMMENT;
5700
5701 continue;
5702 }
5703
5704 /* Not exactly right yet, should handle shell metacharacters, too. If
5705 any changes are made to this test, make analogous changes to subst.c:
5706 extract_delimited_string(). */
5707 else if MBTEST((tflags & LEX_CKCOMMENT) && (tflags & LEX_INCOMMENT) == 0 && ch == '#' && (retind == 0 || ret[retind-1] == '\n' || shellblank (ret[retind - 1])))
5708 tflags |= LEX_INCOMMENT;
5709
5710 if (tflags & LEX_PASSNEXT) /* last char was backslash */
5711 {
5712 tflags &= ~LEX_PASSNEXT;
5713 if (qc != '\'' && ch == '\n') /* double-quoted \<newline> disappears. */
5714 {
5715 if (retind > 0)
5716 retind--; /* swallow previously-added backslash */
5717 continue;
5718 }
5719
5720 RESIZE_MALLOCED_BUFFER (ret, retind, 2, retsize, 64);
5721 if MBTEST(ch == CTLESC)
5722 ret[retind++] = CTLESC;
5723 ret[retind++] = ch;
5724 continue;
5725 }
5726 /* If we're reparsing the input (e.g., from parse_string_to_word_list),
5727 we've already prepended CTLESC to single-quoted results of $'...'.
5728 We may want to do this for other CTLESC-quoted characters in
5729 reparse, too. */
5730 else if MBTEST((parser_state & PST_REPARSE) && open == '\'' && (ch == CTLESC || ch == CTLNUL))
5731 {
5732 RESIZE_MALLOCED_BUFFER (ret, retind, 1, retsize, 64);
5733 ret[retind++] = ch;
5734 continue;
5735 }
5736 else if MBTEST(ch == CTLESC || ch == CTLNUL) /* special shell escapes */
5737 {
5738 RESIZE_MALLOCED_BUFFER (ret, retind, 2, retsize, 64);
5739 ret[retind++] = CTLESC;
5740 ret[retind++] = ch;
5741 continue;
5742 }
5743 else if MBTEST(ch == close) /* ending delimiter */
5744 count--;
5745 /* handle nested ${...} specially. */
5746 else if MBTEST(open != close && (tflags & LEX_WASDOL) && open == '{' && ch == open) /* } */
5747 count++;
5748 else if MBTEST(((flags & P_FIRSTCLOSE) == 0) && ch == open) /* nested begin */
5749 count++;
5750
5751 /* Add this character. */
5752 RESIZE_MALLOCED_BUFFER (ret, retind, 1, retsize, 64);
5753 ret[retind++] = ch;
5754
5755 /* If we just read the ending character, don't bother continuing. */
5756 if (count == 0)
5757 break;
5758
5759 if (open == '\'') /* '' inside grouping construct */
5760 {
5761 if MBTEST((flags & P_ALLOWESC) && ch == '\\')
5762 tflags |= LEX_PASSNEXT;
5763 continue;
5764 }
5765
5766 if MBTEST(ch == '\\') /* backslashes */
5767 tflags |= LEX_PASSNEXT;
5768
5769 /* Based on which dolstate is currently in (param, op, or word),
5770 decide what the op is. We're really only concerned if it's % or
5771 #, so we can turn on a flag that says whether or not we should
5772 treat single quotes as special when inside a double-quoted
5773 ${...}. This logic must agree with subst.c:extract_dollar_brace_string
5774 since they share the same defines. */
5775 /* FLAG POSIX INTERP 221 */
5776 if (flags & P_DOLBRACE)
5777 {
5778 /* ${param%[%]word} */
5779 if MBTEST(dolbrace_state == DOLBRACE_PARAM && ch == '%' && retind > 1)
5780 dolbrace_state = DOLBRACE_QUOTE;
5781 /* ${param#[#]word} */
5782 else if MBTEST(dolbrace_state == DOLBRACE_PARAM && ch == '#' && retind > 1)
5783 dolbrace_state = DOLBRACE_QUOTE;
5784 /* ${param/[/]pat/rep} */
5785 else if MBTEST(dolbrace_state == DOLBRACE_PARAM && ch == '/' && retind > 1)
5786 dolbrace_state = DOLBRACE_QUOTE2; /* XXX */
5787 /* ${param^[^]pat} */
5788 else if MBTEST(dolbrace_state == DOLBRACE_PARAM && ch == '^' && retind > 1)
5789 dolbrace_state = DOLBRACE_QUOTE;
5790 /* ${param,[,]pat} */
5791 else if MBTEST(dolbrace_state == DOLBRACE_PARAM && ch == ',' && retind > 1)
5792 dolbrace_state = DOLBRACE_QUOTE;
5793 else if MBTEST(dolbrace_state == DOLBRACE_PARAM && strchr ("#%^,~:-=?+/", ch) != 0)
5794 dolbrace_state = DOLBRACE_OP;
5795 else if MBTEST(dolbrace_state == DOLBRACE_OP && strchr ("#%^,~:-=?+/", ch) == 0)
5796 dolbrace_state = DOLBRACE_WORD;
5797 }
5798
5799 /* The big hammer. Single quotes aren't special in double quotes. The
5800 problem is that Posix used to say the single quotes are semi-special:
5801 within a double-quoted ${...} construct "an even number of
5802 unescaped double-quotes or single-quotes, if any, shall occur." */
5803 /* This was changed in Austin Group Interp 221 */
5804 if MBTEST(posixly_correct && shell_compatibility_level > 41 && dolbrace_state != DOLBRACE_QUOTE && dolbrace_state != DOLBRACE_QUOTE2 && (flags & P_DQUOTE) && (flags & P_DOLBRACE) && ch == '\'')
5805 continue;
5806
5807 /* Could also check open == '`' if we want to parse grouping constructs
5808 inside old-style command substitution. */
5809 if (open != close) /* a grouping construct */
5810 {
5811 if MBTEST(shellquote (ch))
5812 {
5813 /* '', ``, or "" inside $(...) or other grouping construct. */
5814 push_delimiter (dstack, ch);
5815 if MBTEST((tflags & LEX_WASDOL) && ch == '\'') /* $'...' inside group */
5816 nestret = parse_matched_pair (ch, ch, ch, &nestlen, P_ALLOWESC|rflags);
5817 else
5818 nestret = parse_matched_pair (ch, ch, ch, &nestlen, rflags);
5819 pop_delimiter (dstack);
5820 CHECK_NESTRET_ERROR ();
5821
5822 if MBTEST((tflags & LEX_WASDOL) && ch == '\'' && (extended_quote || (rflags & P_DQUOTE) == 0))
5823 {
5824 /* Translate $'...' here. */
5825 ttrans = ansiexpand (nestret, 0, nestlen - 1, &ttranslen);
5826 xfree (nestret);
5827
5828 /* If we're parsing a double-quoted brace expansion and we are
5829 not in a place where single quotes are treated specially,
5830 make sure we single-quote the results of the ansi
5831 expansion because quote removal should remove them later */
5832 /* FLAG POSIX INTERP 221 */
5833 if ((shell_compatibility_level > 42) && (rflags & P_DQUOTE) && (dolbrace_state == DOLBRACE_QUOTE2) && (flags & P_DOLBRACE))
5834 {
5835 nestret = sh_single_quote (ttrans);
5836 free (ttrans);
5837 nestlen = strlen (nestret);
5838 }
5839 else if ((rflags & P_DQUOTE) == 0)
5840 {
5841 nestret = sh_single_quote (ttrans);
5842 free (ttrans);
5843 nestlen = strlen (nestret);
5844 }
5845 else
5846 {
5847 nestret = ttrans;
5848 nestlen = ttranslen;
5849 }
5850 retind -= 2; /* back up before the $' */
5851 }
5852 else if MBTEST((tflags & LEX_WASDOL) && ch == '"' && (extended_quote || (rflags & P_DQUOTE) == 0))
5853 {
5854 /* Locale expand $"..." here. */
5855 ttrans = localeexpand (nestret, 0, nestlen - 1, start_lineno, &ttranslen);
5856 xfree (nestret);
5857
5858 nestret = sh_mkdoublequoted (ttrans, ttranslen, 0);
5859 free (ttrans);
5860 nestlen = ttranslen + 2;
5861 retind -= 2; /* back up before the $" */
5862 }
5863
5864 APPEND_NESTRET ();
5865 FREE (nestret);
5866 }
5867 else if ((flags & (P_ARRAYSUB|P_DOLBRACE)) && (tflags & LEX_WASDOL) && (ch == '(' || ch == '{' || ch == '[')) /* ) } ] */
5868 goto parse_dollar_word;
5869 }
5870 /* Parse an old-style command substitution within double quotes as a
5871 single word. */
5872 /* XXX - sh and ksh93 don't do this - XXX */
5873 else if MBTEST(open == '"' && ch == '`')
5874 {
5875 nestret = parse_matched_pair (0, '`', '`', &nestlen, rflags);
5876
5877 CHECK_NESTRET_ERROR ();
5878 APPEND_NESTRET ();
5879
5880 FREE (nestret);
5881 }
5882 else if MBTEST(open != '`' && (tflags & LEX_WASDOL) && (ch == '(' || ch == '{' || ch == '[')) /* ) } ] */
5883 /* check for $(), $[], or ${} inside quoted string. */
5884 {
5885 parse_dollar_word:
5886 if (open == ch) /* undo previous increment */
5887 count--;
5888 if (ch == '(') /* ) */
5889 nestret = parse_comsub (0, '(', ')', &nestlen, (rflags|P_COMMAND) & ~P_DQUOTE);
5890 else if (ch == '{') /* } */
5891 nestret = parse_matched_pair (0, '{', '}', &nestlen, P_FIRSTCLOSE|P_DOLBRACE|rflags);
5892 else if (ch == '[') /* ] */
5893 nestret = parse_matched_pair (0, '[', ']', &nestlen, rflags);
5894
5895 CHECK_NESTRET_ERROR ();
5896 APPEND_NESTRET ();
5897
5898 FREE (nestret);
5899 }
5900 if MBTEST(ch == '$')
5901 tflags |= LEX_WASDOL;
5902 else
5903 tflags &= ~LEX_WASDOL;
5904 }
5905
5906 ret[retind] = '\0';
5907 if (lenp)
5908 *lenp = retind;
5909 /*itrace("parse_matched_pair[%d]: returning %s", line_number, ret);*/
5910 return ret;
5911 }
5912
5913 #if defined (DEBUG)
5914 static void
5915 dump_tflags (flags)
5916 int flags;
5917 {
5918 int f;
5919
5920 f = flags;
5921 fprintf (stderr, "%d -> ", f);
5922 if (f & LEX_WASDOL)
5923 {
5924 f &= ~LEX_WASDOL;
5925 fprintf (stderr, "LEX_WASDOL%s", f ? "|" : "");
5926 }
5927 if (f & LEX_CKCOMMENT)
5928 {
5929 f &= ~LEX_CKCOMMENT;
5930 fprintf (stderr, "LEX_CKCOMMENT%s", f ? "|" : "");
5931 }
5932 if (f & LEX_INCOMMENT)
5933 {
5934 f &= ~LEX_INCOMMENT;
5935 fprintf (stderr, "LEX_INCOMMENT%s", f ? "|" : "");
5936 }
5937 if (f & LEX_PASSNEXT)
5938 {
5939 f &= ~LEX_PASSNEXT;
5940 fprintf (stderr, "LEX_PASSNEXT%s", f ? "|" : "");
5941 }
5942 if (f & LEX_RESWDOK)
5943 {
5944 f &= ~LEX_RESWDOK;
5945 fprintf (stderr, "LEX_RESWDOK%s", f ? "|" : "");
5946 }
5947 if (f & LEX_CKCASE)
5948 {
5949 f &= ~LEX_CKCASE;
5950 fprintf (stderr, "LEX_CKCASE%s", f ? "|" : "");
5951 }
5952 if (f & LEX_INCASE)
5953 {
5954 f &= ~LEX_INCASE;
5955 fprintf (stderr, "LEX_INCASE%s", f ? "|" : "");
5956 }
5957 if (f & LEX_INHEREDOC)
5958 {
5959 f &= ~LEX_INHEREDOC;
5960 fprintf (stderr, "LEX_INHEREDOC%s", f ? "|" : "");
5961 }
5962 if (f & LEX_HEREDELIM)
5963 {
5964 f &= ~LEX_HEREDELIM;
5965 fprintf (stderr, "LEX_HEREDELIM%s", f ? "|" : "");
5966 }
5967 if (f & LEX_STRIPDOC)
5968 {
5969 f &= ~LEX_STRIPDOC;
5970 fprintf (stderr, "LEX_WASDOL%s", f ? "|" : "");
5971 }
5972 if (f & LEX_QUOTEDDOC)
5973 {
5974 f &= ~LEX_QUOTEDDOC;
5975 fprintf (stderr, "LEX_QUOTEDDOC%s", f ? "|" : "");
5976 }
5977 if (f & LEX_INWORD)
5978 {
5979 f &= ~LEX_INWORD;
5980 fprintf (stderr, "LEX_INWORD%s", f ? "|" : "");
5981 }
5982
5983 fprintf (stderr, "\n");
5984 fflush (stderr);
5985 }
5986 #endif
5987
5988 /* Parse a $(...) command substitution. This is messier than I'd like, and
5989 reproduces a lot more of the token-reading code than I'd like. */
5990 static char *
5991 parse_comsub (qc, open, close, lenp, flags)
5992 int qc; /* `"' if this construct is within double quotes */
5993 int open, close;
5994 int *lenp, flags;
5995 {
5996 int count, ch, peekc, tflags, lex_rwlen, lex_wlen, lex_firstind;
5997 int nestlen, ttranslen, start_lineno;
5998 char *ret, *nestret, *ttrans, *heredelim;
5999 int retind, retsize, rflags, hdlen;
6000
6001 /* Posix interp 217 says arithmetic expressions have precedence, so
6002 assume $(( introduces arithmetic expansion and parse accordingly. */
6003 peekc = shell_getc (0);
6004 shell_ungetc (peekc);
6005 if (peekc == '(')
6006 return (parse_matched_pair (qc, open, close, lenp, 0));
6007
6008 /*itrace("parse_comsub: qc = `%c' open = %c close = %c", qc, open, close);*/
6009 count = 1;
6010 tflags = LEX_RESWDOK;
6011
6012 if ((flags & P_COMMAND) && qc != '\'' && qc != '"' && (flags & P_DQUOTE) == 0)
6013 tflags |= LEX_CKCASE;
6014 if ((tflags & LEX_CKCASE) && (interactive == 0 || interactive_comments))
6015 tflags |= LEX_CKCOMMENT;
6016
6017 /* RFLAGS is the set of flags we want to pass to recursive calls. */
6018 rflags = (flags & P_DQUOTE);
6019
6020 ret = (char *)xmalloc (retsize = 64);
6021 retind = 0;
6022
6023 start_lineno = line_number;
6024 lex_rwlen = lex_wlen = 0;
6025
6026 heredelim = 0;
6027 lex_firstind = -1;
6028
6029 while (count)
6030 {
6031 comsub_readchar:
6032 ch = shell_getc (qc != '\'' && (tflags & (LEX_INCOMMENT|LEX_PASSNEXT)) == 0);
6033
6034 if (ch == EOF)
6035 {
6036 eof_error:
6037 free (ret);
6038 FREE (heredelim);
6039 parser_error (start_lineno, _("unexpected EOF while looking for matching `%c'"), close);
6040 EOF_Reached = 1; /* XXX */
6041 return (&matched_pair_error);
6042 }
6043
6044 /* If we hit the end of a line and are reading the contents of a here
6045 document, and it's not the same line that the document starts on,
6046 check for this line being the here doc delimiter. Otherwise, if
6047 we're in a here document, mark the next character as the beginning
6048 of a line. */
6049 if (ch == '\n')
6050 {
6051 if ((tflags & LEX_HEREDELIM) && heredelim)
6052 {
6053 tflags &= ~LEX_HEREDELIM;
6054 tflags |= LEX_INHEREDOC;
6055 lex_firstind = retind + 1;
6056 }
6057 else if (tflags & LEX_INHEREDOC)
6058 {
6059 int tind;
6060 tind = lex_firstind;
6061 while ((tflags & LEX_STRIPDOC) && ret[tind] == '\t')
6062 tind++;
6063 if (STREQN (ret + tind, heredelim, hdlen))
6064 {
6065 tflags &= ~(LEX_STRIPDOC|LEX_INHEREDOC|LEX_QUOTEDDOC);
6066 /*itrace("parse_comsub:%d: found here doc end `%s'", line_number, ret + tind);*/
6067 free (heredelim);
6068 heredelim = 0;
6069 lex_firstind = -1;
6070 }
6071 else
6072 lex_firstind = retind + 1;
6073 }
6074 }
6075
6076 /* Possible reprompting. */
6077 if (ch == '\n' && SHOULD_PROMPT ())
6078 prompt_again ();
6079
6080 /* XXX -- possibly allow here doc to be delimited by ending right
6081 paren. */
6082 if ((tflags & LEX_INHEREDOC) && ch == close && count == 1)
6083 {
6084 int tind;
6085 /*itrace("parse_comsub:%d: in here doc, ch == close, retind - firstind = %d hdlen = %d retind = %d", line_number, retind-lex_firstind, hdlen, retind);*/
6086 tind = lex_firstind;
6087 while ((tflags & LEX_STRIPDOC) && ret[tind] == '\t')
6088 tind++;
6089 if (retind-tind == hdlen && STREQN (ret + tind, heredelim, hdlen))
6090 {
6091 tflags &= ~(LEX_STRIPDOC|LEX_INHEREDOC|LEX_QUOTEDDOC);
6092 /*itrace("parse_comsub:%d: found here doc end `%*s'", line_number, hdlen, ret + tind);*/
6093 free (heredelim);
6094 heredelim = 0;
6095 lex_firstind = -1;
6096 }
6097 }
6098
6099 /* Don't bother counting parens or doing anything else if in a comment or
6100 here document (not exactly right for here-docs -- if we want to allow
6101 recursive calls to parse_comsub to have their own here documents,
6102 change the LEX_INHEREDOC to LEX_QUOTEDDOC here and uncomment the next
6103 clause below. Note that to make this work completely, we need to make
6104 additional changes to allow xparse_dolparen to work right when the
6105 command substitution is parsed, because read_secondary_line doesn't know
6106 to recursively parse through command substitutions embedded in here-
6107 documents */
6108 if (tflags & (LEX_INCOMMENT|LEX_INHEREDOC))
6109 {
6110 /* Add this character. */
6111 RESIZE_MALLOCED_BUFFER (ret, retind, 1, retsize, 64);
6112 ret[retind++] = ch;
6113
6114 if ((tflags & LEX_INCOMMENT) && ch == '\n')
6115 {
6116 /*itrace("parse_comsub:%d: lex_incomment -> 0 ch = `%c'", line_number, ch);*/
6117 tflags &= ~LEX_INCOMMENT;
6118 }
6119
6120 continue;
6121 }
6122 #if 0
6123 /* If we're going to recursively parse a command substitution inside a
6124 here-document, make sure we call parse_comsub recursively below. See
6125 above for additional caveats. */
6126 if ((tflags & LEX_INHEREDOC) && ((tflags & LEX_WASDOL) == 0 || ch != '(')) /*)*/
6127 {
6128 /* Add this character. */
6129 RESIZE_MALLOCED_BUFFER (ret, retind, 1, retsize, 64);
6130 ret[retind++] = ch;
6131 if MBTEST(ch == '$')
6132 tflags |= LEX_WASDOL;
6133 else
6134 tflags &= ~LEX_WASDOL;
6135 }
6136 #endif
6137
6138 if (tflags & LEX_PASSNEXT) /* last char was backslash */
6139 {
6140 /*itrace("parse_comsub:%d: lex_passnext -> 0 ch = `%c' (%d)", line_number, ch, __LINE__);*/
6141 tflags &= ~LEX_PASSNEXT;
6142 if (qc != '\'' && ch == '\n') /* double-quoted \<newline> disappears. */
6143 {
6144 if (retind > 0)
6145 retind--; /* swallow previously-added backslash */
6146 continue;
6147 }
6148
6149 RESIZE_MALLOCED_BUFFER (ret, retind, 2, retsize, 64);
6150 if MBTEST(ch == CTLESC)
6151 ret[retind++] = CTLESC;
6152 ret[retind++] = ch;
6153 continue;
6154 }
6155
6156 /* If this is a shell break character, we are not in a word. If not,
6157 we either start or continue a word. */
6158 if MBTEST(shellbreak (ch))
6159 {
6160 tflags &= ~LEX_INWORD;
6161 /*itrace("parse_comsub:%d: lex_inword -> 0 ch = `%c' (%d)", line_number, ch, __LINE__);*/
6162 }
6163 else
6164 {
6165 if (tflags & LEX_INWORD)
6166 {
6167 lex_wlen++;
6168 /*itrace("parse_comsub:%d: lex_inword == 1 ch = `%c' lex_wlen = %d (%d)", line_number, ch, lex_wlen, __LINE__);*/
6169 }
6170 else
6171 {
6172 /*itrace("parse_comsub:%d: lex_inword -> 1 ch = `%c' (%d)", line_number, ch, __LINE__);*/
6173 tflags |= LEX_INWORD;
6174 lex_wlen = 0;
6175 if (tflags & LEX_RESWDOK)
6176 lex_rwlen = 0;
6177 }
6178 }
6179
6180 /* Skip whitespace */
6181 if MBTEST(shellblank (ch) && (tflags & LEX_HEREDELIM) == 0 && lex_rwlen == 0)
6182 {
6183 /* Add this character. */
6184 RESIZE_MALLOCED_BUFFER (ret, retind, 1, retsize, 64);
6185 ret[retind++] = ch;
6186 continue;
6187 }
6188
6189 /* Either we are looking for the start of the here-doc delimiter
6190 (lex_firstind == -1) or we are reading one (lex_firstind >= 0).
6191 If this character is a shell break character and we are reading
6192 the delimiter, save it and note that we are now reading a here
6193 document. If we've found the start of the delimiter, note it by
6194 setting lex_firstind. Backslashes can quote shell metacharacters
6195 in here-doc delimiters. */
6196 if (tflags & LEX_HEREDELIM)
6197 {
6198 if (lex_firstind == -1 && shellbreak (ch) == 0)
6199 lex_firstind = retind;
6200 #if 0
6201 else if (heredelim && (tflags & LEX_PASSNEXT) == 0 && ch == '\n')
6202 {
6203 tflags |= LEX_INHEREDOC;
6204 tflags &= ~LEX_HEREDELIM;
6205 lex_firstind = retind + 1;
6206 }
6207 #endif
6208 else if (lex_firstind >= 0 && (tflags & LEX_PASSNEXT) == 0 && shellbreak (ch))
6209 {
6210 if (heredelim == 0)
6211 {
6212 nestret = substring (ret, lex_firstind, retind);
6213 heredelim = string_quote_removal (nestret, 0);
6214 hdlen = STRLEN(heredelim);
6215 /*itrace("parse_comsub:%d: found here doc delimiter `%s' (%d)", line_number, heredelim, hdlen);*/
6216 if (STREQ (heredelim, nestret) == 0)
6217 tflags |= LEX_QUOTEDDOC;
6218 free (nestret);
6219 }
6220 if (ch == '\n')
6221 {
6222 tflags |= LEX_INHEREDOC;
6223 tflags &= ~LEX_HEREDELIM;
6224 lex_firstind = retind + 1;
6225 }
6226 else
6227 lex_firstind = -1;
6228 }
6229 }
6230
6231 /* Meta-characters that can introduce a reserved word. Not perfect yet. */
6232 if MBTEST((tflags & LEX_RESWDOK) == 0 && (tflags & LEX_CKCASE) && (tflags & LEX_INCOMMENT) == 0 && (shellmeta(ch) || ch == '\n'))
6233 {
6234 /* Add this character. */
6235 RESIZE_MALLOCED_BUFFER (ret, retind, 1, retsize, 64);
6236 ret[retind++] = ch;
6237 peekc = shell_getc (1);
6238 if (ch == peekc && (ch == '&' || ch == '|' || ch == ';')) /* two-character tokens */
6239 {
6240 RESIZE_MALLOCED_BUFFER (ret, retind, 1, retsize, 64);
6241 ret[retind++] = peekc;
6242 /*itrace("parse_comsub:%d: set lex_reswordok = 1, ch = `%c'", line_number, ch);*/
6243 tflags |= LEX_RESWDOK;
6244 lex_rwlen = 0;
6245 continue;
6246 }
6247 else if (ch == '\n' || COMSUB_META(ch))
6248 {
6249 shell_ungetc (peekc);
6250 /*itrace("parse_comsub:%d: set lex_reswordok = 1, ch = `%c'", line_number, ch);*/
6251 tflags |= LEX_RESWDOK;
6252 lex_rwlen = 0;
6253 continue;
6254 }
6255 else if (ch == EOF)
6256 goto eof_error;
6257 else
6258 {
6259 /* `unget' the character we just added and fall through */
6260 retind--;
6261 shell_ungetc (peekc);
6262 }
6263 }
6264
6265 /* If we can read a reserved word, try to read one. */
6266 if (tflags & LEX_RESWDOK)
6267 {
6268 if MBTEST(islower ((unsigned char)ch))
6269 {
6270 /* Add this character. */
6271 RESIZE_MALLOCED_BUFFER (ret, retind, 1, retsize, 64);
6272 ret[retind++] = ch;
6273 lex_rwlen++;
6274 continue;
6275 }
6276 else if MBTEST(lex_rwlen == 4 && shellbreak (ch))
6277 {
6278 if (STREQN (ret + retind - 4, "case", 4))
6279 {
6280 tflags |= LEX_INCASE;
6281 tflags &= ~LEX_RESWDOK;
6282 /*itrace("parse_comsub:%d: found `case', lex_incase -> 1 lex_reswdok -> 0", line_number);*/
6283 }
6284 else if (STREQN (ret + retind - 4, "esac", 4))
6285 {
6286 tflags &= ~LEX_INCASE;
6287 /*itrace("parse_comsub:%d: found `esac', lex_incase -> 0 lex_reswdok -> 1", line_number);*/
6288 tflags |= LEX_RESWDOK;
6289 lex_rwlen = 0;
6290 }
6291 else if (STREQN (ret + retind - 4, "done", 4) ||
6292 STREQN (ret + retind - 4, "then", 4) ||
6293 STREQN (ret + retind - 4, "else", 4) ||
6294 STREQN (ret + retind - 4, "elif", 4) ||
6295 STREQN (ret + retind - 4, "time", 4))
6296 {
6297 /* these are four-character reserved words that can be
6298 followed by a reserved word; anything else turns off
6299 the reserved-word-ok flag */
6300 /*itrace("parse_comsub:%d: found `%.4s', lex_reswdok -> 1", line_number, ret+retind-4);*/
6301 tflags |= LEX_RESWDOK;
6302 lex_rwlen = 0;
6303 }
6304 else
6305 {
6306 tflags &= ~LEX_RESWDOK;
6307 /*itrace("parse_comsub:%d: found `%.4s', lex_reswdok -> 0", line_number, ret+retind-4);*/
6308 }
6309 }
6310 else if MBTEST((tflags & LEX_CKCOMMENT) && ch == '#' && (lex_rwlen == 0 || ((tflags & LEX_INWORD) && lex_wlen == 0)))
6311 ; /* don't modify LEX_RESWDOK if we're starting a comment */
6312 /* Allow `do' followed by space, tab, or newline to preserve the
6313 RESWDOK flag, but reset the reserved word length counter so we
6314 can read another one. */
6315 else if MBTEST(((tflags & LEX_INCASE) == 0) &&
6316 (isblank((unsigned char)ch) || ch == '\n') &&
6317 lex_rwlen == 2 &&
6318 STREQN (ret + retind - 2, "do", 2))
6319 {
6320 /*itrace("parse_comsub:%d: lex_incase == 0 found `%c', found \"do\"", line_number, ch);*/
6321 lex_rwlen = 0;
6322 }
6323 else if MBTEST((tflags & LEX_INCASE) && ch != '\n')
6324 /* If we can read a reserved word and we're in case, we're at the
6325 point where we can read a new pattern list or an esac. We
6326 handle the esac case above. If we read a newline, we want to
6327 leave LEX_RESWDOK alone. If we read anything else, we want to
6328 turn off LEX_RESWDOK, since we're going to read a pattern list. */
6329 {
6330 tflags &= ~LEX_RESWDOK;
6331 /*itrace("parse_comsub:%d: lex_incase == 1 found `%c', lex_reswordok -> 0", line_number, ch);*/
6332 }
6333 else if MBTEST(shellbreak (ch) == 0)
6334 {
6335 tflags &= ~LEX_RESWDOK;
6336 /*itrace("parse_comsub:%d: found `%c', lex_reswordok -> 0", line_number, ch);*/
6337 }
6338 #if 0
6339 /* If we find a space or tab but have read something and it's not
6340 `do', turn off the reserved-word-ok flag */
6341 else if MBTEST(isblank ((unsigned char)ch) && lex_rwlen > 0)
6342 {
6343 tflags &= ~LEX_RESWDOK;
6344 /*itrace("parse_comsub:%d: found `%c', lex_reswordok -> 0", line_number, ch);*/
6345 }
6346 #endif
6347 }
6348
6349 /* Might be the start of a here-doc delimiter */
6350 if MBTEST((tflags & LEX_INCOMMENT) == 0 && (tflags & LEX_CKCASE) && ch == '<')
6351 {
6352 /* Add this character. */
6353 RESIZE_MALLOCED_BUFFER (ret, retind, 1, retsize, 64);
6354 ret[retind++] = ch;
6355 peekc = shell_getc (1);
6356 if (peekc == EOF)
6357 goto eof_error;
6358 if (peekc == ch)
6359 {
6360 RESIZE_MALLOCED_BUFFER (ret, retind, 1, retsize, 64);
6361 ret[retind++] = peekc;
6362 peekc = shell_getc (1);
6363 if (peekc == EOF)
6364 goto eof_error;
6365 if (peekc == '-')
6366 {
6367 RESIZE_MALLOCED_BUFFER (ret, retind, 1, retsize, 64);
6368 ret[retind++] = peekc;
6369 tflags |= LEX_STRIPDOC;
6370 }
6371 else
6372 shell_ungetc (peekc);
6373 if (peekc != '<')
6374 {
6375 tflags |= LEX_HEREDELIM;
6376 lex_firstind = -1;
6377 }
6378 continue;
6379 }
6380 else
6381 ch = peekc; /* fall through and continue XXX */
6382 }
6383 else if MBTEST((tflags & LEX_CKCOMMENT) && (tflags & LEX_INCOMMENT) == 0 && ch == '#' && (((tflags & LEX_RESWDOK) && lex_rwlen == 0) || ((tflags & LEX_INWORD) && lex_wlen == 0)))
6384 {
6385 /*itrace("parse_comsub:%d: lex_incomment -> 1 (%d)", line_number, __LINE__);*/
6386 tflags |= LEX_INCOMMENT;
6387 }
6388
6389 if MBTEST(ch == CTLESC || ch == CTLNUL) /* special shell escapes */
6390 {
6391 RESIZE_MALLOCED_BUFFER (ret, retind, 2, retsize, 64);
6392 ret[retind++] = CTLESC;
6393 ret[retind++] = ch;
6394 continue;
6395 }
6396 #if 0
6397 else if MBTEST((tflags & LEX_INCASE) && ch == close && close == ')')
6398 tflags &= ~LEX_INCASE; /* XXX */
6399 #endif
6400 else if MBTEST(ch == close && (tflags & LEX_INCASE) == 0) /* ending delimiter */
6401 {
6402 count--;
6403 /*itrace("parse_comsub:%d: found close: count = %d", line_number, count);*/
6404 }
6405 else if MBTEST(((flags & P_FIRSTCLOSE) == 0) && (tflags & LEX_INCASE) == 0 && ch == open) /* nested begin */
6406 {
6407 count++;
6408 /*itrace("parse_comsub:%d: found open: count = %d", line_number, count);*/
6409 }
6410
6411 /* Add this character. */
6412 RESIZE_MALLOCED_BUFFER (ret, retind, 1, retsize, 64);
6413 ret[retind++] = ch;
6414
6415 /* If we just read the ending character, don't bother continuing. */
6416 if (count == 0)
6417 break;
6418
6419 if MBTEST(ch == '\\') /* backslashes */
6420 tflags |= LEX_PASSNEXT;
6421
6422 if MBTEST(shellquote (ch))
6423 {
6424 /* '', ``, or "" inside $(...). */
6425 push_delimiter (dstack, ch);
6426 if MBTEST((tflags & LEX_WASDOL) && ch == '\'') /* $'...' inside group */
6427 nestret = parse_matched_pair (ch, ch, ch, &nestlen, P_ALLOWESC|rflags);
6428 else
6429 nestret = parse_matched_pair (ch, ch, ch, &nestlen, rflags);
6430 pop_delimiter (dstack);
6431 CHECK_NESTRET_ERROR ();
6432
6433 if MBTEST((tflags & LEX_WASDOL) && ch == '\'' && (extended_quote || (rflags & P_DQUOTE) == 0))
6434 {
6435 /* Translate $'...' here. */
6436 ttrans = ansiexpand (nestret, 0, nestlen - 1, &ttranslen);
6437 xfree (nestret);
6438
6439 if ((rflags & P_DQUOTE) == 0)
6440 {
6441 nestret = sh_single_quote (ttrans);
6442 free (ttrans);
6443 nestlen = strlen (nestret);
6444 }
6445 else
6446 {
6447 nestret = ttrans;
6448 nestlen = ttranslen;
6449 }
6450 retind -= 2; /* back up before the $' */
6451 }
6452 else if MBTEST((tflags & LEX_WASDOL) && ch == '"' && (extended_quote || (rflags & P_DQUOTE) == 0))
6453 {
6454 /* Locale expand $"..." here. */
6455 ttrans = localeexpand (nestret, 0, nestlen - 1, start_lineno, &ttranslen);
6456 xfree (nestret);
6457
6458 nestret = sh_mkdoublequoted (ttrans, ttranslen, 0);
6459 free (ttrans);
6460 nestlen = ttranslen + 2;
6461 retind -= 2; /* back up before the $" */
6462 }
6463
6464 APPEND_NESTRET ();
6465 FREE (nestret);
6466 }
6467 else if MBTEST((tflags & LEX_WASDOL) && (ch == '(' || ch == '{' || ch == '[')) /* ) } ] */
6468 /* check for $(), $[], or ${} inside command substitution. */
6469 {
6470 if ((tflags & LEX_INCASE) == 0 && open == ch) /* undo previous increment */
6471 count--;
6472 if (ch == '(') /* ) */
6473 nestret = parse_comsub (0, '(', ')', &nestlen, (rflags|P_COMMAND) & ~P_DQUOTE);
6474 else if (ch == '{') /* } */
6475 nestret = parse_matched_pair (0, '{', '}', &nestlen, P_FIRSTCLOSE|P_DOLBRACE|rflags);
6476 else if (ch == '[') /* ] */
6477 nestret = parse_matched_pair (0, '[', ']', &nestlen, rflags);
6478
6479 CHECK_NESTRET_ERROR ();
6480 APPEND_NESTRET ();
6481
6482 FREE (nestret);
6483 }
6484 if MBTEST(ch == '$')
6485 tflags |= LEX_WASDOL;
6486 else
6487 tflags &= ~LEX_WASDOL;
6488 }
6489
6490 FREE (heredelim);
6491 ret[retind] = '\0';
6492 if (lenp)
6493 *lenp = retind;
6494 /*itrace("parse_comsub:%d: returning `%s'", line_number, ret);*/
6495 return ret;
6496 }
6497
6498 /* Recursively call the parser to parse a $(...) command substitution. */
6499 char *
6500 xparse_dolparen (base, string, indp, flags)
6501 char *base;
6502 char *string;
6503 int *indp;
6504 int flags;
6505 {
6506 sh_parser_state_t ps;
6507 sh_input_line_state_t ls;
6508 int orig_ind, nc, sflags, orig_eof_token;
6509 char *ret, *s, *ep, *ostring;
6510
6511 /*yydebug = 1;*/
6512 orig_ind = *indp;
6513 ostring = string;
6514
6515 /*itrace("xparse_dolparen: size = %d shell_input_line = `%s'", shell_input_line_size, shell_input_line);*/
6516 sflags = SEVAL_NONINT|SEVAL_NOHIST|SEVAL_NOFREE;
6517 if (flags & SX_NOLONGJMP)
6518 sflags |= SEVAL_NOLONGJMP;
6519 save_parser_state (&ps);
6520 save_input_line_state (&ls);
6521 orig_eof_token = shell_eof_token;
6522
6523 /*(*/
6524 parser_state |= PST_CMDSUBST|PST_EOFTOKEN; /* allow instant ')' */ /*(*/
6525 shell_eof_token = ')';
6526
6527 nc = parse_string (string, "command substitution", sflags, &ep);
6528
6529 shell_eof_token = orig_eof_token;
6530 restore_parser_state (&ps);
6531 reset_parser ();
6532 /* reset_parser clears shell_input_line and associated variables */
6533 restore_input_line_state (&ls);
6534
6535 token_to_read = 0;
6536
6537 /* If parse_string returns < 0, we need to jump to top level with the
6538 negative of the return value */
6539 if (nc < 0)
6540 jump_to_top_level (-nc); /* XXX */
6541
6542 /* Need to find how many characters parse_and_execute consumed, update
6543 *indp, if flags != 0, copy the portion of the string parsed into RET
6544 and return it. If flags & 1 (EX_NOALLOC) we can return NULL. */
6545
6546 /*(*/
6547 if (ep[-1] != ')')
6548 {
6549 #if DEBUG
6550 if (ep[-1] != '\n')
6551 itrace("xparse_dolparen:%d: ep[-1] != RPAREN (%d), ep = `%s'", line_number, ep[-1], ep);
6552 #endif
6553 while (ep > ostring && ep[-1] == '\n') ep--;
6554 }
6555
6556 nc = ep - ostring;
6557 *indp = ep - base - 1;
6558
6559 /*(*/
6560 #if DEBUG
6561 if (base[*indp] != ')')
6562 itrace("xparse_dolparen:%d: base[%d] != RPAREN (%d), base = `%s'", line_number, *indp, base[*indp], base);
6563 #endif
6564
6565 if (flags & SX_NOALLOC)
6566 return (char *)NULL;
6567
6568 if (nc == 0)
6569 {
6570 ret = xmalloc (1);
6571 ret[0] = '\0';
6572 }
6573 else
6574 ret = substring (ostring, 0, nc - 1);
6575
6576 return ret;
6577 }
6578
6579 #if defined (DPAREN_ARITHMETIC) || defined (ARITH_FOR_COMMAND)
6580 /* Parse a double-paren construct. It can be either an arithmetic
6581 command, an arithmetic `for' command, or a nested subshell. Returns
6582 the parsed token, -1 on error, or -2 if we didn't do anything and
6583 should just go on. */
6584 static int
6585 parse_dparen (c)
6586 int c;
6587 {
6588 int cmdtyp, sline;
6589 char *wval;
6590 WORD_DESC *wd;
6591
6592 #if defined (ARITH_FOR_COMMAND)
6593 if (last_read_token == FOR)
6594 {
6595 arith_for_lineno = line_number;
6596 cmdtyp = parse_arith_cmd (&wval, 0);
6597 if (cmdtyp == 1)
6598 {
6599 wd = alloc_word_desc ();
6600 wd->word = wval;
6601 yylval.word_list = make_word_list (wd, (WORD_LIST *)NULL);
6602 return (ARITH_FOR_EXPRS);
6603 }
6604 else
6605 return -1; /* ERROR */
6606 }
6607 #endif
6608
6609 #if defined (DPAREN_ARITHMETIC)
6610 if (reserved_word_acceptable (last_read_token))
6611 {
6612 sline = line_number;
6613
6614 cmdtyp = parse_arith_cmd (&wval, 0);
6615 if (cmdtyp == 1) /* arithmetic command */
6616 {
6617 wd = alloc_word_desc ();
6618 wd->word = wval;
6619 wd->flags = W_QUOTED|W_NOSPLIT|W_NOGLOB|W_DQUOTE;
6620 yylval.word_list = make_word_list (wd, (WORD_LIST *)NULL);
6621 return (ARITH_CMD);
6622 }
6623 else if (cmdtyp == 0) /* nested subshell */
6624 {
6625 push_string (wval, 0, (alias_t *)NULL);
6626 pushed_string_list->flags = PSH_DPAREN;
6627 if ((parser_state & PST_CASEPAT) == 0)
6628 parser_state |= PST_SUBSHELL;
6629 return (c);
6630 }
6631 else /* ERROR */
6632 return -1;
6633 }
6634 #endif
6635
6636 return -2; /* XXX */
6637 }
6638
6639 /* We've seen a `(('. Look for the matching `))'. If we get it, return 1.
6640 If not, assume it's a nested subshell for backwards compatibility and
6641 return 0. In any case, put the characters we've consumed into a locally-
6642 allocated buffer and make *ep point to that buffer. Return -1 on an
6643 error, for example EOF. */
6644 static int
6645 parse_arith_cmd (ep, adddq)
6646 char **ep;
6647 int adddq;
6648 {
6649 int exp_lineno, rval, c;
6650 char *ttok, *tokstr;
6651 int ttoklen;
6652
6653 exp_lineno = line_number;
6654 ttok = parse_matched_pair (0, '(', ')', &ttoklen, 0);
6655 rval = 1;
6656 if (ttok == &matched_pair_error)
6657 return -1;
6658 /* Check that the next character is the closing right paren. If
6659 not, this is a syntax error. ( */
6660 c = shell_getc (0);
6661 if MBTEST(c != ')')
6662 rval = 0;
6663
6664 tokstr = (char *)xmalloc (ttoklen + 4);
6665
6666 /* if ADDDQ != 0 then (( ... )) -> "..." */
6667 if (rval == 1 && adddq) /* arith cmd, add double quotes */
6668 {
6669 tokstr[0] = '"';
6670 strncpy (tokstr + 1, ttok, ttoklen - 1);
6671 tokstr[ttoklen] = '"';
6672 tokstr[ttoklen+1] = '\0';
6673 }
6674 else if (rval == 1) /* arith cmd, don't add double quotes */
6675 {
6676 strncpy (tokstr, ttok, ttoklen - 1);
6677 tokstr[ttoklen-1] = '\0';
6678 }
6679 else /* nested subshell */
6680 {
6681 tokstr[0] = '(';
6682 strncpy (tokstr + 1, ttok, ttoklen - 1);
6683 tokstr[ttoklen] = ')';
6684 tokstr[ttoklen+1] = c;
6685 tokstr[ttoklen+2] = '\0';
6686 }
6687
6688 *ep = tokstr;
6689 FREE (ttok);
6690 return rval;
6691 }
6692 #endif /* DPAREN_ARITHMETIC || ARITH_FOR_COMMAND */
6693
6694 #if defined (COND_COMMAND)
6695 static void
6696 cond_error ()
6697 {
6698 char *etext;
6699
6700 if (EOF_Reached && cond_token != COND_ERROR) /* [[ */
6701 parser_error (cond_lineno, _("unexpected EOF while looking for `]]'"));
6702 else if (cond_token != COND_ERROR)
6703 {
6704 if (etext = error_token_from_token (cond_token))
6705 {
6706 parser_error (cond_lineno, _("syntax error in conditional expression: unexpected token `%s'"), etext);
6707 free (etext);
6708 }
6709 else
6710 parser_error (cond_lineno, _("syntax error in conditional expression"));
6711 }
6712 }
6713
6714 static COND_COM *
6715 cond_expr ()
6716 {
6717 return (cond_or ());
6718 }
6719
6720 static COND_COM *
6721 cond_or ()
6722 {
6723 COND_COM *l, *r;
6724
6725 l = cond_and ();
6726 if (cond_token == OR_OR)
6727 {
6728 r = cond_or ();
6729 l = make_cond_node (COND_OR, (WORD_DESC *)NULL, l, r);
6730 }
6731 return l;
6732 }
6733
6734 static COND_COM *
6735 cond_and ()
6736 {
6737 COND_COM *l, *r;
6738
6739 l = cond_term ();
6740 if (cond_token == AND_AND)
6741 {
6742 r = cond_and ();
6743 l = make_cond_node (COND_AND, (WORD_DESC *)NULL, l, r);
6744 }
6745 return l;
6746 }
6747
6748 static int
6749 cond_skip_newlines ()
6750 {
6751 while ((cond_token = read_token (READ)) == '\n')
6752 {
6753 if (SHOULD_PROMPT ())
6754 prompt_again ();
6755 }
6756 return (cond_token);
6757 }
6758
6759 #define COND_RETURN_ERROR() \
6760 do { cond_token = COND_ERROR; return ((COND_COM *)NULL); } while (0)
6761
6762 static COND_COM *
6763 cond_term ()
6764 {
6765 WORD_DESC *op;
6766 COND_COM *term, *tleft, *tright;
6767 int tok, lineno;
6768 char *etext;
6769
6770 /* Read a token. It can be a left paren, a `!', a unary operator, or a
6771 word that should be the first argument of a binary operator. Start by
6772 skipping newlines, since this is a compound command. */
6773 tok = cond_skip_newlines ();
6774 lineno = line_number;
6775 if (tok == COND_END)
6776 {
6777 COND_RETURN_ERROR ();
6778 }
6779 else if (tok == '(')
6780 {
6781 term = cond_expr ();
6782 if (cond_token != ')')
6783 {
6784 if (term)
6785 dispose_cond_node (term); /* ( */
6786 if (etext = error_token_from_token (cond_token))
6787 {
6788 parser_error (lineno, _("unexpected token `%s', expected `)'"), etext);
6789 free (etext);
6790 }
6791 else
6792 parser_error (lineno, _("expected `)'"));
6793 COND_RETURN_ERROR ();
6794 }
6795 term = make_cond_node (COND_EXPR, (WORD_DESC *)NULL, term, (COND_COM *)NULL);
6796 (void)cond_skip_newlines ();
6797 }
6798 else if (tok == BANG || (tok == WORD && (yylval.word->word[0] == '!' && yylval.word->word[1] == '\0')))
6799 {
6800 if (tok == WORD)
6801 dispose_word (yylval.word); /* not needed */
6802 term = cond_term ();
6803 if (term)
6804 term->flags |= CMD_INVERT_RETURN;
6805 }
6806 else if (tok == WORD && yylval.word->word[0] == '-' && yylval.word->word[2] == 0 && test_unop (yylval.word->word))
6807 {
6808 op = yylval.word;
6809 tok = read_token (READ);
6810 if (tok == WORD)
6811 {
6812 tleft = make_cond_node (COND_TERM, yylval.word, (COND_COM *)NULL, (COND_COM *)NULL);
6813 term = make_cond_node (COND_UNARY, op, tleft, (COND_COM *)NULL);
6814 }
6815 else
6816 {
6817 dispose_word (op);
6818 if (etext = error_token_from_token (tok))
6819 {
6820 parser_error (line_number, _("unexpected argument `%s' to conditional unary operator"), etext);
6821 free (etext);
6822 }
6823 else
6824 parser_error (line_number, _("unexpected argument to conditional unary operator"));
6825 COND_RETURN_ERROR ();
6826 }
6827
6828 (void)cond_skip_newlines ();
6829 }
6830 else if (tok == WORD) /* left argument to binary operator */
6831 {
6832 /* lhs */
6833 tleft = make_cond_node (COND_TERM, yylval.word, (COND_COM *)NULL, (COND_COM *)NULL);
6834
6835 /* binop */
6836 tok = read_token (READ);
6837 if (tok == WORD && test_binop (yylval.word->word))
6838 {
6839 op = yylval.word;
6840 if (op->word[0] == '=' && (op->word[1] == '\0' || (op->word[1] == '=' && op->word[2] == '\0')))
6841 parser_state |= PST_EXTPAT;
6842 else if (op->word[0] == '!' && op->word[1] == '=' && op->word[2] == '\0')
6843 parser_state |= PST_EXTPAT;
6844 }
6845 #if defined (COND_REGEXP)
6846 else if (tok == WORD && STREQ (yylval.word->word, "=~"))
6847 {
6848 op = yylval.word;
6849 parser_state |= PST_REGEXP;
6850 }
6851 #endif
6852 else if (tok == '<' || tok == '>')
6853 op = make_word_from_token (tok); /* ( */
6854 /* There should be a check before blindly accepting the `)' that we have
6855 seen the opening `('. */
6856 else if (tok == COND_END || tok == AND_AND || tok == OR_OR || tok == ')')
6857 {
6858 /* Special case. [[ x ]] is equivalent to [[ -n x ]], just like
6859 the test command. Similarly for [[ x && expr ]] or
6860 [[ x || expr ]] or [[ (x) ]]. */
6861 op = make_word ("-n");
6862 term = make_cond_node (COND_UNARY, op, tleft, (COND_COM *)NULL);
6863 cond_token = tok;
6864 return (term);
6865 }
6866 else
6867 {
6868 if (etext = error_token_from_token (tok))
6869 {
6870 parser_error (line_number, _("unexpected token `%s', conditional binary operator expected"), etext);
6871 free (etext);
6872 }
6873 else
6874 parser_error (line_number, _("conditional binary operator expected"));
6875 dispose_cond_node (tleft);
6876 COND_RETURN_ERROR ();
6877 }
6878
6879 /* rhs */
6880 if (parser_state & PST_EXTPAT)
6881 extended_glob = 1;
6882 tok = read_token (READ);
6883 if (parser_state & PST_EXTPAT)
6884 extended_glob = global_extglob;
6885 parser_state &= ~(PST_REGEXP|PST_EXTPAT);
6886
6887 if (tok == WORD)
6888 {
6889 tright = make_cond_node (COND_TERM, yylval.word, (COND_COM *)NULL, (COND_COM *)NULL);
6890 term = make_cond_node (COND_BINARY, op, tleft, tright);
6891 }
6892 else
6893 {
6894 if (etext = error_token_from_token (tok))
6895 {
6896 parser_error (line_number, _("unexpected argument `%s' to conditional binary operator"), etext);
6897 free (etext);
6898 }
6899 else
6900 parser_error (line_number, _("unexpected argument to conditional binary operator"));
6901 dispose_cond_node (tleft);
6902 dispose_word (op);
6903 COND_RETURN_ERROR ();
6904 }
6905
6906 (void)cond_skip_newlines ();
6907 }
6908 else
6909 {
6910 if (tok < 256)
6911 parser_error (line_number, _("unexpected token `%c' in conditional command"), tok);
6912 else if (etext = error_token_from_token (tok))
6913 {
6914 parser_error (line_number, _("unexpected token `%s' in conditional command"), etext);
6915 free (etext);
6916 }
6917 else
6918 parser_error (line_number, _("unexpected token %d in conditional command"), tok);
6919 COND_RETURN_ERROR ();
6920 }
6921 return (term);
6922 }
6923
6924 /* This is kind of bogus -- we slip a mini recursive-descent parser in
6925 here to handle the conditional statement syntax. */
6926 static COMMAND *
6927 parse_cond_command ()
6928 {
6929 COND_COM *cexp;
6930
6931 global_extglob = extended_glob;
6932 cexp = cond_expr ();
6933 return (make_cond_command (cexp));
6934 }
6935 #endif
6936
6937 #if defined (ARRAY_VARS)
6938 /* When this is called, it's guaranteed that we don't care about anything
6939 in t beyond i. We do save and restore the chars, though. */
6940 static int
6941 token_is_assignment (t, i)
6942 char *t;
6943 int i;
6944 {
6945 unsigned char c, c1;
6946 int r;
6947
6948 c = t[i]; c1 = t[i+1];
6949 t[i] = '='; t[i+1] = '\0';
6950 r = assignment (t, (parser_state & PST_COMPASSIGN) != 0);
6951 t[i] = c; t[i+1] = c1;
6952 return r;
6953 }
6954
6955 /* XXX - possible changes here for `+=' */
6956 static int
6957 token_is_ident (t, i)
6958 char *t;
6959 int i;
6960 {
6961 unsigned char c;
6962 int r;
6963
6964 c = t[i];
6965 t[i] = '\0';
6966 r = legal_identifier (t);
6967 t[i] = c;
6968 return r;
6969 }
6970 #endif
6971
6972 static int
6973 read_token_word (character)
6974 int character;
6975 {
6976 /* The value for YYLVAL when a WORD is read. */
6977 WORD_DESC *the_word;
6978
6979 /* Index into the token that we are building. */
6980 int token_index;
6981
6982 /* ALL_DIGITS becomes zero when we see a non-digit. */
6983 int all_digit_token;
6984
6985 /* DOLLAR_PRESENT becomes non-zero if we see a `$'. */
6986 int dollar_present;
6987
6988 /* COMPOUND_ASSIGNMENT becomes non-zero if we are parsing a compound
6989 assignment. */
6990 int compound_assignment;
6991
6992 /* QUOTED becomes non-zero if we see one of ("), ('), (`), or (\). */
6993 int quoted;
6994
6995 /* Non-zero means to ignore the value of the next character, and just
6996 to add it no matter what. */
6997 int pass_next_character;
6998
6999 /* The current delimiting character. */
7000 int cd;
7001 int result, peek_char;
7002 char *ttok, *ttrans;
7003 int ttoklen, ttranslen;
7004 intmax_t lvalue;
7005
7006 if (token_buffer_size < TOKEN_DEFAULT_INITIAL_SIZE)
7007 token = (char *)xrealloc (token, token_buffer_size = TOKEN_DEFAULT_INITIAL_SIZE);
7008
7009 token_index = 0;
7010 all_digit_token = DIGIT (character);
7011 dollar_present = quoted = pass_next_character = compound_assignment = 0;
7012
7013 for (;;)
7014 {
7015 if (character == EOF)
7016 goto got_token;
7017
7018 if (pass_next_character)
7019 {
7020 pass_next_character = 0;
7021 goto got_escaped_character;
7022 }
7023
7024 cd = current_delimiter (dstack);
7025
7026 /* Handle backslashes. Quote lots of things when not inside of
7027 double-quotes, quote some things inside of double-quotes. */
7028 if MBTEST(character == '\\')
7029 {
7030 peek_char = shell_getc (0);
7031
7032 /* Backslash-newline is ignored in all cases except
7033 when quoted with single quotes. */
7034 if (peek_char == '\n')
7035 {
7036 character = '\n';
7037 goto next_character;
7038 }
7039 else
7040 {
7041 shell_ungetc (peek_char);
7042
7043 /* If the next character is to be quoted, note it now. */
7044 if (cd == 0 || cd == '`' ||
7045 (cd == '"' && peek_char >= 0 && (sh_syntaxtab[peek_char] & CBSDQUOTE)))
7046 pass_next_character++;
7047
7048 quoted = 1;
7049 goto got_character;
7050 }
7051 }
7052
7053 /* Parse a matched pair of quote characters. */
7054 if MBTEST(shellquote (character))
7055 {
7056 push_delimiter (dstack, character);
7057 ttok = parse_matched_pair (character, character, character, &ttoklen, (character == '`') ? P_COMMAND : 0);
7058 pop_delimiter (dstack);
7059 if (ttok == &matched_pair_error)
7060 return -1; /* Bail immediately. */
7061 RESIZE_MALLOCED_BUFFER (token, token_index, ttoklen + 2,
7062 token_buffer_size, TOKEN_DEFAULT_GROW_SIZE);
7063 token[token_index++] = character;
7064 strcpy (token + token_index, ttok);
7065 token_index += ttoklen;
7066 all_digit_token = 0;
7067 quoted = 1;
7068 dollar_present |= (character == '"' && strchr (ttok, '$') != 0);
7069 FREE (ttok);
7070 goto next_character;
7071 }
7072
7073 #ifdef COND_REGEXP
7074 /* When parsing a regexp as a single word inside a conditional command,
7075 we need to special-case characters special to both the shell and
7076 regular expressions. Right now, that is only '(' and '|'. */ /*)*/
7077 if MBTEST((parser_state & PST_REGEXP) && (character == '(' || character == '|')) /*)*/
7078 {
7079 if (character == '|')
7080 goto got_character;
7081
7082 push_delimiter (dstack, character);
7083 ttok = parse_matched_pair (cd, '(', ')', &ttoklen, 0);
7084 pop_delimiter (dstack);
7085 if (ttok == &matched_pair_error)
7086 return -1; /* Bail immediately. */
7087 RESIZE_MALLOCED_BUFFER (token, token_index, ttoklen + 2,
7088 token_buffer_size, TOKEN_DEFAULT_GROW_SIZE);
7089 token[token_index++] = character;
7090 strcpy (token + token_index, ttok);
7091 token_index += ttoklen;
7092 FREE (ttok);
7093 dollar_present = all_digit_token = 0;
7094 goto next_character;
7095 }
7096 #endif /* COND_REGEXP */
7097
7098 #ifdef EXTENDED_GLOB
7099 /* Parse a ksh-style extended pattern matching specification. */
7100 if MBTEST(extended_glob && PATTERN_CHAR (character))
7101 {
7102 peek_char = shell_getc (1);
7103 if MBTEST(peek_char == '(') /* ) */
7104 {
7105 push_delimiter (dstack, peek_char);
7106 ttok = parse_matched_pair (cd, '(', ')', &ttoklen, 0);
7107 pop_delimiter (dstack);
7108 if (ttok == &matched_pair_error)
7109 return -1; /* Bail immediately. */
7110 RESIZE_MALLOCED_BUFFER (token, token_index, ttoklen + 3,
7111 token_buffer_size,
7112 TOKEN_DEFAULT_GROW_SIZE);
7113 token[token_index++] = character;
7114 token[token_index++] = peek_char;
7115 strcpy (token + token_index, ttok);
7116 token_index += ttoklen;
7117 FREE (ttok);
7118 dollar_present = all_digit_token = 0;
7119 goto next_character;
7120 }
7121 else
7122 shell_ungetc (peek_char);
7123 }
7124 #endif /* EXTENDED_GLOB */
7125
7126 /* If the delimiter character is not single quote, parse some of
7127 the shell expansions that must be read as a single word. */
7128 if (shellexp (character))
7129 {
7130 peek_char = shell_getc (1);
7131 /* $(...), <(...), >(...), $((...)), ${...}, and $[...] constructs */
7132 if MBTEST(peek_char == '(' ||
7133 ((peek_char == '{' || peek_char == '[') && character == '$')) /* ) ] } */
7134 {
7135 if (peek_char == '{') /* } */
7136 ttok = parse_matched_pair (cd, '{', '}', &ttoklen, P_FIRSTCLOSE|P_DOLBRACE);
7137 else if (peek_char == '(') /* ) */
7138 {
7139 /* XXX - push and pop the `(' as a delimiter for use by
7140 the command-oriented-history code. This way newlines
7141 appearing in the $(...) string get added to the
7142 history literally rather than causing a possibly-
7143 incorrect `;' to be added. ) */
7144 push_delimiter (dstack, peek_char);
7145 ttok = parse_comsub (cd, '(', ')', &ttoklen, P_COMMAND);
7146 pop_delimiter (dstack);
7147 }
7148 else
7149 ttok = parse_matched_pair (cd, '[', ']', &ttoklen, 0);
7150 if (ttok == &matched_pair_error)
7151 return -1; /* Bail immediately. */
7152 RESIZE_MALLOCED_BUFFER (token, token_index, ttoklen + 3,
7153 token_buffer_size,
7154 TOKEN_DEFAULT_GROW_SIZE);
7155 token[token_index++] = character;
7156 token[token_index++] = peek_char;
7157 strcpy (token + token_index, ttok);
7158 token_index += ttoklen;
7159 FREE (ttok);
7160 dollar_present = 1;
7161 all_digit_token = 0;
7162 goto next_character;
7163 }
7164 /* This handles $'...' and $"..." new-style quoted strings. */
7165 else if MBTEST(character == '$' && (peek_char == '\'' || peek_char == '"'))
7166 {
7167 int first_line;
7168
7169 first_line = line_number;
7170 push_delimiter (dstack, peek_char);
7171 ttok = parse_matched_pair (peek_char, peek_char, peek_char,
7172 &ttoklen,
7173 (peek_char == '\'') ? P_ALLOWESC : 0);
7174 pop_delimiter (dstack);
7175 if (ttok == &matched_pair_error)
7176 return -1;
7177 if (peek_char == '\'')
7178 {
7179 ttrans = ansiexpand (ttok, 0, ttoklen - 1, &ttranslen);
7180 free (ttok);
7181
7182 /* Insert the single quotes and correctly quote any
7183 embedded single quotes (allowed because P_ALLOWESC was
7184 passed to parse_matched_pair). */
7185 ttok = sh_single_quote (ttrans);
7186 free (ttrans);
7187 ttranslen = strlen (ttok);
7188 ttrans = ttok;
7189 }
7190 else
7191 {
7192 /* Try to locale-expand the converted string. */
7193 ttrans = localeexpand (ttok, 0, ttoklen - 1, first_line, &ttranslen);
7194 free (ttok);
7195
7196 /* Add the double quotes back */
7197 ttok = sh_mkdoublequoted (ttrans, ttranslen, 0);
7198 free (ttrans);
7199 ttranslen += 2;
7200 ttrans = ttok;
7201 }
7202
7203 RESIZE_MALLOCED_BUFFER (token, token_index, ttranslen + 1,
7204 token_buffer_size,
7205 TOKEN_DEFAULT_GROW_SIZE);
7206 strcpy (token + token_index, ttrans);
7207 token_index += ttranslen;
7208 FREE (ttrans);
7209 quoted = 1;
7210 all_digit_token = 0;
7211 goto next_character;
7212 }
7213 /* This could eventually be extended to recognize all of the
7214 shell's single-character parameter expansions, and set flags.*/
7215 else if MBTEST(character == '$' && peek_char == '$')
7216 {
7217 RESIZE_MALLOCED_BUFFER (token, token_index, 3,
7218 token_buffer_size,
7219 TOKEN_DEFAULT_GROW_SIZE);
7220 token[token_index++] = '$';
7221 token[token_index++] = peek_char;
7222 dollar_present = 1;
7223 all_digit_token = 0;
7224 goto next_character;
7225 }
7226 else
7227 shell_ungetc (peek_char);
7228 }
7229
7230 #if defined (ARRAY_VARS)
7231 /* Identify possible array subscript assignment; match [...]. If
7232 parser_state&PST_COMPASSIGN, we need to parse [sub]=words treating
7233 `sub' as if it were enclosed in double quotes. */
7234 else if MBTEST(character == '[' && /* ] */
7235 ((token_index > 0 && assignment_acceptable (last_read_token) && token_is_ident (token, token_index)) ||
7236 (token_index == 0 && (parser_state&PST_COMPASSIGN))))
7237 {
7238 ttok = parse_matched_pair (cd, '[', ']', &ttoklen, P_ARRAYSUB);
7239 if (ttok == &matched_pair_error)
7240 return -1; /* Bail immediately. */
7241 RESIZE_MALLOCED_BUFFER (token, token_index, ttoklen + 2,
7242 token_buffer_size,
7243 TOKEN_DEFAULT_GROW_SIZE);
7244 token[token_index++] = character;
7245 strcpy (token + token_index, ttok);
7246 token_index += ttoklen;
7247 FREE (ttok);
7248 all_digit_token = 0;
7249 goto next_character;
7250 }
7251 /* Identify possible compound array variable assignment. */
7252 else if MBTEST(character == '=' && token_index > 0 && (assignment_acceptable (last_read_token) || (parser_state & PST_ASSIGNOK)) && token_is_assignment (token, token_index))
7253 {
7254 peek_char = shell_getc (1);
7255 if MBTEST(peek_char == '(') /* ) */
7256 {
7257 ttok = parse_compound_assignment (&ttoklen);
7258
7259 RESIZE_MALLOCED_BUFFER (token, token_index, ttoklen + 4,
7260 token_buffer_size,
7261 TOKEN_DEFAULT_GROW_SIZE);
7262
7263 token[token_index++] = '=';
7264 token[token_index++] = '(';
7265 if (ttok)
7266 {
7267 strcpy (token + token_index, ttok);
7268 token_index += ttoklen;
7269 }
7270 token[token_index++] = ')';
7271 FREE (ttok);
7272 all_digit_token = 0;
7273 compound_assignment = 1;
7274 #if 1
7275 goto next_character;
7276 #else
7277 goto got_token; /* ksh93 seems to do this */
7278 #endif
7279 }
7280 else
7281 shell_ungetc (peek_char);
7282 }
7283 #endif
7284
7285 /* When not parsing a multi-character word construct, shell meta-
7286 characters break words. */
7287 if MBTEST(shellbreak (character))
7288 {
7289 shell_ungetc (character);
7290 goto got_token;
7291 }
7292
7293 got_character:
7294 if (character == CTLESC || character == CTLNUL)
7295 {
7296 RESIZE_MALLOCED_BUFFER (token, token_index, 2, token_buffer_size,
7297 TOKEN_DEFAULT_GROW_SIZE);
7298 token[token_index++] = CTLESC;
7299 }
7300 else
7301 got_escaped_character:
7302 RESIZE_MALLOCED_BUFFER (token, token_index, 1, token_buffer_size,
7303 TOKEN_DEFAULT_GROW_SIZE);
7304
7305 token[token_index++] = character;
7306
7307 all_digit_token &= DIGIT (character);
7308 dollar_present |= character == '$';
7309
7310 next_character:
7311 if (character == '\n' && SHOULD_PROMPT ())
7312 prompt_again ();
7313
7314 /* We want to remove quoted newlines (that is, a \<newline> pair)
7315 unless we are within single quotes or pass_next_character is
7316 set (the shell equivalent of literal-next). */
7317 cd = current_delimiter (dstack);
7318 character = shell_getc (cd != '\'' && pass_next_character == 0);
7319 } /* end for (;;) */
7320
7321 got_token:
7322
7323 /* Calls to RESIZE_MALLOCED_BUFFER ensure there is sufficient room. */
7324 token[token_index] = '\0';
7325
7326 /* Check to see what thing we should return. If the last_read_token
7327 is a `<', or a `&', or the character which ended this token is
7328 a '>' or '<', then, and ONLY then, is this input token a NUMBER.
7329 Otherwise, it is just a word, and should be returned as such. */
7330 if MBTEST(all_digit_token && (character == '<' || character == '>' ||
7331 last_read_token == LESS_AND ||
7332 last_read_token == GREATER_AND))
7333 {
7334 if (legal_number (token, &lvalue) && (int)lvalue == lvalue)
7335 {
7336 yylval.number = lvalue;
7337 return (NUMBER);
7338 }
7339 }
7340
7341 /* Check for special case tokens. */
7342 result = (last_shell_getc_is_singlebyte) ? special_case_tokens (token) : -1;
7343 if (result >= 0)
7344 return result;
7345
7346 #if defined (ALIAS)
7347 /* Posix.2 does not allow reserved words to be aliased, so check for all
7348 of them, including special cases, before expanding the current token
7349 as an alias. */
7350 if MBTEST(posixly_correct)
7351 CHECK_FOR_RESERVED_WORD (token);
7352
7353 /* Aliases are expanded iff EXPAND_ALIASES is non-zero, and quoting
7354 inhibits alias expansion. */
7355 if (expand_aliases && quoted == 0)
7356 {
7357 result = alias_expand_token (token);
7358 if (result == RE_READ_TOKEN)
7359 return (RE_READ_TOKEN);
7360 else if (result == NO_EXPANSION)
7361 parser_state &= ~PST_ALEXPNEXT;
7362 }
7363
7364 /* If not in Posix.2 mode, check for reserved words after alias
7365 expansion. */
7366 if MBTEST(posixly_correct == 0)
7367 #endif
7368 CHECK_FOR_RESERVED_WORD (token);
7369
7370 the_word = alloc_word_desc ();
7371 the_word->word = (char *)xmalloc (1 + token_index);
7372 the_word->flags = 0;
7373 strcpy (the_word->word, token);
7374 if (dollar_present)
7375 the_word->flags |= W_HASDOLLAR;
7376 if (quoted)
7377 the_word->flags |= W_QUOTED; /*(*/
7378 if (compound_assignment && token[token_index-1] == ')')
7379 the_word->flags |= W_COMPASSIGN;
7380 /* A word is an assignment if it appears at the beginning of a
7381 simple command, or after another assignment word. This is
7382 context-dependent, so it cannot be handled in the grammar. */
7383 if (assignment (token, (parser_state & PST_COMPASSIGN) != 0))
7384 {
7385 the_word->flags |= W_ASSIGNMENT;
7386 /* Don't perform word splitting on assignment statements. */
7387 if (assignment_acceptable (last_read_token) || (parser_state & PST_COMPASSIGN) != 0)
7388 {
7389 the_word->flags |= W_NOSPLIT;
7390 if (parser_state & PST_COMPASSIGN)
7391 the_word->flags |= W_NOGLOB; /* XXX - W_NOBRACE? */
7392 }
7393 }
7394
7395 if (command_token_position (last_read_token))
7396 {
7397 struct builtin *b;
7398 b = builtin_address_internal (token, 0);
7399 if (b && (b->flags & ASSIGNMENT_BUILTIN))
7400 parser_state |= PST_ASSIGNOK;
7401 else if (STREQ (token, "eval") || STREQ (token, "let"))
7402 parser_state |= PST_ASSIGNOK;
7403 }
7404
7405 yylval.word = the_word;
7406
7407 if (token[0] == '{' && token[token_index-1] == '}' &&
7408 (character == '<' || character == '>'))
7409 {
7410 /* can use token; already copied to the_word */
7411 token[token_index-1] = '\0';
7412 #if defined (ARRAY_VARS)
7413 if (legal_identifier (token+1) || valid_array_reference (token+1, 0))
7414 #else
7415 if (legal_identifier (token+1))
7416 #endif
7417 {
7418 strcpy (the_word->word, token+1);
7419 /*itrace("read_token_word: returning REDIR_WORD for %s", the_word->word);*/
7420 return (REDIR_WORD);
7421 }
7422 }
7423
7424 result = ((the_word->flags & (W_ASSIGNMENT|W_NOSPLIT)) == (W_ASSIGNMENT|W_NOSPLIT))
7425 ? ASSIGNMENT_WORD : WORD;
7426
7427 switch (last_read_token)
7428 {
7429 case FUNCTION:
7430 parser_state |= PST_ALLOWOPNBRC;
7431 function_dstart = line_number;
7432 break;
7433 case CASE:
7434 case SELECT:
7435 case FOR:
7436 if (word_top < MAX_CASE_NEST)
7437 word_top++;
7438 word_lineno[word_top] = line_number;
7439 break;
7440 }
7441
7442 return (result);
7443 }
7444
7445 /* Return 1 if TOKSYM is a token that after being read would allow
7446 a reserved word to be seen, else 0. */
7447 static int
7448 reserved_word_acceptable (toksym)
7449 int toksym;
7450 {
7451 switch (toksym)
7452 {
7453 case '\n':
7454 case ';':
7455 case '(':
7456 case ')':
7457 case '|':
7458 case '&':
7459 case '{':
7460 case '}': /* XXX */
7461 case AND_AND:
7462 case BANG:
7463 case BAR_AND:
7464 case DO:
7465 case DONE:
7466 case ELIF:
7467 case ELSE:
7468 case ESAC:
7469 case FI:
7470 case IF:
7471 case OR_OR:
7472 case SEMI_SEMI:
7473 case SEMI_AND:
7474 case SEMI_SEMI_AND:
7475 case THEN:
7476 case TIME:
7477 case TIMEOPT:
7478 case TIMEIGN:
7479 case COPROC:
7480 case UNTIL:
7481 case WHILE:
7482 case 0:
7483 return 1;
7484 default:
7485 #if defined (COPROCESS_SUPPORT)
7486 if (last_read_token == WORD && token_before_that == COPROC)
7487 return 1;
7488 #endif
7489 if (last_read_token == WORD && token_before_that == FUNCTION)
7490 return 1;
7491 return 0;
7492 }
7493 }
7494
7495 /* Return the index of TOKEN in the alist of reserved words, or -1 if
7496 TOKEN is not a shell reserved word. */
7497 int
7498 find_reserved_word (tokstr)
7499 char *tokstr;
7500 {
7501 int i;
7502 for (i = 0; word_token_alist[i].word; i++)
7503 if (STREQ (tokstr, word_token_alist[i].word))
7504 return i;
7505 return -1;
7506 }
7507
7508 /* An interface to let the rest of the shell (primarily the completion
7509 system) know what the parser is expecting. */
7510 int
7511 parser_in_command_position ()
7512 {
7513 return (command_token_position (last_read_token));
7514 }
7515
7516 #if 0
7517 #if defined (READLINE)
7518 /* Called after each time readline is called. This insures that whatever
7519 the new prompt string is gets propagated to readline's local prompt
7520 variable. */
7521 static void
7522 reset_readline_prompt ()
7523 {
7524 char *temp_prompt;
7525
7526 if (prompt_string_pointer)
7527 {
7528 temp_prompt = (*prompt_string_pointer)
7529 ? decode_prompt_string (*prompt_string_pointer)
7530 : (char *)NULL;
7531
7532 if (temp_prompt == 0)
7533 {
7534 temp_prompt = (char *)xmalloc (1);
7535 temp_prompt[0] = '\0';
7536 }
7537
7538 FREE (current_readline_prompt);
7539 current_readline_prompt = temp_prompt;
7540 }
7541 }
7542 #endif /* READLINE */
7543 #endif /* 0 */
7544
7545 #if defined (HISTORY)
7546 /* A list of tokens which can be followed by newlines, but not by
7547 semi-colons. When concatenating multiple lines of history, the
7548 newline separator for such tokens is replaced with a space. */
7549 static const int no_semi_successors[] = {
7550 '\n', '{', '(', ')', ';', '&', '|',
7551 CASE, DO, ELSE, IF, SEMI_SEMI, SEMI_AND, SEMI_SEMI_AND, THEN, UNTIL,
7552 WHILE, AND_AND, OR_OR, IN,
7553 0
7554 };
7555
7556 /* If we are not within a delimited expression, try to be smart
7557 about which separators can be semi-colons and which must be
7558 newlines. Returns the string that should be added into the
7559 history entry. LINE is the line we're about to add; it helps
7560 make some more intelligent decisions in certain cases. */
7561 char *
7562 history_delimiting_chars (line)
7563 const char *line;
7564 {
7565 static int last_was_heredoc = 0; /* was the last entry the start of a here document? */
7566 register int i;
7567
7568 if ((parser_state & PST_HEREDOC) == 0)
7569 last_was_heredoc = 0;
7570
7571 if (dstack.delimiter_depth != 0)
7572 return ("\n");
7573
7574 /* We look for current_command_line_count == 2 because we are looking to
7575 add the first line of the body of the here document (the second line
7576 of the command). We also keep LAST_WAS_HEREDOC as a private sentinel
7577 variable to note when we think we added the first line of a here doc
7578 (the one with a "<<" somewhere in it) */
7579 if (parser_state & PST_HEREDOC)
7580 {
7581 if (last_was_heredoc)
7582 {
7583 last_was_heredoc = 0;
7584 return "\n";
7585 }
7586 return (here_doc_first_line ? "\n" : "");
7587 }
7588
7589 if (parser_state & PST_COMPASSIGN)
7590 return (" ");
7591
7592 /* First, handle some special cases. */
7593 /*(*/
7594 /* If we just read `()', assume it's a function definition, and don't
7595 add a semicolon. If the token before the `)' was not `(', and we're
7596 not in the midst of parsing a case statement, assume it's a
7597 parenthesized command and add the semicolon. */
7598 /*)(*/
7599 if (token_before_that == ')')
7600 {
7601 if (two_tokens_ago == '(') /*)*/ /* function def */
7602 return " ";
7603 /* This does not work for subshells inside case statement
7604 command lists. It's a suboptimal solution. */
7605 else if (parser_state & PST_CASESTMT) /* case statement pattern */
7606 return " ";
7607 else
7608 return "; "; /* (...) subshell */
7609 }
7610 else if (token_before_that == WORD && two_tokens_ago == FUNCTION)
7611 return " "; /* function def using `function name' without `()' */
7612
7613 /* If we're not in a here document, but we think we're about to parse one,
7614 and we would otherwise return a `;', return a newline to delimit the
7615 line with the here-doc delimiter */
7616 else if ((parser_state & PST_HEREDOC) == 0 && current_command_line_count > 1 && last_read_token == '\n' && strstr (line, "<<"))
7617 {
7618 last_was_heredoc = 1;
7619 return "\n";
7620 }
7621 else if ((parser_state & PST_HEREDOC) == 0 && current_command_line_count > 1 && need_here_doc > 0)
7622 return "\n";
7623 else if (token_before_that == WORD && two_tokens_ago == FOR)
7624 {
7625 /* Tricky. `for i\nin ...' should not have a semicolon, but
7626 `for i\ndo ...' should. We do what we can. */
7627 for (i = shell_input_line_index; whitespace (shell_input_line[i]); i++)
7628 ;
7629 if (shell_input_line[i] && shell_input_line[i] == 'i' && shell_input_line[i+1] == 'n')
7630 return " ";
7631 return ";";
7632 }
7633 else if (two_tokens_ago == CASE && token_before_that == WORD && (parser_state & PST_CASESTMT))
7634 return " ";
7635
7636 for (i = 0; no_semi_successors[i]; i++)
7637 {
7638 if (token_before_that == no_semi_successors[i])
7639 return (" ");
7640 }
7641
7642 return ("; ");
7643 }
7644 #endif /* HISTORY */
7645
7646 /* Issue a prompt, or prepare to issue a prompt when the next character
7647 is read. */
7648 static void
7649 prompt_again ()
7650 {
7651 char *temp_prompt;
7652
7653 if (interactive == 0 || expanding_alias ()) /* XXX */
7654 return;
7655
7656 ps1_prompt = get_string_value ("PS1");
7657 ps2_prompt = get_string_value ("PS2");
7658
7659 ps0_prompt = get_string_value ("PS0");
7660
7661 if (!prompt_string_pointer)
7662 prompt_string_pointer = &ps1_prompt;
7663
7664 temp_prompt = *prompt_string_pointer
7665 ? decode_prompt_string (*prompt_string_pointer)
7666 : (char *)NULL;
7667
7668 if (temp_prompt == 0)
7669 {
7670 temp_prompt = (char *)xmalloc (1);
7671 temp_prompt[0] = '\0';
7672 }
7673
7674 current_prompt_string = *prompt_string_pointer;
7675 prompt_string_pointer = &ps2_prompt;
7676
7677 #if defined (READLINE)
7678 if (!no_line_editing)
7679 {
7680 FREE (current_readline_prompt);
7681 current_readline_prompt = temp_prompt;
7682 }
7683 else
7684 #endif /* READLINE */
7685 {
7686 FREE (current_decoded_prompt);
7687 current_decoded_prompt = temp_prompt;
7688 }
7689 }
7690
7691 int
7692 get_current_prompt_level ()
7693 {
7694 return ((current_prompt_string && current_prompt_string == ps2_prompt) ? 2 : 1);
7695 }
7696
7697 void
7698 set_current_prompt_level (x)
7699 int x;
7700 {
7701 prompt_string_pointer = (x == 2) ? &ps2_prompt : &ps1_prompt;
7702 current_prompt_string = *prompt_string_pointer;
7703 }
7704
7705 static void
7706 print_prompt ()
7707 {
7708 fprintf (stderr, "%s", current_decoded_prompt);
7709 fflush (stderr);
7710 }
7711
7712 /* Return a string which will be printed as a prompt. The string
7713 may contain special characters which are decoded as follows:
7714
7715 \a bell (ascii 07)
7716 \d the date in Day Mon Date format
7717 \e escape (ascii 033)
7718 \h the hostname up to the first `.'
7719 \H the hostname
7720 \j the number of active jobs
7721 \l the basename of the shell's tty device name
7722 \n CRLF
7723 \r CR
7724 \s the name of the shell
7725 \t the time in 24-hour hh:mm:ss format
7726 \T the time in 12-hour hh:mm:ss format
7727 \@ the time in 12-hour hh:mm am/pm format
7728 \A the time in 24-hour hh:mm format
7729 \D{fmt} the result of passing FMT to strftime(3)
7730 \u your username
7731 \v the version of bash (e.g., 2.00)
7732 \V the release of bash, version + patchlevel (e.g., 2.00.0)
7733 \w the current working directory
7734 \W the last element of $PWD
7735 \! the history number of this command
7736 \# the command number of this command
7737 \$ a $ or a # if you are root
7738 \nnn character code nnn in octal
7739 \\ a backslash
7740 \[ begin a sequence of non-printing chars
7741 \] end a sequence of non-printing chars
7742 */
7743 #define PROMPT_GROWTH 48
7744 char *
7745 decode_prompt_string (string)
7746 char *string;
7747 {
7748 WORD_LIST *list;
7749 char *result, *t;
7750 struct dstack save_dstack;
7751 int last_exit_value, last_comsub_pid;
7752 #if defined (PROMPT_STRING_DECODE)
7753 size_t result_size;
7754 int result_index;
7755 int c, n, i;
7756 char *temp, *t_host, octal_string[4];
7757 struct tm *tm;
7758 time_t the_time;
7759 char timebuf[128];
7760 char *timefmt;
7761
7762 result = (char *)xmalloc (result_size = PROMPT_GROWTH);
7763 result[result_index = 0] = 0;
7764 temp = (char *)NULL;
7765
7766 while (c = *string++)
7767 {
7768 if (posixly_correct && c == '!')
7769 {
7770 if (*string == '!')
7771 {
7772 temp = savestring ("!");
7773 goto add_string;
7774 }
7775 else
7776 {
7777 #if !defined (HISTORY)
7778 temp = savestring ("1");
7779 #else /* HISTORY */
7780 temp = itos (history_number ());
7781 #endif /* HISTORY */
7782 string--; /* add_string increments string again. */
7783 goto add_string;
7784 }
7785 }
7786 if (c == '\\')
7787 {
7788 c = *string;
7789
7790 switch (c)
7791 {
7792 case '0':
7793 case '1':
7794 case '2':
7795 case '3':
7796 case '4':
7797 case '5':
7798 case '6':
7799 case '7':
7800 strncpy (octal_string, string, 3);
7801 octal_string[3] = '\0';
7802
7803 n = read_octal (octal_string);
7804 temp = (char *)xmalloc (3);
7805
7806 if (n == CTLESC || n == CTLNUL)
7807 {
7808 temp[0] = CTLESC;
7809 temp[1] = n;
7810 temp[2] = '\0';
7811 }
7812 else if (n == -1)
7813 {
7814 temp[0] = '\\';
7815 temp[1] = '\0';
7816 }
7817 else
7818 {
7819 temp[0] = n;
7820 temp[1] = '\0';
7821 }
7822
7823 for (c = 0; n != -1 && c < 3 && ISOCTAL (*string); c++)
7824 string++;
7825
7826 c = 0; /* tested at add_string: */
7827 goto add_string;
7828
7829 case 'd':
7830 case 't':
7831 case 'T':
7832 case '@':
7833 case 'A':
7834 /* Make the current time/date into a string. */
7835 (void) time (&the_time);
7836 #if defined (HAVE_TZSET)
7837 sv_tz ("TZ"); /* XXX -- just make sure */
7838 #endif
7839 tm = localtime (&the_time);
7840
7841 if (c == 'd')
7842 n = strftime (timebuf, sizeof (timebuf), "%a %b %d", tm);
7843 else if (c == 't')
7844 n = strftime (timebuf, sizeof (timebuf), "%H:%M:%S", tm);
7845 else if (c == 'T')
7846 n = strftime (timebuf, sizeof (timebuf), "%I:%M:%S", tm);
7847 else if (c == '@')
7848 n = strftime (timebuf, sizeof (timebuf), "%I:%M %p", tm);
7849 else if (c == 'A')
7850 n = strftime (timebuf, sizeof (timebuf), "%H:%M", tm);
7851
7852 if (n == 0)
7853 timebuf[0] = '\0';
7854 else
7855 timebuf[sizeof(timebuf) - 1] = '\0';
7856
7857 temp = savestring (timebuf);
7858 goto add_string;
7859
7860 case 'D': /* strftime format */
7861 if (string[1] != '{') /* } */
7862 goto not_escape;
7863
7864 (void) time (&the_time);
7865 tm = localtime (&the_time);
7866 string += 2; /* skip { */
7867 timefmt = xmalloc (strlen (string) + 3);
7868 for (t = timefmt; *string && *string != '}'; )
7869 *t++ = *string++;
7870 *t = '\0';
7871 c = *string; /* tested at add_string */
7872 if (timefmt[0] == '\0')
7873 {
7874 timefmt[0] = '%';
7875 timefmt[1] = 'X'; /* locale-specific current time */
7876 timefmt[2] = '\0';
7877 }
7878 n = strftime (timebuf, sizeof (timebuf), timefmt, tm);
7879 free (timefmt);
7880
7881 if (n == 0)
7882 timebuf[0] = '\0';
7883 else
7884 timebuf[sizeof(timebuf) - 1] = '\0';
7885
7886 if (promptvars || posixly_correct)
7887 /* Make sure that expand_prompt_string is called with a
7888 second argument of Q_DOUBLE_QUOTES if we use this
7889 function here. */
7890 temp = sh_backslash_quote_for_double_quotes (timebuf);
7891 else
7892 temp = savestring (timebuf);
7893 goto add_string;
7894
7895 case 'n':
7896 temp = (char *)xmalloc (3);
7897 temp[0] = no_line_editing ? '\n' : '\r';
7898 temp[1] = no_line_editing ? '\0' : '\n';
7899 temp[2] = '\0';
7900 goto add_string;
7901
7902 case 's':
7903 temp = base_pathname (shell_name);
7904 /* Try to quote anything the user can set in the file system */
7905 if (promptvars || posixly_correct)
7906 temp = sh_backslash_quote_for_double_quotes (temp);
7907 else
7908 temp = savestring (temp);
7909 goto add_string;
7910
7911 case 'v':
7912 case 'V':
7913 temp = (char *)xmalloc (16);
7914 if (c == 'v')
7915 strcpy (temp, dist_version);
7916 else
7917 sprintf (temp, "%s.%d", dist_version, patch_level);
7918 goto add_string;
7919
7920 case 'w':
7921 case 'W':
7922 {
7923 /* Use the value of PWD because it is much more efficient. */
7924 char t_string[PATH_MAX];
7925 int tlen;
7926
7927 temp = get_string_value ("PWD");
7928
7929 if (temp == 0)
7930 {
7931 if (getcwd (t_string, sizeof(t_string)) == 0)
7932 {
7933 t_string[0] = '.';
7934 tlen = 1;
7935 }
7936 else
7937 tlen = strlen (t_string);
7938 }
7939 else
7940 {
7941 tlen = sizeof (t_string) - 1;
7942 strncpy (t_string, temp, tlen);
7943 }
7944 t_string[tlen] = '\0';
7945
7946 #if defined (MACOSX)
7947 /* Convert from "fs" format to "input" format */
7948 temp = fnx_fromfs (t_string, strlen (t_string));
7949 if (temp != t_string)
7950 strcpy (t_string, temp);
7951 #endif
7952
7953 #define ROOT_PATH(x) ((x)[0] == '/' && (x)[1] == 0)
7954 #define DOUBLE_SLASH_ROOT(x) ((x)[0] == '/' && (x)[1] == '/' && (x)[2] == 0)
7955 /* Abbreviate \W as ~ if $PWD == $HOME */
7956 if (c == 'W' && (((t = get_string_value ("HOME")) == 0) || STREQ (t, t_string) == 0))
7957 {
7958 if (ROOT_PATH (t_string) == 0 && DOUBLE_SLASH_ROOT (t_string) == 0)
7959 {
7960 t = strrchr (t_string, '/');
7961 if (t)
7962 memmove (t_string, t + 1, strlen (t)); /* strlen(t) to copy NULL */
7963 }
7964 }
7965 #undef ROOT_PATH
7966 #undef DOUBLE_SLASH_ROOT
7967 else
7968 {
7969 /* polite_directory_format is guaranteed to return a string
7970 no longer than PATH_MAX - 1 characters. */
7971 temp = polite_directory_format (t_string);
7972 if (temp != t_string)
7973 strcpy (t_string, temp);
7974 }
7975
7976 temp = trim_pathname (t_string, PATH_MAX - 1);
7977 /* If we're going to be expanding the prompt string later,
7978 quote the directory name. */
7979 if (promptvars || posixly_correct)
7980 /* Make sure that expand_prompt_string is called with a
7981 second argument of Q_DOUBLE_QUOTES if we use this
7982 function here. */
7983 temp = sh_backslash_quote_for_double_quotes (t_string);
7984 else
7985 temp = savestring (t_string);
7986
7987 goto add_string;
7988 }
7989
7990 case 'u':
7991 if (current_user.user_name == 0)
7992 get_current_user_info ();
7993 temp = savestring (current_user.user_name);
7994 goto add_string;
7995
7996 case 'h':
7997 case 'H':
7998 t_host = savestring (current_host_name);
7999 if (c == 'h' && (t = (char *)strchr (t_host, '.')))
8000 *t = '\0';
8001 if (promptvars || posixly_correct)
8002 /* Make sure that expand_prompt_string is called with a
8003 second argument of Q_DOUBLE_QUOTES if we use this
8004 function here. */
8005 temp = sh_backslash_quote_for_double_quotes (t_host);
8006 else
8007 temp = savestring (t_host);
8008 free (t_host);
8009 goto add_string;
8010
8011 case '#':
8012 temp = itos (current_command_number);
8013 goto add_string;
8014
8015 case '!':
8016 #if !defined (HISTORY)
8017 temp = savestring ("1");
8018 #else /* HISTORY */
8019 temp = itos (history_number ());
8020 #endif /* HISTORY */
8021 goto add_string;
8022
8023 case '$':
8024 t = temp = (char *)xmalloc (3);
8025 if ((promptvars || posixly_correct) && (current_user.euid != 0))
8026 *t++ = '\\';
8027 *t++ = current_user.euid == 0 ? '#' : '$';
8028 *t = '\0';
8029 goto add_string;
8030
8031 case 'j':
8032 temp = itos (count_all_jobs ());
8033 goto add_string;
8034
8035 case 'l':
8036 #if defined (HAVE_TTYNAME)
8037 temp = (char *)ttyname (fileno (stdin));
8038 t = temp ? base_pathname (temp) : "tty";
8039 temp = savestring (t);
8040 #else
8041 temp = savestring ("tty");
8042 #endif /* !HAVE_TTYNAME */
8043 goto add_string;
8044
8045 #if defined (READLINE)
8046 case '[':
8047 case ']':
8048 if (no_line_editing)
8049 {
8050 string++;
8051 break;
8052 }
8053 temp = (char *)xmalloc (3);
8054 n = (c == '[') ? RL_PROMPT_START_IGNORE : RL_PROMPT_END_IGNORE;
8055 i = 0;
8056 if (n == CTLESC || n == CTLNUL)
8057 temp[i++] = CTLESC;
8058 temp[i++] = n;
8059 temp[i] = '\0';
8060 goto add_string;
8061 #endif /* READLINE */
8062
8063 case '\\':
8064 case 'a':
8065 case 'e':
8066 case 'r':
8067 temp = (char *)xmalloc (2);
8068 if (c == 'a')
8069 temp[0] = '\07';
8070 else if (c == 'e')
8071 temp[0] = '\033';
8072 else if (c == 'r')
8073 temp[0] = '\r';
8074 else /* (c == '\\') */
8075 temp[0] = c;
8076 temp[1] = '\0';
8077 goto add_string;
8078
8079 default:
8080 not_escape:
8081 temp = (char *)xmalloc (3);
8082 temp[0] = '\\';
8083 temp[1] = c;
8084 temp[2] = '\0';
8085
8086 add_string:
8087 if (c)
8088 string++;
8089 result =
8090 sub_append_string (temp, result, &result_index, &result_size);
8091 temp = (char *)NULL; /* Freed in sub_append_string (). */
8092 result[result_index] = '\0';
8093 break;
8094 }
8095 }
8096 else
8097 {
8098 RESIZE_MALLOCED_BUFFER (result, result_index, 3, result_size, PROMPT_GROWTH);
8099 /* dequote_string should take care of removing this if we are not
8100 performing the rest of the word expansions. */
8101 if (c == CTLESC || c == CTLNUL)
8102 result[result_index++] = CTLESC;
8103 result[result_index++] = c;
8104 result[result_index] = '\0';
8105 }
8106 }
8107 #else /* !PROMPT_STRING_DECODE */
8108 result = savestring (string);
8109 #endif /* !PROMPT_STRING_DECODE */
8110
8111 /* Save the delimiter stack and point `dstack' to temp space so any
8112 command substitutions in the prompt string won't result in screwing
8113 up the parser's quoting state. */
8114 save_dstack = dstack;
8115 dstack = temp_dstack;
8116 dstack.delimiter_depth = 0;
8117
8118 /* Perform variable and parameter expansion and command substitution on
8119 the prompt string. */
8120 if (promptvars || posixly_correct)
8121 {
8122 last_exit_value = last_command_exit_value;
8123 last_comsub_pid = last_command_subst_pid;
8124 list = expand_prompt_string (result, Q_DOUBLE_QUOTES, 0);
8125 free (result);
8126 result = string_list (list);
8127 dispose_words (list);
8128 last_command_exit_value = last_exit_value;
8129 last_command_subst_pid = last_comsub_pid;
8130 }
8131 else
8132 {
8133 t = dequote_string (result);
8134 free (result);
8135 result = t;
8136 }
8137
8138 dstack = save_dstack;
8139
8140 return (result);
8141 }
8142
8143 /************************************************
8144 * *
8145 * ERROR HANDLING *
8146 * *
8147 ************************************************/
8148
8149 /* Report a syntax error, and restart the parser. Call here for fatal
8150 errors. */
8151 int
8152 yyerror (msg)
8153 const char *msg;
8154 {
8155 report_syntax_error ((char *)NULL);
8156 reset_parser ();
8157 return (0);
8158 }
8159
8160 static char *
8161 error_token_from_token (tok)
8162 int tok;
8163 {
8164 char *t;
8165
8166 if (t = find_token_in_alist (tok, word_token_alist, 0))
8167 return t;
8168
8169 if (t = find_token_in_alist (tok, other_token_alist, 0))
8170 return t;
8171
8172 t = (char *)NULL;
8173 /* This stuff is dicy and needs closer inspection */
8174 switch (current_token)
8175 {
8176 case WORD:
8177 case ASSIGNMENT_WORD:
8178 if (yylval.word)
8179 t = savestring (yylval.word->word);
8180 break;
8181 case NUMBER:
8182 t = itos (yylval.number);
8183 break;
8184 case ARITH_CMD:
8185 if (yylval.word_list)
8186 t = string_list (yylval.word_list);
8187 break;
8188 case ARITH_FOR_EXPRS:
8189 if (yylval.word_list)
8190 t = string_list_internal (yylval.word_list, " ; ");
8191 break;
8192 case COND_CMD:
8193 t = (char *)NULL; /* punt */
8194 break;
8195 }
8196
8197 return t;
8198 }
8199
8200 static char *
8201 error_token_from_text ()
8202 {
8203 char *msg, *t;
8204 int token_end, i;
8205
8206 t = shell_input_line;
8207 i = shell_input_line_index;
8208 token_end = 0;
8209 msg = (char *)NULL;
8210
8211 if (i && t[i] == '\0')
8212 i--;
8213
8214 while (i && (whitespace (t[i]) || t[i] == '\n'))
8215 i--;
8216
8217 if (i)
8218 token_end = i + 1;
8219
8220 while (i && (member (t[i], " \n\t;|&") == 0))
8221 i--;
8222
8223 while (i != token_end && (whitespace (t[i]) || t[i] == '\n'))
8224 i++;
8225
8226 /* Return our idea of the offending token. */
8227 if (token_end || (i == 0 && token_end == 0))
8228 {
8229 if (token_end)
8230 msg = substring (t, i, token_end);
8231 else /* one-character token */
8232 {
8233 msg = (char *)xmalloc (2);
8234 msg[0] = t[i];
8235 msg[1] = '\0';
8236 }
8237 }
8238
8239 return (msg);
8240 }
8241
8242 static void
8243 print_offending_line ()
8244 {
8245 char *msg;
8246 int token_end;
8247
8248 msg = savestring (shell_input_line);
8249 token_end = strlen (msg);
8250 while (token_end && msg[token_end - 1] == '\n')
8251 msg[--token_end] = '\0';
8252
8253 parser_error (line_number, "`%s'", msg);
8254 free (msg);
8255 }
8256
8257 /* Report a syntax error with line numbers, etc.
8258 Call here for recoverable errors. If you have a message to print,
8259 then place it in MESSAGE, otherwise pass NULL and this will figure
8260 out an appropriate message for you. */
8261 static void
8262 report_syntax_error (message)
8263 char *message;
8264 {
8265 char *msg, *p;
8266
8267 if (message)
8268 {
8269 parser_error (line_number, "%s", message);
8270 if (interactive && EOF_Reached)
8271 EOF_Reached = 0;
8272 last_command_exit_value = parse_and_execute_level ? EX_BADSYNTAX : EX_BADUSAGE;
8273 return;
8274 }
8275
8276 /* If the line of input we're reading is not null, try to find the
8277 objectionable token. First, try to figure out what token the
8278 parser's complaining about by looking at current_token. */
8279 if (current_token != 0 && EOF_Reached == 0 && (msg = error_token_from_token (current_token)))
8280 {
8281 if (ansic_shouldquote (msg))
8282 {
8283 p = ansic_quote (msg, 0, NULL);
8284 free (msg);
8285 msg = p;
8286 }
8287 parser_error (line_number, _("syntax error near unexpected token `%s'"), msg);
8288 free (msg);
8289
8290 if (interactive == 0)
8291 print_offending_line ();
8292
8293 last_command_exit_value = parse_and_execute_level ? EX_BADSYNTAX : EX_BADUSAGE;
8294 return;
8295 }
8296
8297 /* If looking at the current token doesn't prove fruitful, try to find the
8298 offending token by analyzing the text of the input line near the current
8299 input line index and report what we find. */
8300 if (shell_input_line && *shell_input_line)
8301 {
8302 msg = error_token_from_text ();
8303 if (msg)
8304 {
8305 parser_error (line_number, _("syntax error near `%s'"), msg);
8306 free (msg);
8307 }
8308
8309 /* If not interactive, print the line containing the error. */
8310 if (interactive == 0)
8311 print_offending_line ();
8312 }
8313 else
8314 {
8315 msg = EOF_Reached ? _("syntax error: unexpected end of file") : _("syntax error");
8316 parser_error (line_number, "%s", msg);
8317 /* When the shell is interactive, this file uses EOF_Reached
8318 only for error reporting. Other mechanisms are used to
8319 decide whether or not to exit. */
8320 if (interactive && EOF_Reached)
8321 EOF_Reached = 0;
8322 }
8323
8324 last_command_exit_value = parse_and_execute_level ? EX_BADSYNTAX : EX_BADUSAGE;
8325 }
8326
8327 /* ??? Needed function. ??? We have to be able to discard the constructs
8328 created during parsing. In the case of error, we want to return
8329 allocated objects to the memory pool. In the case of no error, we want
8330 to throw away the information about where the allocated objects live.
8331 (dispose_command () will actually free the command.) */
8332 static void
8333 discard_parser_constructs (error_p)
8334 int error_p;
8335 {
8336 }
8337
8338 /************************************************
8339 * *
8340 * EOF HANDLING *
8341 * *
8342 ************************************************/
8343
8344 /* Do that silly `type "bye" to exit' stuff. You know, "ignoreeof". */
8345
8346 /* A flag denoting whether or not ignoreeof is set. */
8347 int ignoreeof = 0;
8348
8349 /* The number of times that we have encountered an EOF character without
8350 another character intervening. When this gets above the limit, the
8351 shell terminates. */
8352 int eof_encountered = 0;
8353
8354 /* The limit for eof_encountered. */
8355 int eof_encountered_limit = 10;
8356
8357 /* If we have EOF as the only input unit, this user wants to leave
8358 the shell. If the shell is not interactive, then just leave.
8359 Otherwise, if ignoreeof is set, and we haven't done this the
8360 required number of times in a row, print a message. */
8361 static void
8362 handle_eof_input_unit ()
8363 {
8364 if (interactive)
8365 {
8366 /* shell.c may use this to decide whether or not to write out the
8367 history, among other things. We use it only for error reporting
8368 in this file. */
8369 if (EOF_Reached)
8370 EOF_Reached = 0;
8371
8372 /* If the user wants to "ignore" eof, then let her do so, kind of. */
8373 if (ignoreeof)
8374 {
8375 if (eof_encountered < eof_encountered_limit)
8376 {
8377 fprintf (stderr, _("Use \"%s\" to leave the shell.\n"),
8378 login_shell ? "logout" : "exit");
8379 eof_encountered++;
8380 /* Reset the parsing state. */
8381 last_read_token = current_token = '\n';
8382 /* Reset the prompt string to be $PS1. */
8383 prompt_string_pointer = (char **)NULL;
8384 prompt_again ();
8385 return;
8386 }
8387 }
8388
8389 /* In this case EOF should exit the shell. Do it now. */
8390 reset_parser ();
8391 exit_builtin ((WORD_LIST *)NULL);
8392 }
8393 else
8394 {
8395 /* We don't write history files, etc., for non-interactive shells. */
8396 EOF_Reached = 1;
8397 }
8398 }
8399
8400 /************************************************
8401 * *
8402 * STRING PARSING FUNCTIONS *
8403 * *
8404 ************************************************/
8405
8406 /* It's very important that these two functions treat the characters
8407 between ( and ) identically. */
8408
8409 static WORD_LIST parse_string_error;
8410
8411 /* Take a string and run it through the shell parser, returning the
8412 resultant word list. Used by compound array assignment. */
8413 WORD_LIST *
8414 parse_string_to_word_list (s, flags, whom)
8415 char *s;
8416 int flags;
8417 const char *whom;
8418 {
8419 WORD_LIST *wl;
8420 int tok, orig_current_token, orig_line_number, orig_input_terminator;
8421 int orig_line_count;
8422 int old_echo_input, old_expand_aliases;
8423 #if defined (HISTORY)
8424 int old_remember_on_history, old_history_expansion_inhibited;
8425 #endif
8426
8427 #if defined (HISTORY)
8428 old_remember_on_history = remember_on_history;
8429 # if defined (BANG_HISTORY)
8430 old_history_expansion_inhibited = history_expansion_inhibited;
8431 # endif
8432 bash_history_disable ();
8433 #endif
8434
8435 orig_line_number = line_number;
8436 orig_line_count = current_command_line_count;
8437 orig_input_terminator = shell_input_line_terminator;
8438 old_echo_input = echo_input_at_read;
8439 old_expand_aliases = expand_aliases;
8440
8441 push_stream (1);
8442 last_read_token = WORD; /* WORD to allow reserved words here */
8443 current_command_line_count = 0;
8444 echo_input_at_read = expand_aliases = 0;
8445
8446 with_input_from_string (s, whom);
8447 wl = (WORD_LIST *)NULL;
8448
8449 if (flags & 1)
8450 parser_state |= PST_COMPASSIGN|PST_REPARSE;
8451
8452 while ((tok = read_token (READ)) != yacc_EOF)
8453 {
8454 if (tok == '\n' && *bash_input.location.string == '\0')
8455 break;
8456 if (tok == '\n') /* Allow newlines in compound assignments */
8457 continue;
8458 if (tok != WORD && tok != ASSIGNMENT_WORD)
8459 {
8460 line_number = orig_line_number + line_number - 1;
8461 orig_current_token = current_token;
8462 current_token = tok;
8463 yyerror (NULL); /* does the right thing */
8464 current_token = orig_current_token;
8465 if (wl)
8466 dispose_words (wl);
8467 wl = &parse_string_error;
8468 break;
8469 }
8470 wl = make_word_list (yylval.word, wl);
8471 }
8472
8473 last_read_token = '\n';
8474 pop_stream ();
8475
8476 #if defined (HISTORY)
8477 remember_on_history = old_remember_on_history;
8478 # if defined (BANG_HISTORY)
8479 history_expansion_inhibited = old_history_expansion_inhibited;
8480 # endif /* BANG_HISTORY */
8481 #endif /* HISTORY */
8482
8483 echo_input_at_read = old_echo_input;
8484 expand_aliases = old_expand_aliases;
8485
8486 current_command_line_count = orig_line_count;
8487 shell_input_line_terminator = orig_input_terminator;
8488
8489 if (flags & 1)
8490 parser_state &= ~(PST_COMPASSIGN|PST_REPARSE);
8491
8492 if (wl == &parse_string_error)
8493 {
8494 last_command_exit_value = EXECUTION_FAILURE;
8495 if (interactive_shell == 0 && posixly_correct)
8496 jump_to_top_level (FORCE_EOF);
8497 else
8498 jump_to_top_level (DISCARD);
8499 }
8500
8501 return (REVERSE_LIST (wl, WORD_LIST *));
8502 }
8503
8504 static char *
8505 parse_compound_assignment (retlenp)
8506 int *retlenp;
8507 {
8508 WORD_LIST *wl, *rl;
8509 int tok, orig_line_number, orig_token_size, orig_last_token, assignok;
8510 char *saved_token, *ret;
8511
8512 saved_token = token;
8513 orig_token_size = token_buffer_size;
8514 orig_line_number = line_number;
8515 orig_last_token = last_read_token;
8516
8517 last_read_token = WORD; /* WORD to allow reserved words here */
8518
8519 token = (char *)NULL;
8520 token_buffer_size = 0;
8521
8522 assignok = parser_state&PST_ASSIGNOK; /* XXX */
8523
8524 wl = (WORD_LIST *)NULL; /* ( */
8525 parser_state |= PST_COMPASSIGN;
8526
8527 while ((tok = read_token (READ)) != ')')
8528 {
8529 if (tok == '\n') /* Allow newlines in compound assignments */
8530 {
8531 if (SHOULD_PROMPT ())
8532 prompt_again ();
8533 continue;
8534 }
8535 if (tok != WORD && tok != ASSIGNMENT_WORD)
8536 {
8537 current_token = tok; /* for error reporting */
8538 if (tok == yacc_EOF) /* ( */
8539 parser_error (orig_line_number, _("unexpected EOF while looking for matching `)'"));
8540 else
8541 yyerror(NULL); /* does the right thing */
8542 if (wl)
8543 dispose_words (wl);
8544 wl = &parse_string_error;
8545 break;
8546 }
8547 wl = make_word_list (yylval.word, wl);
8548 }
8549
8550 FREE (token);
8551 token = saved_token;
8552 token_buffer_size = orig_token_size;
8553
8554 parser_state &= ~PST_COMPASSIGN;
8555
8556 if (wl == &parse_string_error)
8557 {
8558 last_command_exit_value = EXECUTION_FAILURE;
8559 last_read_token = '\n'; /* XXX */
8560 if (interactive_shell == 0 && posixly_correct)
8561 jump_to_top_level (FORCE_EOF);
8562 else
8563 jump_to_top_level (DISCARD);
8564 }
8565
8566 last_read_token = orig_last_token; /* XXX - was WORD? */
8567
8568 if (wl)
8569 {
8570 rl = REVERSE_LIST (wl, WORD_LIST *);
8571 ret = string_list (rl);
8572 dispose_words (rl);
8573 }
8574 else
8575 ret = (char *)NULL;
8576
8577 if (retlenp)
8578 *retlenp = (ret && *ret) ? strlen (ret) : 0;
8579
8580 if (assignok)
8581 parser_state |= PST_ASSIGNOK;
8582
8583 return ret;
8584 }
8585
8586 /************************************************
8587 * *
8588 * SAVING AND RESTORING PARTIAL PARSE STATE *
8589 * *
8590 ************************************************/
8591
8592 sh_parser_state_t *
8593 save_parser_state (ps)
8594 sh_parser_state_t *ps;
8595 {
8596 int i;
8597
8598 if (ps == 0)
8599 ps = (sh_parser_state_t *)xmalloc (sizeof (sh_parser_state_t));
8600 if (ps == 0)
8601 return ((sh_parser_state_t *)NULL);
8602
8603 ps->parser_state = parser_state;
8604 ps->token_state = save_token_state ();
8605
8606 ps->input_line_terminator = shell_input_line_terminator;
8607 ps->eof_encountered = eof_encountered;
8608
8609 ps->prompt_string_pointer = prompt_string_pointer;
8610
8611 ps->current_command_line_count = current_command_line_count;
8612
8613 #if defined (HISTORY)
8614 ps->remember_on_history = remember_on_history;
8615 # if defined (BANG_HISTORY)
8616 ps->history_expansion_inhibited = history_expansion_inhibited;
8617 # endif
8618 #endif
8619
8620 ps->last_command_exit_value = last_command_exit_value;
8621 #if defined (ARRAY_VARS)
8622 ps->pipestatus = save_pipestatus_array ();
8623 #endif
8624
8625 ps->last_shell_builtin = last_shell_builtin;
8626 ps->this_shell_builtin = this_shell_builtin;
8627
8628 ps->expand_aliases = expand_aliases;
8629 ps->echo_input_at_read = echo_input_at_read;
8630 ps->need_here_doc = need_here_doc;
8631 ps->here_doc_first_line = here_doc_first_line;
8632
8633 #if 0
8634 for (i = 0; i < HEREDOC_MAX; i++)
8635 ps->redir_stack[i] = redir_stack[i];
8636 #else
8637 if (need_here_doc == 0)
8638 ps->redir_stack[0] = 0;
8639 else
8640 memcpy (ps->redir_stack, redir_stack, sizeof (redir_stack[0]) * HEREDOC_MAX);
8641 #endif
8642
8643 ps->token = token;
8644 ps->token_buffer_size = token_buffer_size;
8645 /* Force reallocation on next call to read_token_word */
8646 token = 0;
8647 token_buffer_size = 0;
8648
8649 return (ps);
8650 }
8651
8652 void
8653 restore_parser_state (ps)
8654 sh_parser_state_t *ps;
8655 {
8656 int i;
8657
8658 if (ps == 0)
8659 return;
8660
8661 parser_state = ps->parser_state;
8662 if (ps->token_state)
8663 {
8664 restore_token_state (ps->token_state);
8665 free (ps->token_state);
8666 }
8667
8668 shell_input_line_terminator = ps->input_line_terminator;
8669 eof_encountered = ps->eof_encountered;
8670
8671 prompt_string_pointer = ps->prompt_string_pointer;
8672
8673 current_command_line_count = ps->current_command_line_count;
8674
8675 #if defined (HISTORY)
8676 remember_on_history = ps->remember_on_history;
8677 # if defined (BANG_HISTORY)
8678 history_expansion_inhibited = ps->history_expansion_inhibited;
8679 # endif
8680 #endif
8681
8682 last_command_exit_value = ps->last_command_exit_value;
8683 #if defined (ARRAY_VARS)
8684 restore_pipestatus_array (ps->pipestatus);
8685 #endif
8686
8687 last_shell_builtin = ps->last_shell_builtin;
8688 this_shell_builtin = ps->this_shell_builtin;
8689
8690 expand_aliases = ps->expand_aliases;
8691 echo_input_at_read = ps->echo_input_at_read;
8692 need_here_doc = ps->need_here_doc;
8693 here_doc_first_line = ps->here_doc_first_line;
8694
8695 #if 0
8696 for (i = 0; i < HEREDOC_MAX; i++)
8697 redir_stack[i] = ps->redir_stack[i];
8698 #else
8699 if (need_here_doc == 0)
8700 redir_stack[0] = 0;
8701 else
8702 memcpy (redir_stack, ps->redir_stack, sizeof (redir_stack[0]) * HEREDOC_MAX);
8703 #endif
8704
8705 FREE (token);
8706 token = ps->token;
8707 token_buffer_size = ps->token_buffer_size;
8708 }
8709
8710 sh_input_line_state_t *
8711 save_input_line_state (ls)
8712 sh_input_line_state_t *ls;
8713 {
8714 if (ls == 0)
8715 ls = (sh_input_line_state_t *)xmalloc (sizeof (sh_input_line_state_t));
8716 if (ls == 0)
8717 return ((sh_input_line_state_t *)NULL);
8718
8719 ls->input_line = shell_input_line;
8720 ls->input_line_size = shell_input_line_size;
8721 ls->input_line_len = shell_input_line_len;
8722 ls->input_line_index = shell_input_line_index;
8723
8724 /* force reallocation */
8725 shell_input_line = 0;
8726 shell_input_line_size = shell_input_line_len = shell_input_line_index = 0;
8727
8728 return ls;
8729 }
8730
8731 void
8732 restore_input_line_state (ls)
8733 sh_input_line_state_t *ls;
8734 {
8735 FREE (shell_input_line);
8736 shell_input_line = ls->input_line;
8737 shell_input_line_size = ls->input_line_size;
8738 shell_input_line_len = ls->input_line_len;
8739 shell_input_line_index = ls->input_line_index;
8740
8741 set_line_mbstate ();
8742 }
8743
8744 /************************************************
8745 * *
8746 * MULTIBYTE CHARACTER HANDLING *
8747 * *
8748 ************************************************/
8749
8750 #if defined (HANDLE_MULTIBYTE)
8751 static void
8752 set_line_mbstate ()
8753 {
8754 int c;
8755 size_t i, previ, len;
8756 mbstate_t mbs, prevs;
8757 size_t mbclen;
8758
8759 if (shell_input_line == NULL)
8760 return;
8761 len = strlen (shell_input_line); /* XXX - shell_input_line_len ? */
8762 shell_input_line_property = (char *)xrealloc (shell_input_line_property, len + 1);
8763
8764 memset (&prevs, '\0', sizeof (mbstate_t));
8765 for (i = previ = 0; i < len; i++)
8766 {
8767 mbs = prevs;
8768
8769 c = shell_input_line[i];
8770 if (c == EOF)
8771 {
8772 size_t j;
8773 for (j = i; j < len; j++)
8774 shell_input_line_property[j] = 1;
8775 break;
8776 }
8777
8778 mbclen = mbrlen (shell_input_line + previ, i - previ + 1, &mbs);
8779 if (mbclen == 1 || mbclen == (size_t)-1)
8780 {
8781 mbclen = 1;
8782 previ = i + 1;
8783 }
8784 else if (mbclen == (size_t)-2)
8785 mbclen = 0;
8786 else if (mbclen > 1)
8787 {
8788 mbclen = 0;
8789 previ = i + 1;
8790 prevs = mbs;
8791 }
8792 else
8793 {
8794 /* XXX - what to do if mbrlen returns 0? (null wide character) */
8795 size_t j;
8796 for (j = i; j < len; j++)
8797 shell_input_line_property[j] = 1;
8798 break;
8799 }
8800
8801 shell_input_line_property[i] = mbclen;
8802 }
8803 }
8804 #endif /* HANDLE_MULTIBYTE */