mirror of
git://git.code.sf.net/p/cdesktopenv/code
synced 2025-03-09 15:50:02 +00:00
enum: remove arbitrary one-argument limitation
b_enum() contains a check that exactly one argument is given: 237: if (error_info.errors || !*argv || *(argv + 1)) But the subsequent argument handling loop will happily deal with multiple arguments: 246: while(cp = *argv++) Every other declaration command supports multiple arguments and I see no reason why enum shouldn't. Simply removing the '*(argv + 1)' check allows 'enum' to create more than one type per invocation. src/cmd/ksh93/bltins/enum.c: - b_enum(): Remove check for >1 args as described above. - Update documentation to describe the behaviour of enumeration types in arithmetic expressions and to add an example: a bool type with two enumeration values 'false' (0) and 'true' (1). That type is predefined in ksh 93v- and 2020. We're not going to do that in 93u+m but it's good to document the possibility. src/cmd/ksh93/sh.1: - Make changes parallel to the enum.c self-doc update.
This commit is contained in:
parent
b398f33c49
commit
fae1932e62
4 changed files with 39 additions and 12 deletions
|
@ -20,21 +20,33 @@
|
|||
***********************************************************************/
|
||||
#include "defs.h"
|
||||
|
||||
#define ENUM_ID "enum (ksh 93u+m) 2021-12-17"
|
||||
#define ENUM_ID "enum (ksh 93u+m) 2022-03-05"
|
||||
|
||||
const char sh_optenum[] =
|
||||
"[-?@(#)$Id: " ENUM_ID " $\n]"
|
||||
"[--catalog?" ERROR_CATALOG "]"
|
||||
"[+NAME?enum - create an enumeration type]"
|
||||
"[+DESCRIPTION?\benum\b is a declaration command that creates an enumeration "
|
||||
"type \atypename\a that can only store any one of the values in the indexed "
|
||||
"array variable \atypename\a.]"
|
||||
"[+DESCRIPTION?\benum\b is a declaration command that creates one or more "
|
||||
"enumeration type declaration commands named \atypename\a. Variables "
|
||||
"of the created type can only store any one of the \avalue\as given. "
|
||||
"For example, \benum bool=(false true)\b creates a Boolean variable "
|
||||
"type of which variables may be declared like \bbool x=true y=false\b.]"
|
||||
"[+?If the list of \avalue\as is omitted, then \atypename\a must name an "
|
||||
"indexed array variable with at least two elements.]"
|
||||
"[+?For more information, see \atypename\a \b--man\b.]"
|
||||
"[+?For more information, create a type, then use \atypename\a \b--man\b.]"
|
||||
"[+USE IN ARITHMETIC EXPRESSIONS?When an enumeration variable is used in an "
|
||||
"arithmetic expression, its value is the index into the array that "
|
||||
"defined it, starting from 0. Taking the \bbool\b type from the "
|
||||
"example above, if a variable of this type is used in an arithmetic "
|
||||
"expression, \bfalse\b translates to 0 and \btrue\b to 1.]"
|
||||
"[+?Enumeration values may also be used directly in an arithmetic expression "
|
||||
"that refers to a variable of an enumeration type. "
|
||||
"To continue our example, for a \bbool\b variable \bv\b, "
|
||||
"\b((v==true))\b is the same as \b((v==1))\b and "
|
||||
"if a variable named \btrue\b exists, it is ignored.]"
|
||||
"[i:ignorecase?The values are case insensitive.]"
|
||||
"\n"
|
||||
"\n\atypename\a[\b=(\b \avalue\a ... \b)\b]\n"
|
||||
"\n\atypename\a[\b=(\b \avalue\a ... \b)\b] ...\n"
|
||||
"\n"
|
||||
"[+EXIT STATUS]"
|
||||
"{"
|
||||
|
@ -234,7 +246,7 @@ int b_enum(int argc, char** argv, Shbltin_t *context)
|
|||
break;
|
||||
}
|
||||
argv += opt_info.index;
|
||||
if (error_info.errors || !*argv || *(argv + 1))
|
||||
if (error_info.errors || !*argv)
|
||||
{
|
||||
error(ERROR_USAGE|2, "%s", optusage(NiL));
|
||||
return 1;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue