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

-o posix: inverse-sync braceexpand; properly sync letoctal

{Brace,expansion} is potentially incompatible with POSIX scripts,
because in POSIX those are simple literal strings with no special
meaning. So the POSIX option should really turn that off.

As of b301d417, the 'posix' option was also forcing 'letoctal'
behaviour on, without actually setting that option. I've since
found that to be a botch; 'let' may recognise octals without that
option being set, and that looks like a bug.

So as of this commit, the '-o posix' option actually toggles both
of these options off/on and on/of, respectively. 'set +o posix'
toggles them inversely. However, it is now possible to control both
options (and their associated behaviour) independently in between
'set -o posix' and 'set +o posix'. Much better.

src/cmd/ksh93/sh/main.c: sh_main():
- If SH_POSIX was set on init, turn on SH_LETOCTAL by default
  instead of SH_BRACEEXPAND.

src/cmd/ksh93/sh/args.c: sh_applyopts():
- Turn off SH_BRACEEXPAND and turn on SH_LETOCTAL when SH_POSIX is
  turned on (but not if it was already on).
- Turn on SH_BRACEEXPAND and turn off SH_LETOCTAL when SH_POSIX is
  turned off (but not if it was already off).

src/cmd/ksh93/sh/arith.c: arith():
- Revert to pre-b301d417 and only check SH_LETOCTAL option when
  deciding whether 'let' should skip initial zeros.

src/cmd/ksh93/tests/options.sh:
- Update $- test to allow '-o posix' to switch B = braceexpand.

src/cmd/ksh93/sh.1:
- Update.
- Edit for clarity.
This commit is contained in:
Martijn Dekker 2020-09-18 20:32:34 +02:00
parent dc80f40d40
commit f45a0f1650
7 changed files with 69 additions and 25 deletions

View file

@ -289,9 +289,7 @@ int sh_argopts(int argc,register char *argv[], void *context)
}
argc--;
}
/* handling SH_INTERACTIVE and SH_PRIVILEGED has been moved to
* sh_applyopts(), so that the code can be reused from b_shopt(), too
*/
/* SH_INTERACTIVE and SH_PRIVILEGED are handled in sh_applyopts() */
sh_applyopts(ap->sh,newflags);
#if SHOPT_KIA
if(ap->kiafile)
@ -343,6 +341,21 @@ void sh_applyopts(Shell_t* shp,Shopt_t newflags)
(shp->gd->userid==shp->gd->euserid && shp->gd->groupid==shp->gd->egroupid))
off_option(&newflags,SH_PRIVILEGED);
}
/* -o posix also switches -o braceexpand and -o letoctal */
if(!sh_isoption(SH_POSIX) && is_option(&newflags,SH_POSIX))
{
#if SHOPT_BRACEPAT
off_option(&newflags,SH_BRACEEXPAND);
#endif
on_option(&newflags,SH_LETOCTAL);
}
else if(sh_isoption(SH_POSIX) && !is_option(&newflags,SH_POSIX))
{
#if SHOPT_BRACEPAT
on_option(&newflags,SH_BRACEEXPAND);
#endif
off_option(&newflags,SH_LETOCTAL);
}
shp->options = newflags;
}

View file

@ -390,10 +390,10 @@ static Sfdouble_t arith(const char **ptr, struct lval *lvalue, int type, Sfdoubl
char lastbase=0, *val = xp, oerrno = errno;
lvalue->eflag = 0;
errno = 0;
if(shp->bltindata.bnode==SYSLET && !sh_isoption(SH_LETOCTAL) && !sh_isoption(SH_POSIX))
if(shp->bltindata.bnode==SYSLET && !sh_isoption(SH_LETOCTAL))
{ /*
* Since we're running the "let" builtin, disable octal number processing by
* skipping all initial zeros, unless the 'letoctal' or 'posix' option is on.
* skipping all initial zeros, unless the 'letoctal' option is on.
*/
while(*val=='0' && isdigit(val[1]))
val++;

View file

@ -157,8 +157,11 @@ int sh_main(int ac, char *av[], Shinit_f userinit)
nv_putval(PS4NOD,e_traceprompt,NV_RDONLY);
path_pwd(shp,1);
iop = (Sfio_t*)0;
if(sh_isoption(SH_POSIX))
sh_onoption(SH_LETOCTAL);
#if SHOPT_BRACEPAT
sh_onoption(SH_BRACEEXPAND);
else
sh_onoption(SH_BRACEEXPAND);
#endif
if((beenhere++)==0)
{