definition:
|
main :: IO ()
main = do
args <- getArgs
case args of
(orgSourceFile:inFile:outFile:options) ->
maybe (showUsage args)
(\opts ->
if optHelp opts
then putStrLn (cppBanner ++ usageText) >> exitWith 1
else do
cpath <- getEnv "CURRYPATH"
let (mbdir, modname) = pathToModName cpath orgSourceFile
when (optVerb opts > 1) $ putStr cppBanner
when (optVerb opts > 2) $ putStr $ unlines
["CURRYPATH : " ++ cpath
,"Module name : " ++ modname
,"Original file name : " ++ orgSourceFile
,"Input file name : " ++ inFile
,"Output file name : " ++ outFile ]
addDir2CurryPath opts cpath mbdir $
preprocess opts modname orgSourceFile inFile outFile
when (optSave opts) $ saveFile orgSourceFile outFile
when (optVerb opts > 3) $ do
putStrLn "TRANSFORMED PROGRAM:"
putStrLn "===================="
readFile outFile >>= putStrLn
putStrLn "--------------------"
)
(processOptions initOpts options)
_ -> maybe (showUsage args)
(\opts -> if optHelp opts
then putStrLn (cppBanner ++ usageText)
else showUsage args)
(processOptions initOpts args)
where
-- extend CURRYPATH with a directory (if necessary) and execute last argument
addDir2CurryPath _ _ Nothing act = act
addDir2CurryPath opts cpath (Just dir) act
| dir == "." = act
| otherwise = do
when (optVerb opts > 2) $ putStrLn $
"Adding directory '" ++ dir ++ "' to CURRYPATH"
let newcpath = if null cpath then dir
else dir ++ [searchPathSeparator] ++ cpath
setEnv "CURRYPATH" newcpath
act
setEnv "CURRYPATH" cpath
saveFile orgSourceFile outFile = do
let sFile = orgSourceFile++".CURRYPP"
copyFile outFile sFile
putStrLn $ "Translated Curry file written to '" ++ sFile ++ "'"
|