From 05a0a04aeef566c571df1529e7d7bae5bd6a5aee Mon Sep 17 00:00:00 2001 From: Devin Teske Date: Fri, 7 Mar 2014 20:29:19 +0000 Subject: [PATCH] s/__number/__num/ for code clarify but more to prevent localization of __number if passed as the var_to_set argument. --- usr.sbin/bsdconfig/share/strings.subr | 30 +++++++++++++++++---------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/usr.sbin/bsdconfig/share/strings.subr b/usr.sbin/bsdconfig/share/strings.subr index 1bb42e3620db..55764689de12 100644 --- a/usr.sbin/bsdconfig/share/strings.subr +++ b/usr.sbin/bsdconfig/share/strings.subr @@ -33,6 +33,12 @@ BSDCFG_SHARE="/usr/share/bsdconfig" ############################################################ GLOBALS +# +# A Literal newline (for use with f_replace_all(), or IFS, or whatever) +# +NL=" +" # END-QUOTE + # # Valid characters that can appear in an sh(1) variable name # @@ -369,14 +375,16 @@ f_shell_unescape() f_expand_number() { local __string="$1" __var_to_set="$2" - local __cp __number __bshift __maxinput + local __cp __num __bshift __maxinput - # Remove any leading non-digits and store numbers (sans suffix) + # Remove any leading non-digits __string="${__string#${__string%%[0-9]*}}" - __number="${__string%%[!0-9]*}" + + # Store the numbers (no trailing suffix) + __num="${__string%%[!0-9]*}" # Produce `-1' if string didn't contain any digits - if [ ! "$__number" ]; then + if [ ! "$__num" ]; then if [ "$__var_to_set" ]; then setvar "$__var_to_set" -1 else @@ -386,7 +394,7 @@ f_expand_number() fi # Remove all the leading numbers from the string to get at the prefix - __string="${__string#"$__number"}" + __string="${__string#"$__num"}" # # Test for invalid prefix (and determine bitshift length) @@ -394,9 +402,9 @@ f_expand_number() case "$__string" in ""|[[:space:]]*) # Shortcut if [ "$__var_to_set" ]; then - setvar "$__var_to_set" $__number + setvar "$__var_to_set" $__num else - echo $__number + echo $__num fi return $SUCCESS ;; [Kk]*) __bshift=10 ;; @@ -417,7 +425,7 @@ f_expand_number() # Determine if the wheels fall off __maxinput=$(( 0x7fffffffffffffff >> $__bshift )) - if [ $__number -gt $__maxinput ]; then + if [ $__num -gt $__maxinput ]; then # Input (before expanding) would exceed 64-bit signed int if [ "$__var_to_set" ]; then setvar "$__var_to_set" -1 @@ -428,11 +436,11 @@ f_expand_number() fi # Shift the number out and produce it - __number=$(( $__number << $__bshift )) + __num=$(( $__num << $__bshift )) if [ "$__var_to_set" ]; then - setvar "$__var_to_set" $__number + setvar "$__var_to_set" $__num else - echo $__number + echo $__num fi }