|
|
1.1 root 1: /* t4.c: read table specification */
2: # include "t..c"
3: int oncol;
4: getspec()
5: {
6: int icol, i;
7: qcol = findcol()+1;/* must allow one extra for line at right */
8: garray(qcol);
9: sep[-1]= -1;
10: for(icol=0; icol<qcol; icol++)
11: {
12: sep[icol]= -1;
13: evenup[icol]=0;
14: cll[icol][0]=0;
15: for(i=0; i<MAXHEAD; i++)
16: {
17: csize[icol][i][0]=0;
18: vsize[icol][i][0]=0;
19: font[icol][i][0] = lefline[icol][i] = 0;
20: flags[icol][i]=0;
21: style[icol][i]= 'l';
22: }
23: }
24: nclin=ncol=0;
25: oncol =0;
26: left1flg=rightl=0;
27: readspec();
28: fprintf(tabout, ".rm");
29: for(i=0; i<ncol; i++)
30: fprintf(tabout, " %2s", reg(i, CRIGHT));
31: fprintf(tabout, "\n");
32: }
33: readspec()
34: {
35: int icol, c, sawchar, stopc, i;
36: char sn[10], *snp, *temp;
37: sawchar=icol=0;
38: while (c=get1char())
39: {
40: switch(c)
41: {
42: default:
43: if (c != tab)
44: error("bad table specification character");
45: case ' ': /* note this is also case tab */
46: continue;
47: case '\n':
48: if(sawchar==0) continue;
49: case ',':
50: case '.': /* end of table specification */
51: ncol = max(ncol, icol);
52: if (lefline[ncol][nclin]>0) {ncol++; rightl++;};
53: if(sawchar)
54: nclin++;
55: if (nclin>=MAXHEAD)
56: error("too many lines in specification");
57: icol=0;
58: if (ncol==0 || nclin==0)
59: error("no specification");
60: if (c== '.')
61: {
62: while ((c=get1char()) && c != '\n')
63: if (c != ' ' && c != '\t')
64: error("dot not last character on format line");
65: /* fix up sep - default is 3 except at edge */
66: for(icol=0; icol<ncol; icol++)
67: if (sep[icol]<0)
68: sep[icol] = icol+1<ncol ? 3 : 2;
69: if (oncol == 0)
70: oncol = ncol;
71: else if (oncol +2 <ncol)
72: error("tried to widen table in T&, not allowed");
73: return;
74: }
75: sawchar=0;
76: continue;
77: case 'C': case 'S': case 'R': case 'N': case 'L': case 'A':
78: c += ('a'-'A');
79: case '_': if (c=='_') c= '-';
80: case '=': case '-':
81: case '^':
82: case 'c': case 's': case 'n': case 'r': case 'l': case 'a':
83: style[icol][nclin]=c;
84: if (c== 's' && icol<=0)
85: error("first column can not be S-type");
86: if (c=='s' && style[icol-1][nclin] == 'a')
87: {
88: fprintf(tabout, ".tm warning: can't span a-type cols, changed to l\n");
89: style[icol-1][nclin] = 'l';
90: }
91: if (c=='s' && style[icol-1][nclin] == 'n')
92: {
93: fprintf(tabout, ".tm warning: can't span n-type cols, changed to c\n");
94: style[icol-1][nclin] = 'c';
95: }
96: icol++;
97: if (c=='^' && nclin<=0)
98: error("first row can not contain vertical span");
99: if (icol>qcol)
100: error("too many columns in table");
101: sawchar=1;
102: continue;
103: case 'b': case 'i':
104: c += 'A'-'a';
105: case 'B': case 'I':
106: if (icol==0) continue;
107: snp=font[icol-1][nclin];
108: snp[0]= (c=='I' ? '2' : '3');
109: snp[1]=0;
110: continue;
111: case 't': case 'T':
112: if (icol>0)
113: flags[icol-1][nclin] |= CTOP;
114: continue;
115: case 'd': case 'D':
116: if (icol>0)
117: flags[icol-1][nclin] |= CDOWN;
118: continue;
119: case 'f': case 'F':
120: if (icol==0) continue;
121: snp=font[icol-1][nclin];
122: snp[0]=snp[1]=stopc=0;
123: for(i=0; i<2; i++)
124: {
125: c = get1char();
126: if (i==0 && c=='(')
127: {
128: stopc=')';
129: c = get1char();
130: }
131: if (c==0) break;
132: if (c==stopc) {stopc=0; break;}
133: if (stopc==0) if (c==' ' || c== tab ) break;
134: if (c=='\n'){un1getc(c); break;}
135: snp[i] = c;
136: if (c>= '0' && c<= '9') break;
137: }
138: if (stopc) if (get1char()!=stopc)
139: error("Nonterminated font name");
140: continue;
141: case 'P': case 'p':
142: if (icol<=0) continue;
143: temp = snp = csize[icol-1][nclin];
144: while (c = get1char())
145: {
146: if (c== ' ' || c== tab || c=='\n') break;
147: if (c=='-' || c == '+')
148: if (snp>temp)
149: break;
150: else
151: *snp++=c;
152: else
153: if (digit(c))
154: *snp++ = c;
155: else break;
156: if (snp-temp>4)
157: error("point size too large");
158: }
159: *snp = 0;
160: if (atoi(temp)>36)
161: error("point size unreasonable");
162: un1getc (c);
163: continue;
164: case 'V': case 'v':
165: if (icol<=0) continue;
166: temp = snp = vsize[icol-1][nclin];
167: while (c = get1char())
168: {
169: if (c== ' ' || c== tab || c=='\n') break;
170: if (c=='-' || c == '+')
171: if (snp>temp)
172: break;
173: else
174: *snp++=c;
175: else
176: if (digit(c))
177: *snp++ = c;
178: else break;
179: if (snp-temp>4)
180: error("vertical spacing value too large");
181: }
182: *snp=0;
183: un1getc(c);
184: continue;
185: case 'w': case 'W':
186: snp = cll [icol-1];
187: /* Dale Smith didn't like this check - possible to have two text blocks
188: of different widths now ....
189: if (*snp)
190: {
191: fprintf(tabout, "Ignored second width specification");
192: continue;
193: }
194: /* end commented out code ... */
195: stopc=0;
196: while (c = get1char())
197: {
198: if (snp==cll[icol-1] && c=='(')
199: {
200: stopc = ')';
201: continue;
202: }
203: if ( !stopc && (c>'9' || c< '0'))
204: break;
205: if (stopc && c== stopc)
206: break;
207: *snp++ =c;
208: }
209: *snp=0;
210: if (snp-cll[icol-1]>CLLEN)
211: error ("column width too long");
212: if (!stopc)
213: un1getc(c);
214: continue;
215: case 'e': case 'E':
216: if (icol<1) continue;
217: evenup[icol-1]=1;
218: evenflg=1;
219: continue;
220: case 'z': case 'Z': /* zero width-ignre width this item */
221: if (icol<1) continue;
222: flags[icol-1][nclin] |= ZEROW;
223: continue;
224: case 'u': case 'U': /* half line up */
225: if (icol<1) continue;
226: flags[icol-1][nclin] |= HALFUP;
227: continue;
228: case '0': case '1': case '2': case '3': case '4':
229: case '5': case '6': case '7': case '8': case '9':
230: sn[0] = c;
231: snp=sn+1;
232: while (digit(*snp++ = c = get1char()))
233: ;
234: un1getc(c);
235: sep[icol-1] = max(sep[icol-1], numb(sn));
236: continue;
237: case '|':
238: lefline[icol][nclin]++;
239: if (icol==0) left1flg=1;
240: continue;
241: }
242: }
243: error("EOF reading table specification");
244: }
245: findcol()
246: {
247: # define FLNLIM 200
248: /* this counts the number of columns and then puts the line back*/
249: char *s, line[FLNLIM+2], *p;
250: int c, n=0, inpar=0;
251: while ((c=get1char())!=EOF && c == ' ')
252: ;
253: if (c!='\n')
254: un1getc(c);
255: for(s=line; *s = c = get1char(); s++)
256: {
257: if (c==')') inpar=0;
258: if (inpar) continue;
259: if (c=='\n' || c == EOF || c == '.' || c==',')
260: break;
261: else if (c=='(')
262: inpar=1;
263: else
264: if (s>=line+FLNLIM)
265: error("too long spec line");
266: }
267: for(p=line; p<s; p++)
268: switch (c= *p)
269: {
270: case 'l': case 'r': case 'c': case 'n': case 'a': case 's':
271: case 'L': case 'R': case 'C': case 'N': case 'A': case 'S':
272: case '-': case '=': case '_':
273: n++;
274: }
275: while (p>=line)
276: un1getc(*p--);
277: return(n);
278: }
279: garray(qcol)
280: {
281: char * getcore();
282: style = (int (*)[]) getcore(MAXHEAD*qcol, sizeof(int));
283: evenup = (int *) getcore(qcol, sizeof(int));
284: lefline = (int (*)[]) getcore(MAXHEAD*qcol, sizeof (int));
285: font = (char (*)[][2]) getcore(MAXHEAD*qcol, 2);
286: csize = (char (*)[MAXHEAD][4]) getcore(MAXHEAD*qcol, 4);
287: vsize = (char (*)[MAXHEAD][4]) getcore(MAXHEAD*qcol, 4);
288: flags = (int (*)[]) getcore(MAXHEAD*qcol, sizeof(int));
289: cll = (char (*)[])getcore(qcol, CLLEN);
290: sep = (int *) getcore(qcol+1, sizeof(int));
291: sep++; /* sep[-1] must be legal */
292: used = (int *) getcore(qcol+1, sizeof(int));
293: lused = (int *) getcore(qcol+1, sizeof(int));
294: rused = (int *) getcore(qcol+1, sizeof(int));
295: doubled = (int *) getcore(qcol+1, sizeof(int));
296: acase = (int *) getcore(qcol+1, sizeof(int));
297: topat = (int *) getcore(qcol+1, sizeof(int));
298: }
299: char *
300: getcore(a,b)
301: {
302: char *x, *calloc();
303: x = calloc(a,b);
304: if (x==0)
305: error("Couldn't get memory");
306: return(x);
307: }
308: freearr()
309: {
310: cfree(style);
311: cfree(evenup);
312: cfree(lefline);
313: cfree(flags);
314: cfree(font);
315: cfree(csize);
316: cfree(vsize);
317: cfree(cll);
318: cfree(sep);
319: cfree(used);
320: cfree(lused);
321: cfree(rused);
322: cfree(doubled);
323: cfree(acase);
324: cfree(topat);
325: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.