fix tree printing multiple heredocs in one command, bug found by izabera

This commit is contained in:
tg 2015-09-05 20:20:48 +00:00
parent 4adcfe8b58
commit edc2acd61d
4 changed files with 76 additions and 29 deletions

48
check.t
View File

@ -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:
@ -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

10
lex.c
View File

@ -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
View File

@ -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
View File

@ -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;
}