xref: /csrg-svn/games/sail/lo_main.c (revision 41324)
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
634795Sbostic  * provided that the above copyright notice and this paragraph are
734795Sbostic  * duplicated in all such forms and that any documentation,
834795Sbostic  * advertising materials, and other materials related to such
934795Sbostic  * distribution and use acknowledge that the software was developed
1034795Sbostic  * by the University of California, Berkeley.  The name of the
1134795Sbostic  * University may not be used to endorse or promote products derived
1234795Sbostic  * from this software without specific prior written permission.
1334795Sbostic  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
1434795Sbostic  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
1534795Sbostic  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
1618709Sedward  */
1718709Sedward 
1811599Sleres #ifndef lint
19*41324Sbostic static char sccsid[] = "@(#)lo_main.c	5.5 (Berkeley) 05/03/90";
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  */
2737016Sbostic #include <sys/types.h>
2811599Sleres #include <pwd.h>
2911599Sleres #include "externs.h"
30*41324Sbostic #include "pathnames.h"
3111599Sleres 
3211599Sleres char *title[] = {
3314019Sedward 	"Admiral", "Commodore", "Captain", "Captain",
3414019Sedward 	"Captain", "Captain", "Captain", "Commander",
3514019Sedward 	"Commander", "Lieutenant"
3611599Sleres };
3711599Sleres 
3818250Sedward lo_main()
3911599Sleres {
4014019Sedward 	FILE *fp;
4114019Sedward 	char sbuf[32];
4214019Sedward 	int n = 0, people;
4314019Sedward 	struct passwd *getpwuid(), *pass;
4414019Sedward 	struct logs log;
4514019Sedward 	struct ship *ship;
4611599Sleres 
47*41324Sbostic 	if ((fp = fopen(_PATH_LOGFILE, "r")) == 0) {
48*41324Sbostic 		perror(_PATH_LOGFILE);
4914019Sedward 		exit(1);
5011599Sleres 	}
5114019Sedward 	switch (fread((char *)&people, sizeof people, 1, fp)) {
5214019Sedward 	case 0:
5314019Sedward 		printf("Nobody has sailed yet.\n");
5414019Sedward 		exit(0);
5514019Sedward 	case 1:
5614019Sedward 		break;
5714019Sedward 	default:
58*41324Sbostic 		perror(_PATH_LOGFILE);
5914019Sedward 		exit(1);
6014019Sedward 	}
6118250Sedward 	while (fread((char *)&log, sizeof log, 1, fp) == 1 &&
6218250Sedward 	       log.l_name[0] != '\0') {
6318250Sedward 		if (longfmt && (pass = getpwuid(log.l_uid)) != NULL)
6414019Sedward 			(void) sprintf(sbuf, "%10.10s (%s)",
6514019Sedward 				log.l_name, pass->pw_name);
6614019Sedward 		else
6714019Sedward 			(void) sprintf(sbuf, "%20.20s", log.l_name);
6814019Sedward 		ship = &scene[log.l_gamenum].ship[log.l_shipnum];
6914019Sedward 		printf("%-10s %21s of the %15s %3d points, %5.2f equiv\n",
7014019Sedward 			title[n++], sbuf, ship->shipname, log.l_netpoints,
7114019Sedward 			(float) log.l_netpoints / ship->specs->pts);
7214019Sedward 	}
7314019Sedward 	printf("\n%d people have played.\n", people);
7418250Sedward 	return 0;
7511599Sleres }
76