]> git.saurik.com Git - apt.git/blobdiff - apt-pkg/deb/deblistparser.cc
factor out parsing of MultiArch flag
[apt.git] / apt-pkg / deb / deblistparser.cc
index 89f3514c942c32ff5bb9cc847637737fdf25ed11..18b8b931dcd6afa0ae935b4e36ad8563f1f316c9 100644 (file)
 #include <apt-pkg/fileutl.h>
 #include <apt-pkg/crc-16.h>
 #include <apt-pkg/md5.h>
+#include <apt-pkg/mmap.h>
+#include <apt-pkg/pkgcache.h>
+#include <apt-pkg/cacheiterators.h>
+#include <apt-pkg/tagfile.h>
 #include <apt-pkg/macros.h>
 
+#include <stddef.h>
+#include <string.h>
+#include <algorithm>
+#include <string>
+#include <vector>
 #include <ctype.h>
                                                                        /*}}}*/
 
@@ -34,7 +43,7 @@ static debListParser::WordList PrioList[] = {
    {"standard",pkgCache::State::Standard},
    {"optional",pkgCache::State::Optional},
    {"extra",pkgCache::State::Extra},
-   {}};
+   {NULL, 0}};
 
 // ListParser::debListParser - Constructor                             /*{{{*/
 // ---------------------------------------------------------------------
@@ -95,44 +104,49 @@ string debListParser::Version()
    return Section.FindS("Version");
 }
                                                                        /*}}}*/
-// ListParser::NewVersion - Fill in the version structure              /*{{{*/
-// ---------------------------------------------------------------------
-/* */
-bool debListParser::NewVersion(pkgCache::VerIterator &Ver)
+unsigned char debListParser::ParseMultiArch(bool const showErrors)     /*{{{*/
 {
-   // Parse the section
-   Ver->Section = UniqFindTagWrite("Section");
-
-   // Parse multi-arch
+   unsigned char MA;
    string const MultiArch = Section.FindS("Multi-Arch");
    if (MultiArch.empty() == true)
-      Ver->MultiArch = pkgCache::Version::None;
+      MA = pkgCache::Version::None;
    else if (MultiArch == "same") {
-      // Parse multi-arch
       if (ArchitectureAll() == true)
       {
-        /* Arch all packages can't be Multi-Arch: same */
-        _error->Warning("Architecture: all package '%s' can't be Multi-Arch: same",
-                       Section.FindS("Package").c_str());
-        Ver->MultiArch = pkgCache::Version::None;
+        if (showErrors == true)
+           _error->Warning("Architecture: all package '%s' can't be Multi-Arch: same",
+                 Section.FindS("Package").c_str());
+        MA = pkgCache::Version::None;
       }
       else
-        Ver->MultiArch = pkgCache::Version::Same;
+        MA = pkgCache::Version::Same;
    }
    else if (MultiArch == "foreign")
-      Ver->MultiArch = pkgCache::Version::Foreign;
+      MA = pkgCache::Version::Foreign;
    else if (MultiArch == "allowed")
-      Ver->MultiArch = pkgCache::Version::Allowed;
+      MA = pkgCache::Version::Allowed;
    else
    {
-      _error->Warning("Unknown Multi-Arch type '%s' for package '%s'",
-                       MultiArch.c_str(), Section.FindS("Package").c_str());
-      Ver->MultiArch = pkgCache::Version::None;
+      if (showErrors == true)
+        _error->Warning("Unknown Multi-Arch type '%s' for package '%s'",
+              MultiArch.c_str(), Section.FindS("Package").c_str());
+      MA = pkgCache::Version::None;
    }
 
    if (ArchitectureAll() == true)
-      Ver->MultiArch |= pkgCache::Version::All;
+      MA |= pkgCache::Version::All;
 
+   return MA;
+}
+                                                                       /*}}}*/
+// ListParser::NewVersion - Fill in the version structure              /*{{{*/
+// ---------------------------------------------------------------------
+/* */
+bool debListParser::NewVersion(pkgCache::VerIterator &Ver)
+{
+   // Parse the section
+   Ver->Section = UniqFindTagWrite("Section");
+   Ver->MultiArch = ParseMultiArch(true);
    // Archive Size
    Ver->Size = Section.FindULL("Size");
    // Unpacked Size (in K)
@@ -354,7 +368,7 @@ bool debListParser::ParseStatus(pkgCache::PkgIterator &Pkg,
                           {"hold",pkgCache::State::Hold},
                           {"deinstall",pkgCache::State::DeInstall},
                           {"purge",pkgCache::State::Purge},
-                          {}};
+                          {NULL, 0}};
    if (GrabWord(string(Start,I-Start),WantList,Pkg->SelectedState) == false)
       return _error->Error("Malformed 1st word in the Status line");
 
@@ -370,7 +384,7 @@ bool debListParser::ParseStatus(pkgCache::PkgIterator &Pkg,
                           {"reinstreq",pkgCache::State::ReInstReq},
                           {"hold",pkgCache::State::HoldInst},
                           {"hold-reinstreq",pkgCache::State::HoldReInstReq},
-                          {}};
+                          {NULL, 0}};
    if (GrabWord(string(Start,I-Start),FlagList,Pkg->InstState) == false)
       return _error->Error("Malformed 2nd word in the Status line");
 
@@ -392,7 +406,7 @@ bool debListParser::ParseStatus(pkgCache::PkgIterator &Pkg,
                             {"triggers-pending",pkgCache::State::TriggersPending},
                             {"post-inst-failed",pkgCache::State::HalfConfigured},
                             {"removal-failed",pkgCache::State::HalfInstalled},
-                            {}};
+                            {NULL, 0}};
    if (GrabWord(string(Start,I-Start),StatusList,Pkg->CurrentState) == false)
       return _error->Error("Malformed 3rd word in the Status line");