be more robust against things like Debian #535970
reverts and rewrites the code from cid 10047C1EBA57E4F4AF0 XXX find out if this is done right
This commit is contained in:
parent
0b4b689c92
commit
f349aeab3c
40
check.t
40
check.t
@ -1,4 +1,4 @@
|
|||||||
# $MirOS: src/bin/mksh/check.t,v 1.289 2009/07/05 13:56:46 tg Exp $
|
# $MirOS: src/bin/mksh/check.t,v 1.290 2009/07/06 15:06:23 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 $
|
||||||
@ -25,7 +25,7 @@
|
|||||||
# http://www.research.att.com/~gsf/public/ifs.sh
|
# http://www.research.att.com/~gsf/public/ifs.sh
|
||||||
|
|
||||||
expected-stdout:
|
expected-stdout:
|
||||||
@(#)MIRBSD KSH R38 2009/07/05
|
@(#)MIRBSD KSH R38 2009/07/06
|
||||||
description:
|
description:
|
||||||
Check version of shell.
|
Check version of shell.
|
||||||
stdin:
|
stdin:
|
||||||
@ -4804,6 +4804,42 @@ expected-stdout:
|
|||||||
suspend='kill -STOP $$'
|
suspend='kill -STOP $$'
|
||||||
type='whence -v'
|
type='whence -v'
|
||||||
---
|
---
|
||||||
|
name: aliases-funcdef-1
|
||||||
|
description:
|
||||||
|
Check if POSIX functions take precedences over aliases
|
||||||
|
stdin:
|
||||||
|
alias foo='echo makro'
|
||||||
|
foo() {
|
||||||
|
echo funktion
|
||||||
|
}
|
||||||
|
foo
|
||||||
|
expected-stdout:
|
||||||
|
funktion
|
||||||
|
---
|
||||||
|
name: aliases-funcdef-2
|
||||||
|
description:
|
||||||
|
Check if POSIX functions take precedences over aliases
|
||||||
|
stdin:
|
||||||
|
alias foo='echo makro'
|
||||||
|
foo () {
|
||||||
|
echo funktion
|
||||||
|
}
|
||||||
|
foo
|
||||||
|
expected-stdout:
|
||||||
|
funktion
|
||||||
|
---
|
||||||
|
name: aliases-funcdef-3
|
||||||
|
description:
|
||||||
|
Check if aliases take precedences over Korn functions
|
||||||
|
stdin:
|
||||||
|
alias foo='echo makro'
|
||||||
|
function foo {
|
||||||
|
echo funktion
|
||||||
|
}
|
||||||
|
foo
|
||||||
|
expected-stdout:
|
||||||
|
makro
|
||||||
|
---
|
||||||
name: arrays-1
|
name: arrays-1
|
||||||
description:
|
description:
|
||||||
Check if Korn Shell arrays work as expected
|
Check if Korn Shell arrays work as expected
|
||||||
|
40
lex.c
40
lex.c
@ -22,7 +22,7 @@
|
|||||||
|
|
||||||
#include "sh.h"
|
#include "sh.h"
|
||||||
|
|
||||||
__RCSID("$MirOS: src/bin/mksh/lex.c,v 1.88 2009/06/11 12:42:19 tg Exp $");
|
__RCSID("$MirOS: src/bin/mksh/lex.c,v 1.89 2009/07/06 15:06:23 tg Exp $");
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* states while lexing word
|
* states while lexing word
|
||||||
@ -159,7 +159,6 @@ yylex(int cf)
|
|||||||
char *wp; /* output word pointer */
|
char *wp; /* output word pointer */
|
||||||
char *sp, *dp;
|
char *sp, *dp;
|
||||||
int c2;
|
int c2;
|
||||||
bool last_terminal_was_bracket;
|
|
||||||
|
|
||||||
Again:
|
Again:
|
||||||
states[0].ls_state = -1;
|
states[0].ls_state = -1;
|
||||||
@ -881,8 +880,14 @@ yylex(int cf)
|
|||||||
state == SLETARRAY) /* ONEWORD? */
|
state == SLETARRAY) /* ONEWORD? */
|
||||||
return (LWORD);
|
return (LWORD);
|
||||||
|
|
||||||
last_terminal_was_bracket = c == '(';
|
/* unget terminator */
|
||||||
ungetsc(c); /* unget terminator */
|
ungetsc(c);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* note: the alias-vs-function code below depends on several
|
||||||
|
* interna: starting from here, source->str is not modified;
|
||||||
|
* the way getsc() and ungetsc() operate; etc.
|
||||||
|
*/
|
||||||
|
|
||||||
/* copy word to unprefixed string ident */
|
/* copy word to unprefixed string ident */
|
||||||
sp = yylval.cp;
|
sp = yylval.cp;
|
||||||
@ -914,8 +919,31 @@ yylex(int cf)
|
|||||||
}
|
}
|
||||||
if ((cf & ALIAS) && (p = ktsearch(&aliases, ident, h)) &&
|
if ((cf & ALIAS) && (p = ktsearch(&aliases, ident, h)) &&
|
||||||
(p->flag & ISSET)) {
|
(p->flag & ISSET)) {
|
||||||
if (last_terminal_was_bracket)
|
/*
|
||||||
/* prefer functions over aliases */
|
* this still points to the same character as the
|
||||||
|
* ungetsc'd terminator from above
|
||||||
|
*/
|
||||||
|
const char *cp = source->str;
|
||||||
|
|
||||||
|
/* prefer POSIX but not Korn functions over aliases */
|
||||||
|
while (*cp == ' ' || *cp == '\t')
|
||||||
|
/*
|
||||||
|
* this is like getsc() without skipping
|
||||||
|
* over Source boundaries (including not
|
||||||
|
* parsing ungetsc'd characters that got
|
||||||
|
* pushed into an SREREAD) which is what
|
||||||
|
* we want here anyway: find out whether
|
||||||
|
* the alias name is followed by a POSIX
|
||||||
|
* function definition (only the opening
|
||||||
|
* parenthesis is checked though)
|
||||||
|
*/
|
||||||
|
++cp;
|
||||||
|
/* prefer functions over aliases */
|
||||||
|
if (*cp == '(' /*)*/)
|
||||||
|
/*
|
||||||
|
* delete alias upon encountering function
|
||||||
|
* definition
|
||||||
|
*/
|
||||||
ktdelete(p);
|
ktdelete(p);
|
||||||
else {
|
else {
|
||||||
Source *s = source;
|
Source *s = source;
|
||||||
|
9
mksh.1
9
mksh.1
@ -1,4 +1,4 @@
|
|||||||
.\" $MirOS: src/bin/mksh/mksh.1,v 1.171 2009/07/06 09:37:03 tg Exp $
|
.\" $MirOS: src/bin/mksh/mksh.1,v 1.172 2009/07/06 15:06:24 tg Exp $
|
||||||
.\" $OpenBSD: ksh.1,v 1.129 2009/05/28 06:09:06 jmc Exp $
|
.\" $OpenBSD: ksh.1,v 1.129 2009/05/28 06:09:06 jmc Exp $
|
||||||
.\"-
|
.\"-
|
||||||
.\" Copyright © 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
|
.\" Copyright © 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
|
||||||
@ -738,6 +738,9 @@ Mostly the same as
|
|||||||
(see
|
(see
|
||||||
.Sx Functions
|
.Sx Functions
|
||||||
below).
|
below).
|
||||||
|
Whitespace (space or tab) after
|
||||||
|
.Ar name
|
||||||
|
will be ignored most of the time.
|
||||||
.It Xo Ic time Op Fl p
|
.It Xo Ic time Op Fl p
|
||||||
.Op Ar pipeline
|
.Op Ar pipeline
|
||||||
.Xc
|
.Xc
|
||||||
@ -2479,6 +2482,10 @@ untouched, so using
|
|||||||
inside a function interferes with using
|
inside a function interferes with using
|
||||||
.Ic getopts
|
.Ic getopts
|
||||||
outside the function).
|
outside the function).
|
||||||
|
.It
|
||||||
|
Bourne-style function definitions take precedence over alias dereferences
|
||||||
|
and remove alias definitions upon encounter, while aliases take precedence
|
||||||
|
over Korn-style functions.
|
||||||
.El
|
.El
|
||||||
.Pp
|
.Pp
|
||||||
In the future, the following differences will also be added:
|
In the future, the following differences will also be added:
|
||||||
|
4
sh.h
4
sh.h
@ -122,9 +122,9 @@
|
|||||||
#define __SCCSID(x) __IDSTRING(sccsid,x)
|
#define __SCCSID(x) __IDSTRING(sccsid,x)
|
||||||
|
|
||||||
#ifdef EXTERN
|
#ifdef EXTERN
|
||||||
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.311 2009/07/05 13:56:48 tg Exp $");
|
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.312 2009/07/06 15:06:25 tg Exp $");
|
||||||
#endif
|
#endif
|
||||||
#define MKSH_VERSION "R38 2009/07/05"
|
#define MKSH_VERSION "R38 2009/07/06"
|
||||||
|
|
||||||
#ifndef MKSH_INCLUDES_ONLY
|
#ifndef MKSH_INCLUDES_ONLY
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user