fix tree printing multiple heredocs in one command, bug found by izabera
This commit is contained in:
parent
4adcfe8b58
commit
edc2acd61d
84
check.t
84
check.t
@ -1,9 +1,9 @@
|
||||
# $MirOS: src/bin/mksh/check.t,v 1.705 2015/08/13 22:06:19 tg Exp $
|
||||
# $MirOS: src/bin/mksh/check.t,v 1.706 2015/09/05 20:20:42 tg Exp $
|
||||
# -*- mode: sh -*-
|
||||
#-
|
||||
# Copyright © 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
|
||||
# 2011, 2012, 2013, 2014, 2015
|
||||
# Thorsten Glaser <tg@mirbsd.org>
|
||||
# mirabilos <tg@mirbsd.org>
|
||||
#
|
||||
# Provided that these terms and disclaimer and all copyright notices
|
||||
# are retained or reproduced in an accompanying document, permission
|
||||
@ -30,7 +30,7 @@
|
||||
# (2013/12/02 20:39:44) http://openbsd.cs.toronto.edu/cgi-bin/cvsweb/src/regress/bin/ksh/?sortby=date
|
||||
|
||||
expected-stdout:
|
||||
@(#)MIRBSD KSH R51 2015/08/13
|
||||
@(#)MIRBSD KSH R51 2015/09/05
|
||||
description:
|
||||
Check version of shell.
|
||||
stdin:
|
||||
@ -39,7 +39,7 @@ name: KSH_VERSION
|
||||
category: shell:legacy-no
|
||||
---
|
||||
expected-stdout:
|
||||
@(#)LEGACY KSH R51 2015/08/13
|
||||
@(#)LEGACY KSH R51 2015/09/05
|
||||
description:
|
||||
Check version of legacy shell.
|
||||
stdin:
|
||||
@ -2423,7 +2423,7 @@ stdin:
|
||||
print -r -- "| ${v//$'\n'/^} |"
|
||||
expected-stdout:
|
||||
function foo {
|
||||
vc=<<-EOF
|
||||
vc=<<-EOF
|
||||
=c $x \x40=
|
||||
EOF
|
||||
|
||||
@ -2476,11 +2476,11 @@ stdin:
|
||||
print -r -- "| ${v//$'\n'/^} |"
|
||||
expected-stdout:
|
||||
function foo {
|
||||
vc=<<-
|
||||
vc=<<-
|
||||
=c $x \x40=
|
||||
<<
|
||||
|
||||
vd=<<-""
|
||||
vd=<<-""
|
||||
=d $x \x40=
|
||||
|
||||
|
||||
@ -2538,6 +2538,46 @@ expected-stdout:
|
||||
3 baz a b baz
|
||||
3 bla "a b" bla
|
||||
---
|
||||
name: heredoc-14
|
||||
description:
|
||||
Check that using multiple here documents works
|
||||
stdin:
|
||||
foo() {
|
||||
echo "got $(cat) on stdin"
|
||||
echo "got $(cat <&4) on fd#4"
|
||||
echo "got $(cat <&5) on fd#5"
|
||||
}
|
||||
bar() {
|
||||
foo 4<<-a <<-b 5<<-c
|
||||
four
|
||||
a
|
||||
zero
|
||||
b
|
||||
five
|
||||
c
|
||||
}
|
||||
x=$(typeset -f bar)
|
||||
eval "$x"
|
||||
y=$(typeset -f bar)
|
||||
[[ $x = "$y" ]]; echo $?
|
||||
typeset -f bar
|
||||
bar
|
||||
expected-stdout:
|
||||
0
|
||||
bar() {
|
||||
foo 4<<-a <<-b 5<<-c
|
||||
four
|
||||
a
|
||||
zero
|
||||
b
|
||||
five
|
||||
c
|
||||
|
||||
}
|
||||
got zero on stdin
|
||||
got four on fd#4
|
||||
got five on fd#5
|
||||
---
|
||||
name: heredoc-comsub-1
|
||||
description:
|
||||
Tests for here documents in COMSUB, taken from Austin ML
|
||||
@ -10566,7 +10606,7 @@ expected-stdout:
|
||||
EOFN
|
||||
}
|
||||
inline_IOWRITE_IOCLOB_IOHERE_noIOSKIP() {
|
||||
cat >|bar <<"EOFN"
|
||||
cat >|bar <<"EOFN"
|
||||
foo
|
||||
EOFN
|
||||
|
||||
@ -10577,7 +10617,7 @@ expected-stdout:
|
||||
EOFN
|
||||
); }
|
||||
function comsub_IOWRITE_IOCLOB_IOHERE_noIOSKIP {
|
||||
x=$(cat >|bar <<"EOFN"
|
||||
x=$(cat >|bar <<"EOFN"
|
||||
foo
|
||||
EOFN
|
||||
)
|
||||
@ -10588,7 +10628,7 @@ expected-stdout:
|
||||
EOFN
|
||||
)|tr u x); }
|
||||
function reread_IOWRITE_IOCLOB_IOHERE_noIOSKIP {
|
||||
x=$(( cat >|bar <<"EOFN"
|
||||
x=$(( cat >|bar <<"EOFN"
|
||||
foo
|
||||
EOFN
|
||||
) | tr u x )
|
||||
@ -10599,7 +10639,7 @@ expected-stdout:
|
||||
EOFI
|
||||
}
|
||||
inline_IOWRITE_noIOCLOB_IOHERE_IOSKIP() {
|
||||
cat >bar <<-EOFI
|
||||
cat >bar <<-EOFI
|
||||
foo
|
||||
EOFI
|
||||
|
||||
@ -10610,7 +10650,7 @@ expected-stdout:
|
||||
EOFI
|
||||
); }
|
||||
function comsub_IOWRITE_noIOCLOB_IOHERE_IOSKIP {
|
||||
x=$(cat >bar <<-EOFI
|
||||
x=$(cat >bar <<-EOFI
|
||||
foo
|
||||
EOFI
|
||||
)
|
||||
@ -10621,7 +10661,7 @@ expected-stdout:
|
||||
EOFI
|
||||
)|tr u x); }
|
||||
function reread_IOWRITE_noIOCLOB_IOHERE_IOSKIP {
|
||||
x=$(( cat >bar <<-EOFI
|
||||
x=$(( cat >bar <<-EOFI
|
||||
foo
|
||||
EOFI
|
||||
) | tr u x )
|
||||
@ -10712,7 +10752,7 @@ expected-stdout:
|
||||
EOFN); echo $x
|
||||
}
|
||||
inline_heredoc_closed() {
|
||||
x=$(cat <<EOFN
|
||||
x=$(cat <<EOFN
|
||||
note there must be no space between EOFN and )
|
||||
EOFN
|
||||
)
|
||||
@ -10724,7 +10764,7 @@ expected-stdout:
|
||||
EOFN); echo $x
|
||||
); }
|
||||
function comsub_heredoc_closed {
|
||||
x=$(x=$(cat <<EOFN
|
||||
x=$(x=$(cat <<EOFN
|
||||
note there must be no space between EOFN and )
|
||||
EOFN
|
||||
) ; echo $x )
|
||||
@ -10735,7 +10775,7 @@ expected-stdout:
|
||||
EOFN); echo $x
|
||||
)|tr u x); }
|
||||
function reread_heredoc_closed {
|
||||
x=$(( x=$(cat <<EOFN
|
||||
x=$(( x=$(cat <<EOFN
|
||||
note there must be no space between EOFN and )
|
||||
EOFN
|
||||
) ; echo $x ) | tr u x )
|
||||
@ -10746,7 +10786,7 @@ expected-stdout:
|
||||
EOFN ); echo $x
|
||||
}
|
||||
inline_heredoc_space() {
|
||||
x=$(cat <<EOFN\
|
||||
x=$(cat <<EOFN\
|
||||
note the space between EOFN and ) is actually part of the here document marker
|
||||
EOFN
|
||||
)
|
||||
@ -10758,7 +10798,7 @@ expected-stdout:
|
||||
EOFN ); echo $x
|
||||
); }
|
||||
function comsub_heredoc_space {
|
||||
x=$(x=$(cat <<EOFN\
|
||||
x=$(x=$(cat <<EOFN\
|
||||
note the space between EOFN and ) is actually part of the here document marker
|
||||
EOFN
|
||||
) ; echo $x )
|
||||
@ -10769,7 +10809,7 @@ expected-stdout:
|
||||
EOFN ); echo $x
|
||||
)|tr u x); }
|
||||
function reread_heredoc_space {
|
||||
x=$(( x=$(cat <<EOFN\
|
||||
x=$(( x=$(cat <<EOFN\
|
||||
note the space between EOFN and ) is actually part of the here document marker
|
||||
EOFN
|
||||
) ; echo $x ) | tr u x )
|
||||
@ -10792,7 +10832,7 @@ expected-stdout:
|
||||
}
|
||||
inline_patch_motd() {
|
||||
x=$(sysctl -n kern.version | sed 1q )
|
||||
[[ -s /etc/motd && "$([[ "$(head -1 /etc/motd )" != $x ]] && ed -s /etc/motd 2>&1 <<-EOF
|
||||
[[ -s /etc/motd && "$([[ "$(head -1 /etc/motd )" != $x ]] && ed -s /etc/motd 2>&1 <<-EOF
|
||||
1,/^\$/d
|
||||
0a
|
||||
$x
|
||||
@ -10824,7 +10864,7 @@ expected-stdout:
|
||||
fi
|
||||
); }
|
||||
function comsub_patch_motd {
|
||||
x=$(x=$(sysctl -n kern.version | sed 1q ) ; [[ -s /etc/motd && "$([[ "$(head -1 /etc/motd )" != $x ]] && ed -s /etc/motd 2>&1 <<-EOF
|
||||
x=$(x=$(sysctl -n kern.version | sed 1q ) ; [[ -s /etc/motd && "$([[ "$(head -1 /etc/motd )" != $x ]] && ed -s /etc/motd 2>&1 <<-EOF
|
||||
1,/^\$/d
|
||||
0a
|
||||
$x
|
||||
@ -10851,7 +10891,7 @@ expected-stdout:
|
||||
fi
|
||||
)|tr u x); }
|
||||
function reread_patch_motd {
|
||||
x=$(( x=$(sysctl -n kern.version | sed 1q ) ; [[ -s /etc/motd && "$([[ "$(head -1 /etc/motd )" != $x ]] && ed -s /etc/motd 2>&1 <<-EOF
|
||||
x=$(( x=$(sysctl -n kern.version | sed 1q ) ; [[ -s /etc/motd && "$([[ "$(head -1 /etc/motd )" != $x ]] && ed -s /etc/motd 2>&1 <<-EOF
|
||||
1,/^\$/d
|
||||
0a
|
||||
$x
|
||||
|
10
lex.c
10
lex.c
@ -23,7 +23,7 @@
|
||||
|
||||
#include "sh.h"
|
||||
|
||||
__RCSID("$MirOS: src/bin/mksh/lex.c,v 1.206 2015/09/05 19:19:06 tg Exp $");
|
||||
__RCSID("$MirOS: src/bin/mksh/lex.c,v 1.207 2015/09/05 20:20:46 tg Exp $");
|
||||
|
||||
/*
|
||||
* states while lexing word
|
||||
@ -946,6 +946,14 @@ yylex(int cf)
|
||||
c2 = getsc();
|
||||
} else if (c2 == '<')
|
||||
iop->ioflag |= IOHERESTR;
|
||||
if (c2 == ' ') {
|
||||
/*XXX reentrancy hack IONDELIM */
|
||||
c2 = getsc();
|
||||
if (c2 != '\n') {
|
||||
ungetsc(c2);
|
||||
c2 = ' ';
|
||||
}
|
||||
}
|
||||
ungetsc(c2);
|
||||
if (c2 == '\n')
|
||||
iop->ioflag |= IONDELIM;
|
||||
|
4
sh.h
4
sh.h
@ -172,9 +172,9 @@
|
||||
#endif
|
||||
|
||||
#ifdef EXTERN
|
||||
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.742 2015/09/05 19:19:10 tg Exp $");
|
||||
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.743 2015/09/05 20:20:46 tg Exp $");
|
||||
#endif
|
||||
#define MKSH_VERSION "R51 2015/08/13"
|
||||
#define MKSH_VERSION "R51 2015/09/05"
|
||||
|
||||
/* arithmetic types: C implementation */
|
||||
#if !HAVE_CAN_INTTYPES
|
||||
|
7
tree.c
7
tree.c
@ -23,7 +23,7 @@
|
||||
|
||||
#include "sh.h"
|
||||
|
||||
__RCSID("$MirOS: src/bin/mksh/tree.c,v 1.75 2015/09/05 19:19:11 tg Exp $");
|
||||
__RCSID("$MirOS: src/bin/mksh/tree.c,v 1.76 2015/09/05 20:20:48 tg Exp $");
|
||||
|
||||
#define INDENT 8
|
||||
|
||||
@ -285,15 +285,14 @@ pioact(struct shf *shf, struct ioword *iop)
|
||||
if (type == IOHERE) {
|
||||
if (iop->delim)
|
||||
wdvarput(shf, iop->delim, 0, WDS_TPUTS);
|
||||
if (flag & IOHERESTR)
|
||||
shf_putc(' ', shf);
|
||||
/*XXX see IONDELIM hack */
|
||||
} else if (iop->name) {
|
||||
if (flag & IONAMEXP)
|
||||
print_value_quoted(shf, iop->name);
|
||||
else
|
||||
wdvarput(shf, iop->name, 0, WDS_TPUTS);
|
||||
shf_putc(' ', shf);
|
||||
}
|
||||
shf_putc(' ', shf);
|
||||
prevent_semicolon = false;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user