xref: /onnv-gate/usr/src/cmd/eqn/shift.c (revision 364:f36290b8cb0b)
1*364Sceastha /*
2*364Sceastha  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
3*364Sceastha  * Use is subject to license terms.
4*364Sceastha  */
5*364Sceastha 
60Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
70Sstevel@tonic-gate /*	  All Rights Reserved  	*/
80Sstevel@tonic-gate 
90Sstevel@tonic-gate /*
100Sstevel@tonic-gate  * Copyright (c) 1980 Regents of the University of California.
110Sstevel@tonic-gate  * All rights reserved. The Berkeley software License Agreement
120Sstevel@tonic-gate  * specifies the terms and conditions for redistribution.
130Sstevel@tonic-gate  */
140Sstevel@tonic-gate 
15*364Sceastha #pragma ident	"%Z%%M%	%I%	%E% SMI"
16*364Sceastha 
17*364Sceastha #include "e.h"
180Sstevel@tonic-gate #include "e.def"
190Sstevel@tonic-gate 
20*364Sceastha void
bshiftb(int p1,int dir,int p2)21*364Sceastha bshiftb(int p1, int dir, int p2)
22*364Sceastha {
230Sstevel@tonic-gate 	int shval, d1, h1, b1, h2, b2;
240Sstevel@tonic-gate #ifndef NEQN
250Sstevel@tonic-gate 	int diffps, effps, effps2;
260Sstevel@tonic-gate 	char *sh1, *sh2;
27*364Sceastha #endif	/* NEQN */
280Sstevel@tonic-gate 
290Sstevel@tonic-gate 	yyval = p1;
300Sstevel@tonic-gate 	h1 = eht[p1];
310Sstevel@tonic-gate 	b1 = ebase[p1];
320Sstevel@tonic-gate 	h2 = eht[p2];
330Sstevel@tonic-gate 	b2 = ebase[p2];
340Sstevel@tonic-gate #ifndef NEQN
350Sstevel@tonic-gate 	effps = EFFPS(ps);
360Sstevel@tonic-gate 	effps2 = EFFPS(ps+deltaps);
370Sstevel@tonic-gate 	diffps = deltaps;
380Sstevel@tonic-gate 	sh1 = sh2 = "";
39*364Sceastha #endif	/* NEQN */
40*364Sceastha 	if (dir == SUB) {	/* subscript */
410Sstevel@tonic-gate #ifndef NEQN
420Sstevel@tonic-gate 		/* top 1/2m above bottom of main box */
430Sstevel@tonic-gate 		d1 = VERT(EM(0.5, effps2));
44*364Sceastha #else	/* NEQN */
450Sstevel@tonic-gate 		d1 = VERT(1);
46*364Sceastha #endif	/* NEQN */
470Sstevel@tonic-gate 		shval = - d1 + h2 - b2;
48*364Sceastha 		if (d1+b1 > h2) /* move little sub down */
490Sstevel@tonic-gate 			shval = b1-b2;
500Sstevel@tonic-gate 		ebase[yyval] = b1 + max(0, h2-b1-d1);
510Sstevel@tonic-gate 		eht[yyval] = h1 + max(0, h2-b1-d1);
520Sstevel@tonic-gate #ifndef NEQN
530Sstevel@tonic-gate 		if (rfont[p1] == ITAL && lfont[p2] == ROM)
540Sstevel@tonic-gate 			sh1 = "\\|";
550Sstevel@tonic-gate 		if (rfont[p2] == ITAL)
560Sstevel@tonic-gate 			sh2 = "\\|";
57*364Sceastha #endif	/* NEQN */
580Sstevel@tonic-gate 	} else {	/* superscript */
590Sstevel@tonic-gate #ifndef NEQN
600Sstevel@tonic-gate 		/* 4/10 up main box */
610Sstevel@tonic-gate 		d1 = VERT(EM(0.2, effps));
62*364Sceastha #else	/* NEQN */
630Sstevel@tonic-gate 		d1 = VERT(1);
64*364Sceastha #endif	/* NEQN */
650Sstevel@tonic-gate 		ebase[yyval] = b1;
660Sstevel@tonic-gate #ifndef NEQN
67*364Sceastha 		shval = -VERT((4 * (h1-b1)) / 10) - b2;
68*364Sceastha 		if (VERT(4*(h1-b1)/10) + h2 < h1-b1)	/* raise little super */
69*364Sceastha #else	/* NEQN */
700Sstevel@tonic-gate 		shval = -VERT(1) - b2;
71*364Sceastha 		if (VERT(1) + h2 < h1-b1)	/* raise little super */
72*364Sceastha #endif	/* NEQN */
730Sstevel@tonic-gate 			shval = -(h1-b1) + h2-b2 - d1;
740Sstevel@tonic-gate #ifndef NEQN
750Sstevel@tonic-gate 		eht[yyval] = h1 + max(0, h2-VERT((6*(h1-b1))/10));
760Sstevel@tonic-gate 		if (rfont[p1] == ITAL)
770Sstevel@tonic-gate 			sh1 = "\\|";
780Sstevel@tonic-gate 		if (rfont[p2] == ITAL)
790Sstevel@tonic-gate 			sh2 = "\\|";
80*364Sceastha #else	/* NEQN */
810Sstevel@tonic-gate 		eht[yyval] = h1 + max(0, h2 - VERT(1));
82*364Sceastha #endif	/* NEQN */
830Sstevel@tonic-gate 	}
84*364Sceastha 	if (dbg)
85*364Sceastha 		printf(".\tb:b shift b: S%d <- S%d vert %d S%d vert %d; "
86*364Sceastha 		    "b=%d, h=%d\n", yyval, p1, shval, p2, -shval,
87*364Sceastha 		    ebase[yyval], eht[yyval]);
880Sstevel@tonic-gate #ifndef NEQN
89*364Sceastha 	printf(".as %d \\v'%du'\\s-%d%s\\*(%d\\s+%d%s\\v'%du'\n",
90*364Sceastha 	    yyval, shval, diffps, sh1, p2, diffps, sh2, -shval);
910Sstevel@tonic-gate 	ps += deltaps;
920Sstevel@tonic-gate 	if (rfont[p2] == ITAL)
930Sstevel@tonic-gate 		rfont[p1] = 0;
940Sstevel@tonic-gate 	else
950Sstevel@tonic-gate 		rfont[p1] = rfont[p2];
96*364Sceastha #else	/* NEQN */
97*364Sceastha 	printf(".as %d \\v'%du'\\*(%d\\v'%du'\n",
98*364Sceastha 	    yyval, shval, p2, -shval);
99*364Sceastha #endif	/* NEQN */
1000Sstevel@tonic-gate 	ofree(p2);
1010Sstevel@tonic-gate }
1020Sstevel@tonic-gate 
103*364Sceastha void
shift(int p1)104*364Sceastha shift(int p1)
105*364Sceastha {
1060Sstevel@tonic-gate 	ps -= deltaps;
1070Sstevel@tonic-gate 	yyval = p1;
108*364Sceastha 	if (dbg) printf(".\tshift: %d;ps=%d\n", yyval, ps);
1090Sstevel@tonic-gate }
1100Sstevel@tonic-gate 
111*364Sceastha void
shift2(int p1,int p2,int p3)112*364Sceastha shift2(int p1, int p2, int p3)
113*364Sceastha {
1140Sstevel@tonic-gate 	int effps, h1, h2, h3, b1, b2, b3, subsh, d1, d2, supsh, treg;
1150Sstevel@tonic-gate #ifndef NEQN
1160Sstevel@tonic-gate 	int effps2;
117*364Sceastha #endif	/* NEQN */
1180Sstevel@tonic-gate 
1190Sstevel@tonic-gate 	treg = oalloc();
1200Sstevel@tonic-gate 	yyval = p1;
121*364Sceastha 	if (dbg) printf(".\tshift2 s%d <- %d %d %d\n", yyval, p1, p2, p3);
1220Sstevel@tonic-gate 	effps = EFFPS(ps+deltaps);
1230Sstevel@tonic-gate #ifndef NEQN
124*364Sceastha 	eht[p3] = h3 = VERT((eht[p3] * effps) / EFFPS(ps));
1250Sstevel@tonic-gate 	ps += deltaps;
1260Sstevel@tonic-gate 	effps2 = EFFPS(ps+deltaps);
127*364Sceastha #endif	/* NEQN */
1280Sstevel@tonic-gate 	h1 = eht[p1]; b1 = ebase[p1];
1290Sstevel@tonic-gate 	h2 = eht[p2]; b2 = ebase[p2];
1300Sstevel@tonic-gate #ifndef NEQN
1310Sstevel@tonic-gate 	b3 = ebase[p3];
1320Sstevel@tonic-gate 	d1 = VERT(EM(0.5, effps2));
133*364Sceastha #else	/* NEQN */
1340Sstevel@tonic-gate 	h3 = eht[p3]; b3 = ebase[p3];
1350Sstevel@tonic-gate 	d1 = VERT(1);
136*364Sceastha #endif	/* NEQN */
1370Sstevel@tonic-gate 	subsh = -d1+h2-b2;
138*364Sceastha 	if (d1+b1 > h2) /* move little sub down */
1390Sstevel@tonic-gate 		subsh = b1-b2;
1400Sstevel@tonic-gate #ifndef NEQN
141*364Sceastha 	supsh = -VERT((4*(h1-b1))/10) - b3;
1420Sstevel@tonic-gate 	d2 = VERT(EM(0.2, effps));
143*364Sceastha 	if (VERT(4*(h1-b1)/10)+h3 < h1-b1)
144*364Sceastha #else	/* NEQN */
1450Sstevel@tonic-gate 	supsh = - VERT(1) - b3;
1460Sstevel@tonic-gate 	d2 = VERT(1);
147*364Sceastha 	if (VERT(1)+h3 < h1-b1)
148*364Sceastha #endif	/* NEQN */
1490Sstevel@tonic-gate 		supsh = -(h1-b1) + (h3-b3) - d2;
1500Sstevel@tonic-gate #ifndef NEQN
151*364Sceastha 	eht[yyval] = h1 + max(0, h3-VERT((6*(h1-b1))/10)) + max(0, h2-b1-d1);
152*364Sceastha #else	/* NEQN */
1530Sstevel@tonic-gate 	eht[yyval] = h1 + max(0, h3-VERT(1)) + max(0, h2-b1-d1);
154*364Sceastha #endif	/* NEQN */
1550Sstevel@tonic-gate 	ebase[yyval] = b1+max(0, h2-b1-d1);
1560Sstevel@tonic-gate #ifndef NEQN
1570Sstevel@tonic-gate 	if (rfont[p1] == ITAL && lfont[p2] == ROM)
1580Sstevel@tonic-gate 		printf(".ds %d \\|\\*(%d\n", p2, p2);
1590Sstevel@tonic-gate 	if (rfont[p2] == ITAL)
1600Sstevel@tonic-gate 		printf(".as %d \\|\n", p2);
161*364Sceastha #endif	/* NEQN */
1620Sstevel@tonic-gate 	nrwid(p2, effps, p2);
1630Sstevel@tonic-gate #ifndef NEQN
1640Sstevel@tonic-gate 	if (rfont[p1] == ITAL && lfont[p3] == ROM)
1650Sstevel@tonic-gate 		printf(".ds %d \\|\\|\\*(%d\n", p3, p3);
1660Sstevel@tonic-gate 	else
1670Sstevel@tonic-gate 		printf(".ds %d \\|\\*(%d\n", p3, p3);
168*364Sceastha #endif	/* NEQN */
1690Sstevel@tonic-gate 	nrwid(p3, effps, p3);
1700Sstevel@tonic-gate 	printf(".nr %d \\n(%d\n", treg, p3);
1710Sstevel@tonic-gate 	printf(".if \\n(%d>\\n(%d .nr %d \\n(%d\n", p2, treg, treg, p2);
1720Sstevel@tonic-gate #ifndef NEQN
173*364Sceastha 	printf(".as %d \\v'%du'\\s%d\\*(%d\\h'-\\n(%du'\\v'%du'\\\n",
174*364Sceastha 	    p1, subsh, effps, p2, p2, -subsh+supsh);
175*364Sceastha 	printf("\\s%d\\*(%d\\h'-\\n(%du+\\n(%du'\\s%d\\v'%du'\n",
176*364Sceastha 	    effps, p3, p3, treg, effps2, -supsh);
177*364Sceastha #else	/* NEQN */
178*364Sceastha 	printf(".as %d \\v'%du'\\*(%d\\h'-\\n(%du'\\v'%du'\\\n",
179*364Sceastha 	    p1, subsh, p2, p2, -subsh+supsh);
180*364Sceastha 	printf("\\*(%d\\h'-\\n(%du+\\n(%du'\\v'%du'\n",
181*364Sceastha 	    p3, p3, treg, -supsh);
182*364Sceastha #endif	/* NEQN */
1830Sstevel@tonic-gate 	ps += deltaps;
1840Sstevel@tonic-gate #ifndef NEQN
1850Sstevel@tonic-gate 	if (rfont[p2] == ITAL)
1860Sstevel@tonic-gate 		rfont[yyval] = 0;	/* lie */
187*364Sceastha #endif	/* NEQN */
1880Sstevel@tonic-gate 	ofree(p2); ofree(p3); ofree(treg);
1890Sstevel@tonic-gate }
190