]> git.saurik.com Git - apt.git/blobdiff - apt-pkg/contrib/configuration.cc
Use the 'binary' target rather than 'all' so that the s...
[apt.git] / apt-pkg / contrib / configuration.cc
index b8c806e28524cef4380f586476d0caaca2eedf94..e6ea2a0efd6b8f037028e020f141c2d072f1b05a 100644 (file)
@@ -1,6 +1,6 @@
 // -*- mode: cpp; mode: fold -*-
 // Description                                                         /*{{{*/
-// $Id: configuration.cc,v 1.21 2001/04/29 05:24:42 jgg Exp $
+// $Id: configuration.cc,v 1.27 2003/07/26 00:27:36 mdz Exp $
 /* ######################################################################
 
    Configuration Class
@@ -8,6 +8,9 @@
    This class provides a configuration file and command line parser
    for a tree-oriented configuration environment. All runtime configuration
    is stored in here.
+
+   This source is placed in the Public Domain, do with it what you will
+   It was originally written by Jason Gunthorpe <jgg@debian.org>.
    
    ##################################################################### */
                                                                        /*}}}*/
 #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 +98,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 +282,7 @@ string Configuration::FindAny(const char *Name,const char *Default) const
       case 'i': 
       {
         char buf[16];
-        snprintf(buf, sizeof(buf)-1, "%d", FindI(key, atoi(Default)));
+        snprintf(buf, sizeof(buf)-1, "%d", FindI(key, Default ? atoi(Default) : 0 ));
         return buf;
       }
    }
@@ -377,13 +383,17 @@ bool Configuration::ExistsAny(const char *Name) const
 {
    string key = Name;
 
-   if (key.size() > 2 && key.end()[-2] == '/' &&
-       key.find_first_of("fdbi",key.size()-1) < key.size())
-   {
-      key.resize(key.size() - 2);
-      if (Exists(key.c_str()))
-        return true;
-   }
+   if (key.size() > 2 && key.end()[-2] == '/')
+      if (key.find_first_of("fdbi",key.size()-1) < key.size())
+      {
+         key.resize(key.size() - 2);
+         if (Exists(key.c_str()))
+            return true;
+      }
+      else
+      {
+         _error->Warning(_("Unrecognized type abbreviation: '%c'"), key.end()[-3]);
+      }
 
    return Exists(Name);
 }
@@ -391,14 +401,14 @@ bool Configuration::ExistsAny(const char *Name) const
 // Configuration::Dump - Dump the config                               /*{{{*/
 // ---------------------------------------------------------------------
 /* Dump the entire configuration space */
-void Configuration::Dump()
+void Configuration::Dump(ostream& str)
 {
    /* Write out all of the configuration directives by walking the 
       configuration tree */
    const Configuration::Item *Top = Tree(0);
    for (; Top != 0;)
    {
-      clog << Top->FullTag() << " \"" << Top->Value << "\";" << endl;
+      str << Top->FullTag() << " \"" << Top->Value << "\";" << endl;
       
       if (Top->Child != 0)
       {
@@ -438,7 +448,7 @@ 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());