1 /* $NetBSD: v_ch.c,v 1.3 2014/01/26 21:43:45 christos Exp $ */
3 * Copyright (c) 1992, 1993, 1994
4 * The Regents of the University of California. All rights reserved.
5 * Copyright (c) 1992, 1993, 1994, 1995, 1996
6 * Keith Bostic. All rights reserved.
8 * See the LICENSE file for redistribution information.
13 #include <sys/cdefs.h>
16 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 ";
19 __RCSID("$NetBSD: v_ch.c,v 1.3 2014/01/26 21:43:45 christos Exp $");
22 #include <sys/types.h>
23 #include <sys/queue.h>
26 #include <bitstring.h>
31 #include "../common/common.h"
34 static void notfound
__P((SCR
*, ARG_CHAR_T
));
35 static void noprev
__P((SCR
*));
38 * v_chrepeat -- [count];
39 * Repeat the last F, f, T or t search.
41 * PUBLIC: int v_chrepeat __P((SCR *, VICMD *));
44 v_chrepeat(SCR
*sp
, VICMD
*vp
)
46 vp
->character
= VIP(sp
)->lastckey
;
48 switch (VIP(sp
)->csearchdir
) {
53 return (v_chF(sp
, vp
));
55 return (v_chf(sp
, vp
));
57 return (v_chT(sp
, vp
));
59 return (v_cht(sp
, vp
));
67 * v_chrrepeat -- [count],
68 * Repeat the last F, f, T or t search in the reverse direction.
70 * PUBLIC: int v_chrrepeat __P((SCR *, VICMD *));
73 v_chrrepeat(SCR
*sp
, VICMD
*vp
)
78 vp
->character
= VIP(sp
)->lastckey
;
79 savedir
= VIP(sp
)->csearchdir
;
81 switch (VIP(sp
)->csearchdir
) {
100 VIP(sp
)->csearchdir
= savedir
;
106 * Search forward in the line for the character before the next
107 * occurrence of the specified character.
109 * PUBLIC: int v_cht __P((SCR *, VICMD *));
112 v_cht(SCR
*sp
, VICMD
*vp
)
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 *));
143 v_chf(SCR
*sp
, VICMD
*vp
)
149 CHAR_T
*endp
, *p
, *startp
;
153 * If it's a dot command, it doesn't reset the key for which we're
154 * searching, e.g. in "df1|f2|.|;", the ';' searches for a '2'.
157 if (!F_ISSET(vp
, VC_ISDOT
))
158 VIP(sp
)->lastckey
= key
;
159 VIP(sp
)->csearchdir
= fSEARCH
;
161 if (db_eget(sp
, vp
->m_start
.lno
, &p
, &len
, &isempty
)) {
168 empty
: notfound(sp
, key
);
172 endp
= (startp
= p
) + len
;
173 p
+= vp
->m_start
.cno
;
174 for (cnt
= F_ISSET(vp
, VC_C1SET
) ? vp
->count
: 1; cnt
--;) {
175 while (++p
< endp
&& *p
!= key
);
182 vp
->m_stop
.cno
= p
- startp
;
185 * Non-motion commands move to the end of the range.
186 * Delete and yank stay at the start, ignore others.
188 vp
->m_final
= ISMOTION(vp
) ? vp
->m_start
: vp
->m_stop
;
194 * Search backward in the line for the character after the next
195 * occurrence of the specified character.
197 * PUBLIC: int v_chT __P((SCR *, VICMD *));
200 v_chT(SCR
*sp
, VICMD
*vp
)
206 * v_chF places the cursor on the character, where the 'T'
207 * command wants it to its right. We know this is safe since
208 * we had to move left for v_chF() to have succeeded.
211 vp
->m_final
= vp
->m_stop
;
213 VIP(sp
)->csearchdir
= TSEARCH
;
219 * Search backward in the line for the next occurrence of the
220 * specified character.
222 * PUBLIC: int v_chF __P((SCR *, VICMD *));
225 v_chF(SCR
*sp
, VICMD
*vp
)
235 * If it's a dot command, it doesn't reset the key for which
236 * we're searching, e.g. in "df1|f2|.|;", the ';' searches
240 if (!F_ISSET(vp
, VC_ISDOT
))
241 VIP(sp
)->lastckey
= key
;
242 VIP(sp
)->csearchdir
= FSEARCH
;
244 if (db_eget(sp
, vp
->m_start
.lno
, &p
, &len
, &isempty
)) {
251 empty
: notfound(sp
, key
);
256 p
+= vp
->m_start
.cno
;
257 for (cnt
= F_ISSET(vp
, VC_C1SET
) ? vp
->count
: 1; cnt
--;) {
258 while (--p
> endp
&& *p
!= key
);
265 vp
->m_stop
.cno
= (p
- endp
) - 1;
268 * All commands move to the end of the range. Motion commands
269 * adjust the starting point to the character before the current
272 vp
->m_final
= vp
->m_stop
;
281 msgq(sp
, M_BERR
, "178|No previous F, f, T or t search");
285 notfound(SCR
*sp
, ARG_CHAR_T ch
)
287 msgq(sp
, M_BERR
, "179|%s not found", KEY_NAME(sp
, ch
));