[project @ 2003-05-25 20:54:18 by stolz]
[ghc-hetmet.git] / ghc / compiler / main / SysTools.lhs
index bca9a7e..d99ce5d 100644 (file)
@@ -11,7 +11,8 @@ module SysTools (
        -- Initialisation
        initSysTools,
 
-       setPgmP,                -- String -> IO ()
+       setPgmL,                -- String -> IO ()
+       setPgmP,
        setPgmF,
        setPgmc,
        setPgmm,
@@ -71,18 +72,14 @@ import Util         ( global, notNull )
 import CmdLineOpts     ( dynFlag, verbosity )
 
 import EXCEPTION       ( throwDyn )
-#if __GLASGOW_HASKELL__ > 408
-import qualified EXCEPTION as Exception ( catch )
-#else
-import EXCEPTION        ( catchAllIO )
-#endif
-
 import DATA_IOREF      ( IORef, readIORef, writeIORef )
 import DATA_INT
     
 import Monad           ( when, unless )
 import System          ( ExitCode(..), exitWith, getEnv, system )
-import IO
+import IO              ( try, catch,
+                         openFile, hPutChar, hPutStrLn, hPutStr, hClose, hFlush, IOMode(..),
+                         stderr )
 import Directory       ( doesFileExist, removeFile )
 
 #include "../includes/config.h"
@@ -95,16 +92,15 @@ import Directory    ( doesFileExist, removeFile )
 
 #ifndef mingw32_HOST_OS
 #if __GLASGOW_HASKELL__ > 504
-import qualified GHC.Posix
+import qualified System.Posix.Internals
 #else
 import qualified Posix
 #endif
-#else
+#else /* Must be Win32 */
 import List            ( isPrefixOf )
 import Util            ( dropList )
-import MarshalArray
 import Foreign
-import CString
+import CString         ( CString, peekCString )
 #endif
 
 #ifdef mingw32_HOST_OS
@@ -113,17 +109,11 @@ import System.Cmd       ( rawSystem )
 #else
 import SystemExts       ( rawSystem )
 #endif
-#else
-import System          ( system )
-#endif
 
--- Make catch work on older GHCs
-#if __GLASGOW_HASKELL__ > 408
-myCatch = Exception.catch
-#else
-myCatch = catchAllIO
-#endif
+#else /* Not Win32 */
 
+import System          ( system )
+#endif
 \end{code}
 
 
@@ -440,6 +430,7 @@ like
 is used to override a particular program with a new one
 
 \begin{code}
+setPgmL = writeIORef v_Pgm_L
 setPgmP = writeIORef v_Pgm_P
 setPgmF = writeIORef v_Pgm_F
 setPgmc = writeIORef v_Pgm_c
@@ -676,7 +667,7 @@ removeTmpFiles verb fs
             ("Deleting: " ++ unwords fs)
             (mapM_ rm fs)
   where
-    rm f = removeFile f `myCatch` 
+    rm f = removeFile f `IO.catch` 
                (\_ignored -> 
                    when (verb >= 2) $
                      hPutStrLn stderr ("Warning: deleting non-existent " ++ f)
@@ -738,7 +729,7 @@ traceCmd phase_name cmd_line action
        ; unless n $ do {
 
           -- And run it!
-       ; action `myCatch` handle_exn verb
+       ; action `IO.catch` handle_exn verb
        }}
   where
     handle_exn verb exn = do { when (verb >= 2) (hPutStr   stderr "\n")
@@ -852,28 +843,24 @@ getExecDir = do let len = (2048::Int) -- plenty, PATH_MAX is 512 under Win32.
                                    return (Just (reverse (dropList "/bin/ghc.exe" (reverse (unDosifyPath s)))))
 
 
-foreign import stdcall "GetModuleFileNameA" unsafe 
+foreign import stdcall "GetModuleFileNameA" unsafe
   getModuleFileName :: Ptr () -> CString -> Int -> IO Int32
 #else
 getExecDir :: IO (Maybe String) = do return Nothing
 #endif
 
 #ifdef mingw32_HOST_OS
-foreign import "_getpid" unsafe getProcessID :: IO Int -- relies on Int == Int32 on Windows
+foreign import ccall "_getpid" unsafe getProcessID :: IO Int -- relies on Int == Int32 on Windows
 #elif __GLASGOW_HASKELL__ > 504
 getProcessID :: IO Int
-getProcessID = GHC.Posix.c_getpid >>= return . fromIntegral
+getProcessID = System.Posix.Internals.c_getpid >>= return . fromIntegral
 #else
 getProcessID :: IO Int
 getProcessID = Posix.getProcessID
 #endif
 
 quote :: String -> String
-#if defined(mingw32_HOST_OS)
 quote "" = ""
 quote s  = "\"" ++ s ++ "\""
-#else
-quote s = s
-#endif
 
 \end{code}