Rearranged whitespace (and comments) in all the code!
[mmh] / sbr / showfile.c
1 /*
2  * showfile.c -- invoke the `lproc' command
3  *
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.
7  */
8
9 #include <h/mh.h>
10
11
12 int
13 showfile (char **arg, char *file)
14 {
15         pid_t pid;
16         int isdraft, vecp;
17         char *vec[MAXARGS];
18
19         context_save();  /* save the context file */
20         fflush(stdout);
21
22         /*
23          * If you have your lproc listed as "mhl",
24          * then really invoked the mhlproc instead
25          * (which is usually mhl anyway).
26          */
27         if (!strcmp (r1bindex (lproc, '/'), "mhl"))
28                 lproc = mhlproc;
29
30         switch (pid = vfork()) {
31         case -1:
32                 /* fork error */
33                 advise ("fork", "unable to");
34                 return 1;
35
36         case 0:
37                 /* child */
38                 vecp = 0;
39                 vec[vecp++] = r1bindex (lproc, '/');
40                 isdraft = 1;
41                 if (arg) {
42                         while (*arg) {
43                                 if (**arg != '-')
44                                         isdraft = 0;
45                                 vec[vecp++] = *arg++;
46                         }
47                 }
48                 if (isdraft) {
49                         if (!strcmp (vec[0], "show"))
50                                 vec[vecp++] = "-file";
51                         vec[vecp++] = file;
52                 }
53                 vec[vecp] = NULL;
54
55                 execvp (lproc, vec);
56                 fprintf (stderr, "unable to exec ");
57                 perror (lproc);
58                 _exit (-1);
59
60         default:
61                 /* parent */
62                 return (pidwait (pid, -1) & 0377 ? 1 : 0);
63         }
64
65         return 1;  /* NOT REACHED */
66 }