Skip to content

Commit

Permalink
stty: workaround Bash 3.2 bug of array initialization with SOH/DEL
Browse files Browse the repository at this point in the history
  • Loading branch information
akinomyoga committed Jan 24, 2020
1 parent bb31b11 commit defdbd4
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 9 deletions.
43 changes: 36 additions & 7 deletions memo.txt
Original file line number Diff line number Diff line change
Expand Up @@ -912,11 +912,30 @@ bash_tips
ToDo
-------------------------------------------------------------------------------

2020-01-23
2020-01-24

* stty: Bash 3.2 で変なエラーメッセージが出ている
/usr/bin/stty: invalid integer argument: `\001\177'
/usr/bin/stty: invalid integer argument: `\001\177'
* Bash 3.2 ^A, ^? を含む配列に対する対策 [#T0003]

更に履歴に格納されている値も変化している。
history -s で登録されている値は合っている。
何処でずれるのだろうか。。。

よく考えたらこれは可也広範に亘るのではないだろうか。
そもそも配列の複製 arr2=("${arr1[@]}") を安全に実行できるのだろうか。
これは別項目を立てて対策を考えるべきである。

どういう操作が安全でどういう操作が駄目なのか。
対策する事は可能だろうか。

* arr2=("${arr1[@]}") これは安全の様だ
* arr1=("$del" "$soh") これも安全の様だ

ble.sh の中で特に問題になりそうなのは何処か。

* binding のキャッシュ?
* vi のマクロの記録?

2020-01-23

* 前々から発生していたが曖昧補完などを実行すると時々ごみが残る。
これは何故だろうか。そもそもカーソルよりも右に何か文字列が入るはずがないのに?
Expand Down Expand Up @@ -2561,14 +2580,14 @@ bash_tips
- syntax: support hexadecimal literals for arithmetic expression (reported by cmplstofB) `#D1228` 90e4f35
- history: fix a bug that history append does not work with `set -C` (reported by cmplstofB) `#D1229` 604bb8b
- decode (`ble/builtin/bind`): fix widget mapping for `default_keymap=safe` `#D1234` 750a9f5
- main (ble-update): fix a bug that the check of `make` does not work in Bash 3.2 `#D1236`
- main (ble-update): fix a bug that the check of `make` does not work in Bash 3.2 `#D1236` 08ced81

Internal changes and fixes
- internal: merge subdir `test` into `memo` `#D1230` f0c38b6
- ble-measure: improve calibration `DD1231` d3a7a52
- vi_test: fix a bug that test fails to restore the original state `#D1232` 4b882fb
- decode (ble/builtin/bind): skip checking stdin in parsing the keyseq `#D1235` 0000000
- syntax: delay load of `ble/syntax/parse` for syntax highlighting `#D1237`
- decode (ble/builtin/bind): skip checking stdin in parsing the keyseq `#D1235` 5f949e8
- syntax: delay load of `ble/syntax/parse` for syntax highlighting `#D1237` bb31b11

2019-03-21 -- 2020-01-12 (#D1015...#D1215) df4feaa...c74abc5

Expand Down Expand Up @@ -3704,6 +3723,16 @@ bash_tips

2020-01-24

* stty: Bash 3.2 で変なエラーメッセージが出ている [#D1238]
/usr/bin/stty: invalid integer argument: `\001\177'
/usr/bin/stty: invalid integer argument: `\001\177'

調べると ^? $'\x7F' を arr=() の形式で配列に代入すると勝手に ^A^? になる様だ。
更に調べると declare -p は ^? を勝手に ^A^? に変換するらしい。面倒だ。
というか配列の要素の中に ^? が含まれている場合、
これを正しく補正して arr=() の形式にする事ができない。うーん。
取り敢えず別項目を立てて処理する事にする #T0003

* ble/syntax/parse の遅延が動いていない [#D1237]
update-syntax で is-function でチェックしているが、
これだと autoload で定義している物に当たってロードされてしまう。
Expand Down
17 changes: 15 additions & 2 deletions src/util.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1426,6 +1426,14 @@ function ble/util/declare-print-definitions {
# bash-3.0 の declare -p は改行について誤った出力をする。
if (_ble_bash < 30100) gsub(/\\\n/, "\n", decl);
if (_ble_bash < 40000) {
# #D1238 bash-3.2 以前の declare -p は ^A, ^? を
# ^A^A, ^A^? と出力してしまうので補正する。
gsub(/\001\001/, "\001\002", decl);
gsub(/\001\177/, "\177", decl);
gsub(/\001\002/, "\001", decl);
}
# declare 除去
sub(/^declare +(-[-aAfFgilrtux]+ +)?(-- +)?/, "", decl);
if (isArray) {
Expand Down Expand Up @@ -3147,9 +3155,14 @@ function ble/term/visible-bell/cancel-erasure {

## 変数 _ble_term_stty_state
## 現在 stty で制御文字の効果が解除されているかどうかを保持します。
##
## Note #D1238: arr=(...) の形式を用いると Bash 3.2 では勝手に ^? が ^A^? に化けてしまう
## 仕方がないので此処では ble/array#push を使って以下の配列を初期化する事にする。
_ble_term_stty_state=
_ble_term_stty_flags_enter=(kill undef erase undef intr undef quit undef susp undef)
_ble_term_stty_flags_leave=(kill '' erase '' intr '' quit '' susp '')
_ble_term_stty_flags_enter=()
_ble_term_stty_flags_leave=()
ble/array#push _ble_term_stty_flags_enter kill undef erase undef intr undef quit undef susp undef
ble/array#push _ble_term_stty_flags_leave kill '' erase '' intr '' quit '' susp ''
function ble/term/stty/.initialize-flags {
local stty; ble/util/assign stty 'stty -a'
# lnext, werase は POSIX にはないのでチェックする
Expand Down

0 comments on commit defdbd4

Please sign in to comment.