diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-11-19 08:56:12 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-11-19 08:56:12 +0000 |
commit | fccb7c52842298dc51471c806c6d363ca062002b (patch) | |
tree | d524b139aa622df3081b184f2516e1829fe06bba | |
parent | 9987a2d66c52742037ae41154a97151771ddf6a0 (diff) | |
download | ruby-fccb7c52842298dc51471c806c6d363ca062002b.tar.gz |
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
-rw-r--r-- | ruby.c | 41 |
1 files changed, 21 insertions, 20 deletions
@@ -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 |