diff options
author | John Wiegley <johnw@newartisans.com> | 2004-11-08 06:43:11 +0000 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2008-04-13 02:40:47 -0400 |
commit | c9fb11bd60a2170fb896d77ff8d7706f563ad597 (patch) | |
tree | 42bdf09e7d8727ba31d1d8dae9b4eb4b2a605441 /option.h | |
parent | fa2ceaed13c031add578ee8eb33da0c9980b9fb1 (diff) | |
download | fork-ledger-c9fb11bd60a2170fb896d77ff8d7706f563ad597.tar.gz fork-ledger-c9fb11bd60a2170fb896d77ff8d7706f563ad597.tar.bz2 fork-ledger-c9fb11bd60a2170fb896d77ff8d7706f563ad597.zip |
updated to version 2.0
Diffstat (limited to 'option.h')
-rw-r--r-- | option.h | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/option.h b/option.h new file mode 100644 index 00000000..2e4d7599 --- /dev/null +++ b/option.h @@ -0,0 +1,44 @@ +#ifndef _OPTION_H +#define _OPTION_H + +#include <list> +#include <string> +#include <exception> + +struct option_handler { + bool handled; + option_handler() : handled(false) {} + virtual void operator()(const char * arg = NULL) = 0; +}; + +struct option_t { + char short_opt; + std::string long_opt; + bool wants_arg; + option_handler * handler; + + option_t() : short_opt(0), wants_arg(false), handler(NULL) {} +}; + +class option_error : public std::exception { + std::string reason; + public: + option_error(const std::string& _reason) throw() : reason(_reason) {} + virtual ~option_error() throw() {} + + virtual const char* what() const throw() { + return reason.c_str(); + } +}; + +void add_option_handler(std::list<option_t>& options, const std::string& label, + const std::string& opt_chars, option_handler& option); +bool process_option(std::list<option_t>& options, + const std::string& opt, const char * arg = NULL); +void process_arguments(std::list<option_t>& options, + int argc, char ** argv, const bool anywhere, + std::list<std::string>& args); +void process_environment(std::list<option_t>& options, + char ** envp, const std::string& tag); + +#endif // _OPTION_H |