summaryrefslogtreecommitdiff
path: root/source/y/bsd-games/patches/0009-hangman-Error-out-on-1000-unsuitable-words.-Closes-6.patch
blob: b55d7132471c568c33fdd0a84fd7020f8efa992e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
From: Peter Pentchev <roam@ringlet.net>
Date: Thu, 16 Feb 2012 22:37:50 +0100
Subject: hangman: Error out on 1000 unsuitable words. Closes: #610270

---
 hangman/getword.c | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/hangman/getword.c b/hangman/getword.c
index 1b5396a..dc42a53 100644
--- a/hangman/getword.c
+++ b/hangman/getword.c
@@ -50,8 +50,10 @@ getword()
 	FILE *inf;
 	char *wp, *gp;
 	long pos;
+	int tries;
 
 	inf = Dict;
+	tries = 0;
 	for (;;) {
 		pos = (double) rand() / (RAND_MAX + 1.0) * (double) Dict_size;
 		fseek(inf, pos, SEEK_SET);
@@ -66,7 +68,21 @@ getword()
 			if (!islower((unsigned char)*wp))
 				goto cont;
 		break;
-cont:		;
+cont:
+		if (++tries >= 1000) {
+			move(MESGY, MESGX);
+			deleteln();
+			deleteln();
+			deleteln();
+			move(MESGY, MESGX);
+			printw("No suitable word found, try using "
+			    "another dictionary!");
+			leaveok(stdscr, FALSE);
+			refresh();
+			readch();
+			leaveok(stdscr, TRUE);
+			die(0);
+		}
 	}
 	gp = Known;
 	wp = Word;