plan9port

fork of plan9port with libvec, libstr and libsdb
Log | Files | Refs | README | LICENSE

matrix.c (1760B)


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