Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCorinna Vinschen <corinna@vinschen.de>2010-04-28 13:59:37 +0400
committerCorinna Vinschen <corinna@vinschen.de>2010-04-28 13:59:37 +0400
commitd47d5b850bed398357e7f05d8fef508be1bb7f51 (patch)
tree8571d6a5751c102c12b11c58261ee663e83d7fce /newlib/libc/locale
parent9b53b52a80f79a7746f51e2092b23dfab3d50c6f (diff)
Extend locale support to maintain wide char values of native strings
if __HAVE_LOCALE_INFO_EXTENDED__ is defined. * libc/include/langinfo.h (enum __nl_item): New type. Define all native values accessible through nl_langinfo. Define previously existing POSIX-compatible values as macros as well. * libc/include/stdlib.h (__mb_cur_max): Drop declaration. (__locale_mb_cur_max): Declare. (MB_CUR_MAX): Re-define calling __locale_mb_cur_max. * libc/locale/Makefile.am (ELIX_SOURCES): Add lctype.c. * libc/locale/Makefile.in: Regenerate. * libc/locale/lctype.c: New file to define and load LC_CTYPE category. * libc/locale/lctype.h: New file, matching header. * libc/locale/lmessages.c (_C_messages_locale): Add default values for wide char members. (__messages_load_locale): Add _C_messages_locale in call to __set_lc_messages_from_win. * libc/locale/lmessages.h (struct lc_messages_T): Add wide char members. * libc/locale/lmonetary.c (_C_monetary_locale): Add default values for wide char members. (__monetary_load_locale): Add _C_monetary_locale in call to __set_lc_monetary_from_win. * libc/locale/lmonetary.h (struct lc_monetary_T): Add wide char members. Add numerical values for international currency formatting per POSIX-1.2008, if __HAVE_LOCALE_INFO_EXTENDED__ is defined. * libc/locale/lnumeric.c (_C_numeric_locale): Add default values for wide char members. (__numeric_load_locale): Add _C_numeric_locale in call to __set_lc_numeric_from_win. * libc/locale/lnumeric.h (struct lc_numeric_T): Add wide char members. * libc/locale/locale.c (loadlocale): Return doing nothing if category locale didn't change. Convert category if chain to switch statement. Call __ctype_load_locale in LC_CTYPE case. (__locale_charset): Add (but disable for now) returning codeset from __get_current_ctype_locale. (__locale_mb_cur_max): Add (but disable for now) returning mb_cur_max from __get_current_ctype_locale. (__locale_msgcharset): Add returning codeset from __get_current_messages_locale. (_localeconv_r): Accommodate int_XXX values. * libc/locale/nl_langinfo.c (nl_ext): New array to define what is to be returned for non-POSIX values. (nl_Langinfo): Return correct codeset for each locale category. Return extended values if __HAVE_LOCALE_INFO_EXTENDED__ is defined. * libc/locale/timelocal.c (_C_time_locale): Add default values for wide char members. (__time_load_locale): Add _C_time_locale in call to __set_lc_time_from_win. * libc/locale/timelocal.h (struct lc_time_T): Add wide char members. * libc/stdio/vfwprintf.c (_VFWPRINTF_R): Use wide char decimal point and thousands_sep if __HAVE_LOCALE_INFO_EXTENDED__ is defined. * libc/time/strftime.c: Rework to accommodate availability of wide char strings in LC_TIME category if __HAVE_LOCALE_INFO_EXTENDED__ is defined.
Diffstat (limited to 'newlib/libc/locale')
-rw-r--r--newlib/libc/locale/Makefile.am3
-rw-r--r--newlib/libc/locale/Makefile.in15
-rw-r--r--newlib/libc/locale/lctype.c108
-rw-r--r--newlib/libc/locale/lctype.h47
-rw-r--r--newlib/libc/locale/lmessages.c11
-rw-r--r--newlib/libc/locale/lmessages.h9
-rw-r--r--newlib/libc/locale/lmonetary.c22
-rw-r--r--newlib/libc/locale/lmonetary.h17
-rw-r--r--newlib/libc/locale/lnumeric.c18
-rw-r--r--newlib/libc/locale/lnumeric.h7
-rw-r--r--newlib/libc/locale/locale.c77
-rw-r--r--newlib/libc/locale/nl_langinfo.c171
-rw-r--r--newlib/libc/locale/timelocal.c36
-rw-r--r--newlib/libc/locale/timelocal.h22
14 files changed, 530 insertions, 33 deletions
diff --git a/newlib/libc/locale/Makefile.am b/newlib/libc/locale/Makefile.am
index 02b586b23..66cc7ba9e 100644
--- a/newlib/libc/locale/Makefile.am
+++ b/newlib/libc/locale/Makefile.am
@@ -17,7 +17,8 @@ ELIX_SOURCES = \
lnumeric.c \
lmonetary.c \
nl_langinfo.c \
- timelocal.c
+ timelocal.c \
+ lctype.c
endif
liblocale_la_LDFLAGS = -Xcompiler -nostdlib
diff --git a/newlib/libc/locale/Makefile.in b/newlib/libc/locale/Makefile.in
index fe128f4ae..57a52fe5c 100644
--- a/newlib/libc/locale/Makefile.in
+++ b/newlib/libc/locale/Makefile.in
@@ -62,7 +62,8 @@ am__objects_1 = lib_a-locale.$(OBJEXT)
@ELIX_LEVEL_1_FALSE@ lib_a-lnumeric.$(OBJEXT) \
@ELIX_LEVEL_1_FALSE@ lib_a-lmonetary.$(OBJEXT) \
@ELIX_LEVEL_1_FALSE@ lib_a-nl_langinfo.$(OBJEXT) \
-@ELIX_LEVEL_1_FALSE@ lib_a-timelocal.$(OBJEXT)
+@ELIX_LEVEL_1_FALSE@ lib_a-timelocal.$(OBJEXT) \
+@ELIX_LEVEL_1_FALSE@ lib_a-lctype.$(OBJEXT)
@USE_LIBTOOL_FALSE@am_lib_a_OBJECTS = $(am__objects_1) \
@USE_LIBTOOL_FALSE@ $(am__objects_2)
lib_a_OBJECTS = $(am_lib_a_OBJECTS)
@@ -71,7 +72,7 @@ liblocale_la_LIBADD =
am__objects_3 = locale.lo
@ELIX_LEVEL_1_FALSE@am__objects_4 = fix_grouping.lo ldpart.lo \
@ELIX_LEVEL_1_FALSE@ lmessages.lo lnumeric.lo lmonetary.lo \
-@ELIX_LEVEL_1_FALSE@ nl_langinfo.lo timelocal.lo
+@ELIX_LEVEL_1_FALSE@ nl_langinfo.lo timelocal.lo lctype.lo
@USE_LIBTOOL_TRUE@am_liblocale_la_OBJECTS = $(am__objects_3) \
@USE_LIBTOOL_TRUE@ $(am__objects_4)
liblocale_la_OBJECTS = $(am_liblocale_la_OBJECTS)
@@ -168,6 +169,7 @@ PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
PACKAGE_NAME = @PACKAGE_NAME@
PACKAGE_STRING = @PACKAGE_STRING@
PACKAGE_TARNAME = @PACKAGE_TARNAME@
+PACKAGE_URL = @PACKAGE_URL@
PACKAGE_VERSION = @PACKAGE_VERSION@
PATH_SEPARATOR = @PATH_SEPARATOR@
RANLIB = @RANLIB@
@@ -247,7 +249,8 @@ GENERAL_SOURCES = timelocal.h ldpart.h locale.c lnumeric.h lmonetary.h lmessages
@ELIX_LEVEL_1_FALSE@ lnumeric.c \
@ELIX_LEVEL_1_FALSE@ lmonetary.c \
@ELIX_LEVEL_1_FALSE@ nl_langinfo.c \
-@ELIX_LEVEL_1_FALSE@ timelocal.c
+@ELIX_LEVEL_1_FALSE@ timelocal.c \
+@ELIX_LEVEL_1_FALSE@ lctype.c
@ELIX_LEVEL_1_TRUE@ELIX_SOURCES =
liblocale_la_LDFLAGS = -Xcompiler -nostdlib
@@ -379,6 +382,12 @@ lib_a-timelocal.o: timelocal.c
lib_a-timelocal.obj: timelocal.c
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-timelocal.obj `if test -f 'timelocal.c'; then $(CYGPATH_W) 'timelocal.c'; else $(CYGPATH_W) '$(srcdir)/timelocal.c'; fi`
+lib_a-lctype.o: lctype.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-lctype.o `test -f 'lctype.c' || echo '$(srcdir)/'`lctype.c
+
+lib_a-lctype.obj: lctype.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-lctype.obj `if test -f 'lctype.c'; then $(CYGPATH_W) 'lctype.c'; else $(CYGPATH_W) '$(srcdir)/lctype.c'; fi`
+
mostlyclean-libtool:
-rm -f *.lo
diff --git a/newlib/libc/locale/lctype.c b/newlib/libc/locale/lctype.c
new file mode 100644
index 000000000..bd027ceaa
--- /dev/null
+++ b/newlib/libc/locale/lctype.c
@@ -0,0 +1,108 @@
+/*
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <limits.h>
+#include "lctype.h"
+#include "ldpart.h"
+
+#define LCCTYPE_SIZE (sizeof(struct lc_ctype_T) / sizeof(char *))
+
+static char numone[] = { '\1', '\0'};
+
+static const struct lc_ctype_T _C_ctype_locale = {
+ "ASCII", /* codeset */
+ numone /* mb_cur_max */
+#ifdef __HAVE_LOCALE_INFO_EXTENDED__
+ , "0", "1", "2", "3", "4", /* outdigits */
+ "5", "6", "7", "8", "9",
+ L"0", L"1", L"2", L"3", L"4", /* woutdigits */
+ L"5", L"6", L"7", L"8", L"9"
+#endif
+};
+
+static struct lc_ctype_T _ctype_locale;
+static int _ctype_using_locale;
+#ifdef __HAVE_LOCALE_INFO_EXTENDED__
+static char *_ctype_locale_buf;
+#else
+/* Max encoding_len + NUL byte + 1 byte mb_cur_max plus trailing NUL byte */
+#define _CTYPE_BUF_SIZE (ENCODING_LEN + 3)
+static char _ctype_locale_buf[_CTYPE_BUF_SIZE];
+#endif
+
+int
+__ctype_load_locale(const char *name, void *f_wctomb, const char *charset,
+ int mb_cur_max)
+{
+ int ret;
+
+#ifdef __CYGWIN__
+ extern int __set_lc_ctype_from_win (const char *,
+ const struct lc_ctype_T *,
+ struct lc_ctype_T *, char **,
+ void *, const char *, int);
+ int old_ctype_using_locale = _ctype_using_locale;
+ _ctype_using_locale = 0;
+ ret = __set_lc_ctype_from_win (name, &_C_ctype_locale, &_ctype_locale,
+ &_ctype_locale_buf, f_wctomb, charset,
+ mb_cur_max);
+ /* ret == -1: error, ret == 0: C/POSIX, ret > 0: valid */
+ if (ret < 0)
+ _ctype_using_locale = old_ctype_using_locale;
+ else
+ {
+ _ctype_using_locale = ret;
+ ret = 0;
+ }
+#elif !defined (__HAVE_LOCALE_INFO_EXTENDED__)
+ if (!strcmp (name, "C"))
+ _ctype_using_locale = 0;
+ else
+ {
+ _ctype_locale.codeset = _ctype_locale_buf;
+ _ctype_locale.mb_cur_max = _ctype_locale_buf + _CTYPE_BUF_SIZE - 2;
+ strcpy (_ctype_locale.codeset, charset);
+ _ctype_locale.mb_cur_max[0] = mb_cur_max;
+ _ctype_locale.mb_cur_max[1] = '\0';
+ _ctype_using_locale = 1;
+ }
+ ret = 0;
+#else
+ ret = __part_load_locale(name, &_ctype_using_locale,
+ _ctype_locale_buf, "LC_CTYPE",
+ LCCTYPE_SIZE, LCCTYPE_SIZE,
+ (const char **)&_ctype_locale);
+ if (ret == 0 && _ctype_using_locale)
+ _ctype_locale.grouping =
+ __fix_locale_grouping_str(_ctype_locale.grouping);
+#endif
+ return ret;
+}
+
+struct lc_ctype_T *
+__get_current_ctype_locale(void) {
+
+ return (_ctype_using_locale
+ ? &_ctype_locale
+ : (struct lc_ctype_T *)&_C_ctype_locale);
+}
diff --git a/newlib/libc/locale/lctype.h b/newlib/libc/locale/lctype.h
new file mode 100644
index 000000000..663074f54
--- /dev/null
+++ b/newlib/libc/locale/lctype.h
@@ -0,0 +1,47 @@
+/*
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef _LCTYPE_H_
+#define _LCTYPE_H_
+
+#include <_ansi.h>
+#include <sys/cdefs.h>
+#include <wchar.h>
+
+__BEGIN_DECLS
+
+struct lc_ctype_T {
+ const char *codeset; /* codeset for mbtowc conversion */
+ const char *mb_cur_max;
+#ifdef __HAVE_LOCALE_INFO_EXTENDED__
+ const char *outdigits[10];
+ const wchar_t *woutdigits[10];
+#endif
+};
+
+struct lc_ctype_T *__get_current_ctype_locale(void);
+int __ctype_load_locale(const char *, void *, const char *, int);
+
+__END_DECLS
+
+#endif /* !_LCTYPE_H_ */
diff --git a/newlib/libc/locale/lmessages.c b/newlib/libc/locale/lmessages.c
index 24e4858d5..12373c28e 100644
--- a/newlib/libc/locale/lmessages.c
+++ b/newlib/libc/locale/lmessages.c
@@ -42,6 +42,13 @@ static const struct lc_messages_T _C_messages_locale = {
"^[nN]" , /* noexpr */
"yes" , /* yesstr */
"no" /* nostr */
+ "ASCII" /* codeset */
+#ifdef __HAVE_LOCALE_INFO_EXTENDED__
+ , L"^[yY]" , /* wyesexpr */
+ L"^[nN]" , /* wnoexpr */
+ L"yes" , /* wyesstr */
+ L"no" /* wnostr */
+#endif
};
static struct lc_messages_T _messages_locale;
@@ -53,13 +60,15 @@ __messages_load_locale (const char *name, void *f_wctomb, const char *charset)
{
#ifdef __CYGWIN__
extern int __set_lc_messages_from_win (const char *,
+ const struct lc_messages_T *,
struct lc_messages_T *, char **,
void *, const char *);
int ret;
int old_messages_using_locale = _messages_using_locale;
_messages_using_locale = 0;
- ret = __set_lc_messages_from_win (name, &_messages_locale,
+ ret = __set_lc_messages_from_win (name, &_C_messages_locale,
+ &_messages_locale,
&_messages_locale_buf,
f_wctomb, charset);
/* ret == -1: error, ret == 0: C/POSIX, ret > 0: valid */
diff --git a/newlib/libc/locale/lmessages.h b/newlib/libc/locale/lmessages.h
index b1e14b7c9..52cf6f67c 100644
--- a/newlib/libc/locale/lmessages.h
+++ b/newlib/libc/locale/lmessages.h
@@ -29,7 +29,9 @@
#ifndef _LMESSAGES_H_
#define _LMESSAGES_H_
+#include <_ansi.h>
#include <sys/cdefs.h>
+#include <wchar.h>
__BEGIN_DECLS
@@ -38,6 +40,13 @@ struct lc_messages_T {
const char *noexpr;
const char *yesstr;
const char *nostr;
+#ifdef __HAVE_LOCALE_INFO_EXTENDED__
+ const char *codeset; /* codeset for mbtowc conversion */
+ const wchar_t *wyesexpr;
+ const wchar_t *wnoexpr;
+ const wchar_t *wyesstr;
+ const wchar_t *wnostr;
+#endif
};
struct lc_messages_T *__get_current_messages_locale(void);
diff --git a/newlib/libc/locale/lmonetary.c b/newlib/libc/locale/lmonetary.c
index c96d74802..f1101a902 100644
--- a/newlib/libc/locale/lmonetary.c
+++ b/newlib/libc/locale/lmonetary.c
@@ -38,6 +38,9 @@ extern const char * __fix_locale_grouping_str(const char *);
static char empty[] = "";
static char numempty[] = { CHAR_MAX, '\0'};
+#ifdef __HAVE_LOCALE_INFO_EXTENDED__
+static wchar_t wempty[] = L"";
+#endif
static const struct lc_monetary_T _C_monetary_locale = {
empty, /* int_curr_symbol */
@@ -55,6 +58,21 @@ static const struct lc_monetary_T _C_monetary_locale = {
numempty, /* n_sep_by_space */
numempty, /* p_sign_posn */
numempty /* n_sign_posn */
+#ifdef __HAVE_LOCALE_INFO_EXTENDED__
+ , numempty, /* int_p_cs_precedes */
+ numempty, /* int_p_sep_by_space */
+ numempty, /* int_n_cs_precedes */
+ numempty, /* int_n_sep_by_space */
+ numempty, /* int_p_sign_posn */
+ numempty, /* int_n_sign_posn */
+ "ASCII", /* codeset */
+ wempty, /* wint_curr_symbol */
+ wempty, /* wcurrency_symbol */
+ wempty, /* wmon_decimal_point */
+ wempty, /* wmon_thousands_sep */
+ wempty, /* wpositive_sign */
+ wempty /* wnegative_sign */
+#endif
};
static struct lc_monetary_T _monetary_locale;
@@ -76,11 +94,13 @@ __monetary_load_locale(const char *name , void *f_wctomb, const char *charset)
#ifdef __CYGWIN__
extern int __set_lc_monetary_from_win (const char *,
+ const struct lc_monetary_T *,
struct lc_monetary_T *, char **,
void *, const char *);
int old_monetary_using_locale = _monetary_using_locale;
_monetary_using_locale = 0;
- ret = __set_lc_monetary_from_win (name, &_monetary_locale,
+ ret = __set_lc_monetary_from_win (name, &_C_monetary_locale,
+ &_monetary_locale,
&_monetary_locale_buf,
f_wctomb, charset);
/* ret == -1: error, ret == 0: C/POSIX, ret > 0: valid */
diff --git a/newlib/libc/locale/lmonetary.h b/newlib/libc/locale/lmonetary.h
index 14c9cc15d..7aa21e298 100644
--- a/newlib/libc/locale/lmonetary.h
+++ b/newlib/libc/locale/lmonetary.h
@@ -29,7 +29,9 @@
#ifndef _LMONETARY_H_
#define _LMONETARY_H_
+#include <_ansi.h>
#include <sys/cdefs.h>
+#include <wchar.h>
__BEGIN_DECLS
@@ -49,6 +51,21 @@ struct lc_monetary_T {
const char *n_sep_by_space;
const char *p_sign_posn;
const char *n_sign_posn;
+#ifdef __HAVE_LOCALE_INFO_EXTENDED__
+ const char *int_p_cs_precedes;
+ const char *int_p_sep_by_space;
+ const char *int_n_cs_precedes;
+ const char *int_n_sep_by_space;
+ const char *int_p_sign_posn;
+ const char *int_n_sign_posn;
+ const char *codeset; /* codeset for mbtowc conversion */
+ const wchar_t *wint_curr_symbol;
+ const wchar_t *wcurrency_symbol;
+ const wchar_t *wmon_decimal_point;
+ const wchar_t *wmon_thousands_sep;
+ const wchar_t *wpositive_sign;
+ const wchar_t *wnegative_sign;
+#endif
};
struct lc_monetary_T *__get_current_monetary_locale(void);
diff --git a/newlib/libc/locale/lnumeric.c b/newlib/libc/locale/lnumeric.c
index 81c0061ff..ae2447066 100644
--- a/newlib/libc/locale/lnumeric.c
+++ b/newlib/libc/locale/lnumeric.c
@@ -24,8 +24,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-
#include <limits.h>
#include "lnumeric.h"
#include "ldpart.h"
@@ -38,9 +36,14 @@ extern const char *__fix_locale_grouping_str(const char *);
static char numempty[] = { CHAR_MAX, '\0' };
static const struct lc_numeric_T _C_numeric_locale = {
- ".", /* decimal_point */
- "", /* thousands_sep */
- numempty /* grouping */
+ ".", /* decimal_point */
+ "", /* thousands_sep */
+ numempty /* grouping */
+#ifdef __HAVE_LOCALE_INFO_EXTENDED__
+ , "ASCII", /* codeset */
+ L".", /* wdecimal_point */
+ L"", /* wthousands_sep */
+#endif
};
static struct lc_numeric_T _numeric_locale;
@@ -54,12 +57,13 @@ __numeric_load_locale(const char *name , void *f_wctomb, const char *charset)
#ifdef __CYGWIN__
extern int __set_lc_numeric_from_win (const char *,
+ const struct lc_numeric_T *,
struct lc_numeric_T *, char **,
void *, const char *);
int old_numeric_using_locale = _numeric_using_locale;
_numeric_using_locale = 0;
- ret = __set_lc_numeric_from_win (name, &_numeric_locale,
- &_numeric_locale_buf,
+ ret = __set_lc_numeric_from_win (name, &_C_numeric_locale,
+ &_numeric_locale, &_numeric_locale_buf,
f_wctomb, charset);
/* ret == -1: error, ret == 0: C/POSIX, ret > 0: valid */
if (ret < 0)
diff --git a/newlib/libc/locale/lnumeric.h b/newlib/libc/locale/lnumeric.h
index bed75e868..2bd7d9745 100644
--- a/newlib/libc/locale/lnumeric.h
+++ b/newlib/libc/locale/lnumeric.h
@@ -29,7 +29,9 @@
#ifndef _LNUMERIC_H_
#define _LNUMERIC_H_
+#include <_ansi.h>
#include <sys/cdefs.h>
+#include <wchar.h>
__BEGIN_DECLS
@@ -37,6 +39,11 @@ struct lc_numeric_T {
const char *decimal_point;
const char *thousands_sep;
const char *grouping;
+#ifdef __HAVE_LOCALE_INFO_EXTENDED__
+ const char *codeset; /* codeset for mbtowc conversion */
+ const wchar_t *wdecimal_point;
+ const wchar_t *wthousands_sep;
+#endif
};
struct lc_numeric_T *__get_current_numeric_locale(void);
diff --git a/newlib/libc/locale/locale.c b/newlib/libc/locale/locale.c
index 14ee907ff..a204d3412 100644
--- a/newlib/libc/locale/locale.c
+++ b/newlib/libc/locale/locale.c
@@ -179,8 +179,10 @@ No supporting OS subroutines are required.
#include <reent.h>
#include <stdlib.h>
#include <wchar.h>
+#include "lmessages.h"
#include "lmonetary.h"
#include "lnumeric.h"
+#include "lctype.h"
#include "../stdlib/local.h"
#define _LC_LAST 7
@@ -457,6 +459,11 @@ loadlocale(struct _reent *p, int category)
int (*l_mbtowc) (struct _reent *, wchar_t *, const char *, size_t,
const char *, mbstate_t *);
int cjknarrow = 0;
+
+ /* Avoid doing everything twice if nothing has changed. */
+ if (!strcmp (new_categories[category], current_categories[category]))
+ return current_categories[category];
+
#ifdef __CYGWIN__
/* This additional code handles the case that the incoming locale string
is not valid. If so, it calls the function __set_locale_from_locale_alias,
@@ -830,8 +837,9 @@ restart:
default:
FAIL;
}
- if (category == LC_CTYPE)
+ switch (category)
{
+ case LC_CTYPE:
strcpy (lc_ctype_charset, charset);
__mb_cur_max = mbc_max;
__wctomb = l_wctomb;
@@ -847,27 +855,36 @@ restart:
&& ((strncmp (locale, "ja", 2) == 0
|| strncmp (locale, "ko", 2) == 0
|| strncmp (locale, "zh", 2) == 0));
- }
- else if (category == LC_MESSAGES)
- {
+#ifdef __HAVE_LOCALE_INFO__
+ ret = __ctype_load_locale (locale, (void *) l_wctomb, charset, mbc_max);
+#endif /* __HAVE_LOCALE_INFO__ */
+ break;
+ case LC_MESSAGES:
+ strcpy (lc_message_charset, charset);
#ifdef __HAVE_LOCALE_INFO__
ret = __messages_load_locale (locale, (void *) l_wctomb, charset);
if (!ret)
#endif /* __HAVE_LOCALE_INFO__ */
- strcpy (lc_message_charset, charset);
- }
+ break;
#ifdef __HAVE_LOCALE_INFO__
#ifdef __CYGWIN__
/* Right now only Cygwin supports a __collate_load_locale function at all. */
- else if (category == LC_COLLATE)
- ret = __collate_load_locale (locale, (void *) l_mbtowc, charset);
+ case LC_COLLATE:
+ ret = __collate_load_locale (locale, (void *) l_mbtowc, charset);
+ break;
#endif
- else if (category == LC_MONETARY)
- ret = __monetary_load_locale (locale, (void *) l_wctomb, charset);
- else if (category == LC_NUMERIC)
- ret = __numeric_load_locale (locale, (void *) l_wctomb, charset);
- else if (category == LC_TIME)
- ret = __time_load_locale (locale, (void *) l_wctomb, charset);
+ case LC_MONETARY:
+ ret = __monetary_load_locale (locale, (void *) l_wctomb, charset);
+ break;
+ case LC_NUMERIC:
+ ret = __numeric_load_locale (locale, (void *) l_wctomb, charset);
+ break;
+ case LC_TIME:
+ ret = __time_load_locale (locale, (void *) l_wctomb, charset);
+ break;
+ default:
+ break;
+ }
if (ret)
FAIL;
#endif /* __HAVE_LOCALE_INFO__ */
@@ -901,13 +918,32 @@ __get_locale_env(struct _reent *p, int category)
char *
_DEFUN_VOID(__locale_charset)
{
+#if 0//def __HAVE_LOCALE_INFO__
+ return __get_current_ctype_locale ()->codeset;
+#else
return lc_ctype_charset;
+#endif
+}
+
+int
+_DEFUN_VOID(__locale_mb_cur_max)
+{
+#if 0//def __HAVE_LOCALE_INFO__
+ return __get_current_ctype_locale ()->mb_cur_max[0];
+#else
+ return __mb_cur_max;
+#endif
}
+
char *
_DEFUN_VOID(__locale_msgcharset)
{
+#ifdef __HAVE_LOCALE_INFO__
+ return __get_current_messages_locale ()->codeset;
+#else
return lc_message_charset;
+#endif
}
int
@@ -947,12 +983,21 @@ _DEFUN(_localeconv_r, (data),
lconv.n_sep_by_space = m->n_sep_by_space[0];
lconv.p_sign_posn = m->p_sign_posn[0];
lconv.n_sign_posn = m->n_sign_posn[0];
+#ifdef __HAVE_LOCALE_INFO_EXTENDED__
+ lconv.int_p_cs_precedes = m->int_p_cs_precedes[0];
+ lconv.int_p_sep_by_space = m->int_p_sep_by_space[0];
+ lconv.int_n_cs_precedes = m->int_n_cs_precedes[0];
+ lconv.int_n_sep_by_space = m->int_n_sep_by_space[0];
+ lconv.int_n_sign_posn = m->int_n_sign_posn[0];
+ lconv.int_p_sign_posn = m->int_p_sign_posn[0];
+#else /* !__HAVE_LOCALE_INFO_EXTENDED__ */
+ lconv.int_p_cs_precedes = m->p_cs_precedes[0];
+ lconv.int_p_sep_by_space = m->p_sep_by_space[0];
lconv.int_n_cs_precedes = m->n_cs_precedes[0];
lconv.int_n_sep_by_space = m->n_sep_by_space[0];
lconv.int_n_sign_posn = m->n_sign_posn[0];
- lconv.int_p_cs_precedes = m->p_cs_precedes[0];
- lconv.int_p_sep_by_space = m->p_sep_by_space[0];
lconv.int_p_sign_posn = m->p_sign_posn[0];
+#endif /* !__HAVE_LOCALE_INFO_EXTENDED__ */
__mlocale_changed = 0;
}
#endif /* __HAVE_LOCALE_INFO__ */
diff --git a/newlib/libc/locale/nl_langinfo.c b/newlib/libc/locale/nl_langinfo.c
index d4f30e932..97d835bef 100644
--- a/newlib/libc/locale/nl_langinfo.c
+++ b/newlib/libc/locale/nl_langinfo.c
@@ -32,6 +32,7 @@
#include <stdlib.h>
#include <string.h>
+#include "lctype.h"
#include "timelocal.h"
#include "lnumeric.h"
#include "lmonetary.h"
@@ -41,6 +42,138 @@
#define TRANSITION_PERIOD_HACK
#endif
+#undef offsetoff
+#define _O(TYPE, MEMBER) __builtin_offsetof (TYPE, MEMBER)
+
+#define _NLITEM(cat,memb) { { cat:__get_current_##cat##_locale }, \
+ _O (struct lc_##cat##_T, memb) }
+
+#ifdef __HAVE_LOCALE_INFO_EXTENDED__
+static struct _nl_item_t
+{
+ union {
+ struct lc_ctype_T * (*ctype)(void);
+ struct lc_time_T * (*time)(void);
+ struct lc_numeric_T * (*numeric)(void);
+ struct lc_monetary_T * (*monetary)(void);
+ struct lc_messages_T * (*messages)(void);
+ void * (*base)(void);
+ };
+ _off_t offset;
+} nl_ext[] =
+{
+ /* First element has an nl_item value of _NL_LOCALE_EXTENDED_FIRST_ENTRY */
+ _NLITEM (ctype, outdigits[0]),
+ _NLITEM (ctype, outdigits[1]),
+ _NLITEM (ctype, outdigits[2]),
+ _NLITEM (ctype, outdigits[3]),
+ _NLITEM (ctype, outdigits[4]),
+ _NLITEM (ctype, outdigits[5]),
+ _NLITEM (ctype, outdigits[6]),
+ _NLITEM (ctype, outdigits[7]),
+ _NLITEM (ctype, outdigits[8]),
+ _NLITEM (ctype, outdigits[9]),
+ _NLITEM (ctype, woutdigits[0]),
+ _NLITEM (ctype, woutdigits[1]),
+ _NLITEM (ctype, woutdigits[2]),
+ _NLITEM (ctype, woutdigits[3]),
+ _NLITEM (ctype, woutdigits[4]),
+ _NLITEM (ctype, woutdigits[5]),
+ _NLITEM (ctype, woutdigits[6]),
+ _NLITEM (ctype, woutdigits[7]),
+ _NLITEM (ctype, woutdigits[8]),
+ _NLITEM (ctype, woutdigits[9]),
+ _NLITEM (time, codeset),
+ _NLITEM (time, wmon[1]),
+ _NLITEM (time, wmon[2]),
+ _NLITEM (time, wmon[3]),
+ _NLITEM (time, wmon[4]),
+ _NLITEM (time, wmon[5]),
+ _NLITEM (time, wmon[6]),
+ _NLITEM (time, wmon[7]),
+ _NLITEM (time, wmon[8]),
+ _NLITEM (time, wmon[9]),
+ _NLITEM (time, wmon[10]),
+ _NLITEM (time, wmon[11]),
+ _NLITEM (time, wmon[12]),
+ _NLITEM (time, wmonth[1]),
+ _NLITEM (time, wmonth[2]),
+ _NLITEM (time, wmonth[3]),
+ _NLITEM (time, wmonth[4]),
+ _NLITEM (time, wmonth[5]),
+ _NLITEM (time, wmonth[6]),
+ _NLITEM (time, wmonth[7]),
+ _NLITEM (time, wmonth[8]),
+ _NLITEM (time, wmonth[9]),
+ _NLITEM (time, wmonth[10]),
+ _NLITEM (time, wmonth[11]),
+ _NLITEM (time, wmonth[12]),
+ _NLITEM (time, wwday[1]),
+ _NLITEM (time, wwday[2]),
+ _NLITEM (time, wwday[3]),
+ _NLITEM (time, wwday[4]),
+ _NLITEM (time, wwday[5]),
+ _NLITEM (time, wwday[6]),
+ _NLITEM (time, wwday[7]),
+ _NLITEM (time, wweekday[1]),
+ _NLITEM (time, wweekday[2]),
+ _NLITEM (time, wweekday[3]),
+ _NLITEM (time, wweekday[4]),
+ _NLITEM (time, wweekday[5]),
+ _NLITEM (time, wweekday[6]),
+ _NLITEM (time, wweekday[7]),
+ _NLITEM (time, wX_fmt),
+ _NLITEM (time, wx_fmt),
+ _NLITEM (time, wc_fmt),
+ _NLITEM (time, wam_pm[0]),
+ _NLITEM (time, wam_pm[1]),
+ _NLITEM (time, wdate_fmt),
+ _NLITEM (time, wampm_fmt),
+ _NLITEM (time, wera),
+ _NLITEM (time, wera_d_fmt),
+ _NLITEM (time, wera_d_t_fmt),
+ _NLITEM (time, wera_t_fmt),
+ _NLITEM (time, walt_digits),
+ _NLITEM (numeric, codeset),
+ _NLITEM (numeric, grouping),
+ _NLITEM (numeric, wdecimal_point),
+ _NLITEM (numeric, wthousands_sep),
+ _NLITEM (monetary, int_curr_symbol),
+ _NLITEM (monetary, currency_symbol),
+ _NLITEM (monetary, mon_decimal_point),
+ _NLITEM (monetary, mon_thousands_sep),
+ _NLITEM (monetary, mon_grouping),
+ _NLITEM (monetary, positive_sign),
+ _NLITEM (monetary, negative_sign),
+ _NLITEM (monetary, int_frac_digits),
+ _NLITEM (monetary, frac_digits),
+ _NLITEM (monetary, p_cs_precedes),
+ _NLITEM (monetary, p_sep_by_space),
+ _NLITEM (monetary, n_cs_precedes),
+ _NLITEM (monetary, n_sep_by_space),
+ _NLITEM (monetary, p_sign_posn),
+ _NLITEM (monetary, n_sign_posn),
+ _NLITEM (monetary, int_p_cs_precedes),
+ _NLITEM (monetary, int_p_sep_by_space),
+ _NLITEM (monetary, int_n_cs_precedes),
+ _NLITEM (monetary, int_n_sep_by_space),
+ _NLITEM (monetary, int_p_sign_posn),
+ _NLITEM (monetary, int_n_sign_posn),
+ _NLITEM (monetary, codeset),
+ _NLITEM (monetary, wint_curr_symbol),
+ _NLITEM (monetary, wcurrency_symbol),
+ _NLITEM (monetary, wmon_decimal_point),
+ _NLITEM (monetary, wmon_thousands_sep),
+ _NLITEM (monetary, wpositive_sign),
+ _NLITEM (monetary, wnegative_sign),
+ _NLITEM (messages, codeset),
+ _NLITEM (messages, wyesexpr),
+ _NLITEM (messages, wnoexpr),
+ _NLITEM (messages, wyesstr),
+ _NLITEM (messages, wnostr),
+};
+#endif /* __HAVE_LOCALE_INFO_EXTENDED__ */
+
#define _REL(BASE) ((int)item-BASE)
extern char *__locale_charset ();
@@ -57,9 +190,36 @@ _DEFUN(nl_langinfo, (item),
char *nptr;
switch (item) {
+#ifdef __HAVE_LOCALE_INFO__
+ case _NL_MESSAGES_CODESET:
+ ret = (char *) __get_current_messages_locale ()->codeset;
+ goto do_codeset;
+#ifdef __HAVE_LOCALE_INFO_EXTENDED__
+ case _NL_TIME_CODESET:
+ ret = (char *) __get_current_time_locale ()->codeset;
+ goto do_codeset;
+ case _NL_NUMERIC_CODESET:
+ ret = (char *) __get_current_numeric_locale ()->codeset;
+ goto do_codeset;
+ case _NL_MONETARY_CODESET:
+ ret = (char *) __get_current_monetary_locale ()->codeset;
+ goto do_codeset;
+#ifdef __CYGWIN__
+ case _NL_COLLATE_CODESET:
+ {
+ extern const char *__get_current_collate_codeset (void);
+ ret = (char *) __get_current_collate_codeset ();
+ goto do_codeset;
+ }
+#endif /* __CYGWIN__ */
+#endif /* __HAVE_LOCALE_INFO_EXTENDED__ */
+#endif /* __HAVE_LOCALE_INFO__ */
case CODESET:
#ifdef __CYGWIN__
ret = __locale_charset ();
+#endif
+do_codeset:
+#ifdef __CYGWIN__
/* Convert charset to Linux compatible codeset string. */
if (ret[0] == 'A'/*SCII*/)
ret = "ANSI_X3.4-1968";
@@ -252,7 +412,18 @@ _DEFUN(nl_langinfo, (item),
case D_MD_ORDER: /* local extension */
ret = (char *) __get_current_time_locale()->md_order;
break;
+ case _NL_CTYPE_MB_CUR_MAX:
+ ret = (char *) __get_current_ctype_locale()->mb_cur_max;
+ break;
default:
+#ifdef __HAVE_LOCALE_INFO_EXTENDED__
+ if (item > _NL_LOCALE_EXTENDED_FIRST_ENTRY
+ && item < _NL_LOCALE_EXTENDED_LAST_ENTRY) {
+ int idx = item - _NL_LOCALE_EXTENDED_FIRST_ENTRY - 1;
+ return *(char **) ((char *) (*nl_ext[idx].base)()
+ + nl_ext[idx].offset);
+ }
+#endif
ret = "";
}
return (ret);
diff --git a/newlib/libc/locale/timelocal.c b/newlib/libc/locale/timelocal.c
index 4c0f50c76..ca2f79b50 100644
--- a/newlib/libc/locale/timelocal.c
+++ b/newlib/libc/locale/timelocal.c
@@ -119,6 +119,34 @@ static const struct lc_time_T _C_time_locale = {
* Alternate digits used if %O format prefix is specified
*/
""
+#ifdef __HAVE_LOCALE_INFO_EXTENDED__
+ , "ASCII", /* codeset */
+ {
+ L"Jan", L"Feb", L"Mar", L"Apr", L"May", L"Jun",
+ L"Jul", L"Aug", L"Sep", L"Oct", L"Nov", L"Dec"
+ }, {
+ L"January", L"February", L"March", L"April", L"May", L"June",
+ L"July", L"August", L"September", L"October", L"November",
+ L"December"
+ }, {
+ L"Sun", L"Mon", L"Tue", L"Wed",
+ L"Thu", L"Fri", L"Sat"
+ }, {
+ L"Sunday", L"Monday", L"Tuesday", L"Wednesday",
+ L"Thursday", L"Friday", L"Saturday"
+ },
+ L"%H:%M:%S",
+ L"%m/%d/%y",
+ L"%a %b %e %H:%M:%S %Y",
+ { L"AM", L"PM" },
+ L"%a %b %e %H:%M:%S %Z %Y",
+ L"%I:%M:%S %p",
+ L"",
+ L"",
+ L"",
+ L"",
+ L""
+#endif
};
struct lc_time_T *
@@ -134,12 +162,14 @@ __time_load_locale(const char *name, void *f_wctomb, const char *charset) {
int ret;
#ifdef __CYGWIN__
- extern int __set_lc_time_from_win (const char *, struct lc_time_T *,
+ extern int __set_lc_time_from_win (const char *,
+ const struct lc_time_T *,
+ struct lc_time_T *,
char **, void *, const char *);
int old_time_using_locale = _time_using_locale;
_time_using_locale = 0;
- ret = __set_lc_time_from_win (name, &_time_locale, &time_locale_buf,
- f_wctomb, charset);
+ ret = __set_lc_time_from_win (name, &_C_time_locale, &_time_locale,
+ &time_locale_buf, f_wctomb, charset);
/* ret == -1: error, ret == 0: C/POSIX, ret > 0: valid */
if (ret < 0)
_time_using_locale = old_time_using_locale;
diff --git a/newlib/libc/locale/timelocal.h b/newlib/libc/locale/timelocal.h
index 80f72b66e..a0c1ef7ef 100644
--- a/newlib/libc/locale/timelocal.h
+++ b/newlib/libc/locale/timelocal.h
@@ -29,7 +29,9 @@
#ifndef _TIMELOCAL_H_
#define _TIMELOCAL_H_
+#include <_ansi.h>
#include <sys/cdefs.h>
+#include <wchar.h>
__BEGIN_DECLS
@@ -47,7 +49,7 @@ struct lc_time_T {
const char *c_fmt;
const char *am_pm[2];
const char *date_fmt;
- const char *alt_month[12];
+ const char *alt_month[12]; /* unused */
const char *md_order;
const char *ampm_fmt;
const char *era;
@@ -55,6 +57,24 @@ struct lc_time_T {
const char *era_d_t_fmt;
const char *era_t_fmt;
const char *alt_digits;
+#ifdef __HAVE_LOCALE_INFO_EXTENDED__
+ const char *codeset; /* codeset for mbtowc conversion */
+ const wchar_t *wmon[12];
+ const wchar_t *wmonth[12];
+ const wchar_t *wwday[7];
+ const wchar_t *wweekday[7];
+ const wchar_t *wX_fmt;
+ const wchar_t *wx_fmt;
+ const wchar_t *wc_fmt;
+ const wchar_t *wam_pm[2];
+ const wchar_t *wdate_fmt;
+ const wchar_t *wampm_fmt;
+ const wchar_t *wera;
+ const wchar_t *wera_d_fmt;
+ const wchar_t *wera_d_t_fmt;
+ const wchar_t *wera_t_fmt;
+ const wchar_t *walt_digits;
+#endif
};
struct lc_time_T *__get_current_time_locale(void);