]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - atc/main.c
1 /* $NetBSD: main.c,v 1.10 1999/07/24 15:50:44 mjl 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.10 1999/07/24 15:50:44 mjl 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(NULL
);
87 while ((ch
= getopt(ac
, av
, "ulstpg:f:r:")) != -1) {
119 "Usage: %s -[u?lstp] [-[gf] game_name] [-r random seed]\n",
128 strcpy(buf
, _PATH_GAMES
);
129 buf
[strlen(buf
) - 1] = '\0';
133 if (f_usage
|| f_showscore
|| f_list
|| f_printpath
)
137 file
= default_game();
139 file
= okay_game(file
);
141 if (file
== NULL
|| read_file(file
) < 0)
149 signal(SIGINT
, quit
);
150 signal(SIGQUIT
, quit
);
152 signal(SIGTSTP
, SIG_IGN
);
153 signal(SIGSTOP
, SIG_IGN
);
155 signal(SIGHUP
, log_score_quit
);
156 signal(SIGTERM
, log_score_quit
);
158 tcgetattr(fileno(stdin
), &tty_start
);
160 tty_new
.c_lflag
&= ~(ICANON
|ECHO
);
161 tty_new
.c_iflag
|= ICRNL
;
162 tty_new
.c_cc
[VMIN
] = 1;
163 tty_new
.c_cc
[VTIME
] = 0;
164 tcsetattr(fileno(stdin
), TCSADRAIN
, &tty_new
);
166 sa
.sa_handler
= update
;
167 sigemptyset(&sa
.sa_mask
);
168 sigaddset(&sa
.sa_mask
, SIGALRM
);
169 sigaddset(&sa
.sa_mask
, SIGINT
);
171 sigaction(SIGALRM
, &sa
, (struct sigaction
*)0);
174 itv
.it_value
.tv_sec
= 0;
175 itv
.it_value
.tv_usec
= 1;
176 itv
.it_interval
.tv_sec
= sp
->update_secs
;
177 itv
.it_interval
.tv_usec
= 0;
178 setitimer(ITIMER_REAL
, &itv
, NULL
);
181 alarm(sp
->update_secs
);
185 if (getcommand() != 1)
189 itv
.it_value
.tv_sec
= 0;
190 itv
.it_value
.tv_usec
= 0;
191 setitimer(ITIMER_REAL
, &itv
, NULL
);
200 itv
.it_value
.tv_sec
= sp
->update_secs
;
201 itv
.it_value
.tv_usec
= 0;
202 itv
.it_interval
.tv_sec
= sp
->update_secs
;
203 itv
.it_interval
.tv_usec
= 0;
204 setitimer(ITIMER_REAL
, &itv
, NULL
);
207 alarm(sp
->update_secs
);
221 yyin
= fopen(s
, "r");
239 static char file
[256];
240 char line
[256], games
[256];
242 strcpy(games
, _PATH_GAMES
);
243 strcat(games
, GAMES
);
245 if ((fp
= fopen(games
, "r")) == NULL
) {
246 warn("fopen %s", games
);
249 if (fgets(line
, sizeof(line
), fp
) == NULL
) {
250 fprintf(stderr
, "%s: no default game available\n", games
);
254 line
[strlen(line
) - 1] = '\0';
255 strcpy(file
, _PATH_GAMES
);
265 static char file
[256];
266 const char *ret
= NULL
;
267 char line
[256], games
[256];
269 strcpy(games
, _PATH_GAMES
);
270 strcat(games
, GAMES
);
272 if ((fp
= fopen(games
, "r")) == NULL
) {
273 warn("fopen %s", games
);
276 while (fgets(line
, sizeof(line
), fp
) != NULL
) {
277 line
[strlen(line
) - 1] = '\0';
278 if (strcmp(s
, line
) == 0) {
279 strcpy(file
, _PATH_GAMES
);
289 fprintf(stderr
, "%s: %s: game not found\n", games
, s
);
290 fprintf(stderr
, "Your score will not be logged.\n");
291 sleep(2); /* give the guy time to read it */
300 char line
[256], games
[256];
303 strcpy(games
, _PATH_GAMES
);
304 strcat(games
, GAMES
);
306 if ((fp
= fopen(games
, "r")) == NULL
) {
307 warn("fopen %s", games
);
310 puts("available games:");
311 while (fgets(line
, sizeof(line
), fp
) != NULL
) {
316 if (num_games
== 0) {
317 fprintf(stderr
, "%s: no games available\n", games
);