1 /* the "incl" state is used for picking up the name of an include file */
6 %option never-interactive
15 #include "conffile_internal.h"
16 #include "conffile.tab.h"
21 #define YY_INPUT(buf,result,max_size) \
23 (result)= fread((buf),1,(max_size),yyin); \
25 fatal_perror("Error reading configuration file (%s)", \
29 #define MAX_INCLUDE_DEPTH 10
30 struct include_stack_item {
35 struct include_stack_item include_stack[MAX_INCLUDE_DEPTH];
36 int include_stack_ptr=0;
39 cstring_t config_file="xxx";
41 static struct p_node *leafnode(uint32_t type)
45 r=safe_malloc(sizeof(*r),"leafnode");
47 r->loc.file=config_file;
48 r->loc.line=config_lineno;
53 static struct p_node *keynode(atom_t key)
57 r->data.key=intern(key);
61 static struct p_node *stringnode(string_t string)
66 string[strlen(string)-1]=0;
67 r->data.string=safe_strdup(string,"stringnode");
71 static struct p_node *numnode(string_t number)
75 r->data.number=atoi(number);
83 <incl>[ \t]* /* eat the whitespace */
84 <incl>[^ \t\n]+ { /* got the include filename */
85 if (include_stack_ptr >= MAX_INCLUDE_DEPTH) {
86 fatal("Configuration file includes nested too deeply");
88 include_stack[include_stack_ptr].bst=YY_CURRENT_BUFFER;
89 include_stack[include_stack_ptr].lineno=config_lineno;
90 include_stack[include_stack_ptr].file=config_file;
92 yyin=fopen(yytext,"r");
94 fatal("Can't open included file %s",yytext);
97 config_file=safe_strdup(yytext,"conffile.fl/include");
98 yy_switch_to_buffer(yy_create_buffer(yyin, YY_BUF_SIZE));
101 <incl>\n { /* include with no filename */
102 Message(M_FATAL,"config file %s line %d: %s\n",config_file,
103 config_lineno,"``include'' requires a filename");
105 assert(config_lineno < INT_MAX);
111 if (--include_stack_ptr < 0) {
116 yy_delete_buffer(YY_CURRENT_BUFFER);
117 yy_switch_to_buffer(include_stack[include_stack_ptr].bst);
118 config_lineno=include_stack[include_stack_ptr].lineno;
119 config_file=include_stack[include_stack_ptr].file;
122 \"[^\"]*\" yylval=stringnode(yytext); return TOK_STRING;
124 [[:alpha:]_][[:alnum:]\-_]* yylval=keynode(yytext); return TOK_KEY;
126 [[:digit:]]+ yylval=numnode(yytext); return TOK_NUMBER;
129 \#.*\n config_lineno++;
135 /* Return all unclaimed single characters to the parser */