]> mj.ucw.cz Git - umpf.git/blobdiff - umpf.c
fix modified flags
[umpf.git] / umpf.c
diff --git a/umpf.c b/umpf.c
index bb8ca58f0fa002dcb08e62a7d3e5733b17e76316..5918a0db7dfdc5aaddb5c32222bf94d88362d254 100644 (file)
--- a/umpf.c
+++ b/umpf.c
@@ -1,43 +1,90 @@
 #include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
 #include <pwd.h>
+#include <getopt.h>
 
 #include "umpf.h"
 
+#define DEFAULT_CONF ".umpf"
+
+void
+init(void)
+{
+       list_init(&input_code);
+       var_hash = new_var_hash();
+       const_tab = xmalloc(BUFSIZE);
+       cur_const_n = 1;
+       cur_const_s = BUFSIZE;
+       empty = "";
+}
+
 int
 main(int argc, char** argv)
 {
-       int res;
+       int res, i, opt;
+       char* conffile = NULL;
        
-/*     //FIXME:
-       struct passwd* p;
-       p = getpwuid(getuid());
-       char* default_mbox = cat("/var/mail/", p->pw_name);
-       get_default_mailbox(default_mbox);
-*/
-       if (argc < 2)
-               die("Usage: ./umpf conf_file");
-
-       save_gids();
-       read_conf(argv[1]);
-
-//     yydebug=1;
+       while ((opt = getopt(argc, argv, "c:m:")) != -1) {
+               switch (opt) {
+               case 'm':
+                       default_mailbox = optarg;
+                       break;
+               case 'c':
+                       conffile = optarg;
+                       break;
+               default:
+                       die("Usage: ./umpf [-c conf_file] [-m default_mailbox]");
+               }
+       }
+
+       if (!default_mailbox) {
+               struct passwd* p;
+
+               p = getpwuid(getuid());
+               default_mailbox = cat("/var/mail/", p->pw_name);
+       }
+
+               save_gids();
+       init();
+
+       /* returning from longjump? save the mail and exit */
+       if (setjmp(env))
+               goto skip_conf;
+
+       if (! conffile) {
+               int len;
+               char* home; 
+
+               home = getenv("HOME");
+               if (! home)
+                       goto skip_conf;
+
+               conffile = xmalloc(strlen(home) + strlen(DEFAULT_CONF) + 1);
+               sprintf(conffile, "%s/%s", home, DEFAULT_CONF); 
+       }
+       read_conf(conffile);
        res = yyparse ();
 
        if (res)
                return res;
 
-       init();
-       compile(input_tree);
+       temp_varcode_start = current_varcode;
+       compile(input_tree, NULL);
+
+skip_conf:
+       var_tab = xmalloc((max_varcode + 1) * sizeof(struct vartab));
+       for (i = 0; i <= max_varcode; i++) {
+               var_tab[i].value = empty;
+               var_tab[i].modif = 0;
+       }       
 
-       print_code(input_tree);
+       current_headers = make_hlist(0);
+       current_body = get_body(0);
+       save_current_headers(var_hash);
+       set_cur_mail_length_var(curr_email_len, var_hash);
 
-//     var_hash = new_var_hash();
-//     current_headers = make_hlist();
-//     current_body = get_body();
-//     print_headers(current_headers);
-//     save_current_headers(var_hash);
-//     interp(input_tree, var_hash);
-//     print_vars(var_hash);
+       interp(&input_code, var_hash);
 
        return 0;
 }