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