X-Git-Url: https://git.cameronkatri.com/bsdgames-darwin.git/blobdiff_plain/04f4d7044367099914cf1906ae27ac20c24e44cf..84d25b7fc1866e662d07f1e5d4b17f13c8547fc9:/robots/score.c?ds=sidebyside diff --git a/robots/score.c b/robots/score.c index c22a7463..62709435 100644 --- a/robots/score.c +++ b/robots/score.c @@ -1,4 +1,4 @@ -/* $NetBSD: score.c,v 1.8 1999/09/08 21:17:57 jsm Exp $ */ +/* $NetBSD: score.c,v 1.18 2006/03/17 23:11:47 abs Exp $ */ /* * Copyright (c) 1980, 1993 @@ -12,11 +12,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -38,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)score.c 8.1 (Berkeley) 5/31/93"; #else -__RCSID("$NetBSD: score.c,v 1.8 1999/09/08 21:17:57 jsm Exp $"); +__RCSID("$NetBSD: score.c,v 1.18 2006/03/17 23:11:47 abs Exp $"); #endif #endif /* not lint */ @@ -53,8 +49,8 @@ static SCORE Top[MAXSCORES]; static u_int32_t numscores, max_uid; -static void read_score __P((int)); -static void write_score __P((int)); +static void read_score(int); +static void write_score(int); /* * read_score: @@ -94,7 +90,7 @@ write_score(inf) { SCORE *scp; - lseek(inf, 0L, 0); + lseek(inf, 0L, SEEK_SET); max_uid = htonl(max_uid); write(inf, &max_uid, sizeof max_uid); @@ -116,18 +112,17 @@ write_score(inf) * 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); @@ -135,8 +130,7 @@ score() 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; @@ -161,7 +155,7 @@ score() if (!Newscore) { Full_clear = FALSE; - close(inf); + lseek(inf, 0, SEEK_SET); return; } else @@ -177,9 +171,9 @@ score() 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; @@ -191,7 +185,7 @@ score() if (Newscore) { write_score(inf); } - close(inf); + lseek(inf, 0, SEEK_SET); } void @@ -199,11 +193,11 @@ set_name(scp) SCORE *scp; { PASSWD *pp; - static char unknown[] = "???"; if ((pp = getpwuid(scp->s_uid)) == NULL) - pp->pw_name = unknown; - strncpy(scp->s_name, pp->pw_name, MAXNAME); + strncpy(scp->s_name, "???", MAXNAME); + else + strncpy(scp->s_name, pp->pw_name, MAXNAME); } /* @@ -239,7 +233,7 @@ show_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); }