995
|
1 /*
|
|
2 * The routines in this file implement commands that work word at a time.
|
|
3 * There are all sorts of word mode commands. If I do any sentence and/or
|
|
4 * paragraph mode commands, they are likely to be put in this file.
|
|
5 */
|
|
6
|
|
7 #include <stdio.h>
|
|
8 #include "ueed.h"
|
|
9
|
|
10
|
|
11 /* Word wrap on n-spaces. Back-over whatever precedes the point on the current
|
|
12 * line and stop on the first word-break or the beginning of the line. If we
|
|
13 * reach the beginning of the line, jump back to the end of the word and start
|
|
14 * a new line. Otherwise, break the line at the word-break, eat it, and jump
|
|
15 * back to the end of the word.
|
|
16 * NOTE: This function may leaving trailing blanks.
|
|
17 * Returns TRUE on success, FALSE on errors.
|
|
18 */
|
|
19 wrapword(n)
|
|
20 int n;
|
|
21 {
|
|
22 register int cnt, oldp;
|
|
23 oldp = curwp->w_dotp;
|
|
24 cnt = -1;
|
|
25 do {
|
|
26 cnt++;
|
|
27 if (! backchar(NULL, 1))
|
|
28 return(FALSE);
|
|
29 }
|
|
30 while (! inword());
|
|
31 if (! backword(NULL, 1))
|
|
32 return(FALSE);
|
|
33 if (oldp == (int) (curwp->w_dotp && curwp->w_doto)) {
|
|
34 if (! backdel(NULL, 1))
|
|
35 return(FALSE);
|
|
36 if (! newline(NULL, 1))
|
|
37 return(FALSE);
|
|
38 }
|
|
39 return(forwword(NULL, 1) && forwchar(NULL, cnt));
|
|
40 }
|
|
41
|
|
42 /*
|
|
43 * Move the cursor backward by "n" words. All of the details of motion are
|
|
44 * performed by the "backchar" and "forwchar" routines. Error if you try to
|
|
45 * move beyond the buffers.
|
|
46 */
|
|
47 backword(f, n)
|
|
48 {
|
|
49 if (n < 0)
|
|
50 return (forwword(f, -n));
|
|
51 if (backchar(FALSE, 1) == FALSE)
|
|
52 return (FALSE);
|
|
53 while (n--) {
|
|
54 while (inword() == FALSE) {
|
|
55 if (backchar(FALSE, 1) == FALSE)
|
|
56 return (FALSE);
|
|
57 }
|
|
58 while (inword() != FALSE) {
|
|
59 if (backchar(FALSE, 1) == FALSE)
|
|
60 return (FALSE);
|
|
61 }
|
|
62 }
|
|
63 return (forwchar(FALSE, 1));
|
|
64 }
|
|
65
|
|
66 /*
|
|
67 * Move the cursor forward by the specified number of words. All of the motion
|
|
68 * is done by "forwchar". Error if you try and move beyond the buffer's end.
|
|
69 */
|
|
70 forwword(f, n)
|
|
71 {
|
|
72 if (n < 0)
|
|
73 return (backword(f, -n));
|
|
74 while (n--) {
|
|
75 while (inword() == FALSE) {
|
|
76 if (forwchar(FALSE, 1) == FALSE)
|
|
77 return (FALSE);
|
|
78 }
|
|
79 while (inword() != FALSE) {
|
|
80 if (forwchar(FALSE, 1) == FALSE)
|
|
81 return (FALSE);
|
|
82 }
|
|
83 }
|
|
84 return (TRUE);
|
|
85 }
|
|
86
|
|
87 /*
|
|
88 * Move the cursor forward by the specified number of words. As you move,
|
|
89 * convert any characters to upper case. Error if you try and move beyond the
|
|
90 * end of the buffer. Bound to "M-U".
|
|
91 */
|
|
92 upperword(f, n)
|
|
93 {
|
|
94 register int c;
|
|
95
|
|
96 if (n < 0)
|
|
97 return (FALSE);
|
|
98 while (n--) {
|
|
99 while (inword() == FALSE) {
|
|
100 if (forwchar(FALSE, 1) == FALSE)
|
|
101 return (FALSE);
|
|
102 }
|
|
103 while (inword() != FALSE) {
|
|
104 c = lgetc(curwp->w_dotp, curwp->w_doto);
|
|
105 if (c>='a' && c<='z') {
|
|
106 c -= 'a'-'A';
|
|
107 lputc(curwp->w_dotp, curwp->w_doto, c);
|
|
108 lchange(WFHARD);
|
|
109 }
|
|
110 if (forwchar(FALSE, 1) == FALSE)
|
|
111 return (FALSE);
|
|
112 }
|
|
113 }
|
|
114 return (TRUE);
|
|
115 }
|
|
116
|
|
117 /*
|
|
118 * Move the cursor forward by the specified number of words. As you move
|
|
119 * convert characters to lower case. Error if you try and move over the end of
|
|
120 * the buffer. Bound to "M-L".
|
|
121 */
|
|
122 lowerword(f, n)
|
|
123 {
|
|
124 register int c;
|
|
125
|
|
126 if (n < 0)
|
|
127 return (FALSE);
|
|
128 while (n--) {
|
|
129 while (inword() == FALSE) {
|
|
130 if (forwchar(FALSE, 1) == FALSE)
|
|
131 return (FALSE);
|
|
132 }
|
|
133 while (inword() != FALSE) {
|
|
134 c = lgetc(curwp->w_dotp, curwp->w_doto);
|
|
135 if (c>='A' && c<='Z') {
|
|
136 c += 'a'-'A';
|
|
137 lputc(curwp->w_dotp, curwp->w_doto, c);
|
|
138 lchange(WFHARD);
|
|
139 }
|
|
140 if (forwchar(FALSE, 1) == FALSE)
|
|
141 return (FALSE);
|
|
142 }
|
|
143 }
|
|
144 return (TRUE);
|
|
145 }
|
|
146
|
|
147 /*
|
|
148 * Move the cursor forward by the specified number of words. As you move
|
|
149 * convert the first character of the word to upper case, and subsequent
|
|
150 * characters to lower case. Error if you try and move past the end of the
|
|
151 * buffer. Bound to "M-C".
|
|
152 */
|
|
153 capword(f, n)
|
|
154 {
|
|
155 register int c;
|
|
156
|
|
157 if (n < 0)
|
|
158 return (FALSE);
|
|
159 while (n--) {
|
|
160 while (inword() == FALSE) {
|
|
161 if (forwchar(FALSE, 1) == FALSE)
|
|
162 return (FALSE);
|
|
163 }
|
|
164 if (inword() != FALSE) {
|
|
165 c = lgetc(curwp->w_dotp, curwp->w_doto);
|
|
166 if (c>='a' && c<='z') {
|
|
167 c -= 'a'-'A';
|
|
168 lputc(curwp->w_dotp, curwp->w_doto, c);
|
|
169 lchange(WFHARD);
|
|
170 }
|
|
171 if (forwchar(FALSE, 1) == FALSE)
|
|
172 return (FALSE);
|
|
173 while (inword() != FALSE) {
|
|
174 c = lgetc(curwp->w_dotp, curwp->w_doto);
|
|
175 if (c>='A' && c<='Z') {
|
|
176 c += 'a'-'A';
|
|
177 lputc(curwp->w_dotp, curwp->w_doto, c);
|
|
178 lchange(WFHARD);
|
|
179 }
|
|
180 if (forwchar(FALSE, 1) == FALSE)
|
|
181 return (FALSE);
|
|
182 }
|
|
183 }
|
|
184 }
|
|
185 return (TRUE);
|
|
186 }
|
|
187
|
|
188 /*
|
|
189 * Kill forward by "n" words. Remember the location of dot. Move forward by
|
|
190 * the right number of words. Put dot back where it was and issue the kill
|
|
191 * command for the right number of characters. Bound to "M-D".
|
|
192 */
|
|
193 delfword(f, n)
|
|
194 {
|
|
195 register int size;
|
|
196 register LINE *dotp;
|
|
197 register int doto;
|
|
198
|
|
199 if (n < 0)
|
|
200 return (FALSE);
|
|
201 dotp = curwp->w_dotp;
|
|
202 doto = curwp->w_doto;
|
|
203 size = 0;
|
|
204 while (n--) {
|
|
205 while (inword() == FALSE) {
|
|
206 if (forwchar(FALSE, 1) == FALSE)
|
|
207 return (FALSE);
|
|
208 ++size;
|
|
209 }
|
|
210 while (inword() != FALSE) {
|
|
211 if (forwchar(FALSE, 1) == FALSE)
|
|
212 return (FALSE);
|
|
213 ++size;
|
|
214
|
|
215 }
|
|
216 }
|
|
217 curwp->w_dotp = dotp;
|
|
218 curwp->w_doto = doto;
|
|
219 return (ldelete(size, TRUE));
|
|
220 }
|
|
221
|
|
222 /*
|
|
223 * Kill backwards by "n" words. Move backwards by the desired number of words,
|
|
224 * counting the characters. When dot is finally moved to its resting place,
|
|
225 * fire off the kill command. Bound to "M-Rubout" and to "M-Backspace".
|
|
226 */
|
|
227 delbword(f, n)
|
|
228 {
|
|
229 register int size;
|
|
230
|
|
231 if (n < 0)
|
|
232 return (FALSE);
|
|
233 if (backchar(FALSE, 1) == FALSE)
|
|
234 return (FALSE);
|
|
235 size = 0;
|
|
236 while (n--) {
|
|
237 while (inword() == FALSE) {
|
|
238 if (backchar(FALSE, 1) == FALSE)
|
|
239 return (FALSE);
|
|
240 ++size;
|
|
241 }
|
|
242 while (inword() != FALSE) {
|
|
243 if (backchar(FALSE, 1) == FALSE)
|
|
244 return (FALSE);
|
|
245 ++size;
|
|
246 }
|
|
247 }
|
|
248 if (forwchar(FALSE, 1) == FALSE)
|
|
249 return (FALSE);
|
|
250 return (ldelete(size, TRUE));
|
|
251 }
|
|
252
|
|
253 /*
|
|
254 * Return TRUE if the character at dot is a character that is considered to be
|
|
255 * part of a word. The word character list is hard coded. Should be setable.
|
|
256 */
|
|
257 inword()
|
|
258 {
|
|
259 register int c;
|
|
260
|
|
261 if (curwp->w_doto == llength(curwp->w_dotp))
|
|
262 return (FALSE);
|
|
263 c = lgetc(curwp->w_dotp, curwp->w_doto);
|
|
264 if (c>='a' && c<='z')
|
|
265 return (TRUE);
|
|
266 if (c>='A' && c<='Z')
|
|
267 return (TRUE);
|
|
268 if (c>='0' && c<='9')
|
|
269 return (TRUE);
|
|
270 if (c=='$' || c=='_') /* For identifiers */
|
|
271 return (TRUE);
|
|
272 return (FALSE);
|
|
273 }
|
|
274
|