|
|
1.1 root 1: /* move5.c */
2:
3: /* Author:
4: * Steve Kirkendall
5: * 16820 SW Tallac Way
6: * Beaverton, OR 97006
7: * [email protected], or ...uunet!tektronix!psueea!jove!kirkenda
8: */
9:
10:
11: /* This file contains the word-oriented movement functions */
12:
13: #include <ctype.h>
14: #include "config.h"
15: #include "vi.h"
16:
17: #ifndef isascii
18: # define isascii(c) !((c) & ~0x7f)
19: #endif
20:
21:
22: MARK m_fword(m, cnt, cmd)
23: MARK m; /* movement is relative to this mark */
24: long cnt; /* a numeric argument */
25: int cmd; /* either 'w' or 'W' */
26: {
27: REG long l;
28: REG char *text;
29: REG int i;
30:
31: DEFAULT(1);
32:
33: l = markline(m);
34: pfetch(l);
35: text = ptext + markidx(m);
36: while (cnt-- > 0) /* yes, ASSIGNMENT! */
37: {
38: i = *text++;
39:
40: if (cmd == 'W')
41: {
42: /* include any non-whitespace */
43: while (i && (!isascii(i) || !isspace(i)))
44: {
45: i = *text++;
46: }
47: }
48: else if (!isascii(i) || isalnum(i) || i == '_')
49: {
50: /* include an alphanumeric word */
51: while (i && (!isascii(i) || isalnum(i) || i == '_'))
52: {
53: i = *text++;
54: }
55: }
56: else
57: {
58: /* include contiguous punctuation */
59: while (i && isascii(i) && !isalnum(i) && !isspace(i))
60: {
61: i = *text++;
62: }
63: }
64:
65: /* include trailing whitespace */
66: while (!i || isascii(i) && isspace(i))
67: {
68: /* did we hit the end of this line? */
69: if (!i)
70: {
71: /* move to next line, if there is one */
72: l++;
73: if (l > nlines)
74: {
75: return MARK_UNSET;
76: }
77: pfetch(l);
78: text = ptext;
79: }
80:
81: i = *text++;
82: }
83: text--;
84: }
85:
86: /* construct a MARK for this place */
87: m = buildmark(text);
88: return m;
89: }
90:
91:
92: MARK m_bword(m, cnt, cmd)
93: MARK m; /* movement is relative to this mark */
94: long cnt; /* a numeric argument */
95: int cmd; /* either 'b' or 'B' */
96: {
97: REG long l;
98: REG char *text;
99:
100: DEFAULT(1);
101:
102: l = markline(m);
103: pfetch(l);
104: text = ptext + markidx(m);
105: while (cnt-- > 0) /* yes, ASSIGNMENT! */
106: {
107: text--;
108:
109: /* include preceding whitespace */
110: while (text < ptext || isascii(*text) && isspace(*text))
111: {
112: /* did we hit the end of this line? */
113: if (text < ptext)
114: {
115: /* move to preceding line, if there is one */
116: l--;
117: if (l <= 0)
118: {
119: return MARK_UNSET;
120: }
121: pfetch(l);
122: text = ptext + plen - 1;
123: }
124: else
125: {
126: text--;
127: }
128: }
129:
130: if (cmd == 'B')
131: {
132: /* include any non-whitespace */
133: while (text >= ptext && (!isascii(*text) || !isspace(*text)))
134: {
135: text--;
136: }
137: }
138: else if (!isascii(*text) || isalnum(*text) || *text == '_')
139: {
140: /* include an alphanumeric word */
141: while (text >= ptext && (!isascii(*text) || isalnum(*text) || *text == '_'))
142: {
143: text--;
144: }
145: }
146: else
147: {
148: /* include contiguous punctuation */
149: while (text >= ptext && isascii(*text) && !isalnum(*text) && !isspace(*text))
150: {
151: text--;
152: }
153: }
154: text++;
155: }
156:
157: /* construct a MARK for this place */
158: m = buildmark(text);
159: return m;
160: }
161:
162: MARK m_eword(m, cnt, cmd)
163: MARK m; /* movement is relative to this mark */
164: long cnt; /* a numeric argument */
165: int cmd; /* either 'e' or 'E' */
166: {
167: REG long l;
168: REG char *text;
169: REG int i;
170:
171: DEFAULT(1);
172:
173: l = markline(m);
174: pfetch(l);
175: text = ptext + markidx(m);
176: while (cnt-- > 0) /* yes, ASSIGNMENT! */
177: {
178: text++;
179: i = *text++;
180:
181: /* include preceding whitespace */
182: while (!i || isascii(i) && isspace(i))
183: {
184: /* did we hit the end of this line? */
185: if (!i)
186: {
187: /* move to next line, if there is one */
188: l++;
189: if (l > nlines)
190: {
191: return MARK_UNSET;
192: }
193: pfetch(l);
194: text = ptext;
195: }
196:
197: i = *text++;
198: }
199:
200: if (cmd == 'E')
201: {
202: /* include any non-whitespace */
203: while (i && (!isascii(i) || !isspace(i)))
204: {
205: i = *text++;
206: }
207: }
208: else if (!isascii(i) || isalnum(i) || i == '_')
209: {
210: /* include an alphanumeric word */
211: while (i && (!isascii(i) || isalnum(i) || i == '_'))
212: {
213: i = *text++;
214: }
215: }
216: else
217: {
218: /* include contiguous punctuation */
219: while (i && isascii(i) && !isalnum(i) && !isspace(i))
220: {
221: i = *text++;
222: }
223: }
224: text -= 2;
225: }
226:
227: /* construct a MARK for this place */
228: m = buildmark(text);
229: return m;
230: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.