(C) Roger Whittaker 2015
roger@disruptive.org.uk
Free software licenced under the GPL

> import System.IO
> import Text.Printf
> import System.Environment
> import System.Console.GetOpt.Utils
> import System.Console.GetOpt
> import Control.Monad
> import System.Exit
> import Data.List
> import Data.Maybe

> import Penrose
> import Version
> import Postscript
> import Svg
> import Utils

for the options stuff, used this:
http://code.ohloh.net/file?fid=AuGSnlNskuYVFduT-ZUnfMhC1Q8&cid=qWJZ3iR2uhs&s=&browser=Default#L0

> main :: IO ()
> main = do
>        argv <- getArgs
>        case getOpt RequireOrder options argv of
>             (o, n, []) -> run o n
>             (_, _, errors) -> usageerror (concat errors)

> options = [Option "t" ["type"  ] (ReqArg (stdRequired "t") "svg|ps|txt") "type"
>           ,Option "o" ["output"] (ReqArg (stdRequired "o") "FILE"      ) "output file"
>           ,Option "n" ["nofill"] (NoArg  ("f", ""        )             ) "no fill"
>           ]

> p "ps"  = processps
> p "svg" = processsvg
> p "txt" = unlines . snd


> run args cmdargs = do let j = cmdargs
>                       if length j >= 5
>                         then do let it = read (j!!0) :: Int
>                                 let sc = fixdec (j!!1)
>                                 let g  = (map fixnum (drop 2 j)) :: [Double]
>                                 if (isNothing (lookup "t" args))
>                                   then do putStrLn "no type given: the -t option is required"
>                                           usageerror ""
>                                   else do let t = fromJust (lookup "t" args)
>                                           if not (t `elem` ["ps", "txt", "svg"])
>                                             then do putStrLn "unknown type: the -t option is required"
>                                                     usageerror ""
>                                             else if isNothing (lookup "o" args)
>                                                     then do putStrLn (p t (writeall g it sc ver))
>                                                     else do let fn = fromJust (lookup "o" args)
>                                                             fh <- openFile fn WriteMode
>                                                             hPutStrLn fh (p t (writeall g it sc ver))
>                                                             hClose fh
>                       else do putStrLn "not enough arguments"
>                               usageerror ""

> usageerror errormsg = do putStrLn errormsg
>                          putStrLn (usageInfo header options)
>                          exitFailure

> header = "Usage: gppg -t TYPE [-o FILE] <it> <sc> <g 0> <g 1> ... <g n-1>\n\n" ++
>          "       where TYPE is one of \"ps\", \"svg\", or \"txt\", and\n"      ++
>          "             <it> (number of iterations) is an integer >=0\n"        ++
>          "             <sc> (scale) is any positive number\n"                  ++
>          "             <g 0>, <g 1> ... <g n-1> are any decimals (n>=3) \n\n"
