import PrelAddr
import PrelIOBase ( IOError(..), IOErrorType(..), constructErrorAndFailWithInfo, stToIO )
import PrelPack ( unpackCString, unpackCStringST, packString )
-import PrelArr ( ByteArray )
+import PrelByteArr ( ByteArray )
type PrimByteArray = ByteArray Int
--
-- Suitable for use with Hugs 98
-----------------------------------------------------------------------------
+import PrelPrim ( primGetRawArgs
+ , primGetEnv
+ , prelCleanupAfterRunAction
+ , copy_String_to_cstring
+ , readIORef
+ , nh_stderr
+ , nh_stdout
+ , nh_stdin
+ , nh_exitwith
+ , nh_flush
+ , nh_close
+ , nh_system
+ , nh_free
+ , nh_getPID
+ )
+
data ExitCode = ExitSuccess | ExitFailure Int
deriving (Eq, Ord, Read, Show)
getArgs :: IO [String]
getArgs = primGetRawArgs >>= \rawargs ->
- return (drop 1 (dropWhile (/= "--") rawargs))
+ return (tail rawargs)
getProgName :: IO String
getProgName = primGetRawArgs >>= \rawargs ->
fromExitCode ExitSuccess = 0
fromExitCode (ExitFailure n) = n
--- Note. exitWith is supposed to flush and close all open or
--- semi-open handles. The code below doesn't do that --
--- we'd have to keep a list of them somewhere.
+-- see comment in Prelude.hs near primRunIO_hugs_toplevel
exitWith :: ExitCode -> IO a
exitWith c
- = do nh_exitwith (fromExitCode c)
+ = do cleanup_action <- readIORef prelCleanupAfterRunAction
+ case cleanup_action of
+ Just xx -> xx
+ Nothing -> return ()
+ nh_stderr >>= nh_flush
+ nh_stdout >>= nh_flush
+ nh_stdin >>= nh_close
+ nh_exitwith (fromExitCode c)
(ioError.IOError) "System.exitWith: should not return"
system :: String -> IO ExitCode