]> Savannah Git Hosting - gnulib.git/commitdiff
monetary: New module.
authorBruno Haible <bruno@clisp.org>
Sat, 23 Sep 2017 07:26:48 +0000 (09:26 +0200)
committerBruno Haible <bruno@clisp.org>
Sat, 23 Sep 2017 15:29:05 +0000 (17:29 +0200)
* 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.

ChangeLog
doc/posix-headers/monetary.texi
lib/monetary.in.h [new file with mode: 0644]
m4/monetary_h.m4 [new file with mode: 0644]
modules/duplocale-tests
modules/monetary [new file with mode: 0644]
modules/monetary-c++-tests [new file with mode: 0644]
modules/monetary-tests [new file with mode: 0644]
tests/test-monetary-c++.cc [new file with mode: 0644]
tests/test-monetary.c [new file with mode: 0644]

index be1f9f8df46dd52b23f9631db3a6b3df2cba51e7..2b88ede19e0513b34007572825f4b97f2e9f330a 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -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.
index 834bf524f5f9a4b003052588f916e81319e9cd13..27ad38e4cd3403905f4bd841d972bcbc94aadba4 100644 (file)
@@ -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
diff --git a/lib/monetary.in.h b/lib/monetary.in.h
new file mode 100644 (file)
index 0000000..52966c4
--- /dev/null
@@ -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 */
diff --git a/m4/monetary_h.m4 b/m4/monetary_h.m4
new file mode 100644 (file)
index 0000000..3ef6a0b
--- /dev/null
@@ -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])
+])
index 3420abf5de52dd6dd67f687ba9aef3a828829ee3..baa9a6310255d72f885d33aa487d1a3760de176e 100644 (file)
@@ -8,7 +8,7 @@ langinfo
 
 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
diff --git a/modules/monetary b/modules/monetary
new file mode 100644 (file)
index 0000000..c8be360
--- /dev/null
@@ -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
diff --git a/modules/monetary-c++-tests b/modules/monetary-c++-tests
new file mode 100644 (file)
index 0000000..bd4d52e
--- /dev/null
@@ -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
diff --git a/modules/monetary-tests b/modules/monetary-tests
new file mode 100644 (file)
index 0000000..eedd0a1
--- /dev/null
@@ -0,0 +1,10 @@
+Files:
+tests/test-monetary.c
+
+Depends-on:
+
+configure.ac:
+
+Makefile.am:
+TESTS += test-monetary
+check_PROGRAMS += test-monetary
diff --git a/tests/test-monetary-c++.cc b/tests/test-monetary-c++.cc
new file mode 100644 (file)
index 0000000..6b3079a
--- /dev/null
@@ -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 ()
+{
+}
diff --git a/tests/test-monetary.c b/tests/test-monetary.c
new file mode 100644 (file)
index 0000000..c1f01fc
--- /dev/null
@@ -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;
+}