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