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.
12 #include <sys/types.h>
13 #include <sys/queue.h>
16 #include <bitstring.h>
24 #include "../common/common.h"
27 static int ulcase(SCR *, recno_t, CHAR_T *, size_t, size_t, size_t);
30 * v_ulcase -- [count]~
31 * Toggle upper & lower case letters.
34 * Historic vi didn't permit ~ to cross newline boundaries. I can
35 * think of no reason why it shouldn't, which at least lets the user
36 * auto-repeat through a paragraph.
39 * In historic vi, the count was ignored. It would have been better
40 * if there had been an associated motion, but it's too late to make
41 * that the default now.
43 * PUBLIC: int v_ulcase(SCR *, VICMD *);
46 v_ulcase(SCR *sp, VICMD *vp)
49 size_t cno, lcnt, len;
53 lno = vp->m_start.lno;
54 cno = vp->m_start.cno;
56 for (cnt = F_ISSET(vp, VC_C1SET) ? vp->count : 1; cnt > 0; cno = 0) {
57 /* SOF is an error, EOF is an infinite count sink. */
58 if (db_get(sp, lno, 0, &p, &len)) {
60 v_emsg(sp, NULL, VIM_EMPTY);
67 /* Empty lines decrement the count by one. */
74 if (cno + cnt >= len) {
78 vp->m_final.cno = len - 1;
83 vp->m_final.cno = lcnt + 1;
86 if (ulcase(sp, lno, p, len, cno, lcnt))
93 vp->m_final.lno = lno;
98 * v_mulcase -- [count]~[count]motion
99 * Toggle upper & lower case letters over a range.
101 * PUBLIC: int v_mulcase(SCR *, VICMD *);
104 v_mulcase(SCR *sp, VICMD *vp)
110 for (lno = vp->m_start.lno;;) {
111 if (db_get(sp, lno, DBG_FATAL, &p, &len))
113 if (len != 0 && ulcase(sp, lno, p, len,
114 lno == vp->m_start.lno ? vp->m_start.cno : 0,
115 !F_ISSET(vp, VM_LMODE) &&
116 lno == vp->m_stop.lno ? vp->m_stop.cno : len))
119 if (++lno > vp->m_stop.lno)
125 * I didn't create a new motion command when I added motion semantics
126 * for ~. While that's the correct way to do it, that choice would
127 * have required changes all over the vi directory for little gain.
128 * Instead, we pretend it's a yank command. Note, this means that we
129 * follow the cursor motion rules for yank commands, but that seems
137 * Change part of a line's case.
140 ulcase(SCR *sp, recno_t lno, CHAR_T *lp, size_t len, size_t scno, size_t ecno)
147 GET_SPACE_RETW(sp, bp, blen, len);
148 MEMMOVE(bp, lp, len);
151 for (p = bp + scno, t = bp + ecno + 1; p < t; ++p) {
156 } else if (ISUPPER(ch)) {
162 if (change && db_set(sp, lno, bp, len))
165 FREE_SPACEW(sp, bp, blen);