xref: /illumos-gate/usr/src/cmd/eqn/matrix.c (revision 779fc935)
1*779fc935Sceastha /*
2*779fc935Sceastha  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
3*779fc935Sceastha  * Use is subject to license terms.
4*779fc935Sceastha  */
5*779fc935Sceastha 
67c478bd9Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
77c478bd9Sstevel@tonic-gate /*	  All Rights Reserved  	*/
87c478bd9Sstevel@tonic-gate 
97c478bd9Sstevel@tonic-gate /*
107c478bd9Sstevel@tonic-gate  * Copyright (c) 1980 Regents of the University of California.
117c478bd9Sstevel@tonic-gate  * All rights reserved. The Berkeley software License Agreement
127c478bd9Sstevel@tonic-gate  * specifies the terms and conditions for redistribution.
137c478bd9Sstevel@tonic-gate  */
14*779fc935Sceastha 
15*779fc935Sceastha #pragma ident	"%Z%%M%	%I%	%E% SMI"
167c478bd9Sstevel@tonic-gate 
177c478bd9Sstevel@tonic-gate #include "e.h"
187c478bd9Sstevel@tonic-gate 
19*779fc935Sceastha void
20*779fc935Sceastha column(int type, int p1)
21*779fc935Sceastha {
227c478bd9Sstevel@tonic-gate 	int i;
237c478bd9Sstevel@tonic-gate 
247c478bd9Sstevel@tonic-gate 	lp[p1] = ct - p1 - 1;
25*779fc935Sceastha 	if (dbg) {
267c478bd9Sstevel@tonic-gate 		printf(".\t%d column of", type);
27*779fc935Sceastha 		for (i = p1 + 1; i < ct; i++)
287c478bd9Sstevel@tonic-gate 			printf(" S%d", lp[i]);
29*779fc935Sceastha 		printf(", rows=%d\n", lp[p1]);
307c478bd9Sstevel@tonic-gate 	}
317c478bd9Sstevel@tonic-gate 	lp[ct++] = type;
327c478bd9Sstevel@tonic-gate }
337c478bd9Sstevel@tonic-gate 
34*779fc935Sceastha void
35*779fc935Sceastha matrix(int p1)
36*779fc935Sceastha {
377c478bd9Sstevel@tonic-gate 	int nrow, ncol, i, j, k, hb, b, val[100];
387c478bd9Sstevel@tonic-gate 	char *space;
397c478bd9Sstevel@tonic-gate 
407c478bd9Sstevel@tonic-gate 	space = "\\ \\ ";
417c478bd9Sstevel@tonic-gate 	nrow = lp[p1];	/* disaster if rows inconsistent */
427c478bd9Sstevel@tonic-gate 	ncol = 0;
43*779fc935Sceastha 	for (i = p1; i < ct; i += lp[i] + 2) {
447c478bd9Sstevel@tonic-gate 		ncol++;
45*779fc935Sceastha 		if (dbg) printf(".\tcolct=%d\n", lp[i]);
467c478bd9Sstevel@tonic-gate 	}
47*779fc935Sceastha 	for (k = 1; k <= nrow; k++) {
487c478bd9Sstevel@tonic-gate 		hb = b = 0;
497c478bd9Sstevel@tonic-gate 		j = p1 + k;
50*779fc935Sceastha 		for (i = 0; i < ncol; i++) {
517c478bd9Sstevel@tonic-gate 			hb = max(hb, eht[lp[j]]-ebase[lp[j]]);
527c478bd9Sstevel@tonic-gate 			b = max(b, ebase[lp[j]]);
537c478bd9Sstevel@tonic-gate 			j += nrow + 2;
547c478bd9Sstevel@tonic-gate 		}
55*779fc935Sceastha 		if (dbg) printf(".\trow %d: b=%d, hb=%d\n", k, b, hb);
567c478bd9Sstevel@tonic-gate 		j = p1 + k;
57*779fc935Sceastha 		for (i = 0; i < ncol; i++) {
587c478bd9Sstevel@tonic-gate 			ebase[lp[j]] = b;
597c478bd9Sstevel@tonic-gate 			eht[lp[j]] = b + hb;
607c478bd9Sstevel@tonic-gate 			j += nrow + 2;
617c478bd9Sstevel@tonic-gate 		}
627c478bd9Sstevel@tonic-gate 	}
637c478bd9Sstevel@tonic-gate 	j = p1;
64*779fc935Sceastha 	for (i = 0; i < ncol; i++) {
657c478bd9Sstevel@tonic-gate 		lpile(lp[j+lp[j]+1], j+1, j+lp[j]+1);
667c478bd9Sstevel@tonic-gate 		val[i] = yyval;
677c478bd9Sstevel@tonic-gate 		j += nrow + 2;
687c478bd9Sstevel@tonic-gate 	}
697c478bd9Sstevel@tonic-gate 	yyval = oalloc();
707c478bd9Sstevel@tonic-gate 	eht[yyval] = eht[val[0]];
717c478bd9Sstevel@tonic-gate 	ebase[yyval] = ebase[val[0]];
727c478bd9Sstevel@tonic-gate 	lfont[yyval] = rfont[yyval] = 0;
73*779fc935Sceastha 	if (dbg)
74*779fc935Sceastha 		printf(".\tmatrix S%d: r=%d, c=%d, h=%d, b=%d\n",
75*779fc935Sceastha 		    yyval, nrow, ncol, eht[yyval], ebase[yyval]);
767c478bd9Sstevel@tonic-gate 	printf(".ds %d \"", yyval);
77*779fc935Sceastha 	for (i = 0; i < ncol; i++) {
78*779fc935Sceastha 		printf("\\*(%d%s", val[i], i == ncol-1 ? "" : space);
797c478bd9Sstevel@tonic-gate 		ofree(val[i]);
807c478bd9Sstevel@tonic-gate 	}
817c478bd9Sstevel@tonic-gate 	printf("\n");
827c478bd9Sstevel@tonic-gate 	ct = p1;
837c478bd9Sstevel@tonic-gate }
84