----------------------------------------------------------------------
-- |
-- Module : Main
-- Maintainer : Aarne Ranta
-- Stability : (stability)
-- Portability : (portability)
--
-- > CVS $Date: 2005/06/30 11:36:49 $
-- > CVS $Author: aarne $
-- > CVS $Revision: 1.29 $
--
-- The Main module of GF program.
-----------------------------------------------------------------------------
module Main (main) where
import GF.GFModes (gfInteract, gfBatch, batchCompile)
import GF.Data.Operations
import GF.Infra.UseIO
import GF.Infra.Option
import GF.API.IOGrammar
import GF.Compile.ShellState
import GF.Compile.Compile
import GF.Compile.MkConcrete
import GF.Shell
import GF.Shell.SubShell
import GF.Shell.ShellCommands
import GF.Shell.PShell
import GF.Shell.JGF
import GF.Text.UTF8
import GF.Today (today,version)
import GF.System.Arch
import System (getArgs,system)
import Control.Monad (foldM,liftM)
import Data.List (nub)
-- AR 19/4/2000 -- 28/4/2005
main :: IO ()
main = do
xs <- getArgs
let
(os,fs) = getOptions "-" xs
opt j = oElem j os
st0 = optInitShellState os
ifNotSil c = if oElem beSilent os then return () else c
doGF os fs = case 0 of
_ | opt getHelp -> do
putStrLnFlush $ encodeUTF8 helpMsg
_ | opt forJava -> do
putStrLnFlush $ encodeUTF8 welcomeMsg
st <- useIOE st0 $
foldM (shellStateFromFiles os) st0 fs
sessionLineJ True st
return ()
_ | opt doMake -> do
case fs of
[f] -> batchCompile os f
_ -> putStrLnFlush "expecting exactly one gf file to compile"
_ | opt makeConcrete -> do
mkConcretes fs
_ | opt openEditor -> do
system $ "jgf" +++ unwords xs
return ()
_ | opt doBatch -> do
if opt beSilent then return () else putStrLnFlush ""
st <- useIOE st0 $
foldM (shellStateFromFiles os) st0 fs
gfBatch (initHState st)
if opt beSilent then return () else putStrLnFlush ""
return ()
_ -> do
ifNotSil $ putStrLnFlush $ welcomeMsg
st <- useIOE st0 $
foldM (shellStateFromFiles os) st0 fs
if null fs then return () else (ifNotSil putCPU)
gfInteract (initHState st)
return ()
-- preprocessing gfe
if opt fromExamples
then do
es <- liftM (nub . concat) $ mapM (getGFEFiles os) fs
mkConcretes es
doGF (removeOption fromExamples os) fs
else doGF os fs
helpMsg = unlines [
"Usage: gf