Commit d45791ef d45791efa25233eed9c2837593f4e9428253cab3 by Sergey Poznyakoff

Use util_getenv()

1 parent 92d14adf
...@@ -77,7 +77,7 @@ mail_set_my_name (char *name) ...@@ -77,7 +77,7 @@ mail_set_my_name (char *name)
77 int 77 int
78 mail_is_my_name (char *name) 78 mail_is_my_name (char *name)
79 { 79 {
80 if (util_find_env("metoo")->set) 80 if (util_getenv (NULL, "metoo", Mail_env_boolean, 0) == 0)
81 return 0; 81 return 0;
82 if (strchr(name, '@') == NULL && strcasecmp (name, my_name) == 0) 82 if (strchr(name, '@') == NULL && strcasecmp (name, my_name) == 0)
83 return 1; 83 return 1;
......
...@@ -62,7 +62,8 @@ display_message (message_t mesg, msgset_t *msgset, void *arg) ...@@ -62,7 +62,8 @@ display_message (message_t mesg, msgset_t *msgset, void *arg)
62 return 1; 62 return 1;
63 63
64 message_lines (mesg, &lines); 64 message_lines (mesg, &lines);
65 if ((util_find_env("crt"))->set && (int)lines > util_getlines ()) 65 if (util_getenv (NULL, "crt", Mail_env_boolean, 0) == 0
66 && (int)lines > util_getlines ())
66 out = popen (getenv("PAGER"), "w"); 67 out = popen (getenv("PAGER"), "w");
67 else 68 else
68 out = ofile; 69 out = ofile;
......
...@@ -64,7 +64,7 @@ mail_delete (int argc, char **argv) ...@@ -64,7 +64,7 @@ mail_delete (int argc, char **argv)
64 cursor = realcursor; 64 cursor = realcursor;
65 } 65 }
66 66
67 if (util_find_env("autoprint")->set) 67 if (util_getenv (NULL, "autoprint", Mail_env_boolean, 0) == 0)
68 util_do_command("print"); 68 util_do_command("print");
69 69
70 return rc; 70 return rc;
......
...@@ -25,17 +25,12 @@ int ...@@ -25,17 +25,12 @@ int
25 mail_folders (int argc, char **argv) 25 mail_folders (int argc, char **argv)
26 { 26 {
27 char *path; 27 char *path;
28 struct mail_env_entry *env = util_find_env ("folder");
29 28
30 (void)argc; (void)argv; 29 (void)argc; (void)argv;
31 30
32 if (!env->set) 31 if (util_getenv (&path, "folder", Mail_env_string, 1))
33 { 32 return 1;
34 util_error ("No value set for \"folder\"");
35 return 1;
36 }
37 33
38 path = env->value;
39 if (path[0] != '/' && path[0] != '~') 34 if (path[0] != '/' && path[0] != '~')
40 { 35 {
41 char *tmp = alloca (strlen (path) + 3); 36 char *tmp = alloca (strlen (path) + 3);
......
...@@ -80,7 +80,7 @@ _cond_pop() ...@@ -80,7 +80,7 @@ _cond_pop()
80 int 80 int
81 mail_if (int argc, char **argv) 81 mail_if (int argc, char **argv)
82 { 82 {
83 struct mail_env_entry *mode; 83 char *mode;
84 int cond; 84 int cond;
85 85
86 if (argc != 2) 86 if (argc != 2)
...@@ -95,11 +95,8 @@ mail_if (int argc, char **argv) ...@@ -95,11 +95,8 @@ mail_if (int argc, char **argv)
95 return 1; 95 return 1;
96 } 96 }
97 97
98 mode = util_find_env("mode"); 98 if (util_getenv (&mode, "mode", Mail_env_string, 1))
99 if (!mode) 99 exit (EXIT_FAILURE);
100 {
101 exit (EXIT_FAILURE);
102 }
103 100
104 if (if_cond() == 0) 101 if (if_cond() == 0)
105 /* Propagate negative condition */ 102 /* Propagate negative condition */
...@@ -109,10 +106,10 @@ mail_if (int argc, char **argv) ...@@ -109,10 +106,10 @@ mail_if (int argc, char **argv)
109 switch (argv[1][0]) 106 switch (argv[1][0])
110 { 107 {
111 case 's': /* Send mode */ 108 case 's': /* Send mode */
112 cond = strcmp(mode->value, "send") == 0; 109 cond = strcmp(mode, "send") == 0;
113 break; 110 break;
114 case 'r': /* Read mode */ 111 case 'r': /* Read mode */
115 cond = strcmp(mode->value, "send") != 0; 112 cond = strcmp(mode, "send") != 0;
116 break; 113 break;
117 case 't': /* Reading from a terminal */ 114 case 't': /* Reading from a terminal */
118 cond = interactive; 115 cond = interactive;
......
...@@ -504,7 +504,7 @@ select_header (message_t msg, void *closure) ...@@ -504,7 +504,7 @@ select_header (message_t msg, void *closure)
504 message_get_header (msg, &hdr); 504 message_get_header (msg, &hdr);
505 if (header_aget_value (hdr, header, &contents) == 0) 505 if (header_aget_value (hdr, header, &contents) == 0)
506 { 506 {
507 if (!(util_find_env ("noregex"))->set) 507 if (util_getenv (NULL, "regex", Mail_env_boolean, 0) == 0)
508 { 508 {
509 /* Match string against the extended regular expression(ignoring 509 /* Match string against the extended regular expression(ignoring
510 case) in pattern, treating errors as no match. 510 case) in pattern, treating errors as no match.
...@@ -542,7 +542,7 @@ int ...@@ -542,7 +542,7 @@ int
542 select_body (message_t msg, void *closure) 542 select_body (message_t msg, void *closure)
543 { 543 {
544 char *expr = closure; 544 char *expr = closure;
545 int noregex = util_find_env ("noregex")->set; 545 int noregex = util_getenv (NULL, "regex", Mail_env_boolean, 0);
546 regex_t re; 546 regex_t re;
547 int status; 547 int status;
548 body_t body = NULL; 548 body_t body = NULL;
......
...@@ -36,9 +36,7 @@ mail_pipe (int argc, char **argv) ...@@ -36,9 +36,7 @@ mail_pipe (int argc, char **argv)
36 36
37 if (argc > 1) 37 if (argc > 1)
38 cmd = argv[--argc]; 38 cmd = argv[--argc];
39 else if ((util_find_env ("cmd"))->set) 39 else if (util_getenv (&cmd, "cmd", Mail_env_boolean, 1))
40 cmd = (util_find_env ("cmd"))->value;
41 else
42 return 1; 40 return 1;
43 41
44 if (msgset_parse (argc, argv, &list)) 42 if (msgset_parse (argc, argv, &list))
...@@ -59,7 +57,7 @@ mail_pipe (int argc, char **argv) ...@@ -59,7 +57,7 @@ mail_pipe (int argc, char **argv)
59 fprintf (tube, "%s", buffer); 57 fprintf (tube, "%s", buffer);
60 off += n; 58 off += n;
61 } 59 }
62 if ((util_find_env("page"))->set && mp->next) 60 if (util_getenv (NULL, "page", Mail_env_boolean, 0) == 0)
63 fprintf (tube, "\f\n"); 61 fprintf (tube, "\f\n");
64 } 62 }
65 } 63 }
......
...@@ -52,7 +52,7 @@ mail_print (int argc, char **argv) ...@@ -52,7 +52,7 @@ mail_print (int argc, char **argv)
52 to be smart about it. */ 52 to be smart about it. */
53 if (lines == 0) 53 if (lines == 0)
54 { 54 {
55 if ((util_find_env("crt"))->set) 55 if (util_getenv (NULL, "crt", Mail_env_boolean, 0) == 0)
56 { 56 {
57 size_t col = (size_t)util_getcols (); 57 size_t col = (size_t)util_getcols ();
58 if (col) 58 if (col)
...@@ -64,8 +64,9 @@ mail_print (int argc, char **argv) ...@@ -64,8 +64,9 @@ mail_print (int argc, char **argv)
64 } 64 }
65 } 65 }
66 66
67 if ((util_find_env("crt"))->set && lines > (size_t)util_getlines ()) 67 if (util_getenv (NULL, "crt", Mail_env_boolean, 0) == 0
68 out = popen (getenv("PAGER"), "w"); 68 && lines > (size_t)util_getlines ())
69 out = popen (getenv ("PAGER"), "w");
69 70
70 if (islower (argv[0][0])) 71 if (islower (argv[0][0]))
71 { 72 {
......
...@@ -37,7 +37,7 @@ mail_mbox_close () ...@@ -37,7 +37,7 @@ mail_mbox_close ()
37 url_t url = NULL; 37 url_t url = NULL;
38 size_t held_count; 38 size_t held_count;
39 39
40 if (!util_find_env ("readonly")->set) 40 if (util_getenv (NULL, "readonly", Mail_env_boolean, 0))
41 { 41 {
42 if (mail_mbox_commit ()) 42 if (mail_mbox_commit ())
43 return 1; 43 return 1;
...@@ -62,8 +62,8 @@ mail_mbox_commit () ...@@ -62,8 +62,8 @@ mail_mbox_commit ()
62 int saved_count = 0; 62 int saved_count = 0;
63 message_t msg; 63 message_t msg;
64 attribute_t attr; 64 attribute_t attr;
65 int keepsave = util_find_env("keepsave")->set; 65 int keepsave = util_getenv (NULL, "keepsave", Mail_env_boolean, 0) == 0;
66 int hold = util_find_env ("hold")->set; 66 int hold = util_getenv (NULL, "hold", Mail_env_boolean, 0) == 0;
67 url_t url; 67 url_t url;
68 int is_user_mbox; 68 int is_user_mbox;
69 69
......
...@@ -74,15 +74,18 @@ mail_send (int argc, char **argv) ...@@ -74,15 +74,18 @@ mail_send (int argc, char **argv)
74 } 74 }
75 } 75 }
76 76
77 if ((util_find_env ("askcc"))->set) 77 if (util_getenv (NULL, "askcc", Mail_env_boolean, 0) == 0)
78 env.cc = ml_readline ((char *)"Cc: "); 78 env.cc = ml_readline ((char *)"Cc: ");
79 if ((util_find_env ("askbcc"))->set) 79 if (util_getenv (NULL, "askbcc", Mail_env_boolean, 0) == 0)
80 env.bcc = ml_readline ((char *)"Bcc: "); 80 env.bcc = ml_readline ((char *)"Bcc: ");
81 81
82 if ((util_find_env ("asksub"))->set) 82 if (util_getenv (NULL, "asksub", Mail_env_boolean, 0) == 0)
83 env.subj = ml_readline ((char *)"Subject: "); 83 env.subj = ml_readline ((char *)"Subject: ");
84 else 84 else
85 env.subj = (util_find_env ("subject"))->value; 85 {
86 env.subj = NULL;
87 util_getenv (&env.subj, "subject", Mail_env_string, 0);
88 }
86 89
87 status = mail_send0 (&env, isupper(argv[0][0])); 90 status = mail_send0 (&env, isupper(argv[0][0]));
88 free_env_headers (&env); 91 free_env_headers (&env);
...@@ -135,6 +138,7 @@ mail_send0 (struct send_environ *env, int save_to) ...@@ -135,6 +138,7 @@ mail_send0 (struct send_environ *env, int save_to)
135 FILE *file; 138 FILE *file;
136 char *savefile = NULL; 139 char *savefile = NULL;
137 int int_cnt; 140 int int_cnt;
141 char *escape;
138 142
139 fd = mu_tempfile (NULL, &filename); 143 fd = mu_tempfile (NULL, &filename);
140 144
...@@ -159,7 +163,7 @@ mail_send0 (struct send_environ *env, int save_to) ...@@ -159,7 +163,7 @@ mail_send0 (struct send_environ *env, int save_to)
159 163
160 if (ml_got_interrupt ()) 164 if (ml_got_interrupt ())
161 { 165 {
162 if (util_find_env ("ignore")->set) 166 if (util_getenv (NULL, "ignore", Mail_env_boolean, 0) == 0)
163 { 167 {
164 fprintf (stdout, "@\n"); 168 fprintf (stdout, "@\n");
165 } 169 }
...@@ -176,9 +180,9 @@ mail_send0 (struct send_environ *env, int save_to) ...@@ -176,9 +180,9 @@ mail_send0 (struct send_environ *env, int save_to)
176 180
177 if (!buf) 181 if (!buf)
178 { 182 {
179 if (util_find_env ("ignoreeof")->set) 183 if (util_getenv (NULL, "ignore", Mail_env_boolean, 0) == 0)
180 { 184 {
181 util_error (util_find_env ("dot")->set ? 185 util_error (util_getenv (NULL, "dot", Mail_env_boolean, 0) == 0 ?
182 "Use \".\" to terminate letter." : 186 "Use \".\" to terminate letter." :
183 "Use \"~.\" to terminate letter."); 187 "Use \"~.\" to terminate letter.");
184 continue; 188 continue;
...@@ -189,9 +193,10 @@ mail_send0 (struct send_environ *env, int save_to) ...@@ -189,9 +193,10 @@ mail_send0 (struct send_environ *env, int save_to)
189 193
190 int_cnt = 0; 194 int_cnt = 0;
191 195
192 if (buf[0] == '.' && util_find_env ("dot")->set) 196 if (buf[0] == '.' && util_getenv (NULL, "dot", Mail_env_boolean, 0) == 0)
193 done = 1; 197 done = 1;
194 else if (buf[0] == (util_find_env ("escape"))->value[0]) 198 else if (util_getenv (&escape, "escape", Mail_env_string, 0) == 0
199 && buf[0] == escape[0])
195 { 200 {
196 if (buf[1] == buf[0]) 201 if (buf[1] == buf[0])
197 fprintf (env->file, "%s\n", buf+1); 202 fprintf (env->file, "%s\n", buf+1);
...@@ -240,10 +245,11 @@ mail_send0 (struct send_environ *env, int save_to) ...@@ -240,10 +245,11 @@ mail_send0 (struct send_environ *env, int save_to)
240 /* If interrupted dumpt the file to dead.letter. */ 245 /* If interrupted dumpt the file to dead.letter. */
241 if (int_cnt) 246 if (int_cnt)
242 { 247 {
243 if (util_find_env ("save")->set) 248 if (util_getenv (NULL, "save", Mail_env_boolean, 0) == 0)
244 { 249 {
245 FILE *fp = fopen (getenv ("DEAD"), 250 FILE *fp = fopen (getenv ("DEAD"),
246 util_find_env ("appenddeadletter")->set ? 251 util_getenv (NULL, "appenddeadletter",
252 Mail_env_boolean, 0) == 0 ?
247 "a" : "w"); 253 "a" : "w");
248 254
249 if (!fp) 255 if (!fp)
...@@ -369,13 +375,13 @@ mail_send0 (struct send_environ *env, int save_to) ...@@ -369,13 +375,13 @@ mail_send0 (struct send_environ *env, int save_to)
369 || (env->cc && *env->cc != '\0') 375 || (env->cc && *env->cc != '\0')
370 || (env->bcc && *env->bcc != '\0')) 376 || (env->bcc && *env->bcc != '\0'))
371 { 377 {
372 if (util_find_env ("sendmail")->set) 378 char *sendmail;
379 if (util_getenv (&sendmail, "sendmail", Mail_env_string, 0) == 0)
373 { 380 {
374 char *sendmail = util_find_env ("sendmail")->value;
375 int status = mailer_create (&mailer, sendmail); 381 int status = mailer_create (&mailer, sendmail);
376 if (status == 0) 382 if (status == 0)
377 { 383 {
378 if (util_find_env ("verbose")->set) 384 if (util_getenv (NULL, "verbose", Mail_env_boolean, 0) == 0)
379 { 385 {
380 mu_debug_t debug = NULL; 386 mu_debug_t debug = NULL;
381 mailer_get_debug (mailer, &debug); 387 mailer_get_debug (mailer, &debug);
......
...@@ -33,9 +33,10 @@ mail_top (int argc, char **argv) ...@@ -33,9 +33,10 @@ mail_top (int argc, char **argv)
33 char buf[512]; 33 char buf[512];
34 size_t n; 34 size_t n;
35 off_t off; 35 off_t off;
36 int lines = strtol ((util_find_env("toplines"))->value, NULL, 10); 36 int lines;
37 37
38 if (lines < 0) 38 if (util_getenv (&lines, "toplines", Mail_env_number, 1)
39 || lines < 0)
39 return 1; 40 return 1;
40 41
41 if (mailbox_get_message (mbox, cursor, &msg) != 0) 42 if (mailbox_get_message (mbox, cursor, &msg) != 0)
......
...@@ -30,8 +30,9 @@ static int var_check_args (int argc, char **argv) ...@@ -30,8 +30,9 @@ static int var_check_args (int argc, char **argv)
30 { 30 {
31 if (argc == 1) 31 if (argc == 1)
32 { 32 {
33 util_error ("%c%s requires an argument", 33 char *escape = "~";
34 util_find_env ("escape")->value[0], argv[0]); 34 util_getenv (&escape, "escape", Mail_env_string, 0);
35 util_error ("%c%s requires an argument", escape[0], argv[0]);
35 return 1; 36 return 1;
36 } 37 }
37 return 0; 38 return 0;
...@@ -102,19 +103,16 @@ var_help(int argc, char **argv, struct send_environ *env) ...@@ -102,19 +103,16 @@ var_help(int argc, char **argv, struct send_environ *env)
102 int 103 int
103 var_sign(int argc, char **argv, struct send_environ *env) 104 var_sign(int argc, char **argv, struct send_environ *env)
104 { 105 {
105 struct mail_env_entry *p; 106 char *p;
106 107
107 (void)argc; (void)env; 108 (void)argc; (void)env;
108 109
109 if (isupper(argv[0][0])) 110 if (util_getenv (&p, isupper (argv[0][0]) ? "Sign" : "sign",
110 p = util_find_env("Sign"); 111 Mail_env_string, 1) == 0)
111 else
112 p = util_find_env("sign");
113 if (p->set)
114 { 112 {
115 if (isupper(argv[0][0])) 113 if (isupper (argv[0][0]))
116 { 114 {
117 char *name = util_fullpath(p->value); 115 char *name = util_fullpath (p);
118 FILE *fp = fopen(name, "r"); 116 FILE *fp = fopen(name, "r");
119 char *buf = NULL; 117 char *buf = NULL;
120 size_t n = 0; 118 size_t n = 0;
...@@ -134,11 +132,9 @@ var_sign(int argc, char **argv, struct send_environ *env) ...@@ -134,11 +132,9 @@ var_sign(int argc, char **argv, struct send_environ *env)
134 free(name); 132 free(name);
135 } 133 }
136 else 134 else
137 fprintf(ofile, "%s", p->value); 135 fprintf(ofile, "%s", p);
138 var_continue(); 136 var_continue();
139 } 137 }
140 else
141 util_error("\"sign\" not set");
142 return 0; 138 return 0;
143 } 139 }
144 140
...@@ -232,12 +228,32 @@ var_headers(int argc, char **argv, struct send_environ *env) ...@@ -232,12 +228,32 @@ var_headers(int argc, char **argv, struct send_environ *env)
232 228
233 /* ~i[var-name] */ 229 /* ~i[var-name] */
234 int 230 int
235 var_insert(int argc, char **argv, struct send_environ *env) 231 var_insert (int argc, char **argv, struct send_environ *env)
236 { 232 {
233 struct mail_env_entry *env;
234
237 (void)env; 235 (void)env;
238 if (var_check_args (argc, argv)) 236 if (var_check_args (argc, argv))
239 return 1; 237 return 1;
240 fprintf(ofile, "%s", util_find_env(argv[1])->value); 238 env = util_find_env (argv[1], 0);
239 if (env)
240 switch (env->type)
241 {
242 case Mail_env_string:
243 fprintf (ofile, "%s", env->value.string);
244 break;
245
246 case Mail_env_number:
247 fprintf (ofile, "%d", env->value.number);
248 break;
249
250 case Mail_env_boolean:
251 fprintf (ofile, "%s", env->set ? "yes" : "no");
252 break;
253
254 default:
255 break;
256 }
241 return 0; 257 return 0;
242 } 258 }
243 259
...@@ -257,13 +273,15 @@ var_quote(int argc, char **argv, struct send_environ *env) ...@@ -257,13 +273,15 @@ var_quote(int argc, char **argv, struct send_environ *env)
257 char buffer[512]; 273 char buffer[512];
258 off_t off = 0; 274 off_t off = 0;
259 size_t n = 0; 275 size_t n = 0;
260 char *prefix = util_find_env("indentprefix")->value; 276 char *prefix = "\t";
261 277
262 if (mailbox_get_message(mbox, cursor, &mesg) != 0) 278 if (mailbox_get_message(mbox, cursor, &mesg) != 0)
263 return 1; 279 return 1;
264 280
265 fprintf(stdout, "Interpolating: %d\n", cursor); 281 fprintf(stdout, "Interpolating: %d\n", cursor);
266 282
283 util_getenv(&prefix, "indentprefix", Mail_env_string, 0);
284
267 if (islower(argv[0][0])) 285 if (islower(argv[0][0]))
268 { 286 {
269 size_t i, num = 0; 287 size_t i, num = 0;
......