]> git.saurik.com Git - apt.git/blobdiff - apt-pkg/contrib/configuration.cc
show in madison command again also source packages (LP: #614589)
[apt.git] / apt-pkg / contrib / configuration.cc
index ff49ce8576671bf07fc50cef4a083373cf1530e1..81cc87d15e93b434e1a0003c65bdcc96b6ec7866 100644 (file)
 #include <apti18n.h>
 
 #include <vector>
 #include <apti18n.h>
 
 #include <vector>
-#include <algorithm>
 #include <fstream>
 #include <iostream>
 #include <fstream>
 #include <iostream>
-    
-#include <stdio.h>
-#include <dirent.h>
-#include <sys/stat.h>
-#include <unistd.h>
 
 using namespace std;
                                                                        /*}}}*/
 
 using namespace std;
                                                                        /*}}}*/
@@ -779,6 +773,8 @@ bool ReadConfigFile(Configuration &Conf,const string &FName,bool const &AsSectio
               else
                  return _error->Error(_("Syntax error %s:%u: Unsupported directive '%s'"),FName.c_str(),CurLine,Tag.c_str());
            }
               else
                  return _error->Error(_("Syntax error %s:%u: Unsupported directive '%s'"),FName.c_str(),CurLine,Tag.c_str());
            }
+           else if (Tag.empty() == true && NoWord == false && Word == "#clear")
+              return _error->Error(_("Syntax error %s:%u: clear directive requires an option tree as argument"),FName.c_str(),CurLine);
            else
            {
               // Set the item in the configuration class
            else
            {
               // Set the item in the configuration class
@@ -835,39 +831,10 @@ bool ReadConfigFile(Configuration &Conf,const string &FName,bool const &AsSectio
 // ReadConfigDir - Read a directory of config files                    /*{{{*/
 // ---------------------------------------------------------------------
 /* */
 // ReadConfigDir - Read a directory of config files                    /*{{{*/
 // ---------------------------------------------------------------------
 /* */
-bool ReadConfigDir(Configuration &Conf,const string &Dir,bool const &AsSectional,
-                  unsigned const &Depth)
-{   
-   DIR *D = opendir(Dir.c_str());
-   if (D == 0)
-      return _error->Errno("opendir",_("Unable to read %s"),Dir.c_str());
-
-   vector<string> List;
-   
-   for (struct dirent *Ent = readdir(D); Ent != 0; Ent = readdir(D))
-   {
-      if (Ent->d_name[0] == '.')
-        continue;
-      
-      // Skip bad file names ala run-parts
-      const char *C = Ent->d_name;
-      for (; *C != 0; C++)
-        if (isalpha(*C) == 0 && isdigit(*C) == 0 && *C != '_' && *C != '-')
-           break;
-      if (*C != 0)
-        continue;
-      
-      // Make sure it is a file and not something else
-      string File = flCombine(Dir,Ent->d_name);
-      struct stat St;
-      if (stat(File.c_str(),&St) != 0 || S_ISREG(St.st_mode) == 0)
-        continue;
-      
-      List.push_back(File);      
-   }   
-   closedir(D);
-   
-   sort(List.begin(),List.end());
+bool ReadConfigDir(Configuration &Conf,const string &Dir,
+                  bool const &AsSectional, unsigned const &Depth)
+{
+   vector<string> const List = GetListOfFilesInDir(Dir, "conf", true, true);
 
    // Read the files
    for (vector<string>::const_iterator I = List.begin(); I != List.end(); I++)
 
    // Read the files
    for (vector<string>::const_iterator I = List.begin(); I != List.end(); I++)
@@ -876,3 +843,46 @@ bool ReadConfigDir(Configuration &Conf,const string &Dir,bool const &AsSectional
    return true;
 }
                                                                        /*}}}*/
    return true;
 }
                                                                        /*}}}*/
+// MatchAgainstConfig Constructor                                      /*{{{*/
+Configuration::MatchAgainstConfig::MatchAgainstConfig(char const * Config)
+{
+   std::vector<std::string> const strings = _config->FindVector(Config);
+   for (std::vector<std::string>::const_iterator s = strings.begin();
+       s != strings.end(); ++s)
+   {
+      regex_t *p = new regex_t;
+      if (regcomp(p, s->c_str(), REG_EXTENDED | REG_ICASE | REG_NOSUB) == 0)
+        patterns.push_back(p);
+      else
+      {
+        regfree(p);
+        delete p;
+        _error->Warning("Regex compilation error for '%s' in configuration option '%s'",
+                               s->c_str(), Config);
+      }
+    }
+
+}
+                                                                       /*}}}*/
+// MatchAgainstConfig Destructor                                       /*{{{*/
+Configuration::MatchAgainstConfig::~MatchAgainstConfig()
+{
+   for(std::vector<regex_t *>::const_iterator p = patterns.begin();
+       p != patterns.end(); ++p)
+   {
+      regfree(*p);
+      delete *p;
+   }
+}
+                                                                       /*}}}*/
+// MatchAgainstConfig::Match - returns true if a pattern matches       /*{{{*/
+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)
+        return true;
+
+   return false;
+}
+                                                                       /*}}}*/