diff options
author | dteske <dteske@FreeBSD.org> | 2013-06-04 03:47:21 +0000 |
---|---|---|
committer | dteske <dteske@FreeBSD.org> | 2013-06-04 03:47:21 +0000 |
commit | 209fc7d0b7dc1305b123f79d4ae1927069065686 (patch) | |
tree | 077183a1b1930df204266f948d2730385bcc6bb6 | |
parent | 3f33ca83457c3011ee463ecd9a63ba4ccfec4ad5 (diff) | |
download | FreeBSD-src-209fc7d0b7dc1305b123f79d4ae1927069065686.zip FreeBSD-src-209fc7d0b7dc1305b123f79d4ae1927069065686.tar.gz |
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.
-rwxr-xr-x | usr.sbin/bsdconfig/bsdconfig | 5 | ||||
-rw-r--r-- | usr.sbin/bsdconfig/share/device.subr | 4 | ||||
-rw-r--r-- | usr.sbin/bsdconfig/share/variable.subr | 5 |
3 files changed, 6 insertions, 8 deletions
diff --git a/usr.sbin/bsdconfig/bsdconfig b/usr.sbin/bsdconfig/bsdconfig index cecedb3..340beb8 100755 --- a/usr.sbin/bsdconfig/bsdconfig +++ b/usr.sbin/bsdconfig/bsdconfig @@ -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'" diff --git a/usr.sbin/bsdconfig/share/device.subr b/usr.sbin/bsdconfig/share/device.subr index f724af4..28e3ee8 100644 --- a/usr.sbin/bsdconfig/share/device.subr +++ b/usr.sbin/bsdconfig/share/device.subr @@ -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 diff --git a/usr.sbin/bsdconfig/share/variable.subr b/usr.sbin/bsdconfig/share/variable.subr index 079c564..879eece 100644 --- a/usr.sbin/bsdconfig/share/variable.subr +++ b/usr.sbin/bsdconfig/share/variable.subr @@ -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 |