From 852c6d1f1a6ab8b8c3fd40922a83af70a70fdf2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Manuel=20Tom=C3=A1s?= Date: Mon, 20 Apr 2020 02:42:22 -0300 Subject: Add point structure --- page.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'page.c') diff --git a/page.c b/page.c index 59b1701..ee4861c 100644 --- a/page.c +++ b/page.c @@ -12,6 +12,33 @@ struct page { struct page *prev; }; +struct point { + struct page *current_page; + uint16_t offset; +}; + +void move_point_forward(struct point *point) { + point->offset++; + if (point->offset == point->current_page->gap_start + 1) { + point->offset = point->current_page->gap_end; + } + if (point->offset == PAGE_SIZE) { + point->offset = 0; + point->current_page = point->current_page->next; + } +} + +void move_point_backward(struct point *point) { + if (point->offset == 0) { + point->offset = PAGE_SIZE; + point->current_page = point->current_page->prev; + } + point->offset--; + if (point->offset == point->current_page->gap_end - 1) { + point->offset = point->current_page->gap_start; + } +} + struct page *new_page() { struct page *result = malloc(sizeof(struct page)); result->buffer = malloc(PAGE_SIZE); -- cgit v1.2.3