Add path separator support, patch by Sam Bishop.
authorChris Lattner <sabre@nondot.org>
Wed, 27 Feb 2008 06:17:10 +0000 (06:17 +0000)
committerChris Lattner <sabre@nondot.org>
Wed, 27 Feb 2008 06:17:10 +0000 (06:17 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@47662 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/System/Path.h
lib/System/Path.cpp
lib/System/Unix/Path.inc
lib/System/Win32/Path.inc

index db1de770fc2876e33af29cd18ebd0bef90a82b61..ee860e8cf91d2553937deb3a6b3777002bd46947 100644 (file)
@@ -662,6 +662,10 @@ namespace sys {
   /// @returns true if an error occurs, false otherwise
   /// @brief Copy one file to another.
   bool CopyFile(const Path& Dest, const Path& Src, std::string* ErrMsg);
+
+  /// This is the OS-specific path separator: a colon on Unix or a semicolon
+  /// on Windows.
+  extern const char PathSeparator;
 }
 
 std::ostream& operator<<(std::ostream& strm, const sys::Path& aPath);
index 11035cfee7aa55d6ba55973905eeebd730a44934..8a1de75e478c90979d2a6abd6b3fd6d3c42053f5 100644 (file)
@@ -177,6 +177,25 @@ Path::getSuffix() const {
   return path.substr(path.rfind('.') + 1);
 }
 
+static void getPathList(const char*path, std::vector<Path>& Paths) {
+  const char* at = path;
+  const char* delim = strchr(at, PathSeparator);
+  Path tmpPath;
+  while (delim != 0) {
+    std::string tmp(at, size_t(delim-at));
+    if (tmpPath.set(tmp))
+      if (tmpPath.canRead())
+        Paths.push_back(tmpPath);
+    at = delim + 1;
+    delim = strchr(at, PathSeparator);
+  }
+
+  if (*at != 0)
+    if (tmpPath.set(std::string(at)))
+      if (tmpPath.canRead())
+        Paths.push_back(tmpPath);
+}
+
 // Include the truly platform-specific parts of this class.
 #if defined(LLVM_ON_UNIX)
 #include "Unix/Path.inc"
index 2dde37cdaee491c699b677ced18792181872d5ce..c8bdd088c3250df14f94332cf4492eff2d112bef 100644 (file)
@@ -63,6 +63,8 @@ inline bool lastIsSlash(const std::string& path) {
 namespace llvm {
 using namespace sys;
 
+extern const char sys::PathSeparator = ':';
+
 bool 
 Path::isValid() const {
   // Check some obvious things
@@ -183,25 +185,6 @@ Path::GetTemporaryDirectory(std::string* ErrMsg ) {
 #endif
 }
 
-static void getPathList(const char*path, std::vector<sys::Path>& Paths) {
-  const char* at = path;
-  const char* delim = strchr(at, ':');
-  Path tmpPath;
-  while( delim != 0 ) {
-    std::string tmp(at, size_t(delim-at));
-    if (tmpPath.set(tmp))
-      if (tmpPath.canRead())
-        Paths.push_back(tmpPath);
-    at = delim + 1;
-    delim = strchr(at, ':');
-  }
-  if (*at != 0)
-    if (tmpPath.set(std::string(at)))
-      if (tmpPath.canRead())
-        Paths.push_back(tmpPath);
-
-}
-
 void 
 Path::GetSystemLibraryPaths(std::vector<sys::Path>& Paths) {
 #ifdef LTDL_SHLIBPATH_VAR
index ff5cc0a840f4951a12d64c475db74c5f84d353a7..ee3f622ed32ab876ddb9e4723a321ab64c0b664f 100644 (file)
@@ -45,6 +45,8 @@ static void FlipBackSlashes(std::string& s) {
 namespace llvm {
 namespace sys {
 
+extern const char sys::PathSeparator = ';';
+
 bool
 Path::isValid() const {
   if (path.empty())
@@ -164,25 +166,6 @@ Path::GetRootDirectory() {
   return result;
 }
 
-static void getPathList(const char*path, std::vector<sys::Path>& Paths) {
-  const char* at = path;
-  const char* delim = strchr(at, ';');
-  Path tmpPath;
-  while (delim != 0) {
-    std::string tmp(at, size_t(delim-at));
-    if (tmpPath.set(tmp))
-      if (tmpPath.canRead())
-        Paths.push_back(tmpPath);
-    at = delim + 1;
-    delim = strchr(at, ';');
-  }
-
-  if (*at != 0)
-    if (tmpPath.set(std::string(at)))
-      if (tmpPath.canRead())
-        Paths.push_back(tmpPath);
-}
-
 void
 Path::GetSystemLibraryPaths(std::vector<sys::Path>& Paths) {
   Paths.push_back(sys::Path("C:/WINDOWS/SYSTEM32"));