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