]> git.saurik.com Git - apt.git/blobdiff - apt-pkg/contrib/configuration.cc
Merge remote-tracking branch 'upstream/debian/sid' into debian/experimental
[apt.git] / apt-pkg / contrib / configuration.cc
index ce02f1bd22e73e76b16b8c41f23454a3261d3e21..fbe180f8ea03cfa620a5d0105aaaf99d48df303f 100644 (file)
 #include <apt-pkg/error.h>
 #include <apt-pkg/strutl.h>
 #include <apt-pkg/fileutl.h>
-
+#include <apt-pkg/macros.h>
+
+#include <ctype.h>
+#include <regex.h>
+#include <stddef.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <algorithm>
+#include <string>
 #include <vector>
 #include <fstream>
-#include <iostream>
 
 #include <apti18n.h>
 
@@ -42,8 +50,7 @@ Configuration::Configuration() : ToFree(true)
 }
 Configuration::Configuration(const Item *Root) : Root((Item *)Root), ToFree(false)
 {
-};
-
+}
                                                                        /*}}}*/
 // Configuration::~Configuration - Destructor                          /*{{{*/
 // ---------------------------------------------------------------------
@@ -194,7 +201,11 @@ string Configuration::FindFile(const char *Name,const char *Default) const
 
         // Absolute
         if (val.length() >= 1 && val[0] == '/')
+        {
+           if (val.compare(0, 9, "/dev/null") == 0)
+              val.erase(9);
            break;
+        }
 
         // ~/foo or ./foo
         if (val.length() >= 2 && (val[0] == '~' || val[0] == '.') && val[1] == '/')
@@ -230,19 +241,32 @@ string Configuration::FindDir(const char *Name,const char *Default) const
 {
    string Res = FindFile(Name,Default);
    if (Res.end()[-1] != '/')
+   {
+      size_t const found = Res.rfind("/dev/null");
+      if (found != string::npos && found == Res.size() - 9)
+        return Res; // /dev/null returning
       return Res + '/';
+   }
    return Res;
 }
                                                                        /*}}}*/
 // Configuration::FindVector - Find a vector of values                 /*{{{*/
 // ---------------------------------------------------------------------
 /* Returns a vector of config values under the given item */
-vector<string> Configuration::FindVector(const char *Name) const
+#if (APT_PKG_MAJOR >= 4 && APT_PKG_MINOR < 13)
+vector<string> Configuration::FindVector(const char *Name) const { 
+   return FindVector(Name, ""); 
+}
+#endif
+vector<string> Configuration::FindVector(const char *Name, std::string const &Default) const
 {
    vector<string> Vec;
    const Item *Top = Lookup(Name);
    if (Top == NULL)
-      return Vec;
+      return VectorizeString(Default, ',');
+
+   if (Top->Value.empty() == false)
+      return VectorizeString(Top->Value, ',');
 
    Item *I = Top->Child;
    while(I != NULL)
@@ -250,6 +274,9 @@ vector<string> Configuration::FindVector(const char *Name) const
       Vec.push_back(I->Value);
       I = I->Next;
    }
+   if (Vec.empty() == true)
+      return VectorizeString(Default, ',');
+
    return Vec;
 }
                                                                        /*}}}*/
@@ -411,6 +438,18 @@ void Configuration::Clear(string const &Name, string const &Value)
       }
    }
      
+}
+                                                                       /*}}}*/
+// Configuration::Clear - Clear everything                             /*{{{*/
+// ---------------------------------------------------------------------
+void Configuration::Clear()
+{
+   const Configuration::Item *Top = Tree(0);
+   while( Top != 0 )
+   {
+      Clear(Top->FullTag());
+      Top = Top->Next;
+   }
 }
                                                                        /*}}}*/
 // Configuration::Clear - Clear an entire tree                         /*{{{*/
@@ -802,7 +841,7 @@ bool ReadConfigFile(Configuration &Conf,const string &FName,bool const &AsSectio
            // Go down a level
            if (TermChar == '{')
            {
-              if (StackPos <= 100)
+              if (StackPos < sizeof(Stack)/sizeof(std::string))
                  Stack[StackPos++] = ParentTag;
               
               /* Make sectional tags incorperate the section into the
@@ -949,7 +988,7 @@ Configuration::MatchAgainstConfig::MatchAgainstConfig(char const * Config)
         continue;
       }
    }
-   if (strings.size() == 0)
+   if (strings.empty() == true)
       patterns.push_back(NULL);
 }
                                                                        /*}}}*/