1*364Sceastha /*
2*364Sceastha * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
3*364Sceastha * Use is subject to license terms.
4*364Sceastha */
5*364Sceastha
60Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
70Sstevel@tonic-gate /* All Rights Reserved */
80Sstevel@tonic-gate
90Sstevel@tonic-gate /*
100Sstevel@tonic-gate * Copyright (c) 1980 Regents of the University of California.
110Sstevel@tonic-gate * All rights reserved. The Berkeley software License Agreement
120Sstevel@tonic-gate * specifies the terms and conditions for redistribution.
130Sstevel@tonic-gate */
14*364Sceastha
15*364Sceastha #pragma ident "%Z%%M% %I% %E% SMI"
160Sstevel@tonic-gate
17*364Sceastha #include "e.h"
180Sstevel@tonic-gate
19*364Sceastha void
lpile(int type,int p1,int p2)20*364Sceastha lpile(int type, int p1, int p2)
21*364Sceastha {
220Sstevel@tonic-gate int bi, hi, i, gap, h, b, nlist, nlist2, mid;
230Sstevel@tonic-gate yyval = oalloc();
240Sstevel@tonic-gate #ifndef NEQN
250Sstevel@tonic-gate gap = VERT(EM(0.4, ps)); /* 4/10 m between blocks */
26*364Sceastha #else /* NEQN */
270Sstevel@tonic-gate gap = VERT(1);
28*364Sceastha #endif /* NEQN */
29*364Sceastha if (type == '-') gap = 0;
300Sstevel@tonic-gate nlist = p2 - p1;
310Sstevel@tonic-gate nlist2 = (nlist+1)/2;
320Sstevel@tonic-gate mid = p1 + nlist2 -1;
330Sstevel@tonic-gate h = 0;
34*364Sceastha for (i = p1; i < p2; i++)
350Sstevel@tonic-gate h += eht[lp[i]];
360Sstevel@tonic-gate eht[yyval] = h + (nlist-1)*gap;
370Sstevel@tonic-gate b = 0;
38*364Sceastha for (i = p2-1; i > mid; i--)
390Sstevel@tonic-gate b += eht[lp[i]] + gap;
400Sstevel@tonic-gate #ifndef NEQN
41*364Sceastha ebase[yyval] = (nlist%2) ? b + ebase[lp[mid]]
42*364Sceastha : b - VERT(EM(0.5, ps)) - gap;
43*364Sceastha #else /* NEQN */
44*364Sceastha ebase[yyval] = (nlist%2) ? b + ebase[lp[mid]]
45*364Sceastha : b - VERT(1) - gap;
46*364Sceastha #endif /* NEQN */
47*364Sceastha if (dbg) {
480Sstevel@tonic-gate printf(".\tS%d <- %c pile of:", yyval, type);
49*364Sceastha for (i = p1; i < p2; i++)
500Sstevel@tonic-gate printf(" S%d", lp[i]);
510Sstevel@tonic-gate printf(";h=%d b=%d\n", eht[yyval], ebase[yyval]);
520Sstevel@tonic-gate }
530Sstevel@tonic-gate nrwid(lp[p1], ps, lp[p1]);
540Sstevel@tonic-gate printf(".nr %d \\n(%d\n", yyval, lp[p1]);
55*364Sceastha for (i = p1+1; i < p2; i++) {
560Sstevel@tonic-gate nrwid(lp[i], ps, lp[i]);
57*364Sceastha printf(".if \\n(%d>\\n(%d .nr %d \\n(%d\n",
58*364Sceastha lp[i], yyval, yyval, lp[i]);
590Sstevel@tonic-gate }
60*364Sceastha printf(".ds %d \\v'%du'\\h'%du*\\n(%du'\\\n", yyval, ebase[yyval],
61*364Sceastha type == 'R' ? 1 : 0, yyval);
62*364Sceastha for (i = p2-1; i >= p1; i--) {
63*364Sceastha hi = eht[lp[i]];
640Sstevel@tonic-gate bi = ebase[lp[i]];
65*364Sceastha switch (type) {
660Sstevel@tonic-gate
670Sstevel@tonic-gate case 'L':
68*364Sceastha printf("\\v'%du'\\*(%d\\h'-\\n(%du'\\v'0-%du'\\\n",
69*364Sceastha -bi, lp[i], lp[i], hi-bi+gap);
700Sstevel@tonic-gate continue;
710Sstevel@tonic-gate case 'R':
72*364Sceastha printf("\\v'%du'\\h'-\\n(%du'\\*(%d\\v'0-%du'\\\n",
73*364Sceastha -bi, lp[i], lp[i], hi-bi+gap);
740Sstevel@tonic-gate continue;
750Sstevel@tonic-gate case 'C':
760Sstevel@tonic-gate case '-':
77*364Sceastha printf("\\v'%du'\\h'\\n(%du-\\n(%du/2u'\\*(%d",
78*364Sceastha -bi, yyval, lp[i], lp[i]);
79*364Sceastha printf("\\h'-\\n(%du-\\n(%du/2u'\\v'0-%du'\\\n",
80*364Sceastha yyval, lp[i], hi-bi+gap);
810Sstevel@tonic-gate continue;
820Sstevel@tonic-gate }
830Sstevel@tonic-gate }
84*364Sceastha printf("\\v'%du'\\h'%du*\\n(%du'\n", eht[yyval]-ebase[yyval]+gap,
85*364Sceastha type != 'R' ? 1 : 0, yyval);
86*364Sceastha for (i = p1; i < p2; i++)
870Sstevel@tonic-gate ofree(lp[i]);
880Sstevel@tonic-gate lfont[yyval] = rfont[yyval] = 0;
890Sstevel@tonic-gate }
90