ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/src/conf/lexer.l
Revision: 475
Committed: Sat Feb 18 02:34:20 2006 UTC (20 years, 5 months ago) by adx
File size: 5922 byte(s)
Log Message:
+ make it compile, and maybe even run...

File Contents

# User Rev Content
1 adx 89 /*
2     * ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd).
3     * lexer.l: A set of rules for flex.
4     *
5     * Copyright (C) 2003 by Piotr Nizynski, Advanced IRC Services Project
6     * Copyright (C) 2005 by the Hybrid Development Team.
7     *
8     * This program is free software; you can redistribute it and/or modify
9     * it under the terms of the GNU General Public License as published by
10     * the Free Software Foundation; either version 2 of the License, or
11     * (at your option) any later version.
12     *
13     * This program is distributed in the hope that it will be useful,
14     * but WITHOUT ANY WARRANTY; without even the implied warranty of
15     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16     * GNU General Public License for more details.
17     *
18     * You should have received a copy of the GNU General Public License
19     * along with this program; if not, write to the Free Software
20     * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
21     * USA
22     *
23     * $Id: conf_lexer.l,v 1.5 2003/10/14 16:18:56 adx Exp $
24     */
25    
26     %option case-insensitive
27     %option noyywrap
28     %option nounput
29    
30     %{
31    
32     #include "stdinc.h"
33 adx 179 #include "conf/conf.h"
34 adx 89 #include "y.tab.h"
35    
36     int conf_include_sptr = 0;
37    
38     #undef YY_INPUT
39     #define YY_INPUT(buf, res, siz) res = conf_yy_input(buf, siz)
40     /* flex's default is to print a message and exit(0) */
41     #define YY_FATAL_ERROR(msg) conf_yy_fatal_error(msg)
42    
43     #define MAX_INCLUDE_DEPTH 10
44    
45     YY_BUFFER_STATE conf_include_yystack[MAX_INCLUDE_DEPTH];
46     struct ConfParserContext conf_include_ctxstack[MAX_INCLUDE_DEPTH];
47    
48     static void conf_include(void);
49     static int conf_eof(void);
50     static int conf_yy_fatal_error(const char *msg)
51     {
52     return(0);
53     }
54    
55     %}
56    
57     ws [ \t]*
58     include \.include{ws}(\<.*\>|\".*\")
59     qstring \"[^\"]*\"
60 adx 267 identifier [a-zA-Z_][a-zA-Z0-9_:]*
61 adx 89
62     %%
63    
64     {include} { conf_include(); }
65     "/*" {
66 adx 475 int c;
67 adx 89
68 adx 475 while (1)
69     {
70     while ((c = input()) != '*' && c != EOF)
71     if (c == '\n')
72     {
73     conf_curctx.lineno++;
74     conf_linebuf[0] = '\0';
75     }
76     while (c == '*')
77     c = input();
78     if (c == '/')
79     break;
80     if (c == EOF)
81     {
82     yyerror("EOF in comment");
83     break;
84     }
85     }
86     }
87 adx 89 \n.* {
88 adx 475 conf_curctx.lineno++;
89     strlcpy(conf_linebuf, yytext + 1, CONF_BUFSIZE);
90     yyless(1);
91     }
92 adx 89 {ws} ;
93     #.* {
94 adx 475 if (!strncasecmp(yytext, "#include", 8))
95     yyerror("You probably meant '.include', ignoring");
96 adx 89 }
97     [0-9]+ { yylval.number = atoi(yytext); return NUMBER; }
98     {qstring} {
99 adx 475 yytext[yyleng - 1] = '\0';
100     yylval.string = yytext + 1;
101     return QSTRING;
102     }
103     b { return BYTES; }
104     byte { return BYTES; }
105     bytes { return BYTES; }
106     d { return DAYS; }
107     day { return DAYS; }
108     days { return DAYS; }
109 adx 89 false { yylval.number = 0; return BOOL; }
110 adx 475 h { return HOURS; }
111 adx 89 hour { return HOURS; }
112     hours { return HOURS; }
113 adx 475 kb { return KBYTES; }
114 adx 89 kbyte { return KBYTES; }
115     kbytes { return KBYTES; }
116     kilobyte { return KBYTES; }
117     kilobytes { return KBYTES; }
118 adx 475 mb { return MBYTES; }
119 adx 89 mbyte { return MBYTES; }
120     mbytes { return MBYTES; }
121     megabyte { return MBYTES; }
122     megabytes { return MBYTES; }
123 adx 475 m { return MINUTES; }
124     min { return MINUTES; }
125 adx 89 mins { return MINUTES; }
126     minute { return MINUTES; }
127     minutes { return MINUTES; }
128 adx 475 no { yylval.number = 0; return BOOL; }
129     off { yylval.number = 0; return BOOL; }
130     on { yylval.number = 1; return BOOL; }
131     s { return SECONDS; }
132     sec { return SECONDS; }
133 adx 89 secs { return SECONDS; }
134     second { return SECONDS; }
135     seconds { return SECONDS; }
136     true { yylval.number = 1; return BOOL; }
137 adx 475 w { return WEEKS; }
138 adx 89 week { return WEEKS; }
139     weeks { return WEEKS; }
140 adx 475 yes { yylval.number = 1; return BOOL; }
141 adx 89 {identifier} { yylval.string = yytext; return IDENTIFIER; }
142 adx 475 . { return yytext[0]; }
143 adx 89 <<EOF>> { if (conf_eof()) yyterminate(); }
144    
145     %%
146    
147     /*
148     * conf_include()
149     *
150     * Enters a new configuration file.
151     *
152     * inputs: none
153     * output: none
154     */
155     static void
156     conf_include(void)
157     {
158     char *fname, *buf;
159     FBFILE *f;
160    
161     if (conf_include_sptr == MAX_INCLUDE_DEPTH)
162     {
163     yyerror("includes nested too deep");
164     return;
165     }
166    
167     if ((fname = strchr(yytext, '"')) == NULL)
168     *strchr(fname = strchr(yytext, '<') + 1, '>') = '\0';
169     else
170     *strchr(++fname, '"') = '\0';
171    
172     if (fname[0] == '/')
173     f = fbopen(fname, "r");
174     else
175     {
176     buf = MyMalloc(strlen(ETCPATH) + 1 + strlen(fname) + 1);
177     sprintf(buf, "%s/%s", ETCPATH, fname);
178     f = fbopen(buf, "r");
179     MyFree(buf);
180     }
181    
182     if (f == NULL)
183     {
184     yyerror("cannot open file to include");
185     return;
186     }
187    
188     /* save current state */
189     memcpy(&conf_include_ctxstack[conf_include_sptr], &conf_curctx,
190     sizeof(struct ConfParserContext));
191     conf_include_yystack[conf_include_sptr++] = YY_CURRENT_BUFFER;
192    
193     /* switch lexer context */
194     conf_linebuf[0] = '\0';
195     conf_curctx.f = f;
196     DupString(conf_curctx.filename, fname);
197     conf_curctx.lineno = 1;
198     yy_switch_to_buffer(yy_create_buffer(yyin, YY_BUF_SIZE));
199     }
200    
201     /*
202     * conf_eof()
203     *
204     * Ends processing of a configuration file.
205     *
206     * inputs: none
207     * output: 1 if the parser should be exited, 0 otherwise
208     */
209     static int
210     conf_eof(void)
211     {
212     if (conf_include_sptr == 0)
213     return 1;
214    
215     /* destroy current buffer */
216     yy_delete_buffer(YY_CURRENT_BUFFER);
217     fbclose(conf_curctx.f);
218    
219     /* restore old context */
220     conf_linebuf[0] = '\0';
221     memcpy(&conf_curctx, &conf_include_ctxstack[--conf_include_sptr],
222     sizeof(struct ConfParserContext));
223     yy_switch_to_buffer(conf_include_yystack[conf_include_sptr]);
224    
225     return 0;
226     yy_fatal_error(NULL); /* use it somewhere to avoid the warning */
227     }