diff options
author | Brad King <brad.king@kitware.com> | 2002-12-04 23:44:39 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2002-12-04 23:44:39 (GMT) |
commit | d66aa2262ab04f695aa4f9869cd7ffa4450b3ac3 (patch) | |
tree | 2c9fcb04b0b94f8b337fd30465411cdf5cb6c684 /Source/cmStringCommand.cxx | |
parent | 9992fe5103d8d55d65e2dc0ae3ce9458a47832c7 (diff) | |
download | CMake-d66aa2262ab04f695aa4f9869cd7ffa4450b3ac3.zip CMake-d66aa2262ab04f695aa4f9869cd7ffa4450b3ac3.tar.gz CMake-d66aa2262ab04f695aa4f9869cd7ffa4450b3ac3.tar.bz2 |
ENH: Added COMPARE modes to STRING command.
Diffstat (limited to 'Source/cmStringCommand.cxx')
-rw-r--r-- | Source/cmStringCommand.cxx | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/Source/cmStringCommand.cxx b/Source/cmStringCommand.cxx index 8278a85..f6e473a 100644 --- a/Source/cmStringCommand.cxx +++ b/Source/cmStringCommand.cxx @@ -30,6 +30,10 @@ bool cmStringCommand::InitialPass(std::vector<std::string> const& args) { return this->HandleRegexCommand(args); } + else if(subCommand == "COMPARE") + { + return this->HandleCompareCommand(args); + } std::string e = "does not recognize sub-command "+subCommand; this->SetError(e.c_str()); @@ -307,3 +311,59 @@ bool cmStringCommand::RegexReplace(std::vector<std::string> const& args) m_Makefile->AddDefinition(outvar.c_str(), output.c_str()); return true; } + +//---------------------------------------------------------------------------- +bool cmStringCommand::HandleCompareCommand(std::vector<std::string> const& args) +{ + if(args.size() < 2) + { + this->SetError("sub-command COMPARE requires a mode to be specified."); + return false; + } + std::string mode = args[1]; + if((mode == "EQUAL") || (mode == "NOTEQUAL") || + (mode == "LESS") || (mode == "GREATER")) + { + if(args.size() < 5) + { + std::string e = "sub-command COMPARE, mode "; + e += mode; + e += " needs at least 5 arguments total to command."; + this->SetError(e.c_str()); + return false; + } + + const std::string& left = args[2]; + const std::string& right = args[3]; + const std::string& outvar = args[4]; + bool result; + if(mode == "LESS") + { + result = (left < right); + } + else if(mode == "GREATER") + { + result = (left > right); + } + else if(mode == "EQUAL") + { + result = (left == right); + } + else // if(mode == "NOTEQUAL") + { + result = !(left == right); + } + if(result) + { + m_Makefile->AddDefinition(outvar.c_str(), "1"); + } + else + { + m_Makefile->AddDefinition(outvar.c_str(), "0"); + } + return true; + } + std::string e = "sub-command COMPARE does not recognize mode "+mode; + this->SetError(e.c_str()); + return false; +} |