From: Nick Bowler Date: Sun, 3 Dec 2023 06:04:21 +0000 (-0500) Subject: gen-strtab.awk: Work around weird ULTRIX nawk bug. X-Git-Url: https://git.draconx.ca/gitweb/dxcommon.git/commitdiff_plain/9cacb902a5d6f6c4271ee3066e2efe13663f145a 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. --- diff --git a/scripts/gen-strtab.awk b/scripts/gen-strtab.awk index beacad6..716a8ec 100755 --- a/scripts/gen-strtab.awk +++ b/scripts/gen-strtab.awk @@ -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 {