Line | Count | Source (jump to first uncovered line) |
1 | | /* A Bison parser, made by GNU Bison 3.5.1. */ |
2 | | |
3 | | /* Bison implementation for Yacc-like parsers in C |
4 | | |
5 | | Copyright (C) 1984, 1989-1990, 2000-2015, 2018-2020 Free Software Foundation, |
6 | | Inc. |
7 | | |
8 | | This program is free software: you can redistribute it and/or modify |
9 | | it under the terms of the GNU General Public License as published by |
10 | | the Free Software Foundation, either version 3 of the License, or |
11 | | (at your option) any later version. |
12 | | |
13 | | This program is distributed in the hope that it will be useful, |
14 | | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | | GNU General Public License for more details. |
17 | | |
18 | | You should have received a copy of the GNU General Public License |
19 | | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
20 | | |
21 | | /* As a special exception, you may create a larger work that contains |
22 | | part or all of the Bison parser skeleton and distribute that work |
23 | | under terms of your choice, so long as that work isn't itself a |
24 | | parser generator using the skeleton or a modified version thereof |
25 | | as a parser skeleton. Alternatively, if you modify or redistribute |
26 | | the parser skeleton itself, you may (at your option) remove this |
27 | | special exception, which will cause the skeleton and the resulting |
28 | | Bison output files to be licensed under the GNU General Public |
29 | | License without this special exception. |
30 | | |
31 | | This special exception was added by the Free Software Foundation in |
32 | | version 2.2 of Bison. */ |
33 | | |
34 | | /* C LALR(1) parser skeleton written by Richard Stallman, by |
35 | | simplifying the original so-called "semantic" parser. */ |
36 | | |
37 | | /* All symbols defined below should begin with yy or YY, to avoid |
38 | | infringing on user name space. This should be done even for local |
39 | | variables, as they might otherwise be expanded by user macros. |
40 | | There are some unavoidable exceptions within include files to |
41 | | define necessary library symbols; they are noted "INFRINGES ON |
42 | | USER NAME SPACE" below. */ |
43 | | |
44 | | /* Undocumented macros, especially those whose name start with YY_, |
45 | | are private implementation details. Do not rely on them. */ |
46 | | |
47 | | /* Identify Bison output. */ |
48 | | #define YYBISON 1 |
49 | | |
50 | | /* Bison version. */ |
51 | | #define YYBISON_VERSION "3.5.1" |
52 | | |
53 | | /* Skeleton name. */ |
54 | | #define YYSKELETON_NAME "yacc.c" |
55 | | |
56 | | /* Pure parsers. */ |
57 | | #define YYPURE 0 |
58 | | |
59 | | /* Push parsers. */ |
60 | | #define YYPUSH 0 |
61 | | |
62 | | /* Pull parsers. */ |
63 | | #define YYPULL 1 |
64 | | |
65 | | |
66 | | |
67 | | |
68 | | /* First part of user prologue. */ |
69 | | #line 19 "cmd-parse.y" |
70 | | |
71 | | |
72 | | #include <sys/types.h> |
73 | | |
74 | | #include <ctype.h> |
75 | | #include <errno.h> |
76 | | #include <pwd.h> |
77 | | #include <stdlib.h> |
78 | | #include <string.h> |
79 | | #include <unistd.h> |
80 | | #include <wchar.h> |
81 | | |
82 | | #include "tmux.h" |
83 | | |
84 | | static int yylex(void); |
85 | | static int yyparse(void); |
86 | | static void printflike(1,2) yyerror(const char *, ...); |
87 | | |
88 | | static char *yylex_token(int); |
89 | | static char *yylex_format(void); |
90 | | |
91 | | struct cmd_parse_scope { |
92 | | int flag; |
93 | | TAILQ_ENTRY (cmd_parse_scope) entry; |
94 | | }; |
95 | | |
96 | | enum cmd_parse_argument_type { |
97 | | CMD_PARSE_STRING, |
98 | | CMD_PARSE_COMMANDS, |
99 | | CMD_PARSE_PARSED_COMMANDS |
100 | | }; |
101 | | |
102 | | struct cmd_parse_argument { |
103 | | enum cmd_parse_argument_type type; |
104 | | char *string; |
105 | | struct cmd_parse_commands *commands; |
106 | | struct cmd_list *cmdlist; |
107 | | |
108 | | TAILQ_ENTRY(cmd_parse_argument) entry; |
109 | | }; |
110 | | TAILQ_HEAD(cmd_parse_arguments, cmd_parse_argument); |
111 | | |
112 | | struct cmd_parse_command { |
113 | | u_int line; |
114 | | struct cmd_parse_arguments arguments; |
115 | | |
116 | | TAILQ_ENTRY(cmd_parse_command) entry; |
117 | | }; |
118 | | TAILQ_HEAD(cmd_parse_commands, cmd_parse_command); |
119 | | |
120 | | struct cmd_parse_state { |
121 | | FILE *f; |
122 | | |
123 | | const char *buf; |
124 | | size_t len; |
125 | | size_t off; |
126 | | |
127 | | int condition; |
128 | | int eol; |
129 | | int eof; |
130 | | struct cmd_parse_input *input; |
131 | | u_int escapes; |
132 | | |
133 | | char *error; |
134 | | struct cmd_parse_commands *commands; |
135 | | |
136 | | struct cmd_parse_scope *scope; |
137 | | TAILQ_HEAD(, cmd_parse_scope) stack; |
138 | | }; |
139 | | static struct cmd_parse_state parse_state; |
140 | | |
141 | | static char *cmd_parse_get_error(const char *, u_int, const char *); |
142 | | static void cmd_parse_free_command(struct cmd_parse_command *); |
143 | | static struct cmd_parse_commands *cmd_parse_new_commands(void); |
144 | | static void cmd_parse_free_commands(struct cmd_parse_commands *); |
145 | | static void cmd_parse_build_commands(struct cmd_parse_commands *, |
146 | | struct cmd_parse_input *, struct cmd_parse_result *); |
147 | | static void cmd_parse_print_commands(struct cmd_parse_input *, |
148 | | struct cmd_list *); |
149 | | |
150 | | |
151 | | #line 152 "cmd-parse.c" |
152 | | |
153 | | # ifndef YY_CAST |
154 | | # ifdef __cplusplus |
155 | | # define YY_CAST(Type, Val) static_cast<Type> (Val) |
156 | | # define YY_REINTERPRET_CAST(Type, Val) reinterpret_cast<Type> (Val) |
157 | | # else |
158 | 20 | # define YY_CAST(Type, Val) ((Type) (Val)) |
159 | | # define YY_REINTERPRET_CAST(Type, Val) ((Type) (Val)) |
160 | | # endif |
161 | | # endif |
162 | | # ifndef YY_NULLPTR |
163 | | # if defined __cplusplus |
164 | | # if 201103L <= __cplusplus |
165 | | # define YY_NULLPTR nullptr |
166 | | # else |
167 | | # define YY_NULLPTR 0 |
168 | | # endif |
169 | | # else |
170 | | # define YY_NULLPTR ((void*)0) |
171 | | # endif |
172 | | # endif |
173 | | |
174 | | /* Enabling verbose error messages. */ |
175 | | #ifdef YYERROR_VERBOSE |
176 | | # undef YYERROR_VERBOSE |
177 | | # define YYERROR_VERBOSE 1 |
178 | | #else |
179 | | # define YYERROR_VERBOSE 0 |
180 | | #endif |
181 | | |
182 | | |
183 | | /* Debug traces. */ |
184 | | #ifndef YYDEBUG |
185 | | # define YYDEBUG 0 |
186 | | #endif |
187 | | #if YYDEBUG |
188 | | extern int yydebug; |
189 | | #endif |
190 | | |
191 | | /* Token type. */ |
192 | | #ifndef YYTOKENTYPE |
193 | | # define YYTOKENTYPE |
194 | | enum yytokentype |
195 | | { |
196 | | ERROR = 258, |
197 | | HIDDEN = 259, |
198 | | IF = 260, |
199 | | ELSE = 261, |
200 | | ELIF = 262, |
201 | | ENDIF = 263, |
202 | | FORMAT = 264, |
203 | | TOKEN = 265, |
204 | | EQUALS = 266 |
205 | | }; |
206 | | #endif |
207 | | /* Tokens. */ |
208 | 0 | #define ERROR 258 |
209 | 0 | #define HIDDEN 259 |
210 | 0 | #define IF 260 |
211 | 0 | #define ELSE 261 |
212 | 0 | #define ELIF 262 |
213 | 0 | #define ENDIF 263 |
214 | 0 | #define FORMAT 264 |
215 | 2 | #define TOKEN 265 |
216 | 0 | #define EQUALS 266 |
217 | | |
218 | | /* Value type. */ |
219 | | #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED |
220 | | union YYSTYPE |
221 | | { |
222 | | #line 102 "cmd-parse.y" |
223 | | |
224 | | char *token; |
225 | | struct cmd_parse_arguments *arguments; |
226 | | struct cmd_parse_argument *argument; |
227 | | int flag; |
228 | | struct { |
229 | | int flag; |
230 | | struct cmd_parse_commands *commands; |
231 | | } elif; |
232 | | struct cmd_parse_commands *commands; |
233 | | struct cmd_parse_command *command; |
234 | | |
235 | | #line 236 "cmd-parse.c" |
236 | | |
237 | | }; |
238 | | typedef union YYSTYPE YYSTYPE; |
239 | | # define YYSTYPE_IS_TRIVIAL 1 |
240 | | # define YYSTYPE_IS_DECLARED 1 |
241 | | #endif |
242 | | |
243 | | |
244 | | extern YYSTYPE yylval; |
245 | | |
246 | | int yyparse (void); |
247 | | |
248 | | |
249 | | |
250 | | |
251 | | |
252 | | #ifdef short |
253 | | # undef short |
254 | | #endif |
255 | | |
256 | | /* On compilers that do not define __PTRDIFF_MAX__ etc., make sure |
257 | | <limits.h> and (if available) <stdint.h> are included |
258 | | so that the code can choose integer types of a good width. */ |
259 | | |
260 | | #ifndef __PTRDIFF_MAX__ |
261 | | # include <limits.h> /* INFRINGES ON USER NAME SPACE */ |
262 | | # if defined __STDC_VERSION__ && 199901 <= __STDC_VERSION__ |
263 | | # include <stdint.h> /* INFRINGES ON USER NAME SPACE */ |
264 | | # define YY_STDINT_H |
265 | | # endif |
266 | | #endif |
267 | | |
268 | | /* Narrow types that promote to a signed type and that can represent a |
269 | | signed or unsigned integer of at least N bits. In tables they can |
270 | | save space and decrease cache pressure. Promoting to a signed type |
271 | | helps avoid bugs in integer arithmetic. */ |
272 | | |
273 | | #ifdef __INT_LEAST8_MAX__ |
274 | | typedef __INT_LEAST8_TYPE__ yytype_int8; |
275 | | #elif defined YY_STDINT_H |
276 | | typedef int_least8_t yytype_int8; |
277 | | #else |
278 | | typedef signed char yytype_int8; |
279 | | #endif |
280 | | |
281 | | #ifdef __INT_LEAST16_MAX__ |
282 | | typedef __INT_LEAST16_TYPE__ yytype_int16; |
283 | | #elif defined YY_STDINT_H |
284 | | typedef int_least16_t yytype_int16; |
285 | | #else |
286 | | typedef short yytype_int16; |
287 | | #endif |
288 | | |
289 | | #if defined __UINT_LEAST8_MAX__ && __UINT_LEAST8_MAX__ <= __INT_MAX__ |
290 | | typedef __UINT_LEAST8_TYPE__ yytype_uint8; |
291 | | #elif (!defined __UINT_LEAST8_MAX__ && defined YY_STDINT_H \ |
292 | | && UINT_LEAST8_MAX <= INT_MAX) |
293 | | typedef uint_least8_t yytype_uint8; |
294 | | #elif !defined __UINT_LEAST8_MAX__ && UCHAR_MAX <= INT_MAX |
295 | | typedef unsigned char yytype_uint8; |
296 | | #else |
297 | | typedef short yytype_uint8; |
298 | | #endif |
299 | | |
300 | | #if defined __UINT_LEAST16_MAX__ && __UINT_LEAST16_MAX__ <= __INT_MAX__ |
301 | | typedef __UINT_LEAST16_TYPE__ yytype_uint16; |
302 | | #elif (!defined __UINT_LEAST16_MAX__ && defined YY_STDINT_H \ |
303 | | && UINT_LEAST16_MAX <= INT_MAX) |
304 | | typedef uint_least16_t yytype_uint16; |
305 | | #elif !defined __UINT_LEAST16_MAX__ && USHRT_MAX <= INT_MAX |
306 | | typedef unsigned short yytype_uint16; |
307 | | #else |
308 | | typedef int yytype_uint16; |
309 | | #endif |
310 | | |
311 | | #ifndef YYPTRDIFF_T |
312 | | # if defined __PTRDIFF_TYPE__ && defined __PTRDIFF_MAX__ |
313 | 2 | # define YYPTRDIFF_T __PTRDIFF_TYPE__ |
314 | | # define YYPTRDIFF_MAXIMUM __PTRDIFF_MAX__ |
315 | | # elif defined PTRDIFF_MAX |
316 | | # ifndef ptrdiff_t |
317 | | # include <stddef.h> /* INFRINGES ON USER NAME SPACE */ |
318 | | # endif |
319 | | # define YYPTRDIFF_T ptrdiff_t |
320 | | # define YYPTRDIFF_MAXIMUM PTRDIFF_MAX |
321 | | # else |
322 | | # define YYPTRDIFF_T long |
323 | | # define YYPTRDIFF_MAXIMUM LONG_MAX |
324 | | # endif |
325 | | #endif |
326 | | |
327 | | #ifndef YYSIZE_T |
328 | | # ifdef __SIZE_TYPE__ |
329 | | # define YYSIZE_T __SIZE_TYPE__ |
330 | | # elif defined size_t |
331 | | # define YYSIZE_T size_t |
332 | | # elif defined __STDC_VERSION__ && 199901 <= __STDC_VERSION__ |
333 | | # include <stddef.h> /* INFRINGES ON USER NAME SPACE */ |
334 | | # define YYSIZE_T size_t |
335 | | # else |
336 | | # define YYSIZE_T unsigned |
337 | | # endif |
338 | | #endif |
339 | | |
340 | | #define YYSIZE_MAXIMUM \ |
341 | | YY_CAST (YYPTRDIFF_T, \ |
342 | | (YYPTRDIFF_MAXIMUM < YY_CAST (YYSIZE_T, -1) \ |
343 | | ? YYPTRDIFF_MAXIMUM \ |
344 | | : YY_CAST (YYSIZE_T, -1))) |
345 | | |
346 | 0 | #define YYSIZEOF(X) YY_CAST (YYPTRDIFF_T, sizeof (X)) |
347 | | |
348 | | /* Stored state numbers (used for stacks). */ |
349 | | typedef yytype_int8 yy_state_t; |
350 | | |
351 | | /* State numbers in computations. */ |
352 | | typedef int yy_state_fast_t; |
353 | | |
354 | | #ifndef YY_ |
355 | | # if defined YYENABLE_NLS && YYENABLE_NLS |
356 | | # if ENABLE_NLS |
357 | | # include <libintl.h> /* INFRINGES ON USER NAME SPACE */ |
358 | | # define YY_(Msgid) dgettext ("bison-runtime", Msgid) |
359 | | # endif |
360 | | # endif |
361 | | # ifndef YY_ |
362 | 0 | # define YY_(Msgid) Msgid |
363 | | # endif |
364 | | #endif |
365 | | |
366 | | #ifndef YY_ATTRIBUTE_PURE |
367 | | # if defined __GNUC__ && 2 < __GNUC__ + (96 <= __GNUC_MINOR__) |
368 | | # define YY_ATTRIBUTE_PURE __attribute__ ((__pure__)) |
369 | | # else |
370 | | # define YY_ATTRIBUTE_PURE |
371 | | # endif |
372 | | #endif |
373 | | |
374 | | #ifndef YY_ATTRIBUTE_UNUSED |
375 | | # if defined __GNUC__ && 2 < __GNUC__ + (7 <= __GNUC_MINOR__) |
376 | | # define YY_ATTRIBUTE_UNUSED __attribute__ ((__unused__)) |
377 | | # else |
378 | | # define YY_ATTRIBUTE_UNUSED |
379 | | # endif |
380 | | #endif |
381 | | |
382 | | /* Suppress unused-variable warnings by "using" E. */ |
383 | | #if ! defined lint || defined __GNUC__ |
384 | 8 | # define YYUSE(E) ((void) (E)) |
385 | | #else |
386 | | # define YYUSE(E) /* empty */ |
387 | | #endif |
388 | | |
389 | | #if defined __GNUC__ && ! defined __ICC && 407 <= __GNUC__ * 100 + __GNUC_MINOR__ |
390 | | /* Suppress an incorrect diagnostic about yylval being uninitialized. */ |
391 | | # define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \ |
392 | | _Pragma ("GCC diagnostic push") \ |
393 | | _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"") \ |
394 | | _Pragma ("GCC diagnostic ignored \"-Wmaybe-uninitialized\"") |
395 | | # define YY_IGNORE_MAYBE_UNINITIALIZED_END \ |
396 | | _Pragma ("GCC diagnostic pop") |
397 | | #else |
398 | | # define YY_INITIAL_VALUE(Value) Value |
399 | | #endif |
400 | | #ifndef YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN |
401 | | # define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN |
402 | | # define YY_IGNORE_MAYBE_UNINITIALIZED_END |
403 | | #endif |
404 | | #ifndef YY_INITIAL_VALUE |
405 | | # define YY_INITIAL_VALUE(Value) /* Nothing. */ |
406 | | #endif |
407 | | |
408 | | #if defined __cplusplus && defined __GNUC__ && ! defined __ICC && 6 <= __GNUC__ |
409 | | # define YY_IGNORE_USELESS_CAST_BEGIN \ |
410 | | _Pragma ("GCC diagnostic push") \ |
411 | | _Pragma ("GCC diagnostic ignored \"-Wuseless-cast\"") |
412 | | # define YY_IGNORE_USELESS_CAST_END \ |
413 | | _Pragma ("GCC diagnostic pop") |
414 | | #endif |
415 | | #ifndef YY_IGNORE_USELESS_CAST_BEGIN |
416 | | # define YY_IGNORE_USELESS_CAST_BEGIN |
417 | | # define YY_IGNORE_USELESS_CAST_END |
418 | | #endif |
419 | | |
420 | | |
421 | 20 | #define YY_ASSERT(E) ((void) (0 && (E))) |
422 | | |
423 | | #if ! defined yyoverflow || YYERROR_VERBOSE |
424 | | |
425 | | /* The parser invokes alloca or malloc; define the necessary symbols. */ |
426 | | |
427 | | # ifdef YYSTACK_USE_ALLOCA |
428 | | # if YYSTACK_USE_ALLOCA |
429 | | # ifdef __GNUC__ |
430 | | # define YYSTACK_ALLOC __builtin_alloca |
431 | | # elif defined __BUILTIN_VA_ARG_INCR |
432 | | # include <alloca.h> /* INFRINGES ON USER NAME SPACE */ |
433 | | # elif defined _AIX |
434 | | # define YYSTACK_ALLOC __alloca |
435 | | # elif defined _MSC_VER |
436 | | # include <malloc.h> /* INFRINGES ON USER NAME SPACE */ |
437 | | # define alloca _alloca |
438 | | # else |
439 | | # define YYSTACK_ALLOC alloca |
440 | | # if ! defined _ALLOCA_H && ! defined EXIT_SUCCESS |
441 | | # include <stdlib.h> /* INFRINGES ON USER NAME SPACE */ |
442 | | /* Use EXIT_SUCCESS as a witness for stdlib.h. */ |
443 | | # ifndef EXIT_SUCCESS |
444 | | # define EXIT_SUCCESS 0 |
445 | | # endif |
446 | | # endif |
447 | | # endif |
448 | | # endif |
449 | | # endif |
450 | | |
451 | | # ifdef YYSTACK_ALLOC |
452 | | /* Pacify GCC's 'empty if-body' warning. */ |
453 | | # define YYSTACK_FREE(Ptr) do { /* empty */; } while (0) |
454 | | # ifndef YYSTACK_ALLOC_MAXIMUM |
455 | | /* The OS might guarantee only one guard page at the bottom of the stack, |
456 | | and a page size can be as small as 4096 bytes. So we cannot safely |
457 | | invoke alloca (N) if N exceeds 4096. Use a slightly smaller number |
458 | | to allow for a few compiler-allocated temporary stack slots. */ |
459 | | # define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */ |
460 | | # endif |
461 | | # else |
462 | | # define YYSTACK_ALLOC YYMALLOC |
463 | 0 | # define YYSTACK_FREE YYFREE |
464 | | # ifndef YYSTACK_ALLOC_MAXIMUM |
465 | | # define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM |
466 | | # endif |
467 | | # if (defined __cplusplus && ! defined EXIT_SUCCESS \ |
468 | | && ! ((defined YYMALLOC || defined malloc) \ |
469 | | && (defined YYFREE || defined free))) |
470 | | # include <stdlib.h> /* INFRINGES ON USER NAME SPACE */ |
471 | | # ifndef EXIT_SUCCESS |
472 | | # define EXIT_SUCCESS 0 |
473 | | # endif |
474 | | # endif |
475 | | # ifndef YYMALLOC |
476 | | # define YYMALLOC malloc |
477 | | # if ! defined malloc && ! defined EXIT_SUCCESS |
478 | | void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */ |
479 | | # endif |
480 | | # endif |
481 | | # ifndef YYFREE |
482 | 0 | # define YYFREE free |
483 | | # if ! defined free && ! defined EXIT_SUCCESS |
484 | | void free (void *); /* INFRINGES ON USER NAME SPACE */ |
485 | | # endif |
486 | | # endif |
487 | | # endif |
488 | | #endif /* ! defined yyoverflow || YYERROR_VERBOSE */ |
489 | | |
490 | | |
491 | | #if (! defined yyoverflow \ |
492 | | && (! defined __cplusplus \ |
493 | | || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL))) |
494 | | |
495 | | /* A type that is properly aligned for any stack member. */ |
496 | | union yyalloc |
497 | | { |
498 | | yy_state_t yyss_alloc; |
499 | | YYSTYPE yyvs_alloc; |
500 | | }; |
501 | | |
502 | | /* The size of the maximum gap between one aligned stack and the next. */ |
503 | 0 | # define YYSTACK_GAP_MAXIMUM (YYSIZEOF (union yyalloc) - 1) |
504 | | |
505 | | /* The size of an array large to enough to hold all stacks, each with |
506 | | N elements. */ |
507 | | # define YYSTACK_BYTES(N) \ |
508 | | ((N) * (YYSIZEOF (yy_state_t) + YYSIZEOF (YYSTYPE)) \ |
509 | | + YYSTACK_GAP_MAXIMUM) |
510 | | |
511 | | # define YYCOPY_NEEDED 1 |
512 | | |
513 | | /* Relocate STACK from its old location to the new one. The |
514 | | local variables YYSIZE and YYSTACKSIZE give the old and new number of |
515 | | elements in the stack, and YYPTR gives the new location of the |
516 | | stack. Advance YYPTR to a properly aligned location for the next |
517 | | stack. */ |
518 | | # define YYSTACK_RELOCATE(Stack_alloc, Stack) \ |
519 | 0 | do \ |
520 | 0 | { \ |
521 | 0 | YYPTRDIFF_T yynewbytes; \ |
522 | 0 | YYCOPY (&yyptr->Stack_alloc, Stack, yysize); \ |
523 | 0 | Stack = &yyptr->Stack_alloc; \ |
524 | 0 | yynewbytes = yystacksize * YYSIZEOF (*Stack) + YYSTACK_GAP_MAXIMUM; \ |
525 | 0 | yyptr += yynewbytes / YYSIZEOF (*yyptr); \ |
526 | 0 | } \ |
527 | 0 | while (0) |
528 | | |
529 | | #endif |
530 | | |
531 | | #if defined YYCOPY_NEEDED && YYCOPY_NEEDED |
532 | | /* Copy COUNT objects from SRC to DST. The source and destination do |
533 | | not overlap. */ |
534 | | # ifndef YYCOPY |
535 | | # if defined __GNUC__ && 1 < __GNUC__ |
536 | | # define YYCOPY(Dst, Src, Count) \ |
537 | 0 | __builtin_memcpy (Dst, Src, YY_CAST (YYSIZE_T, (Count)) * sizeof (*(Src))) |
538 | | # else |
539 | | # define YYCOPY(Dst, Src, Count) \ |
540 | | do \ |
541 | | { \ |
542 | | YYPTRDIFF_T yyi; \ |
543 | | for (yyi = 0; yyi < (Count); yyi++) \ |
544 | | (Dst)[yyi] = (Src)[yyi]; \ |
545 | | } \ |
546 | | while (0) |
547 | | # endif |
548 | | # endif |
549 | | #endif /* !YYCOPY_NEEDED */ |
550 | | |
551 | | /* YYFINAL -- State number of the termination state. */ |
552 | 20 | #define YYFINAL 20 |
553 | | /* YYLAST -- Last index in YYTABLE. */ |
554 | 28 | #define YYLAST 104 |
555 | | |
556 | | /* YYNTOKENS -- Number of terminals. */ |
557 | 12 | #define YYNTOKENS 16 |
558 | | /* YYNNTS -- Number of nonterminals. */ |
559 | | #define YYNNTS 22 |
560 | | /* YYNRULES -- Number of rules. */ |
561 | | #define YYNRULES 47 |
562 | | /* YYNSTATES -- Number of states. */ |
563 | | #define YYNSTATES 75 |
564 | | |
565 | 0 | #define YYUNDEFTOK 2 |
566 | 10 | #define YYMAXUTOK 266 |
567 | | |
568 | | |
569 | | /* YYTRANSLATE(TOKEN-NUM) -- Symbol number corresponding to TOKEN-NUM |
570 | | as returned by yylex, with out-of-bounds checking. */ |
571 | | #define YYTRANSLATE(YYX) \ |
572 | 10 | (0 <= (YYX) && (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK) |
573 | | |
574 | | /* YYTRANSLATE[TOKEN-NUM] -- Symbol number corresponding to TOKEN-NUM |
575 | | as returned by yylex. */ |
576 | | static const yytype_int8 yytranslate[] = |
577 | | { |
578 | | 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
579 | | 12, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
580 | | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
581 | | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
582 | | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
583 | | 2, 2, 2, 2, 2, 2, 2, 2, 2, 13, |
584 | | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
585 | | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
586 | | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
587 | | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
588 | | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
589 | | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
590 | | 2, 2, 2, 14, 2, 15, 2, 2, 2, 2, |
591 | | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
592 | | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
593 | | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
594 | | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
595 | | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
596 | | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
597 | | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
598 | | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
599 | | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
600 | | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
601 | | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
602 | | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
603 | | 2, 2, 2, 2, 2, 2, 1, 2, 3, 4, |
604 | | 5, 6, 7, 8, 9, 10, 11 |
605 | | }; |
606 | | |
607 | | #if YYDEBUG |
608 | | /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */ |
609 | | static const yytype_int16 yyrline[] = |
610 | | { |
611 | | 0, 134, 134, 135, 142, 146, 154, 158, 163, 174, |
612 | | 186, 190, 195, 219, 220, 222, 240, 258, 272, 284, |
613 | | 297, 307, 316, 326, 340, 357, 368, 386, 397, 401, |
614 | | 407, 421, 426, 434, 448, 466, 475, 485, 499, 516, |
615 | | 527, 545, 552, 558, 564, 570, 577, 581 |
616 | | }; |
617 | | #endif |
618 | | |
619 | | #if YYDEBUG || YYERROR_VERBOSE || 0 |
620 | | /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM. |
621 | | First, the terminals, then, starting at YYNTOKENS, nonterminals. */ |
622 | | static const char *const yytname[] = |
623 | | { |
624 | | "$end", "error", "$undefined", "ERROR", "HIDDEN", "IF", "ELSE", "ELIF", |
625 | | "ENDIF", "FORMAT", "TOKEN", "EQUALS", "'\\n'", "';'", "'{'", "'}'", |
626 | | "$accept", "lines", "statements", "statement", "format", "expanded", |
627 | | "optional_assignment", "assignment", "hidden_assignment", "if_open", |
628 | | "if_else", "if_elif", "if_close", "condition", "elif", "commands", |
629 | | "command", "condition1", "elif1", "arguments", "argument", |
630 | | "argument_statements", YY_NULLPTR |
631 | | }; |
632 | | #endif |
633 | | |
634 | | # ifdef YYPRINT |
635 | | /* YYTOKNUM[NUM] -- (External) token number corresponding to the |
636 | | (internal) symbol number NUM (which must be that of a token). */ |
637 | | static const yytype_int16 yytoknum[] = |
638 | | { |
639 | | 0, 256, 257, 258, 259, 260, 261, 262, 263, 264, |
640 | | 265, 266, 10, 59, 123, 125 |
641 | | }; |
642 | | # endif |
643 | | |
644 | 18 | #define YYPACT_NINF (-32) |
645 | | |
646 | | #define yypact_value_is_default(Yyn) \ |
647 | 18 | ((Yyn) == YYPACT_NINF) |
648 | | |
649 | | #define YYTABLE_NINF (-15) |
650 | | |
651 | | #define yytable_value_is_error(Yyn) \ |
652 | 2 | 0 |
653 | | |
654 | | /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing |
655 | | STATE-NUM. */ |
656 | | static const yytype_int8 yypact[] = |
657 | | { |
658 | | 49, 3, 14, -32, 33, 49, 29, 47, 60, -32, |
659 | | 4, -32, 35, -32, -32, -32, -32, -32, -32, -32, |
660 | | -32, 68, -32, 83, 81, 38, 5, 17, -32, -32, |
661 | | -32, 81, -32, 83, 71, -32, 14, -32, 38, 38, |
662 | | -32, -1, -32, -32, 81, 40, -32, -32, 76, 86, |
663 | | -32, -1, -32, 32, 58, 38, -32, 84, -32, 81, |
664 | | 81, 88, -32, -32, -32, 32, -32, 79, 62, 81, |
665 | | -32, -32, -32, 79, -32 |
666 | | }; |
667 | | |
668 | | /* YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM. |
669 | | Performed when YYTABLE does not specify something else to do. Zero |
670 | | means the default is an error. */ |
671 | | static const yytype_int8 yydefact[] = |
672 | | { |
673 | | 2, 0, 0, 15, 0, 3, 0, 0, 32, 7, |
674 | | 13, 8, 9, 27, 31, 16, 10, 11, 12, 17, |
675 | | 1, 0, 4, 33, 6, 13, 0, 28, 5, 43, |
676 | | 44, 6, 34, 41, 6, 18, 0, 20, 13, 13, |
677 | | 35, 0, 30, 29, 6, 0, 45, 42, 0, 0, |
678 | | 21, 0, 19, 0, 39, 13, 37, 0, 46, 6, |
679 | | 6, 0, 23, 36, 40, 0, 47, 6, 25, 6, |
680 | | 38, 22, 26, 6, 24 |
681 | | }; |
682 | | |
683 | | /* YYPGOTO[NTERM-NUM]. */ |
684 | | static const yytype_int8 yypgoto[] = |
685 | | { |
686 | | -32, -32, -23, -5, -32, 59, -32, -32, -32, -8, |
687 | | -31, -30, -9, -32, -18, -4, 74, 75, 50, 70, |
688 | | -32, -32 |
689 | | }; |
690 | | |
691 | | /* YYDEFGOTO[NTERM-NUM]. */ |
692 | | static const yytype_int8 yydefgoto[] = |
693 | | { |
694 | | -1, 4, 5, 6, 18, 19, 7, 8, 9, 10, |
695 | | 38, 39, 40, 11, 51, 12, 13, 14, 41, 32, |
696 | | 33, 46 |
697 | | }; |
698 | | |
699 | | /* YYTABLE[YYPACT[STATE-NUM]] -- What to do in state STATE-NUM. If |
700 | | positive, shift that token. If negative, reduce the rule whose |
701 | | number is the opposite. If YYTABLE_NINF, syntax error. */ |
702 | | static const yytype_int8 yytable[] = |
703 | | { |
704 | | 21, 34, 25, 48, 49, 35, 26, 37, 44, 2, |
705 | | 55, 35, 36, 37, 15, 3, 24, 25, 27, 25, |
706 | | 61, 26, 2, 16, 17, 50, 45, -13, 3, 21, |
707 | | 25, 25, 56, 20, 53, 54, 67, 68, 49, 57, |
708 | | 37, 22, 62, 2, 63, 27, 73, 25, 27, 3, |
709 | | 72, 65, 22, 1, 2, 58, 70, 23, 71, -13, |
710 | | 3, -6, 21, 21, 74, 36, 1, 2, 21, 36, |
711 | | -14, 27, -13, 3, -6, 1, 2, 35, 36, 37, |
712 | | 28, -13, 3, 1, 2, 1, 2, 37, 59, -13, |
713 | | 3, -13, 3, 29, 30, 52, 28, 31, 60, 66, |
714 | | 69, 42, 43, 47, 64 |
715 | | }; |
716 | | |
717 | | static const yytype_int8 yycheck[] = |
718 | | { |
719 | | 5, 24, 10, 34, 34, 6, 10, 8, 31, 5, |
720 | | 41, 6, 7, 8, 11, 11, 12, 25, 13, 27, |
721 | | 51, 25, 5, 9, 10, 34, 31, 10, 11, 34, |
722 | | 38, 39, 41, 0, 38, 39, 59, 60, 68, 44, |
723 | | 8, 12, 51, 5, 53, 13, 69, 55, 13, 11, |
724 | | 68, 55, 12, 4, 5, 15, 65, 10, 67, 10, |
725 | | 11, 12, 67, 68, 73, 7, 4, 5, 73, 7, |
726 | | 10, 13, 10, 11, 12, 4, 5, 6, 7, 8, |
727 | | 12, 10, 11, 4, 5, 4, 5, 8, 12, 10, |
728 | | 11, 10, 11, 10, 11, 36, 12, 14, 12, 15, |
729 | | 12, 27, 27, 33, 54 |
730 | | }; |
731 | | |
732 | | /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing |
733 | | symbol of state STATE-NUM. */ |
734 | | static const yytype_int8 yystos[] = |
735 | | { |
736 | | 0, 4, 5, 11, 17, 18, 19, 22, 23, 24, |
737 | | 25, 29, 31, 32, 33, 11, 9, 10, 20, 21, |
738 | | 0, 19, 12, 10, 12, 25, 31, 13, 12, 10, |
739 | | 11, 14, 35, 36, 18, 6, 7, 8, 26, 27, |
740 | | 28, 34, 32, 33, 18, 19, 37, 35, 26, 27, |
741 | | 28, 30, 21, 31, 31, 26, 28, 19, 15, 12, |
742 | | 12, 26, 28, 28, 34, 31, 15, 18, 18, 12, |
743 | | 28, 28, 30, 18, 28 |
744 | | }; |
745 | | |
746 | | /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */ |
747 | | static const yytype_int8 yyr1[] = |
748 | | { |
749 | | 0, 16, 17, 17, 18, 18, 19, 19, 19, 19, |
750 | | 20, 20, 21, 22, 22, 23, 24, 25, 26, 27, |
751 | | 28, 29, 29, 29, 29, 30, 30, 31, 31, 31, |
752 | | 31, 31, 32, 32, 32, 33, 33, 33, 33, 34, |
753 | | 34, 35, 35, 36, 36, 36, 37, 37 |
754 | | }; |
755 | | |
756 | | /* YYR2[YYN] -- Number of symbols on the right hand side of rule YYN. */ |
757 | | static const yytype_int8 yyr2[] = |
758 | | { |
759 | | 0, 2, 0, 1, 2, 3, 0, 1, 1, 1, |
760 | | 1, 1, 1, 0, 1, 1, 2, 2, 1, 2, |
761 | | 1, 4, 7, 5, 8, 3, 4, 1, 2, 3, |
762 | | 3, 1, 1, 2, 3, 3, 5, 4, 6, 2, |
763 | | 3, 1, 2, 1, 1, 2, 2, 3 |
764 | | }; |
765 | | |
766 | | |
767 | | #define yyerrok (yyerrstatus = 0) |
768 | | #define yyclearin (yychar = YYEMPTY) |
769 | 24 | #define YYEMPTY (-2) |
770 | 18 | #define YYEOF 0 |
771 | | |
772 | 2 | #define YYACCEPT goto yyacceptlab |
773 | 0 | #define YYABORT goto yyabortlab |
774 | 0 | #define YYERROR goto yyerrorlab |
775 | | |
776 | | |
777 | | #define YYRECOVERING() (!!yyerrstatus) |
778 | | |
779 | | #define YYBACKUP(Token, Value) \ |
780 | | do \ |
781 | | if (yychar == YYEMPTY) \ |
782 | | { \ |
783 | | yychar = (Token); \ |
784 | | yylval = (Value); \ |
785 | | YYPOPSTACK (yylen); \ |
786 | | yystate = *yyssp; \ |
787 | | goto yybackup; \ |
788 | | } \ |
789 | | else \ |
790 | | { \ |
791 | | yyerror (YY_("syntax error: cannot back up")); \ |
792 | | YYERROR; \ |
793 | | } \ |
794 | | while (0) |
795 | | |
796 | | /* Error token number */ |
797 | 0 | #define YYTERROR 1 |
798 | | #define YYERRCODE 256 |
799 | | |
800 | | |
801 | | |
802 | | /* Enable debugging if requested. */ |
803 | | #if YYDEBUG |
804 | | |
805 | | # ifndef YYFPRINTF |
806 | | # include <stdio.h> /* INFRINGES ON USER NAME SPACE */ |
807 | | # define YYFPRINTF fprintf |
808 | | # endif |
809 | | |
810 | | # define YYDPRINTF(Args) \ |
811 | | do { \ |
812 | | if (yydebug) \ |
813 | | YYFPRINTF Args; \ |
814 | | } while (0) |
815 | | |
816 | | /* This macro is provided for backward compatibility. */ |
817 | | #ifndef YY_LOCATION_PRINT |
818 | | # define YY_LOCATION_PRINT(File, Loc) ((void) 0) |
819 | | #endif |
820 | | |
821 | | |
822 | | # define YY_SYMBOL_PRINT(Title, Type, Value, Location) \ |
823 | | do { \ |
824 | | if (yydebug) \ |
825 | | { \ |
826 | | YYFPRINTF (stderr, "%s ", Title); \ |
827 | | yy_symbol_print (stderr, \ |
828 | | Type, Value); \ |
829 | | YYFPRINTF (stderr, "\n"); \ |
830 | | } \ |
831 | | } while (0) |
832 | | |
833 | | |
834 | | /*-----------------------------------. |
835 | | | Print this symbol's value on YYO. | |
836 | | `-----------------------------------*/ |
837 | | |
838 | | static void |
839 | | yy_symbol_value_print (FILE *yyo, int yytype, YYSTYPE const * const yyvaluep) |
840 | | { |
841 | | FILE *yyoutput = yyo; |
842 | | YYUSE (yyoutput); |
843 | | if (!yyvaluep) |
844 | | return; |
845 | | # ifdef YYPRINT |
846 | | if (yytype < YYNTOKENS) |
847 | | YYPRINT (yyo, yytoknum[yytype], *yyvaluep); |
848 | | # endif |
849 | | YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN |
850 | | YYUSE (yytype); |
851 | | YY_IGNORE_MAYBE_UNINITIALIZED_END |
852 | | } |
853 | | |
854 | | |
855 | | /*---------------------------. |
856 | | | Print this symbol on YYO. | |
857 | | `---------------------------*/ |
858 | | |
859 | | static void |
860 | | yy_symbol_print (FILE *yyo, int yytype, YYSTYPE const * const yyvaluep) |
861 | | { |
862 | | YYFPRINTF (yyo, "%s %s (", |
863 | | yytype < YYNTOKENS ? "token" : "nterm", yytname[yytype]); |
864 | | |
865 | | yy_symbol_value_print (yyo, yytype, yyvaluep); |
866 | | YYFPRINTF (yyo, ")"); |
867 | | } |
868 | | |
869 | | /*------------------------------------------------------------------. |
870 | | | yy_stack_print -- Print the state stack from its BOTTOM up to its | |
871 | | | TOP (included). | |
872 | | `------------------------------------------------------------------*/ |
873 | | |
874 | | static void |
875 | | yy_stack_print (yy_state_t *yybottom, yy_state_t *yytop) |
876 | | { |
877 | | YYFPRINTF (stderr, "Stack now"); |
878 | | for (; yybottom <= yytop; yybottom++) |
879 | | { |
880 | | int yybot = *yybottom; |
881 | | YYFPRINTF (stderr, " %d", yybot); |
882 | | } |
883 | | YYFPRINTF (stderr, "\n"); |
884 | | } |
885 | | |
886 | | # define YY_STACK_PRINT(Bottom, Top) \ |
887 | | do { \ |
888 | | if (yydebug) \ |
889 | | yy_stack_print ((Bottom), (Top)); \ |
890 | | } while (0) |
891 | | |
892 | | |
893 | | /*------------------------------------------------. |
894 | | | Report that the YYRULE is going to be reduced. | |
895 | | `------------------------------------------------*/ |
896 | | |
897 | | static void |
898 | | yy_reduce_print (yy_state_t *yyssp, YYSTYPE *yyvsp, int yyrule) |
899 | | { |
900 | | int yylno = yyrline[yyrule]; |
901 | | int yynrhs = yyr2[yyrule]; |
902 | | int yyi; |
903 | | YYFPRINTF (stderr, "Reducing stack by rule %d (line %d):\n", |
904 | | yyrule - 1, yylno); |
905 | | /* The symbols being reduced. */ |
906 | | for (yyi = 0; yyi < yynrhs; yyi++) |
907 | | { |
908 | | YYFPRINTF (stderr, " $%d = ", yyi + 1); |
909 | | yy_symbol_print (stderr, |
910 | | yystos[+yyssp[yyi + 1 - yynrhs]], |
911 | | &yyvsp[(yyi + 1) - (yynrhs)] |
912 | | ); |
913 | | YYFPRINTF (stderr, "\n"); |
914 | | } |
915 | | } |
916 | | |
917 | | # define YY_REDUCE_PRINT(Rule) \ |
918 | | do { \ |
919 | | if (yydebug) \ |
920 | | yy_reduce_print (yyssp, yyvsp, Rule); \ |
921 | | } while (0) |
922 | | |
923 | | /* Nonzero means print parse trace. It is left uninitialized so that |
924 | | multiple parsers can coexist. */ |
925 | | int yydebug; |
926 | | #else /* !YYDEBUG */ |
927 | | # define YYDPRINTF(Args) |
928 | | # define YY_SYMBOL_PRINT(Title, Type, Value, Location) |
929 | | # define YY_STACK_PRINT(Bottom, Top) |
930 | | # define YY_REDUCE_PRINT(Rule) |
931 | | #endif /* !YYDEBUG */ |
932 | | |
933 | | |
934 | | /* YYINITDEPTH -- initial size of the parser's stacks. */ |
935 | | #ifndef YYINITDEPTH |
936 | 2 | # define YYINITDEPTH 200 |
937 | | #endif |
938 | | |
939 | | /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only |
940 | | if the built-in stack extension method is used). |
941 | | |
942 | | Do not make this value too large; the results are undefined if |
943 | | YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH) |
944 | | evaluated with infinite-precision integer arithmetic. */ |
945 | | |
946 | | #ifndef YYMAXDEPTH |
947 | 0 | # define YYMAXDEPTH 10000 |
948 | | #endif |
949 | | |
950 | | |
951 | | #if YYERROR_VERBOSE |
952 | | |
953 | | # ifndef yystrlen |
954 | | # if defined __GLIBC__ && defined _STRING_H |
955 | | # define yystrlen(S) (YY_CAST (YYPTRDIFF_T, strlen (S))) |
956 | | # else |
957 | | /* Return the length of YYSTR. */ |
958 | | static YYPTRDIFF_T |
959 | | yystrlen (const char *yystr) |
960 | | { |
961 | | YYPTRDIFF_T yylen; |
962 | | for (yylen = 0; yystr[yylen]; yylen++) |
963 | | continue; |
964 | | return yylen; |
965 | | } |
966 | | # endif |
967 | | # endif |
968 | | |
969 | | # ifndef yystpcpy |
970 | | # if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE |
971 | | # define yystpcpy stpcpy |
972 | | # else |
973 | | /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in |
974 | | YYDEST. */ |
975 | | static char * |
976 | | yystpcpy (char *yydest, const char *yysrc) |
977 | | { |
978 | | char *yyd = yydest; |
979 | | const char *yys = yysrc; |
980 | | |
981 | | while ((*yyd++ = *yys++) != '\0') |
982 | | continue; |
983 | | |
984 | | return yyd - 1; |
985 | | } |
986 | | # endif |
987 | | # endif |
988 | | |
989 | | # ifndef yytnamerr |
990 | | /* Copy to YYRES the contents of YYSTR after stripping away unnecessary |
991 | | quotes and backslashes, so that it's suitable for yyerror. The |
992 | | heuristic is that double-quoting is unnecessary unless the string |
993 | | contains an apostrophe, a comma, or backslash (other than |
994 | | backslash-backslash). YYSTR is taken from yytname. If YYRES is |
995 | | null, do not copy; instead, return the length of what the result |
996 | | would have been. */ |
997 | | static YYPTRDIFF_T |
998 | | yytnamerr (char *yyres, const char *yystr) |
999 | | { |
1000 | | if (*yystr == '"') |
1001 | | { |
1002 | | YYPTRDIFF_T yyn = 0; |
1003 | | char const *yyp = yystr; |
1004 | | |
1005 | | for (;;) |
1006 | | switch (*++yyp) |
1007 | | { |
1008 | | case '\'': |
1009 | | case ',': |
1010 | | goto do_not_strip_quotes; |
1011 | | |
1012 | | case '\\': |
1013 | | if (*++yyp != '\\') |
1014 | | goto do_not_strip_quotes; |
1015 | | else |
1016 | | goto append; |
1017 | | |
1018 | | append: |
1019 | | default: |
1020 | | if (yyres) |
1021 | | yyres[yyn] = *yyp; |
1022 | | yyn++; |
1023 | | break; |
1024 | | |
1025 | | case '"': |
1026 | | if (yyres) |
1027 | | yyres[yyn] = '\0'; |
1028 | | return yyn; |
1029 | | } |
1030 | | do_not_strip_quotes: ; |
1031 | | } |
1032 | | |
1033 | | if (yyres) |
1034 | | return yystpcpy (yyres, yystr) - yyres; |
1035 | | else |
1036 | | return yystrlen (yystr); |
1037 | | } |
1038 | | # endif |
1039 | | |
1040 | | /* Copy into *YYMSG, which is of size *YYMSG_ALLOC, an error message |
1041 | | about the unexpected token YYTOKEN for the state stack whose top is |
1042 | | YYSSP. |
1043 | | |
1044 | | Return 0 if *YYMSG was successfully written. Return 1 if *YYMSG is |
1045 | | not large enough to hold the message. In that case, also set |
1046 | | *YYMSG_ALLOC to the required number of bytes. Return 2 if the |
1047 | | required number of bytes is too large to store. */ |
1048 | | static int |
1049 | | yysyntax_error (YYPTRDIFF_T *yymsg_alloc, char **yymsg, |
1050 | | yy_state_t *yyssp, int yytoken) |
1051 | | { |
1052 | | enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 }; |
1053 | | /* Internationalized format string. */ |
1054 | | const char *yyformat = YY_NULLPTR; |
1055 | | /* Arguments of yyformat: reported tokens (one for the "unexpected", |
1056 | | one per "expected"). */ |
1057 | | char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM]; |
1058 | | /* Actual size of YYARG. */ |
1059 | | int yycount = 0; |
1060 | | /* Cumulated lengths of YYARG. */ |
1061 | | YYPTRDIFF_T yysize = 0; |
1062 | | |
1063 | | /* There are many possibilities here to consider: |
1064 | | - If this state is a consistent state with a default action, then |
1065 | | the only way this function was invoked is if the default action |
1066 | | is an error action. In that case, don't check for expected |
1067 | | tokens because there are none. |
1068 | | - The only way there can be no lookahead present (in yychar) is if |
1069 | | this state is a consistent state with a default action. Thus, |
1070 | | detecting the absence of a lookahead is sufficient to determine |
1071 | | that there is no unexpected or expected token to report. In that |
1072 | | case, just report a simple "syntax error". |
1073 | | - Don't assume there isn't a lookahead just because this state is a |
1074 | | consistent state with a default action. There might have been a |
1075 | | previous inconsistent state, consistent state with a non-default |
1076 | | action, or user semantic action that manipulated yychar. |
1077 | | - Of course, the expected token list depends on states to have |
1078 | | correct lookahead information, and it depends on the parser not |
1079 | | to perform extra reductions after fetching a lookahead from the |
1080 | | scanner and before detecting a syntax error. Thus, state merging |
1081 | | (from LALR or IELR) and default reductions corrupt the expected |
1082 | | token list. However, the list is correct for canonical LR with |
1083 | | one exception: it will still contain any token that will not be |
1084 | | accepted due to an error action in a later state. |
1085 | | */ |
1086 | | if (yytoken != YYEMPTY) |
1087 | | { |
1088 | | int yyn = yypact[+*yyssp]; |
1089 | | YYPTRDIFF_T yysize0 = yytnamerr (YY_NULLPTR, yytname[yytoken]); |
1090 | | yysize = yysize0; |
1091 | | yyarg[yycount++] = yytname[yytoken]; |
1092 | | if (!yypact_value_is_default (yyn)) |
1093 | | { |
1094 | | /* Start YYX at -YYN if negative to avoid negative indexes in |
1095 | | YYCHECK. In other words, skip the first -YYN actions for |
1096 | | this state because they are default actions. */ |
1097 | | int yyxbegin = yyn < 0 ? -yyn : 0; |
1098 | | /* Stay within bounds of both yycheck and yytname. */ |
1099 | | int yychecklim = YYLAST - yyn + 1; |
1100 | | int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS; |
1101 | | int yyx; |
1102 | | |
1103 | | for (yyx = yyxbegin; yyx < yyxend; ++yyx) |
1104 | | if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR |
1105 | | && !yytable_value_is_error (yytable[yyx + yyn])) |
1106 | | { |
1107 | | if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM) |
1108 | | { |
1109 | | yycount = 1; |
1110 | | yysize = yysize0; |
1111 | | break; |
1112 | | } |
1113 | | yyarg[yycount++] = yytname[yyx]; |
1114 | | { |
1115 | | YYPTRDIFF_T yysize1 |
1116 | | = yysize + yytnamerr (YY_NULLPTR, yytname[yyx]); |
1117 | | if (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM) |
1118 | | yysize = yysize1; |
1119 | | else |
1120 | | return 2; |
1121 | | } |
1122 | | } |
1123 | | } |
1124 | | } |
1125 | | |
1126 | | switch (yycount) |
1127 | | { |
1128 | | # define YYCASE_(N, S) \ |
1129 | | case N: \ |
1130 | | yyformat = S; \ |
1131 | | break |
1132 | | default: /* Avoid compiler warnings. */ |
1133 | | YYCASE_(0, YY_("syntax error")); |
1134 | | YYCASE_(1, YY_("syntax error, unexpected %s")); |
1135 | | YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s")); |
1136 | | YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s")); |
1137 | | YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s")); |
1138 | | YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s")); |
1139 | | # undef YYCASE_ |
1140 | | } |
1141 | | |
1142 | | { |
1143 | | /* Don't count the "%s"s in the final size, but reserve room for |
1144 | | the terminator. */ |
1145 | | YYPTRDIFF_T yysize1 = yysize + (yystrlen (yyformat) - 2 * yycount) + 1; |
1146 | | if (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM) |
1147 | | yysize = yysize1; |
1148 | | else |
1149 | | return 2; |
1150 | | } |
1151 | | |
1152 | | if (*yymsg_alloc < yysize) |
1153 | | { |
1154 | | *yymsg_alloc = 2 * yysize; |
1155 | | if (! (yysize <= *yymsg_alloc |
1156 | | && *yymsg_alloc <= YYSTACK_ALLOC_MAXIMUM)) |
1157 | | *yymsg_alloc = YYSTACK_ALLOC_MAXIMUM; |
1158 | | return 1; |
1159 | | } |
1160 | | |
1161 | | /* Avoid sprintf, as that infringes on the user's name space. |
1162 | | Don't have undefined behavior even if the translation |
1163 | | produced a string with the wrong number of "%s"s. */ |
1164 | | { |
1165 | | char *yyp = *yymsg; |
1166 | | int yyi = 0; |
1167 | | while ((*yyp = *yyformat) != '\0') |
1168 | | if (*yyp == '%' && yyformat[1] == 's' && yyi < yycount) |
1169 | | { |
1170 | | yyp += yytnamerr (yyp, yyarg[yyi++]); |
1171 | | yyformat += 2; |
1172 | | } |
1173 | | else |
1174 | | { |
1175 | | ++yyp; |
1176 | | ++yyformat; |
1177 | | } |
1178 | | } |
1179 | | return 0; |
1180 | | } |
1181 | | #endif /* YYERROR_VERBOSE */ |
1182 | | |
1183 | | /*-----------------------------------------------. |
1184 | | | Release the memory associated to this symbol. | |
1185 | | `-----------------------------------------------*/ |
1186 | | |
1187 | | static void |
1188 | | yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep) |
1189 | 4 | { |
1190 | 4 | YYUSE (yyvaluep); |
1191 | 4 | if (!yymsg) |
1192 | 0 | yymsg = "Deleting"; |
1193 | 4 | YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp); |
1194 | | |
1195 | 4 | YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN |
1196 | 4 | YYUSE (yytype); |
1197 | 4 | YY_IGNORE_MAYBE_UNINITIALIZED_END |
1198 | 4 | } |
1199 | | |
1200 | | |
1201 | | |
1202 | | |
1203 | | /* The lookahead symbol. */ |
1204 | | int yychar; |
1205 | | |
1206 | | /* The semantic value of the lookahead symbol. */ |
1207 | | YYSTYPE yylval; |
1208 | | /* Number of syntax errors so far. */ |
1209 | | int yynerrs; |
1210 | | |
1211 | | |
1212 | | /*----------. |
1213 | | | yyparse. | |
1214 | | `----------*/ |
1215 | | |
1216 | | int |
1217 | | yyparse (void) |
1218 | 2 | { |
1219 | 2 | yy_state_fast_t yystate; |
1220 | | /* Number of tokens to shift before error messages enabled. */ |
1221 | 2 | int yyerrstatus; |
1222 | | |
1223 | | /* The stacks and their tools: |
1224 | | 'yyss': related to states. |
1225 | | 'yyvs': related to semantic values. |
1226 | | |
1227 | | Refer to the stacks through separate pointers, to allow yyoverflow |
1228 | | to reallocate them elsewhere. */ |
1229 | | |
1230 | | /* The state stack. */ |
1231 | 2 | yy_state_t yyssa[YYINITDEPTH]; |
1232 | 2 | yy_state_t *yyss; |
1233 | 2 | yy_state_t *yyssp; |
1234 | | |
1235 | | /* The semantic value stack. */ |
1236 | 2 | YYSTYPE yyvsa[YYINITDEPTH]; |
1237 | 2 | YYSTYPE *yyvs; |
1238 | 2 | YYSTYPE *yyvsp; |
1239 | | |
1240 | 2 | YYPTRDIFF_T yystacksize; |
1241 | | |
1242 | 2 | int yyn; |
1243 | 2 | int yyresult; |
1244 | | /* Lookahead token as an internal (translated) token number. */ |
1245 | 2 | int yytoken = 0; |
1246 | | /* The variables used to return semantic value and location from the |
1247 | | action routines. */ |
1248 | 2 | YYSTYPE yyval; |
1249 | | |
1250 | | #if YYERROR_VERBOSE |
1251 | | /* Buffer for error messages, and its allocated size. */ |
1252 | | char yymsgbuf[128]; |
1253 | | char *yymsg = yymsgbuf; |
1254 | | YYPTRDIFF_T yymsg_alloc = sizeof yymsgbuf; |
1255 | | #endif |
1256 | | |
1257 | 18 | #define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N)) |
1258 | | |
1259 | | /* The number of symbols on the RHS of the reduced rule. |
1260 | | Keep to zero when no symbol should be popped. */ |
1261 | 2 | int yylen = 0; |
1262 | | |
1263 | 2 | yyssp = yyss = yyssa; |
1264 | 2 | yyvsp = yyvs = yyvsa; |
1265 | 2 | yystacksize = YYINITDEPTH; |
1266 | | |
1267 | 2 | YYDPRINTF ((stderr, "Starting parse\n")); |
1268 | | |
1269 | 2 | yystate = 0; |
1270 | 2 | yyerrstatus = 0; |
1271 | 2 | yynerrs = 0; |
1272 | 2 | yychar = YYEMPTY; /* Cause a token to be read. */ |
1273 | 2 | goto yysetstate; |
1274 | | |
1275 | | |
1276 | | /*------------------------------------------------------------. |
1277 | | | yynewstate -- push a new state, which is found in yystate. | |
1278 | | `------------------------------------------------------------*/ |
1279 | 18 | yynewstate: |
1280 | | /* In all cases, when you get here, the value and location stacks |
1281 | | have just been pushed. So pushing a state here evens the stacks. */ |
1282 | 18 | yyssp++; |
1283 | | |
1284 | | |
1285 | | /*--------------------------------------------------------------------. |
1286 | | | yysetstate -- set current state (the top of the stack) to yystate. | |
1287 | | `--------------------------------------------------------------------*/ |
1288 | 20 | yysetstate: |
1289 | 20 | YYDPRINTF ((stderr, "Entering state %d\n", yystate)); |
1290 | 20 | YY_ASSERT (0 <= yystate && yystate < YYNSTATES); |
1291 | 20 | YY_IGNORE_USELESS_CAST_BEGIN |
1292 | 20 | *yyssp = YY_CAST (yy_state_t, yystate); |
1293 | 20 | YY_IGNORE_USELESS_CAST_END |
1294 | | |
1295 | 20 | if (yyss + yystacksize - 1 <= yyssp) |
1296 | | #if !defined yyoverflow && !defined YYSTACK_RELOCATE |
1297 | | goto yyexhaustedlab; |
1298 | | #else |
1299 | 0 | { |
1300 | | /* Get the current used size of the three stacks, in elements. */ |
1301 | 0 | YYPTRDIFF_T yysize = yyssp - yyss + 1; |
1302 | |
|
1303 | | # if defined yyoverflow |
1304 | | { |
1305 | | /* Give user a chance to reallocate the stack. Use copies of |
1306 | | these so that the &'s don't force the real ones into |
1307 | | memory. */ |
1308 | | yy_state_t *yyss1 = yyss; |
1309 | | YYSTYPE *yyvs1 = yyvs; |
1310 | | |
1311 | | /* Each stack pointer address is followed by the size of the |
1312 | | data in use in that stack, in bytes. This used to be a |
1313 | | conditional around just the two extra args, but that might |
1314 | | be undefined if yyoverflow is a macro. */ |
1315 | | yyoverflow (YY_("memory exhausted"), |
1316 | | &yyss1, yysize * YYSIZEOF (*yyssp), |
1317 | | &yyvs1, yysize * YYSIZEOF (*yyvsp), |
1318 | | &yystacksize); |
1319 | | yyss = yyss1; |
1320 | | yyvs = yyvs1; |
1321 | | } |
1322 | | # else /* defined YYSTACK_RELOCATE */ |
1323 | | /* Extend the stack our own way. */ |
1324 | 0 | if (YYMAXDEPTH <= yystacksize) |
1325 | 0 | goto yyexhaustedlab; |
1326 | 0 | yystacksize *= 2; |
1327 | 0 | if (YYMAXDEPTH < yystacksize) |
1328 | 0 | yystacksize = YYMAXDEPTH; |
1329 | |
|
1330 | 0 | { |
1331 | 0 | yy_state_t *yyss1 = yyss; |
1332 | 0 | union yyalloc *yyptr = |
1333 | 0 | YY_CAST (union yyalloc *, |
1334 | 0 | YYSTACK_ALLOC (YY_CAST (YYSIZE_T, YYSTACK_BYTES (yystacksize)))); |
1335 | 0 | if (! yyptr) |
1336 | 0 | goto yyexhaustedlab; |
1337 | 0 | YYSTACK_RELOCATE (yyss_alloc, yyss); |
1338 | 0 | YYSTACK_RELOCATE (yyvs_alloc, yyvs); |
1339 | 0 | # undef YYSTACK_RELOCATE |
1340 | 0 | if (yyss1 != yyssa) |
1341 | 0 | YYSTACK_FREE (yyss1); |
1342 | 0 | } |
1343 | 0 | # endif |
1344 | | |
1345 | 0 | yyssp = yyss + yysize - 1; |
1346 | 0 | yyvsp = yyvs + yysize - 1; |
1347 | |
|
1348 | 0 | YY_IGNORE_USELESS_CAST_BEGIN |
1349 | 0 | YYDPRINTF ((stderr, "Stack size increased to %ld\n", |
1350 | 0 | YY_CAST (long, yystacksize))); |
1351 | 0 | YY_IGNORE_USELESS_CAST_END |
1352 | |
|
1353 | 0 | if (yyss + yystacksize - 1 <= yyssp) |
1354 | 0 | YYABORT; |
1355 | 0 | } |
1356 | 20 | #endif /* !defined yyoverflow && !defined YYSTACK_RELOCATE */ |
1357 | | |
1358 | 20 | if (yystate == YYFINAL) |
1359 | 2 | YYACCEPT; |
1360 | | |
1361 | 18 | goto yybackup; |
1362 | | |
1363 | | |
1364 | | /*-----------. |
1365 | | | yybackup. | |
1366 | | `-----------*/ |
1367 | 18 | yybackup: |
1368 | | /* Do appropriate processing given the current state. Read a |
1369 | | lookahead token if we need one and don't already have one. */ |
1370 | | |
1371 | | /* First try to decide what to do without reference to lookahead token. */ |
1372 | 18 | yyn = yypact[yystate]; |
1373 | 18 | if (yypact_value_is_default (yyn)) |
1374 | 4 | goto yydefault; |
1375 | | |
1376 | | /* Not known => get a lookahead token if don't already have one. */ |
1377 | | |
1378 | | /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol. */ |
1379 | 14 | if (yychar == YYEMPTY) |
1380 | 6 | { |
1381 | 6 | YYDPRINTF ((stderr, "Reading a token: ")); |
1382 | 6 | yychar = yylex (); |
1383 | 6 | } |
1384 | | |
1385 | 14 | if (yychar <= YYEOF) |
1386 | 4 | { |
1387 | 4 | yychar = yytoken = YYEOF; |
1388 | 4 | YYDPRINTF ((stderr, "Now at end of input.\n")); |
1389 | 4 | } |
1390 | 10 | else |
1391 | 10 | { |
1392 | 10 | yytoken = YYTRANSLATE (yychar); |
1393 | 10 | YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc); |
1394 | 10 | } |
1395 | | |
1396 | | /* If the proper action on seeing token YYTOKEN is to reduce or to |
1397 | | detect an error, take that action. */ |
1398 | 14 | yyn += yytoken; |
1399 | 14 | if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken) |
1400 | 6 | goto yydefault; |
1401 | 8 | yyn = yytable[yyn]; |
1402 | 8 | if (yyn <= 0) |
1403 | 2 | { |
1404 | 2 | if (yytable_value_is_error (yyn)) |
1405 | 0 | goto yyerrlab; |
1406 | 2 | yyn = -yyn; |
1407 | 2 | goto yyreduce; |
1408 | 2 | } |
1409 | | |
1410 | | /* Count tokens shifted since error; after three, turn off error |
1411 | | status. */ |
1412 | 6 | if (yyerrstatus) |
1413 | 0 | yyerrstatus--; |
1414 | | |
1415 | | /* Shift the lookahead token. */ |
1416 | 6 | YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc); |
1417 | 6 | yystate = yyn; |
1418 | 6 | YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN |
1419 | 6 | *++yyvsp = yylval; |
1420 | 6 | YY_IGNORE_MAYBE_UNINITIALIZED_END |
1421 | | |
1422 | | /* Discard the shifted token. */ |
1423 | 6 | yychar = YYEMPTY; |
1424 | 6 | goto yynewstate; |
1425 | | |
1426 | | |
1427 | | /*-----------------------------------------------------------. |
1428 | | | yydefault -- do the default action for the current state. | |
1429 | | `-----------------------------------------------------------*/ |
1430 | 10 | yydefault: |
1431 | 10 | yyn = yydefact[yystate]; |
1432 | 10 | if (yyn == 0) |
1433 | 0 | goto yyerrlab; |
1434 | 10 | goto yyreduce; |
1435 | | |
1436 | | |
1437 | | /*-----------------------------. |
1438 | | | yyreduce -- do a reduction. | |
1439 | | `-----------------------------*/ |
1440 | 12 | yyreduce: |
1441 | | /* yyn is the number of a rule to reduce with. */ |
1442 | 12 | yylen = yyr2[yyn]; |
1443 | | |
1444 | | /* If YYLEN is nonzero, implement the default value of the action: |
1445 | | '$$ = $1'. |
1446 | | |
1447 | | Otherwise, the following line sets YYVAL to garbage. |
1448 | | This behavior is undocumented and Bison |
1449 | | users should not rely upon it. Assigning to YYVAL |
1450 | | unconditionally makes the parser a bit smaller, and it avoids a |
1451 | | GCC warning that YYVAL may be used uninitialized. */ |
1452 | 12 | yyval = yyvsp[1-yylen]; |
1453 | | |
1454 | | |
1455 | 12 | YY_REDUCE_PRINT (yyn); |
1456 | 12 | switch (yyn) |
1457 | 12 | { |
1458 | 2 | case 3: |
1459 | 2 | #line 136 "cmd-parse.y" |
1460 | 2 | { |
1461 | 2 | struct cmd_parse_state *ps = &parse_state; |
1462 | | |
1463 | 2 | ps->commands = (yyvsp[0].commands); |
1464 | 2 | } |
1465 | 2 | #line 1466 "cmd-parse.c" |
1466 | 2 | break; |
1467 | | |
1468 | 2 | case 4: |
1469 | 2 | #line 143 "cmd-parse.y" |
1470 | 2 | { |
1471 | 2 | (yyval.commands) = (yyvsp[-1].commands); |
1472 | 2 | } |
1473 | 2 | #line 1474 "cmd-parse.c" |
1474 | 2 | break; |
1475 | | |
1476 | 0 | case 5: |
1477 | 0 | #line 147 "cmd-parse.y" |
1478 | 0 | { |
1479 | 0 | (yyval.commands) = (yyvsp[-2].commands); |
1480 | 0 | TAILQ_CONCAT((yyval.commands), (yyvsp[-1].commands), entry); |
1481 | 0 | free((yyvsp[-1].commands)); |
1482 | 0 | } |
1483 | 0 | #line 1484 "cmd-parse.c" |
1484 | 0 | break; |
1485 | | |
1486 | 0 | case 6: |
1487 | 0 | #line 154 "cmd-parse.y" |
1488 | 0 | { |
1489 | 0 | (yyval.commands) = xmalloc (sizeof *(yyval.commands)); |
1490 | 0 | TAILQ_INIT((yyval.commands)); |
1491 | 0 | } |
1492 | 0 | #line 1493 "cmd-parse.c" |
1493 | 0 | break; |
1494 | | |
1495 | 0 | case 7: |
1496 | 0 | #line 159 "cmd-parse.y" |
1497 | 0 | { |
1498 | 0 | (yyval.commands) = xmalloc (sizeof *(yyval.commands)); |
1499 | 0 | TAILQ_INIT((yyval.commands)); |
1500 | 0 | } |
1501 | 0 | #line 1502 "cmd-parse.c" |
1502 | 0 | break; |
1503 | | |
1504 | 0 | case 8: |
1505 | 0 | #line 164 "cmd-parse.y" |
1506 | 0 | { |
1507 | 0 | struct cmd_parse_state *ps = &parse_state; |
1508 | |
|
1509 | 0 | if (ps->scope == NULL || ps->scope->flag) |
1510 | 0 | (yyval.commands) = (yyvsp[0].commands); |
1511 | 0 | else { |
1512 | 0 | (yyval.commands) = cmd_parse_new_commands(); |
1513 | 0 | cmd_parse_free_commands((yyvsp[0].commands)); |
1514 | 0 | } |
1515 | 0 | } |
1516 | 0 | #line 1517 "cmd-parse.c" |
1517 | 0 | break; |
1518 | | |
1519 | 2 | case 9: |
1520 | 2 | #line 175 "cmd-parse.y" |
1521 | 2 | { |
1522 | 2 | struct cmd_parse_state *ps = &parse_state; |
1523 | | |
1524 | 2 | if (ps->scope == NULL || ps->scope->flag) |
1525 | 2 | (yyval.commands) = (yyvsp[0].commands); |
1526 | 0 | else { |
1527 | 0 | (yyval.commands) = cmd_parse_new_commands(); |
1528 | 0 | cmd_parse_free_commands((yyvsp[0].commands)); |
1529 | 0 | } |
1530 | 2 | } |
1531 | 2 | #line 1532 "cmd-parse.c" |
1532 | 2 | break; |
1533 | | |
1534 | 0 | case 10: |
1535 | 0 | #line 187 "cmd-parse.y" |
1536 | 0 | { |
1537 | 0 | (yyval.token) = (yyvsp[0].token); |
1538 | 0 | } |
1539 | 0 | #line 1540 "cmd-parse.c" |
1540 | 0 | break; |
1541 | | |
1542 | 0 | case 11: |
1543 | 0 | #line 191 "cmd-parse.y" |
1544 | 0 | { |
1545 | 0 | (yyval.token) = (yyvsp[0].token); |
1546 | 0 | } |
1547 | 0 | #line 1548 "cmd-parse.c" |
1548 | 0 | break; |
1549 | | |
1550 | 0 | case 12: |
1551 | 0 | #line 196 "cmd-parse.y" |
1552 | 0 | { |
1553 | 0 | struct cmd_parse_state *ps = &parse_state; |
1554 | 0 | struct cmd_parse_input *pi = ps->input; |
1555 | 0 | struct format_tree *ft; |
1556 | 0 | struct client *c = pi->c; |
1557 | 0 | struct cmd_find_state *fsp; |
1558 | 0 | struct cmd_find_state fs; |
1559 | 0 | int flags = FORMAT_NOJOBS; |
1560 | |
|
1561 | 0 | if (cmd_find_valid_state(&pi->fs)) |
1562 | 0 | fsp = &pi->fs; |
1563 | 0 | else { |
1564 | 0 | cmd_find_from_client(&fs, c, 0); |
1565 | 0 | fsp = &fs; |
1566 | 0 | } |
1567 | 0 | ft = format_create(NULL, pi->item, FORMAT_NONE, flags); |
1568 | 0 | format_defaults(ft, c, fsp->s, fsp->wl, fsp->wp); |
1569 | |
|
1570 | 0 | (yyval.token) = format_expand(ft, (yyvsp[0].token)); |
1571 | 0 | format_free(ft); |
1572 | 0 | free((yyvsp[0].token)); |
1573 | 0 | } |
1574 | 0 | #line 1575 "cmd-parse.c" |
1575 | 0 | break; |
1576 | | |
1577 | 0 | case 15: |
1578 | 0 | #line 223 "cmd-parse.y" |
1579 | 0 | { |
1580 | 0 | struct cmd_parse_state *ps = &parse_state; |
1581 | 0 | int flags = ps->input->flags; |
1582 | 0 | int flag = 1; |
1583 | 0 | struct cmd_parse_scope *scope; |
1584 | |
|
1585 | 0 | if (ps->scope != NULL) { |
1586 | 0 | flag = ps->scope->flag; |
1587 | 0 | TAILQ_FOREACH(scope, &ps->stack, entry) |
1588 | 0 | flag = flag && scope->flag; |
1589 | 0 | } |
1590 | |
|
1591 | 0 | if ((~flags & CMD_PARSE_PARSEONLY) && flag) |
1592 | 0 | environ_put(global_environ, (yyvsp[0].token), 0); |
1593 | 0 | free((yyvsp[0].token)); |
1594 | 0 | } |
1595 | 0 | #line 1596 "cmd-parse.c" |
1596 | 0 | break; |
1597 | | |
1598 | 0 | case 16: |
1599 | 0 | #line 241 "cmd-parse.y" |
1600 | 0 | { |
1601 | 0 | struct cmd_parse_state *ps = &parse_state; |
1602 | 0 | int flags = ps->input->flags; |
1603 | 0 | int flag = 1; |
1604 | 0 | struct cmd_parse_scope *scope; |
1605 | |
|
1606 | 0 | if (ps->scope != NULL) { |
1607 | 0 | flag = ps->scope->flag; |
1608 | 0 | TAILQ_FOREACH(scope, &ps->stack, entry) |
1609 | 0 | flag = flag && scope->flag; |
1610 | 0 | } |
1611 | |
|
1612 | 0 | if ((~flags & CMD_PARSE_PARSEONLY) && flag) |
1613 | 0 | environ_put(global_environ, (yyvsp[0].token), ENVIRON_HIDDEN); |
1614 | 0 | free((yyvsp[0].token)); |
1615 | 0 | } |
1616 | 0 | #line 1617 "cmd-parse.c" |
1617 | 0 | break; |
1618 | | |
1619 | 0 | case 17: |
1620 | 0 | #line 259 "cmd-parse.y" |
1621 | 0 | { |
1622 | 0 | struct cmd_parse_state *ps = &parse_state; |
1623 | 0 | struct cmd_parse_scope *scope; |
1624 | |
|
1625 | 0 | scope = xmalloc(sizeof *scope); |
1626 | 0 | (yyval.flag) = scope->flag = format_true((yyvsp[0].token)); |
1627 | 0 | free((yyvsp[0].token)); |
1628 | |
|
1629 | 0 | if (ps->scope != NULL) |
1630 | 0 | TAILQ_INSERT_HEAD(&ps->stack, ps->scope, entry); |
1631 | 0 | ps->scope = scope; |
1632 | 0 | } |
1633 | 0 | #line 1634 "cmd-parse.c" |
1634 | 0 | break; |
1635 | | |
1636 | 0 | case 18: |
1637 | 0 | #line 273 "cmd-parse.y" |
1638 | 0 | { |
1639 | 0 | struct cmd_parse_state *ps = &parse_state; |
1640 | 0 | struct cmd_parse_scope *scope; |
1641 | |
|
1642 | 0 | scope = xmalloc(sizeof *scope); |
1643 | 0 | scope->flag = !ps->scope->flag; |
1644 | |
|
1645 | 0 | free(ps->scope); |
1646 | 0 | ps->scope = scope; |
1647 | 0 | } |
1648 | 0 | #line 1649 "cmd-parse.c" |
1649 | 0 | break; |
1650 | | |
1651 | 0 | case 19: |
1652 | 0 | #line 285 "cmd-parse.y" |
1653 | 0 | { |
1654 | 0 | struct cmd_parse_state *ps = &parse_state; |
1655 | 0 | struct cmd_parse_scope *scope; |
1656 | |
|
1657 | 0 | scope = xmalloc(sizeof *scope); |
1658 | 0 | (yyval.flag) = scope->flag = format_true((yyvsp[0].token)); |
1659 | 0 | free((yyvsp[0].token)); |
1660 | |
|
1661 | 0 | free(ps->scope); |
1662 | 0 | ps->scope = scope; |
1663 | 0 | } |
1664 | 0 | #line 1665 "cmd-parse.c" |
1665 | 0 | break; |
1666 | | |
1667 | 0 | case 20: |
1668 | 0 | #line 298 "cmd-parse.y" |
1669 | 0 | { |
1670 | 0 | struct cmd_parse_state *ps = &parse_state; |
1671 | |
|
1672 | 0 | free(ps->scope); |
1673 | 0 | ps->scope = TAILQ_FIRST(&ps->stack); |
1674 | 0 | if (ps->scope != NULL) |
1675 | 0 | TAILQ_REMOVE(&ps->stack, ps->scope, entry); |
1676 | 0 | } |
1677 | 0 | #line 1678 "cmd-parse.c" |
1678 | 0 | break; |
1679 | | |
1680 | 0 | case 21: |
1681 | 0 | #line 308 "cmd-parse.y" |
1682 | 0 | { |
1683 | 0 | if ((yyvsp[-3].flag)) |
1684 | 0 | (yyval.commands) = (yyvsp[-1].commands); |
1685 | 0 | else { |
1686 | 0 | (yyval.commands) = cmd_parse_new_commands(); |
1687 | 0 | cmd_parse_free_commands((yyvsp[-1].commands)); |
1688 | 0 | } |
1689 | 0 | } |
1690 | 0 | #line 1691 "cmd-parse.c" |
1691 | 0 | break; |
1692 | | |
1693 | 0 | case 22: |
1694 | 0 | #line 317 "cmd-parse.y" |
1695 | 0 | { |
1696 | 0 | if ((yyvsp[-6].flag)) { |
1697 | 0 | (yyval.commands) = (yyvsp[-4].commands); |
1698 | 0 | cmd_parse_free_commands((yyvsp[-1].commands)); |
1699 | 0 | } else { |
1700 | 0 | (yyval.commands) = (yyvsp[-1].commands); |
1701 | 0 | cmd_parse_free_commands((yyvsp[-4].commands)); |
1702 | 0 | } |
1703 | 0 | } |
1704 | 0 | #line 1705 "cmd-parse.c" |
1705 | 0 | break; |
1706 | | |
1707 | 0 | case 23: |
1708 | 0 | #line 327 "cmd-parse.y" |
1709 | 0 | { |
1710 | 0 | if ((yyvsp[-4].flag)) { |
1711 | 0 | (yyval.commands) = (yyvsp[-2].commands); |
1712 | 0 | cmd_parse_free_commands((yyvsp[-1].elif).commands); |
1713 | 0 | } else if ((yyvsp[-1].elif).flag) { |
1714 | 0 | (yyval.commands) = (yyvsp[-1].elif).commands; |
1715 | 0 | cmd_parse_free_commands((yyvsp[-2].commands)); |
1716 | 0 | } else { |
1717 | 0 | (yyval.commands) = cmd_parse_new_commands(); |
1718 | 0 | cmd_parse_free_commands((yyvsp[-2].commands)); |
1719 | 0 | cmd_parse_free_commands((yyvsp[-1].elif).commands); |
1720 | 0 | } |
1721 | 0 | } |
1722 | 0 | #line 1723 "cmd-parse.c" |
1723 | 0 | break; |
1724 | | |
1725 | 0 | case 24: |
1726 | 0 | #line 341 "cmd-parse.y" |
1727 | 0 | { |
1728 | 0 | if ((yyvsp[-7].flag)) { |
1729 | 0 | (yyval.commands) = (yyvsp[-5].commands); |
1730 | 0 | cmd_parse_free_commands((yyvsp[-4].elif).commands); |
1731 | 0 | cmd_parse_free_commands((yyvsp[-1].commands)); |
1732 | 0 | } else if ((yyvsp[-4].elif).flag) { |
1733 | 0 | (yyval.commands) = (yyvsp[-4].elif).commands; |
1734 | 0 | cmd_parse_free_commands((yyvsp[-5].commands)); |
1735 | 0 | cmd_parse_free_commands((yyvsp[-1].commands)); |
1736 | 0 | } else { |
1737 | 0 | (yyval.commands) = (yyvsp[-1].commands); |
1738 | 0 | cmd_parse_free_commands((yyvsp[-5].commands)); |
1739 | 0 | cmd_parse_free_commands((yyvsp[-4].elif).commands); |
1740 | 0 | } |
1741 | 0 | } |
1742 | 0 | #line 1743 "cmd-parse.c" |
1743 | 0 | break; |
1744 | | |
1745 | 0 | case 25: |
1746 | 0 | #line 358 "cmd-parse.y" |
1747 | 0 | { |
1748 | 0 | if ((yyvsp[-2].flag)) { |
1749 | 0 | (yyval.elif).flag = 1; |
1750 | 0 | (yyval.elif).commands = (yyvsp[0].commands); |
1751 | 0 | } else { |
1752 | 0 | (yyval.elif).flag = 0; |
1753 | 0 | (yyval.elif).commands = cmd_parse_new_commands(); |
1754 | 0 | cmd_parse_free_commands((yyvsp[0].commands)); |
1755 | 0 | } |
1756 | 0 | } |
1757 | 0 | #line 1758 "cmd-parse.c" |
1758 | 0 | break; |
1759 | | |
1760 | 0 | case 26: |
1761 | 0 | #line 369 "cmd-parse.y" |
1762 | 0 | { |
1763 | 0 | if ((yyvsp[-3].flag)) { |
1764 | 0 | (yyval.elif).flag = 1; |
1765 | 0 | (yyval.elif).commands = (yyvsp[-1].commands); |
1766 | 0 | cmd_parse_free_commands((yyvsp[0].elif).commands); |
1767 | 0 | } else if ((yyvsp[0].elif).flag) { |
1768 | 0 | (yyval.elif).flag = 1; |
1769 | 0 | (yyval.elif).commands = (yyvsp[0].elif).commands; |
1770 | 0 | cmd_parse_free_commands((yyvsp[-1].commands)); |
1771 | 0 | } else { |
1772 | 0 | (yyval.elif).flag = 0; |
1773 | 0 | (yyval.elif).commands = cmd_parse_new_commands(); |
1774 | 0 | cmd_parse_free_commands((yyvsp[-1].commands)); |
1775 | 0 | cmd_parse_free_commands((yyvsp[0].elif).commands); |
1776 | 0 | } |
1777 | 0 | } |
1778 | 0 | #line 1779 "cmd-parse.c" |
1779 | 0 | break; |
1780 | | |
1781 | 2 | case 27: |
1782 | 2 | #line 387 "cmd-parse.y" |
1783 | 2 | { |
1784 | 2 | struct cmd_parse_state *ps = &parse_state; |
1785 | | |
1786 | 2 | (yyval.commands) = cmd_parse_new_commands(); |
1787 | 2 | if (!TAILQ_EMPTY(&(yyvsp[0].command)->arguments) && |
1788 | 2 | (ps->scope == NULL || ps->scope->flag)) |
1789 | 2 | TAILQ_INSERT_TAIL((yyval.commands), (yyvsp[0].command), entry); |
1790 | 0 | else |
1791 | 0 | cmd_parse_free_command((yyvsp[0].command)); |
1792 | 2 | } |
1793 | 2 | #line 1794 "cmd-parse.c" |
1794 | 2 | break; |
1795 | | |
1796 | 0 | case 28: |
1797 | 0 | #line 398 "cmd-parse.y" |
1798 | 0 | { |
1799 | 0 | (yyval.commands) = (yyvsp[-1].commands); |
1800 | 0 | } |
1801 | 0 | #line 1802 "cmd-parse.c" |
1802 | 0 | break; |
1803 | | |
1804 | 0 | case 29: |
1805 | 0 | #line 402 "cmd-parse.y" |
1806 | 0 | { |
1807 | 0 | (yyval.commands) = (yyvsp[-2].commands); |
1808 | 0 | TAILQ_CONCAT((yyval.commands), (yyvsp[0].commands), entry); |
1809 | 0 | free((yyvsp[0].commands)); |
1810 | 0 | } |
1811 | 0 | #line 1812 "cmd-parse.c" |
1812 | 0 | break; |
1813 | | |
1814 | 0 | case 30: |
1815 | 0 | #line 408 "cmd-parse.y" |
1816 | 0 | { |
1817 | 0 | struct cmd_parse_state *ps = &parse_state; |
1818 | |
|
1819 | 0 | if (!TAILQ_EMPTY(&(yyvsp[0].command)->arguments) && |
1820 | 0 | (ps->scope == NULL || ps->scope->flag)) { |
1821 | 0 | (yyval.commands) = (yyvsp[-2].commands); |
1822 | 0 | TAILQ_INSERT_TAIL((yyval.commands), (yyvsp[0].command), entry); |
1823 | 0 | } else { |
1824 | 0 | (yyval.commands) = cmd_parse_new_commands(); |
1825 | 0 | cmd_parse_free_commands((yyvsp[-2].commands)); |
1826 | 0 | cmd_parse_free_command((yyvsp[0].command)); |
1827 | 0 | } |
1828 | 0 | } |
1829 | 0 | #line 1830 "cmd-parse.c" |
1830 | 0 | break; |
1831 | | |
1832 | 0 | case 31: |
1833 | 0 | #line 422 "cmd-parse.y" |
1834 | 0 | { |
1835 | 0 | (yyval.commands) = (yyvsp[0].commands); |
1836 | 0 | } |
1837 | 0 | #line 1838 "cmd-parse.c" |
1838 | 0 | break; |
1839 | | |
1840 | 0 | case 32: |
1841 | 0 | #line 427 "cmd-parse.y" |
1842 | 0 | { |
1843 | 0 | struct cmd_parse_state *ps = &parse_state; |
1844 | |
|
1845 | 0 | (yyval.command) = xcalloc(1, sizeof *(yyval.command)); |
1846 | 0 | (yyval.command)->line = ps->input->line; |
1847 | 0 | TAILQ_INIT(&(yyval.command)->arguments); |
1848 | 0 | } |
1849 | 0 | #line 1850 "cmd-parse.c" |
1850 | 0 | break; |
1851 | | |
1852 | 2 | case 33: |
1853 | 2 | #line 435 "cmd-parse.y" |
1854 | 2 | { |
1855 | 2 | struct cmd_parse_state *ps = &parse_state; |
1856 | 2 | struct cmd_parse_argument *arg; |
1857 | | |
1858 | 2 | (yyval.command) = xcalloc(1, sizeof *(yyval.command)); |
1859 | 2 | (yyval.command)->line = ps->input->line; |
1860 | 2 | TAILQ_INIT(&(yyval.command)->arguments); |
1861 | | |
1862 | 2 | arg = xcalloc(1, sizeof *arg); |
1863 | 2 | arg->type = CMD_PARSE_STRING; |
1864 | 2 | arg->string = (yyvsp[0].token); |
1865 | 2 | TAILQ_INSERT_HEAD(&(yyval.command)->arguments, arg, entry); |
1866 | 2 | } |
1867 | 2 | #line 1868 "cmd-parse.c" |
1868 | 2 | break; |
1869 | | |
1870 | 0 | case 34: |
1871 | 0 | #line 449 "cmd-parse.y" |
1872 | 0 | { |
1873 | 0 | struct cmd_parse_state *ps = &parse_state; |
1874 | 0 | struct cmd_parse_argument *arg; |
1875 | |
|
1876 | 0 | (yyval.command) = xcalloc(1, sizeof *(yyval.command)); |
1877 | 0 | (yyval.command)->line = ps->input->line; |
1878 | 0 | TAILQ_INIT(&(yyval.command)->arguments); |
1879 | |
|
1880 | 0 | TAILQ_CONCAT(&(yyval.command)->arguments, (yyvsp[0].arguments), entry); |
1881 | 0 | free((yyvsp[0].arguments)); |
1882 | |
|
1883 | 0 | arg = xcalloc(1, sizeof *arg); |
1884 | 0 | arg->type = CMD_PARSE_STRING; |
1885 | 0 | arg->string = (yyvsp[-1].token); |
1886 | 0 | TAILQ_INSERT_HEAD(&(yyval.command)->arguments, arg, entry); |
1887 | 0 | } |
1888 | 0 | #line 1889 "cmd-parse.c" |
1889 | 0 | break; |
1890 | | |
1891 | 0 | case 35: |
1892 | 0 | #line 467 "cmd-parse.y" |
1893 | 0 | { |
1894 | 0 | if ((yyvsp[-2].flag)) |
1895 | 0 | (yyval.commands) = (yyvsp[-1].commands); |
1896 | 0 | else { |
1897 | 0 | (yyval.commands) = cmd_parse_new_commands(); |
1898 | 0 | cmd_parse_free_commands((yyvsp[-1].commands)); |
1899 | 0 | } |
1900 | 0 | } |
1901 | 0 | #line 1902 "cmd-parse.c" |
1902 | 0 | break; |
1903 | | |
1904 | 0 | case 36: |
1905 | 0 | #line 476 "cmd-parse.y" |
1906 | 0 | { |
1907 | 0 | if ((yyvsp[-4].flag)) { |
1908 | 0 | (yyval.commands) = (yyvsp[-3].commands); |
1909 | 0 | cmd_parse_free_commands((yyvsp[-1].commands)); |
1910 | 0 | } else { |
1911 | 0 | (yyval.commands) = (yyvsp[-1].commands); |
1912 | 0 | cmd_parse_free_commands((yyvsp[-3].commands)); |
1913 | 0 | } |
1914 | 0 | } |
1915 | 0 | #line 1916 "cmd-parse.c" |
1916 | 0 | break; |
1917 | | |
1918 | 0 | case 37: |
1919 | 0 | #line 486 "cmd-parse.y" |
1920 | 0 | { |
1921 | 0 | if ((yyvsp[-3].flag)) { |
1922 | 0 | (yyval.commands) = (yyvsp[-2].commands); |
1923 | 0 | cmd_parse_free_commands((yyvsp[-1].elif).commands); |
1924 | 0 | } else if ((yyvsp[-1].elif).flag) { |
1925 | 0 | (yyval.commands) = (yyvsp[-1].elif).commands; |
1926 | 0 | cmd_parse_free_commands((yyvsp[-2].commands)); |
1927 | 0 | } else { |
1928 | 0 | (yyval.commands) = cmd_parse_new_commands(); |
1929 | 0 | cmd_parse_free_commands((yyvsp[-2].commands)); |
1930 | 0 | cmd_parse_free_commands((yyvsp[-1].elif).commands); |
1931 | 0 | } |
1932 | 0 | } |
1933 | 0 | #line 1934 "cmd-parse.c" |
1934 | 0 | break; |
1935 | | |
1936 | 0 | case 38: |
1937 | 0 | #line 500 "cmd-parse.y" |
1938 | 0 | { |
1939 | 0 | if ((yyvsp[-5].flag)) { |
1940 | 0 | (yyval.commands) = (yyvsp[-4].commands); |
1941 | 0 | cmd_parse_free_commands((yyvsp[-3].elif).commands); |
1942 | 0 | cmd_parse_free_commands((yyvsp[-1].commands)); |
1943 | 0 | } else if ((yyvsp[-3].elif).flag) { |
1944 | 0 | (yyval.commands) = (yyvsp[-3].elif).commands; |
1945 | 0 | cmd_parse_free_commands((yyvsp[-4].commands)); |
1946 | 0 | cmd_parse_free_commands((yyvsp[-1].commands)); |
1947 | 0 | } else { |
1948 | 0 | (yyval.commands) = (yyvsp[-1].commands); |
1949 | 0 | cmd_parse_free_commands((yyvsp[-4].commands)); |
1950 | 0 | cmd_parse_free_commands((yyvsp[-3].elif).commands); |
1951 | 0 | } |
1952 | 0 | } |
1953 | 0 | #line 1954 "cmd-parse.c" |
1954 | 0 | break; |
1955 | | |
1956 | 0 | case 39: |
1957 | 0 | #line 517 "cmd-parse.y" |
1958 | 0 | { |
1959 | 0 | if ((yyvsp[-1].flag)) { |
1960 | 0 | (yyval.elif).flag = 1; |
1961 | 0 | (yyval.elif).commands = (yyvsp[0].commands); |
1962 | 0 | } else { |
1963 | 0 | (yyval.elif).flag = 0; |
1964 | 0 | (yyval.elif).commands = cmd_parse_new_commands(); |
1965 | 0 | cmd_parse_free_commands((yyvsp[0].commands)); |
1966 | 0 | } |
1967 | 0 | } |
1968 | 0 | #line 1969 "cmd-parse.c" |
1969 | 0 | break; |
1970 | | |
1971 | 0 | case 40: |
1972 | 0 | #line 528 "cmd-parse.y" |
1973 | 0 | { |
1974 | 0 | if ((yyvsp[-2].flag)) { |
1975 | 0 | (yyval.elif).flag = 1; |
1976 | 0 | (yyval.elif).commands = (yyvsp[-1].commands); |
1977 | 0 | cmd_parse_free_commands((yyvsp[0].elif).commands); |
1978 | 0 | } else if ((yyvsp[0].elif).flag) { |
1979 | 0 | (yyval.elif).flag = 1; |
1980 | 0 | (yyval.elif).commands = (yyvsp[0].elif).commands; |
1981 | 0 | cmd_parse_free_commands((yyvsp[-1].commands)); |
1982 | 0 | } else { |
1983 | 0 | (yyval.elif).flag = 0; |
1984 | 0 | (yyval.elif).commands = cmd_parse_new_commands(); |
1985 | 0 | cmd_parse_free_commands((yyvsp[-1].commands)); |
1986 | 0 | cmd_parse_free_commands((yyvsp[0].elif).commands); |
1987 | 0 | } |
1988 | 0 | } |
1989 | 0 | #line 1990 "cmd-parse.c" |
1990 | 0 | break; |
1991 | | |
1992 | 0 | case 41: |
1993 | 0 | #line 546 "cmd-parse.y" |
1994 | 0 | { |
1995 | 0 | (yyval.arguments) = xcalloc(1, sizeof *(yyval.arguments)); |
1996 | 0 | TAILQ_INIT((yyval.arguments)); |
1997 | |
|
1998 | 0 | TAILQ_INSERT_HEAD((yyval.arguments), (yyvsp[0].argument), entry); |
1999 | 0 | } |
2000 | 0 | #line 2001 "cmd-parse.c" |
2001 | 0 | break; |
2002 | | |
2003 | 0 | case 42: |
2004 | 0 | #line 553 "cmd-parse.y" |
2005 | 0 | { |
2006 | 0 | TAILQ_INSERT_HEAD((yyvsp[0].arguments), (yyvsp[-1].argument), entry); |
2007 | 0 | (yyval.arguments) = (yyvsp[0].arguments); |
2008 | 0 | } |
2009 | 0 | #line 2010 "cmd-parse.c" |
2010 | 0 | break; |
2011 | | |
2012 | 0 | case 43: |
2013 | 0 | #line 559 "cmd-parse.y" |
2014 | 0 | { |
2015 | 0 | (yyval.argument) = xcalloc(1, sizeof *(yyval.argument)); |
2016 | 0 | (yyval.argument)->type = CMD_PARSE_STRING; |
2017 | 0 | (yyval.argument)->string = (yyvsp[0].token); |
2018 | 0 | } |
2019 | 0 | #line 2020 "cmd-parse.c" |
2020 | 0 | break; |
2021 | | |
2022 | 0 | case 44: |
2023 | 0 | #line 565 "cmd-parse.y" |
2024 | 0 | { |
2025 | 0 | (yyval.argument) = xcalloc(1, sizeof *(yyval.argument)); |
2026 | 0 | (yyval.argument)->type = CMD_PARSE_STRING; |
2027 | 0 | (yyval.argument)->string = (yyvsp[0].token); |
2028 | 0 | } |
2029 | 0 | #line 2030 "cmd-parse.c" |
2030 | 0 | break; |
2031 | | |
2032 | 0 | case 45: |
2033 | 0 | #line 571 "cmd-parse.y" |
2034 | 0 | { |
2035 | 0 | (yyval.argument) = xcalloc(1, sizeof *(yyval.argument)); |
2036 | 0 | (yyval.argument)->type = CMD_PARSE_COMMANDS; |
2037 | 0 | (yyval.argument)->commands = (yyvsp[0].commands); |
2038 | 0 | } |
2039 | 0 | #line 2040 "cmd-parse.c" |
2040 | 0 | break; |
2041 | | |
2042 | 0 | case 46: |
2043 | 0 | #line 578 "cmd-parse.y" |
2044 | 0 | { |
2045 | 0 | (yyval.commands) = (yyvsp[-1].commands); |
2046 | 0 | } |
2047 | 0 | #line 2048 "cmd-parse.c" |
2048 | 0 | break; |
2049 | | |
2050 | 0 | case 47: |
2051 | 0 | #line 582 "cmd-parse.y" |
2052 | 0 | { |
2053 | 0 | (yyval.commands) = (yyvsp[-2].commands); |
2054 | 0 | TAILQ_CONCAT((yyval.commands), (yyvsp[-1].commands), entry); |
2055 | 0 | free((yyvsp[-1].commands)); |
2056 | 0 | } |
2057 | 0 | #line 2058 "cmd-parse.c" |
2058 | 0 | break; |
2059 | | |
2060 | | |
2061 | 0 | #line 2062 "cmd-parse.c" |
2062 | | |
2063 | 2 | default: break; |
2064 | 12 | } |
2065 | | /* User semantic actions sometimes alter yychar, and that requires |
2066 | | that yytoken be updated with the new translation. We take the |
2067 | | approach of translating immediately before every use of yytoken. |
2068 | | One alternative is translating here after every semantic action, |
2069 | | but that translation would be missed if the semantic action invokes |
2070 | | YYABORT, YYACCEPT, or YYERROR immediately after altering yychar or |
2071 | | if it invokes YYBACKUP. In the case of YYABORT or YYACCEPT, an |
2072 | | incorrect destructor might then be invoked immediately. In the |
2073 | | case of YYERROR or YYBACKUP, subsequent parser actions might lead |
2074 | | to an incorrect destructor call or verbose syntax error message |
2075 | | before the lookahead is translated. */ |
2076 | 12 | YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc); |
2077 | | |
2078 | 12 | YYPOPSTACK (yylen); |
2079 | 12 | yylen = 0; |
2080 | 12 | YY_STACK_PRINT (yyss, yyssp); |
2081 | | |
2082 | 12 | *++yyvsp = yyval; |
2083 | | |
2084 | | /* Now 'shift' the result of the reduction. Determine what state |
2085 | | that goes to, based on the state we popped back to and the rule |
2086 | | number reduced by. */ |
2087 | 12 | { |
2088 | 12 | const int yylhs = yyr1[yyn] - YYNTOKENS; |
2089 | 12 | const int yyi = yypgoto[yylhs] + *yyssp; |
2090 | 12 | yystate = (0 <= yyi && yyi <= YYLAST && yycheck[yyi] == *yyssp |
2091 | 12 | ? yytable[yyi] |
2092 | 12 | : yydefgoto[yylhs]); |
2093 | 12 | } |
2094 | | |
2095 | 12 | goto yynewstate; |
2096 | | |
2097 | | |
2098 | | /*--------------------------------------. |
2099 | | | yyerrlab -- here on detecting error. | |
2100 | | `--------------------------------------*/ |
2101 | 0 | yyerrlab: |
2102 | | /* Make sure we have latest lookahead translation. See comments at |
2103 | | user semantic actions for why this is necessary. */ |
2104 | 0 | yytoken = yychar == YYEMPTY ? YYEMPTY : YYTRANSLATE (yychar); |
2105 | | |
2106 | | /* If not already recovering from an error, report this error. */ |
2107 | 0 | if (!yyerrstatus) |
2108 | 0 | { |
2109 | 0 | ++yynerrs; |
2110 | 0 | #if ! YYERROR_VERBOSE |
2111 | 0 | yyerror (YY_("syntax error")); |
2112 | | #else |
2113 | | # define YYSYNTAX_ERROR yysyntax_error (&yymsg_alloc, &yymsg, \ |
2114 | | yyssp, yytoken) |
2115 | | { |
2116 | | char const *yymsgp = YY_("syntax error"); |
2117 | | int yysyntax_error_status; |
2118 | | yysyntax_error_status = YYSYNTAX_ERROR; |
2119 | | if (yysyntax_error_status == 0) |
2120 | | yymsgp = yymsg; |
2121 | | else if (yysyntax_error_status == 1) |
2122 | | { |
2123 | | if (yymsg != yymsgbuf) |
2124 | | YYSTACK_FREE (yymsg); |
2125 | | yymsg = YY_CAST (char *, YYSTACK_ALLOC (YY_CAST (YYSIZE_T, yymsg_alloc))); |
2126 | | if (!yymsg) |
2127 | | { |
2128 | | yymsg = yymsgbuf; |
2129 | | yymsg_alloc = sizeof yymsgbuf; |
2130 | | yysyntax_error_status = 2; |
2131 | | } |
2132 | | else |
2133 | | { |
2134 | | yysyntax_error_status = YYSYNTAX_ERROR; |
2135 | | yymsgp = yymsg; |
2136 | | } |
2137 | | } |
2138 | | yyerror (yymsgp); |
2139 | | if (yysyntax_error_status == 2) |
2140 | | goto yyexhaustedlab; |
2141 | | } |
2142 | | # undef YYSYNTAX_ERROR |
2143 | | #endif |
2144 | 0 | } |
2145 | | |
2146 | | |
2147 | |
|
2148 | 0 | if (yyerrstatus == 3) |
2149 | 0 | { |
2150 | | /* If just tried and failed to reuse lookahead token after an |
2151 | | error, discard it. */ |
2152 | |
|
2153 | 0 | if (yychar <= YYEOF) |
2154 | 0 | { |
2155 | | /* Return failure if at end of input. */ |
2156 | 0 | if (yychar == YYEOF) |
2157 | 0 | YYABORT; |
2158 | 0 | } |
2159 | 0 | else |
2160 | 0 | { |
2161 | 0 | yydestruct ("Error: discarding", |
2162 | 0 | yytoken, &yylval); |
2163 | 0 | yychar = YYEMPTY; |
2164 | 0 | } |
2165 | 0 | } |
2166 | | |
2167 | | /* Else will try to reuse lookahead token after shifting the error |
2168 | | token. */ |
2169 | 0 | goto yyerrlab1; |
2170 | | |
2171 | | |
2172 | | /*---------------------------------------------------. |
2173 | | | yyerrorlab -- error raised explicitly by YYERROR. | |
2174 | | `---------------------------------------------------*/ |
2175 | 0 | yyerrorlab: |
2176 | | /* Pacify compilers when the user code never invokes YYERROR and the |
2177 | | label yyerrorlab therefore never appears in user code. */ |
2178 | 0 | if (0) |
2179 | 0 | YYERROR; |
2180 | | |
2181 | | /* Do not reclaim the symbols of the rule whose action triggered |
2182 | | this YYERROR. */ |
2183 | 0 | YYPOPSTACK (yylen); |
2184 | 0 | yylen = 0; |
2185 | 0 | YY_STACK_PRINT (yyss, yyssp); |
2186 | 0 | yystate = *yyssp; |
2187 | 0 | goto yyerrlab1; |
2188 | | |
2189 | | |
2190 | | /*-------------------------------------------------------------. |
2191 | | | yyerrlab1 -- common code for both syntax error and YYERROR. | |
2192 | | `-------------------------------------------------------------*/ |
2193 | 0 | yyerrlab1: |
2194 | 0 | yyerrstatus = 3; /* Each real token shifted decrements this. */ |
2195 | |
|
2196 | 0 | for (;;) |
2197 | 0 | { |
2198 | 0 | yyn = yypact[yystate]; |
2199 | 0 | if (!yypact_value_is_default (yyn)) |
2200 | 0 | { |
2201 | 0 | yyn += YYTERROR; |
2202 | 0 | if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR) |
2203 | 0 | { |
2204 | 0 | yyn = yytable[yyn]; |
2205 | 0 | if (0 < yyn) |
2206 | 0 | break; |
2207 | 0 | } |
2208 | 0 | } |
2209 | | |
2210 | | /* Pop the current state because it cannot handle the error token. */ |
2211 | 0 | if (yyssp == yyss) |
2212 | 0 | YYABORT; |
2213 | | |
2214 | | |
2215 | 0 | yydestruct ("Error: popping", |
2216 | 0 | yystos[yystate], yyvsp); |
2217 | 0 | YYPOPSTACK (1); |
2218 | 0 | yystate = *yyssp; |
2219 | 0 | YY_STACK_PRINT (yyss, yyssp); |
2220 | 0 | } |
2221 | | |
2222 | 0 | YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN |
2223 | 0 | *++yyvsp = yylval; |
2224 | 0 | YY_IGNORE_MAYBE_UNINITIALIZED_END |
2225 | | |
2226 | | |
2227 | | /* Shift the error token. */ |
2228 | 0 | YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp); |
2229 | |
|
2230 | 0 | yystate = yyn; |
2231 | 0 | goto yynewstate; |
2232 | | |
2233 | | |
2234 | | /*-------------------------------------. |
2235 | | | yyacceptlab -- YYACCEPT comes here. | |
2236 | | `-------------------------------------*/ |
2237 | 2 | yyacceptlab: |
2238 | 2 | yyresult = 0; |
2239 | 2 | goto yyreturn; |
2240 | | |
2241 | | |
2242 | | /*-----------------------------------. |
2243 | | | yyabortlab -- YYABORT comes here. | |
2244 | | `-----------------------------------*/ |
2245 | 0 | yyabortlab: |
2246 | 0 | yyresult = 1; |
2247 | 0 | goto yyreturn; |
2248 | | |
2249 | | |
2250 | 0 | #if !defined yyoverflow || YYERROR_VERBOSE |
2251 | | /*-------------------------------------------------. |
2252 | | | yyexhaustedlab -- memory exhaustion comes here. | |
2253 | | `-------------------------------------------------*/ |
2254 | 0 | yyexhaustedlab: |
2255 | 0 | yyerror (YY_("memory exhausted")); |
2256 | 0 | yyresult = 2; |
2257 | | /* Fall through. */ |
2258 | 0 | #endif |
2259 | | |
2260 | | |
2261 | | /*-----------------------------------------------------. |
2262 | | | yyreturn -- parsing is finished, return the result. | |
2263 | | `-----------------------------------------------------*/ |
2264 | 2 | yyreturn: |
2265 | 2 | if (yychar != YYEMPTY) |
2266 | 0 | { |
2267 | | /* Make sure we have latest lookahead translation. See comments at |
2268 | | user semantic actions for why this is necessary. */ |
2269 | 0 | yytoken = YYTRANSLATE (yychar); |
2270 | 0 | yydestruct ("Cleanup: discarding lookahead", |
2271 | 0 | yytoken, &yylval); |
2272 | 0 | } |
2273 | | /* Do not reclaim the symbols of the rule whose action triggered |
2274 | | this YYABORT or YYACCEPT. */ |
2275 | 2 | YYPOPSTACK (yylen); |
2276 | 2 | YY_STACK_PRINT (yyss, yyssp); |
2277 | 6 | while (yyssp != yyss) |
2278 | 4 | { |
2279 | 4 | yydestruct ("Cleanup: popping", |
2280 | 4 | yystos[+*yyssp], yyvsp); |
2281 | 4 | YYPOPSTACK (1); |
2282 | 4 | } |
2283 | 2 | #ifndef yyoverflow |
2284 | 2 | if (yyss != yyssa) |
2285 | 0 | YYSTACK_FREE (yyss); |
2286 | 2 | #endif |
2287 | | #if YYERROR_VERBOSE |
2288 | | if (yymsg != yymsgbuf) |
2289 | | YYSTACK_FREE (yymsg); |
2290 | | #endif |
2291 | 2 | return yyresult; |
2292 | 0 | } |
2293 | | #line 588 "cmd-parse.y" |
2294 | | |
2295 | | |
2296 | | static char * |
2297 | | cmd_parse_get_error(const char *file, u_int line, const char *error) |
2298 | 0 | { |
2299 | 0 | char *s; |
2300 | |
|
2301 | 0 | if (file == NULL) |
2302 | 0 | s = xstrdup(error); |
2303 | 0 | else |
2304 | 0 | xasprintf(&s, "%s:%u: %s", file, line, error); |
2305 | 0 | return (s); |
2306 | 0 | } |
2307 | | |
2308 | | static void |
2309 | | cmd_parse_print_commands(struct cmd_parse_input *pi, struct cmd_list *cmdlist) |
2310 | 2 | { |
2311 | 2 | char *s; |
2312 | | |
2313 | 2 | if (pi->item == NULL || (~pi->flags & CMD_PARSE_VERBOSE)) |
2314 | 2 | return; |
2315 | 0 | s = cmd_list_print(cmdlist, 0); |
2316 | 0 | if (pi->file != NULL) |
2317 | 0 | cmdq_print(pi->item, "%s:%u: %s", pi->file, pi->line, s); |
2318 | 0 | else |
2319 | 0 | cmdq_print(pi->item, "%u: %s", pi->line, s); |
2320 | 0 | free(s); |
2321 | 0 | } |
2322 | | |
2323 | | static void |
2324 | | cmd_parse_free_argument(struct cmd_parse_argument *arg) |
2325 | 2 | { |
2326 | 2 | switch (arg->type) { |
2327 | 2 | case CMD_PARSE_STRING: |
2328 | 2 | free(arg->string); |
2329 | 2 | break; |
2330 | 0 | case CMD_PARSE_COMMANDS: |
2331 | 0 | cmd_parse_free_commands(arg->commands); |
2332 | 0 | break; |
2333 | 0 | case CMD_PARSE_PARSED_COMMANDS: |
2334 | 0 | cmd_list_free(arg->cmdlist); |
2335 | 0 | break; |
2336 | 2 | } |
2337 | 2 | free(arg); |
2338 | 2 | } |
2339 | | |
2340 | | static void |
2341 | | cmd_parse_free_arguments(struct cmd_parse_arguments *args) |
2342 | 2 | { |
2343 | 2 | struct cmd_parse_argument *arg, *arg1; |
2344 | | |
2345 | 2 | TAILQ_FOREACH_SAFE(arg, args, entry, arg1) { |
2346 | 2 | TAILQ_REMOVE(args, arg, entry); |
2347 | 2 | cmd_parse_free_argument(arg); |
2348 | 2 | } |
2349 | 2 | } |
2350 | | |
2351 | | static void |
2352 | | cmd_parse_free_command(struct cmd_parse_command *cmd) |
2353 | 2 | { |
2354 | 2 | cmd_parse_free_arguments(&cmd->arguments); |
2355 | 2 | free(cmd); |
2356 | 2 | } |
2357 | | |
2358 | | static struct cmd_parse_commands * |
2359 | | cmd_parse_new_commands(void) |
2360 | 2 | { |
2361 | 2 | struct cmd_parse_commands *cmds; |
2362 | | |
2363 | 2 | cmds = xmalloc(sizeof *cmds); |
2364 | 2 | TAILQ_INIT(cmds); |
2365 | 2 | return (cmds); |
2366 | 2 | } |
2367 | | |
2368 | | static void |
2369 | | cmd_parse_free_commands(struct cmd_parse_commands *cmds) |
2370 | 2 | { |
2371 | 2 | struct cmd_parse_command *cmd, *cmd1; |
2372 | | |
2373 | 2 | TAILQ_FOREACH_SAFE(cmd, cmds, entry, cmd1) { |
2374 | 2 | TAILQ_REMOVE(cmds, cmd, entry); |
2375 | 2 | cmd_parse_free_command(cmd); |
2376 | 2 | } |
2377 | 2 | free(cmds); |
2378 | 2 | } |
2379 | | |
2380 | | static struct cmd_parse_commands * |
2381 | | cmd_parse_run_parser(char **cause) |
2382 | 2 | { |
2383 | 2 | struct cmd_parse_state *ps = &parse_state; |
2384 | 2 | struct cmd_parse_scope *scope, *scope1; |
2385 | 2 | int retval; |
2386 | | |
2387 | 2 | ps->commands = NULL; |
2388 | 2 | TAILQ_INIT(&ps->stack); |
2389 | | |
2390 | 2 | retval = yyparse(); |
2391 | 2 | TAILQ_FOREACH_SAFE(scope, &ps->stack, entry, scope1) { |
2392 | 0 | TAILQ_REMOVE(&ps->stack, scope, entry); |
2393 | 0 | free(scope); |
2394 | 0 | } |
2395 | 2 | if (retval != 0) { |
2396 | 0 | *cause = ps->error; |
2397 | 0 | return (NULL); |
2398 | 0 | } |
2399 | | |
2400 | 2 | if (ps->commands == NULL) |
2401 | 0 | return (cmd_parse_new_commands()); |
2402 | 2 | return (ps->commands); |
2403 | 2 | } |
2404 | | |
2405 | | static struct cmd_parse_commands * |
2406 | | cmd_parse_do_file(FILE *f, struct cmd_parse_input *pi, char **cause) |
2407 | 0 | { |
2408 | 0 | struct cmd_parse_state *ps = &parse_state; |
2409 | |
|
2410 | 0 | memset(ps, 0, sizeof *ps); |
2411 | 0 | ps->input = pi; |
2412 | 0 | ps->f = f; |
2413 | 0 | return (cmd_parse_run_parser(cause)); |
2414 | 0 | } |
2415 | | |
2416 | | static struct cmd_parse_commands * |
2417 | | cmd_parse_do_buffer(const char *buf, size_t len, struct cmd_parse_input *pi, |
2418 | | char **cause) |
2419 | 2 | { |
2420 | 2 | struct cmd_parse_state *ps = &parse_state; |
2421 | | |
2422 | 2 | memset(ps, 0, sizeof *ps); |
2423 | 2 | ps->input = pi; |
2424 | 2 | ps->buf = buf; |
2425 | 2 | ps->len = len; |
2426 | 2 | return (cmd_parse_run_parser(cause)); |
2427 | 2 | } |
2428 | | |
2429 | | static void |
2430 | | cmd_parse_log_commands(struct cmd_parse_commands *cmds, const char *prefix) |
2431 | 2 | { |
2432 | 2 | struct cmd_parse_command *cmd; |
2433 | 2 | struct cmd_parse_argument *arg; |
2434 | 2 | u_int i, j; |
2435 | 2 | char *s; |
2436 | | |
2437 | 2 | i = 0; |
2438 | 2 | TAILQ_FOREACH(cmd, cmds, entry) { |
2439 | 2 | j = 0; |
2440 | 2 | TAILQ_FOREACH(arg, &cmd->arguments, entry) { |
2441 | 2 | switch (arg->type) { |
2442 | 2 | case CMD_PARSE_STRING: |
2443 | 2 | log_debug("%s %u:%u: %s", prefix, i, j, |
2444 | 2 | arg->string); |
2445 | 2 | break; |
2446 | 0 | case CMD_PARSE_COMMANDS: |
2447 | 0 | xasprintf(&s, "%s %u:%u", prefix, i, j); |
2448 | 0 | cmd_parse_log_commands(arg->commands, s); |
2449 | 0 | free(s); |
2450 | 0 | break; |
2451 | 0 | case CMD_PARSE_PARSED_COMMANDS: |
2452 | 0 | s = cmd_list_print(arg->cmdlist, 0); |
2453 | 0 | log_debug("%s %u:%u: %s", prefix, i, j, s); |
2454 | 0 | free(s); |
2455 | 0 | break; |
2456 | 2 | } |
2457 | 2 | j++; |
2458 | 2 | } |
2459 | 2 | i++; |
2460 | 2 | } |
2461 | 2 | } |
2462 | | |
2463 | | static int |
2464 | | cmd_parse_expand_alias(struct cmd_parse_command *cmd, |
2465 | | struct cmd_parse_input *pi, struct cmd_parse_result *pr) |
2466 | 2 | { |
2467 | 2 | struct cmd_parse_argument *arg, *arg1, *first; |
2468 | 2 | struct cmd_parse_commands *cmds; |
2469 | 2 | struct cmd_parse_command *last; |
2470 | 2 | char *alias, *name, *cause; |
2471 | | |
2472 | 2 | if (pi->flags & CMD_PARSE_NOALIAS) |
2473 | 0 | return (0); |
2474 | 2 | memset(pr, 0, sizeof *pr); |
2475 | | |
2476 | 2 | first = TAILQ_FIRST(&cmd->arguments); |
2477 | 2 | if (first == NULL || first->type != CMD_PARSE_STRING) { |
2478 | 0 | pr->status = CMD_PARSE_SUCCESS; |
2479 | 0 | pr->cmdlist = cmd_list_new(); |
2480 | 0 | return (1); |
2481 | 0 | } |
2482 | 2 | name = first->string; |
2483 | | |
2484 | 2 | alias = cmd_get_alias(name); |
2485 | 2 | if (alias == NULL) |
2486 | 2 | return (0); |
2487 | 0 | log_debug("%s: %u alias %s = %s", __func__, pi->line, name, alias); |
2488 | |
|
2489 | 0 | cmds = cmd_parse_do_buffer(alias, strlen(alias), pi, &cause); |
2490 | 0 | free(alias); |
2491 | 0 | if (cmds == NULL) { |
2492 | 0 | pr->status = CMD_PARSE_ERROR; |
2493 | 0 | pr->error = cause; |
2494 | 0 | return (1); |
2495 | 0 | } |
2496 | | |
2497 | 0 | last = TAILQ_LAST(cmds, cmd_parse_commands); |
2498 | 0 | if (last == NULL) { |
2499 | 0 | pr->status = CMD_PARSE_SUCCESS; |
2500 | 0 | pr->cmdlist = cmd_list_new(); |
2501 | 0 | return (1); |
2502 | 0 | } |
2503 | | |
2504 | 0 | TAILQ_REMOVE(&cmd->arguments, first, entry); |
2505 | 0 | cmd_parse_free_argument(first); |
2506 | |
|
2507 | 0 | TAILQ_FOREACH_SAFE(arg, &cmd->arguments, entry, arg1) { |
2508 | 0 | TAILQ_REMOVE(&cmd->arguments, arg, entry); |
2509 | 0 | TAILQ_INSERT_TAIL(&last->arguments, arg, entry); |
2510 | 0 | } |
2511 | 0 | cmd_parse_log_commands(cmds, __func__); |
2512 | |
|
2513 | 0 | pi->flags |= CMD_PARSE_NOALIAS; |
2514 | 0 | cmd_parse_build_commands(cmds, pi, pr); |
2515 | 0 | pi->flags &= ~CMD_PARSE_NOALIAS; |
2516 | 0 | return (1); |
2517 | 0 | } |
2518 | | |
2519 | | static void |
2520 | | cmd_parse_build_command(struct cmd_parse_command *cmd, |
2521 | | struct cmd_parse_input *pi, struct cmd_parse_result *pr) |
2522 | 2 | { |
2523 | 2 | struct cmd_parse_argument *arg; |
2524 | 2 | struct cmd *add; |
2525 | 2 | char *cause; |
2526 | 2 | struct args_value *values = NULL; |
2527 | 2 | u_int count = 0, idx; |
2528 | | |
2529 | 2 | memset(pr, 0, sizeof *pr); |
2530 | | |
2531 | 2 | if (cmd_parse_expand_alias(cmd, pi, pr)) |
2532 | 0 | return; |
2533 | | |
2534 | 2 | TAILQ_FOREACH(arg, &cmd->arguments, entry) { |
2535 | 2 | values = xrecallocarray(values, count, count + 1, |
2536 | 2 | sizeof *values); |
2537 | 2 | switch (arg->type) { |
2538 | 2 | case CMD_PARSE_STRING: |
2539 | 2 | values[count].type = ARGS_STRING; |
2540 | 2 | values[count].string = xstrdup(arg->string); |
2541 | 2 | break; |
2542 | 0 | case CMD_PARSE_COMMANDS: |
2543 | 0 | cmd_parse_build_commands(arg->commands, pi, pr); |
2544 | 0 | if (pr->status != CMD_PARSE_SUCCESS) |
2545 | 0 | goto out; |
2546 | 0 | values[count].type = ARGS_COMMANDS; |
2547 | 0 | values[count].cmdlist = pr->cmdlist; |
2548 | 0 | break; |
2549 | 0 | case CMD_PARSE_PARSED_COMMANDS: |
2550 | 0 | values[count].type = ARGS_COMMANDS; |
2551 | 0 | values[count].cmdlist = arg->cmdlist; |
2552 | 0 | values[count].cmdlist->references++; |
2553 | 0 | break; |
2554 | 2 | } |
2555 | 2 | count++; |
2556 | 2 | } |
2557 | | |
2558 | 2 | add = cmd_parse(values, count, pi->file, pi->line, &cause); |
2559 | 2 | if (add == NULL) { |
2560 | 0 | pr->status = CMD_PARSE_ERROR; |
2561 | 0 | pr->error = cmd_parse_get_error(pi->file, pi->line, cause); |
2562 | 0 | free(cause); |
2563 | 0 | goto out; |
2564 | 0 | } |
2565 | 2 | pr->status = CMD_PARSE_SUCCESS; |
2566 | 2 | pr->cmdlist = cmd_list_new(); |
2567 | 2 | cmd_list_append(pr->cmdlist, add); |
2568 | | |
2569 | 2 | out: |
2570 | 4 | for (idx = 0; idx < count; idx++) |
2571 | 2 | args_free_value(&values[idx]); |
2572 | 2 | free(values); |
2573 | 2 | } |
2574 | | |
2575 | | static void |
2576 | | cmd_parse_build_commands(struct cmd_parse_commands *cmds, |
2577 | | struct cmd_parse_input *pi, struct cmd_parse_result *pr) |
2578 | 2 | { |
2579 | 2 | struct cmd_parse_command *cmd; |
2580 | 2 | u_int line = UINT_MAX; |
2581 | 2 | struct cmd_list *current = NULL, *result; |
2582 | 2 | char *s; |
2583 | | |
2584 | 2 | memset(pr, 0, sizeof *pr); |
2585 | | |
2586 | | /* Check for an empty list. */ |
2587 | 2 | if (TAILQ_EMPTY(cmds)) { |
2588 | 0 | pr->status = CMD_PARSE_SUCCESS; |
2589 | 0 | pr->cmdlist = cmd_list_new(); |
2590 | 0 | return; |
2591 | 0 | } |
2592 | 2 | cmd_parse_log_commands(cmds, __func__); |
2593 | | |
2594 | | /* |
2595 | | * Parse each command into a command list. Create a new command list |
2596 | | * for each line (unless the flag is set) so they get a new group (so |
2597 | | * the queue knows which ones to remove if a command fails when |
2598 | | * executed). |
2599 | | */ |
2600 | 2 | result = cmd_list_new(); |
2601 | 2 | TAILQ_FOREACH(cmd, cmds, entry) { |
2602 | 2 | if (((~pi->flags & CMD_PARSE_ONEGROUP) && cmd->line != line)) { |
2603 | 0 | if (current != NULL) { |
2604 | 0 | cmd_parse_print_commands(pi, current); |
2605 | 0 | cmd_list_move(result, current); |
2606 | 0 | cmd_list_free(current); |
2607 | 0 | } |
2608 | 0 | current = cmd_list_new(); |
2609 | 0 | } |
2610 | 2 | if (current == NULL) |
2611 | 2 | current = cmd_list_new(); |
2612 | 2 | line = pi->line = cmd->line; |
2613 | | |
2614 | 2 | cmd_parse_build_command(cmd, pi, pr); |
2615 | 2 | if (pr->status != CMD_PARSE_SUCCESS) { |
2616 | 0 | cmd_list_free(result); |
2617 | 0 | cmd_list_free(current); |
2618 | 0 | return; |
2619 | 0 | } |
2620 | 2 | cmd_list_append_all(current, pr->cmdlist); |
2621 | 2 | cmd_list_free(pr->cmdlist); |
2622 | 2 | } |
2623 | 2 | if (current != NULL) { |
2624 | 2 | cmd_parse_print_commands(pi, current); |
2625 | 2 | cmd_list_move(result, current); |
2626 | 2 | cmd_list_free(current); |
2627 | 2 | } |
2628 | | |
2629 | 2 | s = cmd_list_print(result, 0); |
2630 | 2 | log_debug("%s: %s", __func__, s); |
2631 | 2 | free(s); |
2632 | | |
2633 | 2 | pr->status = CMD_PARSE_SUCCESS; |
2634 | 2 | pr->cmdlist = result; |
2635 | 2 | } |
2636 | | |
2637 | | struct cmd_parse_result * |
2638 | | cmd_parse_from_file(FILE *f, struct cmd_parse_input *pi) |
2639 | 0 | { |
2640 | 0 | static struct cmd_parse_result pr; |
2641 | 0 | struct cmd_parse_input input; |
2642 | 0 | struct cmd_parse_commands *cmds; |
2643 | 0 | char *cause; |
2644 | |
|
2645 | 0 | if (pi == NULL) { |
2646 | 0 | memset(&input, 0, sizeof input); |
2647 | 0 | pi = &input; |
2648 | 0 | } |
2649 | 0 | memset(&pr, 0, sizeof pr); |
2650 | |
|
2651 | 0 | cmds = cmd_parse_do_file(f, pi, &cause); |
2652 | 0 | if (cmds == NULL) { |
2653 | 0 | pr.status = CMD_PARSE_ERROR; |
2654 | 0 | pr.error = cause; |
2655 | 0 | return (&pr); |
2656 | 0 | } |
2657 | 0 | cmd_parse_build_commands(cmds, pi, &pr); |
2658 | 0 | cmd_parse_free_commands(cmds); |
2659 | 0 | return (&pr); |
2660 | |
|
2661 | 0 | } |
2662 | | |
2663 | | struct cmd_parse_result * |
2664 | | cmd_parse_from_string(const char *s, struct cmd_parse_input *pi) |
2665 | 2 | { |
2666 | 2 | struct cmd_parse_input input; |
2667 | | |
2668 | 2 | if (pi == NULL) { |
2669 | 2 | memset(&input, 0, sizeof input); |
2670 | 2 | pi = &input; |
2671 | 2 | } |
2672 | | |
2673 | | /* |
2674 | | * When parsing a string, put commands in one group even if there are |
2675 | | * multiple lines. This means { a \n b } is identical to "a ; b" when |
2676 | | * given as an argument to another command. |
2677 | | */ |
2678 | 2 | pi->flags |= CMD_PARSE_ONEGROUP; |
2679 | 2 | return (cmd_parse_from_buffer(s, strlen(s), pi)); |
2680 | 2 | } |
2681 | | |
2682 | | enum cmd_parse_status |
2683 | | cmd_parse_and_insert(const char *s, struct cmd_parse_input *pi, |
2684 | | struct cmdq_item *after, struct cmdq_state *state, char **error) |
2685 | 0 | { |
2686 | 0 | struct cmd_parse_result *pr; |
2687 | 0 | struct cmdq_item *item; |
2688 | |
|
2689 | 0 | pr = cmd_parse_from_string(s, pi); |
2690 | 0 | switch (pr->status) { |
2691 | 0 | case CMD_PARSE_ERROR: |
2692 | 0 | if (error != NULL) |
2693 | 0 | *error = pr->error; |
2694 | 0 | else |
2695 | 0 | free(pr->error); |
2696 | 0 | break; |
2697 | 0 | case CMD_PARSE_SUCCESS: |
2698 | 0 | item = cmdq_get_command(pr->cmdlist, state); |
2699 | 0 | cmdq_insert_after(after, item); |
2700 | 0 | cmd_list_free(pr->cmdlist); |
2701 | 0 | break; |
2702 | 0 | } |
2703 | 0 | return (pr->status); |
2704 | 0 | } |
2705 | | |
2706 | | enum cmd_parse_status |
2707 | | cmd_parse_and_append(const char *s, struct cmd_parse_input *pi, |
2708 | | struct client *c, struct cmdq_state *state, char **error) |
2709 | 0 | { |
2710 | 0 | struct cmd_parse_result *pr; |
2711 | 0 | struct cmdq_item *item; |
2712 | |
|
2713 | 0 | pr = cmd_parse_from_string(s, pi); |
2714 | 0 | switch (pr->status) { |
2715 | 0 | case CMD_PARSE_ERROR: |
2716 | 0 | if (error != NULL) |
2717 | 0 | *error = pr->error; |
2718 | 0 | else |
2719 | 0 | free(pr->error); |
2720 | 0 | break; |
2721 | 0 | case CMD_PARSE_SUCCESS: |
2722 | 0 | item = cmdq_get_command(pr->cmdlist, state); |
2723 | 0 | cmdq_append(c, item); |
2724 | 0 | cmd_list_free(pr->cmdlist); |
2725 | 0 | break; |
2726 | 0 | } |
2727 | 0 | return (pr->status); |
2728 | 0 | } |
2729 | | |
2730 | | struct cmd_parse_result * |
2731 | | cmd_parse_from_buffer(const void *buf, size_t len, struct cmd_parse_input *pi) |
2732 | 2 | { |
2733 | 2 | static struct cmd_parse_result pr; |
2734 | 2 | struct cmd_parse_input input; |
2735 | 2 | struct cmd_parse_commands *cmds; |
2736 | 2 | char *cause; |
2737 | | |
2738 | 2 | if (pi == NULL) { |
2739 | 0 | memset(&input, 0, sizeof input); |
2740 | 0 | pi = &input; |
2741 | 0 | } |
2742 | 2 | memset(&pr, 0, sizeof pr); |
2743 | | |
2744 | 2 | if (len == 0) { |
2745 | 0 | pr.status = CMD_PARSE_SUCCESS; |
2746 | 0 | pr.cmdlist = cmd_list_new(); |
2747 | 0 | return (&pr); |
2748 | 0 | } |
2749 | | |
2750 | 2 | cmds = cmd_parse_do_buffer(buf, len, pi, &cause); |
2751 | 2 | if (cmds == NULL) { |
2752 | 0 | pr.status = CMD_PARSE_ERROR; |
2753 | 0 | pr.error = cause; |
2754 | 0 | return (&pr); |
2755 | 0 | } |
2756 | 2 | cmd_parse_build_commands(cmds, pi, &pr); |
2757 | 2 | cmd_parse_free_commands(cmds); |
2758 | 2 | return (&pr); |
2759 | 2 | } |
2760 | | |
2761 | | struct cmd_parse_result * |
2762 | | cmd_parse_from_arguments(struct args_value *values, u_int count, |
2763 | | struct cmd_parse_input *pi) |
2764 | 0 | { |
2765 | 0 | static struct cmd_parse_result pr; |
2766 | 0 | struct cmd_parse_input input; |
2767 | 0 | struct cmd_parse_commands *cmds; |
2768 | 0 | struct cmd_parse_command *cmd; |
2769 | 0 | struct cmd_parse_argument *arg; |
2770 | 0 | u_int i; |
2771 | 0 | char *copy; |
2772 | 0 | size_t size; |
2773 | 0 | int end; |
2774 | | |
2775 | | /* |
2776 | | * The commands are already split up into arguments, so just separate |
2777 | | * into a set of commands by ';'. |
2778 | | */ |
2779 | |
|
2780 | 0 | if (pi == NULL) { |
2781 | 0 | memset(&input, 0, sizeof input); |
2782 | 0 | pi = &input; |
2783 | 0 | } |
2784 | 0 | memset(&pr, 0, sizeof pr); |
2785 | |
|
2786 | 0 | cmds = cmd_parse_new_commands(); |
2787 | |
|
2788 | 0 | cmd = xcalloc(1, sizeof *cmd); |
2789 | 0 | cmd->line = pi->line; |
2790 | 0 | TAILQ_INIT(&cmd->arguments); |
2791 | |
|
2792 | 0 | for (i = 0; i < count; i++) { |
2793 | 0 | end = 0; |
2794 | 0 | if (values[i].type == ARGS_STRING) { |
2795 | 0 | copy = xstrdup(values[i].string); |
2796 | 0 | size = strlen(copy); |
2797 | 0 | if (size != 0 && copy[size - 1] == ';') { |
2798 | 0 | copy[--size] = '\0'; |
2799 | 0 | if (size > 0 && copy[size - 1] == '\\') |
2800 | 0 | copy[size - 1] = ';'; |
2801 | 0 | else |
2802 | 0 | end = 1; |
2803 | 0 | } |
2804 | 0 | if (!end || size != 0) { |
2805 | 0 | arg = xcalloc(1, sizeof *arg); |
2806 | 0 | arg->type = CMD_PARSE_STRING; |
2807 | 0 | arg->string = copy; |
2808 | 0 | TAILQ_INSERT_TAIL(&cmd->arguments, arg, entry); |
2809 | 0 | } else |
2810 | 0 | free(copy); |
2811 | 0 | } else if (values[i].type == ARGS_COMMANDS) { |
2812 | 0 | arg = xcalloc(1, sizeof *arg); |
2813 | 0 | arg->type = CMD_PARSE_PARSED_COMMANDS; |
2814 | 0 | arg->cmdlist = values[i].cmdlist; |
2815 | 0 | arg->cmdlist->references++; |
2816 | 0 | TAILQ_INSERT_TAIL(&cmd->arguments, arg, entry); |
2817 | 0 | } else |
2818 | 0 | fatalx("unknown argument type"); |
2819 | 0 | if (end) { |
2820 | 0 | TAILQ_INSERT_TAIL(cmds, cmd, entry); |
2821 | 0 | cmd = xcalloc(1, sizeof *cmd); |
2822 | 0 | cmd->line = pi->line; |
2823 | 0 | TAILQ_INIT(&cmd->arguments); |
2824 | 0 | } |
2825 | 0 | } |
2826 | 0 | if (!TAILQ_EMPTY(&cmd->arguments)) |
2827 | 0 | TAILQ_INSERT_TAIL(cmds, cmd, entry); |
2828 | 0 | else |
2829 | 0 | free(cmd); |
2830 | |
|
2831 | 0 | cmd_parse_build_commands(cmds, pi, &pr); |
2832 | 0 | cmd_parse_free_commands(cmds); |
2833 | 0 | return (&pr); |
2834 | 0 | } |
2835 | | |
2836 | | static void printflike(1, 2) |
2837 | | yyerror(const char *fmt, ...) |
2838 | 0 | { |
2839 | 0 | struct cmd_parse_state *ps = &parse_state; |
2840 | 0 | struct cmd_parse_input *pi = ps->input; |
2841 | 0 | va_list ap; |
2842 | 0 | char *error; |
2843 | |
|
2844 | 0 | if (ps->error != NULL) |
2845 | 0 | return; |
2846 | | |
2847 | 0 | va_start(ap, fmt); |
2848 | 0 | xvasprintf(&error, fmt, ap); |
2849 | 0 | va_end(ap); |
2850 | |
|
2851 | 0 | ps->error = cmd_parse_get_error(pi->file, pi->line, error); |
2852 | 0 | free(error); |
2853 | 0 | } |
2854 | | |
2855 | | static int |
2856 | | yylex_is_var(char ch, int first) |
2857 | 0 | { |
2858 | 0 | if (ch == '=') |
2859 | 0 | return (0); |
2860 | 0 | if (first && isdigit((u_char)ch)) |
2861 | 0 | return (0); |
2862 | 0 | return (isalnum((u_char)ch) || ch == '_'); |
2863 | 0 | } |
2864 | | |
2865 | | static void |
2866 | | yylex_append(char **buf, size_t *len, const char *add, size_t addlen) |
2867 | 22 | { |
2868 | 22 | if (addlen > SIZE_MAX - 1 || *len > SIZE_MAX - 1 - addlen) |
2869 | 0 | fatalx("buffer is too big"); |
2870 | 22 | *buf = xrealloc(*buf, (*len) + 1 + addlen); |
2871 | 22 | memcpy((*buf) + *len, add, addlen); |
2872 | 22 | (*len) += addlen; |
2873 | 22 | } |
2874 | | |
2875 | | static void |
2876 | | yylex_append1(char **buf, size_t *len, char add) |
2877 | 22 | { |
2878 | 22 | yylex_append(buf, len, &add, 1); |
2879 | 22 | } |
2880 | | |
2881 | | static int |
2882 | | yylex_getc1(void) |
2883 | 28 | { |
2884 | 28 | struct cmd_parse_state *ps = &parse_state; |
2885 | 28 | int ch; |
2886 | | |
2887 | 28 | if (ps->f != NULL) |
2888 | 0 | ch = getc(ps->f); |
2889 | 28 | else { |
2890 | 28 | if (ps->off == ps->len) |
2891 | 6 | ch = EOF; |
2892 | 22 | else |
2893 | 22 | ch = ps->buf[ps->off++]; |
2894 | 28 | } |
2895 | 28 | return (ch); |
2896 | 28 | } |
2897 | | |
2898 | | static void |
2899 | | yylex_ungetc(int ch) |
2900 | 2 | { |
2901 | 2 | struct cmd_parse_state *ps = &parse_state; |
2902 | | |
2903 | 2 | if (ps->f != NULL) |
2904 | 0 | ungetc(ch, ps->f); |
2905 | 2 | else if (ps->off > 0 && ch != EOF) |
2906 | 0 | ps->off--; |
2907 | 2 | } |
2908 | | |
2909 | | static int |
2910 | | yylex_getc(void) |
2911 | 28 | { |
2912 | 28 | struct cmd_parse_state *ps = &parse_state; |
2913 | 28 | int ch; |
2914 | | |
2915 | 28 | if (ps->escapes != 0) { |
2916 | 0 | ps->escapes--; |
2917 | 0 | return ('\\'); |
2918 | 0 | } |
2919 | 28 | for (;;) { |
2920 | 28 | ch = yylex_getc1(); |
2921 | 28 | if (ch == '\\') { |
2922 | 0 | ps->escapes++; |
2923 | 0 | continue; |
2924 | 0 | } |
2925 | 28 | if (ch == '\n' && (ps->escapes % 2) == 1) { |
2926 | 0 | ps->input->line++; |
2927 | 0 | ps->escapes--; |
2928 | 0 | continue; |
2929 | 0 | } |
2930 | | |
2931 | 28 | if (ps->escapes != 0) { |
2932 | 0 | yylex_ungetc(ch); |
2933 | 0 | ps->escapes--; |
2934 | 0 | return ('\\'); |
2935 | 0 | } |
2936 | 28 | return (ch); |
2937 | 28 | } |
2938 | 28 | } |
2939 | | |
2940 | | static char * |
2941 | | yylex_get_word(int ch) |
2942 | 0 | { |
2943 | 0 | char *buf; |
2944 | 0 | size_t len; |
2945 | |
|
2946 | 0 | len = 0; |
2947 | 0 | buf = xmalloc(1); |
2948 | |
|
2949 | 0 | do |
2950 | 0 | yylex_append1(&buf, &len, ch); |
2951 | 0 | while ((ch = yylex_getc()) != EOF && strchr(" \t\n", ch) == NULL); |
2952 | 0 | yylex_ungetc(ch); |
2953 | |
|
2954 | 0 | buf[len] = '\0'; |
2955 | 0 | log_debug("%s: %s", __func__, buf); |
2956 | 0 | return (buf); |
2957 | 0 | } |
2958 | | |
2959 | | static int |
2960 | | yylex(void) |
2961 | 6 | { |
2962 | 6 | struct cmd_parse_state *ps = &parse_state; |
2963 | 6 | char *token, *cp; |
2964 | 6 | int ch, next, condition; |
2965 | | |
2966 | 6 | if (ps->eol) |
2967 | 0 | ps->input->line++; |
2968 | 6 | ps->eol = 0; |
2969 | | |
2970 | 6 | condition = ps->condition; |
2971 | 6 | ps->condition = 0; |
2972 | | |
2973 | 6 | for (;;) { |
2974 | 6 | ch = yylex_getc(); |
2975 | | |
2976 | 6 | if (ch == EOF) { |
2977 | | /* |
2978 | | * Ensure every file or string is terminated by a |
2979 | | * newline. This keeps the parser simpler and avoids |
2980 | | * having to add a newline to each string. |
2981 | | */ |
2982 | 4 | if (ps->eof) |
2983 | 2 | break; |
2984 | 2 | ps->eof = 1; |
2985 | 2 | return ('\n'); |
2986 | 4 | } |
2987 | | |
2988 | 2 | if (ch == ' ' || ch == '\t') { |
2989 | | /* |
2990 | | * Ignore whitespace. |
2991 | | */ |
2992 | 0 | continue; |
2993 | 0 | } |
2994 | | |
2995 | 2 | if (ch == '\r') { |
2996 | | /* |
2997 | | * Treat \r\n as \n. |
2998 | | */ |
2999 | 0 | ch = yylex_getc(); |
3000 | 0 | if (ch != '\n') { |
3001 | 0 | yylex_ungetc(ch); |
3002 | 0 | ch = '\r'; |
3003 | 0 | } |
3004 | 0 | } |
3005 | 2 | if (ch == '\n') { |
3006 | | /* |
3007 | | * End of line. Update the line number. |
3008 | | */ |
3009 | 0 | ps->eol = 1; |
3010 | 0 | return ('\n'); |
3011 | 0 | } |
3012 | | |
3013 | 2 | if (ch == ';' || ch == '{' || ch == '}') { |
3014 | | /* |
3015 | | * A semicolon or { or } is itself. |
3016 | | */ |
3017 | 0 | return (ch); |
3018 | 0 | } |
3019 | | |
3020 | 2 | if (ch == '#') { |
3021 | | /* |
3022 | | * #{ after a condition opens a format; anything else |
3023 | | * is a comment, ignore up to the end of the line. |
3024 | | */ |
3025 | 0 | next = yylex_getc(); |
3026 | 0 | if (condition && next == '{') { |
3027 | 0 | yylval.token = yylex_format(); |
3028 | 0 | if (yylval.token == NULL) |
3029 | 0 | return (ERROR); |
3030 | 0 | return (FORMAT); |
3031 | 0 | } |
3032 | 0 | while (next != '\n' && next != EOF) |
3033 | 0 | next = yylex_getc(); |
3034 | 0 | if (next == '\n') { |
3035 | 0 | ps->input->line++; |
3036 | 0 | return ('\n'); |
3037 | 0 | } |
3038 | 0 | continue; |
3039 | 0 | } |
3040 | | |
3041 | 2 | if (ch == '%') { |
3042 | | /* |
3043 | | * % is a condition unless it is all % or all numbers, |
3044 | | * then it is a token. |
3045 | | */ |
3046 | 0 | yylval.token = yylex_get_word('%'); |
3047 | 0 | for (cp = yylval.token; *cp != '\0'; cp++) { |
3048 | 0 | if (*cp != '%' && !isdigit((u_char)*cp)) |
3049 | 0 | break; |
3050 | 0 | } |
3051 | 0 | if (*cp == '\0') |
3052 | 0 | return (TOKEN); |
3053 | 0 | ps->condition = 1; |
3054 | 0 | if (strcmp(yylval.token, "%hidden") == 0) { |
3055 | 0 | free(yylval.token); |
3056 | 0 | return (HIDDEN); |
3057 | 0 | } |
3058 | 0 | if (strcmp(yylval.token, "%if") == 0) { |
3059 | 0 | free(yylval.token); |
3060 | 0 | return (IF); |
3061 | 0 | } |
3062 | 0 | if (strcmp(yylval.token, "%else") == 0) { |
3063 | 0 | free(yylval.token); |
3064 | 0 | return (ELSE); |
3065 | 0 | } |
3066 | 0 | if (strcmp(yylval.token, "%elif") == 0) { |
3067 | 0 | free(yylval.token); |
3068 | 0 | return (ELIF); |
3069 | 0 | } |
3070 | 0 | if (strcmp(yylval.token, "%endif") == 0) { |
3071 | 0 | free(yylval.token); |
3072 | 0 | return (ENDIF); |
3073 | 0 | } |
3074 | 0 | free(yylval.token); |
3075 | 0 | return (ERROR); |
3076 | 0 | } |
3077 | | |
3078 | | /* |
3079 | | * Otherwise this is a token. |
3080 | | */ |
3081 | 2 | token = yylex_token(ch); |
3082 | 2 | if (token == NULL) |
3083 | 0 | return (ERROR); |
3084 | 2 | yylval.token = token; |
3085 | | |
3086 | 2 | if (strchr(token, '=') != NULL && yylex_is_var(*token, 1)) { |
3087 | 0 | for (cp = token + 1; *cp != '='; cp++) { |
3088 | 0 | if (!yylex_is_var(*cp, 0)) |
3089 | 0 | break; |
3090 | 0 | } |
3091 | 0 | if (*cp == '=') |
3092 | 0 | return (EQUALS); |
3093 | 0 | } |
3094 | 2 | return (TOKEN); |
3095 | 2 | } |
3096 | 2 | return (0); |
3097 | 6 | } |
3098 | | |
3099 | | static char * |
3100 | | yylex_format(void) |
3101 | 0 | { |
3102 | 0 | char *buf; |
3103 | 0 | size_t len; |
3104 | 0 | int ch, brackets = 1; |
3105 | |
|
3106 | 0 | len = 0; |
3107 | 0 | buf = xmalloc(1); |
3108 | |
|
3109 | 0 | yylex_append(&buf, &len, "#{", 2); |
3110 | 0 | for (;;) { |
3111 | 0 | if ((ch = yylex_getc()) == EOF || ch == '\n') |
3112 | 0 | goto error; |
3113 | 0 | if (ch == '#') { |
3114 | 0 | if ((ch = yylex_getc()) == EOF || ch == '\n') |
3115 | 0 | goto error; |
3116 | 0 | if (ch == '{') |
3117 | 0 | brackets++; |
3118 | 0 | yylex_append1(&buf, &len, '#'); |
3119 | 0 | } else if (ch == '}') { |
3120 | 0 | if (brackets != 0 && --brackets == 0) { |
3121 | 0 | yylex_append1(&buf, &len, ch); |
3122 | 0 | break; |
3123 | 0 | } |
3124 | 0 | } |
3125 | 0 | yylex_append1(&buf, &len, ch); |
3126 | 0 | } |
3127 | 0 | if (brackets != 0) |
3128 | 0 | goto error; |
3129 | | |
3130 | 0 | buf[len] = '\0'; |
3131 | 0 | log_debug("%s: %s", __func__, buf); |
3132 | 0 | return (buf); |
3133 | | |
3134 | 0 | error: |
3135 | 0 | free(buf); |
3136 | 0 | return (NULL); |
3137 | 0 | } |
3138 | | |
3139 | | static int |
3140 | | yylex_token_escape(char **buf, size_t *len) |
3141 | 0 | { |
3142 | 0 | int ch, type, o2, o3, mlen; |
3143 | 0 | u_int size, i, tmp; |
3144 | 0 | char s[9], m[MB_LEN_MAX]; |
3145 | |
|
3146 | 0 | ch = yylex_getc(); |
3147 | |
|
3148 | 0 | if (ch >= '4' && ch <= '7') { |
3149 | 0 | yyerror("invalid octal escape"); |
3150 | 0 | return (0); |
3151 | 0 | } |
3152 | 0 | if (ch >= '0' && ch <= '3') { |
3153 | 0 | o2 = yylex_getc(); |
3154 | 0 | if (o2 >= '0' && o2 <= '7') { |
3155 | 0 | o3 = yylex_getc(); |
3156 | 0 | if (o3 >= '0' && o3 <= '7') { |
3157 | 0 | ch = 64 * (ch - '0') + |
3158 | 0 | 8 * (o2 - '0') + |
3159 | 0 | (o3 - '0'); |
3160 | 0 | yylex_append1(buf, len, ch); |
3161 | 0 | return (1); |
3162 | 0 | } |
3163 | 0 | } |
3164 | 0 | yyerror("invalid octal escape"); |
3165 | 0 | return (0); |
3166 | 0 | } |
3167 | | |
3168 | 0 | switch (ch) { |
3169 | 0 | case EOF: |
3170 | 0 | return (0); |
3171 | 0 | case 'a': |
3172 | 0 | ch = '\a'; |
3173 | 0 | break; |
3174 | 0 | case 'b': |
3175 | 0 | ch = '\b'; |
3176 | 0 | break; |
3177 | 0 | case 'e': |
3178 | 0 | ch = '\033'; |
3179 | 0 | break; |
3180 | 0 | case 'f': |
3181 | 0 | ch = '\f'; |
3182 | 0 | break; |
3183 | 0 | case 's': |
3184 | 0 | ch = ' '; |
3185 | 0 | break; |
3186 | 0 | case 'v': |
3187 | 0 | ch = '\v'; |
3188 | 0 | break; |
3189 | 0 | case 'r': |
3190 | 0 | ch = '\r'; |
3191 | 0 | break; |
3192 | 0 | case 'n': |
3193 | 0 | ch = '\n'; |
3194 | 0 | break; |
3195 | 0 | case 't': |
3196 | 0 | ch = '\t'; |
3197 | 0 | break; |
3198 | 0 | case 'u': |
3199 | 0 | type = 'u'; |
3200 | 0 | size = 4; |
3201 | 0 | goto unicode; |
3202 | 0 | case 'U': |
3203 | 0 | type = 'U'; |
3204 | 0 | size = 8; |
3205 | 0 | goto unicode; |
3206 | 0 | } |
3207 | | |
3208 | 0 | yylex_append1(buf, len, ch); |
3209 | 0 | return (1); |
3210 | | |
3211 | 0 | unicode: |
3212 | 0 | for (i = 0; i < size; i++) { |
3213 | 0 | ch = yylex_getc(); |
3214 | 0 | if (ch == EOF || ch == '\n') |
3215 | 0 | return (0); |
3216 | 0 | if (!isxdigit((u_char)ch)) { |
3217 | 0 | yyerror("invalid \\%c argument", type); |
3218 | 0 | return (0); |
3219 | 0 | } |
3220 | 0 | s[i] = ch; |
3221 | 0 | } |
3222 | 0 | s[i] = '\0'; |
3223 | |
|
3224 | 0 | if ((size == 4 && sscanf(s, "%4x", &tmp) != 1) || |
3225 | 0 | (size == 8 && sscanf(s, "%8x", &tmp) != 1)) { |
3226 | 0 | yyerror("invalid \\%c argument", type); |
3227 | 0 | return (0); |
3228 | 0 | } |
3229 | 0 | mlen = wctomb(m, tmp); |
3230 | 0 | if (mlen <= 0 || mlen > (int)sizeof m) { |
3231 | 0 | yyerror("invalid \\%c argument", type); |
3232 | 0 | return (0); |
3233 | 0 | } |
3234 | 0 | yylex_append(buf, len, m, mlen); |
3235 | 0 | return (1); |
3236 | 0 | } |
3237 | | |
3238 | | static int |
3239 | | yylex_token_variable(char **buf, size_t *len) |
3240 | 0 | { |
3241 | 0 | struct environ_entry *envent; |
3242 | 0 | int ch, brackets = 0; |
3243 | 0 | char name[1024]; |
3244 | 0 | size_t namelen = 0; |
3245 | 0 | const char *value; |
3246 | |
|
3247 | 0 | ch = yylex_getc(); |
3248 | 0 | if (ch == EOF) |
3249 | 0 | return (0); |
3250 | 0 | if (ch == '{') |
3251 | 0 | brackets = 1; |
3252 | 0 | else { |
3253 | 0 | if (!yylex_is_var(ch, 1)) { |
3254 | 0 | yylex_append1(buf, len, '$'); |
3255 | 0 | yylex_ungetc(ch); |
3256 | 0 | return (1); |
3257 | 0 | } |
3258 | 0 | name[namelen++] = ch; |
3259 | 0 | } |
3260 | | |
3261 | 0 | for (;;) { |
3262 | 0 | ch = yylex_getc(); |
3263 | 0 | if (brackets && ch == '}') |
3264 | 0 | break; |
3265 | 0 | if (ch == EOF || !yylex_is_var(ch, 0)) { |
3266 | 0 | if (!brackets) { |
3267 | 0 | yylex_ungetc(ch); |
3268 | 0 | break; |
3269 | 0 | } |
3270 | 0 | yyerror("invalid environment variable"); |
3271 | 0 | return (0); |
3272 | 0 | } |
3273 | 0 | if (namelen == (sizeof name) - 2) { |
3274 | 0 | yyerror("environment variable is too long"); |
3275 | 0 | return (0); |
3276 | 0 | } |
3277 | 0 | name[namelen++] = ch; |
3278 | 0 | } |
3279 | 0 | name[namelen] = '\0'; |
3280 | |
|
3281 | 0 | envent = environ_find(global_environ, name); |
3282 | 0 | if (envent != NULL && envent->value != NULL) { |
3283 | 0 | value = envent->value; |
3284 | 0 | log_debug("%s: %s -> %s", __func__, name, value); |
3285 | 0 | yylex_append(buf, len, value, strlen(value)); |
3286 | 0 | } |
3287 | 0 | return (1); |
3288 | 0 | } |
3289 | | |
3290 | | static int |
3291 | | yylex_token_tilde(char **buf, size_t *len) |
3292 | 0 | { |
3293 | 0 | struct environ_entry *envent; |
3294 | 0 | int ch; |
3295 | 0 | char name[1024]; |
3296 | 0 | size_t namelen = 0; |
3297 | 0 | struct passwd *pw; |
3298 | 0 | const char *home = NULL; |
3299 | |
|
3300 | 0 | for (;;) { |
3301 | 0 | ch = yylex_getc(); |
3302 | 0 | if (ch == EOF || strchr("/ \t\n\"'", ch) != NULL) { |
3303 | 0 | yylex_ungetc(ch); |
3304 | 0 | break; |
3305 | 0 | } |
3306 | 0 | if (namelen == (sizeof name) - 2) { |
3307 | 0 | yyerror("user name is too long"); |
3308 | 0 | return (0); |
3309 | 0 | } |
3310 | 0 | name[namelen++] = ch; |
3311 | 0 | } |
3312 | 0 | name[namelen] = '\0'; |
3313 | |
|
3314 | 0 | if (*name == '\0') { |
3315 | 0 | envent = environ_find(global_environ, "HOME"); |
3316 | 0 | if (envent != NULL && *envent->value != '\0') |
3317 | 0 | home = envent->value; |
3318 | 0 | else if ((pw = getpwuid(getuid())) != NULL) |
3319 | 0 | home = pw->pw_dir; |
3320 | 0 | } else { |
3321 | 0 | if ((pw = getpwnam(name)) != NULL) |
3322 | 0 | home = pw->pw_dir; |
3323 | 0 | } |
3324 | 0 | if (home == NULL) |
3325 | 0 | return (0); |
3326 | | |
3327 | 0 | log_debug("%s: ~%s -> %s", __func__, name, home); |
3328 | 0 | yylex_append(buf, len, home, strlen(home)); |
3329 | 0 | return (1); |
3330 | 0 | } |
3331 | | |
3332 | | static char * |
3333 | | yylex_token(int ch) |
3334 | 2 | { |
3335 | 2 | struct cmd_parse_state *ps = &parse_state; |
3336 | 2 | char *buf; |
3337 | 2 | size_t len; |
3338 | 2 | enum { START, |
3339 | 2 | NONE, |
3340 | 2 | DOUBLE_QUOTES, |
3341 | 2 | SINGLE_QUOTES } state = NONE, last = START; |
3342 | | |
3343 | 2 | len = 0; |
3344 | 2 | buf = xmalloc(1); |
3345 | | |
3346 | 24 | for (;;) { |
3347 | | /* EOF or \n are always the end of the token. */ |
3348 | 24 | if (ch == EOF) { |
3349 | 2 | log_debug("%s: end at EOF", __func__); |
3350 | 2 | break; |
3351 | 2 | } |
3352 | 22 | if (state == NONE && ch == '\r') { |
3353 | 0 | ch = yylex_getc(); |
3354 | 0 | if (ch != '\n') { |
3355 | 0 | yylex_ungetc(ch); |
3356 | 0 | ch = '\r'; |
3357 | 0 | } |
3358 | 0 | } |
3359 | 22 | if (ch == '\n') { |
3360 | 0 | if (state == NONE) { |
3361 | 0 | log_debug("%s: end at EOL", __func__); |
3362 | 0 | break; |
3363 | 0 | } |
3364 | 0 | ps->input->line++; |
3365 | 0 | } |
3366 | | |
3367 | | /* Whitespace or ; or } ends a token unless inside quotes. */ |
3368 | 22 | if (state == NONE && (ch == ' ' || ch == '\t')) { |
3369 | 0 | log_debug("%s: end at WS", __func__); |
3370 | 0 | break; |
3371 | 0 | } |
3372 | 22 | if (state == NONE && (ch == ';' || ch == '}')) { |
3373 | 0 | log_debug("%s: end at %c", __func__, ch); |
3374 | 0 | break; |
3375 | 0 | } |
3376 | | |
3377 | | /* |
3378 | | * Spaces and comments inside quotes after \n are removed but |
3379 | | * the \n is left. |
3380 | | */ |
3381 | 22 | if (ch == '\n' && state != NONE) { |
3382 | 0 | yylex_append1(&buf, &len, '\n'); |
3383 | 0 | while ((ch = yylex_getc()) == ' ' || ch == '\t') |
3384 | 0 | /* nothing */; |
3385 | 0 | if (ch != '#') |
3386 | 0 | continue; |
3387 | 0 | ch = yylex_getc(); |
3388 | 0 | if (strchr(",#{}:", ch) != NULL) { |
3389 | 0 | yylex_ungetc(ch); |
3390 | 0 | ch = '#'; |
3391 | 0 | } else { |
3392 | 0 | while ((ch = yylex_getc()) != '\n' && ch != EOF) |
3393 | 0 | /* nothing */; |
3394 | 0 | } |
3395 | 0 | continue; |
3396 | 0 | } |
3397 | | |
3398 | | /* \ ~ and $ are expanded except in single quotes. */ |
3399 | 22 | if (ch == '\\' && state != SINGLE_QUOTES) { |
3400 | 0 | if (!yylex_token_escape(&buf, &len)) |
3401 | 0 | goto error; |
3402 | 0 | goto skip; |
3403 | 0 | } |
3404 | 22 | if (ch == '~' && last != state && state != SINGLE_QUOTES) { |
3405 | 0 | if (!yylex_token_tilde(&buf, &len)) |
3406 | 0 | goto error; |
3407 | 0 | goto skip; |
3408 | 0 | } |
3409 | 22 | if (ch == '$' && state != SINGLE_QUOTES) { |
3410 | 0 | if (!yylex_token_variable(&buf, &len)) |
3411 | 0 | goto error; |
3412 | 0 | goto skip; |
3413 | 0 | } |
3414 | 22 | if (ch == '}' && state == NONE) |
3415 | 0 | goto error; /* unmatched (matched ones were handled) */ |
3416 | | |
3417 | | /* ' and " starts or end quotes (and is consumed). */ |
3418 | 22 | if (ch == '\'') { |
3419 | 0 | if (state == NONE) { |
3420 | 0 | state = SINGLE_QUOTES; |
3421 | 0 | goto next; |
3422 | 0 | } |
3423 | 0 | if (state == SINGLE_QUOTES) { |
3424 | 0 | state = NONE; |
3425 | 0 | goto next; |
3426 | 0 | } |
3427 | 0 | } |
3428 | 22 | if (ch == '"') { |
3429 | 0 | if (state == NONE) { |
3430 | 0 | state = DOUBLE_QUOTES; |
3431 | 0 | goto next; |
3432 | 0 | } |
3433 | 0 | if (state == DOUBLE_QUOTES) { |
3434 | 0 | state = NONE; |
3435 | 0 | goto next; |
3436 | 0 | } |
3437 | 0 | } |
3438 | | |
3439 | | /* Otherwise add the character to the buffer. */ |
3440 | 22 | yylex_append1(&buf, &len, ch); |
3441 | | |
3442 | 22 | skip: |
3443 | 22 | last = state; |
3444 | | |
3445 | 22 | next: |
3446 | 22 | ch = yylex_getc(); |
3447 | 22 | } |
3448 | 2 | yylex_ungetc(ch); |
3449 | | |
3450 | 2 | buf[len] = '\0'; |
3451 | 2 | log_debug("%s: %s", __func__, buf); |
3452 | 2 | return (buf); |
3453 | | |
3454 | 0 | error: |
3455 | 0 | free(buf); |
3456 | 0 | return (NULL); |
3457 | 2 | } |