ormaaj reported “command shift” not working correctly; fix

This commit is contained in:
tg 2013-01-06 18:51:43 +00:00
parent 7a2130b02a
commit 2d9a039ec0
3 changed files with 41 additions and 9 deletions

34
check.t
View File

@ -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: 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: 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 $ # $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 # http://www.freebsd.org/cgi/cvsweb.cgi/src/tools/regression/bin/test/regress.sh?rev=HEAD
expected-stdout: expected-stdout:
@(#)MIRBSD KSH R41 2013/01/01 @(#)MIRBSD KSH R41 2013/01/06
description: description:
Check version of shell. Check version of shell.
stdin: stdin:
@ -38,7 +38,7 @@ name: KSH_VERSION
category: shell:legacy-no category: shell:legacy-no
--- ---
expected-stdout: expected-stdout:
@(#)LEGACY KSH R41 2013/01/01 @(#)LEGACY KSH R41 2013/01/06
description: description:
Check version of legacy shell. Check version of legacy shell.
stdin: stdin:
@ -10566,6 +10566,34 @@ expected-stdout:
5(esac)bourne no 5(esac)bourne no
6(esac)korn esac 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 name: stateptr-underflow
description: description:
This check overflows an Xrestpos stored in a short in R40 This check overflows an Xrestpos stored in a short in R40

12
exec.c
View File

@ -23,7 +23,7 @@
#include "sh.h" #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 #ifndef MKSH_DEFAULT_EXECSHELL
#define MKSH_DEFAULT_EXECSHELL "/bin/sh" #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?) */ /* Must be static (XXX but why?) */
static struct op texec; static struct op texec;
int type_flags; int type_flags;
int keepasn_ok; bool keepasn_ok;
int fcflags = FC_BI|FC_FUNC|FC_PATH; int fcflags = FC_BI|FC_FUNC|FC_PATH;
bool bourne_function_call = false; bool bourne_function_call = false;
struct block *l_expand, *l_assign; 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 * FOO=bar command FOO is neither kept nor exported
* PATH=... foobar use new PATH in foobar search * PATH=... foobar use new PATH in foobar search
*/ */
keepasn_ok = 1; keepasn_ok = true;
while (tp && tp->type == CSHELL) { while (tp && tp->type == CSHELL) {
/* undo effects of command */ /* undo effects of command */
fcflags = FC_BI|FC_FUNC|FC_PATH; 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 * POSIX says special builtins lose their status
* if accessed using command. * if accessed using command.
*/ */
keepasn_ok = 0; keepasn_ok = false;
if (!ap[0]) { if (!ap[0]) {
/* ensure command with no args exits with 0 */ /* ensure command with no args exits with 0 */
subst_exstat = 0; subst_exstat = 0;
@ -678,6 +678,10 @@ comexec(struct op *t, struct tbl * volatile tp, const char **ap,
/* shell built-in */ /* shell built-in */
case CSHELL: case CSHELL:
rv = call_builtin(tp, (const char **)ap, null); 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; break;
/* function call */ /* function call */

4
sh.h
View File

@ -164,9 +164,9 @@
#endif #endif
#ifdef EXTERN #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 #endif
#define MKSH_VERSION "R41 2013/01/01" #define MKSH_VERSION "R41 2013/01/06"
/* arithmetic types: C implementation */ /* arithmetic types: C implementation */
#if !HAVE_CAN_INTTYPES #if !HAVE_CAN_INTTYPES