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