]>
diplodocus.org Git - nmh/blob - uip/whatnowproc.c
1 /* whatnowproc.c -- exec the "whatnowproc"
3 * This code is Copyright (c) 2002, by the authors of nmh. See the
4 * COPYRIGHT file in the root directory of the nmh distribution for
5 * complete copyright information.
9 #include "sbr/r1bindex.h"
10 #include "sbr/geteditor.h"
11 #include "sbr/context_save.h"
12 #include "sbr/error.h"
17 * This routine is used by comp, repl, forw, and dist to exec
18 * the "whatnowproc". It first sets up all the environment
19 * variables that the "whatnowproc" will need to check, and
20 * then execs the command. As an optimization, if the
21 * "whatnowproc" is the nmh command "whatnow" (typical case),
22 * it will call this routine directly without exec'ing it.
27 what_now (char *ed
, int nedit
, int use
, char *file
, char *altmsg
, int dist
,
28 struct msgs
*mp
, char *text
, int inplace
, char *cwd
, int atfile
)
34 char buffer
[BUFSIZ
], *vec
[MAXARGS
];
37 vec
[vecp
++] = r1bindex (whatnowproc
, '/');
40 setenv("mhdraft", file
, 1);
42 setenv("mhfolder", mp
->foldpath
, 1);
46 if (mp
== NULL
|| *altmsg
== '/' || cwd
== NULL
)
47 setenv("mhaltmsg", altmsg
, 1);
49 snprintf (buffer
, sizeof(buffer
), "%s/%s", mp
->foldpath
, altmsg
);
50 setenv("mhaltmsg", buffer
, 1);
55 if ((bp
= getenv ("mhaltmsg")))/* XXX */
56 setenv("editalt", bp
, 1);
57 snprintf (buffer
, sizeof(buffer
), "%d", dist
);
58 setenv("mhdist", buffer
, 1);
63 ed
= get_default_editor();
64 setenv("mheditor", ed
, 1);
66 snprintf (buffer
, sizeof(buffer
), "%d", use
);
67 setenv("mhuse", buffer
, 1);
68 snprintf (buffer
, sizeof(buffer
), "%d", atfile
);
69 setenv("mhatfile", buffer
, 1);
71 unsetenv("mhmessages");
72 unsetenv("mhannotate");
73 unsetenv("mhinplace");
75 if (text
&& mp
&& !is_readonly(mp
)) {
78 buflen
= sizeof(buffer
);
79 for (msgnum
= mp
->lowmsg
; msgnum
<= mp
->hghmsg
; msgnum
++) {
80 if (is_selected(mp
, msgnum
)) {
81 snprintf (bp
, buflen
, "%s%s", found
? " " : "", m_name (msgnum
));
85 for (k
= msgnum
+ 1; k
<= mp
->hghmsg
&& is_selected(mp
, k
); k
++)
88 snprintf (bp
, buflen
, "-%s", m_name (k
));
98 setenv("mhmessages", buffer
, 1);
99 setenv("mhannotate", text
, 1);
100 snprintf (buffer
, sizeof(buffer
), "%d", inplace
);
101 setenv("mhinplace", buffer
, 1);
105 context_save (); /* save the context file */
109 if (chdir (cwd
) < 0) {
110 advise (cwd
, "chdir");
115 * If the "whatnowproc" is the nmh command "whatnow",
116 * we run it internally, rather than exec'ing it.
118 if (strcmp (vec
[0], "whatnow") == 0) {
123 execvp (whatnowproc
, vec
);
124 fprintf (stderr
, "unable to exec ");
125 perror (whatnowproc
);