diff options
author | Paul Janzen <pjanzen@cvs.openbsd.org> | 2000-07-23 21:49:08 +0000 |
---|---|---|
committer | Paul Janzen <pjanzen@cvs.openbsd.org> | 2000-07-23 21:49:08 +0000 |
commit | 02987a4b80b90523e231e88ea50eec97b413715f (patch) | |
tree | 0c1e8ebc25501cf1861a289a53eac63982b7e7c1 /games/canfield/cfscores | |
parent | bb6ee9445b49236cf0f512084eb9cfb7c27b91fe (diff) |
Code cleanups (some from NetBSD), typo fix.
Don't barf if stdin hits EOF.
Install cfscores in /var/games if one isn't already there.
Diffstat (limited to 'games/canfield/cfscores')
-rw-r--r-- | games/canfield/cfscores/Makefile | 2 | ||||
-rw-r--r-- | games/canfield/cfscores/cfscores.c | 42 |
2 files changed, 24 insertions, 20 deletions
diff --git a/games/canfield/cfscores/Makefile b/games/canfield/cfscores/Makefile index bdc6269f8c3..78ccc6a39f7 100644 --- a/games/canfield/cfscores/Makefile +++ b/games/canfield/cfscores/Makefile @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.3 1995/03/21 15:08:36 cgd Exp $ +# $OpenBSD: Makefile,v 1.2 2000/07/23 21:49:07 pjanzen Exp $ # @(#)Makefile 8.1 (Berkeley) 5/31/93 PROG= cfscores diff --git a/games/canfield/cfscores/cfscores.c b/games/canfield/cfscores/cfscores.c index c3f9fe3be89..fb0bbf7be49 100644 --- a/games/canfield/cfscores/cfscores.c +++ b/games/canfield/cfscores/cfscores.c @@ -1,3 +1,4 @@ +/* $OpenBSD: cfscores.c,v 1.5 2000/07/23 21:49:07 pjanzen Exp $ */ /* $NetBSD: cfscores.c,v 1.3 1995/03/21 15:08:37 cgd Exp $ */ /* @@ -43,11 +44,12 @@ static char copyright[] = #if 0 static char sccsid[] = "@(#)cfscores.c 8.1 (Berkeley) 5/31/93"; #else -static char rcsid[] = "$NetBSD: cfscores.c,v 1.3 1995/03/21 15:08:37 cgd Exp $"; +static char rcsid[] = "$OpenBSD: cfscores.c,v 1.5 2000/07/23 21:49:07 pjanzen Exp $"; #endif #endif /* not lint */ #include <sys/types.h> +#include <err.h> #include <fcntl.h> #include <pwd.h> #include <stdio.h> @@ -67,22 +69,23 @@ struct betinfo { int dbfd; +void printuser __P((const struct passwd *, int)); + +int main(argc, argv) int argc; char *argv[]; { - register struct passwd *pw; + struct passwd *pw; int uid; if (argc > 2) { - printf("Usage: cfscores [user]\n"); + fprintf(stderr, "Usage: cfscores [user]\n"); exit(1); } dbfd = open(_PATH_SCORE, O_RDONLY); - if (dbfd < 0) { - perror(_PATH_SCORE); - exit(2); - } + if (dbfd < 0) + err(2, "%s", _PATH_SCORE); /* revoke privs */ setegid(getgid()); @@ -116,8 +119,9 @@ main(argc, argv) /* * print out info for specified password entry */ +void printuser(pw, printfail) - register struct passwd *pw; + const struct passwd *pw; int printfail; { struct betinfo total; @@ -129,12 +133,12 @@ printuser(pw, printfail) } i = lseek(dbfd, pw->pw_uid * sizeof(struct betinfo), SEEK_SET); if (i < 0) { - perror("lseek"); + warn("lseek %s", _PATH_SCORE); return; } i = read(dbfd, (char *)&total, sizeof(total)); if (i < 0) { - perror("read"); + warn("lseek %s", _PATH_SCORE); return; } if (i == 0 || total.hand == 0) { @@ -149,14 +153,14 @@ printuser(pw, printfail) printf("* Losses for %-10s*\n", pw->pw_name); printf("*======================*\n"); printf("|Costs Total |\n"); - printf("| Hands %8d |\n", total.hand); - printf("| Inspections %8d |\n", total.inspection); - printf("| Games %8d |\n", total.game); - printf("| Runs %8d |\n", total.runs); - printf("| Information %8d |\n", total.information); - printf("| Think time %8d |\n", total.thinktime); - printf("|Total Costs %8d |\n", total.wins - total.worth); - printf("|Winnings %8d |\n", total.wins); - printf("|Net Worth %8d |\n", total.worth); + printf("| Hands %8ld |\n", total.hand); + printf("| Inspections %8ld |\n", total.inspection); + printf("| Games %8ld |\n", total.game); + printf("| Runs %8ld |\n", total.runs); + printf("| Information %8ld |\n", total.information); + printf("| Think time %8ld |\n", total.thinktime); + printf("|Total Costs %8ld |\n", total.wins - total.worth); + printf("|Winnings %8ld |\n", total.wins); + printf("|Net Worth %8ld |\n", total.worth); printf("*----------------------*\n\n"); } |