{-
  Main function. Starts shell.
  Copyright (C) 2005, 2008 Luis Francisco Araujo
-}

module Main
    where

import ConfigFile (globalConfig)
import Exec (mainExec)
import Options (programOptions)
import Signals (handler, setSignalHandler)
import System.Posix.Signals (Handler())

-- | Main function. Initialize the signal handlers and enter the main loop
-- of the program.
main :: IO ()
main = do
       initialize
       opts <- programOptions
       cfg <- globalConfig opts
       fhsLoop cfg
               where
                 fhsLoop :: [(String, String)] -> IO b
                 fhsLoop cfg = do handler $ mainExec cfg
                                  fhsLoop cfg

                 initialize :: IO System.Posix.Signals.Handler
                 initialize = setSignalHandler