xref: /titanic_53/usr/src/cmd/tbl/t6.c (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1*7c478bd9Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
2*7c478bd9Sstevel@tonic-gate /*	  All Rights Reserved  	*/
3*7c478bd9Sstevel@tonic-gate 
4*7c478bd9Sstevel@tonic-gate 
5*7c478bd9Sstevel@tonic-gate /*
6*7c478bd9Sstevel@tonic-gate  * Copyright (c) 1980 Regents of the University of California.
7*7c478bd9Sstevel@tonic-gate  * All rights reserved. The Berkeley software License Agreement
8*7c478bd9Sstevel@tonic-gate  * specifies the terms and conditions for redistribution.
9*7c478bd9Sstevel@tonic-gate  */
10*7c478bd9Sstevel@tonic-gate 
11*7c478bd9Sstevel@tonic-gate /*
12*7c478bd9Sstevel@tonic-gate  * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
13*7c478bd9Sstevel@tonic-gate  * All Rights Reserved.
14*7c478bd9Sstevel@tonic-gate  */
15*7c478bd9Sstevel@tonic-gate 
16*7c478bd9Sstevel@tonic-gate #ident	"%Z%%M%	%I%	%E% SMI"	/* SVr4.0 1.1	*/
17*7c478bd9Sstevel@tonic-gate 
18*7c478bd9Sstevel@tonic-gate  /* t6.c: compute tab stops */
19*7c478bd9Sstevel@tonic-gate # define tx(a) (a>(char *)0 && a<(char *)128)
20*7c478bd9Sstevel@tonic-gate # include "t..c"
21*7c478bd9Sstevel@tonic-gate maktab()
22*7c478bd9Sstevel@tonic-gate {
23*7c478bd9Sstevel@tonic-gate # define FN(i,c) font[stynum[i]][c]
24*7c478bd9Sstevel@tonic-gate # define SZ(i,c) csize[stynum[i]][c]
25*7c478bd9Sstevel@tonic-gate /* define the tab stops of the table */
26*7c478bd9Sstevel@tonic-gate int icol, ilin, tsep, k, ik, vforml, il, text;
27*7c478bd9Sstevel@tonic-gate int doubled[MAXCOL], acase[MAXCOL];
28*7c478bd9Sstevel@tonic-gate char *s;
29*7c478bd9Sstevel@tonic-gate for(icol=0; icol <ncol; icol++)
30*7c478bd9Sstevel@tonic-gate 	{
31*7c478bd9Sstevel@tonic-gate 	doubled[icol] = acase[icol] = 0;
32*7c478bd9Sstevel@tonic-gate 	fprintf(tabout, ".nr %d 0\n", icol+CRIGHT);
33*7c478bd9Sstevel@tonic-gate    for(text=0; text<2; text++)
34*7c478bd9Sstevel@tonic-gate 	{
35*7c478bd9Sstevel@tonic-gate 	if (text)
36*7c478bd9Sstevel@tonic-gate 		fprintf(tabout, ".%02d\n.rm %02d\n", icol+80, icol+80);
37*7c478bd9Sstevel@tonic-gate 	for(ilin=0; ilin<nlin; ilin++)
38*7c478bd9Sstevel@tonic-gate 		{
39*7c478bd9Sstevel@tonic-gate 		if (instead[ilin]|| fullbot[ilin]) continue;
40*7c478bd9Sstevel@tonic-gate 		vforml=ilin;
41*7c478bd9Sstevel@tonic-gate 		for(il=prev(ilin); il>=0 && vspen(table[il][icol].col); il=prev(il))
42*7c478bd9Sstevel@tonic-gate 			vforml=il;
43*7c478bd9Sstevel@tonic-gate 		if (fspan(vforml,icol)) continue;
44*7c478bd9Sstevel@tonic-gate 		if (filler(table[ilin][icol].col)) continue;
45*7c478bd9Sstevel@tonic-gate 		switch(ctype(vforml,icol))
46*7c478bd9Sstevel@tonic-gate 			{
47*7c478bd9Sstevel@tonic-gate 			case 'a':
48*7c478bd9Sstevel@tonic-gate 				acase[icol]=1;
49*7c478bd9Sstevel@tonic-gate 				s = table[ilin][icol].col;
50*7c478bd9Sstevel@tonic-gate 				if (s>(char *)0 && s<(char *)128 && text)
51*7c478bd9Sstevel@tonic-gate 					{
52*7c478bd9Sstevel@tonic-gate 					if (doubled[icol]==0)
53*7c478bd9Sstevel@tonic-gate 						fprintf(tabout, ".nr %d 0\n.nr %d 0\n",S1,S2);
54*7c478bd9Sstevel@tonic-gate 					doubled[icol]=1;
55*7c478bd9Sstevel@tonic-gate 					fprintf(tabout, ".if \\n(%c->\\n(%d .nr %d \\n(%c-\n",s,S2,S2,s);
56*7c478bd9Sstevel@tonic-gate 					}
57*7c478bd9Sstevel@tonic-gate 			case 'n':
58*7c478bd9Sstevel@tonic-gate 				if (table[ilin][icol].rcol!=0)
59*7c478bd9Sstevel@tonic-gate 					{
60*7c478bd9Sstevel@tonic-gate 					if (doubled[icol]==0 && text==0)
61*7c478bd9Sstevel@tonic-gate 						fprintf(tabout, ".nr %d 0\n.nr %d 0\n", S1, S2);
62*7c478bd9Sstevel@tonic-gate 					doubled[icol]=1;
63*7c478bd9Sstevel@tonic-gate 					if (real(s=table[ilin][icol].col) && !vspen(s))
64*7c478bd9Sstevel@tonic-gate 						{
65*7c478bd9Sstevel@tonic-gate 						if (tx(s) != text) continue;
66*7c478bd9Sstevel@tonic-gate 						fprintf(tabout, ".nr %d ", TMP);
67*7c478bd9Sstevel@tonic-gate 						wide(s, FN(vforml,icol), SZ(vforml,icol)); fprintf(tabout, "\n");
68*7c478bd9Sstevel@tonic-gate 						fprintf(tabout, ".if \\n(%d<\\n(%d .nr %d \\n(%d\n", S1, TMP, S1, TMP);
69*7c478bd9Sstevel@tonic-gate 						}
70*7c478bd9Sstevel@tonic-gate 					if (text==0 && real(s=table[ilin][icol].rcol) && !vspen(s) && !barent(s))
71*7c478bd9Sstevel@tonic-gate 						{
72*7c478bd9Sstevel@tonic-gate 						fprintf(tabout, ".nr %d \\w%c%s%c\n",TMP, F1, s, F1);
73*7c478bd9Sstevel@tonic-gate 						fprintf(tabout, ".if \\n(%d<\\n(%d .nr %d \\n(%d\n",S2,TMP,S2,TMP);
74*7c478bd9Sstevel@tonic-gate 						}
75*7c478bd9Sstevel@tonic-gate 					continue;
76*7c478bd9Sstevel@tonic-gate 					}
77*7c478bd9Sstevel@tonic-gate 			case 'r':
78*7c478bd9Sstevel@tonic-gate 			case 'c':
79*7c478bd9Sstevel@tonic-gate 			case 'l':
80*7c478bd9Sstevel@tonic-gate 				if (real(s=table[ilin][icol].col) && !vspen(s))
81*7c478bd9Sstevel@tonic-gate 					{
82*7c478bd9Sstevel@tonic-gate 					if (tx(s) != text) continue;
83*7c478bd9Sstevel@tonic-gate 					fprintf(tabout, ".nr %d ", TMP);
84*7c478bd9Sstevel@tonic-gate 					wide(s, FN(vforml,icol), SZ(vforml,icol)); fprintf(tabout, "\n");
85*7c478bd9Sstevel@tonic-gate 					fprintf(tabout, ".if \\n(%d<\\n(%d .nr %d \\n(%d\n", icol+CRIGHT, TMP, icol+CRIGHT, TMP);
86*7c478bd9Sstevel@tonic-gate 					}
87*7c478bd9Sstevel@tonic-gate 			}
88*7c478bd9Sstevel@tonic-gate 		}
89*7c478bd9Sstevel@tonic-gate 		}
90*7c478bd9Sstevel@tonic-gate 	if (acase[icol])
91*7c478bd9Sstevel@tonic-gate 		{
92*7c478bd9Sstevel@tonic-gate 		fprintf(tabout, ".if \\n(%d>=\\n(%d .nr %d \\n(%du+2n\n",S2,icol+CRIGHT,icol+CRIGHT,S2);
93*7c478bd9Sstevel@tonic-gate 		}
94*7c478bd9Sstevel@tonic-gate 	if (doubled[icol])
95*7c478bd9Sstevel@tonic-gate 		{
96*7c478bd9Sstevel@tonic-gate 		fprintf(tabout, ".nr %d \\n(%d\n", icol+CMID, S1);
97*7c478bd9Sstevel@tonic-gate 		fprintf(tabout, ".nr %d \\n(%d+\\n(%d\n",TMP,icol+CMID,S2);
98*7c478bd9Sstevel@tonic-gate 		fprintf(tabout, ".if \\n(%d>\\n(%d .nr %d \\n(%d\n",TMP,icol+CRIGHT,icol+CRIGHT,TMP);
99*7c478bd9Sstevel@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);
100*7c478bd9Sstevel@tonic-gate 		}
101*7c478bd9Sstevel@tonic-gate 	if (cll[icol][0])
102*7c478bd9Sstevel@tonic-gate 		{
103*7c478bd9Sstevel@tonic-gate 		fprintf(tabout, ".nr %d %sn\n", TMP, cll[icol]);
104*7c478bd9Sstevel@tonic-gate 		fprintf(tabout, ".if \\n(%d<\\n(%d .nr %d \\n(%d\n",icol+CRIGHT, TMP, icol+CRIGHT, TMP);
105*7c478bd9Sstevel@tonic-gate 		}
106*7c478bd9Sstevel@tonic-gate 	for(ilin=0; ilin<nlin; ilin++)
107*7c478bd9Sstevel@tonic-gate 	if (k=lspan(ilin, icol))
108*7c478bd9Sstevel@tonic-gate 		{
109*7c478bd9Sstevel@tonic-gate 		s=table[ilin][icol-k].col;
110*7c478bd9Sstevel@tonic-gate 		if (!real(s) || barent(s) || vspen(s) ) continue;
111*7c478bd9Sstevel@tonic-gate 		fprintf(tabout, ".nr %d ", TMP);
112*7c478bd9Sstevel@tonic-gate 		wide(table[ilin][icol-k].col, FN(ilin,icol-k), SZ(ilin,icol-k));
113*7c478bd9Sstevel@tonic-gate 		for(ik=k; ik>=0; ik--)
114*7c478bd9Sstevel@tonic-gate 			{
115*7c478bd9Sstevel@tonic-gate 			fprintf(tabout, "-\\n(%d",CRIGHT+icol-ik);
116*7c478bd9Sstevel@tonic-gate 			if (!expflg && ik>0) fprintf(tabout, "-%dn", sep[icol-ik]);
117*7c478bd9Sstevel@tonic-gate 			}
118*7c478bd9Sstevel@tonic-gate 		fprintf(tabout, "\n");
119*7c478bd9Sstevel@tonic-gate 		fprintf(tabout, ".if \\n(%d>0 .nr %d \\n(%d/%d\n", TMP, TMP, TMP, k);
120*7c478bd9Sstevel@tonic-gate 		fprintf(tabout, ".if \\n(%d<0 .nr %d 0\n", TMP, TMP);
121*7c478bd9Sstevel@tonic-gate 		for(ik=0; ik<k; ik++)
122*7c478bd9Sstevel@tonic-gate 			{
123*7c478bd9Sstevel@tonic-gate 			if (doubled[icol-k+ik])
124*7c478bd9Sstevel@tonic-gate 				fprintf(tabout, ".nr %d +\\n(%d/2\n", icol-k+ik+CMID, TMP);
125*7c478bd9Sstevel@tonic-gate 			fprintf(tabout, ".nr %d +\\n(%d\n", icol-k+ik+CRIGHT, TMP);
126*7c478bd9Sstevel@tonic-gate 			}
127*7c478bd9Sstevel@tonic-gate 		}
128*7c478bd9Sstevel@tonic-gate 	}
129*7c478bd9Sstevel@tonic-gate if (textflg) untext();
130*7c478bd9Sstevel@tonic-gate /* if even requested, make all columns widest width */
131*7c478bd9Sstevel@tonic-gate # define TMP1 S1
132*7c478bd9Sstevel@tonic-gate # define TMP2 S2
133*7c478bd9Sstevel@tonic-gate if (evenflg)
134*7c478bd9Sstevel@tonic-gate 	{
135*7c478bd9Sstevel@tonic-gate 	fprintf(tabout, ".nr %d 0\n", TMP);
136*7c478bd9Sstevel@tonic-gate 	for(icol=0; icol<ncol; icol++)
137*7c478bd9Sstevel@tonic-gate 		{
138*7c478bd9Sstevel@tonic-gate 		if (evenup[icol]==0) continue;
139*7c478bd9Sstevel@tonic-gate 		fprintf(tabout, ".if \\n(%d>\\n(%d .nr %d \\n(%d\n",
140*7c478bd9Sstevel@tonic-gate 		icol+CRIGHT, TMP, TMP, icol+CRIGHT);
141*7c478bd9Sstevel@tonic-gate 		}
142*7c478bd9Sstevel@tonic-gate 	for(icol=0; icol<ncol; icol++)
143*7c478bd9Sstevel@tonic-gate 		{
144*7c478bd9Sstevel@tonic-gate 		if (evenup[icol]==0)
145*7c478bd9Sstevel@tonic-gate 			/* if column not evened just retain old interval */
146*7c478bd9Sstevel@tonic-gate 			continue;
147*7c478bd9Sstevel@tonic-gate 		if (doubled[icol])
148*7c478bd9Sstevel@tonic-gate 			fprintf(tabout, ".nr %d (100*\\n(%d/\\n(%d)*\\n(%d/100\n",
149*7c478bd9Sstevel@tonic-gate 				icol+CMID, icol+CMID, icol+CRIGHT, TMP);
150*7c478bd9Sstevel@tonic-gate 				/* that nonsense with the 100's and parens tries
151*7c478bd9Sstevel@tonic-gate 				   to avoid overflow while proportionally shifting
152*7c478bd9Sstevel@tonic-gate 				   the middle of the number */
153*7c478bd9Sstevel@tonic-gate 		fprintf(tabout, ".nr %d \\n(%d\n", icol+CRIGHT, TMP);
154*7c478bd9Sstevel@tonic-gate 		}
155*7c478bd9Sstevel@tonic-gate 	}
156*7c478bd9Sstevel@tonic-gate /* now adjust for total table width */
157*7c478bd9Sstevel@tonic-gate for(tsep=icol=0; icol<ncol; icol++)
158*7c478bd9Sstevel@tonic-gate 	tsep+= sep[icol];
159*7c478bd9Sstevel@tonic-gate if (expflg)
160*7c478bd9Sstevel@tonic-gate 	{
161*7c478bd9Sstevel@tonic-gate 	fprintf(tabout, ".nr %d 0", TMP);
162*7c478bd9Sstevel@tonic-gate 	for(icol=0; icol<ncol; icol++)
163*7c478bd9Sstevel@tonic-gate 		fprintf(tabout, "+\\n(%d", icol+CRIGHT);
164*7c478bd9Sstevel@tonic-gate 	fprintf(tabout, "\n");
165*7c478bd9Sstevel@tonic-gate 	fprintf(tabout, ".nr %d \\n(.l-\\n(.i-\\n(%d\n", TMP, TMP);
166*7c478bd9Sstevel@tonic-gate 	if (boxflg || dboxflg || allflg)
167*7c478bd9Sstevel@tonic-gate 		tsep += 1;
168*7c478bd9Sstevel@tonic-gate 	else
169*7c478bd9Sstevel@tonic-gate 		tsep -= sep[ncol-1];
170*7c478bd9Sstevel@tonic-gate 	fprintf(tabout, ".nr %d \\n(%d/%d\n", TMP, TMP,  tsep);
171*7c478bd9Sstevel@tonic-gate 	fprintf(tabout, ".if \\n(%d<1n .nr %d 1n\n", TMP, TMP);
172*7c478bd9Sstevel@tonic-gate 	}
173*7c478bd9Sstevel@tonic-gate else
174*7c478bd9Sstevel@tonic-gate 	fprintf(tabout, ".nr %d 1n\n", TMP);
175*7c478bd9Sstevel@tonic-gate fprintf(tabout, ".nr %d 0\n",CRIGHT-1);
176*7c478bd9Sstevel@tonic-gate tsep= (boxflg || allflg || dboxflg || left1flg) ? 1 : 0;
177*7c478bd9Sstevel@tonic-gate for(icol=0; icol<ncol; icol++)
178*7c478bd9Sstevel@tonic-gate 	{
179*7c478bd9Sstevel@tonic-gate 	fprintf(tabout, ".nr %d \\n(%d+(%d*\\n(%d)\n",icol+CLEFT, icol+CRIGHT-1, tsep, TMP);
180*7c478bd9Sstevel@tonic-gate 	fprintf(tabout, ".nr %d +\\n(%d\n",icol+CRIGHT, icol+CLEFT);
181*7c478bd9Sstevel@tonic-gate 	if (doubled[icol])
182*7c478bd9Sstevel@tonic-gate 		{
183*7c478bd9Sstevel@tonic-gate 		/* the next line is last-ditch effort to avoid zero field width */
184*7c478bd9Sstevel@tonic-gate 		/*fprintf(tabout, ".if \\n(%d=0 .nr %d 1\n",icol+CMID, icol+CMID);*/
185*7c478bd9Sstevel@tonic-gate 		fprintf(tabout, ".nr %d +\\n(%d\n", icol+CMID, icol+CLEFT);
186*7c478bd9Sstevel@tonic-gate 	/*  fprintf(tabout, ".if n .if \\n(%d%%24>0 .nr %d +12u\n",icol+CMID, icol+CMID); */
187*7c478bd9Sstevel@tonic-gate 		}
188*7c478bd9Sstevel@tonic-gate 	tsep=sep[icol];
189*7c478bd9Sstevel@tonic-gate 	}
190*7c478bd9Sstevel@tonic-gate if (rightl)
191*7c478bd9Sstevel@tonic-gate 	fprintf(tabout, ".nr %d (\\n(%d+\\n(%d)/2\n",ncol+CRIGHT-1, ncol+CLEFT-1, ncol+CRIGHT-2);
192*7c478bd9Sstevel@tonic-gate fprintf(tabout, ".nr TW \\n(%d\n", ncol+CRIGHT-1);
193*7c478bd9Sstevel@tonic-gate if (boxflg || allflg || dboxflg)
194*7c478bd9Sstevel@tonic-gate 	fprintf(tabout, ".nr TW +%d*\\n(%d\n", sep[ncol-1], TMP);
195*7c478bd9Sstevel@tonic-gate fprintf(tabout,
196*7c478bd9Sstevel@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);
197*7c478bd9Sstevel@tonic-gate return;
198*7c478bd9Sstevel@tonic-gate }
199*7c478bd9Sstevel@tonic-gate wide(s, fn, size)
200*7c478bd9Sstevel@tonic-gate 	char *s, *size, *fn;
201*7c478bd9Sstevel@tonic-gate {
202*7c478bd9Sstevel@tonic-gate if (point(s))
203*7c478bd9Sstevel@tonic-gate 	{
204*7c478bd9Sstevel@tonic-gate 	fprintf(tabout, "\\w%c", F1);
205*7c478bd9Sstevel@tonic-gate 	if (*fn>0) putfont(fn);
206*7c478bd9Sstevel@tonic-gate 	if (*size) putsize(size);
207*7c478bd9Sstevel@tonic-gate 	fprintf(tabout, "%s", s);
208*7c478bd9Sstevel@tonic-gate 	if (*fn>0) putfont("P");
209*7c478bd9Sstevel@tonic-gate 	if (*size) putsize("0");
210*7c478bd9Sstevel@tonic-gate 	fprintf(tabout, "%c",F1);
211*7c478bd9Sstevel@tonic-gate 	}
212*7c478bd9Sstevel@tonic-gate else
213*7c478bd9Sstevel@tonic-gate 	fprintf(tabout, "\\n(%c-", s);
214*7c478bd9Sstevel@tonic-gate }
215*7c478bd9Sstevel@tonic-gate filler(s)
216*7c478bd9Sstevel@tonic-gate 	char *s;
217*7c478bd9Sstevel@tonic-gate {
218*7c478bd9Sstevel@tonic-gate return (point(s) && s[0]=='\\' && s[1] == 'R');
219*7c478bd9Sstevel@tonic-gate }
220