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
				
			
		|  | @ -1718,7 +1718,7 @@ USAGE_LICENSE | |||
| ; | ||||
| 
 | ||||
| const char sh_opttypeset[] = | ||||
| "+[-1c?\n@(#)$Id: typeset (AT&T Research/ksh93) 2020-07-15 $\n]" | ||||
| "+[-1c?\n@(#)$Id: typeset (AT&T Research/ksh93) 2021-01-20 $\n]" | ||||
| USAGE_LICENSE | ||||
| "[+NAME?typeset - declare or display variables with attributes]" | ||||
| "[+DESCRIPTION?Without the \b-f\b option, \btypeset\b sets, unsets, " | ||||
|  | @ -1738,7 +1738,7 @@ USAGE_LICENSE | |||
| "[+?Note also the following builtin command equivalents:]{" | ||||
| 	"[+autoload?\btypeset -fu\b]" | ||||
| 	"[+compound?\btypeset -C\b]" | ||||
| 	"[+float?\btypeset -lE\b]" | ||||
| 	"[+float ?\btypeset -lE\b]" | ||||
| 	"[+functions?\btypeset -f\b]" | ||||
| 	"[+integer?\btypeset -li\b]" | ||||
| 	"[+nameref?\btypeset -n\b]" | ||||
|  | @ -1768,11 +1768,9 @@ USAGE_LICENSE | |||
| "[l?Without \b-i\b, sets character mapping to \btolower\b. When used " | ||||
| 	"with \b-i\b, \b-E\b, or \b-F\b indicates long variant.]" | ||||
| "[m?Move.  The value is the name of a variable whose value will be " | ||||
| 	"moved to \aname\a.  The original variable will be unset.  Cannot be " | ||||
| 	"used with any other options.]" | ||||
| 	"moved to \aname\a.  The original variable will be unset.]" | ||||
| "[n?Name reference.  The value is the name of a variable that \aname\a " | ||||
| 	"references.  \aname\a cannot contain a \b.\b.  Cannot be used with " | ||||
| 	"any other options.]" | ||||
| 	"references.  \aname\a cannot contain a \b.\b.]" | ||||
| "[p?Causes the output to be in a format that can be used as input to the " | ||||
| 	"shell to recreate the attributes for variables.]" | ||||
| "[r?Enables readonly.  Once enabled it cannot be disabled.  See " | ||||
|  | @ -1830,6 +1828,9 @@ USAGE_LICENSE | |||
| "\n" | ||||
| "\n[name[=value]...]\n" | ||||
| " -f [name...]\n" | ||||
| " -m [name=name...]\n" | ||||
| " -n [name=name...]\n" | ||||
| " -T [tname[=(type definition)]...]\n" | ||||
| "\n" | ||||
| "[+EXIT STATUS?]{" | ||||
|         "[+0?No errors occurred.]" | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue