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