diff options
author | dteske <dteske@FreeBSD.org> | 2013-06-01 23:58:44 +0000 |
---|---|---|
committer | dteske <dteske@FreeBSD.org> | 2013-06-01 23:58:44 +0000 |
commit | 9e2431c34dc087e0ff7bb1a5ae076865b37fd54e (patch) | |
tree | aff553824a76a9a13ba24f03ece60b3c50def184 /usr.sbin/bsdconfig/networking | |
parent | 2201176ef968245558d98feec1de87cfdca36bf4 (diff) | |
download | FreeBSD-src-9e2431c34dc087e0ff7bb1a5ae076865b37fd54e.zip FreeBSD-src-9e2431c34dc087e0ff7bb1a5ae076865b37fd54e.tar.gz |
Improve portion of the dialog(1) API in dialog.subr responsible for
retrieving stored data (for the --menu, --calendar, --timebox, --checklist,
and --radiolist widgets).
When we (Ron McDowell and I) developed the first version of bsdconfig, it
used temporary files to store responses from dialog(1). That hasn't been
true for some very long time, so the need to always store the return status
of dialog(1) and then call some function to clean-up is long-deprecated. The
function that used to do the clean-up was f_dialog_menutag().
We really don't need f_dialog_menutag() for its originally designed purpose,
as all dialog invocations (even when in a sub-shell) do not use temporary
files anymore.
However, we do need to keep f_dialog_menutag() around because it still fills
the need of being able to abstract the procedure for fetching stored data
provided by functions that display the aforementioned widgets.
In re-designing f_dialog_menutag(), four important changes are made:
1. Rename f_dialog_menutag() to f_dialog_menutag_fetch()
2. Introduce the new first-argument of $var_to_set to reduce number of forks
3. Create a corresponding f_dialog_menutag_store() to abstract the storage
4. Offload the sanitization to a new function, f_dialog_data_sanitize()
NOTE: That last one is important. Not all functions need to store their data
for later fetching, meanwhile every invocation of dialog should be sanitized
(as we learned early-on in the i18n-effort -- underlying libraries will spit
warnings to stderr for bad values of $LANG and since dialog outputs its
responses to stderr, we need to sanitize every response of these warnings).
These changes greatly improve readbaility and also improve performance by
reducing unnecessary forking.
Diffstat (limited to 'usr.sbin/bsdconfig/networking')
-rwxr-xr-x | usr.sbin/bsdconfig/networking/devices | 7 | ||||
-rwxr-xr-x | usr.sbin/bsdconfig/networking/networking | 16 | ||||
-rw-r--r-- | usr.sbin/bsdconfig/networking/share/device.subr | 14 | ||||
-rw-r--r-- | usr.sbin/bsdconfig/networking/share/media.subr | 9 | ||||
-rw-r--r-- | usr.sbin/bsdconfig/networking/share/resolv.subr | 9 |
5 files changed, 23 insertions, 32 deletions
diff --git a/usr.sbin/bsdconfig/networking/devices b/usr.sbin/bsdconfig/networking/devices index 11614f0..2ed9af80 100755 --- a/usr.sbin/bsdconfig/networking/devices +++ b/usr.sbin/bsdconfig/networking/devices @@ -73,13 +73,10 @@ f_mustberoot_init # defaultitem="" while :; do - f_dialog_menu_netdev "$defaultitem" - retval=$? - interface=$( f_dialog_menutag ) + f_dialog_menu_netdev "$defaultitem" || break + f_dialog_menutag_fetch interface defaultitem="$interface" - [ $retval -eq 0 ] || break - # # dialog_menu_netdev adds an asterisk (*) to the right of the # device name if the interface is active. Remove the asterisk diff --git a/usr.sbin/bsdconfig/networking/networking b/usr.sbin/bsdconfig/networking/networking index 5f69ccb..13d5018 100755 --- a/usr.sbin/bsdconfig/networking/networking +++ b/usr.sbin/bsdconfig/networking/networking @@ -67,8 +67,8 @@ dialog_menu_main() \"\$hline\" \ $menu_list - local dialog_menu - dialog_menu=$( eval $DIALOG \ + local menu_choice + menu_choice=$( eval $DIALOG \ --title \"\$DIALOG_TITLE\" \ --backtitle \"\$DIALOG_BACKTITLE\" \ --hline \"\$hline\" \ @@ -81,8 +81,9 @@ dialog_menu_main() 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD ) local retval=$? - setvar DEFAULTITEM_$$ "$dialog_menu" - setvar DIALOG_MENU_$$ "$dialog_menu" + f_dialog_data_sanitize menu_choice + f_dialog_menutag_store "$menu_choice" + setvar DEFAULTITEM_$$ "$menu_choice" return $retval } @@ -112,11 +113,8 @@ f_mustberoot_init # Launch application main menu # while :; do - dialog_menu_main - retval=$? - mtag=$( f_dialog_menutag ) - - [ $retval -eq 0 ] || f_die + dialog_menu_main || f_die + f_dialog_menutag_fetch mtag case "$mtag" in X) # Exit diff --git a/usr.sbin/bsdconfig/networking/share/device.subr b/usr.sbin/bsdconfig/networking/share/device.subr index f248c39..069086a 100644 --- a/usr.sbin/bsdconfig/networking/share/device.subr +++ b/usr.sbin/bsdconfig/networking/share/device.subr @@ -151,8 +151,8 @@ f_dialog_menu_netdev() \"\$prompt\" \ \"\$hline\" \ $interfaces - local dialog_menu - dialog_menu=$( eval $DIALOG \ + local menu_choice + menu_choice=$( eval $DIALOG \ --title \"\$DIALOG_TITLE\" \ --backtitle \"\$DIALOG_BACKTITLE\" \ --hline \"\$hline\" \ @@ -165,7 +165,7 @@ f_dialog_menu_netdev() 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD ) local retval=$? - setvar DIALOG_MENU_$$ "$dialog_menu" + f_dialog_menutag_store -s "$menu_choice" return $retval } @@ -224,8 +224,8 @@ f_dialog_menu_netdev_edit() \"\$prompt\" \ \"\$hline\" \ $menu_list - local dialog_menu - dialog_menu=$( eval $DIALOG \ + local tag + tag=$( eval $DIALOG \ --title \"\$DIALOG_TITLE\" \ --backtitle \"\$DIALOG_BACKTITLE\" \ --hline \"\$hline\" \ @@ -240,10 +240,8 @@ f_dialog_menu_netdev_edit() $menu_list \ 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD ) - local retval=$? - setvar DIALOG_MENU_$$ "$dialog_menu" - local tag="$( f_dialog_menutag )" + f_dialog_data_sanitize tag if [ $retval -eq 2 ]; then # The Help button was pressed diff --git a/usr.sbin/bsdconfig/networking/share/media.subr b/usr.sbin/bsdconfig/networking/share/media.subr index e0e71e7..0ed7637 100644 --- a/usr.sbin/bsdconfig/networking/share/media.subr +++ b/usr.sbin/bsdconfig/networking/share/media.subr @@ -205,8 +205,8 @@ f_dialog_menu_media_options() local hline="$hline_arrows_tab_enter" - local dialog_menu - dialog_menu=$( eval $DIALOG \ + local tag + tag=$( eval $DIALOG \ --title \"\$DIALOG_TITLE\" \ --backtitle \"\$DIALOG_BACKTITLE\" \ --hline \"\$hline\" \ @@ -216,11 +216,10 @@ f_dialog_menu_media_options() $supported_media \ 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD ) - local retval=$? - setvar DIALOG_MENU_$$ "$dialog_menu" + f_dialog_data_sanitize tag + if [ $retval -eq $SUCCESS ]; then - local tag="$( f_dialog_menutag )" options=$( eval f_dialog_menutag2item \"\$tag\" \ $supported_media ) [ "$options" = "$opt_none" ] && options= diff --git a/usr.sbin/bsdconfig/networking/share/resolv.subr b/usr.sbin/bsdconfig/networking/share/resolv.subr index e439d38..0793c81 100644 --- a/usr.sbin/bsdconfig/networking/share/resolv.subr +++ b/usr.sbin/bsdconfig/networking/share/resolv.subr @@ -435,8 +435,8 @@ f_dialog_menu_nameservers() \"\$prompt\" \ \"\$hline\" \ $menu_list - local dialog_menu - dialog_menu=$( eval $DIALOG \ + local tag + tag=$( eval $DIALOG \ --title \"\$DIALOG_TITLE\" \ --backtitle \"\$DIALOG_BACKTITLE\" \ --hline \"\$hline\" \ @@ -448,10 +448,8 @@ f_dialog_menu_nameservers() $menu_list \ 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD ) - local retval=$? - setvar DIALOG_MENU_$$ "$dialog_menu" - local tag="$( f_dialog_menutag )" ns="" + f_dialog_data_sanitize tag # Return if "Cancel" was chosen (-1) or ESC was pressed (255) if [ $retval -ne $SUCCESS ]; then @@ -467,6 +465,7 @@ f_dialog_menu_nameservers() f_dialog_input_nameserver ;; *) + local n ns n=$( eval f_dialog_menutag2index \"\$tag\" $menu_list ) ns=$( eval f_dialog_menutag2item \"\$tag\" $menu_list ) f_dialog_input_nameserver $(( $n - 2 )) "$ns" |