1 /* This code is in the public domain.
2 * $Nightmare: nightmare/src/main/parser.y,v 1.2.2.1.2.1 2002/07/02 03:42:10 ejb Exp $
13 #define WE_ARE_MEMORY_C
17 #include "ircd_defs.h"
26 void yyerror(const char *);
29 static time_t conf_find_time(char*);
36 {"second", "seconds", 1},
37 {"minute", "minutes", 60},
38 {"hour", "hours", 60 * 60},
39 {"day", "days", 60 * 60 * 24},
40 {"week", "weeks", 60 * 60 * 24 * 7},
41 {"fortnight", "fortnights", 60 * 60 * 24 * 14},
42 {"month", "months", 60 * 60 * 24 * 7 * 4},
43 {"year", "years", 60 * 60 * 24 * 365},
44 /* ok-- we now do sizes here too. they aren't times, but
48 {"kbyte", "kbytes", 1024},
49 {"kilobyte", "kilebytes", 1024},
50 {"mb", NULL, 1024 * 1024},
51 {"mbyte", "mbytes", 1024 * 1024},
52 {"megabyte", "megabytes", 1024 * 1024},
56 time_t conf_find_time(char *name)
60 for (i = 0; ircd_times[i].name; i++)
62 if (strcasecmp(ircd_times[i].name, name) == 0 ||
63 (ircd_times[i].plural && strcasecmp(ircd_times[i].plural, name) == 0))
64 return ircd_times[i].val;
84 static int conf_get_yesno_value(char *str)
88 for (i = 0; yesno[i].word; i++)
90 if (strcasecmp(str, yesno[i].word) == 0)
92 return yesno[i].yesno;
99 static void free_cur_list(conf_parm_t* list)
101 if (list->type == CF_STRING || list->type == CF_QSTRING) {
102 rb_free(list->v.string);
103 } else if (list->type == CF_FLIST) {
104 /* Even though CF_FLIST is a flag, comparing with == is valid
105 * because conf_parm_t.type must be either a type or one flag.
107 free_cur_list(list->v.list);
111 free_cur_list(list->next);
118 conf_parm_t * cur_list = NULL;
120 static void add_cur_list_cpt(conf_parm_t *new)
122 if (cur_list == NULL)
124 cur_list = rb_malloc(sizeof(conf_parm_t));
125 cur_list->type = CF_FLIST;
126 cur_list->v.list = new;
130 new->next = cur_list->v.list;
131 cur_list->v.list = new;
135 static void add_cur_list(int type, char *str, int number)
139 new = rb_malloc(sizeof(conf_parm_t));
148 new->v.number = number;
152 new->v.string = rb_strdup(str);
156 add_cur_list_cpt(new);
164 char string[IRCD_BUFSIZE + 1];
165 conf_parm_t * conf_parm;
168 %token LOADMODULE TWODOTS
170 %token <string> QSTRING STRING
171 %token <number> NUMBER
173 %type <string> qstring string
174 %type <number> number timespec
175 %type <conf_parm> oneitem single itemlist
192 conf_start_block($1, NULL);
194 '{' block_items '}' ';'
197 conf_end_block(conf_cur_block);
201 conf_start_block($1, $2);
203 '{' block_items '}' ';'
206 conf_end_block(conf_cur_block);
210 block_items: block_items block_item
214 block_item: string '=' itemlist ';'
216 conf_call_set(conf_cur_block, $1, cur_list);
217 free_cur_list(cur_list);
222 itemlist: itemlist ',' single
228 add_cur_list_cpt($1);
230 | oneitem TWODOTS oneitem
232 /* "1 .. 5" meaning 1,2,3,4,5 - only valid for integers */
233 if ($1->type != CF_INT || $3->type != CF_INT)
235 conf_report_error("Both arguments in '..' notation must be integers.");
242 for (i = $1->v.number; i <= $3->v.number; i++)
244 add_cur_list(CF_INT, 0, i);
252 $$ = rb_malloc(sizeof(conf_parm_t));
253 $$->type = CF_QSTRING;
254 $$->v.string = rb_strdup($1);
258 $$ = rb_malloc(sizeof(conf_parm_t));
264 $$ = rb_malloc(sizeof(conf_parm_t));
270 /* a 'string' could also be a yes/no value ..
271 so pass it as that, if so */
272 int val = conf_get_yesno_value($1);
274 $$ = rb_malloc(sizeof(conf_parm_t));
283 $$->type = CF_STRING;
284 $$->v.string = rb_strdup($1);
293 m_bn = rb_basename((char *) $2);
295 if (findmodule_byname(m_bn) == -1)
297 load_one_module($2, MAPI_ORIGIN_EXTENSION, 0);
305 qstring: QSTRING { strcpy($$, $1); } ;
306 string: STRING { strcpy($$, $1); } ;
307 number: NUMBER { $$ = $1; } ;
309 timespec: number string
313 if ((t = conf_find_time($2)) == 0)
315 conf_report_error("Unrecognised time type/size '%s'", $2);