Removed the altmsglink (named `@') and env var `$editalt' for repl and dist.
[mmh] / uip / whatnow.c
index 7217096..e3a411a 100644 (file)
@@ -92,8 +92,7 @@ static char *myprompt = "\nWhat now? ";
 /*
 ** static prototypes
 */
-static int editfile(char **, char **, char *, int, struct msgs *,
-       char *, char *);
+static int editfile(char **, char **, char *, int);
 static int sendfile(char **, char *);
 static int refile(char **, char *);
 static int removefile(char *);
@@ -103,17 +102,12 @@ static FILE* popen_in_dir(const char *dir, const char *cmd, const char *type);
 static int system_in_dir(const char *dir, const char *cmd);
 
 
-#ifdef HAVE_LSTAT
-static int copyf(char *, char *);
-#endif
-
-
 int
 main(int argc, char **argv)
 {
        int use = 0;
        char *cp;
-       char *ed = NULL, *drft = NULL, *msgnam = NULL;
+       char *ed = NULL, *drft = NULL;
        char buf[BUFSIZ], prompt[BUFSIZ];
        char **argp, **arguments;
        struct stat st;
@@ -185,8 +179,6 @@ main(int argc, char **argv)
        if ((!drft && !(drft = getenv("mhdraft"))) || !*drft)
                drft = getcpy(m_draft(seq_cur));
 
-       msgnam = (cp = getenv("mhaltmsg")) && *cp ? getcpy(cp) : NULL;
-
        if ((cp = getenv("mhuse")) && *cp)
                use = atoi(cp);
 
@@ -196,7 +188,7 @@ 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 (editfile(&ed, NULL, drft, use) <0) {
                        if (!use) {
                                unlink(drft);
                        }
@@ -208,15 +200,14 @@ main(int argc, char **argv)
        snprintf(prompt, sizeof(prompt), myprompt, invo_name);
        for (;;) {
                if (!(argp = getans(prompt, aleqs))) {
-                       unlink(altmsglink);
                        done(1);
                }
                switch (smatch(*argp, aleqs)) {
                case DISPSW:
                        /* display the msg being replied to or distributed */
-                       if (msgnam) {
+                       if ((cp = getenv("mhaltmsg")) && *cp) {
                                snprintf(buf, sizeof buf, "%s '%s'",
-                                               listproc, msgnam);
+                                               listproc, cp);
                                system(buf);
                        } else {
                                advise(NULL, "no alternate message to display");
@@ -227,7 +218,7 @@ main(int argc, char **argv)
                        /* Call an editor on the draft file */
                        if (*++argp)
                                ed = *argp++;
-                       editfile(&ed, argp, drft, NOUSE, NULL, msgnam, NULL);
+                       editfile(&ed, argp, drft, NOUSE);
                        break;
 
                case LISTSW:
@@ -575,17 +566,10 @@ static char *edsave = NULL;  /* the editor we used previously */
 
 
 static int
-editfile(char **ed, char **arg, char *file, int use, struct msgs *mp,
-       char *altmsg, char *cwd)
+editfile(char **ed, char **arg, char *file, int use)
 {
        int pid, status, vecp;
-       char altpath[BUFSIZ], linkpath[BUFSIZ];
        char *cp, *vec[MAXARGS];
-       struct stat st;
-
-#ifdef HAVE_LSTAT
-       int slinked = 0;
-#endif /* HAVE_LSTAT */
 
        if (!*ed || !**ed) {
                /* We have no explicit editor. */
@@ -605,31 +589,7 @@ editfile(char **ed, char **arg, char *file, int use, struct msgs *mp,
                }
        }
 
-       if (altmsg) {
-               if (!mp || *altmsg == '/' || !cwd)
-                       strncpy(altpath, altmsg, sizeof(altpath));
-               else
-                       snprintf(altpath, sizeof(altpath), "%s/%s",
-                                       mp->foldpath, altmsg);
-               if (!cwd)
-                       strncpy(linkpath, altmsglink, sizeof(linkpath));
-               else
-                       snprintf(linkpath, sizeof(linkpath), "%s/%s",
-                                       cwd, altmsglink);
-               unlink(linkpath);
-#ifdef HAVE_LSTAT
-               if (link(altpath, linkpath) == NOTOK) {
-                       symlink(altpath, linkpath);
-                       slinked = 1;
-               } else {
-                       slinked = 0;
-               }
-#else /* not HAVE_LSTAT */
-               link(altpath, linkpath);
-#endif /* not HAVE_LSTAT */
-       }
-
-       context_save();  /* save the context file */
+       context_save();
        fflush(stdout);
 
        switch (pid = fork()) {
@@ -639,14 +599,6 @@ editfile(char **ed, char **arg, char *file, int use, struct msgs *mp,
                break;
 
        case OK:
-               if (cwd)
-                       chdir(cwd);
-               if (altmsg) {
-                       if (mp)
-                               m_putenv("mhfolder", mp->foldpath);
-                       m_putenv("editalt", altpath);
-               }
-
                vecp = 0;
                vec[vecp++] = mhbasename(*ed);
                if (arg)
@@ -679,68 +631,17 @@ editfile(char **ed, char **arg, char *file, int use, struct msgs *mp,
                        status = -1;
                        break;
                }
-
-#ifdef HAVE_LSTAT
-               if (altmsg && mp && !is_readonly(mp) && (slinked ?
-                               lstat (linkpath, &st) != NOTOK &&
-                               S_ISREG(st.st_mode) &&
-                               copyf(linkpath, altpath) == NOTOK :
-                               stat(linkpath, &st) != NOTOK &&
-                               st.st_nlink == 1 &&
-                               (unlink(altpath) == NOTOK ||
-                               link(linkpath, altpath) == NOTOK)))
-                       advise(linkpath, "unable to update %s from", altmsg);
-#else /* HAVE_LSTAT */
-               if (altmsg && mp && !is_readonly(mp) &&
-                               stat(linkpath, &st) != NOTOK &&
-                               st.st_nlink == 1 &&
-                               (unlink(altpath) == NOTOK ||
-                               link(linkpath, altpath) == NOTOK))
-                       advise(linkpath, "unable to update %s from", altmsg);
-#endif /* HAVE_LSTAT */
        }
 
        /* remember which editor we used */
        edsave = getcpy(*ed);
 
        *ed = NULL;
-       if (altmsg) {
-               unlink(linkpath);
-       }
 
        return status;
 }
 
 
-#ifdef HAVE_LSTAT
-static int
-copyf(char *ifile, char *ofile)
-{
-       int i, in, out;
-       char buffer[BUFSIZ];
-
-       if ((in = open(ifile, O_RDONLY)) == NOTOK)
-               return NOTOK;
-       if ((out = open(ofile, O_WRONLY | O_TRUNC)) == NOTOK) {
-               admonish(ofile, "unable to open and truncate");
-               close(in);
-               return NOTOK;
-       }
-
-       while ((i = read(in, buffer, sizeof(buffer))) > OK)
-               if (write(out, buffer, i) != i) {
-                       advise(ofile, "may have damaged");
-                       i = NOTOK;
-                       break;
-               }
-
-       close(in);
-       close(out);
-       return i;
-}
-#endif /* HAVE_LSTAT */
-
-
 /*
 ** SEND
 */