From 6e5af0e6ccbb0f2c0a4aec00003ea0ce68ea2f95 Mon Sep 17 00:00:00 2001 From: Ken Martin Date: Thu, 26 Apr 2001 10:49:12 -0400 Subject: [PATCH] some fixes for If commands --- Source/cmCacheManager.cxx | 3 +-- Source/cmElseCommand.cxx | 3 +-- Source/cmIfCommand.cxx | 3 +-- Source/cmSystemTools.cxx | 17 +++++++++++++++++ Source/cmSystemTools.h | 2 ++ 5 files changed, 22 insertions(+), 6 deletions(-) diff --git a/Source/cmCacheManager.cxx b/Source/cmCacheManager.cxx index bc2f0a794..2424526f0 100644 --- a/Source/cmCacheManager.cxx +++ b/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()); } diff --git a/Source/cmElseCommand.cxx b/Source/cmElseCommand.cxx index ff396fc97..51e9f25c4 100644 --- a/Source/cmElseCommand.cxx +++ b/Source/cmElseCommand.cxx @@ -26,8 +26,7 @@ bool cmElseCommand::Invoke(std::vector& 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(); diff --git a/Source/cmIfCommand.cxx b/Source/cmIfCommand.cxx index 5dab24b73..0701ee230 100644 --- a/Source/cmIfCommand.cxx +++ b/Source/cmIfCommand.cxx @@ -48,8 +48,7 @@ bool cmIfCommand::Invoke(std::vector& 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 } diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx index 0087ca05d..2a27d3f02 100644 --- a/Source/cmSystemTools.cxx +++ b/Source/cmSystemTools.cxx @@ -18,6 +18,7 @@ #include "stdio.h" #include #include "cmRegularExpression.h" +#include #if defined(_MSC_VER) || defined(__BORLANDC__) #include @@ -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 v = val; + + for(std::basic_string::iterator c = v.begin(); + c != v.end(); c++) + { + *c = toupper(*c); + } + return (v == "ON" || v == "1" || v == "YES" || v == "TRUE" || v == "Y"); +} diff --git a/Source/cmSystemTools.h b/Source/cmSystemTools.h index 04347fc4e..a13eb56ad 100644 --- a/Source/cmSystemTools.h +++ b/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);