1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

ruby.c: feature_option

* ruby.c (feature_option): unify enable_option and disable_option
  not to repeat feature names twice.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52669 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2015-11-19 08:56:12 +00:00
parent 95273072a7
commit c1da4ef8d1

41
ruby.c
View file

@ -745,35 +745,36 @@ name_match_p(const char *name, const char *str, size_t len)
}
static void
enable_option(const char *str, int len, void *arg)
feature_option(const char *str, int len, void *arg, const unsigned int enable)
{
#define SET_WHEN_ENABLE(bit) SET_WHEN(#bit, FEATURE_BIT(bit), str, len)
SET_WHEN_ENABLE(gems);
SET_WHEN_ENABLE(did_you_mean);
SET_WHEN_ENABLE(rubyopt);
SET_WHEN_ENABLE(frozen_string_literal);
SET_WHEN_ENABLE(frozen_string_literal_debug);
unsigned int *argp = arg;
unsigned int mask = ~0U;
#define SET_FEATURE(bit) \
if (NAME_MATCH_P(#bit, str, len)) {mask = FEATURE_BIT(bit); goto found;}
SET_FEATURE(gems);
SET_FEATURE(did_you_mean);
SET_FEATURE(rubyopt);
SET_FEATURE(frozen_string_literal);
SET_FEATURE(frozen_string_literal_debug);
if (NAME_MATCH_P("all", str, len)) {
*(unsigned int *)arg = ~0U;
found:
*argp = (*argp & ~mask) | (mask & enable);
return;
}
rb_warn("unknown argument for --enable: `%.*s'", len, str);
rb_warn("unknown argument for --%s: `%.*s'",
enable ? "enable" : "disable", len, str);
}
static void
enable_option(const char *str, int len, void *arg)
{
feature_option(str, len, arg, ~0U);
}
static void
disable_option(const char *str, int len, void *arg)
{
#define UNSET_WHEN_DISABLE(bit) UNSET_WHEN(#bit, FEATURE_BIT(bit), str, len)
UNSET_WHEN_DISABLE(gems);
UNSET_WHEN_DISABLE(did_you_mean);
UNSET_WHEN_DISABLE(rubyopt);
UNSET_WHEN_DISABLE(frozen_string_literal);
UNSET_WHEN_DISABLE(frozen_string_literal_debug);
if (NAME_MATCH_P("all", str, len)) {
*(unsigned int *)arg = 0U;
return;
}
rb_warn("unknown argument for --disable: `%.*s'", len, str);
feature_option(str, len, arg, 0U);
}
static void