]>
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.
20 /* from whatnowsbr.c */
21 int WhatNow (int, char **);
25 what_now (char *ed
, int nedit
, int use
, char *file
, char *altmsg
, int dist
,
26 struct msgs
*mp
, char *text
, int inplace
, char *cwd
)
28 int found
, k
, msgnum
, vecp
;
31 char buffer
[BUFSIZ
], *vec
[MAXARGS
];
34 vec
[vecp
++] = r1bindex (whatnowproc
, '/');
37 m_putenv ("mhdraft", file
);
39 m_putenv ("mhfolder", mp
->foldpath
);
41 unputenv ("mhfolder");
43 if (mp
== NULL
|| *altmsg
== '/' || cwd
== NULL
)
44 m_putenv ("mhaltmsg", altmsg
);
46 snprintf (buffer
, sizeof(buffer
), "%s/%s", mp
->foldpath
, altmsg
);
47 m_putenv ("mhaltmsg", buffer
);
50 unputenv ("mhaltmsg");
52 if ((bp
= getenv ("mhaltmsg")))/* XXX */
53 m_putenv ("editalt", bp
);
54 snprintf (buffer
, sizeof(buffer
), "%d", dist
);
55 m_putenv ("mhdist", buffer
);
57 unputenv ("mheditor");
59 m_putenv ("mheditor", ed
? ed
: (ed
= context_find ("editor"))
60 ? ed
: defaulteditor
);
62 snprintf (buffer
, sizeof(buffer
), "%d", use
);
63 m_putenv ("mhuse", buffer
);
65 unputenv ("mhmessages");
66 unputenv ("mhannotate");
67 unputenv ("mhinplace");
69 if (text
&& mp
&& !is_readonly(mp
)) {
72 buflen
= sizeof(buffer
);
73 for (msgnum
= mp
->lowmsg
; msgnum
<= mp
->hghmsg
; msgnum
++) {
74 if (is_selected(mp
, msgnum
)) {
75 snprintf (bp
, buflen
, "%s%s", found
? " " : "", m_name (msgnum
));
79 for (k
= msgnum
+ 1; k
<= mp
->hghmsg
&& is_selected(mp
, k
); k
++)
82 snprintf (bp
, buflen
, "-%s", m_name (k
));
92 m_putenv ("mhmessages", buffer
);
93 m_putenv ("mhannotate", text
);
94 snprintf (buffer
, sizeof(buffer
), "%d", inplace
);
95 m_putenv ("mhinplace", buffer
);
99 context_save (); /* save the context file */
106 * If the "whatnowproc" is the nmh command "whatnow",
107 * we run it internally, rather than exec'ing it.
109 if (strcmp (vec
[0], "whatnow") == 0) {
114 execvp (whatnowproc
, vec
);
115 fprintf (stderr
, "unable to exec ");
116 perror (whatnowproc
);