xref: /original-bsd/old/eqn/common_source/matrix.c (revision 6e73d10f)
1 /*-
2  * Copyright (c) 1991 The Regents of the University of California.
3  * All rights reserved.
4  *
5  * %sccs.include.proprietary.c%
6  */
7 
8 #ifndef lint
9 static char sccsid[] = "@(#)matrix.c	4.3 (Berkeley) 04/17/91";
10 #endif /* not lint */
11 
12 #include "e.h"
13 
14 column(type, p1) int type, p1; {
15 	int i;
16 
17 	lp[p1] = ct - p1 - 1;
18 	if( dbg ){
19 		printf(".\t%d column of", type);
20 		for( i=p1+1; i<ct; i++ )
21 			printf(" S%d", lp[i]);
22 		printf(", rows=%d\n",lp[p1]);
23 	}
24 	lp[ct++] = type;
25 }
26 
27 matrix(p1) int p1; {
28 	int nrow, ncol, i, j, k, hb, b, val[100];
29 	char *space;
30 
31 	space = "\\ \\ ";
32 	nrow = lp[p1];	/* disaster if rows inconsistent */
33 	ncol = 0;
34 	for( i=p1; i<ct; i += lp[i]+2 ){
35 		ncol++;
36 		if(dbg)printf(".\tcolct=%d\n",lp[i]);
37 	}
38 	for( k=1; k<=nrow; k++ ) {
39 		hb = b = 0;
40 		j = p1 + k;
41 		for( i=0; i<ncol; i++ ) {
42 			hb = max(hb, eht[lp[j]]-ebase[lp[j]]);
43 			b = max(b, ebase[lp[j]]);
44 			j += nrow + 2;
45 		}
46 		if(dbg)printf(".\trow %d: b=%d, hb=%d\n", k, b, hb);
47 		j = p1 + k;
48 		for( i=0; i<ncol; i++ ) {
49 			ebase[lp[j]] = b;
50 			eht[lp[j]] = b + hb;
51 			j += nrow + 2;
52 		}
53 	}
54 	j = p1;
55 	for( i=0; i<ncol; i++ ) {
56 		lpile(lp[j+lp[j]+1], j+1, j+lp[j]+1);
57 		val[i] = yyval;
58 		j += nrow + 2;
59 	}
60 	yyval = oalloc();
61 	eht[yyval] = eht[val[0]];
62 	ebase[yyval] = ebase[val[0]];
63 	lfont[yyval] = rfont[yyval] = 0;
64 	if(dbg)printf(".\tmatrix S%d: r=%d, c=%d, h=%d, b=%d\n",
65 		yyval,nrow,ncol,eht[yyval],ebase[yyval]);
66 	printf(".ds %d \"", yyval);
67 	for( i=0; i<ncol; i++ )  {
68 		printf("\\*(%d%s", val[i], i==ncol-1 ? "" : space);
69 		ofree(val[i]);
70 	}
71 	printf("\n");
72 	ct = p1;
73 }
74