date and time created 83/03/09 16:22:19 by ralph
[unix-history] / usr / src / old / tbl / t4.c
CommitLineData
dfef12f4
BS
1/* t4.c 4.1 83/02/12 */
2
3 /* t4.c: read table specification */
4# include "t..c"
5int oncol;
6getspec()
7{
8int icol, i;
9for(icol=0; icol<MAXCOL; icol++)
10 {
11 sep[icol]= -1;
12 evenup[icol]=0;
13 cll[icol][0]=0;
14 for(i=0; i<MAXHEAD; i++)
15 {
16 csize[i][icol][0]=0;
17 vsize[i][icol][0]=0;
18 font[i][icol][0] = lefline[i][icol] = 0;
19 ctop[i][icol]=0;
20 style[i][icol]= 'l';
21 }
22 }
23nclin=ncol=0;
24oncol =0;
25left1flg=rightl=0;
26readspec();
27fprintf(tabout, ".rm");
28for(i=0; i<ncol; i++)
29 fprintf(tabout, " %02d", 80+i);
30fprintf(tabout, "\n");
31}
32readspec()
33{
34int icol, c, sawchar, stopc, i;
35char sn[10], *snp, *temp;
36sawchar=icol=0;
37while (c=get1char())
38 {
39 switch(c)
40 {
41 default:
42 if (c != tab)
43 error("bad table specification character");
44 case ' ': /* note this is also case tab */
45 continue;
46 case '\n':
47 if(sawchar==0) continue;
48 case ',':
49 case '.': /* end of table specification */
50 ncol = max(ncol, icol);
51 if (lefline[nclin][ncol]>0) {ncol++; rightl++;};
52 if(sawchar)
53 nclin++;
54 if (nclin>=MAXHEAD)
55 error("too many lines in specification");
56 icol=0;
57 if (ncol==0 || nclin==0)
58 error("no specification");
59 if (c== '.')
60 {
61 while ((c=get1char()) && c != '\n')
62 if (c != ' ' && c != '\t')
63 error("dot not last character on format line");
64 /* fix up sep - default is 3 except at edge */
65 for(icol=0; icol<ncol; icol++)
66 if (sep[icol]<0)
67 sep[icol] = icol+1<ncol ? 3 : 1;
68 if (oncol == 0)
69 oncol = ncol;
70 else if (oncol +2 <ncol)
71 error("tried to widen table in T&, not allowed");
72 return;
73 }
74 sawchar=0;
75 continue;
76 case 'C': case 'S': case 'R': case 'N': case 'L': case 'A':
77 c += ('a'-'A');
78 case '_': if (c=='_') c= '-';
79 case '=': case '-':
80 case '^':
81 case 'c': case 's': case 'n': case 'r': case 'l': case 'a':
82 style[nclin][icol]=c;
83 if (c== 's' && icol<=0)
84 error("first column can not be S-type");
85 if (c=='s' && style[nclin][icol-1] == 'a')
86 {
87 fprintf(tabout, ".tm warning: can't span a-type cols, changed to l\n");
88 style[nclin][icol-1] = 'l';
89 }
90 if (c=='s' && style[nclin][icol-1] == 'n')
91 {
92 fprintf(tabout, ".tm warning: can't span n-type cols, changed to c\n");
93 style[nclin][icol-1] = 'c';
94 }
95 icol++;
96 if (c=='^' && nclin<=0)
97 error("first row can not contain vertical span");
98 if (icol>=MAXCOL)
99 error("too many columns in table");
100 sawchar=1;
101 continue;
102 case 'b': case 'i':
103 c += 'A'-'a';
104 case 'B': case 'I':
105 if (icol==0) continue;
106 snp=font[nclin][icol-1];
107 snp[0]= (c=='I' ? '2' : '3');
108 snp[1]=0;
109 continue;
110 case 't': case 'T':
111 if (icol>0)
112 ctop[nclin][icol-1] = 1;
113 continue;
114 case 'd': case 'D':
115 if (icol>0)
116 ctop[nclin][icol-1] = -1;
117 continue;
118 case 'f': case 'F':
119 if (icol==0) continue;
120 snp=font[nclin][icol-1];
121 snp[0]=snp[1]=stopc=0;
122 for(i=0; i<2; i++)
123 {
124 c = get1char();
125 if (i==0 && c=='(')
126 {
127 stopc=')';
128 c = get1char();
129 }
130 if (c==0) break;
131 if (c==stopc) {stopc=0; break;}
132 if (stopc==0) if (c==' ' || c== tab ) break;
133 if (c=='\n'){un1getc(c); break;}
134 snp[i] = c;
135 if (c>= '0' && c<= '9') break;
136 }
137 if (stopc) if (get1char()!=stopc)
138 error("Nonterminated font name");
139 continue;
140 case 'P': case 'p':
141 if (icol<=0) continue;
142 temp = snp = csize[nclin][icol-1];
143 while (c = get1char())
144 {
145 if (c== ' ' || c== tab || c=='\n') break;
146 if (c=='-' || c == '+')
147 if (snp>temp)
148 break;
149 else
150 *snp++=c;
151 else
152 if (digit(c))
153 *snp++ = c;
154 else break;
155 if (snp-temp>4)
156 error("point size too large");
157 }
158 *snp = 0;
159 if (atoi(temp)>36)
160 error("point size unreasonable");
161 un1getc (c);
162 continue;
163 case 'V': case 'v':
164 if (icol<=0) continue;
165 temp = snp = vsize[nclin][icol-1];
166 while (c = get1char())
167 {
168 if (c== ' ' || c== tab || c=='\n') break;
169 if (c=='-' || c == '+')
170 if (snp>temp)
171 break;
172 else
173 *snp++=c;
174 else
175 if (digit(c))
176 *snp++ = c;
177 else break;
178 if (snp-temp>4)
179 error("vertical spacing value too large");
180 }
181 *snp=0;
182 un1getc(c);
183 continue;
184 case 'w': case 'W':
185 snp = cll [icol-1];
186 /* Dale Smith didn't like this check - possible to have two text blocks
187 of different widths now ....
188 if (*snp)
189 {
190 fprintf(tabout, "Ignored second width specification");
191 continue;
192 }
193 /* end commented out code ... */
194 stopc=0;
195 while (c = get1char())
196 {
197 if (snp==cll[icol-1] && c=='(')
198 {
199 stopc = ')';
200 continue;
201 }
202 if ( !stopc && (c>'9' || c< '0'))
203 break;
204 if (stopc && c== stopc)
205 break;
206 *snp++ =c;
207 }
208 *snp=0;
209 if (snp-cll[icol-1]>CLLEN)
210 error ("column width too long");
211 if (!stopc)
212 un1getc(c);
213 continue;
214 case 'e': case 'E':
215 if (icol<1) continue;
216 evenup[icol-1]=1;
217 evenflg=1;
218 continue;
219 case '0': case '1': case '2': case '3': case '4':
220 case '5': case '6': case '7': case '8': case '9':
221 sn[0] = c;
222 snp=sn+1;
223 while (digit(*snp++ = c = get1char()))
224 ;
225 un1getc(c);
226 sep[icol-1] = max(sep[icol-1], numb(sn));
227 continue;
228 case '|':
229 lefline[nclin][icol]++;
230 if (icol==0) left1flg=1;
231 continue;
232 }
233 }
234error("EOF reading table specification");
235}