1 /*- 2 * Copyright (c) 1990 The Regents of the University of California. 3 * All rights reserved. 4 * 5 * %sccs.include.redist.c% 6 */ 7 8 #ifndef lint 9 static char sccsid[] = "@(#)instr.c 5.1 (Berkeley) 06/01/90"; 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> 16 #include <sys/file.h> 17 #include <stdio.h> 18 #include "pathnames.h" 19 20 instructions() 21 { 22 extern int errno; 23 struct stat sb; 24 union wait pstat; 25 pid_t pid, waitpid(); 26 char *pager, *path, *getenv(), *rindex(), *strerror(); 27 28 if (stat(_PATH_INSTR, &sb)) { 29 (void)fprintf(stderr, "cribbage: %s: %s.\n", _PATH_INSTR, 30 strerror(errno)); 31 exit(1); 32 } 33 switch(pid = vfork()) { 34 case -1: 35 (void)fprintf(stderr, "cribbage: %s.\n", strerror(errno)); 36 exit(1); 37 case 0: 38 if (!(path = getenv("PAGER"))) 39 path = _PATH_MORE; 40 if (pager = rindex(path, '/')) 41 ++pager; 42 pager = path; 43 execlp(path, pager, _PATH_INSTR, (char *)NULL); 44 (void)fprintf(stderr, "cribbage: %s.\n", strerror(errno)); 45 _exit(1); 46 default: 47 do { 48 pid = waitpid(pid, &pstat, 0); 49 } while (pid == -1 && errno == EINTR); 50 if (pid == -1 || pstat.w_status) 51 exit(1); 52 } 53 } 54