1 /* t6.c: compute tab stops */
2 # define tx(a) (a>0 && a<128)
4 # define FN(i,c) font[c][stynum[i]]
5 # define SZ(i,c) csize[c][stynum[i]]
10 maktab(void) /* define the tab stops of the table */
12 int icol, ilin, tsep, k, ik, vforml, il, text;
15 for (icol = 0; icol < ncol; icol++) {
16 doubled[icol] = acase[icol] = 0;
17 Bprint(&tabout, ".nr %2s 0\n", reg(icol, CRIGHT));
18 for (text = 0; text < 2; text++) {
20 Bprint(&tabout, ".%2s\n.rm %2s\n", reg(icol, CRIGHT),
22 for (ilin = 0; ilin < nlin; ilin++) {
23 if (instead[ilin] || fullbot[ilin])
26 for (il = prev(ilin); il >= 0 && vspen(table[il][icol].col); il = prev(il))
28 if (fspan(vforml, icol))
30 if (filler(table[ilin][icol].col))
32 if ((flags[icol][stynum[ilin]] & ZEROW) != 0)
34 switch (ctype(vforml, icol)) {
37 s = table[ilin][icol].col;
38 if ((int)s > 0 && (int)s < 128 && text) {
39 if (doubled[icol] == 0)
40 Bprint(&tabout, ".nr %d 0\n.nr %d 0\n",
43 Bprint(&tabout, ".if \\n(%c->\\n(%d .nr %d \\n(%c-\n",
44 (int)s, S2, S2, (int)s);
47 if (table[ilin][icol].rcol != 0) {
48 if (doubled[icol] == 0 && text == 0)
49 Bprint(&tabout, ".nr %d 0\n.nr %d 0\n",
52 if (real(s = table[ilin][icol].col) && !vspen(s)) {
53 if (tx((int)s) != text)
55 Bprint(&tabout, ".nr %d ", TMP);
56 wide(s, FN(vforml, icol), SZ(vforml, icol));
57 Bprint(&tabout, "\n");
58 Bprint(&tabout, ".if \\n(%d<\\n(%d .nr %d \\n(%d\n",
61 if (text == 0 && real(s = table[ilin][icol].rcol) && !vspen(s) && !barent(s)) {
62 Bprint(&tabout, ".nr %d \\w%c%s%c\n",
64 Bprint(&tabout, ".if \\n(%d<\\n(%d .nr %d \\n(%d\n", S2, TMP, S2,
72 if (real(s = table[ilin][icol].col) && !vspen(s)) {
73 if (tx((int)s) != text)
75 Bprint(&tabout, ".nr %d ", TMP);
76 wide(s, FN(vforml, icol), SZ(vforml, icol));
77 Bprint(&tabout, "\n");
78 Bprint(&tabout, ".if \\n(%2s<\\n(%d .nr %2s \\n(%d\n",
79 reg(icol, CRIGHT), TMP, reg(icol, CRIGHT), TMP);
85 Bprint(&tabout, ".if \\n(%d>=\\n(%2s .nr %2s \\n(%du+2n\n",
86 S2, reg(icol, CRIGHT), reg(icol, CRIGHT), S2);
89 Bprint(&tabout, ".nr %2s \\n(%d\n", reg(icol, CMID), S1);
90 Bprint(&tabout, ".nr %d \\n(%2s+\\n(%d\n", TMP, reg(icol, CMID), S2);
91 Bprint(&tabout, ".if \\n(%d>\\n(%2s .nr %2s \\n(%d\n", TMP,
92 reg(icol, CRIGHT), reg(icol, CRIGHT), TMP);
93 Bprint(&tabout, ".if \\n(%d<\\n(%2s .nr %2s +(\\n(%2s-\\n(%d)/2\n",
94 TMP, reg(icol, CRIGHT), reg(icol, CMID), reg(icol, CRIGHT), TMP);
97 Bprint(&tabout, ".nr %d %sn\n", TMP, cll[icol]);
98 Bprint(&tabout, ".if \\n(%2s<\\n(%d .nr %2s \\n(%d\n",
99 reg(icol, CRIGHT), TMP, reg(icol, CRIGHT), TMP);
101 for (ilin = 0; ilin < nlin; ilin++)
102 if (k = lspan(ilin, icol)) {
103 s = table[ilin][icol-k].col;
104 if (!real(s) || barent(s) || vspen(s) )
106 Bprint(&tabout, ".nr %d ", TMP);
107 wide(table[ilin][icol-k].col, FN(ilin, icol - k), SZ(ilin, icol - k));
108 for (ik = k; ik >= 0; ik--) {
109 Bprint(&tabout, "-\\n(%2s", reg(icol - ik, CRIGHT));
110 if (!expflg && ik > 0)
111 Bprint(&tabout, "-%dn", sep[icol-ik]);
113 Bprint(&tabout, "\n");
114 Bprint(&tabout, ".if \\n(%d>0 .nr %d \\n(%d/%d\n", TMP,
116 Bprint(&tabout, ".if \\n(%d<0 .nr %d 0\n", TMP, TMP);
117 for (ik = 1; ik <= k; ik++) {
118 if (doubled[icol-k+ik])
119 Bprint(&tabout, ".nr %2s +\\n(%d/2\n",
120 reg(icol - k + ik, CMID), TMP);
121 Bprint(&tabout, ".nr %2s +\\n(%d\n",
122 reg(icol - k + ik, CRIGHT), TMP);
128 /* if even requested, make all columns widest width */
130 Bprint(&tabout, ".nr %d 0\n", TMP);
131 for (icol = 0; icol < ncol; icol++) {
132 if (evenup[icol] == 0)
134 Bprint(&tabout, ".if \\n(%2s>\\n(%d .nr %d \\n(%2s\n",
135 reg(icol, CRIGHT), TMP, TMP, reg(icol, CRIGHT));
137 for (icol = 0; icol < ncol; icol++) {
138 if (evenup[icol] == 0)
139 /* if column not evened just retain old interval */
142 Bprint(&tabout, ".nr %2s (100*\\n(%2s/\\n(%2s)*\\n(%d/100\n",
143 reg(icol, CMID), reg(icol, CMID), reg(icol, CRIGHT), TMP);
144 /* that nonsense with the 100's and parens tries
145 to avoid overflow while proportionally shifting
146 the middle of the number */
147 Bprint(&tabout, ".nr %2s \\n(%d\n", reg(icol, CRIGHT), TMP);
150 /* now adjust for total table width */
151 for (tsep = icol = 0; icol < ncol; icol++)
154 Bprint(&tabout, ".nr %d 0", TMP);
155 for (icol = 0; icol < ncol; icol++)
156 Bprint(&tabout, "+\\n(%2s", reg(icol, CRIGHT));
157 Bprint(&tabout, "\n");
158 Bprint(&tabout, ".nr %d \\n(.l-\\n(%d\n", TMP, TMP);
159 if (boxflg || dboxflg || allflg)
163 Bprint(&tabout, ".nr %d \\n(%d/%d\n", TMP, TMP, tsep);
164 Bprint(&tabout, ".if \\n(%d<0 .nr %d 0\n", TMP, TMP);
166 Bprint(&tabout, ".nr %d 1n\n", TMP);
167 Bprint(&tabout, ".nr %2s 0\n", reg(-1, CRIGHT));
168 tsep = (boxflg || allflg || dboxflg || left1flg) ? 2 : 0;
171 for (icol = 0; icol < ncol; icol++) {
172 Bprint(&tabout, ".nr %2s \\n(%2s+((%d*\\n(%d)/2)\n", reg(icol, CLEFT),
173 reg(icol - 1, CRIGHT), tsep, TMP);
174 Bprint(&tabout, ".nr %2s +\\n(%2s\n", reg(icol, CRIGHT), reg(icol, CLEFT));
176 /* the next line is last-ditch effort to avoid zero field width */
177 /*Bprint(&tabout, ".if \\n(%2s=0 .nr %2s 1\n",reg(icol,CMID), reg(icol,CMID));*/
178 Bprint(&tabout, ".nr %2s +\\n(%2s\n", reg(icol, CMID),
180 /* Bprint(&tabout, ".if n .if \\n(%s%%24>0 .nr %s +12u\n",reg(icol,CMID), reg(icol,CMID)); */
182 tsep = sep[icol] * 2;
185 Bprint(&tabout, ".nr %s (\\n(%s+\\n(%s)/2\n", reg(ncol - 1, CRIGHT),
186 reg(ncol - 1, CLEFT), reg(ncol - 2, CRIGHT));
187 Bprint(&tabout, ".nr TW \\n(%2s\n", reg(ncol - 1, CRIGHT));
189 if (boxflg || allflg || dboxflg)
190 Bprint(&tabout, ".nr TW +((%d*\\n(%d)/2)\n", tsep, TMP);
192 ".if t .if (\\n(TW+\\n(.o)>7.65i .tm Table at line %d file %s is too wide - \\n(TW units\n", iline - 1, ifile);
198 wide(char *s, char *fn, char *size)
201 Bprint(&tabout, "\\w%c", F1);
206 Bprint(&tabout, "%s", s);
211 Bprint(&tabout, "%c", F1);
213 Bprint(&tabout, "\\n(%c-", (int)s);
220 return (point(s) && s[0] == '\\' && s[1] == 'R');