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
, s
, text
;
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
++) {
20 fprintf(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 ss
= table
[ilin
][icol
].col
;
39 if (s
> 0 && s
< 128 && text
) {
40 if (doubled
[icol
] == 0)
41 fprintf(tabout
, ".nr %d 0\n.nr %d 0\n",
44 fprintf(tabout
, ".if \\n(%c->\\n(%d .nr %d \\n(%c-\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",
53 if (real(ss
= table
[ilin
][icol
].col
) && !vspen(ss
)) {
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",
63 if (text
== 0 && real(ss
= table
[ilin
][icol
].rcol
) && !vspen(ss
) && !barent(ss
)) {
64 fprintf(tabout
, ".nr %d \\w%c%s%c\n",
66 fprintf(tabout
, ".if \\n(%d<\\n(%d .nr %d \\n(%d\n", S2
, TMP
, S2
,
74 if (real(ss
= table
[ilin
][icol
].col
) && !vspen(ss
)) {
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
);
88 fprintf(tabout
, ".if \\n(%d>=\\n(%2s .nr %2s \\n(%du+2n\n",
89 S2
, reg(icol
, CRIGHT
), reg(icol
, CRIGHT
), S2
);
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
);
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
) )
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
,
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
);
131 /* if even requested, make all columns widest width */
133 fprintf(tabout
, ".nr %d 0\n", TMP
);
134 for (icol
= 0; icol
< ncol
; icol
++) {
135 if (evenup
[icol
] == 0)
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 */
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
++)
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
)
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
);
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;
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
));
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
),
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;
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
));
192 if (boxflg
|| allflg
|| dboxflg
)
193 fprintf(tabout
, ".nr TW +((%d*\\n(%d)/2)\n", tsep
, TMP
);
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
);
200 wide(char *s
, char *fn
, char *size
)
203 fprintf(tabout
, "\\w%c", F1
);
208 fprintf(tabout
, "%s", s
);
213 fprintf(tabout
, "%c", F1
);
215 fprintf(tabout
, "\\n(%c-", (int)(uintptr
)s
);
222 return (point(s
) && s
[0] == '\\' && s
[1] == 'R');