diff options
author | Christian Linke <christian.linke@bmw.de> | 2015-04-28 18:27:28 +0200 |
---|---|---|
committer | Christian Linke <christian.linke@bmw.de> | 2015-04-28 18:27:28 +0200 |
commit | 82c16d84de8461c3e0255d4d9646707682b79656 (patch) | |
tree | adea48bc1220d1d5cabf58b0cfef92cb1c2dcae1 /tclap-1.2.1 | |
parent | 919cb14349cd5b6e86645d1e56483118589e4e9b (diff) | |
download | audiomanager-82c16d84de8461c3e0255d4d9646707682b79656.tar.gz |
* make commandline argument parsing a little nicer.
* added preparse method
* removed debug message
* added deamonize function again
Signed-off-by: Christian Linke <christian.linke@bmw.de>
Diffstat (limited to 'tclap-1.2.1')
-rw-r--r-- | tclap-1.2.1/include/tclap/CmdLine.h | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/tclap-1.2.1/include/tclap/CmdLine.h b/tclap-1.2.1/include/tclap/CmdLine.h index 0fec8d8..e8d7da1 100644 --- a/tclap-1.2.1/include/tclap/CmdLine.h +++ b/tclap-1.2.1/include/tclap/CmdLine.h @@ -242,6 +242,20 @@ private: void parse(int argc, const char * const * argv); /** + * Parses the command line but does not process help. + * \param args - A vector of strings representing the args. + * args[0] is still the program name. + */ + void preparse(std::vector<std::string>& args); + + /** + * Parses the command line but does not process help. + * \param argc - Number of arguments. + * \param argv - Array of arguments. + */ + void preparse(int argc, const char * const * argv); + + /** * Parses the command line. * \param args - A vector of strings representing the args. * args[0] is still the program name. @@ -441,6 +455,49 @@ inline void CmdLine::parse(int argc, const char * const * argv) parse(args); } +inline void CmdLine::preparse(int argc, const char * const * argv) +{ + // this step is necessary so that we have easy access to + // mutable strings. + std::vector<std::string> args; + for (int i = 0; i < argc; i++) + args.push_back(argv[i]); + + preparse(args); +} + +inline void CmdLine::preparse(std::vector<std::string>& args) +{ + bool shouldExit = false; + int estat = 0; + + try { + + _progName = args.front(); + args.erase(args.begin()); + + int requiredCount = 0; + + for (int i = 0; static_cast<unsigned int>(i) < args.size(); i++) + { + bool matched = false; + for (ArgListIterator it = _argList.begin(); + it != _argList.end(); it++) { + if ( (*it)->processArg( &i, args ) ) + { + requiredCount += _xorHandler.check( *it ); + matched = true; + break; + } + } + } + } catch ( ArgException& e ) { + try { + _output->failure(*this,e); + } catch ( ExitException &ee ) {} + } catch (ExitException &ee) {} +} + inline void CmdLine::parse(std::vector<std::string>& args) { bool shouldExit = false; |