home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_disks / 100-199 / ff197.lzh / Stevie / linefunc.c < prev    next >
C/C++ Source or Header  |  1989-03-28  |  2KB  |  94 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!watcgl!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. LPtr           *
  64. coladvance(p, col)
  65.     LPtr           *p;
  66.     int             col;
  67. {
  68.     static LPtr     lp;
  69.     int             c, in;
  70.  
  71.     lp.linep = p->linep;
  72.     lp.index = p->index;
  73.  
  74.     /* If we're on a blank ('\n' only) line, we can't do anything */
  75.     if (lp.linep->s[lp.index] == '\0')
  76.     return &lp;
  77.     /* try to advance to the specified column */
  78.     for (c = 0; col-- > 0; c++) {
  79.     /* Count a tab for what it's worth (if list mode not on) */
  80.     if (gchar(&lp) == TAB && !P(P_LS)) {
  81.         in = ((P(P_TS) - 1) - c % P(P_TS));
  82.         col -= in;
  83.         c += in;
  84.     }
  85.     /* Don't go past the end of */
  86.     /* the file or the line. */
  87.     if (inc(&lp)) {
  88.         dec(&lp);
  89.         break;
  90.     }
  91.     }
  92.     return &lp;
  93. }
  94.