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.1 1993/06/09 22:26:44 bostic Exp $ (Berkeley) $Date: 1993/06/09 22:26:44 $";
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, or to its left if 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 it's right if a motion command, or on it if not.
125 v_chf(sp
, ep
, vp
, fm
, tm
, rp
)
132 register char *endp
, *p
;
138 sp
->csearchdir
= fSEARCH
;
139 sp
->lastckey
= key
= vp
->character
;
141 if ((p
= file_gline(sp
, ep
, fm
->lno
, &len
)) == NULL
) {
142 if (file_lline(sp
, ep
, &lno
))
146 GETLINE_ERR(sp
, fm
->lno
);
156 for (cnt
= F_ISSET(vp
, VC_C1SET
) ? vp
->count
: 1; cnt
--;) {
157 while (++p
< endp
&& *p
!= key
);
162 rp
->cno
= p
- startp
;
163 if (F_ISSET(vp
, VC_C
| VC_D
| VC_Y
))
170 * Search backward in the line for the next occurrence of the character.
171 * Place the cursor to its right.
174 v_chT(sp
, ep
, vp
, fm
, tm
, rp
)
182 rval
= v_chF(sp
, ep
, vp
, fm
, tm
, rp
);
185 sp
->csearchdir
= TSEARCH
;
191 * Search backward in the line for the next occurrence of the character.
192 * Place the cursor on it.
195 v_chF(sp
, ep
, vp
, fm
, tm
, rp
)
202 register char *p
, *endp
;
207 sp
->csearchdir
= FSEARCH
;
208 sp
->lastckey
= key
= vp
->character
;
210 if ((p
= file_gline(sp
, ep
, fm
->lno
, &len
)) == NULL
) {
211 if (file_lline(sp
, ep
, &lno
))
215 GETLINE_ERR(sp
, fm
->lno
);
224 for (cnt
= F_ISSET(vp
, VC_C1SET
) ? vp
->count
: 1; cnt
--;) {
225 while (--p
> endp
&& *p
!= key
);
230 rp
->cno
= (p
- endp
) - 1;