xref: /csrg-svn/games/cribbage/instr.c (revision 60777)
142574Sbostic /*-
2*60777Sbostic  * Copyright (c) 1990, 1993
3*60777Sbostic  *	The Regents of the University of California.  All rights reserved.
442574Sbostic  *
542574Sbostic  * %sccs.include.redist.c%
642574Sbostic  */
742574Sbostic 
842574Sbostic #ifndef lint
9*60777Sbostic static char sccsid[] = "@(#)instr.c	8.1 (Berkeley) 05/31/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>
1659264Sbostic 
1759264Sbostic #include <curses.h>
1842574Sbostic #include <stdio.h>
1946743Sbostic #include <stdlib.h>
2046743Sbostic #include <string.h>
2159264Sbostic #include <unistd.h>
2259264Sbostic 
2359264Sbostic #include "deck.h"
2459264Sbostic #include "cribbage.h"
2542574Sbostic #include "pathnames.h"
2642574Sbostic 
2759264Sbostic void
instructions()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 	}
4159264Sbostic 	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