mirror of
git://git.code.sf.net/p/cdesktopenv/code
synced 2025-03-09 15:50:02 +00:00
typeset: add error msgs for incompatible options; improve usage msg
This adds informative error messages if incompatible options are
given. It also documents the exclusive -m, -n and -T options on
separate usage lines, as was already done with -f. The usage
message for incompatible options now looks something like this:
| $ ksh -c 'typeset -L10 -F -f -i foo'
| ksh: typeset: -i/-F/-E/-X cannot be used with -L/-R/-Z
| ksh: typeset: -f cannot be used with other options
| Usage: typeset [-bflmnprstuxACHS] [-a[type]] [-i[base]] [-E[n]]
| [-F[n]] [-L[n]] [-M[mapping]] [-R[n]] [-X[n]]
| [-h string] [-T[tname]] [-Z[n]] [name[=value]...]
| Or: typeset -f [name...]
| Or: typeset -m [name=name...]
| Or: typeset -n [name=name...]
| Or: typeset -T [tname[=(type definition)]...]
| Help: typeset [ --help | --man ] 2>&1
(see also the previous commit, e21a053e)
Unfortunately the first "Usage" line has some redundancies with the
"Or:" lines showing separate usages. It doesn't seem to be possible
to avoid this; it's a flaw in how libast generates everything
(usage, help, manual) from one huge getopt(3) string. I still think
the three added "Or:" lines are an improvement as it wasn't
previously shown that these options need to be used on their own.
src/cmd/ksh93/bltins/typeset.c: b_typeset():
- Instead of only showing a generic usage message, add an
informative error message if incompatible options were given.
- Conflicting options detection was failing because NV_LJUST and
NV_EXPNOTE have the same bitmask value. Use a new 'isadjust'
flag for -L/-R/-Z to remember if one of these was set.
- Detect conflict between -L/-R/-Z and a float option, not just -i.
src/cmd/ksh93/include/name.h, src/cmd/ksh93/data/msg.c:
- Add the two new error messages for incompatible options.
src/cmd/ksh93/data/builtins.c: sh_opttypeset[]:
- Add a space after 'float' in in "[+float?\btypeset -lE\b]" as
this makes 'float' appear on its own line, improving formatting.
- Show -m, -n, -T on separate usage lines like -f, as none of these
can be combined with other options.
- Remove "cannot be combined with other options" from -m and -n
descriptions, as that should now be clear from the separate usage
lines -- and even if not, the error message is now informative.
src/cmd/ksh93/sh.1, src/cmd/ksh93/COMPATIBILITY:
- Update.
src/cmd/ksh93/tests/types.sh:
- Remove obsolete test: 'typeset -RF' is no longer accepted.
(It crashed in 93u+, so this is not an incompatibility...)
Resolves: https://github.com/ksh93/ksh/issues/48
This commit is contained in:
parent
e21a053e19
commit
0a10e76ccc
8 changed files with 58 additions and 17 deletions
|
|
@ -195,7 +195,7 @@ int b_typeset(int argc,register char *argv[],Shbltin_t *context)
|
|||
const char *optstring = sh_opttypeset;
|
||||
Namdecl_t *ntp = (Namdecl_t*)context->ptr;
|
||||
Dt_t *troot;
|
||||
int isfloat=0, shortint=0, sflag=0;
|
||||
int isfloat=0, isadjust=0, shortint=0, sflag=0;
|
||||
|
||||
memset((void*)&tdata,0,sizeof(tdata));
|
||||
tdata.sh = context->shp;
|
||||
|
|
@ -297,6 +297,7 @@ int b_typeset(int argc,register char *argv[],Shbltin_t *context)
|
|||
tdata.argnum = (int)opt_info.num;
|
||||
if(tdata.argnum < 0)
|
||||
errormsg(SH_DICT,ERROR_exit(1), e_badfield, tdata.argnum);
|
||||
isadjust = 1;
|
||||
if(n=='Z')
|
||||
flag |= NV_ZFILL;
|
||||
else
|
||||
|
|
@ -377,18 +378,36 @@ endargs:
|
|||
argv--;
|
||||
if((flag&NV_ZFILL) && !(flag&NV_LJUST))
|
||||
flag |= NV_RJUST;
|
||||
if((flag&NV_INTEGER) && (flag&(NV_LJUST|NV_RJUST|NV_ZFILL)))
|
||||
if((isfloat || flag&NV_INTEGER) && isadjust)
|
||||
{
|
||||
errormsg(SH_DICT,2,e_optincompat2,"-i/-F/-E/-X","-L/-R/-Z");
|
||||
error_info.errors++;
|
||||
}
|
||||
if((flag&NV_BINARY) && (flag&(NV_LJUST|NV_UTOL|NV_LTOU)))
|
||||
{
|
||||
errormsg(SH_DICT,2,e_optincompat2,"-b","-L/-u/-l");
|
||||
error_info.errors++;
|
||||
}
|
||||
if((flag&NV_MOVE) && (flag&~(NV_MOVE|NV_VARNAME|NV_ASSIGN)))
|
||||
{
|
||||
errormsg(SH_DICT,2,e_optincompat1,"-m");
|
||||
error_info.errors++;
|
||||
}
|
||||
if((flag&NV_REF) && (flag&~(NV_REF|NV_IDENT|NV_ASSIGN)))
|
||||
{
|
||||
errormsg(SH_DICT,2,e_optincompat1,"-n");
|
||||
error_info.errors++;
|
||||
}
|
||||
if((flag&NV_TYPE) && (flag&~(NV_TYPE|NV_VARNAME|NV_ASSIGN)))
|
||||
{
|
||||
errormsg(SH_DICT,2,e_optincompat1,"-T");
|
||||
error_info.errors++;
|
||||
}
|
||||
if(troot==tdata.sh->fun_tree && ((isfloat || flag&~(NV_FUNCT|NV_TAGGED|NV_EXPORT|NV_LTOU))))
|
||||
{
|
||||
errormsg(SH_DICT,2,e_optincompat1,"-f");
|
||||
error_info.errors++;
|
||||
}
|
||||
if(sflag && troot==tdata.sh->fun_tree)
|
||||
{
|
||||
/* static function */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue