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)
104 while ((c = getc(conf)) != delim){
108 parse_err("Unbounded string, %c missing", delim);
110 } else if (c == '\n' || c == EOF)
111 parse_err("Unbounded string, %c missing", delim);
116 parse_err("Too long string, max allowed length is %d",BUFSIZE-1);
126 return (c >= '0' && c <= '9' ) ||
127 (c >= 'a' && c <= 'z') ||
128 (c >= 'A' && c <= 'Z') ||
136 return (c >= 'a' && c <= 'z') ||
137 (c >= 'A' && c <= 'Z');
141 get_token_start(void)
144 int want_newline = 0;
159 if (c != '\n' && want_newline)
161 if (c != ' ' && c != '\t')
171 c = get_token_start();
178 case CC('!','='): yylval.n = CC('!','='); return NEQ;
179 case CC('!','~'): yylval.n = CC('!','='); return NRE;
180 case CC('<','='): yylval.n = CC('<','='); return LE;
181 case CC('>','='): yylval.n = CC('>','='); return GE;
182 case CC('=','='): yylval.n = CC('=','='); return EQ;
183 case CC('~','~'): yylval.n = CC('~','~'); return RE;
184 case CC('-','>'): yylval.n = CC('-','>'); return ARROW;
212 yylval.str = get_string_out(c);
216 if (c >= '0' && c <= '9'){
221 while ((c = getc(conf))>= '0' && c<= '9'){
225 parse_err("Too long number");
230 yylval.str = xstrdup(buf);
239 while (is_var_id(c = getc(conf))){
243 parse_err("Too long identifier, max allowed length is %d",BUFSIZE-1);
246 parse_err("Variable identifier must not be empty");
250 yylval.str = xstrdup(buf);
260 while (is_alpha(c = getc(conf))){
263 parse_err("Keyword too long");
269 n = (sizeof(kwds)/sizeof(struct keys));
270 for (i = 0; i < n; i++){
271 if (!strcmp(buf,kwds[i].keywords))
272 return kwds[i].keytoks;
275 parse_err("Unknown keyword %s", buf);
278 parse_err("Unknown character %c", c);