From 95b54c5699d04db1f311e5a204600c5859361064 Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Thu, 1 Apr 2010 01:29:26 -0400 Subject: [PATCH] Take a newline-separated list of CIDRs as input, and output a regex that will match any of them. --- src/hath.hs | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) 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 + -- 2.43.2