xref: /titanic_41/usr/src/cmd/tbl/tt.c (revision 70025d765b044c6d8594bb965a2247a61e991a99)
1 /*
2  * Copyright 1990 Sun Microsystems, Inc.  All rights reserved.
3  * Use is subject to license terms.
4  */
5 
6 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
7 /*	  All Rights Reserved  	*/
8 
9 /*
10  * Copyright (c) 1980 Regents of the University of California.
11  * All rights reserved. The Berkeley software License Agreement
12  * specifies the terms and conditions for redistribution.
13  */
14 
15 #pragma ident	"%Z%%M%	%I%	%E% SMI"
16 
17  /* tt.c: subroutines for drawing horizontal lines */
18 # include "t..c"
19 
20 int
21 ctype(int il, int ic)
22 {
23 if (instead[il])
24 	return(0);
25 if (fullbot[il])
26 	return(0);
27 il = stynum[il];
28 return(style[il][ic]);
29 }
30 
31 int
32 min(int a, int b)
33 {
34 return(a<b ? a : b);
35 }
36 
37 int
38 fspan(int i, int c)
39 {
40 c++;
41 return(c<ncol && ctype(i,c)=='s');
42 }
43 
44 int
45 lspan(int i, int c)
46 {
47 int k;
48 if (ctype(i,c) != 's') return(0);
49 c++;
50 if (c < ncol && ctype(i,c)== 's')
51 	return(0);
52 for(k=0; ctype(i,--c) == 's'; k++);
53 return(k);
54 }
55 
56 int
57 ctspan(int i, int c)
58 {
59 int k;
60 c++;
61 for(k=1; c<ncol && ctype(i,c)=='s'; k++)
62 	c++;
63 return(k);
64 }
65 
66 void
67 tohcol(int ic)
68 {
69 			if (ic==0)
70 				fprintf(tabout, "\\h'|0'");
71 			else
72 				fprintf(tabout, "\\h'(|\\n(%du+|\\n(%du)/2u'", ic+CLEFT, ic+CRIGHT-1);
73 }
74 
75 int
76 allh(int i)
77 {
78 /* return true if every element in line i is horizontal */
79 /* also at least one must be horizontl */
80 int c, one, k;
81 if (fullbot[i]) return(1);
82 for(one=c=0; c<ncol; c++)
83 	{
84 	k = thish(i,c);
85 	if (k==0) return(0);
86 	if (k==1) continue;
87 	one=1;
88 	}
89 return(one);
90 }
91 
92 int
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(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