}
}
-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]));
}
}
}
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;
int console_width, console_height;
int nb_printed_lines = 0;
int cursor_x;
+ int nb_switches;
initialize_matcher(&matcher, use_regexp, case_sensitive, pattern);
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,
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++;
}
}
/* 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) {
}
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) {
buffer[k++] = '\0';
}
print_string_with_switches(buffer, k, console_width,
- matcher.nb_patterns, switches);
+ nb_switches, switches);
}
nb_printed_lines++;