1if [ ! "$_TIMEZONE_COUNTRIES_SUBR" ]; then _TIMEZONE_COUNTRIES_SUBR=1 2# 3# Copyright (c) 2011-2012 Devin Teske 4# All rights reserved. 5# 6# Redistribution and use in source and binary forms, with or without 7# modification, are permitted provided that the following conditions 8# are met: 9# 1. Redistributions of source code must retain the above copyright 10# notice, this list of conditions and the following disclaimer. 11# 2. Redistributions in binary form must reproduce the above copyright 12# notice, this list of conditions and the following disclaimer in the 13# documentation and/or other materials provided with the distribution. 14# 15# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25# SUCH DAMAGE. 26# 27# $FreeBSD$ 28 29# f_country $code $property 30# 31# Returns a single property of a given country. Available properties are: 32# 33# name Name of the country as read from _PATH_ISO3166. 34# nzones Number of zones within the country (-1 if country has 35# only a single zone). 36# filename The filename portion of the TZ field (after the `/') as 37# read from _PATH_ZONETAB. 38# cont The principal continent in which the country lies (appears 39# before the `/' in the TZ field of _PATH_ZONETAB). 40# filename_N Like filename, but for the Nth zone when the country has 41# multiple zones (nzones > 0). 42# cont_N Like cont, but for the Nth zone when the country has 43# multiple zones (nzones > 0). 44# descr_N Like name, but for the Nth zone when the country has 45# multiple zones (nzones > 0) 46# 47f_country() 48{ 49 local code="$1" property="$2" 50 eval echo \"\${country_${code}_$property}\" 51} 52 53# f_sort_countries 54# 55# Sorts alphabetically the 2-character country codes listed in $COUNTRIES based 56# on the name of each country. 57# 58# This function is a two-parter. Below is the awk(1) portion of the function, 59# afterward is the sh(1) function which utilizes the below awk script. 60# 61f_sort_countries_awk=' 62{ 63 split($0, array, /[[:space:]]+/) 64 for (item in array) 65 { 66 tlc = array[item] 67 print ENVIRON["country_" tlc "_name"] " " tlc 68 } 69} 70' 71f_sort_countries() 72{ 73 COUNTRIES=$( echo "$COUNTRIES" | awk "$f_sort_countries_awk" | 74 sort | awk '{print $NF}' ) 75 export COUNTRIES 76} 77 78f_dprintf "%s: Successfully loaded." timezone/countries.subr 79 80fi # ! $_TIMEZONE_COUNTRIES_SUBR 81