sacc

sacc(omys), simple console gopher client (mirror)
git clone https://git.parazyd.org/sacc
Log | Files | Refs | LICENSE

commit 71302cd77ae2eb37e2b1281b9e8d6215e5d70e15
parent d8d55448c98ebba791bf971579705d44d99d0ae2
Author: Quentin Rameau <quinq@fifth.space>
Date:   Wed, 21 Jun 2017 21:13:37 +0200

Improve navigation handling

Diffstat:
Msacc.c | 17+++++++++++++----
1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/sacc.c b/sacc.c @@ -307,27 +307,36 @@ delve(Item *hole) char buf[BUFSIZ]; Item *entry = NULL; int n, itm; + char nl; for (;;) { if (dig(entry, hole)) { n = display(hole); } else { n = 0; - fprintf(stderr, "Couldn't get %s:%s/%c%s\n", - hole->host, hole->port, - hole->type, hole->selector); + fprintf(stderr, "Couldn't get %s:%s/%c%s\n", hole->host, + hole->port, hole->type, hole->selector); } + do { printf("%d items, visit (0: back, ^D or q: quit): ", n); + if (!fgets(buf, sizeof(buf), stdin)) { putchar('\n'); return; } if (!strcmp(buf, "q\n")) return; - if (sscanf(buf, "%d", &itm) != 1) + + itm = -1; + if (*buf < '0' || *buf > '9') continue; + + nl = '\0'; + if (sscanf(buf, "%d%c", &itm, &nl) != 2 || nl != '\n') + itm = -1; } while (itm < 0 || itm > n); + if (itm) { entry = hole; hole = ((Item **)hole->target)[itm-1];