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.

54 lines
1.6 KiB

  1. module Opt(parseArgs,Options(..)) where
  2. import System.Console.GetOpt
  3. import Data.Maybe
  4. -- import Vm
  5. data Flag = File String
  6. | Time Int
  7. | Mem Int
  8. | PowerPhrase String
  9. deriving Show
  10. data Options = Options { optFile :: [String]
  11. , optTime :: Maybe Int
  12. , optMem :: Maybe Int
  13. , optPowerPhrase :: Maybe String
  14. }
  15. deriving Show
  16. startOptions = Options { optFile = []
  17. , optTime = Nothing
  18. , optMem = Nothing
  19. , optPowerPhrase = Nothing
  20. }
  21. options :: [ OptDescr (Options -> IO Options) ]
  22. options = [ Option "f" ["filename"]
  23. (ReqArg
  24. (\arg opt -> return opt { optFile = (arg:(optFile opt)) })
  25. "FILE")
  26. "Input Filename"
  27. , Option "t" ["timelimit"]
  28. (ReqArg
  29. (\arg opt -> return opt { optTime = Just (read arg) })
  30. "TIMELIMIT")
  31. "Time Limit in seconds"
  32. , Option "m" ["memlimit"]
  33. (ReqArg
  34. (\arg opt -> return opt { optMem = Just (read arg) })
  35. "MEMLIMIT")
  36. "Memory Limit in MB"
  37. , Option "p" ["phrasepower"]
  38. (ReqArg
  39. (\arg opt -> return opt { optPowerPhrase = Just arg })
  40. "POWERPHRASE")
  41. "Power Phrase"
  42. ]
  43. parseArgs :: [String] -> IO Options
  44. parseArgs args = do
  45. let (actions, _, _) = getOpt RequireOrder options args
  46. opts <- foldl (>>=) (return startOptions) actions
  47. return opts