diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-09-27 05:47:24 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-09-27 05:47:24 +0000 |
commit | d01b06ff7c706a689c98548bc4d0e8a3eeb65539 (patch) | |
tree | 37fba19b46eda1fa396e4e5bb625d4f992969638 | |
parent | ad115bca3226ac574fe6cf1235d1f38d7d8a7de7 (diff) | |
download | ruby-d01b06ff7c706a689c98548bc4d0e8a3eeb65539.tar.gz |
ruby.c: abbreviated option name
* ruby.c (name_match_p): allow option argument names to be
abbreviated for each words.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51951 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ruby.c | 20 |
1 files changed, 19 insertions, 1 deletions
@@ -693,8 +693,26 @@ moreswitches(const char *s, struct cmdline_options *opt, int envopt) rb_str_resize(argstr, 0); } +static int +name_match_p(const char *name, const char *str, size_t len) +{ + if (len == 0) return 0; + do { + while (TOLOWER(*str) == *name) { + if (!--len || !*++str) return 1; + ++name; + } + if (*str != '-' && *str != '_') return 0; + while (ISALNUM(*name)) name++; + if (*name != '-' && *name != '_') return 0; + ++name; + ++str; + } while (len > 0); + return !*name; +} + #define NAME_MATCH_P(name, str, len) \ - ((len) < (int)sizeof(name) && strncmp((str), (name), (len)) == 0) + ((len) < (int)sizeof(name) && name_match_p((name), (str), (len))) #define UNSET_WHEN(name, bit, str, len) \ if (NAME_MATCH_P((name), (str), (len))) { \ |