allocate only as many FILE's as needed
[unix-history] / usr / src / games / sail / lo_main.c
CommitLineData
b8bd6816 1#ifndef lint
ce837792 2static char *sccsid = "@(#)lo_main.c 2.1 83/10/31";
b8bd6816 3#endif
b3a57661 4
b8bd6816
CL
5/*
6 * Print out the top ten SAILors
7 *
8 * sail.log [-s/l]
9 *
10 * -s force a short listing (without real usernames)
11 * -l force a long listing (print out real usernames)
12 */
13#include <pwd.h>
14#include "externs.h"
15
16char *title[] = {
b3a57661
EW
17 "Admiral", "Commodore", "Captain", "Captain",
18 "Captain", "Captain", "Captain", "Commander",
19 "Commander", "Lieutenant"
b8bd6816
CL
20};
21
22main(argc, argv)
23int argc;
24char **argv;
25{
b3a57661
EW
26 FILE *fp;
27 char sbuf[32];
28 int n = 0, people;
29 int usrnam = 0;
30 struct passwd *getpwuid(), *pass;
31 struct logs log;
32 struct ship *ship;
b8bd6816 33
b3a57661
EW
34 if (argc > 1 && argc == 2)
35 if (strcmp(argv[1], "-s") == 0)
36 usrnam = 0;
37 else if (strcmp(argv[1], "-l") == 0)
38 usrnam = 1;
39 else {
40 fprintf(stderr, "usage: %s: [-s/l]\n", argv[0]);
41 exit(1);
42 }
43 if ((fp = fopen(LOGFILE, "r")) == 0) {
44 perror(LOGFILE);
45 exit(1);
46 }
47 switch (fread((char *)&people, sizeof people, 1, fp)) {
48 case 0:
49 printf("Nobody has sailed yet.\n");
50 exit(0);
51 case 1:
52 break;
53 default:
54 perror(LOGFILE);
55 exit(1);
56 }
57 while (fread((char *)&log, sizeof log, 1, fp) == 1
58 && log.l_name[0] != '\0') {
59 if (usrnam && (pass = getpwuid(log.l_uid)) != NULL)
60 (void) sprintf(sbuf, "%10.10s (%s)",
61 log.l_name, pass->pw_name);
62 else
63 (void) sprintf(sbuf, "%20.20s", log.l_name);
64 ship = &scene[log.l_gamenum].ship[log.l_shipnum];
65 printf("%-10s %21s of the %15s %3d points, %5.2f equiv\n",
66 title[n++], sbuf, ship->shipname, log.l_netpoints,
67 (float) log.l_netpoints / ship->specs->pts);
b8bd6816 68 }
b3a57661 69 printf("\n%d people have played.\n", people);
b8bd6816 70}