X-Git-Url: https://git.saurik.com/apt.git/blobdiff_plain/233b185f104d72df97b953362ef154e628a3c4c8..af7a92c35accda98b667ff41f62ea500fca95a7c:/apt-pkg/deb/debversion.cc diff --git a/apt-pkg/deb/debversion.cc b/apt-pkg/deb/debversion.cc index 17281425b..755ffbe96 100644 --- a/apt-pkg/deb/debversion.cc +++ b/apt-pkg/deb/debversion.cc @@ -1,6 +1,6 @@ // -*- mode: cpp; mode: fold -*- // Description /*{{{*/ -// $Id: debversion.cc,v 1.3 2001/05/07 05:14:53 jgg Exp $ +// $Id: debversion.cc,v 1.8 2003/09/10 23:39:49 mdz Exp $ /* ###################################################################### Debian Version - Versioning system for Debian @@ -11,9 +11,6 @@ /*}}}*/ // Include Files /*{{{*/ #define APT_COMPATIBILITY 986 -#ifdef __GNUG__ -#pragma implementation "apt-pkg/debversion.h" -#endif #include #include @@ -32,35 +29,34 @@ debVersioningSystem::debVersioningSystem() Label = "Standard .deb"; } /*}}}*/ -// StrToLong - Convert the string between two iterators to a long /*{{{*/ -// --------------------------------------------------------------------- -/* */ -static unsigned long StrToLong(const char *begin,const char *end) -{ - char S[40]; - char *I = S; - for (; begin != end && I < S + 40;) - *I++ = *begin++; - *I = 0; - return strtoul(S,0,10); -} - /*}}}*/ + // debVS::CmpFragment - Compare versions /*{{{*/ // --------------------------------------------------------------------- -/* This compares a fragment of the version. Dpkg has a really short - version of this, but it is uh.. interesting to grok. */ -int debVersioningSystem::CmpFragment(const char *A,const char *AEnd, +/* This compares a fragment of the version. This is a slightly adapted + version of what dpkg uses. */ +#define order(x) ((x) == '~' ? -1 \ + : isdigit((x)) ? 0 \ + : !(x) ? 0 \ + : isalpha((x)) ? (x) \ + : (x) + 256) +int debVersioningSystem::CmpFragment(const char *A,const char *AEnd, const char *B,const char *BEnd) { if (A >= AEnd && B >= BEnd) return 0; if (A >= AEnd) + { + if (*B == '~') return 1; return -1; + } if (B >= BEnd) + { + if (*A == '~') return -1; return 1; - + } + /* Iterate over the whole string - What this does is to spilt the whole string into groups of + What this does is to split the whole string into groups of numeric and non numeric portions. For instance: a67bhgs89 Has 4 portions 'a', '67', 'bhgs', '89'. A more normal: @@ -70,58 +66,36 @@ int debVersioningSystem::CmpFragment(const char *A,const char *AEnd, const char *rhs = B; while (lhs != AEnd && rhs != BEnd) { - // Starting points - const char *Slhs = lhs; - const char *Srhs = rhs; - - // Compute ending points were we have passed over the portion - bool Digit = (isdigit(*lhs) > 0?true:false); - for (;lhs != AEnd && (isdigit(*lhs) > 0?true:false) == Digit; lhs++); - for (;rhs != BEnd && (isdigit(*rhs) > 0?true:false) == Digit; rhs++); - - if (Digit == true) + int first_diff = 0; + + while (lhs != AEnd && rhs != BEnd && + (!isdigit(*lhs) || !isdigit(*rhs))) { - // If the lhs has a digit and the rhs does not then < - if (rhs - Srhs == 0) - return -1; - - // Generate integers from the strings. - unsigned long Ilhs = StrToLong(Slhs,lhs); - unsigned long Irhs = StrToLong(Srhs,rhs); - if (Ilhs != Irhs) - { - if (Ilhs > Irhs) - return 1; - return -1; - } + int vc = order(*lhs); + int rc = order(*rhs); + if (vc != rc) + return vc - rc; + lhs++; rhs++; } - else - { - // They are equal length so do a straight text compare - for (;Slhs != lhs && Srhs != rhs; Slhs++, Srhs++) - { - if (*Slhs != *Srhs) - { - /* We need to compare non alpha chars as higher than alpha - chars (a < !) */ - int lc = *Slhs; - int rc = *Srhs; - if (isalpha(lc) == 0) lc += 256; - if (isalpha(rc) == 0) rc += 256; - if (lc > rc) - return 1; - return -1; - } - } - // If the lhs is shorter than the right it is 'less' - if (lhs - Slhs < rhs - Srhs) - return -1; + while (*lhs == '0') + lhs++; + while (*rhs == '0') + rhs++; + while (isdigit(*lhs) && isdigit(*rhs)) + { + if (!first_diff) + first_diff = *lhs - *rhs; + lhs++; + rhs++; + } - // If the lhs is longer than the right it is 'more' - if (lhs - Slhs > rhs - Srhs) - return 1; - } + if (isdigit(*lhs)) + return 1; + if (isdigit(*rhs)) + return -1; + if (first_diff) + return first_diff; } // The strings must be equal @@ -130,12 +104,18 @@ int debVersioningSystem::CmpFragment(const char *A,const char *AEnd, // lhs is shorter if (lhs == AEnd) + { + if (*rhs == '~') return 1; return -1; + } // rhs is shorter if (rhs == BEnd) + { + if (*lhs == '~') return -1; return 1; - + } + // Shouldnt happen return 1; } @@ -157,6 +137,27 @@ int debVersioningSystem::DoCmpVersion(const char *A,const char *AEnd, if (rhs == BEnd) rhs = B; + // Special case: a zero epoch is the same as no epoch, + // so remove it. + if (lhs != A) + { + for (; *A == '0'; ++A); + if (A == lhs) + { + ++A; + ++lhs; + } + } + if (rhs != B) + { + for (; *B == '0'; ++B); + if (B == rhs) + { + ++B; + ++rhs; + } + } + // Compare the epoch int Res = CmpFragment(A,lhs,B,rhs); if (Res != 0) @@ -189,8 +190,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 /*{{{*/