X-Git-Url: http://gitweb.michael.orlitzky.com/?a=blobdiff_plain;f=src%2FMain.hs;h=174efe28258e608ac48c488ae8225522699b7057;hb=e47e94c4121f7b1669df1a97fbaf8e8c434c256d;hp=d66b6009c5187b643b0ea12e588cda26873eb39e;hpb=13b975060857b8acd64b7231074dc4a0c0a2915a;p=hath.git diff --git a/src/Main.hs b/src/Main.hs index d66b600..174efe2 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -4,13 +4,12 @@ where import Control.Monad (when) import Data.List ((\\), intercalate) import Data.Maybe (catMaybes, isNothing) -import Data.String.Utils (splitWs) -import System.Exit (ExitCode(..), exitWith) +import System.Exit (ExitCode( ExitFailure ), exitWith) import System.IO (stderr, hPutStrLn) import Text.Read (readMaybe) import Cidr ( - Cidr(..), + Cidr(), combine_all, enumerate, max_octet1, @@ -21,7 +20,9 @@ import Cidr ( min_octet2, min_octet3, min_octet4 ) -import CommandLine (Args(..), get_args) +import CommandLine( + Args( Regexed, Reduced, Duped, Diffed, Listed, barriers ), + get_args ) import ExitCodes ( exit_invalid_cidr ) import Octet () @@ -51,7 +52,7 @@ add_barriers x = non_addr_char ++ x ++ non_addr_char -- 5. Stick an address boundary on either side of the result if -- use_barriers is True. -- -cidr_to_regex :: Bool -> Cidr.Cidr -> String +cidr_to_regex :: Bool -> Cidr -> String cidr_to_regex use_barriers cidr = let f = if use_barriers then add_barriers else id in f (intercalate "\\." [range1, range2, range3, range4]) @@ -101,7 +102,7 @@ main = do -- This reads stdin. input <- getContents - let cidr_strings = splitWs input + let cidr_strings = words input let cidrs = map readMaybe cidr_strings :: [Maybe Cidr] when (any isNothing cidrs) $ do @@ -109,7 +110,9 @@ main = do -- Output the bad lines, safely. let pairs = zip cidr_strings cidrs - let print_pair (x, Nothing) = hPutStrLn stderr (" * " ++ x) + + let print_pair :: (String, Maybe Cidr) -> IO () + print_pair (x, Nothing) = hPutStrLn stderr (" * " ++ x) print_pair (_, _) = return () mapM_ print_pair pairs