1 /* the "incl" state is used for picking up the name of an include file */
9 #include "conffile_internal.h"
10 #include "conffile.tab.h"
15 #define MAX_INCLUDE_DEPTH 10
16 struct include_stack_item {
21 struct include_stack_item include_stack[MAX_INCLUDE_DEPTH];
22 int include_stack_ptr=0;
24 uint32_t config_lineno=0;
25 string_t config_file="xxx";
27 static struct p_node *leafnode(uint32_t type)
31 r=safe_malloc(sizeof(*r),"leafnode");
33 r->loc.file=config_file;
34 r->loc.line=config_lineno;
39 static struct p_node *keynode(atom_t key)
43 r->data.key=intern(key);
47 static struct p_node *stringnode(string_t string)
52 string[strlen(string)-1]=0;
53 r->data.string=safe_strdup(string,"stringnode");
57 static struct p_node *numnode(string_t number)
61 r->data.number=atoi(number);
69 <incl>[ \t]* /* eat the whitespace */
70 <incl>[^ \t\n]+ { /* got the include filename */
71 if (include_stack_ptr >= MAX_INCLUDE_DEPTH) {
72 fatal("Configuration file includes nested too deeply");
74 include_stack[include_stack_ptr].bst=YY_CURRENT_BUFFER;
75 include_stack[include_stack_ptr].lineno=config_lineno;
76 include_stack[include_stack_ptr].file=config_file;
78 yyin=fopen(yytext,"r");
80 fatal("Can't open included file %s",yytext);
83 config_file=safe_strdup(yytext,"conffile.fl/include");
84 yy_switch_to_buffer(yy_create_buffer(yyin, YY_BUF_SIZE));
88 if (--include_stack_ptr < 0) {
93 yy_delete_buffer(YY_CURRENT_BUFFER);
94 yy_switch_to_buffer(include_stack[include_stack_ptr].bst);
95 config_lineno=include_stack[include_stack_ptr].lineno;
96 config_file=include_stack[include_stack_ptr].file;
99 \"[^\"]*\" yylval=stringnode(yytext); return TOK_STRING;
101 [[:alpha:]_][[:alnum:]\-_]* yylval=keynode(yytext); return TOK_KEY;
103 [[:digit:]]+ yylval=numnode(yytext); return TOK_NUMBER;
106 \#.*\n config_lineno++;
112 /* Return all unclaimed single characters to the parser */