keymap revision 260678
1238438Sdteske#!/bin/sh 2238438Sdteske#- 3249746Sdteske# Copyright (c) 2012-2013 Devin Teske 4252980Sdteske# All rights reserved. 5238438Sdteske# 6238438Sdteske# Redistribution and use in source and binary forms, with or without 7238438Sdteske# modification, are permitted provided that the following conditions 8238438Sdteske# are met: 9238438Sdteske# 1. Redistributions of source code must retain the above copyright 10238438Sdteske# notice, this list of conditions and the following disclaimer. 11238438Sdteske# 2. Redistributions in binary form must reproduce the above copyright 12238438Sdteske# notice, this list of conditions and the following disclaimer in the 13238438Sdteske# documentation and/or other materials provided with the distribution. 14238438Sdteske# 15238438Sdteske# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16252987Sdteske# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17238438Sdteske# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18238438Sdteske# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19238438Sdteske# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20252987Sdteske# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21238438Sdteske# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22238438Sdteske# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23238438Sdteske# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24238438Sdteske# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25238438Sdteske# SUCH DAMAGE. 26238438Sdteske# 27238438Sdteske# $FreeBSD: stable/10/usr.sbin/bsdconfig/console/keymap 260678 2014-01-15 07:49:17Z dteske $ 28238438Sdteske# 29238438Sdteske############################################################ INCLUDES 30238438Sdteske 31240684SdteskeBSDCFG_SHARE="/usr/share/bsdconfig" 32240684Sdteske. $BSDCFG_SHARE/common.subr || exit 1 33244675Sdteskef_dprintf "%s: loading includes..." "$0" 34240684Sdteskef_include $BSDCFG_SHARE/dialog.subr 35240684Sdteskef_include $BSDCFG_SHARE/mustberoot.subr 36240684Sdteskef_include $BSDCFG_SHARE/sysrc.subr 37238438Sdteske 38240684SdteskeBSDCFG_LIBE="/usr/libexec/bsdconfig" APP_DIR="080.console" 39238438Sdteskef_include_lang $BSDCFG_LIBE/$APP_DIR/include/messages.subr 40238438Sdteske 41260678Sdteskef_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" ipgm && 42260678Sdteske pgm="${ipgm:-$pgm}" 43238438Sdteske 44238438Sdteske############################################################ CONFIGURATION 45238438Sdteske 46238438Sdteske# 47238438Sdteske# List of keymap names 48238438Sdteske# 49238438SdteskeKEYMAP_NAMES=" 50238438Sdteske belgian brazil_cp850 brazil_iso 51238438Sdteske brazil_iso_accent bulgarian_bds bulgarian_phonetic 52238438Sdteske central_european_iso croatian_iso czech_iso_accent 53238438Sdteske danish_cp865 danish_iso estonian_cp850 54238438Sdteske estonian_iso estonian_iso_15 finnish_cp850 55238438Sdteske finnish_iso french_iso french_iso_accent 56238438Sdteske french_iso_macbook german_cp850 german_iso 57238438Sdteske greek_101 greek_104 greek_elot 58238438Sdteske hungarian_101 hungarian_102 icelandic 59238438Sdteske icelandic_accent italian japanese_106 60238438Sdteske latin_american latin_american_accent norway_iso 61238438Sdteske polish_iso portuguese portuguese_accent 62238438Sdteske russia_koi8_r slovak slovenian 63238438Sdteske spanish spanish_accent swedish_cp850 64238438Sdteske swedish_iso swiss_french_cp850 swiss_french_iso 65238438Sdteske swiss_french_iso_accent swiss_german_cp850 swiss_german_iso 66238438Sdteske swiss_german_iso_accent uk_cp850 uk_iso 67238438Sdteske ukrainian_koi8_u ukrainian_koi8_u_koi8_r usa_capslock_ctrl 68238438Sdteske usa_dvorak usa_dvorak_left usa_dvorak_right 69238438Sdteske usa_emacs usa_iso usa_unix 70238438Sdteske" # END-QUOTE 71238438Sdteske 72238438Sdteske############################################################ FUNCTIONS 73238438Sdteske 74238438Sdteske# dialog_menu_main 75238438Sdteske# 76238438Sdteske# Display the dialog(1)-based application main menu. 77238438Sdteske# 78238438Sdteskedialog_menu_main() 79238438Sdteske{ 80251264Sdteske local prompt="$msg_keymap_menu_text" 81251264Sdteske local menu_list defaultitem= # Calculated below 82238438Sdteske local hline="$hline_choose_a_keyboard_map" 83238438Sdteske 84238438Sdteske # 85238438Sdteske # Export variables for awk(1) ENVIRON visibility 86238438Sdteske # 87238438Sdteske local name 88238438Sdteske for name in $KEYMAP_NAMES; do 89238438Sdteske export msg_$name msg_${name}_desc 90238438Sdteske done 91238438Sdteske 92238438Sdteske # 93238438Sdteske # Generate a sorted list of keymaps. If the first letter of the keymap 94238438Sdteske # name is unique (case-insensitive) then it is used as the tag to allow 95238438Sdteske # the user to jump to that entry. 96238438Sdteske # 97238438Sdteske menu_list=$( 98238438Sdteske for name in $KEYMAP_NAMES; do 99238438Sdteske eval echo \"\$msg_$name\" msg_$name 100238438Sdteske done | sort | awk 'BEGIN { prefix = "" } 101238438Sdteske { 102238438Sdteske cur_prefix = tolower(substr(ENVIRON[$NF], 1, 1)) 103238438Sdteske printf "'\''" 104238438Sdteske if ( prefix != cur_prefix ) 105238438Sdteske prefix = cur_prefix 106238438Sdteske else 107238438Sdteske printf " " 108238438Sdteske printf "%s'\'' '\''%s'\''\n", 109238438Sdteske ENVIRON[$NF], ENVIRON[$NF"_desc"] 110238438Sdteske }' 111238438Sdteske ) 112238438Sdteske 113251190Sdteske local height width rows 114251190Sdteske eval f_dialog_menu_size height width rows \ 115251190Sdteske \"\$DIALOG_TITLE\" \ 116251190Sdteske \"\$DIALOG_BACKTITLE\" \ 117251190Sdteske \"\$prompt\" \ 118251190Sdteske \"\$hline\" \ 119251190Sdteske $menu_list 120238438Sdteske 121249751Sdteske case "$( f_sysrc_get keymap )" in 122251904Sdteske be.iso) defaultitem="$msg_belgian" ;; 123251904Sdteske br275.cp850) defaultitem="$msg_brazil_cp850" ;; 124251904Sdteske br275.iso) defaultitem="$msg_brazil_iso" ;; 125251904Sdteske br275.iso.acc) defaultitem="$msg_brazil_iso_accent" ;; 126251904Sdteske bg.bds.ctrlcaps) defaultitem="$msg_bulgarian_bds" ;; 127251904Sdteske bg.phonetic.ctrlcaps) defaultitem="$msg_bulgarian_phonetic" ;; 128251904Sdteske ce.iso2) defaultitem="$msg_central_european_iso" ;; 129251904Sdteske hr.iso) defaultitem="$msg_croatian_iso" ;; 130251904Sdteske cs.latin2.qwertz) defaultitem="$msg_czech_iso_accent" ;; 131251904Sdteske danish.cp865) defaultitem="$msg_danish_cp865" ;; 132251904Sdteske danish.iso) defaultitem="$msg_danish_iso" ;; 133251904Sdteske estonian.cp850) defaultitem="$msg_estonian_cp850" ;; 134251904Sdteske estonian.iso) defaultitem="$msg_estonian_iso" ;; 135251904Sdteske estonian.iso15) defaultitem="$msg_estonian_iso_15" ;; 136251904Sdteske finnish.cp850) defaultitem="$msg_finnish_cp850" ;; 137251904Sdteske finnish.iso) defaultitem="$msg_finnish_iso" ;; 138251904Sdteske fr.iso) defaultitem="$msg_french_iso" ;; 139251904Sdteske fr.iso.acc) defaultitem="$msg_french_iso_accent" ;; 140251904Sdteske fr.macbook.acc) defaultitem="$msg_french_iso_macbook" ;; 141251904Sdteske german.cp850) defaultitem="$msg_german_cp850" ;; 142251904Sdteske german.iso) defaultitem="$msg_german_iso" ;; 143251904Sdteske gr.us101.acc) defaultitem="$msg_greek_101" ;; 144251904Sdteske el.iso07) defaultitem="$msg_greek_104" ;; 145251904Sdteske gr.elot.acc) defaultitem="$msg_greek_elot" ;; 146251904Sdteske hu.iso2.101keys) defaultitem="$msg_hungarian_101" ;; 147251904Sdteske hu.iso2.102keys) defaultitem="$msg_hungarian_102" ;; 148251904Sdteske icelandic.iso) defaultitem="$msg_icelandic" ;; 149251904Sdteske icelandic.iso.acc) defaultitem="$msg_icelandic_accent" ;; 150251904Sdteske it.iso) defaultitem="$msg_italian" ;; 151251904Sdteske jp.106) defaultitem="$msg_japanese_106" ;; 152251904Sdteske latinamerican) defaultitem="$msg_latin_american" ;; 153251904Sdteske latinamerican.iso.acc) defaultitem="$msg_latin_american_accent" ;; 154251904Sdteske norwegian.iso) defaultitem="$msg_norway_iso" ;; 155251904Sdteske pl_PL.ISO8859-2) defaultitem="$msg_polish_iso" ;; 156251904Sdteske pt.iso) defaultitem="$msg_portuguese" ;; 157251904Sdteske pt.iso.acc) defaultitem="$msg_portuguese_accent" ;; 158251904Sdteske ru.koi8-r) defaultitem="$msg_russia_koi8_r" ;; 159251904Sdteske sk.iso2) defaultitem="$msg_slovak" ;; 160251904Sdteske si.iso) defaultitem="$msg_slovenian" ;; 161251904Sdteske spanish.iso) defaultitem="$msg_spanish" ;; 162251904Sdteske spanish.iso.acc) defaultitem="$msg_spanish_accent" ;; 163251904Sdteske swedish.cp850) defaultitem="$msg_swedish_cp850" ;; 164251904Sdteske swedish.iso) defaultitem="$msg_swedish_iso" ;; 165251904Sdteske swissfrench.cp850) defaultitem="$msg_swiss_french_cp850" ;; 166251904Sdteske swissfrench.iso) defaultitem="$msg_swiss_french_iso" ;; 167251904Sdteske swissfrench.iso.acc) defaultitem="$msg_swiss_french_iso_accent" ;; 168251904Sdteske swissgerman.cp850) defaultitem="$msg_swiss_german_cp850" ;; 169251904Sdteske swissgerman.iso) defaultitem="$msg_swiss_german_iso" ;; 170251904Sdteske swissgerman.iso.acc) defaultitem="$msg_swiss_german_iso_accent" ;; 171251904Sdteske uk.cp850) defaultitem="$msg_uk_cp850" ;; 172251904Sdteske uk.iso) defaultitem="$msg_uk_iso" ;; 173251904Sdteske ua.koi8-u) defaultitem="$msg_ukrainian_koi8_u" ;; 174251904Sdteske ua.koi8-u.shift.alt) defaultitem="$msg_ukrainian_koi8_u_koi8_r" ;; 175251904Sdteske us.pc-ctrl) defaultitem="$msg_usa_capslock_ctrl" ;; 176251904Sdteske us.dvorak) defaultitem="$msg_usa_dvorak" ;; 177251904Sdteske us.dvorakl) defaultitem="$msg_usa_dvorak_left" ;; 178251904Sdteske us.dvorakr) defaultitem="$msg_usa_dvorak_right" ;; 179251904Sdteske us.emacs) defaultitem="$msg_usa_emacs" ;; 180251904Sdteske us.iso) defaultitem="$msg_usa_iso" ;; 181251904Sdteske us.unix) defaultitem="$msg_usa_unix" ;; 182249751Sdteske esac 183249751Sdteske 184249751Sdteske # The defaultitem may have to be indented to match the menu_list 185249751Sdteske if [ "$defaultitem" ]; then 186249751Sdteske ( eval set -- $menu_list 187249751Sdteske while [ $# -gt 0 ]; do 188249751Sdteske [ "$defaultitem" = "$1" ] && break 189249751Sdteske [ " $defaultitem" = "$1" ] && exit 0 190249751Sdteske shift 2 # tag/item 191249751Sdteske done 192249751Sdteske exit 1 # No modification needed 193249751Sdteske ) && defaultitem=" $defaultitem" 194249751Sdteske fi 195249751Sdteske 196251236Sdteske local menu_choice 197251236Sdteske menu_choice=$( eval $DIALOG \ 198249751Sdteske --title \"\$DIALOG_TITLE\" \ 199238438Sdteske --backtitle \"\$DIALOG_BACKTITLE\" \ 200238438Sdteske --hline \"\$hline\" \ 201238438Sdteske --ok-label \"\$msg_ok\" \ 202238438Sdteske --cancel-label \"\$msg_cancel\" \ 203249751Sdteske --default-item \"\$defaultitem\" \ 204251190Sdteske --menu \"\$prompt\" \ 205251190Sdteske $height $width $rows \ 206238438Sdteske $menu_list \ 207240768Sdteske 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD 208240768Sdteske ) 209240768Sdteske local retval=$? 210251236Sdteske f_dialog_menutag_store -s "$menu_choice" 211240768Sdteske return $retval 212238438Sdteske} 213238438Sdteske 214238438Sdteske############################################################ MAIN 215238438Sdteske 216238438Sdteske# Incorporate rc-file if it exists 217238438Sdteske[ -f "$HOME/.bsdconfigrc" ] && f_include "$HOME/.bsdconfigrc" 218238438Sdteske 219238438Sdteske# 220238438Sdteske# Process command-line arguments 221238438Sdteske# 222250633Sdteskewhile getopts h$GETOPTS_STDARGS flag; do 223238438Sdteske case "$flag" in 224252178Sdteske h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm" ;; 225238438Sdteske esac 226238438Sdteskedone 227238438Sdteskeshift $(( $OPTIND - 1 )) 228238438Sdteske 229238438Sdteske# 230238438Sdteske# Initialize 231238438Sdteske# 232238438Sdteskef_dialog_title "$msg_system_console_keymap" 233238438Sdteskef_dialog_backtitle "${ipgm:+bsdconfig }$pgm" 234238438Sdteskef_mustberoot_init 235238438Sdteske 236238438Sdteske# 237238438Sdteske# Launch application main menu 238238438Sdteske# 239238438Sdteskewhile :; do 240251236Sdteske dialog_menu_main || f_die 241251236Sdteske f_dialog_menutag_fetch mtag 242238438Sdteske 243238438Sdteske # 244238438Sdteske # Reverse the users choice into the variable name 245238438Sdteske # 246238438Sdteske keymap_name= 247238438Sdteske mtag="${mtag# }" # remove single leading-space if-present 248238438Sdteske for name in $KEYMAP_NAMES; do 249260678Sdteske debug= f_getvar msg_$name msg 250260678Sdteske [ "$msg" = "$mtag" ] && keymap_name="$name" break 251238438Sdteske done 252238438Sdteske 253238438Sdteske [ "$keymap_name" ] || continue 254238438Sdteske 255251905Sdteske keymap_to_set= 256238438Sdteske case "$keymap_name" in 257251905Sdteske belgian) keymap_to_set="be.iso" ;; 258251905Sdteske brazil_cp850) keymap_to_set="br275.cp850" ;; 259251905Sdteske brazil_iso) keymap_to_set="br275.iso" ;; 260251905Sdteske brazil_iso_accent) keymap_to_set="br275.iso.acc" ;; 261251905Sdteske bulgarian_bds) keymap_to_set="bg.bds.ctrlcaps" ;; 262251905Sdteske bulgarian_phonetic) keymap_to_set="bg.phonetic.ctrlcaps" ;; 263251905Sdteske central_european_iso) keymap_to_set="ce.iso2" ;; 264251905Sdteske croatian_iso) keymap_to_set="hr.iso" ;; 265251905Sdteske czech_iso_accent) keymap_to_set="cs.latin2.qwertz" ;; 266251905Sdteske danish_cp865) keymap_to_set="danish.cp865" ;; 267251905Sdteske danish_iso) keymap_to_set="danish.iso" ;; 268251905Sdteske estonian_cp850) keymap_to_set="estonian.cp850" ;; 269251905Sdteske estonian_iso) keymap_to_set="estonian.iso" ;; 270251905Sdteske estonian_iso_15) keymap_to_set="estonian.iso15" ;; 271251905Sdteske finnish_cp850) keymap_to_set="finnish.cp850" ;; 272251905Sdteske finnish_iso) keymap_to_set="finnish.iso" ;; 273251905Sdteske french_iso) keymap_to_set="fr.iso" ;; 274251905Sdteske french_iso_accent) keymap_to_set="fr.iso.acc" ;; 275251905Sdteske french_iso_macbook) keymap_to_set="fr.macbook.acc" ;; 276251905Sdteske german_cp850) keymap_to_set="german.cp850" ;; 277251905Sdteske german_iso) keymap_to_set="german.iso" ;; 278251905Sdteske greek_101) keymap_to_set="gr.us101.acc" ;; 279251905Sdteske greek_104) keymap_to_set="el.iso07" ;; 280251905Sdteske greek_elot) keymap_to_set="gr.elot.acc" ;; 281251905Sdteske hungarian_101) keymap_to_set="hu.iso2.101keys" ;; 282251905Sdteske hungarian_102) keymap_to_set="hu.iso2.102keys" ;; 283251905Sdteske icelandic) keymap_to_set="icelandic.iso" ;; 284251905Sdteske icelandic_accent) keymap_to_set="icelandic.iso.acc" ;; 285251905Sdteske italian) keymap_to_set="it.iso" ;; 286251905Sdteske japanese_106) keymap_to_set="jp.106" ;; 287251905Sdteske latin_american) keymap_to_set="latinamerican" ;; 288251905Sdteske latin_american_accent) keymap_to_set="latinamerican.iso.acc" ;; 289251905Sdteske norway_iso) keymap_to_set="norwegian.iso" ;; 290251905Sdteske polish_iso) keymap_to_set="pl_PL.ISO8859-2" ;; 291251905Sdteske portuguese) keymap_to_set="pt.iso" ;; 292251905Sdteske portuguese_accent) keymap_to_set="pt.iso.acc" ;; 293251905Sdteske russia_koi8_r) keymap_to_set="ru.koi8-r" ;; 294251905Sdteske slovak) keymap_to_set="sk.iso2" ;; 295251905Sdteske slovenian) keymap_to_set="si.iso" ;; 296251905Sdteske spanish) keymap_to_set="spanish.iso" ;; 297251905Sdteske spanish_accent) keymap_to_set="spanish.iso.acc" ;; 298251905Sdteske swedish_cp850) keymap_to_set="swedish.cp850" ;; 299251905Sdteske swedish_iso) keymap_to_set="swedish.iso" ;; 300251905Sdteske swiss_french_cp850) keymap_to_set="swissfrench.cp850" ;; 301251905Sdteske swiss_french_iso) keymap_to_set="swissfrench.iso" ;; 302251905Sdteske swiss_french_iso_accent) keymap_to_set="swissfrench.iso.acc" ;; 303251905Sdteske swiss_german_cp850) keymap_to_set="swissgerman.cp850" ;; 304251905Sdteske swiss_german_iso) keymap_to_set="swissgerman.iso" ;; 305251905Sdteske swiss_german_iso_accent) keymap_to_set="swissgerman.iso.acc" ;; 306251905Sdteske uk_cp850) keymap_to_set="uk.cp850" ;; 307251905Sdteske uk_iso) keymap_to_set="uk.iso" ;; 308251905Sdteske ukrainian_koi8_u) keymap_to_set="ua.koi8-u" ;; 309251905Sdteske ukrainian_koi8_u_koi8_r) keymap_to_set="ua.koi8-u.shift.alt" ;; 310251905Sdteske usa_capslock_ctrl) keymap_to_set="us.pc-ctrl" ;; 311251905Sdteske usa_dvorak) keymap_to_set="us.dvorak" ;; 312251905Sdteske usa_dvorak_left) keymap_to_set="us.dvorakl" ;; 313251905Sdteske usa_dvorak_right) keymap_to_set="us.dvorakr" ;; 314251905Sdteske usa_emacs) keymap_to_set="us.emacs" ;; 315251905Sdteske usa_iso) keymap_to_set="us.iso" ;; 316251905Sdteske usa_unix) keymap_to_set="us.unix" ;; 317238438Sdteske esac 318251905Sdteske 319251905Sdteske if [ "$keymap_to_set" ]; then 320260678Sdteske f_eval_catch "$0" f_sysrc_set \ 321260678Sdteske 'f_sysrc_set keymap "%s"' "$keymap_to_set" || f_die 322251905Sdteske break 323251905Sdteske else 324251907Sdteske f_die 1 "$msg_unknown_keymap" 325251905Sdteske fi 326238438Sdteskedone 327238438Sdteske 328238438Sdteskeexit $SUCCESS 329238438Sdteske 330238438Sdteske################################################################################ 331238438Sdteske# END 332238438Sdteske################################################################################ 333