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 #pragma implementation "apt-pkg/debversion.h"
18 #include <apt-pkg/debversion.h>
19 #include <apt-pkg/pkgcache.h>
25 debVersioningSystem debVS
;
27 // debVS::debVersioningSystem - Constructor /*{{{*/
28 // ---------------------------------------------------------------------
30 debVersioningSystem::debVersioningSystem()
32 Label
= "Standard .deb";
36 // debVS::CmpFragment - Compare versions /*{{{*/
37 // ---------------------------------------------------------------------
38 /* This compares a fragment of the version. This is a slightly adapted
39 version of what dpkg uses. */
40 #define order(x) ((x) == '~' ? -1 \
43 : isalpha((x)) ? (x) \
45 int debVersioningSystem::CmpFragment(const char *A
,const char *AEnd
,
46 const char *B
,const char *BEnd
)
48 if (A
>= AEnd
&& B
>= BEnd
)
52 if (*B
== '~') return 1;
57 if (*A
== '~') return -1;
61 /* Iterate over the whole string
62 What this does is to split the whole string into groups of
63 numeric and non numeric portions. For instance:
65 Has 4 portions 'a', '67', 'bhgs', '89'. A more normal:
67 Has '2', '.', '7', '.' ,'-linux-','1' */
70 while (lhs
!= AEnd
&& rhs
!= BEnd
)
74 while (lhs
!= AEnd
&& rhs
!= BEnd
&&
75 (!isdigit(*lhs
) || !isdigit(*rhs
)))
88 while (isdigit(*lhs
) && isdigit(*rhs
))
91 first_diff
= *lhs
- *rhs
;
104 // The strings must be equal
105 if (lhs
== AEnd
&& rhs
== BEnd
)
111 if (*rhs
== '~') return 1;
118 if (*lhs
== '~') return -1;
126 // debVS::CmpVersion - Comparison for versions /*{{{*/
127 // ---------------------------------------------------------------------
128 /* This fragments the version into E:V-R triples and compares each
129 portion separately. */
130 int debVersioningSystem::DoCmpVersion(const char *A
,const char *AEnd
,
131 const char *B
,const char *BEnd
)
133 // Strip off the epoch and compare it
136 for (;lhs
!= AEnd
&& *lhs
!= ':'; lhs
++);
137 for (;rhs
!= BEnd
&& *rhs
!= ':'; rhs
++);
143 // Special case: a zero epoch is the same as no epoch,
147 for (; *A
== '0'; ++A
);
156 for (; *B
== '0'; ++B
);
165 int Res
= CmpFragment(A
,lhs
,B
,rhs
);
176 const char *dlhs
= AEnd
-1;
177 const char *drhs
= BEnd
-1;
178 for (;dlhs
> lhs
&& *dlhs
!= '-'; dlhs
--);
179 for (;drhs
> rhs
&& *drhs
!= '-'; drhs
--);
186 // Compare the main version
187 Res
= CmpFragment(lhs
,dlhs
,rhs
,drhs
);
197 return CmpFragment(dlhs
,AEnd
,drhs
,BEnd
);
200 // debVS::CheckDep - Check a single dependency /*{{{*/
201 // ---------------------------------------------------------------------
202 /* This simply preforms the version comparison and switch based on
203 operator. If DepVer is 0 then we are comparing against a provides
205 bool debVersioningSystem::CheckDep(const char *PkgVer
,
206 int Op
,const char *DepVer
)
208 if (DepVer
== 0 || DepVer
[0] == 0)
210 if (PkgVer
== 0 || PkgVer
[0] == 0)
213 // Perform the actual comparision.
214 int Res
= CmpVersion(PkgVer
,DepVer
);
217 case pkgCache::Dep::LessEq
:
222 case pkgCache::Dep::GreaterEq
:
227 case pkgCache::Dep::Less
:
232 case pkgCache::Dep::Greater
:
237 case pkgCache::Dep::Equals
:
242 case pkgCache::Dep::NotEquals
:
251 // debVS::UpstreamVersion - Return the upstream version string /*{{{*/
252 // ---------------------------------------------------------------------
253 /* This strips all the debian specific information from the version number */
254 string
debVersioningSystem::UpstreamVersion(const char *Ver
)
256 // Strip off the bit before the first colon
258 for (; *I
!= 0 && *I
!= ':'; I
++);
262 // Chop off the trailing -
264 unsigned Last
= strlen(Ver
);
269 return string(Ver
,Last
);