From: Francois Fleuret Date: Fri, 10 Feb 2012 07:28:06 +0000 (+0100) Subject: Finished, seems to bug a bit. X-Git-Url: https://fleuret.org/cgi-bin/gitweb/gitweb.cgi?a=commitdiff_plain;h=ba39a532d21befe924af75cc5f9161a4cd793147;p=selector.git Finished, seems to bug a bit. --- diff --git a/selector.c b/selector.c index 07160f5..ff75c7a 100644 --- a/selector.c +++ b/selector.c @@ -390,26 +390,29 @@ int add_interval(int n, int *switches, int start, int end) { } } -int match(struct matcher *matcher, char *string, int *switches) { - int n, nb_switches = 0; +int match(struct matcher *matcher, char *string, int *nb_switches, int *switches) { + int n; char *where; + + if(nb_switches) { *nb_switches = 0; } + if(matcher->nb_patterns >= 0) { if(matcher->case_sensitive) { for(n = 0; n < matcher->nb_patterns; n++) { if((where = strstr(string, matcher->patterns[n])) == 0) return 0; if(switches) { - nb_switches = add_interval(nb_switches, switches, - (int) (where - string), - (int) (where - string) + strlen(matcher->patterns[n])); + *nb_switches = add_interval(*nb_switches, switches, + (int) (where - string), + (int) (where - string) + strlen(matcher->patterns[n])); } } } else { for(n = 0; n < matcher->nb_patterns; n++) { if((where = strcasestr(string, matcher->patterns[n])) == 0) return 0; if(switches) { - nb_switches = add_interval(nb_switches, switches, - (int) (where - string), - (int) (where - string) + strlen(matcher->patterns[n])); + *nb_switches = add_interval(*nb_switches, switches, + (int) (where - string), + (int) (where - string) + strlen(matcher->patterns[n])); } } } @@ -541,14 +544,14 @@ void kill_after_cursor(char *buffer, int *position) { int previous_visible(int current_line, char **lines, struct matcher *matcher) { int line = current_line - 1; - while(line >= 0 && !match(matcher, lines[line], 0)) line--; + while(line >= 0 && !match(matcher, lines[line], 0, 0)) line--; return line; } int next_visible(int current_line, int nb_lines, char **lines, struct matcher *matcher) { int line = current_line + 1; - while(line < nb_lines && !match(matcher, lines[line], 0)) line++; + while(line < nb_lines && !match(matcher, lines[line], 0, 0)) line++; if(line < nb_lines) return line; @@ -609,6 +612,7 @@ void update_screen(int *current_focus_line, int *displayed_focus_line, int console_width, console_height; int nb_printed_lines = 0; int cursor_x; + int nb_switches; initialize_matcher(&matcher, use_regexp, case_sensitive, pattern); @@ -639,7 +643,7 @@ void update_screen(int *current_focus_line, int *displayed_focus_line, else if(nb_lines > 0) { int new_focus_line; - if(match(&matcher, lines[*current_focus_line], 0)) { + if(match(&matcher, lines[*current_focus_line], 0, 0)) { new_focus_line = *current_focus_line; } else { new_focus_line = next_visible(*current_focus_line, nb_lines, lines, @@ -689,21 +693,21 @@ void update_screen(int *current_focus_line, int *displayed_focus_line, if(first_line > 0) { first_line--; - while(first_line > 0 && !match(&matcher, lines[first_line], 0)) { + while(first_line > 0 && !match(&matcher, lines[first_line], 0, 0)) { first_line--; } - if(match(&matcher, lines[first_line], 0)) { + if(match(&matcher, lines[first_line], 0, 0)) { nb_match++; } } if(nb_match < console_height - 1 && last_line < nb_lines - 1) { last_line++; - while(last_line < nb_lines - 1 && !match(&matcher, lines[last_line], 0)) { + while(last_line < nb_lines - 1 && !match(&matcher, lines[last_line], 0, 0)) { last_line++; } - if(match(&matcher, lines[last_line], 0)) { + if(match(&matcher, lines[last_line], 0, 0)) { nb_match++; } } @@ -712,7 +716,7 @@ void update_screen(int *current_focus_line, int *displayed_focus_line, /* Now we display them */ for(l = first_line; l <= last_line; l++) { - if(match(&matcher, lines[l], switches)) { + if(match(&matcher, lines[l], &nb_switches, switches)) { int k = 0; while(lines[l][k] && k < BUFFER_SIZE - 2 && k < console_width) { @@ -737,7 +741,7 @@ void update_screen(int *current_focus_line, int *displayed_focus_line, } attron(attr_focus_line); print_string_with_switches(buffer, k, console_width, - matcher.nb_patterns, switches); + nb_switches, switches); attroff(attr_focus_line); } else { if(show_long_lines && k >= console_width) { @@ -752,7 +756,7 @@ void update_screen(int *current_focus_line, int *displayed_focus_line, buffer[k++] = '\0'; } print_string_with_switches(buffer, k, console_width, - matcher.nb_patterns, switches); + nb_switches, switches); } nb_printed_lines++;