2 * ircd_lexer.l: A lexical scanner for ircd config files.
3 * This is part of ircu, an Internet Relay Chat server.
4 * The contents of this file are Copyright(C) 2001 by Andrew Miller, the
5 * ircd-hybrid team and the ircu team.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
20 * $Id: ircd_lexer.l 1851 2007-11-30 22:10:04Z klmitch $
31 #include "ircd_alloc.h"
32 #include "ircd_string.h"
38 static struct lexer_token {
42 #define TOKEN(NAME) { #NAME, NAME }
117 { "administrator", ADMIN },
118 { "apass_opmode", TPRIV_APASS_OPMODE },
119 { "auto", AUTOCONNECT },
121 { "badchan", TPRIV_BADCHAN },
122 { "chan_limit", TPRIV_CHAN_LIMIT },
123 { "deop_lchan", TPRIV_DEOP_LCHAN },
124 { "die", TPRIV_DIE },
125 { "display", TPRIV_DISPLAY },
127 { "force_local_opmode", TPRIV_FORCE_LOCAL_OPMODE },
128 { "force_opmode", TPRIV_FORCE_OPMODE },
130 { "gigabytes", GBYTES },
131 { "gline", TPRIV_GLINE },
132 #ifdef OLD_OGN_IRCU_COMPAT
133 { "hide_channels", TPRIV_UMODE_NOCHAN },
134 { "hide_idletime", TPRIV_UMODE_NOIDLE },
136 { "umode_nochan", TPRIV_UMODE_NOCHAN },
137 { "umode_noidle", TPRIV_UMODE_NOIDLE },
138 { "extra_hide_idletime", TPRIV_HIDE_IDLETIME },
139 #ifndef OLD_OGN_IRCU_COMPAT
140 { "hide_idletime", TPRIV_HIDE_IDLETIME },
142 { "ipv4", TOK_IPV4 },
143 { "ipv6", TOK_IPV6 },
145 { "kilobytes", KBYTES },
146 { "list_chan", TPRIV_LIST_CHAN },
147 { "local_badchan", TPRIV_LOCAL_BADCHAN },
148 { "local_gline", TPRIV_LOCAL_GLINE },
149 { "local_jupe", TPRIV_LOCAL_JUPE },
150 { "local_kill", TPRIV_LOCAL_KILL },
151 { "local_opmode", TPRIV_LOCAL_OPMODE },
152 { "maxchans", MAXCHANS },
154 { "megabytes", MBYTES },
155 { "mode_lchan", TPRIV_MODE_LCHAN },
156 { "more_flood", TPRIV_HALFFLOOD },
157 { "noamsg_override", TPRIV_NOAMSG_OVERRIDE },
158 { "operator", OPER },
159 { "opmode", TPRIV_OPMODE },
160 { "password", PASS },
161 { "propagate", TPRIV_PROPAGATE },
162 { "realname", REAL },
163 { "rehash", TPRIV_REHASH },
164 { "restart", TPRIV_RESTART },
165 { "see_chan", TPRIV_SEE_CHAN },
166 { "see_idletime", TPRIV_SEE_IDLETIME },
167 { "see_opers", TPRIV_SEE_OPERS },
168 { "set", TPRIV_SET },
169 { "show_all_invis", TPRIV_SHOW_ALL_INVIS },
170 { "show_invis", TPRIV_SHOW_INVIS },
171 #ifdef OLD_OGN_IRCU_COMPAT
172 { "targetchange", TPRIV_UNLIMITED_TARGET },
174 { "unlimited_targets", TPRIV_UNLIMITED_TARGET },
176 { "terabytes", TBYTES },
177 { "umode_chserv", TPRIV_UMODE_CHSERV },
178 { "umode_xtraop", TPRIV_UMODE_XTRAOP },
179 { "umode_netserv", TPRIV_UMODE_NETSERV },
180 { "umode_overridecc", TPRIV_UMODE_OVERRIDECC },
181 { "unlimit_query", TPRIV_UNLIMIT_QUERY },
182 { "unlimited_flood", TPRIV_FLOOD },
183 { "walk_lchan", TPRIV_WALK_LCHAN },
184 { "wide_gline", TPRIV_WIDE_GLINE },
185 { "whox", TPRIV_WHOX },
191 token_compare(const void *pa, const void *pb)
193 const struct lexer_token *ta = pa;
194 const struct lexer_token *tb = pb;
197 while (ta->string[ii] && (ToLower(ta->string[ii]) == ToLower(tb->string[ii])))
199 res = ToLower(tb->string[ii]) - ToLower(ta->string[ii]);
206 for (ntokens = 0; tokens[ntokens].string; ++ntokens) ;
207 qsort(tokens, ntokens, sizeof(tokens[0]), token_compare);
211 find_token(char *token)
213 struct lexer_token *tok;
216 tok = bsearch(&token, tokens, ntokens, sizeof(tokens[0]), token_compare);
217 return tok ? tok->value : 0;
220 static FBFILE *lexer_input;
223 #define YY_INPUT(buf, res, size) res = (fbgets(buf, size, lexer_input) ? strlen(buf) : 0)
228 lexer_input = fbopen(configfile, "r");
229 if (lexer_input == NULL)
231 #ifdef YY_FATAL_ERROR
232 YY_FATAL_ERROR("Could not open the configuration file.");
234 fprintf(stderr, "Could not open the configuration file.");
245 void deinit_lexer(void)
247 if (lexer_input != NULL)
249 fbclose(lexer_input);
265 QSTRING \"[^"\n]+[\"\n]
268 {QSTRING} {yytext[yyleng-1] = 0; DupString(yylval.text, yytext+1); return QSTRING;}
269 {NUMBER} {yylval.num = strtoul(yytext, NULL, 10); return NUMBER;}
273 [a-zA-Z_][a-zA-Z_0-9]* { int res = find_token(yytext); if (res) return res; else REJECT; }