Annotation of researchv10no/games/atc/sread.c, revision 1.1

1.1     ! root        1: /* read stats file generated by atc */
        !             2: 
        !             3: #define STATSFILE "/usr/games/lib/atc/stats"
        !             4: 
        !             5: #include <stdio.h>
        !             6: 
        !             7: #define AMAX 20 /* no more than 20 airspaces yet */
        !             8: #define UMAX 100 /* number of likely users */
        !             9: 
        !            10: struct
        !            11: {       char month[5];  /* Apr 15 17:04 */
        !            12:        char date[5];
        !            13:        int dhour;
        !            14:        int dmin;
        !            15:        char user[9];
        !            16:        int crashes;
        !            17:        int system;
        !            18:        int towtruck;
        !            19:        int boundary;
        !            20:        int goaround;
        !            21:        int remain;
        !            22:        int seed;
        !            23:        int rtime;
        !            24:        int gas;
        !            25:        int cmds;
        !            26:        char airspace[50];
        !            27: } r;
        !            28: 
        !            29: struct          /* record with each airspace */
        !            30: {       char recordholder[9];
        !            31:        int time;
        !            32:        char smo[5];
        !            33:        char sdate[5];
        !            34:        int shour;
        !            35:        int smin;
        !            36:        char airspname[50];
        !            37: } s[AMAX];
        !            38: 
        !            39: int nairspace = 0;
        !            40: 
        !            41: int users = 0;
        !            42: 
        !            43: struct  /* user */
        !            44: {       char uname[9];
        !            45:        int minutes;    /* total time played */
        !            46:        int start;
        !            47:        int ucrashes;
        !            48:        int usystem;
        !            49:        int utowtruck;
        !            50:        int uboundary;
        !            51:        int ugoaround;
        !            52:        int through;
        !            53:        int urtime;
        !            54:        int ugas;
        !            55:        int ucmds;
        !            56: } u[UMAX];
        !            57: 
        !            58: #define BUFSIZE 80
        !            59: #define SKIP while (*c != ' ') c++;
        !            60: 
        !            61: main(argc,argv)
        !            62: int argc;
        !            63: char **argv;
        !            64: {       FILE *sfile;
        !            65:        char buf[BUFSIZE],*c;
        !            66:        int dump,i,j,done,ok;
        !            67: 
        !            68: 
        !            69:        if ((sfile = fopen(STATSFILE,"r")) == NULL)
        !            70:        {       fprintf(stderr,"No stats file.\n");
        !            71:                exit(1);
        !            72:        }
        !            73:        if (argc == 2)  /* don't want the beginning */
        !            74:                if (-1 == fseek(sfile,-atoi(argv[1]),2))/* seek forward from end */
        !            75:                        printf("Couldn't seek.\n");
        !            76:        while (fgets(buf,BUFSIZE,sfile) != NULL)
        !            77:        {       if ((j = sscanf(buf,"%s%s%d:%d:%s %d%d%d%d%d%d%d%d.%d%d %s\n",
        !            78:                       r.month,r.date,&r.dhour,&r.dmin,
        !            79:                       r.user,&r.crashes,&r.system,&r.towtruck,
        !            80:                       &r.boundary,&r.goaround,&r.gas,&r.cmds,
        !            81:                       &r.remain,
        !            82:                       &r.seed,&r.rtime,
        !            83:                       r.airspace)) == 0) continue;
        !            84:                for (c = r.user; *c; c++) if (*c == ':') *c = 0;
        !            85:                if (strcmp("CR",r.month) == 0) continue;
        !            86:                for (i=0; i<users; i++)
        !            87:                        if (strcmp(u[i].uname,r.user) == 0) break;
        !            88:                if (i == users) strcpy(u[users++].uname,r.user);
        !            89:                if (j < 13)
        !            90:                {       u[i].start = 60*r.dhour+r.dmin;
        !            91:                        continue;
        !            92:                }
        !            93: 
        !            94:                if (u[i].start == 0) continue;
        !            95:                done = 60*r.dhour+r.dmin;
        !            96:                u[i].minutes += done - u[i].start;
        !            97:                u[i].ucrashes += r.crashes;
        !            98:                u[i].usystem += r.system;
        !            99:                u[i].utowtruck += r.towtruck;
        !           100:                u[i].uboundary += r.boundary;
        !           101:                u[i].ugoaround += r.goaround;
        !           102:                u[i].urtime += r.rtime;
        !           103:                u[i].ugas += r.gas;
        !           104:                u[i].ucmds += r.cmds;
        !           105:                ok = 26-r.remain-r.crashes-r.towtruck-r.boundary-2*r.system;
        !           106:                if (ok > 0) u[i].through += ok;
        !           107:                if (done - u[i].start < 0) u[i].minutes += 24*60;
        !           108: 
        !           109:                if (r.remain+r.crashes+r.system+r.towtruck+r.boundary
        !           110:                    != 0) continue; /* need only perfect games */
        !           111: 
        !           112:                for (i=0; i<nairspace; i++)
        !           113:                        if (strcmp(r.airspace,s[i].airspname) == 0) break;
        !           114: 
        !           115:                if (i != nairspace && s[i].time <= r.rtime) continue;
        !           116:                strcpy(s[i].airspname,r.airspace);
        !           117:                strcpy(s[i].recordholder,r.user);
        !           118:                s[i].time = r.rtime;
        !           119:                strcpy(s[i].smo,r.month);
        !           120:                s[i].shour = r.dhour;
        !           121:                s[i].smin = r.dmin;
        !           122:                strcpy(s[i].sdate,r.date);
        !           123:                if (i == nairspace) nairspace++;
        !           124:        }
        !           125:        printf("           RECORDHOLDERS\n\n");
        !           126:        for (i=0; i<nairspace; i++)
        !           127:                printf("%s %s %2d:%02d %s: %s in %d minutes\n",
        !           128:                        s[i].smo,s[i].sdate,s[i].shour,s[i].smin,
        !           129:                        s[i].recordholder,s[i].airspname,s[i].time);
        !           130: 
        !           131:        printf("\nINDIVIDUAL STATS: per declared hour\n\n");
        !           132:        printf("            Time  SYS GAS CMD  CR TT BD GA    OK\n");
        !           133:        for (i=0; i<users; i++)
        !           134:        {       if (u[i].minutes <= 0) continue;
        !           135:                printf("%8s:%4d:%02d %3d%5d%4d%4d%3d%3d%3d%6d\n",u[i].uname,
        !           136:                       u[i].urtime/60, u[i].urtime%60,
        !           137:                       60 * u[i].usystem/u[i].urtime,
        !           138:                       60 * u[i].ugas/u[i].urtime,
        !           139:                       60 * u[i].ucmds/u[i].urtime,
        !           140:                       60 * u[i].ucrashes/u[i].urtime,
        !           141:                       60 * u[i].utowtruck/u[i].urtime,
        !           142:                       60 * u[i].uboundary/u[i].urtime,
        !           143:                       60 * u[i].ugoaround/u[i].urtime,
        !           144:                       60 * u[i].through/u[i].urtime);
        !           145:        }
        !           146:        printf("\nINDIVIDUAL STATS: per real hour\n\n");
        !           147:        printf("            Time  SYS GAS CMD  CR TT BD GA    OK\n");
        !           148:        for (i=0; i<users; i++)
        !           149:        {       if (u[i].minutes <= 0) continue;
        !           150:                printf("%8s:%4d:%02d %3d%5d%4d%4d%3d%3d%3d%6d\n",u[i].uname,
        !           151:                       u[i].minutes/60, u[i].minutes%60,
        !           152:                       60 * u[i].usystem/u[i].minutes,
        !           153:                       60 * u[i].ugas/u[i].minutes,
        !           154:                       60 * u[i].ucmds/u[i].minutes,
        !           155:                       60 * u[i].ucrashes/u[i].minutes,
        !           156:                       60 * u[i].utowtruck/u[i].minutes,
        !           157:                       60 * u[i].uboundary/u[i].minutes,
        !           158:                       60 * u[i].ugoaround/u[i].minutes,
        !           159:                       60 * u[i].through/u[i].minutes);
        !           160:        }
        !           161: }
        !           162: 
        !           163: 

unix.superglobalmegacorp.com

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