From: Nick Bowler Date: Sun, 8 Jan 2023 04:14:56 +0000 (-0500) Subject: gen-options.awk: Fix generated help text under mawk. X-Git-Url: http://git.draconx.ca/gitweb/dxcommon.git/commitdiff_plain/e5d13e101de909b69a33cfe26e243148df8cbf51?hp=62bc7469bf3ef88c4f81ddf615aa7dabe9ddbf74 gen-options.awk: Fix generated help text under mawk. It appears that the following construction is not portable: % gawk 'BEGIN { a[0] = 0 in a ? 54 : 42; print a[0]; }' 42 % mawk 'BEGIN { a[0] = 0 in a ? 54 : 42; print a[0]; }' 54 In gen-options.awk, this results in results in bogus leading newlines added to the help text. It is easy enough to restructure the code to not do that, separating the test from the assignment. --- diff --git a/scripts/gen-options.awk b/scripts/gen-options.awk index 679dc99..f1dbb1c 100755 --- a/scripts/gen-options.awk +++ b/scripts/gen-options.awk @@ -213,7 +213,9 @@ lopt { sub(/^[ \t]*/, "") if (!$0) { next } - optionhelp[lopt] = (lopt in optionhelp ? optionhelp[lopt] "\n" : "") $0 + if (lopt in optionhelp) + $0 = "\n" $0; + optionhelp[lopt] = optionhelp[lopt] $0; } # Exit immediately on error