From: Michael Orlitzky Date: Thu, 1 Apr 2010 05:29:26 +0000 (-0400) Subject: Take a newline-separated list of CIDRs as input, and output a regex that will match... X-Git-Tag: 0.0.1~96 X-Git-Url: https://gitweb.michael.orlitzky.com/?a=commitdiff_plain;h=95b54c5699d04db1f311e5a204600c5859361064;p=hath.git Take a newline-separated list of CIDRs as input, and output a regex that will match any of them. --- diff --git a/src/hath.hs b/src/hath.hs index ecdb566..7b406a8 100644 --- a/src/hath.hs +++ b/src/hath.hs @@ -199,14 +199,22 @@ numeric_range x y = upper = maximum [x,y] -main :: IO () -main = do - line <- getLine - - if (is_valid_cidr line) +-- Take a CIDR String, and exitFailure if it's invalid. +validate_or_die :: String -> IO () +validate_or_die cidr = do + if (is_valid_cidr cidr) then do - putStrLn (cidr_to_regex line) + return () else do putStrLn "Error: not valid CIDR notation." exitFailure + +main :: IO () +main = do + input <- getContents + let cidrs = lines input + mapM validate_or_die cidrs + let regexes = map cidr_to_regex cidrs + putStrLn $ alternate regexes +