1
1
// -*- mode: cpp; mode: fold -*-
2
2
// Description /*{{{*/
3
// $Id: debversion.cc,v 1.3 2001/05/07 05:14:53 jgg Exp $
3
// $Id: debversion.cc,v 1.8 2003/09/10 23:39:49 mdz Exp $
4
4
/* ######################################################################
6
6
Debian Version - Versioning system for Debian
32
32
Label = "Standard .deb";
35
// StrToLong - Convert the string between two iterators to a long /*{{{*/
36
// ---------------------------------------------------------------------
38
static unsigned long StrToLong(const char *begin,const char *end)
42
for (; begin != end && I < S + 40;)
45
return strtoul(S,0,10);
48
36
// debVS::CmpFragment - Compare versions /*{{{*/
49
37
// ---------------------------------------------------------------------
50
/* This compares a fragment of the version. Dpkg has a really short
51
version of this, but it is uh.. interesting to grok. */
52
int debVersioningSystem::CmpFragment(const char *A,const char *AEnd,
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,
53
46
const char *B,const char *BEnd)
55
48
if (A >= AEnd && B >= BEnd)
52
if (*B == '~') return 1;
57
if (*A == '~') return -1;
62
61
/* Iterate over the whole string
63
What this does is to spilt the whole string into groups of
62
What this does is to spilt the whole string into groups of
64
63
numeric and non numeric portions. For instance:
66
65
Has 4 portions 'a', '67', 'bhgs', '89'. A more normal:
70
69
const char *rhs = B;
71
70
while (lhs != AEnd && rhs != BEnd)
74
const char *Slhs = lhs;
75
const char *Srhs = rhs;
77
// Compute ending points were we have passed over the portion
78
bool Digit = (isdigit(*lhs) > 0?true:false);
79
for (;lhs != AEnd && (isdigit(*lhs) > 0?true:false) == Digit; lhs++);
80
for (;rhs != BEnd && (isdigit(*rhs) > 0?true:false) == Digit; rhs++);
84
// If the lhs has a digit and the rhs does not then <
88
// Generate integers from the strings.
89
unsigned long Ilhs = StrToLong(Slhs,lhs);
90
unsigned long Irhs = StrToLong(Srhs,rhs);
100
// They are equal length so do a straight text compare
101
for (;Slhs != lhs && Srhs != rhs; Slhs++, Srhs++)
105
/* We need to compare non alpha chars as higher than alpha
109
if (isalpha(lc) == 0) lc += 256;
110
if (isalpha(rc) == 0) rc += 256;
117
// If the lhs is shorter than the right it is 'less'
118
if (lhs - Slhs < rhs - Srhs)
121
// If the lhs is longer than the right it is 'more'
122
if (lhs - Slhs > rhs - Srhs)
74
while (lhs != AEnd && rhs != BEnd &&
75
(!isdigit(*lhs) || !isdigit(*rhs)))
88
while (isdigit(*lhs) && isdigit(*rhs))
91
first_diff = *lhs - *rhs;
127
104
// The strings must be equal