|
|
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 MAX 32767 ! 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: ioctl(0, TIOCGETP, &sttysave); ! 52: strcpy(buf, "level"); ! 53: for(argc--, argv++; *argv && (**argv == '-'); argv++) ! 54: switch(argv[0][1]) ! 55: { ! 56: case 'z': ! 57: zflag = "-z"; ! 58: break; ! 59: case 's': ! 60: shade++; ! 61: break; ! 62: case 'g': ! 63: grid = 0; ! 64: break; ! 65: case 'T': ! 66: if(argv[0][2] == 'c') cv = 1; ! 67: else if(argv[0][2] == '5') cv = 0; ! 68: else if(argv[0][2] == 'p') cv = 2; ! 69: else if(argv[0][2] == 'h') cv = 3; ! 70: else goto err; ! 71: break; ! 72: case 't': ! 73: i = sscanf(&argv[0][2], "%hd, %hd", &ts, &te); ! 74: if(i==0) error("bad TS,TE"); ! 75: timewarp = i; ! 76: break; ! 77: case 'p': ! 78: sscanf(&argv[0][2], "%d", &period); ! 79: break; ! 80: case 'i': ! 81: sscanf(&argv[0][2], "%d", &floor); ! 82: break; ! 83: case 'B': ! 84: case 'D': ! 85: case 'S': ! 86: case 'b': ! 87: case 'm': ! 88: case 'w': ! 89: /* these options only apply in color, so assume -Tc */ ! 90: cv = 1; ! 91: break; ! 92: case 'c': ! 93: if(cv==0) cv = 1; /* maybe -Tp, but probably -Tc */ ! 94: case 'v': ! 95: break; ! 96: default: ! 97: err: ! 98: fprintf(stderr, "Usage: view2d [-Tdev] [-ptime] [-cn] [-ms]\n"); ! 99: exit(1); ! 100: } ! 101: if(*argv){ ! 102: if((fd = open(*argv, 0)) == -1) ! 103: quit("cannot open input"); ! 104: }else{ ! 105: fd = 0; /* if no file argument, try standard input */ ! 106: } ! 107: if(cv==1) ! 108: { ! 109: if(access((s="/usr/lib/view2d/level"), 1) == -1) ! 110: { ! 111: fprintf(stderr, "go to swift for color\n"); ! 112: exit(1); ! 113: } ! 114: dup2(fd,0); /* close(0); dup(fd); close(fd); */ ! 115: strcpy(*av, "level"); ! 116: execvp(s, av); ! 117: perror(s); ! 118: exit(1); ! 119: } else if(cv==2) { ! 120: if(access((s="/usr/lib/view2d/contour"), 1) == -1) ! 121: { ! 122: fprintf(stderr, "can't find %s\n",s); ! 123: exit(1); ! 124: } ! 125: dup2(fd,0); /* close(0); dup(fd); close(fd); */ ! 126: strcpy(*av, "cntour"); ! 127: /* WARNING: strlen("cntour") must <= strlen("view2d") */ ! 128: execvp(s, av); ! 129: perror(s); ! 130: exit(1); ! 131: } else if(cv==3) ! 132: { ! 133: if(access((s="/usr/lib/view2d/halft"), 1) == -1) ! 134: { ! 135: fprintf(stderr, "can't find %s\n",s); ! 136: exit(1); ! 137: } ! 138: dup2(fd,0); /* close(0); dup(fd); close(fd); */ ! 139: strcpy(*av, "halft"); ! 140: execvp(s, av); ! 141: perror(s); ! 142: exit(1); ! 143: } ! 144: sttybuf = sttysave; ! 145: sttybuf.sg_flags |= RAW; ! 146: sttybuf.sg_flags &= ~ECHO; ! 147: ioctl(0, TIOCSETP, &sttybuf); ! 148: rd2dh(fd, &nx, &ny); ! 149: if(nx*ny*sizeof(short) > sizeof z) ! 150: { ! 151: fprintf(stderr, "nx*ny=%d: must be less than 4096\n", nx*ny); ! 152: exit(1); ! 153: } ! 154: sprintf(buf, "/usr/jerq/bin/32ld %s /usr/lib/view2d/view2d.m", zflag); ! 155: if(system(buf)) exit(1); ! 156: putchar('X'); sendn(nx); ! 157: putchar('Y'); sendn(ny); ! 158: if(grid) putchar('G'); ! 159: if(shade) putchar('S'); ! 160: putchar('P'); ! 161: sendn(period); ! 162: putchar('n'); ! 163: sendn(rd.nfr); ! 164: putchar('I'); ! 165: sendn(floor); ! 166: m = 2*nx*ny; ! 167: fmid = (rd.fmin+rd.fmax)/2; ! 168: fscale = MAX/(rd.fmax - fmid); ! 169: while(rd2di(&ztime, z)) ! 170: { ! 171: char buf[56]; ! 172: ! 173: putchar('F'); ! 174: sprintf(buf, "%g", ztime); ! 175: sends(buf); ! 176: for(q = nx*ny + (p = z); q != p; p++) ! 177: sendn((short)((*p-fmid)*fscale)); ! 178: } ! 179: ! 180: putchar('Q'); ! 181: fflush(stdout); ! 182: (void)getchar(); ! 183: quit(0); ! 184: } ! 185: ! 186: quit(s) ! 187: char *s; ! 188: { ! 189: ioctl(0, JTERM, 0); ! 190: ioctl(0, TIOCSETP, &sttysave); ! 191: if(s) ! 192: printf("view2d: %s\n", s); ! 193: exit(0); ! 194: } ! 195: ! 196: sendn(n) ! 197: { ! 198: putchar(n>>8); ! 199: putchar(n); ! 200: } ! 201: ! 202: sends(s) ! 203: char *s; ! 204: { ! 205: while(*s) putchar(*s++); ! 206: putchar(0); ! 207: } ! 208: ! 209: abs(n) ! 210: { ! 211: return(n<0? -n:n); ! 212: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.