Improve navigation handling - sacc - sacc (saccomys): simple gopher client. | |
Log | |
Files | |
Refs | |
LICENSE | |
--- | |
commit 5035e8a5d53fe0003422fdf550fc4b94addf95bc | |
parent 2025a3c168bbfe7cb7c0f2cfb6b7d6f88e1403f6 | |
Author: Quentin Rameau <[email protected]> | |
Date: Wed, 21 Jun 2017 21:13:37 +0200 | |
Improve navigation handling | |
Diffstat: | |
sacc.c | 17 +++++++++++++---- | |
1 file changed, 13 insertions(+), 4 deletions(-) | |
--- | |
diff --git a/sacc.c b/sacc.c | |
@@ -312,27 +312,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->hos… | |
+ 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]; |