118709Sedward /* 221236Sdist * Copyright (c) 1983 Regents of the University of California. 333695Sbostic * All rights reserved. 433695Sbostic * 533695Sbostic * Redistribution and use in source and binary forms are permitted 634795Sbostic * provided that the above copyright notice and this paragraph are 734795Sbostic * duplicated in all such forms and that any documentation, 834795Sbostic * advertising materials, and other materials related to such 934795Sbostic * distribution and use acknowledge that the software was developed 1034795Sbostic * by the University of California, Berkeley. The name of the 1134795Sbostic * University may not be used to endorse or promote products derived 1234795Sbostic * from this software without specific prior written permission. 1334795Sbostic * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 1434795Sbostic * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 1534795Sbostic * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. 1618709Sedward */ 1718709Sedward 1811599Sleres #ifndef lint 19*37016Sbostic static char sccsid[] = "@(#)lo_main.c 5.4 (Berkeley) 03/05/89"; 2033695Sbostic #endif /* not lint */ 2114019Sedward 2211599Sleres /* 2311599Sleres * Print out the top ten SAILors 2411599Sleres * 2518250Sedward * -l force a long listing (print out real usernames) 2611599Sleres */ 27*37016Sbostic #include <sys/types.h> 2811599Sleres #include <pwd.h> 2911599Sleres #include "externs.h" 3011599Sleres 3111599Sleres char *title[] = { 3214019Sedward "Admiral", "Commodore", "Captain", "Captain", 3314019Sedward "Captain", "Captain", "Captain", "Commander", 3414019Sedward "Commander", "Lieutenant" 3511599Sleres }; 3611599Sleres 3718250Sedward lo_main() 3811599Sleres { 3914019Sedward FILE *fp; 4014019Sedward char sbuf[32]; 4114019Sedward int n = 0, people; 4214019Sedward struct passwd *getpwuid(), *pass; 4314019Sedward struct logs log; 4414019Sedward struct ship *ship; 4511599Sleres 4614019Sedward if ((fp = fopen(LOGFILE, "r")) == 0) { 4714019Sedward perror(LOGFILE); 4814019Sedward exit(1); 4911599Sleres } 5014019Sedward switch (fread((char *)&people, sizeof people, 1, fp)) { 5114019Sedward case 0: 5214019Sedward printf("Nobody has sailed yet.\n"); 5314019Sedward exit(0); 5414019Sedward case 1: 5514019Sedward break; 5614019Sedward default: 5714019Sedward perror(LOGFILE); 5814019Sedward exit(1); 5914019Sedward } 6018250Sedward while (fread((char *)&log, sizeof log, 1, fp) == 1 && 6118250Sedward log.l_name[0] != '\0') { 6218250Sedward if (longfmt && (pass = getpwuid(log.l_uid)) != NULL) 6314019Sedward (void) sprintf(sbuf, "%10.10s (%s)", 6414019Sedward log.l_name, pass->pw_name); 6514019Sedward else 6614019Sedward (void) sprintf(sbuf, "%20.20s", log.l_name); 6714019Sedward ship = &scene[log.l_gamenum].ship[log.l_shipnum]; 6814019Sedward printf("%-10s %21s of the %15s %3d points, %5.2f equiv\n", 6914019Sedward title[n++], sbuf, ship->shipname, log.l_netpoints, 7014019Sedward (float) log.l_netpoints / ship->specs->pts); 7114019Sedward } 7214019Sedward printf("\n%d people have played.\n", people); 7318250Sedward return 0; 7411599Sleres } 75