xref: /csrg-svn/games/sail/lo_main.c (revision 18709)
1*18709Sedward /*
2*18709Sedward  * Copyright (c) 1983 Regents of the University of California,
3*18709Sedward  * All rights reserved.  Redistribution permitted subject to
4*18709Sedward  * the terms of the Berkeley Software License Agreement.
5*18709Sedward  */
6*18709Sedward 
711599Sleres #ifndef lint
8*18709Sedward static	char *sccsid = "@(#)lo_main.c	2.3 85/04/23";
911599Sleres #endif
1014019Sedward 
1111599Sleres /*
1211599Sleres  * Print out the top ten SAILors
1311599Sleres  *
1418250Sedward  * -l force a long listing (print out real usernames)
1511599Sleres  */
1611599Sleres #include <pwd.h>
1711599Sleres #include "externs.h"
1811599Sleres 
1911599Sleres char *title[] = {
2014019Sedward 	"Admiral", "Commodore", "Captain", "Captain",
2114019Sedward 	"Captain", "Captain", "Captain", "Commander",
2214019Sedward 	"Commander", "Lieutenant"
2311599Sleres };
2411599Sleres 
2518250Sedward lo_main()
2611599Sleres {
2714019Sedward 	FILE *fp;
2814019Sedward 	char sbuf[32];
2914019Sedward 	int n = 0, people;
3014019Sedward 	struct passwd *getpwuid(), *pass;
3114019Sedward 	struct logs log;
3214019Sedward 	struct ship *ship;
3311599Sleres 
3414019Sedward 	if ((fp = fopen(LOGFILE, "r")) == 0) {
3514019Sedward 		perror(LOGFILE);
3614019Sedward 		exit(1);
3711599Sleres 	}
3814019Sedward 	switch (fread((char *)&people, sizeof people, 1, fp)) {
3914019Sedward 	case 0:
4014019Sedward 		printf("Nobody has sailed yet.\n");
4114019Sedward 		exit(0);
4214019Sedward 	case 1:
4314019Sedward 		break;
4414019Sedward 	default:
4514019Sedward 		perror(LOGFILE);
4614019Sedward 		exit(1);
4714019Sedward 	}
4818250Sedward 	while (fread((char *)&log, sizeof log, 1, fp) == 1 &&
4918250Sedward 	       log.l_name[0] != '\0') {
5018250Sedward 		if (longfmt && (pass = getpwuid(log.l_uid)) != NULL)
5114019Sedward 			(void) sprintf(sbuf, "%10.10s (%s)",
5214019Sedward 				log.l_name, pass->pw_name);
5314019Sedward 		else
5414019Sedward 			(void) sprintf(sbuf, "%20.20s", log.l_name);
5514019Sedward 		ship = &scene[log.l_gamenum].ship[log.l_shipnum];
5614019Sedward 		printf("%-10s %21s of the %15s %3d points, %5.2f equiv\n",
5714019Sedward 			title[n++], sbuf, ship->shipname, log.l_netpoints,
5814019Sedward 			(float) log.l_netpoints / ship->specs->pts);
5914019Sedward 	}
6014019Sedward 	printf("\n%d people have played.\n", people);
6118250Sedward 	return 0;
6211599Sleres }
63