Date: Tue, 4 Jun 2013 03:47:21 +0000 (UTC) From: Devin Teske <dteske@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r251364 - in head/usr.sbin/bsdconfig: . share Message-ID: <201306040347.r543lL0G008524@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: dteske Date: Tue Jun 4 03:47:21 2013 New Revision: 251364 URL: http://svnweb.freebsd.org/changeset/base/251364 Log: 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. Modified: head/usr.sbin/bsdconfig/bsdconfig head/usr.sbin/bsdconfig/share/device.subr head/usr.sbin/bsdconfig/share/variable.subr Modified: head/usr.sbin/bsdconfig/bsdconfig ============================================================================== --- head/usr.sbin/bsdconfig/bsdconfig Tue Jun 4 03:38:16 2013 (r251363) +++ head/usr.sbin/bsdconfig/bsdconfig Tue Jun 4 03:47:21 2013 (r251364) @@ -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'" Modified: head/usr.sbin/bsdconfig/share/device.subr ============================================================================== --- head/usr.sbin/bsdconfig/share/device.subr Tue Jun 4 03:38:16 2013 (r251363) +++ head/usr.sbin/bsdconfig/share/device.subr Tue Jun 4 03:47:21 2013 (r251364) @@ -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 Modified: head/usr.sbin/bsdconfig/share/variable.subr ============================================================================== --- head/usr.sbin/bsdconfig/share/variable.subr Tue Jun 4 03:38:16 2013 (r251363) +++ head/usr.sbin/bsdconfig/share/variable.subr Tue Jun 4 03:47:21 2013 (r251364) @@ -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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201306040347.r543lL0G008524>