]>
diplodocus.org Git - nmh/blob - uip/whatnowproc.c
6a10dba657c322500b35dfea23bc75fdafc8ea4d
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 "whatnowproc.h"
10 #include "sbr/m_name.h"
11 #include "sbr/r1bindex.h"
12 #include "sbr/geteditor.h"
13 #include "sbr/context_save.h"
14 #include "sbr/error.h"
19 * This routine is used by comp, repl, forw, and dist to exec
20 * the "whatnowproc". It first sets up all the environment
21 * variables that the "whatnowproc" will need to check, and
22 * then execs the command. As an optimization, if the
23 * "whatnowproc" is the nmh command "whatnow" (typical case),
24 * it will call this routine directly without exec'ing it.
29 what_now (char *ed
, int nedit
, int use
, char *file
, char *altmsg
, int dist
,
30 struct msgs
*mp
, char *text
, int inplace
, char *cwd
, int atfile
)
36 char buffer
[BUFSIZ
], *vec
[MAXARGS
];
39 vec
[vecp
++] = r1bindex (whatnowproc
, '/');
42 setenv("mhdraft", file
, 1);
44 setenv("mhfolder", mp
->foldpath
, 1);
48 if (mp
== NULL
|| *altmsg
== '/' || cwd
== NULL
)
49 setenv("mhaltmsg", altmsg
, 1);
51 snprintf (buffer
, sizeof(buffer
), "%s/%s", mp
->foldpath
, altmsg
);
52 setenv("mhaltmsg", buffer
, 1);
57 if ((bp
= getenv ("mhaltmsg")))/* XXX */
58 setenv("editalt", bp
, 1);
59 snprintf (buffer
, sizeof(buffer
), "%d", dist
);
60 setenv("mhdist", buffer
, 1);
65 ed
= get_default_editor();
66 setenv("mheditor", ed
, 1);
68 snprintf (buffer
, sizeof(buffer
), "%d", use
);
69 setenv("mhuse", buffer
, 1);
70 snprintf (buffer
, sizeof(buffer
), "%d", atfile
);
71 setenv("mhatfile", buffer
, 1);
73 unsetenv("mhmessages");
74 unsetenv("mhannotate");
75 unsetenv("mhinplace");
77 if (text
&& mp
&& !is_readonly(mp
)) {
80 buflen
= sizeof(buffer
);
81 for (msgnum
= mp
->lowmsg
; msgnum
<= mp
->hghmsg
; msgnum
++) {
82 if (is_selected(mp
, msgnum
)) {
83 snprintf (bp
, buflen
, "%s%s", found
? " " : "", m_name (msgnum
));
87 for (k
= msgnum
+ 1; k
<= mp
->hghmsg
&& is_selected(mp
, k
); k
++)
90 snprintf (bp
, buflen
, "-%s", m_name (k
));
100 setenv("mhmessages", buffer
, 1);
101 setenv("mhannotate", text
, 1);
102 snprintf (buffer
, sizeof(buffer
), "%d", inplace
);
103 setenv("mhinplace", buffer
, 1);
107 context_save (); /* save the context file */
111 if (chdir (cwd
) < 0) {
112 advise (cwd
, "chdir");
117 * If the "whatnowproc" is the nmh command "whatnow",
118 * we run it internally, rather than exec'ing it.
120 if (strcmp (vec
[0], "whatnow") == 0) {
125 execvp (whatnowproc
, vec
);
126 fprintf (stderr
, "unable to exec ");
127 perror (whatnowproc
);