pile.c 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. * This file is part of the UCB release of Plan 9. It is subject to the license
  3. * terms in the LICENSE file found in the top-level directory of this
  4. * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  5. * part of the UCB release of Plan 9, including this file, may be copied,
  6. * modified, propagated, or distributed except according to the terms contained
  7. * in the LICENSE file.
  8. */
  9. #include "e.h"
  10. #include "y.tab.h"
  11. void pile(int oct)
  12. {
  13. int i, nlist, nlist2, mid;
  14. double bi, h, b, gap, sb;
  15. extern double Pilegap, Pilebase;
  16. int type, p1, p2;
  17. yyval = salloc();
  18. type = lp[oct];
  19. p1 = oct + 3; /* first entry */
  20. p2 = p1 + lp[oct+1]; /* 1 after last */
  21. gap = lp[oct+2];
  22. if (gap != DEFGAP)
  23. gap = EM(gap/100.0, ps);
  24. else if (type == COL)
  25. gap = 0;
  26. else
  27. gap = EM(Pilegap, ps); /* 0.4 m between LCOL, etc. */
  28. nlist = p2 - p1;
  29. nlist2 = (nlist+1)/2;
  30. mid = p1 + nlist2 - 1;
  31. h = 0;
  32. for (i = p1; i < p2; i++)
  33. h += eht[lp[i]];
  34. eht[yyval] = h + (nlist-1)*gap;
  35. b = 0;
  36. for (i = p2-1; i > mid; i--)
  37. b += eht[lp[i]] + gap;
  38. ebase[yyval] = (nlist%2) ? b + ebase[lp[mid]]
  39. : b - EM(Pilebase, ps) - gap;
  40. if (dbg) {
  41. printf(".\tS%d <- %d pile of:", yyval, type);
  42. for (i = p1; i < p2; i++)
  43. printf(" S%d", lp[i]);
  44. printf("; h=%g b=%g\n", eht[yyval], ebase[yyval]);
  45. }
  46. nrwid(lp[p1], ps, lp[p1]);
  47. printf(".nr %d \\n(%d\n", yyval, lp[p1]);
  48. for (i = p1+1; i < p2; i++) {
  49. nrwid(lp[i], ps, lp[i]);
  50. printf(".if \\n(%d>\\n(%d .nr %d \\n(%d\n",
  51. lp[i], yyval, yyval, lp[i]);
  52. }
  53. printf(".ds %d \\v'%gm'\\h'%du*\\n(%du'\\\n", yyval, REL(ebase[yyval],ps),
  54. type==RCOL ? 1 : 0, yyval);
  55. sb = 0; /* sum of box hts */
  56. for (i = p2-1; i >= p1; i--) {
  57. bi = sb + ebase[lp[i]];
  58. switch (type) {
  59. case LCOL:
  60. printf("\\v'%gm'\\*(%d\\h'-\\n(%du'\\v'%gm'\\\n",
  61. REL(-bi,ps), lp[i], lp[i], REL(bi,ps));
  62. break;
  63. case RCOL:
  64. printf("\\v'%gm'\\h'-\\n(%du'\\*(%d\\v'%gm'\\\n",
  65. REL(-bi,ps), lp[i], lp[i], REL(bi,ps));
  66. break;
  67. case CCOL:
  68. case COL:
  69. printf("\\v'%gm'\\h'\\n(%du-\\n(%du/2u'\\*(%d",
  70. REL(-bi,ps), yyval, lp[i], lp[i]);
  71. printf("\\h'-\\n(%du-\\n(%du/2u'\\v'%gm'\\\n",
  72. yyval, lp[i], REL(bi,ps));
  73. break;
  74. }
  75. sb += eht[lp[i]] + gap;
  76. }
  77. printf("\\v'%gm'\\h'%du*\\n(%du'\n", REL(-ebase[yyval],ps),
  78. type!=RCOL ? 1 : 0, yyval);
  79. for (i = p1; i < p2; i++)
  80. sfree(lp[i]);
  81. lfont[yyval] = rfont[yyval] = 0;
  82. }