xref: /titanic_41/usr/src/cmd/tbl/tt.c (revision b55148877d473978f0b46d593fd6213fa526fcc5)
1*b5514887Smuffin /*
2*b5514887Smuffin  * Copyright 1990 Sun Microsystems, Inc.  All rights reserved.
3*b5514887Smuffin  * Use is subject to license terms.
4*b5514887Smuffin  */
5*b5514887Smuffin 
67c478bd9Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
77c478bd9Sstevel@tonic-gate /*	  All Rights Reserved  	*/
87c478bd9Sstevel@tonic-gate 
97c478bd9Sstevel@tonic-gate /*
107c478bd9Sstevel@tonic-gate  * Copyright (c) 1980 Regents of the University of California.
117c478bd9Sstevel@tonic-gate  * All rights reserved. The Berkeley software License Agreement
127c478bd9Sstevel@tonic-gate  * specifies the terms and conditions for redistribution.
137c478bd9Sstevel@tonic-gate  */
147c478bd9Sstevel@tonic-gate 
15*b5514887Smuffin #pragma ident	"%Z%%M%	%I%	%E% SMI"
167c478bd9Sstevel@tonic-gate 
177c478bd9Sstevel@tonic-gate  /* tt.c: subroutines for drawing horizontal lines */
187c478bd9Sstevel@tonic-gate # include "t..c"
19*b5514887Smuffin 
20*b5514887Smuffin int
ctype(int il,int ic)21*b5514887Smuffin ctype(int il, int ic)
227c478bd9Sstevel@tonic-gate {
237c478bd9Sstevel@tonic-gate if (instead[il])
247c478bd9Sstevel@tonic-gate 	return(0);
257c478bd9Sstevel@tonic-gate if (fullbot[il])
267c478bd9Sstevel@tonic-gate 	return(0);
277c478bd9Sstevel@tonic-gate il = stynum[il];
287c478bd9Sstevel@tonic-gate return(style[il][ic]);
297c478bd9Sstevel@tonic-gate }
30*b5514887Smuffin 
31*b5514887Smuffin int
min(int a,int b)32*b5514887Smuffin min(int a, int b)
337c478bd9Sstevel@tonic-gate {
347c478bd9Sstevel@tonic-gate return(a<b ? a : b);
357c478bd9Sstevel@tonic-gate }
36*b5514887Smuffin 
37*b5514887Smuffin int
fspan(int i,int c)38*b5514887Smuffin fspan(int i, int c)
397c478bd9Sstevel@tonic-gate {
407c478bd9Sstevel@tonic-gate c++;
417c478bd9Sstevel@tonic-gate return(c<ncol && ctype(i,c)=='s');
427c478bd9Sstevel@tonic-gate }
43*b5514887Smuffin 
44*b5514887Smuffin int
lspan(int i,int c)45*b5514887Smuffin lspan(int i, int c)
467c478bd9Sstevel@tonic-gate {
477c478bd9Sstevel@tonic-gate int k;
487c478bd9Sstevel@tonic-gate if (ctype(i,c) != 's') return(0);
497c478bd9Sstevel@tonic-gate c++;
507c478bd9Sstevel@tonic-gate if (c < ncol && ctype(i,c)== 's')
517c478bd9Sstevel@tonic-gate 	return(0);
527c478bd9Sstevel@tonic-gate for(k=0; ctype(i,--c) == 's'; k++);
537c478bd9Sstevel@tonic-gate return(k);
547c478bd9Sstevel@tonic-gate }
55*b5514887Smuffin 
56*b5514887Smuffin int
ctspan(int i,int c)57*b5514887Smuffin ctspan(int i, int c)
587c478bd9Sstevel@tonic-gate {
597c478bd9Sstevel@tonic-gate int k;
607c478bd9Sstevel@tonic-gate c++;
617c478bd9Sstevel@tonic-gate for(k=1; c<ncol && ctype(i,c)=='s'; k++)
627c478bd9Sstevel@tonic-gate 	c++;
637c478bd9Sstevel@tonic-gate return(k);
647c478bd9Sstevel@tonic-gate }
65*b5514887Smuffin 
66*b5514887Smuffin void
tohcol(int ic)67*b5514887Smuffin tohcol(int ic)
687c478bd9Sstevel@tonic-gate {
697c478bd9Sstevel@tonic-gate 			if (ic==0)
707c478bd9Sstevel@tonic-gate 				fprintf(tabout, "\\h'|0'");
717c478bd9Sstevel@tonic-gate 			else
727c478bd9Sstevel@tonic-gate 				fprintf(tabout, "\\h'(|\\n(%du+|\\n(%du)/2u'", ic+CLEFT, ic+CRIGHT-1);
737c478bd9Sstevel@tonic-gate }
74*b5514887Smuffin 
75*b5514887Smuffin int
allh(int i)76*b5514887Smuffin allh(int i)
777c478bd9Sstevel@tonic-gate {
787c478bd9Sstevel@tonic-gate /* return true if every element in line i is horizontal */
797c478bd9Sstevel@tonic-gate /* also at least one must be horizontl */
807c478bd9Sstevel@tonic-gate int c, one, k;
817c478bd9Sstevel@tonic-gate if (fullbot[i]) return(1);
827c478bd9Sstevel@tonic-gate for(one=c=0; c<ncol; c++)
837c478bd9Sstevel@tonic-gate 	{
847c478bd9Sstevel@tonic-gate 	k = thish(i,c);
857c478bd9Sstevel@tonic-gate 	if (k==0) return(0);
867c478bd9Sstevel@tonic-gate 	if (k==1) continue;
877c478bd9Sstevel@tonic-gate 	one=1;
887c478bd9Sstevel@tonic-gate 	}
897c478bd9Sstevel@tonic-gate return(one);
907c478bd9Sstevel@tonic-gate }
91*b5514887Smuffin 
92*b5514887Smuffin int
thish(int i,int c)93*b5514887Smuffin thish(int i, int c)
947c478bd9Sstevel@tonic-gate {
957c478bd9Sstevel@tonic-gate 	int t;
967c478bd9Sstevel@tonic-gate 	char *s;
977c478bd9Sstevel@tonic-gate 	struct colstr *pc;
987c478bd9Sstevel@tonic-gate 	if (c<0)return(0);
997c478bd9Sstevel@tonic-gate 	if (i<0) return(0);
1007c478bd9Sstevel@tonic-gate 	t = ctype(i,c);
1017c478bd9Sstevel@tonic-gate 	if (t=='_' || t == '-')
1027c478bd9Sstevel@tonic-gate 		return('-');
1037c478bd9Sstevel@tonic-gate 	if (t=='=')return('=');
1047c478bd9Sstevel@tonic-gate 	if (t=='^') return(1);
1057c478bd9Sstevel@tonic-gate 	if (fullbot[i] )
1067c478bd9Sstevel@tonic-gate 		return(fullbot[i]);
1077c478bd9Sstevel@tonic-gate 	if (t=='s') return(thish(i,c-1));
1087c478bd9Sstevel@tonic-gate 	if (t==0) return(1);
1097c478bd9Sstevel@tonic-gate 	pc = &table[i][c];
1107c478bd9Sstevel@tonic-gate 	s = (t=='a' ? pc->rcol : pc->col);
1117c478bd9Sstevel@tonic-gate 	if (s==0 || (point(s) && *s==0))
1127c478bd9Sstevel@tonic-gate 		return(1);
1137c478bd9Sstevel@tonic-gate 	if (vspen(s)) return(1);
1147c478bd9Sstevel@tonic-gate 	if (t=barent( s))
1157c478bd9Sstevel@tonic-gate 		return(t);
1167c478bd9Sstevel@tonic-gate 	return(0);
1177c478bd9Sstevel@tonic-gate }
118