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