summaryrefslogtreecommitdiffstats
path: root/dwarflint/option.cc
diff options
context:
space:
mode:
authorPetr Machata <[email protected]>2010-09-23 18:00:36 +0200
committerPetr Machata <[email protected]>2010-09-23 18:00:36 +0200
commit75c18f5e549e400cafca2b9137c83f7c6460cf02 (patch)
tree0b36c7f0b49484a061de7d4b614bfae70c2fc9fb /dwarflint/option.cc
parent56df0cc20114ed6042de2838e22f21bcbd5c1c33 (diff)
dwarflint: Don't assume all options are global
- currently this breaks dwarflint, because per-check options are not yet processed. Options that belonged to global group before still work and are correctly registered as globals, but e.g. -i or the suite of options at locstats aren't recognized.
Diffstat (limited to 'dwarflint/option.cc')
-rw-r--r--dwarflint/option.cc39
1 files changed, 20 insertions, 19 deletions
diff --git a/dwarflint/option.cc b/dwarflint/option.cc
index 6fadf9ab..8a127efa 100644
--- a/dwarflint/option.cc
+++ b/dwarflint/option.cc
@@ -32,8 +32,8 @@
#include <cstring>
#include <iostream>
-option_common *
-options::opt (int key) const
+option_i *
+options::find_opt (int key) const
{
const_iterator it = find (key);
if (it == end ())
@@ -41,17 +41,17 @@ options::opt (int key) const
return it->second;
}
-option_common const *
+option_i const *
options::getopt (int key) const
{
- return opt (key);
+ return find_opt (key);
}
error_t
options::parse_opt (int key, char *arg,
__attribute__ ((unused)) argp_state *state)
{
- option_common *o = registered ().opt (key);
+ option_i *o = global_opts.find_opt (key); // XXX temporary
if (o == NULL)
return ARGP_ERR_UNKNOWN;
return o->parse_opt (arg, state);
@@ -60,11 +60,20 @@ options::parse_opt (int key, char *arg,
struct last_option
: public argp_option
{
- last_option () {
+ last_option ()
+ {
std::memset (this, 0, sizeof (*this));
}
};
+void
+options::add (option_i *opt)
+{
+ int key = opt->key ();
+ assert (getopt (key) == NULL);
+ (*this)[key] = opt;
+}
+
/* Bug report address. */
const char *argp_program_bug_address = PACKAGE_BUGREPORT;
@@ -87,17 +96,10 @@ Pedantic checking of DWARF stored in ELF files.",
}
-int option_common::_m_last_opt = 300;
-
-options &
-options::registered ()
-{
- static options opts;
- return opts;
-}
+int option_i::_m_last_opt = 300;
int
-option_common::get_short_option (char opt_short)
+option_i::get_short_option (char opt_short)
{
if (opt_short)
return opt_short;
@@ -127,7 +129,6 @@ option_common::option_common (char const *description,
arg_description, flags,
description, 0))
, _m_seen (false)
-{
- assert (options::registered ().getopt (_m_opt.key) == NULL);
- options::registered ()[_m_opt.key] = this;
-}
+{}
+
+options global_opts;