diff options
author | Kartik Agaram <vc@akkartik.com> | 2020-05-16 14:32:42 -0700 |
---|---|---|
committer | Kartik Agaram <vc@akkartik.com> | 2020-05-18 00:44:49 -0700 |
commit | 1de6f280423f484ae0037e6c805320fa61d1bc66 (patch) | |
tree | 76317abc295d59a70e3b822fbca43f27ca68a015 /tools | |
parent | 58c2fe660f20d7f84a53fb7835363aae67525450 (diff) | |
download | mu-1de6f280423f484ae0037e6c805320fa61d1bc66.tar.gz |
mu.subx: make handles in Primitives easier to read
Diffstat (limited to 'tools')
-rwxr-xr-x | tools/expand_string | 17 |
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 |