home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-387-Vol-3of3.iso / e / elv17src.zip / MOVE3.C < prev    next >
C/C++ Source or Header  |  1992-12-30  |  3KB  |  146 lines

  1. /* move3.c */
  2.  
  3. /* Author:
  4.  *    Steve Kirkendall
  5.  *    14407 SW Teal Blvd. #C
  6.  *    Beaverton, OR 97005
  7.  *    kirkenda@cs.pdx.edu
  8.  */
  9.  
  10.  
  11. /* This file contains movement functions that perform character searches */
  12.  
  13. #include "config.h"
  14. #include "vi.h"
  15.  
  16. #ifndef NO_CHARSEARCH
  17. static MARK    (*prevfwdfn)();    /* function to search in same direction */
  18. static MARK    (*prevrevfn)();    /* function to search in opposite direction */
  19. static char    prev_key;    /* sought cvhar from previous [fFtT] */
  20.  
  21. MARK    m__ch(m, cnt, cmd)
  22.     MARK    m;    /* current position */
  23.     long    cnt;
  24.     int    cmd;    /* command: either ',' or ';' */
  25. {
  26.     MARK    (*tmp)();
  27.  
  28.     if (!prevfwdfn)
  29.     {
  30.         msg("No previous f, F, t, or T command");
  31.         return MARK_UNSET;
  32.     }
  33.  
  34.     if (cmd == ',')
  35.     {
  36.         m =  (*prevrevfn)(m, cnt, prev_key);
  37.  
  38.         /* Oops! we didn't want to change the prev*fn vars! */
  39.         tmp = prevfwdfn;
  40.         prevfwdfn = prevrevfn;
  41.         prevrevfn = tmp;
  42.  
  43.         return m;
  44.     }
  45.     else
  46.     {
  47.         return (*prevfwdfn)(m, cnt, prev_key);
  48.     }
  49. }
  50.  
  51. /* move forward within this line to next occurrence of key */
  52. MARK    m_fch(m, cnt, key)
  53.     MARK    m;    /* where to search from */
  54.     long    cnt;
  55.     int    key;    /* what to search for */
  56. {
  57.     REG char    *text;
  58.  
  59.     DEFAULT(1);
  60.  
  61.     prevfwdfn = m_fch;
  62.     prevrevfn = m_Fch;
  63.     prev_key = key;
  64.  
  65.     pfetch(markline(m));
  66.     text = ptext + markidx(m);
  67.     while (cnt-- > 0)
  68.     {
  69.         do
  70.         {
  71.             m++;
  72.             text++;
  73.         } while (*text && *text != key);
  74.     }
  75.     if (!*text)
  76.     {
  77.         return MARK_UNSET;
  78.     }
  79.     return m;
  80. }
  81.  
  82. /* move backward within this line to previous occurrence of key */
  83. MARK    m_Fch(m, cnt, key)
  84.     MARK    m;    /* where to search from */
  85.     long    cnt;
  86.     int    key;    /* what to search for */
  87. {
  88.     REG char    *text;
  89.  
  90.     DEFAULT(1);
  91.  
  92.     prevfwdfn = m_Fch;
  93.     prevrevfn = m_fch;
  94.     prev_key = key;
  95.  
  96.     pfetch(markline(m));
  97.     text = ptext + markidx(m);
  98.     while (cnt-- > 0)
  99.     {
  100.         do
  101.         {
  102.             m--;
  103.             text--;
  104.         } while (text >= ptext && *text != key);
  105.     }
  106.     if (text < ptext)
  107.     {
  108.         return MARK_UNSET;
  109.     }
  110.     return m;
  111. }
  112.  
  113. /* move forward within this line almost to next occurrence of key */
  114. MARK    m_tch(m, cnt, key)
  115.     MARK    m;    /* where to search from */
  116.     long    cnt;
  117.     int    key;    /* what to search for */
  118. {
  119.     m = m_fch(m, cnt, key);
  120.     if (m != MARK_UNSET)
  121.     {
  122.         prevfwdfn = m_tch;
  123.         prevrevfn = m_Tch;
  124.         m--;
  125.     }
  126.     return m;
  127. }
  128.  
  129. /* move backward within this line almost to previous occurrence of key */
  130. MARK    m_Tch(m, cnt, key)
  131.     MARK    m;    /* where to search from */
  132.     long    cnt;
  133.     int    key;    /* what to search for */
  134. {
  135.     m = m_Fch(m, cnt, key);
  136.     if (m == MARK_UNSET)
  137.     {
  138.         prevfwdfn = m_Tch;
  139.         prevrevfn = m_tch;
  140.         m++;
  141.     }
  142.  
  143.     return m;
  144. }
  145. #endif
  146.