-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathboa_lexer.l
155 lines (128 loc) · 3.28 KB
/
boa_lexer.l
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
%{
/*
* Boa, an http server
* Copyright (C) 1995 Paul Phillips <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 1, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/
/* $Id: boa_lexer.l,v 1.13.2.1 2002/07/07 23:19:55 jnelson Exp $*/
#include "y.tab.h"
#include <stdlib.h>
#include <unistd.h>
#include "parse.h"
#define MAX_STR_CONST 1024
#define qspush(c) \
if (string_buf_ptr < string_buf+MAX_STR_CONST) \
*string_buf_ptr++ = c; \
else \
yyerror("quoted string overflow");
char *mime_types = NULL;
static int file = 0;
int lineno = 1;
struct ccommand *k;
char string_buf[MAX_STR_CONST];
char *string_buf_ptr;
%}
%s MIME
/* Quoted string handling (almost) straight out of
the flex 2.5 man page, April 1995 */
%x STR
%%
[ \t]+ ;
#.* ;
<MIME>[^ \t\n]+\/[^ \t\n]+ { yylval.sval = yytext; return MIMETYPE; }
[^ \"\t\n]+ { /* XXX could use better checks that we are in a state to
* accept keywords; this version matches original behavior */
if ((YYSTATE==INITIAL) && (k=lookup_keyword(yytext))) {
yylval.cval=k;
return (k->type);
} else { yylval.sval = yytext; return STRING; }
}
\" {
string_buf_ptr = string_buf;
BEGIN(STR);
}
<STR>{
\" { /* saw closing quote - all done */
BEGIN(INITIAL);
*string_buf_ptr = '\0';
/* return string constant token type and value to parser */
yylval.sval = string_buf; return STRING;
}
\n {
/* error - unterminated string constant */
/* generate error message */
yyerror("unterminated string constant");
}
\\[0-7]{1,3} {
/* octal escape sequence */
int result;
(void) sscanf( yytext + 1, "%o", &result );
if ( result > 0xff )
{ /* error, constant is out-of-bounds */ }
qspush(result);
}
\\[0-9]+ {
/* generate error - bad escape sequence; something
* like '\48' or '\0777777'
*/
yyerror("bad escape sequence");
}
\\n qspush('\n');
\\t qspush('\t');
\\r qspush('\r');
\\b qspush('\b');
\\f qspush('\f');
\\(.|\n) *string_buf_ptr++ = yytext[1];
[^\\\n\"]+ {
char *yptr = yytext;
while ( *yptr )
qspush(*yptr++);
}
}
/* End of <STR> dependence */
\n { lineno++; }
%%
/* In yywrap we track which file we are on.
* 1: close boa.conf, open mime.types
* 2: return 1;
*/
int yywrap()
{
fclose(yyin);
file++;
switch(file) {
case 1:
yyin = fopen(mime_types, "r");
if(!yyin) {
fprintf(stderr, "Could not open mime.types file, \"%s\", "
"for reading\n", mime_types);
exit(1);
}
BEGIN MIME;
return 0;
default:
BEGIN INITIAL;
file = 0; /* in case we reread config files */
return 1;
}
}
int yyerror(char * msg)
{
fprintf(stderr, "Error on line %d of %s: %s\n", lineno,
(file == 0 ? "boa.conf" : "mime.types"), msg);
return 1;
}