Add new Debug::RunScripts option
[ntk/apt.git] / apt-pkg / deb / debversion.cc
index 064d8fa..a5eacb7 100644 (file)
    ##################################################################### */
                                                                        /*}}}*/
 // Include Files                                                       /*{{{*/
-#define APT_COMPATIBILITY 986
-#ifdef __GNUG__
-#pragma implementation "apt-pkg/debversion.h"
-#endif
+#include <config.h>
 
 #include <apt-pkg/debversion.h>
 #include <apt-pkg/pkgcache.h>
 
+#include <string.h>
+#include <string>
 #include <stdlib.h>
 #include <ctype.h>
                                                                        /*}}}*/
@@ -119,7 +118,7 @@ int debVersioningSystem::CmpFragment(const char *A,const char *AEnd,
       return 1;
    }
 
-   // Shouldnt happen
+   // Shouldn't happen
    return 1;
 }
                                                                        /*}}}*/
@@ -130,14 +129,12 @@ int debVersioningSystem::CmpFragment(const char *A,const char *AEnd,
 int debVersioningSystem::DoCmpVersion(const char *A,const char *AEnd,
                                      const char *B,const char *BEnd)
 {
-   // Strip off the epoch and compare it 
-   const char *lhs = A;
-   const char *rhs = B;
-   for (;lhs != AEnd && *lhs != ':'; lhs++);
-   for (;rhs != BEnd && *rhs != ':'; rhs++);
-   if (lhs == AEnd)
+   // Strip off the epoch and compare it
+   const char *lhs = (const char*) memchr(A, ':', AEnd - A);
+   const char *rhs = (const char*) memchr(B, ':', BEnd - B);
+   if (lhs == NULL)
       lhs = A;
-   if (rhs == BEnd)
+   if (rhs == NULL)
       rhs = B;
    
    // Special case: a zero epoch is the same as no epoch,
@@ -172,15 +169,12 @@ int debVersioningSystem::DoCmpVersion(const char *A,const char *AEnd,
    if (rhs != B)
       rhs++;
    
-   // Find the last - 
-   const char *dlhs = AEnd-1;
-   const char *drhs = BEnd-1;
-   for (;dlhs > lhs && *dlhs != '-'; dlhs--);
-   for (;drhs > rhs && *drhs != '-'; drhs--);
-
-   if (dlhs == lhs)
+   // Find the last -
+   const char *dlhs = (const char*) memrchr(lhs, '-', AEnd - lhs);
+   const char *drhs = (const char*) memrchr(rhs, '-', BEnd - rhs);
+   if (dlhs == NULL)
       dlhs = AEnd;
-   if (drhs == rhs)
+   if (drhs == NULL)
       drhs = BEnd;
    
    // Compare the main version
@@ -193,8 +187,22 @@ int debVersioningSystem::DoCmpVersion(const char *A,const char *AEnd,
       dlhs++;
    if (drhs != rhs)
       drhs++;
-   
-   return CmpFragment(dlhs,AEnd,drhs,BEnd);
+
+   // no debian revision need to be treated like -0
+   if (*(dlhs-1) == '-' && *(drhs-1) == '-')
+      return CmpFragment(dlhs,AEnd,drhs,BEnd);
+   else if (*(dlhs-1) == '-')
+   {
+      const char* null = "0";
+      return CmpFragment(dlhs,AEnd,null, null+1);
+   }
+   else if (*(drhs-1) == '-')
+   {
+      const char* null = "0";
+      return CmpFragment(null, null+1, drhs, BEnd);
+   }
+   else
+      return 0;
 }
                                                                        /*}}}*/
 // debVS::CheckDep - Check a single dependency                         /*{{{*/
@@ -209,10 +217,15 @@ bool debVersioningSystem::CheckDep(const char *PkgVer,
       return true;
    if (PkgVer == 0 || PkgVer[0] == 0)
       return false;
-   
-   // Perform the actual comparision.
-   int Res = CmpVersion(PkgVer,DepVer);
-   switch (Op & 0x0F)
+   Op &= 0x0F;
+
+   // fast track for (equal) strings [by location] which are by definition equal versions
+   if (PkgVer == DepVer)
+      return Op == pkgCache::Dep::Equals || Op == pkgCache::Dep::LessEq || Op == pkgCache::Dep::GreaterEq;
+
+   // Perform the actual comparison.
+   int const Res = CmpVersion(PkgVer, DepVer);
+   switch (Op)
    {
       case pkgCache::Dep::LessEq:
       if (Res <= 0)
@@ -251,7 +264,7 @@ bool debVersioningSystem::CheckDep(const char *PkgVer,
 // debVS::UpstreamVersion - Return the upstream version string         /*{{{*/
 // ---------------------------------------------------------------------
 /* This strips all the debian specific information from the version number */
-string debVersioningSystem::UpstreamVersion(const char *Ver)
+std::string debVersioningSystem::UpstreamVersion(const char *Ver)
 {
    // Strip off the bit before the first colon
    const char *I = Ver;
@@ -266,6 +279,6 @@ string debVersioningSystem::UpstreamVersion(const char *Ver)
       if (*I == '-')
         Last = I - Ver;
    
-   return string(Ver,Last);
+   return std::string(Ver,Last);
 }
                                                                        /*}}}*/