1 /* $MirOS: src/usr.bin/oldroff/tbl/tt.c,v 1.3 2008/11/08 23:04:54 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 /* tt.c: subroutines for drawing horizontal lines */
46 
47 # include "t..c"
48 __SCCSID("@(#)tt.c	4.3 (Berkeley) 4/18/91");
49 __RCSID("$MirOS: src/usr.bin/oldroff/tbl/tt.c,v 1.3 2008/11/08 23:04:54 tg Exp $");
50 
ctype(il,ic)51 ctype(il, ic)
52 {
53 if (instead[il])
54 	return(0);
55 if (fullbot[il])
56 	return(0);
57 il = stynum[il];
58 return(style[il][ic]);
59 }
min(a,b)60 min(a,b)
61 {
62 return(a<b ? a : b);
63 }
fspan(i,c)64 fspan(i,c)
65 {
66 c++;
67 return(c<ncol && ctype(i,c)=='s');
68 }
lspan(i,c)69 lspan(i,c)
70 {
71 int k;
72 if (ctype(i,c) != 's') return(0);
73 c++;
74 if (c < ncol && ctype(i,c)== 's')
75 	return(0);
76 for(k=0; ctype(i,--c) == 's'; k++);
77 return(k);
78 }
ctspan(i,c)79 ctspan(i,c)
80 {
81 int k;
82 c++;
83 for(k=1; c<ncol && ctype(i,c)=='s'; k++)
84 	c++;
85 return(k);
86 }
tohcol(ic)87 tohcol(ic)
88 {
89 			if (ic==0)
90 				fprintf(tabout, "\\h'|0'");
91 			else
92 				fprintf(tabout, "\\h'(|\\n(%du+|\\n(%du)/2u'", ic+CLEFT, ic+CRIGHT-1);
93 }
allh(i)94 allh(i)
95 {
96 /* return true if every element in line i is horizontal */
97 /* also at least one must be horizontl */
98 int c, one, k;
99 if (fullbot[i]) return(1);
100 for(one=c=0; c<ncol; c++)
101 	{
102 	k = thish(i,c);
103 	if (k==0) return(0);
104 	if (k==1) continue;
105 	one=1;
106 	}
107 return(one);
108 }
thish(i,c)109 thish(i,c)
110 {
111 	int t;
112 	char *s;
113 	struct colstr *pc;
114 	if (c<0)return(0);
115 	if (i<0) return(0);
116 	t = ctype(i,c);
117 	if (t=='_' || t == '-')
118 		return('-');
119 	if (t=='=')return('=');
120 	if (t=='^') return(1);
121 	if (fullbot[i] )
122 		return(fullbot[i]);
123 	if (t=='s') return(thish(i,c-1));
124 	if (t==0) return(1);
125 	pc = &table[i][c];
126 	s = (t=='a' ? pc->rcol : pc->col);
127 	if (s==0 || (point(s) && *s==0))
128 		return(1);
129 	if (vspen(s)) return(1);
130 	if (t=barent( s))
131 		return(t);
132 	return(0);
133 }
134