about summary refs log tree commit diff stats
path: root/tools/expand_string
diff options
context:
space:
mode:
Diffstat (limited to 'tools/expand_string')
-rwxr-xr-xtools/expand_string17
1 files changed, 17 insertions, 0 deletions
diff --git a/tools/expand_string b/tools/expand_string
new file mode 100755
index 00000000..a5a9ad30
--- /dev/null
+++ b/tools/expand_string
@@ -0,0 +1,17 @@
+#!/bin/sh
+# Expand syntax sugar for SubX string literals.
+# Helpful for converting them into handles to strings.
+
+INPUT=$(cat)
+echo "    # \"$INPUT\""
+
+# print length in bytes
+printf "    0x%x/imm32/size\n" $(echo -n $INPUT |wc -c)
+
+# print ascii codes for each character in hex
+echo -n "   "
+for c in $(echo "$INPUT" | sed -e 's/./& /g')
+do
+  echo -n " 0x$(printf '%x' "'$c")/$c"
+done
+echo