diff options
| author | Juan Manuel Tomás <jtomas1815@gmail.com> | 2020-04-20 02:42:22 -0300 | 
|---|---|---|
| committer | Juan Manuel Tomás <jtomas1815@gmail.com> | 2020-04-20 02:42:22 -0300 | 
| commit | 852c6d1f1a6ab8b8c3fd40922a83af70a70fdf2d (patch) | |
| tree | 7d27d3f0eb23637684ed2fbb4a40d259fb313ef3 /page.c | |
| parent | e1e020df18299c89d4fcb9cce728b6e24f24bfff (diff) | |
| download | jet-852c6d1f1a6ab8b8c3fd40922a83af70a70fdf2d.tar.gz jet-852c6d1f1a6ab8b8c3fd40922a83af70a70fdf2d.zip | |
Add point structure
Diffstat (limited to 'page.c')
| -rw-r--r-- | page.c | 27 | 
1 files changed, 27 insertions, 0 deletions
| @@ -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); | 
