xref: /freebsd/usr.sbin/bsdconfig/timezone/share/continents.subr (revision 257e70f1d5ee61037c8c59b116538d3b6b1427a2)
1if [ ! "$_TIMEZONE_CONTINENTS_SUBR" ]; then _TIMEZONE_CONTINENTS_SUBR=1
2#
3# Copyright (c) 2011-2015 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#
28############################################################ INCLUDES
29
30BSDCFG_SHARE="/usr/share/bsdconfig"
31. $BSDCFG_SHARE/common.subr || exit 1
32f_dprintf "%s: loading includes..." timezone/continents.subr
33
34BSDCFG_LIBE="/usr/libexec/bsdconfig" APP_DIR="090.timezone"
35f_include_lang $BSDCFG_LIBE/$APP_DIR/include/messages.subr
36
37############################################################ CONFIGURATION
38
39#
40# List of worldly continents/oceans (export'ed for awk(1) ENVIRON visibility)
41#
42export CONTINENTS="
43	africa
44	america
45	antarctica
46	arctic
47	asia
48	atlantic
49	australia
50	europe
51	indian
52	pacific
53	utc
54"
55
56#
57# Directory name of each continent/ocean (in _PATH_ZONEINFO)
58#
59export continent_africa_name="Africa"
60export continent_america_name="America"
61export continent_antarctica_name="Antarctica"
62export continent_arctic_name="Arctic"
63export continent_asia_name="Asia"
64export continent_atlantic_name="Atlantic"
65export continent_australia_name="Australia"
66export continent_europe_name="Europe"
67export continent_indian_name="Indian"
68export continent_pacific_name="Pacific"
69export continent_utc_name="UTC"
70
71#
72# Export i18n menu texts of continents/oceans for awk(1) ENVIRON visibility
73# NOTE: These are defined in messages.subr included above.
74#
75export continent_africa_title
76export continent_america_title
77export continent_antarctica_title
78export continent_arctic_title
79export continent_asia_title
80export continent_atlantic_title
81export continent_australia_title
82export continent_europe_title
83export continent_indian_title
84export continent_pacific_title
85export continent_utc_title
86
87############################################################ FUNCTIONS
88
89# f_continent $cont $property [$var_to_set]
90#
91# Returns a single property of a given continent. Available properties are:
92#
93# 	name        Directory name of continent/ocean as it appears in
94# 	            _PATH_ZONEINFO.
95# 	title       Menu text of this continent/ocean to be displayed in the
96# 	            continent-selection menu.
97# 	nitems      Number of submenu items associated with this
98# 	            continent/ocean.
99# 	tlc_N       2-character country code of the Nth submenu item associated
100# 	            with this continent displayed in the country-selection menu
101# 	            (which appears after continent selection).
102# 	menu_list   Menu-list of regions for this continent.
103#
104# If $var_to_set is missing or NULL, the value of $var_to_get is printed to
105# standard output for capturing in a sub-shell (which is less-recommended
106# because of performance degredation; for example, when called in a loop).
107#
108f_continent()
109{
110	f_getvar "continent_${1}_$2" $3
111}
112
113# f_find_continent $title [$var_to_set]
114#
115# Returns continent identifier given continent title.
116#
117# If $var_to_set is missing or NULL, the value of $var_to_get is printed to
118# standard output for capturing in a sub-shell (which is less-recommended
119# because of performance degredation; for example, when called in a loop).
120#
121f_find_continent()
122{
123	local __cont __title
124	for __cont in $CONTINENTS; do
125		f_continent $__cont title __title
126		if [ "$1" = "$__title" ]; then
127			if [ "$2" ]; then
128				setvar "$2" $__cont
129			else
130				echo "$__cont"
131			fi
132			return $SUCCESS
133		fi
134	done
135	return $FAILURE
136}
137
138# f_OCEANP $cont [$var_to_set]
139#
140# Returns "1" if the first argument is an ocean, otherwise NULL.
141#
142# If $var_to_set is missing or NULL, the value of $var_to_get is printed to
143# standard output for capturing in a sub-shell (which is less-recommended
144# because of performance degredation; for example, when called in a loop).
145#
146f_OCEANP()
147{
148	case "$1" in
149	arctic|atlantic|indian|pacific)
150		if [ "$2" ]; then
151			setvar "$2" 1
152		else
153			echo 1
154		fi
155		;;
156	*)
157		[ "$2" ] && setvar "$2" ""
158	esac
159}
160
161############################################################ MAIN
162
163f_dprintf "%s: Successfully loaded." timezone/continents.subr
164
165fi # ! $_TIMEZONE_CONTINENTS_SUBR
166