summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhubertf <hubertf@NetBSD.org>1999-02-10 00:11:28 +0000
committerhubertf <hubertf@NetBSD.org>1999-02-10 00:11:28 +0000
commit08ab0f321a0273c7bb84fa2b327832e4cd59784f (patch)
tree9f7abd82539d80f96fb817989699d4e79ecfc918
parentefa00c6291ec5a696a95656d8b37b0b5366f5f49 (diff)
The game adventure(6) handles EOF on standard input rather
ungracefully. The patch, derived from OpenBSD, improves this handling. Sent in in PR 6556 by Joseph Myers <jsm28@cam.ac.uk>.
-rw-r--r--games/adventure/hdr.h4
-rw-r--r--games/adventure/io.c29
-rw-r--r--games/adventure/wizard.c13
3 files changed, 30 insertions, 16 deletions
diff --git a/games/adventure/hdr.h b/games/adventure/hdr.h
index fa47b6de2f6..80ab5d61013 100644
--- a/games/adventure/hdr.h
+++ b/games/adventure/hdr.h
@@ -1,4 +1,4 @@
-/* $NetBSD: hdr.h,v 1.5 1998/08/29 20:19:56 hubertf Exp $ */
+/* $NetBSD: hdr.h,v 1.6 1999/02/10 00:11:28 hubertf Exp $ */
/*-
* Copyright (c) 1991, 1993
@@ -64,7 +64,7 @@ extern char data_file[]; /* Virtual data file */
#define TAB 011
#define LF 012
-#define FLUSHLINE while (getchar()!='\n')
+#define FLUSHLINE do { int flushline_ch; while ((flushline_ch = getchar()) != EOF && flushline_ch != '\n'); } while (0)
#define FLUSHLF while (next()!=LF)
int loc, newloc, oldloc, oldlc2, wzdark, gaveup, kq, k, k2;
diff --git a/games/adventure/io.c b/games/adventure/io.c
index 97987009801..bbe54d922a7 100644
--- a/games/adventure/io.c
+++ b/games/adventure/io.c
@@ -1,4 +1,4 @@
-/* $NetBSD: io.c,v 1.10 1998/09/14 09:29:08 hubertf Exp $ */
+/* $NetBSD: io.c,v 1.11 1999/02/10 00:11:28 hubertf Exp $ */
/*-
* Copyright (c) 1991, 1993
@@ -43,7 +43,7 @@
#if 0
static char sccsid[] = "@(#)io.c 8.1 (Berkeley) 5/31/93";
#else
-__RCSID("$NetBSD: io.c,v 1.10 1998/09/14 09:29:08 hubertf Exp $");
+__RCSID("$NetBSD: io.c,v 1.11 1999/02/10 00:11:28 hubertf Exp $");
#endif
#endif /* not lint */
@@ -89,6 +89,9 @@ getin(wrd1, wrd2) /* get command from user */
*s = 0;
return;
}
+ case EOF:
+ printf("user closed input stream, quitting...\n");
+ exit(0);
default:
if (++numch >= MAXSTR) { /* string too long */
printf("Give me a break!!\n");
@@ -106,14 +109,17 @@ yes(x, y, z) /* confirm with rspeak */
int x, y, z;
{
int result = TRUE; /* pacify gcc */
- char ch;
+ int ch;
for (;;) {
rspeak(x); /* tell him what we want */
if ((ch = getchar()) == 'y')
result = TRUE;
- else
- if (ch == 'n')
- result = FALSE;
+ else if (ch == 'n')
+ result = FALSE;
+ else if (ch == EOF) {
+ printf("user closed input stream, quitting...\n");
+ exit(0);
+ }
FLUSHLINE;
if (ch == 'y' || ch == 'n')
break;
@@ -131,14 +137,17 @@ yesm(x, y, z) /* confirm with mspeak */
int x, y, z;
{
int result = TRUE; /* pacify gcc */
- char ch;
+ int ch;
for (;;) {
mspeak(x); /* tell him what we want */
if ((ch = getchar()) == 'y')
result = TRUE;
- else
- if (ch == 'n')
- result = FALSE;
+ else if (ch == 'n')
+ result = FALSE;
+ else if (ch == EOF) {
+ printf("user closed input stream, quitting...\n");
+ exit(0);
+ }
FLUSHLINE;
if (ch == 'y' || ch == 'n')
break;
diff --git a/games/adventure/wizard.c b/games/adventure/wizard.c
index 5df1b08d06f..94de0530918 100644
--- a/games/adventure/wizard.c
+++ b/games/adventure/wizard.c
@@ -1,4 +1,4 @@
-/* $NetBSD: wizard.c,v 1.8 1998/08/24 22:07:37 hubertf Exp $ */
+/* $NetBSD: wizard.c,v 1.9 1999/02/10 00:11:28 hubertf Exp $ */
/*-
* Copyright (c) 1991, 1993
@@ -43,7 +43,7 @@
#if 0
static char sccsid[] = "@(#)wizard.c 8.1 (Berkeley) 6/2/93";
#else
-__RCSID("$NetBSD: wizard.c,v 1.8 1998/08/24 22:07:37 hubertf Exp $");
+__RCSID("$NetBSD: wizard.c,v 1.9 1999/02/10 00:11:28 hubertf Exp $");
#endif
#endif /* not lint */
@@ -136,9 +136,14 @@ ciao()
char fname[80];
printf("What would you like to call the saved version?\n");
- for (c = fname;; c++)
- if ((*c = getchar()) == '\n')
+ /* XXX - should use fgetln to avoid arbitrary limit */
+ for (c = fname; c < fname + sizeof fname - 1; c++) {
+ int ch;
+ ch = getchar();
+ if (ch == '\n' || ch == EOF)
break;
+ *c = ch;
+ }
*c = 0;
if (save(fname) != 0)
return; /* Save failed */