Skip to content

Commit

Permalink
global: work around the arithmetic syntax error of "10#" in Bash-5.1
Browse files Browse the repository at this point in the history
  • Loading branch information
akinomyoga committed Jun 28, 2022
1 parent 7bd03a5 commit b321b57
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 37 deletions.
8 changes: 4 additions & 4 deletions keymap/vi.sh
Expand Up @@ -665,7 +665,7 @@ function ble/keymap:vi/get-arg {
if [[ ! $_ble_edit_arg && ! $_ble_keymap_vi_oparg ]]; then
ARG=$default_value
else
ARG=$((10#${_ble_edit_arg:-1}*10#${_ble_keymap_vi_oparg:-1}))
ARG=$((10#0${_ble_edit_arg:-1}*10#0${_ble_keymap_vi_oparg:-1}))
fi
ble/keymap:vi/clear-arg
}
Expand Down Expand Up @@ -5648,9 +5648,9 @@ function ble/widget/vi_nmap/increment.impl {
local abs=${number#-}
if [[ $abs == 0?* ]]; then
if [[ $number == -* ]]; then
number=-$((10#$abs))
number=-$((10#0$abs))
else
number=$((10#$abs))
number=$((10#0$abs))
fi
fi

Expand Down Expand Up @@ -7152,7 +7152,7 @@ function ble/widget/vi_xmap/increment.impl {
local rematch1=${BASH_REMATCH[1]}
local rematch2=${BASH_REMATCH[2]}
local offset=${#rematch1} length=${#rematch2}
local number=$((10#$rematch2))
local number=$((10#0$rematch2))
[[ $rematch1 == *- ]] && ((number=-number,offset--,length++))

# 新しい数
Expand Down
4 changes: 2 additions & 2 deletions lib/core-syntax.sh
Expand Up @@ -2274,8 +2274,8 @@ function ble/syntax:bash/check-brace-expansion {
# リダイレクトで複数語に展開される時はエラー
local lhs=${rematch1::len2} rhs=${rematch1:len2+2}
if [[ $rematch2 ]]; then
local lhs1=$((10#${lhs#[-+]})); [[ $lhs == -* ]] && ((lhs1=-lhs1))
local rhs1=$((10#${rhs#[-+]})); [[ $rhs == -* ]] && ((rhs1=-rhs1))
local lhs1=$((10#0${lhs#[-+]})); [[ $lhs == -* ]] && ((lhs1=-lhs1))
local rhs1=$((10#0${rhs#[-+]})); [[ $rhs == -* ]] && ((rhs1=-rhs1))
lhs=$lhs1 rhs=$rhs1
fi
[[ $lhs != "$rhs" ]] && ((attr=ATTR_ERR))
Expand Down
2 changes: 1 addition & 1 deletion src/canvas.sh
Expand Up @@ -657,7 +657,7 @@ function ble/canvas/trace/.process-csi-sequence {
return ;;
([ABCDEFGIZ\`ade])
local arg=0
[[ $param =~ ^[0-9]+$ ]] && ((arg=10#$param))
[[ $param =~ ^[0-9]+$ ]] && ((arg=10#0$param))
((arg==0&&(arg=1)))

local x0=$x y0=$y
Expand Down
10 changes: 5 additions & 5 deletions src/color.sh
Expand Up @@ -179,7 +179,7 @@ function ble/color/gspec2sgr {
function ble/color/.name2color {
local colorName=$1
if [[ ! ${colorName//[0-9]} ]]; then
((ret=10#$colorName&255))
((ret=10#0$colorName&255))
else
case "$colorName" in
(black) ret=0 ;;
Expand Down Expand Up @@ -207,7 +207,7 @@ function ble/color/.name2color {
fi
}
function ble/color/.color2name {
((ret=(10#$1&255)))
((ret=(10#0$1&255)))
case $ret in
(0) ret=black ;;
(1) ret=brown ;;
Expand Down Expand Up @@ -347,10 +347,10 @@ function ble/color/read-sgrspec/.arg-next {
fi

if ((j<${#fields[*]})); then
((_ret=10#${fields[j++]}))
((_ret=10#0${fields[j++]}))
else
((i++))
((_ret=10#${specs[i]%%:*}))
((_ret=10#0${specs[i]%%:*}))
fi

(($_var=_ret))
Expand All @@ -365,7 +365,7 @@ function ble/color/read-sgrspec {
for ((i=0,iN=${#specs[@]};i<iN;i++)); do
local spec=${specs[i]} fields
ble/string#split fields : "$spec"
local arg=$((10#${fields[0]}))
local arg=$((10#0${fields[0]}))
if ((arg==0)); then
g=0
continue
Expand Down
20 changes: 10 additions & 10 deletions src/decode.sh
Expand Up @@ -564,8 +564,8 @@ function ble-decode-char/csi/.decode {
if ((char==126)); then
if rex='^>?27;([0-9]+);?([0-9]+)$' && [[ $_ble_decode_csi_args =~ $rex ]]; then
# xterm "CSI 2 7 ; <mod> ; <char> ~" sequences
local param1=$((10#${BASH_REMATCH[1]}))
local param2=$((10#${BASH_REMATCH[2]}))
local param1=$((10#0${BASH_REMATCH[1]}))
local param2=$((10#0${BASH_REMATCH[2]}))
local key=$((param2&_ble_decode_MaskChar))
ble-decode-char/csi/.modify-key "$param1"
csistat=$key
Expand All @@ -574,8 +574,8 @@ function ble-decode-char/csi/.decode {

if rex='^>?([0-9]+)(;([0-9]+))?$' && [[ $_ble_decode_csi_args =~ $rex ]]; then
# "CSI <key> ; <mod> ~" sequences
local param1=$((10#${BASH_REMATCH[1]}))
local param3=$((10#${BASH_REMATCH[3]}))
local param1=$((10#0${BASH_REMATCH[1]}))
local param3=$((10#0${BASH_REMATCH[3]}))
key=${_ble_decode_csimap_tilde[param1]}
if [[ $key ]]; then
ble-decode-char/csi/.modify-key "$param3"
Expand All @@ -589,7 +589,7 @@ function ble-decode-char/csi/.decode {
# Note: 実は "CSI 1 ; mod u" が kp5 とする端末がある事に注意する。
local rematch1=${BASH_REMATCH[1]}
if [[ $rematch1 != 1 ]]; then
local key=$((10#$rematch1)) mods=$((10#${BASH_REMATCH:${#rematch1}+1}))
local key=$((10#0$rematch1)) mods=$((10#0${BASH_REMATCH:${#rematch1}+1}))
ble-decode-char/csi/.modify-key "$mods"
csistat=$key
fi
Expand All @@ -598,8 +598,8 @@ function ble-decode-char/csi/.decode {
elif ((char==94||char==64)); then # ^, @
if rex='^[0-9]+$' && [[ $_ble_decode_csi_args =~ $rex ]]; then
# rxvt "CSI <key> ^", "CSI <key> @" sequences
local param1=$((10#${BASH_REMATCH[1]}))
local param3=$((10#${BASH_REMATCH[3]}))
local param1=$((10#0${BASH_REMATCH[1]}))
local param3=$((10#0${BASH_REMATCH[3]}))
key=${_ble_decode_csimap_tilde[param1]}
if [[ $key ]]; then
((key|=_ble_decode_Ctrl,
Expand All @@ -625,8 +625,8 @@ function ble-decode-char/csi/.decode {
if rex='^([0-9]+);([0-9]+)$'; [[ $_ble_decode_csi_args =~ $rex ]]; then
# DSR(6) に対する応答 CPR "CSI Pn ; Pn R"
# Note: Poderosa は DSR(Pn;Pn) "CSI Pn ; Pn n" で返す。
local param1=$((10#${BASH_REMATCH[1]}))
local param2=$((10#${BASH_REMATCH[2]}))
local param1=$((10#0${BASH_REMATCH[1]}))
local param2=$((10#0${BASH_REMATCH[2]}))
ble/term/CPR/notify "$param1" "$param2"
csistat=$_ble_decode_KCODE_IGNORE
return 0
Expand All @@ -637,7 +637,7 @@ function ble-decode-char/csi/.decode {
key=${_ble_decode_csimap_alpha[char]}
if [[ $key ]]; then
if rex='^(1?|>?1;([0-9]+))$' && [[ $_ble_decode_csi_args =~ $rex ]]; then
local param2=$((10#${BASH_REMATCH[2]}))
local param2=$((10#0${BASH_REMATCH[2]}))
ble-decode-char/csi/.modify-key "$param2"
csistat=$key
return 0
Expand Down
10 changes: 5 additions & 5 deletions src/edit.sh
Expand Up @@ -1110,11 +1110,11 @@ function ble-edit/content/get-arg {
if [[ $_ble_edit_arg == - ]]; then
arg=-1
else
arg=$((-10#${_ble_edit_arg#-}))
arg=$((-10#0${_ble_edit_arg#-}))
fi
else
if [[ $_ble_edit_arg ]]; then
arg=$((10#$_ble_edit_arg))
arg=$((10#0$_ble_edit_arg))
else
arg=$default_value
fi
Expand Down Expand Up @@ -1211,7 +1211,7 @@ function ble-edit/eval-IGNOREEOF {

if [[ $value && ! ${value//[0-9]} ]]; then
# 正の整数は十進数で解釈
ret=$((10#$value))
ret=$((10#0$value))
else
# 負の整数、空文字列、その他
ret=10
Expand Down Expand Up @@ -5278,7 +5278,7 @@ function ble-edit/isearch/.shift-backward-references {
local buff=
while [[ $needle =~ $rex ]]; do
local mlen=${#BASH_REMATCH}
buff=$buff${BASH_REMATCH::mlen-1}$((10#${BASH_REMATCH:mlen-1}+1))
buff=$buff${BASH_REMATCH::mlen-1}$((10#0${BASH_REMATCH:mlen-1}+1))
needle=${needle:mlen}
done
needle=$buff$needle
Expand Down Expand Up @@ -6702,7 +6702,7 @@ function ble/builtin/read/.loop {
if [[ $opt_timeout == *.* ]]; then
local mantissa=${opt_timeout%%.*}
local fraction=${opt_timeout##*.}000
((timeout=mantissa*1000+10#${fraction::3}))
((timeout=mantissa*1000+10#0${fraction::3}))
else
((timeout=opt_timeout*1000))
fi
Expand Down
16 changes: 8 additions & 8 deletions src/util.sh
Expand Up @@ -1608,7 +1608,7 @@ function ble/util/msleep/.check-sleep-decimal-support {
_ble_util_msleep_delay=2000 # [usec]
function ble/util/msleep/.core {
local sec=${1%%.*}
((10#${1##*.}&&sec++)) # 小数部分は切り上げ
((10#0${1##*.}&&sec++)) # 小数部分は切り上げ
ble/bin/sleep "$sec"
}
function ble/util/msleep {
Expand Down Expand Up @@ -1721,7 +1721,7 @@ function ble/util/sleep {
local msec=$((${1%%.*}*1000))
if [[ $1 == *.* ]]; then
frac=${1##*.}000
((msec+=10#${frac::3}))
((msec+=10#0${frac::3}))
fi
ble/util/msleep "$msec"
}
Expand Down Expand Up @@ -2440,15 +2440,15 @@ function ble/util/clock/.initialize {
local LC_ALL= LC_NUMERIC=C
if ((_ble_bash>=50000)) && [[ $EPOCHREALTIME == *.???* ]]; then
# implementation with EPOCHREALTIME
_ble_util_clock_base=$((10#${EPOCHREALTIME%.*}))
_ble_util_clock_base=$((10#0${EPOCHREALTIME%.*}))
_ble_util_clock_reso=1
_ble_util_clock_type=EPOCHREALTIME
function ble/util/clock {
local LC_ALL= LC_NUMERIC=C
local now=$EPOCHREALTIME
local integral=$((10#${now%%.*}-_ble_util_clock_base))
local integral=$((10#0${now%%.*}-_ble_util_clock_base))
local mantissa=${now#*.}000; mantissa=${mantissa::3}
((ret=integral*1000+10#$mantissa))
((ret=integral*1000+10#0$mantissa))
}
ble/function#suppress-stderr ble/util/clock # locale
elif [[ -r /proc/uptime ]] && {
Expand All @@ -2457,16 +2457,16 @@ function ble/util/clock/.initialize {
ble/string#split-words uptime "$uptime"
[[ $uptime == *.* ]]; }; then
# implementation with /proc/uptime
_ble_util_clock_base=$((10#${uptime%.*}))
_ble_util_clock_base=$((10#0${uptime%.*}))
_ble_util_clock_reso=10
_ble_util_clock_type=uptime
function ble/util/clock {
local now
ble/util/readfile now /proc/uptime
ble/string#split-words now "$now"
local integral=$((10#${now%%.*}-_ble_util_clock_base))
local integral=$((10#0${now%%.*}-_ble_util_clock_base))
local fraction=${now#*.}000; fraction=${fraction::3}
((ret=integral*1000+10#$fraction))
((ret=integral*1000+10#0$fraction))
}
elif ((_ble_bash>=40200)); then
printf -v _ble_util_clock_base '%(%s)T'
Expand Down
4 changes: 2 additions & 2 deletions test/benchmark/benchmark.sh
Expand Up @@ -30,7 +30,7 @@ if [[ $ZSH_VERSION ]]; then
fi
m=${m:-0} ms=${ms}000; ms=${ms:0:3}

((utot=((10#$m*60+10#$s)*1000+10#$ms)*1000,
((utot=((10#0$m*60+10#0$s)*1000+10#0$ms)*1000,
usec=utot/n))
return 0
else
Expand Down Expand Up @@ -70,7 +70,7 @@ else
[[ $result =~ $rex ]] || return 1
local s=${BASH_REMATCH[1]}
local ms=${BASH_REMATCH[3]}000; ms=${ms::3}
((utot=(10#$s*1000+10#$ms)*1000,usec=utot1/n))
((utot=(10#0$s*1000+10#0$ms)*1000,usec=utot1/n))
return 0
}
fi
Expand Down

0 comments on commit b321b57

Please sign in to comment.