diff options
-rw-r--r-- | adventure/hdr.h | 4 | ||||
-rw-r--r-- | adventure/io.c | 29 | ||||
-rw-r--r-- | adventure/wizard.c | 13 |
3 files changed, 30 insertions, 16 deletions
diff --git a/adventure/hdr.h b/adventure/hdr.h index fa47b6de..80ab5d61 100644 --- a/adventure/hdr.h +++ b/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/adventure/io.c b/adventure/io.c index 97987009..bbe54d92 100644 --- a/adventure/io.c +++ b/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/adventure/wizard.c b/adventure/wizard.c index 5df1b08d..94de0530 100644 --- a/adventure/wizard.c +++ b/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 */ |