Skip to content

Commit

Permalink
Make 'source' a regular built-in
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
McDutchie committed Jun 15, 2020
1 parent b7f48e8 commit ef1621c
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 21 deletions.
5 changes: 5 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@ For full details, see the git log at: https://github.com/ksh93/ksh

Any uppercase BUG_* names are modernish shell bug IDs.

2020-06-15:

- The 'source' alias has been converted into a regular built-in command.

2020-06-14:

- 'read -S' is now able to correctly handle strings with double quotes
nested inside of double quotes.

Expand Down
7 changes: 4 additions & 3 deletions TODO
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,13 @@ Fix or remove broken or misguided default aliases:
- functions='typeset -f'
- integer='typeset -li'
- nameref='typeset -n'
- source='command .'
- stop='kill -s STOP'
- suspend='kill -s STOP $$'
Keep these default aliases for the benefit of interactive shells:
+ history='hist -l'
+ r='hist -s'
+ stop='kill -s STOP'
+ suspend='kill -s STOP $$'
To avoid interfering with shell functions by those names that POSIX
scripts may set, those should only intialise on interactive shells.

______
Fix currently known bugs affecting shell scripting. These are identified by
Expand Down
1 change: 0 additions & 1 deletion src/cmd/ksh93/data/aliases.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ const struct shtable2 shtab_aliases[] =
"integer", NV_NOFREE|BLT_DCL, "typeset -li",
"nameref", NV_NOFREE|BLT_DCL, "typeset -n",
"r", NV_NOFREE, "hist -s",
"source", NV_NOFREE, "command .",
#ifdef SIGTSTP
"stop", NV_NOFREE, "kill -s STOP",
"suspend", NV_NOFREE, "kill -s STOP $$",
Expand Down
21 changes: 11 additions & 10 deletions src/cmd/ksh93/data/builtins.c
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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 "
Expand All @@ -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)]"
;

Expand Down
5 changes: 3 additions & 2 deletions src/cmd/ksh93/include/builtins.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,10 @@
#define SYSLET (shgd->bltin_cmds+12) /* let */
#define SYSEXPORT (shgd->bltin_cmds+13) /* export */
#define SYSDOT (shgd->bltin_cmds+14) /* . */
#define SYSRETURN (shgd->bltin_cmds+15) /* return */
#define SYSSOURCE (shgd->bltin_cmds+15) /* source */
#define SYSRETURN (shgd->bltin_cmds+16) /* return */
#if SHOPT_BASH
# define SYSLOCAL (shgd->bltin_cmds+16) /* local */
# define SYSLOCAL (shgd->bltin_cmds+17) /* local */
#else
# define SYSLOCAL 0
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/ksh93/include/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@
* David Korn <[email protected]> *
* *
***********************************************************************/
#define SH_RELEASE "93u+m 2020-06-14"
#define SH_RELEASE "93u+m 2020-06-15"
7 changes: 5 additions & 2 deletions src/cmd/ksh93/sh.1
Original file line number Diff line number Diff line change
Expand Up @@ -804,8 +804,6 @@ but can be unset or redefined:
.TP
.B "r=\(fmhist \-s\(fm"
.TP
.B "source=\(fmcommand \s+2.\s-2\(fm"
.TP
.B "stop=\(fmkill \-s \s-1STOP\s+1\(fm"
.TP
.B "suspend=\(fmkill \-s \s-1STOP\s+1 $$\(fm"
Expand Down Expand Up @@ -7125,6 +7123,11 @@ Suspends execution for the number of decimal seconds or fractions of a
second given by
.IR seconds .
.TP
\f3source\fP \f2name\^\fP \*(OK \f2arg\^\fP .\|.\|. \*(CK
Same as
.BR \|.\^ ,
except it is not treated as a special built-in command.
.TP
\f3times\fP
Displays the accumulated user and system CPU times, one line with the times
used by the shell and another with those used by all of the shell's child
Expand Down
11 changes: 9 additions & 2 deletions src/cmd/ksh93/sh/parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -1023,7 +1023,11 @@ static struct argnod *assign(Lex_t *lexp, register struct argnod *ap, int type)
}
else if(n && n!=FUNCTSYM)
sh_syntax(lexp);
else if(type!=NV_ARRAY && n!=FUNCTSYM && !(lexp->arg->argflag&ARG_ASSIGN) && !((np=nv_search(lexp->arg->argval,lexp->sh->fun_tree,0)) && (nv_isattr(np,BLT_DCL)|| np==SYSDOT)))
else if(type!=NV_ARRAY &&
n!=FUNCTSYM &&
!(lexp->arg->argflag&ARG_ASSIGN) &&
!((np=nv_search(lexp->arg->argval,lexp->sh->fun_tree,0)) &&
(nv_isattr(np,BLT_DCL) || np==SYSDOT || np==SYSSOURCE)))
{
array=SH_ARRAY;
if(fcgetc(n)==LPAREN)
Expand Down Expand Up @@ -1078,7 +1082,10 @@ static struct argnod *assign(Lex_t *lexp, register struct argnod *ap, int type)
if(array || n!=FUNCTSYM)
sh_syntax(lexp);
}
if((n!=FUNCTSYM) && !(lexp->arg->argflag&ARG_ASSIGN) && !((np=nv_search(lexp->arg->argval,lexp->sh->fun_tree,0)) && (nv_isattr(np,BLT_DCL)||np==SYSDOT)))
if((n!=FUNCTSYM) &&
!(lexp->arg->argflag&ARG_ASSIGN) &&
!((np=nv_search(lexp->arg->argval,lexp->sh->fun_tree,0)) &&
(nv_isattr(np,BLT_DCL) || np==SYSDOT || np==SYSSOURCE)))
{
struct argnod *arg = lexp->arg;
if(n!=0)
Expand Down

0 comments on commit ef1621c

Please sign in to comment.