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