X-Git-Url: https://gitweb.michael.orlitzky.com/?p=hath.git;a=blobdiff_plain;f=src%2FMain.hs;h=12511b61463b6d04a721434cbb7e7d8b09db15e8;hp=dd7eefe963e5aedb5c0b19d486f1cc510d470fac;hb=3c9316fed6fd100be9a5e1f8d72db6534fb163cd;hpb=ea257ba2e191df27cf23feb98a8110157987bfb9 diff --git a/src/Main.hs b/src/Main.hs index dd7eefe..12511b6 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -1,8 +1,8 @@ -import Control.Monad (when) -import Data.List ((\\), intercalate, intersperse) +import Control.Monad (unless, when) +import Data.List ((\\), intercalate) import Data.Maybe (catMaybes, isNothing) import Data.String.Utils (splitWs) -import System.Exit (ExitCode(..), exitWith) +import System.Exit (ExitCode(..), exitSuccess, exitWith) import System.IO (stderr, hPutStrLn) import Cidr (Cidr(..), @@ -71,7 +71,7 @@ cidr_to_regex cidr = -- | Take a list of Strings, and return a regular expression matching -- any of them. alternate :: [String] -> String -alternate terms = "(" ++ (concat (intersperse "|" terms)) ++ ")" +alternate terms = "(" ++ (intercalate "|" terms) ++ ")" -- | Take two Ints as parameters, and return a regex matching any @@ -89,7 +89,7 @@ main = do -- First, check for any errors that occurred while parsing -- the command line options. errors <- CommandLine.parse_errors - when ((not . null) errors) $ do + unless (null errors) $ do hPutStrLn stderr (concat errors) putStrLn CommandLine.help_text exitWith (ExitFailure exit_args_parse_failed) @@ -99,7 +99,7 @@ main = do help_opt_set <- CommandLine.help_set when help_opt_set $ do putStrLn CommandLine.help_text - exitWith ExitSuccess + exitSuccess -- The input function we receive here should know what to read. inputfunc <- (CommandLine.input_function) @@ -123,10 +123,10 @@ main = do let regexes = map cidr_to_regex valid_cidrs putStrLn $ alternate regexes Reduce -> do - _ <- mapM (putStrLn . show) (combine_all valid_cidrs) + _ <- mapM print (combine_all valid_cidrs) return () Dupe -> do - _ <- mapM (putStrLn . show) dupes + _ <- mapM print dupes return () where dupes = valid_cidrs \\ (combine_all valid_cidrs) @@ -136,6 +136,6 @@ main = do return () where dupes = valid_cidrs \\ (combine_all valid_cidrs) - deletions = map (\s -> "-" ++ (show s)) dupes + deletions = map (\s -> '-' : (show s)) dupes newcidrs = (combine_all valid_cidrs) \\ valid_cidrs - additions = map (\s -> "+" ++ (show s)) newcidrs + additions = map (\s -> '+' : (show s)) newcidrs