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 Jul 28, 2022
1 parent 6aa12c8 commit 2b55aa1
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 19 deletions.
2 changes: 1 addition & 1 deletion ble-color.sh
Expand Up @@ -132,7 +132,7 @@ 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
2 changes: 1 addition & 1 deletion ble-core.sh
Expand Up @@ -914,7 +914,7 @@ function ble/util/sleep/.check-builtin-sleep {
_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
14 changes: 7 additions & 7 deletions ble-decode.sh
Expand Up @@ -397,8 +397,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 kcode=$((param2&ble_decode_MaskChar))
ble-decode-char/csi/.modify-kcode "$param1"
csistat=$kcode
Expand All @@ -407,8 +407,8 @@ function ble-decode-char/csi/.decode {

if rex='^([1-9][0-9]*)(;([1-9][0-9]*))?$' && [[ $_ble_decode_csi_args =~ $rex ]]; then
# "CSI <kcode> ; <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]}))
kcode=${_ble_decode_csimap_tilde[param1]}
if [[ $kcode ]]; then
ble-decode-char/csi/.modify-kcode "$param3"
Expand All @@ -419,8 +419,8 @@ function ble-decode-char/csi/.decode {
elif ((char==94||char==64)); then
if rex='^[1-9][0-9]*$' && [[ $_ble_decode_csi_args =~ $rex ]]; then
# rxvt "CSI <kcode> ^", "CSI <kcode> @" 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]}))
kcode=${_ble_decode_csimap_tilde[param1]}
if [[ $kcode ]]; then
((kcode|=ble_decode_Ctrl,
Expand All @@ -436,7 +436,7 @@ function ble-decode-char/csi/.decode {
kcode=${_ble_decode_csimap_alpha[char]}
if [[ $kcode ]]; then
if rex='^(1?|1;([1-9][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-kcode "$param2"
csistat=$kcode
return
Expand Down
8 changes: 4 additions & 4 deletions ble-edit.sh
Expand Up @@ -656,7 +656,7 @@ function ble-edit/draw/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 Expand Up @@ -2192,11 +2192,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 @@ -5902,7 +5902,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
8 changes: 4 additions & 4 deletions keymap/vi.sh
Expand Up @@ -617,7 +617,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 @@ -5036,9 +5036,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 @@ -6420,7 +6420,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 test/benchmark/benchmark.sh
Expand Up @@ -23,7 +23,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 All @@ -50,7 +50,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 2b55aa1

Please sign in to comment.