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
19 %option case-insensitive
24 #include <sys/types.h>
27 #include <netinet/in.h>
33 #define WE_ARE_MEMORY_C
36 #include "ircd_defs.h"
47 /* here to fixup gcc 3.3 errors */
48 int yyget_lineno(void);
50 FILE *yyget_out(void);
52 char *yyget_text(void);
53 void yyset_lineno(int line_number);
54 void yyset_in(FILE * in_str);
55 void yyset_out(FILE * out_str);
56 int yyget_debug(void);
57 void yyset_debug(int bdebug);
58 int yylex_destroy(void);
61 #define MAX_INCLUDE_DEPTH 10
63 YY_BUFFER_STATE include_stack[MAX_INCLUDE_DEPTH];
64 int include_stack_ptr=0;
68 void hashcomment(void);
70 int lineno_stack[MAX_INCLUDE_DEPTH];
71 char conffile_stack[MAX_INCLUDE_DEPTH][IRCD_BUFSIZE];
72 char conffilebuf[IRCD_BUFSIZE+1];
73 char *current_file = conffilebuf;
75 FILE *inc_fbfile_in[MAX_INCLUDE_DEPTH];
81 #define YY_FATAL_ERROR(msg) conf_yy_fatal_error(msg)
83 #define YY_INPUT(buf,result,max_size) \
84 if (!(result = conf_fgets(buf, max_size, conf_fbfile_in))) \
85 YY_FATAL_ERROR("input in flex scanner failed");
91 qstring \"[^\"\n]*[\"\n]
92 string [a-zA-Z_\~][a-zA-Z0-9_]*
93 include \.include{ws}(\<.*\>|\".*\")
96 {include} { cinclude(); }
98 \n.* { strcpy(linebuf, yytext+1); lineno++; yyless(1); }
101 {comment} { hashcomment(); }
103 {digit}+ { yylval.number = atoi(yytext); return NUMBER; }
106 if(yytext[yyleng-2] == '\\')
108 yyless(yyleng-1); /* return last quote */
109 yymore(); /* append next string */
113 strcpy(yylval.string, yytext + 1);
114 if(yylval.string[yyleng-2] != '"')
115 ilog(L_MAIN, "Unterminated character string");
119 yylval.string[yyleng-2] = '\0'; /* remove close
123 for (j=i=0 ;yylval.string[i] != '\0'; i++,j++)
125 if (yylval.string[i] != '\\')
127 yylval.string[j] = yylval.string[i];
132 if (yylval.string[i] == '\0') /* XXX
138 "Unterminated character string");
141 yylval.string[j] = yylval.string[i];
144 yylval.string[j] = '\0';
151 loadmodule { return LOADMODULE; }
153 strcpy(yylval.string, yytext);
154 yylval.string[yyleng] = '\0';
158 \.\. { return TWODOTS; }
159 . { return yytext[0]; }
160 <<EOF>> { if (ieof()) yyterminate(); }
163 /* C-comment ignoring routine -kre*/
168 /* log(L_NOTICE, "got comment"); */
171 while ((c = input()) != '*' && c != EOF)
172 if (c == '\n') ++lineno;
175 while ((c = input()) == '*');
181 YY_FATAL_ERROR("EOF in comment");
182 /* XXX hack alert this disables
183 * the stupid unused function warning
186 yy_fatal_error("EOF in comment");
195 if ((c = strchr(yytext, '<')) == NULL)
196 *strchr(c = strchr(yytext, '"') + 1, '"') = 0;
198 *strchr(++c, '>') = 0;
200 /* do stacking and co. */
201 if (include_stack_ptr >= MAX_INCLUDE_DEPTH)
202 conf_report_error("Includes nested too deep (max is %d)", MAX_INCLUDE_DEPTH);
207 tmp_fbfile_in = fopen(c, "r");
209 if (tmp_fbfile_in == NULL)
211 /* if its not found in PREFIX, look in ETCPATH */
212 char fnamebuf[IRCD_BUFSIZE];
214 snprintf(fnamebuf, sizeof(fnamebuf), "%s/%s", ETCPATH, c);
215 tmp_fbfile_in = fopen(fnamebuf, "r");
217 /* wasnt found there either.. error. */
218 if(tmp_fbfile_in == NULL)
220 conf_report_error("Include %s: %s.", c, strerror(errno));
224 lineno_stack[include_stack_ptr] = lineno;
226 inc_fbfile_in[include_stack_ptr] = conf_fbfile_in;
227 strcpy(conffile_stack[include_stack_ptr], c);
228 current_file = conffile_stack[include_stack_ptr];
229 include_stack[include_stack_ptr++] = YY_CURRENT_BUFFER;
230 conf_fbfile_in = tmp_fbfile_in;
231 yy_switch_to_buffer(yy_create_buffer(yyin, YY_BUF_SIZE));
237 if (include_stack_ptr)
238 fclose(conf_fbfile_in);
239 if (--include_stack_ptr < 0)
241 /* We will now exit the lexer - restore init values if we get /rehash
242 * later and reenter lexer -kre */
243 include_stack_ptr = 0;
248 yy_delete_buffer(YY_CURRENT_BUFFER);
249 lineno = lineno_stack[include_stack_ptr];
250 conf_fbfile_in = inc_fbfile_in[include_stack_ptr];
252 if(include_stack_ptr)
253 current_file = conffile_stack[include_stack_ptr];
255 current_file = conffilebuf;
257 yy_switch_to_buffer(include_stack[include_stack_ptr]);
261 /* #-comment style, look for #include */
262 #define INCLUDE "#include"
264 void hashcomment(void)
266 if (strlen(yytext) < sizeof(INCLUDE) - 1)
269 if (!strncasecmp(yytext, INCLUDE, sizeof(INCLUDE) - 1))
270 yyerror("You probably meant '.include', skipping");