From 2d9a039ec0e810dfb36336ba55247297913259ff Mon Sep 17 00:00:00 2001 From: tg Date: Sun, 6 Jan 2013 18:51:43 +0000 Subject: [PATCH] =?UTF-8?q?ormaaj=20reported=20=E2=80=9Ccommand=20shift?= =?UTF-8?q?=E2=80=9D=20not=20working=20correctly;=20fix?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- check.t | 34 +++++++++++++++++++++++++++++++--- exec.c | 12 ++++++++---- sh.h | 4 ++-- 3 files changed, 41 insertions(+), 9 deletions(-) diff --git a/check.t b/check.t index ee7b6bb..9db82d0 100644 --- a/check.t +++ b/check.t @@ -1,4 +1,4 @@ -# $MirOS: src/bin/mksh/check.t,v 1.585 2013/01/01 22:23:14 tg Exp $ +# $MirOS: src/bin/mksh/check.t,v 1.586 2013/01/06 18:51:39 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 $ @@ -29,7 +29,7 @@ # http://www.freebsd.org/cgi/cvsweb.cgi/src/tools/regression/bin/test/regress.sh?rev=HEAD expected-stdout: - @(#)MIRBSD KSH R41 2013/01/01 + @(#)MIRBSD KSH R41 2013/01/06 description: Check version of shell. stdin: @@ -38,7 +38,7 @@ name: KSH_VERSION category: shell:legacy-no --- expected-stdout: - @(#)LEGACY KSH R41 2013/01/01 + @(#)LEGACY KSH R41 2013/01/06 description: Check version of legacy shell. stdin: @@ -10566,6 +10566,34 @@ expected-stdout: 5(esac)bourne no 6(esac)korn esac --- +name: command-shift +description: + Check that 'command shift' works +stdin: + function snc { + echo "before 0='$0' 1='$1' 2='$2'" + shift + echo "after 0='$0' 1='$1' 2='$2'" + } + function swc { + echo "before 0='$0' 1='$1' 2='$2'" + command shift + echo "after 0='$0' 1='$1' 2='$2'" + } + echo = without command + snc 一 二 + echo = with command + swc 一 二 + echo = done +expected-stdout: + = without command + before 0='snc' 1='一' 2='二' + after 0='snc' 1='二' 2='' + = with command + before 0='swc' 1='一' 2='二' + after 0='swc' 1='二' 2='' + = done +--- name: stateptr-underflow description: This check overflows an Xrestpos stored in a short in R40 diff --git a/exec.c b/exec.c index 6b649b3..253162d 100644 --- a/exec.c +++ b/exec.c @@ -23,7 +23,7 @@ #include "sh.h" -__RCSID("$MirOS: src/bin/mksh/exec.c,v 1.111 2013/01/01 20:45:02 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/exec.c,v 1.112 2013/01/06 18:51:42 tg Exp $"); #ifndef MKSH_DEFAULT_EXECSHELL #define MKSH_DEFAULT_EXECSHELL "/bin/sh" @@ -506,7 +506,7 @@ comexec(struct op *t, struct tbl * volatile tp, const char **ap, /* Must be static (XXX but why?) */ static struct op texec; int type_flags; - int keepasn_ok; + bool keepasn_ok; int fcflags = FC_BI|FC_FUNC|FC_PATH; bool bourne_function_call = false; struct block *l_expand, *l_assign; @@ -538,7 +538,7 @@ comexec(struct op *t, struct tbl * volatile tp, const char **ap, * FOO=bar command FOO is neither kept nor exported * PATH=... foobar use new PATH in foobar search */ - keepasn_ok = 1; + keepasn_ok = true; while (tp && tp->type == CSHELL) { /* undo effects of command */ fcflags = FC_BI|FC_FUNC|FC_PATH; @@ -585,7 +585,7 @@ comexec(struct op *t, struct tbl * volatile tp, const char **ap, * POSIX says special builtins lose their status * if accessed using command. */ - keepasn_ok = 0; + keepasn_ok = false; if (!ap[0]) { /* ensure command with no args exits with 0 */ subst_exstat = 0; @@ -678,6 +678,10 @@ comexec(struct op *t, struct tbl * volatile tp, const char **ap, /* shell built-in */ case CSHELL: rv = call_builtin(tp, (const char **)ap, null); + if (!keepasn_ok && tp->val.f == c_shift) { + l_expand->argc = l_assign->argc; + l_expand->argv = l_assign->argv; + } break; /* function call */ diff --git a/sh.h b/sh.h index cce9c05..fc39916 100644 --- a/sh.h +++ b/sh.h @@ -164,9 +164,9 @@ #endif #ifdef EXTERN -__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.626 2013/01/01 20:45:04 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.627 2013/01/06 18:51:43 tg Exp $"); #endif -#define MKSH_VERSION "R41 2013/01/01" +#define MKSH_VERSION "R41 2013/01/06" /* arithmetic types: C implementation */ #if !HAVE_CAN_INTTYPES