X-Git-Url: http://gitweb.michael.orlitzky.com/?a=blobdiff_plain;f=src%2FMain.hs;h=6fa7da9203645e193d177de6a97ffed87a7c7f97;hb=f81e236ab90102d8afd6d6080131b77d59e38348;hp=7017a191b85530f639b822acd19b5143fb8cf5ee;hpb=76b555ca0ff80d36b481d1b86900bf1683d57081;p=hath.git diff --git a/src/Main.hs b/src/Main.hs index 7017a19..6fa7da9 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -1,10 +1,18 @@ -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, - combine_all) + combine_all, + max_octet1, + max_octet2, + max_octet3, + max_octet4, + min_octet1, + min_octet2, + min_octet3, + min_octet4 ) import CommandLine (help_set, help_text, @@ -13,7 +21,6 @@ import CommandLine (help_set, parse_errors, parse_mode) -import IPv4Address import Octet -- Some exit codes, used in the ExitFailure constructor. @@ -54,14 +61,14 @@ cidr_to_regex cidr = range2 = numeric_range min2 max2 range3 = numeric_range min3 max3 range4 = numeric_range min4 max4 - min1 = octet_to_int (min_octet1 (ipv4address cidr) (maskbits cidr)) - min2 = octet_to_int (min_octet2 (ipv4address cidr) (maskbits cidr)) - min3 = octet_to_int (min_octet3 (ipv4address cidr) (maskbits cidr)) - min4 = octet_to_int (min_octet4 (ipv4address cidr) (maskbits cidr)) - max1 = octet_to_int (max_octet1 (ipv4address cidr) (maskbits cidr)) - max2 = octet_to_int (max_octet2 (ipv4address cidr) (maskbits cidr)) - max3 = octet_to_int (max_octet3 (ipv4address cidr) (maskbits cidr)) - max4 = octet_to_int (max_octet4 (ipv4address cidr) (maskbits cidr)) + min1 = octet_to_int (min_octet1 cidr) + min2 = octet_to_int (min_octet2 cidr) + min3 = octet_to_int (min_octet3 cidr) + min4 = octet_to_int (min_octet4 cidr) + max1 = octet_to_int (max_octet1 cidr) + max2 = octet_to_int (max_octet2 cidr) + max3 = octet_to_int (max_octet3 cidr) + max4 = octet_to_int (max_octet4 cidr) @@ -123,5 +130,19 @@ main = do let regexes = map cidr_to_regex cidrs putStrLn $ alternate regexes Reduce -> do - mapM (putStrLn . show) (combine_all cidrs) + _ <- mapM (putStrLn . show) (combine_all cidrs) return () + Dupe -> do + _ <- mapM (putStrLn . show) dupes + return () + where + dupes = cidrs \\ (combine_all cidrs) + Diff -> do + _ <- mapM putStrLn deletions + _ <- mapM putStrLn additions + return () + where + dupes = cidrs \\ (combine_all cidrs) + deletions = map (\s -> "-" ++ (show s)) dupes + newcidrs = (combine_all cidrs) \\ cidrs + additions = map (\s -> "+" ++ (show s)) newcidrs