]>
diplodocus.org Git - nmh/blob - uip/whatnowproc.c
3 * whatnowproc.c -- exec the "whatnowproc"
12 * This routine is used by comp, repl, forw, and dist to exec
13 * the "whatnowproc". It first sets up all the environment
14 * variables that the "whatnowproc" will need to check, and
15 * then execs the command. As an optimization, if the
16 * "whatnowproc" is the nmh command "whatnow" (typical case),
17 * it will call this routine directly without exec'ing it.
21 what_now (char *ed
, int nedit
, int use
, char *file
, char *altmsg
, int dist
,
22 struct msgs
*mp
, char *text
, int inplace
, char *cwd
)
24 int found
, k
, msgnum
, vecp
;
27 char buffer
[BUFSIZ
], *vec
[MAXARGS
];
30 vec
[vecp
++] = r1bindex (whatnowproc
, '/');
33 m_putenv ("mhdraft", file
);
35 m_putenv ("mhfolder", mp
->foldpath
);
37 unputenv ("mhfolder");
39 if (mp
== NULL
|| *altmsg
== '/' || cwd
== NULL
)
40 m_putenv ("mhaltmsg", altmsg
);
42 snprintf (buffer
, sizeof(buffer
), "%s/%s", mp
->foldpath
, altmsg
);
43 m_putenv ("mhaltmsg", buffer
);
46 unputenv ("mhaltmsg");
48 if ((bp
= getenv ("mhaltmsg")))/* XXX */
49 m_putenv ("editalt", bp
);
50 snprintf (buffer
, sizeof(buffer
), "%d", dist
);
51 m_putenv ("mhdist", buffer
);
53 unputenv ("mheditor");
55 m_putenv ("mheditor", ed
? ed
: (ed
= context_find ("editor"))
56 ? ed
: defaulteditor
);
58 snprintf (buffer
, sizeof(buffer
), "%d", use
);
59 m_putenv ("mhuse", buffer
);
61 unputenv ("mhmessages");
62 unputenv ("mhannotate");
63 unputenv ("mhinplace");
65 if (text
&& mp
&& !is_readonly(mp
)) {
68 buflen
= sizeof(buffer
);
69 for (msgnum
= mp
->lowmsg
; msgnum
<= mp
->hghmsg
; msgnum
++) {
70 if (is_selected(mp
, msgnum
)) {
71 snprintf (bp
, buflen
, "%s%s", found
? " " : "", m_name (msgnum
));
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
);
90 snprintf (buffer
, sizeof(buffer
), "%d", inplace
);
91 m_putenv ("mhinplace", buffer
);
95 context_save (); /* save the context file */
102 * If the "whatnowproc" is the nmh command "whatnow",
103 * we run it internally, rather than exec'ing it.
105 if (strcmp (vec
[0], "whatnow") == 0) {
110 execvp (whatnowproc
, vec
);
111 fprintf (stderr
, "unable to exec ");
112 perror (whatnowproc
);