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.
13 static const char sccsid
[] = "@(#)v_ch.c 10.8 (Berkeley) 3/6/96";
16 #include <sys/types.h>
17 #include <sys/queue.h>
20 #include <bitstring.h>
25 #include "../common/common.h"
28 static void notfound
__P((SCR
*, ARG_CHAR_T
));
29 static void noprev
__P((SCR
*));
32 * v_chrepeat -- [count];
33 * Repeat the last F, f, T or t search.
35 * PUBLIC: int v_chrepeat __P((SCR *, VICMD *));
42 vp
->character
= VIP(sp
)->lastckey
;
44 switch (VIP(sp
)->csearchdir
) {
49 return (v_chF(sp
, vp
));
51 return (v_chf(sp
, vp
));
53 return (v_chT(sp
, vp
));
55 return (v_cht(sp
, vp
));
63 * v_chrrepeat -- [count],
64 * Repeat the last F, f, T or t search in the reverse direction.
66 * PUBLIC: int v_chrrepeat __P((SCR *, VICMD *));
76 vp
->character
= VIP(sp
)->lastckey
;
77 savedir
= VIP(sp
)->csearchdir
;
79 switch (VIP(sp
)->csearchdir
) {
98 VIP(sp
)->csearchdir
= savedir
;
104 * Search forward in the line for the character before the next
105 * occurrence of the specified character.
107 * PUBLIC: int v_cht __P((SCR *, VICMD *));
118 * v_chf places the cursor on the character, where the 't'
119 * command wants it to its left. We know this is safe since
120 * we had to move right for v_chf() to have succeeded.
125 * Make any necessary correction to the motion decision made
126 * by the v_chf routine.
129 vp
->m_final
= vp
->m_stop
;
131 VIP(sp
)->csearchdir
= tSEARCH
;
137 * Search forward in the line for the next occurrence of the
138 * specified character.
140 * PUBLIC: int v_chf __P((SCR *, VICMD *));
150 char *endp
, *p
, *startp
;
154 * If it's a dot command, it doesn't reset the key for which we're
155 * searching, e.g. in "df1|f2|.|;", the ';' searches for a '2'.
158 if (!F_ISSET(vp
, VC_ISDOT
))
159 VIP(sp
)->lastckey
= key
;
160 VIP(sp
)->csearchdir
= fSEARCH
;
162 if (db_eget(sp
, vp
->m_start
.lno
, &p
, &len
, &isempty
)) {
169 empty
: notfound(sp
, key
);
173 endp
= (startp
= p
) + len
;
174 p
+= vp
->m_start
.cno
;
175 for (cnt
= F_ISSET(vp
, VC_C1SET
) ? vp
->count
: 1; cnt
--;) {
176 while (++p
< endp
&& *p
!= key
);
183 vp
->m_stop
.cno
= p
- startp
;
186 * Non-motion commands move to the end of the range.
187 * Delete and yank stay at the start, ignore others.
189 vp
->m_final
= ISMOTION(vp
) ? vp
->m_start
: vp
->m_stop
;
195 * Search backward in the line for the character after the next
196 * occurrence of the specified character.
198 * PUBLIC: int v_chT __P((SCR *, VICMD *));
209 * v_chF places the cursor on the character, where the 'T'
210 * command wants it to its right. We know this is safe since
211 * we had to move left for v_chF() to have succeeded.
214 vp
->m_final
= vp
->m_stop
;
216 VIP(sp
)->csearchdir
= TSEARCH
;
222 * Search backward in the line for the next occurrence of the
223 * specified character.
225 * PUBLIC: int v_chF __P((SCR *, VICMD *));
239 * If it's a dot command, it doesn't reset the key for which
240 * we're searching, e.g. in "df1|f2|.|;", the ';' searches
244 if (!F_ISSET(vp
, VC_ISDOT
))
245 VIP(sp
)->lastckey
= key
;
246 VIP(sp
)->csearchdir
= FSEARCH
;
248 if (db_eget(sp
, vp
->m_start
.lno
, &p
, &len
, &isempty
)) {
255 empty
: notfound(sp
, key
);
260 p
+= vp
->m_start
.cno
;
261 for (cnt
= F_ISSET(vp
, VC_C1SET
) ? vp
->count
: 1; cnt
--;) {
262 while (--p
> endp
&& *p
!= key
);
269 vp
->m_stop
.cno
= (p
- endp
) - 1;
272 * All commands move to the end of the range. Motion commands
273 * adjust the starting point to the character before the current
276 vp
->m_final
= vp
->m_stop
;
286 msgq(sp
, M_BERR
, "178|No previous F, f, T or t search");
294 msgq(sp
, M_BERR
, "179|%s not found", KEY_NAME(sp
, ch
));