]> gitweb.michael.orlitzky.com - hath.git/blobdiff - src/Main.hs
Use "words" instead of "splitWs" and drop MissingH dependency.
[hath.git] / src / Main.hs
index 5b75533863c11b515f7f104df7b09948065a9e59..174efe28258e608ac48c488ae8225522699b7057 100644 (file)
@@ -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,15 +102,17 @@ main = do
   -- This reads stdin.
   input <- getContents
 
-  let cidr_strings = splitWs input
-  let cidrs = map readMaybe cidr_strings
+  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 (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