ti.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. * This file is part of the UCB release of Plan 9. It is subject to the license
  3. * terms in the LICENSE file found in the top-level directory of this
  4. * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  5. * part of the UCB release of Plan 9, including this file, may be copied,
  6. * modified, propagated, or distributed except according to the terms contained
  7. * in the LICENSE file.
  8. */
  9. /* ti.c: classify line intersections */
  10. # include "t.h"
  11. /* determine local environment for intersections */
  12. int
  13. interv(int i, int c)
  14. {
  15. int ku, kl;
  16. if (c >= ncol || c == 0) {
  17. if (dboxflg) {
  18. if (i == 0)
  19. return(BOT);
  20. if (i >= nlin)
  21. return(TOP);
  22. return(THRU);
  23. }
  24. if (c >= ncol)
  25. return(0);
  26. }
  27. ku = i > 0 ? lefdata(i - 1, c) : 0;
  28. if (i + 1 >= nlin && allh(i))
  29. kl = 0;
  30. else
  31. kl = lefdata(allh(i) ? i + 1 : i, c);
  32. if (ku == 2 && kl == 2)
  33. return(THRU);
  34. if (ku == 2)
  35. return(TOP);
  36. if (kl == BOT)
  37. return(2);
  38. return(0);
  39. }
  40. int
  41. interh(int i, int c)
  42. {
  43. int kl, kr;
  44. if (fullbot[i] == '=' || (dboxflg && (i == 0 || i >= nlin - 1))) {
  45. if (c == ncol)
  46. return(LEFT);
  47. if (c == 0)
  48. return(RIGHT);
  49. return(THRU);
  50. }
  51. if (i >= nlin)
  52. return(0);
  53. kl = c > 0 ? thish (i, c - 1) : 0;
  54. if (kl <= 1 && i > 0 && allh(up1(i)))
  55. kl = c > 0 ? thish(up1(i), c - 1) : 0;
  56. kr = thish(i, c);
  57. if (kr <= 1 && i > 0 && allh(up1(i)))
  58. kr = c > 0 ? thish(up1(i), c) : 0;
  59. if (kl == '=' && kr == '=')
  60. return(THRU);
  61. if (kl == '=')
  62. return(LEFT);
  63. if (kr == '=')
  64. return(RIGHT);
  65. return(0);
  66. }
  67. int
  68. up1(int i)
  69. {
  70. i--;
  71. while (instead[i] && i > 0)
  72. i--;
  73. return(i);
  74. }