chiark / gitweb /
versioncmp: Fix for `~' characters. 2.0.5
authorMark Wooding <mdw@distorted.org.uk>
Wed, 14 May 2008 14:13:39 +0000 (15:13 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Wed, 14 May 2008 14:13:39 +0000 (15:13 +0100)
In the Debian version number ordering, `~' compares before end-of-
string.  Fix the function to actually cope with this, and introduce test
cases to make sure we actually get it right.

This is release 2.0.5.

Makefile.am
configure.in
debian/changelog
versioncmp-test.c [new file with mode: 0644]
versioncmp.c
versioncmp.in [new file with mode: 0644]

index 381ba0b485f6485fabbe6bc5312bdea6cd7786e1..36431e3fa72fb48aeea50a637b9e5881c5be5a2e 100644 (file)
@@ -56,7 +56,7 @@ pkginclude_HEADERS = \
 
 ## --- Things to put in the library ---
 
 
 ## --- Things to put in the library ---
 
-libmLib_la_LDFLAGS = -version-info 2:4:0
+libmLib_la_LDFLAGS = -version-info 2:5:0
 ## Middle number is the patchlevel.  Final number is the minor version.  The
 ## difference between the first and last numbers is major version.
 
 ## Middle number is the patchlevel.  Final number is the minor version.  The
 ## difference between the first and last numbers is major version.
 
@@ -101,11 +101,11 @@ unihash_mkstatic_CFLAGS = $(AM_CFLAGS)
 
 ## --- Test code ---
 
 
 ## --- Test code ---
 
-noinst_PROGRAMS = da.t sym.t assoc.t bits.t
+noinst_PROGRAMS = da.t sym.t assoc.t bits.t versioncmp.t
 
 check: \
        da.test sym.test assoc.test bits.test base64.test hex.test \
 
 check: \
        da.test sym.test assoc.test bits.test base64.test hex.test \
-       base32.test \
+       base32.test versioncmp.test \
        unihash.test
 
 da_t_SOURCES = da-test.c
        unihash.test
 
 da_t_SOURCES = da-test.c
@@ -152,6 +152,14 @@ bits.o: bits.c
 bits.test: bits.t
        ./bits.t -f $(srcdir)/bits.in
 
 bits.test: bits.t
        ./bits.t -f $(srcdir)/bits.in
 
+versioncmp_t_SOURCES = versioncmp-test.c
+versioncmp_t_LDADD = libmLib.la
+versioncmp_t_LDFLAGS = -static
+versioncmp-test.o: versioncmp-test.c
+       $(COMPILE) -c -DSRCDIR="\"$(srcdir)\"" $(srcdir)/versioncmp-test.c -o $@
+versioncmp.test: versioncmp.t
+       ./versioncmp.t -f $(srcdir)/versioncmp.in
+
 base64.to: base64.c
        $(COMPILE) -c -DTEST_RIG -DSRCDIR=\"$(srcdir)\" \
                $(srcdir)/base64.c -o base64.to
 base64.to: base64.c
        $(COMPILE) -c -DTEST_RIG -DSRCDIR=\"$(srcdir)\" \
                $(srcdir)/base64.c -o base64.to
index 39ca6b531d56a5ec653127b0e4f62df344764023..6e250ba304cca50872c949f6be1d6d0b079eb1d4 100644 (file)
@@ -27,7 +27,7 @@ dnl Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
 dnl MA 02111-1307, USA.
 
 AC_INIT(exc.c)
 dnl MA 02111-1307, USA.
 
 AC_INIT(exc.c)
-AM_INIT_AUTOMAKE(mLib, 2.0.4)
+AM_INIT_AUTOMAKE(mLib, 2.0.5)
 
 AC_PROG_CC
 AM_PROG_LIBTOOL
 
 AC_PROG_CC
 AM_PROG_LIBTOOL
index 2d18770cfbed0d14776d16a6aaa8e47dc38f544c..067f84f6a626ac397d33dbd2cbac262e24d687e7 100644 (file)
@@ -1,3 +1,10 @@
+mlib (2.0.5) experimental; urgency=low
+
+  * Fix versioncmp to deal with `~' characters properly, in line with
+    Debian policy.
+
+ -- Mark Wooding <mdw@distorted.org.uk>  Wed, 14 May 2008 15:10:32 +0100
+
 mlib (2.0.4) experimental; urgency=low
 
   * Switch over to pkgconfig.  This is largely a stopgap release, to stop
 mlib (2.0.4) experimental; urgency=low
 
   * Switch over to pkgconfig.  This is largely a stopgap release, to stop
diff --git a/versioncmp-test.c b/versioncmp-test.c
new file mode 100644 (file)
index 0000000..0927f46
--- /dev/null
@@ -0,0 +1,51 @@
+/* -*-c-*-
+ *
+ * Test rig for versioncmp
+ *
+ * (c) 2008 Straylight/Edgeware
+ */
+
+/*----- Licensing notice --------------------------------------------------*
+ *
+ * This file is part of the mLib utilities library.
+ *
+ * mLib is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Library General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * mLib is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with mLib; if not, write to the Free
+ * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
+ * MA 02111-1307, USA.
+ */
+
+#include "testrig.h"
+#include "versioncmp.h"
+
+static int t_vcmp(dstr *v)
+{
+  int ok = 1;
+  int rc = versioncmp(v[0].buf, v[1].buf);
+  if (rc != *(int *)v[2].buf) {
+    fprintf(stderr, "\nversioncmp(%s, %s) returns %d != %d\n",
+           v[0].buf, v[1].buf, rc, *(int *)v[2].buf);
+    ok = 0;
+  }
+  return (ok);
+}
+
+static const test_chunk tests[] = {
+  { "versioncmp", t_vcmp, { &type_string, &type_string, &type_int } },
+  { 0 }
+};
+
+int main(int argc, char *argv[])
+  { test_run(argc, argv, tests, SRCDIR "/versioncmp.in"); return (1); }
+
+/*----- That's all, folks -------------------------------------------------*/
index 1b77ca9899ab70feb90123030abebaca0fa386bd..7b67dc21446cf6ed916cc1eb6881429172171329 100644 (file)
@@ -125,28 +125,26 @@ static int vcmp(const char *va, const char *val,
 
     pa = vchr(&va, val); pb = vchr(&vb, vbl);
     for (;;) {
 
     pa = vchr(&va, val); pb = vchr(&vb, vbl);
     for (;;) {
-      if (pa == va && pb == vb)
-       break;
-      else if (pa == va)
-       return (-1);
-      else if (pb == vb)
-       return (+1);
-      else if (*pa == *pb) {
-       pa++; pb++;
-       continue;
-      } else if (isalpha((unsigned char)*pa) == isalpha((unsigned char)*pb))
-       return (CMP(*pa, *pb));
-      else if (isalpha((unsigned char)*pa))
-       return (-1);
-      else
-       return (+1);
+      if (pa == va) ia = 1;
+      else if (isalpha((unsigned char)*pa)) ia = 2;
+      else if (*pa == '~') ia = 0;
+      else ia = 3;
+
+      if (pb == vb) ib = 1;
+      else if (isalpha((unsigned char)*pb)) ib = 2;
+      else if (*pb == '~') ib = 0;
+      else ib = 3;
+
+      if (ia != ib) return (CMP(ia, ib));
+      else if (pa == va && pb == vb) break;
+      else if (*pa != *pb) return (CMP(*pa, *pb));
+      pa++; pb++;
     }
 
     /* --- Compare digit portions --- */
 
     ia = vint(&va, val); ib = vint(&vb, vbl);
     }
 
     /* --- Compare digit portions --- */
 
     ia = vint(&va, val); ib = vint(&vb, vbl);
-    if (ia != ib)
-      return (CMP(ia, ib));
+    if (ia != ib) return (CMP(ia, ib));
   }
 }
 
   }
 }
 
diff --git a/versioncmp.in b/versioncmp.in
new file mode 100644 (file)
index 0000000..421974a
--- /dev/null
@@ -0,0 +1,14 @@
+## test for versioncmp
+
+versioncmp {
+  1.2 1.2 0;
+  1.1 1.2 -1;
+  1.1 1.0 +1;
+  1.0 1.a -1;
+  1:2.0 2:0.4 -1;
+  1.2 1.2~pre0 +1;
+  1~~ 1~~a -1;
+  1~~a 1~ -1;
+  1~ 1 -1;
+  1 1a -1;
+}