2 * This file is part of secnet.
3 * See LICENCE and this file CREDITS for full list of copyright holders.
4 * SPDX-License-Identifier: GPL-3.0-or-later
5 * There is NO WARRANTY.
18 /* Bison stupidly redeclares malloc/free unless they are #defined
19 * (or a bunch of madder conditions) */
21 # define malloc malloc
25 #include "conffile_internal.h"
26 #include "conffile.yy.h"
28 #define YYERROR_VERBOSE
30 static struct p_node *node(uint32_t type, struct p_node *l, struct p_node *r);
32 static struct p_node *result;
34 static void yyerror(const char *s);
40 input: assignments { result = $1; $$=result; }
43 assignments: assignments assignment { $$=node(T_ALIST, $2, $1); }
44 | assignment { $$=node(T_ALIST, $1, NULL); }
47 searchpath: /* empty */ { $$ = NULL; }
48 | '<' list '>' { $$ = $2; }
51 dict: searchpath '{' assignments '}'
52 { $$ = node(T_DICT, $3, $1); }
53 | searchpath '{' '}' { $$ = node(T_DICT, NULL, $1); }
56 path: '/' pathelements { $$ = node(T_ABSPATH, NULL, $2); }
57 | pathelements { $$ = node(T_RELPATH, NULL, $1); }
60 pathelements: pathelements '/' TOK_KEY { $$ = node(T_PATHELEM, $3, $1); }
61 | TOK_KEY { $$ = node(T_PATHELEM, $1, NULL); }
64 exec: item '(' list ')' { $$ = node(T_EXEC, $1, $3); }
65 | item '(' ')' { $$ = node(T_EXEC, $1, NULL); }
67 { $$ = node(T_EXEC, $1, node(T_LISTITEM, $2, NULL)); }
70 list: list ',' item { $$ = node(T_LISTITEM, $3, $1); }
71 | item { $$ = node(T_LISTITEM, $1, NULL); }
74 assignment: TOK_KEY '=' list ';' { $$ = node(T_ASSIGNMENT, $1, $3); }
75 | TOK_KEY list ';' { $$ = node(T_ASSIGNMENT, $1, $2); }
76 | error ';' { $$ = node(T_ERROR, NULL, NULL); }
77 | error '}' { $$ = node(T_ERROR, NULL, NULL); }
78 | error ')' { $$ = node(T_ERROR, NULL, NULL); }
90 static void yyerror(const char *s)
92 Message(M_FATAL,"config file %s line %d: %s\n",config_file,
96 struct p_node *parse_conffile(FILE *conffile)
100 fatal("Configuration file parsing failed\n");
103 fatal("%d error%s encountered in configuration file\n",
104 yynerrs,yynerrs==1?"":"s");
109 static struct p_node *node(uint32_t type, struct p_node *l, struct p_node *r)
115 rv->loc.file=config_file;
116 rv->loc.line=config_lineno;