tools/pas2c/Main.hs
author koda
Mon, 05 Nov 2012 01:35:54 +0100
branchwebgl
changeset 7969 7fcbbd46704a
parent 7965 tools/Main.hs@b518458f83e6
child 7975 1a8308265fdd
permissions -rw-r--r--
move pas2c files in their own directory and add a warning about argument order
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( getArgs )
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.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
     5
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
     6
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
     7
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
     8
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
     9
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
    10
b518458f83e6 pas2c is now fully parametric with command line options (maybe unC0Rr needs to clean this up a little)
koda
parents:
diff changeset
    11
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
    12
    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
    13
    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
    14
    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
    15
        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
    16
        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
    17
        exitFailure
b518458f83e6 pas2c is now fully parametric with command line options (maybe unC0Rr needs to clean this up a little)
koda
parents:
diff changeset
    18
    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
    19
        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
    20
          (flags, [],      [])     ->
b518458f83e6 pas2c is now fully parametric with command line options (maybe unC0Rr needs to clean this up a little)
koda
parents:
diff changeset
    21
            if length args == 8 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
    22
                pas2C (args !! 1) ((args !! 3)++"/") ((args !! 5)++"/") ((args !! 7)++"/")
b518458f83e6 pas2c is now fully parametric with command line options (maybe unC0Rr needs to clean this up a little)
koda
parents:
diff changeset
    23
            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
    24
                if length args == 6 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
    25
                    pas2C (args !! 1) ((args !! 3)++"/") ((args !! 5)++"/") "./"
b518458f83e6 pas2c is now fully parametric with command line options (maybe unC0Rr needs to clean this up a little)
koda
parents:
diff changeset
    26
                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
    27
                    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
    28
          (_,     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
    29
          (_,     _,       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
    30
    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
    31
b518458f83e6 pas2c is now fully parametric with command line options (maybe unC0Rr needs to clean this up a little)
koda
parents:
diff changeset
    32
b518458f83e6 pas2c is now fully parametric with command line options (maybe unC0Rr needs to clean this up a little)
koda
parents:
diff changeset
    33
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
    34
b518458f83e6 pas2c is now fully parametric with command line options (maybe unC0Rr needs to clean this up a little)
koda
parents:
diff changeset
    35
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
    36
options = [
b518458f83e6 pas2c is now fully parametric with command line options (maybe unC0Rr needs to clean this up a little)
koda
parents:
diff changeset
    37
    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
    38
    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
    39
    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
    40
    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
    41
    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
    42
  ]
b518458f83e6 pas2c is now fully parametric with command line options (maybe unC0Rr needs to clean this up a little)
koda
parents:
diff changeset
    43