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 spilt 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
++);
144 int Res
= CmpFragment(A
,lhs
,B
,rhs
);
155 const char *dlhs
= AEnd
-1;
156 const char *drhs
= BEnd
-1;
157 for (;dlhs
> lhs
&& *dlhs
!= '-'; dlhs
--);
158 for (;drhs
> rhs
&& *drhs
!= '-'; drhs
--);
165 // Compare the main version
166 Res
= CmpFragment(lhs
,dlhs
,rhs
,drhs
);
176 return CmpFragment(dlhs
,AEnd
,drhs
,BEnd
);
179 // debVS::CheckDep - Check a single dependency /*{{{*/
180 // ---------------------------------------------------------------------
181 /* This simply preforms the version comparison and switch based on
182 operator. If DepVer is 0 then we are comparing against a provides
184 bool debVersioningSystem::CheckDep(const char *PkgVer
,
185 int Op
,const char *DepVer
)
187 if (DepVer
== 0 || DepVer
[0] == 0)
189 if (PkgVer
== 0 || PkgVer
[0] == 0)
192 // Perform the actual comparision.
193 int Res
= CmpVersion(PkgVer
,DepVer
);
196 case pkgCache::Dep::LessEq
:
201 case pkgCache::Dep::GreaterEq
:
206 case pkgCache::Dep::Less
:
211 case pkgCache::Dep::Greater
:
216 case pkgCache::Dep::Equals
:
221 case pkgCache::Dep::NotEquals
:
230 // debVS::UpstreamVersion - Return the upstream version string /*{{{*/
231 // ---------------------------------------------------------------------
232 /* This strips all the debian specific information from the version number */
233 string
debVersioningSystem::UpstreamVersion(const char *Ver
)
235 // Strip off the bit before the first colon
237 for (; *I
!= 0 && *I
!= ':'; I
++);
241 // Chop off the trailing -
243 unsigned Last
= strlen(Ver
);
248 return string(Ver
,Last
);