#include <stdarg.h>
#include "cond.tab.h"
-#include "brum.h"
-#define BUFSIZE 4096
+#include "umpf.h"
#define KLEN 10
struct keys {
{"if", KW_IF},
{"mail", KW_MAIL},
{"pipe", KW_PIPE},
- {"discard", KW_DISCARD}
+ {"discard", KW_DISCARD},
+ {"filter", KW_FILTER}
};
void
{
conf = fopen(filename, "r");
- if (! conf)
- die("read_conf: %m");
+ if (! conf) {
+ fprintf(stderr, "Error reading config file: %m\nSaving to default mailbox %s\n", default_mailbox);
+ longjmp(env, 1);
+ }
}
void __attribute__ ((noreturn))
fprintf(stderr, "Line %d: ", line);
vfprintf(stderr, msg, args);
fputc('\n', stderr);
+ fprintf(stderr, "Saving the email to default mailbox %s\n",
+ default_mailbox);
va_end(args);
- exit(1);
+ longjmp(env, 1);
}
char*
-xstrdup(char* s)
+xstrdup(const char* s)
{
void* ret;
static char*
get_string_out(int delim)
{
- int last = delim;
int i = 0;
int c;
char buf[BUFSIZE];
- while ((c = getc(conf)) != delim || last == '\\'){
- if (last=='\\' && c != delim)
- buf[i-1] = c;
- else {
- buf[i] = c;
- i++;
- }
- last = c;
+ while ((c = getc(conf)) != delim){
+ if (c == '\\') {
+ c = getc(conf);
+ if (c == EOF)
+ parse_err("Unbounded string, %c missing", delim);
+ buf[i++] = c;
+ } else if (c == '\n' || c == EOF)
+ parse_err("Unbounded string, %c missing", delim);
+ else
+ buf[i++] = c;
+
if (i >= BUFSIZE-1)
parse_err("Too long string, max allowed length is %d",BUFSIZE-1);
}
(c >= 'A' && c <= 'Z');
}
-int
-yylex(void)
+static int
+get_token_start(void)
{
int c;
-
- while ((c = getc(conf)) == ' ' || c == '\t' || c =='\n'){
- if (c == '\n')
+ int want_newline = 0;
+
+ for(;;) {
+ c = getc(conf);
+ if (c == EOF)
+ return c;
+ if (c == '#') {
+ want_newline = 1;
+ continue;
+ }
+ if (c == '\n') {
line++;
+ want_newline = 0;
+ continue;
+ }
+ if (c != '\n' && want_newline)
+ continue;
+ if (c != ' ' && c != '\t')
+ return c;
}
+}
+
+int
+yylex(void)
+{
+ int c;
+ c = get_token_start();
if (c == EOF)
return 0;
if (i >= BUFSIZE-1)
parse_err("Too long number");
}
- ungetc(c,conf);
+ if (c != EOF)
+ ungetc(c,conf);
buf[i] = 0;
yylval.str = xstrdup(buf);
if (i >= BUFSIZE-1)
parse_err("Too long identifier, max allowed length is %d",BUFSIZE-1);
}
- ungetc(c,conf);
+ if (!i)
+ parse_err("Variable identifier must not be empty");
+ if (c > 0)
+ ungetc(c,conf);
buf[i] = 0;
yylval.str = xstrdup(buf);
parse_err("Keyword too long");
}
buf[i] = 0;
- ungetc(c,conf);
+ if (c > 0)
+ ungetc(c,conf);
n = (sizeof(kwds)/sizeof(struct keys));
for (i = 0; i < n; i++){