summaryrefslogtreecommitdiff
path: root/src/user
diff options
context:
space:
mode:
authorBenji Dial <Benji3.141@gmail.com>2020-11-08 11:40:36 -0500
committerBenji Dial <Benji3.141@gmail.com>2020-11-08 11:40:36 -0500
commite9376ea26d3819e540a80ba2d8db97eb5f593afd (patch)
tree932e904829efd1d668cb328b8749f5b07708a84e /src/user
parent21491514b3642a321ce65f2a07428f63c4d9feb5 (diff)
downloadportland-os-e9376ea26d3819e540a80ba2d8db97eb5f593afd.tar.gz
adding history feature to manual (duplicates current entry on missing pages)
Diffstat (limited to 'src/user')
-rw-r--r--src/user/manual/manual.c39
1 files 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;