Use f_shell_escape() instead of forking to awk. In this case, the

replacement comes with a great performance increase (as f_shell_escape()
uses the built-in based f_replaceall() which out-performs forking to
awk(1)). This should also improve readability slightly.
This commit is contained in:
Devin Teske 2013-06-04 03:47:21 +00:00
parent 97142e6ae7
commit 44392705fa
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=251364
3 changed files with 6 additions and 8 deletions

View File

@ -167,7 +167,6 @@ dialog_menu_main()
local defaultitem= # Calculated below
local hline=
local sanitize_awk="{ gsub(/'/, \"'\\\\''\"); print }"
local menuitem menu_title menu_help menu_selection index=2
for menuitem in $( cd $BSDCFG_LIBE && ls -d [0-9][0-9][0-9].* ); do
[ $index -lt ${#DIALOG_MENU_TAGS} ] || break
@ -185,8 +184,8 @@ dialog_menu_main()
menu_program="$menuitem/$menu_program"
esac
menu_title=$( echo "$menu_title" | awk "$sanitize_awk" )
menu_help=$( echo "$menu_help" | awk "$sanitize_awk" )
f_shell_escape "$menu_title" menu_title
f_shell_escape "$menu_help" menu_help
setvar "menu_program$tag" "$menu_program"
menu_list="$menu_list '$tag' '$menu_title' '$menu_help'"

View File

@ -598,12 +598,10 @@ f_device_menu()
done
[ "$devs" ] || return $FAILURE
local sanitize_awk="{ gsub(/'/, \"'\\\\''\"); print }"
local desc menu_list=
for dev in $devs; do
device_$dev get desc desc
desc=$( echo "$desc" | awk "$sanitize_awk" )
f_shell_escape "$desc" desc
menu_list="$menu_list '$dev' '$desc'"
done

View File

@ -32,6 +32,7 @@ BSDCFG_SHARE="/usr/share/bsdconfig"
. $BSDCFG_SHARE/common.subr || exit 1
f_dprintf "%s: loading includes..." variable.subr
f_include $BSDCFG_SHARE/dialog.subr
f_include $BSDCFG_SHARE/strings.subr
############################################################ GLOBALS
@ -130,12 +131,12 @@ f_variable_set_defaults()
#
f_dump_variables()
{
local err sanitize_awk="{ gsub(/'/, \"'\\\\''\"); print }"
local err
if ! err=$(
( for handle in $VARIABLES; do
f_getvar $handle var || continue
f_getvar $var value || continue
value=$( echo "$value" | awk "$sanitize_awk" )
f_shell_escape "$value" value
printf "%s='%s'\n" "$var" "$value"
done > "$VARIABLE_DUMPFILE" ) 2>&1
); then