+2002-08-28 Ulrich Drepper <drepper@redhat.com>
+
+ * include/wchar.h: Declare __mbsrtowcs_l.
+ * wcsmbs/Makefile (routines): Add mbsrtowcs_l.
+ * wcsmbs/mbsrtowcs.c: Add support for compilation with
+ USE_IN_EXTENDED_LOCALE_MODEL.
+ * wcsmbs/mbsrtowcs_l: New file.
+ * wcsmbs/wcsmbsload.c (__wcsmbs_to_wc): Renamed from to_wc. Don't
+ define as static. Change all uses.
+ (__wcsmbs_getfct): Renamed from getfct. Don't define as static.
+ Change all callers.
+ * wcsmbs/wcsmbsload.h: Declare __wcsmbs_to_wc and __wcsmbs_getfct.
+ * time/strftime.c: When translating for the extended locale model
+ use the _l functions.
+ * time/Makefile (tests): Add tst-ftime_l.
+ * time/tst-ftime_l.c: New file.
+
2002-08-28 Roland McGrath <roland@redhat.com>
* locale/findlocale.c [NL_CURRENT_INDIRECT] (_nl_C): New variable.
__gnuc_va_list __arg)
/* __attribute__ ((__format__ (__wprintf__, 3, 0))) */;
+
+/* Internal functions. */
+extern size_t __mbsrtowcs_l (wchar_t *dst, const char **src, size_t len,
+ mbstate_t *ps, __locale_t l) attribute_hidden;
# endif
#endif
distribute := datemsk
tests := test_time clocktest tst-posixtz tst-strptime tst_wcsftime \
- tst-getdate tst-mktime
+ tst-getdate tst-mktime tst-ftime_l
include ../Rules
#define cpy(n, s) \
add ((n), \
if (to_lowcase) \
- memcpy_lowcase (p, (s), _n); \
+ memcpy_lowcase (p, (s), _n LOCALE_ARG); \
else if (to_uppcase) \
- memcpy_uppcase (p, (s), _n); \
+ memcpy_uppcase (p, (s), _n LOCALE_ARG); \
else \
MEMCPY ((PTR) p, (const PTR) (s), _n))
#ifdef COMPILE_WIDE
-# define widen(os, ws, l) \
+# ifdef USE_IN_EXTENDED_LOCALE_MODEL
+# define widen(os, ws, l) \
+ { \
+ mbstate_t __st; \
+ const char *__s = os; \
+ memset (&__st, '\0', sizeof (__st)); \
+ l = __mbsrtowcs_l (NULL, &__s, 0, &__st, loc); \
+ ws = alloca ((l + 1) * sizeof (wchar_t)); \
+ (void) __mbsrtowcs_l (ws, &__s, l, &__st, loc); \
+ }
+# else
+# define widen(os, ws, l) \
{ \
mbstate_t __st; \
const char *__s = os; \
ws = alloca ((l + 1) * sizeof (wchar_t)); \
(void) __mbsrtowcs (ws, &__s, l, &__st); \
}
+# endif
#endif
(current->values[_NL_ITEM_INDEX (item)].string)
# define LOCALE_PARAM , loc
# define LOCALE_ARG , loc
-# define LOCALE_PARAM_DECL __locale_t loc;
-# define HELPER_LOCALE_ARG , current
+# define LOCALE_PARAM_DECL __locale_t loc;
+# define LOCALE_PARAM_PROTO , __locale_t loc
+# define HELPER_LOCALE_ARG , current
#else
# define LOCALE_PARAM
+# define LOCALE_PARAM_PROTO
# define LOCALE_ARG
# define LOCALE_PARAM_DECL
# ifdef _LIBC
#endif
#ifdef COMPILE_WIDE
-# define TOUPPER(Ch) towupper (Ch)
-# define TOLOWER(Ch) towlower (Ch)
+# ifdef USE_IN_EXTENDED_LOCALE_MODEL
+# define TOUPPER(Ch, L) __towupper_l (Ch, L)
+# define TOLOWER(Ch, L) __towlower_l (Ch, L)
+# else
+# define TOUPPER(Ch, L) towupper (Ch)
+# define TOLOWER(Ch, L) towlower (Ch)
+# endif
#else
# ifdef _LIBC
-# define TOUPPER(Ch) toupper (Ch)
-# define TOLOWER(Ch) tolower (Ch)
+# ifdef USE_IN_EXTENDED_LOCALE_MODEL
+# define TOUPPER(Ch, L) __toupper_l (Ch, L)
+# define TOLOWER(Ch, L) __tolower_l (Ch, L)
+# else
+# define TOUPPER(Ch, L) toupper (Ch)
+# define TOLOWER(Ch, L) tolower (Ch)
+# endif
# else
-# define TOUPPER(Ch) (islower (Ch) ? toupper (Ch) : (Ch))
-# define TOLOWER(Ch) (isupper (Ch) ? tolower (Ch) : (Ch))
+# define TOUPPER(Ch, L) (islower (Ch) ? toupper (Ch) : (Ch))
+# define TOLOWER(Ch, L) (isupper (Ch) ? tolower (Ch) : (Ch))
# endif
#endif
/* We don't use `isdigit' here since the locale dependent
#define ISDIGIT(Ch) ((unsigned int) (Ch) - L_('0') <= 9)
static CHAR_T *memcpy_lowcase __P ((CHAR_T *dest, const CHAR_T *src,
- size_t len));
+ size_t len LOCALE_PARAM_PROTO));
static CHAR_T *
-memcpy_lowcase (dest, src, len)
+memcpy_lowcase (dest, src, len LOCALE_PARAM)
CHAR_T *dest;
const CHAR_T *src;
size_t len;
+ LOCALE_PARAM_DECL
{
while (len-- > 0)
- dest[len] = TOLOWER ((UCHAR_T) src[len]);
+ dest[len] = TOLOWER ((UCHAR_T) src[len], loc);
return dest;
}
static CHAR_T *memcpy_uppcase __P ((CHAR_T *dest, const CHAR_T *src,
- size_t len));
+ size_t len LOCALE_PARAM_PROTO));
static CHAR_T *
-memcpy_uppcase (dest, src, len)
+memcpy_uppcase (dest, src, len LOCALE_PARAM)
CHAR_T *dest;
const CHAR_T *src;
size_t len;
+ LOCALE_PARAM_DECL
{
while (len-- > 0)
- dest[len] = TOUPPER ((UCHAR_T) src[len]);
+ dest[len] = TOUPPER ((UCHAR_T) src[len], loc);
return dest;
}
if (to_uppcase)
while (old_start < p)
{
- *old_start = TOUPPER ((UCHAR_T) *old_start);
+ *old_start = TOUPPER ((UCHAR_T) *old_start, loc);
++old_start;
}
}
-# Copyright (C) 1995,1996,1997,1998,1999,2000 Free Software Foundation, Inc.
+# Copyright (C) 1995-2000, 2002 Free Software Foundation, Inc.
# This file is part of the GNU C Library.
# The GNU C Library is free software; you can redistribute it and/or
wcwidth wcswidth \
wcscoll_l wcsxfrm_l \
wcscasecmp wcsncase wcscasecmp_l wcsncase_l \
- wcsmbsload
+ wcsmbsload mbsrtowcs_l
tests := tst-wcstof wcsmbs-tst1 tst-wcsnlen tst-btowc tst-mbrtowc \
tst-wcrtomb
-/* Copyright (C) 1996, 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
+/* Copyright (C) 1996,1997,1998,1999,2000,2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@gnu.org>, 1996.
#endif
+#ifdef USE_IN_EXTENDED_LOCALE_MODEL
+size_t
+attribute_hidden
+__mbsrtowcs_l (dst, src, len, ps, l)
+ wchar_t *dst;
+ const char **src;
+ size_t len;
+ mbstate_t *ps;
+ __locale_t l;
+#else
/* This is the private state used if PS is NULL. */
static mbstate_t state;
const char **src;
size_t len;
mbstate_t *ps;
+#endif
{
struct __gconv_step_data data;
size_t result;
data.__invocation_counter = 0;
data.__internal_use = 1;
data.__flags = __GCONV_IS_LAST;
+#ifdef USE_IN_EXTENDED_LOCALE_MODEL
+ data.__statep = ps;
+#else
data.__statep = ps ?: &state;
+#endif
data.__trans = NULL;
+#ifdef USE_IN_EXTENDED_LOCALE_MODEL
+ /* Get the conversion function matching the locale. */
+ towc = wcsmbs_get_towc_func (l);
+#else
/* Make sure we use the correct function. */
update_conversion_ptrs ();
/* Get the structure with the function pointers. */
towc = __wcsmbs_gconv_fcts.towc;
+#endif
/* We have to handle DST == NULL special. */
if (dst == NULL)
__set_errno (EILSEQ);
}
+#ifdef USE_IN_EXTENDED_LOCALE_MODEL
+ /* Free the conversion function data structures. */
+ wcsmbs_free_funcs (towc);
+#endif
+
return result;
}
+#ifndef USE_IN_EXTENDED_LOCALE_MODEL
weak_alias (__mbsrtowcs, mbsrtowcs)
+#endif
--- /dev/null
+/* Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@gnu.org>, 2002.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library 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
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <ctype.h>
+#include <string.h>
+#include "wcsmbsload.h"
+
+
+static inline struct __gconv_step *
+wcsmbs_get_towc_func (__locale_t l)
+{
+ const char *charset;
+ int use_translit;
+ char *norm;
+ size_t nsteps;
+
+ charset = l->__locales[LC_CTYPE]->values[_NL_ITEM_INDEX(CODESET)].string;
+
+ /* Transliteration requested? */
+ use_translit = l->__locales[LC_CTYPE]->use_translit;
+
+ /* Normalize the name. */
+ norm = norm_add_slashes (charset, use_translit ? "TRANSLIT" : NULL);
+
+ return __wcsmbs_getfct ("INTERNAL", charset, &nsteps) ?: &__wcsmbs_to_wc;
+}
+
+
+static inline void
+wcsmbs_free_funcs (struct __gconv_step *step)
+{
+ if (step != &__wcsmbs_to_wc)
+ /* There is only one step. */
+ __gconv_close_transform (step, 1);
+}
+
+
+#define USE_IN_EXTENDED_LOCALE_MODEL 1
+#include "mbsrtowcs.c"
-/* Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
+/* Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1998.
#include <locale/localeinfo.h>
#include <wcsmbsload.h>
#include <bits/libc-lock.h>
-#include <iconv/gconv_int.h>
/* Last loaded locale for LC_CTYPE. We initialize for the C locale
/* These are the descriptions for the default conversion functions. */
-static struct __gconv_step to_wc =
+struct __gconv_step __wcsmbs_to_wc attribute_hidden =
{
.__shlib_handle = NULL,
.__modname = NULL,
/* For the default locale we only have to handle ANSI_X3.4-1968. */
struct gconv_fcts __wcsmbs_gconv_fcts =
{
- .towc = &to_wc,
+ .towc = &__wcsmbs_to_wc,
.towc_nsteps = 1,
.tomb = &to_mb,
.tomb_nsteps = 1
};
-static inline struct __gconv_step *
-getfct (const char *to, const char *from, size_t *nstepsp)
+struct __gconv_step *
+attribute_hidden
+__wcsmbs_getfct (const char *to, const char *from, size_t *nstepsp)
{
size_t nsteps;
struct __gconv_step *result;
if (new_category->name == _nl_C_name) /* Yes, pointer comparison. */
{
failed:
- __wcsmbs_gconv_fcts.towc = &to_wc;
+ __wcsmbs_gconv_fcts.towc = &__wcsmbs_to_wc;
__wcsmbs_gconv_fcts.tomb = &to_mb;
}
else
if (__wcsmbs_gconv_fcts.tomb != &to_mb)
__gconv_close_transform (__wcsmbs_gconv_fcts.tomb,
__wcsmbs_gconv_fcts.tomb_nsteps);
- if (__wcsmbs_gconv_fcts.towc != &to_wc)
+ if (__wcsmbs_gconv_fcts.towc != &__wcsmbs_to_wc)
__gconv_close_transform (__wcsmbs_gconv_fcts.towc,
__wcsmbs_gconv_fcts.towc_nsteps);
/* It is not necessary to use transliteration in this direction
since the internal character set is supposed to be able to
represent all others. */
- new_towc = getfct ("INTERNAL", complete_name, &new_towc_nsteps);
+ new_towc = __wcsmbs_getfct ("INTERNAL", complete_name,
+ &new_towc_nsteps);
new_tomb = (new_towc != NULL
- ? getfct (complete_name, "INTERNAL", &new_tomb_nsteps)
+ ? __wcsmbs_getfct (complete_name, "INTERNAL",
+ &new_tomb_nsteps)
: NULL);
/* If any of the conversion functions is not available we don't
internal_function
__wcsmbs_named_conv (struct gconv_fcts *copy, const char *name)
{
- copy->towc = getfct ("INTERNAL", name, ©->towc_nsteps);
+ copy->towc = __wcsmbs_getfct ("INTERNAL", name, ©->towc_nsteps);
if (copy->towc != NULL)
{
- copy->tomb = getfct (name, "INTERNAL", ©->tomb_nsteps);
+ copy->tomb = __wcsmbs_getfct (name, "INTERNAL", ©->tomb_nsteps);
if (copy->tomb == NULL)
__gconv_close_transform (copy->towc, copy->towc_nsteps);
}
__gconv_release_cache (old, nold);
}
- if (__wcsmbs_gconv_fcts.towc != &to_wc)
+ if (__wcsmbs_gconv_fcts.towc != &__wcsmbs_to_wc)
{
struct __gconv_step *old = __wcsmbs_gconv_fcts.towc;
size_t nold = __wcsmbs_gconv_fcts.towc_nsteps;
- __wcsmbs_gconv_fcts.towc = &to_wc;
+ __wcsmbs_gconv_fcts.towc = &__wcsmbs_to_wc;
__wcsmbs_gconv_fcts.towc_nsteps = 1;
__gconv_release_cache (old, nold);
}
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
+#ifndef _WCSMBSLOAD_H
+#define _WCSMBSLOAD_H 1
+
#include <locale.h>
#include <wchar.h>
#include <locale/localeinfo.h>
internal_function;
+#include <iconv/gconv_int.h>
+
+
+/* Variable for conversion from ASCII to wchar_t. */
+extern struct __gconv_step __wcsmbs_to_wc attribute_hidden;
+
+
+/* Load the function implementation if necessary. */
+extern struct __gconv_step *__wcsmbs_getfct (const char *to, const char *from,
+ size_t *nstepsp)
+ attribute_hidden;
+
+
/* Check whether the LC_CTYPE locale changed since the last call.
Update the pointers appropriately. */
static inline void
if (__wcsmbs_last_locale != _NL_CURRENT_DATA (LC_CTYPE))
__wcsmbs_load_conv (_NL_CURRENT_DATA (LC_CTYPE));
}
+
+#endif /* wcsmbsload.h */