BSD 4_4 release
[unix-history] / usr / src / old / tbl / t8.c
CommitLineData
94bed826 1/*-
ad787160
C
2 * This module is believed to contain source code proprietary to AT&T.
3 * Use and redistribution is subject to the Berkeley Software License
4 * Agreement and your Software Agreement with AT&T (Western Electric).
94bed826
KB
5 */
6
476fcd16 7#ifndef lint
ad787160 8static char sccsid[] = "@(#)t8.c 4.5 (Berkeley) 4/18/91";
94bed826 9#endif /* not lint */
ffa64172
BS
10
11 /* t8.c: write out one line of output table */
12# include "t..c"
13# define realsplit ((ct=='a'||ct=='n') && table[nl][c].rcol)
14int watchout;
15int once;
16int topat[MAXCOL];
17putline(i, nl)
18 /* i is line number for deciding format */
19 /* nl is line number for finding data usually identical */
20{
d11dede0 21int c, lf, ct, form, lwid, vspf, ip = -1, cmidx, exvspen, vforml;
ffa64172
BS
22int vct, chfont;
23char *s, *size, *fn;
24watchout=vspf=exvspen=0;
25if (i==0) once=0;
26if (i==0 && ( allflg || boxflg || dboxflg))
27 fullwide(0, dboxflg? '=' : '-');
28if (instead[nl]==0 && fullbot[nl] ==0)
29for(c=0; c<ncol; c++)
30 {
31 s = table[nl][c].col;
32 if (s==0) continue;
33 if (vspen(s))
34 {
35 for(ip=nl; ip<nlin; ip=next(ip))
36 if (!vspen(s=table[ip][c].col)) break;
bdbc9c90 37 if (tx(s))
ffa64172
BS
38 fprintf(tabout, ".ne \\n(%c|u+\\n(.Vu\n",s);
39 continue;
40 }
41 if (point(s)) continue;
42 fprintf(tabout, ".ne \\n(%c|u+\\n(.Vu\n",s);
43 watchout=1;
44 }
45if (linestop[nl])
46 fprintf(tabout, ".mk #%c\n", linestop[nl]+'a'-1);
47lf = prev(nl);
48if (instead[nl])
49 {
50 puts(instead[nl]);
51 return;
52 }
53if (fullbot[nl])
54 {
55 switch (ct=fullbot[nl])
56 {
57 case '=':
58 case '-':
59 fullwide(nl,ct);
60 }
61 return;
62 }
63for(c=0; c<ncol; c++)
64 {
65 if (instead[nl]==0 && fullbot[nl]==0)
66 if (vspen(table[nl][c].col)) vspf=1;
67 if (lf>=0)
68 if (vspen(table[lf][c].col)) vspf=1;
69 }
70if (vspf)
71 {
72 fprintf(tabout, ".nr #^ \\n(\\*(#du\n");
73 fprintf(tabout, ".nr #- \\n(#^\n"); /* current line position relative to bottom */
74 }
75vspf=0;
76chfont=0;
77for(c=0; c<ncol; c++)
78 {
79 s = table[nl][c].col;
80 if (s==0) continue;
81 chfont |= (int)(font[stynum[nl]][c]);
82 if (point(s) ) continue;
83 lf=prev(nl);
84 if (lf>=0 && vspen(table[lf][c].col))
85 fprintf(tabout, ".if (\\n(%c|+\\n(^%c-1v)>\\n(#- .nr #- +(\\n(%c|+\\n(^%c-\\n(#--1v)\n",s,'a'+c,s,'a'+c);
86 else
87 fprintf(tabout, ".if (\\n(%c|+\\n(#^-1v)>\\n(#- .nr #- +(\\n(%c|+\\n(#^-\\n(#--1v)\n",s,s);
88 }
89if (allflg && once>0 )
90 fullwide(i,'-');
91once=1;
92runtabs(i, nl);
93if (allh(i) && !pr1403)
94 {
95 fprintf(tabout, ".nr %d \\n(.v\n", SVS);
96 fprintf(tabout, ".vs \\n(.vu-\\n(.sp\n");
97 }
98if (chfont)
99 fprintf(tabout, ".nr %2d \\n(.f\n", S1);
100fprintf(tabout, ".nr 35 1m\n");
101fprintf(tabout, "\\&");
102vct = 0;
103for(c=0; c<ncol; c++)
104 {
105 if (watchout==0 && i+1<nlin && (lf=left(i,c, &lwid))>=0)
106 {
107 tohcol(c);
108 drawvert(lf, i, c, lwid);
109 vct += 2;
110 }
111 if (rightl && c+1==ncol) continue;
112 vforml=i;
113 for(lf=prev(nl); lf>=0 && vspen(table[lf][c].col); lf=prev(lf))
114 vforml= lf;
115 form= ctype(vforml,c);
116 if (form != 's')
117 {
118 ct = c+CLEFT;
119 if (form=='a') ct = c+CMID;
120 if (form=='n' && table[nl][c].rcol && lused[c]==0) ct= c+CMID;
121 fprintf(tabout, "\\h'|\\n(%du'", ct);
122 }
123 s= table[nl][c].col;
124 fn = font[stynum[vforml]][c];
125 size = csize[stynum[vforml]][c];
126 if (*size==0)size=0;
127 switch(ct=ctype(vforml, c))
128 {
129 case 'n':
130 case 'a':
131 if (table[nl][c].rcol)
132 {
133 if (lused[c]) /*Zero field width*/
134 {
135 ip = prev(nl);
136 if (ip>=0)
137 if (vspen(table[ip][c].col))
138 {
139 if (exvspen==0)
140 {
141 fprintf(tabout, "\\v'-(\\n(\\*(#du-\\n(^%cu", c+'a');
142 if (cmidx)
143 fprintf(tabout, "-((\\n(#-u-\\n(^%cu)/2u)", c+'a');
144 vct++;
145 fprintf(tabout, "'");
146 exvspen=1;
147 }
148 }
149 fprintf(tabout, "%c%c",F1,F2);
150 puttext(s,fn,size);
151 fprintf(tabout, "%c",F1);
152 }
153 s= table[nl][c].rcol;
154 form=1;
155 break;
156 }
157 case 'c':
158 form=3; break;
159 case 'r':
160 form=2; break;
161 case 'l':
162 form=1; break;
163 case '-':
164 case '=':
165 if (real(table[nl][c].col))
166 fprintf(stderr,"%s: line %d: Data ignored on table line %d\n", ifile, iline-1, i+1);
167 makeline(i,c,ct);
168 continue;
169 default:
170 continue;
171 }
172 if (realsplit ? rused[c]: used[c]) /*Zero field width*/
173 {
174 /* form: 1 left, 2 right, 3 center adjust */
175 if (ifline(s))
176 {
177 makeline(i,c,ifline(s));
178 continue;
179 }
180 if (filler(s))
181 {
182 printf("\\l'|\\n(%du\\&%s'", c+CRIGHT, s+2);
183 continue;
184 }
185 ip = prev(nl);
186 cmidx = ctop[stynum[nl]][c]==0;
187 if (ip>=0)
188 if (vspen(table[ip][c].col))
189 {
190 if (exvspen==0)
191 {
192 fprintf(tabout, "\\v'-(\\n(\\*(#du-\\n(^%cu", c+'a');
193 if (cmidx)
194 fprintf(tabout, "-((\\n(#-u-\\n(^%cu)/2u)", c+'a');
195 vct++;
196 fprintf(tabout, "'");
197 }
198 }
199 fprintf(tabout, "%c", F1);
200 if (form!= 1)
201 fprintf(tabout, "%c", F2);
202 if (vspen(s))
203 vspf=1;
204 else
205 puttext(s, fn, size);
206 if (form !=2)
207 fprintf(tabout, "%c", F2);
208 fprintf(tabout, "%c", F1);
209 }
210 if (ip>=0)
211 if (vspen(table[ip][c].col))
212 {
213 exvspen = (c+1 < ncol) && vspen(table[ip][c+1].col) &&
214 (topat[c] == topat[c+1]) &&
215 (cmidx == (ctop [stynum[nl]][c+1]==0)) && (left(i,c+1,&lwid)<0);
216 if (exvspen==0)
217 {
218 fprintf(tabout, "\\v'(\\n(\\*(#du-\\n(^%cu", c+'a');
219 if (cmidx)
220 fprintf(tabout, "-((\\n(#-u-\\n(^%cu)/2u)", c+'a');
221 vct++;
222 fprintf(tabout, "'");
223 }
224 }
225 else
226 exvspen=0;
227 /* if lines need to be split for gcos here is the place for a backslash */
228 if (vct > 7 && c < ncol)
229 {
230 fprintf(tabout, "\n.sp-1\n\\&");
231 vct=0;
232 }
233 }
234fprintf(tabout, "\n");
235if (allh(i) && !pr1403) fprintf(tabout, ".vs \\n(%du\n", SVS);
236if (watchout)
237 funnies(i,nl);
238if (vspf)
239 {
240 for(c=0; c<ncol; c++)
241 if (vspen(table[nl][c].col) && (nl==0 || (lf=prev(nl))<0 || !vspen(table[lf][c].col)))
242 {
243 fprintf(tabout, ".nr ^%c \\n(#^u\n", 'a'+c);
244 topat[c]=nl;
245 }
246 }
247}
248puttext(s,fn, size)
249 char *s, *size, *fn;
250{
251if (point(s))
252 {
253 putfont(fn);
254 putsize(size);
255 fprintf(tabout, "%s",s);
256 if (*fn>0) fprintf(tabout, "\\f\\n(%2d", S1);
257 if (size!=0) putsize("0");
258 }
259}
260funnies( stl, lin)
261{
262/* write out funny diverted things */
263int c, s, pl, lwid, dv, lf, ct;
264char *fn;
265fprintf(tabout, ".mk ##\n"); /* rmember current vertical position */
266fprintf(tabout, ".nr %d \\n(##\n", S1); /* bottom position */
267for(c=0; c<ncol; c++)
268 {
269 s = table[lin][c].col;
270 if (point(s)) continue;
271 if (s==0) continue;
272 fprintf(tabout, ".sp |\\n(##u-1v\n");
273 fprintf(tabout, ".nr %d ", SIND);
274 for(pl=stl; pl>=0 && !isalpha(ct=ctype(pl,c)); pl=prev(pl))
275 ;
276 switch (ct)
277 {
278 case 'n':
279 case 'c':
280 fprintf(tabout, "(\\n(%du+\\n(%du-\\n(%c-u)/2u\n",c+CLEFT,c-1+ctspan(lin,c)+CRIGHT, s);
281 break;
282 case 'l':
283 fprintf(tabout, "\\n(%du\n",c+CLEFT);
284 break;
285 case 'a':
286 fprintf(tabout, "\\n(%du\n",c+CMID);
287 break;
288 case 'r':
289 fprintf(tabout, "\\n(%du-\\n(%c-u\n", c+CRIGHT, s);
290 break;
291 }
292 fprintf(tabout, ".in +\\n(%du\n", SIND);
293 fn=font[stynum[stl]][c];
294 putfont(fn);
295 pl = prev(stl);
296 if (stl>0 && pl>=0 && vspen(table[pl][c].col))
297 {
298 fprintf(tabout, ".sp |\\n(^%cu\n", 'a'+c);
299 if (ctop[stynum[stl]][c]==0)
300 {
301 fprintf(tabout, ".nr %d \\n(#-u-\\n(^%c-\\n(%c|+1v\n",TMP, 'a'+c, s);
302 fprintf(tabout, ".if \\n(%d>0 .sp \\n(%du/2u\n", TMP, TMP);
303 }
304 }
305 fprintf(tabout, ".%c+\n",s);
306 fprintf(tabout, ".in -\\n(%du\n", SIND);
307 if (*fn>0) putfont("P");
308 fprintf(tabout, ".mk %d\n", S2);
309 fprintf(tabout, ".if \\n(%d>\\n(%d .nr %d \\n(%d\n", S2, S1, S1, S2);
310 }
311fprintf(tabout, ".sp |\\n(%du\n", S1);
312for(c=dv=0; c<ncol; c++)
313 {
314 if (stl+1< nlin && (lf=left(stl,c,&lwid))>=0)
315 {
316 if (dv++ == 0)
317 fprintf(tabout, ".sp -1\n");
318 tohcol(c);
319 dv++;
320 drawvert(lf, stl, c, lwid);
321 }
322 }
323if (dv)
324 fprintf(tabout,"\n");
325}
326putfont(fn)
327 char *fn;
328{
329if (fn && *fn)
330 fprintf(tabout, fn[1] ? "\\f(%.2s" : "\\f%.2s", fn);
331}
332putsize(s)
333 char *s;
334{
335if (s && *s)
336 fprintf(tabout, "\\s%s",s);
337}