diff --git a/libs/pbd/pathscanner.cc b/libs/pbd/pathscanner.cc index 05e90b599b..1a197b27aa 100644 --- a/libs/pbd/pathscanner.cc +++ b/libs/pbd/pathscanner.cc @@ -52,16 +52,17 @@ regexp_filter (const string& str, void *arg) return regexec (pattern, str.c_str(), 0, 0, 0) == 0; } -vector -PathScanner::operator() (const string &dirpath, const string ®exp, - bool match_fullpath, bool return_fullpath, - long limit, bool recurse) - +void +PathScanner::find_files_matching_regex (vector& result, + const std::string& dirpath, + const std::string& regexp, + bool match_fullpath, bool return_fullpath, + long limit, + bool recurse) { int err; char msg[256]; regex_t compiled_pattern; - vector result; if ((err = regcomp (&compiled_pattern, regexp.c_str(), REG_EXTENDED|REG_NOSUB))) { @@ -74,17 +75,33 @@ PathScanner::operator() (const string &dirpath, const string ®exp, << ")" << endmsg; - return vector(); + return; } - - result = run_scan (dirpath, - regexp_filter, - &compiled_pattern, - match_fullpath, - return_fullpath, - limit, recurse); + + result = run_scan (dirpath, + regexp_filter, + &compiled_pattern, + match_fullpath, + return_fullpath, + limit, recurse); regfree (&compiled_pattern); +} + +vector +PathScanner::operator() (const string &dirpath, const string ®exp, + bool match_fullpath, bool return_fullpath, + long limit, bool recurse) + +{ + vector result; + + find_files_matching_regex (result, + dirpath, + regexp, + match_fullpath, + return_fullpath, + limit, recurse); return result; } @@ -184,30 +201,10 @@ PathScanner::find_first (const string &dirpath, bool return_fullpath) { vector res; - int err; - char msg[256]; - regex_t compiled_pattern; - if ((err = regcomp (&compiled_pattern, regexp.c_str(), - REG_EXTENDED|REG_NOSUB))) { - - regerror (err, &compiled_pattern, - msg, sizeof (msg)); - - error << "Cannot compile soundfile regexp for use (" << msg << ")" << endmsg; - - return 0; - } + find_files_matching_regex (res, dirpath, regexp, + match_fullpath, return_fullpath, 1); - run_scan_internal (res, dirpath, - ®exp_filter, - &compiled_pattern, - match_fullpath, - return_fullpath, - 1); - - regfree (&compiled_pattern); - if (res.size() == 0) { return string(); } diff --git a/libs/pbd/pbd/pathscanner.h b/libs/pbd/pbd/pathscanner.h index de23d7c645..4d9ef56e15 100644 --- a/libs/pbd/pbd/pathscanner.h +++ b/libs/pbd/pbd/pathscanner.h @@ -69,6 +69,14 @@ class LIBPBD_API PathScanner private: + void find_files_matching_regex (std::vector& results, + const std::string& dirpath, + const std::string& regexp, + bool match_fullpath, + bool return_fullpath, + long limit, + bool recurse = false); + std::vector run_scan (const std::string &dirpath, bool (*filter)(const std::string &, void *), void *arg,