1 if [ ! "$_TIMEZONE_COUNTRIES_SUBR" ]; then _TIMEZONE_COUNTRIES_SUBR=1
3 # Copyright (c) 2011-2012 Devin Teske
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
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.
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
29 # f_country $code $property
31 # Returns a single property of a given country. Available properties are:
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)
49 local code="$1" property="$2"
50 eval echo \"\${country_${code}_$property}\"
55 # Sorts alphabetically the 2-character country codes listed in $COUNTRIES based
56 # on the name of each country.
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.
61 f_sort_countries_awk='
63 split($0, array, /[[:space:]]+/)
67 print ENVIRON["country_" tlc "_name"] " " tlc
73 COUNTRIES=$( echo "$COUNTRIES" | awk "$f_sort_countries_awk" |
74 sort | awk '{print $NF}' )
78 f_dprintf "%s: Successfully loaded." timezone/countries.subr
80 fi # ! $_TIMEZONE_COUNTRIES_SUBR