1 /* 2 * Copyright (c) 1983, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * %sccs.include.redist.c% 6 */ 7 8 #ifndef lint 9 static char sccsid[] = "@(#)lo_main.c 8.2 (Berkeley) 04/28/95"; 10 #endif /* not lint */ 11 12 /* 13 * Print out the top ten SAILors 14 * 15 * -l force a long listing (print out real usernames) 16 */ 17 #include <sys/types.h> 18 #include <pwd.h> 19 #include "extern.h" 20 #include "pathnames.h" 21 22 char *title[] = { 23 "Admiral", "Commodore", "Captain", "Captain", 24 "Captain", "Captain", "Captain", "Commander", 25 "Commander", "Lieutenant" 26 }; 27 28 lo_main() 29 { 30 FILE *fp; 31 char sbuf[32]; 32 int n = 0, people; 33 struct passwd *pass; 34 struct logs log; 35 struct ship *ship; 36 37 if ((fp = fopen(_PATH_LOGFILE, "r")) == 0) { 38 perror(_PATH_LOGFILE); 39 exit(1); 40 } 41 switch (fread((char *)&people, sizeof people, 1, fp)) { 42 case 0: 43 printf("Nobody has sailed yet.\n"); 44 exit(0); 45 case 1: 46 break; 47 default: 48 perror(_PATH_LOGFILE); 49 exit(1); 50 } 51 while (fread((char *)&log, sizeof log, 1, fp) == 1 && 52 log.l_name[0] != '\0') { 53 if (longfmt && (pass = getpwuid(log.l_uid)) != NULL) 54 (void) sprintf(sbuf, "%10.10s (%s)", 55 log.l_name, pass->pw_name); 56 else 57 (void) sprintf(sbuf, "%20.20s", log.l_name); 58 ship = &scene[log.l_gamenum].ship[log.l_shipnum]; 59 printf("%-10s %21s of the %15s %3d points, %5.2f equiv\n", 60 title[n++], sbuf, ship->shipname, log.l_netpoints, 61 (float) log.l_netpoints / ship->specs->pts); 62 } 63 printf("\n%d people have played.\n", people); 64 return 0; 65 } 66