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