summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorticktock35 <ticktock35@e8e0d7a0-c8d9-11dd-a880-a1081c7ac358>2008-12-14 23:51:34 (EST)
committer ticktock35 <ticktock35@e8e0d7a0-c8d9-11dd-a880-a1081c7ac358>2008-12-14 23:51:34 (EST)
commit3da076c8ece54d126f3708b5e6b10182f465e18b (patch)
tree8b004b48d32c9a944290ef917f8303bd21560eea
parent16f37e3866a32ffd42e8e00414d10f8a934dec14 (diff)
opkg: Update the version comparision to a more recent one from dpkg. This
means it now recognises 0.0-foo > 0.0+foo as it should. Patch from Richard Purdie <rpurdie rpsys net> git-svn-id: http://opkg.googlecode.com/svn/trunk@40 e8e0d7a0-c8d9-11dd-a880-a1081c7ac358
-rw-r--r--libopkg/pkg.c68
1 files changed, 31 insertions, 37 deletions
diff --git a/libopkg/pkg.c b/libopkg/pkg.c
index fe9118f..887b217 100644
--- a/libopkg/pkg.c
+++ b/libopkg/pkg.c
@@ -1079,43 +1079,37 @@ int pkg_compare_versions(const pkg_t *pkg, const pkg_t *ref_pkg)
return r;
}
-int verrevcmp(const char *val, const char *ref)
-{
- int vc, rc;
- long vl, rl;
- const char *vp, *rp;
- const char *vsep, *rsep;
-
- 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;
- if (vc != rc) return vc - rc;
- }
- 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;
- }
+/* 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= "";
+
+ 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++;
+ }
+
+ 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 pkg_version_satisfied(pkg_t *it, pkg_t *ref, const char *op)