|
|
1.1 ! root 1: /* ! 2: * 300s [+12] [-n] [-dt,l,c] ! 3: * for DTC/DASI 300/S ! 4: * +12 12-pitch, 6 lines/inch (needs to be faked on this terminal ! 5: * -n # increments for half-line spacing ! 6: * -dt,l,c delays for tab, line char ! 7: * ! 8: */ ! 9: ! 10: char *xxxvers = "@(#)300s.c 1.7"; ! 11: #include <stdio.h> ! 12: #include <signal.h> ! 13: #include <sys/types.h> ! 14: #include <sys/stat.h> ! 15: #include <sgtty.h> ! 16: /* input sequences (TTY37 style) */ ! 17: #define ESC 033 /* escape */ ! 18: #define HFWD '9' ! 19: #define HREV '8' ! 20: #define FREV '7' ! 21: #define SO 016 /* shift out - enter greek */ ! 22: #define SI 017 /* shift in */ ! 23: ! 24: /* output specials (300 style) */ ! 25: #define PLOT 006 /* ack, on/off plot mode */ ! 26: #define BEL 007 /* exit plot mode */ ! 27: #define U 032 ! 28: #define D 012 ! 29: #define R ' ' ! 30: #define L '\b' ! 31: #define LF '\n' ! 32: #define CR '\r' ! 33: #define TABVAL 4 /* approx equivalent of blanks per tab */ ! 34: #define FLIPMODE intrmod ^= 01 ! 35: ! 36: int nlcnt, /* accumulated newline count */ ! 37: frevcnt, /* accumulated reverse line-feeds */ ! 38: pitch12, /* 1==> 12-pitch&6lines/inch, 0==>10-pitch */ ! 39: fullsiz, /* # increments for full line */ ! 40: halfsiz = 4; /* # increments for halfline */ ! 41: int tabcnt, /* accumulated tabs in 1 line */ ! 42: charcnt, /* # chars in line */ ! 43: nblcnt; /* nonblanks contiguous */ ! 44: int delay[3] = {3,90,20}; ! 45: /* tab limit, characters/line, contiguous lim*/ ! 46: char *ttydev; ! 47: int svstmode; /* for mesg restore */ ! 48: int restore(); ! 49: int svsgflgs; ! 50: struct sgttyb sgb; ! 51: char *scanptr; /* side-effect of getnum() */ ! 52: ! 53: int intrmod = 1, /* internal mode, 1==> text, 0 ==> plot */ ! 54: extrmod =1; /* external, same */ ! 55: ! 56: ! 57: main(argc, argv) ! 58: char **argv; ! 59: { ! 60: register c; ! 61: ! 62: scanarg(argc, argv); ! 63: if (((int)signal(SIGINT, SIG_IGN) & 01) == 0) ! 64: signal(SIGINT, restore); ! 65: if (gtty(1, &sgb) == 0) ! 66: fixtty(); ! 67: setbuf(stdin, calloc(BUFSIZ,1)); ! 68: while ((c = getchar()) != EOF) { ! 69: if (intrmod) { ! 70: if (c == '\n') { ! 71: if (frevcnt) ! 72: flushrv(); ! 73: nlcnt++; ! 74: continue; ! 75: } else if (nlcnt) ! 76: flushnl(); ! 77: else if (frevcnt && c != ESC) ! 78: flushrv(); ! 79: } ! 80: if (c == PLOT) { ! 81: FLIPMODE; ! 82: continue; ! 83: } ! 84: if (c == SO) { ! 85: special(); ! 86: continue; ! 87: } ! 88: if (c != ESC) { ! 89: charcnt++; ! 90: if (c == ' ') ! 91: nblcnt = 0; ! 92: else if (c == '\t') { ! 93: charcnt += TABVAL; ! 94: nblcnt = 0; ! 95: if (++tabcnt >= delay[0]) { ! 96: putx('\0'); ! 97: tabcnt = 0; ! 98: if (delay[0] == 0) /* 2 nulls per tab */ ! 99: putx('\0'); ! 100: } ! 101: } else if (c == '\b') ! 102: charcnt--; ! 103: else if (++nblcnt >= delay[2]) { ! 104: nblcnt = 0; ! 105: putx('\0'); ! 106: if (delay[2] == 0) ! 107: putx('\0'); ! 108: } ! 109: if (intrmod != extrmod) { ! 110: if (intrmod == 1) ! 111: putchar(ESC); /* 300s uses ESC PLOT to get out */ ! 112: putchar(PLOT); /* flip real state */ ! 113: extrmod = intrmod; ! 114: } ! 115: putchar(c); ! 116: continue; ! 117: } ! 118: FLIPMODE; ! 119: c = getchar(); ! 120: if (frevcnt && c != FREV) { ! 121: FLIPMODE; ! 122: flushrv(); ! 123: FLIPMODE; ! 124: } ! 125: if (c == HREV) ! 126: nplot(halfsiz,U); ! 127: else if (c == HFWD) ! 128: nplot(halfsiz,D); ! 129: else if (c == FREV) ! 130: frevcnt++; ! 131: FLIPMODE; ! 132: } ! 133: flusher(); ! 134: restore(); ! 135: } ! 136: ! 137: ! 138: /* scanarg: scan arguments and set flags; ignore unknown args */ ! 139: scanarg(argc, argv) ! 140: char **argv; ! 141: { ! 142: register char *p; ! 143: ! 144: while (--argc > 0) { ! 145: p = *++argv; ! 146: if (strcmp(p, "+12") == 0) ! 147: pitch12 = 1; ! 148: else if (*p++ == '-') { ! 149: if (*p == 'd') ! 150: getdelay(++p); ! 151: else if (*p > '0' && *p <= '9') ! 152: halfsiz = *p - '0'; ! 153: } ! 154: } ! 155: fullsiz = pitch12 ? 6 : 8; ! 156: } ! 157: ! 158: /* getdelay: scan fields of delay arg */ ! 159: getdelay(p) ! 160: register char *p; ! 161: { ! 162: register i; ! 163: ! 164: for (i = 0; i <= 2; i++) { ! 165: if (*p == ',') { ! 166: p++; ! 167: continue; ! 168: } ! 169: if (*p == '\0') ! 170: break; ! 171: delay[i] = getnum(p); ! 172: p = scanptr+1; ! 173: if (*scanptr != ',') ! 174: break; ! 175: } ! 176: } ! 177: ! 178: /* fixtty: get tty status and save; remove CR-LF mapping */ ! 179: fixtty() ! 180: { ! 181: struct stat sb; ! 182: ! 183: svsgflgs = sgb.sg_flags; ! 184: sgb.sg_flags &= ~CRMOD; ! 185: stty(1, &sgb); /* stty nl */ ! 186: fstat(1, &sb); ! 187: svstmode = sb.st_mode; ! 188: ttydev = (char*)ttyname(1); ! 189: chmod(ttydev, 0600); /* mesg n */ ! 190: } ! 191: ! 192: getnum(p) ! 193: register char *p; ! 194: { ! 195: register i = 0 ; ! 196: ! 197: while (*p >= '0' && *p <= '9') ! 198: i = 10*i + *p++ - '0'; ! 199: scanptr = p; ! 200: return(i); ! 201: } ! 202: ! 203: /* flusher: flush accumulated newlines, reverse line feeds, buffer */ ! 204: flusher() ! 205: { ! 206: if (nlcnt) ! 207: flushnl(); ! 208: if (frevcnt) ! 209: flushrv(); ! 210: fflush(stdout); ! 211: } ! 212: ! 213: /* flushrv: flush accumulated reverse line feeds */ ! 214: /* note: expects to be out of plot mode on entry */ ! 215: char frv1[] = {U,PLOT,U,U,PLOT,0}; /* 1 FREV leftover */ ! 216: char frv2[] = {U,U,PLOT,U,U,U,U,PLOT,0}; /* 2 of them */ ! 217: char frvadj[] = {U,U,U,LF,LF,LF,0}; /* forms tractor fixup */ ! 218: flushrv() ! 219: { ! 220: register numleft; ! 221: ! 222: if (pitch12) { ! 223: numleft = frevcnt % 3; ! 224: frevcnt = 4 * (frevcnt / 3); ! 225: } else ! 226: numleft = 0; ! 227: while (frevcnt--) { ! 228: putx(U); ! 229: nplot(5,'\0'); /* slow down somewhat */ ! 230: } ! 231: if (numleft == 1) ! 232: putstr(frv1); ! 233: else if (numleft == 2) ! 234: putstr(frv2); ! 235: putstr(frvadj); ! 236: frevcnt = 0; ! 237: } ! 238: ! 239: /* flushnl: flush accumulated newlines (count in nlcnt) */ ! 240: char nl1[] = {LF, PLOT, LF, LF, PLOT, 0}; /* 12pitch: 1 nl */ ! 241: char nl2[] = {LF, LF, PLOT, LF, LF, LF, LF, PLOT, 0}; /* 2 nls */ ! 242: flushnl() ! 243: { ! 244: register numleft; ! 245: ! 246: if (pitch12) { ! 247: numleft = nlcnt % 3; ! 248: nlcnt = 4 * (nlcnt/3); ! 249: } else ! 250: numleft = 0; ! 251: putx(CR); /* must have 1 CR; only 1 needed */ ! 252: while (nlcnt--) ! 253: putx(LF); /* no plot mode needed for these */ ! 254: if (numleft == 1) ! 255: putstr(nl1); ! 256: else if (numleft == 2) ! 257: putstr(nl2); ! 258: if (charcnt > delay[1]) ! 259: nplot(1 + charcnt/20,'\0'); ! 260: nlcnt = charcnt = nblcnt = tabcnt = 0; ! 261: } ! 262: ! 263: putstr(p) ! 264: register char *p; ! 265: { ! 266: while (*p) ! 267: putx(*p++); ! 268: } ! 269: ! 270: restore() ! 271: { ! 272: putchar(ESC); ! 273: putchar(PLOT); ! 274: if (isatty(1)) { ! 275: sgb.sg_flags = svsgflgs; ! 276: stty(1, &sgb); ! 277: chmod(ttydev, svstmode); ! 278: } ! 279: exit(0); ! 280: } ! 281: ! 282: char alpha[] = {L,'c',R,R,'(',L,0}; ! 283: char beta[] = {'B',L,L,D,D,'|',R,R,U,U,0}; ! 284: char delta[] = {'o',U,U,'<',D,D,0}; ! 285: char DELTA[] = {L,L,'/',0203,D,'-',0204,R,'-',0203,U,'\\',L,L,0}; ! 286: char epsilon[] = {'<','-',0}; ! 287: char eta[] = {'n',R,R,D,D,'|',L,L,U,U,0}; ! 288: char gamma[] = {')',R,'/',L,0}; ! 289: char GAMMA[] = {L,L,'|',R,R,0203,U,'-',0203,D,R,R,'`',L,L,0}; ! 290: char infinity[] = {L,L,'c',0204,R,'o',L,L,0}; ! 291: char integral[] = {'|','\'',R,R,'`',0203,L,0206,D,'\'',L,'`',R,R,0206,U,0}; ! 292: char lambda[] = {'\\',0204,D,L,'\'',D,L,'\'',0205,U,R,R,0}; ! 293: char LAMBDA[] = {L,L,'/',0204,R,'\\',L,L,0}; ! 294: char mu[] = {'u',L,L,',',R,R,0}; ! 295: char nabla[] = {L,L,'\\',0203,U,'-',0204,R,'-',0203,D,'/',L,L,0}; ! 296: char not[] = {'-',0202,R,U,',',D,0202,L,0}; ! 297: char nu[] = {L,'(',0203,R,'/',L,L,0}; ! 298: char omega[] = {L,'u',0203,R,'u',L,L,0}; ! 299: char OMEGA[] = {'O',D,D,L,'-',R,R,'-',L,U,U,0}; ! 300: char partial[] = {'o',R,D,'`',L,U,'`',L,U,'`',R,D,0}; ! 301: char phi[] = {'o','/',0}; ! 302: char PHI[] = {'o','[',']',0}; ! 303: char psi[] = {'/','-',D,D,R,R,'\'',0204,L,'\'',R,R,U,U,0}; ! 304: char PSI[] = {'[',']','-',D,D,R,R,'\'',0204,L,'`',R,R,U,U,0}; ! 305: char pi[] = {U,'-',0203,D,'"',D,'"',0203,U,0}; ! 306: char PI[] = {L,L,'[',']',0204,R,'[',']',L,L,0203,U,'-',0203,D,0}; ! 307: char rho[] = {'o',L,L,D,D,'|',U,U,R,R,0}; ! 308: char sigma[] = {'o',D,R,R,'~',U,L,L,0}; ! 309: char SIGMA[] = {'>',0202,D,'-',0205,U,'-',D,D,0}; ! 310: char tau[] = {'t',D,R,R,'~',L,L,L,'~',R,U,0}; ! 311: char theta[] = {'O','-',0}; ! 312: char THETA[] = {'O','=',0}; ! 313: char xi[] = {'c',R,D,',',L,0203,U,'c',L,D,'`',R,D,0}; ! 314: char zeta[] = {'c',R,D,',',L,0203,U,'<',D,D,0}; ! 315: ! 316: char tab[] = { ! 317: 'A', /* alpha */ ! 318: 'B', /* beta */ ! 319: 'D', /* delta */ ! 320: 'W', /* DELTA */ ! 321: 'S', /* epsilon */ ! 322: 'N', /* eta */ ! 323: '\\', /* gamma */ ! 324: 'G', /* GAMMA */ ! 325: 'o', /* infinity - not in M37 */ ! 326: '^', /* integral */ ! 327: 'L', /* lambda */ ! 328: 'E', /* LAMBDA */ ! 329: 'M', /* mu */ ! 330: '[', /* nabla (del) */ ! 331: '_', /* not */ ! 332: '@', /* nu */ ! 333: 'C', /* omega */ ! 334: 'Z', /* OMEGA */ ! 335: ']', /* partial */ ! 336: 'U', /* phi */ ! 337: 'F', /* PHI */ ! 338: 'V', /* psi */ ! 339: 'H', /* PSI */ ! 340: 'J', /* pi */ ! 341: 'P', /* PI */ ! 342: 'K', /* rho */ ! 343: 'Y', /* sigma */ ! 344: 'R', /* SIGMA */ ! 345: 'I', /* tau */ ! 346: 'T', /* theta */ ! 347: 'O', /* THETA */ ! 348: 'X', /* xi */ ! 349: 'Q', /* zeta */ ! 350: 0 ! 351: }; ! 352: char *trans[] = { ! 353: alpha, ! 354: beta, ! 355: delta, ! 356: DELTA, ! 357: epsilon, ! 358: eta, ! 359: gamma, ! 360: GAMMA, ! 361: infinity, ! 362: integral, ! 363: lambda, ! 364: LAMBDA, ! 365: mu, ! 366: nabla, ! 367: not, ! 368: nu, ! 369: omega, ! 370: OMEGA, ! 371: partial, ! 372: phi, ! 373: PHI, ! 374: psi, ! 375: PSI, ! 376: pi, ! 377: PI, ! 378: rho, ! 379: sigma, ! 380: SIGMA, ! 381: tau, ! 382: theta, ! 383: THETA, ! 384: xi, ! 385: zeta, ! 386: 0 ! 387: }; ! 388: ! 389: special() ! 390: { ! 391: register c, i; ! 392: ! 393: loop: ! 394: if ((c = getchar()) == SI || c < 0) ! 395: return; ! 396: for (i = 0; tab[i] != 0; i++) ! 397: if (c == tab[i]) { ! 398: plot(trans[i]); ! 399: goto loop; ! 400: } ! 401: putx(c); ! 402: goto loop; ! 403: } ! 404: ! 405: plot(s) ! 406: register char *s; ! 407: { ! 408: register i, c; ! 409: ! 410: FLIPMODE; ! 411: for (i = 0; (c = s[i]) != 0; i++) { ! 412: if (c & 0200) ! 413: nplot(c&0177, s[++i]); ! 414: else ! 415: putx(c); ! 416: } ! 417: FLIPMODE; ! 418: putx(' '); ! 419: } ! 420: ! 421: nplot(n, c) ! 422: register n, c; ! 423: { ! 424: while(n--) ! 425: putx(c); ! 426: } ! 427: ! 428: /* putx: add ordinary (not PLOT or BEL) character to output, adding ! 429: extra PLOT when needed to flip state. */ ! 430: putx(c) ! 431: register c; ! 432: { ! 433: if (intrmod != extrmod) { ! 434: if (intrmod == 1) ! 435: putchar(ESC); /* 300s uses ESC PLOT to get out, not flipflop */ ! 436: putchar(PLOT); ! 437: extrmod = intrmod; ! 438: } ! 439: putchar(c); ! 440: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.