1ab2043b8SDevin Teskeif [ ! "$_TIMEZONE_MENUS_SUBR" ]; then _TIMEZONE_MENUS_SUBR=1 2ab2043b8SDevin Teske# 3ab2043b8SDevin Teske# Copyright (c) 2011-2012 Devin Teske 4f8ea072aSDevin Teske# All rights reserved. 5ab2043b8SDevin Teske# 6ab2043b8SDevin Teske# Redistribution and use in source and binary forms, with or without 7ab2043b8SDevin Teske# modification, are permitted provided that the following conditions 8ab2043b8SDevin Teske# are met: 9ab2043b8SDevin Teske# 1. Redistributions of source code must retain the above copyright 10ab2043b8SDevin Teske# notice, this list of conditions and the following disclaimer. 11ab2043b8SDevin Teske# 2. Redistributions in binary form must reproduce the above copyright 12ab2043b8SDevin Teske# notice, this list of conditions and the following disclaimer in the 13ab2043b8SDevin Teske# documentation and/or other materials provided with the distribution. 14ab2043b8SDevin Teske# 15ab2043b8SDevin Teske# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 168e37a7c8SDevin Teske# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17ab2043b8SDevin Teske# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18ab2043b8SDevin Teske# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19ab2043b8SDevin Teske# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 208e37a7c8SDevin Teske# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21ab2043b8SDevin Teske# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22ab2043b8SDevin Teske# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23ab2043b8SDevin Teske# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24ab2043b8SDevin Teske# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25ab2043b8SDevin Teske# SUCH DAMAGE. 26ab2043b8SDevin Teske# 27ab2043b8SDevin Teske# $FreeBSD$ 28ab2043b8SDevin Teske# 29ab2043b8SDevin Teske############################################################ INCLUDES 30ab2043b8SDevin Teske 31ab2043b8SDevin TeskeBSDCFG_SHARE="/usr/share/bsdconfig" 32ab2043b8SDevin Teske. $BSDCFG_SHARE/common.subr || exit 1 3356961fd7SDevin Teskef_dprintf "%s: loading includes..." timezone/menus.subr 34ab2043b8SDevin Teskef_include $BSDCFG_SHARE/dialog.subr 35ab2043b8SDevin Teske 36ab2043b8SDevin Teske############################################################ GLOBALS 37ab2043b8SDevin Teske 38ab2043b8SDevin Teske# 39ab2043b8SDevin Teske# Export special included variables required by awk(1) for `ENVIRON' visibility 40ab2043b8SDevin Teske# 41ab2043b8SDevin Teskeexport DIALOG_MENU_TAGS 42ab2043b8SDevin Teske 43ab2043b8SDevin Teske############################################################ FUNCTIONS 44ab2043b8SDevin Teske 45ab2043b8SDevin Teske# f_make_menus 46ab2043b8SDevin Teske# 47ab2043b8SDevin Teske# Creates the tag/item ordered-pair list environment variables for the 48ab2043b8SDevin Teske# continent and country menus. 49ab2043b8SDevin Teske# 50ab2043b8SDevin Teske# Required variables [from continents.subr]: 51ab2043b8SDevin Teske# 52ab2043b8SDevin Teske# CONTINENTS 53ab2043b8SDevin Teske# Space-separated list of continents. 54ab2043b8SDevin Teske# continent_*_title 55ab2043b8SDevin Teske# Desired menu text for the continent represented by *. 56ab2043b8SDevin Teske# 57ab2043b8SDevin Teske# Required variables [created by f_read_iso3166_table from iso3166.subr]: 58ab2043b8SDevin Teske# 59ab2043b8SDevin Teske# COUNTRIES 60ab2043b8SDevin Teske# Space-separated list of 2-character country codes. 61ab2043b8SDevin Teske# country_*_name :: when country_*_nzones < 0 62ab2043b8SDevin Teske# Desired menu text for the country-zone represented by *, the 2- 63ab2043b8SDevin Teske# character country code. 64ab2043b8SDevin Teske# 65ab2043b8SDevin Teske# Required variables [created by f_read_zones from zones.subr]: 66ab2043b8SDevin Teske# 67ab2043b8SDevin Teske# country_*_nzones 68ab2043b8SDevin Teske# Number of zones for the country represented by *, the 2- 69ab2043b8SDevin Teske# character country code. Should be -1 if the country has only 70ab2043b8SDevin Teske# one single zone, otherwise 1 or greater to indicate how many 71ab2043b8SDevin Teske# zones the country has. 72ab2043b8SDevin Teske# country_*_cont :: when country_*_nzones < 0 73ab2043b8SDevin Teske# Principal continent (or ocean) in which the country-zone 74ab2043b8SDevin Teske# represented by *, the 2-character country code, resides. 75ab2043b8SDevin Teske# country_*_cont_N :: when country_*_nzones > 0 76ab2043b8SDevin Teske# Principal continent (or ocean) in which zone-N of the country 77ab2043b8SDevin Teske# represented by * resides, the 2-character country code. 78ab2043b8SDevin Teske# country_*_descr_N :: when country_*_nzones > 0 79ab2043b8SDevin Teske# Desired submenu text for zone-N of the country represented by 80ab2043b8SDevin Teske# *, the 2-character country code. 81ab2043b8SDevin Teske# 82ab2043b8SDevin Teske# Variables created by this function: 83ab2043b8SDevin Teske# 84ab2043b8SDevin Teske# continent_menu_list 85ab2043b8SDevin Teske# Menu-list of continents. 86ab2043b8SDevin Teske# continent_*_nitems 87ab2043b8SDevin Teske# Number of items associated with the continent represented by *, 88ab2043b8SDevin Teske# the continent identifier. 89ab2043b8SDevin Teske# continent_*_tlc_N 90ab2043b8SDevin Teske# 2-character country code of the Nth item in the continent menu 91ab2043b8SDevin Teske# for the continent represented by *, the continent identifier. 92ab2043b8SDevin Teske# continent_*_menu_list 93ab2043b8SDevin Teske# Menu-list of countries/zones for each continent represented by 94ab2043b8SDevin Teske# *, the continent identifier. 95ab2043b8SDevin Teske# country_*_menu_list 96ab2043b8SDevin Teske# For countries that have multiple zones, this is the submenu- 97ab2043b8SDevin Teske# list of zones for said country represented by *, the 2- 98ab2043b8SDevin Teske# character country code. 99ab2043b8SDevin Teske# 100ab2043b8SDevin Teske# This function is a two-parter. Below is the awk(1) portion of the function, 101ab2043b8SDevin Teske# afterward is the sh(1) function which utilizes the below awk script. 102ab2043b8SDevin Teske# 103ab2043b8SDevin Teskef_make_menus_awk=' 104ab2043b8SDevin Teskefunction add_zone_n_to_country_menu(tlc, n) 105ab2043b8SDevin Teske{ 106ab2043b8SDevin Teske zone_title = ENVIRON["country_" tlc "_descr_" n] 107*bc3f5ec9SDevin Teske gsub(/'\''/, "'\''\\'\'\''", zone_title) 108ab2043b8SDevin Teske country_menu_list[tlc] = country_menu_list[tlc] \ 109ab2043b8SDevin Teske ( length(country_menu_list[tlc]) > 0 ? "\n" : "" ) \ 110ab2043b8SDevin Teske n " '\''" zone_title "'\''" 111ab2043b8SDevin Teske} 112ab2043b8SDevin TeskeBEGIN { 113ab2043b8SDevin Teske # 114ab2043b8SDevin Teske # First, count up all the countries in each continent/ocean. 115ab2043b8SDevin Teske # Be careful to count those countries which have multiple zones 116ab2043b8SDevin Teske # only once for each. NB: some countries are in multiple 117ab2043b8SDevin Teske # continents/oceans. 118ab2043b8SDevin Teske # 119ab2043b8SDevin Teske i = split(ENVIRON["COUNTRIES"], countries, /[[:space:]]+/) 120ab2043b8SDevin Teske for (cp = 1; cp <= i; cp++) 121ab2043b8SDevin Teske { 122ab2043b8SDevin Teske tlc = countries[cp] 123ab2043b8SDevin Teske title = ENVIRON["country_" tlc "_name"] 124*bc3f5ec9SDevin Teske gsub(/'\''/, "'\''\\'\'\''", title) 125ab2043b8SDevin Teske nzones = ENVIRON["country_" tlc "_nzones"] 126ab2043b8SDevin Teske if (!nzones) 127ab2043b8SDevin Teske { 128ab2043b8SDevin Teske # Country has no zones 129ab2043b8SDevin Teske continue 130ab2043b8SDevin Teske } 131ab2043b8SDevin Teske else if (nzones < 0) 132ab2043b8SDevin Teske { 133ab2043b8SDevin Teske # Country has only one zone 134ab2043b8SDevin Teske cont = ENVIRON["country_" tlc "_cont"] 135ab2043b8SDevin Teske nitems = ++continent_nitems[cont] 136ab2043b8SDevin Teske continent_tlc[cont,nitems] = tlc 137ab2043b8SDevin Teske continent_title[cont,nitems] = title 138ab2043b8SDevin Teske } 139ab2043b8SDevin Teske else 140ab2043b8SDevin Teske { 141ab2043b8SDevin Teske # Country has one or more zones 142ab2043b8SDevin Teske for (n = 1; n <= nzones; n++) 143ab2043b8SDevin Teske { 144ab2043b8SDevin Teske add_zone_n_to_country_menu(tlc, n) 145ab2043b8SDevin Teske cont = ENVIRON["country_" tlc "_cont_" n] 146ab2043b8SDevin Teske for (x = 1; x < n; x++) 147ab2043b8SDevin Teske { 148ab2043b8SDevin Teske contx = ENVIRON["country_"tlc"_cont_"x] 149ab2043b8SDevin Teske if (cont == contx) break 150ab2043b8SDevin Teske } 151ab2043b8SDevin Teske if (x == n) 152ab2043b8SDevin Teske { 153ab2043b8SDevin Teske nitems = ++continent_nitems[cont] 154ab2043b8SDevin Teske continent_tlc[cont,nitems] = tlc 155ab2043b8SDevin Teske continent_title[cont,nitems] = title 156ab2043b8SDevin Teske } 157ab2043b8SDevin Teske } 158ab2043b8SDevin Teske } 159ab2043b8SDevin Teske } 160ab2043b8SDevin Teske} 161ab2043b8SDevin TeskeEND { 162ab2043b8SDevin Teske tags = ENVIRON["DIALOG_MENU_TAGS"] 163ab2043b8SDevin Teske cont_menu_list = "" 164ab2043b8SDevin Teske tagn = 0 165ab2043b8SDevin Teske 166ab2043b8SDevin Teske # 167ab2043b8SDevin Teske # Assemble the menu items in the menu list for each continent/ocean. 168ab2043b8SDevin Teske # 169ab2043b8SDevin Teske i = split(ENVIRON["CONTINENTS"], array, /[[:space:]]+/) 170ab2043b8SDevin Teske for (item = 1; item <= i; item++) 171ab2043b8SDevin Teske { 172ab2043b8SDevin Teske cont = array[item] 173ab2043b8SDevin Teske if (!cont) continue 174ab2043b8SDevin Teske 175ab2043b8SDevin Teske if (++tagn >= length(tags)) break 176ab2043b8SDevin Teske tag = substr(tags, tagn, 1) 177ab2043b8SDevin Teske cont_menu_list = cont_menu_list \ 178ab2043b8SDevin Teske ( length(cont_menu_list) > 0 ? "\n" : "" ) \ 179ab2043b8SDevin Teske "'\''" tag "'\'' '\''" \ 180ab2043b8SDevin Teske ENVIRON["continent_" cont "_title"] "'\''" 181ab2043b8SDevin Teske 182ab2043b8SDevin Teske nitems = continent_nitems[cont] 183ab2043b8SDevin Teske printf "continent_%s_nitems=%d\n", cont, nitems 184ab2043b8SDevin Teske 185ab2043b8SDevin Teske menu_list = "" 186ab2043b8SDevin Teske for (n = 1; n <= nitems; n++) 187ab2043b8SDevin Teske { 188ab2043b8SDevin Teske printf "continent_%s_tlc_%d=%s\n", 189ab2043b8SDevin Teske cont, n, continent_tlc[cont,n] 190ab2043b8SDevin Teske 191ab2043b8SDevin Teske title = continent_title[cont,n] 192ab2043b8SDevin Teske menu_list = menu_list \ 193ab2043b8SDevin Teske ( length(menu_list) > 0 ? "\n" : "" ) \ 194ab2043b8SDevin Teske n " '\''" title "'\''" 195ab2043b8SDevin Teske } 196ab2043b8SDevin Teske 197ab2043b8SDevin Teske gsub(/"/, "\\\"", menu_list) 198ab2043b8SDevin Teske printf "continent_%s_menu_list=\"%s\"\n", cont, menu_list 199ab2043b8SDevin Teske } 200ab2043b8SDevin Teske 201ab2043b8SDevin Teske gsub(/"/, "\\\"", continent_menu_list) 202ab2043b8SDevin Teske printf "continent_menu_list=\"%s\"\n", cont_menu_list 203ab2043b8SDevin Teske print "export continent_menu_list" 204ab2043b8SDevin Teske 205ab2043b8SDevin Teske # 206ab2043b8SDevin Teske # Dump the submenus of countries with multiple zones 207ab2043b8SDevin Teske # 208ab2043b8SDevin Teske for (tlc in country_menu_list) 209ab2043b8SDevin Teske { 210ab2043b8SDevin Teske menu_list = country_menu_list[tlc] 211ab2043b8SDevin Teske gsub(/"/, "\\\"", menu_list) 212ab2043b8SDevin Teske printf "country_%s_menu_list=\"%s\"\n", tlc, menu_list 213ab2043b8SDevin Teske } 214ab2043b8SDevin Teske} 215ab2043b8SDevin Teske' 216ab2043b8SDevin Teskef_make_menus() 217ab2043b8SDevin Teske{ 218ab2043b8SDevin Teske eval $( :| awk "$f_make_menus_awk" ) 219ab2043b8SDevin Teske} 220ab2043b8SDevin Teske 22156961fd7SDevin Teske############################################################ MAIN 22256961fd7SDevin Teske 22356961fd7SDevin Teskef_dprintf "%s: Successfully loaded." timezone/menus.subr 22456961fd7SDevin Teske 225ab2043b8SDevin Teskefi # ! $_TIMEZONE_MENUS_SUBR 226