summaryrefslogtreecommitdiffstats
path: root/dwarflint
diff options
context:
space:
mode:
authorPetr Machata <[email protected]>2010-09-24 18:41:40 +0200
committerPetr Machata <[email protected]>2010-09-24 18:41:40 +0200
commite966f19d486f4874faced1baac15307e61010b4b (patch)
tree790f8043ab41742b2e06bf9a98ad9e8430aea08d /dwarflint
parent2e8236968ede6077d4d75782bd02c6c470c3f6b9 (diff)
dwarflint: --list-checks now lists options associated with check passes
Diffstat (limited to 'dwarflint')
-rw-r--r--dwarflint/dwarflint.cc10
-rw-r--r--dwarflint/option.cc41
-rw-r--r--dwarflint/option.hh11
3 files changed, 58 insertions, 4 deletions
diff --git a/dwarflint/dwarflint.cc b/dwarflint/dwarflint.cc
index 2a56a370..6d01f7e0 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 99277270..5312a724 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 6bde308c..15a9bf46 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<int, option_i *>::empty ();
- }
+ using std::map<int, option_i *>::empty;
+ using std::map<int, option_i *>::begin;
+ using std::map<int, option_i *>::end;
+ using std::map<int, option_i *>::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<class arg_type>