2 * Copyright 1990 Sun Microsystems, Inc. All rights reserved.
3 * Use is subject to license terms.
6 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
7 /* All Rights Reserved */
11 * Copyright (c) 1980 Regents of the University of California.
12 * All rights reserved. The Berkeley software License Agreement
13 * specifies the terms and conditions for redistribution.
16 #pragma ident "%Z%%M% %I% %E% SMI"
18 /* t6.c: compute tab stops */
19 # define tx(a) (a>(char *)0 && a<(char *)128)
22 void wide(char *, char *, char *);
27 # define FN(i,c) font[stynum[i]][c]
28 # define SZ(i,c) csize[stynum[i]][c]
29 /* define the tab stops of the table */
30 int icol
, ilin
, tsep
, k
, ik
, vforml
, il
, text
;
31 int doubled
[MAXCOL
], acase
[MAXCOL
];
33 for(icol
=0; icol
<ncol
; icol
++)
35 doubled
[icol
] = acase
[icol
] = 0;
36 fprintf(tabout
, ".nr %d 0\n", icol
+CRIGHT
);
37 for(text
=0; text
<2; text
++)
40 fprintf(tabout
, ".%02d\n.rm %02d\n", icol
+80, icol
+80);
41 for(ilin
=0; ilin
<nlin
; ilin
++)
43 if (instead
[ilin
]|| fullbot
[ilin
]) continue;
45 for(il
=prev(ilin
); il
>=0 && vspen(table
[il
][icol
].col
); il
=prev(il
))
47 if (fspan(vforml
,icol
)) continue;
48 if (filler(table
[ilin
][icol
].col
)) continue;
49 switch(ctype(vforml
,icol
))
53 s
= table
[ilin
][icol
].col
;
54 if (s
>(char *)0 && s
<(char *)128 && text
)
57 fprintf(tabout
, ".nr %d 0\n.nr %d 0\n",S1
,S2
);
59 fprintf(tabout
, ".if \\n(%c->\\n(%d .nr %d \\n(%c-\n",s
,S2
,S2
,s
);
62 if (table
[ilin
][icol
].rcol
!=0)
64 if (doubled
[icol
]==0 && text
==0)
65 fprintf(tabout
, ".nr %d 0\n.nr %d 0\n", S1
, S2
);
67 if (real(s
=table
[ilin
][icol
].col
) && !vspen(s
))
69 if (tx(s
) != text
) continue;
70 fprintf(tabout
, ".nr %d ", TMP
);
71 wide(s
, FN(vforml
,icol
), SZ(vforml
,icol
)); fprintf(tabout
, "\n");
72 fprintf(tabout
, ".if \\n(%d<\\n(%d .nr %d \\n(%d\n", S1
, TMP
, S1
, TMP
);
74 if (text
==0 && real(s
=table
[ilin
][icol
].rcol
) && !vspen(s
) && !barent(s
))
76 fprintf(tabout
, ".nr %d \\w%c%s%c\n",TMP
, F1
, s
, F1
);
77 fprintf(tabout
, ".if \\n(%d<\\n(%d .nr %d \\n(%d\n",S2
,TMP
,S2
,TMP
);
84 if (real(s
=table
[ilin
][icol
].col
) && !vspen(s
))
86 if (tx(s
) != text
) continue;
87 fprintf(tabout
, ".nr %d ", TMP
);
88 wide(s
, FN(vforml
,icol
), SZ(vforml
,icol
)); fprintf(tabout
, "\n");
89 fprintf(tabout
, ".if \\n(%d<\\n(%d .nr %d \\n(%d\n", icol
+CRIGHT
, TMP
, icol
+CRIGHT
, TMP
);
96 fprintf(tabout
, ".if \\n(%d>=\\n(%d .nr %d \\n(%du+2n\n",S2
,icol
+CRIGHT
,icol
+CRIGHT
,S2
);
100 fprintf(tabout
, ".nr %d \\n(%d\n", icol
+CMID
, S1
);
101 fprintf(tabout
, ".nr %d \\n(%d+\\n(%d\n",TMP
,icol
+CMID
,S2
);
102 fprintf(tabout
, ".if \\n(%d>\\n(%d .nr %d \\n(%d\n",TMP
,icol
+CRIGHT
,icol
+CRIGHT
,TMP
);
103 fprintf(tabout
, ".if \\n(%d<\\n(%d .nr %d +(\\n(%d-\\n(%d)/2\n",TMP
,icol
+CRIGHT
,icol
+CMID
,icol
+CRIGHT
,TMP
);
107 fprintf(tabout
, ".nr %d %sn\n", TMP
, cll
[icol
]);
108 fprintf(tabout
, ".if \\n(%d<\\n(%d .nr %d \\n(%d\n",icol
+CRIGHT
, TMP
, icol
+CRIGHT
, TMP
);
110 for(ilin
=0; ilin
<nlin
; ilin
++)
111 if (k
=lspan(ilin
, icol
))
113 s
=table
[ilin
][icol
-k
].col
;
114 if (!real(s
) || barent(s
) || vspen(s
) ) continue;
115 fprintf(tabout
, ".nr %d ", TMP
);
116 wide(table
[ilin
][icol
-k
].col
, FN(ilin
,icol
-k
), SZ(ilin
,icol
-k
));
117 for(ik
=k
; ik
>=0; ik
--)
119 fprintf(tabout
, "-\\n(%d",CRIGHT
+icol
-ik
);
120 if (!expflg
&& ik
>0) fprintf(tabout
, "-%dn", sep
[icol
-ik
]);
122 fprintf(tabout
, "\n");
123 fprintf(tabout
, ".if \\n(%d>0 .nr %d \\n(%d/%d\n", TMP
, TMP
, TMP
, k
);
124 fprintf(tabout
, ".if \\n(%d<0 .nr %d 0\n", TMP
, TMP
);
125 for(ik
=0; ik
<k
; ik
++)
127 if (doubled
[icol
-k
+ik
])
128 fprintf(tabout
, ".nr %d +\\n(%d/2\n", icol
-k
+ik
+CMID
, TMP
);
129 fprintf(tabout
, ".nr %d +\\n(%d\n", icol
-k
+ik
+CRIGHT
, TMP
);
133 if (textflg
) untext();
134 /* if even requested, make all columns widest width */
139 fprintf(tabout
, ".nr %d 0\n", TMP
);
140 for(icol
=0; icol
<ncol
; icol
++)
142 if (evenup
[icol
]==0) continue;
143 fprintf(tabout
, ".if \\n(%d>\\n(%d .nr %d \\n(%d\n",
144 icol
+CRIGHT
, TMP
, TMP
, icol
+CRIGHT
);
146 for(icol
=0; icol
<ncol
; icol
++)
149 /* if column not evened just retain old interval */
152 fprintf(tabout
, ".nr %d (100*\\n(%d/\\n(%d)*\\n(%d/100\n",
153 icol
+CMID
, icol
+CMID
, icol
+CRIGHT
, TMP
);
154 /* that nonsense with the 100's and parens tries
155 to avoid overflow while proportionally shifting
156 the middle of the number */
157 fprintf(tabout
, ".nr %d \\n(%d\n", icol
+CRIGHT
, TMP
);
160 /* now adjust for total table width */
161 for(tsep
=icol
=0; icol
<ncol
; icol
++)
165 fprintf(tabout
, ".nr %d 0", TMP
);
166 for(icol
=0; icol
<ncol
; icol
++)
167 fprintf(tabout
, "+\\n(%d", icol
+CRIGHT
);
168 fprintf(tabout
, "\n");
169 fprintf(tabout
, ".nr %d \\n(.l-\\n(.i-\\n(%d\n", TMP
, TMP
);
170 if (boxflg
|| dboxflg
|| allflg
)
174 fprintf(tabout
, ".nr %d \\n(%d/%d\n", TMP
, TMP
, tsep
);
175 fprintf(tabout
, ".if \\n(%d<1n .nr %d 1n\n", TMP
, TMP
);
178 fprintf(tabout
, ".nr %d 1n\n", TMP
);
179 fprintf(tabout
, ".nr %d 0\n",CRIGHT
-1);
180 tsep
= (boxflg
|| allflg
|| dboxflg
|| left1flg
) ? 1 : 0;
181 for(icol
=0; icol
<ncol
; icol
++)
183 fprintf(tabout
, ".nr %d \\n(%d+(%d*\\n(%d)\n",icol
+CLEFT
, icol
+CRIGHT
-1, tsep
, TMP
);
184 fprintf(tabout
, ".nr %d +\\n(%d\n",icol
+CRIGHT
, icol
+CLEFT
);
187 /* the next line is last-ditch effort to avoid zero field width */
188 /*fprintf(tabout, ".if \\n(%d=0 .nr %d 1\n",icol+CMID, icol+CMID);*/
189 fprintf(tabout
, ".nr %d +\\n(%d\n", icol
+CMID
, icol
+CLEFT
);
190 /* fprintf(tabout, ".if n .if \\n(%d%%24>0 .nr %d +12u\n",icol+CMID, icol+CMID); */
195 fprintf(tabout
, ".nr %d (\\n(%d+\\n(%d)/2\n",ncol
+CRIGHT
-1, ncol
+CLEFT
-1, ncol
+CRIGHT
-2);
196 fprintf(tabout
, ".nr TW \\n(%d\n", ncol
+CRIGHT
-1);
197 if (boxflg
|| allflg
|| dboxflg
)
198 fprintf(tabout
, ".nr TW +%d*\\n(%d\n", sep
[ncol
-1], TMP
);
200 ".if t .if \\n(TW>\\n(.li .tm Table at line %d file %s is too wide - \\n(TW units\n", iline
-1, ifile
);
205 wide(char *s
, char *fn
, char *size
)
209 fprintf(tabout
, "\\w%c", F1
);
210 if (*fn
>0) putfont(fn
);
211 if (*size
) putsize(size
);
212 fprintf(tabout
, "%s", s
);
213 if (*fn
>0) putfont("P");
214 if (*size
) putsize("0");
215 fprintf(tabout
, "%c",F1
);
218 fprintf(tabout
, "\\n(%c-", s
);
224 return (point(s
) && s
[0]=='\\' && s
[1] == 'R');