995
|
1 /*
|
|
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
|
|
6 * internal use.
|
|
7 */
|
|
8 #include <stdio.h>
|
|
9 #include "ueed.h"
|
|
10
|
|
11 /*
|
|
12 * Kill the region. Ask "getregion"
|
|
13 * to figure out the bounds of the region.
|
|
14 * Move "." to the start, and kill the characters.
|
|
15 * Bound to "C-W".
|
|
16 */
|
|
17 killregion(f, n)
|
|
18 {
|
|
19 register int s;
|
|
20 REGION region;
|
|
21
|
|
22 if ((s=getregion(®ion)) != TRUE)
|
|
23 return (s);
|
|
24 if ((lastflag&CFKILL) == 0) /* This is a kill type */
|
|
25 kdelete(); /* command, so do magic */
|
|
26 thisflag |= CFKILL; /* kill buffer stuff. */
|
|
27 curwp->w_dotp = region.r_linep;
|
|
28 curwp->w_doto = region.r_offset;
|
|
29 return (ldelete(region.r_size, TRUE));
|
|
30 }
|
|
31
|
|
32 /*
|
|
33 * Copy all of the characters in the
|
|
34 * region to the kill buffer. Don't move dot
|
|
35 * at all. This is a bit like a kill region followed
|
|
36 * by a yank. Bound to "M-W".
|
|
37 */
|
|
38 copyregion(f, n)
|
|
39 {
|
|
40 register LINE *linep;
|
|
41 register int loffs;
|
|
42 register int s;
|
|
43 REGION region;
|
|
44
|
|
45 if ((s=getregion(®ion)) != TRUE)
|
|
46 return (s);
|
|
47 if ((lastflag&CFKILL) == 0) /* Kill type command. */
|
|
48 kdelete();
|
|
49 thisflag |= CFKILL;
|
|
50 linep = region.r_linep; /* Current line. */
|
|
51 loffs = region.r_offset; /* Current offset. */
|
|
52 while (region.r_size--) {
|
|
53 if (loffs == llength(linep)) { /* End of line. */
|
|
54 if ((s=kinsert('\n')) != TRUE)
|
|
55 return (s);
|
|
56 linep = lforw(linep);
|
|
57 loffs = 0;
|
|
58 } else { /* Middle of line. */
|
|
59 if ((s=kinsert(lgetc(linep, loffs))) != TRUE)
|
|
60 return (s);
|
|
61 ++loffs;
|
|
62 }
|
|
63 }
|
|
64 return (TRUE);
|
|
65 }
|
|
66
|
|
67 /*
|
|
68 * Lower case region. Zap all of the upper
|
|
69 * case characters in the region to lower case. Use
|
|
70 * the region code to set the limits. Scan the buffer,
|
|
71 * doing the changes. Call "lchange" to ensure that
|
|
72 * redisplay is done in all buffers. Bound to
|
|
73 * "C-X C-L".
|
|
74 */
|
|
75 lowerregion(f, n)
|
|
76 {
|
|
77 register LINE *linep;
|
|
78 register int loffs;
|
|
79 register int c;
|
|
80 register int s;
|
|
81 REGION region;
|
|
82
|
|
83 if ((s=getregion(®ion)) != TRUE)
|
|
84 return (s);
|
|
85 lchange(WFHARD);
|
|
86 linep = region.r_linep;
|
|
87 loffs = region.r_offset;
|
|
88 while (region.r_size--) {
|
|
89 if (loffs == llength(linep)) {
|
|
90 linep = lforw(linep);
|
|
91 loffs = 0;
|
|
92 } else {
|
|
93 c = lgetc(linep, loffs);
|
|
94 if (c>='A' && c<='Z')
|
|
95 lputc(linep, loffs, c+'a'-'A');
|
|
96 ++loffs;
|
|
97 }
|
|
98 }
|
|
99 return (TRUE);
|
|
100 }
|
|
101
|
|
102 /*
|
|
103 * Upper case region. Zap all of the lower
|
|
104 * case characters in the region to upper case. Use
|
|
105 * the region code to set the limits. Scan the buffer,
|
|
106 * doing the changes. Call "lchange" to ensure that
|
|
107 * redisplay is done in all buffers. Bound to
|
|
108 * "C-X C-L".
|
|
109 */
|
|
110 upperregion(f, n)
|
|
111 {
|
|
112 register LINE *linep;
|
|
113 register int loffs;
|
|
114 register int c;
|
|
115 register int s;
|
|
116 REGION region;
|
|
117
|
|
118 if ((s=getregion(®ion)) != TRUE)
|
|
119 return (s);
|
|
120 lchange(WFHARD);
|
|
121 linep = region.r_linep;
|
|
122 loffs = region.r_offset;
|
|
123 while (region.r_size--) {
|
|
124 if (loffs == llength(linep)) {
|
|
125 linep = lforw(linep);
|
|
126 loffs = 0;
|
|
127 } else {
|
|
128 c = lgetc(linep, loffs);
|
|
129 if (c>='a' && c<='z')
|
|
130 lputc(linep, loffs, c-'a'+'A');
|
|
131 ++loffs;
|
|
132 }
|
|
133 }
|
|
134 return (TRUE);
|
|
135 }
|
|
136
|
|
137 /*
|
|
138 * This routine figures out the
|
|
139 * bounds of the region in the current window, and
|
|
140 * fills in the fields of the "REGION" structure pointed
|
|
141 * to by "rp". Because the dot and mark are usually very
|
|
142 * close together, we scan outward from dot looking for
|
|
143 * mark. This should save time. Return a standard code.
|
|
144 * Callers of this routine should be prepared to get
|
|
145 * an "ABORT" status; we might make this have the
|
|
146 * conform thing later.
|
|
147 */
|
|
148 getregion(rp)
|
|
149 register REGION *rp;
|
|
150 {
|
|
151 register LINE *flp;
|
|
152 register LINE *blp;
|
|
153 register int fsize;
|
|
154 register int bsize;
|
|
155
|
|
156 if (curwp->w_markp == NULL) {
|
|
157 mlwrite("No mark set in this window");
|
|
158 return (FALSE);
|
|
159 }
|
|
160 if (curwp->w_dotp == curwp->w_markp) {
|
|
161 rp->r_linep = curwp->w_dotp;
|
|
162 if (curwp->w_doto < curwp->w_marko) {
|
|
163 rp->r_offset = curwp->w_doto;
|
|
164 rp->r_size = curwp->w_marko-curwp->w_doto;
|
|
165 } else {
|
|
166 rp->r_offset = curwp->w_marko;
|
|
167 rp->r_size = curwp->w_doto-curwp->w_marko;
|
|
168 }
|
|
169 return (TRUE);
|
|
170 }
|
|
171 blp = curwp->w_dotp;
|
|
172 bsize = curwp->w_doto;
|
|
173 flp = curwp->w_dotp;
|
|
174 fsize = llength(flp)-curwp->w_doto+1;
|
|
175 while (flp!=curbp->b_linep || lback(blp)!=curbp->b_linep) {
|
|
176 if (flp != curbp->b_linep) {
|
|
177 flp = lforw(flp);
|
|
178 if (flp == curwp->w_markp) {
|
|
179 rp->r_linep = curwp->w_dotp;
|
|
180 rp->r_offset = curwp->w_doto;
|
|
181 rp->r_size = fsize+curwp->w_marko;
|
|
182 return (TRUE);
|
|
183 }
|
|
184 fsize += llength(flp)+1;
|
|
185 }
|
|
186 if (lback(blp) != curbp->b_linep) {
|
|
187 blp = lback(blp);
|
|
188 bsize += llength(blp)+1;
|
|
189 if (blp == curwp->w_markp) {
|
|
190 rp->r_linep = blp;
|
|
191 rp->r_offset = curwp->w_marko;
|
|
192 rp->r_size = bsize - curwp->w_marko;
|
|
193 return (TRUE);
|
|
194 }
|
|
195 }
|
|
196 }
|
|
197 mlwrite("Bug: lost mark");
|
|
198 return (FALSE);
|
|
199 }
|
|
200
|
|
201
|