mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-04-23 11:42:49 -06:00
cleanup
Simplify the implementation of writeUTF8File and use it in one more place. Remove unused imports left over after a previous change.
This commit is contained in:
@@ -188,16 +188,14 @@ putPointE v opts msg act = do
|
|||||||
-- * File IO
|
-- * File IO
|
||||||
|
|
||||||
writeUTF8File :: FilePath -> String -> IO ()
|
writeUTF8File :: FilePath -> String -> IO ()
|
||||||
writeUTF8File fpath content = do
|
writeUTF8File fpath content =
|
||||||
h <- openFile fpath WriteMode
|
withFile fpath WriteMode $ \ h -> do hSetEncoding h utf8
|
||||||
hSetEncoding h utf8
|
hPutStr h content
|
||||||
hPutStr h content
|
|
||||||
hClose h
|
|
||||||
|
|
||||||
readBinaryFile path = hGetContents =<< openBinaryFile path ReadMode
|
readBinaryFile path = hGetContents =<< openBinaryFile path ReadMode
|
||||||
writeBinaryFile path s = withBinaryFile path WriteMode (flip hPutStr s)
|
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.
|
-- calls to fail.
|
||||||
ioErrorText e = if isUserError e
|
ioErrorText e = if isUserError e
|
||||||
then ioeGetErrorString e
|
then ioeGetErrorString e
|
||||||
|
|||||||
@@ -117,11 +117,7 @@ grammarName opts pgf = fromMaybe (showCId (absname pgf)) (flag optName opts)
|
|||||||
|
|
||||||
writeOutput :: Options -> FilePath-> String -> IOE ()
|
writeOutput :: Options -> FilePath-> String -> IOE ()
|
||||||
writeOutput opts file str =
|
writeOutput opts file str =
|
||||||
do let path = case flag optOutputDir opts of
|
putPointE Normal opts ("Writing " ++ path ++ "...") $ ioeIO $
|
||||||
Nothing -> file
|
writeUTF8File path str
|
||||||
Just dir -> dir </> file
|
where
|
||||||
putPointE Normal opts ("Writing " ++ path ++ "...") $ ioeIO $
|
path = maybe id (</>) (flag optOutputDir opts) file
|
||||||
bracket
|
|
||||||
(openFile path WriteMode)
|
|
||||||
(hClose)
|
|
||||||
(\h -> hSetEncoding h utf8 >> hPutStr h str)
|
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ import Data.List(nub,isPrefixOf,isInfixOf,partition)
|
|||||||
import qualified Data.Map as Map
|
import qualified Data.Map as Map
|
||||||
import qualified Data.ByteString.Char8 as BS
|
import qualified Data.ByteString.Char8 as BS
|
||||||
import qualified Text.ParserCombinators.ReadP as RP
|
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.CPUTime(getCPUTime)
|
||||||
import System.Directory({-getCurrentDirectory,-}getAppUserDataDirectory)
|
import System.Directory({-getCurrentDirectory,-}getAppUserDataDirectory)
|
||||||
import Control.Exception(SomeException,fromException,evaluate,try)
|
import Control.Exception(SomeException,fromException,evaluate,try)
|
||||||
|
|||||||
Reference in New Issue
Block a user