]> git.ipfire.org Git - thirdparty/pdns.git/blame - pdns/bindlexer.l
auth 4.1 build: Switch to devtoolset 7 for el6
[thirdparty/pdns.git] / pdns / bindlexer.l
CommitLineData
12c86877
BH
1%{
2#include <stdio.h>
3#include <stdlib.h>
4#include <string.h>
5#include <errno.h>
6
222efdc0 7#define YY_NO_INPUT 1
12c86877
BH
8#define YYSTYPE char *
9
12c86877 10#include "bindparser.h"
12c86877
BH
11
12int linenumber;
13#define MAX_INCLUDE_DEPTH 10
14YY_BUFFER_STATE include_stack[MAX_INCLUDE_DEPTH];
15int include_stack_ln[MAX_INCLUDE_DEPTH];
16char *include_stack_name[MAX_INCLUDE_DEPTH];
17char *current_filename;
18char *original_filename;
19int include_stack_ptr = 0;
20extern const char *bind_directory;
21
22%}
23
24%x comment
25%x incl
26%x quoted
27%option stack
222efdc0
PD
28%option nounput
29%option noyy_top_state
30%option noinput
31
12c86877
BH
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
41include 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 {
d6a69bc5 47 fprintf( stderr, "Includes nested too deeply\n" );
12c86877
BH
48 exit( 1 );
49 }
50
d6a69bc5
RG
51 if (strlen(yytext) <= 2) {
52 fprintf( stderr, "Empty include directive\n" );
53 exit( 1 );
54 }
55
12c86877
BH
56 yytext[strlen(yytext)-2]=0;
57
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;
61 linenumber=1;
d6a69bc5
RG
62
63 if(*(yytext+1)=='/') {
64 if (strlen(yytext+1) >= sizeof(filename)) {
65 fprintf( stderr, "Filename '%s' is too long\n",yytext+1);
66 exit( 1 );
67 }
12c86877 68 strcpy(filename,yytext+1);
d6a69bc5 69 }
12c86877 70 else {
d6a69bc5
RG
71 size_t bind_directory_len = strlen(bind_directory);
72 if (bind_directory_len >= sizeof(filename) ||
73 strlen(yytext+1) + 2 >= sizeof(filename) - bind_directory_len) {
74 fprintf( stderr, "Filename '%s' is too long\n",yytext+1);
75 exit( 1 );
76 }
12c86877
BH
77 strcpy(filename,bind_directory);
78 strcat(filename,"/");
79 strcat(filename,yytext+1);
80 }
d6a69bc5 81 filename[sizeof(filename)-1]='\0';
12c86877 82
d6a69bc5 83 if (!(yyin=fopen(filename,"r"))) {
12c86877
BH
84 fprintf( stderr, "Unable to open '%s': %s\n",filename,strerror(errno));
85 exit( 1 );
86 }
87
88 BEGIN(INITIAL);
89 yy_switch_to_buffer(yy_create_buffer(yyin,YY_BUF_SIZE));
90
91 }
92
93
94<<EOF>> {
95 if ( --include_stack_ptr < 0 )
751f7add 96 {
12c86877 97 yyterminate();
751f7add 98 }
12c86877
BH
99
100 else
101 {
e35673c4 102 fclose(yyin);
12c86877
BH
103 yy_delete_buffer(YY_CURRENT_BUFFER);
104 yy_switch_to_buffer(include_stack[include_stack_ptr]);
105 linenumber=include_stack_ln[include_stack_ptr];
106 free(include_stack_name[include_stack_ptr]);
107 if(include_stack_ptr)
108 current_filename=include_stack_name[include_stack_ptr-1];
109 else
110 current_filename=original_filename;
111 }
112 }
113
114
115
116
117zone return ZONETOK;
118
119file return FILETOK;
120options return OPTIONSTOK;
27d94a79 121also-notify return ALSONOTIFYTOK;
12c86877
BH
122acl return ACLTOK;
123logging return LOGGINGTOK;
124directory return DIRECTORYTOK;
125masters return MASTERTOK;
126type return TYPETOK;
127\" yy_push_state(quoted);
128<quoted>[^\"]* yylval=strdup(yytext); return QUOTEDWORD;
129<quoted>\" yy_pop_state();
caa6eefa 130[^\" \t\n{};]* yylval=strdup(yytext);return AWORD;
12c86877
BH
131\{ return OBRACE;
132\} return EBRACE;
133; return SEMICOLON;
134\n linenumber++;
135[ \t]* ;
136\/\/.*$ ;
137\#.*$ ;
12c86877 138%%