summaryrefslogtreecommitdiff
path: root/libs/pbd
diff options
context:
space:
mode:
authorTim Mayberry <mojofunk@gmail.com>2007-06-27 12:12:18 +0000
committerTim Mayberry <mojofunk@gmail.com>2007-06-27 12:12:18 +0000
commit0abcfb16ba203be43fcb2d2cd0b740da85679e7a (patch)
treea3960e9ff490dab3ff5a239acc561ae21ab23a64 /libs/pbd
parent1b77a3535304c25a49686886054db148442b1032 (diff)
Replace code for finding ControlProtocols/Surface plugins with a portable equivalent.
Remove Session::control_protocol_path and the supporting non-portable Session::suffixed_search_path from Session. Add ARDOUR::control_protocol_search_path which is used in place of Session::control_protocol_path Replace ARDOUR::get_system_module_path with ARDOUR::system_module_directory which is used by ARDOUR::control_protocol_search_path Export ARDOUR_SURFACES_PATH in gtk2_ardour/ardev_common.sh which is returned by ARDOUR::control_protocol_search_path if defined. This means the control surfaces in the libs/surfaces/* directories can now be used without installing them. Add pbd/file_utils.h/cc containing functions for finding files matching a certain pattern Update documentation in SearchPath and add another constructor that takes a sys::path git-svn-id: svn://localhost/ardour2/trunk@2049 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'libs/pbd')
-rw-r--r--libs/pbd/SConscript1
-rw-r--r--libs/pbd/file_utils.cc132
-rw-r--r--libs/pbd/pbd/file_utils.h99
-rw-r--r--libs/pbd/pbd/search_path.h16
-rw-r--r--libs/pbd/search_path.cc11
5 files changed, 252 insertions, 7 deletions
diff --git a/libs/pbd/SConscript b/libs/pbd/SConscript
index 3dee418398..bb1f56e6c7 100644
--- a/libs/pbd/SConscript
+++ b/libs/pbd/SConscript
@@ -28,6 +28,7 @@ enumwriter.cc
dmalloc.cc
error.cc
filesystem.cc
+file_utils.cc
fpu.cc
id.cc
mountpoint.cc
diff --git a/libs/pbd/file_utils.cc b/libs/pbd/file_utils.cc
new file mode 100644
index 0000000000..30ecbc0586
--- /dev/null
+++ b/libs/pbd/file_utils.cc
@@ -0,0 +1,132 @@
+/*
+ Copyright (C) 2007 Tim Mayberry
+
+ 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.
+
+*/
+
+#include <algorithm>
+
+#include <glibmm/fileutils.h>
+#include <glibmm/pattern.h>
+
+#include <pbd/compose.h>
+#include <pbd/file_utils.h>
+
+#include <pbd/error.h>
+
+namespace PBD {
+
+void
+get_files_in_directory (const sys::path& directory_path, vector<string>& result)
+{
+ if (!is_directory(directory_path)) return;
+
+ try
+ {
+ Glib::Dir dir(directory_path.to_string());
+ std::copy(dir.begin(), dir.end(), std::back_inserter(result));
+ }
+ catch (Glib::FileError& err)
+ {
+ warning << err.what();
+ }
+}
+
+void
+find_matching_files_in_directory (const sys::path& directory,
+ const Glib::PatternSpec& pattern,
+ vector<sys::path>& result)
+{
+ vector<string> tmp_files;
+
+ get_files_in_directory (directory, tmp_files);
+
+ for (vector<string>::iterator file_iter = tmp_files.begin();
+ file_iter != tmp_files.end();
+ ++file_iter)
+ {
+ if (!pattern.match(*file_iter)) continue;
+
+ sys::path full_path(directory);
+ full_path /= *file_iter;
+
+ result.push_back(full_path);
+ }
+}
+
+void
+find_matching_files_in_directories (const vector<sys::path>& paths,
+ const Glib::PatternSpec& pattern,
+ vector<sys::path>& result)
+{
+ for (vector<sys::path>::const_iterator path_iter = paths.begin();
+ path_iter != paths.end();
+ ++path_iter)
+ {
+ find_matching_files_in_directory (*path_iter, pattern, result);
+ }
+}
+
+void
+find_matching_files_in_search_path (const SearchPath& search_path,
+ const Glib::PatternSpec& pattern,
+ vector<sys::path>& result)
+{
+ vector<sys::path> dirs;
+ std::copy(search_path.begin(), search_path.end(), std::back_inserter(dirs));
+ find_matching_files_in_directories (dirs, pattern, result);
+}
+
+bool
+find_file_in_search_path(const SearchPath& search_path,
+ const string& filename,
+ sys::path& result)
+{
+ vector<sys::path> tmp;
+ Glib::PatternSpec tmp_pattern(filename);
+
+ find_matching_files_in_search_path (search_path, tmp_pattern, tmp);
+
+ if (tmp.size() == 0)
+ {
+ info << string_compose
+ (
+ "Found no file named %1 in search path %2",
+ filename,
+ search_path.get_string ()
+ )
+ << endmsg;
+
+ return false;
+ }
+
+ if (tmp.size() != 1)
+ {
+ info << string_compose
+ (
+ "Found more than one file matching %1 in search path %2",
+ filename,
+ search_path.get_string ()
+ )
+ << endmsg;
+ }
+
+ result = tmp.front();
+
+ return true;
+}
+
+} // namespace PBD
diff --git a/libs/pbd/pbd/file_utils.h b/libs/pbd/pbd/file_utils.h
new file mode 100644
index 0000000000..a9832ce720
--- /dev/null
+++ b/libs/pbd/pbd/file_utils.h
@@ -0,0 +1,99 @@
+/*
+ Copyright (C) 2007 Tim Mayberry
+
+ 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 PBD_FILE_UTILS_INCLUDED
+#define PBD_FILE_UTILS_INCLUDED
+
+#include <string>
+#include <vector>
+
+#include <glibmm/pattern.h>
+
+#include <pbd/search_path.h>
+
+namespace PBD {
+
+using std::string;
+using std::vector;
+
+/**
+ * Get a list of files in a directory.
+ * @note You must join path with result to get the absolute path
+ * to the file.
+ *
+ * @param path An Absolute path to a directory
+ * @param result A vector of filenames.
+ */
+void
+get_files_in_directory (const sys::path& path,
+ vector<string>& result);
+
+/**
+ * Takes a directory path and returns all the files in the directory
+ * matching a particular pattern.
+ *
+ * @param directory A directory path
+ * @param pattern A Glib::PatternSpec used to match the files.
+ * @param result A vector in which to place the resulting matches.
+ */
+void
+find_matching_files_in_directory (const sys::path& directory,
+ const Glib::PatternSpec& pattern,
+ vector<sys::path>& result);
+
+/**
+ * Takes a number of directory paths and returns all the files matching
+ * a particular pattern.
+ *
+ * @param paths A vector containing the Absolute paths
+ * @param pattern A Glib::PatternSpec used to match the files
+ * @param result A vector in which to place the resulting matches.
+ */
+void
+find_matching_files_in_directories (const vector<sys::path>& directory_paths,
+ const Glib::PatternSpec& pattern,
+ vector<sys::path>& result);
+
+/**
+ * Takes a SearchPath and puts a list of all the files in the search path
+ * that match pattern into the result vector.
+ *
+ * @param search_path A SearchPath
+ * @param pattern A Glib::PatternSpec used to match the files
+ * @param result A vector in which to place the resulting matches.
+ */
+void
+find_matching_files_in_search_path (const SearchPath& search_path,
+ const Glib::PatternSpec& pattern,
+ vector<sys::path>& result);
+
+/**
+ * Takes a search path and a file name and place the full path
+ * to that file in result if it is found within the search path.
+ *
+ * @return true If file is found within the search path.
+ */
+bool
+find_file_in_search_path (const SearchPath& search_path,
+ const string& filename,
+ sys::path& result);
+
+} // namespace PBD
+
+#endif
diff --git a/libs/pbd/pbd/search_path.h b/libs/pbd/pbd/search_path.h
index 18f05ef014..e51d5de4ad 100644
--- a/libs/pbd/pbd/search_path.h
+++ b/libs/pbd/pbd/search_path.h
@@ -53,14 +53,26 @@ public:
SearchPath ();
/**
- * Initialize SearchPath from a string each path may or may not
- * exist.
+ * Initialize SearchPath from a string where the string contains
+ * one or more absolute paths to directories which are delimited
+ * by a path separation character. The path delimeter is a
+ * colon(:) on unix and a semi-colon(;) on windows.
+ *
+ * Each path contained in the search path may or may not resolve to
+ * an existing directory in the filesystem.
*
* @param search_path A path string.
*/
SearchPath (const string& search_path);
/**
+ * Initialize SearchPath from a sys::path.
+ *
+ * @param directory_path A directory path.
+ */
+ SearchPath (const sys::path& directory_path);
+
+ /**
* Initialize SearchPath from a vector of paths that may or may
* not exist.
*
diff --git a/libs/pbd/search_path.cc b/libs/pbd/search_path.cc
index 146fd7eaf0..b3590ba7bd 100644
--- a/libs/pbd/search_path.cc
+++ b/libs/pbd/search_path.cc
@@ -42,14 +42,15 @@ SearchPath::SearchPath (const string& path)
{
vector<sys::path> tmp;
- if(!tokenize ( path, string(path_delimiter), std::back_inserter (tmp)))
+ if(tokenize (path, string(path_delimiter), std::back_inserter (tmp)))
{
- // log warning(info perhaps?) that the path is empty
- warning << "SearchPath contains no tokens" << endmsg;
-
+ add_directories (tmp);
}
+}
- add_directories (tmp);
+SearchPath::SearchPath (const sys::path& directory_path)
+{
+ add_directory (directory_path);
}
SearchPath::SearchPath (const vector<sys::path>& paths)