]> mj.ucw.cz Git - umpf.git/blob - umpf.c
do not die on syntax errors, save email to default mailbox instead
[umpf.git] / umpf.c
1 #include <stdio.h>
2 #include <string.h>
3 #include <pwd.h>
4
5 #include "umpf.h"
6
7 void
8 init(void)
9 {
10         list_init(&input_code);
11         var_hash = new_var_hash();
12         const_tab = xmalloc(BUFSIZE);
13         cur_const_n = 1;
14         cur_const_s = BUFSIZE;
15         empty = "";
16 }
17
18 int
19 main(int argc, char** argv)
20 {
21         int res;
22         int i;
23         
24         if (argc < 2)
25                 die("Usage: ./umpf conf_file [default_mailbox]");
26
27         struct passwd* p;
28         p = getpwuid(getuid());
29         if (argc < 3)
30                  default_mailbox = cat("/var/mail/", p->pw_name);
31         else
32                  default_mailbox = argv[2];
33
34         save_gids();
35
36         init();
37
38         /* returning from longjump? save the mail and exit */
39         if (setjmp(env))
40                 goto skip_conf;
41
42         read_conf(argv[1]);
43         res = yyparse ();
44
45         if (res)
46                 return res;
47
48         temp_varcode_start = current_varcode;
49         compile(input_tree, NULL);
50
51 skip_conf:
52         var_tab = xmalloc((max_varcode + 1) * sizeof(char*));
53         for (i = 0; i <= max_varcode; i++) {
54                 var_tab[i] = empty;
55         }       
56
57         current_headers = make_hlist(0);
58         current_body = get_body(0);
59         save_current_headers(var_hash);
60         set_cur_mail_length_var(curr_email_len, var_hash);
61
62         interp(&input_code, var_hash);
63
64         return 0;
65 }