Skip to content

Commit

Permalink
global: suppress missing locale errors
Browse files Browse the repository at this point in the history
  • Loading branch information
akinomyoga committed May 18, 2021
1 parent cc8ca96 commit b52a798
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 30 deletions.
2 changes: 1 addition & 1 deletion lib/core-syntax.sh
Expand Up @@ -2756,7 +2756,7 @@ function ble/syntax:bash/ctx-command/check-word-end {
local word_expanded=$word
local type; ble/util/type type "$word"
if [[ $type == alias ]]; then
local data; ble/util/assign data 'LANG=C alias "$word"' &>/dev/null
local data; ble/util/assign data 'LC_ALL=C alias "$word"' &>/dev/null
[[ $data == 'alias '*=* ]] &&
eval "word_expanded=${data#alias *=}"
fi
Expand Down
24 changes: 14 additions & 10 deletions src/canvas.sh
Expand Up @@ -824,6 +824,10 @@ function ble/canvas/trace/.process-esc-sequence {
function ble/canvas/trace/.impl {
local text=$1 opts=$2

# cygwin では LC_COLLATE=C にしないと
# 正規表現の range expression が期待通りに動かない。
local LC_ALL= LC_COLLATE=C

# Note: 文字符号化方式によっては対応する文字が存在しない可能性がある。
# その時は st='\u009C' になるはず。2文字以上のとき変換に失敗したと見做す。
local ret
Expand Down Expand Up @@ -1008,17 +1012,13 @@ function ble/canvas/trace/.impl {
[[ $opt_measure ]] && ((y2++))
}
function ble/canvas/trace.draw {
# cygwin では LC_COLLATE=C にしないと
# 正規表現の range expression が期待通りに動かない。
local LC_ALL= LC_COLLATE=C
ble/canvas/trace/.impl "$@"
} 2>/dev/null # Note: suppress LC_COLLATE errors #D1205
ble/canvas/trace/.impl "$@" 2>/dev/null # Note: suppress LC_COLLATE errors #D1205 #D1341 #D1440
}
function ble/canvas/trace {
local LC_ALL= LC_COLLATE=C
local -a DRAW_BUFF=()
ble/canvas/trace/.impl "$@"
ble/canvas/trace/.impl "$@" 2>/dev/null # Note: suppress LC_COLLATE errors #D1205 #D1341 #D1440
ble/canvas/sflush.draw # -> ret
} 2>/dev/null # Note: suppress LC_COLLATE errors #D1205, #D1341
}

#------------------------------------------------------------------------------
# ble/canvas/construct-text
Expand Down Expand Up @@ -1108,7 +1108,9 @@ function ble/canvas/trace-text/.put-nl-if-eol {
## @exit
## 指定した範囲に文字列が収まった時に成功します。
function ble/canvas/trace-text {
local out= LC_ALL= LC_COLLATE=C glob='*[! -~]*'
local LC_ALL= LC_COLLATE=C
local out= glob='*[! -~]*'

local opts=$2 flag_overflow=
[[ :$opts: == *:external-sgr:* ]] ||
local sgr0=$_ble_term_sgr0 sgr1=$_ble_term_rev
Expand Down Expand Up @@ -1152,7 +1154,9 @@ function ble/canvas/trace-text {
# 収まったかどうか
((y>=lines)) && flag_overflow=1
[[ ! $flag_overflow ]]
} 2>/dev/null # Note: suppress LC_COLLATE errors #D1205
}
# Note: suppress LC_COLLATE errors #D1205 #D1262 #1341 #D1440
ble/function#suppress-stderr ble/canvas/trace-text

#------------------------------------------------------------------------------
# ble/textmap
Expand Down
4 changes: 3 additions & 1 deletion src/color.sh
Expand Up @@ -792,7 +792,9 @@ function ble/highlight/layer:plain/update {

PREV_BUFF=_ble_highlight_layer_plain_buff
((PREV_UMIN=DMIN,PREV_UMAX=DMAX))
} 2>/dev/null # Note: suppress LC_COLLATE errors #D1205
}
# Note: suppress LC_COLLATE errors #D1205 #D1440
ble/function#suppress-stderr ble/highlight/layer:plain/update

## 関数 ble/highlight/layer:plain/getg index
## @var[out] g
Expand Down
66 changes: 48 additions & 18 deletions src/util.sh
Expand Up @@ -568,7 +568,7 @@ function ble/string#last-index-of {
## @var[out] ret
_ble_util_string_lower_list=abcdefghijklmnopqrstuvwxyz
_ble_util_string_upper_list=ABCDEFGHIJKLMNOPQRSTUVWXYZ
function ble/string#toggle-case {
function ble/string#toggle-case.impl {
local LC_ALL= LC_COLLATE=C
local text=$* ch i
local -a buff
Expand All @@ -584,7 +584,10 @@ function ble/string#toggle-case {
ble/array#push buff "$ch"
done
IFS= builtin eval 'ret="${buff[*]-}"'
} 2>/dev/null
}
function ble/string#toggle-case {
ble/string#toggle-case.impl "$@" 2>/dev/null # suppress locale error #D1440
}
## 関数 ble/string#tolower text...
## 関数 ble/string#toupper text...
## @var[out] ret
Expand All @@ -593,6 +596,7 @@ if ((_ble_bash>=40000)); then
function ble/string#toupper { ret="${*^^}"; }
else
function ble/string#tolower.impl {
local LC_ALL= LC_COLLATE=C
local i text="$*"
local -a buff ch
for ((i=0;i<${#text};i++)); do
Expand All @@ -606,6 +610,7 @@ else
IFS= eval 'ret="${buff[*]-}"'
}
function ble/string#toupper.impl {
local LC_ALL= LC_COLLATE=C
local i text="$*"
local -a buff ch
for ((i=0;i<${#text};i++)); do
Expand All @@ -619,13 +624,11 @@ else
IFS= eval 'ret="${buff[*]-}"'
}
function ble/string#tolower {
local LC_ALL= LC_COLLATE=C
ble/string#tolower.impl "$@"
} 2>/dev/null
ble/string#tolower.impl "$@" 2>/dev/null # suppress locale error #D1440
}
function ble/string#toupper {
local LC_ALL= LC_COLLATE=C
ble/string#toupper.impl "$@" 2>/dev/null
} 2>/dev/null
ble/string#toupper.impl "$@" 2>/dev/null # suppress locale error #D1440
}
fi

## 関数 ble/string#trim text...
Expand Down Expand Up @@ -874,14 +877,20 @@ function ble/string#create-unicode-progress-bar {
}
# Note: Bash-4.1 以下では "LC_CTYPE=C 組み込みコマンド" の形式だと
# locale がその場で適用されないバグがある。
function ble/util/strlen {
function ble/util/strlen.impl {
local LC_ALL= LC_CTYPE=C
ret=${#1}
} 2>/dev/null
function ble/util/substr {
}
function ble/util/strlen {
ble/util/strlen.impl "$@" 2>/dev/null # suppress locale error #D1440
}
function ble/util/substr.impl {
local LC_ALL= LC_CTYPE=C
ret=${1:$2:$3}
} 2>/dev/null
}
function ble/util/substr {
ble/util/substr.impl "$@" 2>/dev/null # suppress locale error #D1440
}

function ble/path#add {
local _ble_local_script='opts=$opts${opts:+:}$2'
Expand Down Expand Up @@ -1101,6 +1110,24 @@ function ble/function#try {
"$@"
}

## 関数 ble/function#suppress-stderr function_name
## @param[in] function_name
function ble/function#suppress-stderr {
local name=$1
if ! ble/is-function "$name"; then
echo "$FUNCNAME: '$name' is not a function name" >&2
return 2
fi

local def; ble/function#getdef "$name"
builtin eval "ble/function#suppress-stderr:$def"
local lambda=ble/function#suppress-stderr:$name

local q=\' Q="'\''"
builtin eval "function $name { $lambda \"\$@\" 2>/dev/null; }"
return 0
}

#
# miscallaneous utils
#
Expand Down Expand Up @@ -1141,7 +1168,9 @@ if ((_ble_bash>=40000)); then
function ble/util/is-stdin-ready {
local IFS= LC_ALL= LC_CTYPE=C
builtin read -t 0
} &>/dev/null
}
# suppress locale error #D1440
ble/function#suppress-stderr ble/util/is-stdin-ready
else
function ble/util/is-stdin-ready { false; }
fi
Expand Down Expand Up @@ -1380,13 +1409,11 @@ _ble_util_rex_isprint='^[ -~]+'
##
## @var[out] BASH_REMATCH ble-exit/text/update/position で使用する。
function ble/util/isprint+ {
# LC_COLLATE=C ... &>/dev/null for cygwin collation
local LC_ALL= LC_COLLATE=C
ble/util/isprint+.impl "$@"
} 2>/dev/null # Note: suppress LC_COLLATE errors #D1205
function ble/util/isprint+.impl {
[[ $1 =~ $_ble_util_rex_isprint ]]
}
# suppress locale error #D1440
ble/function#suppress-stderr ble/util/isprint+

if ((_ble_bash>=40200)); then
function ble/util/strftime {
Expand Down Expand Up @@ -1424,7 +1451,7 @@ function ble/util/msleep/.check-builtin-sleep {
fi
}
function ble/util/msleep/.check-sleep-decimal-support {
local version; ble/util/assign version 'LANG=C ble/bin/sleep --version 2>&1'
local version; ble/util/assign version 'LC_ALL=C ble/bin/sleep --version 2>&1' 2>/dev/null # suppress locale error #D1440
[[ $version == *'GNU coreutils'* || $OSTYPE == darwin* && $version == 'usage: sleep seconds' ]]
}

Expand Down Expand Up @@ -3240,6 +3267,9 @@ if ((_ble_bash>=40200)); then
builtin printf -v ret '\uFFFF'
((${#ret}==2))
}
# suppress locale error #D1440
ble/function#suppress-stderr ble/util/.has-bashbug-printf-uffff

if ble/util/.has-bashbug-printf-uffff; then
function ble/util/c2s-impl {
if ((0xE000<=$1&&$1<=0xFFFF)) && [[ $_ble_util_locale_encoding == UTF-8 ]]; then
Expand Down

0 comments on commit b52a798

Please sign in to comment.