delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin-developers/1999/10/01/23:50:19

Mailing-List: contact cygwin-developers-help AT sourceware DOT cygnus DOT com; run by ezmlm
List-Unsubscribe: <mailto:cygwin-developers-unsubscribe-archive-cygwin-developers=delorie DOT com AT sourceware DOT cygnus DOT com>
List-Subscribe: <mailto:cygwin-developers-subscribe AT sourceware DOT cygnus DOT com>
List-Archive: <http://sourceware.cygnus.com/ml/cygwin-developers/>
List-Post: <mailto:cygwin-developers AT sourceware DOT cygnus DOT com>
List-Help: <mailto:cygwin-developers-help AT sourceware DOT cygnus DOT com>, <http://sourceware.cygnus.com/ml/#faqs>
Sender: cygwin-developers-owner AT sourceware DOT cygnus DOT com
Delivered-To: mailing list cygwin-developers AT sourceware DOT cygnus DOT com
To: cygwin-developers AT sourceware DOT cygnus DOT com
Subject: automatic TZ-string generation still faulty in Asian Windows
Mime-Version: 1.0 (generated by tm-edit 7.106)
From: Kazuhiro Fujieda <fujieda AT jaist DOT ac DOT jp>
Date: 02 Oct 1999 12:49:53 +0900
Message-ID: <s1s3dvubevy.fsf@jaist.ac.jp>
Lines: 81
X-Mailer: Gnus v5.3/Emacs 19.34

In Japanese Windows, probably in Chinese and Korean ones, the
automatic TZ-string generation always fails about any timezones,
because GetTimeZoneInformation() can't return valid timezone and
daylight names.

In Japanese Windows, tz.StandardName and tz.DaylightName don't
contain the timezone and daylight name but Japanese descriptions
of them. So it is necessary to accommodate tzsetwall() to such
case as the following patch.

In my patch, WILDABBR is modified into "   " and used as the
fall back name in Asian Windows.

Then, my patch doesn't convert tz.StandardName and
tz.DaylightName to multi-byte characters. Multi-byte characters
in Japanese, Chinese, and Korean encoding methods can't be
classified into upper-case ASCII characters or not by each byte. 
Such kind of operation should be operated on wide characters.

--- localtime.c-	Thu Sep 30 03:56:37 1999
+++ localtime.c	Sat Oct 02 01:50:20 1999
@@ -523,7 +523,7 @@ struct tzhead {
 #define WILDABBR	"   "
 #endif /* !defined WILDABBR */
 
-static char		wildabbr[] = "WILDABBR";
+static char		wildabbr[] = WILDABBR;
 
 static const char	gmt[] = "GMT";
 
@@ -1436,24 +1436,40 @@ tzsetwall P((void))
 	{
 	    TIME_ZONE_INFORMATION tz;
 	    char buf[BUFSIZ];
-	    char* cp = buf;
-	    char* src;
+	    char *cp, *dst;
+	    wchar_t *src;
 	    div_t d;
 	    GetTimeZoneInformation(&tz);
-	    wcstombs(cp, tz.StandardName, sizeof(tz.StandardName));
-	    for (src = cp; *src; ++src) {
-		if (is_upper(*src)) *cp++ = *src;
-	    }
+	    dst = cp = buf;
+	    for (src = tz.StandardName; *src; src++)
+	      if (is_upper(*src)) *dst++ = *src;
+	    if (cp == dst)
+	      {
+		/* In Asian Windows, tz.StandardName may not contain
+		   the timezone name. */
+		strcpy(cp, wildabbr);
+		cp += strlen(wildabbr);
+	      }
+	    else
+	      cp = dst;
 	    d = div(tz.Bias+tz.StandardBias, 60);
 	    sprintf(cp, "%d", d.quot);
 	    if (d.rem)
 		sprintf(cp=strchr(cp, 0), ":%d", abs(d.rem));
 	    if(tz.StandardDate.wMonth) {
 		cp = strchr(cp, 0);
-		wcstombs(cp, tz.DaylightName, sizeof(tz.DaylightName));
-		for (src = cp; *src; ++src) {
-		    if (is_upper(*src)) *cp++ = *src;
-		}
+		dst = cp;
+		for (src = tz.DaylightName; *src; src++)
+		  if (is_upper(*src)) *dst++ = *src;
+		if (cp == dst)
+		  {
+		    /* In Asian Windows, tz.StandardName may not contain
+		       the daylight name. */
+		    strcpy(buf, wildabbr);
+		    cp += strlen(wildabbr);
+		  }
+		else
+		  cp = dst;
 		d = div(tz.Bias+tz.DaylightBias, 60);
 		sprintf(cp, "%d", d.quot);
 		if (d.rem)

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019