make “source” into a built-in command (keepasn, to match ksh93 and “dot”);

remove the “stop” alias and drop old Android and OS/2 hacks and auto-unalias
This commit is contained in:
tg 2015-10-09 21:36:59 +00:00
parent 52b0370973
commit cef386fb60
8 changed files with 34 additions and 218 deletions

151
check.t
View File

@ -1,4 +1,4 @@
# $MirOS: src/bin/mksh/check.t,v 1.709 2015/10/09 17:48:46 tg Exp $
# $MirOS: src/bin/mksh/check.t,v 1.710 2015/10/09 21:36:52 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 R51 2015/10/05
@(#)MIRBSD KSH R51 2015/10/09
description:
Check version of shell.
stdin:
@ -39,7 +39,7 @@ name: KSH_VERSION
category: shell:legacy-no
---
expected-stdout:
@(#)LEGACY KSH R51 2015/10/05
@(#)LEGACY KSH R51 2015/10/09
description:
Check version of legacy shell.
stdin:
@ -7491,7 +7491,6 @@ expected-stdout:
name: aliases-1
description:
Check if built-in shell aliases are okay
category: !android,!arge,!os:os2
stdin:
alias
typeset -f
@ -7506,56 +7505,11 @@ expected-stdout:
nameref='\typeset -n'
nohup='nohup '
r='\builtin fc -e -'
source='PATH=$PATH:. \command .'
stop='\kill -STOP'
type='\builtin whence -v'
---
name: aliases-1-hartz4
description:
Check if built-in shell aliases are okay
category: android,arge
stdin:
alias
typeset -f
expected-stdout:
autoload='\typeset -fu'
functions='\typeset -f'
hash='\builtin alias -t'
history='\builtin fc -l'
integer='\typeset -i'
local='\typeset'
login='\exec login'
nameref='\typeset -n'
nohup='nohup '
r='\builtin fc -e -'
source='PATH=$PATH:. \command .'
type='\builtin whence -v'
---
name: aliases-1-os2
description:
Check if built-in shell aliases are okay
category: os:os2
stdin:
alias
typeset -f
expected-stdout:
autoload='\typeset -fu'
functions='\typeset -f'
hash='\builtin alias -t'
history='\builtin fc -l'
integer='\typeset -i'
local='\typeset'
login='\exec login'
nameref='\typeset -n'
nohup='nohup '
r='\builtin fc -e -'
source='PATH=$PATH\;. \command .'
type='\builtin whence -v'
---
name: aliases-2b
description:
Check if set -o sh does not influence built-in aliases
category: !android,!arge,!os:os2
arguments: !-o!sh!
stdin:
alias
@ -7571,14 +7525,11 @@ expected-stdout:
nameref='\typeset -n'
nohup='nohup '
r='\builtin fc -e -'
source='PATH=$PATH:. \command .'
stop='\kill -STOP'
type='\builtin whence -v'
---
name: aliases-3b
description:
Check if running as sh does not influence built-in aliases
category: !android,!arge,!os:os2
stdin:
cp "$__progname" sh
./sh -c 'alias; typeset -f'
@ -7594,96 +7545,6 @@ expected-stdout:
nameref='\typeset -n'
nohup='nohup '
r='\builtin fc -e -'
source='PATH=$PATH:. \command .'
stop='\kill -STOP'
type='\builtin whence -v'
---
name: aliases-2b-hartz4
description:
Check if set -o sh does not influence built-in aliases
category: android,arge
arguments: !-o!sh!
stdin:
alias
typeset -f
expected-stdout:
autoload='\typeset -fu'
functions='\typeset -f'
hash='\builtin alias -t'
history='\builtin fc -l'
integer='\typeset -i'
local='\typeset'
login='\exec login'
nameref='\typeset -n'
nohup='nohup '
r='\builtin fc -e -'
source='PATH=$PATH:. \command .'
type='\builtin whence -v'
---
name: aliases-3b-hartz4
description:
Check if running as sh does not influence built-in aliases
category: android,arge
stdin:
cp "$__progname" sh
./sh -c 'alias; typeset -f'
rm -f sh
expected-stdout:
autoload='\typeset -fu'
functions='\typeset -f'
hash='\builtin alias -t'
history='\builtin fc -l'
integer='\typeset -i'
local='\typeset'
login='\exec login'
nameref='\typeset -n'
nohup='nohup '
r='\builtin fc -e -'
source='PATH=$PATH:. \command .'
type='\builtin whence -v'
---
name: aliases-2b-os2
description:
Check if set -o sh does not influence built-in aliases
category: os:os2
arguments: !-o!sh!
stdin:
alias
typeset -f
expected-stdout:
autoload='\typeset -fu'
functions='\typeset -f'
hash='\builtin alias -t'
history='\builtin fc -l'
integer='\typeset -i'
local='\typeset'
login='\exec login'
nameref='\typeset -n'
nohup='nohup '
r='\builtin fc -e -'
source='PATH=$PATH\;. \command .'
type='\builtin whence -v'
---
name: aliases-3b-os2
description:
Check if running as sh does not influence built-in aliases
category: os:os2
stdin:
cp "$__progname" sh
./sh -c 'alias; typeset -f'
rm -f sh
expected-stdout:
autoload='\typeset -fu'
functions='\typeset -f'
hash='\builtin alias -t'
history='\builtin fc -l'
integer='\typeset -i'
local='\typeset'
login='\exec login'
nameref='\typeset -n'
nohup='nohup '
r='\builtin fc -e -'
source='PATH=$PATH\;. \command .'
type='\builtin whence -v'
---
name: aliases-cmdline
@ -8955,7 +8816,7 @@ stdin:
"$__progname" -c source
expected-exit: e != 0
expected-stderr-pattern:
/\.: missing argument.*\n.*\.: missing argument/
/\.: missing argument.*\n.*source: missing argument/
---
name: alias-function-no-conflict-legacy
description:
@ -9054,20 +8915,16 @@ stdin:
mk 'function foo' >f-korn
mk 'foo ()' >f-dash
mk 'function foo ()' >f-bash
# lksh can do without the backslash, too (cf. aliases-funcdef-2-legacy)
mk 'function stop ()' '\stop' >f-stop
print '#!'"$__progname"'\nprint -r -- "${0%/f-argh}"' >f-argh
chmod +x f-*
u=$(./f-argh)
x="korn: $(./f-korn)"; echo "${x/@("$u")/.}"
x="dash: $(./f-dash)"; echo "${x/@("$u")/.}"
x="bash: $(./f-bash)"; echo "${x/@("$u")/.}"
x="stop: $(./f-stop)"; echo "${x/@("$u")/.}"
expected-stdout:
korn: bar='foo'
dash: bar='./f-dash'
bash: bar='./f-bash'
stop: bar='./f-stop'
---
name: integer-base-one-1
description:

View File

@ -1,9 +1,9 @@
# $Id$
# $MirOS: src/bin/mksh/dot.mkshrc,v 1.101 2015/07/18 23:03:24 tg Exp $
# $MirOS: src/bin/mksh/dot.mkshrc,v 1.102 2015/10/09 21:36:54 tg Exp $
#-
# Copyright (c) 2002, 2003, 2004, 2006, 2007, 2008, 2009, 2010,
# 2011, 2012, 2013, 2014, 2015
# mirabilos <tg@mirbsd.org>
# mirabilos <m@mirbsd.org>
#
# Provided that these terms and disclaimer and all copyright notices
# are retained or reproduced in an accompanying document, permission
@ -410,9 +410,6 @@ function enable {
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 -'
#XXX OS/2
i_alias[nalias]=source; b_alias[nalias++]='PATH=$PATH:. \command .'
i_alias[nalias]=stop; b_alias[nalias++]='\kill -STOP'
i_alias[nalias]=type; b_alias[nalias++]='\builtin whence -v'
# accumulate mksh built-in utilities, in definition order, even ifndef
@ -449,6 +446,7 @@ function enable {
i_func[nfunc++]=return
i_func[nfunc++]=set
i_func[nfunc++]=shift
i_func[nfunc++]=source
i_func[nfunc++]=suspend
i_func[nfunc++]=test
i_func[nfunc++]=times
@ -468,6 +466,7 @@ function enable {
i_func[nfunc++]=printf
i_func[nfunc++]=sleep
i_func[nfunc++]=domainname
i_func[nfunc++]=extproc
# accumulate aliases from dot.mkshrc, in definition order
i_alias[nalias]=l; b_alias[nalias++]='ls -F'

13
exec.c
View File

@ -23,7 +23,7 @@
#include "sh.h"
__RCSID("$MirOS: src/bin/mksh/exec.c,v 1.167 2015/10/09 19:29:48 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/exec.c,v 1.168 2015/10/09 21:36:55 tg Exp $");
#ifndef MKSH_DEFAULT_EXECSHELL
#define MKSH_DEFAULT_EXECSHELL MKSH_UNIXROOT "/bin/sh"
@ -39,7 +39,6 @@ static const char *do_selectargs(const char **, bool);
static Test_op dbteste_isa(Test_env *, Test_meta);
static const char *dbteste_getopnd(Test_env *, Test_op, bool);
static void dbteste_error(Test_env *, int, const char *);
static int search_access(const char *, int);
/* XXX: horrible kludge to fit within the framework */
static void plain_fmt_entry(char *, size_t, unsigned int, const void *);
static void select_fmt_entry(char *, size_t, unsigned int, const void *);
@ -1065,14 +1064,6 @@ define(const char *name, struct op *t)
nhash = hash(name);
#ifdef MKSH_LEGACY_MODE
if (t != NULL && !tobool(t->u.ksh_func)) {
/* drop same-name aliases for POSIX functions */
if ((tp = ktsearch(&aliases, name, nhash)))
ktdelete(tp);
}
#endif
while (/* CONSTCOND */ 1) {
tp = findfunc(name, nhash, true);
@ -1257,7 +1248,7 @@ flushcom(bool all)
}
/* check if path is something we want to find */
static int
int
search_access(const char *fn, int mode)
{
struct stat sb;

View File

@ -38,7 +38,7 @@
#endif
#endif
__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.285 2015/10/09 17:48:50 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.286 2015/10/09 21:36:55 tg Exp $");
#if HAVE_KILLPG
/*
@ -127,6 +127,7 @@ const struct builtin mkshbuiltins[] = {
{"*=return", c_exitreturn},
{Tsgset, c_set},
{"*=shift", c_shift},
{"=source", c_dot},
#if !defined(MKSH_UNEMPLOYED) && HAVE_GETSID
{"suspend", c_suspend},
#endif
@ -1786,7 +1787,11 @@ c_dot(const char **wp)
bi_errorf("missing argument");
return (1);
}
if ((file = search_path(cp, path, R_OK, &errcode)) == NULL) {
file = search_path(cp, path, R_OK, &errcode);
if (!file && errcode == ENOENT && wp[0][0] == 's' &&
search_access(cp, R_OK) == 0)
file = cp;
if (!file) {
bi_errorf("%s: %s", cp, cstrerror(errcode));
return (1);
}

14
lksh.1
View File

@ -1,4 +1,4 @@
.\" $MirOS: src/bin/mksh/lksh.1,v 1.14 2015/10/09 20:33:49 tg Exp $
.\" $MirOS: src/bin/mksh/lksh.1,v 1.15 2015/10/09 21:36:56 tg Exp $
.\"-
.\" Copyright (c) 2008, 2009, 2010, 2012, 2013, 2015
.\" mirabilos <m@mirbsd.org>
@ -289,18 +289,6 @@ mode and
.Nm lksh
do not keep file descriptors \*(Gt 2 private from sub-processes.
.It
.\"XXX TODO: move to FSH? fix upstreams? both ugh.
.Nm lksh
undefines an alias when a
.Tn POSIX
function with the same name is defined,
to make that function immediately callable.
In
.Nm mksh ,
aliases have precedence; the name must be quoted or
.Ic unalias Ns ed
to access it.
.It
Functions defined with the
.Ic function
reserved word share the shell options

10
main.c
View File

@ -34,7 +34,7 @@
#include <locale.h>
#endif
__RCSID("$MirOS: src/bin/mksh/main.c,v 1.305 2015/10/09 17:48:51 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/main.c,v 1.306 2015/10/09 21:36:57 tg Exp $");
extern char **environ;
@ -71,18 +71,12 @@ static const char *initcoms[] = {
/* not "alias -t --": hash -r needs to work */
"hash=\\builtin alias -t",
"type=\\builtin whence -v",
#if !defined(ANDROID) && !defined(MKSH_UNEMPLOYED)
/* not in Android for political reasons */
/* not in ARGE mksh due to no job control */
"stop=\\kill -STOP",
#endif
"autoload=\\typeset -fu",
"functions=\\typeset -f",
"history=\\builtin fc -l",
"nameref=\\typeset -n",
"nohup=nohup ",
"r=\\builtin fc -e -",
"source=PATH=$PATH" MKSH_PATHSEPE ". \\command .",
"login=\\exec login",
NULL,
/* this is what AT&T ksh seems to track, with the addition of emacs */
@ -255,7 +249,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 51 builtins: 75% of 128 = 2^7 */
/* currently up to 54 builtins: 75% of 128 = 2^7 */
7);
for (i = 0; mkshbuiltins[i].name != NULL; i++)
if (!strcmp(ccp, builtin(mkshbuiltins[i].name,

33
mksh.1
View File

@ -1,4 +1,4 @@
.\" $MirOS: src/bin/mksh/mksh.1,v 1.381 2015/10/09 20:43:11 tg Exp $
.\" $MirOS: src/bin/mksh/mksh.1,v 1.382 2015/10/09 21:36:57 tg Exp $
.\" $OpenBSD: ksh.1,v 1.160 2015/07/04 13:27:04 feinerer Exp $
.\"-
.\" Copyright © 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
@ -1130,8 +1130,6 @@ login=\*(aq\eexec login\*(aq
nameref=\*(aq\etypeset \-n\*(aq
nohup=\*(aqnohup \*(aq
r=\*(aq\ebuiltin fc \-e \-\*(aq
source=\*(aqPATH=$PATH:. \ecommand .\*(aq
stop=\*(aq\ekill \-STOP\*(aq
type=\*(aq\ebuiltin whence \-v\*(aq
.Ed
.Pp
@ -2942,18 +2940,18 @@ Additional
.Nm
commands keeping assignments:
.Pp
.Ic builtin , global , typeset , wait
.Ic builtin , global , source , typeset ,
.Ic wait
.Pp
Builtins that are not special:
.Pp
.Ic [ , alias , bg , bind ,
.Ic cat , cd , command , echo ,
.Ic false , fc , fg , getopts ,
.Ic jobs , kill , let , mknod ,
.Ic print , pwd , read , realpath ,
.Ic rename , sleep , suspend , test ,
.Ic true , ulimit , umask , unalias ,
.Ic whence
.Ic jobs , kill , let , print ,
.Ic pwd , read , realpath , rename ,
.Ic sleep , suspend , 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.
@ -3673,10 +3671,6 @@ option),
and
.Ar minor
(minor device number).
.Pp
See
.Xr mknod 8
for further information.
This is not normally part of
.Nm mksh ;
however, distributors may have added this as builtin as a speed hack.
@ -4324,16 +4318,9 @@ Signal delivery may continue execution earlier.
Like
.Ic \&. Po Do dot Dc Pc ,
except that the current working directory is appended to the
.Ev PATH
in GNU
search path (GNU
.Nm bash
and
.Nm mksh .
In
.Nm ksh93
and
.Nm mksh ,
this is implemented as a shell alias instead of a builtin.
extension).
.Pp
.It Ic suspend
Stops the shell as if it had received the suspend character from
@ -6578,7 +6565,7 @@ for the in-memory portion of the history is slow, should use
.Xr memmove 3 .
.Pp
This document attempts to describe
.Nm mksh\ R51
.Nm mksh\ R51 Ns -CVS
and up,
.\" with vendor patches from insert-your-name-here,
compiled without any options impacting functionality, such as

13
sh.h
View File

@ -172,9 +172,9 @@
#endif
#ifdef EXTERN
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.748 2015/10/09 19:29:49 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.749 2015/10/09 21:36:59 tg Exp $");
#endif
#define MKSH_VERSION "R51 2015/10/05"
#define MKSH_VERSION "R51 2015/10/09"
/* arithmetic types: C implementation */
#if !HAVE_CAN_INTTYPES
@ -387,12 +387,10 @@ struct rusage {
#endif
#ifdef __OS2__
#define MKSH_PATHSEPE "\\;"
#define MKSH_PATHSEPS ";"
#define MKSH_PATHSEPC ';'
#define MKSH_UNIXROOT "/@unixroot"
#else
#define MKSH_PATHSEPE ":"
#define MKSH_PATHSEPS ":"
#define MKSH_PATHSEPC ':'
#define MKSH_UNIXROOT ""
@ -1047,7 +1045,7 @@ EXTERN sigset_t sm_default, sm_sigchld;
/* name of called builtin function (used by error functions) */
EXTERN const char *builtin_argv0;
/* is called builtin SPEC_BI? */
/* is called builtin SPEC_BI? (also KEEPASN, odd use though) */
EXTERN bool builtin_spec;
/* current working directory */
@ -1072,12 +1070,8 @@ EXTERN mksh_ari_t x_lins E_INIT(24); /* tty lines */
/* Determine the location of the system (common) profile */
#ifndef MKSH_DEFAULT_PROFILEDIR
#if defined(ANDROID)
#define MKSH_DEFAULT_PROFILEDIR "/system/etc"
#else
#define MKSH_DEFAULT_PROFILEDIR "/etc"
#endif
#endif
#define MKSH_SYSTEM_PROFILE MKSH_DEFAULT_PROFILEDIR "/profile"
#define MKSH_SUID_PROFILE MKSH_DEFAULT_PROFILEDIR "/suid_profile"
@ -1719,6 +1713,7 @@ int define(const char *, struct op *);
const char *builtin(const char *, int (*)(const char **));
struct tbl *findcom(const char *, int);
void flushcom(bool);
int search_access(const char *, int);
const char *search_path(const char *, const char *, int, int *);
void pr_menu(const char * const *);
void pr_list(char * const *);