home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_disks / 200-299 / ff256.lzh / Stevie / linefunc.c < prev    next >
C/C++ Source or Header  |  1989-10-19  |  2KB  |  90 lines

  1. /*
  2.  * STEVIE - Simply Try this Editor for VI Enthusiasts
  3.  *
  4.  * Code Contributions By : Tim Thompson           twitch!tjt
  5.  *                         Tony Andrews           onecom!wldrdg!tony 
  6.  *                         G. R. (Fred) Walter    watmath!grwalter 
  7.  */
  8.  
  9. #include "stevie.h"
  10.  
  11. /*
  12.  * nextline(curr) 
  13.  *
  14.  * Return a pointer to the beginning of the next line after the one referenced
  15.  * by 'curr'. Return NULL if there is no next line (at EOF). 
  16.  */
  17.  
  18. LPtr           *
  19. nextline(curr)
  20.     LPtr           *curr;
  21. {
  22.     static LPtr     next;
  23.  
  24.     if (curr != NULL) {
  25.     if (curr->linep->next != Fileend->linep) {
  26.         next.index = 0;
  27.         next.linep = curr->linep->next;
  28.         return &next;
  29.     }
  30.     }
  31.     return (LPtr *) NULL;
  32. }
  33.  
  34. /*
  35.  * prevline(curr) 
  36.  *
  37.  * Return a pointer to the beginning of the line before the one referenced by
  38.  * 'curr'. Return NULL if there is no prior line. 
  39.  */
  40.  
  41. LPtr           *
  42. prevline(curr)
  43.     LPtr           *curr;
  44. {
  45.     static LPtr     prev;
  46.  
  47.     if (curr != NULL) {
  48.     if (curr->linep->prev != Filetop->linep) {
  49.         prev.index = 0;
  50.         prev.linep = curr->linep->prev;
  51.         return &prev;
  52.     }
  53.     }
  54.     return (LPtr *) NULL;
  55. }
  56.  
  57. /*
  58.  * coladvance(p,col) 
  59.  *
  60.  * Try to advance to the specified column, starting at p. 
  61.  */
  62.  
  63. void
  64. coladvance(p, want_col)
  65.     register LPtr  *p;
  66.     register int    want_col;
  67. {
  68.     register char   c;
  69.     register int    col;
  70.     register int    incr;
  71.  
  72.     if (gchar(p) != NUL) {    /* already at the end of line */
  73.     for (col = 0; want_col > 0;) {
  74.         c = gchar(p);
  75.         if (c == TAB && !P(P_LS))
  76.         incr = (P(P_TS) - col % P(P_TS));
  77.         else
  78.         incr = chars[c].ch_size;
  79.         want_col -= incr;
  80.         col += incr;
  81.  
  82.         /* Don't go past the end of the file or the line. */
  83.         if (inc(p)) {
  84.         dec(p);
  85.         break;
  86.         }
  87.     }
  88.     }
  89. }
  90.