1: #define PLOT 006 /* ack */ 2: #define BEL 007 /* exit plot mode */ 3: #define ESC 033 /* escape */ 4: #define HFWD '9' 5: #define HREV '8' 6: #define FREV '7' 7: #define SO 016 /* shift out - enter greek */ 8: #define SI 017 /* shift in */ 9: #define UP 013 10: #define DN 012 11: #define RT ' ' 12: #define LF '\b' 13: 14: int restore(); 15: int svmode, mode[3]; 16: 17: main(argc,argv) int argc; char **argv; { 18: int c, textmode; 19: extern int fin,fout; 20: fin = dup(0); 21: fout = dup(1); 22: if ((signal(2, 1) & 01) == 0) 23: signal(2, &restore); 24: gtty(1, mode); 25: svmode = mode[2]; 26: mode[2] =& 0777757; /* turn off cr-lf */ 27: mode[2] =| 03; /* turn off delays, tabs */ 28: stty(1, mode); 29: textmode = 1; 30: while( (c=getchar()) != '\0' ){ 31: if( c==SO ){ 32: special(); 33: continue; 34: } 35: if (c== PLOT) textmode = 1-textmode; 36: if (c==BEL) textmode = 1; 37: if( c=='\n' && textmode ) 38: putchar(015); /* CR */ 39: if( c!=ESC ){ 40: putchar(c); 41: continue; 42: } 43: putchar(PLOT); 44: c = getchar(); 45: if( c == HREV ) 46: nplot(4,UP); 47: else if( c == HFWD ) 48: nplot(4,DN); 49: else if( c == FREV ) 50: nplot(8,UP); 51: putchar(PLOT); 52: } 53: flush(); 54: restore(); 55: } 56: 57: restore(){ 58: mode[2] = svmode; 59: stty(1, mode); 60: exit(); 61: } 62: 63: int tab[]{ 64: 'A', /* alpha */ 65: 'B', /* beta */ 66: 'D', /* delta */ 67: 'W', /* DELTA */ 68: 'S', /* epsilon */ 69: 'N', /* eta */ 70: '\\', /* gamma */ 71: 'G', /* GAMMA */ 72: 'o', /* infinity - not in M37 */ 73: '^', /* integral */ 74: 'L', /* lambda */ 75: 'E', /* LAMBDA */ 76: 'M', /* mu */ 77: '[', /* nabla (del) */ 78: '_', /* not */ 79: '@', /* nu */ 80: 'C', /* omega */ 81: 'Z', /* OMEGA */ 82: ']', /* partial */ 83: 'U', /* phi */ 84: 'F', /* PHI */ 85: 'V', /* psi */ 86: 'H', /* PSI */ 87: 'J', /* pi */ 88: 'P', /* PI */ 89: 'K', /* rho */ 90: 'Y', /* sigma */ 91: 'R', /* SIGMA */ 92: 'I', /* tau */ 93: 'T', /* theta */ 94: 'O', /* THETA */ 95: 'X', /* xi */ 96: 'Q', /* zeta */ 97: 0 98: }; 99: int trans[]{ 100: alpha, 101: beta, 102: delta, 103: DELTA, 104: epsilon, 105: eta, 106: gamma, 107: GAMMA, 108: infinity, 109: integral, 110: lambda, 111: LAMBDA, 112: mu, 113: nabla, 114: not, 115: nu, 116: omega, 117: OMEGA, 118: partial, 119: phi, 120: PHI, 121: psi, 122: PSI, 123: pi, 124: PI, 125: rho, 126: sigma, 127: SIGMA, 128: tau, 129: theta, 130: THETA, 131: xi, 132: zeta, 133: 0 134: }; 135: 136: int alpha[] {LF,'c',RT,RT,'(',LF,0}; 137: int beta[] {'B',LF,LF,DN,DN,'|',RT,RT,UP,UP,0}; 138: int delta[] {'o',UP,UP,'<',DN,DN,0}; 139: int DELTA[] {LF,LF,'/',-3,DN,'-',-4,RT,'-',-3,UP,'\\',LF,LF,0}; 140: int epsilon[] {'<','-',0}; 141: int eta[] {'n',RT,RT,DN,DN,'|',LF,LF,UP,UP,0}; 142: int gamma[] {')',RT,'/',LF,0}; 143: int GAMMA[] {LF,LF,'|',RT,RT,-3,UP,'-',-3,DN,RT,RT,'`',LF,LF,0}; 144: int infinity[] {LF,LF,'c',-4,RT,'o',LF,LF,0}; 145: int integral[] {'|','\'',RT,RT,'`',-3,LF,-6,DN,'\'',LF,'`',RT,RT,-6,UP,0}; 146: int lambda[] {'\\',-4,DN,LF,'\'',DN,LF,'\'',-5,UP,RT,RT,0}; 147: int LAMBDA[] {LF,LF,'/',-4,RT,'\\',LF,LF,0}; 148: int mu[] {'u',LF,LF,',',RT,RT,0}; 149: int nabla[] {LF,LF,'\\',-3,UP,'-',-4,RT,'-',-3,DN,'/',LF,LF,0}; 150: int not[] {'-',-2,RT,UP,',',DN,-2,LF,0}; 151: int nu[] {LF,'(',-3,RT,'/',LF,LF,0}; 152: int omega[] {LF,'u',-3,RT,'u',LF,LF,0}; 153: int OMEGA[] {'O',DN,DN,LF,'-',RT,RT,'-',LF,UP,UP,0}; 154: int partial[] {'o',RT,DN,'`',LF,UP,'`',LF,UP,'`',RT,DN,0}; 155: int phi[] {'o','/',0}; 156: int PHI[] {'o','[',']',0}; 157: int psi[] {'/','-',DN,DN,RT,RT,'\'',-4,LF,'\'',RT,RT,UP,UP,0}; 158: int PSI[] {'[',']','-',DN,DN,RT,RT,'\'',-4,LF,'`',RT,RT,UP,UP,0}; 159: int pi[] {UP,'-',-3,DN,'"',DN,'"',-3,UP,0}; 160: int PI[] {LF,LF,'[',']',-4,RT,'[',']',LF,LF,-3,UP,'-',-3,DN,0}; 161: int rho[] {'o',LF,LF,DN,DN,'|',UP,UP,RT,RT,0}; 162: int sigma[] {'o',DN,RT,RT,'~',UP,LF,LF,0}; 163: int SIGMA[] {'>',-2,DN,'-',-5,UP,'-',-3,DN,0}; 164: int tau[] {'t',DN,RT,RT,'~',LF,LF,LF,'~',RT,UP,0}; 165: int theta[] {'O','-',0}; 166: int THETA[] {'O','=',0}; 167: int xi[] {'c',RT,DN,',',LF,-3,UP,'c',LF,DN,'`',RT,DN,0}; 168: int zeta[] {'c',RT,DN,',',LF,-3,UP,'<',DN,DN,0}; 169: 170: special(){ 171: int c,i,j,t; 172: loop: 173: if( (c=getchar()) == SI ) 174: return; 175: for( i=0; tab[i]!=0; i++) 176: if( c==tab[i] ){ 177: plot(trans[i]); 178: goto loop; 179: } 180: putchar(c); 181: goto loop; 182: } 183: 184: plot(s) int *s; { 185: int i,c; 186: putchar(PLOT); 187: for( i=0; (c=s[i])!=0; i++ ) 188: if( c<0 ) 189: nplot(-c,s[++i]); 190: else 191: putchar(c); 192: putchar(PLOT); 193: putchar(' '); 194: } 195: 196: nplot(n,c) int n,c; { 197: while(n--) 198: putchar(c); 199: }