2 * The routines in this file
3 * deal with the region, that magic space
4 * between "." and mark. Some functions are
5 * commands. Some functions are just for
12 * Kill the region. Ask "getregion"
13 * to figure out the bounds of the region.
14 * Move "." to the start, and kill the characters.
24 if ((s
=getregion(®ion
)) != TRUE
)
26 if ((lastflag
&CFKILL
) == 0) /* This is a kill type */
27 kdelete(); /* command, so do magic */
28 thisflag
|= CFKILL
; /* kill buffer stuff. */
29 curwp
->w_dotp
= region
.r_linep
;
30 curwp
->w_doto
= region
.r_offset
;
31 return (ldelete(region
.r_size
, TRUE
));
35 * Copy all of the characters in the
36 * region to the kill buffer. Don't move dot
37 * at all. This is a bit like a kill region followed
38 * by a yank. Bound to "M-W".
49 if ((s
=getregion(®ion
)) != TRUE
)
51 if ((lastflag
&CFKILL
) == 0) /* Kill type command. */
54 linep
= region
.r_linep
; /* Current line. */
55 loffs
= region
.r_offset
; /* Current offset. */
56 while (region
.r_size
--) {
57 if (loffs
== llength(linep
)) { /* End of line. */
58 if ((s
=kinsert('\n')) != TRUE
)
62 } else { /* Middle of line. */
63 if ((s
=kinsert(lgetc(linep
, loffs
))) != TRUE
)
72 * Lower case region. Zap all of the upper
73 * case characters in the region to lower case. Use
74 * the region code to set the limits. Scan the buffer,
75 * doing the changes. Call "lchange" to ensure that
76 * redisplay is done in all buffers. Bound to
89 if ((s
=getregion(®ion
)) != TRUE
)
92 linep
= region
.r_linep
;
93 loffs
= region
.r_offset
;
94 while (region
.r_size
--) {
95 if (loffs
== llength(linep
)) {
99 c
= lgetc(linep
, loffs
);
100 if (c
>='A' && c
<='Z')
101 lputc(linep
, loffs
, c
+'a'-'A');
109 * Upper case region. Zap all of the lower
110 * case characters in the region to upper case. Use
111 * the region code to set the limits. Scan the buffer,
112 * doing the changes. Call "lchange" to ensure that
113 * redisplay is done in all buffers. Bound to
116 int upperregion(f
, n
)
120 register LINE
*linep
;
126 if ((s
=getregion(®ion
)) != TRUE
)
129 linep
= region
.r_linep
;
130 loffs
= region
.r_offset
;
131 while (region
.r_size
--) {
132 if (loffs
== llength(linep
)) {
133 linep
= lforw(linep
);
136 c
= lgetc(linep
, loffs
);
137 if (c
>='a' && c
<='z')
138 lputc(linep
, loffs
, c
-'a'+'A');
146 * This routine figures out the
147 * bounds of the region in the current window, and
148 * fills in the fields of the "REGION" structure pointed
149 * to by "rp". Because the dot and mark are usually very
150 * close together, we scan outward from dot looking for
151 * mark. This should save time. Return a standard code.
152 * Callers of this routine should be prepared to get
153 * an "ABORT" status; we might make this have the
154 * conform thing later.
164 if (curwp
->w_markp
== NULL
) {
165 mlwrite("No mark set in this window");
168 if (curwp
->w_dotp
== curwp
->w_markp
) {
169 rp
->r_linep
= curwp
->w_dotp
;
170 if (curwp
->w_doto
< curwp
->w_marko
) {
171 rp
->r_offset
= curwp
->w_doto
;
172 rp
->r_size
= curwp
->w_marko
-curwp
->w_doto
;
174 rp
->r_offset
= curwp
->w_marko
;
175 rp
->r_size
= curwp
->w_doto
-curwp
->w_marko
;
180 bsize
= curwp
->w_doto
;
182 fsize
= llength(flp
)-curwp
->w_doto
+1;
183 while (flp
!=curbp
->b_linep
|| lback(blp
)!=curbp
->b_linep
) {
184 if (flp
!= curbp
->b_linep
) {
186 if (flp
== curwp
->w_markp
) {
187 rp
->r_linep
= curwp
->w_dotp
;
188 rp
->r_offset
= curwp
->w_doto
;
189 rp
->r_size
= fsize
+curwp
->w_marko
;
192 fsize
+= llength(flp
)+1;
194 if (lback(blp
) != curbp
->b_linep
) {
196 bsize
+= llength(blp
)+1;
197 if (blp
== curwp
->w_markp
) {
199 rp
->r_offset
= curwp
->w_marko
;
200 rp
->r_size
= bsize
- curwp
->w_marko
;
205 mlwrite("Bug: lost mark");