xref: /illumos-gate/usr/src/cmd/eqn/pile.c (revision 2a8bcb4e)
1*779fc935Sceastha /*
2*779fc935Sceastha  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
3*779fc935Sceastha  * Use is subject to license terms.
4*779fc935Sceastha  */
5*779fc935Sceastha 
67c478bd9Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
77c478bd9Sstevel@tonic-gate /*	  All Rights Reserved  	*/
87c478bd9Sstevel@tonic-gate 
97c478bd9Sstevel@tonic-gate /*
107c478bd9Sstevel@tonic-gate  * Copyright (c) 1980 Regents of the University of California.
117c478bd9Sstevel@tonic-gate  * All rights reserved. The Berkeley software License Agreement
127c478bd9Sstevel@tonic-gate  * specifies the terms and conditions for redistribution.
137c478bd9Sstevel@tonic-gate  */
147c478bd9Sstevel@tonic-gate 
15*779fc935Sceastha #include "e.h"
167c478bd9Sstevel@tonic-gate 
17*779fc935Sceastha void
lpile(int type,int p1,int p2)18*779fc935Sceastha lpile(int type, int p1, int p2)
19*779fc935Sceastha {
207c478bd9Sstevel@tonic-gate 	int bi, hi, i, gap, h, b, nlist, nlist2, mid;
217c478bd9Sstevel@tonic-gate 	yyval = oalloc();
227c478bd9Sstevel@tonic-gate #ifndef NEQN
237c478bd9Sstevel@tonic-gate 	gap = VERT(EM(0.4, ps)); /* 4/10 m between blocks */
24*779fc935Sceastha #else	/* NEQN */
257c478bd9Sstevel@tonic-gate 	gap = VERT(1);
26*779fc935Sceastha #endif	/* NEQN */
27*779fc935Sceastha 	if (type == '-') gap = 0;
287c478bd9Sstevel@tonic-gate 	nlist = p2 - p1;
297c478bd9Sstevel@tonic-gate 	nlist2 = (nlist+1)/2;
307c478bd9Sstevel@tonic-gate 	mid = p1 + nlist2 -1;
317c478bd9Sstevel@tonic-gate 	h = 0;
32*779fc935Sceastha 	for (i = p1; i < p2; i++)
337c478bd9Sstevel@tonic-gate 		h += eht[lp[i]];
347c478bd9Sstevel@tonic-gate 	eht[yyval] = h + (nlist-1)*gap;
357c478bd9Sstevel@tonic-gate 	b = 0;
36*779fc935Sceastha 	for (i = p2-1; i > mid; i--)
377c478bd9Sstevel@tonic-gate 		b += eht[lp[i]] + gap;
387c478bd9Sstevel@tonic-gate #ifndef NEQN
39*779fc935Sceastha 	ebase[yyval] = (nlist%2) ? b + ebase[lp[mid]]
40*779fc935Sceastha 	    : b - VERT(EM(0.5, ps)) - gap;
41*779fc935Sceastha #else	/* NEQN */
42*779fc935Sceastha 	ebase[yyval] = (nlist%2) ? b + ebase[lp[mid]]
43*779fc935Sceastha 	    : b - VERT(1) - gap;
44*779fc935Sceastha #endif	/* NEQN */
45*779fc935Sceastha 	if (dbg) {
467c478bd9Sstevel@tonic-gate 		printf(".\tS%d <- %c pile of:", yyval, type);
47*779fc935Sceastha 		for (i = p1; i < p2; i++)
487c478bd9Sstevel@tonic-gate 			printf(" S%d", lp[i]);
497c478bd9Sstevel@tonic-gate 		printf(";h=%d b=%d\n", eht[yyval], ebase[yyval]);
507c478bd9Sstevel@tonic-gate 	}
517c478bd9Sstevel@tonic-gate 	nrwid(lp[p1], ps, lp[p1]);
527c478bd9Sstevel@tonic-gate 	printf(".nr %d \\n(%d\n", yyval, lp[p1]);
53*779fc935Sceastha 	for (i = p1+1; i < p2; i++) {
547c478bd9Sstevel@tonic-gate 		nrwid(lp[i], ps, lp[i]);
55*779fc935Sceastha 		printf(".if \\n(%d>\\n(%d .nr %d \\n(%d\n",
56*779fc935Sceastha 		    lp[i], yyval, yyval, lp[i]);
577c478bd9Sstevel@tonic-gate 	}
58*779fc935Sceastha 	printf(".ds %d \\v'%du'\\h'%du*\\n(%du'\\\n", yyval, ebase[yyval],
59*779fc935Sceastha 	    type == 'R' ? 1 : 0, yyval);
60*779fc935Sceastha 	for (i = p2-1; i >= p1; i--) {
61*779fc935Sceastha 		hi = eht[lp[i]];
627c478bd9Sstevel@tonic-gate 		bi = ebase[lp[i]];
63*779fc935Sceastha 	switch (type) {
647c478bd9Sstevel@tonic-gate 
657c478bd9Sstevel@tonic-gate 	case 'L':
66*779fc935Sceastha 		printf("\\v'%du'\\*(%d\\h'-\\n(%du'\\v'0-%du'\\\n",
67*779fc935Sceastha 		    -bi, lp[i], lp[i], hi-bi+gap);
687c478bd9Sstevel@tonic-gate 		continue;
697c478bd9Sstevel@tonic-gate 	case 'R':
70*779fc935Sceastha 		printf("\\v'%du'\\h'-\\n(%du'\\*(%d\\v'0-%du'\\\n",
71*779fc935Sceastha 		    -bi, lp[i], lp[i], hi-bi+gap);
727c478bd9Sstevel@tonic-gate 		continue;
737c478bd9Sstevel@tonic-gate 	case 'C':
747c478bd9Sstevel@tonic-gate 	case '-':
75*779fc935Sceastha 		printf("\\v'%du'\\h'\\n(%du-\\n(%du/2u'\\*(%d",
76*779fc935Sceastha 		    -bi, yyval, lp[i], lp[i]);
77*779fc935Sceastha 		printf("\\h'-\\n(%du-\\n(%du/2u'\\v'0-%du'\\\n",
78*779fc935Sceastha 		    yyval, lp[i], hi-bi+gap);
797c478bd9Sstevel@tonic-gate 		continue;
807c478bd9Sstevel@tonic-gate 		}
817c478bd9Sstevel@tonic-gate 	}
82*779fc935Sceastha 	printf("\\v'%du'\\h'%du*\\n(%du'\n", eht[yyval]-ebase[yyval]+gap,
83*779fc935Sceastha 	    type != 'R' ? 1 : 0, yyval);
84*779fc935Sceastha 	for (i = p1; i < p2; i++)
857c478bd9Sstevel@tonic-gate 		ofree(lp[i]);
867c478bd9Sstevel@tonic-gate 	lfont[yyval] = rfont[yyval] = 0;
877c478bd9Sstevel@tonic-gate }
88