X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Fstrftime.c;h=897aab71e5dd4063b05d955ed5b270077f9add91;hb=cb9819cbb9261bd50c3466cf0a4cd873f0d7ebd7;hp=d740ae018d8f326651df78d0a6ea674f1d7e34e3;hpb=c0e63657aced0f505bab0d91a2d5db472d7d1013;p=gnulib.git diff --git a/lib/strftime.c b/lib/strftime.c index d740ae018..897aab71e 100644 --- a/lib/strftime.c +++ b/lib/strftime.c @@ -1,26 +1,21 @@ -/* Copyright (C) 1991-1999, 2000, 2001, 2003, 2004, 2005 Free Software +/* Copyright (C) 1991-1999, 2000, 2001, 2003, 2004, 2005, 2006, 2007 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. - This program is free software; you can redistribute it and/or modify + 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 2, or (at your option) - any later version. + 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, write to the Free Software Foundation, - Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ - -#ifdef HAVE_CONFIG_H -# include -#endif + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ #ifdef _LIBC # define HAVE_MBLEN 1 @@ -32,22 +27,17 @@ # define HAVE_TZSET 1 # define MULTIBYTE_IS_FORMAT_SAFE 1 # include "../locale/localeinfo.h" +#else +# include +# if FPRINTFTIME +# include "fprintftime.h" +# endif #endif #include -#include /* Some systems define `time_t' here. */ +#include -#ifdef TIME_WITH_SYS_TIME -# include -# include -#else -# ifdef HAVE_SYS_TIME_H -# include -# else -# include -# endif -#endif -#if HAVE_TZNAME +#if HAVE_TZNAME && !HAVE_DECL_TZNAME extern char *tzname[]; #endif @@ -57,7 +47,7 @@ extern char *tzname[]; conversion specifications. The GNU C Library uses UTF8 multibyte encoding, which is safe for formats, but strftime.c can be used with other C libraries that use unsafe encodings. */ -#define DO_MULTIBYTE (HAVE_MBLEN && HAVE_WCHAR_H && ! MULTIBYTE_IS_FORMAT_SAFE) +#define DO_MULTIBYTE (HAVE_MBLEN && ! MULTIBYTE_IS_FORMAT_SAFE) #if DO_MULTIBYTE # if HAVE_MBRLEN @@ -143,11 +133,10 @@ extern char *tzname[]; #endif #if !HAVE_TM_GMTOFF -/* Portable standalone applications should supply a "time_r.h" that +/* Portable standalone applications should supply a "time.h" that declares a POSIX-compliant localtime_r, for the benefit of older implementations that lack localtime_r or have a nonstandard one. See the gnulib time_r module for one way to implement this. */ -# include "time_r.h" # undef __gmtime_r # undef __localtime_r # define __gmtime_r gmtime_r @@ -180,6 +169,12 @@ extern char *tzname[]; # define memset_zero(P, Len) (memset (P, '0', Len), (P) += (Len)) #endif +#if FPRINTFTIME +# define advance(P, N) +#else +# define advance(P, N) ((P) += (N)) +#endif + #define add(n, f) \ do \ { \ @@ -198,7 +193,7 @@ extern char *tzname[]; memset_space (p, _delta); \ } \ f; \ - p += FPRINTFTIME ? 0 : _n; \ + advance (p, _n); \ } \ i += _incr; \ } while (0) @@ -278,17 +273,12 @@ extern char *tzname[]; # define TOLOWER(Ch, L) towlower (Ch) # endif #else -# ifdef _LIBC -# 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 +# 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) (islower (Ch) ? toupper (Ch) : (Ch)) -# define TOLOWER(Ch, L) (isupper (Ch) ? tolower (Ch) : (Ch)) +# define TOUPPER(Ch, L) toupper (Ch) +# define TOLOWER(Ch, L) tolower (Ch) # endif #endif /* We don't use `isdigit' here since the locale dependent @@ -387,21 +377,6 @@ iso_week_days (int yday, int wday) } -#if !(defined _NL_CURRENT || HAVE_STRFTIME) -static CHAR_T const weekday_name[][10] = - { - L_("Sunday"), L_("Monday"), L_("Tuesday"), L_("Wednesday"), - L_("Thursday"), L_("Friday"), L_("Saturday") - }; -static CHAR_T const month_name[][10] = - { - L_("January"), L_("February"), L_("March"), L_("April"), L_("May"), - L_("June"), L_("July"), L_("August"), L_("September"), L_("October"), - L_("November"), L_("December") - }; -#endif - - /* When compiling this file, GNU applications can #define my_strftime to a symbol (typically nstrftime) to get an extended strftime with extra arguments UT and NS. Emacs is a special case for now, but @@ -473,18 +448,6 @@ strftime_case_ (bool upcase, STREAM_OR_CHAR_T *s, # define aw_len STRLEN (a_wkday) # define am_len STRLEN (a_month) # define ap_len STRLEN (ampm) -#else -# if !HAVE_STRFTIME -# define f_wkday (weekday_name[tp->tm_wday]) -# define f_month (month_name[tp->tm_mon]) -# define a_wkday f_wkday -# define a_month f_month -# define ampm (L_("AMPM") + 2 * (tp->tm_hour > 11)) - - size_t aw_len = 3; - size_t am_len = 3; - size_t ap_len = 2; -# endif #endif const char *zone; size_t i = 0; @@ -745,7 +708,7 @@ strftime_case_ (bool upcase, STREAM_OR_CHAR_T *s, to_uppcase = true; to_lowcase = false; } -#if defined _NL_CURRENT || !HAVE_STRFTIME +#ifdef _NL_CURRENT cpy (aw_len, a_wkday); break; #else @@ -760,7 +723,7 @@ strftime_case_ (bool upcase, STREAM_OR_CHAR_T *s, to_uppcase = true; to_lowcase = false; } -#if defined _NL_CURRENT || !HAVE_STRFTIME +#ifdef _NL_CURRENT cpy (STRLEN (f_wkday), f_wkday); break; #else @@ -776,7 +739,7 @@ strftime_case_ (bool upcase, STREAM_OR_CHAR_T *s, } if (modifier != 0) goto bad_format; -#if defined _NL_CURRENT || !HAVE_STRFTIME +#ifdef _NL_CURRENT cpy (am_len, a_month); break; #else @@ -791,7 +754,7 @@ strftime_case_ (bool upcase, STREAM_OR_CHAR_T *s, to_uppcase = true; to_lowcase = false; } -#if defined _NL_CURRENT || !HAVE_STRFTIME +#ifdef _NL_CURRENT cpy (STRLEN (f_month), f_month); break; #else @@ -809,11 +772,7 @@ strftime_case_ (bool upcase, STREAM_OR_CHAR_T *s, != '\0'))) subfmt = (const CHAR_T *) _NL_CURRENT (LC_TIME, NLW(D_T_FMT)); #else -# if HAVE_STRFTIME goto underlying_strftime; -# else - subfmt = L_("%a %b %e %H:%M:%S %Y"); -# endif #endif subformat: @@ -829,7 +788,7 @@ strftime_case_ (bool upcase, STREAM_OR_CHAR_T *s, } break; -#if HAVE_STRFTIME && ! (defined _NL_CURRENT && HAVE_STRUCT_ERA_ENTRY) +#if !(defined _NL_CURRENT && HAVE_STRUCT_ERA_ENTRY) underlying_strftime: { /* The relevant information is available only via the @@ -880,9 +839,7 @@ strftime_case_ (bool upcase, STREAM_OR_CHAR_T *s, break; } #else -# if HAVE_STRFTIME goto underlying_strftime; -# endif #endif } @@ -903,11 +860,7 @@ strftime_case_ (bool upcase, STREAM_OR_CHAR_T *s, subfmt = (const CHAR_T *) _NL_CURRENT (LC_TIME, NLW(D_FMT)); goto subformat; #else -# if HAVE_STRFTIME goto underlying_strftime; -# else - /* Fall through. */ -# endif #endif case L_('D'): if (modifier != 0) @@ -972,9 +925,7 @@ strftime_case_ (bool upcase, STREAM_OR_CHAR_T *s, } } #else -# if HAVE_STRFTIME goto underlying_strftime; -# endif #endif } @@ -1122,7 +1073,7 @@ strftime_case_ (bool upcase, STREAM_OR_CHAR_T *s, case L_('P'): to_lowcase = true; -#if !defined _NL_CURRENT && HAVE_STRFTIME +#ifndef _NL_CURRENT format_char = L_('p'); #endif /* FALLTHROUGH */ @@ -1133,7 +1084,7 @@ strftime_case_ (bool upcase, STREAM_OR_CHAR_T *s, to_uppcase = false; to_lowcase = true; } -#if defined _NL_CURRENT || !HAVE_STRFTIME +#ifdef _NL_CURRENT cpy (ap_len, ampm); break; #else @@ -1145,16 +1096,14 @@ strftime_case_ (bool upcase, STREAM_OR_CHAR_T *s, goto subformat; case L_('r'): -#if !defined _NL_CURRENT && HAVE_STRFTIME - goto underlying_strftime; -#else -# ifdef _NL_CURRENT +#ifdef _NL_CURRENT if (*(subfmt = (const CHAR_T *) _NL_CURRENT (LC_TIME, NLW(T_FMT_AMPM))) == L_('\0')) -# endif subfmt = L_("%I:%M:%S %p"); goto subformat; +#else + goto underlying_strftime; #endif case L_('S'): @@ -1201,11 +1150,7 @@ strftime_case_ (bool upcase, STREAM_OR_CHAR_T *s, subfmt = (const CHAR_T *) _NL_CURRENT (LC_TIME, NLW(T_FMT)); goto subformat; #else -# if HAVE_STRFTIME goto underlying_strftime; -# else - /* Fall through. */ -# endif #endif case L_('T'): subfmt = L_("%H:%M:%S"); @@ -1309,9 +1254,7 @@ strftime_case_ (bool upcase, STREAM_OR_CHAR_T *s, goto subformat; } #else -# if HAVE_STRFTIME goto underlying_strftime; -# endif #endif } if (modifier == L_('O')) @@ -1332,9 +1275,7 @@ strftime_case_ (bool upcase, STREAM_OR_CHAR_T *s, + delta * era->absolute_direction)); } #else -# if HAVE_STRFTIME goto underlying_strftime; -# endif #endif }