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