main.cc \
messages.cc messages.hh \
misc.cc misc.hh \
- option.cc option.hh \
+ option.cc option.hh option.ii \
pri.cc pri.hh \
readctx.c readctx.h \
reloc.cc reloc.hh \
, _m_groups (c._m_groups)
, _m_prereq (c._m_prereq)
, _m_hidden (c._m_hidden)
+ , _m_opts (c._m_opts)
{}
bool
#include <iosfwd>
#include <vector>
-#include "option.ii"
+#include "option.hh"
struct checkgroups
: public std::set<std::string>
char const *const _m_name;
char const *_m_description;
bool _m_hidden;
- std::vector<option_i *> _m_opts;
+ options _m_opts;
public:
create (char const *name = NULL);
create option (option_i &opt)
{
- _m_opts.push_back (&opt);
+ _m_opts.add (&opt);
return *this;
}
};
bool hidden () const { return _m_hidden; }
+ options const &opts () const { return _m_opts; }
+
private:
char const *const _m_name;
char const *const _m_description;
checkgroups const _m_groups;
prereqs const _m_prereq;
bool _m_hidden;
+ options const _m_opts;
};
template <class T>
}
}
-void
-dwarflint::check_registrar::list_checks () const
+dwarflint::check_registrar::checkdescriptors_t
+dwarflint::check_registrar::get_descriptors () const
{
- bool be_verbose = opt_list_checks.value () == "full";
- typedef std::set<checkdescriptor const *> descset;
- descset descriptors;
+ std::set<checkdescriptor const *> descriptors;
for (std::vector <item *>::const_iterator it = _m_items.begin ();
it != _m_items.end (); ++it)
include (descriptors, (*it)->descriptor ());
+ return checkdescriptors_t (descriptors.begin (), descriptors.end ());
+}
+
+void
+dwarflint::check_registrar::list_checks () const
+{
+ bool be_verbose = opt_list_checks.value () == "full";
+ checkdescriptors_t descriptors = get_descriptors ();
- for (descset::const_iterator it = descriptors.begin ();
+ for (checkdescriptors_t::const_iterator it = descriptors.begin ();
it != descriptors.end (); ++it)
{
checkdescriptor const &cd = **it;
void list_checks () const;
+ typedef std::vector<checkdescriptor const *> checkdescriptors_t;
+ checkdescriptors_t get_descriptors () const;
+
private:
friend class dwarflint;
void enroll (dwarflint &lint);
textdomain (PACKAGE_TARNAME);
/* Parse and process arguments. */
- struct argp argp = global_opts.build_argp ();
+ argp_full args (global_opts,
+ dwarflint::check_registrar::inst ()->get_descriptors ());
+
+
int remaining;
- argp_parse (&argp, argc, argv, 0, &remaining, NULL);
+ argp_parse (&args.get (), argc, argv, 0, &remaining, NULL);
if (opt_list_checks.seen ())
{
else if (remaining == argc)
{
fputs (gettext ("Missing file name.\n"), stderr);
- argp_help (&argp, stderr, ARGP_HELP_SEE | ARGP_HELP_EXIT_ERR,
+ argp_help (&args.get (), stderr, ARGP_HELP_SEE | ARGP_HELP_EXIT_ERR,
program_invocation_short_name);
std::exit (1);
}
#endif
#include "option.hh"
+#include "dwarflint.hh"
+#include "checkdescriptor.hh"
#include <cassert>
#include <cstring>
#include <iostream>
const char *argp_program_bug_address = PACKAGE_BUGREPORT;
argp
-options::build_argp ()
+options::build_argp () const
{
_m_opts.clear ();
for (const_iterator it = begin (); it != end (); ++it)
return a;
}
+argp_full::argp_full (options const &global,
+ std::vector<checkdescriptor const *> checkdescriptors)
+{
+ argp main = global.build_argp ();
+
+ typedef dwarflint::check_registrar::checkdescriptors_t checkdescriptors_t;
+ for (checkdescriptors_t::const_iterator it = checkdescriptors.begin ();
+ it != checkdescriptors.end (); ++it)
+ if (!(*it)->opts ().empty ())
+ {
+ _m_children_argps.push_back ((*it)->opts ().build_argp ());
+ _m_children_headers.push_back (std::string ("Options for ")
+ + (*it)->name ()
+ + ":");
+ }
+
+ unsigned pos = 0;
+ for (checkdescriptors_t::const_iterator it = checkdescriptors.begin ();
+ it != checkdescriptors.end (); ++it)
+ if (!(*it)->opts ().empty ())
+ {
+ argp_child child = {&_m_children_argps[pos], 0,
+ _m_children_headers[pos].c_str (), 0};
+ _m_children.push_back (child);
+ pos++;
+ }
+ assert (_m_children_argps.size () == _m_children.size ());
+
+ if (!_m_children.empty ())
+ {
+ _m_children.push_back ((argp_child){NULL, 0, NULL, 0});
+ main.children = &_m_children.front ();
+ }
+
+ _m_argp = main;
+}
+
int option_i::_m_last_opt = 300;
#include <iostream>
#include "option.ii"
+#include "checkdescriptor.ii"
class options
: private std::map<int, option_i *>
{
friend class option_common;
- std::vector<argp_option> _m_opts;
+ mutable std::vector<argp_option> _m_opts;
option_i *find_opt (int key) const;
static error_t parse_opt (int key, char *arg, argp_state *state);
public:
option_i const *getopt (int key) const;
- argp build_argp ();
+ argp build_argp () const;
void add (option_i *opt);
+ bool empty () const
+ {
+ return std::map<int, option_i *>::empty ();
+ }
+};
+
+class argp_full
+{
+ std::vector<argp> _m_children_argps;
+ std::vector<std::string> _m_children_headers;
+ std::vector<argp_child> _m_children;
+ argp _m_argp;
+
+public:
+ argp_full (options const &global,
+ std::vector<checkdescriptor const *> checkdescriptors);
+ argp const &get () const { return _m_argp; }
};
class option_i // we cannot call it simply "option", this conflicts