Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/lib/libc/time Merge strftime from tzcode2000g.



details:   https://anonhg.NetBSD.org/src/rev/0e07e817aefc
branches:  trunk
changeset: 500459:0e07e817aefc
user:      kleink <kleink%NetBSD.org@localhost>
date:      Tue Dec 12 15:35:31 2000 +0000

description:
Merge strftime from tzcode2000g.

diffstat:

 lib/libc/time/private.h  |    8 +-
 lib/libc/time/strftime.c |  602 +++++++++++++++++++++++++++-------------------
 2 files changed, 356 insertions(+), 254 deletions(-)

diffs (truncated from 744 to 300 lines):

diff -r 6ac0fd86a835 -r 0e07e817aefc lib/libc/time/private.h
--- a/lib/libc/time/private.h   Tue Dec 12 15:25:41 2000 +0000
+++ b/lib/libc/time/private.h   Tue Dec 12 15:35:31 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: private.h,v 1.17 2000/12/12 15:25:41 kleink Exp $      */
+/*     $NetBSD: private.h,v 1.18 2000/12/12 15:35:31 kleink Exp $      */
 
 #ifndef PRIVATE_H
 #define PRIVATE_H
@@ -75,9 +75,9 @@
 #define HAVE_UTMPX_H           0
 #endif /* !defined HAVE_UTMPX_H */
 
-#ifndef LOCALE_HOME
-#define LOCALE_HOME            "/usr/lib/locale"
-#endif /* !defined LOCALE_HOME */
+#ifdef LOCALE_HOME
+#undefine LOCALE_HOME          /* not to be handled by tzcode itself */
+#endif /* defined LOCALE_HOME */
 
 #if HAVE_INCOMPATIBLE_CTIME_R
 #define asctime_r _incompatible_asctime_r
diff -r 6ac0fd86a835 -r 0e07e817aefc lib/libc/time/strftime.c
--- a/lib/libc/time/strftime.c  Tue Dec 12 15:25:41 2000 +0000
+++ b/lib/libc/time/strftime.c  Tue Dec 12 15:35:31 2000 +0000
@@ -1,236 +1,299 @@
-/*     $NetBSD: strftime.c,v 1.11 2000/09/07 12:45:03 taca Exp $       */
-
-/*
- * Copyright (c) 1989 The Regents of the University of California.
- * All rights reserved.
- *
- * 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.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *     This product includes software developed by the University of
- *     California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
- */
+/*     $NetBSD: strftime.c,v 1.12 2000/12/12 15:35:31 kleink Exp $     */
 
 #include <sys/cdefs.h>
 #if defined(LIBC_SCCS) && !defined(lint)
 #if 0
-static char *sccsid = "@(#)strftime.c  5.11 (Berkeley) 2/24/91";
+static char    elsieid[] = "@(#)strftime.c     7.62";
 #else
-__RCSID("$NetBSD: strftime.c,v 1.11 2000/09/07 12:45:03 taca Exp $");
+__RCSID("$NetBSD: strftime.c,v 1.12 2000/12/12 15:35:31 kleink Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
 #include "namespace.h"
+
+/*
+** Based on the UCB version with the ID appearing below.
+** This is ANSIish only when "multibyte character == plain character".
+*/
+
 #include "private.h"
-#include <sys/localedef.h>
-#include <locale.h>
-#include <string.h>
-#include <tzfile.h>
-#include <time.h>
+
+/*
+** Copyright (c) 1989 The Regents of the University of California.
+** All rights reserved.
+**
+** Redistribution and use in source and binary forms are permitted
+** provided that the above copyright notice and this paragraph are
+** duplicated in all such forms and that any documentation,
+** advertising materials, and other materials related to such
+** distribution and use acknowledge that the software was developed
+** by the University of California, Berkeley.  The name of the
+** University may not be used to endorse or promote products derived
+** from this software without specific prior written permission.
+** THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
+** IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+*/
 
-static int _add __P((const char *, char **, const char *));
-static int _conv __P((int, int, int, char **, const char *));
-static int _secs __P((const struct tm *, char **, const char *));
-static size_t _fmt __P((const char *, const struct tm *, char **,
-           const char *));
+#ifndef LIBC_SCCS
+#ifndef lint
+static const char      sccsid[] = "@(#)strftime.c      5.4 (Berkeley) 3/14/89";
+#endif /* !defined lint */
+#endif /* !defined LIBC_SCCS */
+
+#include "tzfile.h"
+#include "fcntl.h"
+#include "locale.h"
+
+#include "sys/localedef.h"
+#define Locale _CurrentTimeLocale
+
+static char *  _add P((const char *, char *, const char *));
+static char *  _conv P((int, const char *, char *, const char *));
+static char *  _fmt P((const char *, const struct tm *, char *, const char *, int *));
+
+#define NO_RUN_TIME_WARNINGS_ABOUT_YEAR_2000_PROBLEMS_THANK_YOU
+
+#ifndef YEAR_2000_NAME
+#define YEAR_2000_NAME "CHECK_STRFTIME_FORMATS_FOR_TWO_DIGIT_YEARS"
+#endif /* !defined YEAR_2000_NAME */
+
+
+#define IN_NONE        0
+#define IN_SOME        1
+#define IN_THIS        2
+#define IN_ALL 3
 
 size_t
 strftime(s, maxsize, format, t)
-       char *s;
-       size_t maxsize;
-       const char *format;
-       const struct tm *t;
+char * const           s;
+const size_t           maxsize;
+const char * const     format;
+const struct tm * const        t;
 {
-       char *pt;
+       char *  p;
+       int     warn;
 
        tzset();
-       if (maxsize < 1)
-               return (0);
-
-       pt = s;
-       if (_fmt(format, t, &pt, s + maxsize)) {
-               *pt = '\0';
-               return (pt - s);
-       } else
-               return (0);
+       warn = IN_NONE;
+       p = _fmt(((format == NULL) ? "%c" : format), t, s, s + maxsize, &warn);
+#ifndef NO_RUN_TIME_WARNINGS_ABOUT_YEAR_2000_PROBLEMS_THANK_YOU
+       if (warn != IN_NONE && getenv(YEAR_2000_NAME) != NULL) {
+               (void) fprintf(stderr, "\n");
+               if (format == NULL)
+                       (void) fprintf(stderr, "NULL strftime format ");
+               else    (void) fprintf(stderr, "strftime format \"%s\" ",
+                               format);
+               (void) fprintf(stderr, "yields only two digits of years in ");
+               if (warn == IN_SOME)
+                       (void) fprintf(stderr, "some locales");
+               else if (warn == IN_THIS)
+                       (void) fprintf(stderr, "the current locale");
+               else    (void) fprintf(stderr, "all locales");
+               (void) fprintf(stderr, "\n");
+       }
+#endif /* !defined NO_RUN_TIME_WARNINGS_ABOUT_YEAR_2000_PROBLEMS_THANK_YOU */
+       if (p == s + maxsize)
+               return 0;
+       *p = '\0';
+       return p - s;
 }
 
-#define SUN_WEEK(t)    (((t)->tm_yday + 7 - \
-                               ((t)->tm_wday)) / 7)
-#define MON_WEEK(t)    (((t)->tm_yday + 7 - \
-                               ((t)->tm_wday ? (t)->tm_wday - 1 : 6)) / 7)
-
-static size_t
-_fmt(format, t, pt, ptlim)
-       const char *format;
-       const struct tm *t;
-       char **pt;
-       const char * const ptlim;
+static char *
+_fmt(format, t, pt, ptlim, warnp)
+const char *           format;
+const struct tm * const        t;
+char *                 pt;
+const char * const     ptlim;
+int *                  warnp;
 {
-       for (; *format; ++format) {
+       for ( ; *format; ++format) {
                if (*format == '%') {
-                       ++format;
-                       if (*format == 'E') {
-                               /* Alternate Era */
-                               ++format;
-                       } else if (*format == 'O') {
-                               /* Alternate numeric symbols */
-                               ++format;
-                       }
-                       switch (*format) {
+label:
+                       switch (*++format) {
                        case '\0':
                                --format;
                                break;
                        case 'A':
-                               if (t->tm_wday < 0 || t->tm_wday > 6)
-                                       return (0);
-                               if (!_add(_CurrentTimeLocale->day[t->tm_wday],
-                                   pt, ptlim))
-                                       return (0);
+                               pt = _add((t->tm_wday < 0 ||
+                                       t->tm_wday >= DAYSPERWEEK) ?
+                                       "?" : Locale->day[t->tm_wday],
+                                       pt, ptlim);
                                continue;
-
                        case 'a':
-                               if (t->tm_wday < 0 || t->tm_wday > 6)
-                                       return (0);
-                               if (!_add(_CurrentTimeLocale->abday[t->tm_wday],
-                                   pt, ptlim))
-                                       return (0);
+                               pt = _add((t->tm_wday < 0 ||
+                                       t->tm_wday >= DAYSPERWEEK) ?
+                                       "?" : Locale->abday[t->tm_wday],
+                                       pt, ptlim);
                                continue;
                        case 'B':
-                               if (t->tm_mon < 0 || t->tm_mon > 11)
-                                       return (0);
-                               if (!_add(_CurrentTimeLocale->mon[t->tm_mon],
-                                   pt, ptlim))
-                                       return (0);
+                               pt = _add((t->tm_mon < 0 ||
+                                       t->tm_mon >= MONSPERYEAR) ?
+                                       "?" : Locale->mon[t->tm_mon],
+                                       pt, ptlim);
                                continue;
                        case 'b':
                        case 'h':
-                               if (t->tm_mon < 0 || t->tm_mon > 11)
-                                       return (0);
-                               if (!_add(_CurrentTimeLocale->abmon[t->tm_mon],
-                                   pt, ptlim))
-                                       return (0);
+                               pt = _add((t->tm_mon < 0 ||
+                                       t->tm_mon >= MONSPERYEAR) ?
+                                       "?" : Locale->abmon[t->tm_mon],
+                                       pt, ptlim);
                                continue;
                        case 'C':
-                               if (!_conv((t->tm_year + TM_YEAR_BASE) / 100,
-                                   2, '0', pt, ptlim))
-                                       return (0);
+                               /*
+                               ** %C used to do a...
+                               **      _fmt("%a %b %e %X %Y", t);
+                               ** ...whereas now POSIX 1003.2 calls for
+                               ** something completely different.
+                               ** (ado, 1993-05-24)
+                               */
+                               pt = _conv((t->tm_year + TM_YEAR_BASE) / 100,
+                                       "%02d", pt, ptlim);
                                continue;
                        case 'c':
-                               if (!_fmt(_CurrentTimeLocale->d_t_fmt, t, pt,
-                                   ptlim))
-                                       return (0);
+                               {
+                               int warn2 = IN_SOME;
+
+                               pt = _fmt(Locale->d_t_fmt, t, pt, ptlim, warnp);
+                               if (warn2 == IN_ALL)
+                                       warn2 = IN_THIS;
+                               if (warn2 > *warnp)
+                                       *warnp = warn2;
+                               }
                                continue;
                        case 'D':
-                               if (!_fmt("%m/%d/%y", t, pt, ptlim))
-                                       return (0);



Home | Main Index | Thread Index | Old Index