-/* $NetBSD: score.c,v 1.7 1999/05/16 00:03:35 christos Exp $ */
+/* $NetBSD: score.c,v 1.15 2000/04/27 19:31:23 thorpej Exp $ */
/*
* Copyright (c) 1980, 1993
#if 0
static char sccsid[] = "@(#)score.c 8.1 (Berkeley) 5/31/93";
#else
-__RCSID("$NetBSD: score.c,v 1.7 1999/05/16 00:03:35 christos Exp $");
+__RCSID("$NetBSD: score.c,v 1.15 2000/04/27 19:31:23 thorpej Exp $");
#endif
#endif /* not lint */
# include "robots.h"
# include "pathnames.h"
-char *Scorefile = _PATH_SCORE;
+const char *Scorefile = _PATH_SCORE;
int Max_per_uid = MAX_PER_UID;
{
SCORE *scp;
- lseek(inf, 0L, 0);
+ lseek(inf, 0L, SEEK_SET);
max_uid = htonl(max_uid);
write(inf, &max_uid, sizeof max_uid);
* top list.
*/
void
-score()
+score(score_wfd)
+ int score_wfd;
{
- int inf;
+ int inf = score_wfd;
SCORE *scp;
- int uid;
+ u_int32_t uid;
bool done_show = FALSE;
Newscore = FALSE;
- if ((inf = open(Scorefile, O_RDWR)) < 0) {
- warn("opening `%s'", Scorefile);
+ if (inf < 0)
return;
- }
read_score(inf);
if (Top[MAXSCORES-1].s_score <= Score) {
numscores = 0;
for (scp = Top; scp < &Top[MAXSCORES]; scp++)
- if (scp->s_score < 0 ||
- (scp->s_uid == uid && ++numscores == max_uid)) {
+ if ((scp->s_uid == uid && ++numscores == max_uid)) {
if (scp->s_score > Score)
break;
scp->s_score = Score;
if (!Newscore) {
Full_clear = FALSE;
- close(inf);
+ lseek(inf, 0, SEEK_SET);
return;
}
else
move((scp - Top) + 2, 15);
if (!done_show && scp->s_uid == uid && scp->s_score == Score)
standout();
- printw("%5.5d %5.5d %-8.8s %-9.9s %5.5d",
- (scp - Top) + 1, scp->s_score, scp->s_name,
- Auto_bot ? "(autobot)" : "", scp->s_level);
+ printw("%5ld %5d %-8.8s %-9.9s %5d",
+ (long)(scp - Top) + 1, scp->s_score, scp->s_name,
+ scp->s_auto ? "(autobot)" : "", scp->s_level);
if (!done_show && scp->s_uid == uid && scp->s_score == Score) {
standend();
done_show = TRUE;
if (Newscore) {
write_score(inf);
}
- close(inf);
+ lseek(inf, 0, SEEK_SET);
}
void
SCORE *scp;
{
PASSWD *pp;
+ static char unknown[] = "???";
if ((pp = getpwuid(scp->s_uid)) == NULL)
- pp->pw_name = "???";
+ pp->pw_name = unknown;
strncpy(scp->s_name, pp->pw_name, MAXNAME);
}
cmp_sc(s1, s2)
const void *s1, *s2;
{
- return ((SCORE *)s2)->s_score - ((SCORE *)s1)->s_score;
+ return ((const SCORE *)s2)->s_score - ((const SCORE *)s1)->s_score;
}
/*
" ", "Level");
for (scp = Top; scp < &Top[MAXSCORES]; scp++)
if (scp->s_score > 0)
- printf("%5.5d %5.5d %-8.8s %-9.9s %5.5d\n",
+ printf("%5d %5d %-8.8s %-9.9s %5d\n",
inf++, scp->s_score, scp->s_name,
scp->s_auto ? "(autobot)" : "", scp->s_level);
}