|
|
- 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
- }
- deriving Show
-
- startOptions = Options { optFile = []
- , optTime = Nothing
- , optMem = Nothing
- , optPowerPhrase = Nothing
- }
-
- 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"
- ]
-
- parseArgs :: [String] -> IO Options
- parseArgs args = do
- let (actions, _, _) = getOpt RequireOrder options args
- opts <- foldl (>>=) (return startOptions) actions
- return opts
|