From 4a512788e60cda5b4bd5f3151cd2834c9b9f0b32 Mon Sep 17 00:00:00 2001 From: Nick Bowler Date: Mon, 1 Jan 2024 16:37:55 -0500 Subject: [PATCH] gen-strtab.awk: Work around AIX substitution bug. On AIX 7.2 awk, the sub and gsub functions have a bug when the replacement string contains a "\1" character. The substituted strings have \1 characters replaced with amperands, for example: aix72% awk 'BEGIN { s="x"; sub("x","\1",s); sub("\1","x",s); print s; }' & Very strange. The problem is internal to (g)sub, there is no problem using "\1" characters in other contexts -- including with the other arguments to (g)sub. It should be fine to use "\2" instead which avoids this particular bug. --- scripts/gen-strtab.awk | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/scripts/gen-strtab.awk b/scripts/gen-strtab.awk index 56f0807..2a56fd6 100755 --- a/scripts/gen-strtab.awk +++ b/scripts/gen-strtab.awk @@ -1,6 +1,6 @@ #!/bin/awk -f # -# Copyright © 2021, 2023 Nick Bowler +# Copyright © 2021, 2023-2024 Nick Bowler # # Generate a C string table based on an input string specification file. # @@ -207,25 +207,25 @@ END { # strings[ident] = val. function finish_string_input(strings, ident, val, n, tmpval) { - gsub(/\\\\/, "\1", val); + gsub(/\\\\/, "\2", val); if (endline > startline) val = val "\n"; gsub(/\\\n/, "", val); tmpval = "" while ((n = match(val, /\\[^abtnvfr]/)) > 0) { - tmpval = tmpval substr(val, 1, n-1) - val = substr(val, n+1) + tmpval = tmpval substr(val, 1, n-1); + val = substr(val, n+1); } - tmpval = tmpval val + tmpval = tmpval val; # Escape special characters - gsub(/"/, bs"\"", tmpval) - gsub(/\t/, bs"t", tmpval) - gsub(/\n/, bs"n", tmpval) - gsub("\1", bs bs, tmpval) + gsub(/"/, bs"\"", tmpval); + gsub(/\t/, bs"t", tmpval); + gsub(/\n/, bs"n", tmpval); + gsub("\2", bs bs, tmpval); - strings[ident] = tmpval + strings[ident] = tmpval; if (!current_l10n) { nol10n[tmpval] = 1; } -- 2.43.2