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 /*	from OpenSolaris "tt.c	1.3	05/06/02 SMI"	 SVr4.0 1.1		*/
17 
18 /*
19  * Portions Copyright (c) 2005 Gunnar Ritter, Freiburg i. Br., Germany
20  *
21  * Sccsid @(#)tt.c	1.3 (gritter) 7/23/05
22  */
23 
24  /* tt.c: subroutines for drawing horizontal lines */
25 # include "t..c"
26 # include <inttypes.h>
27 int
ctype(int il,int ic)28 ctype(int il, int ic)
29 {
30 	if (instead[il])
31 		return(0);
32 	if (fullbot[il])
33 		return(0);
34 	il = stynum[il];
35 	return(style[il][ic]);
36 }
37 int
min(int a,int b)38 min(int a, int b)
39 {
40 return(a<b ? a : b);
41 }
42 int
fspan(int i,int c)43 fspan(int i, int c)
44 {
45 c++;
46 return(c<ncol && ctype(i,c)=='s');
47 }
48 int
lspan(int i,int c)49 lspan(int i, int c)
50 {
51 int k;
52 if (ctype(i,c) != 's') return(0);
53 c++;
54 if (c < ncol && ctype(i,c)== 's')
55 	return(0);
56 for(k=0; ctype(i,--c) == 's'; k++);
57 return(k);
58 }
59 int
ctspan(int i,int c)60 ctspan(int i, int c)
61 {
62 int k;
63 c++;
64 for(k=1; c<ncol && ctype(i,c)=='s'; k++)
65 	c++;
66 return(k);
67 }
68 void
tohcol(int ic)69 tohcol(int ic)
70 {
71 	if (ic==0)
72 		fprintf(tabout, "\\h'|0'");
73 	else
74 		fprintf(tabout, "\\h'(|\\n(%du+|\\n(%du)/2u'", ic+CLEFT, ic+CRIGHT-1);
75 }
76 int
allh(int i)77 allh(int i)
78 {
79 	/* return true if every element in line i is horizontal */
80 	/* also at least one must be horizontl */
81 	int c, one, k;
82 	if (fullbot[i]) return(1);
83 	for(one=c=0; c<ncol; c++)
84 	{
85 		k = thish(i,c);
86 		if (k==0) return(0);
87 		if (k==1) continue;
88 		one=1;
89 	}
90 	return(one);
91 }
92 int
thish(int i,int c)93 thish(int i, int c)
94 {
95 	int t;
96 	char *s;
97 	struct colstr *pc;
98 	if (c<0)return(0);
99 	if (i<0) return(0);
100 	t = ctype(i,c);
101 	if (t=='_' || t == '-')
102 		return('-');
103 	if (t=='=')return('=');
104 	if (t=='^') return(1);
105 	if (fullbot[i] )
106 		return(fullbot[i]);
107 	if (t=='s') return(thish(i,c-1));
108 	if (t==0) return(1);
109 	pc = &table[i][c];
110 	s = (t=='a' ? pc->rcol : pc->col);
111 	if (s==0 || (point((intptr_t)s) && *s==0))
112 		return(1);
113 	if (vspen(s)) return(1);
114 	if ((t=barent( s)))
115 		return(t);
116 	return(0);
117 }
118