]> diplodocus.org Git - nmh/blob - sbr/showfile.c
Fix stupid accidental dependence on a bash quirk in previous
[nmh] / sbr / showfile.c
1
2 /*
3 * showfile.c -- invoke the `lproc' command
4 *
5 * $Id$
6 *
7 * This code is Copyright (c) 2002, by the authors of nmh. See the
8 * COPYRIGHT file in the root directory of the nmh distribution for
9 * complete copyright information.
10 */
11
12 #include <h/mh.h>
13
14
15 int
16 showfile (char **arg, char *file)
17 {
18 pid_t pid;
19 int isdraft, vecp;
20 char *vec[MAXARGS];
21
22 context_save(); /* save the context file */
23 fflush(stdout);
24
25 /*
26 * If you have your lproc listed as "mhl",
27 * then really invoked the mhlproc instead
28 * (which is usually mhl anyway).
29 */
30 if (!strcmp (r1bindex (lproc, '/'), "mhl"))
31 lproc = mhlproc;
32
33 switch (pid = vfork()) {
34 case -1:
35 /* fork error */
36 advise ("fork", "unable to");
37 return 1;
38
39 case 0:
40 /* child */
41 vecp = 0;
42 vec[vecp++] = r1bindex (lproc, '/');
43 isdraft = 1;
44 if (arg) {
45 while (*arg) {
46 if (**arg != '-')
47 isdraft = 0;
48 vec[vecp++] = *arg++;
49 }
50 }
51 if (isdraft) {
52 if (!strcmp (vec[0], "show"))
53 vec[vecp++] = "-file";
54 vec[vecp++] = file;
55 }
56 vec[vecp] = NULL;
57
58 execvp (lproc, vec);
59 fprintf (stderr, "unable to exec ");
60 perror (lproc);
61 _exit (-1);
62
63 default:
64 /* parent */
65 return (pidwait (pid, -1) & 0377 ? 1 : 0);
66 }
67
68 return 1; /* NOT REACHED */
69 }