xref: /onnv-gate/usr/src/cmd/tbl/tt.c (revision 381:1a7f0e46092a)
1*381Smuffin /*
2*381Smuffin  * Copyright 1990 Sun Microsystems, Inc.  All rights reserved.
3*381Smuffin  * Use is subject to license terms.
4*381Smuffin  */
5*381Smuffin 
60Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
70Sstevel@tonic-gate /*	  All Rights Reserved  	*/
80Sstevel@tonic-gate 
90Sstevel@tonic-gate /*
100Sstevel@tonic-gate  * Copyright (c) 1980 Regents of the University of California.
110Sstevel@tonic-gate  * All rights reserved. The Berkeley software License Agreement
120Sstevel@tonic-gate  * specifies the terms and conditions for redistribution.
130Sstevel@tonic-gate  */
140Sstevel@tonic-gate 
15*381Smuffin #pragma ident	"%Z%%M%	%I%	%E% SMI"
160Sstevel@tonic-gate 
170Sstevel@tonic-gate  /* tt.c: subroutines for drawing horizontal lines */
180Sstevel@tonic-gate # include "t..c"
19*381Smuffin 
20*381Smuffin int
ctype(int il,int ic)21*381Smuffin ctype(int il, int ic)
220Sstevel@tonic-gate {
230Sstevel@tonic-gate if (instead[il])
240Sstevel@tonic-gate 	return(0);
250Sstevel@tonic-gate if (fullbot[il])
260Sstevel@tonic-gate 	return(0);
270Sstevel@tonic-gate il = stynum[il];
280Sstevel@tonic-gate return(style[il][ic]);
290Sstevel@tonic-gate }
30*381Smuffin 
31*381Smuffin int
min(int a,int b)32*381Smuffin min(int a, int b)
330Sstevel@tonic-gate {
340Sstevel@tonic-gate return(a<b ? a : b);
350Sstevel@tonic-gate }
36*381Smuffin 
37*381Smuffin int
fspan(int i,int c)38*381Smuffin fspan(int i, int c)
390Sstevel@tonic-gate {
400Sstevel@tonic-gate c++;
410Sstevel@tonic-gate return(c<ncol && ctype(i,c)=='s');
420Sstevel@tonic-gate }
43*381Smuffin 
44*381Smuffin int
lspan(int i,int c)45*381Smuffin lspan(int i, int c)
460Sstevel@tonic-gate {
470Sstevel@tonic-gate int k;
480Sstevel@tonic-gate if (ctype(i,c) != 's') return(0);
490Sstevel@tonic-gate c++;
500Sstevel@tonic-gate if (c < ncol && ctype(i,c)== 's')
510Sstevel@tonic-gate 	return(0);
520Sstevel@tonic-gate for(k=0; ctype(i,--c) == 's'; k++);
530Sstevel@tonic-gate return(k);
540Sstevel@tonic-gate }
55*381Smuffin 
56*381Smuffin int
ctspan(int i,int c)57*381Smuffin ctspan(int i, int c)
580Sstevel@tonic-gate {
590Sstevel@tonic-gate int k;
600Sstevel@tonic-gate c++;
610Sstevel@tonic-gate for(k=1; c<ncol && ctype(i,c)=='s'; k++)
620Sstevel@tonic-gate 	c++;
630Sstevel@tonic-gate return(k);
640Sstevel@tonic-gate }
65*381Smuffin 
66*381Smuffin void
tohcol(int ic)67*381Smuffin tohcol(int ic)
680Sstevel@tonic-gate {
690Sstevel@tonic-gate 			if (ic==0)
700Sstevel@tonic-gate 				fprintf(tabout, "\\h'|0'");
710Sstevel@tonic-gate 			else
720Sstevel@tonic-gate 				fprintf(tabout, "\\h'(|\\n(%du+|\\n(%du)/2u'", ic+CLEFT, ic+CRIGHT-1);
730Sstevel@tonic-gate }
74*381Smuffin 
75*381Smuffin int
allh(int i)76*381Smuffin allh(int i)
770Sstevel@tonic-gate {
780Sstevel@tonic-gate /* return true if every element in line i is horizontal */
790Sstevel@tonic-gate /* also at least one must be horizontl */
800Sstevel@tonic-gate int c, one, k;
810Sstevel@tonic-gate if (fullbot[i]) return(1);
820Sstevel@tonic-gate for(one=c=0; c<ncol; c++)
830Sstevel@tonic-gate 	{
840Sstevel@tonic-gate 	k = thish(i,c);
850Sstevel@tonic-gate 	if (k==0) return(0);
860Sstevel@tonic-gate 	if (k==1) continue;
870Sstevel@tonic-gate 	one=1;
880Sstevel@tonic-gate 	}
890Sstevel@tonic-gate return(one);
900Sstevel@tonic-gate }
91*381Smuffin 
92*381Smuffin int
thish(int i,int c)93*381Smuffin thish(int i, int c)
940Sstevel@tonic-gate {
950Sstevel@tonic-gate 	int t;
960Sstevel@tonic-gate 	char *s;
970Sstevel@tonic-gate 	struct colstr *pc;
980Sstevel@tonic-gate 	if (c<0)return(0);
990Sstevel@tonic-gate 	if (i<0) return(0);
1000Sstevel@tonic-gate 	t = ctype(i,c);
1010Sstevel@tonic-gate 	if (t=='_' || t == '-')
1020Sstevel@tonic-gate 		return('-');
1030Sstevel@tonic-gate 	if (t=='=')return('=');
1040Sstevel@tonic-gate 	if (t=='^') return(1);
1050Sstevel@tonic-gate 	if (fullbot[i] )
1060Sstevel@tonic-gate 		return(fullbot[i]);
1070Sstevel@tonic-gate 	if (t=='s') return(thish(i,c-1));
1080Sstevel@tonic-gate 	if (t==0) return(1);
1090Sstevel@tonic-gate 	pc = &table[i][c];
1100Sstevel@tonic-gate 	s = (t=='a' ? pc->rcol : pc->col);
1110Sstevel@tonic-gate 	if (s==0 || (point(s) && *s==0))
1120Sstevel@tonic-gate 		return(1);
1130Sstevel@tonic-gate 	if (vspen(s)) return(1);
1140Sstevel@tonic-gate 	if (t=barent( s))
1150Sstevel@tonic-gate 		return(t);
1160Sstevel@tonic-gate 	return(0);
1170Sstevel@tonic-gate }
118