]> git.saurik.com Git - apt-legacy.git/blobdiff - apt-pkg/pkgcache.cc
Remove code that isn't being used with Apple http.
[apt-legacy.git] / apt-pkg / pkgcache.cc
index 8eb62089a8369af4c23f89b07045a71804ed5169..c0e2e37dc6b7eddaf360667a1195dbf81b74cf3e 100644 (file)
@@ -21,6 +21,7 @@
                                                                        /*}}}*/
 // Include Files                                                       /*{{{*/
 #include <apt-pkg/pkgcache.h>
+#include <apt-pkg/policy.h>
 #include <apt-pkg/indexfile.h>
 #include <apt-pkg/version.h>
 #include <apt-pkg/error.h>
@@ -34,7 +35,6 @@
 #include <unistd.h>
 
 #include <ctype.h>
-#include <system.h>
                                                                        /*}}}*/
 
 using std::string;
@@ -124,6 +124,7 @@ bool pkgCache::ReMap()
    VerP = (Version *)Map.Data();
    DescP = (Description *)Map.Data();
    ProvideP = (Provides *)Map.Data();
+   TagP = (Tag *)Map.Data();
    DepP = (Dependency *)Map.Data();
    StringItemP = (StringItem *)Map.Data();
    StrP = (char *)Map.Data();
@@ -163,7 +164,7 @@ unsigned long pkgCache::sHash(const string &Str) const
 {
    unsigned long Hash = 0;
    for (string::const_iterator I = Str.begin(); I != Str.end(); I++)
-      Hash = 5*Hash + tolower(*I);
+      Hash = 5*Hash + tolower_ascii(*I);
    return Hash % _count(HeaderP->HashTable);
 }
 
@@ -171,7 +172,15 @@ unsigned long pkgCache::sHash(const char *Str) const
 {
    unsigned long Hash = 0;
    for (const char *I = Str; *I != 0; I++)
-      Hash = 5*Hash + tolower(*I);
+      Hash = 5*Hash + tolower_ascii(*I);
+   return Hash % _count(HeaderP->HashTable);
+}
+
+unsigned long pkgCache::sHash(const srkString &Str) const
+{
+   unsigned long Hash = 0;
+   for (const char *I = Str.Start, *E = I + Str.Size; I != E; I++)
+      Hash = 5*Hash + tolower_ascii(*I);
    return Hash % _count(HeaderP->HashTable);
 }
 
@@ -180,12 +189,17 @@ unsigned long pkgCache::sHash(const char *Str) const
 // ---------------------------------------------------------------------
 /* Returns 0 on error, pointer to the package otherwise */
 pkgCache::PkgIterator pkgCache::FindPkg(const string &Name)
+{
+   return FindPkg(srkString(Name));
+}
+
+pkgCache::PkgIterator pkgCache::FindPkg(const srkString &Name)
 {
    // Look at the hash bucket
    Package *Pkg = PkgP + HeaderP->HashTable[Hash(Name)];
    for (; Pkg != PkgP; Pkg = PkgP + Pkg->NextPackage)
    {
-      if (Pkg->Name != 0 && StrP[Pkg->Name] == Name[0] &&
+      if (Pkg->Name != 0 &&
          stringcasecmp(Name,StrP + Pkg->Name) == 0)
         return PkgIterator(*this,Pkg);
    }
@@ -223,7 +237,7 @@ const char *pkgCache::DepType(unsigned char Type)
 {
    const char *Types[] = {"",_("Depends"),_("PreDepends"),_("Suggests"),
                           _("Recommends"),_("Conflicts"),_("Replaces"),
-                          _("Obsoletes"),_("Breaks")};
+                          _("Obsoletes"),_("Breaks"), _("Enhances")};
    if (Type < sizeof(Types)/sizeof(*Types))
       return Types[Type];
    return "";
@@ -274,9 +288,13 @@ pkgCache::PkgIterator::OkState pkgCache::PkgIterator::State() const
       return NeedsUnpack;
    
    if (Pkg->CurrentState == pkgCache::State::UnPacked ||
-       Pkg->CurrentState == pkgCache::State::HalfConfigured ||
-       Pkg->CurrentState == pkgCache::State::TriggersPending ||
-       Pkg->CurrentState == pkgCache::State::TriggersAwaited)
+       Pkg->CurrentState == pkgCache::State::HalfConfigured)
+      // we leave triggers alone complettely. dpkg deals with
+      // them in a hard-to-predict manner and if they get 
+      // resolved by dpkg before apt run dpkg --configure on 
+      // the TriggersPending package dpkg returns a error
+      //Pkg->CurrentState == pkgCache::State::TriggersAwaited
+      //Pkg->CurrentState == pkgCache::State::TriggersPending)
       return NeedsConfigure;
    
    if (Pkg->CurrentState == pkgCache::State::HalfInstalled ||
@@ -286,6 +304,56 @@ pkgCache::PkgIterator::OkState pkgCache::PkgIterator::State() const
    return NeedsNothing;
 }
                                                                        /*}}}*/
+// PkgIterator::CandVersion - Returns the candidate version string     /*{{{*/
+// ---------------------------------------------------------------------
+/* Return string representing of the candidate version. */
+const char *
+pkgCache::PkgIterator::CandVersion() const 
+{
+  //TargetVer is empty, so don't use it.
+  VerIterator version = pkgPolicy(Owner).GetCandidateVer(*this);
+  if (version.IsGood())
+    return version.VerStr();
+  return 0;
+};
+                                                                       /*}}}*/
+// PkgIterator::CurVersion - Returns the current version string                /*{{{*/
+// ---------------------------------------------------------------------
+/* Return string representing of the current version. */
+const char *
+pkgCache::PkgIterator::CurVersion() const 
+{
+  VerIterator version = CurrentVer();
+  if (version.IsGood())
+    return CurrentVer().VerStr();
+  return 0;
+};
+                                                                       /*}}}*/
+// ostream operator to handle string representation of a package       /*{{{*/
+// ---------------------------------------------------------------------
+/* Output name < cur.rent.version -> candid.ate.version | new.est.version > (section)
+   Note that the characters <|>() are all literal above. Versions will be ommited
+   if they provide no new information (e.g. there is no newer version than candidate)
+   If no version and/or section can be found "none" is used. */
+std::ostream& 
+operator<<(ostream& out, pkgCache::PkgIterator Pkg) 
+{
+   if (Pkg.end() == true)
+      return out << "invalid package";
+
+   string current = string(Pkg.CurVersion() == 0 ? "none" : Pkg.CurVersion());
+   string candidate = string(Pkg.CandVersion() == 0 ? "none" : Pkg.CandVersion());
+   string newest = string(Pkg.VersionList().end() ? "none" : Pkg.VersionList().VerStr());
+
+   out << Pkg.Name() << " < " << current;
+   if (current != candidate)
+      out << " -> " << candidate;
+   if ( newest != "none" && candidate != newest)
+      out << " | " << newest;
+   out << " > ( " << string(Pkg.Section()==0?"none":Pkg.Section()) << " )";
+   return out;
+}
+                                                                       /*}}}*/
 // DepIterator::IsCritical - Returns true if the dep is important      /*{{{*/
 // ---------------------------------------------------------------------
 /* Currently critical deps are defined as depends, predepends and