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