zygo

ncurses gopher client
Log | Files | Refs

commit 5a001b2af6acad2469b345ae34977a8d56613936
parent 72cc544ffedfa4914e4bc8a463356a16d0334e42
Author: hhvn <dev@hhvn.uk>
Date:   Sat, 16 Jul 2022 13:33:10 +0100

readline() leaves \r for analysis

Diffstat:
Mzygo.c | 15++++++++-------
1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/zygo.c b/zygo.c @@ -408,14 +408,13 @@ readline(char *buf, size_t count) { size_t i = 0; char c = 0; - do { - if (net_read(&c, sizeof(char)) != sizeof(char)) + while (i < count && c != '\n') { + if (net_read(&c, sizeof(char)) < 1) return 0; - if (c != '\r') - buf[i++] = c; - } while (c != '\n' && i < count); + buf[i++] = c; + } - buf[i - 1] = 0; + buf[i - 1] = '\0'; return 1; } @@ -509,9 +508,11 @@ go(Elem *e, int mhist, int notls) { list_free(&page); while (readline(line, sizeof(line))) { - if (strcmp(line, ".") == 0) { + if (strcmp(line, ".\r") == 0) { gotall = 1; } else { + if (line[strlen(line) - 1] == '\r') + line[strlen(line) - 1] = '\0'; if (dup->type == '0') elem = elem_create(0, 'i', line, NULL, NULL, NULL); else