Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

86 lines
2.0 KiB

  1. /* $Header: /nw/tony/src/stevie/src/RCS/linefunc.c,v 1.2 89/03/11 22:42:32 tony Exp $
  2. *
  3. * Basic line-oriented motions.
  4. */
  5. #include "stevie.h"
  6. /*
  7. * nextline(curr)
  8. *
  9. * Return a pointer to the beginning of the next line after the one
  10. * referenced by 'curr'. Return NULL if there is no next line (at EOF).
  11. */
  12. LNPTR *
  13. nextline(curr)
  14. LNPTR *curr;
  15. {
  16. static LNPTR next;
  17. if (curr->linep && curr->linep->next != Fileend->linep) {
  18. next.index = 0;
  19. next.linep = curr->linep->next;
  20. return &next;
  21. }
  22. return (LNPTR *) NULL;
  23. }
  24. /*
  25. * prevline(curr)
  26. *
  27. * Return a pointer to the beginning of the line before the one
  28. * referenced by 'curr'. Return NULL if there is no prior line.
  29. */
  30. LNPTR *
  31. prevline(curr)
  32. LNPTR *curr;
  33. {
  34. static LNPTR prev;
  35. if (curr->linep->prev != Filetop->linep) {
  36. prev.index = 0;
  37. prev.linep = curr->linep->prev;
  38. return &prev;
  39. }
  40. return (LNPTR *) NULL;
  41. }
  42. /*
  43. * coladvance(p,col)
  44. *
  45. * Try to advance to the specified column, starting at p.
  46. */
  47. LNPTR *
  48. coladvance(p, col)
  49. LNPTR *p;
  50. register int col;
  51. {
  52. static LNPTR lp;
  53. register int c, in;
  54. lp.linep = p->linep;
  55. lp.index = p->index;
  56. /* If we're on a blank ('\n' only) line, we can't do anything */
  57. if (lp.linep->s[lp.index] == '\0')
  58. return &lp;
  59. /* try to advance to the specified column */
  60. for ( c=0; col-- > 0; c++ ) {
  61. /* Count a tab for what it's worth (if list mode not on) */
  62. if ( gchar(&lp) == TAB && !P(P_LS) ) {
  63. in = ((P(P_TS)-1) - c%P(P_TS));
  64. col -= in;
  65. c += in;
  66. }
  67. /* Don't go past the end of */
  68. /* the file or the line. */
  69. if (inc(&lp)) {
  70. dec(&lp);
  71. break;
  72. }
  73. }
  74. return &lp;
  75. }