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 YY_INPUT(buf,result,max_size) \
17 (result)= fread((buf),1,(max_size),yyin); \
19 fatal_perror("Error reading configuration file (%s)", \
23 #define MAX_INCLUDE_DEPTH 10
24 struct include_stack_item {
29 struct include_stack_item include_stack[MAX_INCLUDE_DEPTH];
30 int include_stack_ptr=0;
32 uint32_t config_lineno=0;
33 cstring_t config_file="xxx";
35 static struct p_node *leafnode(uint32_t type)
39 r=safe_malloc(sizeof(*r),"leafnode");
41 r->loc.file=config_file;
42 r->loc.line=config_lineno;
47 static struct p_node *keynode(atom_t key)
51 r->data.key=intern(key);
55 static struct p_node *stringnode(string_t string)
60 string[strlen(string)-1]=0;
61 r->data.string=safe_strdup(string,"stringnode");
65 static struct p_node *numnode(string_t number)
69 r->data.number=atoi(number);
77 <incl>[ \t]* /* eat the whitespace */
78 <incl>[^ \t\n]+ { /* got the include filename */
79 if (include_stack_ptr >= MAX_INCLUDE_DEPTH) {
80 fatal("Configuration file includes nested too deeply");
82 include_stack[include_stack_ptr].bst=YY_CURRENT_BUFFER;
83 include_stack[include_stack_ptr].lineno=config_lineno;
84 include_stack[include_stack_ptr].file=config_file;
86 yyin=fopen(yytext,"r");
88 fatal("Can't open included file %s",yytext);
91 config_file=safe_strdup(yytext,"conffile.fl/include");
92 yy_switch_to_buffer(yy_create_buffer(yyin, YY_BUF_SIZE));
95 <incl>\n { /* include with no filename */
96 Message(M_FATAL,"config file %s line %d: %s\n",config_file,
97 config_lineno,"``include'' requires a filename");
104 if (--include_stack_ptr < 0) {
109 yy_delete_buffer(YY_CURRENT_BUFFER);
110 yy_switch_to_buffer(include_stack[include_stack_ptr].bst);
111 config_lineno=include_stack[include_stack_ptr].lineno;
112 config_file=include_stack[include_stack_ptr].file;
115 \"[^\"]*\" yylval=stringnode(yytext); return TOK_STRING;
117 [[:alpha:]_][[:alnum:]\-_]* yylval=keynode(yytext); return TOK_KEY;
119 [[:digit:]]+ yylval=numnode(yytext); return TOK_NUMBER;
122 \#.*\n config_lineno++;
128 /* Return all unclaimed single characters to the parser */