1 module Parse ( ekitaiOpts, optTimeStep, hGetLines ) where
3 import System.Console.GetOpt
4 import System.Environment
10 data Options = Options
16 defaultOptions = Options
22 options :: [OptDescr (Options -> Options)]
24 [ Option ['h'] ["help"]
25 (NoArg (\opts -> opts { optHelp = True }))
26 "display's this message"
27 , Option ['c'] ["color", "colour"]
28 (NoArg (\opts -> opts { optColor = True }))
30 , Option ['t'] ["timestep"]
31 (ReqArg (\t opts -> opts { optTimeStep = read t :: Int }) "timestep")
32 "sets the simulation time step"
35 ekitaiOpts :: [String] -> IO (Options, String)
37 case getOpt RequireOrder options argv of
38 (o, [n], []) -> return (foldl (flip id) defaultOptions o, n)
39 (o, _, []) -> ioError $ userError $ "missing input file"
40 (_, _, errs) -> ioError $ userError $ concat errs
42 -- reads in file by lines
43 hGetLines :: Handle -> IO [String]
47 if isEof then return [line]