perform in chunks, don’t read the entire file into memory ahead

This commit is contained in:
tg 2017-08-08 20:38:08 +00:00
parent ce64148abb
commit 252c4b181b
1 changed files with 24 additions and 22 deletions

View File

@ -1,5 +1,5 @@
# $Id$
# $MirOS: src/bin/mksh/dot.mkshrc,v 1.115 2017/08/08 20:22:16 tg Exp $
# $MirOS: src/bin/mksh/dot.mkshrc,v 1.116 2017/08/08 20:38:08 tg Exp $
#-
# Copyright (c) 2002, 2003, 2004, 2006, 2007, 2008, 2009, 2010,
# 2011, 2012, 2013, 2014, 2015, 2016, 2017
@ -109,26 +109,28 @@ function hd_mksh {
\\builtin typeset dasc line i
\\builtin set +U
\\builtin cat "$@" | if \\builtin read -arN -1 line; then
\\builtin typeset -i1 'line[*]'
i=0
while (( i < ${#line[*]} )); do
hv=${line[i++]}
if (( (pos & 15) == 0 )); then
(( pos )) && \
\\builtin print -r -- "$dasc|"
\\builtin print -nr "${pos#16#} "
dasc=' |'
fi
\\builtin print -nr "${hv#16#} "
#XXX EBCDIC, but we need [[:print:]] to fix this
if (( (hv < 32) || (hv > 126) )); then
dasc+=.
else
dasc+=${line[i-1]#1#}
fi
(( (pos++ & 15) == 7 )) && \
\\builtin print -nr -- '- '
\\builtin cat "$@" | {
while \\builtin read -arn 512 line; do
\\builtin typeset -i1 'line[*]'
i=0
while (( i < ${#line[*]} )); do
hv=${line[i++]}
if (( (pos & 15) == 0 )); then
(( pos )) && \
\\builtin print -r -- "$dasc|"
\\builtin print -nr "${pos#16#} "
dasc=' |'
fi
\\builtin print -nr "${hv#16#} "
#XXX EBCDIC, but we need [[:print:]] to fix this
if (( (hv < 32) || (hv > 126) )); then
dasc+=.
else
dasc+=${line[i-1]#1#}
fi
(( (pos++ & 15) == 7 )) && \
\\builtin print -nr -- '- '
done
done
while (( pos & 15 )); do
\\builtin print -nr ' '
@ -136,7 +138,7 @@ function hd_mksh {
\\builtin print -nr -- '- '
done
(( hv == 2147483647 )) || \\builtin print -r -- "$dasc|"
fi
}
}
# Berkeley C shell compatible dirs, popd, and pushd functions