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