diff options
author | P. J. McDermott <pj@pehjota.net> | 2017-02-08 20:39:37 (EST) |
---|---|---|
committer | P. J. McDermott <pj@pehjota.net> | 2017-02-08 20:40:27 (EST) |
commit | 8ed3dcb534324d8db54bac799eeea01b8a0a7cbb (patch) | |
tree | 3de4a238a6f08257690091de89ca1f22fd3daa3c | |
parent | 860861c7feaa939705a2a9fab95029a774d9a5cf (diff) | |
download | eggshell-8ed3dcb534324d8db54bac799eeea01b8a0a7cbb.zip eggshell-8ed3dcb534324d8db54bac799eeea01b8a0a7cbb.tar.gz eggshell-8ed3dcb534324d8db54bac799eeea01b8a0a7cbb.tar.bz2 |
eshtrans/split.sh: New experimental file
-rw-r--r-- | eshtrans/split.sh | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/eshtrans/split.sh b/eshtrans/split.sh new file mode 100644 index 0000000..bfc51cd --- /dev/null +++ b/eshtrans/split.sh @@ -0,0 +1,48 @@ +set -u + +buf="Hello, 'world'!" + +old() +{ + eval "$(printf '%s' "${buf}" | awk -v FS='' -v j=0 \ + -v squote="'" -v esc_squote="'\\\\''" ' + { + for (i = 1; i <= NF; ++i) { + sub(squote, esc_squote, $i); + printf("lbufv_%d='\''%s'\''\n", j++, $i); + }; + printf("lbufv_%d='\''\n'\''\n", j++); + } + ')" +} + +new() +{ + eval "$(printf '%s' "${buf}" | awk -v FS='' -v j=0 \ + -v squote="'" -v esc_squote="'\\\\''" ' + { + for (i = 1; i <= NF; ++i) { + sub(squote, esc_squote, $i); + printf("lbufv_%d=" squote "%s" squote "\n", + j++, $i); + }; + printf("lbufv_%d=" squote "\n" squote "\n", j++); + } + ')" +} + +print_and_clear() +{ + i=0 + while [ ${i} -le ${#buf} ]; do + c=$(eval "printf '%sx' \"\${lbufv_${i}}\"") + eval "lbufv_${i}=" + printf 'i: %2d, c: "%s"\n' ${i} "${c%x}" + i=$((${i} + 1)) + done +} + +old +print_and_clear +new +print_and_clear |