diff options
author | Andy Cedilnik <andy.cedilnik@kitware.com> | 2006-07-14 19:02:27 (GMT) |
---|---|---|
committer | Andy Cedilnik <andy.cedilnik@kitware.com> | 2006-07-14 19:02:27 (GMT) |
commit | 9bc53f64434e807b5fdb9103995f82eddd16d6d7 (patch) | |
tree | 9895540ec0442e0502e69a3b919ed3666abedf9f /Source/kwsys/CommandLineArguments.cxx | |
parent | 71395c78cee2abe5cdfb7b27bb3a4f2610c87653 (diff) | |
download | CMake-9bc53f64434e807b5fdb9103995f82eddd16d6d7.zip CMake-9bc53f64434e807b5fdb9103995f82eddd16d6d7.tar.gz CMake-9bc53f64434e807b5fdb9103995f82eddd16d6d7.tar.bz2 |
ENH: Add a way to get unused arguments and add a test
Diffstat (limited to 'Source/kwsys/CommandLineArguments.cxx')
-rw-r--r-- | Source/kwsys/CommandLineArguments.cxx | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/Source/kwsys/CommandLineArguments.cxx b/Source/kwsys/CommandLineArguments.cxx index 36892ee..20fb3ef 100644 --- a/Source/kwsys/CommandLineArguments.cxx +++ b/Source/kwsys/CommandLineArguments.cxx @@ -99,6 +99,8 @@ public: void* ClientData; VectorOfStrings::size_type LastArgument; + + VectorOfStrings UnusedArguments; }; //============================================================================ //---------------------------------------------------------------------------- @@ -109,6 +111,7 @@ CommandLineArguments::CommandLineArguments() this->Internals = new CommandLineArguments::Internal; this->Help = ""; this->LineLength = 80; + this->StoreUnusedArgumentsFlag = false; } //---------------------------------------------------------------------------- @@ -185,6 +188,10 @@ int CommandLineArguments::Parse() { kwsys_stl::vector<kwsys_stl::string>::size_type cc; kwsys_stl::vector<kwsys_stl::string> matches; + if ( this->StoreUnusedArgumentsFlag ) + { + this->Internals->UnusedArguments.clear(); + } for ( cc = 0; cc < this->Internals->Argv.size(); cc ++ ) { const kwsys_stl::string& arg = this->Internals->Argv[cc]; @@ -281,6 +288,7 @@ int CommandLineArguments::Parse() cc--; continue; } + break; default: kwsys_ios::cerr << "Got unknown argument type: \"" << cs->ArgumentType << "\"" << kwsys_ios::endl; this->Internals->LastArgument --; @@ -300,6 +308,11 @@ int CommandLineArguments::Parse() } return 1; } + else if ( this->StoreUnusedArgumentsFlag ) + { + CommandLineArguments_DEBUG("Store unused argument " << arg); + this->Internals->UnusedArguments.push_back(arg.c_str()); + } else { kwsys_ios::cerr << "Got unknown argument: \"" << arg.c_str() << "\"" << kwsys_ios::endl; @@ -337,6 +350,32 @@ void CommandLineArguments::GetRemainingArguments(int* argc, char*** argv) } //---------------------------------------------------------------------------- +void CommandLineArguments::GetUnusedArguments(int* argc, char*** argv) +{ + CommandLineArguments::Internal::VectorOfStrings::size_type size + = this->Internals->UnusedArguments.size() + 1; + CommandLineArguments::Internal::VectorOfStrings::size_type cc; + + // Copy Argv0 as the first argument + char** args = new char*[ size ]; + args[0] = new char[ this->Internals->Argv0.size() + 1 ]; + strcpy(args[0], this->Internals->Argv0.c_str()); + int cnt = 1; + + // Copy everything after the LastArgument, since that was not parsed. + for ( cc = 0; + cc < this->Internals->UnusedArguments.size(); cc ++ ) + { + kwsys::String &str = this->Internals->UnusedArguments[cc]; + args[cnt] = new char[ str.size() + 1]; + strcpy(args[cnt], str.c_str()); + cnt ++; + } + *argc = cnt; + *argv = args; +} + +//---------------------------------------------------------------------------- void CommandLineArguments::DeleteRemainingArguments(int argc, char*** argv) { int cc; @@ -769,6 +808,7 @@ bool CommandLineArguments::PopulateVariable(CommandLineArgumentsCallbackStructur return 0; } } + CommandLineArguments_DEBUG("Set argument: " << cs->Argument << " to " << value); if ( cs->Variable ) { kwsys_stl::string var = "1"; |