changeset 1058:8c9ee29f3de0

update from FSF
author Jim Meyering <jim@meyering.net>
date Wed, 22 Oct 1997 14:06:16 +0000
parents ef00faa3c68a
children 7f4b4f1a238c
files lib/strftime.c
diffstat 1 files changed, 72 insertions(+), 31 deletions(-) [+]
line wrap: on
line diff
--- a/lib/strftime.c
+++ b/lib/strftime.c
@@ -1,22 +1,22 @@
 /* Copyright (C) 1991, 92, 93, 94, 95, 96, 97 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.
+   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 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.
+   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.
 
-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.
+   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., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
-USA.  */
+   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., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+   USA.  */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
@@ -33,10 +33,13 @@
 # define HAVE_TZSET 1
 # define MULTIBYTE_IS_FORMAT_SAFE 1
 # define STDC_HEADERS 1
-# include <ansidecl.h>
 # include "../locale/localeinfo.h"
 #endif
 
+#if defined emacs && !defined HAVE_BCOPY
+# define HAVE_MEMCPY 1
+#endif
+
 #include <ctype.h>
 #include <sys/types.h>		/* Some systems define `time_t' here.  */
 
@@ -83,7 +86,9 @@
 # include <stdlib.h>
 # include <string.h>
 #else
-# define memcpy(d, s, n) bcopy ((s), (d), (n))
+# ifndef HAVE_MEMCPY
+#  define memcpy(d, s, n) bcopy ((s), (d), (n))
+# endif
 #endif
 
 #ifndef __P
@@ -133,13 +138,13 @@
 #ifdef _LIBC
 # define gmtime_r __gmtime_r
 # define localtime_r __localtime_r
-extern int __tz_compute __P ((time_t timer, const struct tm *tm));
 # define tzname __tzname
 # define tzset __tzset
 #else
 # if ! HAVE_LOCALTIME_R
 #  if ! HAVE_TM_GMTOFF
 /* Approximate gmtime_r as best we can in its absence.  */
+#   undef gmtime_r
 #   define gmtime_r my_gmtime_r
 static struct tm *gmtime_r __P ((const time_t *, struct tm *));
 static struct tm *
@@ -156,7 +161,8 @@
 #  endif /* ! HAVE_TM_GMTOFF */
 
 /* Approximate localtime_r as best we can in its absence.  */
-#  define localtime_r my_localtime_r
+#  undef localtime_r
+#  define localtime_r my_ftime_localtime_r
 static struct tm *localtime_r __P ((const time_t *, struct tm *));
 static struct tm *
 localtime_r (t, tp)
@@ -173,11 +179,15 @@
 #endif /* ! defined (_LIBC) */
 
 
-#if !defined (memset) && !defined (HAVE_MEMSET) && !defined (_LIBC)
+#if !defined memset && !defined HAVE_MEMSET && !defined _LIBC
 /* Some systems lack the `memset' function and we don't want to
    introduce additional dependencies.  */
-static const char spaces[16] = "                ";
-static const char zeroes[16] = "0000000000000000";
+/* The SGI compiler reportedly barfs on the trailing null
+   if we use a string constant as the initializer.  28 June 1997, rms.  */
+static const char spaces[16] = /* "                " */
+  { ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ' };
+static const char zeroes[16] = /* "0000000000000000" */
+  { '0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0' };
 
 # define memset_space(P, Len) \
   do {									      \
@@ -284,9 +294,11 @@
   return dest;
 }
 
+
 #if ! HAVE_TM_GMTOFF
 /* Yield the difference between *A and *B,
    measured in seconds, ignoring leap seconds.  */
+# define tm_diff ftime_tm_diff
 static int tm_diff __P ((const struct tm *, const struct tm *));
 static int
 tm_diff (a, b)
@@ -323,7 +335,7 @@
 #define YDAY_MINIMUM (-366)
 static int iso_week_days __P ((int, int));
 #ifdef __GNUC__
-inline
+__inline__
 #endif
 static int
 iso_week_days (yday, wday)
@@ -419,15 +431,13 @@
   const char *f;
 
   zone = NULL;
-#if !defined _LIBC && HAVE_TM_ZONE
-  /* XXX We have some problems here.  First, the string pointed to by
-     tm_zone is dynamically allocated while loading the zone data.  But
-     when another zone is loaded since the information in TP were
-     computed this would be a stale pointer.
-     The second problem is the POSIX test suite which assumes setting
+#if HAVE_TM_ZONE
+  /* The POSIX test suite assumes that setting
      the environment variable TZ to a new value before calling strftime()
      will influence the result (the %Z format) even if the information in
-     TP is computed with a totally different time zone.  --drepper@gnu  */
+     TP is computed with a totally different time zone.
+     This is bogus: though POSIX allows bad behavior like this,
+     POSIX does not require it.  Do the right thing instead.  */
   zone = (const char *) tp->tm_zone;
 #endif
 #if HAVE_TZNAME
@@ -466,6 +476,7 @@
       int width = -1;
       int to_lowcase = 0;
       int to_uppcase = 0;
+      int change_case = 0;
 
 #if DO_MULTIBYTE
 
@@ -557,6 +568,9 @@
 	    case '^':
 	      to_uppcase = 1;
 	      continue;
+	    case '#':
+	      change_case = 1;
+	      continue;
 
 	    default:
 	      break;
@@ -594,9 +608,11 @@
       switch (*f)
 	{
 #define DO_NUMBER(d, v) \
-	  digits = d; number_value = v; goto do_number
+	  digits = width == -1 ? d : width;				      \
+	  number_value = v; goto do_number
 #define DO_NUMBER_SPACEPAD(d, v) \
-	  digits = d; number_value = v; goto do_number_spacepad
+	  digits = width == -1 ? d : width;				      \
+	  number_value = v; goto do_number_spacepad
 
 	case '%':
 	  if (modifier != 0)
@@ -607,12 +623,22 @@
 	case 'a':
 	  if (modifier != 0)
 	    goto bad_format;
+	  if (change_case)
+	    {
+	      to_uppcase = 1;
+	      to_lowcase = 0;
+	    }
 	  cpy (aw_len, a_wkday);
 	  break;
 
 	case 'A':
 	  if (modifier != 0)
 	    goto bad_format;
+	  if (change_case)
+	    {
+	      to_uppcase = 1;
+	      to_lowcase = 0;
+	    }
 	  cpy (wkday_len, f_wkday);
 	  break;
 
@@ -626,6 +652,11 @@
 	case 'B':
 	  if (modifier != 0)
 	    goto bad_format;
+	  if (change_case)
+	    {
+	      to_uppcase = 1;
+	      to_lowcase = 0;
+	    }
 	  cpy (month_len, f_month);
 	  break;
 
@@ -826,6 +857,11 @@
 	  /* FALLTHROUGH */
 
 	case 'p':
+	  if (change_case)
+	    {
+	      to_uppcase = 0;
+	      to_lowcase = 1;
+	    }
 	  cpy (ap_len, ampm);
 	  break;
 
@@ -998,6 +1034,11 @@
 	  DO_NUMBER (2, (tp->tm_year % 100 + 100) % 100);
 
 	case 'Z':
+	  if (change_case)
+	    {
+	      to_uppcase = 0;
+	      to_lowcase = 1;
+	    }
 	  cpy (zonelen, zone);
 	  break;