+ let cidr_strings = words input
+ let cidrs = map readMaybe cidr_strings :: [Maybe Cidr]
+
+ when (any isNothing cidrs) $ do
+ hPutStrLn stderr "ERROR: not valid CIDR notation:"
+
+ -- Output the bad lines, safely.
+ let pairs = zip cidr_strings cidrs
+
+ let print_pair :: (String, Maybe Cidr) -> IO ()
+ print_pair (x, Nothing) = hPutStrLn stderr (" * " ++ x)
+ print_pair (_, _) = return ()
+
+ mapM_ print_pair pairs
+ exitWith (ExitFailure exit_invalid_cidr)
+
+ -- Filter out only the valid ones.
+ let valid_cidrs = catMaybes cidrs
+
+ case args of
+ Regexed{} -> do
+ let cidrs' = combine_all valid_cidrs
+ let regexes = map (cidr_to_regex (barriers args)) cidrs'
+ putStrLn $ alternate regexes
+ Reduced{} -> do
+ -- Pre-normalize all CIDRs if the user asked for it.
+ let nrml_func = if (normalize args) then Cidr.normalize else id
+ let sort_func = if (sort args) then List.sort else id :: [Cidr] -> [Cidr]
+ mapM_ (print . nrml_func) (sort_func $ combine_all valid_cidrs)
+ Duped{} ->
+ mapM_ print dupes
+ where
+ dupes = valid_cidrs \\ (combine_all valid_cidrs)
+ Diffed{} -> do
+ mapM_ putStrLn deletions
+ mapM_ putStrLn additions
+ where
+ dupes = valid_cidrs \\ (combine_all valid_cidrs)
+ deletions = map (\s -> '-' : (show s)) dupes
+ newcidrs = (combine_all valid_cidrs) \\ valid_cidrs
+ additions = map (\s -> '+' : (show s)) newcidrs
+ Listed{} -> do
+ let combined_cidrs = combine_all valid_cidrs
+ let addrs = concatMap enumerate combined_cidrs
+ mapM_ print addrs