1*381Smuffin /*
2*381Smuffin * Copyright 1990 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 /*
110Sstevel@tonic-gate * Copyright (c) 1980 Regents of the University of California.
120Sstevel@tonic-gate * All rights reserved. The Berkeley software License Agreement
130Sstevel@tonic-gate * specifies the terms and conditions for redistribution.
140Sstevel@tonic-gate */
150Sstevel@tonic-gate
16*381Smuffin #pragma ident "%Z%%M% %I% %E% SMI"
170Sstevel@tonic-gate
180Sstevel@tonic-gate /* t6.c: compute tab stops */
190Sstevel@tonic-gate # define tx(a) (a>(char *)0 && a<(char *)128)
200Sstevel@tonic-gate # include "t..c"
21*381Smuffin
22*381Smuffin void wide(char *, char *, char *);
23*381Smuffin
24*381Smuffin void
maktab(void)25*381Smuffin maktab(void)
260Sstevel@tonic-gate {
270Sstevel@tonic-gate # define FN(i,c) font[stynum[i]][c]
280Sstevel@tonic-gate # define SZ(i,c) csize[stynum[i]][c]
290Sstevel@tonic-gate /* define the tab stops of the table */
300Sstevel@tonic-gate int icol, ilin, tsep, k, ik, vforml, il, text;
310Sstevel@tonic-gate int doubled[MAXCOL], acase[MAXCOL];
320Sstevel@tonic-gate char *s;
330Sstevel@tonic-gate for(icol=0; icol <ncol; icol++)
340Sstevel@tonic-gate {
350Sstevel@tonic-gate doubled[icol] = acase[icol] = 0;
360Sstevel@tonic-gate fprintf(tabout, ".nr %d 0\n", icol+CRIGHT);
370Sstevel@tonic-gate for(text=0; text<2; text++)
380Sstevel@tonic-gate {
390Sstevel@tonic-gate if (text)
400Sstevel@tonic-gate fprintf(tabout, ".%02d\n.rm %02d\n", icol+80, icol+80);
410Sstevel@tonic-gate for(ilin=0; ilin<nlin; ilin++)
420Sstevel@tonic-gate {
430Sstevel@tonic-gate if (instead[ilin]|| fullbot[ilin]) continue;
440Sstevel@tonic-gate vforml=ilin;
450Sstevel@tonic-gate for(il=prev(ilin); il>=0 && vspen(table[il][icol].col); il=prev(il))
460Sstevel@tonic-gate vforml=il;
470Sstevel@tonic-gate if (fspan(vforml,icol)) continue;
480Sstevel@tonic-gate if (filler(table[ilin][icol].col)) continue;
490Sstevel@tonic-gate switch(ctype(vforml,icol))
500Sstevel@tonic-gate {
510Sstevel@tonic-gate case 'a':
520Sstevel@tonic-gate acase[icol]=1;
530Sstevel@tonic-gate s = table[ilin][icol].col;
540Sstevel@tonic-gate if (s>(char *)0 && s<(char *)128 && text)
550Sstevel@tonic-gate {
560Sstevel@tonic-gate if (doubled[icol]==0)
570Sstevel@tonic-gate fprintf(tabout, ".nr %d 0\n.nr %d 0\n",S1,S2);
580Sstevel@tonic-gate doubled[icol]=1;
590Sstevel@tonic-gate fprintf(tabout, ".if \\n(%c->\\n(%d .nr %d \\n(%c-\n",s,S2,S2,s);
600Sstevel@tonic-gate }
610Sstevel@tonic-gate case 'n':
620Sstevel@tonic-gate if (table[ilin][icol].rcol!=0)
630Sstevel@tonic-gate {
640Sstevel@tonic-gate if (doubled[icol]==0 && text==0)
650Sstevel@tonic-gate fprintf(tabout, ".nr %d 0\n.nr %d 0\n", S1, S2);
660Sstevel@tonic-gate doubled[icol]=1;
670Sstevel@tonic-gate if (real(s=table[ilin][icol].col) && !vspen(s))
680Sstevel@tonic-gate {
690Sstevel@tonic-gate if (tx(s) != text) continue;
700Sstevel@tonic-gate fprintf(tabout, ".nr %d ", TMP);
710Sstevel@tonic-gate wide(s, FN(vforml,icol), SZ(vforml,icol)); fprintf(tabout, "\n");
720Sstevel@tonic-gate fprintf(tabout, ".if \\n(%d<\\n(%d .nr %d \\n(%d\n", S1, TMP, S1, TMP);
730Sstevel@tonic-gate }
740Sstevel@tonic-gate if (text==0 && real(s=table[ilin][icol].rcol) && !vspen(s) && !barent(s))
750Sstevel@tonic-gate {
760Sstevel@tonic-gate fprintf(tabout, ".nr %d \\w%c%s%c\n",TMP, F1, s, F1);
770Sstevel@tonic-gate fprintf(tabout, ".if \\n(%d<\\n(%d .nr %d \\n(%d\n",S2,TMP,S2,TMP);
780Sstevel@tonic-gate }
790Sstevel@tonic-gate continue;
800Sstevel@tonic-gate }
810Sstevel@tonic-gate case 'r':
820Sstevel@tonic-gate case 'c':
830Sstevel@tonic-gate case 'l':
840Sstevel@tonic-gate if (real(s=table[ilin][icol].col) && !vspen(s))
850Sstevel@tonic-gate {
860Sstevel@tonic-gate if (tx(s) != text) continue;
870Sstevel@tonic-gate fprintf(tabout, ".nr %d ", TMP);
880Sstevel@tonic-gate wide(s, FN(vforml,icol), SZ(vforml,icol)); fprintf(tabout, "\n");
890Sstevel@tonic-gate fprintf(tabout, ".if \\n(%d<\\n(%d .nr %d \\n(%d\n", icol+CRIGHT, TMP, icol+CRIGHT, TMP);
900Sstevel@tonic-gate }
910Sstevel@tonic-gate }
920Sstevel@tonic-gate }
930Sstevel@tonic-gate }
940Sstevel@tonic-gate if (acase[icol])
950Sstevel@tonic-gate {
960Sstevel@tonic-gate fprintf(tabout, ".if \\n(%d>=\\n(%d .nr %d \\n(%du+2n\n",S2,icol+CRIGHT,icol+CRIGHT,S2);
970Sstevel@tonic-gate }
980Sstevel@tonic-gate if (doubled[icol])
990Sstevel@tonic-gate {
1000Sstevel@tonic-gate fprintf(tabout, ".nr %d \\n(%d\n", icol+CMID, S1);
1010Sstevel@tonic-gate fprintf(tabout, ".nr %d \\n(%d+\\n(%d\n",TMP,icol+CMID,S2);
1020Sstevel@tonic-gate fprintf(tabout, ".if \\n(%d>\\n(%d .nr %d \\n(%d\n",TMP,icol+CRIGHT,icol+CRIGHT,TMP);
1030Sstevel@tonic-gate fprintf(tabout, ".if \\n(%d<\\n(%d .nr %d +(\\n(%d-\\n(%d)/2\n",TMP,icol+CRIGHT,icol+CMID,icol+CRIGHT,TMP);
1040Sstevel@tonic-gate }
1050Sstevel@tonic-gate if (cll[icol][0])
1060Sstevel@tonic-gate {
1070Sstevel@tonic-gate fprintf(tabout, ".nr %d %sn\n", TMP, cll[icol]);
1080Sstevel@tonic-gate fprintf(tabout, ".if \\n(%d<\\n(%d .nr %d \\n(%d\n",icol+CRIGHT, TMP, icol+CRIGHT, TMP);
1090Sstevel@tonic-gate }
1100Sstevel@tonic-gate for(ilin=0; ilin<nlin; ilin++)
1110Sstevel@tonic-gate if (k=lspan(ilin, icol))
1120Sstevel@tonic-gate {
1130Sstevel@tonic-gate s=table[ilin][icol-k].col;
1140Sstevel@tonic-gate if (!real(s) || barent(s) || vspen(s) ) continue;
1150Sstevel@tonic-gate fprintf(tabout, ".nr %d ", TMP);
1160Sstevel@tonic-gate wide(table[ilin][icol-k].col, FN(ilin,icol-k), SZ(ilin,icol-k));
1170Sstevel@tonic-gate for(ik=k; ik>=0; ik--)
1180Sstevel@tonic-gate {
1190Sstevel@tonic-gate fprintf(tabout, "-\\n(%d",CRIGHT+icol-ik);
1200Sstevel@tonic-gate if (!expflg && ik>0) fprintf(tabout, "-%dn", sep[icol-ik]);
1210Sstevel@tonic-gate }
1220Sstevel@tonic-gate fprintf(tabout, "\n");
1230Sstevel@tonic-gate fprintf(tabout, ".if \\n(%d>0 .nr %d \\n(%d/%d\n", TMP, TMP, TMP, k);
1240Sstevel@tonic-gate fprintf(tabout, ".if \\n(%d<0 .nr %d 0\n", TMP, TMP);
1250Sstevel@tonic-gate for(ik=0; ik<k; ik++)
1260Sstevel@tonic-gate {
1270Sstevel@tonic-gate if (doubled[icol-k+ik])
1280Sstevel@tonic-gate fprintf(tabout, ".nr %d +\\n(%d/2\n", icol-k+ik+CMID, TMP);
1290Sstevel@tonic-gate fprintf(tabout, ".nr %d +\\n(%d\n", icol-k+ik+CRIGHT, TMP);
1300Sstevel@tonic-gate }
1310Sstevel@tonic-gate }
1320Sstevel@tonic-gate }
1330Sstevel@tonic-gate if (textflg) untext();
1340Sstevel@tonic-gate /* if even requested, make all columns widest width */
1350Sstevel@tonic-gate # define TMP1 S1
1360Sstevel@tonic-gate # define TMP2 S2
1370Sstevel@tonic-gate if (evenflg)
1380Sstevel@tonic-gate {
1390Sstevel@tonic-gate fprintf(tabout, ".nr %d 0\n", TMP);
1400Sstevel@tonic-gate for(icol=0; icol<ncol; icol++)
1410Sstevel@tonic-gate {
1420Sstevel@tonic-gate if (evenup[icol]==0) continue;
1430Sstevel@tonic-gate fprintf(tabout, ".if \\n(%d>\\n(%d .nr %d \\n(%d\n",
1440Sstevel@tonic-gate icol+CRIGHT, TMP, TMP, icol+CRIGHT);
1450Sstevel@tonic-gate }
1460Sstevel@tonic-gate for(icol=0; icol<ncol; icol++)
1470Sstevel@tonic-gate {
1480Sstevel@tonic-gate if (evenup[icol]==0)
1490Sstevel@tonic-gate /* if column not evened just retain old interval */
1500Sstevel@tonic-gate continue;
1510Sstevel@tonic-gate if (doubled[icol])
1520Sstevel@tonic-gate fprintf(tabout, ".nr %d (100*\\n(%d/\\n(%d)*\\n(%d/100\n",
1530Sstevel@tonic-gate icol+CMID, icol+CMID, icol+CRIGHT, TMP);
1540Sstevel@tonic-gate /* that nonsense with the 100's and parens tries
1550Sstevel@tonic-gate to avoid overflow while proportionally shifting
1560Sstevel@tonic-gate the middle of the number */
1570Sstevel@tonic-gate fprintf(tabout, ".nr %d \\n(%d\n", icol+CRIGHT, TMP);
1580Sstevel@tonic-gate }
1590Sstevel@tonic-gate }
1600Sstevel@tonic-gate /* now adjust for total table width */
1610Sstevel@tonic-gate for(tsep=icol=0; icol<ncol; icol++)
1620Sstevel@tonic-gate tsep+= sep[icol];
1630Sstevel@tonic-gate if (expflg)
1640Sstevel@tonic-gate {
1650Sstevel@tonic-gate fprintf(tabout, ".nr %d 0", TMP);
1660Sstevel@tonic-gate for(icol=0; icol<ncol; icol++)
1670Sstevel@tonic-gate fprintf(tabout, "+\\n(%d", icol+CRIGHT);
1680Sstevel@tonic-gate fprintf(tabout, "\n");
1690Sstevel@tonic-gate fprintf(tabout, ".nr %d \\n(.l-\\n(.i-\\n(%d\n", TMP, TMP);
1700Sstevel@tonic-gate if (boxflg || dboxflg || allflg)
1710Sstevel@tonic-gate tsep += 1;
1720Sstevel@tonic-gate else
1730Sstevel@tonic-gate tsep -= sep[ncol-1];
1740Sstevel@tonic-gate fprintf(tabout, ".nr %d \\n(%d/%d\n", TMP, TMP, tsep);
1750Sstevel@tonic-gate fprintf(tabout, ".if \\n(%d<1n .nr %d 1n\n", TMP, TMP);
1760Sstevel@tonic-gate }
1770Sstevel@tonic-gate else
1780Sstevel@tonic-gate fprintf(tabout, ".nr %d 1n\n", TMP);
1790Sstevel@tonic-gate fprintf(tabout, ".nr %d 0\n",CRIGHT-1);
1800Sstevel@tonic-gate tsep= (boxflg || allflg || dboxflg || left1flg) ? 1 : 0;
1810Sstevel@tonic-gate for(icol=0; icol<ncol; icol++)
1820Sstevel@tonic-gate {
1830Sstevel@tonic-gate fprintf(tabout, ".nr %d \\n(%d+(%d*\\n(%d)\n",icol+CLEFT, icol+CRIGHT-1, tsep, TMP);
1840Sstevel@tonic-gate fprintf(tabout, ".nr %d +\\n(%d\n",icol+CRIGHT, icol+CLEFT);
1850Sstevel@tonic-gate if (doubled[icol])
1860Sstevel@tonic-gate {
1870Sstevel@tonic-gate /* the next line is last-ditch effort to avoid zero field width */
1880Sstevel@tonic-gate /*fprintf(tabout, ".if \\n(%d=0 .nr %d 1\n",icol+CMID, icol+CMID);*/
1890Sstevel@tonic-gate fprintf(tabout, ".nr %d +\\n(%d\n", icol+CMID, icol+CLEFT);
1900Sstevel@tonic-gate /* fprintf(tabout, ".if n .if \\n(%d%%24>0 .nr %d +12u\n",icol+CMID, icol+CMID); */
1910Sstevel@tonic-gate }
1920Sstevel@tonic-gate tsep=sep[icol];
1930Sstevel@tonic-gate }
1940Sstevel@tonic-gate if (rightl)
1950Sstevel@tonic-gate fprintf(tabout, ".nr %d (\\n(%d+\\n(%d)/2\n",ncol+CRIGHT-1, ncol+CLEFT-1, ncol+CRIGHT-2);
1960Sstevel@tonic-gate fprintf(tabout, ".nr TW \\n(%d\n", ncol+CRIGHT-1);
1970Sstevel@tonic-gate if (boxflg || allflg || dboxflg)
1980Sstevel@tonic-gate fprintf(tabout, ".nr TW +%d*\\n(%d\n", sep[ncol-1], TMP);
1990Sstevel@tonic-gate fprintf(tabout,
2000Sstevel@tonic-gate ".if t .if \\n(TW>\\n(.li .tm Table at line %d file %s is too wide - \\n(TW units\n", iline-1, ifile);
2010Sstevel@tonic-gate return;
2020Sstevel@tonic-gate }
203*381Smuffin
204*381Smuffin void
wide(char * s,char * fn,char * size)205*381Smuffin wide(char *s, char *fn, char *size)
2060Sstevel@tonic-gate {
2070Sstevel@tonic-gate if (point(s))
2080Sstevel@tonic-gate {
2090Sstevel@tonic-gate fprintf(tabout, "\\w%c", F1);
2100Sstevel@tonic-gate if (*fn>0) putfont(fn);
2110Sstevel@tonic-gate if (*size) putsize(size);
2120Sstevel@tonic-gate fprintf(tabout, "%s", s);
2130Sstevel@tonic-gate if (*fn>0) putfont("P");
2140Sstevel@tonic-gate if (*size) putsize("0");
2150Sstevel@tonic-gate fprintf(tabout, "%c",F1);
2160Sstevel@tonic-gate }
2170Sstevel@tonic-gate else
2180Sstevel@tonic-gate fprintf(tabout, "\\n(%c-", s);
2190Sstevel@tonic-gate }
220*381Smuffin
221*381Smuffin int
filler(char * s)222*381Smuffin filler(char *s)
2230Sstevel@tonic-gate {
2240Sstevel@tonic-gate return (point(s) && s[0]=='\\' && s[1] == 'R');
2250Sstevel@tonic-gate }
226