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,
29 #include "ircd_string.h"
35 static struct lexer_token {
39 #define TOKEN(NAME) { #NAME, NAME }
100 { "administrator", ADMIN },
102 { "badchan", TPRIV_BADCHAN },
103 { "chan_limit", TPRIV_CHAN_LIMIT },
104 { "deop_lchan", TPRIV_DEOP_LCHAN },
105 { "die", TPRIV_DIE },
106 { "display", TPRIV_DISPLAY },
108 { "force_local_opmode", TPRIV_FORCE_LOCAL_OPMODE },
109 { "force_opmode", TPRIV_FORCE_OPMODE },
110 { "gline", TPRIV_GLINE },
112 { "kilobytes", KBYTES },
113 { "local_badchan", TPRIV_LOCAL_BADCHAN },
114 { "local_gline", TPRIV_LOCAL_GLINE },
115 { "local_jupe", TPRIV_LOCAL_JUPE },
116 { "local_kill", TPRIV_LOCAL_KILL },
118 { "megabytes", MBYTES },
119 { "mode_lchan", TPRIV_MODE_LCHAN },
121 { "gigabytes", GBYTES },
122 { "operator", OPER },
123 { "opmode", TPRIV_OPMODE },
124 { "password", PASS },
125 { "propagate", TPRIV_PROPAGATE },
126 { "realname", REAL },
127 { "rehash", TPRIV_REHASH },
128 { "restart", TPRIV_RESTART },
129 { "see_chan", TPRIV_SEE_CHAN },
130 { "see_opers", TPRIV_SEE_OPERS },
131 { "set", TPRIV_SET },
132 { "show_all_invis", TPRIV_SHOW_ALL_INVIS },
133 { "show_invis", TPRIV_SHOW_INVIS },
135 { "terabytes", TBYTES },
136 { "unlimit_query", TPRIV_UNLIMIT_QUERY },
137 { "walk_lchan", TPRIV_WALK_LCHAN },
138 { "wide_gline", TPRIV_WIDE_GLINE },
139 { "whox", TPRIV_WHOX },
145 token_compare(const void *pa, const void *pb)
147 const struct lexer_token *ta = pa;
148 const struct lexer_token *tb = pb;
151 while (ta->string[ii] && (ToLower(ta->string[ii]) == ToLower(tb->string[ii])))
153 res = ToLower(tb->string[ii]) - ToLower(ta->string[ii]);
160 for (ntokens = 0; tokens[ntokens].string; ++ntokens) ;
161 qsort(tokens, ntokens, sizeof(tokens[0]), token_compare);
165 find_token(char *token)
167 struct lexer_token *tok;
170 tok = bsearch(&token, tokens, ntokens, sizeof(tokens[0]), token_compare);
171 return tok ? tok->value : 0;
177 yyin = fopen(configfile, "r");
180 #ifdef YY_FATAL_ERROR
181 YY_FATAL_ERROR("Could not open the configuration file.");
183 fprintf(stderr, "Could not open the configuration file.");
197 QSTRING \"[^"\n]+[\"\n]
200 {QSTRING} {yytext[yyleng-1] = 0; yylval.text = yytext+1; return QSTRING;}
201 {NUMBER} {yylval.num = strtoul(yytext, NULL, 10); return NUMBER;}
205 [a-zA-Z_]+ { int res = find_token(yytext); if (res) return res; else REJECT; }