From: Colin Patrick McCabe Date: Thu, 31 Mar 2011 21:28:02 +0000 (-0700) Subject: ceph_argparse: convert dashes to underscores X-Git-Tag: v0.27~193 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=07ffd55c43f3439938c51d82d730424a295d8df2;p=ceph.git ceph_argparse: convert dashes to underscores Signed-off-by: Colin McCabe --- diff --git a/src/common/ceph_argparse.cc b/src/common/ceph_argparse.cc index 39ee867e80613..7e68ef2be390f 100644 --- a/src/common/ceph_argparse.cc +++ b/src/common/ceph_argparse.cc @@ -254,10 +254,34 @@ get_conf_files() const return ret; } +static void dashes_to_underscores(const char *input, char *output) +{ + char c = 0; + char *o = output; + const char *i = input; + // first two characters are copied as-is + *o++ = *i++; + if (*o == '\0') + return; + *o++ = *i++; + if (*o == '\0') + return; + for (; ((c = *i)); ++i) { + if (c == '-') + *o++ = '_'; + else + *o++ = c; + } + *o++ = '\0'; +} + bool ceph_argparse_flag(std::vector &args, std::vector::iterator &i, ...) { const char *first = *i; + char tmp[strlen(first)+1]; + dashes_to_underscores(first, tmp); + first = tmp; const char *a; va_list ap; @@ -277,6 +301,9 @@ bool ceph_argparse_witharg(std::vector &args, std::vector::iterator &i, std::string *ret, ...) { const char *first = *i; + char tmp[strlen(first)+1]; + dashes_to_underscores(first, tmp); + first = tmp; const char *a; va_list ap; int strlen_a;