module snug import StdEnv import StdMaybe import System.CommandLine import Snug.Parse Start w # ([prog:args],w) = getCommandLine w | length args <> 1 = abort ("Usage: " +++ prog +++ " INPUT\n") # input = hd args # (mbInput,w) = readFile input w input = fromJust mbInput | isNone mbInput = abort "Failed to read input\n" | otherwise = parseSnug input readFile :: !String !*World -> (!?[Char], !*World) readFile path w # (ok,f,w) = fopen path FReadData w | not ok = (?None, w) # (contents,f) = read [] f # (_,w) = fclose f w = (?Just contents, w) where read :: ![Char] !*File -> (![Char], !*File) read acc f # (ok,c,f) = freadc f | not ok = (reverse acc, f) | otherwise = read [c:acc] f