tools/pas2c/Main.hs
branchwebgl
changeset 9982 24ea101fdc7f
parent 8836 7a474fcc343d
child 10015 4feced261c68
--- a/tools/pas2c/Main.hs	Wed Jan 08 23:49:08 2014 +0100
+++ b/tools/pas2c/Main.hs	Thu Jan 09 23:54:40 2014 +0400
@@ -5,7 +5,7 @@
 import System.Exit
 import System.IO
 import Data.Maybe( fromMaybe, isJust, fromJust )
-import Data.List (find)
+import Data.List (find, intercalate)
 import Control.Monad
 import Pas2C
 
@@ -23,13 +23,15 @@
                 let i = flag flags isInput
                 let o = flag flags isOutput
                 let a = fromMaybe o $ liftM extractString $ find isAlt flags
+                let symbols = ["PAS2C", "FPC"] ++ (map extractString $ filter isSymbol flags)
                 hPutStrLn stdout $ "--------Pas2C Config--------"
                 hPutStrLn stdout $ "Main module: " ++ m
                 hPutStrLn stdout $ "Input path : " ++ i
                 hPutStrLn stdout $ "Output path: " ++ o
                 hPutStrLn stdout $ "Altern path: " ++ a
+                hPutStrLn stdout $ "Symbols defined: " ++ (intercalate ", " symbols)
                 hPutStrLn stdout $ "----------------------------"
-                pas2C m (i++"/") (o++"/") (a++"/")
+                pas2C m (i++"/") (o++"/") (a++"/") symbols
                 hPutStrLn stdout $ "----------------------------"
                       | otherwise ->  error $ usageInfo header options
           (_,     nonOpts, [])     -> error $ "unrecognized arguments: " ++ unwords nonOpts
@@ -40,7 +42,12 @@
         flag f = extractString . fromJust . flip find f
 
 
-data Flag = HelpMessage | Name String | Input String | Output String | Alternate String
+data Flag = HelpMessage
+          | Name String
+          | Input String
+          | Output String
+          | Alternate String
+          | Symbol String
 
 
 extractString :: Flag -> String
@@ -48,9 +55,10 @@
 extractString (Input s) = s
 extractString (Output s) = s
 extractString (Alternate s) = s
+extractString (Symbol s) = s
 extractString _ = undefined
 
-isName, isInput, isOutput, isAlt :: Flag -> Bool
+isName, isInput, isOutput, isAlt, isSymbol :: Flag -> Bool
 isName (Name _) = True
 isName _ = False
 isInput (Input _) = True
@@ -59,6 +67,8 @@
 isOutput _ = False
 isAlt (Alternate _) = True
 isAlt _ = False
+isSymbol (Symbol _) = True
+isSymbol _ = False
 
 options :: [OptDescr Flag]
 options = [
@@ -66,6 +76,7 @@
     Option ['n'] ["name"]      (ReqArg Name "MAIN")     "name of the main Pascal module",
     Option ['i'] ["input"]     (ReqArg Input "DIR")     "input directory, where .pas files will be read",
     Option ['o'] ["output"]    (ReqArg Output "DIR")    "output directory, where .c/.h files will be written",
-    Option ['a'] ["alternate"] (ReqArg Alternate "DIR") "alternate input directory, for out of source builds"
+    Option ['a'] ["alternate"] (ReqArg Alternate "DIR") "alternate input directory, for out of source builds",
+    Option ['d'] ["define"]    (ReqArg Symbol "SYMBOL") "define symbol"
   ]