xref: /csrg-svn/games/sail/lo_main.c (revision 34795)
118709Sedward /*
221236Sdist  * Copyright (c) 1983 Regents of the University of California.
333695Sbostic  * All rights reserved.
433695Sbostic  *
533695Sbostic  * Redistribution and use in source and binary forms are permitted
6*34795Sbostic  * provided that the above copyright notice and this paragraph are
7*34795Sbostic  * duplicated in all such forms and that any documentation,
8*34795Sbostic  * advertising materials, and other materials related to such
9*34795Sbostic  * distribution and use acknowledge that the software was developed
10*34795Sbostic  * by the University of California, Berkeley.  The name of the
11*34795Sbostic  * University may not be used to endorse or promote products derived
12*34795Sbostic  * from this software without specific prior written permission.
13*34795Sbostic  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
14*34795Sbostic  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
15*34795Sbostic  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
1618709Sedward  */
1718709Sedward 
1811599Sleres #ifndef lint
19*34795Sbostic static char sccsid[] = "@(#)lo_main.c	5.3 (Berkeley) 06/18/88";
2033695Sbostic #endif /* not lint */
2114019Sedward 
2211599Sleres /*
2311599Sleres  * Print out the top ten SAILors
2411599Sleres  *
2518250Sedward  * -l force a long listing (print out real usernames)
2611599Sleres  */
2711599Sleres #include <pwd.h>
2811599Sleres #include "externs.h"
2911599Sleres 
3011599Sleres char *title[] = {
3114019Sedward 	"Admiral", "Commodore", "Captain", "Captain",
3214019Sedward 	"Captain", "Captain", "Captain", "Commander",
3314019Sedward 	"Commander", "Lieutenant"
3411599Sleres };
3511599Sleres 
3618250Sedward lo_main()
3711599Sleres {
3814019Sedward 	FILE *fp;
3914019Sedward 	char sbuf[32];
4014019Sedward 	int n = 0, people;
4114019Sedward 	struct passwd *getpwuid(), *pass;
4214019Sedward 	struct logs log;
4314019Sedward 	struct ship *ship;
4411599Sleres 
4514019Sedward 	if ((fp = fopen(LOGFILE, "r")) == 0) {
4614019Sedward 		perror(LOGFILE);
4714019Sedward 		exit(1);
4811599Sleres 	}
4914019Sedward 	switch (fread((char *)&people, sizeof people, 1, fp)) {
5014019Sedward 	case 0:
5114019Sedward 		printf("Nobody has sailed yet.\n");
5214019Sedward 		exit(0);
5314019Sedward 	case 1:
5414019Sedward 		break;
5514019Sedward 	default:
5614019Sedward 		perror(LOGFILE);
5714019Sedward 		exit(1);
5814019Sedward 	}
5918250Sedward 	while (fread((char *)&log, sizeof log, 1, fp) == 1 &&
6018250Sedward 	       log.l_name[0] != '\0') {
6118250Sedward 		if (longfmt && (pass = getpwuid(log.l_uid)) != NULL)
6214019Sedward 			(void) sprintf(sbuf, "%10.10s (%s)",
6314019Sedward 				log.l_name, pass->pw_name);
6414019Sedward 		else
6514019Sedward 			(void) sprintf(sbuf, "%20.20s", log.l_name);
6614019Sedward 		ship = &scene[log.l_gamenum].ship[log.l_shipnum];
6714019Sedward 		printf("%-10s %21s of the %15s %3d points, %5.2f equiv\n",
6814019Sedward 			title[n++], sbuf, ship->shipname, log.l_netpoints,
6914019Sedward 			(float) log.l_netpoints / ship->specs->pts);
7014019Sedward 	}
7114019Sedward 	printf("\n%d people have played.\n", people);
7218250Sedward 	return 0;
7311599Sleres }
74