summaryrefslogtreecommitdiffstats
path: root/patches/opkg-utils-r4747/0001-opkg-compare-versions-Adapted-to-the-latest-opkg-ups.patch
blob: 95c3128933ac71103683c603f247821623ed250a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
From: Lianhao Lu <lianhao.lu@intel.com>
Date: Tue, 10 Apr 2012 21:44:14 +0800
Subject: [PATCH] opkg-compare-versions: Adapted to the latest opkg upstream.

Adapted to the latest opkg upstream implemenation for comparing
versions.

This is part of the bug fixing [YOCTO #2233].

Signed-off-by: Lianhao Lu <lianhao.lu@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
---
 opkg-compare-versions.c | 59 ++++++++++++++++++++++---------------------------
 1 file changed, 27 insertions(+), 32 deletions(-)

diff --git a/opkg-compare-versions.c b/opkg-compare-versions.c
index d5133fa..62851fa 100644
--- a/opkg-compare-versions.c
+++ b/opkg-compare-versions.c
@@ -31,43 +31,38 @@ struct versionrevision {
   const char *revision;
 };  
 
-static int verrevcmp(const char *val, const char *ref) 
-{
-  int vc, rc;
-  long vl, rl;
-  const char *vp, *rp;
-  const char *vsep, *rsep;
-
+/* assume ascii; warning: evaluates x multiple times! */
+#define order(x) ((x) == '~' ? -1 \
+		: isdigit((x)) ? 0 \
+		: !(x) ? 0 \
+		: isalpha((x)) ? (x) \
+		: (x) + 256)
+
+static int
+verrevcmp(const char *val, const char *ref) {
   if (!val) val= "";
   if (!ref) ref= "";
-  for (;;) {
-    vp= val;  while (*vp && !isdigit(*vp)) vp++;
-    rp= ref;  while (*rp && !isdigit(*rp)) rp++;
-    for (;;) {
-      vc= val == vp ? 0 : *val++;
-      rc= ref == rp ? 0 : *ref++;
-      if (!rc && !vc) break;
-      if (vc && !isalpha(vc)) vc += 256; /* assumes ASCII character set */
-      if (rc && !isalpha(rc)) rc += 256;
+
+  while (*val || *ref) {
+    int first_diff= 0;
+
+    while ( (*val && !isdigit(*val)) || (*ref && !isdigit(*ref)) ) {
+      int vc= order(*val), rc= order(*ref);
       if (vc != rc) return vc - rc;
+      val++; ref++;
     }
-    val= vp;
-    ref= rp;
-    vl=0;  if (isdigit(*vp)) vl= strtol(val,(char**)&val,10);
-    rl=0;  if (isdigit(*rp)) rl= strtol(ref,(char**)&ref,10);
-    if (vl != rl) return vl - rl;
-
-    vc = *val;
-    rc = *ref;
-    vsep = strchr(".-", vc);
-    rsep = strchr(".-", rc);
-    if (vsep && !rsep) return -1;
-    if (!vsep && rsep) return +1;
-
-    if (!*val && !*ref) return 0;
-    if (!*val) return -1;
-    if (!*ref) return +1;
+
+    while ( *val == '0' ) val++;
+    while ( *ref == '0' ) ref++;
+    while (isdigit(*val) && isdigit(*ref)) {
+      if (!first_diff) first_diff= *val - *ref;
+      val++; ref++;
+    }
+    if (isdigit(*val)) return 1;
+    if (isdigit(*ref)) return -1;
+    if (first_diff) return first_diff;
   }
+  return 0;
 }
 
 int versioncompare(const struct versionrevision *version,