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"
41 #include "ircd_parser.h"
45 #define MAX_INCLUDE_DEPTH 10
47 YY_BUFFER_STATE include_stack[MAX_INCLUDE_DEPTH];
48 int include_stack_ptr=0;
52 void hashcomment(void);
54 int lineno_stack[MAX_INCLUDE_DEPTH];
55 char conffile_stack[MAX_INCLUDE_DEPTH][BUFSIZE];
56 char conffilebuf[BUFSIZE+1];
57 char *current_file = conffilebuf;
59 FILE *inc_fbfile_in[MAX_INCLUDE_DEPTH];
65 #define YY_FATAL_ERROR(msg) conf_yy_fatal_error(msg)
67 #define YY_INPUT(buf,result,max_size) \
68 if (!(result = conf_fgets(buf, max_size, conf_fbfile_in))) \
69 YY_FATAL_ERROR("input in flex scanner failed");
75 qstring \"[^\"\n]*[\"\n]
76 string [a-zA-Z_\~\:][a-zA-Z0-9_\:]*
77 include \.include{ws}(\<.*\>|\".*\")
80 {include} { cinclude(); }
82 \n.* { strcpy(linebuf, yytext+1); lineno++; yyless(1); }
85 {comment} { hashcomment(); }
87 {digit}+ { yylval.number = atoi(yytext); return NUMBER; }
90 if(yytext[yyleng-2] == '\\')
92 yyless(yyleng-1); /* return last quote */
93 yymore(); /* append next string */
97 strcpy(yylval.string, yytext + 1);
98 if(yylval.string[yyleng-2] != '"')
99 ilog(L_MAIN, "Unterminated character string");
103 yylval.string[yyleng-2] = '\0'; /* remove close
107 for (j=i=0 ;yylval.string[i] != '\0'; i++,j++)
109 if (yylval.string[i] != '\\')
111 yylval.string[j] = yylval.string[i];
116 if (yylval.string[i] == '\0') /* XXX
122 "Unterminated character string");
125 yylval.string[j] = yylval.string[i];
128 yylval.string[j] = '\0';
135 loadmodule { return LOADMODULE; }
137 strcpy(yylval.string, yytext);
138 yylval.string[yyleng] = '\0';
142 \.\. { return TWODOTS; }
143 . { return yytext[0]; }
144 <<EOF>> { if (ieof()) yyterminate(); }
147 /* C-comment ignoring routine -kre*/
152 /* log(L_NOTICE, "got comment"); */
155 while ((c = input()) != '*' && c != EOF)
156 if (c == '\n') ++lineno;
159 while ((c = input()) == '*');
162 if (c == '\n') ++lineno;
166 YY_FATAL_ERROR("EOF in comment");
167 /* XXX hack alert this disables
168 * the stupid unused function warning
171 yy_fatal_error("EOF in comment");
180 if ((c = strchr(yytext, '<')) == NULL)
181 *strchr(c = strchr(yytext, '"') + 1, '"') = 0;
183 *strchr(++c, '>') = 0;
185 /* do stacking and co. */
186 if (include_stack_ptr >= MAX_INCLUDE_DEPTH)
187 conf_report_error("Includes nested too deep (max is %d)", MAX_INCLUDE_DEPTH);
192 tmp_fbfile_in = fopen(c, "r");
194 if (tmp_fbfile_in == NULL)
196 /* if its not found in PREFIX, look in IRCD_PATH_ETC */
197 char fnamebuf[BUFSIZE];
199 snprintf(fnamebuf, sizeof(fnamebuf), "%s%c%s", ircd_paths[IRCD_PATH_ETC], RB_PATH_SEPARATOR, c);
200 tmp_fbfile_in = fopen(fnamebuf, "r");
202 /* wasnt found there either.. error. */
203 if(tmp_fbfile_in == NULL)
205 conf_report_error("Include %s: %s.", c, strerror(errno));
209 lineno_stack[include_stack_ptr] = lineno;
211 inc_fbfile_in[include_stack_ptr] = conf_fbfile_in;
212 strcpy(conffile_stack[include_stack_ptr], c);
213 current_file = conffile_stack[include_stack_ptr];
214 include_stack[include_stack_ptr++] = YY_CURRENT_BUFFER;
215 conf_fbfile_in = tmp_fbfile_in;
216 yy_switch_to_buffer(yy_create_buffer(yyin, YY_BUF_SIZE));
222 if (include_stack_ptr)
223 fclose(conf_fbfile_in);
224 if (--include_stack_ptr < 0)
226 /* We will now exit the lexer - restore init values if we get /rehash
227 * later and reenter lexer -kre */
228 include_stack_ptr = 0;
233 yy_delete_buffer(YY_CURRENT_BUFFER);
234 lineno = lineno_stack[include_stack_ptr];
235 conf_fbfile_in = inc_fbfile_in[include_stack_ptr];
237 if(include_stack_ptr)
238 current_file = conffile_stack[include_stack_ptr];
240 current_file = conffilebuf;
242 yy_switch_to_buffer(include_stack[include_stack_ptr]);
246 /* #-comment style, look for #include */
247 #define INCLUDE "#include"
249 void hashcomment(void)
251 if (strlen(yytext) < sizeof(INCLUDE) - 1)
254 if (!rb_strncasecmp(yytext, INCLUDE, sizeof(INCLUDE) - 1))
255 yyerror("You probably meant '.include', skipping");