sacc

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

commit 3a53a319d4ade0631accac3fd9177e6fbfc49c7f
parent 26bc04284d9becc870a6a036a9a6f9bdfba8ba2a
Author: Quentin Rameau <quinq@fifth.space>
Date:   Mon, 28 Oct 2019 02:12:50 +0100

Print better URI

Diffstat:
Mui_ti.c | 20++++++++++++++------
Mui_txt.c | 27++++++++++++++++++++++-----
2 files changed, 36 insertions(+), 11 deletions(-)

diff --git a/ui_ti.c b/ui_ti.c @@ -218,12 +218,20 @@ displayuri(Item *item) item->selector, item->host, item->port); break; default: - fmt = strcmp(item->port, "70") ? - "gopher://%1$s:%4$s/%2$c%3$s" : - "gopher://%s/%c%s"; - n = snprintf(bufout, sizeof(bufout), fmt, - item->host, item->type, - item->selector, item->port); + n = snprintf(bufout, sizeof(bufout), "gopher://%s", item->host); + + if (n < sizeof(bufout) && strcmp(item->port, "70")) { + n += snprintf(bufout+n, sizeof(bufout)-n, ":%s", + item->port); + } + if (n < sizeof(bufout)) { + n += snprintf(bufout+n, sizeof(bufout)-n, "/%c%s", + item->type, item->selector); + } + if (n < sizeof(bufout) && item->type == '7' && item->tag) { + n += snprintf(bufout+n, sizeof(bufout)-n, " %s", + item->tag + strlen(item->selector)); + } break; } diff --git a/ui_txt.c b/ui_txt.c @@ -199,11 +199,28 @@ printuri(Item *item, size_t i) item->selector, item->host, item->port); break; default: - fmt = strcmp(item->port, "70") ? - "%1$zu: %2$s: gopher://%3$s:%6$s/%4$c%5$s" : - "%zu: %s: gopher://%s/%c%s"; - n = snprintf(bufout, sizeof(bufout), fmt, i, item->username, - item->host, item->type, item->selector, item->port); + n = snprintf(bufout, sizeof(bufout), "%zu: ", i); + + if (n < sizeof(bufout) && *item->username) { + n += snprintf(bufout+n, sizeof(bufout)-n, "%s: ", + item->username); + } + if (n < sizeof(bufout)) { + n += snprintf(bufout+n, sizeof(bufout)-n, "gopher://%s", + item->host); + } + if (n < sizeof(bufout) && strcmp(item->port, "70")) { + n += snprintf(bufout+n, sizeof(bufout)-n, ":%s", + item->port); + } + if (n < sizeof(bufout)) { + n += snprintf(bufout+n, sizeof(bufout)-n, "/%c%s", + item->type, item->selector); + } + if (n < sizeof(bufout) && item->type == '7' && item->tag) { + n += snprintf(bufout+n, sizeof(bufout)-n, " %s", + item->tag + strlen(item->selector)); + } break; }