2 * Copyright (c) 1990, 1993
3 * The Regents of the University of California. All rights reserved.
5 * This code is derived from software contributed to Berkeley by
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by the University of
19 * California, Berkeley and its contributors.
20 * 4. Neither the name of the University nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38 * Copyright (c) 1987 by Ed James, UC Berkeley. All rights reserved.
40 * Copy permission is hereby granted provided that this notice is
41 * retained on all partial or complete copies.
43 * For more info on this and all of my stuff, mail edjames@berkeley.edu.
47 static const char copyright[] =
48 "@(#) Copyright (c) 1990, 1993\n\
49 The Regents of the University of California. All rights reserved.\n";
54 static char sccsid[] = "@(#)main.c 8.1 (Berkeley) 5/31/93";
56 static const char rcsid[] =
57 "$FreeBSD: src/games/atc/main.c,v 1.9 1999/11/30 03:48:21 billf Exp $";
62 #include "pathnames.h"
69 int f_usage = 0, f_list = 0, f_showscore = 0;
71 const char *file = NULL;
76 extern const char *default_game(), *okay_game();
77 extern void log_score(), quit(), update();
79 /* Open the score file then revoke setgid privileges */
81 setregid(getgid(), getgid());
121 fprintf(stderr, "Unknown option '%c'\n", *ptr);
133 "Usage: %s -[u?lstp] [-[gf] game_name] [-r random seed]\n",
142 strcpy(buf, _PATH_GAMES);
143 buf[strlen(buf) - 1] = '\0';
147 if (f_usage || f_showscore || f_list || f_printpath)
151 file = default_game();
153 file = okay_game(file);
155 if (file == NULL || read_file(file) < 0)
163 signal(SIGINT, quit);
164 signal(SIGQUIT, quit);
166 signal(SIGTSTP, SIG_IGN);
167 signal(SIGSTOP, SIG_IGN);
169 signal(SIGHUP, log_score);
170 signal(SIGTERM, log_score);
173 ioctl(fileno(stdin), TIOCGETP, &tty_start);
174 bcopy(&tty_start, &tty_new, sizeof(tty_new));
175 tty_new.sg_flags |= CBREAK;
176 tty_new.sg_flags &= ~ECHO;
177 ioctl(fileno(stdin), TIOCSETP, &tty_new);
181 ioctl(fileno(stdin), TCGETA, &tty_start);
182 bcopy(&tty_start, &tty_new, sizeof(tty_new));
183 tty_new.c_lflag &= ~ICANON;
184 tty_new.c_lflag &= ~ECHO;
185 tty_new.c_cc[VMIN] = 1;
186 tty_new.c_cc[VTIME] = 0;
187 ioctl(fileno(stdin), TCSETAW, &tty_new);
190 signal(SIGALRM, update);
193 itv.it_value.tv_sec = 0;
194 itv.it_value.tv_usec = 1;
195 itv.it_interval.tv_sec = sp->update_secs;
196 itv.it_interval.tv_usec = 0;
197 setitimer(ITIMER_REAL, &itv, NULL);
200 alarm(sp->update_secs);
204 if (getcommand() != 1)
208 itv.it_value.tv_sec = 0;
209 itv.it_value.tv_usec = 0;
210 setitimer(ITIMER_REAL, &itv, NULL);
219 itv.it_value.tv_sec = sp->update_secs;
220 itv.it_value.tv_usec = 0;
221 itv.it_interval.tv_sec = sp->update_secs;
222 itv.it_interval.tv_usec = 0;
223 setitimer(ITIMER_REAL, &itv, NULL);
226 alarm(sp->update_secs);
239 yyin = fopen(s, "r");
257 static char file[256];
258 char line[256], games[256];
260 strcpy(games, _PATH_GAMES);
261 strcat(games, GAMES);
263 if ((fp = fopen(games, "r")) == NULL) {
267 if (fgets(line, sizeof(line), fp) == NULL) {
268 fprintf(stderr, "%s: no default game available\n", games);
272 line[strlen(line) - 1] = '\0';
273 strcpy(file, _PATH_GAMES);
283 static char file[256];
284 const char *ret = NULL;
285 char line[256], games[256];
287 strcpy(games, _PATH_GAMES);
288 strcat(games, GAMES);
290 if ((fp = fopen(games, "r")) == NULL) {
294 while (fgets(line, sizeof(line), fp) != NULL) {
295 line[strlen(line) - 1] = '\0';
296 if (strcmp(s, line) == 0) {
297 strcpy(file, _PATH_GAMES);
307 fprintf(stderr, "%s: %s: game not found\n", games, s);
308 fprintf(stderr, "Your score will not be logged.\n");
309 sleep(2); /* give the guy time to read it */
317 char line[256], games[256];
320 strcpy(games, _PATH_GAMES);
321 strcat(games, GAMES);
323 if ((fp = fopen(games, "r")) == NULL) {
327 puts("available games:");
328 while (fgets(line, sizeof(line), fp) != NULL) {
333 if (num_games == 0) {
334 fprintf(stderr, "%s: no games available\n", games);