[tz] [PATCH 1/2] * tzselect.ksh: Compute list of continents from the time zone table,

Paul Eggert eggert at cs.ucla.edu
Wed Aug 21 03:26:31 UTC 2013


so that 'tzselect -t time' doesn't create a blind alley for the Arctic.
---
 tzselect.ksh | 54 +++++++++++++++++++++++++++++++-----------------------
 1 file changed, 31 insertions(+), 23 deletions(-)

diff --git a/tzselect.ksh b/tzselect.ksh
index da6adb2..b8f2bc6 100644
--- a/tzselect.ksh
+++ b/tzselect.ksh
@@ -200,31 +200,39 @@ while
 
 	echo >&2 'Please select a continent, ocean, "coord", or "TZ".'
 
-	select continent in \
-	    Africa \
-	    Americas \
-	    Antarctica \
-	    'Arctic Ocean' \
-	    Asia \
-	    'Atlantic Ocean' \
-	    Australia \
-	    Europe \
-	    'Indian Ocean' \
-	    'Pacific Ocean' \
-	    'coord - I want to use geographical coordinates.' \
-	    'TZ - I want to specify the time zone using the Posix TZ format.'
-	do
-	    case $continent in
-	    '')
-		echo >&2 'Please enter a number in range.';;
-	    ?*)
+        quoted_continents=$(
+	  $AWK -F'\t' '
+	    /^[^#]/ {
+              entry = substr($3, 1, index($3, "/") - 1)
+              if (entry == "America")
+		entry = entry "s"
+              if (entry ~ /^(Arctic|Atlantic|Indian|Pacific)$/)
+		entry = entry " Ocean"
+              printf "'\''%s'\''\n", entry
+            }
+          ' $TZ_ZONE_TABLE |
+	  sort -u |
+	  tr '\n' ' '
+	  echo ''
+	)
+
+	eval '
+	    select continent in '"$quoted_continents"' \
+		"coord - I want to use geographical coordinates." \
+		"TZ - I want to specify the time zone using the Posix TZ format."
+	    do
 		case $continent in
-		Americas) continent=America;;
-		*' '*) continent=$(expr "$continent" : '\([^ ]*\)')
+		"")
+		    echo >&2 "Please enter a number in range.";;
+		?*)
+		    case $continent in
+		    Americas) continent=America;;
+		    *" "*) continent=$(expr "$continent" : '\''\([^ ]*\)'\'')
+		    esac
+		    break
 		esac
-		break
-	    esac
-	done
+	    done
+	'
 	esac
 
 	case $continent in
-- 
1.8.1.2





More information about the tz mailing list