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