X-Git-Url: https://git.danieliu.xyz/?p=ekitaihs.git;a=blobdiff_plain;f=Parse.hs;h=2375c4fb4db8674bc05c4cb66f625081872e40e8;hp=367caff6d151839d76090125d007648b46fada3c;hb=HEAD;hpb=4de2980e358a4ed8bb05e615a3fee16215b03c1f diff --git a/Parse.hs b/Parse.hs index 367caff..2375c4f 100644 --- a/Parse.hs +++ b/Parse.hs @@ -1,32 +1,23 @@ -module Parse ( ekitaiOpts, optTimeStep ) where +module Parse ( ekitaiOpts, optTimeStep, hGetLines ) where import System.Console.GetOpt import System.Environment import System.Exit +import System.IO import Data.Maybe import Data.Either data Options = Options - { optHelp :: Bool - , optColor :: Bool - , optTimeStep :: Int + { optTimeStep :: Int } defaultOptions = Options - { optHelp = False - , optColor = False - , optTimeStep = 50000 + { optTimeStep = 50000 } options :: [OptDescr (Options -> Options)] options = - [ Option ['h'] ["help"] - (NoArg (\opts -> opts { optHelp = True })) - "display's this message" - , Option ['c'] ["color", "colour"] - (NoArg (\opts -> opts { optColor = True })) - "enables color" - , Option ['t'] ["timestep"] + [ Option ['t'] ["timestep"] (ReqArg (\t opts -> opts { optTimeStep = read t :: Int }) "timestep") "sets the simulation time step" ] @@ -38,10 +29,13 @@ ekitaiOpts argv = (o, _, []) -> ioError $ userError $ "missing input file" (_, _, errs) -> ioError $ userError $ concat errs --- ++ usageInfo header options --- where header = "Usage: ekitai [OPTIONS...] simfile" +-- reads in file by lines +hGetLines :: Handle -> IO [String] +hGetLines h = do + line <- hGetLine h + isEof <- hIsEOF h + if isEof then return [line] + else do + lines <- hGetLines h + return (line:lines) - -- (o, _, []) -> do - -- opts <- (foldl (flip id) defaultOptions o) - -- if optHelp then userError $ concat usageInfo "Usage: ekitai [OPTIONS...] simfile" options - -- else ioError $ userError $ "missing input file"