]> git.draconx.ca Git - dxcommon.git/blobdiff - scripts/gen-tree.awk
Rework backslash substitutions in awk scripts.
[dxcommon.git] / scripts / gen-tree.awk
index c461e5d1b97ec211575241408a54d03d4f63530a..55a7d5c4e6bebe3bc02bdbfa867f43702907c0e7 100755 (executable)
@@ -93,6 +93,10 @@ END {
 }
 
 BEGIN {
+  # Check if "\\\\" in substitutions gives just one backslash.
+  bs = "x"; sub(/x/, "\\\\", bs);
+  bs = (length(bs) == 1 ? "\\\\" : "\\");
+
   opts["strtab"] = 1;
 
   depth = max_depth = 0;
@@ -187,7 +191,7 @@ END {
       }
     }
 
-    gsub(/\1/, "\"\n\t\"\\0\" \"", entry_strtab);
+    gsub("\1", "\"\n\t\"" bs "0\" \"", entry_strtab);
     sub(/^"/, "", entry_strtab);
     sub(/\n[^\n]*$/, ";", entry_strtab);
     print "\nstatic const char tree_strtab[] =" entry_strtab