]> git.ipfire.org Git - thirdparty/pdns.git/blame - pdns/bindlexer.l
Merge pull request #7628 from tcely/patch-3
[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 62
385b86f6
OM
63 int ret;
64 if(*(yytext+1)=='/') {
65 ret = snprintf(filename, sizeof(filename), "%s", yytext+1);
66 }
67 else {
68 ret = snprintf(filename, sizeof(filename), "%s/%s", bind_directory, yytext+1);
69 }
70 if (ret == -1 || ret >= sizeof(filename)) {
71 fprintf( stderr, "Filename '%s' is too long\n",yytext+1);
72 exit( 1 );
73 }
12c86877 74
d6a69bc5 75 if (!(yyin=fopen(filename,"r"))) {
12c86877
BH
76 fprintf( stderr, "Unable to open '%s': %s\n",filename,strerror(errno));
77 exit( 1 );
78 }
79
80 BEGIN(INITIAL);
81 yy_switch_to_buffer(yy_create_buffer(yyin,YY_BUF_SIZE));
82
83 }
84
85
86<<EOF>> {
87 if ( --include_stack_ptr < 0 )
751f7add 88 {
12c86877 89 yyterminate();
751f7add 90 }
12c86877
BH
91
92 else
93 {
e35673c4 94 fclose(yyin);
12c86877
BH
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]);
99 if(include_stack_ptr)
100 current_filename=include_stack_name[include_stack_ptr-1];
101 else
102 current_filename=original_filename;
103 }
104 }
105
106
107
108
109zone return ZONETOK;
110
111file return FILETOK;
112options return OPTIONSTOK;
27d94a79 113also-notify return ALSONOTIFYTOK;
12c86877
BH
114acl return ACLTOK;
115logging return LOGGINGTOK;
116directory return DIRECTORYTOK;
117masters return MASTERTOK;
118type return TYPETOK;
119\" yy_push_state(quoted);
120<quoted>[^\"]* yylval=strdup(yytext); return QUOTEDWORD;
121<quoted>\" yy_pop_state();
caa6eefa 122[^\" \t\n{};]* yylval=strdup(yytext);return AWORD;
12c86877
BH
123\{ return OBRACE;
124\} return EBRACE;
125; return SEMICOLON;
126\n linenumber++;
127[ \t]* ;
128\/\/.*$ ;
129\#.*$ ;
12c86877 130%%