changeset 16720:7dbecbf765a8

New module 'localeconv'. * lib/locale.in.h (localeconv): New declaration. * lib/localeconv.c: New file. * m4/localeconv.m4: New file. * m4/locale_h.m4 (gl_LOCALE_H_DEFAULTS): Initialize GNULIB_LOCALECONV, REPLACE_LOCALECONV. * modules/locale (Makefile.am): Substitute GNULIB_LOCALECONV, REPLACE_LOCALECONV. * modules/localeconv: New file. * modules/nl_langinfo (Depends-on): Add localeconv. * modules/human (Depends-on): Likewise. * doc/posix-functions/localeconv.texi: Mention the new module.
author Bruno Haible <bruno@clisp.org>
date Sun, 25 Mar 2012 15:19:45 +0200
parents 8d5d2ed0afb0
children ec061881e329
files ChangeLog doc/posix-functions/localeconv.texi lib/locale.in.h lib/localeconv.c m4/locale_h.m4 m4/localeconv.m4 modules/human modules/locale modules/localeconv modules/nl_langinfo
diffstat 10 files changed, 210 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,18 @@
+2012-03-25  Bruno Haible  <bruno@clisp.org>
+
+	New module 'localeconv'.
+	* lib/locale.in.h (localeconv): New declaration.
+	* lib/localeconv.c: New file.
+	* m4/localeconv.m4: New file.
+	* m4/locale_h.m4 (gl_LOCALE_H_DEFAULTS): Initialize GNULIB_LOCALECONV,
+	REPLACE_LOCALECONV.
+	* modules/locale (Makefile.am): Substitute GNULIB_LOCALECONV,
+	REPLACE_LOCALECONV.
+	* modules/localeconv: New file.
+	* modules/nl_langinfo (Depends-on): Add localeconv.
+	* modules/human (Depends-on): Likewise.
+	* doc/posix-functions/localeconv.texi: Mention the new module.
+
 2012-03-25  Bruno Haible  <bruno@clisp.org>
 
 	locale: Provide a complete 'struct lconv'.
--- a/doc/posix-functions/localeconv.texi
+++ b/doc/posix-functions/localeconv.texi
@@ -4,10 +4,19 @@
 
 POSIX specification:@* @url{http://www.opengroup.org/onlinepubs/9699919799/functions/localeconv.html}
 
-Gnulib module: ---
+Gnulib module: localeconv
 
 Portability problems fixed by Gnulib:
 @itemize
+@item
+The @code{struct lconv} type does not contain any members on some platforms:
+Android.
+@item
+The @code{struct lconv} type does not contain the members
+@code{int_p_cs_precedes}, @code{int_p_sign_posn}, @code{int_p_sep_by_space},
+@code{int_n_cs_precedes}, @code{int_n_sign_posn}, @code{int_n_sep_by_space}
+on some platforms:
+glibc, OpenBSD 4.9, HP-UX 11, IRIX 6.5, OSF/1 5.1, Solaris 11 2011-11, Cygwin 1.5.x, mingw, MSVC 9.
 @end itemize
 
 Portability problems not fixed by Gnulib:
--- a/lib/locale.in.h
+++ b/lib/locale.in.h
@@ -128,6 +128,30 @@
 };
 #endif
 
+#if @GNULIB_LOCALECONV@
+# if @REPLACE_LOCALECONV@
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   undef localeconv
+#   define localeconv rpl_localeconv
+#  endif
+_GL_FUNCDECL_RPL (localeconv, struct lconv *, (void));
+_GL_CXXALIAS_RPL (localeconv, struct lconv *, (void));
+# else
+_GL_CXXALIAS_SYS (localeconv, struct lconv *, (void));
+# endif
+_GL_CXXALIASWARN (localeconv);
+#elif @REPLACE_STRUCT_LCONV@
+# undef localeconv
+# define localeconv localeconv_used_without_requesting_gnulib_module_localeconv
+#elif defined GNULIB_POSIXCHECK
+# undef localeconv
+# if HAVE_RAW_DECL_LOCALECONV
+_GL_WARN_ON_USE (localeconv,
+                 "localeconv returns too few information on some platforms - "
+                 "use gnulib module localeconv for portability");
+# endif
+#endif
+
 #if @GNULIB_SETLOCALE@
 # if @REPLACE_SETLOCALE@
 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
new file mode 100644
--- /dev/null
+++ b/lib/localeconv.c
@@ -0,0 +1,103 @@
+/* Query locale dependent information for formatting numbers.
+   Copyright (C) 2012 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 <http://www.gnu.org/licenses/>.  */
+
+#include <config.h>
+
+/* Specification.  */
+#include <locale.h>
+
+#if HAVE_STRUCT_LCONV_DECIMAL_POINT
+
+/* Override for platforms where 'struct lconv' lacks the int_p_*, int_n_*
+   members.  */
+
+struct lconv *
+localeconv (void)
+{
+  static struct lconv result;
+# undef lconv
+# undef localeconv
+  struct lconv *sys_result = localeconv ();
+
+  result.decimal_point = sys_result->decimal_point;
+  result.thousands_sep = sys_result->thousands_sep;
+  result.grouping = sys_result->grouping;
+  result.mon_decimal_point = sys_result->mon_decimal_point;
+  result.mon_thousands_sep = sys_result->mon_thousands_sep;
+  result.mon_grouping = sys_result->mon_grouping;
+  result.positive_sign = sys_result->positive_sign;
+  result.negative_sign = sys_result->negative_sign;
+  result.currency_symbol = sys_result->currency_symbol;
+  result.frac_digits = sys_result->frac_digits;
+  result.p_cs_precedes = sys_result->p_cs_precedes;
+  result.p_sign_posn = sys_result->p_sign_posn;
+  result.p_sep_by_space = sys_result->p_sep_by_space;
+  result.n_cs_precedes = sys_result->n_cs_precedes;
+  result.n_sign_posn = sys_result->n_sign_posn;
+  result.n_sep_by_space = sys_result->n_sep_by_space;
+  result.int_curr_symbol = sys_result->int_curr_symbol;
+  result.int_frac_digits = sys_result->int_frac_digits;
+  result.int_p_cs_precedes = sys_result->p_cs_precedes;
+  result.int_p_sign_posn = sys_result->p_sign_posn;
+  result.int_p_sep_by_space = sys_result->p_sep_by_space;
+  result.int_n_cs_precedes = sys_result->n_cs_precedes;
+  result.int_n_sign_posn = sys_result->n_sign_posn;
+  result.int_n_sep_by_space = sys_result->n_sep_by_space;
+
+  return &result;
+}
+
+#else
+
+/* Override for platforms where 'struct lconv' is a dummy.  */
+
+# include <limits.h>
+
+struct lconv *
+localeconv (void)
+{
+  static /*const*/ struct lconv result =
+    {
+      /* decimal_point */ ".",
+      /* thousands_sep */ "",
+      /* grouping */ "",
+      /* mon_decimal_point */ "",
+      /* mon_thousands_sep */ "",
+      /* mon_grouping */ "",
+      /* positive_sign */ "",
+      /* negative_sign */ "",
+      /* currency_symbol */ "",
+      /* frac_digits */ CHAR_MAX,
+      /* p_cs_precedes */ CHAR_MAX,
+      /* p_sign_posn */ CHAR_MAX,
+      /* p_sep_by_space */ CHAR_MAX,
+      /* n_cs_precedes */ CHAR_MAX,
+      /* n_sign_posn */ CHAR_MAX,
+      /* n_sep_by_space */ CHAR_MAX,
+      /* int_curr_symbol */ "",
+      /* int_frac_digits */ CHAR_MAX,
+      /* int_p_cs_precedes */ CHAR_MAX,
+      /* int_p_sign_posn */ CHAR_MAX,
+      /* int_p_sep_by_space */ CHAR_MAX,
+      /* int_n_cs_precedes */ CHAR_MAX,
+      /* int_n_sign_posn */ CHAR_MAX,
+      /* int_n_sep_by_space */ CHAR_MAX
+    };
+
+  return &result;
+}
+
+#endif
--- a/m4/locale_h.m4
+++ b/m4/locale_h.m4
@@ -1,4 +1,4 @@
-# locale_h.m4 serial 17
+# locale_h.m4 serial 18
 dnl Copyright (C) 2007, 2009-2012 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -110,10 +110,12 @@
 
 AC_DEFUN([gl_LOCALE_H_DEFAULTS],
 [
+  GNULIB_LOCALECONV=0; AC_SUBST([GNULIB_LOCALECONV])
   GNULIB_SETLOCALE=0;  AC_SUBST([GNULIB_SETLOCALE])
   GNULIB_DUPLOCALE=0;  AC_SUBST([GNULIB_DUPLOCALE])
   dnl Assume proper GNU behavior unless another module says otherwise.
   HAVE_DUPLOCALE=1;       AC_SUBST([HAVE_DUPLOCALE])
+  REPLACE_LOCALECONV=0;   AC_SUBST([REPLACE_LOCALECONV])
   REPLACE_SETLOCALE=0;    AC_SUBST([REPLACE_SETLOCALE])
   REPLACE_DUPLOCALE=0;    AC_SUBST([REPLACE_DUPLOCALE])
   REPLACE_STRUCT_LCONV=0; AC_SUBST([REPLACE_STRUCT_LCONV])
new file mode 100644
--- /dev/null
+++ b/m4/localeconv.m4
@@ -0,0 +1,22 @@
+# localeconv.m4 serial 1
+dnl Copyright (C) 2012 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_FUNC_LOCALECONV],
+[
+  AC_REQUIRE([gl_LOCALE_H_DEFAULTS])
+  AC_REQUIRE([gl_LOCALE_H])
+
+  if test $REPLACE_STRUCT_LCONV = 1; then
+    REPLACE_LOCALECONV=1
+  fi
+])
+
+# Prerequisites of lib/localeconv.c.
+AC_DEFUN([gl_PREREQ_LOCALECONV],
+[
+  AC_CHECK_MEMBERS([struct lconv.decimal_point], [], [],
+    [[#include <locale.h>]])
+])
--- a/modules/human
+++ b/modules/human
@@ -11,6 +11,7 @@
 argmatch
 error
 intprops
+localeconv
 memmove
 xstrtoumax
 stdbool
--- a/modules/locale
+++ b/modules/locale
@@ -29,10 +29,12 @@
 	      -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
 	      -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
 	      -e 's|@''NEXT_LOCALE_H''@|$(NEXT_LOCALE_H)|g' \
+	      -e 's/@''GNULIB_LOCALECONV''@/$(GNULIB_LOCALECONV)/g' \
 	      -e 's/@''GNULIB_SETLOCALE''@/$(GNULIB_SETLOCALE)/g' \
 	      -e 's/@''GNULIB_DUPLOCALE''@/$(GNULIB_DUPLOCALE)/g' \
 	      -e 's|@''HAVE_DUPLOCALE''@|$(HAVE_DUPLOCALE)|g' \
 	      -e 's|@''HAVE_XLOCALE_H''@|$(HAVE_XLOCALE_H)|g' \
+	      -e 's|@''REPLACE_LOCALECONV''@|$(REPLACE_LOCALECONV)|g' \
 	      -e 's|@''REPLACE_SETLOCALE''@|$(REPLACE_SETLOCALE)|g' \
 	      -e 's|@''REPLACE_DUPLOCALE''@|$(REPLACE_DUPLOCALE)|g' \
 	      -e 's|@''REPLACE_STRUCT_LCONV''@|$(REPLACE_STRUCT_LCONV)|g' \
new file mode 100644
--- /dev/null
+++ b/modules/localeconv
@@ -0,0 +1,29 @@
+Description:
+localeconv() function: query locale dependent information for formatting
+numbers.
+
+Files:
+lib/localeconv.c
+m4/localeconv.m4
+
+Depends-on:
+locale
+
+configure.ac:
+gl_FUNC_LOCALECONV
+if test $REPLACE_LOCALECONV = 1; then
+  AC_LIBOBJ([localeconv])
+  gl_PREREQ_LOCALECONV
+fi
+gl_LOCALE_MODULE_INDICATOR([localeconv])
+
+Makefile.am:
+
+Include:
+<locale.h>
+
+License:
+LGPLv2+
+
+Maintainer:
+Bruno Haible
--- a/modules/nl_langinfo
+++ b/modules/nl_langinfo
@@ -7,6 +7,7 @@
 
 Depends-on:
 langinfo
+localeconv      [test $HAVE_NL_LANGINFO = 0 || test $REPLACE_NL_LANGINFO = 1]
 
 configure.ac:
 gl_FUNC_NL_LANGINFO