1 /* the "incl" state is used for picking up the name of an include file */
12 #include "conffile_internal.h"
13 #include "conffile.tab.h"
18 #define YY_INPUT(buf,result,max_size) \
20 (result)= fread((buf),1,(max_size),yyin); \
22 fatal_perror("Error reading configuration file (%s)", \
26 #define MAX_INCLUDE_DEPTH 10
27 struct include_stack_item {
32 struct include_stack_item include_stack[MAX_INCLUDE_DEPTH];
33 int include_stack_ptr=0;
35 uint32_t config_lineno=0;
36 cstring_t config_file="xxx";
38 static struct p_node *leafnode(uint32_t type)
42 r=safe_malloc(sizeof(*r),"leafnode");
44 r->loc.file=config_file;
45 r->loc.line=config_lineno;
50 static struct p_node *keynode(atom_t key)
54 r->data.key=intern(key);
58 static struct p_node *stringnode(string_t string)
63 string[strlen(string)-1]=0;
64 r->data.string=safe_strdup(string,"stringnode");
68 static struct p_node *numnode(string_t number)
72 r->data.number=atoi(number);
80 <incl>[ \t]* /* eat the whitespace */
81 <incl>[^ \t\n]+ { /* got the include filename */
82 if (include_stack_ptr >= MAX_INCLUDE_DEPTH) {
83 fatal("Configuration file includes nested too deeply");
85 include_stack[include_stack_ptr].bst=YY_CURRENT_BUFFER;
86 include_stack[include_stack_ptr].lineno=config_lineno;
87 include_stack[include_stack_ptr].file=config_file;
89 yyin=fopen(yytext,"r");
91 fatal("Can't open included file %s",yytext);
94 config_file=safe_strdup(yytext,"conffile.fl/include");
95 yy_switch_to_buffer(yy_create_buffer(yyin, YY_BUF_SIZE));
98 <incl>\n { /* include with no filename */
99 Message(M_FATAL,"config file %s line %d: %s\n",config_file,
100 config_lineno,"``include'' requires a filename");
107 if (--include_stack_ptr < 0) {
112 yy_delete_buffer(YY_CURRENT_BUFFER);
113 yy_switch_to_buffer(include_stack[include_stack_ptr].bst);
114 config_lineno=include_stack[include_stack_ptr].lineno;
115 config_file=include_stack[include_stack_ptr].file;
118 \"[^\"]*\" yylval=stringnode(yytext); return TOK_STRING;
120 [[:alpha:]_][[:alnum:]\-_]* yylval=keynode(yytext); return TOK_KEY;
122 [[:digit:]]+ yylval=numnode(yytext); return TOK_NUMBER;
125 \#.*\n config_lineno++;
131 /* Return all unclaimed single characters to the parser */