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