2 * Copyright (c) 1992, 1993
3 * The Regents of the University of California. All rights reserved.
5 * %sccs.include.redist.c%
9 static char sccsid
[] = "$Id: v_ch.c,v 8.2 1993/12/20 12:23:03 bostic Exp $ (Berkeley) $Date: 1993/12/20 12:23:03 $";
12 #include <sys/types.h>
20 msgq(sp, M_BERR, "No previous F, f, T or t search."); \
24 #define NOTFOUND(ch) { \
25 msgq(sp, M_BERR, "%s not found.", charname(sp, ch)); \
30 * v_chrepeat -- [count];
31 * Repeat the last F, f, T or t search.
34 v_chrepeat(sp
, ep
, vp
, fm
, tm
, rp
)
40 vp
->character
= sp
->lastckey
;
42 switch (sp
->csearchdir
) {
46 return (v_chF(sp
, ep
, vp
, fm
, tm
, rp
));
48 return (v_chf(sp
, ep
, vp
, fm
, tm
, rp
));
50 return (v_chT(sp
, ep
, vp
, fm
, tm
, rp
));
52 return (v_cht(sp
, ep
, vp
, fm
, tm
, rp
));
60 * v_chrrepeat -- [count],
61 * Repeat the last F, f, T or t search in the reverse direction.
64 v_chrrepeat(sp
, ep
, vp
, fm
, tm
, rp
)
71 enum cdirection savedir
;
73 vp
->character
= sp
->lastckey
;
74 savedir
= sp
->csearchdir
;
76 switch (sp
->csearchdir
) {
80 rval
= v_chf(sp
, ep
, vp
, fm
, tm
, rp
);
83 rval
= v_chF(sp
, ep
, vp
, fm
, tm
, rp
);
86 rval
= v_cht(sp
, ep
, vp
, fm
, tm
, rp
);
89 rval
= v_chT(sp
, ep
, vp
, fm
, tm
, rp
);
94 sp
->csearchdir
= savedir
;
100 * Search forward in the line for the next occurrence of the character.
101 * Place the cursor on it if a motion command, to its left if its not.
104 v_cht(sp
, ep
, vp
, fm
, tm
, rp
)
112 rval
= v_chf(sp
, ep
, vp
, fm
, tm
, rp
);
114 --rp
->cno
; /* XXX: Motion interaction with v_chf. */
115 sp
->csearchdir
= tSEARCH
;
121 * Search forward in the line for the next occurrence of the character.
122 * Place the cursor to its right if a motion command, on it if its not.
125 v_chf(sp
, ep
, vp
, fm
, tm
, rp
)
135 char *endp
, *p
, *startp
;
139 * If it's a dot command, it doesn't reset the key for which
140 * we're searching, e.g. in "df1|f2|.|;", the ';' searches
144 if (!F_ISSET(vp
, VC_ISDOT
))
146 sp
->csearchdir
= fSEARCH
;
148 if ((p
= file_gline(sp
, ep
, fm
->lno
, &len
)) == NULL
) {
149 if (file_lline(sp
, ep
, &lno
))
153 GETLINE_ERR(sp
, fm
->lno
);
163 for (cnt
= F_ISSET(vp
, VC_C1SET
) ? vp
->count
: 1; cnt
--;) {
164 while (++p
< endp
&& *p
!= key
);
169 rp
->cno
= p
- startp
;
170 if (F_ISSET(vp
, VC_C
| VC_D
| VC_Y
))
177 * Search backward in the line for the next occurrence of the character.
178 * Place the cursor to its right.
181 v_chT(sp
, ep
, vp
, fm
, tm
, rp
)
189 rval
= v_chF(sp
, ep
, vp
, fm
, tm
, rp
);
192 sp
->csearchdir
= TSEARCH
;
198 * Search backward in the line for the next occurrence of the character.
199 * Place the cursor on it.
202 v_chF(sp
, ep
, vp
, fm
, tm
, rp
)
216 * If it's a dot command, it doesn't reset the key for which
217 * we're searching, e.g. in "df1|f2|.|;", the ';' searches
221 if (!F_ISSET(vp
, VC_ISDOT
))
223 sp
->csearchdir
= FSEARCH
;
225 if ((p
= file_gline(sp
, ep
, fm
->lno
, &len
)) == NULL
) {
226 if (file_lline(sp
, ep
, &lno
))
230 GETLINE_ERR(sp
, fm
->lno
);
239 for (cnt
= F_ISSET(vp
, VC_C1SET
) ? vp
->count
: 1; cnt
--;) {
240 while (--p
> endp
&& *p
!= key
);
245 rp
->cno
= (p
- endp
) - 1;