xref: /onnv-gate/usr/src/cmd/tbl/t5.c (revision 381:1a7f0e46092a)
10Sstevel@tonic-gate /*
2*381Smuffin  * Copyright 2003 Sun Microsystems, Inc.  All rights reserved.
30Sstevel@tonic-gate  * Use is subject to license terms.
40Sstevel@tonic-gate  */
50Sstevel@tonic-gate 
60Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
70Sstevel@tonic-gate /*	  All Rights Reserved  	*/
80Sstevel@tonic-gate 
90Sstevel@tonic-gate /*
100Sstevel@tonic-gate  * Copyright (c) 1980 Regents of the University of California.
110Sstevel@tonic-gate  * All rights reserved. The Berkeley software License Agreement
120Sstevel@tonic-gate  * specifies the terms and conditions for redistribution.
130Sstevel@tonic-gate  */
140Sstevel@tonic-gate 
150Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
160Sstevel@tonic-gate 
170Sstevel@tonic-gate  /* t5.c: read data for table */
180Sstevel@tonic-gate # include "t..c"
19*381Smuffin 
20*381Smuffin void	permute(void);
21*381Smuffin 
22*381Smuffin void
gettbl(void)23*381Smuffin gettbl(void)
240Sstevel@tonic-gate {
250Sstevel@tonic-gate int icol, ch;
260Sstevel@tonic-gate cstore=cspace= chspace();
270Sstevel@tonic-gate textflg=0;
280Sstevel@tonic-gate for (nlin=nslin=0; gets1(cstore, MAXSTR); nlin++)
290Sstevel@tonic-gate 	{
300Sstevel@tonic-gate 	stynum[nlin]=nslin;
310Sstevel@tonic-gate 	if (prefix(".TE", cstore))
320Sstevel@tonic-gate 		{
330Sstevel@tonic-gate 		leftover=0;
340Sstevel@tonic-gate 		break;
350Sstevel@tonic-gate 		}
360Sstevel@tonic-gate 	if (prefix(".TC", cstore) || prefix(".T&", cstore))
370Sstevel@tonic-gate 		{
380Sstevel@tonic-gate 		readspec();
390Sstevel@tonic-gate 		nslin++;
400Sstevel@tonic-gate 		}
410Sstevel@tonic-gate 	if (nlin>=MAXLIN)
420Sstevel@tonic-gate 		{
430Sstevel@tonic-gate 		leftover=cstore;
440Sstevel@tonic-gate 		break;
450Sstevel@tonic-gate 		}
460Sstevel@tonic-gate 	fullbot[nlin]=0;
470Sstevel@tonic-gate 	if (cstore[0] == '.' && !isdigit((unsigned char)cstore[1]))
480Sstevel@tonic-gate 		{
490Sstevel@tonic-gate 		instead[nlin] = cstore;
500Sstevel@tonic-gate 		while (*cstore++);
510Sstevel@tonic-gate 		continue;
520Sstevel@tonic-gate 		}
530Sstevel@tonic-gate 	else instead[nlin] = 0;
540Sstevel@tonic-gate 	if (nodata(nlin))
550Sstevel@tonic-gate 		{
560Sstevel@tonic-gate 		if (ch = oneh(nlin))
570Sstevel@tonic-gate 			fullbot[nlin]= ch;
580Sstevel@tonic-gate 		nlin++;
590Sstevel@tonic-gate 		nslin++;
600Sstevel@tonic-gate 		instead[nlin]=(char *)0;
610Sstevel@tonic-gate 		fullbot[nlin]=0;
620Sstevel@tonic-gate 		}
630Sstevel@tonic-gate 	table[nlin] = (struct colstr *) alocv((ncol+2)*sizeof(table[0][0]));
640Sstevel@tonic-gate 	if (cstore[1]==0)
650Sstevel@tonic-gate 	switch(cstore[0])
660Sstevel@tonic-gate 		{
670Sstevel@tonic-gate 		case '_': fullbot[nlin]= '-'; continue;
680Sstevel@tonic-gate 		case '=': fullbot[nlin]= '='; continue;
690Sstevel@tonic-gate 		}
700Sstevel@tonic-gate 	stynum[nlin] = nslin;
710Sstevel@tonic-gate 	nslin = min(nslin+1, nclin-1);
720Sstevel@tonic-gate 	for (icol = 0; icol <ncol; icol++)
730Sstevel@tonic-gate 		{
740Sstevel@tonic-gate 		table[nlin][icol].col = cstore;
750Sstevel@tonic-gate 		table[nlin][icol].rcol=0;
760Sstevel@tonic-gate 		ch=1;
770Sstevel@tonic-gate 		if (match(cstore, "T{")) /* text follows */
780Sstevel@tonic-gate 			/* get_text was originally gettext and was renamed */
790Sstevel@tonic-gate 			table[nlin][icol].col =
800Sstevel@tonic-gate 				(char *)get_text(cstore, nlin, icol,
810Sstevel@tonic-gate 					font[stynum[nlin]][icol],
820Sstevel@tonic-gate 					csize[stynum[nlin]][icol]);
830Sstevel@tonic-gate 		else
840Sstevel@tonic-gate 			{
850Sstevel@tonic-gate 			for(; (ch= *cstore) != '\0' && ch != tab; cstore++)
860Sstevel@tonic-gate 					;
870Sstevel@tonic-gate 			*cstore++ = '\0';
880Sstevel@tonic-gate 			switch(ctype(nlin,icol)) /* numerical or alpha, subcol */
890Sstevel@tonic-gate 				{
900Sstevel@tonic-gate 				case 'n':
910Sstevel@tonic-gate 					table[nlin][icol].rcol =
920Sstevel@tonic-gate 					    (char *)maknew(table[nlin][icol].col);
930Sstevel@tonic-gate 					break;
940Sstevel@tonic-gate 				case 'a':
950Sstevel@tonic-gate 					table[nlin][icol].rcol = table[nlin][icol].col;
960Sstevel@tonic-gate 					table[nlin][icol].col = "";
970Sstevel@tonic-gate 					break;
980Sstevel@tonic-gate 				}
990Sstevel@tonic-gate 			}
1000Sstevel@tonic-gate 		while (ctype(nlin,icol+1)== 's') /* spanning */
1010Sstevel@tonic-gate 			table[nlin][++icol].col = "";
1020Sstevel@tonic-gate 		if (ch == '\0') break;
1030Sstevel@tonic-gate 		}
1040Sstevel@tonic-gate 	while (++icol <ncol+2)
1050Sstevel@tonic-gate 		{
1060Sstevel@tonic-gate 		table[nlin][icol].col = "";
1070Sstevel@tonic-gate 		table [nlin][icol].rcol=0;
1080Sstevel@tonic-gate 		}
1090Sstevel@tonic-gate 	while (*cstore != '\0')
1100Sstevel@tonic-gate 		 cstore++;
1110Sstevel@tonic-gate 	if (cstore-cspace > MAXCHS)
1120Sstevel@tonic-gate 		cstore = cspace = chspace();
1130Sstevel@tonic-gate 	}
1140Sstevel@tonic-gate last = cstore;
1150Sstevel@tonic-gate permute();
1160Sstevel@tonic-gate if (textflg) untext();
1170Sstevel@tonic-gate return;
1180Sstevel@tonic-gate }
119*381Smuffin 
120*381Smuffin int
nodata(int il)121*381Smuffin nodata(int il)
1220Sstevel@tonic-gate {
1230Sstevel@tonic-gate int c;
1240Sstevel@tonic-gate for (c=0; c<ncol;c++)
1250Sstevel@tonic-gate 	{
1260Sstevel@tonic-gate 	switch(ctype(il,c))
1270Sstevel@tonic-gate 		{
1280Sstevel@tonic-gate 		case 'c': case 'n': case 'r': case 'l': case 's': case 'a':
1290Sstevel@tonic-gate 			return(0);
1300Sstevel@tonic-gate 		}
1310Sstevel@tonic-gate 	}
1320Sstevel@tonic-gate return(1);
1330Sstevel@tonic-gate }
134*381Smuffin 
135*381Smuffin int
oneh(int lin)136*381Smuffin oneh(int lin)
1370Sstevel@tonic-gate {
1380Sstevel@tonic-gate int k, icol;
1390Sstevel@tonic-gate k = ctype(lin,0);
1400Sstevel@tonic-gate for(icol=1; icol<ncol; icol++)
1410Sstevel@tonic-gate 	{
1420Sstevel@tonic-gate 	if (k != ctype(lin,icol))
1430Sstevel@tonic-gate 		return(0);
1440Sstevel@tonic-gate 	}
1450Sstevel@tonic-gate return(k);
1460Sstevel@tonic-gate }
147*381Smuffin 
1480Sstevel@tonic-gate # define SPAN "\\^"
149*381Smuffin 
150*381Smuffin void
permute(void)151*381Smuffin permute(void)
1520Sstevel@tonic-gate {
1530Sstevel@tonic-gate int irow, jcol, is;
1540Sstevel@tonic-gate char *start, *strig;
1550Sstevel@tonic-gate for(jcol=0; jcol<ncol; jcol++)
1560Sstevel@tonic-gate 	{
1570Sstevel@tonic-gate 	for(irow=1; irow<nlin; irow++)
1580Sstevel@tonic-gate 		{
1590Sstevel@tonic-gate 		if (vspand(irow,jcol,0))
1600Sstevel@tonic-gate 			{
1610Sstevel@tonic-gate 			is = prev(irow);
1620Sstevel@tonic-gate 			if (is<0)
1630Sstevel@tonic-gate 				error(gettext("Vertical spanning in first row not allowed"));
1640Sstevel@tonic-gate 			start = table[is][jcol].col;
1650Sstevel@tonic-gate 			strig = table[is][jcol].rcol;
1660Sstevel@tonic-gate 			while (irow<nlin &&vspand(irow,jcol,0))
1670Sstevel@tonic-gate 				irow++;
1680Sstevel@tonic-gate 			table[--irow][jcol].col = start;
1690Sstevel@tonic-gate 			table[irow][jcol].rcol = strig;
1700Sstevel@tonic-gate 			while (is<irow)
1710Sstevel@tonic-gate 				{
1720Sstevel@tonic-gate 				table[is][jcol].rcol =0;
1730Sstevel@tonic-gate 				table[is][jcol].col= SPAN;
1740Sstevel@tonic-gate 				is = next(is);
1750Sstevel@tonic-gate 				}
1760Sstevel@tonic-gate 			}
1770Sstevel@tonic-gate 		}
1780Sstevel@tonic-gate 	}
1790Sstevel@tonic-gate }
180*381Smuffin 
181*381Smuffin int
vspand(int ir,int ij,int ifform)182*381Smuffin vspand(int ir, int ij, int ifform)
1830Sstevel@tonic-gate {
1840Sstevel@tonic-gate if (ir<0) return(0);
1850Sstevel@tonic-gate if (ir>=nlin)return(0);
1860Sstevel@tonic-gate if (instead[ir]) return(0);
1870Sstevel@tonic-gate if (ifform==0 && ctype(ir,ij)=='^') return(1);
1880Sstevel@tonic-gate if (table[ir]==0) return(0);
1890Sstevel@tonic-gate if (table[ir][ij].rcol!=0) return(0);
1900Sstevel@tonic-gate if (fullbot[ir]) return(0);
1910Sstevel@tonic-gate return(vspen(table[ir][ij].col));
1920Sstevel@tonic-gate }
193*381Smuffin 
194*381Smuffin int
vspen(char * s)195*381Smuffin vspen(char *s)
1960Sstevel@tonic-gate {
1970Sstevel@tonic-gate if (s==0) return(0);
1980Sstevel@tonic-gate if (!point(s)) return(0);
1990Sstevel@tonic-gate return(match(s, SPAN));
2000Sstevel@tonic-gate }
201