blob: 83c936771e987a014ec8604e81ff8e5e89bcb8a7 [file] [log] [blame]
Jari Aalto31859422009-01-12 13:36:28 +00001/* A Bison parser, made by GNU Bison 2.3. */
Jari Aaltob80f6442004-07-27 13:29:18 +00002
Jari Aalto31859422009-01-12 13:36:28 +00003/* Skeleton implementation for Bison's Yacc-like parsers in C
Jari Aaltof73dda02001-11-13 17:56:06 +00004
Jari Aalto31859422009-01-12 13:36:28 +00005 Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006
6 Free Software Foundation, Inc.
Jari Aaltof73dda02001-11-13 17:56:06 +00007
Jari Aalto31859422009-01-12 13:36:28 +00008 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
11 any later version.
Jari Aaltof73dda02001-11-13 17:56:06 +000012
Jari Aalto31859422009-01-12 13:36:28 +000013 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 Boston, MA 02110-1301, USA. */
22
23/* As a special exception, you may create a larger work that contains
24 part or all of the Bison parser skeleton and distribute that work
25 under terms of your choice, so long as that work isn't itself a
26 parser generator using the skeleton or a modified version thereof
27 as a parser skeleton. Alternatively, if you modify or redistribute
28 the parser skeleton itself, you may (at your option) remove this
29 special exception, which will cause the skeleton and the resulting
30 Bison output files to be licensed under the GNU General Public
31 License without this special exception.
32
33 This special exception was added by the Free Software Foundation in
34 version 2.2 of Bison. */
35
36/* C LALR(1) parser skeleton written by Richard Stallman, by
37 simplifying the original so-called "semantic" parser. */
38
39/* All symbols defined below should begin with yy or YY, to avoid
40 infringing on user name space. This should be done even for local
41 variables, as they might otherwise be expanded by user macros.
42 There are some unavoidable exceptions within include files to
43 define necessary library symbols; they are noted "INFRINGES ON
44 USER NAME SPACE" below. */
45
46/* Identify Bison output. */
47#define YYBISON 1
48
49/* Bison version. */
50#define YYBISON_VERSION "2.3"
51
52/* Skeleton name. */
53#define YYSKELETON_NAME "yacc.c"
54
55/* Pure parsers. */
56#define YYPURE 0
57
58/* Using locations. */
59#define YYLSP_NEEDED 0
60
61
62
63/* Tokens. */
64#ifndef YYTOKENTYPE
65# define YYTOKENTYPE
66 /* Put the tokens into the symbol table, so that GDB and other debuggers
67 know about them. */
68 enum yytokentype {
69 IF = 258,
70 THEN = 259,
71 ELSE = 260,
72 ELIF = 261,
73 FI = 262,
74 CASE = 263,
75 ESAC = 264,
76 FOR = 265,
77 SELECT = 266,
78 WHILE = 267,
79 UNTIL = 268,
80 DO = 269,
81 DONE = 270,
82 FUNCTION = 271,
83 COPROC = 272,
84 COND_START = 273,
85 COND_END = 274,
86 COND_ERROR = 275,
87 IN = 276,
88 BANG = 277,
89 TIME = 278,
90 TIMEOPT = 279,
Chet Ramey495aee42011-11-22 19:11:26 -050091 TIMEIGN = 280,
92 WORD = 281,
93 ASSIGNMENT_WORD = 282,
94 REDIR_WORD = 283,
95 NUMBER = 284,
96 ARITH_CMD = 285,
97 ARITH_FOR_EXPRS = 286,
98 COND_CMD = 287,
99 AND_AND = 288,
100 OR_OR = 289,
101 GREATER_GREATER = 290,
102 LESS_LESS = 291,
103 LESS_AND = 292,
104 LESS_LESS_LESS = 293,
105 GREATER_AND = 294,
106 SEMI_SEMI = 295,
107 SEMI_AND = 296,
108 SEMI_SEMI_AND = 297,
109 LESS_LESS_MINUS = 298,
110 AND_GREATER = 299,
111 AND_GREATER_GREATER = 300,
112 LESS_GREATER = 301,
113 GREATER_BAR = 302,
114 BAR_AND = 303,
115 yacc_EOF = 304
Jari Aalto31859422009-01-12 13:36:28 +0000116 };
117#endif
118/* Tokens. */
119#define IF 258
120#define THEN 259
121#define ELSE 260
122#define ELIF 261
123#define FI 262
124#define CASE 263
125#define ESAC 264
126#define FOR 265
127#define SELECT 266
128#define WHILE 267
129#define UNTIL 268
130#define DO 269
131#define DONE 270
132#define FUNCTION 271
133#define COPROC 272
134#define COND_START 273
135#define COND_END 274
136#define COND_ERROR 275
137#define IN 276
138#define BANG 277
139#define TIME 278
140#define TIMEOPT 279
Chet Ramey495aee42011-11-22 19:11:26 -0500141#define TIMEIGN 280
142#define WORD 281
143#define ASSIGNMENT_WORD 282
144#define REDIR_WORD 283
145#define NUMBER 284
146#define ARITH_CMD 285
147#define ARITH_FOR_EXPRS 286
148#define COND_CMD 287
149#define AND_AND 288
150#define OR_OR 289
151#define GREATER_GREATER 290
152#define LESS_LESS 291
153#define LESS_AND 292
154#define LESS_LESS_LESS 293
155#define GREATER_AND 294
156#define SEMI_SEMI 295
157#define SEMI_AND 296
158#define SEMI_SEMI_AND 297
159#define LESS_LESS_MINUS 298
160#define AND_GREATER 299
161#define AND_GREATER_GREATER 300
162#define LESS_GREATER 301
163#define GREATER_BAR 302
164#define BAR_AND 303
165#define yacc_EOF 304
Jari Aalto31859422009-01-12 13:36:28 +0000166
167
168
169
170/* Copy the first part of user declarations. */
Chet Ramey80b4d712014-10-05 19:12:20 -0400171#line 21 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Jari Aaltof73dda02001-11-13 17:56:06 +0000172
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000173#include "config.h"
174
Jari Aalto726f6381996-08-26 18:22:31 +0000175#include "bashtypes.h"
Jari Aalto726f6381996-08-26 18:22:31 +0000176#include "bashansi.h"
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000177
Jari Aalto28ef6c32001-04-06 19:14:31 +0000178#include "filecntl.h"
179
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000180#if defined (HAVE_UNISTD_H)
181# include <unistd.h>
182#endif
183
184#if defined (HAVE_LOCALE_H)
185# include <locale.h>
186#endif
187
188#include <stdio.h>
Jari Aaltof73dda02001-11-13 17:56:06 +0000189#include "chartypes.h"
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000190#include <signal.h>
191
192#include "memalloc.h"
193
Jari Aaltob80f6442004-07-27 13:29:18 +0000194#include "bashintl.h"
195
Jari Aalto7117c2d2002-07-17 14:10:11 +0000196#define NEED_STRFTIME_DECL /* used in externs.h */
197
Jari Aalto726f6381996-08-26 18:22:31 +0000198#include "shell.h"
Chet Rameyac50fba2014-02-26 09:36:43 -0500199#include "typemax.h" /* SIZE_MAX if needed */
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000200#include "trap.h"
Jari Aalto726f6381996-08-26 18:22:31 +0000201#include "flags.h"
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000202#include "parser.h"
203#include "mailcheck.h"
Jari Aaltof73dda02001-11-13 17:56:06 +0000204#include "test.h"
Jari Aalto95732b42005-12-07 14:08:12 +0000205#include "builtins.h"
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000206#include "builtins/common.h"
207#include "builtins/builtext.h"
Jari Aalto726f6381996-08-26 18:22:31 +0000208
Jari Aalto7117c2d2002-07-17 14:10:11 +0000209#include "shmbutil.h"
210
Jari Aalto726f6381996-08-26 18:22:31 +0000211#if defined (READLINE)
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000212# include "bashline.h"
Jari Aalto726f6381996-08-26 18:22:31 +0000213# include <readline/readline.h>
214#endif /* READLINE */
215
216#if defined (HISTORY)
217# include "bashhist.h"
218# include <readline/history.h>
219#endif /* HISTORY */
220
221#if defined (JOB_CONTROL)
222# include "jobs.h"
223#endif /* JOB_CONTROL */
224
225#if defined (ALIAS)
226# include "alias.h"
Jari Aaltob80f6442004-07-27 13:29:18 +0000227#else
228typedef void *alias_t;
Jari Aalto726f6381996-08-26 18:22:31 +0000229#endif /* ALIAS */
230
231#if defined (PROMPT_STRING_DECODE)
Jari Aaltocce855b1998-04-17 19:52:44 +0000232# ifndef _MINIX
233# include <sys/param.h>
234# endif
235# include <time.h>
Jari Aalto7117c2d2002-07-17 14:10:11 +0000236# if defined (TM_IN_SYS_TIME)
237# include <sys/types.h>
238# include <sys/time.h>
239# endif /* TM_IN_SYS_TIME */
Jari Aaltocce855b1998-04-17 19:52:44 +0000240# include "maxpath.h"
Jari Aalto726f6381996-08-26 18:22:31 +0000241#endif /* PROMPT_STRING_DECODE */
242
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000243#define RE_READ_TOKEN -99
244#define NO_EXPANSION -100
245
Jari Aalto7117c2d2002-07-17 14:10:11 +0000246#ifdef DEBUG
247# define YYDEBUG 1
248#else
249# define YYDEBUG 0
250#endif
251
252#if defined (HANDLE_MULTIBYTE)
253# define last_shell_getc_is_singlebyte \
254 ((shell_input_line_index > 1) \
255 ? shell_input_line_property[shell_input_line_index - 1] \
256 : 1)
257# define MBTEST(x) ((x) && last_shell_getc_is_singlebyte)
258#else
259# define last_shell_getc_is_singlebyte 1
260# define MBTEST(x) ((x))
261#endif
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000262
Jari Aaltocce855b1998-04-17 19:52:44 +0000263#if defined (EXTENDED_GLOB)
Jari Aaltocce855b1998-04-17 19:52:44 +0000264extern int extended_glob;
265#endif
266
Jari Aalto726f6381996-08-26 18:22:31 +0000267extern int eof_encountered;
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000268extern int no_line_editing, running_under_emacs;
Jari Aalto726f6381996-08-26 18:22:31 +0000269extern int current_command_number;
Jari Aalto31859422009-01-12 13:36:28 +0000270extern int sourcelevel, parse_and_execute_level;
Jari Aalto726f6381996-08-26 18:22:31 +0000271extern int posixly_correct;
272extern int last_command_exit_value;
Chet Ramey00018032011-11-21 20:51:19 -0500273extern pid_t last_command_subst_pid;
Jari Aalto726f6381996-08-26 18:22:31 +0000274extern char *shell_name, *current_host_name;
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000275extern char *dist_version;
276extern int patch_level;
Jari Aaltocce855b1998-04-17 19:52:44 +0000277extern int dump_translatable_strings, dump_po_strings;
Jari Aaltof73dda02001-11-13 17:56:06 +0000278extern sh_builtin_func_t *last_shell_builtin, *this_shell_builtin;
Jari Aalto726f6381996-08-26 18:22:31 +0000279#if defined (BUFFERED_INPUT)
280extern int bash_input_fd_changed;
281#endif
282
Ricardo Cerqueiraa02fbff2013-07-25 22:35:34 +0100283#include <errno.h>
Jari Aalto726f6381996-08-26 18:22:31 +0000284/* **************************************************************** */
285/* */
286/* "Forward" declarations */
287/* */
288/* **************************************************************** */
289
Jari Aaltof73dda02001-11-13 17:56:06 +0000290#ifdef DEBUG
291static void debug_parser __P((int));
Jari Aaltocce855b1998-04-17 19:52:44 +0000292#endif
Jari Aalto726f6381996-08-26 18:22:31 +0000293
Jari Aaltof73dda02001-11-13 17:56:06 +0000294static int yy_getc __P((void));
295static int yy_ungetc __P((int));
296
297#if defined (READLINE)
298static int yy_readline_get __P((void));
299static int yy_readline_unget __P((int));
Jari Aaltod166f041997-06-05 14:59:13 +0000300#endif
Jari Aaltof73dda02001-11-13 17:56:06 +0000301
302static int yy_string_get __P((void));
303static int yy_string_unget __P((int));
Jari Aalto31859422009-01-12 13:36:28 +0000304static void rewind_input_string __P((void));
Jari Aaltof73dda02001-11-13 17:56:06 +0000305static int yy_stream_get __P((void));
306static int yy_stream_unget __P((int));
307
308static int shell_getc __P((int));
309static void shell_ungetc __P((int));
310static void discard_until __P((int));
311
312#if defined (ALIAS) || defined (DPAREN_ARITHMETIC)
313static void push_string __P((char *, int, alias_t *));
314static void pop_string __P((void));
315static void free_string_list __P((void));
316#endif
317
318static char *read_a_line __P((int));
319
Jari Aaltof73dda02001-11-13 17:56:06 +0000320static int reserved_word_acceptable __P((int));
321static int yylex __P((void));
Chet Ramey90a39f32014-10-02 09:07:21 -0400322
323static void push_heredoc __P((REDIRECT *));
324static char *mk_alexpansion __P((char *));
Jari Aaltof73dda02001-11-13 17:56:06 +0000325static int alias_expand_token __P((char *));
326static int time_command_acceptable __P((void));
327static int special_case_tokens __P((char *));
328static int read_token __P((int));
329static char *parse_matched_pair __P((int, int, int, int *, int));
Jari Aalto31859422009-01-12 13:36:28 +0000330static char *parse_comsub __P((int, int, int, int *, int));
Jari Aalto7117c2d2002-07-17 14:10:11 +0000331#if defined (ARRAY_VARS)
332static char *parse_compound_assignment __P((int *));
333#endif
Jari Aaltof73dda02001-11-13 17:56:06 +0000334#if defined (DPAREN_ARITHMETIC) || defined (ARITH_FOR_COMMAND)
Jari Aalto7117c2d2002-07-17 14:10:11 +0000335static int parse_dparen __P((int));
Jari Aaltob80f6442004-07-27 13:29:18 +0000336static int parse_arith_cmd __P((char **, int));
Jari Aaltof73dda02001-11-13 17:56:06 +0000337#endif
338#if defined (COND_COMMAND)
Jari Aalto7117c2d2002-07-17 14:10:11 +0000339static void cond_error __P((void));
Jari Aaltof73dda02001-11-13 17:56:06 +0000340static COND_COM *cond_expr __P((void));
341static COND_COM *cond_or __P((void));
342static COND_COM *cond_and __P((void));
343static COND_COM *cond_term __P((void));
344static int cond_skip_newlines __P((void));
345static COMMAND *parse_cond_command __P((void));
346#endif
Jari Aalto7117c2d2002-07-17 14:10:11 +0000347#if defined (ARRAY_VARS)
348static int token_is_assignment __P((char *, int));
349static int token_is_ident __P((char *, int));
350#endif
Jari Aaltof73dda02001-11-13 17:56:06 +0000351static int read_token_word __P((int));
352static void discard_parser_constructs __P((int));
353
Jari Aalto7117c2d2002-07-17 14:10:11 +0000354static char *error_token_from_token __P((int));
355static char *error_token_from_text __P((void));
356static void print_offending_line __P((void));
Jari Aaltof73dda02001-11-13 17:56:06 +0000357static void report_syntax_error __P((char *));
Jari Aalto7117c2d2002-07-17 14:10:11 +0000358
Jari Aaltof73dda02001-11-13 17:56:06 +0000359static void handle_eof_input_unit __P((void));
360static void prompt_again __P((void));
361#if 0
362static void reset_readline_prompt __P((void));
363#endif
364static void print_prompt __P((void));
Jari Aalto726f6381996-08-26 18:22:31 +0000365
Jari Aalto7117c2d2002-07-17 14:10:11 +0000366#if defined (HANDLE_MULTIBYTE)
367static void set_line_mbstate __P((void));
368static char *shell_input_line_property = NULL;
369#else
370# define set_line_mbstate()
371#endif
372
Jari Aaltof73dda02001-11-13 17:56:06 +0000373extern int yyerror __P((const char *));
Jari Aaltod166f041997-06-05 14:59:13 +0000374
Jari Aalto7117c2d2002-07-17 14:10:11 +0000375#ifdef DEBUG
376extern int yydebug;
377#endif
378
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000379/* Default prompt strings */
380char *primary_prompt = PPROMPT;
381char *secondary_prompt = SPROMPT;
382
Jari Aalto726f6381996-08-26 18:22:31 +0000383/* PROMPT_STRING_POINTER points to one of these, never to an actual string. */
384char *ps1_prompt, *ps2_prompt;
385
386/* Handle on the current prompt string. Indirectly points through
387 ps1_ or ps2_prompt. */
388char **prompt_string_pointer = (char **)NULL;
389char *current_prompt_string;
390
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000391/* Non-zero means we expand aliases in commands. */
392int expand_aliases = 0;
393
394/* If non-zero, the decoded prompt string undergoes parameter and
395 variable substitution, command substitution, arithmetic substitution,
396 string expansion, process substitution, and quote removal in
397 decode_prompt_string. */
398int promptvars = 1;
399
Jari Aaltob80f6442004-07-27 13:29:18 +0000400/* If non-zero, $'...' and $"..." are expanded when they appear within
401 a ${...} expansion, even when the expansion appears within double
402 quotes. */
403int extended_quote = 1;
404
Jari Aalto726f6381996-08-26 18:22:31 +0000405/* The number of lines read from input while creating the current command. */
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000406int current_command_line_count;
Jari Aalto726f6381996-08-26 18:22:31 +0000407
Chet Ramey495aee42011-11-22 19:11:26 -0500408/* The number of lines in a command saved while we run parse_and_execute */
409int saved_command_line_count;
410
Jari Aalto31859422009-01-12 13:36:28 +0000411/* The token that currently denotes the end of parse. */
412int shell_eof_token;
413
414/* The token currently being read. */
415int current_token;
416
Chet Ramey00018032011-11-21 20:51:19 -0500417/* The current parser state. */
418int parser_state;
419
Jari Aalto726f6381996-08-26 18:22:31 +0000420/* Variables to manage the task of reading here documents, because we need to
421 defer the reading until after a complete command has been collected. */
Chet Ramey90a39f32014-10-02 09:07:21 -0400422#define HEREDOC_MAX 16
423
424static REDIRECT *redir_stack[HEREDOC_MAX];
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000425int need_here_doc;
Jari Aalto726f6381996-08-26 18:22:31 +0000426
427/* Where shell input comes from. History expansion is performed on each
428 line when the shell is interactive. */
429static char *shell_input_line = (char *)NULL;
Chet Rameyac50fba2014-02-26 09:36:43 -0500430static size_t shell_input_line_index;
431static size_t shell_input_line_size; /* Amount allocated for shell_input_line. */
432static size_t shell_input_line_len; /* strlen (shell_input_line) */
Jari Aalto726f6381996-08-26 18:22:31 +0000433
434/* Either zero or EOF. */
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000435static int shell_input_line_terminator;
436
437/* The line number in a script on which a function definition starts. */
438static int function_dstart;
439
440/* The line number in a script on which a function body starts. */
441static int function_bstart;
Jari Aalto726f6381996-08-26 18:22:31 +0000442
Jari Aaltobb706242000-03-17 21:46:59 +0000443/* The line number in a script at which an arithmetic for command starts. */
444static int arith_for_lineno;
445
Chet Ramey00018032011-11-21 20:51:19 -0500446/* The decoded prompt string. Used if READLINE is not defined or if
447 editing is turned off. Analogous to current_readline_prompt. */
448static char *current_decoded_prompt;
Jari Aalto31859422009-01-12 13:36:28 +0000449
450/* The last read token, or NULL. read_token () uses this for context
451 checking. */
452static int last_read_token;
453
454/* The token read prior to last_read_token. */
455static int token_before_that;
456
457/* The token read prior to token_before_that. */
458static int two_tokens_ago;
459
Chet Ramey00018032011-11-21 20:51:19 -0500460static int global_extglob;
461
Jari Aaltob80f6442004-07-27 13:29:18 +0000462/* The line number in a script where the word in a `case WORD', `select WORD'
463 or `for WORD' begins. This is a nested command maximum, since the array
464 index is decremented after a case, select, or for command is parsed. */
465#define MAX_CASE_NEST 128
Chet Ramey90a39f32014-10-02 09:07:21 -0400466static int word_lineno[MAX_CASE_NEST+1];
Jari Aaltob80f6442004-07-27 13:29:18 +0000467static int word_top = -1;
468
469/* If non-zero, it is the token that we want read_token to return
470 regardless of what text is (or isn't) present to be read. This
471 is reset by read_token. If token_to_read == WORD or
472 ASSIGNMENT_WORD, yylval.word should be set to word_desc_to_read. */
473static int token_to_read;
474static WORD_DESC *word_desc_to_read;
475
Chet Ramey00018032011-11-21 20:51:19 -0500476static REDIRECTEE source;
Jari Aalto726f6381996-08-26 18:22:31 +0000477static REDIRECTEE redir;
Jari Aaltof73dda02001-11-13 17:56:06 +0000478
Jari Aalto31859422009-01-12 13:36:28 +0000479
480/* Enabling traces. */
481#ifndef YYDEBUG
482# define YYDEBUG 0
483#endif
484
485/* Enabling verbose error messages. */
486#ifdef YYERROR_VERBOSE
487# undef YYERROR_VERBOSE
488# define YYERROR_VERBOSE 1
489#else
490# define YYERROR_VERBOSE 0
491#endif
492
493/* Enabling the token table. */
494#ifndef YYTOKEN_TABLE
495# define YYTOKEN_TABLE 0
496#endif
497
498#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
499typedef union YYSTYPE
Chet Ramey80b4d712014-10-05 19:12:20 -0400500#line 329 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Jari Aalto31859422009-01-12 13:36:28 +0000501{
Jari Aalto726f6381996-08-26 18:22:31 +0000502 WORD_DESC *word; /* the word that we read. */
503 int number; /* the number that we read. */
504 WORD_LIST *word_list;
505 COMMAND *command;
506 REDIRECT *redirect;
507 ELEMENT element;
508 PATTERN_LIST *pattern;
Jari Aalto31859422009-01-12 13:36:28 +0000509}
Chet Ramey509a4432013-01-10 19:53:16 -0500510/* Line 193 of yacc.c. */
Chet Ramey90a39f32014-10-02 09:07:21 -0400511#line 512 "y.tab.c"
Jari Aalto31859422009-01-12 13:36:28 +0000512 YYSTYPE;
513# define yystype YYSTYPE /* obsolescent; will be withdrawn */
514# define YYSTYPE_IS_DECLARED 1
515# define YYSTYPE_IS_TRIVIAL 1
Jari Aaltof73dda02001-11-13 17:56:06 +0000516#endif
517
518
519
Jari Aalto31859422009-01-12 13:36:28 +0000520/* Copy the second part of user declarations. */
Jari Aaltof73dda02001-11-13 17:56:06 +0000521
Jari Aaltof73dda02001-11-13 17:56:06 +0000522
Jari Aalto31859422009-01-12 13:36:28 +0000523/* Line 216 of yacc.c. */
Chet Ramey90a39f32014-10-02 09:07:21 -0400524#line 525 "y.tab.c"
Jari Aaltof73dda02001-11-13 17:56:06 +0000525
Jari Aalto31859422009-01-12 13:36:28 +0000526#ifdef short
527# undef short
Jari Aaltof73dda02001-11-13 17:56:06 +0000528#endif
529
Jari Aalto31859422009-01-12 13:36:28 +0000530#ifdef YYTYPE_UINT8
531typedef YYTYPE_UINT8 yytype_uint8;
Jari Aaltob80f6442004-07-27 13:29:18 +0000532#else
Jari Aalto31859422009-01-12 13:36:28 +0000533typedef unsigned char yytype_uint8;
Jari Aalto7117c2d2002-07-17 14:10:11 +0000534#endif
Jari Aaltob80f6442004-07-27 13:29:18 +0000535
Jari Aalto31859422009-01-12 13:36:28 +0000536#ifdef YYTYPE_INT8
537typedef YYTYPE_INT8 yytype_int8;
538#elif (defined __STDC__ || defined __C99__FUNC__ \
539 || defined __cplusplus || defined _MSC_VER)
540typedef signed char yytype_int8;
541#else
542typedef short int yytype_int8;
543#endif
544
545#ifdef YYTYPE_UINT16
546typedef YYTYPE_UINT16 yytype_uint16;
547#else
548typedef unsigned short int yytype_uint16;
549#endif
550
551#ifdef YYTYPE_INT16
552typedef YYTYPE_INT16 yytype_int16;
553#else
554typedef short int yytype_int16;
555#endif
556
557#ifndef YYSIZE_T
558# ifdef __SIZE_TYPE__
559# define YYSIZE_T __SIZE_TYPE__
560# elif defined size_t
561# define YYSIZE_T size_t
562# elif ! defined YYSIZE_T && (defined __STDC__ || defined __C99__FUNC__ \
563 || defined __cplusplus || defined _MSC_VER)
564# include <stddef.h> /* INFRINGES ON USER NAME SPACE */
565# define YYSIZE_T size_t
566# else
567# define YYSIZE_T unsigned int
568# endif
569#endif
570
571#define YYSIZE_MAXIMUM ((YYSIZE_T) -1)
572
573#ifndef YY_
Chet Ramey509a4432013-01-10 19:53:16 -0500574# if defined YYENABLE_NLS && YYENABLE_NLS
Jari Aalto31859422009-01-12 13:36:28 +0000575# if ENABLE_NLS
576# include <libintl.h> /* INFRINGES ON USER NAME SPACE */
577# define YY_(msgid) dgettext ("bison-runtime", msgid)
578# endif
579# endif
580# ifndef YY_
581# define YY_(msgid) msgid
582# endif
583#endif
584
585/* Suppress unused-variable warnings by "using" E. */
586#if ! defined lint || defined __GNUC__
587# define YYUSE(e) ((void) (e))
588#else
589# define YYUSE(e) /* empty */
590#endif
591
592/* Identity function, used to suppress warnings about constant conditions. */
593#ifndef lint
594# define YYID(n) (n)
595#else
596#if (defined __STDC__ || defined __C99__FUNC__ \
597 || defined __cplusplus || defined _MSC_VER)
598static int
599YYID (int i)
600#else
601static int
602YYID (i)
603 int i;
604#endif
605{
606 return i;
607}
608#endif
609
610#if ! defined yyoverflow || YYERROR_VERBOSE
611
612/* The parser invokes alloca or malloc; define the necessary symbols. */
613
614# ifdef YYSTACK_USE_ALLOCA
615# if YYSTACK_USE_ALLOCA
616# ifdef __GNUC__
617# define YYSTACK_ALLOC __builtin_alloca
618# elif defined __BUILTIN_VA_ARG_INCR
619# include <alloca.h> /* INFRINGES ON USER NAME SPACE */
620# elif defined _AIX
621# define YYSTACK_ALLOC __alloca
622# elif defined _MSC_VER
623# include <malloc.h> /* INFRINGES ON USER NAME SPACE */
624# define alloca _alloca
625# else
626# define YYSTACK_ALLOC alloca
627# if ! defined _ALLOCA_H && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
628 || defined __cplusplus || defined _MSC_VER)
629# include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
630# ifndef _STDLIB_H
631# define _STDLIB_H 1
632# endif
633# endif
634# endif
635# endif
636# endif
637
638# ifdef YYSTACK_ALLOC
639 /* Pacify GCC's `empty if-body' warning. */
640# define YYSTACK_FREE(Ptr) do { /* empty */; } while (YYID (0))
641# ifndef YYSTACK_ALLOC_MAXIMUM
642 /* The OS might guarantee only one guard page at the bottom of the stack,
643 and a page size can be as small as 4096 bytes. So we cannot safely
644 invoke alloca (N) if N exceeds 4096. Use a slightly smaller number
645 to allow for a few compiler-allocated temporary stack slots. */
646# define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */
647# endif
648# else
649# define YYSTACK_ALLOC YYMALLOC
650# define YYSTACK_FREE YYFREE
651# ifndef YYSTACK_ALLOC_MAXIMUM
652# define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM
653# endif
654# if (defined __cplusplus && ! defined _STDLIB_H \
655 && ! ((defined YYMALLOC || defined malloc) \
656 && (defined YYFREE || defined free)))
657# include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
658# ifndef _STDLIB_H
659# define _STDLIB_H 1
660# endif
661# endif
662# ifndef YYMALLOC
663# define YYMALLOC malloc
664# if ! defined malloc && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
665 || defined __cplusplus || defined _MSC_VER)
666void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */
667# endif
668# endif
669# ifndef YYFREE
670# define YYFREE free
671# if ! defined free && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
672 || defined __cplusplus || defined _MSC_VER)
673void free (void *); /* INFRINGES ON USER NAME SPACE */
674# endif
675# endif
676# endif
677#endif /* ! defined yyoverflow || YYERROR_VERBOSE */
678
679
680#if (! defined yyoverflow \
681 && (! defined __cplusplus \
682 || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
683
684/* A type that is properly aligned for any stack member. */
685union yyalloc
686{
687 yytype_int16 yyss;
688 YYSTYPE yyvs;
689 };
690
691/* The size of the maximum gap between one aligned stack and the next. */
692# define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1)
693
694/* The size of an array large to enough to hold all stacks, each with
695 N elements. */
696# define YYSTACK_BYTES(N) \
697 ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE)) \
698 + YYSTACK_GAP_MAXIMUM)
699
700/* Copy COUNT objects from FROM to TO. The source and destination do
701 not overlap. */
702# ifndef YYCOPY
703# if defined __GNUC__ && 1 < __GNUC__
704# define YYCOPY(To, From, Count) \
705 __builtin_memcpy (To, From, (Count) * sizeof (*(From)))
706# else
707# define YYCOPY(To, From, Count) \
708 do \
709 { \
710 YYSIZE_T yyi; \
711 for (yyi = 0; yyi < (Count); yyi++) \
712 (To)[yyi] = (From)[yyi]; \
713 } \
714 while (YYID (0))
715# endif
716# endif
717
718/* Relocate STACK from its old location to the new one. The
719 local variables YYSIZE and YYSTACKSIZE give the old and new number of
720 elements in the stack, and YYPTR gives the new location of the
721 stack. Advance YYPTR to a properly aligned location for the next
722 stack. */
723# define YYSTACK_RELOCATE(Stack) \
724 do \
725 { \
726 YYSIZE_T yynewbytes; \
727 YYCOPY (&yyptr->Stack, Stack, yysize); \
728 Stack = &yyptr->Stack; \
729 yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \
730 yyptr += yynewbytes / sizeof (*yyptr); \
731 } \
732 while (YYID (0))
733
734#endif
735
736/* YYFINAL -- State number of the termination state. */
Chet Ramey495aee42011-11-22 19:11:26 -0500737#define YYFINAL 116
Jari Aalto31859422009-01-12 13:36:28 +0000738/* YYLAST -- Last index in YYTABLE. */
Chet Ramey495aee42011-11-22 19:11:26 -0500739#define YYLAST 659
Jari Aalto31859422009-01-12 13:36:28 +0000740
741/* YYNTOKENS -- Number of terminals. */
Chet Ramey495aee42011-11-22 19:11:26 -0500742#define YYNTOKENS 61
Jari Aalto31859422009-01-12 13:36:28 +0000743/* YYNNTS -- Number of nonterminals. */
744#define YYNNTS 38
745/* YYNRULES -- Number of rules. */
Chet Ramey00018032011-11-21 20:51:19 -0500746#define YYNRULES 167
Jari Aalto31859422009-01-12 13:36:28 +0000747/* YYNRULES -- Number of states. */
Chet Ramey495aee42011-11-22 19:11:26 -0500748#define YYNSTATES 342
Jari Aalto31859422009-01-12 13:36:28 +0000749
750/* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
751#define YYUNDEFTOK 2
Chet Ramey495aee42011-11-22 19:11:26 -0500752#define YYMAXUTOK 304
Jari Aalto31859422009-01-12 13:36:28 +0000753
754#define YYTRANSLATE(YYX) \
755 ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
756
757/* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */
758static const yytype_uint8 yytranslate[] =
759{
760 0, 2, 2, 2, 2, 2, 2, 2, 2, 2,
Chet Ramey495aee42011-11-22 19:11:26 -0500761 51, 2, 2, 2, 2, 2, 2, 2, 2, 2,
Jari Aalto31859422009-01-12 13:36:28 +0000762 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
Chet Ramey495aee42011-11-22 19:11:26 -0500763 2, 2, 2, 2, 2, 2, 2, 2, 49, 2,
764 59, 60, 2, 2, 2, 56, 2, 2, 2, 2,
765 2, 2, 2, 2, 2, 2, 2, 2, 2, 50,
766 55, 2, 54, 2, 2, 2, 2, 2, 2, 2,
Jari Aalto31859422009-01-12 13:36:28 +0000767 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
768 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
769 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
770 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
771 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
Chet Ramey495aee42011-11-22 19:11:26 -0500772 2, 2, 2, 57, 53, 58, 2, 2, 2, 2,
Jari Aalto31859422009-01-12 13:36:28 +0000773 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
774 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
775 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
776 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
777 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
778 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
779 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
780 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
781 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
782 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
783 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
784 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
785 2, 2, 2, 2, 2, 2, 1, 2, 3, 4,
786 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
787 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
788 25, 26, 27, 28, 29, 30, 31, 32, 33, 34,
789 35, 36, 37, 38, 39, 40, 41, 42, 43, 44,
Chet Ramey495aee42011-11-22 19:11:26 -0500790 45, 46, 47, 48, 52
Jari Aalto31859422009-01-12 13:36:28 +0000791};
792
793#if YYDEBUG
794/* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
795 YYRHS. */
796static const yytype_uint16 yyprhs[] =
797{
798 0, 0, 3, 6, 8, 11, 13, 15, 18, 21,
Chet Ramey00018032011-11-21 20:51:19 -0500799 24, 28, 32, 36, 40, 43, 47, 51, 54, 58,
800 62, 65, 69, 73, 76, 80, 84, 87, 91, 95,
801 98, 102, 106, 109, 113, 117, 120, 124, 128, 131,
802 135, 139, 142, 146, 150, 153, 157, 161, 164, 168,
803 172, 175, 178, 180, 182, 184, 186, 189, 191, 194,
804 196, 198, 201, 203, 205, 207, 209, 215, 221, 223,
805 225, 227, 229, 231, 233, 235, 242, 249, 257, 265,
806 276, 287, 297, 307, 315, 323, 329, 335, 342, 349,
807 357, 365, 376, 387, 394, 402, 409, 415, 422, 427,
808 429, 432, 436, 439, 443, 447, 452, 455, 461, 469,
809 476, 480, 482, 486, 491, 498, 504, 506, 509, 514,
810 519, 525, 531, 534, 538, 541, 545, 548, 552, 554,
811 558, 561, 563, 566, 570, 574, 578, 583, 588, 593,
812 598, 603, 605, 607, 609, 611, 613, 615, 616, 619,
813 621, 624, 627, 632, 637, 641, 645, 647, 649, 652,
Chet Ramey495aee42011-11-22 19:11:26 -0500814 655, 658, 661, 666, 671, 673, 675, 678
Jari Aalto31859422009-01-12 13:36:28 +0000815};
816
817/* YYRHS -- A `-1'-separated list of the rules' RHS. */
818static const yytype_int8 yyrhs[] =
819{
Chet Ramey495aee42011-11-22 19:11:26 -0500820 62, 0, -1, 94, 91, -1, 51, -1, 1, 51,
821 -1, 52, -1, 26, -1, 63, 26, -1, 54, 26,
822 -1, 55, 26, -1, 29, 54, 26, -1, 29, 55,
823 26, -1, 28, 54, 26, -1, 28, 55, 26, -1,
824 35, 26, -1, 29, 35, 26, -1, 28, 35, 26,
825 -1, 47, 26, -1, 29, 47, 26, -1, 28, 47,
826 26, -1, 46, 26, -1, 29, 46, 26, -1, 28,
827 46, 26, -1, 36, 26, -1, 29, 36, 26, -1,
828 28, 36, 26, -1, 43, 26, -1, 29, 43, 26,
829 -1, 28, 43, 26, -1, 38, 26, -1, 29, 38,
830 26, -1, 28, 38, 26, -1, 37, 29, -1, 29,
831 37, 29, -1, 28, 37, 29, -1, 39, 29, -1,
832 29, 39, 29, -1, 28, 39, 29, -1, 37, 26,
833 -1, 29, 37, 26, -1, 28, 37, 26, -1, 39,
834 26, -1, 29, 39, 26, -1, 28, 39, 26, -1,
835 39, 56, -1, 29, 39, 56, -1, 28, 39, 56,
836 -1, 37, 56, -1, 29, 37, 56, -1, 28, 37,
837 56, -1, 44, 26, -1, 45, 26, -1, 26, -1,
838 27, -1, 64, -1, 64, -1, 66, 64, -1, 65,
839 -1, 67, 65, -1, 67, -1, 69, -1, 69, 66,
840 -1, 74, -1, 77, -1, 70, -1, 73, -1, 12,
841 88, 14, 88, 15, -1, 13, 88, 14, 88, 15,
842 -1, 72, -1, 78, -1, 76, -1, 79, -1, 80,
843 -1, 81, -1, 71, -1, 10, 26, 93, 14, 88,
844 15, -1, 10, 26, 93, 57, 88, 58, -1, 10,
845 26, 50, 93, 14, 88, 15, -1, 10, 26, 50,
846 93, 57, 88, 58, -1, 10, 26, 93, 21, 63,
847 92, 93, 14, 88, 15, -1, 10, 26, 93, 21,
848 63, 92, 93, 57, 88, 58, -1, 10, 26, 93,
849 21, 92, 93, 14, 88, 15, -1, 10, 26, 93,
850 21, 92, 93, 57, 88, 58, -1, 10, 31, 92,
851 93, 14, 88, 15, -1, 10, 31, 92, 93, 57,
852 88, 58, -1, 10, 31, 14, 88, 15, -1, 10,
853 31, 57, 88, 58, -1, 11, 26, 93, 14, 87,
854 15, -1, 11, 26, 93, 57, 87, 58, -1, 11,
855 26, 50, 93, 14, 87, 15, -1, 11, 26, 50,
856 93, 57, 87, 58, -1, 11, 26, 93, 21, 63,
857 92, 93, 14, 87, 15, -1, 11, 26, 93, 21,
858 63, 92, 93, 57, 87, 58, -1, 8, 26, 93,
859 21, 93, 9, -1, 8, 26, 93, 21, 85, 93,
860 9, -1, 8, 26, 93, 21, 83, 9, -1, 26,
861 59, 60, 93, 75, -1, 16, 26, 59, 60, 93,
862 75, -1, 16, 26, 93, 75, -1, 69, -1, 69,
863 66, -1, 59, 88, 60, -1, 17, 69, -1, 17,
864 69, 66, -1, 17, 26, 69, -1, 17, 26, 69,
865 66, -1, 17, 67, -1, 3, 88, 4, 88, 7,
866 -1, 3, 88, 4, 88, 5, 88, 7, -1, 3,
867 88, 4, 88, 82, 7, -1, 57, 88, 58, -1,
868 30, -1, 18, 32, 19, -1, 6, 88, 4, 88,
869 -1, 6, 88, 4, 88, 5, 88, -1, 6, 88,
870 4, 88, 82, -1, 84, -1, 85, 84, -1, 93,
871 86, 60, 88, -1, 93, 86, 60, 93, -1, 93,
872 59, 86, 60, 88, -1, 93, 59, 86, 60, 93,
873 -1, 84, 40, -1, 85, 84, 40, -1, 84, 41,
874 -1, 85, 84, 41, -1, 84, 42, -1, 85, 84,
875 42, -1, 26, -1, 86, 53, 26, -1, 93, 89,
876 -1, 87, -1, 93, 90, -1, 90, 51, 93, -1,
877 90, 49, 93, -1, 90, 50, 93, -1, 90, 33,
878 93, 90, -1, 90, 34, 93, 90, -1, 90, 49,
879 93, 90, -1, 90, 50, 93, 90, -1, 90, 51,
880 93, 90, -1, 96, -1, 51, -1, 52, -1, 51,
881 -1, 50, -1, 52, -1, -1, 93, 51, -1, 95,
882 -1, 95, 49, -1, 95, 50, -1, 95, 33, 93,
883 95, -1, 95, 34, 93, 95, -1, 95, 49, 95,
884 -1, 95, 50, 95, -1, 96, -1, 97, -1, 22,
885 96, -1, 98, 96, -1, 98, 92, -1, 22, 92,
886 -1, 97, 53, 93, 97, -1, 97, 48, 93, 97,
887 -1, 68, -1, 23, -1, 23, 24, -1, 23, 24,
888 25, -1
Jari Aalto31859422009-01-12 13:36:28 +0000889};
890
891/* YYRLINE[YYN] -- source line where rule number YYN was defined. */
892static const yytype_uint16 yyrline[] =
893{
Chet Ramey90a39f32014-10-02 09:07:21 -0400894 0, 382, 382, 393, 402, 417, 427, 429, 433, 439,
895 445, 451, 457, 463, 469, 475, 481, 487, 493, 499,
896 505, 511, 517, 523, 530, 537, 544, 551, 558, 565,
897 571, 577, 583, 589, 595, 601, 607, 613, 619, 625,
898 631, 637, 643, 649, 655, 661, 667, 673, 679, 685,
899 691, 697, 705, 707, 709, 713, 717, 728, 730, 734,
900 736, 738, 754, 756, 760, 762, 764, 766, 768, 770,
901 772, 774, 776, 778, 780, 784, 789, 794, 799, 804,
902 809, 814, 819, 826, 831, 836, 841, 848, 853, 858,
903 863, 868, 873, 880, 885, 890, 897, 900, 903, 907,
904 909, 940, 947, 952, 969, 974, 991, 998, 1000, 1002,
905 1007, 1011, 1015, 1019, 1021, 1023, 1027, 1028, 1032, 1034,
906 1036, 1038, 1042, 1044, 1046, 1048, 1050, 1052, 1056, 1058,
907 1067, 1075, 1076, 1082, 1083, 1090, 1094, 1096, 1098, 1105,
908 1107, 1109, 1113, 1114, 1117, 1119, 1121, 1125, 1126, 1135,
909 1148, 1164, 1179, 1181, 1183, 1190, 1193, 1197, 1199, 1205,
910 1211, 1228, 1248, 1250, 1273, 1277, 1279, 1281
Jari Aalto31859422009-01-12 13:36:28 +0000911};
912#endif
913
914#if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
915/* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
916 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
917static const char *const yytname[] =
918{
919 "$end", "error", "$undefined", "IF", "THEN", "ELSE", "ELIF", "FI",
920 "CASE", "ESAC", "FOR", "SELECT", "WHILE", "UNTIL", "DO", "DONE",
921 "FUNCTION", "COPROC", "COND_START", "COND_END", "COND_ERROR", "IN",
Chet Ramey495aee42011-11-22 19:11:26 -0500922 "BANG", "TIME", "TIMEOPT", "TIMEIGN", "WORD", "ASSIGNMENT_WORD",
923 "REDIR_WORD", "NUMBER", "ARITH_CMD", "ARITH_FOR_EXPRS", "COND_CMD",
924 "AND_AND", "OR_OR", "GREATER_GREATER", "LESS_LESS", "LESS_AND",
925 "LESS_LESS_LESS", "GREATER_AND", "SEMI_SEMI", "SEMI_AND",
926 "SEMI_SEMI_AND", "LESS_LESS_MINUS", "AND_GREATER", "AND_GREATER_GREATER",
927 "LESS_GREATER", "GREATER_BAR", "BAR_AND", "'&'", "';'", "'\\n'",
928 "yacc_EOF", "'|'", "'>'", "'<'", "'-'", "'{'", "'}'", "'('", "')'",
929 "$accept", "inputunit", "word_list", "redirection",
930 "simple_command_element", "redirection_list", "simple_command",
931 "command", "shell_command", "for_command", "arith_for_command",
932 "select_command", "case_command", "function_def", "function_body",
933 "subshell", "coproc", "if_command", "group_command", "arith_command",
934 "cond_command", "elif_clause", "case_clause", "pattern_list",
935 "case_clause_sequence", "pattern", "list", "compound_list", "list0",
936 "list1", "simple_list_terminator", "list_terminator", "newline_list",
937 "simple_list", "simple_list1", "pipeline_command", "pipeline",
938 "timespec", 0
Jari Aalto31859422009-01-12 13:36:28 +0000939};
940#endif
941
942# ifdef YYPRINT
943/* YYTOKNUM[YYLEX-NUM] -- Internal token number corresponding to
944 token YYLEX-NUM. */
945static const yytype_uint16 yytoknum[] =
946{
947 0, 256, 257, 258, 259, 260, 261, 262, 263, 264,
948 265, 266, 267, 268, 269, 270, 271, 272, 273, 274,
949 275, 276, 277, 278, 279, 280, 281, 282, 283, 284,
950 285, 286, 287, 288, 289, 290, 291, 292, 293, 294,
Chet Ramey495aee42011-11-22 19:11:26 -0500951 295, 296, 297, 298, 299, 300, 301, 302, 303, 38,
952 59, 10, 304, 124, 62, 60, 45, 123, 125, 40,
953 41
Jari Aalto31859422009-01-12 13:36:28 +0000954};
955# endif
956
957/* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
958static const yytype_uint8 yyr1[] =
959{
Chet Ramey495aee42011-11-22 19:11:26 -0500960 0, 61, 62, 62, 62, 62, 63, 63, 64, 64,
961 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
962 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
963 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
964 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
965 64, 64, 65, 65, 65, 66, 66, 67, 67, 68,
966 68, 68, 68, 68, 69, 69, 69, 69, 69, 69,
967 69, 69, 69, 69, 69, 70, 70, 70, 70, 70,
968 70, 70, 70, 71, 71, 71, 71, 72, 72, 72,
969 72, 72, 72, 73, 73, 73, 74, 74, 74, 75,
970 75, 76, 77, 77, 77, 77, 77, 78, 78, 78,
971 79, 80, 81, 82, 82, 82, 83, 83, 84, 84,
972 84, 84, 85, 85, 85, 85, 85, 85, 86, 86,
973 87, 88, 88, 89, 89, 89, 90, 90, 90, 90,
974 90, 90, 91, 91, 92, 92, 92, 93, 93, 94,
975 94, 94, 95, 95, 95, 95, 95, 96, 96, 96,
976 96, 96, 97, 97, 97, 98, 98, 98
Jari Aalto31859422009-01-12 13:36:28 +0000977};
978
979/* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
980static const yytype_uint8 yyr2[] =
981{
982 0, 2, 2, 1, 2, 1, 1, 2, 2, 2,
Chet Ramey00018032011-11-21 20:51:19 -0500983 3, 3, 3, 3, 2, 3, 3, 2, 3, 3,
984 2, 3, 3, 2, 3, 3, 2, 3, 3, 2,
985 3, 3, 2, 3, 3, 2, 3, 3, 2, 3,
986 3, 2, 3, 3, 2, 3, 3, 2, 3, 3,
987 2, 2, 1, 1, 1, 1, 2, 1, 2, 1,
988 1, 2, 1, 1, 1, 1, 5, 5, 1, 1,
989 1, 1, 1, 1, 1, 6, 6, 7, 7, 10,
990 10, 9, 9, 7, 7, 5, 5, 6, 6, 7,
991 7, 10, 10, 6, 7, 6, 5, 6, 4, 1,
992 2, 3, 2, 3, 3, 4, 2, 5, 7, 6,
993 3, 1, 3, 4, 6, 5, 1, 2, 4, 4,
994 5, 5, 2, 3, 2, 3, 2, 3, 1, 3,
995 2, 1, 2, 3, 3, 3, 4, 4, 4, 4,
996 4, 1, 1, 1, 1, 1, 1, 0, 2, 1,
997 2, 2, 4, 4, 3, 3, 1, 1, 2, 2,
Chet Ramey495aee42011-11-22 19:11:26 -0500998 2, 2, 4, 4, 1, 1, 2, 3
Jari Aalto31859422009-01-12 13:36:28 +0000999};
1000
1001/* YYDEFACT[STATE-NAME] -- Default rule to reduce with in state
1002 STATE-NUM when YYTABLE doesn't specify something else to do. Zero
1003 means the default is an error. */
1004static const yytype_uint8 yydefact[] =
1005{
Chet Ramey00018032011-11-21 20:51:19 -05001006 0, 0, 147, 0, 0, 0, 147, 147, 0, 0,
Chet Ramey495aee42011-11-22 19:11:26 -05001007 0, 0, 165, 52, 53, 0, 0, 111, 0, 0,
Chet Ramey00018032011-11-21 20:51:19 -05001008 0, 0, 0, 0, 0, 0, 0, 0, 3, 5,
Chet Ramey495aee42011-11-22 19:11:26 -05001009 0, 0, 147, 147, 0, 54, 57, 59, 164, 60,
Chet Ramey00018032011-11-21 20:51:19 -05001010 64, 74, 68, 65, 62, 70, 63, 69, 71, 72,
1011 73, 0, 149, 156, 157, 0, 4, 131, 0, 0,
1012 147, 147, 0, 147, 0, 0, 147, 52, 106, 102,
Chet Ramey495aee42011-11-22 19:11:26 -05001013 0, 145, 144, 146, 161, 158, 166, 0, 0, 0,
Chet Ramey00018032011-11-21 20:51:19 -05001014 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
Chet Ramey495aee42011-11-22 19:11:26 -05001015 0, 0, 0, 0, 0, 0, 0, 0, 14, 23,
1016 38, 32, 47, 29, 41, 35, 44, 26, 50, 51,
1017 20, 17, 8, 9, 0, 0, 1, 52, 58, 55,
1018 61, 142, 143, 2, 147, 147, 150, 151, 147, 147,
1019 160, 159, 147, 148, 130, 132, 141, 0, 147, 0,
1020 147, 147, 147, 147, 0, 147, 147, 0, 0, 104,
1021 103, 112, 167, 147, 16, 25, 40, 34, 49, 31,
1022 43, 37, 46, 28, 22, 19, 12, 13, 15, 24,
1023 39, 33, 48, 30, 42, 36, 45, 27, 21, 18,
1024 10, 11, 110, 101, 56, 0, 0, 154, 155, 0,
1025 0, 0, 147, 147, 147, 147, 147, 147, 0, 147,
1026 0, 147, 0, 0, 0, 0, 147, 0, 147, 0,
1027 0, 147, 99, 98, 105, 0, 152, 153, 0, 0,
1028 163, 162, 147, 147, 107, 0, 0, 0, 134, 135,
1029 133, 0, 116, 147, 0, 147, 147, 0, 6, 0,
1030 147, 0, 85, 86, 147, 147, 147, 147, 0, 0,
1031 0, 0, 66, 67, 0, 100, 96, 0, 0, 109,
1032 136, 137, 138, 139, 140, 95, 122, 124, 126, 117,
1033 0, 93, 128, 0, 0, 0, 0, 75, 7, 147,
1034 0, 76, 0, 0, 0, 0, 87, 0, 147, 88,
1035 97, 108, 147, 147, 147, 147, 123, 125, 127, 94,
1036 0, 0, 147, 77, 78, 0, 147, 147, 83, 84,
1037 89, 90, 0, 113, 0, 0, 0, 147, 129, 118,
1038 119, 147, 147, 0, 0, 147, 147, 147, 115, 120,
1039 121, 0, 0, 81, 82, 0, 0, 114, 79, 80,
1040 91, 92
Jari Aalto31859422009-01-12 13:36:28 +00001041};
1042
1043/* YYDEFGOTO[NTERM-NUM]. */
1044static const yytype_int16 yydefgoto[] =
1045{
Chet Ramey495aee42011-11-22 19:11:26 -05001046 -1, 34, 239, 35, 36, 120, 37, 38, 39, 40,
1047 41, 42, 43, 44, 213, 45, 46, 47, 48, 49,
1048 50, 225, 231, 232, 233, 274, 57, 58, 134, 135,
1049 123, 74, 59, 51, 187, 136, 54, 55
Jari Aalto31859422009-01-12 13:36:28 +00001050};
1051
1052/* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
1053 STATE-NUM. */
Chet Ramey495aee42011-11-22 19:11:26 -05001054#define YYPACT_NINF -208
Jari Aalto31859422009-01-12 13:36:28 +00001055static const yytype_int16 yypact[] =
1056{
Chet Ramey495aee42011-11-22 19:11:26 -05001057 296, -35, -208, -2, 38, 10, -208, -208, 24, 546,
1058 31, 346, 51, 47, -208, 591, 604, -208, 56, 71,
1059 -18, 112, 130, 115, 128, 136, 143, 154, -208, -208,
1060 157, 170, -208, -208, 111, -208, -208, 229, -208, 578,
1061 -208, -208, -208, -208, -208, -208, -208, -208, -208, -208,
1062 -208, -12, -3, -208, 48, 346, -208, -208, 208, 396,
1063 -208, 73, 15, 163, 190, 201, 160, 107, 229, 578,
1064 204, -208, -208, -208, -208, -208, 195, 165, 202, 215,
1065 152, 216, 153, 222, 227, 236, 237, 244, 245, 253,
1066 158, 254, 171, 255, 256, 259, 261, 262, -208, -208,
1067 -208, -208, -208, -208, -208, -208, -208, -208, -208, -208,
1068 -208, -208, -208, -208, 231, 230, -208, -208, -208, -208,
1069 578, -208, -208, -208, -208, -208, 446, 446, -208, -208,
1070 -208, -208, -208, -208, -208, 210, -208, 4, -208, 65,
1071 -208, -208, -208, -208, 70, -208, -208, 232, 41, 578,
1072 578, -208, -208, -208, -208, -208, -208, -208, -208, -208,
1073 -208, -208, -208, -208, -208, -208, -208, -208, -208, -208,
1074 -208, -208, -208, -208, -208, -208, -208, -208, -208, -208,
1075 -208, -208, -208, -208, -208, 396, 396, 23, 23, 496,
1076 496, 97, -208, -208, -208, -208, -208, -208, 85, -208,
1077 185, -208, 276, 235, 100, 110, -208, 268, -208, 280,
1078 283, -208, 578, -208, 578, 41, -208, -208, 446, 446,
1079 48, 48, -208, -208, -208, 295, 396, 396, 396, 396,
1080 396, 294, 161, -208, 19, -208, -208, 290, -208, 200,
1081 -208, 252, -208, -208, -208, -208, -208, -208, 302, 396,
1082 200, 269, -208, -208, 41, 578, -208, 313, 324, -208,
1083 -208, -208, 55, 55, 55, -208, -208, -208, -208, 192,
1084 34, -208, -208, 303, -19, 315, 278, -208, -208, -208,
1085 114, -208, 322, 286, 323, 287, -208, 210, -208, -208,
1086 -208, -208, -208, -208, -208, -208, -208, -208, -208, -208,
1087 8, 320, -208, -208, -208, 117, -208, -208, -208, -208,
1088 -208, -208, 119, 167, 396, 396, 396, -208, -208, -208,
1089 396, -208, -208, 337, 307, -208, -208, -208, -208, -208,
1090 396, 345, 308, -208, -208, 352, 312, -208, -208, -208,
1091 -208, -208
Jari Aalto31859422009-01-12 13:36:28 +00001092};
1093
1094/* YYPGOTO[NTERM-NUM]. */
1095static const yytype_int16 yypgoto[] =
1096{
Chet Ramey495aee42011-11-22 19:11:26 -05001097 -208, -208, 164, -37, -31, -62, 368, -208, -5, -208,
1098 -208, -208, -208, -208, -206, -208, -208, -208, -208, -208,
1099 -208, 66, -208, 145, -208, 88, -173, -6, -208, -207,
1100 -208, -45, -48, -208, 5, 3, 17, -208
Jari Aalto31859422009-01-12 13:36:28 +00001101};
1102
1103/* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
1104 positive, shift that token. If negative, reduce the rule which
1105 number is the opposite. If zero, do what YYDEFACT says.
1106 If YYTABLE_NINF, syntax error. */
1107#define YYTABLE_NINF -1
1108static const yytype_uint16 yytable[] =
1109{
Chet Ramey495aee42011-11-22 19:11:26 -05001110 64, 65, 119, 53, 69, 52, 118, 150, 100, 256,
1111 130, 101, 137, 139, 75, 144, 56, 142, 148, 260,
1112 261, 262, 263, 264, 60, 197, 114, 115, 271, 140,
1113 124, 125, 119, 248, 301, 251, 63, 118, 102, 121,
1114 122, 302, 287, 299, 2, 272, 126, 127, 290, 3,
1115 66, 4, 5, 6, 7, 133, 124, 125, 131, 10,
1116 272, 301, 149, 70, 61, 71, 72, 73, 317, 62,
1117 133, 17, 141, 284, 285, 76, 185, 186, 273, 199,
1118 189, 190, 98, 184, 206, 133, 200, 214, 192, 193,
1119 198, 207, 133, 273, 204, 205, 128, 99, 32, 235,
1120 33, 129, 222, 223, 224, 215, 77, 262, 263, 264,
1121 2, 116, 119, 184, 244, 3, 133, 4, 5, 6,
1122 7, 133, 201, 138, 246, 10, 191, 208, 306, 53,
1123 53, 321, 188, 325, 202, 203, 133, 17, 103, 209,
1124 210, 107, 236, 212, 226, 227, 228, 229, 230, 234,
1125 255, 133, 335, 336, 108, 240, 104, 245, 249, 105,
1126 249, 133, 109, 254, 32, 133, 33, 247, 133, 110,
1127 133, 307, 327, 223, 322, 119, 326, 184, 156, 160,
1128 111, 157, 161, 112, 170, 270, 106, 171, 53, 53,
1129 216, 217, 280, 237, 279, 241, 113, 174, 249, 249,
1130 175, 266, 267, 268, 145, 288, 220, 221, 158, 162,
1131 212, 238, 132, 143, 172, 146, 257, 258, 184, 147,
1132 152, 53, 53, 151, 188, 153, 278, 176, 154, 275,
1133 276, 305, 296, 297, 298, 71, 72, 73, 282, 283,
1134 312, 155, 159, 192, 193, 314, 315, 316, 163, 212,
1135 71, 72, 73, 164, 320, 117, 14, 15, 16, 194,
1136 195, 196, 165, 166, 18, 19, 20, 21, 22, 330,
1137 167, 168, 23, 24, 25, 26, 27, 249, 249, 169,
1138 173, 177, 178, 30, 31, 179, 313, 180, 181, 182,
1139 183, 242, 211, 243, 238, 252, 319, 1, 253, 2,
1140 323, 324, 259, 265, 3, 277, 4, 5, 6, 7,
1141 281, 329, 8, 9, 10, 331, 332, 286, 11, 12,
1142 291, 337, 13, 14, 15, 16, 17, 289, 292, 272,
1143 303, 18, 19, 20, 21, 22, 304, 308, 310, 23,
1144 24, 25, 26, 27, 309, 311, 318, 28, 29, 2,
1145 30, 31, 333, 32, 3, 33, 4, 5, 6, 7,
1146 338, 300, 8, 9, 10, 334, 339, 340, 11, 12,
1147 341, 250, 13, 14, 15, 16, 17, 68, 269, 328,
Chet Ramey00018032011-11-21 20:51:19 -05001148 0, 18, 19, 20, 21, 22, 0, 0, 0, 23,
Chet Ramey495aee42011-11-22 19:11:26 -05001149 24, 25, 26, 27, 0, 0, 71, 72, 73, 2,
Chet Ramey00018032011-11-21 20:51:19 -05001150 30, 31, 0, 32, 3, 33, 4, 5, 6, 7,
1151 0, 0, 8, 9, 10, 0, 0, 0, 11, 12,
Chet Ramey495aee42011-11-22 19:11:26 -05001152 0, 0, 13, 14, 15, 16, 17, 0, 0, 0,
1153 0, 18, 19, 20, 21, 22, 0, 0, 0, 23,
1154 24, 25, 26, 27, 0, 0, 0, 133, 0, 2,
1155 30, 31, 0, 32, 3, 33, 4, 5, 6, 7,
1156 0, 0, 8, 9, 10, 0, 0, 0, 11, 12,
1157 0, 0, 13, 14, 15, 16, 17, 0, 0, 0,
1158 0, 18, 19, 20, 21, 22, 0, 0, 0, 23,
1159 24, 25, 26, 27, 0, 0, 0, 0, 0, 2,
1160 30, 31, 0, 32, 3, 33, 4, 5, 6, 7,
1161 0, 0, 8, 9, 10, 0, 0, 0, 0, 0,
1162 0, 0, 13, 14, 15, 16, 17, 0, 0, 0,
1163 0, 18, 19, 20, 21, 22, 0, 0, 0, 23,
1164 24, 25, 26, 27, 0, 0, 0, 133, 0, 2,
1165 30, 31, 0, 32, 3, 33, 4, 5, 6, 7,
1166 0, 0, 0, 0, 10, 0, 0, 0, 0, 0,
1167 0, 0, 67, 14, 15, 16, 17, 0, 0, 0,
1168 0, 18, 19, 20, 21, 22, 0, 0, 0, 23,
1169 24, 25, 26, 27, 0, 0, 0, 0, 0, 0,
1170 30, 31, 0, 32, 0, 33, 15, 16, 0, 0,
1171 0, 0, 0, 18, 19, 20, 21, 22, 0, 0,
1172 0, 23, 24, 25, 26, 27, 78, 79, 80, 81,
1173 82, 0, 30, 31, 83, 0, 0, 84, 85, 88,
1174 89, 90, 91, 92, 0, 86, 87, 93, 0, 0,
1175 94, 95, 0, 0, 0, 0, 0, 0, 96, 97
Jari Aalto31859422009-01-12 13:36:28 +00001176};
1177
1178static const yytype_int16 yycheck[] =
1179{
Chet Ramey495aee42011-11-22 19:11:26 -05001180 6, 7, 39, 0, 9, 0, 37, 69, 26, 215,
1181 55, 29, 60, 61, 11, 63, 51, 62, 66, 226,
1182 227, 228, 229, 230, 26, 21, 32, 33, 9, 14,
1183 33, 34, 69, 206, 53, 208, 26, 68, 56, 51,
1184 52, 60, 249, 9, 3, 26, 49, 50, 254, 8,
1185 26, 10, 11, 12, 13, 51, 33, 34, 55, 18,
1186 26, 53, 67, 32, 26, 50, 51, 52, 60, 31,
1187 51, 30, 57, 246, 247, 24, 124, 125, 59, 14,
1188 128, 129, 26, 120, 14, 51, 21, 149, 33, 34,
1189 138, 21, 51, 59, 142, 143, 48, 26, 57, 14,
1190 59, 53, 5, 6, 7, 153, 59, 314, 315, 316,
1191 3, 0, 149, 150, 14, 8, 51, 10, 11, 12,
1192 13, 51, 57, 50, 14, 18, 132, 57, 14, 126,
1193 127, 14, 127, 14, 140, 141, 51, 30, 26, 145,
1194 146, 26, 57, 148, 192, 193, 194, 195, 196, 197,
1195 212, 51, 325, 326, 26, 200, 26, 57, 206, 29,
1196 208, 51, 26, 211, 57, 51, 59, 57, 51, 26,
1197 51, 57, 5, 6, 57, 212, 57, 214, 26, 26,
1198 26, 29, 29, 26, 26, 233, 56, 29, 185, 186,
1199 185, 186, 240, 199, 239, 201, 26, 26, 246, 247,
1200 29, 40, 41, 42, 14, 250, 189, 190, 56, 56,
1201 215, 26, 4, 50, 56, 14, 222, 223, 255, 59,
1202 25, 218, 219, 19, 219, 60, 26, 56, 26, 235,
1203 236, 279, 40, 41, 42, 50, 51, 52, 244, 245,
1204 288, 26, 26, 33, 34, 293, 294, 295, 26, 254,
1205 50, 51, 52, 26, 302, 26, 27, 28, 29, 49,
1206 50, 51, 26, 26, 35, 36, 37, 38, 39, 317,
1207 26, 26, 43, 44, 45, 46, 47, 325, 326, 26,
1208 26, 26, 26, 54, 55, 26, 292, 26, 26, 58,
1209 60, 15, 60, 58, 26, 15, 302, 1, 15, 3,
1210 306, 307, 7, 9, 8, 15, 10, 11, 12, 13,
1211 58, 317, 16, 17, 18, 321, 322, 15, 22, 23,
1212 7, 327, 26, 27, 28, 29, 30, 58, 4, 26,
1213 15, 35, 36, 37, 38, 39, 58, 15, 15, 43,
1214 44, 45, 46, 47, 58, 58, 26, 51, 52, 3,
1215 54, 55, 15, 57, 8, 59, 10, 11, 12, 13,
1216 15, 273, 16, 17, 18, 58, 58, 15, 22, 23,
1217 58, 207, 26, 27, 28, 29, 30, 9, 233, 313,
1218 -1, 35, 36, 37, 38, 39, -1, -1, -1, 43,
1219 44, 45, 46, 47, -1, -1, 50, 51, 52, 3,
1220 54, 55, -1, 57, 8, 59, 10, 11, 12, 13,
Chet Ramey00018032011-11-21 20:51:19 -05001221 -1, -1, 16, 17, 18, -1, -1, -1, 22, 23,
Chet Ramey495aee42011-11-22 19:11:26 -05001222 -1, -1, 26, 27, 28, 29, 30, -1, -1, -1,
1223 -1, 35, 36, 37, 38, 39, -1, -1, -1, 43,
1224 44, 45, 46, 47, -1, -1, -1, 51, -1, 3,
1225 54, 55, -1, 57, 8, 59, 10, 11, 12, 13,
1226 -1, -1, 16, 17, 18, -1, -1, -1, 22, 23,
1227 -1, -1, 26, 27, 28, 29, 30, -1, -1, -1,
1228 -1, 35, 36, 37, 38, 39, -1, -1, -1, 43,
1229 44, 45, 46, 47, -1, -1, -1, -1, -1, 3,
1230 54, 55, -1, 57, 8, 59, 10, 11, 12, 13,
1231 -1, -1, 16, 17, 18, -1, -1, -1, -1, -1,
1232 -1, -1, 26, 27, 28, 29, 30, -1, -1, -1,
1233 -1, 35, 36, 37, 38, 39, -1, -1, -1, 43,
1234 44, 45, 46, 47, -1, -1, -1, 51, -1, 3,
1235 54, 55, -1, 57, 8, 59, 10, 11, 12, 13,
1236 -1, -1, -1, -1, 18, -1, -1, -1, -1, -1,
1237 -1, -1, 26, 27, 28, 29, 30, -1, -1, -1,
1238 -1, 35, 36, 37, 38, 39, -1, -1, -1, 43,
1239 44, 45, 46, 47, -1, -1, -1, -1, -1, -1,
1240 54, 55, -1, 57, -1, 59, 28, 29, -1, -1,
1241 -1, -1, -1, 35, 36, 37, 38, 39, -1, -1,
1242 -1, 43, 44, 45, 46, 47, 35, 36, 37, 38,
1243 39, -1, 54, 55, 43, -1, -1, 46, 47, 35,
1244 36, 37, 38, 39, -1, 54, 55, 43, -1, -1,
1245 46, 47, -1, -1, -1, -1, -1, -1, 54, 55
Jari Aalto31859422009-01-12 13:36:28 +00001246};
1247
1248/* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
1249 symbol of state STATE-NUM. */
1250static const yytype_uint8 yystos[] =
1251{
1252 0, 1, 3, 8, 10, 11, 12, 13, 16, 17,
Chet Ramey495aee42011-11-22 19:11:26 -05001253 18, 22, 23, 26, 27, 28, 29, 30, 35, 36,
1254 37, 38, 39, 43, 44, 45, 46, 47, 51, 52,
1255 54, 55, 57, 59, 62, 64, 65, 67, 68, 69,
1256 70, 71, 72, 73, 74, 76, 77, 78, 79, 80,
1257 81, 94, 95, 96, 97, 98, 51, 87, 88, 93,
1258 26, 26, 31, 26, 88, 88, 26, 26, 67, 69,
1259 32, 50, 51, 52, 92, 96, 24, 59, 35, 36,
1260 37, 38, 39, 43, 46, 47, 54, 55, 35, 36,
1261 37, 38, 39, 43, 46, 47, 54, 55, 26, 26,
1262 26, 29, 56, 26, 26, 29, 56, 26, 26, 26,
1263 26, 26, 26, 26, 88, 88, 0, 26, 65, 64,
1264 66, 51, 52, 91, 33, 34, 49, 50, 48, 53,
1265 92, 96, 4, 51, 89, 90, 96, 93, 50, 93,
1266 14, 57, 92, 50, 93, 14, 14, 59, 93, 69,
1267 66, 19, 25, 60, 26, 26, 26, 29, 56, 26,
1268 26, 29, 56, 26, 26, 26, 26, 26, 26, 26,
1269 26, 29, 56, 26, 26, 29, 56, 26, 26, 26,
1270 26, 26, 58, 60, 64, 93, 93, 95, 95, 93,
1271 93, 88, 33, 34, 49, 50, 51, 21, 93, 14,
1272 21, 57, 88, 88, 93, 93, 14, 21, 57, 88,
1273 88, 60, 69, 75, 66, 93, 95, 95, 49, 50,
1274 97, 97, 5, 6, 7, 82, 93, 93, 93, 93,
1275 93, 83, 84, 85, 93, 14, 57, 88, 26, 63,
1276 92, 88, 15, 58, 14, 57, 14, 57, 87, 93,
1277 63, 87, 15, 15, 93, 66, 75, 88, 88, 7,
1278 90, 90, 90, 90, 90, 9, 40, 41, 42, 84,
1279 93, 9, 26, 59, 86, 88, 88, 15, 26, 92,
1280 93, 58, 88, 88, 87, 87, 15, 90, 92, 58,
1281 75, 7, 4, 49, 50, 51, 40, 41, 42, 9,
1282 86, 53, 60, 15, 58, 93, 14, 57, 15, 58,
1283 15, 58, 93, 88, 93, 93, 93, 60, 26, 88,
1284 93, 14, 57, 88, 88, 14, 57, 5, 82, 88,
1285 93, 88, 88, 15, 58, 87, 87, 88, 15, 58,
1286 15, 58
Jari Aalto31859422009-01-12 13:36:28 +00001287};
Jari Aaltof73dda02001-11-13 17:56:06 +00001288
1289#define yyerrok (yyerrstatus = 0)
1290#define yyclearin (yychar = YYEMPTY)
Jari Aalto31859422009-01-12 13:36:28 +00001291#define YYEMPTY (-2)
Jari Aaltof73dda02001-11-13 17:56:06 +00001292#define YYEOF 0
Jari Aalto31859422009-01-12 13:36:28 +00001293
Jari Aaltof73dda02001-11-13 17:56:06 +00001294#define YYACCEPT goto yyacceptlab
Jari Aalto31859422009-01-12 13:36:28 +00001295#define YYABORT goto yyabortlab
1296#define YYERROR goto yyerrorlab
1297
1298
1299/* Like YYERROR except do call yyerror. This remains here temporarily
1300 to ease the transition to the new meaning of YYERROR, for GCC.
Jari Aaltof73dda02001-11-13 17:56:06 +00001301 Once GCC version 2 has supplanted version 1, this can go. */
Jari Aalto31859422009-01-12 13:36:28 +00001302
Jari Aaltof73dda02001-11-13 17:56:06 +00001303#define YYFAIL goto yyerrlab
Jari Aalto31859422009-01-12 13:36:28 +00001304
Jari Aaltof73dda02001-11-13 17:56:06 +00001305#define YYRECOVERING() (!!yyerrstatus)
Jari Aalto31859422009-01-12 13:36:28 +00001306
1307#define YYBACKUP(Token, Value) \
Jari Aaltof73dda02001-11-13 17:56:06 +00001308do \
1309 if (yychar == YYEMPTY && yylen == 1) \
Jari Aalto31859422009-01-12 13:36:28 +00001310 { \
1311 yychar = (Token); \
1312 yylval = (Value); \
1313 yytoken = YYTRANSLATE (yychar); \
1314 YYPOPSTACK (1); \
Jari Aaltof73dda02001-11-13 17:56:06 +00001315 goto yybackup; \
1316 } \
1317 else \
Jari Aalto31859422009-01-12 13:36:28 +00001318 { \
1319 yyerror (YY_("syntax error: cannot back up")); \
1320 YYERROR; \
1321 } \
1322while (YYID (0))
1323
Jari Aaltof73dda02001-11-13 17:56:06 +00001324
1325#define YYTERROR 1
1326#define YYERRCODE 256
1327
Jari Aalto31859422009-01-12 13:36:28 +00001328
1329/* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
1330 If N is 0, then set CURRENT to the empty location which ends
1331 the previous symbol: RHS[0] (always defined). */
1332
1333#define YYRHSLOC(Rhs, K) ((Rhs)[K])
1334#ifndef YYLLOC_DEFAULT
1335# define YYLLOC_DEFAULT(Current, Rhs, N) \
1336 do \
1337 if (YYID (N)) \
1338 { \
1339 (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \
1340 (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \
1341 (Current).last_line = YYRHSLOC (Rhs, N).last_line; \
1342 (Current).last_column = YYRHSLOC (Rhs, N).last_column; \
1343 } \
1344 else \
1345 { \
1346 (Current).first_line = (Current).last_line = \
1347 YYRHSLOC (Rhs, 0).last_line; \
1348 (Current).first_column = (Current).last_column = \
1349 YYRHSLOC (Rhs, 0).last_column; \
1350 } \
1351 while (YYID (0))
Jari Aaltof73dda02001-11-13 17:56:06 +00001352#endif
1353
Jari Aalto31859422009-01-12 13:36:28 +00001354
1355/* YY_LOCATION_PRINT -- Print the location on the stream.
1356 This macro was not mandated originally: define only if we know
1357 we won't break user code: when these are the locations we know. */
1358
1359#ifndef YY_LOCATION_PRINT
Chet Ramey509a4432013-01-10 19:53:16 -05001360# if defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL
Jari Aalto31859422009-01-12 13:36:28 +00001361# define YY_LOCATION_PRINT(File, Loc) \
1362 fprintf (File, "%d.%d-%d.%d", \
1363 (Loc).first_line, (Loc).first_column, \
1364 (Loc).last_line, (Loc).last_column)
1365# else
1366# define YY_LOCATION_PRINT(File, Loc) ((void) 0)
1367# endif
1368#endif
1369
1370
1371/* YYLEX -- calling `yylex' with the right arguments. */
1372
Jari Aaltob80f6442004-07-27 13:29:18 +00001373#ifdef YYLEX_PARAM
Jari Aalto31859422009-01-12 13:36:28 +00001374# define YYLEX yylex (YYLEX_PARAM)
Jari Aaltob80f6442004-07-27 13:29:18 +00001375#else
Jari Aalto31859422009-01-12 13:36:28 +00001376# define YYLEX yylex ()
Jari Aaltob80f6442004-07-27 13:29:18 +00001377#endif
Jari Aalto31859422009-01-12 13:36:28 +00001378
1379/* Enable debugging if requested. */
1380#if YYDEBUG
1381
1382# ifndef YYFPRINTF
1383# include <stdio.h> /* INFRINGES ON USER NAME SPACE */
1384# define YYFPRINTF fprintf
1385# endif
1386
1387# define YYDPRINTF(Args) \
1388do { \
1389 if (yydebug) \
1390 YYFPRINTF Args; \
1391} while (YYID (0))
1392
1393# define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
1394do { \
1395 if (yydebug) \
1396 { \
1397 YYFPRINTF (stderr, "%s ", Title); \
1398 yy_symbol_print (stderr, \
1399 Type, Value); \
1400 YYFPRINTF (stderr, "\n"); \
1401 } \
1402} while (YYID (0))
1403
1404
1405/*--------------------------------.
1406| Print this symbol on YYOUTPUT. |
1407`--------------------------------*/
1408
1409/*ARGSUSED*/
1410#if (defined __STDC__ || defined __C99__FUNC__ \
1411 || defined __cplusplus || defined _MSC_VER)
1412static void
1413yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep)
Jari Aaltob80f6442004-07-27 13:29:18 +00001414#else
Jari Aalto31859422009-01-12 13:36:28 +00001415static void
1416yy_symbol_value_print (yyoutput, yytype, yyvaluep)
1417 FILE *yyoutput;
1418 int yytype;
1419 YYSTYPE const * const yyvaluep;
Jari Aaltob80f6442004-07-27 13:29:18 +00001420#endif
Jari Aalto31859422009-01-12 13:36:28 +00001421{
1422 if (!yyvaluep)
1423 return;
1424# ifdef YYPRINT
1425 if (yytype < YYNTOKENS)
1426 YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep);
1427# else
1428 YYUSE (yyoutput);
1429# endif
1430 switch (yytype)
1431 {
1432 default:
1433 break;
1434 }
1435}
1436
1437
1438/*--------------------------------.
1439| Print this symbol on YYOUTPUT. |
1440`--------------------------------*/
1441
1442#if (defined __STDC__ || defined __C99__FUNC__ \
1443 || defined __cplusplus || defined _MSC_VER)
1444static void
1445yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep)
1446#else
1447static void
1448yy_symbol_print (yyoutput, yytype, yyvaluep)
1449 FILE *yyoutput;
1450 int yytype;
1451 YYSTYPE const * const yyvaluep;
Jari Aaltob80f6442004-07-27 13:29:18 +00001452#endif
Jari Aalto31859422009-01-12 13:36:28 +00001453{
1454 if (yytype < YYNTOKENS)
1455 YYFPRINTF (yyoutput, "token %s (", yytname[yytype]);
1456 else
1457 YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]);
Jari Aaltof73dda02001-11-13 17:56:06 +00001458
Jari Aalto31859422009-01-12 13:36:28 +00001459 yy_symbol_value_print (yyoutput, yytype, yyvaluep);
1460 YYFPRINTF (yyoutput, ")");
1461}
Jari Aaltof73dda02001-11-13 17:56:06 +00001462
Jari Aalto31859422009-01-12 13:36:28 +00001463/*------------------------------------------------------------------.
1464| yy_stack_print -- Print the state stack from its BOTTOM up to its |
1465| TOP (included). |
1466`------------------------------------------------------------------*/
Jari Aaltof73dda02001-11-13 17:56:06 +00001467
Jari Aalto31859422009-01-12 13:36:28 +00001468#if (defined __STDC__ || defined __C99__FUNC__ \
1469 || defined __cplusplus || defined _MSC_VER)
1470static void
1471yy_stack_print (yytype_int16 *bottom, yytype_int16 *top)
1472#else
1473static void
1474yy_stack_print (bottom, top)
1475 yytype_int16 *bottom;
1476 yytype_int16 *top;
Jari Aaltob80f6442004-07-27 13:29:18 +00001477#endif
Jari Aalto31859422009-01-12 13:36:28 +00001478{
1479 YYFPRINTF (stderr, "Stack now");
1480 for (; bottom <= top; ++bottom)
1481 YYFPRINTF (stderr, " %d", *bottom);
1482 YYFPRINTF (stderr, "\n");
1483}
Jari Aaltof73dda02001-11-13 17:56:06 +00001484
Jari Aalto31859422009-01-12 13:36:28 +00001485# define YY_STACK_PRINT(Bottom, Top) \
1486do { \
1487 if (yydebug) \
1488 yy_stack_print ((Bottom), (Top)); \
1489} while (YYID (0))
Jari Aaltof73dda02001-11-13 17:56:06 +00001490
Jari Aalto31859422009-01-12 13:36:28 +00001491
1492/*------------------------------------------------.
1493| Report that the YYRULE is going to be reduced. |
1494`------------------------------------------------*/
1495
1496#if (defined __STDC__ || defined __C99__FUNC__ \
1497 || defined __cplusplus || defined _MSC_VER)
1498static void
1499yy_reduce_print (YYSTYPE *yyvsp, int yyrule)
1500#else
1501static void
1502yy_reduce_print (yyvsp, yyrule)
1503 YYSTYPE *yyvsp;
1504 int yyrule;
Jari Aaltob80f6442004-07-27 13:29:18 +00001505#endif
Jari Aalto31859422009-01-12 13:36:28 +00001506{
1507 int yynrhs = yyr2[yyrule];
1508 int yyi;
1509 unsigned long int yylno = yyrline[yyrule];
1510 YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n",
1511 yyrule - 1, yylno);
1512 /* The symbols being reduced. */
1513 for (yyi = 0; yyi < yynrhs; yyi++)
1514 {
1515 fprintf (stderr, " $%d = ", yyi + 1);
1516 yy_symbol_print (stderr, yyrhs[yyprhs[yyrule] + yyi],
1517 &(yyvsp[(yyi + 1) - (yynrhs)])
1518 );
1519 fprintf (stderr, "\n");
1520 }
1521}
Jari Aaltof73dda02001-11-13 17:56:06 +00001522
Jari Aalto31859422009-01-12 13:36:28 +00001523# define YY_REDUCE_PRINT(Rule) \
1524do { \
1525 if (yydebug) \
1526 yy_reduce_print (yyvsp, Rule); \
1527} while (YYID (0))
Jari Aaltob80f6442004-07-27 13:29:18 +00001528
Jari Aalto31859422009-01-12 13:36:28 +00001529/* Nonzero means print parse trace. It is left uninitialized so that
1530 multiple parsers can coexist. */
1531int yydebug;
1532#else /* !YYDEBUG */
1533# define YYDPRINTF(Args)
1534# define YY_SYMBOL_PRINT(Title, Type, Value, Location)
1535# define YY_STACK_PRINT(Bottom, Top)
1536# define YY_REDUCE_PRINT(Rule)
1537#endif /* !YYDEBUG */
1538
1539
1540/* YYINITDEPTH -- initial size of the parser's stacks. */
Jari Aaltof73dda02001-11-13 17:56:06 +00001541#ifndef YYINITDEPTH
Jari Aalto31859422009-01-12 13:36:28 +00001542# define YYINITDEPTH 200
Jari Aaltof73dda02001-11-13 17:56:06 +00001543#endif
1544
Jari Aalto31859422009-01-12 13:36:28 +00001545/* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
1546 if the built-in stack extension method is used).
Jari Aaltof73dda02001-11-13 17:56:06 +00001547
Jari Aalto31859422009-01-12 13:36:28 +00001548 Do not make this value too large; the results are undefined if
1549 YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH)
1550 evaluated with infinite-precision integer arithmetic. */
Jari Aaltof73dda02001-11-13 17:56:06 +00001551
1552#ifndef YYMAXDEPTH
Jari Aalto31859422009-01-12 13:36:28 +00001553# define YYMAXDEPTH 10000
Jari Aalto726f6381996-08-26 18:22:31 +00001554#endif
Jari Aalto31859422009-01-12 13:36:28 +00001555
Jari Aaltof73dda02001-11-13 17:56:06 +00001556
Jari Aaltob80f6442004-07-27 13:29:18 +00001557
Jari Aalto31859422009-01-12 13:36:28 +00001558#if YYERROR_VERBOSE
Jari Aaltof73dda02001-11-13 17:56:06 +00001559
Jari Aalto31859422009-01-12 13:36:28 +00001560# ifndef yystrlen
1561# if defined __GLIBC__ && defined _STRING_H
1562# define yystrlen strlen
1563# else
1564/* Return the length of YYSTR. */
1565#if (defined __STDC__ || defined __C99__FUNC__ \
1566 || defined __cplusplus || defined _MSC_VER)
1567static YYSIZE_T
1568yystrlen (const char *yystr)
Jari Aalto7117c2d2002-07-17 14:10:11 +00001569#else
Jari Aalto31859422009-01-12 13:36:28 +00001570static YYSIZE_T
1571yystrlen (yystr)
1572 const char *yystr;
1573#endif
1574{
1575 YYSIZE_T yylen;
1576 for (yylen = 0; yystr[yylen]; yylen++)
1577 continue;
1578 return yylen;
1579}
1580# endif
1581# endif
1582
1583# ifndef yystpcpy
1584# if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
1585# define yystpcpy stpcpy
1586# else
1587/* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
1588 YYDEST. */
1589#if (defined __STDC__ || defined __C99__FUNC__ \
1590 || defined __cplusplus || defined _MSC_VER)
1591static char *
1592yystpcpy (char *yydest, const char *yysrc)
1593#else
1594static char *
1595yystpcpy (yydest, yysrc)
1596 char *yydest;
1597 const char *yysrc;
1598#endif
1599{
1600 char *yyd = yydest;
1601 const char *yys = yysrc;
1602
1603 while ((*yyd++ = *yys++) != '\0')
1604 continue;
1605
1606 return yyd - 1;
1607}
1608# endif
1609# endif
1610
1611# ifndef yytnamerr
1612/* Copy to YYRES the contents of YYSTR after stripping away unnecessary
1613 quotes and backslashes, so that it's suitable for yyerror. The
1614 heuristic is that double-quoting is unnecessary unless the string
1615 contains an apostrophe, a comma, or backslash (other than
1616 backslash-backslash). YYSTR is taken from yytname. If YYRES is
1617 null, do not copy; instead, return the length of what the result
1618 would have been. */
1619static YYSIZE_T
1620yytnamerr (char *yyres, const char *yystr)
1621{
1622 if (*yystr == '"')
1623 {
1624 YYSIZE_T yyn = 0;
1625 char const *yyp = yystr;
1626
1627 for (;;)
1628 switch (*++yyp)
1629 {
1630 case '\'':
1631 case ',':
1632 goto do_not_strip_quotes;
1633
1634 case '\\':
1635 if (*++yyp != '\\')
1636 goto do_not_strip_quotes;
1637 /* Fall through. */
1638 default:
1639 if (yyres)
1640 yyres[yyn] = *yyp;
1641 yyn++;
1642 break;
1643
1644 case '"':
1645 if (yyres)
1646 yyres[yyn] = '\0';
1647 return yyn;
1648 }
1649 do_not_strip_quotes: ;
1650 }
1651
1652 if (! yyres)
1653 return yystrlen (yystr);
1654
1655 return yystpcpy (yyres, yystr) - yyres;
1656}
1657# endif
1658
1659/* Copy into YYRESULT an error message about the unexpected token
1660 YYCHAR while in state YYSTATE. Return the number of bytes copied,
1661 including the terminating null byte. If YYRESULT is null, do not
1662 copy anything; just return the number of bytes that would be
1663 copied. As a special case, return 0 if an ordinary "syntax error"
1664 message will do. Return YYSIZE_MAXIMUM if overflow occurs during
1665 size calculation. */
1666static YYSIZE_T
1667yysyntax_error (char *yyresult, int yystate, int yychar)
1668{
1669 int yyn = yypact[yystate];
1670
1671 if (! (YYPACT_NINF < yyn && yyn <= YYLAST))
1672 return 0;
1673 else
1674 {
1675 int yytype = YYTRANSLATE (yychar);
1676 YYSIZE_T yysize0 = yytnamerr (0, yytname[yytype]);
1677 YYSIZE_T yysize = yysize0;
1678 YYSIZE_T yysize1;
1679 int yysize_overflow = 0;
1680 enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
1681 char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
1682 int yyx;
1683
1684# if 0
1685 /* This is so xgettext sees the translatable formats that are
1686 constructed on the fly. */
1687 YY_("syntax error, unexpected %s");
1688 YY_("syntax error, unexpected %s, expecting %s");
1689 YY_("syntax error, unexpected %s, expecting %s or %s");
1690 YY_("syntax error, unexpected %s, expecting %s or %s or %s");
1691 YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s");
1692# endif
1693 char *yyfmt;
1694 char const *yyf;
1695 static char const yyunexpected[] = "syntax error, unexpected %s";
1696 static char const yyexpecting[] = ", expecting %s";
1697 static char const yyor[] = " or %s";
1698 char yyformat[sizeof yyunexpected
1699 + sizeof yyexpecting - 1
1700 + ((YYERROR_VERBOSE_ARGS_MAXIMUM - 2)
1701 * (sizeof yyor - 1))];
1702 char const *yyprefix = yyexpecting;
1703
1704 /* Start YYX at -YYN if negative to avoid negative indexes in
1705 YYCHECK. */
1706 int yyxbegin = yyn < 0 ? -yyn : 0;
1707
1708 /* Stay within bounds of both yycheck and yytname. */
1709 int yychecklim = YYLAST - yyn + 1;
1710 int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
1711 int yycount = 1;
1712
1713 yyarg[0] = yytname[yytype];
1714 yyfmt = yystpcpy (yyformat, yyunexpected);
1715
1716 for (yyx = yyxbegin; yyx < yyxend; ++yyx)
1717 if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
1718 {
1719 if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
1720 {
1721 yycount = 1;
1722 yysize = yysize0;
1723 yyformat[sizeof yyunexpected - 1] = '\0';
1724 break;
1725 }
1726 yyarg[yycount++] = yytname[yyx];
1727 yysize1 = yysize + yytnamerr (0, yytname[yyx]);
1728 yysize_overflow |= (yysize1 < yysize);
1729 yysize = yysize1;
1730 yyfmt = yystpcpy (yyfmt, yyprefix);
1731 yyprefix = yyor;
1732 }
1733
1734 yyf = YY_(yyformat);
1735 yysize1 = yysize + yystrlen (yyf);
1736 yysize_overflow |= (yysize1 < yysize);
1737 yysize = yysize1;
1738
1739 if (yysize_overflow)
1740 return YYSIZE_MAXIMUM;
1741
1742 if (yyresult)
1743 {
1744 /* Avoid sprintf, as that infringes on the user's name space.
1745 Don't have undefined behavior even if the translation
1746 produced a string with the wrong number of "%s"s. */
1747 char *yyp = yyresult;
1748 int yyi = 0;
1749 while ((*yyp = *yyf) != '\0')
1750 {
1751 if (*yyp == '%' && yyf[1] == 's' && yyi < yycount)
1752 {
1753 yyp += yytnamerr (yyp, yyarg[yyi++]);
1754 yyf += 2;
1755 }
1756 else
1757 {
1758 yyp++;
1759 yyf++;
1760 }
1761 }
1762 }
1763 return yysize;
1764 }
1765}
1766#endif /* YYERROR_VERBOSE */
1767
1768
1769/*-----------------------------------------------.
1770| Release the memory associated to this symbol. |
1771`-----------------------------------------------*/
1772
1773/*ARGSUSED*/
1774#if (defined __STDC__ || defined __C99__FUNC__ \
1775 || defined __cplusplus || defined _MSC_VER)
1776static void
1777yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep)
1778#else
1779static void
1780yydestruct (yymsg, yytype, yyvaluep)
1781 const char *yymsg;
1782 int yytype;
1783 YYSTYPE *yyvaluep;
1784#endif
1785{
1786 YYUSE (yyvaluep);
1787
1788 if (!yymsg)
1789 yymsg = "Deleting";
1790 YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
1791
1792 switch (yytype)
1793 {
1794
1795 default:
1796 break;
1797 }
1798}
1799
1800
1801/* Prevent warnings from -Wmissing-prototypes. */
1802
1803#ifdef YYPARSE_PARAM
1804#if defined __STDC__ || defined __cplusplus
1805int yyparse (void *YYPARSE_PARAM);
1806#else
1807int yyparse ();
1808#endif
1809#else /* ! YYPARSE_PARAM */
1810#if defined __STDC__ || defined __cplusplus
Jari Aaltob80f6442004-07-27 13:29:18 +00001811int yyparse (void);
Jari Aaltof73dda02001-11-13 17:56:06 +00001812#else
Jari Aalto31859422009-01-12 13:36:28 +00001813int yyparse ();
Jari Aaltof73dda02001-11-13 17:56:06 +00001814#endif
Jari Aalto31859422009-01-12 13:36:28 +00001815#endif /* ! YYPARSE_PARAM */
Jari Aaltof73dda02001-11-13 17:56:06 +00001816
Jari Aaltof73dda02001-11-13 17:56:06 +00001817
Jari Aalto31859422009-01-12 13:36:28 +00001818
1819/* The look-ahead symbol. */
1820int yychar;
1821
1822/* The semantic value of the look-ahead symbol. */
1823YYSTYPE yylval;
1824
1825/* Number of syntax errors so far. */
1826int yynerrs;
1827
1828
1829
1830/*----------.
1831| yyparse. |
1832`----------*/
1833
1834#ifdef YYPARSE_PARAM
1835#if (defined __STDC__ || defined __C99__FUNC__ \
1836 || defined __cplusplus || defined _MSC_VER)
1837int
1838yyparse (void *YYPARSE_PARAM)
1839#else
1840int
1841yyparse (YYPARSE_PARAM)
1842 void *YYPARSE_PARAM;
1843#endif
1844#else /* ! YYPARSE_PARAM */
1845#if (defined __STDC__ || defined __C99__FUNC__ \
1846 || defined __cplusplus || defined _MSC_VER)
1847int
1848yyparse (void)
1849#else
1850int
1851yyparse ()
1852
Jari Aaltob80f6442004-07-27 13:29:18 +00001853#endif
Jari Aaltof73dda02001-11-13 17:56:06 +00001854#endif
Jari Aalto31859422009-01-12 13:36:28 +00001855{
1856
1857 int yystate;
1858 int yyn;
1859 int yyresult;
1860 /* Number of tokens to shift before error messages enabled. */
1861 int yyerrstatus;
1862 /* Look-ahead token as an internal (translated) token number. */
1863 int yytoken = 0;
1864#if YYERROR_VERBOSE
1865 /* Buffer for error messages, and its allocated size. */
1866 char yymsgbuf[128];
1867 char *yymsg = yymsgbuf;
1868 YYSIZE_T yymsg_alloc = sizeof yymsgbuf;
Jari Aaltob80f6442004-07-27 13:29:18 +00001869#endif
Jari Aaltof73dda02001-11-13 17:56:06 +00001870
Jari Aalto31859422009-01-12 13:36:28 +00001871 /* Three stacks and their tools:
1872 `yyss': related to states,
1873 `yyvs': related to semantic values,
1874 `yyls': related to locations.
1875
1876 Refer to the stacks thru separate pointers, to allow yyoverflow
1877 to reallocate them elsewhere. */
1878
1879 /* The state stack. */
1880 yytype_int16 yyssa[YYINITDEPTH];
1881 yytype_int16 *yyss = yyssa;
1882 yytype_int16 *yyssp;
1883
1884 /* The semantic value stack. */
1885 YYSTYPE yyvsa[YYINITDEPTH];
1886 YYSTYPE *yyvs = yyvsa;
1887 YYSTYPE *yyvsp;
1888
1889
1890
1891#define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N))
1892
1893 YYSIZE_T yystacksize = YYINITDEPTH;
1894
1895 /* The variables used to return semantic value and location from the
1896 action routines. */
1897 YYSTYPE yyval;
1898
1899
1900 /* The number of symbols on the RHS of the reduced rule.
1901 Keep to zero when no symbol should be popped. */
1902 int yylen = 0;
1903
1904 YYDPRINTF ((stderr, "Starting parse\n"));
1905
Jari Aaltof73dda02001-11-13 17:56:06 +00001906 yystate = 0;
1907 yyerrstatus = 0;
1908 yynerrs = 0;
1909 yychar = YYEMPTY; /* Cause a token to be read. */
1910
1911 /* Initialize stack pointers.
1912 Waste one element of value and location stack
1913 so that they stay on the same level as the state stack.
1914 The wasted elements are never initialized. */
1915
Jari Aalto31859422009-01-12 13:36:28 +00001916 yyssp = yyss;
Jari Aaltof73dda02001-11-13 17:56:06 +00001917 yyvsp = yyvs;
Jari Aaltof73dda02001-11-13 17:56:06 +00001918
Jari Aalto31859422009-01-12 13:36:28 +00001919 goto yysetstate;
Jari Aaltof73dda02001-11-13 17:56:06 +00001920
Jari Aalto31859422009-01-12 13:36:28 +00001921/*------------------------------------------------------------.
1922| yynewstate -- Push a new state, which is found in yystate. |
1923`------------------------------------------------------------*/
1924 yynewstate:
1925 /* In all cases, when you get here, the value and location stacks
1926 have just been pushed. So pushing a state here evens the stacks. */
1927 yyssp++;
Jari Aaltof73dda02001-11-13 17:56:06 +00001928
Jari Aalto31859422009-01-12 13:36:28 +00001929 yysetstate:
1930 *yyssp = yystate;
1931
1932 if (yyss + yystacksize - 1 <= yyssp)
Jari Aaltof73dda02001-11-13 17:56:06 +00001933 {
Jari Aaltof73dda02001-11-13 17:56:06 +00001934 /* Get the current used size of the three stacks, in elements. */
Jari Aalto31859422009-01-12 13:36:28 +00001935 YYSIZE_T yysize = yyssp - yyss + 1;
Jari Aaltof73dda02001-11-13 17:56:06 +00001936
1937#ifdef yyoverflow
Jari Aalto31859422009-01-12 13:36:28 +00001938 {
1939 /* Give user a chance to reallocate the stack. Use copies of
1940 these so that the &'s don't force the real ones into
1941 memory. */
1942 YYSTYPE *yyvs1 = yyvs;
1943 yytype_int16 *yyss1 = yyss;
Jari Aaltof73dda02001-11-13 17:56:06 +00001944
Jari Aalto31859422009-01-12 13:36:28 +00001945
1946 /* Each stack pointer address is followed by the size of the
1947 data in use in that stack, in bytes. This used to be a
1948 conditional around just the two extra args, but that might
1949 be undefined if yyoverflow is a macro. */
1950 yyoverflow (YY_("memory exhausted"),
1951 &yyss1, yysize * sizeof (*yyssp),
1952 &yyvs1, yysize * sizeof (*yyvsp),
1953
1954 &yystacksize);
1955
1956 yyss = yyss1;
1957 yyvs = yyvs1;
1958 }
Jari Aaltof73dda02001-11-13 17:56:06 +00001959#else /* no yyoverflow */
Jari Aalto31859422009-01-12 13:36:28 +00001960# ifndef YYSTACK_RELOCATE
1961 goto yyexhaustedlab;
1962# else
Jari Aaltof73dda02001-11-13 17:56:06 +00001963 /* Extend the stack our own way. */
Jari Aalto31859422009-01-12 13:36:28 +00001964 if (YYMAXDEPTH <= yystacksize)
1965 goto yyexhaustedlab;
Jari Aaltof73dda02001-11-13 17:56:06 +00001966 yystacksize *= 2;
Jari Aalto31859422009-01-12 13:36:28 +00001967 if (YYMAXDEPTH < yystacksize)
Jari Aaltof73dda02001-11-13 17:56:06 +00001968 yystacksize = YYMAXDEPTH;
Jari Aalto31859422009-01-12 13:36:28 +00001969
1970 {
1971 yytype_int16 *yyss1 = yyss;
1972 union yyalloc *yyptr =
1973 (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
1974 if (! yyptr)
1975 goto yyexhaustedlab;
1976 YYSTACK_RELOCATE (yyss);
1977 YYSTACK_RELOCATE (yyvs);
1978
1979# undef YYSTACK_RELOCATE
1980 if (yyss1 != yyssa)
1981 YYSTACK_FREE (yyss1);
1982 }
1983# endif
Jari Aaltof73dda02001-11-13 17:56:06 +00001984#endif /* no yyoverflow */
1985
Jari Aalto31859422009-01-12 13:36:28 +00001986 yyssp = yyss + yysize - 1;
1987 yyvsp = yyvs + yysize - 1;
Jari Aaltof73dda02001-11-13 17:56:06 +00001988
Jari Aaltof73dda02001-11-13 17:56:06 +00001989
Jari Aalto31859422009-01-12 13:36:28 +00001990 YYDPRINTF ((stderr, "Stack size increased to %lu\n",
1991 (unsigned long int) yystacksize));
1992
1993 if (yyss + yystacksize - 1 <= yyssp)
Jari Aaltof73dda02001-11-13 17:56:06 +00001994 YYABORT;
1995 }
1996
Jari Aalto31859422009-01-12 13:36:28 +00001997 YYDPRINTF ((stderr, "Entering state %d\n", yystate));
Jari Aaltof73dda02001-11-13 17:56:06 +00001998
1999 goto yybackup;
Jari Aaltof73dda02001-11-13 17:56:06 +00002000
Jari Aalto31859422009-01-12 13:36:28 +00002001/*-----------.
2002| yybackup. |
2003`-----------*/
2004yybackup:
Jari Aaltof73dda02001-11-13 17:56:06 +00002005
Jari Aalto31859422009-01-12 13:36:28 +00002006 /* Do appropriate processing given the current state. Read a
2007 look-ahead token if we need one and don't already have one. */
Jari Aaltof73dda02001-11-13 17:56:06 +00002008
Jari Aalto31859422009-01-12 13:36:28 +00002009 /* First try to decide what to do without reference to look-ahead token. */
Jari Aaltof73dda02001-11-13 17:56:06 +00002010 yyn = yypact[yystate];
Jari Aalto31859422009-01-12 13:36:28 +00002011 if (yyn == YYPACT_NINF)
Jari Aaltof73dda02001-11-13 17:56:06 +00002012 goto yydefault;
2013
Jari Aalto31859422009-01-12 13:36:28 +00002014 /* Not known => get a look-ahead token if don't already have one. */
Jari Aaltof73dda02001-11-13 17:56:06 +00002015
Jari Aalto31859422009-01-12 13:36:28 +00002016 /* YYCHAR is either YYEMPTY or YYEOF or a valid look-ahead symbol. */
Jari Aaltof73dda02001-11-13 17:56:06 +00002017 if (yychar == YYEMPTY)
2018 {
Jari Aalto31859422009-01-12 13:36:28 +00002019 YYDPRINTF ((stderr, "Reading a token: "));
Jari Aaltof73dda02001-11-13 17:56:06 +00002020 yychar = YYLEX;
2021 }
2022
Jari Aalto31859422009-01-12 13:36:28 +00002023 if (yychar <= YYEOF)
Jari Aaltof73dda02001-11-13 17:56:06 +00002024 {
Jari Aalto31859422009-01-12 13:36:28 +00002025 yychar = yytoken = YYEOF;
2026 YYDPRINTF ((stderr, "Now at end of input.\n"));
Jari Aaltof73dda02001-11-13 17:56:06 +00002027 }
2028 else
2029 {
Jari Aalto31859422009-01-12 13:36:28 +00002030 yytoken = YYTRANSLATE (yychar);
2031 YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
Jari Aaltof73dda02001-11-13 17:56:06 +00002032 }
2033
Jari Aalto31859422009-01-12 13:36:28 +00002034 /* If the proper action on seeing token YYTOKEN is to reduce or to
2035 detect an error, take that action. */
2036 yyn += yytoken;
2037 if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
Jari Aaltof73dda02001-11-13 17:56:06 +00002038 goto yydefault;
Jari Aaltof73dda02001-11-13 17:56:06 +00002039 yyn = yytable[yyn];
Jari Aalto31859422009-01-12 13:36:28 +00002040 if (yyn <= 0)
Jari Aaltof73dda02001-11-13 17:56:06 +00002041 {
Jari Aalto31859422009-01-12 13:36:28 +00002042 if (yyn == 0 || yyn == YYTABLE_NINF)
Jari Aaltof73dda02001-11-13 17:56:06 +00002043 goto yyerrlab;
2044 yyn = -yyn;
2045 goto yyreduce;
2046 }
Jari Aaltof73dda02001-11-13 17:56:06 +00002047
2048 if (yyn == YYFINAL)
2049 YYACCEPT;
2050
Jari Aalto31859422009-01-12 13:36:28 +00002051 /* Count tokens shifted since error; after three, turn off error
2052 status. */
2053 if (yyerrstatus)
2054 yyerrstatus--;
Jari Aaltob80f6442004-07-27 13:29:18 +00002055
Jari Aalto31859422009-01-12 13:36:28 +00002056 /* Shift the look-ahead token. */
2057 YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
Jari Aaltof73dda02001-11-13 17:56:06 +00002058
Jari Aalto31859422009-01-12 13:36:28 +00002059 /* Discard the shifted token unless it is eof. */
Jari Aaltof73dda02001-11-13 17:56:06 +00002060 if (yychar != YYEOF)
2061 yychar = YYEMPTY;
2062
Jari Aaltof73dda02001-11-13 17:56:06 +00002063 yystate = yyn;
Jari Aalto31859422009-01-12 13:36:28 +00002064 *++yyvsp = yylval;
2065
Jari Aaltof73dda02001-11-13 17:56:06 +00002066 goto yynewstate;
2067
Jari Aaltob80f6442004-07-27 13:29:18 +00002068
Jari Aalto31859422009-01-12 13:36:28 +00002069/*-----------------------------------------------------------.
2070| yydefault -- do the default action for the current state. |
2071`-----------------------------------------------------------*/
2072yydefault:
Jari Aaltof73dda02001-11-13 17:56:06 +00002073 yyn = yydefact[yystate];
2074 if (yyn == 0)
2075 goto yyerrlab;
Jari Aalto31859422009-01-12 13:36:28 +00002076 goto yyreduce;
Jari Aaltof73dda02001-11-13 17:56:06 +00002077
Jari Aalto31859422009-01-12 13:36:28 +00002078
2079/*-----------------------------.
2080| yyreduce -- Do a reduction. |
2081`-----------------------------*/
Jari Aaltof73dda02001-11-13 17:56:06 +00002082yyreduce:
Jari Aalto31859422009-01-12 13:36:28 +00002083 /* yyn is the number of a rule to reduce with. */
Jari Aaltof73dda02001-11-13 17:56:06 +00002084 yylen = yyr2[yyn];
Jari Aaltof73dda02001-11-13 17:56:06 +00002085
Jari Aalto31859422009-01-12 13:36:28 +00002086 /* If YYLEN is nonzero, implement the default value of the action:
2087 `$$ = $1'.
2088
2089 Otherwise, the following line sets YYVAL to garbage.
2090 This behavior is undocumented and Bison
2091 users should not rely upon it. Assigning to YYVAL
2092 unconditionally makes the parser a bit smaller, and it avoids a
2093 GCC warning that YYVAL may be used uninitialized. */
2094 yyval = yyvsp[1-yylen];
2095
2096
2097 YY_REDUCE_PRINT (yyn);
2098 switch (yyn)
Jari Aalto7117c2d2002-07-17 14:10:11 +00002099 {
Jari Aalto31859422009-01-12 13:36:28 +00002100 case 2:
Chet Ramey80b4d712014-10-05 19:12:20 -04002101#line 383 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Jari Aalto31859422009-01-12 13:36:28 +00002102 {
Jari Aaltof73dda02001-11-13 17:56:06 +00002103 /* Case of regular command. Discard the error
2104 safety net,and return the command just parsed. */
Jari Aalto31859422009-01-12 13:36:28 +00002105 global_command = (yyvsp[(1) - (2)].command);
Jari Aaltof73dda02001-11-13 17:56:06 +00002106 eof_encountered = 0;
Jari Aalto7117c2d2002-07-17 14:10:11 +00002107 /* discard_parser_constructs (0); */
Jari Aalto31859422009-01-12 13:36:28 +00002108 if (parser_state & PST_CMDSUBST)
2109 parser_state |= PST_EOFTOKEN;
Jari Aaltof73dda02001-11-13 17:56:06 +00002110 YYACCEPT;
Jari Aalto31859422009-01-12 13:36:28 +00002111 }
2112 break;
2113
2114 case 3:
Chet Ramey80b4d712014-10-05 19:12:20 -04002115#line 394 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Jari Aalto31859422009-01-12 13:36:28 +00002116 {
Jari Aaltof73dda02001-11-13 17:56:06 +00002117 /* Case of regular command, but not a very
2118 interesting one. Return a NULL command. */
2119 global_command = (COMMAND *)NULL;
Jari Aalto31859422009-01-12 13:36:28 +00002120 if (parser_state & PST_CMDSUBST)
2121 parser_state |= PST_EOFTOKEN;
Jari Aaltof73dda02001-11-13 17:56:06 +00002122 YYACCEPT;
Jari Aalto31859422009-01-12 13:36:28 +00002123 }
2124 break;
2125
2126 case 4:
Chet Ramey80b4d712014-10-05 19:12:20 -04002127#line 403 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Jari Aalto31859422009-01-12 13:36:28 +00002128 {
Jari Aaltof73dda02001-11-13 17:56:06 +00002129 /* Error during parsing. Return NULL command. */
2130 global_command = (COMMAND *)NULL;
2131 eof_encountered = 0;
Jari Aalto7117c2d2002-07-17 14:10:11 +00002132 /* discard_parser_constructs (1); */
Jari Aalto31859422009-01-12 13:36:28 +00002133 if (interactive && parse_and_execute_level == 0)
Jari Aaltof73dda02001-11-13 17:56:06 +00002134 {
2135 YYACCEPT;
2136 }
2137 else
2138 {
2139 YYABORT;
2140 }
Jari Aalto31859422009-01-12 13:36:28 +00002141 }
2142 break;
2143
2144 case 5:
Chet Ramey80b4d712014-10-05 19:12:20 -04002145#line 418 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Jari Aalto31859422009-01-12 13:36:28 +00002146 {
Jari Aaltof73dda02001-11-13 17:56:06 +00002147 /* Case of EOF seen by itself. Do ignoreeof or
2148 not. */
2149 global_command = (COMMAND *)NULL;
2150 handle_eof_input_unit ();
2151 YYACCEPT;
Jari Aalto31859422009-01-12 13:36:28 +00002152 }
2153 break;
2154
2155 case 6:
Chet Ramey80b4d712014-10-05 19:12:20 -04002156#line 428 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Jari Aalto31859422009-01-12 13:36:28 +00002157 { (yyval.word_list) = make_word_list ((yyvsp[(1) - (1)].word), (WORD_LIST *)NULL); }
2158 break;
2159
2160 case 7:
Chet Ramey80b4d712014-10-05 19:12:20 -04002161#line 430 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Jari Aalto31859422009-01-12 13:36:28 +00002162 { (yyval.word_list) = make_word_list ((yyvsp[(2) - (2)].word), (yyvsp[(1) - (2)].word_list)); }
2163 break;
2164
2165 case 8:
Chet Ramey80b4d712014-10-05 19:12:20 -04002166#line 434 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Jari Aalto31859422009-01-12 13:36:28 +00002167 {
Chet Ramey00018032011-11-21 20:51:19 -05002168 source.dest = 1;
Jari Aalto31859422009-01-12 13:36:28 +00002169 redir.filename = (yyvsp[(2) - (2)].word);
Chet Ramey00018032011-11-21 20:51:19 -05002170 (yyval.redirect) = make_redirection (source, r_output_direction, redir, 0);
Jari Aalto31859422009-01-12 13:36:28 +00002171 }
2172 break;
2173
2174 case 9:
Chet Ramey80b4d712014-10-05 19:12:20 -04002175#line 440 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Jari Aalto31859422009-01-12 13:36:28 +00002176 {
Chet Ramey00018032011-11-21 20:51:19 -05002177 source.dest = 0;
Jari Aalto31859422009-01-12 13:36:28 +00002178 redir.filename = (yyvsp[(2) - (2)].word);
Chet Ramey00018032011-11-21 20:51:19 -05002179 (yyval.redirect) = make_redirection (source, r_input_direction, redir, 0);
Jari Aalto31859422009-01-12 13:36:28 +00002180 }
2181 break;
2182
2183 case 10:
Chet Ramey80b4d712014-10-05 19:12:20 -04002184#line 446 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Jari Aalto31859422009-01-12 13:36:28 +00002185 {
Chet Ramey00018032011-11-21 20:51:19 -05002186 source.dest = (yyvsp[(1) - (3)].number);
Jari Aalto31859422009-01-12 13:36:28 +00002187 redir.filename = (yyvsp[(3) - (3)].word);
Chet Ramey00018032011-11-21 20:51:19 -05002188 (yyval.redirect) = make_redirection (source, r_output_direction, redir, 0);
Jari Aalto31859422009-01-12 13:36:28 +00002189 }
2190 break;
2191
2192 case 11:
Chet Ramey80b4d712014-10-05 19:12:20 -04002193#line 452 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Jari Aalto31859422009-01-12 13:36:28 +00002194 {
Chet Ramey00018032011-11-21 20:51:19 -05002195 source.dest = (yyvsp[(1) - (3)].number);
Jari Aalto31859422009-01-12 13:36:28 +00002196 redir.filename = (yyvsp[(3) - (3)].word);
Chet Ramey00018032011-11-21 20:51:19 -05002197 (yyval.redirect) = make_redirection (source, r_input_direction, redir, 0);
Jari Aalto31859422009-01-12 13:36:28 +00002198 }
2199 break;
2200
2201 case 12:
Chet Ramey80b4d712014-10-05 19:12:20 -04002202#line 458 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Jari Aalto31859422009-01-12 13:36:28 +00002203 {
Chet Ramey00018032011-11-21 20:51:19 -05002204 source.filename = (yyvsp[(1) - (3)].word);
2205 redir.filename = (yyvsp[(3) - (3)].word);
2206 (yyval.redirect) = make_redirection (source, r_output_direction, redir, REDIR_VARASSIGN);
Jari Aalto31859422009-01-12 13:36:28 +00002207 }
2208 break;
2209
2210 case 13:
Chet Ramey80b4d712014-10-05 19:12:20 -04002211#line 464 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Jari Aalto31859422009-01-12 13:36:28 +00002212 {
Chet Ramey00018032011-11-21 20:51:19 -05002213 source.filename = (yyvsp[(1) - (3)].word);
Jari Aalto31859422009-01-12 13:36:28 +00002214 redir.filename = (yyvsp[(3) - (3)].word);
Chet Ramey00018032011-11-21 20:51:19 -05002215 (yyval.redirect) = make_redirection (source, r_input_direction, redir, REDIR_VARASSIGN);
Jari Aalto31859422009-01-12 13:36:28 +00002216 }
2217 break;
2218
2219 case 14:
Chet Ramey80b4d712014-10-05 19:12:20 -04002220#line 470 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Jari Aalto31859422009-01-12 13:36:28 +00002221 {
Chet Ramey00018032011-11-21 20:51:19 -05002222 source.dest = 1;
Jari Aalto31859422009-01-12 13:36:28 +00002223 redir.filename = (yyvsp[(2) - (2)].word);
Chet Ramey00018032011-11-21 20:51:19 -05002224 (yyval.redirect) = make_redirection (source, r_appending_to, redir, 0);
Jari Aalto31859422009-01-12 13:36:28 +00002225 }
2226 break;
2227
2228 case 15:
Chet Ramey80b4d712014-10-05 19:12:20 -04002229#line 476 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Jari Aalto31859422009-01-12 13:36:28 +00002230 {
Chet Ramey00018032011-11-21 20:51:19 -05002231 source.dest = (yyvsp[(1) - (3)].number);
Jari Aalto31859422009-01-12 13:36:28 +00002232 redir.filename = (yyvsp[(3) - (3)].word);
Chet Ramey00018032011-11-21 20:51:19 -05002233 (yyval.redirect) = make_redirection (source, r_appending_to, redir, 0);
Jari Aalto31859422009-01-12 13:36:28 +00002234 }
2235 break;
2236
2237 case 16:
Chet Ramey80b4d712014-10-05 19:12:20 -04002238#line 482 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Jari Aalto31859422009-01-12 13:36:28 +00002239 {
Chet Ramey00018032011-11-21 20:51:19 -05002240 source.filename = (yyvsp[(1) - (3)].word);
2241 redir.filename = (yyvsp[(3) - (3)].word);
2242 (yyval.redirect) = make_redirection (source, r_appending_to, redir, REDIR_VARASSIGN);
Jari Aalto31859422009-01-12 13:36:28 +00002243 }
2244 break;
2245
2246 case 17:
Chet Ramey80b4d712014-10-05 19:12:20 -04002247#line 488 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Jari Aalto31859422009-01-12 13:36:28 +00002248 {
Chet Ramey00018032011-11-21 20:51:19 -05002249 source.dest = 1;
2250 redir.filename = (yyvsp[(2) - (2)].word);
2251 (yyval.redirect) = make_redirection (source, r_output_force, redir, 0);
Jari Aalto31859422009-01-12 13:36:28 +00002252 }
2253 break;
2254
2255 case 18:
Chet Ramey80b4d712014-10-05 19:12:20 -04002256#line 494 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Jari Aalto31859422009-01-12 13:36:28 +00002257 {
Chet Ramey00018032011-11-21 20:51:19 -05002258 source.dest = (yyvsp[(1) - (3)].number);
2259 redir.filename = (yyvsp[(3) - (3)].word);
2260 (yyval.redirect) = make_redirection (source, r_output_force, redir, 0);
Jari Aalto31859422009-01-12 13:36:28 +00002261 }
2262 break;
2263
2264 case 19:
Chet Ramey80b4d712014-10-05 19:12:20 -04002265#line 500 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Jari Aalto31859422009-01-12 13:36:28 +00002266 {
Chet Ramey00018032011-11-21 20:51:19 -05002267 source.filename = (yyvsp[(1) - (3)].word);
2268 redir.filename = (yyvsp[(3) - (3)].word);
2269 (yyval.redirect) = make_redirection (source, r_output_force, redir, REDIR_VARASSIGN);
Jari Aalto31859422009-01-12 13:36:28 +00002270 }
2271 break;
2272
2273 case 20:
Chet Ramey80b4d712014-10-05 19:12:20 -04002274#line 506 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Jari Aalto31859422009-01-12 13:36:28 +00002275 {
Chet Ramey00018032011-11-21 20:51:19 -05002276 source.dest = 0;
2277 redir.filename = (yyvsp[(2) - (2)].word);
2278 (yyval.redirect) = make_redirection (source, r_input_output, redir, 0);
Jari Aalto31859422009-01-12 13:36:28 +00002279 }
2280 break;
2281
2282 case 21:
Chet Ramey80b4d712014-10-05 19:12:20 -04002283#line 512 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Jari Aalto31859422009-01-12 13:36:28 +00002284 {
Chet Ramey00018032011-11-21 20:51:19 -05002285 source.dest = (yyvsp[(1) - (3)].number);
2286 redir.filename = (yyvsp[(3) - (3)].word);
2287 (yyval.redirect) = make_redirection (source, r_input_output, redir, 0);
Jari Aalto31859422009-01-12 13:36:28 +00002288 }
2289 break;
2290
2291 case 22:
Chet Ramey80b4d712014-10-05 19:12:20 -04002292#line 518 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Jari Aalto31859422009-01-12 13:36:28 +00002293 {
Chet Ramey00018032011-11-21 20:51:19 -05002294 source.filename = (yyvsp[(1) - (3)].word);
2295 redir.filename = (yyvsp[(3) - (3)].word);
2296 (yyval.redirect) = make_redirection (source, r_input_output, redir, REDIR_VARASSIGN);
Jari Aalto31859422009-01-12 13:36:28 +00002297 }
2298 break;
2299
2300 case 23:
Chet Ramey80b4d712014-10-05 19:12:20 -04002301#line 524 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Jari Aalto31859422009-01-12 13:36:28 +00002302 {
Chet Ramey00018032011-11-21 20:51:19 -05002303 source.dest = 0;
2304 redir.filename = (yyvsp[(2) - (2)].word);
2305 (yyval.redirect) = make_redirection (source, r_reading_until, redir, 0);
Chet Ramey90a39f32014-10-02 09:07:21 -04002306 push_heredoc ((yyval.redirect));
Jari Aalto31859422009-01-12 13:36:28 +00002307 }
2308 break;
2309
2310 case 24:
Chet Ramey80b4d712014-10-05 19:12:20 -04002311#line 531 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Jari Aalto31859422009-01-12 13:36:28 +00002312 {
Chet Ramey00018032011-11-21 20:51:19 -05002313 source.dest = (yyvsp[(1) - (3)].number);
2314 redir.filename = (yyvsp[(3) - (3)].word);
2315 (yyval.redirect) = make_redirection (source, r_reading_until, redir, 0);
Chet Ramey90a39f32014-10-02 09:07:21 -04002316 push_heredoc ((yyval.redirect));
Jari Aalto31859422009-01-12 13:36:28 +00002317 }
2318 break;
2319
2320 case 25:
Chet Ramey80b4d712014-10-05 19:12:20 -04002321#line 538 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Jari Aalto31859422009-01-12 13:36:28 +00002322 {
Chet Ramey00018032011-11-21 20:51:19 -05002323 source.filename = (yyvsp[(1) - (3)].word);
Jari Aalto31859422009-01-12 13:36:28 +00002324 redir.filename = (yyvsp[(3) - (3)].word);
Chet Ramey00018032011-11-21 20:51:19 -05002325 (yyval.redirect) = make_redirection (source, r_reading_until, redir, REDIR_VARASSIGN);
Chet Ramey90a39f32014-10-02 09:07:21 -04002326 push_heredoc ((yyval.redirect));
Jari Aalto31859422009-01-12 13:36:28 +00002327 }
2328 break;
2329
2330 case 26:
Chet Ramey80b4d712014-10-05 19:12:20 -04002331#line 545 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Jari Aalto31859422009-01-12 13:36:28 +00002332 {
Chet Ramey00018032011-11-21 20:51:19 -05002333 source.dest = 0;
Jari Aalto31859422009-01-12 13:36:28 +00002334 redir.filename = (yyvsp[(2) - (2)].word);
Chet Ramey00018032011-11-21 20:51:19 -05002335 (yyval.redirect) = make_redirection (source, r_deblank_reading_until, redir, 0);
Chet Ramey90a39f32014-10-02 09:07:21 -04002336 push_heredoc ((yyval.redirect));
Jari Aalto31859422009-01-12 13:36:28 +00002337 }
2338 break;
2339
2340 case 27:
Chet Ramey80b4d712014-10-05 19:12:20 -04002341#line 552 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Jari Aalto31859422009-01-12 13:36:28 +00002342 {
Chet Ramey00018032011-11-21 20:51:19 -05002343 source.dest = (yyvsp[(1) - (3)].number);
Jari Aalto31859422009-01-12 13:36:28 +00002344 redir.filename = (yyvsp[(3) - (3)].word);
Chet Ramey00018032011-11-21 20:51:19 -05002345 (yyval.redirect) = make_redirection (source, r_deblank_reading_until, redir, 0);
Chet Ramey90a39f32014-10-02 09:07:21 -04002346 push_heredoc ((yyval.redirect));
Jari Aalto31859422009-01-12 13:36:28 +00002347 }
2348 break;
2349
2350 case 28:
Chet Ramey80b4d712014-10-05 19:12:20 -04002351#line 559 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Jari Aalto31859422009-01-12 13:36:28 +00002352 {
Chet Ramey00018032011-11-21 20:51:19 -05002353 source.filename = (yyvsp[(1) - (3)].word);
2354 redir.filename = (yyvsp[(3) - (3)].word);
2355 (yyval.redirect) = make_redirection (source, r_deblank_reading_until, redir, REDIR_VARASSIGN);
Chet Ramey90a39f32014-10-02 09:07:21 -04002356 push_heredoc ((yyval.redirect));
Jari Aalto31859422009-01-12 13:36:28 +00002357 }
2358 break;
2359
2360 case 29:
Chet Ramey80b4d712014-10-05 19:12:20 -04002361#line 566 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Jari Aalto31859422009-01-12 13:36:28 +00002362 {
Chet Ramey00018032011-11-21 20:51:19 -05002363 source.dest = 0;
2364 redir.filename = (yyvsp[(2) - (2)].word);
2365 (yyval.redirect) = make_redirection (source, r_reading_string, redir, 0);
Jari Aalto31859422009-01-12 13:36:28 +00002366 }
2367 break;
2368
2369 case 30:
Chet Ramey80b4d712014-10-05 19:12:20 -04002370#line 572 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Jari Aalto31859422009-01-12 13:36:28 +00002371 {
Chet Ramey00018032011-11-21 20:51:19 -05002372 source.dest = (yyvsp[(1) - (3)].number);
2373 redir.filename = (yyvsp[(3) - (3)].word);
2374 (yyval.redirect) = make_redirection (source, r_reading_string, redir, 0);
Jari Aalto31859422009-01-12 13:36:28 +00002375 }
2376 break;
2377
2378 case 31:
Chet Ramey80b4d712014-10-05 19:12:20 -04002379#line 578 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Jari Aalto31859422009-01-12 13:36:28 +00002380 {
Chet Ramey00018032011-11-21 20:51:19 -05002381 source.filename = (yyvsp[(1) - (3)].word);
2382 redir.filename = (yyvsp[(3) - (3)].word);
2383 (yyval.redirect) = make_redirection (source, r_reading_string, redir, REDIR_VARASSIGN);
Jari Aalto31859422009-01-12 13:36:28 +00002384 }
2385 break;
2386
2387 case 32:
Chet Ramey80b4d712014-10-05 19:12:20 -04002388#line 584 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Jari Aalto31859422009-01-12 13:36:28 +00002389 {
Chet Ramey00018032011-11-21 20:51:19 -05002390 source.dest = 0;
2391 redir.dest = (yyvsp[(2) - (2)].number);
2392 (yyval.redirect) = make_redirection (source, r_duplicating_input, redir, 0);
Jari Aalto31859422009-01-12 13:36:28 +00002393 }
2394 break;
2395
2396 case 33:
Chet Ramey80b4d712014-10-05 19:12:20 -04002397#line 590 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Jari Aalto31859422009-01-12 13:36:28 +00002398 {
Chet Ramey00018032011-11-21 20:51:19 -05002399 source.dest = (yyvsp[(1) - (3)].number);
2400 redir.dest = (yyvsp[(3) - (3)].number);
2401 (yyval.redirect) = make_redirection (source, r_duplicating_input, redir, 0);
Jari Aalto31859422009-01-12 13:36:28 +00002402 }
2403 break;
2404
2405 case 34:
Chet Ramey80b4d712014-10-05 19:12:20 -04002406#line 596 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Jari Aalto31859422009-01-12 13:36:28 +00002407 {
Chet Ramey00018032011-11-21 20:51:19 -05002408 source.filename = (yyvsp[(1) - (3)].word);
2409 redir.dest = (yyvsp[(3) - (3)].number);
2410 (yyval.redirect) = make_redirection (source, r_duplicating_input, redir, REDIR_VARASSIGN);
Jari Aalto31859422009-01-12 13:36:28 +00002411 }
2412 break;
2413
2414 case 35:
Chet Ramey80b4d712014-10-05 19:12:20 -04002415#line 602 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Jari Aalto31859422009-01-12 13:36:28 +00002416 {
Chet Ramey00018032011-11-21 20:51:19 -05002417 source.dest = 1;
2418 redir.dest = (yyvsp[(2) - (2)].number);
2419 (yyval.redirect) = make_redirection (source, r_duplicating_output, redir, 0);
Jari Aalto31859422009-01-12 13:36:28 +00002420 }
2421 break;
2422
2423 case 36:
Chet Ramey80b4d712014-10-05 19:12:20 -04002424#line 608 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Jari Aalto31859422009-01-12 13:36:28 +00002425 {
Chet Ramey00018032011-11-21 20:51:19 -05002426 source.dest = (yyvsp[(1) - (3)].number);
2427 redir.dest = (yyvsp[(3) - (3)].number);
2428 (yyval.redirect) = make_redirection (source, r_duplicating_output, redir, 0);
Jari Aalto31859422009-01-12 13:36:28 +00002429 }
2430 break;
2431
2432 case 37:
Chet Ramey80b4d712014-10-05 19:12:20 -04002433#line 614 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Jari Aalto31859422009-01-12 13:36:28 +00002434 {
Chet Ramey00018032011-11-21 20:51:19 -05002435 source.filename = (yyvsp[(1) - (3)].word);
2436 redir.dest = (yyvsp[(3) - (3)].number);
2437 (yyval.redirect) = make_redirection (source, r_duplicating_output, redir, REDIR_VARASSIGN);
Jari Aalto31859422009-01-12 13:36:28 +00002438 }
2439 break;
2440
2441 case 38:
Chet Ramey80b4d712014-10-05 19:12:20 -04002442#line 620 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Chet Ramey00018032011-11-21 20:51:19 -05002443 {
2444 source.dest = 0;
2445 redir.filename = (yyvsp[(2) - (2)].word);
2446 (yyval.redirect) = make_redirection (source, r_duplicating_input_word, redir, 0);
2447 }
Jari Aalto31859422009-01-12 13:36:28 +00002448 break;
2449
2450 case 39:
Chet Ramey80b4d712014-10-05 19:12:20 -04002451#line 626 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Chet Ramey00018032011-11-21 20:51:19 -05002452 {
2453 source.dest = (yyvsp[(1) - (3)].number);
2454 redir.filename = (yyvsp[(3) - (3)].word);
2455 (yyval.redirect) = make_redirection (source, r_duplicating_input_word, redir, 0);
2456 }
Jari Aalto31859422009-01-12 13:36:28 +00002457 break;
2458
2459 case 40:
Chet Ramey80b4d712014-10-05 19:12:20 -04002460#line 632 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Chet Ramey00018032011-11-21 20:51:19 -05002461 {
2462 source.filename = (yyvsp[(1) - (3)].word);
2463 redir.filename = (yyvsp[(3) - (3)].word);
2464 (yyval.redirect) = make_redirection (source, r_duplicating_input_word, redir, REDIR_VARASSIGN);
2465 }
Jari Aalto31859422009-01-12 13:36:28 +00002466 break;
2467
2468 case 41:
Chet Ramey80b4d712014-10-05 19:12:20 -04002469#line 638 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Chet Ramey00018032011-11-21 20:51:19 -05002470 {
2471 source.dest = 1;
2472 redir.filename = (yyvsp[(2) - (2)].word);
2473 (yyval.redirect) = make_redirection (source, r_duplicating_output_word, redir, 0);
2474 }
2475 break;
2476
2477 case 42:
Chet Ramey80b4d712014-10-05 19:12:20 -04002478#line 644 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Chet Ramey00018032011-11-21 20:51:19 -05002479 {
2480 source.dest = (yyvsp[(1) - (3)].number);
2481 redir.filename = (yyvsp[(3) - (3)].word);
2482 (yyval.redirect) = make_redirection (source, r_duplicating_output_word, redir, 0);
2483 }
2484 break;
2485
2486 case 43:
Chet Ramey80b4d712014-10-05 19:12:20 -04002487#line 650 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Chet Ramey00018032011-11-21 20:51:19 -05002488 {
2489 source.filename = (yyvsp[(1) - (3)].word);
2490 redir.filename = (yyvsp[(3) - (3)].word);
2491 (yyval.redirect) = make_redirection (source, r_duplicating_output_word, redir, REDIR_VARASSIGN);
2492 }
2493 break;
2494
2495 case 44:
Chet Ramey80b4d712014-10-05 19:12:20 -04002496#line 656 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Chet Ramey00018032011-11-21 20:51:19 -05002497 {
2498 source.dest = 1;
2499 redir.dest = 0;
2500 (yyval.redirect) = make_redirection (source, r_close_this, redir, 0);
2501 }
2502 break;
2503
2504 case 45:
Chet Ramey80b4d712014-10-05 19:12:20 -04002505#line 662 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Chet Ramey00018032011-11-21 20:51:19 -05002506 {
2507 source.dest = (yyvsp[(1) - (3)].number);
2508 redir.dest = 0;
2509 (yyval.redirect) = make_redirection (source, r_close_this, redir, 0);
2510 }
2511 break;
2512
2513 case 46:
Chet Ramey80b4d712014-10-05 19:12:20 -04002514#line 668 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Chet Ramey00018032011-11-21 20:51:19 -05002515 {
2516 source.filename = (yyvsp[(1) - (3)].word);
2517 redir.dest = 0;
2518 (yyval.redirect) = make_redirection (source, r_close_this, redir, REDIR_VARASSIGN);
2519 }
2520 break;
2521
2522 case 47:
Chet Ramey80b4d712014-10-05 19:12:20 -04002523#line 674 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Chet Ramey00018032011-11-21 20:51:19 -05002524 {
2525 source.dest = 0;
2526 redir.dest = 0;
2527 (yyval.redirect) = make_redirection (source, r_close_this, redir, 0);
2528 }
2529 break;
2530
2531 case 48:
Chet Ramey80b4d712014-10-05 19:12:20 -04002532#line 680 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Chet Ramey00018032011-11-21 20:51:19 -05002533 {
2534 source.dest = (yyvsp[(1) - (3)].number);
2535 redir.dest = 0;
2536 (yyval.redirect) = make_redirection (source, r_close_this, redir, 0);
2537 }
2538 break;
2539
2540 case 49:
Chet Ramey80b4d712014-10-05 19:12:20 -04002541#line 686 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Chet Ramey00018032011-11-21 20:51:19 -05002542 {
2543 source.filename = (yyvsp[(1) - (3)].word);
2544 redir.dest = 0;
2545 (yyval.redirect) = make_redirection (source, r_close_this, redir, REDIR_VARASSIGN);
2546 }
2547 break;
2548
2549 case 50:
Chet Ramey80b4d712014-10-05 19:12:20 -04002550#line 692 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Chet Ramey00018032011-11-21 20:51:19 -05002551 {
2552 source.dest = 1;
2553 redir.filename = (yyvsp[(2) - (2)].word);
2554 (yyval.redirect) = make_redirection (source, r_err_and_out, redir, 0);
2555 }
2556 break;
2557
2558 case 51:
Chet Ramey80b4d712014-10-05 19:12:20 -04002559#line 698 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Chet Ramey00018032011-11-21 20:51:19 -05002560 {
2561 source.dest = 1;
2562 redir.filename = (yyvsp[(2) - (2)].word);
2563 (yyval.redirect) = make_redirection (source, r_append_err_and_out, redir, 0);
2564 }
2565 break;
2566
2567 case 52:
Chet Ramey80b4d712014-10-05 19:12:20 -04002568#line 706 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Chet Ramey00018032011-11-21 20:51:19 -05002569 { (yyval.element).word = (yyvsp[(1) - (1)].word); (yyval.element).redirect = 0; }
2570 break;
2571
2572 case 53:
Chet Ramey80b4d712014-10-05 19:12:20 -04002573#line 708 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Chet Ramey00018032011-11-21 20:51:19 -05002574 { (yyval.element).word = (yyvsp[(1) - (1)].word); (yyval.element).redirect = 0; }
2575 break;
2576
2577 case 54:
Chet Ramey80b4d712014-10-05 19:12:20 -04002578#line 710 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Chet Ramey00018032011-11-21 20:51:19 -05002579 { (yyval.element).redirect = (yyvsp[(1) - (1)].redirect); (yyval.element).word = 0; }
2580 break;
2581
2582 case 55:
Chet Ramey80b4d712014-10-05 19:12:20 -04002583#line 714 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Jari Aalto31859422009-01-12 13:36:28 +00002584 {
2585 (yyval.redirect) = (yyvsp[(1) - (1)].redirect);
2586 }
2587 break;
2588
Chet Ramey00018032011-11-21 20:51:19 -05002589 case 56:
Chet Ramey80b4d712014-10-05 19:12:20 -04002590#line 718 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Jari Aalto31859422009-01-12 13:36:28 +00002591 {
Jari Aaltof73dda02001-11-13 17:56:06 +00002592 register REDIRECT *t;
2593
Jari Aalto31859422009-01-12 13:36:28 +00002594 for (t = (yyvsp[(1) - (2)].redirect); t->next; t = t->next)
Jari Aaltof73dda02001-11-13 17:56:06 +00002595 ;
Jari Aalto31859422009-01-12 13:36:28 +00002596 t->next = (yyvsp[(2) - (2)].redirect);
2597 (yyval.redirect) = (yyvsp[(1) - (2)].redirect);
2598 }
2599 break;
2600
Chet Ramey00018032011-11-21 20:51:19 -05002601 case 57:
Chet Ramey80b4d712014-10-05 19:12:20 -04002602#line 729 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Jari Aalto31859422009-01-12 13:36:28 +00002603 { (yyval.command) = make_simple_command ((yyvsp[(1) - (1)].element), (COMMAND *)NULL); }
2604 break;
2605
Chet Ramey00018032011-11-21 20:51:19 -05002606 case 58:
Chet Ramey80b4d712014-10-05 19:12:20 -04002607#line 731 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Jari Aalto31859422009-01-12 13:36:28 +00002608 { (yyval.command) = make_simple_command ((yyvsp[(2) - (2)].element), (yyvsp[(1) - (2)].command)); }
2609 break;
2610
Chet Ramey00018032011-11-21 20:51:19 -05002611 case 59:
Chet Ramey80b4d712014-10-05 19:12:20 -04002612#line 735 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Jari Aalto31859422009-01-12 13:36:28 +00002613 { (yyval.command) = clean_simple_command ((yyvsp[(1) - (1)].command)); }
2614 break;
2615
Chet Ramey00018032011-11-21 20:51:19 -05002616 case 60:
Chet Ramey80b4d712014-10-05 19:12:20 -04002617#line 737 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Jari Aalto31859422009-01-12 13:36:28 +00002618 { (yyval.command) = (yyvsp[(1) - (1)].command); }
2619 break;
2620
Chet Ramey00018032011-11-21 20:51:19 -05002621 case 61:
Chet Ramey80b4d712014-10-05 19:12:20 -04002622#line 739 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Jari Aalto31859422009-01-12 13:36:28 +00002623 {
Jari Aaltof73dda02001-11-13 17:56:06 +00002624 COMMAND *tc;
2625
Jari Aalto31859422009-01-12 13:36:28 +00002626 tc = (yyvsp[(1) - (2)].command);
Jari Aaltof73dda02001-11-13 17:56:06 +00002627 if (tc->redirects)
2628 {
2629 register REDIRECT *t;
2630 for (t = tc->redirects; t->next; t = t->next)
2631 ;
Jari Aalto31859422009-01-12 13:36:28 +00002632 t->next = (yyvsp[(2) - (2)].redirect);
Jari Aaltof73dda02001-11-13 17:56:06 +00002633 }
2634 else
Jari Aalto31859422009-01-12 13:36:28 +00002635 tc->redirects = (yyvsp[(2) - (2)].redirect);
2636 (yyval.command) = (yyvsp[(1) - (2)].command);
2637 }
2638 break;
2639
Jari Aalto31859422009-01-12 13:36:28 +00002640 case 62:
Chet Ramey80b4d712014-10-05 19:12:20 -04002641#line 755 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Chet Ramey00018032011-11-21 20:51:19 -05002642 { (yyval.command) = (yyvsp[(1) - (1)].command); }
Jari Aalto31859422009-01-12 13:36:28 +00002643 break;
2644
2645 case 63:
Chet Ramey80b4d712014-10-05 19:12:20 -04002646#line 757 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Chet Ramey00018032011-11-21 20:51:19 -05002647 { (yyval.command) = (yyvsp[(1) - (1)].command); }
Jari Aalto31859422009-01-12 13:36:28 +00002648 break;
2649
2650 case 64:
Chet Ramey80b4d712014-10-05 19:12:20 -04002651#line 761 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Chet Ramey00018032011-11-21 20:51:19 -05002652 { (yyval.command) = (yyvsp[(1) - (1)].command); }
Jari Aalto31859422009-01-12 13:36:28 +00002653 break;
2654
2655 case 65:
Chet Ramey80b4d712014-10-05 19:12:20 -04002656#line 763 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Chet Ramey00018032011-11-21 20:51:19 -05002657 { (yyval.command) = (yyvsp[(1) - (1)].command); }
Jari Aalto31859422009-01-12 13:36:28 +00002658 break;
2659
2660 case 66:
Chet Ramey80b4d712014-10-05 19:12:20 -04002661#line 765 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Chet Ramey00018032011-11-21 20:51:19 -05002662 { (yyval.command) = make_while_command ((yyvsp[(2) - (5)].command), (yyvsp[(4) - (5)].command)); }
Jari Aalto31859422009-01-12 13:36:28 +00002663 break;
2664
2665 case 67:
Chet Ramey80b4d712014-10-05 19:12:20 -04002666#line 767 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Chet Ramey00018032011-11-21 20:51:19 -05002667 { (yyval.command) = make_until_command ((yyvsp[(2) - (5)].command), (yyvsp[(4) - (5)].command)); }
Jari Aalto31859422009-01-12 13:36:28 +00002668 break;
2669
2670 case 68:
Chet Ramey80b4d712014-10-05 19:12:20 -04002671#line 769 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Chet Ramey00018032011-11-21 20:51:19 -05002672 { (yyval.command) = (yyvsp[(1) - (1)].command); }
Jari Aalto31859422009-01-12 13:36:28 +00002673 break;
2674
2675 case 69:
Chet Ramey80b4d712014-10-05 19:12:20 -04002676#line 771 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Chet Ramey00018032011-11-21 20:51:19 -05002677 { (yyval.command) = (yyvsp[(1) - (1)].command); }
Jari Aalto31859422009-01-12 13:36:28 +00002678 break;
2679
2680 case 70:
Chet Ramey80b4d712014-10-05 19:12:20 -04002681#line 773 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Chet Ramey00018032011-11-21 20:51:19 -05002682 { (yyval.command) = (yyvsp[(1) - (1)].command); }
Jari Aalto31859422009-01-12 13:36:28 +00002683 break;
2684
2685 case 71:
Chet Ramey80b4d712014-10-05 19:12:20 -04002686#line 775 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Chet Ramey00018032011-11-21 20:51:19 -05002687 { (yyval.command) = (yyvsp[(1) - (1)].command); }
Jari Aalto31859422009-01-12 13:36:28 +00002688 break;
2689
2690 case 72:
Chet Ramey80b4d712014-10-05 19:12:20 -04002691#line 777 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Chet Ramey00018032011-11-21 20:51:19 -05002692 { (yyval.command) = (yyvsp[(1) - (1)].command); }
Jari Aalto31859422009-01-12 13:36:28 +00002693 break;
2694
2695 case 73:
Chet Ramey80b4d712014-10-05 19:12:20 -04002696#line 779 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Chet Ramey00018032011-11-21 20:51:19 -05002697 { (yyval.command) = (yyvsp[(1) - (1)].command); }
Jari Aalto31859422009-01-12 13:36:28 +00002698 break;
2699
2700 case 74:
Chet Ramey80b4d712014-10-05 19:12:20 -04002701#line 781 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Chet Ramey00018032011-11-21 20:51:19 -05002702 { (yyval.command) = (yyvsp[(1) - (1)].command); }
Jari Aalto31859422009-01-12 13:36:28 +00002703 break;
2704
2705 case 75:
Chet Ramey80b4d712014-10-05 19:12:20 -04002706#line 785 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Jari Aalto31859422009-01-12 13:36:28 +00002707 {
Chet Ramey00018032011-11-21 20:51:19 -05002708 (yyval.command) = make_for_command ((yyvsp[(2) - (6)].word), add_string_to_list ("\"$@\"", (WORD_LIST *)NULL), (yyvsp[(5) - (6)].command), word_lineno[word_top]);
Jari Aaltob80f6442004-07-27 13:29:18 +00002709 if (word_top > 0) word_top--;
Jari Aalto31859422009-01-12 13:36:28 +00002710 }
2711 break;
2712
2713 case 76:
Chet Ramey80b4d712014-10-05 19:12:20 -04002714#line 790 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Chet Ramey00018032011-11-21 20:51:19 -05002715 {
2716 (yyval.command) = make_for_command ((yyvsp[(2) - (6)].word), add_string_to_list ("\"$@\"", (WORD_LIST *)NULL), (yyvsp[(5) - (6)].command), word_lineno[word_top]);
2717 if (word_top > 0) word_top--;
2718 }
2719 break;
2720
2721 case 77:
Chet Ramey80b4d712014-10-05 19:12:20 -04002722#line 795 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Chet Ramey00018032011-11-21 20:51:19 -05002723 {
2724 (yyval.command) = make_for_command ((yyvsp[(2) - (7)].word), add_string_to_list ("\"$@\"", (WORD_LIST *)NULL), (yyvsp[(6) - (7)].command), word_lineno[word_top]);
2725 if (word_top > 0) word_top--;
2726 }
2727 break;
2728
2729 case 78:
Chet Ramey80b4d712014-10-05 19:12:20 -04002730#line 800 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Chet Ramey00018032011-11-21 20:51:19 -05002731 {
2732 (yyval.command) = make_for_command ((yyvsp[(2) - (7)].word), add_string_to_list ("\"$@\"", (WORD_LIST *)NULL), (yyvsp[(6) - (7)].command), word_lineno[word_top]);
2733 if (word_top > 0) word_top--;
2734 }
2735 break;
2736
2737 case 79:
Chet Ramey80b4d712014-10-05 19:12:20 -04002738#line 805 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Chet Ramey00018032011-11-21 20:51:19 -05002739 {
2740 (yyval.command) = make_for_command ((yyvsp[(2) - (10)].word), REVERSE_LIST ((yyvsp[(5) - (10)].word_list), WORD_LIST *), (yyvsp[(9) - (10)].command), word_lineno[word_top]);
2741 if (word_top > 0) word_top--;
2742 }
2743 break;
2744
2745 case 80:
Chet Ramey80b4d712014-10-05 19:12:20 -04002746#line 810 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Chet Ramey00018032011-11-21 20:51:19 -05002747 {
2748 (yyval.command) = make_for_command ((yyvsp[(2) - (10)].word), REVERSE_LIST ((yyvsp[(5) - (10)].word_list), WORD_LIST *), (yyvsp[(9) - (10)].command), word_lineno[word_top]);
2749 if (word_top > 0) word_top--;
2750 }
2751 break;
2752
2753 case 81:
Chet Ramey80b4d712014-10-05 19:12:20 -04002754#line 815 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Chet Ramey00018032011-11-21 20:51:19 -05002755 {
2756 (yyval.command) = make_for_command ((yyvsp[(2) - (9)].word), (WORD_LIST *)NULL, (yyvsp[(8) - (9)].command), word_lineno[word_top]);
2757 if (word_top > 0) word_top--;
2758 }
2759 break;
2760
2761 case 82:
Chet Ramey80b4d712014-10-05 19:12:20 -04002762#line 820 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Chet Ramey00018032011-11-21 20:51:19 -05002763 {
2764 (yyval.command) = make_for_command ((yyvsp[(2) - (9)].word), (WORD_LIST *)NULL, (yyvsp[(8) - (9)].command), word_lineno[word_top]);
2765 if (word_top > 0) word_top--;
2766 }
2767 break;
2768
2769 case 83:
Chet Ramey80b4d712014-10-05 19:12:20 -04002770#line 827 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Chet Ramey00018032011-11-21 20:51:19 -05002771 {
2772 (yyval.command) = make_arith_for_command ((yyvsp[(2) - (7)].word_list), (yyvsp[(6) - (7)].command), arith_for_lineno);
2773 if (word_top > 0) word_top--;
2774 }
2775 break;
2776
2777 case 84:
Chet Ramey80b4d712014-10-05 19:12:20 -04002778#line 832 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Chet Ramey00018032011-11-21 20:51:19 -05002779 {
2780 (yyval.command) = make_arith_for_command ((yyvsp[(2) - (7)].word_list), (yyvsp[(6) - (7)].command), arith_for_lineno);
2781 if (word_top > 0) word_top--;
2782 }
2783 break;
2784
2785 case 85:
Chet Ramey80b4d712014-10-05 19:12:20 -04002786#line 837 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Chet Ramey00018032011-11-21 20:51:19 -05002787 {
2788 (yyval.command) = make_arith_for_command ((yyvsp[(2) - (5)].word_list), (yyvsp[(4) - (5)].command), arith_for_lineno);
2789 if (word_top > 0) word_top--;
2790 }
2791 break;
2792
2793 case 86:
Chet Ramey80b4d712014-10-05 19:12:20 -04002794#line 842 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Chet Ramey00018032011-11-21 20:51:19 -05002795 {
2796 (yyval.command) = make_arith_for_command ((yyvsp[(2) - (5)].word_list), (yyvsp[(4) - (5)].command), arith_for_lineno);
2797 if (word_top > 0) word_top--;
2798 }
2799 break;
2800
2801 case 87:
Chet Ramey80b4d712014-10-05 19:12:20 -04002802#line 849 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Chet Ramey00018032011-11-21 20:51:19 -05002803 {
2804 (yyval.command) = make_select_command ((yyvsp[(2) - (6)].word), add_string_to_list ("\"$@\"", (WORD_LIST *)NULL), (yyvsp[(5) - (6)].command), word_lineno[word_top]);
2805 if (word_top > 0) word_top--;
2806 }
2807 break;
2808
2809 case 88:
Chet Ramey80b4d712014-10-05 19:12:20 -04002810#line 854 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Chet Ramey00018032011-11-21 20:51:19 -05002811 {
2812 (yyval.command) = make_select_command ((yyvsp[(2) - (6)].word), add_string_to_list ("\"$@\"", (WORD_LIST *)NULL), (yyvsp[(5) - (6)].command), word_lineno[word_top]);
2813 if (word_top > 0) word_top--;
2814 }
2815 break;
2816
2817 case 89:
Chet Ramey80b4d712014-10-05 19:12:20 -04002818#line 859 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Jari Aalto31859422009-01-12 13:36:28 +00002819 {
2820 (yyval.command) = make_select_command ((yyvsp[(2) - (7)].word), add_string_to_list ("\"$@\"", (WORD_LIST *)NULL), (yyvsp[(6) - (7)].command), word_lineno[word_top]);
2821 if (word_top > 0) word_top--;
2822 }
2823 break;
2824
Chet Ramey00018032011-11-21 20:51:19 -05002825 case 90:
Chet Ramey80b4d712014-10-05 19:12:20 -04002826#line 864 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Chet Ramey00018032011-11-21 20:51:19 -05002827 {
2828 (yyval.command) = make_select_command ((yyvsp[(2) - (7)].word), add_string_to_list ("\"$@\"", (WORD_LIST *)NULL), (yyvsp[(6) - (7)].command), word_lineno[word_top]);
2829 if (word_top > 0) word_top--;
2830 }
2831 break;
2832
2833 case 91:
Chet Ramey80b4d712014-10-05 19:12:20 -04002834#line 869 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Jari Aalto31859422009-01-12 13:36:28 +00002835 {
2836 (yyval.command) = make_select_command ((yyvsp[(2) - (10)].word), REVERSE_LIST ((yyvsp[(5) - (10)].word_list), WORD_LIST *), (yyvsp[(9) - (10)].command), word_lineno[word_top]);
2837 if (word_top > 0) word_top--;
2838 }
2839 break;
2840
Chet Ramey00018032011-11-21 20:51:19 -05002841 case 92:
Chet Ramey80b4d712014-10-05 19:12:20 -04002842#line 874 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Jari Aalto31859422009-01-12 13:36:28 +00002843 {
2844 (yyval.command) = make_select_command ((yyvsp[(2) - (10)].word), REVERSE_LIST ((yyvsp[(5) - (10)].word_list), WORD_LIST *), (yyvsp[(9) - (10)].command), word_lineno[word_top]);
2845 if (word_top > 0) word_top--;
2846 }
2847 break;
2848
Chet Ramey00018032011-11-21 20:51:19 -05002849 case 93:
Chet Ramey80b4d712014-10-05 19:12:20 -04002850#line 881 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Jari Aalto31859422009-01-12 13:36:28 +00002851 {
2852 (yyval.command) = make_case_command ((yyvsp[(2) - (6)].word), (PATTERN_LIST *)NULL, word_lineno[word_top]);
2853 if (word_top > 0) word_top--;
2854 }
2855 break;
2856
Chet Ramey00018032011-11-21 20:51:19 -05002857 case 94:
Chet Ramey80b4d712014-10-05 19:12:20 -04002858#line 886 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Jari Aalto31859422009-01-12 13:36:28 +00002859 {
2860 (yyval.command) = make_case_command ((yyvsp[(2) - (7)].word), (yyvsp[(5) - (7)].pattern), word_lineno[word_top]);
2861 if (word_top > 0) word_top--;
2862 }
2863 break;
2864
Chet Ramey00018032011-11-21 20:51:19 -05002865 case 95:
Chet Ramey80b4d712014-10-05 19:12:20 -04002866#line 891 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Jari Aalto31859422009-01-12 13:36:28 +00002867 {
2868 (yyval.command) = make_case_command ((yyvsp[(2) - (6)].word), (yyvsp[(5) - (6)].pattern), word_lineno[word_top]);
2869 if (word_top > 0) word_top--;
2870 }
2871 break;
2872
Chet Ramey00018032011-11-21 20:51:19 -05002873 case 96:
Chet Ramey80b4d712014-10-05 19:12:20 -04002874#line 898 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Jari Aalto31859422009-01-12 13:36:28 +00002875 { (yyval.command) = make_function_def ((yyvsp[(1) - (5)].word), (yyvsp[(5) - (5)].command), function_dstart, function_bstart); }
2876 break;
2877
Chet Ramey00018032011-11-21 20:51:19 -05002878 case 97:
Chet Ramey80b4d712014-10-05 19:12:20 -04002879#line 901 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Jari Aalto31859422009-01-12 13:36:28 +00002880 { (yyval.command) = make_function_def ((yyvsp[(2) - (6)].word), (yyvsp[(6) - (6)].command), function_dstart, function_bstart); }
2881 break;
2882
Chet Ramey00018032011-11-21 20:51:19 -05002883 case 98:
Chet Ramey80b4d712014-10-05 19:12:20 -04002884#line 904 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Jari Aalto31859422009-01-12 13:36:28 +00002885 { (yyval.command) = make_function_def ((yyvsp[(2) - (4)].word), (yyvsp[(4) - (4)].command), function_dstart, function_bstart); }
2886 break;
2887
Chet Ramey00018032011-11-21 20:51:19 -05002888 case 99:
Chet Ramey80b4d712014-10-05 19:12:20 -04002889#line 908 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Jari Aalto31859422009-01-12 13:36:28 +00002890 { (yyval.command) = (yyvsp[(1) - (1)].command); }
2891 break;
2892
Chet Ramey00018032011-11-21 20:51:19 -05002893 case 100:
Chet Ramey80b4d712014-10-05 19:12:20 -04002894#line 910 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Jari Aalto31859422009-01-12 13:36:28 +00002895 {
Jari Aaltof73dda02001-11-13 17:56:06 +00002896 COMMAND *tc;
2897
Jari Aalto31859422009-01-12 13:36:28 +00002898 tc = (yyvsp[(1) - (2)].command);
Jari Aaltof73dda02001-11-13 17:56:06 +00002899 /* According to Posix.2 3.9.5, redirections
2900 specified after the body of a function should
2901 be attached to the function and performed when
2902 the function is executed, not as part of the
2903 function definition command. */
2904 /* XXX - I don't think it matters, but we might
2905 want to change this in the future to avoid
2906 problems differentiating between a function
2907 definition with a redirection and a function
2908 definition containing a single command with a
2909 redirection. The two are semantically equivalent,
2910 though -- the only difference is in how the
2911 command printing code displays the redirections. */
2912 if (tc->redirects)
2913 {
2914 register REDIRECT *t;
2915 for (t = tc->redirects; t->next; t = t->next)
2916 ;
Jari Aalto31859422009-01-12 13:36:28 +00002917 t->next = (yyvsp[(2) - (2)].redirect);
Jari Aaltof73dda02001-11-13 17:56:06 +00002918 }
2919 else
Jari Aalto31859422009-01-12 13:36:28 +00002920 tc->redirects = (yyvsp[(2) - (2)].redirect);
2921 (yyval.command) = (yyvsp[(1) - (2)].command);
2922 }
2923 break;
2924
Chet Ramey00018032011-11-21 20:51:19 -05002925 case 101:
Chet Ramey80b4d712014-10-05 19:12:20 -04002926#line 941 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Jari Aalto31859422009-01-12 13:36:28 +00002927 {
2928 (yyval.command) = make_subshell_command ((yyvsp[(2) - (3)].command));
2929 (yyval.command)->flags |= CMD_WANT_SUBSHELL;
2930 }
2931 break;
2932
Chet Ramey00018032011-11-21 20:51:19 -05002933 case 102:
Chet Ramey80b4d712014-10-05 19:12:20 -04002934#line 948 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Jari Aalto31859422009-01-12 13:36:28 +00002935 {
2936 (yyval.command) = make_coproc_command ("COPROC", (yyvsp[(2) - (2)].command));
2937 (yyval.command)->flags |= CMD_WANT_SUBSHELL|CMD_COPROC_SUBSHELL;
2938 }
2939 break;
2940
Chet Ramey00018032011-11-21 20:51:19 -05002941 case 103:
Chet Ramey80b4d712014-10-05 19:12:20 -04002942#line 953 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Jari Aalto31859422009-01-12 13:36:28 +00002943 {
2944 COMMAND *tc;
2945
2946 tc = (yyvsp[(2) - (3)].command);
2947 if (tc->redirects)
2948 {
2949 register REDIRECT *t;
2950 for (t = tc->redirects; t->next; t = t->next)
2951 ;
2952 t->next = (yyvsp[(3) - (3)].redirect);
2953 }
2954 else
2955 tc->redirects = (yyvsp[(3) - (3)].redirect);
2956 (yyval.command) = make_coproc_command ("COPROC", (yyvsp[(2) - (3)].command));
2957 (yyval.command)->flags |= CMD_WANT_SUBSHELL|CMD_COPROC_SUBSHELL;
2958 }
2959 break;
2960
Chet Ramey00018032011-11-21 20:51:19 -05002961 case 104:
Chet Ramey80b4d712014-10-05 19:12:20 -04002962#line 970 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Jari Aalto31859422009-01-12 13:36:28 +00002963 {
2964 (yyval.command) = make_coproc_command ((yyvsp[(2) - (3)].word)->word, (yyvsp[(3) - (3)].command));
2965 (yyval.command)->flags |= CMD_WANT_SUBSHELL|CMD_COPROC_SUBSHELL;
2966 }
2967 break;
2968
Chet Ramey00018032011-11-21 20:51:19 -05002969 case 105:
Chet Ramey80b4d712014-10-05 19:12:20 -04002970#line 975 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Jari Aalto31859422009-01-12 13:36:28 +00002971 {
2972 COMMAND *tc;
2973
2974 tc = (yyvsp[(3) - (4)].command);
2975 if (tc->redirects)
2976 {
2977 register REDIRECT *t;
2978 for (t = tc->redirects; t->next; t = t->next)
2979 ;
2980 t->next = (yyvsp[(4) - (4)].redirect);
2981 }
Jari Aaltof73dda02001-11-13 17:56:06 +00002982 else
Jari Aalto31859422009-01-12 13:36:28 +00002983 tc->redirects = (yyvsp[(4) - (4)].redirect);
2984 (yyval.command) = make_coproc_command ((yyvsp[(2) - (4)].word)->word, (yyvsp[(3) - (4)].command));
2985 (yyval.command)->flags |= CMD_WANT_SUBSHELL|CMD_COPROC_SUBSHELL;
2986 }
2987 break;
2988
Chet Ramey00018032011-11-21 20:51:19 -05002989 case 106:
Chet Ramey80b4d712014-10-05 19:12:20 -04002990#line 992 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Jari Aalto31859422009-01-12 13:36:28 +00002991 {
2992 (yyval.command) = make_coproc_command ("COPROC", clean_simple_command ((yyvsp[(2) - (2)].command)));
2993 (yyval.command)->flags |= CMD_WANT_SUBSHELL|CMD_COPROC_SUBSHELL;
2994 }
2995 break;
2996
Chet Ramey00018032011-11-21 20:51:19 -05002997 case 107:
Chet Ramey80b4d712014-10-05 19:12:20 -04002998#line 999 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Jari Aalto31859422009-01-12 13:36:28 +00002999 { (yyval.command) = make_if_command ((yyvsp[(2) - (5)].command), (yyvsp[(4) - (5)].command), (COMMAND *)NULL); }
3000 break;
3001
Chet Ramey00018032011-11-21 20:51:19 -05003002 case 108:
Chet Ramey80b4d712014-10-05 19:12:20 -04003003#line 1001 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Jari Aalto31859422009-01-12 13:36:28 +00003004 { (yyval.command) = make_if_command ((yyvsp[(2) - (7)].command), (yyvsp[(4) - (7)].command), (yyvsp[(6) - (7)].command)); }
3005 break;
3006
Chet Ramey00018032011-11-21 20:51:19 -05003007 case 109:
Chet Ramey80b4d712014-10-05 19:12:20 -04003008#line 1003 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Jari Aalto31859422009-01-12 13:36:28 +00003009 { (yyval.command) = make_if_command ((yyvsp[(2) - (6)].command), (yyvsp[(4) - (6)].command), (yyvsp[(5) - (6)].command)); }
3010 break;
3011
Chet Ramey00018032011-11-21 20:51:19 -05003012 case 110:
Chet Ramey80b4d712014-10-05 19:12:20 -04003013#line 1008 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Jari Aalto31859422009-01-12 13:36:28 +00003014 { (yyval.command) = make_group_command ((yyvsp[(2) - (3)].command)); }
3015 break;
3016
Chet Ramey00018032011-11-21 20:51:19 -05003017 case 111:
Chet Ramey80b4d712014-10-05 19:12:20 -04003018#line 1012 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Jari Aalto31859422009-01-12 13:36:28 +00003019 { (yyval.command) = make_arith_command ((yyvsp[(1) - (1)].word_list)); }
3020 break;
3021
Chet Ramey00018032011-11-21 20:51:19 -05003022 case 112:
Chet Ramey80b4d712014-10-05 19:12:20 -04003023#line 1016 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Jari Aalto31859422009-01-12 13:36:28 +00003024 { (yyval.command) = (yyvsp[(2) - (3)].command); }
3025 break;
3026
Chet Ramey00018032011-11-21 20:51:19 -05003027 case 113:
Chet Ramey80b4d712014-10-05 19:12:20 -04003028#line 1020 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Jari Aalto31859422009-01-12 13:36:28 +00003029 { (yyval.command) = make_if_command ((yyvsp[(2) - (4)].command), (yyvsp[(4) - (4)].command), (COMMAND *)NULL); }
3030 break;
3031
Chet Ramey00018032011-11-21 20:51:19 -05003032 case 114:
Chet Ramey80b4d712014-10-05 19:12:20 -04003033#line 1022 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Jari Aalto31859422009-01-12 13:36:28 +00003034 { (yyval.command) = make_if_command ((yyvsp[(2) - (6)].command), (yyvsp[(4) - (6)].command), (yyvsp[(6) - (6)].command)); }
3035 break;
3036
Chet Ramey00018032011-11-21 20:51:19 -05003037 case 115:
Chet Ramey80b4d712014-10-05 19:12:20 -04003038#line 1024 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Jari Aalto31859422009-01-12 13:36:28 +00003039 { (yyval.command) = make_if_command ((yyvsp[(2) - (5)].command), (yyvsp[(4) - (5)].command), (yyvsp[(5) - (5)].command)); }
3040 break;
3041
Chet Ramey00018032011-11-21 20:51:19 -05003042 case 117:
Chet Ramey80b4d712014-10-05 19:12:20 -04003043#line 1029 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Jari Aalto31859422009-01-12 13:36:28 +00003044 { (yyvsp[(2) - (2)].pattern)->next = (yyvsp[(1) - (2)].pattern); (yyval.pattern) = (yyvsp[(2) - (2)].pattern); }
3045 break;
3046
Chet Ramey00018032011-11-21 20:51:19 -05003047 case 118:
Chet Ramey80b4d712014-10-05 19:12:20 -04003048#line 1033 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Jari Aalto31859422009-01-12 13:36:28 +00003049 { (yyval.pattern) = make_pattern_list ((yyvsp[(2) - (4)].word_list), (yyvsp[(4) - (4)].command)); }
3050 break;
3051
Chet Ramey00018032011-11-21 20:51:19 -05003052 case 119:
Chet Ramey80b4d712014-10-05 19:12:20 -04003053#line 1035 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Jari Aalto31859422009-01-12 13:36:28 +00003054 { (yyval.pattern) = make_pattern_list ((yyvsp[(2) - (4)].word_list), (COMMAND *)NULL); }
3055 break;
3056
Chet Ramey00018032011-11-21 20:51:19 -05003057 case 120:
Chet Ramey80b4d712014-10-05 19:12:20 -04003058#line 1037 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Jari Aalto31859422009-01-12 13:36:28 +00003059 { (yyval.pattern) = make_pattern_list ((yyvsp[(3) - (5)].word_list), (yyvsp[(5) - (5)].command)); }
3060 break;
3061
Chet Ramey00018032011-11-21 20:51:19 -05003062 case 121:
Chet Ramey80b4d712014-10-05 19:12:20 -04003063#line 1039 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Jari Aalto31859422009-01-12 13:36:28 +00003064 { (yyval.pattern) = make_pattern_list ((yyvsp[(3) - (5)].word_list), (COMMAND *)NULL); }
3065 break;
3066
Chet Ramey00018032011-11-21 20:51:19 -05003067 case 122:
Chet Ramey80b4d712014-10-05 19:12:20 -04003068#line 1043 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Jari Aalto31859422009-01-12 13:36:28 +00003069 { (yyval.pattern) = (yyvsp[(1) - (2)].pattern); }
3070 break;
3071
Chet Ramey00018032011-11-21 20:51:19 -05003072 case 123:
Chet Ramey80b4d712014-10-05 19:12:20 -04003073#line 1045 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Jari Aalto31859422009-01-12 13:36:28 +00003074 { (yyvsp[(2) - (3)].pattern)->next = (yyvsp[(1) - (3)].pattern); (yyval.pattern) = (yyvsp[(2) - (3)].pattern); }
3075 break;
3076
Chet Ramey00018032011-11-21 20:51:19 -05003077 case 124:
Chet Ramey80b4d712014-10-05 19:12:20 -04003078#line 1047 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Jari Aalto31859422009-01-12 13:36:28 +00003079 { (yyvsp[(1) - (2)].pattern)->flags |= CASEPAT_FALLTHROUGH; (yyval.pattern) = (yyvsp[(1) - (2)].pattern); }
3080 break;
3081
Chet Ramey00018032011-11-21 20:51:19 -05003082 case 125:
Chet Ramey80b4d712014-10-05 19:12:20 -04003083#line 1049 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Jari Aalto31859422009-01-12 13:36:28 +00003084 { (yyvsp[(2) - (3)].pattern)->flags |= CASEPAT_FALLTHROUGH; (yyvsp[(2) - (3)].pattern)->next = (yyvsp[(1) - (3)].pattern); (yyval.pattern) = (yyvsp[(2) - (3)].pattern); }
3085 break;
3086
Chet Ramey00018032011-11-21 20:51:19 -05003087 case 126:
Chet Ramey80b4d712014-10-05 19:12:20 -04003088#line 1051 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Jari Aalto31859422009-01-12 13:36:28 +00003089 { (yyvsp[(1) - (2)].pattern)->flags |= CASEPAT_TESTNEXT; (yyval.pattern) = (yyvsp[(1) - (2)].pattern); }
3090 break;
3091
Chet Ramey00018032011-11-21 20:51:19 -05003092 case 127:
Chet Ramey80b4d712014-10-05 19:12:20 -04003093#line 1053 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Jari Aalto31859422009-01-12 13:36:28 +00003094 { (yyvsp[(2) - (3)].pattern)->flags |= CASEPAT_TESTNEXT; (yyvsp[(2) - (3)].pattern)->next = (yyvsp[(1) - (3)].pattern); (yyval.pattern) = (yyvsp[(2) - (3)].pattern); }
3095 break;
3096
Chet Ramey00018032011-11-21 20:51:19 -05003097 case 128:
Chet Ramey80b4d712014-10-05 19:12:20 -04003098#line 1057 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Jari Aalto31859422009-01-12 13:36:28 +00003099 { (yyval.word_list) = make_word_list ((yyvsp[(1) - (1)].word), (WORD_LIST *)NULL); }
3100 break;
3101
Chet Ramey00018032011-11-21 20:51:19 -05003102 case 129:
Chet Ramey80b4d712014-10-05 19:12:20 -04003103#line 1059 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Jari Aalto31859422009-01-12 13:36:28 +00003104 { (yyval.word_list) = make_word_list ((yyvsp[(3) - (3)].word), (yyvsp[(1) - (3)].word_list)); }
3105 break;
3106
Chet Ramey00018032011-11-21 20:51:19 -05003107 case 130:
Chet Ramey80b4d712014-10-05 19:12:20 -04003108#line 1068 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Jari Aalto31859422009-01-12 13:36:28 +00003109 {
3110 (yyval.command) = (yyvsp[(2) - (2)].command);
3111 if (need_here_doc)
3112 gather_here_documents ();
3113 }
3114 break;
3115
Chet Ramey00018032011-11-21 20:51:19 -05003116 case 132:
Chet Ramey80b4d712014-10-05 19:12:20 -04003117#line 1077 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Jari Aalto31859422009-01-12 13:36:28 +00003118 {
3119 (yyval.command) = (yyvsp[(2) - (2)].command);
3120 }
3121 break;
3122
Chet Ramey00018032011-11-21 20:51:19 -05003123 case 134:
Chet Ramey80b4d712014-10-05 19:12:20 -04003124#line 1084 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Jari Aalto31859422009-01-12 13:36:28 +00003125 {
3126 if ((yyvsp[(1) - (3)].command)->type == cm_connection)
3127 (yyval.command) = connect_async_list ((yyvsp[(1) - (3)].command), (COMMAND *)NULL, '&');
3128 else
3129 (yyval.command) = command_connect ((yyvsp[(1) - (3)].command), (COMMAND *)NULL, '&');
3130 }
3131 break;
3132
Chet Ramey00018032011-11-21 20:51:19 -05003133 case 136:
Chet Ramey80b4d712014-10-05 19:12:20 -04003134#line 1095 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Jari Aalto31859422009-01-12 13:36:28 +00003135 { (yyval.command) = command_connect ((yyvsp[(1) - (4)].command), (yyvsp[(4) - (4)].command), AND_AND); }
3136 break;
3137
Chet Ramey00018032011-11-21 20:51:19 -05003138 case 137:
Chet Ramey80b4d712014-10-05 19:12:20 -04003139#line 1097 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Jari Aalto31859422009-01-12 13:36:28 +00003140 { (yyval.command) = command_connect ((yyvsp[(1) - (4)].command), (yyvsp[(4) - (4)].command), OR_OR); }
3141 break;
3142
Chet Ramey00018032011-11-21 20:51:19 -05003143 case 138:
Chet Ramey80b4d712014-10-05 19:12:20 -04003144#line 1099 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Jari Aalto31859422009-01-12 13:36:28 +00003145 {
3146 if ((yyvsp[(1) - (4)].command)->type == cm_connection)
3147 (yyval.command) = connect_async_list ((yyvsp[(1) - (4)].command), (yyvsp[(4) - (4)].command), '&');
3148 else
3149 (yyval.command) = command_connect ((yyvsp[(1) - (4)].command), (yyvsp[(4) - (4)].command), '&');
3150 }
3151 break;
3152
Chet Ramey00018032011-11-21 20:51:19 -05003153 case 139:
Chet Ramey80b4d712014-10-05 19:12:20 -04003154#line 1106 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Jari Aalto31859422009-01-12 13:36:28 +00003155 { (yyval.command) = command_connect ((yyvsp[(1) - (4)].command), (yyvsp[(4) - (4)].command), ';'); }
3156 break;
3157
Chet Ramey00018032011-11-21 20:51:19 -05003158 case 140:
Chet Ramey80b4d712014-10-05 19:12:20 -04003159#line 1108 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Jari Aalto31859422009-01-12 13:36:28 +00003160 { (yyval.command) = command_connect ((yyvsp[(1) - (4)].command), (yyvsp[(4) - (4)].command), ';'); }
3161 break;
3162
Chet Ramey00018032011-11-21 20:51:19 -05003163 case 141:
Chet Ramey80b4d712014-10-05 19:12:20 -04003164#line 1110 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Jari Aalto31859422009-01-12 13:36:28 +00003165 { (yyval.command) = (yyvsp[(1) - (1)].command); }
3166 break;
3167
Chet Ramey00018032011-11-21 20:51:19 -05003168 case 144:
Chet Ramey80b4d712014-10-05 19:12:20 -04003169#line 1118 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Jari Aalto31859422009-01-12 13:36:28 +00003170 { (yyval.number) = '\n'; }
3171 break;
3172
Chet Ramey00018032011-11-21 20:51:19 -05003173 case 145:
Chet Ramey80b4d712014-10-05 19:12:20 -04003174#line 1120 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Jari Aalto31859422009-01-12 13:36:28 +00003175 { (yyval.number) = ';'; }
3176 break;
3177
Chet Ramey00018032011-11-21 20:51:19 -05003178 case 146:
Chet Ramey80b4d712014-10-05 19:12:20 -04003179#line 1122 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Jari Aalto31859422009-01-12 13:36:28 +00003180 { (yyval.number) = yacc_EOF; }
3181 break;
3182
Chet Ramey00018032011-11-21 20:51:19 -05003183 case 149:
Chet Ramey80b4d712014-10-05 19:12:20 -04003184#line 1136 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Jari Aalto31859422009-01-12 13:36:28 +00003185 {
3186 (yyval.command) = (yyvsp[(1) - (1)].command);
3187 if (need_here_doc)
3188 gather_here_documents ();
3189 if ((parser_state & PST_CMDSUBST) && current_token == shell_eof_token)
3190 {
3191 global_command = (yyvsp[(1) - (1)].command);
3192 eof_encountered = 0;
3193 rewind_input_string ();
3194 YYACCEPT;
3195 }
3196 }
3197 break;
3198
Chet Ramey00018032011-11-21 20:51:19 -05003199 case 150:
Chet Ramey80b4d712014-10-05 19:12:20 -04003200#line 1149 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Jari Aalto31859422009-01-12 13:36:28 +00003201 {
3202 if ((yyvsp[(1) - (2)].command)->type == cm_connection)
3203 (yyval.command) = connect_async_list ((yyvsp[(1) - (2)].command), (COMMAND *)NULL, '&');
3204 else
3205 (yyval.command) = command_connect ((yyvsp[(1) - (2)].command), (COMMAND *)NULL, '&');
3206 if (need_here_doc)
3207 gather_here_documents ();
3208 if ((parser_state & PST_CMDSUBST) && current_token == shell_eof_token)
3209 {
3210 global_command = (yyvsp[(1) - (2)].command);
3211 eof_encountered = 0;
3212 rewind_input_string ();
3213 YYACCEPT;
3214 }
3215 }
3216 break;
3217
Chet Ramey00018032011-11-21 20:51:19 -05003218 case 151:
Chet Ramey80b4d712014-10-05 19:12:20 -04003219#line 1165 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Jari Aalto31859422009-01-12 13:36:28 +00003220 {
3221 (yyval.command) = (yyvsp[(1) - (2)].command);
3222 if (need_here_doc)
3223 gather_here_documents ();
3224 if ((parser_state & PST_CMDSUBST) && current_token == shell_eof_token)
3225 {
3226 global_command = (yyvsp[(1) - (2)].command);
3227 eof_encountered = 0;
3228 rewind_input_string ();
3229 YYACCEPT;
3230 }
3231 }
3232 break;
3233
Chet Ramey00018032011-11-21 20:51:19 -05003234 case 152:
Chet Ramey80b4d712014-10-05 19:12:20 -04003235#line 1180 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Jari Aalto31859422009-01-12 13:36:28 +00003236 { (yyval.command) = command_connect ((yyvsp[(1) - (4)].command), (yyvsp[(4) - (4)].command), AND_AND); }
3237 break;
3238
Chet Ramey00018032011-11-21 20:51:19 -05003239 case 153:
Chet Ramey80b4d712014-10-05 19:12:20 -04003240#line 1182 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Jari Aalto31859422009-01-12 13:36:28 +00003241 { (yyval.command) = command_connect ((yyvsp[(1) - (4)].command), (yyvsp[(4) - (4)].command), OR_OR); }
3242 break;
3243
Chet Ramey00018032011-11-21 20:51:19 -05003244 case 154:
Chet Ramey80b4d712014-10-05 19:12:20 -04003245#line 1184 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Jari Aalto31859422009-01-12 13:36:28 +00003246 {
3247 if ((yyvsp[(1) - (3)].command)->type == cm_connection)
3248 (yyval.command) = connect_async_list ((yyvsp[(1) - (3)].command), (yyvsp[(3) - (3)].command), '&');
3249 else
3250 (yyval.command) = command_connect ((yyvsp[(1) - (3)].command), (yyvsp[(3) - (3)].command), '&');
3251 }
3252 break;
3253
Chet Ramey00018032011-11-21 20:51:19 -05003254 case 155:
Chet Ramey80b4d712014-10-05 19:12:20 -04003255#line 1191 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Jari Aalto31859422009-01-12 13:36:28 +00003256 { (yyval.command) = command_connect ((yyvsp[(1) - (3)].command), (yyvsp[(3) - (3)].command), ';'); }
3257 break;
3258
Chet Ramey00018032011-11-21 20:51:19 -05003259 case 156:
Chet Ramey80b4d712014-10-05 19:12:20 -04003260#line 1194 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Jari Aalto31859422009-01-12 13:36:28 +00003261 { (yyval.command) = (yyvsp[(1) - (1)].command); }
3262 break;
3263
Chet Ramey00018032011-11-21 20:51:19 -05003264 case 157:
Chet Ramey80b4d712014-10-05 19:12:20 -04003265#line 1198 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Jari Aalto31859422009-01-12 13:36:28 +00003266 { (yyval.command) = (yyvsp[(1) - (1)].command); }
3267 break;
3268
Chet Ramey00018032011-11-21 20:51:19 -05003269 case 158:
Chet Ramey80b4d712014-10-05 19:12:20 -04003270#line 1200 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Jari Aalto31859422009-01-12 13:36:28 +00003271 {
3272 if ((yyvsp[(2) - (2)].command))
Chet Ramey495aee42011-11-22 19:11:26 -05003273 (yyvsp[(2) - (2)].command)->flags ^= CMD_INVERT_RETURN; /* toggle */
Jari Aalto31859422009-01-12 13:36:28 +00003274 (yyval.command) = (yyvsp[(2) - (2)].command);
3275 }
3276 break;
3277
Chet Ramey00018032011-11-21 20:51:19 -05003278 case 159:
Chet Ramey80b4d712014-10-05 19:12:20 -04003279#line 1206 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Jari Aalto31859422009-01-12 13:36:28 +00003280 {
3281 if ((yyvsp[(2) - (2)].command))
3282 (yyvsp[(2) - (2)].command)->flags |= (yyvsp[(1) - (2)].number);
3283 (yyval.command) = (yyvsp[(2) - (2)].command);
3284 }
3285 break;
3286
Chet Ramey00018032011-11-21 20:51:19 -05003287 case 160:
Chet Ramey80b4d712014-10-05 19:12:20 -04003288#line 1212 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Jari Aalto31859422009-01-12 13:36:28 +00003289 {
Jari Aaltob80f6442004-07-27 13:29:18 +00003290 ELEMENT x;
3291
3292 /* Boy, this is unclean. `time' by itself can
3293 time a null command. We cheat and push a
3294 newline back if the list_terminator was a newline
3295 to avoid the double-newline problem (one to
3296 terminate this, one to terminate the command) */
3297 x.word = 0;
3298 x.redirect = 0;
Jari Aalto31859422009-01-12 13:36:28 +00003299 (yyval.command) = make_simple_command (x, (COMMAND *)NULL);
3300 (yyval.command)->flags |= (yyvsp[(1) - (2)].number);
Jari Aaltob80f6442004-07-27 13:29:18 +00003301 /* XXX - let's cheat and push a newline back */
Jari Aalto31859422009-01-12 13:36:28 +00003302 if ((yyvsp[(2) - (2)].number) == '\n')
Jari Aaltob80f6442004-07-27 13:29:18 +00003303 token_to_read = '\n';
Jari Aalto31859422009-01-12 13:36:28 +00003304 }
3305 break;
Jari Aaltof73dda02001-11-13 17:56:06 +00003306
Chet Ramey495aee42011-11-22 19:11:26 -05003307 case 161:
Chet Ramey80b4d712014-10-05 19:12:20 -04003308#line 1229 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Chet Ramey495aee42011-11-22 19:11:26 -05003309 {
3310 ELEMENT x;
3311
3312 /* This is just as unclean. Posix says that `!'
3313 by itself should be equivalent to `false'.
3314 We cheat and push a
3315 newline back if the list_terminator was a newline
3316 to avoid the double-newline problem (one to
3317 terminate this, one to terminate the command) */
3318 x.word = 0;
3319 x.redirect = 0;
3320 (yyval.command) = make_simple_command (x, (COMMAND *)NULL);
3321 (yyval.command)->flags |= CMD_INVERT_RETURN;
3322 /* XXX - let's cheat and push a newline back */
3323 if ((yyvsp[(2) - (2)].number) == '\n')
3324 token_to_read = '\n';
3325 }
3326 break;
3327
3328 case 162:
Chet Ramey80b4d712014-10-05 19:12:20 -04003329#line 1249 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Jari Aalto31859422009-01-12 13:36:28 +00003330 { (yyval.command) = command_connect ((yyvsp[(1) - (4)].command), (yyvsp[(4) - (4)].command), '|'); }
3331 break;
3332
Chet Ramey495aee42011-11-22 19:11:26 -05003333 case 163:
Chet Ramey80b4d712014-10-05 19:12:20 -04003334#line 1251 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Jari Aaltof73dda02001-11-13 17:56:06 +00003335 {
Jari Aalto31859422009-01-12 13:36:28 +00003336 /* Make cmd1 |& cmd2 equivalent to cmd1 2>&1 | cmd2 */
3337 COMMAND *tc;
Chet Ramey00018032011-11-21 20:51:19 -05003338 REDIRECTEE rd, sd;
Jari Aalto31859422009-01-12 13:36:28 +00003339 REDIRECT *r;
3340
Chet Ramey00018032011-11-21 20:51:19 -05003341 tc = (yyvsp[(1) - (4)].command)->type == cm_simple ? (COMMAND *)(yyvsp[(1) - (4)].command)->value.Simple : (yyvsp[(1) - (4)].command);
3342 sd.dest = 2;
Jari Aalto31859422009-01-12 13:36:28 +00003343 rd.dest = 1;
Chet Ramey00018032011-11-21 20:51:19 -05003344 r = make_redirection (sd, r_duplicating_output, rd, 0);
Jari Aalto31859422009-01-12 13:36:28 +00003345 if (tc->redirects)
3346 {
3347 register REDIRECT *t;
3348 for (t = tc->redirects; t->next; t = t->next)
3349 ;
3350 t->next = r;
3351 }
3352 else
3353 tc->redirects = r;
3354
3355 (yyval.command) = command_connect ((yyvsp[(1) - (4)].command), (yyvsp[(4) - (4)].command), '|');
3356 }
3357 break;
3358
Chet Ramey495aee42011-11-22 19:11:26 -05003359 case 164:
Chet Ramey80b4d712014-10-05 19:12:20 -04003360#line 1274 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Jari Aalto31859422009-01-12 13:36:28 +00003361 { (yyval.command) = (yyvsp[(1) - (1)].command); }
3362 break;
3363
Chet Ramey495aee42011-11-22 19:11:26 -05003364 case 165:
Chet Ramey80b4d712014-10-05 19:12:20 -04003365#line 1278 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Jari Aalto31859422009-01-12 13:36:28 +00003366 { (yyval.number) = CMD_TIME_PIPELINE; }
3367 break;
3368
Chet Ramey495aee42011-11-22 19:11:26 -05003369 case 166:
Chet Ramey80b4d712014-10-05 19:12:20 -04003370#line 1280 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Chet Ramey495aee42011-11-22 19:11:26 -05003371 { (yyval.number) = CMD_TIME_PIPELINE|CMD_TIME_POSIX; }
3372 break;
3373
Chet Ramey00018032011-11-21 20:51:19 -05003374 case 167:
Chet Ramey80b4d712014-10-05 19:12:20 -04003375#line 1282 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Jari Aalto31859422009-01-12 13:36:28 +00003376 { (yyval.number) = CMD_TIME_PIPELINE|CMD_TIME_POSIX; }
3377 break;
3378
3379
3380/* Line 1267 of yacc.c. */
Chet Ramey90a39f32014-10-02 09:07:21 -04003381#line 3382 "y.tab.c"
Jari Aalto31859422009-01-12 13:36:28 +00003382 default: break;
Jari Aaltof73dda02001-11-13 17:56:06 +00003383 }
Jari Aalto31859422009-01-12 13:36:28 +00003384 YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc);
3385
3386 YYPOPSTACK (yylen);
3387 yylen = 0;
3388 YY_STACK_PRINT (yyss, yyssp);
Jari Aaltof73dda02001-11-13 17:56:06 +00003389
3390 *++yyvsp = yyval;
Jari Aaltob80f6442004-07-27 13:29:18 +00003391
Jari Aaltof73dda02001-11-13 17:56:06 +00003392
Jari Aalto31859422009-01-12 13:36:28 +00003393 /* Now `shift' the result of the reduction. Determine what state
3394 that goes to, based on the state we popped back to and the rule
3395 number reduced by. */
Jari Aaltof73dda02001-11-13 17:56:06 +00003396
3397 yyn = yyr1[yyn];
3398
Jari Aalto31859422009-01-12 13:36:28 +00003399 yystate = yypgoto[yyn - YYNTOKENS] + *yyssp;
3400 if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp)
Jari Aaltof73dda02001-11-13 17:56:06 +00003401 yystate = yytable[yystate];
3402 else
Jari Aalto31859422009-01-12 13:36:28 +00003403 yystate = yydefgoto[yyn - YYNTOKENS];
Jari Aaltof73dda02001-11-13 17:56:06 +00003404
3405 goto yynewstate;
3406
Jari Aaltof73dda02001-11-13 17:56:06 +00003407
Jari Aalto31859422009-01-12 13:36:28 +00003408/*------------------------------------.
3409| yyerrlab -- here on detecting error |
3410`------------------------------------*/
3411yyerrlab:
3412 /* If not already recovering from an error, report this error. */
3413 if (!yyerrstatus)
Jari Aaltof73dda02001-11-13 17:56:06 +00003414 {
3415 ++yynerrs;
Jari Aalto31859422009-01-12 13:36:28 +00003416#if ! YYERROR_VERBOSE
3417 yyerror (YY_("syntax error"));
3418#else
3419 {
3420 YYSIZE_T yysize = yysyntax_error (0, yystate, yychar);
3421 if (yymsg_alloc < yysize && yymsg_alloc < YYSTACK_ALLOC_MAXIMUM)
3422 {
3423 YYSIZE_T yyalloc = 2 * yysize;
3424 if (! (yysize <= yyalloc && yyalloc <= YYSTACK_ALLOC_MAXIMUM))
3425 yyalloc = YYSTACK_ALLOC_MAXIMUM;
3426 if (yymsg != yymsgbuf)
3427 YYSTACK_FREE (yymsg);
3428 yymsg = (char *) YYSTACK_ALLOC (yyalloc);
3429 if (yymsg)
3430 yymsg_alloc = yyalloc;
3431 else
3432 {
3433 yymsg = yymsgbuf;
3434 yymsg_alloc = sizeof yymsgbuf;
3435 }
3436 }
Jari Aaltof73dda02001-11-13 17:56:06 +00003437
Jari Aalto31859422009-01-12 13:36:28 +00003438 if (0 < yysize && yysize <= yymsg_alloc)
3439 {
3440 (void) yysyntax_error (yymsg, yystate, yychar);
3441 yyerror (yymsg);
3442 }
3443 else
3444 {
3445 yyerror (YY_("syntax error"));
3446 if (yysize != 0)
3447 goto yyexhaustedlab;
3448 }
3449 }
3450#endif
Jari Aaltof73dda02001-11-13 17:56:06 +00003451 }
Jari Aaltob80f6442004-07-27 13:29:18 +00003452
Jari Aalto31859422009-01-12 13:36:28 +00003453
Jari Aaltof73dda02001-11-13 17:56:06 +00003454
3455 if (yyerrstatus == 3)
3456 {
Jari Aalto31859422009-01-12 13:36:28 +00003457 /* If just tried and failed to reuse look-ahead token after an
3458 error, discard it. */
Jari Aaltof73dda02001-11-13 17:56:06 +00003459
Jari Aalto31859422009-01-12 13:36:28 +00003460 if (yychar <= YYEOF)
3461 {
3462 /* Return failure if at end of input. */
3463 if (yychar == YYEOF)
3464 YYABORT;
3465 }
3466 else
3467 {
3468 yydestruct ("Error: discarding",
3469 yytoken, &yylval);
3470 yychar = YYEMPTY;
3471 }
3472 }
3473
3474 /* Else will try to reuse look-ahead token after shifting the error
3475 token. */
3476 goto yyerrlab1;
3477
3478
3479/*---------------------------------------------------.
3480| yyerrorlab -- error raised explicitly by YYERROR. |
3481`---------------------------------------------------*/
3482yyerrorlab:
3483
3484 /* Pacify compilers like GCC when the user code never invokes
3485 YYERROR and the label yyerrorlab therefore never appears in user
3486 code. */
3487 if (/*CONSTCOND*/ 0)
3488 goto yyerrorlab;
3489
3490 /* Do not reclaim the symbols of the rule which action triggered
3491 this YYERROR. */
3492 YYPOPSTACK (yylen);
3493 yylen = 0;
3494 YY_STACK_PRINT (yyss, yyssp);
3495 yystate = *yyssp;
3496 goto yyerrlab1;
3497
3498
3499/*-------------------------------------------------------------.
3500| yyerrlab1 -- common code for both syntax error and YYERROR. |
3501`-------------------------------------------------------------*/
3502yyerrlab1:
3503 yyerrstatus = 3; /* Each real token shifted decrements this. */
3504
3505 for (;;)
3506 {
3507 yyn = yypact[yystate];
3508 if (yyn != YYPACT_NINF)
3509 {
3510 yyn += YYTERROR;
3511 if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
3512 {
3513 yyn = yytable[yyn];
3514 if (0 < yyn)
3515 break;
3516 }
3517 }
3518
3519 /* Pop the current state because it cannot handle the error token. */
3520 if (yyssp == yyss)
Jari Aaltof73dda02001-11-13 17:56:06 +00003521 YYABORT;
Jari Aaltob80f6442004-07-27 13:29:18 +00003522
Jari Aaltob80f6442004-07-27 13:29:18 +00003523
Jari Aalto31859422009-01-12 13:36:28 +00003524 yydestruct ("Error: popping",
3525 yystos[yystate], yyvsp);
3526 YYPOPSTACK (1);
3527 yystate = *yyssp;
3528 YY_STACK_PRINT (yyss, yyssp);
Jari Aaltof73dda02001-11-13 17:56:06 +00003529 }
3530
Jari Aaltof73dda02001-11-13 17:56:06 +00003531 if (yyn == YYFINAL)
3532 YYACCEPT;
3533
Jari Aaltof73dda02001-11-13 17:56:06 +00003534 *++yyvsp = yylval;
Jari Aalto31859422009-01-12 13:36:28 +00003535
3536
3537 /* Shift the error token. */
3538 YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp);
Jari Aaltof73dda02001-11-13 17:56:06 +00003539
3540 yystate = yyn;
3541 goto yynewstate;
3542
Jari Aaltob80f6442004-07-27 13:29:18 +00003543
Jari Aalto31859422009-01-12 13:36:28 +00003544/*-------------------------------------.
3545| yyacceptlab -- YYACCEPT comes here. |
3546`-------------------------------------*/
3547yyacceptlab:
3548 yyresult = 0;
3549 goto yyreturn;
3550
3551/*-----------------------------------.
3552| yyabortlab -- YYABORT comes here. |
3553`-----------------------------------*/
3554yyabortlab:
3555 yyresult = 1;
3556 goto yyreturn;
3557
3558#ifndef yyoverflow
3559/*-------------------------------------------------.
3560| yyexhaustedlab -- memory exhaustion comes here. |
3561`-------------------------------------------------*/
3562yyexhaustedlab:
3563 yyerror (YY_("memory exhausted"));
3564 yyresult = 2;
3565 /* Fall through. */
Jari Aaltob80f6442004-07-27 13:29:18 +00003566#endif
Jari Aalto31859422009-01-12 13:36:28 +00003567
3568yyreturn:
3569 if (yychar != YYEOF && yychar != YYEMPTY)
3570 yydestruct ("Cleanup: discarding lookahead",
3571 yytoken, &yylval);
3572 /* Do not reclaim the symbols of the rule which action triggered
3573 this YYABORT or YYACCEPT. */
3574 YYPOPSTACK (yylen);
3575 YY_STACK_PRINT (yyss, yyssp);
3576 while (yyssp != yyss)
3577 {
3578 yydestruct ("Cleanup: popping",
3579 yystos[*yyssp], yyvsp);
3580 YYPOPSTACK (1);
Jari Aaltob80f6442004-07-27 13:29:18 +00003581 }
Jari Aalto31859422009-01-12 13:36:28 +00003582#ifndef yyoverflow
3583 if (yyss != yyssa)
3584 YYSTACK_FREE (yyss);
3585#endif
3586#if YYERROR_VERBOSE
3587 if (yymsg != yymsgbuf)
3588 YYSTACK_FREE (yymsg);
3589#endif
3590 /* Make sure YYID is used. */
3591 return YYID (yyresult);
Jari Aaltof73dda02001-11-13 17:56:06 +00003592}
Jari Aaltof73dda02001-11-13 17:56:06 +00003593
Jari Aalto726f6381996-08-26 18:22:31 +00003594
Chet Ramey80b4d712014-10-05 19:12:20 -04003595#line 1284 "/usr/src/local/bash/bash-4.3-patched/parse.y"
Jari Aalto31859422009-01-12 13:36:28 +00003596
Jari Aaltoccc6cda1996-12-23 17:02:34 +00003597
Jari Aalto726f6381996-08-26 18:22:31 +00003598/* Initial size to allocate for tokens, and the
3599 amount to grow them by. */
Jari Aaltod166f041997-06-05 14:59:13 +00003600#define TOKEN_DEFAULT_INITIAL_SIZE 496
Jari Aalto726f6381996-08-26 18:22:31 +00003601#define TOKEN_DEFAULT_GROW_SIZE 512
3602
Jari Aaltob80f6442004-07-27 13:29:18 +00003603/* Should we call prompt_again? */
3604#define SHOULD_PROMPT() \
3605 (interactive && (bash_input.type == st_stdin || bash_input.type == st_stream))
3606
3607#if defined (ALIAS)
3608# define expanding_alias() (pushed_string_list && pushed_string_list->expander)
3609#else
3610# define expanding_alias() 0
3611#endif
3612
Jari Aalto726f6381996-08-26 18:22:31 +00003613/* Global var is non-zero when end of file has been reached. */
3614int EOF_Reached = 0;
3615
Jari Aaltof73dda02001-11-13 17:56:06 +00003616#ifdef DEBUG
3617static void
Jari Aaltoccc6cda1996-12-23 17:02:34 +00003618debug_parser (i)
3619 int i;
3620{
3621#if YYDEBUG != 0
3622 yydebug = i;
3623#endif
3624}
Jari Aaltof73dda02001-11-13 17:56:06 +00003625#endif
Jari Aaltoccc6cda1996-12-23 17:02:34 +00003626
Jari Aalto726f6381996-08-26 18:22:31 +00003627/* yy_getc () returns the next available character from input or EOF.
3628 yy_ungetc (c) makes `c' the next character to read.
3629 init_yy_io (get, unget, type, location) makes the function GET the
3630 installed function for getting the next character, makes UNGET the
3631 installed function for un-getting a character, sets the type of stream
3632 (either string or file) from TYPE, and makes LOCATION point to where
3633 the input is coming from. */
3634
3635/* Unconditionally returns end-of-file. */
Jari Aaltoccc6cda1996-12-23 17:02:34 +00003636int
Jari Aalto726f6381996-08-26 18:22:31 +00003637return_EOF ()
3638{
3639 return (EOF);
3640}
3641
3642/* Variable containing the current get and unget functions.
3643 See ./input.h for a clearer description. */
3644BASH_INPUT bash_input;
3645
Jari Aaltoccc6cda1996-12-23 17:02:34 +00003646/* Set all of the fields in BASH_INPUT to NULL. Free bash_input.name if it
3647 is non-null, avoiding a memory leak. */
Jari Aalto726f6381996-08-26 18:22:31 +00003648void
3649initialize_bash_input ()
3650{
Jari Aaltoccc6cda1996-12-23 17:02:34 +00003651 bash_input.type = st_none;
3652 FREE (bash_input.name);
Jari Aalto726f6381996-08-26 18:22:31 +00003653 bash_input.name = (char *)NULL;
3654 bash_input.location.file = (FILE *)NULL;
3655 bash_input.location.string = (char *)NULL;
Jari Aaltof73dda02001-11-13 17:56:06 +00003656 bash_input.getter = (sh_cget_func_t *)NULL;
3657 bash_input.ungetter = (sh_cunget_func_t *)NULL;
Jari Aalto726f6381996-08-26 18:22:31 +00003658}
3659
3660/* Set the contents of the current bash input stream from
3661 GET, UNGET, TYPE, NAME, and LOCATION. */
3662void
3663init_yy_io (get, unget, type, name, location)
Jari Aaltof73dda02001-11-13 17:56:06 +00003664 sh_cget_func_t *get;
3665 sh_cunget_func_t *unget;
Jari Aaltod166f041997-06-05 14:59:13 +00003666 enum stream_type type;
Jari Aaltof73dda02001-11-13 17:56:06 +00003667 const char *name;
Jari Aalto726f6381996-08-26 18:22:31 +00003668 INPUT_STREAM location;
3669{
3670 bash_input.type = type;
3671 FREE (bash_input.name);
Jari Aaltoccc6cda1996-12-23 17:02:34 +00003672 bash_input.name = name ? savestring (name) : (char *)NULL;
Jari Aalto726f6381996-08-26 18:22:31 +00003673
Jari Aaltoccc6cda1996-12-23 17:02:34 +00003674 /* XXX */
Jari Aalto726f6381996-08-26 18:22:31 +00003675#if defined (CRAY)
3676 memcpy((char *)&bash_input.location.string, (char *)&location.string, sizeof(location));
3677#else
3678 bash_input.location = location;
3679#endif
3680 bash_input.getter = get;
3681 bash_input.ungetter = unget;
3682}
3683
Jari Aalto7117c2d2002-07-17 14:10:11 +00003684char *
3685yy_input_name ()
3686{
3687 return (bash_input.name ? bash_input.name : "stdin");
3688}
3689
Jari Aalto726f6381996-08-26 18:22:31 +00003690/* Call this to get the next character of input. */
Jari Aaltof73dda02001-11-13 17:56:06 +00003691static int
Jari Aalto726f6381996-08-26 18:22:31 +00003692yy_getc ()
3693{
3694 return (*(bash_input.getter)) ();
3695}
3696
3697/* Call this to unget C. That is, to make C the next character
3698 to be read. */
Jari Aaltof73dda02001-11-13 17:56:06 +00003699static int
Jari Aalto726f6381996-08-26 18:22:31 +00003700yy_ungetc (c)
3701 int c;
3702{
3703 return (*(bash_input.ungetter)) (c);
3704}
3705
3706#if defined (BUFFERED_INPUT)
Jari Aaltof73dda02001-11-13 17:56:06 +00003707#ifdef INCLUDE_UNUSED
Jari Aalto726f6381996-08-26 18:22:31 +00003708int
3709input_file_descriptor ()
3710{
3711 switch (bash_input.type)
3712 {
3713 case st_stream:
3714 return (fileno (bash_input.location.file));
3715 case st_bstream:
3716 return (bash_input.location.buffered_fd);
Jari Aaltoccc6cda1996-12-23 17:02:34 +00003717 case st_stdin:
Jari Aalto726f6381996-08-26 18:22:31 +00003718 default:
3719 return (fileno (stdin));
3720 }
3721}
Jari Aaltof73dda02001-11-13 17:56:06 +00003722#endif
Jari Aalto726f6381996-08-26 18:22:31 +00003723#endif /* BUFFERED_INPUT */
3724
3725/* **************************************************************** */
3726/* */
3727/* Let input be read from readline (). */
3728/* */
3729/* **************************************************************** */
3730
3731#if defined (READLINE)
3732char *current_readline_prompt = (char *)NULL;
3733char *current_readline_line = (char *)NULL;
3734int current_readline_line_index = 0;
3735
3736static int
3737yy_readline_get ()
3738{
Jari Aaltoccc6cda1996-12-23 17:02:34 +00003739 SigHandler *old_sigint;
Jari Aaltof73dda02001-11-13 17:56:06 +00003740 int line_len;
3741 unsigned char c;
Jari Aaltoccc6cda1996-12-23 17:02:34 +00003742
Jari Aalto726f6381996-08-26 18:22:31 +00003743 if (!current_readline_line)
3744 {
Jari Aalto726f6381996-08-26 18:22:31 +00003745 if (!bash_readline_initialized)
3746 initialize_readline ();
3747
3748#if defined (JOB_CONTROL)
3749 if (job_control)
Jari Aalto28ef6c32001-04-06 19:14:31 +00003750 give_terminal_to (shell_pgrp, 0);
Jari Aalto726f6381996-08-26 18:22:31 +00003751#endif /* JOB_CONTROL */
3752
Chet Ramey495aee42011-11-22 19:11:26 -05003753 old_sigint = (SigHandler *)IMPOSSIBLE_TRAP_HANDLER;
Jari Aalto726f6381996-08-26 18:22:31 +00003754 if (signal_is_ignored (SIGINT) == 0)
3755 {
Chet Rameyac50fba2014-02-26 09:36:43 -05003756 /* interrupt_immediately++; */
Chet Ramey495aee42011-11-22 19:11:26 -05003757 old_sigint = (SigHandler *)set_signal_handler (SIGINT, sigint_sighandler);
Jari Aalto726f6381996-08-26 18:22:31 +00003758 }
3759
Jari Aaltoccc6cda1996-12-23 17:02:34 +00003760 current_readline_line = readline (current_readline_prompt ?
3761 current_readline_prompt : "");
Jari Aalto726f6381996-08-26 18:22:31 +00003762
Chet Rameyac50fba2014-02-26 09:36:43 -05003763 CHECK_TERMSIG;
Chet Ramey495aee42011-11-22 19:11:26 -05003764 if (signal_is_ignored (SIGINT) == 0)
Jari Aalto726f6381996-08-26 18:22:31 +00003765 {
Chet Rameyac50fba2014-02-26 09:36:43 -05003766 /* interrupt_immediately--; */
Chet Ramey495aee42011-11-22 19:11:26 -05003767 if (old_sigint != IMPOSSIBLE_TRAP_HANDLER)
3768 set_signal_handler (SIGINT, old_sigint);
Jari Aalto726f6381996-08-26 18:22:31 +00003769 }
3770
Jari Aaltoccc6cda1996-12-23 17:02:34 +00003771#if 0
3772 /* Reset the prompt to the decoded value of prompt_string_pointer. */
Jari Aalto726f6381996-08-26 18:22:31 +00003773 reset_readline_prompt ();
Jari Aaltoccc6cda1996-12-23 17:02:34 +00003774#endif
Jari Aalto726f6381996-08-26 18:22:31 +00003775
Jari Aaltoccc6cda1996-12-23 17:02:34 +00003776 if (current_readline_line == 0)
Jari Aalto726f6381996-08-26 18:22:31 +00003777 return (EOF);
3778
Jari Aaltoccc6cda1996-12-23 17:02:34 +00003779 current_readline_line_index = 0;
Jari Aalto726f6381996-08-26 18:22:31 +00003780 line_len = strlen (current_readline_line);
Jari Aaltoccc6cda1996-12-23 17:02:34 +00003781
Jari Aaltof73dda02001-11-13 17:56:06 +00003782 current_readline_line = (char *)xrealloc (current_readline_line, 2 + line_len);
Jari Aalto726f6381996-08-26 18:22:31 +00003783 current_readline_line[line_len++] = '\n';
3784 current_readline_line[line_len] = '\0';
3785 }
3786
Jari Aaltoccc6cda1996-12-23 17:02:34 +00003787 if (current_readline_line[current_readline_line_index] == 0)
Jari Aalto726f6381996-08-26 18:22:31 +00003788 {
3789 free (current_readline_line);
3790 current_readline_line = (char *)NULL;
3791 return (yy_readline_get ());
3792 }
3793 else
3794 {
Jari Aaltof73dda02001-11-13 17:56:06 +00003795 c = current_readline_line[current_readline_line_index++];
Jari Aalto726f6381996-08-26 18:22:31 +00003796 return (c);
3797 }
3798}
3799
3800static int
3801yy_readline_unget (c)
Jari Aaltoccc6cda1996-12-23 17:02:34 +00003802 int c;
Jari Aalto726f6381996-08-26 18:22:31 +00003803{
3804 if (current_readline_line_index && current_readline_line)
3805 current_readline_line[--current_readline_line_index] = c;
3806 return (c);
3807}
3808
Jari Aaltoccc6cda1996-12-23 17:02:34 +00003809void
Jari Aalto726f6381996-08-26 18:22:31 +00003810with_input_from_stdin ()
3811{
3812 INPUT_STREAM location;
3813
3814 if (bash_input.type != st_stdin && stream_on_stack (st_stdin) == 0)
3815 {
3816 location.string = current_readline_line;
3817 init_yy_io (yy_readline_get, yy_readline_unget,
3818 st_stdin, "readline stdin", location);
3819 }
3820}
3821
3822#else /* !READLINE */
3823
3824void
3825with_input_from_stdin ()
3826{
3827 with_input_from_stream (stdin, "stdin");
3828}
3829#endif /* !READLINE */
3830
3831/* **************************************************************** */
3832/* */
3833/* Let input come from STRING. STRING is zero terminated. */
3834/* */
3835/* **************************************************************** */
3836
3837static int
3838yy_string_get ()
3839{
Jari Aaltoccc6cda1996-12-23 17:02:34 +00003840 register char *string;
Jari Aaltof73dda02001-11-13 17:56:06 +00003841 register unsigned char c;
Jari Aalto726f6381996-08-26 18:22:31 +00003842
3843 string = bash_input.location.string;
Jari Aalto726f6381996-08-26 18:22:31 +00003844
3845 /* If the string doesn't exist, or is empty, EOF found. */
3846 if (string && *string)
3847 {
Jari Aaltof73dda02001-11-13 17:56:06 +00003848 c = *string++;
Jari Aalto726f6381996-08-26 18:22:31 +00003849 bash_input.location.string = string;
Jari Aaltof73dda02001-11-13 17:56:06 +00003850 return (c);
Jari Aalto726f6381996-08-26 18:22:31 +00003851 }
Jari Aaltof73dda02001-11-13 17:56:06 +00003852 else
3853 return (EOF);
Jari Aalto726f6381996-08-26 18:22:31 +00003854}
3855
3856static int
3857yy_string_unget (c)
3858 int c;
3859{
3860 *(--bash_input.location.string) = c;
3861 return (c);
3862}
3863
3864void
3865with_input_from_string (string, name)
Jari Aaltof73dda02001-11-13 17:56:06 +00003866 char *string;
3867 const char *name;
Jari Aalto726f6381996-08-26 18:22:31 +00003868{
3869 INPUT_STREAM location;
3870
3871 location.string = string;
Jari Aalto726f6381996-08-26 18:22:31 +00003872 init_yy_io (yy_string_get, yy_string_unget, st_string, name, location);
3873}
3874
Jari Aalto31859422009-01-12 13:36:28 +00003875/* Count the number of characters we've consumed from bash_input.location.string
3876 and read into shell_input_line, but have not returned from shell_getc.
3877 That is the true input location. Rewind bash_input.location.string by
3878 that number of characters, so it points to the last character actually
3879 consumed by the parser. */
3880static void
3881rewind_input_string ()
3882{
3883 int xchars;
3884
3885 /* number of unconsumed characters in the input -- XXX need to take newlines
3886 into account, e.g., $(...\n) */
3887 xchars = shell_input_line_len - shell_input_line_index;
3888 if (bash_input.location.string[-1] == '\n')
3889 xchars++;
3890
3891 /* XXX - how to reflect bash_input.location.string back to string passed to
3892 parse_and_execute or xparse_dolparen? xparse_dolparen needs to know how
3893 far into the string we parsed. parse_and_execute knows where bash_input.
3894 location.string is, and how far from orig_string that is -- that's the
3895 number of characters the command consumed. */
3896
3897 /* bash_input.location.string - xchars should be where we parsed to */
3898 /* need to do more validation on xchars value for sanity -- test cases. */
3899 bash_input.location.string -= xchars;
3900}
3901
Jari Aalto726f6381996-08-26 18:22:31 +00003902/* **************************************************************** */
3903/* */
3904/* Let input come from STREAM. */
3905/* */
3906/* **************************************************************** */
3907
Jari Aaltobb706242000-03-17 21:46:59 +00003908/* These two functions used to test the value of the HAVE_RESTARTABLE_SYSCALLS
3909 define, and just use getc/ungetc if it was defined, but since bash
3910 installs its signal handlers without the SA_RESTART flag, some signals
3911 (like SIGCHLD, SIGWINCH, etc.) received during a read(2) will not cause
3912 the read to be restarted. We need to restart it ourselves. */
3913
Jari Aalto726f6381996-08-26 18:22:31 +00003914static int
3915yy_stream_get ()
3916{
Jari Aaltobb706242000-03-17 21:46:59 +00003917 int result;
Jari Aalto726f6381996-08-26 18:22:31 +00003918
Jari Aaltobb706242000-03-17 21:46:59 +00003919 result = EOF;
Jari Aalto726f6381996-08-26 18:22:31 +00003920 if (bash_input.location.file)
Jari Aalto95732b42005-12-07 14:08:12 +00003921 {
Chet Rameyac50fba2014-02-26 09:36:43 -05003922#if 0
Jari Aalto95732b42005-12-07 14:08:12 +00003923 if (interactive)
Chet Rameyac50fba2014-02-26 09:36:43 -05003924 interrupt_immediately++;
3925#endif
3926
3927 /* XXX - don't need terminate_immediately; getc_with_restart checks
3928 for terminating signals itself if read returns < 0 */
Jari Aalto95732b42005-12-07 14:08:12 +00003929 result = getc_with_restart (bash_input.location.file);
Chet Rameyac50fba2014-02-26 09:36:43 -05003930
3931#if 0
Jari Aalto95732b42005-12-07 14:08:12 +00003932 if (interactive)
Chet Rameyac50fba2014-02-26 09:36:43 -05003933 interrupt_immediately--;
3934#endif
Jari Aalto95732b42005-12-07 14:08:12 +00003935 }
Jari Aalto726f6381996-08-26 18:22:31 +00003936 return (result);
3937}
3938
3939static int
3940yy_stream_unget (c)
3941 int c;
3942{
Jari Aalto726f6381996-08-26 18:22:31 +00003943 return (ungetc_with_restart (c, bash_input.location.file));
Jari Aalto726f6381996-08-26 18:22:31 +00003944}
3945
3946void
3947with_input_from_stream (stream, name)
3948 FILE *stream;
Jari Aaltof73dda02001-11-13 17:56:06 +00003949 const char *name;
Jari Aalto726f6381996-08-26 18:22:31 +00003950{
3951 INPUT_STREAM location;
3952
3953 location.file = stream;
3954 init_yy_io (yy_stream_get, yy_stream_unget, st_stream, name, location);
3955}
3956
3957typedef struct stream_saver {
3958 struct stream_saver *next;
3959 BASH_INPUT bash_input;
3960 int line;
3961#if defined (BUFFERED_INPUT)
3962 BUFFERED_STREAM *bstream;
3963#endif /* BUFFERED_INPUT */
3964} STREAM_SAVER;
3965
3966/* The globally known line number. */
3967int line_number = 0;
3968
Chet Ramey495aee42011-11-22 19:11:26 -05003969/* The line number offset set by assigning to LINENO. Not currently used. */
3970int line_number_base = 0;
3971
Jari Aaltocce855b1998-04-17 19:52:44 +00003972#if defined (COND_COMMAND)
3973static int cond_lineno;
3974static int cond_token;
3975#endif
3976
Jari Aalto726f6381996-08-26 18:22:31 +00003977STREAM_SAVER *stream_list = (STREAM_SAVER *)NULL;
3978
Jari Aaltoccc6cda1996-12-23 17:02:34 +00003979void
3980push_stream (reset_lineno)
3981 int reset_lineno;
Jari Aalto726f6381996-08-26 18:22:31 +00003982{
3983 STREAM_SAVER *saver = (STREAM_SAVER *)xmalloc (sizeof (STREAM_SAVER));
3984
3985 xbcopy ((char *)&bash_input, (char *)&(saver->bash_input), sizeof (BASH_INPUT));
3986
3987#if defined (BUFFERED_INPUT)
3988 saver->bstream = (BUFFERED_STREAM *)NULL;
3989 /* If we have a buffered stream, clear out buffers[fd]. */
3990 if (bash_input.type == st_bstream && bash_input.location.buffered_fd >= 0)
Jari Aaltocce855b1998-04-17 19:52:44 +00003991 saver->bstream = set_buffered_stream (bash_input.location.buffered_fd,
3992 (BUFFERED_STREAM *)NULL);
Jari Aalto726f6381996-08-26 18:22:31 +00003993#endif /* BUFFERED_INPUT */
3994
3995 saver->line = line_number;
3996 bash_input.name = (char *)NULL;
3997 saver->next = stream_list;
3998 stream_list = saver;
Jari Aaltoccc6cda1996-12-23 17:02:34 +00003999 EOF_Reached = 0;
4000 if (reset_lineno)
4001 line_number = 0;
Jari Aalto726f6381996-08-26 18:22:31 +00004002}
4003
Jari Aaltoccc6cda1996-12-23 17:02:34 +00004004void
Jari Aalto726f6381996-08-26 18:22:31 +00004005pop_stream ()
4006{
Jari Aalto726f6381996-08-26 18:22:31 +00004007 if (!stream_list)
4008 EOF_Reached = 1;
4009 else
4010 {
4011 STREAM_SAVER *saver = stream_list;
4012
4013 EOF_Reached = 0;
4014 stream_list = stream_list->next;
4015
4016 init_yy_io (saver->bash_input.getter,
4017 saver->bash_input.ungetter,
4018 saver->bash_input.type,
4019 saver->bash_input.name,
4020 saver->bash_input.location);
4021
4022#if defined (BUFFERED_INPUT)
4023 /* If we have a buffered stream, restore buffers[fd]. */
4024 /* If the input file descriptor was changed while this was on the
4025 save stack, update the buffered fd to the new file descriptor and
4026 re-establish the buffer <-> bash_input fd correspondence. */
4027 if (bash_input.type == st_bstream && bash_input.location.buffered_fd >= 0)
Jari Aalto28ef6c32001-04-06 19:14:31 +00004028 {
4029 if (bash_input_fd_changed)
Jari Aalto726f6381996-08-26 18:22:31 +00004030 {
4031 bash_input_fd_changed = 0;
4032 if (default_buffered_input >= 0)
4033 {
4034 bash_input.location.buffered_fd = default_buffered_input;
4035 saver->bstream->b_fd = default_buffered_input;
Jari Aalto28ef6c32001-04-06 19:14:31 +00004036 SET_CLOSE_ON_EXEC (default_buffered_input);
Jari Aalto726f6381996-08-26 18:22:31 +00004037 }
4038 }
Jari Aalto28ef6c32001-04-06 19:14:31 +00004039 /* XXX could free buffered stream returned as result here. */
Jari Aaltocce855b1998-04-17 19:52:44 +00004040 set_buffered_stream (bash_input.location.buffered_fd, saver->bstream);
Jari Aalto28ef6c32001-04-06 19:14:31 +00004041 }
Jari Aalto726f6381996-08-26 18:22:31 +00004042#endif /* BUFFERED_INPUT */
4043
4044 line_number = saver->line;
4045
4046 FREE (saver->bash_input.name);
4047 free (saver);
4048 }
4049}
4050
4051/* Return 1 if a stream of type TYPE is saved on the stack. */
4052int
4053stream_on_stack (type)
Jari Aaltoccc6cda1996-12-23 17:02:34 +00004054 enum stream_type type;
Jari Aalto726f6381996-08-26 18:22:31 +00004055{
4056 register STREAM_SAVER *s;
Jari Aaltoccc6cda1996-12-23 17:02:34 +00004057
Jari Aalto726f6381996-08-26 18:22:31 +00004058 for (s = stream_list; s; s = s->next)
4059 if (s->bash_input.type == type)
4060 return 1;
4061 return 0;
4062}
4063
Jari Aaltobb706242000-03-17 21:46:59 +00004064/* Save the current token state and return it in a malloced array. */
4065int *
4066save_token_state ()
4067{
4068 int *ret;
4069
Chet Ramey00018032011-11-21 20:51:19 -05004070 ret = (int *)xmalloc (4 * sizeof (int));
Jari Aaltobb706242000-03-17 21:46:59 +00004071 ret[0] = last_read_token;
4072 ret[1] = token_before_that;
4073 ret[2] = two_tokens_ago;
Chet Ramey00018032011-11-21 20:51:19 -05004074 ret[3] = current_token;
Jari Aaltobb706242000-03-17 21:46:59 +00004075 return ret;
4076}
4077
4078void
4079restore_token_state (ts)
4080 int *ts;
4081{
4082 if (ts == 0)
4083 return;
4084 last_read_token = ts[0];
4085 token_before_that = ts[1];
4086 two_tokens_ago = ts[2];
Chet Ramey00018032011-11-21 20:51:19 -05004087 current_token = ts[3];
Jari Aaltobb706242000-03-17 21:46:59 +00004088}
4089
Jari Aalto726f6381996-08-26 18:22:31 +00004090/*
4091 * This is used to inhibit alias expansion and reserved word recognition
Jari Aaltoccc6cda1996-12-23 17:02:34 +00004092 * inside case statement pattern lists. A `case statement pattern list' is:
4093 *
Jari Aalto726f6381996-08-26 18:22:31 +00004094 * everything between the `in' in a `case word in' and the next ')'
4095 * or `esac'
4096 * everything between a `;;' and the next `)' or `esac'
4097 */
Jari Aalto726f6381996-08-26 18:22:31 +00004098
Jari Aaltocce855b1998-04-17 19:52:44 +00004099#if defined (ALIAS) || defined (DPAREN_ARITHMETIC)
4100
Jari Aaltoccc6cda1996-12-23 17:02:34 +00004101#define END_OF_ALIAS 0
4102
Jari Aalto726f6381996-08-26 18:22:31 +00004103/*
4104 * Pseudo-global variables used in implementing token-wise alias expansion.
4105 */
4106
Jari Aalto726f6381996-08-26 18:22:31 +00004107/*
Jari Aaltoccc6cda1996-12-23 17:02:34 +00004108 * Pushing and popping strings. This works together with shell_getc to
Jari Aalto726f6381996-08-26 18:22:31 +00004109 * implement alias expansion on a per-token basis.
4110 */
4111
Chet Rameyac50fba2014-02-26 09:36:43 -05004112#define PSH_ALIAS 0x01
4113#define PSH_DPAREN 0x02
4114#define PSH_SOURCE 0x04
4115
Jari Aalto726f6381996-08-26 18:22:31 +00004116typedef struct string_saver {
4117 struct string_saver *next;
4118 int expand_alias; /* Value to set expand_alias to when string is popped. */
4119 char *saved_line;
Jari Aaltocce855b1998-04-17 19:52:44 +00004120#if defined (ALIAS)
Jari Aaltoccc6cda1996-12-23 17:02:34 +00004121 alias_t *expander; /* alias that caused this line to be pushed. */
Jari Aaltocce855b1998-04-17 19:52:44 +00004122#endif
Chet Rameyac50fba2014-02-26 09:36:43 -05004123 size_t saved_line_size, saved_line_index;
4124 int saved_line_terminator;
4125 int flags;
Jari Aalto726f6381996-08-26 18:22:31 +00004126} STRING_SAVER;
4127
4128STRING_SAVER *pushed_string_list = (STRING_SAVER *)NULL;
4129
Jari Aalto726f6381996-08-26 18:22:31 +00004130/*
4131 * Push the current shell_input_line onto a stack of such lines and make S
4132 * the current input. Used when expanding aliases. EXPAND is used to set
4133 * the value of expand_next_token when the string is popped, so that the
4134 * word after the alias in the original line is handled correctly when the
4135 * alias expands to multiple words. TOKEN is the token that was expanded
4136 * into S; it is saved and used to prevent infinite recursive expansion.
4137 */
4138static void
Jari Aaltoccc6cda1996-12-23 17:02:34 +00004139push_string (s, expand, ap)
Jari Aalto726f6381996-08-26 18:22:31 +00004140 char *s;
4141 int expand;
Jari Aaltoccc6cda1996-12-23 17:02:34 +00004142 alias_t *ap;
Jari Aalto726f6381996-08-26 18:22:31 +00004143{
Jari Aaltof73dda02001-11-13 17:56:06 +00004144 STRING_SAVER *temp = (STRING_SAVER *)xmalloc (sizeof (STRING_SAVER));
Jari Aalto726f6381996-08-26 18:22:31 +00004145
4146 temp->expand_alias = expand;
4147 temp->saved_line = shell_input_line;
4148 temp->saved_line_size = shell_input_line_size;
4149 temp->saved_line_index = shell_input_line_index;
4150 temp->saved_line_terminator = shell_input_line_terminator;
Chet Rameyac50fba2014-02-26 09:36:43 -05004151 temp->flags = 0;
Jari Aaltocce855b1998-04-17 19:52:44 +00004152#if defined (ALIAS)
Jari Aaltoccc6cda1996-12-23 17:02:34 +00004153 temp->expander = ap;
Chet Rameyac50fba2014-02-26 09:36:43 -05004154 if (ap)
4155 temp->flags = PSH_ALIAS;
Jari Aaltocce855b1998-04-17 19:52:44 +00004156#endif
Jari Aalto726f6381996-08-26 18:22:31 +00004157 temp->next = pushed_string_list;
4158 pushed_string_list = temp;
4159
Jari Aaltocce855b1998-04-17 19:52:44 +00004160#if defined (ALIAS)
Jari Aaltod166f041997-06-05 14:59:13 +00004161 if (ap)
4162 ap->flags |= AL_BEINGEXPANDED;
Jari Aaltocce855b1998-04-17 19:52:44 +00004163#endif
Jari Aalto726f6381996-08-26 18:22:31 +00004164
4165 shell_input_line = s;
Chet Rameyac50fba2014-02-26 09:36:43 -05004166 shell_input_line_size = STRLEN (s);
Jari Aalto726f6381996-08-26 18:22:31 +00004167 shell_input_line_index = 0;
4168 shell_input_line_terminator = '\0';
Jari Aaltob80f6442004-07-27 13:29:18 +00004169#if 0
4170 parser_state &= ~PST_ALEXPNEXT; /* XXX */
4171#endif
Jari Aalto7117c2d2002-07-17 14:10:11 +00004172
4173 set_line_mbstate ();
Jari Aalto726f6381996-08-26 18:22:31 +00004174}
4175
4176/*
4177 * Make the top of the pushed_string stack be the current shell input.
4178 * Only called when there is something on the stack. Called from shell_getc
4179 * when it thinks it has consumed the string generated by an alias expansion
4180 * and needs to return to the original input line.
4181 */
4182static void
4183pop_string ()
4184{
4185 STRING_SAVER *t;
4186
4187 FREE (shell_input_line);
4188 shell_input_line = pushed_string_list->saved_line;
4189 shell_input_line_index = pushed_string_list->saved_line_index;
4190 shell_input_line_size = pushed_string_list->saved_line_size;
4191 shell_input_line_terminator = pushed_string_list->saved_line_terminator;
Jari Aaltoccc6cda1996-12-23 17:02:34 +00004192
4193 if (pushed_string_list->expand_alias)
4194 parser_state |= PST_ALEXPNEXT;
4195 else
4196 parser_state &= ~PST_ALEXPNEXT;
Jari Aalto726f6381996-08-26 18:22:31 +00004197
4198 t = pushed_string_list;
4199 pushed_string_list = pushed_string_list->next;
Jari Aaltoccc6cda1996-12-23 17:02:34 +00004200
Jari Aaltocce855b1998-04-17 19:52:44 +00004201#if defined (ALIAS)
Jari Aaltod166f041997-06-05 14:59:13 +00004202 if (t->expander)
4203 t->expander->flags &= ~AL_BEINGEXPANDED;
Jari Aaltocce855b1998-04-17 19:52:44 +00004204#endif
Jari Aaltoccc6cda1996-12-23 17:02:34 +00004205
4206 free ((char *)t);
Jari Aalto7117c2d2002-07-17 14:10:11 +00004207
4208 set_line_mbstate ();
Jari Aalto726f6381996-08-26 18:22:31 +00004209}
4210
4211static void
4212free_string_list ()
4213{
Jari Aaltoccc6cda1996-12-23 17:02:34 +00004214 register STRING_SAVER *t, *t1;
Jari Aalto726f6381996-08-26 18:22:31 +00004215
Jari Aaltoccc6cda1996-12-23 17:02:34 +00004216 for (t = pushed_string_list; t; )
Jari Aalto726f6381996-08-26 18:22:31 +00004217 {
4218 t1 = t->next;
4219 FREE (t->saved_line);
Jari Aaltocce855b1998-04-17 19:52:44 +00004220#if defined (ALIAS)
4221 if (t->expander)
4222 t->expander->flags &= ~AL_BEINGEXPANDED;
4223#endif
Jari Aalto726f6381996-08-26 18:22:31 +00004224 free ((char *)t);
4225 t = t1;
4226 }
4227 pushed_string_list = (STRING_SAVER *)NULL;
4228}
4229
Jari Aaltocce855b1998-04-17 19:52:44 +00004230#endif /* ALIAS || DPAREN_ARITHMETIC */
Jari Aaltoccc6cda1996-12-23 17:02:34 +00004231
Jari Aaltob80f6442004-07-27 13:29:18 +00004232void
4233free_pushed_string_input ()
4234{
4235#if defined (ALIAS) || defined (DPAREN_ARITHMETIC)
4236 free_string_list ();
4237#endif
4238}
4239
Chet Rameyac50fba2014-02-26 09:36:43 -05004240int
4241parser_expanding_alias ()
4242{
4243 return (expanding_alias ());
4244}
4245
4246void
4247parser_save_alias ()
4248{
4249#if defined (ALIAS) || defined (DPAREN_ARITHMETIC)
4250 push_string ((char *)NULL, 0, (alias_t *)NULL);
4251 pushed_string_list->flags = PSH_SOURCE; /* XXX - for now */
4252#else
4253 ;
4254#endif
4255}
4256
4257void
4258parser_restore_alias ()
4259{
4260#if defined (ALIAS) || defined (DPAREN_ARITHMETIC)
4261 if (pushed_string_list)
4262 pop_string ();
4263#else
4264 ;
4265#endif
4266}
4267
Jari Aalto726f6381996-08-26 18:22:31 +00004268/* Return a line of text, taken from wherever yylex () reads input.
4269 If there is no more input, then we return NULL. If REMOVE_QUOTED_NEWLINE
4270 is non-zero, we remove unquoted \<newline> pairs. This is used by
4271 read_secondary_line to read here documents. */
4272static char *
4273read_a_line (remove_quoted_newline)
4274 int remove_quoted_newline;
4275{
4276 static char *line_buffer = (char *)NULL;
4277 static int buffer_size = 0;
Chet Ramey00018032011-11-21 20:51:19 -05004278 int indx, c, peekc, pass_next;
Jari Aalto726f6381996-08-26 18:22:31 +00004279
Jari Aaltoccc6cda1996-12-23 17:02:34 +00004280#if defined (READLINE)
Jari Aaltob80f6442004-07-27 13:29:18 +00004281 if (no_line_editing && SHOULD_PROMPT ())
Jari Aaltoccc6cda1996-12-23 17:02:34 +00004282#else
Jari Aaltob80f6442004-07-27 13:29:18 +00004283 if (SHOULD_PROMPT ())
Jari Aaltoccc6cda1996-12-23 17:02:34 +00004284#endif
4285 print_prompt ();
4286
Chet Ramey00018032011-11-21 20:51:19 -05004287 pass_next = indx = 0;
Jari Aalto726f6381996-08-26 18:22:31 +00004288 while (1)
4289 {
Jari Aalto726f6381996-08-26 18:22:31 +00004290 /* Allow immediate exit if interrupted during input. */
4291 QUIT;
4292
Jari Aalto95732b42005-12-07 14:08:12 +00004293 c = yy_getc ();
4294
Jari Aalto28ef6c32001-04-06 19:14:31 +00004295 /* Ignore null bytes in input. */
Jari Aalto726f6381996-08-26 18:22:31 +00004296 if (c == 0)
Jari Aalto28ef6c32001-04-06 19:14:31 +00004297 {
4298#if 0
4299 internal_warning ("read_a_line: ignored null byte in input");
4300#endif
4301 continue;
4302 }
Jari Aalto726f6381996-08-26 18:22:31 +00004303
4304 /* If there is no more input, then we return NULL. */
4305 if (c == EOF)
4306 {
Jari Aaltoccc6cda1996-12-23 17:02:34 +00004307 if (interactive && bash_input.type == st_stream)
4308 clearerr (stdin);
Jari Aalto726f6381996-08-26 18:22:31 +00004309 if (indx == 0)
4310 return ((char *)NULL);
4311 c = '\n';
4312 }
4313
4314 /* `+2' in case the final character in the buffer is a newline. */
Jari Aaltoccc6cda1996-12-23 17:02:34 +00004315 RESIZE_MALLOCED_BUFFER (line_buffer, indx, 2, buffer_size, 128);
Jari Aalto726f6381996-08-26 18:22:31 +00004316
4317 /* IF REMOVE_QUOTED_NEWLINES is non-zero, we are reading a
4318 here document with an unquoted delimiter. In this case,
4319 the line will be expanded as if it were in double quotes.
4320 We allow a backslash to escape the next character, but we
4321 need to treat the backslash specially only if a backslash
4322 quoting a backslash-newline pair appears in the line. */
4323 if (pass_next)
Jari Aalto28ef6c32001-04-06 19:14:31 +00004324 {
Jari Aalto726f6381996-08-26 18:22:31 +00004325 line_buffer[indx++] = c;
4326 pass_next = 0;
Jari Aalto28ef6c32001-04-06 19:14:31 +00004327 }
Jari Aalto726f6381996-08-26 18:22:31 +00004328 else if (c == '\\' && remove_quoted_newline)
4329 {
Chet Ramey495aee42011-11-22 19:11:26 -05004330 QUIT;
Jari Aalto726f6381996-08-26 18:22:31 +00004331 peekc = yy_getc ();
4332 if (peekc == '\n')
Jari Aaltob80f6442004-07-27 13:29:18 +00004333 {
4334 line_number++;
4335 continue; /* Make the unquoted \<newline> pair disappear. */
4336 }
Jari Aalto726f6381996-08-26 18:22:31 +00004337 else
4338 {
4339 yy_ungetc (peekc);
4340 pass_next = 1;
4341 line_buffer[indx++] = c; /* Preserve the backslash. */
4342 }
4343 }
4344 else
4345 line_buffer[indx++] = c;
4346
4347 if (c == '\n')
4348 {
4349 line_buffer[indx] = '\0';
4350 return (line_buffer);
4351 }
4352 }
4353}
4354
4355/* Return a line as in read_a_line (), but insure that the prompt is
4356 the secondary prompt. This is used to read the lines of a here
4357 document. REMOVE_QUOTED_NEWLINE is non-zero if we should remove
4358 newlines quoted with backslashes while reading the line. It is
4359 non-zero unless the delimiter of the here document was quoted. */
4360char *
4361read_secondary_line (remove_quoted_newline)
4362 int remove_quoted_newline;
4363{
Jari Aalto31859422009-01-12 13:36:28 +00004364 char *ret;
4365 int n, c;
4366
Jari Aalto726f6381996-08-26 18:22:31 +00004367 prompt_string_pointer = &ps2_prompt;
Jari Aaltob80f6442004-07-27 13:29:18 +00004368 if (SHOULD_PROMPT())
4369 prompt_again ();
Jari Aalto31859422009-01-12 13:36:28 +00004370 ret = read_a_line (remove_quoted_newline);
4371#if defined (HISTORY)
Chet Ramey00018032011-11-21 20:51:19 -05004372 if (ret && remember_on_history && (parser_state & PST_HEREDOC))
Jari Aalto31859422009-01-12 13:36:28 +00004373 {
4374 /* To make adding the the here-document body right, we need to rely
4375 on history_delimiting_chars() returning \n for the first line of
4376 the here-document body and the null string for the second and
4377 subsequent lines, so we avoid double newlines.
4378 current_command_line_count == 2 for the first line of the body. */
4379
4380 current_command_line_count++;
4381 maybe_add_history (ret);
4382 }
4383#endif /* HISTORY */
4384 return ret;
Jari Aalto726f6381996-08-26 18:22:31 +00004385}
4386
Jari Aalto726f6381996-08-26 18:22:31 +00004387/* **************************************************************** */
4388/* */
4389/* YYLEX () */
4390/* */
4391/* **************************************************************** */
4392
4393/* Reserved words. These are only recognized as the first word of a
4394 command. */
4395STRING_INT_ALIST word_token_alist[] = {
4396 { "if", IF },
4397 { "then", THEN },
4398 { "else", ELSE },
4399 { "elif", ELIF },
4400 { "fi", FI },
4401 { "case", CASE },
4402 { "esac", ESAC },
4403 { "for", FOR },
4404#if defined (SELECT_COMMAND)
4405 { "select", SELECT },
4406#endif
4407 { "while", WHILE },
4408 { "until", UNTIL },
4409 { "do", DO },
4410 { "done", DONE },
4411 { "in", IN },
4412 { "function", FUNCTION },
Jari Aaltoccc6cda1996-12-23 17:02:34 +00004413#if defined (COMMAND_TIMING)
4414 { "time", TIME },
4415#endif
Jari Aalto726f6381996-08-26 18:22:31 +00004416 { "{", '{' },
4417 { "}", '}' },
4418 { "!", BANG },
Jari Aaltocce855b1998-04-17 19:52:44 +00004419#if defined (COND_COMMAND)
4420 { "[[", COND_START },
4421 { "]]", COND_END },
4422#endif
Jari Aalto31859422009-01-12 13:36:28 +00004423#if defined (COPROCESS_SUPPORT)
4424 { "coproc", COPROC },
4425#endif
Jari Aalto726f6381996-08-26 18:22:31 +00004426 { (char *)NULL, 0}
4427};
4428
Jari Aalto7117c2d2002-07-17 14:10:11 +00004429/* other tokens that can be returned by read_token() */
4430STRING_INT_ALIST other_token_alist[] = {
4431 /* Multiple-character tokens with special values */
Chet Ramey495aee42011-11-22 19:11:26 -05004432 { "--", TIMEIGN },
Jari Aalto7117c2d2002-07-17 14:10:11 +00004433 { "-p", TIMEOPT },
4434 { "&&", AND_AND },
4435 { "||", OR_OR },
4436 { ">>", GREATER_GREATER },
4437 { "<<", LESS_LESS },
4438 { "<&", LESS_AND },
4439 { ">&", GREATER_AND },
4440 { ";;", SEMI_SEMI },
Jari Aalto31859422009-01-12 13:36:28 +00004441 { ";&", SEMI_AND },
4442 { ";;&", SEMI_SEMI_AND },
Jari Aalto7117c2d2002-07-17 14:10:11 +00004443 { "<<-", LESS_LESS_MINUS },
4444 { "<<<", LESS_LESS_LESS },
4445 { "&>", AND_GREATER },
Jari Aalto31859422009-01-12 13:36:28 +00004446 { "&>>", AND_GREATER_GREATER },
Jari Aalto7117c2d2002-07-17 14:10:11 +00004447 { "<>", LESS_GREATER },
4448 { ">|", GREATER_BAR },
Jari Aalto31859422009-01-12 13:36:28 +00004449 { "|&", BAR_AND },
Jari Aalto7117c2d2002-07-17 14:10:11 +00004450 { "EOF", yacc_EOF },
4451 /* Tokens whose value is the character itself */
4452 { ">", '>' },
4453 { "<", '<' },
4454 { "-", '-' },
4455 { "{", '{' },
4456 { "}", '}' },
4457 { ";", ';' },
4458 { "(", '(' },
4459 { ")", ')' },
4460 { "|", '|' },
4461 { "&", '&' },
4462 { "newline", '\n' },
4463 { (char *)NULL, 0}
4464};
4465
4466/* others not listed here:
4467 WORD look at yylval.word
4468 ASSIGNMENT_WORD look at yylval.word
4469 NUMBER look at yylval.number
4470 ARITH_CMD look at yylval.word_list
4471 ARITH_FOR_EXPRS look at yylval.word_list
4472 COND_CMD look at yylval.command
4473*/
Jari Aaltob72432f1999-02-19 17:11:39 +00004474
Jari Aaltoccc6cda1996-12-23 17:02:34 +00004475/* These are used by read_token_word, but appear up here so that shell_getc
4476 can use them to decide when to add otherwise blank lines to the history. */
4477
4478/* The primary delimiter stack. */
4479struct dstack dstack = { (char *)NULL, 0, 0 };
4480
4481/* A temporary delimiter stack to be used when decoding prompt strings.
4482 This is needed because command substitutions in prompt strings (e.g., PS2)
4483 can screw up the parser's quoting state. */
4484static struct dstack temp_dstack = { (char *)NULL, 0, 0 };
4485
4486/* Macro for accessing the top delimiter on the stack. Returns the
4487 delimiter or zero if none. */
4488#define current_delimiter(ds) \
4489 (ds.delimiter_depth ? ds.delimiters[ds.delimiter_depth - 1] : 0)
4490
4491#define push_delimiter(ds, character) \
4492 do \
4493 { \
4494 if (ds.delimiter_depth + 2 > ds.delimiter_space) \
Jari Aaltof73dda02001-11-13 17:56:06 +00004495 ds.delimiters = (char *)xrealloc \
Jari Aaltoccc6cda1996-12-23 17:02:34 +00004496 (ds.delimiters, (ds.delimiter_space += 10) * sizeof (char)); \
4497 ds.delimiters[ds.delimiter_depth] = character; \
4498 ds.delimiter_depth++; \
4499 } \
4500 while (0)
4501
4502#define pop_delimiter(ds) ds.delimiter_depth--
4503
Jari Aalto726f6381996-08-26 18:22:31 +00004504/* Return the next shell input character. This always reads characters
4505 from shell_input_line; when that line is exhausted, it is time to
4506 read the next line. This is called by read_token when the shell is
4507 processing normal command input. */
Jari Aaltoccc6cda1996-12-23 17:02:34 +00004508
Jari Aalto28ef6c32001-04-06 19:14:31 +00004509/* This implements one-character lookahead/lookbehind across physical input
4510 lines, to avoid something being lost because it's pushed back with
4511 shell_ungetc when we're at the start of a line. */
4512static int eol_ungetc_lookahead = 0;
4513
Jari Aalto726f6381996-08-26 18:22:31 +00004514static int
4515shell_getc (remove_quoted_newline)
4516 int remove_quoted_newline;
4517{
Jari Aaltoccc6cda1996-12-23 17:02:34 +00004518 register int i;
Chet Rameyac50fba2014-02-26 09:36:43 -05004519 int c, truncating;
Jari Aaltof73dda02001-11-13 17:56:06 +00004520 unsigned char uc;
Jari Aalto726f6381996-08-26 18:22:31 +00004521
4522 QUIT;
4523
Jari Aalto95732b42005-12-07 14:08:12 +00004524 if (sigwinch_received)
4525 {
4526 sigwinch_received = 0;
4527 get_new_window_size (0, (int *)0, (int *)0);
4528 }
4529
Jari Aalto28ef6c32001-04-06 19:14:31 +00004530 if (eol_ungetc_lookahead)
4531 {
4532 c = eol_ungetc_lookahead;
4533 eol_ungetc_lookahead = 0;
4534 return (c);
4535 }
4536
Jari Aaltocce855b1998-04-17 19:52:44 +00004537#if defined (ALIAS) || defined (DPAREN_ARITHMETIC)
Jari Aalto726f6381996-08-26 18:22:31 +00004538 /* If shell_input_line[shell_input_line_index] == 0, but there is
4539 something on the pushed list of strings, then we don't want to go
4540 off and get another line. We let the code down below handle it. */
4541
4542 if (!shell_input_line || ((!shell_input_line[shell_input_line_index]) &&
4543 (pushed_string_list == (STRING_SAVER *)NULL)))
Jari Aaltocce855b1998-04-17 19:52:44 +00004544#else /* !ALIAS && !DPAREN_ARITHMETIC */
Jari Aalto726f6381996-08-26 18:22:31 +00004545 if (!shell_input_line || !shell_input_line[shell_input_line_index])
Jari Aaltocce855b1998-04-17 19:52:44 +00004546#endif /* !ALIAS && !DPAREN_ARITHMETIC */
Jari Aalto726f6381996-08-26 18:22:31 +00004547 {
Jari Aalto726f6381996-08-26 18:22:31 +00004548 line_number++;
4549
Chet Rameyac50fba2014-02-26 09:36:43 -05004550 /* Let's not let one really really long line blow up memory allocation */
4551 if (shell_input_line && shell_input_line_size >= 32768)
4552 {
4553 free (shell_input_line);
4554 shell_input_line = 0;
4555 shell_input_line_size = 0;
4556 }
4557
Jari Aalto726f6381996-08-26 18:22:31 +00004558 restart_read:
4559
4560 /* Allow immediate exit if interrupted during input. */
4561 QUIT;
4562
Chet Rameyac50fba2014-02-26 09:36:43 -05004563 i = truncating = 0;
Jari Aalto726f6381996-08-26 18:22:31 +00004564 shell_input_line_terminator = 0;
4565
Jari Aaltob80f6442004-07-27 13:29:18 +00004566 /* If the shell is interatctive, but not currently printing a prompt
4567 (interactive_shell && interactive == 0), we don't want to print
4568 notifies or cleanup the jobs -- we want to defer it until we do
4569 print the next prompt. */
4570 if (interactive_shell == 0 || SHOULD_PROMPT())
4571 {
Jari Aalto726f6381996-08-26 18:22:31 +00004572#if defined (JOB_CONTROL)
4573 /* This can cause a problem when reading a command as the result
4574 of a trap, when the trap is called from flush_child. This call
4575 had better not cause jobs to disappear from the job table in
4576 that case, or we will have big trouble. */
Jari Aaltob80f6442004-07-27 13:29:18 +00004577 notify_and_cleanup ();
Jari Aalto726f6381996-08-26 18:22:31 +00004578#else /* !JOB_CONTROL */
Jari Aaltob80f6442004-07-27 13:29:18 +00004579 cleanup_dead_jobs ();
Jari Aalto726f6381996-08-26 18:22:31 +00004580#endif /* !JOB_CONTROL */
Jari Aaltob80f6442004-07-27 13:29:18 +00004581 }
Jari Aalto726f6381996-08-26 18:22:31 +00004582
4583#if defined (READLINE)
Jari Aaltob80f6442004-07-27 13:29:18 +00004584 if (no_line_editing && SHOULD_PROMPT())
Jari Aalto726f6381996-08-26 18:22:31 +00004585#else
Jari Aaltob80f6442004-07-27 13:29:18 +00004586 if (SHOULD_PROMPT())
Jari Aalto726f6381996-08-26 18:22:31 +00004587#endif
4588 print_prompt ();
4589
4590 if (bash_input.type == st_stream)
4591 clearerr (stdin);
4592
Jari Aalto28ef6c32001-04-06 19:14:31 +00004593 while (1)
Jari Aalto726f6381996-08-26 18:22:31 +00004594 {
Jari Aalto28ef6c32001-04-06 19:14:31 +00004595 c = yy_getc ();
4596
Jari Aalto726f6381996-08-26 18:22:31 +00004597 /* Allow immediate exit if interrupted during input. */
4598 QUIT;
4599
Jari Aalto28ef6c32001-04-06 19:14:31 +00004600 if (c == '\0')
4601 {
4602#if 0
4603 internal_warning ("shell_getc: ignored null byte in input");
4604#endif
4605 continue;
4606 }
4607
Chet Rameyac50fba2014-02-26 09:36:43 -05004608 /* Theoretical overflow */
4609 /* If we can't put 256 bytes more into the buffer, allocate
4610 everything we can and fill it as full as we can. */
4611 /* XXX - we ignore rest of line using `truncating' flag */
4612 if (shell_input_line_size > (SIZE_MAX - 256))
4613 {
4614 size_t n;
4615
4616 n = SIZE_MAX - i; /* how much more can we put into the buffer? */
4617 if (n <= 2) /* we have to save 1 for the newline added below */
4618 {
4619 if (truncating == 0)
4620 internal_warning("shell_getc: shell_input_line_size (%zu) exceeds SIZE_MAX (%llu): line truncated", shell_input_line_size, SIZE_MAX);
4621 shell_input_line[i] = '\0';
4622 truncating = 1;
4623 }
4624 if (shell_input_line_size < SIZE_MAX)
4625 {
4626 shell_input_line_size = SIZE_MAX;
4627 shell_input_line = xrealloc (shell_input_line, shell_input_line_size);
4628 }
4629 }
4630 else
4631 RESIZE_MALLOCED_BUFFER (shell_input_line, i, 2, shell_input_line_size, 256);
Jari Aalto726f6381996-08-26 18:22:31 +00004632
4633 if (c == EOF)
4634 {
4635 if (bash_input.type == st_stream)
4636 clearerr (stdin);
4637
Jari Aaltoccc6cda1996-12-23 17:02:34 +00004638 if (i == 0)
Jari Aalto726f6381996-08-26 18:22:31 +00004639 shell_input_line_terminator = EOF;
4640
4641 shell_input_line[i] = '\0';
4642 break;
4643 }
4644
Chet Rameyac50fba2014-02-26 09:36:43 -05004645 if (truncating == 0 || c == '\n')
4646 shell_input_line[i++] = c;
Jari Aalto726f6381996-08-26 18:22:31 +00004647
4648 if (c == '\n')
4649 {
4650 shell_input_line[--i] = '\0';
4651 current_command_line_count++;
4652 break;
4653 }
4654 }
Jari Aalto28ef6c32001-04-06 19:14:31 +00004655
Jari Aalto726f6381996-08-26 18:22:31 +00004656 shell_input_line_index = 0;
4657 shell_input_line_len = i; /* == strlen (shell_input_line) */
4658
Jari Aalto7117c2d2002-07-17 14:10:11 +00004659 set_line_mbstate ();
4660
Jari Aalto726f6381996-08-26 18:22:31 +00004661#if defined (HISTORY)
Jari Aaltoccc6cda1996-12-23 17:02:34 +00004662 if (remember_on_history && shell_input_line && shell_input_line[0])
Jari Aalto726f6381996-08-26 18:22:31 +00004663 {
4664 char *expansions;
Jari Aaltoccc6cda1996-12-23 17:02:34 +00004665# if defined (BANG_HISTORY)
4666 int old_hist;
Jari Aalto726f6381996-08-26 18:22:31 +00004667
Jari Aaltoccc6cda1996-12-23 17:02:34 +00004668 /* If the current delimiter is a single quote, we should not be
4669 performing history expansion, even if we're on a different
4670 line from the original single quote. */
4671 old_hist = history_expansion_inhibited;
4672 if (current_delimiter (dstack) == '\'')
4673 history_expansion_inhibited = 1;
4674# endif
Jari Aalto726f6381996-08-26 18:22:31 +00004675 expansions = pre_process_line (shell_input_line, 1, 1);
Jari Aaltoccc6cda1996-12-23 17:02:34 +00004676# if defined (BANG_HISTORY)
4677 history_expansion_inhibited = old_hist;
4678# endif
Jari Aaltod166f041997-06-05 14:59:13 +00004679 if (expansions != shell_input_line)
4680 {
4681 free (shell_input_line);
4682 shell_input_line = expansions;
4683 shell_input_line_len = shell_input_line ?
4684 strlen (shell_input_line) : 0;
Chet Ramey495aee42011-11-22 19:11:26 -05004685 if (shell_input_line_len == 0)
Jari Aaltod166f041997-06-05 14:59:13 +00004686 current_command_line_count--;
Jari Aalto726f6381996-08-26 18:22:31 +00004687
Jari Aaltod166f041997-06-05 14:59:13 +00004688 /* We have to force the xrealloc below because we don't know
Jari Aalto28ef6c32001-04-06 19:14:31 +00004689 the true allocated size of shell_input_line anymore. */
Jari Aaltod166f041997-06-05 14:59:13 +00004690 shell_input_line_size = shell_input_line_len;
Jari Aalto7117c2d2002-07-17 14:10:11 +00004691
4692 set_line_mbstate ();
Jari Aaltod166f041997-06-05 14:59:13 +00004693 }
Jari Aalto726f6381996-08-26 18:22:31 +00004694 }
Jari Aalto28ef6c32001-04-06 19:14:31 +00004695 /* Try to do something intelligent with blank lines encountered while
4696 entering multi-line commands. XXX - this is grotesque */
Jari Aaltoccc6cda1996-12-23 17:02:34 +00004697 else if (remember_on_history && shell_input_line &&
4698 shell_input_line[0] == '\0' &&
Jari Aalto28ef6c32001-04-06 19:14:31 +00004699 current_command_line_count > 1)
Jari Aaltoccc6cda1996-12-23 17:02:34 +00004700 {
Jari Aalto28ef6c32001-04-06 19:14:31 +00004701 if (current_delimiter (dstack))
4702 /* We know shell_input_line[0] == 0 and we're reading some sort of
4703 quoted string. This means we've got a line consisting of only
4704 a newline in a quoted string. We want to make sure this line
4705 gets added to the history. */
4706 maybe_add_history (shell_input_line);
4707 else
4708 {
4709 char *hdcs;
Chet Ramey495aee42011-11-22 19:11:26 -05004710 hdcs = history_delimiting_chars (shell_input_line);
Jari Aalto28ef6c32001-04-06 19:14:31 +00004711 if (hdcs && hdcs[0] == ';')
4712 maybe_add_history (shell_input_line);
4713 }
Jari Aaltoccc6cda1996-12-23 17:02:34 +00004714 }
4715
Jari Aalto726f6381996-08-26 18:22:31 +00004716#endif /* HISTORY */
4717
4718 if (shell_input_line)
4719 {
4720 /* Lines that signify the end of the shell's input should not be
Chet Rameyac50fba2014-02-26 09:36:43 -05004721 echoed. We should not echo lines while parsing command
4722 substitutions with recursive calls into the parsing engine; those
4723 should only be echoed once when we read the word. That is the
4724 reason for the test against shell_eof_token, which is set to a
4725 right paren when parsing the contents of command substitutions. */
Jari Aalto726f6381996-08-26 18:22:31 +00004726 if (echo_input_at_read && (shell_input_line[0] ||
Chet Rameyac50fba2014-02-26 09:36:43 -05004727 shell_input_line_terminator != EOF) &&
4728 shell_eof_token == 0)
Jari Aalto726f6381996-08-26 18:22:31 +00004729 fprintf (stderr, "%s\n", shell_input_line);
4730 }
4731 else
4732 {
4733 shell_input_line_size = 0;
4734 prompt_string_pointer = &current_prompt_string;
Jari Aaltob80f6442004-07-27 13:29:18 +00004735 if (SHOULD_PROMPT ())
4736 prompt_again ();
Jari Aalto726f6381996-08-26 18:22:31 +00004737 goto restart_read;
4738 }
4739
4740 /* Add the newline to the end of this string, iff the string does
4741 not already end in an EOF character. */
4742 if (shell_input_line_terminator != EOF)
4743 {
Chet Ramey6ebbb242014-04-11 11:04:26 -04004744 if (shell_input_line_size < SIZE_MAX-3 && (shell_input_line_len+3 > shell_input_line_size))
Jari Aaltof73dda02001-11-13 17:56:06 +00004745 shell_input_line = (char *)xrealloc (shell_input_line,
Jari Aalto726f6381996-08-26 18:22:31 +00004746 1 + (shell_input_line_size += 2));
4747
Jari Aaltoccc6cda1996-12-23 17:02:34 +00004748 shell_input_line[shell_input_line_len] = '\n';
4749 shell_input_line[shell_input_line_len + 1] = '\0';
Jari Aalto7117c2d2002-07-17 14:10:11 +00004750
4751 set_line_mbstate ();
Jari Aalto726f6381996-08-26 18:22:31 +00004752 }
4753 }
Jari Aaltoccc6cda1996-12-23 17:02:34 +00004754
Chet Ramey495aee42011-11-22 19:11:26 -05004755next_alias_char:
Jari Aaltof73dda02001-11-13 17:56:06 +00004756 uc = shell_input_line[shell_input_line_index];
Jari Aalto726f6381996-08-26 18:22:31 +00004757
Jari Aaltof73dda02001-11-13 17:56:06 +00004758 if (uc)
Jari Aalto726f6381996-08-26 18:22:31 +00004759 shell_input_line_index++;
4760
Jari Aaltocce855b1998-04-17 19:52:44 +00004761#if defined (ALIAS) || defined (DPAREN_ARITHMETIC)
Jari Aaltof73dda02001-11-13 17:56:06 +00004762 /* If UC is NULL, we have reached the end of the current input string. If
Jari Aalto726f6381996-08-26 18:22:31 +00004763 pushed_string_list is non-empty, it's time to pop to the previous string
4764 because we have fully consumed the result of the last alias expansion.
4765 Do it transparently; just return the next character of the string popped
4766 to. */
Chet Rameyac50fba2014-02-26 09:36:43 -05004767 /* If pushed_string_list != 0 but pushed_string_list->expander == 0 (not
4768 currently tested) and the flags value is not PSH_SOURCE, we are not
4769 parsing an alias, we have just saved one (push_string, when called by
4770 the parse_dparen code) In this case, just go on as well. The PSH_SOURCE
4771 case is handled below. */
Chet Ramey00018032011-11-21 20:51:19 -05004772pop_alias:
Chet Rameyac50fba2014-02-26 09:36:43 -05004773 if (uc == 0 && pushed_string_list && pushed_string_list->flags != PSH_SOURCE)
Jari Aalto726f6381996-08-26 18:22:31 +00004774 {
Jari Aaltob80f6442004-07-27 13:29:18 +00004775 pop_string ();
4776 uc = shell_input_line[shell_input_line_index];
4777 if (uc)
4778 shell_input_line_index++;
Jari Aalto726f6381996-08-26 18:22:31 +00004779 }
Jari Aaltocce855b1998-04-17 19:52:44 +00004780#endif /* ALIAS || DPAREN_ARITHMETIC */
Jari Aalto726f6381996-08-26 18:22:31 +00004781
Jari Aalto95732b42005-12-07 14:08:12 +00004782 if MBTEST(uc == '\\' && remove_quoted_newline && shell_input_line[shell_input_line_index] == '\n')
4783 {
4784 if (SHOULD_PROMPT ())
4785 prompt_again ();
4786 line_number++;
Chet Ramey495aee42011-11-22 19:11:26 -05004787 /* What do we do here if we're expanding an alias whose definition
4788 includes an escaped newline? If that's the last character in the
4789 alias expansion, we just pop the pushed string list (recall that
4790 we inhibit the appending of a space in mk_alexpansion() if newline
4791 is the last character). If it's not the last character, we need
4792 to consume the quoted newline and move to the next character in
4793 the expansion. */
Chet Ramey509a4432013-01-10 19:53:16 -05004794#if defined (ALIAS)
Chet Ramey00018032011-11-21 20:51:19 -05004795 if (expanding_alias () && shell_input_line[shell_input_line_index+1] == '\0')
4796 {
4797 uc = 0;
4798 goto pop_alias;
4799 }
Chet Ramey495aee42011-11-22 19:11:26 -05004800 else if (expanding_alias () && shell_input_line[shell_input_line_index+1] != '\0')
4801 {
4802 shell_input_line_index++; /* skip newline */
4803 goto next_alias_char; /* and get next character */
4804 }
Chet Ramey509a4432013-01-10 19:53:16 -05004805 else
4806#endif
Chet Ramey495aee42011-11-22 19:11:26 -05004807 goto restart_read;
Jari Aalto95732b42005-12-07 14:08:12 +00004808 }
4809
Chet Ramey495aee42011-11-22 19:11:26 -05004810 if (uc == 0 && shell_input_line_terminator == EOF)
Jari Aaltoccc6cda1996-12-23 17:02:34 +00004811 return ((shell_input_line_index != 0) ? '\n' : EOF);
Jari Aalto726f6381996-08-26 18:22:31 +00004812
Chet Rameyac50fba2014-02-26 09:36:43 -05004813#if defined (ALIAS) || defined (DPAREN_ARITHMETIC)
4814 /* We already know that we are not parsing an alias expansion because of the
4815 check for expanding_alias() above. This knows how parse_and_execute
4816 handles switching to st_string input while an alias is being expanded,
4817 hence the check for pushed_string_list without pushed_string_list->expander
4818 and the check for PSH_SOURCE as pushed_string_list->flags.
4819 parse_and_execute and parse_string both change the input type to st_string
4820 and place the string to be parsed and executed into location.string, so
4821 we should not stop reading that until the pointer is '\0'.
4822 The check for shell_input_line_terminator may be superfluous.
4823
4824 This solves the problem of `.' inside a multi-line alias with embedded
4825 newlines executing things out of order. */
4826 if (uc == 0 && bash_input.type == st_string && *bash_input.location.string &&
4827 pushed_string_list && pushed_string_list->flags == PSH_SOURCE &&
4828 shell_input_line_terminator == 0)
4829 {
4830 shell_input_line_index = 0;
4831 goto restart_read;
4832 }
4833#endif
4834
Jari Aaltof73dda02001-11-13 17:56:06 +00004835 return (uc);
Jari Aalto726f6381996-08-26 18:22:31 +00004836}
4837
Jari Aalto7117c2d2002-07-17 14:10:11 +00004838/* Put C back into the input for the shell. This might need changes for
4839 HANDLE_MULTIBYTE around EOLs. Since we (currently) never push back a
4840 character different than we read, shell_input_line_property doesn't need
4841 to change when manipulating shell_input_line. The define for
4842 last_shell_getc_is_singlebyte should take care of it, though. */
Jari Aalto726f6381996-08-26 18:22:31 +00004843static void
4844shell_ungetc (c)
4845 int c;
4846{
4847 if (shell_input_line && shell_input_line_index)
4848 shell_input_line[--shell_input_line_index] = c;
Jari Aalto28ef6c32001-04-06 19:14:31 +00004849 else
4850 eol_ungetc_lookahead = c;
Jari Aalto726f6381996-08-26 18:22:31 +00004851}
4852
Chet Ramey80b4d712014-10-05 19:12:20 -04004853char *
4854parser_remaining_input ()
4855{
4856 if (shell_input_line == 0)
4857 return 0;
4858 if (shell_input_line_index < 0 || shell_input_line_index >= shell_input_line_len)
4859 return '\0'; /* XXX */
4860 return (shell_input_line + shell_input_line_index);
4861}
4862
Jari Aaltof73dda02001-11-13 17:56:06 +00004863#ifdef INCLUDE_UNUSED
4864/* Back the input pointer up by one, effectively `ungetting' a character. */
Jari Aaltoccc6cda1996-12-23 17:02:34 +00004865static void
4866shell_ungetchar ()
4867{
4868 if (shell_input_line && shell_input_line_index)
4869 shell_input_line_index--;
4870}
Jari Aaltof73dda02001-11-13 17:56:06 +00004871#endif
Jari Aaltoccc6cda1996-12-23 17:02:34 +00004872
4873/* Discard input until CHARACTER is seen, then push that character back
4874 onto the input stream. */
Jari Aalto726f6381996-08-26 18:22:31 +00004875static void
4876discard_until (character)
4877 int character;
4878{
4879 int c;
4880
4881 while ((c = shell_getc (0)) != EOF && c != character)
4882 ;
4883
4884 if (c != EOF)
4885 shell_ungetc (c);
4886}
Jari Aalto726f6381996-08-26 18:22:31 +00004887
4888void
Jari Aalto06285672006-10-10 14:15:34 +00004889execute_variable_command (command, vname)
4890 char *command, *vname;
Jari Aalto726f6381996-08-26 18:22:31 +00004891{
Jari Aalto726f6381996-08-26 18:22:31 +00004892 char *last_lastarg;
Jari Aaltob80f6442004-07-27 13:29:18 +00004893 sh_parser_state_t ps;
Jari Aalto726f6381996-08-26 18:22:31 +00004894
Jari Aaltob80f6442004-07-27 13:29:18 +00004895 save_parser_state (&ps);
Jari Aalto726f6381996-08-26 18:22:31 +00004896 last_lastarg = get_string_value ("_");
4897 if (last_lastarg)
4898 last_lastarg = savestring (last_lastarg);
4899
Jari Aalto06285672006-10-10 14:15:34 +00004900 parse_and_execute (savestring (command), vname, SEVAL_NONINT|SEVAL_NOHIST);
Jari Aalto726f6381996-08-26 18:22:31 +00004901
Jari Aaltob80f6442004-07-27 13:29:18 +00004902 restore_parser_state (&ps);
Jari Aalto95732b42005-12-07 14:08:12 +00004903 bind_variable ("_", last_lastarg, 0);
Jari Aalto726f6381996-08-26 18:22:31 +00004904 FREE (last_lastarg);
4905
Jari Aaltoccc6cda1996-12-23 17:02:34 +00004906 if (token_to_read == '\n') /* reset_parser was called */
Jari Aalto726f6381996-08-26 18:22:31 +00004907 token_to_read = 0;
4908}
4909
Jari Aaltoccc6cda1996-12-23 17:02:34 +00004910/* Place to remember the token. We try to keep the buffer
4911 at a reasonable size, but it can grow. */
4912static char *token = (char *)NULL;
4913
4914/* Current size of the token buffer. */
4915static int token_buffer_size;
4916
Jari Aalto726f6381996-08-26 18:22:31 +00004917/* Command to read_token () explaining what we want it to do. */
4918#define READ 0
4919#define RESET 1
4920#define prompt_is_ps1 \
4921 (!prompt_string_pointer || prompt_string_pointer == &ps1_prompt)
4922
4923/* Function for yyparse to call. yylex keeps track of
4924 the last two tokens read, and calls read_token. */
Jari Aaltoccc6cda1996-12-23 17:02:34 +00004925static int
Jari Aalto726f6381996-08-26 18:22:31 +00004926yylex ()
4927{
Jari Aaltoccc6cda1996-12-23 17:02:34 +00004928 if (interactive && (current_token == 0 || current_token == '\n'))
Jari Aalto726f6381996-08-26 18:22:31 +00004929 {
4930 /* Before we print a prompt, we might have to check mailboxes.
4931 We do this only if it is time to do so. Notice that only here
4932 is the mail alarm reset; nothing takes place in check_mail ()
4933 except the checking of mail. Please don't change this. */
Chet Ramey509a4432013-01-10 19:53:16 -05004934 if (prompt_is_ps1 && parse_and_execute_level == 0 && time_to_check_mail ())
Jari Aalto726f6381996-08-26 18:22:31 +00004935 {
4936 check_mail ();
4937 reset_mail_timer ();
4938 }
4939
4940 /* Avoid printing a prompt if we're not going to read anything, e.g.
4941 after resetting the parser with read_token (RESET). */
Jari Aaltob80f6442004-07-27 13:29:18 +00004942 if (token_to_read == 0 && SHOULD_PROMPT ())
Jari Aalto726f6381996-08-26 18:22:31 +00004943 prompt_again ();
4944 }
4945
Jari Aaltoccc6cda1996-12-23 17:02:34 +00004946 two_tokens_ago = token_before_that;
Jari Aalto726f6381996-08-26 18:22:31 +00004947 token_before_that = last_read_token;
4948 last_read_token = current_token;
4949 current_token = read_token (READ);
Jari Aalto31859422009-01-12 13:36:28 +00004950
4951 if ((parser_state & PST_EOFTOKEN) && current_token == shell_eof_token)
4952 {
4953 current_token = yacc_EOF;
4954 if (bash_input.type == st_string)
4955 rewind_input_string ();
4956 }
4957 parser_state &= ~PST_EOFTOKEN;
4958
Jari Aalto726f6381996-08-26 18:22:31 +00004959 return (current_token);
4960}
4961
Jari Aalto726f6381996-08-26 18:22:31 +00004962/* When non-zero, we have read the required tokens
4963 which allow ESAC to be the next one read. */
Jari Aaltoccc6cda1996-12-23 17:02:34 +00004964static int esacs_needed_count;
Jari Aalto726f6381996-08-26 18:22:31 +00004965
Chet Ramey90a39f32014-10-02 09:07:21 -04004966static void
4967push_heredoc (r)
4968 REDIRECT *r;
4969{
4970 if (need_here_doc >= HEREDOC_MAX)
4971 {
4972 last_command_exit_value = EX_BADUSAGE;
4973 need_here_doc = 0;
4974 report_syntax_error (_("maximum here-document count exceeded"));
4975 reset_parser ();
4976 exit_shell (last_command_exit_value);
4977 }
4978 redir_stack[need_here_doc++] = r;
4979}
4980
Jari Aalto726f6381996-08-26 18:22:31 +00004981void
4982gather_here_documents ()
4983{
Jari Aalto31859422009-01-12 13:36:28 +00004984 int r;
4985
4986 r = 0;
Chet Rameydaefb2c2014-08-01 15:30:48 -04004987 while (need_here_doc > 0)
Jari Aalto726f6381996-08-26 18:22:31 +00004988 {
Jari Aalto31859422009-01-12 13:36:28 +00004989 parser_state |= PST_HEREDOC;
4990 make_here_document (redir_stack[r++], line_number);
4991 parser_state &= ~PST_HEREDOC;
Jari Aalto726f6381996-08-26 18:22:31 +00004992 need_here_doc--;
4993 }
4994}
4995
Jari Aalto726f6381996-08-26 18:22:31 +00004996/* When non-zero, an open-brace used to create a group is awaiting a close
4997 brace partner. */
Jari Aaltoccc6cda1996-12-23 17:02:34 +00004998static int open_brace_count;
Jari Aalto726f6381996-08-26 18:22:31 +00004999
5000#define command_token_position(token) \
Chet Ramey00018032011-11-21 20:51:19 -05005001 (((token) == ASSIGNMENT_WORD) || (parser_state&PST_REDIRLIST) || \
Jari Aalto31859422009-01-12 13:36:28 +00005002 ((token) != SEMI_SEMI && (token) != SEMI_AND && (token) != SEMI_SEMI_AND && reserved_word_acceptable(token)))
Jari Aalto726f6381996-08-26 18:22:31 +00005003
Jari Aaltob80f6442004-07-27 13:29:18 +00005004#define assignment_acceptable(token) \
5005 (command_token_position(token) && ((parser_state & PST_CASEPAT) == 0))
Jari Aalto726f6381996-08-26 18:22:31 +00005006
5007/* Check to see if TOKEN is a reserved word and return the token
5008 value if it is. */
5009#define CHECK_FOR_RESERVED_WORD(tok) \
5010 do { \
5011 if (!dollar_present && !quoted && \
5012 reserved_word_acceptable (last_read_token)) \
5013 { \
5014 int i; \
5015 for (i = 0; word_token_alist[i].word != (char *)NULL; i++) \
5016 if (STREQ (tok, word_token_alist[i].word)) \
5017 { \
Jari Aaltoccc6cda1996-12-23 17:02:34 +00005018 if ((parser_state & PST_CASEPAT) && (word_token_alist[i].token != ESAC)) \
Jari Aalto726f6381996-08-26 18:22:31 +00005019 break; \
Jari Aaltob80f6442004-07-27 13:29:18 +00005020 if (word_token_alist[i].token == TIME && time_command_acceptable () == 0) \
Jari Aaltocce855b1998-04-17 19:52:44 +00005021 break; \
Jari Aalto726f6381996-08-26 18:22:31 +00005022 if (word_token_alist[i].token == ESAC) \
Jari Aaltoccc6cda1996-12-23 17:02:34 +00005023 parser_state &= ~(PST_CASEPAT|PST_CASESTMT); \
5024 else if (word_token_alist[i].token == CASE) \
5025 parser_state |= PST_CASESTMT; \
Jari Aaltocce855b1998-04-17 19:52:44 +00005026 else if (word_token_alist[i].token == COND_END) \
5027 parser_state &= ~(PST_CONDCMD|PST_CONDEXPR); \
5028 else if (word_token_alist[i].token == COND_START) \
5029 parser_state |= PST_CONDCMD; \
Jari Aaltoccc6cda1996-12-23 17:02:34 +00005030 else if (word_token_alist[i].token == '{') \
5031 open_brace_count++; \
5032 else if (word_token_alist[i].token == '}' && open_brace_count) \
5033 open_brace_count--; \
Jari Aalto726f6381996-08-26 18:22:31 +00005034 return (word_token_alist[i].token); \
5035 } \
5036 } \
5037 } while (0)
5038
Jari Aaltoccc6cda1996-12-23 17:02:34 +00005039#if defined (ALIAS)
5040
5041 /* OK, we have a token. Let's try to alias expand it, if (and only if)
5042 it's eligible.
5043
Jari Aalto7117c2d2002-07-17 14:10:11 +00005044 It is eligible for expansion if EXPAND_ALIASES is set, and
Jari Aaltoccc6cda1996-12-23 17:02:34 +00005045 the token is unquoted and the last token read was a command
5046 separator (or expand_next_token is set), and we are currently
5047 processing an alias (pushed_string_list is non-empty) and this
5048 token is not the same as the current or any previously
5049 processed alias.
5050
5051 Special cases that disqualify:
5052 In a pattern list in a case statement (parser_state & PST_CASEPAT). */
Jari Aaltob80f6442004-07-27 13:29:18 +00005053
5054static char *
5055mk_alexpansion (s)
5056 char *s;
5057{
5058 int l;
5059 char *r;
5060
5061 l = strlen (s);
5062 r = xmalloc (l + 2);
5063 strcpy (r, s);
Chet Ramey495aee42011-11-22 19:11:26 -05005064 /* If the last character in the alias is a newline, don't add a trailing
5065 space to the expansion. Works with shell_getc above. */
5066 if (r[l - 1] != ' ' && r[l - 1] != '\n')
Jari Aaltob80f6442004-07-27 13:29:18 +00005067 r[l++] = ' ';
5068 r[l] = '\0';
5069 return r;
5070}
5071
Jari Aaltoccc6cda1996-12-23 17:02:34 +00005072static int
Jari Aaltof73dda02001-11-13 17:56:06 +00005073alias_expand_token (tokstr)
5074 char *tokstr;
Jari Aaltoccc6cda1996-12-23 17:02:34 +00005075{
5076 char *expanded;
5077 alias_t *ap;
5078
5079 if (((parser_state & PST_ALEXPNEXT) || command_token_position (last_read_token)) &&
5080 (parser_state & PST_CASEPAT) == 0)
5081 {
Jari Aaltof73dda02001-11-13 17:56:06 +00005082 ap = find_alias (tokstr);
Jari Aaltoccc6cda1996-12-23 17:02:34 +00005083
5084 /* Currently expanding this token. */
5085 if (ap && (ap->flags & AL_BEINGEXPANDED))
5086 return (NO_EXPANSION);
5087
Jari Aaltob80f6442004-07-27 13:29:18 +00005088 /* mk_alexpansion puts an extra space on the end of the alias expansion,
5089 so the lookahead by the parser works right. If this gets changed,
5090 make sure the code in shell_getc that deals with reaching the end of
5091 an expanded alias is changed with it. */
5092 expanded = ap ? mk_alexpansion (ap->value) : (char *)NULL;
5093
Jari Aaltoccc6cda1996-12-23 17:02:34 +00005094 if (expanded)
5095 {
5096 push_string (expanded, ap->flags & AL_EXPANDNEXT, ap);
5097 return (RE_READ_TOKEN);
5098 }
5099 else
5100 /* This is an eligible token that does not have an expansion. */
5101 return (NO_EXPANSION);
5102 }
5103 return (NO_EXPANSION);
5104}
5105#endif /* ALIAS */
5106
Jari Aaltocce855b1998-04-17 19:52:44 +00005107static int
5108time_command_acceptable ()
5109{
5110#if defined (COMMAND_TIMING)
Chet Ramey495aee42011-11-22 19:11:26 -05005111 int i;
5112
5113 if (posixly_correct && shell_compatibility_level > 41)
5114 {
5115 /* Quick check of the rest of the line to find the next token. If it
5116 begins with a `-', Posix says to not return `time' as the token.
5117 This was interp 267. */
5118 i = shell_input_line_index;
5119 while (i < shell_input_line_len && (shell_input_line[i] == ' ' || shell_input_line[i] == '\t'))
5120 i++;
5121 if (shell_input_line[i] == '-')
5122 return 0;
5123 }
5124
Jari Aaltocce855b1998-04-17 19:52:44 +00005125 switch (last_read_token)
5126 {
5127 case 0:
5128 case ';':
5129 case '\n':
5130 case AND_AND:
5131 case OR_OR:
5132 case '&':
Chet Rameyccfc3032015-05-19 15:49:39 -04005133 case WHILE:
Jari Aaltob72432f1999-02-19 17:11:39 +00005134 case DO:
Chet Rameyccfc3032015-05-19 15:49:39 -04005135 case UNTIL:
5136 case IF:
Jari Aaltob72432f1999-02-19 17:11:39 +00005137 case THEN:
Chet Rameyccfc3032015-05-19 15:49:39 -04005138 case ELIF:
Jari Aaltob72432f1999-02-19 17:11:39 +00005139 case ELSE:
Jari Aalto28ef6c32001-04-06 19:14:31 +00005140 case '{': /* } */
Chet Rameyccfc3032015-05-19 15:49:39 -04005141 case '(': /* )( */
5142 case ')': /* only valid in case statement */
Chet Ramey495aee42011-11-22 19:11:26 -05005143 case BANG: /* ! time pipeline */
5144 case TIME: /* time time pipeline */
5145 case TIMEOPT: /* time -p time pipeline */
5146 case TIMEIGN: /* time -p -- ... */
Jari Aaltocce855b1998-04-17 19:52:44 +00005147 return 1;
5148 default:
5149 return 0;
5150 }
5151#else
5152 return 0;
5153#endif /* COMMAND_TIMING */
5154}
5155
Jari Aaltoccc6cda1996-12-23 17:02:34 +00005156/* Handle special cases of token recognition:
5157 IN is recognized if the last token was WORD and the token
5158 before that was FOR or CASE or SELECT.
5159
5160 DO is recognized if the last token was WORD and the token
5161 before that was FOR or SELECT.
5162
5163 ESAC is recognized if the last token caused `esacs_needed_count'
5164 to be set
5165
5166 `{' is recognized if the last token as WORD and the token
Jari Aalto28ef6c32001-04-06 19:14:31 +00005167 before that was FUNCTION, or if we just parsed an arithmetic
5168 `for' command.
Jari Aaltoccc6cda1996-12-23 17:02:34 +00005169
Jari Aalto28ef6c32001-04-06 19:14:31 +00005170 `}' is recognized if there is an unclosed `{' present.
Jari Aaltocce855b1998-04-17 19:52:44 +00005171
5172 `-p' is returned as TIMEOPT if the last read token was TIME.
Chet Ramey495aee42011-11-22 19:11:26 -05005173 `--' is returned as TIMEIGN if the last read token was TIMEOPT.
Jari Aaltocce855b1998-04-17 19:52:44 +00005174
5175 ']]' is returned as COND_END if the parser is currently parsing
5176 a conditional expression ((parser_state & PST_CONDEXPR) != 0)
5177
5178 `time' is returned as TIME if and only if it is immediately
5179 preceded by one of `;', `\n', `||', `&&', or `&'.
Jari Aaltoccc6cda1996-12-23 17:02:34 +00005180*/
5181
5182static int
Jari Aaltof73dda02001-11-13 17:56:06 +00005183special_case_tokens (tokstr)
5184 char *tokstr;
Jari Aaltoccc6cda1996-12-23 17:02:34 +00005185{
5186 if ((last_read_token == WORD) &&
5187#if defined (SELECT_COMMAND)
5188 ((token_before_that == FOR) || (token_before_that == CASE) || (token_before_that == SELECT)) &&
5189#else
5190 ((token_before_that == FOR) || (token_before_that == CASE)) &&
5191#endif
Jari Aaltof73dda02001-11-13 17:56:06 +00005192 (tokstr[0] == 'i' && tokstr[1] == 'n' && tokstr[2] == 0))
Jari Aaltoccc6cda1996-12-23 17:02:34 +00005193 {
5194 if (token_before_that == CASE)
5195 {
5196 parser_state |= PST_CASEPAT;
5197 esacs_needed_count++;
5198 }
5199 return (IN);
5200 }
5201
5202 if (last_read_token == WORD &&
5203#if defined (SELECT_COMMAND)
5204 (token_before_that == FOR || token_before_that == SELECT) &&
5205#else
5206 (token_before_that == FOR) &&
5207#endif
Jari Aaltof73dda02001-11-13 17:56:06 +00005208 (tokstr[0] == 'd' && tokstr[1] == 'o' && tokstr[2] == '\0'))
Jari Aaltoccc6cda1996-12-23 17:02:34 +00005209 return (DO);
5210
5211 /* Ditto for ESAC in the CASE case.
5212 Specifically, this handles "case word in esac", which is a legal
5213 construct, certainly because someone will pass an empty arg to the
5214 case construct, and we don't want it to barf. Of course, we should
5215 insist that the case construct has at least one pattern in it, but
5216 the designers disagree. */
5217 if (esacs_needed_count)
5218 {
5219 esacs_needed_count--;
Jari Aaltof73dda02001-11-13 17:56:06 +00005220 if (STREQ (tokstr, "esac"))
Jari Aaltoccc6cda1996-12-23 17:02:34 +00005221 {
5222 parser_state &= ~PST_CASEPAT;
5223 return (ESAC);
5224 }
5225 }
5226
5227 /* The start of a shell function definition. */
5228 if (parser_state & PST_ALLOWOPNBRC)
5229 {
5230 parser_state &= ~PST_ALLOWOPNBRC;
Jari Aaltof73dda02001-11-13 17:56:06 +00005231 if (tokstr[0] == '{' && tokstr[1] == '\0') /* } */
Jari Aaltoccc6cda1996-12-23 17:02:34 +00005232 {
5233 open_brace_count++;
5234 function_bstart = line_number;
5235 return ('{'); /* } */
5236 }
5237 }
5238
Jari Aalto28ef6c32001-04-06 19:14:31 +00005239 /* We allow a `do' after a for ((...)) without an intervening
5240 list_terminator */
Jari Aaltof73dda02001-11-13 17:56:06 +00005241 if (last_read_token == ARITH_FOR_EXPRS && tokstr[0] == 'd' && tokstr[1] == 'o' && !tokstr[2])
Jari Aalto28ef6c32001-04-06 19:14:31 +00005242 return (DO);
Jari Aaltof73dda02001-11-13 17:56:06 +00005243 if (last_read_token == ARITH_FOR_EXPRS && tokstr[0] == '{' && tokstr[1] == '\0') /* } */
Jari Aalto28ef6c32001-04-06 19:14:31 +00005244 {
5245 open_brace_count++;
5246 return ('{'); /* } */
5247 }
5248
Jari Aaltof73dda02001-11-13 17:56:06 +00005249 if (open_brace_count && reserved_word_acceptable (last_read_token) && tokstr[0] == '}' && !tokstr[1])
Jari Aaltoccc6cda1996-12-23 17:02:34 +00005250 {
5251 open_brace_count--; /* { */
5252 return ('}');
5253 }
5254
Jari Aaltocce855b1998-04-17 19:52:44 +00005255#if defined (COMMAND_TIMING)
Jari Aaltoccc6cda1996-12-23 17:02:34 +00005256 /* Handle -p after `time'. */
Jari Aaltof73dda02001-11-13 17:56:06 +00005257 if (last_read_token == TIME && tokstr[0] == '-' && tokstr[1] == 'p' && !tokstr[2])
Jari Aaltoccc6cda1996-12-23 17:02:34 +00005258 return (TIMEOPT);
Chet Ramey495aee42011-11-22 19:11:26 -05005259 /* Handle -- after `time -p'. */
5260 if (last_read_token == TIMEOPT && tokstr[0] == '-' && tokstr[1] == '-' && !tokstr[2])
5261 return (TIMEIGN);
Jari Aaltob80f6442004-07-27 13:29:18 +00005262#endif
Jari Aaltocce855b1998-04-17 19:52:44 +00005263
5264#if defined (COND_COMMAND) /* [[ */
Jari Aaltof73dda02001-11-13 17:56:06 +00005265 if ((parser_state & PST_CONDEXPR) && tokstr[0] == ']' && tokstr[1] == ']' && tokstr[2] == '\0')
Jari Aaltocce855b1998-04-17 19:52:44 +00005266 return (COND_END);
5267#endif
Jari Aaltoccc6cda1996-12-23 17:02:34 +00005268
5269 return (-1);
5270}
5271
5272/* Called from shell.c when Control-C is typed at top level. Or
5273 by the error rule at top level. */
5274void
5275reset_parser ()
5276{
5277 dstack.delimiter_depth = 0; /* No delimiters found so far. */
5278 open_brace_count = 0;
5279
Chet Ramey00018032011-11-21 20:51:19 -05005280#if defined (EXTENDED_GLOB)
5281 /* Reset to global value of extended glob */
5282 if (parser_state & PST_EXTPAT)
5283 extended_glob = global_extglob;
5284#endif
5285
Jari Aaltoccc6cda1996-12-23 17:02:34 +00005286 parser_state = 0;
5287
Jari Aaltocce855b1998-04-17 19:52:44 +00005288#if defined (ALIAS) || defined (DPAREN_ARITHMETIC)
Jari Aaltoccc6cda1996-12-23 17:02:34 +00005289 if (pushed_string_list)
Jari Aaltocce855b1998-04-17 19:52:44 +00005290 free_string_list ();
5291#endif /* ALIAS || DPAREN_ARITHMETIC */
Jari Aaltoccc6cda1996-12-23 17:02:34 +00005292
5293 if (shell_input_line)
5294 {
5295 free (shell_input_line);
5296 shell_input_line = (char *)NULL;
5297 shell_input_line_size = shell_input_line_index = 0;
5298 }
5299
5300 FREE (word_desc_to_read);
5301 word_desc_to_read = (WORD_DESC *)NULL;
5302
Chet Ramey836a17b2014-09-26 17:00:50 -04005303 eol_ungetc_lookahead = 0;
5304
Chet Ramey00018032011-11-21 20:51:19 -05005305 current_token = '\n'; /* XXX */
Jari Aaltoccc6cda1996-12-23 17:02:34 +00005306 last_read_token = '\n';
5307 token_to_read = '\n';
5308}
5309
5310/* Read the next token. Command can be READ (normal operation) or
Jari Aalto726f6381996-08-26 18:22:31 +00005311 RESET (to normalize state). */
5312static int
5313read_token (command)
5314 int command;
5315{
5316 int character; /* Current character. */
5317 int peek_char; /* Temporary look-ahead character. */
5318 int result; /* The thing to return. */
Jari Aalto726f6381996-08-26 18:22:31 +00005319
5320 if (command == RESET)
5321 {
Jari Aaltoccc6cda1996-12-23 17:02:34 +00005322 reset_parser ();
Jari Aalto726f6381996-08-26 18:22:31 +00005323 return ('\n');
5324 }
5325
5326 if (token_to_read)
5327 {
Jari Aaltoccc6cda1996-12-23 17:02:34 +00005328 result = token_to_read;
5329 if (token_to_read == WORD || token_to_read == ASSIGNMENT_WORD)
Jari Aaltod166f041997-06-05 14:59:13 +00005330 {
5331 yylval.word = word_desc_to_read;
5332 word_desc_to_read = (WORD_DESC *)NULL;
5333 }
Jari Aalto726f6381996-08-26 18:22:31 +00005334 token_to_read = 0;
Jari Aaltoccc6cda1996-12-23 17:02:34 +00005335 return (result);
Jari Aalto726f6381996-08-26 18:22:31 +00005336 }
5337
Jari Aaltocce855b1998-04-17 19:52:44 +00005338#if defined (COND_COMMAND)
5339 if ((parser_state & (PST_CONDCMD|PST_CONDEXPR)) == PST_CONDCMD)
5340 {
5341 cond_lineno = line_number;
5342 parser_state |= PST_CONDEXPR;
5343 yylval.command = parse_cond_command ();
5344 if (cond_token != COND_END)
5345 {
Jari Aalto7117c2d2002-07-17 14:10:11 +00005346 cond_error ();
Jari Aaltocce855b1998-04-17 19:52:44 +00005347 return (-1);
5348 }
5349 token_to_read = COND_END;
5350 parser_state &= ~(PST_CONDEXPR|PST_CONDCMD);
5351 return (COND_CMD);
5352 }
5353#endif
5354
Jari Aalto726f6381996-08-26 18:22:31 +00005355#if defined (ALIAS)
Jari Aalto726f6381996-08-26 18:22:31 +00005356 /* This is a place to jump back to once we have successfully expanded a
5357 token with an alias and pushed the string with push_string () */
5358 re_read_token:
Jari Aalto726f6381996-08-26 18:22:31 +00005359#endif /* ALIAS */
5360
5361 /* Read a single word from input. Start by skipping blanks. */
Jari Aalto06285672006-10-10 14:15:34 +00005362 while ((character = shell_getc (1)) != EOF && shellblank (character))
Jari Aaltoccc6cda1996-12-23 17:02:34 +00005363 ;
Jari Aalto726f6381996-08-26 18:22:31 +00005364
5365 if (character == EOF)
5366 {
5367 EOF_Reached = 1;
5368 return (yacc_EOF);
5369 }
5370
Jari Aalto7117c2d2002-07-17 14:10:11 +00005371 if MBTEST(character == '#' && (!interactive || interactive_comments))
Jari Aalto726f6381996-08-26 18:22:31 +00005372 {
5373 /* A comment. Discard until EOL or EOF, and then return a newline. */
5374 discard_until ('\n');
5375 shell_getc (0);
Jari Aaltoccc6cda1996-12-23 17:02:34 +00005376 character = '\n'; /* this will take the next if statement and return. */
Jari Aalto726f6381996-08-26 18:22:31 +00005377 }
5378
5379 if (character == '\n')
5380 {
5381 /* If we're about to return an unquoted newline, we can go and collect
5382 the text of any pending here document. */
5383 if (need_here_doc)
5384 gather_here_documents ();
5385
5386#if defined (ALIAS)
Jari Aaltoccc6cda1996-12-23 17:02:34 +00005387 parser_state &= ~PST_ALEXPNEXT;
Jari Aalto726f6381996-08-26 18:22:31 +00005388#endif /* ALIAS */
5389
Jari Aalto95732b42005-12-07 14:08:12 +00005390 parser_state &= ~PST_ASSIGNOK;
5391
Jari Aalto726f6381996-08-26 18:22:31 +00005392 return (character);
5393 }
5394
Jari Aalto31859422009-01-12 13:36:28 +00005395 if (parser_state & PST_REGEXP)
5396 goto tokword;
5397
Jari Aaltoccc6cda1996-12-23 17:02:34 +00005398 /* Shell meta-characters. */
Jari Aalto7117c2d2002-07-17 14:10:11 +00005399 if MBTEST(shellmeta (character) && ((parser_state & PST_DBLPAREN) == 0))
Jari Aalto726f6381996-08-26 18:22:31 +00005400 {
5401#if defined (ALIAS)
5402 /* Turn off alias tokenization iff this character sequence would
5403 not leave us ready to read a command. */
5404 if (character == '<' || character == '>')
Jari Aaltoccc6cda1996-12-23 17:02:34 +00005405 parser_state &= ~PST_ALEXPNEXT;
Jari Aalto726f6381996-08-26 18:22:31 +00005406#endif /* ALIAS */
5407
Jari Aalto95732b42005-12-07 14:08:12 +00005408 parser_state &= ~PST_ASSIGNOK;
5409
Jari Aaltoccc6cda1996-12-23 17:02:34 +00005410 peek_char = shell_getc (1);
5411 if (character == peek_char)
Jari Aalto726f6381996-08-26 18:22:31 +00005412 {
5413 switch (character)
5414 {
Jari Aaltoccc6cda1996-12-23 17:02:34 +00005415 case '<':
Jari Aalto726f6381996-08-26 18:22:31 +00005416 /* If '<' then we could be at "<<" or at "<<-". We have to
5417 look ahead one more character. */
Jari Aalto726f6381996-08-26 18:22:31 +00005418 peek_char = shell_getc (1);
Jari Aalto31859422009-01-12 13:36:28 +00005419 if MBTEST(peek_char == '-')
Jari Aalto726f6381996-08-26 18:22:31 +00005420 return (LESS_LESS_MINUS);
Jari Aalto31859422009-01-12 13:36:28 +00005421 else if MBTEST(peek_char == '<')
Jari Aalto7117c2d2002-07-17 14:10:11 +00005422 return (LESS_LESS_LESS);
Jari Aalto726f6381996-08-26 18:22:31 +00005423 else
5424 {
5425 shell_ungetc (peek_char);
5426 return (LESS_LESS);
5427 }
5428
5429 case '>':
5430 return (GREATER_GREATER);
5431
5432 case ';':
Jari Aaltoccc6cda1996-12-23 17:02:34 +00005433 parser_state |= PST_CASEPAT;
Jari Aalto726f6381996-08-26 18:22:31 +00005434#if defined (ALIAS)
Jari Aaltoccc6cda1996-12-23 17:02:34 +00005435 parser_state &= ~PST_ALEXPNEXT;
Jari Aalto726f6381996-08-26 18:22:31 +00005436#endif /* ALIAS */
Jari Aalto95732b42005-12-07 14:08:12 +00005437
Jari Aalto31859422009-01-12 13:36:28 +00005438 peek_char = shell_getc (1);
5439 if MBTEST(peek_char == '&')
5440 return (SEMI_SEMI_AND);
5441 else
5442 {
5443 shell_ungetc (peek_char);
5444 return (SEMI_SEMI);
5445 }
Jari Aalto726f6381996-08-26 18:22:31 +00005446
5447 case '&':
5448 return (AND_AND);
5449
5450 case '|':
5451 return (OR_OR);
Jari Aaltoccc6cda1996-12-23 17:02:34 +00005452
Jari Aaltobb706242000-03-17 21:46:59 +00005453#if defined (DPAREN_ARITHMETIC) || defined (ARITH_FOR_COMMAND)
Jari Aaltoccc6cda1996-12-23 17:02:34 +00005454 case '(': /* ) */
Jari Aalto7117c2d2002-07-17 14:10:11 +00005455 result = parse_dparen (character);
5456 if (result == -2)
5457 break;
5458 else
5459 return result;
Jari Aaltoccc6cda1996-12-23 17:02:34 +00005460#endif
Jari Aalto726f6381996-08-26 18:22:31 +00005461 }
Jari Aalto726f6381996-08-26 18:22:31 +00005462 }
Jari Aalto7117c2d2002-07-17 14:10:11 +00005463 else if MBTEST(character == '<' && peek_char == '&')
Jari Aaltoccc6cda1996-12-23 17:02:34 +00005464 return (LESS_AND);
Jari Aalto7117c2d2002-07-17 14:10:11 +00005465 else if MBTEST(character == '>' && peek_char == '&')
Jari Aaltoccc6cda1996-12-23 17:02:34 +00005466 return (GREATER_AND);
Jari Aalto7117c2d2002-07-17 14:10:11 +00005467 else if MBTEST(character == '<' && peek_char == '>')
Jari Aaltoccc6cda1996-12-23 17:02:34 +00005468 return (LESS_GREATER);
Jari Aalto7117c2d2002-07-17 14:10:11 +00005469 else if MBTEST(character == '>' && peek_char == '|')
Jari Aaltoccc6cda1996-12-23 17:02:34 +00005470 return (GREATER_BAR);
Jari Aalto31859422009-01-12 13:36:28 +00005471 else if MBTEST(character == '&' && peek_char == '>')
5472 {
5473 peek_char = shell_getc (1);
5474 if MBTEST(peek_char == '>')
5475 return (AND_GREATER_GREATER);
5476 else
5477 {
5478 shell_ungetc (peek_char);
5479 return (AND_GREATER);
5480 }
5481 }
5482 else if MBTEST(character == '|' && peek_char == '&')
5483 return (BAR_AND);
5484 else if MBTEST(character == ';' && peek_char == '&')
5485 {
5486 parser_state |= PST_CASEPAT;
5487#if defined (ALIAS)
5488 parser_state &= ~PST_ALEXPNEXT;
5489#endif /* ALIAS */
5490 return (SEMI_AND);
5491 }
Jari Aaltoccc6cda1996-12-23 17:02:34 +00005492
Jari Aalto726f6381996-08-26 18:22:31 +00005493 shell_ungetc (peek_char);
5494
5495 /* If we look like we are reading the start of a function
5496 definition, then let the reader know about it so that
5497 we will do the right thing with `{'. */
Jari Aalto7117c2d2002-07-17 14:10:11 +00005498 if MBTEST(character == ')' && last_read_token == '(' && token_before_that == WORD)
Jari Aalto726f6381996-08-26 18:22:31 +00005499 {
Jari Aaltoccc6cda1996-12-23 17:02:34 +00005500 parser_state |= PST_ALLOWOPNBRC;
Jari Aalto726f6381996-08-26 18:22:31 +00005501#if defined (ALIAS)
Jari Aaltoccc6cda1996-12-23 17:02:34 +00005502 parser_state &= ~PST_ALEXPNEXT;
Jari Aalto726f6381996-08-26 18:22:31 +00005503#endif /* ALIAS */
Jari Aaltoccc6cda1996-12-23 17:02:34 +00005504 function_dstart = line_number;
Jari Aalto726f6381996-08-26 18:22:31 +00005505 }
5506
Jari Aaltoccc6cda1996-12-23 17:02:34 +00005507 /* case pattern lists may be preceded by an optional left paren. If
5508 we're not trying to parse a case pattern list, the left paren
5509 indicates a subshell. */
Jari Aalto7117c2d2002-07-17 14:10:11 +00005510 if MBTEST(character == '(' && (parser_state & PST_CASEPAT) == 0) /* ) */
Jari Aaltoccc6cda1996-12-23 17:02:34 +00005511 parser_state |= PST_SUBSHELL;
5512 /*(*/
Jari Aalto7117c2d2002-07-17 14:10:11 +00005513 else if MBTEST((parser_state & PST_CASEPAT) && character == ')')
Jari Aalto28ef6c32001-04-06 19:14:31 +00005514 parser_state &= ~PST_CASEPAT;
Jari Aaltoccc6cda1996-12-23 17:02:34 +00005515 /*(*/
Jari Aalto7117c2d2002-07-17 14:10:11 +00005516 else if MBTEST((parser_state & PST_SUBSHELL) && character == ')')
Jari Aaltoccc6cda1996-12-23 17:02:34 +00005517 parser_state &= ~PST_SUBSHELL;
Jari Aalto726f6381996-08-26 18:22:31 +00005518
5519#if defined (PROCESS_SUBSTITUTION)
5520 /* Check for the constructs which introduce process substitution.
5521 Shells running in `posix mode' don't do process substitution. */
Jari Aalto7117c2d2002-07-17 14:10:11 +00005522 if MBTEST(posixly_correct || ((character != '>' && character != '<') || peek_char != '(')) /*)*/
Jari Aalto726f6381996-08-26 18:22:31 +00005523#endif /* PROCESS_SUBSTITUTION */
5524 return (character);
5525 }
5526
Jari Aalto7117c2d2002-07-17 14:10:11 +00005527 /* Hack <&- (close stdin) case. Also <&N- (dup and close). */
5528 if MBTEST(character == '-' && (last_read_token == LESS_AND || last_read_token == GREATER_AND))
Jari Aaltoccc6cda1996-12-23 17:02:34 +00005529 return (character);
5530
Jari Aalto31859422009-01-12 13:36:28 +00005531tokword:
Jari Aalto726f6381996-08-26 18:22:31 +00005532 /* Okay, if we got this far, we have to read a word. Read one,
5533 and then check it against the known ones. */
Jari Aaltoccc6cda1996-12-23 17:02:34 +00005534 result = read_token_word (character);
5535#if defined (ALIAS)
5536 if (result == RE_READ_TOKEN)
5537 goto re_read_token;
5538#endif
5539 return result;
5540}
Jari Aalto726f6381996-08-26 18:22:31 +00005541
Jari Aalto7117c2d2002-07-17 14:10:11 +00005542/*
5543 * Match a $(...) or other grouping construct. This has to handle embedded
5544 * quoted strings ('', ``, "") and nested constructs. It also must handle
Jari Aalto95732b42005-12-07 14:08:12 +00005545 * reprompting the user, if necessary, after reading a newline, and returning
5546 * correct error values if it reads EOF.
Jari Aalto7117c2d2002-07-17 14:10:11 +00005547 */
Chet Ramey495aee42011-11-22 19:11:26 -05005548#define P_FIRSTCLOSE 0x0001
5549#define P_ALLOWESC 0x0002
5550#define P_DQUOTE 0x0004
5551#define P_COMMAND 0x0008 /* parsing a command, so look for comments */
5552#define P_BACKQUOTE 0x0010 /* parsing a backquoted command substitution */
5553#define P_ARRAYSUB 0x0020 /* parsing a [...] array subscript for assignment */
5554#define P_DOLBRACE 0x0040 /* parsing a ${...} construct */
Jari Aaltob72432f1999-02-19 17:11:39 +00005555
Jari Aalto31859422009-01-12 13:36:28 +00005556/* Lexical state while parsing a grouping construct or $(...). */
5557#define LEX_WASDOL 0x001
5558#define LEX_CKCOMMENT 0x002
5559#define LEX_INCOMMENT 0x004
5560#define LEX_PASSNEXT 0x008
5561#define LEX_RESWDOK 0x010
5562#define LEX_CKCASE 0x020
5563#define LEX_INCASE 0x040
5564#define LEX_INHEREDOC 0x080
5565#define LEX_HEREDELIM 0x100 /* reading here-doc delimiter */
5566#define LEX_STRIPDOC 0x200 /* <<- strip tabs from here doc delim */
Chet Ramey00018032011-11-21 20:51:19 -05005567#define LEX_INWORD 0x400
Jari Aalto31859422009-01-12 13:36:28 +00005568
5569#define COMSUB_META(ch) ((ch) == ';' || (ch) == '&' || (ch) == '|')
5570
5571#define CHECK_NESTRET_ERROR() \
5572 do { \
5573 if (nestret == &matched_pair_error) \
5574 { \
5575 free (ret); \
5576 return &matched_pair_error; \
5577 } \
5578 } while (0)
5579
5580#define APPEND_NESTRET() \
5581 do { \
5582 if (nestlen) \
5583 { \
5584 RESIZE_MALLOCED_BUFFER (ret, retind, nestlen, retsize, 64); \
5585 strcpy (ret + retind, nestret); \
5586 retind += nestlen; \
5587 } \
5588 } while (0)
5589
Jari Aaltoccc6cda1996-12-23 17:02:34 +00005590static char matched_pair_error;
Jari Aalto31859422009-01-12 13:36:28 +00005591
Jari Aaltoccc6cda1996-12-23 17:02:34 +00005592static char *
5593parse_matched_pair (qc, open, close, lenp, flags)
5594 int qc; /* `"' if this construct is within double quotes */
5595 int open, close;
5596 int *lenp, flags;
5597{
Jari Aalto31859422009-01-12 13:36:28 +00005598 int count, ch, tflags;
5599 int nestlen, ttranslen, start_lineno;
Jari Aalto28ef6c32001-04-06 19:14:31 +00005600 char *ret, *nestret, *ttrans;
Jari Aaltob80f6442004-07-27 13:29:18 +00005601 int retind, retsize, rflags;
Chet Ramey495aee42011-11-22 19:11:26 -05005602 int dolbrace_state;
5603
5604 dolbrace_state = (flags & P_DOLBRACE) ? DOLBRACE_PARAM : 0;
Jari Aalto726f6381996-08-26 18:22:31 +00005605
Chet Ramey00018032011-11-21 20:51:19 -05005606/*itrace("parse_matched_pair[%d]: open = %c close = %c flags = %d", line_number, open, close, flags);*/
Jari Aaltoccc6cda1996-12-23 17:02:34 +00005607 count = 1;
Jari Aalto31859422009-01-12 13:36:28 +00005608 tflags = 0;
5609
5610 if ((flags & P_COMMAND) && qc != '`' && qc != '\'' && qc != '"' && (flags & P_DQUOTE) == 0)
5611 tflags |= LEX_CKCOMMENT;
Jari Aalto726f6381996-08-26 18:22:31 +00005612
Jari Aaltob80f6442004-07-27 13:29:18 +00005613 /* RFLAGS is the set of flags we want to pass to recursive calls. */
5614 rflags = (qc == '"') ? P_DQUOTE : (flags & P_DQUOTE);
5615
Jari Aaltof73dda02001-11-13 17:56:06 +00005616 ret = (char *)xmalloc (retsize = 64);
Jari Aaltoccc6cda1996-12-23 17:02:34 +00005617 retind = 0;
Jari Aalto726f6381996-08-26 18:22:31 +00005618
Jari Aaltoccc6cda1996-12-23 17:02:34 +00005619 start_lineno = line_number;
5620 while (count)
5621 {
Chet Ramey495aee42011-11-22 19:11:26 -05005622 ch = shell_getc (qc != '\'' && (tflags & (LEX_PASSNEXT)) == 0);
Jari Aalto06285672006-10-10 14:15:34 +00005623
Jari Aaltoccc6cda1996-12-23 17:02:34 +00005624 if (ch == EOF)
5625 {
5626 free (ret);
Jari Aaltob80f6442004-07-27 13:29:18 +00005627 parser_error (start_lineno, _("unexpected EOF while looking for matching `%c'"), close);
Jari Aaltoccc6cda1996-12-23 17:02:34 +00005628 EOF_Reached = 1; /* XXX */
5629 return (&matched_pair_error);
5630 }
Jari Aalto726f6381996-08-26 18:22:31 +00005631
Jari Aaltoccc6cda1996-12-23 17:02:34 +00005632 /* Possible reprompting. */
Jari Aaltob80f6442004-07-27 13:29:18 +00005633 if (ch == '\n' && SHOULD_PROMPT ())
Jari Aaltoccc6cda1996-12-23 17:02:34 +00005634 prompt_again ();
Jari Aalto726f6381996-08-26 18:22:31 +00005635
Jari Aalto31859422009-01-12 13:36:28 +00005636 /* Don't bother counting parens or doing anything else if in a comment
5637 or part of a case statement */
5638 if (tflags & LEX_INCOMMENT)
Jari Aalto95732b42005-12-07 14:08:12 +00005639 {
5640 /* Add this character. */
5641 RESIZE_MALLOCED_BUFFER (ret, retind, 1, retsize, 64);
5642 ret[retind++] = ch;
5643
5644 if (ch == '\n')
Jari Aalto31859422009-01-12 13:36:28 +00005645 tflags &= ~LEX_INCOMMENT;
Jari Aalto95732b42005-12-07 14:08:12 +00005646
5647 continue;
5648 }
Jari Aalto31859422009-01-12 13:36:28 +00005649
Jari Aalto06285672006-10-10 14:15:34 +00005650 /* Not exactly right yet, should handle shell metacharacters, too. If
5651 any changes are made to this test, make analogous changes to subst.c:
5652 extract_delimited_string(). */
Jari Aalto31859422009-01-12 13:36:28 +00005653 else if MBTEST((tflags & LEX_CKCOMMENT) && (tflags & LEX_INCOMMENT) == 0 && ch == '#' && (retind == 0 || ret[retind-1] == '\n' || shellblank (ret[retind - 1])))
5654 tflags |= LEX_INCOMMENT;
Jari Aalto95732b42005-12-07 14:08:12 +00005655
Jari Aalto31859422009-01-12 13:36:28 +00005656 if (tflags & LEX_PASSNEXT) /* last char was backslash */
Jari Aalto06285672006-10-10 14:15:34 +00005657 {
Jari Aalto31859422009-01-12 13:36:28 +00005658 tflags &= ~LEX_PASSNEXT;
Jari Aaltoccc6cda1996-12-23 17:02:34 +00005659 if (qc != '\'' && ch == '\n') /* double-quoted \<newline> disappears. */
5660 {
Jari Aalto31859422009-01-12 13:36:28 +00005661 if (retind > 0)
5662 retind--; /* swallow previously-added backslash */
Jari Aaltoccc6cda1996-12-23 17:02:34 +00005663 continue;
5664 }
Jari Aalto726f6381996-08-26 18:22:31 +00005665
Jari Aaltoccc6cda1996-12-23 17:02:34 +00005666 RESIZE_MALLOCED_BUFFER (ret, retind, 2, retsize, 64);
Chet Rameyac50fba2014-02-26 09:36:43 -05005667 if MBTEST(ch == CTLESC)
Jari Aaltoccc6cda1996-12-23 17:02:34 +00005668 ret[retind++] = CTLESC;
5669 ret[retind++] = ch;
5670 continue;
5671 }
Jari Aalto31859422009-01-12 13:36:28 +00005672 /* If we're reparsing the input (e.g., from parse_string_to_word_list),
5673 we've already prepended CTLESC to single-quoted results of $'...'.
5674 We may want to do this for other CTLESC-quoted characters in
5675 reparse, too. */
5676 else if MBTEST((parser_state & PST_REPARSE) && open == '\'' && (ch == CTLESC || ch == CTLNUL))
5677 {
5678 RESIZE_MALLOCED_BUFFER (ret, retind, 1, retsize, 64);
5679 ret[retind++] = ch;
5680 continue;
5681 }
Jari Aalto7117c2d2002-07-17 14:10:11 +00005682 else if MBTEST(ch == CTLESC || ch == CTLNUL) /* special shell escapes */
Jari Aaltoccc6cda1996-12-23 17:02:34 +00005683 {
5684 RESIZE_MALLOCED_BUFFER (ret, retind, 2, retsize, 64);
5685 ret[retind++] = CTLESC;
5686 ret[retind++] = ch;
5687 continue;
5688 }
Jari Aalto7117c2d2002-07-17 14:10:11 +00005689 else if MBTEST(ch == close) /* ending delimiter */
Jari Aaltoccc6cda1996-12-23 17:02:34 +00005690 count--;
Jari Aaltobb706242000-03-17 21:46:59 +00005691 /* handle nested ${...} specially. */
Jari Aalto31859422009-01-12 13:36:28 +00005692 else if MBTEST(open != close && (tflags & LEX_WASDOL) && open == '{' && ch == open) /* } */
Jari Aalto28ef6c32001-04-06 19:14:31 +00005693 count++;
Jari Aalto7117c2d2002-07-17 14:10:11 +00005694 else if MBTEST(((flags & P_FIRSTCLOSE) == 0) && ch == open) /* nested begin */
Jari Aaltoccc6cda1996-12-23 17:02:34 +00005695 count++;
Jari Aalto726f6381996-08-26 18:22:31 +00005696
Jari Aaltoccc6cda1996-12-23 17:02:34 +00005697 /* Add this character. */
5698 RESIZE_MALLOCED_BUFFER (ret, retind, 1, retsize, 64);
5699 ret[retind++] = ch;
Jari Aalto726f6381996-08-26 18:22:31 +00005700
Jari Aalto31859422009-01-12 13:36:28 +00005701 /* If we just read the ending character, don't bother continuing. */
5702 if (count == 0)
5703 break;
5704
Jari Aaltoccc6cda1996-12-23 17:02:34 +00005705 if (open == '\'') /* '' inside grouping construct */
Jari Aaltobb706242000-03-17 21:46:59 +00005706 {
Jari Aalto7117c2d2002-07-17 14:10:11 +00005707 if MBTEST((flags & P_ALLOWESC) && ch == '\\')
Jari Aalto31859422009-01-12 13:36:28 +00005708 tflags |= LEX_PASSNEXT;
Jari Aaltobb706242000-03-17 21:46:59 +00005709 continue;
5710 }
Jari Aalto726f6381996-08-26 18:22:31 +00005711
Jari Aalto7117c2d2002-07-17 14:10:11 +00005712 if MBTEST(ch == '\\') /* backslashes */
Jari Aalto31859422009-01-12 13:36:28 +00005713 tflags |= LEX_PASSNEXT;
Jari Aalto726f6381996-08-26 18:22:31 +00005714
Chet Ramey495aee42011-11-22 19:11:26 -05005715 /* Based on which dolstate is currently in (param, op, or word),
5716 decide what the op is. We're really only concerned if it's % or
5717 #, so we can turn on a flag that says whether or not we should
5718 treat single quotes as special when inside a double-quoted
5719 ${...}. This logic must agree with subst.c:extract_dollar_brace_string
5720 since they share the same defines. */
Chet Rameyac50fba2014-02-26 09:36:43 -05005721 /* FLAG POSIX INTERP 221 */
Chet Ramey495aee42011-11-22 19:11:26 -05005722 if (flags & P_DOLBRACE)
5723 {
5724 /* ${param%[%]word} */
5725 if MBTEST(dolbrace_state == DOLBRACE_PARAM && ch == '%' && retind > 1)
5726 dolbrace_state = DOLBRACE_QUOTE;
5727 /* ${param#[#]word} */
5728 else if MBTEST(dolbrace_state == DOLBRACE_PARAM && ch == '#' && retind > 1)
5729 dolbrace_state = DOLBRACE_QUOTE;
5730 /* ${param/[/]pat/rep} */
5731 else if MBTEST(dolbrace_state == DOLBRACE_PARAM && ch == '/' && retind > 1)
Chet Rameyac50fba2014-02-26 09:36:43 -05005732 dolbrace_state = DOLBRACE_QUOTE2; /* XXX */
Chet Ramey495aee42011-11-22 19:11:26 -05005733 /* ${param^[^]pat} */
5734 else if MBTEST(dolbrace_state == DOLBRACE_PARAM && ch == '^' && retind > 1)
5735 dolbrace_state = DOLBRACE_QUOTE;
5736 /* ${param,[,]pat} */
5737 else if MBTEST(dolbrace_state == DOLBRACE_PARAM && ch == ',' && retind > 1)
5738 dolbrace_state = DOLBRACE_QUOTE;
5739 else if MBTEST(dolbrace_state == DOLBRACE_PARAM && strchr ("#%^,~:-=?+/", ch) != 0)
5740 dolbrace_state = DOLBRACE_OP;
5741 else if MBTEST(dolbrace_state == DOLBRACE_OP && strchr ("#%^,~:-=?+/", ch) == 0)
5742 dolbrace_state = DOLBRACE_WORD;
5743 }
5744
Jari Aalto31859422009-01-12 13:36:28 +00005745 /* The big hammer. Single quotes aren't special in double quotes. The
Chet Ramey495aee42011-11-22 19:11:26 -05005746 problem is that Posix used to say the single quotes are semi-special:
Jari Aalto31859422009-01-12 13:36:28 +00005747 within a double-quoted ${...} construct "an even number of
5748 unescaped double-quotes or single-quotes, if any, shall occur." */
Chet Ramey495aee42011-11-22 19:11:26 -05005749 /* This was changed in Austin Group Interp 221 */
Chet Rameybc63a082014-03-28 11:53:44 -04005750 if MBTEST(posixly_correct && shell_compatibility_level > 41 && dolbrace_state != DOLBRACE_QUOTE && dolbrace_state != DOLBRACE_QUOTE2 && (flags & P_DQUOTE) && (flags & P_DOLBRACE) && ch == '\'')
Jari Aalto31859422009-01-12 13:36:28 +00005751 continue;
Jari Aalto31859422009-01-12 13:36:28 +00005752
5753 /* Could also check open == '`' if we want to parse grouping constructs
5754 inside old-style command substitution. */
Jari Aaltoccc6cda1996-12-23 17:02:34 +00005755 if (open != close) /* a grouping construct */
5756 {
Jari Aalto7117c2d2002-07-17 14:10:11 +00005757 if MBTEST(shellquote (ch))
Jari Aaltoccc6cda1996-12-23 17:02:34 +00005758 {
5759 /* '', ``, or "" inside $(...) or other grouping construct. */
5760 push_delimiter (dstack, ch);
Jari Aalto31859422009-01-12 13:36:28 +00005761 if MBTEST((tflags & LEX_WASDOL) && ch == '\'') /* $'...' inside group */
Jari Aaltob80f6442004-07-27 13:29:18 +00005762 nestret = parse_matched_pair (ch, ch, ch, &nestlen, P_ALLOWESC|rflags);
Jari Aalto28ef6c32001-04-06 19:14:31 +00005763 else
Jari Aaltob80f6442004-07-27 13:29:18 +00005764 nestret = parse_matched_pair (ch, ch, ch, &nestlen, rflags);
Jari Aaltoccc6cda1996-12-23 17:02:34 +00005765 pop_delimiter (dstack);
Jari Aalto31859422009-01-12 13:36:28 +00005766 CHECK_NESTRET_ERROR ();
5767
5768 if MBTEST((tflags & LEX_WASDOL) && ch == '\'' && (extended_quote || (rflags & P_DQUOTE) == 0))
Jari Aalto28ef6c32001-04-06 19:14:31 +00005769 {
5770 /* Translate $'...' here. */
5771 ttrans = ansiexpand (nestret, 0, nestlen - 1, &ttranslen);
Jari Aaltof73dda02001-11-13 17:56:06 +00005772 xfree (nestret);
Jari Aalto95732b42005-12-07 14:08:12 +00005773
Chet Rameyac50fba2014-02-26 09:36:43 -05005774 /* If we're parsing a double-quoted brace expansion and we are
5775 not in a place where single quotes are treated specially,
5776 make sure we single-quote the results of the ansi
5777 expansion because quote removal should remove them later */
5778 /* FLAG POSIX INTERP 221 */
5779 if ((shell_compatibility_level > 42) && (rflags & P_DQUOTE) && (dolbrace_state == DOLBRACE_QUOTE2) && (flags & P_DOLBRACE))
5780 {
5781 nestret = sh_single_quote (ttrans);
5782 free (ttrans);
5783 nestlen = strlen (nestret);
5784 }
5785 else if ((rflags & P_DQUOTE) == 0)
Jari Aalto95732b42005-12-07 14:08:12 +00005786 {
5787 nestret = sh_single_quote (ttrans);
5788 free (ttrans);
5789 nestlen = strlen (nestret);
5790 }
5791 else
5792 {
5793 nestret = ttrans;
5794 nestlen = ttranslen;
5795 }
Jari Aalto28ef6c32001-04-06 19:14:31 +00005796 retind -= 2; /* back up before the $' */
5797 }
Jari Aalto31859422009-01-12 13:36:28 +00005798 else if MBTEST((tflags & LEX_WASDOL) && ch == '"' && (extended_quote || (rflags & P_DQUOTE) == 0))
Jari Aalto28ef6c32001-04-06 19:14:31 +00005799 {
5800 /* Locale expand $"..." here. */
5801 ttrans = localeexpand (nestret, 0, nestlen - 1, start_lineno, &ttranslen);
Jari Aaltof73dda02001-11-13 17:56:06 +00005802 xfree (nestret);
Jari Aalto95732b42005-12-07 14:08:12 +00005803
5804 nestret = sh_mkdoublequoted (ttrans, ttranslen, 0);
Jari Aalto28ef6c32001-04-06 19:14:31 +00005805 free (ttrans);
Jari Aalto95732b42005-12-07 14:08:12 +00005806 nestlen = ttranslen + 2;
Jari Aalto28ef6c32001-04-06 19:14:31 +00005807 retind -= 2; /* back up before the $" */
5808 }
Jari Aalto7117c2d2002-07-17 14:10:11 +00005809
Jari Aalto31859422009-01-12 13:36:28 +00005810 APPEND_NESTRET ();
Jari Aaltoccc6cda1996-12-23 17:02:34 +00005811 FREE (nestret);
5812 }
Chet Ramey00018032011-11-21 20:51:19 -05005813 else if ((flags & P_ARRAYSUB) && (tflags & LEX_WASDOL) && (ch == '(' || ch == '{' || ch == '[')) /* ) } ] */
5814 goto parse_dollar_word;
Jari Aaltoccc6cda1996-12-23 17:02:34 +00005815 }
5816 /* Parse an old-style command substitution within double quotes as a
5817 single word. */
5818 /* XXX - sh and ksh93 don't do this - XXX */
Jari Aalto7117c2d2002-07-17 14:10:11 +00005819 else if MBTEST(open == '"' && ch == '`')
Jari Aaltoccc6cda1996-12-23 17:02:34 +00005820 {
Jari Aaltob80f6442004-07-27 13:29:18 +00005821 nestret = parse_matched_pair (0, '`', '`', &nestlen, rflags);
Jari Aalto31859422009-01-12 13:36:28 +00005822
5823 CHECK_NESTRET_ERROR ();
5824 APPEND_NESTRET ();
5825
Jari Aaltoccc6cda1996-12-23 17:02:34 +00005826 FREE (nestret);
5827 }
Jari Aalto31859422009-01-12 13:36:28 +00005828 else if MBTEST(open != '`' && (tflags & LEX_WASDOL) && (ch == '(' || ch == '{' || ch == '[')) /* ) } ] */
Jari Aaltoccc6cda1996-12-23 17:02:34 +00005829 /* check for $(), $[], or ${} inside quoted string. */
5830 {
Chet Ramey00018032011-11-21 20:51:19 -05005831parse_dollar_word:
Jari Aaltoccc6cda1996-12-23 17:02:34 +00005832 if (open == ch) /* undo previous increment */
5833 count--;
5834 if (ch == '(') /* ) */
Jari Aalto31859422009-01-12 13:36:28 +00005835 nestret = parse_comsub (0, '(', ')', &nestlen, (rflags|P_COMMAND) & ~P_DQUOTE);
Jari Aaltoccc6cda1996-12-23 17:02:34 +00005836 else if (ch == '{') /* } */
Chet Ramey495aee42011-11-22 19:11:26 -05005837 nestret = parse_matched_pair (0, '{', '}', &nestlen, P_FIRSTCLOSE|P_DOLBRACE|rflags);
Jari Aaltoccc6cda1996-12-23 17:02:34 +00005838 else if (ch == '[') /* ] */
Jari Aaltob80f6442004-07-27 13:29:18 +00005839 nestret = parse_matched_pair (0, '[', ']', &nestlen, rflags);
Jari Aalto95732b42005-12-07 14:08:12 +00005840
Jari Aalto31859422009-01-12 13:36:28 +00005841 CHECK_NESTRET_ERROR ();
5842 APPEND_NESTRET ();
5843
5844 FREE (nestret);
Jari Aaltoccc6cda1996-12-23 17:02:34 +00005845 }
Jari Aalto31859422009-01-12 13:36:28 +00005846 if MBTEST(ch == '$')
5847 tflags |= LEX_WASDOL;
5848 else
5849 tflags &= ~LEX_WASDOL;
Jari Aaltoccc6cda1996-12-23 17:02:34 +00005850 }
Jari Aalto726f6381996-08-26 18:22:31 +00005851
Jari Aaltoccc6cda1996-12-23 17:02:34 +00005852 ret[retind] = '\0';
5853 if (lenp)
5854 *lenp = retind;
Chet Ramey00018032011-11-21 20:51:19 -05005855/*itrace("parse_matched_pair[%d]: returning %s", line_number, ret);*/
Jari Aaltoccc6cda1996-12-23 17:02:34 +00005856 return ret;
5857}
Jari Aalto726f6381996-08-26 18:22:31 +00005858
Jari Aalto31859422009-01-12 13:36:28 +00005859/* Parse a $(...) command substitution. This is messier than I'd like, and
5860 reproduces a lot more of the token-reading code than I'd like. */
5861static char *
5862parse_comsub (qc, open, close, lenp, flags)
5863 int qc; /* `"' if this construct is within double quotes */
5864 int open, close;
5865 int *lenp, flags;
5866{
Chet Ramey00018032011-11-21 20:51:19 -05005867 int count, ch, peekc, tflags, lex_rwlen, lex_wlen, lex_firstind;
Jari Aalto31859422009-01-12 13:36:28 +00005868 int nestlen, ttranslen, start_lineno;
5869 char *ret, *nestret, *ttrans, *heredelim;
5870 int retind, retsize, rflags, hdlen;
5871
Chet Ramey495aee42011-11-22 19:11:26 -05005872 /* Posix interp 217 says arithmetic expressions have precedence, so
5873 assume $(( introduces arithmetic expansion and parse accordingly. */
5874 peekc = shell_getc (0);
5875 shell_ungetc (peekc);
5876 if (peekc == '(')
5877 return (parse_matched_pair (qc, open, close, lenp, 0));
5878
Jari Aalto31859422009-01-12 13:36:28 +00005879/*itrace("parse_comsub: qc = `%c' open = %c close = %c", qc, open, close);*/
5880 count = 1;
5881 tflags = LEX_RESWDOK;
5882
5883 if ((flags & P_COMMAND) && qc != '\'' && qc != '"' && (flags & P_DQUOTE) == 0)
5884 tflags |= LEX_CKCASE;
5885 if ((tflags & LEX_CKCASE) && (interactive == 0 || interactive_comments))
5886 tflags |= LEX_CKCOMMENT;
5887
5888 /* RFLAGS is the set of flags we want to pass to recursive calls. */
5889 rflags = (flags & P_DQUOTE);
5890
5891 ret = (char *)xmalloc (retsize = 64);
5892 retind = 0;
5893
5894 start_lineno = line_number;
Chet Ramey00018032011-11-21 20:51:19 -05005895 lex_rwlen = lex_wlen = 0;
Jari Aalto31859422009-01-12 13:36:28 +00005896
5897 heredelim = 0;
5898 lex_firstind = -1;
5899
5900 while (count)
5901 {
5902comsub_readchar:
Chet Ramey495aee42011-11-22 19:11:26 -05005903 ch = shell_getc (qc != '\'' && (tflags & (LEX_INCOMMENT|LEX_PASSNEXT)) == 0);
Jari Aalto31859422009-01-12 13:36:28 +00005904
5905 if (ch == EOF)
5906 {
5907eof_error:
5908 free (ret);
5909 FREE (heredelim);
5910 parser_error (start_lineno, _("unexpected EOF while looking for matching `%c'"), close);
5911 EOF_Reached = 1; /* XXX */
5912 return (&matched_pair_error);
5913 }
5914
5915 /* If we hit the end of a line and are reading the contents of a here
5916 document, and it's not the same line that the document starts on,
5917 check for this line being the here doc delimiter. Otherwise, if
5918 we're in a here document, mark the next character as the beginning
5919 of a line. */
5920 if (ch == '\n')
5921 {
5922 if ((tflags & LEX_HEREDELIM) && heredelim)
5923 {
5924 tflags &= ~LEX_HEREDELIM;
5925 tflags |= LEX_INHEREDOC;
5926 lex_firstind = retind + 1;
5927 }
5928 else if (tflags & LEX_INHEREDOC)
5929 {
5930 int tind;
5931 tind = lex_firstind;
5932 while ((tflags & LEX_STRIPDOC) && ret[tind] == '\t')
5933 tind++;
5934 if (STREQN (ret + tind, heredelim, hdlen))
5935 {
5936 tflags &= ~(LEX_STRIPDOC|LEX_INHEREDOC);
5937/*itrace("parse_comsub:%d: found here doc end `%s'", line_number, ret + tind);*/
Chet Ramey00018032011-11-21 20:51:19 -05005938 free (heredelim);
5939 heredelim = 0;
Jari Aalto31859422009-01-12 13:36:28 +00005940 lex_firstind = -1;
5941 }
5942 else
5943 lex_firstind = retind + 1;
5944 }
5945 }
5946
5947 /* Possible reprompting. */
5948 if (ch == '\n' && SHOULD_PROMPT ())
5949 prompt_again ();
5950
Chet Ramey00018032011-11-21 20:51:19 -05005951 /* XXX -- possibly allow here doc to be delimited by ending right
5952 paren. */
5953 if ((tflags & LEX_INHEREDOC) && ch == close && count == 1)
5954 {
5955 int tind;
5956/*itrace("parse_comsub: in here doc, ch == close, retind - firstind = %d hdlen = %d retind = %d", retind-lex_firstind, hdlen, retind);*/
5957 tind = lex_firstind;
5958 while ((tflags & LEX_STRIPDOC) && ret[tind] == '\t')
5959 tind++;
5960 if (retind-tind == hdlen && STREQN (ret + tind, heredelim, hdlen))
5961 {
5962 tflags &= ~(LEX_STRIPDOC|LEX_INHEREDOC);
5963/*itrace("parse_comsub:%d: found here doc end `%s'", line_number, ret + tind);*/
5964 free (heredelim);
5965 heredelim = 0;
5966 lex_firstind = -1;
5967 }
5968 }
5969
Jari Aalto31859422009-01-12 13:36:28 +00005970 /* Don't bother counting parens or doing anything else if in a comment */
5971 if (tflags & (LEX_INCOMMENT|LEX_INHEREDOC))
5972 {
5973 /* Add this character. */
5974 RESIZE_MALLOCED_BUFFER (ret, retind, 1, retsize, 64);
5975 ret[retind++] = ch;
5976
5977 if ((tflags & LEX_INCOMMENT) && ch == '\n')
Chet Rameyac50fba2014-02-26 09:36:43 -05005978 {
Chet Ramey00018032011-11-21 20:51:19 -05005979/*itrace("parse_comsub:%d: lex_incomment -> 0 ch = `%c'", line_number, ch);*/
Chet Rameyac50fba2014-02-26 09:36:43 -05005980 tflags &= ~LEX_INCOMMENT;
5981 }
Jari Aalto31859422009-01-12 13:36:28 +00005982
5983 continue;
5984 }
5985
Chet Ramey00018032011-11-21 20:51:19 -05005986 if (tflags & LEX_PASSNEXT) /* last char was backslash */
5987 {
5988/*itrace("parse_comsub:%d: lex_passnext -> 0 ch = `%c' (%d)", line_number, ch, __LINE__);*/
5989 tflags &= ~LEX_PASSNEXT;
5990 if (qc != '\'' && ch == '\n') /* double-quoted \<newline> disappears. */
5991 {
5992 if (retind > 0)
5993 retind--; /* swallow previously-added backslash */
5994 continue;
5995 }
5996
5997 RESIZE_MALLOCED_BUFFER (ret, retind, 2, retsize, 64);
Chet Rameyac50fba2014-02-26 09:36:43 -05005998 if MBTEST(ch == CTLESC)
Chet Ramey00018032011-11-21 20:51:19 -05005999 ret[retind++] = CTLESC;
6000 ret[retind++] = ch;
6001 continue;
6002 }
6003
6004 /* If this is a shell break character, we are not in a word. If not,
6005 we either start or continue a word. */
6006 if MBTEST(shellbreak (ch))
6007 {
6008 tflags &= ~LEX_INWORD;
6009/*itrace("parse_comsub:%d: lex_inword -> 0 ch = `%c' (%d)", line_number, ch, __LINE__);*/
6010 }
6011 else
6012 {
6013 if (tflags & LEX_INWORD)
6014 {
6015 lex_wlen++;
6016/*itrace("parse_comsub:%d: lex_inword == 1 ch = `%c' lex_wlen = %d (%d)", line_number, ch, lex_wlen, __LINE__);*/
6017 }
6018 else
6019 {
6020/*itrace("parse_comsub:%d: lex_inword -> 1 ch = `%c' (%d)", line_number, ch, __LINE__);*/
6021 tflags |= LEX_INWORD;
6022 lex_wlen = 0;
Chet Rameyf88c5442015-08-13 15:38:42 -04006023 if (tflags & LEX_RESWDOK)
6024 lex_rwlen = 0;
Chet Ramey00018032011-11-21 20:51:19 -05006025 }
6026 }
6027
Jari Aalto31859422009-01-12 13:36:28 +00006028 /* Skip whitespace */
Chet Ramey495aee42011-11-22 19:11:26 -05006029 if MBTEST(shellblank (ch) && (tflags & LEX_HEREDELIM) == 0 && lex_rwlen == 0)
Jari Aalto31859422009-01-12 13:36:28 +00006030 {
6031 /* Add this character. */
6032 RESIZE_MALLOCED_BUFFER (ret, retind, 1, retsize, 64);
6033 ret[retind++] = ch;
6034 continue;
6035 }
6036
6037 /* Either we are looking for the start of the here-doc delimiter
6038 (lex_firstind == -1) or we are reading one (lex_firstind >= 0).
6039 If this character is a shell break character and we are reading
6040 the delimiter, save it and note that we are now reading a here
6041 document. If we've found the start of the delimiter, note it by
6042 setting lex_firstind. Backslashes can quote shell metacharacters
6043 in here-doc delimiters. */
6044 if (tflags & LEX_HEREDELIM)
6045 {
6046 if (lex_firstind == -1 && shellbreak (ch) == 0)
6047 lex_firstind = retind;
Chet Ramey00018032011-11-21 20:51:19 -05006048#if 0
6049 else if (heredelim && (tflags & LEX_PASSNEXT) == 0 && ch == '\n')
6050 {
6051 tflags |= LEX_INHEREDOC;
6052 tflags &= ~LEX_HEREDELIM;
6053 lex_firstind = retind + 1;
6054 }
6055#endif
Jari Aalto31859422009-01-12 13:36:28 +00006056 else if (lex_firstind >= 0 && (tflags & LEX_PASSNEXT) == 0 && shellbreak (ch))
6057 {
Chet Ramey00018032011-11-21 20:51:19 -05006058 if (heredelim == 0)
6059 {
6060 nestret = substring (ret, lex_firstind, retind);
6061 heredelim = string_quote_removal (nestret, 0);
6062 free (nestret);
6063 hdlen = STRLEN(heredelim);
Jari Aalto31859422009-01-12 13:36:28 +00006064/*itrace("parse_comsub:%d: found here doc delimiter `%s' (%d)", line_number, heredelim, hdlen);*/
Chet Ramey00018032011-11-21 20:51:19 -05006065 }
Jari Aalto31859422009-01-12 13:36:28 +00006066 if (ch == '\n')
6067 {
6068 tflags |= LEX_INHEREDOC;
6069 tflags &= ~LEX_HEREDELIM;
6070 lex_firstind = retind + 1;
6071 }
6072 else
6073 lex_firstind = -1;
6074 }
6075 }
6076
6077 /* Meta-characters that can introduce a reserved word. Not perfect yet. */
Chet Ramey00018032011-11-21 20:51:19 -05006078 if MBTEST((tflags & LEX_RESWDOK) == 0 && (tflags & LEX_CKCASE) && (tflags & LEX_INCOMMENT) == 0 && (shellmeta(ch) || ch == '\n'))
Jari Aalto31859422009-01-12 13:36:28 +00006079 {
6080 /* Add this character. */
6081 RESIZE_MALLOCED_BUFFER (ret, retind, 1, retsize, 64);
6082 ret[retind++] = ch;
6083 peekc = shell_getc (1);
6084 if (ch == peekc && (ch == '&' || ch == '|' || ch == ';')) /* two-character tokens */
6085 {
6086 RESIZE_MALLOCED_BUFFER (ret, retind, 1, retsize, 64);
6087 ret[retind++] = peekc;
Chet Ramey00018032011-11-21 20:51:19 -05006088/*itrace("parse_comsub:%d: set lex_reswordok = 1, ch = `%c'", line_number, ch);*/
Jari Aalto31859422009-01-12 13:36:28 +00006089 tflags |= LEX_RESWDOK;
6090 lex_rwlen = 0;
6091 continue;
6092 }
6093 else if (ch == '\n' || COMSUB_META(ch))
6094 {
6095 shell_ungetc (peekc);
Jari Aalto31859422009-01-12 13:36:28 +00006096/*itrace("parse_comsub:%d: set lex_reswordok = 1, ch = `%c'", line_number, ch);*/
Chet Ramey00018032011-11-21 20:51:19 -05006097 tflags |= LEX_RESWDOK;
Jari Aalto31859422009-01-12 13:36:28 +00006098 lex_rwlen = 0;
6099 continue;
6100 }
6101 else if (ch == EOF)
6102 goto eof_error;
6103 else
6104 {
6105 /* `unget' the character we just added and fall through */
6106 retind--;
6107 shell_ungetc (peekc);
6108 }
6109 }
6110
6111 /* If we can read a reserved word, try to read one. */
6112 if (tflags & LEX_RESWDOK)
6113 {
6114 if MBTEST(islower (ch))
6115 {
6116 /* Add this character. */
6117 RESIZE_MALLOCED_BUFFER (ret, retind, 1, retsize, 64);
6118 ret[retind++] = ch;
6119 lex_rwlen++;
6120 continue;
6121 }
6122 else if MBTEST(lex_rwlen == 4 && shellbreak (ch))
6123 {
6124 if (STREQN (ret + retind - 4, "case", 4))
Chet Rameyac50fba2014-02-26 09:36:43 -05006125 {
6126 tflags |= LEX_INCASE;
Chet Ramey00018032011-11-21 20:51:19 -05006127/*itrace("parse_comsub:%d: found `case', lex_incase -> 1 lex_reswdok -> 0", line_number);*/
Chet Rameyac50fba2014-02-26 09:36:43 -05006128 }
Jari Aalto31859422009-01-12 13:36:28 +00006129 else if (STREQN (ret + retind - 4, "esac", 4))
Chet Rameyac50fba2014-02-26 09:36:43 -05006130 {
6131 tflags &= ~LEX_INCASE;
Chet Ramey00018032011-11-21 20:51:19 -05006132/*itrace("parse_comsub:%d: found `esac', lex_incase -> 0 lex_reswdok -> 0", line_number);*/
Chet Rameyac50fba2014-02-26 09:36:43 -05006133 }
Jari Aalto31859422009-01-12 13:36:28 +00006134 tflags &= ~LEX_RESWDOK;
6135 }
Chet Ramey00018032011-11-21 20:51:19 -05006136 else if MBTEST((tflags & LEX_CKCOMMENT) && ch == '#' && (lex_rwlen == 0 || ((tflags & LEX_INWORD) && lex_wlen == 0)))
6137 ; /* don't modify LEX_RESWDOK if we're starting a comment */
Chet Rameyac50fba2014-02-26 09:36:43 -05006138 /* Allow `do' followed by space, tab, or newline to preserve the
6139 RESWDOK flag, but reset the reserved word length counter so we
6140 can read another one. */
6141 else if MBTEST(((tflags & LEX_INCASE) == 0) &&
6142 (isblank(ch) || ch == '\n') &&
6143 lex_rwlen == 2 &&
6144 STREQN (ret + retind - 2, "do", 2))
6145 {
6146/*itrace("parse_comsub:%d: lex_incase == 1 found `%c', found \"do\"", line_number, ch);*/
6147 lex_rwlen = 0;
6148 }
Chet Ramey00018032011-11-21 20:51:19 -05006149 else if MBTEST((tflags & LEX_INCASE) && ch != '\n')
6150 /* If we can read a reserved word and we're in case, we're at the
6151 point where we can read a new pattern list or an esac. We
6152 handle the esac case above. If we read a newline, we want to
6153 leave LEX_RESWDOK alone. If we read anything else, we want to
6154 turn off LEX_RESWDOK, since we're going to read a pattern list. */
Chet Rameyac50fba2014-02-26 09:36:43 -05006155 {
6156 tflags &= ~LEX_RESWDOK;
Chet Ramey00018032011-11-21 20:51:19 -05006157/*itrace("parse_comsub:%d: lex_incase == 1 found `%c', lex_reswordok -> 0", line_number, ch);*/
Chet Rameyac50fba2014-02-26 09:36:43 -05006158 }
Chet Ramey00018032011-11-21 20:51:19 -05006159 else if MBTEST(shellbreak (ch) == 0)
Chet Rameyac50fba2014-02-26 09:36:43 -05006160 {
6161 tflags &= ~LEX_RESWDOK;
Jari Aalto31859422009-01-12 13:36:28 +00006162/*itrace("parse_comsub:%d: found `%c', lex_reswordok -> 0", line_number, ch);*/
Chet Rameyac50fba2014-02-26 09:36:43 -05006163 }
6164#if 0
6165 /* If we find a space or tab but have read something and it's not
6166 `do', turn off the reserved-word-ok flag */
6167 else if MBTEST(isblank (ch) && lex_rwlen > 0)
6168 {
6169 tflags &= ~LEX_RESWDOK;
6170/*itrace("parse_comsub:%d: found `%c', lex_reswordok -> 0", line_number, ch);*/
6171 }
6172#endif
Jari Aalto31859422009-01-12 13:36:28 +00006173 }
6174
Chet Ramey00018032011-11-21 20:51:19 -05006175 /* Might be the start of a here-doc delimiter */
Jari Aalto31859422009-01-12 13:36:28 +00006176 if MBTEST((tflags & LEX_INCOMMENT) == 0 && (tflags & LEX_CKCASE) && ch == '<')
6177 {
6178 /* Add this character. */
6179 RESIZE_MALLOCED_BUFFER (ret, retind, 1, retsize, 64);
6180 ret[retind++] = ch;
6181 peekc = shell_getc (1);
6182 if (peekc == EOF)
6183 goto eof_error;
6184 if (peekc == ch)
6185 {
6186 RESIZE_MALLOCED_BUFFER (ret, retind, 1, retsize, 64);
6187 ret[retind++] = peekc;
6188 peekc = shell_getc (1);
6189 if (peekc == EOF)
6190 goto eof_error;
6191 if (peekc == '-')
6192 {
6193 RESIZE_MALLOCED_BUFFER (ret, retind, 1, retsize, 64);
6194 ret[retind++] = peekc;
6195 tflags |= LEX_STRIPDOC;
6196 }
6197 else
6198 shell_ungetc (peekc);
Chet Ramey00018032011-11-21 20:51:19 -05006199 if (peekc != '<')
6200 {
6201 tflags |= LEX_HEREDELIM;
6202 lex_firstind = -1;
6203 }
Jari Aalto31859422009-01-12 13:36:28 +00006204 continue;
6205 }
6206 else
Chet Ramey00018032011-11-21 20:51:19 -05006207 ch = peekc; /* fall through and continue XXX */
Jari Aalto31859422009-01-12 13:36:28 +00006208 }
Chet Ramey00018032011-11-21 20:51:19 -05006209 else if MBTEST((tflags & LEX_CKCOMMENT) && (tflags & LEX_INCOMMENT) == 0 && ch == '#' && (((tflags & LEX_RESWDOK) && lex_rwlen == 0) || ((tflags & LEX_INWORD) && lex_wlen == 0)))
Chet Rameyac50fba2014-02-26 09:36:43 -05006210 {
Chet Ramey00018032011-11-21 20:51:19 -05006211/*itrace("parse_comsub:%d: lex_incomment -> 1 (%d)", line_number, __LINE__);*/
Chet Rameyac50fba2014-02-26 09:36:43 -05006212 tflags |= LEX_INCOMMENT;
6213 }
Jari Aalto31859422009-01-12 13:36:28 +00006214
Chet Ramey00018032011-11-21 20:51:19 -05006215 if MBTEST(ch == CTLESC || ch == CTLNUL) /* special shell escapes */
Jari Aalto31859422009-01-12 13:36:28 +00006216 {
6217 RESIZE_MALLOCED_BUFFER (ret, retind, 2, retsize, 64);
6218 ret[retind++] = CTLESC;
6219 ret[retind++] = ch;
6220 continue;
6221 }
6222#if 0
6223 else if MBTEST((tflags & LEX_INCASE) && ch == close && close == ')')
6224 tflags &= ~LEX_INCASE; /* XXX */
6225#endif
6226 else if MBTEST(ch == close && (tflags & LEX_INCASE) == 0) /* ending delimiter */
Chet Rameyac50fba2014-02-26 09:36:43 -05006227 {
6228 count--;
Jari Aalto31859422009-01-12 13:36:28 +00006229/*itrace("parse_comsub:%d: found close: count = %d", line_number, count);*/
Chet Rameyac50fba2014-02-26 09:36:43 -05006230 }
Jari Aalto31859422009-01-12 13:36:28 +00006231 else if MBTEST(((flags & P_FIRSTCLOSE) == 0) && (tflags & LEX_INCASE) == 0 && ch == open) /* nested begin */
Chet Rameyac50fba2014-02-26 09:36:43 -05006232 {
6233 count++;
Chet Ramey00018032011-11-21 20:51:19 -05006234/*itrace("parse_comsub:%d: found open: count = %d", line_number, count);*/
Chet Rameyac50fba2014-02-26 09:36:43 -05006235 }
Jari Aalto31859422009-01-12 13:36:28 +00006236
6237 /* Add this character. */
6238 RESIZE_MALLOCED_BUFFER (ret, retind, 1, retsize, 64);
6239 ret[retind++] = ch;
6240
6241 /* If we just read the ending character, don't bother continuing. */
6242 if (count == 0)
6243 break;
6244
6245 if MBTEST(ch == '\\') /* backslashes */
6246 tflags |= LEX_PASSNEXT;
6247
6248 if MBTEST(shellquote (ch))
6249 {
6250 /* '', ``, or "" inside $(...). */
6251 push_delimiter (dstack, ch);
6252 if MBTEST((tflags & LEX_WASDOL) && ch == '\'') /* $'...' inside group */
6253 nestret = parse_matched_pair (ch, ch, ch, &nestlen, P_ALLOWESC|rflags);
6254 else
6255 nestret = parse_matched_pair (ch, ch, ch, &nestlen, rflags);
6256 pop_delimiter (dstack);
6257 CHECK_NESTRET_ERROR ();
6258
6259 if MBTEST((tflags & LEX_WASDOL) && ch == '\'' && (extended_quote || (rflags & P_DQUOTE) == 0))
6260 {
6261 /* Translate $'...' here. */
6262 ttrans = ansiexpand (nestret, 0, nestlen - 1, &ttranslen);
6263 xfree (nestret);
6264
6265 if ((rflags & P_DQUOTE) == 0)
6266 {
6267 nestret = sh_single_quote (ttrans);
6268 free (ttrans);
6269 nestlen = strlen (nestret);
6270 }
6271 else
6272 {
6273 nestret = ttrans;
6274 nestlen = ttranslen;
6275 }
6276 retind -= 2; /* back up before the $' */
6277 }
6278 else if MBTEST((tflags & LEX_WASDOL) && ch == '"' && (extended_quote || (rflags & P_DQUOTE) == 0))
6279 {
6280 /* Locale expand $"..." here. */
6281 ttrans = localeexpand (nestret, 0, nestlen - 1, start_lineno, &ttranslen);
6282 xfree (nestret);
6283
6284 nestret = sh_mkdoublequoted (ttrans, ttranslen, 0);
6285 free (ttrans);
6286 nestlen = ttranslen + 2;
6287 retind -= 2; /* back up before the $" */
6288 }
6289
6290 APPEND_NESTRET ();
6291 FREE (nestret);
6292 }
6293 else if MBTEST((tflags & LEX_WASDOL) && (ch == '(' || ch == '{' || ch == '[')) /* ) } ] */
6294 /* check for $(), $[], or ${} inside command substitution. */
6295 {
6296 if ((tflags & LEX_INCASE) == 0 && open == ch) /* undo previous increment */
6297 count--;
6298 if (ch == '(') /* ) */
6299 nestret = parse_comsub (0, '(', ')', &nestlen, (rflags|P_COMMAND) & ~P_DQUOTE);
6300 else if (ch == '{') /* } */
Chet Ramey495aee42011-11-22 19:11:26 -05006301 nestret = parse_matched_pair (0, '{', '}', &nestlen, P_FIRSTCLOSE|P_DOLBRACE|rflags);
Jari Aalto31859422009-01-12 13:36:28 +00006302 else if (ch == '[') /* ] */
6303 nestret = parse_matched_pair (0, '[', ']', &nestlen, rflags);
6304
6305 CHECK_NESTRET_ERROR ();
6306 APPEND_NESTRET ();
6307
6308 FREE (nestret);
6309 }
6310 if MBTEST(ch == '$')
6311 tflags |= LEX_WASDOL;
6312 else
6313 tflags &= ~LEX_WASDOL;
6314 }
6315
6316 FREE (heredelim);
6317 ret[retind] = '\0';
6318 if (lenp)
6319 *lenp = retind;
6320/*itrace("parse_comsub:%d: returning `%s'", line_number, ret);*/
6321 return ret;
6322}
6323
Chet Ramey495aee42011-11-22 19:11:26 -05006324/* Recursively call the parser to parse a $(...) command substitution. */
Jari Aalto31859422009-01-12 13:36:28 +00006325char *
6326xparse_dolparen (base, string, indp, flags)
6327 char *base;
6328 char *string;
6329 int *indp;
6330 int flags;
6331{
6332 sh_parser_state_t ps;
Chet Ramey509a4432013-01-10 19:53:16 -05006333 sh_input_line_state_t ls;
Chet Rameyac50fba2014-02-26 09:36:43 -05006334 int orig_ind, nc, sflags, orig_eof_token;
Jari Aalto31859422009-01-12 13:36:28 +00006335 char *ret, *s, *ep, *ostring;
6336
6337 /*yydebug = 1;*/
6338 orig_ind = *indp;
6339 ostring = string;
6340
Chet Ramey509a4432013-01-10 19:53:16 -05006341/*itrace("xparse_dolparen: size = %d shell_input_line = `%s'", shell_input_line_size, shell_input_line);*/
Jari Aalto31859422009-01-12 13:36:28 +00006342 sflags = SEVAL_NONINT|SEVAL_NOHIST|SEVAL_NOFREE;
6343 if (flags & SX_NOLONGJMP)
6344 sflags |= SEVAL_NOLONGJMP;
6345 save_parser_state (&ps);
Chet Ramey509a4432013-01-10 19:53:16 -05006346 save_input_line_state (&ls);
Chet Rameyac50fba2014-02-26 09:36:43 -05006347 orig_eof_token = shell_eof_token;
Jari Aalto31859422009-01-12 13:36:28 +00006348
6349 /*(*/
6350 parser_state |= PST_CMDSUBST|PST_EOFTOKEN; /* allow instant ')' */ /*(*/
6351 shell_eof_token = ')';
6352 parse_string (string, "command substitution", sflags, &ep);
6353
Chet Rameyac50fba2014-02-26 09:36:43 -05006354 shell_eof_token = orig_eof_token;
Jari Aalto31859422009-01-12 13:36:28 +00006355 restore_parser_state (&ps);
6356 reset_parser ();
Chet Ramey509a4432013-01-10 19:53:16 -05006357 /* reset_parser clears shell_input_line and associated variables */
6358 restore_input_line_state (&ls);
Chet Ramey80b4d712014-10-05 19:12:20 -04006359
6360 token_to_read = 0;
Jari Aalto31859422009-01-12 13:36:28 +00006361
6362 /* Need to find how many characters parse_and_execute consumed, update
6363 *indp, if flags != 0, copy the portion of the string parsed into RET
6364 and return it. If flags & 1 (EX_NOALLOC) we can return NULL. */
6365
6366 /*(*/
6367 if (ep[-1] != ')')
6368 {
6369#if DEBUG
6370 if (ep[-1] != '\n')
6371 itrace("xparse_dolparen:%d: ep[-1] != RPAREN (%d), ep = `%s'", line_number, ep[-1], ep);
6372#endif
6373 while (ep > ostring && ep[-1] == '\n') ep--;
6374 }
6375
6376 nc = ep - ostring;
6377 *indp = ep - base - 1;
6378
6379 /*(*/
6380#if DEBUG
6381 if (base[*indp] != ')')
6382 itrace("xparse_dolparen:%d: base[%d] != RPAREN (%d), base = `%s'", line_number, *indp, base[*indp], base);
6383#endif
6384
6385 if (flags & SX_NOALLOC)
6386 return (char *)NULL;
6387
6388 if (nc == 0)
6389 {
6390 ret = xmalloc (1);
6391 ret[0] = '\0';
6392 }
6393 else
6394 ret = substring (ostring, 0, nc - 1);
6395
6396 return ret;
6397}
6398
Jari Aaltobb706242000-03-17 21:46:59 +00006399#if defined (DPAREN_ARITHMETIC) || defined (ARITH_FOR_COMMAND)
Jari Aalto7117c2d2002-07-17 14:10:11 +00006400/* Parse a double-paren construct. It can be either an arithmetic
6401 command, an arithmetic `for' command, or a nested subshell. Returns
6402 the parsed token, -1 on error, or -2 if we didn't do anything and
6403 should just go on. */
6404static int
6405parse_dparen (c)
6406 int c;
6407{
Jari Aalto06285672006-10-10 14:15:34 +00006408 int cmdtyp, sline;
6409 char *wval;
Jari Aalto7117c2d2002-07-17 14:10:11 +00006410 WORD_DESC *wd;
6411
6412#if defined (ARITH_FOR_COMMAND)
6413 if (last_read_token == FOR)
6414 {
6415 arith_for_lineno = line_number;
Jari Aaltob80f6442004-07-27 13:29:18 +00006416 cmdtyp = parse_arith_cmd (&wval, 0);
Jari Aalto7117c2d2002-07-17 14:10:11 +00006417 if (cmdtyp == 1)
6418 {
Jari Aalto95732b42005-12-07 14:08:12 +00006419 wd = alloc_word_desc ();
6420 wd->word = wval;
Jari Aalto7117c2d2002-07-17 14:10:11 +00006421 yylval.word_list = make_word_list (wd, (WORD_LIST *)NULL);
Jari Aalto7117c2d2002-07-17 14:10:11 +00006422 return (ARITH_FOR_EXPRS);
6423 }
6424 else
6425 return -1; /* ERROR */
6426 }
6427#endif
6428
6429#if defined (DPAREN_ARITHMETIC)
6430 if (reserved_word_acceptable (last_read_token))
6431 {
6432 sline = line_number;
Jari Aalto95732b42005-12-07 14:08:12 +00006433
Jari Aaltob80f6442004-07-27 13:29:18 +00006434 cmdtyp = parse_arith_cmd (&wval, 0);
Jari Aalto7117c2d2002-07-17 14:10:11 +00006435 if (cmdtyp == 1) /* arithmetic command */
6436 {
Jari Aalto95732b42005-12-07 14:08:12 +00006437 wd = alloc_word_desc ();
6438 wd->word = wval;
6439 wd->flags = W_QUOTED|W_NOSPLIT|W_NOGLOB|W_DQUOTE;
Jari Aalto7117c2d2002-07-17 14:10:11 +00006440 yylval.word_list = make_word_list (wd, (WORD_LIST *)NULL);
Jari Aalto7117c2d2002-07-17 14:10:11 +00006441 return (ARITH_CMD);
6442 }
6443 else if (cmdtyp == 0) /* nested subshell */
6444 {
6445 push_string (wval, 0, (alias_t *)NULL);
Chet Rameyac50fba2014-02-26 09:36:43 -05006446 pushed_string_list->flags = PSH_DPAREN;
Jari Aalto7117c2d2002-07-17 14:10:11 +00006447 if ((parser_state & PST_CASEPAT) == 0)
6448 parser_state |= PST_SUBSHELL;
6449 return (c);
6450 }
6451 else /* ERROR */
6452 return -1;
6453 }
6454#endif
6455
6456 return -2; /* XXX */
6457}
6458
Jari Aaltod166f041997-06-05 14:59:13 +00006459/* We've seen a `(('. Look for the matching `))'. If we get it, return 1.
6460 If not, assume it's a nested subshell for backwards compatibility and
6461 return 0. In any case, put the characters we've consumed into a locally-
6462 allocated buffer and make *ep point to that buffer. Return -1 on an
6463 error, for example EOF. */
6464static int
Jari Aaltob80f6442004-07-27 13:29:18 +00006465parse_arith_cmd (ep, adddq)
Jari Aaltod166f041997-06-05 14:59:13 +00006466 char **ep;
Jari Aaltob80f6442004-07-27 13:29:18 +00006467 int adddq;
Jari Aaltod166f041997-06-05 14:59:13 +00006468{
6469 int exp_lineno, rval, c;
Jari Aaltof73dda02001-11-13 17:56:06 +00006470 char *ttok, *tokstr;
Jari Aaltod166f041997-06-05 14:59:13 +00006471 int ttoklen;
6472
6473 exp_lineno = line_number;
6474 ttok = parse_matched_pair (0, '(', ')', &ttoklen, 0);
6475 rval = 1;
6476 if (ttok == &matched_pair_error)
6477 return -1;
6478 /* Check that the next character is the closing right paren. If
6479 not, this is a syntax error. ( */
Jari Aalto7117c2d2002-07-17 14:10:11 +00006480 c = shell_getc (0);
6481 if MBTEST(c != ')')
Jari Aaltod166f041997-06-05 14:59:13 +00006482 rval = 0;
6483
Jari Aaltof73dda02001-11-13 17:56:06 +00006484 tokstr = (char *)xmalloc (ttoklen + 4);
Jari Aaltod166f041997-06-05 14:59:13 +00006485
Jari Aaltob80f6442004-07-27 13:29:18 +00006486 /* if ADDDQ != 0 then (( ... )) -> "..." */
6487 if (rval == 1 && adddq) /* arith cmd, add double quotes */
Jari Aaltod166f041997-06-05 14:59:13 +00006488 {
Jari Aaltob80f6442004-07-27 13:29:18 +00006489 tokstr[0] = '"';
6490 strncpy (tokstr + 1, ttok, ttoklen - 1);
Jari Aaltof73dda02001-11-13 17:56:06 +00006491 tokstr[ttoklen] = '"';
6492 tokstr[ttoklen+1] = '\0';
Jari Aaltod166f041997-06-05 14:59:13 +00006493 }
Jari Aaltob80f6442004-07-27 13:29:18 +00006494 else if (rval == 1) /* arith cmd, don't add double quotes */
Jari Aaltod166f041997-06-05 14:59:13 +00006495 {
Jari Aaltob80f6442004-07-27 13:29:18 +00006496 strncpy (tokstr, ttok, ttoklen - 1);
6497 tokstr[ttoklen-1] = '\0';
6498 }
6499 else /* nested subshell */
6500 {
6501 tokstr[0] = '(';
6502 strncpy (tokstr + 1, ttok, ttoklen - 1);
Jari Aaltof73dda02001-11-13 17:56:06 +00006503 tokstr[ttoklen] = ')';
6504 tokstr[ttoklen+1] = c;
6505 tokstr[ttoklen+2] = '\0';
Jari Aaltod166f041997-06-05 14:59:13 +00006506 }
Jari Aaltob80f6442004-07-27 13:29:18 +00006507
Jari Aaltof73dda02001-11-13 17:56:06 +00006508 *ep = tokstr;
Jari Aaltod166f041997-06-05 14:59:13 +00006509 FREE (ttok);
6510 return rval;
6511}
Jari Aaltobb706242000-03-17 21:46:59 +00006512#endif /* DPAREN_ARITHMETIC || ARITH_FOR_COMMAND */
Jari Aaltod166f041997-06-05 14:59:13 +00006513
Jari Aaltocce855b1998-04-17 19:52:44 +00006514#if defined (COND_COMMAND)
Jari Aalto7117c2d2002-07-17 14:10:11 +00006515static void
6516cond_error ()
6517{
6518 char *etext;
6519
6520 if (EOF_Reached && cond_token != COND_ERROR) /* [[ */
Jari Aaltob80f6442004-07-27 13:29:18 +00006521 parser_error (cond_lineno, _("unexpected EOF while looking for `]]'"));
Jari Aalto7117c2d2002-07-17 14:10:11 +00006522 else if (cond_token != COND_ERROR)
6523 {
6524 if (etext = error_token_from_token (cond_token))
6525 {
Jari Aaltob80f6442004-07-27 13:29:18 +00006526 parser_error (cond_lineno, _("syntax error in conditional expression: unexpected token `%s'"), etext);
Jari Aalto7117c2d2002-07-17 14:10:11 +00006527 free (etext);
6528 }
6529 else
Jari Aaltob80f6442004-07-27 13:29:18 +00006530 parser_error (cond_lineno, _("syntax error in conditional expression"));
Jari Aalto7117c2d2002-07-17 14:10:11 +00006531 }
6532}
6533
Jari Aaltocce855b1998-04-17 19:52:44 +00006534static COND_COM *
6535cond_expr ()
6536{
6537 return (cond_or ());
6538}
6539
6540static COND_COM *
6541cond_or ()
6542{
6543 COND_COM *l, *r;
6544
6545 l = cond_and ();
6546 if (cond_token == OR_OR)
6547 {
6548 r = cond_or ();
6549 l = make_cond_node (COND_OR, (WORD_DESC *)NULL, l, r);
6550 }
6551 return l;
6552}
6553
6554static COND_COM *
6555cond_and ()
6556{
6557 COND_COM *l, *r;
6558
6559 l = cond_term ();
6560 if (cond_token == AND_AND)
6561 {
6562 r = cond_and ();
6563 l = make_cond_node (COND_AND, (WORD_DESC *)NULL, l, r);
6564 }
6565 return l;
6566}
6567
6568static int
6569cond_skip_newlines ()
6570{
6571 while ((cond_token = read_token (READ)) == '\n')
6572 {
Jari Aaltob80f6442004-07-27 13:29:18 +00006573 if (SHOULD_PROMPT ())
Jari Aaltocce855b1998-04-17 19:52:44 +00006574 prompt_again ();
6575 }
6576 return (cond_token);
6577}
6578
6579#define COND_RETURN_ERROR() \
6580 do { cond_token = COND_ERROR; return ((COND_COM *)NULL); } while (0)
6581
6582static COND_COM *
6583cond_term ()
6584{
6585 WORD_DESC *op;
6586 COND_COM *term, *tleft, *tright;
6587 int tok, lineno;
Jari Aalto7117c2d2002-07-17 14:10:11 +00006588 char *etext;
Jari Aaltocce855b1998-04-17 19:52:44 +00006589
6590 /* Read a token. It can be a left paren, a `!', a unary operator, or a
6591 word that should be the first argument of a binary operator. Start by
6592 skipping newlines, since this is a compound command. */
6593 tok = cond_skip_newlines ();
6594 lineno = line_number;
6595 if (tok == COND_END)
6596 {
6597 COND_RETURN_ERROR ();
6598 }
6599 else if (tok == '(')
6600 {
6601 term = cond_expr ();
6602 if (cond_token != ')')
6603 {
6604 if (term)
6605 dispose_cond_node (term); /* ( */
Jari Aalto7117c2d2002-07-17 14:10:11 +00006606 if (etext = error_token_from_token (cond_token))
6607 {
Jari Aaltob80f6442004-07-27 13:29:18 +00006608 parser_error (lineno, _("unexpected token `%s', expected `)'"), etext);
Jari Aalto7117c2d2002-07-17 14:10:11 +00006609 free (etext);
6610 }
6611 else
Jari Aaltob80f6442004-07-27 13:29:18 +00006612 parser_error (lineno, _("expected `)'"));
Jari Aaltocce855b1998-04-17 19:52:44 +00006613 COND_RETURN_ERROR ();
6614 }
6615 term = make_cond_node (COND_EXPR, (WORD_DESC *)NULL, term, (COND_COM *)NULL);
6616 (void)cond_skip_newlines ();
6617 }
6618 else if (tok == BANG || (tok == WORD && (yylval.word->word[0] == '!' && yylval.word->word[1] == '\0')))
6619 {
6620 if (tok == WORD)
6621 dispose_word (yylval.word); /* not needed */
6622 term = cond_term ();
6623 if (term)
6624 term->flags |= CMD_INVERT_RETURN;
6625 }
Jari Aalto31859422009-01-12 13:36:28 +00006626 else if (tok == WORD && yylval.word->word[0] == '-' && yylval.word->word[2] == 0 && test_unop (yylval.word->word))
Jari Aaltocce855b1998-04-17 19:52:44 +00006627 {
6628 op = yylval.word;
6629 tok = read_token (READ);
6630 if (tok == WORD)
6631 {
6632 tleft = make_cond_node (COND_TERM, yylval.word, (COND_COM *)NULL, (COND_COM *)NULL);
6633 term = make_cond_node (COND_UNARY, op, tleft, (COND_COM *)NULL);
6634 }
6635 else
6636 {
6637 dispose_word (op);
Jari Aalto7117c2d2002-07-17 14:10:11 +00006638 if (etext = error_token_from_token (tok))
6639 {
Jari Aaltob80f6442004-07-27 13:29:18 +00006640 parser_error (line_number, _("unexpected argument `%s' to conditional unary operator"), etext);
Jari Aalto7117c2d2002-07-17 14:10:11 +00006641 free (etext);
6642 }
6643 else
Jari Aaltob80f6442004-07-27 13:29:18 +00006644 parser_error (line_number, _("unexpected argument to conditional unary operator"));
Jari Aaltocce855b1998-04-17 19:52:44 +00006645 COND_RETURN_ERROR ();
6646 }
6647
6648 (void)cond_skip_newlines ();
6649 }
Jari Aaltobb706242000-03-17 21:46:59 +00006650 else if (tok == WORD) /* left argument to binary operator */
Jari Aaltocce855b1998-04-17 19:52:44 +00006651 {
6652 /* lhs */
6653 tleft = make_cond_node (COND_TERM, yylval.word, (COND_COM *)NULL, (COND_COM *)NULL);
6654
6655 /* binop */
6656 tok = read_token (READ);
6657 if (tok == WORD && test_binop (yylval.word->word))
Chet Ramey00018032011-11-21 20:51:19 -05006658 {
6659 op = yylval.word;
6660 if (op->word[0] == '=' && (op->word[1] == '\0' || (op->word[1] == '=' && op->word[2] == '\0')))
6661 parser_state |= PST_EXTPAT;
6662 else if (op->word[0] == '!' && op->word[1] == '=' && op->word[2] == '\0')
6663 parser_state |= PST_EXTPAT;
6664 }
Jari Aaltob80f6442004-07-27 13:29:18 +00006665#if defined (COND_REGEXP)
Jari Aalto31859422009-01-12 13:36:28 +00006666 else if (tok == WORD && STREQ (yylval.word->word, "=~"))
6667 {
6668 op = yylval.word;
6669 parser_state |= PST_REGEXP;
6670 }
Jari Aaltob80f6442004-07-27 13:29:18 +00006671#endif
Jari Aaltocce855b1998-04-17 19:52:44 +00006672 else if (tok == '<' || tok == '>')
Jari Aalto28ef6c32001-04-06 19:14:31 +00006673 op = make_word_from_token (tok); /* ( */
6674 /* There should be a check before blindly accepting the `)' that we have
6675 seen the opening `('. */
6676 else if (tok == COND_END || tok == AND_AND || tok == OR_OR || tok == ')')
Jari Aaltocce855b1998-04-17 19:52:44 +00006677 {
6678 /* Special case. [[ x ]] is equivalent to [[ -n x ]], just like
6679 the test command. Similarly for [[ x && expr ]] or
Jari Aalto28ef6c32001-04-06 19:14:31 +00006680 [[ x || expr ]] or [[ (x) ]]. */
Jari Aaltocce855b1998-04-17 19:52:44 +00006681 op = make_word ("-n");
6682 term = make_cond_node (COND_UNARY, op, tleft, (COND_COM *)NULL);
6683 cond_token = tok;
6684 return (term);
6685 }
6686 else
6687 {
Jari Aalto7117c2d2002-07-17 14:10:11 +00006688 if (etext = error_token_from_token (tok))
6689 {
Jari Aaltob80f6442004-07-27 13:29:18 +00006690 parser_error (line_number, _("unexpected token `%s', conditional binary operator expected"), etext);
Jari Aalto7117c2d2002-07-17 14:10:11 +00006691 free (etext);
6692 }
6693 else
Jari Aaltob80f6442004-07-27 13:29:18 +00006694 parser_error (line_number, _("conditional binary operator expected"));
Jari Aaltocce855b1998-04-17 19:52:44 +00006695 dispose_cond_node (tleft);
6696 COND_RETURN_ERROR ();
6697 }
6698
6699 /* rhs */
Chet Ramey00018032011-11-21 20:51:19 -05006700 if (parser_state & PST_EXTPAT)
6701 extended_glob = 1;
Jari Aaltocce855b1998-04-17 19:52:44 +00006702 tok = read_token (READ);
Chet Ramey00018032011-11-21 20:51:19 -05006703 if (parser_state & PST_EXTPAT)
6704 extended_glob = global_extglob;
6705 parser_state &= ~(PST_REGEXP|PST_EXTPAT);
6706
Jari Aaltocce855b1998-04-17 19:52:44 +00006707 if (tok == WORD)
6708 {
6709 tright = make_cond_node (COND_TERM, yylval.word, (COND_COM *)NULL, (COND_COM *)NULL);
6710 term = make_cond_node (COND_BINARY, op, tleft, tright);
6711 }
6712 else
6713 {
Jari Aalto7117c2d2002-07-17 14:10:11 +00006714 if (etext = error_token_from_token (tok))
6715 {
Jari Aaltob80f6442004-07-27 13:29:18 +00006716 parser_error (line_number, _("unexpected argument `%s' to conditional binary operator"), etext);
Jari Aalto7117c2d2002-07-17 14:10:11 +00006717 free (etext);
6718 }
6719 else
Jari Aaltob80f6442004-07-27 13:29:18 +00006720 parser_error (line_number, _("unexpected argument to conditional binary operator"));
Jari Aaltocce855b1998-04-17 19:52:44 +00006721 dispose_cond_node (tleft);
6722 dispose_word (op);
6723 COND_RETURN_ERROR ();
6724 }
6725
6726 (void)cond_skip_newlines ();
6727 }
Jari Aaltobb706242000-03-17 21:46:59 +00006728 else
6729 {
6730 if (tok < 256)
Jari Aaltob80f6442004-07-27 13:29:18 +00006731 parser_error (line_number, _("unexpected token `%c' in conditional command"), tok);
Jari Aalto7117c2d2002-07-17 14:10:11 +00006732 else if (etext = error_token_from_token (tok))
6733 {
Jari Aaltob80f6442004-07-27 13:29:18 +00006734 parser_error (line_number, _("unexpected token `%s' in conditional command"), etext);
Jari Aalto7117c2d2002-07-17 14:10:11 +00006735 free (etext);
6736 }
Jari Aaltobb706242000-03-17 21:46:59 +00006737 else
Jari Aaltob80f6442004-07-27 13:29:18 +00006738 parser_error (line_number, _("unexpected token %d in conditional command"), tok);
Jari Aaltobb706242000-03-17 21:46:59 +00006739 COND_RETURN_ERROR ();
6740 }
Jari Aaltocce855b1998-04-17 19:52:44 +00006741 return (term);
6742}
6743
6744/* This is kind of bogus -- we slip a mini recursive-descent parser in
6745 here to handle the conditional statement syntax. */
6746static COMMAND *
6747parse_cond_command ()
6748{
6749 COND_COM *cexp;
6750
Chet Ramey00018032011-11-21 20:51:19 -05006751 global_extglob = extended_glob;
Jari Aaltocce855b1998-04-17 19:52:44 +00006752 cexp = cond_expr ();
6753 return (make_cond_command (cexp));
6754}
6755#endif
6756
Jari Aalto7117c2d2002-07-17 14:10:11 +00006757#if defined (ARRAY_VARS)
6758/* When this is called, it's guaranteed that we don't care about anything
6759 in t beyond i. We do save and restore the chars, though. */
6760static int
6761token_is_assignment (t, i)
6762 char *t;
6763 int i;
6764{
6765 unsigned char c, c1;
6766 int r;
6767
6768 c = t[i]; c1 = t[i+1];
6769 t[i] = '='; t[i+1] = '\0';
Jari Aaltob80f6442004-07-27 13:29:18 +00006770 r = assignment (t, (parser_state & PST_COMPASSIGN) != 0);
Jari Aalto7117c2d2002-07-17 14:10:11 +00006771 t[i] = c; t[i+1] = c1;
6772 return r;
6773}
6774
Jari Aalto95732b42005-12-07 14:08:12 +00006775/* XXX - possible changes here for `+=' */
Jari Aalto7117c2d2002-07-17 14:10:11 +00006776static int
6777token_is_ident (t, i)
6778 char *t;
6779 int i;
6780{
6781 unsigned char c;
6782 int r;
6783
6784 c = t[i];
6785 t[i] = '\0';
6786 r = legal_identifier (t);
6787 t[i] = c;
6788 return r;
6789}
6790#endif
6791
Jari Aaltoccc6cda1996-12-23 17:02:34 +00006792static int
6793read_token_word (character)
6794 int character;
6795{
6796 /* The value for YYLVAL when a WORD is read. */
6797 WORD_DESC *the_word;
Jari Aalto726f6381996-08-26 18:22:31 +00006798
Jari Aaltoccc6cda1996-12-23 17:02:34 +00006799 /* Index into the token that we are building. */
6800 int token_index;
Jari Aalto726f6381996-08-26 18:22:31 +00006801
Jari Aaltoccc6cda1996-12-23 17:02:34 +00006802 /* ALL_DIGITS becomes zero when we see a non-digit. */
Jari Aaltof73dda02001-11-13 17:56:06 +00006803 int all_digit_token;
Jari Aaltoccc6cda1996-12-23 17:02:34 +00006804
6805 /* DOLLAR_PRESENT becomes non-zero if we see a `$'. */
6806 int dollar_present;
6807
Jari Aalto95732b42005-12-07 14:08:12 +00006808 /* COMPOUND_ASSIGNMENT becomes non-zero if we are parsing a compound
6809 assignment. */
6810 int compound_assignment;
6811
Jari Aaltoccc6cda1996-12-23 17:02:34 +00006812 /* QUOTED becomes non-zero if we see one of ("), ('), (`), or (\). */
6813 int quoted;
6814
6815 /* Non-zero means to ignore the value of the next character, and just
6816 to add it no matter what. */
6817 int pass_next_character;
6818
6819 /* The current delimiting character. */
6820 int cd;
6821 int result, peek_char;
6822 char *ttok, *ttrans;
6823 int ttoklen, ttranslen;
Jari Aalto7117c2d2002-07-17 14:10:11 +00006824 intmax_t lvalue;
Jari Aaltoccc6cda1996-12-23 17:02:34 +00006825
Jari Aaltod166f041997-06-05 14:59:13 +00006826 if (token_buffer_size < TOKEN_DEFAULT_INITIAL_SIZE)
Jari Aaltof73dda02001-11-13 17:56:06 +00006827 token = (char *)xrealloc (token, token_buffer_size = TOKEN_DEFAULT_INITIAL_SIZE);
Jari Aaltoccc6cda1996-12-23 17:02:34 +00006828
6829 token_index = 0;
Jari Aaltof73dda02001-11-13 17:56:06 +00006830 all_digit_token = DIGIT (character);
Jari Aalto95732b42005-12-07 14:08:12 +00006831 dollar_present = quoted = pass_next_character = compound_assignment = 0;
Jari Aaltoccc6cda1996-12-23 17:02:34 +00006832
6833 for (;;)
6834 {
6835 if (character == EOF)
6836 goto got_token;
6837
6838 if (pass_next_character)
6839 {
6840 pass_next_character = 0;
Jari Aalto31859422009-01-12 13:36:28 +00006841 goto got_escaped_character;
Jari Aaltoccc6cda1996-12-23 17:02:34 +00006842 }
6843
6844 cd = current_delimiter (dstack);
6845
6846 /* Handle backslashes. Quote lots of things when not inside of
6847 double-quotes, quote some things inside of double-quotes. */
Jari Aalto7117c2d2002-07-17 14:10:11 +00006848 if MBTEST(character == '\\')
Jari Aaltoccc6cda1996-12-23 17:02:34 +00006849 {
6850 peek_char = shell_getc (0);
6851
6852 /* Backslash-newline is ignored in all cases except
6853 when quoted with single quotes. */
6854 if (peek_char == '\n')
6855 {
6856 character = '\n';
6857 goto next_character;
6858 }
6859 else
6860 {
Jari Aalto726f6381996-08-26 18:22:31 +00006861 shell_ungetc (peek_char);
Jari Aalto726f6381996-08-26 18:22:31 +00006862
Jari Aaltoccc6cda1996-12-23 17:02:34 +00006863 /* If the next character is to be quoted, note it now. */
6864 if (cd == 0 || cd == '`' ||
Jari Aaltof73dda02001-11-13 17:56:06 +00006865 (cd == '"' && peek_char >= 0 && (sh_syntaxtab[peek_char] & CBSDQUOTE)))
Jari Aaltoccc6cda1996-12-23 17:02:34 +00006866 pass_next_character++;
Jari Aalto726f6381996-08-26 18:22:31 +00006867
Jari Aaltoccc6cda1996-12-23 17:02:34 +00006868 quoted = 1;
6869 goto got_character;
6870 }
6871 }
Jari Aalto726f6381996-08-26 18:22:31 +00006872
Jari Aaltoccc6cda1996-12-23 17:02:34 +00006873 /* Parse a matched pair of quote characters. */
Jari Aalto7117c2d2002-07-17 14:10:11 +00006874 if MBTEST(shellquote (character))
Jari Aaltoccc6cda1996-12-23 17:02:34 +00006875 {
6876 push_delimiter (dstack, character);
Jari Aalto95732b42005-12-07 14:08:12 +00006877 ttok = parse_matched_pair (character, character, character, &ttoklen, (character == '`') ? P_COMMAND : 0);
Jari Aaltoccc6cda1996-12-23 17:02:34 +00006878 pop_delimiter (dstack);
6879 if (ttok == &matched_pair_error)
6880 return -1; /* Bail immediately. */
6881 RESIZE_MALLOCED_BUFFER (token, token_index, ttoklen + 2,
6882 token_buffer_size, TOKEN_DEFAULT_GROW_SIZE);
6883 token[token_index++] = character;
6884 strcpy (token + token_index, ttok);
6885 token_index += ttoklen;
Jari Aaltof73dda02001-11-13 17:56:06 +00006886 all_digit_token = 0;
Jari Aaltoccc6cda1996-12-23 17:02:34 +00006887 quoted = 1;
6888 dollar_present |= (character == '"' && strchr (ttok, '$') != 0);
6889 FREE (ttok);
6890 goto next_character;
6891 }
Jari Aalto726f6381996-08-26 18:22:31 +00006892
Jari Aalto31859422009-01-12 13:36:28 +00006893#ifdef COND_REGEXP
6894 /* When parsing a regexp as a single word inside a conditional command,
6895 we need to special-case characters special to both the shell and
6896 regular expressions. Right now, that is only '(' and '|'. */ /*)*/
6897 if MBTEST((parser_state & PST_REGEXP) && (character == '(' || character == '|')) /*)*/
6898 {
6899 if (character == '|')
6900 goto got_character;
6901
6902 push_delimiter (dstack, character);
6903 ttok = parse_matched_pair (cd, '(', ')', &ttoklen, 0);
6904 pop_delimiter (dstack);
6905 if (ttok == &matched_pair_error)
6906 return -1; /* Bail immediately. */
6907 RESIZE_MALLOCED_BUFFER (token, token_index, ttoklen + 2,
6908 token_buffer_size, TOKEN_DEFAULT_GROW_SIZE);
6909 token[token_index++] = character;
6910 strcpy (token + token_index, ttok);
6911 token_index += ttoklen;
6912 FREE (ttok);
6913 dollar_present = all_digit_token = 0;
6914 goto next_character;
6915 }
6916#endif /* COND_REGEXP */
6917
Jari Aaltocce855b1998-04-17 19:52:44 +00006918#ifdef EXTENDED_GLOB
6919 /* Parse a ksh-style extended pattern matching specification. */
Jari Aalto31859422009-01-12 13:36:28 +00006920 if MBTEST(extended_glob && PATTERN_CHAR (character))
Jari Aaltocce855b1998-04-17 19:52:44 +00006921 {
6922 peek_char = shell_getc (1);
Jari Aalto7117c2d2002-07-17 14:10:11 +00006923 if MBTEST(peek_char == '(') /* ) */
Jari Aaltocce855b1998-04-17 19:52:44 +00006924 {
6925 push_delimiter (dstack, peek_char);
6926 ttok = parse_matched_pair (cd, '(', ')', &ttoklen, 0);
6927 pop_delimiter (dstack);
6928 if (ttok == &matched_pair_error)
6929 return -1; /* Bail immediately. */
Chet Rameyac50fba2014-02-26 09:36:43 -05006930 RESIZE_MALLOCED_BUFFER (token, token_index, ttoklen + 3,
Jari Aaltocce855b1998-04-17 19:52:44 +00006931 token_buffer_size,
6932 TOKEN_DEFAULT_GROW_SIZE);
6933 token[token_index++] = character;
6934 token[token_index++] = peek_char;
6935 strcpy (token + token_index, ttok);
6936 token_index += ttoklen;
6937 FREE (ttok);
Jari Aaltof73dda02001-11-13 17:56:06 +00006938 dollar_present = all_digit_token = 0;
Jari Aaltocce855b1998-04-17 19:52:44 +00006939 goto next_character;
6940 }
6941 else
6942 shell_ungetc (peek_char);
6943 }
6944#endif /* EXTENDED_GLOB */
6945
Jari Aaltoccc6cda1996-12-23 17:02:34 +00006946 /* If the delimiter character is not single quote, parse some of
6947 the shell expansions that must be read as a single word. */
Jari Aalto28ef6c32001-04-06 19:14:31 +00006948 if (shellexp (character))
Jari Aaltoccc6cda1996-12-23 17:02:34 +00006949 {
6950 peek_char = shell_getc (1);
6951 /* $(...), <(...), >(...), $((...)), ${...}, and $[...] constructs */
Chet Rameyac50fba2014-02-26 09:36:43 -05006952 if MBTEST(peek_char == '(' ||
Jari Aaltoccc6cda1996-12-23 17:02:34 +00006953 ((peek_char == '{' || peek_char == '[') && character == '$')) /* ) ] } */
6954 {
6955 if (peek_char == '{') /* } */
Chet Ramey495aee42011-11-22 19:11:26 -05006956 ttok = parse_matched_pair (cd, '{', '}', &ttoklen, P_FIRSTCLOSE|P_DOLBRACE);
Jari Aaltoccc6cda1996-12-23 17:02:34 +00006957 else if (peek_char == '(') /* ) */
Jari Aaltod166f041997-06-05 14:59:13 +00006958 {
6959 /* XXX - push and pop the `(' as a delimiter for use by
6960 the command-oriented-history code. This way newlines
6961 appearing in the $(...) string get added to the
6962 history literally rather than causing a possibly-
Jari Aaltobb706242000-03-17 21:46:59 +00006963 incorrect `;' to be added. ) */
Jari Aaltod166f041997-06-05 14:59:13 +00006964 push_delimiter (dstack, peek_char);
Jari Aalto31859422009-01-12 13:36:28 +00006965 ttok = parse_comsub (cd, '(', ')', &ttoklen, P_COMMAND);
Jari Aaltod166f041997-06-05 14:59:13 +00006966 pop_delimiter (dstack);
6967 }
Jari Aaltoccc6cda1996-12-23 17:02:34 +00006968 else
6969 ttok = parse_matched_pair (cd, '[', ']', &ttoklen, 0);
6970 if (ttok == &matched_pair_error)
6971 return -1; /* Bail immediately. */
Chet Rameyac50fba2014-02-26 09:36:43 -05006972 RESIZE_MALLOCED_BUFFER (token, token_index, ttoklen + 3,
Jari Aaltoccc6cda1996-12-23 17:02:34 +00006973 token_buffer_size,
6974 TOKEN_DEFAULT_GROW_SIZE);
6975 token[token_index++] = character;
6976 token[token_index++] = peek_char;
6977 strcpy (token + token_index, ttok);
6978 token_index += ttoklen;
6979 FREE (ttok);
6980 dollar_present = 1;
Jari Aaltof73dda02001-11-13 17:56:06 +00006981 all_digit_token = 0;
Jari Aaltoccc6cda1996-12-23 17:02:34 +00006982 goto next_character;
6983 }
6984 /* This handles $'...' and $"..." new-style quoted strings. */
Jari Aalto7117c2d2002-07-17 14:10:11 +00006985 else if MBTEST(character == '$' && (peek_char == '\'' || peek_char == '"'))
Jari Aaltoccc6cda1996-12-23 17:02:34 +00006986 {
Jari Aaltocce855b1998-04-17 19:52:44 +00006987 int first_line;
6988
6989 first_line = line_number;
Jari Aaltobb706242000-03-17 21:46:59 +00006990 push_delimiter (dstack, peek_char);
6991 ttok = parse_matched_pair (peek_char, peek_char, peek_char,
6992 &ttoklen,
6993 (peek_char == '\'') ? P_ALLOWESC : 0);
6994 pop_delimiter (dstack);
Jari Aaltoccc6cda1996-12-23 17:02:34 +00006995 if (ttok == &matched_pair_error)
6996 return -1;
6997 if (peek_char == '\'')
Jari Aaltobb706242000-03-17 21:46:59 +00006998 {
6999 ttrans = ansiexpand (ttok, 0, ttoklen - 1, &ttranslen);
7000 free (ttok);
Jari Aalto95732b42005-12-07 14:08:12 +00007001
Jari Aaltobb706242000-03-17 21:46:59 +00007002 /* Insert the single quotes and correctly quote any
7003 embedded single quotes (allowed because P_ALLOWESC was
7004 passed to parse_matched_pair). */
Jari Aalto28ef6c32001-04-06 19:14:31 +00007005 ttok = sh_single_quote (ttrans);
Jari Aaltobb706242000-03-17 21:46:59 +00007006 free (ttrans);
Jari Aalto95732b42005-12-07 14:08:12 +00007007 ttranslen = strlen (ttok);
Jari Aaltobb706242000-03-17 21:46:59 +00007008 ttrans = ttok;
Jari Aaltobb706242000-03-17 21:46:59 +00007009 }
Jari Aaltoccc6cda1996-12-23 17:02:34 +00007010 else
Jari Aaltobb706242000-03-17 21:46:59 +00007011 {
Jari Aalto06285672006-10-10 14:15:34 +00007012 /* Try to locale-expand the converted string. */
Jari Aaltobb706242000-03-17 21:46:59 +00007013 ttrans = localeexpand (ttok, 0, ttoklen - 1, first_line, &ttranslen);
7014 free (ttok);
7015
7016 /* Add the double quotes back */
Jari Aalto95732b42005-12-07 14:08:12 +00007017 ttok = sh_mkdoublequoted (ttrans, ttranslen, 0);
Jari Aaltobb706242000-03-17 21:46:59 +00007018 free (ttrans);
Jari Aalto95732b42005-12-07 14:08:12 +00007019 ttranslen += 2;
Jari Aaltobb706242000-03-17 21:46:59 +00007020 ttrans = ttok;
7021 }
7022
Chet Rameyac50fba2014-02-26 09:36:43 -05007023 RESIZE_MALLOCED_BUFFER (token, token_index, ttranslen + 1,
Jari Aaltoccc6cda1996-12-23 17:02:34 +00007024 token_buffer_size,
7025 TOKEN_DEFAULT_GROW_SIZE);
Jari Aaltoccc6cda1996-12-23 17:02:34 +00007026 strcpy (token + token_index, ttrans);
7027 token_index += ttranslen;
Jari Aaltoccc6cda1996-12-23 17:02:34 +00007028 FREE (ttrans);
7029 quoted = 1;
Jari Aaltof73dda02001-11-13 17:56:06 +00007030 all_digit_token = 0;
Jari Aaltoccc6cda1996-12-23 17:02:34 +00007031 goto next_character;
7032 }
Jari Aaltob72432f1999-02-19 17:11:39 +00007033 /* This could eventually be extended to recognize all of the
7034 shell's single-character parameter expansions, and set flags.*/
Jari Aalto7117c2d2002-07-17 14:10:11 +00007035 else if MBTEST(character == '$' && peek_char == '$')
Jari Aaltob72432f1999-02-19 17:11:39 +00007036 {
Jari Aaltob72432f1999-02-19 17:11:39 +00007037 RESIZE_MALLOCED_BUFFER (token, token_index, 3,
7038 token_buffer_size,
7039 TOKEN_DEFAULT_GROW_SIZE);
Chet Rameyac50fba2014-02-26 09:36:43 -05007040 token[token_index++] = '$';
7041 token[token_index++] = peek_char;
Jari Aaltob72432f1999-02-19 17:11:39 +00007042 dollar_present = 1;
Jari Aaltof73dda02001-11-13 17:56:06 +00007043 all_digit_token = 0;
Jari Aaltob72432f1999-02-19 17:11:39 +00007044 goto next_character;
7045 }
Jari Aaltoccc6cda1996-12-23 17:02:34 +00007046 else
7047 shell_ungetc (peek_char);
7048 }
7049
7050#if defined (ARRAY_VARS)
Jari Aalto31859422009-01-12 13:36:28 +00007051 /* Identify possible array subscript assignment; match [...]. If
7052 parser_state&PST_COMPASSIGN, we need to parse [sub]=words treating
7053 `sub' as if it were enclosed in double quotes. */
7054 else if MBTEST(character == '[' && /* ] */
7055 ((token_index > 0 && assignment_acceptable (last_read_token) && token_is_ident (token, token_index)) ||
7056 (token_index == 0 && (parser_state&PST_COMPASSIGN))))
Jari Aalto7117c2d2002-07-17 14:10:11 +00007057 {
Chet Ramey00018032011-11-21 20:51:19 -05007058 ttok = parse_matched_pair (cd, '[', ']', &ttoklen, P_ARRAYSUB);
Jari Aalto7117c2d2002-07-17 14:10:11 +00007059 if (ttok == &matched_pair_error)
7060 return -1; /* Bail immediately. */
7061 RESIZE_MALLOCED_BUFFER (token, token_index, ttoklen + 2,
7062 token_buffer_size,
7063 TOKEN_DEFAULT_GROW_SIZE);
7064 token[token_index++] = character;
7065 strcpy (token + token_index, ttok);
7066 token_index += ttoklen;
7067 FREE (ttok);
7068 all_digit_token = 0;
7069 goto next_character;
7070 }
Jari Aaltoccc6cda1996-12-23 17:02:34 +00007071 /* Identify possible compound array variable assignment. */
Jari Aalto95732b42005-12-07 14:08:12 +00007072 else if MBTEST(character == '=' && token_index > 0 && (assignment_acceptable (last_read_token) || (parser_state & PST_ASSIGNOK)) && token_is_assignment (token, token_index))
Jari Aaltoccc6cda1996-12-23 17:02:34 +00007073 {
7074 peek_char = shell_getc (1);
Jari Aalto7117c2d2002-07-17 14:10:11 +00007075 if MBTEST(peek_char == '(') /* ) */
Jari Aaltoccc6cda1996-12-23 17:02:34 +00007076 {
Jari Aalto7117c2d2002-07-17 14:10:11 +00007077 ttok = parse_compound_assignment (&ttoklen);
7078
7079 RESIZE_MALLOCED_BUFFER (token, token_index, ttoklen + 4,
Jari Aaltoccc6cda1996-12-23 17:02:34 +00007080 token_buffer_size,
7081 TOKEN_DEFAULT_GROW_SIZE);
Jari Aalto7117c2d2002-07-17 14:10:11 +00007082
7083 token[token_index++] = '=';
7084 token[token_index++] = '(';
7085 if (ttok)
7086 {
7087 strcpy (token + token_index, ttok);
7088 token_index += ttoklen;
7089 }
7090 token[token_index++] = ')';
Jari Aaltoccc6cda1996-12-23 17:02:34 +00007091 FREE (ttok);
Jari Aaltof73dda02001-11-13 17:56:06 +00007092 all_digit_token = 0;
Jari Aalto95732b42005-12-07 14:08:12 +00007093 compound_assignment = 1;
Jari Aalto06285672006-10-10 14:15:34 +00007094#if 1
Jari Aaltoccc6cda1996-12-23 17:02:34 +00007095 goto next_character;
Jari Aalto95732b42005-12-07 14:08:12 +00007096#else
7097 goto got_token; /* ksh93 seems to do this */
7098#endif
Jari Aaltoccc6cda1996-12-23 17:02:34 +00007099 }
7100 else
7101 shell_ungetc (peek_char);
7102 }
Jari Aalto726f6381996-08-26 18:22:31 +00007103#endif
Jari Aaltoccc6cda1996-12-23 17:02:34 +00007104
7105 /* When not parsing a multi-character word construct, shell meta-
7106 characters break words. */
Jari Aalto7117c2d2002-07-17 14:10:11 +00007107 if MBTEST(shellbreak (character))
Jari Aaltoccc6cda1996-12-23 17:02:34 +00007108 {
7109 shell_ungetc (character);
7110 goto got_token;
7111 }
7112
Chet Rameyac50fba2014-02-26 09:36:43 -05007113got_character:
Jari Aaltoccc6cda1996-12-23 17:02:34 +00007114
Jari Aaltoccc6cda1996-12-23 17:02:34 +00007115 if (character == CTLESC || character == CTLNUL)
Chet Rameyac50fba2014-02-26 09:36:43 -05007116 {
7117 RESIZE_MALLOCED_BUFFER (token, token_index, 2, token_buffer_size,
7118 TOKEN_DEFAULT_GROW_SIZE);
7119 token[token_index++] = CTLESC;
7120 }
7121 else
7122got_escaped_character:
7123 RESIZE_MALLOCED_BUFFER (token, token_index, 1, token_buffer_size,
7124 TOKEN_DEFAULT_GROW_SIZE);
Jari Aalto31859422009-01-12 13:36:28 +00007125
Jari Aaltoccc6cda1996-12-23 17:02:34 +00007126 token[token_index++] = character;
7127
Chet Rameyac50fba2014-02-26 09:36:43 -05007128 all_digit_token &= DIGIT (character);
7129 dollar_present |= character == '$';
Jari Aaltoccc6cda1996-12-23 17:02:34 +00007130
7131 next_character:
Jari Aaltob80f6442004-07-27 13:29:18 +00007132 if (character == '\n' && SHOULD_PROMPT ())
Jari Aaltoccc6cda1996-12-23 17:02:34 +00007133 prompt_again ();
7134
7135 /* We want to remove quoted newlines (that is, a \<newline> pair)
7136 unless we are within single quotes or pass_next_character is
7137 set (the shell equivalent of literal-next). */
7138 cd = current_delimiter (dstack);
7139 character = shell_getc (cd != '\'' && pass_next_character == 0);
7140 } /* end for (;;) */
7141
7142got_token:
7143
Chet Rameyac50fba2014-02-26 09:36:43 -05007144 /* Calls to RESIZE_MALLOCED_BUFFER ensure there is sufficient room. */
Jari Aaltoccc6cda1996-12-23 17:02:34 +00007145 token[token_index] = '\0';
7146
7147 /* Check to see what thing we should return. If the last_read_token
7148 is a `<', or a `&', or the character which ended this token is
7149 a '>' or '<', then, and ONLY then, is this input token a NUMBER.
7150 Otherwise, it is just a word, and should be returned as such. */
Chet Rameyac50fba2014-02-26 09:36:43 -05007151 if MBTEST(all_digit_token && (character == '<' || character == '>' ||
7152 last_read_token == LESS_AND ||
Jari Aaltoccc6cda1996-12-23 17:02:34 +00007153 last_read_token == GREATER_AND))
Jari Aalto726f6381996-08-26 18:22:31 +00007154 {
Jari Aaltof73dda02001-11-13 17:56:06 +00007155 if (legal_number (token, &lvalue) && (int)lvalue == lvalue)
Chet Rameyac50fba2014-02-26 09:36:43 -05007156 {
7157 yylval.number = lvalue;
7158 return (NUMBER);
7159 }
Jari Aalto726f6381996-08-26 18:22:31 +00007160 }
7161
Jari Aaltoccc6cda1996-12-23 17:02:34 +00007162 /* Check for special case tokens. */
Jari Aalto7117c2d2002-07-17 14:10:11 +00007163 result = (last_shell_getc_is_singlebyte) ? special_case_tokens (token) : -1;
Jari Aaltoccc6cda1996-12-23 17:02:34 +00007164 if (result >= 0)
7165 return result;
Jari Aalto726f6381996-08-26 18:22:31 +00007166
7167#if defined (ALIAS)
Jari Aaltoccc6cda1996-12-23 17:02:34 +00007168 /* Posix.2 does not allow reserved words to be aliased, so check for all
7169 of them, including special cases, before expanding the current token
7170 as an alias. */
Jari Aalto7117c2d2002-07-17 14:10:11 +00007171 if MBTEST(posixly_correct)
Jari Aaltoccc6cda1996-12-23 17:02:34 +00007172 CHECK_FOR_RESERVED_WORD (token);
Jari Aalto726f6381996-08-26 18:22:31 +00007173
Jari Aaltoccc6cda1996-12-23 17:02:34 +00007174 /* Aliases are expanded iff EXPAND_ALIASES is non-zero, and quoting
7175 inhibits alias expansion. */
7176 if (expand_aliases && quoted == 0)
7177 {
7178 result = alias_expand_token (token);
7179 if (result == RE_READ_TOKEN)
7180 return (RE_READ_TOKEN);
7181 else if (result == NO_EXPANSION)
7182 parser_state &= ~PST_ALEXPNEXT;
7183 }
Jari Aalto726f6381996-08-26 18:22:31 +00007184
Jari Aaltoccc6cda1996-12-23 17:02:34 +00007185 /* If not in Posix.2 mode, check for reserved words after alias
7186 expansion. */
Jari Aalto7117c2d2002-07-17 14:10:11 +00007187 if MBTEST(posixly_correct == 0)
Jari Aaltoccc6cda1996-12-23 17:02:34 +00007188#endif
7189 CHECK_FOR_RESERVED_WORD (token);
Jari Aalto726f6381996-08-26 18:22:31 +00007190
Jari Aaltoccc6cda1996-12-23 17:02:34 +00007191 the_word = (WORD_DESC *)xmalloc (sizeof (WORD_DESC));
Jari Aaltof73dda02001-11-13 17:56:06 +00007192 the_word->word = (char *)xmalloc (1 + token_index);
Jari Aaltoccc6cda1996-12-23 17:02:34 +00007193 the_word->flags = 0;
7194 strcpy (the_word->word, token);
7195 if (dollar_present)
7196 the_word->flags |= W_HASDOLLAR;
7197 if (quoted)
Jari Aalto06285672006-10-10 14:15:34 +00007198 the_word->flags |= W_QUOTED; /*(*/
7199 if (compound_assignment && token[token_index-1] == ')')
Jari Aalto95732b42005-12-07 14:08:12 +00007200 the_word->flags |= W_COMPASSIGN;
Jari Aaltoccc6cda1996-12-23 17:02:34 +00007201 /* A word is an assignment if it appears at the beginning of a
7202 simple command, or after another assignment word. This is
7203 context-dependent, so it cannot be handled in the grammar. */
Jari Aaltob80f6442004-07-27 13:29:18 +00007204 if (assignment (token, (parser_state & PST_COMPASSIGN) != 0))
Jari Aaltoccc6cda1996-12-23 17:02:34 +00007205 {
7206 the_word->flags |= W_ASSIGNMENT;
7207 /* Don't perform word splitting on assignment statements. */
Jari Aaltob80f6442004-07-27 13:29:18 +00007208 if (assignment_acceptable (last_read_token) || (parser_state & PST_COMPASSIGN) != 0)
Chet Rameyac50fba2014-02-26 09:36:43 -05007209 {
7210 the_word->flags |= W_NOSPLIT;
7211 if (parser_state & PST_COMPASSIGN)
7212 the_word->flags |= W_NOGLOB; /* XXX - W_NOBRACE? */
7213 }
Jari Aaltoccc6cda1996-12-23 17:02:34 +00007214 }
Jari Aalto726f6381996-08-26 18:22:31 +00007215
Jari Aalto95732b42005-12-07 14:08:12 +00007216 if (command_token_position (last_read_token))
7217 {
7218 struct builtin *b;
7219 b = builtin_address_internal (token, 0);
7220 if (b && (b->flags & ASSIGNMENT_BUILTIN))
Jari Aalto06285672006-10-10 14:15:34 +00007221 parser_state |= PST_ASSIGNOK;
7222 else if (STREQ (token, "eval") || STREQ (token, "let"))
7223 parser_state |= PST_ASSIGNOK;
Jari Aalto95732b42005-12-07 14:08:12 +00007224 }
7225
Jari Aaltoccc6cda1996-12-23 17:02:34 +00007226 yylval.word = the_word;
Jari Aalto726f6381996-08-26 18:22:31 +00007227
Chet Ramey00018032011-11-21 20:51:19 -05007228 if (token[0] == '{' && token[token_index-1] == '}' &&
7229 (character == '<' || character == '>'))
7230 {
7231 /* can use token; already copied to the_word */
7232 token[token_index-1] = '\0';
Chet Rameyac50fba2014-02-26 09:36:43 -05007233#if defined (ARRAY_VARS)
7234 if (legal_identifier (token+1) || valid_array_reference (token+1))
7235#else
Chet Ramey00018032011-11-21 20:51:19 -05007236 if (legal_identifier (token+1))
Chet Rameyac50fba2014-02-26 09:36:43 -05007237#endif
Chet Ramey00018032011-11-21 20:51:19 -05007238 {
7239 strcpy (the_word->word, token+1);
7240/*itrace("read_token_word: returning REDIR_WORD for %s", the_word->word);*/
7241 return (REDIR_WORD);
7242 }
7243 }
7244
Jari Aaltoccc6cda1996-12-23 17:02:34 +00007245 result = ((the_word->flags & (W_ASSIGNMENT|W_NOSPLIT)) == (W_ASSIGNMENT|W_NOSPLIT))
7246 ? ASSIGNMENT_WORD : WORD;
Jari Aalto726f6381996-08-26 18:22:31 +00007247
Jari Aaltob80f6442004-07-27 13:29:18 +00007248 switch (last_read_token)
Jari Aaltoccc6cda1996-12-23 17:02:34 +00007249 {
Jari Aaltob80f6442004-07-27 13:29:18 +00007250 case FUNCTION:
Jari Aaltoccc6cda1996-12-23 17:02:34 +00007251 parser_state |= PST_ALLOWOPNBRC;
7252 function_dstart = line_number;
Jari Aaltob80f6442004-07-27 13:29:18 +00007253 break;
7254 case CASE:
7255 case SELECT:
7256 case FOR:
7257 if (word_top < MAX_CASE_NEST)
7258 word_top++;
7259 word_lineno[word_top] = line_number;
7260 break;
Jari Aaltoccc6cda1996-12-23 17:02:34 +00007261 }
Jari Aalto726f6381996-08-26 18:22:31 +00007262
Jari Aalto726f6381996-08-26 18:22:31 +00007263 return (result);
7264}
7265
Jari Aaltof73dda02001-11-13 17:56:06 +00007266/* Return 1 if TOKSYM is a token that after being read would allow
Jari Aalto726f6381996-08-26 18:22:31 +00007267 a reserved word to be seen, else 0. */
7268static int
Jari Aaltof73dda02001-11-13 17:56:06 +00007269reserved_word_acceptable (toksym)
7270 int toksym;
Jari Aalto726f6381996-08-26 18:22:31 +00007271{
Jari Aalto7117c2d2002-07-17 14:10:11 +00007272 switch (toksym)
7273 {
7274 case '\n':
7275 case ';':
7276 case '(':
7277 case ')':
7278 case '|':
7279 case '&':
7280 case '{':
7281 case '}': /* XXX */
7282 case AND_AND:
7283 case BANG:
Chet Ramey00018032011-11-21 20:51:19 -05007284 case BAR_AND:
Jari Aalto7117c2d2002-07-17 14:10:11 +00007285 case DO:
7286 case DONE:
7287 case ELIF:
7288 case ELSE:
7289 case ESAC:
7290 case FI:
7291 case IF:
7292 case OR_OR:
7293 case SEMI_SEMI:
Jari Aalto31859422009-01-12 13:36:28 +00007294 case SEMI_AND:
7295 case SEMI_SEMI_AND:
Jari Aalto7117c2d2002-07-17 14:10:11 +00007296 case THEN:
7297 case TIME:
7298 case TIMEOPT:
Chet Ramey495aee42011-11-22 19:11:26 -05007299 case TIMEIGN:
Jari Aalto31859422009-01-12 13:36:28 +00007300 case COPROC:
Jari Aalto7117c2d2002-07-17 14:10:11 +00007301 case UNTIL:
7302 case WHILE:
7303 case 0:
7304 return 1;
7305 default:
Jari Aalto31859422009-01-12 13:36:28 +00007306#if defined (COPROCESS_SUPPORT)
7307 if (last_read_token == WORD && token_before_that == COPROC)
7308 return 1;
7309#endif
Chet Ramey495aee42011-11-22 19:11:26 -05007310 if (last_read_token == WORD && token_before_that == FUNCTION)
7311 return 1;
Jari Aalto7117c2d2002-07-17 14:10:11 +00007312 return 0;
7313 }
Jari Aalto726f6381996-08-26 18:22:31 +00007314}
Jari Aalto7117c2d2002-07-17 14:10:11 +00007315
Jari Aalto726f6381996-08-26 18:22:31 +00007316/* Return the index of TOKEN in the alist of reserved words, or -1 if
7317 TOKEN is not a shell reserved word. */
7318int
Jari Aaltof73dda02001-11-13 17:56:06 +00007319find_reserved_word (tokstr)
7320 char *tokstr;
Jari Aalto726f6381996-08-26 18:22:31 +00007321{
7322 int i;
Jari Aaltoccc6cda1996-12-23 17:02:34 +00007323 for (i = 0; word_token_alist[i].word; i++)
Jari Aaltof73dda02001-11-13 17:56:06 +00007324 if (STREQ (tokstr, word_token_alist[i].word))
Jari Aalto726f6381996-08-26 18:22:31 +00007325 return i;
7326 return -1;
7327}
7328
Chet Rameyac50fba2014-02-26 09:36:43 -05007329/* An interface to let the rest of the shell (primarily the completion
7330 system) know what the parser is expecting. */
7331int
7332parser_in_command_position ()
7333{
7334 return (command_token_position (last_read_token));
7335}
7336
Jari Aaltoccc6cda1996-12-23 17:02:34 +00007337#if 0
Jari Aalto726f6381996-08-26 18:22:31 +00007338#if defined (READLINE)
7339/* Called after each time readline is called. This insures that whatever
7340 the new prompt string is gets propagated to readline's local prompt
7341 variable. */
7342static void
7343reset_readline_prompt ()
7344{
Jari Aaltoccc6cda1996-12-23 17:02:34 +00007345 char *temp_prompt;
7346
Jari Aalto726f6381996-08-26 18:22:31 +00007347 if (prompt_string_pointer)
7348 {
Jari Aaltoccc6cda1996-12-23 17:02:34 +00007349 temp_prompt = (*prompt_string_pointer)
Jari Aalto726f6381996-08-26 18:22:31 +00007350 ? decode_prompt_string (*prompt_string_pointer)
7351 : (char *)NULL;
7352
7353 if (temp_prompt == 0)
7354 {
Jari Aaltof73dda02001-11-13 17:56:06 +00007355 temp_prompt = (char *)xmalloc (1);
Jari Aalto726f6381996-08-26 18:22:31 +00007356 temp_prompt[0] = '\0';
7357 }
7358
7359 FREE (current_readline_prompt);
Jari Aalto726f6381996-08-26 18:22:31 +00007360 current_readline_prompt = temp_prompt;
7361 }
7362}
7363#endif /* READLINE */
Jari Aaltoccc6cda1996-12-23 17:02:34 +00007364#endif /* 0 */
Jari Aalto726f6381996-08-26 18:22:31 +00007365
7366#if defined (HISTORY)
7367/* A list of tokens which can be followed by newlines, but not by
7368 semi-colons. When concatenating multiple lines of history, the
7369 newline separator for such tokens is replaced with a space. */
Jari Aalto31859422009-01-12 13:36:28 +00007370static const int no_semi_successors[] = {
Jari Aalto726f6381996-08-26 18:22:31 +00007371 '\n', '{', '(', ')', ';', '&', '|',
Jari Aalto31859422009-01-12 13:36:28 +00007372 CASE, DO, ELSE, IF, SEMI_SEMI, SEMI_AND, SEMI_SEMI_AND, THEN, UNTIL,
7373 WHILE, AND_AND, OR_OR, IN,
Jari Aalto726f6381996-08-26 18:22:31 +00007374 0
7375};
7376
7377/* If we are not within a delimited expression, try to be smart
7378 about which separators can be semi-colons and which must be
Jari Aaltoccc6cda1996-12-23 17:02:34 +00007379 newlines. Returns the string that should be added into the
Chet Ramey495aee42011-11-22 19:11:26 -05007380 history entry. LINE is the line we're about to add; it helps
7381 make some more intelligent decisions in certain cases. */
Jari Aalto726f6381996-08-26 18:22:31 +00007382char *
Chet Ramey495aee42011-11-22 19:11:26 -05007383history_delimiting_chars (line)
7384 const char *line;
Jari Aalto726f6381996-08-26 18:22:31 +00007385{
Chet Ramey495aee42011-11-22 19:11:26 -05007386 static int last_was_heredoc = 0; /* was the last entry the start of a here document? */
Jari Aaltoccc6cda1996-12-23 17:02:34 +00007387 register int i;
Jari Aalto726f6381996-08-26 18:22:31 +00007388
Chet Ramey495aee42011-11-22 19:11:26 -05007389 if ((parser_state & PST_HEREDOC) == 0)
7390 last_was_heredoc = 0;
7391
Jari Aaltoccc6cda1996-12-23 17:02:34 +00007392 if (dstack.delimiter_depth != 0)
Jari Aalto726f6381996-08-26 18:22:31 +00007393 return ("\n");
Jari Aalto31859422009-01-12 13:36:28 +00007394
7395 /* We look for current_command_line_count == 2 because we are looking to
7396 add the first line of the body of the here document (the second line
Chet Ramey495aee42011-11-22 19:11:26 -05007397 of the command). We also keep LAST_WAS_HEREDOC as a private sentinel
7398 variable to note when we think we added the first line of a here doc
7399 (the one with a "<<" somewhere in it) */
Jari Aalto31859422009-01-12 13:36:28 +00007400 if (parser_state & PST_HEREDOC)
Chet Ramey495aee42011-11-22 19:11:26 -05007401 {
7402 if (last_was_heredoc)
7403 {
7404 last_was_heredoc = 0;
7405 return "\n";
7406 }
7407 return (current_command_line_count == 2 ? "\n" : "");
7408 }
Jari Aalto31859422009-01-12 13:36:28 +00007409
Chet Ramey509a4432013-01-10 19:53:16 -05007410 if (parser_state & PST_COMPASSIGN)
7411 return (" ");
7412
Jari Aaltoccc6cda1996-12-23 17:02:34 +00007413 /* First, handle some special cases. */
7414 /*(*/
7415 /* If we just read `()', assume it's a function definition, and don't
7416 add a semicolon. If the token before the `)' was not `(', and we're
7417 not in the midst of parsing a case statement, assume it's a
7418 parenthesized command and add the semicolon. */
7419 /*)(*/
7420 if (token_before_that == ')')
7421 {
7422 if (two_tokens_ago == '(') /*)*/ /* function def */
7423 return " ";
7424 /* This does not work for subshells inside case statement
7425 command lists. It's a suboptimal solution. */
7426 else if (parser_state & PST_CASESTMT) /* case statement pattern */
Jari Aalto28ef6c32001-04-06 19:14:31 +00007427 return " ";
Jari Aaltoccc6cda1996-12-23 17:02:34 +00007428 else
Jari Aalto28ef6c32001-04-06 19:14:31 +00007429 return "; "; /* (...) subshell */
Jari Aaltoccc6cda1996-12-23 17:02:34 +00007430 }
Jari Aaltocce855b1998-04-17 19:52:44 +00007431 else if (token_before_that == WORD && two_tokens_ago == FUNCTION)
7432 return " "; /* function def using `function name' without `()' */
Jari Aaltoccc6cda1996-12-23 17:02:34 +00007433
Chet Ramey495aee42011-11-22 19:11:26 -05007434 /* If we're not in a here document, but we think we're about to parse one,
7435 and we would otherwise return a `;', return a newline to delimit the
7436 line with the here-doc delimiter */
7437 else if ((parser_state & PST_HEREDOC) == 0 && current_command_line_count > 1 && last_read_token == '\n' && strstr (line, "<<"))
7438 {
7439 last_was_heredoc = 1;
7440 return "\n";
7441 }
7442
Jari Aaltobb706242000-03-17 21:46:59 +00007443 else if (token_before_that == WORD && two_tokens_ago == FOR)
7444 {
7445 /* Tricky. `for i\nin ...' should not have a semicolon, but
7446 `for i\ndo ...' should. We do what we can. */
Jari Aalto31859422009-01-12 13:36:28 +00007447 for (i = shell_input_line_index; whitespace (shell_input_line[i]); i++)
Jari Aalto28ef6c32001-04-06 19:14:31 +00007448 ;
Jari Aaltobb706242000-03-17 21:46:59 +00007449 if (shell_input_line[i] && shell_input_line[i] == 'i' && shell_input_line[i+1] == 'n')
7450 return " ";
7451 return ";";
7452 }
Jari Aalto95732b42005-12-07 14:08:12 +00007453 else if (two_tokens_ago == CASE && token_before_that == WORD && (parser_state & PST_CASESTMT))
7454 return " ";
Jari Aaltobb706242000-03-17 21:46:59 +00007455
Jari Aaltoccc6cda1996-12-23 17:02:34 +00007456 for (i = 0; no_semi_successors[i]; i++)
7457 {
7458 if (token_before_that == no_semi_successors[i])
7459 return (" ");
7460 }
7461
7462 return ("; ");
Jari Aalto726f6381996-08-26 18:22:31 +00007463}
7464#endif /* HISTORY */
7465
7466/* Issue a prompt, or prepare to issue a prompt when the next character
7467 is read. */
7468static void
7469prompt_again ()
7470{
7471 char *temp_prompt;
7472
Chet Ramey00018032011-11-21 20:51:19 -05007473 if (interactive == 0 || expanding_alias ()) /* XXX */
Jari Aalto726f6381996-08-26 18:22:31 +00007474 return;
7475
7476 ps1_prompt = get_string_value ("PS1");
7477 ps2_prompt = get_string_value ("PS2");
7478
7479 if (!prompt_string_pointer)
7480 prompt_string_pointer = &ps1_prompt;
7481
Jari Aaltoccc6cda1996-12-23 17:02:34 +00007482 temp_prompt = *prompt_string_pointer
Jari Aalto726f6381996-08-26 18:22:31 +00007483 ? decode_prompt_string (*prompt_string_pointer)
7484 : (char *)NULL;
7485
7486 if (temp_prompt == 0)
7487 {
Jari Aaltof73dda02001-11-13 17:56:06 +00007488 temp_prompt = (char *)xmalloc (1);
Jari Aalto726f6381996-08-26 18:22:31 +00007489 temp_prompt[0] = '\0';
7490 }
7491
7492 current_prompt_string = *prompt_string_pointer;
7493 prompt_string_pointer = &ps2_prompt;
7494
7495#if defined (READLINE)
7496 if (!no_line_editing)
7497 {
7498 FREE (current_readline_prompt);
7499 current_readline_prompt = temp_prompt;
7500 }
7501 else
7502#endif /* READLINE */
7503 {
7504 FREE (current_decoded_prompt);
7505 current_decoded_prompt = temp_prompt;
7506 }
7507}
7508
Jari Aaltobb706242000-03-17 21:46:59 +00007509int
7510get_current_prompt_level ()
7511{
7512 return ((current_prompt_string && current_prompt_string == ps2_prompt) ? 2 : 1);
7513}
7514
7515void
7516set_current_prompt_level (x)
7517 int x;
7518{
7519 prompt_string_pointer = (x == 2) ? &ps2_prompt : &ps1_prompt;
7520 current_prompt_string = *prompt_string_pointer;
7521}
7522
Jari Aalto726f6381996-08-26 18:22:31 +00007523static void
7524print_prompt ()
7525{
7526 fprintf (stderr, "%s", current_decoded_prompt);
7527 fflush (stderr);
7528}
7529
7530/* Return a string which will be printed as a prompt. The string
7531 may contain special characters which are decoded as follows:
Jari Aaltoccc6cda1996-12-23 17:02:34 +00007532
7533 \a bell (ascii 07)
Jari Aaltoccc6cda1996-12-23 17:02:34 +00007534 \d the date in Day Mon Date format
Jari Aalto7117c2d2002-07-17 14:10:11 +00007535 \e escape (ascii 033)
Jari Aaltoccc6cda1996-12-23 17:02:34 +00007536 \h the hostname up to the first `.'
7537 \H the hostname
Jari Aaltobb706242000-03-17 21:46:59 +00007538 \j the number of active jobs
7539 \l the basename of the shell's tty device name
Jari Aalto726f6381996-08-26 18:22:31 +00007540 \n CRLF
Jari Aalto7117c2d2002-07-17 14:10:11 +00007541 \r CR
Jari Aalto726f6381996-08-26 18:22:31 +00007542 \s the name of the shell
Jari Aaltoccc6cda1996-12-23 17:02:34 +00007543 \t the time in 24-hour hh:mm:ss format
7544 \T the time in 12-hour hh:mm:ss format
Jari Aalto7117c2d2002-07-17 14:10:11 +00007545 \@ the time in 12-hour hh:mm am/pm format
7546 \A the time in 24-hour hh:mm format
7547 \D{fmt} the result of passing FMT to strftime(3)
7548 \u your username
Jari Aaltoccc6cda1996-12-23 17:02:34 +00007549 \v the version of bash (e.g., 2.00)
7550 \V the release of bash, version + patchlevel (e.g., 2.00.0)
Jari Aalto726f6381996-08-26 18:22:31 +00007551 \w the current working directory
Jari Aaltoccc6cda1996-12-23 17:02:34 +00007552 \W the last element of $PWD
Jari Aalto726f6381996-08-26 18:22:31 +00007553 \! the history number of this command
Jari Aalto7117c2d2002-07-17 14:10:11 +00007554 \# the command number of this command
Jari Aalto726f6381996-08-26 18:22:31 +00007555 \$ a $ or a # if you are root
Jari Aaltoccc6cda1996-12-23 17:02:34 +00007556 \nnn character code nnn in octal
Jari Aalto726f6381996-08-26 18:22:31 +00007557 \\ a backslash
Jari Aaltoccc6cda1996-12-23 17:02:34 +00007558 \[ begin a sequence of non-printing chars
7559 \] end a sequence of non-printing chars
Jari Aalto726f6381996-08-26 18:22:31 +00007560*/
Jari Aaltod166f041997-06-05 14:59:13 +00007561#define PROMPT_GROWTH 48
Jari Aalto726f6381996-08-26 18:22:31 +00007562char *
7563decode_prompt_string (string)
7564 char *string;
7565{
Jari Aalto726f6381996-08-26 18:22:31 +00007566 WORD_LIST *list;
Jari Aaltoccc6cda1996-12-23 17:02:34 +00007567 char *result, *t;
7568 struct dstack save_dstack;
Chet Ramey00018032011-11-21 20:51:19 -05007569 int last_exit_value, last_comsub_pid;
Jari Aalto726f6381996-08-26 18:22:31 +00007570#if defined (PROMPT_STRING_DECODE)
Jari Aaltoccc6cda1996-12-23 17:02:34 +00007571 int result_size, result_index;
Jari Aalto06285672006-10-10 14:15:34 +00007572 int c, n, i;
Jari Aaltoccc6cda1996-12-23 17:02:34 +00007573 char *temp, octal_string[4];
Jari Aalto7117c2d2002-07-17 14:10:11 +00007574 struct tm *tm;
Jari Aaltoccc6cda1996-12-23 17:02:34 +00007575 time_t the_time;
Jari Aalto7117c2d2002-07-17 14:10:11 +00007576 char timebuf[128];
7577 char *timefmt;
Jari Aalto726f6381996-08-26 18:22:31 +00007578
Jari Aaltof73dda02001-11-13 17:56:06 +00007579 result = (char *)xmalloc (result_size = PROMPT_GROWTH);
Jari Aaltoccc6cda1996-12-23 17:02:34 +00007580 result[result_index = 0] = 0;
7581 temp = (char *)NULL;
Jari Aalto726f6381996-08-26 18:22:31 +00007582
7583 while (c = *string++)
7584 {
7585 if (posixly_correct && c == '!')
7586 {
7587 if (*string == '!')
7588 {
7589 temp = savestring ("!");
7590 goto add_string;
7591 }
7592 else
7593 {
7594#if !defined (HISTORY)
7595 temp = savestring ("1");
7596#else /* HISTORY */
7597 temp = itos (history_number ());
7598#endif /* HISTORY */
7599 string--; /* add_string increments string again. */
7600 goto add_string;
7601 }
Jari Aaltoccc6cda1996-12-23 17:02:34 +00007602 }
Jari Aalto726f6381996-08-26 18:22:31 +00007603 if (c == '\\')
7604 {
7605 c = *string;
7606
7607 switch (c)
7608 {
7609 case '0':
7610 case '1':
7611 case '2':
7612 case '3':
7613 case '4':
7614 case '5':
7615 case '6':
7616 case '7':
Jari Aaltoccc6cda1996-12-23 17:02:34 +00007617 strncpy (octal_string, string, 3);
7618 octal_string[3] = '\0';
Jari Aalto726f6381996-08-26 18:22:31 +00007619
Jari Aaltoccc6cda1996-12-23 17:02:34 +00007620 n = read_octal (octal_string);
Jari Aaltof73dda02001-11-13 17:56:06 +00007621 temp = (char *)xmalloc (3);
Jari Aalto726f6381996-08-26 18:22:31 +00007622
Jari Aaltoccc6cda1996-12-23 17:02:34 +00007623 if (n == CTLESC || n == CTLNUL)
7624 {
Jari Aaltoccc6cda1996-12-23 17:02:34 +00007625 temp[0] = CTLESC;
7626 temp[1] = n;
7627 temp[2] = '\0';
7628 }
7629 else if (n == -1)
7630 {
7631 temp[0] = '\\';
7632 temp[1] = '\0';
7633 }
7634 else
7635 {
Jari Aaltoccc6cda1996-12-23 17:02:34 +00007636 temp[0] = n;
7637 temp[1] = '\0';
7638 }
Jari Aalto726f6381996-08-26 18:22:31 +00007639
Jari Aalto28ef6c32001-04-06 19:14:31 +00007640 for (c = 0; n != -1 && c < 3 && ISOCTAL (*string); c++)
7641 string++;
7642
Jari Aalto7117c2d2002-07-17 14:10:11 +00007643 c = 0; /* tested at add_string: */
Jari Aaltoccc6cda1996-12-23 17:02:34 +00007644 goto add_string;
Jari Aalto726f6381996-08-26 18:22:31 +00007645
Jari Aalto726f6381996-08-26 18:22:31 +00007646 case 'd':
Jari Aalto7117c2d2002-07-17 14:10:11 +00007647 case 't':
Jari Aaltoccc6cda1996-12-23 17:02:34 +00007648 case 'T':
7649 case '@':
Jari Aaltof73dda02001-11-13 17:56:06 +00007650 case 'A':
Jari Aalto726f6381996-08-26 18:22:31 +00007651 /* Make the current time/date into a string. */
Jari Aalto7117c2d2002-07-17 14:10:11 +00007652 (void) time (&the_time);
Chet Ramey509a4432013-01-10 19:53:16 -05007653#if defined (HAVE_TZSET)
7654 sv_tz ("TZ"); /* XXX -- just make sure */
7655#endif
Jari Aalto7117c2d2002-07-17 14:10:11 +00007656 tm = localtime (&the_time);
Jari Aalto726f6381996-08-26 18:22:31 +00007657
Jari Aalto7117c2d2002-07-17 14:10:11 +00007658 if (c == 'd')
7659 n = strftime (timebuf, sizeof (timebuf), "%a %b %d", tm);
7660 else if (c == 't')
7661 n = strftime (timebuf, sizeof (timebuf), "%H:%M:%S", tm);
7662 else if (c == 'T')
7663 n = strftime (timebuf, sizeof (timebuf), "%I:%M:%S", tm);
7664 else if (c == '@')
7665 n = strftime (timebuf, sizeof (timebuf), "%I:%M %p", tm);
7666 else if (c == 'A')
7667 n = strftime (timebuf, sizeof (timebuf), "%H:%M", tm);
Jari Aalto726f6381996-08-26 18:22:31 +00007668
Jari Aaltob80f6442004-07-27 13:29:18 +00007669 if (n == 0)
7670 timebuf[0] = '\0';
7671 else
7672 timebuf[sizeof(timebuf) - 1] = '\0';
7673
Jari Aalto7117c2d2002-07-17 14:10:11 +00007674 temp = savestring (timebuf);
7675 goto add_string;
7676
7677 case 'D': /* strftime format */
7678 if (string[1] != '{') /* } */
7679 goto not_escape;
7680
7681 (void) time (&the_time);
7682 tm = localtime (&the_time);
7683 string += 2; /* skip { */
7684 timefmt = xmalloc (strlen (string) + 3);
7685 for (t = timefmt; *string && *string != '}'; )
7686 *t++ = *string++;
7687 *t = '\0';
7688 c = *string; /* tested at add_string */
7689 if (timefmt[0] == '\0')
Jari Aaltoccc6cda1996-12-23 17:02:34 +00007690 {
Jari Aalto7117c2d2002-07-17 14:10:11 +00007691 timefmt[0] = '%';
7692 timefmt[1] = 'X'; /* locale-specific current time */
7693 timefmt[2] = '\0';
Jari Aaltoccc6cda1996-12-23 17:02:34 +00007694 }
Jari Aalto7117c2d2002-07-17 14:10:11 +00007695 n = strftime (timebuf, sizeof (timebuf), timefmt, tm);
7696 free (timefmt);
Jari Aalto726f6381996-08-26 18:22:31 +00007697
Jari Aaltob80f6442004-07-27 13:29:18 +00007698 if (n == 0)
7699 timebuf[0] = '\0';
7700 else
7701 timebuf[sizeof(timebuf) - 1] = '\0';
7702
Jari Aalto7117c2d2002-07-17 14:10:11 +00007703 if (promptvars || posixly_correct)
7704 /* Make sure that expand_prompt_string is called with a
7705 second argument of Q_DOUBLE_QUOTES if we use this
7706 function here. */
7707 temp = sh_backslash_quote_for_double_quotes (timebuf);
7708 else
7709 temp = savestring (timebuf);
Jari Aaltocce855b1998-04-17 19:52:44 +00007710 goto add_string;
Jari Aalto7117c2d2002-07-17 14:10:11 +00007711
Jari Aalto726f6381996-08-26 18:22:31 +00007712 case 'n':
Jari Aaltof73dda02001-11-13 17:56:06 +00007713 temp = (char *)xmalloc (3);
Jari Aaltoccc6cda1996-12-23 17:02:34 +00007714 temp[0] = no_line_editing ? '\n' : '\r';
7715 temp[1] = no_line_editing ? '\0' : '\n';
7716 temp[2] = '\0';
Jari Aalto726f6381996-08-26 18:22:31 +00007717 goto add_string;
7718
7719 case 's':
Jari Aaltoccc6cda1996-12-23 17:02:34 +00007720 temp = base_pathname (shell_name);
7721 temp = savestring (temp);
7722 goto add_string;
7723
7724 case 'v':
7725 case 'V':
Jari Aalto7117c2d2002-07-17 14:10:11 +00007726 temp = (char *)xmalloc (16);
Jari Aaltoccc6cda1996-12-23 17:02:34 +00007727 if (c == 'v')
7728 strcpy (temp, dist_version);
7729 else
7730 sprintf (temp, "%s.%d", dist_version, patch_level);
7731 goto add_string;
7732
Jari Aalto726f6381996-08-26 18:22:31 +00007733 case 'w':
7734 case 'W':
7735 {
Jari Aaltoccc6cda1996-12-23 17:02:34 +00007736 /* Use the value of PWD because it is much more efficient. */
Jari Aalto06285672006-10-10 14:15:34 +00007737 char t_string[PATH_MAX];
Jari Aaltoe8ce7751997-09-22 20:22:27 +00007738 int tlen;
Jari Aalto726f6381996-08-26 18:22:31 +00007739
7740 temp = get_string_value ("PWD");
7741
Jari Aaltoccc6cda1996-12-23 17:02:34 +00007742 if (temp == 0)
7743 {
7744 if (getcwd (t_string, sizeof(t_string)) == 0)
7745 {
Jari Aalto28ef6c32001-04-06 19:14:31 +00007746 t_string[0] = '.';
Jari Aaltoe8ce7751997-09-22 20:22:27 +00007747 tlen = 1;
Jari Aaltoccc6cda1996-12-23 17:02:34 +00007748 }
Jari Aaltoe8ce7751997-09-22 20:22:27 +00007749 else
7750 tlen = strlen (t_string);
Jari Aaltoccc6cda1996-12-23 17:02:34 +00007751 }
Jari Aalto726f6381996-08-26 18:22:31 +00007752 else
Jari Aaltoe8ce7751997-09-22 20:22:27 +00007753 {
7754 tlen = sizeof (t_string) - 1;
7755 strncpy (t_string, temp, tlen);
7756 }
7757 t_string[tlen] = '\0';
Jari Aalto726f6381996-08-26 18:22:31 +00007758
Chet Ramey00018032011-11-21 20:51:19 -05007759#if defined (MACOSX)
7760 /* Convert from "fs" format to "input" format */
7761 temp = fnx_fromfs (t_string, strlen (t_string));
7762 if (temp != t_string)
7763 strcpy (t_string, temp);
7764#endif
7765
Jari Aalto28ef6c32001-04-06 19:14:31 +00007766#define ROOT_PATH(x) ((x)[0] == '/' && (x)[1] == 0)
7767#define DOUBLE_SLASH_ROOT(x) ((x)[0] == '/' && (x)[1] == '/' && (x)[2] == 0)
Jari Aaltob80f6442004-07-27 13:29:18 +00007768 /* Abbreviate \W as ~ if $PWD == $HOME */
Jari Aalto95732b42005-12-07 14:08:12 +00007769 if (c == 'W' && (((t = get_string_value ("HOME")) == 0) || STREQ (t, t_string) == 0))
Jari Aalto726f6381996-08-26 18:22:31 +00007770 {
Jari Aalto28ef6c32001-04-06 19:14:31 +00007771 if (ROOT_PATH (t_string) == 0 && DOUBLE_SLASH_ROOT (t_string) == 0)
7772 {
7773 t = strrchr (t_string, '/');
7774 if (t)
Chet Ramey495aee42011-11-22 19:11:26 -05007775 memmove (t_string, t + 1, strlen (t)); /* strlen(t) to copy NULL */
Jari Aalto28ef6c32001-04-06 19:14:31 +00007776 }
Jari Aalto726f6381996-08-26 18:22:31 +00007777 }
Jari Aalto28ef6c32001-04-06 19:14:31 +00007778#undef ROOT_PATH
7779#undef DOUBLE_SLASH_ROOT
Jari Aalto726f6381996-08-26 18:22:31 +00007780 else
Chet Rameyac50fba2014-02-26 09:36:43 -05007781 {
7782 /* polite_directory_format is guaranteed to return a string
7783 no longer than PATH_MAX - 1 characters. */
7784 temp = polite_directory_format (t_string);
7785 if (temp != t_string)
7786 strcpy (t_string, temp);
7787 }
Jari Aaltoccc6cda1996-12-23 17:02:34 +00007788
Jari Aalto31859422009-01-12 13:36:28 +00007789 temp = trim_pathname (t_string, PATH_MAX - 1);
Jari Aaltoccc6cda1996-12-23 17:02:34 +00007790 /* If we're going to be expanding the prompt string later,
7791 quote the directory name. */
7792 if (promptvars || posixly_correct)
Jari Aaltobb706242000-03-17 21:46:59 +00007793 /* Make sure that expand_prompt_string is called with a
Jari Aalto7117c2d2002-07-17 14:10:11 +00007794 second argument of Q_DOUBLE_QUOTES if we use this
Jari Aaltobb706242000-03-17 21:46:59 +00007795 function here. */
Jari Aalto28ef6c32001-04-06 19:14:31 +00007796 temp = sh_backslash_quote_for_double_quotes (t_string);
Jari Aaltoccc6cda1996-12-23 17:02:34 +00007797 else
7798 temp = savestring (t_string);
7799
Jari Aalto726f6381996-08-26 18:22:31 +00007800 goto add_string;
7801 }
Jari Aaltoccc6cda1996-12-23 17:02:34 +00007802
Jari Aalto726f6381996-08-26 18:22:31 +00007803 case 'u':
Jari Aaltobb706242000-03-17 21:46:59 +00007804 if (current_user.user_name == 0)
7805 get_current_user_info ();
Jari Aaltoccc6cda1996-12-23 17:02:34 +00007806 temp = savestring (current_user.user_name);
7807 goto add_string;
Jari Aalto726f6381996-08-26 18:22:31 +00007808
7809 case 'h':
Jari Aaltoccc6cda1996-12-23 17:02:34 +00007810 case 'H':
7811 temp = savestring (current_host_name);
7812 if (c == 'h' && (t = (char *)strchr (temp, '.')))
7813 *t = '\0';
7814 goto add_string;
Jari Aalto726f6381996-08-26 18:22:31 +00007815
7816 case '#':
Jari Aaltoccc6cda1996-12-23 17:02:34 +00007817 temp = itos (current_command_number);
7818 goto add_string;
Jari Aalto726f6381996-08-26 18:22:31 +00007819
7820 case '!':
Jari Aalto726f6381996-08-26 18:22:31 +00007821#if !defined (HISTORY)
Jari Aaltoccc6cda1996-12-23 17:02:34 +00007822 temp = savestring ("1");
Jari Aalto726f6381996-08-26 18:22:31 +00007823#else /* HISTORY */
Jari Aaltoccc6cda1996-12-23 17:02:34 +00007824 temp = itos (history_number ());
Jari Aalto726f6381996-08-26 18:22:31 +00007825#endif /* HISTORY */
Jari Aaltoccc6cda1996-12-23 17:02:34 +00007826 goto add_string;
Jari Aalto726f6381996-08-26 18:22:31 +00007827
7828 case '$':
Jari Aaltof73dda02001-11-13 17:56:06 +00007829 t = temp = (char *)xmalloc (3);
Jari Aaltob72432f1999-02-19 17:11:39 +00007830 if ((promptvars || posixly_correct) && (current_user.euid != 0))
7831 *t++ = '\\';
7832 *t++ = current_user.euid == 0 ? '#' : '$';
7833 *t = '\0';
Jari Aalto726f6381996-08-26 18:22:31 +00007834 goto add_string;
7835
Jari Aaltobb706242000-03-17 21:46:59 +00007836 case 'j':
7837 temp = itos (count_all_jobs ());
7838 goto add_string;
7839
7840 case 'l':
7841#if defined (HAVE_TTYNAME)
7842 temp = (char *)ttyname (fileno (stdin));
7843 t = temp ? base_pathname (temp) : "tty";
7844 temp = savestring (t);
7845#else
7846 temp = savestring ("tty");
7847#endif /* !HAVE_TTYNAME */
7848 goto add_string;
7849
Jari Aalto726f6381996-08-26 18:22:31 +00007850#if defined (READLINE)
7851 case '[':
7852 case ']':
Jari Aaltob80f6442004-07-27 13:29:18 +00007853 if (no_line_editing)
7854 {
7855 string++;
7856 break;
7857 }
Jari Aaltof73dda02001-11-13 17:56:06 +00007858 temp = (char *)xmalloc (3);
Jari Aalto06285672006-10-10 14:15:34 +00007859 n = (c == '[') ? RL_PROMPT_START_IGNORE : RL_PROMPT_END_IGNORE;
7860 i = 0;
7861 if (n == CTLESC || n == CTLNUL)
7862 temp[i++] = CTLESC;
7863 temp[i++] = n;
7864 temp[i] = '\0';
Jari Aalto726f6381996-08-26 18:22:31 +00007865 goto add_string;
Jari Aaltoccc6cda1996-12-23 17:02:34 +00007866#endif /* READLINE */
Jari Aalto726f6381996-08-26 18:22:31 +00007867
7868 case '\\':
Jari Aaltoccc6cda1996-12-23 17:02:34 +00007869 case 'a':
7870 case 'e':
Jari Aalto7117c2d2002-07-17 14:10:11 +00007871 case 'r':
Jari Aaltof73dda02001-11-13 17:56:06 +00007872 temp = (char *)xmalloc (2);
Jari Aalto7117c2d2002-07-17 14:10:11 +00007873 if (c == 'a')
7874 temp[0] = '\07';
7875 else if (c == 'e')
7876 temp[0] = '\033';
7877 else if (c == 'r')
7878 temp[0] = '\r';
7879 else /* (c == '\\') */
7880 temp[0] = c;
Jari Aaltoccc6cda1996-12-23 17:02:34 +00007881 temp[1] = '\0';
Jari Aalto726f6381996-08-26 18:22:31 +00007882 goto add_string;
7883
7884 default:
Jari Aalto7117c2d2002-07-17 14:10:11 +00007885not_escape:
Jari Aaltof73dda02001-11-13 17:56:06 +00007886 temp = (char *)xmalloc (3);
Jari Aaltoccc6cda1996-12-23 17:02:34 +00007887 temp[0] = '\\';
Jari Aalto726f6381996-08-26 18:22:31 +00007888 temp[1] = c;
Jari Aaltoccc6cda1996-12-23 17:02:34 +00007889 temp[2] = '\0';
Jari Aalto726f6381996-08-26 18:22:31 +00007890
7891 add_string:
7892 if (c)
7893 string++;
7894 result =
7895 sub_append_string (temp, result, &result_index, &result_size);
Jari Aaltoccc6cda1996-12-23 17:02:34 +00007896 temp = (char *)NULL; /* Freed in sub_append_string (). */
Jari Aalto726f6381996-08-26 18:22:31 +00007897 result[result_index] = '\0';
7898 break;
7899 }
7900 }
7901 else
7902 {
Jari Aaltoccc6cda1996-12-23 17:02:34 +00007903 RESIZE_MALLOCED_BUFFER (result, result_index, 3, result_size, PROMPT_GROWTH);
Jari Aalto726f6381996-08-26 18:22:31 +00007904 result[result_index++] = c;
7905 result[result_index] = '\0';
7906 }
7907 }
7908#else /* !PROMPT_STRING_DECODE */
7909 result = savestring (string);
7910#endif /* !PROMPT_STRING_DECODE */
7911
Jari Aaltoccc6cda1996-12-23 17:02:34 +00007912 /* Save the delimiter stack and point `dstack' to temp space so any
7913 command substitutions in the prompt string won't result in screwing
7914 up the parser's quoting state. */
7915 save_dstack = dstack;
7916 dstack = temp_dstack;
7917 dstack.delimiter_depth = 0;
7918
Jari Aalto726f6381996-08-26 18:22:31 +00007919 /* Perform variable and parameter expansion and command substitution on
7920 the prompt string. */
Jari Aaltoccc6cda1996-12-23 17:02:34 +00007921 if (promptvars || posixly_correct)
7922 {
Jari Aaltof73dda02001-11-13 17:56:06 +00007923 last_exit_value = last_command_exit_value;
Chet Ramey00018032011-11-21 20:51:19 -05007924 last_comsub_pid = last_command_subst_pid;
Jari Aalto31859422009-01-12 13:36:28 +00007925 list = expand_prompt_string (result, Q_DOUBLE_QUOTES, 0);
Jari Aaltoccc6cda1996-12-23 17:02:34 +00007926 free (result);
7927 result = string_list (list);
7928 dispose_words (list);
Jari Aaltof73dda02001-11-13 17:56:06 +00007929 last_command_exit_value = last_exit_value;
Chet Ramey00018032011-11-21 20:51:19 -05007930 last_command_subst_pid = last_comsub_pid;
Jari Aaltoccc6cda1996-12-23 17:02:34 +00007931 }
7932 else
7933 {
7934 t = dequote_string (result);
7935 free (result);
7936 result = t;
7937 }
7938
7939 dstack = save_dstack;
Jari Aalto726f6381996-08-26 18:22:31 +00007940
7941 return (result);
7942}
7943
Jari Aalto7117c2d2002-07-17 14:10:11 +00007944/************************************************
7945 * *
7946 * ERROR HANDLING *
7947 * *
7948 ************************************************/
7949
Jari Aalto726f6381996-08-26 18:22:31 +00007950/* Report a syntax error, and restart the parser. Call here for fatal
7951 errors. */
Jari Aaltoccc6cda1996-12-23 17:02:34 +00007952int
Jari Aaltof73dda02001-11-13 17:56:06 +00007953yyerror (msg)
7954 const char *msg;
Jari Aalto726f6381996-08-26 18:22:31 +00007955{
7956 report_syntax_error ((char *)NULL);
7957 reset_parser ();
Jari Aaltoccc6cda1996-12-23 17:02:34 +00007958 return (0);
Jari Aalto726f6381996-08-26 18:22:31 +00007959}
7960
Jari Aalto7117c2d2002-07-17 14:10:11 +00007961static char *
Jari Aalto06285672006-10-10 14:15:34 +00007962error_token_from_token (tok)
7963 int tok;
Jari Aalto7117c2d2002-07-17 14:10:11 +00007964{
7965 char *t;
7966
Jari Aalto06285672006-10-10 14:15:34 +00007967 if (t = find_token_in_alist (tok, word_token_alist, 0))
Jari Aalto7117c2d2002-07-17 14:10:11 +00007968 return t;
7969
Jari Aalto06285672006-10-10 14:15:34 +00007970 if (t = find_token_in_alist (tok, other_token_alist, 0))
Jari Aalto7117c2d2002-07-17 14:10:11 +00007971 return t;
7972
7973 t = (char *)NULL;
7974 /* This stuff is dicy and needs closer inspection */
7975 switch (current_token)
7976 {
7977 case WORD:
7978 case ASSIGNMENT_WORD:
7979 if (yylval.word)
7980 t = savestring (yylval.word->word);
7981 break;
7982 case NUMBER:
7983 t = itos (yylval.number);
7984 break;
7985 case ARITH_CMD:
7986 if (yylval.word_list)
7987 t = string_list (yylval.word_list);
7988 break;
7989 case ARITH_FOR_EXPRS:
7990 if (yylval.word_list)
7991 t = string_list_internal (yylval.word_list, " ; ");
7992 break;
7993 case COND_CMD:
7994 t = (char *)NULL; /* punt */
7995 break;
7996 }
7997
7998 return t;
7999}
8000
8001static char *
8002error_token_from_text ()
8003{
8004 char *msg, *t;
8005 int token_end, i;
8006
8007 t = shell_input_line;
8008 i = shell_input_line_index;
8009 token_end = 0;
8010 msg = (char *)NULL;
8011
8012 if (i && t[i] == '\0')
8013 i--;
8014
8015 while (i && (whitespace (t[i]) || t[i] == '\n'))
8016 i--;
8017
8018 if (i)
8019 token_end = i + 1;
8020
8021 while (i && (member (t[i], " \n\t;|&") == 0))
8022 i--;
8023
8024 while (i != token_end && (whitespace (t[i]) || t[i] == '\n'))
8025 i++;
8026
8027 /* Return our idea of the offending token. */
8028 if (token_end || (i == 0 && token_end == 0))
8029 {
8030 if (token_end)
8031 msg = substring (t, i, token_end);
8032 else /* one-character token */
8033 {
8034 msg = (char *)xmalloc (2);
8035 msg[0] = t[i];
8036 msg[1] = '\0';
8037 }
8038 }
8039
8040 return (msg);
8041}
8042
8043static void
8044print_offending_line ()
8045{
8046 char *msg;
8047 int token_end;
8048
8049 msg = savestring (shell_input_line);
8050 token_end = strlen (msg);
8051 while (token_end && msg[token_end - 1] == '\n')
8052 msg[--token_end] = '\0';
8053
8054 parser_error (line_number, "`%s'", msg);
8055 free (msg);
8056}
8057
Jari Aalto726f6381996-08-26 18:22:31 +00008058/* Report a syntax error with line numbers, etc.
8059 Call here for recoverable errors. If you have a message to print,
8060 then place it in MESSAGE, otherwise pass NULL and this will figure
8061 out an appropriate message for you. */
8062static void
8063report_syntax_error (message)
8064 char *message;
8065{
Chet Ramey495aee42011-11-22 19:11:26 -05008066 char *msg, *p;
Jari Aaltoccc6cda1996-12-23 17:02:34 +00008067
Jari Aalto726f6381996-08-26 18:22:31 +00008068 if (message)
8069 {
Jari Aaltoccc6cda1996-12-23 17:02:34 +00008070 parser_error (line_number, "%s", message);
8071 if (interactive && EOF_Reached)
8072 EOF_Reached = 0;
Chet Ramey00018032011-11-21 20:51:19 -05008073 last_command_exit_value = parse_and_execute_level ? EX_BADSYNTAX : EX_BADUSAGE;
Jari Aalto726f6381996-08-26 18:22:31 +00008074 return;
8075 }
8076
Jari Aaltoccc6cda1996-12-23 17:02:34 +00008077 /* If the line of input we're reading is not null, try to find the
Jari Aalto7117c2d2002-07-17 14:10:11 +00008078 objectionable token. First, try to figure out what token the
8079 parser's complaining about by looking at current_token. */
8080 if (current_token != 0 && EOF_Reached == 0 && (msg = error_token_from_token (current_token)))
8081 {
Chet Ramey495aee42011-11-22 19:11:26 -05008082 if (ansic_shouldquote (msg))
8083 {
8084 p = ansic_quote (msg, 0, NULL);
8085 free (msg);
8086 msg = p;
8087 }
Jari Aaltob80f6442004-07-27 13:29:18 +00008088 parser_error (line_number, _("syntax error near unexpected token `%s'"), msg);
Jari Aalto7117c2d2002-07-17 14:10:11 +00008089 free (msg);
8090
8091 if (interactive == 0)
8092 print_offending_line ();
8093
Chet Ramey00018032011-11-21 20:51:19 -05008094 last_command_exit_value = parse_and_execute_level ? EX_BADSYNTAX : EX_BADUSAGE;
Jari Aalto7117c2d2002-07-17 14:10:11 +00008095 return;
8096 }
8097
8098 /* If looking at the current token doesn't prove fruitful, try to find the
8099 offending token by analyzing the text of the input line near the current
8100 input line index and report what we find. */
Jari Aalto726f6381996-08-26 18:22:31 +00008101 if (shell_input_line && *shell_input_line)
8102 {
Jari Aalto7117c2d2002-07-17 14:10:11 +00008103 msg = error_token_from_text ();
8104 if (msg)
Jari Aalto726f6381996-08-26 18:22:31 +00008105 {
Jari Aaltob80f6442004-07-27 13:29:18 +00008106 parser_error (line_number, _("syntax error near `%s'"), msg);
Jari Aalto7117c2d2002-07-17 14:10:11 +00008107 free (msg);
Jari Aalto726f6381996-08-26 18:22:31 +00008108 }
8109
Jari Aaltoccc6cda1996-12-23 17:02:34 +00008110 /* If not interactive, print the line containing the error. */
8111 if (interactive == 0)
Jari Aalto7117c2d2002-07-17 14:10:11 +00008112 print_offending_line ();
Jari Aalto726f6381996-08-26 18:22:31 +00008113 }
8114 else
8115 {
Jari Aaltob80f6442004-07-27 13:29:18 +00008116 msg = EOF_Reached ? _("syntax error: unexpected end of file") : _("syntax error");
Jari Aaltoccc6cda1996-12-23 17:02:34 +00008117 parser_error (line_number, "%s", msg);
8118 /* When the shell is interactive, this file uses EOF_Reached
8119 only for error reporting. Other mechanisms are used to
8120 decide whether or not to exit. */
8121 if (interactive && EOF_Reached)
8122 EOF_Reached = 0;
Jari Aalto726f6381996-08-26 18:22:31 +00008123 }
Jari Aalto7117c2d2002-07-17 14:10:11 +00008124
Chet Ramey00018032011-11-21 20:51:19 -05008125 last_command_exit_value = parse_and_execute_level ? EX_BADSYNTAX : EX_BADUSAGE;
Jari Aalto726f6381996-08-26 18:22:31 +00008126}
8127
8128/* ??? Needed function. ??? We have to be able to discard the constructs
8129 created during parsing. In the case of error, we want to return
8130 allocated objects to the memory pool. In the case of no error, we want
8131 to throw away the information about where the allocated objects live.
Jari Aalto7117c2d2002-07-17 14:10:11 +00008132 (dispose_command () will actually free the command.) */
Jari Aaltoccc6cda1996-12-23 17:02:34 +00008133static void
Jari Aalto726f6381996-08-26 18:22:31 +00008134discard_parser_constructs (error_p)
8135 int error_p;
8136{
8137}
Jari Aaltoccc6cda1996-12-23 17:02:34 +00008138
Jari Aalto7117c2d2002-07-17 14:10:11 +00008139/************************************************
8140 * *
8141 * EOF HANDLING *
8142 * *
8143 ************************************************/
8144
Jari Aalto726f6381996-08-26 18:22:31 +00008145/* Do that silly `type "bye" to exit' stuff. You know, "ignoreeof". */
8146
8147/* A flag denoting whether or not ignoreeof is set. */
8148int ignoreeof = 0;
8149
8150/* The number of times that we have encountered an EOF character without
8151 another character intervening. When this gets above the limit, the
8152 shell terminates. */
8153int eof_encountered = 0;
8154
8155/* The limit for eof_encountered. */
8156int eof_encountered_limit = 10;
8157
8158/* If we have EOF as the only input unit, this user wants to leave
8159 the shell. If the shell is not interactive, then just leave.
8160 Otherwise, if ignoreeof is set, and we haven't done this the
8161 required number of times in a row, print a message. */
8162static void
8163handle_eof_input_unit ()
8164{
8165 if (interactive)
8166 {
8167 /* shell.c may use this to decide whether or not to write out the
8168 history, among other things. We use it only for error reporting
8169 in this file. */
8170 if (EOF_Reached)
8171 EOF_Reached = 0;
8172
8173 /* If the user wants to "ignore" eof, then let her do so, kind of. */
8174 if (ignoreeof)
8175 {
8176 if (eof_encountered < eof_encountered_limit)
8177 {
Jari Aaltob80f6442004-07-27 13:29:18 +00008178 fprintf (stderr, _("Use \"%s\" to leave the shell.\n"),
Jari Aalto726f6381996-08-26 18:22:31 +00008179 login_shell ? "logout" : "exit");
8180 eof_encountered++;
Jari Aalto7117c2d2002-07-17 14:10:11 +00008181 /* Reset the parsing state. */
8182 last_read_token = current_token = '\n';
Jari Aalto726f6381996-08-26 18:22:31 +00008183 /* Reset the prompt string to be $PS1. */
8184 prompt_string_pointer = (char **)NULL;
8185 prompt_again ();
Jari Aalto726f6381996-08-26 18:22:31 +00008186 return;
Jari Aaltoccc6cda1996-12-23 17:02:34 +00008187 }
Jari Aalto726f6381996-08-26 18:22:31 +00008188 }
8189
8190 /* In this case EOF should exit the shell. Do it now. */
8191 reset_parser ();
8192 exit_builtin ((WORD_LIST *)NULL);
8193 }
8194 else
8195 {
8196 /* We don't write history files, etc., for non-interactive shells. */
8197 EOF_Reached = 1;
8198 }
8199}
Jari Aaltobb706242000-03-17 21:46:59 +00008200
Jari Aalto7117c2d2002-07-17 14:10:11 +00008201/************************************************
8202 * *
8203 * STRING PARSING FUNCTIONS *
8204 * *
8205 ************************************************/
8206
8207/* It's very important that these two functions treat the characters
8208 between ( and ) identically. */
8209
Jari Aaltobb706242000-03-17 21:46:59 +00008210static WORD_LIST parse_string_error;
8211
8212/* Take a string and run it through the shell parser, returning the
8213 resultant word list. Used by compound array assignment. */
8214WORD_LIST *
Jari Aaltob80f6442004-07-27 13:29:18 +00008215parse_string_to_word_list (s, flags, whom)
Jari Aaltof73dda02001-11-13 17:56:06 +00008216 char *s;
Jari Aaltob80f6442004-07-27 13:29:18 +00008217 int flags;
Jari Aaltof73dda02001-11-13 17:56:06 +00008218 const char *whom;
Jari Aaltobb706242000-03-17 21:46:59 +00008219{
8220 WORD_LIST *wl;
Jari Aalto7117c2d2002-07-17 14:10:11 +00008221 int tok, orig_current_token, orig_line_number, orig_input_terminator;
Jari Aalto28ef6c32001-04-06 19:14:31 +00008222 int orig_line_count;
Jari Aalto7117c2d2002-07-17 14:10:11 +00008223 int old_echo_input, old_expand_aliases;
Jari Aaltobb706242000-03-17 21:46:59 +00008224#if defined (HISTORY)
8225 int old_remember_on_history, old_history_expansion_inhibited;
8226#endif
8227
8228#if defined (HISTORY)
8229 old_remember_on_history = remember_on_history;
8230# if defined (BANG_HISTORY)
8231 old_history_expansion_inhibited = history_expansion_inhibited;
8232# endif
8233 bash_history_disable ();
8234#endif
8235
8236 orig_line_number = line_number;
Jari Aalto28ef6c32001-04-06 19:14:31 +00008237 orig_line_count = current_command_line_count;
Jari Aaltobb706242000-03-17 21:46:59 +00008238 orig_input_terminator = shell_input_line_terminator;
Jari Aalto7117c2d2002-07-17 14:10:11 +00008239 old_echo_input = echo_input_at_read;
8240 old_expand_aliases = expand_aliases;
Jari Aaltobb706242000-03-17 21:46:59 +00008241
8242 push_stream (1);
Jari Aalto7117c2d2002-07-17 14:10:11 +00008243 last_read_token = WORD; /* WORD to allow reserved words here */
Jari Aalto28ef6c32001-04-06 19:14:31 +00008244 current_command_line_count = 0;
Jari Aalto7117c2d2002-07-17 14:10:11 +00008245 echo_input_at_read = expand_aliases = 0;
Jari Aaltobb706242000-03-17 21:46:59 +00008246
8247 with_input_from_string (s, whom);
8248 wl = (WORD_LIST *)NULL;
Jari Aaltob80f6442004-07-27 13:29:18 +00008249
8250 if (flags & 1)
Jari Aalto31859422009-01-12 13:36:28 +00008251 parser_state |= PST_COMPASSIGN|PST_REPARSE;
Jari Aaltob80f6442004-07-27 13:29:18 +00008252
Jari Aaltobb706242000-03-17 21:46:59 +00008253 while ((tok = read_token (READ)) != yacc_EOF)
8254 {
8255 if (tok == '\n' && *bash_input.location.string == '\0')
8256 break;
Jari Aalto28ef6c32001-04-06 19:14:31 +00008257 if (tok == '\n') /* Allow newlines in compound assignments */
8258 continue;
Jari Aaltobb706242000-03-17 21:46:59 +00008259 if (tok != WORD && tok != ASSIGNMENT_WORD)
8260 {
8261 line_number = orig_line_number + line_number - 1;
Jari Aalto7117c2d2002-07-17 14:10:11 +00008262 orig_current_token = current_token;
8263 current_token = tok;
Jari Aalto95732b42005-12-07 14:08:12 +00008264 yyerror (NULL); /* does the right thing */
Jari Aalto7117c2d2002-07-17 14:10:11 +00008265 current_token = orig_current_token;
Jari Aaltobb706242000-03-17 21:46:59 +00008266 if (wl)
8267 dispose_words (wl);
8268 wl = &parse_string_error;
8269 break;
8270 }
8271 wl = make_word_list (yylval.word, wl);
8272 }
8273
8274 last_read_token = '\n';
8275 pop_stream ();
8276
8277#if defined (HISTORY)
8278 remember_on_history = old_remember_on_history;
8279# if defined (BANG_HISTORY)
8280 history_expansion_inhibited = old_history_expansion_inhibited;
8281# endif /* BANG_HISTORY */
8282#endif /* HISTORY */
8283
Jari Aalto7117c2d2002-07-17 14:10:11 +00008284 echo_input_at_read = old_echo_input;
8285 expand_aliases = old_expand_aliases;
8286
Jari Aalto28ef6c32001-04-06 19:14:31 +00008287 current_command_line_count = orig_line_count;
Jari Aaltobb706242000-03-17 21:46:59 +00008288 shell_input_line_terminator = orig_input_terminator;
8289
Jari Aaltob80f6442004-07-27 13:29:18 +00008290 if (flags & 1)
Jari Aalto31859422009-01-12 13:36:28 +00008291 parser_state &= ~(PST_COMPASSIGN|PST_REPARSE);
Jari Aaltob80f6442004-07-27 13:29:18 +00008292
Jari Aaltobb706242000-03-17 21:46:59 +00008293 if (wl == &parse_string_error)
8294 {
8295 last_command_exit_value = EXECUTION_FAILURE;
8296 if (interactive_shell == 0 && posixly_correct)
8297 jump_to_top_level (FORCE_EOF);
8298 else
8299 jump_to_top_level (DISCARD);
8300 }
8301
8302 return (REVERSE_LIST (wl, WORD_LIST *));
8303}
Jari Aalto7117c2d2002-07-17 14:10:11 +00008304
8305static char *
8306parse_compound_assignment (retlenp)
8307 int *retlenp;
8308{
8309 WORD_LIST *wl, *rl;
Jari Aalto06285672006-10-10 14:15:34 +00008310 int tok, orig_line_number, orig_token_size, orig_last_token, assignok;
Jari Aalto7117c2d2002-07-17 14:10:11 +00008311 char *saved_token, *ret;
8312
8313 saved_token = token;
8314 orig_token_size = token_buffer_size;
8315 orig_line_number = line_number;
Jari Aalto06285672006-10-10 14:15:34 +00008316 orig_last_token = last_read_token;
Jari Aalto7117c2d2002-07-17 14:10:11 +00008317
8318 last_read_token = WORD; /* WORD to allow reserved words here */
8319
8320 token = (char *)NULL;
8321 token_buffer_size = 0;
8322
Jari Aalto06285672006-10-10 14:15:34 +00008323 assignok = parser_state&PST_ASSIGNOK; /* XXX */
8324
Jari Aalto7117c2d2002-07-17 14:10:11 +00008325 wl = (WORD_LIST *)NULL; /* ( */
Jari Aaltob80f6442004-07-27 13:29:18 +00008326 parser_state |= PST_COMPASSIGN;
8327
Jari Aalto7117c2d2002-07-17 14:10:11 +00008328 while ((tok = read_token (READ)) != ')')
8329 {
8330 if (tok == '\n') /* Allow newlines in compound assignments */
Jari Aaltob80f6442004-07-27 13:29:18 +00008331 {
8332 if (SHOULD_PROMPT ())
8333 prompt_again ();
8334 continue;
8335 }
Jari Aalto7117c2d2002-07-17 14:10:11 +00008336 if (tok != WORD && tok != ASSIGNMENT_WORD)
8337 {
8338 current_token = tok; /* for error reporting */
8339 if (tok == yacc_EOF) /* ( */
Jari Aaltob80f6442004-07-27 13:29:18 +00008340 parser_error (orig_line_number, _("unexpected EOF while looking for matching `)'"));
Jari Aalto7117c2d2002-07-17 14:10:11 +00008341 else
Jari Aalto95732b42005-12-07 14:08:12 +00008342 yyerror(NULL); /* does the right thing */
Jari Aalto7117c2d2002-07-17 14:10:11 +00008343 if (wl)
8344 dispose_words (wl);
8345 wl = &parse_string_error;
8346 break;
8347 }
8348 wl = make_word_list (yylval.word, wl);
8349 }
8350
8351 FREE (token);
8352 token = saved_token;
8353 token_buffer_size = orig_token_size;
8354
Jari Aaltob80f6442004-07-27 13:29:18 +00008355 parser_state &= ~PST_COMPASSIGN;
8356
Jari Aalto7117c2d2002-07-17 14:10:11 +00008357 if (wl == &parse_string_error)
8358 {
8359 last_command_exit_value = EXECUTION_FAILURE;
8360 last_read_token = '\n'; /* XXX */
8361 if (interactive_shell == 0 && posixly_correct)
8362 jump_to_top_level (FORCE_EOF);
8363 else
8364 jump_to_top_level (DISCARD);
8365 }
8366
Jari Aalto06285672006-10-10 14:15:34 +00008367 last_read_token = orig_last_token; /* XXX - was WORD? */
8368
Jari Aalto7117c2d2002-07-17 14:10:11 +00008369 if (wl)
8370 {
8371 rl = REVERSE_LIST (wl, WORD_LIST *);
8372 ret = string_list (rl);
8373 dispose_words (rl);
8374 }
8375 else
8376 ret = (char *)NULL;
8377
8378 if (retlenp)
8379 *retlenp = (ret && *ret) ? strlen (ret) : 0;
Jari Aalto06285672006-10-10 14:15:34 +00008380
8381 if (assignok)
8382 parser_state |= PST_ASSIGNOK;
8383
Jari Aalto7117c2d2002-07-17 14:10:11 +00008384 return ret;
8385}
8386
8387/************************************************
8388 * *
Jari Aaltob80f6442004-07-27 13:29:18 +00008389 * SAVING AND RESTORING PARTIAL PARSE STATE *
8390 * *
8391 ************************************************/
8392
8393sh_parser_state_t *
8394save_parser_state (ps)
8395 sh_parser_state_t *ps;
8396{
Jari Aaltob80f6442004-07-27 13:29:18 +00008397 if (ps == 0)
Jari Aalto95732b42005-12-07 14:08:12 +00008398 ps = (sh_parser_state_t *)xmalloc (sizeof (sh_parser_state_t));
Jari Aaltob80f6442004-07-27 13:29:18 +00008399 if (ps == 0)
8400 return ((sh_parser_state_t *)NULL);
8401
8402 ps->parser_state = parser_state;
8403 ps->token_state = save_token_state ();
8404
8405 ps->input_line_terminator = shell_input_line_terminator;
8406 ps->eof_encountered = eof_encountered;
8407
Chet Ramey495aee42011-11-22 19:11:26 -05008408 ps->prompt_string_pointer = prompt_string_pointer;
8409
Jari Aaltob80f6442004-07-27 13:29:18 +00008410 ps->current_command_line_count = current_command_line_count;
8411
8412#if defined (HISTORY)
8413 ps->remember_on_history = remember_on_history;
8414# if defined (BANG_HISTORY)
8415 ps->history_expansion_inhibited = history_expansion_inhibited;
8416# endif
8417#endif
8418
8419 ps->last_command_exit_value = last_command_exit_value;
8420#if defined (ARRAY_VARS)
Chet Ramey495aee42011-11-22 19:11:26 -05008421 ps->pipestatus = save_pipestatus_array ();
Jari Aaltob80f6442004-07-27 13:29:18 +00008422#endif
8423
8424 ps->last_shell_builtin = last_shell_builtin;
8425 ps->this_shell_builtin = this_shell_builtin;
8426
8427 ps->expand_aliases = expand_aliases;
8428 ps->echo_input_at_read = echo_input_at_read;
Chet Rameydaefb2c2014-08-01 15:30:48 -04008429 ps->need_here_doc = need_here_doc;
Jari Aaltob80f6442004-07-27 13:29:18 +00008430
Chet Ramey509a4432013-01-10 19:53:16 -05008431 ps->token = token;
8432 ps->token_buffer_size = token_buffer_size;
8433 /* Force reallocation on next call to read_token_word */
8434 token = 0;
8435 token_buffer_size = 0;
8436
Jari Aaltob80f6442004-07-27 13:29:18 +00008437 return (ps);
8438}
8439
8440void
8441restore_parser_state (ps)
8442 sh_parser_state_t *ps;
8443{
Jari Aaltob80f6442004-07-27 13:29:18 +00008444 if (ps == 0)
8445 return;
8446
8447 parser_state = ps->parser_state;
8448 if (ps->token_state)
8449 {
8450 restore_token_state (ps->token_state);
8451 free (ps->token_state);
8452 }
8453
8454 shell_input_line_terminator = ps->input_line_terminator;
8455 eof_encountered = ps->eof_encountered;
8456
Chet Ramey495aee42011-11-22 19:11:26 -05008457 prompt_string_pointer = ps->prompt_string_pointer;
8458
Jari Aaltob80f6442004-07-27 13:29:18 +00008459 current_command_line_count = ps->current_command_line_count;
8460
8461#if defined (HISTORY)
8462 remember_on_history = ps->remember_on_history;
8463# if defined (BANG_HISTORY)
8464 history_expansion_inhibited = ps->history_expansion_inhibited;
8465# endif
8466#endif
8467
8468 last_command_exit_value = ps->last_command_exit_value;
8469#if defined (ARRAY_VARS)
Chet Ramey495aee42011-11-22 19:11:26 -05008470 restore_pipestatus_array (ps->pipestatus);
Jari Aaltob80f6442004-07-27 13:29:18 +00008471#endif
8472
8473 last_shell_builtin = ps->last_shell_builtin;
8474 this_shell_builtin = ps->this_shell_builtin;
8475
8476 expand_aliases = ps->expand_aliases;
8477 echo_input_at_read = ps->echo_input_at_read;
Chet Rameydaefb2c2014-08-01 15:30:48 -04008478 need_here_doc = ps->need_here_doc;
Chet Ramey509a4432013-01-10 19:53:16 -05008479
8480 FREE (token);
8481 token = ps->token;
8482 token_buffer_size = ps->token_buffer_size;
8483}
8484
8485sh_input_line_state_t *
8486save_input_line_state (ls)
8487 sh_input_line_state_t *ls;
8488{
8489 if (ls == 0)
8490 ls = (sh_input_line_state_t *)xmalloc (sizeof (sh_input_line_state_t));
8491 if (ls == 0)
8492 return ((sh_input_line_state_t *)NULL);
8493
8494 ls->input_line = shell_input_line;
8495 ls->input_line_size = shell_input_line_size;
8496 ls->input_line_len = shell_input_line_len;
8497 ls->input_line_index = shell_input_line_index;
8498
8499 /* force reallocation */
8500 shell_input_line = 0;
8501 shell_input_line_size = shell_input_line_len = shell_input_line_index = 0;
Chet Rameyac50fba2014-02-26 09:36:43 -05008502
8503 return ls;
Chet Ramey509a4432013-01-10 19:53:16 -05008504}
8505
8506void
8507restore_input_line_state (ls)
8508 sh_input_line_state_t *ls;
8509{
8510 FREE (shell_input_line);
8511 shell_input_line = ls->input_line;
8512 shell_input_line_size = ls->input_line_size;
8513 shell_input_line_len = ls->input_line_len;
8514 shell_input_line_index = ls->input_line_index;
8515
8516 set_line_mbstate ();
Jari Aaltob80f6442004-07-27 13:29:18 +00008517}
8518
8519/************************************************
8520 * *
Jari Aalto7117c2d2002-07-17 14:10:11 +00008521 * MULTIBYTE CHARACTER HANDLING *
8522 * *
8523 ************************************************/
8524
8525#if defined (HANDLE_MULTIBYTE)
8526static void
8527set_line_mbstate ()
8528{
Chet Rameyac50fba2014-02-26 09:36:43 -05008529 int c;
8530 size_t i, previ, len;
Jari Aalto7117c2d2002-07-17 14:10:11 +00008531 mbstate_t mbs, prevs;
8532 size_t mbclen;
8533
8534 if (shell_input_line == NULL)
8535 return;
8536 len = strlen (shell_input_line); /* XXX - shell_input_line_len ? */
8537 FREE (shell_input_line_property);
8538 shell_input_line_property = (char *)xmalloc (len + 1);
8539
8540 memset (&prevs, '\0', sizeof (mbstate_t));
8541 for (i = previ = 0; i < len; i++)
8542 {
8543 mbs = prevs;
8544
Jari Aaltob80f6442004-07-27 13:29:18 +00008545 c = shell_input_line[i];
8546 if (c == EOF)
Jari Aalto7117c2d2002-07-17 14:10:11 +00008547 {
Chet Rameyac50fba2014-02-26 09:36:43 -05008548 size_t j;
Jari Aalto7117c2d2002-07-17 14:10:11 +00008549 for (j = i; j < len; j++)
8550 shell_input_line_property[j] = 1;
8551 break;
8552 }
8553
8554 mbclen = mbrlen (shell_input_line + previ, i - previ + 1, &mbs);
8555 if (mbclen == 1 || mbclen == (size_t)-1)
8556 {
8557 mbclen = 1;
8558 previ = i + 1;
8559 }
8560 else if (mbclen == (size_t)-2)
8561 mbclen = 0;
8562 else if (mbclen > 1)
8563 {
8564 mbclen = 0;
8565 previ = i + 1;
8566 prevs = mbs;
8567 }
8568 else
8569 {
Jari Aaltob80f6442004-07-27 13:29:18 +00008570 /* XXX - what to do if mbrlen returns 0? (null wide character) */
Chet Rameyac50fba2014-02-26 09:36:43 -05008571 size_t j;
Jari Aaltob80f6442004-07-27 13:29:18 +00008572 for (j = i; j < len; j++)
8573 shell_input_line_property[j] = 1;
8574 break;
Jari Aalto7117c2d2002-07-17 14:10:11 +00008575 }
8576
8577 shell_input_line_property[i] = mbclen;
8578 }
8579}
8580#endif /* HANDLE_MULTIBYTE */
Chet Ramey90a39f32014-10-02 09:07:21 -04008581