summaryrefslogtreecommitdiff
path: root/src/GF.hs
blob: 5eafefe8d8965707018dde4c29b70bf9cc3081f9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
module Main where

import GFModes
import Operations
import UseIO
import Option
import IOGrammar
import ShellState
import Shell
import SubShell
import ShellCommands
import PShell
import JGF
import UTF8

import Today (today)
import Arch
import System (getArgs)
import Monad (foldM)

-- AR 19/4/2000 -- 11/11/2001

main :: IO ()
main = do
  xs <- getArgs
  let (os,fs) = getOptions "-" xs
      opt j   = oElem j os
  case 0 of

    _ | opt getHelp -> do
      putStrLnFlush $ encodeUTF8 helpMsg

    _ | opt forJava -> do
      putStrLnFlush $ encodeUTF8 welcomeMsg 
      st <- useIOE emptyShellState $ 
              foldM (shellStateFromFiles os) emptyShellState fs
      sessionLineJ True st
      return ()

    _ | opt doMake -> do
      case fs of
        [f] -> batchCompile os f
        _ -> putStrLnFlush "expecting exactly one gf file to compile"

    _ | opt doBatch -> do
      if opt beSilent then return () else putStrLnFlush "<gfbatch>"
      st <- useIOE emptyShellState $ 
              foldM (shellStateFromFiles os) emptyShellState fs
      gfBatch (initHState st) 
      if opt beSilent then return () else putStrLnFlush "</gfbatch>"
      return ()
    _ -> do
      putStrLnFlush $ welcomeMsg
      st <- useIOE emptyShellState $ 
              foldM (shellStateFromFiles os) emptyShellState fs
      if null fs then return () else putCPU 
      gfInteract (initHState st) 
      return ()

helpMsg = unlines [
  "Usage: gf <option>* <file>*",
  "Options:",
  "  -make    batch-compile files",
  "   -noemit do not emit code when compiling",
  "   -v      be verbose when compiling",
  "  -batch   structure session by XML tags (use > to send into a file)",
  "  -help    show this message",
  "To use the GUI: jgf <option>* <file>*"
  ]

welcomeMsg = 
  "Welcome to " ++ authorMsg ++++ welcomeArch ++ "\n\nType 'h' for help."

authorMsg = unlines [
 "Grammatical Framework, Version 2-beta (incomplete functionality)",
 "April 1, 2004", 
--- "Compiled March 26, 2003",
 "Compiled " ++ today,
 "Copyright (c) Markus Forsberg, Thomas Hallgren, Harald Hammarström,",
 "Kristofer Johannisson, Janna Khegai, Peter Ljunglöf, Petri Mäenpää,", 
 "and Aarne Ranta, 1998-2003, under GNU General Public License (GPL)",
 "Bug reports to aarne@cs.chalmers.se"
 ]