summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruno Haible <bruno@clisp.org>2012-03-25 15:19:45 +0200
committerBruno Haible <bruno@clisp.org>2012-03-25 15:19:45 +0200
commit0491c1244075391cb114940990fa85afd28d54af (patch)
tree4b5ef3f8b6c3e30924b333236bb5fbd585d8d1fa
parent7c05b5f06162c3c1667ae139bb81a8621971a325 (diff)
downloadgnulib-0491c1244075391cb114940990fa85afd28d54af.tar.gz
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.
-rw-r--r--ChangeLog15
-rw-r--r--doc/posix-functions/localeconv.texi11
-rw-r--r--lib/locale.in.h24
-rw-r--r--lib/localeconv.c103
-rw-r--r--m4/locale_h.m44
-rw-r--r--m4/localeconv.m422
-rw-r--r--modules/human1
-rw-r--r--modules/locale2
-rw-r--r--modules/localeconv29
-rw-r--r--modules/nl_langinfo1
10 files changed, 210 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index 15dde819cc..17ad4f3b3f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,20 @@
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'.
* m4/locale_h.m4 (gl_LOCALE_H): Set REPLACE_STRUCT_LCONV to 1 if
'struct lconv' does not contain int_p_cs_precedes.
diff --git a/doc/posix-functions/localeconv.texi b/doc/posix-functions/localeconv.texi
index f6bde8dcb0..2b331c6876 100644
--- 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:
diff --git a/lib/locale.in.h b/lib/locale.in.h
index 41c641430b..7747902cbd 100644
--- a/lib/locale.in.h
+++ b/lib/locale.in.h
@@ -128,6 +128,30 @@ struct lconv
};
#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)
diff --git a/lib/localeconv.c b/lib/localeconv.c
new file mode 100644
index 0000000000..2c91b374f0
--- /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
diff --git a/m4/locale_h.m4 b/m4/locale_h.m4
index 266a2b1e41..fb72e4e51e 100644
--- 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_MODULE_INDICATOR],
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])
diff --git a/m4/localeconv.m4 b/m4/localeconv.m4
new file mode 100644
index 0000000000..5fae06d883
--- /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>]])
+])
diff --git a/modules/human b/modules/human
index a88b15ed9e..2ad48f28fb 100644
--- a/modules/human
+++ b/modules/human
@@ -11,6 +11,7 @@ Depends-on:
argmatch
error
intprops
+localeconv
memmove
xstrtoumax
stdbool
diff --git a/modules/locale b/modules/locale
index 09f2d67e23..d7e3789ed0 100644
--- a/modules/locale
+++ b/modules/locale
@@ -29,10 +29,12 @@ locale.h: locale.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H
-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' \
diff --git a/modules/localeconv b/modules/localeconv
new file mode 100644
index 0000000000..60864856a5
--- /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
diff --git a/modules/nl_langinfo b/modules/nl_langinfo
index e749cbdd59..f92ed3e0c7 100644
--- a/modules/nl_langinfo
+++ b/modules/nl_langinfo
@@ -7,6 +7,7 @@ m4/nl_langinfo.m4
Depends-on:
langinfo
+localeconv [test $HAVE_NL_LANGINFO = 0 || test $REPLACE_NL_LANGINFO = 1]
configure.ac:
gl_FUNC_NL_LANGINFO