xref: /illumos-gate/usr/src/cmd/eqn/matrix.c (revision 2a8bcb4e)
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 
157c478bd9Sstevel@tonic-gate #include "e.h"
167c478bd9Sstevel@tonic-gate 
17*779fc935Sceastha void
column(int type,int p1)18*779fc935Sceastha column(int type, int p1)
19*779fc935Sceastha {
207c478bd9Sstevel@tonic-gate 	int i;
217c478bd9Sstevel@tonic-gate 
227c478bd9Sstevel@tonic-gate 	lp[p1] = ct - p1 - 1;
23*779fc935Sceastha 	if (dbg) {
247c478bd9Sstevel@tonic-gate 		printf(".\t%d column of", type);
25*779fc935Sceastha 		for (i = p1 + 1; i < ct; i++)
267c478bd9Sstevel@tonic-gate 			printf(" S%d", lp[i]);
27*779fc935Sceastha 		printf(", rows=%d\n", lp[p1]);
287c478bd9Sstevel@tonic-gate 	}
297c478bd9Sstevel@tonic-gate 	lp[ct++] = type;
307c478bd9Sstevel@tonic-gate }
317c478bd9Sstevel@tonic-gate 
32*779fc935Sceastha void
matrix(int p1)33*779fc935Sceastha matrix(int p1)
34*779fc935Sceastha {
357c478bd9Sstevel@tonic-gate 	int nrow, ncol, i, j, k, hb, b, val[100];
367c478bd9Sstevel@tonic-gate 	char *space;
377c478bd9Sstevel@tonic-gate 
387c478bd9Sstevel@tonic-gate 	space = "\\ \\ ";
397c478bd9Sstevel@tonic-gate 	nrow = lp[p1];	/* disaster if rows inconsistent */
407c478bd9Sstevel@tonic-gate 	ncol = 0;
41*779fc935Sceastha 	for (i = p1; i < ct; i += lp[i] + 2) {
427c478bd9Sstevel@tonic-gate 		ncol++;
43*779fc935Sceastha 		if (dbg) printf(".\tcolct=%d\n", lp[i]);
447c478bd9Sstevel@tonic-gate 	}
45*779fc935Sceastha 	for (k = 1; k <= nrow; k++) {
467c478bd9Sstevel@tonic-gate 		hb = b = 0;
477c478bd9Sstevel@tonic-gate 		j = p1 + k;
48*779fc935Sceastha 		for (i = 0; i < ncol; i++) {
497c478bd9Sstevel@tonic-gate 			hb = max(hb, eht[lp[j]]-ebase[lp[j]]);
507c478bd9Sstevel@tonic-gate 			b = max(b, ebase[lp[j]]);
517c478bd9Sstevel@tonic-gate 			j += nrow + 2;
527c478bd9Sstevel@tonic-gate 		}
53*779fc935Sceastha 		if (dbg) printf(".\trow %d: b=%d, hb=%d\n", k, b, hb);
547c478bd9Sstevel@tonic-gate 		j = p1 + k;
55*779fc935Sceastha 		for (i = 0; i < ncol; i++) {
567c478bd9Sstevel@tonic-gate 			ebase[lp[j]] = b;
577c478bd9Sstevel@tonic-gate 			eht[lp[j]] = b + hb;
587c478bd9Sstevel@tonic-gate 			j += nrow + 2;
597c478bd9Sstevel@tonic-gate 		}
607c478bd9Sstevel@tonic-gate 	}
617c478bd9Sstevel@tonic-gate 	j = p1;
62*779fc935Sceastha 	for (i = 0; i < ncol; i++) {
637c478bd9Sstevel@tonic-gate 		lpile(lp[j+lp[j]+1], j+1, j+lp[j]+1);
647c478bd9Sstevel@tonic-gate 		val[i] = yyval;
657c478bd9Sstevel@tonic-gate 		j += nrow + 2;
667c478bd9Sstevel@tonic-gate 	}
677c478bd9Sstevel@tonic-gate 	yyval = oalloc();
687c478bd9Sstevel@tonic-gate 	eht[yyval] = eht[val[0]];
697c478bd9Sstevel@tonic-gate 	ebase[yyval] = ebase[val[0]];
707c478bd9Sstevel@tonic-gate 	lfont[yyval] = rfont[yyval] = 0;
71*779fc935Sceastha 	if (dbg)
72*779fc935Sceastha 		printf(".\tmatrix S%d: r=%d, c=%d, h=%d, b=%d\n",
73*779fc935Sceastha 		    yyval, nrow, ncol, eht[yyval], ebase[yyval]);
747c478bd9Sstevel@tonic-gate 	printf(".ds %d \"", yyval);
75*779fc935Sceastha 	for (i = 0; i < ncol; i++) {
76*779fc935Sceastha 		printf("\\*(%d%s", val[i], i == ncol-1 ? "" : space);
777c478bd9Sstevel@tonic-gate 		ofree(val[i]);
787c478bd9Sstevel@tonic-gate 	}
797c478bd9Sstevel@tonic-gate 	printf("\n");
807c478bd9Sstevel@tonic-gate 	ct = p1;
817c478bd9Sstevel@tonic-gate }
82