Annotation of 43BSDReno/games/snake/snscore/snscore.c, revision 1.1.1.1

1.1       root        1: /*
                      2:  * Copyright (c) 1980 Regents of the University of California.
                      3:  * All rights reserved.
                      4:  *
                      5:  * Redistribution and use in source and binary forms are permitted
                      6:  * provided that: (1) source distributions retain this entire copyright
                      7:  * notice and comment, and (2) distributions including binaries display
                      8:  * the following acknowledgement:  ``This product includes software
                      9:  * developed by the University of California, Berkeley and its contributors''
                     10:  * in the documentation or other materials provided with the distribution
                     11:  * and in all advertising materials mentioning features or use of this
                     12:  * software. Neither the name of the University nor the names of its
                     13:  * contributors may be used to endorse or promote products derived
                     14:  * from this software without specific prior written permission.
                     15:  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
                     16:  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
                     17:  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
                     18:  */
                     19: 
                     20: #ifndef lint
                     21: char copyright[] =
                     22: "@(#) Copyright (c) 1980 Regents of the University of California.\n\
                     23:  All rights reserved.\n";
                     24: #endif /* not lint */
                     25: 
                     26: #ifndef lint
                     27: static char sccsid[] = "@(#)snscore.c  5.5 (Berkeley) 6/1/90";
                     28: #endif /* not lint */
                     29: 
                     30: #include <stdio.h>
                     31: #include <sys/types.h>
                     32: #include <pwd.h>
                     33: #include "pathnames.h"
                     34: 
                     35: char *recfile = _PATH_RAWSCORES;
                     36: #define MAXPLAYERS 256
                     37: 
                     38: struct passwd  *getpwuid();
                     39: char   *malloc();
                     40: 
                     41: struct player  {
                     42:        short   uids;
                     43:        short   scores;
                     44:        char    *name;
                     45: } players[MAXPLAYERS], temp;
                     46: 
                     47: main()
                     48: {
                     49:        char    buf[80], cp;
                     50:        short   uid, score;
                     51:        FILE    *fd;
                     52:        int     noplayers;
                     53:        int     i, j, notsorted;
                     54:        short   whoallbest, allbest;
                     55:        char    *q;
                     56:        struct  passwd  *p;
                     57: 
                     58:        fd = fopen(recfile, "r");
                     59:        if (fd == NULL) {
                     60:                perror(recfile);
                     61:                exit(1);
                     62:        }
                     63:        printf("Snake players scores to date\n");
                     64:        fread(&whoallbest, sizeof(short), 1, fd);
                     65:        fread(&allbest, sizeof(short), 1, fd);
                     66:        for (uid=2;;uid++) {
                     67:                if(fread(&score, sizeof(short), 1, fd) == 0)
                     68:                        break;
                     69:                if (score > 0) {
                     70:                        if (noplayers > MAXPLAYERS) {
                     71:                                printf("too many players\n");
                     72:                                exit(2);
                     73:                        }
                     74:                        players[noplayers].uids = uid;
                     75:                        players[noplayers].scores = score;
                     76:                        p = getpwuid(uid);
                     77:                        if (p == NULL)
                     78:                                continue;
                     79:                        q = p -> pw_name;
                     80:                        players[noplayers].name = malloc(strlen(q)+1);
                     81:                        strcpy(players[noplayers].name, q);
                     82:                        noplayers++;
                     83:                }
                     84:        }
                     85: 
                     86:        /* bubble sort scores */
                     87:        for (notsorted=1; notsorted; ) {
                     88:                notsorted = 0;
                     89:                for (i=0; i<noplayers-1; i++)
                     90:                        if (players[i].scores < players[i+1].scores) {
                     91:                                temp = players[i];
                     92:                                players[i] = players[i+1];
                     93:                                players[i+1] = temp;
                     94:                                notsorted++;
                     95:                        }
                     96:        }
                     97: 
                     98:        j = 1;
                     99:        for (i=0; i<noplayers; i++) {
                    100:                printf("%d:\t$%d\t%s\n", j, players[i].scores, players[i].name);
                    101:                if (players[i].scores > players[i+1].scores)
                    102:                        j = i+2;
                    103:        }
                    104:        exit(0);
                    105: }

unix.superglobalmegacorp.com

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