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