touch, -- String -> String -> IO ()
copy, -- String -> String -> String -> IO ()
- unDosifyPath, -- String -> String
+ normalisePath, -- FilePath -> FilePath
-- Temporary-file management
setTmpDir,
where
-- get_proto returns a Unix-format path (relying on getExecDir to do so too)
get_proto | notNull minusbs
- = return (unDosifyPath (drop 2 (last minusbs))) -- 2 for "-B"
+ = return (normalisePath (drop 2 (last minusbs))) -- 2 for "-B"
| otherwise
= do { maybe_exec_dir <- getExecDir -- Get directory of executable
; case maybe_exec_dir of -- (only works on Windows;
String -- the filepath/filename portion
| Option String
-showOpt (FileOption pre f) = pre ++ dosifyPath f
+showOpt (FileOption pre f) = pre ++ platformPath f
showOpt (Option "") = ""
showOpt (Option s) = s
to the Windows command.
The alternative, of using '/' consistently on Unix and '\' on Windows,
-proved quite awkward. There were a lot more calls to dosifyPath,
+proved quite awkward. There were a lot more calls to platformPath,
and even on Windows we might invoke a unix-like utility (eg 'sh'), which
interpreted a command line 'foo\baz' as 'foobaz'.
\begin{code}
-----------------------------------------------------------------------------
--- Convert filepath into MSDOS form.
+-- Convert filepath into platform / MSDOS form.
-dosifyPaths :: [String] -> [String]
--- dosifyPaths does two things
+-- platformPath does two things
-- a) change '/' to '\'
-- b) remove initial '/cygdrive/'
-unDosifyPath :: String -> String
+normalisePath :: String -> String
-- Just change '\' to '/'
pgmPath :: String -- Directory string in Unix format
#if defined(mingw32_HOST_OS)
-
--------------------- Windows version ------------------
-dosifyPaths xs = map dosifyPath xs
-
-unDosifyPath xs = subst '\\' '/' xs
-
-pgmPath dir pgm = dosifyPath dir ++ '\\' : pgm
+normalisePath xs = subst '\\' '/' xs
+platformPath p = subst '/' '\\' p
+pgmPath dir pgm = platformPath dir ++ '\\' : pgm
-dosifyPath stuff
- = subst '/' '\\' real_stuff
- where
- -- fully convince myself that /cygdrive/ prefixes cannot
- -- really appear here.
- cygdrive_prefix = "/cygdrive/"
-
- real_stuff
- | cygdrive_prefix `isPrefixOf` stuff = dropList cygdrive_prefix stuff
- | otherwise = stuff
-
+subst a b ls = map (\ x -> if x == a then b else x) ls
#else
-
---------------------- Unix version ---------------------
-dosifyPaths ps = ps
-unDosifyPath xs = xs
-pgmPath dir pgm = dir ++ '/' : pgm
-dosifyPath stuff = stuff
+--------------------- Non-Windows version --------------
+normalisePath xs = xs
+pgmPath dir pgm = dir ++ '/' : pgm
+platformPath stuff = stuff
--------------------------------------------------------
#endif
-subst a b ls = map (\ x -> if x == a then b else x) ls
\end{code}
if ret == 0 then free buf >> return Nothing
else do s <- peekCString buf
free buf
- return (Just (reverse (dropList "/bin/ghc.exe" (reverse (unDosifyPath s)))))
-
+ return (Just (rootDir s))
+ where
+ rootDir s = reverse (dropList "/bin/ghc.exe" (reverse (normalisePath s)))
foreign import stdcall "GetModuleFileNameA" unsafe
getModuleFileName :: Ptr () -> CString -> Int -> IO Int32