]> git.draconx.ca Git - dxcommon.git/commitdiff
gen-strtab.awk: Work around portability problems with \\\\.
authorNick Bowler <nbowler@draconx.ca>
Wed, 4 Jan 2023 03:41:58 +0000 (22:41 -0500)
committerNick Bowler <nbowler@draconx.ca>
Wed, 4 Jan 2023 03:41:58 +0000 (22:41 -0500)
It seems that mawk, and also gawk in POSIX mode, handle backslashes
in the (g)sub replacement strings strangely.  For example:

  % echo 'hello' | mawk '{ sub(/e/, "\\\\"); print }'
  h\llo

  % echo 'hello' | gawk '{ sub(/e/, "\\\\"); print }'
  h\\llo

  % echo 'hello' | POSIXLY_CORRECT=1 gawk '{ sub(/e/, "\\\\"); print }'
  h\llo

This causes errors when the script tries to use gsub to restore
the double backslashes on these implementations.  There seems to
be no trouble substiting "\\" to get a single backslash, so we
can work around the problem by doubling up the characters being
replaced instead (which additionally requires an adjustment to
the length calculations to reverse this).


No differences found