add symlin(1)
[unix-history] / usr / src / old / tbl / t5.c
CommitLineData
94bed826
KB
1/*-
2 * %sccs.include.proprietary.c%
3 */
4
476fcd16 5#ifndef lint
94bed826
KB
6static char sccsid[] = "@(#)t5.c 4.4 (Berkeley) %G%";
7#endif /* not lint */
485ece2d
BS
8
9 /* t5.c: read data for table */
10# include "t..c"
11gettbl()
12{
13int icol, ch;
14cstore=cspace= chspace();
15textflg=0;
16for (nlin=nslin=0; gets1(cstore); nlin++)
17 {
18 stynum[nlin]=nslin;
19 if (prefix(".TE", cstore))
20 {
21 leftover=0;
22 break;
23 }
24 if (prefix(".TC", cstore) || prefix(".T&", cstore))
25 {
26 readspec();
27 nslin++;
28 }
29 if (nlin>=MAXLIN)
30 {
496e6be8 31 leftover=(int)cstore;
485ece2d
BS
32 break;
33 }
34 fullbot[nlin]=0;
35 if (cstore[0] == '.' && !isdigit(cstore[1]))
36 {
37 instead[nlin] = cstore;
38 while (*cstore++);
39 continue;
40 }
41 else instead[nlin] = 0;
42 if (nodata(nlin))
43 {
44 if (ch = oneh(nlin))
45 fullbot[nlin]= ch;
46 nlin++;
47 nslin++;
496e6be8
JB
48 instead[nlin]=(char *)0;
49 fullbot[nlin]=0;
485ece2d 50 }
496e6be8 51 table[nlin] = (struct colstr *)alocv((ncol+2)*sizeof(table[0][0]));
485ece2d
BS
52 if (cstore[1]==0)
53 switch(cstore[0])
54 {
55 case '_': fullbot[nlin]= '-'; continue;
56 case '=': fullbot[nlin]= '='; continue;
57 }
58 stynum[nlin] = nslin;
59 nslin = min(nslin+1, nclin-1);
60 for (icol = 0; icol <ncol; icol++)
61 {
62 table[nlin][icol].col = cstore;
63 table[nlin][icol].rcol=0;
64 ch=1;
65 if (match(cstore, "T{")) /* text follows */
66 table[nlin][icol].col =
496e6be8 67 (char *)gettext(cstore, nlin, icol,
485ece2d
BS
68 font[stynum[nlin]][icol],
69 csize[stynum[nlin]][icol]);
70 else
71 {
72 for(; (ch= *cstore) != '\0' && ch != tab; cstore++)
73 ;
74 *cstore++ = '\0';
75 switch(ctype(nlin,icol)) /* numerical or alpha, subcol */
76 {
77 case 'n':
496e6be8
JB
78 table[nlin][icol].rcol =
79 (char *)maknew(table[nlin][icol].col);
485ece2d
BS
80 break;
81 case 'a':
82 table[nlin][icol].rcol = table[nlin][icol].col;
83 table[nlin][icol].col = "";
84 break;
85 }
86 }
87 while (ctype(nlin,icol+1)== 's') /* spanning */
88 table[nlin][++icol].col = "";
89 if (ch == '\0') break;
90 }
91 while (++icol <ncol+2)
92 {
93 table[nlin][icol].col = "";
94 table [nlin][icol].rcol=0;
95 }
96 while (*cstore != '\0')
97 cstore++;
98 if (cstore-cspace > MAXCHS)
99 cstore = cspace = chspace();
100 }
101last = cstore;
102permute();
103if (textflg) untext();
104return;
105}
106nodata(il)
107{
108int c;
109for (c=0; c<ncol;c++)
110 {
111 switch(ctype(il,c))
112 {
113 case 'c': case 'n': case 'r': case 'l': case 's': case 'a':
114 return(0);
115 }
116 }
117return(1);
118}
119oneh(lin)
120{
121int k, icol;
122k = ctype(lin,0);
123for(icol=1; icol<ncol; icol++)
124 {
125 if (k != ctype(lin,icol))
126 return(0);
127 }
128return(k);
129}
130# define SPAN "\\^"
131permute()
132{
133int irow, jcol, is;
134char *start, *strig;
135for(jcol=0; jcol<ncol; jcol++)
136 {
137 for(irow=1; irow<nlin; irow++)
138 {
139 if (vspand(irow,jcol,0))
140 {
141 is = prev(irow);
142 if (is<0)
143 error("Vertical spanning in first row not allowed");
144 start = table[is][jcol].col;
145 strig = table[is][jcol].rcol;
146 while (irow<nlin &&vspand(irow,jcol,0))
147 irow++;
148 table[--irow][jcol].col = start;
149 table[irow][jcol].rcol = strig;
150 while (is<irow)
151 {
152 table[is][jcol].rcol =0;
153 table[is][jcol].col= SPAN;
154 is = next(is);
155 }
156 }
157 }
158 }
159}
160vspand(ir,ij,ifform)
161{
162if (ir<0) return(0);
163if (ir>=nlin)return(0);
164if (instead[ir]) return(0);
165if (ifform==0 && ctype(ir,ij)=='^') return(1);
166if (table[ir][ij].rcol!=0) return(0);
167if (fullbot[ir]) return(0);
168return(vspen(table[ir][ij].col));
169}
170vspen(s)
171 char *s;
172{
173if (s==0) return(0);
174if (!point(s)) return(0);
175return(match(s, SPAN));
176}