move3.c

Go to the documentation of this file.
00001 /* move3.c */
00002 
00003 /* Author:
00004  *      Steve Kirkendall
00005  *      14407 SW Teal Blvd. #C
00006  *      Beaverton, OR 97005
00007  *      kirkenda@cs.pdx.edu
00008  */
00009 
00010 
00011 /* This file contains movement functions that perform character searches */
00012 
00013 #include "config.h"
00014 #include "vi.h"
00015 
00016 #ifndef NO_CHARSEARCH
00017 static MARK     (*prevfwdfn)(); /* function to search in same direction */
00018 static MARK     (*prevrevfn)(); /* function to search in opposite direction */
00019 static char     prev_key;       /* sought cvhar from previous [fFtT] */
00020 
00021 MARK    m__ch(m, cnt, cmd)
00022         MARK    m;      /* current position */
00023         long    cnt;
00024         char    cmd;    /* command: either ',' or ';' */
00025 {
00026         MARK    (*tmp)();
00027 
00028         if (!prevfwdfn)
00029         {
00030                 msg("No previous f, F, t, or T command");
00031                 return MARK_UNSET;
00032         }
00033 
00034         if (cmd == ',')
00035         {
00036                 m =  (*prevrevfn)(m, cnt, prev_key);
00037 
00038                 /* Oops! we didn't want to change the prev*fn vars! */
00039                 tmp = prevfwdfn;
00040                 prevfwdfn = prevrevfn;
00041                 prevrevfn = tmp;
00042 
00043                 return m;
00044         }
00045         else
00046         {
00047                 return (*prevfwdfn)(m, cnt, prev_key);
00048         }
00049 }
00050 
00051 /* move forward within this line to next occurrence of key */
00052 MARK    m_fch(m, cnt, key)
00053         MARK    m;      /* where to search from */
00054         long    cnt;
00055         char    key;    /* what to search for */
00056 {
00057         REG char        *text;
00058 
00059         DEFAULT(1);
00060 
00061         prevfwdfn = m_fch;
00062         prevrevfn = m_Fch;
00063         prev_key = key;
00064 
00065         pfetch(markline(m));
00066         text = ptext + markidx(m);
00067         while (cnt-- > 0)
00068         {
00069                 do
00070                 {
00071                         m++;
00072                         text++;
00073                 } while (*text && *text != key);
00074         }
00075         if (!*text)
00076         {
00077                 return MARK_UNSET;
00078         }
00079         return m;
00080 }
00081 
00082 /* move backward within this line to previous occurrence of key */
00083 MARK    m_Fch(m, cnt, key)
00084         MARK    m;      /* where to search from */
00085         long    cnt;
00086         char    key;    /* what to search for */
00087 {
00088         REG char        *text;
00089 
00090         DEFAULT(1);
00091 
00092         prevfwdfn = m_Fch;
00093         prevrevfn = m_fch;
00094         prev_key = key;
00095 
00096         pfetch(markline(m));
00097         text = ptext + markidx(m);
00098         while (cnt-- > 0)
00099         {
00100                 do
00101                 {
00102                         m--;
00103                         text--;
00104                 } while (text >= ptext && *text != key);
00105         }
00106         if (text < ptext)
00107         {
00108                 return MARK_UNSET;
00109         }
00110         return m;
00111 }
00112 
00113 /* move forward within this line almost to next occurrence of key */
00114 MARK    m_tch(m, cnt, key)
00115         MARK    m;      /* where to search from */
00116         long    cnt;
00117         char    key;    /* what to search for */
00118 {
00119         /* skip the adjacent char */
00120         pfetch(markline(m));
00121         if (plen <= markidx(m))
00122         {
00123                 return MARK_UNSET;
00124         }
00125         m++;
00126 
00127         m = m_fch(m, cnt, key);
00128         if (m == MARK_UNSET)
00129         {
00130                 return MARK_UNSET;
00131         }
00132 
00133         prevfwdfn = m_tch;
00134         prevrevfn = m_Tch;
00135 
00136         return m - 1;
00137 }
00138 
00139 /* move backward within this line almost to previous occurrence of key */
00140 MARK    m_Tch(m, cnt, key)
00141         MARK    m;      /* where to search from */
00142         long    cnt;
00143         char    key;    /* what to search for */
00144 {
00145         /* skip the adjacent char */
00146         if (markidx(m) == 0)
00147         {
00148                 return MARK_UNSET;
00149         }
00150         m--;
00151 
00152         m = m_Fch(m, cnt, key);
00153         if (m == MARK_UNSET)
00154         {
00155                 return MARK_UNSET;
00156         }
00157 
00158         prevfwdfn = m_Tch;
00159         prevrevfn = m_tch;
00160 
00161         return m + 1;
00162 }
00163 #endif

Generated on Fri Apr 14 22:56:53 2006 for minix by  doxygen 1.4.6