Explorar o código

Checkpoint
Author: jgg
Date: 1998-07-04 05:57:34 GMT
Checkpoint

Arch Librarian %!s(int64=22) %!d(string=hai) anos
pai
achega
f55a958ff2

+ 7 - 2
apt-pkg/cacheiterators.h

@@ -1,6 +1,6 @@
 // -*- mode: cpp; mode: fold -*-
 // -*- mode: cpp; mode: fold -*-
 // Description								/*{{{*/
 // Description								/*{{{*/
-// $Id: cacheiterators.h,v 1.1 1998/07/02 02:58:12 jgg Exp $
+// $Id: cacheiterators.h,v 1.2 1998/07/04 05:57:34 jgg Exp $
 /* ######################################################################
 /* ######################################################################
    
    
    Cache Iterators - Iterators for navigating the cache structure
    Cache Iterators - Iterators for navigating the cache structure
@@ -65,6 +65,7 @@ class pkgCache::PkgIterator
    inline VerIterator CurrentVer() const;
    inline VerIterator CurrentVer() const;
    inline DepIterator RevDependsList() const;
    inline DepIterator RevDependsList() const;
    inline PrvIterator ProvidesList() const;
    inline PrvIterator ProvidesList() const;
+   inline unsigned long Index() const {return Pkg - Owner->PkgP;};
    OkState State() const;
    OkState State() const;
    
    
    // Constructors
    // Constructors
@@ -116,8 +117,9 @@ class pkgCache::VerIterator
    inline PkgIterator ParentPkg() const {return PkgIterator(Owner,Owner.PkgP + Ver->ParentPkg);};
    inline PkgIterator ParentPkg() const {return PkgIterator(Owner,Owner.PkgP + Ver->ParentPkg);};
    inline DepIterator DependsList() const;
    inline DepIterator DependsList() const;
    inline PrvIterator ProvidesList() const;
    inline PrvIterator ProvidesList() const;
+   inline unsigned long Index() const {return Ver - Owner.VerP;};
 
 
-   inline VerIterator(pkgCache &Owner,Version *Trg) : Ver(Trg), Owner(Owner) 
+   inline VerIterator(pkgCache &Owner,Version *Trg = 0) : Ver(Trg), Owner(Owner) 
    { 
    { 
       if (Ver == 0)
       if (Ver == 0)
 	 Ver = Owner.VerP;
 	 Ver = Owner.VerP;
@@ -161,6 +163,7 @@ class pkgCache::DepIterator
    inline PkgIterator ParentPkg() {return PkgIterator(*Owner,Owner->PkgP + Owner->VerP[Dep->ParentVer].ParentPkg);};
    inline PkgIterator ParentPkg() {return PkgIterator(*Owner,Owner->PkgP + Owner->VerP[Dep->ParentVer].ParentPkg);};
    bool IsCritical();
    bool IsCritical();
    inline bool Reverse() {return Type == DepRev;};
    inline bool Reverse() {return Type == DepRev;};
+   inline unsigned long Index() const {return Dep - Owner->DepP;};
       
       
    inline DepIterator(pkgCache &Owner,Dependency *Trg,Version * = 0) :
    inline DepIterator(pkgCache &Owner,Dependency *Trg,Version * = 0) :
           Dep(Trg), Type(DepVer), Owner(&Owner) 
           Dep(Trg), Type(DepVer), Owner(&Owner) 
@@ -210,6 +213,7 @@ class pkgCache::PrvIterator
    inline PkgIterator ParentPkg() {return PkgIterator(*Owner,Owner->PkgP + Prv->ParentPkg);};
    inline PkgIterator ParentPkg() {return PkgIterator(*Owner,Owner->PkgP + Prv->ParentPkg);};
    inline VerIterator OwnerVer() {return VerIterator(*Owner,Owner->VerP + Prv->Version);};
    inline VerIterator OwnerVer() {return VerIterator(*Owner,Owner->VerP + Prv->Version);};
    inline PkgIterator OwnerPkg() {return PkgIterator(*Owner,Owner->PkgP + Owner->VerP[Prv->Version].ParentPkg);};
    inline PkgIterator OwnerPkg() {return PkgIterator(*Owner,Owner->PkgP + Owner->VerP[Prv->Version].ParentPkg);};
+   inline unsigned long Index() const {return Prv - Owner->ProvideP;};
 
 
    inline PrvIterator(pkgCache &Owner,Provides *Trg,Version *) :
    inline PrvIterator(pkgCache &Owner,Provides *Trg,Version *) :
           Prv(Trg), Type(PrvVer), Owner(&Owner) 
           Prv(Trg), Type(PrvVer), Owner(&Owner) 
@@ -252,6 +256,7 @@ class pkgCache::PkgFileIterator
    inline const char *FileName() const {return File->FileName == 0?0:Owner->StrP + File->FileName;};
    inline const char *FileName() const {return File->FileName == 0?0:Owner->StrP + File->FileName;};
    inline const char *Version() const {return File->Version == 0?0:Owner->StrP + File->Version;};
    inline const char *Version() const {return File->Version == 0?0:Owner->StrP + File->Version;};
    inline const char *Distribution() const {return File->Distribution == 0?0:Owner->StrP + File->Distribution;};
    inline const char *Distribution() const {return File->Distribution == 0?0:Owner->StrP + File->Distribution;};
+   inline unsigned long Index() const {return File - Owner->PkgFileP;};
 
 
    bool IsOk();
    bool IsOk();
    
    

+ 2 - 2
apt-pkg/contrib/fileutl.cc

@@ -1,6 +1,6 @@
 // -*- mode: cpp; mode: fold -*-
 // -*- mode: cpp; mode: fold -*-
 // Description								/*{{{*/
 // Description								/*{{{*/
-// $Id: fileutl.cc,v 1.1 1998/07/02 02:58:13 jgg Exp $
+// $Id: fileutl.cc,v 1.2 1998/07/04 05:57:41 jgg Exp $
 /* ######################################################################
 /* ######################################################################
    
    
    File Utilities
    File Utilities
@@ -14,7 +14,7 @@
    ##################################################################### */
    ##################################################################### */
 									/*}}}*/
 									/*}}}*/
 // Include Files							/*{{{*/
 // Include Files							/*{{{*/
-#include <fileutl.h>
+#include <pkglib/fileutl.h>
 #include <pkglib/error.h>
 #include <pkglib/error.h>
 
 
 #include <unistd.h>
 #include <unistd.h>

+ 9 - 7
apt-pkg/contrib/mmap.cc

@@ -1,6 +1,6 @@
 // -*- mode: cpp; mode: fold -*-
 // -*- mode: cpp; mode: fold -*-
 // Description								/*{{{*/
 // Description								/*{{{*/
-// $Id: mmap.cc,v 1.1 1998/07/02 02:58:13 jgg Exp $
+// $Id: mmap.cc,v 1.2 1998/07/04 05:57:42 jgg Exp $
 /* ######################################################################
 /* ######################################################################
    
    
    MMap Class - Provides 'real' mmap or a faked mmap using read().
    MMap Class - Provides 'real' mmap or a faked mmap using read().
@@ -142,11 +142,14 @@ DynamicMMap::~DynamicMMap()
 									/*}}}*/
 									/*}}}*/
 // DynamicMMap::RawAllocate - Allocate a raw chunk of unaligned space	/*{{{*/
 // DynamicMMap::RawAllocate - Allocate a raw chunk of unaligned space	/*{{{*/
 // ---------------------------------------------------------------------
 // ---------------------------------------------------------------------
-/* */
-unsigned long DynamicMMap::RawAllocate(unsigned long Size)
+/* This allocates a block of memory aligned to the given size */
+unsigned long DynamicMMap::RawAllocate(unsigned long Size,unsigned long Aln)
 {
 {
    unsigned long Result = iSize;
    unsigned long Result = iSize;
-   iSize += Size;
+   if (Aln != 0)
+      Result += Aln - (iSize%Aln);
+   
+   iSize = Result + Size;
    
    
    // Just in case error check
    // Just in case error check
    if (Result > WorkSpace)
    if (Result > WorkSpace)
@@ -154,7 +157,6 @@ unsigned long DynamicMMap::RawAllocate(unsigned long Size)
       _error->Error("Dynamic MMap ran out of room");
       _error->Error("Dynamic MMap ran out of room");
       return 0;
       return 0;
    }
    }
-
    return Result;
    return Result;
 }
 }
 									/*}}}*/
 									/*}}}*/
@@ -194,9 +196,9 @@ unsigned long DynamicMMap::Allocate(unsigned long ItemSize)
    if (I->Count == 0)
    if (I->Count == 0)
    {
    {
       I->Count = 20*1024/ItemSize;
       I->Count = 20*1024/ItemSize;
-      I->Start = RawAllocate(I->Count*ItemSize);
+      I->Start = RawAllocate(I->Count*ItemSize,ItemSize);
    }   
    }   
-   
+
    I->Count--;
    I->Count--;
    unsigned long Result = I->Start;
    unsigned long Result = I->Start;
    I->Start += ItemSize;
    I->Start += ItemSize;

+ 2 - 2
apt-pkg/contrib/mmap.h

@@ -1,6 +1,6 @@
 // -*- mode: cpp; mode: fold -*-
 // -*- mode: cpp; mode: fold -*-
 // Description								/*{{{*/
 // Description								/*{{{*/
-// $Id: mmap.h,v 1.1 1998/07/02 02:58:13 jgg Exp $
+// $Id: mmap.h,v 1.2 1998/07/04 05:57:43 jgg Exp $
 /* ######################################################################
 /* ######################################################################
    
    
    MMap Class - Provides 'real' mmap or a faked mmap using read().
    MMap Class - Provides 'real' mmap or a faked mmap using read().
@@ -79,7 +79,7 @@ class DynamicMMap : public MMap
    public:
    public:
 
 
    // Allocation
    // Allocation
-   unsigned long RawAllocate(unsigned long Size);
+   unsigned long RawAllocate(unsigned long Size,unsigned long Aln = 0);
    unsigned long Allocate(unsigned long ItemSize);
    unsigned long Allocate(unsigned long ItemSize);
    unsigned long WriteString(const char *String,unsigned long Len = 0);
    unsigned long WriteString(const char *String,unsigned long Len = 0);
    inline unsigned long WriteString(string S) {return WriteString(S.begin(),S.size());};
    inline unsigned long WriteString(string S) {return WriteString(S.begin(),S.size());};

+ 255 - 0
apt-pkg/deb/deblistparser.cc

@@ -0,0 +1,255 @@
+// -*- mode: cpp; mode: fold -*-
+// Description								/*{{{*/
+// $Id: deblistparser.cc,v 1.1 1998/07/04 05:58:08 jgg Exp $
+/* ######################################################################
+   
+   Package Cache Generator - Generator for the cache structure.
+   
+   This builds the cache structure from the abstract package list parser. 
+   
+   ##################################################################### */
+									/*}}}*/
+// Include Files							/*{{{*/
+#include <pkglib/deblistparser.h>
+#include <pkglib/error.h>
+#include <system.h>
+									/*}}}*/
+
+// ListParser::debListParser - Constructor				/*{{{*/
+// ---------------------------------------------------------------------
+/* */
+debListParser::debListParser(File &File) : Tags(File)
+{
+   Step();
+}
+									/*}}}*/
+// ListParser::FindTag - Find the tag and return a string		/*{{{*/
+// ---------------------------------------------------------------------
+/* */
+string debListParser::FindTag(const char *Tag)
+{
+   const char *Start;
+   const char *Stop;
+   if (Section.Find(Tag,Start,Stop) == false)
+      return string();
+   return string(Start,Stop - Start);
+}
+									/*}}}*/
+// ListParser::UniqFindTagWrite - Find the tag and write a unq string	/*{{{*/
+// ---------------------------------------------------------------------
+/* */
+unsigned long debListParser::UniqFindTagWrite(const char *Tag)
+{
+   const char *Start;
+   const char *Stop;
+   if (Section.Find(Tag,Start,Stop) == false)
+      return 0;
+   return WriteUniqString(Start,Stop - Start);
+}
+									/*}}}*/
+// ListParser::HandleFlag - Sets a flag variable based on a tag		/*{{{*/
+// ---------------------------------------------------------------------
+/* This checks the tag for true/false yes/no etc */
+bool debListParser::HandleFlag(const char *Tag,unsigned long &Flags,
+			       unsigned long Flag)
+{
+   const char *Start;
+   const char *Stop;
+   if (Section.Find(Tag,Start,Stop) == false)
+      return true;
+   
+   int Set = 2;
+   if (strncasecmp(Start,"yes",Stop - Start) == 0)
+      Set = 1;
+   if (strncasecmp(Start,"true",Stop - Start) == 0)
+      Set = 1;
+   if (strncasecmp(Start,"no",Stop - Start) == 0)
+      Set = 0;
+   if (strncasecmp(Start,"false",Stop - Start) == 0)
+      Set = 0;
+   if (Set == 2)
+   {
+      _error->Warning("Unknown flag value");
+      return true;
+   }
+   
+   if (Set == 0)
+      Flags &= ~Flag;
+   if (Set == 1)
+      Flags |= Flag;
+   return true;
+}
+									/*}}}*/
+// ListParser::Package - Return the package name			/*{{{*/
+// ---------------------------------------------------------------------
+/* This is to return the name of the package this section describes */
+string debListParser::Package()
+{
+   string Result = FindTag("Package");
+   if (Result.empty() == true)
+      _error->Error("Encoutered a section with no Package: header");
+   return Result;
+}
+									/*}}}*/
+// ListParser::Version - Return the version string			/*{{{*/
+// ---------------------------------------------------------------------
+/* This is to return the string describing the version in debian form,
+   epoch:upstream-release. If this returns the blank string then the 
+   entry is assumed to only describe package properties */
+string debListParser::Version()
+{
+   return FindTag("Version");
+}
+									/*}}}*/
+// ListParser::NewPackage - Fill in the package structure		/*{{{*/
+// ---------------------------------------------------------------------
+/* This is called when a new package structure is created. It must fill
+   in the static package information. */
+bool debListParser::NewPackage(pkgCache::PkgIterator Pkg)
+{
+   // Debian doesnt have anything, everything is condionally megered
+   return true;
+}
+									/*}}}*/
+// ListParser::NewVersion - Fill in the version structure		/*{{{*/
+// ---------------------------------------------------------------------
+/* */
+bool debListParser::NewVersion(pkgCache::VerIterator Ver)
+{   
+   return true;
+}
+									/*}}}*/
+// ListParser::UsePackage - Update a package structure			/*{{{*/
+// ---------------------------------------------------------------------
+/* This is called to update the package with any new information 
+   that might be found in the section */
+bool debListParser::UsePackage(pkgCache::PkgIterator Pkg,
+			       pkgCache::VerIterator Ver)
+{
+   if (Pkg->Section == 0)
+      if ((Pkg->Section = UniqFindTagWrite("Section")) == 0)
+	 return false;
+   if (HandleFlag("Essential",Pkg->Flags,pkgCache::Essential) == false)
+      return false;
+   if (HandleFlag("Immediate-Configure",Pkg->Flags,pkgCache::ImmediateConf) == false)
+      return false;
+   if (ParseStatus(Pkg,Ver) == false)
+      return false;
+   return true;
+}
+									/*}}}*/
+// ListParser::ParseStatus - Parse the status feild			/*{{{*/
+// ---------------------------------------------------------------------
+/* Status lines are of the form,
+     Status: want flag status
+   want = unknown, install, hold, deinstall, purge
+   flag = ok, reinstreq, hold, hold-reinstreq
+   status = not-installed, unpacked, half-configured, uninstalled,
+            half-installed, config-files, post-inst-failed, 
+            removal-failed, installed
+   
+   Some of the above are obsolete (I think?) flag = hold-* and 
+   status = post-inst-failed, removal-failed at least.
+ */
+bool debListParser::ParseStatus(pkgCache::PkgIterator Pkg,
+				pkgCache::VerIterator Ver)
+{
+   const char *Start;
+   const char *Stop;
+   if (Section.Find("Status",Start,Stop) == false)
+      return true;
+   
+   // Isolate the first word
+   const char *I = Start;
+   for(; I < Stop && *I != ' '; I++);
+   if (I >= Stop || *I != ' ')
+      return _error->Error("Malformed Status line");
+
+   // Process the want field
+   WordList WantList[] = {{"unknown",pkgCache::Unknown},
+                          {"install",pkgCache::Install},
+                          {"hold",pkgCache::Hold},
+                          {"deinstall",pkgCache::DeInstall},
+                          {"purge",pkgCache::Purge}};
+   if (GrabWord(string(Start,I-Start),WantList,
+		_count(WantList),Pkg->SelectedState) == false)
+      return _error->Error("Malformed 1st word in the Status line");
+
+   // Isloate the next word
+   I++;
+   Start = I;
+   for(; I < Stop && *I != ' '; I++);
+   if (I >= Stop || *I != ' ')
+      return _error->Error("Malformed status line, no 2nd word");
+
+   // Process the flag field
+   WordList FlagList[] = {{"ok",pkgCache::Ok},
+                          {"reinstreq",pkgCache::ReInstReq},
+                          {"hold",pkgCache::HoldInst},
+                          {"hold-reinstreq",pkgCache::HoldReInstReq}};
+   if (GrabWord(string(Start,I-Start),FlagList,
+		_count(FlagList),Pkg->InstState) == false)
+      return _error->Error("Malformed 2nd word in the Status line");
+
+   // Isloate the last word
+   I++;
+   Start = I;
+   for(; I < Stop && *I != ' '; I++);
+   if (I != Stop)
+      return _error->Error("Malformed Status line, no 3rd word");
+
+   // Process the flag field
+   WordList StatusList[] = {{"not-installed",pkgCache::NotInstalled},
+                            {"unpacked",pkgCache::UnPacked},
+                            {"half-configured",pkgCache::HalfConfigured},
+                            {"installed",pkgCache::Installed},
+                            {"uninstalled",pkgCache::UnInstalled},
+                            {"half-installed",pkgCache::HalfInstalled},
+                            {"config-files",pkgCache::ConfigFiles},
+                            {"post-inst-failed",pkgCache::HalfConfigured},
+                            {"removal-failed",pkgCache::HalfInstalled}};
+   if (GrabWord(string(Start,I-Start),StatusList,
+		_count(StatusList),Pkg->CurrentState) == false)
+      return _error->Error("Malformed 3rd word in the Status line");
+
+   /* A Status line marks the package as indicating the current
+      version as well. Only if it is actually installed.. Otherwise
+      the interesting dpkg handling of the status file creates bogus 
+      entries. */
+   if (!(Pkg->CurrentState == pkgCache::NotInstalled ||
+	 Pkg->CurrentState == pkgCache::ConfigFiles))
+   {
+      if (Ver.end() == true)
+	 _error->Warning("Encountered status field in a non-version description");
+      else
+	 Pkg->CurrentVer = Ver.Index();
+   }
+   
+   return true;
+}
+									/*}}}*/
+// ListParser::GrabWord - Matches a word and returns			/*{{{*/
+// ---------------------------------------------------------------------
+/* Looks for a word in a list of words - for ParseStatus */
+bool debListParser::GrabWord(string Word,WordList *List,int Count,
+			     unsigned char &Out)
+{
+   for (int C = 0; C != Count; C++)
+   {
+      if (strcasecmp(Word.c_str(),List[C].Str) == 0)
+      {
+	 Out = List[C].Val;
+	 return true;
+      }
+   }
+   return false;
+}
+									/*}}}*/
+// ListParser::Step - Move to the next section in the file		/*{{{*/
+// ---------------------------------------------------------------------
+/* */
+bool debListParser::Step()
+{
+   return Tags.Step(Section);
+}
+									/*}}}*/

+ 51 - 0
apt-pkg/deb/deblistparser.h

@@ -0,0 +1,51 @@
+// -*- mode: cpp; mode: fold -*-
+// Description								/*{{{*/
+// $Id: deblistparser.h,v 1.1 1998/07/04 05:58:08 jgg Exp $
+/* ######################################################################
+   
+   Debian Package List Parser - This implements the abstract parser 
+   interface for Debian package files
+   
+   ##################################################################### */
+									/*}}}*/
+// Header section: pkglib
+#ifndef PKGLIB_DEBLISTPARSER_H
+#define PKGLIB_DEBLISTPARSER_H
+
+#include <pkglib/pkgcachegen.h>
+#include <pkglib/tagfile.h>
+
+class debListParser : public pkgCacheGenerator::ListParser
+{
+   pkgTagFile Tags;
+   pkgTagSection Section;
+   
+   // Parser Helper
+   struct WordList
+   {
+      char *Str;
+      unsigned char Val;
+   };
+   
+   string FindTag(const char *Tag);
+   unsigned long UniqFindTagWrite(const char *Tag);
+   bool HandleFlag(const char *Tag,unsigned long &Flags,unsigned long Flag);
+   bool ParseStatus(pkgCache::PkgIterator Pkg,pkgCache::VerIterator Ver);
+   bool GrabWord(string Word,WordList *List,int Count,unsigned char &Out);
+   
+   public:
+   
+   // These all operate against the current section
+   virtual string Package();
+   virtual string Version();
+   virtual bool NewVersion(pkgCache::VerIterator Ver);
+   virtual bool NewPackage(pkgCache::PkgIterator Pkg);
+   virtual bool UsePackage(pkgCache::PkgIterator Pkg,
+			   pkgCache::VerIterator Ver);
+
+   virtual bool Step();
+   
+   debListParser(File &File);
+};
+
+#endif

+ 16 - 16
apt-pkg/pkgcache.cc

@@ -1,6 +1,6 @@
 // -*- mode: cpp; mode: fold -*-
 // -*- mode: cpp; mode: fold -*-
 // Description								/*{{{*/
 // Description								/*{{{*/
-// $Id: pkgcache.cc,v 1.1 1998/07/02 02:58:12 jgg Exp $
+// $Id: pkgcache.cc,v 1.2 1998/07/04 05:57:35 jgg Exp $
 /* ######################################################################
 /* ######################################################################
    
    
    Package Cache - Accessor code for the cache
    Package Cache - Accessor code for the cache
@@ -159,7 +159,12 @@ pkgCache::PkgIterator pkgCache::FindPkg(string Name)
 }
 }
 									/*}}}*/
 									/*}}}*/
 
 
-// Cache::PkgIterator - operator ++ - Postfix incr			/*{{{*/
+// Bases for iterator classes						/*{{{*/
+void pkgCache::VerIterator::_dummy() {}
+void pkgCache::DepIterator::_dummy() {}
+void pkgCache::PrvIterator::_dummy() {}
+									/*}}}*/
+// PkgIterator::operator ++ - Postfix incr				/*{{{*/
 // ---------------------------------------------------------------------
 // ---------------------------------------------------------------------
 /* This will advance to the next logical package in the hash table. */
 /* This will advance to the next logical package in the hash table. */
 void pkgCache::PkgIterator::operator ++(int) 
 void pkgCache::PkgIterator::operator ++(int) 
@@ -176,23 +181,18 @@ void pkgCache::PkgIterator::operator ++(int)
    }
    }
 };
 };
 									/*}}}*/
 									/*}}}*/
-// Bases for iterator classes						/*{{{*/
-void pkgCache::VerIterator::_dummy() {}
-void pkgCache::DepIterator::_dummy() {}
-void pkgCache::PrvIterator::_dummy() {}
-									/*}}}*/
 // PkgIterator::State - Check the State of the package			/*{{{*/
 // PkgIterator::State - Check the State of the package			/*{{{*/
 // ---------------------------------------------------------------------
 // ---------------------------------------------------------------------
 /* By this we mean if it is either cleanly installed or cleanly removed. */
 /* By this we mean if it is either cleanly installed or cleanly removed. */
 pkgCache::PkgIterator::OkState pkgCache::PkgIterator::State() const
 pkgCache::PkgIterator::OkState pkgCache::PkgIterator::State() const
 {
 {
-   if (Pkg->CurrentState == pkgSTATE_UnPacked ||
-       Pkg->CurrentState == pkgSTATE_HalfConfigured)
+   if (Pkg->CurrentState == UnPacked ||
+       Pkg->CurrentState == HalfConfigured)
       return NeedsConfigure;
       return NeedsConfigure;
    
    
-   if (Pkg->CurrentState == pkgSTATE_UnInstalled ||
-       Pkg->CurrentState == pkgSTATE_HalfInstalled ||
-       Pkg->InstState != pkgSTATE_Ok)
+   if (Pkg->CurrentState == UnInstalled ||
+       Pkg->CurrentState == HalfInstalled ||
+       Pkg->InstState != Ok)
       return NeedsUnpack;
       return NeedsUnpack;
       
       
    return NeedsNothing;
    return NeedsNothing;
@@ -204,8 +204,8 @@ pkgCache::PkgIterator::OkState pkgCache::PkgIterator::State() const
    conflicts. */
    conflicts. */
 bool pkgCache::DepIterator::IsCritical()
 bool pkgCache::DepIterator::IsCritical()
 {
 {
-   if (Dep->Type == pkgDEP_Conflicts || Dep->Type == pkgDEP_Depends ||
-       Dep->Type == pkgDEP_PreDepends)
+   if (Dep->Type == Conflicts || Dep->Type == Depends ||
+       Dep->Type == PreDepends)
       return true;
       return true;
    return false;
    return false;
 }
 }
@@ -280,7 +280,7 @@ pkgCache::Version **pkgCache::DepIterator::AllTargets()
 	 if (pkgCheckDep(TargetVer(),I.VerStr(),Dep->CompareOp) == false)
 	 if (pkgCheckDep(TargetVer(),I.VerStr(),Dep->CompareOp) == false)
 	    continue;
 	    continue;
 
 
-	 if (Dep->Type == pkgDEP_Conflicts && ParentPkg() == I.ParentPkg())
+	 if (Dep->Type == Conflicts && ParentPkg() == I.ParentPkg())
 	    continue;
 	    continue;
 	 
 	 
 	 Size++;
 	 Size++;
@@ -294,7 +294,7 @@ pkgCache::Version **pkgCache::DepIterator::AllTargets()
 	 if (pkgCheckDep(TargetVer(),I.ProvideVersion(),Dep->CompareOp) == false)
 	 if (pkgCheckDep(TargetVer(),I.ProvideVersion(),Dep->CompareOp) == false)
 	    continue;
 	    continue;
 	 
 	 
-	 if (Dep->Type == pkgDEP_Conflicts && ParentPkg() == I.OwnerPkg())
+	 if (Dep->Type == Conflicts && ParentPkg() == I.OwnerPkg())
 	    continue;
 	    continue;
 	 
 	 
 	 Size++;
 	 Size++;

+ 18 - 59
apt-pkg/pkgcache.h

@@ -1,6 +1,6 @@
 // -*- mode: cpp; mode: fold -*-
 // -*- mode: cpp; mode: fold -*-
 // Description								/*{{{*/
 // Description								/*{{{*/
-// $Id: pkgcache.h,v 1.1 1998/07/02 02:58:12 jgg Exp $
+// $Id: pkgcache.h,v 1.2 1998/07/04 05:57:36 jgg Exp $
 /* ######################################################################
 /* ######################################################################
    
    
    Cache - Structure definitions for the cache file
    Cache - Structure definitions for the cache file
@@ -24,62 +24,6 @@
 #include <time.h>
 #include <time.h>
 #include <pkglib/mmap.h>
 #include <pkglib/mmap.h>
 
 
-// Definitions for Depends::Type
-#define pkgDEP_Depends 1
-#define pkgDEP_PreDepends 2
-#define pkgDEP_Suggests 3
-#define pkgDEP_Recommends 4
-#define pkgDEP_Conflicts 5
-#define pkgDEP_Replaces 6
-
-// Definitions for Version::Priority
-#define pkgPRIO_Important 1
-#define pkgPRIO_Required 2
-#define pkgPRIO_Standard 3
-#define pkgPRIO_Optional 4
-#define pkgPRIO_Extra 5
-
-// Definitions for Package::SelectedState
-#define pkgSTATE_Unkown 0
-#define pkgSTATE_Install 1
-#define pkgSTATE_Hold 2
-#define pkgSTATE_DeInstall 3
-#define pkgSTATE_Purge 4
-
-// Definitions for Package::Flags
-#define pkgFLAG_Auto (1 << 0)
-#define pkgFLAG_New (1 << 1)
-#define pkgFLAG_Obsolete (1 << 2)
-#define pkgFLAG_Essential (1 << 3)
-#define pkgFLAG_ImmediateConf (1 << 4)
-
-// Definitions for Package::InstState
-#define pkgSTATE_Ok 0
-#define pkgSTATE_ReInstReq 1
-#define pkgSTATE_Hold 2
-#define pkgSTATE_HoldReInstReq 3
-
-// Definitions for Package::CurrentState
-#define pkgSTATE_NotInstalled 0
-#define pkgSTATE_UnPacked 1
-#define pkgSTATE_HalfConfigured 2
-#define pkgSTATE_UnInstalled 3
-#define pkgSTATE_HalfInstalled 4
-#define pkgSTATE_ConfigFiles 5
-#define pkgSTATE_Installed 6
-
-// Definitions for PackageFile::Flags
-#define pkgFLAG_NotSource (1 << 0)
-
-// Definitions for Dependency::CompareOp
-#define pkgOP_OR 0x10
-#define pkgOP_LESSEQ 0x1
-#define pkgOP_GREATEREQ 0x2
-#define pkgOP_LESS 0x3
-#define pkgOP_GREATER 0x4
-#define pkgOP_EQUALS 0x5
-#define pkgOP_NOTEQUALS 0x6
-
 class pkgCache
 class pkgCache
 {
 {
    public:
    public:
@@ -103,6 +47,21 @@ class pkgCache
    friend DepIterator;
    friend DepIterator;
    friend PrvIterator;
    friend PrvIterator;
    friend PkgFileIterator;
    friend PkgFileIterator;
+
+   // These are all the constants used in the cache structures
+   enum DepType {Depends=1,PreDepends=2,Suggests=3,Recommends=4,
+                 Conflicts=5,Replaces=6};
+   enum VerPriority {Important=1,Required=2,Standard=3,Optional=5,Extra=5};
+   enum PkgSelectedState {Unknown=0,Install=1,Hold=2,DeInstall=3,Purge=4};
+   enum PkgFlags {Auto=(1<<0),New=(1<<1),Obsolete=(1<<2),Essential=(1<<3),
+                  ImmediateConf=(1<<4)};
+   enum PkgInstState {Ok=0,ReInstReq=1,HoldInst=2,HoldReInstReq=3};
+   enum PkgCurrentState {NotInstalled=0,UnPacked=1,HalfConfigured=2,
+                         UnInstalled=3,HalfInstalled=4,ConfigFiles=5,
+                         Installed=6};
+   enum PkgFFlags {NotSource=(1<<0)};
+   enum DepCompareOp {Or=0x10,LessEq=0x1,GreaterEq=0x2,Less=0x3,
+                      Greater=0x4,Equals=0x5,NotEquals=0x6};
    
    
    protected:
    protected:
    
    
@@ -204,7 +163,7 @@ struct pkgCache::Package
    unsigned char CurrentState;      // State
    unsigned char CurrentState;      // State
    
    
    unsigned short ID;
    unsigned short ID;
-   unsigned short Flags;
+   unsigned long Flags;
 };
 };
 
 
 struct pkgCache::PackageFile
 struct pkgCache::PackageFile
@@ -218,7 +177,7 @@ struct pkgCache::PackageFile
    // Linked list
    // Linked list
    unsigned long NextFile;        // PackageFile
    unsigned long NextFile;        // PackageFile
    unsigned short ID;
    unsigned short ID;
-   unsigned short Flags;
+   unsigned long Flags;
    time_t mtime;                  // Modification time for the file
    time_t mtime;                  // Modification time for the file
 };
 };
 
 

+ 81 - 12
apt-pkg/pkgcachegen.cc

@@ -1,6 +1,6 @@
 // -*- mode: cpp; mode: fold -*-
 // -*- mode: cpp; mode: fold -*-
 // Description								/*{{{*/
 // Description								/*{{{*/
-// $Id: pkgcachegen.cc,v 1.1 1998/07/02 02:58:12 jgg Exp $
+// $Id: pkgcachegen.cc,v 1.2 1998/07/04 05:57:37 jgg Exp $
 /* ######################################################################
 /* ######################################################################
    
    
    Package Cache Generator - Generator for the cache structure.
    Package Cache Generator - Generator for the cache structure.
@@ -58,13 +58,12 @@ pkgCacheGenerator::~pkgCacheGenerator()
 bool pkgCacheGenerator::MergeList(ListParser &List)
 bool pkgCacheGenerator::MergeList(ListParser &List)
 {
 {
    List.Owner = this;
    List.Owner = this;
-   
    do
    do
    {
    {
       // Get a pointer to the package structure
       // Get a pointer to the package structure
       string Package = List.Package();
       string Package = List.Package();
       pkgCache::PkgIterator Pkg = Cache.FindPkg(Package);
       pkgCache::PkgIterator Pkg = Cache.FindPkg(Package);
-      if (Pkg.end() == false)
+      if (Pkg.end() == true)
       {
       {
 	 if (NewPackage(Pkg,Package) == false)
 	 if (NewPackage(Pkg,Package) == false)
 	    return false;
 	    return false;
@@ -72,17 +71,22 @@ bool pkgCacheGenerator::MergeList(ListParser &List)
 	 if (List.NewPackage(Pkg) == false)
 	 if (List.NewPackage(Pkg) == false)
 	    return false;
 	    return false;
       }
       }
-      if (List.UsePackage(Pkg) == false)
-	 return false;
       
       
       /* Get a pointer to the version structure. We know the list is sorted
       /* Get a pointer to the version structure. We know the list is sorted
          so we use that fact in the search. Insertion of new versions is
          so we use that fact in the search. Insertion of new versions is
 	 done with correct sorting */
 	 done with correct sorting */
       string Version = List.Version();
       string Version = List.Version();
+      if (Version.empty() == true)
+      {
+	 if (List.UsePackage(Pkg,pkgCache::VerIterator(Cache)) == false)
+	    return false;
+	 continue;
+      }
+
       pkgCache::VerIterator Ver = Pkg.VersionList();
       pkgCache::VerIterator Ver = Pkg.VersionList();
       unsigned long *Last = &Pkg->VersionList;
       unsigned long *Last = &Pkg->VersionList;
       int Res;
       int Res;
-      for (; Ver.end() == false; Ver++, Last = &Ver->NextVer)
+      for (; Ver.end() == false; Last = &Ver->NextVer, Ver++)
       {
       {
 	 Res = pkgVersionCompare(Version.begin(),Version.end(),Ver.VerStr(),
 	 Res = pkgVersionCompare(Version.begin(),Version.end(),Ver.VerStr(),
 				 Ver.VerStr() + strlen(Ver.VerStr()));
 				 Ver.VerStr() + strlen(Ver.VerStr()));
@@ -94,6 +98,9 @@ bool pkgCacheGenerator::MergeList(ListParser &List)
          saw it */
          saw it */
       if (Res == 0)
       if (Res == 0)
       {
       {
+	 if (List.UsePackage(Pkg,Ver) == false)
+	    return false;
+	 
 	 if (NewFileVer(Ver,List) == false)
 	 if (NewFileVer(Ver,List) == false)
 	    return false;
 	    return false;
 	 
 	 
@@ -101,10 +108,14 @@ bool pkgCacheGenerator::MergeList(ListParser &List)
       }      
       }      
 
 
       // Add a new version
       // Add a new version
-      *Last = NewVersion(Ver,*Last);
+      *Last = NewVersion(Ver,Version,*Last);
+      Ver->ParentPkg = Pkg.Index();
       if (List.NewVersion(Ver) == false)
       if (List.NewVersion(Ver) == false)
 	 return false;
 	 return false;
       
       
+      if (List.UsePackage(Pkg,Ver) == false)
+	 return false;
+      
       if (NewFileVer(Ver,List) == false)
       if (NewFileVer(Ver,List) == false)
 	 return false;
 	 return false;
    }
    }
@@ -116,17 +127,17 @@ bool pkgCacheGenerator::MergeList(ListParser &List)
 // CacheGenerator::NewPackage - Add a new package			/*{{{*/
 // CacheGenerator::NewPackage - Add a new package			/*{{{*/
 // ---------------------------------------------------------------------
 // ---------------------------------------------------------------------
 /* This creates a new package structure and adds it to the hash table */
 /* This creates a new package structure and adds it to the hash table */
-bool pkgCacheGenerator::NewPackage(pkgCache::PkgIterator Pkg,string Name)
+bool pkgCacheGenerator::NewPackage(pkgCache::PkgIterator &Pkg,string Name)
 {
 {
    // Get a structure
    // Get a structure
    unsigned long Package = Map.Allocate(sizeof(pkgCache::Package));
    unsigned long Package = Map.Allocate(sizeof(pkgCache::Package));
    if (Package == 0)
    if (Package == 0)
       return false;
       return false;
    
    
-   Pkg = pkgCache::PkgIterator(Cache,Cache.PackageP + Package);
+   Pkg = pkgCache::PkgIterator(Cache,Cache.PkgP + Package);
    
    
    // Insert it into the hash table
    // Insert it into the hash table
-   unsigned long Hash = Map.Hash(Name);
+   unsigned long Hash = Cache.Hash(Name);
    Pkg->NextPackage = Cache.HeaderP->HashTable[Hash];
    Pkg->NextPackage = Cache.HeaderP->HashTable[Hash];
    Cache.HeaderP->HashTable[Hash] = Package;
    Cache.HeaderP->HashTable[Hash] = Package;
    
    
@@ -142,17 +153,34 @@ bool pkgCacheGenerator::NewPackage(pkgCache::PkgIterator Pkg,string Name)
 // CacheGenerator::NewFileVer - Create a new File<->Version association	/*{{{*/
 // CacheGenerator::NewFileVer - Create a new File<->Version association	/*{{{*/
 // ---------------------------------------------------------------------
 // ---------------------------------------------------------------------
 /* */
 /* */
-bool pkgCacheGenerator::NewFileVer(pkgCache::VerIterator Ver,
+bool pkgCacheGenerator::NewFileVer(pkgCache::VerIterator &Ver,
 				   ListParser &List)
 				   ListParser &List)
 {
 {
+   return true;
 }
 }
 									/*}}}*/
 									/*}}}*/
 // CacheGenerator::NewVersion - Create a new Version 			/*{{{*/
 // CacheGenerator::NewVersion - Create a new Version 			/*{{{*/
 // ---------------------------------------------------------------------
 // ---------------------------------------------------------------------
-/* */
+/* This puts a version structure in the linked list */
 unsigned long pkgCacheGenerator::NewVersion(pkgCache::VerIterator &Ver,
 unsigned long pkgCacheGenerator::NewVersion(pkgCache::VerIterator &Ver,
+					    string VerStr,
 					    unsigned long Next)
 					    unsigned long Next)
 {
 {
+   // Get a structure
+   unsigned long Version = Map.Allocate(sizeof(pkgCache::Version));
+   if (Version == 0)
+      return false;
+   
+   // Fill it in
+   Ver = pkgCache::VerIterator(Cache,Cache.VerP + Version);
+   Ver->File = CurrentFile - Cache.PkgFileP;
+   Ver->NextVer = Next;
+   Ver->ID = Cache.HeaderP->VersionCount++;
+   Ver->VerStr = Map.WriteString(VerStr);
+   if (Ver->VerStr == 0)
+      return false;
+   
+   return true;
 }
 }
 									/*}}}*/
 									/*}}}*/
 // CacheGenerator::SelectFile - Select the current file being parsed	/*{{{*/
 // CacheGenerator::SelectFile - Select the current file being parsed	/*{{{*/
@@ -182,3 +210,44 @@ bool pkgCacheGenerator::SelectFile(string File,unsigned long Flags)
       return false;
       return false;
 }
 }
 									/*}}}*/
 									/*}}}*/
+// CacheGenerator::WriteUniqueString - Insert a unique string		/*{{{*/
+// ---------------------------------------------------------------------
+/* This is used to create handles to strings. Given the same text it
+   always returns the same number */
+unsigned long pkgCacheGenerator::WriteUniqString(const char *S,
+						 unsigned int Size)
+{
+   // Search for an insertion point
+   pkgCache::StringItem *I = Cache.StringItemP + Cache.HeaderP->StringList;
+   int Res = 1;
+   unsigned long *Last = &Cache.HeaderP->StringList;
+   for (; I != Cache.StringItemP; Last = &I->NextItem, 
+        I = Cache.StringItemP + I->NextItem)
+   {
+      Res = strncmp(Cache.StrP + I->String,S,Size);
+      if (Res == 0 && *(Cache.StrP + I->String + Size) != 0)
+	 Res = 1;
+      if (Res >= 0)
+	 break;
+   }
+   
+   // Match
+   if (Res == 0)
+      return I - Cache.StringItemP;
+   
+   // Get a structure
+   unsigned long Item = Map.Allocate(sizeof(pkgCache::StringItem));
+   if (Item == 0)
+      return false;
+   
+   // Fill in the structure
+   pkgCache::StringItem *ItemP = Cache.StringItemP + Item;
+   ItemP->NextItem = I - Cache.StringItemP;
+   *Last = Item;
+   ItemP->String = Map.WriteString(S,Size);
+   if (ItemP->String == 0)
+      return false;
+   
+   return true;
+}
+									/*}}}*/

+ 14 - 7
apt-pkg/pkgcachegen.h

@@ -1,6 +1,6 @@
 // -*- mode: cpp; mode: fold -*-
 // -*- mode: cpp; mode: fold -*-
 // Description								/*{{{*/
 // Description								/*{{{*/
-// $Id: pkgcachegen.h,v 1.1 1998/07/02 02:58:13 jgg Exp $
+// $Id: pkgcachegen.h,v 1.2 1998/07/04 05:57:38 jgg Exp $
 /* ######################################################################
 /* ######################################################################
    
    
    Package Cache Generator - Generator for the cache structure.
    Package Cache Generator - Generator for the cache structure.
@@ -29,10 +29,13 @@ class pkgCacheGenerator
    string PkgFileName;
    string PkgFileName;
    pkgCache::PackageFile *CurrentFile;
    pkgCache::PackageFile *CurrentFile;
    
    
-   bool NewPackage(pkgCache::PkgIterator Pkg,string Pkg);
-   bool NewFileVer(pkgCache::VerIterator Ver,ListParser &List);
-   unsigned long NewVersion(pkgCache::VerIterator &Ver,unsigned long Next);
+   bool NewPackage(pkgCache::PkgIterator &Pkg,string Pkg);
+   bool NewFileVer(pkgCache::VerIterator &Ver,ListParser &List);
+   unsigned long NewVersion(pkgCache::VerIterator &Ver,string VerStr,unsigned long Next);
 
 
+   unsigned long WriteUniqString(const char *S,unsigned int Size);
+   inline unsigned long WriteUniqString(string S) {return WriteUniqString(S);};
+   
    public:
    public:
    
    
    // This is the abstract package list parser class.
    // This is the abstract package list parser class.
@@ -43,9 +46,11 @@ class pkgCacheGenerator
       
       
       protected:
       protected:
       
       
+      inline unsigned long WriteUniqString(string S) {return Owner->WriteUniqString(S);};
+      inline unsigned long WriteUniqString(const char *S,unsigned int Size) {return Owner->WriteUniqString(S,Size);};
       inline unsigned long WriteString(string S) {return Owner->Map.WriteString(S);};
       inline unsigned long WriteString(string S) {return Owner->Map.WriteString(S);};
       inline unsigned long WriteString(const char *S,unsigned int Size) {return Owner->Map.WriteString(S,Size);};
       inline unsigned long WriteString(const char *S,unsigned int Size) {return Owner->Map.WriteString(S,Size);};
-
+      
       public:
       public:
       
       
       // These all operate against the current section
       // These all operate against the current section
@@ -53,9 +58,11 @@ class pkgCacheGenerator
       virtual string Version() = 0;
       virtual string Version() = 0;
       virtual bool NewVersion(pkgCache::VerIterator Ver) = 0;
       virtual bool NewVersion(pkgCache::VerIterator Ver) = 0;
       virtual bool NewPackage(pkgCache::PkgIterator Pkg) = 0;
       virtual bool NewPackage(pkgCache::PkgIterator Pkg) = 0;
-      virtual bool UsePackage(pkgCache::PkgIterator Pkg) = 0;
-      
+      virtual bool UsePackage(pkgCache::PkgIterator Pkg,
+			      pkgCache::VerIterator Ver) = 0;
+				   
       virtual bool Step() = 0;
       virtual bool Step() = 0;
+      virtual ~ListParser() {};
    };
    };
    friend ListParser;
    friend ListParser;
 
 

+ 16 - 3
apt-pkg/tagfile.cc

@@ -1,6 +1,6 @@
 // -*- mode: cpp; mode: fold -*-
 // -*- mode: cpp; mode: fold -*-
 // Description								/*{{{*/
 // Description								/*{{{*/
-// $Id: tagfile.cc,v 1.1 1998/07/02 02:58:13 jgg Exp $
+// $Id: tagfile.cc,v 1.2 1998/07/04 05:57:39 jgg Exp $
 /* ######################################################################
 /* ######################################################################
 
 
    Fast scanner for RFC-822 type header information
    Fast scanner for RFC-822 type header information
@@ -147,18 +147,31 @@ bool pkgTagSection::Find(const char *Tag,const char *&Start,
 									/*}}}*/
 									/*}}}*/
 
 
 #include <pkglib/pkgcachegen.h>
 #include <pkglib/pkgcachegen.h>
+#include <pkglib/deblistparser.h>
 
 
 int main(int argc,char *argv[])
 int main(int argc,char *argv[])
 {
 {
    {
    {
       File F(argv[1],File::ReadOnly);
       File F(argv[1],File::ReadOnly);
-      pkgTagFile Test(F);
       File CacheF("./cache",File::WriteEmpty);
       File CacheF("./cache",File::WriteEmpty);
       DynamicMMap Map(CacheF,MMap::Public);
       DynamicMMap Map(CacheF,MMap::Public);
       pkgCacheGenerator Gen(Map);
       pkgCacheGenerator Gen(Map);
-      Gen.SelectFile("tet");
+      Gen.SelectFile(argv[1]);
+      
+      debListParser Parser(F);
+      Gen.MergeList(Parser);
    }
    }
 
 
+   {
+      File CacheF("./cache",File::WriteExists);
+      MMap Map(CacheF,MMap::Public);
+      pkgCache Cache(Map);
+      for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; I++)
+      {
+	 cout << "Package: " << I.Name() << endl;
+      }      
+   }
+   
 #if 0 
 #if 0 
    pkgTagSection I;
    pkgTagSection I;
    while (Test.Step(I) == true)
    while (Test.Step(I) == true)

+ 7 - 7
apt-pkg/version.cc

@@ -1,6 +1,6 @@
 // -*- mode: cpp; mode: fold -*-
 // -*- mode: cpp; mode: fold -*-
 // Description								/*{{{*/
 // Description								/*{{{*/
-// $Id: version.cc,v 1.1 1998/07/02 02:58:13 jgg Exp $
+// $Id: version.cc,v 1.2 1998/07/04 05:57:40 jgg Exp $
 /* ######################################################################
 /* ######################################################################
 
 
    Version - Version string 
    Version - Version string 
@@ -212,32 +212,32 @@ bool pkgCheckDep(const char *DepVer,const char *PkgVer,int Op)
    int Res = pkgVersionCompare(PkgVer,DepVer);
    int Res = pkgVersionCompare(PkgVer,DepVer);
    switch (Op & 0x0F)
    switch (Op & 0x0F)
    {
    {
-      case pkgOP_LESSEQ:
+      case pkgCache::LessEq:
       if (Res <= 0)
       if (Res <= 0)
 	 return true;
 	 return true;
       break;
       break;
       
       
-      case pkgOP_GREATEREQ:
+      case pkgCache::GreaterEq:
       if (Res >= 0)
       if (Res >= 0)
 	 return true;
 	 return true;
       break;
       break;
       
       
-      case pkgOP_LESS:
+      case pkgCache::Less:
       if (Res < 0)
       if (Res < 0)
 	 return true;
 	 return true;
       break;
       break;
       
       
-      case pkgOP_GREATER:
+      case pkgCache::Greater:
       if (Res > 0)
       if (Res > 0)
 	 return true;
 	 return true;
       break;
       break;
       
       
-      case pkgOP_EQUALS:
+      case pkgCache::Equals:
       if (Res == 0)
       if (Res == 0)
 	 return true;
 	 return true;
       break;
       break;
       
       
-      case pkgOP_NOTEQUALS:
+      case pkgCache::NotEquals:
       if (Res != 0)
       if (Res != 0)
 	 return true;
 	 return true;
       break;
       break;