3
* This program is free software; you can redistribute it and/or modify
4
* it under the terms of the GNU General Public License as published by
5
* the Free Software Foundation; either version 2 of the License, or
6
* (at your option) any later version.
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU General Public License for more details.
13
* You should have received a copy of the GNU General Public License
14
* along with this program; if not, write to the Free Software
15
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
18
* $Id: ircd_lexer.l 3540 2007-07-30 17:26:00Z jilles $
21
%option case-insensitive
26
#include <sys/types.h>
29
#include <netinet/in.h>
35
#define WE_ARE_MEMORY_C
38
#include "ircd_defs.h"
49
/* here to fixup gcc 3.3 errors */
50
int yyget_lineno(void);
52
FILE *yyget_out(void);
54
char *yyget_text(void);
55
void yyset_lineno(int line_number);
56
void yyset_in(FILE * in_str);
57
void yyset_out(FILE * out_str);
58
int yyget_debug(void);
59
void yyset_debug(int bdebug);
60
int yylex_destroy(void);
63
#define MAX_INCLUDE_DEPTH 10
65
YY_BUFFER_STATE include_stack[MAX_INCLUDE_DEPTH];
66
int include_stack_ptr=0;
70
void hashcomment(void);
72
int lineno_stack[MAX_INCLUDE_DEPTH];
73
char conffile_stack[MAX_INCLUDE_DEPTH][IRCD_BUFSIZE];
74
char conffilebuf[IRCD_BUFSIZE+1];
75
char *current_file = conffilebuf;
77
FILE *inc_fbfile_in[MAX_INCLUDE_DEPTH];
83
#define YY_FATAL_ERROR(msg) conf_yy_fatal_error(msg)
85
#define YY_INPUT(buf,result,max_size) \
86
if (!(result = conf_fgets(buf, max_size, conf_fbfile_in))) \
87
YY_FATAL_ERROR("input in flex scanner failed");
93
qstring \"[^\"\n]*[\"\n]
94
string [a-zA-Z_\~\:][a-zA-Z0-9_\:]*
95
include \.include{ws}(\<.*\>|\".*\")
98
{include} { cinclude(); }
100
\n.* { strcpy(linebuf, yytext+1); lineno++; yyless(1); }
103
{comment} { hashcomment(); }
105
{digit}+ { yylval.number = atoi(yytext); return NUMBER; }
108
if(yytext[yyleng-2] == '\\')
110
yyless(yyleng-1); /* return last quote */
111
yymore(); /* append next string */
115
strcpy(yylval.string, yytext + 1);
116
if(yylval.string[yyleng-2] != '"')
117
ilog(L_MAIN, "Unterminated character string");
121
yylval.string[yyleng-2] = '\0'; /* remove close
125
for (j=i=0 ;yylval.string[i] != '\0'; i++,j++)
127
if (yylval.string[i] != '\\')
129
yylval.string[j] = yylval.string[i];
134
if (yylval.string[i] == '\0') /* XXX
140
"Unterminated character string");
143
yylval.string[j] = yylval.string[i];
146
yylval.string[j] = '\0';
153
loadmodule { return LOADMODULE; }
155
strcpy(yylval.string, yytext);
156
yylval.string[yyleng] = '\0';
160
\.\. { return TWODOTS; }
161
. { return yytext[0]; }
162
<<EOF>> { if (ieof()) yyterminate(); }
165
/* C-comment ignoring routine -kre*/
170
/* log(L_NOTICE, "got comment"); */
173
while ((c = input()) != '*' && c != EOF)
174
if (c == '\n') ++lineno;
177
while ((c = input()) == '*');
180
if (c == '\n') ++lineno;
184
YY_FATAL_ERROR("EOF in comment");
185
/* XXX hack alert this disables
186
* the stupid unused function warning
189
yy_fatal_error("EOF in comment");
198
if ((c = strchr(yytext, '<')) == NULL)
199
*strchr(c = strchr(yytext, '"') + 1, '"') = 0;
201
*strchr(++c, '>') = 0;
203
/* do stacking and co. */
204
if (include_stack_ptr >= MAX_INCLUDE_DEPTH)
205
conf_report_error("Includes nested too deep (max is %d)", MAX_INCLUDE_DEPTH);
210
tmp_fbfile_in = fopen(c, "r");
212
if (tmp_fbfile_in == NULL)
214
/* if its not found in PREFIX, look in ETCPATH */
215
char fnamebuf[IRCD_BUFSIZE];
217
snprintf(fnamebuf, sizeof(fnamebuf), "%s/%s", ETCPATH, c);
218
tmp_fbfile_in = fopen(fnamebuf, "r");
220
/* wasnt found there either.. error. */
221
if(tmp_fbfile_in == NULL)
223
conf_report_error("Include %s: %s.", c, strerror(errno));
227
lineno_stack[include_stack_ptr] = lineno;
229
inc_fbfile_in[include_stack_ptr] = conf_fbfile_in;
230
strcpy(conffile_stack[include_stack_ptr], c);
231
current_file = conffile_stack[include_stack_ptr];
232
include_stack[include_stack_ptr++] = YY_CURRENT_BUFFER;
233
conf_fbfile_in = tmp_fbfile_in;
234
yy_switch_to_buffer(yy_create_buffer(yyin, YY_BUF_SIZE));
240
if (include_stack_ptr)
241
fclose(conf_fbfile_in);
242
if (--include_stack_ptr < 0)
244
/* We will now exit the lexer - restore init values if we get /rehash
245
* later and reenter lexer -kre */
246
include_stack_ptr = 0;
251
yy_delete_buffer(YY_CURRENT_BUFFER);
252
lineno = lineno_stack[include_stack_ptr];
253
conf_fbfile_in = inc_fbfile_in[include_stack_ptr];
255
if(include_stack_ptr)
256
current_file = conffile_stack[include_stack_ptr];
258
current_file = conffilebuf;
260
yy_switch_to_buffer(include_stack[include_stack_ptr]);
264
/* #-comment style, look for #include */
265
#define INCLUDE "#include"
267
void hashcomment(void)
269
if (strlen(yytext) < sizeof(INCLUDE) - 1)
272
if (!strncasecmp(yytext, INCLUDE, sizeof(INCLUDE) - 1))
273
yyerror("You probably meant '.include', skipping");