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.12 2011/12/02 19:58:32 zy Exp $";
16 #include <sys/types.h>
17 #include <sys/queue.h>
20 #include <bitstring.h>
28 #include "../common/common.h"
31 static int ulcase(SCR *, 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(SCR *, VICMD *);
50 v_ulcase(SCR *sp, VICMD *vp)
53 size_t cno, lcnt, len;
57 lno = vp->m_start.lno;
58 cno = vp->m_start.cno;
60 for (cnt = F_ISSET(vp, VC_C1SET) ? vp->count : 1; cnt > 0; cno = 0) {
61 /* SOF is an error, EOF is an infinite count sink. */
62 if (db_get(sp, lno, 0, &p, &len)) {
64 v_emsg(sp, NULL, VIM_EMPTY);
71 /* Empty lines decrement the count by one. */
78 if (cno + cnt >= len) {
82 vp->m_final.cno = len - 1;
87 vp->m_final.cno = lcnt + 1;
90 if (ulcase(sp, lno, p, len, cno, lcnt))
97 vp->m_final.lno = lno;
102 * v_mulcase -- [count]~[count]motion
103 * Toggle upper & lower case letters over a range.
105 * PUBLIC: int v_mulcase(SCR *, VICMD *);
108 v_mulcase(SCR *sp, VICMD *vp)
114 for (lno = vp->m_start.lno;;) {
115 if (db_get(sp, lno, DBG_FATAL, &p, &len))
117 if (len != 0 && ulcase(sp, lno, p, len,
118 lno == vp->m_start.lno ? vp->m_start.cno : 0,
119 !F_ISSET(vp, VM_LMODE) &&
120 lno == vp->m_stop.lno ? vp->m_stop.cno : len))
123 if (++lno > vp->m_stop.lno)
129 * I didn't create a new motion command when I added motion semantics
130 * for ~. While that's the correct way to do it, that choice would
131 * have required changes all over the vi directory for little gain.
132 * Instead, we pretend it's a yank command. Note, this means that we
133 * follow the cursor motion rules for yank commands, but that seems
141 * Change part of a line's case.
144 ulcase(SCR *sp, recno_t lno, CHAR_T *lp, size_t len, size_t scno, size_t ecno)
151 GET_SPACE_RETW(sp, bp, blen, len);
152 MEMMOVE(bp, lp, len);
155 for (p = bp + scno, t = bp + ecno + 1; p < t; ++p) {
160 } else if (ISUPPER(ch)) {
166 if (change && db_set(sp, lno, bp, len))
169 FREE_SPACEW(sp, bp, blen);