]> git.cameronkatri.com Git - bsdgames-darwin.git/blobdiff - robots/main.c
Changed deprecated curses call to new equivalent.
[bsdgames-darwin.git] / robots / main.c
index b1c2ff368d34b5793c32f36e5f7eb6538b7cd3d9..3cb81a0b442c4762bf4f3ddcab825a39fff315c5 100644 (file)
@@ -1,4 +1,4 @@
-/*     $NetBSD: main.c,v 1.8 1999/05/15 23:56:36 christos Exp $        */
+/*     $NetBSD: main.c,v 1.18 2001/12/06 12:17:57 blymn Exp $  */
 
 /*
  * Copyright (c) 1980, 1993
@@ -43,7 +43,7 @@ __COPYRIGHT("@(#) Copyright (c) 1980, 1993\n\
 #if 0
 static char sccsid[] = "@(#)main.c     8.1 (Berkeley) 5/31/93";
 #else
-__RCSID("$NetBSD: main.c,v 1.8 1999/05/15 23:56:36 christos Exp $");
+__RCSID("$NetBSD: main.c,v 1.18 2001/12/06 12:17:57 blymn Exp $");
 #endif
 #endif /* not lint */
 
@@ -51,16 +51,28 @@ __RCSID("$NetBSD: main.c,v 1.8 1999/05/15 23:56:36 christos Exp $");
 
 int main __P((int, char **));
 
+extern const char      *Scorefile;
+extern int     Max_per_uid;
+
 int
 main(ac, av)
        int     ac;
        char    **av;
 {
-       char    *sp;
+       const char      *sp;
        bool    bad_arg;
        bool    show_only;
-       extern char     *Scorefile;
-       extern int      Max_per_uid;
+       int             score_wfd; /* high score writable file descriptor */
+       int             score_err = 0; /* hold errno from score file open */
+
+       score_wfd = open(Scorefile, O_RDWR);
+       if (score_wfd < 0)
+               score_err = errno;
+       else if (score_wfd < 3)
+               exit(1);
+
+       /* Revoke setgid privileges */
+       setgid(getgid());
 
        show_only = FALSE;
        Num_games = 1;
@@ -71,9 +83,12 @@ main(ac, av)
                                if (isdigit(av[0][0]))
                                        Max_per_uid = atoi(av[0]);
                                else {
-                                       setuid(getuid());
-                                       setgid(getgid());
                                        Scorefile = av[0];
+                                       if (score_wfd >= 0)
+                                               close(score_wfd);
+                                       score_wfd = open(Scorefile, O_RDWR);
+                                       if (score_wfd < 0)
+                                               score_err = errno;
 # ifdef        FANCY
                                        sp = strrchr(Scorefile, '/');
                                        if (sp == NULL)
@@ -112,7 +127,7 @@ main(ac, av)
                                                break;
                                          
                                          default:
-                                               fprintf(stderr, "robots: uknown option: %c\n", *sp);
+                                               fprintf(stderr, "robots: unknown option: %c\n", *sp);
                                                bad_arg = TRUE;
                                                break;
                                        }
@@ -128,9 +143,16 @@ main(ac, av)
                /* NOTREACHED */
        }
 
+       if (score_wfd < 0) {
+               errno = score_err;
+               warn("%s", Scorefile);
+               warnx("High scores will not be recorded!");
+               sleep(2);
+       }
+
        initscr();
        signal(SIGINT, quit);
-       crmode();
+       cbreak();
        noecho();
        nonl();
        if (LINES != Y_SIZE || COLS != X_SIZE) {
@@ -161,31 +183,25 @@ main(ac, av)
                        refresh();
                        if (Auto_bot)
                                sleep(1);
-                       score();
+                       score(score_wfd);
                        if (Auto_bot)
                                sleep(1);
                        refresh();
                }
+               Num_games = 1;
        } while (!Auto_bot && another());
        quit(0);
        /* NOTREACHED */
        return(0);
 }
 
-void
-__cputchar(ch)
-       int ch;
-{
-       (void)putchar(ch);
-}
-
 /*
  * quit:
  *     Leave the program elegantly.
  */
 void
 quit(dummy)
-       int dummy;
+       int dummy __attribute__((__unused__));
 {
        endwin();
        exit(0);