summaryrefslogtreecommitdiff
path: root/page.c
diff options
context:
space:
mode:
authorJuan Manuel Tomás <jtomas1815@gmail.com>2020-04-20 02:42:22 -0300
committerJuan Manuel Tomás <jtomas1815@gmail.com>2020-04-20 02:42:22 -0300
commit852c6d1f1a6ab8b8c3fd40922a83af70a70fdf2d (patch)
tree7d27d3f0eb23637684ed2fbb4a40d259fb313ef3 /page.c
parente1e020df18299c89d4fcb9cce728b6e24f24bfff (diff)
downloadjet-852c6d1f1a6ab8b8c3fd40922a83af70a70fdf2d.tar.gz
jet-852c6d1f1a6ab8b8c3fd40922a83af70a70fdf2d.zip
Add point structure
Diffstat (limited to 'page.c')
-rw-r--r--page.c27
1 files changed, 27 insertions, 0 deletions
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);