xref: /titanic_44/usr/src/cmd/eqn/shift.c (revision 779fc935796a940997d18b31d64a9fec9c6b40f6)
1*779fc935Sceastha /*
2*779fc935Sceastha  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
3*779fc935Sceastha  * Use is subject to license terms.
4*779fc935Sceastha  */
5*779fc935Sceastha 
67c478bd9Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
77c478bd9Sstevel@tonic-gate /*	  All Rights Reserved  	*/
87c478bd9Sstevel@tonic-gate 
97c478bd9Sstevel@tonic-gate /*
107c478bd9Sstevel@tonic-gate  * Copyright (c) 1980 Regents of the University of California.
117c478bd9Sstevel@tonic-gate  * All rights reserved. The Berkeley software License Agreement
127c478bd9Sstevel@tonic-gate  * specifies the terms and conditions for redistribution.
137c478bd9Sstevel@tonic-gate  */
147c478bd9Sstevel@tonic-gate 
15*779fc935Sceastha #pragma ident	"%Z%%M%	%I%	%E% SMI"
167c478bd9Sstevel@tonic-gate 
177c478bd9Sstevel@tonic-gate #include "e.h"
187c478bd9Sstevel@tonic-gate #include "e.def"
197c478bd9Sstevel@tonic-gate 
20*779fc935Sceastha void
bshiftb(int p1,int dir,int p2)21*779fc935Sceastha bshiftb(int p1, int dir, int p2)
22*779fc935Sceastha {
237c478bd9Sstevel@tonic-gate 	int shval, d1, h1, b1, h2, b2;
247c478bd9Sstevel@tonic-gate #ifndef NEQN
257c478bd9Sstevel@tonic-gate 	int diffps, effps, effps2;
267c478bd9Sstevel@tonic-gate 	char *sh1, *sh2;
27*779fc935Sceastha #endif	/* NEQN */
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate 	yyval = p1;
307c478bd9Sstevel@tonic-gate 	h1 = eht[p1];
317c478bd9Sstevel@tonic-gate 	b1 = ebase[p1];
327c478bd9Sstevel@tonic-gate 	h2 = eht[p2];
337c478bd9Sstevel@tonic-gate 	b2 = ebase[p2];
347c478bd9Sstevel@tonic-gate #ifndef NEQN
357c478bd9Sstevel@tonic-gate 	effps = EFFPS(ps);
367c478bd9Sstevel@tonic-gate 	effps2 = EFFPS(ps+deltaps);
377c478bd9Sstevel@tonic-gate 	diffps = deltaps;
387c478bd9Sstevel@tonic-gate 	sh1 = sh2 = "";
39*779fc935Sceastha #endif	/* NEQN */
407c478bd9Sstevel@tonic-gate 	if (dir == SUB) {	/* subscript */
417c478bd9Sstevel@tonic-gate #ifndef NEQN
427c478bd9Sstevel@tonic-gate 		/* top 1/2m above bottom of main box */
437c478bd9Sstevel@tonic-gate 		d1 = VERT(EM(0.5, effps2));
44*779fc935Sceastha #else	/* NEQN */
457c478bd9Sstevel@tonic-gate 		d1 = VERT(1);
46*779fc935Sceastha #endif	/* NEQN */
477c478bd9Sstevel@tonic-gate 		shval = - d1 + h2 - b2;
487c478bd9Sstevel@tonic-gate 		if (d1+b1 > h2) /* move little sub down */
497c478bd9Sstevel@tonic-gate 			shval = b1-b2;
507c478bd9Sstevel@tonic-gate 		ebase[yyval] = b1 + max(0, h2-b1-d1);
517c478bd9Sstevel@tonic-gate 		eht[yyval] = h1 + max(0, h2-b1-d1);
527c478bd9Sstevel@tonic-gate #ifndef NEQN
537c478bd9Sstevel@tonic-gate 		if (rfont[p1] == ITAL && lfont[p2] == ROM)
547c478bd9Sstevel@tonic-gate 			sh1 = "\\|";
557c478bd9Sstevel@tonic-gate 		if (rfont[p2] == ITAL)
567c478bd9Sstevel@tonic-gate 			sh2 = "\\|";
57*779fc935Sceastha #endif	/* NEQN */
587c478bd9Sstevel@tonic-gate 	} else {	/* superscript */
597c478bd9Sstevel@tonic-gate #ifndef NEQN
607c478bd9Sstevel@tonic-gate 		/* 4/10 up main box */
617c478bd9Sstevel@tonic-gate 		d1 = VERT(EM(0.2, effps));
62*779fc935Sceastha #else	/* NEQN */
637c478bd9Sstevel@tonic-gate 		d1 = VERT(1);
64*779fc935Sceastha #endif	/* NEQN */
657c478bd9Sstevel@tonic-gate 		ebase[yyval] = b1;
667c478bd9Sstevel@tonic-gate #ifndef NEQN
677c478bd9Sstevel@tonic-gate 		shval = -VERT((4 * (h1-b1)) / 10) - b2;
687c478bd9Sstevel@tonic-gate 		if (VERT(4*(h1-b1)/10) + h2 < h1-b1)	/* raise little super */
69*779fc935Sceastha #else	/* NEQN */
707c478bd9Sstevel@tonic-gate 		shval = -VERT(1) - b2;
717c478bd9Sstevel@tonic-gate 		if (VERT(1) + h2 < h1-b1)	/* raise little super */
72*779fc935Sceastha #endif	/* NEQN */
737c478bd9Sstevel@tonic-gate 			shval = -(h1-b1) + h2-b2 - d1;
747c478bd9Sstevel@tonic-gate #ifndef NEQN
757c478bd9Sstevel@tonic-gate 		eht[yyval] = h1 + max(0, h2-VERT((6*(h1-b1))/10));
767c478bd9Sstevel@tonic-gate 		if (rfont[p1] == ITAL)
777c478bd9Sstevel@tonic-gate 			sh1 = "\\|";
787c478bd9Sstevel@tonic-gate 		if (rfont[p2] == ITAL)
797c478bd9Sstevel@tonic-gate 			sh2 = "\\|";
80*779fc935Sceastha #else	/* NEQN */
817c478bd9Sstevel@tonic-gate 		eht[yyval] = h1 + max(0, h2 - VERT(1));
82*779fc935Sceastha #endif	/* NEQN */
837c478bd9Sstevel@tonic-gate 	}
84*779fc935Sceastha 	if (dbg)
85*779fc935Sceastha 		printf(".\tb:b shift b: S%d <- S%d vert %d S%d vert %d; "
86*779fc935Sceastha 		    "b=%d, h=%d\n", yyval, p1, shval, p2, -shval,
87*779fc935Sceastha 		    ebase[yyval], eht[yyval]);
887c478bd9Sstevel@tonic-gate #ifndef NEQN
897c478bd9Sstevel@tonic-gate 	printf(".as %d \\v'%du'\\s-%d%s\\*(%d\\s+%d%s\\v'%du'\n",
907c478bd9Sstevel@tonic-gate 	    yyval, shval, diffps, sh1, p2, diffps, sh2, -shval);
917c478bd9Sstevel@tonic-gate 	ps += deltaps;
927c478bd9Sstevel@tonic-gate 	if (rfont[p2] == ITAL)
937c478bd9Sstevel@tonic-gate 		rfont[p1] = 0;
947c478bd9Sstevel@tonic-gate 	else
957c478bd9Sstevel@tonic-gate 		rfont[p1] = rfont[p2];
96*779fc935Sceastha #else	/* NEQN */
977c478bd9Sstevel@tonic-gate 	printf(".as %d \\v'%du'\\*(%d\\v'%du'\n",
987c478bd9Sstevel@tonic-gate 	    yyval, shval, p2, -shval);
99*779fc935Sceastha #endif	/* NEQN */
1007c478bd9Sstevel@tonic-gate 	ofree(p2);
1017c478bd9Sstevel@tonic-gate }
1027c478bd9Sstevel@tonic-gate 
103*779fc935Sceastha void
shift(int p1)104*779fc935Sceastha shift(int p1)
105*779fc935Sceastha {
1067c478bd9Sstevel@tonic-gate 	ps -= deltaps;
1077c478bd9Sstevel@tonic-gate 	yyval = p1;
1087c478bd9Sstevel@tonic-gate 	if (dbg) printf(".\tshift: %d;ps=%d\n", yyval, ps);
1097c478bd9Sstevel@tonic-gate }
1107c478bd9Sstevel@tonic-gate 
111*779fc935Sceastha void
shift2(int p1,int p2,int p3)112*779fc935Sceastha shift2(int p1, int p2, int p3)
113*779fc935Sceastha {
1147c478bd9Sstevel@tonic-gate 	int effps, h1, h2, h3, b1, b2, b3, subsh, d1, d2, supsh, treg;
1157c478bd9Sstevel@tonic-gate #ifndef NEQN
1167c478bd9Sstevel@tonic-gate 	int effps2;
117*779fc935Sceastha #endif	/* NEQN */
1187c478bd9Sstevel@tonic-gate 
1197c478bd9Sstevel@tonic-gate 	treg = oalloc();
1207c478bd9Sstevel@tonic-gate 	yyval = p1;
1217c478bd9Sstevel@tonic-gate 	if (dbg) printf(".\tshift2 s%d <- %d %d %d\n", yyval, p1, p2, p3);
1227c478bd9Sstevel@tonic-gate 	effps = EFFPS(ps+deltaps);
1237c478bd9Sstevel@tonic-gate #ifndef NEQN
1247c478bd9Sstevel@tonic-gate 	eht[p3] = h3 = VERT((eht[p3] * effps) / EFFPS(ps));
1257c478bd9Sstevel@tonic-gate 	ps += deltaps;
1267c478bd9Sstevel@tonic-gate 	effps2 = EFFPS(ps+deltaps);
127*779fc935Sceastha #endif	/* NEQN */
1287c478bd9Sstevel@tonic-gate 	h1 = eht[p1]; b1 = ebase[p1];
1297c478bd9Sstevel@tonic-gate 	h2 = eht[p2]; b2 = ebase[p2];
1307c478bd9Sstevel@tonic-gate #ifndef NEQN
1317c478bd9Sstevel@tonic-gate 	b3 = ebase[p3];
1327c478bd9Sstevel@tonic-gate 	d1 = VERT(EM(0.5, effps2));
133*779fc935Sceastha #else	/* NEQN */
1347c478bd9Sstevel@tonic-gate 	h3 = eht[p3]; b3 = ebase[p3];
1357c478bd9Sstevel@tonic-gate 	d1 = VERT(1);
136*779fc935Sceastha #endif	/* NEQN */
1377c478bd9Sstevel@tonic-gate 	subsh = -d1+h2-b2;
1387c478bd9Sstevel@tonic-gate 	if (d1+b1 > h2) /* move little sub down */
1397c478bd9Sstevel@tonic-gate 		subsh = b1-b2;
1407c478bd9Sstevel@tonic-gate #ifndef NEQN
1417c478bd9Sstevel@tonic-gate 	supsh = -VERT((4*(h1-b1))/10) - b3;
1427c478bd9Sstevel@tonic-gate 	d2 = VERT(EM(0.2, effps));
1437c478bd9Sstevel@tonic-gate 	if (VERT(4*(h1-b1)/10)+h3 < h1-b1)
144*779fc935Sceastha #else	/* NEQN */
1457c478bd9Sstevel@tonic-gate 	supsh = - VERT(1) - b3;
1467c478bd9Sstevel@tonic-gate 	d2 = VERT(1);
1477c478bd9Sstevel@tonic-gate 	if (VERT(1)+h3 < h1-b1)
148*779fc935Sceastha #endif	/* NEQN */
1497c478bd9Sstevel@tonic-gate 		supsh = -(h1-b1) + (h3-b3) - d2;
1507c478bd9Sstevel@tonic-gate #ifndef NEQN
1517c478bd9Sstevel@tonic-gate 	eht[yyval] = h1 + max(0, h3-VERT((6*(h1-b1))/10)) + max(0, h2-b1-d1);
152*779fc935Sceastha #else	/* NEQN */
1537c478bd9Sstevel@tonic-gate 	eht[yyval] = h1 + max(0, h3-VERT(1)) + max(0, h2-b1-d1);
154*779fc935Sceastha #endif	/* NEQN */
1557c478bd9Sstevel@tonic-gate 	ebase[yyval] = b1+max(0, h2-b1-d1);
1567c478bd9Sstevel@tonic-gate #ifndef NEQN
1577c478bd9Sstevel@tonic-gate 	if (rfont[p1] == ITAL && lfont[p2] == ROM)
1587c478bd9Sstevel@tonic-gate 		printf(".ds %d \\|\\*(%d\n", p2, p2);
1597c478bd9Sstevel@tonic-gate 	if (rfont[p2] == ITAL)
1607c478bd9Sstevel@tonic-gate 		printf(".as %d \\|\n", p2);
161*779fc935Sceastha #endif	/* NEQN */
1627c478bd9Sstevel@tonic-gate 	nrwid(p2, effps, p2);
1637c478bd9Sstevel@tonic-gate #ifndef NEQN
1647c478bd9Sstevel@tonic-gate 	if (rfont[p1] == ITAL && lfont[p3] == ROM)
1657c478bd9Sstevel@tonic-gate 		printf(".ds %d \\|\\|\\*(%d\n", p3, p3);
1667c478bd9Sstevel@tonic-gate 	else
1677c478bd9Sstevel@tonic-gate 		printf(".ds %d \\|\\*(%d\n", p3, p3);
168*779fc935Sceastha #endif	/* NEQN */
1697c478bd9Sstevel@tonic-gate 	nrwid(p3, effps, p3);
1707c478bd9Sstevel@tonic-gate 	printf(".nr %d \\n(%d\n", treg, p3);
1717c478bd9Sstevel@tonic-gate 	printf(".if \\n(%d>\\n(%d .nr %d \\n(%d\n", p2, treg, treg, p2);
1727c478bd9Sstevel@tonic-gate #ifndef NEQN
1737c478bd9Sstevel@tonic-gate 	printf(".as %d \\v'%du'\\s%d\\*(%d\\h'-\\n(%du'\\v'%du'\\\n",
1747c478bd9Sstevel@tonic-gate 	    p1, subsh, effps, p2, p2, -subsh+supsh);
1757c478bd9Sstevel@tonic-gate 	printf("\\s%d\\*(%d\\h'-\\n(%du+\\n(%du'\\s%d\\v'%du'\n",
1767c478bd9Sstevel@tonic-gate 	    effps, p3, p3, treg, effps2, -supsh);
177*779fc935Sceastha #else	/* NEQN */
1787c478bd9Sstevel@tonic-gate 	printf(".as %d \\v'%du'\\*(%d\\h'-\\n(%du'\\v'%du'\\\n",
1797c478bd9Sstevel@tonic-gate 	    p1, subsh, p2, p2, -subsh+supsh);
1807c478bd9Sstevel@tonic-gate 	printf("\\*(%d\\h'-\\n(%du+\\n(%du'\\v'%du'\n",
1817c478bd9Sstevel@tonic-gate 	    p3, p3, treg, -supsh);
182*779fc935Sceastha #endif	/* NEQN */
1837c478bd9Sstevel@tonic-gate 	ps += deltaps;
1847c478bd9Sstevel@tonic-gate #ifndef NEQN
1857c478bd9Sstevel@tonic-gate 	if (rfont[p2] == ITAL)
1867c478bd9Sstevel@tonic-gate 		rfont[yyval] = 0;	/* lie */
187*779fc935Sceastha #endif	/* NEQN */
1887c478bd9Sstevel@tonic-gate 	ofree(p2); ofree(p3); ofree(treg);
1897c478bd9Sstevel@tonic-gate }
190