Annotation of researchv10no/games/rnd.c, revision 1.1.1.1

1.1       root        1: /*%cc -O %
                      2:  */
                      3: char copr[] = "Copyright (c) 1976 Thomas S. Duff";
                      4: #include <stdio.h>
                      5: #define NCOLS (132+1)
                      6: #define CENTRE 1
                      7: #define UL     2
                      8: #define UR     4
                      9: #define LL     8
                     10: #define LR     16
                     11: char line[NCOLS+1][3];
                     12: char outline[NCOLS];
                     13: int eof;
                     14: int xs, ys;
                     15: int nsp;
                     16: char buf[BUFSIZ];
                     17: main(argc, argv)
                     18: char *argv[];
                     19: {
                     20:        extern fout;
                     21:        if(argc!=3){
                     22:                fprintf(stderr, "Usage: rnd verscale horscale\n");
                     23:                exit(1);
                     24:        }
                     25:        setbuf(stdout, buf);
                     26:        ys=atoi(argv[1]);
                     27:        xs=atoi(argv[2]);
                     28:        readline();
                     29:        while(!eof){
                     30:                readline();
                     31:                fill();
                     32:                writeline();
                     33:        }
                     34: }
                     35: readline(){
                     36:        register c;
                     37:        register i;
                     38:        for(i=1;i!=NCOLS;i++){
                     39:                line[i][0]=line[i][1];
                     40:                line[i][1]=line[i][2];
                     41:        }
                     42:        if(eof)
                     43:                for(i=1;i!=NCOLS;i++)
                     44:                        line[i][3]=0;
                     45: 
                     46:        else{
                     47:                for(i=1;i!=NCOLS;i++){
                     48:                        switch(getchar()){
                     49:                        case EOF:
                     50:                                eof++;
                     51:                        case '\n':
                     52:                                for(;i!=NCOLS;i++)
                     53:                                        line[i][2]=0;
                     54:                                return;
                     55:                        case ' ':
                     56:                                line[i][2]=0;
                     57:                                break;
                     58:                        default:
                     59:                                line[i][2]=1;
                     60:                        }
                     61:                }
                     62:                while(getchar()!='\n');
                     63:        }
                     64: }
                     65: #define wchars(bit,ctrl) if(outline[i]&bit)for(ctrl)putx();else for(ctrl)nsp++
                     66: writeline(){
                     67:        register i, j, k;
                     68:        int t;
                     69:        for(j=0;j<ys/2;j++){
                     70:                t=xs/2-j*xs/ys;
                     71:                if(t<0)
                     72:                        t=0;
                     73:                for(i=1;i!=NCOLS;i++){
                     74:                        wchars(UL, k=0;k<t;k++);
                     75:                        wchars(CENTRE, ;k<xs-t;k++);
                     76:                        wchars(UR, ;k<xs;k++);
                     77:                }
                     78:                nsp=0;
                     79:                putchar('\n');
                     80:        }
                     81:        for(;j<ys;j++){
                     82:                t=j*xs/ys-xs/2;
                     83:                if(t<0)
                     84:                        t=0;
                     85:                for(i=1;i!=NCOLS;i++){
                     86:                        wchars(LL, k=0;k<t;k++);
                     87:                        wchars(CENTRE, ;k<xs-t;k++);
                     88:                        wchars(LR, ;k<xs;k++);
                     89:                }
                     90:                nsp=0;
                     91:                putchar('\n');
                     92:        }
                     93: }
                     94: putx(){
                     95:        register i;
                     96:        i=nsp;
                     97:        if(i)
                     98:                do
                     99:                        putchar(' ');
                    100:                while(--i);
                    101:        putchar('#');
                    102:        nsp=0;
                    103: }
                    104: #define NDIRS 4
                    105: char corner[NDIRS] = {
                    106:        UL,
                    107:        UR,
                    108:        LL,
                    109:        LR};
                    110: struct{
                    111:        int x0, y0, x1, y1, x2, y2;
                    112: }full[NDIRS] = {
                    113:        -1,0,0,0,-1,1,
                    114:        0,0,1,0,1,1,
                    115:        -1,1,-1,2,0,2,
                    116:        1,1,1,2,0,2
                    117: };
                    118: struct{
                    119:        int x0, y0, x1, y1;
                    120: }empty[NDIRS] = {
                    121:        -1,1,0,0,
                    122:        0,0,1,1,
                    123:        -1,1,0,2,
                    124:        0,2,1,1
                    125: };
                    126: fill(){
                    127:        register i, j;
                    128:        for(i=1;i!=NCOLS;i++)
                    129:                if(line[i][1]){
                    130:                        outline[i]=CENTRE;
                    131:                        for(j=0;j!=NDIRS;j++)
                    132:                                if(line[full[j].x0+i][full[j].y0])
                    133:                                        outline[i]|=corner[j];
                    134:                                else if(line[full[j].x1+i][full[j].y1])
                    135:                                        outline[i]|=corner[j];
                    136:                                else if(line[full[j].x2+i][full[j].y2])
                    137:                                        outline[i]|=corner[j];
                    138:                }
                    139:                else{
                    140:                        outline[i]=0;
                    141:                        for(j=0;j!=NDIRS;j++)
                    142:                                if(line[empty[j].x0+i][empty[j].y0]
                    143:                                && line[empty[j].x1+i][empty[j].y1])
                    144:                                        outline[i]|=corner[j];
                    145:                }
                    146: }

unix.superglobalmegacorp.com

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