]> git.ipfire.org Git - thirdparty/pdns.git/blob - pdns/bindlexer.l
move bindbackend to modules
[thirdparty/pdns.git] / pdns / bindlexer.l
1 %{
2
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <string.h>
6 #include <errno.h>
7
8 #define YY_NO_INPUT 1
9 #define YYSTYPE char *
10
11 #include "bindparser.h"
12
13 int linenumber;
14 #define MAX_INCLUDE_DEPTH 10
15 YY_BUFFER_STATE include_stack[MAX_INCLUDE_DEPTH];
16 int include_stack_ln[MAX_INCLUDE_DEPTH];
17 char *include_stack_name[MAX_INCLUDE_DEPTH];
18 char *current_filename;
19 char *original_filename;
20 int include_stack_ptr = 0;
21 extern const char *bind_directory;
22
23 %}
24
25 %x comment
26 %x incl
27 %x quoted
28 %option stack
29 %option nounput
30 %option noyy_top_state
31 %option noinput
32
33 %%
34
35
36 "/*" BEGIN(comment);
37 <comment>[^*\n]* /* eat anything that's not a '*' */
38 <comment>"*"+[^*/\n]* /* eat up '*'s not followed by '/'s */
39 <comment>\n ++linenumber;
40 <comment>"*"+"/" BEGIN(INITIAL);
41
42 include BEGIN(incl);
43 <incl>[ \t;]* /* eat the whitespace */
44 <incl>\"[^ \t\n";]+\"; { /* got the include file name */
45 char filename[1024];
46 if ( include_stack_ptr >= MAX_INCLUDE_DEPTH )
47 {
48 fprintf( stderr, "Includes nested too deeply" );
49 exit( 1 );
50 }
51
52 yytext[strlen(yytext)-2]=0;
53
54 include_stack[include_stack_ptr]=YY_CURRENT_BUFFER;
55 include_stack_name[include_stack_ptr]=current_filename=strdup(yytext+1);
56 include_stack_ln[include_stack_ptr++]=linenumber;
57 linenumber=1;
58 if(*(yytext+1)=='/')
59 strcpy(filename,yytext+1);
60 else {
61 strcpy(filename,bind_directory);
62 strcat(filename,"/");
63 strcat(filename,yytext+1);
64 }
65
66 if (*yytext &&!(yyin=fopen(filename,"r"))) {
67 fprintf( stderr, "Unable to open '%s': %s\n",filename,strerror(errno));
68 exit( 1 );
69 }
70
71 BEGIN(INITIAL);
72 yy_switch_to_buffer(yy_create_buffer(yyin,YY_BUF_SIZE));
73
74 }
75
76
77 <<EOF>> {
78 if ( --include_stack_ptr < 0 )
79 {
80 yyterminate();
81 }
82
83 else
84 {
85 fclose(yyin);
86 yy_delete_buffer(YY_CURRENT_BUFFER);
87 yy_switch_to_buffer(include_stack[include_stack_ptr]);
88 linenumber=include_stack_ln[include_stack_ptr];
89 free(include_stack_name[include_stack_ptr]);
90 if(include_stack_ptr)
91 current_filename=include_stack_name[include_stack_ptr-1];
92 else
93 current_filename=original_filename;
94 }
95 }
96
97
98
99
100 zone return ZONETOK;
101
102 file return FILETOK;
103 options return OPTIONSTOK;
104 also-notify return ALSONOTIFYTOK;
105 acl return ACLTOK;
106 logging return LOGGINGTOK;
107 directory return DIRECTORYTOK;
108 masters return MASTERTOK;
109 type return TYPETOK;
110 \" yy_push_state(quoted);
111 <quoted>[^\"]* yylval=strdup(yytext); return QUOTEDWORD;
112 <quoted>\" yy_pop_state();
113 [^\" \t\n{};]* yylval=strdup(yytext);return AWORD;
114 \{ return OBRACE;
115 \} return EBRACE;
116 ; return SEMICOLON;
117 \n linenumber++;
118 [ \t]* ;
119 \/\/.*$ ;
120 \#.*$ ;
121 . {
122 fprintf(stderr,"Parsing '%s': unable to parse line %d at character '%s'\n",current_filename, linenumber, yytext);
123 exit(1); }
124 %%