]> git.saurik.com Git - apt.git/blobdiff - apt-pkg/contrib/configuration.cc
merge with debian/experimental
[apt.git] / apt-pkg / contrib / configuration.cc
index 81cc87d15e93b434e1a0003c65bdcc96b6ec7866..0f7b37ee9964d0592b09806da07fdf50a44fc5d3 100644 (file)
    ##################################################################### */
                                                                        /*}}}*/
 // Include files                                                       /*{{{*/
+#include <config.h>
+
 #include <apt-pkg/configuration.h>
 #include <apt-pkg/error.h>
 #include <apt-pkg/strutl.h>
 #include <apt-pkg/fileutl.h>
-#include <apti18n.h>
 
 #include <vector>
 #include <fstream>
 #include <iostream>
 
+#include <apti18n.h>
+
 using namespace std;
                                                                        /*}}}*/
 
@@ -318,6 +321,19 @@ void Configuration::CndSet(const char *Name,const string &Value)
       Itm->Value = Value;
 }
                                                                        /*}}}*/
+// Configuration::Set - Set an integer value                           /*{{{*/
+// ---------------------------------------------------------------------
+/* */
+void Configuration::CndSet(const char *Name,int const Value)
+{
+   Item *Itm = Lookup(Name,true);
+   if (Itm == 0 || Itm->Value.empty() == false)
+      return;
+   char S[300];
+   snprintf(S,sizeof(S),"%i",Value);
+   Itm->Value = S;
+}
+                                                                       /*}}}*/
 // Configuration::Set - Set a value                                    /*{{{*/
 // ---------------------------------------------------------------------
 /* */
@@ -659,9 +675,9 @@ bool ReadConfigFile(Configuration &Conf,const string &FName,bool const &AsSectio
            // Put the last fragment into the buffer
            std::string::const_iterator NonWhitespaceStart = Start;
            std::string::const_iterator NonWhitespaceStop = I;
-           for (; NonWhitespaceStart != I && isspace(*NonWhitespaceStart) != 0; NonWhitespaceStart++)
+           for (; NonWhitespaceStart != I && isspace(*NonWhitespaceStart) != 0; ++NonWhitespaceStart)
              ;
-           for (; NonWhitespaceStop != NonWhitespaceStart && isspace(NonWhitespaceStop[-1]) != 0; NonWhitespaceStop--)
+           for (; NonWhitespaceStop != NonWhitespaceStart && isspace(NonWhitespaceStop[-1]) != 0; --NonWhitespaceStop)
              ;
            if (LineBuffer.empty() == false && NonWhitespaceStop - NonWhitespaceStart != 0)
               LineBuffer += ' ';
@@ -837,7 +853,7 @@ bool ReadConfigDir(Configuration &Conf,const string &Dir,
    vector<string> const List = GetListOfFilesInDir(Dir, "conf", true, true);
 
    // Read the files
-   for (vector<string>::const_iterator I = List.begin(); I != List.end(); I++)
+   for (vector<string>::const_iterator I = List.begin(); I != List.end(); ++I)
       if (ReadConfigFile(Conf,*I,AsSectional,Depth) == false)
         return false;
    return true;
@@ -857,19 +873,27 @@ Configuration::MatchAgainstConfig::MatchAgainstConfig(char const * Config)
       {
         regfree(p);
         delete p;
+        clearPatterns();
         _error->Warning("Regex compilation error for '%s' in configuration option '%s'",
                                s->c_str(), Config);
+        return;
       }
-    }
-
+   }
+   if (strings.size() == 0)
+      patterns.push_back(NULL);
 }
                                                                        /*}}}*/
 // MatchAgainstConfig Destructor                                       /*{{{*/
 Configuration::MatchAgainstConfig::~MatchAgainstConfig()
+{
+   clearPatterns();
+}
+void Configuration::MatchAgainstConfig::clearPatterns()
 {
    for(std::vector<regex_t *>::const_iterator p = patterns.begin();
        p != patterns.end(); ++p)
    {
+      if (*p == NULL) continue;
       regfree(*p);
       delete *p;
    }
@@ -880,7 +904,7 @@ bool Configuration::MatchAgainstConfig::Match(char const * str) const
 {
    for(std::vector<regex_t *>::const_iterator p = patterns.begin();
        p != patterns.end(); ++p)
-      if (regexec(*p, str, 0, 0, 0) == 0)
+      if (*p != NULL && regexec(*p, str, 0, 0, 0) == 0)
         return true;
 
    return false;