Blob


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