xref: /onnv-gate/usr/src/cmd/tbl/t5.c (revision 0)
1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate  * Copyright 1983-2003 Sun Microsystems, Inc.  All rights reserved.
3*0Sstevel@tonic-gate  * Use is subject to license terms.
4*0Sstevel@tonic-gate  */
5*0Sstevel@tonic-gate 
6*0Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
7*0Sstevel@tonic-gate /*	  All Rights Reserved  	*/
8*0Sstevel@tonic-gate 
9*0Sstevel@tonic-gate 
10*0Sstevel@tonic-gate /*
11*0Sstevel@tonic-gate  * Copyright (c) 1980 Regents of the University of California.
12*0Sstevel@tonic-gate  * All rights reserved. The Berkeley software License Agreement
13*0Sstevel@tonic-gate  * specifies the terms and conditions for redistribution.
14*0Sstevel@tonic-gate  */
15*0Sstevel@tonic-gate 
16*0Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
17*0Sstevel@tonic-gate 
18*0Sstevel@tonic-gate  /* t5.c: read data for table */
19*0Sstevel@tonic-gate # include "t..c"
20*0Sstevel@tonic-gate gettbl()
21*0Sstevel@tonic-gate {
22*0Sstevel@tonic-gate int icol, ch;
23*0Sstevel@tonic-gate cstore=cspace= chspace();
24*0Sstevel@tonic-gate textflg=0;
25*0Sstevel@tonic-gate for (nlin=nslin=0; gets1(cstore, MAXSTR); nlin++)
26*0Sstevel@tonic-gate 	{
27*0Sstevel@tonic-gate 	stynum[nlin]=nslin;
28*0Sstevel@tonic-gate 	if (prefix(".TE", cstore))
29*0Sstevel@tonic-gate 		{
30*0Sstevel@tonic-gate 		leftover=0;
31*0Sstevel@tonic-gate 		break;
32*0Sstevel@tonic-gate 		}
33*0Sstevel@tonic-gate 	if (prefix(".TC", cstore) || prefix(".T&", cstore))
34*0Sstevel@tonic-gate 		{
35*0Sstevel@tonic-gate 		readspec();
36*0Sstevel@tonic-gate 		nslin++;
37*0Sstevel@tonic-gate 		}
38*0Sstevel@tonic-gate 	if (nlin>=MAXLIN)
39*0Sstevel@tonic-gate 		{
40*0Sstevel@tonic-gate 		leftover=cstore;
41*0Sstevel@tonic-gate 		break;
42*0Sstevel@tonic-gate 		}
43*0Sstevel@tonic-gate 	fullbot[nlin]=0;
44*0Sstevel@tonic-gate 	if (cstore[0] == '.' && !isdigit((unsigned char)cstore[1]))
45*0Sstevel@tonic-gate 		{
46*0Sstevel@tonic-gate 		instead[nlin] = cstore;
47*0Sstevel@tonic-gate 		while (*cstore++);
48*0Sstevel@tonic-gate 		continue;
49*0Sstevel@tonic-gate 		}
50*0Sstevel@tonic-gate 	else instead[nlin] = 0;
51*0Sstevel@tonic-gate 	if (nodata(nlin))
52*0Sstevel@tonic-gate 		{
53*0Sstevel@tonic-gate 		if (ch = oneh(nlin))
54*0Sstevel@tonic-gate 			fullbot[nlin]= ch;
55*0Sstevel@tonic-gate 		nlin++;
56*0Sstevel@tonic-gate 		nslin++;
57*0Sstevel@tonic-gate 		instead[nlin]=(char *)0;
58*0Sstevel@tonic-gate 		fullbot[nlin]=0;
59*0Sstevel@tonic-gate 		}
60*0Sstevel@tonic-gate 	table[nlin] = (struct colstr *) alocv((ncol+2)*sizeof(table[0][0]));
61*0Sstevel@tonic-gate 	if (cstore[1]==0)
62*0Sstevel@tonic-gate 	switch(cstore[0])
63*0Sstevel@tonic-gate 		{
64*0Sstevel@tonic-gate 		case '_': fullbot[nlin]= '-'; continue;
65*0Sstevel@tonic-gate 		case '=': fullbot[nlin]= '='; continue;
66*0Sstevel@tonic-gate 		}
67*0Sstevel@tonic-gate 	stynum[nlin] = nslin;
68*0Sstevel@tonic-gate 	nslin = min(nslin+1, nclin-1);
69*0Sstevel@tonic-gate 	for (icol = 0; icol <ncol; icol++)
70*0Sstevel@tonic-gate 		{
71*0Sstevel@tonic-gate 		table[nlin][icol].col = cstore;
72*0Sstevel@tonic-gate 		table[nlin][icol].rcol=0;
73*0Sstevel@tonic-gate 		ch=1;
74*0Sstevel@tonic-gate 		if (match(cstore, "T{")) /* text follows */
75*0Sstevel@tonic-gate 			/* get_text was originally gettext and was renamed */
76*0Sstevel@tonic-gate 			table[nlin][icol].col =
77*0Sstevel@tonic-gate 				(char *)get_text(cstore, nlin, icol,
78*0Sstevel@tonic-gate 					font[stynum[nlin]][icol],
79*0Sstevel@tonic-gate 					csize[stynum[nlin]][icol]);
80*0Sstevel@tonic-gate 		else
81*0Sstevel@tonic-gate 			{
82*0Sstevel@tonic-gate 			for(; (ch= *cstore) != '\0' && ch != tab; cstore++)
83*0Sstevel@tonic-gate 					;
84*0Sstevel@tonic-gate 			*cstore++ = '\0';
85*0Sstevel@tonic-gate 			switch(ctype(nlin,icol)) /* numerical or alpha, subcol */
86*0Sstevel@tonic-gate 				{
87*0Sstevel@tonic-gate 				case 'n':
88*0Sstevel@tonic-gate 					table[nlin][icol].rcol =
89*0Sstevel@tonic-gate 					    (char *)maknew(table[nlin][icol].col);
90*0Sstevel@tonic-gate 					break;
91*0Sstevel@tonic-gate 				case 'a':
92*0Sstevel@tonic-gate 					table[nlin][icol].rcol = table[nlin][icol].col;
93*0Sstevel@tonic-gate 					table[nlin][icol].col = "";
94*0Sstevel@tonic-gate 					break;
95*0Sstevel@tonic-gate 				}
96*0Sstevel@tonic-gate 			}
97*0Sstevel@tonic-gate 		while (ctype(nlin,icol+1)== 's') /* spanning */
98*0Sstevel@tonic-gate 			table[nlin][++icol].col = "";
99*0Sstevel@tonic-gate 		if (ch == '\0') break;
100*0Sstevel@tonic-gate 		}
101*0Sstevel@tonic-gate 	while (++icol <ncol+2)
102*0Sstevel@tonic-gate 		{
103*0Sstevel@tonic-gate 		table[nlin][icol].col = "";
104*0Sstevel@tonic-gate 		table [nlin][icol].rcol=0;
105*0Sstevel@tonic-gate 		}
106*0Sstevel@tonic-gate 	while (*cstore != '\0')
107*0Sstevel@tonic-gate 		 cstore++;
108*0Sstevel@tonic-gate 	if (cstore-cspace > MAXCHS)
109*0Sstevel@tonic-gate 		cstore = cspace = chspace();
110*0Sstevel@tonic-gate 	}
111*0Sstevel@tonic-gate last = cstore;
112*0Sstevel@tonic-gate permute();
113*0Sstevel@tonic-gate if (textflg) untext();
114*0Sstevel@tonic-gate return;
115*0Sstevel@tonic-gate }
116*0Sstevel@tonic-gate nodata(il)
117*0Sstevel@tonic-gate {
118*0Sstevel@tonic-gate int c;
119*0Sstevel@tonic-gate for (c=0; c<ncol;c++)
120*0Sstevel@tonic-gate 	{
121*0Sstevel@tonic-gate 	switch(ctype(il,c))
122*0Sstevel@tonic-gate 		{
123*0Sstevel@tonic-gate 		case 'c': case 'n': case 'r': case 'l': case 's': case 'a':
124*0Sstevel@tonic-gate 			return(0);
125*0Sstevel@tonic-gate 		}
126*0Sstevel@tonic-gate 	}
127*0Sstevel@tonic-gate return(1);
128*0Sstevel@tonic-gate }
129*0Sstevel@tonic-gate oneh(lin)
130*0Sstevel@tonic-gate {
131*0Sstevel@tonic-gate int k, icol;
132*0Sstevel@tonic-gate k = ctype(lin,0);
133*0Sstevel@tonic-gate for(icol=1; icol<ncol; icol++)
134*0Sstevel@tonic-gate 	{
135*0Sstevel@tonic-gate 	if (k != ctype(lin,icol))
136*0Sstevel@tonic-gate 		return(0);
137*0Sstevel@tonic-gate 	}
138*0Sstevel@tonic-gate return(k);
139*0Sstevel@tonic-gate }
140*0Sstevel@tonic-gate # define SPAN "\\^"
141*0Sstevel@tonic-gate permute()
142*0Sstevel@tonic-gate {
143*0Sstevel@tonic-gate int irow, jcol, is;
144*0Sstevel@tonic-gate char *start, *strig;
145*0Sstevel@tonic-gate for(jcol=0; jcol<ncol; jcol++)
146*0Sstevel@tonic-gate 	{
147*0Sstevel@tonic-gate 	for(irow=1; irow<nlin; irow++)
148*0Sstevel@tonic-gate 		{
149*0Sstevel@tonic-gate 		if (vspand(irow,jcol,0))
150*0Sstevel@tonic-gate 			{
151*0Sstevel@tonic-gate 			is = prev(irow);
152*0Sstevel@tonic-gate 			if (is<0)
153*0Sstevel@tonic-gate 				error(gettext("Vertical spanning in first row not allowed"));
154*0Sstevel@tonic-gate 			start = table[is][jcol].col;
155*0Sstevel@tonic-gate 			strig = table[is][jcol].rcol;
156*0Sstevel@tonic-gate 			while (irow<nlin &&vspand(irow,jcol,0))
157*0Sstevel@tonic-gate 				irow++;
158*0Sstevel@tonic-gate 			table[--irow][jcol].col = start;
159*0Sstevel@tonic-gate 			table[irow][jcol].rcol = strig;
160*0Sstevel@tonic-gate 			while (is<irow)
161*0Sstevel@tonic-gate 				{
162*0Sstevel@tonic-gate 				table[is][jcol].rcol =0;
163*0Sstevel@tonic-gate 				table[is][jcol].col= SPAN;
164*0Sstevel@tonic-gate 				is = next(is);
165*0Sstevel@tonic-gate 				}
166*0Sstevel@tonic-gate 			}
167*0Sstevel@tonic-gate 		}
168*0Sstevel@tonic-gate 	}
169*0Sstevel@tonic-gate }
170*0Sstevel@tonic-gate vspand(ir,ij,ifform)
171*0Sstevel@tonic-gate {
172*0Sstevel@tonic-gate if (ir<0) return(0);
173*0Sstevel@tonic-gate if (ir>=nlin)return(0);
174*0Sstevel@tonic-gate if (instead[ir]) return(0);
175*0Sstevel@tonic-gate if (ifform==0 && ctype(ir,ij)=='^') return(1);
176*0Sstevel@tonic-gate if (table[ir]==0) return(0);
177*0Sstevel@tonic-gate if (table[ir][ij].rcol!=0) return(0);
178*0Sstevel@tonic-gate if (fullbot[ir]) return(0);
179*0Sstevel@tonic-gate return(vspen(table[ir][ij].col));
180*0Sstevel@tonic-gate }
181*0Sstevel@tonic-gate vspen(s)
182*0Sstevel@tonic-gate 	char *s;
183*0Sstevel@tonic-gate {
184*0Sstevel@tonic-gate if (s==0) return(0);
185*0Sstevel@tonic-gate if (!point(s)) return(0);
186*0Sstevel@tonic-gate return(match(s, SPAN));
187*0Sstevel@tonic-gate }
188