1 /* shift.c 4.2 83/02/12 */ 2 3 # include "e.h" 4 #include "e.def" 5 6 bshiftb(p1, dir, p2) int p1, dir, p2; { 7 int shval, d1, h1, b1, h2, b2; 8 #ifndef NEQN 9 int diffps, effps, effps2; 10 char *sh1, *sh2; 11 #endif NEQN 12 13 yyval = p1; 14 h1 = eht[p1]; 15 b1 = ebase[p1]; 16 h2 = eht[p2]; 17 b2 = ebase[p2]; 18 #ifndef NEQN 19 effps = EFFPS(ps); 20 effps2 = EFFPS(ps+deltaps); 21 diffps = deltaps; 22 sh1 = sh2 = ""; 23 #endif NEQN 24 if( dir == SUB ) { /* subscript */ 25 #ifndef NEQN 26 /* top 1/2m above bottom of main box */ 27 d1 = VERT( (effps2*6)/2 ); 28 #else NEQN 29 d1 = VERT(1); 30 #endif NEQN 31 shval = - d1 + h2 - b2; 32 if( d1+b1 > h2 ) /* move little sub down */ 33 shval = b1-b2; 34 ebase[yyval] = b1 + max(0, h2-b1-d1); 35 eht[yyval] = h1 + max(0, h2-b1-d1); 36 #ifndef NEQN 37 if (rfont[p1] == ITAL && lfont[p2] == ROM) 38 sh1 = "\\|"; 39 if (rfont[p2] == ITAL) 40 sh2 = "\\|"; 41 #endif NEQN 42 } else { /* superscript */ 43 #ifndef NEQN 44 /* 4/10 up main box */ 45 d1 = VERT( (effps*6*2)/10 ); 46 #else NEQN 47 d1 = VERT(1); 48 #endif NEQN 49 ebase[yyval] = b1; 50 #ifndef NEQN 51 shval = -VERT( (4 * (h1-b1)) / 10 ) - b2; 52 if( VERT(4*(h1-b1)/10) + h2 < h1-b1 ) /* raise little super */ 53 #else NEQN 54 shval = -VERT(1) - b2; 55 if( VERT(1) + h2 < h1-b1 ) /* raise little super */ 56 #endif NEQN 57 shval = -(h1-b1) + h2-b2 - d1; 58 #ifndef NEQN 59 eht[yyval] = h1 + max(0, h2-VERT((6*(h1-b1))/10)); 60 if (rfont[p1] == ITAL) 61 sh1 = "\\|"; 62 if (rfont[p2] == ITAL) 63 sh2 = "\\|"; 64 #else NEQN 65 eht[yyval] = h1 + max(0, h2 - VERT(1)); 66 #endif NEQN 67 } 68 if(dbg)printf(".\tb:b shift b: S%d <- S%d vert %d S%d vert %d; b=%d, h=%d\n", 69 yyval, p1, shval, p2, -shval, ebase[yyval], eht[yyval]); 70 #ifndef NEQN 71 printf(".as %d \\v'%du'\\s-%d%s\\*(%d\\s+%d%s\\v'%du'\n", 72 yyval, shval, diffps, sh1, p2, diffps, sh2, -shval); 73 ps += deltaps; 74 if (rfont[p2] == ITAL) 75 rfont[p1] = 0; 76 else 77 rfont[p1] = rfont[p2]; 78 #else NEQN 79 printf(".as %d \\v'%du'\\*(%d\\v'%du'\n", 80 yyval, shval, p2, -shval); 81 #endif NEQN 82 ofree(p2); 83 } 84 85 shift(p1) int p1; { 86 ps -= deltaps; 87 yyval = p1; 88 if(dbg)printf(".\tshift: %d;ps=%d\n", yyval, ps); 89 } 90 91 shift2(p1, p2, p3) int p1, p2, p3; { 92 int effps, h1, h2, h3, b1, b2, b3, subsh, d1, d2, supsh, treg; 93 #ifndef NEQN 94 int effps2; 95 #endif NEQN 96 97 treg = oalloc(); 98 yyval = p1; 99 if(dbg)printf(".\tshift2 s%d <- %d %d %d\n", yyval, p1, p2, p3); 100 effps = EFFPS(ps+deltaps); 101 #ifndef NEQN 102 eht[p3] = h3 = VERT( (eht[p3] * effps) / EFFPS(ps) ); 103 ps += deltaps; 104 effps2 = EFFPS(ps+deltaps); 105 #endif NEQN 106 h1 = eht[p1]; b1 = ebase[p1]; 107 h2 = eht[p2]; b2 = ebase[p2]; 108 #ifndef NEQN 109 b3 = ebase[p3]; 110 d1 = VERT( (effps2*6)/2 ); 111 #else NEQN 112 h3 = eht[p3]; b3 = ebase[p3]; 113 d1 = VERT(1); 114 #endif NEQN 115 subsh = -d1+h2-b2; 116 if( d1+b1 > h2 ) /* move little sub down */ 117 subsh = b1-b2; 118 #ifndef NEQN 119 supsh = -VERT( (4*(h1-b1))/10 ) - b3; 120 d2 = VERT( (effps*6*2)/10 ); 121 if( VERT(4*(h1-b1)/10)+h3 < h1-b1 ) 122 #else NEQN 123 supsh = - VERT(1) - b3; 124 d2 = VERT(1); 125 if( VERT(1)+h3 < h1-b1 ) 126 #endif NEQN 127 supsh = -(h1-b1) + (h3-b3) - d2; 128 #ifndef NEQN 129 eht[yyval] = h1 + max(0, h3-VERT( (6*(h1-b1))/10 )) + max(0, h2-b1-d1); 130 #else NEQN 131 eht[yyval] = h1 + max(0, h3-VERT(1)) + max(0, h2-b1-d1); 132 #endif NEQN 133 ebase[yyval] = b1+max(0, h2-b1-d1); 134 #ifndef NEQN 135 if (rfont[p1] == ITAL && lfont[p2] == ROM) 136 printf(".ds %d \\|\\*(%d\n", p2, p2); 137 if (rfont[p2] == ITAL) 138 printf(".as %d \\|\n", p2); 139 #endif NEQN 140 nrwid(p2, effps, p2); 141 #ifndef NEQN 142 if (rfont[p1] == ITAL && lfont[p3] == ROM) 143 printf(".ds %d \\|\\|\\*(%d\n", p3, p3); 144 else 145 printf(".ds %d \\|\\*(%d\n", p3, p3); 146 #endif NEQN 147 nrwid(p3, effps, p3); 148 printf(".nr %d \\n(%d\n", treg, p3); 149 printf(".if \\n(%d>\\n(%d .nr %d \\n(%d\n", p2, treg, treg, p2); 150 #ifndef NEQN 151 printf(".as %d \\v'%du'\\s%d\\*(%d\\h'-\\n(%du'\\v'%du'\\\n", 152 p1, subsh, effps, p2, p2, -subsh+supsh); 153 printf("\\s%d\\*(%d\\h'-\\n(%du+\\n(%du'\\s%d\\v'%du'\n", 154 effps, p3, p3, treg, effps2, -supsh); 155 #else NEQN 156 printf(".as %d \\v'%du'\\*(%d\\h'-\\n(%du'\\v'%du'\\\n", 157 p1, subsh, p2, p2, -subsh+supsh); 158 printf("\\*(%d\\h'-\\n(%du+\\n(%du'\\v'%du'\n", 159 p3, p3, treg, -supsh); 160 #endif NEQN 161 ps += deltaps; 162 #ifndef NEQN 163 if (rfont[p2] == ITAL) 164 rfont[yyval] = 0; /* lie */ 165 #endif NEQN 166 ofree(p2); ofree(p3); ofree(treg); 167 } 168