- // The strings must be equal
- if (lhs == AEnd && rhs == BEnd)
- return 0;
-
- // lhs is shorter
- if (lhs == AEnd)
- return -1;
-
- // rhs is shorter
- if (rhs == BEnd)
- return 1;
-
- // Shouldnt happen
- return 1;
-}
- /*}}}*/
-// VersionCompare - Comparison for versions /*{{{*/
-// ---------------------------------------------------------------------
-/* This fragments the version into E:V-R triples and compares each
- portion seperately. */
-int pkgVersionCompare(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)
- lhs = A;
- if (rhs == BEnd)
- rhs = B;
-
- // Compare the epoch
- int Res = iVersionCompare(A,lhs,B,rhs);
- if (Res != 0)
- return Res;
-
- // Skip the :
- if (lhs != A)
- lhs++;
- 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)
- dlhs = AEnd;
- if (drhs == rhs)
- drhs = BEnd;
-
- // Compare the main version
- Res = iVersionCompare(lhs,dlhs,rhs,drhs);
- if (Res != 0)
- return Res;
-
- // Skip the -
- if (dlhs != lhs)
- dlhs++;
- if (drhs != rhs)
- drhs++;
- return iVersionCompare(dlhs,AEnd,drhs,BEnd);
-}
- /*}}}*/
-// CheckDep - Check a single dependency /*{{{*/
-// ---------------------------------------------------------------------
-/* This simply preforms the version comparison and switch based on
- operator. */
-bool pkgCheckDep(const char *DepVer,const char *PkgVer,int Op)
-{
- if (DepVer == 0)
- return true;
- if (PkgVer == 0)
- return false;
-
- // Perform the actuall comparision.
- int Res = pkgVersionCompare(PkgVer,DepVer);
- switch (Op & 0x0F)
- {
- case pkgCache::Dep::LessEq:
- if (Res <= 0)
- return true;
- break;
-
- case pkgCache::Dep::GreaterEq:
- if (Res >= 0)
- return true;
- break;
-
- case pkgCache::Dep::Less:
- if (Res < 0)
- return true;
- break;
-
- case pkgCache::Dep::Greater:
- if (Res > 0)
- return true;
- break;
-
- case pkgCache::Dep::Equals:
- if (Res == 0)
- return true;
- break;
-
- case pkgCache::Dep::NotEquals:
- if (Res != 0)
- return true;
- break;
- }
-
- return false;
-}
- /*}}}*/
-// BaseVersion - Return the upstream version string /*{{{*/
-// ---------------------------------------------------------------------
-/* This strips all the debian specific information from the version number */
-string pkgBaseVersion(const char *Ver)
-{
- // Strip off the bit before the first colon
- const char *I = Ver;
- for (; *I != 0 && *I != ':'; I++);
- if (*I == ':')
- Ver = I + 1;
-
- // Chop off the trailing -
- I = Ver;
- unsigned Last = strlen(Ver);
- for (; *I != 0; I++)
- if (*I == '-')
- Last = I - Ver;
-
- return string(Ver,Last);
-}
- /*}}}*/