]>
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.
14 * This routine is used by comp, repl, forw, and dist to exec
15 * the "whatnowproc". It first sets up all the environment
16 * variables that the "whatnowproc" will need to check, and
17 * then execs the command. As an optimization, if the
18 * "whatnowproc" is the nmh command "whatnow" (typical case),
19 * it will call this routine directly without exec'ing it.
24 what_now (char *ed
, int nedit
, int use
, char *file
, char *altmsg
, int dist
,
25 struct msgs
*mp
, char *text
, int inplace
, char *cwd
, int atfile
)
31 char buffer
[BUFSIZ
], *vec
[MAXARGS
];
34 vec
[vecp
++] = r1bindex (whatnowproc
, '/');
37 setenv("mhdraft", file
, 1);
39 setenv("mhfolder", mp
->foldpath
, 1);
43 if (mp
== NULL
|| *altmsg
== '/' || cwd
== NULL
)
44 setenv("mhaltmsg", altmsg
, 1);
46 snprintf (buffer
, sizeof(buffer
), "%s/%s", mp
->foldpath
, altmsg
);
47 setenv("mhaltmsg", buffer
, 1);
52 if ((bp
= getenv ("mhaltmsg")))/* XXX */
53 setenv("editalt", bp
, 1);
54 snprintf (buffer
, sizeof(buffer
), "%d", dist
);
55 setenv("mhdist", buffer
, 1);
60 ed
= get_default_editor();
61 setenv("mheditor", ed
, 1);
63 snprintf (buffer
, sizeof(buffer
), "%d", use
);
64 setenv("mhuse", buffer
, 1);
65 snprintf (buffer
, sizeof(buffer
), "%d", atfile
);
66 setenv("mhatfile", buffer
, 1);
68 unsetenv("mhmessages");
69 unsetenv("mhannotate");
70 unsetenv("mhinplace");
72 if (text
&& mp
&& !is_readonly(mp
)) {
75 buflen
= sizeof(buffer
);
76 for (msgnum
= mp
->lowmsg
; msgnum
<= mp
->hghmsg
; msgnum
++) {
77 if (is_selected(mp
, msgnum
)) {
78 snprintf (bp
, buflen
, "%s%s", found
? " " : "", m_name (msgnum
));
82 for (k
= msgnum
+ 1; k
<= mp
->hghmsg
&& is_selected(mp
, k
); k
++)
85 snprintf (bp
, buflen
, "-%s", m_name (k
));
95 setenv("mhmessages", buffer
, 1);
96 setenv("mhannotate", text
, 1);
97 snprintf (buffer
, sizeof(buffer
), "%d", inplace
);
98 setenv("mhinplace", buffer
, 1);
102 context_save (); /* save the context file */
106 if (chdir (cwd
) < 0) {
107 advise (cwd
, "chdir");
112 * If the "whatnowproc" is the nmh command "whatnow",
113 * we run it internally, rather than exec'ing it.
115 if (strcmp (vec
[0], "whatnow") == 0) {
120 execvp (whatnowproc
, vec
);
121 fprintf (stderr
, "unable to exec ");
122 perror (whatnowproc
);