From 0e96d84079c1792523d99b6bbec5878d11f5c8e4 Mon Sep 17 00:00:00 2001 From: Tim Mayberry Date: Mon, 16 Jun 2014 20:39:45 +1000 Subject: [PATCH 01/12] Change PBD::PathScanner API to return results by value to avoid inadvertent memory leaks --- gtk2_ardour/ardour_ui.cc | 7 +- gtk2_ardour/session_dialog.cc | 8 +- libs/ardour/ardour/session.h | 4 +- libs/ardour/lv2_plugin.cc | 21 ++- libs/ardour/panner_manager.cc | 9 +- libs/ardour/plugin_manager.cc | 125 ++++++------------ libs/ardour/session_state.cc | 88 +++++------- libs/ardour/template_utils.cc | 28 ++-- libs/pbd/file_utils.cc | 14 +- libs/pbd/pathscanner.cc | 90 ++++++------- libs/pbd/pbd/pathscanner.h | 78 +++++------ .../generic_midi_control_protocol.cc | 10 +- libs/surfaces/mackie/device_info.cc | 18 +-- libs/surfaces/mackie/device_profile.cc | 16 +-- 14 files changed, 202 insertions(+), 314 deletions(-) diff --git a/gtk2_ardour/ardour_ui.cc b/gtk2_ardour/ardour_ui.cc index 3ad33b5c8c..d9ac37e36f 100644 --- a/gtk2_ardour/ardour_ui.cc +++ b/gtk2_ardour/ardour_ui.cc @@ -1416,7 +1416,7 @@ ARDOUR_UI::redisplay_recent_sessions () get_state_files_in_directory (*i, state_file_paths); - vector* states; + vector states; vector item; string fullpath = *i; @@ -1433,13 +1433,12 @@ ARDOUR_UI::redisplay_recent_sessions () } /* now get available states for this session */ + states = Session::possible_states (fullpath); - if ((states = Session::possible_states (fullpath)) == 0) { + if (states.empty()) { /* no state file? */ continue; } - vector_delete(states); - delete(states); std::vector state_file_names(get_file_names_no_extension (state_file_paths)); diff --git a/gtk2_ardour/session_dialog.cc b/gtk2_ardour/session_dialog.cc index 178fcb835c..7fb765e2bc 100644 --- a/gtk2_ardour/session_dialog.cc +++ b/gtk2_ardour/session_dialog.cc @@ -621,7 +621,7 @@ SessionDialog::redisplay_recent_sessions () get_state_files_in_directory (*i, state_file_paths); - vector* states; + vector states; vector item; string dirname = *i; @@ -639,12 +639,12 @@ SessionDialog::redisplay_recent_sessions () /* now get available states for this session */ - if ((states = Session::possible_states (dirname)) == 0) { + states = Session::possible_states (dirname); + + if (states.empty()) { /* no state file? */ continue; } - vector_delete (states); - delete (states); std::vector state_file_names(get_file_names_no_extension (state_file_paths)); diff --git a/libs/ardour/ardour/session.h b/libs/ardour/ardour/session.h index 08d0ec1e4e..0dd986226b 100644 --- a/libs/ardour/ardour/session.h +++ b/libs/ardour/ardour/session.h @@ -402,8 +402,8 @@ class LIBARDOUR_API Session : public PBD::StatefulDestructible, public PBD::Scop PBD::Signal0 StateReady; PBD::Signal0 SaveSession; - std::vector* possible_states() const; - static std::vector* possible_states (std::string path); + std::vector possible_states() const; + static std::vector possible_states (std::string path); XMLNode& get_state(); int set_state(const XMLNode& node, int version); // not idempotent diff --git a/libs/ardour/lv2_plugin.cc b/libs/ardour/lv2_plugin.cc index 8fac9369b0..d68c4e5077 100644 --- a/libs/ardour/lv2_plugin.cc +++ b/libs/ardour/lv2_plugin.cc @@ -2013,23 +2013,20 @@ void LV2World::load_bundled_plugins() { if (!_bundle_checked) { - cout << "Scanning folders for bundled LV2s: " << ARDOUR::lv2_bundled_search_path().to_string() << endl; PathScanner scanner; - vector *plugin_objects = scanner (ARDOUR::lv2_bundled_search_path().to_string(), lv2_filter, 0, true, true); - if (plugin_objects) { - for ( vector::iterator x = plugin_objects->begin(); x != plugin_objects->end (); ++x) { + cout << "Scanning folders for bundled LV2s: " << ARDOUR::lv2_bundled_search_path().to_string() << endl; + + vector plugin_objects = scanner (ARDOUR::lv2_bundled_search_path().to_string(), lv2_filter, 0, true, true); + for ( vector::iterator x = plugin_objects.begin(); x != plugin_objects.end (); ++x) { #ifdef PLATFORM_WINDOWS - string uri = "file:///" + **x + "/"; + string uri = "file:///" + *x + "/"; #else - string uri = "file://" + **x + "/"; + string uri = "file://" + *x + "/"; #endif - LilvNode *node = lilv_new_uri(world, uri.c_str()); - lilv_world_load_bundle(world, node); - lilv_node_free(node); - } + LilvNode *node = lilv_new_uri(world, uri.c_str()); + lilv_world_load_bundle(world, node); + lilv_node_free(node); } - vector_delete (plugin_objects); - delete (plugin_objects); _bundle_checked = true; } diff --git a/libs/ardour/panner_manager.cc b/libs/ardour/panner_manager.cc index 95136c2951..2988a8ab46 100644 --- a/libs/ardour/panner_manager.cc +++ b/libs/ardour/panner_manager.cc @@ -91,19 +91,16 @@ void PannerManager::discover_panners () { PathScanner scanner; - std::vector *panner_modules; + std::vector panner_modules; std::string search_path = panner_search_path().to_string(); DEBUG_TRACE (DEBUG::Panning, string_compose (_("looking for panners in %1\n"), search_path)); panner_modules = scanner (search_path, panner_filter, 0, false, true, 1, true); - for (vector::iterator i = panner_modules->begin(); i != panner_modules->end(); ++i) { - panner_discover (**i); + for (vector::iterator i = panner_modules.begin(); i != panner_modules.end(); ++i) { + panner_discover (*i); } - - vector_delete (panner_modules); - delete (panner_modules); } int diff --git a/libs/ardour/plugin_manager.cc b/libs/ardour/plugin_manager.cc index c638ff2e86..c1e596ff3d 100644 --- a/libs/ardour/plugin_manager.cc +++ b/libs/ardour/plugin_manager.cc @@ -243,31 +243,23 @@ PluginManager::clear_vst_cache () #ifdef WINDOWS_VST_SUPPORT { PathScanner scanner; - vector *fsi_files; + vector fsi_files; fsi_files = scanner (Config->get_plugin_path_vst(), "\\.fsi$", true, true, -1, false); - if (fsi_files) { - for (vector::iterator i = fsi_files->begin(); i != fsi_files->end (); ++i) { - ::g_unlink((*i)->c_str()); - } + for (vector::iterator i = fsi_files.begin(); i != fsi_files.end (); ++i) { + ::g_unlink(i->c_str()); } - vector_delete(fsi_files); - delete(fsi_files); } #endif #ifdef LXVST_SUPPORT { PathScanner scanner; - vector *fsi_files; + vector fsi_files; fsi_files = scanner (Config->get_plugin_path_lxvst(), "\\.fsi$", true, true, -1, false); - if (fsi_files) { - for (vector::iterator i = fsi_files->begin(); i != fsi_files->end (); ++i) { - ::g_unlink((*i)->c_str()); - } + for (vector::iterator i = fsi_files.begin(); i != fsi_files.end (); ++i) { + ::g_unlink(i->c_str()); } - vector_delete(fsi_files); - delete(fsi_files); } #endif @@ -275,15 +267,11 @@ PluginManager::clear_vst_cache () { string personal = get_personal_vst_info_cache_dir(); PathScanner scanner; - vector *fsi_files; + vector fsi_files; fsi_files = scanner (personal, "\\.fsi$", true, true, -1, false); - if (fsi_files) { - for (vector::iterator i = fsi_files->begin(); i != fsi_files->end (); ++i) { - ::g_unlink((*i)->c_str()); - } + for (vector::iterator i = fsi_files.begin(); i != fsi_files.end (); ++i) { + ::g_unlink(i->c_str()); } - vector_delete(fsi_files); - delete(fsi_files); } #endif } @@ -294,31 +282,23 @@ PluginManager::clear_vst_blacklist () #ifdef WINDOWS_VST_SUPPORT { PathScanner scanner; - vector *fsi_files; + vector fsi_files; fsi_files = scanner (Config->get_plugin_path_vst(), "\\.fsb$", true, true, -1, false); - if (fsi_files) { - for (vector::iterator i = fsi_files->begin(); i != fsi_files->end (); ++i) { - ::g_unlink((*i)->c_str()); - } + for (vector::iterator i = fsi_files.begin(); i != fsi_files.end (); ++i) { + ::g_unlink(i->c_str()); } - vector_delete(fsi_files); - delete(fsi_files); } #endif #ifdef LXVST_SUPPORT { PathScanner scanner; - vector *fsi_files; + vector fsi_files; fsi_files = scanner (Config->get_plugin_path_lxvst(), "\\.fsb$", true, true, -1, false); - if (fsi_files) { - for (vector::iterator i = fsi_files->begin(); i != fsi_files->end (); ++i) { - ::g_unlink((*i)->c_str()); - } + for (vector::iterator i = fsi_files.begin(); i != fsi_files.end (); ++i) { + ::g_unlink(i->c_str()); } - vector_delete(fsi_files); - delete(fsi_files); } #endif @@ -327,15 +307,11 @@ PluginManager::clear_vst_blacklist () string personal = get_personal_vst_blacklist_dir(); PathScanner scanner; - vector *fsi_files; + vector fsi_files; fsi_files = scanner (personal, "\\.fsb$", true, true, -1, false); - if (fsi_files) { - for (vector::iterator i = fsi_files->begin(); i != fsi_files->end (); ++i) { - ::g_unlink((*i)->c_str()); - } + for (vector::iterator i = fsi_files.begin(); i != fsi_files.end (); ++i) { + ::g_unlink(i->c_str()); } - vector_delete(fsi_files); - delete(fsi_files); } #endif } @@ -410,8 +386,8 @@ PluginManager::add_presets(string domain) { #ifdef HAVE_LRDF PathScanner scanner; - vector *presets; - vector::iterator x; + vector presets; + vector::iterator x; char* envvar; if ((envvar = getenv ("HOME")) == 0) { @@ -421,17 +397,13 @@ PluginManager::add_presets(string domain) string path = string_compose("%1/.%2/rdf", envvar, domain); presets = scanner (path, rdf_filter, 0, false, true); - if (presets) { - for (x = presets->begin(); x != presets->end (); ++x) { - string file = "file:" + **x; - if (lrdf_read_file(file.c_str())) { - warning << string_compose(_("Could not parse rdf file: %1"), *x) << endmsg; - } + for (x = presets.begin(); x != presets.end (); ++x) { + string file = "file:" + *x; + if (lrdf_read_file(file.c_str())) { + warning << string_compose(_("Could not parse rdf file: %1"), *x) << endmsg; } - - vector_delete (presets); - delete (presets); } + #endif } @@ -440,22 +412,17 @@ PluginManager::add_lrdf_data (const string &path) { #ifdef HAVE_LRDF PathScanner scanner; - vector* rdf_files; - vector::iterator x; + vector rdf_files; + vector::iterator x; rdf_files = scanner (path, rdf_filter, 0, false, true); - if (rdf_files) { - for (x = rdf_files->begin(); x != rdf_files->end (); ++x) { - const string uri(string("file://") + **x); + for (x = rdf_files.begin(); x != rdf_files.end (); ++x) { + const string uri(string("file://") + *x); - if (lrdf_read_file(uri.c_str())) { - warning << "Could not parse rdf file: " << uri << endmsg; - } + if (lrdf_read_file(uri.c_str())) { + warning << "Could not parse rdf file: " << uri << endmsg; } - - vector_delete (rdf_files); - delete (rdf_files); } #endif } @@ -662,22 +629,17 @@ int PluginManager::windows_vst_discover_from_path (string path, bool cache_only) { PathScanner scanner; - vector *plugin_objects; - vector::iterator x; + vector plugin_objects; + vector::iterator x; int ret = 0; DEBUG_TRACE (DEBUG::PluginManager, string_compose ("detecting Windows VST plugins along %1\n", path)); plugin_objects = scanner (Config->get_plugin_path_vst(), windows_vst_filter, 0, false, true); - if (plugin_objects) { - for (x = plugin_objects->begin(); x != plugin_objects->end (); ++x) { - ARDOUR::PluginScanMessage(_("VST"), **x, !cache_only && !cancelled()); - windows_vst_discover (**x, cache_only || cancelled()); - } - - vector_delete (plugin_objects); - delete (plugin_objects); + for (x = plugin_objects.begin(); x != plugin_objects.end (); ++x) { + ARDOUR::PluginScanMessage(_("VST"), *x, !cache_only && !cancelled()); + windows_vst_discover (*x, cache_only || cancelled()); } return ret; @@ -783,8 +745,8 @@ int PluginManager::lxvst_discover_from_path (string path, bool cache_only) { PathScanner scanner; - vector *plugin_objects; - vector::iterator x; + vector plugin_objects; + vector::iterator x; int ret = 0; #ifndef NDEBUG @@ -795,14 +757,9 @@ PluginManager::lxvst_discover_from_path (string path, bool cache_only) plugin_objects = scanner (Config->get_plugin_path_lxvst(), lxvst_filter, 0, false, true); - if (plugin_objects) { - for (x = plugin_objects->begin(); x != plugin_objects->end (); ++x) { - ARDOUR::PluginScanMessage(_("LXVST"), **x, !cache_only && !cancelled()); - lxvst_discover (**x, cache_only || cancelled()); - } - - vector_delete (plugin_objects); - delete (plugin_objects); + for (x = plugin_objects.begin(); x != plugin_objects.end (); ++x) { + ARDOUR::PluginScanMessage(_("LXVST"), *x, !cache_only && !cancelled()); + lxvst_discover (*x, cache_only || cancelled()); } return ret; diff --git a/libs/ardour/session_state.cc b/libs/ardour/session_state.cc index 8999927729..9151ebf5eb 100644 --- a/libs/ardour/session_state.cc +++ b/libs/ardour/session_state.cc @@ -2299,16 +2299,10 @@ state_file_filter (const string &str, void* /*arg*/) str.find (statefile_suffix) == (str.length() - strlen (statefile_suffix))); } -struct string_cmp { - bool operator()(const string* a, const string* b) { - return *a < *b; - } -}; - -static string* -remove_end(string* state) +static string +remove_end(string state) { - string statename(*state); + string statename(state); string::size_type start,end; if ((start = statename.find_last_of (G_DIR_SEPARATOR)) != string::npos) { @@ -2319,24 +2313,23 @@ remove_end(string* state) end = statename.length(); } - return new string(statename.substr (0, end)); + return string(statename.substr (0, end)); } -vector * +vector Session::possible_states (string path) { PathScanner scanner; - vector* states = scanner (path, state_file_filter, 0, false, false); + vector states = scanner (path, state_file_filter, 0, false, false); - transform(states->begin(), states->end(), states->begin(), remove_end); + transform(states.begin(), states.end(), states.begin(), remove_end); - string_cmp cmp; - sort (states->begin(), states->end(), cmp); + sort (states.begin(), states.end()); return states; } -vector * +vector Session::possible_states () const { return possible_states(_path); @@ -2561,7 +2554,7 @@ int Session::find_all_sources_across_snapshots (set& result, bool exclude_this_snapshot) { PathScanner scanner; - vector* state_files; + vector state_files; string ripped; string this_snapshot_path; @@ -2575,7 +2568,7 @@ Session::find_all_sources_across_snapshots (set& result, bool exclude_th state_files = scanner (ripped, accept_all_state_files, (void *) 0, true, true); - if (state_files == 0) { + if (state_files.empty()) { /* impossible! */ return 0; } @@ -2584,13 +2577,13 @@ Session::find_all_sources_across_snapshots (set& result, bool exclude_th this_snapshot_path += legalize_for_path (_current_snapshot_name); this_snapshot_path += statefile_suffix; - for (vector::iterator i = state_files->begin(); i != state_files->end(); ++i) { + for (vector::iterator i = state_files.begin(); i != state_files.end(); ++i) { - if (exclude_this_snapshot && **i == this_snapshot_path) { + if (exclude_this_snapshot && *i == this_snapshot_path) { continue; } - if (find_all_sources (**i, result) < 0) { + if (find_all_sources (*i, result) < 0) { return -1; } } @@ -2645,8 +2638,8 @@ Session::cleanup_sources (CleanupReport& rep) string midi_path; vector::iterator i; vector::iterator nexti; - vector* candidates; - vector* candidates2; + vector candidates; + vector candidates2; vector unused; set all_sources; bool used; @@ -2733,16 +2726,9 @@ Session::cleanup_sources (CleanupReport& rep) /* merge them */ - if (candidates) { - if (candidates2) { - for (vector::iterator i = candidates2->begin(); i != candidates2->end(); ++i) { - candidates->push_back (*i); - } - delete candidates2; - } - } else { - candidates = candidates2; // might still be null - } + for (vector::iterator i = candidates2.begin(); i != candidates2.end(); ++i) { + candidates.push_back (*i); + } /* find all sources, but don't use this snapshot because the state file on disk still references sources we may have already @@ -2782,32 +2768,26 @@ Session::cleanup_sources (CleanupReport& rep) i = tmp; } - if (candidates) { - for (vector::iterator x = candidates->begin(); x != candidates->end(); ++x) { + for (vector::iterator x = candidates.begin(); x != candidates.end(); ++x) { - used = false; - spath = **x; + used = false; + spath = *x; - for (set::iterator i = all_sources.begin(); i != all_sources.end(); ++i) { + for (set::iterator i = all_sources.begin(); i != all_sources.end(); ++i) { - tmppath1 = canonical_path (spath); - tmppath2 = canonical_path ((*i)); + tmppath1 = canonical_path (spath); + tmppath2 = canonical_path ((*i)); - if (tmppath1 == tmppath2) { - used = true; - break; - } - } + if (tmppath1 == tmppath2) { + used = true; + break; + } + } - if (!used) { - unused.push_back (spath); - } - - delete *x; - } - - delete candidates; - } + if (!used) { + unused.push_back (spath); + } + } /* now try to move all unused files into the "dead" directory(ies) */ diff --git a/libs/ardour/template_utils.cc b/libs/ardour/template_utils.cc index 86881adfc3..20530ca9cc 100644 --- a/libs/ardour/template_utils.cc +++ b/libs/ardour/template_utils.cc @@ -81,21 +81,21 @@ session_template_dir_to_file (string const & dir) void find_session_templates (vector& template_names) { - vector *templates; + vector templates; PathScanner scanner; Searchpath spath (template_search_path()); templates = scanner (spath.to_string(), template_filter, 0, true, true); - if (!templates) { + if (templates.empty()) { cerr << "Found nothing along " << spath.to_string() << endl; return; } - cerr << "Found " << templates->size() << " along " << spath.to_string() << endl; + cerr << "Found " << templates.size() << " along " << spath.to_string() << endl; - for (vector::iterator i = templates->begin(); i != templates->end(); ++i) { - string file = session_template_dir_to_file (**i); + for (vector::iterator i = templates.begin(); i != templates.end(); ++i) { + string file = session_template_dir_to_file (*i); XMLTree tree; @@ -105,31 +105,28 @@ find_session_templates (vector& template_names) TemplateInfo rti; - rti.name = basename_nosuffix (**i); - rti.path = **i; + rti.name = basename_nosuffix (*i); + rti.path = *i; template_names.push_back (rti); } - - vector_delete (templates); - delete templates; } void find_route_templates (vector& template_names) { - vector *templates; + vector templates; PathScanner scanner; Searchpath spath (route_template_search_path()); templates = scanner (spath.to_string(), route_template_filter, 0, false, true); - if (!templates) { + if (templates.empty()) { return; } - for (vector::iterator i = templates->begin(); i != templates->end(); ++i) { - string fullpath = *(*i); + for (vector::iterator i = templates.begin(); i != templates.end(); ++i) { + string fullpath = *i; XMLTree tree; @@ -146,9 +143,6 @@ find_route_templates (vector& template_names) template_names.push_back (rti); } - - vector_delete (templates); - delete templates; } } diff --git a/libs/pbd/file_utils.cc b/libs/pbd/file_utils.cc index 756bd24fe4..552012d227 100644 --- a/libs/pbd/file_utils.cc +++ b/libs/pbd/file_utils.cc @@ -229,16 +229,12 @@ void copy_files(const std::string & from_path, const std::string & to_dir) { PathScanner scanner; - vector* files = scanner (from_path, accept_all_files, 0, true, false); + vector files = scanner (from_path, accept_all_files, 0, true, false); - if (files) { - for (vector::iterator i = files->begin(); i != files->end(); ++i) { - std::string from = Glib::build_filename (from_path, **i); - std::string to = Glib::build_filename (to_dir, **i); - copy_file (from, to); - } - vector_delete (files); - delete (files); + for (vector::iterator i = files.begin(); i != files.end(); ++i) { + std::string from = Glib::build_filename (from_path, *i); + std::string to = Glib::build_filename (to_dir, *i); + copy_file (from, to); } } diff --git a/libs/pbd/pathscanner.cc b/libs/pbd/pathscanner.cc index b60e1eee1a..bd010e66c5 100644 --- a/libs/pbd/pathscanner.cc +++ b/libs/pbd/pathscanner.cc @@ -40,12 +40,11 @@ using PBD::closedir; #include "pbd/error.h" #include "pbd/pathexpand.h" #include "pbd/pathscanner.h" -#include "pbd/stl_delete.h" using namespace std; using namespace PBD; -vector * +vector PathScanner::operator() (const string &dirpath, const string ®exp, bool match_fullpath, bool return_fullpath, long limit, bool recurse) @@ -65,7 +64,7 @@ PathScanner::operator() (const string &dirpath, const string ®exp, << ")" << endmsg; - return 0; + return vector(); } return run_scan (dirpath, &PathScanner::regexp_filter, @@ -76,7 +75,7 @@ PathScanner::operator() (const string &dirpath, const string ®exp, limit, recurse); } -vector * +vector PathScanner::run_scan (const string &dirpath, bool (PathScanner::*memberfilter)(const string &), bool (*filter)(const string &, void *), @@ -85,11 +84,13 @@ PathScanner::run_scan (const string &dirpath, long limit, bool recurse) { - return run_scan_internal ((vector*) 0, dirpath, memberfilter, filter, arg, match_fullpath, return_fullpath, limit, recurse); + vector result; + run_scan_internal (result, dirpath, memberfilter, filter, arg, match_fullpath, return_fullpath, limit, recurse); + return result; } -vector * -PathScanner::run_scan_internal (vector *result, +void +PathScanner::run_scan_internal (vector& result, const string &dirpath, bool (PathScanner::*memberfilter)(const string &), bool (*filter)(const string &, void *), @@ -104,18 +105,13 @@ PathScanner::run_scan_internal (vector *result, char *thisdir; string fullpath; string search_str; - string *newstr; long nfound = 0; char *saveptr; if ((thisdir = strtok_r (pathcopy, G_SEARCHPATH_SEPARATOR_S, &saveptr)) == 0 || strlen (thisdir) == 0) { free (pathcopy); - return 0; - } - - if (result == 0) { - result = new vector; + return; } do { @@ -161,12 +157,11 @@ PathScanner::run_scan_internal (vector *result, } if (return_fullpath) { - newstr = new string (fullpath); + result.push_back(fullpath); } else { - newstr = new string (finfo->d_name); + result.push_back(finfo->d_name); } - result->push_back (newstr); nfound++; } } @@ -175,17 +170,16 @@ PathScanner::run_scan_internal (vector *result, } while ((limit < 0 || (nfound < limit)) && (thisdir = strtok_r (0, G_SEARCHPATH_SEPARATOR_S, &saveptr))); free (pathcopy); - return result; + return; } -string * +string PathScanner::find_first (const string &dirpath, const string ®exp, bool match_fullpath, bool return_fullpath) { - vector *res; - string *ret; + vector res; int err; char msg[256]; @@ -197,51 +191,45 @@ PathScanner::find_first (const string &dirpath, error << "Cannot compile soundfile regexp for use (" << msg << ")" << endmsg; - return 0; } - res = run_scan (dirpath, - &PathScanner::regexp_filter, - (bool (*)(const string &, void *)) 0, - 0, - match_fullpath, - return_fullpath, - 1); + run_scan_internal (res, dirpath, + &PathScanner::regexp_filter, + (bool (*)(const string &, void *)) 0, + 0, + match_fullpath, + return_fullpath, + 1); - if (res->size() == 0) { - ret = 0; - } else { - ret = res->front(); + if (res.size() == 0) { + return string(); } - vector_delete (res); - delete res; - return ret; + + return res.front(); } -string * +string PathScanner::find_first (const string &dirpath, bool (*filter)(const string &, void *), void * /*arg*/, bool match_fullpath, bool return_fullpath) { - vector *res; - string *ret; + vector res; + string ret; - res = run_scan (dirpath, - (bool (PathScanner::*)(const string &)) 0, - filter, - 0, - match_fullpath, - return_fullpath, 1); + run_scan_internal (res, + dirpath, + (bool (PathScanner::*)(const string &)) 0, + filter, + 0, + match_fullpath, + return_fullpath, 1); - if (res->size() == 0) { - ret = 0; - } else { - ret = res->front(); + if (res.size() == 0) { + return string(); } - vector_delete (res); - delete res; - return ret; + + return res.front(); } diff --git a/libs/pbd/pbd/pathscanner.h b/libs/pbd/pbd/pathscanner.h index d62203c008..990aa44c77 100644 --- a/libs/pbd/pbd/pathscanner.h +++ b/libs/pbd/pbd/pathscanner.h @@ -34,13 +34,13 @@ class LIBPBD_API PathScanner { public: - std::vector *operator() (const std::string &dirpath, - bool (*filter)(const std::string &, void *arg), - void *arg, - bool match_fullpath = true, - bool return_fullpath = true, - long limit = -1, - bool recurse = false) { + std::vector operator() (const std::string &dirpath, + bool (*filter)(const std::string &, void *arg), + void *arg, + bool match_fullpath = true, + bool return_fullpath = true, + long limit = -1, + bool recurse = false) { return run_scan (dirpath, (bool (PathScanner::*)(const std::string &)) 0, filter, @@ -50,23 +50,23 @@ class LIBPBD_API PathScanner limit, recurse); } - std::vector *operator() (const std::string &dirpath, - const std::string ®exp, - bool match_fullpath = true, - bool return_fullpath = true, - long limit = -1, - bool recurse = false); + std::vector operator() (const std::string &dirpath, + const std::string ®exp, + bool match_fullpath = true, + bool return_fullpath = true, + long limit = -1, + bool recurse = false); - std::string *find_first (const std::string &dirpath, - const std::string ®exp, - bool match_fullpath = true, - bool return_fullpath = true); + std::string find_first (const std::string &dirpath, + const std::string ®exp, + bool match_fullpath = true, + bool return_fullpath = true); - std::string *find_first (const std::string &dirpath, - bool (*filter)(const std::string &, void *), - void *arg, - bool match_fullpath = true, - bool return_fullpath = true); + std::string find_first (const std::string &dirpath, + bool (*filter)(const std::string &, void *), + void *arg, + bool match_fullpath = true, + bool return_fullpath = true); private: regex_t compiled_pattern; @@ -75,24 +75,24 @@ class LIBPBD_API PathScanner return regexec (&compiled_pattern, str.c_str(), 0, 0, 0) == 0; } - std::vector *run_scan (const std::string &dirpath, - bool (PathScanner::*mfilter) (const std::string &), - bool (*filter)(const std::string &, void *), - void *arg, - bool match_fullpath, - bool return_fullpath, - long limit, - bool recurse = false); + std::vector run_scan (const std::string &dirpath, + bool (PathScanner::*mfilter) (const std::string &), + bool (*filter)(const std::string &, void *), + void *arg, + bool match_fullpath, + bool return_fullpath, + long limit, + bool recurse = false); - std::vector *run_scan_internal (std::vector*, - const std::string &dirpath, - bool (PathScanner::*mfilter) (const std::string &), - bool (*filter)(const std::string &, void *), - void *arg, - bool match_fullpath, - bool return_fullpath, - long limit, - bool recurse = false); + void run_scan_internal (std::vector&, + const std::string &dirpath, + bool (PathScanner::*mfilter) (const std::string &), + bool (*filter)(const std::string &, void *), + void *arg, + bool match_fullpath, + bool return_fullpath, + long limit, + bool recurse = false); }; #endif // __libmisc_pathscanner_h__ diff --git a/libs/surfaces/generic_midi/generic_midi_control_protocol.cc b/libs/surfaces/generic_midi/generic_midi_control_protocol.cc index bae6a48837..7a9104cfdb 100644 --- a/libs/surfaces/generic_midi/generic_midi_control_protocol.cc +++ b/libs/surfaces/generic_midi/generic_midi_control_protocol.cc @@ -136,20 +136,20 @@ midi_map_filter (const string &str, void* /*arg*/) void GenericMidiControlProtocol::reload_maps () { - vector *midi_maps; + vector midi_maps; PathScanner scanner; Searchpath spath (system_midi_map_search_path()); spath += user_midi_map_directory (); midi_maps = scanner (spath.to_string(), midi_map_filter, 0, false, true); - if (!midi_maps) { + if (midi_maps.empty()) { cerr << "No MIDI maps found using " << spath.to_string() << endl; return; } - for (vector::iterator i = midi_maps->begin(); i != midi_maps->end(); ++i) { - string fullpath = *(*i); + for (vector::iterator i = midi_maps.begin(); i != midi_maps.end(); ++i) { + string fullpath = *i; XMLTree tree; @@ -170,8 +170,6 @@ GenericMidiControlProtocol::reload_maps () map_info.push_back (mi); } - - delete midi_maps; } void diff --git a/libs/surfaces/mackie/device_info.cc b/libs/surfaces/mackie/device_info.cc index a2aeaa08aa..672bb25511 100644 --- a/libs/surfaces/mackie/device_info.cc +++ b/libs/surfaces/mackie/device_info.cc @@ -471,31 +471,24 @@ DeviceInfo::reload_device_info () { DeviceInfo di; vector s; - vector *devinfos; + vector devinfos; PathScanner scanner; Searchpath spath (devinfo_search_path()); devinfos = scanner (spath.to_string(), devinfo_filter, 0, false, true); device_info.clear (); - if (!devinfos) { + if (devinfos.empty()) { error << "No MCP device info files found using " << spath.to_string() << endmsg; std::cerr << "No MCP device info files found using " << spath.to_string() << std::endl; return; } - if (devinfos->empty()) { - error << "No MCP device info files found using " << spath.to_string() << endmsg; - std::cerr << "No MCP device info files found using " << spath.to_string() << std::endl; - return; - } - - for (vector::iterator i = devinfos->begin(); i != devinfos->end(); ++i) { - string fullpath = *(*i); + for (vector::iterator i = devinfos.begin(); i != devinfos.end(); ++i) { + string fullpath = *i; XMLTree tree; - if (!tree.read (fullpath.c_str())) { continue; } @@ -509,9 +502,6 @@ DeviceInfo::reload_device_info () device_info[di.name()] = di; } } - - vector_delete (devinfos); - delete devinfos; } std::ostream& operator<< (std::ostream& os, const Mackie::DeviceInfo& di) diff --git a/libs/surfaces/mackie/device_profile.cc b/libs/surfaces/mackie/device_profile.cc index 73e885d8c5..42b70830cb 100644 --- a/libs/surfaces/mackie/device_profile.cc +++ b/libs/surfaces/mackie/device_profile.cc @@ -90,25 +90,20 @@ DeviceProfile::reload_device_profiles () { DeviceProfile dp; vector s; - vector *devprofiles; + vector devprofiles; PathScanner scanner; Searchpath spath (devprofile_search_path()); devprofiles = scanner (spath.to_string(), devprofile_filter, 0, false, true); device_profiles.clear (); - if (!devprofiles) { + if (devprofiles.empty()) { error << "No MCP device info files found using " << spath.to_string() << endmsg; return; } - if (devprofiles->empty()) { - error << "No MCP device info files found using " << spath.to_string() << endmsg; - return; - } - - for (vector::iterator i = devprofiles->begin(); i != devprofiles->end(); ++i) { - string fullpath = *(*i); + for (vector::iterator i = devprofiles.begin(); i != devprofiles.end(); ++i) { + string fullpath = *i; XMLTree tree; @@ -126,9 +121,6 @@ DeviceProfile::reload_device_profiles () device_profiles[dp.name()] = dp; } } - - vector_delete (devprofiles); - delete devprofiles; } int From f220d011320528ab08bee25d9ce790bcd0c637f2 Mon Sep 17 00:00:00 2001 From: Tim Mayberry Date: Tue, 17 Jun 2014 10:44:36 +1000 Subject: [PATCH 02/12] Remove member filter argument from PathScanner methods and use normal filter for regex Also use regfree to free memory of compiled patterns --- libs/pbd/pathscanner.cc | 53 +++++++++++++++++++++----------------- libs/pbd/pbd/pathscanner.h | 10 +------ 2 files changed, 30 insertions(+), 33 deletions(-) diff --git a/libs/pbd/pathscanner.cc b/libs/pbd/pathscanner.cc index bd010e66c5..05e90b599b 100644 --- a/libs/pbd/pathscanner.cc +++ b/libs/pbd/pathscanner.cc @@ -44,6 +44,14 @@ using PBD::closedir; using namespace std; using namespace PBD; +static +bool +regexp_filter (const string& str, void *arg) +{ + regex_t* pattern = (regex_t*)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, @@ -52,6 +60,8 @@ PathScanner::operator() (const string &dirpath, const string ®exp, { int err; char msg[256]; + regex_t compiled_pattern; + vector result; if ((err = regcomp (&compiled_pattern, regexp.c_str(), REG_EXTENDED|REG_NOSUB))) { @@ -67,17 +77,20 @@ PathScanner::operator() (const string &dirpath, const string ®exp, return vector(); } - return run_scan (dirpath, &PathScanner::regexp_filter, - (bool (*)(const string &, void *)) 0, - 0, - match_fullpath, - return_fullpath, - limit, recurse); + result = run_scan (dirpath, + regexp_filter, + &compiled_pattern, + match_fullpath, + return_fullpath, + limit, recurse); + + regfree (&compiled_pattern); + + return result; } vector PathScanner::run_scan (const string &dirpath, - bool (PathScanner::*memberfilter)(const string &), bool (*filter)(const string &, void *), void *arg, bool match_fullpath, bool return_fullpath, @@ -85,14 +98,13 @@ PathScanner::run_scan (const string &dirpath, bool recurse) { vector result; - run_scan_internal (result, dirpath, memberfilter, filter, arg, match_fullpath, return_fullpath, limit, recurse); + run_scan_internal (result, dirpath, filter, arg, match_fullpath, return_fullpath, limit, recurse); return result; } void PathScanner::run_scan_internal (vector& result, const string &dirpath, - bool (PathScanner::*memberfilter)(const string &), bool (*filter)(const string &, void *), void *arg, bool match_fullpath, bool return_fullpath, @@ -135,7 +147,7 @@ PathScanner::run_scan_internal (vector& result, } if (statbuf.st_mode & S_IFDIR && recurse) { - run_scan_internal (result, fullpath, memberfilter, filter, arg, match_fullpath, return_fullpath, limit, recurse); + run_scan_internal (result, fullpath, filter, arg, match_fullpath, return_fullpath, limit, recurse); } else { if (match_fullpath) { @@ -144,16 +156,8 @@ PathScanner::run_scan_internal (vector& result, search_str = finfo->d_name; } - /* handle either type of function ptr */ - - if (memberfilter) { - if (!(this->*memberfilter)(search_str)) { - continue; - } - } else { - if (!filter(search_str, arg)) { - continue; - } + if (!filter(search_str, arg)) { + continue; } if (return_fullpath) { @@ -182,6 +186,7 @@ PathScanner::find_first (const string &dirpath, vector res; int err; char msg[256]; + regex_t compiled_pattern; if ((err = regcomp (&compiled_pattern, regexp.c_str(), REG_EXTENDED|REG_NOSUB))) { @@ -195,13 +200,14 @@ PathScanner::find_first (const string &dirpath, } run_scan_internal (res, dirpath, - &PathScanner::regexp_filter, - (bool (*)(const string &, void *)) 0, - 0, + ®exp_filter, + &compiled_pattern, match_fullpath, return_fullpath, 1); + regfree (&compiled_pattern); + if (res.size() == 0) { return string(); } @@ -221,7 +227,6 @@ PathScanner::find_first (const string &dirpath, run_scan_internal (res, dirpath, - (bool (PathScanner::*)(const string &)) 0, filter, 0, match_fullpath, diff --git a/libs/pbd/pbd/pathscanner.h b/libs/pbd/pbd/pathscanner.h index 990aa44c77..de23d7c645 100644 --- a/libs/pbd/pbd/pathscanner.h +++ b/libs/pbd/pbd/pathscanner.h @@ -42,7 +42,6 @@ class LIBPBD_API PathScanner long limit = -1, bool recurse = false) { return run_scan (dirpath, - (bool (PathScanner::*)(const std::string &)) 0, filter, arg, match_fullpath, @@ -69,14 +68,8 @@ class LIBPBD_API PathScanner bool return_fullpath = true); private: - regex_t compiled_pattern; - - bool regexp_filter (const std::string &str) { - return regexec (&compiled_pattern, str.c_str(), 0, 0, 0) == 0; - } - + std::vector run_scan (const std::string &dirpath, - bool (PathScanner::*mfilter) (const std::string &), bool (*filter)(const std::string &, void *), void *arg, bool match_fullpath, @@ -86,7 +79,6 @@ class LIBPBD_API PathScanner void run_scan_internal (std::vector&, const std::string &dirpath, - bool (PathScanner::*mfilter) (const std::string &), bool (*filter)(const std::string &, void *), void *arg, bool match_fullpath, From f54092dadac9e177e925f3c59cf033a7b1b4c9ce Mon Sep 17 00:00:00 2001 From: Tim Mayberry Date: Tue, 17 Jun 2014 11:15:10 +1000 Subject: [PATCH 03/12] Add PathScanner::find_files_matching_regex and move regexp usage to one place --- libs/pbd/pathscanner.cc | 69 ++++++++++++++++++-------------------- libs/pbd/pbd/pathscanner.h | 8 +++++ 2 files changed, 41 insertions(+), 36 deletions(-) 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, From 3066bd48da29c84e9a491b809c81d512babd869c Mon Sep 17 00:00:00 2001 From: Tim Mayberry Date: Tue, 17 Jun 2014 11:22:52 +1000 Subject: [PATCH 04/12] Remove PathScanner::run_scan and use PathScanner::run_scan_internal directly --- libs/pbd/pathscanner.cc | 23 ++++------------------- libs/pbd/pbd/pathscanner.h | 20 ++++++-------------- 2 files changed, 10 insertions(+), 33 deletions(-) diff --git a/libs/pbd/pathscanner.cc b/libs/pbd/pathscanner.cc index 1a197b27aa..29c339c087 100644 --- a/libs/pbd/pathscanner.cc +++ b/libs/pbd/pathscanner.cc @@ -78,12 +78,10 @@ PathScanner::find_files_matching_regex (vector& result, return; } - result = run_scan (dirpath, - regexp_filter, - &compiled_pattern, - match_fullpath, - return_fullpath, - limit, recurse); + run_scan_internal (result, dirpath, + regexp_filter, &compiled_pattern, + match_fullpath, return_fullpath, + limit, recurse); regfree (&compiled_pattern); } @@ -105,19 +103,6 @@ PathScanner::operator() (const string &dirpath, const string ®exp, return result; } - -vector -PathScanner::run_scan (const string &dirpath, - bool (*filter)(const string &, void *), - void *arg, - bool match_fullpath, bool return_fullpath, - long limit, - bool recurse) -{ - vector result; - run_scan_internal (result, dirpath, filter, arg, match_fullpath, return_fullpath, limit, recurse); - return result; -} void PathScanner::run_scan_internal (vector& result, diff --git a/libs/pbd/pbd/pathscanner.h b/libs/pbd/pbd/pathscanner.h index 4d9ef56e15..d97cbb7693 100644 --- a/libs/pbd/pbd/pathscanner.h +++ b/libs/pbd/pbd/pathscanner.h @@ -41,12 +41,12 @@ class LIBPBD_API PathScanner bool return_fullpath = true, long limit = -1, bool recurse = false) { - return run_scan (dirpath, - filter, - arg, - match_fullpath, - return_fullpath, - limit, recurse); + std::vector result; + run_scan_internal (result, dirpath, + filter, arg, + match_fullpath, return_fullpath, + limit, recurse); + return result; } std::vector operator() (const std::string &dirpath, @@ -77,14 +77,6 @@ class LIBPBD_API PathScanner long limit, bool recurse = false); - std::vector run_scan (const std::string &dirpath, - bool (*filter)(const std::string &, void *), - void *arg, - bool match_fullpath, - bool return_fullpath, - long limit, - bool recurse = false); - void run_scan_internal (std::vector&, const std::string &dirpath, bool (*filter)(const std::string &, void *), From cde8776e8014a84b9e9feb860b537679daeb1aaf Mon Sep 17 00:00:00 2001 From: Tim Mayberry Date: Tue, 17 Jun 2014 11:32:51 +1000 Subject: [PATCH 05/12] Rename PathScanner::run_scan_internal to PathScanner::find_files_matching_filter --- libs/pbd/pathscanner.cc | 33 ++++++++++++++------------------- libs/pbd/pbd/pathscanner.h | 24 ++++++++++++------------ 2 files changed, 26 insertions(+), 31 deletions(-) diff --git a/libs/pbd/pathscanner.cc b/libs/pbd/pathscanner.cc index 29c339c087..eb19c08fe9 100644 --- a/libs/pbd/pathscanner.cc +++ b/libs/pbd/pathscanner.cc @@ -78,10 +78,10 @@ PathScanner::find_files_matching_regex (vector& result, return; } - run_scan_internal (result, dirpath, - regexp_filter, &compiled_pattern, - match_fullpath, return_fullpath, - limit, recurse); + find_files_matching_filter (result, dirpath, + regexp_filter, &compiled_pattern, + match_fullpath, return_fullpath, + limit, recurse); regfree (&compiled_pattern); } @@ -105,13 +105,13 @@ PathScanner::operator() (const string &dirpath, const string ®exp, } void -PathScanner::run_scan_internal (vector& result, - const string &dirpath, - bool (*filter)(const string &, void *), - void *arg, - bool match_fullpath, bool return_fullpath, - long limit, - bool recurse) +PathScanner::find_files_matching_filter (vector& result, + const string &dirpath, + bool (*filter)(const string &, void *), + void *arg, + bool match_fullpath, bool return_fullpath, + long limit, + bool recurse) { DIR *dir; struct dirent *finfo; @@ -149,7 +149,7 @@ PathScanner::run_scan_internal (vector& result, } if (statbuf.st_mode & S_IFDIR && recurse) { - run_scan_internal (result, fullpath, filter, arg, match_fullpath, return_fullpath, limit, recurse); + find_files_matching_filter (result, fullpath, filter, arg, match_fullpath, return_fullpath, limit, recurse); } else { if (match_fullpath) { @@ -205,14 +205,9 @@ PathScanner::find_first (const string &dirpath, bool return_fullpath) { vector res; - string ret; - run_scan_internal (res, - dirpath, - filter, - 0, - match_fullpath, - return_fullpath, 1); + find_files_matching_filter (res, dirpath, filter, 0, + match_fullpath, return_fullpath, 1); if (res.size() == 0) { return string(); diff --git a/libs/pbd/pbd/pathscanner.h b/libs/pbd/pbd/pathscanner.h index d97cbb7693..28ff2c5dcb 100644 --- a/libs/pbd/pbd/pathscanner.h +++ b/libs/pbd/pbd/pathscanner.h @@ -42,10 +42,10 @@ class LIBPBD_API PathScanner long limit = -1, bool recurse = false) { std::vector result; - run_scan_internal (result, dirpath, - filter, arg, - match_fullpath, return_fullpath, - limit, recurse); + find_files_matching_filter (result, dirpath, + filter, arg, + match_fullpath, return_fullpath, + limit, recurse); return result; } @@ -77,14 +77,14 @@ class LIBPBD_API PathScanner long limit, bool recurse = false); - void run_scan_internal (std::vector&, - const std::string &dirpath, - bool (*filter)(const std::string &, void *), - void *arg, - bool match_fullpath, - bool return_fullpath, - long limit, - bool recurse = false); + void find_files_matching_filter (std::vector&, + const std::string &dirpath, + bool (*filter)(const std::string &, void *), + void *arg, + bool match_fullpath, + bool return_fullpath, + long limit, + bool recurse = false); }; #endif // __libmisc_pathscanner_h__ From b457c938cd0fc005deb332a11bf7cc9c9463e2bc Mon Sep 17 00:00:00 2001 From: Tim Mayberry Date: Tue, 17 Jun 2014 11:39:04 +1000 Subject: [PATCH 06/12] Remove unused methods in PathScanner Now that these methods are only a few lines it doesn't make much sense to keep them seeing as they are unused. There are also functions with near identical functionality in pbd/file_utils.h --- libs/pbd/pathscanner.cc | 37 ------------------------------------- libs/pbd/pbd/pathscanner.h | 13 +------------ 2 files changed, 1 insertion(+), 49 deletions(-) diff --git a/libs/pbd/pathscanner.cc b/libs/pbd/pathscanner.cc index eb19c08fe9..fee1ffc84c 100644 --- a/libs/pbd/pathscanner.cc +++ b/libs/pbd/pathscanner.cc @@ -178,40 +178,3 @@ PathScanner::find_files_matching_filter (vector& result, free (pathcopy); return; } - -string -PathScanner::find_first (const string &dirpath, - const string ®exp, - bool match_fullpath, - bool return_fullpath) -{ - vector res; - - find_files_matching_regex (res, dirpath, regexp, - match_fullpath, return_fullpath, 1); - - if (res.size() == 0) { - return string(); - } - - return res.front(); -} - -string -PathScanner::find_first (const string &dirpath, - bool (*filter)(const string &, void *), - void * /*arg*/, - bool match_fullpath, - bool return_fullpath) -{ - vector res; - - find_files_matching_filter (res, dirpath, filter, 0, - match_fullpath, return_fullpath, 1); - - if (res.size() == 0) { - return string(); - } - - return res.front(); -} diff --git a/libs/pbd/pbd/pathscanner.h b/libs/pbd/pbd/pathscanner.h index 28ff2c5dcb..a3a2b76237 100644 --- a/libs/pbd/pbd/pathscanner.h +++ b/libs/pbd/pbd/pathscanner.h @@ -55,18 +55,7 @@ class LIBPBD_API PathScanner bool return_fullpath = true, long limit = -1, bool recurse = false); - - std::string find_first (const std::string &dirpath, - const std::string ®exp, - bool match_fullpath = true, - bool return_fullpath = true); - - std::string find_first (const std::string &dirpath, - bool (*filter)(const std::string &, void *), - void *arg, - bool match_fullpath = true, - bool return_fullpath = true); - + private: void find_files_matching_regex (std::vector& results, From ea5f9a8ea62f774258cd056e61e61648f91fe46e Mon Sep 17 00:00:00 2001 From: Tim Mayberry Date: Tue, 17 Jun 2014 11:48:46 +1000 Subject: [PATCH 07/12] Move PathScanner::operator() into header --- libs/pbd/pathscanner.cc | 18 ------------------ libs/pbd/pbd/pathscanner.h | 14 +++++++++++++- 2 files changed, 13 insertions(+), 19 deletions(-) diff --git a/libs/pbd/pathscanner.cc b/libs/pbd/pathscanner.cc index fee1ffc84c..a320ec8d54 100644 --- a/libs/pbd/pathscanner.cc +++ b/libs/pbd/pathscanner.cc @@ -85,24 +85,6 @@ PathScanner::find_files_matching_regex (vector& result, 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; -} void PathScanner::find_files_matching_filter (vector& result, diff --git a/libs/pbd/pbd/pathscanner.h b/libs/pbd/pbd/pathscanner.h index a3a2b76237..d9522affe3 100644 --- a/libs/pbd/pbd/pathscanner.h +++ b/libs/pbd/pbd/pathscanner.h @@ -54,7 +54,19 @@ class LIBPBD_API PathScanner bool match_fullpath = true, bool return_fullpath = true, long limit = -1, - bool recurse = false); + bool recurse = false) + { + std::vector result; + + find_files_matching_regex (result, + dirpath, + regexp, + match_fullpath, + return_fullpath, + limit, recurse); + + return result; + } private: From dc81ab8640107086c71b910c0a5d9c12f873d27d Mon Sep 17 00:00:00 2001 From: Tim Mayberry Date: Tue, 17 Jun 2014 12:16:37 +1000 Subject: [PATCH 08/12] Move member functions from PathScanner to functions in pbd/file_utils.h This allows us to remove PathScanner source file and keep PathScanner class as header only until it is removed --- libs/pbd/file_utils.cc | 128 ++++++++++++++++++++++++++++- libs/pbd/pathscanner.cc | 162 ------------------------------------- libs/pbd/pbd/file_utils.h | 26 ++++++ libs/pbd/pbd/pathscanner.h | 41 +++------- libs/pbd/wscript | 1 - 5 files changed, 165 insertions(+), 193 deletions(-) delete mode 100644 libs/pbd/pathscanner.cc diff --git a/libs/pbd/file_utils.cc b/libs/pbd/file_utils.cc index 552012d227..7e58f0fed5 100644 --- a/libs/pbd/file_utils.cc +++ b/libs/pbd/file_utils.cc @@ -1,5 +1,6 @@ /* - Copyright (C) 2007 Tim Mayberry + Copyright (C) 2007-2014 Tim Mayberry + Copyright (C) 1998-2014 Paul Davis This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -42,8 +43,15 @@ /* close(), read(), write() */ #ifdef COMPILER_MSVC #include // Microsoft's nearest equivalent to +#include #else +#include #include +#include +#endif + +#ifdef PLATFORM_WINDOWS +#define strtok_r strtok_s #endif #include "pbd/compose.h" @@ -51,6 +59,7 @@ #include "pbd/debug.h" #include "pbd/error.h" #include "pbd/pathscanner.h" +#include "pbd/pathexpand.h" #include "pbd/stl_delete.h" #include "i18n.h" @@ -161,6 +170,123 @@ find_file_in_search_path(const Searchpath& search_path, return true; } +static +bool +regexp_filter (const string& str, void *arg) +{ + regex_t* pattern = (regex_t*)arg; + return regexec (pattern, str.c_str(), 0, 0, 0) == 0; +} + +void +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; + + 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; + } + + find_files_matching_filter (result, dirpath, + regexp_filter, &compiled_pattern, + match_fullpath, return_fullpath, + limit, recurse); + + regfree (&compiled_pattern); +} + +void +find_files_matching_filter (vector& result, + const string &dirpath, + bool (*filter)(const string &, void *), + void *arg, + bool match_fullpath, bool return_fullpath, + long limit, + bool recurse) +{ + DIR *dir; + struct dirent *finfo; + char *pathcopy = strdup (search_path_expand (dirpath).c_str()); + char *thisdir; + string fullpath; + string search_str; + long nfound = 0; + char *saveptr; + + if ((thisdir = strtok_r (pathcopy, G_SEARCHPATH_SEPARATOR_S, &saveptr)) == 0 || + strlen (thisdir) == 0) { + free (pathcopy); + return; + } + + do { + + if ((dir = opendir (thisdir)) == 0) { + continue; + } + + while ((finfo = readdir (dir)) != 0) { + + if ((finfo->d_name[0] == '.' && finfo->d_name[1] == '\0') || + (finfo->d_name[0] == '.' && finfo->d_name[1] == '.' && finfo->d_name[2] == '\0')) { + continue; + } + + fullpath = Glib::build_filename (thisdir, finfo->d_name); + + struct stat statbuf; + if (stat (fullpath.c_str(), &statbuf) < 0) { + continue; + } + + if (statbuf.st_mode & S_IFDIR && recurse) { + find_files_matching_filter (result, fullpath, filter, arg, match_fullpath, return_fullpath, limit, recurse); + } else { + + if (match_fullpath) { + search_str = fullpath; + } else { + search_str = finfo->d_name; + } + + if (!filter(search_str, arg)) { + continue; + } + + if (return_fullpath) { + result.push_back(fullpath); + } else { + result.push_back(finfo->d_name); + } + + nfound++; + } + } + closedir (dir); + + } while ((limit < 0 || (nfound < limit)) && (thisdir = strtok_r (0, G_SEARCHPATH_SEPARATOR_S, &saveptr))); + + free (pathcopy); + return; +} + bool copy_file(const std::string & from_path, const std::string & to_path) { diff --git a/libs/pbd/pathscanner.cc b/libs/pbd/pathscanner.cc deleted file mode 100644 index a320ec8d54..0000000000 --- a/libs/pbd/pathscanner.cc +++ /dev/null @@ -1,162 +0,0 @@ -/* - Copyright (C) 1998-99 Paul Barton-Davis - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - - $Id$ -*/ - -#ifdef COMPILER_MSVC -#include -#include -using PBD::readdir; -using PBD::opendir; -using PBD::closedir; -#define strtok_r strtok_s // @john: this should probably go to msvc_extra_headers/ardourext/misc.h.input instead of the current define there -#else -#include -#include -#include -#endif -#include -#include -#include -#include - -#include - -#include "pbd/error.h" -#include "pbd/pathexpand.h" -#include "pbd/pathscanner.h" - -using namespace std; -using namespace PBD; - -static -bool -regexp_filter (const string& str, void *arg) -{ - regex_t* pattern = (regex_t*)arg; - return regexec (pattern, str.c_str(), 0, 0, 0) == 0; -} - -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; - - 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; - } - - find_files_matching_filter (result, dirpath, - regexp_filter, &compiled_pattern, - match_fullpath, return_fullpath, - limit, recurse); - - regfree (&compiled_pattern); -} - -void -PathScanner::find_files_matching_filter (vector& result, - const string &dirpath, - bool (*filter)(const string &, void *), - void *arg, - bool match_fullpath, bool return_fullpath, - long limit, - bool recurse) -{ - DIR *dir; - struct dirent *finfo; - char *pathcopy = strdup (search_path_expand (dirpath).c_str()); - char *thisdir; - string fullpath; - string search_str; - long nfound = 0; - char *saveptr; - - if ((thisdir = strtok_r (pathcopy, G_SEARCHPATH_SEPARATOR_S, &saveptr)) == 0 || - strlen (thisdir) == 0) { - free (pathcopy); - return; - } - - do { - - if ((dir = opendir (thisdir)) == 0) { - continue; - } - - while ((finfo = readdir (dir)) != 0) { - - if ((finfo->d_name[0] == '.' && finfo->d_name[1] == '\0') || - (finfo->d_name[0] == '.' && finfo->d_name[1] == '.' && finfo->d_name[2] == '\0')) { - continue; - } - - fullpath = Glib::build_filename (thisdir, finfo->d_name); - - struct stat statbuf; - if (stat (fullpath.c_str(), &statbuf) < 0) { - continue; - } - - if (statbuf.st_mode & S_IFDIR && recurse) { - find_files_matching_filter (result, fullpath, filter, arg, match_fullpath, return_fullpath, limit, recurse); - } else { - - if (match_fullpath) { - search_str = fullpath; - } else { - search_str = finfo->d_name; - } - - if (!filter(search_str, arg)) { - continue; - } - - if (return_fullpath) { - result.push_back(fullpath); - } else { - result.push_back(finfo->d_name); - } - - nfound++; - } - } - closedir (dir); - - } while ((limit < 0 || (nfound < limit)) && (thisdir = strtok_r (0, G_SEARCHPATH_SEPARATOR_S, &saveptr))); - - free (pathcopy); - return; -} diff --git a/libs/pbd/pbd/file_utils.h b/libs/pbd/pbd/file_utils.h index 01ff8606a7..51fb2c1ad1 100644 --- a/libs/pbd/pbd/file_utils.h +++ b/libs/pbd/pbd/file_utils.h @@ -92,6 +92,32 @@ find_file_in_search_path (const Searchpath& search_path, const std::string& filename, std::string& result); + +/** + * @return files in dirpath that match a regular expression + */ +LIBPBD_API 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); + +/** + * @return files in dirpath that match a supplied filter(functor) + */ +LIBPBD_API void +find_files_matching_filter (std::vector&, + const std::string &dirpath, + bool (*filter)(const std::string &, void *), + void *arg, + bool match_fullpath, + bool return_fullpath, + long limit, + bool recurse = false); + /** * Attempt to copy the contents of the file from_path to a new file * at path to_path. If to_path exists it is overwritten. diff --git a/libs/pbd/pbd/pathscanner.h b/libs/pbd/pbd/pathscanner.h index d9522affe3..e4d2f6aa0e 100644 --- a/libs/pbd/pbd/pathscanner.h +++ b/libs/pbd/pbd/pathscanner.h @@ -30,6 +30,8 @@ #include "pbd/libpbd_visibility.h" +#include "pbd/file_utils.h" + class LIBPBD_API PathScanner { @@ -42,10 +44,10 @@ class LIBPBD_API PathScanner long limit = -1, bool recurse = false) { std::vector result; - find_files_matching_filter (result, dirpath, - filter, arg, - match_fullpath, return_fullpath, - limit, recurse); + PBD::find_files_matching_filter (result, dirpath, + filter, arg, + match_fullpath, return_fullpath, + limit, recurse); return result; } @@ -58,34 +60,15 @@ class LIBPBD_API PathScanner { std::vector result; - find_files_matching_regex (result, - dirpath, - regexp, - match_fullpath, - return_fullpath, - limit, recurse); + PBD::find_files_matching_regex (result, + dirpath, + regexp, + match_fullpath, + return_fullpath, + limit, recurse); return result; } - - 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); - - void find_files_matching_filter (std::vector&, - const std::string &dirpath, - bool (*filter)(const std::string &, void *), - void *arg, - bool match_fullpath, - bool return_fullpath, - long limit, - bool recurse = false); }; #endif // __libmisc_pathscanner_h__ diff --git a/libs/pbd/wscript b/libs/pbd/wscript index 2ba79d0c34..35f4b4c5c7 100644 --- a/libs/pbd/wscript +++ b/libs/pbd/wscript @@ -57,7 +57,6 @@ libpbd_sources = [ 'mountpoint.cc', 'openuri.cc', 'pathexpand.cc', - 'pathscanner.cc', 'pbd.cc', 'pool.cc', 'property_list.cc', From 26285a3bc01eda0627802ac8aee4b9e18c937527 Mon Sep 17 00:00:00 2001 From: Tim Mayberry Date: Tue, 17 Jun 2014 12:37:43 +1000 Subject: [PATCH 09/12] Add default arguments to match those in PathScanner::operator() --- libs/pbd/pbd/file_utils.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/pbd/pbd/file_utils.h b/libs/pbd/pbd/file_utils.h index 51fb2c1ad1..8a3b014ba5 100644 --- a/libs/pbd/pbd/file_utils.h +++ b/libs/pbd/pbd/file_utils.h @@ -102,7 +102,7 @@ find_files_matching_regex (std::vector& results, const std::string& regexp, bool match_fullpath, bool return_fullpath, - long limit, + long limit = -1, bool recurse = false); /** @@ -115,7 +115,7 @@ find_files_matching_filter (std::vector&, void *arg, bool match_fullpath, bool return_fullpath, - long limit, + long limit = -1, bool recurse = false); /** From cb6934a189ce3940cdfa05dd5e302a8006afa83f Mon Sep 17 00:00:00 2001 From: Tim Mayberry Date: Tue, 17 Jun 2014 12:53:12 +1000 Subject: [PATCH 10/12] Remove unused header includes --- libs/ardour/session.cc | 1 - libs/ardour/smf_source.cc | 1 - libs/ardour/system_exec.cc | 1 - libs/ardour/vst_plugin.cc | 1 - libs/gtkmm2ext/selector.cc | 2 -- 5 files changed, 6 deletions(-) diff --git a/libs/ardour/session.cc b/libs/ardour/session.cc index fbde7edf60..95d319b4d8 100644 --- a/libs/ardour/session.cc +++ b/libs/ardour/session.cc @@ -38,7 +38,6 @@ #include "pbd/error.h" #include "pbd/boost_debug.h" -#include "pbd/pathscanner.h" #include "pbd/stl_delete.h" #include "pbd/basename.h" #include "pbd/stacktrace.h" diff --git a/libs/ardour/smf_source.cc b/libs/ardour/smf_source.cc index 34eec3b4a6..b0ba6c9bfc 100644 --- a/libs/ardour/smf_source.cc +++ b/libs/ardour/smf_source.cc @@ -26,7 +26,6 @@ #include #include -#include "pbd/pathscanner.h" #include "pbd/stl_delete.h" #include "pbd/strsplit.h" diff --git a/libs/ardour/system_exec.cc b/libs/ardour/system_exec.cc index 760a9b7878..d5c3f31903 100644 --- a/libs/ardour/system_exec.cc +++ b/libs/ardour/system_exec.cc @@ -19,7 +19,6 @@ */ #include -#include "pbd/pathscanner.h" #include "pbd/file_utils.h" #include "pbd/error.h" diff --git a/libs/ardour/vst_plugin.cc b/libs/ardour/vst_plugin.cc index a18cc07356..24020e8356 100644 --- a/libs/ardour/vst_plugin.cc +++ b/libs/ardour/vst_plugin.cc @@ -25,7 +25,6 @@ #include "pbd/floating.h" #include "pbd/locale_guard.h" -#include "pbd/pathscanner.h" #include "ardour/vst_plugin.h" #include "ardour/vestige/aeffectx.h" diff --git a/libs/gtkmm2ext/selector.cc b/libs/gtkmm2ext/selector.cc index e4b95d1e03..97f468707b 100644 --- a/libs/gtkmm2ext/selector.cc +++ b/libs/gtkmm2ext/selector.cc @@ -25,8 +25,6 @@ #include #include -#include "pbd/pathscanner.h" - #include "gtkmm2ext/keyboard.h" #include "gtkmm2ext/selector.h" #include "gtkmm2ext/utils.h" From 547689a0552661108806a4028960f32d1b20adf8 Mon Sep 17 00:00:00 2001 From: Tim Mayberry Date: Tue, 17 Jun 2014 21:41:29 +1000 Subject: [PATCH 11/12] Replace all use of PathScanner with equivalent functions from pbd/file_utils.h --- libs/ardour/audio_unit.cc | 17 ++++------ libs/ardour/lv2_plugin.cc | 6 ++-- libs/ardour/panner_manager.cc | 5 ++- libs/ardour/plugin_manager.cc | 33 ++++++------------- libs/ardour/session_state.cc | 20 +++-------- libs/ardour/template_utils.cc | 8 ++--- libs/pbd/file_utils.cc | 5 ++- .../generic_midi_control_protocol.cc | 5 ++- libs/surfaces/mackie/device_info.cc | 5 ++- libs/surfaces/mackie/device_profile.cc | 5 ++- 10 files changed, 37 insertions(+), 72 deletions(-) diff --git a/libs/ardour/audio_unit.cc b/libs/ardour/audio_unit.cc index cf489751cb..5423fc1688 100644 --- a/libs/ardour/audio_unit.cc +++ b/libs/ardour/audio_unit.cc @@ -28,7 +28,7 @@ #include "pbd/xml++.h" #include "pbd/convert.h" #include "pbd/whitespace.h" -#include "pbd/pathscanner.h" +#include "pbd/file_utils.h" #include "pbd/locale_guard.h" #include @@ -2049,20 +2049,19 @@ AUPlugin::current_preset() const void AUPlugin::find_presets () { - vector* preset_files; - PathScanner scanner; + vector preset_files; user_preset_map.clear (); - preset_files = scanner (preset_search_path, au_preset_filter, this, true, true, -1, true); + find_files_matching_filter (preset_files, preset_search_path, au_preset_filter, this, true, true, -1, true); - if (!preset_files) { + if (preset_files.empty()) { return; } - for (vector::iterator x = preset_files->begin(); x != preset_files->end(); ++x) { + for (vector::iterator x = preset_files.begin(); x != preset_files.end(); ++x) { - string path = *(*x); + string path = *x; string preset_name; /* make an initial guess at the preset name using the path */ @@ -2079,12 +2078,8 @@ AUPlugin::find_presets () user_preset_map[preset_name] = path; } - delete *x; } - vector_delete (preset_files); - delete preset_files; - /* now fill the vector with the names we have */ for (UserPresetMap::iterator i = user_preset_map.begin(); i != user_preset_map.end(); ++i) { diff --git a/libs/ardour/lv2_plugin.cc b/libs/ardour/lv2_plugin.cc index d68c4e5077..6ae99302da 100644 --- a/libs/ardour/lv2_plugin.cc +++ b/libs/ardour/lv2_plugin.cc @@ -32,7 +32,7 @@ #include #include "pbd/clear_dir.h" -#include "pbd/pathscanner.h" +#include "pbd/file_utils.h" #include "pbd/stl_delete.h" #include "pbd/compose.h" #include "pbd/error.h" @@ -2013,10 +2013,10 @@ void LV2World::load_bundled_plugins() { if (!_bundle_checked) { - PathScanner scanner; cout << "Scanning folders for bundled LV2s: " << ARDOUR::lv2_bundled_search_path().to_string() << endl; - vector plugin_objects = scanner (ARDOUR::lv2_bundled_search_path().to_string(), lv2_filter, 0, true, true); + vector plugin_objects; + find_files_matching_filter (plugin_objects, ARDOUR::lv2_bundled_search_path().to_string(), lv2_filter, 0, true, true); for ( vector::iterator x = plugin_objects.begin(); x != plugin_objects.end (); ++x) { #ifdef PLATFORM_WINDOWS string uri = "file:///" + *x + "/"; diff --git a/libs/ardour/panner_manager.cc b/libs/ardour/panner_manager.cc index 2988a8ab46..c23d6b5951 100644 --- a/libs/ardour/panner_manager.cc +++ b/libs/ardour/panner_manager.cc @@ -24,7 +24,7 @@ #include "pbd/error.h" #include "pbd/compose.h" -#include "pbd/pathscanner.h" +#include "pbd/file_utils.h" #include "pbd/stl_delete.h" #include "ardour/debug.h" @@ -90,13 +90,12 @@ static bool panner_filter (const string& str, void */*arg*/) void PannerManager::discover_panners () { - PathScanner scanner; std::vector panner_modules; std::string search_path = panner_search_path().to_string(); DEBUG_TRACE (DEBUG::Panning, string_compose (_("looking for panners in %1\n"), search_path)); - panner_modules = scanner (search_path, panner_filter, 0, false, true, 1, true); + find_files_matching_filter (panner_modules, search_path, panner_filter, 0, false, true, 1, true); for (vector::iterator i = panner_modules.begin(); i != panner_modules.end(); ++i) { panner_discover (*i); diff --git a/libs/ardour/plugin_manager.cc b/libs/ardour/plugin_manager.cc index c1e596ff3d..7399d30f89 100644 --- a/libs/ardour/plugin_manager.cc +++ b/libs/ardour/plugin_manager.cc @@ -50,7 +50,6 @@ #include #include -#include "pbd/pathscanner.h" #include "pbd/whitespace.h" #include "pbd/file_utils.h" @@ -242,10 +241,8 @@ PluginManager::clear_vst_cache () // see also libs/ardour/vst_info_file.cc - vstfx_infofile_path() #ifdef WINDOWS_VST_SUPPORT { - PathScanner scanner; vector fsi_files; - - fsi_files = scanner (Config->get_plugin_path_vst(), "\\.fsi$", true, true, -1, false); + find_files_matching_regex (fsi_files, Config->get_plugin_path_vst(), "\\.fsi$", true, true, -1, false); for (vector::iterator i = fsi_files.begin(); i != fsi_files.end (); ++i) { ::g_unlink(i->c_str()); } @@ -254,9 +251,8 @@ PluginManager::clear_vst_cache () #ifdef LXVST_SUPPORT { - PathScanner scanner; vector fsi_files; - fsi_files = scanner (Config->get_plugin_path_lxvst(), "\\.fsi$", true, true, -1, false); + find_files_matching_regex (fsi_files, Config->get_plugin_path_lxvst(), "\\.fsi$", true, true, -1, false); for (vector::iterator i = fsi_files.begin(); i != fsi_files.end (); ++i) { ::g_unlink(i->c_str()); } @@ -266,9 +262,8 @@ PluginManager::clear_vst_cache () #if (defined WINDOWS_VST_SUPPORT || defined LXVST_SUPPORT) { string personal = get_personal_vst_info_cache_dir(); - PathScanner scanner; vector fsi_files; - fsi_files = scanner (personal, "\\.fsi$", true, true, -1, false); + find_files_matching_regex (fsi_files, personal, "\\.fsi$", true, true, -1, false); for (vector::iterator i = fsi_files.begin(); i != fsi_files.end (); ++i) { ::g_unlink(i->c_str()); } @@ -281,10 +276,8 @@ PluginManager::clear_vst_blacklist () { #ifdef WINDOWS_VST_SUPPORT { - PathScanner scanner; vector fsi_files; - - fsi_files = scanner (Config->get_plugin_path_vst(), "\\.fsb$", true, true, -1, false); + find_files_matching_regex (fsi_files, Config->get_plugin_path_vst(), "\\.fsb$", true, true, -1, false); for (vector::iterator i = fsi_files.begin(); i != fsi_files.end (); ++i) { ::g_unlink(i->c_str()); } @@ -293,9 +286,8 @@ PluginManager::clear_vst_blacklist () #ifdef LXVST_SUPPORT { - PathScanner scanner; vector fsi_files; - fsi_files = scanner (Config->get_plugin_path_lxvst(), "\\.fsb$", true, true, -1, false); + find_files_matching_regex (fsi_files, Config->get_plugin_path_lxvst(), "\\.fsb$", true, true, -1, false); for (vector::iterator i = fsi_files.begin(); i != fsi_files.end (); ++i) { ::g_unlink(i->c_str()); } @@ -306,9 +298,8 @@ PluginManager::clear_vst_blacklist () { string personal = get_personal_vst_blacklist_dir(); - PathScanner scanner; vector fsi_files; - fsi_files = scanner (personal, "\\.fsb$", true, true, -1, false); + find_files_matching_regex (fsi_files, personal, "\\.fsb$", true, true, -1, false); for (vector::iterator i = fsi_files.begin(); i != fsi_files.end (); ++i) { ::g_unlink(i->c_str()); } @@ -385,7 +376,6 @@ void PluginManager::add_presets(string domain) { #ifdef HAVE_LRDF - PathScanner scanner; vector presets; vector::iterator x; @@ -395,7 +385,7 @@ PluginManager::add_presets(string domain) } string path = string_compose("%1/.%2/rdf", envvar, domain); - presets = scanner (path, rdf_filter, 0, false, true); + find_files_matching_filter (presets, path, rdf_filter, 0, false, true); for (x = presets.begin(); x != presets.end (); ++x) { string file = "file:" + *x; @@ -411,11 +401,10 @@ void PluginManager::add_lrdf_data (const string &path) { #ifdef HAVE_LRDF - PathScanner scanner; vector rdf_files; vector::iterator x; - rdf_files = scanner (path, rdf_filter, 0, false, true); + find_files_matching_filter (rdf_files, path, rdf_filter, 0, false, true); for (x = rdf_files.begin(); x != rdf_files.end (); ++x) { const string uri(string("file://") + *x); @@ -628,14 +617,13 @@ static bool windows_vst_filter (const string& str, void * /*arg*/) int PluginManager::windows_vst_discover_from_path (string path, bool cache_only) { - PathScanner scanner; vector plugin_objects; vector::iterator x; int ret = 0; DEBUG_TRACE (DEBUG::PluginManager, string_compose ("detecting Windows VST plugins along %1\n", path)); - plugin_objects = scanner (Config->get_plugin_path_vst(), windows_vst_filter, 0, false, true); + find_files_matching_filter (plugin_objects, Config->get_plugin_path_vst(), windows_vst_filter, 0, false, true); for (x = plugin_objects.begin(); x != plugin_objects.end (); ++x) { ARDOUR::PluginScanMessage(_("VST"), *x, !cache_only && !cancelled()); @@ -744,7 +732,6 @@ static bool lxvst_filter (const string& str, void *) int PluginManager::lxvst_discover_from_path (string path, bool cache_only) { - PathScanner scanner; vector plugin_objects; vector::iterator x; int ret = 0; @@ -755,7 +742,7 @@ PluginManager::lxvst_discover_from_path (string path, bool cache_only) DEBUG_TRACE (DEBUG::PluginManager, string_compose ("Discovering linuxVST plugins along %1\n", path)); - plugin_objects = scanner (Config->get_plugin_path_lxvst(), lxvst_filter, 0, false, true); + find_files_matching_filter (plugin_objects, Config->get_plugin_path_lxvst(), lxvst_filter, 0, false, true); for (x = plugin_objects.begin(); x != plugin_objects.end (); ++x) { ARDOUR::PluginScanMessage(_("LXVST"), *x, !cache_only && !cancelled()); diff --git a/libs/ardour/session_state.cc b/libs/ardour/session_state.cc index 9151ebf5eb..43d756d826 100644 --- a/libs/ardour/session_state.cc +++ b/libs/ardour/session_state.cc @@ -69,7 +69,6 @@ #include "pbd/error.h" #include "pbd/file_utils.h" #include "pbd/pathexpand.h" -#include "pbd/pathscanner.h" #include "pbd/pthread_utils.h" #include "pbd/stacktrace.h" #include "pbd/convert.h" @@ -2319,8 +2318,8 @@ remove_end(string state) vector Session::possible_states (string path) { - PathScanner scanner; - vector states = scanner (path, state_file_filter, 0, false, false); + vector states; + find_files_matching_filter (states, path, state_file_filter, 0, false, false); transform(states.begin(), states.end(), states.begin(), remove_end); @@ -2553,7 +2552,6 @@ Session::find_all_sources (string path, set& result) int Session::find_all_sources_across_snapshots (set& result, bool exclude_this_snapshot) { - PathScanner scanner; vector state_files; string ripped; string this_snapshot_path; @@ -2566,7 +2564,7 @@ Session::find_all_sources_across_snapshots (set& result, bool exclude_th ripped = ripped.substr (0, ripped.length() - 1); } - state_files = scanner (ripped, accept_all_state_files, (void *) 0, true, true); + find_files_matching_filter (state_files, ripped, accept_all_state_files, (void *) 0, true, true); if (state_files.empty()) { /* impossible! */ @@ -2633,13 +2631,11 @@ Session::cleanup_sources (CleanupReport& rep) // FIXME: needs adaptation to midi vector > dead_sources; - PathScanner scanner; string audio_path; string midi_path; vector::iterator i; vector::iterator nexti; vector candidates; - vector candidates2; vector unused; set all_sources; bool used; @@ -2721,14 +2717,8 @@ Session::cleanup_sources (CleanupReport& rep) i = nexti; } - candidates = scanner (audio_path, accept_all_audio_files, (void *) 0, true, true); - candidates2 = scanner (midi_path, accept_all_midi_files, (void *) 0, true, true); - - /* merge them */ - - for (vector::iterator i = candidates2.begin(); i != candidates2.end(); ++i) { - candidates.push_back (*i); - } + find_files_matching_filter (candidates, audio_path, accept_all_audio_files, (void *) 0, true, true); + find_files_matching_filter (candidates, midi_path, accept_all_midi_files, (void *) 0, true, true); /* find all sources, but don't use this snapshot because the state file on disk still references sources we may have already diff --git a/libs/ardour/template_utils.cc b/libs/ardour/template_utils.cc index 20530ca9cc..64f6ce75ab 100644 --- a/libs/ardour/template_utils.cc +++ b/libs/ardour/template_utils.cc @@ -23,7 +23,7 @@ #include #include "pbd/basename.h" -#include "pbd/pathscanner.h" +#include "pbd/file_utils.h" #include "pbd/stl_delete.h" #include "pbd/xml++.h" @@ -82,10 +82,9 @@ void find_session_templates (vector& template_names) { vector templates; - PathScanner scanner; Searchpath spath (template_search_path()); - templates = scanner (spath.to_string(), template_filter, 0, true, true); + find_files_matching_filter (templates, spath.to_string(), template_filter, 0, true, true); if (templates.empty()) { cerr << "Found nothing along " << spath.to_string() << endl; @@ -116,10 +115,9 @@ void find_route_templates (vector& template_names) { vector templates; - PathScanner scanner; Searchpath spath (route_template_search_path()); - templates = scanner (spath.to_string(), route_template_filter, 0, false, true); + find_files_matching_filter (templates, spath.to_string(), route_template_filter, 0, false, true); if (templates.empty()) { return; diff --git a/libs/pbd/file_utils.cc b/libs/pbd/file_utils.cc index 7e58f0fed5..dba185ba79 100644 --- a/libs/pbd/file_utils.cc +++ b/libs/pbd/file_utils.cc @@ -58,7 +58,6 @@ #include "pbd/file_utils.h" #include "pbd/debug.h" #include "pbd/error.h" -#include "pbd/pathscanner.h" #include "pbd/pathexpand.h" #include "pbd/stl_delete.h" @@ -354,8 +353,8 @@ bool accept_all_files (string const &, void *) void copy_files(const std::string & from_path, const std::string & to_dir) { - PathScanner scanner; - vector files = scanner (from_path, accept_all_files, 0, true, false); + vector files; + find_files_matching_filter (files, from_path, accept_all_files, 0, true, false); for (vector::iterator i = files.begin(); i != files.end(); ++i) { std::string from = Glib::build_filename (from_path, *i); diff --git a/libs/surfaces/generic_midi/generic_midi_control_protocol.cc b/libs/surfaces/generic_midi/generic_midi_control_protocol.cc index 7a9104cfdb..86b7f6e463 100644 --- a/libs/surfaces/generic_midi/generic_midi_control_protocol.cc +++ b/libs/surfaces/generic_midi/generic_midi_control_protocol.cc @@ -28,7 +28,7 @@ #include "pbd/controllable_descriptor.h" #include "pbd/error.h" #include "pbd/failed_constructor.h" -#include "pbd/pathscanner.h" +#include "pbd/file_utils.h" #include "pbd/xml++.h" #include "midi++/port.h" @@ -137,11 +137,10 @@ void GenericMidiControlProtocol::reload_maps () { vector midi_maps; - PathScanner scanner; Searchpath spath (system_midi_map_search_path()); spath += user_midi_map_directory (); - midi_maps = scanner (spath.to_string(), midi_map_filter, 0, false, true); + find_files_matching_filter (midi_maps, spath.to_string(), midi_map_filter, 0, false, true); if (midi_maps.empty()) { cerr << "No MIDI maps found using " << spath.to_string() << endl; diff --git a/libs/surfaces/mackie/device_info.cc b/libs/surfaces/mackie/device_info.cc index 672bb25511..c0675c8377 100644 --- a/libs/surfaces/mackie/device_info.cc +++ b/libs/surfaces/mackie/device_info.cc @@ -23,7 +23,7 @@ #include "pbd/xml++.h" #include "pbd/error.h" -#include "pbd/pathscanner.h" +#include "pbd/file_utils.h" #include "pbd/convert.h" #include "pbd/stl_delete.h" @@ -472,10 +472,9 @@ DeviceInfo::reload_device_info () DeviceInfo di; vector s; vector devinfos; - PathScanner scanner; Searchpath spath (devinfo_search_path()); - devinfos = scanner (spath.to_string(), devinfo_filter, 0, false, true); + find_files_matching_filter (devinfos, spath.to_string(), devinfo_filter, 0, false, true); device_info.clear (); if (devinfos.empty()) { diff --git a/libs/surfaces/mackie/device_profile.cc b/libs/surfaces/mackie/device_profile.cc index 42b70830cb..269ff36aca 100644 --- a/libs/surfaces/mackie/device_profile.cc +++ b/libs/surfaces/mackie/device_profile.cc @@ -24,7 +24,7 @@ #include "pbd/xml++.h" #include "pbd/error.h" -#include "pbd/pathscanner.h" +#include "pbd/file_utils.h" #include "pbd/stl_delete.h" #include "pbd/replace_all.h" @@ -91,10 +91,9 @@ DeviceProfile::reload_device_profiles () DeviceProfile dp; vector s; vector devprofiles; - PathScanner scanner; Searchpath spath (devprofile_search_path()); - devprofiles = scanner (spath.to_string(), devprofile_filter, 0, false, true); + find_files_matching_filter (devprofiles, spath.to_string(), devprofile_filter, 0, false, true); device_profiles.clear (); if (devprofiles.empty()) { From 3aa2a4ac8c046b548792dffb9032953d5d5211e2 Mon Sep 17 00:00:00 2001 From: Tim Mayberry Date: Tue, 17 Jun 2014 13:29:31 +1000 Subject: [PATCH 12/12] Remove PathScanner class from libpbd --- libs/pbd/pbd/pathscanner.h | 74 -------------------------------------- 1 file changed, 74 deletions(-) delete mode 100644 libs/pbd/pbd/pathscanner.h diff --git a/libs/pbd/pbd/pathscanner.h b/libs/pbd/pbd/pathscanner.h deleted file mode 100644 index e4d2f6aa0e..0000000000 --- a/libs/pbd/pbd/pathscanner.h +++ /dev/null @@ -1,74 +0,0 @@ -/* - Copyright (C) 2000-2007 Paul Davis - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - -*/ - -#ifndef __libmisc_pathscanner_h__ -#define __libmisc_pathscanner_h__ - -#include -#include -#ifdef COMPILER_MSVC -#include -#else -#include -#endif - -#include "pbd/libpbd_visibility.h" - -#include "pbd/file_utils.h" - -class LIBPBD_API PathScanner - -{ - public: - std::vector operator() (const std::string &dirpath, - bool (*filter)(const std::string &, void *arg), - void *arg, - bool match_fullpath = true, - bool return_fullpath = true, - long limit = -1, - bool recurse = false) { - std::vector result; - PBD::find_files_matching_filter (result, dirpath, - filter, arg, - match_fullpath, return_fullpath, - limit, recurse); - return result; - } - - std::vector operator() (const std::string &dirpath, - const std::string ®exp, - bool match_fullpath = true, - bool return_fullpath = true, - long limit = -1, - bool recurse = false) - { - std::vector result; - - PBD::find_files_matching_regex (result, - dirpath, - regexp, - match_fullpath, - return_fullpath, - limit, recurse); - - return result; - } -}; - -#endif // __libmisc_pathscanner_h__