summaryrefslogtreecommitdiffstats
path: root/Source/cmSystemTools.cxx
diff options
context:
space:
mode:
authorBill Hoffman <bill.hoffman@kitware.com>2007-02-22 02:24:17 (GMT)
committerBill Hoffman <bill.hoffman@kitware.com>2007-02-22 02:24:17 (GMT)
commit5647e6e254f82a81997cd3913f872b06fe761f1e (patch)
tree50022ba8365b2c196965087a23a86cb848e36302 /Source/cmSystemTools.cxx
parent806001bbb633a27624e9a0f5e564cab3bfefb0c3 (diff)
downloadCMake-5647e6e254f82a81997cd3913f872b06fe761f1e.zip
CMake-5647e6e254f82a81997cd3913f872b06fe761f1e.tar.gz
CMake-5647e6e254f82a81997cd3913f872b06fe761f1e.tar.bz2
ENH: fix parens in the path with spaces in the path
Diffstat (limited to 'Source/cmSystemTools.cxx')
-rw-r--r--Source/cmSystemTools.cxx58
1 files changed, 58 insertions, 0 deletions
diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx
index 7af78fb..942f593 100644
--- a/Source/cmSystemTools.cxx
+++ b/Source/cmSystemTools.cxx
@@ -1341,6 +1341,64 @@ std::string cmSystemTools::ConvertToOutputPath(const char* path)
#endif
}
+std::string cmSystemTools::EscapeForUnixShell(std::string& result)
+{
+ // For UNIX Shell paths we need to escape () in the path
+ if(result.find_first_of("()") != result.npos)
+ {
+ std::string newResult = "";
+ char lastch = 1;
+ bool inDollarVariable = false;
+ for(const char* ch = result.c_str(); *ch != '\0'; ++ch)
+ {
+ // if it is already escaped then don't try to escape it again
+ if((*ch == ' ' || *ch == '(' || *ch == ')') && lastch != '\\')
+ {
+ if(*ch == '(' && lastch == '$')
+ {
+ inDollarVariable = true;
+ }
+ // if we are in a $(..... and we get a ) then do not escape
+ // the ) and but set inDollarVariable to false
+ else if(*ch == ')' && inDollarVariable)
+ {
+ inDollarVariable = false;
+ }
+ else
+ {
+ newResult += '\\';
+ }
+ }
+ newResult += *ch;
+ lastch = *ch;
+ }
+ return newResult;
+ }
+ return result;
+}
+
+std::string cmSystemTools::ConvertToShellPath(const char* path)
+{
+ bool useUnix = false; // assume windows
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ // if windows and force paths but not cygwin useUnix is on
+ if(s_ForceUnixPaths)
+ {
+ useUnix = true;
+ }
+#else
+ // if not win32 and maybe cygwin then unix is true
+ useUnix = true;
+#endif
+ // if unix we need to call EscapeForUnixShell as well
+ if(useUnix)
+ {
+ std::string result = cmSystemTools::ConvertToUnixOutputPath(path);
+ return cmSystemTools::EscapeForUnixShell(result);
+ }
+ return cmSystemTools::ConvertToWindowsOutputPath(path);
+}
+
std::string cmSystemTools::ConvertToRunCommandPath(const char* path)
{
#if defined(_WIN32) && !defined(__CYGWIN__)