* Copyright (c) 1990 The Regents of the University of California.
* This code is derived from software contributed to Berkeley by
* %sccs.include.redist.c%
* 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) %G%";
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
);