From 5755ce4bfcb7ad4a6f3720e7c611f3fc371de748 Mon Sep 17 00:00:00 2001 From: Leonardo de Moura Date: Mon, 4 Aug 2014 14:45:23 -0700 Subject: [PATCH] fix(util/lean_path): use unix style paths when using cygwin Signed-off-by: Leonardo de Moura --- src/util/lean_path.cpp | 62 +----------------------------------------- src/util/realpath.cpp | 4 +-- 2 files changed, 3 insertions(+), 63 deletions(-) diff --git a/src/util/lean_path.cpp b/src/util/lean_path.cpp index 01d8cc382..8ffb74b31 100644 --- a/src/util/lean_path.cpp +++ b/src/util/lean_path.cpp @@ -30,7 +30,7 @@ bool is_directory(char const * pathname) { return info.st_mode & S_IFDIR; } -#if defined(LEAN_WINDOWS) +#if defined(LEAN_WINDOWS) && !defined(LEAN_CYGWIN) // Windows version #include static char g_path_sep = ';'; @@ -80,67 +80,11 @@ static std::string get_exe_location() { } #endif -#if defined(LEAN_CYGWIN) -/** - \brief Cleanup path when using cygwin. - This procedure performs two fixes, if the string contains '/'. - - 1- It replaces '/' with '\\' and ':' with ';' - - 2- Then, it replaces "\cygdrive\c\" with "c:" -*/ -static std::string fix_cygwin_path(std::string f) { - if (f.find('/') != std::string::npos) { - // Step 1. - for (auto & c : f) { - if (c == g_bad_sep) - c = g_sep; - else if (c == ':') - c = g_path_sep; - } - // Step 2. - size_t pos = 0; - size_t matchpos; - std::string cygdrive("\\cygdrive\\"); - while ((matchpos = f.find(cygdrive, pos)) != std::string::npos) { - // erase "\cygdrive\" - f = f.replace(matchpos, cygdrive.size(), ""); - // replace the next "\" with ":\" - if ((matchpos = f.find("\\", matchpos)) != std::string::npos) { - f.replace(matchpos, 1, ":\\"); - } - pos = matchpos; - } - } - return f; -} - -/** \brief Convert back to a cygwin_path */ -static std::string to_cygwin_path(std::string f) { - if (f.find('\\') != std::string::npos) { - if (f.size() > 2 && f[1] == ':') { - f = std::string("/cygdrive/") + f[0] + f.substr(2); - } - for (auto & c : f) { - if (c == g_sep) - c = g_bad_sep; - else if (c == ';') - c = ':'; - } - } - return f; -} -#endif - std::string normalize_path(std::string f) { -#if defined(LEAN_CYGWIN) - f = fix_cygwin_path(f); -#else for (auto & c : f) { if (c == g_bad_sep) c = g_sep; } -#endif return f; } @@ -284,11 +228,7 @@ char const * get_lean_path() { } void display_path(std::ostream & out, std::string const & fname) { -#if defined(LEAN_CYGWIN) - out << to_cygwin_path(fname); -#else out << fname; -#endif } std::string dirname(char const * fname) { diff --git a/src/util/realpath.cpp b/src/util/realpath.cpp index e98843571..c1a0fc412 100644 --- a/src/util/realpath.cpp +++ b/src/util/realpath.cpp @@ -8,13 +8,13 @@ Author: Leonardo de Moura #include #include "util/realpath.h" -#ifdef LEAN_WINDOWS +#if defined(LEAN_WINDOWS) && !defined(LEAN_CYGWIN) #include #endif namespace lean { std::string lrealpath(char const * fname) { -#ifdef LEAN_WINDOWS +#if defined(LEAN_WINDOWS) && !defined(LEAN_CYGWIN) constexpr unsigned BufferSize = 8192; char buffer[BufferSize]; DWORD retval = GetFullPathName(fname, BufferSize, buffer, nullptr);