Skip to content

Commit

Permalink
main: use /usr/xpg4/bin/awk for Solaris
Browse files Browse the repository at this point in the history
  • Loading branch information
akinomyoga committed Jan 11, 2020
1 parent b443f46 commit 90ad15b
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 37 deletions.
32 changes: 20 additions & 12 deletions ble.pp
@@ -1,7 +1,6 @@
#!/bin/bash
#%$> out/ble.sh
#%[release = 1]
#%[use_gawk = 0]
#%[measure_load_time = 0]
#%[debug_keylogger = 1]
#%#----------------------------------------------------------------------------
Expand Down Expand Up @@ -214,14 +213,6 @@ function ble/.check-environment {
echo "ble.sh: modified PATH=\$PATH${PATH:${#original_path}}" >&2
fi

#%if use_gawk
if ! type gawk &>/dev/null; then
echo "ble.sh: \`gawk' not found. Please install gawk (GNU awk), or check your environment variable PATH." >&2
return 1
fi
ble/bin/.default-utility-path gawk
#%end

# 暫定的な ble/bin/$cmd 設定
ble/bin/.default-utility-path "${_ble_init_posix_command_list[@]}"

Expand All @@ -239,6 +230,21 @@ function ble/.check-environment {
fi
fi

_ble_bin_awk_solaris_xpg4=
function ble/bin/awk.use-solaris-xpg4 {
if [[ ! $_ble_bin_awk_solaris_xpg4 ]]; then
if [[ $OSTYPE == solaris* ]] && type /usr/xpg4/bin/awk >/dev/null; then
_ble_bin_awk_solaris_xpg4=yes
else
_ble_bin_awk_solaris_xpg4=no
fi
fi

# Solaris の既定の awk は絶望的なので /usr/xpg4/bin/awk (nawk) を使う
[[ $_ble_bin_awk_solaris_xpg4 == yes ]] &&
function ble/bin/awk { /usr/xpg4/bin/awk "$@"; }
}

#------------------------------------------------------------------------------
#%$ echo "BLE_VERSION=$FULLVER+$(git show -s --format=%h)"
function ble/base/initialize-version-information {
Expand Down Expand Up @@ -558,14 +564,16 @@ function ble-update {
}
#%end

# Solaris: src/util の中でちゃんとした awk が必要
ble/bin/awk.use-solaris-xpg4

#%x inc.r|@|src/def|
#%x inc.r|@|src/util|

ble/bin/.freeze-utility-path "${_ble_init_posix_command_list[@]}" # <- this uses ble/util/assign.
#%if use_gawk
ble/bin/.freeze-utility-path gawk
#%end
ble/bin/.freeze-utility-path man
# Solaris: .freeze-utility-path で上書きされた awk を戻す
ble/bin/awk.use-solaris-xpg4

#%x inc.r|@|src/decode|
#%x inc.r|@|src/color|
Expand Down
30 changes: 8 additions & 22 deletions src/decode.sh
Expand Up @@ -2082,23 +2082,25 @@ function ble-decode-bind/.generate-source-to-unbind-default {
fi
echo '__BINDP__'
builtin bind -sp
#%x
} | LC_ALL=C ble-decode-bind/.generate-source-to-unbind-default/.process

# Note: 2>/dev/null は、(1) bind -X のエラーメッセージ、及び、
# (2) LC_ALL 復元時のエラーメッセージ (外側の値が不正な時) を捨てる為に必要。
} 2>/dev/null
function ble-decode-bind/.generate-source-to-unbind-default/.process {
ble/bin/${.eval/use_gawk?"gawk":"awk"} -v apos="'" '
#%end.i
local q=\' b=\\ Q="'\''"
# Note: Solaris xpg4 awk では gsub の置換後のエスケープシーケンスも処理される
[[ $_ble_bin_awk_solaris_xpg4 == yes ]] && Q="'$b$b''"
local QUOT_Q=\"${Q//"$b"/$b$b}\"
ble/bin/awk -v q="$q" '
BEGIN {
APOS = apos "\\" apos apos;
Q = '"$QUOT_Q"';
mode = 1;
}
function quote(text) {
gsub(apos, APOS, text);
return apos text apos;
gsub(q, Q, text);
return q text q;
}
function unescape_control_modifier(str, _, i, esc, chr) {
Expand Down Expand Up @@ -2157,27 +2159,12 @@ function ble-decode-bind/.generate-source-to-unbind-default/.process {
#% # ※bash-4.3 では bind -r しても bind -X に残る。
#% # 再登録を防ぐ為 ble-decode-bind を明示的に避ける
#%if use_gawk
if (line ~ /\yble-decode\/.hook\y/) next;
#%else
if (line ~ /(^|[^[:alnum:]])ble-decode\/.hook($|[^[:alnum:]])/) next;
#%end
#% # ※bind -X で得られた物は直接 bind -x に用いる事はできない。
#% # コマンド部分の "" を外して中の escape を外す必要がある。
#% # escape には以下の種類がある: \C-a など \C-? \e \\ \"
#% # \n\r\f\t\v\b\a 等は使われない様だ。
#%if use_gawk
if (match(line, /^("([^"\\]|\\.)*":) "(([^"\\]|\\.)*)"/, captures) > 0) {
sequence = captures[1];
command = captures[3];
if (command ~ /\\/)
command = unescape(command);
line = sequence command;
}
#%else
if (match(line, /^("([^"\\]|\\.)*":) "(([^"\\]|\\.)*)"/) > 0) {
rlen = RLENGTH;
match(line, /^"([^"\\]|\\.)*":/);
Expand All @@ -2191,7 +2178,6 @@ function ble-decode-bind/.generate-source-to-unbind-default/.process {
line = sequence command;
}
#%end
print "builtin bind -x " quote(line) > "/dev/stderr";
}
Expand Down
8 changes: 5 additions & 3 deletions test/benchmark/benchmark.sh
Expand Up @@ -122,9 +122,11 @@ function ble-measure {

local nsec0=$_ble_measure_base
local reso=$_ble_measure_resolution
awk -v utot=$utot -v nsec0=$nsec0 -v n=$n -v reso=$reso -v title="$* (x$n)" \
' function genround(x, mod) { return int(x / mod + 0.5) * mod; }
BEGIN { printf("%12.2f usec/eval: %s\n", genround(utot / n - nsec0 / 1000, reso / 10.0 / n), title); exit }'
local awk=ble/bin/awk
type "$awk" &>/dev/null || awk=awk
"$awk" -v utot=$utot -v nsec0=$nsec0 -v n=$n -v reso=$reso -v title="$* (x$n)" \
' function genround(x, mod) { return int(x / mod + 0.5) * mod; }
BEGIN { printf("%12.2f usec/eval: %s\n", genround(utot / n - nsec0 / 1000, reso / 10.0 / n), title); exit }'
((ret=utot/n))
if ((n>=1000)); then
((nsec=utot/(n/1000)))
Expand Down

0 comments on commit 90ad15b

Please sign in to comment.