Commit baa0bce1 baa0bce1da41df422b4f36d3d6fd0c743ae86c1a by Sergey Poznyakoff

(parse_opt): Use util_cache_command, except

for -n, which should be executed immediately.
(main): Run cached commands after sourcing the startup files.
1 parent 30b799ed
Showing 1 changed file with 20 additions and 17 deletions
...@@ -24,6 +24,8 @@ size_t total; ...@@ -24,6 +24,8 @@ size_t total;
24 FILE *ofile; 24 FILE *ofile;
25 int interactive; 25 int interactive;
26 26
27 static list_t command_list;
28
27 const char *program_version = "mail (" PACKAGE_STRING ")"; 29 const char *program_version = "mail (" PACKAGE_STRING ")";
28 static char doc[] = N_("GNU mail -- the standard /bin/mail interface"); 30 static char doc[] = N_("GNU mail -- the standard /bin/mail interface");
29 static char args_doc[] = N_("[address...]"); 31 static char args_doc[] = N_("[address...]");
...@@ -67,7 +69,7 @@ parse_opt (int key, char *arg, struct argp_state *state) ...@@ -67,7 +69,7 @@ parse_opt (int key, char *arg, struct argp_state *state)
67 switch (key) 69 switch (key)
68 { 70 {
69 case 'e': 71 case 'e':
70 util_do_command ("set mode=exist"); 72 util_cache_command (&command_list, "set mode=exist");
71 break; 73 break;
72 74
73 case 'f': 75 case 'f':
...@@ -86,23 +88,23 @@ parse_opt (int key, char *arg, struct argp_state *state) ...@@ -86,23 +88,23 @@ parse_opt (int key, char *arg, struct argp_state *state)
86 88
87 case 'p': 89 case 'p':
88 case 'r': 90 case 'r':
89 util_do_command ("set mode=print"); 91 util_cache_command (&command_list, "set mode=print");
90 break; 92 break;
91 93
92 case 'q': 94 case 'q':
93 util_do_command ("set quit"); 95 util_cache_command (&command_list, "set quit");
94 break; 96 break;
95 97
96 case 't': 98 case 't':
97 util_do_command ("set mode=send"); 99 util_cache_command (&command_list, "set mode=send");
98 break; 100 break;
99 101
100 case 'H': 102 case 'H':
101 util_do_command ("set mode=headers"); 103 util_cache_command (&command_list, "set mode=headers");
102 break; 104 break;
103 105
104 case 'i': 106 case 'i':
105 util_do_command ("set ignore"); 107 util_cache_command (&command_list, "set ignore");
106 break; 108 break;
107 109
108 case 'n': 110 case 'n':
...@@ -110,13 +112,13 @@ parse_opt (int key, char *arg, struct argp_state *state) ...@@ -110,13 +112,13 @@ parse_opt (int key, char *arg, struct argp_state *state)
110 break; 112 break;
111 113
112 case 'N': 114 case 'N':
113 util_do_command ("set noheader"); 115 util_cache_command (&command_list, "set noheader");
114 break; 116 break;
115 117
116 case 's': 118 case 's':
117 util_do_command ("set mode=send"); 119 util_cache_command (&command_list, "set mode=send");
118 util_do_command ("set noasksub"); 120 util_cache_command (&command_list, "set noasksub");
119 util_do_command ("set subject=\"%s\"", arg); 121 util_cache_command (&command_list, "set subject=\"%s\"", arg);
120 break; 122 break;
121 123
122 case 'u': 124 case 'u':
...@@ -124,7 +126,7 @@ parse_opt (int key, char *arg, struct argp_state *state) ...@@ -124,7 +126,7 @@ parse_opt (int key, char *arg, struct argp_state *state)
124 break; 126 break;
125 127
126 case 'F': 128 case 'F':
127 util_do_command ("set byname"); 129 util_cache_command (&command_list, "set byname");
128 break; 130 break;
129 131
130 case ARGP_KEY_ARG: 132 case ARGP_KEY_ARG:
...@@ -146,7 +148,7 @@ parse_opt (int key, char *arg, struct argp_state *state) ...@@ -146,7 +148,7 @@ parse_opt (int key, char *arg, struct argp_state *state)
146 sizeof (char *) * (state->arg_num + 2)); 148 sizeof (char *) * (state->arg_num + 2));
147 args->args[state->arg_num] = arg; 149 args->args[state->arg_num] = arg;
148 args->args[state->arg_num + 1] = NULL; 150 args->args[state->arg_num + 1] = NULL;
149 util_do_command ("set mode=send"); 151 util_cache_command (&command_list, "set mode=send");
150 } 152 }
151 break; 153 break;
152 154
...@@ -303,6 +305,9 @@ main (int argc, char **argv) ...@@ -303,6 +305,9 @@ main (int argc, char **argv)
303 util_do_command ("set toplines=5"); 305 util_do_command ("set toplines=5");
304 util_do_command ("set autoinc"); 306 util_do_command ("set autoinc");
305 util_do_command ("set regex"); 307 util_do_command ("set regex");
308 /* Start in mail reading mode */
309 util_do_command ("set mode=read");
310 util_do_command ("set noquit");
306 311
307 /* Set the default mailer to sendmail. */ 312 /* Set the default mailer to sendmail. */
308 { 313 {
...@@ -312,11 +317,6 @@ main (int argc, char **argv) ...@@ -312,11 +317,6 @@ main (int argc, char **argv)
312 util_setenv ("sendmail", mailer_name, Mail_env_string, 1); 317 util_setenv ("sendmail", mailer_name, Mail_env_string, 1);
313 } 318 }
314 319
315 /* GNU extensions to the environment, for sparky's sanity */
316 util_do_command ("set mode=read");
317 util_do_command ("set nobyname");
318 util_do_command ("set rc");
319 util_do_command ("set noquit");
320 320
321 args.args = NULL; 321 args.args = NULL;
322 args.file = NULL; 322 args.file = NULL;
...@@ -331,6 +331,9 @@ main (int argc, char **argv) ...@@ -331,6 +331,9 @@ main (int argc, char **argv)
331 if (util_getenv (NULL, "rc", Mail_env_boolean, 0) == 0) 331 if (util_getenv (NULL, "rc", Mail_env_boolean, 0) == 0)
332 util_do_command ("source %s", SITE_MAIL_RC); 332 util_do_command ("source %s", SITE_MAIL_RC);
333 util_do_command ("source %s", getenv ("MAILRC")); 333 util_do_command ("source %s", getenv ("MAILRC"));
334
335 util_run_cached_commands (&command_list);
336
334 if (!interactive) 337 if (!interactive)
335 { 338 {
336 util_do_command ("set nocrt"); 339 util_do_command ("set nocrt");
......