Oh well… this looks well, is done done, and gcc-snapshot doesn’t complain:

• correct order of built-in commands; use POSIX special versus “all others”
  plus “keeps assignments” as distinction, no longer play POSIX regular vs.
  others game; sync manpage
• fix LP#1156707: map (( internally to “let]” which is no valid function
  name and so can’t be overridden but is unlikely to be used otherwhere
  and not strictly permitted (by POSIX) anyway
• we do not need -Wno-overflow any more, either
• bump to R45
This commit is contained in:
tg 2013-04-26 21:22:50 +00:00
parent d8ce0c480b
commit deb4a3bf20
9 changed files with 110 additions and 126 deletions

View File

@ -1,5 +1,5 @@
#!/bin/sh
srcversion='$MirOS: src/bin/mksh/Build.sh,v 1.626 2013/04/26 19:40:07 tg Exp $'
srcversion='$MirOS: src/bin/mksh/Build.sh,v 1.627 2013/04/26 21:22:39 tg Exp $'
#-
# Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
# 2011, 2012, 2013
@ -1177,7 +1177,6 @@ i=0
if test $ct = gcc; then
# The following tests run with -Werror (gcc only) if possible
NOWARN=$DOWARN; phase=u
ac_flags 0 wnooverflow -Wno-overflow
# mksh is not written in CFrustFrust!
ac_flags 1 no_eh_frame -fno-asynchronous-unwind-tables
ac_flags 1 fnostrictaliasing -fno-strict-aliasing
@ -1532,7 +1531,7 @@ else
#define EXTERN
#define MKSH_INCLUDES_ONLY
#include "sh.h"
__RCSID("$MirOS: src/bin/mksh/Build.sh,v 1.626 2013/04/26 19:40:07 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/Build.sh,v 1.627 2013/04/26 21:22:39 tg Exp $");
int main(void) { printf("Hello, World!\n"); return (0); }
EOF
case $cm in
@ -1848,7 +1847,6 @@ ac_testdone
ac_cppflags
save_CFLAGS=$CFLAGS
test x1 = x$HAVE_CAN_WNOOVERFLOW && CFLAGS="$CFLAGS -Wno-overflow"
ac_testn compile_time_asserts_$$ '' 'whether compile-time assertions pass' <<-'EOF'
#define MKSH_INCLUDES_ONLY
#include "sh.h"
@ -2048,7 +2046,7 @@ addsrcs USE_PRINTF_BUILTIN printf.c
test 1 = "$USE_PRINTF_BUILTIN" && add_cppflags -DMKSH_PRINTF_BUILTIN
test 1 = "$HAVE_CAN_VERB" && CFLAGS="$CFLAGS -verbose"
test -n "$LDSTATIC" && add_cppflags -DMKSH_OPTSTATIC
add_cppflags -DMKSH_BUILD_R=449
add_cppflags -DMKSH_BUILD_R=451
$e $bi$me: Finished configuration testing, now producing output.$ao

View File

@ -1,4 +1,4 @@
# $MirOS: src/bin/mksh/Makefile,v 1.116 2013/04/26 19:40:09 tg Exp $
# $MirOS: src/bin/mksh/Makefile,v 1.117 2013/04/26 21:22:40 tg Exp $
#-
# Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
# 2011, 2012, 2013
@ -54,7 +54,7 @@ CPPFLAGS+= -DMKSH_ASSUME_UTF8 -DMKSH_DISABLE_DEPRECATED \
-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=449
-DHAVE_PERSISTENT_HISTORY=1 -DMKSH_BUILD_R=451
CPPFLAGS+= -D${${PROG:L}_tf:C/(Mir${MAN:E}{0,1}){2}/4/:S/x/mksh_BUILD/:U}
COPTS+= -std=c99 -Wall
.endif

30
check.t
View File

@ -1,4 +1,4 @@
# $MirOS: src/bin/mksh/check.t,v 1.606 2013/04/26 19:40:42 tg Exp $
# $MirOS: src/bin/mksh/check.t,v 1.607 2013/04/26 21:22:42 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 $
@ -29,7 +29,7 @@
# http://www.freebsd.org/cgi/cvsweb.cgi/src/tools/regression/bin/test/regress.sh?rev=HEAD
expected-stdout:
@(#)MIRBSD KSH R44 2013/04/26
@(#)MIRBSD KSH R45 2013/04/26
description:
Check version of shell.
stdin:
@ -38,7 +38,7 @@ name: KSH_VERSION
category: shell:legacy-no
---
expected-stdout:
@(#)LEGACY KSH R44 2013/04/26
@(#)LEGACY KSH R45 2013/04/26
description:
Check version of legacy shell.
stdin:
@ -9090,7 +9090,7 @@ expected-stdout:
}
inline_TWHILE() {
i=1
while let " i < 10 "
while let] " i < 10 "
do
echo $i
let ++i
@ -9100,20 +9100,20 @@ expected-stdout:
i=1; while (( i < 10 )); do echo $i; let ++i; done
); }
function comsub_TWHILE {
x=$(i=1 ; while let " i < 10 " ; do echo $i ; let ++i ; done )
x=$(i=1 ; while let] " i < 10 " ; do echo $i ; let ++i ; done )
}
function reread_TWHILE { x=$((
i=1; while (( i < 10 )); do echo $i; let ++i; done
)|tr u x); }
function reread_TWHILE {
x=$(( i=1 ; while let " i < 10 " ; do echo $i ; let ++i ; done ) | tr u x )
x=$(( i=1 ; while let] " i < 10 " ; do echo $i ; let ++i ; done ) | tr u x )
}
inline_TUNTIL() {
i=10; until (( !--i )) ; do echo $i; done
}
inline_TUNTIL() {
i=10
until let " !--i "
until let] " !--i "
do
echo $i
done
@ -9122,13 +9122,13 @@ expected-stdout:
i=10; until (( !--i )) ; do echo $i; done
); }
function comsub_TUNTIL {
x=$(i=10 ; until let " !--i " ; do echo $i ; done )
x=$(i=10 ; until let] " !--i " ; do echo $i ; done )
}
function reread_TUNTIL { x=$((
i=10; until (( !--i )) ; do echo $i; done
)|tr u x); }
function reread_TUNTIL {
x=$(( i=10 ; until let " !--i " ; do echo $i ; done ) | tr u x )
x=$(( i=10 ; until let] " !--i " ; do echo $i ; done ) | tr u x )
}
inline_TCOPROC() {
cat * |& ls
@ -9742,7 +9742,7 @@ expected-stdout:
}
inline_TWHILE() {
i=1
while let " i < 10 " >&3
while let] " i < 10 " >&3
do
echo $i
let ++i
@ -9752,20 +9752,20 @@ expected-stdout:
i=1; while (( i < 10 )) >&3; do echo $i; let ++i; done >&3
); }
function comsub_TWHILE {
x=$(i=1 ; while let " i < 10 " >&3 ; do echo $i ; let ++i ; done >&3 )
x=$(i=1 ; while let] " i < 10 " >&3 ; do echo $i ; let ++i ; done >&3 )
}
function reread_TWHILE { x=$((
i=1; while (( i < 10 )) >&3; do echo $i; let ++i; done >&3
)|tr u x); }
function reread_TWHILE {
x=$(( i=1 ; while let " i < 10 " >&3 ; do echo $i ; let ++i ; done >&3 ) | tr u x )
x=$(( i=1 ; while let] " i < 10 " >&3 ; do echo $i ; let ++i ; done >&3 ) | tr u x )
}
inline_TUNTIL() {
i=10; until (( !--i )) >&3 ; do echo $i; done >&3
}
inline_TUNTIL() {
i=10
until let " !--i " >&3
until let] " !--i " >&3
do
echo $i
done >&3
@ -9774,13 +9774,13 @@ expected-stdout:
i=10; until (( !--i )) >&3 ; do echo $i; done >&3
); }
function comsub_TUNTIL {
x=$(i=10 ; until let " !--i " >&3 ; do echo $i ; done >&3 )
x=$(i=10 ; until let] " !--i " >&3 ; do echo $i ; done >&3 )
}
function reread_TUNTIL { x=$((
i=10; until (( !--i )) >&3 ; do echo $i; done >&3
)|tr u x); }
function reread_TUNTIL {
x=$(( i=10 ; until let " !--i " >&3 ; do echo $i ; done >&3 ) | tr u x )
x=$(( i=10 ; until let] " !--i " >&3 ; do echo $i ; done >&3 ) | tr u x )
}
inline_TCOPROC() {
cat * >&3 |& >&3 ls

18
exec.c
View File

@ -23,7 +23,7 @@
#include "sh.h"
__RCSID("$MirOS: src/bin/mksh/exec.c,v 1.119 2013/04/26 19:47:07 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/exec.c,v 1.120 2013/04/26 21:22:44 tg Exp $");
#ifndef MKSH_DEFAULT_EXECSHELL
#define MKSH_DEFAULT_EXECSHELL "/bin/sh"
@ -1047,25 +1047,23 @@ const char *
builtin(const char *name, int (*func) (const char **))
{
struct tbl *tp;
uint32_t flag;
uint32_t flag = DEFINED;
/* see if any flags should be set for this builtin */
for (flag = 0; ; name++) {
while (1) {
if (*name == '=')
/* command does variable assignment */
flag |= KEEPASN;
else if (*name == '*')
/* POSIX special builtin */
flag |= SPEC_BI;
else if (*name == '+')
/* POSIX regular builtin */
flag |= REG_BI;
else
break;
name++;
}
tp = ktenter(&builtins, name, hash(name));
tp->flag = DEFINED | flag;
tp->flag = flag;
tp->type = CSHELL;
tp->val.f = func;
@ -1097,7 +1095,7 @@ findcom(const char *name, int flags)
tbi = (flags & FC_BI) ? ktsearch(&builtins, name, h) : NULL;
/*
* POSIX says special builtins first, then functions, then
* POSIX regular builtins, then search path...
* regular builtins, then search path...
*/
if ((flags & FC_SPECBI) && tbi && (tbi->flag & SPEC_BI))
tp = tbi;
@ -1112,9 +1110,7 @@ findcom(const char *name, int flags)
&tp->u2.errnov);
}
}
if (!tp && (flags & FC_REGBI) && tbi && (tbi->flag & REG_BI))
tp = tbi;
if (!tp && (flags & FC_UNREGBI) && tbi)
if (!tp && (flags & FC_NORMBI) && tbi)
tp = tbi;
if (!tp && (flags & FC_PATH) && !(flags & FC_DEFPATH)) {
tp = ktsearch(&taliases, name, h);

79
funcs.c
View File

@ -38,7 +38,7 @@
#endif
#endif
__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.241 2013/04/26 17:39:28 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.242 2013/04/26 21:22:45 tg Exp $");
#if HAVE_KILLPG
/*
@ -84,70 +84,69 @@ c_false(const char **wp MKSH_A_UNUSED)
}
/*
* A leading = means assignments before command are kept;
* a leading * means a POSIX special builtin;
* a leading + means a POSIX regular builtin
* (* and + should not be combined).
* A leading = means assignments before command are kept.
* A leading * means a POSIX special builtin.
*/
const struct builtin mkshbuiltins[] = {
{"*=.", c_dot},
{"*=:", c_true},
{"[", c_test},
/* no =: AT&T manual wrong */
{Talias, c_alias},
{"*=break", c_brkcont},
{Tgbuiltin, c_builtin},
{"cat", c_cat},
{"cd", c_cd},
/* dash compatibility hack */
{"chdir", c_cd},
{"command", c_command},
{"*=continue", c_brkcont},
{"echo", c_print},
{"*=eval", c_eval},
{"*=exec", c_exec},
{"*=exit", c_exitreturn},
{"+false", c_false},
{Tsgexport, c_typeset},
{"false", c_false},
{"fc", c_fc},
{"getopts", c_getopts},
{"=global", c_typeset},
{"jobs", c_jobs},
{"kill", c_kill},
{"let", c_let},
{"let]", c_let},
{"print", c_print},
{"pwd", c_pwd},
{"read", c_read},
{Tsgreadonly, c_typeset},
{"realpath", c_realpath},
{"rename", c_rename},
{"*=return", c_exitreturn},
{Tsgset, c_set},
{"*=shift", c_shift},
{"=times", c_times},
{"*=trap", c_trap},
{"+=wait", c_wait},
{"+read", c_read},
{"test", c_test},
{"+true", c_true},
{"ulimit", c_ulimit},
{"+umask", c_umask},
{Tsgunset, c_unset},
/* no =: AT&T manual wrong */
{Tpalias, c_alias},
{"+cd", c_cd},
/* dash compatibility hack */
{"chdir", c_cd},
{"+command", c_command},
{"echo", c_print},
{Tsgexport, c_typeset},
{"+fc", c_fc},
{"+getopts", c_getopts},
{"=global", c_typeset},
{"+jobs", c_jobs},
{"+kill", c_kill},
{"let", c_let},
{"print", c_print},
#ifdef MKSH_PRINTF_BUILTIN
{"printf", c_printf},
#endif
{"pwd", c_pwd},
{Tsgreadonly, c_typeset},
{"*=times", c_times},
{"*=trap", c_trap},
{"true", c_true},
{T_typeset, c_typeset},
{Tpunalias, c_unalias},
{"ulimit", c_ulimit},
{"umask", c_umask},
{Tunalias, c_unalias},
{Tsgunset, c_unset},
{"=wait", c_wait},
{"whence", c_whence},
#ifndef MKSH_UNEMPLOYED
{"+bg", c_fgbg},
{"+fg", c_fgbg},
{"bg", c_fgbg},
{"fg", c_fgbg},
#endif
#ifndef MKSH_NO_CMDLINE_EDITING
{"bind", c_bind},
#endif
{"cat", c_cat},
#if HAVE_MKNOD
{"mknod", c_mknod},
#endif
{"realpath", c_realpath},
{"rename", c_rename},
#ifdef MKSH_PRINTF_BUILTIN
{"printf", c_printf},
#endif
#if HAVE_SELECT
{"sleep", c_sleep},
#endif

4
main.c
View File

@ -34,7 +34,7 @@
#include <locale.h>
#endif
__RCSID("$MirOS: src/bin/mksh/main.c,v 1.261 2013/03/29 17:33:07 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/main.c,v 1.262 2013/04/26 21:22:46 tg Exp $");
extern char **environ;
@ -238,7 +238,7 @@ main_init(int argc, const char *argv[], Source **sp, struct block **lp)
/* define built-in commands and see if we were called as one */
ktinit(APERM, &builtins,
/* currently up to 50 builtins: 75% of 128 = 2^7 */
/* currently up to 51 builtins: 75% of 128 = 2^7 */
7);
for (i = 0; mkshbuiltins[i].name != NULL; i++)
if (!strcmp(ccp, builtin(mkshbuiltins[i].name,

63
mksh.1
View File

@ -1,4 +1,4 @@
.\" $MirOS: src/bin/mksh/mksh.1,v 1.309 2013/04/14 13:36:53 tg Exp $
.\" $MirOS: src/bin/mksh/mksh.1,v 1.310 2013/04/26 21:22:47 tg Exp $
.\" $OpenBSD: ksh.1,v 1.146 2013/03/18 11:10:52 mpi Exp $
.\"-
.\" Copyright © 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
@ -74,7 +74,7 @@
.\" with -mandoc, it might implement .Mx itself, but we want to
.\" use our own definition. And .Dd must come *first*, always.
.\"
.Dd $Mdocdate: April 14 2013 $
.Dd $Mdocdate: April 26 2013 $
.\"
.\" Check which macro package we use, and do other -mdoc setup.
.\"
@ -2768,8 +2768,7 @@ However, unlike
shell arguments (i.e. positional parameters $1, $2, etc.)\&
are never visible inside them.
When the shell is determining the location of a command, functions
are searched after special built-in commands, before regular and
non-regular built-ins, and before the
are searched after special built-in commands, before builtins and the
.Ev PATH
is searched.
.Pp
@ -2883,8 +2882,8 @@ returns.
.El
.Ss Command execution
After evaluation of command-line arguments, redirections, and parameter
assignments, the type of command is determined: a special built-in, a
function, a regular built-in, or the name of a file to execute found using the
assignments, the type of command is determined: a special built-in command,
a function, a normal builtin, or the name of a file to execute found using the
.Ev PATH
parameter.
The checks are made in the above order.
@ -2900,46 +2899,30 @@ parameter is not used to find them.
The original
.Nm ksh
and POSIX differ somewhat in which commands are considered
special or regular:
special or regular.
.Pp
POSIX special commands
POSIX special built-in utilities:
.Pp
.Ic \&. , \&: , break , continue ,
.Ic eval , exec , exit , export ,
.Ic readonly , return , set , shift ,
.Ic trap , unset , wait
.Ic times , trap , unset
.Pp
Additional
.Nm
special commands
commands keeping assignments:
.Pp
.Ic builtin , global , times , typeset
.Ic builtin , global , typeset , wait
.Pp
Very special commands
.Pq non-POSIX
Builtins that are not special:
.Pp
.Ic alias , readonly , set , typeset
.Pp
POSIX regular commands
.Pp
.Ic alias , bg , cd , command ,
.Ic [ , alias , bg , bind ,
.Ic cat , cd , command , echo ,
.Ic false , fc , fg , getopts ,
.Ic jobs , kill , read , true ,
.Ic umask , unalias
.Pp
Additional
.Nm
regular commands
.Pp
.Ic \&[ , chdir , bind , cat ,
.Ic echo , let , mknod , print ,
.Ic pwd , realpath , rename , sleep ,
.Ic test , ulimit , whence
.Pp
In the future, the additional
.Nm
special and regular commands may be treated
differently from the POSIX special and regular commands.
.Ic jobs , kill , let , mknod ,
.Ic print , pwd , read , realpath ,
.Ic rename , sleep , test , true ,
.Ic ulimit , umask , unalias , whence
.Pp
Once the type of command has been determined, any command-line parameter
assignments are performed and exported for the duration of the command.
@ -2967,6 +2950,10 @@ those of the environment the command is used in.
The null command.
Exit status is set to zero.
.Pp
.It Ic \&[ Ar expression Ic \&]
See
.Ic test .
.Pp
.It Xo Ic alias
.Oo Fl d \*(Ba t Oo Fl r Oc \*(Ba
.Cm +\-x Oc
@ -3521,6 +3508,10 @@ resetting
.Ev OPTIND ,
may lead to unexpected results.
.Pp
.It global Ar ...
See
.Ic typeset .
.Pp
.It Xo
.Ic hash
.Op Fl r
@ -3600,6 +3591,10 @@ Since expressions may need to be quoted,
is syntactic sugar for
.No let \&" Ns Ar expr Ns \&" .
.Pp
.It let]
Internally used alias for
.Ic let .
.Pp
.It Xo
.Ic mknod
.Op Fl m Ar mode

24
sh.h
View File

@ -164,9 +164,9 @@
#endif
#ifdef EXTERN
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.650 2013/04/26 19:40:45 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.651 2013/04/26 21:22:49 tg Exp $");
#endif
#define MKSH_VERSION "R44 2013/04/26"
#define MKSH_VERSION "R45 2013/04/26"
/* arithmetic types: C implementation */
#if !HAVE_CAN_INTTYPES
@ -520,7 +520,7 @@ char *ucstrstr(char *, const char *);
#define mkssert(e) do { } while (/* CONSTCOND */ 0)
#endif
#if (!defined(MKSH_BUILDMAKEFILE4BSD) && !defined(MKSH_BUILDSH)) || (MKSH_BUILD_R != 449)
#if (!defined(MKSH_BUILDMAKEFILE4BSD) && !defined(MKSH_BUILDSH)) || (MKSH_BUILD_R != 451)
#error Must run Build.sh to compile this.
int
im_sorry_dave(void)
@ -797,10 +797,8 @@ EXTERN const char Tr_fc_e_dash[] E_INIT("r=fc -e -");
EXTERN const char Tlocal_typeset[] E_INIT("local=typeset");
#define T_typeset (Tlocal_typeset + 5) /* "=typeset" */
#define Ttypeset (Tlocal_typeset + 6) /* "typeset" */
EXTERN const char Tpalias[] E_INIT("+alias");
#define Talias (Tpalias + 1) /* "alias" */
EXTERN const char Tpunalias[] E_INIT("+unalias");
#define Tunalias (Tpunalias + 1) /* "unalias" */
EXTERN const char Talias[] E_INIT("alias");
EXTERN const char Tunalias[] E_INIT("unalias");
EXTERN const char Tsgset[] E_INIT("*=set");
#define Tset (Tsgset + 2) /* "set" */
EXTERN const char Tsgunset[] E_INIT("*=unset");
@ -1160,7 +1158,6 @@ EXTERN struct tbl vtemp;
#define FDELETE BIT(10) /* function deleted while it was executing */
#define FKSH BIT(11) /* function defined with function x (vs x()) */
#define SPEC_BI BIT(12) /* a POSIX special builtin */
#define REG_BI BIT(13) /* a POSIX regular builtin */
/*
* Attributes that can be set by the user (used to decide if an unset
* param should be repoted by set/typeset). Does not include ARRAY or
@ -1189,12 +1186,11 @@ EXTERN enum {
/* Flags for findcom()/comexec() */
#define FC_SPECBI BIT(0) /* special builtin */
#define FC_FUNC BIT(1) /* function builtin */
#define FC_REGBI BIT(2) /* regular builtin */
#define FC_UNREGBI BIT(3) /* un-regular builtin (!special,!regular) */
#define FC_BI (FC_SPECBI|FC_REGBI|FC_UNREGBI)
#define FC_PATH BIT(4) /* do path search */
#define FC_DEFPATH BIT(5) /* use default path in path search */
#define FC_FUNC BIT(1) /* function */
#define FC_NORMBI BIT(2) /* not special builtin */
#define FC_BI (FC_SPECBI | FC_NORMBI)
#define FC_PATH BIT(3) /* do path search */
#define FC_DEFPATH BIT(4) /* use default path in path search */
#define AF_ARGV_ALLOC 0x1 /* argv[] array allocated */

6
syn.c
View File

@ -2,7 +2,7 @@
/*-
* Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009,
* 2011, 2012
* 2011, 2012, 2013
* 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/syn.c,v 1.89 2013/04/26 18:27:07 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/syn.c,v 1.90 2013/04/26 21:22:50 tg Exp $");
struct nesting_state {
int start_token; /* token than began nesting (eg, FOR) */
@ -243,7 +243,7 @@ nested(int type, int smark, int emark)
}
static const char let_cmd[] = {
CHAR, 'l', CHAR, 'e', CHAR, 't', EOS
CHAR, 'l', CHAR, 'e', CHAR, 't', CHAR, ']', EOS
};
static const char setA_cmd0[] = {
CHAR, 's', CHAR, 'e', CHAR, 't', EOS