Fix -nowhatnow proc in mh
* mh/mh.h (mh_whatnow_env) <nowhatnowproc>: New member. * mh/compcommon.c (check_draft_disposition): Return DISP_REPLACE if nowhatnowproc is set. * mh/mh_whatnow.c (mh_whatnowproc): Return 0 if nowhatnowproc is set. * mh/comp.c: Fix -nowhatnowproc * mh/forw.c: Likewise. * mh/repl.c: Likewise.
Showing
6 changed files
with
16 additions
and
24 deletions
... | @@ -27,7 +27,6 @@ static char args_doc[] = N_("[MSG]"); | ... | @@ -27,7 +27,6 @@ static char args_doc[] = N_("[MSG]"); |
27 | struct mh_whatnow_env wh_env = { 0 }; | 27 | struct mh_whatnow_env wh_env = { 0 }; |
28 | static int initial_edit = 1; | 28 | static int initial_edit = 1; |
29 | static const char *whatnowproc; | 29 | static const char *whatnowproc; |
30 | static int nowhatnowproc; | ||
31 | char *formfile; | 30 | char *formfile; |
32 | static int build_only = 0; /* -build flag */ | 31 | static int build_only = 0; /* -build flag */ |
33 | static int use_draft = 0; /* -use flag */ | 32 | static int use_draft = 0; /* -use flag */ |
... | @@ -81,7 +80,7 @@ static struct mu_option options[] = { | ... | @@ -81,7 +80,7 @@ static struct mu_option options[] = { |
81 | mu_c_string, &whatnowproc }, | 80 | mu_c_string, &whatnowproc }, |
82 | { "nowhatnowproc", 0, NULL, MU_OPTION_DEFAULT, | 81 | { "nowhatnowproc", 0, NULL, MU_OPTION_DEFAULT, |
83 | N_("don't run whatnowproc"), | 82 | N_("don't run whatnowproc"), |
84 | mu_c_string, &nowhatnowproc, NULL, "1" }, | 83 | mu_c_int, &wh_env.nowhatnowproc, NULL, "1" }, |
85 | { "use", 0, NULL, MU_OPTION_DEFAULT, | 84 | { "use", 0, NULL, MU_OPTION_DEFAULT, |
86 | N_("use draft file preserved after the last session"), | 85 | N_("use draft file preserved after the last session"), |
87 | mu_c_bool, &use_draft }, | 86 | mu_c_bool, &use_draft }, |
... | @@ -235,7 +234,7 @@ main (int argc, char **argv) | ... | @@ -235,7 +234,7 @@ main (int argc, char **argv) |
235 | } | 234 | } |
236 | 235 | ||
237 | /* Exit immediately if -build is given */ | 236 | /* Exit immediately if -build is given */ |
238 | if (build_only || nowhatnowproc) | 237 | if (build_only || wh_env.nowhatnowproc) |
239 | return 0; | 238 | return 0; |
240 | 239 | ||
241 | return mh_whatnowproc (&wh_env, initial_edit, whatnowproc); | 240 | return mh_whatnowproc (&wh_env, initial_edit, whatnowproc); | ... | ... |
... | @@ -74,6 +74,9 @@ check_draft_disposition (struct mh_whatnow_env *wh, int use_draft) | ... | @@ -74,6 +74,9 @@ check_draft_disposition (struct mh_whatnow_env *wh, int use_draft) |
74 | struct stat st; | 74 | struct stat st; |
75 | int disp = DISP_REPLACE; | 75 | int disp = DISP_REPLACE; |
76 | 76 | ||
77 | if (wh->nowhatnowproc) | ||
78 | return disp; | ||
79 | |||
77 | /* First check if the draft exists */ | 80 | /* First check if the draft exists */ |
78 | if (stat (wh->draftfile, &st) == 0) | 81 | if (stat (wh->draftfile, &st) == 0) |
79 | { | 82 | { | ... | ... |
... | @@ -37,7 +37,6 @@ static const char *whatnowproc; | ... | @@ -37,7 +37,6 @@ static const char *whatnowproc; |
37 | static char *mhl_filter_file = NULL; /* --filter flag */ | 37 | static char *mhl_filter_file = NULL; /* --filter flag */ |
38 | 38 | ||
39 | static int build_only = 0; /* --build flag */ | 39 | static int build_only = 0; /* --build flag */ |
40 | static int nowhatnowproc = 0; /* --nowhatnowproc */ | ||
41 | static int annotate = 0; /* --annotate flag */ | 40 | static int annotate = 0; /* --annotate flag */ |
42 | static enum encap_type encap = encap_clear; /* controlled by --format, --form | 41 | static enum encap_type encap = encap_clear; /* controlled by --format, --form |
43 | and --mime flags */ | 42 | and --mime flags */ |
... | @@ -136,7 +135,7 @@ static struct mu_option options[] = { | ... | @@ -136,7 +135,7 @@ static struct mu_option options[] = { |
136 | mu_c_string, &whatnowproc }, | 135 | mu_c_string, &whatnowproc }, |
137 | { "nowhatnowproc", 0, NULL, MU_OPTION_DEFAULT, | 136 | { "nowhatnowproc", 0, NULL, MU_OPTION_DEFAULT, |
138 | N_("don't run whatnowproc"), | 137 | N_("don't run whatnowproc"), |
139 | mu_c_int, &nowhatnowproc, NULL, "1" }, | 138 | mu_c_int, &wh_env.nowhatnowproc, NULL, "1" }, |
140 | { "use", 0, NULL, MU_OPTION_DEFAULT, | 139 | { "use", 0, NULL, MU_OPTION_DEFAULT, |
141 | N_("use draft file preserved after the last session"), | 140 | N_("use draft file preserved after the last session"), |
142 | mu_c_bool, &use_draft }, | 141 | mu_c_bool, &use_draft }, |
... | @@ -434,7 +433,7 @@ main (int argc, char **argv) | ... | @@ -434,7 +433,7 @@ main (int argc, char **argv) |
434 | } | 433 | } |
435 | 434 | ||
436 | /* Exit immediately if --build is given */ | 435 | /* Exit immediately if --build is given */ |
437 | if (build_only || nowhatnowproc) | 436 | if (build_only || wh_env.nowhatnowproc) |
438 | { | 437 | { |
439 | if (strcmp (wh_env.file, wh_env.draftfile)) | 438 | if (strcmp (wh_env.file, wh_env.draftfile)) |
440 | rename (wh_env.file, wh_env.draftfile); | 439 | rename (wh_env.file, wh_env.draftfile); | ... | ... |
... | @@ -215,6 +215,7 @@ struct mh_whatnow_env /* whatnow shell environment */ | ... | @@ -215,6 +215,7 @@ struct mh_whatnow_env /* whatnow shell environment */ |
215 | char *anno_field; /* Annotate field to be used */ | 215 | char *anno_field; /* Annotate field to be used */ |
216 | mu_list_t anno_list; /* List of messages (mu_message_t) to annotate */ | 216 | mu_list_t anno_list; /* List of messages (mu_message_t) to annotate */ |
217 | mu_mailbox_t mbox; | 217 | mu_mailbox_t mbox; |
218 | int nowhatnowproc; | ||
218 | }; | 219 | }; |
219 | 220 | ||
220 | #define DISP_QUIT 0 | 221 | #define DISP_QUIT 0 | ... | ... |
... | @@ -583,6 +583,9 @@ mh_whatnowproc (struct mh_whatnow_env *wh, int initial_edit, const char *prog) | ... | @@ -583,6 +583,9 @@ mh_whatnowproc (struct mh_whatnow_env *wh, int initial_edit, const char *prog) |
583 | int rc; | 583 | int rc; |
584 | pid_t pid; | 584 | pid_t pid; |
585 | 585 | ||
586 | if (wh->nowhatnowproc) | ||
587 | return 0; | ||
588 | |||
586 | if (!prog) | 589 | if (!prog) |
587 | return mh_whatnow (wh, initial_edit); | 590 | return mh_whatnow (wh, initial_edit); |
588 | 591 | ... | ... |
... | @@ -35,7 +35,6 @@ static const char *whatnowproc; | ... | @@ -35,7 +35,6 @@ static const char *whatnowproc; |
35 | static mu_msgset_t msgset; | 35 | static mu_msgset_t msgset; |
36 | static mu_mailbox_t mbox; | 36 | static mu_mailbox_t mbox; |
37 | static int build_only = 0; /* -build flag */ | 37 | static int build_only = 0; /* -build flag */ |
38 | static int nowhatnowproc = 0; /* -nowhatnowproc */ | ||
39 | static int use_draft = 0; /* -use flag */ | 38 | static int use_draft = 0; /* -use flag */ |
40 | static char *mhl_filter = NULL; /* -filter flag */ | 39 | static char *mhl_filter = NULL; /* -filter flag */ |
41 | static int annotate; /* -annotate flag */ | 40 | static int annotate; /* -annotate flag */ |
... | @@ -86,7 +85,7 @@ set_whatnowproc (struct mu_parseopt *po, struct mu_option *opt, | ... | @@ -86,7 +85,7 @@ set_whatnowproc (struct mu_parseopt *po, struct mu_option *opt, |
86 | char const *arg) | 85 | char const *arg) |
87 | { | 86 | { |
88 | whatnowproc = mu_strdup (arg); | 87 | whatnowproc = mu_strdup (arg); |
89 | nowhatnowproc = 0; | 88 | wh_env.nowhatnowproc = 0; |
90 | } | 89 | } |
91 | 90 | ||
92 | static void | 91 | static void |
... | @@ -165,7 +164,7 @@ static struct mu_option options[] = { | ... | @@ -165,7 +164,7 @@ static struct mu_option options[] = { |
165 | mu_c_string, NULL, set_whatnowproc }, | 164 | mu_c_string, NULL, set_whatnowproc }, |
166 | { "nowhatnowproc", 0, NULL, MU_OPTION_DEFAULT, | 165 | { "nowhatnowproc", 0, NULL, MU_OPTION_DEFAULT, |
167 | N_("don't run whatnowproc"), | 166 | N_("don't run whatnowproc"), |
168 | mu_c_int, &nowhatnowproc, NULL, "1" }, | 167 | mu_c_int, &wh_env.nowhatnowproc, NULL, "1" }, |
169 | { "use", 0, NULL, MU_OPTION_DEFAULT, | 168 | { "use", 0, NULL, MU_OPTION_DEFAULT, |
170 | N_("use draft file preserved after the last session"), | 169 | N_("use draft file preserved after the last session"), |
171 | mu_c_bool, &use_draft }, | 170 | mu_c_bool, &use_draft }, |
... | @@ -190,23 +189,11 @@ make_draft (mu_mailbox_t mbox, int disp, struct mh_whatnow_env *wh) | ... | @@ -190,23 +189,11 @@ make_draft (mu_mailbox_t mbox, int disp, struct mh_whatnow_env *wh) |
190 | { | 189 | { |
191 | int rc; | 190 | int rc; |
192 | mu_message_t msg; | 191 | mu_message_t msg; |
193 | struct stat st; | ||
194 | size_t msgno; | 192 | size_t msgno; |
195 | 193 | ||
196 | /* First check if the draft exists */ | 194 | /* First check if the draft exists */ |
197 | if (!build_only && stat (wh->draftfile, &st) == 0) | 195 | if (!build_only) |
198 | { | 196 | disp = check_draft_disposition (wh, use_draft); |
199 | if (use_draft) | ||
200 | disp = DISP_USE; | ||
201 | else | ||
202 | { | ||
203 | printf (ngettext ("Draft \"%s\" exists (%s byte).\n", | ||
204 | "Draft \"%s\" exists (%s bytes).\n", | ||
205 | (unsigned long) st.st_size), | ||
206 | wh->draftfile, mu_umaxtostr (0, st.st_size)); | ||
207 | disp = mh_disposition (wh->draftfile); | ||
208 | } | ||
209 | } | ||
210 | 197 | ||
211 | switch (disp) | 198 | switch (disp) |
212 | { | 199 | { |
... | @@ -344,7 +331,7 @@ main (int argc, char **argv) | ... | @@ -344,7 +331,7 @@ main (int argc, char **argv) |
344 | make_draft (mbox, DISP_REPLACE, &wh_env); | 331 | make_draft (mbox, DISP_REPLACE, &wh_env); |
345 | 332 | ||
346 | /* Exit immediately if --build is given */ | 333 | /* Exit immediately if --build is given */ |
347 | if (build_only || nowhatnowproc) | 334 | if (build_only || wh_env.nowhatnowproc) |
348 | return 0; | 335 | return 0; |
349 | 336 | ||
350 | rc = mh_whatnowproc (&wh_env, initial_edit, whatnowproc); | 337 | rc = mh_whatnowproc (&wh_env, initial_edit, whatnowproc); | ... | ... |
-
Please register or sign in to post a comment