our test(1) promises we can do string1 < string2, and

our /bin/test uses mksh... so we pee (literally) on
POSIX and don't accept < and > only for [[ ... ]] operator
This commit is contained in:
tg
2005-10-08 19:31:00 +00:00
parent 1b081938fb
commit 7ee8296628
6 changed files with 36 additions and 30 deletions

13
check.t
View File

@ -1,4 +1,4 @@
# $MirOS: src/bin/mksh/check.t,v 1.31 2005/10/08 18:53:09 tg Exp $ # $MirOS: src/bin/mksh/check.t,v 1.32 2005/10/08 19:30:58 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 $
@ -3694,6 +3694,17 @@ expected-stderr:
+ /usr/bin/env false + /usr/bin/env false
expected-exit: 1 expected-exit: 1
--- ---
name: test-stlt
description:
Check that test also can handle string1 < string2 etc.
stdin:
test 2005/10/08 '<' 2005/08/21 && echo ja || echo nein
test 2005/08/21 \< 2005/10/08 && echo ja || echo nein
expected-stdout:
nein
ja
expected-stderr-pattern: !/unexpected op/
---
name: version-1 name: version-1
description: description:
Check version of shell. Check version of shell.

6
exec.c
View File

@ -1,11 +1,11 @@
/** $MirOS: src/bin/mksh/exec.c,v 1.8 2005/07/07 22:00:45 tg Exp $ */ /** $MirOS: src/bin/mksh/exec.c,v 1.9 2005/10/08 19:30:58 tg Exp $ */
/* $OpenBSD: exec.c,v 1.41 2005/03/30 17:16:37 deraadt Exp $ */ /* $OpenBSD: exec.c,v 1.41 2005/03/30 17:16:37 deraadt Exp $ */
#include "sh.h" #include "sh.h"
#include <sys/stat.h> #include <sys/stat.h>
#include <ctype.h> #include <ctype.h>
__RCSID("$MirOS: src/bin/mksh/exec.c,v 1.8 2005/07/07 22:00:45 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/exec.c,v 1.9 2005/10/08 19:30:58 tg Exp $");
static int comexec(struct op *, struct tbl *volatile, char **, static int comexec(struct op *, struct tbl *volatile, char **,
int volatile); int volatile);
@ -1348,7 +1348,7 @@ dbteste_isa(Test_env *te, Test_meta meta)
*p == CHAR && q < &buf[sizeof(buf) - 1]; p += 2) *p == CHAR && q < &buf[sizeof(buf) - 1]; p += 2)
*q++ = p[1]; *q++ = p[1];
*q = '\0'; *q = '\0';
ret = test_isop(te, meta, buf); ret = test_isop(meta, buf);
} }
} else if (meta == TM_END) } else if (meta == TM_END)
ret = 0; ret = 0;

21
funcs.c
View File

@ -1,4 +1,4 @@
/** $MirOS: src/bin/mksh/funcs.c,v 1.18 2005/09/12 19:28:18 tg Exp $ */ /** $MirOS: src/bin/mksh/funcs.c,v 1.19 2005/10/08 19:30:59 tg Exp $ */
/* $OpenBSD: c_ksh.c,v 1.27 2005/03/30 17:16:37 deraadt Exp $ */ /* $OpenBSD: c_ksh.c,v 1.27 2005/03/30 17:16:37 deraadt Exp $ */
/* $OpenBSD: c_sh.c,v 1.29 2005/03/30 17:16:37 deraadt Exp $ */ /* $OpenBSD: c_sh.c,v 1.29 2005/03/30 17:16:37 deraadt Exp $ */
/* $OpenBSD: c_test.c,v 1.17 2005/03/30 17:16:37 deraadt Exp $ */ /* $OpenBSD: c_test.c,v 1.17 2005/03/30 17:16:37 deraadt Exp $ */
@ -13,7 +13,7 @@
#include <ulimit.h> #include <ulimit.h>
#endif #endif
__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.18 2005/09/12 19:28:18 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.19 2005/10/08 19:30:59 tg Exp $");
#ifdef USE_PRINTF #ifdef USE_PRINTF
int c_printf(char **); int c_printf(char **);
@ -2415,20 +2415,17 @@ c_test(char **wp)
*/ */
Test_op Test_op
test_isop(Test_env *te, Test_meta meta, const char *s) test_isop(Test_meta meta, const char *s)
{ {
char sc1; char sc1;
const struct t_op *otab; const struct t_op *tbl;
otab = meta == TM_UNOP ? u_ops : b_ops; tbl = meta == TM_UNOP ? u_ops : b_ops;
if (*s) { if (*s) {
sc1 = s[1]; sc1 = s[1];
for (; otab->op_text[0]; otab++) for (; tbl->op_text[0]; tbl++)
if (sc1 == otab->op_text[1] && if (sc1 == tbl->op_text[1] && !strcmp(s, tbl->op_text))
strcmp(s, otab->op_text) == 0 && return tbl->op_num;
((te->flags & TEF_DBRACKET) ||
(otab->op_num != TO_STLT && otab->op_num != TO_STGT)))
return otab->op_num;
} }
return TO_NONOP; return TO_NONOP;
} }
@ -2722,7 +2719,7 @@ ptest_isa(Test_env *te, Test_meta meta)
return meta == TM_END; return meta == TM_END;
if (meta == TM_UNOP || meta == TM_BINOP) if (meta == TM_UNOP || meta == TM_BINOP)
ret = test_isop(te, meta, *te->pos.wp); ret = test_isop(meta, *te->pos.wp);
else if (meta == TM_END) else if (meta == TM_END)
ret = 0; ret = 0;
else else

16
mksh.1
View File

@ -1,4 +1,4 @@
.\" $MirOS: src/bin/mksh/mksh.1,v 1.20 2005/10/07 18:36:19 tg Exp $ .\" $MirOS: src/bin/mksh/mksh.1,v 1.21 2005/10/08 19:30:59 tg Exp $
.\" $OpenBSD: ksh.1,v 1.101 2005/08/01 19:29:57 jmc Exp $ .\" $OpenBSD: ksh.1,v 1.101 2005/08/01 19:29:57 jmc Exp $
.\" $OpenBSD: sh.1tbl,v 1.53 2004/12/10 01:56:56 jaredy Exp $ .\" $OpenBSD: sh.1tbl,v 1.53 2004/12/10 01:56:56 jaredy Exp $
.\" .\"
@ -737,13 +737,6 @@ expressions are patterns (e.g. the comparison
.Ic [[ foobar = f*r ]] .Ic [[ foobar = f*r ]]
succeeds). succeeds).
.It .It
There are two additional binary operators,
.Ql \*(Lt
and
.Ql \*(Gt ,
which return true if their first string operand is less than, or greater than,
their second string operand, respectively.
.It
The single argument form of The single argument form of
.Ic test , .Ic test ,
which tests if the argument has a non-zero length, is not valid; explicit which tests if the argument has a non-zero length, is not valid; explicit
@ -3466,6 +3459,10 @@ is empty.
Strings are equal. Strings are equal.
.It Ar string No == Ar string .It Ar string No == Ar string
Strings are equal. Strings are equal.
.It Ar string No \*(Gt Ar string
First string operand is greater than second string operand.
.It Ar string No \*(Lt Ar string
First string operand is less than second string operand.
.It Ar string No != Ar string .It Ar string No != Ar string
Strings are not equal. Strings are not equal.
.It Ar number Fl eq Ar number .It Ar number Fl eq Ar number
@ -3524,7 +3521,8 @@ or
.Sq Fl n . .Sq Fl n .
Use tests like Use tests like
.Dq if \&[ x\&"$foo\&" = x"bar" \&] .Dq if \&[ x\&"$foo\&" = x"bar" \&]
instead. instead, or the double-bracket operator:
.Dq if \&[[ $foo = bar \&]]
.Pp .Pp
.It Xo .It Xo
.Ic time .Ic time

4
sh.h
View File

@ -1,4 +1,4 @@
/** $MirOS: src/bin/mksh/sh.h,v 1.17 2005/08/02 12:35:27 tg Exp $ */ /** $MirOS: src/bin/mksh/sh.h,v 1.18 2005/10/08 19:31:00 tg Exp $ */
/* $OpenBSD: sh.h,v 1.27 2005/03/28 21:33:04 deraadt Exp $ */ /* $OpenBSD: sh.h,v 1.27 2005/03/28 21:33:04 deraadt Exp $ */
/* $OpenBSD: shf.h,v 1.5 2005/03/30 17:16:37 deraadt Exp $ */ /* $OpenBSD: shf.h,v 1.5 2005/03/30 17:16:37 deraadt Exp $ */
/* $OpenBSD: table.h,v 1.6 2004/12/18 20:55:52 millert Exp $ */ /* $OpenBSD: table.h,v 1.6 2004/12/18 20:55:52 millert Exp $ */
@ -1257,7 +1257,7 @@ struct test_env {
void (*error)(Test_env *, int, const char *); void (*error)(Test_env *, int, const char *);
}; };
Test_op test_isop(Test_env *, Test_meta, const char *); Test_op test_isop(Test_meta, const char *);
int test_eval(Test_env *, Test_op, const char *, const char *, int); int test_eval(Test_env *, Test_op, const char *, const char *, int);
int test_parse(Test_env *); int test_parse(Test_env *);

6
syn.c
View File

@ -1,9 +1,9 @@
/** $MirOS: src/bin/mksh/syn.c,v 1.2 2005/07/04 12:27:28 tg Exp $ */ /** $MirOS: src/bin/mksh/syn.c,v 1.3 2005/10/08 19:31:00 tg Exp $ */
/* $OpenBSD: syn.c,v 1.22 2005/03/30 17:16:37 deraadt Exp $ */ /* $OpenBSD: syn.c,v 1.22 2005/03/30 17:16:37 deraadt Exp $ */
#include "sh.h" #include "sh.h"
__RCSID("$MirOS: src/bin/mksh/syn.c,v 1.2 2005/07/04 12:27:28 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/syn.c,v 1.3 2005/10/08 19:31:00 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) */
@ -846,7 +846,7 @@ dbtestp_isa(Test_env *te, Test_meta meta)
ret = 1; ret = 1;
save = wdcopy(yylval.iop->flag == IOREAD ? save = wdcopy(yylval.iop->flag == IOREAD ?
db_lthan : db_gthan, ATEMP); db_lthan : db_gthan, ATEMP);
} else if (uqword && (ret = test_isop(te, meta, ident))) } else if (uqword && (ret = test_isop(meta, ident)))
save = yylval.cp; save = yylval.cp;
} else /* meta == TM_END */ } else /* meta == TM_END */
ret = uqword && strcmp(yylval.cp, db_close) == 0; ret = uqword && strcmp(yylval.cp, db_close) == 0;