summaryrefslogtreecommitdiff
path: root/apt-pkg/contrib
diff options
context:
space:
mode:
authorArch Librarian <arch@canonical.com>2004-09-20 16:50:43 +0000
committerArch Librarian <arch@canonical.com>2004-09-20 16:50:43 +0000
commit9c14e3d619e713aefa623986b5bbae81a1d6cc94 (patch)
tree282c77581b35bbdc46faa400be5d64ec37605507 /apt-pkg/contrib
parent6c139d6e362f04a1582e8a8f511f8aeab031fecf (diff)
Config class and source list
Author: jgg Date: 1998-07-09 05:12:27 GMT Config class and source list
Diffstat (limited to 'apt-pkg/contrib')
-rw-r--r--apt-pkg/contrib/configuration.cc45
-rw-r--r--apt-pkg/contrib/configuration.h10
-rw-r--r--apt-pkg/contrib/strutl.h4
3 files changed, 46 insertions, 13 deletions
diff --git a/apt-pkg/contrib/configuration.cc b/apt-pkg/contrib/configuration.cc
index 6d937d657..7694330f9 100644
--- a/apt-pkg/contrib/configuration.cc
+++ b/apt-pkg/contrib/configuration.cc
@@ -1,6 +1,6 @@
// -*- mode: cpp; mode: fold -*-
// Description /*{{{*/
-// $Id: configuration.cc,v 1.1 1998/07/07 04:17:10 jgg Exp $
+// $Id: configuration.cc,v 1.2 1998/07/09 05:12:33 jgg Exp $
/* ######################################################################
Configuration Class
@@ -20,7 +20,8 @@
#include <stdio.h>
/*}}}*/
-Configuration *_config;
+
+Configuration *_config = new Configuration;
// Configuration::Configuration - Constructor /*{{{*/
// ---------------------------------------------------------------------
@@ -41,17 +42,18 @@ Configuration::Item *Configuration::Lookup(Item *Head,const char *S,
Item *I = Head->Child;
Item **Last = &Head->Child;
for (; I != 0; Last = &I->Next, I = I->Next)
- if ((Res = stringcasecmp(I->Value.begin(),I->Value.end(),S,S + Len)) == 0)
+ if ((Res = stringcasecmp(I->Tag.begin(),I->Tag.end(),S,S + Len)) == 0)
break;
-
+
if (Res == 0)
return I;
if (Create == false)
return 0;
I = new Item;
- I->Value = string(S,Len);
+ I->Tag = string(S,Len);
I->Next = *Last;
+ I->Parent = Head;
*Last = I;
return I;
}
@@ -78,8 +80,6 @@ Configuration::Item *Configuration::Lookup(const char *Name,bool Create)
}
Itm = Lookup(Itm,Start,End - Start,Create);
- if (Itm == 0)
- return 0;
return Itm;
}
/*}}}*/
@@ -90,10 +90,39 @@ string Configuration::Find(const char *Name,const char *Default)
{
Item *Itm = Lookup(Name,false);
if (Itm == 0 || Itm->Value.empty() == true)
- return Default;
+ {
+ if (Default == 0)
+ return string();
+ else
+ return Default;
+ }
+
return Itm->Value;
}
/*}}}*/
+// Configuration::FindDir - Find a directory /*{{{*/
+// ---------------------------------------------------------------------
+/* Directories are stored as the base dir in the Parent node and the
+ */
+string Configuration::FindDir(const char *Name,const char *Default = 0)
+{
+ Item *Itm = Lookup(Name,false);
+ if (Itm == 0 || Itm->Value.empty() == true)
+ {
+ if (Default == 0)
+ return string();
+ else
+ return Default;
+ }
+
+ if (Itm->Value[0] == '/' || Itm->Parent == 0)
+ return Itm->Value;
+ if (Itm->Parent->Value.end()[-1] == '/')
+ return Itm->Parent->Value + Itm->Value;
+ else
+ return Itm->Parent->Value + '/' + Itm->Value;
+}
+ /*}}}*/
// Configuration::FindI - Find an integer value /*{{{*/
// ---------------------------------------------------------------------
/* */
diff --git a/apt-pkg/contrib/configuration.h b/apt-pkg/contrib/configuration.h
index 7476346ef..bd06f5e37 100644
--- a/apt-pkg/contrib/configuration.h
+++ b/apt-pkg/contrib/configuration.h
@@ -1,6 +1,6 @@
// -*- mode: cpp; mode: fold -*-
// Description /*{{{*/
-// $Id: configuration.h,v 1.1 1998/07/07 04:17:10 jgg Exp $
+// $Id: configuration.h,v 1.2 1998/07/09 05:12:34 jgg Exp $
/* ######################################################################
Configuration Class
@@ -21,8 +21,8 @@
##################################################################### */
/*}}}*/
// Header section: pkglib
-#ifndef PKGLIB_TAGFILE_H
-#define PKGLIB_TAGFILE_H
+#ifndef PKGLIB_CONFIGURATION_H
+#define PKGLIB_CONFIGURATION_H
#ifdef __GNUG__
#pragma interface "pkglib/configuration.h"
@@ -36,6 +36,7 @@ class Configuration
{
string Value;
string Tag;
+ Item *Parent;
Item *Child;
Item *Next;
Item() : Child(0), Next(0) {};
@@ -48,11 +49,12 @@ class Configuration
public:
string Find(const char *Name,const char *Default = 0);
+ string FindDir(const char *Name,const char *Default = 0);
int FindI(const char *Name,int Default = 0);
void Set(const char *Name,string Value);
void Set(const char *Name,int Value);
-
+
Configuration();
};
diff --git a/apt-pkg/contrib/strutl.h b/apt-pkg/contrib/strutl.h
index 44a10c2f3..0aabf0186 100644
--- a/apt-pkg/contrib/strutl.h
+++ b/apt-pkg/contrib/strutl.h
@@ -1,6 +1,6 @@
// -*- mode: cpp; mode: fold -*-
// Description /*{{{*/
-// $Id: strutl.h,v 1.1 1998/07/07 04:17:16 jgg Exp $
+// $Id: strutl.h,v 1.2 1998/07/09 05:12:35 jgg Exp $
/* ######################################################################
String Util - These are some usefull string functions
@@ -31,6 +31,8 @@ string SubstVar(string Str,string Subst,string Contents);
string Base64Encode(string Str);
int stringcmp(const char *A,const char *AEnd,const char *B,const char *BEnd);
+inline int stringcmp(const char *A,const char *AEnd,const char *B) {return stringcmp(A,AEnd,B,B+strlen(B));};
int stringcasecmp(const char *A,const char *AEnd,const char *B,const char *BEnd);
+inline int stringcasecmp(const char *A,const char *AEnd,const char *B) {return stringcasecmp(A,AEnd,B,B+strlen(B));};
#endif