118709Sedward /*
260846Sbostic * Copyright (c) 1983, 1993
360846Sbostic * The Regents of the University of California. All rights reserved.
433695Sbostic *
542604Sbostic * %sccs.include.redist.c%
618709Sedward */
718709Sedward
811599Sleres #ifndef lint
9*69068Sbostic static char sccsid[] = "@(#)lo_main.c 8.2 (Berkeley) 04/28/95";
1033695Sbostic #endif /* not lint */
1114019Sedward
1211599Sleres /*
1311599Sleres * Print out the top ten SAILors
1411599Sleres *
1518250Sedward * -l force a long listing (print out real usernames)
1611599Sleres */
1737016Sbostic #include <sys/types.h>
1811599Sleres #include <pwd.h>
19*69068Sbostic #include "extern.h"
2041324Sbostic #include "pathnames.h"
2111599Sleres
2211599Sleres char *title[] = {
2314019Sedward "Admiral", "Commodore", "Captain", "Captain",
2414019Sedward "Captain", "Captain", "Captain", "Commander",
2514019Sedward "Commander", "Lieutenant"
2611599Sleres };
2711599Sleres
lo_main()2818250Sedward lo_main()
2911599Sleres {
3014019Sedward FILE *fp;
3114019Sedward char sbuf[32];
3214019Sedward int n = 0, people;
3346759Sbostic struct passwd *pass;
3414019Sedward struct logs log;
3514019Sedward struct ship *ship;
3611599Sleres
3741324Sbostic if ((fp = fopen(_PATH_LOGFILE, "r")) == 0) {
3841324Sbostic perror(_PATH_LOGFILE);
3914019Sedward exit(1);
4011599Sleres }
4114019Sedward switch (fread((char *)&people, sizeof people, 1, fp)) {
4214019Sedward case 0:
4314019Sedward printf("Nobody has sailed yet.\n");
4414019Sedward exit(0);
4514019Sedward case 1:
4614019Sedward break;
4714019Sedward default:
4841324Sbostic perror(_PATH_LOGFILE);
4914019Sedward exit(1);
5014019Sedward }
5118250Sedward while (fread((char *)&log, sizeof log, 1, fp) == 1 &&
5218250Sedward log.l_name[0] != '\0') {
5318250Sedward if (longfmt && (pass = getpwuid(log.l_uid)) != NULL)
5414019Sedward (void) sprintf(sbuf, "%10.10s (%s)",
5514019Sedward log.l_name, pass->pw_name);
5614019Sedward else
5714019Sedward (void) sprintf(sbuf, "%20.20s", log.l_name);
5814019Sedward ship = &scene[log.l_gamenum].ship[log.l_shipnum];
5914019Sedward printf("%-10s %21s of the %15s %3d points, %5.2f equiv\n",
6014019Sedward title[n++], sbuf, ship->shipname, log.l_netpoints,
6114019Sedward (float) log.l_netpoints / ship->specs->pts);
6214019Sedward }
6314019Sedward printf("\n%d people have played.\n", people);
6418250Sedward return 0;
6511599Sleres }
66