[Cmake-commits] [cmake-commits] king committed cmSeparateArgumentsCommand.cxx 1.6 1.7 cmSeparateArgumentsCommand.h 1.9 1.10
cmake-commits at cmake.org
cmake-commits at cmake.org
Tue Jul 14 10:15:47 EDT 2009
Update of /cvsroot/CMake/CMake/Source
In directory public:/mounts/ram/cvs-serv10164/Source
Modified Files:
cmSeparateArgumentsCommand.cxx cmSeparateArgumentsCommand.h
Log Message:
ENH: Teach separate_arguments() to parse commands
This adds UNIX_COMMAND and WINDOWS_COMMAND modes to the command.
These modes parse unix- and windows-style command lines.
Index: cmSeparateArgumentsCommand.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmSeparateArgumentsCommand.h,v
retrieving revision 1.9
retrieving revision 1.10
diff -C 2 -d -r1.9 -r1.10
*** cmSeparateArgumentsCommand.h 23 Jan 2008 15:27:59 -0000 1.9
--- cmSeparateArgumentsCommand.h 14 Jul 2009 14:15:44 -0000 1.10
***************
*** 59,63 ****
{
return
! "Split space separated arguments into a semi-colon separated list.";
}
--- 59,63 ----
{
return
! "Parse space-separated arguments into a semicolon-separated list.";
}
***************
*** 68,71 ****
--- 68,87 ----
{
return
+ " separate_arguments(<var> <UNIX|WINDOWS>_COMMAND \"<args>\")\n"
+ "Parses a unix- or windows-style command-line string \"<args>\" and "
+ "stores a semicolon-separated list of the arguments in <var>. "
+ "The entire command line must be given in one \"<args>\" argument."
+ "\n"
+ "The UNIX_COMMAND mode separates arguments by unquoted whitespace. "
+ "It recognizes both single-quote and double-quote pairs. "
+ "A backslash escapes the next literal character (\\\" is \"); "
+ "there are no special escapes (\\n is just n)."
+ "\n"
+ "The WINDOWS_COMMAND mode parses a windows command-line using the "
+ "same syntax the runtime library uses to construct argv at startup. "
+ "It separates arguments by whitespace that is not double-quoted. "
+ "Backslashes are literal unless they precede double-quotes. "
+ "See the MSDN article \"Parsing C Command-Line Arguments\" for details."
+ "\n"
" separate_arguments(VARIABLE)\n"
"Convert the value of VARIABLE to a semi-colon separated list. "
Index: cmSeparateArgumentsCommand.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmSeparateArgumentsCommand.cxx,v
retrieving revision 1.6
retrieving revision 1.7
diff -C 2 -d -r1.6 -r1.7
*** cmSeparateArgumentsCommand.cxx 23 Jan 2008 15:27:59 -0000 1.6
--- cmSeparateArgumentsCommand.cxx 14 Jul 2009 14:15:43 -0000 1.7
***************
*** 21,38 ****
::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
{
! if(args.size() != 1 )
{
! this->SetError("called with incorrect number of arguments");
return false;
}
! const char* cacheValue = this->Makefile->GetDefinition(args[0].c_str());
! if(!cacheValue)
{
! return true;
}
! std::string value = cacheValue;
! cmSystemTools::ReplaceString(value," ", ";");
! this->Makefile->AddDefinition(args[0].c_str(), value.c_str());
return true;
}
-
--- 21,114 ----
::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
{
! if(args.empty())
{
! this->SetError("must be given at least one argument.");
return false;
}
!
! std::string var;
! std::string command;
! enum Mode { ModeOld, ModeUnix, ModeWindows };
! Mode mode = ModeOld;
! enum Doing { DoingNone, DoingVariable, DoingMode, DoingCommand };
! Doing doing = DoingVariable;
! for(unsigned int i=0; i < args.size(); ++i)
{
! if(doing == DoingVariable)
! {
! var = args[i];
! doing = DoingMode;
! }
! else if(doing == DoingMode && args[i] == "UNIX_COMMAND")
! {
! mode = ModeUnix;
! doing = DoingCommand;
! }
! else if(doing == DoingMode && args[i] == "WINDOWS_COMMAND")
! {
! mode = ModeWindows;
! doing = DoingCommand;
! }
! else if(doing == DoingCommand)
! {
! command = args[i];
! doing = DoingNone;
! }
! else
! {
! cmOStringStream e;
! e << "given unknown argument " << args[i];
! this->SetError(e.str().c_str());
! return false;
! }
}
!
! if(mode == ModeOld)
! {
! // Original space-replacement version of command.
! if(const char* def = this->Makefile->GetDefinition(var.c_str()))
! {
! std::string value = def;
! cmSystemTools::ReplaceString(value, " ", ";");
! this->Makefile->AddDefinition(var.c_str(), value.c_str());
! }
! }
! else
! {
! // Parse the command line.
! std::vector<std::string> vec;
! if(mode == ModeUnix)
! {
! cmSystemTools::ParseUnixCommandLine(command.c_str(), vec);
! }
! else // if(mode == ModeWindows)
! {
! cmSystemTools::ParseWindowsCommandLine(command.c_str(), vec);
! }
!
! // Construct the result list value.
! std::string value;
! const char* sep = "";
! for(std::vector<std::string>::const_iterator vi = vec.begin();
! vi != vec.end(); ++vi)
! {
! // Separate from the previous argument.
! value += sep;
! sep = ";";
!
! // Preserve semicolons.
! for(std::string::const_iterator si = vi->begin();
! si != vi->end(); ++si)
! {
! if(*si == ';')
! {
! value += '\\';
! }
! value += *si;
! }
! }
! this->Makefile->AddDefinition(var.c_str(), value.c_str());
! }
!
return true;
}
More information about the Cmake-commits
mailing list