From 82c16d84de8461c3e0255d4d9646707682b79656 Mon Sep 17 00:00:00 2001 From: Christian Linke Date: Tue, 28 Apr 2015 18:27:28 +0200 Subject: * make commandline argument parsing a little nicer. * added preparse method * removed debug message * added deamonize function again Signed-off-by: Christian Linke --- tclap-1.2.1/include/tclap/CmdLine.h | 57 +++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) (limited to 'tclap-1.2.1/include') 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 @@ -241,6 +241,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& 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. @@ -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 args; + for (int i = 0; i < argc; i++) + args.push_back(argv[i]); + + preparse(args); +} + +inline void CmdLine::preparse(std::vector& args) +{ + bool shouldExit = false; + int estat = 0; + + try { + + _progName = args.front(); + args.erase(args.begin()); + + int requiredCount = 0; + + for (int i = 0; static_cast(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& args) { bool shouldExit = false; -- cgit v1.2.1