xref: /illumos-gate/usr/src/cmd/tbl/tt.c (revision 2a8bcb4e)
1b5514887Smuffin /*
2b5514887Smuffin  * Copyright 1990 Sun Microsystems, Inc.  All rights reserved.
3b5514887Smuffin  * Use is subject to license terms.
4b5514887Smuffin  */
5b5514887Smuffin 
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 
157c478bd9Sstevel@tonic-gate  /* tt.c: subroutines for drawing horizontal lines */
167c478bd9Sstevel@tonic-gate # include "t..c"
17b5514887Smuffin 
18b5514887Smuffin int
ctype(int il,int ic)19b5514887Smuffin ctype(int il, int ic)
207c478bd9Sstevel@tonic-gate {
217c478bd9Sstevel@tonic-gate if (instead[il])
227c478bd9Sstevel@tonic-gate 	return(0);
237c478bd9Sstevel@tonic-gate if (fullbot[il])
247c478bd9Sstevel@tonic-gate 	return(0);
257c478bd9Sstevel@tonic-gate il = stynum[il];
267c478bd9Sstevel@tonic-gate return(style[il][ic]);
277c478bd9Sstevel@tonic-gate }
28b5514887Smuffin 
29b5514887Smuffin int
min(int a,int b)30b5514887Smuffin min(int a, int b)
317c478bd9Sstevel@tonic-gate {
327c478bd9Sstevel@tonic-gate return(a<b ? a : b);
337c478bd9Sstevel@tonic-gate }
34b5514887Smuffin 
35b5514887Smuffin int
fspan(int i,int c)36b5514887Smuffin fspan(int i, int c)
377c478bd9Sstevel@tonic-gate {
387c478bd9Sstevel@tonic-gate c++;
397c478bd9Sstevel@tonic-gate return(c<ncol && ctype(i,c)=='s');
407c478bd9Sstevel@tonic-gate }
41b5514887Smuffin 
42b5514887Smuffin int
lspan(int i,int c)43b5514887Smuffin lspan(int i, int c)
447c478bd9Sstevel@tonic-gate {
457c478bd9Sstevel@tonic-gate int k;
467c478bd9Sstevel@tonic-gate if (ctype(i,c) != 's') return(0);
477c478bd9Sstevel@tonic-gate c++;
48*2a8bcb4eSToomas Soome if (c < ncol && ctype(i,c)== 's')
497c478bd9Sstevel@tonic-gate 	return(0);
507c478bd9Sstevel@tonic-gate for(k=0; ctype(i,--c) == 's'; k++);
517c478bd9Sstevel@tonic-gate return(k);
527c478bd9Sstevel@tonic-gate }
53b5514887Smuffin 
54b5514887Smuffin int
ctspan(int i,int c)55b5514887Smuffin ctspan(int i, int c)
567c478bd9Sstevel@tonic-gate {
577c478bd9Sstevel@tonic-gate int k;
587c478bd9Sstevel@tonic-gate c++;
597c478bd9Sstevel@tonic-gate for(k=1; c<ncol && ctype(i,c)=='s'; k++)
607c478bd9Sstevel@tonic-gate 	c++;
617c478bd9Sstevel@tonic-gate return(k);
627c478bd9Sstevel@tonic-gate }
63b5514887Smuffin 
64b5514887Smuffin void
tohcol(int ic)65b5514887Smuffin tohcol(int ic)
667c478bd9Sstevel@tonic-gate {
677c478bd9Sstevel@tonic-gate 			if (ic==0)
687c478bd9Sstevel@tonic-gate 				fprintf(tabout, "\\h'|0'");
697c478bd9Sstevel@tonic-gate 			else
707c478bd9Sstevel@tonic-gate 				fprintf(tabout, "\\h'(|\\n(%du+|\\n(%du)/2u'", ic+CLEFT, ic+CRIGHT-1);
717c478bd9Sstevel@tonic-gate }
72b5514887Smuffin 
73b5514887Smuffin int
allh(int i)74b5514887Smuffin allh(int i)
757c478bd9Sstevel@tonic-gate {
767c478bd9Sstevel@tonic-gate /* return true if every element in line i is horizontal */
777c478bd9Sstevel@tonic-gate /* also at least one must be horizontl */
787c478bd9Sstevel@tonic-gate int c, one, k;
797c478bd9Sstevel@tonic-gate if (fullbot[i]) return(1);
807c478bd9Sstevel@tonic-gate for(one=c=0; c<ncol; c++)
817c478bd9Sstevel@tonic-gate 	{
827c478bd9Sstevel@tonic-gate 	k = thish(i,c);
837c478bd9Sstevel@tonic-gate 	if (k==0) return(0);
847c478bd9Sstevel@tonic-gate 	if (k==1) continue;
857c478bd9Sstevel@tonic-gate 	one=1;
867c478bd9Sstevel@tonic-gate 	}
877c478bd9Sstevel@tonic-gate return(one);
887c478bd9Sstevel@tonic-gate }
89b5514887Smuffin 
90b5514887Smuffin int
thish(int i,int c)91b5514887Smuffin thish(int i, int c)
927c478bd9Sstevel@tonic-gate {
937c478bd9Sstevel@tonic-gate 	int t;
947c478bd9Sstevel@tonic-gate 	char *s;
957c478bd9Sstevel@tonic-gate 	struct colstr *pc;
967c478bd9Sstevel@tonic-gate 	if (c<0)return(0);
977c478bd9Sstevel@tonic-gate 	if (i<0) return(0);
987c478bd9Sstevel@tonic-gate 	t = ctype(i,c);
997c478bd9Sstevel@tonic-gate 	if (t=='_' || t == '-')
1007c478bd9Sstevel@tonic-gate 		return('-');
1017c478bd9Sstevel@tonic-gate 	if (t=='=')return('=');
1027c478bd9Sstevel@tonic-gate 	if (t=='^') return(1);
1037c478bd9Sstevel@tonic-gate 	if (fullbot[i] )
1047c478bd9Sstevel@tonic-gate 		return(fullbot[i]);
1057c478bd9Sstevel@tonic-gate 	if (t=='s') return(thish(i,c-1));
1067c478bd9Sstevel@tonic-gate 	if (t==0) return(1);
1077c478bd9Sstevel@tonic-gate 	pc = &table[i][c];
1087c478bd9Sstevel@tonic-gate 	s = (t=='a' ? pc->rcol : pc->col);
1097c478bd9Sstevel@tonic-gate 	if (s==0 || (point(s) && *s==0))
1107c478bd9Sstevel@tonic-gate 		return(1);
1117c478bd9Sstevel@tonic-gate 	if (vspen(s)) return(1);
1127c478bd9Sstevel@tonic-gate 	if (t=barent( s))
1137c478bd9Sstevel@tonic-gate 		return(t);
1147c478bd9Sstevel@tonic-gate 	return(0);
1157c478bd9Sstevel@tonic-gate }
116