# HG changeset patch # User Jim Meyering # Date 1050071784 0 # Node ID 2da9db9c7ef8136239282bc9a94a39f51310b775 # Parent f366a5d5b79ee79dbb95856ab09f4e842475aacd (my_strftime): Merge in locale-related changes from libc. These changes have no effect outside of _LIBC. diff --git a/lib/strftime.c b/lib/strftime.c --- a/lib/strftime.c +++ b/lib/strftime.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991-1999, 2000, 2001 Free Software Foundation, Inc. +/* Copyright (C) 1991-1999, 2000, 2001, 2003 Free Software Foundation, Inc. NOTE: The canonical source of this file is maintained with the GNU C Library. Bugs can be reported to bug-glibc@prep.ai.mit.edu. @@ -285,14 +285,25 @@ #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; \ @@ -301,19 +312,57 @@ ws = alloca ((l + 1) * sizeof (wchar_t)); \ (void) __mbsrtowcs (ws, &__s, l, &__st); \ } +# endif #endif +#if defined _LIBC && defined USE_IN_EXTENDED_LOCALE_MODEL +/* We use this code also for the extended locale handling where the + function gets as an additional argument the locale which has to be + used. To access the values we have to redefine the _NL_CURRENT + macro. */ +# define strftime __strftime_l +# define wcsftime __wcsftime_l +# undef _NL_CURRENT +# define _NL_CURRENT(category, item) \ + (current->values[_NL_ITEM_INDEX (item)].string) +# define LOCALE_PARAM , loc +# define LOCALE_ARG , loc +# 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 +# define HELPER_LOCALE_ARG , _NL_CURRENT_DATA (LC_TIME) +# else +# define HELPER_LOCALE_ARG +# endif +#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 @@ -323,30 +372,32 @@ #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; } @@ -477,13 +528,18 @@ anywhere, so to determine how many characters would be written, use NULL for S and (size_t) UINT_MAX for MAXSIZE. */ size_t -my_strftime (s, maxsize, format, tp extra_args) +my_strftime (s, maxsize, format, tp extra_args LOCALE_PARAM) CHAR_T *s; size_t maxsize; const CHAR_T *format; const struct tm *tp; extra_args_spec + LOCALE_PARAM_DECL { +#if defined _LIBC && defined USE_IN_EXTENDED_LOCALE_MODEL + struct locale_data *const current = loc->__locales[LC_TIME]; +#endif + int hour12 = tp->tm_hour; #ifdef _NL_CURRENT /* We cannot make the following values variables since we must delay @@ -546,9 +602,8 @@ } else { - /* POSIX.1 8.1.1 requires that whenever strftime() is called, the - time zone names contained in the external variable `tzname' shall - be set as if the tzset() function had been called. */ + /* POSIX.1 requires that local time zone information be used as + though strftime called tzset. */ # if HAVE_TZSET tzset (); # endif @@ -767,7 +822,7 @@ #endif case L_('b'): - case L_('h'): /* POSIX.2 extension. */ + case L_('h'): if (change_case) { to_uppcase = 1; @@ -819,14 +874,14 @@ { CHAR_T *old_start = p; size_t len = my_strftime (NULL, (size_t) -1, subfmt, - tp extra_args); + tp extra_args LOCALE_ARG); add (len, my_strftime (p, maxsize - i, subfmt, - tp extra_args)); + tp extra_args LOCALE_ARG)); if (to_uppcase) while (old_start < p) { - *old_start = TOUPPER ((UCHAR_T) *old_start); + *old_start = TOUPPER ((UCHAR_T) *old_start, loc); ++old_start; } } @@ -862,13 +917,13 @@ break; #endif - case L_('C'): /* POSIX.2 extension. */ + case L_('C'): if (modifier == L_('O')) goto bad_format; if (modifier == L_('E')) { #if HAVE_STRUCT_ERA_ENTRY - struct era_entry *era = _nl_get_era_entry (tp); + struct era_entry *era = _nl_get_era_entry (tp HELPER_LOCALE_ARG); if (era) { # ifdef COMPILE_WIDE @@ -909,7 +964,7 @@ /* Fall through. */ # endif #endif - case L_('D'): /* POSIX.2 extension. */ + case L_('D'): if (modifier != 0) goto bad_format; subfmt = L_("%m/%d/%y"); @@ -921,7 +976,7 @@ DO_NUMBER (2, tp->tm_mday); - case L_('e'): /* POSIX.2 extension. */ + case L_('e'): if (modifier == L_('E')) goto bad_format; @@ -944,9 +999,11 @@ /* Get the locale specific alternate representation of the number NUMBER_VALUE. If none exist NULL is returned. */ # ifdef COMPILE_WIDE - const wchar_t *cp = _nl_get_walt_digit (number_value); + const wchar_t *cp = _nl_get_walt_digit (number_value + HELPER_LOCALE_ARG); # else - const char *cp = _nl_get_alt_digit (number_value); + const char *cp = _nl_get_alt_digit (number_value + HELPER_LOCALE_ARG); # endif if (cp != NULL) @@ -1053,6 +1110,7 @@ DO_NUMBER (2, tp->tm_mon + 1); +#ifndef _LIBC case L_('N'): /* GNU extension. */ if (modifier == L_('E')) goto bad_format; @@ -1067,8 +1125,9 @@ } DO_NUMBER (9, number_value); +#endif - case L_('n'): /* POSIX.2 extension. */ + case L_('n'): add (1, *p = L_('\n')); break; @@ -1092,11 +1151,11 @@ goto underlying_strftime; #endif - case L_('R'): /* ISO C99 extension. */ + case L_('R'): subfmt = L_("%H:%M"); goto subformat; - case L_('r'): /* POSIX.2 extension. */ + case L_('r'): #ifdef _NL_CURRENT if (*(subfmt = (const CHAR_T *) _NL_CURRENT (LC_TIME, NLW(T_FMT_AMPM))) @@ -1167,15 +1226,15 @@ /* Fall through. */ # endif #endif - case L_('T'): /* POSIX.2 extension. */ + case L_('T'): subfmt = L_("%H:%M:%S"); goto subformat; - case L_('t'): /* POSIX.2 extension. */ + case L_('t'): add (1, *p = L_('\t')); break; - case L_('u'): /* POSIX.2 extension. */ + case L_('u'): DO_NUMBER (1, (tp->tm_wday - 1 + 7) % 7 + 1); case L_('U'): @@ -1185,8 +1244,8 @@ DO_NUMBER (2, (tp->tm_yday - tp->tm_wday + 7) / 7); case L_('V'): - case L_('g'): /* ISO C99 extension. */ - case L_('G'): /* ISO C99 extension. */ + case L_('g'): + case L_('G'): if (modifier == L_('E')) goto bad_format; { @@ -1241,7 +1300,7 @@ if (modifier == 'E') { #if HAVE_STRUCT_ERA_ENTRY - struct era_entry *era = _nl_get_era_entry (tp); + struct era_entry *era = _nl_get_era_entry (tp HELPER_LOCALE_ARG); if (era) { # ifdef COMPILE_WIDE @@ -1266,7 +1325,7 @@ if (modifier == L_('E')) { #if HAVE_STRUCT_ERA_ENTRY - struct era_entry *era = _nl_get_era_entry (tp); + struct era_entry *era = _nl_get_era_entry (tp HELPER_LOCALE_ARG); if (era) { int delta = tp->tm_year - era->start_date[0]; @@ -1294,7 +1353,7 @@ zone = tzname[tp->tm_isdst]; #endif if (! zone) - zone = ""; /* POSIX.2 requires the empty string here. */ + zone = ""; #ifdef COMPILE_WIDE { @@ -1310,7 +1369,7 @@ #endif break; - case L_('z'): /* ISO C99 extension. */ + case L_('z'): if (tp->tm_isdst < 0) break; @@ -1388,6 +1447,9 @@ *p = L_('\0'); return i; } +#ifdef _LIBC +libc_hidden_def (my_strftime) +#endif #ifdef emacs