1*48252Sbostic /*-
2*48252Sbostic * Copyright (c) 1991 The Regents of the University of California.
3*48252Sbostic * All rights reserved.
4*48252Sbostic *
5*48252Sbostic * %sccs.include.proprietary.c%
6*48252Sbostic */
7*48252Sbostic
814486Ssam #ifndef lint
9*48252Sbostic static char sccsid[] = "@(#)matrix.c 4.3 (Berkeley) 04/17/91";
10*48252Sbostic #endif /* not lint */
1111011Sshannon
1211011Sshannon #include "e.h"
1311011Sshannon
column(type,p1)1411011Sshannon column(type, p1) int type, p1; {
1511011Sshannon int i;
1611011Sshannon
1711011Sshannon lp[p1] = ct - p1 - 1;
1811011Sshannon if( dbg ){
1911011Sshannon printf(".\t%d column of", type);
2011011Sshannon for( i=p1+1; i<ct; i++ )
2111011Sshannon printf(" S%d", lp[i]);
2211011Sshannon printf(", rows=%d\n",lp[p1]);
2311011Sshannon }
2411011Sshannon lp[ct++] = type;
2511011Sshannon }
2611011Sshannon
matrix(p1)2711011Sshannon matrix(p1) int p1; {
2811011Sshannon int nrow, ncol, i, j, k, hb, b, val[100];
2911011Sshannon char *space;
3011011Sshannon
3111011Sshannon space = "\\ \\ ";
3211011Sshannon nrow = lp[p1]; /* disaster if rows inconsistent */
3311011Sshannon ncol = 0;
3411011Sshannon for( i=p1; i<ct; i += lp[i]+2 ){
3511011Sshannon ncol++;
3611011Sshannon if(dbg)printf(".\tcolct=%d\n",lp[i]);
3711011Sshannon }
3811011Sshannon for( k=1; k<=nrow; k++ ) {
3911011Sshannon hb = b = 0;
4011011Sshannon j = p1 + k;
4111011Sshannon for( i=0; i<ncol; i++ ) {
4211011Sshannon hb = max(hb, eht[lp[j]]-ebase[lp[j]]);
4311011Sshannon b = max(b, ebase[lp[j]]);
4411011Sshannon j += nrow + 2;
4511011Sshannon }
4611011Sshannon if(dbg)printf(".\trow %d: b=%d, hb=%d\n", k, b, hb);
4711011Sshannon j = p1 + k;
4811011Sshannon for( i=0; i<ncol; i++ ) {
4911011Sshannon ebase[lp[j]] = b;
5011011Sshannon eht[lp[j]] = b + hb;
5111011Sshannon j += nrow + 2;
5211011Sshannon }
5311011Sshannon }
5411011Sshannon j = p1;
5511011Sshannon for( i=0; i<ncol; i++ ) {
5611011Sshannon lpile(lp[j+lp[j]+1], j+1, j+lp[j]+1);
5711011Sshannon val[i] = yyval;
5811011Sshannon j += nrow + 2;
5911011Sshannon }
6011011Sshannon yyval = oalloc();
6111011Sshannon eht[yyval] = eht[val[0]];
6211011Sshannon ebase[yyval] = ebase[val[0]];
6311011Sshannon lfont[yyval] = rfont[yyval] = 0;
6411011Sshannon if(dbg)printf(".\tmatrix S%d: r=%d, c=%d, h=%d, b=%d\n",
6511011Sshannon yyval,nrow,ncol,eht[yyval],ebase[yyval]);
6611011Sshannon printf(".ds %d \"", yyval);
6711011Sshannon for( i=0; i<ncol; i++ ) {
6811011Sshannon printf("\\*(%d%s", val[i], i==ncol-1 ? "" : space);
6911011Sshannon ofree(val[i]);
7011011Sshannon }
7111011Sshannon printf("\n");
7211011Sshannon ct = p1;
7311011Sshannon }
74