libav: switch from CODEC_ID to AV_CODEC_ID
[mplayer.git] / TOOLS / file2string.py
blobcb121e4884f7e95c6246683fcd459c8277772895
1 #!/usr/bin/env python3
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.
8 import sys
10 def main(infile):
11 conv = ['\\' + ("%03o" % c) for c in range(256)]
12 safe_chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" \
13 "0123456789!#%&'()*+,-./:;<=>?[]^_{|}~ "
14 for c in safe_chars:
15 conv[ord(c)] = c
16 for c, esc in ("\nn", "\tt", r"\\", '""'):
17 conv[ord(c)] = '\\' + esc
18 for line in infile:
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])
23 main(infile)