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"
13 #define MAX_INCLUDE_DEPTH 10
14 struct include_stack_item {
19 struct include_stack_item include_stack[MAX_INCLUDE_DEPTH];
20 int include_stack_ptr=0;
22 uint32_t config_lineno=0;
23 string_t config_file="xxx";
25 static struct p_node *leafnode(uint32_t type)
29 r=safe_malloc(sizeof(*r),"leafnode");
31 r->loc.file=config_file;
32 r->loc.line=config_lineno;
37 static struct p_node *keynode(atom_t key)
41 r->data.key=intern(key);
45 static struct p_node *stringnode(string_t string)
50 string[strlen(string)-1]=0;
51 r->data.string=safe_strdup(string,"stringnode");
55 static struct p_node *numnode(string_t number)
59 r->data.number=atoi(number);
67 <incl>[ \t]* /* eat the whitespace */
68 <incl>[^ \t\n]+ { /* got the include filename */
69 if (include_stack_ptr >= MAX_INCLUDE_DEPTH) {
70 fatal("Configuration file includes nested too deeply");
72 include_stack[include_stack_ptr].bst=YY_CURRENT_BUFFER;
73 include_stack[include_stack_ptr].lineno=config_lineno;
74 include_stack[include_stack_ptr].file=config_file;
76 yyin=fopen(yytext,"r");
78 fatal("Can't open included file %s",yytext);
81 config_file=safe_strdup(yytext,"conffile.fl/include");
82 yy_switch_to_buffer(yy_create_buffer(yyin, YY_BUF_SIZE));
86 if (--include_stack_ptr < 0) {
91 yy_delete_buffer(YY_CURRENT_BUFFER);
92 yy_switch_to_buffer(include_stack[include_stack_ptr].bst);
93 config_lineno=include_stack[include_stack_ptr].lineno;
94 config_file=include_stack[include_stack_ptr].file;
97 \"[^\"]*\" yylval=stringnode(yytext); return TOK_STRING;
99 [[:alpha:]_][[:alnum:]\-_]* yylval=keynode(yytext); return TOK_KEY;
101 [[:digit:]]+ yylval=numnode(yytext); return TOK_NUMBER;
104 \#.*\n config_lineno++;
110 /* Return all unclaimed single characters to the parser */