142574Sbostic /*- 242574Sbostic * Copyright (c) 1990 The Regents of the University of California. 342574Sbostic * All rights reserved. 442574Sbostic * 542574Sbostic * %sccs.include.redist.c% 642574Sbostic */ 742574Sbostic 842574Sbostic #ifndef lint 9*59264Sbostic static char sccsid[] = "@(#)instr.c 5.3 (Berkeley) 04/26/93"; 1042574Sbostic #endif /* not lint */ 1142574Sbostic 1242574Sbostic #include <sys/types.h> 1342574Sbostic #include <sys/wait.h> 1442574Sbostic #include <sys/errno.h> 1542574Sbostic #include <sys/stat.h> 16*59264Sbostic 17*59264Sbostic #include <curses.h> 1842574Sbostic #include <stdio.h> 1946743Sbostic #include <stdlib.h> 2046743Sbostic #include <string.h> 21*59264Sbostic #include <unistd.h> 22*59264Sbostic 23*59264Sbostic #include "deck.h" 24*59264Sbostic #include "cribbage.h" 2542574Sbostic #include "pathnames.h" 2642574Sbostic 27*59264Sbostic void 2842574Sbostic instructions() 2942574Sbostic { 3042574Sbostic extern int errno; 3142574Sbostic struct stat sb; 3242574Sbostic union wait pstat; 3346743Sbostic pid_t pid; 3446743Sbostic char *pager, *path; 3542574Sbostic 3642574Sbostic if (stat(_PATH_INSTR, &sb)) { 3742574Sbostic (void)fprintf(stderr, "cribbage: %s: %s.\n", _PATH_INSTR, 3842574Sbostic strerror(errno)); 3942574Sbostic exit(1); 4042574Sbostic } 41*59264Sbostic switch (pid = vfork()) { 4242574Sbostic case -1: 4342574Sbostic (void)fprintf(stderr, "cribbage: %s.\n", strerror(errno)); 4442574Sbostic exit(1); 4542574Sbostic case 0: 4642574Sbostic if (!(path = getenv("PAGER"))) 4742574Sbostic path = _PATH_MORE; 4842574Sbostic if (pager = rindex(path, '/')) 4942574Sbostic ++pager; 5042574Sbostic pager = path; 5142574Sbostic execlp(path, pager, _PATH_INSTR, (char *)NULL); 5242574Sbostic (void)fprintf(stderr, "cribbage: %s.\n", strerror(errno)); 5342574Sbostic _exit(1); 5442574Sbostic default: 5542574Sbostic do { 5646743Sbostic pid = waitpid(pid, (int *)&pstat, 0); 5742574Sbostic } while (pid == -1 && errno == EINTR); 5842574Sbostic if (pid == -1 || pstat.w_status) 5942574Sbostic exit(1); 6042574Sbostic } 6142574Sbostic } 62