From: markus schnalke Date: Tue, 1 May 2012 06:09:56 +0000 (+0200) Subject: whatnow: Simplified and clarified (or fixed?) the situation of failed edits. X-Git-Tag: mmh-thesis-end~70 X-Git-Url: http://git.marmaro.de/?p=mmh;a=commitdiff_plain;h=8bdc45422ae3279fde81b1d1e7eb9dcf881f961f whatnow: Simplified and clarified (or fixed?) the situation of failed edits. If the initial edit fails, no new draft is created, but any existing re-used draft is preserved. Failures of later edits are ignored and another prompt is printed. --- diff --git a/man/comp.man1 b/man/comp.man1 index 5ea88aa..bc723a9 100644 --- a/man/comp.man1 +++ b/man/comp.man1 @@ -25,7 +25,7 @@ comp \- compose a message is used to create a new message to be mailed. It copies a message form to the draft being composed and then invokes an editor on the draft (unless the -.B \-edit +.B \-editor switch with an empty string argument is given, in which case the initial edit is suppressed). .PP diff --git a/man/whatnow.man1 b/man/whatnow.man1 index 42956c1..a181cca 100644 --- a/man/whatnow.man1 +++ b/man/whatnow.man1 @@ -31,7 +31,7 @@ or after the initial edit. .PP When started, the editor is started on the draft (unless the -.B \-edit +.B \-editor switch with an empty string argument is given, in which case the initial edit is suppressed). Then, .B whatnow @@ -118,6 +118,10 @@ used to direct .BR whatnow 's actions in complex ways. .PP +If the initial edit fails, no new draft is created, but any +existing re-used draft is preserved. +Failures of later edits are ignored and another prompt is printed. +.PP The .B \-prompt .I string @@ -160,9 +164,3 @@ send(1) .SH CONTEXT None - -.SH BUGS -If the initial edit fails, -.B whatnow -deletes your draft (by renaming -it with a leading comma); failure of a later edit preserves the draft. diff --git a/uip/whatnow.c b/uip/whatnow.c index 08e3be8..f26dcb7 100644 --- a/uip/whatnow.c +++ b/uip/whatnow.c @@ -197,6 +197,10 @@ main(int argc, char **argv) /* start editing the draft, unless editor is the empty string */ if (*ed) { if (editfile(&ed, NULL, drft, use, NULL, msgnam, NULL) <0) { + if (!use) { + unlink(drft); + } + advise(NULL, "Try again."); done(1); } } @@ -223,9 +227,7 @@ main(int argc, char **argv) /* Call an editor on the draft file */ if (*++argp) ed = *argp++; - if (editfile(&ed, argp, drft, NOUSE, NULL, - msgnam, NULL) == NOTOK) - done(1); + editfile(&ed, argp, drft, NOUSE, NULL, msgnam, NULL); break; case LISTSW: @@ -654,21 +656,27 @@ editfile(char **ed, char **arg, char *file, int use, struct msgs *mp, vec[vecp] = NULL; execvp(*ed, vec); - fprintf(stderr, "unable to exec "); + fprintf(stderr, "%s: unable to exec ", invo_name); perror(*ed); _exit(-1); default: if ((status = pidwait(pid, NOTOK))) { - if (((status & 0xff00) != 0xff00) && - (!edsave || (status & 0x00ff))) { - if (!use && (status & 0xff00) && (rename(file, cp = m_backup(file)) != NOTOK)) { - advise(NULL, "problems with edit--draft left in %s", cp); - } else { - advise(NULL, "problems with edit--%s preserved", file); - } + if ((status & 0xff00) == 0xff00) { + /* cmd not found or pidwait() failed */ + status = -1; + break; } - status = -2; /* maybe "edsave ? -2 : -1"? */ + if (status & 0x00ff) { + /* terminated by signal */ + advise(NULL, "%s terminated by signal %d", + *ed, status & 0x7f); + } else { + /* failure exit */ + advise(NULL, "%s exited with return code %d", + *ed, (status & 0xff00) >> 8); + } + status = -1; break; } @@ -696,8 +704,9 @@ editfile(char **ed, char **arg, char *file, int use, struct msgs *mp, edsave = getcpy(*ed); *ed = NULL; - if (altmsg) + if (altmsg) { unlink(linkpath); + } return status; } @@ -760,7 +769,7 @@ sendfile(char **arg, char *file) vec[vecp] = NULL; execvp("send", vec); - fprintf(stderr, "unable to exec "); + fprintf(stderr, "%s: unable to exec ", invo_name); perror("send"); _exit(-1); @@ -803,7 +812,7 @@ refile(char **arg, char *file) case 0: execvp(*vec, vec); - fprintf(stderr, "unable to exec "); + fprintf(stderr, "%s: unable to exec ", invo_name); perror(*vec); _exit(-1);