cleanup headers and especially #includes everywhere
[ntk/apt.git] / apt-pkg / deb / deblistparser.cc
index 68d544e..7777d65 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                             /*{{{*/
 // ---------------------------------------------------------------------
@@ -354,7 +363,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 +379,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 +401,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");
 
@@ -474,18 +483,31 @@ const char *debListParser::ConvertRelation(const char *I,unsigned int &Op)
 // ---------------------------------------------------------------------
 /* This parses the dependency elements out of a standard string in place,
    bit by bit. */
+const char *debListParser::ParseDepends(const char *Start,const char *Stop,
+               std::string &Package,std::string &Ver,unsigned int &Op)
+   { return ParseDepends(Start, Stop, Package, Ver, Op, false, true, false); }
+const char *debListParser::ParseDepends(const char *Start,const char *Stop,
+               std::string &Package,std::string &Ver,unsigned int &Op,
+               bool const &ParseArchFlags)
+   { return ParseDepends(Start, Stop, Package, Ver, Op, ParseArchFlags, true, false); }
+const char *debListParser::ParseDepends(const char *Start,const char *Stop,
+               std::string &Package,std::string &Ver,unsigned int &Op,
+               bool const &ParseArchFlags, bool const &StripMultiArch)
+   { return ParseDepends(Start, Stop, Package, Ver, Op, ParseArchFlags, StripMultiArch, false); }
 const char *debListParser::ParseDepends(const char *Start,const char *Stop,
                                        string &Package,string &Ver,
                                        unsigned int &Op, bool const &ParseArchFlags,
-                                       bool const &StripMultiArch)
+                                       bool const &StripMultiArch,
+                                       bool const &ParseRestrictionsList)
 {
    // Strip off leading space
-   for (;Start != Stop && isspace(*Start) != 0; Start++);
+   for (;Start != Stop && isspace(*Start) != 0; ++Start);
    
    // Parse off the package name
    const char *I = Start;
    for (;I != Stop && isspace(*I) == 0 && *I != '(' && *I != ')' &&
-       *I != ',' && *I != '|' && *I != '[' && *I != ']'; I++);
+       *I != ',' && *I != '|' && *I != '[' && *I != ']' &&
+       *I != '<' && *I != '>'; ++I);
    
    // Malformed, no '('
    if (I != Stop && *I == ')')
@@ -602,6 +624,76 @@ const char *debListParser::ParseDepends(const char *Start,const char *Stop,
       for (;I != Stop && isspace(*I) != 0; I++);
    }
 
+   if (ParseRestrictionsList == true)
+   {
+      // Parse a restrictions list
+      if (I != Stop && *I == '<')
+      {
+        ++I;
+        // malformed
+        if (unlikely(I == Stop))
+           return 0;
+
+        std::vector<string> const profiles = APT::Configuration::getBuildProfiles();
+
+        const char *End = I;
+        bool Found = false;
+        bool NegRestriction = false;
+        while (I != Stop)
+        {
+           // look for whitespace or ending '>'
+           for (;End != Stop && !isspace(*End) && *End != '>'; ++End);
+
+           if (unlikely(End == Stop))
+              return 0;
+
+           if (*I == '!')
+           {
+              NegRestriction = true;
+              ++I;
+           }
+
+           std::string restriction(I, End);
+
+           std::string prefix = "profile.";
+           // only support for "profile" prefix, ignore others
+           if (restriction.size() > prefix.size() &&
+                 restriction.substr(0, prefix.size()) == prefix)
+           {
+              // get the name of the profile
+              restriction = restriction.substr(prefix.size());
+
+              if (restriction.empty() == false && profiles.empty() == false &&
+                    std::find(profiles.begin(), profiles.end(), restriction) != profiles.end())
+              {
+                 Found = true;
+                 if (I[-1] != '!')
+                    NegRestriction = false;
+                 // we found a match, so fast-forward to the end of the wildcards
+                 for (; End != Stop && *End != '>'; ++End);
+              }
+           }
+
+           if (*End++ == '>') {
+              I = End;
+              break;
+           }
+
+           I = End;
+           for (;I != Stop && isspace(*I) != 0; I++);
+        }
+
+        if (NegRestriction == true)
+           Found = !Found;
+
+        if (Found == false)
+           Package = ""; /* not for this restriction */
+      }
+
+      // Skip whitespace
+      for (;I != Stop && isspace(*I) != 0; I++);
+   }
+
    if (I != Stop && *I == '|')
       Op |= pkgCache::Dep::Or;
    
@@ -635,7 +727,7 @@ bool debListParser::ParseDepends(pkgCache::VerIterator &Ver,
       string Version;
       unsigned int Op;
 
-      Start = ParseDepends(Start, Stop, Package, Version, Op, false, false);
+      Start = ParseDepends(Start, Stop, Package, Version, Op, false, false, false);
       if (Start == 0)
         return _error->Error("Problem parsing dependency %s",Tag);
       size_t const found = Package.rfind(':');
@@ -758,7 +850,7 @@ bool debListParser::GrabWord(string Word,WordList *List,unsigned char &Out)
                                                                        /*}}}*/
 // ListParser::Step - Move to the next section in the file             /*{{{*/
 // ---------------------------------------------------------------------
-/* This has to be carefull to only process the correct architecture */
+/* This has to be careful to only process the correct architecture */
 bool debListParser::Step()
 {
    iOffset = Tags.Offset();