X-Git-Url: http://gitweb.michael.orlitzky.com/?a=blobdiff_plain;f=src%2FMain.hs;h=a3b1bfe4a811faad00f6e8503b58de540bd8703f;hb=6c671cd410b81257514e1be76ca3f252ea69ccdb;hp=a86eebf90081f0807a8628d35cff6c7a677d20c2;hpb=6c076a2622dd9a6bfc96ed05f8478b5150db176a;p=hath.git diff --git a/src/Main.hs b/src/Main.hs index a86eebf..a3b1bfe 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -1,10 +1,10 @@ -import Data.List (intercalate, intersperse) +import Data.List ((\\), intercalate, intersperse) import System.Exit (ExitCode(..), exitWith) import System.IO (stderr, hPutStrLn) import Cidr (Cidr(..), cidr_from_string, - is_valid_cidr) + combine_all) import CommandLine (help_set, help_text, @@ -81,18 +81,6 @@ numeric_range x y = upper = maximum [x,y] --- Take a CIDR String, and exit with a failure if it's invalid. -validate_or_die :: String -> IO () -validate_or_die cidr = do - if (Cidr.is_valid_cidr cidr) - then do - return () - else do - putStrLn "Error: not valid CIDR notation." - exitWith (ExitFailure exit_invalid_cidr) - - - main :: IO () main = do -- First, check for any errors that occurred while parsing @@ -119,9 +107,14 @@ main = do input <- inputfunc let cidr_strings = lines input - mapM validate_or_die cidr_strings let cidrs = map Cidr.cidr_from_string cidr_strings + if (any (== Cidr.None) cidrs) + then do + putStrLn "Error: not valid CIDR notation." + exitWith (ExitFailure exit_invalid_cidr) + else do -- Nothing + -- Get the mode of operation. mode <- CommandLine.parse_mode @@ -130,4 +123,10 @@ main = do let regexes = map cidr_to_regex cidrs putStrLn $ alternate regexes Reduce -> do - putStr input + mapM (putStrLn . show) (combine_all cidrs) + return () + Dupe -> do + mapM (putStrLn . show) dupes + return () + where + dupes = cidrs \\ (combine_all cidrs)