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.
14 ** This routine is used by comp, repl, forw, and dist to exec
15 ** the "whatnowproc". It first sets up all the environment
16 ** variables that the "whatnowproc" will need to check, and
17 ** then execs the command.
20 what_now(char *ed, int use, char *file, char *altmsg, int dist,
21 struct msgs *mp, char *text, char *cwd)
23 int found, k, msgnum, vecp;
26 char buffer[BUFSIZ], *vec[MAXARGS];
29 vec[vecp++] = mhbasename(whatnowproc);
32 m_putenv("mhdraft", file);
34 m_putenv("mhfolder", mp->foldpath);
38 if (mp == NULL || *altmsg == '/' || cwd == NULL)
39 m_putenv("mhaltmsg", altmsg);
41 snprintf(buffer, sizeof(buffer), "%s/%s",
42 mp->foldpath, altmsg);
43 m_putenv("mhaltmsg", buffer);
48 snprintf(buffer, sizeof(buffer), "%d", dist);
49 m_putenv("mhdist", buffer);
51 m_putenv("mheditor", defaulteditor);
53 m_putenv("mheditor", ed);
57 snprintf(buffer, sizeof(buffer), "%d", use);
58 m_putenv("mhuse", buffer);
60 unputenv("mhmessages");
61 unputenv("mhannotate");
63 if (text && mp && !is_readonly(mp)) {
66 buflen = sizeof(buffer);
67 for (msgnum = mp->lowmsg; msgnum <= mp->hghmsg; msgnum++) {
68 if (is_selected(mp, msgnum)) {
69 snprintf(bp, buflen, "%s%s", found ? " " : "",
74 for (k = msgnum + 1; k <= mp->hghmsg && is_selected(mp, k); k++)
77 snprintf(bp, buflen, "-%s", m_name(k));
87 m_putenv("mhmessages", buffer);
88 m_putenv("mhannotate", text);
92 context_save(); /* save the context file */
98 execvp(whatnowproc, vec);
99 fprintf(stderr, "unable to exec ");