You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

74 lines
2.3 KiB

module Opt(parseArgs,Options(..)) where
import System.Console.GetOpt
import Data.Maybe
-- import Vm
data Flag = File String
| Time Int
| Mem Int
| PowerPhrase String
deriving Show
data Options = Options { optFile :: [String],
optTime :: Maybe Int,
optMem :: Maybe Int,
optPowerPhrase :: Maybe String,
optSeedNumber :: Int,
optCores :: Int,
optLog :: Bool
}
deriving Show
startOptions = Options { optFile = [],
optTime = Nothing,
optMem = Nothing,
optPowerPhrase = Nothing,
optSeedNumber = 0,
optCores = 1,
optLog = True
}
options :: [ OptDescr (Options -> IO Options) ]
options = [ Option "f" ["filename"]
(ReqArg
(\arg opt -> return opt { optFile = (arg:(optFile opt)) })
"FILE")
"Input Filename"
, Option "t" ["timelimit"]
(ReqArg
(\arg opt -> return opt { optTime = Just (read arg) })
"TIMELIMIT")
"Time Limit in seconds"
, Option "m" ["memlimit"]
(ReqArg
(\arg opt -> return opt { optMem = Just (read arg) })
"MEMLIMIT")
"Memory Limit in MB"
, Option "p" ["phrasepower"]
(ReqArg
(\arg opt -> return opt { optPowerPhrase = Just arg })
"POWERPHRASE")
"Power Phrase"
, Option "n" ["seednumber"]
(ReqArg
(\arg opt -> return opt { optSeedNumber = (read arg) })
"SEEDNUMBER")
"Seed Number"
, Option "c" ["cores"]
(ReqArg
(\arg opt -> return opt { optCores = (read arg) })
"CORES")
"Cores"
, Option "l" ["log"]
(NoArg
(\ opt -> return opt { optLog = True }))
"Log"
]
parseArgs :: [String] -> IO Options
parseArgs args = do
let (actions, _, _) = getOpt RequireOrder options args
opts <- foldl (>>=) (return startOptions) actions
return opts