Просмотр исходного кода

Better fix for tzselect in non-UTF-8 locales

* NEWS: Document this.
* tzselect.ksh (TZ_COUNTRY_TABLE, TZ_ZONE_TABLE):
If the current locale is not UTF-8, convert these tables
to the current locale's encoding before using them.
That's better than switching ths ehell to UTF-8, which
may not work if the current terminal doesn't support it.
Problem reported by Random832 in:
http://mm.icann.org/pipermail/tz/2015-May/022260.html
Paul Eggert 10 лет назад
Родитель
Сommit
8f9ffd332b
2 измененных файлов с 17 добавлено и 13 удалено
  1. 2 1
      NEWS
  2. 15 12
      tzselect.ksh

+ 2 - 1
NEWS

@@ -9,7 +9,8 @@ Unreleased, experimental changes
 
   Changes affecting code
 
-    tzselect aligns UTF-8 columns better, if a UTF-8 locale is available.
+    When displaying data, tzselect converts it to the current locale's
+    encoding if the iconv command works.  (Problem reported by random832.)
 
 
 Release 2015d - 2015-04-24 08:09:46 -0700

+ 15 - 12
tzselect.ksh

@@ -50,18 +50,6 @@ say() {
 	exit 1
 }
 
-# Use a UTF-8 locale if available, as the data contain UTF-8,
-# and the shell aligns columns better that way.
-# Check the UTF-8 of U+12345 CUNEIFORM SIGN URU TIMES KI.
-utf8_locale='BEGIN { u12345 = "\360\222\215\205"; exit length(u12345) != 1 }'
-$AWK "$utf8_locale" ||
-    for locale in en_US.utf8 en_US.UTF-8 C.utf8; do
-	(LC_ALL=$locale $AWK "$utf8_locale") 2>/dev/null && {
-	    export LC_ALL=$locale
-	    break
-	}
-    done
-
 coord=
 location_limit=10
 zonetabtype=zone1970
@@ -195,6 +183,21 @@ do
 	}
 done
 
+# If the current locale does not support UTF-8, convert data to current
+# locale's format if possible, as the shell aligns columns better that way.
+# Check the UTF-8 of U+12345 CUNEIFORM SIGN URU TIMES KI.
+! $AWK 'BEGIN { u12345 = "\360\222\215\205"; exit length(u12345) != 1 }' &&
+    { tmp=`(mktemp -d) 2>/dev/null` || {
+	tmp=${TMPDIR-/tmp}/tzselect.$$ &&
+	(umask 77 && mkdir -- "$tmp")
+    };} &&
+    trap 'status=$?; rm -fr -- "$tmp"; exit $status' 0 1 12 13 15 &&
+    (iconv -f UTF-8 -t //TRANSLIT <"$TZ_COUNTRY_TABLE" >$tmp/iso3166.tab) \
+        2>/dev/null &&
+    TZ_COUNTRY_TABLE=$tmp/iso3166.tab &&
+    iconv -f UTF-8 -t //TRANSLIT <"$TZ_ZONE_TABLE" >$tmp/$zonetabtype.tab &&
+    TZ_ZONE_TABLE=$tmp/$zonetabtype.tab
+
 newline='
 '
 IFS=$newline