mirror of
git://git.code.sf.net/p/cdesktopenv/code
synced 2025-02-15 04:32:24 +00:00
Parser limitations prevent shcomp or source from handling enum types correctly: $ cat /tmp/colors.sh enum Color_t=(red green blue orange yellow) Color_t -A Colors=([foo]=red) $ shcomp /tmp/colors.sh > /dev/null /tmp/colors.sh: syntax error at line 2: `(' unexpected $ source /tmp/colors.sh /bin/ksh: source: syntax error: `(' unexpected Yet, for types created using 'typeset -T', this works. This is done via a check_typedef() function that preliminarily adds the special declaration builtin at parse time, with details to be filled in later at execution time. This hack will produce ugly undefined behaviour if the definition command creating that type built-in is then not actually run at execution time before the type built-in is accessed. But the hack is necessary because we're dealing with a fundamental design flaw in the ksh language. Dynamically addable built-ins that change the syntactic parsing of the shell language on the fly are an absurdity that violates the separation between parsing and execution, which muddies the waters and creates the need for some kind of ugly hack to keep things like shcomp more or less working. This commit extends that hack to support enum. src/cmd/ksh93/sh/parse.c: - check_typedef(): - Add 'intypeset' parameter that should be set to 1 for typeset and friends, 2 for enum. - When processing enum arguments, use AST getopt(3) to skip over enum's options to find the name of the type to be defined. (getopt failed if we were running a -c script; deal with this by zeroing opt_info.index first.) - item(): Update check_typedef() call, passing lexp->intypeset. - simple(): Set lexp->intypeset to 2 when processing enum. The rest of the changes are all to support the above and should be fairly obvious, except: src/cmd/ksh93/bltins/enum.c: - enuminfo(): Return on null pointer, avoiding a crash upon executing 'Type_t --man' if Type_t has not been fully defined due to the definition being pre-added at parse time but not executed. It's all still wrong, but a crash is worse. Resolves: https://github.com/ksh93/ksh/issues/256 |
||
---|---|---|
.. | ||
cmd | ||
lib | ||
Mamfile |