// -*- mode: cpp; mode: fold -*-
// 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
inline VerIterator CurrentVer() const;
inline DepIterator RevDependsList() const;
inline PrvIterator ProvidesList() const;
+ inline unsigned long Index() const {return Pkg - Owner->PkgP;};
OkState State() const;
// Constructors
inline PkgIterator ParentPkg() const {return PkgIterator(Owner,Owner.PkgP + Ver->ParentPkg);};
inline DepIterator DependsList() 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)
Ver = Owner.VerP;
inline PkgIterator ParentPkg() {return PkgIterator(*Owner,Owner->PkgP + Owner->VerP[Dep->ParentVer].ParentPkg);};
bool IsCritical();
inline bool Reverse() {return Type == DepRev;};
+ inline unsigned long Index() const {return Dep - Owner->DepP;};
inline DepIterator(pkgCache &Owner,Dependency *Trg,Version * = 0) :
Dep(Trg), Type(DepVer), Owner(&Owner)
inline PkgIterator ParentPkg() {return PkgIterator(*Owner,Owner->PkgP + Prv->ParentPkg);};
inline VerIterator OwnerVer() {return VerIterator(*Owner,Owner->VerP + Prv->Version);};
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 *) :
Prv(Trg), Type(PrvVer), Owner(&Owner)
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 *Distribution() const {return File->Distribution == 0?0:Owner->StrP + File->Distribution;};
+ inline unsigned long Index() const {return File - Owner->PkgFileP;};
bool IsOk();
// -*- mode: cpp; mode: fold -*-
// 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
##################################################################### */
/*}}}*/
// Include Files /*{{{*/
-#include <fileutl.h>
+#include <pkglib/fileutl.h>
#include <pkglib/error.h>
#include <unistd.h>
// -*- mode: cpp; mode: fold -*-
// 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().
/*}}}*/
// 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;
- iSize += Size;
+ if (Aln != 0)
+ Result += Aln - (iSize%Aln);
+
+ iSize = Result + Size;
// Just in case error check
if (Result > WorkSpace)
_error->Error("Dynamic MMap ran out of room");
return 0;
}
-
return Result;
}
/*}}}*/
if (I->Count == 0)
{
I->Count = 20*1024/ItemSize;
- I->Start = RawAllocate(I->Count*ItemSize);
+ I->Start = RawAllocate(I->Count*ItemSize,ItemSize);
}
-
+
I->Count--;
unsigned long Result = I->Start;
I->Start += ItemSize;
// -*- mode: cpp; mode: fold -*-
// 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().
public:
// 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 WriteString(const char *String,unsigned long Len = 0);
inline unsigned long WriteString(string S) {return WriteString(S.begin(),S.size());};
--- /dev/null
+// -*- 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);
+}
+ /*}}}*/
--- /dev/null
+// -*- 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
// -*- mode: cpp; mode: fold -*-
// 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
}
/*}}}*/
-// 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. */
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 /*{{{*/
// ---------------------------------------------------------------------
/* By this we mean if it is either cleanly installed or cleanly removed. */
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;
- 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 NeedsNothing;
conflicts. */
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 false;
}
if (pkgCheckDep(TargetVer(),I.VerStr(),Dep->CompareOp) == false)
continue;
- if (Dep->Type == pkgDEP_Conflicts && ParentPkg() == I.ParentPkg())
+ if (Dep->Type == Conflicts && ParentPkg() == I.ParentPkg())
continue;
Size++;
if (pkgCheckDep(TargetVer(),I.ProvideVersion(),Dep->CompareOp) == false)
continue;
- if (Dep->Type == pkgDEP_Conflicts && ParentPkg() == I.OwnerPkg())
+ if (Dep->Type == Conflicts && ParentPkg() == I.OwnerPkg())
continue;
Size++;
// -*- mode: cpp; mode: fold -*-
// 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
#include <time.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
{
public:
friend DepIterator;
friend PrvIterator;
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:
unsigned char CurrentState; // State
unsigned short ID;
- unsigned short Flags;
+ unsigned long Flags;
};
struct pkgCache::PackageFile
// Linked list
unsigned long NextFile; // PackageFile
unsigned short ID;
- unsigned short Flags;
+ unsigned long Flags;
time_t mtime; // Modification time for the file
};
// -*- mode: cpp; mode: fold -*-
// 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.
bool pkgCacheGenerator::MergeList(ListParser &List)
{
List.Owner = this;
-
do
{
// Get a pointer to the package structure
string Package = List.Package();
pkgCache::PkgIterator Pkg = Cache.FindPkg(Package);
- if (Pkg.end() == false)
+ if (Pkg.end() == true)
{
if (NewPackage(Pkg,Package) == false)
return false;
if (List.NewPackage(Pkg) == false)
return false;
}
- if (List.UsePackage(Pkg) == false)
- return false;
/* 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
done with correct sorting */
string Version = List.Version();
+ if (Version.empty() == true)
+ {
+ if (List.UsePackage(Pkg,pkgCache::VerIterator(Cache)) == false)
+ return false;
+ continue;
+ }
+
pkgCache::VerIterator Ver = Pkg.VersionList();
unsigned long *Last = &Pkg->VersionList;
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(),
Ver.VerStr() + strlen(Ver.VerStr()));
saw it */
if (Res == 0)
{
+ if (List.UsePackage(Pkg,Ver) == false)
+ return false;
+
if (NewFileVer(Ver,List) == false)
return false;
}
// Add a new version
- *Last = NewVersion(Ver,*Last);
+ *Last = NewVersion(Ver,Version,*Last);
+ Ver->ParentPkg = Pkg.Index();
if (List.NewVersion(Ver) == false)
return false;
+ if (List.UsePackage(Pkg,Ver) == false)
+ return false;
+
if (NewFileVer(Ver,List) == false)
return false;
}
// CacheGenerator::NewPackage - Add a new package /*{{{*/
// ---------------------------------------------------------------------
/* 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
unsigned long Package = Map.Allocate(sizeof(pkgCache::Package));
if (Package == 0)
return false;
- Pkg = pkgCache::PkgIterator(Cache,Cache.PackageP + Package);
+ Pkg = pkgCache::PkgIterator(Cache,Cache.PkgP + Package);
// Insert it into the hash table
- unsigned long Hash = Map.Hash(Name);
+ unsigned long Hash = Cache.Hash(Name);
Pkg->NextPackage = Cache.HeaderP->HashTable[Hash];
Cache.HeaderP->HashTable[Hash] = Package;
// CacheGenerator::NewFileVer - Create a new File<->Version association /*{{{*/
// ---------------------------------------------------------------------
/* */
-bool pkgCacheGenerator::NewFileVer(pkgCache::VerIterator Ver,
+bool pkgCacheGenerator::NewFileVer(pkgCache::VerIterator &Ver,
ListParser &List)
{
+ return true;
}
/*}}}*/
// CacheGenerator::NewVersion - Create a new Version /*{{{*/
// ---------------------------------------------------------------------
-/* */
+/* This puts a version structure in the linked list */
unsigned long pkgCacheGenerator::NewVersion(pkgCache::VerIterator &Ver,
+ string VerStr,
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 /*{{{*/
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;
+}
+ /*}}}*/
// -*- mode: cpp; mode: fold -*-
// 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.
string PkgFileName;
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:
// This is the abstract package list parser class.
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(const char *S,unsigned int Size) {return Owner->Map.WriteString(S,Size);};
-
+
public:
// These all operate against the current section
virtual string Version() = 0;
virtual bool NewVersion(pkgCache::VerIterator Ver) = 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 ~ListParser() {};
};
friend ListParser;
// -*- mode: cpp; mode: fold -*-
// 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
/*}}}*/
#include <pkglib/pkgcachegen.h>
+#include <pkglib/deblistparser.h>
int main(int argc,char *argv[])
{
{
File F(argv[1],File::ReadOnly);
- pkgTagFile Test(F);
File CacheF("./cache",File::WriteEmpty);
DynamicMMap Map(CacheF,MMap::Public);
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
pkgTagSection I;
while (Test.Step(I) == true)
// -*- mode: cpp; mode: fold -*-
// 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
int Res = pkgVersionCompare(PkgVer,DepVer);
switch (Op & 0x0F)
{
- case pkgOP_LESSEQ:
+ case pkgCache::LessEq:
if (Res <= 0)
return true;
break;
- case pkgOP_GREATEREQ:
+ case pkgCache::GreaterEq:
if (Res >= 0)
return true;
break;
- case pkgOP_LESS:
+ case pkgCache::Less:
if (Res < 0)
return true;
break;
- case pkgOP_GREATER:
+ case pkgCache::Greater:
if (Res > 0)
return true;
break;
- case pkgOP_EQUALS:
+ case pkgCache::Equals:
if (Res == 0)
return true;
break;
- case pkgOP_NOTEQUALS:
+ case pkgCache::NotEquals:
if (Res != 0)
return true;
break;