hush: rework input char buffering to allow more than one-deep peek

This fixes backslash+newline continuation in
	$VAR\
	NAME
construct. (ash has a bug there as well).

function                                             old     new   delta
file_peek2                                             -      74     +74
parse_dollar                                         746     773     +27
expand_vars_to_list                                 1143    1167     +24
setup_string_in_str                                   32      46     +14
setup_file_in_str                                     33      47     +14
file_get                                             264     278     +14
static_peek2                                           -       7      +7
file_peek                                             91      72     -19
------------------------------------------------------------------------------
(add/remove: 2/0 grow/shrink: 5/1 up/down: 174/-19)           Total: 155 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
Denys Vlasenko 2016-09-29 16:59:06 +02:00
parent 3b4d04b77e
commit 8286513838
10 changed files with 177 additions and 0 deletions

View File

@ -0,0 +1,5 @@
Assignments only: c=a
Assignments and a command: c=a
Assignments and a builtin: c=a
Assignments and a function: c=a
Done

View File

@ -0,0 +1,22 @@
a=a
b=b
c=c
# Second assignment depends on the first:
b=$a c=$b
echo Assignments only: c=$c
b=b
c=c
b=$a c=$b "$THIS_SH" -c 'echo Assignments and a command: c=$c'
b=b
c=c
b=$a c=$b eval 'echo Assignments and a builtin: c=$c'
b=b
c=c
f() { echo Assignments and a function: c=$c; }
b=$a c=$b f
echo Done

View File

@ -0,0 +1,40 @@
Testing: in x y z
.x.
.y.
.z.
Testing: in u $empty v
.u.
.v.
Testing: in u " $empty" v
.u.
. .
.v.
Testing: in u $empty $empty$a v
.u.
.a.
.v.
Testing: in $a_b
.a.
.b.
Testing: in $*
.abc.
.d.
.e.
Testing: in $@
.abc.
.d.
.e.
Testing: in -$*-
.-abc.
.d.
.e-.
Testing: in -$@-
.-abc.
.d.
.e-.
Testing: in $a_b -$a_b-
.a.
.b.
.-a.
.b-.
Finished

View File

@ -0,0 +1,40 @@
if test $# = 0; then
exec "$THIS_SH" "$0" abc "d e"
fi
echo 'Testing: in x y z'
for a in x y z; do echo ".$a."; done
echo 'Testing: in u $empty v'
empty=''
for a in u $empty v; do echo ".$a."; done
echo 'Testing: in u " $empty" v'
empty=''
for a in u " $empty" v; do echo ".$a."; done
echo 'Testing: in u $empty $empty$a v'
a='a'
for a in u $empty $empty$a v; do echo ".$a."; done
echo 'Testing: in $a_b'
a_b='a b'
for a in $a_b; do echo ".$a."; done
echo 'Testing: in $*'
for a in $*; do echo ".$a."; done
echo 'Testing: in $@'
for a in $@; do echo ".$a."; done
echo 'Testing: in -$*-'
for a in -$*-; do echo ".$a."; done
echo 'Testing: in -$@-'
for a in -$@-; do echo ".$a."; done
echo 'Testing: in $a_b -$a_b-'
a_b='a b'
for a in $a_b -$a_b-; do echo ".$a."; done
echo Finished

View File

@ -0,0 +1,11 @@
b1=-qwerty-t-\-"-`---z-*-?-
b1=-qwerty-t-\-"-`---z-*-?-
b2=-qwerty-\t-\-"-`-\--\z-\*-\?-
b2=-qwerty-\t-\-"-`-\--\z-\*-\?-
b3=-$a-\t-\\-\"-\`-\--\z-\*-\?-
b3=-$a-\t-\\-\"-\`-\--\z-\*-\?-
c=-$a-\t-\\-\"-\`-\--\z-\*-\?-
c=-$a-\t-\\-\"-\`-\--\z-\*-\?-
c=-$a-\t-\\-\"-\`-\--\z-\*-\?-
c=-$a-\t-\\-\"-\`-\--\z-\*-\?-
Done: 0

View File

@ -0,0 +1,23 @@
# Test for correct handling of backslashes
a=qwerty
b=-$a-\t-\\-\"-\`-\--\z-\*-\?-
echo b1=$b
echo "b1=$b"
b="-$a-\t-\\-\"-\`-\--\z-\*-\?-"
echo b2=$b
echo "b2=$b"
b='-$a-\t-\\-\"-\`-\--\z-\*-\?-'
echo b3=$b
echo "b3=$b"
c=$b
echo "c=$c"
c=${b}
echo "c=$c"
c="$b"
echo "c=$c"
c="${b}"
echo "c=$c"
echo "Done: $?"

View File

@ -0,0 +1,3 @@
Ok
Ba d
Ok

View File

@ -0,0 +1,15 @@
ad="Ok"
a="Ba"
# "Ok"
echo $a\
d
# This variable contains backslash+newline!
e='echo $a\
d'
# "Ba d"
eval $e
# "Ok"
eval "$e"

View File

@ -0,0 +1,3 @@
Ok
Ba d
Ok

View File

@ -0,0 +1,15 @@
ad="Ok"
a="Ba"
# "Ok"
echo $a\
d
# This variable contains backslash+newline!
e='echo $a\
d'
# "Ba d"
eval $e
# "Ok"
eval "$e"