/[hydra]/hydra/src/boa_lexer.l
ViewVC logotype

Annotation of /hydra/src/boa_lexer.l

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.4 - (hide annotations)
Thu Sep 26 14:02:11 2002 UTC (21 years, 6 months ago) by nmav
Branch: MAIN
CVS Tags: hydra_0_1_6_without_hic, hydra_0_0_10, hydra_0_0_8, hydra_0_0_9, hydra_0_0_2, hydra_0_0_3, hydra_0_0_6, hydra_0_0_7, hydra_0_0_4, hydra_0_0_5, hydra_0_1_3, hydra_0_1_2, hydra_0_1_1, hydra_0_1_0, hydra_0_1_7, hydra_0_1_6, hydra_0_1_4, hydra_0_1_8, HEAD
Branch point for: hydra_0_1_0_patches
Changes since 1.3: +2 -2 lines
*** empty log message ***

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

webmaster@linux.gr
ViewVC Help
Powered by ViewVC 1.1.26