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