~jr/ubuntu/oneiric/apt/bzr-get-rename

« back to all changes in this revision

Viewing changes to apt-pkg/deb/debversion.cc

  • Committer: Bazaar Package Importer
  • Author(s): Matt Zimmerman
  • Date: 2005-03-07 20:08:33 UTC
  • Revision ID: james.westby@ubuntu.com-20050307200833-0lxdgg2cb4oculdv
Tags: 0.6.35
* Merge apt--mvo--0 (incorporates 0.6.34ubuntu1):
  - Implement MaxSize and MaxAge in apt.cron.daily, to prevent the cache
    from growing too large (Ubuntu #6761)
  - some comments about the pkgAcqMetaSig::Custom600Headers() added
  - use gpg --with-colons
  - commented the ftp no_proxy unseting in methods/ftp.cc
  - added support for "Acquire::gpgv::options" in methods/gpgv.cc
* Merge bubulle@debian.org--2005/apt--main--0
  - Make capitalization more consistent
  - Un-fuzzy translations resulting from capitalization changes
  - Italian translation update

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
/* ######################################################################
5
5
 
6
6
   Debian Version - Versioning system for Debian
32
32
   Label = "Standard .deb";
33
33
}
34
34
                                                                        /*}}}*/
35
 
// StrToLong - Convert the string between two iterators to a long       /*{{{*/
36
 
// ---------------------------------------------------------------------
37
 
/* */
38
 
static unsigned long StrToLong(const char *begin,const char *end)
39
 
{
40
 
   char S[40];
41
 
   char *I = S;
42
 
   for (; begin != end && I < S + 40;)
43
 
      *I++ = *begin++;
44
 
   *I = 0;
45
 
   return strtoul(S,0,10);
46
 
}
47
 
                                                                        /*}}}*/
 
35
 
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    \
 
41
                : isdigit((x)) ? 0   \
 
42
                : !(x) ? 0           \
 
43
                : isalpha((x)) ? (x) \
 
44
                : (x) + 256)
 
45
int debVersioningSystem::CmpFragment(const char *A,const char *AEnd,
53
46
                                     const char *B,const char *BEnd)
54
47
{
55
48
   if (A >= AEnd && B >= BEnd)
56
49
      return 0;
57
50
   if (A >= AEnd)
 
51
   {
 
52
      if (*B == '~') return 1;
58
53
      return -1;
 
54
   }
59
55
   if (B >= BEnd)
 
56
   {
 
57
      if (*A == '~') return -1;
60
58
      return 1;
61
 
   
 
59
   }
 
60
 
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:
65
64
         a67bhgs89
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)
72
71
   {
73
 
      // Starting points
74
 
      const char *Slhs = lhs;
75
 
      const char *Srhs = rhs;
76
 
      
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++);
81
 
      
82
 
      if (Digit == true)
83
 
      {
84
 
         // If the lhs has a digit and the rhs does not then <
85
 
         if (rhs - Srhs == 0)
86
 
            return -1;
87
 
         
88
 
         // Generate integers from the strings.
89
 
         unsigned long Ilhs = StrToLong(Slhs,lhs);
90
 
         unsigned long Irhs = StrToLong(Srhs,rhs);
91
 
         if (Ilhs != Irhs)
92
 
         {
93
 
            if (Ilhs > Irhs)
94
 
               return 1;
95
 
            return -1;
96
 
         }
97
 
      }
98
 
      else
99
 
      {
100
 
         // They are equal length so do a straight text compare
101
 
         for (;Slhs != lhs && Srhs != rhs; Slhs++, Srhs++)
102
 
         {
103
 
            if (*Slhs != *Srhs)
104
 
            {
105
 
               /* We need to compare non alpha chars as higher than alpha
106
 
                  chars (a < !) */
107
 
               int lc = *Slhs;
108
 
               int rc = *Srhs;
109
 
               if (isalpha(lc) == 0) lc += 256;
110
 
               if (isalpha(rc) == 0) rc += 256;
111
 
               if (lc > rc)
112
 
                  return 1;
113
 
               return -1;
114
 
            }
115
 
         }
116
 
 
117
 
         // If the lhs is shorter than the right it is 'less'
118
 
         if (lhs - Slhs < rhs - Srhs)
119
 
            return -1;
120
 
 
121
 
         // If the lhs is longer than the right it is 'more'
122
 
         if (lhs - Slhs > rhs - Srhs)
123
 
            return 1;            
124
 
      }      
 
72
      int first_diff = 0;
 
73
 
 
74
      while (lhs != AEnd && rhs != BEnd &&
 
75
             (!isdigit(*lhs) || !isdigit(*rhs)))
 
76
      {
 
77
         int vc = order(*lhs);
 
78
         int rc = order(*rhs);
 
79
         if (vc != rc)
 
80
            return vc - rc;
 
81
         lhs++; rhs++;
 
82
      }
 
83
 
 
84
      while (*lhs == '0')
 
85
         lhs++;
 
86
      while (*rhs == '0')
 
87
         rhs++;
 
88
      while (isdigit(*lhs) && isdigit(*rhs))
 
89
      {
 
90
         if (!first_diff)
 
91
            first_diff = *lhs - *rhs;
 
92
         lhs++;
 
93
         rhs++;
 
94
      }
 
95
 
 
96
      if (isdigit(*lhs))
 
97
         return 1;
 
98
      if (isdigit(*rhs))
 
99
         return -1;
 
100
      if (first_diff)
 
101
         return first_diff;
125
102
   }
126
103
 
127
104
   // The strings must be equal
130
107
 
131
108
   // lhs is shorter
132
109
   if (lhs == AEnd)
 
110
   {
 
111
      if (*rhs == '~') return 1;
133
112
      return -1;
 
113
   }
134
114
 
135
115
   // rhs is shorter
136
116
   if (rhs == BEnd)
 
117
   {
 
118
      if (*lhs == '~') return -1;
137
119
      return 1;
138
 
       
 
120
   }
 
121
 
139
122
   // Shouldnt happen
140
123
   return 1;
141
124
}