cleaner code - iomenu - interactive terminal-based selection menu HTML git clone git://bitreich.org/iomenu git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws65d7roiv6bfj7d652fid.onion/iomenu DIR Log DIR Files DIR Refs DIR Tags DIR README DIR LICENSE --- DIR commit 277ca72956b6deb921cbe96f981214602624c6ac DIR parent cf83d371853dced03fb2db5af7f2b8e04e48f469 HTML Author: Josuah Demangeon <mail@josuah.net> Date: Tue, 31 Oct 2017 15:59:42 +0100 cleaner code Diffstat: M buffer.c | 28 ++++++++++++++++------------ M main.c | 2 +- 2 files changed, 17 insertions(+), 13 deletions(-) --- DIR diff --git a/buffer.c b/buffer.c @@ -79,29 +79,33 @@ read_stdin(void) void filter(void) { - int tokc = 0; - int n = 0; - int i; - char **tokv = NULL; - char *s; - char buffer[sizeof (input)]; extern char **linev; - extern current; + extern int current; + int tokc; + int n; + char **tokv = NULL; + char *s; + char buf[sizeof (input)]; current = offset = next = 0; - strcpy(buffer, input); - for (s = strtok(buffer, " "); s; s = strtok(NULL, " "), tokc++) { + strcpy(buf, input); + tokc = 0; + n = 0; + s = strtok(buf, " "); + while (s) { if (tokc >= n) { tokv = realloc(tokv, ++n * sizeof (*tokv)); if (tokv == NULL) die("realloc"); } tokv[tokc] = s; + s = strtok(NULL, " "); + tokc++; } matchc = 0; - for (i = 0; i < linec; i++) - if (match_line(linev[i], tokv, tokc)) - matchv[matchc++] = linev[i]; + for (n = 0; n < linec; n++) + if (match_line(linev[n], tokv, tokc)) + matchv[matchc++] = linev[n]; free(tokv); if (opt['#'] && matchv[current][0] == '#') move(+1); DIR diff --git a/main.c b/main.c @@ -47,7 +47,7 @@ set_terminal(void) { struct termios new; - fputs("\x1b[s\x1b[?1049h", stderr); + fputs("\x1b[s\x1b[?1049h\x1b[H", stderr); if (tcgetattr(ttyfd, &termios) < 0 || tcgetattr(ttyfd, &new) < 0) { perror("tcgetattr"); exit(EXIT_FAILURE);