]> diplodocus.org Git - nmh/blob - sbr/showfile.c
new.c: Order two return statements to match comment.
[nmh] / sbr / showfile.c
1 /* showfile.c -- invoke the `lproc' command
2 *
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.
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, *program;
17 int retval = 1;
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 = fork()) {
31 case -1:
32 /* fork error */
33 advise ("fork", "unable to");
34 break;
35
36 case 0:
37 /* child */
38 vec = argsplit(lproc, &program, &vecp);
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 (program, vec);
55 fprintf (stderr, "unable to exec ");
56 perror (lproc);
57 _exit (-1);
58
59 default:
60 /* parent */
61 retval = pidwait (pid, -1) & 0377 ? 1 : 0;
62 }
63
64 return retval;
65 }