summaryrefslogtreecommitdiffstats
path: root/Source/cmMathCommand.cxx
diff options
context:
space:
mode:
authorAndy Cedilnik <andy.cedilnik@kitware.com>2005-10-17 20:42:47 (GMT)
committerAndy Cedilnik <andy.cedilnik@kitware.com>2005-10-17 20:42:47 (GMT)
commit985d092d4d9f6d38c794755c3c64405ef7ec8d35 (patch)
tree382b35ed4376ba936acb4f160dd4fc5b76173dc6 /Source/cmMathCommand.cxx
parent427ed70363ad4aea83e071f46d9704f69472017d (diff)
downloadCMake-985d092d4d9f6d38c794755c3c64405ef7ec8d35.zip
CMake-985d092d4d9f6d38c794755c3c64405ef7ec8d35.tar.gz
CMake-985d092d4d9f6d38c794755c3c64405ef7ec8d35.tar.bz2
ENH: Add rudamentary mathematical expression support
Diffstat (limited to 'Source/cmMathCommand.cxx')
-rw-r--r--Source/cmMathCommand.cxx65
1 files changed, 65 insertions, 0 deletions
diff --git a/Source/cmMathCommand.cxx b/Source/cmMathCommand.cxx
new file mode 100644
index 0000000..bbb3edc
--- /dev/null
+++ b/Source/cmMathCommand.cxx
@@ -0,0 +1,65 @@
+/*=========================================================================
+
+ Program: CMake - Cross-Platform Makefile Generator
+ Module: $RCSfile$
+ Language: C++
+ Date: $Date$
+ Version: $Revision$
+
+ Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
+ See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
+
+ This software is distributed WITHOUT ANY WARRANTY; without even
+ the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ PURPOSE. See the above copyright notices for more information.
+
+=========================================================================*/
+#include "cmMathCommand.h"
+
+#include "cmExprParserHelper.h"
+
+//----------------------------------------------------------------------------
+bool cmMathCommand::InitialPass(std::vector<std::string> const& args)
+{
+ if ( args.size() < 1 )
+ {
+ this->SetError("must be called with at least one argument.");
+ return false;
+ }
+ const std::string &subCommand = args[0];
+ if(subCommand == "EXPR")
+ {
+ return this->HandleExprCommand(args);
+ }
+ std::string e = "does not recognize sub-command "+subCommand;
+ this->SetError(e.c_str());
+ return false;
+}
+
+//----------------------------------------------------------------------------
+bool cmMathCommand::HandleExprCommand(std::vector<std::string> const& args)
+{
+ if ( args.size() != 3 )
+ {
+ this->SetError("EXPR called with incorrect arguments.");
+ return false;
+ }
+
+ const std::string& outputVariable = args[1];
+ const std::string& expression = args[2];
+
+ cmExprParserHelper helper;
+ if ( !helper.ParseString(expression.c_str(), 0) )
+ {
+ std::string e = "cannot parse the expression: \""+expression+"\": ";
+ e += helper.GetError();
+ this->SetError(e.c_str());
+ return false;
+ }
+
+ char buffer[1024];
+ sprintf(buffer, "%d", helper.GetResult());
+
+ m_Makefile->AddDefinition(outputVariable.c_str(), buffer);
+ return true;
+}