1 /* 2 * Copyright (c) 1982 Regents of the University of California. 3 * All rights reserved. 4 * 5 * %sccs.include.redist.c% 6 */ 7 8 #ifndef lint 9 char copyright[] = 10 "@(#) Copyright (c) 1982 Regents of the University of California.\n\ 11 All rights reserved.\n"; 12 #endif /* not lint */ 13 14 #ifndef lint 15 static char sccsid[] = "@(#)mille.c 5.7 (Berkeley) 01/11/93"; 16 #endif /* not lint */ 17 18 # include "mille.h" 19 # include <signal.h> 20 # ifdef attron 21 # include <term.h> 22 # endif attron 23 24 /* 25 * @(#)mille.c 1.3 (Berkeley) 5/10/83 26 */ 27 28 void rub(); 29 30 main(ac, av) 31 reg int ac; 32 reg char *av[]; { 33 34 reg bool restore; 35 36 /* run as the user */ 37 setuid(getuid()); 38 39 if (strcmp(av[0], "a.out") == 0) { 40 outf = fopen("q", "w"); 41 setbuf(outf, (char *)NULL); 42 Debug = TRUE; 43 } 44 restore = FALSE; 45 switch (ac) { 46 case 2: 47 rest_f(av[1]); 48 restore = TRUE; 49 case 1: 50 break; 51 default: 52 printf("usage: milles [ restore_file ]\n"); 53 exit(-1); 54 /* NOTREACHED */ 55 } 56 Play = PLAYER; 57 initscr(); 58 delwin(stdscr); 59 stdscr = Board = newwin(BOARD_Y, BOARD_X, 0, 0); 60 Score = newwin(SCORE_Y, SCORE_X, 0, 40); 61 Miles = newwin(MILES_Y, MILES_X, 17, 0); 62 #ifdef attron 63 idlok(Board, TRUE); 64 idlok(Score, TRUE); 65 idlok(Miles, TRUE); 66 #endif 67 leaveok(Score, TRUE); 68 leaveok(Miles, TRUE); 69 clearok(curscr, TRUE); 70 # ifndef PROF 71 srandom(getpid()); 72 # else 73 srandom(0); 74 # endif 75 crmode(); 76 noecho(); 77 signal(SIGINT, rub); 78 for (;;) { 79 if (!restore || (Player[PLAYER].total >= 5000 80 || Player[COMP].total >= 5000)) { 81 if (Player[COMP].total < Player[PLAYER].total) 82 Player[PLAYER].games++; 83 else if (Player[COMP].total > Player[PLAYER].total) 84 Player[COMP].games++; 85 Player[COMP].total = 0; 86 Player[PLAYER].total = 0; 87 } 88 do { 89 if (!restore) 90 Handstart = Play = other(Handstart); 91 if (!restore || On_exit) { 92 shuffle(); 93 init(); 94 } 95 newboard(); 96 if (restore) 97 mvwaddstr(Score, ERR_Y, ERR_X, Initstr); 98 prboard(); 99 do { 100 domove(); 101 if (Finished) 102 newscore(); 103 prboard(); 104 } while (!Finished); 105 check_more(); 106 restore = On_exit = FALSE; 107 } while (Player[COMP].total < 5000 108 && Player[PLAYER].total < 5000); 109 } 110 } 111 112 /* 113 * Routine to trap rubouts, and make sure they really want to 114 * quit. 115 */ 116 void 117 rub() { 118 119 (void)signal(SIGINT, SIG_IGN); 120 if (getyn(REALLYPROMPT)) 121 die(0); 122 (void)signal(SIGINT, rub); 123 } 124 125 /* 126 * Time to go beddy-by 127 */ 128 die(code) 129 int code; { 130 131 (void)signal(SIGINT, SIG_IGN); 132 if (outf) 133 fflush(outf); 134 mvcur(0, COLS - 1, LINES - 1, 0); 135 endwin(); 136 exit(code); 137 } 138