diff options
author | lostd <lostd@2f30.org> | 2015-01-28 12:30:59 +0200 |
---|---|---|
committer | lostd <lostd@2f30.org> | 2015-01-28 12:30:59 +0200 |
commit | 3c45733f470bebf036289348d7c2fae7b02b14eb (patch) | |
tree | 4689e1006903a78780f3b18fb89864b6bec449a2 | |
parent | ab0c9e592146fefe4298cdc3e061bfb8f8a8fb1f (diff) | |
download | nnn-3c45733f470bebf036289348d7c2fae7b02b14eb.tar.gz |
Rework readmore(), replace goto with a switch
-rw-r--r-- | noice.c | 29 |
1 files changed, 15 insertions, 14 deletions
@@ -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; |