[cmake-commits] king committed cmCommandArgumentParserHelper.cxx 1.19 1.20 cmCommandArgumentParserHelper.h 1.10 1.11 cmMakefile.cxx 1.393 1.394 cmMakefile.h 1.204 1.205

cmake-commits at cmake.org cmake-commits at cmake.org
Wed Jun 6 16:20:04 EDT 2007


Update of /cvsroot/CMake/CMake/Source
In directory public:/mounts/ram/cvs-serv4731/Source

Modified Files:
	cmCommandArgumentParserHelper.cxx 
	cmCommandArgumentParserHelper.h cmMakefile.cxx cmMakefile.h 
Log Message:
BUG: Fixed @ONLY configuration to not try to parse ${} syntax at all.  This fixes the original fix to bug#4393 and adds a test.


Index: cmCommandArgumentParserHelper.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmCommandArgumentParserHelper.h,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- cmCommandArgumentParserHelper.h	9 Feb 2007 18:44:37 -0000	1.10
+++ cmCommandArgumentParserHelper.h	6 Jun 2007 20:20:02 -0000	1.11
@@ -58,7 +58,7 @@
   char* CombineUnions(char* in1, char* in2);
 
   char* ExpandSpecialVariable(const char* key, const char* var);
-  char* ExpandVariable(const char* var, bool doingAt=false);
+  char* ExpandVariable(const char* var);
   char* ExpandVariableForAt(const char* var);
   void SetResult(const char* value);
 
@@ -71,7 +71,6 @@
   void SetNoEscapeMode(bool b) { this->NoEscapeMode = b; }
   void SetReplaceAtSyntax(bool b) { this->ReplaceAtSyntax = b; }
   void SetRemoveEmpty(bool b) { this->RemoveEmpty = b; }
-  void SetAtOnly(bool b) { this->AtOnly = b; }
   
   const char* GetError() { return this->ErrorString.c_str(); } 
   char EmptyVariable[1];
@@ -107,7 +106,6 @@
   bool NoEscapeMode;
   bool ReplaceAtSyntax;
   bool RemoveEmpty; 
-  bool AtOnly;
 };
 
 #endif

Index: cmCommandArgumentParserHelper.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmCommandArgumentParserHelper.cxx,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -d -r1.19 -r1.20
--- cmCommandArgumentParserHelper.cxx	4 Jun 2007 19:57:33 -0000	1.19
+++ cmCommandArgumentParserHelper.cxx	6 Jun 2007 20:20:02 -0000	1.20
@@ -38,7 +38,6 @@
 
   this->NoEscapeMode = false;
   this->ReplaceAtSyntax = false;
-  this->AtOnly = false;
 }
 
 
@@ -72,18 +71,6 @@
     {
     return this->ExpandVariable(var);
     } 
-  if(this->AtOnly)
-    {
-    std::string ref = "$";
-    ref += key;
-    ref += "{";
-    if(var)
-      {
-      ref += var;
-      }
-    ref += "}";
-    return this->AddString(ref.c_str());
-    }
   if ( strcmp(key, "ENV") == 0 )
     {
     char *ptr = getenv(var);
@@ -105,21 +92,8 @@
   return 0;
 }
 
-char* cmCommandArgumentParserHelper::ExpandVariable(const char* var,
-                                                    bool doingAt)
+char* cmCommandArgumentParserHelper::ExpandVariable(const char* var)
 {
-  // if we are in AtOnly mode, and we are not expanding an @ variable
-  // then put back the ${var} unexpanded
-  if(!doingAt && this->AtOnly)
-    {
-    std::string ref = "${";
-    if(var)
-      {
-      ref += var;
-      }
-    ref += "}";
-    return this->AddString(ref.c_str());
-    }
   if(!var)
     {
     return 0;
@@ -151,7 +125,7 @@
   if(this->ReplaceAtSyntax)
     {
     // try to expand the variable
-    char* ret = this->ExpandVariable(var, true);
+    char* ret = this->ExpandVariable(var);
     // if the return was 0 and we want to replace empty strings
     // then return an empty string 
     if(!ret && this->RemoveEmpty)

Index: cmMakefile.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmMakefile.h,v
retrieving revision 1.204
retrieving revision 1.205
diff -u -d -r1.204 -r1.205
--- cmMakefile.h	22 May 2007 14:24:59 -0000	1.204
+++ cmMakefile.h	6 Jun 2007 20:20:02 -0000	1.205
@@ -570,14 +570,14 @@
    * entry in the this->Definitions map.  Also @var@ is
    * expanded to match autoconf style expansions.
    */
-  const char *ExpandVariablesInString(std::string& source) const;
+  const char *ExpandVariablesInString(std::string& source);
   const char *ExpandVariablesInString(std::string& source, bool escapeQuotes,
                                       bool noEscapes,
                                       bool atOnly = false,
                                       const char* filename = 0,
                                       long line = -1,
                                       bool removeEmpty = false,
-                                      bool replaceAt = true) const;
+                                      bool replaceAt = true);
 
   /**
    * Remove any remaining variables in the string. Anything with ${var} or
@@ -807,6 +807,7 @@
 
   cmsys::RegularExpression cmDefineRegex;
   cmsys::RegularExpression cmDefine01Regex;
+  cmsys::RegularExpression cmAtVarRegex;
 
   cmPropertyMap Properties;
 

Index: cmMakefile.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmMakefile.cxx,v
retrieving revision 1.393
retrieving revision 1.394
diff -u -d -r1.393 -r1.394
--- cmMakefile.cxx	28 May 2007 13:59:08 -0000	1.393
+++ cmMakefile.cxx	6 Jun 2007 20:20:02 -0000	1.394
@@ -87,7 +87,7 @@
   this->AddDefaultDefinitions();
   this->cmDefineRegex.compile("#cmakedefine[ \t]+([A-Za-z_0-9]*)");
   this->cmDefine01Regex.compile("#cmakedefine01[ \t]+([A-Za-z_0-9]*)");
-
+  this->cmAtVarRegex.compile("(@[A-Za-z_0-9/.+-]+@)");
   this->PreOrder = false;
 }
 
@@ -1745,7 +1745,7 @@
 }
 
 
-const char *cmMakefile::ExpandVariablesInString(std::string& source) const
+const char *cmMakefile::ExpandVariablesInString(std::string& source)
 {
   return this->ExpandVariablesInString(source, false, false);
 }
@@ -1757,12 +1757,65 @@
                                                 const char* filename,
                                                 long line,
                                                 bool removeEmpty,
-                                                bool replaceAt) const
+                                                bool replaceAt)
 {
   if ( source.empty() || source.find_first_of("$@\\") == source.npos)
     {
     return source.c_str();
     }
+
+  // Special-case the @ONLY mode.
+  if(atOnly)
+    {
+    if(!noEscapes || !removeEmpty || !replaceAt)
+      {
+      // This case should never be called.  At-only is for
+      // configure-file/string which always does no escapes.
+      abort();
+      }
+
+    // Store an original copy of the input.
+    std::string input = source;
+
+    // Start with empty output.
+    source = "";
+
+    // Look for one @VAR@ at a time.
+    const char* in = input.c_str();
+    while(this->cmAtVarRegex.find(in))
+      {
+      // Get the range of the string to replace.
+      const char* first = in + this->cmAtVarRegex.start();
+      const char* last =  in + this->cmAtVarRegex.end();
+
+      // Store the unchanged part of the string now.
+      source.append(in, first-in);
+
+      // Lookup the definition of VAR.
+      std::string var(first+1, last-first-2);
+      if(const char* val = this->GetDefinition(var.c_str()))
+        {
+        // Store the value in the output escaping as requested.
+        if(escapeQuotes)
+          {
+          source.append(cmSystemTools::EscapeQuotes(val));
+          }
+        else
+          {
+          source.append(val);
+          }
+        }
+
+      // Continue looking for @VAR@ further along the string.
+      in = last;
+      }
+
+    // Append the rest of the unchanged part of the string.
+    source.append(in);
+
+    return source.c_str();
+    }
+
   // This method replaces ${VAR} and @VAR@ where VAR is looked up
   // with GetDefinition(), if not found in the map, nothing is expanded.
   // It also supports the $ENV{VAR} syntax where VAR is looked up in
@@ -1775,7 +1828,6 @@
   parser.SetNoEscapeMode(noEscapes);
   parser.SetReplaceAtSyntax(replaceAt);
   parser.SetRemoveEmpty(removeEmpty);
-  parser.SetAtOnly(atOnly);
   int res = parser.ParseString(source.c_str(), 0);
   if ( res )
     {



More information about the Cmake-commits mailing list