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