From 638c095d5cf47282d99189e1425435a0763a369b Mon Sep 17 00:00:00 2001 From: hubertf Date: Wed, 10 Feb 1999 00:11:28 +0000 Subject: 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 . --- adventure/io.c | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) (limited to 'adventure/io.c') 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; -- cgit v1.2.3-56-ge451