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