Use util_getenv(). Provide default for "regexp" internal variable
Showing
1 changed file
with
20 additions
and
22 deletions
... | @@ -177,23 +177,20 @@ static const char *mail_capa[] = { | ... | @@ -177,23 +177,20 @@ static const char *mail_capa[] = { |
177 | static char * | 177 | static char * |
178 | mail_cmdline(void *closure, int cont) | 178 | mail_cmdline(void *closure, int cont) |
179 | { | 179 | { |
180 | struct mail_env_entry *pev = closure; | 180 | char *prompt = (char*) (closure ? closure : NULL); |
181 | char *prompt = NULL; | ||
182 | char *rc; | 181 | char *rc; |
183 | 182 | ||
184 | (void)cont; | 183 | (void)cont; |
185 | 184 | ||
186 | while (1) | 185 | while (1) |
187 | { | 186 | { |
188 | if (util_find_env ("autoinc")->set && !mailbox_is_updated (mbox)) | 187 | if (util_getenv (NULL, "autoinc", Mail_env_boolean, 0) == 0 |
188 | && !mailbox_is_updated (mbox)) | ||
189 | { | 189 | { |
190 | mailbox_messages_count (mbox, &total); | 190 | mailbox_messages_count (mbox, &total); |
191 | fprintf (ofile, "New mail has arrived\n"); | 191 | fprintf (ofile, "New mail has arrived\n"); |
192 | } | 192 | } |
193 | 193 | ||
194 | if (interactive) | ||
195 | prompt = pev->set && pev->value != NULL ? pev->value : (char *)"? "; | ||
196 | |||
197 | rc = ml_readline (prompt); | 194 | rc = ml_readline (prompt); |
198 | 195 | ||
199 | if (ml_got_interrupt()) | 196 | if (ml_got_interrupt()) |
... | @@ -202,7 +199,7 @@ mail_cmdline(void *closure, int cont) | ... | @@ -202,7 +199,7 @@ mail_cmdline(void *closure, int cont) |
202 | continue; | 199 | continue; |
203 | } | 200 | } |
204 | 201 | ||
205 | if (!rc && util_find_env ("ignoreeof")->set) | 202 | if (!rc && util_getenv (NULL, "ignoreeof", Mail_env_boolean, 0) == 0) |
206 | { | 203 | { |
207 | util_error ("Use \"quit\" to quit."); | 204 | util_error ("Use \"quit\" to quit."); |
208 | continue; | 205 | continue; |
... | @@ -216,7 +213,7 @@ mail_cmdline(void *closure, int cont) | ... | @@ -216,7 +213,7 @@ mail_cmdline(void *closure, int cont) |
216 | int | 213 | int |
217 | main (int argc, char **argv) | 214 | main (int argc, char **argv) |
218 | { | 215 | { |
219 | struct mail_env_entry *mode = NULL, *prompt = NULL; | 216 | char *mode = NULL, *prompt = NULL; |
220 | size_t modelen = 0; | 217 | size_t modelen = 0; |
221 | struct arguments args; | 218 | struct arguments args; |
222 | int rc; | 219 | int rc; |
... | @@ -308,13 +305,14 @@ main (int argc, char **argv) | ... | @@ -308,13 +305,14 @@ main (int argc, char **argv) |
308 | util_do_command ("set noSign"); | 305 | util_do_command ("set noSign"); |
309 | util_do_command ("set toplines=5"); | 306 | util_do_command ("set toplines=5"); |
310 | util_do_command ("set autoinc"); | 307 | util_do_command ("set autoinc"); |
311 | 308 | util_do_command ("set regex"); | |
309 | |||
312 | /* Set the default mailer to sendmail. */ | 310 | /* Set the default mailer to sendmail. */ |
313 | { | 311 | { |
314 | char *mailer_name = alloca (strlen ("sendmail:") | 312 | char *mailer_name = alloca (strlen ("sendmail:") |
315 | + strlen (_PATH_SENDMAIL) + 1); | 313 | + strlen (_PATH_SENDMAIL) + 1); |
316 | sprintf (mailer_name, "sendmail:%s", _PATH_SENDMAIL); | 314 | sprintf (mailer_name, "sendmail:%s", _PATH_SENDMAIL); |
317 | util_setenv ("sendmail", mailer_name, 0); | 315 | util_setenv ("sendmail", mailer_name, Mail_env_string, 1); |
318 | } | 316 | } |
319 | 317 | ||
320 | /* GNU extensions to the environment, for sparky's sanity */ | 318 | /* GNU extensions to the environment, for sparky's sanity */ |
... | @@ -332,7 +330,7 @@ main (int argc, char **argv) | ... | @@ -332,7 +330,7 @@ main (int argc, char **argv) |
332 | mu_argp_parse (&argp, &argc, &argv, 0, mail_capa, NULL, &args); | 330 | mu_argp_parse (&argp, &argc, &argv, 0, mail_capa, NULL, &args); |
333 | 331 | ||
334 | /* read system-wide mail.rc and user's .mailrc */ | 332 | /* read system-wide mail.rc and user's .mailrc */ |
335 | if ((util_find_env ("rc"))->set) | 333 | if (util_getenv (NULL, "rc", Mail_env_boolean, 0) == 0) |
336 | util_do_command ("source %s", SITE_MAIL_RC); | 334 | util_do_command ("source %s", SITE_MAIL_RC); |
337 | util_do_command ("source %s", getenv ("MAILRC")); | 335 | util_do_command ("source %s", getenv ("MAILRC")); |
338 | if (!interactive) | 336 | if (!interactive) |
... | @@ -345,12 +343,12 @@ main (int argc, char **argv) | ... | @@ -345,12 +343,12 @@ main (int argc, char **argv) |
345 | } | 343 | } |
346 | 344 | ||
347 | /* how should we be running? */ | 345 | /* how should we be running? */ |
348 | if ((mode = util_find_env ("mode")) == NULL || mode->set == 0) | 346 | if (util_getenv (&mode, "mode", Mail_env_string, 1)) |
349 | exit (EXIT_FAILURE); | 347 | exit (EXIT_FAILURE); |
350 | modelen = strlen (mode->value); | 348 | modelen = strlen (mode); |
351 | 349 | ||
352 | /* Interactive mode */ | 350 | /* Interactive mode */ |
353 | if (!(util_find_env("quiet"))->set) | 351 | if (util_getenv (NULL, "quiet", Mail_env_boolean, 0)) |
354 | { | 352 | { |
355 | fprintf (ofile, | 353 | fprintf (ofile, |
356 | "%s, Copyright (C) 2001 Free Software Foundation, Inc.\n" | 354 | "%s, Copyright (C) 2001 Free Software Foundation, Inc.\n" |
... | @@ -364,7 +362,7 @@ main (int argc, char **argv) | ... | @@ -364,7 +362,7 @@ main (int argc, char **argv) |
364 | mail_set_my_name(args.user); | 362 | mail_set_my_name(args.user); |
365 | 363 | ||
366 | /* Mode is just sending */ | 364 | /* Mode is just sending */ |
367 | if (strlen ("send") == modelen && !strcmp ("send", mode->value)) | 365 | if (strlen ("send") == modelen && !strcmp ("send", mode)) |
368 | { | 366 | { |
369 | /* FIXME: set cmd to "mail [add1...]" */ | 367 | /* FIXME: set cmd to "mail [add1...]" */ |
370 | char *buf = NULL; | 368 | char *buf = NULL; |
... | @@ -435,13 +433,13 @@ main (int argc, char **argv) | ... | @@ -435,13 +433,13 @@ main (int argc, char **argv) |
435 | exit (EXIT_FAILURE); | 433 | exit (EXIT_FAILURE); |
436 | } | 434 | } |
437 | 435 | ||
438 | if (strlen ("exist") == modelen && !strcmp ("exist", mode->value)) | 436 | if (strlen ("exist") == modelen && !strcmp ("exist", mode)) |
439 | return (total < 1) ? 1 : 0; | 437 | return (total < 1) ? 1 : 0; |
440 | else if (strlen ("print") == modelen | 438 | else if (strlen ("print") == modelen |
441 | && !strcmp ("print", mode->value)) | 439 | && !strcmp ("print", mode)) |
442 | return util_do_command ("print *"); | 440 | return util_do_command ("print *"); |
443 | else if (strlen ("headers") == modelen | 441 | else if (strlen ("headers") == modelen |
444 | && !strcmp ("headers", mode->value)) | 442 | && !strcmp ("headers", mode)) |
445 | return util_do_command ("from *"); | 443 | return util_do_command ("from *"); |
446 | } | 444 | } |
447 | 445 | ||
... | @@ -456,14 +454,14 @@ main (int argc, char **argv) | ... | @@ -456,14 +454,14 @@ main (int argc, char **argv) |
456 | } | 454 | } |
457 | 455 | ||
458 | /* initial commands */ | 456 | /* initial commands */ |
459 | if ((util_find_env("header"))->set) | 457 | if (util_getenv(NULL, "header", Mail_env_boolean, 0) == 0) |
460 | { | 458 | { |
461 | util_do_command ("summary"); | 459 | util_do_command ("summary"); |
462 | util_do_command ("z."); | 460 | util_do_command ("z."); |
463 | } | 461 | } |
464 | 462 | ||
465 | prompt = util_find_env ("prompt"); | 463 | util_getenv (&prompt, "prompt", Mail_env_string, 0); |
466 | mail_mainloop(mail_cmdline, (void*) prompt, 1); | 464 | mail_mainloop (mail_cmdline, (void*) prompt, 1); |
467 | fprintf (ofile, "\n"); | 465 | fprintf (ofile, "\n"); |
468 | util_do_command ("quit"); | 466 | util_do_command ("quit"); |
469 | return 0; | 467 | return 0; |
... | @@ -474,7 +472,7 @@ main (int argc, char **argv) | ... | @@ -474,7 +472,7 @@ main (int argc, char **argv) |
474 | 472 | ||
475 | 473 | ||
476 | void | 474 | void |
477 | mail_mainloop(char *(*input) __P((void *, int)), void *closure, int do_history) | 475 | mail_mainloop (char *(*input) __P((void *, int)), void *closure, int do_history) |
478 | { | 476 | { |
479 | char *command, *cmd; | 477 | char *command, *cmd; |
480 | while ((command = (*input)(closure, 0)) != NULL) | 478 | while ((command = (*input)(closure, 0)) != NULL) | ... | ... |
-
Please register or sign in to post a comment