2 Apt is copyright 1997, 1998, 1999 Jason Gunthorpe and others.
3 Apt is currently developed by APT Development Team <deity@lists.debian.org>.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 See /usr/share/common-licenses/GPL-2, or
22 <http://www.gnu.org/copyleft/gpl.txt> for the terms of the latest version
23 of the GNU General Public License.
27 // -*- mode: cpp; mode: fold -*-
28 // Description /*{{{*/
29 // $Id: debversion.cc,v 1.8 2003/09/10 23:39:49 mdz Exp $
30 /* ######################################################################
32 Debian Version - Versioning system for Debian
34 This implements the standard Debian versioning system.
36 ##################################################################### */
38 // Include Files /*{{{*/
39 #define APT_COMPATIBILITY 986
41 #include "debversion.h"
48 debVersioningSystem debVS;
50 // debVS::debVersioningSystem - Constructor /*{{{*/
51 // ---------------------------------------------------------------------
53 debVersioningSystem::debVersioningSystem()
55 Label = "Standard .deb";
59 // debVS::CmpFragment - Compare versions /*{{{*/
60 // ---------------------------------------------------------------------
61 /* This compares a fragment of the version. This is a slightly adapted
62 version of what dpkg uses. */
63 #define order(x) ((x) == '~' ? -1 \
66 : isalpha((x)) ? (x) \
68 int debVersioningSystem::CmpFragment(const char *A,const char *AEnd,
69 const char *B,const char *BEnd)
71 if (A >= AEnd && B >= BEnd)
75 if (*B == '~') return 1;
80 if (*A == '~') return -1;
84 /* Iterate over the whole string
85 What this does is to split the whole string into groups of
86 numeric and non numeric portions. For instance:
88 Has 4 portions 'a', '67', 'bhgs', '89'. A more normal:
90 Has '2', '.', '7', '.' ,'-linux-','1' */
93 while (lhs != AEnd && rhs != BEnd)
97 while (lhs != AEnd && rhs != BEnd &&
98 (!isdigit(*lhs) || !isdigit(*rhs)))
100 int vc = order(*lhs);
101 int rc = order(*rhs);
111 while (isdigit(*lhs) && isdigit(*rhs))
114 first_diff = *lhs - *rhs;
127 // The strings must be equal
128 if (lhs == AEnd && rhs == BEnd)
134 if (*rhs == '~') return 1;
141 if (*lhs == '~') return -1;
149 // debVS::CmpVersion - Comparison for versions /*{{{*/
150 // ---------------------------------------------------------------------
151 /* This fragments the version into E:V-R triples and compares each
152 portion separately. */
153 int debVersioningSystem::DoCmpVersion(const char *A,const char *AEnd,
154 const char *B,const char *BEnd)
156 // Strip off the epoch and compare it
159 for (;lhs != AEnd && *lhs != ':'; lhs++);
160 for (;rhs != BEnd && *rhs != ':'; rhs++);
166 // Special case: a zero epoch is the same as no epoch,
170 for (; *A == '0'; ++A);
179 for (; *B == '0'; ++B);
188 int Res = CmpFragment(A,lhs,B,rhs);
199 const char *dlhs = AEnd-1;
200 const char *drhs = BEnd-1;
201 for (;dlhs > lhs && *dlhs != '-'; dlhs--);
202 for (;drhs > rhs && *drhs != '-'; drhs--);
209 // Compare the main version
210 Res = CmpFragment(lhs,dlhs,rhs,drhs);
220 return CmpFragment(dlhs,AEnd,drhs,BEnd);
223 // debVS::CheckDep - Check a single dependency /*{{{*/
224 // ---------------------------------------------------------------------
225 /* This simply preforms the version comparison and switch based on
226 operator. If DepVer is 0 then we are comparing against a provides
228 bool debVersioningSystem::CheckDep(const char *PkgVer,
229 int Op,const char *DepVer)
231 if (DepVer == 0 || DepVer[0] == 0)
233 if (PkgVer == 0 || PkgVer[0] == 0)
236 // Perform the actual comparision.
237 int Res = CmpVersion(PkgVer,DepVer);
240 case pkgCache::Dep::LessEq:
245 case pkgCache::Dep::GreaterEq:
250 case pkgCache::Dep::Less:
255 case pkgCache::Dep::Greater:
260 case pkgCache::Dep::Equals:
265 case pkgCache::Dep::NotEquals:
274 // debVS::UpstreamVersion - Return the upstream version string /*{{{*/
275 // ---------------------------------------------------------------------
276 /* This strips all the debian specific information from the version number */
277 string debVersioningSystem::UpstreamVersion(const char *Ver)
279 // Strip off the bit before the first colon
281 for (; *I != 0 && *I != ':'; I++);
285 // Chop off the trailing -
287 unsigned Last = strlen(Ver);
292 return string(Ver,Last);