* Copyright (c) 1990 The Regents of the University of California.
* This code is derived from software contributed to Berkeley by
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* Copyright (c) 1987 by Ed James, UC Berkeley. All rights reserved.
* Copy permission is hereby granted provided that this notice is
* retained on all partial or complete copies.
* For more info on this and all of my stuff, mail edjames@berkeley.edu.
"@(#) Copyright (c) 1990 The Regents of the University of California.\n\
static char sccsid
[] = "@(#)main.c 5.4 (Berkeley) 3/5/91";
int f_usage
= 0, f_list
= 0, f_showscore
= 0;
extern char *default_game(), *okay_game();
extern void log_score(), quit(), update();
start_time
= seed
= time(0);
fprintf(stderr
, "Unknown option '%c'\n", *ptr
,
"Usage: %s -[u?lstp] [-[gf] game_name] [-r random seed]\n",
strcpy(buf
, _PATH_GAMES
);
buf
[strlen(buf
) - 1] = '\0';
if (f_usage
|| f_showscore
|| f_list
|| f_printpath
)
if (file
== NULL
|| read_file(file
) < 0)
signal(SIGTSTP
, SIG_IGN
);
signal(SIGSTOP
, SIG_IGN
);
signal(SIGHUP
, log_score
);
signal(SIGTERM
, log_score
);
ioctl(fileno(stdin
), TIOCGETP
, &tty_start
);
bcopy(&tty_start
, &tty_new
, sizeof(tty_new
));
tty_new
.sg_flags
|= CBREAK
;
tty_new
.sg_flags
&= ~ECHO
;
ioctl(fileno(stdin
), TIOCSETP
, &tty_new
);
ioctl(fileno(stdin
), TCGETA
, &tty_start
);
bcopy(&tty_start
, &tty_new
, sizeof(tty_new
));
tty_new
.c_lflag
&= ~ICANON
;
tty_new
.c_lflag
&= ~ECHO
;
ioctl(fileno(stdin
), TCSETAW
, &tty_new
);
itv
.it_value
.tv_usec
= 1;
itv
.it_interval
.tv_sec
= sp
->update_secs
;
itv
.it_interval
.tv_usec
= 0;
setitimer(ITIMER_REAL
, &itv
, NULL
);
itv
.it_value
.tv_usec
= 0;
setitimer(ITIMER_REAL
, &itv
, NULL
);
itv
.it_value
.tv_sec
= sp
->update_secs
;
itv
.it_value
.tv_usec
= 0;
itv
.it_interval
.tv_sec
= sp
->update_secs
;
itv
.it_interval
.tv_usec
= 0;
setitimer(ITIMER_REAL
, &itv
, NULL
);
char line
[256], games
[256];
strcpy(games
, _PATH_GAMES
);
if ((fp
= fopen(games
, "r")) == NULL
) {
if (fgets(line
, sizeof(line
), fp
) == NULL
) {
fprintf(stderr
, "%s: no default game available\n", games
);
line
[strlen(line
) - 1] = '\0';
strcpy(file
, _PATH_GAMES
);
char *ret
= NULL
, line
[256], games
[256];
strcpy(games
, _PATH_GAMES
);
if ((fp
= fopen(games
, "r")) == NULL
) {
while (fgets(line
, sizeof(line
), fp
) != NULL
) {
line
[strlen(line
) - 1] = '\0';
if (strcmp(s
, line
) == 0) {
strcpy(file
, _PATH_GAMES
);
fprintf(stderr
, "%s: %s: game not found\n", games
, s
);
fprintf(stderr
, "Your score will not be logged.\n");
sleep(2); /* give the guy time to read it */
char line
[256], games
[256];
strcpy(games
, _PATH_GAMES
);
if ((fp
= fopen(games
, "r")) == NULL
) {
puts("available games:");
while (fgets(line
, sizeof(line
), fp
) != NULL
) {
fprintf(stderr
, "%s: no games available\n", games
);