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

Remove SHOPT_BASH; keep &> redir operator, '-o posix' option

On 16 June there was a call for volunteers to fix the bash
compatibility mode; it has never successfully compiled in 93u+.
Since no one showed up, it is now removed due to lack of interest.

A couple of things are kept, which are now globally enabled:

1. The &>file redirection shorthand (for >file 2>&1). As a matter
   of fact, ksh93 already supported this natively, but only while
   running rc/profile/login scripts, and it issued a warning. This
   makse it globally available and removes the warning, bringing
   ksh93 in line with mksh, bash and zsh.

2. The '-o posix' standard compliance option. It is now enabled on
   startup if ksh is invoked as 'sh' or if the POSIXLY_CORRECT
   variable exists in the environment. To begin with, it disables
   the aforementioned &> redirection shorthand. Further compliance
   tweaks will be added in subsequent commits. The differences will
   be fairly minimal as ksh93 is mostly compliant already.

In all changed files, code was removed that was compiled (more
precisely, failed to compile/link) if the SHOPT_BASH preprocessor
identifier was defined. Below are other changes worth mentioning:

src/cmd/ksh93/sh/bash.c,
src/cmd/ksh93/data/bash_pre_rc.sh:
- Removed.

src/cmd/ksh93/data/lexstates.c,
src/cmd/ksh93/include/shlex.h,
src/cmd/ksh93/sh/lex.c:
- Globally enable &> redirection operator if SH_POSIX not active.
- Remove warning that was issued when &> was used in rc scripts.

src/cmd/ksh93/data/options.c,
src/cmd/ksh93/include/defs.h,
src/cmd/ksh93/sh/args.c:
- Keep SH_POSIX option (-o posix).
- Replace SH_TYPE_BASH shell type by SH_TYPE_POSIX.

src/cmd/ksh93/sh/init.c:
- sh_type(): Return SH_TYPE_POSIX shell type if ksh was invoked
  as sh (or rsh, restricted sh).
- sh_init(): Enable posix option if the SH_TYPE_POSIX shell type
  was detected, or if the CONFORMANCE ast config variable was set
  to "standard" (which libast sets on init if POSIXLY_CORRECT
  exists in the environment).

src/cmd/ksh93/tests/options.sh,
src/cmd/ksh93/tests/io.sh:
- Replace regression tests for &> and move to io.sh. Since &> is
  now for general use, no longer test in an rc script, and don't
  check that a warning is issued.

Closes: #9
Progresses: #20
This commit is contained in:
Martijn Dekker 2020-09-01 06:19:19 +01:00
parent 84331a96fc
commit 921bbcaeb7
25 changed files with 95 additions and 1148 deletions

View file

@ -96,10 +96,6 @@ int path_expand(Shell_t *shp,const char *pattern, struct argnod **arghead)
register struct argnod *ap;
register glob_t *gp= &gdata;
register int flags,extra=0;
#if SHOPT_BASH
register int off;
register char *sp, *cp, *cp2;
#endif
sh_stats(STAT_GLOBS);
memset(gp,0,sizeof(gdata));
flags = GLOB_GROUP|GLOB_AUGMENTED|GLOB_NOCHECK|GLOB_NOSORT|GLOB_STACK|GLOB_LIST|GLOB_DISC;
@ -107,16 +103,6 @@ int path_expand(Shell_t *shp,const char *pattern, struct argnod **arghead)
flags |= GLOB_MARK;
if(sh_isoption(SH_GLOBSTARS))
flags |= GLOB_STARSTAR;
#if SHOPT_BASH
#if 0
if(sh_isoption(SH_BASH) && !sh_isoption(SH_EXTGLOB))
flags &= ~GLOB_AUGMENTED;
#endif
if(sh_isoption(SH_NULLGLOB))
flags &= ~GLOB_NOCHECK;
if(sh_isoption(SH_NOCASEGLOB))
flags |= GLOB_ICASE;
#endif
if(sh_isstate(SH_COMPLETE))
{
#if KSHELL
@ -129,62 +115,6 @@ int path_expand(Shell_t *shp,const char *pattern, struct argnod **arghead)
flags |= GLOB_COMPLETE;
flags &= ~GLOB_NOCHECK;
}
#if SHOPT_BASH
if(off = staktell())
sp = stakfreeze(0);
if(sh_isoption(SH_BASH))
{
/*
* For bash, FIGNORE is a colon separated list of suffixes to
* ignore when doing filename/command completion.
* GLOBIGNORE is similar to ksh FIGNORE, but colon separated
* instead of being an augmented shell pattern.
* Generate shell patterns out of those here.
*/
if(sh_isstate(SH_FCOMPLETE))
cp=nv_getval(sh_scoped(shp,FIGNORENOD));
else
{
static Namval_t *GLOBIGNORENOD;
if(!GLOBIGNORENOD)
GLOBIGNORENOD = nv_open("GLOBIGNORE",shp->var_tree,0);
cp=nv_getval(sh_scoped(shp,GLOBIGNORENOD));
}
if(cp)
{
flags |= GLOB_AUGMENTED;
stakputs("@(");
if(!sh_isstate(SH_FCOMPLETE))
{
stakputs(cp);
for(cp=stakptr(off); *cp; cp++)
if(*cp == ':')
*cp='|';
}
else
{
cp2 = strtok(cp, ":");
if(!cp2)
cp2=cp;
do
{
stakputc('*');
stakputs(cp2);
if(cp2 = strtok(NULL, ":"))
{
*(cp2-1)=':';
stakputc('|');
}
} while(cp2);
}
stakputc(')');
gp->gl_fignore = stakfreeze(1);
}
else if(!sh_isstate(SH_FCOMPLETE) && sh_isoption(SH_DOTGLOB))
gp->gl_fignore = "";
}
else
#endif
gp->gl_fignore = nv_getval(sh_scoped(shp,FIGNORENOD));
if(suflen)
gp->gl_suffix = sufstr;
@ -193,12 +123,6 @@ int path_expand(Shell_t *shp,const char *pattern, struct argnod **arghead)
if(memcmp(pattern,"~(N",3)==0)
flags &= ~GLOB_NOCHECK;
glob(pattern, flags, 0, gp);
#if SHOPT_BASH
if(off)
stakset(sp,off);
else
stakseek(0);
#endif
sh_sigcheck(shp);
for(ap= (struct argnod*)gp->gl_list; ap; ap = ap->argnxt.ap)
{