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);
85 xstrdup(const char* s)
89 if (!(ret = strdup(s)))
96 get_string_out(int delim)
103 while ((c = getc(conf)) != delim || last == '\\'){
104 if (last=='\\' && c != delim)
112 parse_err("Too long string, max allowed length is %d",BUFSIZE-1);
122 return (c >= '0' && c <= '9' ) ||
123 (c >= 'a' && c <= 'z') ||
124 (c >= 'A' && c <= 'Z') ||
132 return (c >= 'a' && c <= 'z') ||
133 (c >= 'A' && c <= 'Z');
141 while ((c = getc(conf)) == ' ' || c == '\t' || c =='\n'){
152 case CC('!','='): yylval.n = CC('!','='); return NEQ;
153 case CC('!','~'): yylval.n = CC('!','='); return NRE;
154 case CC('<','='): yylval.n = CC('<','='); return LE;
155 case CC('>','='): yylval.n = CC('>','='); return GE;
156 case CC('=','='): yylval.n = CC('=','='); return EQ;
157 case CC('~','~'): yylval.n = CC('~','~'); return RE;
158 case CC('-','>'): yylval.n = CC('-','>'); return ARROW;
186 yylval.str = get_string_out(c);
190 if (c >= '0' && c <= '9'){
195 while ((c = getc(conf))>= '0' && c<= '9'){
199 parse_err("Too long number");
203 yylval.str = xstrdup(buf);
212 while (is_var_id(c = getc(conf))){
216 parse_err("Too long identifier, max allowed length is %d",BUFSIZE-1);
220 yylval.str = xstrdup(buf);
230 while (is_alpha(c = getc(conf))){
233 parse_err("Keyword too long");
238 n = (sizeof(kwds)/sizeof(struct keys));
239 for (i = 0; i < n; i++){
240 if (!strcmp(buf,kwds[i].keywords))
241 return kwds[i].keytoks;
244 parse_err("Unknown keyword %s", buf);
247 parse_err("Unknown character %c", c);