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_ulcase.c,v 8.2 1993/11/04 09:16:58 bostic Exp $ (Berkeley) $Date: 1993/11/04 09:16:58 $";
12 #include <sys/types.h>
23 * v_ulcase -- [count]~
24 * Toggle upper & lower case letters.
27 * In historic vi, the count was ignored. It would have been better
28 * if there had been an associated motion, but it's too late to change
32 v_ulcase(sp
, ep
, vp
, fm
, tm
, rp
)
39 size_t blen
, lcnt
, len
;
44 /* Figure out what memory to use. */
45 GET_SPACE(sp
, bp
, blen
, 256);
49 * Historic vi didn't permit ~ to cross newline boundaries.
50 * I can think of no reason why it shouldn't, which at least
51 * lets you auto-repeat through a paragraph.
54 for (change
= -1, cnt
= F_ISSET(vp
, VC_C1SET
) ? vp
->count
: 1; cnt
;) {
55 /* Get the line; EOF is an infinite sink. */
56 if ((p
= file_gline(sp
, ep
, fm
->lno
, &len
)) == NULL
) {
57 if (file_lline(sp
, ep
, &lno
))
60 GETLINE_ERR(sp
, fm
->lno
);
71 /* Set current line number. */
74 /* Empty lines just decrement the count. */
83 /* Get a copy of the line. */
84 ADD_SPACE(sp
, bp
, blen
, len
);
87 /* Set starting pointer. */
94 * Figure out how many characters get changed in this
95 * line. Set the final cursor column.
97 if (fm
->cno
+ cnt
>= len
) {
102 fm
->cno
+= lcnt
= cnt
;
105 /* Change the line. */
106 for (change
= 0; lcnt
--; ++p
) {
111 } else if (isupper(ch
)) {
117 /* Update the line if necessary. */
118 if (change
&& file_sline(sp
, ep
, lno
, bp
, len
)) {
124 /* If changed lines, could be on an illegal line. */
125 if (fm
->lno
!= lno
&& file_gline(sp
, ep
, fm
->lno
, &len
) == NULL
) {
127 fm
->cno
= len
? len
- 1 : 0;
131 FREE_SPACE(sp
, bp
, blen
);