added strequal

This commit is contained in:
Ken Martin 2004-06-14 12:02:12 -04:00
parent cd875fe781
commit a18fbc3b37
2 changed files with 27 additions and 23 deletions

View File

@ -133,7 +133,7 @@ bool cmIfCommand::InvokeInitialPass(const std::vector<cmListFileArgument>& args)
// order of operations,
// EXISTS COMMAND DEFINED
// MATCHES LESS GREATER EQUAL STRLESS STRGREATER
// MATCHES LESS GREATER EQUAL STRLESS STRGREATER STREQUAL
// AND OR
//
// There is an issue on whether the arguments should be values of references,
@ -357,13 +357,27 @@ bool cmIfCommand::IsTrue(const std::vector<std::string> &args,
}
if (argP1 != newArgs.end() && argP2 != newArgs.end() &&
(*(argP1) == "STRLESS" || *(argP1) == "STRGREATER"))
(*(argP1) == "STRLESS" ||
*(argP1) == "STREQUAL" ||
*(argP1) == "STRGREATER"))
{
def = cmIfCommand::GetVariableOrString(arg->c_str(), makefile);
def2 = cmIfCommand::GetVariableOrString((argP2)->c_str(), makefile);
int val = strcmp(def,def2);
int result;
if (*(argP1) == "STRLESS")
{
if(strcmp(def,def2) < 0)
result = (val < 0);
}
else if (*(argP1) == "STRGREATER")
{
result = (val > 0);
}
else // strequal
{
result = (val == 0);
}
if(result)
{
*arg = "1";
}
@ -371,18 +385,6 @@ bool cmIfCommand::IsTrue(const std::vector<std::string> &args,
{
*arg = "0";
}
}
else
{
if(strcmp(def,def2) > 0)
{
*arg = "1";
}
else
{
*arg = "0";
}
}
newArgs.erase(argP2);
newArgs.erase(argP1);
argP1 = arg;

View File

@ -115,9 +115,9 @@ public:
"the same expression must be given to IF, ELSE, and ENDIF. Long "
"exressions can be used and the order or precidence is that the "
"EXISTS, COMMAND, and DEFINED operators will be evaluated first. "
"Then any EQUAL, LESS, GREATER, STRLESS, STRGREATER, MATCHES will be "
"evaluated. Then NOT operators and finally AND, OR operators will be "
"evaluated. Possible expressions are:\n"
"Then any EQUAL, LESS, GREATER, STRLESS, STRGREATER, STREQUAL, MATCHES "
"will be evaluated. Then NOT operators and finally AND, OR operators "
"will be evaluated. Possible expressions are:\n"
" IF(variable)\n"
"True if the variable's value is not empty, 0, FALSE, OFF, or NOTFOUND.\n"
" IF(NOT variable)\n"
@ -149,8 +149,10 @@ public:
" IF(string STRLESS string)\n"
" IF(variable STRGREATER string)\n"
" IF(string STRGREATER string)\n"
" IF(variable STREQUAL string)\n"
" IF(string STREQUAL string)\n"
"True if the given string or variable's value is lexicographically "
"less (or greater) than the string on the right.\n"
"less (or greater, or equal) than the string on the right.\n"
" IF(DEFINED variable)\n"
"True if the given variable is defined. It does not matter if the "
"variable is true or false just if it has been set.";