s/lproc/listproc/
[mmh] / uip / whatnow.c
index 0ec8e41..3d97716 100644 (file)
@@ -66,15 +66,15 @@ static struct swit aleqs[] = {
 #define REFILEOPT  1
        { "refile [<switches>] +folder", 0 },
 #define DISPSW  2
-       { "display [<switches>]", 0 },
+       { "display", 0 },
 #define LISTSW  3
-       { "list [<switches>]", 0 },
+       { "list", 0 },
 #define SENDSW  4
        { "send [<switches>]", 0 },
 #define PUSHSW  5
        { "push [<switches>]", 0 },
 #define QUITSW  6
-       { "quit [-delete]", 0 },
+       { "quit", 0 },
 #define DELETESW  7
        { "delete", 0 },
 #define CDCMDSW  8
@@ -100,7 +100,6 @@ static char *myprompt = "\nWhat now? ";
 static int editfile(char **, char **, char *, int, struct msgs *,
        char *, char *, int);
 static int sendfile(char **, char *, int);
-static void sendit(char *, char **, char *, int);
 static int removefile(char *);
 static void writelscmd(char *, int, char **);
 static void writesomecmd(char *buf, int bufsz, char *cmd, char *trailcmd, char **argp);
@@ -218,14 +217,14 @@ main(int argc, char **argv)
                }
                switch (smatch(*argp, aleqs)) {
                case DISPSW:
-                       /*
-                       ** display the message being replied to,
-                       ** or distributed
-                       */
-                       if (msgnam)
-                               showfile(++argp, msgnam);
-                       else
+                       /* display the msg being replied to or distributed */
+                       if (msgnam) {
+                               snprintf(buf, sizeof buf, "%s '%s'",
+                                               listproc, msgnam);
+                               system(buf);
+                       } else {
                                advise(NULL, "no alternate message to display");
+                       }
                        break;
 
                case EDITSW:
@@ -239,17 +238,14 @@ main(int argc, char **argv)
 
                case LISTSW:
                        /* display the draft file */
-                       showfile(++argp, drft);
+                       snprintf(buf, sizeof buf, "%s '%s'", listproc, drft);
+                       system(buf);
                        break;
 
                case QUITSW:
-                       /* Quit, and possibly delete the draft */
-                       if (*++argp && (*argp[0] == 'd' ||
-                               ((*argp)[0] == '-' && (*argp)[1] == 'd'))) {
-                               removefile(drft);
-                       } else {
-                               if (stat(drft, &st) != NOTOK)
-                                       advise(NULL, "draft left on %s", drft);
+                       /* quit */
+                       if (stat(drft, &st) != NOTOK) {
+                               advise(NULL, "draft left on %s", drft);
                        }
                        done(1);
 
@@ -391,14 +387,14 @@ main(int argc, char **argv)
 
                                        if (*shell == '/')
                                                annotate(drft, attach_hdr,
-                                                               shell, 1, 0,
-                                                               -2, 1);
+                                                               shell, 0,
+                                                               -2, 1, 0);
                                        else {
                                                sprintf(file, "%s/%s", cwd,
                                                                shell);
                                                annotate(drft, attach_hdr,
-                                                               file, 1, 0,
-                                                               -2, 1);
+                                                               file, 0,
+                                                               -2, 1, 0);
                                        }
                                }
 
@@ -445,8 +441,8 @@ main(int argc, char **argv)
                                        if (**arguments != '\0') {
                                                n = atoi(*arguments);
                                                annotate(drft, attach_hdr,
-                                                               NULL, 1, 0,
-                                                               n, 1);
+                                                               NULL, 0,
+                                                               n, 1, 0);
 
                                                for (argp = arguments + 1; *argp != NULL; argp++) {
                                                        if (atoi(*argp) > n) {
@@ -478,7 +474,7 @@ main(int argc, char **argv)
                                                != NULL) {
                                        *(strchr(shell, '\n')) = '\0';
                                        annotate(drft, attach_hdr, shell,
-                                                       1, 0, 0, 1);
+                                                       0, 0, 1, 0);
                                }
                                pclose(f);
                        } else {
@@ -626,10 +622,9 @@ editfile(char **ed, char **arg, char *file, int use, struct msgs *mp,
                        if ((cp = context_find(cp)) != NULL)
                                *ed = cp;
                }
-       } else {
+       } else if (!*ed) {
                /* set initial editor */
-               if (*ed == NULL && (*ed = context_find("editor")) == NULL)
-                       *ed = defaulteditor;
+               *ed = defaulteditor;
        }
 
        if (altmsg) {
@@ -774,28 +769,13 @@ static int
 sendfile(char **arg, char *file, int pushsw)
 {
        pid_t child_id;
-       int i, vecp;
-       char *cp, *sp, *vec[MAXARGS];
-
-       /*
-       ** If the sendproc is the nmh command `send', then we call
-       ** those routines directly rather than exec'ing the command.
-       */
-       if (strcmp(sp = mhbasename(sendproc), "send") == 0) {
-               cp = invo_name;
-               sendit(invo_name = sp, arg, file, pushsw);
-               invo_name = cp;
-               return 1;
-       }
-
-       /* some different sendproc */
+       int vecp;
+       char *vec[MAXARGS];
 
        context_save();  /* save the context file */
        fflush(stdout);
 
-       for (i = 0; (child_id = fork()) == NOTOK && i < 5; i++)
-               sleep(5);
-       switch (child_id) {
+       switch (child_id = fork()) {
        case NOTOK:
                advise(NULL, "unable to fork, so sending directly...");
                /* fall */
@@ -823,234 +803,6 @@ sendfile(char **arg, char *file, int pushsw)
 }
 
 
-static struct swit  sendswitches[] = {
-#define ALIASW  0
-       { "alias aliasfile", 0 },
-#define DEBUGSW  1
-       { "debug", -5 },
-#define FILTSW  2
-       { "filter filterfile", 0 },
-#define NFILTSW  3
-       { "nofilter", 0 },
-#define FRMTSW  4
-       { "format", 0 },
-#define NFRMTSW  5
-       { "noformat", 0 },
-#define FORWSW  6
-       { "forward", 0 },
-#define NFORWSW  7
-       { "noforward", 0 },
-#define SPSHSW  8
-       { "push", 0 },
-#define NSPSHSW  9
-       { "nopush", 0 },
-#define VERBSW  10
-       { "verbose", 0 },
-#define NVERBSW  11
-       { "noverbose", 0 },
-#define WATCSW  12
-       { "watch", 0 },
-#define NWATCSW  13
-       { "nowatch", 0 },
-#define WIDTHSW  14
-       { "width columns", 0 },
-#define SVERSIONSW  15
-       { "version", 0 },
-#define SHELPSW  16
-       { "help", 0 },
-       { NULL, 0 }
-};
-
-
-extern int debugsw;  /* from sendsbr.c */
-extern int forwsw;
-extern int inplace;
-extern int pushsw;
-extern int verbsw;
-
-extern char *altmsg;  /*  .. */
-extern char *annotext;
-extern char *distfile;
-
-
-static void
-sendit(char *sp, char **arg, char *file, int pushed)
-{
-       int vecp, n = 1;
-       char *cp, buf[BUFSIZ], **argp;
-       char **arguments, *vec[MAXARGS];
-       struct stat st;
-
-#ifndef lint
-       int distsw = 0;
-#endif
-
-       /*
-       ** Make sure these are defined.  In particular, we need
-       ** vec[1] to be NULL, in case "arg" is NULL below.  It
-       ** doesn't matter what is the value of vec[0], but we
-       ** set it to NULL, to help catch "off-by-one" errors.
-       */
-       vec[0] = NULL;
-       vec[1] = NULL;
-
-       /*
-       ** Temporarily copy arg to vec, since the brkstring() call in
-       ** getarguments() will wipe it out before it is merged in.
-       ** Also, we skip the first element of vec, since getarguments()
-       ** skips it.  Then we count the number of arguments
-       ** copied.  The value of "n" will be one greater than
-       ** this in order to simulate the standard argc/argv.
-       */
-       if (arg) {
-               char **bp;
-
-               copyip(arg, vec+1, MAXARGS-1);
-               bp = vec+1;
-               while (*bp++)
-                       n++;
-       }
-
-       /*
-       ** Merge any arguments from command line (now in vec)
-       ** and arguments from profile.
-       */
-       arguments = getarguments(sp, n, vec, 1);
-       argp = arguments;
-
-       debugsw = 0;
-       forwsw = 1;
-       inplace = 1;
-
-       altmsg = NULL;
-       annotext = NULL;
-       distfile = NULL;
-
-       vecp = 1;  /* we'll get the zero'th element later */
-       vec[vecp++] = "-library";
-       vec[vecp++] = getcpy(toabsdir("+"));
-
-       while ((cp = *argp++)) {
-               if (*cp == '-') {
-                       switch (smatch(++cp, sendswitches)) {
-                       case AMBIGSW:
-                               ambigsw(cp, sendswitches);
-                               return;
-                       case UNKWNSW:
-                               advise(NULL, "-%s unknown\n", cp);
-                               return;
-
-                       case SHELPSW:
-                               snprintf(buf, sizeof(buf),
-                                               "%s [switches]", sp);
-                               print_help(buf, sendswitches, 1);
-                               return;
-                       case SVERSIONSW:
-                               print_version(invo_name);
-                               return;
-
-                       case SPSHSW:
-                               pushed++;
-                               continue;
-                       case NSPSHSW:
-                               pushed = 0;
-                               continue;
-
-                       case FORWSW:
-                               forwsw++;
-                               continue;
-                       case NFORWSW:
-                               forwsw = 0;
-                               continue;
-
-                       case VERBSW:
-                               verbsw++;
-                               vec[vecp++] = --cp;
-                               continue;
-                       case NVERBSW:
-                               verbsw = 0;
-                               vec[vecp++] = --cp;
-                               continue;
-
-                       case DEBUGSW:
-                               debugsw++;  /* fall */
-                       case NFILTSW:
-                       case FRMTSW:
-                       case NFRMTSW:
-                       case WATCSW:
-                       case NWATCSW:
-                               vec[vecp++] = --cp;
-                               continue;
-
-                       case ALIASW:
-                       case FILTSW:
-                       case WIDTHSW:
-                               vec[vecp++] = --cp;
-                               if (!(cp = *argp++) || *cp == '-') {
-                                       advise(NULL, "missing argument to %s",
-                                                       argp[-2]);
-                                       return;
-                               }
-                               vec[vecp++] = cp;
-                               continue;
-
-                       }
-               }
-               advise(NULL, "usage: %s [switches]", sp);
-               return;
-       }
-
-       /* allow Aliasfile: profile entry */
-       if ((cp = context_find("Aliasfile"))) {
-               char **ap, *dp;
-
-               dp = getcpy(cp);
-               for (ap = brkstring(dp, " ", "\n"); ap && *ap; ap++) {
-                       vec[vecp++] = "-alias";
-                       vec[vecp++] = getcpy(etcpath(*ap));
-               }
-       }
-
-       if (!(cp = getenv("SIGNATURE")) || !*cp)
-               if ((cp = context_find("signature")) && *cp)
-                       m_putenv("SIGNATURE", cp);
-
-       if ((annotext = getenv("mhannotate")) == NULL || *annotext == 0)
-               annotext = NULL;
-       if ((altmsg = getenv("mhaltmsg")) == NULL || *altmsg == 0)
-               altmsg = NULL;
-       if (annotext && ((cp = getenv("mhinplace")) != NULL && *cp != 0))
-               inplace = atoi(cp);
-
-       if ((cp = getenv("mhdist")) && *cp
-#ifndef lint
-                       && (distsw = atoi (cp))
-#endif /* not lint */
-                       && altmsg) {
-               vec[vecp++] = "-dist";
-               distfile = getcpy(m_mktemp2(altmsg, invo_name, NULL, NULL));
-               if (link(altmsg, distfile) == NOTOK)
-                       adios(distfile, "unable to link %s to", altmsg);
-       } else {
-               distfile = NULL;
-       }
-
-       if (altmsg == NULL || stat(altmsg, &st) == NOTOK) {
-               st.st_mtime = 0;
-               st.st_dev = 0;
-               st.st_ino = 0;
-       }
-       if ((pushsw = pushed))
-               push();
-
-       vec[0] = mhbasename(postproc);
-       closefds(3);
-
-       if (sendsbr(vec, vecp, file, &st, 1) == OK)
-               done(0);
-}
-
-
 /*
 ** Remove the draft file
 */