]>
diplodocus.org Git - nmh/blob - uip/whatnowproc.c
3 * whatnowproc.c -- exec the "whatnowproc"
5 * This code is Copyright (c) 2002, by the authors of nmh. See the
6 * COPYRIGHT file in the root directory of the nmh distribution for
7 * 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. As an optimization, if the
18 * "whatnowproc" is the nmh command "whatnow" (typical case),
19 * it will call this routine directly without exec'ing it.
24 what_now (char *ed
, int nedit
, int use
, char *file
, char *altmsg
, int dist
,
25 struct msgs
*mp
, char *text
, int inplace
, char *cwd
, int atfile
)
27 int found
, k
, msgnum
, vecp
;
30 char buffer
[BUFSIZ
], *vec
[MAXARGS
];
33 vec
[vecp
++] = r1bindex (whatnowproc
, '/');
36 m_putenv ("mhdraft", file
);
38 m_putenv ("mhfolder", mp
->foldpath
);
40 unputenv ("mhfolder");
42 if (mp
== NULL
|| *altmsg
== '/' || cwd
== NULL
)
43 m_putenv ("mhaltmsg", altmsg
);
45 snprintf (buffer
, sizeof(buffer
), "%s/%s", mp
->foldpath
, altmsg
);
46 m_putenv ("mhaltmsg", buffer
);
49 unputenv ("mhaltmsg");
51 if ((bp
= getenv ("mhaltmsg")))/* XXX */
52 m_putenv ("editalt", bp
);
53 snprintf (buffer
, sizeof(buffer
), "%d", dist
);
54 m_putenv ("mhdist", buffer
);
56 unputenv ("mheditor");
58 m_putenv ("mheditor", ed
? ed
: (ed
= context_find ("editor"))
59 ? ed
: defaulteditor
);
61 snprintf (buffer
, sizeof(buffer
), "%d", use
);
62 m_putenv ("mhuse", buffer
);
63 snprintf (buffer
, sizeof(buffer
), "%d", atfile
);
64 m_putenv ("mhatfile", buffer
);
66 unputenv ("mhmessages");
67 unputenv ("mhannotate");
68 unputenv ("mhinplace");
70 if (text
&& mp
&& !is_readonly(mp
)) {
73 buflen
= sizeof(buffer
);
74 for (msgnum
= mp
->lowmsg
; msgnum
<= mp
->hghmsg
; msgnum
++) {
75 if (is_selected(mp
, msgnum
)) {
76 snprintf (bp
, buflen
, "%s%s", found
? " " : "", m_name (msgnum
));
80 for (k
= msgnum
+ 1; k
<= mp
->hghmsg
&& is_selected(mp
, k
); k
++)
83 snprintf (bp
, buflen
, "-%s", m_name (k
));
93 m_putenv ("mhmessages", buffer
);
94 m_putenv ("mhannotate", text
);
95 snprintf (buffer
, sizeof(buffer
), "%d", inplace
);
96 m_putenv ("mhinplace", buffer
);
100 context_save (); /* save the context file */
107 * If the "whatnowproc" is the nmh command "whatnow",
108 * we run it internally, rather than exec'ing it.
110 if (strcmp (vec
[0], "whatnow") == 0) {
115 execvp (whatnowproc
, vec
);
116 fprintf (stderr
, "unable to exec ");
117 perror (whatnowproc
);