]> git.cameronkatri.com Git - bsdgames-darwin.git/blobdiff - larn/scores.c
Fix merge conflicts
[bsdgames-darwin.git] / larn / scores.c
index a6a47cf64531bb3cfd3fe5f1655cc06ad4212afd..6d4d8c5bfc1d1009908cd1c8909dfcb54d81058a 100644 (file)
@@ -1,10 +1,10 @@
-/*     $NetBSD: scores.c,v 1.18 2009/08/12 08:04:05 dholland Exp $     */
+/*     $NetBSD: scores.c,v 1.22 2021/05/02 12:50:45 rillig Exp $       */
 
 /*
  * scores.c                     Larn is copyrighted 1986 by Noah Morgan.
- * 
+ *
  * Functions in this file are:
- * 
+ *
  * readboard()         Function to read in the scoreboard into a static buffer
  * writeboard()        Function to write the scoreboard from readboard()'s buffer
  * makeboard()         Function to create a new scoreboard (wipe out old one)
  * line showing player when he is killed diedlog()     Subroutine to read a
  * log file and print it out in ascii format getplid(name)
  * on to get players id # from id file
- * 
+ *
  */
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: scores.c,v 1.18 2009/08/12 08:04:05 dholland Exp $");
+__RCSID("$NetBSD: scores.c,v 1.22 2021/05/02 12:50:45 rillig Exp $");
 #endif                         /* not lint */
 #include <sys/types.h>
 #include <sys/times.h>
@@ -38,6 +38,8 @@ __RCSID("$NetBSD: scores.c,v 1.18 2009/08/12 08:04:05 dholland Exp $");
 #include "header.h"
 #include "extern.h"
 
+#include <time.h>
+
 struct scofmt {                        /* This is the structure for the scoreboard              */
        long            score;  /* the score of the player                                                       */
        long            suid;   /* the user id number of the player                              */
@@ -64,7 +66,7 @@ struct wscofmt {              /* This is the structure for the winning
 
 struct log_fmt {               /* 102 bytes struct for the log file                             */
        long            score;  /* the players score                                                             */
-       time_t          diedtime;       /* time when game was over                                                       */
+       int32_t          diedtime;      /* time when game was over                                                       */
        short           cavelev;/* level in caves                                                                        */
        short           diff;   /* difficulty player played at                                           */
 #ifdef EXTRA
@@ -118,7 +120,7 @@ static void diedsub(int);
  * returns -1 if unable to read in the scoreboard, returns 0 if all is OK
  */
 static int
-readboard()
+readboard(void)
 {
        int             i;
 
@@ -145,7 +147,7 @@ readboard()
  * returns -1 if unable to write the scoreboard, returns 0 if all is OK
  */
 static int
-writeboard()
+writeboard(void)
 {
        int             i;
 
@@ -173,7 +175,7 @@ writeboard()
  * returns -1 if unable to write the scoreboard, returns 0 if all is OK
  */
 int
-makeboard()
+makeboard(void)
 {
        int    i;
        set_score_output();
@@ -200,7 +202,7 @@ makeboard()
  * the winners scoreboard.
  */
 int
-hashewon()
+hashewon(void)
 {
        int    i;
        c[HARDGAME] = 0;
@@ -222,9 +224,8 @@ hashewon()
  * Enter with the amount (in gp) to pay on the taxes.
  * Returns amount actually paid.
  */
-long 
-paytaxes(x)
-       long            x;
+long
+paytaxes(long x)
 {
        int    i;
        long   amt;
@@ -257,7 +258,7 @@ paytaxes(x)
  * Returns the number of players on scoreboard that were shown
  */
 static int
-winshou()
+winshou(void)
 {
        struct wscofmt *p;
        int    i, j, count;
@@ -296,8 +297,7 @@ winshou()
  * Returns the number of players on scoreboard that were shown
  */
 static int
-shou(x)
-       int             x;
+shou(int x)
 {
        int    i, j, n, k;
        int             count;
@@ -351,7 +351,7 @@ shou(x)
  */
 static char     esb[] = "The scoreboard is empty.\n";
 void
-showscores()
+showscores(void)
 {
        int    i, j;
        lflush();
@@ -373,7 +373,7 @@ showscores()
  * Returns nothing of value
  */
 void
-showallscores()
+showallscores(void)
 {
        int    i, j;
        lflush();
@@ -401,7 +401,7 @@ showallscores()
  * Returns 0 if no sorting done, else returns 1
  */
 static int
-sortboard()
+sortboard(void)
 {
        int    i, j = 0, pos;
        long            jdat;
@@ -440,10 +440,7 @@ sortboard()
  * ex.         newscore(1000, "player 1", 32, 0);
  */
 static void
-newscore(score, whoo, whyded, winner)
-       long            score;
-       int             winner, whyded;
-       char           *whoo;
+newscore(long score, char *whoo, int whyded, int winner)
 {
        int    i;
        long            taxes;
@@ -509,10 +506,7 @@ newscore(score, whoo, whyded, winner)
  * Returns nothing of value
  */
 static void
-new1sub(score, i, whoo, taxes)
-       long            score, taxes;
-       int             i;
-       char           *whoo;
+new1sub(long score, int i, char *whoo, long taxes)
 {
        struct wscofmt *p;
        p = &winr[i];
@@ -536,10 +530,7 @@ new1sub(score, i, whoo, taxes)
  * Returns nothing of value
  */
 static void
-new2sub(score, i, whoo, whyded)
-       long            score;
-       int             i, whyded;
-       char           *whoo;
+new2sub(long score, int i, char *whoo, int whyded)
 {
        int    j;
        struct scofmt *p;
@@ -601,8 +592,7 @@ new2sub(score, i, whoo, whyded)
 
 static int      scorerror;
 void
-died(x)
-       int             x;
+died(int x)
 {
        int    f, win;
        char            ch;
@@ -768,11 +758,14 @@ diedsub(int x)
  * diedlog()   Subroutine to read a log file and print it out in ascii format
  */
 void
-diedlog()
+diedlog(void)
 {
        int    n;
        char  *p;
+       static char  q[] = "?";
        struct stat     stbuf;
+       time_t t;
+
        lcreat((char *) 0);
        if (lopen(logfile) < 0) {
                lprintf("Can't locate log file <%s>\n", logfile);
@@ -784,9 +777,13 @@ diedlog()
        }
        for (n = stbuf.st_size / sizeof(struct log_fmt); n > 0; --n) {
                lrfill((char *) &logg, sizeof(struct log_fmt));
-               p = ctime(&logg.diedtime);
-               p[16] = '\n';
-               p[17] = 0;
+               t = logg.diedtime;
+               if ((p = ctime(&t)) == NULL)
+                       p = q;
+               else {
+                       p[16] = '\n';
+                       p[17] = 0;
+               }
                lprintf("Score: %ld, Diff: %ld,  %s %s on %ld at %s", (long) (logg.score), (long) (logg.diff), logg.who, logg.what, (long) (logg.cavelev), p + 4);
 #ifdef EXTRA
                if (logg.moves <= 0)