hangman-Error-out-on-1000-unsuitable-words.-Closes-6.patch 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. From: Peter Pentchev <roam@ringlet.net>
  2. Date: Thu, 16 Feb 2012 22:37:50 +0100
  3. Subject: hangman: Error out on 1000 unsuitable words. Closes: #610270
  4. ---
  5. hangman/getword.c | 18 +++++++++++++++++-
  6. 1 files changed, 17 insertions(+), 1 deletions(-)
  7. diff --git a/hangman/getword.c b/hangman/getword.c
  8. index 1b5396a..dc42a53 100644
  9. --- a/hangman/getword.c
  10. +++ b/hangman/getword.c
  11. @@ -50,8 +50,10 @@ getword()
  12. FILE *inf;
  13. char *wp, *gp;
  14. long pos;
  15. + int tries;
  16. inf = Dict;
  17. + tries = 0;
  18. for (;;) {
  19. pos = (double) rand() / (RAND_MAX + 1.0) * (double) Dict_size;
  20. fseek(inf, pos, SEEK_SET);
  21. @@ -66,7 +68,21 @@ getword()
  22. if (!islower((unsigned char)*wp))
  23. goto cont;
  24. break;
  25. -cont: ;
  26. +cont:
  27. + if (++tries >= 1000) {
  28. + move(MESGY, MESGX);
  29. + deleteln();
  30. + deleteln();
  31. + deleteln();
  32. + move(MESGY, MESGX);
  33. + printw("No suitable word found, try using "
  34. + "another dictionary!");
  35. + leaveok(stdscr, FALSE);
  36. + refresh();
  37. + readch();
  38. + leaveok(stdscr, TRUE);
  39. + die(0);
  40. + }
  41. }
  42. gp = Known;
  43. wp = Word;
  44. --