Skip to content

Commit

Permalink
Make matches_option() in cf-check sources more reusable
Browse files Browse the repository at this point in the history
It's useful for all the cf-check commands that support options.
  • Loading branch information
vpodzime committed Oct 11, 2019
1 parent 697f84c commit ddf7b6c
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 25 deletions.
25 changes: 0 additions & 25 deletions cf-check/dump.c
Expand Up @@ -426,31 +426,6 @@ static int dump_dbs(Seq *const files, const dump_mode mode)
return ret;
}

static bool matches_option(
const char *const supplied,
const char *const longopt,
const char *const shortopt)
{
assert(supplied != NULL);
assert(shortopt != NULL);
assert(longopt != NULL);
assert(strlen(shortopt) == 2);
assert(strlen(longopt) >= 3);
assert(shortopt[0] == '-' && shortopt[1] != '-');
assert(longopt[0] == '-' && longopt[1] == '-' && longopt[2] != '-');

const size_t length = strlen(supplied);
if (length <= 1)
{
return false;
}
else if (length == 2)
{
return StringSafeEqual(supplied, shortopt);
}
return StringSafeEqualN_IgnoreCase(supplied, longopt, length);
}

int dump_main(int argc, const char *const *const argv)
{
assert(argv != NULL);
Expand Down
25 changes: 25 additions & 0 deletions cf-check/utilities.c
Expand Up @@ -32,3 +32,28 @@ Seq *argv_to_lmdb_files(

return SeqFromArgv(argc - offset, argv + offset);
}

bool matches_option(
const char *const supplied,
const char *const longopt,
const char *const shortopt)
{
assert(supplied != NULL);
assert(shortopt != NULL);
assert(longopt != NULL);
assert(strlen(shortopt) == 2);
assert(strlen(longopt) >= 3);
assert(shortopt[0] == '-' && shortopt[1] != '-');
assert(longopt[0] == '-' && longopt[1] == '-' && longopt[2] != '-');

const size_t length = strlen(supplied);
if (length <= 1)
{
return false;
}
else if (length == 2)
{
return StringSafeEqual(supplied, shortopt);
}
return StringSafeEqualN_IgnoreCase(supplied, longopt, length);
}
4 changes: 4 additions & 0 deletions cf-check/utilities.h
Expand Up @@ -10,5 +10,9 @@ Seq *argv_to_seq(int argc, const char *const *argv);
Seq *default_lmdb_files();

Seq *argv_to_lmdb_files(int count, const char *const *files, size_t offset);
bool matches_option(
const char *const supplied,
const char *const longopt,
const char *const shortopt);

#endif

0 comments on commit ddf7b6c

Please sign in to comment.