]>
diplodocus.org Git - nmh/blob - uip/whatnowproc.c
6ed9fb7c9750392d4437215719f0f258e2a75b42
2 * whatnowproc.c -- exec the "whatnowproc"
4 * This code is Copyright (c) 2002, by the authors of nmh. See the
5 * COPYRIGHT file in the root directory of the nmh distribution for
6 * 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
)
26 int found
, k
, msgnum
, vecp
;
29 char buffer
[BUFSIZ
], *vec
[MAXARGS
];
32 vec
[vecp
++] = r1bindex (whatnowproc
, '/');
35 m_putenv ("mhdraft", file
);
37 m_putenv ("mhfolder", mp
->foldpath
);
39 unputenv ("mhfolder");
41 if (mp
== NULL
|| *altmsg
== '/' || cwd
== NULL
)
42 m_putenv ("mhaltmsg", altmsg
);
44 snprintf (buffer
, sizeof(buffer
), "%s/%s", mp
->foldpath
, altmsg
);
45 m_putenv ("mhaltmsg", buffer
);
48 unputenv ("mhaltmsg");
50 if ((bp
= getenv ("mhaltmsg")))/* XXX */
51 m_putenv ("editalt", bp
);
52 snprintf (buffer
, sizeof(buffer
), "%d", dist
);
53 m_putenv ("mhdist", buffer
);
55 unputenv ("mheditor");
57 m_putenv ("mheditor", ed
? ed
: (ed
= get_default_editor()));
59 snprintf (buffer
, sizeof(buffer
), "%d", use
);
60 m_putenv ("mhuse", buffer
);
61 snprintf (buffer
, sizeof(buffer
), "%d", atfile
);
62 m_putenv ("mhatfile", buffer
);
64 unputenv ("mhmessages");
65 unputenv ("mhannotate");
66 unputenv ("mhinplace");
68 if (text
&& mp
&& !is_readonly(mp
)) {
71 buflen
= sizeof(buffer
);
72 for (msgnum
= mp
->lowmsg
; msgnum
<= mp
->hghmsg
; msgnum
++) {
73 if (is_selected(mp
, msgnum
)) {
74 snprintf (bp
, buflen
, "%s%s", found
? " " : "", m_name (msgnum
));
78 for (k
= msgnum
+ 1; k
<= mp
->hghmsg
&& is_selected(mp
, k
); k
++)
81 snprintf (bp
, buflen
, "-%s", m_name (k
));
91 m_putenv ("mhmessages", buffer
);
92 m_putenv ("mhannotate", text
);
93 snprintf (buffer
, sizeof(buffer
), "%d", inplace
);
94 m_putenv ("mhinplace", buffer
);
98 context_save (); /* save the context file */
102 if (chdir (cwd
) < 0) {
103 advise (cwd
, "chdir");
108 * If the "whatnowproc" is the nmh command "whatnow",
109 * we run it internally, rather than exec'ing it.
111 if (strcmp (vec
[0], "whatnow") == 0) {
116 execvp (whatnowproc
, vec
);
117 fprintf (stderr
, "unable to exec ");
118 perror (whatnowproc
);