let hd_mksh take from stdin, great simplification

This commit is contained in:
tg 2017-08-08 20:42:16 +00:00
parent 7f7fb75205
commit 0af974d905

View File

@ -1,5 +1,5 @@
# $Id$ # $Id$
# $MirOS: src/bin/mksh/dot.mkshrc,v 1.117 2017/08/08 20:40:25 tg Exp $ # $MirOS: src/bin/mksh/dot.mkshrc,v 1.118 2017/08/08 20:42:16 tg Exp $
#- #-
# Copyright (c) 2002, 2003, 2004, 2006, 2007, 2008, 2009, 2010, # Copyright (c) 2002, 2003, 2004, 2006, 2007, 2008, 2009, 2010,
# 2011, 2012, 2013, 2014, 2015, 2016, 2017 # 2011, 2012, 2013, 2014, 2015, 2016, 2017
@ -99,7 +99,7 @@ elif \\builtin command -v hexdump >/dev/null; then
} }
else else
function hd { function hd {
hd_mksh "$@" \\builtin cat "$@" | hd_mksh "$@"
} }
fi fi
@ -109,36 +109,34 @@ function hd_mksh {
\\builtin typeset dasc dn line i \\builtin typeset dasc dn line i
\\builtin set +U \\builtin set +U
\\builtin cat "$@" | { while \\builtin read -arn 512 line; do
while \\builtin read -arn 512 line; do \\builtin typeset -i1 'line[*]'
\\builtin typeset -i1 'line[*]' i=0
i=0 while (( i < ${#line[*]} )); do
while (( i < ${#line[*]} )); do dn=
dn= (( (hv = line[i++]) != 0 )) && dn=${line[i-1]#1#}
(( (hv = line[i++]) != 0 )) && dn=${line[i-1]#1#} if (( (pos & 15) == 0 )); then
if (( (pos & 15) == 0 )); then (( pos )) && \
(( pos )) && \ \\builtin print -r -- "$dasc|"
\\builtin print -r -- "$dasc|" \\builtin print -nr "${pos#16#} "
\\builtin print -nr "${pos#16#} " dasc=' |'
dasc=' |' fi
fi \\builtin print -nr "${hv#16#} "
\\builtin print -nr "${hv#16#} " if [[ $dn = [[:print:]] ]]; then
if [[ $dn = [[:print:]] ]]; then dasc+=$dn
dasc+=$dn else
else dasc+=.
dasc+=. fi
fi
(( (pos++ & 15) == 7 )) && \
\\builtin print -nr -- '- '
done
done
while (( pos & 15 )); do
\\builtin print -nr ' '
(( (pos++ & 15) == 7 )) && \ (( (pos++ & 15) == 7 )) && \
\\builtin print -nr -- '- ' \\builtin print -nr -- '- '
done done
(( hv == 2147483647 )) || \\builtin print -r -- "$dasc|" done
} while (( pos & 15 )); do
\\builtin print -nr ' '
(( (pos++ & 15) == 7 )) && \
\\builtin print -nr -- '- '
done
(( hv == 2147483647 )) || \\builtin print -r -- "$dasc|"
} }
# Berkeley C shell compatible dirs, popd, and pushd functions # Berkeley C shell compatible dirs, popd, and pushd functions