installer - Several improvements
[dragonfly.git] / games / sail / lo_main.c
1 /*-
2  * Copyright (c) 1983, 1993
3  *      The Regents of the University of California.  All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  * 3. Neither the name of the University nor the names of its contributors
14  *    may be used to endorse or promote products derived from this software
15  *    without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  *
29  * @(#)lo_main.c        8.1 (Berkeley) 5/31/93
30  * $FreeBSD: src/games/sail/lo_main.c,v 1.2 1999/11/30 03:49:34 billf Exp $
31  */
32
33 /*
34  * Print out the top ten SAILors
35  *
36  * -l force a long listing (print out real usernames)
37  */
38 #include <sys/types.h>
39 #include <pwd.h>
40 #include "externs.h"
41 #include "pathnames.h"
42
43 const char *title[] = {
44         "Admiral", "Commodore", "Captain", "Captain",
45         "Captain", "Captain", "Captain", "Commander",
46         "Commander", "Lieutenant"
47 };
48
49 int
50 lo_main(void)
51 {
52         FILE *fp;
53         char sbuf[32];
54         int n = 0, ppl;
55         struct passwd *pass;
56         struct logs log;
57         struct ship *ship;
58
59         if ((fp = fopen(_PATH_LOGFILE, "r")) == NULL) {
60                 perror(_PATH_LOGFILE);
61                 exit(1);
62         }
63         switch (fread((char *)&ppl, sizeof ppl, 1, fp)) {
64         case 0:
65                 printf("Nobody has sailed yet.\n");
66                 exit(0);
67         case 1:
68                 break;
69         default:
70                 perror(_PATH_LOGFILE);
71                 exit(1);
72         }
73         while (fread((char *)&log, sizeof log, 1, fp) == 1 &&
74                log.l_name[0] != '\0') {
75                 if (longfmt && (pass = getpwuid(log.l_uid)) != NULL)
76                         sprintf(sbuf, "%10.10s (%s)",
77                                 log.l_name, pass->pw_name);
78                 else
79                         sprintf(sbuf, "%20.20s", log.l_name);
80                 ship = &scene[log.l_gamenum].ship[log.l_shipnum];
81                 printf("%-10s %21s of the %15s %3d points, %5.2f equiv\n",
82                         title[n++], sbuf, ship->shipname, log.l_netpoints,
83                         (float) log.l_netpoints / ship->specs->pts);
84         }
85         printf("\n%d people have played.\n", ppl);
86         return 0;
87 }