]>
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/geteditor.h"
10 #include "sbr/context_save.h"
11 #include "sbr/error.h"
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.
26 what_now (char *ed
, int nedit
, int use
, char *file
, char *altmsg
, int dist
,
27 struct msgs
*mp
, char *text
, int inplace
, char *cwd
, int atfile
)
33 char buffer
[BUFSIZ
], *vec
[MAXARGS
];
36 vec
[vecp
++] = r1bindex (whatnowproc
, '/');
39 setenv("mhdraft", file
, 1);
41 setenv("mhfolder", mp
->foldpath
, 1);
45 if (mp
== NULL
|| *altmsg
== '/' || cwd
== NULL
)
46 setenv("mhaltmsg", altmsg
, 1);
48 snprintf (buffer
, sizeof(buffer
), "%s/%s", mp
->foldpath
, altmsg
);
49 setenv("mhaltmsg", buffer
, 1);
54 if ((bp
= getenv ("mhaltmsg")))/* XXX */
55 setenv("editalt", bp
, 1);
56 snprintf (buffer
, sizeof(buffer
), "%d", dist
);
57 setenv("mhdist", buffer
, 1);
62 ed
= get_default_editor();
63 setenv("mheditor", ed
, 1);
65 snprintf (buffer
, sizeof(buffer
), "%d", use
);
66 setenv("mhuse", buffer
, 1);
67 snprintf (buffer
, sizeof(buffer
), "%d", atfile
);
68 setenv("mhatfile", buffer
, 1);
70 unsetenv("mhmessages");
71 unsetenv("mhannotate");
72 unsetenv("mhinplace");
74 if (text
&& mp
&& !is_readonly(mp
)) {
77 buflen
= sizeof(buffer
);
78 for (msgnum
= mp
->lowmsg
; msgnum
<= mp
->hghmsg
; msgnum
++) {
79 if (is_selected(mp
, msgnum
)) {
80 snprintf (bp
, buflen
, "%s%s", found
? " " : "", m_name (msgnum
));
84 for (k
= msgnum
+ 1; k
<= mp
->hghmsg
&& is_selected(mp
, k
); k
++)
87 snprintf (bp
, buflen
, "-%s", m_name (k
));
97 setenv("mhmessages", buffer
, 1);
98 setenv("mhannotate", text
, 1);
99 snprintf (buffer
, sizeof(buffer
), "%d", inplace
);
100 setenv("mhinplace", buffer
, 1);
104 context_save (); /* save the context file */
108 if (chdir (cwd
) < 0) {
109 advise (cwd
, "chdir");
114 * If the "whatnowproc" is the nmh command "whatnow",
115 * we run it internally, rather than exec'ing it.
117 if (strcmp (vec
[0], "whatnow") == 0) {
122 execvp (whatnowproc
, vec
);
123 fprintf (stderr
, "unable to exec ");
124 perror (whatnowproc
);