Commit | Line | Data |
---|---|---|
822fe7d0 | 1 | /*- |
44837faf KB |
2 | * Copyright (c) 1990, 1993 |
3 | * The Regents of the University of California. All rights reserved. | |
822fe7d0 KB |
4 | * |
5 | * %sccs.include.redist.c% | |
6 | */ | |
7 | ||
8 | #ifndef lint | |
44837faf | 9 | static char sccsid[] = "@(#)instr.c 8.1 (Berkeley) %G%"; |
822fe7d0 KB |
10 | #endif /* not lint */ |
11 | ||
12 | #include <sys/types.h> | |
13 | #include <sys/wait.h> | |
14 | #include <sys/errno.h> | |
15 | #include <sys/stat.h> | |
3f03c0c5 KB |
16 | |
17 | #include <curses.h> | |
822fe7d0 | 18 | #include <stdio.h> |
6538ddf3 KB |
19 | #include <stdlib.h> |
20 | #include <string.h> | |
3f03c0c5 KB |
21 | #include <unistd.h> |
22 | ||
23 | #include "deck.h" | |
24 | #include "cribbage.h" | |
822fe7d0 KB |
25 | #include "pathnames.h" |
26 | ||
3f03c0c5 | 27 | void |
822fe7d0 KB |
28 | instructions() |
29 | { | |
30 | extern int errno; | |
31 | struct stat sb; | |
32 | union wait pstat; | |
6538ddf3 KB |
33 | pid_t pid; |
34 | char *pager, *path; | |
822fe7d0 KB |
35 | |
36 | if (stat(_PATH_INSTR, &sb)) { | |
37 | (void)fprintf(stderr, "cribbage: %s: %s.\n", _PATH_INSTR, | |
38 | strerror(errno)); | |
39 | exit(1); | |
40 | } | |
3f03c0c5 | 41 | switch (pid = vfork()) { |
822fe7d0 KB |
42 | case -1: |
43 | (void)fprintf(stderr, "cribbage: %s.\n", strerror(errno)); | |
44 | exit(1); | |
45 | case 0: | |
46 | if (!(path = getenv("PAGER"))) | |
47 | path = _PATH_MORE; | |
48 | if (pager = rindex(path, '/')) | |
49 | ++pager; | |
50 | pager = path; | |
51 | execlp(path, pager, _PATH_INSTR, (char *)NULL); | |
52 | (void)fprintf(stderr, "cribbage: %s.\n", strerror(errno)); | |
53 | _exit(1); | |
54 | default: | |
55 | do { | |
6538ddf3 | 56 | pid = waitpid(pid, (int *)&pstat, 0); |
822fe7d0 KB |
57 | } while (pid == -1 && errno == EINTR); |
58 | if (pid == -1 || pstat.w_status) | |
59 | exit(1); | |
60 | } | |
61 | } |