[clean up libraries, fill out System.IO and System.Directory
John Meacham <john@repetae.net>**20090821042550
 Ignore-this: d307ef6085a645832c08bac9c83c25da
] hunk ./lib/base/Control/Monad/Fix.hs 26
-import System.IO
hunk ./lib/base/Control/Monad/Fix.hs 28
+import Jhc.IO
hunk ./lib/base/Foreign/Marshal/Error.hs 32
-import Prelude.IOError
rmdir ./lib/base/Prelude
hunk ./lib/base/System/CPUTime.hs 1
--- | Skeleton only, fixme.
-module System.CPUTime where
+-----------------------------------------------------------------------------
+-- |
+-- Module      :  System.CPUTime
+-- Copyright   :  (c) The University of Glasgow 2001
+-- License     :  BSD-style (see the file libraries/base/LICENSE)
+--
+-- Maintainer  :  libraries@haskell.org
+-- Stability   :  provisional
+-- Portability :  portable
+--
+-- The standard CPUTime library.
+--
+-----------------------------------------------------------------------------
+
+module System.CPUTime (
+    getCPUTime,
+    cpuTimePrecision
+    ) where
+
+
+-- |Computation 'getCPUTime' returns the number of picoseconds CPU time
+-- used by the current program.  The precision of this result is
+-- implementation-dependent.
+getCPUTime :: IO Integer
+getCPUTime = error "getCPUTime"
+
+-- |The 'cpuTimePrecision' constant is the smallest measurable difference
+-- in CPU time that the implementation can record, and is given as an
+-- integral number of picoseconds.
+cpuTimePrecision :: Integer
+cpuTimePrecision = error "cpuTimePrecision"
hunk ./lib/base/System/Directory.hs 1
-module System.Directory where
-{-
- (
+{-# OPTIONS_JHC -fffi #-}
+module System.Directory (
hunk ./lib/base/System/Directory.hs 11
-import Time ( ClockTime )
+import Foreign
+import Foreign.C.Error
+import Foreign.C.String
+import Foreign.C
+
+import System.Time
hunk ./lib/base/System/Directory.hs 20
-    executable, searchable :: Bool
+    executable, searchable :: !Bool
hunk ./lib/base/System/Directory.hs 23
+cPathMax :: CSize
+cPathMax = 1024
+
+getCurrentDirectory  :: IO FilePath
+getCurrentDirectory = allocaBytes (fromIntegral cPathMax) $ \cp -> do
+    cp <- throwErrnoIfNull "getCurrentDirectory" (getcwd cp cPathMax)
+    peekCString cp
+
+
+setCurrentDirectory :: FilePath -> IO ()
+setCurrentDirectory fp = throwErrnoIfMinus1_ fp $ withCString fp chdir
hunk ./lib/base/System/Directory.hs 35
+foreign import ccall unsafe chdir :: CString -> IO Int
+foreign import ccall unsafe getcwd :: Ptr CChar -> CSize -> IO (Ptr CChar)
+foreign import ccall unsafe mkdir :: CString -> Int -> IO Int
+foreign import ccall unsafe rmdir :: CString -> IO Int
+foreign import ccall unsafe unlink :: CString -> IO Int
+foreign import ccall unsafe rename :: CString -> CString -> IO Int
hunk ./lib/base/System/Directory.hs 44
+createDirectory fp = throwErrnoIfMinus1_ fp $ withCString fp $ \cs -> mkdir cs (-1) 
+
+
hunk ./lib/base/System/Directory.hs 48
+removeDirectory fp = throwErrnoIfMinus1_ fp $ withCString fp rmdir
+
+
hunk ./lib/base/System/Directory.hs 52
+removeFile fp = throwErrnoIfMinus1_ fp $ withCString fp unlink
+
+
hunk ./lib/base/System/Directory.hs 56
+renameDirectory fp1 fp2 = throwErrnoIfMinus1_ "rename" $ do
+    withCString fp1 $ \fp1 -> do
+    withCString fp2 $ \fp2 -> do
+    rename fp1 fp2
+
hunk ./lib/base/System/Directory.hs 62
+renameFile x y = renameDirectory x y
hunk ./lib/base/System/Directory.hs 65
-getCurrentDirectory  :: IO FilePath
-setCurrentDirectory  :: FilePath -> IO ()
+getDirectoryContents = error "getDirectoryContents"
+
hunk ./lib/base/System/Directory.hs 69
+doesFileExist = error "doesFileExist"
+
hunk ./lib/base/System/Directory.hs 72
+doesDirectoryExist = error "doesDirectoryExist"
hunk ./lib/base/System/Directory.hs 75
+getPermissions = error "getPermissions"
+
hunk ./lib/base/System/Directory.hs 78
+setPermissions = error "setPermissions"
hunk ./lib/base/System/Directory.hs 81
+getModificationTime = error "getModificationTime"
+
+
hunk ./lib/base/System/Directory.hs 85
--}
hunk ./lib/base/System/IO/Error.hs 1
-module System.IO.Error where
+module System.IO.Error (
+
+    -- * I\/O errors
+    IOError,
+    userError,		       	-- :: String  -> IOError
+    --mkIOError,			-- :: IOErrorType -> String -> Maybe Handle
+				--    -> Maybe FilePath -> IOError
+
+    -- ** Classifying I\/O errors
+    isAlreadyExistsError,	-- :: IOError -> Bool
+    isDoesNotExistError,
+    isAlreadyInUseError,
+    isFullError,
+    isEOFError,
+    isIllegalOperation,
+    isPermissionError,
+    isUserError,
+
+    -- * Throwing and catching I\/O errors
+
+    ioError,		       	-- :: IOError -> IO a
+
+    catch,			-- :: IO a -> (IOError -> IO a) -> IO a
+    try,			-- :: IO a -> IO (Either IOError a)
+    ioeGetErrorString,
+    ioeGetFileName,
+    ioeGetHandle,
+
+    modifyIOError		-- :: (IOError -> IOError) -> IO a -> IO a
+  ) where
+
+import Data.Maybe
+import Jhc.IO
+
+
+
+
+-- | The construct 'try' @comp@ exposes IO errors which occur within a
+-- computation, and which are not fully handled.
+--
+-- Non-I\/O exceptions are not caught by this variant; to catch all
+-- exceptions, use 'Control.Exception.try' from "Control.Exception".
+
+try            :: IO a -> IO (Either IOError a)
+try f          =  catch (do r <- f
+                            return (Right r))
+                        (return . Left)
+
+-- -----------------------------------------------------------------------------
+-- Constructing an IOError
+
+-- | Construct an 'IOError' of the given type where the second argument
+-- describes the error location and the third and fourth argument
+-- contain the file handle and file path of the file involved in the
+-- error if applicable.
+--mkIOError :: IOErrorType -> String -> Maybe Handle -> Maybe FilePath -> IOError
+--mkIOError = error "mkIOError"
+
+-- -----------------------------------------------------------------------------
+-- IOErrorType
+
+-- | An error indicating that an 'IO' operation failed because
+-- one of its arguments already exists.
+isAlreadyExistsError :: IOError -> Bool
+isAlreadyExistsError = isAlreadyExistsErrorType    . ioeGetErrorType
+
+-- | An error indicating that an 'IO' operation failed because
+-- one of its arguments does not exist.
+isDoesNotExistError :: IOError -> Bool
+isDoesNotExistError  = isDoesNotExistErrorType     . ioeGetErrorType
+
+-- | An error indicating that an 'IO' operation failed because
+-- one of its arguments is a single-use resource, which is already
+-- being used (for example, opening the same file twice for writing
+-- might give this error).
+isAlreadyInUseError :: IOError -> Bool
+isAlreadyInUseError  = isAlreadyInUseErrorType     . ioeGetErrorType
+
+-- | An error indicating that an 'IO' operation failed because
+-- the device is full.
+isFullError         :: IOError -> Bool
+isFullError          = isFullErrorType             . ioeGetErrorType
+
+-- | An error indicating that an 'IO' operation failed because
+-- the end of file has been reached.
+isEOFError          :: IOError -> Bool
+isEOFError           = isEOFErrorType              . ioeGetErrorType
+
+-- | An error indicating that an 'IO' operation failed because
+-- the operation was not possible.
+-- Any computation which returns an 'IO' result may fail with
+-- 'isIllegalOperation'.  In some cases, an implementation will not be
+-- able to distinguish between the possible error causes.  In this case
+-- it should fail with 'isIllegalOperation'.
+isIllegalOperation  :: IOError -> Bool
+isIllegalOperation   = isIllegalOperationErrorType . ioeGetErrorType
+
+-- | An error indicating that an 'IO' operation failed because
+-- the user does not have sufficient operating system privilege
+-- to perform that operation.
+isPermissionError   :: IOError -> Bool
+isPermissionError    = isPermissionErrorType       . ioeGetErrorType
+
+-- | A programmer-defined error value constructed using 'userError'.
+isUserError         :: IOError -> Bool
+isUserError          = isUserErrorType             . ioeGetErrorType
+
+-- -----------------------------------------------------------------------------
+-- IOErrorTypes
+
+data IOErrorType = AlreadyExists | NoSuchThing | ResourceBusy
+		 | ResourceExhausted | EOF | IllegalOperation
+		 | PermissionDenied | UserError
+                 deriving(Eq,Ord)
+
+instance Show IOError where
+    showsPrec _ s = showString (showIOError s)
+
+-- -----------------------------------------------------------------------------
+-- IOErrorType predicates
+
+-- | I\/O error where the operation failed because one of its arguments
+-- already exists.
+isAlreadyExistsErrorType :: IOErrorType -> Bool
+isAlreadyExistsErrorType AlreadyExists = True
+isAlreadyExistsErrorType _ = False
+
+-- | I\/O error where the operation failed because one of its arguments
+-- does not exist.
+isDoesNotExistErrorType :: IOErrorType -> Bool
+isDoesNotExistErrorType NoSuchThing = True
+isDoesNotExistErrorType _ = False
+
+-- | I\/O error where the operation failed because one of its arguments
+-- is a single-use resource, which is already being used.
+isAlreadyInUseErrorType :: IOErrorType -> Bool
+isAlreadyInUseErrorType ResourceBusy = True
+isAlreadyInUseErrorType _ = False
+
+-- | I\/O error where the operation failed because the device is full.
+isFullErrorType :: IOErrorType -> Bool
+isFullErrorType ResourceExhausted = True
+isFullErrorType _ = False
+
+-- | I\/O error where the operation failed because the end of file has
+-- been reached.
+isEOFErrorType :: IOErrorType -> Bool
+isEOFErrorType EOF = True
+isEOFErrorType _ = False
+
+-- | I\/O error where the operation is not possible.
+isIllegalOperationErrorType :: IOErrorType -> Bool
+isIllegalOperationErrorType IllegalOperation = True
+isIllegalOperationErrorType _ = False
+
+-- | I\/O error where the operation failed because the user does not
+-- have sufficient operating system privilege to perform that operation.
+isPermissionErrorType :: IOErrorType -> Bool
+isPermissionErrorType PermissionDenied = True
+isPermissionErrorType _ = False
+
+-- | I\/O error that is programmer-defined.
+isUserErrorType :: IOErrorType -> Bool
+isUserErrorType UserError = True
+isUserErrorType _ = False
+
+-- -----------------------------------------------------------------------------
+-- Miscellaneous
+
+-- | Catch any 'IOError' that occurs in the computation and throw a
+-- modified version.
+modifyIOError :: (IOError -> IOError) -> IO a -> IO a
+modifyIOError f io = catch io (\e -> ioError (f e))
+
+ioeGetErrorType	      :: IOError -> IOErrorType
+ioeGetErrorType _ = UserError
+
+ioeGetHandle _ = error "ioeGetHandle"
+ioeGetHandle _ = error "ioeGetHandle"
+
+ioeGetErrorString s = showIOError s
+ioeGetFileName _ = error "ioeGetFileName"
+
+
hunk ./lib/base/System/IO.hs 3
+    module System.IO.Error,
hunk ./lib/base/System/IO.hs 20
+    hIsClosed,
hunk ./lib/base/System/IO.hs 27
+    isEOF,
hunk ./lib/base/System/IO.hs 33
+    HandlePosn,
hunk ./lib/base/System/IO.hs 35
-    try
+    hIsReadable,
+    hIsSeekable,
+    hIsWritable,
+    hLookAhead,
+    hReady,
+    hSetBuffering,
+    hGetBuffering
hunk ./lib/base/System/IO.hs 47
-import Prelude.IOError
hunk ./lib/base/System/IO.hs 52
+import System.IO.Error
hunk ./lib/base/System/IO.hs 62
-
-
-try            :: IO a -> IO (Either IOError a)
-try f          =  catch (do r <- f
-                            return (Right r))
-                        (return . Left)
-
+hIsReadable h = return $ handleIOMode h `elem` [ReadMode,ReadWriteMode]
+hIsWritable h = return $ handleIOMode h `elem` [AppendMode,WriteMode,ReadWriteMode]
hunk ./lib/base/System/IO.hs 72
+hIsClosed h = not `fmap` hIsOpen h
hunk ./lib/base/System/IO.hs 159
+hIsSeekable :: Handle -> IO Bool
+hIsSeekable _ = return True
+
+hLookAhead :: Handle -> IO Char
+hLookAhead = error "hLookAhead"
+
+hReady :: Handle -> IO Bool
+hReady _ = return True
+
+hSetBuffering :: Handle -> BufferMode -> IO ()
+hSetBuffering _ _ = return ()
+
+hGetBuffering :: Handle -> IO BufferMode
+hGetBuffering _ = error "hGetBuffering"
+
hunk ./lib/jhc/Data/Char.hs 24
+lexLitChar :: ReadS String
+lexLitChar ('\\':s) = lexEsc s
+lexLitChar (c:s) = [([c],s)]
hunk ./lib/jhc/Data/Char.hs 58
+lexEsc          :: ReadS String
+lexEsc (c:s) | c `elem` "abfnrtv\\\"\'" = [('\\':[c],s)]
+lexEsc ('^':(c:s)) | c >= '@' && c <= '_'
+                 = [('\\':'^':[c], s)]
+--lexEsc s@(d:_) | isDigit d
+--                 = [(chr n, t) | (n,t) <- readDec s]
+--lexEsc ('o':s)  = [(chr n, t) | (n,t) <- readOct s]
+--lexEsc ('x':s)  = [(chr n, t) | (n,t) <- readHex s]
+--lexEsc s@(c:_) | isUpper c
+--                 = let table = ('\DEL', "DEL") : zip ['\NUL' .. ] asciiTab
+--                   in case [(c,s') | (c, mne) <- table,
+--                                     ([],s') <- [match mne s]]
+--                      of (pr:_) -> [pr]
+--                         []     -> []
+lexEsc _        = []
+
hunk ./lib/jhc/Foreign/Marshal/Alloc.hs 24
-import Prelude.IOError
hunk ./lib/jhc/Foreign/Marshal/Array.hs 61
-import Prelude.IOError
hunk ./lib/jhc/Foreign/Ptr.hs 42
+castFunPtr :: FunPtr a -> FunPtr b
+castFunPtr (FunPtr x) = FunPtr x
hunk ./lib/jhc/Foreign/Ptr.hs 52
+freeHaskellFunPtr :: FunPtr a -> IO ()
+freeHaskellFunPtr _ = error "freeHaskellFunPtr"
+
hunk ./lib/jhc/Jhc/IO.hs 19
-    runExpr,
hunk ./lib/jhc/Prelude/IO.hs 32
-import Prelude.IOError
hunk ./lib/jhc/Prelude/IOError.hs 1
-{-# OPTIONS_JHC -N #-}
-module Prelude.IOError(IOError(),showIOError,userError) where
-
-import Jhc.IO
-import Jhc.Show
-
-instance Show IOError where
-    showsPrec _ s = showString (showIOError s)
-
-{-
-
-data IOError = IOError {
-     ioe_handle   :: Maybe Handle,   -- the handle used by the action flagging
-				     -- the error.
-     ioe_type     :: IOErrorType,    -- what it was.
-     ioe_location :: String,	     -- location.
-     ioe_description :: String,      -- error type specific information.
-     ioe_filename :: Maybe FilePath  -- filename the error is related to.
-   } deriving(Eq)
-
-
--- | An abstract type that contains a value for each variant of 'IOError'.
-data IOErrorType
-  = AlreadyExists
-  | NoSuchThing
-  | ResourceBusy
-  | ResourceExhausted
-  | EOF
-  | IllegalOperation
-  | PermissionDenied
-  | UserError
-
-instance Show IOErrorType where
-  showsPrec _ e =
-    showString $
-    case e of
-      AlreadyExists	-> "already exists"
-      NoSuchThing       -> "does not exist"
-      ResourceBusy      -> "resource busy"
-      ResourceExhausted -> "resource exhausted"
-      EOF		-> "end of file"
-      IllegalOperation	-> "illegal operation"
-      PermissionDenied  -> "permission denied"
-      UserError		-> "user error"
-
-instance Show IOException where
-    showsPrec p (IOError hdl iot loc s fn) =
-      (case fn of
-	 Nothing -> case hdl of
-		        Nothing -> id
-			Just h  -> showsPrec p h . showString ": "
-	 Just name -> showString name . showString ": ") .
-      (case loc of
-         "" -> id
-	 _  -> showString loc . showString ": ") .
-      showsPrec p iot .
-      (case s of
-	 "" -> id
-	 _  -> showString " (" . showString s . showString ")")
-
--}
-
rmfile ./lib/jhc/Prelude/IOError.hs
hunk ./lib/jhc/Prelude.hs 84
-import Prelude.IOError
hunk ./lib/jhc/jhc.cabal 51
-	Prelude.IOError,