From: Petr Machata Date: Fri, 24 Sep 2010 16:41:40 +0000 (+0200) Subject: dwarflint: --list-checks now lists options associated with check passes X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=e966f19d486f4874faced1baac15307e61010b4b;p=thirdparty%2Felfutils.git dwarflint: --list-checks now lists options associated with check passes --- diff --git a/dwarflint/dwarflint.cc b/dwarflint/dwarflint.cc index 2a56a3704..6d01f7e02 100644 --- a/dwarflint/dwarflint.cc +++ b/dwarflint/dwarflint.cc @@ -163,6 +163,16 @@ dwarflint::check_registrar::list_checks () const char const *desc = cd.description (); if (desc != NULL) std::cout << desc; + + options const &opts = cd.opts (); + if (!opts.empty ()) + { + std::cout << "recognized options:" << std::endl; + for (options::const_iterator ot = opts.begin (); + ot != opts.end (); ++ot) + std::cout << " " << ot->second->format () << std::endl; + } + std::cout << std::endl; } } diff --git a/dwarflint/option.cc b/dwarflint/option.cc index 99277270e..5312a7248 100644 --- a/dwarflint/option.cc +++ b/dwarflint/option.cc @@ -209,4 +209,45 @@ option_common::option_common (char const *description, , _m_seen (false) {} +std::string +option_common::format () const +{ + std::string ret; + bool has_short = _m_opt.key < 127; + if (has_short) + { + char buf[3] = {}; + std::sprintf (buf, "-%c", _m_opt.key); + std::string xxx (buf); + ret += buf; + } + + if (_m_opt.name != NULL) + { + if (has_short) + ret += ", "; + ret += "--"; + ret += _m_opt.name; + } + + if (_m_opt.arg != NULL) + { + bool optional = !!(_m_opt.flags & OPTION_ARG_OPTIONAL); + if (optional) + ret += '['; + ret += '='; + ret += _m_opt.arg; + if (optional) + ret += ']'; + } + + if (_m_opt.doc != NULL) + { + ret += "\t"; + ret += _m_opt.doc; + } + + return ret; +} + options global_opts; diff --git a/dwarflint/option.hh b/dwarflint/option.hh index 6bde308c3..15a9bf463 100644 --- a/dwarflint/option.hh +++ b/dwarflint/option.hh @@ -48,10 +48,10 @@ public: option_i const *getopt (int key) const; argp build_argp (bool toplev = false) const; void add (option_i *opt); - bool empty () const - { - return std::map::empty (); - } + using std::map::empty; + using std::map::begin; + using std::map::end; + using std::map::const_iterator; }; // Wrapper of argp parsing. While in general argp does a decent job, @@ -97,6 +97,7 @@ public: virtual argp_option const &build_option () const = 0; virtual error_t parse_opt (char *arg, argp_state *state) = 0; virtual int key () const = 0; + virtual std::string format () const = 0; virtual ~option_i () {} }; @@ -131,6 +132,8 @@ public: { return _m_opt.key; } + + std::string format () const; }; template