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
20 %option case-insensitive
25 #include <sys/types.h>
32 #define WE_ARE_MEMORY_C
35 #include "ircd_defs.h"
42 #include "ircd_parser.h"
46 #define MAX_INCLUDE_DEPTH 10
48 YY_BUFFER_STATE include_stack[MAX_INCLUDE_DEPTH];
49 int include_stack_ptr=0;
53 void hashcomment(void);
55 int lineno_stack[MAX_INCLUDE_DEPTH];
56 char conffile_stack[MAX_INCLUDE_DEPTH][IRCD_BUFSIZE];
57 char conffilebuf[IRCD_BUFSIZE+1];
58 char *current_file = conffilebuf;
60 FILE *inc_fbfile_in[MAX_INCLUDE_DEPTH];
66 #define YY_FATAL_ERROR(msg) conf_yy_fatal_error(msg)
68 #define YY_INPUT(buf,result,max_size) \
69 if (!(result = conf_fgets(buf, max_size, conf_fbfile_in))) \
70 YY_FATAL_ERROR("input in flex scanner failed");
76 qstring \"[^\"\n]*[\"\n]
77 string [a-zA-Z_\~\:][a-zA-Z0-9_\:]*
78 include \.include{ws}(\<.*\>|\".*\")
81 {include} { cinclude(); }
83 \n.* { strcpy(linebuf, yytext+1); lineno++; yyless(1); }
86 {comment} { hashcomment(); }
88 {digit}+ { yylval.number = atoi(yytext); return NUMBER; }
91 if(yytext[yyleng-2] == '\\')
93 yyless(yyleng-1); /* return last quote */
94 yymore(); /* append next string */
98 strcpy(yylval.string, yytext + 1);
99 if(yylval.string[yyleng-2] != '"')
100 ilog(L_MAIN, "Unterminated character string");
104 yylval.string[yyleng-2] = '\0'; /* remove close
108 for (j=i=0 ;yylval.string[i] != '\0'; i++,j++)
110 if (yylval.string[i] != '\\')
112 yylval.string[j] = yylval.string[i];
117 if (yylval.string[i] == '\0') /* XXX
123 "Unterminated character string");
126 yylval.string[j] = yylval.string[i];
129 yylval.string[j] = '\0';
136 loadmodule { return LOADMODULE; }
138 strcpy(yylval.string, yytext);
139 yylval.string[yyleng] = '\0';
143 \.\. { return TWODOTS; }
144 . { return yytext[0]; }
145 <<EOF>> { if (ieof()) yyterminate(); }
148 /* C-comment ignoring routine -kre*/
153 /* log(L_NOTICE, "got comment"); */
156 while ((c = input()) != '*' && c != EOF)
157 if (c == '\n') ++lineno;
160 while ((c = input()) == '*');
163 if (c == '\n') ++lineno;
167 YY_FATAL_ERROR("EOF in comment");
168 /* XXX hack alert this disables
169 * the stupid unused function warning
172 yy_fatal_error("EOF in comment");
181 if ((c = strchr(yytext, '<')) == NULL)
182 *strchr(c = strchr(yytext, '"') + 1, '"') = 0;
184 *strchr(++c, '>') = 0;
186 /* do stacking and co. */
187 if (include_stack_ptr >= MAX_INCLUDE_DEPTH)
188 conf_report_error("Includes nested too deep (max is %d)", MAX_INCLUDE_DEPTH);
193 tmp_fbfile_in = fopen(c, "r");
195 if (tmp_fbfile_in == NULL)
197 /* if its not found in PREFIX, look in ETCPATH */
198 char fnamebuf[IRCD_BUFSIZE];
200 snprintf(fnamebuf, sizeof(fnamebuf), "%s/%s", ETCPATH, c);
201 tmp_fbfile_in = fopen(fnamebuf, "r");
203 /* wasnt found there either.. error. */
204 if(tmp_fbfile_in == NULL)
206 conf_report_error("Include %s: %s.", c, strerror(errno));
210 lineno_stack[include_stack_ptr] = lineno;
212 inc_fbfile_in[include_stack_ptr] = conf_fbfile_in;
213 strcpy(conffile_stack[include_stack_ptr], c);
214 current_file = conffile_stack[include_stack_ptr];
215 include_stack[include_stack_ptr++] = YY_CURRENT_BUFFER;
216 conf_fbfile_in = tmp_fbfile_in;
217 yy_switch_to_buffer(yy_create_buffer(yyin, YY_BUF_SIZE));
223 if (include_stack_ptr)
224 fclose(conf_fbfile_in);
225 if (--include_stack_ptr < 0)
227 /* We will now exit the lexer - restore init values if we get /rehash
228 * later and reenter lexer -kre */
229 include_stack_ptr = 0;
234 yy_delete_buffer(YY_CURRENT_BUFFER);
235 lineno = lineno_stack[include_stack_ptr];
236 conf_fbfile_in = inc_fbfile_in[include_stack_ptr];
238 if(include_stack_ptr)
239 current_file = conffile_stack[include_stack_ptr];
241 current_file = conffilebuf;
243 yy_switch_to_buffer(include_stack[include_stack_ptr]);
247 /* #-comment style, look for #include */
248 #define INCLUDE "#include"
250 void hashcomment(void)
252 if (strlen(yytext) < sizeof(INCLUDE) - 1)
255 if (!strncasecmp(yytext, INCLUDE, sizeof(INCLUDE) - 1))
256 yyerror("You probably meant '.include', skipping");