]> git.saurik.com Git - apt.git/blobdiff - apt-pkg/contrib/configuration.cc
Fixed more (null) printouts
[apt.git] / apt-pkg / contrib / configuration.cc
index 81521590a6fb4f9d29933d50366a87d21133e8f6..2fa570c2195bf5fd15d7cb6ce9fff76b5d489b47 100644 (file)
@@ -1,6 +1,6 @@
 // -*- mode: cpp; mode: fold -*-
 // Description                                                         /*{{{*/
-// $Id: configuration.cc,v 1.17 2001/03/04 00:44:35 jgg Exp $
+// $Id: configuration.cc,v 1.22 2001/05/14 05:47:30 jgg Exp $
 /* ######################################################################
 
    Configuration Class
 #include <vector>
 #include <algorithm>
 #include <fstream>
+#include <iostream>
     
 #include <stdio.h>
 #include <dirent.h>
 #include <sys/stat.h>
 #include <unistd.h>
+
+using namespace std;
                                                                        /*}}}*/
 
 Configuration *_config = new Configuration;
@@ -92,7 +95,7 @@ Configuration::Item *Configuration::Lookup(Item *Head,const char *S,
    if (Len != 0)
    {
       for (; I != 0; Last = &I->Next, I = I->Next)
-        if ((Res = stringcasecmp(I->Tag.begin(),I->Tag.end(),S,S + Len)) == 0)
+        if ((Res = stringcasecmp(I->Tag,S,S + Len)) == 0)
            break;
    }
    else
@@ -276,7 +279,7 @@ string Configuration::FindAny(const char *Name,const char *Default) const
       case 'i': 
       {
         char buf[16];
-        snprintf(buf, sizeof(buf)-1, "%d", FindI(key, Default));
+        snprintf(buf, sizeof(buf)-1, "%d", FindI(key, atoi(Default)));
         return buf;
       }
    }
@@ -433,12 +436,12 @@ string Configuration::Item::FullTag(const Item *Stop) const
    Sectional config files are like bind's named.conf where there are 
    sections like 'zone "foo.org" { .. };' This causes each section to be
    added in with a tag like "zone::foo.org" instead of being split 
-   tag/value. */
+   tag/value. AsSectional enables Sectional parsing.*/
 bool ReadConfigFile(Configuration &Conf,string FName,bool AsSectional,
                    unsigned Depth)
 {   
    // Open the stream for reading
-   ifstream F(FName.c_str(),ios::in | ios::nocreate);
+   ifstream F(FName.c_str(),ios::in); 
    if (!F != 0)
       return _error->Errno("ifstream::ifstream",_("Opening configuration file %s"),FName.c_str());
    
@@ -582,7 +585,8 @@ bool ReadConfigFile(Configuration &Conf,string FName,bool AsSectional,
                  Word = Tag;
                  Tag = "";
               }
-              NoWord = true;
+              else
+                 NoWord = true;
            }
            if (strlen(Pos) != 0)
               return _error->Error(_("Syntax error %s:%u: Extra junk after value"),FName.c_str(),CurLine);
@@ -689,9 +693,6 @@ bool ReadConfigFile(Configuration &Conf,string FName,bool AsSectional,
 bool ReadConfigDir(Configuration &Conf,string Dir,bool AsSectional,
                    unsigned Depth)
 {   
-   static const char *BadExts[] = {".disabled",".dpkg-old",".dpkg-dist",
-                                  ".rpmsave",".rpmorig","~",",v",0};
-   
    DIR *D = opendir(Dir.c_str());
    if (D == 0)
       return _error->Errno("opendir",_("Unable to read %s"),Dir.c_str());
@@ -703,15 +704,12 @@ bool ReadConfigDir(Configuration &Conf,string Dir,bool AsSectional,
       if (Ent->d_name[0] == '.')
         continue;
       
-      // Skip bad extensions
-      const char **I;
-      for (I = BadExts; *I != 0; I++)
-      {
-        if (strcmp(Ent->d_name + strlen(Ent->d_name) - strlen(*I),*I) == 0)
+      // 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 (*I != 0)
+      if (*C != 0)
         continue;
       
       // Make sure it is a file and not something else