13 enum yytokentype keytoks;
16 static struct keys kwds[] =
22 {"discard", KW_DISCARD},
27 read_conf(char* filename)
29 conf = fopen(filename, "r");
32 fprintf(stderr, "Error reading config file: %m\nSaving to default mailbox %s\n", default_mailbox);
37 void __attribute__ ((noreturn))
43 vfprintf(stderr, msg, args);
54 if (!(ret = malloc(size)))
61 xrealloc(void* buf, size_t size)
63 buf = realloc(buf, size);
71 static void __attribute__ ((noreturn))
72 parse_err(char* msg, ...)
77 fprintf(stderr, "Line %d: ", line);
78 vfprintf(stderr, msg, args);
80 fprintf(stderr, "Saving the email to default mailbox %s\n",
87 xstrdup(const char* s)
91 if (!(ret = strdup(s)))
98 get_string_out(int delim)
105 while ((c = getc(conf)) != delim || last == '\\'){
106 if (last=='\\' && c != delim)
114 parse_err("Too long string, max allowed length is %d",BUFSIZE-1);
124 return (c >= '0' && c <= '9' ) ||
125 (c >= 'a' && c <= 'z') ||
126 (c >= 'A' && c <= 'Z') ||
134 return (c >= 'a' && c <= 'z') ||
135 (c >= 'A' && c <= 'Z');
139 get_token_start(void)
142 int want_newline = 0;
157 if (c != '\n' && want_newline)
159 if (c != ' ' && c != '\t')
169 c = get_token_start();
176 case CC('!','='): yylval.n = CC('!','='); return NEQ;
177 case CC('!','~'): yylval.n = CC('!','='); return NRE;
178 case CC('<','='): yylval.n = CC('<','='); return LE;
179 case CC('>','='): yylval.n = CC('>','='); return GE;
180 case CC('=','='): yylval.n = CC('=','='); return EQ;
181 case CC('~','~'): yylval.n = CC('~','~'); return RE;
182 case CC('-','>'): yylval.n = CC('-','>'); return ARROW;
210 yylval.str = get_string_out(c);
214 if (c >= '0' && c <= '9'){
219 while ((c = getc(conf))>= '0' && c<= '9'){
223 parse_err("Too long number");
227 yylval.str = xstrdup(buf);
236 while (is_var_id(c = getc(conf))){
240 parse_err("Too long identifier, max allowed length is %d",BUFSIZE-1);
244 yylval.str = xstrdup(buf);
254 while (is_alpha(c = getc(conf))){
257 parse_err("Keyword too long");
262 n = (sizeof(kwds)/sizeof(struct keys));
263 for (i = 0; i < n; i++){
264 if (!strcmp(buf,kwds[i].keywords))
265 return kwds[i].keytoks;
268 parse_err("Unknown keyword %s", buf);
271 parse_err("Unknown character %c", c);