Import mdocml-1.9.14:
[netbsd-mini2440.git] / games / mille / mille.c
blob0a84212fd9df4473aac417ef8865a67c4ed00e40
1 /* $NetBSD: mille.c,v 1.18 2009/05/25 23:34:50 dholland Exp $ */
3 /*
4 * Copyright (c) 1982, 1993
5 * The Regents of the University of California. All rights reserved.
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.
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.
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 */
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.18 2009/05/25 23:34:50 dholland Exp $");
43 #endif
44 #endif /* not lint */
46 #include <time.h>
47 #include "mille.h"
48 #include <signal.h>
51 * @(#)mille.c 1.3 (Berkeley) 5/10/83
54 int
55 main(int ac, char *av[])
57 bool restore;
59 /* Revoke setgid privileges */
60 setgid(getgid());
62 if (strcmp(av[0], "a.out") == 0) {
63 outf = fopen("q", "w");
64 setbuf(outf, (char *)NULL);
65 Debug = TRUE;
67 restore = FALSE;
68 switch (ac) {
69 case 2:
70 rest_f(av[1]);
71 restore = TRUE;
72 case 1:
73 break;
74 default:
75 printf("usage: milles [ restore_file ]\n");
76 exit(1);
77 /* NOTREACHED */
79 Play = PLAYER;
80 if (!initscr())
81 errx(0, "couldn't initialize screen");
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((long) time(NULL));
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;
112 do {
113 if (!restore)
114 Handstart = Play = other(Handstart);
115 if (!restore || On_exit) {
116 shuffle();
117 init();
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);
137 * Routine to trap rubouts, and make sure they really want to
138 * quit.
140 void
141 rub(int dummy __unused)
143 (void)signal(SIGINT, SIG_IGN);
144 if (getyn(REALLYPROMPT))
145 die(0);
146 (void)signal(SIGINT, rub);
150 * Time to go beddy-by
152 void
153 die(int code)
156 (void)signal(SIGINT, SIG_IGN);
157 if (outf)
158 fflush(outf);
159 mvcur(0, COLS - 1, LINES - 1, 0);
160 endwin();
161 exit(code);