2 ** whatnowproc.c -- exec the "whatnowproc"
4 ** This code is Copyright (c) 2002, by the authors of nmh. See the
5 ** COPYRIGHT file in the root directory of the nmh distribution for
6 ** complete copyright information.
13 ** This routine is used by comp, repl, forw, and dist to exec
14 ** the "whatnowproc". It first sets up all the environment
15 ** variables that the "whatnowproc" will need to check, and
16 ** then execs the command.
19 what_now(char *ed, int nedit, int use, char *file, char *altmsg, int dist,
20 struct msgs *mp, char *text, char *cwd)
22 int found, k, msgnum, vecp;
25 char buffer[BUFSIZ], *vec[MAXARGS];
28 vec[vecp++] = mhbasename(whatnowproc);
31 m_putenv("mhdraft", file);
33 m_putenv("mhfolder", mp->foldpath);
37 if (mp == NULL || *altmsg == '/' || cwd == NULL)
38 m_putenv("mhaltmsg", altmsg);
40 snprintf(buffer, sizeof(buffer), "%s/%s",
41 mp->foldpath, altmsg);
42 m_putenv("mhaltmsg", buffer);
47 if ((bp = getenv("mhaltmsg")))/* XXX */
48 m_putenv("editalt", bp);
49 snprintf(buffer, sizeof(buffer), "%d", dist);
50 m_putenv("mhdist", buffer);
54 m_putenv("mheditor", ed ? ed : defaulteditor);
56 snprintf(buffer, sizeof(buffer), "%d", use);
57 m_putenv("mhuse", buffer);
59 unputenv("mhmessages");
60 unputenv("mhannotate");
62 if (text && mp && !is_readonly(mp)) {
65 buflen = sizeof(buffer);
66 for (msgnum = mp->lowmsg; msgnum <= mp->hghmsg; msgnum++) {
67 if (is_selected(mp, msgnum)) {
68 snprintf(bp, buflen, "%s%s", found ? " " : "",
73 for (k = msgnum + 1; k <= mp->hghmsg && is_selected(mp, k); k++)
76 snprintf(bp, buflen, "-%s", m_name(k));
86 m_putenv("mhmessages", buffer);
87 m_putenv("mhannotate", text);
91 context_save(); /* save the context file */
97 execvp(whatnowproc, vec);
98 fprintf(stderr, "unable to exec ");