analyse: provide defaults for bits, window, and minimum

This commit is contained in:
Danny Robson 2020-12-06 08:42:01 +10:00
parent 255beaefa5
commit 7558c08e7d

View File

@ -56,27 +56,44 @@ static bool region_equal (emory::chunk::region const &a, emory::chunk::region co
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
enum { enum {
ARG_SELF, ARG_SELF,
ARGS_INPUT,
ARGS_OUTPUT,
ARG_BITS, ARG_BITS,
ARG_WINDOW, ARG_WINDOW,
ARGS_MINIMUM, ARG_MINIMUM,
ARGS_INPUT,
NUM_ARGS, 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) int main (int argc, char const **argv)
{ {
if (argc != NUM_ARGS) { if (argc < NUM_ARGS_REQUIRED) {
std::cerr << "usage: " << argv[ARG_SELF] << " <bits> <window> <minimum> <input>\n"; std::cerr << "usage: " << argv[ARG_SELF] << " <input> <output> [bits] [window] [minimum]\n"
<< "default bits = " << DEFAULT_BITS << '\n'
<< "default window = " << DEFAULT_WINDOW << '\n'
<< "default minimum = " << DEFAULT_MINIMUM << '\n';
return EXIT_FAILURE; return EXIT_FAILURE;
} }
#define PARSE_DEFAULT(NAME, TYPE) \
argc > ARG_##NAME \
? cruft::parse::from_string<TYPE> (argv[ARG_##NAME]) \
: DEFAULT_##NAME
emory::chunk::params const p { emory::chunk::params const p {
.bits = cruft::parse::from_string<std::size_t> (argv[ARG_BITS ]), .bits = PARSE_DEFAULT (BITS, std::size_t),
.window = cruft::parse::from_string<std::size_t> (argv[ARG_WINDOW]), .window = PARSE_DEFAULT (WINDOW, std::size_t),
.minimum = cruft::parse::from_string<std::ptrdiff_t> (argv[ARGS_MINIMUM]), .minimum = PARSE_DEFAULT (MINIMUM, std::ptrdiff_t),
}; };
cruft::mapped_file data (argv[ARGS_INPUT]); cruft::mapped_file data (argv[ARGS_INPUT]);