]> git.saurik.com Git - apt.git/blobdiff - apt-pkg/contrib/configuration.cc
* merged with main
[apt.git] / apt-pkg / contrib / configuration.cc
index 69f8d1dca61dc0d681356a278e6faf2078d13283..4b2c0fbb51977e53bdd21eb4f9ddd01e6c9ab03b 100644 (file)
@@ -325,6 +325,47 @@ void Configuration::Set(const char *Name,int Value)
    char S[300];
    snprintf(S,sizeof(S),"%i",Value);
    Itm->Value = S;
+}
+                                                                       /*}}}*/
+// Configuration::Clear - Clear an single value from a list            /*{{{*/
+// ---------------------------------------------------------------------
+/* */
+void Configuration::Clear(string Name, int Value)
+{
+   char S[300];
+   snprintf(S,sizeof(S),"%i",Value);
+   Clear(Name, S);
+}
+                                                                       /*}}}*/
+// Configuration::Clear - Clear an single value from a list            /*{{{*/
+// ---------------------------------------------------------------------
+/* */
+void Configuration::Clear(string Name, string Value)
+{
+   Item *Top = Lookup(Name.c_str(),false);
+   if (Top == 0 || Top->Child == 0)
+      return;
+
+   Item *Tmp, *Prev, *I;
+   Prev = I = Top->Child;
+
+   while(I != NULL)
+   {
+      if(I->Value == Value)
+      {
+        Tmp = I;
+        // was first element, point parent to new first element
+        if(Top->Child == Tmp)
+           Top->Child = I->Next;
+        I = I->Next;
+        Prev->Next = I;
+        delete Tmp;
+      } else {
+        Prev = I;
+        I = I->Next;
+      }
+   }
+     
 }
                                                                        /*}}}*/
 // Configuration::Clear - Clear an entire tree                         /*{{{*/
@@ -333,9 +374,10 @@ void Configuration::Set(const char *Name,int Value)
 void Configuration::Clear(string Name)
 {
    Item *Top = Lookup(Name.c_str(),false);
-   if (Top == 0)
+   if (Top == 0) {
+      cout << "config item: " << Name << " not found" << endl;
       return;
-   
+   }
    Top->Value = string();
    Item *Stop = Top;
    Top = Top->Child;