Merge remote-tracking branch 'mksh/master'

This commit is contained in:
KO Myung-Hun
2015-09-12 12:50:57 +09:00
24 changed files with 210 additions and 215 deletions

View File

@ -1,9 +1,9 @@
#!/bin/sh #!/bin/sh
srcversion='$MirOS: src/bin/mksh/Build.sh,v 1.689 2015/07/10 17:16:23 tg Exp $' srcversion='$MirOS: src/bin/mksh/Build.sh,v 1.690 2015/09/05 19:18:59 tg Exp $'
#- #-
# Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, # Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
# 2011, 2012, 2013, 2014, 2015 # 2011, 2012, 2013, 2014, 2015
# Thorsten “mirabilos” Glaser <tg@mirbsd.org> # mirabilos <tg@mirbsd.org>
# #
# Provided that these terms and disclaimer and all copyright notices # Provided that these terms and disclaimer and all copyright notices
# are retained or reproduced in an accompanying document, permission # are retained or reproduced in an accompanying document, permission
@ -2416,7 +2416,7 @@ cat >test.sh <<-EOF
args[\${#args[*]}]=\$TMPDIR args[\${#args[*]}]=\$TMPDIR
fi fi
print Testing mksh for conformance: print Testing mksh for conformance:
fgrep -e MirOS: -e MIRBSD "\$sflag" fgrep -e Mir''OS: -e MIRBSD "\$sflag"
print "This shell is actually:\\n\\t\$KSH_VERSION" print "This shell is actually:\\n\\t\$KSH_VERSION"
print 'test.sh built for mksh $dstversion' print 'test.sh built for mksh $dstversion'
cstr='\$os = defined \$^O ? \$^O : "unknown";' cstr='\$os = defined \$^O ? \$^O : "unknown";'

View File

@ -1,8 +1,8 @@
# $MirOS: src/bin/mksh/Makefile,v 1.142 2015/07/09 20:52:36 tg Exp $ # $MirOS: src/bin/mksh/Makefile,v 1.143 2015/09/05 19:19:00 tg Exp $
#- #-
# Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, # Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
# 2011, 2012, 2013, 2014, 2015 # 2011, 2012, 2013, 2014, 2015
# Thorsten “mirabilos” Glaser <tg@mirbsd.org> # mirabilos <tg@mirbsd.org>
# #
# Provided that these terms and disclaimer and all copyright notices # Provided that these terms and disclaimer and all copyright notices
# are retained or reproduced in an accompanying document, permission # are retained or reproduced in an accompanying document, permission
@ -154,7 +154,7 @@ cats: ${MANALL} ${MANALL:S/.cat/.ps/}
.endif .endif
.for _m _n in mksh 1 .for _m _n in mksh 1
x=$$(ident ${SRCDIR:Q}/${_m}.${_n} | \ x=$$(ident ${SRCDIR:Q}/${_m}.${_n} | \
awk '/MirOS:/ { print $$4$$5; }' | \ awk '/Mir''OS:/ { print $$4$$5; }' | \
tr -dc 0-9); (( $${#x} == 14 )) || exit 1; exec \ tr -dc 0-9); (( $${#x} == 14 )) || exit 1; exec \
${MKSH} ${BSDSRCDIR:Q}/contrib/hosted/tg/ps2pdfmir -c \ ${MKSH} ${BSDSRCDIR:Q}/contrib/hosted/tg/ps2pdfmir -c \
-o ${_m}.${_n}.pdf '[' /Author '(The MirOS Project)' \ -o ${_m}.${_n}.pdf '[' /Author '(The MirOS Project)' \

View File

@ -1,9 +1,9 @@
# $MirOS: src/bin/mksh/check.pl,v 1.40 2015/07/10 19:36:31 tg Exp $ # $MirOS: src/bin/mksh/check.pl,v 1.41 2015/09/05 19:19:01 tg Exp $
# $OpenBSD: th,v 1.1 2013/12/02 20:39:44 millert Exp $ # $OpenBSD: th,v 1.1 2013/12/02 20:39:44 millert Exp $
#- #-
# Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2011, # Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2011,
# 2012, 2013, 2014, 2015 # 2012, 2013, 2014, 2015
# Thorsten Glaser <tg@mirbsd.org> # mirabilos <tg@mirbsd.org>
# #
# Provided that these terms and disclaimer and all copyright notices # Provided that these terms and disclaimer and all copyright notices
# are retained or reproduced in an accompanying document, permission # are retained or reproduced in an accompanying document, permission

89
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.707 2015/09/06 19:46:56 tg Exp $
# -*- mode: sh -*- # -*- mode: sh -*-
#- #-
# Copyright © 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, # Copyright © 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
# 2011, 2012, 2013, 2014, 2015 # 2011, 2012, 2013, 2014, 2015
# Thorsten Glaser <tg@mirbsd.org> # mirabilos <tg@mirbsd.org>
# #
# Provided that these terms and disclaimer and all copyright notices # Provided that these terms and disclaimer and all copyright notices
# are retained or reproduced in an accompanying document, permission # 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 # (2013/12/02 20:39:44) http://openbsd.cs.toronto.edu/cgi-bin/cvsweb/src/regress/bin/ksh/?sortby=date
expected-stdout: expected-stdout:
@(#)MIRBSD KSH R51 2015/08/13 @(#)MIRBSD KSH R51 2015/09/06
description: description:
Check version of shell. Check version of shell.
stdin: stdin:
@ -39,7 +39,7 @@ name: KSH_VERSION
category: shell:legacy-no category: shell:legacy-no
--- ---
expected-stdout: expected-stdout:
@(#)LEGACY KSH R51 2015/08/13 @(#)LEGACY KSH R51 2015/09/06
description: description:
Check version of legacy shell. Check version of legacy shell.
stdin: stdin:
@ -2325,6 +2325,8 @@ stdin:
tr abcdefghijklmnopqrstuvwxyz nopqrstuvwxyzabcdefghijklm <<<\$bar tr abcdefghijklmnopqrstuvwxyz nopqrstuvwxyzabcdefghijklm <<<\$bar
tr abcdefghijklmnopqrstuvwxyz nopqrstuvwxyzabcdefghijklm <<<-foo tr abcdefghijklmnopqrstuvwxyz nopqrstuvwxyzabcdefghijklm <<<-foo
tr abcdefghijklmnopqrstuvwxyz nopqrstuvwxyzabcdefghijklm <<<"$(echo "foo bar")" tr abcdefghijklmnopqrstuvwxyz nopqrstuvwxyzabcdefghijklm <<<"$(echo "foo bar")"
tr abcdefghijklmnopqrstuvwxyz nopqrstuvwxyzabcdefghijklm <<<"A $(echo "foo bar") B"
tr abcdefghijklmnopqrstuvwxyz nopqrstuvwxyzabcdefghijklm <<<\$b\$b$bar
expected-stdout: expected-stdout:
sbb sbb
sbb sbb
@ -2334,6 +2336,9 @@ expected-stdout:
$one $one
-sbb -sbb
sbb one sbb one
A sbb one B
$o$oone
onm
--- ---
name: heredoc-9b name: heredoc-9b
description: description:
@ -2423,7 +2428,7 @@ stdin:
print -r -- "| ${v//$'\n'/^} |" print -r -- "| ${v//$'\n'/^} |"
expected-stdout: expected-stdout:
function foo { function foo {
vc=<<-EOF vc=<<-EOF
=c $x \x40= =c $x \x40=
EOF EOF
@ -2476,11 +2481,11 @@ stdin:
print -r -- "| ${v//$'\n'/^} |" print -r -- "| ${v//$'\n'/^} |"
expected-stdout: expected-stdout:
function foo { function foo {
vc=<<- vc=<<-
=c $x \x40= =c $x \x40=
<< <<
vd=<<-"" vd=<<-""
=d $x \x40= =d $x \x40=
@ -2538,6 +2543,46 @@ expected-stdout:
3 baz a b baz 3 baz a b baz
3 bla "a b" bla 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 name: heredoc-comsub-1
description: description:
Tests for here documents in COMSUB, taken from Austin ML Tests for here documents in COMSUB, taken from Austin ML
@ -10566,7 +10611,7 @@ expected-stdout:
)|tr u x); } )|tr u x); }
function reread_IOREAD_IOCAT { function reread_IOREAD_IOCAT {
x=$(( tr x u <foo >>bar ) | tr u x ) x=$(( tr x u <foo >>bar ) | tr u x )
} }
inline_IOWRITE_IOCLOB_IOHERE_noIOSKIP() { inline_IOWRITE_IOCLOB_IOHERE_noIOSKIP() {
cat >|bar <<'EOFN' cat >|bar <<'EOFN'
foo foo
@ -10577,7 +10622,7 @@ expected-stdout:
foo foo
EOFN EOFN
} }
function comsub_IOWRITE_IOCLOB_IOHERE_noIOSKIP { x=$( function comsub_IOWRITE_IOCLOB_IOHERE_noIOSKIP { x=$(
cat >|bar <<'EOFN' cat >|bar <<'EOFN'
foo foo
@ -10588,7 +10633,7 @@ expected-stdout:
foo foo
EOFN EOFN
) )
} }
function reread_IOWRITE_IOCLOB_IOHERE_noIOSKIP { x=$(( function reread_IOWRITE_IOCLOB_IOHERE_noIOSKIP { x=$((
cat >|bar <<'EOFN' cat >|bar <<'EOFN'
foo foo
@ -10599,7 +10644,7 @@ expected-stdout:
foo foo
EOFN EOFN
) | tr u x ) ) | tr u x )
} }
inline_IOWRITE_noIOCLOB_IOHERE_IOSKIP() { inline_IOWRITE_noIOCLOB_IOHERE_IOSKIP() {
cat 1>bar <<-EOFI cat 1>bar <<-EOFI
foo foo
@ -10610,7 +10655,7 @@ expected-stdout:
foo foo
EOFI EOFI
} }
function comsub_IOWRITE_noIOCLOB_IOHERE_IOSKIP { x=$( function comsub_IOWRITE_noIOCLOB_IOHERE_IOSKIP { x=$(
cat 1>bar <<-EOFI cat 1>bar <<-EOFI
foo foo
@ -10621,7 +10666,7 @@ expected-stdout:
foo foo
EOFI EOFI
) )
} }
function reread_IOWRITE_noIOCLOB_IOHERE_IOSKIP { x=$(( function reread_IOWRITE_noIOCLOB_IOHERE_IOSKIP { x=$((
cat 1>bar <<-EOFI cat 1>bar <<-EOFI
foo foo
@ -10712,7 +10757,7 @@ expected-stdout:
)|tr u x); } )|tr u x); }
function reread_OSUBST_CSUBST_OPAT_SPAT_CPAT { function reread_OSUBST_CSUBST_OPAT_SPAT_CPAT {
x=$(( [[ ${foo#bl\(u\)b} = @(bar|baz) ]] ) | tr u x ) x=$(( [[ ${foo#bl\(u\)b} = @(bar|baz) ]] ) | tr u x )
} }
inline_heredoc_closed() { inline_heredoc_closed() {
x=$(cat <<EOFN x=$(cat <<EOFN
note there must be no space between EOFN and ) note there must be no space between EOFN and )
@ -10724,7 +10769,7 @@ expected-stdout:
EOFN EOFN
) )
echo $x echo $x
} }
function comsub_heredoc_closed { x=$( function comsub_heredoc_closed { x=$(
x=$(cat <<EOFN x=$(cat <<EOFN
note there must be no space between EOFN and ) note there must be no space between EOFN and )
@ -10735,7 +10780,7 @@ expected-stdout:
note there must be no space between EOFN and ) note there must be no space between EOFN and )
EOFN EOFN
) ; echo $x ) ) ; echo $x )
} }
function reread_heredoc_closed { x=$(( function reread_heredoc_closed { x=$((
x=$(cat <<EOFN x=$(cat <<EOFN
note there must be no space between EOFN and ) note there must be no space between EOFN and )
@ -10746,7 +10791,7 @@ expected-stdout:
note there must be no space between EOFN and ) note there must be no space between EOFN and )
EOFN EOFN
) ; echo $x ) | tr u x ) ) ; echo $x ) | tr u x )
} }
inline_heredoc_space() { inline_heredoc_space() {
x=$(cat <<EOFN\ x=$(cat <<EOFN\
note the space between EOFN and ) is actually part of the here document marker note the space between EOFN and ) is actually part of the here document marker
@ -10758,7 +10803,7 @@ expected-stdout:
EOFN EOFN
) )
echo $x echo $x
} }
function comsub_heredoc_space { x=$( function comsub_heredoc_space { x=$(
x=$(cat <<EOFN\ x=$(cat <<EOFN\
note the space between EOFN and ) is actually part of the here document marker note the space between EOFN and ) is actually part of the here document marker
@ -10769,7 +10814,7 @@ expected-stdout:
note the space between EOFN and ) is actually part of the here document marker note the space between EOFN and ) is actually part of the here document marker
EOFN EOFN
) ; echo $x ) ) ; echo $x )
} }
function reread_heredoc_space { x=$(( function reread_heredoc_space { x=$((
x=$(cat <<EOFN\ x=$(cat <<EOFN\
note the space between EOFN and ) is actually part of the here document marker note the space between EOFN and ) is actually part of the here document marker
@ -10792,7 +10837,7 @@ expected-stdout:
. .
wq wq
EOF)" = @(?) ]] && rm -f /etc/motd EOF)" = @(?) ]] && rm -f /etc/motd
if [[ ! -s /etc/motd ]]; then if [[ ! -s /etc/motd ]]; then
install -c -o root -g wheel -m 664 /dev/null /etc/motd install -c -o root -g wheel -m 664 /dev/null /etc/motd
print -- "$x\n" >/etc/motd print -- "$x\n" >/etc/motd
fi fi
@ -10824,7 +10869,7 @@ expected-stdout:
. .
wq wq
EOF)" = @(?) ]] && rm -f /etc/motd EOF)" = @(?) ]] && rm -f /etc/motd
if [[ ! -s /etc/motd ]]; then if [[ ! -s /etc/motd ]]; then
install -c -o root -g wheel -m 664 /dev/null /etc/motd install -c -o root -g wheel -m 664 /dev/null /etc/motd
print -- "$x\n" >/etc/motd print -- "$x\n" >/etc/motd
@ -10851,7 +10896,7 @@ expected-stdout:
. .
wq wq
EOF)" = @(?) ]] && rm -f /etc/motd EOF)" = @(?) ]] && rm -f /etc/motd
if [[ ! -s /etc/motd ]]; then if [[ ! -s /etc/motd ]]; then
install -c -o root -g wheel -m 664 /dev/null /etc/motd install -c -o root -g wheel -m 664 /dev/null /etc/motd
print -- "$x\n" >/etc/motd print -- "$x\n" >/etc/motd

20
edit.c
View File

@ -1,12 +1,12 @@
/* $OpenBSD: edit.c,v 1.40 2015/03/12 10:20:30 sthen Exp $ */ /* $OpenBSD: edit.c,v 1.41 2015/09/01 13:12:31 tedu Exp $ */
/* $OpenBSD: edit.h,v 1.9 2011/05/30 17:14:35 martynas Exp $ */ /* $OpenBSD: edit.h,v 1.9 2011/05/30 17:14:35 martynas Exp $ */
/* $OpenBSD: emacs.c,v 1.50 2015/03/25 12:10:52 jca Exp $ */ /* $OpenBSD: emacs.c,v 1.51 2015/09/01 13:12:31 tedu Exp $ */
/* $OpenBSD: vi.c,v 1.28 2013/12/18 16:45:46 deraadt Exp $ */ /* $OpenBSD: vi.c,v 1.29 2015/09/01 13:12:31 tedu Exp $ */
/*- /*-
* Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, * Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
* 2011, 2012, 2013, 2014 * 2011, 2012, 2013, 2014, 2015
* Thorsten Glaser <tg@mirbsd.org> * mirabilos <tg@mirbsd.org>
* *
* Provided that these terms and disclaimer and all copyright notices * Provided that these terms and disclaimer and all copyright notices
* are retained or reproduced in an accompanying document, permission * are retained or reproduced in an accompanying document, permission
@ -28,7 +28,7 @@
#ifndef MKSH_NO_CMDLINE_EDITING #ifndef MKSH_NO_CMDLINE_EDITING
__RCSID("$MirOS: src/bin/mksh/edit.c,v 1.290 2015/07/10 19:36:34 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/edit.c,v 1.291 2015/09/05 19:19:01 tg Exp $");
/* /*
* in later versions we might use libtermcap for this, but since external * in later versions we might use libtermcap for this, but since external
@ -2266,12 +2266,8 @@ x_kill(int c MKSH_A_UNUSED)
static void static void
x_push(int nchars) x_push(int nchars)
{ {
char *cp; afree(killstack[killsp], AEDIT);
strndupx(killstack[killsp], xcp, nchars, AEDIT);
strndupx(cp, xcp, nchars, AEDIT);
if (killstack[killsp])
afree(killstack[killsp], AEDIT);
killstack[killsp] = cp;
killsp = (killsp + 1) % KILLSIZE; killsp = (killsp + 1) % KILLSIZE;
} }

6
eval.c
View File

@ -3,7 +3,7 @@
/*- /*-
* Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, * Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
* 2011, 2012, 2013, 2014, 2015 * 2011, 2012, 2013, 2014, 2015
* Thorsten Glaser <tg@mirbsd.org> * mirabilos <tg@mirbsd.org>
* *
* Provided that these terms and disclaimer and all copyright notices * Provided that these terms and disclaimer and all copyright notices
* are retained or reproduced in an accompanying document, permission * are retained or reproduced in an accompanying document, permission
@ -23,7 +23,7 @@
#include "sh.h" #include "sh.h"
__RCSID("$MirOS: src/bin/mksh/eval.c,v 1.170 2015/07/06 17:45:33 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/eval.c,v 1.172 2015/09/06 19:46:59 tg Exp $");
/* /*
* string expansion * string expansion
@ -919,6 +919,8 @@ expand(
(word == IFS_IWS || word == IFS_NWS) && (word == IFS_IWS || word == IFS_NWS) &&
!ctype(c, C_IFSWS))) { !ctype(c, C_IFSWS))) {
emit_word: emit_word:
if (f & DOHERESTR)
*dp++ = '\n';
*dp++ = '\0'; *dp++ = '\0';
cp = Xclose(ds, dp); cp = Xclose(ds, dp);
if (fdo & DOBRACE) if (fdo & DOBRACE)

20
exec.c
View File

@ -3,7 +3,7 @@
/*- /*-
* Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, * Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
* 2011, 2012, 2013, 2014, 2015 * 2011, 2012, 2013, 2014, 2015
* Thorsten Glaser <tg@mirbsd.org> * mirabilos <tg@mirbsd.org>
* *
* Provided that these terms and disclaimer and all copyright notices * Provided that these terms and disclaimer and all copyright notices
* are retained or reproduced in an accompanying document, permission * are retained or reproduced in an accompanying document, permission
@ -23,7 +23,7 @@
#include "sh.h" #include "sh.h"
__RCSID("$MirOS: src/bin/mksh/exec.c,v 1.160 2015/07/10 19:36:35 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/exec.c,v 1.163 2015/09/06 19:46:59 tg Exp $");
#ifndef MKSH_DEFAULT_EXECSHELL #ifndef MKSH_DEFAULT_EXECSHELL
#define MKSH_DEFAULT_EXECSHELL MKSH_UNIXROOT "/bin/sh" #define MKSH_DEFAULT_EXECSHELL MKSH_UNIXROOT "/bin/sh"
@ -1524,7 +1524,7 @@ iosetup(struct ioword *iop, struct tbl *tp)
char *sp; char *sp;
eno = errno; eno = errno;
warningf(true, "%s %s %s", warningf(true, "%s %s: %s",
"can't finish (dup) redirection", "can't finish (dup) redirection",
(sp = snptreef(NULL, 32, "%R", &iotmp)), (sp = snptreef(NULL, 32, "%R", &iotmp)),
cstrerror(eno)); cstrerror(eno));
@ -1560,9 +1560,9 @@ iosetup(struct ioword *iop, struct tbl *tp)
* unquoted, the string is expanded first. * unquoted, the string is expanded first.
*/ */
static int static int
hereinval(const char *content, int sub, char **resbuf, struct shf *shf) hereinval(struct ioword *iop, int sub, char **resbuf, struct shf *shf)
{ {
const char * volatile ccp = content; const char * volatile ccp = iop->heredoc;
struct source *s, *osource; struct source *s, *osource;
osource = source; osource = source;
@ -1573,7 +1573,9 @@ hereinval(const char *content, int sub, char **resbuf, struct shf *shf)
/* special to iosetup(): don't print error */ /* special to iosetup(): don't print error */
return (-2); return (-2);
} }
if (sub) { if (iop->ioflag & IOHERESTR) {
ccp = evalstr(iop->delim, DOHERESTR | DOSCALAR | DOHEREDOC);
} else if (sub) {
/* do substitutions on the content of heredoc */ /* do substitutions on the content of heredoc */
s = pushs(SSTRING, ATEMP); s = pushs(SSTRING, ATEMP);
s->start = s->str = ccp; s->start = s->str = ccp;
@ -1602,7 +1604,7 @@ herein(struct ioword *iop, char **resbuf)
int i; int i;
/* ksh -c 'cat <<EOF' can cause this... */ /* ksh -c 'cat <<EOF' can cause this... */
if (iop->heredoc == NULL) { if (iop->heredoc == NULL && !(iop->ioflag & IOHERESTR)) {
warningf(true, "%s missing", "here document"); warningf(true, "%s missing", "here document");
/* special to iosetup(): don't print error */ /* special to iosetup(): don't print error */
return (-2); return (-2);
@ -1613,7 +1615,7 @@ herein(struct ioword *iop, char **resbuf)
/* skip all the fd setup if we just want the value */ /* skip all the fd setup if we just want the value */
if (resbuf != NULL) if (resbuf != NULL)
return (hereinval(iop->heredoc, i, resbuf, NULL)); return (hereinval(iop, i, resbuf, NULL));
/* /*
* Create temp file to hold content (done before newenv * Create temp file to hold content (done before newenv
@ -1630,7 +1632,7 @@ herein(struct ioword *iop, char **resbuf)
return (-2); return (-2);
} }
if (hereinval(iop->heredoc, i, NULL, shf) == -2) { if (hereinval(iop, i, NULL, shf) == -2) {
close(fd); close(fd);
/* special to iosetup(): don't print error */ /* special to iosetup(): don't print error */
return (-2); return (-2);

4
expr.c
View File

@ -3,7 +3,7 @@
/*- /*-
* Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, * Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
* 2011, 2012, 2013, 2014 * 2011, 2012, 2013, 2014
* Thorsten Glaser <tg@mirbsd.org> * mirabilos <tg@mirbsd.org>
* *
* Provided that these terms and disclaimer and all copyright notices * Provided that these terms and disclaimer and all copyright notices
* are retained or reproduced in an accompanying document, permission * are retained or reproduced in an accompanying document, permission
@ -23,7 +23,7 @@
#include "sh.h" #include "sh.h"
__RCSID("$MirOS: src/bin/mksh/expr.c,v 1.77 2014/12/15 23:26:36 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/expr.c,v 1.78 2015/09/05 19:19:03 tg Exp $");
/* the order of these enums is constrained by the order of opinfo[] */ /* the order of these enums is constrained by the order of opinfo[] */
enum token { enum token {

View File

@ -1,4 +1,4 @@
/* $OpenBSD: c_ksh.c,v 1.34 2013/12/17 16:37:05 deraadt Exp $ */ /* $OpenBSD: c_ksh.c,v 1.35 2015/09/01 13:12:31 tedu Exp $ */
/* $OpenBSD: c_sh.c,v 1.46 2015/07/20 20:46:24 guenther Exp $ */ /* $OpenBSD: c_sh.c,v 1.46 2015/07/20 20:46:24 guenther Exp $ */
/* $OpenBSD: c_test.c,v 1.18 2009/03/01 20:11:06 otto Exp $ */ /* $OpenBSD: c_test.c,v 1.18 2009/03/01 20:11:06 otto Exp $ */
/* $OpenBSD: c_ulimit.c,v 1.19 2013/11/28 10:33:37 sobrado Exp $ */ /* $OpenBSD: c_ulimit.c,v 1.19 2013/11/28 10:33:37 sobrado Exp $ */
@ -6,7 +6,7 @@
/*- /*-
* Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
* 2010, 2011, 2012, 2013, 2014, 2015 * 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 * Provided that these terms and disclaimer and all copyright notices
* are retained or reproduced in an accompanying document, permission * are retained or reproduced in an accompanying document, permission
@ -38,7 +38,7 @@
#endif #endif
#endif #endif
__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.282 2015/08/13 21:38:17 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.283 2015/09/05 19:19:04 tg Exp $");
#if HAVE_KILLPG #if HAVE_KILLPG
/* /*

View File

@ -1,10 +1,10 @@
/* $OpenBSD: history.c,v 1.40 2014/11/20 15:22:39 tedu Exp $ */ /* $OpenBSD: history.c,v 1.41 2015/09/01 13:12:31 tedu Exp $ */
/* $OpenBSD: trap.c,v 1.23 2010/05/19 17:36:08 jasper Exp $ */ /* $OpenBSD: trap.c,v 1.23 2010/05/19 17:36:08 jasper Exp $ */
/*- /*-
* Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, * Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
* 2011, 2012, 2014, 2015 * 2011, 2012, 2014, 2015
* Thorsten Glaser <tg@mirbsd.org> * mirabilos <tg@mirbsd.org>
* *
* Provided that these terms and disclaimer and all copyright notices * Provided that these terms and disclaimer and all copyright notices
* are retained or reproduced in an accompanying document, permission * are retained or reproduced in an accompanying document, permission
@ -27,7 +27,7 @@
#include <sys/file.h> #include <sys/file.h>
#endif #endif
__RCSID("$MirOS: src/bin/mksh/histrap.c,v 1.149 2015/07/09 20:52:40 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/histrap.c,v 1.150 2015/09/05 19:19:05 tg Exp $");
Trap sigtraps[ksh_NSIG + 1]; Trap sigtraps[ksh_NSIG + 1];
static struct sigaction Sigact_ign; static struct sigaction Sigact_ign;
@ -898,8 +898,7 @@ histload(Source *s, unsigned char *base, size_t bytes)
if (lno >= s->line - (histptr - history) && lno <= s->line) { if (lno >= s->line - (histptr - history) && lno <= s->line) {
hp = &histptr[lno - s->line]; hp = &histptr[lno - s->line];
if (*hp) afree(*hp, APERM);
afree(*hp, APERM);
strdupx(*hp, (char *)(base + 4), APERM); strdupx(*hp, (char *)(base + 4), APERM);
} }
} else { } else {
@ -1376,8 +1375,7 @@ settrap(Trap *p, const char *s)
{ {
sig_t f; sig_t f;
if (p->trap) afree(p->trap, APERM);
afree(p->trap, APERM);
/* handles s == NULL */ /* handles s == NULL */
strdupx(p->trap, s, APERM); strdupx(p->trap, s, APERM);
p->flags |= TF_CHANGED; p->flags |= TF_CHANGED;

6
jobs.c
View File

@ -3,7 +3,7 @@
/*- /*-
* Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2011, * Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2011,
* 2012, 2013, 2014, 2015 * 2012, 2013, 2014, 2015
* Thorsten Glaser <tg@mirbsd.org> * mirabilos <tg@mirbsd.org>
* *
* Provided that these terms and disclaimer and all copyright notices * Provided that these terms and disclaimer and all copyright notices
* are retained or reproduced in an accompanying document, permission * are retained or reproduced in an accompanying document, permission
@ -23,7 +23,7 @@
#include "sh.h" #include "sh.h"
__RCSID("$MirOS: src/bin/mksh/jobs.c,v 1.113 2015/08/13 21:38:19 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/jobs.c,v 1.115 2015/09/05 19:19:05 tg Exp $");
#if HAVE_KILLPG #if HAVE_KILLPG
#define mksh_killpg killpg #define mksh_killpg killpg
@ -892,7 +892,7 @@ j_resume(const char *cp, int bg)
(long)kshpgrp, "failed", cstrerror(errno)); (long)kshpgrp, "failed", cstrerror(errno));
} }
sigprocmask(SIG_SETMASK, &omask, NULL); sigprocmask(SIG_SETMASK, &omask, NULL);
bi_errorf("%s %s %s", "can't continue job", bi_errorf("%s %s: %s", "can't continue job",
cp, cstrerror(eno)); cp, cstrerror(eno));
return (1); return (1);
} }

View File

@ -1,6 +1,6 @@
/*- /*-
* Copyright (c) 2009, 2010, 2011, 2013, 2014 * Copyright (c) 2009, 2010, 2011, 2013, 2014
* Thorsten Glaser <tg@mirbsd.org> * mirabilos <tg@mirbsd.org>
* *
* Provided that these terms and disclaimer and all copyright notices * Provided that these terms and disclaimer and all copyright notices
* are retained or reproduced in an accompanying document, permission * are retained or reproduced in an accompanying document, permission
@ -20,7 +20,7 @@
#include "sh.h" #include "sh.h"
__RCSID("$MirOS: src/bin/mksh/lalloc.c,v 1.21 2014/11/25 20:00:39 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/lalloc.c,v 1.22 2015/09/05 19:19:06 tg Exp $");
/* build with CPPFLAGS+= -DUSE_REALLOC_MALLOC=0 on ancient systems */ /* build with CPPFLAGS+= -DUSE_REALLOC_MALLOC=0 on ancient systems */
#if defined(USE_REALLOC_MALLOC) && (USE_REALLOC_MALLOC == 0) #if defined(USE_REALLOC_MALLOC) && (USE_REALLOC_MALLOC == 0)

94
lex.c
View File

@ -3,7 +3,7 @@
/*- /*-
* Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, * Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
* 2011, 2012, 2013, 2014, 2015 * 2011, 2012, 2013, 2014, 2015
* Thorsten Glaser <tg@mirbsd.org> * mirabilos <tg@mirbsd.org>
* *
* Provided that these terms and disclaimer and all copyright notices * Provided that these terms and disclaimer and all copyright notices
* are retained or reproduced in an accompanying document, permission * are retained or reproduced in an accompanying document, permission
@ -23,7 +23,7 @@
#include "sh.h" #include "sh.h"
__RCSID("$MirOS: src/bin/mksh/lex.c,v 1.205 2015/08/13 21:04:12 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/lex.c,v 1.209 2015/09/06 19:47:00 tg Exp $");
/* /*
* states while lexing word * states while lexing word
@ -38,8 +38,8 @@ __RCSID("$MirOS: src/bin/mksh/lex.c,v 1.205 2015/08/13 21:04:12 tg Exp $");
#define SQBRACE 7 /* inside "${}" */ #define SQBRACE 7 /* inside "${}" */
#define SBQUOTE 8 /* inside `` */ #define SBQUOTE 8 /* inside `` */
#define SASPAREN 9 /* inside $(( )) */ #define SASPAREN 9 /* inside $(( )) */
#define SHEREDELIM 10 /* parsing <<,<<-,<<< delimiter */ #define SHEREDELIM 10 /* parsing << or <<- delimiter */
#define SHEREDQUOTE 11 /* parsing " in <<,<<-,<<< delimiter */ #define SHEREDQUOTE 11 /* parsing " in << or <<- delimiter */
#define SPATTERN 12 /* parsing *(...|...) pattern (*+?@!) */ #define SPATTERN 12 /* parsing *(...|...) pattern (*+?@!) */
#define SADELIM 13 /* like SBASE, looking for delimiter */ #define SADELIM 13 /* like SBASE, looking for delimiter */
#define STBRACEKORN 14 /* parsing ${...[#%]...} !FSH */ #define STBRACEKORN 14 /* parsing ${...[#%]...} !FSH */
@ -61,7 +61,7 @@ typedef struct lex_state {
/* point to the next state block */ /* point to the next state block */
struct lex_state *base; struct lex_state *base;
/* marks start of state output in output string */ /* marks start of state output in output string */
int start; size_t start;
/* SBQUOTE: true if in double quotes: "`...`" */ /* SBQUOTE: true if in double quotes: "`...`" */
/* SEQUOTE: got NUL, ignore rest of string */ /* SEQUOTE: got NUL, ignore rest of string */
bool abool; bool abool;
@ -98,7 +98,7 @@ static int s_get(void);
static void s_put(int); static void s_put(int);
static char *get_brace_var(XString *, char *); static char *get_brace_var(XString *, char *);
static bool arraysub(char **); static bool arraysub(char **);
static void gethere(bool); static void gethere(void);
static Lex_state *push_state_i(State_info *, Lex_state *); static Lex_state *push_state_i(State_info *, Lex_state *);
static Lex_state *pop_state_i(State_info *, Lex_state *); static Lex_state *pop_state_i(State_info *, Lex_state *);
@ -240,20 +240,6 @@ yylex(int cf)
/* Initial state: one of SWORD SLETPAREN SHEREDELIM SBASE */ /* Initial state: one of SWORD SLETPAREN SHEREDELIM SBASE */
statep->type = state; statep->type = state;
/* check for here string */
if (state == SHEREDELIM) {
c = getsc();
if (c == '<') {
state = SHEREDELIM;
while ((c = getsc()) == ' ' || c == '\t')
;
ungetsc(c);
c = '<';
goto accept_nonword;
}
ungetsc(c);
}
/* collect non-special or quoted characters to form word */ /* collect non-special or quoted characters to form word */
while (!((c = getsc()) == 0 || while (!((c = getsc()) == 0 ||
((state == SBASE || state == SHEREDELIM) && ctype(c, C_LEX1)))) { ((state == SBASE || state == SHEREDELIM) && ctype(c, C_LEX1)))) {
@ -262,7 +248,6 @@ yylex(int cf)
c == /*{*/ '}') c == /*{*/ '}')
/* possibly end ${ :;} */ /* possibly end ${ :;} */
break; break;
accept_nonword:
Xcheck(ws, wp); Xcheck(ws, wp);
switch (state) { switch (state) {
case SADELIM: case SADELIM:
@ -806,7 +791,7 @@ yylex(int cf)
++statep->nparen; ++statep->nparen;
goto Sbase2; goto Sbase2;
/* <<, <<-, <<< delimiter */ /* << or <<- delimiter */
case SHEREDELIM: case SHEREDELIM:
/* /*
* here delimiters need a special case since * here delimiters need a special case since
@ -844,7 +829,7 @@ yylex(int cf)
} }
break; break;
/* " in <<, <<-, <<< delimiter */ /* " in << or <<- delimiter */
case SHEREDQUOTE: case SHEREDQUOTE:
if (c != '"') if (c != '"')
goto Subst; goto Subst;
@ -941,14 +926,12 @@ yylex(int cf)
iop->ioflag |= c == c2 ? iop->ioflag |= c == c2 ?
(c == '>' ? IOCAT : IOHERE) : IORDWR; (c == '>' ? IOCAT : IOHERE) : IORDWR;
if (iop->ioflag == IOHERE) { if (iop->ioflag == IOHERE) {
if ((c2 = getsc()) == '-') { if ((c2 = getsc()) == '-')
iop->ioflag |= IOSKIP; iop->ioflag |= IOSKIP;
c2 = getsc(); else if (c2 == '<')
} else if (c2 == '<')
iop->ioflag |= IOHERESTR; iop->ioflag |= IOHERESTR;
ungetsc(c2); else
if (c2 == '\n') ungetsc(c2);
iop->ioflag |= IONDELIM;
} }
} else if (c2 == '&') } else if (c2 == '&')
iop->ioflag |= IODUP | (c == '<' ? IORDUP : 0); iop->ioflag |= IODUP | (c == '<' ? IORDUP : 0);
@ -998,12 +981,14 @@ yylex(int cf)
} }
#endif #endif
} else if (c == '\n') { } else if (c == '\n') {
gethere(false); if (cf & HEREDELIM)
if (cf & CONTIN) ungetsc(c);
goto Again; else {
} else if (c == '\0') gethere();
/* need here strings at EOF */ if (cf & CONTIN)
gethere(true); goto Again;
}
}
return (c); return (c);
} }
@ -1026,23 +1011,8 @@ yylex(int cf)
/* copy word to unprefixed string ident */ /* copy word to unprefixed string ident */
sp = yylval.cp; sp = yylval.cp;
dp = ident; dp = ident;
if ((cf & HEREDELIM) && (sp[1] == '<')) { while ((dp - ident) < IDENT && (c = *sp++) == CHAR)
herestringloop: *dp++ = *sp++;
switch ((c = *sp++)) {
case CHAR:
++sp;
/* FALLTHROUGH */
case OQUOTE:
case CQUOTE:
goto herestringloop;
default:
break;
}
/* dummy value */
*dp++ = 'x';
} else
while ((dp - ident) < IDENT && (c = *sp++) == CHAR)
*dp++ = *sp++;
if (c != EOS) if (c != EOS)
/* word is not unquoted */ /* word is not unquoted */
dp = ident; dp = ident;
@ -1118,15 +1088,12 @@ yylex(int cf)
} }
static void static void
gethere(bool iseof) gethere(void)
{ {
struct ioword **p; struct ioword **p;
for (p = heres; p < herep; p++) for (p = heres; p < herep; p++)
if (iseof && !((*p)->ioflag & IOHERESTR)) if (!((*p)->ioflag & IOHERESTR))
/* only here strings at EOF */
return;
else
readhere(*p); readhere(*p);
herep = heres; herep = heres;
} }
@ -1142,18 +1109,9 @@ readhere(struct ioword *iop)
const char *eof, *eofp; const char *eof, *eofp;
XString xs; XString xs;
char *xp; char *xp;
int xpos; size_t xpos;
if (iop->ioflag & IOHERESTR) { eof = evalstr(iop->delim, 0);
/* process the here string */
iop->heredoc = xp = evalstr(iop->delim, DOBLANK);
xpos = strlen(xp) - 1;
memmove(xp, xp + 1, xpos);
xp[xpos] = '\n';
return;
}
eof = iop->ioflag & IONDELIM ? "<<" : evalstr(iop->delim, 0);
if (!(iop->ioflag & IOEVAL)) if (!(iop->ioflag & IOEVAL))
ignore_backslash_newline++; ignore_backslash_newline++;

6
lksh.1
View File

@ -1,7 +1,7 @@
.\" $MirOS: src/bin/mksh/lksh.1,v 1.10 2015/04/12 22:32:12 tg Exp $ .\" $MirOS: src/bin/mksh/lksh.1,v 1.11 2015/09/05 19:19:06 tg Exp $
.\"- .\"-
.\" Copyright (c) 2008, 2009, 2010, 2012, 2013, 2015 .\" Copyright (c) 2008, 2009, 2010, 2012, 2013, 2015
.\" Thorsten “mirabilos” Glaser <tg@mirbsd.org> .\" mirabilos <tg@mirbsd.org>
.\" .\"
.\" Provided that these terms and disclaimer and all copyright notices .\" Provided that these terms and disclaimer and all copyright notices
.\" are retained or reproduced in an accompanying document, permission .\" are retained or reproduced in an accompanying document, permission
@ -72,7 +72,7 @@
.\" with -mandoc, it might implement .Mx itself, but we want to .\" with -mandoc, it might implement .Mx itself, but we want to
.\" use our own definition. And .Dd must come *first*, always. .\" use our own definition. And .Dd must come *first*, always.
.\" .\"
.Dd $Mdocdate: April 12 2015 $ .Dd $Mdocdate: September 5 2015 $
.\" .\"
.\" Check which macro package we use, and do other -mdoc setup. .\" Check which macro package we use, and do other -mdoc setup.
.\" .\"

10
main.c
View File

@ -1,12 +1,12 @@
/* $OpenBSD: main.c,v 1.55 2015/02/09 09:09:30 jsg Exp $ */ /* $OpenBSD: main.c,v 1.56 2015/09/01 17:46:31 tedu Exp $ */
/* $OpenBSD: tty.c,v 1.10 2014/08/10 02:44:26 guenther Exp $ */ /* $OpenBSD: tty.c,v 1.10 2014/08/10 02:44:26 guenther Exp $ */
/* $OpenBSD: io.c,v 1.25 2014/08/11 20:28:47 guenther Exp $ */ /* $OpenBSD: io.c,v 1.25 2014/08/11 20:28:47 guenther Exp $ */
/* $OpenBSD: table.c,v 1.15 2012/02/19 07:52:30 otto Exp $ */ /* $OpenBSD: table.c,v 1.16 2015/09/01 13:12:31 tedu Exp $ */
/*- /*-
* Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, * Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
* 2011, 2012, 2013, 2014, 2015 * 2011, 2012, 2013, 2014, 2015
* Thorsten Glaser <tg@mirbsd.org> * mirabilos <tg@mirbsd.org>
* *
* Provided that these terms and disclaimer and all copyright notices * Provided that these terms and disclaimer and all copyright notices
* are retained or reproduced in an accompanying document, permission * are retained or reproduced in an accompanying document, permission
@ -34,7 +34,7 @@
#include <locale.h> #include <locale.h>
#endif #endif
__RCSID("$MirOS: src/bin/mksh/main.c,v 1.301 2015/08/13 22:06:22 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/main.c,v 1.302 2015/09/05 19:19:06 tg Exp $");
extern char **environ; extern char **environ;
@ -202,7 +202,7 @@ main_init(int argc, const char *argv[], Source **sp, struct block **lp)
/* do things like getpgrp() et al. */ /* do things like getpgrp() et al. */
chvt_reinit(); chvt_reinit();
/* make sure argv[] is sane */ /* make sure argv[] is sane, for weird OSes */
if (!*argv) { if (!*argv) {
argv = empty_argv; argv = empty_argv;
argc = 1; argc = 1;

View File

@ -1,6 +1,6 @@
/*- /*-
* Copyright © 2011, 2014, 2015 * Copyright © 2011, 2014, 2015
* Thorsten “mirabilos” Glaser <tg@mirbsd.org> * mirabilos <tg@mirbsd.org>
* *
* Provided that these terms and disclaimer and all copyright notices * Provided that these terms and disclaimer and all copyright notices
* are retained or reproduced in an accompanying document, permission * are retained or reproduced in an accompanying document, permission
@ -44,7 +44,7 @@
#include <sys/types.h> #include <sys/types.h>
__RCSID("$MirOS: src/bin/mksh/mirhash.h,v 1.4 2015/05/30 22:14:06 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/mirhash.h,v 1.5 2015/09/05 19:19:07 tg Exp $");
/*- /*-
* BAFH itself is defined by the following primitives: * BAFH itself is defined by the following primitives:

12
misc.c
View File

@ -1,10 +1,10 @@
/* $OpenBSD: misc.c,v 1.40 2015/03/18 15:12:36 tedu Exp $ */ /* $OpenBSD: misc.c,v 1.40 2015/03/18 15:12:36 tedu Exp $ */
/* $OpenBSD: path.c,v 1.12 2005/03/30 17:16:37 deraadt Exp $ */ /* $OpenBSD: path.c,v 1.13 2015/09/05 09:47:08 jsg Exp $ */
/*- /*-
* Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, * Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
* 2011, 2012, 2013, 2014, 2015 * 2011, 2012, 2013, 2014, 2015
* Thorsten Glaser <tg@mirbsd.org> * mirabilos <tg@mirbsd.org>
* *
* Provided that these terms and disclaimer and all copyright notices * Provided that these terms and disclaimer and all copyright notices
* are retained or reproduced in an accompanying document, permission * are retained or reproduced in an accompanying document, permission
@ -30,7 +30,7 @@
#include <grp.h> #include <grp.h>
#endif #endif
__RCSID("$MirOS: src/bin/mksh/misc.c,v 1.238 2015/07/10 19:36:36 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/misc.c,v 1.239 2015/09/05 19:19:07 tg Exp $");
#define KSH_CHVT_FLAG #define KSH_CHVT_FLAG
#ifdef MKSH_SMALL #ifdef MKSH_SMALL
@ -1579,16 +1579,14 @@ do_realpath(const char *upath)
} }
/* return target path */ /* return target path */
if (ldest != NULL) afree(ldest, ATEMP);
afree(ldest, ATEMP);
afree(ipath, ATEMP); afree(ipath, ATEMP);
return (Xclose(xs, xp)); return (Xclose(xs, xp));
notfound: notfound:
/* save; freeing memory might trash it */ /* save; freeing memory might trash it */
llen = errno; llen = errno;
if (ldest != NULL) afree(ldest, ATEMP);
afree(ldest, ATEMP);
afree(ipath, ATEMP); afree(ipath, ATEMP);
Xfree(xs, xp); Xfree(xs, xp);
errno = llen; errno = llen;

17
mksh.1
View File

@ -1,9 +1,9 @@
.\" $MirOS: src/bin/mksh/mksh.1,v 1.379 2015/08/13 22:09:10 tg Exp $ .\" $MirOS: src/bin/mksh/mksh.1,v 1.380 2015/09/05 19:19:08 tg Exp $
.\" $OpenBSD: ksh.1,v 1.160 2015/07/04 13:27:04 feinerer Exp $ .\" $OpenBSD: ksh.1,v 1.160 2015/07/04 13:27:04 feinerer Exp $
.\"- .\"-
.\" Copyright © 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, .\" Copyright © 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
.\" 2010, 2011, 2012, 2013, 2014, 2015 .\" 2010, 2011, 2012, 2013, 2014, 2015
.\" Thorsten “mirabilos” Glaser <tg@mirbsd.org> .\" mirabilos <tg@mirbsd.org>
.\" .\"
.\" Provided that these terms and disclaimer and all copyright notices .\" Provided that these terms and disclaimer and all copyright notices
.\" are retained or reproduced in an accompanying document, permission .\" are retained or reproduced in an accompanying document, permission
@ -74,7 +74,7 @@
.\" with -mandoc, it might implement .Mx itself, but we want to .\" with -mandoc, it might implement .Mx itself, but we want to
.\" use our own definition. And .Dd must come *first*, always. .\" use our own definition. And .Dd must come *first*, always.
.\" .\"
.Dd $Mdocdate: August 13 2015 $ .Dd $Mdocdate: September 5 2015 $
.\" .\"
.\" Check which macro package we use, and do other -mdoc setup. .\" Check which macro package we use, and do other -mdoc setup.
.\" .\"
@ -6394,7 +6394,7 @@ contains the system and suid profile.
.An -nosplit .An -nosplit
.Nm "The MirBSD Korn Shell" .Nm "The MirBSD Korn Shell"
is developed by is developed by
.An Thorsten Glaser Aq tg@mirbsd.org .An mirabilos Aq tg@mirbsd.org
and currently maintained as part of The MirOS Project. and currently maintained as part of The MirOS Project.
This shell is based on the public domain 7th edition Bourne shell clone by This shell is based on the public domain 7th edition Bourne shell clone by
.An Charles Forsyth , .An Charles Forsyth ,
@ -6427,10 +6427,11 @@ The complete legalese is at:
.Pa https://www.mirbsd.org/TaC\-mksh.txt .Pa https://www.mirbsd.org/TaC\-mksh.txt
.\" .\"
.\" This boils down to: feel free to use mksh.ico as application icon .\" This boils down to: feel free to use mksh.ico as application icon
.\" or shortcut for mksh or mksh/Win32; distro patches are ok (but we .\" or shortcut for mksh or mksh/Win32 or OS/2; distro patches are ok
.\" request they amend $KSH_VERSION when modifying mksh). Authors are .\" (but we request they amend $KSH_VERSION when modifying mksh).
.\" Marshall Kirk McKusick (UCB), Rick Collette (ekkoBSD), Thorsten .\" Authors are Marshall Kirk McKusick (UCB), Rick Collette (ekkoBSD),
.\" Glaser, Benny Siegert (MirBSD), Michael Langguth (mksh/Win32). .\" mirabilos, Benny Siegert (MirBSD), Michael Langguth (mksh/Win32),
.\" KO Myung-Hun (mksh for OS/2).
.\" .\"
.\" As far as MirBSD is concerned, the files themselves are free .\" As far as MirBSD is concerned, the files themselves are free
.\" to modification and distribution under BSD/MirOS Licence, the .\" to modification and distribution under BSD/MirOS Licence, the

9
sh.h
View File

@ -2,7 +2,7 @@
/* $OpenBSD: shf.h,v 1.6 2005/12/11 18:53:51 deraadt Exp $ */ /* $OpenBSD: shf.h,v 1.6 2005/12/11 18:53:51 deraadt Exp $ */
/* $OpenBSD: table.h,v 1.8 2012/02/19 07:52:30 otto Exp $ */ /* $OpenBSD: table.h,v 1.8 2012/02/19 07:52:30 otto Exp $ */
/* $OpenBSD: tree.h,v 1.10 2005/03/28 21:28:22 deraadt Exp $ */ /* $OpenBSD: tree.h,v 1.10 2005/03/28 21:28:22 deraadt Exp $ */
/* $OpenBSD: expand.h,v 1.6 2005/03/30 17:16:37 deraadt Exp $ */ /* $OpenBSD: expand.h,v 1.7 2015/09/01 13:12:31 tedu Exp $ */
/* $OpenBSD: lex.h,v 1.13 2013/03/03 19:11:34 guenther Exp $ */ /* $OpenBSD: lex.h,v 1.13 2013/03/03 19:11:34 guenther Exp $ */
/* $OpenBSD: proto.h,v 1.35 2013/09/04 15:49:19 millert Exp $ */ /* $OpenBSD: proto.h,v 1.35 2013/09/04 15:49:19 millert Exp $ */
/* $OpenBSD: c_test.h,v 1.4 2004/12/20 11:34:26 otto Exp $ */ /* $OpenBSD: c_test.h,v 1.4 2004/12/20 11:34:26 otto Exp $ */
@ -11,7 +11,7 @@
/*- /*-
* Copyright © 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, * Copyright © 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
* 2011, 2012, 2013, 2014, 2015 * 2011, 2012, 2013, 2014, 2015
* Thorsten Glaser <tg@mirbsd.org> * mirabilos <tg@mirbsd.org>
* *
* Provided that these terms and disclaimer and all copyright notices * Provided that these terms and disclaimer and all copyright notices
* are retained or reproduced in an accompanying document, permission * are retained or reproduced in an accompanying document, permission
@ -172,9 +172,9 @@
#endif #endif
#ifdef EXTERN #ifdef EXTERN
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.741 2015/08/13 22:06:23 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/sh.h,v 1.744 2015/09/06 19:47:00 tg Exp $");
#endif #endif
#define MKSH_VERSION "R51 2015/08/13" #define MKSH_VERSION "R51 2015/09/06"
/* arithmetic types: C implementation */ /* arithmetic types: C implementation */
#if !HAVE_CAN_INTTYPES #if !HAVE_CAN_INTTYPES
@ -1454,6 +1454,7 @@ struct ioword {
#define DOTCOMEXEC BIT(11) /* not an eval flag, used by sh -c hack */ #define DOTCOMEXEC BIT(11) /* not an eval flag, used by sh -c hack */
#define DOSCALAR BIT(12) /* change field handling to non-list context */ #define DOSCALAR BIT(12) /* change field handling to non-list context */
#define DOHEREDOC BIT(13) /* change scalar handling to heredoc body */ #define DOHEREDOC BIT(13) /* change scalar handling to heredoc body */
#define DOHERESTR BIT(14) /* append a newline char */
#define X_EXTRA 20 /* this many extra bytes in X string */ #define X_EXTRA 20 /* this many extra bytes in X string */

4
shf.c
View File

@ -3,7 +3,7 @@
/*- /*-
* Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2011, * Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2011,
* 2012, 2013, 2015 * 2012, 2013, 2015
* Thorsten Glaser <tg@mirbsd.org> * mirabilos <tg@mirbsd.org>
* *
* Provided that these terms and disclaimer and all copyright notices * Provided that these terms and disclaimer and all copyright notices
* are retained or reproduced in an accompanying document, permission * are retained or reproduced in an accompanying document, permission
@ -25,7 +25,7 @@
#include "sh.h" #include "sh.h"
__RCSID("$MirOS: src/bin/mksh/shf.c,v 1.66 2015/07/09 20:52:43 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/shf.c,v 1.67 2015/09/05 19:19:11 tg Exp $");
/* flags to shf_emptybuf() */ /* flags to shf_emptybuf() */
#define EB_READSW 0x01 /* about to switch to reading */ #define EB_READSW 0x01 /* about to switch to reading */

View File

@ -1,6 +1,6 @@
/*- /*-
* Copyright (c) 2006, 2008, 2009, 2013 * Copyright (c) 2006, 2008, 2009, 2013
* Thorsten Glaser <tg@mirbsd.org> * mirabilos <tg@mirbsd.org>
* Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com> * Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com>
* *
* Permission to use, copy, modify, and distribute this software for any * Permission to use, copy, modify, and distribute this software for any
@ -18,7 +18,7 @@
#include "sh.h" #include "sh.h"
__RCSID("$MirOS: src/bin/mksh/strlcpy.c,v 1.8 2013/11/05 22:10:15 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/strlcpy.c,v 1.9 2015/09/05 19:19:11 tg Exp $");
/* /*
* Copy src to string dst of size siz. At most siz-1 characters * Copy src to string dst of size siz. At most siz-1 characters

26
syn.c
View File

@ -1,9 +1,9 @@
/* $OpenBSD: syn.c,v 1.29 2013/06/03 18:40:05 jca Exp $ */ /* $OpenBSD: syn.c,v 1.30 2015/09/01 13:12:31 tedu Exp $ */
/*- /*-
* Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, * Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009,
* 2011, 2012, 2013, 2014, 2015 * 2011, 2012, 2013, 2014, 2015
* Thorsten Glaser <tg@mirbsd.org> * mirabilos <tg@mirbsd.org>
* *
* Provided that these terms and disclaimer and all copyright notices * Provided that these terms and disclaimer and all copyright notices
* are retained or reproduced in an accompanying document, permission * are retained or reproduced in an accompanying document, permission
@ -23,7 +23,7 @@
#include "sh.h" #include "sh.h"
__RCSID("$MirOS: src/bin/mksh/syn.c,v 1.101 2015/04/29 20:07:35 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/syn.c,v 1.104 2015/09/06 19:47:01 tg Exp $");
struct nesting_state { struct nesting_state {
int start_token; /* token than began nesting (eg, FOR) */ int start_token; /* token than began nesting (eg, FOR) */
@ -172,6 +172,8 @@ c_list(bool multi)
return (t); return (t);
} }
static const char IONDELIM_delim[] = { CHAR, '<', CHAR, '<', EOS };
static struct ioword * static struct ioword *
synio(int cf) synio(int cf)
{ {
@ -189,15 +191,19 @@ synio(int cf)
return (NULL); return (NULL);
ACCEPT; ACCEPT;
iop = yylval.iop; iop = yylval.iop;
if (iop->ioflag & IONDELIM)
goto gotnulldelim;
ishere = (iop->ioflag & IOTYPE) == IOHERE; ishere = (iop->ioflag & IOTYPE) == IOHERE;
musthave(LWORD, ishere ? HEREDELIM : 0); if (iop->ioflag & IOHERESTR) {
musthave(LWORD, 0);
} else if (ishere && tpeek(HEREDELIM) == '\n') {
ACCEPT;
yylval.cp = wdcopy(IONDELIM_delim, ATEMP);
iop->ioflag |= IOEVAL | IONDELIM;
} else
musthave(LWORD, ishere ? HEREDELIM : 0);
if (ishere) { if (ishere) {
iop->delim = yylval.cp; iop->delim = yylval.cp;
if (*ident != 0) { if (*ident != 0 && !(iop->ioflag & IOHERESTR)) {
/* unquoted */ /* unquoted */
gotnulldelim:
iop->ioflag |= IOEVAL; iop->ioflag |= IOEVAL;
} }
if (herep > &heres[HERES - 1]) if (herep > &heres[HERES - 1])
@ -822,8 +828,8 @@ initkeywords(void)
static void static void
syntaxerr(const char *what) syntaxerr(const char *what)
{ {
/* 2<<- is the longest redirection, I think */ /* 23<<- is the longest redirection, I think */
char redir[6]; char redir[8];
const char *s; const char *s;
struct tokeninfo const *tt; struct tokeninfo const *tt;
int c; int c;

29
tree.c
View File

@ -1,9 +1,9 @@
/* $OpenBSD: tree.c,v 1.20 2012/06/27 07:17:19 otto Exp $ */ /* $OpenBSD: tree.c,v 1.21 2015/09/01 13:12:31 tedu Exp $ */
/*- /*-
* Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, * Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
* 2011, 2012, 2013, 2015 * 2011, 2012, 2013, 2015
* Thorsten Glaser <tg@mirbsd.org> * mirabilos <tg@mirbsd.org>
* *
* Provided that these terms and disclaimer and all copyright notices * Provided that these terms and disclaimer and all copyright notices
* are retained or reproduced in an accompanying document, permission * are retained or reproduced in an accompanying document, permission
@ -23,7 +23,7 @@
#include "sh.h" #include "sh.h"
__RCSID("$MirOS: src/bin/mksh/tree.c,v 1.74 2015/08/13 20:54:03 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/tree.c,v 1.77 2015/09/06 19:47:01 tg Exp $");
#define INDENT 8 #define INDENT 8
@ -226,7 +226,6 @@ ptree(struct op *t, int indent, struct shf *shf)
shf_putc('\n', shf); shf_putc('\n', shf);
shf_puts(iop->heredoc, shf); shf_puts(iop->heredoc, shf);
fptreef(shf, indent, "%s", fptreef(shf, indent, "%s",
iop->ioflag & IONDELIM ? "<<" :
evalstr(iop->delim, 0)); evalstr(iop->delim, 0));
need_nl = true; need_nl = true;
} }
@ -265,6 +264,8 @@ pioact(struct shf *shf, struct ioword *iop)
shf_puts("<<", shf); shf_puts("<<", shf);
if (flag & IOSKIP) if (flag & IOSKIP)
shf_putc('-', shf); shf_putc('-', shf);
else if (flag & IOHERESTR)
shf_putc('<', shf);
break; break;
case IOCAT: case IOCAT:
shf_puts(">>", shf); shf_puts(">>", shf);
@ -283,17 +284,15 @@ pioact(struct shf *shf, struct ioword *iop)
} }
/* name/delim are NULL when printing syntax errors */ /* name/delim are NULL when printing syntax errors */
if (type == IOHERE) { if (type == IOHERE) {
if (iop->delim) if (iop->delim && !(iop->ioflag & IONDELIM))
wdvarput(shf, iop->delim, 0, WDS_TPUTS); wdvarput(shf, iop->delim, 0, WDS_TPUTS);
if (flag & IOHERESTR)
shf_putc(' ', shf);
} else if (iop->name) { } else if (iop->name) {
if (flag & IONAMEXP) if (flag & IONAMEXP)
print_value_quoted(shf, iop->name); print_value_quoted(shf, iop->name);
else else
wdvarput(shf, iop->name, 0, WDS_TPUTS); wdvarput(shf, iop->name, 0, WDS_TPUTS);
shf_putc(' ', shf);
} }
shf_putc(' ', shf);
prevent_semicolon = false; prevent_semicolon = false;
} }
@ -696,8 +695,7 @@ tfree(struct op *t, Area *ap)
if (t == NULL) if (t == NULL)
return; return;
if (t->str != NULL) afree(t->str, ap);
afree(t->str, ap);
if (t->vars != NULL) { if (t->vars != NULL) {
for (w = t->vars; *w != NULL; w++) for (w = t->vars; *w != NULL; w++)
@ -732,12 +730,9 @@ iofree(struct ioword **iow, Area *ap)
iop = iow; iop = iow;
while ((p = *iop++) != NULL) { while ((p = *iop++) != NULL) {
if (p->name != NULL) afree(p->name, ap);
afree(p->name, ap); afree(p->delim, ap);
if (p->delim != NULL) afree(p->heredoc, ap);
afree(p->delim, ap);
if (p->heredoc != NULL)
afree(p->heredoc, ap);
afree(p, ap); afree(p, ap);
} }
afree(iow, ap); afree(iow, ap);
@ -936,7 +931,7 @@ dumpioact(struct shf *shf, struct op *t)
DB(IOHERESTR) DB(IOHERESTR)
DB(IONDELIM) DB(IONDELIM)
shf_fprintf(shf, ",unit=%d", (int)iop->unit); shf_fprintf(shf, ",unit=%d", (int)iop->unit);
if (iop->delim) { if (iop->delim && !(iop->ioflag & IONDELIM)) {
shf_puts(",delim<", shf); shf_puts(",delim<", shf);
dumpwdvar(shf, iop->delim); dumpwdvar(shf, iop->delim);
shf_putc('>', shf); shf_putc('>', shf);

27
var.c
View File

@ -1,9 +1,9 @@
/* $OpenBSD: var.c,v 1.41 2015/04/17 17:20:41 deraadt Exp $ */ /* $OpenBSD: var.c,v 1.43 2015/09/01 13:12:31 tedu Exp $ */
/*- /*-
* Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, * Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
* 2011, 2012, 2013, 2014, 2015 * 2011, 2012, 2013, 2014, 2015
* Thorsten Glaser <tg@mirbsd.org> * mirabilos <tg@mirbsd.org>
* *
* Provided that these terms and disclaimer and all copyright notices * Provided that these terms and disclaimer and all copyright notices
* are retained or reproduced in an accompanying document, permission * are retained or reproduced in an accompanying document, permission
@ -28,7 +28,7 @@
#include <sys/sysctl.h> #include <sys/sysctl.h>
#endif #endif
__RCSID("$MirOS: src/bin/mksh/var.c,v 1.193 2015/07/10 19:36:38 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/var.c,v 1.194 2015/09/05 19:19:12 tg Exp $");
/*- /*-
* Variables * Variables
@ -715,8 +715,7 @@ exportprep(struct tbl *vp, const char *val)
/* offset to value */ /* offset to value */
vp->type = xp - vp->val.s; vp->type = xp - vp->val.s;
memcpy(xp, val, vallen); memcpy(xp, val, vallen);
if (op != NULL) afree(op, vp->areap);
afree(op, vp->areap);
} }
/* /*
@ -954,8 +953,7 @@ typeset(const char *var, uint32_t set, uint32_t clr, int field, int base)
t->type = 0; t->type = 0;
} }
} }
if (free_me) afree(free_me, t->areap);
afree(free_me, t->areap);
} }
} }
if (!ok) if (!ok)
@ -981,8 +979,7 @@ typeset(const char *var, uint32_t set, uint32_t clr, int field, int base)
/* setstr can't fail (readonly check already done) */ /* setstr can't fail (readonly check already done) */
setstr(vp, val, KSH_RETURN_ERROR | 0x4); setstr(vp, val, KSH_RETURN_ERROR | 0x4);
if (tval != NULL) afree(tval, ATEMP);
afree(tval, ATEMP);
} }
/* only x[0] is ever exported, so use vpbase */ /* only x[0] is ever exported, so use vpbase */
@ -1279,18 +1276,15 @@ setspec(struct tbl *vp)
ifs0 = *s; ifs0 = *s;
return; return;
case V_PATH: case V_PATH:
if (path) afree(path, APERM);
afree(path, APERM);
s = str_val(vp); s = str_val(vp);
strdupx(path, s, APERM); strdupx(path, s, APERM);
/* clear tracked aliases */ /* clear tracked aliases */
flushcom(true); flushcom(true);
return; return;
case V_TMPDIR: case V_TMPDIR:
if (tmpdir) { afree(tmpdir, APERM);
afree(tmpdir, APERM); tmpdir = NULL;
tmpdir = NULL;
}
/* /*
* Use tmpdir iff it is an absolute path, is writable * Use tmpdir iff it is an absolute path, is writable
* and searchable and is a directory... * and searchable and is a directory...
@ -1399,8 +1393,7 @@ unsetspec(struct tbl *vp)
ifs0 = ' '; ifs0 = ' ';
break; break;
case V_PATH: case V_PATH:
if (path) afree(path, APERM);
afree(path, APERM);
strdupx(path, def_path, APERM); strdupx(path, def_path, APERM);
/* clear tracked aliases */ /* clear tracked aliases */
flushcom(true); flushcom(true);