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