]> git.cameronkatri.com Git - bsdgames-darwin.git/blobdiff - tetris/scores.c
- Accept octal input.
[bsdgames-darwin.git] / tetris / scores.c
index eaf2618c16bc67f63db8d12741b5fbc477d954c3..1335df7ba18c8162074b67e6b376d16df77edbb6 100644 (file)
@@ -1,4 +1,4 @@
-/*     $NetBSD: scores.c,v 1.18 2009/09/08 13:38:01 dholland Exp $     */
+/*     $NetBSD: scores.c,v 1.25 2020/09/07 00:31:11 mrg Exp $  */
 
 /*-
  * Copyright (c) 1992, 1993
@@ -50,7 +50,7 @@
 #include <string.h>
 #include <sys/stat.h>
 #include <time.h>
-#include <termcap.h>
+#include <term.h>
 #include <unistd.h>
 
 #include "pathnames.h"
@@ -381,7 +381,7 @@ getscores(int *fdp)
        struct highscore_header header;
        int sd, mint, lck;
        mode_t mask;
-       const char *mstr, *human;
+       const char *human;
        int doflip;
        int serrno;
        ssize_t result;
@@ -395,7 +395,6 @@ getscores(int *fdp)
 #endif
        {
                mint = O_RDONLY;
-               mstr = "r";
                human = "reading";
                lck = LOCK_SH;
        }
@@ -413,6 +412,7 @@ getscores(int *fdp)
                 * trying to write it, don't fail -- we can still show
                 * the player the score they got.
                 */
+               errno = serrno;
                if (fdp != NULL || errno != ENOENT) {
                        warn("Cannot open %s for %s", _PATH_SCOREFILE, human);
                }
@@ -458,8 +458,7 @@ getscores(int *fdp)
        result = read(sd, &header, sizeof(header));
        if (result < 0) {
                warn("Score file %s: read", _PATH_SCOREFILE);
-               close(sd);
-               goto fail;
+               goto sdfail;
        }
        if (result != 0 && (size_t)result != sizeof(header)) {
                warnx("Score file %s: read: unexpected EOF", _PATH_SCOREFILE);
@@ -470,13 +469,12 @@ getscores(int *fdp)
                if (lseek(sd, 0, SEEK_SET) < 0) {
                        /* ? */
                        warn("Score file %s: lseek", _PATH_SCOREFILE);
-                       goto fail;
+                       goto sdfail;
                }
                if (ftruncate(sd, 0) == 0) {
                        result = 0;
                } else {
-                       close(sd);
-                       goto fail;
+                       goto sdfail;
                }
        }
 
@@ -501,17 +499,17 @@ getscores(int *fdp)
                        } else {
                                warnx("Score file %s: Unknown endian tag %u",
                                        _PATH_SCOREFILE, header.hsh_endiantag);
-                               goto fail;
+                               goto sdfail;
                        }
 
                        if (header.hsh_version != HSH_VERSION) {
                                warnx("Score file %s: Unknown version code %u",
                                        _PATH_SCOREFILE, header.hsh_version);
-                               goto fail;
+                               goto sdfail;
                        }
 
                        if (readscores(sd, doflip) < 0) {
-                               goto fail;
+                               goto sdfail;
                        }
                } else {
                        /*
@@ -521,7 +519,7 @@ getscores(int *fdp)
                        result = scorefile_probe(sd);
                        if (lseek(sd, 0, SEEK_SET) < 0) {
                                warn("Score file %s: lseek", _PATH_SCOREFILE);
-                               goto fail;
+                               goto sdfail;
                        }
                        switch (result) {
                        case SCOREFILE_CURRENT:
@@ -543,10 +541,10 @@ getscores(int *fdp)
                                result = readscores50(sd, 1 /* do flip */);
                                break;
                        default:
-                               goto fail;
+                               goto sdfail;
                        }
                        if (result < 0) {
-                               goto fail;
+                               goto sdfail;
                        }
                }
        }
@@ -559,6 +557,8 @@ getscores(int *fdp)
 
        return;
 
+sdfail:
+       close(sd);
  fail:
        if (fdp != NULL) {
                *fdp = -1;
@@ -599,7 +599,7 @@ putscores(int sd)
 {
 #ifdef ALLOW_SCORE_UPDATES
        struct highscore_header header;
-       struct highscore_ondisk buf[MAXHISCORES];
+       struct highscore_ondisk buf[MAXHISCORES] = {0};
        int i;
 
        if (sd == -1) {
@@ -611,7 +611,7 @@ putscores(int sd)
        header.hsh_version = HSH_VERSION;
 
        for (i=0; i<nscores; i++) {
-               strncpy(buf[i].hso_name, scores[i].hs_name,
+               memcpy(buf[i].hso_name, scores[i].hs_name,
                        sizeof(buf[i].hso_name));
                buf[i].hso_score = scores[i].hs_score;
                buf[i].hso_level = scores[i].hs_level;
@@ -830,8 +830,8 @@ checkscores(struct highscore *hs, int num)
                                continue;
                        }
                }
-        if (sp->hs_level < NLEVELS && sp->hs_level >= 0)
-               levelfound[sp->hs_level] = 1;
+               if (sp->hs_level < NLEVELS && sp->hs_level >= 0)
+                       levelfound[sp->hs_level] = 1;
                i++, sp++;
        }
        return (num > MAXHISCORES ? MAXHISCORES : num);
@@ -861,7 +861,7 @@ showscores(int level)
         * the high scores; we do not need to check for printing in highlight
         * mode.  If SOstr is null, we can't do highlighting anyway.
         */
-       me = level && SOstr ? thisuser() : NULL;
+       me = level && enter_standout_mode ? thisuser() : NULL;
 
        /*
         * Set times to 0 except for high score on each level.
@@ -939,12 +939,12 @@ printem(int level, int offset, struct highscore *hs, int n, const char *me)
                            sp->hs_level == level &&
                            sp->hs_score == score &&
                            strcmp(sp->hs_name, me) == 0) {
-                               putpad(SOstr);
+                               putpad(enter_standout_mode);
                                highlight = 1;
                        }
                        (void)printf("%s", buf);
                        if (highlight) {
-                               putpad(SEstr);
+                               putpad(exit_standout_mode);
                                highlight = 0;
                        }