3 # Convert the contents of a file into a C string constant.
4 # Note that the compiler will implicitly add an extra 0 byte at the end
5 # of every string, so code using the string may need to remove that to get
6 # the exact contents of the original file.
11 conv
= ['\\' + ("%03o" % c
) for c
in range(256)]
12 safe_chars
= "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" \
13 "0123456789!#%&'()*+,-./:;<=>?[]^_{|}~ "
16 for c
, esc
in ("\nn", "\tt", r
"\\", '""'):
17 conv
[ord(c
)] = '\\' + esc
19 sys
.stdout
.write('"' + ''.join(conv
[c
] for c
in line
) + '"\n')
21 with
open(sys
.argv
[1], 'rb') as infile
:
22 sys
.stdout
.write("// Generated from %s\n\n" % sys
.argv
[1])