-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathv_move.c
56 lines (51 loc) · 962 Bytes
/
v_move.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include "vstr.h"
ROUTINE int v_move(v, dir, cnt)
register p_vstr v;
register int dir, cnt;
{
register int actual = 0;
entry(v_move)
#ifdef DEBUG
yelp("called with vstr at %x, count of %d, direction = %d\n", v, cnt, dir);
#endif
if (!cnt)
ret(0)
switch (dir) {
case FWD:
while (cnt && !IS_BACK(v)) {
if (++v->cur.u_pos >= v->cur.here->len) {
if (!(v->cur.here = v->cur.here->next)) {
v->cur.here = v->tail;
v->cur.u_pos = v->tail->len;
break;
}
else {
v->cur.u_pos = 0;
}
}
cnt--;
actual++;
}
break;
case BACK:
while (cnt && !IS_FRONT(v)) {
if (--v->cur.u_pos < 0) {
if (!(v->cur.here = v->cur.here->prev)) {
v->cur.here = v->head;
v->cur.u_pos = -1;
break;
}
else {
v->cur.u_pos = v->cur.here->len - 1;
}
}
actual++;
cnt--;
}
break;
}
if (!actual)
ret((dir == FWD) ? ATEND : ATBEG)
else
ret(actual)
}