2 * Copyright (c) 1992, 1993, 1994
3 * The Regents of the University of California. All rights reserved.
4 * Copyright (c) 1992, 1993, 1994, 1995, 1996
5 * Keith Bostic. All rights reserved.
7 * See the LICENSE file for redistribution information.
12 #include <sys/types.h>
13 #include <sys/queue.h>
16 #include <bitstring.h>
21 #include "../common/common.h"
24 static void notfound(SCR *, ARG_CHAR_T);
25 static void noprev(SCR *);
28 * v_chrepeat -- [count];
29 * Repeat the last F, f, T or t search.
31 * PUBLIC: int v_chrepeat(SCR *, VICMD *);
34 v_chrepeat(SCR *sp, VICMD *vp)
36 vp->character = VIP(sp)->lastckey;
38 switch (VIP(sp)->csearchdir) {
43 return (v_chF(sp, vp));
45 return (v_chf(sp, vp));
47 return (v_chT(sp, vp));
49 return (v_cht(sp, vp));
57 * v_chrrepeat -- [count],
58 * Repeat the last F, f, T or t search in the reverse direction.
60 * PUBLIC: int v_chrrepeat(SCR *, VICMD *);
63 v_chrrepeat(SCR *sp, VICMD *vp)
68 vp->character = VIP(sp)->lastckey;
69 savedir = VIP(sp)->csearchdir;
71 switch (VIP(sp)->csearchdir) {
90 VIP(sp)->csearchdir = savedir;
96 * Search forward in the line for the character before the next
97 * occurrence of the specified character.
99 * PUBLIC: int v_cht(SCR *, VICMD *);
102 v_cht(SCR *sp, VICMD *vp)
108 * v_chf places the cursor on the character, where the 't'
109 * command wants it to its left. We know this is safe since
110 * we had to move right for v_chf() to have succeeded.
115 * Make any necessary correction to the motion decision made
116 * by the v_chf routine.
119 vp->m_final = vp->m_stop;
121 VIP(sp)->csearchdir = tSEARCH;
127 * Search forward in the line for the next occurrence of the
128 * specified character.
130 * PUBLIC: int v_chf(SCR *, VICMD *);
133 v_chf(SCR *sp, VICMD *vp)
139 CHAR_T *endp, *p, *startp;
143 * If it's a dot command, it doesn't reset the key for which we're
144 * searching, e.g. in "df1|f2|.|;", the ';' searches for a '2'.
147 if (!F_ISSET(vp, VC_ISDOT))
148 VIP(sp)->lastckey = key;
149 VIP(sp)->csearchdir = fSEARCH;
151 if (db_eget(sp, vp->m_start.lno, &p, &len, &isempty)) {
158 empty: notfound(sp, key);
162 endp = (startp = p) + len;
163 p += vp->m_start.cno;
164 for (cnt = F_ISSET(vp, VC_C1SET) ? vp->count : 1; cnt--;) {
165 while (++p < endp && *p != key);
172 vp->m_stop.cno = p - startp;
175 * Non-motion commands move to the end of the range.
176 * Delete and yank stay at the start, ignore others.
178 vp->m_final = ISMOTION(vp) ? vp->m_start : vp->m_stop;
184 * Search backward in the line for the character after the next
185 * occurrence of the specified character.
187 * PUBLIC: int v_chT(SCR *, VICMD *);
190 v_chT(SCR *sp, VICMD *vp)
196 * Check whether the matching character is to the immediate left
197 * of the original cursor position, offset adjusted for a motion
198 * command. If so, no movement is required.
200 if (vp->m_start.cno == vp->m_stop.cno) {
205 * v_chF places the cursor on the character, where the 'T'
206 * command wants it to its right. We know this is safe since
207 * we had to move left for v_chF() to have succeeded.
210 vp->m_final = vp->m_stop;
212 VIP(sp)->csearchdir = TSEARCH;
218 * Search backward in the line for the next occurrence of the
219 * specified character.
221 * PUBLIC: int v_chF(SCR *, VICMD *);
224 v_chF(SCR *sp, VICMD *vp)
234 * If it's a dot command, it doesn't reset the key for which
235 * we're searching, e.g. in "df1|f2|.|;", the ';' searches
239 if (!F_ISSET(vp, VC_ISDOT))
240 VIP(sp)->lastckey = key;
241 VIP(sp)->csearchdir = FSEARCH;
243 if (db_eget(sp, vp->m_start.lno, &p, &len, &isempty)) {
250 empty: notfound(sp, key);
255 p += vp->m_start.cno;
256 for (cnt = F_ISSET(vp, VC_C1SET) ? vp->count : 1; cnt--;) {
257 while (--p > endp && *p != key);
264 vp->m_stop.cno = (p - endp) - 1;
267 * All commands move to the end of the range. Motion commands
268 * adjust the starting point to the character before the current
271 vp->m_final = vp->m_stop;
280 msgq(sp, M_BERR, "178|No previous F, f, T or t search");
284 notfound(SCR *sp, ARG_CHAR_T ch)
286 msgq(sp, M_BERR, "179|%s not found", KEY_NAME(sp, ch));