Annotation of researchv9/jerq/src/lib/jj/jerq.c, revision 1.1

1.1     ! root        1: #include <jerq.h>
        !             2: #include <jerqio.h>
        !             3: 
        !             4: Texture ones={
        !             5:        0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF,
        !             6:        0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF,
        !             7: };
        !             8: 
        !             9: Point pt1, pt2;
        !            10: Point pt[256];
        !            11: int npts;
        !            12: 
        !            13: main(){
        !            14:        do; while(input());
        !            15:        scan();
        !            16:        output();
        !            17: }
        !            18: input(){
        !            19:        Point t;
        !            20:        static int lineno=0;
        !            21:        if(getline()==0)
        !            22:                return 0;
        !            23:        lineno++;
        !            24:        if(npts==0){
        !            25:                pt[npts++]=pt1;
        !            26:                pt[npts++]=pt2;
        !            27:                return 1;
        !            28:        }
        !            29:        if(eqpt(pt1, pt[npts-1])){
        !            30:                pt[npts++]=pt2;
        !            31:                return 1;
        !            32:        }
        !            33:        if(eqpt(pt2, pt[npts-1])){
        !            34:                pt[npts++]=pt1;
        !            35:                return 1;
        !            36:        }
        !            37:        if(npts!=2){
        !            38:                printf("panic 1: line %d\n", lineno);
        !            39:                exit();
        !            40:        }
        !            41:        t=pt[npts-2];
        !            42:        pt[npts-2]=pt[npts-1];
        !            43:        pt[npts-1]=t;
        !            44:        if(eqpt(pt1, pt[npts-1])){
        !            45:                pt[npts++]=pt2;
        !            46:                return 1;
        !            47:        }
        !            48:        if(eqpt(pt2, pt[npts-1])){
        !            49:                pt[npts++]=pt1;
        !            50:                return 1;
        !            51:        }
        !            52:        printf("panic 2: line %d\n", lineno);
        !            53:        exit();
        !            54:        return 0;
        !            55: }
        !            56: char *
        !            57: rin(p, ip)
        !            58:        register char *p;
        !            59:        register int *ip;
        !            60: {
        !            61:        register n=0, m=0, scale=1, sign=1;
        !            62:        while(*p==' ')
        !            63:                p++;
        !            64:        if(*p=='-')
        !            65:                p++, sign=-1;
        !            66:        while('0'<=*p && *p<='9')
        !            67:                n=10*n+*p++-'0';
        !            68:        n*=100;
        !            69:        if(*p=='.'){
        !            70:                p++;
        !            71:                while('0'<=*p && *p<='9'){
        !            72:                        m=10*m+*p++-'0';
        !            73:                        scale*=10;
        !            74:                }
        !            75:                n+=100*m/scale;
        !            76:        }
        !            77:        *ip=sign*n;
        !            78: printf("read %d.%d\n", sign*n/100, n%100);
        !            79:        return p;
        !            80: }
        !            81: getline(){
        !            82:        char buf[128];
        !            83:        int x;
        !            84:        register char *p;
        !            85:        if(fgets(buf, sizeof buf, stdin)==0)
        !            86:                return 0;
        !            87:        p=buf;
        !            88:        while(*p!=' ')
        !            89:                p++;
        !            90:        p=rin(p, &x);
        !            91:        pt1.x=x;
        !            92:        p=rin(p, &x);
        !            93:        pt1.y=x;
        !            94:        p=rin(p, &x);
        !            95:        pt2.x=x;
        !            96:        p=rin(p, &x);
        !            97:        pt2.y=x;
        !            98:        return 1;
        !            99: }
        !           100: scan(){
        !           101:        register i;
        !           102:        for(i=0; i<npts; i++){
        !           103: printf("pt %d %d %d\n", i, pt[i].x, pt[i].y);
        !           104:                pt[i].x/=50, pt[i].y/=50;
        !           105:                pt[i].x+=Drect.origin.x;
        !           106:                pt[i].y+=(Drect.origin.y+Drect.corner.y)/2;
        !           107:        }
        !           108:        for(i=1; i<npts; i++)
        !           109:                segment(&display, pt[i-1], pt[i], F_OR);
        !           110:        polyture(&display, pt, npts, &ones, F_OR);
        !           111: }
        !           112: output(){
        !           113:        request(KBD);
        !           114:        do wait(KBD); while(kbdchar()!='q');
        !           115:        exit();
        !           116: }
        !           117: pause(){
        !           118:        request(KBD);
        !           119:        rectf(&display, Drect, F_XOR); sleep(20); rectf(&display, Drect, F_XOR);
        !           120:        do wait(KBD); while(kbdchar()!='q');
        !           121: }

unix.superglobalmegacorp.com

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