]> git.cameronkatri.com Git - bsdgames-darwin.git/blobdiff - atc/main.c
Fix merge conflicts
[bsdgames-darwin.git] / atc / main.c
index b4dbde3d932d721c48af3e5cfb98f5074ae1532b..9ef6ce111d9719165c0d6293f33d0327a01f6dde 100644 (file)
@@ -1,4 +1,4 @@
-/*     $NetBSD: main.c,v 1.17 2006/06/07 09:35:03 jnemeth Exp $        */
+/*     $NetBSD: main.c,v 1.25 2021/05/02 12:50:43 rillig Exp $ */
 
 /*-
  * Copyright (c) 1990, 1993
 
 #include <sys/cdefs.h>
 #ifndef lint
-__COPYRIGHT("@(#) Copyright (c) 1990, 1993\n\
      The Regents of the University of California.  All rights reserved.\n");
+__COPYRIGHT("@(#) Copyright (c) 1990, 1993\
The Regents of the University of California.  All rights reserved.");
 #endif /* not lint */
 
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)main.c     8.1 (Berkeley) 5/31/93";
 #else
-__RCSID("$NetBSD: main.c,v 1.17 2006/06/07 09:35:03 jnemeth 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 int read_file(const char *);
+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[])
 {
-       int                     seed;
+       unsigned long           seed;
        int                     f_usage = 0, f_list = 0, f_showscore = 0;
        int                     f_printpath = 0;
        const char              *file = NULL;
@@ -77,24 +94,25 @@ main(int argc, char *argv[])
        open_score_file();
        (void)setgid(getgid());
 
-       start_time = seed = time(NULL);
+       start_time = time(NULL);
+       seed = start_time;
 
        while ((ch = getopt(argc, argv, ":u?lstpg:f:r:")) != -1) {
                switch (ch) {
                case '?':
                case 'u':
-               default: 
-                       f_usage++;
+               default:
+                       f_usage = 1;
                        break;
                case 'l':
-                       f_list++;
+                       f_list = 1;
                        break;
                case 's':
                case 't':
-                       f_showscore++;
+                       f_showscore = 1;
                        break;
                case 'p':
-                       f_printpath++;
+                       f_printpath = 1;
                        break;
                case 'r':
                        seed = atoi(optarg);
@@ -106,11 +124,11 @@ main(int argc, char *argv[])
                }
        }
        if (optind < argc)
-               f_usage++;
-       srandom((unsigned long)seed);
+               f_usage = 1;
+       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)
@@ -123,7 +141,7 @@ main(int argc, char *argv[])
                (void)strlcpy(buf, _PATH_GAMES, 100);
                (void)puts(buf);
        }
-               
+
        if (f_usage || f_showscore || f_list || f_printpath)
                exit(0);
 
@@ -138,7 +156,7 @@ main(int argc, char *argv[])
        init_gr();
        setup_screen(sp);
 
-       (void)addplane();
+       addplane();
 
        (void)signal(SIGINT, quit);
        (void)signal(SIGQUIT, quit);
@@ -203,7 +221,7 @@ main(int argc, char *argv[])
        }
 }
 
-int
+static int
 read_file(const char *s)
 {
        int             retval;
@@ -223,7 +241,7 @@ read_file(const char *s)
                return (0);
 }
 
-const char *
+static const char *
 default_game(void)
 {
        FILE            *fp;
@@ -249,7 +267,7 @@ default_game(void)
        return (file);
 }
 
-const char *
+static const char *
 okay_game(const char *s)
 {
        FILE            *fp;
@@ -284,7 +302,7 @@ okay_game(const char *s)
        return (ret);
 }
 
-int
+static int
 list_games(void)
 {
        FILE            *fp;
@@ -310,3 +328,30 @@ list_games(void)
        }
        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();
+}