1
0
Fork 0
mirror of git://git.code.sf.net/p/cdesktopenv/code synced 2025-03-09 15:50:02 +00:00

Make 'source' a regular built-in

The 'source' alias is now converted into a regular built-in command
so that 'unalias -a' does not remove it, and something like
	cmd=source; $cmd name args
will now work.

This is part of the project to replace default aliases that define
essential commands by proper builtins that act identically (except
you now get the actual command's name in any error/usage messages).

src/cmd/ksh93/data/aliases.c:
- Remove 'source' default alias.

src/cmd/ksh93/data/builtins.c,
src/cmd/ksh93/include/builtins.h:
- Define 'source' regular builtin with extra parser ID "SYSSOURCE".
  Same definition as '.', minus the BLT_SPC flag indicating a
  special builtin. This preserves the behaviour of 'command .'.
- Update sh_optdot[] to include info for 'source --man'.
  (Note that \f?\f expands to the current command name.
  This allows several commands to share a single --man page.)

src/cmd/ksh93/sh/parse.c:
- In the two places that SYSDOT is checked for, also check for
  SYSSOURCE, making sure the two commands are parsed identically.

src/cmd/ksh93/sh.1:
- Remove 'source' default alias.
- Document 'source' regular builtin.
This commit is contained in:
Martijn Dekker 2020-06-15 09:03:44 +02:00
parent b7f48e8a10
commit ef1621c18f
8 changed files with 38 additions and 21 deletions

View file

@ -73,6 +73,7 @@ const struct shtable3 shtab_builtins[] =
"let", NV_BLTIN|BLT_ENV, bltin(let),
"export", NV_BLTIN|BLT_ENV|BLT_SPC|BLT_DCL,bltin(readonly),
".", NV_BLTIN|BLT_ENV|BLT_SPC, bltin(dot_cmd),
"source", NV_BLTIN|BLT_ENV, bltin(dot_cmd),
"return", NV_BLTIN|BLT_ENV|BLT_SPC, bltin(return),
#if SHOPT_BASH
"local", NV_BLTIN|BLT_ENV|BLT_SPC|BLT_DCL,bltin(typeset),
@ -526,11 +527,12 @@ USAGE_LICENSE
;
const char sh_optdot[] =
"[-1c?@(#)$Id: \b.\b (AT&T Research) 2000-04-02 $\n]"
"[-1c?@(#)$Id: \b.\b (AT&T Research/ksh93) 2020-06-15 $\n]"
USAGE_LICENSE
"[+NAME?\b.\b - execute commands in the current environment]"
"[+DESCRIPTION?\b.\b is a special built-in command that executes commands "
"from a function or a file in the current environment.]"
"[+NAME?\f?\f - execute commands in the current environment]"
"[+DESCRIPTION?\b.\b and \bsource\b are built-in commands that execute "
"commands from a function or a file in the current environment. \b.\b "
"is a special built-in, whereas \bsource\b is a regular built-in.]"
"[+?If \aname\a refers to a function defined with the \bfunction\b \aname\a "
"syntax, the function executes in the current environment as "
"if it had been defined with the \aname\a\b()\b syntax so that "
@ -548,12 +550,11 @@ USAGE_LICENSE
"\n"
"\n name [arg ...]\n"
"\n"
"[+EXIT STATUS?If \aname\a is found, then the exit status is that "
"of the last command executed. Otherwise, since this is a special "
"built-in, an error will cause a non-interactive shell to exit with "
"a non-zero exit status. An interactive shell returns a non-zero exit "
"status to indicate an error.]"
"[+EXIT STATUS?If \aname\a is found, then the exit status is that of the last "
"command executed. Otherwise, it is non-zero. \b.\b, being a special "
"built-in, will exit the current shell environment or abort execution "
"of the interactive command line upon error, whereas \bsource\b will "
"allow execution to continue.]"
"[+SEE ALSO?\bcommand\b(1), \bksh\b(1)]"
;