xref: /titanic_50/usr/src/cmd/eqn/pile.c (revision 6451fdbca2f79129a3a09d2fe3f6dd4d062bebff)
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 lpile(int type, int p1, int p2)
21 {
22 	int bi, hi, i, gap, h, b, nlist, nlist2, mid;
23 	yyval = oalloc();
24 #ifndef NEQN
25 	gap = VERT(EM(0.4, ps)); /* 4/10 m between blocks */
26 #else	/* NEQN */
27 	gap = VERT(1);
28 #endif	/* NEQN */
29 	if (type == '-') gap = 0;
30 	nlist = p2 - p1;
31 	nlist2 = (nlist+1)/2;
32 	mid = p1 + nlist2 -1;
33 	h = 0;
34 	for (i = p1; i < p2; i++)
35 		h += eht[lp[i]];
36 	eht[yyval] = h + (nlist-1)*gap;
37 	b = 0;
38 	for (i = p2-1; i > mid; i--)
39 		b += eht[lp[i]] + gap;
40 #ifndef NEQN
41 	ebase[yyval] = (nlist%2) ? b + ebase[lp[mid]]
42 	    : b - VERT(EM(0.5, ps)) - gap;
43 #else	/* NEQN */
44 	ebase[yyval] = (nlist%2) ? b + ebase[lp[mid]]
45 	    : b - VERT(1) - gap;
46 #endif	/* NEQN */
47 	if (dbg) {
48 		printf(".\tS%d <- %c pile of:", yyval, type);
49 		for (i = p1; i < p2; i++)
50 			printf(" S%d", lp[i]);
51 		printf(";h=%d b=%d\n", eht[yyval], ebase[yyval]);
52 	}
53 	nrwid(lp[p1], ps, lp[p1]);
54 	printf(".nr %d \\n(%d\n", yyval, lp[p1]);
55 	for (i = p1+1; i < p2; i++) {
56 		nrwid(lp[i], ps, lp[i]);
57 		printf(".if \\n(%d>\\n(%d .nr %d \\n(%d\n",
58 		    lp[i], yyval, yyval, lp[i]);
59 	}
60 	printf(".ds %d \\v'%du'\\h'%du*\\n(%du'\\\n", yyval, ebase[yyval],
61 	    type == 'R' ? 1 : 0, yyval);
62 	for (i = p2-1; i >= p1; i--) {
63 		hi = eht[lp[i]];
64 		bi = ebase[lp[i]];
65 	switch (type) {
66 
67 	case 'L':
68 		printf("\\v'%du'\\*(%d\\h'-\\n(%du'\\v'0-%du'\\\n",
69 		    -bi, lp[i], lp[i], hi-bi+gap);
70 		continue;
71 	case 'R':
72 		printf("\\v'%du'\\h'-\\n(%du'\\*(%d\\v'0-%du'\\\n",
73 		    -bi, lp[i], lp[i], hi-bi+gap);
74 		continue;
75 	case 'C':
76 	case '-':
77 		printf("\\v'%du'\\h'\\n(%du-\\n(%du/2u'\\*(%d",
78 		    -bi, yyval, lp[i], lp[i]);
79 		printf("\\h'-\\n(%du-\\n(%du/2u'\\v'0-%du'\\\n",
80 		    yyval, lp[i], hi-bi+gap);
81 		continue;
82 		}
83 	}
84 	printf("\\v'%du'\\h'%du*\\n(%du'\n", eht[yyval]-ebase[yyval]+gap,
85 	    type != 'R' ? 1 : 0, yyval);
86 	for (i = p1; i < p2; i++)
87 		ofree(lp[i]);
88 	lfont[yyval] = rfont[yyval] = 0;
89 }
90