Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/games/monop handle EOF in input
details: https://anonhg.NetBSD.org/src/rev/41149792a605
branches: trunk
changeset: 771721:41149792a605
user: ahoka <ahoka%NetBSD.org@localhost>
date: Thu Dec 01 07:05:52 2011 +0000
description:
handle EOF in input
diffstat:
games/monop/misc.c | 12 +++++++++---
games/monop/monop.c | 7 +++----
2 files changed, 12 insertions(+), 7 deletions(-)
diffs (69 lines):
diff -r 6f684b8359a3 -r 41149792a605 games/monop/misc.c
--- a/games/monop/misc.c Thu Dec 01 00:34:05 2011 +0000
+++ b/games/monop/misc.c Thu Dec 01 07:05:52 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: misc.c,v 1.21 2009/08/12 08:10:49 dholland Exp $ */
+/* $NetBSD: misc.c,v 1.22 2011/12/01 07:05:52 ahoka Exp $ */
/*
* Copyright (c) 1980, 1993
@@ -34,7 +34,7 @@
#if 0
static char sccsid[] = "@(#)misc.c 8.1 (Berkeley) 5/31/93";
#else
-__RCSID("$NetBSD: misc.c,v 1.21 2009/08/12 08:10:49 dholland Exp $");
+__RCSID("$NetBSD: misc.c,v 1.22 2011/12/01 07:05:52 ahoka Exp $");
#endif
#endif /* not lint */
@@ -106,8 +106,9 @@
for (;;) {
printf("%s", prompt);
fgets(buf, sizeof(buf), stdin);
+ /* if stdin is closed we cant really play anymore */
if (feof(stdin))
- return 0;
+ quit();
sp = strchr(buf, '\n');
if (sp)
*sp = '\0';
@@ -294,6 +295,11 @@
quit()
{
putchar('\n');
+
+ /* We dont even have a chance to input y/n if stdin is closed */
+ if (feof(stdin))
+ exit(0);
+
if (getyn("Do you all really want to quit? ") == 0)
exit(0);
}
diff -r 6f684b8359a3 -r 41149792a605 games/monop/monop.c
--- a/games/monop/monop.c Thu Dec 01 00:34:05 2011 +0000
+++ b/games/monop/monop.c Thu Dec 01 07:05:52 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: monop.c,v 1.25 2009/08/12 08:10:49 dholland Exp $ */
+/* $NetBSD: monop.c,v 1.26 2011/12/01 07:05:52 ahoka Exp $ */
/*
* Copyright (c) 1980, 1993
@@ -39,7 +39,7 @@
#if 0
static char sccsid[] = "@(#)monop.c 8.1 (Berkeley) 5/31/93";
#else
-__RCSID("$NetBSD: monop.c,v 1.25 2009/08/12 08:10:49 dholland Exp $");
+__RCSID("$NetBSD: monop.c,v 1.26 2011/12/01 07:05:52 ahoka Exp $");
#endif
#endif /* not lint */
@@ -286,8 +286,7 @@
printf("Player %d's name: ", i + 1);
fgets(buf, sizeof(buf), stdin);
if (feof(stdin)) {
- printf("End of file on stdin\n");
- exit(0);
+ quit();
}
buf[strcspn(buf, "\n")] = '\0';
} while (strlen(buf) == 0);
Home |
Main Index |
Thread Index |
Old Index