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