iomenu

interactive text selection menu
Log | Files | Refs | README | LICENSE

commit e3bca30c0b12f79deb675e0e7bd36917226e3dff
parent aed045ad72c3828eaff58e4d289568789a0fa736
Author: Josuah Demangeon <mail@josuah.net>
Date:   Fri,  8 Dec 2017 10:04:09 +0100

fix stdin plitting into lines

Diffstat:
Miomenu.c | 16++++++----------
1 file changed, 6 insertions(+), 10 deletions(-)

diff --git a/iomenu.c b/iomenu.c @@ -72,21 +72,17 @@ split_lines(char *buf) char *b, **lv, **mv; - linec = 0; - b = buf; - while ((b = strchr(b + 1, '\n'))) + linec = 1; + for (b = buf; (b = strchr(b, '\n')) != NULL && b[1] != '\0'; b++) linec++; - if (!linec) - linec = 1; - if (!(lv = linev = calloc(linec + 1, sizeof (char **)))) + if ((lv = linev = calloc(linec, sizeof (char **))) == NULL) die("calloc"); - if (!(mv = matchv = calloc(linec + 1, sizeof (char **)))) + if ((mv = matchv = calloc(linec, sizeof (char **))) == NULL) die("calloc"); *mv = *lv = b = buf; - while ((b = strchr(b, '\n'))) { + while ((b = strchr(b, '\n')) != NULL) { *b = '\0'; - mv++, lv++; - *mv = *lv = ++b; + *++mv = *++lv = ++b; } }