[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
strverscmp
From: |
Eric Blake |
Subject: |
strverscmp |
Date: |
Tue, 19 Aug 2008 15:57:39 +0000 (UTC) |
User-agent: |
Loom/3.14 (http://gmane.org/) |
Coreutils recently got bitten by the fact that developers on GNU/Linux machines
often don't realize that they needed #include "strverscmp.h". This fixes it,
and adds a unit test. Jim, okay to apply?
Also available at 'git pull git://repo.or.cz/gnulib/ericb.git strverscmp'
>From 98dc152be970fe2a64d17f17850cac4fc69ab00d Mon Sep 17 00:00:00 2001
From: Eric Blake <address@hidden>
Date: Tue, 19 Aug 2008 09:23:40 -0600
Subject: [PATCH] strverscmp: migrate from "strverscmp.h" to <string.h>
* modules/string (Makefile.am): Add new hooks.
* modules/strverscmp (Files): Remove strverscmp.h.
(Depends-on): Add string.
(configure.ac): Add indicator.
(Include): Mention new header.
* m4/string_h.m4 (gl_HEADER_STRING_H_DEFAULTS): Provide new
defaults.
* m4/strverscmp.m4 (gl_FUNC_STRVERSCMP): Inform string module of
results.
* lib/strverscmp.h: Delete.
* lib/string.in.h (strverscmp): Provide declaration, when needed.
* NEWS: Document the change.
Signed-off-by: Eric Blake <address@hidden>
---
ChangeLog | 16 ++++++++++++++++
NEWS | 3 +++
lib/string.in.h | 12 ++++++++++++
lib/strverscmp.h | 24 ------------------------
m4/string_h.m4 | 4 +++-
m4/strverscmp.m4 | 7 +++++--
modules/string | 2 ++
modules/strverscmp | 5 +++--
8 files changed, 44 insertions(+), 29 deletions(-)
delete mode 100644 lib/strverscmp.h
diff --git a/ChangeLog b/ChangeLog
index 5e303c7..461fa0d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,19 @@
+2008-08-19 Eric Blake <address@hidden>
+
+ strverscmp: migrate from "strverscmp.h" to <string.h>
+ * modules/string (Makefile.am): Add new hooks.
+ * modules/strverscmp (Files): Remove strverscmp.h.
+ (Depends-on): Add string.
+ (configure.ac): Add indicator.
+ (Include): Mention new header.
+ * m4/string_h.m4 (gl_HEADER_STRING_H_DEFAULTS): Provide new
+ defaults.
+ * m4/strverscmp.m4 (gl_FUNC_STRVERSCMP): Inform string module of
+ results.
+ * lib/strverscmp.h: Delete.
+ * lib/string.in.h (strverscmp): Provide declaration, when needed.
+ * NEWS: Document the change.
+
2008-08-18 Ben Pfaff <address@hidden>
gitlog-to-changelog: give better diagnostic for failed pipe-open
diff --git a/NEWS b/NEWS
index b5b08a6..7b918d3 100644
--- a/NEWS
+++ b/NEWS
@@ -6,6 +6,9 @@ User visible incompatible changes
Date Modules Changes
+2008-08-19 strverscmp The include file is changed from "strverscmp.h"
+ to <string.h>.
+
2008-08-14 lock The include file is changed from "lock.h"
to "glthread/lock.h".
tls The include file is changed from "tls.h"
diff --git a/lib/string.in.h b/lib/string.in.h
index 49ea1d8..e62b8dd 100644
--- a/lib/string.in.h
+++ b/lib/string.in.h
@@ -576,6 +576,18 @@ extern char *strsignal (int __sig);
strsignal (a))
#endif
+#if @GNULIB_STRVERSCMP@
+# if address@hidden@
+extern int strverscmp (const char *, const char *);
+# endif
+#elif defined GNULIB_POSIXCHECK
+# undef strverscmp
+# define strverscmp(a, b) \
+ (GL_LINK_WARNING ("strverscmp is unportable - " \
+ "use gnulib module strverscmp for portability"), \
+ strverscmp (a, b))
+#endif
+
#ifdef __cplusplus
}
diff --git a/lib/strverscmp.h b/lib/strverscmp.h
deleted file mode 100644
index 7edeac5..0000000
--- a/lib/strverscmp.h
+++ /dev/null
@@ -1,24 +0,0 @@
-/* Compare strings while treating digits characters numerically.
-
- Copyright (C) 1997, 2003 Free Software Foundation, Inc.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2, or (at your option)
- any later version.
-
- This program 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 General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software Foundation,
- Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
-
-#ifndef STRVERSCMP_H_
-# define STRVERSCMP_H_
-
-int strverscmp (const char *, const char *);
-
-#endif /* not STRVERSCMP_H_ */
diff --git a/m4/string_h.m4 b/m4/string_h.m4
index 7143690..b37f843 100644
--- a/m4/string_h.m4
+++ b/m4/string_h.m4
@@ -5,7 +5,7 @@
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.
-# serial 4
+# serial 5
# Written by Paul Eggert.
@@ -63,6 +63,7 @@ AC_DEFUN([gl_HEADER_STRING_H_DEFAULTS],
GNULIB_MBSTOK_R=0; AC_SUBST([GNULIB_MBSTOK_R])
GNULIB_STRERROR=0; AC_SUBST([GNULIB_STRERROR])
GNULIB_STRSIGNAL=0; AC_SUBST([GNULIB_STRSIGNAL])
+ GNULIB_STRVERSCMP=0; AC_SUBST([GNULIB_STRVERSCMP])
dnl Assume proper GNU behavior unless another module says otherwise.
HAVE_DECL_MEMMEM=1; AC_SUBST([HAVE_DECL_MEMMEM])
HAVE_MEMPCPY=1; AC_SUBST([HAVE_MEMPCPY])
@@ -81,6 +82,7 @@ AC_DEFUN([gl_HEADER_STRING_H_DEFAULTS],
HAVE_DECL_STRTOK_R=1; AC_SUBST([HAVE_DECL_STRTOK_R])
HAVE_DECL_STRERROR=1; AC_SUBST([HAVE_DECL_STRERROR])
HAVE_DECL_STRSIGNAL=1; AC_SUBST([HAVE_DECL_STRSIGNAL])
+ HAVE_STRVERSCMP=1; AC_SUBST([HAVE_STRVERSCMP])
REPLACE_STRERROR=0; AC_SUBST([REPLACE_STRERROR])
REPLACE_STRSIGNAL=0; AC_SUBST([REPLACE_STRSIGNAL])
REPLACE_MEMMEM=0; AC_SUBST([REPLACE_MEMMEM])
diff --git a/m4/strverscmp.m4 b/m4/strverscmp.m4
index 5f01ba9..a3f9aff 100644
--- a/m4/strverscmp.m4
+++ b/m4/strverscmp.m4
@@ -1,5 +1,6 @@
-# strverscmp.m4 serial 5
-dnl Copyright (C) 2002, 2005, 2006, 2007 Free Software Foundation, Inc.
+# strverscmp.m4 serial 6
+dnl Copyright (C) 2002, 2005, 2006, 2007, 2008 Free Software
+dnl Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
dnl with or without modifications, as long as this notice is preserved.
@@ -9,9 +10,11 @@ AC_DEFUN([gl_FUNC_STRVERSCMP],
dnl Persuade glibc <string.h> to declare strverscmp().
AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
+ AC_REQUIRE([gl_HEADER_STRING_H_DEFAULTS])
AC_REPLACE_FUNCS(strverscmp)
if test $ac_cv_func_strverscmp = no; then
gl_PREREQ_STRVERSCMP
+ HAVE_STRVERSCMP=0
fi
])
diff --git a/modules/string b/modules/string
index 6ca5c23..dc0063d 100644
--- a/modules/string
+++ b/modules/string
@@ -54,6 +54,7 @@ string.h: string.in.h
-e 's|@''GNULIB_STRTOK_R''@|$(GNULIB_STRTOK_R)|g' \
-e 's|@''GNULIB_STRERROR''@|$(GNULIB_STRERROR)|g' \
-e 's|@''GNULIB_STRSIGNAL''@|$(GNULIB_STRSIGNAL)|g' \
+ -e 's|@''GNULIB_STRVERSCMP''@|$(GNULIB_STRVERSCMP)|g' \
-e 's|@''HAVE_DECL_MEMMEM''@|$(HAVE_DECL_MEMMEM)|g' \
-e 's|@''HAVE_MEMPCPY''@|$(HAVE_MEMPCPY)|g' \
-e 's|@''HAVE_DECL_MEMRCHR''@|$(HAVE_DECL_MEMRCHR)|g' \
@@ -71,6 +72,7 @@ string.h: string.in.h
-e 's|@''HAVE_DECL_STRTOK_R''@|$(HAVE_DECL_STRTOK_R)|g' \
-e 's|@''HAVE_DECL_STRERROR''@|$(HAVE_DECL_STRERROR)|g' \
-e 's|@''HAVE_DECL_STRSIGNAL''@|$(HAVE_DECL_STRSIGNAL)|g' \
+ -e 's|@''HAVE_STRVERSCMP''@|$(HAVE_STRVERSCMP)|g' \
-e 's|@''REPLACE_MEMMEM''@|$(REPLACE_MEMMEM)|g' \
-e 's|@''REPLACE_STRCASESTR''@|$(REPLACE_STRCASESTR)|g' \
-e 's|@''REPLACE_STRSTR''@|$(REPLACE_STRSTR)|g' \
diff --git a/modules/strverscmp b/modules/strverscmp
index ad18c1f..33822c7 100644
--- a/modules/strverscmp
+++ b/modules/strverscmp
@@ -2,20 +2,21 @@ Description:
Compare strings holding version numbers.
Files:
-lib/strverscmp.h
lib/strverscmp.c
m4/strverscmp.m4
Depends-on:
extensions
+string
configure.ac:
gl_FUNC_STRVERSCMP
+gl_STRING_MODULE_INDICATOR([strverscmp])
Makefile.am:
Include:
-"strverscmp.h"
+<string.h>
License:
LGPLv2+
--
1.5.6.4
>From f70f72b5d594dcfbe8451b53e76f07276042218a Mon Sep 17 00:00:00 2001
From: Eric Blake <address@hidden>
Date: Tue, 19 Aug 2008 09:40:10 -0600
Subject: [PATCH] strverscmp: add unit test
* modules/strverscmp-tests: New file.
* tests/test-strverscmp.c: Likewise.
Signed-off-by: Eric Blake <address@hidden>
---
ChangeLog | 4 +++
modules/strverscmp-tests | 10 ++++++++
tests/test-strverscmp.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 70 insertions(+), 0 deletions(-)
create mode 100644 modules/strverscmp-tests
create mode 100644 tests/test-strverscmp.c
diff --git a/ChangeLog b/ChangeLog
index 461fa0d..d4ad5e9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
2008-08-19 Eric Blake <address@hidden>
+ strverscmp: add unit test
+ * modules/strverscmp-tests: New file.
+ * tests/test-strverscmp.c: Likewise.
+
strverscmp: migrate from "strverscmp.h" to <string.h>
* modules/string (Makefile.am): Add new hooks.
* modules/strverscmp (Files): Remove strverscmp.h.
diff --git a/modules/strverscmp-tests b/modules/strverscmp-tests
new file mode 100644
index 0000000..343df25
--- /dev/null
+++ b/modules/strverscmp-tests
@@ -0,0 +1,10 @@
+Files:
+tests/test-strverscmp.c
+
+Depends-on:
+
+configure.ac:
+
+Makefile.am:
+TESTS += test-strverscmp
+check_PROGRAMS += test-strverscmp
diff --git a/tests/test-strverscmp.c b/tests/test-strverscmp.c
new file mode 100644
index 0000000..04da20c
--- /dev/null
+++ b/tests/test-strverscmp.c
@@ -0,0 +1,56 @@
+/* Test of strverscmp() function.
+ Copyright (C) 2008 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3, or (at your option)
+ any later version.
+
+ This program 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 General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software Foundation,
+ Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
+
+/* Written by Eric Blake <address@hidden>, 2008. */
+
+#include <config.h>
+
+#include <string.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#define ASSERT(expr) \
+ do \
+ { \
+ if (!(expr)) \
+ { \
+ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \
+ fflush (stderr); \
+ abort (); \
+ } \
+ } \
+ while (0)
+
+int
+main (int argc, char **argv)
+{
+ ASSERT (strverscmp ("", "") == 0);
+ ASSERT (strverscmp ("a", "a") == 0);
+ ASSERT (strverscmp ("a", "b") < 0);
+ ASSERT (strverscmp ("b", "a") > 0);
+ ASSERT (strverscmp ("000", "00") < 0);
+ ASSERT (strverscmp ("00", "000") > 0);
+ ASSERT (strverscmp ("a0", "a") > 0);
+ ASSERT (strverscmp ("00", "01") < 0);
+ ASSERT (strverscmp ("01", "010") < 0);
+ ASSERT (strverscmp ("010", "09") < 0);
+ ASSERT (strverscmp ("09", "0") < 0);
+ ASSERT (strverscmp ("9", "10") < 0);
+ ASSERT (strverscmp ("0a", "0") > 0);
+ return 0;
+}
--
1.5.6.4
- strverscmp,
Eric Blake <=