hevolisa 0.0 → 0.0.1
raw patch · 3 files changed
+37/−3 lines, 3 files
Files
- Hevolisa.hs +32/−1
- Hevolisa/Renderer.hs +4/−1
- hevolisa.cabal +1/−1
Hevolisa.hs view
@@ -1,3 +1,4 @@+{-# LANGUAGE PatternGuards #-} -- -- Module : Hevolisa -- Copyright : (c) Daniel Neun 2008 @@ -9,7 +10,37 @@ module Main where import Hevolisa.Evolution (start) +import System.Console.GetOpt +import System.Environment (getArgs) +import System.Exit (ExitCode(..),exitWith) +import System.IO (hPutStrLn,stderr,stdout) +import System.IO.Error +data Flag = Help | F FilePath + deriving Eq +options :: [OptDescr Flag] +options = [ Option ['h'] ["help"] (NoArg Help) + "Show this help message"] + + main :: IO () -main = start "mona_lisa_crop.png" >> return ()+main = parseArgs >> return () + +parseArgs = do + argv <- getArgs + case parse argv of + (opts,files,[]) + | Help `elem` opts -> help + | not $ null files -> tryStart $ head files + (_,_,errs) -> die errs + where parse argv = getOpt Permute options argv + header = "Usage: hevolisa PNGFILE" + info = usageInfo header options + dump = hPutStrLn stderr + die errs = dump (concat errs ++ info) >> exitWith (ExitFailure 1) + help = dump info >> exitWith ExitSuccess + tryStart path = do result <- try (start path) + case result of + Left e -> putStrLn $ show e + Right _ -> return ()
Hevolisa/Renderer.hs view
@@ -12,6 +12,7 @@ where import System.FilePath ((</>),(<.>))+import System.IO.Error import Control.Monad import Data.ByteString (unpack) import Directory@@ -80,7 +81,9 @@ -- | Open an image file and apply the function withImageFromPNG :: FilePath -> ([Integer] -> IO a) -> IO a-withImageFromPNG fp f = C.withImageSurfaceFromPNG fp unpackSurface >>= f+withImageFromPNG fp f = do fileExists <- doesFileExist fp+ unless fileExists $ ioError $ userError ("File does not exist: " ++ fp)+ C.withImageSurfaceFromPNG fp unpackSurface >>= f -- | Rasterize the drawing and save it to a file drawingToFile :: DnaDrawing -> Int -> IO ()
hevolisa.cabal view
@@ -1,5 +1,5 @@ Name: hevolisa -Version: 0.0 +Version: 0.0.1 Cabal-Version: >= 1.2 License: BSD3 License-file: LICENSE