From c9eaf72567b13cd587e9d5d1d1b0ad17e43a274f Mon Sep 17 00:00:00 2001 From: Andy Cedilnik Date: Tue, 22 Aug 2006 10:16:46 -0400 Subject: [PATCH] BUG: Add missing API --- Source/cmListCommand.cxx | 78 ++++++++++++++++++++++++++++++++++++++++ Source/cmListCommand.h | 2 ++ 2 files changed, 80 insertions(+) diff --git a/Source/cmListCommand.cxx b/Source/cmListCommand.cxx index bc43ecbfe..017b703f2 100644 --- a/Source/cmListCommand.cxx +++ b/Source/cmListCommand.cxx @@ -54,6 +54,14 @@ bool cmListCommand::InitialPass(std::vector const& args) { return this->HandleRemoveItemCommand(args); } + if(subCommand == "SORT") + { + return this->HandleSortCommand(args); + } + if(subCommand == "REVERSE") + { + return this->HandleReverseCommand(args); + } std::string e = "does not recognize sub-command "+subCommand; this->SetError(e.c_str()); @@ -302,6 +310,76 @@ bool cmListCommand return true; } +//---------------------------------------------------------------------------- +bool cmListCommand +::HandleReverseCommand(std::vector const& args) +{ + if(args.size() < 2) + { + this->SetError("sub-command REVERSE requires a list as an argument."); + return false; + } + + const std::string& listName = args[1]; + // expand the variable + std::vector varArgsExpanded; + if ( !this->GetList(varArgsExpanded, listName.c_str()) ) + { + this->SetError("sub-command REVERSE requires list to be present."); + return false; + } + + std::string value; + std::vector::reverse_iterator it; + for ( it = varArgsExpanded.rbegin(); it != varArgsExpanded.rend(); ++ it ) + { + if (value.size()) + { + value += ";"; + } + value += it->c_str(); + } + + this->Makefile->AddDefinition(listName.c_str(), value.c_str()); + return true; +} + +//---------------------------------------------------------------------------- +bool cmListCommand +::HandleSortCommand(std::vector const& args) +{ + if(args.size() < 2) + { + this->SetError("sub-command SORT requires a list as an argument."); + return false; + } + + const std::string& listName = args[1]; + // expand the variable + std::vector varArgsExpanded; + if ( !this->GetList(varArgsExpanded, listName.c_str()) ) + { + this->SetError("sub-command SORT requires list to be present."); + return false; + } + + std::sort(varArgsExpanded.begin(), varArgsExpanded.end()); + + std::string value; + std::vector::iterator it; + for ( it = varArgsExpanded.begin(); it != varArgsExpanded.end(); ++ it ) + { + if (value.size()) + { + value += ";"; + } + value += it->c_str(); + } + + this->Makefile->AddDefinition(listName.c_str(), value.c_str()); + return true; +} + //---------------------------------------------------------------------------- bool cmListCommand::HandleRemoveAtCommand( std::vector const& args) diff --git a/Source/cmListCommand.h b/Source/cmListCommand.h index 2989a63a9..486ff8d99 100644 --- a/Source/cmListCommand.h +++ b/Source/cmListCommand.h @@ -93,6 +93,8 @@ protected: bool HandleInsertCommand(std::vector const& args); bool HandleRemoveAtCommand(std::vector const& args); bool HandleRemoveItemCommand(std::vector const& args); + bool HandleSortCommand(std::vector const& args); + bool HandleReverseCommand(std::vector const& args); bool GetList(std::vector& list, const char* var);