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