1 /* $MirOS: src/usr.bin/oldroff/tbl/t5.c,v 1.3 2008/11/08 23:04:53 tg Exp $ */
2
3 /*-
4 * Copyright (c) 1979, 1980, 1981, 1986, 1988, 1990, 1991, 1992
5 * The Regents of the University of California.
6 * Copyright (C) Caldera International Inc. 2001-2002.
7 * Copyright (c) 2003, 2004
8 * Thorsten "mirabilos" Glaser <tg@mirbsd.org>
9 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms,
12 * with or without modification, are permitted provided
13 * that the following conditions are met:
14 *
15 * Redistributions of source code and documentation must retain
16 * the above copyright notice, this list of conditions and the
17 * following disclaimer. Redistributions in binary form must
18 * reproduce the above copyright notice, this list of conditions
19 * and the following disclaimer in the documentation and/or other
20 * materials provided with the distribution.
21 *
22 * All advertising materials mentioning features or use of this
23 * software must display the following acknowledgement:
24 * This product includes software developed or owned by
25 * Caldera International, Inc.
26 *
27 * Neither the name of Caldera International, Inc. nor the names
28 * of other contributors may be used to endorse or promote products
29 * derived from this software without specific prior written permission.
30 *
31 * USE OF THE SOFTWARE PROVIDED FOR UNDER THIS LICENSE BY CALDERA
32 * INTERNATIONAL, INC. AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
33 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
34 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
35 * ARE DISCLAIMED. IN NO EVENT SHALL CALDERA INTERNATIONAL, INC. BE
36 * LIABLE FOR ANY DIRECT, INDIRECT INCIDENTAL, SPECIAL, EXEMPLARY, OR
37 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
38 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
39 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
40 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
41 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
42 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
43 */
44
45 /* t5.c: read data for table */
46
47 # include "t..c"
48 __SCCSID("@(#)t5.c 4.4 (Berkeley) 4/18/91");
49 __RCSID("$MirOS: src/usr.bin/oldroff/tbl/t5.c,v 1.3 2008/11/08 23:04:53 tg Exp $");
50
gettbl()51 gettbl()
52 {
53 extern char *gettext(char *, int, int, char *, char *);
54 int icol, ch;
55 cstore=cspace= chspace();
56 textflg=0;
57 for (nlin=nslin=0; gets1(cstore); nlin++)
58 {
59 stynum[nlin]=nslin;
60 if (prefix(".TE", cstore))
61 {
62 leftover=0;
63 break;
64 }
65 if (prefix(".TC", cstore) || prefix(".T&", cstore))
66 {
67 readspec();
68 nslin++;
69 }
70 if (nlin>=MAXLIN)
71 {
72 leftover=(int)cstore;
73 break;
74 }
75 fullbot[nlin]=0;
76 if (cstore[0] == '.' && !isdigit(cstore[1]))
77 {
78 instead[nlin] = cstore;
79 while (*cstore++);
80 continue;
81 }
82 else instead[nlin] = 0;
83 if (nodata(nlin))
84 {
85 if (ch = oneh(nlin))
86 fullbot[nlin]= ch;
87 nlin++;
88 nslin++;
89 instead[nlin]=(char *)0;
90 fullbot[nlin]=0;
91 }
92 table[nlin] = (struct colstr *)alocv((ncol+2)*sizeof(table[0][0]));
93 if (cstore[1]==0)
94 switch(cstore[0])
95 {
96 case '_': fullbot[nlin]= '-'; continue;
97 case '=': fullbot[nlin]= '='; continue;
98 }
99 stynum[nlin] = nslin;
100 nslin = min(nslin+1, nclin-1);
101 for (icol = 0; icol <ncol; icol++)
102 {
103 table[nlin][icol].col = cstore;
104 table[nlin][icol].rcol=0;
105 ch=1;
106 if (match(cstore, "T{")) /* text follows */
107 table[nlin][icol].col =
108 (char *)gettext(cstore, nlin, icol,
109 font[stynum[nlin]][icol],
110 csize[stynum[nlin]][icol]);
111 else
112 {
113 for(; (ch= *cstore) != '\0' && ch != tab; cstore++)
114 ;
115 *cstore++ = '\0';
116 switch(ctype(nlin,icol)) /* numerical or alpha, subcol */
117 {
118 case 'n':
119 table[nlin][icol].rcol =
120 (char *)maknew(table[nlin][icol].col);
121 break;
122 case 'a':
123 table[nlin][icol].rcol = table[nlin][icol].col;
124 table[nlin][icol].col = "";
125 break;
126 }
127 }
128 while (ctype(nlin,icol+1)== 's') /* spanning */
129 table[nlin][++icol].col = "";
130 if (ch == '\0') break;
131 }
132 while (++icol <ncol+2)
133 {
134 table[nlin][icol].col = "";
135 table [nlin][icol].rcol=0;
136 }
137 while (*cstore != '\0')
138 cstore++;
139 if (cstore-cspace > MAXCHS)
140 cstore = cspace = chspace();
141 }
142 last = cstore;
143 permute();
144 if (textflg) untext();
145 return;
146 }
nodata(il)147 nodata(il)
148 {
149 int c;
150 for (c=0; c<ncol;c++)
151 {
152 switch(ctype(il,c))
153 {
154 case 'c': case 'n': case 'r': case 'l': case 's': case 'a':
155 return(0);
156 }
157 }
158 return(1);
159 }
oneh(lin)160 oneh(lin)
161 {
162 int k, icol;
163 k = ctype(lin,0);
164 for(icol=1; icol<ncol; icol++)
165 {
166 if (k != ctype(lin,icol))
167 return(0);
168 }
169 return(k);
170 }
171 # define SPAN "\\^"
permute()172 permute()
173 {
174 int irow, jcol, is;
175 char *start, *strig;
176 for(jcol=0; jcol<ncol; jcol++)
177 {
178 for(irow=1; irow<nlin; irow++)
179 {
180 if (vspand(irow,jcol,0))
181 {
182 is = prev(irow);
183 if (is<0)
184 error("Vertical spanning in first row not allowed");
185 start = table[is][jcol].col;
186 strig = table[is][jcol].rcol;
187 while (irow<nlin &&vspand(irow,jcol,0))
188 irow++;
189 table[--irow][jcol].col = start;
190 table[irow][jcol].rcol = strig;
191 while (is<irow)
192 {
193 table[is][jcol].rcol =0;
194 table[is][jcol].col= SPAN;
195 is = next(is);
196 }
197 }
198 }
199 }
200 }
vspand(ir,ij,ifform)201 vspand(ir,ij,ifform)
202 {
203 if (ir<0) return(0);
204 if (ir>=nlin)return(0);
205 if (ij<0) return(0);
206 if (ij>(ncol+1))return(0);
207 if (instead[ir]) return(0);
208 if (ifform==0 && ctype(ir,ij)=='^') return(1);
209 if (table[ir] == NULL) return(0);
210 if (table[ir][ij].rcol!=0) return(0);
211 if (fullbot[ir]) return(0);
212 return(vspen(table[ir][ij].col));
213 }
vspen(s)214 vspen(s)
215 char *s;
216 {
217 if (s==0) return(0);
218 if (!point(s)) return(0);
219 return(match(s, SPAN));
220 }
221