“local x=$1” is supposed to not field-split and so

This commit is contained in:
tg 2015-03-14 05:23:18 +00:00
parent 532af35304
commit 0d72355038
7 changed files with 110 additions and 89 deletions

83
check.t
View File

@ -1,4 +1,4 @@
# $MirOS: src/bin/mksh/check.t,v 1.684 2015/03/08 22:54:31 tg Exp $
# $MirOS: src/bin/mksh/check.t,v 1.685 2015/03/14 05:23:12 tg Exp $
# -*- mode: sh -*-
#-
# Copyright © 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
@ -30,7 +30,7 @@
# (2013/12/02 20:39:44) http://openbsd.cs.toronto.edu/cgi-bin/cvsweb/src/regress/bin/ksh/?sortby=date
expected-stdout:
@(#)MIRBSD KSH R50 2015/03/08
@(#)MIRBSD KSH R50 2015/03/13
description:
Check version of shell.
stdin:
@ -39,7 +39,7 @@ name: KSH_VERSION
category: shell:legacy-no
---
expected-stdout:
@(#)LEGACY KSH R50 2015/03/08
@(#)LEGACY KSH R50 2015/03/13
description:
Check version of legacy shell.
stdin:
@ -257,6 +257,19 @@ stdin:
expected-stdout:
hello world
---
name: alias-11
description:
Check that special argument handling still applies with escaped aliases
stdin:
alias local='\typeset'
function foo {
local x=$1 y=z
print -r -- "$x,$y"
}
foo 'bar - baz'
expected-stdout:
bar - baz,z
---
name: arith-lazy-1
description:
Check that only one side of ternary operator is evaluated
@ -7370,14 +7383,14 @@ stdin:
alias
typeset -f
expected-stdout:
autoload='\builtin typeset -fu'
functions='\builtin typeset -f'
autoload='\typeset -fu'
functions='\typeset -f'
hash='\builtin alias -t'
history='\builtin fc -l'
integer='\builtin typeset -i'
local='\builtin typeset'
integer='\typeset -i'
local='\typeset'
login='\exec login'
nameref='\builtin typeset -n'
nameref='\typeset -n'
nohup='nohup '
r='\builtin fc -e -'
source='PATH=$PATH:. \command .'
@ -7392,14 +7405,14 @@ stdin:
alias
typeset -f
expected-stdout:
autoload='\builtin typeset -fu'
functions='\builtin typeset -f'
autoload='\typeset -fu'
functions='\typeset -f'
hash='\builtin alias -t'
history='\builtin fc -l'
integer='\builtin typeset -i'
local='\builtin typeset'
integer='\typeset -i'
local='\typeset'
login='\exec login'
nameref='\builtin typeset -n'
nameref='\typeset -n'
nohup='nohup '
r='\builtin fc -e -'
source='PATH=$PATH:. \command .'
@ -7414,14 +7427,14 @@ stdin:
alias
typeset -f
expected-stdout:
autoload='\builtin typeset -fu'
functions='\builtin typeset -f'
autoload='\typeset -fu'
functions='\typeset -f'
hash='\builtin alias -t'
history='\builtin fc -l'
integer='\builtin typeset -i'
local='\builtin typeset'
integer='\typeset -i'
local='\typeset'
login='\exec login'
nameref='\builtin typeset -n'
nameref='\typeset -n'
nohup='nohup '
r='\builtin fc -e -'
source='PATH=$PATH:. \command .'
@ -7437,14 +7450,14 @@ stdin:
./sh -c 'alias; typeset -f'
rm -f sh
expected-stdout:
autoload='\builtin typeset -fu'
functions='\builtin typeset -f'
autoload='\typeset -fu'
functions='\typeset -f'
hash='\builtin alias -t'
history='\builtin fc -l'
integer='\builtin typeset -i'
local='\builtin typeset'
integer='\typeset -i'
local='\typeset'
login='\exec login'
nameref='\builtin typeset -n'
nameref='\typeset -n'
nohup='nohup '
r='\builtin fc -e -'
source='PATH=$PATH:. \command .'
@ -7460,14 +7473,14 @@ stdin:
alias
typeset -f
expected-stdout:
autoload='\builtin typeset -fu'
functions='\builtin typeset -f'
autoload='\typeset -fu'
functions='\typeset -f'
hash='\builtin alias -t'
history='\builtin fc -l'
integer='\builtin typeset -i'
local='\builtin typeset'
integer='\typeset -i'
local='\typeset'
login='\exec login'
nameref='\builtin typeset -n'
nameref='\typeset -n'
nohup='nohup '
r='\builtin fc -e -'
source='PATH=$PATH:. \command .'
@ -7482,14 +7495,14 @@ stdin:
./sh -c 'alias; typeset -f'
rm -f sh
expected-stdout:
autoload='\builtin typeset -fu'
functions='\builtin typeset -f'
autoload='\typeset -fu'
functions='\typeset -f'
hash='\builtin alias -t'
history='\builtin fc -l'
integer='\builtin typeset -i'
local='\builtin typeset'
integer='\typeset -i'
local='\typeset'
login='\exec login'
nameref='\builtin typeset -n'
nameref='\typeset -n'
nohup='nohup '
r='\builtin fc -e -'
source='PATH=$PATH:. \command .'
@ -7550,8 +7563,8 @@ stdin:
:|| local() { :; }
alias local
expected-stdout:
local='\builtin typeset'
local='\builtin typeset'
local='\typeset'
local='\typeset'
---
name: arrays-1
description:

View File

@ -1,5 +1,5 @@
# $Id$
# $MirOS: src/bin/mksh/dot.mkshrc,v 1.93 2015/03/08 23:50:00 tg Exp $
# $MirOS: src/bin/mksh/dot.mkshrc,v 1.94 2015/03/14 05:23:14 tg Exp $
#-
# Copyright (c) 2002, 2003, 2004, 2006, 2007, 2008, 2009, 2010,
# 2011, 2012, 2013, 2014, 2015
@ -32,14 +32,14 @@ PS1='#'; (( USER_ID )) && PS1='$'; [[ ${HOSTNAME:=$(\ulimit -c 0; hostname -s \
2>/dev/null)} = *([ ]|localhost) ]] && HOSTNAME=$(\ulimit -c 0; hostname \
2>/dev/null); \: ${EDITOR:=/bin/ed} ${HOSTNAME:=nil} ${TERM:=vt100}
\: ${MKSH:=$(\builtin whence -p mksh)}; PS4='[$EPOCHREALTIME] '; PS1=$'\001\r''${|
\builtin typeset e=$?
\typeset e=$?
(( e )) && REPLY+="$e|"
REPLY+=${USER:=$(\ulimit -c 0; id -un 2>/dev/null || \echo \?)}
REPLY+=@${HOSTNAME%%.*}:
\builtin typeset d=${PWD:-?} p=~; [[ $p = ?(*/) ]] || d=${d/#$p/~}
\builtin typeset m=${%d} n p=...; (( m > 0 )) || m=${#d}
\typeset d=${PWD:-?} p=~; [[ $p = ?(*/) ]] || d=${d/#$p/~}
\typeset m=${%d} n p=...; (( m > 0 )) || m=${#d}
(( m > (n = (COLUMNS/3 < 7 ? 7 : COLUMNS/3)) )) && d=${d:(-n)} || p=
REPLY+=$p$d
@ -62,12 +62,12 @@ if \command -v hd >/dev/null; then \:; elif \command -v hexdump >/dev/null; then
}
else
function hd {
\builtin typeset -Uui16 -Z11 pos=0
\builtin typeset -Uui16 -Z5 hv=2147483647
\builtin typeset dasc line i
\typeset -Uui16 -Z11 pos=0
\typeset -Uui16 -Z5 hv=2147483647
\typeset dasc line i
\cat "$@" | { \set +U; if \read -arN -1 line; then
\builtin typeset -i1 'line[*]'
\typeset -i1 'line[*]'
i=0
while (( i < ${#line[*]} )); do
hv=${line[i++]}
@ -109,7 +109,7 @@ function cd {
\chpwd "$@"
}
function cd_csh {
\builtin typeset d t=${1/#~/$DIRSTACKBASE}
\typeset d t=${1/#~/$DIRSTACKBASE}
if ! d=$(\builtin cd "$t" 2>&1); then
\builtin print -u2 "${1}: ${d##*cd: $t: }."
@ -118,8 +118,8 @@ function cd_csh {
\cd "$t"
}
function dirs {
\builtin typeset d dwidth
\builtin typeset -i fl=0 fv=0 fn=0 cpos=0
\typeset d dwidth
\typeset -i fl=0 fv=0 fn=0 cpos=0
while \getopts ":lvn" d; do
case $d {
@ -162,8 +162,8 @@ function dirs {
\return 0
}
function popd {
\builtin typeset d fa
\builtin typeset -i n=1
\typeset d fa
\typeset -i n=1
while \getopts ":0123456789lvn" d; do
case $d {
@ -198,8 +198,8 @@ function popd {
\dirs $fa
}
function pushd {
\builtin typeset d fa
\builtin typeset -i n=1
\typeset d fa
\typeset -i n=1
while \getopts ":0123456789lvn" d; do
case $d {
@ -263,11 +263,11 @@ function smores {
# base64 encoder and decoder, RFC compliant, NUL safe
function Lb64decode {
[[ -o utf8-mode ]]; \builtin typeset u=$? c s="$*" t
[[ -o utf8-mode ]]; \typeset u=$? c s="$*" t
\set +U
[[ -n $s ]] || { s=$(\cat; \builtin print x); s=${s%x}; }
\builtin typeset -i i=0 j=0 n=${#s} p=0 v x
\builtin typeset -i16 o
\typeset -i i=0 j=0 n=${#s} p=0 v x
\typeset -i16 o
while (( i < n )); do
c=${s:(i++):1}
@ -301,7 +301,7 @@ function Lb64decode {
\set -A Lb64encode_code -- A B C D E F G H I J K L M N O P Q R S T U V W X Y Z \
a b c d e f g h i j k l m n o p q r s t u v w x y z 0 1 2 3 4 5 6 7 8 9 + /
function Lb64encode {
[[ -o utf8-mode ]]; \builtin typeset u=$? c s t
[[ -o utf8-mode ]]; \typeset u=$? c s t
\set +U
if (( $# )); then
\read -raN-1 s <<<"$*"
@ -309,7 +309,7 @@ function Lb64encode {
else
\read -raN-1 s
fi
\builtin typeset -i i=0 n=${#s[*]} j v
\typeset -i i=0 n=${#s[*]} j v
while (( i < n )); do
(( v = s[i++] << 16 ))
@ -335,12 +335,12 @@ function Lb64encode {
}
# Better Avalanche for the Jenkins Hash
\builtin typeset -Z11 -Uui16 Lbafh_v
\typeset -Z11 -Uui16 Lbafh_v
function Lbafh_init {
Lbafh_v=0
}
function Lbafh_add {
[[ -o utf8-mode ]]; \builtin typeset u=$? s
[[ -o utf8-mode ]]; \typeset u=$? s
\set +U
if (( $# )); then
\read -raN-1 s <<<"$*"
@ -348,7 +348,7 @@ function Lbafh_add {
else
\read -raN-1 s
fi
\builtin typeset -i i=0 n=${#s[*]}
\typeset -i i=0 n=${#s[*]}
while (( i < n )); do
((# Lbafh_v = (Lbafh_v + s[i++] + 1) * 1025 ))
@ -358,7 +358,7 @@ function Lbafh_add {
(( u )) || \set -U
}
function Lbafh_finish {
\builtin typeset -Ui t
\typeset -Ui t
((# t = (((Lbafh_v >> 7) & 0x01010101) * 0x1B) ^ \
((Lbafh_v << 1) & 0xFEFEFEFE) ))
@ -383,21 +383,21 @@ function setenv {
# toggle built-in aliases and utilities, and aliases and functions from here
function enable {
\builtin typeset doprnt=0 mode=1 x y z rv=0
\builtin typeset b_alias i_alias i_func nalias=0 nfunc=0 i_all
\typeset doprnt=0 mode=1 x y z rv=0
\typeset b_alias i_alias i_func nalias=0 nfunc=0 i_all
\set -A b_alias
\set -A i_alias
\set -A i_func
# accumulate mksh built-in aliases, in ASCIIbetical order
i_alias[nalias]=autoload; b_alias[nalias++]='\builtin typeset -fu'
i_alias[nalias]=functions; b_alias[nalias++]='\builtin typeset -f'
i_alias[nalias]=autoload; b_alias[nalias++]='\typeset -fu'
i_alias[nalias]=functions; b_alias[nalias++]='\typeset -f'
i_alias[nalias]=hash; b_alias[nalias++]='\builtin alias -t'
i_alias[nalias]=history; b_alias[nalias++]='\builtin fc -l'
i_alias[nalias]=integer; b_alias[nalias++]='\builtin typeset -i'
i_alias[nalias]=local; b_alias[nalias++]='\builtin typeset'
i_alias[nalias]=integer; b_alias[nalias++]='\typeset -i'
i_alias[nalias]=local; b_alias[nalias++]='\typeset'
i_alias[nalias]=login; b_alias[nalias++]='\exec login'
i_alias[nalias]=nameref; b_alias[nalias++]='\builtin typeset -n'
i_alias[nalias]=nameref; b_alias[nalias++]='\typeset -n'
i_alias[nalias]=nohup; b_alias[nalias++]='nohup '
i_alias[nalias]=r; b_alias[nalias++]='\builtin fc -e -'
i_alias[nalias]=source; b_alias[nalias++]='PATH=$PATH:. \command .'

20
lex.c
View File

@ -2,7 +2,7 @@
/*-
* Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
* 2011, 2012, 2013, 2014
* 2011, 2012, 2013, 2014, 2015
* Thorsten Glaser <tg@mirbsd.org>
*
* Provided that these terms and disclaimer and all copyright notices
@ -23,7 +23,7 @@
#include "sh.h"
__RCSID("$MirOS: src/bin/mksh/lex.c,v 1.196 2015/03/01 16:02:48 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/lex.c,v 1.197 2015/03/14 05:23:15 tg Exp $");
/*
* states while lexing word
@ -1044,13 +1044,16 @@ yylex(int cf)
} else
while ((dp - ident) < IDENT && (c = *sp++) == CHAR)
*dp++ = *sp++;
/* make sure the ident array stays NUL padded */
memset(dp, 0, (ident + IDENT) - dp + 1);
if (c != EOS)
/* word is not unquoted */
*ident = '\0';
dp = ident;
/* make sure the ident array stays NUL padded */
memset(dp, 0, (ident + IDENT) - dp + 1);
if (*ident != '\0' && (cf & (KEYWORD | ALIAS))) {
if (!(cf & (KEYWORD | ALIAS)))
return (LWORD);
if (*ident != '\0') {
struct tbl *p;
uint32_t h = hash(ident);
@ -1106,6 +1109,11 @@ yylex(int cf)
goto Again;
}
}
} else if (cf & ALIAS) {
/* retain typeset et al. even when quoted */
if (assign_command((dp = wdstrip(yylval.cp, 0))))
strlcpy(ident, dp, sizeof(ident));
afree(dp, ATEMP);
}
return (LWORD);

12
main.c
View File

@ -34,7 +34,7 @@
#include <locale.h>
#endif
__RCSID("$MirOS: src/bin/mksh/main.c,v 1.289 2015/03/08 22:54:33 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/main.c,v 1.290 2015/03/14 05:23:15 tg Exp $");
extern char **environ;
@ -66,8 +66,8 @@ static const char *initcoms[] = {
Ttypeset, "-x", "HOME", "PATH", "SHELL", NULL,
Ttypeset, "-i10", "COLUMNS", "LINES", "SECONDS", "TMOUT", NULL,
Talias,
"integer=\\builtin typeset -i",
"local=\\builtin typeset",
"integer=\\typeset -i",
"local=\\typeset",
/* not "alias -t --": hash -r needs to work */
"hash=\\builtin alias -t",
"type=\\builtin whence -v",
@ -76,10 +76,10 @@ static const char *initcoms[] = {
/* not in ARGE mksh due to no job control */
"stop=\\kill -STOP",
#endif
"autoload=\\builtin typeset -fu",
"functions=\\builtin typeset -f",
"autoload=\\typeset -fu",
"functions=\\typeset -f",
"history=\\builtin fc -l",
"nameref=\\builtin typeset -n",
"nameref=\\typeset -n",
"nohup=nohup ",
"r=\\builtin fc -e -",
"source=PATH=$PATH:. \\command .",

12
mksh.1
View File

@ -1,4 +1,4 @@
.\" $MirOS: src/bin/mksh/mksh.1,v 1.354 2015/03/14 05:17:17 tg Exp $
.\" $MirOS: src/bin/mksh/mksh.1,v 1.355 2015/03/14 05:23:16 tg Exp $
.\" $OpenBSD: ksh.1,v 1.157 2015/03/13 19:58:40 jmc Exp $
.\"-
.\" Copyright © 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
@ -1120,14 +1120,14 @@ also by newline) may be one same parse tree.
.Pp
The following command aliases are defined automatically by the shell:
.Bd -literal -offset indent
autoload=\*(aq\ebuiltin typeset \-fu\*(aq
functions=\*(aq\ebuiltin typeset \-f\*(aq
autoload=\*(aq\etypeset \-fu\*(aq
functions=\*(aq\etypeset \-f\*(aq
hash=\*(aq\ebuiltin alias \-t\*(aq
history=\*(aq\ebuiltin fc \-l\*(aq
integer=\*(aq\ebuiltin typeset \-i\*(aq
local=\*(aq\ebuiltin typeset\*(aq
integer=\*(aq\etypeset \-i\*(aq
local=\*(aq\etypeset\*(aq
login=\*(aq\eexec login\*(aq
nameref=\*(aq\ebuiltin typeset \-n\*(aq
nameref=\*(aq\etypeset \-n\*(aq
nohup=\*(aqnohup \*(aq
r=\*(aq\ebuiltin fc \-e \-\*(aq
source=\*(aqPATH=$PATH:. \ecommand .'

5
sh.h
View File

@ -169,9 +169,9 @@
#endif
#ifdef EXTERN
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.718 2015/03/14 04:37:54 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.719 2015/03/14 05:23:17 tg Exp $");
#endif
#define MKSH_VERSION "R50 2015/03/08"
#define MKSH_VERSION "R50 2015/03/13"
/* arithmetic types: C implementation */
#if !HAVE_CAN_INTTYPES
@ -1916,6 +1916,7 @@ char *shf_smprintf(const char *, ...)
ssize_t shf_vfprintf(struct shf *, const char *, va_list)
MKSH_A_FORMAT(__printf__, 2, 0);
/* syn.c */
int assign_command(const char *);
void initkeywords(void);
struct op *compile(Source *, bool);
bool parse_usec(const char *, struct timeval *);

5
syn.c
View File

@ -23,7 +23,7 @@
#include "sh.h"
__RCSID("$MirOS: src/bin/mksh/syn.c,v 1.98 2015/03/14 04:38:13 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/syn.c,v 1.99 2015/03/14 05:23:18 tg Exp $");
struct nesting_state {
int start_token; /* token than began nesting (eg, FOR) */
@ -58,7 +58,6 @@ static struct op *newtp(int);
static void syntaxerr(const char *) MKSH_A_NORETURN;
static void nesting_push(struct nesting_state *, int);
static void nesting_pop(struct nesting_state *);
static int assign_command(const char *);
static int inalias(struct source *) MKSH_A_PURE;
static Test_op dbtestp_isa(Test_env *, Test_meta);
static const char *dbtestp_getopnd(Test_env *, Test_op, bool);
@ -927,7 +926,7 @@ compile(Source *s, bool skiputf8bom)
* a=a
* $
*/
static int
int
assign_command(const char *s)
{
if (!*s)