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