2009-09-28 19:43:28 +04:00
|
|
|
/*============================================================================
|
|
|
|
CMake - Cross Platform Makefile Generator
|
|
|
|
Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
|
2007-07-02 23:43:21 +04:00
|
|
|
|
2009-09-28 19:43:28 +04:00
|
|
|
Distributed under the OSI-approved BSD License (the "License");
|
|
|
|
see accompanying file Copyright.txt for details.
|
2007-07-02 23:43:21 +04:00
|
|
|
|
2009-09-28 19:43:28 +04:00
|
|
|
This software is distributed WITHOUT ANY WARRANTY; without even the
|
|
|
|
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
See the License for more information.
|
|
|
|
============================================================================*/
|
2007-07-02 23:43:21 +04:00
|
|
|
|
|
|
|
#include "cmCommandArgumentsHelper.h"
|
|
|
|
|
2012-08-13 21:42:58 +04:00
|
|
|
cmCommandArgument::cmCommandArgument(cmCommandArgumentsHelper* args,
|
|
|
|
const char* key,
|
2007-07-02 23:43:21 +04:00
|
|
|
cmCommandArgumentGroup* group)
|
|
|
|
:Key(key)
|
|
|
|
,Group(group)
|
|
|
|
,WasActive(false)
|
2007-08-24 00:13:15 +04:00
|
|
|
,ArgumentsBeforeEmpty(true)
|
2012-08-13 21:42:58 +04:00
|
|
|
,CurrentIndex(0)
|
2007-07-02 23:43:21 +04:00
|
|
|
{
|
|
|
|
if (args!=0)
|
|
|
|
{
|
|
|
|
args->AddArgument(this);
|
|
|
|
}
|
2012-08-13 21:42:58 +04:00
|
|
|
|
2007-07-02 23:43:21 +04:00
|
|
|
if (this->Group!=0)
|
|
|
|
{
|
|
|
|
this->Group->ContainedArguments.push_back(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void cmCommandArgument::Reset()
|
|
|
|
{
|
|
|
|
this->WasActive =false;
|
|
|
|
this->CurrentIndex = 0;
|
|
|
|
this->DoReset();
|
|
|
|
}
|
|
|
|
|
|
|
|
void cmCommandArgument::Follows(const cmCommandArgument* arg)
|
|
|
|
{
|
2007-08-24 00:13:15 +04:00
|
|
|
this->ArgumentsBeforeEmpty = false;
|
2007-07-02 23:43:21 +04:00
|
|
|
this->ArgumentsBefore.insert(arg);
|
|
|
|
}
|
|
|
|
|
|
|
|
void cmCommandArgument::FollowsGroup(const cmCommandArgumentGroup* group)
|
|
|
|
{
|
|
|
|
if (group!=0)
|
|
|
|
{
|
2007-08-24 00:13:15 +04:00
|
|
|
this->ArgumentsBeforeEmpty = false;
|
2012-08-13 21:42:58 +04:00
|
|
|
for(std::vector<cmCommandArgument*>::const_iterator
|
2007-07-02 23:43:21 +04:00
|
|
|
argIt= group->ContainedArguments.begin();
|
|
|
|
argIt != group->ContainedArguments.end();
|
|
|
|
++argIt)
|
|
|
|
{
|
|
|
|
this->ArgumentsBefore.insert(*argIt);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool cmCommandArgument::MayFollow(const cmCommandArgument* current) const
|
|
|
|
{
|
2007-08-24 00:13:15 +04:00
|
|
|
if (this->ArgumentsBeforeEmpty)
|
2007-07-02 23:43:21 +04:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-08-13 21:42:58 +04:00
|
|
|
std::set<const cmCommandArgument*>::const_iterator argIt
|
2007-07-02 23:43:21 +04:00
|
|
|
= this->ArgumentsBefore.find(current);
|
|
|
|
if (argIt != this->ArgumentsBefore.end())
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool cmCommandArgument::KeyMatches(const std::string& key) const
|
|
|
|
{
|
|
|
|
if ((this->Key==0) || (this->Key[0]=='\0'))
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return (key==this->Key);
|
|
|
|
}
|
|
|
|
|
|
|
|
void cmCommandArgument::ApplyOwnGroup()
|
|
|
|
{
|
|
|
|
if (this->Group!=0)
|
|
|
|
{
|
2012-08-13 21:42:58 +04:00
|
|
|
for (std::vector<cmCommandArgument*>::const_iterator
|
2007-07-02 23:43:21 +04:00
|
|
|
it = this->Group->ContainedArguments.begin();
|
|
|
|
it != this->Group->ContainedArguments.end();
|
|
|
|
++it)
|
|
|
|
{
|
|
|
|
if(*it != this)
|
|
|
|
{
|
|
|
|
this->ArgumentsBefore.insert(*it);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void cmCommandArgument::Activate()
|
|
|
|
{
|
2012-08-13 21:42:58 +04:00
|
|
|
this->WasActive = true;
|
2007-07-02 23:43:21 +04:00
|
|
|
this->CurrentIndex = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool cmCommandArgument::Consume(const std::string& arg)
|
|
|
|
{
|
|
|
|
bool res=this->DoConsume(arg, this->CurrentIndex);
|
|
|
|
this->CurrentIndex++;
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-08-13 21:42:58 +04:00
|
|
|
cmCAStringVector::cmCAStringVector(cmCommandArgumentsHelper* args,
|
|
|
|
const char* key,
|
2007-07-02 23:43:21 +04:00
|
|
|
cmCommandArgumentGroup* group)
|
|
|
|
:cmCommandArgument(args, key, group)
|
2007-07-04 00:10:50 +04:00
|
|
|
,Ignore(0)
|
2007-07-02 23:43:21 +04:00
|
|
|
{
|
|
|
|
if ((key==0) || (*key==0))
|
|
|
|
{
|
|
|
|
this->DataStart = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this->DataStart = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool cmCAStringVector::DoConsume(const std::string& arg,unsigned int index)
|
|
|
|
{
|
|
|
|
if (index >= this->DataStart)
|
|
|
|
{
|
|
|
|
if ((this->Ignore==0) || (arg != this->Ignore))
|
|
|
|
{
|
|
|
|
this->Vector.push_back(arg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void cmCAStringVector::DoReset()
|
|
|
|
{
|
|
|
|
this->Vector.clear();
|
|
|
|
}
|
|
|
|
|
2012-08-13 21:42:58 +04:00
|
|
|
cmCAString::cmCAString(cmCommandArgumentsHelper* args,
|
|
|
|
const char* key,
|
2007-07-02 23:43:21 +04:00
|
|
|
cmCommandArgumentGroup* group)
|
|
|
|
:cmCommandArgument(args, key, group)
|
|
|
|
{
|
|
|
|
if ((key==0) || (*key==0))
|
|
|
|
{
|
|
|
|
this->DataStart = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this->DataStart = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool cmCAString::DoConsume(const std::string& arg, unsigned int index)
|
|
|
|
{
|
|
|
|
if (index == this->DataStart)
|
|
|
|
{
|
|
|
|
this->String = arg;
|
|
|
|
}
|
|
|
|
|
|
|
|
return index >= this->DataStart;
|
|
|
|
}
|
|
|
|
|
|
|
|
void cmCAString::DoReset()
|
|
|
|
{
|
2012-07-11 23:03:21 +04:00
|
|
|
this->String = "";
|
2007-07-02 23:43:21 +04:00
|
|
|
}
|
|
|
|
|
2012-08-13 21:42:58 +04:00
|
|
|
cmCAEnabler::cmCAEnabler(cmCommandArgumentsHelper* args,
|
|
|
|
const char* key,
|
2007-07-02 23:43:21 +04:00
|
|
|
cmCommandArgumentGroup* group)
|
|
|
|
:cmCommandArgument(args, key, group)
|
2012-08-13 21:42:58 +04:00
|
|
|
,Enabled(false)
|
2007-07-02 23:43:21 +04:00
|
|
|
{}
|
|
|
|
|
2007-07-03 00:46:18 +04:00
|
|
|
bool cmCAEnabler::DoConsume(const std::string&, unsigned int index)
|
2007-07-02 23:43:21 +04:00
|
|
|
{
|
|
|
|
if (index==0)
|
|
|
|
{
|
|
|
|
this->Enabled = true;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void cmCAEnabler::DoReset()
|
|
|
|
{
|
|
|
|
this->Enabled = false;
|
|
|
|
}
|
|
|
|
|
2012-08-13 21:42:58 +04:00
|
|
|
cmCADisabler::cmCADisabler(cmCommandArgumentsHelper* args,
|
|
|
|
const char* key,
|
2007-07-02 23:43:21 +04:00
|
|
|
cmCommandArgumentGroup* group)
|
|
|
|
:cmCommandArgument(args, key, group)
|
2012-08-13 21:42:58 +04:00
|
|
|
,Enabled(true)
|
2007-07-02 23:43:21 +04:00
|
|
|
{}
|
|
|
|
|
2007-07-03 00:46:18 +04:00
|
|
|
bool cmCADisabler::DoConsume(const std::string&, unsigned int index)
|
2007-07-02 23:43:21 +04:00
|
|
|
{
|
|
|
|
if (index==0)
|
|
|
|
{
|
|
|
|
this->Enabled = false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void cmCADisabler::DoReset()
|
|
|
|
{
|
|
|
|
this->Enabled = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void cmCommandArgumentGroup::Follows(const cmCommandArgument* arg)
|
|
|
|
{
|
2012-08-13 21:42:58 +04:00
|
|
|
for(std::vector<cmCommandArgument*>::iterator
|
2007-07-02 23:43:21 +04:00
|
|
|
it = this->ContainedArguments.begin();
|
|
|
|
it != this->ContainedArguments.end();
|
|
|
|
++it)
|
|
|
|
{
|
|
|
|
(*it)->Follows(arg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void cmCommandArgumentGroup::FollowsGroup(const cmCommandArgumentGroup* group)
|
|
|
|
{
|
2012-08-13 21:42:58 +04:00
|
|
|
for(std::vector<cmCommandArgument*>::iterator
|
2007-07-02 23:43:21 +04:00
|
|
|
it = this->ContainedArguments.begin();
|
|
|
|
it != this->ContainedArguments.end();
|
|
|
|
++it)
|
|
|
|
{
|
|
|
|
(*it)->FollowsGroup(group);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-13 21:42:58 +04:00
|
|
|
void cmCommandArgumentsHelper::Parse(const std::vector<std::string>* args,
|
2007-07-02 23:43:21 +04:00
|
|
|
std::vector<std::string>* unconsumedArgs)
|
|
|
|
{
|
|
|
|
if(args==0)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-08-13 21:42:58 +04:00
|
|
|
for(std::vector<cmCommandArgument*>::iterator
|
2007-07-02 23:43:21 +04:00
|
|
|
argIt = this->Arguments.begin();
|
|
|
|
argIt != this->Arguments.end();
|
|
|
|
++argIt)
|
|
|
|
{
|
|
|
|
(*argIt)->ApplyOwnGroup();
|
|
|
|
(*argIt)->Reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
cmCommandArgument* activeArgument = 0;
|
|
|
|
const cmCommandArgument* previousArgument = 0;
|
|
|
|
for(std::vector<std::string>::const_iterator it = args->begin();
|
|
|
|
it != args->end();
|
|
|
|
++it)
|
|
|
|
{
|
2012-08-13 21:42:58 +04:00
|
|
|
for(std::vector<cmCommandArgument*>::iterator
|
2007-07-02 23:43:21 +04:00
|
|
|
argIt = this->Arguments.begin();
|
|
|
|
argIt != this->Arguments.end();
|
|
|
|
++argIt)
|
|
|
|
{
|
|
|
|
if ((*argIt)->KeyMatches(*it) && ((*argIt)->MayFollow(previousArgument)))
|
|
|
|
{
|
|
|
|
activeArgument = *argIt;
|
|
|
|
activeArgument->Activate();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (activeArgument)
|
|
|
|
{
|
|
|
|
bool argDone = activeArgument->Consume(*it);
|
|
|
|
previousArgument = activeArgument;
|
|
|
|
if (argDone)
|
|
|
|
{
|
|
|
|
activeArgument = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (unconsumedArgs!=0)
|
|
|
|
{
|
|
|
|
unconsumedArgs->push_back(*it);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void cmCommandArgumentsHelper::AddArgument(cmCommandArgument* arg)
|
|
|
|
{
|
|
|
|
this->Arguments.push_back(arg);
|
|
|
|
}
|
|
|
|
|