1*381Smuffin /*
2*381Smuffin * Copyright 1996 Sun Microsystems, Inc. All rights reserved.
3*381Smuffin * Use is subject to license terms.
4*381Smuffin */
5*381Smuffin
60Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
70Sstevel@tonic-gate /* All Rights Reserved */
80Sstevel@tonic-gate
90Sstevel@tonic-gate /*
100Sstevel@tonic-gate * Copyright (c) 1980 Regents of the University of California.
110Sstevel@tonic-gate * All rights reserved. The Berkeley software License Agreement
120Sstevel@tonic-gate * specifies the terms and conditions for redistribution.
130Sstevel@tonic-gate */
140Sstevel@tonic-gate
15*381Smuffin #pragma ident "%Z%%M% %I% %E% SMI"
160Sstevel@tonic-gate
170Sstevel@tonic-gate /* t8.c: write out one line of output table */
180Sstevel@tonic-gate # include "t..c"
190Sstevel@tonic-gate # include <locale.h>
200Sstevel@tonic-gate # define realsplit ((ct=='a'||ct=='n') && table[nl][c].rcol)
21*381Smuffin
220Sstevel@tonic-gate int watchout;
230Sstevel@tonic-gate int once;
240Sstevel@tonic-gate int topat[MAXCOL];
25*381Smuffin
26*381Smuffin void puttext(char *, char *, char *);
27*381Smuffin void funnies(int, int);
28*381Smuffin void putfont(char *);
29*381Smuffin void putsize(char *);
30*381Smuffin
31*381Smuffin /*
32*381Smuffin * parameters
33*381Smuffin *
34*381Smuffin * i: line number for deciding format
35*381Smuffin * nl: line number for finding data usually identical
36*381Smuffin */
37*381Smuffin void
putline(int i,int nl)38*381Smuffin putline(int i, int nl)
390Sstevel@tonic-gate {
400Sstevel@tonic-gate int c, lf, ct, form, lwid, vspf, ip = -1, cmidx, exvspen, vforml;
410Sstevel@tonic-gate int vct, chfont;
420Sstevel@tonic-gate char *s, *size, *fn;
430Sstevel@tonic-gate watchout=vspf=exvspen=0;
440Sstevel@tonic-gate if (i==0) once=0;
450Sstevel@tonic-gate if (i==0 && ( allflg || boxflg || dboxflg))
460Sstevel@tonic-gate fullwide(0, dboxflg? '=' : '-');
470Sstevel@tonic-gate if (instead[nl]==0 && fullbot[nl] ==0)
480Sstevel@tonic-gate for(c=0; c<ncol; c++)
490Sstevel@tonic-gate {
500Sstevel@tonic-gate s = table[nl][c].col;
510Sstevel@tonic-gate if (s==0) continue;
520Sstevel@tonic-gate if (vspen(s))
530Sstevel@tonic-gate {
540Sstevel@tonic-gate for(ip=nl; ip<nlin; ip=next(ip))
550Sstevel@tonic-gate if (!vspen(s=table[ip][c].col)) break;
560Sstevel@tonic-gate if (s>(char *)0 && s<(char *)128)
570Sstevel@tonic-gate fprintf(tabout, ".ne \\n(%c|u+\\n(.Vu\n",s);
580Sstevel@tonic-gate continue;
590Sstevel@tonic-gate }
600Sstevel@tonic-gate if (point(s)) continue;
610Sstevel@tonic-gate fprintf(tabout, ".ne \\n(%c|u+\\n(.Vu\n",s);
620Sstevel@tonic-gate watchout=1;
630Sstevel@tonic-gate }
640Sstevel@tonic-gate if (linestop[nl])
650Sstevel@tonic-gate fprintf(tabout, ".mk #%c\n", linestop[nl]+'a'-1);
660Sstevel@tonic-gate lf = prev(nl);
670Sstevel@tonic-gate if (instead[nl])
680Sstevel@tonic-gate {
690Sstevel@tonic-gate puts(instead[nl]);
700Sstevel@tonic-gate return;
710Sstevel@tonic-gate }
720Sstevel@tonic-gate if (fullbot[nl])
730Sstevel@tonic-gate {
740Sstevel@tonic-gate switch (ct=fullbot[nl])
750Sstevel@tonic-gate {
760Sstevel@tonic-gate case '=':
770Sstevel@tonic-gate case '-':
780Sstevel@tonic-gate fullwide(nl,ct);
790Sstevel@tonic-gate }
800Sstevel@tonic-gate return;
810Sstevel@tonic-gate }
820Sstevel@tonic-gate for(c=0; c<ncol; c++)
830Sstevel@tonic-gate {
840Sstevel@tonic-gate if (instead[nl]==0 && fullbot[nl]==0)
850Sstevel@tonic-gate if (vspen(table[nl][c].col)) vspf=1;
860Sstevel@tonic-gate if (lf>=0)
870Sstevel@tonic-gate if (vspen(table[lf][c].col)) vspf=1;
880Sstevel@tonic-gate }
890Sstevel@tonic-gate if (vspf)
900Sstevel@tonic-gate {
910Sstevel@tonic-gate fprintf(tabout, ".nr #^ \\n(\\*(#du\n");
920Sstevel@tonic-gate fprintf(tabout, ".nr #- \\n(#^\n"); /* current line position relative to bottom */
930Sstevel@tonic-gate }
940Sstevel@tonic-gate vspf=0;
950Sstevel@tonic-gate chfont=0;
960Sstevel@tonic-gate for(c=0; c<ncol; c++)
970Sstevel@tonic-gate {
980Sstevel@tonic-gate s = table[nl][c].col;
990Sstevel@tonic-gate if (s==0) continue;
1000Sstevel@tonic-gate chfont |= (int)(font[stynum[nl]][c]);
1010Sstevel@tonic-gate if (point(s) ) continue;
1020Sstevel@tonic-gate lf=prev(nl);
1030Sstevel@tonic-gate if (lf>=0 && vspen(table[lf][c].col))
1040Sstevel@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);
1050Sstevel@tonic-gate else
1060Sstevel@tonic-gate fprintf(tabout, ".if (\\n(%c|+\\n(#^-1v)>\\n(#- .nr #- +(\\n(%c|+\\n(#^-\\n(#--1v)\n",s,s);
1070Sstevel@tonic-gate }
1080Sstevel@tonic-gate if (allflg && once>0 )
1090Sstevel@tonic-gate fullwide(i,'-');
1100Sstevel@tonic-gate once=1;
1110Sstevel@tonic-gate runtabs(i, nl);
1120Sstevel@tonic-gate if (allh(nl) && !pr1403)
1130Sstevel@tonic-gate {
1140Sstevel@tonic-gate fprintf(tabout, ".nr %d \\n(.v\n", SVS);
1150Sstevel@tonic-gate fprintf(tabout, ".vs \\n(.vu-\\n(.sp\n");
1160Sstevel@tonic-gate }
1170Sstevel@tonic-gate if (chfont)
1180Sstevel@tonic-gate fprintf(tabout, ".nr %2d \\n(.f\n", S1);
1190Sstevel@tonic-gate fprintf(tabout, ".nr 35 1m\n");
1200Sstevel@tonic-gate fprintf(tabout, "\\&");
1210Sstevel@tonic-gate vct = 0;
1220Sstevel@tonic-gate for(c=0; c<ncol; c++)
1230Sstevel@tonic-gate {
1240Sstevel@tonic-gate if (watchout==0 && i+1<nlin && (lf=left(i,c, &lwid))>=0)
1250Sstevel@tonic-gate {
1260Sstevel@tonic-gate tohcol(c);
1270Sstevel@tonic-gate drawvert(lf, i, c, lwid);
1280Sstevel@tonic-gate vct += 2;
1290Sstevel@tonic-gate }
1300Sstevel@tonic-gate if (rightl && c+1==ncol) continue;
1310Sstevel@tonic-gate vforml=i;
1320Sstevel@tonic-gate for(lf=prev(nl); lf>=0 && vspen(table[lf][c].col); lf=prev(lf))
1330Sstevel@tonic-gate vforml= lf;
1340Sstevel@tonic-gate form= ctype(vforml,c);
1350Sstevel@tonic-gate if (form != 's')
1360Sstevel@tonic-gate {
1370Sstevel@tonic-gate ct = c+CLEFT;
1380Sstevel@tonic-gate if (form=='a') ct = c+CMID;
1390Sstevel@tonic-gate if (form=='n' && table[nl][c].rcol && lused[c]==0) ct= c+CMID;
1400Sstevel@tonic-gate fprintf(tabout, "\\h'|\\n(%du'", ct);
1410Sstevel@tonic-gate }
1420Sstevel@tonic-gate s= table[nl][c].col;
1430Sstevel@tonic-gate fn = font[stynum[vforml]][c];
1440Sstevel@tonic-gate size = csize[stynum[vforml]][c];
1450Sstevel@tonic-gate if (*size==0)size=0;
1460Sstevel@tonic-gate switch(ct=ctype(vforml, c))
1470Sstevel@tonic-gate {
1480Sstevel@tonic-gate case 'n':
1490Sstevel@tonic-gate case 'a':
1500Sstevel@tonic-gate if (table[nl][c].rcol)
1510Sstevel@tonic-gate {
1520Sstevel@tonic-gate if (lused[c]) /*Zero field width*/
1530Sstevel@tonic-gate {
1540Sstevel@tonic-gate ip = prev(nl);
1550Sstevel@tonic-gate if (ip>=0)
1560Sstevel@tonic-gate if (vspen(table[ip][c].col))
1570Sstevel@tonic-gate {
1580Sstevel@tonic-gate if (exvspen==0)
1590Sstevel@tonic-gate {
1600Sstevel@tonic-gate fprintf(tabout, "\\v'-(\\n(\\*(#du-\\n(^%cu", c+'a');
1610Sstevel@tonic-gate if (cmidx)
1620Sstevel@tonic-gate fprintf(tabout, "-((\\n(#-u-\\n(^%cu)/2u)", c+'a');
1630Sstevel@tonic-gate vct++;
1640Sstevel@tonic-gate fprintf(tabout, "'");
1650Sstevel@tonic-gate exvspen=1;
1660Sstevel@tonic-gate }
1670Sstevel@tonic-gate }
1680Sstevel@tonic-gate fprintf(tabout, "%c%c",F1,F2);
1690Sstevel@tonic-gate puttext(s,fn,size);
1700Sstevel@tonic-gate fprintf(tabout, "%c",F1);
1710Sstevel@tonic-gate }
1720Sstevel@tonic-gate s= table[nl][c].rcol;
1730Sstevel@tonic-gate form=1;
1740Sstevel@tonic-gate break;
1750Sstevel@tonic-gate }
1760Sstevel@tonic-gate case 'c':
1770Sstevel@tonic-gate form=3; break;
1780Sstevel@tonic-gate case 'r':
1790Sstevel@tonic-gate form=2; break;
1800Sstevel@tonic-gate case 'l':
1810Sstevel@tonic-gate form=1; break;
1820Sstevel@tonic-gate case '-':
1830Sstevel@tonic-gate case '=':
1840Sstevel@tonic-gate if (real(table[nl][c].col))
1850Sstevel@tonic-gate fprintf(stderr,gettext("%s: line %d: Data ignored on table line %d\n"), ifile, iline-1, i+1);
1860Sstevel@tonic-gate makeline(i,c,ct);
1870Sstevel@tonic-gate continue;
1880Sstevel@tonic-gate default:
1890Sstevel@tonic-gate continue;
1900Sstevel@tonic-gate }
1910Sstevel@tonic-gate if (realsplit ? rused[c]: used[c]) /*Zero field width*/
1920Sstevel@tonic-gate {
1930Sstevel@tonic-gate /* form: 1 left, 2 right, 3 center adjust */
1940Sstevel@tonic-gate if (ifline(s))
1950Sstevel@tonic-gate {
1960Sstevel@tonic-gate makeline(i,c,ifline(s));
1970Sstevel@tonic-gate continue;
1980Sstevel@tonic-gate }
1990Sstevel@tonic-gate if (filler(s))
2000Sstevel@tonic-gate {
2010Sstevel@tonic-gate printf("\\l'|\\n(%du\\&%s'", c+CRIGHT, s+2);
2020Sstevel@tonic-gate continue;
2030Sstevel@tonic-gate }
2040Sstevel@tonic-gate ip = prev(nl);
2050Sstevel@tonic-gate cmidx = ctop[stynum[nl]][c]==0;
2060Sstevel@tonic-gate if (ip>=0)
2070Sstevel@tonic-gate if (vspen(table[ip][c].col))
2080Sstevel@tonic-gate {
2090Sstevel@tonic-gate if (exvspen==0)
2100Sstevel@tonic-gate {
2110Sstevel@tonic-gate fprintf(tabout, "\\v'-(\\n(\\*(#du-\\n(^%cu", c+'a');
2120Sstevel@tonic-gate if (cmidx)
2130Sstevel@tonic-gate fprintf(tabout, "-((\\n(#-u-\\n(^%cu)/2u)", c+'a');
2140Sstevel@tonic-gate vct++;
2150Sstevel@tonic-gate fprintf(tabout, "'");
2160Sstevel@tonic-gate }
2170Sstevel@tonic-gate }
2180Sstevel@tonic-gate fprintf(tabout, "%c", F1);
2190Sstevel@tonic-gate if (form!= 1)
2200Sstevel@tonic-gate fprintf(tabout, "%c", F2);
2210Sstevel@tonic-gate if (vspen(s))
2220Sstevel@tonic-gate vspf=1;
2230Sstevel@tonic-gate else
2240Sstevel@tonic-gate puttext(s, fn, size);
2250Sstevel@tonic-gate if (form !=2)
2260Sstevel@tonic-gate fprintf(tabout, "%c", F2);
2270Sstevel@tonic-gate fprintf(tabout, "%c", F1);
2280Sstevel@tonic-gate }
2290Sstevel@tonic-gate if (ip>=0)
2300Sstevel@tonic-gate if (vspen(table[ip][c].col))
2310Sstevel@tonic-gate {
2320Sstevel@tonic-gate exvspen = (c+1 < ncol) && vspen(table[ip][c+1].col) &&
2330Sstevel@tonic-gate (topat[c] == topat[c+1]) &&
2340Sstevel@tonic-gate (cmidx == (ctop [stynum[nl]][c+1]==0)) && (left(i,c+1,&lwid)<0);
2350Sstevel@tonic-gate if (exvspen==0)
2360Sstevel@tonic-gate {
2370Sstevel@tonic-gate fprintf(tabout, "\\v'(\\n(\\*(#du-\\n(^%cu", c+'a');
2380Sstevel@tonic-gate if (cmidx)
2390Sstevel@tonic-gate fprintf(tabout, "-((\\n(#-u-\\n(^%cu)/2u)", c+'a');
2400Sstevel@tonic-gate vct++;
2410Sstevel@tonic-gate fprintf(tabout, "'");
2420Sstevel@tonic-gate }
2430Sstevel@tonic-gate }
2440Sstevel@tonic-gate else
2450Sstevel@tonic-gate exvspen=0;
2460Sstevel@tonic-gate /* if lines need to be split for gcos here is the place for a backslash */
2470Sstevel@tonic-gate if (vct > 7 && c < ncol)
2480Sstevel@tonic-gate {
2490Sstevel@tonic-gate fprintf(tabout, "\n.sp-1\n\\&");
2500Sstevel@tonic-gate vct=0;
2510Sstevel@tonic-gate }
2520Sstevel@tonic-gate }
2530Sstevel@tonic-gate fprintf(tabout, "\n");
2540Sstevel@tonic-gate if (allh(nl) && !pr1403) fprintf(tabout, ".vs \\n(%du\n", SVS);
2550Sstevel@tonic-gate if (watchout)
2560Sstevel@tonic-gate funnies(i,nl);
2570Sstevel@tonic-gate if (vspf)
2580Sstevel@tonic-gate {
2590Sstevel@tonic-gate for(c=0; c<ncol; c++)
2600Sstevel@tonic-gate if (vspen(table[nl][c].col) && (nl==0 || (lf=prev(nl))<0 || !vspen(table[lf][c].col)))
2610Sstevel@tonic-gate {
2620Sstevel@tonic-gate fprintf(tabout, ".nr ^%c \\n(#^u\n", 'a'+c);
2630Sstevel@tonic-gate topat[c]=nl;
2640Sstevel@tonic-gate }
2650Sstevel@tonic-gate }
2660Sstevel@tonic-gate }
267*381Smuffin
268*381Smuffin void
puttext(char * s,char * fn,char * size)269*381Smuffin puttext(char *s, char *fn, char *size)
2700Sstevel@tonic-gate {
2710Sstevel@tonic-gate if (point(s))
2720Sstevel@tonic-gate {
2730Sstevel@tonic-gate putfont(fn);
2740Sstevel@tonic-gate putsize(size);
2750Sstevel@tonic-gate fprintf(tabout, "%s",s);
2760Sstevel@tonic-gate if (*fn>0) fprintf(tabout, "\\f\\n(%2d", S1);
2770Sstevel@tonic-gate if (size!=0) putsize("0");
2780Sstevel@tonic-gate }
2790Sstevel@tonic-gate }
280*381Smuffin
281*381Smuffin void
funnies(int stl,int lin)282*381Smuffin funnies(int stl, int lin)
2830Sstevel@tonic-gate {
2840Sstevel@tonic-gate /* write out funny diverted things */
2850Sstevel@tonic-gate int c, s, pl, lwid, dv, lf, ct;
2860Sstevel@tonic-gate char *fn;
2870Sstevel@tonic-gate fprintf(tabout, ".mk ##\n"); /* rmember current vertical position */
2880Sstevel@tonic-gate fprintf(tabout, ".nr %d \\n(##\n", S1); /* bottom position */
2890Sstevel@tonic-gate for(c=0; c<ncol; c++)
2900Sstevel@tonic-gate {
2910Sstevel@tonic-gate s = (int)table[lin][c].col;
2920Sstevel@tonic-gate if (point(s)) continue;
2930Sstevel@tonic-gate if (s==0) continue;
2940Sstevel@tonic-gate fprintf(tabout, ".sp |\\n(##u-1v\n");
2950Sstevel@tonic-gate fprintf(tabout, ".nr %d ", SIND);
2960Sstevel@tonic-gate for(pl=stl; pl>=0 && !isalpha(ct=ctype(pl,c)); pl=prev(pl))
2970Sstevel@tonic-gate ;
2980Sstevel@tonic-gate switch (ct)
2990Sstevel@tonic-gate {
3000Sstevel@tonic-gate case 'n':
3010Sstevel@tonic-gate case 'c':
3020Sstevel@tonic-gate fprintf(tabout, "(\\n(%du+\\n(%du-\\n(%c-u)/2u\n",c+CLEFT,c-1+ctspan(lin,c)+CRIGHT, s);
3030Sstevel@tonic-gate break;
3040Sstevel@tonic-gate case 'l':
3050Sstevel@tonic-gate fprintf(tabout, "\\n(%du\n",c+CLEFT);
3060Sstevel@tonic-gate break;
3070Sstevel@tonic-gate case 'a':
3080Sstevel@tonic-gate fprintf(tabout, "\\n(%du\n",c+CMID);
3090Sstevel@tonic-gate break;
3100Sstevel@tonic-gate case 'r':
3110Sstevel@tonic-gate fprintf(tabout, "\\n(%du-\\n(%c-u\n", c+CRIGHT, s);
3120Sstevel@tonic-gate break;
3130Sstevel@tonic-gate }
3140Sstevel@tonic-gate fprintf(tabout, ".in +\\n(%du\n", SIND);
3150Sstevel@tonic-gate fn=font[stynum[stl]][c];
3160Sstevel@tonic-gate putfont(fn);
3170Sstevel@tonic-gate pl = prev(stl);
3180Sstevel@tonic-gate if (stl>0 && pl>=0 && vspen(table[pl][c].col))
3190Sstevel@tonic-gate {
3200Sstevel@tonic-gate fprintf(tabout, ".sp |\\n(^%cu\n", 'a'+c);
3210Sstevel@tonic-gate if (ctop[stynum[stl]][c]==0)
3220Sstevel@tonic-gate {
3230Sstevel@tonic-gate fprintf(tabout, ".nr %d \\n(#-u-\\n(^%c-\\n(%c|+1v\n",TMP, 'a'+c, s);
3240Sstevel@tonic-gate fprintf(tabout, ".if \\n(%d>0 .sp \\n(%du/2u\n", TMP, TMP);
3250Sstevel@tonic-gate }
3260Sstevel@tonic-gate }
3270Sstevel@tonic-gate fprintf(tabout, ".%c+\n",s);
3280Sstevel@tonic-gate fprintf(tabout, ".in -\\n(%du\n", SIND);
3290Sstevel@tonic-gate if (*fn>0) putfont("P");
3300Sstevel@tonic-gate fprintf(tabout, ".mk %d\n", S2);
3310Sstevel@tonic-gate fprintf(tabout, ".if \\n(%d>\\n(%d .nr %d \\n(%d\n", S2, S1, S1, S2);
3320Sstevel@tonic-gate }
3330Sstevel@tonic-gate fprintf(tabout, ".sp |\\n(%du\n", S1);
3340Sstevel@tonic-gate for(c=dv=0; c<ncol; c++)
3350Sstevel@tonic-gate {
3360Sstevel@tonic-gate if (stl+1< nlin && (lf=left(stl,c,&lwid))>=0)
3370Sstevel@tonic-gate {
3380Sstevel@tonic-gate if (dv++ == 0)
3390Sstevel@tonic-gate fprintf(tabout, ".sp -1\n");
3400Sstevel@tonic-gate tohcol(c);
3410Sstevel@tonic-gate dv++;
3420Sstevel@tonic-gate drawvert(lf, stl, c, lwid);
3430Sstevel@tonic-gate }
3440Sstevel@tonic-gate }
3450Sstevel@tonic-gate if (dv)
3460Sstevel@tonic-gate fprintf(tabout,"\n");
3470Sstevel@tonic-gate }
348*381Smuffin
349*381Smuffin void
putfont(char * fn)350*381Smuffin putfont(char *fn)
3510Sstevel@tonic-gate {
3520Sstevel@tonic-gate if (fn && *fn)
3530Sstevel@tonic-gate fprintf(tabout, fn[1] ? "\\f(%.2s" : "\\f%.2s", fn);
3540Sstevel@tonic-gate }
355*381Smuffin
356*381Smuffin void
putsize(char * s)357*381Smuffin putsize(char *s)
3580Sstevel@tonic-gate {
3590Sstevel@tonic-gate if (s && *s)
3600Sstevel@tonic-gate fprintf(tabout, "\\s%s",s);
3610Sstevel@tonic-gate }
362