Home | History | Annotate | Line # | Download | only in mille
mille.c revision 1.4
      1 /*	$NetBSD: mille.c,v 1.4 1995/03/24 05:01:48 cgd 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 #ifndef lint
     37 static char copyright[] =
     38 "@(#) 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 static char rcsid[] = "$NetBSD: mille.c,v 1.4 1995/03/24 05:01:48 cgd 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 void	rub();
     61 
     62 main(ac, av)
     63 reg int		ac;
     64 reg char	*av[]; {
     65 
     66 	reg bool	restore;
     67 
     68 	/* run as the user */
     69 	setuid(getuid());
     70 
     71 	if (strcmp(av[0], "a.out") == 0) {
     72 		outf = fopen("q", "w");
     73 		setbuf(outf, (char *)NULL);
     74 		Debug = TRUE;
     75 	}
     76 	restore = FALSE;
     77 	switch (ac) {
     78 	  case 2:
     79 		rest_f(av[1]);
     80 		restore = TRUE;
     81 	  case 1:
     82 		break;
     83 	  default:
     84 		printf("usage: milles [ restore_file ]\n");
     85 		exit(-1);
     86 		/* NOTREACHED */
     87 	}
     88 	Play = PLAYER;
     89 	initscr();
     90 	delwin(stdscr);
     91 	stdscr = Board = newwin(BOARD_Y, BOARD_X, 0, 0);
     92 	Score = newwin(SCORE_Y, SCORE_X, 0, 40);
     93 	Miles = newwin(MILES_Y, MILES_X, 17, 0);
     94 #ifdef attron
     95 	idlok(Board, TRUE);
     96 	idlok(Score, TRUE);
     97 	idlok(Miles, TRUE);
     98 #endif
     99 	leaveok(Score, TRUE);
    100 	leaveok(Miles, TRUE);
    101 	clearok(curscr, TRUE);
    102 # ifndef PROF
    103 	srandom(getpid());
    104 # else
    105 	srandom(0);
    106 # endif
    107 	crmode();
    108 	noecho();
    109 	signal(SIGINT, rub);
    110 	for (;;) {
    111 		if (!restore || (Player[PLAYER].total >= 5000
    112 		    || Player[COMP].total >= 5000)) {
    113 			if (Player[COMP].total < Player[PLAYER].total)
    114 				Player[PLAYER].games++;
    115 			else if (Player[COMP].total > Player[PLAYER].total)
    116 				Player[COMP].games++;
    117 			Player[COMP].total = 0;
    118 			Player[PLAYER].total = 0;
    119 		}
    120 		do {
    121 			if (!restore)
    122 				Handstart = Play = other(Handstart);
    123 			if (!restore || On_exit) {
    124 				shuffle();
    125 				init();
    126 			}
    127 			newboard();
    128 			if (restore)
    129 				mvwaddstr(Score, ERR_Y, ERR_X, Initstr);
    130 			prboard();
    131 			do {
    132 				domove();
    133 				if (Finished)
    134 					newscore();
    135 				prboard();
    136 			} while (!Finished);
    137 			check_more();
    138 			restore = On_exit = FALSE;
    139 		} while (Player[COMP].total < 5000
    140 		    && Player[PLAYER].total < 5000);
    141 	}
    142 }
    143 
    144 /*
    145  *	Routine to trap rubouts, and make sure they really want to
    146  * quit.
    147  */
    148 void
    149 rub() {
    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 die(code)
    161 int code; {
    162 
    163 	(void)signal(SIGINT, SIG_IGN);
    164 	if (outf)
    165 		fflush(outf);
    166 	mvcur(0, COLS - 1, LINES - 1, 0);
    167 	endwin();
    168 	exit(code);
    169 }
    170