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