11 /* Bison stupidly redeclares malloc/free unless they are #defined
12 * (or a bunch of madder conditions) */
14 # define malloc malloc
18 #include "conffile_internal.h"
19 #include "conffile.yy.h"
21 #define YYERROR_VERBOSE
23 static struct p_node *node(uint32_t type, struct p_node *l, struct p_node *r);
25 static struct p_node *result;
27 static void yyerror(const char *s);
33 input: assignments { result = $1; $$=result; }
36 assignments: assignments assignment { $$=node(T_ALIST, $2, $1); }
37 | assignment { $$=node(T_ALIST, $1, NULL); }
40 searchpath: /* empty */ { $$ = NULL; }
41 | '<' list '>' { $$ = $2; }
44 dict: searchpath '{' assignments '}'
45 { $$ = node(T_DICT, $3, $1); }
46 | searchpath '{' '}' { $$ = node(T_DICT, NULL, $1); }
49 path: '/' pathelements { $$ = node(T_ABSPATH, NULL, $2); }
50 | pathelements { $$ = node(T_RELPATH, NULL, $1); }
53 pathelements: pathelements '/' TOK_KEY { $$ = node(T_PATHELEM, $3, $1); }
54 | TOK_KEY { $$ = node(T_PATHELEM, $1, NULL); }
57 exec: item '(' list ')' { $$ = node(T_EXEC, $1, $3); }
58 | item '(' ')' { $$ = node(T_EXEC, $1, NULL); }
60 { $$ = node(T_EXEC, $1, node(T_LISTITEM, $2, NULL)); }
63 list: list ',' item { $$ = node(T_LISTITEM, $3, $1); }
64 | item { $$ = node(T_LISTITEM, $1, NULL); }
67 assignment: TOK_KEY '=' list ';' { $$ = node(T_ASSIGNMENT, $1, $3); }
68 | TOK_KEY list ';' { $$ = node(T_ASSIGNMENT, $1, $2); }
69 | error ';' { $$ = node(T_ERROR, NULL, NULL); }
70 | error '}' { $$ = node(T_ERROR, NULL, NULL); }
71 | error ')' { $$ = node(T_ERROR, NULL, NULL); }
83 static void yyerror(const char *s)
85 Message(M_FATAL,"config file %s line %d: %s\n",config_file,
89 struct p_node *parse_conffile(FILE *conffile)
93 fatal("Configuration file parsing failed\n");
96 fatal("%d error%s encountered in configuration file\n",
97 yynerrs,yynerrs==1?"":"s");
102 static struct p_node *node(uint32_t type, struct p_node *l, struct p_node *r)
108 rv->loc.file=config_file;
109 rv->loc.line=config_lineno;