1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-04-30 03:40:34 +02:00

i18n: Use Gnulib's `nl_langinfo' module.

* configure.ac: Remove checks for <langinfo.h> and <nl_types.h>, and
  `nl_langinfo'.

* libguile/i18n.c: Remove #ifdefs for HAVE_LANGINFO_H, HAVE_NL_TYPES_H,
  HAVE_NL_ITEM, and HAVE_LANGINFO_CODESET.
  (SCM_VALIDATE_OPTIONAL_LOCALE_COPY): Use `SCM_UNBNDP'.

* m4/gnulib-cache.m4 (gl_MODULES): Add `nl_langinfo'.

* module/ice-9/i18n.scm (define-vector-langinfo-mapping): Remove
  `defaults' parameter; assume (provided? 'nl-langinfo) is always true.
  Update users accordingly.
  (define-simple-langinfo-mapping): Likewise.
  (define-monetary-langinfo-mapping): Likewise, but do not assume
  LOCAL-ITEM and INTL-ITEM are always defined.
This commit is contained in:
Ludovic Courtès 2012-02-03 14:05:31 +01:00
parent eb4a14ed47
commit a0919aefee
5 changed files with 50 additions and 103 deletions

View file

@ -652,24 +652,13 @@ AC_SUBST([SCM_I_GSC_HAVE_STRUCT_DIRENT64])
# machine/fpu.h - on Tru64 5.1b, the declaration of fesetround(3) is in
# this file instead of <fenv.h>
# process.h - mingw specific
# langinfo.h, nl_types.h - SuS v2
# sched.h - missing on MinGW
#
AC_CHECK_HEADERS([complex.h fenv.h io.h libc.h limits.h memory.h process.h string.h \
sys/dir.h sys/ioctl.h sys/select.h \
sys/time.h sys/timeb.h sys/times.h sys/stdtypes.h sys/types.h \
sys/utime.h time.h unistd.h utime.h pwd.h grp.h sys/utsname.h \
direct.h langinfo.h nl_types.h machine/fpu.h poll.h sched.h])
# Reasons for testing:
# nl_item - lacking on Cygwin
AC_CHECK_TYPES([nl_item], [], [],
[[#ifdef HAVE_LANGINFO_H
# include <langinfo.h>
#endif
#ifdef HAVE_NL_TYPES_H
# include <nl_types.h>
#endif]])
direct.h machine/fpu.h poll.h sched.h])
# "complex double" is new in C99, and "complex" is only a keyword if
# <complex.h> is included
@ -764,11 +753,10 @@ AC_CHECK_HEADERS([assert.h crt_externs.h])
# isblank - available as a GNU extension or in C99
# _NSGetEnviron - Darwin specific
# strcoll_l, newlocale - GNU extensions (glibc), also available on Darwin
# nl_langinfo - X/Open, not available on Windows.
# utimensat: posix.1-2008
# sched_getaffinity, sched_setaffinity: GNU extensions (glibc)
#
AC_CHECK_FUNCS([DINFINITY DQNAN cexp chsize clog clog10 ctermid fesetround ftime ftruncate fchown getcwd geteuid getsid gettimeofday gmtime_r ioctl lstat mkdir mknod nice pipe _pipe poll readdir_r readdir64_r readlink rename rmdir select setegid seteuid setlocale setpgid setsid sigaction siginterrupt stat64 strftime strptime symlink sync sysconf tcgetpgrp tcsetpgrp times uname waitpid strdup system usleep atexit on_exit chown link fcntl ttyname getpwent getgrent kill getppid getpgrp fork setitimer getitimer strchr strcmp index bcopy memcpy rindex truncate unsetenv isblank _NSGetEnviron strcoll strcoll_l newlocale nl_langinfo utimensat sched_getaffinity sched_setaffinity])
AC_CHECK_FUNCS([DINFINITY DQNAN cexp chsize clog clog10 ctermid fesetround ftime ftruncate fchown getcwd geteuid getsid gettimeofday gmtime_r ioctl lstat mkdir mknod nice pipe _pipe poll readdir_r readdir64_r readlink rename rmdir select setegid seteuid setlocale setpgid setsid sigaction siginterrupt stat64 strftime strptime symlink sync sysconf tcgetpgrp tcsetpgrp times uname waitpid strdup system usleep atexit on_exit chown link fcntl ttyname getpwent getgrent kill getppid getpgrp fork setitimer getitimer strchr strcmp index bcopy memcpy rindex truncate unsetenv isblank _NSGetEnviron strcoll strcoll_l newlocale utimensat sched_getaffinity sched_setaffinity])
# Reasons for testing:
# netdb.h - not in mingw

View file

@ -21,7 +21,7 @@
# the same distribution terms as the rest of that program.
#
# Generated by gnulib-tool.
# Reproduce by: gnulib-tool --import --dir=. --local-dir=gnulib-local --lib=libgnu --source-base=lib --m4-base=m4 --doc-base=doc --tests-base=tests --aux-dir=build-aux --lgpl=3 --no-conditional-dependencies --libtool --macro-prefix=gl --no-vc-files accept alignof alloca-opt announce-gen autobuild bind byteswap canonicalize-lgpl ceil close connect dirfd duplocale environ extensions flock floor fpieee frexp full-read full-write func gendocs getaddrinfo getpeername getsockname getsockopt git-version-gen gitlog-to-changelog gnu-web-doc-update gnupload havelib iconv_open-utf inet_ntop inet_pton isinf isnan ldexp lib-symbol-versions lib-symbol-visibility libunistring listen localcharset locale log1p maintainer-makefile malloc-gnu malloca nproc open pipe2 putenv recv recvfrom regex rename send sendto setenv setsockopt shutdown socket stat-time stdlib strftime striconveh string sys_stat trunc verify vsnprintf warnings wchar
# Reproduce by: gnulib-tool --import --dir=. --local-dir=gnulib-local --lib=libgnu --source-base=lib --m4-base=m4 --doc-base=doc --tests-base=tests --aux-dir=build-aux --lgpl=3 --no-conditional-dependencies --libtool --macro-prefix=gl --no-vc-files accept alignof alloca-opt announce-gen autobuild bind byteswap canonicalize-lgpl ceil close connect dirfd duplocale environ extensions flock floor fpieee frexp full-read full-write func gendocs getaddrinfo getpeername getsockname getsockopt git-version-gen gitlog-to-changelog gnu-web-doc-update gnupload havelib iconv_open-utf inet_ntop inet_pton isinf isnan ldexp lib-symbol-versions lib-symbol-visibility libunistring listen localcharset locale log1p maintainer-makefile malloc-gnu malloca nl_langinfo nproc open pipe2 putenv recv recvfrom regex rename send sendto setenv setsockopt shutdown socket stat-time stdlib strftime striconveh string sys_stat trunc verify vsnprintf warnings wchar
AUTOMAKE_OPTIONS = 1.5 gnits subdir-objects

View file

@ -59,16 +59,8 @@
#include "libguile/posix.h" /* for `scm_i_locale_mutex' */
#ifdef HAVE_LANGINFO_H
# include <langinfo.h>
#endif
#ifdef HAVE_NL_TYPES_H
# include <nl_types.h>
#endif
#ifndef HAVE_NL_ITEM
/* Cygwin has <langinfo.h> but lacks <nl_types.h> and `nl_item'. */
typedef int nl_item;
#endif
/* Use Gnulib's header, which also provides `nl_item' & co. */
#include <langinfo.h>
#ifndef HAVE_SETLOCALE
static inline char *
@ -223,7 +215,7 @@ SCM_GLOBAL_VARIABLE (scm_global_locale, "%global-locale");
#define SCM_VALIDATE_OPTIONAL_LOCALE_COPY(_pos, _arg, _c_locale) \
do \
{ \
if (!scm_is_eq ((_arg), SCM_UNDEFINED)) \
if (!SCM_UNBNDP (_arg)) \
SCM_VALIDATE_LOCALE_COPY (_pos, _arg, _c_locale); \
else \
(_c_locale) = NULL; \
@ -1481,14 +1473,11 @@ SCM_DEFINE (scm_nl_langinfo, "nl-langinfo", 1, 1, 0,
"Reference Manual}).")
#define FUNC_NAME s_scm_nl_langinfo
{
#ifdef HAVE_NL_LANGINFO
SCM result;
nl_item c_item;
char *c_result;
scm_t_locale c_locale;
#ifdef HAVE_LANGINFO_CODESET
char *codeset;
#endif
SCM_VALIDATE_INT_COPY (2, item, c_item);
SCM_VALIDATE_OPTIONAL_LOCALE_COPY (2, locale, c_locale);
@ -1505,9 +1494,7 @@ SCM_DEFINE (scm_nl_langinfo, "nl-langinfo", 1, 1, 0,
{
#ifdef USE_GNU_LOCALE_API
c_result = nl_langinfo_l (c_item, c_locale);
#ifdef HAVE_LANGINFO_CODESET
codeset = nl_langinfo_l (CODESET, c_locale);
#endif /* HAVE_LANGINFO_CODESET */
#else /* !USE_GNU_LOCALE_API */
/* We can't use `RUN_IN_LOCALE_SECTION ()' here because the locale
mutex is already taken. */
@ -1532,9 +1519,7 @@ SCM_DEFINE (scm_nl_langinfo, "nl-langinfo", 1, 1, 0,
else
{
c_result = nl_langinfo (c_item);
#ifdef HAVE_LANGINFO_CODESET
codeset = nl_langinfo (CODESET);
#endif /* HAVE_LANGINFO_CODESET */
restore_locale_settings (&lsec_prev_locale);
free_locale_settings (&lsec_prev_locale);
@ -1544,9 +1529,7 @@ SCM_DEFINE (scm_nl_langinfo, "nl-langinfo", 1, 1, 0,
else
{
c_result = nl_langinfo (c_item);
#ifdef HAVE_LANGINFO_CODESET
codeset = nl_langinfo (CODESET);
#endif /* HAVE_LANGINFO_CODESET */
}
c_result = strdup (c_result);
@ -1659,26 +1642,14 @@ SCM_DEFINE (scm_nl_langinfo, "nl-langinfo", 1, 1, 0,
#endif
default:
#ifdef HAVE_LANGINFO_CODESET
result = scm_from_stringn (c_result, strlen (c_result),
codeset,
SCM_FAILED_CONVERSION_QUESTION_MARK);
#else /* !HAVE_LANGINFO_CODESET */
/* This may be incorrectly encoded if the locale differs
from the c_locale. */
result = scm_from_locale_string (c_result);
#endif /* !HAVE_LANGINFO_CODESET */
free (c_result);
}
}
return result;
#else
scm_syserror_msg (FUNC_NAME, "`nl-langinfo' not supported on your system",
SCM_EOL, ENOSYS);
return SCM_BOOL_F;
#endif
}
#undef FUNC_NAME
@ -1686,8 +1657,6 @@ SCM_DEFINE (scm_nl_langinfo, "nl-langinfo", 1, 1, 0,
static inline void
define_langinfo_items (void)
{
#ifdef HAVE_LANGINFO_H
#define DEFINE_NLITEM_CONSTANT(_item) \
scm_c_define (# _item, scm_from_int (_item))
@ -1852,8 +1821,6 @@ define_langinfo_items (void)
#endif
#undef DEFINE_NLITEM_CONSTANT
#endif /* HAVE_NL_TYPES_H */
}
@ -1862,10 +1829,8 @@ scm_init_i18n ()
{
SCM global_locale_smob;
#ifdef HAVE_NL_LANGINFO
scm_add_feature ("nl-langinfo");
define_langinfo_items ();
#endif
#include "libguile/i18n.x"

View file

@ -27,7 +27,7 @@
# Specification in the form of a command-line invocation:
# gnulib-tool --import --dir=. --local-dir=gnulib-local --lib=libgnu --source-base=lib --m4-base=m4 --doc-base=doc --tests-base=tests --aux-dir=build-aux --lgpl=3 --no-conditional-dependencies --libtool --macro-prefix=gl --no-vc-files accept alignof alloca-opt announce-gen autobuild bind byteswap canonicalize-lgpl ceil close connect dirfd duplocale environ extensions flock floor fpieee frexp full-read full-write func gendocs getaddrinfo getpeername getsockname getsockopt git-version-gen gitlog-to-changelog gnu-web-doc-update gnupload havelib iconv_open-utf inet_ntop inet_pton isinf isnan ldexp lib-symbol-versions lib-symbol-visibility libunistring listen localcharset locale log1p maintainer-makefile malloc-gnu malloca nproc open pipe2 putenv recv recvfrom regex rename send sendto setenv setsockopt shutdown socket stat-time stdlib strftime striconveh string sys_stat trunc verify vsnprintf warnings wchar
# gnulib-tool --import --dir=. --local-dir=gnulib-local --lib=libgnu --source-base=lib --m4-base=m4 --doc-base=doc --tests-base=tests --aux-dir=build-aux --lgpl=3 --no-conditional-dependencies --libtool --macro-prefix=gl --no-vc-files accept alignof alloca-opt announce-gen autobuild bind byteswap canonicalize-lgpl ceil close connect dirfd duplocale environ extensions flock floor fpieee frexp full-read full-write func gendocs getaddrinfo getpeername getsockname getsockopt git-version-gen gitlog-to-changelog gnu-web-doc-update gnupload havelib iconv_open-utf inet_ntop inet_pton isinf isnan ldexp lib-symbol-versions lib-symbol-visibility libunistring listen localcharset locale log1p maintainer-makefile malloc-gnu malloca nl_langinfo nproc open pipe2 putenv recv recvfrom regex rename send sendto setenv setsockopt shutdown socket stat-time stdlib strftime striconveh string sys_stat trunc verify vsnprintf warnings wchar
# Specification in the form of a few gnulib-tool.m4 macro invocations:
gl_LOCAL_DIR([gnulib-local])
@ -80,6 +80,7 @@ gl_MODULES([
maintainer-makefile
malloc-gnu
malloca
nl_langinfo
nproc
open
pipe2

View file

@ -1,6 +1,6 @@
;;;; i18n.scm --- internationalization support -*- coding: utf-8 -*-
;;;; Copyright (C) 2006, 2007, 2009, 2010 Free Software Foundation, Inc.
;;;; Copyright (C) 2006, 2007, 2009, 2010, 2012 Free Software Foundation, Inc.
;;;;
;;;; This library is free software; you can redistribute it and/or
;;;; modify it under the terms of the GNU Lesser General Public
@ -101,13 +101,10 @@
;;;
;; Helper macro: Define a procedure named NAME that maps its argument to
;; NL-ITEMS (when `nl-langinfo' is provided) or DEFAULTS (when `nl-langinfo'
;; is not provided).
(define-macro (define-vector-langinfo-mapping name nl-items defaults)
;; NL-ITEMS (when `nl-langinfo' is provided).
(define-macro (define-vector-langinfo-mapping name nl-items)
(let* ((item-count (length nl-items))
(defines (if (provided? 'nl-langinfo)
`(define %nl-items (vector #f ,@nl-items))
`(define %defaults (vector #f ,@defaults))))
(defines `(define %nl-items (vector #f ,@nl-items)))
(make-body (lambda (result)
`(if (and (integer? item) (exact? item))
(if (and (>= item 1) (<= item ,item-count))
@ -116,28 +113,21 @@
(throw 'wrong-type-arg "wrong argument type" item)))))
`(define (,name item . locale)
,defines
,(make-body (if (provided? 'nl-langinfo)
'(apply nl-langinfo (vector-ref %nl-items item) locale)
'(vector-ref %defaults item))))))
,(make-body '(apply nl-langinfo (vector-ref %nl-items item) locale)))))
(define-vector-langinfo-mapping locale-day-short
(ABDAY_1 ABDAY_2 ABDAY_3 ABDAY_4 ABDAY_5 ABDAY_6 ABDAY_7)
("Sun" "Mon" "Tue" "Wed" "Thu" "Fri" "Sat"))
(ABDAY_1 ABDAY_2 ABDAY_3 ABDAY_4 ABDAY_5 ABDAY_6 ABDAY_7))
(define-vector-langinfo-mapping locale-day
(DAY_1 DAY_2 DAY_3 DAY_4 DAY_5 DAY_6 DAY_7)
("Sunday" "Monday" "Tuesday" "Wednesday" "Thursday" "Friday" "Saturday"))
(DAY_1 DAY_2 DAY_3 DAY_4 DAY_5 DAY_6 DAY_7))
(define-vector-langinfo-mapping locale-month-short
(ABMON_1 ABMON_2 ABMON_3 ABMON_4 ABMON_5 ABMON_6
ABMON_7 ABMON_8 ABMON_9 ABMON_10 ABMON_11 ABMON_12)
("Jan" "Feb" "Mar" "Apr" "May" "Jun" "Jul" "Aug" "Sep" "Oct" "Nov" "Dec"))
ABMON_7 ABMON_8 ABMON_9 ABMON_10 ABMON_11 ABMON_12))
(define-vector-langinfo-mapping locale-month
(MON_1 MON_2 MON_3 MON_4 MON_5 MON_6 MON_7 MON_8 MON_9 MON_10 MON_11 MON_12)
("January" "February" "March" "April" "May" "June" "July" "August"
"September" "October" "November" "December"))
(MON_1 MON_2 MON_3 MON_4 MON_5 MON_6 MON_7 MON_8 MON_9 MON_10 MON_11 MON_12))
@ -145,36 +135,34 @@
;;; Date and time.
;;;
;; Helper macro: Define a procedure NAME that gets langinfo item ITEM.
(define-macro (define-simple-langinfo-mapping name item default)
(let ((body (if (and (provided? 'nl-langinfo) (defined? item))
`(apply nl-langinfo ,item locale)
default)))
`(define (,name . locale)
,body)))
;; Define a procedure NAME that gets langinfo item ITEM. Gnulib's
;; `nl_langinfo' guarantees that all these items are supported.
(define-syntax-rule (define-simple-langinfo-mapping name item)
(define* (name #:optional (locale %global-locale))
(nl-langinfo item locale)))
(define-simple-langinfo-mapping locale-am-string
AM_STR "AM")
AM_STR)
(define-simple-langinfo-mapping locale-pm-string
PM_STR "PM")
PM_STR)
(define-simple-langinfo-mapping locale-date+time-format
D_T_FMT "%a %b %e %H:%M:%S %Y")
D_T_FMT)
(define-simple-langinfo-mapping locale-date-format
D_FMT "%m/%d/%y")
D_FMT)
(define-simple-langinfo-mapping locale-time-format
T_FMT "%H:%M:%S")
T_FMT)
(define-simple-langinfo-mapping locale-time+am/pm-format
T_FMT_AMPM "%I:%M:%S %p")
T_FMT_AMPM)
(define-simple-langinfo-mapping locale-era
ERA "")
ERA)
(define-simple-langinfo-mapping locale-era-year
ERA_YEAR "")
ERA_YEAR)
(define-simple-langinfo-mapping locale-era-date+time-format
ERA_D_T_FMT "")
ERA_D_T_FMT)
(define-simple-langinfo-mapping locale-era-date-format
ERA_D_FMT "")
ERA_D_FMT)
(define-simple-langinfo-mapping locale-era-time-format
ERA_T_FMT "")
ERA_T_FMT)
@ -182,13 +170,18 @@
;;; Monetary information.
;;;
;; Define a procedure NAME that gets item LOCAL-ITEM or INTL-ITEM,
;; depending on whether the caller asked for the international version
;; or not. Since Gnulib's `nl_langinfo' module doesn't guarantee that
;; all these items are available, use DEFAULT/LOCAL and DEFAULT/INTL as
;; default values when the system does not support them.
(define-macro (define-monetary-langinfo-mapping name local-item intl-item
default/local default/intl)
(let ((body
(let ((intl (if (and (provided? 'nl-langinfo) (defined? intl-item))
(let ((intl (if (defined? intl-item)
`(apply nl-langinfo ,intl-item locale)
default/intl))
(local (if (and (provided? 'nl-langinfo) (defined? local-item))
(local (if (defined? local-item)
`(apply nl-langinfo ,local-item locale)
default/local)))
`(if intl? ,intl ,local))))
@ -205,15 +198,15 @@
2 2)
(define-simple-langinfo-mapping locale-monetary-positive-sign
POSITIVE_SIGN "+")
POSITIVE_SIGN)
(define-simple-langinfo-mapping locale-monetary-negative-sign
NEGATIVE_SIGN "-")
NEGATIVE_SIGN)
(define-simple-langinfo-mapping locale-monetary-decimal-point
MON_DECIMAL_POINT "")
MON_DECIMAL_POINT)
(define-simple-langinfo-mapping locale-monetary-thousands-separator
MON_THOUSANDS_SEP "")
MON_THOUSANDS_SEP)
(define-simple-langinfo-mapping locale-monetary-digit-grouping
MON_GROUPING '())
MON_GROUPING)
(define-monetary-langinfo-mapping locale-currency-symbol-precedes-positive?
P_CS_PRECEDES INT_P_CS_PRECEDES
@ -359,11 +352,11 @@ locale is used."
;;;
(define-simple-langinfo-mapping locale-digit-grouping
GROUPING '())
GROUPING)
(define-simple-langinfo-mapping locale-decimal-point
RADIXCHAR ".")
RADIXCHAR)
(define-simple-langinfo-mapping locale-thousands-separator
THOUSEP "")
THOUSEP)
(define* (number->locale-string number
#:optional (fraction-digits #t)
@ -409,9 +402,9 @@ number of fractional digits to be displayed."
;;;
(define-simple-langinfo-mapping locale-yes-regexp
YESEXPR "^[yY]")
YESEXPR)
(define-simple-langinfo-mapping locale-no-regexp
NOEXPR "^[nN]")
NOEXPR)
;; `YESSTR' and `NOSTR' are considered deprecated so we don't provide them.