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