xref: /csrg-svn/games/sail/lo_main.c (revision 14019)
111599Sleres #ifndef lint
2*14019Sedward static	char *sccsid = "@(#)lo_main.c	1.3 83/07/20";
311599Sleres #endif
4*14019Sedward 
511599Sleres /*
611599Sleres  * Print out the top ten SAILors
711599Sleres  *
811599Sleres  * sail.log [-s/l]
911599Sleres  *
1011599Sleres  *  -s force a short listing (without real usernames)
1111599Sleres  *  -l force a long listing (print out real usernames)
1211599Sleres  */
1311599Sleres #include <pwd.h>
1411599Sleres #include "externs.h"
1511599Sleres 
1611599Sleres char *title[] = {
17*14019Sedward 	"Admiral", "Commodore", "Captain", "Captain",
18*14019Sedward 	"Captain", "Captain", "Captain", "Commander",
19*14019Sedward 	"Commander", "Lieutenant"
2011599Sleres };
2111599Sleres 
2211599Sleres main(argc, argv)
2311599Sleres int argc;
2411599Sleres char **argv;
2511599Sleres {
26*14019Sedward 	FILE *fp;
27*14019Sedward 	char sbuf[32];
28*14019Sedward 	int n = 0, people;
29*14019Sedward 	int usrnam = 0;
30*14019Sedward 	struct passwd *getpwuid(), *pass;
31*14019Sedward 	struct logs log;
32*14019Sedward 	struct ship *ship;
3311599Sleres 
34*14019Sedward 	if (argc > 1 && argc == 2)
35*14019Sedward 		if (strcmp(argv[1], "-s") == 0)
36*14019Sedward 			usrnam = 0;
37*14019Sedward 		else if (strcmp(argv[1], "-l") == 0)
38*14019Sedward 			usrnam = 1;
39*14019Sedward 		else {
40*14019Sedward 			fprintf(stderr, "usage: %s: [-s/l]\n", argv[0]);
41*14019Sedward 			exit(1);
42*14019Sedward 		}
43*14019Sedward 	if ((fp = fopen(LOGFILE, "r")) == 0) {
44*14019Sedward 		perror(LOGFILE);
45*14019Sedward 		exit(1);
4611599Sleres 	}
47*14019Sedward 	switch (fread((char *)&people, sizeof people, 1, fp)) {
48*14019Sedward 	case 0:
49*14019Sedward 		printf("Nobody has sailed yet.\n");
50*14019Sedward 		exit(0);
51*14019Sedward 	case 1:
52*14019Sedward 		break;
53*14019Sedward 	default:
54*14019Sedward 		perror(LOGFILE);
55*14019Sedward 		exit(1);
56*14019Sedward 	}
57*14019Sedward 	while (fread((char *)&log, sizeof log, 1, fp) == 1
58*14019Sedward 	       && log.l_name[0] != '\0') {
59*14019Sedward 		if (usrnam && (pass = getpwuid(log.l_uid)) != NULL)
60*14019Sedward 			(void) sprintf(sbuf, "%10.10s (%s)",
61*14019Sedward 				log.l_name, pass->pw_name);
62*14019Sedward 		else
63*14019Sedward 			(void) sprintf(sbuf, "%20.20s", log.l_name);
64*14019Sedward 		ship = &scene[log.l_gamenum].ship[log.l_shipnum];
65*14019Sedward 		printf("%-10s %21s of the %15s %3d points, %5.2f equiv\n",
66*14019Sedward 			title[n++], sbuf, ship->shipname, log.l_netpoints,
67*14019Sedward 			(float) log.l_netpoints / ship->specs->pts);
68*14019Sedward 	}
69*14019Sedward 	printf("\n%d people have played.\n", people);
7011599Sleres }
71