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