|
|
1.1 root 1: /*
2: * Copyright (c) 1983 Regents of the University of California.
3: * All rights reserved.
4: *
5: * Redistribution and use in source and binary forms are permitted
6: * provided that the above copyright notice and this paragraph are
7: * duplicated in all such forms and that any documentation,
8: * advertising materials, and other materials related to such
9: * distribution and use acknowledge that the software was developed
10: * by the University of California, Berkeley. The name of the
11: * University may not be used to endorse or promote products derived
12: * from this software without specific prior written permission.
13: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
14: * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
15: * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
16: */
17:
18: #ifndef lint
19: char copyright[] =
20: "@(#) Copyright (c) 1983 Regents of the University of California.\n\
21: All rights reserved.\n";
22: #endif /* not lint */
23:
24: #ifndef lint
25: static char sccsid[] = "@(#)cfscores.c 5.3 (Berkeley) 6/18/88";
26: #endif /* not lint */
27:
28: #include <pwd.h>
29:
30: struct betinfo {
31: long hand; /* cost of dealing hand */
32: long inspection; /* cost of inspecting hand */
33: long game; /* cost of buying game */
34: long runs; /* cost of running through hands */
35: long information; /* cost of information */
36: long thinktime; /* cost of thinking time */
37: long wins; /* total winnings */
38: long worth; /* net worth after costs */
39: };
40:
41: char *scorefile = "/usr/games/lib/cfscores";
42: int dbfd;
43:
44: main(argc, argv)
45: int argc;
46: char *argv[];
47: {
48: register struct passwd *pw;
49: int uid;
50:
51: if (argc > 2) {
52: printf("Usage: cfscores [user]\n");
53: exit(1);
54: }
55: dbfd = open(scorefile, 0);
56: if (dbfd < 0) {
57: perror(scorefile);
58: exit(2);
59: }
60: setpwent();
61: if (argc == 1) {
62: uid = getuid();
63: pw = getpwuid(uid);
64: if (pw == 0) {
65: printf("You are not listed in the password file?!?\n");
66: exit(2);
67: }
68: printuser(pw, 1);
69: exit(0);
70: }
71: if (strcmp(argv[1], "-a") == 0) {
72: while ((pw = getpwent()) != 0)
73: printuser(pw, 0);
74: exit(0);
75: }
76: pw = getpwnam(argv[1]);
77: if (pw == 0) {
78: printf("User %s unknown\n", argv[1]);
79: exit(3);
80: }
81: printuser(pw, 1);
82: exit(0);
83: }
84:
85: /*
86: * print out info for specified password entry
87: */
88: printuser(pw, printfail)
89: register struct passwd *pw;
90: int printfail;
91: {
92: struct betinfo total;
93: int i;
94:
95: if (pw->pw_uid < 0) {
96: printf("Bad uid %d\n", pw->pw_uid);
97: return;
98: }
99: i = lseek(dbfd, pw->pw_uid * sizeof(struct betinfo), 0);
100: if (i < 0) {
101: perror("lseek");
102: return;
103: }
104: i = read(dbfd, (char *)&total, sizeof(total));
105: if (i < 0) {
106: perror("read");
107: return;
108: }
109: if (i == 0 || total.hand == 0) {
110: if (printfail)
111: printf("%s has never played canfield.\n", pw->pw_name);
112: return;
113: }
114: printf("*----------------------*\n");
115: if (total.worth >= 0)
116: printf("* Winnings for %-8s*\n", pw->pw_name);
117: else
118: printf("* Losses for %-10s*\n", pw->pw_name);
119: printf("*======================*\n");
120: printf("|Costs Total |\n");
121: printf("| Hands %8d |\n", total.hand);
122: printf("| Inspections %8d |\n", total.inspection);
123: printf("| Games %8d |\n", total.game);
124: printf("| Runs %8d |\n", total.runs);
125: printf("| Information %8d |\n", total.information);
126: printf("| Think time %8d |\n", total.thinktime);
127: printf("|Total Costs %8d |\n", total.wins - total.worth);
128: printf("|Winnings %8d |\n", total.wins);
129: printf("|Net Worth %8d |\n", total.worth);
130: printf("*----------------------*\n\n");
131: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.