t7.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
1/*
2 * Copyright (c) 1983-1998 by Sun Microsystems, Inc.
3 * All Rights Reserved.
4 */
5
6#ident	"%Z%%M%	%I%	%E% SMI"
7
8/*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
9/*	  All Rights Reserved  	*/
10
11
12/*
13 * Copyright (c) 1980 Regents of the University of California.
14 * All rights reserved. The Berkeley software License Agreement
15 * specifies the terms and conditions for redistribution.
16 */
17
18 /* t7.c: control to write table entries */
19# include "t..c"
20# define realsplit ((ct=='a'||ct=='n') && table[ldata][c].rcol)
21runout()
22{
23int i;
24if (boxflg || allflg || dboxflg) need();
25if (ctrflg)
26	{
27	fprintf(tabout, ".nr #I \\n(.i\n");
28	fprintf(tabout, ".in +(\\n(.lu-\\n(TWu-\\n(.iu)/2u\n");
29	}
30fprintf(tabout, ".fc %c %c\n", F1, F2);
31fprintf(tabout, ".nr #T 0-1\n");
32deftail();
33for(i=0; i<nlin; i++)
34	putline(i,i);
35if (leftover)
36	yetmore();
37fprintf(tabout, ".fc\n");
38fprintf(tabout, ".nr T. 1\n");
39fprintf(tabout, ".T# 1\n");
40if (ctrflg)
41	fprintf(tabout, ".in \\n(#Iu\n");
42}
43runtabs(lform, ldata)
44{
45int c, ct, vforml, lf;
46fprintf(tabout, ".ta ");
47for(c=0; c<ncol; c++)
48	{
49	vforml=lform;
50	for(lf=prev(lform); lf>=0 && vspen(table[lf][c].col); lf=prev(lf))
51		vforml=lf;
52	if (fspan(vforml,c))
53		continue;
54	switch(ct=ctype(vforml,c))
55		{
56		case 'n':
57		case 'a':
58			if (table[ldata][c].rcol)
59			  if (lused[c]) /*Zero field width*/
60				fprintf(tabout, "\\n(%du ",c+CMID);
61		case 'c':
62		case 'l':
63		case 'r':
64		    if (realsplit? rused[c]: (used[c]+lused[c]))
65			fprintf(tabout, "\\n(%du ",c+CRIGHT);
66			continue;
67		case 's':
68			if (lspan(lform, c))
69				fprintf(tabout, "\\n(%du ", c+CRIGHT);
70			continue;
71		}
72	}
73fprintf(tabout, "\n");
74}
75ifline(s)
76	char *s;
77{
78if (!point(s)) return(0);
79if (s[0] == '\\') s++;
80if (s[1] ) return(0);
81if (s[0] == '_') return('-');
82if (s[0] == '=') return('=');
83return(0);
84}
85
86need()
87{
88	int texlin, horlin, i;
89
90	for(texlin = horlin = i = 0; i < nlin; i++) {
91		if (allh(i))
92			horlin++;
93		else if (instead[i] != 0)
94			continue;
95		else
96			texlin++;
97	}
98	(void) fprintf(tabout, ".ne %dv+%dp\n", texlin, 2 * horlin);
99	/*
100	 * For nroff runs, we need to reserve space for the full height of the
101	 * horizontal rules.  If we don't reserve sufficient height, we'll have
102	 * problems trying to draw the vertical lines across the page boundary.
103	 */
104	(void) fprintf(tabout, ".if n .ne %dv\n", 2 * texlin + 2 * horlin + 2);
105}
106
107deftail()
108{
109int i, c, lf, lwid;
110for(i=0; i<MAXHEAD; i++)
111	if (linestop[i])
112		fprintf(tabout, ".nr #%c 0-1\n", linestop[i]+'a'-1);
113fprintf(tabout, ".nr #a 0-1\n");
114fprintf(tabout, ".eo\n");
115fprintf(tabout, ".de T#\n");
116fprintf(tabout, ".ds #d .d\n");
117fprintf(tabout, ".if \\(ts\\n(.z\\(ts\\(ts .ds #d nl\n");
118	fprintf(tabout, ".mk ##\n");
119	fprintf(tabout, ".nr ## -1v\n");
120	fprintf(tabout, ".ls 1\n");
121	for(i=0; i<MAXHEAD; i++)
122		if (linestop[i])
123			fprintf(tabout, ".if \\n(#T>=0 .nr #%c \\n(#T\n",linestop[i]+'a'-1);
124if (boxflg || allflg || dboxflg) { /* bottom of table line */
125	if (!pr1403)
126		fprintf(tabout, ".if \\n(T. .vs \\n(.vu-\\n(.sp\n");
127	fprintf(tabout, ".if \\n(T. ");
128	drawline(nlin,0,ncol, dboxflg ? '=' : '-',1,0);
129	fprintf(tabout, "\n.if \\n(T. .vs\n");
130	/* T. is really an argument to a macro but because of
131		   eqn we don't dare pass it as an argument and reference by $1 */
132}
133	for(c=0; c<ncol; c++)
134		{
135		if ((lf=left(nlin-1,c, &lwid))>=0)
136			{
137			fprintf(tabout, ".if \\n(#%c>=0 .sp -1\n",linestop[lf]+'a'-1);
138			fprintf(tabout, ".if \\n(#%c>=0 ", linestop[lf]+'a'-1);
139			tohcol(c);
140			drawvert(lf, nlin-1, c, lwid);
141			fprintf(tabout, "\\h'|\\n(TWu'\n");
142			}
143		}
144	if (boxflg || allflg || dboxflg) /* right hand line */
145		{
146		fprintf(tabout, ".if \\n(#a>=0 .sp -1\n");
147		fprintf(tabout, ".if \\n(#a>=0 \\h'|\\n(TWu'");
148		drawvert (0, nlin-1, ncol, dboxflg? 2 : 1);
149		fprintf(tabout, "\n");
150		}
151fprintf(tabout, ".ls\n");
152fprintf(tabout, "..\n");
153fprintf(tabout, ".ec\n");
154}
155