diff --git a/NEWS b/NEWS index 4f70f67c4..6c6651e78 100644 --- a/NEWS +++ b/NEWS @@ -3,6 +3,10 @@ For full details, see the git log at: https://github.com/ksh93/ksh/tree/1.0 Any uppercase BUG_* names are modernish shell bug IDs. +2022-03-05: + +- The 'enum' command can now create more than one type per invocation. + 2022-02-23: - When reading input from the keyboard, ksh now turns off nonblocking I/O diff --git a/src/cmd/ksh93/bltins/enum.c b/src/cmd/ksh93/bltins/enum.c index a085f7616..603623c27 100644 --- a/src/cmd/ksh93/bltins/enum.c +++ b/src/cmd/ksh93/bltins/enum.c @@ -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; diff --git a/src/cmd/ksh93/include/version.h b/src/cmd/ksh93/include/version.h index a7e2ac1de..f490df320 100644 --- a/src/cmd/ksh93/include/version.h +++ b/src/cmd/ksh93/include/version.h @@ -21,7 +21,7 @@ #define SH_RELEASE_FORK "93u+m" /* only change if you develop a new ksh93 fork */ #define SH_RELEASE_SVER "1.0.0-beta.2" /* semantic version number: https://semver.org */ -#define SH_RELEASE_DATE "2022-02-23" /* must be in this format for $((.sh.version)) */ +#define SH_RELEASE_DATE "2022-03-05" /* must be in this format for $((.sh.version)) */ #define SH_RELEASE_CPYR "(c) 2020-2022 Contributors to ksh " SH_RELEASE_FORK /* Scripts sometimes field-split ${.sh.version}, so don't change amount of whitespace. */ diff --git a/src/cmd/ksh93/sh.1 b/src/cmd/ksh93/sh.1 index dc25a8df1..b4742c1fa 100644 --- a/src/cmd/ksh93/sh.1 +++ b/src/cmd/ksh93/sh.1 @@ -6392,10 +6392,13 @@ See .IR echo (1) for usage and description. .TP -\(dd \f3enum\fP \*(OK \f3\-i\fP \*(CK \f2type\^\fP\*(OK=(\f2value\^\fP .\|.\|.) \*(CK -Creates a declaration command named \f2type\^\fP that -allows one of the specified \f2value\fPs as -enumeration names. If \f3=(\fP\f2value\^\ .\|.\|.\|\fP\f3)\fP is +\(dd \f3enum\fP \*(OK \f3\-i\fP \*(CK \f2type\^\fP\*(OK=(\f2value\^\fP .\|.\|.) \*(CK .\|.\|. +Creates, for each \f2type\^\fP specified, +an enumeration type declaration command named \f2type\^\fP. +Variables of the created type can only store any one of the \f2value\fPs given. +For example, \f3enum bool=(false true)\fP creates a Boolean variable +type of which variables may be declared like \f3bool x=true y=false\fP. +If \f3=(\fP\f2value\^\ .\|.\|.\|\fP\f3)\fP is omitted, then \f2type\^\fP must be an indexed array variable with at least two elements and the values are taken from this array variable. If @@ -6412,6 +6415,14 @@ Within arithmetic expressions (see above), enumeration type values translate to index numbers between 0 and the number of defined values minus 1. It is an error for an arithmetic expression to assign a value outside of that range. Decimal fractions are ignored. +Taking the \f3bool\fP type from the example above, +if a variable of this type is used in an arithmetic expression, +\f3false\fP translates to 0 and \f3true\fP 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 \f3bool\fP variable \f3v\fP, +\f3((v==true))\fP is the same as \f3((v==1))\fP +and if a variable named \f3true\fP exists, it is ignored. .RE .TP \(dg \f3eval\fP \*(OK \f2arg\^\fP .\|.\|. \*(CK