]> git.draconx.ca Git - dxcommon.git/commitdiff
gen-strtab.awk: Work around AIX substitution bug.
authorNick Bowler <nbowler@draconx.ca>
Mon, 1 Jan 2024 21:37:55 +0000 (16:37 -0500)
committerNick Bowler <nbowler@draconx.ca>
Mon, 1 Jan 2024 21:48:11 +0000 (16:48 -0500)
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

index 56f0807998c9fe2fbe527fb1a31f82b9d047a3ef..2a56fd65a52e7324a6c56928cc9d64578457cb9f 100755 (executable)
@@ -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;
   }