From b52a7987a07b442fd9cf5dff48350edda024abc8 Mon Sep 17 00:00:00 2001 From: Koichi Murase Date: Sun, 17 Jan 2021 12:01:57 +0900 Subject: [PATCH] global: suppress missing locale errors --- lib/core-syntax.sh | 2 +- src/canvas.sh | 24 ++++++++++------- src/color.sh | 4 ++- src/util.sh | 66 +++++++++++++++++++++++++++++++++------------- 4 files changed, 66 insertions(+), 30 deletions(-) diff --git a/lib/core-syntax.sh b/lib/core-syntax.sh index 861d096d..ea84faf5 100644 --- a/lib/core-syntax.sh +++ b/lib/core-syntax.sh @@ -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 diff --git a/src/canvas.sh b/src/canvas.sh index d0dc4737..1604be83 100644 --- a/src/canvas.sh +++ b/src/canvas.sh @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/src/color.sh b/src/color.sh index 390ffef5..4fcb28cf 100644 --- a/src/color.sh +++ b/src/color.sh @@ -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 diff --git a/src/util.sh b/src/util.sh index d6e2b29d..a36a6db7 100644 --- a/src/util.sh +++ b/src/util.sh @@ -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 @@ -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 @@ -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 @@ -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 @@ -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... @@ -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' @@ -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 # @@ -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 @@ -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 { @@ -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' ]] } @@ -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