xref: /illumos-gate/usr/src/cmd/eqn/fromto.c (revision 2a8bcb4e)
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 #include "e.h"
167c478bd9Sstevel@tonic-gate 
17*779fc935Sceastha void
fromto(int p1,int p2,int p3)18*779fc935Sceastha fromto(int p1, int p2, int p3)
19*779fc935Sceastha {
207c478bd9Sstevel@tonic-gate 	int b, h1, b1, pss;
217c478bd9Sstevel@tonic-gate 	yyval = oalloc();
227c478bd9Sstevel@tonic-gate 	lfont[yyval] = rfont[yyval] = 0;
237c478bd9Sstevel@tonic-gate 	h1 = eht[yyval] = eht[p1];
247c478bd9Sstevel@tonic-gate 	b1 = ebase[p1];
257c478bd9Sstevel@tonic-gate 	b = 0;
267c478bd9Sstevel@tonic-gate 	pss = EFFPS(ps);
277c478bd9Sstevel@tonic-gate 	ps += 3;
287c478bd9Sstevel@tonic-gate 	nrwid(p1, ps, p1);
297c478bd9Sstevel@tonic-gate 	printf(".nr %d \\n(%d\n", yyval, p1);
30*779fc935Sceastha 	if (p2 > 0) {
317c478bd9Sstevel@tonic-gate 		nrwid(p2, pss, p2);
32*779fc935Sceastha 		printf(".if \\n(%d>\\n(%d .nr %d \\n(%d\n",
33*779fc935Sceastha 		    p2, yyval, yyval, p2);
347c478bd9Sstevel@tonic-gate 		eht[yyval] += eht[p2];
357c478bd9Sstevel@tonic-gate 		b = eht[p2];
367c478bd9Sstevel@tonic-gate 	}
37*779fc935Sceastha 	if (p3 > 0) {
387c478bd9Sstevel@tonic-gate 		nrwid(p3, pss, p3);
39*779fc935Sceastha 		printf(".if \\n(%d>\\n(%d .nr %d \\n(%d\n",
40*779fc935Sceastha 		    p3, yyval, yyval, p3);
417c478bd9Sstevel@tonic-gate 		eht[yyval] += eht[p3];
427c478bd9Sstevel@tonic-gate 	}
437c478bd9Sstevel@tonic-gate 	printf(".ds %d ", yyval);	/* bottom of middle box */
44*779fc935Sceastha 	if (p2 > 0) {
45*779fc935Sceastha 		printf("\\v'%du'\\h'\\n(%du-\\n(%du/2u'\\s%d\\*(%d\\s%d",
46*779fc935Sceastha 		    eht[p2]-ebase[p2]+b1, yyval, p2, pss, p2, EFFPS(ps));
47*779fc935Sceastha 		printf("\\h'-\\n(%du-\\n(%du/2u'\\v'%du'\\\n",
48*779fc935Sceastha 		    yyval, p2, -(eht[p2]-ebase[p2]+b1));
497c478bd9Sstevel@tonic-gate 	}
507c478bd9Sstevel@tonic-gate #ifndef NEQN
51*779fc935Sceastha 	printf("\\h'\\n(%du-\\n(%du/2u'\\*(%d\\h'\\n(%du-\\n(%du/2u'\\\n",
52*779fc935Sceastha 	    yyval, p1, p1, yyval, p1);
53*779fc935Sceastha #else	/* NEQN */
54*779fc935Sceastha 	printf("\\h'\\n(%du-\\n(%du/2u'\\*(%d\\h'\\n(%du-\\n(%du+2u/2u'\\\n",
55*779fc935Sceastha 	    yyval, p1, p1, yyval, p1);
56*779fc935Sceastha #endif	/* NEQN */
57*779fc935Sceastha 	if (p3 > 0) {
58*779fc935Sceastha 		printf("\\v'%du'\\h'-\\n(%du-\\n(%du/2u'\\s%d\\*(%d\\s%d"
59*779fc935Sceastha 		    "\\h'\\n(%du-\\n(%du/2u'\\v'%du'\\\n",
60*779fc935Sceastha 		    -(h1-b1+ebase[p3]), yyval, p3, pss, p3, EFFPS(ps),
61*779fc935Sceastha 		    yyval, p3, (h1-b1+ebase[p3]));
627c478bd9Sstevel@tonic-gate 	}
637c478bd9Sstevel@tonic-gate 	printf("\n");
647c478bd9Sstevel@tonic-gate 	ebase[yyval] = b + b1;
65*779fc935Sceastha 	if (dbg)
66*779fc935Sceastha 		printf(".\tfrom to: S%d <- %d f %d t %d; h=%d b=%d\n",
67*779fc935Sceastha 		    yyval, p1, p2, p3, eht[yyval], ebase[yyval]);
687c478bd9Sstevel@tonic-gate 	ofree(p1);
69*779fc935Sceastha 	if (p2 > 0) ofree(p2);
70*779fc935Sceastha 	if (p3 > 0) ofree(p3);
717c478bd9Sstevel@tonic-gate }
72