Annotation of 42BSD/games/sail/sail.log.c, revision 1.1.1.1

1.1       root        1: #ifndef lint
                      2: static char *sccsid = "@(#)sail.log.c  1.3 83/06/02";
                      3: #endif
                      4: /*
                      5:  * Print out the top ten SAILors
                      6:  *
                      7:  * sail.log [-s/l]
                      8:  *
                      9:  *  -s force a short listing (without real usernames)
                     10:  *  -l force a long listing (print out real usernames)
                     11:  */
                     12: #include <pwd.h>
                     13: #include "externs.h"
                     14: 
                     15: char *title[] = {
                     16:     "Admiral", "Commodore", "Captain", "Captain",
                     17:     "Captain", "Captain", "Captain", "Commander",
                     18:     "Commander", "Lieutenant"
                     19: };
                     20: 
                     21: main(argc, argv)
                     22: int argc;
                     23: char **argv;
                     24: {
                     25:     FILE *fp;
                     26:     char sbuf[32];
                     27:     int n = 0, people;
                     28:     int usrnam = SAILLOGDEF;
                     29:     struct passwd *getpwuid(), *pass;
                     30:     struct logs flog;
                     31: 
                     32:     if (argc > 1)
                     33:        if (argc == 2)
                     34:            if (!strcmp(argv[1], "-s"))
                     35:                usrnam = 0;
                     36:            else if (!strcmp(argv[1], "-l"))
                     37:                usrnam = 1;
                     38:        else {
                     39:            fprintf(stderr, "usage: %s: [-s/l]\n", argv[0]);
                     40:            exit(1);
                     41:        }
                     42:     if((fp = fopen(LOGFILE, "r")) == 0) {
                     43:        printf("%s: Error opening logfile - %s\n", argv[0], LOGFILE);
                     44:        exit(1);
                     45:     }
                     46:     if (fread(&people, sizeof(people), 1, fp) == 0) {
                     47:        printf("%s: Error reading logfile.\n", argv[0]);
                     48:        exit(1);
                     49:     }
                     50:     while ((fread(&flog, sizeof(flog), 1, fp) != 0) && (flog.fname[0] != '\0')) {
                     51:        if (usrnam && ((pass = getpwuid(flog.uid)) != NULL))
                     52:            sprintf(sbuf, "%10.10s (%s)", flog.fname, pass->pw_name);
                     53:        else
                     54:            sprintf(sbuf, "%20.20s", flog.fname);
                     55:        printf("%-10s %21s of the %15s %3d points, %5.2f equiv\n",
                     56:          title[n++], sbuf,
                     57:          scene[flog.fgamenum].ship[flog.fshipnum].shipname,
                     58:          flog.netpoints,
                     59:          (float) flog.netpoints /
                     60:          specs[scene[flog.fgamenum].ship[flog.fshipnum].shipnum].pts);
                     61:     }
                     62:     printf("\n%d people have played.\n", people);
                     63: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.