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
16 #include "ircd_defs.h"
25 void yyerror(const char *);
28 static time_t conf_find_time(char*);
35 {"second", "seconds", 1},
36 {"minute", "minutes", 60},
37 {"hour", "hours", 60 * 60},
38 {"day", "days", 60 * 60 * 24},
39 {"week", "weeks", 60 * 60 * 24 * 7},
40 {"fortnight", "fortnights", 60 * 60 * 24 * 14},
41 {"month", "months", 60 * 60 * 24 * 7 * 4},
42 {"year", "years", 60 * 60 * 24 * 365},
43 /* ok-- we now do sizes here too. they aren't times, but
47 {"kbyte", "kbytes", 1024},
48 {"kilobyte", "kilebytes", 1024},
49 {"mb", NULL, 1024 * 1024},
50 {"mbyte", "mbytes", 1024 * 1024},
51 {"megabyte", "megabytes", 1024 * 1024},
55 time_t conf_find_time(char *name)
59 for (i = 0; ircd_times[i].name; i++)
61 if (strcasecmp(ircd_times[i].name, name) == 0 ||
62 (ircd_times[i].plural && strcasecmp(ircd_times[i].plural, name) == 0))
63 return ircd_times[i].val;
83 static int conf_get_yesno_value(char *str)
87 for (i = 0; yesno[i].word; i++)
89 if (strcasecmp(str, yesno[i].word) == 0)
91 return yesno[i].yesno;
98 static void free_cur_list(conf_parm_t* list)
100 if (list->type == CF_STRING || list->type == CF_QSTRING) {
101 rb_free(list->v.string);
102 } else if (list->type == CF_FLIST) {
103 /* Even though CF_FLIST is a flag, comparing with == is valid
104 * because conf_parm_t.type must be either a type or one flag.
106 free_cur_list(list->v.list);
110 free_cur_list(list->next);
117 conf_parm_t * cur_list = NULL;
119 static void add_cur_list_cpt(conf_parm_t *new)
121 if (cur_list == NULL)
123 cur_list = rb_malloc(sizeof(conf_parm_t));
124 cur_list->type = CF_FLIST;
125 cur_list->v.list = new;
129 new->next = cur_list->v.list;
130 cur_list->v.list = new;
134 static void add_cur_list(int type, char *str, int number)
138 new = rb_malloc(sizeof(conf_parm_t));
147 new->v.number = number;
151 new->v.string = rb_strdup(str);
155 add_cur_list_cpt(new);
163 char string[BUFSIZE + 1];
164 conf_parm_t * conf_parm;
167 %token LOADMODULE TWODOTS
169 %token <string> QSTRING STRING
170 %token <number> NUMBER
172 %type <string> qstring string
173 %type <number> number timespec
174 %type <conf_parm> oneitem single itemlist
191 conf_start_block($1, NULL);
193 '{' block_items '}' ';'
196 conf_end_block(conf_cur_block);
200 conf_start_block($1, $2);
202 '{' block_items '}' ';'
205 conf_end_block(conf_cur_block);
209 block_items: block_items block_item
213 block_item: string '=' itemlist ';'
215 conf_call_set(conf_cur_block, $1, cur_list);
216 free_cur_list(cur_list);
221 itemlist: itemlist ',' single
227 add_cur_list_cpt($1);
229 | oneitem TWODOTS oneitem
231 /* "1 .. 5" meaning 1,2,3,4,5 - only valid for integers */
232 if ($1->type != CF_INT || $3->type != CF_INT)
234 conf_report_error("Both arguments in '..' notation must be integers.");
241 for (i = $1->v.number; i <= $3->v.number; i++)
243 add_cur_list(CF_INT, 0, i);
251 $$ = rb_malloc(sizeof(conf_parm_t));
252 $$->type = CF_QSTRING;
253 $$->v.string = rb_strdup($1);
257 $$ = rb_malloc(sizeof(conf_parm_t));
263 $$ = rb_malloc(sizeof(conf_parm_t));
269 /* a 'string' could also be a yes/no value ..
270 so pass it as that, if so */
271 int val = conf_get_yesno_value($1);
273 $$ = rb_malloc(sizeof(conf_parm_t));
282 $$->type = CF_STRING;
283 $$->v.string = rb_strdup($1);
292 m_bn = rb_basename((char *) $2);
294 if (findmodule_byname(m_bn) == -1)
296 load_one_module($2, MAPI_ORIGIN_EXTENSION, 0);
304 qstring: QSTRING { strcpy($$, $1); } ;
305 string: STRING { strcpy($$, $1); } ;
306 number: NUMBER { $$ = $1; } ;
308 timespec: number string
312 if ((t = conf_find_time($2)) == 0)
314 conf_report_error("Unrecognised time type/size '%s'", $2);