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