]> gitweb.michael.orlitzky.com - hath.git/commitdiff
Take a newline-separated list of CIDRs as input, and output a regex that will match...
authorMichael Orlitzky <michael@orlitzky.com>
Thu, 1 Apr 2010 05:29:26 +0000 (01:29 -0400)
committerMichael Orlitzky <michael@orlitzky.com>
Thu, 1 Apr 2010 05:29:26 +0000 (01:29 -0400)
src/hath.hs

index ecdb56628be3271613af1bb36483229558e17318..7b406a8ce9f3332a182d9ff087a9b8ec9011d19d 100644 (file)
@@ -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
+