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: #include <sys/cdefs.h>
33: #ifndef lint
34: __COPYRIGHT("@(#) Copyright (c) 1982, 1993\n\
35: The Regents of the University of California. All rights reserved.\n");
36: #endif
37:
38: #ifndef lint
39: #if 0
40: static char sccsid[] = "@(#)mille.c 8.1 (Berkeley) 5/31/93";
41: #else
42: __RCSID("$NetBSD: mille.c,v 1.13 2003/08/07 09:37:25 agc Exp $");
43: #endif
44: #endif
45:
46: # include "mille.h"
47: # include <signal.h>
48:
49:
50:
51:
52:
53: int
54: main(ac, av)
55: int ac;
56: char *av[];
57: {
58: bool restore;
59:
60:
61: setregid(getgid(), getgid());
62:
63: if (strcmp(av[0], "a.out") == 0) {
64: outf = fopen("q", "w");
65: setbuf(outf, (char *)NULL);
66: Debug = TRUE;
67: }
68: restore = FALSE;
69: switch (ac) {
70: case 2:
71: rest_f(av[1]);
72: restore = TRUE;
73: case 1:
74: break;
75: default:
76: printf("usage: milles [ restore_file ]\n");
77: exit(1);
78:
79: }
80: Play = PLAYER;
81: initscr();
82: delwin(stdscr);
83: stdscr = Board = newwin(BOARD_Y, BOARD_X, 0, 0);
84: Score = newwin(SCORE_Y, SCORE_X, 0, 40);
85: Miles = newwin(MILES_Y, MILES_X, 17, 0);
86: #ifdef attron
87: idlok(Board, TRUE);
88: idlok(Score, TRUE);
89: idlok(Miles, TRUE);
90: #endif
91: leaveok(Score, TRUE);
92: leaveok(Miles, TRUE);
93: clearok(curscr, TRUE);
94: # ifndef PROF
95: srandom(getpid());
96: # else
97: srandom(0);
98: # endif
99: cbreak();
100: noecho();
101: signal(SIGINT, rub);
102: for (;;) {
103: if (!restore || (Player[PLAYER].total >= 5000
104: || Player[COMP].total >= 5000)) {
105: if (Player[COMP].total < Player[PLAYER].total)
106: Player[PLAYER].games++;
107: else if (Player[COMP].total > Player[PLAYER].total)
108: Player[COMP].games++;
109: Player[COMP].total = 0;
110: Player[PLAYER].total = 0;
111: }
112: do {
113: if (!restore)
114: Handstart = Play = other(Handstart);
115: if (!restore || On_exit) {
116: shuffle();
117: init();
118: }
119: newboard();
120: if (restore)
121: mvwaddstr(Score, ERR_Y, ERR_X, Initstr);
122: prboard();
123: do {
124: domove();
125: if (Finished)
126: newscore();
127: prboard();
128: } while (!Finished);
129: check_more();
130: restore = On_exit = FALSE;
131: } while (Player[COMP].total < 5000
132: && Player[PLAYER].total < 5000);
133: }
134: }
135:
136:
137:
138:
139:
140: void
141: rub(dummy)
142: int dummy __attribute__((__unused__));
143: {
144: (void)signal(SIGINT, SIG_IGN);
145: if (getyn(REALLYPROMPT))
146: die(0);
147: (void)signal(SIGINT, rub);
148: }
149:
150:
151:
152:
153: void
154: die(code)
155: int code;
156: {
157:
158: (void)signal(SIGINT, SIG_IGN);
159: if (outf)
160: fflush(outf);
161: mvcur(0, COLS - 1, LINES - 1, 0);
162: endwin();
163: exit(code);
164: }