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 /* from OpenSolaris "shift.c 1.4 05/06/02 SMI" SVr4.0 1.1 */
17
18 /*
19 * Portions Copyright (c) 2005 Gunnar Ritter, Freiburg i. Br., Germany
20 *
21 * Sccsid @(#)shift.c 1.6 (gritter) 1/13/08
22 */
23
24 /*
25 * Changes Copyright (c) 2014 Carsten Kunze (carsten.kunze at arcor.de)
26 */
27
28 #include "e.h"
29 #include "y.tab.h"
30
31 extern YYSTYPE yyval;
32
33 void
bshiftb(int p1,int dir,int p2)34 bshiftb(int p1, int dir, int p2) {
35 #ifndef NEQN
36 float shval, d1, h1, b1, h2, b2;
37 float diffps, effps, effps2;
38 char *sh1, *sh2;
39 #else /* NEQN */
40 int shval, d1, h1, b1, h2, b2;
41 #endif /* NEQN */
42
43 yyval.token = p1;
44 h1 = eht[p1];
45 b1 = ebase[p1];
46 h2 = eht[p2];
47 b2 = ebase[p2];
48 #ifndef NEQN
49 effps = EFFPS(ps);
50 effps2 = EFFPS(ps+deltaps);
51 diffps = deltaps;
52 sh1 = sh2 = "";
53 #endif /* NEQN */
54 if( dir == SUB ) { /* subscript */
55 #ifndef NEQN
56 /* top 1/2m above bottom of main box */
57 d1 = VERT(EM(0.5, effps2));
58 #else /* NEQN */
59 d1 = VERT(1);
60 #endif /* NEQN */
61 shval = - d1 + h2 - b2;
62 if( d1+b1 > h2 ) /* move little sub down */
63 shval = b1-b2;
64 ebase[yyval.token] = b1 + max(0, h2-b1-d1);
65 eht[yyval.token] = h1 + max(0, h2-b1-d1);
66 #ifndef NEQN
67 if (ital(rfont[p1]) && rom(lfont[p2]))
68 sh1 = "\\|";
69 if (ital(rfont[p2]))
70 sh2 = "\\|";
71 #endif /* NEQN */
72 } else { /* superscript */
73 #ifndef NEQN
74 /* 4/10 up main box */
75 d1 = VERT(EM(0.2, effps));
76 #else /* NEQN */
77 d1 = VERT(1);
78 #endif /* NEQN */
79 ebase[yyval.token] = b1;
80 #ifndef NEQN
81 shval = -VERT( (4 * (h1-b1)) / 10 ) - b2;
82 if( VERT(4*(h1-b1)/10) + h2 < h1-b1 ) /* raise little super */
83 #else /* NEQN */
84 shval = -VERT(1) - b2;
85 if( VERT(1) + h2 < h1-b1 ) /* raise little super */
86 #endif /* NEQN */
87 shval = -(h1-b1) + h2-b2 - d1;
88 #ifndef NEQN
89 eht[yyval.token] = h1 + max(0, h2-VERT((6*(h1-b1))/10));
90 if (ital(rfont[p1]))
91 sh1 = "\\|";
92 if (ital(rfont[p2]))
93 sh2 = "\\|";
94 #else /* NEQN */
95 eht[yyval.token] = h1 + max(0, h2 - VERT(1));
96 #endif /* NEQN */
97 }
98 #ifndef NEQN
99 if(dbg)printf(".\tb:b shift b: S%d <- S%d vert %g S%d vert %g; b=%g, h=%g\n",
100 yyval.token, p1, shval, p2, -shval, ebase[yyval.token], eht[yyval.token]);
101 printf(".as %d \\v'%gp'\\s-%s%s\\*(%d\\s+%s%s\\v'%gp'\n",
102 yyval.token, shval, tsize(diffps), sh1, p2, tsize(diffps), sh2, -shval);
103 ps += deltaps;
104 if (ital(rfont[p2]))
105 rfont[p1] = 0;
106 else
107 rfont[p1] = rfont[p2];
108 #else /* NEQN */
109 if(dbg)printf(".\tb:b shift b: S%d <- S%d vert %d S%d vert %d; b=%d, h=%d\n",
110 yyval.token, p1, shval, p2, -shval, ebase[yyval.token], eht[yyval.token]);
111 printf(".as %d \\v'%du'\\*(%d\\v'%du'\n",
112 yyval.token, shval, p2, -shval);
113 #endif /* NEQN */
114 ofree(p2);
115 }
116
117 void
shift(int p1)118 shift(int p1) {
119 ps -= deltaps;
120 yyval.token = p1;
121 if(dbg)printf(".\tshift: %d;ps=%g\n", yyval.token, ps);
122 }
123
124 void
shift2(int p1,int p2,int p3)125 shift2(int p1, int p2, int p3) {
126 int effps, treg;
127 #ifndef NEQN
128 float h1, h2, h3, b1, b2, b3, subsh, d1, d2, supsh;
129 int effps2;
130 #else /* NEQN */
131 int h1, h2, h3, b1, b2, b3, subsh, d1, d2, supsh;
132 #endif /* NEQN */
133
134 treg = oalloc();
135 yyval.token = p1;
136 if(dbg)printf(".\tshift2 s%d <- %d %d %d\n", yyval.token, p1, p2, p3);
137 effps = EFFPS(ps+deltaps);
138 #ifndef NEQN
139 eht[p3] = h3 = VERT( (eht[p3] * effps) / EFFPS(ps) );
140 ps += deltaps;
141 effps2 = EFFPS(ps+deltaps);
142 #endif /* NEQN */
143 h1 = eht[p1]; b1 = ebase[p1];
144 h2 = eht[p2]; b2 = ebase[p2];
145 #ifndef NEQN
146 b3 = ebase[p3];
147 d1 = VERT(EM(0.5, effps2));
148 #else /* NEQN */
149 h3 = eht[p3]; b3 = ebase[p3];
150 d1 = VERT(1);
151 #endif /* NEQN */
152 subsh = -d1+h2-b2;
153 if( d1+b1 > h2 ) /* move little sub down */
154 subsh = b1-b2;
155 #ifndef NEQN
156 supsh = -VERT( (4*(h1-b1))/10 ) - b3;
157 d2 = VERT(EM(0.2, effps));
158 if( VERT(4*(h1-b1)/10)+h3 < h1-b1 )
159 #else /* NEQN */
160 supsh = - VERT(1) - b3;
161 d2 = VERT(1);
162 if( VERT(1)+h3 < h1-b1 )
163 #endif /* NEQN */
164 supsh = -(h1-b1) + (h3-b3) - d2;
165 #ifndef NEQN
166 eht[yyval.token] = h1 + max(0, h3-VERT( (6*(h1-b1))/10 )) + max(0, h2-b1-d1);
167 #else /* NEQN */
168 eht[yyval.token] = h1 + max(0, h3-VERT(1)) + max(0, h2-b1-d1);
169 #endif /* NEQN */
170 ebase[yyval.token] = b1+max(0, h2-b1-d1);
171 #ifndef NEQN
172 if (ital(rfont[p1]) && rom(lfont[p2]))
173 printf(".ds %d \\|\\*(%d\n", p2, p2);
174 if (ital(rfont[p2]))
175 printf(".as %d \\|\n", p2);
176 #endif /* NEQN */
177 nrwid(p2, effps, p2);
178 #ifndef NEQN
179 if (ital(rfont[p1]) && rom(lfont[p3]))
180 printf(".ds %d \\|\\|\\*(%d\n", p3, p3);
181 else
182 printf(".ds %d \\|\\*(%d\n", p3, p3);
183 #endif /* NEQN */
184 nrwid(p3, effps, p3);
185 printf(".nr %d \\n(%d\n", treg, p3);
186 printf(".if \\n(%d>\\n(%d .nr %d \\n(%d\n", p2, treg, treg, p2);
187 #ifndef NEQN
188 printf(".as %d \\v'%gp'\\s%s\\*(%d\\h'-\\n(%du'\\v'%gp'\\\n",
189 p1, subsh, tsize(effps), p2, p2, -subsh+supsh);
190 printf("\\s%s\\*(%d\\h'-\\n(%du+\\n(%du'\\s%s\\v'%gp'\n",
191 tsize(effps), p3, p3, treg, tsize(effps2), -supsh);
192 #else /* NEQN */
193 printf(".as %d \\v'%du'\\*(%d\\h'-\\n(%du'\\v'%du'\\\n",
194 p1, subsh, p2, p2, -subsh+supsh);
195 printf("\\*(%d\\h'-\\n(%du+\\n(%du'\\v'%du'\n",
196 p3, p3, treg, -supsh);
197 #endif /* NEQN */
198 ps += deltaps;
199 #ifndef NEQN
200 if (ital(rfont[p2]))
201 rfont[yyval.token] = 0; /* lie */
202 #endif /* NEQN */
203 ofree(p2); ofree(p3); ofree(treg);
204 }
205