summaryrefslogtreecommitdiff
path: root/elsie.nci.nih.gov/src/tzselect.ksh
diff options
context:
space:
mode:
authorStuart Bishop <stuart@stuartbishop.net>2015-09-21 17:40:37 +0700
committerStuart Bishop <stuart@stuartbishop.net>2015-09-21 17:40:37 +0700
commit5ea50a7ba6592c1a0f156075231b1593e060200f (patch)
tree9baf601bd067b270a47adc055b16c35ab528f89f /elsie.nci.nih.gov/src/tzselect.ksh
parent575921a11b85d215d27072f96bb70410929969ad (diff)
downloadpytz-5ea50a7ba6592c1a0f156075231b1593e060200f.tar.gz
Import IANA 2015f
Diffstat (limited to 'elsie.nci.nih.gov/src/tzselect.ksh')
-rw-r--r--elsie.nci.nih.gov/src/tzselect.ksh62
1 files changed, 42 insertions, 20 deletions
diff --git a/elsie.nci.nih.gov/src/tzselect.ksh b/elsie.nci.nih.gov/src/tzselect.ksh
index 3acdebd..2c3b2f4 100644
--- a/elsie.nci.nih.gov/src/tzselect.ksh
+++ b/elsie.nci.nih.gov/src/tzselect.ksh
@@ -37,10 +37,16 @@ REPORT_BUGS_TO=tz@iana.org
: ${AWK=awk}
: ${TZDIR=`pwd`}
+# Output one argument as-is to standard output.
+# Safer than 'echo', which can mishandle '\' or leading '-'.
+say() {
+ printf '%s\n' "$1"
+}
+
# Check for awk Posix compliance.
($AWK -v x=y 'BEGIN { exit 123 }') </dev/null >/dev/null 2>&1
[ $? = 123 ] || {
- echo >&2 "$0: Sorry, your '$AWK' program is not Posix compatible."
+ say >&2 "$0: Sorry, your '$AWK' program is not Posix compatible."
exit 1
}
@@ -154,16 +160,16 @@ do
-version)
exec echo "tzselect $PKGVERSION$TZVERSION" ;;
-*)
- echo >&2 "$0: -$opt$OPTARG: unknown option; try '$0 --help'"; exit 1 ;;
+ say >&2 "$0: -$opt$OPTARG: unknown option; try '$0 --help'"; exit 1 ;;
*)
- echo >&2 "$0: try '$0 --help'"; exit 1 ;;
+ say >&2 "$0: try '$0 --help'"; exit 1 ;;
esac
done
shift `expr $OPTIND - 1`
case $# in
0) ;;
-*) echo >&2 "$0: $1: unknown argument"; exit 1 ;;
+*) say >&2 "$0: $1: unknown argument"; exit 1 ;;
esac
# Make sure the tables are readable.
@@ -172,11 +178,26 @@ TZ_ZONE_TABLE=$TZDIR/$zonetabtype.tab
for f in $TZ_COUNTRY_TABLE $TZ_ZONE_TABLE
do
<"$f" || {
- echo >&2 "$0: time zone files are not set up correctly"
+ say >&2 "$0: time zone files are not set up correctly"
exit 1
}
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 HUP INT PIPE TERM &&
+ (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
@@ -336,8 +357,7 @@ while
exit 0
}'
do
- echo >&2 "'$TZ' is not a conforming" \
- 'Posix time zone string.'
+ say >&2 "'$TZ' is not a conforming Posix time zone string."
done
TZ_for_date=$TZ;;
*)
@@ -359,7 +379,7 @@ while
sort -n |
sed "${location_limit}q"
`
- regions=`echo "$distance_table" | $AWK '
+ regions=`say "$distance_table" | $AWK '
BEGIN { FS = "\t" }
{ print $NF }
'`
@@ -369,7 +389,7 @@ while
"of distance from $coord".
doselect $regions
region=$select_result
- TZ=`echo "$distance_table" | $AWK -v region="$region" '
+ TZ=`say "$distance_table" | $AWK -v region="$region" '
BEGIN { FS="\t" }
$NF == region { print $4 }
'`
@@ -429,6 +449,7 @@ while
}
}
}
+ /^#/ { next }
$1 ~ cc { print $4 }
' <"$TZ_ZONE_TABLE"`
@@ -460,6 +481,7 @@ while
}
}
}
+ /^#/ { next }
$1 ~ cc && $4 == region { print $3 }
' <"$TZ_ZONE_TABLE"`
esac
@@ -467,7 +489,7 @@ while
# Make sure the corresponding zoneinfo file exists.
TZ_for_date=$TZDIR/$TZ
<"$TZ_for_date" || {
- echo >&2 "$0: time zone files are not set up correctly"
+ say >&2 "$0: time zone files are not set up correctly"
exit 1
}
esac
@@ -500,15 +522,15 @@ Universal Time is now: $UTdate."
echo >&2 "The following information has been given:"
echo >&2 ""
case $country%$region%$coord in
- ?*%?*%) echo >&2 " $country$newline $region";;
- ?*%%) echo >&2 " $country";;
- %?*%?*) echo >&2 " coord $coord$newline $region";;
- %%?*) echo >&2 " coord $coord";;
- *) echo >&2 " TZ='$TZ'"
+ ?*%?*%) say >&2 " $country$newline $region";;
+ ?*%%) say >&2 " $country";;
+ %?*%?*) say >&2 " coord $coord$newline $region";;
+ %%?*) say >&2 " coord $coord";;
+ *) say >&2 " TZ='$TZ'"
esac
- echo >&2 ""
- echo >&2 "Therefore TZ='$TZ' will be used.$extra_info"
- echo >&2 "Is the above information OK?"
+ say >&2 ""
+ say >&2 "Therefore TZ='$TZ' will be used.$extra_info"
+ say >&2 "Is the above information OK?"
doselect Yes No
ok=$select_result
@@ -523,7 +545,7 @@ case $SHELL in
*) file=.profile line="TZ='$TZ'; export TZ"
esac
-echo >&2 "
+say >&2 "
You can make this change permanent for yourself by appending the line
$line
to the file '$file' in your home directory; then log out and log in again.
@@ -531,4 +553,4 @@ to the file '$file' in your home directory; then log out and log in again.
Here is that TZ value again, this time on standard output so that you
can use the $0 command in shell scripts:"
-echo "$TZ"
+say "$TZ"