12 #include "conffile_internal.h"
13 #include "conffile.yy.h"
15 #define YYERROR_VERBOSE
17 static struct p_node *node(uint32_t type, struct p_node *l, struct p_node *r);
19 static struct p_node *result;
21 static void yyerror(const char *s);
27 input: assignments { result = $1; $$=result; }
30 assignments: assignments assignment { $$=node(T_ALIST, $2, $1); }
31 | assignment { $$=node(T_ALIST, $1, NULL); }
34 searchpath: /* empty */ { $$ = NULL; }
35 | '<' list '>' { $$ = $2; }
38 dict: searchpath '{' assignments '}'
39 { $$ = node(T_DICT, $3, $1); }
40 | searchpath '{' '}' { $$ = node(T_DICT, NULL, $1); }
43 path: '/' pathelements { $$ = node(T_ABSPATH, NULL, $2); }
44 | pathelements { $$ = node(T_RELPATH, NULL, $1); }
47 pathelements: pathelements '/' TOK_KEY { $$ = node(T_PATHELEM, $3, $1); }
48 | TOK_KEY { $$ = node(T_PATHELEM, $1, NULL); }
51 exec: item '(' list ')' { $$ = node(T_EXEC, $1, $3); }
52 | item '(' ')' { $$ = node(T_EXEC, $1, NULL); }
54 { $$ = node(T_EXEC, $1, node(T_LISTITEM, $2, NULL)); }
57 list: list ',' item { $$ = node(T_LISTITEM, $3, $1); }
58 | item { $$ = node(T_LISTITEM, $1, NULL); }
61 assignment: TOK_KEY '=' list ';' { $$ = node(T_ASSIGNMENT, $1, $3); }
62 | TOK_KEY list ';' { $$ = node(T_ASSIGNMENT, $1, $2); }
63 | error ';' { $$ = node(T_ERROR, NULL, NULL); }
64 | error '}' { $$ = node(T_ERROR, NULL, NULL); }
65 | error ')' { $$ = node(T_ERROR, NULL, NULL); }
77 static void yyerror(const char *s)
79 Message(M_FATAL,"config file %s line %d: %s\n",config_file,
83 struct p_node *parse_conffile(FILE *conffile)
87 fatal("Configuration file parsing failed\n");
90 fatal("%d error%s encountered in configuration file\n",
91 yynerrs,yynerrs==1?"":"s");
96 static struct p_node *node(uint32_t type, struct p_node *l, struct p_node *r)
100 rv=safe_malloc(sizeof(*rv),"p_node");
102 rv->loc.file=config_file;
103 rv->loc.line=config_lineno;