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