]> git.draconx.ca Git - dxcommon.git/commit
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)
commit203a69fab1ff61e958dfb88599fd5d7f24648abf
treee13fb3cb611994b2dc7a7a8dfac8b7d2da208174
parentb84052135e522d00278d33e0b3d0afbb46e03f51
gen-strtab.awk: Work around portability problems with \\\\.

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).
scripts/gen-strtab.awk