From 7558c08e7dfb3d15be1bfa9a627373d20dcf2e51 Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Sun, 6 Dec 2020 08:42:01 +1000 Subject: [PATCH] analyse: provide defaults for bits, window, and minimum --- tools/analyse.cpp | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/tools/analyse.cpp b/tools/analyse.cpp index 9eb3cbf..98a3140 100644 --- a/tools/analyse.cpp +++ b/tools/analyse.cpp @@ -56,27 +56,44 @@ static bool region_equal (emory::chunk::region const &a, emory::chunk::region co /////////////////////////////////////////////////////////////////////////////// enum { ARG_SELF, + + ARGS_INPUT, + ARGS_OUTPUT, + ARG_BITS, ARG_WINDOW, - ARGS_MINIMUM, - ARGS_INPUT, + ARG_MINIMUM, NUM_ARGS, + NUM_ARGS_REQUIRED = 3, }; +static constexpr std::size_t DEFAULT_BITS = 12; +static constexpr std::size_t DEFAULT_WINDOW = 4; +static constexpr std::ptrdiff_t DEFAULT_MINIMUM = 512; + + //----------------------------------------------------------------------------- int main (int argc, char const **argv) { - if (argc != NUM_ARGS) { - std::cerr << "usage: " << argv[ARG_SELF] << " \n"; + if (argc < NUM_ARGS_REQUIRED) { + std::cerr << "usage: " << argv[ARG_SELF] << " [bits] [window] [minimum]\n" + << "default bits = " << DEFAULT_BITS << '\n' + << "default window = " << DEFAULT_WINDOW << '\n' + << "default minimum = " << DEFAULT_MINIMUM << '\n'; return EXIT_FAILURE; } + #define PARSE_DEFAULT(NAME, TYPE) \ + argc > ARG_##NAME \ + ? cruft::parse::from_string (argv[ARG_##NAME]) \ + : DEFAULT_##NAME + emory::chunk::params const p { - .bits = cruft::parse::from_string (argv[ARG_BITS ]), - .window = cruft::parse::from_string (argv[ARG_WINDOW]), - .minimum = cruft::parse::from_string (argv[ARGS_MINIMUM]), + .bits = PARSE_DEFAULT (BITS, std::size_t), + .window = PARSE_DEFAULT (WINDOW, std::size_t), + .minimum = PARSE_DEFAULT (MINIMUM, std::ptrdiff_t), }; cruft::mapped_file data (argv[ARGS_INPUT]);