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 // no debian revision need to be treated like -0
195 if (*(dlhs
-1) == '-' && *(drhs
-1) == '-')
196 return CmpFragment(dlhs
,AEnd
,drhs
,BEnd
);
197 else if (*(dlhs
-1) == '-')
199 const char* null
= "0";
200 return CmpFragment(dlhs
,AEnd
,null
, null
+1);
202 else if (*(drhs
-1) == '-')
204 const char* null
= "0";
205 return CmpFragment(null
, null
+1, drhs
, BEnd
);
211 // debVS::CheckDep - Check a single dependency /*{{{*/
212 // ---------------------------------------------------------------------
213 /* This simply preforms the version comparison and switch based on
214 operator. If DepVer is 0 then we are comparing against a provides
216 bool debVersioningSystem::CheckDep(const char *PkgVer
,
217 int Op
,const char *DepVer
)
219 if (DepVer
== 0 || DepVer
[0] == 0)
221 if (PkgVer
== 0 || PkgVer
[0] == 0)
224 // Perform the actual comparision.
225 int Res
= CmpVersion(PkgVer
,DepVer
);
228 case pkgCache::Dep::LessEq
:
233 case pkgCache::Dep::GreaterEq
:
238 case pkgCache::Dep::Less
:
243 case pkgCache::Dep::Greater
:
248 case pkgCache::Dep::Equals
:
253 case pkgCache::Dep::NotEquals
:
262 // debVS::UpstreamVersion - Return the upstream version string /*{{{*/
263 // ---------------------------------------------------------------------
264 /* This strips all the debian specific information from the version number */
265 string
debVersioningSystem::UpstreamVersion(const char *Ver
)
267 // Strip off the bit before the first colon
269 for (; *I
!= 0 && *I
!= ':'; I
++);
273 // Chop off the trailing -
275 unsigned Last
= strlen(Ver
);
280 return string(Ver
,Last
);