noice

small file browser
git clone git://git.2f30.org/noice.git
Log | Files | Refs | README | LICENSE

commit 3c45733f470bebf036289348d7c2fae7b02b14eb
parent ab0c9e592146fefe4298cdc3e061bfb8f8a8fb1f
Author: lostd <lostd@2f30.org>
Date:   Wed Jan 28 12:30:59 +0200

Rework readmore(), replace goto with a switch

Diffstat:
noice.c | 29+++++++++++++++--------------
1 file changed, 15 insertions(+), 14 deletions(-)
diff --git a/noice.c b/noice.c @@ -367,26 +367,26 @@ readln(void) int readmore(char **str) { - int c; - int i; + int c, ret = 0; + size_t i; char *ln = *str; - int ret = 0; if (ln != NULL) i = strlen(ln); else i = 0; - DPRINTF_D(i); curs_set(TRUE); c = getch(); - if (c == KEY_ENTER || c == '\r') { + switch (c) { + case KEY_ENTER: + case '\r': ret = 1; - goto out; - } - if (c == KEY_BACKSPACE || c == CONTROL('H')) { + break; + case KEY_BACKSPACE: + case CONTROL('H'): i--; if (i > 0) { ln = xrealloc(ln, (i + 1) * sizeof(*ln)); @@ -395,13 +395,14 @@ readmore(char **str) free(ln); ln = NULL; } - goto out; + break; + default: + i++; + ln = xrealloc(ln, (i + 1) * sizeof(*ln)); + ln[i - 1] = c; + ln[i] = '\0'; } - ln = xrealloc(ln, (i + 2) * sizeof(*ln)); - ln[i] = c; - i++; - ln[i] = '\0'; -out: + curs_set(FALSE); *str = ln;