From ce123450d908692d2178382293d968d979ac3946 Mon Sep 17 00:00:00 2001 From: josuah Date: Fri, 21 Oct 2016 15:01:36 -0400 Subject: [PATCH] It seems to work now --- iomenu.c | 45 ++++++++++++++------------------------------- 1 file changed, 14 insertions(+), 31 deletions(-) diff --git a/iomenu.c b/iomenu.c index aa6483e..a18e69c 100644 --- a/iomenu.c +++ b/iomenu.c @@ -13,6 +13,9 @@ /* add abstraction at no cost, but may add more complexity as well? */ enum { FALSE = 0, TRUE = 1 }; +/* debug switches */ +#define COMPLETE_MODE 0 + /* preprocessor macros */ #define LENGTH(x) (sizeof(x) / sizeof(*x)) #define CONTROL(char) (char ^ 0x40) @@ -124,17 +127,12 @@ add_line(Buffer *buffer, int number, char *string, char *separator, Line *prev) void filter_lines(Buffer *buffer) { - Line * line = buffer->first; - + Line * line = buffer->first; buffer->matching = 0; while (line) { - if (line_match_input(line, buffer->input)) { - line->matches = TRUE; - buffer->matching++; - } else { - line->matches = FALSE; - } + line->matches = line_match_input(line, buffer->input); + buffer->matching += line->matches; line = line->next; } @@ -144,29 +142,14 @@ filter_lines(Buffer *buffer) * Check if line matches and return TRUE if so */ int -line_match_input(Line *l, char *input) +line_match_input(Line *line, char *input) { - size_t i, j, l_input, l_content; - l_input = strlen(input); - - if (TRUE /* complete-mode */) { - if (!strncmp(input, l->content, l_input)) + if (COMPLETE_MODE) { + if (!strncmp(input, line->content, strlen(input))) return TRUE; } else { - l_content = strlen(l->content); - - for (i = 0; i < l_content - l_input; i++) { - for ( - j = 0; - j <= l_input - && j + i <= l_content - && tolower(input[j]) == tolower(l->content[j + i]); - j++ - ) - ; - if (j >= l_input) - return TRUE; - } + if (strstr(line->content, input)) + return TRUE; } return FALSE; @@ -435,7 +418,7 @@ do_key(char key, Buffer *buffer) break; case CONTROL('I'): /* tab */ - if (TRUE /* complete-mode */) { + if (COMPLETE_MODE) { strcpy(buffer->input, buffer->current->content); filter_lines(buffer); } else { @@ -447,7 +430,7 @@ do_key(char key, Buffer *buffer) case CONTROL('J'): /* enter */ fputs("\r\033[K", stderr); - if (TRUE /* complete-mode */) { + if (COMPLETE_MODE) { puts(buffer->input); } else { puts(buffer->current->content); @@ -551,7 +534,7 @@ print_prompt(Buffer *buffer, int cols) fputs("\033[1;30m", stderr); /* suggest without overflowing terminal width */ - if (TRUE /* complete-mode */) { + if (COMPLETE_MODE) { for (; i < strlen(suggest) && cols > digits; cols--, i++) { fputc(suggest[i], stderr); } -- 2.11.4.GIT