cleanup headers and especially #includes everywhere
[ntk/apt.git] / apt-pkg / deb / debsrcrecords.cc
index ace4e00..b09588d 100644 (file)
@@ -9,15 +9,27 @@
    ##################################################################### */
                                                                        /*}}}*/
 // Include Files                                                       /*{{{*/
+#include <config.h>
+
 #include <apt-pkg/deblistparser.h>
 #include <apt-pkg/debsrcrecords.h>
 #include <apt-pkg/error.h>
 #include <apt-pkg/strutl.h>
-#include <apt-pkg/configuration.h>
+#include <apt-pkg/aptconfiguration.h>
+#include <apt-pkg/srcrecords.h>
+#include <apt-pkg/tagfile.h>
 
-using std::max;
+#include <ctype.h>
+#include <stdlib.h>
+#include <string.h>
+#include <algorithm>
+#include <string>
+#include <vector>
                                                                        /*}}}*/
 
+using std::max;
+using std::string;
+
 // SrcRecordParser::Binaries - Return the binaries field               /*{{{*/
 // ---------------------------------------------------------------------
 /* This member parses the binaries field into a pair of class arrays and
@@ -27,25 +39,32 @@ using std::max;
    used during scanning to find the right package */
 const char **debSrcRecordParser::Binaries()
 {
-   // This should use Start/Stop too, it is supposed to be efficient after all.
-   string Bins = Sect.FindS("Binary");
-   if (Bins.empty() == true || Bins.length() >= 102400)
-      return 0;
-   
-   if (Bins.length() >= BufSize)
-   {
-      delete [] Buffer;
-      // allocate new size based on buffer (but never smaller than 4000)
-      BufSize = max((unsigned int)4000, max((unsigned int)Bins.length()+1,2*BufSize));
-      Buffer = new char[BufSize];
-   }
+   const char *Start, *End;
+   if (Sect.Find("Binary", Start, End) == false)
+      return NULL;
+   for (; isspace(*Start) != 0; ++Start);
+   if (Start >= End)
+      return NULL;
 
-   strcpy(Buffer,Bins.c_str());
-   if (TokSplitString(',',Buffer,StaticBinList,
-                     sizeof(StaticBinList)/sizeof(StaticBinList[0])) == false)
-      return 0;
+   StaticBinList.clear();
+   free(Buffer);
+   Buffer = strndup(Start, End - Start);
+
+   char* bin = Buffer;
+   do {
+      char* binStartNext = strchrnul(bin, ',');
+      char* binEnd = binStartNext - 1;
+      for (; isspace(*binEnd) != 0; --binEnd)
+        binEnd = '\0';
+      StaticBinList.push_back(bin);
+      if (*binStartNext != ',')
+        break;
+      *binStartNext = '\0';
+      for (bin = binStartNext + 1; isspace(*bin) != 0; ++bin);
+   } while (*bin != '\0');
+   StaticBinList.push_back(NULL);
 
-   return (const char **)StaticBinList;
+   return &StaticBinList[0];
 }
                                                                        /*}}}*/
 // SrcRecordParser::BuildDepends - Return the Build-Depends information        /*{{{*/
@@ -54,7 +73,8 @@ const char **debSrcRecordParser::Binaries()
    package/version records representing the build dependency. The returned 
    array need not be freed and will be reused by the next call to this 
    function */
-bool debSrcRecordParser::BuildDepends(vector<pkgSrcRecords::Parser::BuildDepRec> &BuildDeps, bool ArchOnly)
+bool debSrcRecordParser::BuildDepends(std::vector<pkgSrcRecords::Parser::BuildDepRec> &BuildDeps,
+                                       bool const &ArchOnly, bool const &StripMultiArch)
 {
    unsigned int I;
    const char *Start, *Stop;
@@ -77,7 +97,7 @@ bool debSrcRecordParser::BuildDepends(vector<pkgSrcRecords::Parser::BuildDepRec>
       while (1)
       {
          Start = debListParser::ParseDepends(Start, Stop, 
-                    rec.Package,rec.Version,rec.Op,true);
+                    rec.Package,rec.Version,rec.Op,true,StripMultiArch,true);
         
          if (Start == 0) 
             return _error->Error("Problem parsing dependency: %s", fields[I]);
@@ -98,7 +118,7 @@ bool debSrcRecordParser::BuildDepends(vector<pkgSrcRecords::Parser::BuildDepRec>
 // ---------------------------------------------------------------------
 /* 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)
+bool debSrcRecordParser::Files(std::vector<pkgSrcRecords::File> &List)
 {
    List.erase(List.begin(),List.end());
    
@@ -110,7 +130,9 @@ bool debSrcRecordParser::Files(vector<pkgSrcRecords::File> &List)
    string Base = Sect.FindS("Directory");
    if (Base.empty() == false && Base[Base.length()-1] != '/')
       Base += '/';
-   
+
+   std::vector<std::string> const compExts = APT::Configuration::getCompressorExtensions();
+
    // Iterate over the entire list grabbing each triplet
    const char *C = Files.c_str();
    while (*C != 0)
@@ -135,9 +157,16 @@ bool debSrcRecordParser::Files(vector<pkgSrcRecords::File> &List)
         string::size_type Tmp = F.Path.rfind('.',Pos);
         if (Tmp == string::npos)
            break;
+        if (F.Type == "tar") {
+           // source v3 has extension 'debian.tar.*' instead of 'diff.*'
+           if (string(F.Path, Tmp+1, Pos-Tmp) == "debian")
+              F.Type = "diff";
+           break;
+        }
         F.Type = string(F.Path,Tmp+1,Pos-Tmp);
         
-        if (F.Type == "gz" || F.Type == "bz2" || F.Type == "lzma")
+        if (std::find(compExts.begin(), compExts.end(), std::string(".").append(F.Type)) != compExts.end() ||
+            F.Type == "tar")
         {
            Pos = Tmp-1;
            continue;
@@ -152,3 +181,11 @@ bool debSrcRecordParser::Files(vector<pkgSrcRecords::File> &List)
    return true;
 }
                                                                        /*}}}*/
+// SrcRecordParser::~SrcRecordParser - Destructor                      /*{{{*/
+// ---------------------------------------------------------------------
+/* */
+debSrcRecordParser::~debSrcRecordParser()
+{
+   delete[] Buffer;
+}
+                                                                       /*}}}*/