2009-09-28 15:43:28 +00:00
|
|
|
/*============================================================================
|
|
|
|
CMake - Cross Platform Makefile Generator
|
|
|
|
Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
|
2007-07-02 19:43:21 +00:00
|
|
|
|
2009-09-28 15:43:28 +00:00
|
|
|
Distributed under the OSI-approved BSD License (the "License");
|
|
|
|
see accompanying file Copyright.txt for details.
|
2007-07-02 19:43:21 +00:00
|
|
|
|
2009-09-28 15:43:28 +00: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 19:43:21 +00:00
|
|
|
|
|
|
|
#include "cmCommandArgumentsHelper.h"
|
|
|
|
|
2012-08-13 17:42:58 +00:00
|
|
|
cmCommandArgument::cmCommandArgument(cmCommandArgumentsHelper* args,
|
|
|
|
const char* key,
|
2007-07-02 19:43:21 +00:00
|
|
|
cmCommandArgumentGroup* group)
|
2016-05-16 14:34:04 +00:00
|
|
|
: Key(key)
|
|
|
|
, Group(group)
|
|
|
|
, WasActive(false)
|
|
|
|
, ArgumentsBeforeEmpty(true)
|
|
|
|
, CurrentIndex(0)
|
2007-07-02 19:43:21 +00:00
|
|
|
{
|
2016-06-27 20:44:16 +00:00
|
|
|
if (args != CM_NULLPTR) {
|
2007-07-02 19:43:21 +00:00
|
|
|
args->AddArgument(this);
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2012-08-13 17:42:58 +00:00
|
|
|
|
2016-06-27 20:44:16 +00:00
|
|
|
if (this->Group != CM_NULLPTR) {
|
2007-07-02 19:43:21 +00:00
|
|
|
this->Group->ContainedArguments.push_back(this);
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2007-07-02 19:43:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void cmCommandArgument::Reset()
|
|
|
|
{
|
2016-05-16 14:34:04 +00:00
|
|
|
this->WasActive = false;
|
2007-07-02 19:43:21 +00:00
|
|
|
this->CurrentIndex = 0;
|
|
|
|
this->DoReset();
|
|
|
|
}
|
|
|
|
|
|
|
|
void cmCommandArgument::Follows(const cmCommandArgument* arg)
|
|
|
|
{
|
2007-08-23 20:13:15 +00:00
|
|
|
this->ArgumentsBeforeEmpty = false;
|
2007-07-02 19:43:21 +00:00
|
|
|
this->ArgumentsBefore.insert(arg);
|
|
|
|
}
|
|
|
|
|
|
|
|
void cmCommandArgument::FollowsGroup(const cmCommandArgumentGroup* group)
|
|
|
|
{
|
2016-06-27 20:44:16 +00:00
|
|
|
if (group != CM_NULLPTR) {
|
2007-08-23 20:13:15 +00:00
|
|
|
this->ArgumentsBeforeEmpty = false;
|
2014-11-25 15:33:00 +00:00
|
|
|
this->ArgumentsBefore.insert(group->ContainedArguments.begin(),
|
|
|
|
group->ContainedArguments.end());
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2007-07-02 19:43:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool cmCommandArgument::MayFollow(const cmCommandArgument* current) const
|
|
|
|
{
|
2016-05-16 14:34:04 +00:00
|
|
|
if (this->ArgumentsBeforeEmpty) {
|
2007-07-02 19:43:21 +00:00
|
|
|
return true;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2007-07-02 19:43:21 +00:00
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
std::set<const cmCommandArgument*>::const_iterator argIt =
|
|
|
|
this->ArgumentsBefore.find(current);
|
|
|
|
if (argIt != this->ArgumentsBefore.end()) {
|
2007-07-02 19:43:21 +00:00
|
|
|
return true;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2007-07-02 19:43:21 +00:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool cmCommandArgument::KeyMatches(const std::string& key) const
|
|
|
|
{
|
2016-06-27 20:44:16 +00:00
|
|
|
if ((this->Key == CM_NULLPTR) || (this->Key[0] == '\0')) {
|
2007-07-02 19:43:21 +00:00
|
|
|
return true;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
|
|
|
return (key == this->Key);
|
2007-07-02 19:43:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void cmCommandArgument::ApplyOwnGroup()
|
|
|
|
{
|
2016-06-27 20:44:16 +00:00
|
|
|
if (this->Group != CM_NULLPTR) {
|
2016-05-16 14:34:04 +00:00
|
|
|
for (std::vector<cmCommandArgument*>::const_iterator it =
|
|
|
|
this->Group->ContainedArguments.begin();
|
|
|
|
it != this->Group->ContainedArguments.end(); ++it) {
|
|
|
|
if (*it != this) {
|
2007-07-02 19:43:21 +00:00
|
|
|
this->ArgumentsBefore.insert(*it);
|
|
|
|
}
|
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2007-07-02 19:43:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void cmCommandArgument::Activate()
|
|
|
|
{
|
2012-08-13 17:42:58 +00:00
|
|
|
this->WasActive = true;
|
2007-07-02 19:43:21 +00:00
|
|
|
this->CurrentIndex = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool cmCommandArgument::Consume(const std::string& arg)
|
|
|
|
{
|
2016-05-16 14:34:04 +00:00
|
|
|
bool res = this->DoConsume(arg, this->CurrentIndex);
|
2007-07-02 19:43:21 +00:00
|
|
|
this->CurrentIndex++;
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2012-08-13 17:42:58 +00:00
|
|
|
cmCAStringVector::cmCAStringVector(cmCommandArgumentsHelper* args,
|
|
|
|
const char* key,
|
2007-07-02 19:43:21 +00:00
|
|
|
cmCommandArgumentGroup* group)
|
2016-05-16 14:34:04 +00:00
|
|
|
: cmCommandArgument(args, key, group)
|
2016-06-27 20:44:16 +00:00
|
|
|
, Ignore(CM_NULLPTR)
|
2007-07-02 19:43:21 +00:00
|
|
|
{
|
2016-06-27 20:44:16 +00:00
|
|
|
if ((key == CM_NULLPTR) || (*key == 0)) {
|
2007-07-02 19:43:21 +00:00
|
|
|
this->DataStart = 0;
|
2016-05-16 14:34:04 +00:00
|
|
|
} else {
|
2007-07-02 19:43:21 +00:00
|
|
|
this->DataStart = 1;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2007-07-02 19:43:21 +00:00
|
|
|
}
|
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
bool cmCAStringVector::DoConsume(const std::string& arg, unsigned int index)
|
2007-07-02 19:43:21 +00:00
|
|
|
{
|
2016-05-16 14:34:04 +00:00
|
|
|
if (index >= this->DataStart) {
|
2016-06-27 20:44:16 +00:00
|
|
|
if ((this->Ignore == CM_NULLPTR) || (arg != this->Ignore)) {
|
2007-07-02 19:43:21 +00:00
|
|
|
this->Vector.push_back(arg);
|
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2007-07-02 19:43:21 +00:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void cmCAStringVector::DoReset()
|
|
|
|
{
|
|
|
|
this->Vector.clear();
|
|
|
|
}
|
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
cmCAString::cmCAString(cmCommandArgumentsHelper* args, const char* key,
|
2007-07-02 19:43:21 +00:00
|
|
|
cmCommandArgumentGroup* group)
|
2016-05-16 14:34:04 +00:00
|
|
|
: cmCommandArgument(args, key, group)
|
2007-07-02 19:43:21 +00:00
|
|
|
{
|
2016-06-27 20:44:16 +00:00
|
|
|
if ((key == CM_NULLPTR) || (*key == 0)) {
|
2007-07-02 19:43:21 +00:00
|
|
|
this->DataStart = 0;
|
2016-05-16 14:34:04 +00:00
|
|
|
} else {
|
2007-07-02 19:43:21 +00:00
|
|
|
this->DataStart = 1;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2007-07-02 19:43:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool cmCAString::DoConsume(const std::string& arg, unsigned int index)
|
|
|
|
{
|
2016-05-16 14:34:04 +00:00
|
|
|
if (index == this->DataStart) {
|
2007-07-02 19:43:21 +00:00
|
|
|
this->String = arg;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2007-07-02 19:43:21 +00:00
|
|
|
|
|
|
|
return index >= this->DataStart;
|
|
|
|
}
|
|
|
|
|
|
|
|
void cmCAString::DoReset()
|
|
|
|
{
|
2012-07-11 19:03:21 +00:00
|
|
|
this->String = "";
|
2007-07-02 19:43:21 +00:00
|
|
|
}
|
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
cmCAEnabler::cmCAEnabler(cmCommandArgumentsHelper* args, const char* key,
|
2007-07-02 19:43:21 +00:00
|
|
|
cmCommandArgumentGroup* group)
|
2016-05-16 14:34:04 +00:00
|
|
|
: cmCommandArgument(args, key, group)
|
|
|
|
, Enabled(false)
|
|
|
|
{
|
|
|
|
}
|
2007-07-02 19:43:21 +00:00
|
|
|
|
2007-07-02 20:46:18 +00:00
|
|
|
bool cmCAEnabler::DoConsume(const std::string&, unsigned int index)
|
2007-07-02 19:43:21 +00:00
|
|
|
{
|
2016-05-16 14:34:04 +00:00
|
|
|
if (index == 0) {
|
2007-07-02 19:43:21 +00:00
|
|
|
this->Enabled = true;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2007-07-02 19:43:21 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void cmCAEnabler::DoReset()
|
|
|
|
{
|
|
|
|
this->Enabled = false;
|
|
|
|
}
|
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
cmCADisabler::cmCADisabler(cmCommandArgumentsHelper* args, const char* key,
|
2007-07-02 19:43:21 +00:00
|
|
|
cmCommandArgumentGroup* group)
|
2016-05-16 14:34:04 +00:00
|
|
|
: cmCommandArgument(args, key, group)
|
|
|
|
, Enabled(true)
|
|
|
|
{
|
|
|
|
}
|
2007-07-02 19:43:21 +00:00
|
|
|
|
2007-07-02 20:46:18 +00:00
|
|
|
bool cmCADisabler::DoConsume(const std::string&, unsigned int index)
|
2007-07-02 19:43:21 +00:00
|
|
|
{
|
2016-05-16 14:34:04 +00:00
|
|
|
if (index == 0) {
|
2007-07-02 19:43:21 +00:00
|
|
|
this->Enabled = false;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2007-07-02 19:43:21 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void cmCADisabler::DoReset()
|
|
|
|
{
|
|
|
|
this->Enabled = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void cmCommandArgumentGroup::Follows(const cmCommandArgument* arg)
|
|
|
|
{
|
2016-05-16 14:34:04 +00:00
|
|
|
for (std::vector<cmCommandArgument*>::iterator it =
|
|
|
|
this->ContainedArguments.begin();
|
|
|
|
it != this->ContainedArguments.end(); ++it) {
|
2007-07-02 19:43:21 +00:00
|
|
|
(*it)->Follows(arg);
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2007-07-02 19:43:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void cmCommandArgumentGroup::FollowsGroup(const cmCommandArgumentGroup* group)
|
|
|
|
{
|
2016-05-16 14:34:04 +00:00
|
|
|
for (std::vector<cmCommandArgument*>::iterator it =
|
|
|
|
this->ContainedArguments.begin();
|
|
|
|
it != this->ContainedArguments.end(); ++it) {
|
2007-07-02 19:43:21 +00:00
|
|
|
(*it)->FollowsGroup(group);
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2007-07-02 19:43:21 +00:00
|
|
|
}
|
|
|
|
|
2012-08-13 17:42:58 +00:00
|
|
|
void cmCommandArgumentsHelper::Parse(const std::vector<std::string>* args,
|
2007-07-02 19:43:21 +00:00
|
|
|
std::vector<std::string>* unconsumedArgs)
|
|
|
|
{
|
2016-06-27 20:44:16 +00:00
|
|
|
if (args == CM_NULLPTR) {
|
2007-07-02 19:43:21 +00:00
|
|
|
return;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2007-07-02 19:43:21 +00:00
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
for (std::vector<cmCommandArgument*>::iterator argIt =
|
|
|
|
this->Arguments.begin();
|
|
|
|
argIt != this->Arguments.end(); ++argIt) {
|
2007-07-02 19:43:21 +00:00
|
|
|
(*argIt)->ApplyOwnGroup();
|
|
|
|
(*argIt)->Reset();
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2007-07-02 19:43:21 +00:00
|
|
|
|
2016-06-27 20:44:16 +00:00
|
|
|
cmCommandArgument* activeArgument = CM_NULLPTR;
|
|
|
|
const cmCommandArgument* previousArgument = CM_NULLPTR;
|
2016-05-16 14:34:04 +00:00
|
|
|
for (std::vector<std::string>::const_iterator it = args->begin();
|
|
|
|
it != args->end(); ++it) {
|
|
|
|
for (std::vector<cmCommandArgument*>::iterator argIt =
|
|
|
|
this->Arguments.begin();
|
|
|
|
argIt != this->Arguments.end(); ++argIt) {
|
|
|
|
if ((*argIt)->KeyMatches(*it) &&
|
|
|
|
((*argIt)->MayFollow(previousArgument))) {
|
2007-07-02 19:43:21 +00:00
|
|
|
activeArgument = *argIt;
|
|
|
|
activeArgument->Activate();
|
|
|
|
break;
|
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2007-07-02 19:43:21 +00:00
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
if (activeArgument) {
|
2007-07-02 19:43:21 +00:00
|
|
|
bool argDone = activeArgument->Consume(*it);
|
|
|
|
previousArgument = activeArgument;
|
2016-05-16 14:34:04 +00:00
|
|
|
if (argDone) {
|
2016-06-27 20:44:16 +00:00
|
|
|
activeArgument = CM_NULLPTR;
|
2007-07-02 19:43:21 +00:00
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
} else {
|
2016-06-27 20:44:16 +00:00
|
|
|
if (unconsumedArgs != CM_NULLPTR) {
|
2007-07-02 19:43:21 +00:00
|
|
|
unconsumedArgs->push_back(*it);
|
|
|
|
}
|
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2007-07-02 19:43:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void cmCommandArgumentsHelper::AddArgument(cmCommandArgument* arg)
|
|
|
|
{
|
|
|
|
this->Arguments.push_back(arg);
|
|
|
|
}
|