2 # $MirOS: contrib/hosted/tg/bin2print,v 1.1 2013/04/09 23:02:12 tg Exp $
5 # Thorsten Glaser <tg@mirbsd.org>
7 # Provided that these terms and disclaimer and all copyright notices
8 # are retained or reproduced in an accompanying document, permission
9 # is granted to deal in this work without restriction, including un‐
10 # limited rights to use, publicly perform, distribute, sell, modify,
11 # merge, give away, or sublicence.
13 # This work is provided “AS IS” and WITHOUT WARRANTY of any kind, to
14 # the utmost extent permitted by applicable law, neither express nor
15 # implied; without malicious intent or gross negligence. In no event
16 # may a licensor, author or contributor be held liable for indirect,
17 # direct, other damage, loss, or other issues arising in any way out
18 # of dealing in the work, even if advised of the possibility of such
19 # damage or existence of a defect, except proven that it results out
20 # of said person’s immediate fault when using the work as intended.
22 # Converts stdin to an mksh print statement producing identical, NUL
23 # safe, output for embedding (statement is not UTF-8 clean).
26 read -arN -1 line || exit 1
32 while (( i < imax )); do
34 if (( hv == 92 )); then
36 elif (( hv == 39 || hv == 126 )); then
38 elif (( hv > 31 )); then
43 elif (( hv == 7 )); then
45 elif (( hv == 8 )); then
47 elif (( hv == 12 )); then
49 elif (( hv == 10 )); then
51 elif (( hv == 13 )); then
53 elif (( hv == 9 )); then
55 elif (( hv == 11 )); then
61 print -r -- "$s'" | sed 's/\\x00\([^0-9A-Fa-f]\)/\\0\1/g'