[add ability to execute jhci commands from command line via '-e'. add command in jhci for executing a file.
John Meacham <john@repetae.net>**20051204033132] hunk ./Interactive.hs 44
-interact ho = go where
+interact ho = mre where
+    mre = case optStmts options of
+        [] -> go
+        xs -> runInteractions initialInteract (concatMap lines $ reverse xs) >> exitSuccess
hunk ./Interactive.hs 53
-        beginInteraction emptyInteract { interactSettables = ["prog", "args"], interactVersion = versionString, interactCommands = commands, interactExpr = do_expr }
+        beginInteraction initialInteract
+    initialInteract = emptyInteract { interactSettables = ["prog", "args"], interactVersion = versionString, interactCommands = commands, interactExpr = do_expr }
hunk ./Main.hs 313
-    return $ optInteractive options || "ichj" `isPrefixOf` reverse pn
+    return $ optInteractive options || "ichj" `isPrefixOf` reverse pn || not (null $ optStmts options)
hunk ./Options.hs 25
+    optStmts       ::  [String],  -- ^ statements to execute
hunk ./Options.hs 62
+    optStmts       = [],
hunk ./Options.hs 105
-    , Option ['e'] []            (ReqArg (optMainFunc_s . Just . (,) True)  "<expr>")  "main entry point, showable expression."
+    , Option []    ["entry"]     (ReqArg (optMainFunc_s . Just . (,) True)  "<expr>")  "main entry point, showable expression."
+    , Option ['e'] []            (ReqArg (\d -> optStmts_u (d:)) "<statement>")  "run given statement as if on jhci prompt"
hunk ./Util/Interact.hs 4
-module Util.Interact(Interact(..),InteractCommand(..),beginInteraction,emptyInteract) where
+module Util.Interact(
+    Interact(..),
+    InteractCommand(..),
+    beginInteraction,
+    runInteraction,
+    runInteractions,
+    emptyInteract) where
hunk ./Util/Interact.hs 14
-import Data.Version
hunk ./Util/Interact.hs 19
-import System.Info
hunk ./Util/Interact.hs 42
+    (":execfile", "run sequence of commands from a file"),
hunk ./Util/Interact.hs 85
-beginInteraction :: Interact -> IO ()
-beginInteraction act = do
+runInteractions :: Interact -> [String] -> IO Interact
+runInteractions act [] = return act
+runInteractions act (x:xs) = do
+    act' <- runInteraction act x
+    runInteractions act' xs
+
+-- | run a command as if typed at prompt
+
+runInteraction :: Interact -> String -> IO Interact
+runInteraction act s = do
hunk ./Util/Interact.hs 107
-    s <- readLine (interactPrompt act) (return . expand)
hunk ./Util/Interact.hs 108
-        Right "" -> beginInteraction act
-        Right ('!':rest) -> System.system rest >> return ()
+        Right "" -> return act
+        Right ('!':rest) -> System.system rest >> return act
hunk ./Util/Interact.hs 112
-            beginInteraction act'
+            return act'
hunk ./Util/Interact.hs 115
-            [":help"] -> putStrLn help_text
-            [":version"] -> putStrLn (interactVersion act)
-            [":cd"] -> catch (setCurrentDirectory arg) (\_ -> putStrLn $ "Could not change to directory: " ++ arg)
-            [":pwd"] -> catch getCurrentDirectory (\_ -> putStrLn "Could not get current directory." >> return "") >>= putStrLn
+            [":help"] -> putStrLn help_text >> return act
+            [":version"] -> putStrLn (interactVersion act) >> return act
+            [":cd"] -> catch (setCurrentDirectory arg) (\_ -> putStrLn $ "Could not change to directory: " ++ arg) >> return act
+            [":pwd"] -> (catch getCurrentDirectory (\_ -> putStrLn "Could not get current directory." >> return "") >>= putStrLn)  >> return act
hunk ./Util/Interact.hs 120
-                [] -> showSet
+                [] -> showSet >> return act
hunk ./Util/Interact.hs 124
-                    beginInteraction act { interactSet = Map.fromList [ x | x@(a,_) <- ts, a `elem` interactSettables act ] `Map.union` interactSet act }
-            [":unset"] -> beginInteraction act { interactSet = interactSet act Map.\\ Map.fromList [ (cleanupWhitespace rs,"") | rs <- simpleUnquote arg] }
+                    return act { interactSet = Map.fromList [ x | x@(a,_) <- ts, a `elem` interactSettables act ] `Map.union` interactSet act }
+            [":unset"] -> return act { interactSet = interactSet act Map.\\ Map.fromList [ (cleanupWhitespace rs,"") | rs <- simpleUnquote arg] }
+            [":execfile"] -> do
+                fc <- catch (readFile arg) (\_ -> putStrLn "Could not read file." >> return "")
+                runInteractions act (lines fc)
hunk ./Util/Interact.hs 131
-                beginInteraction act'
-            (_:_:_) -> putStrLn "Ambiguous command, possibilites are:" >> putStr  (unlines $ buildTableLL $ args cmd)
-            [] -> putStrLn $ "Unknown command (use :help for help): " ++ cmd
-    beginInteraction act
+                return act'
+            (_:_:_) -> putStrLn "Ambiguous command, possibilites are:" >> putStr  (unlines $ buildTableLL $ args cmd) >> return act
+            [] -> (putStrLn $ "Unknown command (use :help for help): " ++ cmd)  >> return act
+
+
+-- | begin interactive interaction
+
+beginInteraction :: Interact -> IO ()
+beginInteraction act = do
+    let commands' = commands ++ [ (n,h) | InteractCommand { commandName = n, commandHelp = h } <- interactCommands act ]
+        args s =  [ bb | bb@(n,_) <- commands', s `isPrefixOf` n ]
+        expand s = fsts (args s) ++ filter (isPrefixOf s) (interactSettables act)
+    s <- readLine (interactPrompt act) (return . expand)
+    act' <- runInteraction act s
+    beginInteraction act'
+