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