1 /* A Bison parser, made by GNU Bison 2.5.1. */
2
3 /* Bison implementation for Yacc-like parsers in C
4
5 Copyright (C) 1984, 1989-1990, 2000-2012 Free Software Foundation, Inc.
6
7 This program is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
19
20 /* As a special exception, you may create a larger work that contains
21 part or all of the Bison parser skeleton and distribute that work
22 under terms of your choice, so long as that work isn't itself a
23 parser generator using the skeleton or a modified version thereof
24 as a parser skeleton. Alternatively, if you modify or redistribute
25 the parser skeleton itself, you may (at your option) remove this
26 special exception, which will cause the skeleton and the resulting
27 Bison output files to be licensed under the GNU General Public
28 License without this special exception.
29
30 This special exception was added by the Free Software Foundation in
31 version 2.2 of Bison. */
32
33 /* C LALR(1) parser skeleton written by Richard Stallman, by
34 simplifying the original so-called "semantic" parser. */
35
36 /* All symbols defined below should begin with yy or YY, to avoid
37 infringing on user name space. This should be done even for local
38 variables, as they might otherwise be expanded by user macros.
39 There are some unavoidable exceptions within include files to
40 define necessary library symbols; they are noted "INFRINGES ON
41 USER NAME SPACE" below. */
42
43 /* Identify Bison output. */
44 #define YYBISON 1
45
46 /* Bison version. */
47 #define YYBISON_VERSION "2.5.1"
48
49 /* Skeleton name. */
50 #define YYSKELETON_NAME "yacc.c"
51
52 /* Pure parsers. */
53 #define YYPURE 0
54
55 /* Push parsers. */
56 #define YYPUSH 0
57
58 /* Pull parsers. */
59 #define YYPULL 1
60
61 /* Using locations. */
62 #define YYLSP_NEEDED 1
63
64
65
66 /* Copy the first part of user declarations. */
67
68 /* Line 268 of yacc.c */
69 #line 1 "rc-gram.y"
70
71 /*
72 rc-gram.y
73
74 This file is part of GNU Anubis.
75 Copyright (C) 2003-2014 The Anubis Team.
76
77 GNU Anubis is free software; you can redistribute it and/or modify it
78 under the terms of the GNU General Public License as published by the
79 Free Software Foundation; either version 3 of the License, or (at your
80 option) any later version.
81
82 GNU Anubis is distributed in the hope that it will be useful,
83 but WITHOUT ANY WARRANTY; without even the implied warranty of
84 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
85 GNU General Public License for more details.
86
87 You should have received a copy of the GNU General Public License along
88 with GNU Anubis. If not, see <http://www.gnu.org/licenses/>.
89 */
90
91 #ifdef HAVE_CONFIG_H
92 # include <config.h>
93 #endif
94
95 #include <stdlib.h>
96 #include <string.h>
97 #include <setjmp.h>
98 #include "headers.h"
99 #include "extern.h"
100 #include "rcfile.h"
101
102 extern int yylex (void);
103 int yyerror (const char *s);
104
105 static RC_SECTION *rc_section_create (char *, RC_LOC *, RC_STMT *);
106 static void rc_section_destroy (RC_SECTION **);
107 static void rc_section_print (RC_SECTION *);
108 static void rc_asgn_destroy (RC_ASGN *);
109 static void rc_bool_destroy (RC_BOOL *);
110 static void rc_level_print (int, char *);
111 static RC_NODE *rc_node_create (enum rc_node_type, struct rc_loc *loc);
112 static void rc_node_destroy (RC_NODE *);
113 static void rc_node_print (RC_NODE *);
114 static void rc_rule_destroy (RC_RULE *);
115 static void rc_cond_destroy (RC_COND *);
116 static RC_STMT *rc_stmt_create (enum rc_stmt_type, struct rc_loc *loc);
117 static void rc_stmt_destroy (RC_STMT *);
118 static void rc_stmt_list_destroy (RC_STMT *);
119 static void rc_stmt_print (RC_STMT *, int);
120 static int reg_modifier_add (int *, char *, struct rc_loc *);
121 static int check_kw (char *ident, int *flags);
122 static int is_prog_allowed (struct rc_loc *);
123
124 static RC_SECTION *rc_section;
125 static int debug_level;
126 static int error_count;
127 static int def_regex_modifier = R_POSIX;
128 static struct rc_secdef *rc_secdef;
129
130 #define YYLLOC_DEFAULT(Current, Rhs, N) \
131 do \
132 { \
133 if (N) \
134 { \
135 (Current).beg = YYRHSLOC(Rhs, 1).beg; \
136 (Current).end = YYRHSLOC(Rhs, N).end; \
137 } \
138 else \
139 { \
140 (Current).beg = YYRHSLOC(Rhs, 0).end; \
141 (Current).end = (Current).beg; \
142 } \
143 } \
144 while (0)
145
146 #define YY_LOCATION_PRINT(File, Loc) \
147 do \
148 { \
149 if (RC_LOCUS_FILE_EQ(&(Loc).beg, &(Loc).end)) \
150 fprintf(File, "%s:%lu.%lu-%lu.%lu", \
151 (Loc).beg.file, \
152 (unsigned long) (Loc).beg.line, \
153 (unsigned long) (Loc).beg.column, \
154 (unsigned long) (Loc).end.line, \
155 (unsigned long) (Loc).end.column); \
156 else \
157 fprintf(File, "%s:%lu.%lu-%s:%lu.%lu", \
158 (Loc).beg.file, \
159 (unsigned long) (Loc).beg.line, \
160 (unsigned long) (Loc).beg.column, \
161 (Loc).end.file, \
162 (unsigned long) (Loc).end.line, \
163 (unsigned long) (Loc).end.column); \
164 } \
165 while (0)
166
167
168
169 /* Line 268 of yacc.c */
170 #line 171 "rc-gram.c"
171
172 # ifndef YY_NULL
173 # if defined __cplusplus && 201103L <= __cplusplus
174 # define YY_NULL nullptr
175 # else
176 # define YY_NULL 0
177 # endif
178 # endif
179
180 /* Enabling traces. */
181 #ifndef YYDEBUG
182 # define YYDEBUG 1
183 #endif
184
185 /* Enabling verbose error messages. */
186 #ifdef YYERROR_VERBOSE
187 # undef YYERROR_VERBOSE
188 # define YYERROR_VERBOSE 1
189 #else
190 # define YYERROR_VERBOSE 1
191 #endif
192
193 /* Enabling the token table. */
194 #ifndef YYTOKEN_TABLE
195 # define YYTOKEN_TABLE 0
196 #endif
197
198
199 /* Tokens. */
200 #ifndef YYTOKENTYPE
201 # define YYTOKENTYPE
202 /* Put the tokens into the symbol table, so that GDB and other debuggers
203 know about them. */
204 enum yytokentype {
205 EOL = 258,
206 T_BEGIN = 259,
207 T_END = 260,
208 AND = 261,
209 OR = 262,
210 NE = 263,
211 IF = 264,
212 FI = 265,
213 ELSE = 266,
214 ELIF = 267,
215 RULE = 268,
216 DONE = 269,
217 CALL = 270,
218 STOP = 271,
219 ADD = 272,
220 REMOVE = 273,
221 MODIFY = 274,
222 IDENT = 275,
223 STRING = 276,
224 REGEX = 277,
225 D_BEGIN = 278,
226 T_MSGPART = 279,
227 NOT = 280
228 };
229 #endif
230 /* Tokens. */
231 #define EOL 258
232 #define T_BEGIN 259
233 #define T_END 260
234 #define AND 261
235 #define OR 262
236 #define NE 263
237 #define IF 264
238 #define FI 265
239 #define ELSE 266
240 #define ELIF 267
241 #define RULE 268
242 #define DONE 269
243 #define CALL 270
244 #define STOP 271
245 #define ADD 272
246 #define REMOVE 273
247 #define MODIFY 274
248 #define IDENT 275
249 #define STRING 276
250 #define REGEX 277
251 #define D_BEGIN 278
252 #define T_MSGPART 279
253 #define NOT 280
254
255
256
257
258 #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
259 typedef union YYSTYPE
260 {
261
262 /* Line 295 of yacc.c */
263 #line 104 "rc-gram.y"
264
265 char *string;
266 RC_SECTION *section;
267 RC_STMT *stmt;
268 struct
269 {
270 RC_STMT *head;
271 RC_STMT *tail;
272 } stmtlist;
273 RC_COND cond;
274 RC_RULE rule;
275 RC_NODE *node;
276 RC_REGEX *regex;
277 int num;
278 struct
279 {
280 int part;
281 RC_REGEX *key;
282 char *string;
283 char *sep;
284 } msgpart;
285 RC_LOC loc;
286 char *begin_sec;
287 ANUBIS_LIST list;
288 int eq;
289
290
291
292 /* Line 295 of yacc.c */
293 #line 294 "rc-gram.c"
294 } YYSTYPE;
295 # define YYSTYPE_IS_TRIVIAL 1
296 # define yystype YYSTYPE /* obsolescent; will be withdrawn */
297 # define YYSTYPE_IS_DECLARED 1
298 #endif
299
300 #if ! defined YYLTYPE && ! defined YYLTYPE_IS_DECLARED
301 typedef struct YYLTYPE
302 {
303 int first_line;
304 int first_column;
305 int last_line;
306 int last_column;
307 } YYLTYPE;
308 # define yyltype YYLTYPE /* obsolescent; will be withdrawn */
309 # define YYLTYPE_IS_DECLARED 1
310 # define YYLTYPE_IS_TRIVIAL 1
311 #endif
312
313
314 /* Copy the second part of user declarations. */
315
316
317 /* Line 345 of yacc.c */
318 #line 319 "rc-gram.c"
319
320 #ifdef short
321 # undef short
322 #endif
323
324 #ifdef YYTYPE_UINT8
325 typedef YYTYPE_UINT8 yytype_uint8;
326 #else
327 typedef unsigned char yytype_uint8;
328 #endif
329
330 #ifdef YYTYPE_INT8
331 typedef YYTYPE_INT8 yytype_int8;
332 #elif (defined __STDC__ || defined __C99__FUNC__ \
333 || defined __cplusplus || defined _MSC_VER)
334 typedef signed char yytype_int8;
335 #else
336 typedef short int yytype_int8;
337 #endif
338
339 #ifdef YYTYPE_UINT16
340 typedef YYTYPE_UINT16 yytype_uint16;
341 #else
342 typedef unsigned short int yytype_uint16;
343 #endif
344
345 #ifdef YYTYPE_INT16
346 typedef YYTYPE_INT16 yytype_int16;
347 #else
348 typedef short int yytype_int16;
349 #endif
350
351 #ifndef YYSIZE_T
352 # ifdef __SIZE_TYPE__
353 # define YYSIZE_T __SIZE_TYPE__
354 # elif defined size_t
355 # define YYSIZE_T size_t
356 # elif ! defined YYSIZE_T && (defined __STDC__ || defined __C99__FUNC__ \
357 || defined __cplusplus || defined _MSC_VER)
358 # include <stddef.h> /* INFRINGES ON USER NAME SPACE */
359 # define YYSIZE_T size_t
360 # else
361 # define YYSIZE_T unsigned int
362 # endif
363 #endif
364
365 #define YYSIZE_MAXIMUM ((YYSIZE_T) -1)
366
367 #ifndef YY_
368 # if defined YYENABLE_NLS && YYENABLE_NLS
369 # if ENABLE_NLS
370 # include <libintl.h> /* INFRINGES ON USER NAME SPACE */
371 # define YY_(msgid) dgettext ("bison-runtime", msgid)
372 # endif
373 # endif
374 # ifndef YY_
375 # define YY_(msgid) msgid
376 # endif
377 #endif
378
379 /* Suppress unused-variable warnings by "using" E. */
380 #if ! defined lint || defined __GNUC__
381 # define YYUSE(e) ((void) (e))
382 #else
383 # define YYUSE(e) /* empty */
384 #endif
385
386 /* Identity function, used to suppress warnings about constant conditions. */
387 #ifndef lint
388 # define YYID(n) (n)
389 #else
390 #if (defined __STDC__ || defined __C99__FUNC__ \
391 || defined __cplusplus || defined _MSC_VER)
392 static int
YYID(int yyi)393 YYID (int yyi)
394 #else
395 static int
396 YYID (yyi)
397 int yyi;
398 #endif
399 {
400 return yyi;
401 }
402 #endif
403
404 #if ! defined yyoverflow || YYERROR_VERBOSE
405
406 /* The parser invokes alloca or malloc; define the necessary symbols. */
407
408 # ifdef YYSTACK_USE_ALLOCA
409 # if YYSTACK_USE_ALLOCA
410 # ifdef __GNUC__
411 # define YYSTACK_ALLOC __builtin_alloca
412 # elif defined __BUILTIN_VA_ARG_INCR
413 # include <alloca.h> /* INFRINGES ON USER NAME SPACE */
414 # elif defined _AIX
415 # define YYSTACK_ALLOC __alloca
416 # elif defined _MSC_VER
417 # include <malloc.h> /* INFRINGES ON USER NAME SPACE */
418 # define alloca _alloca
419 # else
420 # define YYSTACK_ALLOC alloca
421 # if ! defined _ALLOCA_H && ! defined EXIT_SUCCESS && (defined __STDC__ || defined __C99__FUNC__ \
422 || defined __cplusplus || defined _MSC_VER)
423 # include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
424 /* Use EXIT_SUCCESS as a witness for stdlib.h. */
425 # ifndef EXIT_SUCCESS
426 # define EXIT_SUCCESS 0
427 # endif
428 # endif
429 # endif
430 # endif
431 # endif
432
433 # ifdef YYSTACK_ALLOC
434 /* Pacify GCC's `empty if-body' warning. */
435 # define YYSTACK_FREE(Ptr) do { /* empty */; } while (YYID (0))
436 # ifndef YYSTACK_ALLOC_MAXIMUM
437 /* The OS might guarantee only one guard page at the bottom of the stack,
438 and a page size can be as small as 4096 bytes. So we cannot safely
439 invoke alloca (N) if N exceeds 4096. Use a slightly smaller number
440 to allow for a few compiler-allocated temporary stack slots. */
441 # define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */
442 # endif
443 # else
444 # define YYSTACK_ALLOC YYMALLOC
445 # define YYSTACK_FREE YYFREE
446 # ifndef YYSTACK_ALLOC_MAXIMUM
447 # define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM
448 # endif
449 # if (defined __cplusplus && ! defined EXIT_SUCCESS \
450 && ! ((defined YYMALLOC || defined malloc) \
451 && (defined YYFREE || defined free)))
452 # include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
453 # ifndef EXIT_SUCCESS
454 # define EXIT_SUCCESS 0
455 # endif
456 # endif
457 # ifndef YYMALLOC
458 # define YYMALLOC malloc
459 # if ! defined malloc && ! defined EXIT_SUCCESS && (defined __STDC__ || defined __C99__FUNC__ \
460 || defined __cplusplus || defined _MSC_VER)
461 void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */
462 # endif
463 # endif
464 # ifndef YYFREE
465 # define YYFREE free
466 # if ! defined free && ! defined EXIT_SUCCESS && (defined __STDC__ || defined __C99__FUNC__ \
467 || defined __cplusplus || defined _MSC_VER)
468 void free (void *); /* INFRINGES ON USER NAME SPACE */
469 # endif
470 # endif
471 # endif
472 #endif /* ! defined yyoverflow || YYERROR_VERBOSE */
473
474
475 #if (! defined yyoverflow \
476 && (! defined __cplusplus \
477 || (defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL \
478 && defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
479
480 /* A type that is properly aligned for any stack member. */
481 union yyalloc
482 {
483 yytype_int16 yyss_alloc;
484 YYSTYPE yyvs_alloc;
485 YYLTYPE yyls_alloc;
486 };
487
488 /* The size of the maximum gap between one aligned stack and the next. */
489 # define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1)
490
491 /* The size of an array large to enough to hold all stacks, each with
492 N elements. */
493 # define YYSTACK_BYTES(N) \
494 ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE) + sizeof (YYLTYPE)) \
495 + 2 * YYSTACK_GAP_MAXIMUM)
496
497 # define YYCOPY_NEEDED 1
498
499 /* Relocate STACK from its old location to the new one. The
500 local variables YYSIZE and YYSTACKSIZE give the old and new number of
501 elements in the stack, and YYPTR gives the new location of the
502 stack. Advance YYPTR to a properly aligned location for the next
503 stack. */
504 # define YYSTACK_RELOCATE(Stack_alloc, Stack) \
505 do \
506 { \
507 YYSIZE_T yynewbytes; \
508 YYCOPY (&yyptr->Stack_alloc, Stack, yysize); \
509 Stack = &yyptr->Stack_alloc; \
510 yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \
511 yyptr += yynewbytes / sizeof (*yyptr); \
512 } \
513 while (YYID (0))
514
515 #endif
516
517 #if defined YYCOPY_NEEDED && YYCOPY_NEEDED
518 /* Copy COUNT objects from SRC to DST. The source and destination do
519 not overlap. */
520 # ifndef YYCOPY
521 # if defined __GNUC__ && 1 < __GNUC__
522 # define YYCOPY(Dst, Src, Count) \
523 __builtin_memcpy (Dst, Src, (Count) * sizeof (*(Src)))
524 # else
525 # define YYCOPY(Dst, Src, Count) \
526 do \
527 { \
528 YYSIZE_T yyi; \
529 for (yyi = 0; yyi < (Count); yyi++) \
530 (Dst)[yyi] = (Src)[yyi]; \
531 } \
532 while (YYID (0))
533 # endif
534 # endif
535 #endif /* !YYCOPY_NEEDED */
536
537 /* YYFINAL -- State number of the termination state. */
538 #define YYFINAL 10
539 /* YYLAST -- Last index in YYTABLE. */
540 #define YYLAST 190
541
542 /* YYNTOKENS -- Number of terminals. */
543 #define YYNTOKENS 32
544 /* YYNNTS -- Number of nonterminals. */
545 #define YYNNTS 36
546 /* YYNRULES -- Number of rules. */
547 #define YYNRULES 70
548 /* YYNRULES -- Number of states. */
549 #define YYNSTATES 119
550
551 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
552 #define YYUNDEFTOK 2
553 #define YYMAXUTOK 280
554
555 #define YYTRANSLATE(YYX) \
556 ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
557
558 /* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */
559 static const yytype_uint8 yytranslate[] =
560 {
561 0, 2, 2, 2, 2, 2, 2, 2, 2, 2,
562 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
563 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
564 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
565 26, 27, 2, 2, 2, 2, 2, 2, 2, 2,
566 2, 2, 2, 2, 2, 2, 2, 2, 31, 2,
567 2, 28, 2, 2, 2, 2, 2, 2, 2, 2,
568 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
569 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
570 2, 29, 2, 30, 2, 2, 2, 2, 2, 2,
571 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
572 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
573 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
574 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
575 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
576 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
577 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
578 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
579 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
580 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
581 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
582 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
583 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
584 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
585 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
586 2, 2, 2, 2, 2, 2, 1, 2, 3, 4,
587 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
588 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
589 25
590 };
591
592 #if YYDEBUG
593 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
594 YYRHS. */
595 static const yytype_uint8 yyprhs[] =
596 {
597 0, 0, 3, 5, 7, 10, 13, 15, 19, 22,
598 23, 28, 31, 34, 36, 39, 41, 44, 47, 50,
599 53, 56, 59, 62, 64, 66, 69, 71, 77, 78,
600 83, 86, 88, 92, 96, 100, 103, 104, 106, 108,
601 110, 114, 115, 117, 120, 122, 123, 127, 129, 131,
602 136, 137, 141, 147, 149, 152, 153, 155, 158, 160,
603 165, 169, 171, 173, 175, 177, 180, 184, 187, 192,
604 196
605 };
606
607 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
608 static const yytype_int8 yyrhs[] =
609 {
610 33, 0, -1, 34, -1, 35, -1, 34, 35, -1,
611 34, 1, -1, 3, -1, 36, 39, 38, -1, 36,
612 38, -1, -1, 4, 37, 65, 3, -1, 23, 3,
613 -1, 5, 3, -1, 40, -1, 39, 40, -1, 3,
614 -1, 41, 3, -1, 45, 3, -1, 62, 3, -1,
615 66, 3, -1, 67, 3, -1, 1, 3, -1, 42,
616 43, -1, 20, -1, 44, -1, 43, 44, -1, 65,
617 -1, 61, 47, 39, 46, 10, -1, -1, 12, 47,
618 39, 46, -1, 11, 39, -1, 57, -1, 26, 47,
619 27, -1, 47, 6, 47, -1, 47, 7, 47, -1,
620 25, 47, -1, -1, 28, -1, 8, -1, 55, -1,
621 29, 65, 30, -1, -1, 49, -1, 24, 50, -1,
622 49, -1, -1, 26, 65, 27, -1, 51, -1, 51,
623 -1, 58, 29, 65, 30, -1, -1, 29, 65, 30,
624 -1, 53, 52, 48, 59, 65, -1, 60, -1, 58,
625 60, -1, -1, 58, -1, 31, 20, -1, 9, -1,
626 63, 3, 39, 14, -1, 64, 59, 65, -1, 13,
627 -1, 21, -1, 20, -1, 16, -1, 15, 65, -1,
628 17, 53, 65, -1, 18, 54, -1, 19, 54, 56,
629 65, -1, 19, 54, 56, -1, 22, 58, -1
630 };
631
632 /* YYRLINE[YYN] -- source line where rule number YYN was defined. */
633 static const yytype_uint16 yyrline[] =
634 {
635 0, 155, 155, 160, 164, 179, 191, 195, 199, 205,
636 205, 212, 221, 224, 228, 245, 249, 250, 251, 252,
637 253, 254, 263, 285, 291, 296, 303, 306, 316, 319,
638 326, 332, 333, 337, 344, 351, 361, 364, 368, 374,
639 380, 389, 393, 396, 402, 406, 409, 415, 424, 435,
640 449, 452, 458, 478, 484, 493, 496, 499, 505, 512,
641 520, 530, 537, 538, 541, 553, 565, 583, 601, 613,
642 629
643 };
644 #endif
645
646 #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
647 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
648 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
649 static const char *const yytname[] =
650 {
651 "$end", "error", "$undefined", "EOL", "T_BEGIN", "T_END", "AND", "OR",
652 "NE", "IF", "FI", "ELSE", "ELIF", "RULE", "DONE", "CALL", "STOP", "ADD",
653 "REMOVE", "MODIFY", "IDENT", "STRING", "REGEX", "D_BEGIN", "T_MSGPART",
654 "NOT", "'('", "')'", "'='", "'['", "']'", "':'", "$accept", "input",
655 "seclist", "section", "begin", "$@1", "end", "stmtlist", "stmt",
656 "asgn_stmt", "keyword", "arglist", "arg", "cond_stmt", "else_cond",
657 "cond", "meq", "key", "opt_key", "msgpart", "opt_sep", "s_msgpart",
658 "r_msgpart", "regex", "string_key", "expr", "modlist", "opt_modlist",
659 "modifier", "if", "rule_stmt", "rule_start", "rule", "string",
660 "inst_stmt", "modf_stmt", YY_NULL
661 };
662 #endif
663
664 # ifdef YYPRINT
665 /* YYTOKNUM[YYLEX-NUM] -- Internal token number corresponding to
666 token YYLEX-NUM. */
667 static const yytype_uint16 yytoknum[] =
668 {
669 0, 256, 257, 258, 259, 260, 261, 262, 263, 264,
670 265, 266, 267, 268, 269, 270, 271, 272, 273, 274,
671 275, 276, 277, 278, 279, 280, 40, 41, 61, 91,
672 93, 58
673 };
674 # endif
675
676 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
677 static const yytype_uint8 yyr1[] =
678 {
679 0, 32, 33, 34, 34, 34, 35, 35, 35, 37,
680 36, 36, 38, 39, 39, 40, 40, 40, 40, 40,
681 40, 40, 41, 42, 43, 43, 44, 45, 46, 46,
682 46, 47, 47, 47, 47, 47, 48, 48, 48, 49,
683 49, 50, 50, 51, 51, 52, 52, 53, 54, 55,
684 56, 56, 57, 58, 58, 59, 59, 60, 61, 62,
685 63, 64, 65, 65, 66, 66, 66, 66, 66, 66,
686 67
687 };
688
689 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
690 static const yytype_uint8 yyr2[] =
691 {
692 0, 2, 1, 1, 2, 2, 1, 3, 2, 0,
693 4, 2, 2, 1, 2, 1, 2, 2, 2, 2,
694 2, 2, 2, 1, 1, 2, 1, 5, 0, 4,
695 2, 1, 3, 3, 3, 2, 0, 1, 1, 1,
696 3, 0, 1, 2, 1, 0, 3, 1, 1, 4,
697 0, 3, 5, 1, 2, 0, 1, 2, 1, 4,
698 3, 1, 1, 1, 1, 2, 3, 2, 4, 3,
699 2
700 };
701
702 /* YYDEFACT[STATE-NAME] -- Default reduction number in state STATE-NUM.
703 Performed when YYTABLE doesn't specify something else to do. Zero
704 means the default is an error. */
705 static const yytype_uint8 yydefact[] =
706 {
707 0, 6, 9, 0, 0, 0, 3, 0, 0, 11,
708 1, 5, 4, 0, 15, 0, 58, 61, 0, 64,
709 0, 0, 0, 23, 0, 8, 0, 13, 0, 0,
710 0, 0, 0, 0, 55, 0, 0, 63, 62, 0,
711 21, 12, 65, 41, 0, 0, 44, 47, 0, 39,
712 0, 53, 48, 67, 50, 70, 7, 14, 16, 22,
713 24, 26, 17, 0, 0, 0, 45, 31, 18, 0,
714 56, 0, 19, 20, 10, 42, 43, 0, 57, 66,
715 0, 54, 0, 69, 25, 35, 0, 0, 0, 0,
716 0, 36, 0, 60, 40, 0, 0, 68, 32, 33,
717 34, 0, 0, 0, 0, 38, 37, 55, 59, 49,
718 51, 0, 0, 27, 46, 0, 0, 52, 29
719 };
720
721 /* YYDEFGOTO[NTERM-NUM]. */
722 static const yytype_int8 yydefgoto[] =
723 {
724 -1, 4, 5, 6, 7, 8, 25, 26, 27, 28,
725 29, 59, 60, 30, 103, 65, 107, 46, 76, 47,
726 91, 66, 53, 49, 83, 67, 50, 71, 51, 31,
727 32, 33, 34, 61, 35, 36
728 };
729
730 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
731 STATE-NUM. */
732 #define YYPACT_NINF -63
733 static const yytype_int16 yypact[] =
734 {
735 18, -63, -63, 13, 19, 14, -63, 29, -12, -63,
736 -63, -63, -63, 28, -63, 32, -63, -63, -12, -63,
737 -4, -4, -4, -63, 26, -63, 29, -63, 55, -12,
738 62, 30, 66, 67, 26, 68, 73, -63, -63, 74,
739 -63, -63, -63, 31, -12, 58, -63, -63, -12, -63,
740 37, -63, -63, -63, 50, 26, -63, -63, -63, -12,
741 -63, -63, -63, 30, 30, 108, 54, -63, -63, 168,
742 26, -12, -63, -63, -63, -63, -63, 51, -63, -63,
743 -12, -63, -12, -12, -63, -63, 46, 30, 30, 86,
744 -12, 5, 128, -63, -63, 53, 60, -63, -63, -63,
745 78, 168, 30, 82, 61, -63, -63, 26, -63, -63,
746 -63, 148, 108, -63, -63, -12, 86, -63, -63
747 };
748
749 /* YYPGOTO[NTERM-NUM]. */
750 static const yytype_int8 yypgoto[] =
751 {
752 -63, -63, -63, 88, -63, -63, 84, -62, -25, -63,
753 -63, -63, 35, -63, -16, -59, -63, 69, -63, 2,
754 -63, 93, 94, -63, -63, -63, -22, 11, -44, -63,
755 -63, -63, -63, -8, -63, -63
756 };
757
758 /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
759 positive, shift that token. If negative, reduce the rule which
760 number is the opposite. If YYTABLE_NINF, syntax error. */
761 #define YYTABLE_NINF -31
762 static const yytype_int8 yytable[] =
763 {
764 39, 57, 55, 89, 85, 86, 81, 92, 37, 38,
765 42, 81, 70, 105, -2, 11, 9, 1, 2, 10,
766 43, 1, 2, 52, 52, 44, 81, 45, 99, 100,
767 13, 40, 14, 106, 15, 41, 77, 3, 16, 111,
768 79, 3, 17, 112, 18, 19, 20, 21, 22, 23,
769 116, 24, 87, 88, 43, 63, 64, 45, 58, 44,
770 44, 45, 45, 93, 57, 62, 80, 57, 45, 68,
771 69, 72, 95, 98, 96, 97, 73, 74, 78, 82,
772 90, 94, 104, 109, 87, 70, 57, 13, 114, 14,
773 110, 57, 113, 12, 84, 16, -28, 101, 102, 17,
774 118, 18, 19, 20, 21, 22, 23, 117, 24, 13,
775 56, 14, 75, 48, 87, 88, 54, 16, 115, 0,
776 0, 17, 0, 18, 19, 20, 21, 22, 23, 13,
777 24, 14, 0, 0, 0, 0, 0, 16, 0, 0,
778 0, 17, 108, 18, 19, 20, 21, 22, 23, 13,
779 24, 14, 0, 0, 0, 0, 0, 16, -30, 0,
780 0, 17, 0, 18, 19, 20, 21, 22, 23, 13,
781 24, 14, 0, 0, 0, 0, 0, 16, 0, 0,
782 0, 17, 0, 18, 19, 20, 21, 22, 23, 0,
783 24
784 };
785
786 #define yypact_value_is_default(yystate) \
787 ((yystate) == (-63))
788
789 #define yytable_value_is_error(yytable_value) \
790 YYID (0)
791
792 static const yytype_int8 yycheck[] =
793 {
794 8, 26, 24, 65, 63, 64, 50, 69, 20, 21,
795 18, 55, 34, 8, 0, 1, 3, 3, 4, 0,
796 24, 3, 4, 21, 22, 29, 70, 31, 87, 88,
797 1, 3, 3, 28, 5, 3, 44, 23, 9, 101,
798 48, 23, 13, 102, 15, 16, 17, 18, 19, 20,
799 112, 22, 6, 7, 24, 25, 26, 31, 3, 29,
800 29, 31, 31, 71, 89, 3, 29, 92, 31, 3,
801 3, 3, 80, 27, 82, 83, 3, 3, 20, 29,
802 26, 30, 90, 30, 6, 107, 111, 1, 27, 3,
803 30, 116, 10, 5, 59, 9, 10, 11, 12, 13,
804 116, 15, 16, 17, 18, 19, 20, 115, 22, 1,
805 26, 3, 43, 20, 6, 7, 22, 9, 107, -1,
806 -1, 13, -1, 15, 16, 17, 18, 19, 20, 1,
807 22, 3, -1, -1, -1, -1, -1, 9, -1, -1,
808 -1, 13, 14, 15, 16, 17, 18, 19, 20, 1,
809 22, 3, -1, -1, -1, -1, -1, 9, 10, -1,
810 -1, 13, -1, 15, 16, 17, 18, 19, 20, 1,
811 22, 3, -1, -1, -1, -1, -1, 9, -1, -1,
812 -1, 13, -1, 15, 16, 17, 18, 19, 20, -1,
813 22
814 };
815
816 /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
817 symbol of state STATE-NUM. */
818 static const yytype_uint8 yystos[] =
819 {
820 0, 3, 4, 23, 33, 34, 35, 36, 37, 3,
821 0, 1, 35, 1, 3, 5, 9, 13, 15, 16,
822 17, 18, 19, 20, 22, 38, 39, 40, 41, 42,
823 45, 61, 62, 63, 64, 66, 67, 20, 21, 65,
824 3, 3, 65, 24, 29, 31, 49, 51, 53, 55,
825 58, 60, 51, 54, 54, 58, 38, 40, 3, 43,
826 44, 65, 3, 25, 26, 47, 53, 57, 3, 3,
827 58, 59, 3, 3, 3, 49, 50, 65, 20, 65,
828 29, 60, 29, 56, 44, 47, 47, 6, 7, 39,
829 26, 52, 39, 65, 30, 65, 65, 65, 27, 47,
830 47, 11, 12, 46, 65, 8, 28, 48, 14, 30,
831 30, 39, 47, 10, 27, 59, 39, 65, 46
832 };
833
834 #define yyerrok (yyerrstatus = 0)
835 #define yyclearin (yychar = YYEMPTY)
836 #define YYEMPTY (-2)
837 #define YYEOF 0
838
839 #define YYACCEPT goto yyacceptlab
840 #define YYABORT goto yyabortlab
841 #define YYERROR goto yyerrorlab
842
843
844 /* Like YYERROR except do call yyerror. This remains here temporarily
845 to ease the transition to the new meaning of YYERROR, for GCC.
846 Once GCC version 2 has supplanted version 1, this can go. However,
847 YYFAIL appears to be in use. Nevertheless, it is formally deprecated
848 in Bison 2.4.2's NEWS entry, where a plan to phase it out is
849 discussed. */
850
851 #define YYFAIL goto yyerrlab
852 #if defined YYFAIL
853 /* This is here to suppress warnings from the GCC cpp's
854 -Wunused-macros. Normally we don't worry about that warning, but
855 some users do, and we want to make it easy for users to remove
856 YYFAIL uses, which will produce warnings from Bison 2.5. */
857 #endif
858
859 #define YYRECOVERING() (!!yyerrstatus)
860
861 #define YYBACKUP(Token, Value) \
862 do \
863 if (yychar == YYEMPTY) \
864 { \
865 yychar = (Token); \
866 yylval = (Value); \
867 YYPOPSTACK (yylen); \
868 yystate = *yyssp; \
869 goto yybackup; \
870 } \
871 else \
872 { \
873 yyerror (YY_("syntax error: cannot back up")); \
874 YYERROR; \
875 } \
876 while (YYID (0))
877
878
879 #define YYTERROR 1
880 #define YYERRCODE 256
881
882
883 /* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
884 If N is 0, then set CURRENT to the empty location which ends
885 the previous symbol: RHS[0] (always defined). */
886
887 #define YYRHSLOC(Rhs, K) ((Rhs)[K])
888 #ifndef YYLLOC_DEFAULT
889 # define YYLLOC_DEFAULT(Current, Rhs, N) \
890 do \
891 if (YYID (N)) \
892 { \
893 (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \
894 (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \
895 (Current).last_line = YYRHSLOC (Rhs, N).last_line; \
896 (Current).last_column = YYRHSLOC (Rhs, N).last_column; \
897 } \
898 else \
899 { \
900 (Current).first_line = (Current).last_line = \
901 YYRHSLOC (Rhs, 0).last_line; \
902 (Current).first_column = (Current).last_column = \
903 YYRHSLOC (Rhs, 0).last_column; \
904 } \
905 while (YYID (0))
906 #endif
907
908
909 /* YY_LOCATION_PRINT -- Print the location on the stream.
910 This macro was not mandated originally: define only if we know
911 we won't break user code: when these are the locations we know. */
912
913 #ifndef YY_LOCATION_PRINT
914 # if defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL
915 # define YY_LOCATION_PRINT(File, Loc) \
916 fprintf (File, "%d.%d-%d.%d", \
917 (Loc).first_line, (Loc).first_column, \
918 (Loc).last_line, (Loc).last_column)
919 # else
920 # define YY_LOCATION_PRINT(File, Loc) ((void) 0)
921 # endif
922 #endif
923
924
925 /* YYLEX -- calling `yylex' with the right arguments. */
926
927 #ifdef YYLEX_PARAM
928 # define YYLEX yylex (YYLEX_PARAM)
929 #else
930 # define YYLEX yylex ()
931 #endif
932
933 /* Enable debugging if requested. */
934 #if YYDEBUG
935
936 # ifndef YYFPRINTF
937 # include <stdio.h> /* INFRINGES ON USER NAME SPACE */
938 # define YYFPRINTF fprintf
939 # endif
940
941 # define YYDPRINTF(Args) \
942 do { \
943 if (yydebug) \
944 YYFPRINTF Args; \
945 } while (YYID (0))
946
947 # define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
948 do { \
949 if (yydebug) \
950 { \
951 YYFPRINTF (stderr, "%s ", Title); \
952 yy_symbol_print (stderr, \
953 Type, Value, Location); \
954 YYFPRINTF (stderr, "\n"); \
955 } \
956 } while (YYID (0))
957
958
959 /*--------------------------------.
960 | Print this symbol on YYOUTPUT. |
961 `--------------------------------*/
962
963 /*ARGSUSED*/
964 #if (defined __STDC__ || defined __C99__FUNC__ \
965 || defined __cplusplus || defined _MSC_VER)
966 static void
yy_symbol_value_print(FILE * yyoutput,int yytype,YYSTYPE const * const yyvaluep,YYLTYPE const * const yylocationp)967 yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, YYLTYPE const * const yylocationp)
968 #else
969 static void
970 yy_symbol_value_print (yyoutput, yytype, yyvaluep, yylocationp)
971 FILE *yyoutput;
972 int yytype;
973 YYSTYPE const * const yyvaluep;
974 YYLTYPE const * const yylocationp;
975 #endif
976 {
977 FILE *yyo = yyoutput;
978 YYUSE (yyo);
979 if (!yyvaluep)
980 return;
981 YYUSE (yylocationp);
982 # ifdef YYPRINT
983 if (yytype < YYNTOKENS)
984 YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep);
985 # else
986 YYUSE (yyoutput);
987 # endif
988 switch (yytype)
989 {
990 default:
991 break;
992 }
993 }
994
995
996 /*--------------------------------.
997 | Print this symbol on YYOUTPUT. |
998 `--------------------------------*/
999
1000 #if (defined __STDC__ || defined __C99__FUNC__ \
1001 || defined __cplusplus || defined _MSC_VER)
1002 static void
yy_symbol_print(FILE * yyoutput,int yytype,YYSTYPE const * const yyvaluep,YYLTYPE const * const yylocationp)1003 yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, YYLTYPE const * const yylocationp)
1004 #else
1005 static void
1006 yy_symbol_print (yyoutput, yytype, yyvaluep, yylocationp)
1007 FILE *yyoutput;
1008 int yytype;
1009 YYSTYPE const * const yyvaluep;
1010 YYLTYPE const * const yylocationp;
1011 #endif
1012 {
1013 if (yytype < YYNTOKENS)
1014 YYFPRINTF (yyoutput, "token %s (", yytname[yytype]);
1015 else
1016 YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]);
1017
1018 YY_LOCATION_PRINT (yyoutput, *yylocationp);
1019 YYFPRINTF (yyoutput, ": ");
1020 yy_symbol_value_print (yyoutput, yytype, yyvaluep, yylocationp);
1021 YYFPRINTF (yyoutput, ")");
1022 }
1023
1024 /*------------------------------------------------------------------.
1025 | yy_stack_print -- Print the state stack from its BOTTOM up to its |
1026 | TOP (included). |
1027 `------------------------------------------------------------------*/
1028
1029 #if (defined __STDC__ || defined __C99__FUNC__ \
1030 || defined __cplusplus || defined _MSC_VER)
1031 static void
yy_stack_print(yytype_int16 * yybottom,yytype_int16 * yytop)1032 yy_stack_print (yytype_int16 *yybottom, yytype_int16 *yytop)
1033 #else
1034 static void
1035 yy_stack_print (yybottom, yytop)
1036 yytype_int16 *yybottom;
1037 yytype_int16 *yytop;
1038 #endif
1039 {
1040 YYFPRINTF (stderr, "Stack now");
1041 for (; yybottom <= yytop; yybottom++)
1042 {
1043 int yybot = *yybottom;
1044 YYFPRINTF (stderr, " %d", yybot);
1045 }
1046 YYFPRINTF (stderr, "\n");
1047 }
1048
1049 # define YY_STACK_PRINT(Bottom, Top) \
1050 do { \
1051 if (yydebug) \
1052 yy_stack_print ((Bottom), (Top)); \
1053 } while (YYID (0))
1054
1055
1056 /*------------------------------------------------.
1057 | Report that the YYRULE is going to be reduced. |
1058 `------------------------------------------------*/
1059
1060 #if (defined __STDC__ || defined __C99__FUNC__ \
1061 || defined __cplusplus || defined _MSC_VER)
1062 static void
yy_reduce_print(YYSTYPE * yyvsp,YYLTYPE * yylsp,int yyrule)1063 yy_reduce_print (YYSTYPE *yyvsp, YYLTYPE *yylsp, int yyrule)
1064 #else
1065 static void
1066 yy_reduce_print (yyvsp, yylsp, yyrule)
1067 YYSTYPE *yyvsp;
1068 YYLTYPE *yylsp;
1069 int yyrule;
1070 #endif
1071 {
1072 int yynrhs = yyr2[yyrule];
1073 int yyi;
1074 unsigned long int yylno = yyrline[yyrule];
1075 YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n",
1076 yyrule - 1, yylno);
1077 /* The symbols being reduced. */
1078 for (yyi = 0; yyi < yynrhs; yyi++)
1079 {
1080 YYFPRINTF (stderr, " $%d = ", yyi + 1);
1081 yy_symbol_print (stderr, yyrhs[yyprhs[yyrule] + yyi],
1082 &(yyvsp[(yyi + 1) - (yynrhs)])
1083 , &(yylsp[(yyi + 1) - (yynrhs)]) );
1084 YYFPRINTF (stderr, "\n");
1085 }
1086 }
1087
1088 # define YY_REDUCE_PRINT(Rule) \
1089 do { \
1090 if (yydebug) \
1091 yy_reduce_print (yyvsp, yylsp, Rule); \
1092 } while (YYID (0))
1093
1094 /* Nonzero means print parse trace. It is left uninitialized so that
1095 multiple parsers can coexist. */
1096 int yydebug;
1097 #else /* !YYDEBUG */
1098 # define YYDPRINTF(Args)
1099 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
1100 # define YY_STACK_PRINT(Bottom, Top)
1101 # define YY_REDUCE_PRINT(Rule)
1102 #endif /* !YYDEBUG */
1103
1104
1105 /* YYINITDEPTH -- initial size of the parser's stacks. */
1106 #ifndef YYINITDEPTH
1107 # define YYINITDEPTH 200
1108 #endif
1109
1110 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
1111 if the built-in stack extension method is used).
1112
1113 Do not make this value too large; the results are undefined if
1114 YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH)
1115 evaluated with infinite-precision integer arithmetic. */
1116
1117 #ifndef YYMAXDEPTH
1118 # define YYMAXDEPTH 10000
1119 #endif
1120
1121
1122 #if YYERROR_VERBOSE
1123
1124 # ifndef yystrlen
1125 # if defined __GLIBC__ && defined _STRING_H
1126 # define yystrlen strlen
1127 # else
1128 /* Return the length of YYSTR. */
1129 #if (defined __STDC__ || defined __C99__FUNC__ \
1130 || defined __cplusplus || defined _MSC_VER)
1131 static YYSIZE_T
yystrlen(const char * yystr)1132 yystrlen (const char *yystr)
1133 #else
1134 static YYSIZE_T
1135 yystrlen (yystr)
1136 const char *yystr;
1137 #endif
1138 {
1139 YYSIZE_T yylen;
1140 for (yylen = 0; yystr[yylen]; yylen++)
1141 continue;
1142 return yylen;
1143 }
1144 # endif
1145 # endif
1146
1147 # ifndef yystpcpy
1148 # if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
1149 # define yystpcpy stpcpy
1150 # else
1151 /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
1152 YYDEST. */
1153 #if (defined __STDC__ || defined __C99__FUNC__ \
1154 || defined __cplusplus || defined _MSC_VER)
1155 static char *
yystpcpy(char * yydest,const char * yysrc)1156 yystpcpy (char *yydest, const char *yysrc)
1157 #else
1158 static char *
1159 yystpcpy (yydest, yysrc)
1160 char *yydest;
1161 const char *yysrc;
1162 #endif
1163 {
1164 char *yyd = yydest;
1165 const char *yys = yysrc;
1166
1167 while ((*yyd++ = *yys++) != '\0')
1168 continue;
1169
1170 return yyd - 1;
1171 }
1172 # endif
1173 # endif
1174
1175 # ifndef yytnamerr
1176 /* Copy to YYRES the contents of YYSTR after stripping away unnecessary
1177 quotes and backslashes, so that it's suitable for yyerror. The
1178 heuristic is that double-quoting is unnecessary unless the string
1179 contains an apostrophe, a comma, or backslash (other than
1180 backslash-backslash). YYSTR is taken from yytname. If YYRES is
1181 null, do not copy; instead, return the length of what the result
1182 would have been. */
1183 static YYSIZE_T
yytnamerr(char * yyres,const char * yystr)1184 yytnamerr (char *yyres, const char *yystr)
1185 {
1186 if (*yystr == '"')
1187 {
1188 YYSIZE_T yyn = 0;
1189 char const *yyp = yystr;
1190
1191 for (;;)
1192 switch (*++yyp)
1193 {
1194 case '\'':
1195 case ',':
1196 goto do_not_strip_quotes;
1197
1198 case '\\':
1199 if (*++yyp != '\\')
1200 goto do_not_strip_quotes;
1201 /* Fall through. */
1202 default:
1203 if (yyres)
1204 yyres[yyn] = *yyp;
1205 yyn++;
1206 break;
1207
1208 case '"':
1209 if (yyres)
1210 yyres[yyn] = '\0';
1211 return yyn;
1212 }
1213 do_not_strip_quotes: ;
1214 }
1215
1216 if (! yyres)
1217 return yystrlen (yystr);
1218
1219 return yystpcpy (yyres, yystr) - yyres;
1220 }
1221 # endif
1222
1223 /* Copy into *YYMSG, which is of size *YYMSG_ALLOC, an error message
1224 about the unexpected token YYTOKEN for the state stack whose top is
1225 YYSSP.
1226
1227 Return 0 if *YYMSG was successfully written. Return 1 if *YYMSG is
1228 not large enough to hold the message. In that case, also set
1229 *YYMSG_ALLOC to the required number of bytes. Return 2 if the
1230 required number of bytes is too large to store. */
1231 static int
yysyntax_error(YYSIZE_T * yymsg_alloc,char ** yymsg,yytype_int16 * yyssp,int yytoken)1232 yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg,
1233 yytype_int16 *yyssp, int yytoken)
1234 {
1235 YYSIZE_T yysize0 = yytnamerr (YY_NULL, yytname[yytoken]);
1236 YYSIZE_T yysize = yysize0;
1237 YYSIZE_T yysize1;
1238 enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
1239 /* Internationalized format string. */
1240 const char *yyformat = YY_NULL;
1241 /* Arguments of yyformat. */
1242 char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
1243 /* Number of reported tokens (one for the "unexpected", one per
1244 "expected"). */
1245 int yycount = 0;
1246
1247 /* There are many possibilities here to consider:
1248 - Assume YYFAIL is not used. It's too flawed to consider. See
1249 <http://lists.gnu.org/archive/html/bison-patches/2009-12/msg00024.html>
1250 for details. YYERROR is fine as it does not invoke this
1251 function.
1252 - If this state is a consistent state with a default action, then
1253 the only way this function was invoked is if the default action
1254 is an error action. In that case, don't check for expected
1255 tokens because there are none.
1256 - The only way there can be no lookahead present (in yychar) is if
1257 this state is a consistent state with a default action. Thus,
1258 detecting the absence of a lookahead is sufficient to determine
1259 that there is no unexpected or expected token to report. In that
1260 case, just report a simple "syntax error".
1261 - Don't assume there isn't a lookahead just because this state is a
1262 consistent state with a default action. There might have been a
1263 previous inconsistent state, consistent state with a non-default
1264 action, or user semantic action that manipulated yychar.
1265 - Of course, the expected token list depends on states to have
1266 correct lookahead information, and it depends on the parser not
1267 to perform extra reductions after fetching a lookahead from the
1268 scanner and before detecting a syntax error. Thus, state merging
1269 (from LALR or IELR) and default reductions corrupt the expected
1270 token list. However, the list is correct for canonical LR with
1271 one exception: it will still contain any token that will not be
1272 accepted due to an error action in a later state.
1273 */
1274 if (yytoken != YYEMPTY)
1275 {
1276 int yyn = yypact[*yyssp];
1277 yyarg[yycount++] = yytname[yytoken];
1278 if (!yypact_value_is_default (yyn))
1279 {
1280 /* Start YYX at -YYN if negative to avoid negative indexes in
1281 YYCHECK. In other words, skip the first -YYN actions for
1282 this state because they are default actions. */
1283 int yyxbegin = yyn < 0 ? -yyn : 0;
1284 /* Stay within bounds of both yycheck and yytname. */
1285 int yychecklim = YYLAST - yyn + 1;
1286 int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
1287 int yyx;
1288
1289 for (yyx = yyxbegin; yyx < yyxend; ++yyx)
1290 if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR
1291 && !yytable_value_is_error (yytable[yyx + yyn]))
1292 {
1293 if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
1294 {
1295 yycount = 1;
1296 yysize = yysize0;
1297 break;
1298 }
1299 yyarg[yycount++] = yytname[yyx];
1300 yysize1 = yysize + yytnamerr (YY_NULL, yytname[yyx]);
1301 if (! (yysize <= yysize1
1302 && yysize1 <= YYSTACK_ALLOC_MAXIMUM))
1303 return 2;
1304 yysize = yysize1;
1305 }
1306 }
1307 }
1308
1309 switch (yycount)
1310 {
1311 # define YYCASE_(N, S) \
1312 case N: \
1313 yyformat = S; \
1314 break
1315 YYCASE_(0, YY_("syntax error"));
1316 YYCASE_(1, YY_("syntax error, unexpected %s"));
1317 YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s"));
1318 YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s"));
1319 YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s"));
1320 YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"));
1321 # undef YYCASE_
1322 }
1323
1324 yysize1 = yysize + yystrlen (yyformat);
1325 if (! (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM))
1326 return 2;
1327 yysize = yysize1;
1328
1329 if (*yymsg_alloc < yysize)
1330 {
1331 *yymsg_alloc = 2 * yysize;
1332 if (! (yysize <= *yymsg_alloc
1333 && *yymsg_alloc <= YYSTACK_ALLOC_MAXIMUM))
1334 *yymsg_alloc = YYSTACK_ALLOC_MAXIMUM;
1335 return 1;
1336 }
1337
1338 /* Avoid sprintf, as that infringes on the user's name space.
1339 Don't have undefined behavior even if the translation
1340 produced a string with the wrong number of "%s"s. */
1341 {
1342 char *yyp = *yymsg;
1343 int yyi = 0;
1344 while ((*yyp = *yyformat) != '\0')
1345 if (*yyp == '%' && yyformat[1] == 's' && yyi < yycount)
1346 {
1347 yyp += yytnamerr (yyp, yyarg[yyi++]);
1348 yyformat += 2;
1349 }
1350 else
1351 {
1352 yyp++;
1353 yyformat++;
1354 }
1355 }
1356 return 0;
1357 }
1358 #endif /* YYERROR_VERBOSE */
1359
1360 /*-----------------------------------------------.
1361 | Release the memory associated to this symbol. |
1362 `-----------------------------------------------*/
1363
1364 /*ARGSUSED*/
1365 #if (defined __STDC__ || defined __C99__FUNC__ \
1366 || defined __cplusplus || defined _MSC_VER)
1367 static void
yydestruct(const char * yymsg,int yytype,YYSTYPE * yyvaluep,YYLTYPE * yylocationp)1368 yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep, YYLTYPE *yylocationp)
1369 #else
1370 static void
1371 yydestruct (yymsg, yytype, yyvaluep, yylocationp)
1372 const char *yymsg;
1373 int yytype;
1374 YYSTYPE *yyvaluep;
1375 YYLTYPE *yylocationp;
1376 #endif
1377 {
1378 YYUSE (yyvaluep);
1379 YYUSE (yylocationp);
1380
1381 if (!yymsg)
1382 yymsg = "Deleting";
1383 YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
1384
1385 switch (yytype)
1386 {
1387
1388 default:
1389 break;
1390 }
1391 }
1392
1393
1394 /* Prevent warnings from -Wmissing-prototypes. */
1395 #ifdef YYPARSE_PARAM
1396 #if defined __STDC__ || defined __cplusplus
1397 int yyparse (void *YYPARSE_PARAM);
1398 #else
1399 int yyparse ();
1400 #endif
1401 #else /* ! YYPARSE_PARAM */
1402 #if defined __STDC__ || defined __cplusplus
1403 int yyparse (void);
1404 #else
1405 int yyparse ();
1406 #endif
1407 #endif /* ! YYPARSE_PARAM */
1408
1409
1410 /* The lookahead symbol. */
1411 int yychar;
1412
1413 /* The semantic value of the lookahead symbol. */
1414 YYSTYPE yylval;
1415
1416 /* Location data for the lookahead symbol. */
1417 YYLTYPE yylloc;
1418
1419 /* Number of syntax errors so far. */
1420 int yynerrs;
1421
1422
1423 /*----------.
1424 | yyparse. |
1425 `----------*/
1426
1427 #ifdef YYPARSE_PARAM
1428 #if (defined __STDC__ || defined __C99__FUNC__ \
1429 || defined __cplusplus || defined _MSC_VER)
1430 int
yyparse(void * YYPARSE_PARAM)1431 yyparse (void *YYPARSE_PARAM)
1432 #else
1433 int
1434 yyparse (YYPARSE_PARAM)
1435 void *YYPARSE_PARAM;
1436 #endif
1437 #else /* ! YYPARSE_PARAM */
1438 #if (defined __STDC__ || defined __C99__FUNC__ \
1439 || defined __cplusplus || defined _MSC_VER)
1440 int
1441 yyparse (void)
1442 #else
1443 int
1444 yyparse ()
1445
1446 #endif
1447 #endif
1448 {
1449 int yystate;
1450 /* Number of tokens to shift before error messages enabled. */
1451 int yyerrstatus;
1452
1453 /* The stacks and their tools:
1454 `yyss': related to states.
1455 `yyvs': related to semantic values.
1456 `yyls': related to locations.
1457
1458 Refer to the stacks through separate pointers, to allow yyoverflow
1459 to reallocate them elsewhere. */
1460
1461 /* The state stack. */
1462 yytype_int16 yyssa[YYINITDEPTH];
1463 yytype_int16 *yyss;
1464 yytype_int16 *yyssp;
1465
1466 /* The semantic value stack. */
1467 YYSTYPE yyvsa[YYINITDEPTH];
1468 YYSTYPE *yyvs;
1469 YYSTYPE *yyvsp;
1470
1471 /* The location stack. */
1472 YYLTYPE yylsa[YYINITDEPTH];
1473 YYLTYPE *yyls;
1474 YYLTYPE *yylsp;
1475
1476 /* The locations where the error started and ended. */
1477 YYLTYPE yyerror_range[3];
1478
1479 YYSIZE_T yystacksize;
1480
1481 int yyn;
1482 int yyresult;
1483 /* Lookahead token as an internal (translated) token number. */
1484 int yytoken;
1485 /* The variables used to return semantic value and location from the
1486 action routines. */
1487 YYSTYPE yyval;
1488 YYLTYPE yyloc;
1489
1490 #if YYERROR_VERBOSE
1491 /* Buffer for error messages, and its allocated size. */
1492 char yymsgbuf[128];
1493 char *yymsg = yymsgbuf;
1494 YYSIZE_T yymsg_alloc = sizeof yymsgbuf;
1495 #endif
1496
1497 #define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N), yylsp -= (N))
1498
1499 /* The number of symbols on the RHS of the reduced rule.
1500 Keep to zero when no symbol should be popped. */
1501 int yylen = 0;
1502
1503 yytoken = 0;
1504 yyss = yyssa;
1505 yyvs = yyvsa;
1506 yyls = yylsa;
1507 yystacksize = YYINITDEPTH;
1508
1509 YYDPRINTF ((stderr, "Starting parse\n"));
1510
1511 yystate = 0;
1512 yyerrstatus = 0;
1513 yynerrs = 0;
1514 yychar = YYEMPTY; /* Cause a token to be read. */
1515
1516 /* Initialize stack pointers.
1517 Waste one element of value and location stack
1518 so that they stay on the same level as the state stack.
1519 The wasted elements are never initialized. */
1520 yyssp = yyss;
1521 yyvsp = yyvs;
1522 yylsp = yyls;
1523
1524 #if defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL
1525 /* Initialize the default location before parsing starts. */
1526 yylloc.first_line = yylloc.last_line = 1;
1527 yylloc.first_column = yylloc.last_column = 1;
1528 #endif
1529
1530 goto yysetstate;
1531
1532 /*------------------------------------------------------------.
1533 | yynewstate -- Push a new state, which is found in yystate. |
1534 `------------------------------------------------------------*/
1535 yynewstate:
1536 /* In all cases, when you get here, the value and location stacks
1537 have just been pushed. So pushing a state here evens the stacks. */
1538 yyssp++;
1539
1540 yysetstate:
1541 *yyssp = yystate;
1542
1543 if (yyss + yystacksize - 1 <= yyssp)
1544 {
1545 /* Get the current used size of the three stacks, in elements. */
1546 YYSIZE_T yysize = yyssp - yyss + 1;
1547
1548 #ifdef yyoverflow
1549 {
1550 /* Give user a chance to reallocate the stack. Use copies of
1551 these so that the &'s don't force the real ones into
1552 memory. */
1553 YYSTYPE *yyvs1 = yyvs;
1554 yytype_int16 *yyss1 = yyss;
1555 YYLTYPE *yyls1 = yyls;
1556
1557 /* Each stack pointer address is followed by the size of the
1558 data in use in that stack, in bytes. This used to be a
1559 conditional around just the two extra args, but that might
1560 be undefined if yyoverflow is a macro. */
1561 yyoverflow (YY_("memory exhausted"),
1562 &yyss1, yysize * sizeof (*yyssp),
1563 &yyvs1, yysize * sizeof (*yyvsp),
1564 &yyls1, yysize * sizeof (*yylsp),
1565 &yystacksize);
1566
1567 yyls = yyls1;
1568 yyss = yyss1;
1569 yyvs = yyvs1;
1570 }
1571 #else /* no yyoverflow */
1572 # ifndef YYSTACK_RELOCATE
1573 goto yyexhaustedlab;
1574 # else
1575 /* Extend the stack our own way. */
1576 if (YYMAXDEPTH <= yystacksize)
1577 goto yyexhaustedlab;
1578 yystacksize *= 2;
1579 if (YYMAXDEPTH < yystacksize)
1580 yystacksize = YYMAXDEPTH;
1581
1582 {
1583 yytype_int16 *yyss1 = yyss;
1584 union yyalloc *yyptr =
1585 (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
1586 if (! yyptr)
1587 goto yyexhaustedlab;
1588 YYSTACK_RELOCATE (yyss_alloc, yyss);
1589 YYSTACK_RELOCATE (yyvs_alloc, yyvs);
1590 YYSTACK_RELOCATE (yyls_alloc, yyls);
1591 # undef YYSTACK_RELOCATE
1592 if (yyss1 != yyssa)
1593 YYSTACK_FREE (yyss1);
1594 }
1595 # endif
1596 #endif /* no yyoverflow */
1597
1598 yyssp = yyss + yysize - 1;
1599 yyvsp = yyvs + yysize - 1;
1600 yylsp = yyls + yysize - 1;
1601
1602 YYDPRINTF ((stderr, "Stack size increased to %lu\n",
1603 (unsigned long int) yystacksize));
1604
1605 if (yyss + yystacksize - 1 <= yyssp)
1606 YYABORT;
1607 }
1608
1609 YYDPRINTF ((stderr, "Entering state %d\n", yystate));
1610
1611 if (yystate == YYFINAL)
1612 YYACCEPT;
1613
1614 goto yybackup;
1615
1616 /*-----------.
1617 | yybackup. |
1618 `-----------*/
1619 yybackup:
1620
1621 /* Do appropriate processing given the current state. Read a
1622 lookahead token if we need one and don't already have one. */
1623
1624 /* First try to decide what to do without reference to lookahead token. */
1625 yyn = yypact[yystate];
1626 if (yypact_value_is_default (yyn))
1627 goto yydefault;
1628
1629 /* Not known => get a lookahead token if don't already have one. */
1630
1631 /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol. */
1632 if (yychar == YYEMPTY)
1633 {
1634 YYDPRINTF ((stderr, "Reading a token: "));
1635 yychar = YYLEX;
1636 }
1637
1638 if (yychar <= YYEOF)
1639 {
1640 yychar = yytoken = YYEOF;
1641 YYDPRINTF ((stderr, "Now at end of input.\n"));
1642 }
1643 else
1644 {
1645 yytoken = YYTRANSLATE (yychar);
1646 YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
1647 }
1648
1649 /* If the proper action on seeing token YYTOKEN is to reduce or to
1650 detect an error, take that action. */
1651 yyn += yytoken;
1652 if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
1653 goto yydefault;
1654 yyn = yytable[yyn];
1655 if (yyn <= 0)
1656 {
1657 if (yytable_value_is_error (yyn))
1658 goto yyerrlab;
1659 yyn = -yyn;
1660 goto yyreduce;
1661 }
1662
1663 /* Count tokens shifted since error; after three, turn off error
1664 status. */
1665 if (yyerrstatus)
1666 yyerrstatus--;
1667
1668 /* Shift the lookahead token. */
1669 YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
1670
1671 /* Discard the shifted token. */
1672 yychar = YYEMPTY;
1673
1674 yystate = yyn;
1675 *++yyvsp = yylval;
1676 *++yylsp = yylloc;
1677 goto yynewstate;
1678
1679
1680 /*-----------------------------------------------------------.
1681 | yydefault -- do the default action for the current state. |
1682 `-----------------------------------------------------------*/
1683 yydefault:
1684 yyn = yydefact[yystate];
1685 if (yyn == 0)
1686 goto yyerrlab;
1687 goto yyreduce;
1688
1689
1690 /*-----------------------------.
1691 | yyreduce -- Do a reduction. |
1692 `-----------------------------*/
1693 yyreduce:
1694 /* yyn is the number of a rule to reduce with. */
1695 yylen = yyr2[yyn];
1696
1697 /* If YYLEN is nonzero, implement the default value of the action:
1698 `$$ = $1'.
1699
1700 Otherwise, the following line sets YYVAL to garbage.
1701 This behavior is undocumented and Bison
1702 users should not rely upon it. Assigning to YYVAL
1703 unconditionally makes the parser a bit smaller, and it avoids a
1704 GCC warning that YYVAL may be used uninitialized. */
1705 yyval = yyvsp[1-yylen];
1706
1707 /* Default location. */
1708 YYLLOC_DEFAULT (yyloc, (yylsp - yylen), yylen);
1709 YY_REDUCE_PRINT (yyn);
1710 switch (yyn)
1711 {
1712 case 2:
1713
1714 /* Line 1810 of yacc.c */
1715 #line 156 "rc-gram.y"
1716 {
1717 }
1718 break;
1719
1720 case 3:
1721
1722 /* Line 1810 of yacc.c */
1723 #line 161 "rc-gram.y"
1724 {
1725 (yyval.section) = rc_section = (yyvsp[(1) - (1)].section);
1726 }
1727 break;
1728
1729 case 4:
1730
1731 /* Line 1810 of yacc.c */
1732 #line 165 "rc-gram.y"
1733 {
1734 if ((yyvsp[(2) - (2)].section))
1735 {
1736 if (rc_section == NULL)
1737 {
1738 (yyval.section) = rc_section = (yyvsp[(2) - (2)].section);
1739 }
1740 else
1741 {
1742 (yyvsp[(1) - (2)].section)->next = (yyvsp[(2) - (2)].section);
1743 (yyval.section) = (yyvsp[(2) - (2)].section);
1744 }
1745 }
1746 }
1747 break;
1748
1749 case 5:
1750
1751 /* Line 1810 of yacc.c */
1752 #line 180 "rc-gram.y"
1753 {
1754 lex_clear_state ();
1755 yychar = error_sync_begin ();
1756 if (yychar > 0)
1757 {
1758 yyerrok;
1759 yyclearin;
1760 }
1761 }
1762 break;
1763
1764 case 6:
1765
1766 /* Line 1810 of yacc.c */
1767 #line 192 "rc-gram.y"
1768 {
1769 (yyval.section) = NULL;
1770 }
1771 break;
1772
1773 case 7:
1774
1775 /* Line 1810 of yacc.c */
1776 #line 196 "rc-gram.y"
1777 {
1778 (yyval.section) = rc_section_create ((yyvsp[(1) - (3)].begin_sec), &(yylsp[(1) - (3)]).beg, (yyvsp[(2) - (3)].stmtlist).head);
1779 }
1780 break;
1781
1782 case 8:
1783
1784 /* Line 1810 of yacc.c */
1785 #line 200 "rc-gram.y"
1786 {
1787 (yyval.section) = NULL;
1788 }
1789 break;
1790
1791 case 9:
1792
1793 /* Line 1810 of yacc.c */
1794 #line 205 "rc-gram.y"
1795 { verbatim (); }
1796 break;
1797
1798 case 10:
1799
1800 /* Line 1810 of yacc.c */
1801 #line 206 "rc-gram.y"
1802 {
1803 (yyval.begin_sec) = (yyvsp[(3) - (4)].string);
1804 if (rc_section_lookup (rc_section, (yyvsp[(3) - (4)].string)))
1805 parse_error (&(yylsp[(3) - (4)]).beg, _("Section %s already defined"), (yyvsp[(3) - (4)].string));
1806 rc_secdef = anubis_find_section ((yyvsp[(3) - (4)].string));
1807 }
1808 break;
1809
1810 case 11:
1811
1812 /* Line 1810 of yacc.c */
1813 #line 213 "rc-gram.y"
1814 {
1815 (yyval.begin_sec) = (yyvsp[(1) - (2)].string);
1816 if (rc_section_lookup (rc_section, (yyvsp[(1) - (2)].string)))
1817 parse_error (&(yylsp[(1) - (2)]).beg, _("Section %s already defined"), (yyvsp[(1) - (2)].string));
1818 rc_secdef = anubis_find_section ((yyvsp[(1) - (2)].string));
1819 }
1820 break;
1821
1822 case 13:
1823
1824 /* Line 1810 of yacc.c */
1825 #line 225 "rc-gram.y"
1826 {
1827 (yyval.stmtlist).head = (yyval.stmtlist).tail = (yyvsp[(1) - (1)].stmt);
1828 }
1829 break;
1830
1831 case 14:
1832
1833 /* Line 1810 of yacc.c */
1834 #line 229 "rc-gram.y"
1835 {
1836 if ((yyvsp[(2) - (2)].stmt))
1837 {
1838 if ((yyval.stmtlist).head == NULL)
1839 {
1840 (yyval.stmtlist).head = (yyval.stmtlist).tail = (yyvsp[(2) - (2)].stmt);
1841 }
1842 else
1843 {
1844 (yyval.stmtlist).tail->next = (yyvsp[(2) - (2)].stmt);
1845 (yyval.stmtlist).tail = (yyvsp[(2) - (2)].stmt);
1846 }
1847 }
1848 }
1849 break;
1850
1851 case 15:
1852
1853 /* Line 1810 of yacc.c */
1854 #line 246 "rc-gram.y"
1855 {
1856 (yyval.stmt) = NULL;
1857 }
1858 break;
1859
1860 case 21:
1861
1862 /* Line 1810 of yacc.c */
1863 #line 255 "rc-gram.y"
1864 {
1865 lex_clear_state ();
1866 yyerrok;
1867 yyclearin;
1868 (yyval.stmt) = NULL;
1869 }
1870 break;
1871
1872 case 22:
1873
1874 /* Line 1810 of yacc.c */
1875 #line 264 "rc-gram.y"
1876 {
1877 int flags;
1878 if (!check_kw ((yyvsp[(1) - (2)].string), &flags))
1879 {
1880 parse_error (&(yylsp[(1) - (2)]).beg, _("unknown keyword: %s"), (yyvsp[(1) - (2)].string));
1881 YYERROR;
1882 }
1883
1884 (yyval.stmt) = rc_stmt_create (rc_stmt_asgn, &(yylsp[(1) - (2)]).beg);
1885 (yyval.stmt)->v.asgn.lhs = (yyvsp[(1) - (2)].string);
1886 if (list_count ((yyvsp[(2) - (2)].list)))
1887 {
1888 char *s = list_item ((yyvsp[(2) - (2)].list), 0);
1889 if (s && !strcmp (s, "="))
1890 list_remove ((yyvsp[(2) - (2)].list), s, NULL);
1891 }
1892 (yyval.stmt)->v.asgn.rhs = (yyvsp[(2) - (2)].list);
1893 (yyval.stmt)->v.asgn.flags = flags;
1894 }
1895 break;
1896
1897 case 23:
1898
1899 /* Line 1810 of yacc.c */
1900 #line 286 "rc-gram.y"
1901 {
1902 verbatim ();
1903 }
1904 break;
1905
1906 case 24:
1907
1908 /* Line 1810 of yacc.c */
1909 #line 292 "rc-gram.y"
1910 {
1911 (yyval.list) = list_create ();
1912 list_append ((yyval.list), (yyvsp[(1) - (1)].string));
1913 }
1914 break;
1915
1916 case 25:
1917
1918 /* Line 1810 of yacc.c */
1919 #line 297 "rc-gram.y"
1920 {
1921 list_append ((yyvsp[(1) - (2)].list), (yyvsp[(2) - (2)].string));
1922 (yyval.list) = (yyvsp[(1) - (2)].list);
1923 }
1924 break;
1925
1926 case 27:
1927
1928 /* Line 1810 of yacc.c */
1929 #line 307 "rc-gram.y"
1930 {
1931 (yyval.stmt) = rc_stmt_create (rc_stmt_cond, &(yylsp[(1) - (5)]).beg);
1932 (yyval.stmt)->v.cond.node = (yyvsp[(2) - (5)].node);
1933 (yyval.stmt)->v.cond.iftrue = (yyvsp[(3) - (5)].stmtlist).head;
1934 (yyval.stmt)->v.cond.iffalse = (yyvsp[(4) - (5)].stmt);
1935 }
1936 break;
1937
1938 case 28:
1939
1940 /* Line 1810 of yacc.c */
1941 #line 316 "rc-gram.y"
1942 {
1943 (yyval.stmt) = NULL;
1944 }
1945 break;
1946
1947 case 29:
1948
1949 /* Line 1810 of yacc.c */
1950 #line 320 "rc-gram.y"
1951 {
1952 (yyval.stmt) = rc_stmt_create (rc_stmt_cond, &(yylsp[(1) - (4)]).beg);
1953 (yyval.stmt)->v.cond.node = (yyvsp[(2) - (4)].node);
1954 (yyval.stmt)->v.cond.iftrue = (yyvsp[(3) - (4)].stmtlist).head;
1955 (yyval.stmt)->v.cond.iffalse = (yyvsp[(4) - (4)].stmt);
1956 }
1957 break;
1958
1959 case 30:
1960
1961 /* Line 1810 of yacc.c */
1962 #line 327 "rc-gram.y"
1963 {
1964 (yyval.stmt) = (yyvsp[(2) - (2)].stmtlist).head;
1965 }
1966 break;
1967
1968 case 32:
1969
1970 /* Line 1810 of yacc.c */
1971 #line 334 "rc-gram.y"
1972 {
1973 (yyval.node) = (yyvsp[(2) - (3)].node);
1974 }
1975 break;
1976
1977 case 33:
1978
1979 /* Line 1810 of yacc.c */
1980 #line 338 "rc-gram.y"
1981 {
1982 (yyval.node) = rc_node_create (rc_node_bool, &(yylsp[(2) - (3)]).beg);
1983 (yyval.node)->v.bool.op = bool_and;
1984 (yyval.node)->v.bool.left = (yyvsp[(1) - (3)].node);
1985 (yyval.node)->v.bool.right = (yyvsp[(3) - (3)].node);
1986 }
1987 break;
1988
1989 case 34:
1990
1991 /* Line 1810 of yacc.c */
1992 #line 345 "rc-gram.y"
1993 {
1994 (yyval.node) = rc_node_create (rc_node_bool, &(yylsp[(2) - (3)]).beg);
1995 (yyval.node)->v.bool.op = bool_or;
1996 (yyval.node)->v.bool.left = (yyvsp[(1) - (3)].node);
1997 (yyval.node)->v.bool.right = (yyvsp[(3) - (3)].node);
1998 }
1999 break;
2000
2001 case 35:
2002
2003 /* Line 1810 of yacc.c */
2004 #line 352 "rc-gram.y"
2005 {
2006 (yyval.node) = rc_node_create (rc_node_bool, &(yylsp[(1) - (2)]).beg);
2007 (yyval.node)->v.bool.op = bool_not;
2008 (yyval.node)->v.bool.left = (yyvsp[(2) - (2)].node);
2009 (yyval.node)->v.bool.right = NULL;
2010 }
2011 break;
2012
2013 case 36:
2014
2015 /* Line 1810 of yacc.c */
2016 #line 361 "rc-gram.y"
2017 {
2018 (yyval.eq) = 1;
2019 }
2020 break;
2021
2022 case 37:
2023
2024 /* Line 1810 of yacc.c */
2025 #line 365 "rc-gram.y"
2026 {
2027 (yyval.eq) = 1;
2028 }
2029 break;
2030
2031 case 38:
2032
2033 /* Line 1810 of yacc.c */
2034 #line 369 "rc-gram.y"
2035 {
2036 (yyval.eq) = 0;
2037 }
2038 break;
2039
2040 case 39:
2041
2042 /* Line 1810 of yacc.c */
2043 #line 375 "rc-gram.y"
2044 {
2045 (yyval.msgpart).part = HEADER;
2046 (yyval.msgpart).key = (yyvsp[(1) - (1)].regex);
2047 (yyval.msgpart).string = NULL;
2048 }
2049 break;
2050
2051 case 40:
2052
2053 /* Line 1810 of yacc.c */
2054 #line 381 "rc-gram.y"
2055 {
2056 (yyval.msgpart).part = HEADER;
2057 (yyval.msgpart).key = NULL;
2058 (yyval.msgpart).string = (yyvsp[(2) - (3)].string);
2059 }
2060 break;
2061
2062 case 41:
2063
2064 /* Line 1810 of yacc.c */
2065 #line 389 "rc-gram.y"
2066 {
2067 (yyval.msgpart).string = NULL;
2068 (yyval.msgpart).key = NULL;
2069 }
2070 break;
2071
2072 case 43:
2073
2074 /* Line 1810 of yacc.c */
2075 #line 397 "rc-gram.y"
2076 {
2077 (yyval.msgpart) = (yyvsp[(2) - (2)].msgpart);
2078 (yyval.msgpart).sep = NULL;
2079 (yyval.msgpart).part = (yyvsp[(1) - (2)].num);
2080 }
2081 break;
2082
2083 case 45:
2084
2085 /* Line 1810 of yacc.c */
2086 #line 406 "rc-gram.y"
2087 {
2088 (yyval.string) = NULL;
2089 }
2090 break;
2091
2092 case 46:
2093
2094 /* Line 1810 of yacc.c */
2095 #line 410 "rc-gram.y"
2096 {
2097 (yyval.string) = (yyvsp[(2) - (3)].string);
2098 }
2099 break;
2100
2101 case 47:
2102
2103 /* Line 1810 of yacc.c */
2104 #line 416 "rc-gram.y"
2105 {
2106 (yyval.msgpart) = (yyvsp[(1) - (1)].msgpart);
2107 if ((yyval.msgpart).key)
2108 parse_error (&(yylsp[(1) - (1)]).beg,
2109 _("regexp is not allowed in this context"));
2110 }
2111 break;
2112
2113 case 48:
2114
2115 /* Line 1810 of yacc.c */
2116 #line 425 "rc-gram.y"
2117 {
2118 (yyval.msgpart) = (yyvsp[(1) - (1)].msgpart);
2119 if (!(yyval.msgpart).key)
2120 {
2121 (yyval.msgpart).key = anubis_regex_compile ((yyval.msgpart).string, R_EXACT);
2122 xfree ((yyval.msgpart).string);
2123 }
2124 }
2125 break;
2126
2127 case 49:
2128
2129 /* Line 1810 of yacc.c */
2130 #line 436 "rc-gram.y"
2131 {
2132 (yyval.regex) = anubis_regex_compile ((yyvsp[(3) - (4)].string), (yyvsp[(1) - (4)].num));
2133 free ((yyvsp[(3) - (4)].string));
2134 if (!(yyval.regex))
2135 {
2136 parse_error (&(yylsp[(3) - (4)]).beg,
2137 _("Invalid regular expression (see the above message)"));
2138 YYERROR;
2139 }
2140 }
2141 break;
2142
2143 case 50:
2144
2145 /* Line 1810 of yacc.c */
2146 #line 449 "rc-gram.y"
2147 {
2148 (yyval.string) = NULL;
2149 }
2150 break;
2151
2152 case 51:
2153
2154 /* Line 1810 of yacc.c */
2155 #line 453 "rc-gram.y"
2156 {
2157 (yyval.string) = (yyvsp[(2) - (3)].string);
2158 }
2159 break;
2160
2161 case 52:
2162
2163 /* Line 1810 of yacc.c */
2164 #line 459 "rc-gram.y"
2165 {
2166 RC_NODE *node = rc_node_create (rc_node_expr, &(yylsp[(1) - (5)]).beg);
2167 node->v.expr.part = (yyvsp[(1) - (5)].msgpart).part;
2168 node->v.expr.key = (yyvsp[(1) - (5)].msgpart).string;
2169 node->v.expr.sep = (yyvsp[(2) - (5)].string);
2170 node->v.expr.re = anubis_regex_compile ((yyvsp[(5) - (5)].string), (yyvsp[(4) - (5)].num));
2171 free ((yyvsp[(5) - (5)].string));
2172 if ((yyvsp[(3) - (5)].eq))
2173 (yyval.node) = node;
2174 else
2175 {
2176 (yyval.node) = rc_node_create (rc_node_bool, &(yylsp[(1) - (5)]).beg);
2177 (yyval.node)->v.bool.op = bool_not;
2178 (yyval.node)->v.bool.left = node;
2179 (yyval.node)->v.bool.right = NULL;
2180 }
2181 }
2182 break;
2183
2184 case 53:
2185
2186 /* Line 1810 of yacc.c */
2187 #line 479 "rc-gram.y"
2188 {
2189 (yyval.num) = def_regex_modifier;
2190 reg_modifier_add (&(yyval.num), (yyvsp[(1) - (1)].string), &(yylsp[(1) - (1)]).beg);
2191 xfree ((yyvsp[(1) - (1)].string));
2192 }
2193 break;
2194
2195 case 54:
2196
2197 /* Line 1810 of yacc.c */
2198 #line 485 "rc-gram.y"
2199 {
2200 reg_modifier_add (&(yyvsp[(1) - (2)].num), (yyvsp[(2) - (2)].string), &(yylsp[(1) - (2)]).beg);
2201 xfree ((yyvsp[(2) - (2)].string));
2202 (yyval.num) = (yyvsp[(1) - (2)].num);
2203 }
2204 break;
2205
2206 case 55:
2207
2208 /* Line 1810 of yacc.c */
2209 #line 493 "rc-gram.y"
2210 {
2211 (yyval.num) = def_regex_modifier;
2212 }
2213 break;
2214
2215 case 57:
2216
2217 /* Line 1810 of yacc.c */
2218 #line 500 "rc-gram.y"
2219 {
2220 (yyval.string) = (yyvsp[(2) - (2)].string);
2221 }
2222 break;
2223
2224 case 58:
2225
2226 /* Line 1810 of yacc.c */
2227 #line 506 "rc-gram.y"
2228 {
2229 if (!is_prog_allowed (&(yylsp[(1) - (1)]).beg))
2230 YYERROR;
2231 }
2232 break;
2233
2234 case 59:
2235
2236 /* Line 1810 of yacc.c */
2237 #line 513 "rc-gram.y"
2238 {
2239 (yyval.stmt) = rc_stmt_create (rc_stmt_rule, &(yylsp[(1) - (4)]).beg);
2240 (yyval.stmt)->v.rule.node = (yyvsp[(1) - (4)].node);
2241 (yyval.stmt)->v.rule.stmt = (yyvsp[(3) - (4)].stmtlist).head;
2242 }
2243 break;
2244
2245 case 60:
2246
2247 /* Line 1810 of yacc.c */
2248 #line 521 "rc-gram.y"
2249 {
2250 (yyval.node) = rc_node_create (rc_node_expr, &(yylsp[(1) - (3)]).beg);
2251 (yyval.node)->v.expr.part = HEADER;
2252 (yyval.node)->v.expr.key = strdup (X_ANUBIS_RULE_HEADER);
2253 (yyval.node)->v.expr.re = anubis_regex_compile ((yyvsp[(3) - (3)].string), (yyvsp[(2) - (3)].num));
2254 free ((yyvsp[(3) - (3)].string));
2255 }
2256 break;
2257
2258 case 61:
2259
2260 /* Line 1810 of yacc.c */
2261 #line 531 "rc-gram.y"
2262 {
2263 if (!is_prog_allowed (&(yylsp[(1) - (1)]).beg))
2264 YYERROR;
2265 }
2266 break;
2267
2268 case 64:
2269
2270 /* Line 1810 of yacc.c */
2271 #line 542 "rc-gram.y"
2272 {
2273 if (!is_prog_allowed (&(yylsp[(1) - (1)]).beg))
2274 YYERROR;
2275
2276 (yyval.stmt) = rc_stmt_create (rc_stmt_inst, &(yylsp[(1) - (1)]).beg);
2277 (yyval.stmt)->v.inst.opcode = inst_stop;
2278 (yyval.stmt)->v.inst.part = NIL;
2279 (yyval.stmt)->v.inst.key = NULL;
2280 (yyval.stmt)->v.inst.key2 = NULL;
2281 (yyval.stmt)->v.inst.arg = NULL;
2282 }
2283 break;
2284
2285 case 65:
2286
2287 /* Line 1810 of yacc.c */
2288 #line 554 "rc-gram.y"
2289 {
2290 if (!is_prog_allowed (&(yylsp[(1) - (2)]).beg))
2291 YYERROR;
2292
2293 (yyval.stmt) = rc_stmt_create (rc_stmt_inst, &(yylsp[(1) - (2)]).beg);
2294 (yyval.stmt)->v.inst.opcode = inst_call;
2295 (yyval.stmt)->v.inst.key = NULL;
2296 (yyval.stmt)->v.inst.part = NIL;
2297 (yyval.stmt)->v.inst.key2 = NULL;
2298 (yyval.stmt)->v.inst.arg = (yyvsp[(2) - (2)].string);
2299 }
2300 break;
2301
2302 case 66:
2303
2304 /* Line 1810 of yacc.c */
2305 #line 566 "rc-gram.y"
2306 {
2307 if (!is_prog_allowed (&(yylsp[(1) - (3)]).beg))
2308 YYERROR;
2309
2310 if ((yyvsp[(2) - (3)].msgpart).part == COMMAND)
2311 {
2312 parse_error (&(yylsp[(2) - (3)]).beg, _("command part is not allowed"));
2313 YYERROR;
2314 }
2315
2316 (yyval.stmt) = rc_stmt_create (rc_stmt_inst, &(yylsp[(1) - (3)]).beg);
2317 (yyval.stmt)->v.inst.opcode = inst_add;
2318 (yyval.stmt)->v.inst.part = (yyvsp[(2) - (3)].msgpart).part;
2319 (yyval.stmt)->v.inst.key = NULL;
2320 (yyval.stmt)->v.inst.key2 = (yyvsp[(2) - (3)].msgpart).string;
2321 (yyval.stmt)->v.inst.arg = (yyvsp[(3) - (3)].string);
2322 }
2323 break;
2324
2325 case 67:
2326
2327 /* Line 1810 of yacc.c */
2328 #line 584 "rc-gram.y"
2329 {
2330 if (!is_prog_allowed (&(yylsp[(1) - (2)]).beg))
2331 YYERROR;
2332
2333 if ((yyvsp[(2) - (2)].msgpart).part == COMMAND)
2334 {
2335 parse_error (&(yylsp[(2) - (2)]).beg, _("command part is not allowed"));
2336 YYERROR;
2337 }
2338
2339 (yyval.stmt) = rc_stmt_create (rc_stmt_inst, &(yylsp[(1) - (2)]).beg);
2340 (yyval.stmt)->v.inst.opcode = inst_remove;
2341 (yyval.stmt)->v.inst.part = (yyvsp[(2) - (2)].msgpart).part;
2342 (yyval.stmt)->v.inst.key = (yyvsp[(2) - (2)].msgpart).key;
2343 (yyval.stmt)->v.inst.key2 = NULL;
2344 (yyval.stmt)->v.inst.arg = NULL;
2345 }
2346 break;
2347
2348 case 68:
2349
2350 /* Line 1810 of yacc.c */
2351 #line 602 "rc-gram.y"
2352 {
2353 if (!is_prog_allowed (&(yylsp[(1) - (4)]).beg))
2354 YYERROR;
2355
2356 (yyval.stmt) = rc_stmt_create (rc_stmt_inst, &(yylsp[(1) - (4)]).beg);
2357 (yyval.stmt)->v.inst.opcode = inst_modify;
2358 (yyval.stmt)->v.inst.part = (yyvsp[(2) - (4)].msgpart).part;
2359 (yyval.stmt)->v.inst.key = (yyvsp[(2) - (4)].msgpart).key;
2360 (yyval.stmt)->v.inst.key2 = (yyvsp[(3) - (4)].string);
2361 (yyval.stmt)->v.inst.arg = (yyvsp[(4) - (4)].string);
2362 }
2363 break;
2364
2365 case 69:
2366
2367 /* Line 1810 of yacc.c */
2368 #line 614 "rc-gram.y"
2369 {
2370 if (!is_prog_allowed (&(yylsp[(1) - (3)]).beg))
2371 YYERROR;
2372
2373 (yyval.stmt) = rc_stmt_create (rc_stmt_inst, &(yylsp[(1) - (3)]).beg);
2374 (yyval.stmt)->v.inst.opcode = inst_modify;
2375 (yyval.stmt)->v.inst.part = (yyvsp[(2) - (3)].msgpart).part;
2376 (yyval.stmt)->v.inst.key = (yyvsp[(2) - (3)].msgpart).key;
2377 if ((yyvsp[(3) - (3)].string) == NULL && anubis_regex_refcnt ((yyvsp[(2) - (3)].msgpart).key))
2378 parse_error (&(yylsp[(2) - (3)]).end, _("missing replacement value"));
2379 (yyval.stmt)->v.inst.key2 = (yyvsp[(3) - (3)].string);
2380 (yyval.stmt)->v.inst.arg = NULL;
2381 }
2382 break;
2383
2384 case 70:
2385
2386 /* Line 1810 of yacc.c */
2387 #line 630 "rc-gram.y"
2388 {
2389 if (!is_prog_allowed (&(yylsp[(1) - (2)]).beg))
2390 YYERROR;
2391
2392 def_regex_modifier = (yyvsp[(2) - (2)].num);
2393 (yyval.stmt) = NULL;
2394 }
2395 break;
2396
2397
2398
2399 /* Line 1810 of yacc.c */
2400 #line 2401 "rc-gram.c"
2401 default: break;
2402 }
2403 /* User semantic actions sometimes alter yychar, and that requires
2404 that yytoken be updated with the new translation. We take the
2405 approach of translating immediately before every use of yytoken.
2406 One alternative is translating here after every semantic action,
2407 but that translation would be missed if the semantic action invokes
2408 YYABORT, YYACCEPT, or YYERROR immediately after altering yychar or
2409 if it invokes YYBACKUP. In the case of YYABORT or YYACCEPT, an
2410 incorrect destructor might then be invoked immediately. In the
2411 case of YYERROR or YYBACKUP, subsequent parser actions might lead
2412 to an incorrect destructor call or verbose syntax error message
2413 before the lookahead is translated. */
2414 YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc);
2415
2416 YYPOPSTACK (yylen);
2417 yylen = 0;
2418 YY_STACK_PRINT (yyss, yyssp);
2419
2420 *++yyvsp = yyval;
2421 *++yylsp = yyloc;
2422
2423 /* Now `shift' the result of the reduction. Determine what state
2424 that goes to, based on the state we popped back to and the rule
2425 number reduced by. */
2426
2427 yyn = yyr1[yyn];
2428
2429 yystate = yypgoto[yyn - YYNTOKENS] + *yyssp;
2430 if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp)
2431 yystate = yytable[yystate];
2432 else
2433 yystate = yydefgoto[yyn - YYNTOKENS];
2434
2435 goto yynewstate;
2436
2437
2438 /*------------------------------------.
2439 | yyerrlab -- here on detecting error |
2440 `------------------------------------*/
2441 yyerrlab:
2442 /* Make sure we have latest lookahead translation. See comments at
2443 user semantic actions for why this is necessary. */
2444 yytoken = yychar == YYEMPTY ? YYEMPTY : YYTRANSLATE (yychar);
2445
2446 /* If not already recovering from an error, report this error. */
2447 if (!yyerrstatus)
2448 {
2449 ++yynerrs;
2450 #if ! YYERROR_VERBOSE
2451 yyerror (YY_("syntax error"));
2452 #else
2453 # define YYSYNTAX_ERROR yysyntax_error (&yymsg_alloc, &yymsg, \
2454 yyssp, yytoken)
2455 {
2456 char const *yymsgp = YY_("syntax error");
2457 int yysyntax_error_status;
2458 yysyntax_error_status = YYSYNTAX_ERROR;
2459 if (yysyntax_error_status == 0)
2460 yymsgp = yymsg;
2461 else if (yysyntax_error_status == 1)
2462 {
2463 if (yymsg != yymsgbuf)
2464 YYSTACK_FREE (yymsg);
2465 yymsg = (char *) YYSTACK_ALLOC (yymsg_alloc);
2466 if (!yymsg)
2467 {
2468 yymsg = yymsgbuf;
2469 yymsg_alloc = sizeof yymsgbuf;
2470 yysyntax_error_status = 2;
2471 }
2472 else
2473 {
2474 yysyntax_error_status = YYSYNTAX_ERROR;
2475 yymsgp = yymsg;
2476 }
2477 }
2478 yyerror (yymsgp);
2479 if (yysyntax_error_status == 2)
2480 goto yyexhaustedlab;
2481 }
2482 # undef YYSYNTAX_ERROR
2483 #endif
2484 }
2485
2486 yyerror_range[1] = yylloc;
2487
2488 if (yyerrstatus == 3)
2489 {
2490 /* If just tried and failed to reuse lookahead token after an
2491 error, discard it. */
2492
2493 if (yychar <= YYEOF)
2494 {
2495 /* Return failure if at end of input. */
2496 if (yychar == YYEOF)
2497 YYABORT;
2498 }
2499 else
2500 {
2501 yydestruct ("Error: discarding",
2502 yytoken, &yylval, &yylloc);
2503 yychar = YYEMPTY;
2504 }
2505 }
2506
2507 /* Else will try to reuse lookahead token after shifting the error
2508 token. */
2509 goto yyerrlab1;
2510
2511
2512 /*---------------------------------------------------.
2513 | yyerrorlab -- error raised explicitly by YYERROR. |
2514 `---------------------------------------------------*/
2515 yyerrorlab:
2516
2517 /* Pacify compilers like GCC when the user code never invokes
2518 YYERROR and the label yyerrorlab therefore never appears in user
2519 code. */
2520 if (/*CONSTCOND*/ 0)
2521 goto yyerrorlab;
2522
2523 yyerror_range[1] = yylsp[1-yylen];
2524 /* Do not reclaim the symbols of the rule which action triggered
2525 this YYERROR. */
2526 YYPOPSTACK (yylen);
2527 yylen = 0;
2528 YY_STACK_PRINT (yyss, yyssp);
2529 yystate = *yyssp;
2530 goto yyerrlab1;
2531
2532
2533 /*-------------------------------------------------------------.
2534 | yyerrlab1 -- common code for both syntax error and YYERROR. |
2535 `-------------------------------------------------------------*/
2536 yyerrlab1:
2537 yyerrstatus = 3; /* Each real token shifted decrements this. */
2538
2539 for (;;)
2540 {
2541 yyn = yypact[yystate];
2542 if (!yypact_value_is_default (yyn))
2543 {
2544 yyn += YYTERROR;
2545 if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
2546 {
2547 yyn = yytable[yyn];
2548 if (0 < yyn)
2549 break;
2550 }
2551 }
2552
2553 /* Pop the current state because it cannot handle the error token. */
2554 if (yyssp == yyss)
2555 YYABORT;
2556
2557 yyerror_range[1] = *yylsp;
2558 yydestruct ("Error: popping",
2559 yystos[yystate], yyvsp, yylsp);
2560 YYPOPSTACK (1);
2561 yystate = *yyssp;
2562 YY_STACK_PRINT (yyss, yyssp);
2563 }
2564
2565 *++yyvsp = yylval;
2566
2567 yyerror_range[2] = yylloc;
2568 /* Using YYLLOC is tempting, but would change the location of
2569 the lookahead. YYLOC is available though. */
2570 YYLLOC_DEFAULT (yyloc, yyerror_range, 2);
2571 *++yylsp = yyloc;
2572
2573 /* Shift the error token. */
2574 YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp);
2575
2576 yystate = yyn;
2577 goto yynewstate;
2578
2579
2580 /*-------------------------------------.
2581 | yyacceptlab -- YYACCEPT comes here. |
2582 `-------------------------------------*/
2583 yyacceptlab:
2584 yyresult = 0;
2585 goto yyreturn;
2586
2587 /*-----------------------------------.
2588 | yyabortlab -- YYABORT comes here. |
2589 `-----------------------------------*/
2590 yyabortlab:
2591 yyresult = 1;
2592 goto yyreturn;
2593
2594 #if !defined yyoverflow || YYERROR_VERBOSE
2595 /*-------------------------------------------------.
2596 | yyexhaustedlab -- memory exhaustion comes here. |
2597 `-------------------------------------------------*/
2598 yyexhaustedlab:
2599 yyerror (YY_("memory exhausted"));
2600 yyresult = 2;
2601 /* Fall through. */
2602 #endif
2603
2604 yyreturn:
2605 if (yychar != YYEMPTY)
2606 {
2607 /* Make sure we have latest lookahead translation. See comments at
2608 user semantic actions for why this is necessary. */
2609 yytoken = YYTRANSLATE (yychar);
2610 yydestruct ("Cleanup: discarding lookahead",
2611 yytoken, &yylval, &yylloc);
2612 }
2613 /* Do not reclaim the symbols of the rule which action triggered
2614 this YYABORT or YYACCEPT. */
2615 YYPOPSTACK (yylen);
2616 YY_STACK_PRINT (yyss, yyssp);
2617 while (yyssp != yyss)
2618 {
2619 yydestruct ("Cleanup: popping",
2620 yystos[*yyssp], yyvsp, yylsp);
2621 YYPOPSTACK (1);
2622 }
2623 #ifndef yyoverflow
2624 if (yyss != yyssa)
2625 YYSTACK_FREE (yyss);
2626 #endif
2627 #if YYERROR_VERBOSE
2628 if (yymsg != yymsgbuf)
2629 YYSTACK_FREE (yymsg);
2630 #endif
2631 /* Make sure YYID is used. */
2632 return YYID (yyresult);
2633 }
2634
2635
2636
2637 /* Line 2071 of yacc.c */
2638 #line 639 "rc-gram.y"
2639
2640
2641 static void
default_error_printer(void * data,struct rc_loc * loc,const char * pfx,const char * fmt,va_list ap)2642 default_error_printer (void *data,
2643 struct rc_loc *loc,
2644 const char *pfx,
2645 const char *fmt, va_list ap)
2646 {
2647 char buf[LINEBUFFER];
2648 vsnprintf (buf, sizeof buf, fmt, ap);
2649 if (topt & T_LOCATION_COLUMN)
2650 anubis_error (0, 0, "%s:%lu.%lu: %s%s%s",
2651 loc->file,
2652 (unsigned long)loc->line,
2653 (unsigned long)loc->column,
2654 pfx ? pfx : "",
2655 pfx ? ": " : "",
2656 buf);
2657 else
2658 anubis_error (0, 0, "%s:%lu: %s%s%s",
2659 loc->file, (unsigned long)loc->line,
2660 pfx ? pfx : "",
2661 pfx ? ": " : "",
2662 buf);
2663 }
2664
2665 static void *rc_error_printer_data;
2666 static RC_ERROR_PRINTER rc_error_printer = default_error_printer;
2667
2668 void
parse_error(struct rc_loc * loc,const char * fmt,...)2669 parse_error (struct rc_loc *loc, const char *fmt, ...)
2670 {
2671 va_list ap;
2672
2673 va_start (ap, fmt);
2674 rc_error_printer (rc_error_printer_data, loc ? loc : &rc_locus, NULL,
2675 fmt, ap);
2676 va_end (ap);
2677 error_count++;
2678 }
2679
2680 int
yyerror(const char * s)2681 yyerror (const char *s)
2682 {
2683 parse_error (NULL, "%s", s);
2684 return 0;
2685 }
2686
2687 RC_SECTION *
rc_parse(char * name)2688 rc_parse (char *name)
2689 {
2690 int status;
2691
2692 yydebug = yy_flex_debug = 0;
2693 if (debug_level > 1)
2694 {
2695 yydebug = 1;
2696 if (debug_level > 2)
2697 yy_flex_debug = 1;
2698 }
2699
2700 if (rc_open (name))
2701 return NULL;
2702
2703 rc_section = NULL;
2704 error_count = 0;
2705 status = yyparse ();
2706 if (status || error_count)
2707 rc_section_list_destroy (&rc_section);
2708 if (debug_level)
2709 rc_section_print (rc_section);
2710 return rc_section;
2711 }
2712
2713 /* Same as rc_parse() but also allows user to specify his own
2714 error printer function */
2715 RC_SECTION *
rc_parse_ep(char * name,RC_ERROR_PRINTER errprn,void * data)2716 rc_parse_ep (char *name, RC_ERROR_PRINTER errprn, void *data)
2717 {
2718 void *save_ep_data = rc_error_printer_data;
2719 void *save_ep_handler = rc_error_printer;
2720 RC_SECTION *sec;
2721 rc_error_printer = errprn;
2722 rc_error_printer_data = data;
2723 sec = rc_parse (name);
2724 rc_error_printer = save_ep_handler;
2725 rc_error_printer_data = save_ep_data;
2726 return sec;
2727 }
2728
2729 void
rc_set_debug_level(char * arg)2730 rc_set_debug_level (char *arg)
2731 {
2732 if (!arg)
2733 debug_level = 0;
2734 else if (arg[1] != 0 || !isdigit (arg[0]))
2735 {
2736 mprintf (_("Not a valid debugging level: %s"), arg);
2737 return;
2738 }
2739 else
2740 debug_level = arg[0] - '0';
2741 }
2742
2743
2744 /* Locations */
2745
2746 /* To save space, each filename is allocated only once. Each filename
2747 has a reference count associated with it. It is incremented
2748 with each new allocation of the same string. It is decremented
2749 with each attempt to free the string. Only when the reference count
2750 drops to zero is the storage actually reclaimed */
2751
2752 struct strobj {
2753 char *value; /* String value */
2754 size_t refcnt; /* Reference count */
2755 };
2756
2757 /* A list of string objects */
2758 static ANUBIS_LIST /* of struct strobj */ string_list;
2759
2760 static int
string_comparator(void * item,void * data)2761 string_comparator (void *item, void *data)
2762 {
2763 struct strobj *s = item;
2764 return strcmp (s->value, (char*) data);
2765 }
2766
2767 static int
value_comparator(void * item,void * data)2768 value_comparator (void *item, void *data)
2769 {
2770 struct strobj *s = item;
2771 return s->value != data;
2772 }
2773
2774 /* Looks up a string object with the given value. If not found, a
2775 new object is created and added to the list. In any case the
2776 reference count of the objet is incremented.
2777 The return value is the string value associated with the object. */
2778 char *
string_create(char * str)2779 string_create (char *str)
2780 {
2781 struct strobj *s = list_locate (string_list, str, string_comparator);
2782 if (!s)
2783 {
2784 s = xmalloc (sizeof (*s));
2785 s->value = strdup (str);
2786 s->refcnt = 0;
2787 list_prepend (string_list, s);
2788 }
2789 s->refcnt++;
2790 return s->value;
2791 }
2792
2793 /* Destroys the object with the given string value */
2794 void
string_destroy(char * str)2795 string_destroy (char *str)
2796 {
2797 struct strobj *s = list_locate (string_list, str, value_comparator);
2798 if (s)
2799 {
2800 if (--s->refcnt == 0)
2801 {
2802 free (s->value);
2803 list_remove (string_list, str, value_comparator);
2804 }
2805 }
2806 }
2807
2808 /* Initializes LOC with the current location. If the second argument
2809 is not zero, it overrides the current line number. */
2810 void
rc_mark_loc(RC_LOC * dst,RC_LOC * src)2811 rc_mark_loc (RC_LOC *dst, RC_LOC *src)
2812 {
2813 dst->file = string_create (src->file);
2814 dst->line = src->line;
2815 dst->column = src->column;
2816 }
2817
2818 /* Reclaims the memory associated with the LOC */
2819 void
rc_destroy_loc(RC_LOC * loc)2820 rc_destroy_loc (RC_LOC *loc)
2821 {
2822 string_destroy (loc->file);
2823 }
2824
2825
2826 /* Section manipulation */
2827
2828 RC_SECTION *
rc_section_create(char * name,struct rc_loc * loc,RC_STMT * stmt)2829 rc_section_create (char *name, struct rc_loc *loc, RC_STMT *stmt)
2830 {
2831 RC_SECTION *p = xmalloc (sizeof (*p));
2832 rc_mark_loc (&p->loc, loc);
2833 p->next = NULL;
2834 p->name = name;
2835 p->stmt = stmt;
2836 return p;
2837 }
2838
2839 void
rc_section_destroy(RC_SECTION ** s)2840 rc_section_destroy (RC_SECTION **s)
2841 {
2842 rc_stmt_list_destroy ((*s)->stmt);
2843 rc_destroy_loc (&(*s)->loc);
2844 xfree ((*s)->name);
2845 xfree (*s);
2846 }
2847
2848 void
rc_section_list_destroy(RC_SECTION ** s)2849 rc_section_list_destroy (RC_SECTION **s)
2850 {
2851 while (*s)
2852 {
2853 RC_SECTION *next = (*s)->next;
2854 rc_section_destroy (s);
2855 *s = next;
2856 }
2857 }
2858
2859 void
rc_section_print(RC_SECTION * sect)2860 rc_section_print (RC_SECTION *sect)
2861 {
2862 for (; sect; sect = sect->next)
2863 {
2864 printf ("BEGIN SECTION %s\n", sect->name);
2865 rc_stmt_print (sect->stmt, 1);
2866 printf ("END SECTION %s\n", sect->name);
2867 }
2868 }
2869
2870 RC_SECTION *
rc_section_lookup(RC_SECTION * sec,char * name)2871 rc_section_lookup (RC_SECTION *sec, char *name)
2872 {
2873 for (; sec; sec = sec->next)
2874 if (strcmp (sec->name, name) == 0)
2875 break;
2876 return sec;
2877 }
2878
2879 void
rc_section_link(RC_SECTION ** ap,RC_SECTION * b)2880 rc_section_link (RC_SECTION **ap, RC_SECTION *b)
2881 {
2882 RC_SECTION *a, *prev;
2883
2884 /* Remove all sections with prio == override (the default) */
2885 a = *ap;
2886 prev = NULL;
2887 while (a)
2888 {
2889 RC_SECTION *next = a->next;
2890 struct rc_secdef *sd = anubis_find_section (a->name);
2891 if (sd && sd->prio == prio_user_only)
2892 {
2893 if (prev)
2894 prev->next = next;
2895 else
2896 *ap = next;
2897 rc_section_destroy (&a);
2898 } else
2899 prev = a;
2900 a = next;
2901 }
2902
2903 if (!*ap)
2904 {
2905 *ap = b;
2906 return;
2907 }
2908
2909 for (a = *ap; a->next; a = a->next)
2910 ;
2911
2912 while (b)
2913 {
2914 struct rc_secdef *sd;
2915 RC_SECTION *nxtptr = b->next;
2916
2917 sd = anubis_find_section (b->name);
2918 if (sd)
2919 {
2920 switch (sd->prio)
2921 {
2922 case prio_user:
2923 b->next = *ap;
2924 *ap = b;
2925 break;
2926
2927 case prio_system_only:
2928 rc_section_destroy (&b);
2929 break;
2930
2931 default:
2932 b->next = NULL;
2933 a->next = b;
2934 a = b;
2935 }
2936 }
2937 else
2938 {
2939 b->next = NULL;
2940 a->next = b;
2941 a = b;
2942 }
2943 b = nxtptr;
2944 }
2945 }
2946
2947 /* Assignment manipulations */
2948
2949 void
rc_asgn_destroy(RC_ASGN * asgn)2950 rc_asgn_destroy (RC_ASGN *asgn)
2951 {
2952 xfree (asgn->lhs);
2953 list_destroy (&asgn->rhs, anubis_free_list_item, NULL);
2954 }
2955
2956 /* Bools */
2957
2958 void
rc_bool_destroy(RC_BOOL * bool)2959 rc_bool_destroy (RC_BOOL *bool)
2960 {
2961 rc_node_destroy (bool->left);
2962 rc_node_destroy (bool->right);
2963 }
2964
2965 /* Nodes */
2966
2967 /* FIXME: 2nd should better be struct rc_yyltype */
2968 RC_NODE *
rc_node_create(enum rc_node_type t,struct rc_loc * loc)2969 rc_node_create (enum rc_node_type t, struct rc_loc *loc)
2970 {
2971 RC_NODE *p = xmalloc (sizeof (*p));
2972 memset (p, 0, sizeof (*p));
2973 rc_mark_loc (&p->loc, loc);
2974 p->type = t;
2975 return p;
2976 }
2977
2978 void
rc_node_destroy(RC_NODE * node)2979 rc_node_destroy (RC_NODE *node)
2980 {
2981 if (!node)
2982 return;
2983 switch (node->type)
2984 {
2985 case rc_node_bool:
2986 rc_bool_destroy (&node->v.bool);
2987 break;
2988
2989 case rc_node_expr:
2990 free (node->v.expr.key);
2991 anubis_regex_free (&node->v.expr.re);
2992 }
2993 rc_destroy_loc (&node->loc);
2994 xfree (node);
2995 }
2996
2997 static char *
part_string(int part)2998 part_string (int part)
2999 {
3000 switch (part)
3001 {
3002 case NIL:
3003 return "NIL";
3004 case COMMAND:
3005 return "COMMAND";
3006 case HEADER:
3007 return "HEADER";
3008 case BODY:
3009 return "BODY";
3010 default:
3011 return "UNKNOWN";
3012 }
3013 }
3014
3015 void
rc_node_print(RC_NODE * node)3016 rc_node_print (RC_NODE *node)
3017 {
3018 switch (node->type)
3019 {
3020 case rc_node_expr:
3021 printf ("%s", part_string (node->v.expr.part));
3022 if (node->v.expr.key && node->v.expr.key[0] != '\n')
3023 printf ("[%s]",node->v.expr.key);
3024 if (node->v.expr.sep)
3025 printf ("(%s)", node->v.expr.sep);
3026 printf (" ");
3027 anubis_regex_print (node->v.expr.re);
3028 break;
3029
3030 case rc_node_bool:
3031 switch (node->v.bool.op)
3032 {
3033 case bool_not:
3034 printf ("NOT (");
3035 rc_node_print (node->v.bool.left);
3036 printf (")");
3037 break;
3038
3039 case bool_and:
3040 printf ("AND (");
3041 rc_node_print (node->v.bool.left);
3042 printf (",");
3043 rc_node_print (node->v.bool.right);
3044 printf (")");
3045 break;
3046
3047 case bool_or:
3048 printf ("OR (");
3049 rc_node_print (node->v.bool.left);
3050 printf (",");
3051 rc_node_print (node->v.bool.right);
3052 printf (")");
3053 break;
3054 }
3055 }
3056 }
3057
3058 /* Rules */
3059
3060 void
rc_rule_destroy(RC_RULE * rule)3061 rc_rule_destroy (RC_RULE *rule)
3062 {
3063 rc_node_destroy (rule->node);
3064 rc_stmt_list_destroy (rule->stmt);
3065 }
3066
3067 /* Conditionals */
3068
3069 void
rc_cond_destroy(RC_COND * cond)3070 rc_cond_destroy (RC_COND *cond)
3071 {
3072 rc_node_destroy (cond->node);
3073 rc_stmt_list_destroy (cond->iftrue);
3074 rc_stmt_list_destroy (cond->iffalse);
3075 }
3076
3077 /* Instructions */
3078
3079 void
rc_inst_destroy(RC_INST * inst)3080 rc_inst_destroy (RC_INST *inst)
3081 {
3082 anubis_regex_free (&inst->key);
3083 free (inst->key2);
3084 free (inst->arg);
3085 }
3086
3087 static char *
inst_name(enum rc_inst_opcode opcode)3088 inst_name (enum rc_inst_opcode opcode)
3089 {
3090 switch (opcode)
3091 {
3092 case inst_stop:
3093 return "STOP";
3094 case inst_call:
3095 return "CALL";
3096 case inst_add:
3097 return "ADD";
3098 case inst_remove:
3099 return "REMOVE";
3100 case inst_modify:
3101 return "MODIFY";
3102 }
3103 return "UNKNOWN";
3104 }
3105
3106 void
rc_inst_print(RC_INST * inst,int level)3107 rc_inst_print (RC_INST *inst, int level)
3108 {
3109 rc_level_print (level, inst_name (inst->opcode));
3110 switch (inst->opcode)
3111 {
3112 case inst_stop:
3113 break;
3114
3115 case inst_call:
3116 printf (" %s", inst->arg);
3117 break;
3118
3119 case inst_add:
3120 printf (" %s[%s]", part_string (inst->part), inst->key2);
3121 if (inst->arg)
3122 printf (" \"%s\"", inst->arg);
3123 break;
3124
3125 default:
3126 printf (" %s ", part_string (inst->part));
3127 if (inst->key)
3128 anubis_regex_print (inst->key);
3129 if (inst->key2)
3130 printf (" [%s]", inst->key2);
3131 if (inst->arg)
3132 printf (" \"%s\"", inst->arg);
3133 }
3134 }
3135
3136 /* Statements */
3137 /* FIXME: See rc_node_create */
3138 RC_STMT *
rc_stmt_create(enum rc_stmt_type type,struct rc_loc * loc)3139 rc_stmt_create (enum rc_stmt_type type, struct rc_loc *loc)
3140 {
3141 RC_STMT *p = xmalloc (sizeof (*p));
3142 memset (p, 0, sizeof (*p));
3143 rc_mark_loc (&p->loc, loc);
3144 p->type = type;
3145 return p;
3146 }
3147
3148 void
rc_stmt_destroy(RC_STMT * stmt)3149 rc_stmt_destroy (RC_STMT *stmt)
3150 {
3151 switch (stmt->type)
3152 {
3153 case rc_stmt_asgn:
3154 rc_asgn_destroy (&stmt->v.asgn);
3155 break;
3156
3157 case rc_stmt_rule:
3158 rc_rule_destroy (&stmt->v.rule);
3159 break;
3160
3161 case rc_stmt_cond:
3162 rc_cond_destroy (&stmt->v.cond);
3163 break;
3164
3165 case rc_stmt_inst:
3166 rc_inst_destroy (&stmt->v.inst);
3167 }
3168 rc_destroy_loc (&stmt->loc);
3169 xfree (stmt);
3170 }
3171
3172 void
rc_stmt_list_destroy(RC_STMT * stmt)3173 rc_stmt_list_destroy (RC_STMT *stmt)
3174 {
3175 while (stmt)
3176 {
3177 RC_STMT *next = stmt->next;
3178 rc_stmt_destroy (stmt);
3179 stmt = next;
3180 }
3181 }
3182
3183 void
rc_level_print(int level,char * str)3184 rc_level_print (int level, char *str)
3185 {
3186 int i;
3187
3188 for (i = 0; i < level*2; i++)
3189 putchar (' ');
3190 printf ("%s", str);
3191 }
3192
3193 static int
_print_str(void * item,void * data)3194 _print_str (void *item, void *data)
3195 {
3196 printf (" %s", (char*)item);
3197 return 0;
3198 }
3199
3200 static int
_print_stars(void * item,void * data)3201 _print_stars (void *item, void *data)
3202 {
3203 printf (" ***");
3204 return 0;
3205 }
3206
3207 void
rc_stmt_print(RC_STMT * stmt,int level)3208 rc_stmt_print (RC_STMT *stmt, int level)
3209 {
3210 for (; stmt; stmt = stmt->next)
3211 {
3212 switch (stmt->type)
3213 {
3214 case rc_stmt_asgn:
3215 rc_level_print (level, "ASGN: ");
3216 printf ("%s =", stmt->v.asgn.lhs);
3217 list_iterate (stmt->v.asgn.rhs,
3218 (stmt->v.asgn.flags & KWF_HIDDEN) ?
3219 _print_stars : _print_str, NULL);
3220 break;
3221
3222 case rc_stmt_cond:
3223 rc_level_print (level, "COND: ");
3224 rc_node_print (stmt->v.cond.node);
3225 printf ("\n");
3226 rc_level_print (level, "IFTRUE:\n");
3227 rc_stmt_print (stmt->v.cond.iftrue, level+1);
3228 if (stmt->v.cond.iffalse)
3229 {
3230 rc_level_print (level, "IFFALSE:\n");
3231 rc_stmt_print (stmt->v.cond.iffalse, level+1);
3232 }
3233 rc_level_print (level, "END COND");
3234 break;
3235
3236 case rc_stmt_rule:
3237 rc_level_print (level, "RULE: ");
3238 rc_node_print (stmt->v.rule.node);
3239 printf ("\n");
3240 rc_level_print (level, "BODY\n");
3241 rc_stmt_print (stmt->v.rule.stmt, level+1);
3242 rc_level_print (level, "END RULE");
3243 break;
3244
3245 case rc_stmt_inst:
3246 rc_inst_print (&stmt->v.inst, level);
3247 break;
3248
3249 default:
3250 abort ();
3251 }
3252 printf ("\n");
3253 }
3254 }
3255
3256 int
reg_modifier_add(int * flag,char * opt,struct rc_loc * loc)3257 reg_modifier_add (int *flag, char *opt, struct rc_loc *loc)
3258 {
3259 /* Regex types: */
3260 if (!strcasecmp (opt, "re") || !strcasecmp (opt, "regex"))
3261 {
3262 re_set_type (*flag, re_typeof (def_regex_modifier));
3263 }
3264 else if (!strcasecmp (opt, "posix"))
3265 {
3266 re_set_type (*flag, R_POSIX);
3267 }
3268 #ifdef HAVE_PCRE
3269 else if (!strcasecmp (opt, "perlre")
3270 || !strcasecmp (opt, "perl"))
3271 {
3272 re_set_type (*flag, R_PERLRE);
3273 }
3274 #endif /* HAVE_PCRE */
3275 else if (!strcasecmp (opt, "ex") || !strcasecmp (opt, "exact"))
3276 {
3277 re_set_type (*flag, R_EXACT);
3278 }
3279
3280 /* Modifiers: */
3281 else if (!strcasecmp (opt, "basic"))
3282 {
3283 re_set_type (*flag, R_POSIX);
3284 re_set_flag (*flag, R_BASIC);
3285 }
3286 else if (!strcasecmp (opt, "extended"))
3287 {
3288 re_set_type (*flag, R_POSIX);
3289 re_clear_flag (*flag, R_BASIC);
3290 }
3291 else if (!strcasecmp (opt, "scase"))
3292 re_set_flag (*flag, R_SCASE);
3293 else if (!strcasecmp (opt, "icase"))
3294 re_clear_flag (*flag, R_SCASE);
3295 else
3296 {
3297 parse_error (loc, _("Unknown regexp modifier"));
3298 return 1;
3299 }
3300 return 0;
3301 }
3302
3303
3304 /* ******************************* Runtime ********************************* */
3305
3306 static struct rc_secdef_child *
child_copy(struct rc_secdef_child * p)3307 child_copy (struct rc_secdef_child *p)
3308 {
3309 struct rc_secdef_child *newp = xmalloc (sizeof (*newp));
3310 memcpy (newp, p, sizeof (*newp));
3311 newp->next = NULL;
3312 return newp;
3313 }
3314
3315 void
rc_secdef_add_child(struct rc_secdef * def,struct rc_secdef_child * child)3316 rc_secdef_add_child (struct rc_secdef *def,
3317 struct rc_secdef_child *child)
3318 {
3319 struct rc_secdef_child *p = child_copy (child);
3320 if (!def->child)
3321 def->child = p;
3322 else
3323 {
3324 struct rc_secdef_child *last;
3325 for (last = def->child; last->next; last = last->next)
3326 ;
3327 last->next = p;
3328 }
3329 }
3330
3331 struct rc_secdef_child *
rc_child_lookup(struct rc_secdef_child * child,char * str,int method,int * key,int * flags)3332 rc_child_lookup (struct rc_secdef_child *child, char *str,
3333 int method, int *key, int *flags)
3334 {
3335 for (; child; child = child->next)
3336 {
3337 if (child->method & method)
3338 {
3339 struct rc_kwdef *kw;
3340 for (kw = child->kwdef; kw->name; kw++)
3341 if (!strcmp (kw->name, str))
3342 {
3343 *key = kw->tok;
3344 if (flags)
3345 *flags = kw->flags;
3346 return child;
3347 }
3348 }
3349 }
3350 return NULL;
3351 }
3352
3353
3354 struct disabled_keyword
3355 {
3356 int method_mask;
3357 char *keyword;
3358 };
3359
3360
3361 static ANUBIS_LIST disabled_keyword_list;
3362
3363 void
rc_disable_keyword(int mask,const char * kw)3364 rc_disable_keyword (int mask, const char *kw)
3365 {
3366 ITERATOR itr;
3367 struct disabled_keyword *p;
3368
3369 if (!disabled_keyword_list)
3370 disabled_keyword_list = list_create ();
3371
3372 itr = iterator_create (disabled_keyword_list);
3373 for (p = iterator_first (itr); p; p = iterator_next (itr))
3374 {
3375 if (strcmp (p->keyword, kw) == 0)
3376 {
3377 p->method_mask |= mask;
3378 break;
3379 }
3380 }
3381 iterator_destroy (&itr);
3382
3383 if (!p)
3384 {
3385 p = xmalloc (sizeof (*p));
3386 p->method_mask = mask;
3387 p->keyword = xstrdup (kw);
3388 list_append (disabled_keyword_list, p);
3389 }
3390 }
3391
3392 int
rc_keyword_is_disabled(int mask,const char * kw)3393 rc_keyword_is_disabled (int mask, const char *kw)
3394 {
3395 int rc = 0;
3396 if (disabled_keyword_list)
3397 {
3398 ITERATOR itr = iterator_create (disabled_keyword_list);
3399 struct disabled_keyword *p;
3400
3401 for (p = iterator_first (itr); p; p = iterator_next (itr))
3402 {
3403 if ((rc = (p->method_mask & mask) && strcmp (p->keyword, kw) == 0))
3404 break;
3405 }
3406 iterator_destroy (&itr);
3407 }
3408 return rc;
3409 }
3410
3411
3412 struct eval_env
3413 {
3414 int method;
3415 int cmp_method;
3416 struct rc_secdef_child *child;
3417 MESSAGE msg;
3418 void *data;
3419 int refcnt;
3420 char **refstr;
3421 jmp_buf jmp;
3422 RC_LOC loc;
3423 int traceable;
3424 };
3425
3426 struct rc_loc const *
eval_env_locus(struct eval_env * env)3427 eval_env_locus (struct eval_env *env)
3428 {
3429 return &env->loc;
3430 }
3431
3432 int
eval_env_method(struct eval_env * env)3433 eval_env_method (struct eval_env *env)
3434 {
3435 return env->method;
3436 }
3437
3438 MESSAGE
eval_env_message(struct eval_env * env)3439 eval_env_message (struct eval_env *env)
3440 {
3441 return env->msg;
3442 }
3443
3444 void *
eval_env_data(struct eval_env * env)3445 eval_env_data (struct eval_env *env)
3446 {
3447 return env->data;
3448 }
3449
3450 void
eval_error(int retcode,struct eval_env * env,const char * fmt,...)3451 eval_error (int retcode, struct eval_env *env, const char *fmt, ...)
3452 {
3453 va_list ap;
3454 va_start(ap, fmt);
3455 rc_error_printer (rc_error_printer_data, &env->loc, NULL, fmt, ap);
3456 va_end(ap);
3457 if (retcode)
3458 longjmp(env->jmp, retcode);
3459 }
3460
3461 void
eval_warning(struct eval_env * env,const char * fmt,...)3462 eval_warning (struct eval_env *env, const char *fmt, ...)
3463 {
3464 va_list ap;
3465
3466 va_start(ap, fmt);
3467 rc_error_printer (rc_error_printer_data, &env->loc, _("warning"),
3468 fmt, ap);
3469 va_end(ap);
3470 }
3471
3472 static void asgn_eval (struct eval_env *env, RC_ASGN *asgn);
3473 static int node_eval (struct eval_env *env, RC_NODE *node);
3474 static int bool_eval (struct eval_env *env, RC_BOOL *bool);
3475 static void cond_eval (struct eval_env *env, RC_COND *cond);
3476 static void rule_eval (struct eval_env *env, RC_RULE *rule);
3477 static void stmt_list_eval (struct eval_env *env, RC_STMT *stmt);
3478 static void inst_eval (struct eval_env *env, RC_INST *inst);
3479
3480 #define VALID_STR(s) ((s)?(s):"NULL")
3481
3482 void
inst_eval(struct eval_env * env,RC_INST * inst)3483 inst_eval (struct eval_env *env, RC_INST *inst)
3484 {
3485 char *arg = NULL, *argp = NULL;
3486
3487 if (!env->msg)
3488 return; /* FIXME: bail out? */
3489
3490 if (inst->arg)
3491 {
3492 if (env->refstr)
3493 arg = argp = substitute (inst->arg, env->refstr);
3494 else
3495 arg = inst->arg;
3496 }
3497
3498 switch (inst->opcode)
3499 {
3500 case inst_stop:
3501 tracefile (&env->loc, _("STOP"));
3502 longjmp (env->jmp, 1);
3503 break;
3504
3505 case inst_call:
3506 tracefile (&env->loc, _("Calling %s"), inst->arg);
3507 rcfile_call_section (env->method, inst->arg, "RULE",
3508 env->data, env->msg);
3509 break;
3510
3511 case inst_add:
3512 tracefile (&env->loc, _("ADD %s [%s] %s"),
3513 part_string (inst->part),
3514 VALID_STR (inst->key2), arg);
3515 if (inst->part == BODY)
3516 message_add_body (env->msg, inst->key2, arg);
3517 else if (inst->part == HEADER)
3518 message_add_header (env->msg, inst->key2, arg);
3519 break;
3520
3521 case inst_modify:
3522 tracefile (&env->loc, _("MODIFY %s [%s] [%s] %s"),
3523 part_string (inst->part),
3524 anubis_regex_source (inst->key),
3525 VALID_STR (inst->key2), arg);
3526
3527 switch (inst->part)
3528 {
3529 case BODY:
3530 message_modify_body (env->msg, inst->key, arg);
3531 break;
3532
3533 case HEADER:
3534 message_modify_headers (env->msg, inst->key, inst->key2, arg);
3535 break;
3536
3537 case COMMAND:
3538 message_modify_command (env->msg, inst->key, inst->key2, arg);
3539 break;
3540 }
3541 break;
3542
3543 case inst_remove:
3544 tracefile (&env->loc, _("REMOVE HEADER [%s]"),
3545 anubis_regex_source (inst->key));
3546 message_remove_headers (env->msg, inst->key);
3547 break;
3548
3549 default:
3550 abort ();
3551 }
3552
3553 if (argp)
3554 free (argp);
3555 }
3556
3557 void
asgn_eval(struct eval_env * env,RC_ASGN * asgn)3558 asgn_eval (struct eval_env *env, RC_ASGN *asgn)
3559 {
3560 int key;
3561 struct rc_secdef_child *p = rc_child_lookup (env->child, asgn->lhs,
3562 env->method, &key, NULL);
3563 if (!p)
3564 return;
3565
3566 if (rc_keyword_is_disabled (env->method, asgn->lhs))
3567 {
3568 eval_warning (env,
3569 _("ignoring statement overridden from the command line"));
3570 return;
3571 }
3572
3573 if (env->traceable)
3574 tracefile (&env->loc, _("Executing %s"), asgn->lhs);
3575
3576 if (env->refstr)
3577 {
3578 char *s;
3579 ANUBIS_LIST arg = list_create ();
3580 ITERATOR itr = iterator_create (asgn->rhs);
3581 for (s = iterator_first (itr); s; s = iterator_next (itr))
3582 {
3583 char *str = substitute (s, env->refstr);
3584 list_append (arg, str);
3585 }
3586 iterator_destroy (&itr);
3587 p->parser (env, key, arg, p->data);
3588 list_destroy (&arg, anubis_free_list_item, NULL);
3589 }
3590 else
3591 p->parser (env, key, asgn->rhs, p->data);
3592 }
3593
3594
3595 int
re_eval_list(struct eval_env * env,char * key,char * sep,RC_REGEX * re,ANUBIS_LIST list)3596 re_eval_list (struct eval_env *env, char *key, char *sep,
3597 RC_REGEX *re, ANUBIS_LIST list)
3598 {
3599 ASSOC *p;
3600 ITERATOR itr;
3601 int rc = 0;
3602
3603 itr = iterator_create (list);
3604 if (sep)
3605 {
3606 char *tmpbuf = NULL;
3607 size_t tmpsize = 0;
3608 size_t seplen = strlen (sep);
3609 char *first_val = NULL;
3610
3611 for (p = iterator_first (itr); p; p = iterator_next (itr))
3612 {
3613 if (!p->key || !strcasecmp (p->key, key))
3614 {
3615 if (tmpsize == 0)
3616 {
3617 if (!first_val)
3618 {
3619 first_val = p->value; /* Initialize copy on write */
3620 continue;
3621 }
3622 else
3623 {
3624 tmpbuf = xstrdup (first_val);
3625 tmpsize = strlen (tmpbuf);
3626 first_val = NULL;
3627 }
3628 }
3629 tmpsize += seplen + strlen (p->value);
3630 tmpbuf = xrealloc (tmpbuf, tmpsize + 1);
3631 strcat (tmpbuf, sep);
3632 strcat (tmpbuf, p->value);
3633 }
3634 }
3635 rc = anubis_regex_match (re, first_val ? first_val : tmpbuf,
3636 &env->refcnt, &env->refstr);
3637 free (tmpbuf);
3638 }
3639 else
3640 {
3641 for (p = iterator_first (itr); rc == 0 && p; p = iterator_next (itr))
3642 {
3643 if (!p->key || !strcasecmp (p->key, key))
3644 rc = anubis_regex_match (re, p->value,
3645 &env->refcnt, &env->refstr);
3646 }
3647 }
3648 iterator_destroy (&itr);
3649 return rc;
3650 }
3651
3652 int
re_eval_text(struct eval_env * env,RC_REGEX * re,const char * text)3653 re_eval_text (struct eval_env *env, RC_REGEX *re, const char *text)
3654 {
3655 /* FIXME */
3656 return anubis_regex_match (re, text, &env->refcnt, &env->refstr);
3657 }
3658
3659 int
expr_eval(struct eval_env * env,RC_EXPR * expr)3660 expr_eval (struct eval_env *env, RC_EXPR *expr)
3661 {
3662 int rc;
3663
3664 if (env->refstr && anubis_regex_refcnt (expr->re))
3665 {
3666 argcv_free (-1, env->refstr);
3667 env->refcnt = 0;
3668 env->refstr = NULL;
3669 }
3670
3671 switch (expr->part)
3672 {
3673 case COMMAND:
3674 rc = re_eval_list (env, expr->key, expr->sep, expr->re,
3675 message_get_commands (env->msg));
3676 break;
3677
3678 case HEADER:
3679 rc = re_eval_list (env, expr->key, expr->sep, expr->re,
3680 message_get_header (env->msg));
3681 break;
3682
3683 case BODY:
3684 rc = re_eval_text (env, expr->re, message_get_body (env->msg));
3685 break;
3686
3687 default:
3688 abort ();
3689 }
3690
3691 if (rc)
3692 {
3693 if (!strcmp (VALID_STR (expr->key), X_ANUBIS_RULE_HEADER))
3694 tracefile (&env->loc, _("Matched trigger \"%s\""),
3695 anubis_regex_source (expr->re));
3696 else
3697 tracefile (&env->loc,
3698 _("Matched condition %s[%s] \"%s\""),
3699 part_string (expr->part),
3700 VALID_STR (expr->key),
3701 anubis_regex_source (expr->re));
3702 }
3703 return rc;
3704 }
3705
3706 int
node_eval(struct eval_env * env,RC_NODE * node)3707 node_eval (struct eval_env *env, RC_NODE *node)
3708 {
3709 int rc; /* It won't be used uninitialized despite what cc says.
3710 Note default: branch below */
3711
3712 env->loc = node->loc;
3713 switch (node->type)
3714 {
3715 case rc_node_bool:
3716 rc = bool_eval (env, &node->v.bool);
3717 break;
3718
3719 case rc_node_expr:
3720 rc = expr_eval (env, &node->v.expr);
3721 break;
3722
3723 default:
3724 abort ();
3725 }
3726
3727 return rc;
3728 }
3729
3730 int
bool_eval(struct eval_env * env,RC_BOOL * bool)3731 bool_eval (struct eval_env *env, RC_BOOL *bool)
3732 {
3733 int rc = node_eval (env, bool->left);
3734
3735 switch (bool->op)
3736 {
3737 case bool_not:
3738 return !rc;
3739
3740 case bool_and:
3741 if (!rc)
3742 return 0;
3743 break;
3744
3745 case bool_or:
3746 if (rc)
3747 return 1;
3748 break;
3749 }
3750 return node_eval (env, bool->right);
3751 }
3752
3753 void
cond_eval(struct eval_env * env,RC_COND * cond)3754 cond_eval (struct eval_env *env, RC_COND *cond)
3755 {
3756 if (node_eval (env, cond->node))
3757 stmt_list_eval (env, cond->iftrue);
3758 else
3759 stmt_list_eval (env, cond->iffalse);
3760 }
3761
3762 void
rule_eval(struct eval_env * env,RC_RULE * rule)3763 rule_eval (struct eval_env *env, RC_RULE *rule)
3764 {
3765 if (node_eval (env, rule->node))
3766 stmt_list_eval (env, rule->stmt);
3767 }
3768
3769 void
stmt_list_eval(struct eval_env * env,RC_STMT * stmt)3770 stmt_list_eval (struct eval_env *env, RC_STMT *stmt)
3771 {
3772 for (; stmt; stmt = stmt->next)
3773 {
3774 env->loc = stmt->loc;
3775
3776 switch (stmt->type)
3777 {
3778 case rc_stmt_asgn:
3779 asgn_eval (env, &stmt->v.asgn);
3780 break;
3781
3782 case rc_stmt_cond:
3783 cond_eval (env, &stmt->v.cond);
3784 break;
3785
3786 case rc_stmt_rule:
3787 rule_eval (env, &stmt->v.rule);
3788 break;
3789
3790 case rc_stmt_inst:
3791 inst_eval (env, &stmt->v.inst);
3792 }
3793 }
3794 }
3795
3796 void
eval_section(int method,RC_SECTION * sec,struct rc_secdef * secdef,void * data,MESSAGE msg)3797 eval_section (int method, RC_SECTION *sec, struct rc_secdef *secdef,
3798 void *data, MESSAGE msg)
3799 {
3800 struct eval_env env;
3801 env.method = method;
3802 env.child = secdef->child;
3803 env.refcnt = 0;
3804 env.refstr = NULL;
3805 env.msg = msg;
3806 env.data = data;
3807 env.loc = sec->loc;
3808 env.traceable = secdef->allow_prog;
3809
3810 if (env.traceable)
3811 tracefile (&sec->loc, _("Section %s"), sec->name);
3812
3813 if (setjmp (env.jmp) == 0)
3814 stmt_list_eval (&env, sec->stmt);
3815
3816 if (env.refstr)
3817 argcv_free (-1, env.refstr);
3818 }
3819
3820 void
rc_run_section(int method,RC_SECTION * sec,struct rc_secdef * secdef,const char * class_name,void * data,MESSAGE msg)3821 rc_run_section (int method, RC_SECTION *sec, struct rc_secdef *secdef,
3822 const char *class_name,
3823 void *data, MESSAGE msg)
3824 {
3825 if (!sec)
3826 return;
3827 if (!class_name)
3828 class_name = sec->name;
3829
3830 for (; secdef->name; secdef++)
3831 {
3832 if (!strcmp (secdef->name, class_name))
3833 {
3834 eval_section (method, sec, secdef, data, msg);
3835 return;
3836 }
3837 }
3838 anubis_error (0, 0, _("Unknown section: %s"), sec->name);
3839 }
3840
3841
3842 static int
check_kw(char * ident,int * flags)3843 check_kw (char *ident, int *flags)
3844 {
3845 struct rc_secdef *p = rc_secdef;
3846 int key;
3847
3848 if (!p)
3849 p = anubis_find_section ("RULE");
3850 return rc_child_lookup (p->child, ident, CF_ALL, &key, flags) != NULL;
3851 }
3852
3853 static int
is_prog_allowed(struct rc_loc * loc)3854 is_prog_allowed (struct rc_loc *loc)
3855 {
3856 struct rc_secdef *p = rc_secdef;
3857 if (!p)
3858 p = anubis_find_section ("RULE");
3859
3860 if (!p->allow_prog)
3861 parse_error (loc, _("program is not allowed in this section"));
3862 return p->allow_prog;
3863 }
3864
3865