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 : (ed = context_find("editor")) ?
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 ");