ENH: Remove some errors, fix append to work on nonexisting lists

This commit is contained in:
Andy Cedilnik 2006-05-15 09:25:06 -04:00
parent 52a6524dbf
commit 3b92585cf0
3 changed files with 28 additions and 20 deletions

View File

@ -38,9 +38,9 @@ bool cmListCommand::InitialPass(std::vector<std::string> const& args)
{ {
return this->HandleGetCommand(args); return this->HandleGetCommand(args);
} }
if(subCommand == "SET" || subCommand == "APPEND") if(subCommand == "APPEND")
{ {
return this->HandleSetCommand(args); return this->HandleAppendCommand(args);
} }
if(subCommand == "INSERT") if(subCommand == "INSERT")
{ {
@ -72,9 +72,6 @@ bool cmListCommand::GetListString(std::string& listString, const char* var)
= this->Makefile->GetDefinition(var); = this->Makefile->GetDefinition(var);
if(!cacheValue) if(!cacheValue)
{ {
cmOStringStream str;
str << "cannot find variable: " << var;
this->SetError(str.str().c_str());
return false; return false;
} }
listString = cacheValue; listString = cacheValue;
@ -133,7 +130,8 @@ bool cmListCommand::HandleGetCommand(std::vector<std::string> const& args)
std::vector<std::string> varArgsExpanded; std::vector<std::string> varArgsExpanded;
if ( !this->GetList(varArgsExpanded, listName.c_str()) ) if ( !this->GetList(varArgsExpanded, listName.c_str()) )
{ {
return false; this->Makefile->AddDefinition(variableName.c_str(), "NOTFOUND");
return true;
} }
std::string value; std::string value;
@ -167,21 +165,18 @@ bool cmListCommand::HandleGetCommand(std::vector<std::string> const& args)
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
bool cmListCommand::HandleSetCommand(std::vector<std::string> const& args) bool cmListCommand::HandleAppendCommand(std::vector<std::string> const& args)
{ {
if(args.size() < 3) if(args.size() < 3)
{ {
this->SetError("sub-command SET requires at least two arguments."); this->SetError("sub-command APPEND requires at least two arguments.");
return false; return false;
} }
const std::string& listName = args[1]; const std::string& listName = args[1];
// expand the variable // expand the variable
std::string listString; std::string listString;
if ( !this->GetListString(listString, listName.c_str()) ) this->GetListString(listString, listName.c_str());
{
return false;
}
size_t cc; size_t cc;
for ( cc = 2; cc < args.size(); ++ cc ) for ( cc = 2; cc < args.size(); ++ cc )
{ {
@ -206,15 +201,18 @@ bool cmListCommand::HandleInsertCommand(std::vector<std::string> const& args)
} }
const std::string& listName = args[1]; const std::string& listName = args[1];
// expand the variable // expand the variable
int item = atoi(args[2].c_str());
std::vector<std::string> varArgsExpanded; std::vector<std::string> varArgsExpanded;
if ( !this->GetList(varArgsExpanded, listName.c_str()) ) if ( !this->GetList(varArgsExpanded, listName.c_str()) && (item > 0 || item < -1))
{ {
cmOStringStream str;
str << "index: " << item << " out of range (-1, 0)";
this->SetError(str.str().c_str());
return false; return false;
} }
int item = atoi(args[2].c_str());
size_t nitem = varArgsExpanded.size(); size_t nitem = varArgsExpanded.size();
if ( item < 0 ) if ( item < 0 )
{ {

View File

@ -89,7 +89,7 @@ public:
protected: protected:
bool HandleLengthCommand(std::vector<std::string> const& args); bool HandleLengthCommand(std::vector<std::string> const& args);
bool HandleGetCommand(std::vector<std::string> const& args); bool HandleGetCommand(std::vector<std::string> const& args);
bool HandleSetCommand(std::vector<std::string> const& args); bool HandleAppendCommand(std::vector<std::string> const& args);
bool HandleInsertCommand(std::vector<std::string> const& args); bool HandleInsertCommand(std::vector<std::string> const& args);
bool HandleRemoveCommand(std::vector<std::string> const& args); bool HandleRemoveCommand(std::vector<std::string> const& args);
bool HandleRemoveItemCommand(std::vector<std::string> const& args); bool HandleRemoveItemCommand(std::vector<std::string> const& args);

View File

@ -13,6 +13,9 @@ TEST("LENGTH mylist result" "4")
LIST(LENGTH "mylist" result) LIST(LENGTH "mylist" result)
TEST("LENGTH \"mylist\" result" "4") TEST("LENGTH \"mylist\" result" "4")
LIST(LENGTH "nonexiting_list1" result)
TEST("LENGTH \"nonexiting_list1\" result" "0")
LIST(GET mylist 3 2 1 0 result) LIST(GET mylist 3 2 1 0 result)
TEST("GET mylist 3 2 1 0 result" "brad;ken;bill;andy") TEST("GET mylist 3 2 1 0 result" "brad;ken;bill;andy")
@ -29,9 +32,16 @@ TEST("GET mylist -1 -2 -3 -4 result" "brad;ken;bill;andy")
LIST(GET mylist -1 2 -3 0 result) LIST(GET mylist -1 2 -3 0 result)
TEST("GET mylist -1 2 -3 0 ${result}" "brad;ken;bill;andy") TEST("GET mylist -1 2 -3 0 ${result}" "brad;ken;bill;andy")
LIST(GET "nonexiting_list2" 1 result)
TEST("GET \"nonexiting_list2\" 1 result" "NOTFOUND")
SET(result andy) SET(result andy)
LIST(SET result brad) LIST(APPEND result brad)
TEST("SET result brad" "andy;brad") TEST("APPEND result brad" "andy;brad")
LIST(APPEND "nonexiting_list3" brad)
SET(result "${nonexiting_list3}")
TEST("APPEND \"nonexiting_list1\" brad" "brad")
SET(result andy brad) SET(result andy brad)
LIST(INSERT result -1 bill ken) LIST(INSERT result -1 bill ken)