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_ulcase.c,v 10.10 2000/07/15 20:26:36 skimo Exp $ (Berkeley) $Date: 2000/07/15 20:26:36 $";
16 #include <sys/types.h>
17 #include <sys/queue.h>
20 #include <bitstring.h>
28 #include "../common/common.h"
31 static int ulcase
__P((SCR
*, db_recno_t
, CHAR_T
*, size_t, size_t, size_t));
34 * v_ulcase -- [count]~
35 * Toggle upper & lower case letters.
38 * Historic vi didn't permit ~ to cross newline boundaries. I can
39 * think of no reason why it shouldn't, which at least lets the user
40 * auto-repeat through a paragraph.
43 * In historic vi, the count was ignored. It would have been better
44 * if there had been an associated motion, but it's too late to make
45 * that the default now.
47 * PUBLIC: int v_ulcase __P((SCR *, VICMD *));
55 size_t cno
, lcnt
, len
;
59 lno
= vp
->m_start
.lno
;
60 cno
= vp
->m_start
.cno
;
62 for (cnt
= F_ISSET(vp
, VC_C1SET
) ? vp
->count
: 1; cnt
> 0; cno
= 0) {
63 /* SOF is an error, EOF is an infinite count sink. */
64 if (db_get(sp
, lno
, 0, &p
, &len
)) {
66 v_emsg(sp
, NULL
, VIM_EMPTY
);
73 /* Empty lines decrement the count by one. */
80 if (cno
+ cnt
>= len
) {
84 vp
->m_final
.cno
= len
- 1;
89 vp
->m_final
.cno
= lcnt
+ 1;
92 if (ulcase(sp
, lno
, p
, len
, cno
, lcnt
))
99 vp
->m_final
.lno
= lno
;
104 * v_mulcase -- [count]~[count]motion
105 * Toggle upper & lower case letters over a range.
107 * PUBLIC: int v_mulcase __P((SCR *, VICMD *));
118 for (lno
= vp
->m_start
.lno
;;) {
119 if (db_get(sp
, lno
, DBG_FATAL
, &p
, &len
))
121 if (len
!= 0 && ulcase(sp
, lno
, p
, len
,
122 lno
== vp
->m_start
.lno
? vp
->m_start
.cno
: 0,
123 !F_ISSET(vp
, VM_LMODE
) &&
124 lno
== vp
->m_stop
.lno
? vp
->m_stop
.cno
: len
))
127 if (++lno
> vp
->m_stop
.lno
)
133 * I didn't create a new motion command when I added motion semantics
134 * for ~. While that's the correct way to do it, that choice would
135 * have required changes all over the vi directory for little gain.
136 * Instead, we pretend it's a yank command. Note, this means that we
137 * follow the cursor motion rules for yank commands, but that seems
145 * Change part of a line's case.
148 ulcase(sp
, lno
, lp
, len
, scno
, ecno
)
152 size_t len
, scno
, ecno
;
159 GET_SPACE_RETW(sp
, bp
, blen
, len
);
160 MEMMOVEW(bp
, lp
, len
);
163 for (p
= bp
+ scno
, t
= bp
+ ecno
+ 1; p
< t
; ++p
) {
168 } else if (isupper(ch
)) {
174 if (change
&& db_set(sp
, lno
, bp
, len
))
177 FREE_SPACEW(sp
, bp
, blen
);