-int previous_visible(int current_line, int nb_lines, char **lines, int nb_patterns, char **patterns) {
+void initialize_matcher(int use_regexp, matcher_t *matcher, const char *pattern) {
+ if(use_regexp) {
+ matcher->nb_patterns = -1;
+ matcher->regexp_error = regcomp(&matcher->preg, pattern, REG_ICASE);
+ } else {
+ matcher->regexp_error = 0;
+ matcher->nb_patterns = 1;
+
+ for(const char *s = pattern; *s; s++) {
+ if(*s == pattern_separator) {
+ matcher->nb_patterns++;
+ }
+ }
+
+ matcher->splitted_patterns = new char[strlen(pattern) + 1];
+ matcher->patterns = new char*[matcher->nb_patterns];
+
+ strcpy(matcher->splitted_patterns, pattern);
+
+ int n = 0;
+ char *last_pattern_start = matcher->splitted_patterns;
+ for(char *s = matcher->splitted_patterns; n < matcher->nb_patterns; s++) {
+ if(*s == pattern_separator || *s == '\0') {
+ *s = '\0';
+ matcher->patterns[n++] = last_pattern_start;
+ last_pattern_start = s + 1;
+ }
+ }
+ }
+}
+
+//////////////////////////////////////////////////////////////////////
+
+int previous_visible(int current_line, int nb_lines, char **lines, matcher_t *matcher) {