From 055c0d0d5a5bb0dc75904fe53df7f2e4f5732a8f Mon Sep 17 00:00:00 2001 From: aarne Date: Wed, 21 May 2008 09:26:44 +0000 Subject: GF/src is now for 2.9, and the new sources are in src-3.0 - keep it this way until the release of GF 3 --- src-3.0/GF.hs | 153 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 153 insertions(+) create mode 100644 src-3.0/GF.hs (limited to 'src-3.0/GF.hs') diff --git a/src-3.0/GF.hs b/src-3.0/GF.hs new file mode 100644 index 000000000..50afeb8e9 --- /dev/null +++ b/src-3.0/GF.hs @@ -0,0 +1,153 @@ +{-# OPTIONS -cpp #-} +---------------------------------------------------------------------- +-- | +-- 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.Compile.Wordlist +import GF.Shell +import GF.Shell.SubShell +import GF.Shell.ShellCommands +import GF.Shell.PShell +import GF.Shell.JGF +import GF.System.Signal +import GF.Text.UTF8 + +import GF.Today (today,version,libdir) +import GF.System.Arch +import System (getArgs,system,getEnv) +import System.FilePath +import Control.Monad (foldM,liftM) +import Data.List (nub) + +#ifdef mingw32_HOST_OS +import System.Win32.Console +import System.Win32.NLS +#endif + +-- AR 19/4/2000 -- 21/3/2006 + +main :: IO () +main = do +#ifdef mingw32_HOST_OS + codepage <- getACP + setConsoleCP codepage + setConsoleOutputCP codepage +#endif + + 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 || any opt (map iOpt ["h", "-help", "-h"])-> do + putStrLnFlush $ encodeUTF8 helpMsg + + _ | opt forJava -> do + welcome <- welcomeMsgLib + putStrLnFlush $ encodeUTF8 welcome + st <- useIOE st0 $ + foldM (shellStateFromFiles os) st0 fs + sessionLineJ True st + return () + + _ | opt doMake -> do + mapM_ (batchCompile os) fs + return () + + _ | opt makeConcrete -> do + mkConcretes os 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 + welcome <- welcomeMsgLib + ifNotSil $ putStrLnFlush $ welcome + st <- useIOE st0 $ + foldM (shellStateFromFiles os) st0 fs + if null fs then return () else (ifNotSil putCPU) + blockInterrupt (gfInteract (initHState st)) + return () + -- preprocessing gfe + if opt fromExamples + then do + es <- liftM (nub . concat) $ mapM (getGFEFiles os) fs + mkConcretes os es + doGF (removeOption fromExamples os) fs + -- preprocessing gfwl + else if (length fs == 1 && takeExtensions (head fs) == ".gfwl") + then do + fs' <- mkWordlist (head fs) + doGF os fs' + else doGF os fs + +helpMsg = unlines [ + "Usage: gf