From 2f4162708d9db7c71590370cc998d46e8386c757 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sun, 22 Apr 2012 12:28:10 +0200 Subject: * apt-pkg/contrib/configuration.cc: - add a more versatile Dump() method --- apt-pkg/contrib/configuration.cc | 72 +++++++++++++++++++++++++++++++++++----- apt-pkg/contrib/configuration.h | 2 ++ debian/changelog | 4 ++- 3 files changed, 69 insertions(+), 9 deletions(-) diff --git a/apt-pkg/contrib/configuration.cc b/apt-pkg/contrib/configuration.cc index 36866a35a..ff80dfaf8 100644 --- a/apt-pkg/contrib/configuration.cc +++ b/apt-pkg/contrib/configuration.cc @@ -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 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::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); } /*}}}*/ diff --git a/apt-pkg/contrib/configuration.h b/apt-pkg/contrib/configuration.h index 4c2e75041..ea94c2fe6 100644 --- a/apt-pkg/contrib/configuration.h +++ b/apt-pkg/contrib/configuration.h @@ -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(); diff --git a/debian/changelog b/debian/changelog index a90aa68aa..cbbedda0d 100644 --- a/debian/changelog +++ b/debian/changelog @@ -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 Sat, 21 Apr 2012 18:26:31 +0200 + -- David Kalnischkies Sun, 22 Apr 2012 12:27:47 +0200 apt (0.9.2) unstable; urgency=low -- cgit v1.2.3