home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 1 / ARM_CLUB_CD.iso / contents / apps / program / d / elvis / Source / c / move3 < prev    next >
Encoding:
Text File  |  1989-12-31  |  2.7 KB  |  161 lines

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