28 #include <glibmm/fileutils.h>
29 #include <glibmm/miscutils.h>
56 realpath (
const char *original_path,
char resolved_path[
_MAX_PATH+1])
59 bool bIsSymLink =
false;
76 rpath = _fullpath (temp, Glib::locale_from_utf8 (original_path).c_str(),
_MAX_PATH);
79 snprintf (resolved_path,
_MAX_PATH+1,
"%s", Glib::locale_to_utf8 (temp).c_str());
87 #endif // COMPILER_MINGW
94 if (realpath (path.c_str(), buf) == NULL) {
96 string_compose(
"PBD::canonical_path: Unable to resolve %1: %2\n", path, g_strerror(errno)));
101 string_compose(
"PBD::canonical_path %1 resolved to: %2\n", path,
string(buf)));
115 if (path[0] ==
'~') {
116 if (path.length() == 1) {
117 return Glib::get_home_dir();
120 if (path[1] ==
'/') {
121 path.replace (0, 1, Glib::get_home_dir());
129 regex_t compiled_pattern;
130 const int nmatches = 100;
131 regmatch_t matches[nmatches];
133 if (regcomp (&compiled_pattern,
"\\$([a-zA-Z_][a-zA-Z0-9_]*|\\{[a-zA-Z_][a-zA-Z0-9_]*\\})", REG_EXTENDED)) {
134 std::cerr <<
"bad regcomp\n";
140 if (regexec (&compiled_pattern, path.c_str(), nmatches, matches, 0)) {
146 string match = path.substr (matches[0].rm_so, matches[0].rm_eo - matches[0].rm_so);
150 if (match[1] ==
'{') {
152 match = match.substr (2, match.length() - 3);
155 char* matched_value = getenv (match.c_str());
158 path.replace (matches[0].rm_so, matches[0].rm_eo - matches[0].rm_so, matched_value);
160 path.replace (matches[0].rm_so, matches[0].rm_eo - matches[0].rm_so,
string());
168 regfree (&compiled_pattern);
185 split (path, s, G_SEARCHPATH_SEPARATOR);
187 for (vector<string>::iterator i = s.begin(); i != s.end(); ++i) {
196 for (vector<string>::iterator i = n.begin(); i != n.end(); ++i) {
198 r += G_SEARCHPATH_SEPARATOR;
206 std::vector <std::string>
209 vector <std::string> pathlist;
210 vector <std::string> tmp;
211 PBD::tokenize (path,
string(G_SEARCHPATH_SEPARATOR_S), std::back_inserter (tmp));
213 for(vector<std::string>::const_iterator i = tmp.begin(); i != tmp.end(); ++i) {
214 if ((*i).empty())
continue;
216 #ifndef PLATFORM_WINDOWS
217 if ((*i).substr(0,1) ==
"~") {
218 dir = Glib::build_filename(Glib::get_home_dir(), (*i).substr(1));
225 if (!check_if_exists || Glib::file_test (dir, Glib::FILE_TEST_IS_DIR)) {
226 pathlist.push_back(dir);
LIBPBD_API std::string path_expand(std::string path)
LIBPBD_API void split(std::string, std::vector< std::string > &, char)
unsigned int tokenize(const StringType &str, const StringType &delims, Iter it, bool strip_whitespace=false)
LIBPBD_API std::vector< std::string > parse_path(std::string path, bool check_if_exists=false)
#define DEBUG_TRACE(bits, str)
LIBPBD_API std::string search_path_expand(std::string path)
std::string string_compose(const std::string &fmt, const T1 &o1)
LIBPBD_API std::string canonical_path(const std::string &path)