home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_300 / 313_01 / linefunc.c < prev    next >
C/C++ Source or Header  |  1990-04-22  |  2KB  |  87 lines

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