matrix.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. startcol(int type) /* mark start of column in lp[] array */
  11. {
  12. int oct = ct;
  13. lp[ct++] = type;
  14. lp[ct++] = 0; /* count, to come */
  15. lp[ct++] = 0; /* separation, to come */
  16. return oct;
  17. }
  18. void column(int oct, int sep) /* remember end of column that started at lp[oct] */
  19. {
  20. int i, type;
  21. lp[oct+1] = ct - oct - 3;
  22. lp[oct+2] = sep;
  23. type = lp[oct];
  24. if (dbg) {
  25. printf(".\t%d column of", type);
  26. for (i = oct+3; i < ct; i++ )
  27. printf(" S%d", lp[i]);
  28. printf(", rows=%d, sep=%d\n", lp[oct+1], lp[oct+2]);
  29. }
  30. }
  31. void matrix(int oct) /* matrix is list of columns */
  32. {
  33. int nrow, ncol, i, j, k, val[100];
  34. double b, hb;
  35. char *space;
  36. extern char *Matspace;
  37. space = Matspace; /* between columns of matrix */
  38. nrow = lp[oct+1]; /* disaster if rows inconsistent */
  39. /* also assumes just columns */
  40. /* fix when add other things */
  41. ncol = 0;
  42. for (i = oct+1; i < ct; i += lp[i]+3 ) {
  43. ncol++;
  44. dprintf(".\tcolct=%d\n", lp[i]);
  45. }
  46. for (k=1; k <= nrow; k++) {
  47. hb = b = 0;
  48. j = oct + k + 2;
  49. for (i=0; i < ncol; i++) {
  50. hb = max(hb, eht[lp[j]]-ebase[lp[j]]);
  51. b = max(b, ebase[lp[j]]);
  52. j += nrow + 3;
  53. }
  54. dprintf(".\trow %d: b=%g, hb=%g\n", k, b, hb);
  55. j = oct + k + 2;
  56. for (i=0; i<ncol; i++) {
  57. ebase[lp[j]] = b;
  58. eht[lp[j]] = b + hb;
  59. j += nrow + 3;
  60. }
  61. }
  62. j = oct;
  63. for (i=0; i<ncol; i++) {
  64. pile(j);
  65. val[i] = yyval;
  66. j += nrow + 3;
  67. }
  68. yyval = salloc();
  69. eht[yyval] = eht[val[0]];
  70. ebase[yyval] = ebase[val[0]];
  71. lfont[yyval] = rfont[yyval] = 0;
  72. dprintf(".\tmatrix S%d: r=%d, c=%d, h=%g, b=%g\n",
  73. yyval,nrow,ncol,eht[yyval],ebase[yyval]);
  74. printf(".ds %d \"", yyval);
  75. for( i=0; i<ncol; i++ ) {
  76. printf("\\*(%d%s", val[i], i==ncol-1 ? "" : space);
  77. sfree(val[i]);
  78. }
  79. printf("\n");
  80. }