sacc

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

commit 199205cac2adb7d40a2ef7f4e20ad617e6437323
parent 21f414d9dc19a291e207562994c35bb9e3df3bc1
Author: Hiltjo Posthuma <hiltjo@codemadness.org>
Date:   Fri, 28 Jul 2017 22:11:21 +0200

Handle newline in uiprompt directly

Diffstat:
Msacc.c | 10+++-------
Mui_ti.c | 5++++-
Mui_txt.c | 6+++++-
3 files changed, 12 insertions(+), 9 deletions(-)

diff --git a/sacc.c b/sacc.c @@ -412,9 +412,7 @@ downloaditem(Item *item) if (!(path = uiprompt("Download to [%s] (^D cancel): ", file))) return; - if (path[1]) - path[strlen(path)-1] = '\0'; - else + if (!path[0]) path = xstrdup(file); if (tag = item->tag) { @@ -499,9 +497,7 @@ plumbitem(Item *item) tag = NULL; } - if (path[1]) { - path[strlen(path)-1] = '\0'; - + if (path[0]) { if (tag && !strcmp(tag, path)) goto cleanup; @@ -594,7 +590,7 @@ searchselector(Item *item) if (!(exp = uiprompt("Enter search string (^D cancel) [%s]: ", pexp))) return NULL; - if (strcmp(exp, pexp) && exp[1]) { + if (exp[0] && strcmp(exp, pexp)) { n += 1 + strlen(exp); tag = xmalloc(n); snprintf(tag, n, "%s\t%s", selector, exp); diff --git a/ui_ti.c b/ui_ti.c @@ -81,8 +81,11 @@ uiprompt(char *fmt, ...) putp(tparm(restore_cursor)); fflush(stdout); - if (r > 0) + if (r > 0) { + if (input[r - 1] == '\n') + input[--r] = '\0'; return input; + } free(input); return NULL; diff --git a/ui_txt.c b/ui_txt.c @@ -75,6 +75,7 @@ uiprompt(char *fmt, ...) va_list ap; char *input = NULL; size_t n = 0; + ssize_t r; va_start(ap, fmt); vprintf(fmt, ap); @@ -82,8 +83,11 @@ uiprompt(char *fmt, ...) fflush(stdout); - if (getline(&input, &n, stdin) > 0) + if ((r = getline(&input, &n, stdin)) > 0) { + if (input[r - 1] == '\n') + input[--r] = '\0'; return input; + } free(input); return NULL;