Annotation of researchv10no/cmd/view2d/view2d.c, revision 1.1

1.1     ! root        1: #include       <stdio.h>
        !             2: #include       <signal.h>
        !             3: #include       <sgtty.h>
        !             4: #include       "/usr/jerq/include/jioctl.h"
        !             5: #include       "view2d.h"
        !             6: 
        !             7: #define                PIXMAX          32766
        !             8: 
        !             9: struct sgttyb sttybuf, sttysave;
        !            10: char *zflag = "";
        !            11: int shade = 0;
        !            12: int grid = 1;
        !            13: typedef struct Point
        !            14: {
        !            15:        int x, y;
        !            16: } Point;
        !            17: 
        !            18: short z[4096];
        !            19: double ztime;
        !            20: double fmid, fscale;
        !            21: 
        !            22: int zmax = -1000000000, zmin = 1000000000;
        !            23: int nsleep, ntime;
        !            24: int nframes = 0;
        !            25: int period = 5;
        !            26: int floor = -BIG;
        !            27: char *progname;
        !            28: short timewarp;
        !            29: double ts, te;
        !            30: Rd2d rd;
        !            31: 
        !            32: main(argc, argv)
        !            33:        char **argv;
        !            34: {
        !            35:        char buf[512];
        !            36:        int zc, scale, m, i;
        !            37:        short ragnorok, dim;
        !            38:        short *nz, *p, *q;
        !            39:        int fd;
        !            40:        int cv, tmin, tmax;
        !            41:        short nx, ny, fru, frv;
        !            42:        char *s;
        !            43:        char **av = argv;
        !            44:        int ac = argc;
        !            45:        extern char *getenv();
        !            46:        int magic[4];
        !            47: 
        !            48:        timewarp = 0;
        !            49:        progname = argv[0];
        !            50:        cv = ((s = getenv("TERM")) == 0) || strcmp(s, "5620");
        !            51:        cv = 1;  /* I can't stand -T5 as default!!!  ehg */
        !            52:        ioctl(0, TIOCGETP, &sttysave);
        !            53:        strcpy(buf, "level");
        !            54:        for(argc--, argv++; *argv && (**argv == '-'); argv++)
        !            55:                switch(argv[0][1])
        !            56:                {
        !            57:                case 'z':
        !            58:                        zflag = "-z";
        !            59:                        break;
        !            60:                case 's':
        !            61:                        shade++;
        !            62:                        break;
        !            63:                case 'g':
        !            64:                        grid = 0;
        !            65:                        break;
        !            66:                case 'T':
        !            67:                        if(argv[0][2] == 'c') cv = 1;
        !            68:                        else if(argv[0][2] == '5') cv = 0;
        !            69:                        else if(argv[0][2] == 'p') cv = 2;
        !            70:                        else if(argv[0][2] == 'h') cv = 3;
        !            71:                        else if(argv[0][2] == 'd') cv = 4;
        !            72:                        else if(argv[0][2] == 's') cv = 5;
        !            73:                        else goto err;
        !            74:                        break;
        !            75:                case 't':
        !            76:                        i = sscanf(&argv[0][2], "%hd, %hd", &ts, &te);
        !            77:                        if(i==0) error("bad TS,TE");
        !            78:                        timewarp = i;
        !            79:                        break;
        !            80:                case 'p':
        !            81:                        sscanf(&argv[0][2], "%d", &period);
        !            82:                        break;
        !            83:                case 'i':
        !            84:                        if(cv==0) sscanf(&argv[0][2], "%d", &floor);
        !            85:                        break;
        !            86:                case 'B':
        !            87:                case 'D':
        !            88:                case 'S':
        !            89:                case 'b':
        !            90:                case 'm':
        !            91:                case 'w':
        !            92:                        /* these only apply in color, so assume -Tc */
        !            93:                        cv = 1;
        !            94:                        break;
        !            95:                case 'c':
        !            96:                        if(cv==0) cv = 1; /* maybe -Tp, but probably -Tc */
        !            97:                case 'v':
        !            98:                case 'x':
        !            99:                case 'y':
        !           100:                        break;
        !           101:                default:
        !           102:                err:
        !           103:                        fprintf(stderr, "Usage: view2d [-Tdev] [-ptime] [-cn] [-ms]\n");
        !           104:                        exit(1);
        !           105:                }
        !           106:        if(*argv){
        !           107:                if((fd = open(*argv, 0)) == -1)
        !           108:                        quit("cannot open input", 1);
        !           109:        }else{
        !           110:                fd = 0;  /* if no file argument, try standard input */
        !           111:        }
        !           112:        if(cv==1)
        !           113:        {
        !           114:                if(access((s="/usr/lib/view2d/level"), 1) == -1)
        !           115:                {
        !           116:                        fprintf(stderr, "go to swift for color\n");
        !           117:                        exit(1);
        !           118:                }
        !           119:                dup2(fd,0);     /* close(0); dup(fd); close(fd); */
        !           120:                strcpy(*av, "level");
        !           121:                execvp(s, av);
        !           122:                perror(s);
        !           123:                exit(1);
        !           124:        } else if(cv==2) {
        !           125:                if(access((s="/usr/lib/view2d/contour"), 1) == -1)
        !           126:                {
        !           127:                        fprintf(stderr, "can't find %s\n",s);
        !           128:                        exit(1);
        !           129:                }
        !           130:                dup2(fd,0);     /* close(0); dup(fd); close(fd); */
        !           131:                strcpy(*av, "cntour");
        !           132:                        /* WARNING: strlen("cntour") must <= strlen("view2d") */
        !           133:                execvp(s, av);
        !           134:                perror(s);
        !           135:                exit(1);
        !           136:        } else if(cv==3)
        !           137:        {
        !           138:                if(access((s="/usr/lib/view2d/halft"), 1) == -1)
        !           139:                {
        !           140:                        fprintf(stderr, "can't find %s\n",s);
        !           141:                        exit(1);
        !           142:                }
        !           143:                dup2(fd,0);     /* close(0); dup(fd); close(fd); */
        !           144:                strcpy(*av, "halft");
        !           145:                execvp(s, av);
        !           146:                perror(s);
        !           147:                exit(1);
        !           148:        } else if(cv==4)
        !           149:        {
        !           150:                if(access((s="/usr/lib/view2d/viewtd"), 1) == -1)
        !           151:                {
        !           152:                        fprintf(stderr, "can't find %s\n",s);
        !           153:                        exit(1);
        !           154:                }
        !           155:                dup2(fd,0);     /* close(0); dup(fd); close(fd); */
        !           156:                strcpy(*av, "viewtd");
        !           157:                execvp(s, av);
        !           158:                perror(s);
        !           159:                exit(1);
        !           160:        } else if(cv==5)
        !           161:        {
        !           162:                if(access((s="/usr/lib/view2d/slice"), 1) == -1)
        !           163:                {
        !           164:                        fprintf(stderr, "can't find %s\n",s);
        !           165:                        exit(1);
        !           166:                }
        !           167:                dup2(fd,0);     /* close(0); dup(fd); close(fd); */
        !           168:                strcpy(*av, "slice");
        !           169:                execvp(s, av);
        !           170:                perror(s);
        !           171:                exit(1);
        !           172:        }
        !           173:        rd2dh(fd, &nx, &ny);
        !           174:        if(nx*ny*sizeof(short) > sizeof z)
        !           175:        {
        !           176:                sprintf(buf, "nx*ny=%d: must be less than 4096\n", nx*ny);
        !           177:                quit(buf, 1);
        !           178:        }
        !           179:        sttybuf = sttysave;
        !           180:        sttybuf.sg_flags |= RAW;
        !           181:        sttybuf.sg_flags &= ~ECHO;
        !           182:        ioctl(0, TIOCSETP, &sttybuf);
        !           183:        sprintf(buf, "/usr/jerq/bin/32ld %s /usr/lib/view2d/view2d.m", zflag);/**/
        !           184:        if(system(buf)) quit(0, 1);
        !           185:        putchar('X'); sendn(nx);
        !           186:        putchar('Y'); sendn(ny);
        !           187:        if(grid) putchar('G');
        !           188:        if(shade) putchar('S');
        !           189:        putchar('P');
        !           190:        sendn(period);
        !           191:        putchar('n');
        !           192:        sendn(rd.nfr);
        !           193:        putchar('I');
        !           194:        sendn(floor);
        !           195:        m = 2*nx*ny;
        !           196:        fmid = (rd.pmin+rd.pmax)/2.0;
        !           197:        fscale = PIXMAX/(rd.pmax - fmid);
        !           198:        while(rd2di(&ztime, z))
        !           199:        {
        !           200:                char buf[56];
        !           201: 
        !           202:                putchar('F');
        !           203:                sprintf(buf, "%g", ztime);
        !           204:                sends(buf);
        !           205:                for(q = nx*ny + (p = z); q != p; p++)
        !           206:                        sendn(*p < floor ? floor : (short)((*p-fmid)*fscale));
        !           207:        }
        !           208: 
        !           209:        putchar('Q');
        !           210:        fflush(stdout);
        !           211:        (void)getchar();
        !           212:        quit(0, 0);
        !           213: }
        !           214: 
        !           215: quit(s, e)
        !           216:        char *s;
        !           217: {
        !           218:        ioctl(0, JTERM, 0);
        !           219:        ioctl(0, TIOCSETP, &sttysave);
        !           220:        if(s)
        !           221:                printf("view2d: %s\n", s);
        !           222:        exit(e);
        !           223: }
        !           224: 
        !           225: sendn(n)
        !           226: {
        !           227:        putchar(n>>8);
        !           228:        putchar(n);
        !           229: }
        !           230: 
        !           231: sends(s)
        !           232:        char *s;
        !           233: {
        !           234:        while(*s) putchar(*s++);
        !           235:        putchar(0);
        !           236: }
        !           237: 
        !           238: abs(n)
        !           239: {
        !           240:        return(n<0? -n:n);
        !           241: }

unix.superglobalmegacorp.com

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