Commit | Line | Data |
---|---|---|
b8bd6816 | 1 | #ifndef lint |
ba28d9ed | 2 | static char *sccsid = "@(#)lo_main.c 2.2 85/03/04"; |
b8bd6816 | 3 | #endif |
b3a57661 | 4 | |
b8bd6816 CL |
5 | /* |
6 | * Print out the top ten SAILors | |
7 | * | |
ba28d9ed | 8 | * -l force a long listing (print out real usernames) |
b8bd6816 CL |
9 | */ |
10 | #include <pwd.h> | |
11 | #include "externs.h" | |
12 | ||
13 | char *title[] = { | |
b3a57661 EW |
14 | "Admiral", "Commodore", "Captain", "Captain", |
15 | "Captain", "Captain", "Captain", "Commander", | |
16 | "Commander", "Lieutenant" | |
b8bd6816 CL |
17 | }; |
18 | ||
ba28d9ed | 19 | lo_main() |
b8bd6816 | 20 | { |
b3a57661 EW |
21 | FILE *fp; |
22 | char sbuf[32]; | |
23 | int n = 0, people; | |
b3a57661 EW |
24 | struct passwd *getpwuid(), *pass; |
25 | struct logs log; | |
26 | struct ship *ship; | |
b8bd6816 | 27 | |
b3a57661 EW |
28 | if ((fp = fopen(LOGFILE, "r")) == 0) { |
29 | perror(LOGFILE); | |
30 | exit(1); | |
31 | } | |
32 | switch (fread((char *)&people, sizeof people, 1, fp)) { | |
33 | case 0: | |
34 | printf("Nobody has sailed yet.\n"); | |
35 | exit(0); | |
36 | case 1: | |
37 | break; | |
38 | default: | |
39 | perror(LOGFILE); | |
40 | exit(1); | |
41 | } | |
ba28d9ed EW |
42 | while (fread((char *)&log, sizeof log, 1, fp) == 1 && |
43 | log.l_name[0] != '\0') { | |
44 | if (longfmt && (pass = getpwuid(log.l_uid)) != NULL) | |
b3a57661 EW |
45 | (void) sprintf(sbuf, "%10.10s (%s)", |
46 | log.l_name, pass->pw_name); | |
47 | else | |
48 | (void) sprintf(sbuf, "%20.20s", log.l_name); | |
49 | ship = &scene[log.l_gamenum].ship[log.l_shipnum]; | |
50 | printf("%-10s %21s of the %15s %3d points, %5.2f equiv\n", | |
51 | title[n++], sbuf, ship->shipname, log.l_netpoints, | |
52 | (float) log.l_netpoints / ship->specs->pts); | |
b8bd6816 | 53 | } |
b3a57661 | 54 | printf("\n%d people have played.\n", people); |
ba28d9ed | 55 | return 0; |
b8bd6816 | 56 | } |