1 // -*- mode: cpp; mode: fold -*-
3 // $Id: debversion.cc,v 1.6 2003/01/27 00:05:59 jgg 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
)
55 /* Iterate over the whole string
56 What this does is to spilt the whole string into groups of
57 numeric and non numeric portions. For instance:
59 Has 4 portions 'a', '67', 'bhgs', '89'. A more normal:
61 Has '2', '.', '7', '.' ,'-linux-','1' */
64 while (lhs
!= AEnd
&& rhs
!= BEnd
)
68 while ((lhs
!= AEnd
&& !isdigit(*lhs
)) ||
69 (rhs
!= BEnd
&& !isdigit(*rhs
)) )
82 while (isdigit(*lhs
) && isdigit(*rhs
))
85 first_diff
= *lhs
- *rhs
;
98 // The strings must be equal
99 if (lhs
== AEnd
&& rhs
== BEnd
)
114 // debVS::CmpVersion - Comparison for versions /*{{{*/
115 // ---------------------------------------------------------------------
116 /* This fragments the version into E:V-R triples and compares each
117 portion separately. */
118 int debVersioningSystem::DoCmpVersion(const char *A
,const char *AEnd
,
119 const char *B
,const char *BEnd
)
121 // Strip off the epoch and compare it
124 for (;lhs
!= AEnd
&& *lhs
!= ':'; lhs
++);
125 for (;rhs
!= BEnd
&& *rhs
!= ':'; rhs
++);
132 int Res
= CmpFragment(A
,lhs
,B
,rhs
);
143 const char *dlhs
= AEnd
-1;
144 const char *drhs
= BEnd
-1;
145 for (;dlhs
> lhs
&& *dlhs
!= '-'; dlhs
--);
146 for (;drhs
> rhs
&& *drhs
!= '-'; drhs
--);
153 // Compare the main version
154 Res
= CmpFragment(lhs
,dlhs
,rhs
,drhs
);
164 return CmpFragment(dlhs
,AEnd
,drhs
,BEnd
);
167 // debVS::CheckDep - Check a single dependency /*{{{*/
168 // ---------------------------------------------------------------------
169 /* This simply preforms the version comparison and switch based on
170 operator. If DepVer is 0 then we are comparing against a provides
172 bool debVersioningSystem::CheckDep(const char *PkgVer
,
173 int Op
,const char *DepVer
)
175 if (DepVer
== 0 || DepVer
[0] == 0)
177 if (PkgVer
== 0 || PkgVer
[0] == 0)
180 // Perform the actual comparision.
181 int Res
= CmpVersion(PkgVer
,DepVer
);
184 case pkgCache::Dep::LessEq
:
189 case pkgCache::Dep::GreaterEq
:
194 case pkgCache::Dep::Less
:
199 case pkgCache::Dep::Greater
:
204 case pkgCache::Dep::Equals
:
209 case pkgCache::Dep::NotEquals
:
218 // debVS::UpstreamVersion - Return the upstream version string /*{{{*/
219 // ---------------------------------------------------------------------
220 /* This strips all the debian specific information from the version number */
221 string
debVersioningSystem::UpstreamVersion(const char *Ver
)
223 // Strip off the bit before the first colon
225 for (; *I
!= 0 && *I
!= ':'; I
++);
229 // Chop off the trailing -
231 unsigned Last
= strlen(Ver
);
236 return string(Ver
,Last
);