11 #define DEFAULT_CONF ".umpf"
16 list_init(&input_code);
17 var_hash = new_var_hash();
18 const_tab = xmalloc(BUFSIZE);
20 cur_const_s = BUFSIZE;
34 buf = xmalloc(BUFSIZE);
37 if (tmpbufpos >= tmpread) {
38 tmpread = read(fd, tmpbuf, BUFSIZE);
43 if (p >= (buf + buflen - 1))
44 buf = xrealloc(buf, buflen *= 2);
45 *p++ = tmpbuf[tmpbufpos++];
53 get_home_from_passwd(void)
56 pas = getpwuid(getuid());
58 die("Cannot get uid, please specify config file path");
60 char* login = pas->pw_name;
61 int len = strlen(pas->pw_name);
67 fd = open("/etc/passwd", O_RDONLY);
69 die("Cannot open /etc/passwd, please specify config file path");
73 r = strncmp(buf, login, len);
78 die("Cannot find your login %s in /etc/passwd, please specify config file path", login);
80 for (i = 0; i < 5; i++) {
83 die("Cannot parse /etc/passwd, please specify config file path");
86 while (*q && *q != '\n' && *q != ':')
90 return xstrdup(p + 1);
94 main(int argc, char** argv)
97 char* conffile = NULL;
99 while ((opt = getopt(argc, argv, "c:m:")) != -1) {
102 default_mailbox = optarg;
108 die("Usage: ./umpf [-c conf_file] [-m default_mailbox]");
112 if (!default_mailbox) {
115 p = getpwuid(getuid());
117 die("Cannot get uid, please specify default mailbox");
118 default_mailbox = cat("/var/mail/", p->pw_name);
124 /* returning from longjump? save the mail and exit */
132 home = getenv("HOME");
134 home = get_home_from_passwd();
138 conffile = xmalloc(strlen(home) + strlen(DEFAULT_CONF) + 1);
139 sprintf(conffile, "%s/%s", home, DEFAULT_CONF);
147 temp_varcode_start = current_varcode;
148 compile(input_tree, NULL);
151 var_tab = xmalloc((max_varcode + 1) * sizeof(struct vartab));
152 for (i = 0; i <= max_varcode; i++) {
153 var_tab[i].value = empty;
154 var_tab[i].modif = 0;
157 current_headers = make_hlist(0);
158 current_body = get_body(0);
159 save_current_headers(var_hash);
160 set_cur_mail_length_var(curr_email_len, var_hash);
162 interp(&input_code, var_hash);