X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=ghc%2Fcompiler%2Fmain%2FDriverUtil.hs;h=4932b9e48e132012e942c9525c04e57e04694591;hb=70b6c54b3c140d96b69287f8f400f88a0b7e9c18;hp=367ae543e92534d806d6b5eb5038335c725e1c46;hpb=ce9687a5f450014c5596b32de8e8a7b99b6389e8;p=ghc-hetmet.git diff --git a/ghc/compiler/main/DriverUtil.hs b/ghc/compiler/main/DriverUtil.hs index 367ae54..4932b9e 100644 --- a/ghc/compiler/main/DriverUtil.hs +++ b/ghc/compiler/main/DriverUtil.hs @@ -1,5 +1,5 @@ ----------------------------------------------------------------------------- --- $Id: DriverUtil.hs,v 1.33 2002/08/29 15:44:15 simonmar Exp $ +-- $Id: DriverUtil.hs,v 1.38 2003/06/04 15:47:59 simonmar Exp $ -- -- Utils for the driver -- @@ -16,11 +16,12 @@ import Util import Panic import Config ( cLeadingUnderscore ) -import EXCEPTION as Exception +import EXCEPTION ( Exception(..), finally, throwDyn, catchDyn, throw ) +import qualified EXCEPTION as Exception import DYNAMIC import DATA_IOREF ( IORef, readIORef, writeIORef ) -import Directory ( getDirectoryContents, doesDirectoryExist ) +import Directory import IO import List import Char @@ -50,7 +51,7 @@ getOptionsFromSource file | otherwise -> return [] matchOptions s - | Just s1 <- my_prefix_match "{-#" s, + | Just s1 <- my_prefix_match "{-#" s, -- -} Just s2 <- my_prefix_match "OPTIONS" (remove_spaces s1), Just s3 <- my_prefix_match "}-#" (reverse s2) = Just (reverse s3) @@ -69,11 +70,20 @@ softGetDirectoryContents d ) ----------------------------------------------------------------------------- +-- Create a hierarchy of directories + +createDirectoryHierarchy :: FilePath -> IO () +createDirectoryHierarchy dir = do + b <- doesDirectoryExist dir + when (not b) $ do + createDirectoryHierarchy (directoryOf dir) + createDirectory dir + +----------------------------------------------------------------------------- -- Verify that the 'dirname' portion of a FilePath exists. -- doesDirNameExist :: FilePath -> IO Bool -doesDirNameExist fpath = doesDirectoryExist (getdir fpath) - +doesDirNameExist fpath = doesDirectoryExist (directoryOf fpath) ----------------------------------------------------------------------------- -- Prefixing underscore to linker-level names @@ -148,6 +158,14 @@ splitFilename f = split_longest_prefix f (=='.') getFileSuffix :: String -> Suffix getFileSuffix f = drop_longest_prefix f (=='.') +-- "foo/bar/xyzzy.ext" -> ("foo/bar", "xyzzy.ext") +splitFilenameDir :: String -> (String,String) +splitFilenameDir str + = let (dir, rest) = split_longest_prefix str isPathSeparator + real_dir | null dir = "." + | otherwise = dir + in (real_dir, rest) + -- "foo/bar/xyzzy.ext" -> ("foo/bar", "xyzzy", ".ext") splitFilename3 :: String -> (String,String,Suffix) splitFilename3 str @@ -187,16 +205,17 @@ split_longest_prefix s pred (_:pre) -> (reverse pre, reverse suf) where (suf,pre) = break pred (reverse s) -newsuf :: String -> Suffix -> String -newsuf suf s = remove_suffix '.' s ++ suf +replaceFilenameSuffix :: FilePath -> Suffix -> FilePath +replaceFilenameSuffix s suf = remove_suffix '.' s ++ suf --- getdir strips the filename off the input string, returning the directory. -getdir :: String -> String -getdir s = if null dir then "." else init dir - where dir = take_longest_prefix s isPathSeparator +-- directoryOf strips the filename off the input string, returning +-- the directory. +directoryOf :: FilePath -> String +directoryOf = fst . splitFilenameDir -newdir :: String -> String -> String -newdir dir s = dir ++ '/':drop_longest_prefix s isPathSeparator +replaceFilenameDirectory :: FilePath -> String -> FilePath +replaceFilenameDirectory s dir + = dir ++ '/':drop_longest_prefix s isPathSeparator remove_spaces :: String -> String remove_spaces = reverse . dropWhile isSpace . reverse . dropWhile isSpace