]> git.lizzy.rs Git - plan9front.git/blob - sys/src/cmd/eqn/pile.c
merge
[plan9front.git] / sys / src / cmd / eqn / pile.c
1 #include "e.h"
2 #include "y.tab.h"
3
4 void pile(int oct)
5 {
6         int i, nlist, nlist2, mid;
7         double bi, h, b, gap, sb;
8         extern double Pilegap, Pilebase;
9         int type, p1, p2;
10
11         yyval = salloc();
12         type = lp[oct];
13         p1 = oct + 3;           /* first entry */
14         p2 = p1 + lp[oct+1];    /* 1 after last */
15         gap = lp[oct+2];
16         if (gap != DEFGAP)
17                 gap = EM(gap/100.0, ps);
18         else if (type == COL)
19                 gap = 0;
20         else
21                 gap = EM(Pilegap, ps);  /* 0.4 m between LCOL, etc. */
22         nlist = p2 - p1;
23         nlist2 = (nlist+1)/2;
24         mid = p1 + nlist2 - 1;
25         h = 0;
26         for (i = p1; i < p2; i++)
27                 h += eht[lp[i]];
28         eht[yyval] = h + (nlist-1)*gap;
29         b = 0;
30         for (i = p2-1; i > mid; i--)
31                 b += eht[lp[i]] + gap;
32         ebase[yyval] = (nlist%2) ? b + ebase[lp[mid]]
33                         : b - EM(Pilebase, ps) - gap;
34         if (dbg) {
35                 printf(".\tS%d <- %d pile of:", yyval, type);
36                 for (i = p1; i < p2; i++)
37                         printf(" S%d", lp[i]);
38                 printf("; h=%g b=%g\n", eht[yyval], ebase[yyval]);
39         }
40         nrwid(lp[p1], ps, lp[p1]);
41         printf(".nr %d \\n(%d\n", yyval, lp[p1]);
42         for (i = p1+1; i < p2; i++) {
43                 nrwid(lp[i], ps, lp[i]);
44                 printf(".if \\n(%d>\\n(%d .nr %d \\n(%d\n", 
45                         lp[i], yyval, yyval, lp[i]);
46         }
47         printf(".ds %d \\v'%gm'\\h'%du*\\n(%du'\\\n", yyval, REL(ebase[yyval],ps), 
48                 type==RCOL ? 1 : 0, yyval);
49         sb = 0;         /* sum of box hts */
50         for (i = p2-1; i >= p1; i--) {
51                 bi = sb + ebase[lp[i]];
52                 switch (type) {
53                 case LCOL:
54                         printf("\\v'%gm'\\*(%d\\h'-\\n(%du'\\v'%gm'\\\n", 
55                                 REL(-bi,ps), lp[i], lp[i], REL(bi,ps));
56                         break;
57                 case RCOL:
58                         printf("\\v'%gm'\\h'-\\n(%du'\\*(%d\\v'%gm'\\\n", 
59                                 REL(-bi,ps), lp[i], lp[i], REL(bi,ps));
60                         break;
61                 case CCOL:
62                 case COL:
63                         printf("\\v'%gm'\\h'\\n(%du-\\n(%du/2u'\\*(%d", 
64                                 REL(-bi,ps), yyval, lp[i], lp[i]);
65                         printf("\\h'-\\n(%du-\\n(%du/2u'\\v'%gm'\\\n", 
66                                 yyval, lp[i], REL(bi,ps));
67                         break;
68                 }
69                 sb += eht[lp[i]] + gap;
70         }
71         printf("\\v'%gm'\\h'%du*\\n(%du'\n", REL(-ebase[yyval],ps), 
72                 type!=RCOL ? 1 : 0, yyval);
73         for (i = p1; i < p2; i++)
74                 sfree(lp[i]);
75         lfont[yyval] = rfont[yyval] = 0;
76 }