فهرست منبع

some fixes for If commands

Ken Martin 24 سال پیش
والد
کامیت
6e5af0e6cc
5فایلهای تغییر یافته به همراه22 افزوده شده و 6 حذف شده
  1. 1 2
      Source/cmCacheManager.cxx
  2. 1 2
      Source/cmElseCommand.cxx
  3. 1 2
      Source/cmIfCommand.cxx
  4. 17 0
      Source/cmSystemTools.cxx
  5. 2 0
      Source/cmSystemTools.h

+ 1 - 2
Source/cmCacheManager.cxx

@@ -190,8 +190,7 @@ bool cmCacheManager::IsOn(const char* key) const
     return false;
     }
   const std::string &v = m_Cache.find(key)->second.m_Value;
-  return (v == "ON" || v == "on" || v == "1" || v == "true" || v == "yev"
-          || v == "TRUE" || v == "True" || v == "y" || v == "Y");
+  return cmSystemTools::IsOn(v.c_str());
 }
 
 

+ 1 - 2
Source/cmElseCommand.cxx

@@ -26,8 +26,7 @@ bool cmElseCommand::Invoke(std::vector<std::string>& args)
 
   // check to see if the argument is defined first
   const char *def = m_Makefile->GetDefinition(args[0].c_str());
-  if(def && strcmp(def,"0") && strcmp(def,"false") && strcmp(def,"") && 
-     strcmp(def,"NOTFOUND"))
+  if(cmSystemTools::IsOn(def))
     {
     // add block
     cmIfFunctionBlocker *f = new cmIfFunctionBlocker();

+ 1 - 2
Source/cmIfCommand.cxx

@@ -48,8 +48,7 @@ bool cmIfCommand::Invoke(std::vector<std::string>& args)
 
   // check to see if the argument is defined first
   const char *def = m_Makefile->GetDefinition(args[0].c_str());
-  if(def && strcmp(def,"0") && strcmp(def,"false") && strcmp(def,"") && 
-     strcmp(def,"NOTFOUND"))
+  if(cmSystemTools::IsOn(def))
     {
     // do nothing
     }

+ 17 - 0
Source/cmSystemTools.cxx

@@ -18,6 +18,7 @@
 #include "stdio.h"
 #include <sys/stat.h>
 #include "cmRegularExpression.h"
+#include <ctype.h>
 
 #if defined(_MSC_VER) || defined(__BORLANDC__)
 #include <windows.h>
@@ -502,3 +503,19 @@ void cmSystemTools::RemoveFile(const char* source)
 {
   unlink(source);
 }
+
+bool cmSystemTools::IsOn(const char* val)
+{
+  if (!val)
+    {
+    return false;
+    }
+  std::basic_string<char> v = val;
+  
+  for(std::basic_string<char>::iterator c = v.begin();
+      c != v.end(); c++)
+    {
+    *c = toupper(*c);
+    }
+  return (v == "ON" || v == "1" || v == "YES" || v == "TRUE" || v == "Y");
+}

+ 2 - 0
Source/cmSystemTools.h

@@ -126,6 +126,8 @@ public:
   ///! Remove a file.
   static void RemoveFile(const char* source);
   
+  ///! does a string indicate a true or on value ?
+  static bool IsOn(const char* val);
   
   static long int ModifiedTime(const char* filename);