diff options
| author | WormHeamer | 2026-02-01 16:11:51 -0500 |
|---|---|---|
| committer | WormHeamer | 2026-02-01 16:11:51 -0500 |
| commit | 4ba9e0cd583e848c75acc07f15feb85bdb8b8dac (patch) | |
| tree | 949c07cfcbc27f0f5b2e116e49b1939da0a69e63 | |
| parent | b1ada414e265a429fcd538efdd26efb8c9c6b697 (diff) | |
i never committed this?
| -rw-r--r-- | nav.c | 35 | ||||
| -rw-r--r-- | nav.h | 8 |
2 files changed, 27 insertions, 16 deletions
@@ -12,29 +12,32 @@ void nav_init(struct nav_state *ns) { memset(ns, 0, sizeof *ns); ns->histc = 1; - doc_init(ns->histv); - doc_add_text(ns->histv, strv("Type ? for command help.")); + ns->histv[0].offset = 0; + struct doc *d = &ns->histv[0].doc; + doc_init(d); + doc_add_text(d, strv("Type ? for command help.")); ns->prot_default = PROT_GOPHER; } void nav_fini(struct nav_state *ns) { for (size_t i = 0; i < ns->histc; i++) { - doc_fini(&ns->histv[i]); + doc_fini(&ns->histv[i].doc); } } void nav_push(struct nav_state *ns, struct doc d) { while (ns->histc > ns->cur_doc + 1) { - doc_fini(&ns->histv[--ns->histc]); + doc_fini(&ns->histv[--ns->histc].doc); } if (ns->histc == HIST_MAX) { - doc_fini(ns->histv); - memmove(ns->histv, &ns->histv[1], sizeof(struct doc) * (HIST_MAX - 1)); - memmove(ns->cur_ofs, &ns->cur_ofs[1], sizeof(size_t) * (HIST_MAX - 1)); + doc_fini(&ns->histv[0].doc); + memmove(ns->histv, &ns->histv[1], sizeof(struct nav_doc) * (HIST_MAX - 1)); ns->histc--; } - ns->cur_ofs[ns->histc] = 0; - ns->histv[ns->histc++] = d; + ns->histv[ns->histc++] = (struct nav_doc) { + .doc = d, + .offset = 0 + }; ns->cur_doc = ns->histc - 1; } @@ -55,15 +58,18 @@ size_t pg_lines(void) { } struct doc_line *nav_cur_line(struct nav_state *ns) { - return doc_line_at(&ns->histv[ns->cur_doc], ns->cur_ofs[ns->cur_doc]); + struct nav_doc *d = &ns->histv[ns->cur_doc]; + return doc_line_at(&d->doc, d->offset); } int nav_line_up(struct nav_state *ns) { - return !doc_line_prev(&ns->histv[ns->cur_doc], &ns->cur_ofs[ns->cur_doc]); + struct nav_doc *d = &ns->histv[ns->cur_doc]; + return !doc_line_prev(&d->doc, &d->offset); } int nav_line_down(struct nav_state *ns) { - return !doc_line_next(&ns->histv[ns->cur_doc], &ns->cur_ofs[ns->cur_doc]); + struct nav_doc *d = &ns->histv[ns->cur_doc]; + return !doc_line_next(&d->doc, &d->offset); } void nav_pg_up(struct nav_state *ns) { @@ -121,7 +127,7 @@ int nav_to(struct nav_state *ns, const char *url) { } int nav_link_nr(struct nav_state *ns, unsigned long link_nr) { - struct doc *d = &ns->histv[ns->cur_doc]; + struct doc *d = &ns->histv[ns->cur_doc].doc; const char *url = doc_get_link(d, link_nr); if (url) { return nav_to(ns, url); @@ -132,6 +138,7 @@ int nav_link_nr(struct nav_state *ns, unsigned long link_nr) { } void nav_prompt(struct nav_state *ns) { - int m = doc_line_nextp(&ns->histv[ns->cur_doc], ns->cur_ofs[ns->cur_doc]); + struct nav_doc *d = &ns->histv[ns->cur_doc]; + int m = doc_line_nextp(&d->doc, d->offset); fputs(m ? "MORE* " : "* ", stdout); } @@ -5,10 +5,14 @@ #include "net.h" #define HIST_MAX 32 +struct nav_doc { + struct doc doc; + size_t offset; +}; + struct nav_state { size_t histc, cur_doc; - struct doc histv[HIST_MAX]; - size_t cur_ofs[HIST_MAX]; + struct nav_doc histv[HIST_MAX]; enum protocol prot_default; }; |
