s/__number/__num/ for code clarify but more to prevent localization of
__number if passed as the var_to_set argument.
This commit is contained in:
parent
4bed406fb7
commit
05a0a04aee
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=262901
@ -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
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user