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
+