aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar lostd <lostd@2f30.org>2015-01-28 12:30:59 +0200
committerGravatar lostd <lostd@2f30.org>2015-01-28 12:30:59 +0200
commit3c45733f470bebf036289348d7c2fae7b02b14eb (patch)
tree4689e1006903a78780f3b18fb89864b6bec449a2
parentab0c9e592146fefe4298cdc3e061bfb8f8a8fb1f (diff)
downloadnnn-3c45733f470bebf036289348d7c2fae7b02b14eb.tar.gz
Rework readmore(), replace goto with a switch
-rw-r--r--noice.c29
1 files changed, 15 insertions, 14 deletions
diff --git a/noice.c b/noice.c
index 85ec3d7..63002cf 100644
--- 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;