]>
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.
13 * This routine is used by comp, repl, forw, and dist to exec
14 * the "whatnowproc". It first sets up all the environment
15 * variables that the "whatnowproc" will need to check, and
16 * then execs the command. As an optimization, if the
17 * "whatnowproc" is the nmh command "whatnow" (typical case),
18 * it will call this routine directly without exec'ing it.
23 what_now (char *ed
, int nedit
, int use
, char *file
, char *altmsg
, int dist
,
24 struct msgs
*mp
, char *text
, int inplace
, char *cwd
, int atfile
)
30 char buffer
[BUFSIZ
], *vec
[MAXARGS
];
33 vec
[vecp
++] = r1bindex (whatnowproc
, '/');
36 setenv("mhdraft", file
, 1);
38 setenv("mhfolder", mp
->foldpath
, 1);
42 if (mp
== NULL
|| *altmsg
== '/' || cwd
== NULL
)
43 setenv("mhaltmsg", altmsg
, 1);
45 snprintf (buffer
, sizeof(buffer
), "%s/%s", mp
->foldpath
, altmsg
);
46 setenv("mhaltmsg", buffer
, 1);
51 if ((bp
= getenv ("mhaltmsg")))/* XXX */
52 setenv("editalt", bp
, 1);
53 snprintf (buffer
, sizeof(buffer
), "%d", dist
);
54 setenv("mhdist", buffer
, 1);
59 ed
= get_default_editor();
60 setenv("mheditor", ed
, 1);
62 snprintf (buffer
, sizeof(buffer
), "%d", use
);
63 setenv("mhuse", buffer
, 1);
64 snprintf (buffer
, sizeof(buffer
), "%d", atfile
);
65 setenv("mhatfile", buffer
, 1);
67 unsetenv("mhmessages");
68 unsetenv("mhannotate");
69 unsetenv("mhinplace");
71 if (text
&& mp
&& !is_readonly(mp
)) {
74 buflen
= sizeof(buffer
);
75 for (msgnum
= mp
->lowmsg
; msgnum
<= mp
->hghmsg
; msgnum
++) {
76 if (is_selected(mp
, msgnum
)) {
77 snprintf (bp
, buflen
, "%s%s", found
? " " : "", m_name (msgnum
));
81 for (k
= msgnum
+ 1; k
<= mp
->hghmsg
&& is_selected(mp
, k
); k
++)
84 snprintf (bp
, buflen
, "-%s", m_name (k
));
94 setenv("mhmessages", buffer
, 1);
95 setenv("mhannotate", text
, 1);
96 snprintf (buffer
, sizeof(buffer
), "%d", inplace
);
97 setenv("mhinplace", buffer
, 1);
101 context_save (); /* save the context file */
105 if (chdir (cwd
) < 0) {
106 advise (cwd
, "chdir");
111 * If the "whatnowproc" is the nmh command "whatnow",
112 * we run it internally, rather than exec'ing it.
114 if (strcmp (vec
[0], "whatnow") == 0) {
119 execvp (whatnowproc
, vec
);
120 fprintf (stderr
, "unable to exec ");
121 perror (whatnowproc
);