12 #define DEFAULT_CONF ".umpf"
17 signal(SIGPIPE, SIG_IGN);
18 list_init(&input_code);
19 var_hash = new_var_hash();
20 const_tab = xmalloc(BUFSIZE);
22 cur_const_s = BUFSIZE;
36 buf = xmalloc(BUFSIZE);
39 if (tmpbufpos >= tmpread) {
40 tmpread = read(fd, tmpbuf, BUFSIZE);
45 if (p >= (buf + buflen - 1))
46 buf = xrealloc(buf, buflen *= 2);
47 *p++ = tmpbuf[tmpbufpos++];
55 get_home_from_passwd(void)
58 pas = getpwuid(getuid());
60 die("Cannot get uid, please specify config file path");
62 char* login = pas->pw_name;
63 int len = strlen(pas->pw_name);
69 fd = open("/etc/passwd", O_RDONLY);
71 die("Cannot open /etc/passwd, please specify config file path");
75 r = strncmp(buf, login, len);
80 die("Cannot find your login %s in /etc/passwd, please specify config file path", login);
82 for (i = 0; i < 5; i++) {
85 die("Cannot parse /etc/passwd, please specify config file path");
88 while (*q && *q != '\n' && *q != ':')
92 return xstrdup(p + 1);
96 main(int argc, char** argv)
99 char* conffile = NULL;
102 while ((opt = getopt(argc, argv, "c:m:")) != -1) {
105 default_mailbox = optarg;
111 die("Usage: ./umpf [-c conf_file] [-m default_mailbox]");
115 if (!default_mailbox) {
118 p = getpwuid(getuid());
120 die("Cannot get uid, please specify default mailbox");
121 default_mailbox = cat("/var/mail/", p->pw_name);
126 /* returning from longjump? save the mail and exit */
134 home = getenv("HOME");
136 home = get_home_from_passwd();
140 conffile = xmalloc(strlen(home) + strlen(DEFAULT_CONF) + 1);
141 sprintf(conffile, "%s/%s", home, DEFAULT_CONF);
149 temp_varcode_start = current_varcode;
150 compile(input_tree, NULL);
153 var_tab = xmalloc((max_varcode + 1) * sizeof(struct vartab));
154 for (i = 0; i <= max_varcode; i++) {
155 var_tab[i].value = empty;
156 var_tab[i].modif = 0;
159 current_headers = make_hlist(0);
160 current_body = get_body(0);
161 save_current_headers(var_hash);
162 set_cur_mail_length_var(curr_email_len, var_hash);
164 interp(&input_code, var_hash);