]> mj.ucw.cz Git - umpf.git/blob - umpf.c
fix modified flags
[umpf.git] / umpf.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include <pwd.h>
5 #include <getopt.h>
6
7 #include "umpf.h"
8
9 #define DEFAULT_CONF ".umpf"
10
11 void
12 init(void)
13 {
14         list_init(&input_code);
15         var_hash = new_var_hash();
16         const_tab = xmalloc(BUFSIZE);
17         cur_const_n = 1;
18         cur_const_s = BUFSIZE;
19         empty = "";
20 }
21
22 int
23 main(int argc, char** argv)
24 {
25         int res, i, opt;
26         char* conffile = NULL;
27         
28         while ((opt = getopt(argc, argv, "c:m:")) != -1) {
29                 switch (opt) {
30                 case 'm':
31                         default_mailbox = optarg;
32                         break;
33                 case 'c':
34                         conffile = optarg;
35                         break;
36                 default:
37                         die("Usage: ./umpf [-c conf_file] [-m default_mailbox]");
38                 }
39         }
40
41         if (!default_mailbox) {
42                 struct passwd* p;
43
44                 p = getpwuid(getuid());
45                 default_mailbox = cat("/var/mail/", p->pw_name);
46         }
47
48                 save_gids();
49         init();
50
51         /* returning from longjump? save the mail and exit */
52         if (setjmp(env))
53                 goto skip_conf;
54
55         if (! conffile) {
56                 int len;
57                 char* home; 
58
59                 home = getenv("HOME");
60                 if (! home)
61                         goto skip_conf;
62
63                 conffile = xmalloc(strlen(home) + strlen(DEFAULT_CONF) + 1);
64                 sprintf(conffile, "%s/%s", home, DEFAULT_CONF); 
65         }
66         read_conf(conffile);
67         res = yyparse ();
68
69         if (res)
70                 return res;
71
72         temp_varcode_start = current_varcode;
73         compile(input_tree, NULL);
74
75 skip_conf:
76         var_tab = xmalloc((max_varcode + 1) * sizeof(struct vartab));
77         for (i = 0; i <= max_varcode; i++) {
78                 var_tab[i].value = empty;
79                 var_tab[i].modif = 0;
80         }       
81
82         current_headers = make_hlist(0);
83         current_body = get_body(0);
84         save_current_headers(var_hash);
85         set_cur_mail_length_var(curr_email_len, var_hash);
86
87         interp(&input_code, var_hash);
88
89         return 0;
90 }