Просмотр исходного кода

Source record file list parsing
Author: jgg
Date: 1999-04-04 08:07:39 GMT
Source record file list parsing

Arch Librarian лет назад: 22
Родитель
Сommit
36f610f18a
4 измененных файлов с 57 добавлено и 6 удалено
  1. 3 3
      apt-pkg/contrib/strutl.cc
  2. 41 1
      apt-pkg/deb/debsrcrecords.cc
  3. 2 1
      apt-pkg/deb/debsrcrecords.h
  4. 11 1
      apt-pkg/srcrecords.h

+ 3 - 3
apt-pkg/contrib/strutl.cc

@@ -1,6 +1,6 @@
 // -*- mode: cpp; mode: fold -*-
 // Description								/*{{{*/
-// $Id: strutl.cc,v 1.23 1999/03/16 07:27:17 jgg Exp $
+// $Id: strutl.cc,v 1.24 1999/04/04 08:07:39 jgg Exp $
 /* ######################################################################
 
    String Util - Some usefull string functions.
@@ -97,7 +97,7 @@ bool ParseQuoteWord(const char *&String,string &Res)
       return false;
    
    // Jump to the next word
-   for (;*C != 0 && *C != ' '; C++)
+   for (;*C != 0 && isspace(*C) == 0; C++)
    {
       if (*C == '"')
       {
@@ -133,7 +133,7 @@ bool ParseQuoteWord(const char *&String,string &Res)
    Res = Buffer;
    
    // Skip ending white space
-   for (;*C != 0 && *C == ' '; C++);
+   for (;*C != 0 && isspace(*C) != 0; C++);
    String = C;
    return true;
 }

+ 41 - 1
apt-pkg/deb/debsrcrecords.cc

@@ -1,6 +1,6 @@
 // -*- mode: cpp; mode: fold -*-
 // Description								/*{{{*/
-// $Id: debsrcrecords.cc,v 1.1 1999/04/04 01:17:29 jgg Exp $
+// $Id: debsrcrecords.cc,v 1.2 1999/04/04 08:07:39 jgg Exp $
 /* ######################################################################
    
    Debian Source Package Records - Parser implementation for Debian style
@@ -15,6 +15,7 @@
 
 #include <apt-pkg/debsrcrecords.h>
 #include <apt-pkg/error.h>
+#include <apt-pkg/strutl.h>
 									/*}}}*/
 
 // SrcRecordParser::Binaries - Return the binaries field		/*{{{*/
@@ -61,3 +62,42 @@ const char **debSrcRecordParser::Binaries()
    return StaticBinList;
 }
 									/*}}}*/
+// SrcRecordParser::Files - Return a list of files for this source	/*{{{*/
+// ---------------------------------------------------------------------
+/* This parses the list of files and returns it, each file is required to have
+   a complete source package */
+bool debSrcRecordParser::Files(vector<pkgSrcRecords::File> &List)
+{
+   List.erase(List.begin(),List.end());
+   
+   string Files = Sect.FindS("Files");
+   if (Files.empty() == true)
+      return false;
+
+   // Stash the / terminated directory prefix
+   string Base = Sect.FindS("Directory:");
+   if (Base.empty() == false && Base[Base.length()-1] != '/')
+      Base += '/';
+       
+   // Iterate over the entire list grabbing each triplet
+   const char *C = Files.c_str();
+   while (*C != 0)
+   {   
+      pkgSrcRecords::File F;
+      string Size;
+      
+      // Parse each of the elements
+      if (ParseQuoteWord(C,F.MD5Hash) == false ||
+	  ParseQuoteWord(C,Size) == false ||
+	  ParseQuoteWord(C,F.Path) == false)
+	 return _error->Error("Error parsing file record");
+      
+      // Parse the size and append the directory
+      F.Size = atoi(Size.c_str());
+      F.Path = Base + F.Path;
+      List.push_back(F);
+   }
+   
+   return true;
+}
+									/*}}}*/

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

@@ -1,6 +1,6 @@
 // -*- mode: cpp; mode: fold -*-
 // Description								/*{{{*/
-// $Id: debsrcrecords.h,v 1.1 1999/04/04 01:17:29 jgg Exp $
+// $Id: debsrcrecords.h,v 1.2 1999/04/04 08:07:39 jgg Exp $
 /* ######################################################################
    
    Debian Source Package Records - Parser implementation for Debian style
@@ -38,6 +38,7 @@ class debSrcRecordParser : public pkgSrcRecords::Parser
    virtual string Section() {return Sect.FindS("Section");};
    virtual const char **Binaries();
    virtual unsigned long Offset() {return iOffset;};
+   virtual bool Files(vector<pkgSrcRecords::File> &F);
    
    debSrcRecordParser(FileFd *File) : Parser(File), 
                    Tags(*File,sizeof(Buffer)) {};

+ 11 - 1
apt-pkg/srcrecords.h

@@ -1,6 +1,6 @@
 // -*- mode: cpp; mode: fold -*-
 // Description								/*{{{*/
-// $Id: srcrecords.h,v 1.1 1999/04/04 01:17:29 jgg Exp $
+// $Id: srcrecords.h,v 1.2 1999/04/04 08:07:39 jgg Exp $
 /* ######################################################################
    
    Source Package Records - Allows access to source package records
@@ -23,7 +23,16 @@
 class pkgSrcRecords
 {
    public:
+
+   // Describes a single file
+   struct File
+   {
+      string MD5Hash;
+      unsigned long Size;
+      string Path;
+   };
    
+   // Abstract parser for each source record
    class Parser
    {
       FileFd *File;
@@ -40,6 +49,7 @@ class pkgSrcRecords
       virtual string Maintainer() = 0;
       virtual string Section() = 0;
       virtual const char **Binaries() = 0;
+      virtual bool Files(vector<File> &F) = 0;
       
       Parser(FileFd *File) : File(File) {};
       virtual ~Parser() {delete File;};