]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
Initial support for PACKAGE_VERSION tests
authorHarlan Stenn <stenn@ntp.org>
Sun, 17 May 2015 06:47:45 +0000 (06:47 +0000)
committerHarlan Stenn <stenn@ntp.org>
Sun, 17 May 2015 06:47:45 +0000 (06:47 +0000)
bk: 55583991zPzvdvk7tAOa9SLE_KM6Og

ChangeLog
sntp/Makefile.am
sntp/libpkgver/colcomp.c [new file with mode: 0644]
sntp/libpkgver/pkgver.h [new file with mode: 0644]
sntp/unity/Makefile.am

index c3291e4eadcf038eb11b70409a38ee895f55ec1b..362d998347904c12bb72eeccefc3a28f84dfc44d 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,7 @@
 ---
+
+* Initial support for PACKAGE_VERSION tests.
+---
 (4.2.8p3-RC1) 2015/05/12 Released by Harlan Stenn <stenn@ntp.org>
 
 * CID 739725: Fix a rare resource leak in libevent/listener.c.
index b2a234247edb9a161fd19b94081d220240576bea..f45f2de5c924559f29a50dec1fc72d5444803b08 100644 (file)
@@ -54,7 +54,7 @@ sbin_PROGRAMS =               @SNTP_DS@
 ##
 
 SUBDIRS = include scripts unity
-DIST_SUBDIRS = include scripts unity
+DIST_SUBDIRS = include libpkgver scripts unity
 
 if BUILD_LIBEVENT
 SUBDIRS += libevent
diff --git a/sntp/libpkgver/colcomp.c b/sntp/libpkgver/colcomp.c
new file mode 100644 (file)
index 0000000..4b151e3
--- /dev/null
@@ -0,0 +1,135 @@
+/* COLLATE COMPARE, COMPARES DIGITS NUMERICALLY AND OTHERS IN ASCII */
+
+/*
+ *   Copyright 2001, 2015, Harlan Stenn.  Used by NTP with permission.
+ *
+ *   Author: Harlan Stenn <harlan@pfcs.com>
+ *
+ *   Copying and distribution of this file, with or without modification,
+ *   are permitted in any medium without royalty provided the copyright
+ *   notice and this notice are preserved. This file is offered as-is,
+ *   without any warranty.
+ */
+
+/*
+ * Expected collate order for numeric "pieces" is:
+ * 0 - 9       followed by
+ * 00 - 99     followed by
+ * 000 - 999   followed by
+ * ...
+ */
+
+#include <ctype.h>
+
+/*
+ * Older versions of isdigit() require the argument be isascii()
+ */
+
+#if 0
+# define MyIsDigit(x)  \
+      (isascii ((unsigned char) (x)) && isdigit ((unsigned char) (x)))
+#else
+# define MyIsDigit(x)  isdigit ((unsigned char) (x))
+#endif
+
+
+int 
+colcomp (s1, s2)
+     register char *s1;
+     register char *s2;
+{
+  int hilo = 0;                        /* comparison value */
+
+  while (*s1 && *s2)
+    {
+      if  (  MyIsDigit(*s1)
+          && MyIsDigit(*s2))
+       {
+         hilo = (*s1 < *s2) ? -1 : (*s1 > *s2) ? 1 : 0;
+         ++s1;
+         ++s2;
+         while (MyIsDigit(*s1)
+            &&  MyIsDigit(*s2))
+           {
+             if (!hilo)
+               hilo = (*s1 < *s2) ? -1 : (*s1 > *s2) ? 1 : 0;
+             ++s1;
+             ++s2;
+           }
+         if (MyIsDigit(*s1))
+           hilo = 1;           /* s2 is first */
+         if (MyIsDigit(*s2))
+           hilo = -1;          /* s1 is first */
+         if (hilo)
+           break;
+         continue;
+       }
+      if (MyIsDigit(*s1))
+       {
+         hilo = -1;            /* s1 must come first */
+         break;
+       }
+      if (MyIsDigit(*s2))
+       {
+         hilo = 1;             /* s2 must come first */
+         break;
+       }
+      hilo = (*s1 < *s2) ? -1 : (*s1 > *s2) ? 1 : 0;
+      if (hilo)
+       break;
+      ++s1;
+      ++s2;
+    }
+  if (*s1 && *s2)
+    return (hilo);
+  if (hilo)
+    return (hilo);
+  return ((*s1 < *s2) ? -1 : (*s1 > *s2) ? 1 : 0);
+}
+
+#ifdef TEST
+
+#include <stdlib.h>
+
+static int  qcmp(   const void      *fi1,
+                    const void      *fi2)
+{
+    return colcomp(*(char**)fi1, *(char**)fi2);
+}
+
+int main( int argc, char *argv[], char *environ[]) {
+  void *base;
+  size_t nmemb = 0;
+  size_t size = sizeof(char *);
+  char *ca[] = {
+    "999", "0", "10", "1", "01", "100", "010", "99", "00", "001", "099", "9"
+  };
+  char **cp;
+  int i;
+
+  if (argc > 1) {
+    /* Sort use-provided list */
+  } else {
+    base = (void *) ca;
+    nmemb = sizeof ca / size;
+  }
+  printf("argc is <%d>, nmemb = <%d>\n", argc, nmemb);
+
+  printf("Before:\n");
+  cp = (char **)base;
+  for (i = 0; i < nmemb; ++i) {
+    printf("%s\n", *cp++);
+  }
+
+  qsort((void *)base, nmemb, size, qcmp);
+
+  printf("After:\n");
+  cp = (char **)base;
+  for (i = 0; i < nmemb; ++i) {
+    printf("%s\n", *cp++);
+  }
+
+  exit(0);
+}
+
+#endif
diff --git a/sntp/libpkgver/pkgver.h b/sntp/libpkgver/pkgver.h
new file mode 100644 (file)
index 0000000..e01c34d
--- /dev/null
@@ -0,0 +1,19 @@
+/*
+ * 
+ *   Copyright 2015 Harlan Stenn.  Used by NTP with permission.
+ *
+ *   Author: Harlan Stenn <harlan@pfcs.com>
+ *
+ *   Copying and distribution of this file, with or without modification, are
+ *   permitted in any medium without royalty provided the copyright notice
+ *   and this notice are preserved. This file is offered as-is, without any
+ *   warranty.
+ */
+
+extern int colcomp(char *s1, char *s2);
+
+#define PKG_VER_LT(x)  (colcomp((x), PACKAGE_VERSION) < 0)
+#define PKG_VER_LE(x)  (colcomp((x), PACKAGE_VERSION) <= 0)
+#define PKG_VER_EQ(x)  (colcomp((x), PACKAGE_VERSION) == 0)
+#define PKG_VER_GE(x)  (colcomp((x), PACKAGE_VERSION) >= 0)
+#define PKG_VER_GT(x)  (colcomp((x), PACKAGE_VERSION) > 0)
index e5b36b4e2e00d2ed98b2cff24e00263e3b9fc982..a5c2a5452915076d2fa58da802e07be4796f8188 100644 (file)
@@ -6,6 +6,7 @@ CLEANFILES =
 noinst_LIBRARIES = libunity.a
 
 libunity_a_SOURCES =           \
+       ../libpkgver/colcomp.c  \
        unity.c                 \
        unity.h                 \
        unity_internals.h       \