diff --git a/src/compiler/GF/Infra/UseIO.hs b/src/compiler/GF/Infra/UseIO.hs index 9f2d27f3f..b559f0e92 100644 --- a/src/compiler/GF/Infra/UseIO.hs +++ b/src/compiler/GF/Infra/UseIO.hs @@ -188,16 +188,14 @@ putPointE v opts msg act = do -- * File IO writeUTF8File :: FilePath -> String -> IO () -writeUTF8File fpath content = do - h <- openFile fpath WriteMode - hSetEncoding h utf8 - hPutStr h content - hClose h +writeUTF8File fpath content = + withFile fpath WriteMode $ \ h -> do hSetEncoding h utf8 + hPutStr h content readBinaryFile path = hGetContents =<< openBinaryFile path ReadMode writeBinaryFile path s = withBinaryFile path WriteMode (flip hPutStr s) --- Because GHC adds the confusing text "user error" for failures cased by +-- | Because GHC adds the confusing text "user error" for failures caused by -- calls to fail. ioErrorText e = if isUserError e then ioeGetErrorString e diff --git a/src/compiler/GFC.hs b/src/compiler/GFC.hs index 72a986303..6dc891679 100644 --- a/src/compiler/GFC.hs +++ b/src/compiler/GFC.hs @@ -117,11 +117,7 @@ grammarName opts pgf = fromMaybe (showCId (absname pgf)) (flag optName opts) writeOutput :: Options -> FilePath-> String -> IOE () writeOutput opts file str = - do let path = case flag optOutputDir opts of - Nothing -> file - Just dir -> dir file - putPointE Normal opts ("Writing " ++ path ++ "...") $ ioeIO $ - bracket - (openFile path WriteMode) - (hClose) - (\h -> hSetEncoding h utf8 >> hPutStr h str) + putPointE Normal opts ("Writing " ++ path ++ "...") $ ioeIO $ + writeUTF8File path str + where + path = maybe id () (flag optOutputDir opts) file diff --git a/src/compiler/GFI.hs b/src/compiler/GFI.hs index 634e52164..fcd97c503 100644 --- a/src/compiler/GFI.hs +++ b/src/compiler/GFI.hs @@ -40,7 +40,7 @@ import Data.List(nub,isPrefixOf,isInfixOf,partition) import qualified Data.Map as Map import qualified Data.ByteString.Char8 as BS import qualified Text.ParserCombinators.ReadP as RP -import System.IO(utf8,mkTextEncoding,hSetEncoding,stdin,stdout,stderr) +import System.IO(utf8) --import System.CPUTime(getCPUTime) import System.Directory({-getCurrentDirectory,-}getAppUserDataDirectory) import Control.Exception(SomeException,fromException,evaluate,try)