{-# LANGUAGE CPP #-}
{-# OPTIONS_GHC -cpp #-}
module CIO (
Handle, HandlePosn, IOMode(..), BufferMode(..), SeekMode(..),
stdin, stdout, stderr,
isAlreadyExistsError, isDoesNotExistError, isAlreadyInUseError,
isFullError, isEOFError, isIllegalOperation, isPermissionError,
isUserError,
ioeGetErrorString, ioeGetHandle, ioeGetFileName,
openFileCIO, hCloseCIO,
putCharCIO, putStrCIO, hPutStrCIO, hPutStrLnCIO, writeFileCIO,
readFileCIO, printCIO, getCharCIO, hFlushCIO, hPutCharCIO,
hGetContentsCIO, hSetBufferingCIO, hGetBufferingCIO,
newlineCIO,
doesFileExistCIO, removeFileCIO,
ExitCode(..), exitWithCIO, getArgsCIO, getProgNameCIO,
fileFindInCIO, mktempCIO)
where
import System.IO
import System.IO.Error
import System.Cmd
import System.Directory
import System.Exit
import System.Environment
#if __GLASGOW_HASKELL__ >= 612
import System.IO (hSetEncoding, latin1)
#endif
import FileOps (fileFindIn, mktemp)
import StateBase (PreCST, liftIO)
openFileCIO :: FilePath -> IOMode -> PreCST e s Handle
openFileCIO p m = liftIO $ do
hnd <- openFile p m
#if __GLASGOW_HASKELL__ >= 612
hSetEncoding hnd latin1
#endif
return hnd
hCloseCIO :: Handle -> PreCST e s ()
hCloseCIO h = liftIO (hClose h)
putCharCIO :: Char -> PreCST e s ()
putCharCIO c = liftIO (putChar c)
putStrCIO :: String -> PreCST e s ()
putStrCIO s = liftIO (putStr s)
hPutStrCIO :: Handle -> String -> PreCST e s ()
hPutStrCIO h s = liftIO (hPutStr h s)
hPutStrLnCIO :: Handle -> String -> PreCST e s ()
hPutStrLnCIO h s = liftIO (hPutStrLn h s)
writeFileCIO :: FilePath -> String -> PreCST e s ()
writeFileCIO fname contents = do
hnd <- openFileCIO fname WriteMode
hPutStrCIO hnd contents
hCloseCIO hnd
readFileCIO :: FilePath -> PreCST e s String
readFileCIO fname = do
hnd <- openFileCIO fname ReadMode
liftIO (hGetContents hnd)
hGetContentsCIO :: Handle -> PreCST e s String
hGetContentsCIO hnd = liftIO (hGetContents hnd)
printCIO :: Show a => a -> PreCST e s ()
printCIO a = liftIO (print a)
getCharCIO :: PreCST e s Char
getCharCIO = liftIO getChar
hFlushCIO :: Handle -> PreCST e s ()
hFlushCIO h = liftIO (hFlush h)
hPutCharCIO :: Handle -> Char -> PreCST e s ()
hPutCharCIO h ch = liftIO (hPutChar h ch)
hSetBufferingCIO :: Handle -> BufferMode -> PreCST e s ()
hSetBufferingCIO h m = liftIO (hSetBuffering h m)
hGetBufferingCIO :: Handle -> PreCST e s BufferMode
hGetBufferingCIO h = liftIO (hGetBuffering h)
newlineCIO :: PreCST e s ()
newlineCIO = putCharCIO '\n'
doesFileExistCIO :: FilePath -> PreCST e s Bool
doesFileExistCIO = liftIO . doesFileExist
removeFileCIO :: FilePath -> PreCST e s ()
removeFileCIO = liftIO . removeFile
exitWithCIO :: ExitCode -> PreCST e s a
exitWithCIO = liftIO . exitWith
getArgsCIO :: PreCST e s [String]
getArgsCIO = liftIO getArgs
getProgNameCIO :: PreCST e s String
getProgNameCIO = liftIO getProgName
fileFindInCIO :: FilePath -> [FilePath] -> PreCST e s FilePath
fileFindInCIO file paths = liftIO $ file `fileFindIn` paths
mktempCIO :: FilePath -> FilePath -> PreCST e s (Handle, FilePath)
mktempCIO pre post = liftIO $ mktemp pre post