home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / STEVIE.ZIP / LINEFUNC.C < prev    next >
C/C++ Source or Header  |  1988-06-09  |  2KB  |  89 lines

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