X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=libs%2Fardour%2Futils.cc;h=c1192c4fe123acd645572cddd1bd08acbd54b6b6;hb=80ec3fb37e0156cf02a25e9b353879819b66057d;hp=4b7fdc2f9118325eddf2c9e10fdd8fbfc62248a8;hpb=a7057d69650841386a4003a6616e30b6304f8dcb;p=ardour.git diff --git a/libs/ardour/utils.cc b/libs/ardour/utils.cc index 4b7fdc2f91..c1192c4fe1 100644 --- a/libs/ardour/utils.cc +++ b/libs/ardour/utils.cc @@ -25,6 +25,7 @@ #include /* for sprintf */ #include +#include #include #include #include @@ -75,7 +76,7 @@ legalize_for_path (const string& str) pos += 1; } - return legal; + return string (legal); } string @@ -285,16 +286,41 @@ path_expand (string path) string ret = path; wordexp_t expansion; - switch (wordexp (path.c_str(), &expansion, WRDE_NOCMD|WRDE_UNDEF)) { + + /* force field expansion to avoid use whitespace, since we know this is + * a path + */ + + char *oifs = getenv ("IFS"); + setenv ("IFS", "/", 1); + int result = wordexp (path.c_str(), &expansion, WRDE_NOCMD|WRDE_UNDEF); + if (oifs) { + setenv ("IFS", oifs, 1); + } else { + unsetenv ("IFS"); + } + + switch (result) { case 0: break; + case WRDE_NOSPACE: + /* see docs on wordexp() */ + wordfree (&expansion); + /* fallthru */ default: error << string_compose (_("illegal or badly-formed string used for path (%1)"), path) << endmsg; goto out; } if (expansion.we_wordc > 1) { - error << string_compose (_("path (%1) is ambiguous"), path) << endmsg; + string all; + for (unsigned int i = 0; i < expansion.we_wordc; ++i) { + if (i > 0) { + all += " | "; + } + all += expansion.we_wordv[i]; + } + error << string_compose (_("path (%1) is ambiguous: %2"), path, all) << endmsg; goto out; } @@ -565,6 +591,13 @@ string_is_affirmative (const std::string& str) return false; } + /* the use of g_strncasecmp() is solely to get around issues with + * charsets posed by trying to use C++ for the same + * comparison. switching a std::string to its lower- or upper-case + * version has several issues, but handled by default + * in the way we desire when doing it in C. + */ + return str == "1" || str == "y" || str == "Y" || (!g_strncasecmp(str.c_str(), "yes", str.length())); }