]>
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 "whatnowsbr.h"
10 #include "whatnowproc.h"
11 #include "sbr/m_name.h"
12 #include "sbr/r1bindex.h"
13 #include "sbr/geteditor.h"
14 #include "sbr/context_save.h"
15 #include "sbr/error.h"
20 * This routine is used by comp, repl, forw, and dist to exec
21 * the "whatnowproc". It first sets up all the environment
22 * variables that the "whatnowproc" will need to check, and
23 * then execs the command. As an optimization, if the
24 * "whatnowproc" is the nmh command "whatnow" (typical case),
25 * it will call this routine directly without exec'ing it.
30 what_now (char *ed
, int nedit
, int use
, char *file
, char *altmsg
, int dist
,
31 struct msgs
*mp
, char *text
, int inplace
, char *cwd
, int atfile
)
37 char buffer
[BUFSIZ
], *vec
[MAXARGS
];
40 vec
[vecp
++] = r1bindex (whatnowproc
, '/');
43 setenv("mhdraft", file
, 1);
45 setenv("mhfolder", mp
->foldpath
, 1);
49 if (mp
== NULL
|| *altmsg
== '/' || cwd
== NULL
)
50 setenv("mhaltmsg", altmsg
, 1);
52 snprintf (buffer
, sizeof(buffer
), "%s/%s", mp
->foldpath
, altmsg
);
53 setenv("mhaltmsg", buffer
, 1);
58 if ((bp
= getenv ("mhaltmsg")))/* XXX */
59 setenv("editalt", bp
, 1);
60 snprintf (buffer
, sizeof(buffer
), "%d", dist
);
61 setenv("mhdist", buffer
, 1);
66 ed
= get_default_editor();
67 setenv("mheditor", ed
, 1);
69 snprintf (buffer
, sizeof(buffer
), "%d", use
);
70 setenv("mhuse", buffer
, 1);
71 snprintf (buffer
, sizeof(buffer
), "%d", atfile
);
72 setenv("mhatfile", buffer
, 1);
74 unsetenv("mhmessages");
75 unsetenv("mhannotate");
76 unsetenv("mhinplace");
78 if (text
&& mp
&& !is_readonly(mp
)) {
81 buflen
= sizeof(buffer
);
82 for (msgnum
= mp
->lowmsg
; msgnum
<= mp
->hghmsg
; msgnum
++) {
83 if (is_selected(mp
, msgnum
)) {
84 snprintf (bp
, buflen
, "%s%s", found
? " " : "", m_name (msgnum
));
88 for (k
= msgnum
+ 1; k
<= mp
->hghmsg
&& is_selected(mp
, k
); k
++)
91 snprintf (bp
, buflen
, "-%s", m_name (k
));
101 setenv("mhmessages", buffer
, 1);
102 setenv("mhannotate", text
, 1);
103 snprintf (buffer
, sizeof(buffer
), "%d", inplace
);
104 setenv("mhinplace", buffer
, 1);
108 context_save (); /* save the context file */
112 if (chdir (cwd
) < 0) {
113 advise (cwd
, "chdir");
118 * If the "whatnowproc" is the nmh command "whatnow",
119 * we run it internally, rather than exec'ing it.
121 if (strcmp (vec
[0], "whatnow") == 0) {
126 execvp (whatnowproc
, vec
);
127 fprintf (stderr
, "unable to exec ");
128 perror (whatnowproc
);