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