Explorar el Código

Checkpoint
Author: jgg
Date: 1998-07-04 22:32:11 GMT
Checkpoint

Arch Librarian hace 22 años
padre
commit
0149949bce

+ 3 - 2
apt-pkg/contrib/mmap.cc

@@ -1,6 +1,6 @@
 // -*- mode: cpp; mode: fold -*-
 // -*- mode: cpp; mode: fold -*-
 // Description								/*{{{*/
 // Description								/*{{{*/
-// $Id: mmap.cc,v 1.2 1998/07/04 05:57:42 jgg Exp $
+// $Id: mmap.cc,v 1.3 1998/07/04 22:32:15 jgg Exp $
 /* ######################################################################
 /* ######################################################################
    
    
    MMap Class - Provides 'real' mmap or a faked mmap using read().
    MMap Class - Provides 'real' mmap or a faked mmap using read().
@@ -94,7 +94,8 @@ bool MMap::Close(bool DoClose)
 									/*}}}*/
 									/*}}}*/
 // MMap::Sync - Syncronize the map with the disk			/*{{{*/
 // MMap::Sync - Syncronize the map with the disk			/*{{{*/
 // ---------------------------------------------------------------------
 // ---------------------------------------------------------------------
-/* */
+/* This is done in syncronous mode - the docs indicate that this will 
+   not return till all IO is complete */
 bool MMap::Sync()
 bool MMap::Sync()
 {   
 {   
    if ((Flags & ReadOnly) == ReadOnly)
    if ((Flags & ReadOnly) == ReadOnly)

+ 73 - 5
apt-pkg/deb/deblistparser.cc

@@ -1,6 +1,6 @@
 // -*- mode: cpp; mode: fold -*-
 // -*- mode: cpp; mode: fold -*-
 // Description								/*{{{*/
 // Description								/*{{{*/
-// $Id: deblistparser.cc,v 1.1 1998/07/04 05:58:08 jgg Exp $
+// $Id: deblistparser.cc,v 1.2 1998/07/04 22:32:17 jgg Exp $
 /* ######################################################################
 /* ######################################################################
    
    
    Package Cache Generator - Generator for the cache structure.
    Package Cache Generator - Generator for the cache structure.
@@ -20,7 +20,6 @@
 /* */
 /* */
 debListParser::debListParser(File &File) : Tags(File)
 debListParser::debListParser(File &File) : Tags(File)
 {
 {
-   Step();
 }
 }
 									/*}}}*/
 									/*}}}*/
 // ListParser::FindTag - Find the tag and return a string		/*{{{*/
 // ListParser::FindTag - Find the tag and return a string		/*{{{*/
@@ -35,6 +34,30 @@ string debListParser::FindTag(const char *Tag)
    return string(Start,Stop - Start);
    return string(Start,Stop - Start);
 }
 }
 									/*}}}*/
 									/*}}}*/
+// ListParser::FindTagI - Find the tag and return an int		/*{{{*/
+// ---------------------------------------------------------------------
+/* */
+signed long debListParser::FindTagI(const char *Tag,signed long Default)
+{
+   const char *Start;
+   const char *Stop;
+   if (Section.Find(Tag,Start,Stop) == false)
+      return Default;
+   
+   // Copy it into a temp buffer so we can use strtol
+   char S[300];
+   if ((unsigned)(Stop - Start) >= sizeof(S))
+      return Default;
+   strncpy(S,Start,Stop-Start);
+   S[Stop - Start] = 0;
+   
+   char *End;
+   signed long Result = strtol(S,&End,10);
+   if (S == End)
+      return Default;
+   return Result;
+}
+									/*}}}*/
 // ListParser::UniqFindTagWrite - Find the tag and write a unq string	/*{{{*/
 // ListParser::UniqFindTagWrite - Find the tag and write a unq string	/*{{{*/
 // ---------------------------------------------------------------------
 // ---------------------------------------------------------------------
 /* */
 /* */
@@ -115,7 +138,35 @@ bool debListParser::NewPackage(pkgCache::PkgIterator Pkg)
 // ---------------------------------------------------------------------
 // ---------------------------------------------------------------------
 /* */
 /* */
 bool debListParser::NewVersion(pkgCache::VerIterator Ver)
 bool debListParser::NewVersion(pkgCache::VerIterator Ver)
-{   
+{
+   // Parse the section
+   if ((Ver->Section = UniqFindTagWrite("Section")) == 0)
+      return _error->Warning("Missing Section tag");
+   
+   // Archive Size
+   if ((Ver->Size = (unsigned)FindTagI("Size")) == 0)
+      return _error->Error("Unparsable Size field");
+   
+   // Unpacked Size (in K)
+   if ((Ver->InstalledSize = (unsigned)FindTagI("Installed-Size")) == 0)
+      return _error->Error("Unparsable Installed-Size field");
+   Ver->InstalledSize *= 1024;
+
+   // Priority
+   const char *Start;
+   const char *Stop;
+   if (Section.Find("Priority",Start,Stop) == true)
+   {
+      WordList PrioList[] = {{"important",pkgCache::Important},
+	                     {"required",pkgCache::Required},
+	                     {"standard",pkgCache::Standard},
+                             {"optional",pkgCache::Optional},
+                             {"extra",pkgCache::Extra}};
+      if (GrabWord(string(Start,Stop-Start),PrioList,
+		   _count(PrioList),Ver->Priority) == false)
+	 return _error->Error("Malformed Priority line");
+   }
+   
    return true;
    return true;
 }
 }
 									/*}}}*/
 									/*}}}*/
@@ -247,9 +298,26 @@ bool debListParser::GrabWord(string Word,WordList *List,int Count,
 									/*}}}*/
 									/*}}}*/
 // ListParser::Step - Move to the next section in the file		/*{{{*/
 // ListParser::Step - Move to the next section in the file		/*{{{*/
 // ---------------------------------------------------------------------
 // ---------------------------------------------------------------------
-/* */
+/* This has to be carefull to only process the correct architecture */
 bool debListParser::Step()
 bool debListParser::Step()
 {
 {
-   return Tags.Step(Section);
+   while (Tags.Step(Section) == true)
+   {
+      /* See if this is the correct Architecture, if it isnt then we
+         drop the whole section */
+      const char *Start;
+      const char *Stop;
+      if (Section.Find("Architecture",Start,Stop) == false)
+	 return true;
+            
+      if (strncmp(Start,"i386",Stop - Start) == 0 &&
+	  strlen("i386") == (unsigned)(Stop - Start))
+	 return true;
+
+      if (strncmp(Start,"all",Stop - Start) == 0 &&
+	  3 == (unsigned)(Stop - Start))
+	 return true;
+   }   
+   return false;
 }
 }
 									/*}}}*/
 									/*}}}*/

+ 2 - 1
apt-pkg/deb/deblistparser.h

@@ -1,6 +1,6 @@
 // -*- mode: cpp; mode: fold -*-
 // -*- mode: cpp; mode: fold -*-
 // Description								/*{{{*/
 // Description								/*{{{*/
-// $Id: deblistparser.h,v 1.1 1998/07/04 05:58:08 jgg Exp $
+// $Id: deblistparser.h,v 1.2 1998/07/04 22:32:18 jgg Exp $
 /* ######################################################################
 /* ######################################################################
    
    
    Debian Package List Parser - This implements the abstract parser 
    Debian Package List Parser - This implements the abstract parser 
@@ -28,6 +28,7 @@ class debListParser : public pkgCacheGenerator::ListParser
    };
    };
    
    
    string FindTag(const char *Tag);
    string FindTag(const char *Tag);
+   signed long FindTagI(const char *Tag,signed long Default = 0);
    unsigned long UniqFindTagWrite(const char *Tag);
    unsigned long UniqFindTagWrite(const char *Tag);
    bool HandleFlag(const char *Tag,unsigned long &Flags,unsigned long Flag);
    bool HandleFlag(const char *Tag,unsigned long &Flags,unsigned long Flag);
    bool ParseStatus(pkgCache::PkgIterator Pkg,pkgCache::VerIterator Ver);
    bool ParseStatus(pkgCache::PkgIterator Pkg,pkgCache::VerIterator Ver);

+ 12 - 1
apt-pkg/pkgcache.cc

@@ -1,6 +1,6 @@
 // -*- mode: cpp; mode: fold -*-
 // -*- mode: cpp; mode: fold -*-
 // Description								/*{{{*/
 // Description								/*{{{*/
-// $Id: pkgcache.cc,v 1.2 1998/07/04 05:57:35 jgg Exp $
+// $Id: pkgcache.cc,v 1.3 1998/07/04 22:32:11 jgg Exp $
 /* ######################################################################
 /* ######################################################################
    
    
    Package Cache - Accessor code for the cache
    Package Cache - Accessor code for the cache
@@ -158,6 +158,17 @@ pkgCache::PkgIterator pkgCache::FindPkg(string Name)
    return PkgIterator(*this,0);
    return PkgIterator(*this,0);
 }
 }
 									/*}}}*/
 									/*}}}*/
+// Cache::Priority - Convert a priority value to a string		/*{{{*/
+// ---------------------------------------------------------------------
+/* */
+const char *pkgCache::Priority(unsigned char Prio)
+{
+   const char *Mapping[] = {0,"important","required","standard","optional","extra"};
+   if (Prio < _count(Mapping))
+      return Mapping[Prio];
+   return 0;
+}
+									/*}}}*/
 
 
 // Bases for iterator classes						/*{{{*/
 // Bases for iterator classes						/*{{{*/
 void pkgCache::VerIterator::_dummy() {}
 void pkgCache::VerIterator::_dummy() {}

+ 4 - 1
apt-pkg/pkgcache.h

@@ -1,6 +1,6 @@
 // -*- mode: cpp; mode: fold -*-
 // -*- mode: cpp; mode: fold -*-
 // Description								/*{{{*/
 // Description								/*{{{*/
-// $Id: pkgcache.h,v 1.2 1998/07/04 05:57:36 jgg Exp $
+// $Id: pkgcache.h,v 1.3 1998/07/04 22:32:12 jgg Exp $
 /* ######################################################################
 /* ######################################################################
    
    
    Cache - Structure definitions for the cache file
    Cache - Structure definitions for the cache file
@@ -94,6 +94,9 @@ class pkgCache
    inline unsigned long Hash(string S) const {return sHash(S);};
    inline unsigned long Hash(string S) const {return sHash(S);};
    inline unsigned long Hash(const char *S) const {return sHash(S);};
    inline unsigned long Hash(const char *S) const {return sHash(S);};
 
 
+   // Usefull transformation things
+   const char *Priority(unsigned char Priority);
+   
    // Accessors
    // Accessors
    PkgIterator FindPkg(string Name);
    PkgIterator FindPkg(string Name);
    Header &Head() {return *HeaderP;};
    Header &Head() {return *HeaderP;};

+ 13 - 13
apt-pkg/pkgcachegen.cc

@@ -1,6 +1,6 @@
 // -*- mode: cpp; mode: fold -*-
 // -*- mode: cpp; mode: fold -*-
 // Description								/*{{{*/
 // Description								/*{{{*/
-// $Id: pkgcachegen.cc,v 1.2 1998/07/04 05:57:37 jgg Exp $
+// $Id: pkgcachegen.cc,v 1.3 1998/07/04 22:32:13 jgg Exp $
 /* ######################################################################
 /* ######################################################################
    
    
    Package Cache Generator - Generator for the cache structure.
    Package Cache Generator - Generator for the cache structure.
@@ -58,7 +58,8 @@ pkgCacheGenerator::~pkgCacheGenerator()
 bool pkgCacheGenerator::MergeList(ListParser &List)
 bool pkgCacheGenerator::MergeList(ListParser &List)
 {
 {
    List.Owner = this;
    List.Owner = this;
-   do
+
+   while (List.Step() == true)
    {
    {
       // Get a pointer to the package structure
       // Get a pointer to the package structure
       string Package = List.Package();
       string Package = List.Package();
@@ -112,15 +113,14 @@ bool pkgCacheGenerator::MergeList(ListParser &List)
       Ver->ParentPkg = Pkg.Index();
       Ver->ParentPkg = Pkg.Index();
       if (List.NewVersion(Ver) == false)
       if (List.NewVersion(Ver) == false)
 	 return false;
 	 return false;
-      
+
       if (List.UsePackage(Pkg,Ver) == false)
       if (List.UsePackage(Pkg,Ver) == false)
 	 return false;
 	 return false;
       
       
       if (NewFileVer(Ver,List) == false)
       if (NewFileVer(Ver,List) == false)
 	 return false;
 	 return false;
    }
    }
-   while (List.Step() == true);
-      
+
    return true;
    return true;
 }
 }
 									/*}}}*/
 									/*}}}*/
@@ -169,7 +169,7 @@ unsigned long pkgCacheGenerator::NewVersion(pkgCache::VerIterator &Ver,
    // Get a structure
    // Get a structure
    unsigned long Version = Map.Allocate(sizeof(pkgCache::Version));
    unsigned long Version = Map.Allocate(sizeof(pkgCache::Version));
    if (Version == 0)
    if (Version == 0)
-      return false;
+      return 0;
    
    
    // Fill it in
    // Fill it in
    Ver = pkgCache::VerIterator(Cache,Cache.VerP + Version);
    Ver = pkgCache::VerIterator(Cache,Cache.VerP + Version);
@@ -178,9 +178,9 @@ unsigned long pkgCacheGenerator::NewVersion(pkgCache::VerIterator &Ver,
    Ver->ID = Cache.HeaderP->VersionCount++;
    Ver->ID = Cache.HeaderP->VersionCount++;
    Ver->VerStr = Map.WriteString(VerStr);
    Ver->VerStr = Map.WriteString(VerStr);
    if (Ver->VerStr == 0)
    if (Ver->VerStr == 0)
-      return false;
+      return 0;
    
    
-   return true;
+   return Version;
 }
 }
 									/*}}}*/
 									/*}}}*/
 // CacheGenerator::SelectFile - Select the current file being parsed	/*{{{*/
 // CacheGenerator::SelectFile - Select the current file being parsed	/*{{{*/
@@ -233,21 +233,21 @@ unsigned long pkgCacheGenerator::WriteUniqString(const char *S,
    
    
    // Match
    // Match
    if (Res == 0)
    if (Res == 0)
-      return I - Cache.StringItemP;
+      return I->String;
    
    
    // Get a structure
    // Get a structure
    unsigned long Item = Map.Allocate(sizeof(pkgCache::StringItem));
    unsigned long Item = Map.Allocate(sizeof(pkgCache::StringItem));
    if (Item == 0)
    if (Item == 0)
-      return false;
-   
+      return 0;
+
    // Fill in the structure
    // Fill in the structure
    pkgCache::StringItem *ItemP = Cache.StringItemP + Item;
    pkgCache::StringItem *ItemP = Cache.StringItemP + Item;
    ItemP->NextItem = I - Cache.StringItemP;
    ItemP->NextItem = I - Cache.StringItemP;
    *Last = Item;
    *Last = Item;
    ItemP->String = Map.WriteString(S,Size);
    ItemP->String = Map.WriteString(S,Size);
    if (ItemP->String == 0)
    if (ItemP->String == 0)
-      return false;
+      return 0;
    
    
-   return true;
+   return ItemP->String;
 }
 }
 									/*}}}*/
 									/*}}}*/

+ 12 - 3
apt-pkg/tagfile.cc

@@ -1,6 +1,6 @@
 // -*- mode: cpp; mode: fold -*-
 // -*- mode: cpp; mode: fold -*-
 // Description								/*{{{*/
 // Description								/*{{{*/
-// $Id: tagfile.cc,v 1.2 1998/07/04 05:57:39 jgg Exp $
+// $Id: tagfile.cc,v 1.3 1998/07/04 22:32:14 jgg Exp $
 /* ######################################################################
 /* ######################################################################
 
 
    Fast scanner for RFC-822 type header information
    Fast scanner for RFC-822 type header information
@@ -164,12 +164,21 @@ int main(int argc,char *argv[])
 
 
    {
    {
       File CacheF("./cache",File::WriteExists);
       File CacheF("./cache",File::WriteExists);
-      MMap Map(CacheF,MMap::Public);
+      MMap Map(CacheF,MMap::Public | MMap::ReadOnly);
       pkgCache Cache(Map);
       pkgCache Cache(Map);
       for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; I++)
       for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; I++)
       {
       {
 	 cout << "Package: " << I.Name() << endl;
 	 cout << "Package: " << I.Name() << endl;
-      }      
+	 for (pkgCache::VerIterator V = I.VersionList(); V.end() == false; V++)
+	 {
+	    cout << "Version: " << V.VerStr() << endl;
+	    cout << "Size: " << V->Size << endl;
+	    cout << "Installed-Size: " << V->InstalledSize << endl;
+	    cout << "Section: " << V.Section() << endl;
+	    cout << "Priority: " << Cache.Priority(V->Priority) << endl;
+	 }	 
+	 cout << endl;
+      }
    }
    }
    
    
 #if 0 
 #if 0