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