[project @ 2003-06-21 20:21:04 by malcolm]
[ghc-base.git] / System / IO.hs
index cb1caab..2e7bdd0 100644 (file)
@@ -1,16 +1,14 @@
 {-# OPTIONS -fno-implicit-prelude #-}
 -----------------------------------------------------------------------------
--- 
+-- |
 -- Module      :  System.IO
 -- Copyright   :  (c) The University of Glasgow 2001
--- License     :  BSD-style (see the file libraries/core/LICENSE)
+-- License     :  BSD-style (see the file libraries/base/LICENSE)
 -- 
 -- Maintainer  :  libraries@haskell.org
 -- Stability   :  provisional
 -- Portability :  portable
 --
--- $Id: IO.hs,v 1.4 2002/02/12 10:51:06 simonmar Exp $
---
 -- The standard IO library.
 --
 -----------------------------------------------------------------------------
@@ -26,6 +24,9 @@ module System.IO (
     stdin, stdout, stderr,   -- :: Handle
 
     openFile,                 -- :: FilePath -> IOMode -> IO Handle
+#if !defined(__NHC__)
+    openBinaryFile,           -- :: FilePath -> IOMode -> IO Handle
+#endif
     hClose,                   -- :: Handle -> IO ()
     hFileSize,                -- :: Handle -> IO Integer
     hIsEOF,                   -- :: Handle -> IO Bool
@@ -33,10 +34,16 @@ module System.IO (
 
     hSetBuffering,            -- :: Handle -> BufferMode -> IO ()
     hGetBuffering,            -- :: Handle -> IO BufferMode
+#if !defined(__HUGS__) && !defined(__NHC__)
+    hSetBinaryMode,           -- :: Handle -> Bool -> IO ()
+#endif
     hFlush,                   -- :: Handle -> IO ()
     hGetPosn,                 -- :: Handle -> IO HandlePosn
     hSetPosn,                 -- :: HandlePosn -> IO ()
     hSeek,                    -- :: Handle -> SeekMode -> Integer -> IO ()
+#if !defined(__NHC__)
+    hTell,                    -- :: Handle -> IO Integer
+#endif
     hWaitForInput,            -- :: Handle -> Int -> IO Bool
     hReady,                   -- :: Handle -> IO Bool
     hGetChar,                 -- :: Handle -> IO Char
@@ -61,12 +68,8 @@ module System.IO (
     ioeGetFileName,           -- :: IOError -> Maybe FilePath
 
     try,                      -- :: IO a -> IO (Either IOError a)
-    bracket,                  -- :: IO a -> (a -> IO b) -> (a -> IO c) -> IO c
-    bracket_,                 -- :: IO a -> (a -> IO b) -> IO c -> IO c
 
-    -- Non-standard extension (but will hopefully become standard with 1.5) is
-    -- to export the Prelude io functions via IO (in addition to exporting them
-    -- from the prelude...for now.) 
+    -- re-exports of Prelude names
     IO,                               -- instance MonadFix
     FilePath,                 -- :: String
     IOError,
@@ -88,15 +91,19 @@ module System.IO (
     readIO,                   -- :: Read a => String -> IO a
     readLn,                   -- :: Read a => IO a
 
+#if !defined(__HUGS__) && !defined(__NHC__)
     hPutBuf,                  -- :: Handle -> Ptr a -> Int -> IO ()
     hGetBuf,                  -- :: Handle -> Ptr a -> Int -> IO Int
+#endif
  
     fixIO,                    -- :: (a -> IO a) -> IO a
 
+#if !defined(__HUGS__) && !defined(__NHC__)
     hSetEcho,                  -- :: Handle -> Bool -> IO ()
     hGetEcho,                  -- :: Handle -> IO Bool
 
     hIsTerminalDevice,         -- :: Handle -> IO Bool
+#endif
   ) where
 
 #ifdef __GLASGOW_HASKELL__
@@ -111,25 +118,64 @@ import GHC.Read
 import GHC.Show
 #endif
 
-import Data.Dynamic
-import Control.Monad.Fix
-import System.IO.Error
-
--- -----------------------------------------------------------------------------
--- MonadFix instance
-
-instance MonadFix IO where
-       mfix = fixIO
+#ifdef __HUGS__
+import Hugs.IO
+import Hugs.IOExts
+#endif
 
--- -----------------------------------------------------------------------------
--- Typeable instance for Handle
+#ifdef __NHC__
+import IO
+  ( Handle ()
+  , HandlePosn ()
+  , IOMode (ReadMode,WriteMode,AppendMode,ReadWriteMode)
+  , BufferMode (NoBuffering,LineBuffering,BlockBuffering)
+  , SeekMode (AbsoluteSeek,RelativeSeek,SeekFromEnd)
+  , stdin, stdout, stderr
+  , openFile                  -- :: FilePath -> IOMode -> IO Handle
+  , hClose                    -- :: Handle -> IO ()
+  , hFileSize                 -- :: Handle -> IO Integer
+  , hIsEOF                    -- :: Handle -> IO Bool
+  , isEOF                     -- :: IO Bool
+  , hSetBuffering             -- :: Handle -> BufferMode -> IO ()
+  , hGetBuffering             -- :: Handle -> IO BufferMode
+  , hFlush                    -- :: Handle -> IO ()
+  , hGetPosn                  -- :: Handle -> IO HandlePosn
+  , hSetPosn                  -- :: HandlePosn -> IO ()
+  , hSeek                     -- :: Handle -> SeekMode -> Integer -> IO ()
+  , hWaitForInput             -- :: Handle -> Int -> IO Bool
+  , hGetChar                  -- :: Handle -> IO Char
+  , hGetLine                  -- :: Handle -> IO [Char]
+  , hLookAhead                -- :: Handle -> IO Char
+  , hGetContents              -- :: Handle -> IO [Char]
+  , hPutChar                  -- :: Handle -> Char -> IO ()
+  , hPutStr                   -- :: Handle -> [Char] -> IO ()
+  , hIsOpen, hIsClosed        -- :: Handle -> IO Bool
+  , hIsReadable, hIsWritable  -- :: Handle -> IO Bool
+  , hIsSeekable               -- :: Handle -> IO Bool
+  , isAlreadyExistsError, isDoesNotExistError  -- :: IOError -> Bool
+  , isAlreadyInUseError, isFullError
+  , isEOFError, isIllegalOperation
+  , isPermissionError, isUserError
+  , ioeGetErrorString         -- :: IOError -> String
+  , ioeGetHandle              -- :: IOError -> Maybe Handle
+  , ioeGetFileName            -- :: IOError -> Maybe FilePath
+
+  , IO ()
+  , FilePath                  -- :: String
+  , IOError
+  , ioError                   -- :: IOError -> IO a
+  , userError                 -- :: String  -> IOError
+  , catch                     -- :: IO a    -> (IOError -> IO a) -> IO a
+  )
+import NHC.Internal (unsafePerformIO)
+#endif
 
-#include "Dynamic.h"
-INSTANCE_TYPEABLE0(Handle,handleTc,"Handle")
+import System.IO.Error
 
 -- -----------------------------------------------------------------------------
 -- Standard IO
 
+#ifndef __HUGS__
 putChar         :: Char -> IO ()
 putChar c       =  hPutChar stdout c
 
@@ -184,6 +230,7 @@ readIO s        =  case (do { (x,t) <- reads s ;
                        [x]    -> return x
                        []     -> ioError (userError "Prelude.readIO: no parse")
                        _      -> ioError (userError "Prelude.readIO: ambiguous parse")
+#endif  /* __HUGS__ */
 
 hReady         :: Handle -> IO Bool
 hReady h       =  hWaitForInput h 0
@@ -203,3 +250,7 @@ hPrint hdl  =  hPutStrLn hdl . show
 fixIO          :: (a -> IO a) -> IO a
 fixIO m         = stToIO (fixST (ioToST . m))
 #endif
+#ifdef __NHC__
+fixIO           :: (a -> IO a) -> IO a
+fixIO f         = let x = unsafePerformIO (f x) in return x
+#endif