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