From: Harlan Stenn Date: Sun, 17 May 2015 06:47:45 +0000 (+0000) Subject: Initial support for PACKAGE_VERSION tests X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8e129b5a0446abe4bd7fba0ff0eb0a632130a02a;p=thirdparty%2Fntp.git Initial support for PACKAGE_VERSION tests bk: 55583991zPzvdvk7tAOa9SLE_KM6Og --- diff --git a/ChangeLog b/ChangeLog index c3291e4ea..362d99834 100644 --- 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 * CID 739725: Fix a rare resource leak in libevent/listener.c. diff --git a/sntp/Makefile.am b/sntp/Makefile.am index b2a234247..f45f2de5c 100644 --- a/sntp/Makefile.am +++ b/sntp/Makefile.am @@ -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 index 000000000..4b151e3fa --- /dev/null +++ b/sntp/libpkgver/colcomp.c @@ -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 + * + * 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 + +/* + * 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 + +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 index 000000000..e01c34d55 --- /dev/null +++ b/sntp/libpkgver/pkgver.h @@ -0,0 +1,19 @@ +/* + * + * Copyright 2015 Harlan Stenn. Used by NTP with permission. + * + * Author: Harlan Stenn + * + * 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) diff --git a/sntp/unity/Makefile.am b/sntp/unity/Makefile.am index e5b36b4e2..a5c2a5452 100644 --- a/sntp/unity/Makefile.am +++ b/sntp/unity/Makefile.am @@ -6,6 +6,7 @@ CLEANFILES = noinst_LIBRARIES = libunity.a libunity_a_SOURCES = \ + ../libpkgver/colcomp.c \ unity.c \ unity.h \ unity_internals.h \