retire nonsymbolic rootdev, dev2name
[minix.git] / commands / elvis / move3.c
bloba9e46ea8a949d377da466b51bba1151f74dc9982
1 /* move3.c */
3 /* Author:
4 * Steve Kirkendall
5 * 14407 SW Teal Blvd. #C
6 * Beaverton, OR 97005
7 * kirkenda@cs.pdx.edu
8 */
11 /* This file contains movement functions that perform character searches */
13 #include "config.h"
14 #include "vi.h"
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] */
21 MARK m__ch(m, cnt, cmd)
22 MARK m; /* current position */
23 long cnt;
24 char cmd; /* command: either ',' or ';' */
26 MARK (*tmp)();
28 if (!prevfwdfn)
30 msg("No previous f, F, t, or T command");
31 return MARK_UNSET;
34 if (cmd == ',')
36 m = (*prevrevfn)(m, cnt, prev_key);
38 /* Oops! we didn't want to change the prev*fn vars! */
39 tmp = prevfwdfn;
40 prevfwdfn = prevrevfn;
41 prevrevfn = tmp;
43 return m;
45 else
47 return (*prevfwdfn)(m, cnt, prev_key);
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 char key; /* what to search for */
57 REG char *text;
59 DEFAULT(1);
61 prevfwdfn = m_fch;
62 prevrevfn = m_Fch;
63 prev_key = key;
65 pfetch(markline(m));
66 text = ptext + markidx(m);
67 while (cnt-- > 0)
71 m++;
72 text++;
73 } while (*text && *text != key);
75 if (!*text)
77 return MARK_UNSET;
79 return m;
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 char key; /* what to search for */
88 REG char *text;
90 DEFAULT(1);
92 prevfwdfn = m_Fch;
93 prevrevfn = m_fch;
94 prev_key = key;
96 pfetch(markline(m));
97 text = ptext + markidx(m);
98 while (cnt-- > 0)
102 m--;
103 text--;
104 } while (text >= ptext && *text != key);
106 if (text < ptext)
108 return MARK_UNSET;
110 return m;
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 char key; /* what to search for */
119 /* skip the adjacent char */
120 pfetch(markline(m));
121 if (plen <= markidx(m))
123 return MARK_UNSET;
125 m++;
127 m = m_fch(m, cnt, key);
128 if (m == MARK_UNSET)
130 return MARK_UNSET;
133 prevfwdfn = m_tch;
134 prevrevfn = m_Tch;
136 return m - 1;
139 /* move backward within this line almost to previous occurrence of key */
140 MARK m_Tch(m, cnt, key)
141 MARK m; /* where to search from */
142 long cnt;
143 char key; /* what to search for */
145 /* skip the adjacent char */
146 if (markidx(m) == 0)
148 return MARK_UNSET;
150 m--;
152 m = m_Fch(m, cnt, key);
153 if (m == MARK_UNSET)
155 return MARK_UNSET;
158 prevfwdfn = m_Tch;
159 prevrevfn = m_tch;
161 return m + 1;
163 #endif