another ksh93 feature: test -o ?foo (almost zero cost)

This commit is contained in:
tg 2009-09-07 17:24:49 +00:00
parent ce24c5da13
commit 3639137e48
4 changed files with 53 additions and 10 deletions

45
check.t
View File

@ -1,4 +1,4 @@
# $MirOS: src/bin/mksh/check.t,v 1.304 2009/09/06 17:55:53 tg Exp $
# $MirOS: src/bin/mksh/check.t,v 1.305 2009/09/07 17:24:47 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 $
@ -25,7 +25,7 @@
# http://www.research.att.com/~gsf/public/ifs.sh
expected-stdout:
@(#)MIRBSD KSH R39 2009/09/06
@(#)MIRBSD KSH R39 2009/09/07
description:
Check version of shell.
stdin:
@ -4357,6 +4357,47 @@ stdin:
expected-stdout:
-e 0
---
name: test-option-1
description:
Test the test -o operator
stdin:
runtest() {
test -o $1; echo $?
[ -o $1 ]; echo $?
[[ -o $1 ]]; echo $?
}
if_test() {
test -o $1 -o -o !$1; echo $?
[ -o $1 -o -o !$1 ]; echo $?
[[ -o $1 || -o !$1 ]]; echo $?
test -o ?$1; echo $?
}
echo 0y $(if_test utf8-mode) =
echo 0n $(if_test utf8-hack) =
echo 1= $(runtest utf8-hack) =
echo 2= $(runtest !utf8-hack) =
echo 3= $(runtest ?utf8-hack) =
set +U
echo 1+ $(runtest utf8-mode) =
echo 2+ $(runtest !utf8-mode) =
echo 3+ $(runtest ?utf8-mode) =
set -U
echo 1- $(runtest utf8-mode) =
echo 2- $(runtest !utf8-mode) =
echo 3- $(runtest ?utf8-mode) =
expected-stdout:
0y 0 0 0 0 =
0n 1 1 1 1 =
1= 1 1 1 =
2= 1 1 1 =
3= 1 1 1 =
1+ 1 1 1 =
2+ 0 0 0 =
3+ 0 0 0 =
1- 0 0 0 =
2- 1 1 1 =
3- 0 0 0 =
---
name: mkshrc-1
description:
Check that ~/.mkshrc works correctly.

View File

@ -25,7 +25,7 @@
#include "sh.h"
__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.129 2009/09/06 17:42:12 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.130 2009/09/07 17:24:48 tg Exp $");
#if HAVE_KILLPG
/*
@ -2782,12 +2782,11 @@ test_eval(Test_env *te, Test_op op, const char *opnd1, const char *opnd2,
case TO_STZER: /* -z */
return (*opnd1 == '\0');
case TO_OPTION: /* -o */
if ((i = *opnd1 == '!'))
if ((i = *opnd1) == '!' || i == '?')
opnd1++;
if ((k = option(opnd1)) == (size_t)-1)
return (0);
s = Flag(k);
return (i ? !s : s);
return (i == '?' ? 1 : i == '!' ? !Flag(k) : Flag(k));
case TO_FILRD: /* -r */
return (test_eaccess(opnd1, R_OK) == 0);
case TO_FILWR: /* -w */

7
mksh.1
View File

@ -1,4 +1,4 @@
.\" $MirOS: src/bin/mksh/mksh.1,v 1.183 2009/09/06 18:17:51 tg Exp $
.\" $MirOS: src/bin/mksh/mksh.1,v 1.184 2009/09/07 17:24:49 tg Exp $
.\" $OpenBSD: ksh.1,v 1.129 2009/05/28 06:09:06 jmc Exp $
.\"-
.\" Copyright © 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
@ -48,7 +48,7 @@
.el .xD \\$1 \\$2 \\$3 \\$4 \\$5 \\$6 \\$7 \\$8
..
.\"-
.Dd $Mdocdate: September 6 2009 $
.Dd $Mdocdate: September 7 2009 $
.Dt MKSH 1
.Os MirBSD
.Sh NAME
@ -3882,6 +3882,9 @@ the test is negated; the test always fails if
doesn't exist (so [ \-o foo \-o \-o !foo ] returns true if and only if option
.Ar foo
exists).
The same can be achieved with [ \-o ?foo ] like in
.At
.Nm ksh93 .
.It Fl p Ar file
.Ar file
is a named pipe.

4
sh.h
View File

@ -134,9 +134,9 @@
#endif
#ifdef EXTERN
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.339 2009/09/06 17:55:55 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.340 2009/09/07 17:24:49 tg Exp $");
#endif
#define MKSH_VERSION "R39 2009/09/06"
#define MKSH_VERSION "R39 2009/09/07"
#ifndef MKSH_INCLUDES_ONLY