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 fprintf(tabout, ".ne \\n(%c|u+\\n(.Vu\n", (int)s);
32 continue;
33 }
34 if (point(s))
35 continue;
36 fprintf(tabout, ".ne \\n(%c|u+\\n(.Vu\n", (int)s);
37 watchout = 1;
38 }
39 if (linestop[nl])
40 fprintf(tabout, ".mk #%c\n", linestop[nl] + 'a' - 1);
41 lf = prev(nl);
42 if (instead[nl]) {
43 fprintf(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 fprintf(tabout, ".nr #^ \\n(\\*(#du\n");
64 fprintf(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 fprintf(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 fprintf(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 fprintf(tabout, ".nr %d \\n(.v\n", SVS);
91 fprintf(tabout, ".vs \\n(.vu-\\n(.sp\n");
92 fprintf(tabout, ".nr 35 \\n(.vu\n");
93 } else
94 fprintf(tabout, ".nr 35 1m\n");
95 if (chfont)
96 fprintf(tabout, ".nr %2d \\n(.f\n", S1);
97 fprintf(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 fprintf(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 fprintf(tabout, "\\v'-(\\n(\\*(#du-\\n(^%cu", c + 'a');
137 if (cmidx)
138 /* code folded from here */
139 fprintf(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 fprintf(tabout, "/1v*1v");
145 /* unfolding */
146 fprintf(tabout, "'");
147 exvspen = 1;
150 fprintf(tabout, "%c%c", F1, F2);
151 if (uphalf)
152 fprintf(tabout, "\\u");
153 puttext(s, fn, size);
154 if (uphalf)
155 fprintf(tabout, "\\d");
156 fprintf(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 fprintf(stderr, "%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 fprintf(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 fprintf(tabout, "\\v'-(\\n(\\*(#du-\\n(^%cu", c + 'a');
196 if (cmidx)
197 fprintf(tabout, "-((\\n(#-u-\\n(^%cu)/2u)", c + 'a');
198 vct++;
199 if (pr1403) /* round to whole lines */
200 fprintf(tabout, "/1v*1v");
201 fprintf(tabout, "'");
204 fprintf(tabout, "%c", F1);
205 if (form != 1)
206 fprintf(tabout, "%c", F2);
207 if (vspen(s))
208 vspf = 1;
209 else
211 if (uphalf)
212 fprintf(tabout, "\\u");
213 puttext(s, fn, size);
214 if (uphalf)
215 fprintf(tabout, "\\d");
217 if (form != 2)
218 fprintf(tabout, "%c", F2);
219 fprintf(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 fprintf(tabout, "\\v'(\\n(\\*(#du-\\n(^%cu", c + 'a');
230 if (cmidx)
231 fprintf(tabout, "-((\\n(#-u-\\n(^%cu)/2u)", c + 'a');
232 vct++;
233 if (pr1403) /* round to whole lines */
234 fprintf(tabout, "/1v*1v");
235 fprintf(tabout, "'");
238 else
239 exvspen = 0;
241 /* if lines need to be split for gcos here is the place for a backslash */
242 if (vct > 7 && c < ncol) {
243 fprintf(tabout, "\n.sp-1\n\\&");
244 vct = 0;
247 fprintf(tabout, "\n");
248 if (allh(i) && !pr1403)
249 fprintf(tabout, ".vs \\n(%du\n", SVS);
250 if (watchout)
251 funnies(i, nl);
252 if (vspf) {
253 for (c = 0; c < ncol; c++)
254 if (vspen(table[nl][c].col) && (nl == 0 || (lf = prev(nl)) < 0 ||
255 !vspen(table[lf][c].col))) {
256 fprintf(tabout, ".nr ^%c \\n(#^u\n", 'a' + c);
257 topat[c] = nl;
263 void
264 puttext(char *s, char *fn, char *size)
266 if (point(s)) {
267 putfont(fn);
268 putsize(size);
269 fprintf(tabout, "%s", s);
270 if (*fn > 0)
271 fprintf(tabout, "\\f\\n(%2d", S1);
272 if (size != 0)
273 putsize("0");
278 void
279 funnies(int stl, int lin)
281 /* write out funny diverted things */
282 int c, s, pl, lwid, dv, lf, ct;
283 char *fn, *ss;
285 fprintf(tabout, ".mk ##\n"); /* rmember current vertical position */
286 fprintf(tabout, ".nr %d \\n(##\n", S1); /* bottom position */
287 for (c = 0; c < ncol; c++) {
288 ss = table[lin][c].col;
289 if (point(ss))
290 continue;
291 if (ss == 0)
292 continue;
293 s = (int)ss;
294 fprintf(tabout, ".sp |\\n(##u-1v\n");
295 fprintf(tabout, ".nr %d ", SIND);
296 ct = 0;
297 for (pl = stl; pl >= 0 && !isalpha(ct = ctype(pl, c)); pl = prev(pl))
299 switch (ct) {
300 case 'n':
301 case 'c':
302 fprintf(tabout, "(\\n(%2su+\\n(%2su-\\n(%c-u)/2u\n", reg(c, CLEFT),
303 reg(c - 1 + ctspan(lin, c), CRIGHT),
304 s);
305 break;
306 case 'l':
307 fprintf(tabout, "\\n(%2su\n", reg(c, CLEFT));
308 break;
309 case 'a':
310 fprintf(tabout, "\\n(%2su\n", reg(c, CMID));
311 break;
312 case 'r':
313 fprintf(tabout, "\\n(%2su-\\n(%c-u\n", reg(c, CRIGHT), s);
314 break;
316 fprintf(tabout, ".in +\\n(%du\n", SIND);
317 fn = font[c][stynum[stl]];
318 putfont(fn);
319 pl = prev(stl);
320 if (stl > 0 && pl >= 0 && vspen(table[pl][c].col)) {
321 fprintf(tabout, ".sp |\\n(^%cu\n", 'a' + c);
322 if ((flags[c][stynum[stl]] & (CTOP | CDOWN)) == 0) {
323 fprintf(tabout, ".nr %d \\n(#-u-\\n(^%c-\\n(%c|+1v\n",
324 TMP, 'a' + c, s);
325 fprintf(tabout, ".if \\n(%d>0 .sp \\n(%du/2u", TMP, TMP);
326 if (pr1403) /* round */
327 fprintf(tabout, "/1v*1v");
328 fprintf(tabout, "\n");
331 fprintf(tabout, ".%c+\n", s);
332 fprintf(tabout, ".in -\\n(%du\n", SIND);
333 if (*fn > 0)
334 putfont("P");
335 fprintf(tabout, ".mk %d\n", S2);
336 fprintf(tabout, ".if \\n(%d>\\n(%d .nr %d \\n(%d\n", S2, S1, S1, S2);
338 fprintf(tabout, ".sp |\\n(%du\n", S1);
339 for (c = dv = 0; c < ncol; c++) {
340 if (stl + 1 < nlin && (lf = left(stl, c, &lwid)) >= 0) {
341 if (dv++ == 0)
342 fprintf(tabout, ".sp -1\n");
343 tohcol(c);
344 dv++;
345 drawvert(lf, stl, c, lwid);
348 if (dv)
349 fprintf(tabout, "\n");
353 void
354 putfont(char *fn)
356 if (fn && *fn)
357 fprintf(tabout, fn[1] ? "\\f(%.2s" : "\\f%.2s", fn);
361 void
362 putsize(char *s)
364 if (s && *s)
365 fprintf(tabout, "\\s%s", s);