]>
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.
12 * This routine is used by comp, repl, forw, and dist to exec
13 * the "whatnowproc". It first sets up all the environment
14 * variables that the "whatnowproc" will need to check, and
15 * then execs the command. As an optimization, if the
16 * "whatnowproc" is the nmh command "whatnow" (typical case),
17 * it will call this routine directly without exec'ing it.
22 what_now (char *ed
, int nedit
, int use
, char *file
, char *altmsg
, int dist
,
23 struct msgs
*mp
, char *text
, int inplace
, char *cwd
, int atfile
)
25 int found
, k
, msgnum
, vecp
;
28 char buffer
[BUFSIZ
], *vec
[MAXARGS
];
31 vec
[vecp
++] = r1bindex (whatnowproc
, '/');
34 setenv("mhdraft", file
, 1);
36 setenv("mhfolder", mp
->foldpath
, 1);
40 if (mp
== NULL
|| *altmsg
== '/' || cwd
== NULL
)
41 setenv("mhaltmsg", altmsg
, 1);
43 snprintf (buffer
, sizeof(buffer
), "%s/%s", mp
->foldpath
, altmsg
);
44 setenv("mhaltmsg", buffer
, 1);
49 if ((bp
= getenv ("mhaltmsg")))/* XXX */
50 setenv("editalt", bp
, 1);
51 snprintf (buffer
, sizeof(buffer
), "%d", dist
);
52 setenv("mhdist", buffer
, 1);
57 ed
= get_default_editor();
58 setenv("mheditor", ed
, 1);
60 snprintf (buffer
, sizeof(buffer
), "%d", use
);
61 setenv("mhuse", buffer
, 1);
62 snprintf (buffer
, sizeof(buffer
), "%d", atfile
);
63 setenv("mhatfile", buffer
, 1);
65 unsetenv("mhmessages");
66 unsetenv("mhannotate");
67 unsetenv("mhinplace");
69 if (text
&& mp
&& !is_readonly(mp
)) {
72 buflen
= sizeof(buffer
);
73 for (msgnum
= mp
->lowmsg
; msgnum
<= mp
->hghmsg
; msgnum
++) {
74 if (is_selected(mp
, msgnum
)) {
75 snprintf (bp
, buflen
, "%s%s", found
? " " : "", m_name (msgnum
));
79 for (k
= msgnum
+ 1; k
<= mp
->hghmsg
&& is_selected(mp
, k
); k
++)
82 snprintf (bp
, buflen
, "-%s", m_name (k
));
92 setenv("mhmessages", buffer
, 1);
93 setenv("mhannotate", text
, 1);
94 snprintf (buffer
, sizeof(buffer
), "%d", inplace
);
95 setenv("mhinplace", buffer
, 1);
99 context_save (); /* save the context file */
103 if (chdir (cwd
) < 0) {
104 advise (cwd
, "chdir");
109 * If the "whatnowproc" is the nmh command "whatnow",
110 * we run it internally, rather than exec'ing it.
112 if (strcmp (vec
[0], "whatnow") == 0) {
117 execvp (whatnowproc
, vec
);
118 fprintf (stderr
, "unable to exec ");
119 perror (whatnowproc
);