main = do
  opts <- getOptions
  when (showHelp opts) $ do
    putStr usage
    exitSuccess
  when (showVersion opts) $ do
    putStrLn versionString
    exitSuccess
  let gtl_file = gtlFile opts
  when (gtl_file == "") $ do
    ioError $ userError "No GTL file given"
  exists <- doesFileExist gtl_file
  when (not exists) $ do
    ioError . userError $ (gtl_file ++ " does not exist.")
  (createDirectoryIfMissing True $ outputPath opts)
    `catch` (\e -> putStrLn $ "Could not create build dir: " ++ (ioeGetErrorString e))
  gtl_str <- readFile gtl_file
  mgtl <- case runGTLParser gtl gtl_str of
    Left (err,pos) -> return (Left $ "At "++show pos++": "++err)
    Right defs -> runErrorT $ gtlParseSpec opts defs
  rgtl <- case mgtl of
    Left err -> error err
    Right x -> return x
  case mode opts of
    NativeC -> translateGTL (traceFile opts) rgtl >>= putStrLn
    Local -> verifyLocal opts (dropExtension gtl_file) rgtl
    --PromelaBuddy -> PrBd.verifyModel opts (dropExtension gtl_file) rgtl
    {-Tikz -> do
      str <- PrPr.gtlToTikz rgtl
      putStrLn str-}
    Pretty -> putStrLn (simplePrettyPrint rgtl)
    Native -> PrNat.verifyModel opts (dropExtension gtl_file) rgtl
    UPPAAL -> putStr (prettySpecification $ UPP.translateSpec rgtl)
    SMTBMC -> SMT.verifyModelBMC opts rgtl
    --SMTInduction -> SMT.verifyModelKInduction (smtBinary opts) rgtl
  return ()
main = do
  opts <- getOptions
  when (showHelp opts) $ do
    putStr usage
    exitSuccess
  when (showVersion opts) $ do
    putStrLn versionString
    exitSuccess
  let gtl_file = gtlFile opts
  when (gtl_file == "") $ do
    ioError $ userError "No GTL file given"
  exists <- doesFileExist gtl_file
  when (not exists) $ do
    ioError . userError $ (gtl_file ++ " does not exist.")
  (createDirectoryIfMissing True $ outputPath opts)
    `catch` (\e -> putStrLn $ "Could not create build dir: " ++ (ioeGetErrorString e))
  gtl_str <- readFile gtl_file
  mgtl <- case runGTLParser gtl gtl_str of
    Left (err,pos) -> return (Left $ "At "++show pos++": "++err)
    Right defs -> runErrorT $ gtlParseSpec opts defs
  rgtl <- case mgtl of
    Left err -> error err
    Right x -> return x
  case mode opts of
    NativeC -> translateGTL (traceFile opts) rgtl >>= putStrLn
    Local -> verifyLocal opts (dropExtension gtl_file) rgtl
    --PromelaBuddy -> PrBd.verifyModel opts (dropExtension gtl_file) rgtl
    {-Tikz -> do
      str <- PrPr.gtlToTikz rgtl
      putStrLn str-}
    Pretty -> putStrLn (simplePrettyPrint rgtl)
    Native -> PrNat.verifyModel opts (dropExtension gtl_file) rgtl
    UPPAAL -> putStr (prettySpecification $ UPP.translateSpec rgtl)
    SMTBMC -> SMT.verifyModelBMC opts rgtl
    --SMTInduction -> SMT.verifyModelKInduction (smtBinary opts) rgtl
  return ()
main = do
  opts <- getOptions
  when (showHelp opts) $ do
    putStr usage
    exitSuccess
  when (showVersion opts) $ do
    putStrLn versionString
    exitSuccess
  let gtl_file = gtlFile opts
  when (gtl_file == "") $ do
    ioError $ userError "No GTL file given"
  exists <- doesFileExist gtl_file
  when (not exists) $ do
    ioError . userError $ (gtl_file ++ " does not exist.")
  (createDirectoryIfMissing True $ outputPath opts)
    `catch` (\e -> putStrLn $ "Could not create build dir: " ++ (ioeGetErrorString e))
  gtl_str <- readFile gtl_file
  mgtl <- case runGTLParser gtl gtl_str of
    Left (err,pos) -> return (Left $ "At "++show pos++": "++err)
    Right defs -> runErrorT $ gtlParseSpec opts defs
  rgtl <- case mgtl of
    Left err -> error err
    Right x -> return x
  case mode opts of
    NativeC -> translateGTL (traceFile opts) rgtl >>= putStrLn
    Local -> verifyLocal opts (dropExtension gtl_file) rgtl
    --PromelaBuddy -> PrBd.verifyModel opts (dropExtension gtl_file) rgtl
    {-Tikz -> do
      str <- PrPr.gtlToTikz rgtl
      putStrLn str-}
    Pretty -> putStrLn (simplePrettyPrint rgtl)
    Native -> PrNat.verifyModel opts (dropExtension gtl_file) rgtl
    UPPAAL -> putStr (prettySpecification $ UPP.translateSpec rgtl)
    SMTBMC -> SMT.verifyModelBMC opts rgtl
    --SMTInduction -> SMT.verifyModelKInduction (smtBinary opts) rgtl
  return ()