]> git.draconx.ca Git - dxcommon.git/commit
gen-strtab.awk: Work around weird ULTRIX nawk bug.
authorNick Bowler <nbowler@draconx.ca>
Sun, 3 Dec 2023 06:04:21 +0000 (01:04 -0500)
committerNick Bowler <nbowler@draconx.ca>
Sun, 3 Dec 2023 06:07:52 +0000 (01:07 -0500)
commit9cacb902a5d6f6c4271ee3066e2efe13663f145a
tree6aee671eb484efec3082c4cc1a9abc0225a7fe5b
parentc2851601e2026f36593e985d302def59eba26c17
gen-strtab.awk: Work around weird ULTRIX nawk bug.

ULTRIX 4.5 nawk has a weird bug where it seems to sometimes "forget" the
length of $0 after it has been modified, when assigning the modified
value directly to a named variable.  For example:

  % echo x | nawk '{ $0 = "hello"; x = $0; print x "rld"; }'
  hrld
  % echo xx | nawk '{ $0 = "hello"; x = $0; print x "rld"; }'
  herld

The bug does not occur if there is an intervening assignment to any of
the field variables, or if the assignment is made slightly more complex,
or if any other variable is used:

  % echo x | nawk '{ $0 = "hello"; $1 = $1; x = $0; print x "rld"; }'
  hellorld
  % echo x | nawk '{ $0 = "hello"; x = "" $0; print x "rld"; }'
  hellorld
  % nawk 'BEGIN { z = "hello"; x = z; print x "rld"; }' z=x
  hellorld

So there are many easy workarounds.
scripts/gen-strtab.awk