* apt-pkg/contrib/configuration.cc:
authorDavid Kalnischkies <kalnischkies@gmail.com>
Sun, 22 Apr 2012 10:28:10 +0000 (12:28 +0200)
committerDavid Kalnischkies <kalnischkies@gmail.com>
Sun, 22 Apr 2012 10:28:10 +0000 (12:28 +0200)
  - add a more versatile Dump() method

apt-pkg/contrib/configuration.cc
apt-pkg/contrib/configuration.h
debian/changelog

index 36866a3..ff80dfa 100644 (file)
@@ -482,24 +482,80 @@ bool Configuration::ExistsAny(const char *Name) const
 /* Dump the entire configuration space */
 void Configuration::Dump(ostream& str)
 {
-   /* Write out all of the configuration directives by walking the 
+   Dump(str, NULL, "%f \"%v\";\n", true);
+}
+void Configuration::Dump(ostream& str, char const * const root,
+                        char const * const formatstr, bool const emptyValue)
+{
+   const Configuration::Item* Top = Tree(root);
+   if (Top == 0)
+      return;
+   const Configuration::Item* const Root = (root == NULL) ? NULL : Top;
+   std::vector<std::string> const format = VectorizeString(formatstr, '%');
+
+   /* Write out all of the configuration directives by walking the
       configuration tree */
-   const Configuration::Item *Top = Tree(0);
-   for (; Top != 0;)
-   {
-      str << Top->FullTag() << " \"" << Top->Value << "\";" << endl;
-      
+   do {
+      if (emptyValue == true || Top->Value.empty() == emptyValue)
+      {
+        std::vector<std::string>::const_iterator f = format.begin();
+        str << *f;
+        for (++f; f != format.end(); ++f)
+        {
+           if (f->empty() == true)
+           {
+              ++f;
+              str << '%' << *f;
+              continue;
+           }
+           char const type = (*f)[0];
+           if (type == 'f')
+              str << Top->FullTag();
+           else if (type == 't')
+              str << Top->Tag;
+           else if (type == 'v')
+              str << Top->Value;
+           else if (type == 'F')
+              str << QuoteString(Top->FullTag(), "=\"\n");
+           else if (type == 'T')
+              str << QuoteString(Top->Tag, "=\"\n");
+           else if (type == 'V')
+              str << QuoteString(Top->Value, "=\"\n");
+           else if (type == 'n')
+              str << "\n";
+           else if (type == 'N')
+              str << "\t";
+           else
+              str << '%' << type;
+           str << f->c_str() + 1;
+        }
+      }
+
       if (Top->Child != 0)
       {
         Top = Top->Child;
         continue;
       }
-      
+
       while (Top != 0 && Top->Next == 0)
         Top = Top->Parent;
       if (Top != 0)
         Top = Top->Next;
-   }
+
+      if (Root != NULL)
+      {
+        const Configuration::Item* I = Top;
+        while(I != 0)
+        {
+           if (I == Root)
+              break;
+           else
+              I = I->Parent;
+        }
+        if (I == 0)
+           break;
+      }
+   } while (Top != 0);
 }
                                                                        /*}}}*/
 
index 4c2e750..ea94c2f 100644 (file)
@@ -103,6 +103,8 @@ class Configuration
 
    inline void Dump() { Dump(std::clog); };
    void Dump(std::ostream& str);
+   void Dump(std::ostream& str, char const * const root,
+            char const * const format, bool const emptyValue);
 
    Configuration(const Item *Root);
    Configuration();
index a90aa68..cbbedda 100644 (file)
@@ -3,8 +3,10 @@ apt (0.9.3) unstable; urgency=low
   [ David Kalnischkies ]
   * apt-pkg/contrib/strutl.cc:
     - remove the message size limit from ioprintf and strprintf
+  * apt-pkg/contrib/configuration.cc:
+    - add a more versatile Dump() method
 
- -- David Kalnischkies <kalnischkies@gmail.com>  Sat, 21 Apr 2012 18:26:31 +0200
+ -- David Kalnischkies <kalnischkies@gmail.com>  Sun, 22 Apr 2012 12:27:47 +0200
 
 apt (0.9.2) unstable; urgency=low