-/* $NetBSD: main.c,v 1.21 2012/10/12 10:44:20 dholland Exp $ */
+/* $NetBSD: main.c,v 1.25 2021/05/02 12:50:43 rillig Exp $ */
/*-
* Copyright (c) 1990, 1993
#if 0
static char sccsid[] = "@(#)main.c 8.1 (Berkeley) 5/31/93";
#else
-__RCSID("$NetBSD: main.c,v 1.21 2012/10/12 10:44:20 dholland Exp $");
+__RCSID("$NetBSD: main.c,v 1.25 2021/05/02 12:50:43 rillig Exp $");
#endif
#endif /* not lint */
-#include "include.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <signal.h>
+#include <termios.h>
+#include <getopt.h>
+#include <err.h>
+
#include "pathnames.h"
+#include "def.h"
+#include "struct.h"
+#include "extern.h"
+#include "tunable.h"
extern FILE *yyin;
static const char *default_game(void);
static const char *okay_game(const char *);
static int list_games(void);
+static void quit(int);
int
main(int argc, char *argv[])
switch (ch) {
case '?':
case 'u':
- default:
+ default:
f_usage = 1;
break;
case 'l':
srandom(seed);
if (f_usage)
- (void)fprintf(stderr,
+ (void)fprintf(stderr,
"Usage: %s -[u?lstp] [-[gf] game_name] [-r random seed]\n",
argv[0]);
if (f_showscore)
(void)strlcpy(buf, _PATH_GAMES, 100);
(void)puts(buf);
}
-
+
if (f_usage || f_showscore || f_list || f_printpath)
exit(0);
init_gr();
setup_screen(sp);
- (void)addplane();
+ addplane();
(void)signal(SIGINT, quit);
(void)signal(SIGQUIT, quit);
}
return (0);
}
+
+/* ARGSUSED */
+static void
+quit(int dummy __unused)
+{
+ int c;
+#ifdef BSD
+ struct itimerval itv;
+#endif
+ ioaskquit();
+ c = getAChar();
+ if (c == EOF || c == 'y') {
+ /* disable timer */
+#ifdef BSD
+ itv.it_value.tv_sec = 0;
+ itv.it_value.tv_usec = 0;
+ (void)setitimer(ITIMER_REAL, &itv, NULL);
+#endif
+#ifdef SYSV
+ alarm(0);
+#endif
+ shutdown_gr();
+ (void)log_score(0);
+ exit(0);
+ }
+ ionoquit();
+}