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