overhaul IFS handling, fix bugs reported by Stephane Chazelas and mikeserv

now we’re at: 486 passed testsuite items, 0 failed
ifs.sh still: # tests 6856 passed 6856 failed 0
This commit is contained in:
tg
2014-10-03 17:32:12 +00:00
parent de53d2df1c
commit 968dc7a764
6 changed files with 441 additions and 37 deletions

View File

@@ -1,5 +1,5 @@
#!/bin/sh
srcversion='$MirOS: src/bin/mksh/Build.sh,v 1.667 2014/10/03 17:19:26 tg Exp $'
srcversion='$MirOS: src/bin/mksh/Build.sh,v 1.668 2014/10/03 17:32:07 tg Exp $'
#-
# Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
# 2011, 2012, 2013, 2014
@@ -1784,7 +1784,7 @@ else
#define EXTERN
#define MKSH_INCLUDES_ONLY
#include "sh.h"
__RCSID("$MirOS: src/bin/mksh/Build.sh,v 1.667 2014/10/03 17:19:26 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/Build.sh,v 1.668 2014/10/03 17:32:07 tg Exp $");
int main(void) { printf("Hello, World!\n"); return (isatty(0)); }
EOF
case $cm in
@@ -2316,7 +2316,7 @@ addsrcs '!' HAVE_STRLCPY strlcpy.c
addsrcs USE_PRINTF_BUILTIN printf.c
test 1 = "$USE_PRINTF_BUILTIN" && add_cppflags -DMKSH_PRINTF_BUILTIN
test 1 = "$HAVE_CAN_VERB" && CFLAGS="$CFLAGS -verbose"
add_cppflags -DMKSH_BUILD_R=502
add_cppflags -DMKSH_BUILD_R=503
$e $bi$me: Finished configuration testing, now producing output.$ao

View File

@@ -1,4 +1,4 @@
# $MirOS: src/bin/mksh/Makefile,v 1.136 2014/09/03 19:22:48 tg Exp $
# $MirOS: src/bin/mksh/Makefile,v 1.137 2014/10/03 17:32:08 tg Exp $
#-
# Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
# 2011, 2012, 2013, 2014
@@ -48,14 +48,14 @@ CPPFLAGS+= -DMKSH_ASSUME_UTF8 -DMKSH_DISABLE_DEPRECATED \
-DHAVE_CAN_UCBINT8=1 -DHAVE_RLIM_T=1 -DHAVE_SIG_T=1 \
-DHAVE_SYS_ERRLIST=1 -DHAVE_SYS_SIGNAME=1 -DHAVE_SYS_SIGLIST=1 \
-DHAVE_FLOCK=1 -DHAVE_LOCK_FCNTL=1 -DHAVE_GETRUSAGE=1 \
-DHAVE_GETSID=1 -DHAVE_GETTIMEOFDAY=1 -DHAVE_KILLPG=1 \
-DHAVE_MEMMOVE=1 -DHAVE_MKNOD=0 -DHAVE_MMAP=1 -DHAVE_NICE=1 \
-DHAVE_REVOKE=1 -DHAVE_SETLOCALE_CTYPE=0 \
-DHAVE_GETSID=1 -DHAVE_GETTIMEOFDAY=1 -DHAVE_ISSETUGID=1 \
-DHAVE_KILLPG=1 -DHAVE_MEMMOVE=1 -DHAVE_MKNOD=0 -DHAVE_MMAP=1 \
-DHAVE_NICE=1 -DHAVE_REVOKE=1 -DHAVE_SETLOCALE_CTYPE=0 \
-DHAVE_LANGINFO_CODESET=0 -DHAVE_SELECT=1 -DHAVE_SETRESUGID=1 \
-DHAVE_SETGROUPS=1 -DHAVE_STRERROR=0 -DHAVE_STRSIGNAL=0 \
-DHAVE_STRLCPY=1 -DHAVE_FLOCK_DECL=1 -DHAVE_REVOKE_DECL=1 \
-DHAVE_SYS_ERRLIST_DECL=1 -DHAVE_SYS_SIGLIST_DECL=1 \
-DHAVE_PERSISTENT_HISTORY=1 -DMKSH_BUILD_R=502
-DHAVE_PERSISTENT_HISTORY=1 -DMKSH_BUILD_R=503
CPPFLAGS+= -D${${PROG:L}_tf:C/(Mir${MAN:E}{0,1}){2}/4/:S/x/mksh_BUILD/:U}
CPPFLAGS+= -I.
COPTS+= -std=c89 -Wall

402
check.t
View File

@@ -1,4 +1,4 @@
# $MirOS: src/bin/mksh/check.t,v 1.658 2014/09/03 19:22:49 tg Exp $
# $MirOS: src/bin/mksh/check.t,v 1.659 2014/10/03 17:32:09 tg Exp $
# OpenBSD src/regress/bin/ksh updated: 2013/12/02 20:39:44
#-
# Copyright © 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
@@ -27,7 +27,7 @@
# http://www.freebsd.org/cgi/cvsweb.cgi/src/tools/regression/bin/test/regress.sh?rev=HEAD
expected-stdout:
@(#)MIRBSD KSH R50 2014/09/03
@(#)MIRBSD KSH R50 2014/10/03
description:
Check version of shell.
stdin:
@@ -36,7 +36,7 @@ name: KSH_VERSION
category: shell:legacy-no
---
expected-stdout:
@(#)LEGACY KSH R50 2014/09/03
@(#)LEGACY KSH R50 2014/10/03
description:
Check version of legacy shell.
stdin:
@@ -3736,7 +3736,6 @@ expected-stdout:
name: IFS-subst-3
description:
Check leading IFS non-whitespace after trim does make a field
expected-fail: yes
stdin:
showargs() { for i; do echo -n " <$i>"; done; echo; }
IFS=:
@@ -3744,6 +3743,390 @@ stdin:
expected-stdout:
<1> <> <foo> <bar>
---
name: IFS-subst-4-1
description:
reported by mikeserv
stdin:
a='space divded argument
here'
IFS=\ ; set -- $a
IFS= ; q="$*" ; nq=$*
printf '<%s>\n' "$*" $* "$q" "$nq"
[ "$q" = "$nq" ] && echo =true || echo =false
expected-stdout:
<spacedivdedargument
here>
<space>
<divded>
<argument
here>
<spacedivdedargument
here>
<spacedivdedargument
here>
=true
---
name: IFS-subst-4-2
description:
extended testsuite based on problem by mikeserv
stdin:
a='space divded argument
here'
IFS=\ ; set -- $a
IFS= ; q="$@" ; nq=$@
printf '<%s>\n' "$*" $* "$q" "$nq"
[ "$q" = "$nq" ] && echo =true || echo =false
expected-stdout:
<spacedivdedargument
here>
<space>
<divded>
<argument
here>
<space divded argument
here>
<space divded argument
here>
=true
---
name: IFS-subst-4-3
description:
extended testsuite based on problem by mikeserv
stdin:
a='space divded argument
here'
IFS=\ ; set -- $a; IFS=
qs="$*"
nqs=$*
qk="$@"
nqk=$@
printf '= qs '; printf '<%s>\n' "$qs"
printf '=nqs '; printf '<%s>\n' "$nqs"
printf '= qk '; printf '<%s>\n' "$qk"
printf '=nqk '; printf '<%s>\n' "$nqk"
printf '~ qs '; printf '<%s>\n' "$*"
printf '~nqs '; printf '<%s>\n' $*
printf '~ qk '; printf '<%s>\n' "$@"
printf '~nqk '; printf '<%s>\n' $@
expected-stdout:
= qs <spacedivdedargument
here>
=nqs <spacedivdedargument
here>
= qk <space divded argument
here>
=nqk <space divded argument
here>
~ qs <spacedivdedargument
here>
~nqs <space>
<divded>
<argument
here>
~ qk <space>
<divded>
<argument
here>
~nqk <space>
<divded>
<argument
here>
---
name: IFS-subst-4-4
description:
extended testsuite based on problem by mikeserv
stdin:
a='space divded argument
here'
IFS=\ ; set -- $a; IFS=
qs="$*"
printf '= qs '; printf '<%s>\n' "$qs"
printf '~ qs '; printf '<%s>\n' "$*"
nqs=$*
printf '=nqs '; printf '<%s>\n' "$nqs"
printf '~nqs '; printf '<%s>\n' $*
qk="$@"
printf '= qk '; printf '<%s>\n' "$qk"
printf '~ qk '; printf '<%s>\n' "$@"
nqk=$@
printf '=nqk '; printf '<%s>\n' "$nqk"
printf '~nqk '; printf '<%s>\n' $@
expected-stdout:
= qs <spacedivdedargument
here>
~ qs <spacedivdedargument
here>
=nqs <spacedivdedargument
here>
~nqs <space>
<divded>
<argument
here>
= qk <space divded argument
here>
~ qk <space>
<divded>
<argument
here>
=nqk <space divded argument
here>
~nqk <space>
<divded>
<argument
here>
---
name: IFS-subst-4-4p
description:
extended testsuite based on problem by mikeserv
stdin:
a='space divded argument
here'
IFS=\ ; set -- $a; IFS=
unset v
qs=${v:-"$*"}
printf '= qs '; printf '<%s>\n' "$qs"
printf '~ qs '; printf '<%s>\n' ${v:-"$*"}
nqs=${v:-$*}
printf '=nqs '; printf '<%s>\n' "$nqs"
printf '~nqs '; printf '<%s>\n' ${v:-$*}
qk=${v:-"$@"}
printf '= qk '; printf '<%s>\n' "$qk"
printf '~ qk '; printf '<%s>\n' ${v:-"$@"}
nqk=${v:-$@}
printf '=nqk '; printf '<%s>\n' "$nqk"
printf '~nqk '; printf '<%s>\n' ${v:-$@}
expected-stdout:
= qs <spacedivdedargument
here>
~ qs <spacedivdedargument
here>
=nqs <spacedivdedargument
here>
~nqs <space>
<divded>
<argument
here>
= qk <space divded argument
here>
~ qk <space>
<divded>
<argument
here>
=nqk <space divded argument
here>
~nqk <space>
<divded>
<argument
here>
---
name: IFS-subst-4-5
description:
extended testsuite based on problem by mikeserv
stdin:
a='space divded argument
here'
IFS=\ ; set -- $a; IFS=,
qs="$*"
printf '= qs '; printf '<%s>\n' "$qs"
printf '~ qs '; printf '<%s>\n' "$*"
nqs=$*
printf '=nqs '; printf '<%s>\n' "$nqs"
printf '~nqs '; printf '<%s>\n' $*
qk="$@"
printf '= qk '; printf '<%s>\n' "$qk"
printf '~ qk '; printf '<%s>\n' "$@"
nqk=$@
printf '=nqk '; printf '<%s>\n' "$nqk"
printf '~nqk '; printf '<%s>\n' $@
expected-stdout:
= qs <space,divded,argument
here>
~ qs <space,divded,argument
here>
=nqs <space,divded,argument
here>
~nqs <space>
<divded>
<argument
here>
= qk <space divded argument
here>
~ qk <space>
<divded>
<argument
here>
=nqk <space divded argument
here>
~nqk <space>
<divded>
<argument
here>
---
name: IFS-subst-4-5p
description:
extended testsuite based on problem by mikeserv
stdin:
a='space divded argument
here'
IFS=\ ; set -- $a; IFS=,
unset v
qs=${v:-"$*"}
printf '= qs '; printf '<%s>\n' "$qs"
printf '~ qs '; printf '<%s>\n' ${v:-"$*"}
nqs=${v:-$*}
printf '=nqs '; printf '<%s>\n' "$nqs"
printf '~nqs '; printf '<%s>\n' ${v:-$*}
qk=${v:-"$@"}
printf '= qk '; printf '<%s>\n' "$qk"
printf '~ qk '; printf '<%s>\n' ${v:-"$@"}
nqk=${v:-$@}
printf '=nqk '; printf '<%s>\n' "$nqk"
printf '~nqk '; printf '<%s>\n' ${v:-$@}
expected-stdout:
= qs <space,divded,argument
here>
~ qs <space,divded,argument
here>
=nqs <space,divded,argument
here>
~nqs <space>
<divded>
<argument
here>
= qk <space divded argument
here>
~ qk <space>
<divded>
<argument
here>
=nqk <space divded argument
here>
~nqk <space>
<divded>
<argument
here>
---
name: IFS-subst-5
description:
extended testsuite based on IFS-subst-3
differs slightly from ksh93:
- omit trailing field in a3zna, a7ina (unquoted $@ expansion)
- has extra middle fields in b5ins, b7ina (IFS_NWS unquoted expansion)
differs slightly from bash:
- omit leading field in a5ins, a7ina (IFS_NWS unquoted expansion)
differs slightly from zsh:
- differs in assignment, not expansion; probably zsh bug
- has extra middle fields in b5ins, b7ina (IFS_NWS unquoted expansion)
'emulate sh' zsh has extra fields in
- a5ins (IFS_NWS unquoted $*)
- b5ins, matching mkshs
stdin:
"$__progname" -c 'IFS=; set -- "" 2 ""; printf "[%s]\n" $*; x=$*; printf "<%s>\n" "$x"'
echo '=a1zns'
"$__progname" -c 'IFS=; set -- "" 2 ""; printf "[%s]\n" "$*"; x="$*"; printf "<%s>\n" "$x"'
echo '=a2zqs'
"$__progname" -c 'IFS=; set -- "" 2 ""; printf "[%s]\n" $@; x=$@; printf "<%s>\n" "$x"'
echo '=a3zna'
"$__progname" -c 'IFS=; set -- "" 2 ""; printf "[%s]\n" "$@"; x="$@"; printf "<%s>\n" "$x"'
echo '=a4zqa'
"$__progname" -c 'IFS=,; set -- "" 2 ""; printf "[%s]\n" $*; x=$*; printf "<%s>\n" "$x"'
echo '=a5ins'
"$__progname" -c 'IFS=,; set -- "" 2 ""; printf "[%s]\n" "$*"; x="$*"; printf "<%s>\n" "$x"'
echo '=a6iqs'
"$__progname" -c 'IFS=,; set -- "" 2 ""; printf "[%s]\n" $@; x=$@; printf "<%s>\n" "$x"'
echo '=a7ina'
"$__progname" -c 'IFS=,; set -- "" 2 ""; printf "[%s]\n" "$@"; x="$@"; printf "<%s>\n" "$x"'
echo '=a8iqa'
"$__progname" -c 'IFS=; set -- A B "" "" C; printf "[%s]\n" $*; x=$*; printf "<%s>\n" "$x"'
echo '=b1zns'
"$__progname" -c 'IFS=; set -- A B "" "" C; printf "[%s]\n" "$*"; x="$*"; printf "<%s>\n" "$x"'
echo '=b2zqs'
"$__progname" -c 'IFS=; set -- A B "" "" C; printf "[%s]\n" $@; x=$@; printf "<%s>\n" "$x"'
echo '=b3zna'
"$__progname" -c 'IFS=; set -- A B "" "" C; printf "[%s]\n" "$@"; x="$@"; printf "<%s>\n" "$x"'
echo '=b4zqa'
"$__progname" -c 'IFS=,; set -- A B "" "" C; printf "[%s]\n" $*; x=$*; printf "<%s>\n" "$x"'
echo '=b5ins'
"$__progname" -c 'IFS=,; set -- A B "" "" C; printf "[%s]\n" "$*"; x="$*"; printf "<%s>\n" "$x"'
echo '=b6iqs'
"$__progname" -c 'IFS=,; set -- A B "" "" C; printf "[%s]\n" $@; x=$@; printf "<%s>\n" "$x"'
echo '=b7ina'
"$__progname" -c 'IFS=,; set -- A B "" "" C; printf "[%s]\n" "$@"; x="$@"; printf "<%s>\n" "$x"'
echo '=b8iqa'
expected-stdout:
[2]
<2>
=a1zns
[2]
<2>
=a2zqs
[2]
< 2 >
=a3zna
[]
[2]
[]
< 2 >
=a4zqa
[2]
<,2,>
=a5ins
[,2,]
<,2,>
=a6iqs
[2]
< 2 >
=a7ina
[]
[2]
[]
< 2 >
=a8iqa
[A]
[B]
[C]
<ABC>
=b1zns
[ABC]
<ABC>
=b2zqs
[A]
[B]
[C]
<A B C>
=b3zna
[A]
[B]
[]
[]
[C]
<A B C>
=b4zqa
[A]
[B]
[]
[]
[C]
<A,B,,,C>
=b5ins
[A,B,,,C]
<A,B,,,C>
=b6iqs
[A]
[B]
[]
[]
[C]
<A B C>
=b7ina
[A]
[B]
[]
[]
[C]
<A B C>
=b8iqa
---
name: IFS-arith-1
description:
http://austingroupbugs.net/view.php?id=832
@@ -7802,6 +8185,17 @@ stdin:
expected-stdout:
<1> <> <2> <> <+> <> <3> <> <+> <> .
---
name: varexpand-null-3
description:
Ensure concatenating behaviour matches other shells
although the line 2<> is probably wrong? XNULLSUB case.
stdin:
x=; printf "1<%s>\n" "$x$@"
set A; printf "2<%s>\n" "${@:+}"
expected-stdout:
1<>
2<>
---
name: print-funny-chars
description:
Check print builtin's capability to output designated characters

29
eval.c
View File

@@ -23,7 +23,7 @@
#include "sh.h"
__RCSID("$MirOS: src/bin/mksh/eval.c,v 1.151 2014/07/29 16:29:11 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/eval.c,v 1.152 2014/10/03 17:32:11 tg Exp $");
/*
* string expansion
@@ -245,7 +245,7 @@ expand(
/* for alias, readonly, set, typeset commands */
if ((f & DOVACHECK) && is_wdvarassign(ccp)) {
f &= ~(DOVACHECK | DOBLANK | DOGLOB | DOTILDE);
f |= DOASNTILDE;
f |= DOASNTILDE | DOASNFIELD;
}
if (Flag(FNOGLOB))
f &= ~DOGLOB;
@@ -663,6 +663,7 @@ expand(
f |= DOTEMP;
/* FALLTHROUGH */
default:
word = IFS_WORD;
/* Enable tilde expansion */
tilde_ok = 1;
f |= DOTILDE;
@@ -741,6 +742,7 @@ expand(
if (f & DOBLANK)
doblank++;
st = st->prev;
word = quote || (!*x.str && (f & DOASNFIELD)) ? IFS_WORD : IFS_WS;
continue;
case '?': {
char *s = Xrestpos(ds, dp, st->base);
@@ -756,6 +758,7 @@ expand(
case 0x100 | 'Q':
dp = Xrestpos(ds, dp, st->base);
type = XSUB;
word = quote || (!*x.str && (f & DOASNFIELD)) ? IFS_WORD : IFS_WS;
if (f & DOBLANK)
doblank++;
st = st->prev;
@@ -795,13 +798,6 @@ expand(
type = XBASE;
if (f & DOBLANK) {
doblank--;
/*
* XXX not really correct:
* x=; "$x$@"
* should generate a null argument and
* set A; "${@:+}"
* shouldn't.
*/
if (dp == Xstring(ds, dp))
word = IFS_WS;
}
@@ -825,7 +821,7 @@ expand(
if ((c = *x.str++) == '\0') {
/*
* force null words to be created so
* set -- '' 2 ''; foo "$@" will do
* set -- "" 2 ""; echo "$@" will do
* the right thing
*/
if (quote && x.split)
@@ -837,9 +833,21 @@ expand(
continue;
}
c = ifs0;
if ((f & DOASNFIELD)) {
/* assignment, do not field-split */
if (x.split) {
c = ' ';
break;
}
if (c == 0) {
continue;
}
}
if (c == 0) {
if (quote && !x.split)
continue;
if (!quote && word == IFS_WS)
continue;
/* this is so we don't terminate */
c = ' ';
/* now force-emit a word */
@@ -922,6 +930,7 @@ expand(
strlen(cp) + 1));
fdo = 0;
saw_eq = false;
/* must be 1/0 */
tilde_ok = (f & (DOTILDE | DOASNTILDE)) ? 1 : 0;
if (c == 0)
return;

4
exec.c
View File

@@ -23,7 +23,7 @@
#include "sh.h"
__RCSID("$MirOS: src/bin/mksh/exec.c,v 1.132 2014/06/24 18:38:31 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/exec.c,v 1.133 2014/10/03 17:32:11 tg Exp $");
#ifndef MKSH_DEFAULT_EXECSHELL
#define MKSH_DEFAULT_EXECSHELL "/bin/sh"
@@ -635,7 +635,7 @@ comexec(struct op *t, struct tbl * volatile tp, const char **ap,
for (i = 0; t->vars[i]; i++) {
/* do NOT lookup in the new var/fn block just created */
e->loc = l_expand;
cp = evalstr(t->vars[i], DOASNTILDE);
cp = evalstr(t->vars[i], DOASNTILDE | DOASNFIELD);
e->loc = l_assign;
if (Flag(FXTRACE)) {
const char *ccp;

7
sh.h
View File

@@ -169,9 +169,9 @@
#endif
#ifdef EXTERN
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.694 2014/09/03 19:22:50 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.695 2014/10/03 17:32:12 tg Exp $");
#endif
#define MKSH_VERSION "R50 2014/09/03"
#define MKSH_VERSION "R50 2014/10/03"
/* arithmetic types: C implementation */
#if !HAVE_CAN_INTTYPES
@@ -533,7 +533,7 @@ char *ucstrstr(char *, const char *);
#define mkssert(e) do { } while (/* CONSTCOND */ 0)
#endif
#if (!defined(MKSH_BUILDMAKEFILE4BSD) && !defined(MKSH_BUILDSH)) || (MKSH_BUILD_R != 502)
#if (!defined(MKSH_BUILDMAKEFILE4BSD) && !defined(MKSH_BUILDSH)) || (MKSH_BUILD_R != 503)
#error Must run Build.sh to compile this.
extern void thiswillneverbedefinedIhope(void);
int
@@ -1396,6 +1396,7 @@ struct ioword {
#define DOVACHECK BIT(9) /* var assign check (for typeset, set, etc) */
#define DOMARKDIRS BIT(10) /* force markdirs behaviour */
#define DOTCOMEXEC BIT(11) /* not an eval flag, used by sh -c hack */
#define DOASNFIELD BIT(12) /* is assignment, change field handling */
#define X_EXTRA 20 /* this many extra bytes in X string */