+/* $NetBSD: main.c,v 1.6 1997/10/11 02:01:05 lukem Exp $ */
+
/*-
- * Copyright (c) 1990 The Regents of the University of California.
- * All rights reserved.
+ * Copyright (c) 1990, 1993
+ * The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Ed James.
* For more info on this and all of my stuff, mail edjames@berkeley.edu.
*/
+#include <sys/cdefs.h>
#ifndef lint
-char copyright[] =
-"@(#) Copyright (c) 1990 The Regents of the University of California.\n\
- All rights reserved.\n";
+__COPYRIGHT("@(#) Copyright (c) 1990, 1993\n\
+ The Regents of the University of California. All rights reserved.\n");
#endif /* not lint */
#ifndef lint
-static char sccsid[] = "@(#)main.c 5.4 (Berkeley) 3/5/91";
+#if 0
+static char sccsid[] = "@(#)main.c 8.1 (Berkeley) 5/31/93";
+#else
+__RCSID("$NetBSD: main.c,v 1.6 1997/10/11 02:01:05 lukem Exp $");
+#endif
#endif /* not lint */
#include "include.h"
#include "pathnames.h"
+
+int
main(ac, av)
+ int ac;
char *av[];
{
int seed;
int f_printpath = 0;
char *file = NULL;
char *name, *ptr;
+ struct sigaction sa;
#ifdef BSD
struct itimerval itv;
#endif
- extern char *default_game(), *okay_game();
- extern void log_score(), quit(), update();
start_time = seed = time(0);
while (*av) {
#ifndef SAVEDASH
if (**av == '-')
- *++*av;
+ ++*av;
else
break;
#endif
av++;
break;
default:
- fprintf(stderr, "Unknown option '%c'\n", *ptr,
- name);
+ warnx("unknown option '%c'\n", *ptr);
f_usage++;
break;
}
signal(SIGTSTP, SIG_IGN);
signal(SIGSTOP, SIG_IGN);
#endif
- signal(SIGHUP, log_score);
- signal(SIGTERM, log_score);
-
-#ifdef BSD
- 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);
-#endif
+ signal(SIGHUP, log_score_quit);
+ signal(SIGTERM, log_score_quit);
-#ifdef SYSV
- ioctl(fileno(stdin), TCGETA, &tty_start);
- bcopy(&tty_start, &tty_new, sizeof(tty_new));
- tty_new.c_lflag &= ~ICANON;
- tty_new.c_lflag &= ~ECHO;
+ tcgetattr(fileno(stdin), &tty_start);
+ tty_new = tty_start;
+ tty_new.c_lflag &= ~(ICANON|ECHO);
tty_new.c_cc[VMIN] = 1;
tty_new.c_cc[VTIME] = 0;
- ioctl(fileno(stdin), TCSETAW, &tty_new);
-#endif
+ tcsetattr(fileno(stdin), TCSADRAIN, &tty_new);
- signal(SIGALRM, update);
+ sa.sa_handler = update;
+ sigemptyset(&sa.sa_mask);
+ sigaddset(&sa.sa_mask, SIGALRM);
+ sigaddset(&sa.sa_mask, SIGINT);
+ sa.sa_flags = 0;
+ sigaction(SIGALRM, &sa, (struct sigaction *)0);
#ifdef BSD
itv.it_value.tv_sec = 0;
alarm(0);
#endif
- update();
+ update(0);
#ifdef BSD
itv.it_value.tv_sec = sp->update_secs;
}
}
+int
read_file(s)
char *s;
{
file = s;
yyin = fopen(s, "r");
if (yyin == NULL) {
- perror(s);
+ warn("fopen %s", s);
return (-1);
}
retval = yyparse();
strcat(games, GAMES);
if ((fp = fopen(games, "r")) == NULL) {
- perror(games);
+ warn("fopen %s", games);
return (NULL);
}
if (fgets(line, sizeof(line), fp) == NULL) {
strcat(games, GAMES);
if ((fp = fopen(games, "r")) == NULL) {
- perror(games);
+ warn("fopen %s", games);
return (NULL);
}
while (fgets(line, sizeof(line), fp) != NULL) {
return (ret);
}
+int
list_games()
{
FILE *fp;
strcat(games, GAMES);
if ((fp = fopen(games, "r")) == NULL) {
- perror(games);
+ warn("fopen %s", games);
return (-1);
}
puts("available games:");