mirror of
git://git.code.sf.net/p/cdesktopenv/code
synced 2025-03-09 15:50:02 +00:00
This fixes the following:
1. 'set --posix' now works as an equivalent of 'set -o posix'.
2. The posix option turns off braceexpand and turns on letoctal.
Any attempt to override that in a single command such as 'set -o
posix +o letoctal' was quietly ignored. This now works as long
as the overriding option follows the posix option in the command.
3. The --default option to 'set' now stops the 'posix' option, if
set or unset in the same 'set' command, from changing other
options. This allows the command output by 'set +o' to correctly
restore the current options.
src/cmd/ksh93/data/builtins.c:
- To make 'set --posix' work, we must explicitly list it in
sh_set[] as a supported option so that AST optget(3) recognises
it and won't override it with its own default --posix option,
which converts the optget(3) string to at POSIX getopt(3) string.
This means it will appear as a separate entry in --man output,
whether we want it to or not. So we might as well use it as an
example to document how --optionname == -o optionname, replacing
the original documentation that was part of the '-o' description.
src/cmd/ksh93/sh/args.c: sh_argopts():
- Add handling for explitit --posix option in data/builtins.c.
- Move SH_POSIX syncing SH_BRACEEXPAND and SH_LETOCTAL from
sh_applyopts() into the option parsing loop here. This fixes
the bug that letoctal was ignored in 'set -o posix +o letoctal'.
- Remember if --default was used in a flag, and do not sync options
with SH_POSIX if the flag is set. This makes 'set +o' work.
src/cmd/ksh93/include/argnod.h,
src/cmd/ksh93/data/msg.c,
src/cmd/ksh93/sh/args.c: sh_printopts():
- Do not potentially translate the 'on' and 'off' labels in 'set
-o' output. No other shell does, and some scripts parse these.
src/cmd/ksh93/sh/init.c: sh_init():
- Turn on SH_LETOCTAL early along with SH_POSIX if the shell was
invoked as sh; this makes 'sh -o' and 'sh +o' show expected
options (not that anyone does this, but correctness is good).
src/cmd/ksh93/include/defs.h,
src/cmd/ksh93/include/shell.h:
- The state flags were in defs.h and most (but not all) of the
shell options were in shell.h. Gather all the shell state and
option flag definitions into one place in shell.h for clarity.
- Remove unused SH_NOPROFILE and SH_XARGS option flags.
src/cmd/ksh93/tests/options.sh:
- Add tests for these bugs.
src/lib/libast/misc/optget.c: styles[]:
- Edit default optget(3) option self-documentation for clarity.
Several changed files:
- Some SHOPT_PFSH fixes to avoid compiling dead code.
This commit is contained in:
parent
cd1cd9c5da
commit
af5f7acf99
15 changed files with 123 additions and 83 deletions
|
|
@ -128,7 +128,7 @@ int sh_argopts(int argc,register char *argv[], void *context)
|
|||
Lex_t *lp = (Lex_t*)(shp->lex_context);
|
||||
#endif
|
||||
Shopt_t newflags;
|
||||
int setflag=0, action=0, trace=(int)sh_isoption(SH_XTRACE);
|
||||
int defaultflag=0, setflag=0, action=0, trace=(int)sh_isoption(SH_XTRACE);
|
||||
Namval_t *np = NIL(Namval_t*);
|
||||
const char *cp;
|
||||
int verbose,f;
|
||||
|
|
@ -173,6 +173,12 @@ int sh_argopts(int argc,register char *argv[], void *context)
|
|||
if(sh_isoption(SH_RESTRICTED) && !f && o==SH_RESTRICTED)
|
||||
errormsg(SH_DICT,ERROR_exit(1), e_restricted, opt_info.arg);
|
||||
break;
|
||||
case -5: /* --posix must be handled explicitly to stop AST optget(3) overriding it */
|
||||
if(opt_info.num)
|
||||
on_option(&newflags,SH_POSIX);
|
||||
else
|
||||
off_option(&newflags,SH_POSIX);
|
||||
break;
|
||||
case -6: /* --default */
|
||||
{
|
||||
register const Shtable_t *tp;
|
||||
|
|
@ -180,8 +186,9 @@ int sh_argopts(int argc,register char *argv[], void *context)
|
|||
if(!(o&SH_COMMANDLINE) && is_option(&newflags,o&0xff))
|
||||
off_option(&newflags,o&0xff);
|
||||
}
|
||||
defaultflag++;
|
||||
continue;
|
||||
case -7:
|
||||
case -7: /* --state */
|
||||
f = 0;
|
||||
goto byname;
|
||||
case 'D':
|
||||
|
|
@ -249,8 +256,14 @@ int sh_argopts(int argc,register char *argv[], void *context)
|
|||
off_option(&newflags,SH_EMACS);
|
||||
off_option(&newflags,SH_GMACS);
|
||||
}
|
||||
|
||||
#endif /* SHOPT_ESH && SHOPT_VSH */
|
||||
if(o==SH_POSIX && !defaultflag)
|
||||
{
|
||||
#if SHOPT_BRACEPAT
|
||||
off_option(&newflags,SH_BRACEEXPAND);
|
||||
#endif
|
||||
on_option(&newflags,SH_LETOCTAL);
|
||||
}
|
||||
on_option(&newflags,o);
|
||||
off_option(&ap->sh->offoptions,o);
|
||||
}
|
||||
|
|
@ -258,6 +271,13 @@ int sh_argopts(int argc,register char *argv[], void *context)
|
|||
{
|
||||
if ((o == SH_RESTRICTED) && sh_isoption(SH_RESTRICTED))
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_restricted,"r"); /* set -r cannot be unset */
|
||||
if(o==SH_POSIX && !defaultflag)
|
||||
{
|
||||
#if SHOPT_BRACEPAT
|
||||
on_option(&newflags,SH_BRACEEXPAND);
|
||||
#endif
|
||||
off_option(&newflags,SH_LETOCTAL);
|
||||
}
|
||||
if(o==SH_XTRACE)
|
||||
trace = 0;
|
||||
off_option(&newflags,o);
|
||||
|
|
@ -365,21 +385,6 @@ void sh_applyopts(Shell_t* shp,Shopt_t newflags)
|
|||
sh_onstate(SH_MONITOR);
|
||||
else if(sh_isoption(SH_MONITOR) && !is_option(&newflags,SH_MONITOR))
|
||||
sh_offstate(SH_MONITOR);
|
||||
/* -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;
|
||||
}
|
||||
|
||||
|
|
@ -606,7 +611,7 @@ void sh_printopts(Shopt_t oflags,register int mode, Shopt_t *mask)
|
|||
{
|
||||
sfputr(sfstdout,name,' ');
|
||||
sfnputc(sfstdout,' ',24-strlen(name));
|
||||
sfputr(sfstdout,on ? sh_translate(e_on) : sh_translate(e_off),'\n');
|
||||
sfputr(sfstdout,on ? "on" : "off",'\n');
|
||||
}
|
||||
else if(mode&PRINT_ALL) /* print unset options also */
|
||||
sfprintf(sfstdout, "set %co %s\n", on?'-':'+', name);
|
||||
|
|
|
|||
|
|
@ -1307,7 +1307,10 @@ Shell_t *sh_init(register int argc,register char *argv[], Shinit_f userinit)
|
|||
if(type&SH_TYPE_LOGIN)
|
||||
shp->login_sh = 2;
|
||||
if(type&SH_TYPE_POSIX)
|
||||
{
|
||||
sh_onoption(SH_POSIX);
|
||||
sh_onoption(SH_LETOCTAL);
|
||||
}
|
||||
}
|
||||
/* read the environment; don't import attributes yet, but save pointer to them */
|
||||
save_envmarker = env_init(shp);
|
||||
|
|
|
|||
|
|
@ -212,7 +212,11 @@ static pid_t path_xargs(Shell_t *shp,const char *path, char *argv[],char *const
|
|||
saveargs = 0;
|
||||
}
|
||||
}
|
||||
#if SHOPT_PFSH
|
||||
else if(spawn && !sh_isoption(SH_PFSH))
|
||||
#else
|
||||
else if(spawn)
|
||||
#endif
|
||||
{
|
||||
shp->xargexit = exitval;
|
||||
if(saveargs)
|
||||
|
|
@ -1179,7 +1183,11 @@ pid_t path_spawn(Shell_t *shp,const char *opath,register char **argv, char **env
|
|||
path = sp;
|
||||
}
|
||||
#endif /* SHELLMAGIC */
|
||||
#if SHOPT_PFSH
|
||||
if(spawn && !sh_isoption(SH_PFSH))
|
||||
#else
|
||||
if(spawn)
|
||||
#endif
|
||||
pid = _spawnveg(shp,opath, &argv[0],envp, spawn>>1);
|
||||
else
|
||||
pid = path_pfexecve(shp,opath, &argv[0] ,envp,spawn);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue