summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Source/cmMakefile.cxx95
-rw-r--r--Source/cmMakefile.h14
-rw-r--r--Source/cmRegularExpression.cxx1082
-rw-r--r--Source/cmRegularExpression.h19
-rw-r--r--Source/cmSourceGroupCommand.cxx36
5 files changed, 654 insertions, 592 deletions
diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx
index 9208d83..2466355 100644
--- a/Source/cmMakefile.cxx
+++ b/Source/cmMakefile.cxx
@@ -141,7 +141,7 @@ void cmMakefile::Print() const
m_cmStartDirectory.c_str() << std::endl;
std::cout << " m_cmHomeDirectory; " <<
m_cmHomeDirectory.c_str() << std::endl;
- std::cout << " m_ProjectName; " << m_ProjectName.c_str() << std::endl;
+ std::cout << " m_ProjectName; " << m_ProjectName.c_str() << std::endl;
this->PrintStringVector("m_SubDirectories ", m_SubDirectories);
this->PrintStringVector("m_IncludeDirectories;", m_IncludeDirectories);
this->PrintStringVector("m_LinkDirectories", m_LinkDirectories);
@@ -193,12 +193,12 @@ void cmMakefile::ExecuteCommand(std::string const &name,
}
if(!usedCommand->InitialPass(expandedArguments))
{
- std::string error;
- error = usedCommand->GetName();
- error += ": Error : \n";
- error += usedCommand->GetError();
- error += " from CMakeLists.txt file in directory: ";
- error += m_cmCurrentDirectory;
+ std::string error;
+ error = usedCommand->GetName();
+ error += ": Error : \n";
+ error += usedCommand->GetError();
+ error += " from CMakeLists.txt file in directory: ";
+ error += m_cmCurrentDirectory;
cmSystemTools::Error(error.c_str());
}
else
@@ -271,27 +271,27 @@ bool cmMakefile::ReadListFile(const char* filename, const char* external)
// Home directory? if so recurse and read in that List file
std::string parentList = this->GetParentListFileName(filename);
if (parentList != "")
- {
- std::string srcdir = m_cmCurrentDirectory;
+ {
+ std::string srcdir = m_cmCurrentDirectory;
std::string bindir = m_CurrentOutputDirectory;
- std::string::size_type pos = parentList.rfind('/');
+ std::string::size_type pos = parentList.rfind('/');
m_cmCurrentDirectory = parentList.substr(0, pos);
- m_CurrentOutputDirectory = m_HomeOutputDirectory + parentList.substr(m_cmHomeDirectory.size(), pos - m_cmHomeDirectory.size());
+ m_CurrentOutputDirectory = m_HomeOutputDirectory + parentList.substr(m_cmHomeDirectory.size(), pos - m_cmHomeDirectory.size());
- // if not found, oops
- if(pos == std::string::npos)
- {
+ // if not found, oops
+ if(pos == std::string::npos)
+ {
cmSystemTools::Error("Trailing slash not found");
- }
+ }
- this->ReadListFile(parentList.c_str());
+ this->ReadListFile(parentList.c_str());
- // restore the current directory
- m_cmCurrentDirectory = srcdir;
- m_CurrentOutputDirectory = bindir;
- }
+ // restore the current directory
+ m_cmCurrentDirectory = srcdir;
+ m_CurrentOutputDirectory = bindir;
+ }
}
// are we at the start CMakeLists file or are we processing a parent
@@ -452,7 +452,7 @@ void cmMakefile::AddDefineFlag(const char* flag)
void cmMakefile::AddLinkLibrary(const char* lib, cmTarget::LinkLibraryType llt)
{
m_LinkLibraries.push_back(
- std::pair<std::string, cmTarget::LinkLibraryType>(lib,llt));
+ std::pair<std::string, cmTarget::LinkLibraryType>(lib,llt));
}
void cmMakefile::AddLinkLibraryForTarget(const char *target,
@@ -665,29 +665,29 @@ void cmMakefile::AddLibrary(const char* lname, int shared,
{
case 0:
this->GetCacheManager()->AddCacheEntry(ltname.c_str(),"STATIC",
- "Whether a library is static, shared or module.",
- cmCacheManager::INTERNAL);
+ "Whether a library is static, shared or module.",
+ cmCacheManager::INTERNAL);
break;
case 1:
this->GetCacheManager()->
- AddCacheEntry(ltname.c_str(),
- "SHARED",
- "Whether a library is static, shared or module.",
- cmCacheManager::INTERNAL);
+ AddCacheEntry(ltname.c_str(),
+ "SHARED",
+ "Whether a library is static, shared or module.",
+ cmCacheManager::INTERNAL);
break;
case 2:
this->GetCacheManager()->
- AddCacheEntry(ltname.c_str(),
- "MODULE",
- "Whether a library is static, shared or module.",
- cmCacheManager::INTERNAL);
+ AddCacheEntry(ltname.c_str(),
+ "MODULE",
+ "Whether a library is static, shared or module.",
+ cmCacheManager::INTERNAL);
break;
default:
this->GetCacheManager()->
- AddCacheEntry(ltname.c_str(),
- "STATIC",
- "Whether a library is static, shared or module.",
- cmCacheManager::INTERNAL);
+ AddCacheEntry(ltname.c_str(),
+ "STATIC",
+ "Whether a library is static, shared or module.",
+ cmCacheManager::INTERNAL);
}
}
@@ -752,6 +752,20 @@ void cmMakefile::AddUtilityCommand(const char* utilityName,
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)
{
@@ -762,9 +776,12 @@ void cmMakefile::AddSourceGroup(const char* name, const char* regex)
std::string sgName = sg->GetName();
if(sgName == name)
{
- // We only want to set the regular expression. If there are already
- // source files in the group, we don't want to remove them.
- sg->SetGroupRegex(regex);
+ if ( regex )
+ {
+ // We only want to set the regular expression. If there are already
+ // source files in the group, we don't want to remove them.
+ sg->SetGroupRegex(regex);
+ }
return;
}
}
@@ -1180,7 +1197,7 @@ bool cmMakefile::IsFunctionBlocked(const char *name,
}
void cmMakefile::RemoveFunctionBlocker(const char *name,
- const std::vector<std::string> &args)
+ const std::vector<std::string> &args)
{
// loop over all function blockers to see if any block this command
std::list<cmFunctionBlocker *>::reverse_iterator pos;
diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h
index 7664d9e..81c5298 100644
--- a/Source/cmMakefile.h
+++ b/Source/cmMakefile.h
@@ -239,7 +239,7 @@ public:
/**
* 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.
@@ -452,6 +452,11 @@ public:
{ return m_SourceGroups; }
/**
+ * Get the source group
+ */
+ cmSourceGroup* GetSourceGroup(const char* name);
+
+ /**
* Get the vector of list files on which this makefile depends
*/
const std::vector<std::string>& GetListFiles() const
@@ -488,7 +493,6 @@ public:
*/
cmSourceGroup& FindSourceGroup(const char* source,
std::vector<cmSourceGroup> &groups);
-
void RegisterData(cmData*);
void RegisterData(const char*, cmData*);
cmData* LookupData(const char*) const;
@@ -533,7 +537,7 @@ protected:
std::string m_HomeOutputDirectory;
std::string m_cmCurrentListFile;
- std::string m_ProjectName; // project name
+ std::string m_ProjectName; // project name
// libraries, classes, and executables
cmTargets m_Targets;
@@ -574,8 +578,8 @@ private:
std::string GetParentListFileName(const char *listFileName);
void ReadSources(std::ifstream& fin, bool t);
- friend class cmMakeDepend; // make depend needs direct access
- // to the m_Sources array
+ friend class cmMakeDepend; // make depend needs direct access
+ // to the m_Sources array
void PrintStringVector(const char* s, const std::vector<std::string>& v) const;
void AddDefaultDefinitions();
std::list<cmFunctionBlocker *> m_FunctionBlockers;
diff --git a/Source/cmRegularExpression.cxx b/Source/cmRegularExpression.cxx
index 52df30a..5b709cf 100644
--- a/Source/cmRegularExpression.cxx
+++ b/Source/cmRegularExpression.cxx
@@ -33,20 +33,25 @@
// Updated: DLS 03/22/91 New lite version
//
-#include "cmRegularExpression.h" // Include class specification
+#include "cmRegularExpression.h" // Include class specification
#include "cmStandardIncludes.h"
#include <stdio.h>
// cmRegularExpression -- Copies the given regular expression.
cmRegularExpression::cmRegularExpression (const cmRegularExpression& rxp) {
+ if ( !rxp.program )
+ {
+ this->program = 0;
+ return;
+ }
int ind;
- this->progsize = rxp.progsize; // Copy regular expression size
- this->program = new char[this->progsize]; // Allocate storage
- for(ind=this->progsize; ind-- != 0;) // Copy regular expresion
+ this->progsize = rxp.progsize; // Copy regular expression size
+ this->program = new char[this->progsize]; // Allocate storage
+ for(ind=this->progsize; ind-- != 0;) // Copy regular expresion
this->program[ind] = rxp.program[ind];
- this->startp[0] = rxp.startp[0]; // Copy pointers into last
- this->endp[0] = rxp.endp[0]; // Successful "find" operation
- this->regmust = rxp.regmust; // Copy field
+ this->startp[0] = rxp.startp[0]; // Copy pointers into last
+ this->endp[0] = rxp.endp[0]; // Successful "find" operation
+ this->regmust = rxp.regmust; // Copy field
if (rxp.regmust != 0) {
char* dum = rxp.program;
ind = 0;
@@ -56,23 +61,23 @@ cmRegularExpression::cmRegularExpression (const cmRegularExpression& rxp) {
}
this->regmust = this->program + ind;
}
- this->regstart = rxp.regstart; // Copy starting index
- this->reganch = rxp.reganch; // Copy remaining private data
- this->regmlen = rxp.regmlen; // Copy remaining private data
+ this->regstart = rxp.regstart; // Copy starting index
+ this->reganch = rxp.reganch; // Copy remaining private data
+ this->regmlen = rxp.regmlen; // Copy remaining private data
}
// operator== -- Returns true if two regular expressions have the same
// compiled program for pattern matching.
bool cmRegularExpression::operator== (const cmRegularExpression& rxp) const {
- if (this != &rxp) { // Same address?
- int ind = this->progsize; // Get regular expression size
- if (ind != rxp.progsize) // If different size regexp
- return false; // Return failure
- while(ind-- != 0) // Else while still characters
+ if (this != &rxp) { // Same address?
+ int ind = this->progsize; // Get regular expression size
+ if (ind != rxp.progsize) // If different size regexp
+ return false; // Return failure
+ while(ind-- != 0) // Else while still characters
if(this->program[ind] != rxp.program[ind]) // If regexp are different
- return false; // Return failure
+ return false; // Return failure
}
- return true; // Else same, return success
+ return true; // Else same, return success
}
@@ -80,14 +85,14 @@ bool cmRegularExpression::operator== (const cmRegularExpression& rxp) const {
// and the same start and end pointers.
bool cmRegularExpression::deep_equal (const cmRegularExpression& rxp) const {
- int ind = this->progsize; // Get regular expression size
- if (ind != rxp.progsize) // If different size regexp
- return false; // Return failure
- while(ind-- != 0) // Else while still characters
- if(this->program[ind] != rxp.program[ind]) // If regexp are different
- return false; // Return failure
- return (this->startp[0] == rxp.startp[0] && // Else if same start/end ptrs,
- this->endp[0] == rxp.endp[0]); // Return true
+ int ind = this->progsize; // Get regular expression size
+ if (ind != rxp.progsize) // If different size regexp
+ return false; // Return failure
+ while(ind-- != 0) // Else while still characters
+ if(this->program[ind] != rxp.program[ind]) // If regexp are different
+ return false; // Return failure
+ return (this->startp[0] == rxp.startp[0] && // Else if same start/end ptrs,
+ this->endp[0] == rxp.endp[0]); // Return true
}
// The remaining code in this file is derived from the regular expression code
@@ -97,22 +102,22 @@ bool cmRegularExpression::deep_equal (const cmRegularExpression& rxp) const {
/*
* compile and find
*
- * Copyright (c) 1986 by University of Toronto.
- * Written by Henry Spencer. Not derived from licensed software.
+ * Copyright (c) 1986 by University of Toronto.
+ * Written by Henry Spencer. Not derived from licensed software.
*
- * Permission is granted to anyone to use this software for any
- * purpose on any computer system, and to redistribute it freely,
- * subject to the following restrictions:
+ * Permission is granted to anyone to use this software for any
+ * purpose on any computer system, and to redistribute it freely,
+ * subject to the following restrictions:
*
- * 1. The author is not responsible for the consequences of use of
- * this software, no matter how awful, even if they arise
- * from defects in it.
+ * 1. The author is not responsible for the consequences of use of
+ * this software, no matter how awful, even if they arise
+ * from defects in it.
*
- * 2. The origin of this software must not be misrepresented, either
- * by explicit claim or by omission.
+ * 2. The origin of this software must not be misrepresented, either
+ * by explicit claim or by omission.
*
- * 3. Altered versions must be plainly marked as such, and must not
- * be misrepresented as being the original software.
+ * 3. Altered versions must be plainly marked as such, and must not
+ * be misrepresented as being the original software.
*
* Beware that some of this code is subtly aware of the way operator
* precedence is structured in regular expressions. Serious changes in
@@ -124,10 +129,10 @@ bool cmRegularExpression::deep_equal (const cmRegularExpression& rxp) const {
* compile to execute that permits the execute phase to run lots faster on
* simple cases. They are:
*
- * regstart char that must begin a match; '\0' if none obvious
- * reganch is the match anchored (at beginning-of-line only)?
- * regmust string (pointer into program) that match must include, or NULL
- * regmlen length of regmust string
+ * regstart char that must begin a match; '\0' if none obvious
+ * reganch is the match anchored (at beginning-of-line only)?
+ * regmust string (pointer into program) that match must include, or NULL
+ * regmlen length of regmust string
*
* Regstart and reganch permit very fast decisions on suitable starting points
* for a match, cutting down the work a lot. Regmust permits fast rejection
@@ -155,48 +160,48 @@ bool cmRegularExpression::deep_equal (const cmRegularExpression& rxp) const {
* to the thing following the set of BRANCHes.) The opcodes are:
*/
-// definition number opnd? meaning
-#define END 0 // no End of program.
-#define BOL 1 // no Match "" at beginning of line.
-#define EOL 2 // no Match "" at end of line.
-#define ANY 3 // no Match any one character.
-#define ANYOF 4 // str Match any character in this string.
-#define ANYBUT 5 // str Match any character not in this
- // string.
-#define BRANCH 6 // node Match this alternative, or the
- // next...
-#define BACK 7 // no Match "", "next" ptr points backward.
-#define EXACTLY 8 // str Match this string.
-#define NOTHING 9 // no Match empty string.
-#define STAR 10 // node Match this (simple) thing 0 or more
- // times.
-#define PLUS 11 // node Match this (simple) thing 1 or more
- // times.
-#define OPEN 20 // no Mark this point in input as start of
- // #n.
+// definition number opnd? meaning
+#define END 0 // no End of program.
+#define BOL 1 // no Match "" at beginning of line.
+#define EOL 2 // no Match "" at end of line.
+#define ANY 3 // no Match any one character.
+#define ANYOF 4 // str Match any character in this string.
+#define ANYBUT 5 // str Match any character not in this
+ // string.
+#define BRANCH 6 // node Match this alternative, or the
+ // next...
+#define BACK 7 // no Match "", "next" ptr points backward.
+#define EXACTLY 8 // str Match this string.
+#define NOTHING 9 // no Match empty string.
+#define STAR 10 // node Match this (simple) thing 0 or more
+ // times.
+#define PLUS 11 // node Match this (simple) thing 1 or more
+ // times.
+#define OPEN 20 // no Mark this point in input as start of
+ // #n.
// OPEN+1 is number 1, etc.
-#define CLOSE 30 // no Analogous to OPEN.
+#define CLOSE 30 // no Analogous to OPEN.
/*
* Opcode notes:
*
- * BRANCH The set of branches constituting a single choice are hooked
- * together with their "next" pointers, since precedence prevents
- * anything being concatenated to any individual branch. The
- * "next" pointer of the last BRANCH in a choice points to the
- * thing following the whole choice. This is also where the
- * final "next" pointer of each individual branch points; each
- * branch starts with the operand node of a BRANCH node.
+ * BRANCH The set of branches constituting a single choice are hooked
+ * together with their "next" pointers, since precedence prevents
+ * anything being concatenated to any individual branch. The
+ * "next" pointer of the last BRANCH in a choice points to the
+ * thing following the whole choice. This is also where the
+ * final "next" pointer of each individual branch points; each
+ * branch starts with the operand node of a BRANCH node.
*
- * BACK Normal "next" pointers all implicitly point forward; BACK
- * exists to make loop structures possible.
+ * BACK Normal "next" pointers all implicitly point forward; BACK
+ * exists to make loop structures possible.
*
- * STAR,PLUS '?', and complex '*' and '+', are implemented as circular
- * BRANCH structures using BACK. Simple cases (one character
- * per match) are implemented with STAR and PLUS for speed
- * and to minimize recursive plunges.
+ * STAR,PLUS '?', and complex '*' and '+', are implemented as circular
+ * BRANCH structures using BACK. Simple cases (one character
+ * per match) are implemented with STAR and PLUS for speed
+ * and to minimize recursive plunges.
*
- * OPEN,CLOSE ...are numbered at compile time.
+ * OPEN,CLOSE ...are numbered at compile time.
*/
/*
@@ -210,30 +215,30 @@ bool cmRegularExpression::deep_equal (const cmRegularExpression& rxp) const {
* but allows patterns to get big without disasters.
*/
-#define OP(p) (*(p))
-#define NEXT(p) (((*((p)+1)&0377)<<8) + (*((p)+2)&0377))
-#define OPERAND(p) ((p) + 3)
+#define OP(p) (*(p))
+#define NEXT(p) (((*((p)+1)&0377)<<8) + (*((p)+2)&0377))
+#define OPERAND(p) ((p) + 3)
const unsigned char MAGIC = 0234;
/*
* Utility definitions.
*/
-#define UCHARAT(p) ((const unsigned char*)(p))[0]
+#define UCHARAT(p) ((const unsigned char*)(p))[0]
-#define FAIL(m) { regerror(m); return(0); }
-#define ISMULT(c) ((c) == '*' || (c) == '+' || (c) == '?')
-#define META "^$.[()|?+*\\"
+#define FAIL(m) { regerror(m); return(0); }
+#define ISMULT(c) ((c) == '*' || (c) == '+' || (c) == '?')
+#define META "^$.[()|?+*\\"
/*
* Flags to be passed up and down.
*/
-#define HASWIDTH 01 // Known never to match null string.
-#define SIMPLE 02 // Simple enough to be STAR/PLUS operand.
-#define SPSTART 04 // Starts with * or +.
-#define WORST 0 // Worst case.
+#define HASWIDTH 01 // Known never to match null string.
+#define SIMPLE 02 // Simple enough to be STAR/PLUS operand.
+#define SPSTART 04 // Starts with * or +.
+#define WORST 0 // Worst case.
@@ -247,17 +252,17 @@ const unsigned char MAGIC = 0234;
/*
* Global work variables for compile().
*/
-static const char* regparse; // Input-scan pointer.
-static int regnpar; // () count.
+static const char* regparse; // Input-scan pointer.
+static int regnpar; // () count.
static char regdummy;
-static char* regcode; // Code-emit pointer; &regdummy = don't.
-static long regsize; // Code size.
+static char* regcode; // Code-emit pointer; &regdummy = don't.
+static long regsize; // Code size.
/*
* Forward declarations for compile()'s friends.
*/
// #ifndef static
-// #define static static
+// #define static static
// #endif
static char* reg (int, int*);
static char* regbranch (int*);
@@ -315,13 +320,13 @@ void cmRegularExpression::compile (const char* exp) {
regc(MAGIC);
if(!reg(0, &flags))
{
- printf ("cmRegularExpression::compile(): Error in compile.\n");
- return;
+ printf ("cmRegularExpression::compile(): Error in compile.\n");
+ return;
}
this->startp[0] = this->endp[0] = this->searchstring = 0;
// Small enough for pointer-storage convention?
- if (regsize >= 32767L) { // Probably could be 65535L.
+ if (regsize >= 32767L) { // Probably could be 65535L.
//RAISE Error, SYM(cmRegularExpression), SYM(Expr_Too_Big),
printf ("cmRegularExpression::compile(): Expression too big.\n");
return;
@@ -348,39 +353,39 @@ void cmRegularExpression::compile (const char* exp) {
reg(0, &flags);
// Dig out information for optimizations.
- this->regstart = '\0'; // Worst-case defaults.
+ this->regstart = '\0'; // Worst-case defaults.
this->reganch = 0;
this->regmust = 0;
this->regmlen = 0;
- scan = this->program + 1; // First BRANCH.
- if (OP(regnext(scan)) == END) { // Only one top-level choice.
- scan = OPERAND(scan);
-
- // Starting-point info.
- if (OP(scan) == EXACTLY)
- this->regstart = *OPERAND(scan);
- else if (OP(scan) == BOL)
- this->reganch++;
-
- //
- // If there's something expensive in the r.e., find the longest
- // literal string that must appear and make it the regmust. Resolve
- // ties in favor of later strings, since the regstart check works
- // with the beginning of the r.e. and avoiding duplication
- // strengthens checking. Not a strong reason, but sufficient in the
- // absence of others.
- //
- if (flags & SPSTART) {
- longest = 0;
- len = 0;
- for (; scan != 0; scan = regnext(scan))
- if (OP(scan) == EXACTLY && strlen(OPERAND(scan)) >= len) {
- longest = OPERAND(scan);
- len = int(strlen(OPERAND(scan)));
- }
- this->regmust = longest;
- this->regmlen = len;
- }
+ scan = this->program + 1; // First BRANCH.
+ if (OP(regnext(scan)) == END) { // Only one top-level choice.
+ scan = OPERAND(scan);
+
+ // Starting-point info.
+ if (OP(scan) == EXACTLY)
+ this->regstart = *OPERAND(scan);
+ else if (OP(scan) == BOL)
+ this->reganch++;
+
+ //
+ // If there's something expensive in the r.e., find the longest
+ // literal string that must appear and make it the regmust. Resolve
+ // ties in favor of later strings, since the regstart check works
+ // with the beginning of the r.e. and avoiding duplication
+ // strengthens checking. Not a strong reason, but sufficient in the
+ // absence of others.
+ //
+ if (flags & SPSTART) {
+ longest = 0;
+ len = 0;
+ for (; scan != 0; scan = regnext(scan))
+ if (OP(scan) == EXACTLY && strlen(OPERAND(scan)) >= len) {
+ longest = OPERAND(scan);
+ len = int(strlen(OPERAND(scan)));
+ }
+ this->regmust = longest;
+ this->regmlen = len;
+ }
}
}
@@ -401,42 +406,42 @@ static char* reg (int paren, int *flagp) {
register int parno =0;
int flags;
- *flagp = HASWIDTH; // Tentatively.
+ *flagp = HASWIDTH; // Tentatively.
// Make an OPEN node, if parenthesized.
if (paren) {
- if (regnpar >= NSUBEXP) {
- //RAISE Error, SYM(cmRegularExpression), SYM(Too_Many_Parens),
- printf ("cmRegularExpression::compile(): Too many parentheses.\n");
- return 0;
+ if (regnpar >= NSUBEXP) {
+ //RAISE Error, SYM(cmRegularExpression), SYM(Too_Many_Parens),
+ printf ("cmRegularExpression::compile(): Too many parentheses.\n");
+ return 0;
}
- parno = regnpar;
- regnpar++;
- ret = regnode(OPEN + parno);
+ parno = regnpar;
+ regnpar++;
+ ret = regnode(OPEN + parno);
}
else
- ret = 0;
+ ret = 0;
// Pick up the branches, linking them together.
br = regbranch(&flags);
if (br == 0)
- return (0);
+ return (0);
if (ret != 0)
- regtail(ret, br); // OPEN -> first.
+ regtail(ret, br); // OPEN -> first.
else
- ret = br;
+ ret = br;
if (!(flags & HASWIDTH))
- *flagp &= ~HASWIDTH;
+ *flagp &= ~HASWIDTH;
*flagp |= flags & SPSTART;
while (*regparse == '|') {
- regparse++;
- br = regbranch(&flags);
- if (br == 0)
- return (0);
- regtail(ret, br); // BRANCH -> BRANCH.
- if (!(flags & HASWIDTH))
- *flagp &= ~HASWIDTH;
- *flagp |= flags & SPSTART;
+ regparse++;
+ br = regbranch(&flags);
+ if (br == 0)
+ return (0);
+ regtail(ret, br); // BRANCH -> BRANCH.
+ if (!(flags & HASWIDTH))
+ *flagp &= ~HASWIDTH;
+ *flagp |= flags & SPSTART;
}
// Make a closing node, and hook it on the end.
@@ -445,26 +450,26 @@ static char* reg (int paren, int *flagp) {
// Hook the tails of the branches to the closing node.
for (br = ret; br != 0; br = regnext(br))
- regoptail(br, ender);
+ regoptail(br, ender);
// Check for proper termination.
if (paren && *regparse++ != ')') {
//RAISE Error, SYM(cmRegularExpression), SYM(Unmatched_Parens),
printf ("cmRegularExpression::compile(): Unmatched parentheses.\n");
- return 0;
+ return 0;
}
else if (!paren && *regparse != '\0') {
if (*regparse == ')') {
//RAISE Error, SYM(cmRegularExpression), SYM(Unmatched_Parens),
printf ("cmRegularExpression::compile(): Unmatched parentheses.\n");
- return 0;
- }
- else {
- //RAISE Error, SYM(cmRegularExpression), SYM(Internal_Error),
- printf ("cmRegularExpression::compile(): Internal error.\n");
- return 0;
+ return 0;
}
- // NOTREACHED
+ else {
+ //RAISE Error, SYM(cmRegularExpression), SYM(Internal_Error),
+ printf ("cmRegularExpression::compile(): Internal error.\n");
+ return 0;
+ }
+ // NOTREACHED
}
return (ret);
}
@@ -481,23 +486,23 @@ static char* regbranch (int *flagp) {
register char* latest;
int flags;
- *flagp = WORST; // Tentatively.
+ *flagp = WORST; // Tentatively.
ret = regnode(BRANCH);
chain = 0;
while (*regparse != '\0' && *regparse != '|' && *regparse != ')') {
- latest = regpiece(&flags);
- if (latest == 0)
- return (0);
- *flagp |= flags & HASWIDTH;
- if (chain == 0) // First piece.
- *flagp |= flags & SPSTART;
- else
- regtail(chain, latest);
- chain = latest;
+ latest = regpiece(&flags);
+ if (latest == 0)
+ return (0);
+ *flagp |= flags & HASWIDTH;
+ if (chain == 0) // First piece.
+ *flagp |= flags & SPSTART;
+ else
+ regtail(chain, latest);
+ chain = latest;
}
- if (chain == 0) // Loop ran zero times.
- regnode(NOTHING);
+ if (chain == 0) // Loop ran zero times.
+ regnode(NOTHING);
return (ret);
}
@@ -520,54 +525,54 @@ static char* regpiece (int *flagp) {
ret = regatom(&flags);
if (ret == 0)
- return (0);
+ return (0);
op = *regparse;
if (!ISMULT(op)) {
- *flagp = flags;
- return (ret);
+ *flagp = flags;
+ return (ret);
}
if (!(flags & HASWIDTH) && op != '?') {
//RAISE Error, SYM(cmRegularExpression), SYM(Empty_Operand),
printf ("cmRegularExpression::compile() : *+ operand could be empty.\n");
- return 0;
+ return 0;
}
*flagp = (op != '+') ? (WORST | SPSTART) : (WORST | HASWIDTH);
if (op == '*' && (flags & SIMPLE))
- reginsert(STAR, ret);
+ reginsert(STAR, ret);
else if (op == '*') {
- // Emit x* as (x&|), where & means "self".
- reginsert(BRANCH, ret); // Either x
- regoptail(ret, regnode(BACK)); // and loop
- regoptail(ret, ret); // back
- regtail(ret, regnode(BRANCH)); // or
- regtail(ret, regnode(NOTHING)); // null.
+ // Emit x* as (x&|), where & means "self".
+ reginsert(BRANCH, ret); // Either x
+ regoptail(ret, regnode(BACK)); // and loop
+ regoptail(ret, ret); // back
+ regtail(ret, regnode(BRANCH)); // or
+ regtail(ret, regnode(NOTHING)); // null.
}
else if (op == '+' && (flags & SIMPLE))
- reginsert(PLUS, ret);
+ reginsert(PLUS, ret);
else if (op == '+') {
- // Emit x+ as x(&|), where & means "self".
- next = regnode(BRANCH); // Either
- regtail(ret, next);
- regtail(regnode(BACK), ret); // loop back
- regtail(next, regnode(BRANCH)); // or
- regtail(ret, regnode(NOTHING)); // null.
+ // Emit x+ as x(&|), where & means "self".
+ next = regnode(BRANCH); // Either
+ regtail(ret, next);
+ regtail(regnode(BACK), ret); // loop back
+ regtail(next, regnode(BRANCH)); // or
+ regtail(ret, regnode(NOTHING)); // null.
}
else if (op == '?') {
- // Emit x? as (x|)
- reginsert(BRANCH, ret); // Either x
- regtail(ret, regnode(BRANCH)); // or
- next = regnode(NOTHING);// null.
- regtail(ret, next);
- regoptail(ret, next);
+ // Emit x? as (x|)
+ reginsert(BRANCH, ret); // Either x
+ regtail(ret, regnode(BRANCH)); // or
+ next = regnode(NOTHING);// null.
+ regtail(ret, next);
+ regoptail(ret, next);
}
regparse++;
if (ISMULT(*regparse)) {
//RAISE Error, SYM(cmRegularExpression), SYM(Nested_Operand),
printf ("cmRegularExpression::compile(): Nested *?+.\n");
- return 0;
+ return 0;
}
return (ret);
}
@@ -585,116 +590,116 @@ static char* regatom (int *flagp) {
register char* ret;
int flags;
- *flagp = WORST; // Tentatively.
+ *flagp = WORST; // Tentatively.
switch (*regparse++) {
- case '^':
- ret = regnode(BOL);
- break;
- case '$':
- ret = regnode(EOL);
- break;
- case '.':
- ret = regnode(ANY);
- *flagp |= HASWIDTH | SIMPLE;
- break;
- case '[':{
- register int rxpclass;
- register int rxpclassend;
-
- if (*regparse == '^') { // Complement of range.
- ret = regnode(ANYBUT);
- regparse++;
- }
- else
- ret = regnode(ANYOF);
- if (*regparse == ']' || *regparse == '-')
- regc(*regparse++);
- while (*regparse != '\0' && *regparse != ']') {
- if (*regparse == '-') {
- regparse++;
- if (*regparse == ']' || *regparse == '\0')
- regc('-');
- else {
- rxpclass = UCHARAT(regparse - 2) + 1;
- rxpclassend = UCHARAT(regparse);
- if (rxpclass > rxpclassend + 1) {
- //RAISE Error, SYM(cmRegularExpression), SYM(Invalid_Range),
- printf ("cmRegularExpression::compile(): Invalid range in [].\n");
- return 0;
+ case '^':
+ ret = regnode(BOL);
+ break;
+ case '$':
+ ret = regnode(EOL);
+ break;
+ case '.':
+ ret = regnode(ANY);
+ *flagp |= HASWIDTH | SIMPLE;
+ break;
+ case '[':{
+ register int rxpclass;
+ register int rxpclassend;
+
+ if (*regparse == '^') { // Complement of range.
+ ret = regnode(ANYBUT);
+ regparse++;
+ }
+ else
+ ret = regnode(ANYOF);
+ if (*regparse == ']' || *regparse == '-')
+ regc(*regparse++);
+ while (*regparse != '\0' && *regparse != ']') {
+ if (*regparse == '-') {
+ regparse++;
+ if (*regparse == ']' || *regparse == '\0')
+ regc('-');
+ else {
+ rxpclass = UCHARAT(regparse - 2) + 1;
+ rxpclassend = UCHARAT(regparse);
+ if (rxpclass > rxpclassend + 1) {
+ //RAISE Error, SYM(cmRegularExpression), SYM(Invalid_Range),
+ printf ("cmRegularExpression::compile(): Invalid range in [].\n");
+ return 0;
}
- for (; rxpclass <= rxpclassend; rxpclass++)
- regc(rxpclass);
- regparse++;
- }
- }
- else
- regc(*regparse++);
- }
- regc('\0');
- if (*regparse != ']') {
+ for (; rxpclass <= rxpclassend; rxpclass++)
+ regc(rxpclass);
+ regparse++;
+ }
+ }
+ else
+ regc(*regparse++);
+ }
+ regc('\0');
+ if (*regparse != ']') {
//RAISE Error, SYM(cmRegularExpression), SYM(Unmatched_Bracket),
printf ("cmRegularExpression::compile(): Unmatched [].\n");
- return 0;
- }
- regparse++;
- *flagp |= HASWIDTH | SIMPLE;
- }
- break;
- case '(':
- ret = reg(1, &flags);
- if (ret == 0)
- return (0);
- *flagp |= flags & (HASWIDTH | SPSTART);
- break;
- case '\0':
- case '|':
- case ')':
- //RAISE Error, SYM(cmRegularExpression), SYM(Internal_Error),
+ return 0;
+ }
+ regparse++;
+ *flagp |= HASWIDTH | SIMPLE;
+ }
+ break;
+ case '(':
+ ret = reg(1, &flags);
+ if (ret == 0)
+ return (0);
+ *flagp |= flags & (HASWIDTH | SPSTART);
+ break;
+ case '\0':
+ case '|':
+ case ')':
+ //RAISE Error, SYM(cmRegularExpression), SYM(Internal_Error),
printf ("cmRegularExpression::compile(): Internal error.\n"); // Never here
- return 0;
- case '?':
- case '+':
- case '*':
- //RAISE Error, SYM(cmRegularExpression), SYM(No_Operand),
+ return 0;
+ case '?':
+ case '+':
+ case '*':
+ //RAISE Error, SYM(cmRegularExpression), SYM(No_Operand),
printf ("cmRegularExpression::compile(): ?+* follows nothing.\n");
- return 0;
- case '\\':
- if (*regparse == '\0') {
- //RAISE Error, SYM(cmRegularExpression), SYM(Trailing_Backslash),
+ return 0;
+ case '\\':
+ if (*regparse == '\0') {
+ //RAISE Error, SYM(cmRegularExpression), SYM(Trailing_Backslash),
printf ("cmRegularExpression::compile(): Trailing backslash.\n");
- return 0;
+ return 0;
}
- ret = regnode(EXACTLY);
- regc(*regparse++);
- regc('\0');
- *flagp |= HASWIDTH | SIMPLE;
- break;
- default:{
- register int len;
- register char ender;
-
- regparse--;
- len = int(strcspn(regparse, META));
- if (len <= 0) {
- //RAISE Error, SYM(cmRegularExpression), SYM(Internal_Error),
+ ret = regnode(EXACTLY);
+ regc(*regparse++);
+ regc('\0');
+ *flagp |= HASWIDTH | SIMPLE;
+ break;
+ default:{
+ register int len;
+ register char ender;
+
+ regparse--;
+ len = int(strcspn(regparse, META));
+ if (len <= 0) {
+ //RAISE Error, SYM(cmRegularExpression), SYM(Internal_Error),
printf ("cmRegularExpression::compile(): Internal error.\n");
- return 0;
+ return 0;
}
- ender = *(regparse + len);
- if (len > 1 && ISMULT(ender))
- len--; // Back off clear of ?+* operand.
- *flagp |= HASWIDTH;
- if (len == 1)
- *flagp |= SIMPLE;
- ret = regnode(EXACTLY);
- while (len > 0) {
- regc(*regparse++);
- len--;
- }
- regc('\0');
- }
- break;
+ ender = *(regparse + len);
+ if (len > 1 && ISMULT(ender))
+ len--; // Back off clear of ?+* operand.
+ *flagp |= HASWIDTH;
+ if (len == 1)
+ *flagp |= SIMPLE;
+ ret = regnode(EXACTLY);
+ while (len > 0) {
+ regc(*regparse++);
+ len--;
+ }
+ regc('\0');
+ }
+ break;
}
return (ret);
}
@@ -710,13 +715,13 @@ static char* regnode (char op) {
ret = regcode;
if (ret == &regdummy) {
- regsize += 3;
- return (ret);
+ regsize += 3;
+ return (ret);
}
ptr = ret;
*ptr++ = op;
- *ptr++ = '\0'; // Null "next" pointer.
+ *ptr++ = '\0'; // Null "next" pointer.
*ptr++ = '\0';
regcode = ptr;
@@ -729,9 +734,9 @@ static char* regnode (char op) {
*/
static void regc (unsigned char b) {
if (regcode != &regdummy)
- *regcode++ = b;
+ *regcode++ = b;
else
- regsize++;
+ regsize++;
}
@@ -746,17 +751,17 @@ static void reginsert (char op, char* opnd) {
register char* place;
if (regcode == &regdummy) {
- regsize += 3;
- return;
+ regsize += 3;
+ return;
}
src = regcode;
regcode += 3;
dst = regcode;
while (src > opnd)
- *--dst = *--src;
+ *--dst = *--src;
- place = opnd; // Op node, where operand used to be.
+ place = opnd; // Op node, where operand used to be.
*place++ = op;
*place++ = '\0';
*place++ = '\0';
@@ -772,21 +777,21 @@ static void regtail (char* p, const char* val) {
register int offset;
if (p == &regdummy)
- return;
+ return;
// Find last node.
scan = p;
for (;;) {
- temp = regnext(scan);
- if (temp == 0)
- break;
- scan = temp;
+ temp = regnext(scan);
+ if (temp == 0)
+ break;
+ scan = temp;
}
if (OP(scan) == BACK)
- offset = int(scan - val);
+ offset = int(scan - val);
else
- offset = int(val - scan);
+ offset = int(val - scan);
*(scan + 1) = (offset >> 8) & 0377;
*(scan + 2) = offset & 0377;
}
@@ -798,7 +803,7 @@ static void regtail (char* p, const char* val) {
static void regoptail (char* p, const char* val) {
// "Operandless" and "op != BRANCH" are synonymous in practice.
if (p == 0 || p == &regdummy || OP(p) != BRANCH)
- return;
+ return;
regtail(OPERAND(p), val);
}
@@ -814,16 +819,16 @@ static void regoptail (char* p, const char* val) {
/*
* Global work variables for find().
*/
-static const char* reginput; // String-input pointer.
-static const char* regbol; // Beginning of input, for ^ check.
-static const char* *regstartp; // Pointer to startp array.
-static const char* *regendp; // Ditto for endp.
+static const char* reginput; // String-input pointer.
+static const char* regbol; // Beginning of input, for ^ check.
+static const char* *regstartp; // Pointer to startp array.
+static const char* *regendp; // Ditto for endp.
/*
* Forwards.
*/
static int regtry (const char*, const char* *,
- const char* *, const char*);
+ const char* *, const char*);
static int regmatch (const char*);
static int regrepeat (const char*);
@@ -848,8 +853,13 @@ bool cmRegularExpression::find (const char* string) {
this->searchstring = string;
- // Check validity of program.
- if (!this->program || UCHARAT(this->program) != MAGIC) {
+ if (!this->program)
+ {
+ return false;
+ }
+
+ // Check validity of program.
+ if (UCHARAT(this->program) != MAGIC) {
//RAISE Error, SYM(cmRegularExpression), SYM(Internal_Error),
printf ("cmRegularExpression::find(): Compiled regular expression corrupted.\n");
return 0;
@@ -857,14 +867,14 @@ bool cmRegularExpression::find (const char* string) {
// If there is a "must appear" string, look for it.
if (this->regmust != 0) {
- s = string;
- while ((s = strchr(s, this->regmust[0])) != 0) {
- if (strncmp(s, this->regmust, this->regmlen) == 0)
- break; // Found it.
- s++;
- }
- if (s == 0) // Not present.
- return (0);
+ s = string;
+ while ((s = strchr(s, this->regmust[0])) != 0) {
+ if (strncmp(s, this->regmust, this->regmlen) == 0)
+ break; // Found it.
+ s++;
+ }
+ if (s == 0) // Not present.
+ return (0);
}
// Mark beginning of line for ^ .
@@ -872,24 +882,24 @@ bool cmRegularExpression::find (const char* string) {
// Simplest case: anchored match need be tried only once.
if (this->reganch)
- return (regtry(string, this->startp, this->endp, this->program) != 0);
+ return (regtry(string, this->startp, this->endp, this->program) != 0);
// Messy cases: unanchored match.
s = string;
if (this->regstart != '\0')
- // We know what char it must start with.
- while ((s = strchr(s, this->regstart)) != 0) {
- if (regtry(s, this->startp, this->endp, this->program))
- return (1);
- s++;
-
- }
+ // We know what char it must start with.
+ while ((s = strchr(s, this->regstart)) != 0) {
+ if (regtry(s, this->startp, this->endp, this->program))
+ return (1);
+ s++;
+
+ }
else
- // We don't -- general case.
- do {
- if (regtry(s, this->startp, this->endp, this->program))
- return (1);
- } while (*s++ != '\0');
+ // We don't -- general case.
+ do {
+ if (regtry(s, this->startp, this->endp, this->program))
+ return (1);
+ } while (*s++ != '\0');
// Failure.
return (0);
@@ -901,7 +911,7 @@ bool cmRegularExpression::find (const char* string) {
0 failure, 1 success
*/
static int regtry (const char* string, const char* *start,
- const char* *end, const char* prog) {
+ const char* *end, const char* prog) {
register int i;
register const char* *sp1;
register const char* *ep;
@@ -913,16 +923,16 @@ static int regtry (const char* string, const char* *start,
sp1 = start;
ep = end;
for (i = NSUBEXP; i > 0; i--) {
- *sp1++ = 0;
- *ep++ = 0;
+ *sp1++ = 0;
+ *ep++ = 0;
}
if (regmatch(prog + 1)) {
- start[0] = string;
- end[0] = reginput;
- return (1);
+ start[0] = string;
+ end[0] = reginput;
+ return (1);
}
else
- return (0);
+ return (0);
}
@@ -938,172 +948,172 @@ static int regtry (const char* string, const char* *start,
* 0 failure, 1 success
*/
static int regmatch (const char* prog) {
- register const char* scan; // Current node.
- const char* next; // Next node.
+ register const char* scan; // Current node.
+ const char* next; // Next node.
scan = prog;
while (scan != 0) {
- next = regnext(scan);
-
- switch (OP(scan)) {
- case BOL:
- if (reginput != regbol)
- return (0);
- break;
- case EOL:
- if (*reginput != '\0')
- return (0);
- break;
- case ANY:
- if (*reginput == '\0')
- return (0);
- reginput++;
- break;
- case EXACTLY:{
- register int len;
- register const char* opnd;
-
- opnd = OPERAND(scan);
- // Inline the first character, for speed.
- if (*opnd != *reginput)
- return (0);
- len = int(strlen(opnd));
- if (len > 1 && strncmp(opnd, reginput, len) != 0)
- return (0);
- reginput += len;
- }
- break;
- case ANYOF:
- if (*reginput == '\0' || strchr(OPERAND(scan), *reginput) == 0)
- return (0);
- reginput++;
- break;
- case ANYBUT:
- if (*reginput == '\0' || strchr(OPERAND(scan), *reginput) != 0)
- return (0);
- reginput++;
- break;
- case NOTHING:
- break;
- case BACK:
- break;
- case OPEN + 1:
- case OPEN + 2:
- case OPEN + 3:
- case OPEN + 4:
- case OPEN + 5:
- case OPEN + 6:
- case OPEN + 7:
- case OPEN + 8:
- case OPEN + 9:{
- register int no;
- register const char* save;
-
- no = OP(scan) - OPEN;
- save = reginput;
-
- if (regmatch(next)) {
-
- //
- // Don't set startp if some later invocation of the
- // same parentheses already has.
- //
- if (regstartp[no] == 0)
- regstartp[no] = save;
- return (1);
- }
- else
- return (0);
- }
-// break;
- case CLOSE + 1:
- case CLOSE + 2:
- case CLOSE + 3:
- case CLOSE + 4:
- case CLOSE + 5:
- case CLOSE + 6:
- case CLOSE + 7:
- case CLOSE + 8:
- case CLOSE + 9:{
- register int no;
- register const char* save;
-
- no = OP(scan) - CLOSE;
- save = reginput;
-
- if (regmatch(next)) {
-
- //
- // Don't set endp if some later invocation of the
- // same parentheses already has.
- //
- if (regendp[no] == 0)
- regendp[no] = save;
- return (1);
- }
- else
- return (0);
- }
-// break;
- case BRANCH:{
-
- register const char* save;
-
- if (OP(next) != BRANCH) // No choice.
- next = OPERAND(scan); // Avoid recursion.
- else {
- do {
- save = reginput;
- if (regmatch(OPERAND(scan)))
- return (1);
- reginput = save;
- scan = regnext(scan);
- } while (scan != 0 && OP(scan) == BRANCH);
- return (0);
- // NOTREACHED
- }
- }
- break;
- case STAR:
- case PLUS:{
- register char nextch;
- register int no;
- register const char* save;
- register int min_no;
-
- //
- // Lookahead to avoid useless match attempts when we know
- // what character comes next.
- //
- nextch = '\0';
- if (OP(next) == EXACTLY)
- nextch = *OPERAND(next);
- min_no = (OP(scan) == STAR) ? 0 : 1;
- save = reginput;
- no = regrepeat(OPERAND(scan));
- while (no >= min_no) {
- // If it could work, try it.
- if (nextch == '\0' || *reginput == nextch)
- if (regmatch(next))
- return (1);
- // Couldn't or didn't -- back up.
- no--;
- reginput = save + no;
- }
- return (0);
- }
-// break;
- case END:
- return (1); // Success!
-
- default:
- //RAISE Error, SYM(cmRegularExpression), SYM(Internal_Error),
+ next = regnext(scan);
+
+ switch (OP(scan)) {
+ case BOL:
+ if (reginput != regbol)
+ return (0);
+ break;
+ case EOL:
+ if (*reginput != '\0')
+ return (0);
+ break;
+ case ANY:
+ if (*reginput == '\0')
+ return (0);
+ reginput++;
+ break;
+ case EXACTLY:{
+ register int len;
+ register const char* opnd;
+
+ opnd = OPERAND(scan);
+ // Inline the first character, for speed.
+ if (*opnd != *reginput)
+ return (0);
+ len = int(strlen(opnd));
+ if (len > 1 && strncmp(opnd, reginput, len) != 0)
+ return (0);
+ reginput += len;
+ }
+ break;
+ case ANYOF:
+ if (*reginput == '\0' || strchr(OPERAND(scan), *reginput) == 0)
+ return (0);
+ reginput++;
+ break;
+ case ANYBUT:
+ if (*reginput == '\0' || strchr(OPERAND(scan), *reginput) != 0)
+ return (0);
+ reginput++;
+ break;
+ case NOTHING:
+ break;
+ case BACK:
+ break;
+ case OPEN + 1:
+ case OPEN + 2:
+ case OPEN + 3:
+ case OPEN + 4:
+ case OPEN + 5:
+ case OPEN + 6:
+ case OPEN + 7:
+ case OPEN + 8:
+ case OPEN + 9:{
+ register int no;
+ register const char* save;
+
+ no = OP(scan) - OPEN;
+ save = reginput;
+
+ if (regmatch(next)) {
+
+ //
+ // Don't set startp if some later invocation of the
+ // same parentheses already has.
+ //
+ if (regstartp[no] == 0)
+ regstartp[no] = save;
+ return (1);
+ }
+ else
+ return (0);
+ }
+// break;
+ case CLOSE + 1:
+ case CLOSE + 2:
+ case CLOSE + 3:
+ case CLOSE + 4:
+ case CLOSE + 5:
+ case CLOSE + 6:
+ case CLOSE + 7:
+ case CLOSE + 8:
+ case CLOSE + 9:{
+ register int no;
+ register const char* save;
+
+ no = OP(scan) - CLOSE;
+ save = reginput;
+
+ if (regmatch(next)) {
+
+ //
+ // Don't set endp if some later invocation of the
+ // same parentheses already has.
+ //
+ if (regendp[no] == 0)
+ regendp[no] = save;
+ return (1);
+ }
+ else
+ return (0);
+ }
+// break;
+ case BRANCH:{
+
+ register const char* save;
+
+ if (OP(next) != BRANCH) // No choice.
+ next = OPERAND(scan); // Avoid recursion.
+ else {
+ do {
+ save = reginput;
+ if (regmatch(OPERAND(scan)))
+ return (1);
+ reginput = save;
+ scan = regnext(scan);
+ } while (scan != 0 && OP(scan) == BRANCH);
+ return (0);
+ // NOTREACHED
+ }
+ }
+ break;
+ case STAR:
+ case PLUS:{
+ register char nextch;
+ register int no;
+ register const char* save;
+ register int min_no;
+
+ //
+ // Lookahead to avoid useless match attempts when we know
+ // what character comes next.
+ //
+ nextch = '\0';
+ if (OP(next) == EXACTLY)
+ nextch = *OPERAND(next);
+ min_no = (OP(scan) == STAR) ? 0 : 1;
+ save = reginput;
+ no = regrepeat(OPERAND(scan));
+ while (no >= min_no) {
+ // If it could work, try it.
+ if (nextch == '\0' || *reginput == nextch)
+ if (regmatch(next))
+ return (1);
+ // Couldn't or didn't -- back up.
+ no--;
+ reginput = save + no;
+ }
+ return (0);
+ }
+// break;
+ case END:
+ return (1); // Success!
+
+ default:
+ //RAISE Error, SYM(cmRegularExpression), SYM(Internal_Error),
printf ("cmRegularExpression::find(): Internal error -- memory corrupted.\n");
- return 0;
- }
- scan = next;
+ return 0;
+ }
+ scan = next;
}
//
@@ -1127,32 +1137,32 @@ static int regrepeat (const char* p) {
scan = reginput;
opnd = OPERAND(p);
switch (OP(p)) {
- case ANY:
- count = int(strlen(scan));
- scan += count;
- break;
- case EXACTLY:
- while (*opnd == *scan) {
- count++;
- scan++;
- }
- break;
- case ANYOF:
- while (*scan != '\0' && strchr(opnd, *scan) != 0) {
- count++;
- scan++;
- }
- break;
- case ANYBUT:
- while (*scan != '\0' && strchr(opnd, *scan) == 0) {
- count++;
- scan++;
- }
- break;
- default: // Oh dear. Called inappropriately.
- //RAISE Error, SYM(cmRegularExpression), SYM(Internal_Error),
- printf ("cm RegularExpression::find(): Internal error.\n");
- return 0;
+ case ANY:
+ count = int(strlen(scan));
+ scan += count;
+ break;
+ case EXACTLY:
+ while (*opnd == *scan) {
+ count++;
+ scan++;
+ }
+ break;
+ case ANYOF:
+ while (*scan != '\0' && strchr(opnd, *scan) != 0) {
+ count++;
+ scan++;
+ }
+ break;
+ case ANYBUT:
+ while (*scan != '\0' && strchr(opnd, *scan) == 0) {
+ count++;
+ scan++;
+ }
+ break;
+ default: // Oh dear. Called inappropriately.
+ //RAISE Error, SYM(cmRegularExpression), SYM(Internal_Error),
+ printf ("cm RegularExpression::find(): Internal error.\n");
+ return 0;
}
reginput = scan;
return (count);
@@ -1166,16 +1176,16 @@ static const char* regnext (register const char* p) {
register int offset;
if (p == &regdummy)
- return (0);
+ return (0);
offset = NEXT(p);
if (offset == 0)
- return (0);
+ return (0);
if (OP(p) == BACK)
- return (p - offset);
+ return (p - offset);
else
- return (p + offset);
+ return (p + offset);
}
@@ -1183,14 +1193,14 @@ static char* regnext (register char* p) {
register int offset;
if (p == &regdummy)
- return (0);
+ return (0);
offset = NEXT(p);
if (offset == 0)
- return (0);
+ return (0);
if (OP(p) == BACK)
- return (p - offset);
+ return (p - offset);
else
- return (p + offset);
+ return (p + offset);
}
diff --git a/Source/cmRegularExpression.h b/Source/cmRegularExpression.h
index 86417fb..b8a9963 100644
--- a/Source/cmRegularExpression.h
+++ b/Source/cmRegularExpression.h
@@ -182,7 +182,7 @@ public:
/**
* Instantiate cmRegularExpression with program=NULL.
*/
- inline cmRegularExpression ();
+ inline cmRegularExpression ();
/**
* Instantiate cmRegularExpression with compiled char*.
@@ -215,7 +215,7 @@ public:
* Matches the regular expression to the given std string.
* Returns true if found, and sets start and end indexes accordingly.
*/
- bool find (std::string const&);
+ bool find (std::string const&);
/**
* Index to start of first find.
@@ -253,7 +253,7 @@ public:
/**
* Marks the regular expression as invalid.
*/
- inline void set_invalid();
+ inline void set_invalid();
/**
* Destructor.
@@ -266,10 +266,10 @@ public:
private:
const char* startp[NSUBEXP];
const char* endp[NSUBEXP];
- char regstart; // Internal use only
- char reganch; // Internal use only
- const char* regmust; // Internal use only
- int regmlen; // Internal use only
+ char regstart; // Internal use only
+ char reganch; // Internal use only
+ const char* regmust; // Internal use only
+ int regmlen; // Internal use only
char* program;
int progsize;
const char* searchstring;
@@ -290,7 +290,10 @@ inline cmRegularExpression::cmRegularExpression ()
inline cmRegularExpression::cmRegularExpression (const char* s)
{
this->program = 0;
- compile(s);
+ if ( s )
+ {
+ this->compile(s);
+ }
}
/**
diff --git a/Source/cmSourceGroupCommand.cxx b/Source/cmSourceGroupCommand.cxx
index 17bf434..d62fd77 100644
--- a/Source/cmSourceGroupCommand.cxx
+++ b/Source/cmSourceGroupCommand.cxx
@@ -19,14 +19,42 @@
// cmSourceGroupCommand
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");
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;
}