xref: /csrg-svn/games/cribbage/instr.c (revision 46743)
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*46743Sbostic static char sccsid[] = "@(#)instr.c	5.2 (Berkeley) 02/28/91";
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*46743Sbostic #include <unistd.h>
1742574Sbostic #include <stdio.h>
18*46743Sbostic #include <stdlib.h>
19*46743Sbostic #include <string.h>
2042574Sbostic #include "pathnames.h"
2142574Sbostic 
2242574Sbostic instructions()
2342574Sbostic {
2442574Sbostic 	extern int errno;
2542574Sbostic 	struct stat sb;
2642574Sbostic 	union wait pstat;
27*46743Sbostic 	pid_t pid;
28*46743Sbostic 	char *pager, *path;
2942574Sbostic 
3042574Sbostic 	if (stat(_PATH_INSTR, &sb)) {
3142574Sbostic 		(void)fprintf(stderr, "cribbage: %s: %s.\n", _PATH_INSTR,
3242574Sbostic 		    strerror(errno));
3342574Sbostic 		exit(1);
3442574Sbostic 	}
3542574Sbostic 	switch(pid = vfork()) {
3642574Sbostic 	case -1:
3742574Sbostic 		(void)fprintf(stderr, "cribbage: %s.\n", strerror(errno));
3842574Sbostic 		exit(1);
3942574Sbostic 	case 0:
4042574Sbostic 		if (!(path = getenv("PAGER")))
4142574Sbostic 			path = _PATH_MORE;
4242574Sbostic 		if (pager = rindex(path, '/'))
4342574Sbostic 			++pager;
4442574Sbostic 		pager = path;
4542574Sbostic 		execlp(path, pager, _PATH_INSTR, (char *)NULL);
4642574Sbostic 		(void)fprintf(stderr, "cribbage: %s.\n", strerror(errno));
4742574Sbostic 		_exit(1);
4842574Sbostic 	default:
4942574Sbostic 		do {
50*46743Sbostic 			pid = waitpid(pid, (int *)&pstat, 0);
5142574Sbostic 		} while (pid == -1 && errno == EINTR);
5242574Sbostic 		if (pid == -1 || pstat.w_status)
5342574Sbostic 			exit(1);
5442574Sbostic 	}
5542574Sbostic }
56