"(regexed mode) place barriers in front/back of the regex " ++
"to prevent e.g. '127.0.0.1' from matching '127.0.0.100'"
+normalize_help :: String
+normalize_help =
+ "(reduced mode) normalize the output CIDRS, replacing any " ++
+ "masked bits by zeros; e.g. '127.0.0.1/8' -> '127.0.0.0/8'"
+
-- | The Args type represents the possible command-line options. The
-- duplication here seems necessary; CmdArgs' magic requires us to
-- define some things explicitly.
--
--- The application currently has six modes (if this number is wrong,
+-- The application currently has five modes (if this number is wrong,
-- it means I forgot to update the comment!), all of which take the
-- same options and arguments.
--
data Args =
- Regexed { barriers :: Bool } |
- Reduced { barriers :: Bool } |
- Duped { barriers :: Bool } |
- Diffed { barriers :: Bool } |
- Listed { barriers :: Bool }
+ Regexed { barriers :: Bool, normalize :: Bool } |
+ Reduced { barriers :: Bool, normalize :: Bool } |
+ Duped { barriers :: Bool, normalize :: Bool } |
+ Diffed { barriers :: Bool, normalize :: Bool } |
+ Listed { barriers :: Bool, normalize :: Bool }
deriving (Data, Show)
-- | Description of the 'Regexed' mode.
name "v",
groupname "Common flags"]
where
- make_mode :: (Bool -> Args) -> String -> (Annotate Ann)
+ make_mode :: (Bool -> Bool -> Args) -> String -> (Annotate Ann)
make_mode ctor desc =
- record (ctor def) [ barriers := def
- += groupname "Common flags"
- += help barriers_help ]
- += details [" " ++ desc]
+ record (ctor def def)
+ [ barriers := def
+ += groupname "Common flags"
+ += help barriers_help,
+ normalize := def
+ += groupname "Common flags"
+ += help normalize_help ]
+ += details [" " ++ desc]
regexed = make_mode Regexed regexed_description
reduced = make_mode Reduced reduced_description
min_octet2,
min_octet3,
min_octet4 )
+import qualified Cidr ( normalize )
import CommandLine(
- Args( Regexed, Reduced, Duped, Diffed, Listed, barriers ),
+ Args( Regexed, Reduced, Duped, Diffed, Listed, barriers, normalize ),
get_args )
import ExitCodes ( exit_invalid_cidr )
import Octet ()
let cidrs' = combine_all valid_cidrs
let regexes = map (cidr_to_regex (barriers args)) cidrs'
putStrLn $ alternate regexes
- Reduced{} ->
- mapM_ print (combine_all valid_cidrs)
+ Reduced{} -> do
+ -- Pre-normalize all CIDRs if the user asked for it.
+ let nrml_func = if (normalize args) then Cidr.normalize else id
+ mapM_ print (combine_all (map nrml_func valid_cidrs))
Duped{} ->
mapM_ print dupes
where