xref: /illumos-gate/usr/src/cmd/tbl/ti.c (revision 1a2d662a91cee3bf82f41cd47c7ae6f3825d9db2)
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  /* ti.c: classify line intersections */
16 # include "t..c"
17 /* determine local environment for intersections */
18 
19 int
20 interv(int i, int c)
21 {
22 int ku, kl;
23 if (c>=ncol || c == 0)
24 	{
25 	if (dboxflg)
26 		{
27 		if (i==0) return(BOT);
28 		if (i>=nlin) return(TOP);
29 		return(THRU);
30 		}
31 	if (c>=ncol)
32 		return(0);
33 	}
34 ku = i>0 ? lefdata(i-1,c) : 0;
35 if (i+1 >= nlin)
36 	kl=0;
37 else
38 kl = lefdata(allh(i) ? i+1 : i, c);
39 if (ku==2 && kl==2) return(THRU);
40 if (ku ==2) return(TOP);
41 if (kl==BOT) return(2);
42 return(0);
43 }
44 
45 int
46 interh(int i, int c)
47 {
48 int kl, kr;
49 if (fullbot[i]== '=' || (dboxflg && (i==0 || i>= nlin-1)))
50 	{
51 	if (c==ncol)
52 		return(LEFT);
53 	if (c==0)
54 		return(RIGHT);
55 	return(THRU);
56 	}
57 if (i>=nlin) return(0);
58 kl = c>0 ? thish (i,c-1) : 0;
59 if (kl<=1 && i>0 && allh(up1(i)))
60 	kl = c>0 ? thish(up1(i),c-1) : 0;
61 kr = thish(i,c);
62 if (kr<=1 && i>0 && allh(up1(i)))
63 	kr = c>0 ? thish(up1(i), c) : 0;
64 if (kl== '=' && kr ==  '=') return(THRU);
65 if (kl== '=') return(LEFT);
66 if (kr== '=') return(RIGHT);
67 return(0);
68 }
69 
70 int
71 up1(int i)
72 {
73 i--;
74 while (instead[i] && i>0) i--;
75 return(i);
76 }
77