10 #include "bindparser.h"
13 #define MAX_INCLUDE_DEPTH 10
14 YY_BUFFER_STATE include_stack[MAX_INCLUDE_DEPTH];
15 int include_stack_ln[MAX_INCLUDE_DEPTH];
16 char *include_stack_name[MAX_INCLUDE_DEPTH];
17 char *current_filename;
18 char *original_filename;
19 int include_stack_ptr = 0;
20 extern const char *bind_directory;
29 %option noyy_top_state
36 <comment>[^*\n]* /* eat anything that's not a '*' */
37 <comment>"*"+[^*/\n]* /* eat up '*'s not followed by '/'s */
38 <comment>\n ++linenumber;
39 <comment>"*"+"/" BEGIN(INITIAL);
42 <incl>[ \t;]* /* eat the whitespace */
43 <incl>\"[^ \t\n";]+\"; { /* got the include file name */
45 if ( include_stack_ptr >= MAX_INCLUDE_DEPTH )
47 fprintf( stderr, "Includes nested too deeply\n" );
51 if (strlen(yytext) <= 2) {
52 fprintf( stderr, "Empty include directive\n" );
56 yytext[strlen(yytext)-2]=0;
58 include_stack[include_stack_ptr]=YY_CURRENT_BUFFER;
59 include_stack_name[include_stack_ptr]=current_filename=strdup(yytext+1);
60 include_stack_ln[include_stack_ptr++]=linenumber;
64 if(*(yytext+1)=='/') {
65 ret = snprintf(filename, sizeof(filename), "%s", yytext+1);
68 ret = snprintf(filename, sizeof(filename), "%s/%s", bind_directory, yytext+1);
70 if (ret == -1 || ret >= sizeof(filename)) {
71 fprintf( stderr, "Filename '%s' is too long\n",yytext+1);
75 if (!(yyin=fopen(filename,"r"))) {
76 fprintf( stderr, "Unable to open '%s': %s\n",filename,strerror(errno));
81 yy_switch_to_buffer(yy_create_buffer(yyin,YY_BUF_SIZE));
87 if ( --include_stack_ptr < 0 )
95 yy_delete_buffer(YY_CURRENT_BUFFER);
96 yy_switch_to_buffer(include_stack[include_stack_ptr]);
97 linenumber=include_stack_ln[include_stack_ptr];
98 free(include_stack_name[include_stack_ptr]);
100 current_filename=include_stack_name[include_stack_ptr-1];
102 current_filename=original_filename;
112 options return OPTIONSTOK;
113 also-notify return ALSONOTIFYTOK;
115 logging return LOGGINGTOK;
116 directory return DIRECTORYTOK;
117 masters return MASTERTOK;
119 \" yy_push_state(quoted);
120 <quoted>[^\"]* yylval=strdup(yytext); return QUOTEDWORD;
121 <quoted>\" yy_pop_state();
122 [^\" \t\n{};]* yylval=strdup(yytext);return AWORD;