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
[] = "$Id: v_ch.c,v 10.11 2011/12/02 19:49:50 zy Exp $";
16 #include <sys/types.h>
17 #include <sys/queue.h>
20 #include <bitstring.h>
25 #include "../common/common.h"
28 static void notfound(SCR
*, ARG_CHAR_T
);
29 static void noprev(SCR
*);
32 * v_chrepeat -- [count];
33 * Repeat the last F, f, T or t search.
35 * PUBLIC: int v_chrepeat(SCR *, VICMD *);
38 v_chrepeat(SCR
*sp
, VICMD
*vp
)
40 vp
->character
= VIP(sp
)->lastckey
;
42 switch (VIP(sp
)->csearchdir
) {
47 return (v_chF(sp
, vp
));
49 return (v_chf(sp
, vp
));
51 return (v_chT(sp
, vp
));
53 return (v_cht(sp
, vp
));
61 * v_chrrepeat -- [count],
62 * Repeat the last F, f, T or t search in the reverse direction.
64 * PUBLIC: int v_chrrepeat(SCR *, VICMD *);
67 v_chrrepeat(SCR
*sp
, VICMD
*vp
)
72 vp
->character
= VIP(sp
)->lastckey
;
73 savedir
= VIP(sp
)->csearchdir
;
75 switch (VIP(sp
)->csearchdir
) {
94 VIP(sp
)->csearchdir
= savedir
;
100 * Search forward in the line for the character before the next
101 * occurrence of the specified character.
103 * PUBLIC: int v_cht(SCR *, VICMD *);
106 v_cht(SCR
*sp
, VICMD
*vp
)
112 * v_chf places the cursor on the character, where the 't'
113 * command wants it to its left. We know this is safe since
114 * we had to move right for v_chf() to have succeeded.
119 * Make any necessary correction to the motion decision made
120 * by the v_chf routine.
123 vp
->m_final
= vp
->m_stop
;
125 VIP(sp
)->csearchdir
= tSEARCH
;
131 * Search forward in the line for the next occurrence of the
132 * specified character.
134 * PUBLIC: int v_chf(SCR *, VICMD *);
137 v_chf(SCR
*sp
, VICMD
*vp
)
143 CHAR_T
*endp
, *p
, *startp
;
147 * If it's a dot command, it doesn't reset the key for which we're
148 * searching, e.g. in "df1|f2|.|;", the ';' searches for a '2'.
151 if (!F_ISSET(vp
, VC_ISDOT
))
152 VIP(sp
)->lastckey
= key
;
153 VIP(sp
)->csearchdir
= fSEARCH
;
155 if (db_eget(sp
, vp
->m_start
.lno
, &p
, &len
, &isempty
)) {
162 empty
: notfound(sp
, key
);
166 endp
= (startp
= p
) + len
;
167 p
+= vp
->m_start
.cno
;
168 for (cnt
= F_ISSET(vp
, VC_C1SET
) ? vp
->count
: 1; cnt
--;) {
169 while (++p
< endp
&& *p
!= key
);
176 vp
->m_stop
.cno
= p
- startp
;
179 * Non-motion commands move to the end of the range.
180 * Delete and yank stay at the start, ignore others.
182 vp
->m_final
= ISMOTION(vp
) ? vp
->m_start
: vp
->m_stop
;
188 * Search backward in the line for the character after the next
189 * occurrence of the specified character.
191 * PUBLIC: int v_chT(SCR *, VICMD *);
194 v_chT(SCR
*sp
, VICMD
*vp
)
200 * v_chF places the cursor on the character, where the 'T'
201 * command wants it to its right. We know this is safe since
202 * we had to move left for v_chF() to have succeeded.
205 vp
->m_final
= vp
->m_stop
;
207 VIP(sp
)->csearchdir
= TSEARCH
;
213 * Search backward in the line for the next occurrence of the
214 * specified character.
216 * PUBLIC: int v_chF(SCR *, VICMD *);
219 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
));