Try to improve source group interface

This commit is contained in:
Andy Cedilnik 2002-10-04 18:16:13 -04:00
parent 77616437d1
commit a518fed4e3
5 changed files with 645 additions and 583 deletions

View File

@ -752,6 +752,20 @@ void cmMakefile::AddUtilityCommand(const char* utilityName,
m_Targets.insert(cmTargets::value_type(utilityName,target)); m_Targets.insert(cmTargets::value_type(utilityName,target));
} }
cmSourceGroup* cmMakefile::GetSourceGroup(const char* name)
{
// First see if the group exists. If so, replace its regular expression.
for(std::vector<cmSourceGroup>::iterator sg = m_SourceGroups.begin();
sg != m_SourceGroups.end(); ++sg)
{
std::string sgName = sg->GetName();
if(sgName == name)
{
return &(*sg);
}
}
return 0;
}
void cmMakefile::AddSourceGroup(const char* name, const char* regex) void cmMakefile::AddSourceGroup(const char* name, const char* regex)
{ {
@ -761,10 +775,13 @@ void cmMakefile::AddSourceGroup(const char* name, const char* regex)
{ {
std::string sgName = sg->GetName(); std::string sgName = sg->GetName();
if(sgName == name) if(sgName == name)
{
if ( regex )
{ {
// We only want to set the regular expression. If there are already // We only want to set the regular expression. If there are already
// source files in the group, we don't want to remove them. // source files in the group, we don't want to remove them.
sg->SetGroupRegex(regex); sg->SetGroupRegex(regex);
}
return; return;
} }
} }

View File

@ -239,7 +239,7 @@ public:
/** /**
* Add a source group for consideration when adding a new source. * Add a source group for consideration when adding a new source.
*/ */
void AddSourceGroup(const char* name, const char* regex); void AddSourceGroup(const char* name, const char* regex=0);
/** /**
* Add an auxiliary directory to the build. * Add an auxiliary directory to the build.
@ -451,6 +451,11 @@ public:
const std::vector<cmSourceGroup>& GetSourceGroups() const const std::vector<cmSourceGroup>& GetSourceGroups() const
{ return m_SourceGroups; } { return m_SourceGroups; }
/**
* Get the source group
*/
cmSourceGroup* GetSourceGroup(const char* name);
/** /**
* Get the vector of list files on which this makefile depends * Get the vector of list files on which this makefile depends
*/ */
@ -488,7 +493,6 @@ public:
*/ */
cmSourceGroup& FindSourceGroup(const char* source, cmSourceGroup& FindSourceGroup(const char* source,
std::vector<cmSourceGroup> &groups); std::vector<cmSourceGroup> &groups);
void RegisterData(cmData*); void RegisterData(cmData*);
void RegisterData(const char*, cmData*); void RegisterData(const char*, cmData*);
cmData* LookupData(const char*) const; cmData* LookupData(const char*) const;

View File

@ -39,6 +39,11 @@
// cmRegularExpression -- Copies the given regular expression. // cmRegularExpression -- Copies the given regular expression.
cmRegularExpression::cmRegularExpression (const cmRegularExpression& rxp) { cmRegularExpression::cmRegularExpression (const cmRegularExpression& rxp) {
if ( !rxp.program )
{
this->program = 0;
return;
}
int ind; int ind;
this->progsize = rxp.progsize; // Copy regular expression size this->progsize = rxp.progsize; // Copy regular expression size
this->program = new char[this->progsize]; // Allocate storage this->program = new char[this->progsize]; // Allocate storage
@ -848,8 +853,13 @@ bool cmRegularExpression::find (const char* string) {
this->searchstring = string; this->searchstring = string;
if (!this->program)
{
return false;
}
// Check validity of program. // Check validity of program.
if (!this->program || UCHARAT(this->program) != MAGIC) { if (UCHARAT(this->program) != MAGIC) {
//RAISE Error, SYM(cmRegularExpression), SYM(Internal_Error), //RAISE Error, SYM(cmRegularExpression), SYM(Internal_Error),
printf ("cmRegularExpression::find(): Compiled regular expression corrupted.\n"); printf ("cmRegularExpression::find(): Compiled regular expression corrupted.\n");
return 0; return 0;

View File

@ -290,7 +290,10 @@ inline cmRegularExpression::cmRegularExpression ()
inline cmRegularExpression::cmRegularExpression (const char* s) inline cmRegularExpression::cmRegularExpression (const char* s)
{ {
this->program = 0; this->program = 0;
compile(s); if ( s )
{
this->compile(s);
}
} }
/** /**

View File

@ -19,14 +19,42 @@
// cmSourceGroupCommand // cmSourceGroupCommand
bool cmSourceGroupCommand::InitialPass(std::vector<std::string> const& args) bool cmSourceGroupCommand::InitialPass(std::vector<std::string> const& args)
{ {
if(args.size() != 2) if(args.size() < 1)
{ {
this->SetError("called with incorrect number of arguments"); this->SetError("called with incorrect number of arguments");
return false; return false;
} }
m_Makefile->AddSourceGroup(args[0].c_str(), args[1].c_str()); if ( args[1] == "REGULAR_EXPRESSION" && args.size() == 3 )
{
m_Makefile->AddSourceGroup(args[0].c_str(), args[2].c_str());
return true;
}
if ( args[1] == "FILES" )
{
cmSourceGroup* sg = m_Makefile->GetSourceGroup(args[0].c_str());
if ( !sg )
{
m_Makefile->AddSourceGroup(args[0].c_str(), 0);
sg = m_Makefile->GetSourceGroup(args[0].c_str());
}
unsigned int cc;
for ( cc = 3; cc < args.size(); cc ++ )
{
sg->AddSource(args[cc].c_str(), 0);
}
return true; return true;
}
if ( args.size() == 2 )
{
m_Makefile->AddSourceGroup(args[0].c_str(), args[1].c_str());
return true;
}
this->SetError("called with incorrect number of arguments");
return false;
} }