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