tools/pas2c/Main.hs
author koda
Tue, 13 Nov 2012 23:56:50 +0100
branchwebgl
changeset 8050 c82b68016c68
parent 7979 a3974abc62d3
child 8836 7a474fcc343d
permissions -rw-r--r--
link main on osx
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7965
b518458f83e6 pas2c is now fully parametric with command line options (maybe unC0Rr needs to clean this up a little)
koda
parents:
diff changeset
     1
module Main( main ) where
b518458f83e6 pas2c is now fully parametric with command line options (maybe unC0Rr needs to clean this up a little)
koda
parents:
diff changeset
     2
b518458f83e6 pas2c is now fully parametric with command line options (maybe unC0Rr needs to clean this up a little)
koda
parents:
diff changeset
     3
import System.Console.GetOpt
b518458f83e6 pas2c is now fully parametric with command line options (maybe unC0Rr needs to clean this up a little)
koda
parents:
diff changeset
     4
import System.Environment
b518458f83e6 pas2c is now fully parametric with command line options (maybe unC0Rr needs to clean this up a little)
koda
parents:
diff changeset
     5
import System.Exit
b518458f83e6 pas2c is now fully parametric with command line options (maybe unC0Rr needs to clean this up a little)
koda
parents:
diff changeset
     6
import System.IO
b518458f83e6 pas2c is now fully parametric with command line options (maybe unC0Rr needs to clean this up a little)
koda
parents:
diff changeset
     7
import Data.Maybe( fromMaybe )
b518458f83e6 pas2c is now fully parametric with command line options (maybe unC0Rr needs to clean this up a little)
koda
parents:
diff changeset
     8
import Pas2C
b518458f83e6 pas2c is now fully parametric with command line options (maybe unC0Rr needs to clean this up a little)
koda
parents:
diff changeset
     9
b518458f83e6 pas2c is now fully parametric with command line options (maybe unC0Rr needs to clean this up a little)
koda
parents:
diff changeset
    10
main = do
b518458f83e6 pas2c is now fully parametric with command line options (maybe unC0Rr needs to clean this up a little)
koda
parents:
diff changeset
    11
    args <- getArgs
b518458f83e6 pas2c is now fully parametric with command line options (maybe unC0Rr needs to clean this up a little)
koda
parents:
diff changeset
    12
    if length args == 0
b518458f83e6 pas2c is now fully parametric with command line options (maybe unC0Rr needs to clean this up a little)
koda
parents:
diff changeset
    13
    then do
b518458f83e6 pas2c is now fully parametric with command line options (maybe unC0Rr needs to clean this up a little)
koda
parents:
diff changeset
    14
        name <- getProgName
b518458f83e6 pas2c is now fully parametric with command line options (maybe unC0Rr needs to clean this up a little)
koda
parents:
diff changeset
    15
        hPutStrLn stderr $ usageInfo header options
b518458f83e6 pas2c is now fully parametric with command line options (maybe unC0Rr needs to clean this up a little)
koda
parents:
diff changeset
    16
        exitFailure
b518458f83e6 pas2c is now fully parametric with command line options (maybe unC0Rr needs to clean this up a little)
koda
parents:
diff changeset
    17
    else do
b518458f83e6 pas2c is now fully parametric with command line options (maybe unC0Rr needs to clean this up a little)
koda
parents:
diff changeset
    18
        case getOpt RequireOrder options args of
b518458f83e6 pas2c is now fully parametric with command line options (maybe unC0Rr needs to clean this up a little)
koda
parents:
diff changeset
    19
          (flags, [],      [])     ->
b518458f83e6 pas2c is now fully parametric with command line options (maybe unC0Rr needs to clean this up a little)
koda
parents:
diff changeset
    20
            if length args == 8 then do
7979
a3974abc62d3 verbose pas2c for parsed args
koda
parents: 7975
diff changeset
    21
                hPutStrLn stdout $ "--------Pas2C Config--------"
a3974abc62d3 verbose pas2c for parsed args
koda
parents: 7975
diff changeset
    22
                hPutStrLn stdout $ "Main module: " ++ (args !! 1)
a3974abc62d3 verbose pas2c for parsed args
koda
parents: 7975
diff changeset
    23
                hPutStrLn stdout $ "Input path : " ++ (args !! 3)
a3974abc62d3 verbose pas2c for parsed args
koda
parents: 7975
diff changeset
    24
                hPutStrLn stdout $ "Output path: " ++ (args !! 5)
a3974abc62d3 verbose pas2c for parsed args
koda
parents: 7975
diff changeset
    25
                hPutStrLn stdout $ "Altern path: " ++ (args !! 7)
a3974abc62d3 verbose pas2c for parsed args
koda
parents: 7975
diff changeset
    26
                hPutStrLn stdout $ "----------------------------"
7965
b518458f83e6 pas2c is now fully parametric with command line options (maybe unC0Rr needs to clean this up a little)
koda
parents:
diff changeset
    27
                pas2C (args !! 1) ((args !! 3)++"/") ((args !! 5)++"/") ((args !! 7)++"/")
7979
a3974abc62d3 verbose pas2c for parsed args
koda
parents: 7975
diff changeset
    28
                hPutStrLn stdout $ "----------------------------"
7965
b518458f83e6 pas2c is now fully parametric with command line options (maybe unC0Rr needs to clean this up a little)
koda
parents:
diff changeset
    29
            else do
b518458f83e6 pas2c is now fully parametric with command line options (maybe unC0Rr needs to clean this up a little)
koda
parents:
diff changeset
    30
                if length args == 6 then do
7979
a3974abc62d3 verbose pas2c for parsed args
koda
parents: 7975
diff changeset
    31
                    hPutStrLn stdout $ "--------Pas2C Config--------"
a3974abc62d3 verbose pas2c for parsed args
koda
parents: 7975
diff changeset
    32
                    hPutStrLn stdout $ "Main module: " ++ (args !! 1)
a3974abc62d3 verbose pas2c for parsed args
koda
parents: 7975
diff changeset
    33
                    hPutStrLn stdout $ "Input path : " ++ (args !! 3)
a3974abc62d3 verbose pas2c for parsed args
koda
parents: 7975
diff changeset
    34
                    hPutStrLn stdout $ "Output path: " ++ (args !! 5)
a3974abc62d3 verbose pas2c for parsed args
koda
parents: 7975
diff changeset
    35
                    hPutStrLn stdout $ "Altern path: " ++ "./"
a3974abc62d3 verbose pas2c for parsed args
koda
parents: 7975
diff changeset
    36
                    hPutStrLn stdout $ "----------------------------"
7965
b518458f83e6 pas2c is now fully parametric with command line options (maybe unC0Rr needs to clean this up a little)
koda
parents:
diff changeset
    37
                    pas2C (args !! 1) ((args !! 3)++"/") ((args !! 5)++"/") "./"
7979
a3974abc62d3 verbose pas2c for parsed args
koda
parents: 7975
diff changeset
    38
                    hPutStrLn stdout $ "----------------------------"
7965
b518458f83e6 pas2c is now fully parametric with command line options (maybe unC0Rr needs to clean this up a little)
koda
parents:
diff changeset
    39
                else do
b518458f83e6 pas2c is now fully parametric with command line options (maybe unC0Rr needs to clean this up a little)
koda
parents:
diff changeset
    40
                    error $ usageInfo header options
b518458f83e6 pas2c is now fully parametric with command line options (maybe unC0Rr needs to clean this up a little)
koda
parents:
diff changeset
    41
          (_,     nonOpts, [])     -> error $ "unrecognized arguments: " ++ unwords nonOpts
b518458f83e6 pas2c is now fully parametric with command line options (maybe unC0Rr needs to clean this up a little)
koda
parents:
diff changeset
    42
          (_,     _,       msgs)   -> error $ usageInfo header options
7969
7fcbbd46704a move pas2c files in their own directory and add a warning about argument order
koda
parents: 7965
diff changeset
    43
    where header = "Freepascal to C conversion! Please use -n -i -o -a options in this order.\n"
7965
b518458f83e6 pas2c is now fully parametric with command line options (maybe unC0Rr needs to clean this up a little)
koda
parents:
diff changeset
    44
b518458f83e6 pas2c is now fully parametric with command line options (maybe unC0Rr needs to clean this up a little)
koda
parents:
diff changeset
    45
b518458f83e6 pas2c is now fully parametric with command line options (maybe unC0Rr needs to clean this up a little)
koda
parents:
diff changeset
    46
data Flag = HelpMessage | Name String | Input String | Output String | Alternate String
b518458f83e6 pas2c is now fully parametric with command line options (maybe unC0Rr needs to clean this up a little)
koda
parents:
diff changeset
    47
b518458f83e6 pas2c is now fully parametric with command line options (maybe unC0Rr needs to clean this up a little)
koda
parents:
diff changeset
    48
options :: [OptDescr Flag]
b518458f83e6 pas2c is now fully parametric with command line options (maybe unC0Rr needs to clean this up a little)
koda
parents:
diff changeset
    49
options = [
b518458f83e6 pas2c is now fully parametric with command line options (maybe unC0Rr needs to clean this up a little)
koda
parents:
diff changeset
    50
    Option ['h'] ["help"]      (NoArg HelpMessage)      "print this help message",
b518458f83e6 pas2c is now fully parametric with command line options (maybe unC0Rr needs to clean this up a little)
koda
parents:
diff changeset
    51
    Option ['n'] ["name"]      (ReqArg Name "MAIN")     "name of the main Pascal module",
b518458f83e6 pas2c is now fully parametric with command line options (maybe unC0Rr needs to clean this up a little)
koda
parents:
diff changeset
    52
    Option ['i'] ["input"]     (ReqArg Input "DIR")     "input directory, where .pas files will be read",
b518458f83e6 pas2c is now fully parametric with command line options (maybe unC0Rr needs to clean this up a little)
koda
parents:
diff changeset
    53
    Option ['o'] ["output"]    (ReqArg Output "DIR")    "output directory, where .c/.h files will be written",
b518458f83e6 pas2c is now fully parametric with command line options (maybe unC0Rr needs to clean this up a little)
koda
parents:
diff changeset
    54
    Option ['a'] ["alternate"] (ReqArg Alternate "DIR") "alternate input directory, for out of source builds"
b518458f83e6 pas2c is now fully parametric with command line options (maybe unC0Rr needs to clean this up a little)
koda
parents:
diff changeset
    55
  ]
b518458f83e6 pas2c is now fully parametric with command line options (maybe unC0Rr needs to clean this up a little)
koda
parents:
diff changeset
    56