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