diff options
-rw-r--r-- | doc.c | 10 | ||||
-rw-r--r-- | doc.h | 2 | ||||
-rw-r--r-- | nav.c | 16 |
3 files changed, 28 insertions, 0 deletions
diff --git a/doc.c b/doc.c index 89ff756..d41db7c 100644 --- a/doc.c +++ b/doc.c @@ -17,6 +17,7 @@ void doc_init(struct doc *d) { .len = 0, }; d->latest = 0; + d->linkc = 0; } void doc_fini(struct doc *d) { @@ -89,3 +90,12 @@ int doc_line_next(struct doc *d, size_t *ofs) { return -1; } } + +const char *doc_get_link(struct doc *d, unsigned short lnk) { + size_t l = 1; + for (size_t i = 0; i < d->lnk.sz; i++) { + if (l == lnk) return &d->lnk.buf[i]; + if (d->lnk.buf[i] == 0) l++; + } + return NULL; +} diff --git a/doc.h b/doc.h index 08af700..ab66272 100644 --- a/doc.h +++ b/doc.h @@ -35,6 +35,8 @@ struct doc_line *doc_line_at(struct doc *d, size_t ofs); int doc_line_prev(struct doc *d, size_t *ofs); int doc_line_next(struct doc *d, size_t *ofs); +const char *doc_get_link(struct doc *d, unsigned short lnk); + void doc_set_link(struct doc *d, unsigned short lnk); unsigned short doc_add_link(struct doc *d, const char *url); diff --git a/nav.c b/nav.c index 83826dc..0c31bed 100644 --- a/nav.c +++ b/nav.c @@ -3,6 +3,7 @@ #include "nav.h" #include "net.h" +#include "err.h" #include "parse.h" /* history */ @@ -70,10 +71,17 @@ void nav_pg_up(struct nav_state *ns) { nav_pg_down(ns); } +#define MARGIN 8 + void nav_pg_down(struct nav_state *ns) { size_t lines = pg_lines(); while (lines--) { struct doc_line *l = nav_cur_line(ns); + int n = 0; + if (l->link != DOC_LINK_NONE) { + n = printf("[%hu]", l->link + 1); + } + while (n++ < MARGIN) putchar(' '); fwrite(l->txt, 1, l->len, stdout); putchar('\n'); if (!nav_line_down(ns)) break; @@ -111,5 +119,13 @@ 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]; + const char *url = doc_get_link(d, link_nr); + if (url) { + puts(url); + return nav_to(ns, url); + } else { + perr("invalid link number"); + } return 0; } |