xref: /titanic_51/usr/src/cmd/eqn/pile.c (revision 8eea8e29cc4374d1ee24c25a07f45af132db3499)
1 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
2 /*	  All Rights Reserved  	*/
3 
4 
5 /*
6  * Copyright (c) 1980 Regents of the University of California.
7  * All rights reserved. The Berkeley software License Agreement
8  * specifies the terms and conditions for redistribution.
9  */
10 
11 /*
12  * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
13  * All Rights Reserved.
14  */
15 
16 #ident	"%Z%%M%	%I%	%E% SMI"	/* SVr4.0 1.1	*/
17 
18 # include "e.h"
19 
20 lpile(type, p1, p2) int type, p1, p2; {
21 	int bi, hi, i, gap, h, b, nlist, nlist2, mid;
22 	yyval = oalloc();
23 #ifndef NEQN
24 	gap = VERT(EM(0.4, ps)); /* 4/10 m between blocks */
25 #else NEQN
26 	gap = VERT(1);
27 #endif NEQN
28 	if( type=='-' ) gap = 0;
29 	nlist = p2 - p1;
30 	nlist2 = (nlist+1)/2;
31 	mid = p1 + nlist2 -1;
32 	h = 0;
33 	for( i=p1; i<p2; i++ )
34 		h += eht[lp[i]];
35 	eht[yyval] = h + (nlist-1)*gap;
36 	b = 0;
37 	for( i=p2-1; i>mid; i-- )
38 		b += eht[lp[i]] + gap;
39 	ebase[yyval] = (nlist%2) ? b + ebase[lp[mid]]
40 #ifndef NEQN
41 			: b - VERT(EM(0.5, ps)) - gap;
42 #else NEQN
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