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