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