1: # include "ne.h" 2: 3: boverb(p1,p2) int p1,p2; { 4: int h,b,w,treg; 5: yyval = oalloc(); 6: eht[yyval] = eht[p1] + eht[p2] ; 7: ebase[yyval] = eht[p2] - 1; 8: ewid[yyval] = w = max(ewid[p1],ewid[p2]); 9: if(dbg)printf(".\tb:bob: S%d <- S%d over S%d; b=%d,h=%d,w=%d\n", 10: yyval, p1, p2, ebase[yyval], eht[yyval], ewid[yyval]); 11: printf(".ds %d ", yyval); 12: down(eht[p2]-ebase[p2]-1); 13: fwd((ewid[yyval]-ewid[p2])/2); 14: printf("\\*(%d", p2); 15: back((ewid[yyval]+ewid[p2])/2); 16: up(eht[p2]-ebase[p2]+ebase[p1]); 17: fwd((ewid[yyval]-ewid[p1])/2); 18: printf("\\*(%d", p1); 19: back((ewid[yyval]+ewid[p1])/2); 20: down(ebase[p1]); 21: line(ewid[yyval]); 22: down(1); 23: putchar('\n'); 24: ofree(p1); 25: ofree(p2); 26: } 27: 28: bshiftb(p1,dir,p2) int p1,dir,p2; { 29: int shval, d1, h1, b1,h2,b2; 30: yyval = oalloc(); 31: ewid[yyval] = ewid[p1] + ewid[p2]; 32: h1 = eht[p1]; b1 = ebase[p1]; 33: h2 = eht[p2]; b2 = ebase[p2]; 34: printf(".ds %d \"\\*(%d", yyval, p1); 35: if( dir > 0 ){ /* subscript */ 36: shval = h2-b2-1; 37: if( shval < b1 ) 38: shval = b1; 39: down(shval); 40: printf("\\*(%d", p2); 41: up(shval); 42: ebase[yyval] = max(b1, h2-1); 43: eht[yyval] = h1 + max(0,h2-b1-1); 44: } else { /* superscript */ 45: ebase[yyval] = b1; 46: shval = b2+1; 47: if( shval+h2 < h1-b1 ) 48: shval = h1-b1-h2; 49: up(shval); 50: printf("\\*(%d", p2); 51: down(shval); 52: eht[yyval] = max(h1, b1+1+h2); 53: } 54: putchar('\n'); 55: if(dbg)printf(".\tb:b shift b: S%d <- S%d vert %d S%d vert %d; b=%d,h=%d,w=%d\n", 56: yyval,p1,shval,p2,-shval,ebase[yyval],eht[yyval],ewid[yyval]); 57: ofree(p1); 58: ofree(p2); 59: } 60: 61: eqnbox(p1,p2) int p1,p2; { 62: int b,h; 63: if( p1==0 ){ 64: yyval = p2; return; 65: } 66: yyval = oalloc(); 67: b = max(ebase[p1], ebase[p2]); 68: eht[yyval] = h = b + max(eht[p1]-ebase[p1], 69: eht[p2]-ebase[p2]); 70: ebase[yyval] = b; 71: ewid[yyval] = ewid[p1] + ewid[p2]; 72: if(dbg)printf(".\te:eb: S%d <- S%d S%d; b=%d,h=%d,w=%d\n", 73: yyval,p1,p2,b,h,ewid[yyval]); 74: printf(".ds %d \\*(%d\\*(%d\n", yyval, p1, p2); 75: ofree(p1); 76: ofree(p2); 77: } 78: 79: size(p1,p2) int p1,p2; { 80: yyval = p2; 81: } 82: 83: numb(p1) char *p1; { 84: int i, n, c; 85: for(i=n=0; (c=p1[i++])!='\0'; ) 86: if( c>='0' && c<='9' ) 87: n = n*10 + c-'0'; 88: if(dbg)printf(".\tnumb: %s %d\n",p1,n); 89: return( n ); 90: } 91: 92: font(p1,p2) int p1,p2; { 93: yyval = p2; 94: } 95: 96: shift(p1) int p1; { 97: yyval = p1; 98: if(dbg)printf(".\tshift: %d\n",yyval); 99: } 100: 101: sqrt(p2) int p2; { 102: int nps, h, i; 103: yyval = oalloc(); 104: h = eht[p2]; 105: eht[yyval] = h+1; 106: nps = h-1; 107: ebase[yyval] = ebase[p2]; 108: ewid[yyval] = ewid[p2] + 2; 109: if(dbg)printf(".\tsqrt: S%d <- S%d;b=%d,h=%d,w=%d\n", 110: yyval,p2,ebase[yyval],eht[yyval],ewid[yyval]); 111: printf(".ds %d \\e|", yyval); 112: for( i=2; i<=nps; i++ ){ 113: back(1); 114: up(1); 115: putchar('|'); 116: } 117: up(2); 118: line(ewid[p2]); 119: back(ewid[p2]); 120: down(h); 121: printf("\\*(%d\n", p2); 122: ofree(p2); 123: } 124: 125: lpile(type,p1,p2) int type,p1,p2; { 126: int w,bi,hi,i,gap,h,b,j, nlist, nlist2, mid; 127: yyval = oalloc(); 128: gap = type == '-' ? 0 : 1; 129: nlist = p2 - p1; 130: nlist2 = (nlist+1)/2; 131: mid = p1 + nlist2 -1; 132: h = b = w = 0; 133: for( i=p1; i<p2; i++ ){ 134: h =+ eht[lp[i]]; 135: w = max(w, ewid[lp[i]]); 136: } 137: eht[yyval] = h + (nlist-1)*gap; 138: ewid[yyval] = w; 139: for( i=p2-1; i>mid; i-- ) 140: b =+ eht[lp[i]] + gap; 141: ebase[yyval] = (nlist%2) ? b + ebase[lp[mid]] : b - gap -1; 142: if(dbg){ 143: printf(".\tS%d <- %c pile of:", yyval, type); 144: for( i=p1; i<p2; i++) 145: printf(" S%d", lp[i]); 146: printf(";h=%d b=%d,w=%d\n",eht[yyval],ebase[yyval],ewid[yyval]); 147: } 148: printf(".ds %d \\\n", yyval); 149: down(ebase[yyval]); 150: if( type=='R' ) 151: fwd(ewid[yyval]); 152: for(i = p2-1; i >=p1; i--){ 153: hi = eht[lp[i]]; 154: bi = ebase[lp[i]]; 155: switch(type){ 156: 157: case 'L': 158: up(bi); 159: printf("\\*(%d", lp[i]); 160: back(ewid[lp[i]]); 161: up(hi-bi+gap); 162: printf("\\\n"); 163: continue; 164: case 'R': 165: up(bi); 166: back(ewid[lp[i]]); 167: printf("\\*(%d", lp[i]); 168: up(hi-bi+gap); 169: printf("\\\n"); 170: continue; 171: case 'C': 172: case '-': 173: up(bi); 174: fwd((ewid[yyval]-ewid[lp[i]])/2); 175: printf("\\*(%d", lp[i]); 176: back((ewid[yyval]+ewid[lp[i]])/2); 177: up(hi-bi+gap); 178: printf("\\\n"); 179: continue; 180: } 181: } 182: down(eht[yyval]-ebase[yyval]+gap); 183: if( type!='R' ) 184: fwd(ewid[yyval]); 185: putchar('\n'); 186: for( i=p1; i<p2; i++ ) ofree(lp[i]); 187: } 188: 189: shift2(p1,p2,p3) int p1,p2,p3;{ 190: int h1,h2,h3,b1,b2,b3,subsh,d1,supsh; 191: yyval = oalloc(); 192: h1 = eht[p1]; b1 = ebase[p1]; 193: h2 = eht[p2]; b2 = ebase[p2]; 194: h3 = eht[p3]; b3 = ebase[p3]; 195: d1 = 1; 196: subsh = -d1+h2-b2; 197: if( d1+b1 > h2 ) 198: subsh = b1-b2; 199: supsh = b3 + 1; 200: if( supsh+h3 < h1-b1 ) 201: supsh = h1-b1-h3; 202: eht[yyval] = h1 + max(0,h3-1) + max(0,h2-b1-d1); 203: ebase[yyval] = b1+max(0,h2-b1-d1); 204: ewid[yyval] = ewid[p1] + max(ewid[p2], ewid[p3]); 205: printf(".ds %d \\*(%d", yyval, p1); 206: down(subsh); 207: printf("\\*(%d", p2); 208: back(ewid[p2]); 209: up(subsh+supsh); 210: printf("\\*(%d", p3); 211: down(supsh); 212: if(ewid[p3] < ewid[p2] ) 213: fwd(ewid[p2]-ewid[p3]); 214: putchar('\n'); 215: if(dbg)printf(".\tshift2 s%d <- %d %d %d",yyval,p1,p2,p3); 216: if(dbg)printf(" h=%d,b=%d,w=%d\n", eht[yyval],ebase[yyval],ewid[yyval]); 217: ofree(p1); ofree(p2); ofree(p3); 218: }