-/* $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>
#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 */
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
* returns -1 if unable to read in the scoreboard, returns 0 if all is OK
*/
static int
-readboard()
+readboard(void)
{
int i;
* returns -1 if unable to write the scoreboard, returns 0 if all is OK
*/
static int
-writeboard()
+writeboard(void)
{
int i;
* returns -1 if unable to write the scoreboard, returns 0 if all is OK
*/
int
-makeboard()
+makeboard(void)
{
int i;
set_score_output();
* the winners scoreboard.
*/
int
-hashewon()
+hashewon(void)
{
int i;
c[HARDGAME] = 0;
* 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;
* Returns the number of players on scoreboard that were shown
*/
static int
-winshou()
+winshou(void)
{
struct wscofmt *p;
int i, j, count;
* 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;
*/
static char esb[] = "The scoreboard is empty.\n";
void
-showscores()
+showscores(void)
{
int i, j;
lflush();
* Returns nothing of value
*/
void
-showallscores()
+showallscores(void)
{
int i, j;
lflush();
* Returns 0 if no sorting done, else returns 1
*/
static int
-sortboard()
+sortboard(void)
{
int i, j = 0, pos;
long jdat;
* 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;
* 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];
* 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;
static int scorerror;
void
-died(x)
- int x;
+died(int x)
{
int f, win;
char ch;
* 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);
}
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)