]> git.draconx.ca Git - dxcommon.git/commitdiff
gen-options.awk: Fix generated help text under mawk.
authorNick Bowler <nbowler@draconx.ca>
Sun, 8 Jan 2023 04:14:56 +0000 (23:14 -0500)
committerNick Bowler <nbowler@draconx.ca>
Sun, 8 Jan 2023 05:01:02 +0000 (00:01 -0500)
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.

scripts/gen-options.awk

index 679dc9904c4770fbcbec5f6d32dc991a42237ef4..f1dbb1cb2088c135ac00275c4dc7f5de3a648862 100755 (executable)
@@ -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