3 * whatnowproc.c -- exec the "whatnowproc"
7 * This code is Copyright (c) 2002, by the authors of nmh. See the
8 * COPYRIGHT file in the root directory of the nmh distribution for
9 * complete copyright information.
16 * This routine is used by comp, repl, forw, and dist to exec
17 * the "whatnowproc". It first sets up all the environment
18 * variables that the "whatnowproc" will need to check, and
19 * then execs the command. As an optimization, if the
20 * "whatnowproc" is the nmh command "whatnow" (typical case),
21 * it will call this routine directly without exec'ing it.
24 /* from whatnowsbr.c */
25 int WhatNow (int, char **);
29 what_now (char *ed, int nedit, int use, char *file, char *altmsg, int dist,
30 struct msgs *mp, char *text, int inplace, char *cwd)
32 int found, k, msgnum, vecp;
35 char buffer[BUFSIZ], *vec[MAXARGS];
38 vec[vecp++] = r1bindex (whatnowproc, '/');
41 m_putenv ("mhdraft", file);
43 m_putenv ("mhfolder", mp->foldpath);
45 unputenv ("mhfolder");
47 if (mp == NULL || *altmsg == '/' || cwd == NULL)
48 m_putenv ("mhaltmsg", altmsg);
50 snprintf (buffer, sizeof(buffer), "%s/%s", mp->foldpath, altmsg);
51 m_putenv ("mhaltmsg", buffer);
54 unputenv ("mhaltmsg");
56 if ((bp = getenv ("mhaltmsg")))/* XXX */
57 m_putenv ("editalt", bp);
58 snprintf (buffer, sizeof(buffer), "%d", dist);
59 m_putenv ("mhdist", buffer);
61 unputenv ("mheditor");
63 m_putenv ("mheditor", ed ? ed : (ed = context_find ("editor"))
64 ? ed : defaulteditor);
66 snprintf (buffer, sizeof(buffer), "%d", use);
67 m_putenv ("mhuse", buffer);
69 unputenv ("mhmessages");
70 unputenv ("mhannotate");
71 unputenv ("mhinplace");
73 if (text && mp && !is_readonly(mp)) {
76 buflen = sizeof(buffer);
77 for (msgnum = mp->lowmsg; msgnum <= mp->hghmsg; msgnum++) {
78 if (is_selected(mp, msgnum)) {
79 snprintf (bp, buflen, "%s%s", found ? " " : "", m_name (msgnum));
83 for (k = msgnum + 1; k <= mp->hghmsg && is_selected(mp, k); k++)
86 snprintf (bp, buflen, "-%s", m_name (k));
96 m_putenv ("mhmessages", buffer);
97 m_putenv ("mhannotate", text);
98 snprintf (buffer, sizeof(buffer), "%d", inplace);
99 m_putenv ("mhinplace", buffer);
103 context_save (); /* save the context file */
110 * If the "whatnowproc" is the nmh command "whatnow",
111 * we run it internally, rather than exec'ing it.
113 if (strcmp (vec[0], "whatnow") == 0) {
118 execvp (whatnowproc, vec);
119 fprintf (stderr, "unable to exec ");
120 perror (whatnowproc);