]> git.saurik.com Git - apt.git/blobdiff - apt-pkg/contrib/configuration.cc
Slovak translation update
[apt.git] / apt-pkg / contrib / configuration.cc
index 48a5f0bff1f26551602339623592d96d85a1ee22..8e3b84499c15366f1c24f89becd9873b97332c38 100644 (file)
 #include <apti18n.h>
 
 #include <vector>
-#include <algorithm>
 #include <fstream>
 #include <iostream>
-    
-#include <stdio.h>
-#include <dirent.h>
-#include <sys/stat.h>
-#include <unistd.h>
 
 using namespace std;
                                                                        /*}}}*/
@@ -223,6 +217,25 @@ string Configuration::FindDir(const char *Name,const char *Default) const
    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
+{
+   vector<string> Vec;
+   const Item *Top = Lookup(Name);
+   if (Top == NULL)
+      return Vec;
+
+   Item *I = Top->Child;
+   while(I != NULL)
+   {
+      Vec.push_back(I->Value);
+      I = I->Next;
+   }
+   return Vec;
+}
+                                                                       /*}}}*/
 // Configuration::FindI - Find an integer value                                /*{{{*/
 // ---------------------------------------------------------------------
 /* */
@@ -582,9 +595,11 @@ bool ReadConfigFile(Configuration &Conf,const string &FName,bool AsSectional,
            InQuote = !InQuote;
         if (InQuote == true)
            continue;
-        
-        if ((*I == '/' && I + 1 != End && I[1] == '/') || *I == '#')
-         {
+
+        if ((*I == '/' && I + 1 != End && I[1] == '/') ||
+            (*I == '#' && strcmp(string(I,I+6).c_str(),"#clear") != 0 &&
+             strcmp(string(I,I+8).c_str(),"#include") != 0))
+        {
            End = I;
            break;
         }
@@ -814,39 +829,10 @@ bool ReadConfigFile(Configuration &Conf,const string &FName,bool AsSectional,
 // ReadConfigDir - Read a directory of config files                    /*{{{*/
 // ---------------------------------------------------------------------
 /* */
-bool ReadConfigDir(Configuration &Conf,const string &Dir,bool AsSectional,
-                  unsigned 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 AsSectional, unsigned 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++)