From owner-svn-src-head@FreeBSD.ORG Tue Jun 4 03:30:45 2013 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by hub.freebsd.org (Postfix) with ESMTP id 8F21D7C9; Tue, 4 Jun 2013 03:30:45 +0000 (UTC) (envelope-from dteske@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) by mx1.freebsd.org (Postfix) with ESMTP id 80F9F1826; Tue, 4 Jun 2013 03:30:45 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id r543UjEQ004351; Tue, 4 Jun 2013 03:30:45 GMT (envelope-from dteske@svn.freebsd.org) Received: (from dteske@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id r543Ui5c004344; Tue, 4 Jun 2013 03:30:44 GMT (envelope-from dteske@svn.freebsd.org) Message-Id: <201306040330.r543Ui5c004344@svn.freebsd.org> From: Devin Teske Date: Tue, 4 Jun 2013 03:30:44 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r251361 - in head/usr.sbin/bsdconfig: console share share/packages startup X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 04 Jun 2013 03:30:45 -0000 Author: dteske Date: Tue Jun 4 03:30:44 2013 New Revision: 251361 URL: http://svnweb.freebsd.org/changeset/base/251361 Log: Similar to r251236, r251242, and r251244. Introduce new function-pair to dialog(1) API in dialog.subr responsible for retrieving menu-choice data (for the --menu widget). Add f_dialog_menuitem_store()/f_dialog_menuitem_fetch() for storing and retrieving the menuitem (not the tag) from a --menu widget result. The dialog --menu widget returns the `tag' from the tag/item pair of choices for a menu list. Because the menu list is often local to the function that is displaying it, the ability to dereference this into the item is not possible unless you use a global. This changes things so the function (upon successful return of dialog) dereferences the tag into the item and stores it for later retrieval using these functions. NOTE: Tags are dereferenced into items using f_dialog_menutag2item(). Modified: head/usr.sbin/bsdconfig/console/ttys head/usr.sbin/bsdconfig/share/dialog.subr head/usr.sbin/bsdconfig/share/packages/packages.subr head/usr.sbin/bsdconfig/startup/rcvar Modified: head/usr.sbin/bsdconfig/console/ttys ============================================================================== --- head/usr.sbin/bsdconfig/console/ttys Tue Jun 4 02:56:56 2013 (r251360) +++ head/usr.sbin/bsdconfig/console/ttys Tue Jun 4 03:30:44 2013 (r251361) @@ -48,22 +48,6 @@ ipgm=$( f_index_menusel_keyword $BSDCFG_ # ETC_TTYS=/etc/ttys -############################################################ GLOBALS - -# -# Terminal-type map/menu-item list -# -TTY_MENU_LIST=" - '1 $msg_none' '$msg_none_ttys_desc' - '2 $msg_ibm_437_vga_default' 'cons25' - '3 $msg_iso_8859_1' 'cons25l1' - '4 $msg_iso_8859_2' 'cons25l2' - '5 $msg_iso_8859_7' 'cons25l7' - '6 $msg_koi8_r' 'cons25r' - '7 $msg_koi8_u' 'cons25u' - '8 $msg_us_ascii' 'cons25w' -" # END-QUOTE - ############################################################ FUNCTIONS # dialog_menu_main @@ -73,6 +57,16 @@ TTY_MENU_LIST=" dialog_menu_main() { local prompt="$msg_ttys_menu_text" + local menu_list=" + '1 $msg_none' '$msg_none_ttys_desc' + '2 $msg_ibm_437_vga_default' 'cons25' + '3 $msg_iso_8859_1' 'cons25l1' + '4 $msg_iso_8859_2' 'cons25l2' + '5 $msg_iso_8859_7' 'cons25l7' + '6 $msg_koi8_r' 'cons25r' + '7 $msg_koi8_u' 'cons25u' + '8 $msg_us_ascii' 'cons25w' + " # END-QUOTE local hline="$hline_choose_a_terminal_type" local height width rows @@ -81,7 +75,7 @@ dialog_menu_main() \"\$DIALOG_BACKTITLE\" \ \"\$prompt\" \ \"\$hline\" \ - $TTY_MENU_LIST + $menu_list local menu_choice menu_choice=$( eval $DIALOG \ @@ -92,11 +86,19 @@ dialog_menu_main() --cancel-label \"\$msg_cancel\" \ --menu \"\$prompt\" \ $height $width $rows \ - $TTY_MENU_LIST \ + $menu_ist \ 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD ) local retval=$? f_dialog_menutag_store -s "$menu_choice" + + if [ $retval -eq $SUCCESS ]; then + local item + item=$( eval f_dialog_menutag2item \ + \"\$menu_choice\" $menu_list ) + f_dialog_menuitem_store "$item" + fi + return $retval } @@ -187,7 +189,7 @@ while :; do [ "$mtag" = "1 $msg_none" ] && break - consterm=$( eval f_dialog_menutag2item \"\$mtag\" $TTY_MENU_LIST ) + f_dialog_menuitem_fetch consterm err=$( ttys_set_type "$consterm" 2>&1 ) [ "$err" ] || break Modified: head/usr.sbin/bsdconfig/share/dialog.subr ============================================================================== --- head/usr.sbin/bsdconfig/share/dialog.subr Tue Jun 4 02:56:56 2013 (r251360) +++ head/usr.sbin/bsdconfig/share/dialog.subr Tue Jun 4 03:30:44 2013 (r251361) @@ -1770,6 +1770,44 @@ f_dialog_menutag_fetch() return $SUCCESS } +# f_dialog_menuitem_store [-s] $text +# +# Store the item from a dialog(1) menu (see f_dialog_menutag2item()) to be +# retrieved later by f_dialog_menuitem_fetch(). If the first argument is `-s', +# the text is sanitized before being stored. +# +f_dialog_menuitem_store() +{ + local sanitize= + [ "$1" = "-s" ] && sanitize=1 && shift 1 # -s + local text="$1" + + # Sanitize the menuitem before storing it if desired + [ "$sanitize" ] && f_dialog_data_sanitize text + + setvar DIALOG_MENUITEM_$$ "$text" +} + +# f_dialog_menuitem_fetch [$var_to_set] +# +# Obtain the menuitem chosen by the user from the most recently displayed +# dialog(1) menu (previously stored with f_dialog_menuitem_store() above). If +# $var_to_set is NULL or missing, output is printed to stdout (which is less +# recommended due to performance degradation; in a loop for example). +# +f_dialog_menuitem_fetch() +{ + local __var_to_set="$1" __cp + + debug= f_getvar DIALOG_MENUITEM_$$ "${__var_to_set:-__cp}" # get data + setvar DIALOG_MENUITEM_$$ "" # scrub memory in case data was sensitive + + # Return the data on standard-out if desired + [ "$__var_to_set" ] || echo "$__cp" + + return $SUCCESS +} + # f_dialog_default_store [-s] $text # # Store some text to be used later as the --default-item argument to dialog(1) Modified: head/usr.sbin/bsdconfig/share/packages/packages.subr ============================================================================== --- head/usr.sbin/bsdconfig/share/packages/packages.subr Tue Jun 4 02:56:56 2013 (r251360) +++ head/usr.sbin/bsdconfig/share/packages/packages.subr Tue Jun 4 03:30:44 2013 (r251361) @@ -360,9 +360,10 @@ f_package_index_get_page() # only matters if there are multiple pages; which is determined by the global # maximum $PACKAGE_MENU_PAGESIZE). # -# On success, if the user doesn't press ESC or choose Cancel, the environment -# variable $DIALOG_MENUITEM_$$ will hold the item associated with the chosen -# tag (accessible through f_dialog_menutag_fetch()). +# On success, if the user doesn't press ESC or choose Cancel, use +# f_dialog_menuitem_fetch() to populate a local variable with the item (not +# tag) corresponding to the user's selection. The tag portion of the user's +# selection is available through f_dialog_menutag_fetch(). # f_package_menu_select() { @@ -499,7 +500,7 @@ f_package_menu_select() local item item=$( eval f_dialog_menutag2item${SHOW_DESC:+_with_help} \ \"\$menu_choice\" $menu_list ) - setvar DIALOG_MENUITEM_$$ "$item" + f_dialog_menuitem_store "$item" fi return $retval @@ -739,7 +740,7 @@ f_package_config() # Treat any other selection as a package package="${menu_choice# }" # Trim leading space f_str2varname $package varpkg - f_getvar DIALOG_MENUITEM_$$ mark + f_dialog_menuitem_fetch mark mark="${mark#?}" mark="${mark%%\] *}" case "$mark" in Modified: head/usr.sbin/bsdconfig/startup/rcvar ============================================================================== --- head/usr.sbin/bsdconfig/startup/rcvar Tue Jun 4 02:56:56 2013 (r251360) +++ head/usr.sbin/bsdconfig/startup/rcvar Tue Jun 4 03:30:44 2013 (r251361) @@ -49,7 +49,6 @@ ipgm=$( f_index_menusel_keyword $BSDCFG_ # RCVAR_MAP= _RCVAR_MAP= -RCVAR_MENU_LIST= # # Options @@ -66,15 +65,12 @@ RCVAR_MENU_LIST= dialog_menu_main() { local prompt= - local hline="$hline_arrows_tab_enter" - local defaultitem= # Calculated below - - # NOTE: Using a GLOBAL here because caller will need this list to turn - # the menu tag into the menu item with f_dialog_menutag2item() - RCVAR_MENU_LIST=" + local menu_list=" 'X $msg_exit' '$msg_exit_this_menu' ${SHOW_DESC:+'$msg_exit_this_menu'} " # END-QUOTE + local hline="$hline_arrows_tab_enter" + local defaultitem= # Calculated below if [ ! "$_RCVAR_MAP" ]; then # Generate RCVAR_MAP of `rcvar dflt script desc ...' per-line @@ -84,7 +80,7 @@ dialog_menu_main() export _RCVAR_MAP=1 fi - RCVAR_MENU_LIST="$RCVAR_MENU_LIST $( + menu_list="$menu_list $( . "$RC_DEFAULTS" > /dev/null source_rc_confs > /dev/null for rcvar in $( echo "$RCVAR_MAP" | awk '{print $1}' ); do @@ -126,7 +122,7 @@ dialog_menu_main() }' )" - set -f # set noglob because descriptions in the $RCVAR_MENU_LIST may + set -f # set noglob because descriptions in the $menu_list may # contain `*' and get expanded by dialog(1). This prevents # dialog(1) from expanding wildcards in the help line. @@ -137,7 +133,7 @@ dialog_menu_main() \"\$DIALOG_BACKTITLE\" \ \"\$prompt\" \ \"\$hline\" \ - $RCVAR_MENU_LIST + $menu_list # Obtain default-item from previously stored selection f_dialog_default_fetch defaultitem @@ -154,13 +150,21 @@ dialog_menu_main() --default-item \"\$defaultitem\" \ --menu \"\$prompt\" \ $height $width $rows \ - $RCVAR_MENU_LIST \ + $menu_list \ 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD ) local retval=$? f_dialog_data_sanitize menu_choice f_dialog_menutag_store "$menu_choice" f_dialog_default_store "$menu_choice" + + if [ $retval -eq $SUCCESS ]; then + local item + item=$( eval f_dialog_menutag2item${SHOW_DESC:+_with_help} \ + \"\$menu_choice\" $menu_list ) + f_dialog_menuitem_store "$item" + fi + return $retval } @@ -193,10 +197,8 @@ while :; do case "$mtag" in "X $msg_exit") break ;; *) # Anything else is an rcvar to toggle - rcvar="${mtag# }" - value=$( eval f_dialog_menutag2item${SHOW_DESC:+_with_help} \ - \"\$mtag\" $RCVAR_MENU_LIST ) + f_dialog_menuitem_fetch value # Determine the new [toggled] value to use case "$value" in