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