|
|
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: static char sccsid[] = "@(#)lo_main.c 5.3 (Berkeley) 6/18/88"; ! 20: #endif /* not lint */ ! 21: ! 22: /* ! 23: * Print out the top ten SAILors ! 24: * ! 25: * -l force a long listing (print out real usernames) ! 26: */ ! 27: #include <pwd.h> ! 28: #include "externs.h" ! 29: ! 30: char *title[] = { ! 31: "Admiral", "Commodore", "Captain", "Captain", ! 32: "Captain", "Captain", "Captain", "Commander", ! 33: "Commander", "Lieutenant" ! 34: }; ! 35: ! 36: lo_main() ! 37: { ! 38: FILE *fp; ! 39: char sbuf[32]; ! 40: int n = 0, people; ! 41: struct passwd *getpwuid(), *pass; ! 42: struct logs log; ! 43: struct ship *ship; ! 44: ! 45: if ((fp = fopen(LOGFILE, "r")) == 0) { ! 46: perror(LOGFILE); ! 47: exit(1); ! 48: } ! 49: switch (fread((char *)&people, sizeof people, 1, fp)) { ! 50: case 0: ! 51: printf("Nobody has sailed yet.\n"); ! 52: exit(0); ! 53: case 1: ! 54: break; ! 55: default: ! 56: perror(LOGFILE); ! 57: exit(1); ! 58: } ! 59: while (fread((char *)&log, sizeof log, 1, fp) == 1 && ! 60: log.l_name[0] != '\0') { ! 61: if (longfmt && (pass = getpwuid(log.l_uid)) != NULL) ! 62: (void) sprintf(sbuf, "%10.10s (%s)", ! 63: log.l_name, pass->pw_name); ! 64: else ! 65: (void) sprintf(sbuf, "%20.20s", log.l_name); ! 66: ship = &scene[log.l_gamenum].ship[log.l_shipnum]; ! 67: printf("%-10s %21s of the %15s %3d points, %5.2f equiv\n", ! 68: title[n++], sbuf, ship->shipname, log.l_netpoints, ! 69: (float) log.l_netpoints / ship->specs->pts); ! 70: } ! 71: printf("\n%d people have played.\n", people); ! 72: return 0; ! 73: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.