summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile2
-rw-r--r--point.c14
-rw-r--r--test/point.c6
3 files changed, 13 insertions, 9 deletions
diff --git a/Makefile b/Makefile
index be264eb..2e84b40 100644
--- a/Makefile
+++ b/Makefile
@@ -6,5 +6,5 @@ jet: Makefile *.c
page: Makefile page.c test/page.c
gcc $(FLAGS) test/page.c -o page
-point: Makefile point.c test/point.c
+point: Makefile page.c point.c test/point.c
gcc $(FLAGS) test/point.c -o point
diff --git a/point.c b/point.c
index 7250f2d..5fd02e0 100644
--- a/point.c
+++ b/point.c
@@ -25,20 +25,20 @@ bool at_eof(struct point *point) {
void move_point_forward(struct point *point) {
if (point->index < point->page->element_count) {
point->index++;
- }
- if (point->index == point->page->element_count && point->page->next) {
- point->index = 0;
+ } else if (point->page->next) {
+ point->index = 1;
point->page = point->page->next;
}
}
void move_point_backward(struct point *point) {
- if (point->index == 0 && point->page->prev) {
+ if (point->index > 1) {
+ point->index--;
+ } else if (point->page->prev) {
point->index = point->page->prev->element_count;
point->page = point->page->prev;
- }
- if (point->index > 0) {
- point->index--;
+ } else {
+ point->index = 0;
}
}
diff --git a/test/point.c b/test/point.c
index 9c4abc9..252726c 100644
--- a/test/point.c
+++ b/test/point.c
@@ -21,7 +21,11 @@ int main() {
struct page *iter = page;
while (iter) {
- addch('|');
+ if (iter == point.page) {
+ addch('#');
+ } else {
+ addch('|');
+ }
for (int i = 0; i < iter->gap_start; i++) {
addch(iter->elements[i]);
}