]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - atc/main.c
1 /* $NetBSD: main.c,v 1.9 1999/07/17 19:57:03 hubertf Exp $ */
4 * Copyright (c) 1990, 1993
5 * The Regents of the University of California. All rights reserved.
7 * This code is derived from software contributed to Berkeley by
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the University of
21 * California, Berkeley and its contributors.
22 * 4. Neither the name of the University nor the names of its contributors
23 * may be used to endorse or promote products derived from this software
24 * without specific prior written permission.
26 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
40 * Copyright (c) 1987 by Ed James, UC Berkeley. All rights reserved.
42 * Copy permission is hereby granted provided that this notice is
43 * retained on all partial or complete copies.
45 * For more info on this and all of my stuff, mail edjames@berkeley.edu.
48 #include <sys/cdefs.h>
50 __COPYRIGHT("@(#) Copyright (c) 1990, 1993\n\
51 The Regents of the University of California. All rights reserved.\n");
56 static char sccsid
[] = "@(#)main.c 8.1 (Berkeley) 5/31/93";
58 __RCSID("$NetBSD: main.c,v 1.9 1999/07/17 19:57:03 hubertf Exp $");
63 #include "pathnames.h"
72 int f_usage
= 0, f_list
= 0, f_showscore
= 0;
74 const char *file
= NULL
;
81 /* Open the score file then revoke setgid privileges */
83 setregid(getgid(), getgid());
85 start_time
= seed
= time(0);
122 warnx("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_quit
);
170 signal(SIGTERM
, log_score_quit
);
172 tcgetattr(fileno(stdin
), &tty_start
);
174 tty_new
.c_lflag
&= ~(ICANON
|ECHO
);
175 tty_new
.c_iflag
|= ICRNL
;
176 tty_new
.c_cc
[VMIN
] = 1;
177 tty_new
.c_cc
[VTIME
] = 0;
178 tcsetattr(fileno(stdin
), TCSADRAIN
, &tty_new
);
180 sa
.sa_handler
= update
;
181 sigemptyset(&sa
.sa_mask
);
182 sigaddset(&sa
.sa_mask
, SIGALRM
);
183 sigaddset(&sa
.sa_mask
, SIGINT
);
185 sigaction(SIGALRM
, &sa
, (struct sigaction
*)0);
188 itv
.it_value
.tv_sec
= 0;
189 itv
.it_value
.tv_usec
= 1;
190 itv
.it_interval
.tv_sec
= sp
->update_secs
;
191 itv
.it_interval
.tv_usec
= 0;
192 setitimer(ITIMER_REAL
, &itv
, NULL
);
195 alarm(sp
->update_secs
);
199 if (getcommand() != 1)
203 itv
.it_value
.tv_sec
= 0;
204 itv
.it_value
.tv_usec
= 0;
205 setitimer(ITIMER_REAL
, &itv
, NULL
);
214 itv
.it_value
.tv_sec
= sp
->update_secs
;
215 itv
.it_value
.tv_usec
= 0;
216 itv
.it_interval
.tv_sec
= sp
->update_secs
;
217 itv
.it_interval
.tv_usec
= 0;
218 setitimer(ITIMER_REAL
, &itv
, NULL
);
221 alarm(sp
->update_secs
);
235 yyin
= fopen(s
, "r");
253 static char file
[256];
254 char line
[256], games
[256];
256 strcpy(games
, _PATH_GAMES
);
257 strcat(games
, GAMES
);
259 if ((fp
= fopen(games
, "r")) == NULL
) {
260 warn("fopen %s", games
);
263 if (fgets(line
, sizeof(line
), fp
) == NULL
) {
264 fprintf(stderr
, "%s: no default game available\n", games
);
268 line
[strlen(line
) - 1] = '\0';
269 strcpy(file
, _PATH_GAMES
);
279 static char file
[256];
280 const char *ret
= NULL
;
281 char line
[256], games
[256];
283 strcpy(games
, _PATH_GAMES
);
284 strcat(games
, GAMES
);
286 if ((fp
= fopen(games
, "r")) == NULL
) {
287 warn("fopen %s", games
);
290 while (fgets(line
, sizeof(line
), fp
) != NULL
) {
291 line
[strlen(line
) - 1] = '\0';
292 if (strcmp(s
, line
) == 0) {
293 strcpy(file
, _PATH_GAMES
);
303 fprintf(stderr
, "%s: %s: game not found\n", games
, s
);
304 fprintf(stderr
, "Your score will not be logged.\n");
305 sleep(2); /* give the guy time to read it */
314 char line
[256], games
[256];
317 strcpy(games
, _PATH_GAMES
);
318 strcat(games
, GAMES
);
320 if ((fp
= fopen(games
, "r")) == NULL
) {
321 warn("fopen %s", games
);
324 puts("available games:");
325 while (fgets(line
, sizeof(line
), fp
) != NULL
) {
330 if (num_games
== 0) {
331 fprintf(stderr
, "%s: no games available\n", games
);