]>
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/context_save.h"
10 #include "sbr/error.h"
15 * This routine is used by comp, repl, forw, and dist to exec
16 * the "whatnowproc". It first sets up all the environment
17 * variables that the "whatnowproc" will need to check, and
18 * then execs the command. As an optimization, if the
19 * "whatnowproc" is the nmh command "whatnow" (typical case),
20 * it will call this routine directly without exec'ing it.
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
, int atfile
)
32 char buffer
[BUFSIZ
], *vec
[MAXARGS
];
35 vec
[vecp
++] = r1bindex (whatnowproc
, '/');
38 setenv("mhdraft", file
, 1);
40 setenv("mhfolder", mp
->foldpath
, 1);
44 if (mp
== NULL
|| *altmsg
== '/' || cwd
== NULL
)
45 setenv("mhaltmsg", altmsg
, 1);
47 snprintf (buffer
, sizeof(buffer
), "%s/%s", mp
->foldpath
, altmsg
);
48 setenv("mhaltmsg", buffer
, 1);
53 if ((bp
= getenv ("mhaltmsg")))/* XXX */
54 setenv("editalt", bp
, 1);
55 snprintf (buffer
, sizeof(buffer
), "%d", dist
);
56 setenv("mhdist", buffer
, 1);
61 ed
= get_default_editor();
62 setenv("mheditor", ed
, 1);
64 snprintf (buffer
, sizeof(buffer
), "%d", use
);
65 setenv("mhuse", buffer
, 1);
66 snprintf (buffer
, sizeof(buffer
), "%d", atfile
);
67 setenv("mhatfile", buffer
, 1);
69 unsetenv("mhmessages");
70 unsetenv("mhannotate");
71 unsetenv("mhinplace");
73 if (text
&& mp
&& !is_readonly(mp
)) {
76 buflen
= sizeof(buffer
);
77 for (msgnum
= mp
->lowmsg
; msgnum
<= mp
->hghmsg
; msgnum
++) {
78 if (is_selected(mp
, msgnum
)) {
79 snprintf (bp
, buflen
, "%s%s", found
? " " : "", m_name (msgnum
));
83 for (k
= msgnum
+ 1; k
<= mp
->hghmsg
&& is_selected(mp
, k
); k
++)
86 snprintf (bp
, buflen
, "-%s", m_name (k
));
96 setenv("mhmessages", buffer
, 1);
97 setenv("mhannotate", text
, 1);
98 snprintf (buffer
, sizeof(buffer
), "%d", inplace
);
99 setenv("mhinplace", buffer
, 1);
103 context_save (); /* save the context file */
107 if (chdir (cwd
) < 0) {
108 advise (cwd
, "chdir");
113 * If the "whatnowproc" is the nmh command "whatnow",
114 * we run it internally, rather than exec'ing it.
116 if (strcmp (vec
[0], "whatnow") == 0) {
121 execvp (whatnowproc
, vec
);
122 fprintf (stderr
, "unable to exec ");
123 perror (whatnowproc
);