]> git.cameronkatri.com Git - bsdgames-darwin.git/blobdiff - canfield/cfscores/cfscores.c
This patch adds to backgammon(6) a couple of noreturn attributes
[bsdgames-darwin.git] / canfield / cfscores / cfscores.c
index 4a3a0e8f7828eee5697aac0beaa3b7f86b7667ff..e5830fef6b2b3aa428381fc9870a0d5de6d49b01 100644 (file)
@@ -1,4 +1,4 @@
-/*     $NetBSD: cfscores.c,v 1.3 1995/03/21 15:08:37 cgd Exp $ */
+/*     $NetBSD: cfscores.c,v 1.6 1998/08/29 22:47:57 hubertf Exp $     */
 
 /*
  * Copyright (c) 1983, 1993
  * SUCH DAMAGE.
  */
 
+#include <sys/cdefs.h>
 #ifndef lint
-static char copyright[] =
-"@(#) Copyright (c) 1983, 1993\n\
-       The Regents of the University of California.  All rights reserved.\n";
+__COPYRIGHT("@(#) Copyright (c) 1983, 1993\n\
+       The Regents of the University of California.  All rights reserved.\n");
 #endif /* not lint */
 
 #ifndef lint
 #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 $";
+__RCSID("$NetBSD: cfscores.c,v 1.6 1998/08/29 22:47:57 hubertf Exp $");
 #endif
 #endif /* not lint */
 
 #include <sys/types.h>
+#include <err.h>
+#include <fcntl.h>
 #include <pwd.h>
+#include <stdio.h>
+#include <unistd.h>
 #include "pathnames.h"
 
 struct betinfo {
@@ -64,22 +68,24 @@ struct betinfo {
 
 int dbfd;
 
+int    main __P((int, char *[]));
+void   printuser __P((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");
                exit(1);
        }
-       dbfd = open(_PATH_SCORE, 0);
-       if (dbfd < 0) {
-               perror(_PATH_SCORE);
-               exit(2);
-       }
+       dbfd = open(_PATH_SCORE, O_RDONLY);
+       if (dbfd < 0)
+               err(2, "open %s", _PATH_SCORE);
        setpwent();
        if (argc == 1) {
                uid = getuid();
@@ -108,8 +114,9 @@ main(argc, argv)
 /*
  * print out info for specified password entry
  */
+void
 printuser(pw, printfail)
-       register struct passwd *pw;
+       struct passwd *pw;
        int printfail;
 {
        struct betinfo total;
@@ -119,16 +126,12 @@ printuser(pw, printfail)
                printf("Bad uid %d\n", pw->pw_uid);
                return;
        }
-       i = lseek(dbfd, pw->pw_uid * sizeof(struct betinfo), 0);
-       if (i < 0) {
-               perror("lseek");
-               return;
-       }
+       i = lseek(dbfd, pw->pw_uid * sizeof(struct betinfo), SEEK_SET);
+       if (i < 0)
+               warn("lseek %s", _PATH_SCORE);
        i = read(dbfd, (char *)&total, sizeof(total));
-       if (i < 0) {
-               perror("read");
-               return;
-       }
+       if (i < 0)
+               warn("read %s", _PATH_SCORE);
        if (i == 0 || total.hand == 0) {
                if (printfail)
                        printf("%s has never played canfield.\n", pw->pw_name);
@@ -141,14 +144,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");
 }