plan9port

fork of plan9port with libvec, libstr and libsdb
Log | Files | Refs | README | LICENSE

ti.c (1190B)


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