xref: /original-bsd/old/tbl/t8.c (revision a425a1c9)
1 /*-
2  * %sccs.include.proprietary.c%
3  */
4 
5 #ifndef lint
6 static char sccsid[] = "@(#)t8.c	4.5 (Berkeley) 04/18/91";
7 #endif /* not lint */
8 
9  /* t8.c: write out one line of output table */
10 # include "t..c"
11 # define realsplit ((ct=='a'||ct=='n') && table[nl][c].rcol)
12 int watchout;
13 int once;
14 int topat[MAXCOL];
15 putline(i, nl)
16 	/* i is line number for deciding format */
17 	/* nl is line number for finding data   usually identical */
18 {
19 int c, lf, ct, form, lwid, vspf, ip = -1, cmidx, exvspen, vforml;
20 int vct, chfont;
21 char *s, *size, *fn;
22 watchout=vspf=exvspen=0;
23 if (i==0) once=0;
24 if (i==0 && ( allflg || boxflg || dboxflg))
25 	fullwide(0,   dboxflg? '=' : '-');
26 if (instead[nl]==0 && fullbot[nl] ==0)
27 for(c=0; c<ncol; c++)
28 	{
29 	s = table[nl][c].col;
30 	if (s==0) continue;
31 	if (vspen(s))
32 		{
33 		for(ip=nl; ip<nlin; ip=next(ip))
34 			if (!vspen(s=table[ip][c].col)) break;
35 		if (tx(s))
36 		fprintf(tabout, ".ne \\n(%c|u+\\n(.Vu\n",s);
37 		continue;
38 		}
39 	if (point(s)) continue;
40 	fprintf(tabout, ".ne \\n(%c|u+\\n(.Vu\n",s);
41 	watchout=1;
42 	}
43 if (linestop[nl])
44 	fprintf(tabout, ".mk #%c\n", linestop[nl]+'a'-1);
45 lf = prev(nl);
46 if (instead[nl])
47 	{
48 	puts(instead[nl]);
49 	return;
50 	}
51 if (fullbot[nl])
52 	{
53 	switch (ct=fullbot[nl])
54 		{
55 		case '=':
56 		case '-':
57 			fullwide(nl,ct);
58 		}
59 	return;
60 	}
61 for(c=0; c<ncol; c++)
62 	{
63 	if (instead[nl]==0 && fullbot[nl]==0)
64 	if (vspen(table[nl][c].col)) vspf=1;
65 	if (lf>=0)
66 		if (vspen(table[lf][c].col)) vspf=1;
67 	}
68 if (vspf)
69 	{
70 	fprintf(tabout, ".nr #^ \\n(\\*(#du\n");
71 	fprintf(tabout, ".nr #- \\n(#^\n"); /* current line position relative to bottom */
72 	}
73 vspf=0;
74 chfont=0;
75 for(c=0; c<ncol; c++)
76 	{
77 	s = table[nl][c].col;
78 	if (s==0) continue;
79 	chfont |= (int)(font[stynum[nl]][c]);
80 	if (point(s) ) continue;
81 	lf=prev(nl);
82 	if (lf>=0 && vspen(table[lf][c].col))
83 		fprintf(tabout, ".if (\\n(%c|+\\n(^%c-1v)>\\n(#- .nr #- +(\\n(%c|+\\n(^%c-\\n(#--1v)\n",s,'a'+c,s,'a'+c);
84 	else
85 		fprintf(tabout, ".if (\\n(%c|+\\n(#^-1v)>\\n(#- .nr #- +(\\n(%c|+\\n(#^-\\n(#--1v)\n",s,s);
86 	}
87 if (allflg && once>0 )
88 	fullwide(i,'-');
89 once=1;
90 runtabs(i, nl);
91 if (allh(i) && !pr1403)
92 	{
93 	fprintf(tabout, ".nr %d \\n(.v\n", SVS);
94 	fprintf(tabout, ".vs \\n(.vu-\\n(.sp\n");
95 	}
96 if (chfont)
97 	fprintf(tabout, ".nr %2d \\n(.f\n", S1);
98 fprintf(tabout, ".nr 35 1m\n");
99 fprintf(tabout, "\\&");
100 vct = 0;
101 for(c=0; c<ncol; c++)
102 	{
103 	if (watchout==0 && i+1<nlin && (lf=left(i,c, &lwid))>=0)
104 		{
105 		tohcol(c);
106 		drawvert(lf, i, c, lwid);
107 		vct += 2;
108 		}
109 	if (rightl && c+1==ncol) continue;
110 	vforml=i;
111 	for(lf=prev(nl); lf>=0 && vspen(table[lf][c].col); lf=prev(lf))
112 		vforml= lf;
113 	form= ctype(vforml,c);
114 	if (form != 's')
115 		{
116 		ct = c+CLEFT;
117 		if (form=='a') ct = c+CMID;
118 		if (form=='n' && table[nl][c].rcol && lused[c]==0) ct= c+CMID;
119 		fprintf(tabout, "\\h'|\\n(%du'", ct);
120 		}
121 	s= table[nl][c].col;
122 	fn = font[stynum[vforml]][c];
123 	size = csize[stynum[vforml]][c];
124 	if (*size==0)size=0;
125 	switch(ct=ctype(vforml, c))
126 		{
127 		case 'n':
128 		case 'a':
129 			if (table[nl][c].rcol)
130 				{
131 			   if (lused[c]) /*Zero field width*/
132 				{
133 				ip = prev(nl);
134 				if (ip>=0)
135 				if (vspen(table[ip][c].col))
136 					{
137 					if (exvspen==0)
138 						{
139 						fprintf(tabout, "\\v'-(\\n(\\*(#du-\\n(^%cu", c+'a');
140 						if (cmidx)
141 							fprintf(tabout, "-((\\n(#-u-\\n(^%cu)/2u)", c+'a');
142 						vct++;
143 						fprintf(tabout, "'");
144 						exvspen=1;
145 						}
146 					}
147 				fprintf(tabout, "%c%c",F1,F2);
148 				puttext(s,fn,size);
149 				fprintf(tabout, "%c",F1);
150 				}
151 				s= table[nl][c].rcol;
152 				form=1;
153 				break;
154 				}
155 		case 'c':
156 			form=3; break;
157 		case 'r':
158 			form=2; break;
159 		case 'l':
160 			form=1; break;
161 		case '-':
162 		case '=':
163 			if (real(table[nl][c].col))
164 				fprintf(stderr,"%s: line %d: Data ignored on table line %d\n", ifile, iline-1, i+1);
165 			makeline(i,c,ct);
166 			continue;
167 		default:
168 			continue;
169 		}
170 	if (realsplit ? rused[c]: used[c]) /*Zero field width*/
171 		{
172 		/* form: 1 left, 2 right, 3 center adjust */
173 		if (ifline(s))
174 			{
175 			makeline(i,c,ifline(s));
176 			continue;
177 			}
178 		if (filler(s))
179 			{
180 			printf("\\l'|\\n(%du\\&%s'", c+CRIGHT, s+2);
181 			continue;
182 			}
183 		ip = prev(nl);
184 		cmidx = ctop[stynum[nl]][c]==0;
185 		if (ip>=0)
186 		if (vspen(table[ip][c].col))
187 			{
188 			if (exvspen==0)
189 				{
190 				fprintf(tabout, "\\v'-(\\n(\\*(#du-\\n(^%cu", c+'a');
191 				if (cmidx)
192 					fprintf(tabout, "-((\\n(#-u-\\n(^%cu)/2u)", c+'a');
193 				vct++;
194 				fprintf(tabout, "'");
195 				}
196 			}
197 		fprintf(tabout, "%c", F1);
198 		if (form!= 1)
199 			fprintf(tabout, "%c", F2);
200 		if (vspen(s))
201 			vspf=1;
202 		else
203 		puttext(s, fn, size);
204 		if (form !=2)
205 			fprintf(tabout, "%c", F2);
206 		fprintf(tabout, "%c", F1);
207 		}
208 	if (ip>=0)
209 	if (vspen(table[ip][c].col))
210 		{
211 		exvspen = (c+1 < ncol) && vspen(table[ip][c+1].col) &&
212 			(topat[c] == topat[c+1]) &&
213 			(cmidx == (ctop [stynum[nl]][c+1]==0)) && (left(i,c+1,&lwid)<0);
214 		if (exvspen==0)
215 			{
216 			fprintf(tabout, "\\v'(\\n(\\*(#du-\\n(^%cu", c+'a');
217 			if (cmidx)
218 				fprintf(tabout, "-((\\n(#-u-\\n(^%cu)/2u)", c+'a');
219 			vct++;
220 			fprintf(tabout, "'");
221 			}
222 		}
223 	else
224 		exvspen=0;
225 	/* if lines need to be split for gcos here is the place for a backslash */
226 	if (vct > 7 && c < ncol)
227 		{
228 		fprintf(tabout, "\n.sp-1\n\\&");
229 		vct=0;
230 		}
231 	}
232 fprintf(tabout, "\n");
233 if (allh(i) && !pr1403) fprintf(tabout, ".vs \\n(%du\n", SVS);
234 if (watchout)
235 	funnies(i,nl);
236 if (vspf)
237 	{
238 	for(c=0; c<ncol; c++)
239 		if (vspen(table[nl][c].col) && (nl==0 || (lf=prev(nl))<0 || !vspen(table[lf][c].col)))
240 			{
241 			fprintf(tabout, ".nr ^%c \\n(#^u\n", 'a'+c);
242 			topat[c]=nl;
243 			}
244 	}
245 }
246 puttext(s,fn, size)
247 	char *s, *size, *fn;
248 {
249 if (point(s))
250 	{
251 	putfont(fn);
252 	putsize(size);
253 	fprintf(tabout, "%s",s);
254 	if (*fn>0) fprintf(tabout, "\\f\\n(%2d", S1);
255 	if (size!=0) putsize("0");
256 	}
257 }
258 funnies( stl, lin)
259 {
260 /* write out funny diverted things */
261 int c, s, pl, lwid, dv, lf, ct;
262 char *fn;
263 fprintf(tabout, ".mk ##\n"); /* rmember current vertical position */
264 fprintf(tabout, ".nr %d \\n(##\n", S1); /* bottom position */
265 for(c=0; c<ncol; c++)
266 	{
267 	s = table[lin][c].col;
268 	if (point(s)) continue;
269 	if (s==0) continue;
270 	fprintf(tabout, ".sp |\\n(##u-1v\n");
271 	fprintf(tabout, ".nr %d ", SIND);
272 	for(pl=stl; pl>=0 && !isalpha(ct=ctype(pl,c)); pl=prev(pl))
273 		;
274 	switch (ct)
275 		{
276 		case 'n':
277 		case 'c':
278 			fprintf(tabout, "(\\n(%du+\\n(%du-\\n(%c-u)/2u\n",c+CLEFT,c-1+ctspan(lin,c)+CRIGHT, s);
279 			break;
280 		case 'l':
281 			fprintf(tabout, "\\n(%du\n",c+CLEFT);
282 			break;
283 		case 'a':
284 			fprintf(tabout, "\\n(%du\n",c+CMID);
285 			break;
286 		case 'r':
287 			fprintf(tabout, "\\n(%du-\\n(%c-u\n", c+CRIGHT, s);
288 			break;
289 		}
290 	fprintf(tabout, ".in +\\n(%du\n", SIND);
291 	fn=font[stynum[stl]][c];
292 	putfont(fn);
293 	pl = prev(stl);
294 	if (stl>0 && pl>=0 && vspen(table[pl][c].col))
295 		{
296 		fprintf(tabout, ".sp |\\n(^%cu\n", 'a'+c);
297 		if (ctop[stynum[stl]][c]==0)
298 			{
299 			fprintf(tabout, ".nr %d \\n(#-u-\\n(^%c-\\n(%c|+1v\n",TMP, 'a'+c, s);
300 			fprintf(tabout, ".if \\n(%d>0 .sp \\n(%du/2u\n", TMP, TMP);
301 			}
302 		}
303 	fprintf(tabout, ".%c+\n",s);
304 	fprintf(tabout, ".in -\\n(%du\n", SIND);
305 	if (*fn>0) putfont("P");
306 	fprintf(tabout, ".mk %d\n", S2);
307 	fprintf(tabout, ".if \\n(%d>\\n(%d .nr %d \\n(%d\n", S2, S1, S1, S2);
308 	}
309 fprintf(tabout, ".sp |\\n(%du\n", S1);
310 for(c=dv=0; c<ncol; c++)
311 	{
312 	if (stl+1< nlin && (lf=left(stl,c,&lwid))>=0)
313 		{
314 		if (dv++ == 0)
315 			fprintf(tabout, ".sp -1\n");
316 		tohcol(c);
317 		dv++;
318 		drawvert(lf, stl, c, lwid);
319 		}
320 	}
321 if (dv)
322 	fprintf(tabout,"\n");
323 }
324 putfont(fn)
325 	char *fn;
326 {
327 if (fn && *fn)
328 	fprintf(tabout,  fn[1] ? "\\f(%.2s" : "\\f%.2s",  fn);
329 }
330 putsize(s)
331 	char *s;
332 {
333 if (s && *s)
334 	fprintf(tabout, "\\s%s",s);
335 }
336