don’t clobber the tree used for printing IOACTs in process_TIF (LP: #907224)
This commit is contained in:
parent
bb51eee63c
commit
31bf077591
326
check.t
326
check.t
@ -1,4 +1,4 @@
|
||||
# $MirOS: src/bin/mksh/check.t,v 1.505 2011/12/29 22:03:12 tg Exp $
|
||||
# $MirOS: src/bin/mksh/check.t,v 1.506 2011/12/29 23:36:21 tg Exp $
|
||||
# $OpenBSD: bksl-nl.t,v 1.2 2001/01/28 23:04:56 niklas Exp $
|
||||
# $OpenBSD: history.t,v 1.5 2001/01/28 23:04:56 niklas Exp $
|
||||
# $OpenBSD: read.t,v 1.3 2003/03/10 03:48:16 david Exp $
|
||||
@ -28,7 +28,7 @@
|
||||
# http://www.freebsd.org/cgi/cvsweb.cgi/src/tools/regression/bin/test/regress.sh?rev=HEAD
|
||||
|
||||
expected-stdout:
|
||||
@(#)MIRBSD KSH R40 2011/12/16
|
||||
@(#)MIRBSD KSH R40 2011/12/29
|
||||
description:
|
||||
Check version of shell.
|
||||
stdin:
|
||||
@ -8939,6 +8939,328 @@ expected-stdout:
|
||||
x=$(( case x in (x) a+=b ; set -A c+ -- d e ;; esac ) | tr u x )
|
||||
}
|
||||
---
|
||||
name: comsub-torture-io
|
||||
description:
|
||||
Check the tree dump functions work correctly with I/O redirection
|
||||
stdin:
|
||||
if [[ -z $__progname ]]; then echo >&2 call me with __progname; exit 1; fi
|
||||
while IFS= read -r line; do
|
||||
if [[ $line = '#1' ]]; then
|
||||
lastf=0
|
||||
continue
|
||||
elif [[ $line = EOFN* ]]; then
|
||||
fbody=$fbody$'\n'$line
|
||||
continue
|
||||
elif [[ $line != '#'* ]]; then
|
||||
fbody=$fbody$'\n\t'$line
|
||||
continue
|
||||
fi
|
||||
if (( lastf )); then
|
||||
x="inline_${nextf}() {"$fbody$'\n}\n'
|
||||
print -nr -- "$x"
|
||||
print -r -- "${x}typeset -f inline_$nextf" | "$__progname"
|
||||
x="function comsub_$nextf { x=\$("$fbody$'\n); }\n'
|
||||
print -nr -- "$x"
|
||||
print -r -- "${x}typeset -f comsub_$nextf" | "$__progname"
|
||||
x="function reread_$nextf { x=\$(("$fbody$'\n)|tr u x); }\n'
|
||||
print -nr -- "$x"
|
||||
print -r -- "${x}typeset -f reread_$nextf" | "$__progname"
|
||||
fi
|
||||
lastf=1
|
||||
fbody=
|
||||
nextf=${line#?}
|
||||
done <<'EOD'
|
||||
#1
|
||||
#TCOM
|
||||
vara=1 varb='2 3' cmd arg1 $arg2 "$arg3 4" >&3
|
||||
#TPAREN_TPIPE_TLIST
|
||||
(echo $foo | tr -dc 0-9 >&3; echo >&3) >&3
|
||||
#TAND_TOR
|
||||
cmd >&3 && >&3 echo ja || echo >&3 nein
|
||||
#TSELECT
|
||||
select file in *; do echo "<$file>" ; break >&3 ; done >&3
|
||||
#TFOR_TTIME
|
||||
for i in {1,2,3} ; do time >&3 echo $i ; done >&3
|
||||
#TCASE
|
||||
case $foo in 1) echo eins >&3;& 2) echo zwei >&3 ;| *) echo kann net bis drei zählen >&3;; esac >&3
|
||||
#TIF_TBANG_TDBRACKET_TELIF
|
||||
if ! [[ 1 = 1 ]] >&3 ; then echo eins; elif [[ 1 = 2 ]] >&3; then echo zwei ;else echo drei; fi >&3
|
||||
#TWHILE
|
||||
i=1; while (( i < 10 )) >&3; do echo $i; let ++i; done >&3
|
||||
#TUNTIL
|
||||
i=10; until (( !--i )) >&3 ; do echo $i; done >&3
|
||||
#TCOPROC
|
||||
cat * >&3 |& >&3 ls
|
||||
#TFUNCT_TBRACE_TASYNC
|
||||
function korn { echo eins; echo >&3 zwei ; }
|
||||
bourne () { logger * >&3 & }
|
||||
#COMSUB_EXPRSUB
|
||||
echo $(true >&3) $((1+ 2))
|
||||
#0
|
||||
EOD
|
||||
expected-stdout:
|
||||
inline_TCOM() {
|
||||
vara=1 varb='2 3' cmd arg1 $arg2 "$arg3 4" >&3
|
||||
}
|
||||
inline_TCOM() {
|
||||
vara=1 varb="2 3" cmd arg1 $arg2 "$arg3 4" >&3
|
||||
}
|
||||
function comsub_TCOM { x=$(
|
||||
vara=1 varb='2 3' cmd arg1 $arg2 "$arg3 4" >&3
|
||||
); }
|
||||
function comsub_TCOM {
|
||||
x=$(vara=1 varb="2 3" cmd arg1 $arg2 "$arg3 4" >&3 )
|
||||
}
|
||||
function reread_TCOM { x=$((
|
||||
vara=1 varb='2 3' cmd arg1 $arg2 "$arg3 4" >&3
|
||||
)|tr u x); }
|
||||
function reread_TCOM {
|
||||
x=$(( vara=1 varb="2 3" cmd arg1 $arg2 "$arg3 4" >&3 ) | tr u x )
|
||||
}
|
||||
inline_TPAREN_TPIPE_TLIST() {
|
||||
(echo $foo | tr -dc 0-9 >&3; echo >&3) >&3
|
||||
}
|
||||
inline_TPAREN_TPIPE_TLIST() {
|
||||
( echo $foo | tr -dc 0-9 >&3
|
||||
echo >&3 ) >&3
|
||||
}
|
||||
function comsub_TPAREN_TPIPE_TLIST { x=$(
|
||||
(echo $foo | tr -dc 0-9 >&3; echo >&3) >&3
|
||||
); }
|
||||
function comsub_TPAREN_TPIPE_TLIST {
|
||||
x=$(( echo $foo | tr -dc 0-9 >&3 ; echo >&3 ) >&3 )
|
||||
}
|
||||
function reread_TPAREN_TPIPE_TLIST { x=$((
|
||||
(echo $foo | tr -dc 0-9 >&3; echo >&3) >&3
|
||||
)|tr u x); }
|
||||
function reread_TPAREN_TPIPE_TLIST {
|
||||
x=$(( ( echo $foo | tr -dc 0-9 >&3 ; echo >&3 ) >&3 ) | tr u x )
|
||||
}
|
||||
inline_TAND_TOR() {
|
||||
cmd >&3 && >&3 echo ja || echo >&3 nein
|
||||
}
|
||||
inline_TAND_TOR() {
|
||||
cmd >&3 && echo ja >&3 || echo nein >&3
|
||||
}
|
||||
function comsub_TAND_TOR { x=$(
|
||||
cmd >&3 && >&3 echo ja || echo >&3 nein
|
||||
); }
|
||||
function comsub_TAND_TOR {
|
||||
x=$(cmd >&3 && echo ja >&3 || echo nein >&3 )
|
||||
}
|
||||
function reread_TAND_TOR { x=$((
|
||||
cmd >&3 && >&3 echo ja || echo >&3 nein
|
||||
)|tr u x); }
|
||||
function reread_TAND_TOR {
|
||||
x=$(( cmd >&3 && echo ja >&3 || echo nein >&3 ) | tr u x )
|
||||
}
|
||||
inline_TSELECT() {
|
||||
select file in *; do echo "<$file>" ; break >&3 ; done >&3
|
||||
}
|
||||
inline_TSELECT() {
|
||||
select file in *
|
||||
do
|
||||
echo "<$file>"
|
||||
break >&3
|
||||
done >&3
|
||||
}
|
||||
function comsub_TSELECT { x=$(
|
||||
select file in *; do echo "<$file>" ; break >&3 ; done >&3
|
||||
); }
|
||||
function comsub_TSELECT {
|
||||
x=$(select file in * ; do echo "<$file>" ; break >&3 ; done >&3 )
|
||||
}
|
||||
function reread_TSELECT { x=$((
|
||||
select file in *; do echo "<$file>" ; break >&3 ; done >&3
|
||||
)|tr u x); }
|
||||
function reread_TSELECT {
|
||||
x=$(( select file in * ; do echo "<$file>" ; break >&3 ; done >&3 ) | tr u x )
|
||||
}
|
||||
inline_TFOR_TTIME() {
|
||||
for i in {1,2,3} ; do time >&3 echo $i ; done >&3
|
||||
}
|
||||
inline_TFOR_TTIME() {
|
||||
for i in {1,2,3}
|
||||
do
|
||||
time echo $i >&3
|
||||
done >&3
|
||||
}
|
||||
function comsub_TFOR_TTIME { x=$(
|
||||
for i in {1,2,3} ; do time >&3 echo $i ; done >&3
|
||||
); }
|
||||
function comsub_TFOR_TTIME {
|
||||
x=$(for i in {1,2,3} ; do time echo $i >&3 ; done >&3 )
|
||||
}
|
||||
function reread_TFOR_TTIME { x=$((
|
||||
for i in {1,2,3} ; do time >&3 echo $i ; done >&3
|
||||
)|tr u x); }
|
||||
function reread_TFOR_TTIME {
|
||||
x=$(( for i in {1,2,3} ; do time echo $i >&3 ; done >&3 ) | tr u x )
|
||||
}
|
||||
inline_TCASE() {
|
||||
case $foo in 1) echo eins >&3;& 2) echo zwei >&3 ;| *) echo kann net bis drei zählen >&3;; esac >&3
|
||||
}
|
||||
inline_TCASE() {
|
||||
case $foo in
|
||||
(1)
|
||||
echo eins >&3
|
||||
;&
|
||||
(2)
|
||||
echo zwei >&3
|
||||
;|
|
||||
(*)
|
||||
echo kann net bis drei zählen >&3
|
||||
;;
|
||||
esac >&3
|
||||
}
|
||||
function comsub_TCASE { x=$(
|
||||
case $foo in 1) echo eins >&3;& 2) echo zwei >&3 ;| *) echo kann net bis drei zählen >&3;; esac >&3
|
||||
); }
|
||||
function comsub_TCASE {
|
||||
x=$(case $foo in (1) echo eins >&3 ;& (2) echo zwei >&3 ;| (*) echo kann net bis drei zählen >&3 ;; esac >&3 )
|
||||
}
|
||||
function reread_TCASE { x=$((
|
||||
case $foo in 1) echo eins >&3;& 2) echo zwei >&3 ;| *) echo kann net bis drei zählen >&3;; esac >&3
|
||||
)|tr u x); }
|
||||
function reread_TCASE {
|
||||
x=$(( case $foo in (1) echo eins >&3 ;& (2) echo zwei >&3 ;| (*) echo kann net bis drei zählen >&3 ;; esac >&3 ) | tr u x )
|
||||
}
|
||||
inline_TIF_TBANG_TDBRACKET_TELIF() {
|
||||
if ! [[ 1 = 1 ]] >&3 ; then echo eins; elif [[ 1 = 2 ]] >&3; then echo zwei ;else echo drei; fi >&3
|
||||
}
|
||||
inline_TIF_TBANG_TDBRACKET_TELIF() {
|
||||
if ! [[ 1 = 1 ]] >&3
|
||||
then
|
||||
echo eins
|
||||
elif [[ 1 = 2 ]] >&3
|
||||
then
|
||||
echo zwei
|
||||
else
|
||||
echo drei
|
||||
fi >&3
|
||||
}
|
||||
function comsub_TIF_TBANG_TDBRACKET_TELIF { x=$(
|
||||
if ! [[ 1 = 1 ]] >&3 ; then echo eins; elif [[ 1 = 2 ]] >&3; then echo zwei ;else echo drei; fi >&3
|
||||
); }
|
||||
function comsub_TIF_TBANG_TDBRACKET_TELIF {
|
||||
x=$(if ! [[ 1 = 1 ]] >&3 ; then echo eins ; elif [[ 1 = 2 ]] >&3 ; then echo zwei ; else echo drei ; fi >&3 )
|
||||
}
|
||||
function reread_TIF_TBANG_TDBRACKET_TELIF { x=$((
|
||||
if ! [[ 1 = 1 ]] >&3 ; then echo eins; elif [[ 1 = 2 ]] >&3; then echo zwei ;else echo drei; fi >&3
|
||||
)|tr u x); }
|
||||
function reread_TIF_TBANG_TDBRACKET_TELIF {
|
||||
x=$(( if ! [[ 1 = 1 ]] >&3 ; then echo eins ; elif [[ 1 = 2 ]] >&3 ; then echo zwei ; else echo drei ; fi >&3 ) | tr u x )
|
||||
}
|
||||
inline_TWHILE() {
|
||||
i=1; while (( i < 10 )) >&3; do echo $i; let ++i; done >&3
|
||||
}
|
||||
inline_TWHILE() {
|
||||
i=1
|
||||
while let " i < 10 " >&3
|
||||
do
|
||||
echo $i
|
||||
let ++i
|
||||
done >&3
|
||||
}
|
||||
function comsub_TWHILE { x=$(
|
||||
i=1; while (( i < 10 )) >&3; do echo $i; let ++i; done >&3
|
||||
); }
|
||||
function comsub_TWHILE {
|
||||
x=$(i=1 ; while let " i < 10 " >&3 ; do echo $i ; let ++i ; done >&3 )
|
||||
}
|
||||
function reread_TWHILE { x=$((
|
||||
i=1; while (( i < 10 )) >&3; do echo $i; let ++i; done >&3
|
||||
)|tr u x); }
|
||||
function reread_TWHILE {
|
||||
x=$(( i=1 ; while let " i < 10 " >&3 ; do echo $i ; let ++i ; done >&3 ) | tr u x )
|
||||
}
|
||||
inline_TUNTIL() {
|
||||
i=10; until (( !--i )) >&3 ; do echo $i; done >&3
|
||||
}
|
||||
inline_TUNTIL() {
|
||||
i=10
|
||||
until let " !--i " >&3
|
||||
do
|
||||
echo $i
|
||||
done >&3
|
||||
}
|
||||
function comsub_TUNTIL { x=$(
|
||||
i=10; until (( !--i )) >&3 ; do echo $i; done >&3
|
||||
); }
|
||||
function comsub_TUNTIL {
|
||||
x=$(i=10 ; until let " !--i " >&3 ; do echo $i ; done >&3 )
|
||||
}
|
||||
function reread_TUNTIL { x=$((
|
||||
i=10; until (( !--i )) >&3 ; do echo $i; done >&3
|
||||
)|tr u x); }
|
||||
function reread_TUNTIL {
|
||||
x=$(( i=10 ; until let " !--i " >&3 ; do echo $i ; done >&3 ) | tr u x )
|
||||
}
|
||||
inline_TCOPROC() {
|
||||
cat * >&3 |& >&3 ls
|
||||
}
|
||||
inline_TCOPROC() {
|
||||
cat * >&3 |&
|
||||
ls >&3
|
||||
}
|
||||
function comsub_TCOPROC { x=$(
|
||||
cat * >&3 |& >&3 ls
|
||||
); }
|
||||
function comsub_TCOPROC {
|
||||
x=$(cat * >&3 |& ls >&3 )
|
||||
}
|
||||
function reread_TCOPROC { x=$((
|
||||
cat * >&3 |& >&3 ls
|
||||
)|tr u x); }
|
||||
function reread_TCOPROC {
|
||||
x=$(( cat * >&3 |& ls >&3 ) | tr u x )
|
||||
}
|
||||
inline_TFUNCT_TBRACE_TASYNC() {
|
||||
function korn { echo eins; echo >&3 zwei ; }
|
||||
bourne () { logger * >&3 & }
|
||||
}
|
||||
inline_TFUNCT_TBRACE_TASYNC() {
|
||||
function korn {
|
||||
echo eins
|
||||
echo zwei >&3
|
||||
}
|
||||
bourne() {
|
||||
logger * >&3 &
|
||||
}
|
||||
}
|
||||
function comsub_TFUNCT_TBRACE_TASYNC { x=$(
|
||||
function korn { echo eins; echo >&3 zwei ; }
|
||||
bourne () { logger * >&3 & }
|
||||
); }
|
||||
function comsub_TFUNCT_TBRACE_TASYNC {
|
||||
x=$(function korn { echo eins ; echo zwei >&3 ; } ; bourne() { logger * >&3 & } )
|
||||
}
|
||||
function reread_TFUNCT_TBRACE_TASYNC { x=$((
|
||||
function korn { echo eins; echo >&3 zwei ; }
|
||||
bourne () { logger * >&3 & }
|
||||
)|tr u x); }
|
||||
function reread_TFUNCT_TBRACE_TASYNC {
|
||||
x=$(( function korn { echo eins ; echo zwei >&3 ; } ; bourne() { logger * >&3 & } ) | tr u x )
|
||||
}
|
||||
inline_COMSUB_EXPRSUB() {
|
||||
echo $(true >&3) $((1+ 2))
|
||||
}
|
||||
inline_COMSUB_EXPRSUB() {
|
||||
echo $(true >&3 ) $((1+ 2))
|
||||
}
|
||||
function comsub_COMSUB_EXPRSUB { x=$(
|
||||
echo $(true >&3) $((1+ 2))
|
||||
); }
|
||||
function comsub_COMSUB_EXPRSUB {
|
||||
x=$(echo $(true >&3 ) $((1+ 2)) )
|
||||
}
|
||||
function reread_COMSUB_EXPRSUB { x=$((
|
||||
echo $(true >&3) $((1+ 2))
|
||||
)|tr u x); }
|
||||
function reread_COMSUB_EXPRSUB {
|
||||
x=$(( echo $(true >&3 ) $((1+ 2)) ) | tr u x )
|
||||
}
|
||||
---
|
||||
name: test-stnze-1
|
||||
description:
|
||||
Check that the short form [ $x ] works
|
||||
|
4
sh.h
4
sh.h
@ -151,9 +151,9 @@
|
||||
#endif
|
||||
|
||||
#ifdef EXTERN
|
||||
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.513 2011/12/29 22:54:21 tg Exp $");
|
||||
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.514 2011/12/29 23:36:23 tg Exp $");
|
||||
#endif
|
||||
#define MKSH_VERSION "R40 2011/12/16"
|
||||
#define MKSH_VERSION "R40 2011/12/29"
|
||||
|
||||
/* arithmetics types */
|
||||
typedef int32_t mksh_ari_t;
|
||||
|
19
tree.c
19
tree.c
@ -22,7 +22,7 @@
|
||||
|
||||
#include "sh.h"
|
||||
|
||||
__RCSID("$MirOS: src/bin/mksh/tree.c,v 1.53 2011/12/29 22:54:22 tg Exp $");
|
||||
__RCSID("$MirOS: src/bin/mksh/tree.c,v 1.54 2011/12/29 23:36:25 tg Exp $");
|
||||
|
||||
#define INDENT 8
|
||||
|
||||
@ -133,25 +133,26 @@ ptree(struct op *t, int indent, struct shf *shf)
|
||||
#endif
|
||||
case TIF:
|
||||
i = 2;
|
||||
t1 = t;
|
||||
goto process_TIF;
|
||||
do {
|
||||
t = t->right;
|
||||
t1 = t1->right;
|
||||
i = 0;
|
||||
fptreef(shf, indent, "%;");
|
||||
process_TIF:
|
||||
/* 5 == strlen("elif ") */
|
||||
fptreef(shf, indent + 5 - i, "elif %T" + i, t->left);
|
||||
t = t->right;
|
||||
if (t->left != NULL) {
|
||||
fptreef(shf, indent + 5 - i, "elif %T" + i, t1->left);
|
||||
t1 = t1->right;
|
||||
if (t1->left != NULL) {
|
||||
fptreef(shf, indent, "%;");
|
||||
fptreef(shf, indent + INDENT, "%s%N%T",
|
||||
"then", t->left);
|
||||
"then", t1->left);
|
||||
}
|
||||
} while (t->right && t->right->type == TELIF);
|
||||
if (t->right != NULL) {
|
||||
} while (t1->right && t1->right->type == TELIF);
|
||||
if (t1->right != NULL) {
|
||||
fptreef(shf, indent, "%;");
|
||||
fptreef(shf, indent + INDENT, "%s%N%T",
|
||||
"else", t->right);
|
||||
"else", t1->right);
|
||||
}
|
||||
fptreef(shf, indent, "%;fi ");
|
||||
break;
|
||||
|
Loading…
x
Reference in New Issue
Block a user