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