mille.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. /* $NetBSD: mille.c,v 1.13 2003/08/07 09:37:25 agc Exp $ */
  2. /*
  3. * Copyright (c) 1982, 1993
  4. * The Regents of the University of California. All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions
  8. * are met:
  9. * 1. Redistributions of source code must retain the above copyright
  10. * notice, this list of conditions and the following disclaimer.
  11. * 2. Redistributions in binary form must reproduce the above copyright
  12. * notice, this list of conditions and the following disclaimer in the
  13. * documentation and/or other materials provided with the distribution.
  14. * 3. Neither the name of the University nor the names of its contributors
  15. * may be used to endorse or promote products derived from this software
  16. * without specific prior written permission.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  19. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  20. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  21. * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  22. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  23. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  24. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  25. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  26. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  27. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  28. * SUCH DAMAGE.
  29. */
  30. #include <sys/cdefs.h>
  31. #ifndef lint
  32. __COPYRIGHT("@(#) Copyright (c) 1982, 1993\n\
  33. The Regents of the University of California. All rights reserved.\n");
  34. #endif /* not lint */
  35. #ifndef lint
  36. #if 0
  37. static char sccsid[] = "@(#)mille.c 8.1 (Berkeley) 5/31/93";
  38. #else
  39. __RCSID("$NetBSD: mille.c,v 1.13 2003/08/07 09:37:25 agc Exp $");
  40. #endif
  41. #endif /* not lint */
  42. # include "mille.h"
  43. # include <signal.h>
  44. /*
  45. * @(#)mille.c 1.3 (Berkeley) 5/10/83
  46. */
  47. int
  48. main(ac, av)
  49. int ac;
  50. char *av[];
  51. {
  52. bool restore;
  53. /* Revoke setgid privileges */
  54. setregid(getgid(), getgid());
  55. if (strcmp(av[0], "a.out") == 0) {
  56. outf = fopen("q", "w");
  57. setbuf(outf, (char *)NULL);
  58. Debug = TRUE;
  59. }
  60. restore = FALSE;
  61. switch (ac) {
  62. case 2:
  63. rest_f(av[1]);
  64. restore = TRUE;
  65. case 1:
  66. break;
  67. default:
  68. printf("usage: milles [ restore_file ]\n");
  69. exit(1);
  70. /* NOTREACHED */
  71. }
  72. Play = PLAYER;
  73. initscr();
  74. delwin(stdscr);
  75. stdscr = Board = newwin(BOARD_Y, BOARD_X, 0, 0);
  76. Score = newwin(SCORE_Y, SCORE_X, 0, 40);
  77. Miles = newwin(MILES_Y, MILES_X, 17, 0);
  78. #ifdef attron
  79. idlok(Board, TRUE);
  80. idlok(Score, TRUE);
  81. idlok(Miles, TRUE);
  82. #endif
  83. leaveok(Score, TRUE);
  84. leaveok(Miles, TRUE);
  85. clearok(curscr, TRUE);
  86. # ifndef PROF
  87. srandom(getpid());
  88. # else
  89. srandom(0);
  90. # endif
  91. cbreak();
  92. noecho();
  93. signal(SIGINT, rub);
  94. for (;;) {
  95. if (!restore || (Player[PLAYER].total >= 5000
  96. || Player[COMP].total >= 5000)) {
  97. if (Player[COMP].total < Player[PLAYER].total)
  98. Player[PLAYER].games++;
  99. else if (Player[COMP].total > Player[PLAYER].total)
  100. Player[COMP].games++;
  101. Player[COMP].total = 0;
  102. Player[PLAYER].total = 0;
  103. }
  104. do {
  105. if (!restore)
  106. Handstart = Play = other(Handstart);
  107. if (!restore || On_exit) {
  108. shuffle();
  109. init();
  110. }
  111. newboard();
  112. if (restore)
  113. mvwaddstr(Score, ERR_Y, ERR_X, Initstr);
  114. prboard();
  115. do {
  116. domove();
  117. if (Finished)
  118. newscore();
  119. prboard();
  120. } while (!Finished);
  121. check_more();
  122. restore = On_exit = FALSE;
  123. } while (Player[COMP].total < 5000
  124. && Player[PLAYER].total < 5000);
  125. }
  126. }
  127. /*
  128. * Routine to trap rubouts, and make sure they really want to
  129. * quit.
  130. */
  131. void
  132. rub(dummy)
  133. int dummy __attribute__((__unused__));
  134. {
  135. (void)signal(SIGINT, SIG_IGN);
  136. if (getyn(REALLYPROMPT))
  137. die(0);
  138. (void)signal(SIGINT, rub);
  139. }
  140. /*
  141. * Time to go beddy-by
  142. */
  143. void
  144. die(code)
  145. int code;
  146. {
  147. (void)signal(SIGINT, SIG_IGN);
  148. if (outf)
  149. fflush(outf);
  150. mvcur(0, COLS - 1, LINES - 1, 0);
  151. endwin();
  152. exit(code);
  153. }