summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--games/cribbage/cribbage.66
-rw-r--r--games/cribbage/instr.c46
-rw-r--r--games/fish/fish.c72
-rw-r--r--games/quiz/quiz.c13
-rw-r--r--games/wump/wump.c45
5 files changed, 135 insertions, 47 deletions
diff --git a/games/cribbage/cribbage.6 b/games/cribbage/cribbage.6
index 373546cd68c..e60e5738a50 100644
--- a/games/cribbage/cribbage.6
+++ b/games/cribbage/cribbage.6
@@ -1,4 +1,4 @@
-.\" $OpenBSD: cribbage.6,v 1.5 1998/12/15 19:18:29 pjanzen Exp $
+.\" $OpenBSD: cribbage.6,v 1.6 1999/06/10 22:58:19 pjanzen Exp $
.\"
.\" Copyright (c) 1980, 1993
.\" The Regents of the University of California. All rights reserved.
@@ -48,9 +48,7 @@ plays the card game cribbage, with the program playing one hand
and the user the other. The program will initially ask the user if
the rules of the game are needed \- if so, it will print out
the appropriate section from
-.Em According to Hoyle
-with
-.Xr more 1 .
+.Em According to Hoyle .
.Pp
.Nm
options include:
diff --git a/games/cribbage/instr.c b/games/cribbage/instr.c
index 42f232d763b..6fbbf640233 100644
--- a/games/cribbage/instr.c
+++ b/games/cribbage/instr.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: instr.c,v 1.6 1998/08/19 07:40:21 pjanzen Exp $ */
+/* $OpenBSD: instr.c,v 1.7 1999/06/10 22:58:19 pjanzen Exp $ */
/* $NetBSD: instr.c,v 1.5 1997/07/10 06:47:30 mikel Exp $ */
/*-
@@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "@(#)instr.c 8.1 (Berkeley) 5/31/93";
#else
-static char rcsid[] = "$OpenBSD: instr.c,v 1.6 1998/08/19 07:40:21 pjanzen Exp $";
+static char rcsid[] = "$OpenBSD: instr.c,v 1.7 1999/06/10 22:58:19 pjanzen Exp $";
#endif
#endif /* not lint */
@@ -48,11 +48,13 @@ static char rcsid[] = "$OpenBSD: instr.c,v 1.6 1998/08/19 07:40:21 pjanzen Exp $
#include <curses.h>
#include <err.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <paths.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
-#include <errno.h>
#include "deck.h"
#include "cribbage.h"
@@ -61,32 +63,38 @@ static char rcsid[] = "$OpenBSD: instr.c,v 1.6 1998/08/19 07:40:21 pjanzen Exp $
void
instructions()
{
- struct stat sb;
- union wait pstat;
+ int pstat;
+ int fd;
pid_t pid;
- char *pager, *path;
-
- if (stat(_PATH_INSTR, &sb))
- err(1, "stat %s", _PATH_INSTR);
+ const char *pager;
- if (!(path = getenv("PAGER")))
- path = _PATH_MORE;
- if ((pager = strrchr(path, '/')))
- ++pager;
- pager = path;
+ if ((fd = open(_PATH_INSTR, O_RDONLY)) == - 1)
+ errx(1, "can't open %s", _PATH_INSTR);
switch (pid = vfork()) {
case -1:
err(1, "vfork");
+ /* NOTREACHED */
case 0:
- execlp(path, pager, _PATH_INSTR, NULL);
- warn("%s", "");
- _exit(1);
+ setgid(getgid());
+ if (!isatty(1))
+ pager = "/bin/cat";
+ else {
+ if (!(pager = getenv("PAGER")) || (*pager == 0))
+ pager = _PATH_MORE;
+ }
+ if (dup2(fd, 0) == -1)
+ err(1, "dup2");
+ execl(_PATH_BSHELL, "sh", "-c", pager, NULL);
+ err(1, "exec sh -c %s", pager);
+ /* NOTREACHED */
default:
do {
- pid = waitpid(pid, (int *)&pstat, 0);
+ pid = waitpid(pid, &pstat, 0);
} while (pid == -1 && errno == EINTR);
- if (pid == -1 || pstat.w_status)
+ close(fd);
+ if (pid == -1 || WEXITSTATUS(pstat))
exit(1);
+ break;
}
}
diff --git a/games/fish/fish.c b/games/fish/fish.c
index 3c4ad7e2d19..dbd6245a2b3 100644
--- a/games/fish/fish.c
+++ b/games/fish/fish.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: fish.c,v 1.4 1999/03/26 03:16:10 pjanzen Exp $ */
+/* $OpenBSD: fish.c,v 1.5 1999/06/10 22:58:24 pjanzen Exp $ */
/* $NetBSD: fish.c,v 1.3 1995/03/23 08:28:18 cgd Exp $ */
/*-
@@ -47,12 +47,15 @@ static char copyright[] =
#if 0
static char sccsid[] = "@(#)fish.c 8.1 (Berkeley) 5/31/93";
#else
-static char rcsid[] = "$OpenBSD: fish.c,v 1.4 1999/03/26 03:16:10 pjanzen Exp $";
+static char rcsid[] = "$OpenBSD: fish.c,v 1.5 1999/06/10 22:58:24 pjanzen Exp $";
#endif
#endif /* not lint */
#include <sys/types.h>
+#include <sys/wait.h>
+#include <err.h>
#include <fcntl.h>
+#include <paths.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
@@ -83,6 +86,7 @@ int compmove __P((void));
int countbooks __P((int *));
int countcards __P((int *));
int drawcard __P((int, int *));
+int getans __P((const char *));
int gofish __P((int, int, int *));
void goodmove __P((int, int, int *, int *));
void init __P((void));
@@ -445,20 +449,70 @@ nrandom(n)
return((int)random() % n);
}
+int
+getans(prompt)
+ const char *prompt;
+{
+ char buf[20];
+
+ /*
+ * simple routine to ask the yes/no question specified until the user
+ * answers yes or no, then return 1 if they said 'yes' and 0 if they
+ * answered 'no'.
+ */
+ for (;;) {
+ (void)printf("%s", prompt);
+ (void)fflush(stdout);
+ if (!fgets(buf, sizeof(buf), stdin))
+ return(0);
+ if (*buf == 'N' || *buf == 'n')
+ return(0);
+ if (*buf == 'Y' || *buf == 'y')
+ return(1);
+ (void)printf(
+"I don't understand your answer; please enter 'y' or 'n'!\n");
+ }
+ /* NOTREACHED */
+}
+
void
instructions()
{
+ const char *pager;
+ pid_t pid;
+ int status;
int input;
- char buf[1024];
+ int fd;
- (void)printf("Would you like instructions (y or n)? ");
- input = getchar();
- while (getchar() != '\n');
- if (input != 'y')
+ if (getans("Would you like instructions (y or n)? ") == 0)
return;
- (void)sprintf(buf, "%s %s", _PATH_MORE, _PATH_INSTR);
- (void)system(buf);
+ if ((fd = open(_PATH_INSTR, O_RDONLY)) == -1)
+ (void)printf("No instruction file found!\n");
+ else {
+ switch (pid = fork()) {
+ case 0: /* child */
+ if (!isatty(1))
+ pager = "/bin/cat";
+ else {
+ if (!(pager = getenv("PAGER")) || (*pager == 0))
+ pager = _PATH_MORE;
+ }
+ if (dup2(fd, 0) == -1)
+ err(1, "dup2");
+ (void)execl(_PATH_BSHELL, "sh", "-c", pager, NULL);
+ err(1, "exec sh -c %s", pager);
+ /* NOT REACHED */
+ case -1:
+ err(1, "fork");
+ /* NOT REACHED */
+ default:
+ (void)waitpid(pid, &status, 0);
+ close(fd);
+ break;
+ }
+ }
+
(void)printf("Hit return to continue...\n");
while ((input = getchar()) != EOF && input != '\n');
}
diff --git a/games/quiz/quiz.c b/games/quiz/quiz.c
index 816b23a6812..0529c78108a 100644
--- a/games/quiz/quiz.c
+++ b/games/quiz/quiz.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: quiz.c,v 1.7 1999/03/27 04:45:25 pjanzen Exp $ */
+/* $OpenBSD: quiz.c,v 1.8 1999/06/10 22:58:24 pjanzen Exp $ */
/* $NetBSD: quiz.c,v 1.9 1995/04/22 10:16:58 cgd Exp $ */
/*-
@@ -48,7 +48,7 @@ static char copyright[] =
#if 0
static char sccsid[] = "@(#)quiz.c 8.3 (Berkeley) 5/4/95";
#else
-static char rcsid[] = "$OpenBSD: quiz.c,v 1.7 1999/03/27 04:45:25 pjanzen Exp $";
+static char rcsid[] = "$OpenBSD: quiz.c,v 1.8 1999/06/10 22:58:24 pjanzen Exp $";
#endif
#endif /* not lint */
@@ -168,9 +168,14 @@ show_index()
QE *qp;
const char *p, *s;
FILE *pf;
+ const char *pager;
- if ((pf = popen(_PATH_PAGER, "w")) == NULL)
- err(1, "%s", _PATH_PAGER);
+ if (!isatty(1))
+ pager = "/bin/cat";
+ else if (!(pager = getenv("PAGER")) || (*pager == 0))
+ pager = _PATH_PAGER;
+ if ((pf = popen(pager, "w")) == NULL)
+ err(1, "%s", pager);
(void)fprintf(pf, "Subjects:\n\n");
for (qp = qlist.q_next; qp; qp = qp->q_next) {
for (s = next_cat(qp->q_text); s; s = next_cat(s)) {
diff --git a/games/wump/wump.c b/games/wump/wump.c
index 0371ae6b1cf..0198f31d492 100644
--- a/games/wump/wump.c
+++ b/games/wump/wump.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: wump.c,v 1.8 1998/08/19 07:42:27 pjanzen Exp $ */
+/* $OpenBSD: wump.c,v 1.9 1999/06/10 22:58:24 pjanzen Exp $ */
/*
* Copyright (c) 1989, 1993
@@ -47,7 +47,7 @@ static char copyright[] =
#if 0
static char sccsid[] = "@(#)wump.c 8.1 (Berkeley) 5/31/93";
#else
-static char rcsid[] = "$OpenBSD: wump.c,v 1.8 1998/08/19 07:42:27 pjanzen Exp $";
+static char rcsid[] = "$OpenBSD: wump.c,v 1.9 1999/06/10 22:58:24 pjanzen Exp $";
#endif
#endif /* not lint */
@@ -59,6 +59,9 @@ static char rcsid[] = "$OpenBSD: wump.c,v 1.8 1998/08/19 07:42:27 pjanzen Exp $"
#include <sys/types.h>
#include <sys/file.h>
+#include <sys/wait.h>
+#include <err.h>
+#include <paths.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -255,8 +258,10 @@ quiver holds %d custom super anti-evil Wumpus arrows. Good luck.\n",
} while (!take_action());
(void)fpurge(stdin);
- if (!getans("\nCare to play another game? (y-n) "))
+ if (!getans("\nCare to play another game? (y-n) ")) {
+ (void)printf("\n");
exit(0);
+ }
clear_things_in_cave();
if (!getans("In the same cave? (y-n) "))
cave_init();
@@ -783,7 +788,10 @@ int_compare(a, b)
void
instructions()
{
- char buf[120], *p, *getenv();
+ const char *pager;
+ pid_t pid;
+ int status;
+ int fd;
/*
* read the instructions file, if needed, and show the user how to
@@ -792,19 +800,34 @@ instructions()
if (!getans("Instructions? (y-n) "))
return;
- if (access(_PATH_WUMPINFO, R_OK)) {
+ if ((fd = open(_PATH_WUMPINFO, O_RDONLY)) == -1) {
(void)printf(
"Sorry, but the instruction file seems to have disappeared in a\n\
puff of greasy black smoke! (poof)\n");
return;
}
- if (!(p = getenv("PAGER")) ||
- strlen(p) > sizeof(buf) + strlen(_PATH_WUMPINFO) + 5)
- p = _PATH_PAGER;
-
- (void)sprintf(buf, "%s %s", p, _PATH_WUMPINFO);
- (void)system(buf);
+ if (!isatty(1))
+ pager = "/bin/cat";
+ else {
+ if (!(pager = getenv("PAGER")) || (*pager == 0))
+ pager = _PATH_PAGER;
+ }
+ switch (pid = fork()) {
+ case 0: /* child */
+ if (dup2(fd, 0) == -1)
+ err(1, "dup2");
+ (void)execl(_PATH_BSHELL, "sh", "-c", pager, NULL);
+ err(1, "exec sh -c %s", pager);
+ /* NOT REACHED */
+ case -1:
+ err(1, "fork");
+ /* NOT REACHED */
+ default:
+ (void)waitpid(pid, &status, 0);
+ close(fd);
+ break;
+ }
}
void