int match(struct matcher *matcher, char *string, int *nb_switches, int *switches) {
int n;
char *where;
+ regmatch_t matches;
if(nb_switches) { *nb_switches = 0; }
}
return 1;
} else {
- return regexec(&matcher->preg, string, 0, 0, 0) == 0;
+ if(regexec(&matcher->preg, string, 1, &matches, 0) == 0) {
+ if(switches) {
+ *nb_switches = 2;
+ switches[0] = matches.rm_so;
+ switches[1] = matches.rm_eo;
+ }
+ return 1;
+ } else {
+ return 0;
+ }
}
}
initialize_matcher(&matcher, use_regexp, case_sensitive, pattern);
- if(show_hits && matcher.nb_patterns > 0) {
+ if(show_hits && matcher.nb_patterns >= 0) {
switches = safe_malloc(sizeof(int) * matcher.nb_patterns * 2);
} else {
- switches = 0;
+ switches = safe_malloc(sizeof(int) * 2);
}
console_width = getmaxx(stdscr);
buffer[k++] = '\n';
buffer[k++] = '\0';
}
+
print_string_with_switches(buffer, k, console_width,
nb_switches / 2, switches);
}