summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin B Kenny <kennykb@acm.org>2003-05-18 19:48:25 (GMT)
committerKevin B Kenny <kennykb@acm.org>2003-05-18 19:48:25 (GMT)
commita7ae75e85360445c96accf3acfc542dbe4e60519 (patch)
tree51b5e23a67cd4e57f7e7c0df5dd394a956f99f28
parentb8ab7934b3d5103f68277fb3671b30d22876303c (diff)
downloadtcl-a7ae75e85360445c96accf3acfc542dbe4e60519.zip
tcl-a7ae75e85360445c96accf3acfc542dbe4e60519.tar.gz
tcl-a7ae75e85360445c96accf3acfc542dbe4e60519.tar.bz2
* compat/strftime.c: Modified TclpStrftime to return its
* generic/tclClock.c: result in UTF-8 encoding, and removed * mac/tclMacTime.c: the conversion from system encoding to * unix/tclUnixTime.c: UTF-8 from [clock format]. Needed to * win/tclWinTime.c: avoid double conversion of the timezone name on Windows systems. [Bug 624408]
-rw-r--r--ChangeLog13
-rw-r--r--compat/strftime.c59
-rw-r--r--generic/tclClock.c21
-rw-r--r--mac/tclMacTime.c3
-rw-r--r--unix/tclUnixTime.c33
-rw-r--r--win/tclWinTime.c3
6 files changed, 87 insertions, 45 deletions
diff --git a/ChangeLog b/ChangeLog
index d22910d..3ce27f9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2003-05-18 Kevin Kenny <kennykb@acm.org>
+
+ * compat/strftime.c: Modified TclpStrftime to return its
+ * generic/tclClock.c: result in UTF-8 encoding, and removed
+ * mac/tclMacTime.c: the conversion from system encoding to
+ * unix/tclUnixTime.c: UTF-8 from [clock format]. Needed to
+ * win/tclWinTime.c: avoid double conversion of the timezone
+ name on Windows systems. [Bug 624408]
+
2003-05-16 Pat Thoyts <patthoyts@users.sourceforge.net>
* library/dde/pkgIndex.tcl: Applied TIP #130 which provides
@@ -8,7 +17,7 @@
* tests/winDde.test: Applied patch for [Bug 738929] by KKB and
changed to new-style tests.
-2003-05-16 Kevin B. Kenny <kennykb@hippolyta>
+2003-05-16 Kevin B. Kenny <kennykb@acm.org>
* unix/Makefile.in: Removed one excess source file tclDToA.c
@@ -16,7 +25,7 @@
* macosx/Tcl.pbproj/project.pbxproj: updated copyright year.
-2003-05-15 Kevin B. Kenny <kennykb@hippolyta>
+2003-05-15 Kevin B. Kenny <kennykb@acm.org>
* generic/tclGetDate.y: added further hackery to the yacc
* generic/tclDate.c: post-processing to arrange for the
diff --git a/compat/strftime.c b/compat/strftime.c
index 027e373..d7c63d1 100644
--- a/compat/strftime.c
+++ b/compat/strftime.c
@@ -10,7 +10,7 @@
*
* Changes 2002 Copyright (c) 2002 ActiveState Corporation.
*
- * RCS: @(#) $Id: strftime.c,v 1.10 2002/05/29 00:19:39 hobbs Exp $
+ * RCS: @(#) $Id: strftime.c,v 1.11 2003/05/18 19:48:26 kennykb Exp $
*/
/*
@@ -47,7 +47,7 @@
*/
#if defined(LIBC_SCCS)
-static char *rcsid = "$Id: strftime.c,v 1.10 2002/05/29 00:19:39 hobbs Exp $";
+static char *rcsid = "$Id: strftime.c,v 1.11 2003/05/18 19:48:26 kennykb Exp $";
#endif /* LIBC_SCCS */
#include <time.h>
@@ -59,16 +59,22 @@ static char *rcsid = "$Id: strftime.c,v 1.10 2002/05/29 00:19:39 hobbs Exp $";
#define TM_YEAR_BASE 1900
#define IsLeapYear(x) ((x % 4 == 0) && (x % 100 != 0 || x % 400 == 0))
+/*
+ * Structure type holding the locale-dependent strings for formatting
+ * times. The strings are all expected to be encoded in UTF-8.
+ */
+
typedef struct {
- const char *abday[7];
- const char *day[7];
- const char *abmon[12];
- const char *mon[12];
- const char *am_pm[2];
- const char *d_t_fmt;
- const char *d_fmt;
- const char *t_fmt;
- const char *t_fmt_ampm;
+ const char *abday[7]; /* Abbreviated weekday names */
+ const char *day[7]; /* Full weekday names */
+ const char *abmon[12]; /* Abbreviated month names */
+ const char *mon[12]; /* Full month name */
+ const char *am_pm[2]; /* The strings to use for meridian time
+ * (am, pm) */
+ const char *d_t_fmt; /* The locale-dependent date-time format */
+ const char *d_fmt; /* The locale-dependent date format */
+ const char *t_fmt; /* The locale-dependent 24hr time format */
+ const char *t_fmt_ampm; /* The locale-dependent 12hr time format */
} _TimeLocale;
/*
@@ -114,13 +120,34 @@ static int _secs _ANSI_ARGS_((const struct tm *t));
static size_t _fmt _ANSI_ARGS_((const char *format,
const struct tm *t));
+/*
+ *----------------------------------------------------------------------
+ *
+ * TclpStrftime --
+ *
+ * Formats a time (in 'struct tm' representation) for use by
+ * [clock format].
+ *
+ * Results:
+ * Returns the length of the formatted string.
+ *
+ * Side effects:
+ * Stores the formatted string in the 's' parameter. The
+ * formatted string is returned in UTF-8 encoding, *not* the
+ * system encoding.
+ *
+ *----------------------------------------------------------------------
+ */
+
size_t
TclpStrftime(s, maxsize, format, t, useGMT)
- char *s;
- size_t maxsize;
- const char *format;
- const struct tm *t;
- int useGMT;
+ char *s; /* Buffer to hold the formatted string */
+ size_t maxsize; /* Size of the passed buffer */
+ const char *format; /* Format to use (see the user documentation
+ * for [clock] for details) */
+ const struct tm *t; /* Time to format */
+ int useGMT; /* Flag == 1 if time is to be returned
+ * in UTC */
{
if (format[0] == '%' && format[1] == 'Q') {
/* Format as a stardate */
diff --git a/generic/tclClock.c b/generic/tclClock.c
index 221f961..db6167e 100644
--- a/generic/tclClock.c
+++ b/generic/tclClock.c
@@ -11,7 +11,7 @@
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclClock.c,v 1.22 2003/04/15 03:43:26 dgp Exp $
+ * RCS: @(#) $Id: tclClock.c,v 1.23 2003/05/18 19:48:26 kennykb Exp $
*/
#include "tcl.h"
@@ -264,7 +264,7 @@ FormatClock(interp, clockVal, useGMT, format)
char *format; /* Format string */
{
struct tm *timeDataPtr;
- Tcl_DString buffer, uniBuffer;
+ Tcl_DString buffer;
int bufSize;
char *p;
int result;
@@ -336,8 +336,7 @@ FormatClock(interp, clockVal, useGMT, format)
bufSize++;
}
}
- Tcl_DStringInit(&uniBuffer);
- Tcl_UtfToExternalDString(NULL, format, -1, &uniBuffer);
+
Tcl_DStringInit(&buffer);
Tcl_DStringSetLength(&buffer, bufSize);
@@ -346,12 +345,11 @@ FormatClock(interp, clockVal, useGMT, format)
#if defined(HAVE_TM_ZONE) || defined(WIN32)
Tcl_MutexLock(&clockMutex);
#endif
- result = TclpStrftime(buffer.string, (unsigned int) bufSize,
- Tcl_DStringValue(&uniBuffer), timeDataPtr, useGMT);
+ result = TclpStrftime( buffer.string, (unsigned int) bufSize,
+ format, timeDataPtr, useGMT);
#if defined(HAVE_TM_ZONE) || defined(WIN32)
Tcl_MutexUnlock(&clockMutex);
#endif
- Tcl_DStringFree(&uniBuffer);
#if !defined(HAVE_TM_ZONE) && !defined(WIN32)
if (useGMT) {
@@ -379,15 +377,8 @@ FormatClock(interp, clockVal, useGMT, format)
return TCL_ERROR;
}
- /*
- * Convert the time to UTF from external encoding [Bug: 3345]
- */
- Tcl_DStringInit(&uniBuffer);
- Tcl_ExternalToUtfDString(NULL, buffer.string, -1, &uniBuffer);
-
- Tcl_SetStringObj(Tcl_GetObjResult(interp), uniBuffer.string, -1);
+ Tcl_SetStringObj(Tcl_GetObjResult(interp), buffer.string, -1);
- Tcl_DStringFree(&uniBuffer);
Tcl_DStringFree(&buffer);
return TCL_OK;
}
diff --git a/mac/tclMacTime.c b/mac/tclMacTime.c
index fa5b215..d585ee7 100644
--- a/mac/tclMacTime.c
+++ b/mac/tclMacTime.c
@@ -9,7 +9,7 @@
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclMacTime.c,v 1.7 2002/01/04 11:21:05 das Exp $
+ * RCS: @(#) $Id: tclMacTime.c,v 1.8 2003/05/18 19:48:26 kennykb Exp $
*/
#include "tclInt.h"
@@ -375,6 +375,7 @@ TclpGetDate(
*
* Results:
* Returns a pointer to a static string, or NULL on failure.
+ * The static string is in UTF-8 encoding.
*
* Side effects:
* None.
diff --git a/unix/tclUnixTime.c b/unix/tclUnixTime.c
index fc72f35..77af9b1 100644
--- a/unix/tclUnixTime.c
+++ b/unix/tclUnixTime.c
@@ -9,7 +9,7 @@
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclUnixTime.c,v 1.15 2002/07/19 12:31:10 dkf Exp $
+ * RCS: @(#) $Id: tclUnixTime.c,v 1.16 2003/05/18 19:48:27 kennykb Exp $
*/
#include "tclInt.h"
@@ -308,22 +308,26 @@ TclpGetDate(time, useGMT)
* and also ignore the useGMT parameter.
*
* Results:
- * The normal strftime result.
+ * Returns the number of Unicode code points in the result string.
+ *
*
* Side effects:
- * None.
+ * Stores the converted time in the buffer designated by the
+ * 's' parameter.
*
*----------------------------------------------------------------------
*/
size_t
TclpStrftime(s, maxsize, format, t, useGMT)
- char *s;
- size_t maxsize;
- CONST char *format;
- CONST struct tm *t;
- int useGMT;
+ char *s; /* Buffer to receive the formatted string */
+ size_t maxsize; /* Allocated length of the buffer */
+ CONST char *format; /* Format to use for the conversion */
+ CONST struct tm *t; /* Time to convert */
+ int useGMT; /* Flag == 1 if converting in UTC */
{
+ Tcl_DString utf8Buffer;
+ size_t status;
if (format[0] == '%' && format[1] == 'Q') {
/* Format as a stardate */
sprintf(s, "Stardate %2d%03d.%01d",
@@ -332,9 +336,18 @@ TclpStrftime(s, maxsize, format, t, useGMT)
(365 + IsLeapYear((t->tm_year + TM_YEAR_BASE)))),
(((t->tm_hour * 60) + t->tm_min)/144));
return(strlen(s));
+ } else {
+ setlocale(LC_TIME, "");
+ status = strftime(s, maxsize, format, t);
+ if ( status > 0 ) {
+ Tcl_DStringInit ( &utf8Buffer );
+ Tcl_ExternalToUtfDString( NULL, s, status, &utf8Buffer );
+ strcpy( s, Tcl_DStringValue( &utf8Buffer ) );
+ Tcl_DStringFree( &utf8buffer );
+ }
+ return status;
}
- setlocale(LC_TIME, "");
- return strftime(s, maxsize, format, t);
+
}
/*
diff --git a/win/tclWinTime.c b/win/tclWinTime.c
index 826fae5..9953085 100644
--- a/win/tclWinTime.c
+++ b/win/tclWinTime.c
@@ -9,7 +9,7 @@
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclWinTime.c,v 1.17 2003/04/15 20:59:10 kennykb Exp $
+ * RCS: @(#) $Id: tclWinTime.c,v 1.18 2003/05/18 19:48:27 kennykb Exp $
*/
#include "tclWinInt.h"
@@ -449,6 +449,7 @@ StopCalibration( ClientData unused )
*
* Results:
* Returns a pointer to a static string, or NULL on failure.
+ * Return value is in UTF-8 encoding
*
* Side effects:
* None.