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