changeset 19203:189d600a9236

monetary: New module. * modules/monetary: New file. * lib/monetary.in.h: New file. * m4/monetary_h.m4: New file. * doc/posix-headers/monetary.texi: Mention the new module. * modules/monetary-tests: New file. * tests/test-monetary.c: New file. * modules/monetary-c++-tests: New file. * tests/test-monetary-c++.cc: New file. * modules/duplocale-tests (configure.ac): Use AC_CHECK_HEADERS_ONCE.
author Bruno Haible <bruno@clisp.org>
date Sat, 23 Sep 2017 09:26:48 +0200
parents f878c378244c
children d0e723baf192
files ChangeLog doc/posix-headers/monetary.texi lib/monetary.in.h m4/monetary_h.m4 modules/duplocale-tests modules/monetary modules/monetary-c++-tests modules/monetary-tests tests/test-monetary-c++.cc tests/test-monetary.c
diffstat 10 files changed, 338 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Sat Sep 23 16:01:33 2017 +0200
+++ b/ChangeLog	Sat Sep 23 09:26:48 2017 +0200
@@ -1,3 +1,16 @@
+2017-09-23  Bruno Haible  <bruno@clisp.org>
+
+	monetary: New module.
+	* modules/monetary: New file.
+	* lib/monetary.in.h: New file.
+	* m4/monetary_h.m4: New file.
+	* doc/posix-headers/monetary.texi: Mention the new module.
+	* modules/monetary-tests: New file.
+	* tests/test-monetary.c: New file.
+	* modules/monetary-c++-tests: New file.
+	* tests/test-monetary-c++.cc: New file.
+	* modules/duplocale-tests (configure.ac): Use AC_CHECK_HEADERS_ONCE.
+
 2017-09-23  Bruno Haible  <bruno@clisp.org>
 
 	duplocale tests: Fix test crash on Linux/x86.
--- a/doc/posix-headers/monetary.texi	Sat Sep 23 16:01:33 2017 +0200
+++ b/doc/posix-headers/monetary.texi	Sat Sep 23 09:26:48 2017 +0200
@@ -3,7 +3,7 @@
 
 POSIX specification:@* @url{http://www.opengroup.org/onlinepubs/9699919799/basedefs/monetary.h.html}
 
-Gnulib module: ---
+Gnulib module: monetary
 
 Portability problems fixed by Gnulib:
 @itemize
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/monetary.in.h	Sat Sep 23 09:26:48 2017 +0200
@@ -0,0 +1,105 @@
+/* Wrapper around <monetary.h>.
+   Copyright (C) 2017 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, see <https://www.gnu.org/licenses/>.  */
+
+#ifndef _@GUARD_PREFIX@_MONETARY_H
+
+#if __GNUC__ >= 3
+@PRAGMA_SYSTEM_HEADER@
+#endif
+@PRAGMA_COLUMNS@
+
+/* The include_next requires a split double-inclusion guard.  */
+#if @HAVE_MONETARY_H@
+# @INCLUDE_NEXT@ @NEXT_MONETARY_H@
+#endif
+
+#ifndef _@GUARD_PREFIX@_MONETARY_H
+#define _@GUARD_PREFIX@_MONETARY_H
+
+#if @GNULIB_STRFMON_L@ && @HAVE_XLOCALE_H@
+/* Get locale_t on Mac OS X 10.12.  */
+# include <xlocale.h>
+#endif
+
+/* Like in <stdio.h>.  */
+#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7)
+# define _GL_ATTRIBUTE_FORMAT(spec) __attribute__ ((__format__ spec))
+#else
+# define _GL_ATTRIBUTE_FORMAT(spec) /* empty */
+#endif
+
+/* _GL_ATTRIBUTE_FORMAT_STRFMON
+   indicates to GCC that the function takes a format string and arguments,
+   where the format string directives are the ones standardized by ISO C99
+   and POSIX.  */
+#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4)
+# define _GL_ATTRIBUTE_FORMAT_STRFMON(formatstring_parameter, first_argument) \
+   _GL_ATTRIBUTE_FORMAT ((__gnu_strfmon__, formatstring_parameter, first_argument))
+#elif __GNUC__ >= 3
+# define _GL_ATTRIBUTE_FORMAT_STRFMON(formatstring_parameter, first_argument) \
+   _GL_ATTRIBUTE_FORMAT ((__strfmon__, formatstring_parameter, first_argument))
+#else
+# define _GL_ATTRIBUTE_FORMAT_STRFMON(formatstring_parameter, first_argument) /* empty */
+#endif
+
+
+/* The definitions of _GL_FUNCDECL_RPL etc. are copied here.  */
+
+/* The definition of _GL_ARG_NONNULL is copied here.  */
+
+/* The definition of _GL_WARN_ON_USE is copied here.  */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+#if @GNULIB_STRFMON_L@
+/* Converts a monetary value to a string.
+   See the POSIX:2008 specification
+   <http://pubs.opengroup.org/onlinepubs/9699919799/functions/strfmon_l.html.  */
+# if @REPLACE_STRFMON_L@
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   define strfmon_l rpl_strfmon_l
+#  endif
+_GL_FUNCDECL_RPL (strfmon_l, ssize_t, (char *s, size_t maxsize, locale_t locale,
+                                       const char *format, ...)
+                                      _GL_ATTRIBUTE_FORMAT_STRFMON (4, 5)
+                                      _GL_ARG_NONNULL ((4)));
+_GL_CXXALIAS_RPL (strfmon_l, ssize_t, (char *s, size_t maxsize, locale_t locale,
+                                       const char *format, ...));
+# else
+#  if @HAVE_STRFMON_L@
+_GL_CXXALIAS_SYS (strfmon_l, ssize_t, (char *s, size_t maxsize, locale_t locale,
+                                       const char *format, ...));
+#  endif
+# endif
+_GL_CXXALIASWARN (strfmon_l);
+#elif defined GNULIB_POSIXCHECK
+# undef strfmon_l
+# if HAVE_RAW_DECL_STRFMON_L
+_GL_WARN_ON_USE (strfmon_l, "strfmon_l is buggy on older glibc systems - "
+                 "use gnulib module chown for portability");
+# endif
+#endif
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _@GUARD_PREFIX@_MONETARY_H */
+#endif /* _@GUARD_PREFIX@_MONETARY_H */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/m4/monetary_h.m4	Sat Sep 23 09:26:48 2017 +0200
@@ -0,0 +1,65 @@
+# monetary_h.m4 serial 1
+dnl Copyright (C) 2017 Free Software 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.
+
+AC_DEFUN([gl_MONETARY_H],
+[
+  dnl Use AC_REQUIRE here, so that the default behavior below is expanded
+  dnl once only, before all statements that occur in other macros.
+  AC_REQUIRE([gl_MONETARY_H_BODY])
+])
+
+AC_DEFUN([gl_MONETARY_H_BODY],
+[
+  AC_REQUIRE([gl_MONETARY_H_DEFAULTS])
+
+  AC_CHECK_HEADERS_ONCE([monetary.h])
+  dnl For now, we provide a <monetary.h> wrapper only if the system already
+  dnl has a <monetary.h>.
+  if test $ac_cv_header_monetary_h = yes; then
+    MONETARY_H='monetary.h'
+
+    gl_CHECK_NEXT_HEADERS([monetary.h])
+    if test $ac_cv_header_monetary_h = yes; then
+      HAVE_MONETARY_H=1
+    else
+      HAVE_MONETARY_H=0
+    fi
+    AC_SUBST([HAVE_MONETARY_H])
+
+    AC_CHECK_HEADERS_ONCE([xlocale.h])
+    if test $ac_cv_header_xlocale_h = yes; then
+      HAVE_XLOCALE_H=1
+    else
+      HAVE_XLOCALE_H=0
+    fi
+    AC_SUBST([HAVE_XLOCALE_H])
+
+    dnl Check for declarations of anything we want to poison if the
+    dnl corresponding gnulib module is not in use.
+    gl_WARN_ON_USE_PREPARE([[
+      #include <monetary.h>
+      ]], [strfmon_l])
+  else
+    MONETARY_H=''
+  fi
+  AC_SUBST([MONETARY_H])
+  AM_CONDITIONAL([GL_GENERATE_MONETARY_H], [test -n "$MONETARY_H"])
+])
+
+AC_DEFUN([gl_MONETARY_MODULE_INDICATOR],
+[
+  dnl Use AC_REQUIRE here, so that the default settings are expanded once only.
+  AC_REQUIRE([gl_MONETARY_H_DEFAULTS])
+  gl_MODULE_INDICATOR_SET_VARIABLE([$1])
+])
+
+AC_DEFUN([gl_MONETARY_H_DEFAULTS],
+[
+  GNULIB_STRFMON_L=0;      AC_SUBST([GNULIB_STRFMON_L])
+  dnl Assume proper GNU behavior unless another module says otherwise.
+  HAVE_STRFMON_L=1;        AC_SUBST([HAVE_STRFMON_L])
+  REPLACE_STRFMON_L=0;     AC_SUBST([REPLACE_STRFMON_L])
+])
--- a/modules/duplocale-tests	Sat Sep 23 16:01:33 2017 +0200
+++ b/modules/duplocale-tests	Sat Sep 23 09:26:48 2017 +0200
@@ -8,7 +8,7 @@
 
 configure.ac:
 AC_CHECK_FUNCS_ONCE([duplocale uselocale strfmon_l snprintf_l nl_langinfo_l])
-AC_CHECK_HEADERS([monetary.h])
+AC_CHECK_HEADERS_ONCE([monetary.h])
 
 Makefile.am:
 TESTS += test-duplocale
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/modules/monetary	Sat Sep 23 09:26:48 2017 +0200
@@ -0,0 +1,57 @@
+Description:
+A substitute <monetary.h>.
+
+Files:
+lib/monetary.in.h
+m4/monetary_h.m4
+
+Depends-on:
+include_next
+snippet/arg-nonnull
+snippet/c++defs
+snippet/warn-on-use
+
+configure.ac:
+gl_MONETARY_H
+
+Makefile.am:
+BUILT_SOURCES += $(MONETARY_H)
+
+# We need the following in order to create <monetary.h> when the system
+# doesn't have one that works with the given compiler.
+if GL_GENERATE_MONETARY_H
+monetary.h: monetary.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(WARN_ON_USE_H) $(ARG_NONNULL_H)
+	$(AM_V_GEN)rm -f $@-t $@ && \
+	{ echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */' && \
+	  sed -e 's|@''GUARD_PREFIX''@|${gl_include_guard_prefix}|g' \
+	      -e 's|@''HAVE_MONETARY_H''@|$(HAVE_MONETARY_H)|g' \
+	      -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
+	      -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
+	      -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
+	      -e 's|@''NEXT_MONETARY_H''@|$(NEXT_MONETARY_H)|g' \
+	      -e 's|@''HAVE_XLOCALE_H''@|$(HAVE_XLOCALE_H)|g' \
+	      -e 's|@''GNULIB_STRFMON_L''@|$(GNULIB_STRFMON_L)|g' \
+	      -e 's|@''HAVE_STRFMON_L''@|$(HAVE_STRFMON_L)|g' \
+	      -e 's|@''REPLACE_STRFMON_L''@|$(REPLACE_STRFMON_L)|g' \
+	      -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \
+	      -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \
+	      -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \
+	      < $(srcdir)/monetary.in.h; \
+	} > $@-t && \
+	mv $@-t $@
+else
+monetary.h: $(top_builddir)/config.status
+	rm -f $@
+endif
+MOSTLYCLEANFILES += monetary.h monetary.h-t
+
+Include:
+#if HAVE_MONETARY_H
+<monetary.h>
+#endif
+
+License:
+LGPLv2+
+
+Maintainer:
+all
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/modules/monetary-c++-tests	Sat Sep 23 09:26:48 2017 +0200
@@ -0,0 +1,18 @@
+Files:
+tests/test-monetary-c++.cc
+tests/signature.h
+
+Status:
+c++-test
+
+Depends-on:
+ansi-c++-opt
+
+configure.ac:
+
+Makefile.am:
+if ANSICXX
+TESTS += test-monetary-c++
+check_PROGRAMS += test-monetary-c++
+test_monetary_c___SOURCES = test-monetary-c++.cc
+endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/modules/monetary-tests	Sat Sep 23 09:26:48 2017 +0200
@@ -0,0 +1,10 @@
+Files:
+tests/test-monetary.c
+
+Depends-on:
+
+configure.ac:
+
+Makefile.am:
+TESTS += test-monetary
+check_PROGRAMS += test-monetary
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-monetary-c++.cc	Sat Sep 23 09:26:48 2017 +0200
@@ -0,0 +1,39 @@
+/* Test of <monetary.h> substitute in C++ mode.
+   Copyright (C) 2017 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 of the License, 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, see <https://www.gnu.org/licenses/>.  */
+
+/* Written by Bruno Haible <bruno@clisp.org>, 2017.  */
+
+#define GNULIB_NAMESPACE gnulib
+#include <config.h>
+
+#if HAVE_MONETARY_H
+# include <monetary.h>
+#endif
+
+#include "signature.h"
+
+
+#if GNULIB_TEST_STRFMON_L
+SIGNATURE_CHECK (GNULIB_NAMESPACE::strfmon_l, ssize_t,
+                 (char *s, size_t maxsize, locale_t locale,
+                  const char *format, ...));
+#endif
+
+
+int
+main ()
+{
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-monetary.c	Sat Sep 23 09:26:48 2017 +0200
@@ -0,0 +1,29 @@
+/* Test of <monetary.h> substitute.
+   Copyright (C) 2017 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 of the License, 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, see <https://www.gnu.org/licenses/>.  */
+
+/* Written by Bruno Haible <bruno@clisp.org>, 2017.  */
+
+#include <config.h>
+
+#if HAVE_MONETARY_H
+# include <monetary.h>
+#endif
+
+int
+main ()
+{
+  return 0;
+}