1 /* t4.c: read table specification */
10 qcol = findcol() + 1;/* must allow one extra for line at right */
13 for (icol = 0; icol < qcol; icol++) {
17 for (i = 0; i < MAXHEAD; i++) {
18 csize[icol][i][0] = 0;
19 vsize[icol][i][0] = 0;
20 font[icol][i][0] = lefline[icol][i] = 0;
25 for (i = 0; i < MAXHEAD; i++)
26 lefline[qcol][i] = 0; /* fixes sample55 looping */
29 left1flg = rightl = 0;
31 Bprint(&tabout, ".rm");
32 for (i = 0; i < ncol; i++)
33 Bprint(&tabout, " %2s", reg(i, CRIGHT));
34 Bprint(&tabout, "\n");
41 int icol, c, sawchar, stopc, i;
42 char sn[10], *snp, *temp;
45 while (c = get1char()) {
50 sprint(buf, "bad table specification character %c", c);
53 case ' ': /* note this is also case tab */
59 case '.': /* end of table specification */
60 ncol = max(ncol, icol);
61 if (lefline[ncol][nclin] > 0) {
68 error("too many lines in specification");
70 if (ncol == 0 || nclin == 0)
71 error("no specification");
73 while ((c = get1char()) && c != '\n')
74 if (c != ' ' && c != '\t')
75 error("dot not last character on format line");
76 /* fix up sep - default is 3 except at edge */
77 for (icol = 0; icol < ncol; icol++)
79 sep[icol] = icol + 1 < ncol ? 3 : 2;
82 else if (oncol + 2 < ncol)
83 error("tried to widen table in T&, not allowed");
107 style[icol][nclin] = c;
108 if (c == 's' && icol <= 0)
109 error("first column can not be S-type");
110 if (c == 's' && style[icol-1][nclin] == 'a') {
111 Bprint(&tabout, ".tm warning: can't span a-type cols, changed to l\n");
112 style[icol-1][nclin] = 'l';
114 if (c == 's' && style[icol-1][nclin] == 'n') {
115 Bprint(&tabout, ".tm warning: can't span n-type cols, changed to c\n");
116 style[icol-1][nclin] = 'c';
119 if (c == '^' && nclin <= 0)
120 error("first row can not contain vertical span");
122 error("too many columns in table");
132 snp = font[icol-1][nclin];
133 snp[0] = (c == 'I' ? '2' : '3');
139 flags[icol-1][nclin] |= CTOP;
144 flags[icol-1][nclin] |= CDOWN;
150 snp = font[icol-1][nclin];
151 snp[0] = snp[1] = stopc = 0;
152 for (i = 0; i < 2; i++) {
154 if (i == 0 && c == '(') {
165 if (c == ' ' || c == tab )
167 if (c == '\n' || c == '|') {
172 if (c >= '0' && c <= '9')
176 if (get1char() != stopc)
177 error("Nonterminated font name");
183 temp = snp = csize[icol-1][nclin];
184 while (c = get1char()) {
185 if (c == ' ' || c == tab || c == '\n')
187 if (c == '-' || c == '+')
197 error("point size too large");
201 error("point size unreasonable");
208 temp = snp = vsize[icol-1][nclin];
209 while (c = get1char()) {
210 if (c == ' ' || c == tab || c == '\n')
212 if (c == '-' || c == '+')
222 error("vertical spacing value too large");
230 /* Dale Smith didn't like this check - possible to have two text blocks
231 of different widths now ....
234 Bprint(&tabout, "Ignored second width specification");
237 /* end commented out code ... */
239 while (c = get1char()) {
240 if (snp == cll[icol-1] && c == '(') {
244 if ( !stopc && (c > '9' || c < '0'))
246 if (stopc && c == stopc)
251 if (snp - cll[icol-1] > CLLEN)
252 error ("column width too long");
264 case 'Z': /* zero width-ignre width this item */
267 flags[icol-1][nclin] |= ZEROW;
270 case 'U': /* half line up */
273 flags[icol-1][nclin] |= HALFUP;
287 while (digit(*snp++ = c = get1char()))
290 sep[icol-1] = max(sep[icol-1], numb(sn));
293 lefline[icol][nclin]++;
299 error("EOF reading table specification");
307 /* this counts the number of columns and then puts the line back*/
308 char *s, line[FLNLIM+2], *p;
309 int c, n = 0, inpar = 0;
311 while ((c = get1char()) != 0 && c == ' ')
315 for (s = line; *s = c = get1char(); s++) {
320 if (c == '\n' || c == 0 || c == '.' || c == ',')
324 else if (s >= line + FLNLIM)
325 error("too long spec line");
327 for (p = line; p < s; p++)
355 style = (int (*)[]) getcore(MAXHEAD * qcol, sizeof(int));
356 evenup = (int *) getcore(qcol, sizeof(int));
357 lefline = (int (*)[]) getcore(MAXHEAD * (qcol + 1), sizeof (int)); /*+1 for sample55 loop - others may need it too*/
358 font = (char (*)[][2]) getcore(MAXHEAD * qcol, 2);
359 csize = (char (*)[MAXHEAD][4]) getcore(MAXHEAD * qcol, 4);
360 vsize = (char (*)[MAXHEAD][4]) getcore(MAXHEAD * qcol, 4);
361 flags = (int (*)[]) getcore(MAXHEAD * qcol, sizeof(int));
362 cll = (char (*)[])getcore(qcol, CLLEN);
363 sep = (int *) getcore(qcol + 1, sizeof(int));
364 sep++; /* sep[-1] must be legal */
365 used = (int *) getcore(qcol + 1, sizeof(int));
366 lused = (int *) getcore(qcol + 1, sizeof(int));
367 rused = (int *) getcore(qcol + 1, sizeof(int));
368 doubled = (int *) getcore(qcol + 1, sizeof(int));
369 acase = (int *) getcore(qcol + 1, sizeof(int));
370 topat = (int *) getcore(qcol + 1, sizeof(int));
375 getcore(int a, int b)
380 error("Couldn't get memory");
396 free(--sep); /* netnews says this should be --sep because incremented earlier! */