let hd_mksh take from stdin, great simplification
authortg <tg@mirbsd.org>
Tue, 8 Aug 2017 20:42:16 +0000 (20:42 +0000)
committertg <tg@mirbsd.org>
Tue, 8 Aug 2017 20:42:16 +0000 (20:42 +0000)
dot.mkshrc

index 19c9256..cca9a0f 100644 (file)
@@ -1,5 +1,5 @@
 # $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,
 #              2011, 2012, 2013, 2014, 2015, 2016, 2017
@@ -99,7 +99,7 @@ elif \\builtin command -v hexdump >/dev/null; then
        }
 else
        function hd {
-               hd_mksh "$@"
+               \\builtin cat "$@" | hd_mksh "$@"
        }
 fi
 
@@ -109,36 +109,34 @@ function hd_mksh {
        \\builtin typeset dasc dn line i
        \\builtin set +U
 
-       \\builtin cat "$@" | {
-               while \\builtin read -arn 512 line; do
-                       \\builtin typeset -i1 'line[*]'
-                       i=0
-                       while (( i < ${#line[*]} )); do
-                               dn=
-                               (( (hv = line[i++]) != 0 )) && dn=${line[i-1]#1#}
-                               if (( (pos & 15) == 0 )); then
-                                       (( pos )) && \
-                                           \\builtin print -r -- "$dasc|"
-                                       \\builtin print -nr "${pos#16#}  "
-                                       dasc=' |'
-                               fi
-                               \\builtin print -nr "${hv#16#} "
-                               if [[ $dn = [[:print:]] ]]; then
-                                       dasc+=$dn
-                               else
-                                       dasc+=.
-                               fi
-                               (( (pos++ & 15) == 7 )) && \
-                                   \\builtin print -nr -- '- '
-                       done
-               done
-               while (( pos & 15 )); do
-                       \\builtin print -nr '   '
+       while \\builtin read -arn 512 line; do
+               \\builtin typeset -i1 'line[*]'
+               i=0
+               while (( i < ${#line[*]} )); do
+                       dn=
+                       (( (hv = line[i++]) != 0 )) && dn=${line[i-1]#1#}
+                       if (( (pos & 15) == 0 )); then
+                               (( pos )) && \
+                                   \\builtin print -r -- "$dasc|"
+                               \\builtin print -nr "${pos#16#}  "
+                               dasc=' |'
+                       fi
+                       \\builtin print -nr "${hv#16#} "
+                       if [[ $dn = [[:print:]] ]]; then
+                               dasc+=$dn
+                       else
+                               dasc+=.
+                       fi
                        (( (pos++ & 15) == 7 )) && \
                            \\builtin print -nr -- '- '
                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