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