xref: /titanic_51/usr/src/cmd/eqn/fromto.c (revision bbaa8b60dd95d714741fc474adad3cf710ef4efd)
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 
19 void
20 fromto(int p1, int p2, int p3)
21 {
22 	int b, h1, b1, pss;
23 	yyval = oalloc();
24 	lfont[yyval] = rfont[yyval] = 0;
25 	h1 = eht[yyval] = eht[p1];
26 	b1 = ebase[p1];
27 	b = 0;
28 	pss = EFFPS(ps);
29 	ps += 3;
30 	nrwid(p1, ps, p1);
31 	printf(".nr %d \\n(%d\n", yyval, p1);
32 	if (p2 > 0) {
33 		nrwid(p2, pss, p2);
34 		printf(".if \\n(%d>\\n(%d .nr %d \\n(%d\n",
35 		    p2, yyval, yyval, p2);
36 		eht[yyval] += eht[p2];
37 		b = eht[p2];
38 	}
39 	if (p3 > 0) {
40 		nrwid(p3, pss, p3);
41 		printf(".if \\n(%d>\\n(%d .nr %d \\n(%d\n",
42 		    p3, yyval, yyval, p3);
43 		eht[yyval] += eht[p3];
44 	}
45 	printf(".ds %d ", yyval);	/* bottom of middle box */
46 	if (p2 > 0) {
47 		printf("\\v'%du'\\h'\\n(%du-\\n(%du/2u'\\s%d\\*(%d\\s%d",
48 		    eht[p2]-ebase[p2]+b1, yyval, p2, pss, p2, EFFPS(ps));
49 		printf("\\h'-\\n(%du-\\n(%du/2u'\\v'%du'\\\n",
50 		    yyval, p2, -(eht[p2]-ebase[p2]+b1));
51 	}
52 #ifndef NEQN
53 	printf("\\h'\\n(%du-\\n(%du/2u'\\*(%d\\h'\\n(%du-\\n(%du/2u'\\\n",
54 	    yyval, p1, p1, yyval, p1);
55 #else	/* NEQN */
56 	printf("\\h'\\n(%du-\\n(%du/2u'\\*(%d\\h'\\n(%du-\\n(%du+2u/2u'\\\n",
57 	    yyval, p1, p1, yyval, p1);
58 #endif	/* NEQN */
59 	if (p3 > 0) {
60 		printf("\\v'%du'\\h'-\\n(%du-\\n(%du/2u'\\s%d\\*(%d\\s%d"
61 		    "\\h'\\n(%du-\\n(%du/2u'\\v'%du'\\\n",
62 		    -(h1-b1+ebase[p3]), yyval, p3, pss, p3, EFFPS(ps),
63 		    yyval, p3, (h1-b1+ebase[p3]));
64 	}
65 	printf("\n");
66 	ebase[yyval] = b + b1;
67 	if (dbg)
68 		printf(".\tfrom to: S%d <- %d f %d t %d; h=%d b=%d\n",
69 		    yyval, p1, p2, p3, eht[yyval], ebase[yyval]);
70 	ofree(p1);
71 	if (p2 > 0) ofree(p2);
72 	if (p3 > 0) ofree(p3);
73 }
74