]> git.draconx.ca Git - dxcommon.git/commitdiff
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)
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

index beacad6b7c64a1b97ec68e27a6a730602e6cd2ee..716a8ec46f1b5e057c17e014a0c33f9278279e57 100755 (executable)
@@ -117,22 +117,18 @@ sub(/^[&]/, "") {
   }
 
   current_l10n = !sub(/^[&]/, "", $1);
-  startline = NR
-  ident = $1
+  startline = NR;
+  ident = $1;
 
-  $1 = ""
-  collected = ""
+  $1 = collected = "";
 }
 
 ident != "" {
-  sub(/^[ \t]*/, "")
-  if (collected) {
-    collected = collected "\n" $0
-  } else {
-    collected = $0
-  }
+  sub(/^[ \t]*/, "");
 
-  endline = NR
+  sep = collected != "" ? "\n" : "";
+  collected = collected sep $0;
+  endline = NR;
 }
 
 END {