BSD 4_3_Reno development
[unix-history] / .ref-BSD-4_3_Tahoe / usr / src / games / sail / lo_main.c
CommitLineData
b5f0675e 1/*
1e008c14 2 * Copyright (c) 1983 Regents of the University of California.
c0ca48ec
KB
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms are permitted
65c7d3b6
KB
6 * provided that the above copyright notice and this paragraph are
7 * duplicated in all such forms and that any documentation,
8 * advertising materials, and other materials related to such
9 * distribution and use acknowledge that the software was developed
10 * by the University of California, Berkeley. The name of the
11 * University may not be used to endorse or promote products derived
12 * from this software without specific prior written permission.
13 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
14 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
15 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
b5f0675e
EW
16 */
17
b8bd6816 18#ifndef lint
ca67e7b4 19static char sccsid[] = "@(#)lo_main.c 5.3 (Berkeley) 6/18/88";
c0ca48ec 20#endif /* not lint */
b3a57661 21
b8bd6816
CL
22/*
23 * Print out the top ten SAILors
24 *
ba28d9ed 25 * -l force a long listing (print out real usernames)
b8bd6816
CL
26 */
27#include <pwd.h>
28#include "externs.h"
29
30char *title[] = {
b3a57661
EW
31 "Admiral", "Commodore", "Captain", "Captain",
32 "Captain", "Captain", "Captain", "Commander",
33 "Commander", "Lieutenant"
b8bd6816
CL
34};
35
ba28d9ed 36lo_main()
b8bd6816 37{
b3a57661
EW
38 FILE *fp;
39 char sbuf[32];
40 int n = 0, people;
b3a57661
EW
41 struct passwd *getpwuid(), *pass;
42 struct logs log;
43 struct ship *ship;
b8bd6816 44
b3a57661
EW
45 if ((fp = fopen(LOGFILE, "r")) == 0) {
46 perror(LOGFILE);
47 exit(1);
48 }
49 switch (fread((char *)&people, sizeof people, 1, fp)) {
50 case 0:
51 printf("Nobody has sailed yet.\n");
52 exit(0);
53 case 1:
54 break;
55 default:
56 perror(LOGFILE);
57 exit(1);
58 }
ba28d9ed
EW
59 while (fread((char *)&log, sizeof log, 1, fp) == 1 &&
60 log.l_name[0] != '\0') {
61 if (longfmt && (pass = getpwuid(log.l_uid)) != NULL)
b3a57661
EW
62 (void) sprintf(sbuf, "%10.10s (%s)",
63 log.l_name, pass->pw_name);
64 else
65 (void) sprintf(sbuf, "%20.20s", log.l_name);
66 ship = &scene[log.l_gamenum].ship[log.l_shipnum];
67 printf("%-10s %21s of the %15s %3d points, %5.2f equiv\n",
68 title[n++], sbuf, ship->shipname, log.l_netpoints,
69 (float) log.l_netpoints / ship->specs->pts);
b8bd6816 70 }
b3a57661 71 printf("\n%d people have played.\n", people);
ba28d9ed 72 return 0;
b8bd6816 73}