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