whatnow: Simplified and clarified (or fixed?) the situation of failed edits.
authormarkus schnalke <meillo@marmaro.de>
Tue, 1 May 2012 06:09:56 +0000 (08:09 +0200)
committermarkus schnalke <meillo@marmaro.de>
Tue, 1 May 2012 06:09:56 +0000 (08:09 +0200)
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.

man/comp.man1
man/whatnow.man1
uip/whatnow.c

index 5ea88aa..bc723a9 100644 (file)
@@ -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
 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
 switch with an empty string argument is given,
 in which case the initial edit is suppressed).
 .PP
index 42956c1..a181cca 100644 (file)
@@ -31,7 +31,7 @@ or
 after the initial edit.
 .PP
 When started, the editor is started on the draft (unless the
 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
 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
 .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
 The
 .B \-prompt
 .I string
@@ -160,9 +164,3 @@ send(1)
 
 .SH CONTEXT
 None
 
 .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.
index 08e3be8..f26dcb7 100644 (file)
@@ -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) {
        /* 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);
                }
        }
                        done(1);
                }
        }
@@ -223,9 +227,7 @@ main(int argc, char **argv)
                        /* Call an editor on the draft file */
                        if (*++argp)
                                ed = *argp++;
                        /* 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:
                        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);
                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))) {
                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;
                }
 
                        break;
                }
 
@@ -696,8 +704,9 @@ editfile(char **ed, char **arg, char *file, int use, struct msgs *mp,
        edsave = getcpy(*ed);
 
        *ed = NULL;
        edsave = getcpy(*ed);
 
        *ed = NULL;
-       if (altmsg)
+       if (altmsg) {
                unlink(linkpath);
                unlink(linkpath);
+       }
 
        return status;
 }
 
        return status;
 }
@@ -760,7 +769,7 @@ sendfile(char **arg, char *file)
                vec[vecp] = NULL;
 
                execvp("send", vec);
                vec[vecp] = NULL;
 
                execvp("send", vec);
-               fprintf(stderr, "unable to exec ");
+               fprintf(stderr, "%s: unable to exec ", invo_name);
                perror("send");
                _exit(-1);
 
                perror("send");
                _exit(-1);
 
@@ -803,7 +812,7 @@ refile(char **arg, char *file)
 
        case 0:
                execvp(*vec, vec);
 
        case 0:
                execvp(*vec, vec);
-               fprintf(stderr, "unable to exec ");
+               fprintf(stderr, "%s: unable to exec ", invo_name);
                perror(*vec);
                _exit(-1);
 
                perror(*vec);
                _exit(-1);