some fixes for If commands

This commit is contained in:
Ken Martin 2001-04-26 10:49:12 -04:00
parent 30ad61805b
commit 6e5af0e6cc
5 changed files with 22 additions and 6 deletions

View File

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

View File

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

View File

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

View File

@ -18,6 +18,7 @@
#include "stdio.h" #include "stdio.h"
#include <sys/stat.h> #include <sys/stat.h>
#include "cmRegularExpression.h" #include "cmRegularExpression.h"
#include <ctype.h>
#if defined(_MSC_VER) || defined(__BORLANDC__) #if defined(_MSC_VER) || defined(__BORLANDC__)
#include <windows.h> #include <windows.h>
@ -502,3 +503,19 @@ void cmSystemTools::RemoveFile(const char* source)
{ {
unlink(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");
}

View File

@ -126,6 +126,8 @@ public:
///! Remove a file. ///! Remove a file.
static void RemoveFile(const char* source); 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); static long int ModifiedTime(const char* filename);