{-# OPTIONS -#include "Linker.h" #-}
-----------------------------------------------------------------------------
--- $Id: InteractiveUI.hs,v 1.150 2003/04/12 16:27:24 panne Exp $
+-- $Id: InteractiveUI.hs,v 1.151 2003/04/23 10:42:36 simonmar Exp $
--
-- GHC Interactive User Interface
--
state <- getGHCiState
dflags <- io (getDynFlags)
io (revertCAFs) -- always revert CAFs on load/add.
+ files <- mapM expandPath files
let new_targets = files ++ targets state
graph <- io (cmDepAnal (cmstate state) dflags new_targets)
(cmstate1, ok, mods) <- io (cmLoadModules (cmstate state) dflags graph)
modulesLoadedMsg ok mods dflags
changeDirectory :: String -> GHCi ()
-changeDirectory ('~':d) = do
- tilde <- io (getEnv "HOME") -- will fail if HOME not defined
- io (setCurrentDirectory (tilde ++ '/':d))
-changeDirectory d = io (setCurrentDirectory d)
+changeDirectory dir = do
+ dir <- expandPath dir
+ io (setCurrentDirectory dir)
defineMacro :: String -> GHCi ()
defineMacro s = do
state <- getGHCiState
dflags <- io getDynFlags
+ -- expand tildes
+ files <- mapM expandPath files
+
-- do the dependency anal first, so that if it fails we don't throw
-- away the current set of modules.
graph <- io (cmDepAnal (cmstate state) dflags files)
foreign import ccall "revertCAFs" rts_revertCAFs :: IO ()
-- Make it "safe", just in case
+
+-- -----------------------------------------------------------------------------
+-- Utils
+
+expandPath :: String -> GHCi String
+expandPath path =
+ case dropWhile isSpace path of
+ ('~':d) -> do
+ tilde <- io (getEnv "HOME") -- will fail if HOME not defined
+ return (tilde ++ '/':d)
+ other ->
+ return other