BSD 4_3_Reno release
[unix-history] / 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
1c15e888
C
6 * provided that: (1) source distributions retain this entire copyright
7 * notice and comment, and (2) distributions including binaries display
8 * the following acknowledgement: ``This product includes software
9 * developed by the University of California, Berkeley and its contributors''
10 * in the documentation or other materials provided with the distribution
11 * and in all advertising materials mentioning features or use of this
12 * software. Neither the name of the University nor the names of its
13 * contributors may be used to endorse or promote products derived
65c7d3b6
KB
14 * from this software without specific prior written permission.
15 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
1c15e888 17 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
b5f0675e
EW
18 */
19
b8bd6816 20#ifndef lint
1c15e888 21static char sccsid[] = "@(#)lo_main.c 5.6 (Berkeley) 6/1/90";
c0ca48ec 22#endif /* not lint */
b3a57661 23
b8bd6816
CL
24/*
25 * Print out the top ten SAILors
26 *
ba28d9ed 27 * -l force a long listing (print out real usernames)
b8bd6816 28 */
678dc652 29#include <sys/types.h>
b8bd6816
CL
30#include <pwd.h>
31#include "externs.h"
25d40e98 32#include "pathnames.h"
b8bd6816
CL
33
34char *title[] = {
b3a57661
EW
35 "Admiral", "Commodore", "Captain", "Captain",
36 "Captain", "Captain", "Captain", "Commander",
37 "Commander", "Lieutenant"
b8bd6816
CL
38};
39
ba28d9ed 40lo_main()
b8bd6816 41{
b3a57661
EW
42 FILE *fp;
43 char sbuf[32];
44 int n = 0, people;
b3a57661
EW
45 struct passwd *getpwuid(), *pass;
46 struct logs log;
47 struct ship *ship;
b8bd6816 48
25d40e98
KB
49 if ((fp = fopen(_PATH_LOGFILE, "r")) == 0) {
50 perror(_PATH_LOGFILE);
b3a57661
EW
51 exit(1);
52 }
53 switch (fread((char *)&people, sizeof people, 1, fp)) {
54 case 0:
55 printf("Nobody has sailed yet.\n");
56 exit(0);
57 case 1:
58 break;
59 default:
25d40e98 60 perror(_PATH_LOGFILE);
b3a57661
EW
61 exit(1);
62 }
ba28d9ed
EW
63 while (fread((char *)&log, sizeof log, 1, fp) == 1 &&
64 log.l_name[0] != '\0') {
65 if (longfmt && (pass = getpwuid(log.l_uid)) != NULL)
b3a57661
EW
66 (void) sprintf(sbuf, "%10.10s (%s)",
67 log.l_name, pass->pw_name);
68 else
69 (void) sprintf(sbuf, "%20.20s", log.l_name);
70 ship = &scene[log.l_gamenum].ship[log.l_shipnum];
71 printf("%-10s %21s of the %15s %3d points, %5.2f equiv\n",
72 title[n++], sbuf, ship->shipname, log.l_netpoints,
73 (float) log.l_netpoints / ship->specs->pts);
b8bd6816 74 }
b3a57661 75 printf("\n%d people have played.\n", people);
ba28d9ed 76 return 0;
b8bd6816 77}