xref: /illumos-gate/usr/src/cmd/eqn/matrix.c (revision 7c478bd9)
1 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
2 /*	  All Rights Reserved  	*/
3 
4 
5 /*
6  * Copyright (c) 1980 Regents of the University of California.
7  * All rights reserved. The Berkeley software License Agreement
8  * specifies the terms and conditions for redistribution.
9  */
10 
11 /*
12  * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
13  * All Rights Reserved.
14  */
15 
16 #ident	"%Z%%M%	%I%	%E% SMI"	/* SVr4.0 1.1	*/
17 
18 #include "e.h"
19 
20 column(type, p1) int type, p1; {
21 	int i;
22 
23 	lp[p1] = ct - p1 - 1;
24 	if( dbg ){
25 		printf(".\t%d column of", type);
26 		for( i=p1+1; i<ct; i++ )
27 			printf(" S%d", lp[i]);
28 		printf(", rows=%d\n",lp[p1]);
29 	}
30 	lp[ct++] = type;
31 }
32 
33 matrix(p1) int p1; {
34 	int nrow, ncol, i, j, k, hb, b, val[100];
35 	char *space;
36 
37 	space = "\\ \\ ";
38 	nrow = lp[p1];	/* disaster if rows inconsistent */
39 	ncol = 0;
40 	for( i=p1; i<ct; i += lp[i]+2 ){
41 		ncol++;
42 		if(dbg)printf(".\tcolct=%d\n",lp[i]);
43 	}
44 	for( k=1; k<=nrow; k++ ) {
45 		hb = b = 0;
46 		j = p1 + k;
47 		for( i=0; i<ncol; i++ ) {
48 			hb = max(hb, eht[lp[j]]-ebase[lp[j]]);
49 			b = max(b, ebase[lp[j]]);
50 			j += nrow + 2;
51 		}
52 		if(dbg)printf(".\trow %d: b=%d, hb=%d\n", k, b, hb);
53 		j = p1 + k;
54 		for( i=0; i<ncol; i++ ) {
55 			ebase[lp[j]] = b;
56 			eht[lp[j]] = b + hb;
57 			j += nrow + 2;
58 		}
59 	}
60 	j = p1;
61 	for( i=0; i<ncol; i++ ) {
62 		lpile(lp[j+lp[j]+1], j+1, j+lp[j]+1);
63 		val[i] = yyval;
64 		j += nrow + 2;
65 	}
66 	yyval = oalloc();
67 	eht[yyval] = eht[val[0]];
68 	ebase[yyval] = ebase[val[0]];
69 	lfont[yyval] = rfont[yyval] = 0;
70 	if(dbg)printf(".\tmatrix S%d: r=%d, c=%d, h=%d, b=%d\n",
71 		yyval,nrow,ncol,eht[yyval],ebase[yyval]);
72 	printf(".ds %d \"", yyval);
73 	for( i=0; i<ncol; i++ )  {
74 		printf("\\*(%d%s", val[i], i==ncol-1 ? "" : space);
75 		ofree(val[i]);
76 	}
77 	printf("\n");
78 	ct = p1;
79 }
80