sfeed_curses

[fork] sfeed (atom feed) reader
Log | Files | Refs | README | LICENSE

commit 61f9eb9bb99e3483c34e84eb4387166304a69ce6
parent ccbddab53f0575c73101479891b6b5a49f3babc2
Author: Hiltjo Posthuma <hiltjo@codemadness.org>
Date:   Sat,  4 Jul 2020 13:48:44 +0200

reuse readch() in the tiny line editor

Diffstat:
Msfeed_curses.c | 40++++++++++++++++++----------------------
1 file changed, 18 insertions(+), 22 deletions(-)

diff --git a/sfeed_curses.c b/sfeed_curses.c @@ -860,13 +860,27 @@ scrollbar_draw(struct scrollbar *s) s->dirty = 0; } +int +readch(void) +{ + unsigned char b; + ssize_t n; + + n = read(0, &b, 1); + if (n == 0) + return EOF; + else if (n == -1) + err(1, "read"); + + return (int)b; +} + char * lineeditor(void) { - unsigned char ch; char *input = NULL; size_t cap = 0, nchars = 0; - ssize_t n; + int ch; for (;;) { if (nchars + 1 >= cap) { @@ -874,11 +888,8 @@ lineeditor(void) input = erealloc(input, cap); } - n = read(0, &ch, 1); - if (n < 0) { - free(input); - input = NULL; - } else if (n == 0 || ch == '\r' || ch == '\n') { + ch = readch(); + if (ch == EOF || ch == '\r' || ch == '\n') { input[nchars] = '\0'; break; } else if (ch == '\b' || ch == 0x7f) { @@ -1435,21 +1446,6 @@ item_row_format(struct pane *p, struct row *row) } int -readch(void) -{ - unsigned char b; - ssize_t n; - - n = read(0, &b, 1); - if (n == 0) - return EOF; - else if (n == -1) - err(1, "read"); - - return (int)b; -} - -int main(int argc, char *argv[]) { struct pane *p;