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 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);
52 m_putenv("mheditor", defaulteditor);
54 m_putenv("mheditor", ed);
58 snprintf(buffer, sizeof(buffer), "%d", use);
59 m_putenv("mhuse", buffer);
61 unputenv("mhmessages");
62 unputenv("mhannotate");
64 if (text && mp && !is_readonly(mp)) {
67 buflen = sizeof(buffer);
68 for (msgnum = mp->lowmsg; msgnum <= mp->hghmsg; msgnum++) {
69 if (is_selected(mp, msgnum)) {
70 snprintf(bp, buflen, "%s%s", found ? " " : "",
75 for (k = msgnum + 1; k <= mp->hghmsg && is_selected(mp, k); k++)
78 snprintf(bp, buflen, "-%s", m_name(k));
88 m_putenv("mhmessages", buffer);
89 m_putenv("mhannotate", text);
93 context_save(); /* save the context file */
99 execvp(whatnowproc, vec);
100 fprintf(stderr, "unable to exec ");