1 /* $MirOS: src/usr.bin/oldroff/tbl/t7.c,v 1.3 2008/11/08 23:04:53 tg Exp $ */
2 
3 /*-
4  * Copyright (c) 1979, 1980, 1981, 1986, 1988, 1990, 1991, 1992
5  *     The Regents of the University of California.
6  * Copyright (C) Caldera International Inc.  2001-2002.
7  * Copyright (c) 2003, 2004
8  *	Thorsten "mirabilos" Glaser <tg@mirbsd.org>
9  * All rights reserved.
10  *
11  * Redistribution and use in source and binary forms,
12  * with or without modification, are permitted provided
13  * that the following conditions are met:
14  *
15  * Redistributions of source code and documentation must retain
16  * the above copyright notice, this list of conditions and the
17  * following disclaimer.  Redistributions in binary form must
18  * reproduce the above copyright notice, this list of conditions
19  * and the following disclaimer in the documentation and/or other
20  * materials provided with the distribution.
21  *
22  * All advertising materials mentioning features or use of this
23  * software must display the following acknowledgement:
24  *   This product includes software developed or owned by
25  *   Caldera International, Inc.
26  *
27  * Neither the name of Caldera International, Inc. nor the names
28  * of other contributors may be used to endorse or promote products
29  * derived from this software without specific prior written permission.
30  *
31  * USE OF THE SOFTWARE PROVIDED FOR UNDER THIS LICENSE BY CALDERA
32  * INTERNATIONAL, INC. AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
33  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
34  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
35  * ARE DISCLAIMED.  IN NO EVENT SHALL CALDERA INTERNATIONAL, INC. BE
36  * LIABLE FOR ANY DIRECT, INDIRECT INCIDENTAL, SPECIAL, EXEMPLARY, OR
37  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
38  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
39  * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
40  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
41  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
42  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
43  */
44 
45 /* t7.c: control to write table entries */
46 
47 # include "t..c"
48 __SCCSID("@(#)t7.c	4.5 (Berkeley) 4/18/91");
49 __RCSID("$MirOS: src/usr.bin/oldroff/tbl/t7.c,v 1.3 2008/11/08 23:04:53 tg Exp $");
50 
51 # define realsplit ((ct=='a'||ct=='n') && table[ldata][c].rcol)
runout()52 runout()
53 {
54 int i;
55 if (boxflg || allflg || dboxflg) need();
56 if (ctrflg)
57 	{
58 	fprintf(tabout, ".nr #I \\n(.i\n");
59 	fprintf(tabout, ".in +(\\n(.lu-\\n(TWu-\\n(.iu)/2u\n");
60 	}
61 fprintf(tabout, ".fc %c %c\n", F1, F2);
62 fprintf(tabout, ".nr #T 0-1\n");
63 deftail();
64 for(i=0; i<nlin; i++)
65 	putline(i,i);
66 if (leftover)
67 	yetmore();
68 fprintf(tabout, ".fc\n");
69 fprintf(tabout, ".nr T. 1\n");
70 fprintf(tabout, ".T# 1\n");
71 if (ctrflg)
72 	fprintf(tabout, ".in \\n(#Iu\n");
73 }
runtabs(lform,ldata)74 runtabs(lform, ldata)
75 {
76 int c, ct, vforml, lf;
77 fprintf(tabout, ".ta ");
78 for(c=0; c<ncol; c++)
79 	{
80 	vforml=lform;
81 	for(lf=prev(lform); lf>=0 && vspen(table[lf][c].col); lf=prev(lf))
82 		vforml=lf;
83 	if (fspan(vforml,c))
84 		continue;
85 	switch(ct=ctype(vforml,c))
86 		{
87 		case 'n':
88 		case 'a':
89 			if (table[ldata][c].rcol)
90 			  if (lused[c]) /*Zero field width*/
91 				fprintf(tabout, "\\n(%du ",c+CMID);
92 		case 'c':
93 		case 'l':
94 		case 'r':
95 		    if (realsplit? rused[c]: (used[c]+lused[c]))
96 			fprintf(tabout, "\\n(%du ",c+CRIGHT);
97 			continue;
98 		case 's':
99 			if (lspan(lform, c))
100 				fprintf(tabout, "\\n(%du ", c+CRIGHT);
101 			continue;
102 		}
103 	}
104 fprintf(tabout, "\n");
105 }
ifline(s)106 ifline(s)
107 	char *s;
108 {
109 if (!point(s)) return(0);
110 if (s[0] == '\\') s++;
111 if (s[1] ) return(0);
112 if (s[0] == '_') return('-');
113 if (s[0] == '=') return('=');
114 return(0);
115 }
need()116 need()
117 {
118 int texlin, horlin, i;
119 for(texlin=horlin=i=0; i<nlin; i++)
120 	{
121 	if (fullbot[i]!=0)
122 		horlin++;
123 	else
124 	if (instead[i]!=0)
125 		continue;
126 	else
127 	if (allh(i))
128 		horlin++;
129 	else
130 		texlin++;
131 	}
132 fprintf(tabout, ".ne %dv+%dp\n",texlin,2*horlin);
133 }
deftail()134 deftail()
135 {
136 int i, c, lf, lwid;
137 for(i=0; i<MAXHEAD; i++)
138 	if (linestop[i])
139 		fprintf(tabout, ".nr #%c 0-1\n", linestop[i]+'a'-1);
140 fprintf(tabout, ".nr #a 0-1\n");
141 fprintf(tabout, ".eo\n");
142 fprintf(tabout, ".de T#\n");
143 fprintf(tabout, ".ds #d .d\n");
144 fprintf(tabout, ".if \\(ts\\n(.z\\(ts\\(ts .ds #d nl\n");
145 	fprintf(tabout, ".mk ##\n");
146 	fprintf(tabout, ".nr ## -1v\n");
147 	fprintf(tabout, ".ls 1\n");
148 	for(i=0; i<MAXHEAD; i++)
149 		if (linestop[i])
150 			fprintf(tabout, ".if \\n(#T>=0 .nr #%c \\n(#T\n",linestop[i]+'a'-1);
151 if (boxflg || allflg || dboxflg) /* bottom of table line */
152 	if (fullbot[nlin-1]==0)
153 		{
154 		if (!pr1403)
155 			fprintf(tabout, ".if \\n(T. .vs \\n(.vu-\\n(.sp\n");
156 		fprintf(tabout, ".if \\n(T. ");
157 		drawline(nlin,0,ncol, dboxflg ? '=' : '-',1,0);
158 		fprintf(tabout, "\n.if \\n(T. .vs\n");
159 		/* T. is really an argument to a macro but because of
160 		   eqn we don't dare pass it as an argument and reference by $1 */
161 		}
162 	for(c=0; c<ncol; c++)
163 		{
164 		if ((lf=left(nlin-1,c, &lwid))>=0)
165 			{
166 			fprintf(tabout, ".if \\n(#%c>=0 .sp -1\n",linestop[lf]+'a'-1);
167 			fprintf(tabout, ".if \\n(#%c>=0 ", linestop[lf]+'a'-1);
168 			tohcol(c);
169 			drawvert(lf, nlin-1, c, lwid);
170 			fprintf(tabout, "\\h'|\\n(TWu'\n");
171 			}
172 		}
173 	if (boxflg || allflg || dboxflg) /* right hand line */
174 		{
175 		fprintf(tabout, ".if \\n(#a>=0 .sp -1\n");
176 		fprintf(tabout, ".if \\n(#a>=0 \\h'|\\n(TWu'");
177 		drawvert (0, nlin-1, ncol, dboxflg? 2 : 1);
178 		fprintf(tabout, "\n");
179 		}
180 fprintf(tabout, ".ls\n");
181 fprintf(tabout, "..\n");
182 fprintf(tabout, ".ec\n");
183 }
184