From e9376ea26d3819e540a80ba2d8db97eb5f593afd Mon Sep 17 00:00:00 2001 From: Benji Dial Date: Sun, 8 Nov 2020 11:40:36 -0500 Subject: adding history feature to manual (duplicates current entry on missing pages) --- src/user/manual/manual.c | 39 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/src/user/manual/manual.c b/src/user/manual/manual.c index 48f4f65..d1af406 100644 --- a/src/user/manual/manual.c +++ b/src/user/manual/manual.c @@ -21,6 +21,8 @@ struct file *cur_file = 0; +char *name_backup = 0; + uint32_t *line_offsets = 0; uint32_t n_lines; @@ -122,6 +124,10 @@ void load_file(const char *name) { return; } + if (name_backup) + free_block(name_backup); + name_backup = strdup(name); + if (cur_file) close_file(cur_file); cur_file = new_file; @@ -182,6 +188,32 @@ void load_file(const char *name) { scroll_to(0); } +struct stack_entry { + struct stack_entry *down; + char *name; + uint32_t line; +}; + +struct stack_entry *stack_top = 0; + +void push() { + struct stack_entry *new_entry = get_block(sizeof(struct stack_entry)); + new_entry->down = stack_top; + new_entry->name = strdup(name_backup); + new_entry->line = line_on; + stack_top = new_entry; +} + +void pop() { + if (stack_top) { + load_file(stack_top->name); + scroll_to(stack_top->line); + free_block(stack_top->name); + free_block(stack_top); + stack_top = stack_top->down; + } +} + void main() { _set_color(UI_COLOR); _print_at(24, 79, " "); @@ -255,11 +287,14 @@ void main() { case ' ': case '\n': case _KEY_NENTER: - if (cur_link) + if (cur_link) { + push(); load_file(cur_link->lto); + } break; case _KEY_ESC: - //TODO + if (stack_top) + pop(); break; case 'q': return; -- cgit v1.2.3