[project @ 2005-05-17 11:01:59 by simonmar]
authorsimonmar <unknown>
Tue, 17 May 2005 11:02:00 +0000 (11:02 +0000)
committersimonmar <unknown>
Tue, 17 May 2005 11:02:00 +0000 (11:02 +0000)
Further tweaks to the filename handling.

ghc/compiler/main/DriverMkDepend.hs
ghc/compiler/main/DriverPhases.hs
ghc/compiler/utils/Util.lhs

index c8fb955..7580ccc 100644 (file)
@@ -255,7 +255,7 @@ insertSuffixes
        -- Lots of other things will break first!
 
 insertSuffixes file_name extras
-  = file_name : [ basename ++ "." ++ extra ++ "_" ++ suffix | extra <- extras ]
+  = file_name : [ basename `joinFileExt` (extra ++ "_" ++ suffix) | extra <- extras ]
   where
     (basename, suffix) = splitFilename file_name
 
index 158f6dd..d1b24b3 100644 (file)
@@ -1,5 +1,5 @@
 -----------------------------------------------------------------------------
---  $Id: DriverPhases.hs,v 1.37 2005/05/16 13:47:58 simonmar Exp $
+--  $Id: DriverPhases.hs,v 1.38 2005/05/17 11:01:59 simonmar Exp $
 --
 -- GHC Driver
 --
@@ -33,7 +33,7 @@ module DriverPhases (
    isSourceFilename         -- :: FilePath -> Bool
  ) where
 
-import Util            ( getFileSuffix )
+import Util            ( suffixOf )
 import Panic           ( panic )
 
 -----------------------------------------------------------------------------
@@ -216,13 +216,13 @@ isDynLibSuffix           s = s `elem` dynlib_suffixes
 
 isSourceSuffix suff  = isHaskellishSuffix suff || isCishSuffix suff
 
-isHaskellishFilename     f = isHaskellishSuffix     (getFileSuffix f)
-isHaskellSrcFilename     f = isHaskellSrcSuffix     (getFileSuffix f)
-isCishFilename           f = isCishSuffix           (getFileSuffix f)
-isExtCoreFilename        f = isExtCoreSuffix        (getFileSuffix f)
-isObjectFilename         f = isObjectSuffix         (getFileSuffix f)
-isHaskellUserSrcFilename f = isHaskellUserSrcSuffix (getFileSuffix f)
-isDynLibFilename        f = isDynLibSuffix         (getFileSuffix f)
-isSourceFilename        f = isSourceSuffix         (getFileSuffix f)
+isHaskellishFilename     f = isHaskellishSuffix     (suffixOf f)
+isHaskellSrcFilename     f = isHaskellSrcSuffix     (suffixOf f)
+isCishFilename           f = isCishSuffix           (suffixOf f)
+isExtCoreFilename        f = isExtCoreSuffix        (suffixOf f)
+isObjectFilename         f = isObjectSuffix         (suffixOf f)
+isHaskellUserSrcFilename f = isHaskellUserSrcSuffix (suffixOf f)
+isDynLibFilename        f = isDynLibSuffix         (suffixOf f)
+isSourceFilename        f = isSourceSuffix         (suffixOf f)
 
 
index a36be7a..3f2b452 100644 (file)
@@ -63,9 +63,10 @@ module Util (
 
        -- Filename utils
        Suffix,
-       splitFilename, getFileSuffix, splitFilenameDir, joinFileExt, joinFileName,
-       splitFilename3, removeSuffix, 
-       dropLongestPrefix, takeLongestPrefix, splitLongestPrefix,
+       splitFilename, suffixOf, basenameOf, joinFileExt,
+       splitFilenameDir, joinFileExt, joinFileName,
+       splitFilename3,
+       splitLongestPrefix,
        replaceFilenameSuffix, directoryOf, filenameOf,
        replaceFilenameDirectory,
        escapeSpaces, isPathSeparator,
@@ -871,8 +872,11 @@ type Suffix = String
 splitFilename :: String -> (String,Suffix)
 splitFilename f = splitLongestPrefix f (=='.')
 
-getFileSuffix :: String -> Suffix
-getFileSuffix f = dropLongestPrefix f (=='.')
+basenameOf :: FilePath -> String
+basenameOf = fst . splitFilename
+
+suffixOf :: FilePath -> Suffix
+suffixOf = snd . splitFilename
 
 joinFileExt :: String -> String -> FilePath
 joinFileExt path ""  = path
@@ -899,15 +903,6 @@ joinFileName "." fname = fname
 joinFileName dir ""    = dir
 joinFileName dir fname = dir ++ '/':fname
 
-removeSuffix :: Char -> String -> Suffix
-removeSuffix c s = takeLongestPrefix s (==c)
-
-dropLongestPrefix :: String -> (Char -> Bool) -> String
-dropLongestPrefix s pred = snd (splitLongestPrefix s pred)
-
-takeLongestPrefix :: String -> (Char -> Bool) -> String
-takeLongestPrefix s pred = fst (splitLongestPrefix s pred)
-
 -- split a string at the last character where 'pred' is True,
 -- returning a pair of strings. The first component holds the string
 -- up (but not including) the last character for which 'pred' returned
@@ -924,12 +919,6 @@ splitLongestPrefix s pred
        (_:pre) -> (reverse pre, reverse suf)
   where (suf,pre) = break pred (reverse s)
 
-basenameOf :: FilePath -> String
-basenameOf = fst . splitFilename
-
-suffixOf :: FilePath -> Suffix
-suffixOf = snd . splitFilename
-
 replaceFilenameSuffix :: FilePath -> Suffix -> FilePath
 replaceFilenameSuffix file suf = basenameOf file `joinFileExt` suf