1 // -*- mode: cpp; mode: fold -*-
3 // $Id: debversion.cc,v 1.8 2003/09/10 23:39:49 mdz Exp $
4 /* ######################################################################
6 Debian Version - Versioning system for Debian
8 This implements the standard Debian versioning system.
10 ##################################################################### */
12 // Include Files /*{{{*/
13 #define APT_COMPATIBILITY 986
15 #include <apt-pkg/debversion.h>
16 #include <apt-pkg/pkgcache.h>
22 debVersioningSystem debVS
;
24 // debVS::debVersioningSystem - Constructor /*{{{*/
25 // ---------------------------------------------------------------------
27 debVersioningSystem::debVersioningSystem()
29 Label
= "Standard .deb";
33 // debVS::CmpFragment - Compare versions /*{{{*/
34 // ---------------------------------------------------------------------
35 /* This compares a fragment of the version. This is a slightly adapted
36 version of what dpkg uses. */
37 #define order(x) ((x) == '~' ? -1 \
40 : isalpha((x)) ? (x) \
42 int debVersioningSystem::CmpFragment(const char *A
,const char *AEnd
,
43 const char *B
,const char *BEnd
)
45 if (A
>= AEnd
&& B
>= BEnd
)
49 if (*B
== '~') return 1;
54 if (*A
== '~') return -1;
58 /* Iterate over the whole string
59 What this does is to split the whole string into groups of
60 numeric and non numeric portions. For instance:
62 Has 4 portions 'a', '67', 'bhgs', '89'. A more normal:
64 Has '2', '.', '7', '.' ,'-linux-','1' */
67 while (lhs
!= AEnd
&& rhs
!= BEnd
)
71 while (lhs
!= AEnd
&& rhs
!= BEnd
&&
72 (!isdigit(*lhs
) || !isdigit(*rhs
)))
85 while (isdigit(*lhs
) && isdigit(*rhs
))
88 first_diff
= *lhs
- *rhs
;
101 // The strings must be equal
102 if (lhs
== AEnd
&& rhs
== BEnd
)
108 if (*rhs
== '~') return 1;
115 if (*lhs
== '~') return -1;
123 // debVS::CmpVersion - Comparison for versions /*{{{*/
124 // ---------------------------------------------------------------------
125 /* This fragments the version into E:V-R triples and compares each
126 portion separately. */
127 int debVersioningSystem::DoCmpVersion(const char *A
,const char *AEnd
,
128 const char *B
,const char *BEnd
)
130 // Strip off the epoch and compare it
133 for (;lhs
!= AEnd
&& *lhs
!= ':'; lhs
++);
134 for (;rhs
!= BEnd
&& *rhs
!= ':'; rhs
++);
140 // Special case: a zero epoch is the same as no epoch,
144 for (; *A
== '0'; ++A
);
153 for (; *B
== '0'; ++B
);
162 int Res
= CmpFragment(A
,lhs
,B
,rhs
);
173 const char *dlhs
= AEnd
-1;
174 const char *drhs
= BEnd
-1;
175 for (;dlhs
> lhs
&& *dlhs
!= '-'; dlhs
--);
176 for (;drhs
> rhs
&& *drhs
!= '-'; drhs
--);
183 // Compare the main version
184 Res
= CmpFragment(lhs
,dlhs
,rhs
,drhs
);
194 return CmpFragment(dlhs
,AEnd
,drhs
,BEnd
);
197 // debVS::CheckDep - Check a single dependency /*{{{*/
198 // ---------------------------------------------------------------------
199 /* This simply preforms the version comparison and switch based on
200 operator. If DepVer is 0 then we are comparing against a provides
202 bool debVersioningSystem::CheckDep(const char *PkgVer
,
203 int Op
,const char *DepVer
)
205 if (DepVer
== 0 || DepVer
[0] == 0)
207 if (PkgVer
== 0 || PkgVer
[0] == 0)
210 // Perform the actual comparision.
211 int Res
= CmpVersion(PkgVer
,DepVer
);
214 case pkgCache::Dep::LessEq
:
219 case pkgCache::Dep::GreaterEq
:
224 case pkgCache::Dep::Less
:
229 case pkgCache::Dep::Greater
:
234 case pkgCache::Dep::Equals
:
239 case pkgCache::Dep::NotEquals
:
248 // debVS::UpstreamVersion - Return the upstream version string /*{{{*/
249 // ---------------------------------------------------------------------
250 /* This strips all the debian specific information from the version number */
251 string
debVersioningSystem::UpstreamVersion(const char *Ver
)
253 // Strip off the bit before the first colon
255 for (; *I
!= 0 && *I
!= ':'; I
++);
259 // Chop off the trailing -
261 unsigned Last
= strlen(Ver
);
266 return string(Ver
,Last
);