xref: /original-bsd/old/eqn/common_source/pile.c (revision 81aa1937)
1 /*-
2  * Copyright (c) 1991 The Regents of the University of California.
3  * All rights reserved.
4  *
5  * %sccs.include.proprietary.c%
6  */
7 
8 #ifndef lint
9 static char sccsid[] = "@(#)pile.c	4.4 (Berkeley) 04/17/91";
10 #endif /* not lint */
11 
12 # include "e.h"
13 
14 lpile(type, p1, p2) int type, p1, p2; {
15 	int bi, hi, i, gap, h, b, nlist, nlist2, mid;
16 	yyval = oalloc();
17 #ifndef NEQN
18 	gap = VERT( (ps*6*4)/10 ); /* 4/10 m between blocks */
19 #else NEQN
20 	gap = VERT(1);
21 #endif NEQN
22 	if( type=='-' ) gap = 0;
23 	nlist = p2 - p1;
24 	nlist2 = (nlist+1)/2;
25 	mid = p1 + nlist2 -1;
26 	h = 0;
27 	for( i=p1; i<p2; i++ )
28 		h += eht[lp[i]];
29 	eht[yyval] = h + (nlist-1)*gap;
30 	b = 0;
31 	for( i=p2-1; i>mid; i-- )
32 		b += eht[lp[i]] + gap;
33 	ebase[yyval] = (nlist%2) ? b + ebase[lp[mid]]
34 #ifndef NEQN
35 			: b - VERT( (ps*6*5)/10 ) - gap;
36 #else NEQN
37 			: b - VERT(1) - gap;
38 #endif NEQN
39 	if(dbg) {
40 		printf(".\tS%d <- %c pile of:", yyval, type);
41 		for( i=p1; i<p2; i++)
42 			printf(" S%d", lp[i]);
43 		printf(";h=%d b=%d\n", eht[yyval], ebase[yyval]);
44 	}
45 	nrwid(lp[p1], ps, lp[p1]);
46 	printf(".nr %d \\n(%d\n", yyval, lp[p1]);
47 	for( i = p1+1; i<p2; i++ ) {
48 		nrwid(lp[i], ps, lp[i]);
49 		printf(".if \\n(%d>\\n(%d .nr %d \\n(%d\n",
50 			lp[i], yyval, yyval, lp[i]);
51 	}
52 	printf(".ds %d \\v'%du'\\h'%du*\\n(%du'\\\n", yyval, ebase[yyval],
53 		type=='R' ? 1 : 0, yyval);
54 	for(i = p2-1; i >=p1; i--) {
55 		hi = eht[lp[i]];
56 		bi = ebase[lp[i]];
57 	switch(type) {
58 
59 	case 'L':
60 		printf("\\v'%du'\\*(%d\\h'-\\n(%du'\\v'0-%du'\\\n",
61 			-bi, lp[i], lp[i], hi-bi+gap);
62 		continue;
63 	case 'R':
64 		printf("\\v'%du'\\h'-\\n(%du'\\*(%d\\v'0-%du'\\\n",
65 			-bi, lp[i], lp[i], hi-bi+gap);
66 		continue;
67 	case 'C':
68 	case '-':
69 		printf("\\v'%du'\\h'\\n(%du-\\n(%du/2u'\\*(%d",
70 			-bi, yyval, lp[i], lp[i]);
71 		printf("\\h'-\\n(%du-\\n(%du/2u'\\v'0-%du'\\\n",
72 			yyval, lp[i], hi-bi+gap);
73 		continue;
74 		}
75 	}
76 	printf("\\v'%du'\\h'%du*\\n(%du'\n", eht[yyval]-ebase[yyval]+gap,
77 		type!='R' ? 1 : 0, yyval);
78 	for( i=p1; i<p2; i++ )
79 		ofree(lp[i]);
80 	lfont[yyval] = rfont[yyval] = 0;
81 }
82