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