[project @ 1999-04-27 10:06:47 by sewardj]
[ghc-hetmet.git] / ghc / interpreter / lib / System.hs
1 -----------------------------------------------------------------------------
2 -- Standard Library: System operations
3 --
4 -- Warning: the implementation of these functions in Hugs 98 is very weak.
5 -- The functions themselves are best suited to uses in compiled programs,
6 -- and not to use in an interpreter-based environment like Hugs.
7 --
8 -- Suitable for use with Hugs 98
9 -----------------------------------------------------------------------------
10
11 module System (
12         ExitCode(..), exitWith, exitFailure,
13         getArgs, getProgName, getEnv, 
14         system
15         ) where
16
17 data ExitCode = ExitSuccess | ExitFailure Int
18                 deriving (Eq, Ord, Read, Show)
19
20 getArgs                     :: IO [String]
21 getArgs                      = primGetRawArgs >>= \rawargs ->
22                                return (drop 1 (dropWhile (/= "--") rawargs))
23
24 getProgName                 :: IO String
25 getProgName                  = primGetRawArgs >>= \rawargs ->
26                                return (head rawargs)
27
28 getEnv                      :: String -> IO String
29 getEnv                       = primGetEnv
30
31 system                      :: String -> IO ExitCode
32 system s                     = error "System.system unimplemented"
33
34 exitWith                    :: ExitCode -> IO a
35 exitWith c                   = error "System.exitWith unimplemented"
36
37 exitFailure                 :: IO a
38 exitFailure                  = exitWith (ExitFailure 1)
39
40 toExitCode                  :: Int -> ExitCode
41 toExitCode 0                 = ExitSuccess
42 toExitCode n                 = ExitFailure n
43
44 fromExitCode                :: ExitCode -> Int
45 fromExitCode ExitSuccess     = 0
46 fromExitCode (ExitFailure n) = n
47
48 -----------------------------------------------------------------------------