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

Make the 'history' and 'r' commands builtins (#76)

With this change no more preset aliases exist, so the preset alias
tables can be safely removed. All ksh commands can now be used
without 'unalias -a' removing them, even in interactive shells.
Additionally, the history and r commands are no longer limited to
being used in interactive shells.

src/cmd/ksh93/bltins/hist.c:
- Implement the history and r commands as builtins. Also guarantee
  lflag is set to one by avoiding 'lflag++'.

src/cmd/ksh93/Makefile,
src/cmd/ksh93/Mamfile,
src/cmd/ksh93/sh/main.c,
src/cmd/ksh93/sh/init.c,
src/cmd/ksh93/data/aliases.c:
- Remove the table of predefined aliases because the last few have
  been removed. During init the alias tree is now initialized the
  same way as the function tree.

src/cmd/ksh93/bltins/typeset.c:
- Remove the bugfix for unsetting predefined aliases because it is
  now a no-op. Aliases are no longer able to have the NV_NOFREE
  attribute.

src/cmd/ksh93/tests/alias.sh:
- Remove the regression test for unsetting predefined aliases since
  those no longer exist.

src/cmd/ksh93/data/builtins.c:
- Update sh_opthist[] for 'hist --man', etc.

src/cmd/ksh93/sh.1:
- Remove the list of preset aliases since those no longer exist.
- Document history and r as builtins instead of preset aliases.

Co-authored-by: Martijn Dekker <martijn@inlv.org>
This commit is contained in:
Johnothan King 2020-07-16 10:56:49 -07:00 committed by GitHub
parent 17f81ebedb
commit 03224ae3af
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 47 additions and 100 deletions

View file

@ -217,6 +217,7 @@ static int lctype;
static int nbltins;
static void env_init(Shell_t*);
static Init_t *nv_init(Shell_t*);
static Dt_t *inittree(Shell_t*,const struct shtable2*);
static int shlvl;
#ifdef _WINIX
@ -1560,7 +1561,7 @@ int sh_reinit(char *argv[])
nv_delete(np,dp,NV_NOFREE);
}
dtclose(shp->alias_tree);
shp->alias_tree = sh_inittree(shp,shtab_noaliases);
shp->alias_tree = dtopen(&_Nvdisc,Dtoset);
shp->last_root = shp->var_tree;
shp->inuse_bits = 0;
if(shp->userinit)
@ -1759,7 +1760,7 @@ static Init_t *nv_init(Shell_t *shp)
shp->nvfun.last = (char*)shp;
shp->nvfun.nofree = 1;
ip->sh = shp;
shp->var_base = shp->var_tree = sh_inittree(shp,shtab_variables);
shp->var_base = shp->var_tree = inittree(shp,shtab_variables);
SHLVL->nvalue.ip = &shlvl;
ip->IFS_init.hdr.disc = &IFS_disc;
ip->PATH_init.disc = &RESTRICTED_disc;
@ -1852,9 +1853,9 @@ static Init_t *nv_init(Shell_t *shp)
(MCHKNOD)->nvalue.lp = (&sh_mailchk);
(OPTINDNOD)->nvalue.lp = (&shp->st.optindex);
/* set up the seconds clock */
shp->alias_tree = sh_inittree(shp,shtab_noaliases);
shp->alias_tree = dtopen(&_Nvdisc,Dtoset);
shp->track_tree = dtopen(&_Nvdisc,Dtset);
shp->bltin_tree = sh_inittree(shp,(const struct shtable2*)shtab_builtins);
shp->bltin_tree = inittree(shp,(const struct shtable2*)shtab_builtins);
shp->fun_tree = dtopen(&_Nvdisc,Dtoset);
dtview(shp->fun_tree,shp->bltin_tree);
nv_mount(DOTSHNOD, "type", shp->typedict=dtopen(&_Nvdisc,Dtoset));
@ -1877,7 +1878,7 @@ static Init_t *nv_init(Shell_t *shp)
* initialize name-value pairs
*/
Dt_t *sh_inittree(Shell_t *shp,const struct shtable2 *name_vals)
static Dt_t *inittree(Shell_t *shp,const struct shtable2 *name_vals)
{
register Namval_t *np;
register const struct shtable2 *tp;

View file

@ -176,8 +176,6 @@ int sh_main(int ac, char *av[], Shinit_f userinit)
{
sh_onoption(SH_BGNICE);
sh_onoption(SH_RC);
free(shp->alias_tree);
shp->alias_tree = sh_inittree(shp,shtab_aliases);
}
if(!sh_isoption(SH_RC) && (sh_isoption(SH_BASH) && !sh_isoption(SH_POSIX)
#if SHOPT_REMOTE