tools/pas2c/Main.hs
branchwebgl
changeset 7969 7fcbbd46704a
parent 7965 b518458f83e6
child 7975 1a8308265fdd
equal deleted inserted replaced
7965:b518458f83e6 7969:7fcbbd46704a
       
     1 module Main( main ) where
       
     2 
       
     3 import System( getArgs )
       
     4 import System.Console.GetOpt
       
     5 import System.Environment
       
     6 import System.Exit
       
     7 import System.IO
       
     8 import Data.Maybe( fromMaybe )
       
     9 import Pas2C
       
    10 
       
    11 main = do
       
    12     args <- getArgs
       
    13     if length args == 0
       
    14     then do
       
    15         name <- getProgName
       
    16         hPutStrLn stderr $ usageInfo header options
       
    17         exitFailure
       
    18     else do
       
    19         case getOpt RequireOrder options args of
       
    20           (flags, [],      [])     ->
       
    21             if length args == 8 then do
       
    22                 pas2C (args !! 1) ((args !! 3)++"/") ((args !! 5)++"/") ((args !! 7)++"/")
       
    23             else do
       
    24                 if length args == 6 then do
       
    25                     pas2C (args !! 1) ((args !! 3)++"/") ((args !! 5)++"/") "./"
       
    26                 else do
       
    27                     error $ usageInfo header options
       
    28           (_,     nonOpts, [])     -> error $ "unrecognized arguments: " ++ unwords nonOpts
       
    29           (_,     _,       msgs)   -> error $ usageInfo header options
       
    30     where header = "Freepascal to C conversion! Please use -n -i -o -a options in this order.\n"
       
    31 
       
    32 
       
    33 data Flag = HelpMessage | Name String | Input String | Output String | Alternate String
       
    34 
       
    35 options :: [OptDescr Flag]
       
    36 options = [
       
    37     Option ['h'] ["help"]      (NoArg HelpMessage)      "print this help message",
       
    38     Option ['n'] ["name"]      (ReqArg Name "MAIN")     "name of the main Pascal module",
       
    39     Option ['i'] ["input"]     (ReqArg Input "DIR")     "input directory, where .pas files will be read",
       
    40     Option ['o'] ["output"]    (ReqArg Output "DIR")    "output directory, where .c/.h files will be written",
       
    41     Option ['a'] ["alternate"] (ReqArg Alternate "DIR") "alternate input directory, for out of source builds"
       
    42   ]
       
    43