4 * Copyright (c) 1992, 1993, 1994
5 * The Regents of the University of California. All rights reserved.
6 * Copyright (c) 1992, 1993, 1994, 1995, 1996
7 * Keith Bostic. All rights reserved.
9 * See the LICENSE file for redistribution information.
15 static const char sccsid
[] = "Id: v_ch.c,v 10.10 2001/06/25 15:19:30 skimo Exp (Berkeley) Date: 2001/06/25 15:19:30";
18 #include <sys/types.h>
19 #include <sys/queue.h>
22 #include <bitstring.h>
27 #include "../common/common.h"
30 static void notfound
__P((SCR
*, ARG_CHAR_T
));
31 static void noprev
__P((SCR
*));
34 * v_chrepeat -- [count];
35 * Repeat the last F, f, T or t search.
37 * PUBLIC: int v_chrepeat __P((SCR *, VICMD *));
40 v_chrepeat(SCR
*sp
, VICMD
*vp
)
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 *));
69 v_chrrepeat(SCR
*sp
, VICMD
*vp
)
74 vp
->character
= VIP(sp
)->lastckey
;
75 savedir
= VIP(sp
)->csearchdir
;
77 switch (VIP(sp
)->csearchdir
) {
96 VIP(sp
)->csearchdir
= savedir
;
102 * Search forward in the line for the character before the next
103 * occurrence of the specified character.
105 * PUBLIC: int v_cht __P((SCR *, VICMD *));
108 v_cht(SCR
*sp
, VICMD
*vp
)
114 * v_chf places the cursor on the character, where the 't'
115 * command wants it to its left. We know this is safe since
116 * we had to move right for v_chf() to have succeeded.
121 * Make any necessary correction to the motion decision made
122 * by the v_chf routine.
125 vp
->m_final
= vp
->m_stop
;
127 VIP(sp
)->csearchdir
= tSEARCH
;
133 * Search forward in the line for the next occurrence of the
134 * specified character.
136 * PUBLIC: int v_chf __P((SCR *, VICMD *));
139 v_chf(SCR
*sp
, VICMD
*vp
)
144 CHAR_T
*endp
, *p
, *startp
;
148 * If it's a dot command, it doesn't reset the key for which we're
149 * searching, e.g. in "df1|f2|.|;", the ';' searches for a '2'.
152 if (!F_ISSET(vp
, VC_ISDOT
))
153 VIP(sp
)->lastckey
= key
;
154 VIP(sp
)->csearchdir
= fSEARCH
;
156 if (db_eget(sp
, vp
->m_start
.lno
, &p
, &len
, &isempty
)) {
163 empty
: notfound(sp
, key
);
167 endp
= (startp
= p
) + len
;
168 p
+= vp
->m_start
.cno
;
169 for (cnt
= F_ISSET(vp
, VC_C1SET
) ? vp
->count
: 1; cnt
--;) {
170 while (++p
< endp
&& *p
!= key
);
177 vp
->m_stop
.cno
= p
- startp
;
180 * Non-motion commands move to the end of the range.
181 * Delete and yank stay at the start, ignore others.
183 vp
->m_final
= ISMOTION(vp
) ? vp
->m_start
: vp
->m_stop
;
189 * Search backward in the line for the character after the next
190 * occurrence of the specified character.
192 * PUBLIC: int v_chT __P((SCR *, VICMD *));
195 v_chT(SCR
*sp
, VICMD
*vp
)
201 * v_chF places the cursor on the character, where the 'T'
202 * command wants it to its right. We know this is safe since
203 * we had to move left for v_chF() to have succeeded.
206 vp
->m_final
= vp
->m_stop
;
208 VIP(sp
)->csearchdir
= TSEARCH
;
214 * Search backward in the line for the next occurrence of the
215 * specified character.
217 * PUBLIC: int v_chF __P((SCR *, VICMD *));
220 v_chF(SCR
*sp
, VICMD
*vp
)
229 * If it's a dot command, it doesn't reset the key for which
230 * we're searching, e.g. in "df1|f2|.|;", the ';' searches
234 if (!F_ISSET(vp
, VC_ISDOT
))
235 VIP(sp
)->lastckey
= key
;
236 VIP(sp
)->csearchdir
= FSEARCH
;
238 if (db_eget(sp
, vp
->m_start
.lno
, &p
, &len
, &isempty
)) {
245 empty
: notfound(sp
, key
);
250 p
+= vp
->m_start
.cno
;
251 for (cnt
= F_ISSET(vp
, VC_C1SET
) ? vp
->count
: 1; cnt
--;) {
252 while (--p
> endp
&& *p
!= key
);
259 vp
->m_stop
.cno
= (p
- endp
) - 1;
262 * All commands move to the end of the range. Motion commands
263 * adjust the starting point to the character before the current
266 vp
->m_final
= vp
->m_stop
;
275 msgq(sp
, M_BERR
, "178|No previous F, f, T or t search");
279 notfound(SCR
*sp
, ARG_CHAR_T ch
)
281 msgq(sp
, M_BERR
, "179|%s not found", KEY_NAME(sp
, ch
));